linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / nfs / proc.c
index 8dc6a98..f5150d7 100644 (file)
 
 extern struct rpc_procinfo nfs_procedures[];
 
-static struct rpc_cred *
-nfs_cred(struct inode *inode, struct file *filp)
-{
-       struct rpc_cred *cred = NULL;
-
-       if (filp)
-               cred = (struct rpc_cred *)filp->private_data;
-       if (!cred)
-               cred = NFS_I(inode)->mm_cred;
-       return cred;
-}
-
 /*
  * Bare-bones access to getattr: this is for nfs_read_super.
  */
@@ -73,14 +61,14 @@ nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
        int status;
 
        dprintk("%s: call getattr\n", __FUNCTION__);
-       fattr->valid = 0;
+       nfs_fattr_init(fattr);
        status = rpc_call(server->client_sys, NFSPROC_GETATTR, fhandle, fattr, 0);
-       dprintk("%s: reply getattr %d\n", __FUNCTION__, status);
+       dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);
        if (status)
                return status;
        dprintk("%s: call statfs\n", __FUNCTION__);
        status = rpc_call(server->client_sys, NFSPROC_STATFS, fhandle, &fsinfo, 0);
-       dprintk("%s: reply statfs %d\n", __FUNCTION__, status);
+       dprintk("%s: reply statfs: %d\n", __FUNCTION__, status);
        if (status)
                return status;
        info->rtmax  = NFS_MAXDATA;
@@ -99,15 +87,16 @@ nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
  * One function for each procedure in the NFS protocol.
  */
 static int
-nfs_proc_getattr(struct inode *inode, struct nfs_fattr *fattr)
+nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
+               struct nfs_fattr *fattr)
 {
        int     status;
 
        dprintk("NFS call  getattr\n");
-       fattr->valid = 0;
-       status = rpc_call(NFS_CLIENT(inode), NFSPROC_GETATTR,
-                               NFS_FH(inode), fattr, 0);
-       dprintk("NFS reply getattr\n");
+       nfs_fattr_init(fattr);
+       status = rpc_call(server->client, NFSPROC_GETATTR,
+                               fhandle, fattr, 0);
+       dprintk("NFS reply getattr: %d\n", status);
        return status;
 }
 
@@ -122,10 +111,15 @@ nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
        };
        int     status;
 
+       /* Mask out the non-modebit related stuff from attr->ia_mode */
+       sattr->ia_mode &= S_IALLUGO;
+
        dprintk("NFS call  setattr\n");
-       fattr->valid = 0;
+       nfs_fattr_init(fattr);
        status = rpc_call(NFS_CLIENT(inode), NFSPROC_SETATTR, &arg, fattr, 0);
-       dprintk("NFS reply setattr\n");
+       if (status == 0)
+               nfs_setattr_update_inode(inode, sattr);
+       dprintk("NFS reply setattr: %d\n", status);
        return status;
 }
 
@@ -145,18 +139,19 @@ nfs_proc_lookup(struct inode *dir, struct qstr *name,
        int                     status;
 
        dprintk("NFS call  lookup %s\n", name->name);
-       fattr->valid = 0;
+       nfs_fattr_init(fattr);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_LOOKUP, &arg, &res, 0);
        dprintk("NFS reply lookup: %d\n", status);
        return status;
 }
 
-static int
-nfs_proc_readlink(struct inode *inode, struct page *page)
+static int nfs_proc_readlink(struct inode *inode, struct page *page,
+               unsigned int pgbase, unsigned int pglen)
 {
        struct nfs_readlinkargs args = {
                .fh             = NFS_FH(inode),
-               .count          = PAGE_CACHE_SIZE,
+               .pgbase         = pgbase,
+               .pglen          = pglen,
                .pages          = &page
        };
        int                     status;
@@ -167,8 +162,7 @@ nfs_proc_readlink(struct inode *inode, struct page *page)
        return status;
 }
 
-static int
-nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
+static int nfs_proc_read(struct nfs_read_data *rdata)
 {
        int                     flags = rdata->flags;
        struct inode *          inode = rdata->inode;
@@ -177,15 +171,14 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
                .rpc_proc       = &nfs_procedures[NFSPROC_READ],
                .rpc_argp       = &rdata->args,
                .rpc_resp       = &rdata->res,
+               .rpc_cred       = rdata->cred,
        };
        int                     status;
 
        dprintk("NFS call  read %d @ %Ld\n", rdata->args.count,
                        (long long) rdata->args.offset);
