Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/nfs/proc.c
0004  *
0005  *  Copyright (C) 1992, 1993, 1994  Rick Sladkey
0006  *
0007  *  OS-independent nfs remote procedure call functions
0008  *
0009  *  Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers
0010  *  so at last we can have decent(ish) throughput off a 
0011  *  Sun server.
0012  *
0013  *  Coding optimized and cleaned up by Florian La Roche.
0014  *  Note: Error returns are optimized for NFS_OK, which isn't translated via
0015  *  nfs_stat_to_errno(), but happens to be already the right return code.
0016  *
0017  *  Also, the code currently doesn't check the size of the packet, when
0018  *  it decodes the packet.
0019  *
0020  *  Feel free to fix it and mail me the diffs if it worries you.
0021  *
0022  *  Completely rewritten to support the new RPC call interface;
0023  *  rewrote and moved the entire XDR stuff to xdr.c
0024  *  --Olaf Kirch June 1996
0025  *
0026  *  The code below initializes all auto variables explicitly, otherwise
0027  *  it will fail to work as a module (gcc generates a memset call for an
0028  *  incomplete struct).
0029  */
0030 
0031 #include <linux/types.h>
0032 #include <linux/param.h>
0033 #include <linux/time.h>
0034 #include <linux/mm.h>
0035 #include <linux/errno.h>
0036 #include <linux/string.h>
0037 #include <linux/in.h>
0038 #include <linux/pagemap.h>
0039 #include <linux/sunrpc/clnt.h>
0040 #include <linux/nfs.h>
0041 #include <linux/nfs2.h>
0042 #include <linux/nfs_fs.h>
0043 #include <linux/nfs_page.h>
0044 #include <linux/lockd/bind.h>
0045 #include <linux/freezer.h>
0046 #include "internal.h"
0047 
0048 #define NFSDBG_FACILITY     NFSDBG_PROC
0049 
0050 /*
0051  * Bare-bones access to getattr: this is for nfs_read_super.
0052  */
0053 static int
0054 nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
0055           struct nfs_fsinfo *info)
0056 {
0057     struct nfs_fattr *fattr = info->fattr;
0058     struct nfs2_fsstat fsinfo;
0059     struct rpc_message msg = {
0060         .rpc_proc   = &nfs_procedures[NFSPROC_GETATTR],
0061         .rpc_argp   = fhandle,
0062         .rpc_resp   = fattr,
0063     };
0064     int status;
0065 
0066     dprintk("%s: call getattr\n", __func__);
0067     nfs_fattr_init(fattr);
0068     status = rpc_call_sync(server->client, &msg, 0);
0069     /* Retry with default authentication if different */
0070     if (status && server->nfs_client->cl_rpcclient != server->client)
0071         status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
0072     dprintk("%s: reply getattr: %d\n", __func__, status);
0073     if (status)
0074         return status;
0075     dprintk("%s: call statfs\n", __func__);
0076     msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];
0077     msg.rpc_resp = &fsinfo;
0078     status = rpc_call_sync(server->client, &msg, 0);
0079     /* Retry with default authentication if different */
0080     if (status && server->nfs_client->cl_rpcclient != server->client)
0081         status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);
0082     dprintk("%s: reply statfs: %d\n", __func__, status);
0083     if (status)
0084         return status;
0085     info->rtmax  = NFS_MAXDATA;
0086     info->rtpref = fsinfo.tsize;
0087     info->rtmult = fsinfo.bsize;
0088     info->wtmax  = NFS_MAXDATA;
0089     info->wtpref = fsinfo.tsize;
0090     info->wtmult = fsinfo.bsize;
0091     info->dtpref = fsinfo.tsize;
0092     info->maxfilesize = 0x7FFFFFFF;
0093     info->lease_time = 0;
0094     info->change_attr_type = NFS4_CHANGE_TYPE_IS_UNDEFINED;
0095     info->xattr_support = 0;
0096     return 0;
0097 }
0098 
0099 /*
0100  * One function for each procedure in the NFS protocol.
0101  */
0102 static int
0103 nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
0104         struct nfs_fattr *fattr, struct inode *inode)
0105 {
0106     struct rpc_message msg = {
0107         .rpc_proc   = &nfs_procedures[NFSPROC_GETATTR],
0108         .rpc_argp   = fhandle,
0109         .rpc_resp   = fattr,
0110     };
0111     int status;
0112     unsigned short task_flags = 0;
0113 
0114     /* Is this is an attribute revalidation, subject to softreval? */
0115     if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
0116         task_flags |= RPC_TASK_TIMEOUT;
0117 
0118     dprintk("NFS call  getattr\n");
0119     nfs_fattr_init(fattr);
0120     status = rpc_call_sync(server->client, &msg, task_flags);
0121     dprintk("NFS reply getattr: %d\n", status);
0122     return status;
0123 }
0124 
0125 static int
0126 nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
0127          struct iattr *sattr)
0128 {
0129     struct inode *inode = d_inode(dentry);
0130     struct nfs_sattrargs    arg = { 
0131         .fh = NFS_FH(inode),
0132         .sattr  = sattr
0133     };
0134     struct rpc_message msg = {
0135         .rpc_proc   = &nfs_procedures[NFSPROC_SETATTR],
0136         .rpc_argp   = &arg,
0137         .rpc_resp   = fattr,
0138     };
0139     int status;
0140 
0141     /* Mask out the non-modebit related stuff from attr->ia_mode */
0142     sattr->ia_mode &= S_IALLUGO;
0143 
0144     dprintk("NFS call  setattr\n");
0145     if (sattr->ia_valid & ATTR_FILE)
0146         msg.rpc_cred = nfs_file_cred(sattr->ia_file);
0147     nfs_fattr_init(fattr);
0148     status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0149     if (status == 0)
0150         nfs_setattr_update_inode(inode, sattr, fattr);
0151     dprintk("NFS reply setattr: %d\n", status);
0152     return status;
0153 }
0154 
0155 static int
0156 nfs_proc_lookup(struct inode *dir, struct dentry *dentry,
0157         struct nfs_fh *fhandle, struct nfs_fattr *fattr)
0158 {
0159     struct nfs_diropargs    arg = {
0160         .fh     = NFS_FH(dir),
0161         .name       = dentry->d_name.name,
0162         .len        = dentry->d_name.len
0163     };
0164     struct nfs_diropok  res = {
0165         .fh     = fhandle,
0166         .fattr      = fattr
0167     };
0168     struct rpc_message msg = {
0169         .rpc_proc   = &nfs_procedures[NFSPROC_LOOKUP],
0170         .rpc_argp   = &arg,
0171         .rpc_resp   = &res,
0172     };
0173     int         status;
0174     unsigned short task_flags = 0;
0175 
0176     /* Is this is an attribute revalidation, subject to softreval? */
0177     if (nfs_lookup_is_soft_revalidate(dentry))
0178         task_flags |= RPC_TASK_TIMEOUT;
0179 
0180     dprintk("NFS call  lookup %pd2\n", dentry);
0181     nfs_fattr_init(fattr);
0182     status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
0183     dprintk("NFS reply lookup: %d\n", status);
0184     return status;
0185 }
0186 
0187 static int nfs_proc_readlink(struct inode *inode, struct page *page,
0188         unsigned int pgbase, unsigned int pglen)
0189 {
0190     struct nfs_readlinkargs args = {
0191         .fh     = NFS_FH(inode),
0192         .pgbase     = pgbase,
0193         .pglen      = pglen,
0194         .pages      = &page
0195     };
0196     struct rpc_message msg = {
0197         .rpc_proc   = &nfs_procedures[NFSPROC_READLINK],
0198         .rpc_argp   = &args,
0199     };
0200     int         status;
0201 
0202     dprintk("NFS call  readlink\n");
0203     status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0204     dprintk("NFS reply readlink: %d\n", status);
0205     return status;
0206 }
0207 
0208 struct nfs_createdata {
0209     struct nfs_createargs arg;
0210     struct nfs_diropok res;
0211     struct nfs_fh fhandle;
0212     struct nfs_fattr fattr;
0213 };
0214 
0215 static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
0216         struct dentry *dentry, struct iattr *sattr)
0217 {
0218     struct nfs_createdata *data;
0219 
0220     data = kmalloc(sizeof(*data), GFP_KERNEL);
0221 
0222     if (data != NULL) {
0223         data->arg.fh = NFS_FH(dir);
0224         data->arg.name = dentry->d_name.name;
0225         data->arg.len = dentry->d_name.len;
0226         data->arg.sattr = sattr;
0227         nfs_fattr_init(&data->fattr);
0228         data->fhandle.size = 0;
0229         data->res.fh = &data->fhandle;
0230         data->res.fattr = &data->fattr;
0231     }
0232     return data;
0233 };
0234 
0235 static void nfs_free_createdata(const struct nfs_createdata *data)
0236 {
0237     kfree(data);
0238 }
0239 
0240 static int
0241 nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
0242         int flags)
0243 {
0244     struct nfs_createdata *data;
0245     struct rpc_message msg = {
0246         .rpc_proc   = &nfs_procedures[NFSPROC_CREATE],
0247     };
0248     int status = -ENOMEM;
0249 
0250     dprintk("NFS call  create %pd\n", dentry);
0251     data = nfs_alloc_createdata(dir, dentry, sattr);
0252     if (data == NULL)
0253         goto out;
0254     msg.rpc_argp = &data->arg;
0255     msg.rpc_resp = &data->res;
0256     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0257     nfs_mark_for_revalidate(dir);
0258     if (status == 0)
0259         status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
0260     nfs_free_createdata(data);
0261 out:
0262     dprintk("NFS reply create: %d\n", status);
0263     return status;
0264 }
0265 
0266 /*
0267  * In NFSv2, mknod is grafted onto the create call.
0268  */
0269 static int
0270 nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
0271            dev_t rdev)
0272 {
0273     struct nfs_createdata *data;
0274     struct rpc_message msg = {
0275         .rpc_proc   = &nfs_procedures[NFSPROC_CREATE],
0276     };
0277     umode_t mode;
0278     int status = -ENOMEM;
0279 
0280     dprintk("NFS call  mknod %pd\n", dentry);
0281 
0282     mode = sattr->ia_mode;
0283     if (S_ISFIFO(mode)) {
0284         sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;
0285         sattr->ia_valid &= ~ATTR_SIZE;
0286     } else if (S_ISCHR(mode) || S_ISBLK(mode)) {
0287         sattr->ia_valid |= ATTR_SIZE;
0288         sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
0289     }
0290 
0291     data = nfs_alloc_createdata(dir, dentry, sattr);
0292     if (data == NULL)
0293         goto out;
0294     msg.rpc_argp = &data->arg;
0295     msg.rpc_resp = &data->res;
0296 
0297     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0298     nfs_mark_for_revalidate(dir);
0299 
0300     if (status == -EINVAL && S_ISFIFO(mode)) {
0301         sattr->ia_mode = mode;
0302         nfs_fattr_init(data->res.fattr);
0303         status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0304     }
0305     if (status == 0)
0306         status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
0307     nfs_free_createdata(data);
0308 out:
0309     dprintk("NFS reply mknod: %d\n", status);
0310     return status;
0311 }
0312   
0313 static int
0314 nfs_proc_remove(struct inode *dir, struct dentry *dentry)
0315 {
0316     struct nfs_removeargs arg = {
0317         .fh = NFS_FH(dir),
0318         .name = dentry->d_name,
0319     };
0320     struct rpc_message msg = { 
0321         .rpc_proc = &nfs_procedures[NFSPROC_REMOVE],
0322         .rpc_argp = &arg,
0323     };
0324     int         status;
0325 
0326     dprintk("NFS call  remove %pd2\n",dentry);
0327     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0328     nfs_mark_for_revalidate(dir);
0329 
0330     dprintk("NFS reply remove: %d\n", status);
0331     return status;
0332 }
0333 
0334 static void
0335 nfs_proc_unlink_setup(struct rpc_message *msg,
0336         struct dentry *dentry,
0337         struct inode *inode)
0338 {
0339     msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
0340 }
0341 
0342 static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
0343 {
0344     rpc_call_start(task);
0345 }
0346 
0347 static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
0348 {
0349     nfs_mark_for_revalidate(dir);
0350     return 1;
0351 }
0352 
0353 static void
0354 nfs_proc_rename_setup(struct rpc_message *msg,
0355         struct dentry *old_dentry,
0356         struct dentry *new_dentry)
0357 {
0358     msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
0359 }
0360 
0361 static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
0362 {
0363     rpc_call_start(task);
0364 }
0365 
0366 static int
0367 nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
0368              struct inode *new_dir)
0369 {
0370     nfs_mark_for_revalidate(old_dir);
0371     nfs_mark_for_revalidate(new_dir);
0372     return 1;
0373 }
0374 
0375 static int
0376 nfs_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
0377 {
0378     struct nfs_linkargs arg = {
0379         .fromfh     = NFS_FH(inode),
0380         .tofh       = NFS_FH(dir),
0381         .toname     = name->name,
0382         .tolen      = name->len
0383     };
0384     struct rpc_message msg = {
0385         .rpc_proc   = &nfs_procedures[NFSPROC_LINK],
0386         .rpc_argp   = &arg,
0387     };
0388     int         status;
0389 
0390     dprintk("NFS call  link %s\n", name->name);
0391     status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
0392     nfs_mark_for_revalidate(inode);
0393     nfs_mark_for_revalidate(dir);
0394     dprintk("NFS reply link: %d\n", status);
0395     return status;
0396 }
0397 
0398 static int
0399 nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
0400          unsigned int len, struct iattr *sattr)
0401 {
0402     struct nfs_fh *fh;
0403     struct nfs_fattr *fattr;
0404     struct nfs_symlinkargs  arg = {
0405         .fromfh     = NFS_FH(dir),
0406         .fromname   = dentry->d_name.name,
0407         .fromlen    = dentry->d_name.len,
0408         .pages      = &page,
0409         .pathlen    = len,
0410         .sattr      = sattr
0411     };
0412     struct rpc_message msg = {
0413         .rpc_proc   = &nfs_procedures[NFSPROC_SYMLINK],
0414         .rpc_argp   = &arg,
0415     };
0416     int status = -ENAMETOOLONG;
0417 
0418     dprintk("NFS call  symlink %pd\n", dentry);
0419 
0420     if (len > NFS2_MAXPATHLEN)
0421         goto out;
0422 
0423     fh = nfs_alloc_fhandle();
0424     fattr = nfs_alloc_fattr();
0425     status = -ENOMEM;
0426     if (fh == NULL || fattr == NULL)
0427         goto out_free;
0428 
0429     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0430     nfs_mark_for_revalidate(dir);
0431 
0432     /*
0433      * V2 SYMLINK requests don't return any attributes.  Setting the
0434      * filehandle size to zero indicates to nfs_instantiate that it
0435      * should fill in the data with a LOOKUP call on the wire.
0436      */
0437     if (status == 0)
0438         status = nfs_instantiate(dentry, fh, fattr);
0439 
0440 out_free:
0441     nfs_free_fattr(fattr);
0442     nfs_free_fhandle(fh);
0443 out:
0444     dprintk("NFS reply symlink: %d\n", status);
0445     return status;
0446 }
0447 
0448 static int
0449 nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
0450 {
0451     struct nfs_createdata *data;
0452     struct rpc_message msg = {
0453         .rpc_proc   = &nfs_procedures[NFSPROC_MKDIR],
0454     };
0455     int status = -ENOMEM;
0456 
0457     dprintk("NFS call  mkdir %pd\n", dentry);
0458     data = nfs_alloc_createdata(dir, dentry, sattr);
0459     if (data == NULL)
0460         goto out;
0461     msg.rpc_argp = &data->arg;
0462     msg.rpc_resp = &data->res;
0463 
0464     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0465     nfs_mark_for_revalidate(dir);
0466     if (status == 0)
0467         status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
0468     nfs_free_createdata(data);
0469 out:
0470     dprintk("NFS reply mkdir: %d\n", status);
0471     return status;
0472 }
0473 
0474 static int
0475 nfs_proc_rmdir(struct inode *dir, const struct qstr *name)
0476 {
0477     struct nfs_diropargs    arg = {
0478         .fh     = NFS_FH(dir),
0479         .name       = name->name,
0480         .len        = name->len
0481     };
0482     struct rpc_message msg = {
0483         .rpc_proc   = &nfs_procedures[NFSPROC_RMDIR],
0484         .rpc_argp   = &arg,
0485     };
0486     int         status;
0487 
0488     dprintk("NFS call  rmdir %s\n", name->name);
0489     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0490     nfs_mark_for_revalidate(dir);
0491     dprintk("NFS reply rmdir: %d\n", status);
0492     return status;
0493 }
0494 
0495 /*
0496  * The READDIR implementation is somewhat hackish - we pass a temporary
0497  * buffer to the encode function, which installs it in the receive
0498  * the receive iovec. The decode function just parses the reply to make
0499  * sure it is syntactically correct; the entries itself are decoded
0500  * from nfs_readdir by calling the decode_entry function directly.
0501  */
0502 static int nfs_proc_readdir(struct nfs_readdir_arg *nr_arg,
0503                 struct nfs_readdir_res *nr_res)
0504 {
0505     struct inode        *dir = d_inode(nr_arg->dentry);
0506     struct nfs_readdirargs  arg = {
0507         .fh     = NFS_FH(dir),
0508         .cookie     = nr_arg->cookie,
0509         .count      = nr_arg->page_len,
0510         .pages      = nr_arg->pages,
0511     };
0512     struct rpc_message  msg = {
0513         .rpc_proc   = &nfs_procedures[NFSPROC_READDIR],
0514         .rpc_argp   = &arg,
0515         .rpc_cred   = nr_arg->cred,
0516     };
0517     int         status;
0518 
0519     dprintk("NFS call  readdir %llu\n", (unsigned long long)nr_arg->cookie);
0520     status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
0521     nr_res->verf[0] = nr_res->verf[1] = 0;
0522 
0523     nfs_invalidate_atime(dir);
0524 
0525     dprintk("NFS reply readdir: %d\n", status);
0526     return status;
0527 }
0528 
0529 static int
0530 nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
0531             struct nfs_fsstat *stat)
0532 {
0533     struct nfs2_fsstat fsinfo;
0534     struct rpc_message msg = {
0535         .rpc_proc   = &nfs_procedures[NFSPROC_STATFS],
0536         .rpc_argp   = fhandle,
0537         .rpc_resp   = &fsinfo,
0538     };
0539     int status;
0540 
0541     dprintk("NFS call  statfs\n");
0542     nfs_fattr_init(stat->fattr);
0543     status = rpc_call_sync(server->client, &msg, 0);
0544     dprintk("NFS reply statfs: %d\n", status);
0545     if (status)
0546         goto out;
0547     stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize;
0548     stat->fbytes = (u64)fsinfo.bfree  * fsinfo.bsize;
0549     stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize;
0550     stat->tfiles = 0;
0551     stat->ffiles = 0;
0552     stat->afiles = 0;
0553 out:
0554     return status;
0555 }
0556 
0557 static int
0558 nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
0559             struct nfs_fsinfo *info)
0560 {
0561     struct nfs2_fsstat fsinfo;
0562     struct rpc_message msg = {
0563         .rpc_proc   = &nfs_procedures[NFSPROC_STATFS],
0564         .rpc_argp   = fhandle,
0565         .rpc_resp   = &fsinfo,
0566     };
0567     int status;
0568 
0569     dprintk("NFS call  fsinfo\n");
0570     nfs_fattr_init(info->fattr);
0571     status = rpc_call_sync(server->client, &msg, 0);
0572     dprintk("NFS reply fsinfo: %d\n", status);
0573     if (status)
0574         goto out;
0575     info->rtmax  = NFS_MAXDATA;
0576     info->rtpref = fsinfo.tsize;
0577     info->rtmult = fsinfo.bsize;
0578     info->wtmax  = NFS_MAXDATA;
0579     info->wtpref = fsinfo.tsize;
0580     info->wtmult = fsinfo.bsize;
0581     info->dtpref = fsinfo.tsize;
0582     info->maxfilesize = 0x7FFFFFFF;
0583     info->lease_time = 0;
0584 out:
0585     return status;
0586 }
0587 
0588 static int
0589 nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
0590           struct nfs_pathconf *info)
0591 {
0592     info->max_link = 0;
0593     info->max_namelen = NFS2_MAXNAMLEN;
0594     return 0;
0595 }
0596 
0597 static int nfs_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
0598 {
0599     struct inode *inode = hdr->inode;
0600 
0601     nfs_invalidate_atime(inode);
0602     if (task->tk_status >= 0) {
0603         nfs_refresh_inode(inode, hdr->res.fattr);
0604         /* Emulate the eof flag, which isn't normally needed in NFSv2
0605          * as it is guaranteed to always return the file attributes
0606          */
0607         if ((hdr->res.count == 0 && hdr->args.count > 0) ||
0608             hdr->args.offset + hdr->res.count >= hdr->res.fattr->size)
0609             hdr->res.eof = 1;
0610     }
0611     return 0;
0612 }
0613 
0614 static void nfs_proc_read_setup(struct nfs_pgio_header *hdr,
0615                 struct rpc_message *msg)
0616 {
0617     msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
0618 }
0619 
0620 static int nfs_proc_pgio_rpc_prepare(struct rpc_task *task,
0621                      struct nfs_pgio_header *hdr)
0622 {
0623     rpc_call_start(task);
0624     return 0;
0625 }
0626 
0627 static int nfs_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
0628 {
0629     if (task->tk_status >= 0) {
0630         hdr->res.count = hdr->args.count;
0631         nfs_writeback_update_inode(hdr);
0632     }
0633     return 0;
0634 }
0635 
0636 static void nfs_proc_write_setup(struct nfs_pgio_header *hdr,
0637                  struct rpc_message *msg,
0638                  struct rpc_clnt **clnt)
0639 {
0640     /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */
0641     hdr->args.stable = NFS_FILE_SYNC;
0642     msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
0643 }
0644 
0645 static void nfs_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
0646 {
0647     BUG();
0648 }
0649 
0650 static void
0651 nfs_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
0652             struct rpc_clnt **clnt)
0653 {
0654     BUG();
0655 }
0656 
0657 static int
0658 nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
0659 {
0660     struct inode *inode = file_inode(filp);
0661 
0662     return nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, NULL);
0663 }
0664 
0665 /* Helper functions for NFS lock bounds checking */
0666 #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
0667 static int nfs_lock_check_bounds(const struct file_lock *fl)
0668 {
0669     __s32 start, end;
0670 
0671     start = (__s32)fl->fl_start;
0672     if ((loff_t)start != fl->fl_start)
0673         goto out_einval;
0674 
0675     if (fl->fl_end != OFFSET_MAX) {
0676         end = (__s32)fl->fl_end;
0677         if ((loff_t)end != fl->fl_end)
0678             goto out_einval;
0679     } else
0680         end = NFS_LOCK32_OFFSET_MAX;
0681 
0682     if (start < 0 || start > end)
0683         goto out_einval;
0684     return 0;
0685 out_einval:
0686     return -EINVAL;
0687 }
0688 
0689 static int nfs_have_delegation(struct inode *inode, fmode_t flags)
0690 {
0691     return 0;
0692 }
0693 
0694 static const struct inode_operations nfs_dir_inode_operations = {
0695     .create     = nfs_create,
0696     .lookup     = nfs_lookup,
0697     .link       = nfs_link,
0698     .unlink     = nfs_unlink,
0699     .symlink    = nfs_symlink,
0700     .mkdir      = nfs_mkdir,
0701     .rmdir      = nfs_rmdir,
0702     .mknod      = nfs_mknod,
0703     .rename     = nfs_rename,
0704     .permission = nfs_permission,
0705     .getattr    = nfs_getattr,
0706     .setattr    = nfs_setattr,
0707 };
0708 
0709 static const struct inode_operations nfs_file_inode_operations = {
0710     .permission = nfs_permission,
0711     .getattr    = nfs_getattr,
0712     .setattr    = nfs_setattr,
0713 };
0714 
0715 const struct nfs_rpc_ops nfs_v2_clientops = {
0716     .version    = 2,               /* protocol version */
0717     .dentry_ops = &nfs_dentry_operations,
0718     .dir_inode_ops  = &nfs_dir_inode_operations,
0719     .file_inode_ops = &nfs_file_inode_operations,
0720     .file_ops   = &nfs_file_operations,
0721     .getroot    = nfs_proc_get_root,
0722     .submount   = nfs_submount,
0723     .try_get_tree   = nfs_try_get_tree,
0724     .getattr    = nfs_proc_getattr,
0725     .setattr    = nfs_proc_setattr,
0726     .lookup     = nfs_proc_lookup,
0727     .access     = NULL,            /* access */
0728     .readlink   = nfs_proc_readlink,
0729     .create     = nfs_proc_create,
0730     .remove     = nfs_proc_remove,
0731     .unlink_setup   = nfs_proc_unlink_setup,
0732     .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
0733     .unlink_done    = nfs_proc_unlink_done,
0734     .rename_setup   = nfs_proc_rename_setup,
0735     .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
0736     .rename_done    = nfs_proc_rename_done,
0737     .link       = nfs_proc_link,
0738     .symlink    = nfs_proc_symlink,
0739     .mkdir      = nfs_proc_mkdir,
0740     .rmdir      = nfs_proc_rmdir,
0741     .readdir    = nfs_proc_readdir,
0742     .mknod      = nfs_proc_mknod,
0743     .statfs     = nfs_proc_statfs,
0744     .fsinfo     = nfs_proc_fsinfo,
0745     .pathconf   = nfs_proc_pathconf,
0746     .decode_dirent  = nfs2_decode_dirent,
0747     .pgio_rpc_prepare = nfs_proc_pgio_rpc_prepare,
0748     .read_setup = nfs_proc_read_setup,
0749     .read_done  = nfs_read_done,
0750     .write_setup    = nfs_proc_write_setup,
0751     .write_done = nfs_write_done,
0752     .commit_setup   = nfs_proc_commit_setup,
0753     .commit_rpc_prepare = nfs_proc_commit_rpc_prepare,
0754     .lock       = nfs_proc_lock,
0755     .lock_check_bounds = nfs_lock_check_bounds,
0756     .close_context  = nfs_close_context,
0757     .have_delegation = nfs_have_delegation,
0758     .alloc_client   = nfs_alloc_client,
0759     .init_client    = nfs_init_client,
0760     .free_client    = nfs_free_client,
0761     .create_server  = nfs_create_server,
0762     .clone_server   = nfs_clone_server,
0763 };