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 if (task->tk_status == -EJUKEBOX)
53 nfs_inc_stats(inode, NFSIOS_DELAY);
55 rpc_restart_call(task);
56 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
61 do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle,
62 struct nfs_fsinfo *info)
64 struct rpc_message msg = {
65 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
71 dprintk("%s: call fsinfo\n", __func__);
72 nfs_fattr_init(info->fattr);
73 status = rpc_call_sync(client, &msg, 0);
74 dprintk("%s: reply fsinfo: %d\n", __func__, status);
75 if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) {
76 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
77 msg.rpc_resp = info->fattr;
78 status = rpc_call_sync(client, &msg, 0);
79 dprintk("%s: reply getattr: %d\n", __func__, status);
85 * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb
88 nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
89 struct nfs_fsinfo *info)
93 status = do_proc_get_root(server->client, fhandle, info);
94 if (status && server->nfs_client->cl_rpcclient != server->client)
95 status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info);
100 * One function for each procedure in the NFS protocol.
103 nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
104 struct nfs_fattr *fattr, struct nfs4_label *label,
107 struct rpc_message msg = {
108 .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR],
113 unsigned short task_flags = 0;
115 /* Is this is an attribute revalidation, subject to softreval? */
116 if (inode && (server->flags & NFS_MOUNT_SOFTREVAL))
117 task_flags |= RPC_TASK_TIMEOUT;
119 dprintk("NFS call getattr\n");
120 nfs_fattr_init(fattr);
121 status = rpc_call_sync(server->client, &msg, task_flags);
122 dprintk("NFS reply getattr: %d\n", status);
127 nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
130 struct inode *inode = d_inode(dentry);
131 struct nfs3_sattrargs arg = {
135 struct rpc_message msg = {
136 .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR],
142 dprintk("NFS call setattr\n");
143 if (sattr->ia_valid & ATTR_FILE)
144 msg.rpc_cred = nfs_file_cred(sattr->ia_file);
145 nfs_fattr_init(fattr);
146 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
148 nfs_setattr_update_inode(inode, sattr, fattr);
149 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
150 nfs_zap_acl_cache(inode);
152 dprintk("NFS reply setattr: %d\n", status);
157 __nfs3_proc_lookup(struct inode *dir, const char *name, size_t len,
158 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
159 unsigned short task_flags)
161 struct nfs3_diropargs arg = {
166 struct nfs3_diropres res = {
170 struct rpc_message msg = {
171 .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP],
177 res.dir_attr = nfs_alloc_fattr();
178 if (res.dir_attr == NULL)
181 nfs_fattr_init(fattr);
182 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
183 nfs_refresh_inode(dir, res.dir_attr);
184 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
185 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
186 msg.rpc_argp = fhandle;
187 msg.rpc_resp = fattr;
188 status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags);
190 nfs_free_fattr(res.dir_attr);
191 dprintk("NFS reply lookup: %d\n", status);
196 nfs3_proc_lookup(struct inode *dir, struct dentry *dentry,
197 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
198 struct nfs4_label *label)
200 unsigned short task_flags = 0;
202 /* Is this is an attribute revalidation, subject to softreval? */
203 if (nfs_lookup_is_soft_revalidate(dentry))
204 task_flags |= RPC_TASK_TIMEOUT;
206 dprintk("NFS call lookup %pd2\n", dentry);
207 return __nfs3_proc_lookup(dir, dentry->d_name.name,
208 dentry->d_name.len, fhandle, fattr,
212 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
214 struct nfs3_accessargs arg = {
216 .access = entry->mask,
218 struct nfs3_accessres res;
219 struct rpc_message msg = {
220 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
223 .rpc_cred = entry->cred,
225 int status = -ENOMEM;
227 dprintk("NFS call access\n");
228 res.fattr = nfs_alloc_fattr();
229 if (res.fattr == NULL)
232 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
233 nfs_refresh_inode(inode, res.fattr);
235 nfs_access_set_mask(entry, res.access);
236 nfs_free_fattr(res.fattr);
238 dprintk("NFS reply access: %d\n", status);
242 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
243 unsigned int pgbase, unsigned int pglen)
245 struct nfs_fattr *fattr;
246 struct nfs3_readlinkargs args = {
252 struct rpc_message msg = {
253 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
256 int status = -ENOMEM;
258 dprintk("NFS call readlink\n");
259 fattr = nfs_alloc_fattr();
262 msg.rpc_resp = fattr;
264 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
265 nfs_refresh_inode(inode, fattr);
266 nfs_free_fattr(fattr);
268 dprintk("NFS reply readlink: %d\n", status);
272 struct nfs3_createdata {
273 struct rpc_message msg;
275 struct nfs3_createargs create;
276 struct nfs3_mkdirargs mkdir;
277 struct nfs3_symlinkargs symlink;
278 struct nfs3_mknodargs mknod;
280 struct nfs3_diropres res;
282 struct nfs_fattr fattr;
283 struct nfs_fattr dir_attr;
286 static struct nfs3_createdata *nfs3_alloc_createdata(void)
288 struct nfs3_createdata *data;
290 data = kzalloc(sizeof(*data), GFP_KERNEL);
292 data->msg.rpc_argp = &data->arg;
293 data->msg.rpc_resp = &data->res;
294 data->res.fh = &data->fh;
295 data->res.fattr = &data->fattr;
296 data->res.dir_attr = &data->dir_attr;
297 nfs_fattr_init(data->res.fattr);
298 nfs_fattr_init(data->res.dir_attr);
303 static struct dentry *
304 nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
308 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
309 nfs_post_op_update_inode(dir, data->res.dir_attr);
311 return ERR_PTR(status);
313 return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr, NULL);
316 static void nfs3_free_createdata(struct nfs3_createdata *data)
322 * Create a regular file.
325 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
328 struct posix_acl *default_acl, *acl;
329 struct nfs3_createdata *data;
330 struct dentry *d_alias;
331 int status = -ENOMEM;
333 dprintk("NFS call create %pd\n", dentry);
335 data = nfs3_alloc_createdata();
339 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
340 data->arg.create.fh = NFS_FH(dir);
341 data->arg.create.name = dentry->d_name.name;
342 data->arg.create.len = dentry->d_name.len;
343 data->arg.create.sattr = sattr;
345 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
346 if (flags & O_EXCL) {
347 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
348 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
349 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
352 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
357 d_alias = nfs3_do_create(dir, dentry, data);
358 status = PTR_ERR_OR_ZERO(d_alias);
360 if (status != -ENOTSUPP)
362 /* If the server doesn't support the exclusive creation
363 * semantics, try again with simple 'guarded' mode. */
364 switch (data->arg.create.createmode) {
365 case NFS3_CREATE_EXCLUSIVE:
366 data->arg.create.createmode = NFS3_CREATE_GUARDED;
369 case NFS3_CREATE_GUARDED:
370 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
373 case NFS3_CREATE_UNCHECKED:
376 nfs_fattr_init(data->res.dir_attr);
377 nfs_fattr_init(data->res.fattr);
381 goto out_release_acls;
386 /* When we created the file with exclusive semantics, make
387 * sure we set the attributes afterwards. */
388 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
389 dprintk("NFS call setattr (post-create)\n");
391 if (!(sattr->ia_valid & ATTR_ATIME_SET))
392 sattr->ia_valid |= ATTR_ATIME;
393 if (!(sattr->ia_valid & ATTR_MTIME_SET))
394 sattr->ia_valid |= ATTR_MTIME;
396 /* Note: we could use a guarded setattr here, but I'm
397 * not sure this buys us anything (and I'd have
398 * to revamp the NFSv3 XDR code) */
399 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
400 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
401 dprintk("NFS reply setattr (post-create): %d\n", status);
406 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
411 posix_acl_release(acl);
412 posix_acl_release(default_acl);
414 nfs3_free_createdata(data);
415 dprintk("NFS reply create: %d\n", status);
420 nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
422 struct nfs_removeargs arg = {
424 .name = dentry->d_name,
426 struct nfs_removeres res;
427 struct rpc_message msg = {
428 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
432 int status = -ENOMEM;
434 dprintk("NFS call remove %pd2\n", dentry);
435 res.dir_attr = nfs_alloc_fattr();
436 if (res.dir_attr == NULL)
439 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
440 nfs_post_op_update_inode(dir, res.dir_attr);
441 nfs_free_fattr(res.dir_attr);
443 dprintk("NFS reply remove: %d\n", status);
448 nfs3_proc_unlink_setup(struct rpc_message *msg,
449 struct dentry *dentry,
452 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
455 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
457 rpc_call_start(task);
461 nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
463 struct nfs_removeres *res;
464 if (nfs3_async_handle_jukebox(task, dir))
466 res = task->tk_msg.rpc_resp;
467 nfs_post_op_update_inode(dir, res->dir_attr);
472 nfs3_proc_rename_setup(struct rpc_message *msg,
473 struct dentry *old_dentry,
474 struct dentry *new_dentry)
476 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
479 static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
481 rpc_call_start(task);
485 nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
486 struct inode *new_dir)
488 struct nfs_renameres *res;
490 if (nfs3_async_handle_jukebox(task, old_dir))
492 res = task->tk_msg.rpc_resp;
494 nfs_post_op_update_inode(old_dir, res->old_fattr);
495 nfs_post_op_update_inode(new_dir, res->new_fattr);
500 nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
502 struct nfs3_linkargs arg = {
503 .fromfh = NFS_FH(inode),
505 .toname = name->name,
508 struct nfs3_linkres res;
509 struct rpc_message msg = {
510 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
514 int status = -ENOMEM;
516 dprintk("NFS call link %s\n", name->name);
517 res.fattr = nfs_alloc_fattr();
518 res.dir_attr = nfs_alloc_fattr();
519 if (res.fattr == NULL || res.dir_attr == NULL)
522 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
523 nfs_post_op_update_inode(dir, res.dir_attr);
524 nfs_post_op_update_inode(inode, res.fattr);
526 nfs_free_fattr(res.dir_attr);
527 nfs_free_fattr(res.fattr);
528 dprintk("NFS reply link: %d\n", status);
533 nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
534 unsigned int len, struct iattr *sattr)
536 struct nfs3_createdata *data;
537 struct dentry *d_alias;
538 int status = -ENOMEM;
540 if (len > NFS3_MAXPATHLEN)
541 return -ENAMETOOLONG;
543 dprintk("NFS call symlink %pd\n", dentry);
545 data = nfs3_alloc_createdata();
548 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
549 data->arg.symlink.fromfh = NFS_FH(dir);
550 data->arg.symlink.fromname = dentry->d_name.name;
551 data->arg.symlink.fromlen = dentry->d_name.len;
552 data->arg.symlink.pages = &page;
553 data->arg.symlink.pathlen = len;
554 data->arg.symlink.sattr = sattr;
556 d_alias = nfs3_do_create(dir, dentry, data);
557 status = PTR_ERR_OR_ZERO(d_alias);
562 nfs3_free_createdata(data);
564 dprintk("NFS reply symlink: %d\n", status);
569 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
571 struct posix_acl *default_acl, *acl;
572 struct nfs3_createdata *data;
573 struct dentry *d_alias;
574 int status = -ENOMEM;
576 dprintk("NFS call mkdir %pd\n", dentry);
578 data = nfs3_alloc_createdata();
582 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
586 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
587 data->arg.mkdir.fh = NFS_FH(dir);
588 data->arg.mkdir.name = dentry->d_name.name;
589 data->arg.mkdir.len = dentry->d_name.len;
590 data->arg.mkdir.sattr = sattr;
592 d_alias = nfs3_do_create(dir, dentry, data);
593 status = PTR_ERR_OR_ZERO(d_alias);
596 goto out_release_acls;
601 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
605 posix_acl_release(acl);
606 posix_acl_release(default_acl);
608 nfs3_free_createdata(data);
609 dprintk("NFS reply mkdir: %d\n", status);
614 nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
616 struct nfs_fattr *dir_attr;
617 struct nfs3_diropargs arg = {
622 struct rpc_message msg = {
623 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
626 int status = -ENOMEM;
628 dprintk("NFS call rmdir %s\n", name->name);
629 dir_attr = nfs_alloc_fattr();
630 if (dir_attr == NULL)
633 msg.rpc_resp = dir_attr;
634 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
635 nfs_post_op_update_inode(dir, dir_attr);
636 nfs_free_fattr(dir_attr);
638 dprintk("NFS reply rmdir: %d\n", status);
643 * The READDIR implementation is somewhat hackish - we pass the user buffer
644 * to the encode function, which installs it in the receive iovec.
645 * The decode function itself doesn't perform any decoding, it just makes
646 * sure the reply is syntactically correct.
648 * Also note that this implementation handles both plain readdir and
652 nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
653 u64 cookie, struct page **pages, unsigned int count, bool plus)
655 struct inode *dir = d_inode(dentry);
656 __be32 *verf = NFS_I(dir)->cookieverf;
657 struct nfs3_readdirargs arg = {
660 .verf = {verf[0], verf[1]},
665 struct nfs3_readdirres res = {
669 struct rpc_message msg = {
670 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
675 int status = -ENOMEM;
678 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
680 dprintk("NFS call readdir%s %d\n",
681 plus? "plus" : "", (unsigned int) cookie);
683 res.dir_attr = nfs_alloc_fattr();
684 if (res.dir_attr == NULL)
687 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
689 nfs_invalidate_atime(dir);
690 nfs_refresh_inode(dir, res.dir_attr);
692 nfs_free_fattr(res.dir_attr);
694 dprintk("NFS reply readdir%s: %d\n",
695 plus? "plus" : "", status);
700 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
703 struct posix_acl *default_acl, *acl;
704 struct nfs3_createdata *data;
705 struct dentry *d_alias;
706 int status = -ENOMEM;
708 dprintk("NFS call mknod %pd %u:%u\n", dentry,
709 MAJOR(rdev), MINOR(rdev));
711 data = nfs3_alloc_createdata();
715 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
719 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
720 data->arg.mknod.fh = NFS_FH(dir);
721 data->arg.mknod.name = dentry->d_name.name;
722 data->arg.mknod.len = dentry->d_name.len;
723 data->arg.mknod.sattr = sattr;
724 data->arg.mknod.rdev = rdev;
726 switch (sattr->ia_mode & S_IFMT) {
728 data->arg.mknod.type = NF3BLK;
731 data->arg.mknod.type = NF3CHR;
734 data->arg.mknod.type = NF3FIFO;
737 data->arg.mknod.type = NF3SOCK;
744 d_alias = nfs3_do_create(dir, dentry, data);
745 status = PTR_ERR_OR_ZERO(d_alias);
747 goto out_release_acls;
752 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
756 posix_acl_release(acl);
757 posix_acl_release(default_acl);
759 nfs3_free_createdata(data);
760 dprintk("NFS reply mknod: %d\n", status);
765 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
766 struct nfs_fsstat *stat)
768 struct rpc_message msg = {
769 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
775 dprintk("NFS call fsstat\n");
776 nfs_fattr_init(stat->fattr);
777 status = rpc_call_sync(server->client, &msg, 0);
778 dprintk("NFS reply fsstat: %d\n", status);
783 do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
784 struct nfs_fsinfo *info)
786 struct rpc_message msg = {
787 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
793 dprintk("NFS call fsinfo\n");
794 nfs_fattr_init(info->fattr);
795 status = rpc_call_sync(client, &msg, 0);
796 dprintk("NFS reply fsinfo: %d\n", status);
801 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
805 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
806 struct nfs_fsinfo *info)
810 status = do_proc_fsinfo(server->client, fhandle, info);
811 if (status && server->nfs_client->cl_rpcclient != server->client)
812 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
817 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
818 struct nfs_pathconf *info)
820 struct rpc_message msg = {
821 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
827 dprintk("NFS call pathconf\n");
828 nfs_fattr_init(info->fattr);
829 status = rpc_call_sync(server->client, &msg, 0);
830 dprintk("NFS reply pathconf: %d\n", status);
834 static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
836 struct inode *inode = hdr->inode;
837 struct nfs_server *server = NFS_SERVER(inode);
839 if (hdr->pgio_done_cb != NULL)
840 return hdr->pgio_done_cb(task, hdr);
842 if (nfs3_async_handle_jukebox(task, inode))
845 if (task->tk_status >= 0 && !server->read_hdrsize)
846 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
848 nfs_invalidate_atime(inode);
849 nfs_refresh_inode(inode, &hdr->fattr);
853 static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
854 struct rpc_message *msg)
856 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
857 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
860 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
861 struct nfs_pgio_header *hdr)
863 rpc_call_start(task);
867 static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
869 struct inode *inode = hdr->inode;
871 if (hdr->pgio_done_cb != NULL)
872 return hdr->pgio_done_cb(task, hdr);
874 if (nfs3_async_handle_jukebox(task, inode))
876 if (task->tk_status >= 0)
877 nfs_writeback_update_inode(hdr);
881 static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
882 struct rpc_message *msg,
883 struct rpc_clnt **clnt)
885 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
888 static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
890 rpc_call_start(task);
893 static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
895 if (data->commit_done_cb != NULL)
896 return data->commit_done_cb(task, data);
898 if (nfs3_async_handle_jukebox(task, data->inode))
900 nfs_refresh_inode(data->inode, data->res.fattr);
904 static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
905 struct rpc_clnt **clnt)
907 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
910 static void nfs3_nlm_alloc_call(void *data)
912 struct nfs_lock_context *l_ctx = data;
913 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
914 get_nfs_open_context(l_ctx->open_context);
915 nfs_get_lock_context(l_ctx->open_context);
919 static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
921 struct nfs_lock_context *l_ctx = data;
922 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
923 return nfs_async_iocounter_wait(task, l_ctx);
928 static void nfs3_nlm_release_call(void *data)
930 struct nfs_lock_context *l_ctx = data;
931 struct nfs_open_context *ctx;
932 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
933 ctx = l_ctx->open_context;
934 nfs_put_lock_context(l_ctx);
935 put_nfs_open_context(ctx);
939 static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
940 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
941 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
942 .nlmclnt_release_call = nfs3_nlm_release_call,
946 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
948 struct inode *inode = file_inode(filp);
949 struct nfs_lock_context *l_ctx = NULL;
950 struct nfs_open_context *ctx = nfs_file_open_context(filp);
953 if (fl->fl_flags & FL_CLOSE) {
954 l_ctx = nfs_get_lock_context(ctx);
958 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
961 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
964 nfs_put_lock_context(l_ctx);
969 static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
974 static const struct inode_operations nfs3_dir_inode_operations = {
975 .create = nfs_create,
976 .lookup = nfs_lookup,
978 .unlink = nfs_unlink,
979 .symlink = nfs_symlink,
983 .rename = nfs_rename,
984 .permission = nfs_permission,
985 .getattr = nfs_getattr,
986 .setattr = nfs_setattr,
987 #ifdef CONFIG_NFS_V3_ACL
988 .listxattr = nfs3_listxattr,
989 .get_acl = nfs3_get_acl,
990 .set_acl = nfs3_set_acl,
994 static const struct inode_operations nfs3_file_inode_operations = {
995 .permission = nfs_permission,
996 .getattr = nfs_getattr,
997 .setattr = nfs_setattr,
998 #ifdef CONFIG_NFS_V3_ACL
999 .listxattr = nfs3_listxattr,
1000 .get_acl = nfs3_get_acl,
1001 .set_acl = nfs3_set_acl,
1005 const struct nfs_rpc_ops nfs_v3_clientops = {
1006 .version = 3, /* protocol version */
1007 .dentry_ops = &nfs_dentry_operations,
1008 .dir_inode_ops = &nfs3_dir_inode_operations,
1009 .file_inode_ops = &nfs3_file_inode_operations,
1010 .file_ops = &nfs_file_operations,
1011 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
1012 .getroot = nfs3_proc_get_root,
1013 .submount = nfs_submount,
1014 .try_get_tree = nfs_try_get_tree,
1015 .getattr = nfs3_proc_getattr,
1016 .setattr = nfs3_proc_setattr,
1017 .lookup = nfs3_proc_lookup,
1018 .access = nfs3_proc_access,
1019 .readlink = nfs3_proc_readlink,
1020 .create = nfs3_proc_create,
1021 .remove = nfs3_proc_remove,
1022 .unlink_setup = nfs3_proc_unlink_setup,
1023 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
1024 .unlink_done = nfs3_proc_unlink_done,
1025 .rename_setup = nfs3_proc_rename_setup,
1026 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
1027 .rename_done = nfs3_proc_rename_done,
1028 .link = nfs3_proc_link,
1029 .symlink = nfs3_proc_symlink,
1030 .mkdir = nfs3_proc_mkdir,
1031 .rmdir = nfs3_proc_rmdir,
1032 .readdir = nfs3_proc_readdir,
1033 .mknod = nfs3_proc_mknod,
1034 .statfs = nfs3_proc_statfs,
1035 .fsinfo = nfs3_proc_fsinfo,
1036 .pathconf = nfs3_proc_pathconf,
1037 .decode_dirent = nfs3_decode_dirent,
1038 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
1039 .read_setup = nfs3_proc_read_setup,
1040 .read_done = nfs3_read_done,
1041 .write_setup = nfs3_proc_write_setup,
1042 .write_done = nfs3_write_done,
1043 .commit_setup = nfs3_proc_commit_setup,
1044 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
1045 .commit_done = nfs3_commit_done,
1046 .lock = nfs3_proc_lock,
1047 .clear_acl_cache = forget_all_cached_acls,
1048 .close_context = nfs_close_context,
1049 .have_delegation = nfs3_have_delegation,
1050 .alloc_client = nfs_alloc_client,
1051 .init_client = nfs_init_client,
1052 .free_client = nfs_free_client,
1053 .create_server = nfs3_create_server,
1054 .clone_server = nfs3_clone_server,