-       fattr->valid = 0;
-       msg.rpc_cred = nfs_cred(inode, filp);
+       nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
-
        if (status >= 0) {
                nfs_refresh_inode(inode, fattr);
                /* Emulate the eof flag, which isn't normally needed in NFSv2
@@ -198,8 +191,7 @@ nfs_proc_read(struct nfs_read_data *rdata, struct file *filp)
        return status;
 }
 
-static int
-nfs_proc_write(struct nfs_write_data *wdata, struct file *filp)
+static int nfs_proc_write(struct nfs_write_data *wdata)
 {
        int                     flags = wdata->flags;
        struct inode *          inode = wdata->inode;
@@ -208,16 +200,16 @@ nfs_proc_write(struct nfs_write_data *wdata, struct file *filp)
                .rpc_proc       = &nfs_procedures[NFSPROC_WRITE],
                .rpc_argp       = &wdata->args,
                .rpc_resp       = &wdata->res,
+               .rpc_cred       = wdata->cred,
        };
        int                     status;
 
        dprintk("NFS call  write %d @ %Ld\n", wdata->args.count,
                        (long long) wdata->args.offset);
-       fattr->valid = 0;
-       msg.rpc_cred = nfs_cred(inode, filp);
+       nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
        if (status >= 0) {
-               nfs_refresh_inode(inode, fattr);
+               nfs_post_op_update_inode(inode, fattr);
                wdata->res.count = wdata->args.count;
                wdata->verf.committed = NFS_FILE_SYNC;
        }
@@ -225,16 +217,16 @@ nfs_proc_write(struct nfs_write_data *wdata, struct file *filp)
        return status < 0? status : wdata->res.count;
 }
 
-static struct inode *
-nfs_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
-               int flags)
+static int
+nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
+               int flags, struct nameidata *nd)
 {
        struct nfs_fh           fhandle;
        struct nfs_fattr        fattr;
        struct nfs_createargs   arg = {
                .fh             = NFS_FH(dir),
-               .name           = name->name,
-               .len            = name->len,
+               .name           = dentry->d_name.name,
+               .len            = dentry->d_name.len,
                .sattr          = sattr
        };
        struct nfs_diropok      res = {
@@ -243,40 +235,37 @@ nfs_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,
        };
        int                     status;
 
-       fattr.valid = 0;
-       dprintk("NFS call  create %s\n", name->name);
+       nfs_fattr_init(&fattr);
+       dprintk("NFS call  create %s\n", dentry->d_name.name);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
+       if (status == 0)
+               status = nfs_instantiate(dentry, &fhandle, &fattr);
        dprintk("NFS reply create: %d\n", status);
-       if (status == 0) {
-               struct inode *inode;
-               inode = nfs_fhget(dir->i_sb, &fhandle, &fattr);
-               if (inode)
-                       return inode;
-               status = -ENOMEM;
-       }
-       return ERR_PTR(status);
+       return status;
 }
 
 /*
  * In NFSv2, mknod is grafted onto the create call.
  */
 static int
-nfs_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
-              dev_t rdev, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
+nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
+              dev_t rdev)
 {
+       struct nfs_fh fhandle;
+       struct nfs_fattr fattr;
        struct nfs_createargs   arg = {
                .fh             = NFS_FH(dir),
-               .name           = name->name,
-               .len            = name->len,
+               .name           = dentry->d_name.name,
+               .len            = dentry->d_name.len,
                .sattr          = sattr
        };
        struct nfs_diropok      res = {
-               .fh             = fhandle,
-               .fattr          = fattr
+               .fh             = &fhandle,
+               .fattr          = &fattr
        };
-       int                     status, mode;
+       int status, mode;
 
-       dprintk("NFS call  mknod %s\n", name->name);
+       dprintk("NFS call  mknod %s\n", dentry->d_name.name);
 
        mode = sattr->ia_mode;
        if (S_ISFIFO(mode)) {
@@ -287,14 +276,17 @@ nfs_proc_mknod(struct inode *dir, struct qstr *name, struct iattr *sattr,
                sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
        }
 
-       fattr->valid = 0;
+       nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
+       nfs_mark_for_revalidate(dir);
 
        if (status == -EINVAL && S_ISFIFO(mode)) {
                sattr->ia_mode = mode;
-               fattr->valid = 0;
+               nfs_fattr_init(&fattr);
                status = rpc_call(NFS_CLIENT(dir), NFSPROC_CREATE, &arg, &res, 0);
        }
+       if (status == 0)
+               status = nfs_instantiate(dentry, &fhandle, &fattr);
        dprintk("NFS reply mknod: %d\n", status);
        return status;
 }
@@ -317,6 +309,7 @@ nfs_proc_remove(struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  remove %s\n", name->name);
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
+       nfs_mark_for_revalidate(dir);
 
        dprintk("NFS reply remove: %d\n", status);
        return status;
@@ -343,8 +336,10 @@ nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
 {
        struct rpc_message *msg = &task->tk_msg;
        
-       if (msg->rpc_argp)
+       if (msg->rpc_argp) {
+               nfs_mark_for_revalidate(dir->d_inode);
                kfree(msg->rpc_argp);
+       }
        return 0;
 }
 
@@ -364,6 +359,8 @@ nfs_proc_rename(struct inode *old_dir, struct qstr *old_name,
 
        dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);
        status = rpc_call(NFS_CLIENT(old_dir), NFSPROC_RENAME, &arg, NULL, 0);
+       nfs_mark_for_revalidate(old_dir);
+       nfs_mark_for_revalidate(new_dir);
        dprintk("NFS reply rename: %d\n", status);
        return status;
 }
@@ -381,6 +378,8 @@ nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  link %s\n", name->name);
        status = rpc_call(NFS_CLIENT(inode), NFSPROC_LINK, &arg, NULL, 0);
+       nfs_mark_for_revalidate(inode);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply link: %d\n", status);
        return status;
 }
