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
= {
191 .access
= entry
->mask
,
193 struct nfs3_accessres res
;
194 struct rpc_message msg
= {
195 .rpc_proc
= &nfs3_procedures
[NFS3PROC_ACCESS
],
198 .rpc_cred
= entry
->cred
,
200 int status
= -ENOMEM
;
202 dprintk("NFS call access\n");
203 res
.fattr
= nfs_alloc_fattr();
204 if (res
.fattr
== NULL
)
207 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
208 nfs_refresh_inode(inode
, res
.fattr
);
210 nfs_access_set_mask(entry
, res
.access
);
211 nfs_free_fattr(res
.fattr
);
213 dprintk("NFS reply access: %d\n", status
);
217 static int nfs3_proc_readlink(struct inode
*inode
, struct page
*page
,
218 unsigned int pgbase
, unsigned int pglen
)
220 struct nfs_fattr
*fattr
;
221 struct nfs3_readlinkargs args
= {
227 struct rpc_message msg
= {
228 .rpc_proc
= &nfs3_procedures
[NFS3PROC_READLINK
],
231 int status
= -ENOMEM
;
233 dprintk("NFS call readlink\n");
234 fattr
= nfs_alloc_fattr();
237 msg
.rpc_resp
= fattr
;
239 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
240 nfs_refresh_inode(inode
, fattr
);
241 nfs_free_fattr(fattr
);
243 dprintk("NFS reply readlink: %d\n", status
);
247 struct nfs3_createdata
{
248 struct rpc_message msg
;
250 struct nfs3_createargs create
;
251 struct nfs3_mkdirargs mkdir
;
252 struct nfs3_symlinkargs symlink
;
253 struct nfs3_mknodargs mknod
;
255 struct nfs3_diropres res
;
257 struct nfs_fattr fattr
;
258 struct nfs_fattr dir_attr
;
261 static struct nfs3_createdata
*nfs3_alloc_createdata(void)
263 struct nfs3_createdata
*data
;
265 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
267 data
->msg
.rpc_argp
= &data
->arg
;
268 data
->msg
.rpc_resp
= &data
->res
;
269 data
->res
.fh
= &data
->fh
;
270 data
->res
.fattr
= &data
->fattr
;
271 data
->res
.dir_attr
= &data
->dir_attr
;
272 nfs_fattr_init(data
->res
.fattr
);
273 nfs_fattr_init(data
->res
.dir_attr
);
278 static int nfs3_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs3_createdata
*data
)
282 status
= rpc_call_sync(NFS_CLIENT(dir
), &data
->msg
, 0);
283 nfs_post_op_update_inode(dir
, data
->res
.dir_attr
);
285 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, NULL
);
289 static void nfs3_free_createdata(struct nfs3_createdata
*data
)
295 * Create a regular file.
298 nfs3_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
301 struct posix_acl
*default_acl
, *acl
;
302 struct nfs3_createdata
*data
;
303 int status
= -ENOMEM
;
305 dprintk("NFS call create %pd\n", dentry
);
307 data
= nfs3_alloc_createdata();
311 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_CREATE
];
312 data
->arg
.create
.fh
= NFS_FH(dir
);
313 data
->arg
.create
.name
= dentry
->d_name
.name
;
314 data
->arg
.create
.len
= dentry
->d_name
.len
;
315 data
->arg
.create
.sattr
= sattr
;
317 data
->arg
.create
.createmode
= NFS3_CREATE_UNCHECKED
;
318 if (flags
& O_EXCL
) {
319 data
->arg
.create
.createmode
= NFS3_CREATE_EXCLUSIVE
;
320 data
->arg
.create
.verifier
[0] = cpu_to_be32(jiffies
);
321 data
->arg
.create
.verifier
[1] = cpu_to_be32(current
->pid
);
324 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
329 status
= nfs3_do_create(dir
, dentry
, data
);
331 if (status
!= -ENOTSUPP
)
333 /* If the server doesn't support the exclusive creation
334 * semantics, try again with simple 'guarded' mode. */
335 switch (data
->arg
.create
.createmode
) {
336 case NFS3_CREATE_EXCLUSIVE
:
337 data
->arg
.create
.createmode
= NFS3_CREATE_GUARDED
;
340 case NFS3_CREATE_GUARDED
:
341 data
->arg
.create
.createmode
= NFS3_CREATE_UNCHECKED
;
344 case NFS3_CREATE_UNCHECKED
:
347 nfs_fattr_init(data
->res
.dir_attr
);
348 nfs_fattr_init(data
->res
.fattr
);
352 goto out_release_acls
;
354 /* When we created the file with exclusive semantics, make
355 * sure we set the attributes afterwards. */
356 if (data
->arg
.create
.createmode
== NFS3_CREATE_EXCLUSIVE
) {
357 dprintk("NFS call setattr (post-create)\n");
359 if (!(sattr
->ia_valid
& ATTR_ATIME_SET
))
360 sattr
->ia_valid
|= ATTR_ATIME
;
361 if (!(sattr
->ia_valid
& ATTR_MTIME_SET
))
362 sattr
->ia_valid
|= ATTR_MTIME
;
364 /* Note: we could use a guarded setattr here, but I'm
365 * not sure this buys us anything (and I'd have
366 * to revamp the NFSv3 XDR code) */
367 status
= nfs3_proc_setattr(dentry
, data
->res
.fattr
, sattr
);
368 nfs_post_op_update_inode(d_inode(dentry
), data
->res
.fattr
);
369 dprintk("NFS reply setattr (post-create): %d\n", status
);
371 goto out_release_acls
;
374 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
377 posix_acl_release(acl
);
378 posix_acl_release(default_acl
);
380 nfs3_free_createdata(data
);
381 dprintk("NFS reply create: %d\n", status
);
386 nfs3_proc_remove(struct inode
*dir
, const struct qstr
*name
)
388 struct nfs_removeargs arg
= {
392 struct nfs_removeres res
;
393 struct rpc_message msg
= {
394 .rpc_proc
= &nfs3_procedures
[NFS3PROC_REMOVE
],
398 int status
= -ENOMEM
;
400 dprintk("NFS call remove %s\n", name
->name
);
401 res
.dir_attr
= nfs_alloc_fattr();
402 if (res
.dir_attr
== NULL
)
405 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
406 nfs_post_op_update_inode(dir
, res
.dir_attr
);
407 nfs_free_fattr(res
.dir_attr
);
409 dprintk("NFS reply remove: %d\n", status
);
414 nfs3_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
416 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_REMOVE
];
419 static void nfs3_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
421 rpc_call_start(task
);
425 nfs3_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
427 struct nfs_removeres
*res
;
428 if (nfs3_async_handle_jukebox(task
, dir
))
430 res
= task
->tk_msg
.rpc_resp
;
431 nfs_post_op_update_inode(dir
, res
->dir_attr
);
436 nfs3_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
438 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_RENAME
];
441 static void nfs3_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
443 rpc_call_start(task
);
447 nfs3_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
448 struct inode
*new_dir
)
450 struct nfs_renameres
*res
;
452 if (nfs3_async_handle_jukebox(task
, old_dir
))
454 res
= task
->tk_msg
.rpc_resp
;
456 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
457 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
462 nfs3_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
464 struct nfs3_linkargs arg
= {
465 .fromfh
= NFS_FH(inode
),
467 .toname
= name
->name
,
470 struct nfs3_linkres res
;
471 struct rpc_message msg
= {
472 .rpc_proc
= &nfs3_procedures
[NFS3PROC_LINK
],
476 int status
= -ENOMEM
;
478 dprintk("NFS call link %s\n", name
->name
);
479 res
.fattr
= nfs_alloc_fattr();
480 res
.dir_attr
= nfs_alloc_fattr();
481 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
484 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
485 nfs_post_op_update_inode(dir
, res
.dir_attr
);
486 nfs_post_op_update_inode(inode
, res
.fattr
);
488 nfs_free_fattr(res
.dir_attr
);
489 nfs_free_fattr(res
.fattr
);
490 dprintk("NFS reply link: %d\n", status
);
495 nfs3_proc_symlink(struct inode
*dir
, struct dentry
*dentry
, struct page
*page
,
496 unsigned int len
, struct iattr
*sattr
)
498 struct nfs3_createdata
*data
;
499 int status
= -ENOMEM
;
501 if (len
> NFS3_MAXPATHLEN
)
502 return -ENAMETOOLONG
;
504 dprintk("NFS call symlink %pd\n", dentry
);
506 data
= nfs3_alloc_createdata();
509 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_SYMLINK
];
510 data
->arg
.symlink
.fromfh
= NFS_FH(dir
);
511 data
->arg
.symlink
.fromname
= dentry
->d_name
.name
;
512 data
->arg
.symlink
.fromlen
= dentry
->d_name
.len
;
513 data
->arg
.symlink
.pages
= &page
;
514 data
->arg
.symlink
.pathlen
= len
;
515 data
->arg
.symlink
.sattr
= sattr
;
517 status
= nfs3_do_create(dir
, dentry
, data
);
519 nfs3_free_createdata(data
);
521 dprintk("NFS reply symlink: %d\n", status
);
526 nfs3_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
)
528 struct posix_acl
*default_acl
, *acl
;
529 struct nfs3_createdata
*data
;
530 int status
= -ENOMEM
;
532 dprintk("NFS call mkdir %pd\n", dentry
);
534 data
= nfs3_alloc_createdata();
538 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
542 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_MKDIR
];
543 data
->arg
.mkdir
.fh
= NFS_FH(dir
);
544 data
->arg
.mkdir
.name
= dentry
->d_name
.name
;
545 data
->arg
.mkdir
.len
= dentry
->d_name
.len
;
546 data
->arg
.mkdir
.sattr
= sattr
;
548 status
= nfs3_do_create(dir
, dentry
, data
);
550 goto out_release_acls
;
552 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
555 posix_acl_release(acl
);
556 posix_acl_release(default_acl
);
558 nfs3_free_createdata(data
);
559 dprintk("NFS reply mkdir: %d\n", status
);
564 nfs3_proc_rmdir(struct inode
*dir
, const struct qstr
*name
)
566 struct nfs_fattr
*dir_attr
;
567 struct nfs3_diropargs arg
= {
572 struct rpc_message msg
= {
573 .rpc_proc
= &nfs3_procedures
[NFS3PROC_RMDIR
],
576 int status
= -ENOMEM
;
578 dprintk("NFS call rmdir %s\n", name
->name
);
579 dir_attr
= nfs_alloc_fattr();
580 if (dir_attr
== NULL
)
583 msg
.rpc_resp
= dir_attr
;
584 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
585 nfs_post_op_update_inode(dir
, dir_attr
);
586 nfs_free_fattr(dir_attr
);
588 dprintk("NFS reply rmdir: %d\n", status
);
593 * The READDIR implementation is somewhat hackish - we pass the user buffer
594 * to the encode function, which installs it in the receive iovec.
595 * The decode function itself doesn't perform any decoding, it just makes
596 * sure the reply is syntactically correct.
598 * Also note that this implementation handles both plain readdir and
602 nfs3_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
603 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
605 struct inode
*dir
= d_inode(dentry
);
606 __be32
*verf
= NFS_I(dir
)->cookieverf
;
607 struct nfs3_readdirargs arg
= {
610 .verf
= {verf
[0], verf
[1]},
615 struct nfs3_readdirres res
= {
619 struct rpc_message msg
= {
620 .rpc_proc
= &nfs3_procedures
[NFS3PROC_READDIR
],
625 int status
= -ENOMEM
;
628 msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_READDIRPLUS
];
630 dprintk("NFS call readdir%s %d\n",
631 plus
? "plus" : "", (unsigned int) cookie
);
633 res
.dir_attr
= nfs_alloc_fattr();
634 if (res
.dir_attr
== NULL
)
637 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
639 nfs_invalidate_atime(dir
);
640 nfs_refresh_inode(dir
, res
.dir_attr
);
642 nfs_free_fattr(res
.dir_attr
);
644 dprintk("NFS reply readdir%s: %d\n",
645 plus
? "plus" : "", status
);
650 nfs3_proc_mknod(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
653 struct posix_acl
*default_acl
, *acl
;
654 struct nfs3_createdata
*data
;
655 int status
= -ENOMEM
;
657 dprintk("NFS call mknod %pd %u:%u\n", dentry
,
658 MAJOR(rdev
), MINOR(rdev
));
660 data
= nfs3_alloc_createdata();
664 status
= posix_acl_create(dir
, &sattr
->ia_mode
, &default_acl
, &acl
);
668 data
->msg
.rpc_proc
= &nfs3_procedures
[NFS3PROC_MKNOD
];
669 data
->arg
.mknod
.fh
= NFS_FH(dir
);
670 data
->arg
.mknod
.name
= dentry
->d_name
.name
;
671 data
->arg
.mknod
.len
= dentry
->d_name
.len
;
672 data
->arg
.mknod
.sattr
= sattr
;
673 data
->arg
.mknod
.rdev
= rdev
;
675 switch (sattr
->ia_mode
& S_IFMT
) {
677 data
->arg
.mknod
.type
= NF3BLK
;
680 data
->arg
.mknod
.type
= NF3CHR
;
683 data
->arg
.mknod
.type
= NF3FIFO
;
686 data
->arg
.mknod
.type
= NF3SOCK
;
693 status
= nfs3_do_create(dir
, dentry
, data
);
695 goto out_release_acls
;
697 status
= nfs3_proc_setacls(d_inode(dentry
), acl
, default_acl
);
700 posix_acl_release(acl
);
701 posix_acl_release(default_acl
);
703 nfs3_free_createdata(data
);
704 dprintk("NFS reply mknod: %d\n", status
);
709 nfs3_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
710 struct nfs_fsstat
*stat
)
712 struct rpc_message msg
= {
713 .rpc_proc
= &nfs3_procedures
[NFS3PROC_FSSTAT
],
719 dprintk("NFS call fsstat\n");
720 nfs_fattr_init(stat
->fattr
);
721 status
= rpc_call_sync(server
->client
, &msg
, 0);
722 dprintk("NFS reply fsstat: %d\n", status
);
727 do_proc_fsinfo(struct rpc_clnt
*client
, struct nfs_fh
*fhandle
,
728 struct nfs_fsinfo
*info
)
730 struct rpc_message msg
= {
731 .rpc_proc
= &nfs3_procedures
[NFS3PROC_FSINFO
],
737 dprintk("NFS call fsinfo\n");
738 nfs_fattr_init(info
->fattr
);
739 status
= rpc_call_sync(client
, &msg
, 0);
740 dprintk("NFS reply fsinfo: %d\n", status
);
745 * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via
749 nfs3_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
750 struct nfs_fsinfo
*info
)
754 status
= do_proc_fsinfo(server
->client
, fhandle
, info
);
755 if (status
&& server
->nfs_client
->cl_rpcclient
!= server
->client
)
756 status
= do_proc_fsinfo(server
->nfs_client
->cl_rpcclient
, fhandle
, info
);
761 nfs3_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
762 struct nfs_pathconf
*info
)
764 struct rpc_message msg
= {
765 .rpc_proc
= &nfs3_procedures
[NFS3PROC_PATHCONF
],
771 dprintk("NFS call pathconf\n");
772 nfs_fattr_init(info
->fattr
);
773 status
= rpc_call_sync(server
->client
, &msg
, 0);
774 dprintk("NFS reply pathconf: %d\n", status
);
778 static int nfs3_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
780 struct inode
*inode
= hdr
->inode
;
782 if (hdr
->pgio_done_cb
!= NULL
)
783 return hdr
->pgio_done_cb(task
, hdr
);
785 if (nfs3_async_handle_jukebox(task
, inode
))
788 nfs_invalidate_atime(inode
);
789 nfs_refresh_inode(inode
, &hdr
->fattr
);
793 static void nfs3_proc_read_setup(struct nfs_pgio_header
*hdr
,
794 struct rpc_message
*msg
)
796 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_READ
];
799 static int nfs3_proc_pgio_rpc_prepare(struct rpc_task
*task
,
800 struct nfs_pgio_header
*hdr
)
802 rpc_call_start(task
);
806 static int nfs3_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
808 struct inode
*inode
= hdr
->inode
;
810 if (hdr
->pgio_done_cb
!= NULL
)
811 return hdr
->pgio_done_cb(task
, hdr
);
813 if (nfs3_async_handle_jukebox(task
, inode
))
815 if (task
->tk_status
>= 0)
816 nfs_writeback_update_inode(hdr
);
820 static void nfs3_proc_write_setup(struct nfs_pgio_header
*hdr
,
821 struct rpc_message
*msg
)
823 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_WRITE
];
826 static void nfs3_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
828 rpc_call_start(task
);
831 static int nfs3_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
833 if (data
->commit_done_cb
!= NULL
)
834 return data
->commit_done_cb(task
, data
);
836 if (nfs3_async_handle_jukebox(task
, data
->inode
))
838 nfs_refresh_inode(data
->inode
, data
->res
.fattr
);
842 static void nfs3_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
844 msg
->rpc_proc
= &nfs3_procedures
[NFS3PROC_COMMIT
];
847 static void nfs3_nlm_alloc_call(void *data
)
849 struct nfs_lock_context
*l_ctx
= data
;
850 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
)) {
851 get_nfs_open_context(l_ctx
->open_context
);
852 nfs_get_lock_context(l_ctx
->open_context
);
856 static bool nfs3_nlm_unlock_prepare(struct rpc_task
*task
, void *data
)
858 struct nfs_lock_context
*l_ctx
= data
;
859 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
))
860 return nfs_async_iocounter_wait(task
, l_ctx
);
865 static void nfs3_nlm_release_call(void *data
)
867 struct nfs_lock_context
*l_ctx
= data
;
868 struct nfs_open_context
*ctx
;
869 if (l_ctx
&& test_bit(NFS_CONTEXT_UNLOCK
, &l_ctx
->open_context
->flags
)) {
870 ctx
= l_ctx
->open_context
;
871 nfs_put_lock_context(l_ctx
);
872 put_nfs_open_context(ctx
);
876 static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops
= {
877 .nlmclnt_alloc_call
= nfs3_nlm_alloc_call
,
878 .nlmclnt_unlock_prepare
= nfs3_nlm_unlock_prepare
,
879 .nlmclnt_release_call
= nfs3_nlm_release_call
,
883 nfs3_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*fl
)
885 struct inode
*inode
= file_inode(filp
);
886 struct nfs_lock_context
*l_ctx
= NULL
;
887 struct nfs_open_context
*ctx
= nfs_file_open_context(filp
);
890 if (fl
->fl_flags
& FL_CLOSE
) {
891 l_ctx
= nfs_get_lock_context(ctx
);
895 set_bit(NFS_CONTEXT_UNLOCK
, &ctx
->flags
);
898 status
= nlmclnt_proc(NFS_SERVER(inode
)->nlm_host
, cmd
, fl
, l_ctx
);
901 nfs_put_lock_context(l_ctx
);
906 static int nfs3_have_delegation(struct inode
*inode
, fmode_t flags
)
911 static int nfs3_return_delegation(struct inode
*inode
)
917 static const struct inode_operations nfs3_dir_inode_operations
= {
918 .create
= nfs_create
,
919 .lookup
= nfs_lookup
,
921 .unlink
= nfs_unlink
,
922 .symlink
= nfs_symlink
,
926 .rename
= nfs_rename
,
927 .permission
= nfs_permission
,
928 .getattr
= nfs_getattr
,
929 .setattr
= nfs_setattr
,
930 #ifdef CONFIG_NFS_V3_ACL
931 .listxattr
= nfs3_listxattr
,
932 .get_acl
= nfs3_get_acl
,
933 .set_acl
= nfs3_set_acl
,
937 static const struct inode_operations nfs3_file_inode_operations
= {
938 .permission
= nfs_permission
,
939 .getattr
= nfs_getattr
,
940 .setattr
= nfs_setattr
,
941 #ifdef CONFIG_NFS_V3_ACL
942 .listxattr
= nfs3_listxattr
,
943 .get_acl
= nfs3_get_acl
,
944 .set_acl
= nfs3_set_acl
,
948 const struct nfs_rpc_ops nfs_v3_clientops
= {
949 .version
= 3, /* protocol version */
950 .dentry_ops
= &nfs_dentry_operations
,
951 .dir_inode_ops
= &nfs3_dir_inode_operations
,
952 .file_inode_ops
= &nfs3_file_inode_operations
,
953 .file_ops
= &nfs_file_operations
,
954 .nlmclnt_ops
= &nlmclnt_fl_close_lock_ops
,
955 .getroot
= nfs3_proc_get_root
,
956 .submount
= nfs_submount
,
957 .try_mount
= nfs_try_mount
,
958 .getattr
= nfs3_proc_getattr
,
959 .setattr
= nfs3_proc_setattr
,
960 .lookup
= nfs3_proc_lookup
,
961 .access
= nfs3_proc_access
,
962 .readlink
= nfs3_proc_readlink
,
963 .create
= nfs3_proc_create
,
964 .remove
= nfs3_proc_remove
,
965 .unlink_setup
= nfs3_proc_unlink_setup
,
966 .unlink_rpc_prepare
= nfs3_proc_unlink_rpc_prepare
,
967 .unlink_done
= nfs3_proc_unlink_done
,
968 .rename_setup
= nfs3_proc_rename_setup
,
969 .rename_rpc_prepare
= nfs3_proc_rename_rpc_prepare
,
970 .rename_done
= nfs3_proc_rename_done
,
971 .link
= nfs3_proc_link
,
972 .symlink
= nfs3_proc_symlink
,
973 .mkdir
= nfs3_proc_mkdir
,
974 .rmdir
= nfs3_proc_rmdir
,
975 .readdir
= nfs3_proc_readdir
,
976 .mknod
= nfs3_proc_mknod
,
977 .statfs
= nfs3_proc_statfs
,
978 .fsinfo
= nfs3_proc_fsinfo
,
979 .pathconf
= nfs3_proc_pathconf
,
980 .decode_dirent
= nfs3_decode_dirent
,
981 .pgio_rpc_prepare
= nfs3_proc_pgio_rpc_prepare
,
982 .read_setup
= nfs3_proc_read_setup
,
983 .read_done
= nfs3_read_done
,
984 .write_setup
= nfs3_proc_write_setup
,
985 .write_done
= nfs3_write_done
,
986 .commit_setup
= nfs3_proc_commit_setup
,
987 .commit_rpc_prepare
= nfs3_proc_commit_rpc_prepare
,
988 .commit_done
= nfs3_commit_done
,
989 .lock
= nfs3_proc_lock
,
990 .clear_acl_cache
= forget_all_cached_acls
,
991 .close_context
= nfs_close_context
,
992 .have_delegation
= nfs3_have_delegation
,
993 .return_delegation
= nfs3_return_delegation
,
994 .alloc_client
= nfs_alloc_client
,
995 .init_client
= nfs_init_client
,
996 .free_client
= nfs_free_client
,
997 .create_server
= nfs3_create_server
,
998 .clone_server
= nfs3_clone_server
,