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(int, 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                 printk("nfs_statfs: statfs error = %d\n", -error);
 129                 res.bsize = res.blocks = res.bfree = res.bavail = 0;
 130         }
 131         put_fs_long(res.bsize, &buf->f_bsize);
 132         put_fs_long(res.blocks, &buf->f_blocks);
 133         put_fs_long(res.bfree, &buf->f_bfree);
 134         put_fs_long(res.bavail, &buf->f_bavail);
 135         put_fs_long(0, &buf->f_files);
 136         put_fs_long(0, &buf->f_ffree);
 137 }
 138 
 139 /*
 140  * This is our own version of iget that looks up inodes by file handle
 141  * instead of inode number.  We use this technique instead of using
 142  * the vfs read_inode function because there is no way to pass the
 143  * file handle or current attributes into the read_inode function.
 144  * We just have to be careful not to subvert iget's special handling
 145  * of mount points.
 146  */
 147 
 148 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
     /* [previous][next][first][last][top][bottom][index][help] */
 149                         struct nfs_fattr *fattr)
 150 {
 151         struct nfs_fattr newfattr;
 152         int error;
 153         struct inode *inode;
 154 
 155         if (!sb) {
 156                 printk("nfs_fhget: super block is NULL\n");
 157                 return NULL;
 158         }
 159         if (!fattr) {
 160                 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
 161                         &newfattr);
 162                 if (error) {
 163                         printk("nfs_fhget: getattr error = %d\n", -error);
 164                         return NULL;
 165                 }
 166                 fattr = &newfattr;
 167         }
 168         if (!(inode = iget(sb, fattr->fileid))) {
 169                 printk("nfs_fhget: iget failed\n");
 170                 return NULL;
 171         }
 172         if (inode->i_dev == sb->s_dev) {
 173                 if (inode->i_ino != fattr->fileid) {
 174                         printk("nfs_fhget: unexpected inode from iget\n");
 175                         return inode;
 176                 }
 177                 *NFS_FH(inode) = *fhandle;
 178                 nfs_refresh_inode(inode, fattr);
 179         }
 180         return inode;
 181 }
 182 
 183 int nfs_notify_change(int flags, struct inode *inode)
     /* [previous][next][first][last][top][bottom][index][help] */
 184 {
 185         struct nfs_sattr sattr;
 186         struct nfs_fattr fattr;
 187         int error;
 188 
 189         if (flags & NOTIFY_MODE)
 190                 sattr.mode = inode->i_mode;
 191         else
 192                 sattr.mode = -1;
 193         if (flags & NOTIFY_UIDGID) {
 194                 sattr.uid = inode->i_uid;
 195                 sattr.gid = inode->i_gid;
 196         }
 197         else
 198                 sattr.uid = sattr.gid = -1;
 199         if (flags & NOTIFY_SIZE)
 200                 sattr.size = S_ISREG(inode->i_mode) ? inode->i_size : -1;
 201         else
 202                 sattr.size = -1;
 203         if (flags & NOTIFY_TIME) {
 204                 sattr.mtime.seconds = inode->i_mtime;
 205                 sattr.mtime.useconds = 0;
 206                 sattr.atime.seconds = inode->i_atime;
 207                 sattr.atime.useconds = 0;
 208         }
 209         else {
 210                 sattr.mtime.seconds = sattr.mtime.useconds = -1;
 211                 sattr.atime.seconds = sattr.atime.useconds = -1;
 212         }
 213         error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
 214                 &sattr, &fattr);
 215         if (!error)
 216                 nfs_refresh_inode(inode, &fattr);
 217         inode->i_dirt = 0;
 218         return error;
 219 }
 220 

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