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
)
106 struct rpc_message msg
= {
107 .rpc_proc
= &nfs3_procedures
[NFS3PROC_GETATTR
],
113 dprintk("NFS call getattr\n");
114 nfs_fattr_init(fattr
);
115 status
= rpc_call_sync(server
->client
, &msg
, 0);
116 dprintk("NFS reply getattr: %d\n", status
);
121 nfs3_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
124 struct inode
*inode
= d_inode(dentry
);
125 struct nfs3_sattrargs arg
= {
129 struct rpc_message msg
= {
130 .rpc_proc
= &nfs3_procedures
[NFS3PROC_SETATTR
],
136 dprintk("NFS call setattr\n");
137 if (sattr
->ia_valid
& ATTR_FILE
)
138 msg
.rpc_cred
= nfs_file_cred(sattr
->ia_file
);
139 nfs_fattr_init(fattr
);
140 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
142 nfs_setattr_update_inode(inode
, sattr
, fattr
);
143 dprintk("NFS reply setattr: %d\n", status
);
148 nfs3_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
149 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
150 struct nfs4_label
*label
)
152 struct nfs3_diropargs arg
= {
157 struct nfs3_diropres res
= {
161 struct rpc_message msg
= {
162 .rpc_proc
= &nfs3_procedures
[NFS3PROC_LOOKUP
],
168 dprintk("NFS call lookup %s\n", name
->name
);
169 res
.dir_attr
= nfs_alloc_fattr();
170 if (res
.dir_attr
== NULL
)
173 nfs_fattr_init(fattr
);
174 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
175 nfs_refresh_inode(dir
, res
.dir_attr
);
176 if (status
>= 0 && !(fattr
->valid
& NFS_ATTR_FATTR
)) {
177 msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_GETATTR
];
178 msg
.rpc_argp
= fhandle
;
179 msg
.rpc_resp
= fattr
;
180 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
182 nfs_free_fattr(res
.dir_attr
);
183 dprintk("NFS reply lookup: %d\n", status
);
187 static int nfs3_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
189 struct nfs3_accessargs arg
= {
192 struct nfs3_accessres res
;
193 struct rpc_message msg
= {
194 .rpc_proc
= &nfs3_procedures
[NFS3PROC_ACCESS
],
197 .rpc_cred
= entry
->cred
,
199 int mode
= entry
->mask
;
200 int status
= -ENOMEM
;
202 dprintk("NFS call access\n");
205 arg
.access
|= NFS3_ACCESS_READ
;
206 if (S_ISDIR(inode
->i_mode
)) {
207 if (mode
& MAY_WRITE
)
208 arg
.access
|= NFS3_ACCESS_MODIFY
| NFS3_ACCESS_EXTEND
| NFS3_ACCESS_DELETE
;
210 arg
.access
|= NFS3_ACCESS_LOOKUP
;
212 if (mode
& MAY_WRITE
)
213 arg
.access
|= NFS3_ACCESS_MODIFY
| NFS3_ACCESS_EXTEND
;
215 arg
.access
|= NFS3_ACCESS_EXECUTE
;
218 res
.fattr
= nfs_alloc_fattr();
219 if (res
.fattr
== NULL
)
222 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
223 nfs_refresh_inode(inode
, res
.fattr
);
225 nfs_access_set_mask(entry
, res
.access
);
226 nfs_free_fattr(res
.fattr
);
228 dprintk("NFS reply access: %d\n", status
);
232 static int nfs3_proc_readlink(struct inode
*inode
, struct page
*page
,
233 unsigned int pgbase
, unsigned int pglen
)
235 struct nfs_fattr
*fattr
;
236 struct nfs3_readlinkargs args
= {
242 struct rpc_message msg
= {
243 .rpc_proc
= &nfs3_procedures
[NFS3PROC_READLINK
],
246 int status
= -ENOMEM
;
248 dprintk("NFS call readlink\n");
249 fattr
= nfs_alloc_fattr();
252 msg
.rpc_resp
= fattr
;
254 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
255 nfs_refresh_inode(inode
, fattr
);
256 nfs_free_fattr(fattr
);
258 dprintk("NFS reply readlink: %d\n", status
);
262 struct nfs3_createdata
{
263 struct rpc_message msg
;
265 struct nfs3_createargs create
;
266 struct nfs3_mkdirargs mkdir
;
267 struct nfs3_symlinkargs symlink
;
268 struct nfs3_mknodargs mknod
;
270 struct nfs3_diropres res
;
272 struct nfs_fattr fattr
;
273 struct nfs_fattr dir_attr
;
276 static struct nfs3_createdata
*nfs3_alloc_createdata(void)
278 struct nfs3_createdata
*data
;
280 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
282 data
->msg
.rpc_argp
= &data
->arg
;
283 data
->msg
.rpc_resp
= &data
->res
;
284 data
->res
.fh
= &data
->fh
;
285 data
->res
.fattr
= &data
->fattr
;
286 data
->res
.dir_attr
= &data
->dir_attr
;
287 nfs_fattr_init(data
->res
.fattr
);
288 nfs_fattr_init(data
->res
.dir_attr
);
293 static int nfs3_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs3_createdata
*data
)
297 status
= rpc_call_sync(NFS_CLIENT(dir
), &data
->msg
, 0);
298 nfs_post_op_update_inode(dir
, data
->res
.dir_attr
);
300 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, NULL
);
304 static void nfs3_free_createdata(struct nfs3_createdata
*data
)
310 * Create a regular file.
313 nfs3_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
316 struct posix_acl
*default_acl
, *acl
;
317 struct nfs3_createdata
*data
;
318 int status
= -ENOMEM
;
320 dprintk("NFS call create %pd\n", dentry
);
322 data
= nfs3_alloc_createdata();
326 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_CREATE
];
327 data
->arg
.create
.fh
= NFS_FH(dir
);
328 data
->arg
.create
.name
= dentry
->d_name
.name
;
329 data
->arg
.create
.len
= dentry
->d_name
.len
;
330 data
->arg
.create
.sattr
= sattr
;
332 data
->arg
.create
.createmode
= NFS3_CREATE_UNCHECKED
;
333 if (flags
& O_EXCL
) {
334 data
->arg
.create
.createmode
= NFS3_CREATE_EXCLUSIVE
;
335 data
->arg
.create
.verifier
[0] = cpu_to_be32(jiffies
);
336 data
->arg
.create
.verifier
[1] = cpu_to_be32(current
->pid
);
339 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
344 status
= nfs3_do_create(dir
, dentry
, data
);
346 if (status
!= -ENOTSUPP
)
348 /* If the server doesn't support the exclusive creation
349 * semantics, try again with simple 'guarded' mode. */
350 switch (data
->arg
.create
.createmode
) {
351 case NFS3_CREATE_EXCLUSIVE
:
352 data
->arg
.create
.createmode
= NFS3_CREATE_GUARDED
;
355 case NFS3_CREATE_GUARDED
:
356 data
->arg
.create
.createmode
= NFS3_CREATE_UNCHECKED
;
359 case NFS3_CREATE_UNCHECKED
:
362 nfs_fattr_init(data
->res
.dir_attr
);
363 nfs_fattr_init(data
->res
.fattr
);
367 goto out_release_acls
;
369 /* When we created the file with exclusive semantics, make
370 * sure we set the attributes afterwards. */
371 if (data
->arg
.create
.createmode
== NFS3_CREATE_EXCLUSIVE
) {
372 dprintk("NFS call setattr (post-create)\n");
374 if (!(sattr
->ia_valid
& ATTR_ATIME_SET
))
375 sattr
->ia_valid
|= ATTR_ATIME
;
376 if (!(sattr
->ia_valid
& ATTR_MTIME_SET
))
377 sattr
->ia_valid
|= ATTR_MTIME
;
379 /* Note: we could use a guarded setattr here, but I'm
380 * not sure this buys us anything (and I'd have
381 * to revamp the NFSv3 XDR code) */
382 status
= nfs3_proc_setattr(dentry
, data
->res
.fattr
, sattr
);
383 nfs_post_op_update_inode(d_inode(dentry
), data
->res
.fattr
);
384 dprintk("NFS reply setattr (post-create): %d\n", status
);
386 goto out_release_acls
;
389 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
392 posix_acl_release(acl
);
393 posix_acl_release(default_acl
);
395 nfs3_free_createdata(data
);
396 dprintk("NFS reply create: %d\n", status
);
401 nfs3_proc_remove(struct inode
*dir
, const struct qstr
*name
)
403 struct nfs_removeargs arg
= {
407 struct nfs_removeres res
;
408 struct rpc_message msg
= {
409 .rpc_proc
= &nfs3_procedures
[NFS3PROC_REMOVE
],
413 int status
= -ENOMEM
;
415 dprintk("NFS call remove %s\n", name
->name
);
416 res
.dir_attr
= nfs_alloc_fattr();
417 if (res
.dir_attr
== NULL
)
420 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
421 nfs_post_op_update_inode(dir
, res
.dir_attr
);
422 nfs_free_fattr(res
.dir_attr
);
424 dprintk("NFS reply remove: %d\n", status
);
429 nfs3_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
431 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_REMOVE
];
434 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
436 rpc_call_start(task
);
440 nfs3_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
442 struct nfs_removeres
*res
;
443 if (nfs3_async_handle_jukebox(task
, dir
))
445 res
= task
->tk_msg
.rpc_resp
;
446 nfs_post_op_update_inode(dir
, res
->dir_attr
);
451 nfs3_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
453 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_RENAME
];
456 static void nfs3_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
458 rpc_call_start(task
);
462 nfs3_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
463 struct inode
*new_dir
)
465 struct nfs_renameres
*res
;
467 if (nfs3_async_handle_jukebox(task
, old_dir
))
469 res
= task
->tk_msg
.rpc_resp
;
471 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
472 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
477 nfs3_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
479 struct nfs3_linkargs arg
= {
480 .fromfh
= NFS_FH(inode
),
482 .toname
= name
->name
,
485 struct nfs3_linkres res
;
486 struct rpc_message msg
= {
487 .rpc_proc
= &nfs3_procedures
[NFS3PROC_LINK
],
491 int status
= -ENOMEM
;
493 dprintk("NFS call link %s\n", name
->name
);
494 res
.fattr
= nfs_alloc_fattr();
495 res
.dir_attr
= nfs_alloc_fattr();
496 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
499 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
500 nfs_post_op_update_inode(dir
, res
.dir_attr
);
501 nfs_post_op_update_inode(inode
, res
.fattr
);
503 nfs_free_fattr(res
.dir_attr
);
504 nfs_free_fattr(res
.fattr
);
505 dprintk("NFS reply link: %d\n", status
);
510 nfs3_proc_symlink(struct inode
*dir
, struct dentry
*dentry
, struct page
*page
,
511 unsigned int len
, struct iattr
*sattr
)
513 struct nfs3_createdata
*data
;
514 int status
= -ENOMEM
;
516 if (len
> NFS3_MAXPATHLEN
)
517 return -ENAMETOOLONG
;
519 dprintk("NFS call symlink %pd\n", dentry
);
521 data
= nfs3_alloc_createdata();
524 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_SYMLINK
];
525 data
->arg
.symlink
.fromfh
= NFS_FH(dir
);
526 data
->arg
.symlink
.fromname
= dentry
->d_name
.name
;
527 data
->arg
.symlink
.fromlen
= dentry
->d_name
.len
;
528 data
->arg
.symlink
.pages
= &page
;
529 data
->arg
.symlink
.pathlen
= len
;
530 data
->arg
.symlink
.sattr
= sattr
;
532 status
= nfs3_do_create(dir
, dentry
, data
);
534 nfs3_free_createdata(data
);
536 dprintk("NFS reply symlink: %d\n", status
);
541 nfs3_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
)
543 struct posix_acl
*default_acl
, *acl
;
544 struct nfs3_createdata
*data
;
545 int status
= -ENOMEM
;
547 dprintk("NFS call mkdir %pd\n", dentry
);
549 data
= nfs3_alloc_createdata();
553 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
557 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_MKDIR
];
558 data
->arg
.mkdir
.fh
= NFS_FH(dir
);
559 data
->arg
.mkdir
.name
= dentry
->d_name
.name
;
560 data
->arg
.mkdir
.len
= dentry
->d_name
.len
;
561 data
->arg
.mkdir
.sattr
= sattr
;
563 status
= nfs3_do_create(dir
, dentry
, data
);
565 goto out_release_acls
;
567 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
570 posix_acl_release(acl
);
571 posix_acl_release(default_acl
);
573 nfs3_free_createdata(data
);
574 dprintk("NFS reply mkdir: %d\n", status
);
579 nfs3_proc_rmdir(struct inode
*dir
, const struct qstr
*name
)
581 struct nfs_fattr
*dir_attr
;
582 struct nfs3_diropargs arg
= {
587 struct rpc_message msg
= {
588 .rpc_proc
= &nfs3_procedures
[NFS3PROC_RMDIR
],
591 int status
= -ENOMEM
;
593 dprintk("NFS call rmdir %s\n", name
->name
);
594 dir_attr
= nfs_alloc_fattr();
595 if (dir_attr
== NULL
)
598 msg
.rpc_resp
= dir_attr
;
599 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
600 nfs_post_op_update_inode(dir
, dir_attr
);
601 nfs_free_fattr(dir_attr
);
603 dprintk("NFS reply rmdir: %d\n", status
);
608 * The READDIR implementation is somewhat hackish - we pass the user buffer
609 * to the encode function, which installs it in the receive iovec.
610 * The decode function itself doesn't perform any decoding, it just makes
611 * sure the reply is syntactically correct.
613 * Also note that this implementation handles both plain readdir and
617 nfs3_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
618 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
620 struct inode
*dir
= d_inode(dentry
);
621 __be32
*verf
= NFS_I(dir
)->cookieverf
;
622 struct nfs3_readdirargs arg
= {
625 .verf
= {verf
[0], verf
[1]},
630 struct nfs3_readdirres res
= {
634 struct rpc_message msg
= {
635 .rpc_proc
= &nfs3_procedures
[NFS3PROC_READDIR
],
640 int status
= -ENOMEM
;
643 msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_READDIRPLUS
];
645 dprintk("NFS call readdir%s %d\n",
646 plus
? "plus" : "", (unsigned int) cookie
);
648 res
.dir_attr
= nfs_alloc_fattr();
649 if (res
.dir_attr
== NULL
)
652 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
654 nfs_invalidate_atime(dir
);
655 nfs_refresh_inode(dir
, res
.dir_attr
);
657 nfs_free_fattr(res
.dir_attr
);
659 dprintk("NFS reply readdir%s: %d\n",
660 plus
? "plus" : "", status
);
665 nfs3_proc_mknod(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
668 struct posix_acl
*default_acl
, *acl
;
669 struct nfs3_createdata
*data
;
670 int status
= -ENOMEM
;
672 dprintk("NFS call mknod %pd %u:%u\n", dentry
,
673 MAJOR(rdev
), MINOR(rdev
));
675 data
= nfs3_alloc_createdata();
679 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
683 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_MKNOD
];
684 data
->arg
.mknod
.fh
= NFS_FH(dir
);
685 data
->arg
.mknod
.name
= dentry
->d_name
.name
;
686 data
->arg
.mknod
.len
= dentry
->d_name
.len
;
687 data
->arg
.mknod
.sattr
= sattr
;
688 data
->arg
.mknod
.rdev
= rdev
;
690 switch (sattr
->ia_mode
& S_IFMT
) {
692 data
->arg
.mknod
.type
= NF3BLK
;
695 data
->arg
.mknod
.type
= NF3CHR
;
698 data
->arg
.mknod
.type
= NF3FIFO
;
701 data
->arg
.mknod
.type
= NF3SOCK
;
708 status
= nfs3_do_create(dir
, dentry
, data
);
710 goto out_release_acls
;
712 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
715 posix_acl_release(acl
);
716 posix_acl_release(default_acl
);
718 nfs3_free_createdata(data
);
719 dprintk("NFS reply mknod: %d\n", status
);
724 nfs3_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
725 struct nfs_fsstat
*stat
)
727 struct rpc_message msg
= {
728 .rpc_proc
= &nfs3_procedures
[NFS3PROC_FSSTAT
],
734 dprintk("NFS call fsstat\n");
735 nfs_fattr_init(stat
->fattr
);
736 status
= rpc_call_sync(server
->client
, &msg
, 0);
737 dprintk("NFS reply fsstat: %d\n", status
);
742 do_proc_fsinfo(struct rpc_clnt
*client
, struct nfs_fh
*fhandle
,
743 struct nfs_fsinfo
*info
)
745 struct rpc_message msg
= {
746 .rpc_proc
= &nfs3_procedures
[NFS3PROC_FSINFO
],
752 dprintk("NFS call fsinfo\n");
753 nfs_fattr_init(info
->fattr
);
754 status
= rpc_call_sync(client
, &msg
, 0);
755 dprintk("NFS reply fsinfo: %d\n", status
);
760 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
764 nfs3_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
765 struct nfs_fsinfo
*info
)
769 status
= do_proc_fsinfo(server
->client
, fhandle
, info
);
770 if (status
&& server
->nfs_client
->cl_rpcclient
!= server
->client
)
771 status
= do_proc_fsinfo(server
->nfs_client
->cl_rpcclient
, fhandle
, info
);
776 nfs3_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
777 struct nfs_pathconf
*info
)
779 struct rpc_message msg
= {
780 .rpc_proc
= &nfs3_procedures
[NFS3PROC_PATHCONF
],
786 dprintk("NFS call pathconf\n");
787 nfs_fattr_init(info
->fattr
);
788 status
= rpc_call_sync(server
->client
, &msg
, 0);
789 dprintk("NFS reply pathconf: %d\n", status
);
793 static int nfs3_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
795 struct inode
*inode
= hdr
->inode
;
797 if (hdr
->pgio_done_cb
!= NULL
)
798 return hdr
->pgio_done_cb(task
, hdr
);
800 if (nfs3_async_handle_jukebox(task
, inode
))
803 nfs_invalidate_atime(inode
);
804 nfs_refresh_inode(inode
, &hdr
->fattr
);
808 static void nfs3_proc_read_setup(struct nfs_pgio_header
*hdr
,
809 struct rpc_message
*msg
)
811 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_READ
];
814 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task
*task
,
815 struct nfs_pgio_header
*hdr
)
817 rpc_call_start(task
);
821 static int nfs3_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
823 struct inode
*inode
= hdr
->inode
;
825 if (hdr
->pgio_done_cb
!= NULL
)
826 return hdr
->pgio_done_cb(task
, hdr
);
828 if (nfs3_async_handle_jukebox(task
, inode
))
830 if (task
->tk_status
>= 0)
831 nfs_writeback_update_inode(hdr
);
835 static void nfs3_proc_write_setup(struct nfs_pgio_header
*hdr
,
836 struct rpc_message
*msg
)
838 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_WRITE
];
841 static void nfs3_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
843 rpc_call_start(task
);
846 static int nfs3_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
848 if (data
->commit_done_cb
!= NULL
)
849 return data
->commit_done_cb(task
, data
);
851 if (nfs3_async_handle_jukebox(task
, data
->inode
))
853 nfs_refresh_inode(data
->inode
, data
->res
.fattr
);
857 static void nfs3_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
859 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_COMMIT
];
862 static void nfs3_nlm_alloc_call(void *data
)
864 struct nfs_lock_context
*l_ctx
= data
;
865 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
)) {
866 get_nfs_open_context(l_ctx
->open_context
);
867 nfs_get_lock_context(l_ctx
->open_context
);
871 static bool nfs3_nlm_unlock_prepare(struct rpc_task
*task
, void *data
)
873 struct nfs_lock_context
*l_ctx
= data
;
874 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
))
875 return nfs_async_iocounter_wait(task
, l_ctx
);
880 static void nfs3_nlm_release_call(void *data
)
882 struct nfs_lock_context
*l_ctx
= data
;
883 struct nfs_open_context
*ctx
;
884 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
)) {
885 ctx
= l_ctx
->open_context
;
886 nfs_put_lock_context(l_ctx
);
887 put_nfs_open_context(ctx
);
891 const struct nlmclnt_operations nlmclnt_fl_close_lock_ops
= {
892 .nlmclnt_alloc_call
= nfs3_nlm_alloc_call
,
893 .nlmclnt_unlock_prepare
= nfs3_nlm_unlock_prepare
,
894 .nlmclnt_release_call
= nfs3_nlm_release_call
,
898 nfs3_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*fl
)
900 struct inode
*inode
= file_inode(filp
);
901 struct nfs_lock_context
*l_ctx
= NULL
;
902 struct nfs_open_context
*ctx
= nfs_file_open_context(filp
);
905 if (fl
->fl_flags
& FL_CLOSE
) {
906 l_ctx
= nfs_get_lock_context(ctx
);
910 set_bit(NFS_CONTEXT_UNLOCK
, &ctx
->flags
);
913 status
= nlmclnt_proc(NFS_SERVER(inode
)->nlm_host
, cmd
, fl
, l_ctx
);
916 nfs_put_lock_context(l_ctx
);
921 static int nfs3_have_delegation(struct inode
*inode
, fmode_t flags
)
926 static int nfs3_return_delegation(struct inode
*inode
)
932 static const struct inode_operations nfs3_dir_inode_operations
= {
933 .create
= nfs_create
,
934 .lookup
= nfs_lookup
,
936 .unlink
= nfs_unlink
,
937 .symlink
= nfs_symlink
,
941 .rename
= nfs_rename
,
942 .permission
= nfs_permission
,
943 .getattr
= nfs_getattr
,
944 .setattr
= nfs_setattr
,
945 #ifdef CONFIG_NFS_V3_ACL
946 .listxattr
= nfs3_listxattr
,
947 .get_acl
= nfs3_get_acl
,
948 .set_acl
= nfs3_set_acl
,
952 static const struct inode_operations nfs3_file_inode_operations
= {
953 .permission
= nfs_permission
,
954 .getattr
= nfs_getattr
,
955 .setattr
= nfs_setattr
,
956 #ifdef CONFIG_NFS_V3_ACL
957 .listxattr
= nfs3_listxattr
,
958 .get_acl
= nfs3_get_acl
,
959 .set_acl
= nfs3_set_acl
,
963 const struct nfs_rpc_ops nfs_v3_clientops
= {
964 .version
= 3, /* protocol version */
965 .dentry_ops
= &nfs_dentry_operations
,
966 .dir_inode_ops
= &nfs3_dir_inode_operations
,
967 .file_inode_ops
= &nfs3_file_inode_operations
,
968 .file_ops
= &nfs_file_operations
,
969 .nlmclnt_ops
= &nlmclnt_fl_close_lock_ops
,
970 .getroot
= nfs3_proc_get_root
,
971 .submount
= nfs_submount
,
972 .try_mount
= nfs_try_mount
,
973 .getattr
= nfs3_proc_getattr
,
974 .setattr
= nfs3_proc_setattr
,
975 .lookup
= nfs3_proc_lookup
,
976 .access
= nfs3_proc_access
,
977 .readlink
= nfs3_proc_readlink
,
978 .create
= nfs3_proc_create
,
979 .remove
= nfs3_proc_remove
,
980 .unlink_setup
= nfs3_proc_unlink_setup
,
981 .unlink_rpc_prepare
= nfs3_proc_unlink_rpc_prepare
,
982 .unlink_done
= nfs3_proc_unlink_done
,
983 .rename_setup
= nfs3_proc_rename_setup
,
984 .rename_rpc_prepare
= nfs3_proc_rename_rpc_prepare
,
985 .rename_done
= nfs3_proc_rename_done
,
986 .link
= nfs3_proc_link
,
987 .symlink
= nfs3_proc_symlink
,
988 .mkdir
= nfs3_proc_mkdir
,
989 .rmdir
= nfs3_proc_rmdir
,
990 .readdir
= nfs3_proc_readdir
,
991 .mknod
= nfs3_proc_mknod
,
992 .statfs
= nfs3_proc_statfs
,
993 .fsinfo
= nfs3_proc_fsinfo
,
994 .pathconf
= nfs3_proc_pathconf
,
995 .decode_dirent
= nfs3_decode_dirent
,
996 .pgio_rpc_prepare
= nfs3_proc_pgio_rpc_prepare
,
997 .read_setup
= nfs3_proc_read_setup
,
998 .read_done
= nfs3_read_done
,
999 .write_setup
= nfs3_proc_write_setup
,
1000 .write_done
= nfs3_write_done
,
1001 .commit_setup
= nfs3_proc_commit_setup
,
1002 .commit_rpc_prepare
= nfs3_proc_commit_rpc_prepare
,
1003 .commit_done
= nfs3_commit_done
,
1004 .lock
= nfs3_proc_lock
,
1005 .clear_acl_cache
= forget_all_cached_acls
,
1006 .close_context
= nfs_close_context
,
1007 .have_delegation
= nfs3_have_delegation
,
1008 .return_delegation
= nfs3_return_delegation
,
1009 .alloc_client
= nfs_alloc_client
,
1010 .init_client
= nfs_init_client
,
1011 .free_client
= nfs_free_client
,
1012 .create_server
= nfs3_create_server
,
1013 .clone_server
= nfs3_clone_server
,