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

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