@@ -400,32 +399,40 @@ nfs_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path,
        };
        int                     status;
 
+       if (path->len > NFS2_MAXPATHLEN)
+               return -ENAMETOOLONG;
        dprintk("NFS call  symlink %s -> %s\n", name->name, path->name);
-       fattr->valid = 0;
+       nfs_fattr_init(fattr);
+       fhandle->size = 0;
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_SYMLINK, &arg, NULL, 0);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply symlink: %d\n", status);
        return status;
 }
 
 static int
-nfs_proc_mkdir(struct inode *dir, struct qstr *name, struct iattr *sattr,
-              struct nfs_fh *fhandle, struct nfs_fattr *fattr)
+nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
 {
+       struct nfs_fh fhandle;
+       struct nfs_fattr fattr;
        struct nfs_createargs   arg = {
                .fh             = NFS_FH(dir),
-               .name           = name->name,
-               .len            = name->len,
+               .name           = dentry->d_name.name,
+               .len            = dentry->d_name.len,
                .sattr          = sattr
        };
        struct nfs_diropok      res = {
-               .fh             = fhandle,
-               .fattr          = fattr
+               .fh             = &fhandle,
+               .fattr          = &fattr
        };
        int                     status;
 
-       dprintk("NFS call  mkdir %s\n", name->name);
-       fattr->valid = 0;
+       dprintk("NFS call  mkdir %s\n", dentry->d_name.name);
+       nfs_fattr_init(&fattr);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_MKDIR, &arg, &res, 0);
+       nfs_mark_for_revalidate(dir);
+       if (status == 0)
+               status = nfs_instantiate(dentry, &fhandle, &fattr);
        dprintk("NFS reply mkdir: %d\n", status);
        return status;
 }
@@ -442,6 +449,7 @@ nfs_proc_rmdir(struct inode *dir, struct qstr *name)
 
        dprintk("NFS call  rmdir %s\n", name->name);
        status = rpc_call(NFS_CLIENT(dir), NFSPROC_RMDIR, &arg, NULL, 0);
+       nfs_mark_for_revalidate(dir);
        dprintk("NFS reply rmdir: %d\n", status);
        return status;
 }
@@ -490,7 +498,7 @@ nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
        int     status;
 
        dprintk("NFS call  statfs\n");
-       stat->fattr->valid = 0;
+       nfs_fattr_init(stat->fattr);
        status = rpc_call(server->client, NFSPROC_STATFS, fhandle, &fsinfo, 0);
        dprintk("NFS reply statfs: %d\n", status);
        if (status)
@@ -513,7 +521,7 @@ nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
        int     status;
 
        dprintk("NFS call  fsinfo\n");
