root/fs/nfs/inode.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nfs_put_inode
  2. nfs_put_super
  3. nfs_read_super
  4. nfs_statfs
  5. nfs_fhget
  6. nfs_notify_change
  7. init_module
  8. cleanup_module

   1 /*
   2  *  linux/fs/nfs/inode.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  nfs inode and superblock handling functions
   7  *
   8  *  Modularised by Alan Cox <Alan.Cox@linux.org>, while hacking some
   9  *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
  10  *
  11  *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
  12  *  J.S.Peatfield@damtp.cam.ac.uk
  13  *
  14  */
  15 
  16 #ifdef MODULE
  17 #include <linux/module.h>
  18 #include <linux/version.h>
  19 #else
  20 #define MOD_INC_USE_COUNT
  21 #define MOD_DEC_USE_COUNT
  22 #endif
  23 
  24 #include <asm/system.h>
  25 #include <asm/segment.h>
  26 
  27 #include <linux/sched.h>
  28 #include <linux/nfs_fs.h>
  29 #include <linux/kernel.h>
  30 #include <linux/mm.h>
  31 #include <linux/string.h>
  32 #include <linux/stat.h>
  33 #include <linux/errno.h>
  34 #include <linux/locks.h>
  35 
  36 extern int close_fp(struct file *filp);
  37 
  38 static int nfs_notify_change(struct inode *, struct iattr *);
  39 static void nfs_put_inode(struct inode *);
  40 static void nfs_put_super(struct super_block *);
  41 static void nfs_statfs(struct super_block *, struct statfs *, int bufsiz);
  42 
  43 static struct super_operations nfs_sops = { 
  44         NULL,                   /* read inode */
  45         nfs_notify_change,      /* notify change */
  46         NULL,                   /* write inode */
  47         nfs_put_inode,          /* put inode */
  48         nfs_put_super,          /* put superblock */
  49         NULL,                   /* write superblock */
  50         nfs_statfs,             /* stat filesystem */
  51         NULL
  52 };
  53 
  54 static void nfs_put_inode(struct inode * inode)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         clear_inode(inode);
  57 }
  58 
  59 void nfs_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61         close_fp(sb->u.nfs_sb.s_server.file);
  62         lock_super(sb);
  63         sb->s_dev = 0;
  64         unlock_super(sb);
  65         MOD_DEC_USE_COUNT;
  66 }
  67 
  68 /*
  69  * The way this works is that the mount process passes a structure
  70  * in the data argument which contains an open socket to the NFS
  71  * server and the root file handle obtained from the server's mount
  72  * daemon.  We stash theses away in the private superblock fields.
  73  * Later we can add other mount parameters like caching values.
  74  */
  75 
  76 struct super_block *nfs_read_super(struct super_block *sb, void *raw_data,
     /* [previous][next][first][last][top][bottom][index][help] */
  77                                    int silent)
  78 {
  79         struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
  80         struct nfs_server *server;
  81         unsigned int fd;
  82         struct file *filp;
  83 
  84         kdev_t dev = sb->s_dev;
  85 
  86         MOD_INC_USE_COUNT;
  87         if (!data) {
  88                 printk("nfs_read_super: missing data argument\n");
  89                 sb->s_dev = 0;
  90                 MOD_DEC_USE_COUNT;
  91                 return NULL;
  92         }
  93         fd = data->fd;
  94         if (data->version != NFS_MOUNT_VERSION) {
  95                 printk("nfs warning: mount version %s than kernel\n",
  96                         data->version < NFS_MOUNT_VERSION ? "older" : "newer");
  97         }
  98         if (fd >= NR_OPEN || !(filp = current->files->fd[fd])) {
  99                 printk("nfs_read_super: invalid file descriptor\n");
 100                 sb->s_dev = 0;
 101                 MOD_DEC_USE_COUNT;
 102                 return NULL;
 103         }
 104         if (!S_ISSOCK(filp->f_inode->i_mode)) {
 105                 printk("nfs_read_super: not a socket\n");
 106                 sb->s_dev = 0;
 107                 MOD_DEC_USE_COUNT;
 108                 return NULL;
 109         }
 110         filp->f_count++;
 111         lock_super(sb);
 112 
 113         sb->s_blocksize = 1024; /* XXX */
 114         sb->s_blocksize_bits = 10;
 115         sb->s_magic = NFS_SUPER_MAGIC;
 116         sb->s_dev = dev;
 117         sb->s_op = &nfs_sops;
 118         server = &sb->u.nfs_sb.s_server;
 119         server->file = filp;
 120         server->lock = 0;
 121         server->wait = NULL;
 122         server->flags = data->flags;
 123         server->rsize = data->rsize;
 124         if (server->rsize <= 0)
 125                 server->rsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
 126         else if (server->rsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
 127                 server->rsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
 128         server->wsize = data->wsize;
 129         if (server->wsize <= 0)
 130                 server->wsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
 131         else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
 132                 server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
 133         server->timeo = data->timeo*HZ/10;
 134         server->retrans = data->retrans;
 135         server->acregmin = data->acregmin*HZ;
 136         server->acregmax = data->acregmax*HZ;
 137         server->acdirmin = data->acdirmin*HZ;
 138         server->acdirmax = data->acdirmax*HZ;
 139         strcpy(server->hostname, data->hostname);
 140 
 141         /* Start of JSP NFS patch */
 142         /* Check if passed address in data->addr */
 143         if (data->addr.sin_addr.s_addr == INADDR_ANY) {  /* No address passed */
 144           if (((struct sockaddr_in *)(&server->toaddr))->sin_addr.s_addr == INADDR_ANY) {
 145             printk("NFS: Error passed unconnected socket and no address\n") ;
 146             MOD_DEC_USE_COUNT;
 147             return NULL ;
 148           } else {
 149             /* Need access to socket internals  JSP */
 150             struct socket *sock;
 151             int dummylen ;
 152 
 153          /*   printk("NFS: using socket address\n") ;*/
 154 
 155             sock = &((filp->f_inode)->u.socket_i);
 156 
 157             /* extract the other end of the socket into server->toaddr */
 158             sock->ops->getname(sock, &(server->toaddr), &dummylen, 1) ;
 159           }
 160         } else {
 161         /*  printk("NFS: coppying passed addr to server->toaddr\n") ;*/
 162           memcpy((char *)&(server->toaddr),(char *)(&data->addr),sizeof(server->toaddr));
 163         }
 164         /* End of JSP NFS patch */
 165 
 166         sb->u.nfs_sb.s_root = data->root;
 167         unlock_super(sb);
 168         if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
 169                 sb->s_dev = 0;
 170                 printk("nfs_read_super: get root inode failed\n");
 171                 MOD_DEC_USE_COUNT;
 172                 return NULL;
 173         }
 174         return sb;
 175 }
 176 
 177 void nfs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
     /* [previous][next][first][last][top][bottom][index][help] */
 178 {
 179         int error;
 180         struct nfs_fsinfo res;
 181         struct statfs tmp;
 182 
 183         error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
 184                 &res);
 185         if (error) {
 186                 printk("nfs_statfs: statfs error = %d\n", -error);
 187                 res.bsize = res.blocks = res.bfree = res.bavail = 0;
 188         }
 189         tmp.f_type = NFS_SUPER_MAGIC;
 190         tmp.f_bsize = res.bsize;
 191         tmp.f_blocks = res.blocks;
 192         tmp.f_bfree = res.bfree;
 193         tmp.f_bavail = res.bavail;
 194         tmp.f_files = 0;
 195         tmp.f_ffree = 0;
 196         tmp.f_namelen = NAME_MAX;
 197         memcpy_tofs(buf, &tmp, bufsiz);
 198 }
 199 
 200 /*
 201  * This is our own version of iget that looks up inodes by file handle
 202  * instead of inode number.  We use this technique instead of using
 203  * the vfs read_inode function because there is no way to pass the
 204  * file handle or current attributes into the read_inode function.
 205  * We just have to be careful not to subvert iget's special handling
 206  * of mount points.
 207  */
 208 
 209 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
     /* [previous][next][first][last][top][bottom][index][help] */
 210                         struct nfs_fattr *fattr)
 211 {
 212         struct nfs_fattr newfattr;
 213         int error;
 214         struct inode *inode;
 215 
 216         if (!sb) {
 217                 printk("nfs_fhget: super block is NULL\n");
 218                 return NULL;
 219         }
 220         if (!fattr) {
 221                 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
 222                         &newfattr);
 223                 if (error) {
 224                         printk("nfs_fhget: getattr error = %d\n", -error);
 225                         return NULL;
 226                 }
 227                 fattr = &newfattr;
 228         }
 229         if (!(inode = iget(sb, fattr->fileid))) {
 230                 printk("nfs_fhget: iget failed\n");
 231                 return NULL;
 232         }
 233         if (inode->i_dev == sb->s_dev) {
 234                 if (inode->i_ino != fattr->fileid) {
 235                         printk("nfs_fhget: unexpected inode from iget\n");
 236                         return inode;
 237                 }
 238                 *NFS_FH(inode) = *fhandle;
 239                 nfs_refresh_inode(inode, fattr);
 240         }
 241         return inode;
 242 }
 243 
 244 int nfs_notify_change(struct inode *inode, struct iattr *attr)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         struct nfs_sattr sattr;
 247         struct nfs_fattr fattr;
 248         int error;
 249 
 250         if (attr->ia_valid & ATTR_MODE) 
 251                 sattr.mode = attr->ia_mode;
 252         else
 253                 sattr.mode = (unsigned) -1;
 254 
 255         if (attr->ia_valid & ATTR_UID)
 256                 sattr.uid = attr->ia_uid;
 257         else
 258                 sattr.uid = (unsigned) -1;
 259 
 260         if (attr->ia_valid & ATTR_GID)
 261                 sattr.gid = attr->ia_gid;
 262         else
 263                 sattr.gid = (unsigned) -1;
 264 
 265         if (attr->ia_valid & ATTR_SIZE)
 266                 sattr.size = S_ISREG(inode->i_mode) ? attr->ia_size : -1;
 267         else
 268                 sattr.size = (unsigned) -1;
 269 
 270         if (attr->ia_valid & ATTR_MTIME) {
 271                 sattr.mtime.seconds = attr->ia_mtime;
 272                 sattr.mtime.useconds = 0;
 273         } else 
 274                 sattr.mtime.seconds = sattr.mtime.useconds = (unsigned) -1;
 275 
 276         if (attr->ia_valid & ATTR_ATIME) {
 277                 sattr.atime.seconds = attr->ia_atime;
 278                 sattr.atime.useconds = 0;
 279         } else
 280                 sattr.atime.seconds = sattr.atime.useconds = (unsigned) -1;
 281 
 282         error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
 283                 &sattr, &fattr);
 284         if (!error)
 285                 nfs_refresh_inode(inode, &fattr);
 286         inode->i_dirt = 0;
 287         return error;
 288 }
 289 
 290 #ifdef MODULE
 291 
 292 /* Every kernel module contains stuff like this. */
 293 
 294 char kernel_version[] = UTS_RELEASE;
 295 
 296 static struct file_system_type nfs_fs_type = {
 297         nfs_read_super, "nfs", 0, NULL
 298 };
 299 
 300 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 301 {
 302         register_filesystem(&nfs_fs_type);
 303         return 0;
 304 }
 305 
 306 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 307 {
 308         unregister_filesystem(&nfs_fs_type);
 309         nfs_kfree_cache();
 310 }
 311 
 312 #endif

/* [previous][next][first][last][top][bottom][index][help] */