2 * Server-side procedures for NFSv4.
4 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <linux/fs_struct.h>
36 #include <linux/file.h>
37 #include <linux/falloc.h>
38 #include <linux/slab.h>
39 #include <linux/kthread.h>
40 #include <linux/namei.h>
42 #include <linux/sunrpc/addr.h>
43 #include <linux/nfs_ssc.h>
49 #include "current_stateid.h"
55 static bool inter_copy_offload_enable
;
56 module_param(inter_copy_offload_enable
, bool, 0644);
57 MODULE_PARM_DESC(inter_copy_offload_enable
,
58 "Enable inter server to server copy offload. Default: false");
60 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
61 static int nfsd4_ssc_umount_timeout
= 900000; /* default to 15 mins */
62 module_param(nfsd4_ssc_umount_timeout
, int, 0644);
63 MODULE_PARM_DESC(nfsd4_ssc_umount_timeout
,
64 "idle msecs before unmount export from source server");
67 #define NFSDDBG_FACILITY NFSDDBG_PROC
69 static u32 nfsd_attrmask
[] = {
70 NFSD_WRITEABLE_ATTRS_WORD0
,
71 NFSD_WRITEABLE_ATTRS_WORD1
,
72 NFSD_WRITEABLE_ATTRS_WORD2
75 static u32 nfsd41_ex_attrmask
[] = {
76 NFSD_SUPPATTR_EXCLCREAT_WORD0
,
77 NFSD_SUPPATTR_EXCLCREAT_WORD1
,
78 NFSD_SUPPATTR_EXCLCREAT_WORD2
82 check_attr_support(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
83 u32
*bmval
, u32
*writable
)
85 struct dentry
*dentry
= cstate
->current_fh
.fh_dentry
;
86 struct svc_export
*exp
= cstate
->current_fh
.fh_export
;
88 if (!nfsd_attrs_supported(cstate
->minorversion
, bmval
))
89 return nfserr_attrnotsupp
;
90 if ((bmval
[0] & FATTR4_WORD0_ACL
) && !IS_POSIXACL(d_inode(dentry
)))
91 return nfserr_attrnotsupp
;
92 if ((bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) &&
93 !(exp
->ex_flags
& NFSEXP_SECURITY_LABEL
))
94 return nfserr_attrnotsupp
;
95 if (writable
&& !bmval_is_subset(bmval
, writable
))
97 if (writable
&& (bmval
[2] & FATTR4_WORD2_MODE_UMASK
) &&
98 (bmval
[1] & FATTR4_WORD1_MODE
))
104 nfsd4_check_open_attributes(struct svc_rqst
*rqstp
,
105 struct nfsd4_compound_state
*cstate
, struct nfsd4_open
*open
)
107 __be32 status
= nfs_ok
;
109 if (open
->op_create
== NFS4_OPEN_CREATE
) {
110 if (open
->op_createmode
== NFS4_CREATE_UNCHECKED
111 || open
->op_createmode
== NFS4_CREATE_GUARDED
)
112 status
= check_attr_support(rqstp
, cstate
,
113 open
->op_bmval
, nfsd_attrmask
);
114 else if (open
->op_createmode
== NFS4_CREATE_EXCLUSIVE4_1
)
115 status
= check_attr_support(rqstp
, cstate
,
116 open
->op_bmval
, nfsd41_ex_attrmask
);
123 is_create_with_attrs(struct nfsd4_open
*open
)
125 return open
->op_create
== NFS4_OPEN_CREATE
126 && (open
->op_createmode
== NFS4_CREATE_UNCHECKED
127 || open
->op_createmode
== NFS4_CREATE_GUARDED
128 || open
->op_createmode
== NFS4_CREATE_EXCLUSIVE4_1
);
132 fh_dup2(struct svc_fh
*dst
, struct svc_fh
*src
)
135 dget(src
->fh_dentry
);
137 exp_get(src
->fh_export
);
142 do_open_permission(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
, int accmode
)
145 if (open
->op_truncate
&&
146 !(open
->op_share_access
& NFS4_SHARE_ACCESS_WRITE
))
149 accmode
|= NFSD_MAY_READ_IF_EXEC
;
151 if (open
->op_share_access
& NFS4_SHARE_ACCESS_READ
)
152 accmode
|= NFSD_MAY_READ
;
153 if (open
->op_share_access
& NFS4_SHARE_ACCESS_WRITE
)
154 accmode
|= (NFSD_MAY_WRITE
| NFSD_MAY_TRUNC
);
155 if (open
->op_share_deny
& NFS4_SHARE_DENY_READ
)
156 accmode
|= NFSD_MAY_WRITE
;
158 return fh_verify(rqstp
, current_fh
, S_IFREG
, accmode
);
161 static __be32
nfsd_check_obj_isreg(struct svc_fh
*fh
, u32 minor_version
)
163 umode_t mode
= d_inode(fh
->fh_dentry
)->i_mode
;
170 return nfserr_symlink
;
172 /* RFC 7530 - 16.16.6 */
173 if (minor_version
== 0)
174 return nfserr_symlink
;
176 return nfserr_wrong_type
;
180 static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state
*cstate
, struct nfsd4_open
*open
, struct svc_fh
*resfh
)
182 if (nfsd4_has_session(cstate
))
184 fh_copy_shallow(&open
->op_openowner
->oo_owner
.so_replay
.rp_openfh
,
188 static inline bool nfsd4_create_is_exclusive(int createmode
)
190 return createmode
== NFS4_CREATE_EXCLUSIVE
||
191 createmode
== NFS4_CREATE_EXCLUSIVE4_1
;
195 nfsd4_vfs_create(struct svc_fh
*fhp
, struct dentry
*child
,
196 struct nfsd4_open
*open
)
202 oflags
= O_CREAT
| O_LARGEFILE
;
203 switch (open
->op_share_access
& NFS4_SHARE_ACCESS_BOTH
) {
204 case NFS4_SHARE_ACCESS_WRITE
:
207 case NFS4_SHARE_ACCESS_BOTH
:
214 path
.mnt
= fhp
->fh_export
->ex_path
.mnt
;
216 filp
= dentry_create(&path
, oflags
, open
->op_iattr
.ia_mode
,
219 return nfserrno(PTR_ERR(filp
));
221 open
->op_filp
= filp
;
226 * Implement NFSv4's unchecked, guarded, and exclusive create
227 * semantics for regular files. Open state for this new file is
228 * subsequently fabricated in nfsd4_process_open2().
230 * Upon return, caller must release @fhp and @resfhp.
233 nfsd4_create_file(struct svc_rqst
*rqstp
, struct svc_fh
*fhp
,
234 struct svc_fh
*resfhp
, struct nfsd4_open
*open
)
236 struct iattr
*iap
= &open
->op_iattr
;
237 struct nfsd_attrs attrs
= {
239 .na_seclabel
= &open
->op_label
,
241 struct dentry
*parent
, *child
;
242 __u32 v_mtime
, v_atime
;
247 if (isdotent(open
->op_fname
, open
->op_fnamelen
))
249 if (!(iap
->ia_valid
& ATTR_MODE
))
252 status
= fh_verify(rqstp
, fhp
, S_IFDIR
, NFSD_MAY_EXEC
);
253 if (status
!= nfs_ok
)
255 parent
= fhp
->fh_dentry
;
256 inode
= d_inode(parent
);
258 host_err
= fh_want_write(fhp
);
260 return nfserrno(host_err
);
262 if (is_create_with_attrs(open
))
263 nfsd4_acl_to_attr(NF4REG
, open
->op_acl
, &attrs
);
265 inode_lock_nested(inode
, I_MUTEX_PARENT
);
267 child
= lookup_one_len(open
->op_fname
, parent
, open
->op_fnamelen
);
269 status
= nfserrno(PTR_ERR(child
));
273 if (d_really_is_negative(child
)) {
274 status
= fh_verify(rqstp
, fhp
, S_IFDIR
, NFSD_MAY_CREATE
);
275 if (status
!= nfs_ok
)
279 status
= fh_compose(resfhp
, fhp
->fh_export
, child
, fhp
);
280 if (status
!= nfs_ok
)
285 if (nfsd4_create_is_exclusive(open
->op_createmode
)) {
286 u32
*verifier
= (u32
*)open
->op_verf
.data
;
289 * Solaris 7 gets confused (bugid 4218508) if these have
290 * the high bit set, as do xfs filesystems without the
291 * "bigtime" feature. So just clear the high bits. If this
292 * is ever changed to use different attrs for storing the
293 * verifier, then do_open_lookup() will also need to be
296 v_mtime
= verifier
[0] & 0x7fffffff;
297 v_atime
= verifier
[1] & 0x7fffffff;
300 if (d_really_is_positive(child
)) {
301 /* NFSv4 protocol requires change attributes even though
302 * no change happened.
304 status
= fh_fill_both_attrs(fhp
);
305 if (status
!= nfs_ok
)
308 switch (open
->op_createmode
) {
309 case NFS4_CREATE_UNCHECKED
:
310 if (!d_is_reg(child
))
314 * In NFSv4, we don't want to truncate the file
315 * now. This would be wrong if the OPEN fails for
316 * some other reason. Furthermore, if the size is
317 * nonzero, we should ignore it according to spec!
319 open
->op_truncate
= (iap
->ia_valid
& ATTR_SIZE
) &&
322 case NFS4_CREATE_GUARDED
:
323 status
= nfserr_exist
;
325 case NFS4_CREATE_EXCLUSIVE
:
326 if (inode_get_mtime_sec(d_inode(child
)) == v_mtime
&&
327 inode_get_atime_sec(d_inode(child
)) == v_atime
&&
328 d_inode(child
)->i_size
== 0) {
329 open
->op_created
= true;
332 status
= nfserr_exist
;
334 case NFS4_CREATE_EXCLUSIVE4_1
:
335 if (inode_get_mtime_sec(d_inode(child
)) == v_mtime
&&
336 inode_get_atime_sec(d_inode(child
)) == v_atime
&&
337 d_inode(child
)->i_size
== 0) {
338 open
->op_created
= true;
339 goto set_attr
; /* subtle */
341 status
= nfserr_exist
;
346 if (!IS_POSIXACL(inode
))
347 iap
->ia_mode
&= ~current_umask();
349 status
= fh_fill_pre_attrs(fhp
);
350 if (status
!= nfs_ok
)
352 status
= nfsd4_vfs_create(fhp
, child
, open
);
353 if (status
!= nfs_ok
)
355 open
->op_created
= true;
356 fh_fill_post_attrs(fhp
);
358 /* A newly created file already has a file size of zero. */
359 if ((iap
->ia_valid
& ATTR_SIZE
) && (iap
->ia_size
== 0))
360 iap
->ia_valid
&= ~ATTR_SIZE
;
361 if (nfsd4_create_is_exclusive(open
->op_createmode
)) {
362 iap
->ia_valid
= ATTR_MTIME
| ATTR_ATIME
|
363 ATTR_MTIME_SET
|ATTR_ATIME_SET
;
364 iap
->ia_mtime
.tv_sec
= v_mtime
;
365 iap
->ia_atime
.tv_sec
= v_atime
;
366 iap
->ia_mtime
.tv_nsec
= 0;
367 iap
->ia_atime
.tv_nsec
= 0;
371 status
= nfsd_create_setattr(rqstp
, fhp
, resfhp
, &attrs
);
373 if (attrs
.na_labelerr
)
374 open
->op_bmval
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
376 open
->op_bmval
[0] &= ~FATTR4_WORD0_ACL
;
379 nfsd_attrs_free(&attrs
);
380 if (child
&& !IS_ERR(child
))
387 * set_change_info - set up the change_info4 for a reply
388 * @cinfo: pointer to nfsd4_change_info to be populated
389 * @fhp: pointer to svc_fh to use as source
391 * Many operations in NFSv4 require change_info4 in the reply. This function
392 * populates that from the info that we (should!) have already collected. In
393 * the event that we didn't get any pre-attrs, just zero out both.
396 set_change_info(struct nfsd4_change_info
*cinfo
, struct svc_fh
*fhp
)
398 cinfo
->atomic
= (u32
)(fhp
->fh_pre_saved
&& fhp
->fh_post_saved
&& !fhp
->fh_no_atomic_attr
);
399 cinfo
->before_change
= fhp
->fh_pre_change
;
400 cinfo
->after_change
= fhp
->fh_post_change
;
403 * If fetching the pre-change attributes failed, then we should
404 * have already failed the whole operation. We could have still
405 * failed to fetch post-change attributes however.
407 * If we didn't get post-op attrs, just zero-out the after
408 * field since we don't know what it should be. If the pre_saved
409 * field isn't set for some reason, throw warning and just copy
410 * whatever is in the after field.
412 if (WARN_ON_ONCE(!fhp
->fh_pre_saved
))
413 cinfo
->before_change
= 0;
414 if (!fhp
->fh_post_saved
)
415 cinfo
->after_change
= cinfo
->before_change
+ 1;
419 do_open_lookup(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
, struct nfsd4_open
*open
, struct svc_fh
**resfh
)
421 struct svc_fh
*current_fh
= &cstate
->current_fh
;
425 *resfh
= kmalloc(sizeof(struct svc_fh
), GFP_KERNEL
);
427 return nfserr_jukebox
;
428 fh_init(*resfh
, NFS4_FHSIZE
);
429 open
->op_truncate
= false;
431 if (open
->op_create
) {
432 /* FIXME: check session persistence and pnfs flags.
433 * The nfsv4.1 spec requires the following semantics:
435 * Persistent | pNFS | Server REQUIRED | Client Allowed
436 * Reply Cache | server | |
437 * -------------+--------+-----------------+--------------------
438 * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
440 * | | and EXCLUSIVE4 | or EXCLUSIVE4
442 * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
443 * yes | no | GUARDED4 | GUARDED4
444 * yes | yes | GUARDED4 | GUARDED4
447 current
->fs
->umask
= open
->op_umask
;
448 status
= nfsd4_create_file(rqstp
, current_fh
, *resfh
, open
);
449 current
->fs
->umask
= 0;
452 * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
453 * use the returned bitmask to indicate which attributes
454 * we used to store the verifier:
456 if (nfsd4_create_is_exclusive(open
->op_createmode
) && status
== 0)
457 open
->op_bmval
[1] |= (FATTR4_WORD1_TIME_ACCESS
|
458 FATTR4_WORD1_TIME_MODIFY
);
460 status
= nfsd_lookup(rqstp
, current_fh
,
461 open
->op_fname
, open
->op_fnamelen
, *resfh
);
462 if (status
== nfs_ok
)
463 /* NFSv4 protocol requires change attributes even though
464 * no change happened.
466 status
= fh_fill_both_attrs(current_fh
);
470 status
= nfsd_check_obj_isreg(*resfh
, cstate
->minorversion
);
474 nfsd4_set_open_owner_reply_cache(cstate
, open
, *resfh
);
475 accmode
= NFSD_MAY_NOP
;
476 if (open
->op_created
||
477 open
->op_claim_type
== NFS4_OPEN_CLAIM_DELEGATE_CUR
)
478 accmode
|= NFSD_MAY_OWNER_OVERRIDE
;
479 status
= do_open_permission(rqstp
, *resfh
, open
, accmode
);
480 set_change_info(&open
->op_cinfo
, current_fh
);
486 do_open_fhandle(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
, struct nfsd4_open
*open
)
488 struct svc_fh
*current_fh
= &cstate
->current_fh
;
491 /* We don't know the target directory, and therefore can not
492 * set the change info
495 memset(&open
->op_cinfo
, 0, sizeof(struct nfsd4_change_info
));
497 nfsd4_set_open_owner_reply_cache(cstate
, open
, current_fh
);
499 open
->op_truncate
= (open
->op_iattr
.ia_valid
& ATTR_SIZE
) &&
500 (open
->op_iattr
.ia_size
== 0);
502 * In the delegation case, the client is telling us about an
503 * open that it *already* performed locally, some time ago. We
504 * should let it succeed now if possible.
506 * In the case of a CLAIM_FH open, on the other hand, the client
507 * may be counting on us to enforce permissions (the Linux 4.1
508 * client uses this for normal opens, for example).
510 if (open
->op_claim_type
== NFS4_OPEN_CLAIM_DELEG_CUR_FH
)
511 accmode
= NFSD_MAY_OWNER_OVERRIDE
;
513 return do_open_permission(rqstp
, current_fh
, open
, accmode
);
517 copy_clientid(clientid_t
*clid
, struct nfsd4_session
*session
)
519 struct nfsd4_sessionid
*sid
=
520 (struct nfsd4_sessionid
*)session
->se_sessionid
.data
;
522 clid
->cl_boot
= sid
->clientid
.cl_boot
;
523 clid
->cl_id
= sid
->clientid
.cl_id
;
527 nfsd4_open(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
530 struct nfsd4_open
*open
= &u
->open
;
532 struct svc_fh
*resfh
= NULL
;
533 struct net
*net
= SVC_NET(rqstp
);
534 struct nfsd_net
*nn
= net_generic(net
, nfsd_net_id
);
535 bool reclaim
= false;
537 dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
538 (int)open
->op_fnamelen
, open
->op_fname
,
541 open
->op_filp
= NULL
;
542 open
->op_rqstp
= rqstp
;
544 /* This check required by spec. */
545 if (open
->op_create
&& open
->op_claim_type
!= NFS4_OPEN_CLAIM_NULL
)
548 open
->op_created
= false;
551 * Before RECLAIM_COMPLETE done, server should deny new lock
553 if (nfsd4_has_session(cstate
) &&
554 !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE
, &cstate
->clp
->cl_flags
) &&
555 open
->op_claim_type
!= NFS4_OPEN_CLAIM_PREVIOUS
)
558 if (nfsd4_has_session(cstate
))
559 copy_clientid(&open
->op_clientid
, cstate
->session
);
561 /* check seqid for replay. set nfs4_owner */
562 status
= nfsd4_process_open1(cstate
, open
, nn
);
563 if (status
== nfserr_replay_me
) {
564 struct nfs4_replay
*rp
= &open
->op_openowner
->oo_owner
.so_replay
;
565 fh_put(&cstate
->current_fh
);
566 fh_copy_shallow(&cstate
->current_fh
.fh_handle
,
568 status
= fh_verify(rqstp
, &cstate
->current_fh
, 0, NFSD_MAY_NOP
);
570 dprintk("nfsd4_open: replay failed"
571 " restoring previous filehandle\n");
573 status
= nfserr_replay_me
;
577 if (open
->op_xdr_error
) {
578 status
= open
->op_xdr_error
;
582 status
= nfsd4_check_open_attributes(rqstp
, cstate
, open
);
586 /* Openowner is now set, so sequence id will get bumped. Now we need
587 * these checks before we do any creates: */
588 status
= nfserr_grace
;
589 if (opens_in_grace(net
) && open
->op_claim_type
!= NFS4_OPEN_CLAIM_PREVIOUS
)
591 status
= nfserr_no_grace
;
592 if (!opens_in_grace(net
) && open
->op_claim_type
== NFS4_OPEN_CLAIM_PREVIOUS
)
595 switch (open
->op_claim_type
) {
596 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
597 case NFS4_OPEN_CLAIM_NULL
:
598 status
= do_open_lookup(rqstp
, cstate
, open
, &resfh
);
602 case NFS4_OPEN_CLAIM_PREVIOUS
:
603 status
= nfs4_check_open_reclaim(cstate
->clp
);
606 open
->op_openowner
->oo_flags
|= NFS4_OO_CONFIRMED
;
609 case NFS4_OPEN_CLAIM_FH
:
610 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
611 status
= do_open_fhandle(rqstp
, cstate
, open
);
614 resfh
= &cstate
->current_fh
;
616 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
617 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
618 status
= nfserr_notsupp
;
621 status
= nfserr_inval
;
625 status
= nfsd4_process_open2(rqstp
, resfh
, open
);
626 if (status
&& open
->op_created
)
627 pr_warn("nfsd4_process_open2 failed to open newly-created file: status=%u\n",
628 be32_to_cpu(status
));
629 if (reclaim
&& !status
)
630 nn
->somebody_reclaimed
= true;
634 open
->op_filp
= NULL
;
636 if (resfh
&& resfh
!= &cstate
->current_fh
) {
637 fh_dup2(&cstate
->current_fh
, resfh
);
641 nfsd4_cleanup_open_state(cstate
, open
);
642 nfsd4_bump_seqid(cstate
, status
);
647 * OPEN is the only seqid-mutating operation whose decoding can fail
648 * with a seqid-mutating error (specifically, decoding of user names in
649 * the attributes). Therefore we have to do some processing to look up
650 * the stateowner so that we can bump the seqid.
652 static __be32
nfsd4_open_omfg(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
, struct nfsd4_op
*op
)
654 struct nfsd4_open
*open
= &op
->u
.open
;
656 if (!seqid_mutating_err(ntohl(op
->status
)))
658 if (nfsd4_has_session(cstate
))
660 open
->op_xdr_error
= op
->status
;
661 return nfsd4_open(rqstp
, cstate
, &op
->u
);
665 * filehandle-manipulating ops.
668 nfsd4_getfh(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
671 u
->getfh
= &cstate
->current_fh
;
676 nfsd4_putfh(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
679 struct nfsd4_putfh
*putfh
= &u
->putfh
;
682 fh_put(&cstate
->current_fh
);
683 cstate
->current_fh
.fh_handle
.fh_size
= putfh
->pf_fhlen
;
684 memcpy(&cstate
->current_fh
.fh_handle
.fh_raw
, putfh
->pf_fhval
,
686 ret
= fh_verify(rqstp
, &cstate
->current_fh
, 0, NFSD_MAY_BYPASS_GSS
);
687 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
688 if (ret
== nfserr_stale
&& putfh
->no_verify
) {
689 SET_FH_FLAG(&cstate
->current_fh
, NFSD4_FH_FOREIGN
);
697 nfsd4_putrootfh(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
700 fh_put(&cstate
->current_fh
);
702 return exp_pseudoroot(rqstp
, &cstate
->current_fh
);
706 nfsd4_restorefh(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
709 if (!cstate
->save_fh
.fh_dentry
)
710 return nfserr_restorefh
;
712 fh_dup2(&cstate
->current_fh
, &cstate
->save_fh
);
713 if (HAS_CSTATE_FLAG(cstate
, SAVED_STATE_ID_FLAG
)) {
714 memcpy(&cstate
->current_stateid
, &cstate
->save_stateid
, sizeof(stateid_t
));
715 SET_CSTATE_FLAG(cstate
, CURRENT_STATE_ID_FLAG
);
721 nfsd4_savefh(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
724 fh_dup2(&cstate
->save_fh
, &cstate
->current_fh
);
725 if (HAS_CSTATE_FLAG(cstate
, CURRENT_STATE_ID_FLAG
)) {
726 memcpy(&cstate
->save_stateid
, &cstate
->current_stateid
, sizeof(stateid_t
));
727 SET_CSTATE_FLAG(cstate
, SAVED_STATE_ID_FLAG
);
736 nfsd4_access(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
739 struct nfsd4_access
*access
= &u
->access
;
742 access_full
= NFS3_ACCESS_FULL
;
743 if (cstate
->minorversion
>= 2)
744 access_full
|= NFS4_ACCESS_XALIST
| NFS4_ACCESS_XAREAD
|
747 if (access
->ac_req_access
& ~access_full
)
750 access
->ac_resp_access
= access
->ac_req_access
;
751 return nfsd_access(rqstp
, &cstate
->current_fh
, &access
->ac_resp_access
,
752 &access
->ac_supported
);
756 nfsd4_commit(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
759 struct nfsd4_commit
*commit
= &u
->commit
;
760 struct nfsd_file
*nf
;
763 status
= nfsd_file_acquire(rqstp
, &cstate
->current_fh
, NFSD_MAY_WRITE
|
764 NFSD_MAY_NOT_BREAK_LEASE
, &nf
);
765 if (status
!= nfs_ok
)
768 status
= nfsd_commit(rqstp
, &cstate
->current_fh
, nf
, commit
->co_offset
,
770 (__be32
*)commit
->co_verf
.data
);
776 nfsd4_create(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
779 struct nfsd4_create
*create
= &u
->create
;
780 struct nfsd_attrs attrs
= {
781 .na_iattr
= &create
->cr_iattr
,
782 .na_seclabel
= &create
->cr_label
,
788 fh_init(&resfh
, NFS4_FHSIZE
);
790 status
= fh_verify(rqstp
, &cstate
->current_fh
, S_IFDIR
, NFSD_MAY_NOP
);
794 status
= check_attr_support(rqstp
, cstate
, create
->cr_bmval
,
799 status
= nfsd4_acl_to_attr(create
->cr_type
, create
->cr_acl
, &attrs
);
800 current
->fs
->umask
= create
->cr_umask
;
801 switch (create
->cr_type
) {
803 status
= nfsd_symlink(rqstp
, &cstate
->current_fh
,
804 create
->cr_name
, create
->cr_namelen
,
805 create
->cr_data
, &attrs
, &resfh
);
809 status
= nfserr_inval
;
810 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
811 if (MAJOR(rdev
) != create
->cr_specdata1
||
812 MINOR(rdev
) != create
->cr_specdata2
)
814 status
= nfsd_create(rqstp
, &cstate
->current_fh
,
815 create
->cr_name
, create
->cr_namelen
,
816 &attrs
, S_IFBLK
, rdev
, &resfh
);
820 status
= nfserr_inval
;
821 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
822 if (MAJOR(rdev
) != create
->cr_specdata1
||
823 MINOR(rdev
) != create
->cr_specdata2
)
825 status
= nfsd_create(rqstp
, &cstate
->current_fh
,
826 create
->cr_name
, create
->cr_namelen
,
827 &attrs
, S_IFCHR
, rdev
, &resfh
);
831 status
= nfsd_create(rqstp
, &cstate
->current_fh
,
832 create
->cr_name
, create
->cr_namelen
,
833 &attrs
, S_IFSOCK
, 0, &resfh
);
837 status
= nfsd_create(rqstp
, &cstate
->current_fh
,
838 create
->cr_name
, create
->cr_namelen
,
839 &attrs
, S_IFIFO
, 0, &resfh
);
843 create
->cr_iattr
.ia_valid
&= ~ATTR_SIZE
;
844 status
= nfsd_create(rqstp
, &cstate
->current_fh
,
845 create
->cr_name
, create
->cr_namelen
,
846 &attrs
, S_IFDIR
, 0, &resfh
);
850 status
= nfserr_badtype
;
856 if (attrs
.na_labelerr
)
857 create
->cr_bmval
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
859 create
->cr_bmval
[0] &= ~FATTR4_WORD0_ACL
;
860 set_change_info(&create
->cr_cinfo
, &cstate
->current_fh
);
861 fh_dup2(&cstate
->current_fh
, &resfh
);
865 current
->fs
->umask
= 0;
866 nfsd_attrs_free(&attrs
);
871 nfsd4_getattr(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
874 struct nfsd4_getattr
*getattr
= &u
->getattr
;
877 status
= fh_verify(rqstp
, &cstate
->current_fh
, 0, NFSD_MAY_NOP
);
881 if (getattr
->ga_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
884 getattr
->ga_bmval
[0] &= nfsd_suppattrs
[cstate
->minorversion
][0];
885 getattr
->ga_bmval
[1] &= nfsd_suppattrs
[cstate
->minorversion
][1];
886 getattr
->ga_bmval
[2] &= nfsd_suppattrs
[cstate
->minorversion
][2];
888 getattr
->ga_fhp
= &cstate
->current_fh
;
893 nfsd4_link(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
896 struct nfsd4_link
*link
= &u
->link
;
899 status
= nfsd_link(rqstp
, &cstate
->current_fh
,
900 link
->li_name
, link
->li_namelen
, &cstate
->save_fh
);
902 set_change_info(&link
->li_cinfo
, &cstate
->current_fh
);
906 static __be32
nfsd4_do_lookupp(struct svc_rqst
*rqstp
, struct svc_fh
*fh
)
908 struct svc_fh tmp_fh
;
911 fh_init(&tmp_fh
, NFS4_FHSIZE
);
912 ret
= exp_pseudoroot(rqstp
, &tmp_fh
);
915 if (tmp_fh
.fh_dentry
== fh
->fh_dentry
) {
920 return nfsd_lookup(rqstp
, fh
, "..", 2, fh
);
924 nfsd4_lookupp(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
927 return nfsd4_do_lookupp(rqstp
, &cstate
->current_fh
);
931 nfsd4_lookup(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
934 return nfsd_lookup(rqstp
, &cstate
->current_fh
,
935 u
->lookup
.lo_name
, u
->lookup
.lo_len
,
936 &cstate
->current_fh
);
940 nfsd4_read(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
943 struct nfsd4_read
*read
= &u
->read
;
948 trace_nfsd_read_start(rqstp
, &cstate
->current_fh
,
949 read
->rd_offset
, read
->rd_length
);
951 read
->rd_length
= min_t(u32
, read
->rd_length
, svc_max_payload(rqstp
));
952 if (read
->rd_offset
> (u64
)OFFSET_MAX
)
953 read
->rd_offset
= (u64
)OFFSET_MAX
;
954 if (read
->rd_offset
+ read
->rd_length
> (u64
)OFFSET_MAX
)
955 read
->rd_length
= (u64
)OFFSET_MAX
- read
->rd_offset
;
958 * If we do a zero copy read, then a client will see read data
959 * that reflects the state of the file *after* performing the
960 * following compound.
962 * To ensure proper ordering, we therefore turn off zero copy if
963 * the client wants us to do more in this compound:
965 if (!nfsd4_last_compound_op(rqstp
)) {
966 struct nfsd4_compoundargs
*argp
= rqstp
->rq_argp
;
968 argp
->splice_ok
= false;
972 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
973 &read
->rd_stateid
, RD_STATE
,
976 read
->rd_rqstp
= rqstp
;
977 read
->rd_fhp
= &cstate
->current_fh
;
983 nfsd4_read_release(union nfsd4_op_u
*u
)
986 nfsd_file_put(u
->read
.rd_nf
);
987 trace_nfsd_read_done(u
->read
.rd_rqstp
, u
->read
.rd_fhp
,
988 u
->read
.rd_offset
, u
->read
.rd_length
);
992 nfsd4_readdir(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
995 struct nfsd4_readdir
*readdir
= &u
->readdir
;
996 u64 cookie
= readdir
->rd_cookie
;
997 static const nfs4_verifier zeroverf
;
999 /* no need to check permission - this will be done in nfsd_readdir() */
1001 if (readdir
->rd_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
1002 return nfserr_inval
;
1004 readdir
->rd_bmval
[0] &= nfsd_suppattrs
[cstate
->minorversion
][0];
1005 readdir
->rd_bmval
[1] &= nfsd_suppattrs
[cstate
->minorversion
][1];
1006 readdir
->rd_bmval
[2] &= nfsd_suppattrs
[cstate
->minorversion
][2];
1008 if ((cookie
== 1) || (cookie
== 2) ||
1009 (cookie
== 0 && memcmp(readdir
->rd_verf
.data
, zeroverf
.data
, NFS4_VERIFIER_SIZE
)))
1010 return nfserr_bad_cookie
;
1012 readdir
->rd_rqstp
= rqstp
;
1013 readdir
->rd_fhp
= &cstate
->current_fh
;
1018 nfsd4_readlink(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1019 union nfsd4_op_u
*u
)
1021 u
->readlink
.rl_rqstp
= rqstp
;
1022 u
->readlink
.rl_fhp
= &cstate
->current_fh
;
1027 nfsd4_remove(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1028 union nfsd4_op_u
*u
)
1030 struct nfsd4_remove
*remove
= &u
->remove
;
1033 if (opens_in_grace(SVC_NET(rqstp
)))
1034 return nfserr_grace
;
1035 status
= nfsd_unlink(rqstp
, &cstate
->current_fh
, 0,
1036 remove
->rm_name
, remove
->rm_namelen
);
1038 set_change_info(&remove
->rm_cinfo
, &cstate
->current_fh
);
1043 nfsd4_rename(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1044 union nfsd4_op_u
*u
)
1046 struct nfsd4_rename
*rename
= &u
->rename
;
1049 if (opens_in_grace(SVC_NET(rqstp
)))
1050 return nfserr_grace
;
1051 status
= nfsd_rename(rqstp
, &cstate
->save_fh
, rename
->rn_sname
,
1052 rename
->rn_snamelen
, &cstate
->current_fh
,
1053 rename
->rn_tname
, rename
->rn_tnamelen
);
1056 set_change_info(&rename
->rn_sinfo
, &cstate
->save_fh
);
1057 set_change_info(&rename
->rn_tinfo
, &cstate
->current_fh
);
1062 nfsd4_secinfo(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1063 union nfsd4_op_u
*u
)
1065 struct nfsd4_secinfo
*secinfo
= &u
->secinfo
;
1066 struct svc_export
*exp
;
1067 struct dentry
*dentry
;
1070 err
= fh_verify(rqstp
, &cstate
->current_fh
, S_IFDIR
, NFSD_MAY_EXEC
);
1073 err
= nfsd_lookup_dentry(rqstp
, &cstate
->current_fh
,
1074 secinfo
->si_name
, secinfo
->si_namelen
,
1078 if (d_really_is_negative(dentry
)) {
1082 secinfo
->si_exp
= exp
;
1084 if (cstate
->minorversion
)
1085 /* See rfc 5661 section 2.6.3.1.1.8 */
1086 fh_put(&cstate
->current_fh
);
1091 nfsd4_secinfo_no_name(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1092 union nfsd4_op_u
*u
)
1096 switch (u
->secinfo_no_name
.sin_style
) {
1097 case NFS4_SECINFO_STYLE4_CURRENT_FH
:
1099 case NFS4_SECINFO_STYLE4_PARENT
:
1100 err
= nfsd4_do_lookupp(rqstp
, &cstate
->current_fh
);
1105 return nfserr_inval
;
1108 u
->secinfo_no_name
.sin_exp
= exp_get(cstate
->current_fh
.fh_export
);
1109 fh_put(&cstate
->current_fh
);
1114 nfsd4_secinfo_release(union nfsd4_op_u
*u
)
1116 if (u
->secinfo
.si_exp
)
1117 exp_put(u
->secinfo
.si_exp
);
1121 nfsd4_secinfo_no_name_release(union nfsd4_op_u
*u
)
1123 if (u
->secinfo_no_name
.sin_exp
)
1124 exp_put(u
->secinfo_no_name
.sin_exp
);
1128 nfsd4_setattr(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1129 union nfsd4_op_u
*u
)
1131 struct nfsd4_setattr
*setattr
= &u
->setattr
;
1132 struct nfsd_attrs attrs
= {
1133 .na_iattr
= &setattr
->sa_iattr
,
1134 .na_seclabel
= &setattr
->sa_label
,
1136 struct inode
*inode
;
1137 __be32 status
= nfs_ok
;
1141 if (setattr
->sa_iattr
.ia_valid
& ATTR_SIZE
) {
1142 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
,
1143 &cstate
->current_fh
, &setattr
->sa_stateid
,
1144 WR_STATE
, NULL
, NULL
);
1148 err
= fh_want_write(&cstate
->current_fh
);
1150 return nfserrno(err
);
1153 status
= check_attr_support(rqstp
, cstate
, setattr
->sa_bmval
,
1158 inode
= cstate
->current_fh
.fh_dentry
->d_inode
;
1159 status
= nfsd4_acl_to_attr(S_ISDIR(inode
->i_mode
) ? NF4DIR
: NF4REG
,
1160 setattr
->sa_acl
, &attrs
);
1164 save_no_wcc
= cstate
->current_fh
.fh_no_wcc
;
1165 cstate
->current_fh
.fh_no_wcc
= true;
1166 status
= nfsd_setattr(rqstp
, &cstate
->current_fh
, &attrs
, NULL
);
1167 cstate
->current_fh
.fh_no_wcc
= save_no_wcc
;
1169 status
= nfserrno(attrs
.na_labelerr
);
1171 status
= nfserrno(attrs
.na_aclerr
);
1173 nfsd_attrs_free(&attrs
);
1174 fh_drop_write(&cstate
->current_fh
);
1179 nfsd4_write(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1180 union nfsd4_op_u
*u
)
1182 struct nfsd4_write
*write
= &u
->write
;
1183 stateid_t
*stateid
= &write
->wr_stateid
;
1184 struct nfsd_file
*nf
= NULL
;
1185 __be32 status
= nfs_ok
;
1189 if (write
->wr_offset
> (u64
)OFFSET_MAX
||
1190 write
->wr_offset
+ write
->wr_buflen
> (u64
)OFFSET_MAX
)
1193 cnt
= write
->wr_buflen
;
1194 trace_nfsd_write_start(rqstp
, &cstate
->current_fh
,
1195 write
->wr_offset
, cnt
);
1196 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
1197 stateid
, WR_STATE
, &nf
, NULL
);
1201 write
->wr_how_written
= write
->wr_stable_how
;
1203 nvecs
= svc_fill_write_vector(rqstp
, &write
->wr_payload
);
1204 WARN_ON_ONCE(nvecs
> ARRAY_SIZE(rqstp
->rq_vec
));
1206 status
= nfsd_vfs_write(rqstp
, &cstate
->current_fh
, nf
,
1207 write
->wr_offset
, rqstp
->rq_vec
, nvecs
, &cnt
,
1208 write
->wr_how_written
,
1209 (__be32
*)write
->wr_verifier
.data
);
1212 write
->wr_bytes_written
= cnt
;
1213 trace_nfsd_write_done(rqstp
, &cstate
->current_fh
,
1214 write
->wr_offset
, cnt
);
1219 nfsd4_verify_copy(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1220 stateid_t
*src_stateid
, struct nfsd_file
**src
,
1221 stateid_t
*dst_stateid
, struct nfsd_file
**dst
)
1225 if (!cstate
->save_fh
.fh_dentry
)
1226 return nfserr_nofilehandle
;
1228 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->save_fh
,
1229 src_stateid
, RD_STATE
, src
, NULL
);
1233 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
1234 dst_stateid
, WR_STATE
, dst
, NULL
);
1238 /* fix up for NFS-specific error code */
1239 if (!S_ISREG(file_inode((*src
)->nf_file
)->i_mode
) ||
1240 !S_ISREG(file_inode((*dst
)->nf_file
)->i_mode
)) {
1241 status
= nfserr_wrong_type
;
1248 nfsd_file_put(*dst
);
1251 nfsd_file_put(*src
);
1257 nfsd4_clone(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1258 union nfsd4_op_u
*u
)
1260 struct nfsd4_clone
*clone
= &u
->clone
;
1261 struct nfsd_file
*src
, *dst
;
1264 status
= nfsd4_verify_copy(rqstp
, cstate
, &clone
->cl_src_stateid
, &src
,
1265 &clone
->cl_dst_stateid
, &dst
);
1269 status
= nfsd4_clone_file_range(rqstp
, src
, clone
->cl_src_pos
,
1270 dst
, clone
->cl_dst_pos
, clone
->cl_count
,
1271 EX_ISSYNC(cstate
->current_fh
.fh_export
));
1279 static void nfs4_put_copy(struct nfsd4_copy
*copy
)
1281 if (!refcount_dec_and_test(©
->refcount
))
1283 atomic_dec(©
->cp_nn
->pending_async_copies
);
1284 kfree(copy
->cp_src
);
1288 static void nfsd4_stop_copy(struct nfsd4_copy
*copy
)
1290 if (!test_and_set_bit(NFSD4_COPY_F_STOPPED
, ©
->cp_flags
))
1291 kthread_stop(copy
->copy_task
);
1292 nfs4_put_copy(copy
);
1295 static struct nfsd4_copy
*nfsd4_get_copy(struct nfs4_client
*clp
)
1297 struct nfsd4_copy
*copy
= NULL
;
1299 spin_lock(&clp
->async_lock
);
1300 if (!list_empty(&clp
->async_copies
)) {
1301 copy
= list_first_entry(&clp
->async_copies
, struct nfsd4_copy
,
1303 refcount_inc(©
->refcount
);
1305 spin_unlock(&clp
->async_lock
);
1309 void nfsd4_shutdown_copy(struct nfs4_client
*clp
)
1311 struct nfsd4_copy
*copy
;
1313 while ((copy
= nfsd4_get_copy(clp
)) != NULL
)
1314 nfsd4_stop_copy(copy
);
1316 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
1318 extern struct file
*nfs42_ssc_open(struct vfsmount
*ss_mnt
,
1319 struct nfs_fh
*src_fh
,
1320 nfs4_stateid
*stateid
);
1321 extern void nfs42_ssc_close(struct file
*filep
);
1323 extern void nfs_sb_deactive(struct super_block
*sb
);
1325 #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
1328 * setup a work entry in the ssc delayed unmount list.
1330 static __be32
nfsd4_ssc_setup_dul(struct nfsd_net
*nn
, char *ipaddr
,
1331 struct nfsd4_ssc_umount_item
**nsui
,
1332 struct svc_rqst
*rqstp
)
1334 struct nfsd4_ssc_umount_item
*ni
= NULL
;
1335 struct nfsd4_ssc_umount_item
*work
= NULL
;
1336 struct nfsd4_ssc_umount_item
*tmp
;
1341 work
= kzalloc(sizeof(*work
), GFP_KERNEL
);
1343 spin_lock(&nn
->nfsd_ssc_lock
);
1344 list_for_each_entry_safe(ni
, tmp
, &nn
->nfsd_ssc_mount_list
, nsui_list
) {
1345 if (strncmp(ni
->nsui_ipaddr
, ipaddr
, sizeof(ni
->nsui_ipaddr
)))
1348 if (ni
->nsui_busy
) {
1349 /* wait - and try again */
1350 prepare_to_wait(&nn
->nfsd_ssc_waitq
, &wait
, TASK_IDLE
);
1351 spin_unlock(&nn
->nfsd_ssc_lock
);
1353 /* allow 20secs for mount/unmount for now - revisit */
1354 if (svc_thread_should_stop(rqstp
) ||
1355 (schedule_timeout(20*HZ
) == 0)) {
1356 finish_wait(&nn
->nfsd_ssc_waitq
, &wait
);
1358 return nfserr_eagain
;
1360 finish_wait(&nn
->nfsd_ssc_waitq
, &wait
);
1364 refcount_inc(&ni
->nsui_refcnt
);
1365 spin_unlock(&nn
->nfsd_ssc_lock
);
1368 /* return vfsmount in (*nsui)->nsui_vfsmount */
1372 strscpy(work
->nsui_ipaddr
, ipaddr
, sizeof(work
->nsui_ipaddr
) - 1);
1373 refcount_set(&work
->nsui_refcnt
, 2);
1374 work
->nsui_busy
= true;
1375 list_add_tail(&work
->nsui_list
, &nn
->nfsd_ssc_mount_list
);
1378 status
= nfserr_resource
;
1379 spin_unlock(&nn
->nfsd_ssc_lock
);
1383 static void nfsd4_ssc_update_dul(struct nfsd_net
*nn
,
1384 struct nfsd4_ssc_umount_item
*nsui
,
1385 struct vfsmount
*ss_mnt
)
1387 spin_lock(&nn
->nfsd_ssc_lock
);
1388 nsui
->nsui_vfsmount
= ss_mnt
;
1389 nsui
->nsui_busy
= false;
1390 wake_up_all(&nn
->nfsd_ssc_waitq
);
1391 spin_unlock(&nn
->nfsd_ssc_lock
);
1394 static void nfsd4_ssc_cancel_dul(struct nfsd_net
*nn
,
1395 struct nfsd4_ssc_umount_item
*nsui
)
1397 spin_lock(&nn
->nfsd_ssc_lock
);
1398 list_del(&nsui
->nsui_list
);
1399 wake_up_all(&nn
->nfsd_ssc_waitq
);
1400 spin_unlock(&nn
->nfsd_ssc_lock
);
1405 * Support one copy source server for now.
1408 nfsd4_interssc_connect(struct nl4_server
*nss
, struct svc_rqst
*rqstp
,
1409 struct nfsd4_ssc_umount_item
**nsui
)
1411 struct file_system_type
*type
;
1412 struct vfsmount
*ss_mnt
;
1413 struct nfs42_netaddr
*naddr
;
1414 struct sockaddr_storage tmp_addr
;
1415 size_t tmp_addrlen
, match_netid_len
= 3;
1416 char *startsep
= "", *endsep
= "", *match_netid
= "tcp";
1417 char *ipaddr
, *dev_name
, *raw_data
;
1419 __be32 status
= nfserr_inval
;
1420 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
1422 naddr
= &nss
->u
.nl4_addr
;
1423 tmp_addrlen
= rpc_uaddr2sockaddr(SVC_NET(rqstp
), naddr
->addr
,
1425 (struct sockaddr
*)&tmp_addr
,
1428 if (tmp_addrlen
== 0)
1431 if (tmp_addr
.ss_family
== AF_INET6
) {
1434 match_netid
= "tcp6";
1435 match_netid_len
= 4;
1438 if (naddr
->netid_len
!= match_netid_len
||
1439 strncmp(naddr
->netid
, match_netid
, naddr
->netid_len
))
1442 /* Construct the raw data for the vfs_kern_mount call */
1443 len
= RPC_MAX_ADDRBUFLEN
+ 1;
1444 ipaddr
= kzalloc(len
, GFP_KERNEL
);
1448 rpc_ntop((struct sockaddr
*)&tmp_addr
, ipaddr
, len
);
1450 /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
1452 raw_len
= strlen(NFSD42_INTERSSC_MOUNTOPS
) + strlen(ipaddr
);
1453 raw_data
= kzalloc(raw_len
, GFP_KERNEL
);
1455 goto out_free_ipaddr
;
1457 snprintf(raw_data
, raw_len
, NFSD42_INTERSSC_MOUNTOPS
, ipaddr
);
1459 status
= nfserr_nodev
;
1460 type
= get_fs_type("nfs");
1462 goto out_free_rawdata
;
1464 /* Set the server:<export> for the vfs_kern_mount call */
1465 dev_name
= kzalloc(len
+ 5, GFP_KERNEL
);
1467 goto out_free_rawdata
;
1468 snprintf(dev_name
, len
+ 5, "%s%s%s:/", startsep
, ipaddr
, endsep
);
1470 status
= nfsd4_ssc_setup_dul(nn
, ipaddr
, nsui
, rqstp
);
1472 goto out_free_devname
;
1473 if ((*nsui
)->nsui_vfsmount
)
1476 /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
1477 ss_mnt
= vfs_kern_mount(type
, SB_KERNMOUNT
, dev_name
, raw_data
);
1478 module_put(type
->owner
);
1479 if (IS_ERR(ss_mnt
)) {
1480 status
= nfserr_nodev
;
1481 nfsd4_ssc_cancel_dul(nn
, *nsui
);
1482 goto out_free_devname
;
1484 nfsd4_ssc_update_dul(nn
, *nsui
, ss_mnt
);
1499 * Verify COPY destination stateid.
1501 * Connect to the source server with NFSv4.1.
1502 * Create the source struct file for nfsd_copy_range.
1503 * Called with COPY cstate:
1504 * SAVED_FH: source filehandle
1505 * CURRENT_FH: destination filehandle
1508 nfsd4_setup_inter_ssc(struct svc_rqst
*rqstp
,
1509 struct nfsd4_compound_state
*cstate
,
1510 struct nfsd4_copy
*copy
)
1512 struct svc_fh
*s_fh
= NULL
;
1513 stateid_t
*s_stid
= ©
->cp_src_stateid
;
1514 __be32 status
= nfserr_inval
;
1516 /* Verify the destination stateid and set dst struct file*/
1517 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
1518 ©
->cp_dst_stateid
,
1519 WR_STATE
, ©
->nf_dst
, NULL
);
1523 status
= nfsd4_interssc_connect(copy
->cp_src
, rqstp
, ©
->ss_nsui
);
1527 s_fh
= &cstate
->save_fh
;
1529 copy
->c_fh
.size
= s_fh
->fh_handle
.fh_size
;
1530 memcpy(copy
->c_fh
.data
, &s_fh
->fh_handle
.fh_raw
, copy
->c_fh
.size
);
1531 copy
->stateid
.seqid
= cpu_to_be32(s_stid
->si_generation
);
1532 memcpy(copy
->stateid
.other
, (void *)&s_stid
->si_opaque
,
1533 sizeof(stateid_opaque_t
));
1541 nfsd4_cleanup_inter_ssc(struct nfsd4_ssc_umount_item
*nsui
, struct file
*filp
,
1542 struct nfsd_file
*dst
)
1544 struct nfsd_net
*nn
= net_generic(dst
->nf_net
, nfsd_net_id
);
1545 long timeout
= msecs_to_jiffies(nfsd4_ssc_umount_timeout
);
1547 nfs42_ssc_close(filp
);
1550 spin_lock(&nn
->nfsd_ssc_lock
);
1551 list_del(&nsui
->nsui_list
);
1553 * vfsmount can be shared by multiple exports,
1554 * decrement refcnt. If the count drops to 1 it
1555 * will be unmounted when nsui_expire expires.
1557 refcount_dec(&nsui
->nsui_refcnt
);
1558 nsui
->nsui_expire
= jiffies
+ timeout
;
1559 list_add_tail(&nsui
->nsui_list
, &nn
->nfsd_ssc_mount_list
);
1560 spin_unlock(&nn
->nfsd_ssc_lock
);
1563 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
1566 nfsd4_setup_inter_ssc(struct svc_rqst
*rqstp
,
1567 struct nfsd4_compound_state
*cstate
,
1568 struct nfsd4_copy
*copy
)
1570 return nfserr_inval
;
1574 nfsd4_cleanup_inter_ssc(struct nfsd4_ssc_umount_item
*nsui
, struct file
*filp
,
1575 struct nfsd_file
*dst
)
1579 static struct file
*nfs42_ssc_open(struct vfsmount
*ss_mnt
,
1580 struct nfs_fh
*src_fh
,
1581 nfs4_stateid
*stateid
)
1585 #endif /* CONFIG_NFSD_V4_2_INTER_SSC */
1588 nfsd4_setup_intra_ssc(struct svc_rqst
*rqstp
,
1589 struct nfsd4_compound_state
*cstate
,
1590 struct nfsd4_copy
*copy
)
1592 return nfsd4_verify_copy(rqstp
, cstate
, ©
->cp_src_stateid
,
1593 ©
->nf_src
, ©
->cp_dst_stateid
,
1597 static void nfsd4_cb_offload_release(struct nfsd4_callback
*cb
)
1599 struct nfsd4_cb_offload
*cbo
=
1600 container_of(cb
, struct nfsd4_cb_offload
, co_cb
);
1605 static int nfsd4_cb_offload_done(struct nfsd4_callback
*cb
,
1606 struct rpc_task
*task
)
1608 struct nfsd4_cb_offload
*cbo
=
1609 container_of(cb
, struct nfsd4_cb_offload
, co_cb
);
1611 trace_nfsd_cb_offload_done(&cbo
->co_res
.cb_stateid
, task
);
1615 static const struct nfsd4_callback_ops nfsd4_cb_offload_ops
= {
1616 .release
= nfsd4_cb_offload_release
,
1617 .done
= nfsd4_cb_offload_done
,
1618 .opcode
= OP_CB_OFFLOAD
,
1621 static void nfsd4_init_copy_res(struct nfsd4_copy
*copy
, bool sync
)
1623 copy
->cp_res
.wr_stable_how
=
1624 test_bit(NFSD4_COPY_F_COMMITTED
, ©
->cp_flags
) ?
1625 NFS_FILE_SYNC
: NFS_UNSTABLE
;
1626 nfsd4_copy_set_sync(copy
, sync
);
1629 static ssize_t
_nfsd_copy_file_range(struct nfsd4_copy
*copy
,
1634 ssize_t bytes_copied
= 0;
1635 u64 bytes_total
= copy
->cp_count
;
1636 u64 src_pos
= copy
->cp_src_pos
;
1637 u64 dst_pos
= copy
->cp_dst_pos
;
1641 /* See RFC 7862 p.67: */
1642 if (bytes_total
== 0)
1643 bytes_total
= ULLONG_MAX
;
1645 /* Only async copies can be stopped here */
1646 if (kthread_should_stop())
1648 bytes_copied
= nfsd_copy_file_range(src
, src_pos
, dst
, dst_pos
,
1650 if (bytes_copied
<= 0)
1652 bytes_total
-= bytes_copied
;
1653 copy
->cp_res
.wr_bytes_written
+= bytes_copied
;
1654 src_pos
+= bytes_copied
;
1655 dst_pos
+= bytes_copied
;
1656 } while (bytes_total
> 0 && nfsd4_copy_is_async(copy
));
1657 /* for a non-zero asynchronous copy do a commit of data */
1658 if (nfsd4_copy_is_async(copy
) && copy
->cp_res
.wr_bytes_written
> 0) {
1659 since
= READ_ONCE(dst
->f_wb_err
);
1660 end
= copy
->cp_dst_pos
+ copy
->cp_res
.wr_bytes_written
- 1;
1661 status
= vfs_fsync_range(dst
, copy
->cp_dst_pos
, end
, 0);
1663 status
= filemap_check_wb_err(dst
->f_mapping
, since
);
1665 set_bit(NFSD4_COPY_F_COMMITTED
, ©
->cp_flags
);
1667 return bytes_copied
;
1670 static __be32
nfsd4_do_copy(struct nfsd4_copy
*copy
,
1671 struct file
*src
, struct file
*dst
,
1677 bytes
= _nfsd_copy_file_range(copy
, dst
, src
);
1679 /* for async copy, we ignore the error, client can always retry
1682 if (bytes
< 0 && !copy
->cp_res
.wr_bytes_written
)
1683 status
= nfserrno(bytes
);
1685 nfsd4_init_copy_res(copy
, sync
);
1691 static void dup_copy_fields(struct nfsd4_copy
*src
, struct nfsd4_copy
*dst
)
1693 dst
->cp_src_pos
= src
->cp_src_pos
;
1694 dst
->cp_dst_pos
= src
->cp_dst_pos
;
1695 dst
->cp_count
= src
->cp_count
;
1696 dst
->cp_flags
= src
->cp_flags
;
1697 memcpy(&dst
->cp_res
, &src
->cp_res
, sizeof(src
->cp_res
));
1698 memcpy(&dst
->fh
, &src
->fh
, sizeof(src
->fh
));
1699 dst
->cp_clp
= src
->cp_clp
;
1700 dst
->nf_dst
= nfsd_file_get(src
->nf_dst
);
1701 /* for inter, nf_src doesn't exist yet */
1702 if (!nfsd4_ssc_is_inter(src
))
1703 dst
->nf_src
= nfsd_file_get(src
->nf_src
);
1705 memcpy(&dst
->cp_stateid
, &src
->cp_stateid
, sizeof(src
->cp_stateid
));
1706 memcpy(dst
->cp_src
, src
->cp_src
, sizeof(struct nl4_server
));
1707 memcpy(&dst
->stateid
, &src
->stateid
, sizeof(src
->stateid
));
1708 memcpy(&dst
->c_fh
, &src
->c_fh
, sizeof(src
->c_fh
));
1709 dst
->ss_nsui
= src
->ss_nsui
;
1712 static void release_copy_files(struct nfsd4_copy
*copy
)
1715 nfsd_file_put(copy
->nf_src
);
1717 nfsd_file_put(copy
->nf_dst
);
1720 static void cleanup_async_copy(struct nfsd4_copy
*copy
)
1722 nfs4_free_copy_state(copy
);
1723 release_copy_files(copy
);
1725 spin_lock(©
->cp_clp
->async_lock
);
1726 if (!list_empty(©
->copies
))
1727 list_del_init(©
->copies
);
1728 spin_unlock(©
->cp_clp
->async_lock
);
1730 nfs4_put_copy(copy
);
1733 static void nfsd4_send_cb_offload(struct nfsd4_copy
*copy
)
1735 struct nfsd4_cb_offload
*cbo
;
1737 cbo
= kzalloc(sizeof(*cbo
), GFP_KERNEL
);
1741 memcpy(&cbo
->co_res
, ©
->cp_res
, sizeof(copy
->cp_res
));
1742 memcpy(&cbo
->co_fh
, ©
->fh
, sizeof(copy
->fh
));
1743 cbo
->co_nfserr
= copy
->nfserr
;
1745 nfsd4_init_cb(&cbo
->co_cb
, copy
->cp_clp
, &nfsd4_cb_offload_ops
,
1746 NFSPROC4_CLNT_CB_OFFLOAD
);
1747 trace_nfsd_cb_offload(copy
->cp_clp
, &cbo
->co_res
.cb_stateid
,
1748 &cbo
->co_fh
, copy
->cp_count
, copy
->nfserr
);
1749 nfsd4_run_cb(&cbo
->co_cb
);
1753 * nfsd4_do_async_copy - kthread function for background server-side COPY
1754 * @data: arguments for COPY operation
1757 * %0: Copy operation is done.
1759 static int nfsd4_do_async_copy(void *data
)
1761 struct nfsd4_copy
*copy
= (struct nfsd4_copy
*)data
;
1763 trace_nfsd_copy_async(copy
);
1764 if (nfsd4_ssc_is_inter(copy
)) {
1767 filp
= nfs42_ssc_open(copy
->ss_nsui
->nsui_vfsmount
,
1768 ©
->c_fh
, ©
->stateid
);
1770 switch (PTR_ERR(filp
)) {
1772 copy
->nfserr
= nfserr_wrong_type
;
1775 copy
->nfserr
= nfserr_offload_denied
;
1777 /* ss_mnt will be unmounted by the laundromat */
1780 copy
->nfserr
= nfsd4_do_copy(copy
, filp
, copy
->nf_dst
->nf_file
,
1782 nfsd4_cleanup_inter_ssc(copy
->ss_nsui
, filp
, copy
->nf_dst
);
1784 copy
->nfserr
= nfsd4_do_copy(copy
, copy
->nf_src
->nf_file
,
1785 copy
->nf_dst
->nf_file
, false);
1789 set_bit(NFSD4_COPY_F_COMPLETED
, ©
->cp_flags
);
1790 trace_nfsd_copy_async_done(copy
);
1791 nfsd4_send_cb_offload(copy
);
1792 cleanup_async_copy(copy
);
1797 nfsd4_copy(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1798 union nfsd4_op_u
*u
)
1800 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
1801 struct nfsd4_copy
*async_copy
= NULL
;
1802 struct nfsd4_copy
*copy
= &u
->copy
;
1803 struct nfsd42_write_res
*result
;
1807 * Currently, async COPY is not reliable. Force all COPY
1808 * requests to be synchronous to avoid client application
1809 * hangs waiting for COPY completion.
1811 nfsd4_copy_set_sync(copy
, true);
1813 result
= ©
->cp_res
;
1814 nfsd_copy_write_verifier((__be32
*)&result
->wr_verifier
.data
, nn
);
1816 copy
->cp_clp
= cstate
->clp
;
1817 if (nfsd4_ssc_is_inter(copy
)) {
1818 trace_nfsd_copy_inter(copy
);
1819 if (!inter_copy_offload_enable
|| nfsd4_copy_is_sync(copy
)) {
1820 status
= nfserr_notsupp
;
1823 status
= nfsd4_setup_inter_ssc(rqstp
, cstate
, copy
);
1825 trace_nfsd_copy_done(copy
, status
);
1826 return nfserr_offload_denied
;
1829 trace_nfsd_copy_intra(copy
);
1830 status
= nfsd4_setup_intra_ssc(rqstp
, cstate
, copy
);
1832 trace_nfsd_copy_done(copy
, status
);
1837 memcpy(©
->fh
, &cstate
->current_fh
.fh_handle
,
1838 sizeof(struct knfsd_fh
));
1839 if (nfsd4_copy_is_async(copy
)) {
1840 async_copy
= kzalloc(sizeof(struct nfsd4_copy
), GFP_KERNEL
);
1843 async_copy
->cp_nn
= nn
;
1844 /* Arbitrary cap on number of pending async copy operations */
1845 if (atomic_inc_return(&nn
->pending_async_copies
) >
1846 (int)rqstp
->rq_pool
->sp_nrthreads
) {
1847 atomic_dec(&nn
->pending_async_copies
);
1850 INIT_LIST_HEAD(&async_copy
->copies
);
1851 refcount_set(&async_copy
->refcount
, 1);
1852 async_copy
->cp_src
= kmalloc(sizeof(*async_copy
->cp_src
), GFP_KERNEL
);
1853 if (!async_copy
->cp_src
)
1855 if (!nfs4_init_copy_state(nn
, copy
))
1857 memcpy(&result
->cb_stateid
, ©
->cp_stateid
.cs_stid
,
1858 sizeof(result
->cb_stateid
));
1859 dup_copy_fields(copy
, async_copy
);
1860 async_copy
->copy_task
= kthread_create(nfsd4_do_async_copy
,
1861 async_copy
, "%s", "copy thread");
1862 if (IS_ERR(async_copy
->copy_task
))
1864 spin_lock(&async_copy
->cp_clp
->async_lock
);
1865 list_add(&async_copy
->copies
,
1866 &async_copy
->cp_clp
->async_copies
);
1867 spin_unlock(&async_copy
->cp_clp
->async_lock
);
1868 wake_up_process(async_copy
->copy_task
);
1871 status
= nfsd4_do_copy(copy
, copy
->nf_src
->nf_file
,
1872 copy
->nf_dst
->nf_file
, true);
1875 trace_nfsd_copy_done(copy
, status
);
1876 release_copy_files(copy
);
1879 if (nfsd4_ssc_is_inter(copy
)) {
1881 * Source's vfsmount of inter-copy will be unmounted
1882 * by the laundromat. Use copy instead of async_copy
1883 * since async_copy->ss_nsui might not be set yet.
1885 refcount_dec(©
->ss_nsui
->nsui_refcnt
);
1888 cleanup_async_copy(async_copy
);
1889 status
= nfserr_jukebox
;
1893 static struct nfsd4_copy
*
1894 find_async_copy_locked(struct nfs4_client
*clp
, stateid_t
*stateid
)
1896 struct nfsd4_copy
*copy
;
1898 lockdep_assert_held(&clp
->async_lock
);
1900 list_for_each_entry(copy
, &clp
->async_copies
, copies
) {
1901 if (memcmp(©
->cp_stateid
.cs_stid
, stateid
, NFS4_STATEID_SIZE
))
1908 static struct nfsd4_copy
*
1909 find_async_copy(struct nfs4_client
*clp
, stateid_t
*stateid
)
1911 struct nfsd4_copy
*copy
;
1913 spin_lock(&clp
->async_lock
);
1914 copy
= find_async_copy_locked(clp
, stateid
);
1916 refcount_inc(©
->refcount
);
1917 spin_unlock(&clp
->async_lock
);
1922 nfsd4_offload_cancel(struct svc_rqst
*rqstp
,
1923 struct nfsd4_compound_state
*cstate
,
1924 union nfsd4_op_u
*u
)
1926 struct nfsd4_offload_status
*os
= &u
->offload_status
;
1927 struct nfsd4_copy
*copy
;
1928 struct nfs4_client
*clp
= cstate
->clp
;
1930 copy
= find_async_copy(clp
, &os
->stateid
);
1932 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
1934 return manage_cpntf_state(nn
, &os
->stateid
, clp
, NULL
);
1936 nfsd4_stop_copy(copy
);
1942 nfsd4_copy_notify(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1943 union nfsd4_op_u
*u
)
1945 struct nfsd4_copy_notify
*cn
= &u
->copy_notify
;
1947 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
1948 struct nfs4_stid
*stid
= NULL
;
1949 struct nfs4_cpntf_state
*cps
;
1950 struct nfs4_client
*clp
= cstate
->clp
;
1952 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
1953 &cn
->cpn_src_stateid
, RD_STATE
, NULL
,
1958 return nfserr_bad_stateid
;
1960 cn
->cpn_lease_time
.tv_sec
= nn
->nfsd4_lease
;
1961 cn
->cpn_lease_time
.tv_nsec
= 0;
1963 status
= nfserrno(-ENOMEM
);
1964 cps
= nfs4_alloc_init_cpntf_state(nn
, stid
);
1967 memcpy(&cn
->cpn_cnr_stateid
, &cps
->cp_stateid
.cs_stid
, sizeof(stateid_t
));
1968 memcpy(&cps
->cp_p_stateid
, &stid
->sc_stateid
, sizeof(stateid_t
));
1969 memcpy(&cps
->cp_p_clid
, &clp
->cl_clientid
, sizeof(clientid_t
));
1971 /* For now, only return one server address in cpn_src, the
1972 * address used by the client to connect to this server.
1974 cn
->cpn_src
->nl4_type
= NL4_NETADDR
;
1975 status
= nfsd4_set_netaddr((struct sockaddr
*)&rqstp
->rq_daddr
,
1976 &cn
->cpn_src
->u
.nl4_addr
);
1977 WARN_ON_ONCE(status
);
1979 nfs4_put_cpntf_state(nn
, cps
);
1983 nfs4_put_stid(stid
);
1988 nfsd4_fallocate(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
1989 struct nfsd4_fallocate
*fallocate
, int flags
)
1992 struct nfsd_file
*nf
;
1994 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
1995 &fallocate
->falloc_stateid
,
1996 WR_STATE
, &nf
, NULL
);
1997 if (status
!= nfs_ok
)
2000 status
= nfsd4_vfs_fallocate(rqstp
, &cstate
->current_fh
, nf
->nf_file
,
2001 fallocate
->falloc_offset
,
2002 fallocate
->falloc_length
,
2009 nfsd4_offload_status(struct svc_rqst
*rqstp
,
2010 struct nfsd4_compound_state
*cstate
,
2011 union nfsd4_op_u
*u
)
2013 struct nfsd4_offload_status
*os
= &u
->offload_status
;
2014 __be32 status
= nfs_ok
;
2015 struct nfsd4_copy
*copy
;
2016 struct nfs4_client
*clp
= cstate
->clp
;
2018 os
->completed
= false;
2019 spin_lock(&clp
->async_lock
);
2020 copy
= find_async_copy_locked(clp
, &os
->stateid
);
2022 os
->count
= copy
->cp_res
.wr_bytes_written
;
2023 if (test_bit(NFSD4_COPY_F_COMPLETED
, ©
->cp_flags
)) {
2024 os
->completed
= true;
2025 os
->status
= copy
->nfserr
;
2028 status
= nfserr_bad_stateid
;
2029 spin_unlock(&clp
->async_lock
);
2035 nfsd4_allocate(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2036 union nfsd4_op_u
*u
)
2038 return nfsd4_fallocate(rqstp
, cstate
, &u
->allocate
, 0);
2042 nfsd4_deallocate(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2043 union nfsd4_op_u
*u
)
2045 return nfsd4_fallocate(rqstp
, cstate
, &u
->deallocate
,
2046 FALLOC_FL_PUNCH_HOLE
| FALLOC_FL_KEEP_SIZE
);
2050 nfsd4_seek(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2051 union nfsd4_op_u
*u
)
2053 struct nfsd4_seek
*seek
= &u
->seek
;
2056 struct nfsd_file
*nf
;
2058 status
= nfs4_preprocess_stateid_op(rqstp
, cstate
, &cstate
->current_fh
,
2059 &seek
->seek_stateid
,
2060 RD_STATE
, &nf
, NULL
);
2064 switch (seek
->seek_whence
) {
2065 case NFS4_CONTENT_DATA
:
2068 case NFS4_CONTENT_HOLE
:
2072 status
= nfserr_union_notsupp
;
2077 * Note: This call does change file->f_pos, but nothing in NFSD
2078 * should ever file->f_pos.
2080 seek
->seek_pos
= vfs_llseek(nf
->nf_file
, seek
->seek_offset
, whence
);
2081 if (seek
->seek_pos
< 0)
2082 status
= nfserrno(seek
->seek_pos
);
2083 else if (seek
->seek_pos
>= i_size_read(file_inode(nf
->nf_file
)))
2084 seek
->seek_eof
= true;
2091 /* This routine never returns NFS_OK! If there are no other errors, it
2092 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
2093 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
2094 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
2097 _nfsd4_verify(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2098 struct nfsd4_verify
*verify
)
2104 status
= fh_verify(rqstp
, &cstate
->current_fh
, 0, NFSD_MAY_NOP
);
2108 status
= check_attr_support(rqstp
, cstate
, verify
->ve_bmval
, NULL
);
2112 if ((verify
->ve_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
)
2113 || (verify
->ve_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
))
2114 return nfserr_inval
;
2115 if (verify
->ve_attrlen
& 3)
2116 return nfserr_inval
;
2119 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
2121 count
= 4 + (verify
->ve_attrlen
>> 2);
2122 buf
= kmalloc(count
<< 2, GFP_KERNEL
);
2124 return nfserr_jukebox
;
2127 status
= nfsd4_encode_fattr_to_buf(&p
, count
, &cstate
->current_fh
,
2128 cstate
->current_fh
.fh_export
,
2129 cstate
->current_fh
.fh_dentry
,
2133 * If nfsd4_encode_fattr() ran out of space, assume that's because
2134 * the attributes are longer (hence different) than those given:
2136 if (status
== nfserr_resource
)
2137 status
= nfserr_not_same
;
2142 p
= buf
+ 1 + ntohl(buf
[0]);
2143 status
= nfserr_not_same
;
2144 if (ntohl(*p
++) != verify
->ve_attrlen
)
2146 if (!memcmp(p
, verify
->ve_attrval
, verify
->ve_attrlen
))
2147 status
= nfserr_same
;
2155 nfsd4_nverify(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2156 union nfsd4_op_u
*u
)
2160 status
= _nfsd4_verify(rqstp
, cstate
, &u
->verify
);
2161 return status
== nfserr_not_same
? nfs_ok
: status
;
2165 nfsd4_verify(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2166 union nfsd4_op_u
*u
)
2170 status
= _nfsd4_verify(rqstp
, cstate
, &u
->nverify
);
2171 return status
== nfserr_same
? nfs_ok
: status
;
2175 nfsd4_get_dir_delegation(struct svc_rqst
*rqstp
,
2176 struct nfsd4_compound_state
*cstate
,
2177 union nfsd4_op_u
*u
)
2179 struct nfsd4_get_dir_delegation
*gdd
= &u
->get_dir_delegation
;
2182 * RFC 8881, section 18.39.3 says:
2184 * "The server may refuse to grant the delegation. In that case, the
2185 * server will return NFS4ERR_DIRDELEG_UNAVAIL."
2187 * This is sub-optimal, since it means that the server would need to
2188 * abort compound processing just because the delegation wasn't
2189 * available. RFC8881bis should change this to allow the server to
2190 * return NFS4_OK with a non-fatal status of GDD4_UNAVAIL in this
2193 gdd
->gddrnf_status
= GDD4_UNAVAIL
;
2197 #ifdef CONFIG_NFSD_PNFS
2198 static const struct nfsd4_layout_ops
*
2199 nfsd4_layout_verify(struct svc_export
*exp
, unsigned int layout_type
)
2201 if (!exp
->ex_layout_types
) {
2202 dprintk("%s: export does not support pNFS\n", __func__
);
2206 if (layout_type
>= LAYOUT_TYPE_MAX
||
2207 !(exp
->ex_layout_types
& (1 << layout_type
))) {
2208 dprintk("%s: layout type %d not supported\n",
2209 __func__
, layout_type
);
2213 return nfsd4_layout_ops
[layout_type
];
2217 nfsd4_getdeviceinfo(struct svc_rqst
*rqstp
,
2218 struct nfsd4_compound_state
*cstate
, union nfsd4_op_u
*u
)
2220 struct nfsd4_getdeviceinfo
*gdp
= &u
->getdeviceinfo
;
2221 const struct nfsd4_layout_ops
*ops
;
2222 struct nfsd4_deviceid_map
*map
;
2223 struct svc_export
*exp
;
2226 dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
2228 gdp
->gd_layout_type
,
2229 gdp
->gd_devid
.fsid_idx
, gdp
->gd_devid
.generation
,
2232 map
= nfsd4_find_devid_map(gdp
->gd_devid
.fsid_idx
);
2234 dprintk("%s: couldn't find device ID to export mapping!\n",
2236 return nfserr_noent
;
2239 exp
= rqst_exp_find(&rqstp
->rq_chandle
, SVC_NET(rqstp
),
2240 rqstp
->rq_client
, rqstp
->rq_gssclient
,
2241 map
->fsid_type
, map
->fsid
);
2243 dprintk("%s: could not find device id\n", __func__
);
2244 return nfserr_noent
;
2247 nfserr
= nfserr_layoutunavailable
;
2248 ops
= nfsd4_layout_verify(exp
, gdp
->gd_layout_type
);
2253 if (gdp
->gd_maxcount
!= 0) {
2254 nfserr
= ops
->proc_getdeviceinfo(exp
->ex_path
.mnt
->mnt_sb
,
2255 rqstp
, cstate
->clp
, gdp
);
2258 gdp
->gd_notify_types
&= ops
->notify_types
;
2265 nfsd4_getdeviceinfo_release(union nfsd4_op_u
*u
)
2267 kfree(u
->getdeviceinfo
.gd_device
);
2271 nfsd4_layoutget(struct svc_rqst
*rqstp
,
2272 struct nfsd4_compound_state
*cstate
, union nfsd4_op_u
*u
)
2274 struct nfsd4_layoutget
*lgp
= &u
->layoutget
;
2275 struct svc_fh
*current_fh
= &cstate
->current_fh
;
2276 const struct nfsd4_layout_ops
*ops
;
2277 struct nfs4_layout_stateid
*ls
;
2279 int accmode
= NFSD_MAY_READ_IF_EXEC
| NFSD_MAY_OWNER_OVERRIDE
;
2281 switch (lgp
->lg_seg
.iomode
) {
2283 accmode
|= NFSD_MAY_READ
;
2286 accmode
|= NFSD_MAY_READ
| NFSD_MAY_WRITE
;
2289 dprintk("%s: invalid iomode %d\n",
2290 __func__
, lgp
->lg_seg
.iomode
);
2291 nfserr
= nfserr_badiomode
;
2295 nfserr
= fh_verify(rqstp
, current_fh
, 0, accmode
);
2299 nfserr
= nfserr_layoutunavailable
;
2300 ops
= nfsd4_layout_verify(current_fh
->fh_export
, lgp
->lg_layout_type
);
2305 * Verify minlength and range as per RFC5661:
2306 * o If loga_length is less than loga_minlength,
2307 * the metadata server MUST return NFS4ERR_INVAL.
2308 * o If the sum of loga_offset and loga_minlength exceeds
2309 * NFS4_UINT64_MAX, and loga_minlength is not
2310 * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
2311 * o If the sum of loga_offset and loga_length exceeds
2312 * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
2313 * the error NFS4ERR_INVAL MUST result.
2315 nfserr
= nfserr_inval
;
2316 if (lgp
->lg_seg
.length
< lgp
->lg_minlength
||
2317 (lgp
->lg_minlength
!= NFS4_MAX_UINT64
&&
2318 lgp
->lg_minlength
> NFS4_MAX_UINT64
- lgp
->lg_seg
.offset
) ||
2319 (lgp
->lg_seg
.length
!= NFS4_MAX_UINT64
&&
2320 lgp
->lg_seg
.length
> NFS4_MAX_UINT64
- lgp
->lg_seg
.offset
))
2322 if (lgp
->lg_seg
.length
== 0)
2325 nfserr
= nfsd4_preprocess_layout_stateid(rqstp
, cstate
, &lgp
->lg_sid
,
2326 true, lgp
->lg_layout_type
, &ls
);
2328 trace_nfsd_layout_get_lookup_fail(&lgp
->lg_sid
);
2332 nfserr
= nfserr_recallconflict
;
2333 if (atomic_read(&ls
->ls_stid
.sc_file
->fi_lo_recalls
))
2336 nfserr
= ops
->proc_layoutget(d_inode(current_fh
->fh_dentry
),
2341 nfserr
= nfsd4_insert_layout(lgp
, ls
);
2344 mutex_unlock(&ls
->ls_mutex
);
2345 nfs4_put_stid(&ls
->ls_stid
);
2351 nfsd4_layoutget_release(union nfsd4_op_u
*u
)
2353 kfree(u
->layoutget
.lg_content
);
2357 nfsd4_layoutcommit(struct svc_rqst
*rqstp
,
2358 struct nfsd4_compound_state
*cstate
, union nfsd4_op_u
*u
)
2360 struct nfsd4_layoutcommit
*lcp
= &u
->layoutcommit
;
2361 const struct nfsd4_layout_seg
*seg
= &lcp
->lc_seg
;
2362 struct svc_fh
*current_fh
= &cstate
->current_fh
;
2363 const struct nfsd4_layout_ops
*ops
;
2364 loff_t new_size
= lcp
->lc_last_wr
+ 1;
2365 struct inode
*inode
;
2366 struct nfs4_layout_stateid
*ls
;
2369 nfserr
= fh_verify(rqstp
, current_fh
, 0,
2370 NFSD_MAY_WRITE
| NFSD_MAY_OWNER_OVERRIDE
);
2374 nfserr
= nfserr_layoutunavailable
;
2375 ops
= nfsd4_layout_verify(current_fh
->fh_export
, lcp
->lc_layout_type
);
2378 inode
= d_inode(current_fh
->fh_dentry
);
2380 nfserr
= nfserr_inval
;
2381 if (new_size
<= seg
->offset
) {
2382 dprintk("pnfsd: last write before layout segment\n");
2385 if (new_size
> seg
->offset
+ seg
->length
) {
2386 dprintk("pnfsd: last write beyond layout segment\n");
2389 if (!lcp
->lc_newoffset
&& new_size
> i_size_read(inode
)) {
2390 dprintk("pnfsd: layoutcommit beyond EOF\n");
2394 nfserr
= nfsd4_preprocess_layout_stateid(rqstp
, cstate
, &lcp
->lc_sid
,
2395 false, lcp
->lc_layout_type
,
2398 trace_nfsd_layout_commit_lookup_fail(&lcp
->lc_sid
);
2399 /* fixup error code as per RFC5661 */
2400 if (nfserr
== nfserr_bad_stateid
)
2401 nfserr
= nfserr_badlayout
;
2405 /* LAYOUTCOMMIT does not require any serialization */
2406 mutex_unlock(&ls
->ls_mutex
);
2408 if (new_size
> i_size_read(inode
)) {
2409 lcp
->lc_size_chg
= true;
2410 lcp
->lc_newsize
= new_size
;
2412 lcp
->lc_size_chg
= false;
2415 nfserr
= ops
->proc_layoutcommit(inode
, lcp
);
2416 nfs4_put_stid(&ls
->ls_stid
);
2422 nfsd4_layoutreturn(struct svc_rqst
*rqstp
,
2423 struct nfsd4_compound_state
*cstate
, union nfsd4_op_u
*u
)
2425 struct nfsd4_layoutreturn
*lrp
= &u
->layoutreturn
;
2426 struct svc_fh
*current_fh
= &cstate
->current_fh
;
2429 nfserr
= fh_verify(rqstp
, current_fh
, 0, NFSD_MAY_NOP
);
2433 nfserr
= nfserr_layoutunavailable
;
2434 if (!nfsd4_layout_verify(current_fh
->fh_export
, lrp
->lr_layout_type
))
2437 switch (lrp
->lr_seg
.iomode
) {
2443 dprintk("%s: invalid iomode %d\n", __func__
,
2444 lrp
->lr_seg
.iomode
);
2445 nfserr
= nfserr_inval
;
2449 switch (lrp
->lr_return_type
) {
2451 nfserr
= nfsd4_return_file_layouts(rqstp
, cstate
, lrp
);
2455 nfserr
= nfsd4_return_client_layouts(rqstp
, cstate
, lrp
);
2458 dprintk("%s: invalid return_type %d\n", __func__
,
2459 lrp
->lr_return_type
);
2460 nfserr
= nfserr_inval
;
2466 #endif /* CONFIG_NFSD_PNFS */
2469 nfsd4_getxattr(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2470 union nfsd4_op_u
*u
)
2472 struct nfsd4_getxattr
*getxattr
= &u
->getxattr
;
2474 return nfsd_getxattr(rqstp
, &cstate
->current_fh
,
2475 getxattr
->getxa_name
, &getxattr
->getxa_buf
,
2476 &getxattr
->getxa_len
);
2480 nfsd4_setxattr(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2481 union nfsd4_op_u
*u
)
2483 struct nfsd4_setxattr
*setxattr
= &u
->setxattr
;
2486 if (opens_in_grace(SVC_NET(rqstp
)))
2487 return nfserr_grace
;
2489 ret
= nfsd_setxattr(rqstp
, &cstate
->current_fh
, setxattr
->setxa_name
,
2490 setxattr
->setxa_buf
, setxattr
->setxa_len
,
2491 setxattr
->setxa_flags
);
2494 set_change_info(&setxattr
->setxa_cinfo
, &cstate
->current_fh
);
2500 nfsd4_listxattrs(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2501 union nfsd4_op_u
*u
)
2504 * Get the entire list, then copy out only the user attributes
2505 * in the encode function.
2507 return nfsd_listxattr(rqstp
, &cstate
->current_fh
,
2508 &u
->listxattrs
.lsxa_buf
, &u
->listxattrs
.lsxa_len
);
2512 nfsd4_removexattr(struct svc_rqst
*rqstp
, struct nfsd4_compound_state
*cstate
,
2513 union nfsd4_op_u
*u
)
2515 struct nfsd4_removexattr
*removexattr
= &u
->removexattr
;
2518 if (opens_in_grace(SVC_NET(rqstp
)))
2519 return nfserr_grace
;
2521 ret
= nfsd_removexattr(rqstp
, &cstate
->current_fh
,
2522 removexattr
->rmxa_name
);
2525 set_change_info(&removexattr
->rmxa_cinfo
, &cstate
->current_fh
);
2534 nfsd4_proc_null(struct svc_rqst
*rqstp
)
2539 static inline void nfsd4_increment_op_stats(struct nfsd_net
*nn
, u32 opnum
)
2541 if (opnum
>= FIRST_NFS4_OP
&& opnum
<= LAST_NFS4_OP
)
2542 percpu_counter_inc(&nn
->counter
[NFSD_STATS_NFS4_OP(opnum
)]);
2545 static const struct nfsd4_operation nfsd4_ops
[];
2547 static const char *nfsd4_op_name(unsigned opnum
);
2550 * Enforce NFSv4.1 COMPOUND ordering rules:
2552 * Also note, enforced elsewhere:
2553 * - SEQUENCE other than as first op results in
2554 * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
2555 * - BIND_CONN_TO_SESSION must be the only op in its compound.
2556 * (Enforced in nfsd4_bind_conn_to_session().)
2557 * - DESTROY_SESSION must be the final operation in a compound, if
2558 * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
2559 * (Enforced in nfsd4_destroy_session().)
2561 static __be32
nfs41_check_op_ordering(struct nfsd4_compoundargs
*args
)
2563 struct nfsd4_op
*first_op
= &args
->ops
[0];
2565 /* These ordering requirements don't apply to NFSv4.0: */
2566 if (args
->minorversion
== 0)
2568 /* This is weird, but OK, not our problem: */
2569 if (args
->opcnt
== 0)
2571 if (first_op
->status
== nfserr_op_illegal
)
2573 if (!(nfsd4_ops
[first_op
->opnum
].op_flags
& ALLOWED_AS_FIRST_OP
))
2574 return nfserr_op_not_in_session
;
2575 if (first_op
->opnum
== OP_SEQUENCE
)
2578 * So first_op is something allowed outside a session, like
2579 * EXCHANGE_ID; but then it has to be the only op in the
2582 if (args
->opcnt
!= 1)
2583 return nfserr_not_only_op
;
2587 const struct nfsd4_operation
*OPDESC(struct nfsd4_op
*op
)
2589 return &nfsd4_ops
[op
->opnum
];
2592 bool nfsd4_cache_this_op(struct nfsd4_op
*op
)
2594 if (op
->opnum
== OP_ILLEGAL
)
2596 return OPDESC(op
)->op_flags
& OP_CACHEME
;
2599 static bool need_wrongsec_check(struct svc_rqst
*rqstp
)
2601 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
2602 struct nfsd4_compoundargs
*argp
= rqstp
->rq_argp
;
2603 struct nfsd4_op
*this = &argp
->ops
[resp
->opcnt
- 1];
2604 struct nfsd4_op
*next
= &argp
->ops
[resp
->opcnt
];
2605 const struct nfsd4_operation
*thisd
= OPDESC(this);
2606 const struct nfsd4_operation
*nextd
;
2609 * Most ops check wronsec on our own; only the putfh-like ops
2610 * have special rules.
2612 if (!(thisd
->op_flags
& OP_IS_PUTFH_LIKE
))
2615 * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
2616 * put-filehandle operation if we're not going to use the
2619 if (argp
->opcnt
== resp
->opcnt
)
2621 if (next
->opnum
== OP_ILLEGAL
)
2623 nextd
= OPDESC(next
);
2625 * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
2626 * errors themselves as necessary; others should check for them
2629 return !(nextd
->op_flags
& OP_HANDLES_WRONGSEC
);
2632 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
2634 check_if_stalefh_allowed(struct nfsd4_compoundargs
*args
)
2636 struct nfsd4_op
*op
, *current_op
= NULL
, *saved_op
= NULL
;
2637 struct nfsd4_copy
*copy
;
2638 struct nfsd4_putfh
*putfh
;
2641 /* traverse all operation and if it's a COPY compound, mark the
2642 * source filehandle to skip verification
2644 for (i
= 0; i
< args
->opcnt
; i
++) {
2646 if (op
->opnum
== OP_PUTFH
)
2648 else if (op
->opnum
== OP_SAVEFH
)
2649 saved_op
= current_op
;
2650 else if (op
->opnum
== OP_RESTOREFH
)
2651 current_op
= saved_op
;
2652 else if (op
->opnum
== OP_COPY
) {
2653 copy
= (struct nfsd4_copy
*)&op
->u
;
2655 op
->status
= nfserr_nofilehandle
;
2658 putfh
= (struct nfsd4_putfh
*)&saved_op
->u
;
2659 if (nfsd4_ssc_is_inter(copy
))
2660 putfh
->no_verify
= true;
2666 check_if_stalefh_allowed(struct nfsd4_compoundargs
*args
)
2675 nfsd4_proc_compound(struct svc_rqst
*rqstp
)
2677 struct nfsd4_compoundargs
*args
= rqstp
->rq_argp
;
2678 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
2679 struct nfsd4_op
*op
;
2680 struct nfsd4_compound_state
*cstate
= &resp
->cstate
;
2681 struct svc_fh
*current_fh
= &cstate
->current_fh
;
2682 struct svc_fh
*save_fh
= &cstate
->save_fh
;
2683 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
2686 resp
->xdr
= &rqstp
->rq_res_stream
;
2687 resp
->statusp
= resp
->xdr
->p
;
2689 /* reserve space for: NFS status code */
2690 xdr_reserve_space(resp
->xdr
, XDR_UNIT
);
2692 /* reserve space for: taglen, tag, and opcnt */
2693 xdr_reserve_space(resp
->xdr
, XDR_UNIT
* 2 + args
->taglen
);
2694 resp
->taglen
= args
->taglen
;
2695 resp
->tag
= args
->tag
;
2696 resp
->rqstp
= rqstp
;
2697 cstate
->minorversion
= args
->minorversion
;
2698 fh_init(current_fh
, NFS4_FHSIZE
);
2699 fh_init(save_fh
, NFS4_FHSIZE
);
2701 * Don't use the deferral mechanism for NFSv4; compounds make it
2702 * too hard to avoid non-idempotency problems.
2704 clear_bit(RQ_USEDEFERRAL
, &rqstp
->rq_flags
);
2707 * According to RFC3010, this takes precedence over all other errors.
2709 status
= nfserr_minor_vers_mismatch
;
2710 if (nfsd_minorversion(nn
, args
->minorversion
, NFSD_TEST
) <= 0)
2713 status
= nfs41_check_op_ordering(args
);
2716 op
->status
= status
;
2720 check_if_stalefh_allowed(args
);
2722 rqstp
->rq_lease_breaker
= (void **)&cstate
->clp
;
2724 trace_nfsd_compound(rqstp
, args
->tag
, args
->taglen
, args
->client_opcnt
);
2725 while (!status
&& resp
->opcnt
< args
->opcnt
) {
2726 op
= &args
->ops
[resp
->opcnt
++];
2728 if (unlikely(resp
->opcnt
== NFSD_MAX_OPS_PER_COMPOUND
)) {
2729 /* If there are still more operations to process,
2730 * stop here and report NFS4ERR_RESOURCE. */
2731 if (cstate
->minorversion
== 0 &&
2732 args
->client_opcnt
> resp
->opcnt
) {
2733 op
->status
= nfserr_resource
;
2739 * The XDR decode routines may have pre-set op->status;
2740 * for example, if there is a miscellaneous XDR error
2741 * it will be set to nfserr_bad_xdr.
2744 if (op
->opnum
== OP_OPEN
)
2745 op
->status
= nfsd4_open_omfg(rqstp
, cstate
, op
);
2748 if (!current_fh
->fh_dentry
&&
2749 !HAS_FH_FLAG(current_fh
, NFSD4_FH_FOREIGN
)) {
2750 if (!(op
->opdesc
->op_flags
& ALLOWED_WITHOUT_FH
)) {
2751 op
->status
= nfserr_nofilehandle
;
2754 } else if (current_fh
->fh_export
&&
2755 current_fh
->fh_export
->ex_fslocs
.migrated
&&
2756 !(op
->opdesc
->op_flags
& ALLOWED_ON_ABSENT_FS
)) {
2757 op
->status
= nfserr_moved
;
2761 fh_clear_pre_post_attrs(current_fh
);
2763 /* If op is non-idempotent */
2764 if (op
->opdesc
->op_flags
& OP_MODIFIES_SOMETHING
) {
2766 * Don't execute this op if we couldn't encode a
2769 u32 plen
= op
->opdesc
->op_rsize_bop(rqstp
, op
);
2771 * Plus if there's another operation, make sure
2772 * we'll have space to at least encode an error:
2774 if (resp
->opcnt
< args
->opcnt
)
2775 plen
+= COMPOUND_ERR_SLACK_SPACE
;
2776 op
->status
= nfsd4_check_resp_size(resp
, plen
);
2782 if (op
->opdesc
->op_get_currentstateid
)
2783 op
->opdesc
->op_get_currentstateid(cstate
, &op
->u
);
2784 op
->status
= op
->opdesc
->op_func(rqstp
, cstate
, &op
->u
);
2786 /* Only from SEQUENCE */
2787 if (cstate
->status
== nfserr_replay_cache
) {
2788 dprintk("%s NFS4.1 replay from cache\n", __func__
);
2789 status
= op
->status
;
2793 if (op
->opdesc
->op_set_currentstateid
)
2794 op
->opdesc
->op_set_currentstateid(cstate
, &op
->u
);
2796 if (op
->opdesc
->op_flags
& OP_CLEAR_STATEID
)
2797 clear_current_stateid(cstate
);
2799 if (current_fh
->fh_export
&&
2800 need_wrongsec_check(rqstp
))
2801 op
->status
= check_nfsd_access(current_fh
->fh_export
, rqstp
);
2804 if (op
->status
== nfserr_replay_me
) {
2805 op
->replay
= &cstate
->replay_owner
->so_replay
;
2806 nfsd4_encode_replay(resp
->xdr
, op
);
2807 status
= op
->status
= op
->replay
->rp_status
;
2809 nfsd4_encode_operation(resp
, op
);
2810 status
= op
->status
;
2813 trace_nfsd_compound_status(args
->client_opcnt
, resp
->opcnt
,
2814 status
, nfsd4_op_name(op
->opnum
));
2816 nfsd4_cstate_clear_replay(cstate
);
2817 nfsd4_increment_op_stats(nn
, op
->opnum
);
2822 BUG_ON(cstate
->replay_owner
);
2824 cstate
->status
= status
;
2825 /* Reset deferral mechanism for RPC deferrals */
2826 set_bit(RQ_USEDEFERRAL
, &rqstp
->rq_flags
);
2830 #define op_encode_hdr_size (2)
2831 #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
2832 #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
2833 #define op_encode_change_info_maxsz (5)
2834 #define nfs4_fattr_bitmap_maxsz (4)
2836 /* We'll fall back on returning no lockowner if run out of space: */
2837 #define op_encode_lockowner_maxsz (0)
2838 #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
2840 #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
2842 #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
2843 #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
2844 op_encode_ace_maxsz)
2846 #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
2849 * The _rsize() helpers are invoked by the NFSv4 COMPOUND decoder, which
2850 * is called before sunrpc sets rq_res.buflen. Thus we have to compute
2851 * the maximum payload size here, based on transport limits and the size
2852 * of the remaining space in the rq_pages array.
2854 static u32
nfsd4_max_payload(const struct svc_rqst
*rqstp
)
2858 buflen
= (rqstp
->rq_page_end
- rqstp
->rq_next_page
) * PAGE_SIZE
;
2859 buflen
-= rqstp
->rq_auth_slack
;
2860 buflen
-= rqstp
->rq_res
.head
[0].iov_len
;
2861 return min_t(u32
, buflen
, svc_max_payload(rqstp
));
2864 static u32
nfsd4_only_status_rsize(const struct svc_rqst
*rqstp
,
2865 const struct nfsd4_op
*op
)
2867 return (op_encode_hdr_size
) * sizeof(__be32
);
2870 static u32
nfsd4_status_stateid_rsize(const struct svc_rqst
*rqstp
,
2871 const struct nfsd4_op
*op
)
2873 return (op_encode_hdr_size
+ op_encode_stateid_maxsz
)* sizeof(__be32
);
2876 static u32
nfsd4_access_rsize(const struct svc_rqst
*rqstp
,
2877 const struct nfsd4_op
*op
)
2879 /* ac_supported, ac_resp_access */
2880 return (op_encode_hdr_size
+ 2)* sizeof(__be32
);
2883 static u32
nfsd4_commit_rsize(const struct svc_rqst
*rqstp
,
2884 const struct nfsd4_op
*op
)
2886 return (op_encode_hdr_size
+ op_encode_verifier_maxsz
) * sizeof(__be32
);
2889 static u32
nfsd4_create_rsize(const struct svc_rqst
*rqstp
,
2890 const struct nfsd4_op
*op
)
2892 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
2893 + nfs4_fattr_bitmap_maxsz
) * sizeof(__be32
);
2897 * Note since this is an idempotent operation we won't insist on failing
2898 * the op prematurely if the estimate is too large. We may turn off splice
2899 * reads unnecessarily.
2901 static u32
nfsd4_getattr_rsize(const struct svc_rqst
*rqstp
,
2902 const struct nfsd4_op
*op
)
2904 const u32
*bmap
= op
->u
.getattr
.ga_bmval
;
2905 u32 bmap0
= bmap
[0], bmap1
= bmap
[1], bmap2
= bmap
[2];
2908 if (bmap0
& FATTR4_WORD0_ACL
)
2909 return nfsd4_max_payload(rqstp
);
2910 if (bmap0
& FATTR4_WORD0_FS_LOCATIONS
)
2911 return nfsd4_max_payload(rqstp
);
2913 if (bmap1
& FATTR4_WORD1_OWNER
) {
2914 ret
+= IDMAP_NAMESZ
+ 4;
2915 bmap1
&= ~FATTR4_WORD1_OWNER
;
2917 if (bmap1
& FATTR4_WORD1_OWNER_GROUP
) {
2918 ret
+= IDMAP_NAMESZ
+ 4;
2919 bmap1
&= ~FATTR4_WORD1_OWNER_GROUP
;
2921 if (bmap0
& FATTR4_WORD0_FILEHANDLE
) {
2922 ret
+= NFS4_FHSIZE
+ 4;
2923 bmap0
&= ~FATTR4_WORD0_FILEHANDLE
;
2925 if (bmap2
& FATTR4_WORD2_SECURITY_LABEL
) {
2926 ret
+= NFS4_MAXLABELLEN
+ 12;
2927 bmap2
&= ~FATTR4_WORD2_SECURITY_LABEL
;
2930 * Largest of remaining attributes are 16 bytes (e.g.,
2931 * supported_attributes)
2933 ret
+= 16 * (hweight32(bmap0
) + hweight32(bmap1
) + hweight32(bmap2
));
2934 /* bitmask, length */
2939 static u32
nfsd4_getfh_rsize(const struct svc_rqst
*rqstp
,
2940 const struct nfsd4_op
*op
)
2942 return (op_encode_hdr_size
+ 1) * sizeof(__be32
) + NFS4_FHSIZE
;
2945 static u32
nfsd4_link_rsize(const struct svc_rqst
*rqstp
,
2946 const struct nfsd4_op
*op
)
2948 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
)
2952 static u32
nfsd4_lock_rsize(const struct svc_rqst
*rqstp
,
2953 const struct nfsd4_op
*op
)
2955 return (op_encode_hdr_size
+ op_encode_lock_denied_maxsz
)
2959 static u32
nfsd4_open_rsize(const struct svc_rqst
*rqstp
,
2960 const struct nfsd4_op
*op
)
2962 return (op_encode_hdr_size
+ op_encode_stateid_maxsz
2963 + op_encode_change_info_maxsz
+ 1
2964 + nfs4_fattr_bitmap_maxsz
2965 + op_encode_delegation_maxsz
) * sizeof(__be32
);
2968 static u32
nfsd4_read_rsize(const struct svc_rqst
*rqstp
,
2969 const struct nfsd4_op
*op
)
2971 u32 rlen
= min(op
->u
.read
.rd_length
, nfsd4_max_payload(rqstp
));
2973 return (op_encode_hdr_size
+ 2 + XDR_QUADLEN(rlen
)) * sizeof(__be32
);
2976 static u32
nfsd4_read_plus_rsize(const struct svc_rqst
*rqstp
,
2977 const struct nfsd4_op
*op
)
2979 u32 rlen
= min(op
->u
.read
.rd_length
, nfsd4_max_payload(rqstp
));
2981 * If we detect that the file changed during hole encoding, then we
2982 * recover by encoding the remaining reply as data. This means we need
2983 * to set aside enough room to encode two data segments.
2985 u32 seg_len
= 2 * (1 + 2 + 1);
2987 return (op_encode_hdr_size
+ 2 + seg_len
+ XDR_QUADLEN(rlen
)) * sizeof(__be32
);
2990 static u32
nfsd4_readdir_rsize(const struct svc_rqst
*rqstp
,
2991 const struct nfsd4_op
*op
)
2993 u32 rlen
= min(op
->u
.readdir
.rd_maxcount
, nfsd4_max_payload(rqstp
));
2995 return (op_encode_hdr_size
+ op_encode_verifier_maxsz
+
2996 XDR_QUADLEN(rlen
)) * sizeof(__be32
);
2999 static u32
nfsd4_readlink_rsize(const struct svc_rqst
*rqstp
,
3000 const struct nfsd4_op
*op
)
3002 return (op_encode_hdr_size
+ 1) * sizeof(__be32
) + PAGE_SIZE
;
3005 static u32
nfsd4_remove_rsize(const struct svc_rqst
*rqstp
,
3006 const struct nfsd4_op
*op
)
3008 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
)
3012 static u32
nfsd4_rename_rsize(const struct svc_rqst
*rqstp
,
3013 const struct nfsd4_op
*op
)
3015 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
3016 + op_encode_change_info_maxsz
) * sizeof(__be32
);
3019 static u32
nfsd4_sequence_rsize(const struct svc_rqst
*rqstp
,
3020 const struct nfsd4_op
*op
)
3022 return (op_encode_hdr_size
3023 + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN
) + 5) * sizeof(__be32
);
3026 static u32
nfsd4_test_stateid_rsize(const struct svc_rqst
*rqstp
,
3027 const struct nfsd4_op
*op
)
3029 return (op_encode_hdr_size
+ 1 + op
->u
.test_stateid
.ts_num_ids
)
3033 static u32
nfsd4_setattr_rsize(const struct svc_rqst
*rqstp
,
3034 const struct nfsd4_op
*op
)
3036 return (op_encode_hdr_size
+ nfs4_fattr_bitmap_maxsz
) * sizeof(__be32
);
3039 static u32
nfsd4_secinfo_rsize(const struct svc_rqst
*rqstp
,
3040 const struct nfsd4_op
*op
)
3042 return (op_encode_hdr_size
+ RPC_AUTH_MAXFLAVOR
*
3043 (4 + XDR_QUADLEN(GSS_OID_MAX_LEN
))) * sizeof(__be32
);
3046 static u32
nfsd4_setclientid_rsize(const struct svc_rqst
*rqstp
,
3047 const struct nfsd4_op
*op
)
3049 return (op_encode_hdr_size
+ 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE
)) *
3053 static u32
nfsd4_write_rsize(const struct svc_rqst
*rqstp
,
3054 const struct nfsd4_op
*op
)
3056 return (op_encode_hdr_size
+ 2 + op_encode_verifier_maxsz
) * sizeof(__be32
);
3059 static u32
nfsd4_exchange_id_rsize(const struct svc_rqst
*rqstp
,
3060 const struct nfsd4_op
*op
)
3062 return (op_encode_hdr_size
+ 2 + 1 + /* eir_clientid, eir_sequenceid */\
3063 1 + 1 + /* eir_flags, spr_how */\
3064 4 + /* spo_must_enforce & _allow with bitmap */\
3065 2 + /*eir_server_owner.so_minor_id */\
3066 /* eir_server_owner.so_major_id<> */\
3067 XDR_QUADLEN(NFS4_OPAQUE_LIMIT
) + 1 +\
3068 /* eir_server_scope<> */\
3069 XDR_QUADLEN(NFS4_OPAQUE_LIMIT
) + 1 +\
3070 1 + /* eir_server_impl_id array length */\
3071 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32
);
3074 static u32
nfsd4_bind_conn_to_session_rsize(const struct svc_rqst
*rqstp
,
3075 const struct nfsd4_op
*op
)
3077 return (op_encode_hdr_size
+ \
3078 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN
) + /* bctsr_sessid */\
3079 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32
);
3082 static u32
nfsd4_create_session_rsize(const struct svc_rqst
*rqstp
,
3083 const struct nfsd4_op
*op
)
3085 return (op_encode_hdr_size
+ \
3086 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN
) + /* sessionid */\
3087 2 + /* csr_sequence, csr_flags */\
3088 op_encode_channel_attrs_maxsz
+ \
3089 op_encode_channel_attrs_maxsz
) * sizeof(__be32
);
3092 static u32
nfsd4_copy_rsize(const struct svc_rqst
*rqstp
,
3093 const struct nfsd4_op
*op
)
3095 return (op_encode_hdr_size
+
3096 1 /* wr_callback */ +
3097 op_encode_stateid_maxsz
/* wr_callback */ +
3099 1 /* wr_committed */ +
3100 op_encode_verifier_maxsz
+
3101 1 /* cr_consecutive */ +
3102 1 /* cr_synchronous */) * sizeof(__be32
);
3105 static u32
nfsd4_offload_status_rsize(const struct svc_rqst
*rqstp
,
3106 const struct nfsd4_op
*op
)
3108 return (op_encode_hdr_size
+
3110 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32
);
3113 static u32
nfsd4_copy_notify_rsize(const struct svc_rqst
*rqstp
,
3114 const struct nfsd4_op
*op
)
3116 return (op_encode_hdr_size
+
3117 3 /* cnr_lease_time */ +
3118 1 /* We support one cnr_source_server */ +
3119 1 /* cnr_stateid seq */ +
3120 op_encode_stateid_maxsz
/* cnr_stateid */ +
3121 1 /* num cnr_source_server*/ +
3124 XDR_QUADLEN(NFS4_OPAQUE_LIMIT
) /*nl4_loc + nl4_loc_sz */)
3128 static u32
nfsd4_get_dir_delegation_rsize(const struct svc_rqst
*rqstp
,
3129 const struct nfsd4_op
*op
)
3131 return (op_encode_hdr_size
+
3132 1 /* gddr_status */ +
3133 op_encode_verifier_maxsz
+
3134 op_encode_stateid_maxsz
+
3135 2 /* gddr_notification */ +
3136 2 /* gddr_child_attributes */ +
3137 2 /* gddr_dir_attributes */);
3140 #ifdef CONFIG_NFSD_PNFS
3141 static u32
nfsd4_getdeviceinfo_rsize(const struct svc_rqst
*rqstp
,
3142 const struct nfsd4_op
*op
)
3144 u32 rlen
= min(op
->u
.getdeviceinfo
.gd_maxcount
, nfsd4_max_payload(rqstp
));
3146 return (op_encode_hdr_size
+
3147 1 /* gd_layout_type*/ +
3149 2 /* gd_notify_types */) * sizeof(__be32
);
3153 * At this stage we don't really know what layout driver will handle the request,
3154 * so we need to define an arbitrary upper bound here.
3156 #define MAX_LAYOUT_SIZE 128
3157 static u32
nfsd4_layoutget_rsize(const struct svc_rqst
*rqstp
,
3158 const struct nfsd4_op
*op
)
3160 return (op_encode_hdr_size
+
3161 1 /* logr_return_on_close */ +
3162 op_encode_stateid_maxsz
+
3163 1 /* nr of layouts */ +
3164 MAX_LAYOUT_SIZE
) * sizeof(__be32
);
3167 static u32
nfsd4_layoutcommit_rsize(const struct svc_rqst
*rqstp
,
3168 const struct nfsd4_op
*op
)
3170 return (op_encode_hdr_size
+
3171 1 /* locr_newsize */ +
3172 2 /* ns_size */) * sizeof(__be32
);
3175 static u32
nfsd4_layoutreturn_rsize(const struct svc_rqst
*rqstp
,
3176 const struct nfsd4_op
*op
)
3178 return (op_encode_hdr_size
+
3179 1 /* lrs_stateid */ +
3180 op_encode_stateid_maxsz
) * sizeof(__be32
);
3182 #endif /* CONFIG_NFSD_PNFS */
3185 static u32
nfsd4_seek_rsize(const struct svc_rqst
*rqstp
,
3186 const struct nfsd4_op
*op
)
3188 return (op_encode_hdr_size
+ 3) * sizeof(__be32
);
3191 static u32
nfsd4_getxattr_rsize(const struct svc_rqst
*rqstp
,
3192 const struct nfsd4_op
*op
)
3194 u32 rlen
= min_t(u32
, XATTR_SIZE_MAX
, nfsd4_max_payload(rqstp
));
3196 return (op_encode_hdr_size
+ 1 + XDR_QUADLEN(rlen
)) * sizeof(__be32
);
3199 static u32
nfsd4_setxattr_rsize(const struct svc_rqst
*rqstp
,
3200 const struct nfsd4_op
*op
)
3202 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
)
3205 static u32
nfsd4_listxattrs_rsize(const struct svc_rqst
*rqstp
,
3206 const struct nfsd4_op
*op
)
3208 u32 rlen
= min(op
->u
.listxattrs
.lsxa_maxcount
, nfsd4_max_payload(rqstp
));
3210 return (op_encode_hdr_size
+ 4 + XDR_QUADLEN(rlen
)) * sizeof(__be32
);
3213 static u32
nfsd4_removexattr_rsize(const struct svc_rqst
*rqstp
,
3214 const struct nfsd4_op
*op
)
3216 return (op_encode_hdr_size
+ op_encode_change_info_maxsz
)
3221 static const struct nfsd4_operation nfsd4_ops
[] = {
3223 .op_func
= nfsd4_access
,
3224 .op_name
= "OP_ACCESS",
3225 .op_rsize_bop
= nfsd4_access_rsize
,
3228 .op_func
= nfsd4_close
,
3229 .op_flags
= OP_MODIFIES_SOMETHING
,
3230 .op_name
= "OP_CLOSE",
3231 .op_rsize_bop
= nfsd4_status_stateid_rsize
,
3232 .op_get_currentstateid
= nfsd4_get_closestateid
,
3233 .op_set_currentstateid
= nfsd4_set_closestateid
,
3236 .op_func
= nfsd4_commit
,
3237 .op_flags
= OP_MODIFIES_SOMETHING
,
3238 .op_name
= "OP_COMMIT",
3239 .op_rsize_bop
= nfsd4_commit_rsize
,
3242 .op_func
= nfsd4_create
,
3243 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
| OP_CLEAR_STATEID
,
3244 .op_name
= "OP_CREATE",
3245 .op_rsize_bop
= nfsd4_create_rsize
,
3247 [OP_DELEGRETURN
] = {
3248 .op_func
= nfsd4_delegreturn
,
3249 .op_flags
= OP_MODIFIES_SOMETHING
,
3250 .op_name
= "OP_DELEGRETURN",
3251 .op_rsize_bop
= nfsd4_only_status_rsize
,
3252 .op_get_currentstateid
= nfsd4_get_delegreturnstateid
,
3255 .op_func
= nfsd4_getattr
,
3256 .op_flags
= ALLOWED_ON_ABSENT_FS
,
3257 .op_rsize_bop
= nfsd4_getattr_rsize
,
3258 .op_name
= "OP_GETATTR",
3261 .op_func
= nfsd4_getfh
,
3262 .op_name
= "OP_GETFH",
3263 .op_rsize_bop
= nfsd4_getfh_rsize
,
3266 .op_func
= nfsd4_link
,
3267 .op_flags
= ALLOWED_ON_ABSENT_FS
| OP_MODIFIES_SOMETHING
3269 .op_name
= "OP_LINK",
3270 .op_rsize_bop
= nfsd4_link_rsize
,
3273 .op_func
= nfsd4_lock
,
3274 .op_release
= nfsd4_lock_release
,
3275 .op_flags
= OP_MODIFIES_SOMETHING
|
3276 OP_NONTRIVIAL_ERROR_ENCODE
,
3277 .op_name
= "OP_LOCK",
3278 .op_rsize_bop
= nfsd4_lock_rsize
,
3279 .op_set_currentstateid
= nfsd4_set_lockstateid
,
3282 .op_func
= nfsd4_lockt
,
3283 .op_release
= nfsd4_lockt_release
,
3284 .op_flags
= OP_NONTRIVIAL_ERROR_ENCODE
,
3285 .op_name
= "OP_LOCKT",
3286 .op_rsize_bop
= nfsd4_lock_rsize
,
3289 .op_func
= nfsd4_locku
,
3290 .op_flags
= OP_MODIFIES_SOMETHING
,
3291 .op_name
= "OP_LOCKU",
3292 .op_rsize_bop
= nfsd4_status_stateid_rsize
,
3293 .op_get_currentstateid
= nfsd4_get_lockustateid
,
3296 .op_func
= nfsd4_lookup
,
3297 .op_flags
= OP_HANDLES_WRONGSEC
| OP_CLEAR_STATEID
,
3298 .op_name
= "OP_LOOKUP",
3299 .op_rsize_bop
= nfsd4_only_status_rsize
,
3302 .op_func
= nfsd4_lookupp
,
3303 .op_flags
= OP_HANDLES_WRONGSEC
| OP_CLEAR_STATEID
,
3304 .op_name
= "OP_LOOKUPP",
3305 .op_rsize_bop
= nfsd4_only_status_rsize
,
3308 .op_func
= nfsd4_nverify
,
3309 .op_name
= "OP_NVERIFY",
3310 .op_rsize_bop
= nfsd4_only_status_rsize
,
3313 .op_func
= nfsd4_open
,
3314 .op_flags
= OP_HANDLES_WRONGSEC
| OP_MODIFIES_SOMETHING
,
3315 .op_name
= "OP_OPEN",
3316 .op_rsize_bop
= nfsd4_open_rsize
,
3317 .op_set_currentstateid
= nfsd4_set_openstateid
,
3319 [OP_OPEN_CONFIRM
] = {
3320 .op_func
= nfsd4_open_confirm
,
3321 .op_flags
= OP_MODIFIES_SOMETHING
,
3322 .op_name
= "OP_OPEN_CONFIRM",
3323 .op_rsize_bop
= nfsd4_status_stateid_rsize
,
3325 [OP_OPEN_DOWNGRADE
] = {
3326 .op_func
= nfsd4_open_downgrade
,
3327 .op_flags
= OP_MODIFIES_SOMETHING
,
3328 .op_name
= "OP_OPEN_DOWNGRADE",
3329 .op_rsize_bop
= nfsd4_status_stateid_rsize
,
3330 .op_get_currentstateid
= nfsd4_get_opendowngradestateid
,
3331 .op_set_currentstateid
= nfsd4_set_opendowngradestateid
,
3334 .op_func
= nfsd4_putfh
,
3335 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3336 | OP_IS_PUTFH_LIKE
| OP_CLEAR_STATEID
,
3337 .op_name
= "OP_PUTFH",
3338 .op_rsize_bop
= nfsd4_only_status_rsize
,
3341 .op_func
= nfsd4_putrootfh
,
3342 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3343 | OP_IS_PUTFH_LIKE
| OP_CLEAR_STATEID
,
3344 .op_name
= "OP_PUTPUBFH",
3345 .op_rsize_bop
= nfsd4_only_status_rsize
,
3348 .op_func
= nfsd4_putrootfh
,
3349 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3350 | OP_IS_PUTFH_LIKE
| OP_CLEAR_STATEID
,
3351 .op_name
= "OP_PUTROOTFH",
3352 .op_rsize_bop
= nfsd4_only_status_rsize
,
3355 .op_func
= nfsd4_read
,
3356 .op_release
= nfsd4_read_release
,
3357 .op_name
= "OP_READ",
3358 .op_rsize_bop
= nfsd4_read_rsize
,
3359 .op_get_currentstateid
= nfsd4_get_readstateid
,
3362 .op_func
= nfsd4_readdir
,
3363 .op_name
= "OP_READDIR",
3364 .op_rsize_bop
= nfsd4_readdir_rsize
,
3367 .op_func
= nfsd4_readlink
,
3368 .op_name
= "OP_READLINK",
3369 .op_rsize_bop
= nfsd4_readlink_rsize
,
3372 .op_func
= nfsd4_remove
,
3373 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3374 .op_name
= "OP_REMOVE",
3375 .op_rsize_bop
= nfsd4_remove_rsize
,
3378 .op_func
= nfsd4_rename
,
3379 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3380 .op_name
= "OP_RENAME",
3381 .op_rsize_bop
= nfsd4_rename_rsize
,
3384 .op_func
= nfsd4_renew
,
3385 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3386 | OP_MODIFIES_SOMETHING
,
3387 .op_name
= "OP_RENEW",
3388 .op_rsize_bop
= nfsd4_only_status_rsize
,
3392 .op_func
= nfsd4_restorefh
,
3393 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3394 | OP_IS_PUTFH_LIKE
| OP_MODIFIES_SOMETHING
,
3395 .op_name
= "OP_RESTOREFH",
3396 .op_rsize_bop
= nfsd4_only_status_rsize
,
3399 .op_func
= nfsd4_savefh
,
3400 .op_flags
= OP_HANDLES_WRONGSEC
| OP_MODIFIES_SOMETHING
,
3401 .op_name
= "OP_SAVEFH",
3402 .op_rsize_bop
= nfsd4_only_status_rsize
,
3405 .op_func
= nfsd4_secinfo
,
3406 .op_release
= nfsd4_secinfo_release
,
3407 .op_flags
= OP_HANDLES_WRONGSEC
,
3408 .op_name
= "OP_SECINFO",
3409 .op_rsize_bop
= nfsd4_secinfo_rsize
,
3412 .op_func
= nfsd4_setattr
,
3413 .op_name
= "OP_SETATTR",
3414 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
3415 | OP_NONTRIVIAL_ERROR_ENCODE
,
3416 .op_rsize_bop
= nfsd4_setattr_rsize
,
3417 .op_get_currentstateid
= nfsd4_get_setattrstateid
,
3419 [OP_SETCLIENTID
] = {
3420 .op_func
= nfsd4_setclientid
,
3421 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3422 | OP_MODIFIES_SOMETHING
| OP_CACHEME
3423 | OP_NONTRIVIAL_ERROR_ENCODE
,
3424 .op_name
= "OP_SETCLIENTID",
3425 .op_rsize_bop
= nfsd4_setclientid_rsize
,
3427 [OP_SETCLIENTID_CONFIRM
] = {
3428 .op_func
= nfsd4_setclientid_confirm
,
3429 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3430 | OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3431 .op_name
= "OP_SETCLIENTID_CONFIRM",
3432 .op_rsize_bop
= nfsd4_only_status_rsize
,
3435 .op_func
= nfsd4_verify
,
3436 .op_name
= "OP_VERIFY",
3437 .op_rsize_bop
= nfsd4_only_status_rsize
,
3440 .op_func
= nfsd4_write
,
3441 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3442 .op_name
= "OP_WRITE",
3443 .op_rsize_bop
= nfsd4_write_rsize
,
3444 .op_get_currentstateid
= nfsd4_get_writestateid
,
3446 [OP_RELEASE_LOCKOWNER
] = {
3447 .op_func
= nfsd4_release_lockowner
,
3448 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_ON_ABSENT_FS
3449 | OP_MODIFIES_SOMETHING
,
3450 .op_name
= "OP_RELEASE_LOCKOWNER",
3451 .op_rsize_bop
= nfsd4_only_status_rsize
,
3454 /* NFSv4.1 operations */
3455 [OP_EXCHANGE_ID
] = {
3456 .op_func
= nfsd4_exchange_id
,
3457 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
3458 | OP_MODIFIES_SOMETHING
,
3459 .op_name
= "OP_EXCHANGE_ID",
3460 .op_rsize_bop
= nfsd4_exchange_id_rsize
,
3462 [OP_BACKCHANNEL_CTL
] = {
3463 .op_func
= nfsd4_backchannel_ctl
,
3464 .op_flags
= ALLOWED_WITHOUT_FH
| OP_MODIFIES_SOMETHING
,
3465 .op_name
= "OP_BACKCHANNEL_CTL",
3466 .op_rsize_bop
= nfsd4_only_status_rsize
,
3468 [OP_BIND_CONN_TO_SESSION
] = {
3469 .op_func
= nfsd4_bind_conn_to_session
,
3470 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
3471 | OP_MODIFIES_SOMETHING
,
3472 .op_name
= "OP_BIND_CONN_TO_SESSION",
3473 .op_rsize_bop
= nfsd4_bind_conn_to_session_rsize
,
3475 [OP_CREATE_SESSION
] = {
3476 .op_func
= nfsd4_create_session
,
3477 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
3478 | OP_MODIFIES_SOMETHING
,
3479 .op_name
= "OP_CREATE_SESSION",
3480 .op_rsize_bop
= nfsd4_create_session_rsize
,
3482 [OP_DESTROY_SESSION
] = {
3483 .op_func
= nfsd4_destroy_session
,
3484 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
3485 | OP_MODIFIES_SOMETHING
,
3486 .op_name
= "OP_DESTROY_SESSION",
3487 .op_rsize_bop
= nfsd4_only_status_rsize
,
3490 .op_func
= nfsd4_sequence
,
3491 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
,
3492 .op_name
= "OP_SEQUENCE",
3493 .op_rsize_bop
= nfsd4_sequence_rsize
,
3495 [OP_DESTROY_CLIENTID
] = {
3496 .op_func
= nfsd4_destroy_clientid
,
3497 .op_flags
= ALLOWED_WITHOUT_FH
| ALLOWED_AS_FIRST_OP
3498 | OP_MODIFIES_SOMETHING
,
3499 .op_name
= "OP_DESTROY_CLIENTID",
3500 .op_rsize_bop
= nfsd4_only_status_rsize
,
3502 [OP_RECLAIM_COMPLETE
] = {
3503 .op_func
= nfsd4_reclaim_complete
,
3504 .op_flags
= ALLOWED_WITHOUT_FH
| OP_MODIFIES_SOMETHING
,
3505 .op_name
= "OP_RECLAIM_COMPLETE",
3506 .op_rsize_bop
= nfsd4_only_status_rsize
,
3508 [OP_SECINFO_NO_NAME
] = {
3509 .op_func
= nfsd4_secinfo_no_name
,
3510 .op_release
= nfsd4_secinfo_no_name_release
,
3511 .op_flags
= OP_HANDLES_WRONGSEC
,
3512 .op_name
= "OP_SECINFO_NO_NAME",
3513 .op_rsize_bop
= nfsd4_secinfo_rsize
,
3515 [OP_TEST_STATEID
] = {
3516 .op_func
= nfsd4_test_stateid
,
3517 .op_flags
= ALLOWED_WITHOUT_FH
,
3518 .op_name
= "OP_TEST_STATEID",
3519 .op_rsize_bop
= nfsd4_test_stateid_rsize
,
3521 [OP_FREE_STATEID
] = {
3522 .op_func
= nfsd4_free_stateid
,
3523 .op_flags
= ALLOWED_WITHOUT_FH
| OP_MODIFIES_SOMETHING
,
3524 .op_name
= "OP_FREE_STATEID",
3525 .op_get_currentstateid
= nfsd4_get_freestateid
,
3526 .op_rsize_bop
= nfsd4_only_status_rsize
,
3528 [OP_GET_DIR_DELEGATION
] = {
3529 .op_func
= nfsd4_get_dir_delegation
,
3530 .op_flags
= OP_MODIFIES_SOMETHING
,
3531 .op_name
= "OP_GET_DIR_DELEGATION",
3532 .op_rsize_bop
= nfsd4_get_dir_delegation_rsize
,
3534 #ifdef CONFIG_NFSD_PNFS
3535 [OP_GETDEVICEINFO
] = {
3536 .op_func
= nfsd4_getdeviceinfo
,
3537 .op_release
= nfsd4_getdeviceinfo_release
,
3538 .op_flags
= ALLOWED_WITHOUT_FH
,
3539 .op_name
= "OP_GETDEVICEINFO",
3540 .op_rsize_bop
= nfsd4_getdeviceinfo_rsize
,
3543 .op_func
= nfsd4_layoutget
,
3544 .op_release
= nfsd4_layoutget_release
,
3545 .op_flags
= OP_MODIFIES_SOMETHING
,
3546 .op_name
= "OP_LAYOUTGET",
3547 .op_rsize_bop
= nfsd4_layoutget_rsize
,
3549 [OP_LAYOUTCOMMIT
] = {
3550 .op_func
= nfsd4_layoutcommit
,
3551 .op_flags
= OP_MODIFIES_SOMETHING
,
3552 .op_name
= "OP_LAYOUTCOMMIT",
3553 .op_rsize_bop
= nfsd4_layoutcommit_rsize
,
3555 [OP_LAYOUTRETURN
] = {
3556 .op_func
= nfsd4_layoutreturn
,
3557 .op_flags
= OP_MODIFIES_SOMETHING
,
3558 .op_name
= "OP_LAYOUTRETURN",
3559 .op_rsize_bop
= nfsd4_layoutreturn_rsize
,
3561 #endif /* CONFIG_NFSD_PNFS */
3563 /* NFSv4.2 operations */
3565 .op_func
= nfsd4_allocate
,
3566 .op_flags
= OP_MODIFIES_SOMETHING
,
3567 .op_name
= "OP_ALLOCATE",
3568 .op_rsize_bop
= nfsd4_only_status_rsize
,
3571 .op_func
= nfsd4_deallocate
,
3572 .op_flags
= OP_MODIFIES_SOMETHING
,
3573 .op_name
= "OP_DEALLOCATE",
3574 .op_rsize_bop
= nfsd4_only_status_rsize
,
3577 .op_func
= nfsd4_clone
,
3578 .op_flags
= OP_MODIFIES_SOMETHING
,
3579 .op_name
= "OP_CLONE",
3580 .op_rsize_bop
= nfsd4_only_status_rsize
,
3583 .op_func
= nfsd4_copy
,
3584 .op_flags
= OP_MODIFIES_SOMETHING
,
3585 .op_name
= "OP_COPY",
3586 .op_rsize_bop
= nfsd4_copy_rsize
,
3589 .op_func
= nfsd4_read
,
3590 .op_release
= nfsd4_read_release
,
3591 .op_name
= "OP_READ_PLUS",
3592 .op_rsize_bop
= nfsd4_read_plus_rsize
,
3593 .op_get_currentstateid
= nfsd4_get_readstateid
,
3596 .op_func
= nfsd4_seek
,
3597 .op_name
= "OP_SEEK",
3598 .op_rsize_bop
= nfsd4_seek_rsize
,
3600 [OP_OFFLOAD_STATUS
] = {
3601 .op_func
= nfsd4_offload_status
,
3602 .op_name
= "OP_OFFLOAD_STATUS",
3603 .op_rsize_bop
= nfsd4_offload_status_rsize
,
3605 [OP_OFFLOAD_CANCEL
] = {
3606 .op_func
= nfsd4_offload_cancel
,
3607 .op_flags
= OP_MODIFIES_SOMETHING
,
3608 .op_name
= "OP_OFFLOAD_CANCEL",
3609 .op_rsize_bop
= nfsd4_only_status_rsize
,
3611 [OP_COPY_NOTIFY
] = {
3612 .op_func
= nfsd4_copy_notify
,
3613 .op_flags
= OP_MODIFIES_SOMETHING
,
3614 .op_name
= "OP_COPY_NOTIFY",
3615 .op_rsize_bop
= nfsd4_copy_notify_rsize
,
3618 .op_func
= nfsd4_getxattr
,
3619 .op_name
= "OP_GETXATTR",
3620 .op_rsize_bop
= nfsd4_getxattr_rsize
,
3623 .op_func
= nfsd4_setxattr
,
3624 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3625 .op_name
= "OP_SETXATTR",
3626 .op_rsize_bop
= nfsd4_setxattr_rsize
,
3629 .op_func
= nfsd4_listxattrs
,
3630 .op_name
= "OP_LISTXATTRS",
3631 .op_rsize_bop
= nfsd4_listxattrs_rsize
,
3633 [OP_REMOVEXATTR
] = {
3634 .op_func
= nfsd4_removexattr
,
3635 .op_flags
= OP_MODIFIES_SOMETHING
| OP_CACHEME
,
3636 .op_name
= "OP_REMOVEXATTR",
3637 .op_rsize_bop
= nfsd4_removexattr_rsize
,
3642 * nfsd4_spo_must_allow - Determine if the compound op contains an
3643 * operation that is allowed to be sent with machine credentials
3645 * @rqstp: a pointer to the struct svc_rqst
3647 * Checks to see if the compound contains a spo_must_allow op
3648 * and confirms that it was sent with the proper machine creds.
3651 bool nfsd4_spo_must_allow(struct svc_rqst
*rqstp
)
3653 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
3654 struct nfsd4_compoundargs
*argp
= rqstp
->rq_argp
;
3655 struct nfsd4_op
*this;
3656 struct nfsd4_compound_state
*cstate
= &resp
->cstate
;
3657 struct nfs4_op_map
*allow
= &cstate
->clp
->cl_spo_must_allow
;
3660 if (!cstate
->minorversion
)
3663 if (cstate
->spo_must_allowed
)
3666 opiter
= resp
->opcnt
;
3667 while (opiter
< argp
->opcnt
) {
3668 this = &argp
->ops
[opiter
++];
3669 if (test_bit(this->opnum
, allow
->u
.longs
) &&
3670 cstate
->clp
->cl_mach_cred
&&
3671 nfsd4_mach_creds_match(cstate
->clp
, rqstp
)) {
3672 cstate
->spo_must_allowed
= true;
3676 cstate
->spo_must_allowed
= false;
3680 int nfsd4_max_reply(struct svc_rqst
*rqstp
, struct nfsd4_op
*op
)
3682 if (op
->opnum
== OP_ILLEGAL
|| op
->status
== nfserr_notsupp
)
3683 return op_encode_hdr_size
* sizeof(__be32
);
3685 BUG_ON(OPDESC(op
)->op_rsize_bop
== NULL
);
3686 return OPDESC(op
)->op_rsize_bop(rqstp
, op
);
3689 void warn_on_nonidempotent_op(struct nfsd4_op
*op
)
3691 if (OPDESC(op
)->op_flags
& OP_MODIFIES_SOMETHING
) {
3692 pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
3693 op
->opnum
, nfsd4_op_name(op
->opnum
));
3698 static const char *nfsd4_op_name(unsigned opnum
)
3700 if (opnum
< ARRAY_SIZE(nfsd4_ops
))
3701 return nfsd4_ops
[opnum
].op_name
;
3702 return "unknown_operation";
3705 static const struct svc_procedure nfsd_procedures4
[2] = {
3707 .pc_func
= nfsd4_proc_null
,
3708 .pc_decode
= nfssvc_decode_voidarg
,
3709 .pc_encode
= nfssvc_encode_voidres
,
3710 .pc_argsize
= sizeof(struct nfsd_voidargs
),
3711 .pc_argzero
= sizeof(struct nfsd_voidargs
),
3712 .pc_ressize
= sizeof(struct nfsd_voidres
),
3713 .pc_cachetype
= RC_NOCACHE
,
3717 [NFSPROC4_COMPOUND
] = {
3718 .pc_func
= nfsd4_proc_compound
,
3719 .pc_decode
= nfs4svc_decode_compoundargs
,
3720 .pc_encode
= nfs4svc_encode_compoundres
,
3721 .pc_argsize
= sizeof(struct nfsd4_compoundargs
),
3722 .pc_argzero
= offsetof(struct nfsd4_compoundargs
, iops
),
3723 .pc_ressize
= sizeof(struct nfsd4_compoundres
),
3724 .pc_release
= nfsd4_release_compoundargs
,
3725 .pc_cachetype
= RC_NOCACHE
,
3726 .pc_xdrressize
= NFSD_BUFSIZE
/4,
3727 .pc_name
= "COMPOUND",
3731 static DEFINE_PER_CPU_ALIGNED(unsigned long,
3732 nfsd_count4
[ARRAY_SIZE(nfsd_procedures4
)]);
3733 const struct svc_version nfsd_version4
= {
3735 .vs_nproc
= ARRAY_SIZE(nfsd_procedures4
),
3736 .vs_proc
= nfsd_procedures4
,
3737 .vs_count
= nfsd_count4
,
3738 .vs_dispatch
= nfsd_dispatch
,
3739 .vs_xdrsize
= NFS4_SVC_XDRSIZE
,
3740 .vs_rpcb_optnl
= true,
3741 .vs_need_cong_ctrl
= true,