-       info->fattr->valid = 0;
+       nfs_fattr_init(info->fattr);
        status = rpc_call(server->client, NFSPROC_STATFS, fhandle, &fsinfo, 0);
        dprintk("NFS reply fsinfo: %d\n", status);
        if (status)
@@ -542,10 +550,9 @@ nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
 
 extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
 
-static void
-nfs_read_done(struct rpc_task *task)
+static void nfs_read_done(struct rpc_task *task, void *calldata)
 {
-       struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
+       struct nfs_read_data *data = calldata;
 
        if (task->tk_status >= 0) {
                nfs_refresh_inode(data->inode, data->res.fattr);
@@ -555,9 +562,14 @@ nfs_read_done(struct rpc_task *task)
                if (data->args.offset + data->args.count >= data->res.fattr->size)
                        data->res.eof = 1;
        }
-       nfs_readpage_result(task);
+       nfs_readpage_result(task, calldata);
 }
 
+static const struct rpc_call_ops nfs_read_ops = {
+       .rpc_call_done = nfs_read_done,
+       .rpc_release = nfs_readdata_release,
+};
+
 static void
 nfs_proc_read_setup(struct nfs_read_data *data)
 {
@@ -575,20 +587,24 @@ nfs_proc_read_setup(struct nfs_read_data *data)
        flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
 
        /* Finalize the task. */
-       rpc_init_task(task, NFS_CLIENT(inode), nfs_read_done, flags);
+       rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs_read_ops, data);
        rpc_call_setup(task, &msg, 0);
 }
 
-static void
-nfs_write_done(struct rpc_task *task)
+static void nfs_write_done(struct rpc_task *task, void *calldata)
 {
-       struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
+       struct nfs_write_data *data = calldata;
 
        if (task->tk_status >= 0)
-               nfs_refresh_inode(data->inode, data->res.fattr);
-       nfs_writeback_done(task);
+               nfs_post_op_update_inode(data->inode, data->res.fattr);
+       nfs_writeback_done(task, calldata);
 }
 
+static const struct rpc_call_ops nfs_write_ops = {
+       .rpc_call_done = nfs_write_done,
+       .rpc_release = nfs_writedata_release,
+};
+
 static void
 nfs_proc_write_setup(struct nfs_write_data *data, int how)
 {
@@ -609,7 +625,7 @@ nfs_proc_write_setup(struct nfs_write_data *data, int how)
        flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
 
        /* Finalize the task. */
-       rpc_init_task(task, NFS_CLIENT(inode), nfs_write_done, flags);
+       rpc_init_task(task, NFS_CLIENT(inode), flags, &nfs_write_ops, data);
        rpc_call_setup(task, &msg, 0);
 }
 
@@ -619,27 +635,6 @@ nfs_proc_commit_setup(struct nfs_write_data *data, int how)
        BUG();
 }
 
-/*
- * Set up the nfspage struct with the right credentials
- */
-static void
-nfs_request_init(struct nfs_page *req, struct file *filp)
-{
-       req->wb_cred = get_rpccred(nfs_cred(req->wb_inode, filp));
-}
-
-static int
-nfs_request_compatible(struct nfs_page *req, struct file *filp, struct page *page)
-{
-       if (req->wb_file != filp)
-               return 0;
-       if (req->wb_page != page)
-               return 0;
-       if (req->wb_cred != nfs_file_cred(filp))
-               return 0;
-       return 1;
-}
-
 static int
 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
 {
@@ -651,6 +646,7 @@ struct nfs_rpc_ops  nfs_v2_clientops = {
        .version        = 2,                   /* protocol version */
        .dentry_ops     = &nfs_dentry_operations,
        .dir_inode_ops  = &nfs_dir_inode_operations,
+       .file_inode_ops = &nfs_file_inode_operations,
        .getroot        = nfs_proc_get_root,
        .getattr        = nfs_proc_getattr,
        .setattr        = nfs_proc_setattr,
@@ -680,7 +676,5 @@ struct nfs_rpc_ops  nfs_v2_clientops = {
        .commit_setup   = nfs_proc_commit_setup,
        .file_open      = nfs_open,
        .file_release   = nfs_release,
-       .request_init   = nfs_request_init,
-       .request_compatible = nfs_request_compatible,
        .lock           = nfs_proc_lock,
 };