root/fs/nfs/inode.c

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

DEFINITIONS

This source file includes following definitions.
  1. nfs_put_super
  2. nfs_read_super
  3. nfs_statfs
  4. nfs_fhget
  5. nfs_notify_change

   1 /*
   2  *  linux/fs/nfs/inode.c
   3  *
   4  *  Copyright (C) 1992  Rick Sladkey
   5  *
   6  *  nfs inode and superblock handling functions
   7  */
   8 
   9 #include <asm/system.h>
  10 #include <asm/segment.h>
  11 
  12 #include <linux/sched.h>
  13 #include <linux/nfs_fs.h>
  14 #include <linux/kernel.h>
  15 #include <linux/mm.h>
  16 #include <linux/string.h>
  17 #include <linux/stat.h>
  18 #include <linux/errno.h>
  19 #include <linux/locks.h>
  20 
  21 extern int close_fp(struct file *filp);
  22 
  23 static int nfs_notify_change(struct inode *);
  24 static void nfs_put_super(struct super_block *);
  25 static void nfs_statfs(struct super_block *, struct statfs *);
  26 
  27 static struct super_operations nfs_sops = { 
  28         NULL,                   /* read inode */
  29         nfs_notify_change,      /* notify change */
  30         NULL,                   /* write inode */
  31         NULL,                   /* put inode */
  32         nfs_put_super,          /* put superblock */
  33         NULL,                   /* write superblock */
  34         nfs_statfs              /* stat filesystem */
  35 };
  36 
  37 void nfs_put_super(struct super_block *sb)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39         close_fp(sb->u.nfs_sb.s_server.file);
  40         lock_super(sb);
  41         sb->s_dev = 0;
  42         unlock_super(sb);
  43 }
  44 
  45 /*
  46  * The way this works is that the mount process passes a structure
  47  * in the data argument which contains an open socket to the NFS
  48  * server and the root file handle obtained from the server's mount
  49  * daemon.  We stash theses away in the private superblock fields.
  50  * Later we can add other mount parameters like caching values.
  51  */
  52 
  53 struct super_block *nfs_read_super(struct super_block *sb, void *raw_data)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
  56         struct nfs_server *server;
  57         unsigned int fd;
  58         struct file *filp;
  59         dev_t dev = sb->s_dev;
  60 
  61         if (!data) {
  62                 printk("nfs_read_super: missing data argument\n");
  63                 sb->s_dev = 0;
  64                 return NULL;
  65         }
  66         fd = data->fd;
  67         if (data->version != NFS_MOUNT_VERSION) {
  68                 printk("nfs warning: mount version %s than kernel\n",
  69                         data->version < NFS_MOUNT_VERSION ? "older" : "newer");
  70         }
  71         if (fd >= NR_OPEN || !(filp = current->filp[fd])) {
  72                 printk("nfs_read_super: invalid file descriptor\n");
  73                 sb->s_dev = 0;
  74                 return NULL;
  75         }
  76         if (!S_ISSOCK(filp->f_inode->i_mode)) {
  77                 printk("nfs_read_super: not a socket\n");
  78                 sb->s_dev = 0;
  79                 return NULL;
  80         }
  81         filp->f_count++;
  82         lock_super(sb);
  83         sb->s_blocksize = 1024; /* XXX */
  84         sb->s_magic = NFS_SUPER_MAGIC;
  85         sb->s_dev = dev;
  86         sb->s_op = &nfs_sops;
  87         server = &sb->u.nfs_sb.s_server;
  88         server->file = filp;
  89         server->lock = 0;
  90         server->wait = NULL;
  91         server->flags = data->flags;
  92         server->rsize = data->rsize;
  93         if (server->rsize <= 0)
  94                 server->rsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
  95         else if (server->rsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
  96                 server->rsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
  97         server->wsize = data->wsize;
  98         if (server->wsize <= 0)
  99                 server->wsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
 100         else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
 101                 server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
 102         server->timeo = data->timeo*HZ/10;
 103         server->retrans = data->retrans;
 104         server->acregmin = data->acregmin*HZ;
 105         server->acregmax = data->acregmax*HZ;
 106         server->acdirmin = data->acdirmin*HZ;
 107         server->acdirmax = data->acdirmax*HZ;
 108         strcpy(server->hostname, data->hostname);
 109         sb->u.nfs_sb.s_root = data->root;
 110         unlock_super(sb);
 111         if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
 112                 sb->s_dev = 0;
 113                 printk("nfs_read_super: get root inode failed\n");
 114                 return NULL;
 115         }
 116         return sb;
 117 }
 118 
 119 void nfs_statfs(struct super_block *sb, struct statfs *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         int error;
 122         struct nfs_fsinfo res;
 123 
 124         put_fs_long(NFS_SUPER_MAGIC, &buf->f_type);
 125         error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
 126                 &res);
 127         if (error) {
 128                 if (error != -EINTR)
 129                         printk("nfs_statfs: statfs error = %d\n", -error);
 130                 res.bsize = res.blocks = res.bfree = res.bavail = 0;
 131         }
 132         put_fs_long(res.bsize, &buf->f_bsize);
 133         put_fs_long(res.blocks, &buf->f_blocks);
 134         put_fs_long(res.bfree, &buf->f_bfree);
 135         put_fs_long(res.bavail, &buf->f_bavail);
 136 #if 0
 137         put_fs_long(-1, &buf->f_files);
 138         put_fs_long(-1, &buf->f_ffree);
 139 #else
 140         put_fs_long(0, &buf->f_files);
 141         put_fs_long(0, &buf->f_ffree);
 142 #endif
 143 }
 144 
 145 /*
 146  * This is our own version of iget that looks up inodes by file handle
 147  * instead of inode number.  We use this technique instead of using
 148  * the vfs read_inode function because there is no way to pass the
 149  * file handle or current attributes into the read_inode function.
 150  * We just have to be careful not to subvert iget's special handling
 151  * of mount points.
 152  */
 153 
 154 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
     /* [previous][next][first][last][top][bottom][index][help] */
 155                         struct nfs_fattr *fattr)
 156 {
 157         struct nfs_fattr newfattr;
 158         int error;
 159         struct inode *inode;
 160 
 161         if (!sb) {
 162                 printk("nfs_fhget: super block is NULL\n");
 163                 return NULL;
 164         }
 165         if (!fattr) {
 166                 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
 167                         &newfattr);
 168                 if (error) {
 169                         printk("nfs_fhget: getattr error = %d\n", -error);
 170                         return NULL;
 171                 }
 172                 fattr = &newfattr;
 173         }
 174         if (!(inode = iget(sb, fattr->fileid))) {
 175                 printk("nfs_fhget: iget failed\n");
 176                 return NULL;
 177         }
 178         if (inode->i_dev == sb->s_dev) {
 179                 if (inode->i_ino != fattr->fileid) {
 180                         printk("nfs_fhget: unexpected inode from iget\n");
 181                         return inode;
 182                 }
 183                 *NFS_FH(inode) = *fhandle;
 184                 nfs_refresh_inode(inode, fattr);
 185         }
 186         return inode;
 187 }
 188 
 189 int nfs_notify_change(struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 190 {
 191         struct nfs_sattr sattr;
 192         struct nfs_fattr fattr;
 193         int error;
 194 
 195         sattr.mode = inode->i_mode;
 196         sattr.uid = inode->i_uid;
 197         sattr.gid = inode->i_gid;
 198         sattr.size = S_ISREG(inode->i_mode) ? inode->i_size : -1;
 199         sattr.mtime.seconds = inode->i_mtime;
 200         sattr.mtime.useconds = 0;
 201         sattr.atime.seconds = inode->i_atime;
 202         sattr.atime.useconds = 0;
 203         error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
 204                 &sattr, &fattr);
 205         if (!error)
 206                 nfs_refresh_inode(inode, &fattr);
 207         inode->i_dirt = 0;
 208         return error;
 209 }
 210 

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