1 // SPDX-License-Identifier: GPL-2.0
3 * linux/fs/nfs/nfs3proc.c
5 * Client-side NFSv3 procedures stubs.
7 * Copyright (C) 1997, Olaf Kirch
11 #include <linux/errno.h>
12 #include <linux/string.h>
13 #include <linux/sunrpc/clnt.h>
14 #include <linux/slab.h>
15 #include <linux/nfs.h>
16 #include <linux/nfs3.h>
17 #include <linux/nfs_fs.h>
18 #include <linux/nfs_page.h>
19 #include <linux/lockd/bind.h>
20 #include <linux/nfs_mount.h>
21 #include <linux/freezer.h>
22 #include <linux/xattr.h>
28 #define NFSDBG_FACILITY NFSDBG_PROC
30 /* A wrapper to handle the EJUKEBOX error messages */
32 nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags)
36 res = rpc_call_sync(clnt, msg, flags);
39 freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME);
41 } while (!fatal_signal_pending(current));
45 #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags)
48 nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode)
50 if (task->tk_status != -EJUKEBOX)
52 nfs_inc_stats(inode, NFSIOS_DELAY);
54 rpc_restart_call(task);
55 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
60 do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
61 struct nfs_fsinfo *info)
63 struct rpc_message msg = {
64 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
70 dprintk("%s: call fsinfo\n", __func__);
71 nfs_fattr_init(info->fattr);
72 status = rpc_call_sync(client, &msg, 0);
73 dprintk("%s: reply fsinfo: %d\n", __func__, status);
74 if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) {
75 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
76 msg.rpc_resp = info->fattr;
77 status = rpc_call_sync(client, &msg, 0);
78 dprintk("%s: reply getattr: %d\n", __func__, status);
84 * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
87 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
88 struct nfs_fsinfo *info)
92 status = do_proc_get_root(server->client, fhandle, info);
93 if (status && server->nfs_client->cl_rpcclient != server->client)
94 status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
99 * One function for each procedure in the NFS protocol.
102 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
103 struct nfs_fattr *fattr, struct inode *inode)
105 struct rpc_message msg = {
106 .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
111 unsigned short task_flags = 0;
113 /* Is this is an attribute revalidation, subject to softreval? */
114 if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
115 task_flags |= RPC_TASK_TIMEOUT;
117 dprintk("NFS call getattr\n");
118 nfs_fattr_init(fattr);
119 status = rpc_call_sync(server->client, &msg, task_flags);
120 dprintk("NFS reply getattr: %d\n", status);
125 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
128 struct inode *inode = d_inode(dentry);
129 struct nfs3_sattrargs arg = {
133 struct rpc_message msg = {
134 .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
140 dprintk("NFS call setattr\n");
141 if (sattr->ia_valid & ATTR_FILE)
142 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
143 nfs_fattr_init(fattr);
144 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
146 nfs_setattr_update_inode(inode, sattr, fattr);
147 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
148 nfs_zap_acl_cache(inode);
150 dprintk("NFS reply setattr: %d\n", status);
155 __nfs3_proc_lookup(struct inode *dir, const char *name, size_t len,
156 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
157 unsigned short task_flags)
159 struct nfs3_diropargs arg = {
164 struct nfs3_diropres res = {
168 struct rpc_message msg = {
169 .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
175 res.dir_attr = nfs_alloc_fattr();
176 if (res.dir_attr == NULL)
179 nfs_fattr_init(fattr);
180 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
181 nfs_refresh_inode(dir, res.dir_attr);
182 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
183 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
184 msg.rpc_argp = fhandle;
185 msg.rpc_resp = fattr;
186 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
188 nfs_free_fattr(res.dir_attr);
189 dprintk("NFS reply lookup: %d\n", status);
194 nfs3_proc_lookup(struct inode *dir, struct dentry *dentry,
195 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
197 unsigned short task_flags = 0;
199 /* Is this is an attribute revalidation, subject to softreval? */
200 if (nfs_lookup_is_soft_revalidate(dentry))
201 task_flags |= RPC_TASK_TIMEOUT;
203 dprintk("NFS call lookup %pd2\n", dentry);
204 return __nfs3_proc_lookup(dir, dentry->d_name.name,
205 dentry->d_name.len, fhandle, fattr,
209 static int nfs3_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle,
210 struct nfs_fattr *fattr)
212 const char dotdot[] = "..";
213 const size_t len = strlen(dotdot);
214 unsigned short task_flags = 0;
216 if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL)
217 task_flags |= RPC_TASK_TIMEOUT;
219 return __nfs3_proc_lookup(inode, dotdot, len, fhandle, fattr,
223 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
225 struct nfs3_accessargs arg = {
227 .access = entry->mask,
229 struct nfs3_accessres res;
230 struct rpc_message msg = {
231 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
234 .rpc_cred = entry->cred,
236 int status = -ENOMEM;
238 dprintk("NFS call access\n");
239 res.fattr = nfs_alloc_fattr();
240 if (res.fattr == NULL)
243 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
244 nfs_refresh_inode(inode, res.fattr);
246 nfs_access_set_mask(entry, res.access);
247 nfs_free_fattr(res.fattr);
249 dprintk("NFS reply access: %d\n", status);
253 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
254 unsigned int pgbase, unsigned int pglen)
256 struct nfs_fattr *fattr;
257 struct nfs3_readlinkargs args = {
263 struct rpc_message msg = {
264 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
267 int status = -ENOMEM;
269 dprintk("NFS call readlink\n");
270 fattr = nfs_alloc_fattr();
273 msg.rpc_resp = fattr;
275 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
276 nfs_refresh_inode(inode, fattr);
277 nfs_free_fattr(fattr);
279 dprintk("NFS reply readlink: %d\n", status);
283 struct nfs3_createdata {
284 struct rpc_message msg;
286 struct nfs3_createargs create;
287 struct nfs3_mkdirargs mkdir;
288 struct nfs3_symlinkargs symlink;
289 struct nfs3_mknodargs mknod;
291 struct nfs3_diropres res;
293 struct nfs_fattr fattr;
294 struct nfs_fattr dir_attr;
297 static struct nfs3_createdata *nfs3_alloc_createdata(void)
299 struct nfs3_createdata *data;
301 data = kzalloc(sizeof(*data), GFP_KERNEL);
303 data->msg.rpc_argp = &data->arg;
304 data->msg.rpc_resp = &data->res;
305 data->res.fh = &data->fh;
306 data->res.fattr = &data->fattr;
307 data->res.dir_attr = &data->dir_attr;
308 nfs_fattr_init(data->res.fattr);
309 nfs_fattr_init(data->res.dir_attr);
314 static struct dentry *
315 nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
319 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
320 nfs_post_op_update_inode(dir, data->res.dir_attr);
322 return ERR_PTR(status);
324 return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr);
327 static void nfs3_free_createdata(struct nfs3_createdata *data)
333 * Create a regular file.
336 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
339 struct posix_acl *default_acl, *acl;
340 struct nfs3_createdata *data;
341 struct dentry *d_alias;
342 int status = -ENOMEM;
344 dprintk("NFS call create %pd\n", dentry);
346 data = nfs3_alloc_createdata();
350 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
351 data->arg.create.fh = NFS_FH(dir);
352 data->arg.create.name = dentry->d_name.name;
353 data->arg.create.len = dentry->d_name.len;
354 data->arg.create.sattr = sattr;
356 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
357 if (flags & O_EXCL) {
358 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
359 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
360 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
363 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
368 d_alias = nfs3_do_create(dir, dentry, data);
369 status = PTR_ERR_OR_ZERO(d_alias);
371 if (status != -ENOTSUPP)
373 /* If the server doesn't support the exclusive creation
374 * semantics, try again with simple 'guarded' mode. */
375 switch (data->arg.create.createmode) {
376 case NFS3_CREATE_EXCLUSIVE:
377 data->arg.create.createmode = NFS3_CREATE_GUARDED;
380 case NFS3_CREATE_GUARDED:
381 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
384 case NFS3_CREATE_UNCHECKED:
385 goto out_release_acls;
387 nfs_fattr_init(data->res.dir_attr);
388 nfs_fattr_init(data->res.fattr);
392 goto out_release_acls;
397 /* When we created the file with exclusive semantics, make
398 * sure we set the attributes afterwards. */
399 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
400 dprintk("NFS call setattr (post-create)\n");
402 if (!(sattr->ia_valid & ATTR_ATIME_SET))
403 sattr->ia_valid |= ATTR_ATIME;
404 if (!(sattr->ia_valid & ATTR_MTIME_SET))
405 sattr->ia_valid |= ATTR_MTIME;
407 /* Note: we could use a guarded setattr here, but I'm
408 * not sure this buys us anything (and I'd have
409 * to revamp the NFSv3 XDR code) */
410 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
411 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
412 dprintk("NFS reply setattr (post-create): %d\n", status);
417 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
422 posix_acl_release(acl);
423 posix_acl_release(default_acl);
425 nfs3_free_createdata(data);
426 dprintk("NFS reply create: %d\n", status);
431 nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
433 struct nfs_removeargs arg = {
435 .name = dentry->d_name,
437 struct nfs_removeres res;
438 struct rpc_message msg = {
439 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
443 int status = -ENOMEM;
445 dprintk("NFS call remove %pd2\n", dentry);
446 res.dir_attr = nfs_alloc_fattr();
447 if (res.dir_attr == NULL)
450 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
451 nfs_post_op_update_inode(dir, res.dir_attr);
452 nfs_free_fattr(res.dir_attr);
454 dprintk("NFS reply remove: %d\n", status);
459 nfs3_proc_unlink_setup(struct rpc_message *msg,
460 struct dentry *dentry,
463 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
466 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
468 rpc_call_start(task);
472 nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
474 struct nfs_removeres *res;
475 if (nfs3_async_handle_jukebox(task, dir))
477 res = task->tk_msg.rpc_resp;
478 nfs_post_op_update_inode(dir, res->dir_attr);
483 nfs3_proc_rename_setup(struct rpc_message *msg,
484 struct dentry *old_dentry,
485 struct dentry *new_dentry)
487 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
490 static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
492 rpc_call_start(task);
496 nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
497 struct inode *new_dir)
499 struct nfs_renameres *res;
501 if (nfs3_async_handle_jukebox(task, old_dir))
503 res = task->tk_msg.rpc_resp;
505 nfs_post_op_update_inode(old_dir, res->old_fattr);
506 nfs_post_op_update_inode(new_dir, res->new_fattr);
511 nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
513 struct nfs3_linkargs arg = {
514 .fromfh = NFS_FH(inode),
516 .toname = name->name,
519 struct nfs3_linkres res;
520 struct rpc_message msg = {
521 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
525 int status = -ENOMEM;
527 dprintk("NFS call link %s\n", name->name);
528 res.fattr = nfs_alloc_fattr();
529 res.dir_attr = nfs_alloc_fattr();
530 if (res.fattr == NULL || res.dir_attr == NULL)
533 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
534 nfs_post_op_update_inode(dir, res.dir_attr);
535 nfs_post_op_update_inode(inode, res.fattr);
537 nfs_free_fattr(res.dir_attr);
538 nfs_free_fattr(res.fattr);
539 dprintk("NFS reply link: %d\n", status);
544 nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
545 unsigned int len, struct iattr *sattr)
547 struct nfs3_createdata *data;
548 struct dentry *d_alias;
549 int status = -ENOMEM;
551 if (len > NFS3_MAXPATHLEN)
552 return -ENAMETOOLONG;
554 dprintk("NFS call symlink %pd\n", dentry);
556 data = nfs3_alloc_createdata();
559 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
560 data->arg.symlink.fromfh = NFS_FH(dir);
561 data->arg.symlink.fromname = dentry->d_name.name;
562 data->arg.symlink.fromlen = dentry->d_name.len;
563 data->arg.symlink.pages = &page;
564 data->arg.symlink.pathlen = len;
565 data->arg.symlink.sattr = sattr;
567 d_alias = nfs3_do_create(dir, dentry, data);
568 status = PTR_ERR_OR_ZERO(d_alias);
573 nfs3_free_createdata(data);
575 dprintk("NFS reply symlink: %d\n", status);
580 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
582 struct posix_acl *default_acl, *acl;
583 struct nfs3_createdata *data;
584 struct dentry *d_alias;
585 int status = -ENOMEM;
587 dprintk("NFS call mkdir %pd\n", dentry);
589 data = nfs3_alloc_createdata();
593 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
597 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
598 data->arg.mkdir.fh = NFS_FH(dir);
599 data->arg.mkdir.name = dentry->d_name.name;
600 data->arg.mkdir.len = dentry->d_name.len;
601 data->arg.mkdir.sattr = sattr;
603 d_alias = nfs3_do_create(dir, dentry, data);
604 status = PTR_ERR_OR_ZERO(d_alias);
607 goto out_release_acls;
612 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
616 posix_acl_release(acl);
617 posix_acl_release(default_acl);
619 nfs3_free_createdata(data);
620 dprintk("NFS reply mkdir: %d\n", status);
625 nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
627 struct nfs_fattr *dir_attr;
628 struct nfs3_diropargs arg = {
633 struct rpc_message msg = {
634 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
637 int status = -ENOMEM;
639 dprintk("NFS call rmdir %s\n", name->name);
640 dir_attr = nfs_alloc_fattr();
641 if (dir_attr == NULL)
644 msg.rpc_resp = dir_attr;
645 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
646 nfs_post_op_update_inode(dir, dir_attr);
647 nfs_free_fattr(dir_attr);
649 dprintk("NFS reply rmdir: %d\n", status);
654 * The READDIR implementation is somewhat hackish - we pass the user buffer
655 * to the encode function, which installs it in the receive iovec.
656 * The decode function itself doesn't perform any decoding, it just makes
657 * sure the reply is syntactically correct.
659 * Also note that this implementation handles both plain readdir and
662 static int nfs3_proc_readdir(struct nfs_readdir_arg *nr_arg,
663 struct nfs_readdir_res *nr_res)
665 struct inode *dir = d_inode(nr_arg->dentry);
666 struct nfs3_readdirargs arg = {
668 .cookie = nr_arg->cookie,
669 .plus = nr_arg->plus,
670 .count = nr_arg->page_len,
671 .pages = nr_arg->pages
673 struct nfs3_readdirres res = {
674 .verf = nr_res->verf,
675 .plus = nr_arg->plus,
677 struct rpc_message msg = {
678 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
681 .rpc_cred = nr_arg->cred,
683 int status = -ENOMEM;
686 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
688 memcpy(arg.verf, nr_arg->verf, sizeof(arg.verf));
690 dprintk("NFS call readdir%s %llu\n", nr_arg->plus ? "plus" : "",
691 (unsigned long long)nr_arg->cookie);
693 res.dir_attr = nfs_alloc_fattr();
694 if (res.dir_attr == NULL)
697 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
699 nfs_invalidate_atime(dir);
700 nfs_refresh_inode(dir, res.dir_attr);
702 nfs_free_fattr(res.dir_attr);
704 dprintk("NFS reply readdir%s: %d\n", nr_arg->plus ? "plus" : "",
710 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
713 struct posix_acl *default_acl, *acl;
714 struct nfs3_createdata *data;
715 struct dentry *d_alias;
716 int status = -ENOMEM;
718 dprintk("NFS call mknod %pd %u:%u\n", dentry,
719 MAJOR(rdev), MINOR(rdev));
721 data = nfs3_alloc_createdata();
725 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
729 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
730 data->arg.mknod.fh = NFS_FH(dir);
731 data->arg.mknod.name = dentry->d_name.name;
732 data->arg.mknod.len = dentry->d_name.len;
733 data->arg.mknod.sattr = sattr;
734 data->arg.mknod.rdev = rdev;
736 switch (sattr->ia_mode & S_IFMT) {
738 data->arg.mknod.type = NF3BLK;
741 data->arg.mknod.type = NF3CHR;
744 data->arg.mknod.type = NF3FIFO;
747 data->arg.mknod.type = NF3SOCK;
751 goto out_release_acls;
754 d_alias = nfs3_do_create(dir, dentry, data);
755 status = PTR_ERR_OR_ZERO(d_alias);
757 goto out_release_acls;
762 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
766 posix_acl_release(acl);
767 posix_acl_release(default_acl);
769 nfs3_free_createdata(data);
770 dprintk("NFS reply mknod: %d\n", status);
775 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
776 struct nfs_fsstat *stat)
778 struct rpc_message msg = {
779 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
785 dprintk("NFS call fsstat\n");
786 nfs_fattr_init(stat->fattr);
787 status = rpc_call_sync(server->client, &msg, 0);
788 dprintk("NFS reply fsstat: %d\n", status);
793 do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
794 struct nfs_fsinfo *info)
796 struct rpc_message msg = {
797 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
803 dprintk("NFS call fsinfo\n");
804 nfs_fattr_init(info->fattr);
805 status = rpc_call_sync(client, &msg, 0);
806 dprintk("NFS reply fsinfo: %d\n", status);
811 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
815 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
816 struct nfs_fsinfo *info)
820 status = do_proc_fsinfo(server->client, fhandle, info);
821 if (status && server->nfs_client->cl_rpcclient != server->client)
822 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
827 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
828 struct nfs_pathconf *info)
830 struct rpc_message msg = {
831 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
837 dprintk("NFS call pathconf\n");
838 nfs_fattr_init(info->fattr);
839 status = rpc_call_sync(server->client, &msg, 0);
840 dprintk("NFS reply pathconf: %d\n", status);
844 static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
846 struct inode *inode = hdr->inode;
847 struct nfs_server *server = NFS_SERVER(inode);
849 if (hdr->pgio_done_cb != NULL)
850 return hdr->pgio_done_cb(task, hdr);
852 if (nfs3_async_handle_jukebox(task, inode))
855 if (task->tk_status >= 0 && !server->read_hdrsize)
856 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
858 nfs_invalidate_atime(inode);
859 nfs_refresh_inode(inode, &hdr->fattr);
863 static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
864 struct rpc_message *msg)
866 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
867 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
870 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
871 struct nfs_pgio_header *hdr)
873 rpc_call_start(task);
877 static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
879 struct inode *inode = hdr->inode;
881 if (hdr->pgio_done_cb != NULL)
882 return hdr->pgio_done_cb(task, hdr);
884 if (nfs3_async_handle_jukebox(task, inode))
886 if (task->tk_status >= 0)
887 nfs_writeback_update_inode(hdr);
891 static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
892 struct rpc_message *msg,
893 struct rpc_clnt **clnt)
895 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
898 static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
900 rpc_call_start(task);
903 static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
905 if (data->commit_done_cb != NULL)
906 return data->commit_done_cb(task, data);
908 if (nfs3_async_handle_jukebox(task, data->inode))
910 nfs_refresh_inode(data->inode, data->res.fattr);
914 static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
915 struct rpc_clnt **clnt)
917 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
920 static void nfs3_nlm_alloc_call(void *data)
922 struct nfs_lock_context *l_ctx = data;
923 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
924 get_nfs_open_context(l_ctx->open_context);
925 nfs_get_lock_context(l_ctx->open_context);
929 static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
931 struct nfs_lock_context *l_ctx = data;
932 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
933 return nfs_async_iocounter_wait(task, l_ctx);
938 static void nfs3_nlm_release_call(void *data)
940 struct nfs_lock_context *l_ctx = data;
941 struct nfs_open_context *ctx;
942 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
943 ctx = l_ctx->open_context;
944 nfs_put_lock_context(l_ctx);
945 put_nfs_open_context(ctx);
949 static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
950 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
951 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
952 .nlmclnt_release_call = nfs3_nlm_release_call,
956 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
958 struct inode *inode = file_inode(filp);
959 struct nfs_lock_context *l_ctx = NULL;
960 struct nfs_open_context *ctx = nfs_file_open_context(filp);
963 if (fl->fl_flags & FL_CLOSE) {
964 l_ctx = nfs_get_lock_context(ctx);
968 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
971 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
974 nfs_put_lock_context(l_ctx);
979 static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
984 static const struct inode_operations nfs3_dir_inode_operations = {
985 .create = nfs_create,
986 .lookup = nfs_lookup,
988 .unlink = nfs_unlink,
989 .symlink = nfs_symlink,
993 .rename = nfs_rename,
994 .permission = nfs_permission,
995 .getattr = nfs_getattr,
996 .setattr = nfs_setattr,
997 #ifdef CONFIG_NFS_V3_ACL
998 .listxattr = nfs3_listxattr,
999 .get_acl = nfs3_get_acl,
1000 .set_acl = nfs3_set_acl,
1004 static const struct inode_operations nfs3_file_inode_operations = {
1005 .permission = nfs_permission,
1006 .getattr = nfs_getattr,
1007 .setattr = nfs_setattr,
1008 #ifdef CONFIG_NFS_V3_ACL
1009 .listxattr = nfs3_listxattr,
1010 .get_acl = nfs3_get_acl,
1011 .set_acl = nfs3_set_acl,
1015 const struct nfs_rpc_ops nfs_v3_clientops = {
1016 .version = 3, /* protocol version */
1017 .dentry_ops = &nfs_dentry_operations,
1018 .dir_inode_ops = &nfs3_dir_inode_operations,
1019 .file_inode_ops = &nfs3_file_inode_operations,
1020 .file_ops = &nfs_file_operations,
1021 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
1022 .getroot = nfs3_proc_get_root,
1023 .submount = nfs_submount,
1024 .try_get_tree = nfs_try_get_tree,
1025 .getattr = nfs3_proc_getattr,
1026 .setattr = nfs3_proc_setattr,
1027 .lookup = nfs3_proc_lookup,
1028 .lookupp = nfs3_proc_lookupp,
1029 .access = nfs3_proc_access,
1030 .readlink = nfs3_proc_readlink,
1031 .create = nfs3_proc_create,
1032 .remove = nfs3_proc_remove,
1033 .unlink_setup = nfs3_proc_unlink_setup,
1034 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
1035 .unlink_done = nfs3_proc_unlink_done,
1036 .rename_setup = nfs3_proc_rename_setup,
1037 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
1038 .rename_done = nfs3_proc_rename_done,
1039 .link = nfs3_proc_link,
1040 .symlink = nfs3_proc_symlink,
1041 .mkdir = nfs3_proc_mkdir,
1042 .rmdir = nfs3_proc_rmdir,
1043 .readdir = nfs3_proc_readdir,
1044 .mknod = nfs3_proc_mknod,
1045 .statfs = nfs3_proc_statfs,
1046 .fsinfo = nfs3_proc_fsinfo,
1047 .pathconf = nfs3_proc_pathconf,
1048 .decode_dirent = nfs3_decode_dirent,
1049 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
1050 .read_setup = nfs3_proc_read_setup,
1051 .read_done = nfs3_read_done,
1052 .write_setup = nfs3_proc_write_setup,
1053 .write_done = nfs3_write_done,
1054 .commit_setup = nfs3_proc_commit_setup,
1055 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
1056 .commit_done = nfs3_commit_done,
1057 .lock = nfs3_proc_lock,
1058 .clear_acl_cache = forget_all_cached_acls,
1059 .close_context = nfs_close_context,
1060 .have_delegation = nfs3_have_delegation,
1061 .alloc_client = nfs_alloc_client,
1062 .init_client = nfs_init_client,
1063 .free_client = nfs_free_client,
1064 .create_server = nfs3_create_server,
1065 .clone_server = nfs3_clone_server,