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 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
149 nfs_zap_acl_cache(inode);
150 nfs_setattr_update_inode(inode, sattr, fattr);
152 dprintk("NFS reply setattr: %d\n", status);
157 nfs3_proc_lookup(struct inode *dir, const struct qstr *name,
158 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
159 struct nfs4_label *label)
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 dprintk("NFS call lookup %s\n", name->name);
182 nfs_fattr_init(fattr);
183 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
184 nfs_refresh_inode(dir, res.dir_attr);
185 if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
186 msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
187 msg.rpc_argp = fhandle;
188 msg.rpc_resp = fattr;
189 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
191 nfs_free_fattr(res.dir_attr);
192 dprintk("NFS reply lookup: %d\n", status);
196 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
198 struct nfs3_accessargs arg = {
200 .access = entry->mask,
202 struct nfs3_accessres res;
203 struct rpc_message msg = {
204 .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS],
207 .rpc_cred = entry->cred,
209 int status = -ENOMEM;
211 dprintk("NFS call access\n");
212 res.fattr = nfs_alloc_fattr();
213 if (res.fattr == NULL)
216 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
217 nfs_refresh_inode(inode, res.fattr);
219 nfs_access_set_mask(entry, res.access);
220 nfs_free_fattr(res.fattr);
222 dprintk("NFS reply access: %d\n", status);
226 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
227 unsigned int pgbase, unsigned int pglen)
229 struct nfs_fattr *fattr;
230 struct nfs3_readlinkargs args = {
236 struct rpc_message msg = {
237 .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK],
240 int status = -ENOMEM;
242 dprintk("NFS call readlink\n");
243 fattr = nfs_alloc_fattr();
246 msg.rpc_resp = fattr;
248 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
249 nfs_refresh_inode(inode, fattr);
250 nfs_free_fattr(fattr);
252 dprintk("NFS reply readlink: %d\n", status);
256 struct nfs3_createdata {
257 struct rpc_message msg;
259 struct nfs3_createargs create;
260 struct nfs3_mkdirargs mkdir;
261 struct nfs3_symlinkargs symlink;
262 struct nfs3_mknodargs mknod;
264 struct nfs3_diropres res;
266 struct nfs_fattr fattr;
267 struct nfs_fattr dir_attr;
270 static struct nfs3_createdata *nfs3_alloc_createdata(void)
272 struct nfs3_createdata *data;
274 data = kzalloc(sizeof(*data), GFP_KERNEL);
276 data->msg.rpc_argp = &data->arg;
277 data->msg.rpc_resp = &data->res;
278 data->res.fh = &data->fh;
279 data->res.fattr = &data->fattr;
280 data->res.dir_attr = &data->dir_attr;
281 nfs_fattr_init(data->res.fattr);
282 nfs_fattr_init(data->res.dir_attr);
287 static struct dentry *
288 nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data)
292 status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0);
293 nfs_post_op_update_inode(dir, data->res.dir_attr);
295 return ERR_PTR(status);
297 return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr, NULL);
300 static void nfs3_free_createdata(struct nfs3_createdata *data)
306 * Create a regular file.
309 nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
312 struct posix_acl *default_acl, *acl;
313 struct nfs3_createdata *data;
314 struct dentry *d_alias;
315 int status = -ENOMEM;
317 dprintk("NFS call create %pd\n", dentry);
319 data = nfs3_alloc_createdata();
323 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE];
324 data->arg.create.fh = NFS_FH(dir);
325 data->arg.create.name = dentry->d_name.name;
326 data->arg.create.len = dentry->d_name.len;
327 data->arg.create.sattr = sattr;
329 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
330 if (flags & O_EXCL) {
331 data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE;
332 data->arg.create.verifier[0] = cpu_to_be32(jiffies);
333 data->arg.create.verifier[1] = cpu_to_be32(current->pid);
336 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
341 d_alias = nfs3_do_create(dir, dentry, data);
342 status = PTR_ERR_OR_ZERO(d_alias);
344 if (status != -ENOTSUPP)
346 /* If the server doesn't support the exclusive creation
347 * semantics, try again with simple 'guarded' mode. */
348 switch (data->arg.create.createmode) {
349 case NFS3_CREATE_EXCLUSIVE:
350 data->arg.create.createmode = NFS3_CREATE_GUARDED;
353 case NFS3_CREATE_GUARDED:
354 data->arg.create.createmode = NFS3_CREATE_UNCHECKED;
357 case NFS3_CREATE_UNCHECKED:
360 nfs_fattr_init(data->res.dir_attr);
361 nfs_fattr_init(data->res.fattr);
365 goto out_release_acls;
370 /* When we created the file with exclusive semantics, make
371 * sure we set the attributes afterwards. */
372 if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) {
373 dprintk("NFS call setattr (post-create)\n");
375 if (!(sattr->ia_valid & ATTR_ATIME_SET))
376 sattr->ia_valid |= ATTR_ATIME;
377 if (!(sattr->ia_valid & ATTR_MTIME_SET))
378 sattr->ia_valid |= ATTR_MTIME;
380 /* Note: we could use a guarded setattr here, but I'm
381 * not sure this buys us anything (and I'd have
382 * to revamp the NFSv3 XDR code) */
383 status = nfs3_proc_setattr(dentry, data->res.fattr, sattr);
384 nfs_post_op_update_inode(d_inode(dentry), data->res.fattr);
385 dprintk("NFS reply setattr (post-create): %d\n", status);
390 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
395 posix_acl_release(acl);
396 posix_acl_release(default_acl);
398 nfs3_free_createdata(data);
399 dprintk("NFS reply create: %d\n", status);
404 nfs3_proc_remove(struct inode *dir, struct dentry *dentry)
406 struct nfs_removeargs arg = {
408 .name = dentry->d_name,
410 struct nfs_removeres res;
411 struct rpc_message msg = {
412 .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE],
416 int status = -ENOMEM;
418 dprintk("NFS call remove %pd2\n", dentry);
419 res.dir_attr = nfs_alloc_fattr();
420 if (res.dir_attr == NULL)
423 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
424 nfs_post_op_update_inode(dir, res.dir_attr);
425 nfs_free_fattr(res.dir_attr);
427 dprintk("NFS reply remove: %d\n", status);
432 nfs3_proc_unlink_setup(struct rpc_message *msg,
433 struct dentry *dentry,
436 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
439 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
441 rpc_call_start(task);
445 nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
447 struct nfs_removeres *res;
448 if (nfs3_async_handle_jukebox(task, dir))
450 res = task->tk_msg.rpc_resp;
451 nfs_post_op_update_inode(dir, res->dir_attr);
456 nfs3_proc_rename_setup(struct rpc_message *msg,
457 struct dentry *old_dentry,
458 struct dentry *new_dentry)
460 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
463 static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
465 rpc_call_start(task);
469 nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
470 struct inode *new_dir)
472 struct nfs_renameres *res;
474 if (nfs3_async_handle_jukebox(task, old_dir))
476 res = task->tk_msg.rpc_resp;
478 nfs_post_op_update_inode(old_dir, res->old_fattr);
479 nfs_post_op_update_inode(new_dir, res->new_fattr);
484 nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name)
486 struct nfs3_linkargs arg = {
487 .fromfh = NFS_FH(inode),
489 .toname = name->name,
492 struct nfs3_linkres res;
493 struct rpc_message msg = {
494 .rpc_proc = &nfs3_procedures[NFS3PROC_LINK],
498 int status = -ENOMEM;
500 dprintk("NFS call link %s\n", name->name);
501 res.fattr = nfs_alloc_fattr();
502 res.dir_attr = nfs_alloc_fattr();
503 if (res.fattr == NULL || res.dir_attr == NULL)
506 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
507 nfs_post_op_update_inode(dir, res.dir_attr);
508 nfs_post_op_update_inode(inode, res.fattr);
510 nfs_free_fattr(res.dir_attr);
511 nfs_free_fattr(res.fattr);
512 dprintk("NFS reply link: %d\n", status);
517 nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
518 unsigned int len, struct iattr *sattr)
520 struct nfs3_createdata *data;
521 struct dentry *d_alias;
522 int status = -ENOMEM;
524 if (len > NFS3_MAXPATHLEN)
525 return -ENAMETOOLONG;
527 dprintk("NFS call symlink %pd\n", dentry);
529 data = nfs3_alloc_createdata();
532 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK];
533 data->arg.symlink.fromfh = NFS_FH(dir);
534 data->arg.symlink.fromname = dentry->d_name.name;
535 data->arg.symlink.fromlen = dentry->d_name.len;
536 data->arg.symlink.pages = &page;
537 data->arg.symlink.pathlen = len;
538 data->arg.symlink.sattr = sattr;
540 d_alias = nfs3_do_create(dir, dentry, data);
541 status = PTR_ERR_OR_ZERO(d_alias);
546 nfs3_free_createdata(data);
548 dprintk("NFS reply symlink: %d\n", status);
553 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
555 struct posix_acl *default_acl, *acl;
556 struct nfs3_createdata *data;
557 struct dentry *d_alias;
558 int status = -ENOMEM;
560 dprintk("NFS call mkdir %pd\n", dentry);
562 data = nfs3_alloc_createdata();
566 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
570 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR];
571 data->arg.mkdir.fh = NFS_FH(dir);
572 data->arg.mkdir.name = dentry->d_name.name;
573 data->arg.mkdir.len = dentry->d_name.len;
574 data->arg.mkdir.sattr = sattr;
576 d_alias = nfs3_do_create(dir, dentry, data);
577 status = PTR_ERR_OR_ZERO(d_alias);
580 goto out_release_acls;
585 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
589 posix_acl_release(acl);
590 posix_acl_release(default_acl);
592 nfs3_free_createdata(data);
593 dprintk("NFS reply mkdir: %d\n", status);
598 nfs3_proc_rmdir(struct inode *dir, const struct qstr *name)
600 struct nfs_fattr *dir_attr;
601 struct nfs3_diropargs arg = {
606 struct rpc_message msg = {
607 .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR],
610 int status = -ENOMEM;
612 dprintk("NFS call rmdir %s\n", name->name);
613 dir_attr = nfs_alloc_fattr();
614 if (dir_attr == NULL)
617 msg.rpc_resp = dir_attr;
618 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
619 nfs_post_op_update_inode(dir, dir_attr);
620 nfs_free_fattr(dir_attr);
622 dprintk("NFS reply rmdir: %d\n", status);
627 * The READDIR implementation is somewhat hackish - we pass the user buffer
628 * to the encode function, which installs it in the receive iovec.
629 * The decode function itself doesn't perform any decoding, it just makes
630 * sure the reply is syntactically correct.
632 * Also note that this implementation handles both plain readdir and
636 nfs3_proc_readdir(struct dentry *dentry, const struct cred *cred,
637 u64 cookie, struct page **pages, unsigned int count, bool plus)
639 struct inode *dir = d_inode(dentry);
640 __be32 *verf = NFS_I(dir)->cookieverf;
641 struct nfs3_readdirargs arg = {
644 .verf = {verf[0], verf[1]},
649 struct nfs3_readdirres res = {
653 struct rpc_message msg = {
654 .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR],
659 int status = -ENOMEM;
662 msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
664 dprintk("NFS call readdir%s %d\n",
665 plus? "plus" : "", (unsigned int) cookie);
667 res.dir_attr = nfs_alloc_fattr();
668 if (res.dir_attr == NULL)
671 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
673 nfs_invalidate_atime(dir);
674 nfs_refresh_inode(dir, res.dir_attr);
676 nfs_free_fattr(res.dir_attr);
678 dprintk("NFS reply readdir%s: %d\n",
679 plus? "plus" : "", status);
684 nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
687 struct posix_acl *default_acl, *acl;
688 struct nfs3_createdata *data;
689 struct dentry *d_alias;
690 int status = -ENOMEM;
692 dprintk("NFS call mknod %pd %u:%u\n", dentry,
693 MAJOR(rdev), MINOR(rdev));
695 data = nfs3_alloc_createdata();
699 status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl);
703 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD];
704 data->arg.mknod.fh = NFS_FH(dir);
705 data->arg.mknod.name = dentry->d_name.name;
706 data->arg.mknod.len = dentry->d_name.len;
707 data->arg.mknod.sattr = sattr;
708 data->arg.mknod.rdev = rdev;
710 switch (sattr->ia_mode & S_IFMT) {
712 data->arg.mknod.type = NF3BLK;
715 data->arg.mknod.type = NF3CHR;
718 data->arg.mknod.type = NF3FIFO;
721 data->arg.mknod.type = NF3SOCK;
728 d_alias = nfs3_do_create(dir, dentry, data);
729 status = PTR_ERR_OR_ZERO(d_alias);
731 goto out_release_acls;
736 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl);
740 posix_acl_release(acl);
741 posix_acl_release(default_acl);
743 nfs3_free_createdata(data);
744 dprintk("NFS reply mknod: %d\n", status);
749 nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
750 struct nfs_fsstat *stat)
752 struct rpc_message msg = {
753 .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT],
759 dprintk("NFS call fsstat\n");
760 nfs_fattr_init(stat->fattr);
761 status = rpc_call_sync(server->client, &msg, 0);
762 dprintk("NFS reply fsstat: %d\n", status);
767 do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle,
768 struct nfs_fsinfo *info)
770 struct rpc_message msg = {
771 .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO],
777 dprintk("NFS call fsinfo\n");
778 nfs_fattr_init(info->fattr);
779 status = rpc_call_sync(client, &msg, 0);
780 dprintk("NFS reply fsinfo: %d\n", status);
785 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
789 nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
790 struct nfs_fsinfo *info)
794 status = do_proc_fsinfo(server->client, fhandle, info);
795 if (status && server->nfs_client->cl_rpcclient != server->client)
796 status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info);
801 nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
802 struct nfs_pathconf *info)
804 struct rpc_message msg = {
805 .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF],
811 dprintk("NFS call pathconf\n");
812 nfs_fattr_init(info->fattr);
813 status = rpc_call_sync(server->client, &msg, 0);
814 dprintk("NFS reply pathconf: %d\n", status);
818 static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
820 struct inode *inode = hdr->inode;
821 struct nfs_server *server = NFS_SERVER(inode);
823 if (hdr->pgio_done_cb != NULL)
824 return hdr->pgio_done_cb(task, hdr);
826 if (nfs3_async_handle_jukebox(task, inode))
829 if (task->tk_status >= 0 && !server->read_hdrsize)
830 cmpxchg(&server->read_hdrsize, 0, hdr->res.replen);
832 nfs_invalidate_atime(inode);
833 nfs_refresh_inode(inode, &hdr->fattr);
837 static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr,
838 struct rpc_message *msg)
840 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
841 hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize;
844 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task,
845 struct nfs_pgio_header *hdr)
847 rpc_call_start(task);
851 static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr)
853 struct inode *inode = hdr->inode;
855 if (hdr->pgio_done_cb != NULL)
856 return hdr->pgio_done_cb(task, hdr);
858 if (nfs3_async_handle_jukebox(task, inode))
860 if (task->tk_status >= 0)
861 nfs_writeback_update_inode(hdr);
865 static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr,
866 struct rpc_message *msg,
867 struct rpc_clnt **clnt)
869 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
872 static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
874 rpc_call_start(task);
877 static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
879 if (data->commit_done_cb != NULL)
880 return data->commit_done_cb(task, data);
882 if (nfs3_async_handle_jukebox(task, data->inode))
884 nfs_refresh_inode(data->inode, data->res.fattr);
888 static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg,
889 struct rpc_clnt **clnt)
891 msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT];
894 static void nfs3_nlm_alloc_call(void *data)
896 struct nfs_lock_context *l_ctx = data;
897 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
898 get_nfs_open_context(l_ctx->open_context);
899 nfs_get_lock_context(l_ctx->open_context);
903 static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data)
905 struct nfs_lock_context *l_ctx = data;
906 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags))
907 return nfs_async_iocounter_wait(task, l_ctx);
912 static void nfs3_nlm_release_call(void *data)
914 struct nfs_lock_context *l_ctx = data;
915 struct nfs_open_context *ctx;
916 if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) {
917 ctx = l_ctx->open_context;
918 nfs_put_lock_context(l_ctx);
919 put_nfs_open_context(ctx);
923 static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = {
924 .nlmclnt_alloc_call = nfs3_nlm_alloc_call,
925 .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare,
926 .nlmclnt_release_call = nfs3_nlm_release_call,
930 nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
932 struct inode *inode = file_inode(filp);
933 struct nfs_lock_context *l_ctx = NULL;
934 struct nfs_open_context *ctx = nfs_file_open_context(filp);
937 if (fl->fl_flags & FL_CLOSE) {
938 l_ctx = nfs_get_lock_context(ctx);
942 set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
945 status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx);
948 nfs_put_lock_context(l_ctx);
953 static int nfs3_have_delegation(struct inode *inode, fmode_t flags)
958 static const struct inode_operations nfs3_dir_inode_operations = {
959 .create = nfs_create,
960 .lookup = nfs_lookup,
962 .unlink = nfs_unlink,
963 .symlink = nfs_symlink,
967 .rename = nfs_rename,
968 .permission = nfs_permission,
969 .getattr = nfs_getattr,
970 .setattr = nfs_setattr,
971 #ifdef CONFIG_NFS_V3_ACL
972 .listxattr = nfs3_listxattr,
973 .get_acl = nfs3_get_acl,
974 .set_acl = nfs3_set_acl,
978 static const struct inode_operations nfs3_file_inode_operations = {
979 .permission = nfs_permission,
980 .getattr = nfs_getattr,
981 .setattr = nfs_setattr,
982 #ifdef CONFIG_NFS_V3_ACL
983 .listxattr = nfs3_listxattr,
984 .get_acl = nfs3_get_acl,
985 .set_acl = nfs3_set_acl,
989 const struct nfs_rpc_ops nfs_v3_clientops = {
990 .version = 3, /* protocol version */
991 .dentry_ops = &nfs_dentry_operations,
992 .dir_inode_ops = &nfs3_dir_inode_operations,
993 .file_inode_ops = &nfs3_file_inode_operations,
994 .file_ops = &nfs_file_operations,
995 .nlmclnt_ops = &nlmclnt_fl_close_lock_ops,
996 .getroot = nfs3_proc_get_root,
997 .submount = nfs_submount,
998 .try_get_tree = nfs_try_get_tree,
999 .getattr = nfs3_proc_getattr,
1000 .setattr = nfs3_proc_setattr,
1001 .lookup = nfs3_proc_lookup,
1002 .access = nfs3_proc_access,
1003 .readlink = nfs3_proc_readlink,
1004 .create = nfs3_proc_create,
1005 .remove = nfs3_proc_remove,
1006 .unlink_setup = nfs3_proc_unlink_setup,
1007 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
1008 .unlink_done = nfs3_proc_unlink_done,
1009 .rename_setup = nfs3_proc_rename_setup,
1010 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
1011 .rename_done = nfs3_proc_rename_done,
1012 .link = nfs3_proc_link,
1013 .symlink = nfs3_proc_symlink,
1014 .mkdir = nfs3_proc_mkdir,
1015 .rmdir = nfs3_proc_rmdir,
1016 .readdir = nfs3_proc_readdir,
1017 .mknod = nfs3_proc_mknod,
1018 .statfs = nfs3_proc_statfs,
1019 .fsinfo = nfs3_proc_fsinfo,
1020 .pathconf = nfs3_proc_pathconf,
1021 .decode_dirent = nfs3_decode_dirent,
1022 .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare,
1023 .read_setup = nfs3_proc_read_setup,
1024 .read_done = nfs3_read_done,
1025 .write_setup = nfs3_proc_write_setup,
1026 .write_done = nfs3_write_done,
1027 .commit_setup = nfs3_proc_commit_setup,
1028 .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare,
1029 .commit_done = nfs3_commit_done,
1030 .lock = nfs3_proc_lock,
1031 .clear_acl_cache = forget_all_cached_acls,
1032 .close_context = nfs_close_context,
1033 .have_delegation = nfs3_have_delegation,
1034 .alloc_client = nfs_alloc_client,
1035 .init_client = nfs_init_client,
1036 .free_client = nfs_free_client,
1037 .create_server = nfs3_create_server,
1038 .clone_server = nfs3_clone_server,