4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/ratelimit.h>
43 #include <linux/printk.h>
44 #include <linux/slab.h>
45 #include <linux/sunrpc/clnt.h>
46 #include <linux/nfs.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/nfs_page.h>
50 #include <linux/nfs_mount.h>
51 #include <linux/namei.h>
52 #include <linux/mount.h>
53 #include <linux/module.h>
54 #include <linux/xattr.h>
55 #include <linux/utsname.h>
56 #include <linux/freezer.h>
57 #include <linux/iversion.h>
60 #include "delegation.h"
66 #include "nfs4idmap.h"
67 #include "nfs4session.h"
70 #include "nfs4trace.h"
72 #define NFSDBG_FACILITY NFSDBG_PROC
74 #define NFS4_BITMASK_SZ 3
76 #define NFS4_POLL_RETRY_MIN (HZ/10)
77 #define NFS4_POLL_RETRY_MAX (15*HZ)
79 /* file attributes which can be mapped to nfs attributes */
80 #define NFS4_VALID_ATTRS (ATTR_MODE \
91 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
92 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
93 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
94 static int nfs4_proc_getattr(struct nfs_server
*, struct nfs_fh
*, struct nfs_fattr
*, struct nfs4_label
*label
, struct inode
*inode
);
95 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
, struct nfs4_label
*label
, struct inode
*inode
);
96 static int nfs4_do_setattr(struct inode
*inode
, const struct cred
*cred
,
97 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
98 struct nfs_open_context
*ctx
, struct nfs4_label
*ilabel
,
99 struct nfs4_label
*olabel
);
100 #ifdef CONFIG_NFS_V4_1
101 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
102 const struct cred
*cred
,
103 struct nfs4_slot
*slot
,
105 static int nfs41_test_stateid(struct nfs_server
*, nfs4_stateid
*,
106 const struct cred
*);
107 static int nfs41_free_stateid(struct nfs_server
*, const nfs4_stateid
*,
108 const struct cred
*, bool);
111 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
112 static inline struct nfs4_label
*
113 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
114 struct iattr
*sattr
, struct nfs4_label
*label
)
121 if (nfs_server_capable(dir
, NFS_CAP_SECURITY_LABEL
) == 0)
124 err
= security_dentry_init_security(dentry
, sattr
->ia_mode
,
125 &dentry
->d_name
, (void **)&label
->label
, &label
->len
);
132 nfs4_label_release_security(struct nfs4_label
*label
)
135 security_release_secctx(label
->label
, label
->len
);
137 static inline u32
*nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
140 return server
->attr_bitmask
;
142 return server
->attr_bitmask_nl
;
145 static inline struct nfs4_label
*
146 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
147 struct iattr
*sattr
, struct nfs4_label
*l
)
150 nfs4_label_release_security(struct nfs4_label
*label
)
153 nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
154 { return server
->attr_bitmask
; }
157 /* Prevent leaks of NFSv4 errors into userland */
158 static int nfs4_map_errors(int err
)
163 case -NFS4ERR_RESOURCE
:
164 case -NFS4ERR_LAYOUTTRYLATER
:
165 case -NFS4ERR_RECALLCONFLICT
:
167 case -NFS4ERR_WRONGSEC
:
168 case -NFS4ERR_WRONG_CRED
:
170 case -NFS4ERR_BADOWNER
:
171 case -NFS4ERR_BADNAME
:
173 case -NFS4ERR_SHARE_DENIED
:
175 case -NFS4ERR_MINOR_VERS_MISMATCH
:
176 return -EPROTONOSUPPORT
;
177 case -NFS4ERR_FILE_OPEN
:
180 dprintk("%s could not handle NFSv4 error %d\n",
188 * This is our standard bitmap for GETATTR requests.
190 const u32 nfs4_fattr_bitmap
[3] = {
192 | FATTR4_WORD0_CHANGE
195 | FATTR4_WORD0_FILEID
,
197 | FATTR4_WORD1_NUMLINKS
199 | FATTR4_WORD1_OWNER_GROUP
200 | FATTR4_WORD1_RAWDEV
201 | FATTR4_WORD1_SPACE_USED
202 | FATTR4_WORD1_TIME_ACCESS
203 | FATTR4_WORD1_TIME_METADATA
204 | FATTR4_WORD1_TIME_MODIFY
205 | FATTR4_WORD1_MOUNTED_ON_FILEID
,
206 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
207 FATTR4_WORD2_SECURITY_LABEL
211 static const u32 nfs4_pnfs_open_bitmap
[3] = {
213 | FATTR4_WORD0_CHANGE
216 | FATTR4_WORD0_FILEID
,
218 | FATTR4_WORD1_NUMLINKS
220 | FATTR4_WORD1_OWNER_GROUP
221 | FATTR4_WORD1_RAWDEV
222 | FATTR4_WORD1_SPACE_USED
223 | FATTR4_WORD1_TIME_ACCESS
224 | FATTR4_WORD1_TIME_METADATA
225 | FATTR4_WORD1_TIME_MODIFY
,
226 FATTR4_WORD2_MDSTHRESHOLD
227 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
228 | FATTR4_WORD2_SECURITY_LABEL
232 static const u32 nfs4_open_noattr_bitmap
[3] = {
234 | FATTR4_WORD0_FILEID
,
237 const u32 nfs4_statfs_bitmap
[3] = {
238 FATTR4_WORD0_FILES_AVAIL
239 | FATTR4_WORD0_FILES_FREE
240 | FATTR4_WORD0_FILES_TOTAL
,
241 FATTR4_WORD1_SPACE_AVAIL
242 | FATTR4_WORD1_SPACE_FREE
243 | FATTR4_WORD1_SPACE_TOTAL
246 const u32 nfs4_pathconf_bitmap
[3] = {
248 | FATTR4_WORD0_MAXNAME
,
252 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
253 | FATTR4_WORD0_MAXREAD
254 | FATTR4_WORD0_MAXWRITE
255 | FATTR4_WORD0_LEASE_TIME
,
256 FATTR4_WORD1_TIME_DELTA
257 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
258 FATTR4_WORD2_LAYOUT_BLKSIZE
259 | FATTR4_WORD2_CLONE_BLKSIZE
262 const u32 nfs4_fs_locations_bitmap
[3] = {
266 | FATTR4_WORD0_FILEID
267 | FATTR4_WORD0_FS_LOCATIONS
,
269 | FATTR4_WORD1_OWNER_GROUP
270 | FATTR4_WORD1_RAWDEV
271 | FATTR4_WORD1_SPACE_USED
272 | FATTR4_WORD1_TIME_ACCESS
273 | FATTR4_WORD1_TIME_METADATA
274 | FATTR4_WORD1_TIME_MODIFY
275 | FATTR4_WORD1_MOUNTED_ON_FILEID
,
278 static void nfs4_bitmap_copy_adjust(__u32
*dst
, const __u32
*src
,
281 unsigned long cache_validity
;
283 memcpy(dst
, src
, NFS4_BITMASK_SZ
*sizeof(*dst
));
284 if (!inode
|| !nfs4_have_delegation(inode
, FMODE_READ
))
287 cache_validity
= READ_ONCE(NFS_I(inode
)->cache_validity
);
288 if (!(cache_validity
& NFS_INO_REVAL_FORCED
))
289 cache_validity
&= ~(NFS_INO_INVALID_CHANGE
290 | NFS_INO_INVALID_SIZE
);
292 if (!(cache_validity
& NFS_INO_INVALID_SIZE
))
293 dst
[0] &= ~FATTR4_WORD0_SIZE
;
295 if (!(cache_validity
& NFS_INO_INVALID_CHANGE
))
296 dst
[0] &= ~FATTR4_WORD0_CHANGE
;
299 static void nfs4_bitmap_copy_adjust_setattr(__u32
*dst
,
300 const __u32
*src
, struct inode
*inode
)
302 nfs4_bitmap_copy_adjust(dst
, src
, inode
);
305 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
306 struct nfs4_readdir_arg
*readdir
)
308 unsigned int attrs
= FATTR4_WORD0_FILEID
| FATTR4_WORD0_TYPE
;
312 readdir
->cookie
= cookie
;
313 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
318 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
323 * NFSv4 servers do not return entries for '.' and '..'
324 * Therefore, we fake these entries here. We let '.'
325 * have cookie 0 and '..' have cookie 1. Note that
326 * when talking to the server, we always send cookie 0
329 start
= p
= kmap_atomic(*readdir
->pages
);
332 *p
++ = xdr_one
; /* next */
333 *p
++ = xdr_zero
; /* cookie, first word */
334 *p
++ = xdr_one
; /* cookie, second word */
335 *p
++ = xdr_one
; /* entry len */
336 memcpy(p
, ".\0\0\0", 4); /* entry */
338 *p
++ = xdr_one
; /* bitmap length */
339 *p
++ = htonl(attrs
); /* bitmap */
340 *p
++ = htonl(12); /* attribute buffer length */
341 *p
++ = htonl(NF4DIR
);
342 p
= xdr_encode_hyper(p
, NFS_FILEID(d_inode(dentry
)));
345 *p
++ = xdr_one
; /* next */
346 *p
++ = xdr_zero
; /* cookie, first word */
347 *p
++ = xdr_two
; /* cookie, second word */
348 *p
++ = xdr_two
; /* entry len */
349 memcpy(p
, "..\0\0", 4); /* entry */
351 *p
++ = xdr_one
; /* bitmap length */
352 *p
++ = htonl(attrs
); /* bitmap */
353 *p
++ = htonl(12); /* attribute buffer length */
354 *p
++ = htonl(NF4DIR
);
355 p
= xdr_encode_hyper(p
, NFS_FILEID(d_inode(dentry
->d_parent
)));
357 readdir
->pgbase
= (char *)p
- (char *)start
;
358 readdir
->count
-= readdir
->pgbase
;
359 kunmap_atomic(start
);
362 static void nfs4_test_and_free_stateid(struct nfs_server
*server
,
363 nfs4_stateid
*stateid
,
364 const struct cred
*cred
)
366 const struct nfs4_minor_version_ops
*ops
= server
->nfs_client
->cl_mvops
;
368 ops
->test_and_free_expired(server
, stateid
, cred
);
371 static void __nfs4_free_revoked_stateid(struct nfs_server
*server
,
372 nfs4_stateid
*stateid
,
373 const struct cred
*cred
)
375 stateid
->type
= NFS4_REVOKED_STATEID_TYPE
;
376 nfs4_test_and_free_stateid(server
, stateid
, cred
);
379 static void nfs4_free_revoked_stateid(struct nfs_server
*server
,
380 const nfs4_stateid
*stateid
,
381 const struct cred
*cred
)
385 nfs4_stateid_copy(&tmp
, stateid
);
386 __nfs4_free_revoked_stateid(server
, &tmp
, cred
);
389 static long nfs4_update_delay(long *timeout
)
393 return NFS4_POLL_RETRY_MAX
;
395 *timeout
= NFS4_POLL_RETRY_MIN
;
396 if (*timeout
> NFS4_POLL_RETRY_MAX
)
397 *timeout
= NFS4_POLL_RETRY_MAX
;
403 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
409 freezable_schedule_timeout_killable_unsafe(
410 nfs4_update_delay(timeout
));
411 if (fatal_signal_pending(current
))
416 /* This is the error handling routine for processes that are allowed
419 static int nfs4_do_handle_exception(struct nfs_server
*server
,
420 int errorcode
, struct nfs4_exception
*exception
)
422 struct nfs_client
*clp
= server
->nfs_client
;
423 struct nfs4_state
*state
= exception
->state
;
424 const nfs4_stateid
*stateid
= exception
->stateid
;
425 struct inode
*inode
= exception
->inode
;
428 exception
->delay
= 0;
429 exception
->recovering
= 0;
430 exception
->retry
= 0;
432 if (stateid
== NULL
&& state
!= NULL
)
433 stateid
= &state
->stateid
;
438 case -NFS4ERR_BADHANDLE
:
440 if (inode
!= NULL
&& S_ISREG(inode
->i_mode
))
441 pnfs_destroy_layout(NFS_I(inode
));
443 case -NFS4ERR_DELEG_REVOKED
:
444 case -NFS4ERR_ADMIN_REVOKED
:
445 case -NFS4ERR_EXPIRED
:
446 case -NFS4ERR_BAD_STATEID
:
447 if (inode
!= NULL
&& stateid
!= NULL
) {
448 nfs_inode_find_state_and_recover(inode
,
450 goto wait_on_recovery
;
453 case -NFS4ERR_OPENMODE
:
457 err
= nfs_async_inode_return_delegation(inode
,
460 goto wait_on_recovery
;
461 if (stateid
!= NULL
&& stateid
->type
== NFS4_DELEGATION_STATEID_TYPE
) {
462 exception
->retry
= 1;
468 ret
= nfs4_schedule_stateid_recovery(server
, state
);
471 goto wait_on_recovery
;
472 case -NFS4ERR_STALE_STATEID
:
473 case -NFS4ERR_STALE_CLIENTID
:
474 nfs4_schedule_lease_recovery(clp
);
475 goto wait_on_recovery
;
477 ret
= nfs4_schedule_migration_recovery(server
);
480 goto wait_on_recovery
;
481 case -NFS4ERR_LEASE_MOVED
:
482 nfs4_schedule_lease_moved_recovery(clp
);
483 goto wait_on_recovery
;
484 #if defined(CONFIG_NFS_V4_1)
485 case -NFS4ERR_BADSESSION
:
486 case -NFS4ERR_BADSLOT
:
487 case -NFS4ERR_BAD_HIGH_SLOT
:
488 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
489 case -NFS4ERR_DEADSESSION
:
490 case -NFS4ERR_SEQ_FALSE_RETRY
:
491 case -NFS4ERR_SEQ_MISORDERED
:
492 dprintk("%s ERROR: %d Reset session\n", __func__
,
494 nfs4_schedule_session_recovery(clp
->cl_session
, errorcode
);
495 goto wait_on_recovery
;
496 #endif /* defined(CONFIG_NFS_V4_1) */
497 case -NFS4ERR_FILE_OPEN
:
498 if (exception
->timeout
> HZ
) {
499 /* We have retried a decent amount, time to
507 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
510 case -NFS4ERR_LAYOUTTRYLATER
:
511 case -NFS4ERR_RECALLCONFLICT
:
512 exception
->delay
= 1;
515 case -NFS4ERR_RETRY_UNCACHED_REP
:
516 case -NFS4ERR_OLD_STATEID
:
517 exception
->retry
= 1;
519 case -NFS4ERR_BADOWNER
:
520 /* The following works around a Linux server bug! */
521 case -NFS4ERR_BADNAME
:
522 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
523 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
524 exception
->retry
= 1;
525 printk(KERN_WARNING
"NFS: v4 server %s "
526 "does not accept raw "
528 "Reenabling the idmapper.\n",
529 server
->nfs_client
->cl_hostname
);
532 /* We failed to handle the error */
533 return nfs4_map_errors(ret
);
535 exception
->recovering
= 1;
539 /* This is the error handling routine for processes that are allowed
542 int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
544 struct nfs_client
*clp
= server
->nfs_client
;
547 ret
= nfs4_do_handle_exception(server
, errorcode
, exception
);
548 if (exception
->delay
) {
549 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
552 if (exception
->recovering
) {
553 ret
= nfs4_wait_clnt_recover(clp
);
554 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
561 exception
->retry
= 1;
566 nfs4_async_handle_exception(struct rpc_task
*task
, struct nfs_server
*server
,
567 int errorcode
, struct nfs4_exception
*exception
)
569 struct nfs_client
*clp
= server
->nfs_client
;
572 ret
= nfs4_do_handle_exception(server
, errorcode
, exception
);
573 if (exception
->delay
) {
574 rpc_delay(task
, nfs4_update_delay(&exception
->timeout
));
577 if (exception
->recovering
) {
578 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
579 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
580 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
583 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
588 exception
->retry
= 1;
590 * For NFS4ERR_MOVED, the client transport will need to
591 * be recomputed after migration recovery has completed.
593 if (errorcode
== -NFS4ERR_MOVED
)
594 rpc_task_release_transport(task
);
600 nfs4_async_handle_error(struct rpc_task
*task
, struct nfs_server
*server
,
601 struct nfs4_state
*state
, long *timeout
)
603 struct nfs4_exception exception
= {
607 if (task
->tk_status
>= 0)
610 exception
.timeout
= *timeout
;
611 task
->tk_status
= nfs4_async_handle_exception(task
, server
,
614 if (exception
.delay
&& timeout
)
615 *timeout
= exception
.timeout
;
622 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
623 * or 'false' otherwise.
625 static bool _nfs4_is_integrity_protected(struct nfs_client
*clp
)
627 rpc_authflavor_t flavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
628 return (flavor
== RPC_AUTH_GSS_KRB5I
) || (flavor
== RPC_AUTH_GSS_KRB5P
);
631 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
633 spin_lock(&clp
->cl_lock
);
634 if (time_before(clp
->cl_last_renewal
,timestamp
))
635 clp
->cl_last_renewal
= timestamp
;
636 spin_unlock(&clp
->cl_lock
);
639 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
641 struct nfs_client
*clp
= server
->nfs_client
;
643 if (!nfs4_has_session(clp
))
644 do_renew_lease(clp
, timestamp
);
647 struct nfs4_call_sync_data
{
648 const struct nfs_server
*seq_server
;
649 struct nfs4_sequence_args
*seq_args
;
650 struct nfs4_sequence_res
*seq_res
;
653 void nfs4_init_sequence(struct nfs4_sequence_args
*args
,
654 struct nfs4_sequence_res
*res
, int cache_reply
,
657 args
->sa_slot
= NULL
;
658 args
->sa_cache_this
= cache_reply
;
659 args
->sa_privileged
= privileged
;
664 static void nfs40_sequence_free_slot(struct nfs4_sequence_res
*res
)
666 struct nfs4_slot
*slot
= res
->sr_slot
;
667 struct nfs4_slot_table
*tbl
;
670 spin_lock(&tbl
->slot_tbl_lock
);
671 if (!nfs41_wake_and_assign_slot(tbl
, slot
))
672 nfs4_free_slot(tbl
, slot
);
673 spin_unlock(&tbl
->slot_tbl_lock
);
678 static int nfs40_sequence_done(struct rpc_task
*task
,
679 struct nfs4_sequence_res
*res
)
681 if (res
->sr_slot
!= NULL
)
682 nfs40_sequence_free_slot(res
);
686 #if defined(CONFIG_NFS_V4_1)
688 static void nfs41_release_slot(struct nfs4_slot
*slot
)
690 struct nfs4_session
*session
;
691 struct nfs4_slot_table
*tbl
;
692 bool send_new_highest_used_slotid
= false;
697 session
= tbl
->session
;
699 /* Bump the slot sequence number */
704 spin_lock(&tbl
->slot_tbl_lock
);
705 /* Be nice to the server: try to ensure that the last transmitted
706 * value for highest_user_slotid <= target_highest_slotid
708 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
709 send_new_highest_used_slotid
= true;
711 if (nfs41_wake_and_assign_slot(tbl
, slot
)) {
712 send_new_highest_used_slotid
= false;
715 nfs4_free_slot(tbl
, slot
);
717 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
718 send_new_highest_used_slotid
= false;
720 spin_unlock(&tbl
->slot_tbl_lock
);
721 if (send_new_highest_used_slotid
)
722 nfs41_notify_server(session
->clp
);
723 if (waitqueue_active(&tbl
->slot_waitq
))
724 wake_up_all(&tbl
->slot_waitq
);
727 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
729 nfs41_release_slot(res
->sr_slot
);
733 static int nfs41_sequence_process(struct rpc_task
*task
,
734 struct nfs4_sequence_res
*res
)
736 struct nfs4_session
*session
;
737 struct nfs4_slot
*slot
= res
->sr_slot
;
738 struct nfs_client
*clp
;
739 bool interrupted
= false;
744 /* don't increment the sequence number if the task wasn't sent */
745 if (!RPC_WAS_SENT(task
))
748 session
= slot
->table
->session
;
750 if (slot
->interrupted
) {
751 if (res
->sr_status
!= -NFS4ERR_DELAY
)
752 slot
->interrupted
= 0;
756 trace_nfs4_sequence_done(session
, res
);
757 /* Check the SEQUENCE operation status */
758 switch (res
->sr_status
) {
760 /* Update the slot's sequence and clientid lease timer */
763 do_renew_lease(clp
, res
->sr_timestamp
);
764 /* Check sequence flags */
765 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
,
767 nfs41_update_target_slotid(slot
->table
, slot
, res
);
771 * sr_status remains 1 if an RPC level error occurred.
772 * The server may or may not have processed the sequence
774 * Mark the slot as having hosted an interrupted RPC call.
776 slot
->interrupted
= 1;
779 /* The server detected a resend of the RPC call and
780 * returned NFS4ERR_DELAY as per Section 2.10.6.2
783 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
788 case -NFS4ERR_RETRY_UNCACHED_REP
:
789 case -NFS4ERR_SEQ_FALSE_RETRY
:
791 * The server thinks we tried to replay a request.
792 * Retry the call after bumping the sequence ID.
795 case -NFS4ERR_BADSLOT
:
797 * The slot id we used was probably retired. Try again
798 * using a different slot id.
800 if (slot
->slot_nr
< slot
->table
->target_highest_slotid
)
801 goto session_recover
;
803 case -NFS4ERR_SEQ_MISORDERED
:
805 * Was the last operation on this sequence interrupted?
806 * If so, retry after bumping the sequence number.
811 * Could this slot have been previously retired?
812 * If so, then the server may be expecting seq_nr = 1!
814 if (slot
->seq_nr
!= 1) {
818 goto session_recover
;
820 /* Just update the slot sequence no. */
824 /* The session may be reset by one of the error handlers. */
825 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
829 nfs4_schedule_session_recovery(session
, res
->sr_status
);
834 if (rpc_restart_call_prepare(task
)) {
835 nfs41_sequence_free_slot(res
);
841 if (!rpc_restart_call(task
))
843 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
847 int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
849 if (!nfs41_sequence_process(task
, res
))
851 if (res
->sr_slot
!= NULL
)
852 nfs41_sequence_free_slot(res
);
856 EXPORT_SYMBOL_GPL(nfs41_sequence_done
);
858 static int nfs4_sequence_process(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
860 if (res
->sr_slot
== NULL
)
862 if (res
->sr_slot
->table
->session
!= NULL
)
863 return nfs41_sequence_process(task
, res
);
864 return nfs40_sequence_done(task
, res
);
867 static void nfs4_sequence_free_slot(struct nfs4_sequence_res
*res
)
869 if (res
->sr_slot
!= NULL
) {
870 if (res
->sr_slot
->table
->session
!= NULL
)
871 nfs41_sequence_free_slot(res
);
873 nfs40_sequence_free_slot(res
);
877 int nfs4_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
879 if (res
->sr_slot
== NULL
)
881 if (!res
->sr_slot
->table
->session
)
882 return nfs40_sequence_done(task
, res
);
883 return nfs41_sequence_done(task
, res
);
885 EXPORT_SYMBOL_GPL(nfs4_sequence_done
);
887 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
889 struct nfs4_call_sync_data
*data
= calldata
;
891 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
893 nfs4_setup_sequence(data
->seq_server
->nfs_client
,
894 data
->seq_args
, data
->seq_res
, task
);
897 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
899 struct nfs4_call_sync_data
*data
= calldata
;
901 nfs41_sequence_done(task
, data
->seq_res
);
904 static const struct rpc_call_ops nfs41_call_sync_ops
= {
905 .rpc_call_prepare
= nfs41_call_sync_prepare
,
906 .rpc_call_done
= nfs41_call_sync_done
,
910 nfs4_sequence_process_interrupted(struct nfs_client
*client
,
911 struct nfs4_slot
*slot
, const struct cred
*cred
)
913 struct rpc_task
*task
;
915 task
= _nfs41_proc_sequence(client
, cred
, slot
, true);
917 rpc_put_task_async(task
);
920 #else /* !CONFIG_NFS_V4_1 */
922 static int nfs4_sequence_process(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
924 return nfs40_sequence_done(task
, res
);
927 static void nfs4_sequence_free_slot(struct nfs4_sequence_res
*res
)
929 if (res
->sr_slot
!= NULL
)
930 nfs40_sequence_free_slot(res
);
933 int nfs4_sequence_done(struct rpc_task
*task
,
934 struct nfs4_sequence_res
*res
)
936 return nfs40_sequence_done(task
, res
);
938 EXPORT_SYMBOL_GPL(nfs4_sequence_done
);
941 nfs4_sequence_process_interrupted(struct nfs_client
*client
,
942 struct nfs4_slot
*slot
, const struct cred
*cred
)
945 slot
->interrupted
= 0;
948 #endif /* !CONFIG_NFS_V4_1 */
951 void nfs4_sequence_attach_slot(struct nfs4_sequence_args
*args
,
952 struct nfs4_sequence_res
*res
,
953 struct nfs4_slot
*slot
)
957 slot
->privileged
= args
->sa_privileged
? 1 : 0;
958 args
->sa_slot
= slot
;
961 res
->sr_timestamp
= jiffies
;
962 res
->sr_status_flags
= 0;
967 int nfs4_setup_sequence(struct nfs_client
*client
,
968 struct nfs4_sequence_args
*args
,
969 struct nfs4_sequence_res
*res
,
970 struct rpc_task
*task
)
972 struct nfs4_session
*session
= nfs4_get_session(client
);
973 struct nfs4_slot_table
*tbl
= client
->cl_slot_tbl
;
974 struct nfs4_slot
*slot
;
976 /* slot already allocated? */
977 if (res
->sr_slot
!= NULL
)
981 tbl
= &session
->fc_slot_table
;
982 task
->tk_timeout
= 0;
986 spin_lock(&tbl
->slot_tbl_lock
);
987 /* The state manager will wait until the slot table is empty */
988 if (nfs4_slot_tbl_draining(tbl
) && !args
->sa_privileged
)
991 slot
= nfs4_alloc_slot(tbl
);
993 /* Try again in 1/4 second */
994 if (slot
== ERR_PTR(-ENOMEM
))
995 task
->tk_timeout
= HZ
>> 2;
998 spin_unlock(&tbl
->slot_tbl_lock
);
1000 if (likely(!slot
->interrupted
))
1002 nfs4_sequence_process_interrupted(client
,
1003 slot
, task
->tk_msg
.rpc_cred
);
1006 nfs4_sequence_attach_slot(args
, res
, slot
);
1008 trace_nfs4_setup_sequence(session
, args
);
1010 rpc_call_start(task
);
1014 if (args
->sa_privileged
)
1015 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
1016 NULL
, RPC_PRIORITY_PRIVILEGED
);
1018 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
1019 spin_unlock(&tbl
->slot_tbl_lock
);
1022 EXPORT_SYMBOL_GPL(nfs4_setup_sequence
);
1024 static void nfs40_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
1026 struct nfs4_call_sync_data
*data
= calldata
;
1027 nfs4_setup_sequence(data
->seq_server
->nfs_client
,
1028 data
->seq_args
, data
->seq_res
, task
);
1031 static void nfs40_call_sync_done(struct rpc_task
*task
, void *calldata
)
1033 struct nfs4_call_sync_data
*data
= calldata
;
1034 nfs4_sequence_done(task
, data
->seq_res
);
1037 static const struct rpc_call_ops nfs40_call_sync_ops
= {
1038 .rpc_call_prepare
= nfs40_call_sync_prepare
,
1039 .rpc_call_done
= nfs40_call_sync_done
,
1042 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
1043 struct nfs_server
*server
,
1044 struct rpc_message
*msg
,
1045 struct nfs4_sequence_args
*args
,
1046 struct nfs4_sequence_res
*res
)
1049 struct rpc_task
*task
;
1050 struct nfs_client
*clp
= server
->nfs_client
;
1051 struct nfs4_call_sync_data data
= {
1052 .seq_server
= server
,
1056 struct rpc_task_setup task_setup
= {
1059 .callback_ops
= clp
->cl_mvops
->call_sync_ops
,
1060 .callback_data
= &data
1063 task
= rpc_run_task(&task_setup
);
1065 ret
= PTR_ERR(task
);
1067 ret
= task
->tk_status
;
1073 int nfs4_call_sync(struct rpc_clnt
*clnt
,
1074 struct nfs_server
*server
,
1075 struct rpc_message
*msg
,
1076 struct nfs4_sequence_args
*args
,
1077 struct nfs4_sequence_res
*res
,
1080 nfs4_init_sequence(args
, res
, cache_reply
, 0);
1081 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
);
1085 nfs4_inc_nlink_locked(struct inode
*inode
)
1087 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_OTHER
;
1092 nfs4_dec_nlink_locked(struct inode
*inode
)
1094 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_OTHER
;
1099 update_changeattr_locked(struct inode
*dir
, struct nfs4_change_info
*cinfo
,
1100 unsigned long timestamp
, unsigned long cache_validity
)
1102 struct nfs_inode
*nfsi
= NFS_I(dir
);
1104 nfsi
->cache_validity
|= NFS_INO_INVALID_CTIME
1105 | NFS_INO_INVALID_MTIME
1106 | NFS_INO_INVALID_DATA
1108 if (cinfo
->atomic
&& cinfo
->before
== inode_peek_iversion_raw(dir
)) {
1109 nfsi
->cache_validity
&= ~NFS_INO_REVAL_PAGECACHE
;
1110 nfsi
->attrtimeo_timestamp
= jiffies
;
1112 nfs_force_lookup_revalidate(dir
);
1113 if (cinfo
->before
!= inode_peek_iversion_raw(dir
))
1114 nfsi
->cache_validity
|= NFS_INO_INVALID_ACCESS
|
1115 NFS_INO_INVALID_ACL
;
1117 inode_set_iversion_raw(dir
, cinfo
->after
);
1118 nfsi
->read_cache_jiffies
= timestamp
;
1119 nfsi
->attr_gencount
= nfs_inc_attr_generation_counter();
1120 nfsi
->cache_validity
&= ~NFS_INO_INVALID_CHANGE
;
1121 nfs_fscache_invalidate(dir
);
1125 update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
,
1126 unsigned long timestamp
, unsigned long cache_validity
)
1128 spin_lock(&dir
->i_lock
);
1129 update_changeattr_locked(dir
, cinfo
, timestamp
, cache_validity
);
1130 spin_unlock(&dir
->i_lock
);
1133 struct nfs4_open_createattrs
{
1134 struct nfs4_label
*label
;
1135 struct iattr
*sattr
;
1136 const __u32 verf
[2];
1139 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
1140 int err
, struct nfs4_exception
*exception
)
1144 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
1146 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
1147 exception
->retry
= 1;
1152 nfs4_map_atomic_open_share(struct nfs_server
*server
,
1153 fmode_t fmode
, int openflags
)
1157 switch (fmode
& (FMODE_READ
| FMODE_WRITE
)) {
1159 res
= NFS4_SHARE_ACCESS_READ
;
1162 res
= NFS4_SHARE_ACCESS_WRITE
;
1164 case FMODE_READ
|FMODE_WRITE
:
1165 res
= NFS4_SHARE_ACCESS_BOTH
;
1167 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
1169 /* Want no delegation if we're using O_DIRECT */
1170 if (openflags
& O_DIRECT
)
1171 res
|= NFS4_SHARE_WANT_NO_DELEG
;
1176 static enum open_claim_type4
1177 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
1178 enum open_claim_type4 claim
)
1180 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
1185 case NFS4_OPEN_CLAIM_FH
:
1186 return NFS4_OPEN_CLAIM_NULL
;
1187 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1188 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1189 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1190 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
1194 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
1196 p
->o_res
.f_attr
= &p
->f_attr
;
1197 p
->o_res
.f_label
= p
->f_label
;
1198 p
->o_res
.seqid
= p
->o_arg
.seqid
;
1199 p
->c_res
.seqid
= p
->c_arg
.seqid
;
1200 p
->o_res
.server
= p
->o_arg
.server
;
1201 p
->o_res
.access_request
= p
->o_arg
.access
;
1202 nfs_fattr_init(&p
->f_attr
);
1203 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
1206 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
1207 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
1208 const struct nfs4_open_createattrs
*c
,
1209 enum open_claim_type4 claim
,
1212 struct dentry
*parent
= dget_parent(dentry
);
1213 struct inode
*dir
= d_inode(parent
);
1214 struct nfs_server
*server
= NFS_SERVER(dir
);
1215 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
1216 struct nfs4_label
*label
= (c
!= NULL
) ? c
->label
: NULL
;
1217 struct nfs4_opendata
*p
;
1219 p
= kzalloc(sizeof(*p
), gfp_mask
);
1223 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
1224 if (IS_ERR(p
->f_label
))
1227 p
->a_label
= nfs4_label_alloc(server
, gfp_mask
);
1228 if (IS_ERR(p
->a_label
))
1231 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
1232 p
->o_arg
.seqid
= alloc_seqid(&sp
->so_seqid
, gfp_mask
);
1233 if (IS_ERR(p
->o_arg
.seqid
))
1234 goto err_free_label
;
1235 nfs_sb_active(dentry
->d_sb
);
1236 p
->dentry
= dget(dentry
);
1239 atomic_inc(&sp
->so_count
);
1240 p
->o_arg
.open_flags
= flags
;
1241 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
1242 p
->o_arg
.umask
= current_umask();
1243 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
1244 p
->o_arg
.share_access
= nfs4_map_atomic_open_share(server
,
1246 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
1247 * will return permission denied for all bits until close */
1248 if (!(flags
& O_EXCL
)) {
1249 /* ask server to check for all possible rights as results
1251 switch (p
->o_arg
.claim
) {
1254 case NFS4_OPEN_CLAIM_NULL
:
1255 case NFS4_OPEN_CLAIM_FH
:
1256 p
->o_arg
.access
= NFS4_ACCESS_READ
|
1257 NFS4_ACCESS_MODIFY
|
1258 NFS4_ACCESS_EXTEND
|
1259 NFS4_ACCESS_EXECUTE
;
1262 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
1263 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
1264 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
1265 p
->o_arg
.name
= &dentry
->d_name
;
1266 p
->o_arg
.server
= server
;
1267 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
1268 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
1269 p
->o_arg
.label
= nfs4_label_copy(p
->a_label
, label
);
1270 switch (p
->o_arg
.claim
) {
1271 case NFS4_OPEN_CLAIM_NULL
:
1272 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1273 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1274 p
->o_arg
.fh
= NFS_FH(dir
);
1276 case NFS4_OPEN_CLAIM_PREVIOUS
:
1277 case NFS4_OPEN_CLAIM_FH
:
1278 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1279 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1280 p
->o_arg
.fh
= NFS_FH(d_inode(dentry
));
1282 if (c
!= NULL
&& c
->sattr
!= NULL
&& c
->sattr
->ia_valid
!= 0) {
1283 p
->o_arg
.u
.attrs
= &p
->attrs
;
1284 memcpy(&p
->attrs
, c
->sattr
, sizeof(p
->attrs
));
1286 memcpy(p
->o_arg
.u
.verifier
.data
, c
->verf
,
1287 sizeof(p
->o_arg
.u
.verifier
.data
));
1289 p
->c_arg
.fh
= &p
->o_res
.fh
;
1290 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
1291 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
1292 nfs4_init_opendata_res(p
);
1293 kref_init(&p
->kref
);
1297 nfs4_label_free(p
->a_label
);
1299 nfs4_label_free(p
->f_label
);
1307 static void nfs4_opendata_free(struct kref
*kref
)
1309 struct nfs4_opendata
*p
= container_of(kref
,
1310 struct nfs4_opendata
, kref
);
1311 struct super_block
*sb
= p
->dentry
->d_sb
;
1313 nfs4_lgopen_release(p
->lgp
);
1314 nfs_free_seqid(p
->o_arg
.seqid
);
1315 nfs4_sequence_free_slot(&p
->o_res
.seq_res
);
1316 if (p
->state
!= NULL
)
1317 nfs4_put_open_state(p
->state
);
1318 nfs4_put_state_owner(p
->owner
);
1320 nfs4_label_free(p
->a_label
);
1321 nfs4_label_free(p
->f_label
);
1325 nfs_sb_deactive(sb
);
1326 nfs_fattr_free_names(&p
->f_attr
);
1327 kfree(p
->f_attr
.mdsthreshold
);
1331 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1334 kref_put(&p
->kref
, nfs4_opendata_free
);
1337 static bool nfs4_mode_match_open_stateid(struct nfs4_state
*state
,
1340 switch(fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1341 case FMODE_READ
|FMODE_WRITE
:
1342 return state
->n_rdwr
!= 0;
1344 return state
->n_wronly
!= 0;
1346 return state
->n_rdonly
!= 0;
1352 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
,
1353 int open_mode
, enum open_claim_type4 claim
)
1357 if (open_mode
& (O_EXCL
|O_TRUNC
))
1360 case NFS4_OPEN_CLAIM_NULL
:
1361 case NFS4_OPEN_CLAIM_FH
:
1366 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1368 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1369 && state
->n_rdonly
!= 0;
1372 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1373 && state
->n_wronly
!= 0;
1375 case FMODE_READ
|FMODE_WRITE
:
1376 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1377 && state
->n_rdwr
!= 0;
1383 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
,
1384 enum open_claim_type4 claim
)
1386 if (delegation
== NULL
)
1388 if ((delegation
->type
& fmode
) != fmode
)
1390 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1393 case NFS4_OPEN_CLAIM_NULL
:
1394 case NFS4_OPEN_CLAIM_FH
:
1396 case NFS4_OPEN_CLAIM_PREVIOUS
:
1397 if (!test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1403 nfs_mark_delegation_referenced(delegation
);
1407 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1416 case FMODE_READ
|FMODE_WRITE
:
1419 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1422 #ifdef CONFIG_NFS_V4_1
1423 static bool nfs_open_stateid_recover_openmode(struct nfs4_state
*state
)
1425 if (state
->n_rdonly
&& !test_bit(NFS_O_RDONLY_STATE
, &state
->flags
))
1427 if (state
->n_wronly
&& !test_bit(NFS_O_WRONLY_STATE
, &state
->flags
))
1429 if (state
->n_rdwr
&& !test_bit(NFS_O_RDWR_STATE
, &state
->flags
))
1433 #endif /* CONFIG_NFS_V4_1 */
1435 static void nfs_state_log_update_open_stateid(struct nfs4_state
*state
)
1437 if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
))
1438 wake_up_all(&state
->waitq
);
1441 static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state
*state
,
1442 const nfs4_stateid
*stateid
)
1444 u32 state_seqid
= be32_to_cpu(state
->open_stateid
.seqid
);
1445 u32 stateid_seqid
= be32_to_cpu(stateid
->seqid
);
1447 if (stateid_seqid
== state_seqid
+ 1U ||
1448 (stateid_seqid
== 1U && state_seqid
== 0xffffffffU
))
1449 nfs_state_log_update_open_stateid(state
);
1451 set_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
);
1454 static void nfs_test_and_clear_all_open_stateid(struct nfs4_state
*state
)
1456 struct nfs_client
*clp
= state
->owner
->so_server
->nfs_client
;
1457 bool need_recover
= false;
1459 if (test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
) && state
->n_rdonly
)
1460 need_recover
= true;
1461 if (test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
) && state
->n_wronly
)
1462 need_recover
= true;
1463 if (test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
) && state
->n_rdwr
)
1464 need_recover
= true;
1466 nfs4_state_mark_reclaim_nograce(clp
, state
);
1470 * Check for whether or not the caller may update the open stateid
1471 * to the value passed in by stateid.
1473 * Note: This function relies heavily on the server implementing
1474 * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2
1476 * i.e. The stateid seqids have to be initialised to 1, and
1477 * are then incremented on every state transition.
1479 static bool nfs_need_update_open_stateid(struct nfs4_state
*state
,
1480 const nfs4_stateid
*stateid
)
1482 if (test_bit(NFS_OPEN_STATE
, &state
->flags
) == 0 ||
1483 !nfs4_stateid_match_other(stateid
, &state
->open_stateid
)) {
1484 if (stateid
->seqid
== cpu_to_be32(1))
1485 nfs_state_log_update_open_stateid(state
);
1487 set_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
);
1491 if (nfs4_stateid_is_newer(stateid
, &state
->open_stateid
)) {
1492 nfs_state_log_out_of_order_open_stateid(state
, stateid
);
1498 static void nfs_resync_open_stateid_locked(struct nfs4_state
*state
)
1500 if (!(state
->n_wronly
|| state
->n_rdonly
|| state
->n_rdwr
))
1502 if (state
->n_wronly
)
1503 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1504 if (state
->n_rdonly
)
1505 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1507 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1508 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1511 static void nfs_clear_open_stateid_locked(struct nfs4_state
*state
,
1512 nfs4_stateid
*stateid
, fmode_t fmode
)
1514 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1515 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1517 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1520 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1523 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1524 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1525 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1527 if (stateid
== NULL
)
1529 /* Handle OPEN+OPEN_DOWNGRADE races */
1530 if (nfs4_stateid_match_other(stateid
, &state
->open_stateid
) &&
1531 !nfs4_stateid_is_newer(stateid
, &state
->open_stateid
)) {
1532 nfs_resync_open_stateid_locked(state
);
1535 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1536 nfs4_stateid_copy(&state
->stateid
, stateid
);
1537 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1538 trace_nfs4_open_stateid_update(state
->inode
, stateid
, 0);
1540 nfs_state_log_update_open_stateid(state
);
1543 static void nfs_clear_open_stateid(struct nfs4_state
*state
,
1544 nfs4_stateid
*arg_stateid
,
1545 nfs4_stateid
*stateid
, fmode_t fmode
)
1547 write_seqlock(&state
->seqlock
);
1548 /* Ignore, if the CLOSE argment doesn't match the current stateid */
1549 if (nfs4_state_match_open_stateid_other(state
, arg_stateid
))
1550 nfs_clear_open_stateid_locked(state
, stateid
, fmode
);
1551 write_sequnlock(&state
->seqlock
);
1552 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1553 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1556 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
,
1557 const nfs4_stateid
*stateid
, nfs4_stateid
*freeme
)
1558 __must_hold(&state
->owner
->so_lock
)
1559 __must_hold(&state
->seqlock
)
1567 if (!nfs_need_update_open_stateid(state
, stateid
))
1569 if (!test_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
))
1573 /* Rely on seqids for serialisation with NFSv4.0 */
1574 if (!nfs4_has_session(NFS_SERVER(state
->inode
)->nfs_client
))
1577 prepare_to_wait(&state
->waitq
, &wait
, TASK_KILLABLE
);
1579 * Ensure we process the state changes in the same order
1580 * in which the server processed them by delaying the
1581 * update of the stateid until we are in sequence.
1583 write_sequnlock(&state
->seqlock
);
1584 spin_unlock(&state
->owner
->so_lock
);
1586 trace_nfs4_open_stateid_update_wait(state
->inode
, stateid
, 0);
1587 if (!signal_pending(current
)) {
1588 if (schedule_timeout(5*HZ
) == 0)
1594 finish_wait(&state
->waitq
, &wait
);
1596 spin_lock(&state
->owner
->so_lock
);
1597 write_seqlock(&state
->seqlock
);
1600 if (test_bit(NFS_OPEN_STATE
, &state
->flags
) &&
1601 !nfs4_stateid_match_other(stateid
, &state
->open_stateid
)) {
1602 nfs4_stateid_copy(freeme
, &state
->open_stateid
);
1603 nfs_test_and_clear_all_open_stateid(state
);
1606 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1607 nfs4_stateid_copy(&state
->stateid
, stateid
);
1608 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1609 trace_nfs4_open_stateid_update(state
->inode
, stateid
, status
);
1610 nfs_state_log_update_open_stateid(state
);
1613 static void nfs_state_set_open_stateid(struct nfs4_state
*state
,
1614 const nfs4_stateid
*open_stateid
,
1616 nfs4_stateid
*freeme
)
1619 * Protect the call to nfs4_state_set_mode_locked and
1620 * serialise the stateid update
1622 write_seqlock(&state
->seqlock
);
1623 nfs_set_open_stateid_locked(state
, open_stateid
, freeme
);
1626 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1629 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1631 case FMODE_READ
|FMODE_WRITE
:
1632 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1634 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1635 write_sequnlock(&state
->seqlock
);
1638 static void nfs_state_set_delegation(struct nfs4_state
*state
,
1639 const nfs4_stateid
*deleg_stateid
,
1643 * Protect the call to nfs4_state_set_mode_locked and
1644 * serialise the stateid update
1646 write_seqlock(&state
->seqlock
);
1647 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1648 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1649 write_sequnlock(&state
->seqlock
);
1652 static void nfs_state_clear_delegation(struct nfs4_state
*state
)
1654 write_seqlock(&state
->seqlock
);
1655 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1656 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1657 write_sequnlock(&state
->seqlock
);
1660 static int update_open_stateid(struct nfs4_state
*state
,
1661 const nfs4_stateid
*open_stateid
,
1662 const nfs4_stateid
*delegation
,
1665 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1666 struct nfs_client
*clp
= server
->nfs_client
;
1667 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1668 struct nfs_delegation
*deleg_cur
;
1669 nfs4_stateid freeme
= { };
1672 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1675 spin_lock(&state
->owner
->so_lock
);
1676 if (open_stateid
!= NULL
) {
1677 nfs_state_set_open_stateid(state
, open_stateid
, fmode
, &freeme
);
1681 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1682 if (deleg_cur
== NULL
)
1685 spin_lock(&deleg_cur
->lock
);
1686 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1687 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1688 (deleg_cur
->type
& fmode
) != fmode
)
1689 goto no_delegation_unlock
;
1691 if (delegation
== NULL
)
1692 delegation
= &deleg_cur
->stateid
;
1693 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1694 goto no_delegation_unlock
;
1696 nfs_mark_delegation_referenced(deleg_cur
);
1697 nfs_state_set_delegation(state
, &deleg_cur
->stateid
, fmode
);
1699 no_delegation_unlock
:
1700 spin_unlock(&deleg_cur
->lock
);
1703 update_open_stateflags(state
, fmode
);
1704 spin_unlock(&state
->owner
->so_lock
);
1707 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1708 nfs4_schedule_state_manager(clp
);
1709 if (freeme
.type
!= 0)
1710 nfs4_test_and_free_stateid(server
, &freeme
,
1711 state
->owner
->so_cred
);
1716 static bool nfs4_update_lock_stateid(struct nfs4_lock_state
*lsp
,
1717 const nfs4_stateid
*stateid
)
1719 struct nfs4_state
*state
= lsp
->ls_state
;
1722 spin_lock(&state
->state_lock
);
1723 if (!nfs4_stateid_match_other(stateid
, &lsp
->ls_stateid
))
1725 if (!nfs4_stateid_is_newer(stateid
, &lsp
->ls_stateid
))
1727 nfs4_stateid_copy(&lsp
->ls_stateid
, stateid
);
1730 spin_unlock(&state
->state_lock
);
1734 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1736 struct nfs_delegation
*delegation
;
1738 fmode
&= FMODE_READ
|FMODE_WRITE
;
1740 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1741 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1746 nfs4_inode_return_delegation(inode
);
1749 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1751 struct nfs4_state
*state
= opendata
->state
;
1752 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1753 struct nfs_delegation
*delegation
;
1754 int open_mode
= opendata
->o_arg
.open_flags
;
1755 fmode_t fmode
= opendata
->o_arg
.fmode
;
1756 enum open_claim_type4 claim
= opendata
->o_arg
.claim
;
1757 nfs4_stateid stateid
;
1761 spin_lock(&state
->owner
->so_lock
);
1762 if (can_open_cached(state
, fmode
, open_mode
, claim
)) {
1763 update_open_stateflags(state
, fmode
);
1764 spin_unlock(&state
->owner
->so_lock
);
1765 goto out_return_state
;
1767 spin_unlock(&state
->owner
->so_lock
);
1769 delegation
= rcu_dereference(nfsi
->delegation
);
1770 if (!can_open_delegated(delegation
, fmode
, claim
)) {
1774 /* Save the delegation */
1775 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1777 nfs_release_seqid(opendata
->o_arg
.seqid
);
1778 if (!opendata
->is_recover
) {
1779 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1785 /* Try to update the stateid using the delegation */
1786 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1787 goto out_return_state
;
1790 return ERR_PTR(ret
);
1792 refcount_inc(&state
->count
);
1797 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1799 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1800 struct nfs_delegation
*delegation
;
1801 int delegation_flags
= 0;
1804 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1806 delegation_flags
= delegation
->flags
;
1808 switch (data
->o_arg
.claim
) {
1811 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1812 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1813 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1814 "returning a delegation for "
1815 "OPEN(CLAIM_DELEGATE_CUR)\n",
1819 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1820 nfs_inode_set_delegation(state
->inode
,
1821 data
->owner
->so_cred
,
1822 data
->o_res
.delegation_type
,
1823 &data
->o_res
.delegation
,
1824 data
->o_res
.pagemod_limit
);
1826 nfs_inode_reclaim_delegation(state
->inode
,
1827 data
->owner
->so_cred
,
1828 data
->o_res
.delegation_type
,
1829 &data
->o_res
.delegation
,
1830 data
->o_res
.pagemod_limit
);
1832 if (data
->o_res
.do_recall
)
1833 nfs_async_inode_return_delegation(state
->inode
,
1834 &data
->o_res
.delegation
);
1838 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1839 * and update the nfs4_state.
1841 static struct nfs4_state
*
1842 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1844 struct inode
*inode
= data
->state
->inode
;
1845 struct nfs4_state
*state
= data
->state
;
1848 if (!data
->rpc_done
) {
1849 if (data
->rpc_status
)
1850 return ERR_PTR(data
->rpc_status
);
1851 /* cached opens have already been processed */
1855 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1857 return ERR_PTR(ret
);
1859 if (data
->o_res
.delegation_type
!= 0)
1860 nfs4_opendata_check_deleg(data
, state
);
1862 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1864 refcount_inc(&state
->count
);
1869 static struct inode
*
1870 nfs4_opendata_get_inode(struct nfs4_opendata
*data
)
1872 struct inode
*inode
;
1874 switch (data
->o_arg
.claim
) {
1875 case NFS4_OPEN_CLAIM_NULL
:
1876 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1877 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1878 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1879 return ERR_PTR(-EAGAIN
);
1880 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
,
1881 &data
->f_attr
, data
->f_label
);
1884 inode
= d_inode(data
->dentry
);
1886 nfs_refresh_inode(inode
, &data
->f_attr
);
1891 static struct nfs4_state
*
1892 nfs4_opendata_find_nfs4_state(struct nfs4_opendata
*data
)
1894 struct nfs4_state
*state
;
1895 struct inode
*inode
;
1897 inode
= nfs4_opendata_get_inode(data
);
1899 return ERR_CAST(inode
);
1900 if (data
->state
!= NULL
&& data
->state
->inode
== inode
) {
1901 state
= data
->state
;
1902 refcount_inc(&state
->count
);
1904 state
= nfs4_get_open_state(inode
, data
->owner
);
1907 state
= ERR_PTR(-ENOMEM
);
1911 static struct nfs4_state
*
1912 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1914 struct nfs4_state
*state
;
1916 if (!data
->rpc_done
) {
1917 state
= nfs4_try_open_cached(data
);
1918 trace_nfs4_cached_open(data
->state
);
1922 state
= nfs4_opendata_find_nfs4_state(data
);
1926 if (data
->o_res
.delegation_type
!= 0)
1927 nfs4_opendata_check_deleg(data
, state
);
1928 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1931 nfs_release_seqid(data
->o_arg
.seqid
);
1935 static struct nfs4_state
*
1936 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1938 struct nfs4_state
*ret
;
1940 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1941 ret
=_nfs4_opendata_reclaim_to_nfs4_state(data
);
1943 ret
= _nfs4_opendata_to_nfs4_state(data
);
1944 nfs4_sequence_free_slot(&data
->o_res
.seq_res
);
1948 static struct nfs_open_context
*
1949 nfs4_state_find_open_context_mode(struct nfs4_state
*state
, fmode_t mode
)
1951 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1952 struct nfs_open_context
*ctx
;
1955 list_for_each_entry_rcu(ctx
, &nfsi
->open_files
, list
) {
1956 if (ctx
->state
!= state
)
1958 if ((ctx
->mode
& mode
) != mode
)
1960 if (!get_nfs_open_context(ctx
))
1966 return ERR_PTR(-ENOENT
);
1969 static struct nfs_open_context
*
1970 nfs4_state_find_open_context(struct nfs4_state
*state
)
1972 struct nfs_open_context
*ctx
;
1974 ctx
= nfs4_state_find_open_context_mode(state
, FMODE_READ
|FMODE_WRITE
);
1977 ctx
= nfs4_state_find_open_context_mode(state
, FMODE_WRITE
);
1980 return nfs4_state_find_open_context_mode(state
, FMODE_READ
);
1983 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1984 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1986 struct nfs4_opendata
*opendata
;
1988 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1989 NULL
, claim
, GFP_NOFS
);
1990 if (opendata
== NULL
)
1991 return ERR_PTR(-ENOMEM
);
1992 opendata
->state
= state
;
1993 refcount_inc(&state
->count
);
1997 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
,
2000 struct nfs4_state
*newstate
;
2003 if (!nfs4_mode_match_open_stateid(opendata
->state
, fmode
))
2005 opendata
->o_arg
.open_flags
= 0;
2006 opendata
->o_arg
.fmode
= fmode
;
2007 opendata
->o_arg
.share_access
= nfs4_map_atomic_open_share(
2008 NFS_SB(opendata
->dentry
->d_sb
),
2010 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
2011 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
2012 nfs4_init_opendata_res(opendata
);
2013 ret
= _nfs4_recover_proc_open(opendata
);
2016 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
2017 if (IS_ERR(newstate
))
2018 return PTR_ERR(newstate
);
2019 if (newstate
!= opendata
->state
)
2021 nfs4_close_state(newstate
, fmode
);
2025 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
2029 /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */
2030 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2031 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2032 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2033 /* memory barrier prior to reading state->n_* */
2034 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2035 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2037 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
);
2040 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
);
2043 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
);
2047 * We may have performed cached opens for all three recoveries.
2048 * Check if we need to update the current stateid.
2050 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
2051 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
2052 write_seqlock(&state
->seqlock
);
2053 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
2054 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
2055 write_sequnlock(&state
->seqlock
);
2062 * reclaim state on the server after a reboot.
2064 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2066 struct nfs_delegation
*delegation
;
2067 struct nfs4_opendata
*opendata
;
2068 fmode_t delegation_type
= 0;
2071 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2072 NFS4_OPEN_CLAIM_PREVIOUS
);
2073 if (IS_ERR(opendata
))
2074 return PTR_ERR(opendata
);
2076 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2077 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
2078 delegation_type
= delegation
->type
;
2080 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
2081 status
= nfs4_open_recover(opendata
, state
);
2082 nfs4_opendata_put(opendata
);
2086 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2088 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2089 struct nfs4_exception exception
= { };
2092 err
= _nfs4_do_open_reclaim(ctx
, state
);
2093 trace_nfs4_open_reclaim(ctx
, 0, err
);
2094 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2096 if (err
!= -NFS4ERR_DELAY
)
2098 nfs4_handle_exception(server
, err
, &exception
);
2099 } while (exception
.retry
);
2103 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2105 struct nfs_open_context
*ctx
;
2108 ctx
= nfs4_state_find_open_context(state
);
2111 ret
= nfs4_do_open_reclaim(ctx
, state
);
2112 put_nfs_open_context(ctx
);
2116 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, struct file_lock
*fl
, int err
)
2120 printk(KERN_ERR
"NFS: %s: unhandled error "
2121 "%d.\n", __func__
, err
);
2127 case -NFS4ERR_BADSESSION
:
2128 case -NFS4ERR_BADSLOT
:
2129 case -NFS4ERR_BAD_HIGH_SLOT
:
2130 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
2131 case -NFS4ERR_DEADSESSION
:
2132 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2133 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
2135 case -NFS4ERR_STALE_CLIENTID
:
2136 case -NFS4ERR_STALE_STATEID
:
2137 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2138 /* Don't recall a delegation if it was lost */
2139 nfs4_schedule_lease_recovery(server
->nfs_client
);
2141 case -NFS4ERR_MOVED
:
2142 nfs4_schedule_migration_recovery(server
);
2144 case -NFS4ERR_LEASE_MOVED
:
2145 nfs4_schedule_lease_moved_recovery(server
->nfs_client
);
2147 case -NFS4ERR_DELEG_REVOKED
:
2148 case -NFS4ERR_ADMIN_REVOKED
:
2149 case -NFS4ERR_EXPIRED
:
2150 case -NFS4ERR_BAD_STATEID
:
2151 case -NFS4ERR_OPENMODE
:
2152 nfs_inode_find_state_and_recover(state
->inode
,
2154 nfs4_schedule_stateid_recovery(server
, state
);
2156 case -NFS4ERR_DELAY
:
2157 case -NFS4ERR_GRACE
:
2158 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2162 case -NFS4ERR_DENIED
:
2164 struct nfs4_lock_state
*lsp
= fl
->fl_u
.nfs4_fl
.owner
;
2166 set_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
);
2173 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
,
2174 struct nfs4_state
*state
, const nfs4_stateid
*stateid
,
2177 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2178 struct nfs4_opendata
*opendata
;
2181 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2182 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
2183 if (IS_ERR(opendata
))
2184 return PTR_ERR(opendata
);
2185 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
2186 nfs_state_clear_delegation(state
);
2187 switch (type
& (FMODE_READ
|FMODE_WRITE
)) {
2188 case FMODE_READ
|FMODE_WRITE
:
2190 err
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
);
2193 err
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
);
2198 err
= nfs4_open_recover_helper(opendata
, FMODE_READ
);
2200 nfs4_opendata_put(opendata
);
2201 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, NULL
, err
);
2204 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
2206 struct nfs4_opendata
*data
= calldata
;
2208 nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
2209 &data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, task
);
2212 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
2214 struct nfs4_opendata
*data
= calldata
;
2216 nfs40_sequence_done(task
, &data
->c_res
.seq_res
);
2218 data
->rpc_status
= task
->tk_status
;
2219 if (data
->rpc_status
== 0) {
2220 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
2221 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
2222 renew_lease(data
->o_res
.server
, data
->timestamp
);
2223 data
->rpc_done
= true;
2227 static void nfs4_open_confirm_release(void *calldata
)
2229 struct nfs4_opendata
*data
= calldata
;
2230 struct nfs4_state
*state
= NULL
;
2232 /* If this request hasn't been cancelled, do nothing */
2233 if (!data
->cancelled
)
2235 /* In case of error, no cleanup! */
2236 if (!data
->rpc_done
)
2238 state
= nfs4_opendata_to_nfs4_state(data
);
2240 nfs4_close_state(state
, data
->o_arg
.fmode
);
2242 nfs4_opendata_put(data
);
2245 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
2246 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
2247 .rpc_call_done
= nfs4_open_confirm_done
,
2248 .rpc_release
= nfs4_open_confirm_release
,
2252 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
2254 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
2256 struct nfs_server
*server
= NFS_SERVER(d_inode(data
->dir
));
2257 struct rpc_task
*task
;
2258 struct rpc_message msg
= {
2259 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
2260 .rpc_argp
= &data
->c_arg
,
2261 .rpc_resp
= &data
->c_res
,
2262 .rpc_cred
= data
->owner
->so_cred
,
2264 struct rpc_task_setup task_setup_data
= {
2265 .rpc_client
= server
->client
,
2266 .rpc_message
= &msg
,
2267 .callback_ops
= &nfs4_open_confirm_ops
,
2268 .callback_data
= data
,
2269 .workqueue
= nfsiod_workqueue
,
2270 .flags
= RPC_TASK_ASYNC
,
2274 nfs4_init_sequence(&data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, 1,
2276 kref_get(&data
->kref
);
2277 data
->rpc_done
= false;
2278 data
->rpc_status
= 0;
2279 data
->timestamp
= jiffies
;
2280 task
= rpc_run_task(&task_setup_data
);
2282 return PTR_ERR(task
);
2283 status
= rpc_wait_for_completion_task(task
);
2285 data
->cancelled
= true;
2288 status
= data
->rpc_status
;
2293 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
2295 struct nfs4_opendata
*data
= calldata
;
2296 struct nfs4_state_owner
*sp
= data
->owner
;
2297 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
2298 enum open_claim_type4 claim
= data
->o_arg
.claim
;
2300 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
2303 * Check if we still need to send an OPEN call, or if we can use
2304 * a delegation instead.
2306 if (data
->state
!= NULL
) {
2307 struct nfs_delegation
*delegation
;
2309 if (can_open_cached(data
->state
, data
->o_arg
.fmode
,
2310 data
->o_arg
.open_flags
, claim
))
2313 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
2314 if (can_open_delegated(delegation
, data
->o_arg
.fmode
, claim
))
2315 goto unlock_no_action
;
2318 /* Update client id. */
2319 data
->o_arg
.clientid
= clp
->cl_clientid
;
2323 case NFS4_OPEN_CLAIM_PREVIOUS
:
2324 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
2325 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
2326 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
2328 case NFS4_OPEN_CLAIM_FH
:
2329 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
2331 data
->timestamp
= jiffies
;
2332 if (nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
2333 &data
->o_arg
.seq_args
,
2334 &data
->o_res
.seq_res
,
2336 nfs_release_seqid(data
->o_arg
.seqid
);
2338 /* Set the create mode (note dependency on the session type) */
2339 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
2340 if (data
->o_arg
.open_flags
& O_EXCL
) {
2341 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
2342 if (nfs4_has_persistent_session(clp
))
2343 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
2344 else if (clp
->cl_mvops
->minor_version
> 0)
2345 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
2349 trace_nfs4_cached_open(data
->state
);
2352 task
->tk_action
= NULL
;
2354 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
2357 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
2359 struct nfs4_opendata
*data
= calldata
;
2361 data
->rpc_status
= task
->tk_status
;
2363 if (!nfs4_sequence_process(task
, &data
->o_res
.seq_res
))
2366 if (task
->tk_status
== 0) {
2367 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
2368 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
2372 data
->rpc_status
= -ELOOP
;
2375 data
->rpc_status
= -EISDIR
;
2378 data
->rpc_status
= -ENOTDIR
;
2381 renew_lease(data
->o_res
.server
, data
->timestamp
);
2382 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
2383 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
2385 data
->rpc_done
= true;
2388 static void nfs4_open_release(void *calldata
)
2390 struct nfs4_opendata
*data
= calldata
;
2391 struct nfs4_state
*state
= NULL
;
2393 /* If this request hasn't been cancelled, do nothing */
2394 if (!data
->cancelled
)
2396 /* In case of error, no cleanup! */
2397 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
2399 /* In case we need an open_confirm, no cleanup! */
2400 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
2402 state
= nfs4_opendata_to_nfs4_state(data
);
2404 nfs4_close_state(state
, data
->o_arg
.fmode
);
2406 nfs4_opendata_put(data
);
2409 static const struct rpc_call_ops nfs4_open_ops
= {
2410 .rpc_call_prepare
= nfs4_open_prepare
,
2411 .rpc_call_done
= nfs4_open_done
,
2412 .rpc_release
= nfs4_open_release
,
2415 static int nfs4_run_open_task(struct nfs4_opendata
*data
,
2416 struct nfs_open_context
*ctx
)
2418 struct inode
*dir
= d_inode(data
->dir
);
2419 struct nfs_server
*server
= NFS_SERVER(dir
);
2420 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2421 struct nfs_openres
*o_res
= &data
->o_res
;
2422 struct rpc_task
*task
;
2423 struct rpc_message msg
= {
2424 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
2427 .rpc_cred
= data
->owner
->so_cred
,
2429 struct rpc_task_setup task_setup_data
= {
2430 .rpc_client
= server
->client
,
2431 .rpc_message
= &msg
,
2432 .callback_ops
= &nfs4_open_ops
,
2433 .callback_data
= data
,
2434 .workqueue
= nfsiod_workqueue
,
2435 .flags
= RPC_TASK_ASYNC
,
2439 kref_get(&data
->kref
);
2440 data
->rpc_done
= false;
2441 data
->rpc_status
= 0;
2442 data
->cancelled
= false;
2443 data
->is_recover
= false;
2445 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1, 1);
2446 data
->is_recover
= true;
2448 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1, 0);
2449 pnfs_lgopen_prepare(data
, ctx
);
2451 task
= rpc_run_task(&task_setup_data
);
2453 return PTR_ERR(task
);
2454 status
= rpc_wait_for_completion_task(task
);
2456 data
->cancelled
= true;
2459 status
= data
->rpc_status
;
2465 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
2467 struct inode
*dir
= d_inode(data
->dir
);
2468 struct nfs_openres
*o_res
= &data
->o_res
;
2471 status
= nfs4_run_open_task(data
, NULL
);
2472 if (status
!= 0 || !data
->rpc_done
)
2475 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
2477 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
)
2478 status
= _nfs4_proc_open_confirm(data
);
2484 * Additional permission checks in order to distinguish between an
2485 * open for read, and an open for execute. This works around the
2486 * fact that NFSv4 OPEN treats read and execute permissions as being
2488 * Note that in the non-execute case, we want to turn off permission
2489 * checking if we just created a new file (POSIX open() semantics).
2491 static int nfs4_opendata_access(const struct cred
*cred
,
2492 struct nfs4_opendata
*opendata
,
2493 struct nfs4_state
*state
, fmode_t fmode
,
2496 struct nfs_access_entry cache
;
2499 /* access call failed or for some reason the server doesn't
2500 * support any access modes -- defer access call until later */
2501 if (opendata
->o_res
.access_supported
== 0)
2506 * Use openflags to check for exec, because fmode won't
2507 * always have FMODE_EXEC set when file open for exec.
2509 if (openflags
& __FMODE_EXEC
) {
2510 /* ONLY check for exec rights */
2511 if (S_ISDIR(state
->inode
->i_mode
))
2512 mask
= NFS4_ACCESS_LOOKUP
;
2514 mask
= NFS4_ACCESS_EXECUTE
;
2515 } else if ((fmode
& FMODE_READ
) && !opendata
->file_created
)
2516 mask
= NFS4_ACCESS_READ
;
2519 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
2520 nfs_access_add_cache(state
->inode
, &cache
);
2522 flags
= NFS4_ACCESS_READ
| NFS4_ACCESS_EXECUTE
| NFS4_ACCESS_LOOKUP
;
2523 if ((mask
& ~cache
.mask
& flags
) == 0)
2530 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
2532 static int _nfs4_proc_open(struct nfs4_opendata
*data
,
2533 struct nfs_open_context
*ctx
)
2535 struct inode
*dir
= d_inode(data
->dir
);
2536 struct nfs_server
*server
= NFS_SERVER(dir
);
2537 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2538 struct nfs_openres
*o_res
= &data
->o_res
;
2541 status
= nfs4_run_open_task(data
, ctx
);
2542 if (!data
->rpc_done
)
2545 if (status
== -NFS4ERR_BADNAME
&&
2546 !(o_arg
->open_flags
& O_CREAT
))
2551 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
2553 if (o_arg
->open_flags
& O_CREAT
) {
2554 if (o_arg
->open_flags
& O_EXCL
)
2555 data
->file_created
= true;
2556 else if (o_res
->cinfo
.before
!= o_res
->cinfo
.after
)
2557 data
->file_created
= true;
2558 if (data
->file_created
||
2559 inode_peek_iversion_raw(dir
) != o_res
->cinfo
.after
)
2560 update_changeattr(dir
, &o_res
->cinfo
,
2561 o_res
->f_attr
->time_start
, 0);
2563 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
2564 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
2565 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
2566 status
= _nfs4_proc_open_confirm(data
);
2570 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
)) {
2571 nfs4_sequence_free_slot(&o_res
->seq_res
);
2572 nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
,
2573 o_res
->f_label
, NULL
);
2580 * reclaim state on the server after a network partition.
2581 * Assumes caller holds the appropriate lock
2583 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2585 struct nfs4_opendata
*opendata
;
2588 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2589 NFS4_OPEN_CLAIM_FH
);
2590 if (IS_ERR(opendata
))
2591 return PTR_ERR(opendata
);
2592 ret
= nfs4_open_recover(opendata
, state
);
2594 d_drop(ctx
->dentry
);
2595 nfs4_opendata_put(opendata
);
2599 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2601 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2602 struct nfs4_exception exception
= { };
2606 err
= _nfs4_open_expired(ctx
, state
);
2607 trace_nfs4_open_expired(ctx
, 0, err
);
2608 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2613 case -NFS4ERR_GRACE
:
2614 case -NFS4ERR_DELAY
:
2615 nfs4_handle_exception(server
, err
, &exception
);
2618 } while (exception
.retry
);
2623 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2625 struct nfs_open_context
*ctx
;
2628 ctx
= nfs4_state_find_open_context(state
);
2631 ret
= nfs4_do_open_expired(ctx
, state
);
2632 put_nfs_open_context(ctx
);
2636 static void nfs_finish_clear_delegation_stateid(struct nfs4_state
*state
,
2637 const nfs4_stateid
*stateid
)
2639 nfs_remove_bad_delegation(state
->inode
, stateid
);
2640 nfs_state_clear_delegation(state
);
2643 static void nfs40_clear_delegation_stateid(struct nfs4_state
*state
)
2645 if (rcu_access_pointer(NFS_I(state
->inode
)->delegation
) != NULL
)
2646 nfs_finish_clear_delegation_stateid(state
, NULL
);
2649 static int nfs40_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2651 /* NFSv4.0 doesn't allow for delegation recovery on open expire */
2652 nfs40_clear_delegation_stateid(state
);
2653 return nfs4_open_expired(sp
, state
);
2656 static int nfs40_test_and_free_expired_stateid(struct nfs_server
*server
,
2657 nfs4_stateid
*stateid
,
2658 const struct cred
*cred
)
2660 return -NFS4ERR_BAD_STATEID
;
2663 #if defined(CONFIG_NFS_V4_1)
2664 static int nfs41_test_and_free_expired_stateid(struct nfs_server
*server
,
2665 nfs4_stateid
*stateid
,
2666 const struct cred
*cred
)
2670 switch (stateid
->type
) {
2673 case NFS4_INVALID_STATEID_TYPE
:
2674 case NFS4_SPECIAL_STATEID_TYPE
:
2675 return -NFS4ERR_BAD_STATEID
;
2676 case NFS4_REVOKED_STATEID_TYPE
:
2680 status
= nfs41_test_stateid(server
, stateid
, cred
);
2682 case -NFS4ERR_EXPIRED
:
2683 case -NFS4ERR_ADMIN_REVOKED
:
2684 case -NFS4ERR_DELEG_REVOKED
:
2690 /* Ack the revoked state to the server */
2691 nfs41_free_stateid(server
, stateid
, cred
, true);
2692 return -NFS4ERR_EXPIRED
;
2695 static void nfs41_check_delegation_stateid(struct nfs4_state
*state
)
2697 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2698 nfs4_stateid stateid
;
2699 struct nfs_delegation
*delegation
;
2700 const struct cred
*cred
= NULL
;
2703 /* Get the delegation credential for use by test/free_stateid */
2705 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2706 if (delegation
== NULL
) {
2708 nfs_state_clear_delegation(state
);
2712 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
2713 if (test_bit(NFS_DELEGATION_REVOKED
, &delegation
->flags
)) {
2715 nfs_state_clear_delegation(state
);
2719 if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED
,
2720 &delegation
->flags
)) {
2725 if (delegation
->cred
)
2726 cred
= get_cred(delegation
->cred
);
2728 status
= nfs41_test_and_free_expired_stateid(server
, &stateid
, cred
);
2729 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
2730 if (status
== -NFS4ERR_EXPIRED
|| status
== -NFS4ERR_BAD_STATEID
)
2731 nfs_finish_clear_delegation_stateid(state
, &stateid
);
2733 if (delegation
->cred
)
2738 * nfs41_check_expired_locks - possibly free a lock stateid
2740 * @state: NFSv4 state for an inode
2742 * Returns NFS_OK if recovery for this stateid is now finished.
2743 * Otherwise a negative NFS4ERR value is returned.
2745 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
2747 int status
, ret
= NFS_OK
;
2748 struct nfs4_lock_state
*lsp
, *prev
= NULL
;
2749 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2751 if (!test_bit(LK_STATE_IN_USE
, &state
->flags
))
2754 spin_lock(&state
->state_lock
);
2755 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
2756 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
2757 const struct cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
2759 refcount_inc(&lsp
->ls_count
);
2760 spin_unlock(&state
->state_lock
);
2762 nfs4_put_lock_state(prev
);
2765 status
= nfs41_test_and_free_expired_stateid(server
,
2768 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
2769 if (status
== -NFS4ERR_EXPIRED
||
2770 status
== -NFS4ERR_BAD_STATEID
) {
2771 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
2772 lsp
->ls_stateid
.type
= NFS4_INVALID_STATEID_TYPE
;
2773 if (!recover_lost_locks
)
2774 set_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
);
2775 } else if (status
!= NFS_OK
) {
2777 nfs4_put_lock_state(prev
);
2780 spin_lock(&state
->state_lock
);
2783 spin_unlock(&state
->state_lock
);
2784 nfs4_put_lock_state(prev
);
2790 * nfs41_check_open_stateid - possibly free an open stateid
2792 * @state: NFSv4 state for an inode
2794 * Returns NFS_OK if recovery for this stateid is now finished.
2795 * Otherwise a negative NFS4ERR value is returned.
2797 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2799 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2800 nfs4_stateid
*stateid
= &state
->open_stateid
;
2801 const struct cred
*cred
= state
->owner
->so_cred
;
2804 if (test_bit(NFS_OPEN_STATE
, &state
->flags
) == 0) {
2805 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0) {
2806 if (nfs4_have_delegation(state
->inode
, state
->state
))
2808 return -NFS4ERR_OPENMODE
;
2810 return -NFS4ERR_BAD_STATEID
;
2812 status
= nfs41_test_and_free_expired_stateid(server
, stateid
, cred
);
2813 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2814 if (status
== -NFS4ERR_EXPIRED
|| status
== -NFS4ERR_BAD_STATEID
) {
2815 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2816 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2817 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2818 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2819 stateid
->type
= NFS4_INVALID_STATEID_TYPE
;
2822 if (nfs_open_stateid_recover_openmode(state
))
2823 return -NFS4ERR_OPENMODE
;
2827 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2831 nfs41_check_delegation_stateid(state
);
2832 status
= nfs41_check_expired_locks(state
);
2833 if (status
!= NFS_OK
)
2835 status
= nfs41_check_open_stateid(state
);
2836 if (status
!= NFS_OK
)
2837 status
= nfs4_open_expired(sp
, state
);
2843 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2844 * fields corresponding to attributes that were used to store the verifier.
2845 * Make sure we clobber those fields in the later setattr call
2847 static unsigned nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
,
2848 struct iattr
*sattr
, struct nfs4_label
**label
)
2850 const __u32
*bitmask
= opendata
->o_arg
.server
->exclcreat_bitmask
;
2855 for (i
= 0; i
< ARRAY_SIZE(attrset
); i
++) {
2856 attrset
[i
] = opendata
->o_res
.attrset
[i
];
2857 if (opendata
->o_arg
.createmode
== NFS4_CREATE_EXCLUSIVE4_1
)
2858 attrset
[i
] &= ~bitmask
[i
];
2861 ret
= (opendata
->o_arg
.createmode
== NFS4_CREATE_EXCLUSIVE
) ?
2862 sattr
->ia_valid
: 0;
2864 if ((attrset
[1] & (FATTR4_WORD1_TIME_ACCESS
|FATTR4_WORD1_TIME_ACCESS_SET
))) {
2865 if (sattr
->ia_valid
& ATTR_ATIME_SET
)
2866 ret
|= ATTR_ATIME_SET
;
2871 if ((attrset
[1] & (FATTR4_WORD1_TIME_MODIFY
|FATTR4_WORD1_TIME_MODIFY_SET
))) {
2872 if (sattr
->ia_valid
& ATTR_MTIME_SET
)
2873 ret
|= ATTR_MTIME_SET
;
2878 if (!(attrset
[2] & FATTR4_WORD2_SECURITY_LABEL
))
2883 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2886 struct nfs_open_context
*ctx
)
2888 struct nfs4_state_owner
*sp
= opendata
->owner
;
2889 struct nfs_server
*server
= sp
->so_server
;
2890 struct dentry
*dentry
;
2891 struct nfs4_state
*state
;
2895 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2897 ret
= _nfs4_proc_open(opendata
, ctx
);
2901 state
= _nfs4_opendata_to_nfs4_state(opendata
);
2902 ret
= PTR_ERR(state
);
2906 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2907 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2908 if (opendata
->o_res
.rflags
& NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK
)
2909 set_bit(NFS_STATE_MAY_NOTIFY_LOCK
, &state
->flags
);
2911 dentry
= opendata
->dentry
;
2912 if (d_really_is_negative(dentry
)) {
2913 struct dentry
*alias
;
2915 alias
= d_exact_alias(dentry
, state
->inode
);
2917 alias
= d_splice_alias(igrab(state
->inode
), dentry
);
2918 /* d_splice_alias() can't fail here - it's a non-directory */
2921 ctx
->dentry
= dentry
= alias
;
2923 nfs_set_verifier(dentry
,
2924 nfs_save_change_attribute(d_inode(opendata
->dir
)));
2927 /* Parse layoutget results before we check for access */
2928 pnfs_parse_lgopen(state
->inode
, opendata
->lgp
, ctx
);
2930 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2934 if (d_inode(dentry
) == state
->inode
) {
2935 nfs_inode_attach_open_context(ctx
);
2936 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2937 nfs4_schedule_stateid_recovery(server
, state
);
2941 nfs4_sequence_free_slot(&opendata
->o_res
.seq_res
);
2946 * Returns a referenced nfs4_state
2948 static int _nfs4_do_open(struct inode
*dir
,
2949 struct nfs_open_context
*ctx
,
2951 const struct nfs4_open_createattrs
*c
,
2954 struct nfs4_state_owner
*sp
;
2955 struct nfs4_state
*state
= NULL
;
2956 struct nfs_server
*server
= NFS_SERVER(dir
);
2957 struct nfs4_opendata
*opendata
;
2958 struct dentry
*dentry
= ctx
->dentry
;
2959 const struct cred
*cred
= ctx
->cred
;
2960 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2961 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2962 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2963 struct iattr
*sattr
= c
->sattr
;
2964 struct nfs4_label
*label
= c
->label
;
2965 struct nfs4_label
*olabel
= NULL
;
2968 /* Protect against reboot recovery conflicts */
2970 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2972 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2975 status
= nfs4_client_recover_expired_lease(server
->nfs_client
);
2977 goto err_put_state_owner
;
2978 if (d_really_is_positive(dentry
))
2979 nfs4_return_incompatible_delegation(d_inode(dentry
), fmode
);
2981 if (d_really_is_positive(dentry
))
2982 claim
= NFS4_OPEN_CLAIM_FH
;
2983 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
,
2984 c
, claim
, GFP_KERNEL
);
2985 if (opendata
== NULL
)
2986 goto err_put_state_owner
;
2989 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2990 if (IS_ERR(olabel
)) {
2991 status
= PTR_ERR(olabel
);
2992 goto err_opendata_put
;
2996 if (server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2997 if (!opendata
->f_attr
.mdsthreshold
) {
2998 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2999 if (!opendata
->f_attr
.mdsthreshold
)
3000 goto err_free_label
;
3002 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
3004 if (d_really_is_positive(dentry
))
3005 opendata
->state
= nfs4_get_open_state(d_inode(dentry
), sp
);
3007 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
3009 goto err_free_label
;
3012 if ((opendata
->o_arg
.open_flags
& (O_CREAT
|O_EXCL
)) == (O_CREAT
|O_EXCL
) &&
3013 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
3014 unsigned attrs
= nfs4_exclusive_attrset(opendata
, sattr
, &label
);
3016 * send create attributes which was not set by open
3017 * with an extra setattr.
3019 if (attrs
|| label
) {
3020 unsigned ia_old
= sattr
->ia_valid
;
3022 sattr
->ia_valid
= attrs
;
3023 nfs_fattr_init(opendata
->o_res
.f_attr
);
3024 status
= nfs4_do_setattr(state
->inode
, cred
,
3025 opendata
->o_res
.f_attr
, sattr
,
3026 ctx
, label
, olabel
);
3028 nfs_setattr_update_inode(state
->inode
, sattr
,
3029 opendata
->o_res
.f_attr
);
3030 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
3032 sattr
->ia_valid
= ia_old
;
3035 if (opened
&& opendata
->file_created
)
3038 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
)) {
3039 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
3040 opendata
->f_attr
.mdsthreshold
= NULL
;
3043 nfs4_label_free(olabel
);
3045 nfs4_opendata_put(opendata
);
3046 nfs4_put_state_owner(sp
);
3049 nfs4_label_free(olabel
);
3051 nfs4_opendata_put(opendata
);
3052 err_put_state_owner
:
3053 nfs4_put_state_owner(sp
);
3059 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
3060 struct nfs_open_context
*ctx
,
3062 struct iattr
*sattr
,
3063 struct nfs4_label
*label
,
3066 struct nfs_server
*server
= NFS_SERVER(dir
);
3067 struct nfs4_exception exception
= { };
3068 struct nfs4_state
*res
;
3069 struct nfs4_open_createattrs c
= {
3073 [0] = (__u32
)jiffies
,
3074 [1] = (__u32
)current
->pid
,
3080 status
= _nfs4_do_open(dir
, ctx
, flags
, &c
, opened
);
3082 trace_nfs4_open_file(ctx
, flags
, status
);
3085 /* NOTE: BAD_SEQID means the server and client disagree about the
3086 * book-keeping w.r.t. state-changing operations
3087 * (OPEN/CLOSE/LOCK/LOCKU...)
3088 * It is actually a sign of a bug on the client or on the server.
3090 * If we receive a BAD_SEQID error in the particular case of
3091 * doing an OPEN, we assume that nfs_increment_open_seqid() will
3092 * have unhashed the old state_owner for us, and that we can
3093 * therefore safely retry using a new one. We should still warn
3094 * the user though...
3096 if (status
== -NFS4ERR_BAD_SEQID
) {
3097 pr_warn_ratelimited("NFS: v4 server %s "
3098 " returned a bad sequence-id error!\n",
3099 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
3100 exception
.retry
= 1;
3104 * BAD_STATEID on OPEN means that the server cancelled our
3105 * state before it received the OPEN_CONFIRM.
3106 * Recover by retrying the request as per the discussion
3107 * on Page 181 of RFC3530.
3109 if (status
== -NFS4ERR_BAD_STATEID
) {
3110 exception
.retry
= 1;
3113 if (status
== -EAGAIN
) {
3114 /* We must have found a delegation */
3115 exception
.retry
= 1;
3118 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
3120 res
= ERR_PTR(nfs4_handle_exception(server
,
3121 status
, &exception
));
3122 } while (exception
.retry
);
3126 static int _nfs4_do_setattr(struct inode
*inode
,
3127 struct nfs_setattrargs
*arg
,
3128 struct nfs_setattrres
*res
,
3129 const struct cred
*cred
,
3130 struct nfs_open_context
*ctx
)
3132 struct nfs_server
*server
= NFS_SERVER(inode
);
3133 struct rpc_message msg
= {
3134 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
3139 const struct cred
*delegation_cred
= NULL
;
3140 unsigned long timestamp
= jiffies
;
3144 nfs_fattr_init(res
->fattr
);
3146 /* Servers should only apply open mode checks for file size changes */
3147 truncate
= (arg
->iap
->ia_valid
& ATTR_SIZE
) ? true : false;
3151 if (nfs4_copy_delegation_stateid(inode
, FMODE_WRITE
, &arg
->stateid
, &delegation_cred
)) {
3152 /* Use that stateid */
3153 } else if (ctx
!= NULL
) {
3154 struct nfs_lock_context
*l_ctx
;
3155 if (!nfs4_valid_open_stateid(ctx
->state
))
3157 l_ctx
= nfs_get_lock_context(ctx
);
3159 return PTR_ERR(l_ctx
);
3160 status
= nfs4_select_rw_stateid(ctx
->state
, FMODE_WRITE
, l_ctx
,
3161 &arg
->stateid
, &delegation_cred
);
3162 nfs_put_lock_context(l_ctx
);
3167 nfs4_stateid_copy(&arg
->stateid
, &zero_stateid
);
3169 if (delegation_cred
)
3170 msg
.rpc_cred
= delegation_cred
;
3172 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
->seq_args
, &res
->seq_res
, 1);
3174 put_cred(delegation_cred
);
3175 if (status
== 0 && ctx
!= NULL
)
3176 renew_lease(server
, timestamp
);
3177 trace_nfs4_setattr(inode
, &arg
->stateid
, status
);
3181 static int nfs4_do_setattr(struct inode
*inode
, const struct cred
*cred
,
3182 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
3183 struct nfs_open_context
*ctx
, struct nfs4_label
*ilabel
,
3184 struct nfs4_label
*olabel
)
3186 struct nfs_server
*server
= NFS_SERVER(inode
);
3187 __u32 bitmask
[NFS4_BITMASK_SZ
];
3188 struct nfs4_state
*state
= ctx
? ctx
->state
: NULL
;
3189 struct nfs_setattrargs arg
= {
3190 .fh
= NFS_FH(inode
),
3196 struct nfs_setattrres res
= {
3201 struct nfs4_exception exception
= {
3204 .stateid
= &arg
.stateid
,
3209 nfs4_bitmap_copy_adjust_setattr(bitmask
,
3210 nfs4_bitmask(server
, olabel
),
3213 err
= _nfs4_do_setattr(inode
, &arg
, &res
, cred
, ctx
);
3215 case -NFS4ERR_OPENMODE
:
3216 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
3217 pr_warn_once("NFSv4: server %s is incorrectly "
3218 "applying open mode checks to "
3219 "a SETATTR that is not "
3220 "changing file size.\n",
3221 server
->nfs_client
->cl_hostname
);
3223 if (state
&& !(state
->state
& FMODE_WRITE
)) {
3225 if (sattr
->ia_valid
& ATTR_OPEN
)
3230 err
= nfs4_handle_exception(server
, err
, &exception
);
3231 } while (exception
.retry
);
3237 nfs4_wait_on_layoutreturn(struct inode
*inode
, struct rpc_task
*task
)
3239 if (inode
== NULL
|| !nfs_have_layout(inode
))
3242 return pnfs_wait_on_layoutreturn(inode
, task
);
3245 struct nfs4_closedata
{
3246 struct inode
*inode
;
3247 struct nfs4_state
*state
;
3248 struct nfs_closeargs arg
;
3249 struct nfs_closeres res
;
3251 struct nfs4_layoutreturn_args arg
;
3252 struct nfs4_layoutreturn_res res
;
3253 struct nfs4_xdr_opaque_data ld_private
;
3257 struct nfs_fattr fattr
;
3258 unsigned long timestamp
;
3261 static void nfs4_free_closedata(void *data
)
3263 struct nfs4_closedata
*calldata
= data
;
3264 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
3265 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
3267 if (calldata
->lr
.roc
)
3268 pnfs_roc_release(&calldata
->lr
.arg
, &calldata
->lr
.res
,
3269 calldata
->res
.lr_ret
);
3270 nfs4_put_open_state(calldata
->state
);
3271 nfs_free_seqid(calldata
->arg
.seqid
);
3272 nfs4_put_state_owner(sp
);
3273 nfs_sb_deactive(sb
);
3277 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
3279 struct nfs4_closedata
*calldata
= data
;
3280 struct nfs4_state
*state
= calldata
->state
;
3281 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
3282 nfs4_stateid
*res_stateid
= NULL
;
3283 struct nfs4_exception exception
= {
3285 .inode
= calldata
->inode
,
3286 .stateid
= &calldata
->arg
.stateid
,
3289 dprintk("%s: begin!\n", __func__
);
3290 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
3292 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
3294 /* Handle Layoutreturn errors */
3295 if (calldata
->arg
.lr_args
&& task
->tk_status
!= 0) {
3296 switch (calldata
->res
.lr_ret
) {
3298 calldata
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
3301 calldata
->arg
.lr_args
= NULL
;
3302 calldata
->res
.lr_res
= NULL
;
3304 case -NFS4ERR_OLD_STATEID
:
3305 if (nfs4_layoutreturn_refresh_stateid(&calldata
->arg
.lr_args
->stateid
,
3306 &calldata
->arg
.lr_args
->range
,
3310 case -NFS4ERR_ADMIN_REVOKED
:
3311 case -NFS4ERR_DELEG_REVOKED
:
3312 case -NFS4ERR_EXPIRED
:
3313 case -NFS4ERR_BAD_STATEID
:
3314 case -NFS4ERR_UNKNOWN_LAYOUTTYPE
:
3315 case -NFS4ERR_WRONG_CRED
:
3316 calldata
->arg
.lr_args
= NULL
;
3317 calldata
->res
.lr_res
= NULL
;
3322 /* hmm. we are done with the inode, and in the process of freeing
3323 * the state_owner. we keep this around to process errors
3325 switch (task
->tk_status
) {
3327 res_stateid
= &calldata
->res
.stateid
;
3328 renew_lease(server
, calldata
->timestamp
);
3330 case -NFS4ERR_ACCESS
:
3331 if (calldata
->arg
.bitmask
!= NULL
) {
3332 calldata
->arg
.bitmask
= NULL
;
3333 calldata
->res
.fattr
= NULL
;
3338 case -NFS4ERR_OLD_STATEID
:
3339 /* Did we race with OPEN? */
3340 if (nfs4_refresh_open_stateid(&calldata
->arg
.stateid
,
3344 case -NFS4ERR_ADMIN_REVOKED
:
3345 case -NFS4ERR_STALE_STATEID
:
3346 case -NFS4ERR_EXPIRED
:
3347 nfs4_free_revoked_stateid(server
,
3348 &calldata
->arg
.stateid
,
3349 task
->tk_msg
.rpc_cred
);
3351 case -NFS4ERR_BAD_STATEID
:
3354 task
->tk_status
= nfs4_async_handle_exception(task
,
3355 server
, task
->tk_status
, &exception
);
3356 if (exception
.retry
)
3359 nfs_clear_open_stateid(state
, &calldata
->arg
.stateid
,
3360 res_stateid
, calldata
->arg
.fmode
);
3362 task
->tk_status
= 0;
3363 nfs_release_seqid(calldata
->arg
.seqid
);
3364 nfs_refresh_inode(calldata
->inode
, &calldata
->fattr
);
3365 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
3368 calldata
->res
.lr_ret
= 0;
3370 task
->tk_status
= 0;
3371 rpc_restart_call_prepare(task
);
3375 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
3377 struct nfs4_closedata
*calldata
= data
;
3378 struct nfs4_state
*state
= calldata
->state
;
3379 struct inode
*inode
= calldata
->inode
;
3380 struct pnfs_layout_hdr
*lo
;
3381 bool is_rdonly
, is_wronly
, is_rdwr
;
3384 dprintk("%s: begin!\n", __func__
);
3385 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3388 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
3389 spin_lock(&state
->owner
->so_lock
);
3390 is_rdwr
= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
3391 is_rdonly
= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
3392 is_wronly
= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
3393 /* Calculate the change in open mode */
3394 calldata
->arg
.fmode
= 0;
3395 if (state
->n_rdwr
== 0) {
3396 if (state
->n_rdonly
== 0)
3397 call_close
|= is_rdonly
;
3399 calldata
->arg
.fmode
|= FMODE_READ
;
3400 if (state
->n_wronly
== 0)
3401 call_close
|= is_wronly
;
3403 calldata
->arg
.fmode
|= FMODE_WRITE
;
3404 if (calldata
->arg
.fmode
!= (FMODE_READ
|FMODE_WRITE
))
3405 call_close
|= is_rdwr
;
3407 calldata
->arg
.fmode
|= FMODE_READ
|FMODE_WRITE
;
3409 if (!nfs4_valid_open_stateid(state
) ||
3410 !nfs4_refresh_open_stateid(&calldata
->arg
.stateid
, state
))
3412 spin_unlock(&state
->owner
->so_lock
);
3415 /* Note: exit _without_ calling nfs4_close_done */
3419 if (!calldata
->lr
.roc
&& nfs4_wait_on_layoutreturn(inode
, task
)) {
3420 nfs_release_seqid(calldata
->arg
.seqid
);
3424 lo
= calldata
->arg
.lr_args
? calldata
->arg
.lr_args
->layout
: NULL
;
3425 if (lo
&& !pnfs_layout_is_valid(lo
)) {
3426 calldata
->arg
.lr_args
= NULL
;
3427 calldata
->res
.lr_res
= NULL
;
3430 if (calldata
->arg
.fmode
== 0)
3431 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
3433 if (calldata
->arg
.fmode
== 0 || calldata
->arg
.fmode
== FMODE_READ
) {
3434 /* Close-to-open cache consistency revalidation */
3435 if (!nfs4_have_delegation(inode
, FMODE_READ
))
3436 calldata
->arg
.bitmask
= NFS_SERVER(inode
)->cache_consistency_bitmask
;
3438 calldata
->arg
.bitmask
= NULL
;
3441 calldata
->arg
.share_access
=
3442 nfs4_map_atomic_open_share(NFS_SERVER(inode
),
3443 calldata
->arg
.fmode
, 0);
3445 if (calldata
->res
.fattr
== NULL
)
3446 calldata
->arg
.bitmask
= NULL
;
3447 else if (calldata
->arg
.bitmask
== NULL
)
3448 calldata
->res
.fattr
= NULL
;
3449 calldata
->timestamp
= jiffies
;
3450 if (nfs4_setup_sequence(NFS_SERVER(inode
)->nfs_client
,
3451 &calldata
->arg
.seq_args
,
3452 &calldata
->res
.seq_res
,
3454 nfs_release_seqid(calldata
->arg
.seqid
);
3455 dprintk("%s: done!\n", __func__
);
3458 task
->tk_action
= NULL
;
3460 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
3463 static const struct rpc_call_ops nfs4_close_ops
= {
3464 .rpc_call_prepare
= nfs4_close_prepare
,
3465 .rpc_call_done
= nfs4_close_done
,
3466 .rpc_release
= nfs4_free_closedata
,
3470 * It is possible for data to be read/written from a mem-mapped file
3471 * after the sys_close call (which hits the vfs layer as a flush).
3472 * This means that we can't safely call nfsv4 close on a file until
3473 * the inode is cleared. This in turn means that we are not good
3474 * NFSv4 citizens - we do not indicate to the server to update the file's
3475 * share state even when we are done with one of the three share
3476 * stateid's in the inode.
3478 * NOTE: Caller must be holding the sp->so_owner semaphore!
3480 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
3482 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3483 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
3484 struct nfs4_closedata
*calldata
;
3485 struct nfs4_state_owner
*sp
= state
->owner
;
3486 struct rpc_task
*task
;
3487 struct rpc_message msg
= {
3488 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
3489 .rpc_cred
= state
->owner
->so_cred
,
3491 struct rpc_task_setup task_setup_data
= {
3492 .rpc_client
= server
->client
,
3493 .rpc_message
= &msg
,
3494 .callback_ops
= &nfs4_close_ops
,
3495 .workqueue
= nfsiod_workqueue
,
3496 .flags
= RPC_TASK_ASYNC
,
3498 int status
= -ENOMEM
;
3500 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_CLEANUP
,
3501 &task_setup_data
.rpc_client
, &msg
);
3503 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
3504 if (calldata
== NULL
)
3506 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1, 0);
3507 calldata
->inode
= state
->inode
;
3508 calldata
->state
= state
;
3509 calldata
->arg
.fh
= NFS_FH(state
->inode
);
3510 if (!nfs4_copy_open_stateid(&calldata
->arg
.stateid
, state
))
3511 goto out_free_calldata
;
3512 /* Serialization for the sequence id */
3513 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
3514 calldata
->arg
.seqid
= alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
3515 if (IS_ERR(calldata
->arg
.seqid
))
3516 goto out_free_calldata
;
3517 nfs_fattr_init(&calldata
->fattr
);
3518 calldata
->arg
.fmode
= 0;
3519 calldata
->lr
.arg
.ld_private
= &calldata
->lr
.ld_private
;
3520 calldata
->res
.fattr
= &calldata
->fattr
;
3521 calldata
->res
.seqid
= calldata
->arg
.seqid
;
3522 calldata
->res
.server
= server
;
3523 calldata
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
3524 calldata
->lr
.roc
= pnfs_roc(state
->inode
,
3525 &calldata
->lr
.arg
, &calldata
->lr
.res
, msg
.rpc_cred
);
3526 if (calldata
->lr
.roc
) {
3527 calldata
->arg
.lr_args
= &calldata
->lr
.arg
;
3528 calldata
->res
.lr_res
= &calldata
->lr
.res
;
3530 nfs_sb_active(calldata
->inode
->i_sb
);
3532 msg
.rpc_argp
= &calldata
->arg
;
3533 msg
.rpc_resp
= &calldata
->res
;
3534 task_setup_data
.callback_data
= calldata
;
3535 task
= rpc_run_task(&task_setup_data
);
3537 return PTR_ERR(task
);
3540 status
= rpc_wait_for_completion_task(task
);
3546 nfs4_put_open_state(state
);
3547 nfs4_put_state_owner(sp
);
3551 static struct inode
*
3552 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
,
3553 int open_flags
, struct iattr
*attr
, int *opened
)
3555 struct nfs4_state
*state
;
3556 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
3558 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
3560 /* Protect against concurrent sillydeletes */
3561 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
, opened
);
3563 nfs4_label_release_security(label
);
3566 return ERR_CAST(state
);
3567 return state
->inode
;
3570 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
3572 if (ctx
->state
== NULL
)
3575 nfs4_close_sync(ctx
->state
, ctx
->mode
);
3577 nfs4_close_state(ctx
->state
, ctx
->mode
);
3580 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
3581 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
3582 #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL)
3584 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
3586 u32 bitmask
[3] = {}, minorversion
= server
->nfs_client
->cl_minorversion
;
3587 struct nfs4_server_caps_arg args
= {
3591 struct nfs4_server_caps_res res
= {};
3592 struct rpc_message msg
= {
3593 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
3600 bitmask
[0] = FATTR4_WORD0_SUPPORTED_ATTRS
|
3601 FATTR4_WORD0_FH_EXPIRE_TYPE
|
3602 FATTR4_WORD0_LINK_SUPPORT
|
3603 FATTR4_WORD0_SYMLINK_SUPPORT
|
3604 FATTR4_WORD0_ACLSUPPORT
;
3606 bitmask
[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT
;
3608 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3610 /* Sanity check the server answers */
3611 switch (minorversion
) {
3613 res
.attr_bitmask
[1] &= FATTR4_WORD1_NFS40_MASK
;
3614 res
.attr_bitmask
[2] = 0;
3617 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS41_MASK
;
3620 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS42_MASK
;
3622 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
3623 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
3624 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
3625 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
3626 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
3627 NFS_CAP_CTIME
|NFS_CAP_MTIME
|
3628 NFS_CAP_SECURITY_LABEL
);
3629 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
&&
3630 res
.acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3631 server
->caps
|= NFS_CAP_ACLS
;
3632 if (res
.has_links
!= 0)
3633 server
->caps
|= NFS_CAP_HARDLINKS
;
3634 if (res
.has_symlinks
!= 0)
3635 server
->caps
|= NFS_CAP_SYMLINKS
;
3636 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
3637 server
->caps
|= NFS_CAP_FILEID
;
3638 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
3639 server
->caps
|= NFS_CAP_MODE
;
3640 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
3641 server
->caps
|= NFS_CAP_NLINK
;
3642 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
3643 server
->caps
|= NFS_CAP_OWNER
;
3644 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
3645 server
->caps
|= NFS_CAP_OWNER_GROUP
;
3646 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
3647 server
->caps
|= NFS_CAP_ATIME
;
3648 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
3649 server
->caps
|= NFS_CAP_CTIME
;
3650 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
3651 server
->caps
|= NFS_CAP_MTIME
;
3652 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
3653 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
3654 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
3656 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
3657 sizeof(server
->attr_bitmask
));
3658 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
3660 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
3661 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
3662 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
3663 server
->cache_consistency_bitmask
[2] = 0;
3665 /* Avoid a regression due to buggy server */
3666 for (i
= 0; i
< ARRAY_SIZE(res
.exclcreat_bitmask
); i
++)
3667 res
.exclcreat_bitmask
[i
] &= res
.attr_bitmask
[i
];
3668 memcpy(server
->exclcreat_bitmask
, res
.exclcreat_bitmask
,
3669 sizeof(server
->exclcreat_bitmask
));
3671 server
->acl_bitmask
= res
.acl_bitmask
;
3672 server
->fh_expire_type
= res
.fh_expire_type
;
3678 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
3680 struct nfs4_exception exception
= { };
3683 err
= nfs4_handle_exception(server
,
3684 _nfs4_server_capabilities(server
, fhandle
),
3686 } while (exception
.retry
);
3690 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3691 struct nfs_fsinfo
*info
)
3694 struct nfs4_lookup_root_arg args
= {
3697 struct nfs4_lookup_res res
= {
3699 .fattr
= info
->fattr
,
3702 struct rpc_message msg
= {
3703 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
3708 bitmask
[0] = nfs4_fattr_bitmap
[0];
3709 bitmask
[1] = nfs4_fattr_bitmap
[1];
3711 * Process the label in the upcoming getfattr
3713 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
3715 nfs_fattr_init(info
->fattr
);
3716 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3719 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3720 struct nfs_fsinfo
*info
)
3722 struct nfs4_exception exception
= { };
3725 err
= _nfs4_lookup_root(server
, fhandle
, info
);
3726 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
3729 case -NFS4ERR_WRONGSEC
:
3732 err
= nfs4_handle_exception(server
, err
, &exception
);
3734 } while (exception
.retry
);
3739 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3740 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
3742 struct rpc_auth_create_args auth_args
= {
3743 .pseudoflavor
= flavor
,
3745 struct rpc_auth
*auth
;
3747 auth
= rpcauth_create(&auth_args
, server
->client
);
3750 return nfs4_lookup_root(server
, fhandle
, info
);
3754 * Retry pseudoroot lookup with various security flavors. We do this when:
3756 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
3757 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
3759 * Returns zero on success, or a negative NFS4ERR value, or a
3760 * negative errno value.
3762 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3763 struct nfs_fsinfo
*info
)
3765 /* Per 3530bis 15.33.5 */
3766 static const rpc_authflavor_t flav_array
[] = {
3770 RPC_AUTH_UNIX
, /* courtesy */
3773 int status
= -EPERM
;
3776 if (server
->auth_info
.flavor_len
> 0) {
3777 /* try each flavor specified by user */
3778 for (i
= 0; i
< server
->auth_info
.flavor_len
; i
++) {
3779 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3780 server
->auth_info
.flavors
[i
]);
3781 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3786 /* no flavors specified by user, try default list */
3787 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
3788 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3790 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3797 * -EACCES could mean that the user doesn't have correct permissions
3798 * to access the mount. It could also mean that we tried to mount
3799 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
3800 * existing mount programs don't handle -EACCES very well so it should
3801 * be mapped to -EPERM instead.
3803 if (status
== -EACCES
)
3809 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
3810 * @server: initialized nfs_server handle
3811 * @fhandle: we fill in the pseudo-fs root file handle
3812 * @info: we fill in an FSINFO struct
3813 * @auth_probe: probe the auth flavours
3815 * Returns zero on success, or a negative errno.
3817 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3818 struct nfs_fsinfo
*info
,
3824 status
= nfs4_lookup_root(server
, fhandle
, info
);
3826 if (auth_probe
|| status
== NFS4ERR_WRONGSEC
)
3827 status
= server
->nfs_client
->cl_mvops
->find_root_sec(server
,
3831 status
= nfs4_server_capabilities(server
, fhandle
);
3833 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
3835 return nfs4_map_errors(status
);
3838 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
3839 struct nfs_fsinfo
*info
)
3842 struct nfs_fattr
*fattr
= info
->fattr
;
3843 struct nfs4_label
*label
= NULL
;
3845 error
= nfs4_server_capabilities(server
, mntfh
);
3847 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
3851 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3853 return PTR_ERR(label
);
3855 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
, NULL
);
3857 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
3858 goto err_free_label
;
3861 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
3862 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
3863 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
3866 nfs4_label_free(label
);
3872 * Get locations and (maybe) other attributes of a referral.
3873 * Note that we'll actually follow the referral later when
3874 * we detect fsid mismatch in inode revalidation
3876 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
3877 const struct qstr
*name
, struct nfs_fattr
*fattr
,
3878 struct nfs_fh
*fhandle
)
3880 int status
= -ENOMEM
;
3881 struct page
*page
= NULL
;
3882 struct nfs4_fs_locations
*locations
= NULL
;
3884 page
= alloc_page(GFP_KERNEL
);
3887 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
3888 if (locations
== NULL
)
3891 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
3896 * If the fsid didn't change, this is a migration event, not a
3897 * referral. Cause us to drop into the exception handler, which
3898 * will kick off migration recovery.
3900 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
3901 dprintk("%s: server did not return a different fsid for"
3902 " a referral at %s\n", __func__
, name
->name
);
3903 status
= -NFS4ERR_MOVED
;
3906 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3907 nfs_fixup_referral_attributes(&locations
->fattr
);
3909 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3910 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
3911 memset(fhandle
, 0, sizeof(struct nfs_fh
));
3919 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3920 struct nfs_fattr
*fattr
, struct nfs4_label
*label
,
3921 struct inode
*inode
)
3923 __u32 bitmask
[NFS4_BITMASK_SZ
];
3924 struct nfs4_getattr_arg args
= {
3928 struct nfs4_getattr_res res
= {
3933 struct rpc_message msg
= {
3934 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
3939 nfs4_bitmap_copy_adjust(bitmask
, nfs4_bitmask(server
, label
), inode
);
3941 nfs_fattr_init(fattr
);
3942 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3945 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3946 struct nfs_fattr
*fattr
, struct nfs4_label
*label
,
3947 struct inode
*inode
)
3949 struct nfs4_exception exception
= { };
3952 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
, inode
);
3953 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
3954 err
= nfs4_handle_exception(server
, err
,
3956 } while (exception
.retry
);
3961 * The file is not closed if it is opened due to the a request to change
3962 * the size of the file. The open call will not be needed once the
3963 * VFS layer lookup-intents are implemented.
3965 * Close is called when the inode is destroyed.
3966 * If we haven't opened the file for O_WRONLY, we
3967 * need to in the size_change case to obtain a stateid.
3970 * Because OPEN is always done by name in nfsv4, it is
3971 * possible that we opened a different file by the same
3972 * name. We can recognize this race condition, but we
3973 * can't do anything about it besides returning an error.
3975 * This will be fixed with VFS changes (lookup-intent).
3978 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
3979 struct iattr
*sattr
)
3981 struct inode
*inode
= d_inode(dentry
);
3982 const struct cred
*cred
= NULL
;
3983 struct nfs_open_context
*ctx
= NULL
;
3984 struct nfs4_label
*label
= NULL
;
3987 if (pnfs_ld_layoutret_on_setattr(inode
) &&
3988 sattr
->ia_valid
& ATTR_SIZE
&&
3989 sattr
->ia_size
< i_size_read(inode
))
3990 pnfs_commit_and_return_layout(inode
);
3992 nfs_fattr_init(fattr
);
3994 /* Deal with open(O_TRUNC) */
3995 if (sattr
->ia_valid
& ATTR_OPEN
)
3996 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
3998 /* Optimization: if the end result is no change, don't RPC */
3999 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
4002 /* Search for an existing open(O_WRITE) file */
4003 if (sattr
->ia_valid
& ATTR_FILE
) {
4005 ctx
= nfs_file_open_context(sattr
->ia_file
);
4010 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4012 return PTR_ERR(label
);
4014 /* Return any delegations if we're going to change ACLs */
4015 if ((sattr
->ia_valid
& (ATTR_MODE
|ATTR_UID
|ATTR_GID
)) != 0)
4016 nfs4_inode_make_writeable(inode
);
4018 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, ctx
, NULL
, label
);
4020 nfs_setattr_update_inode(inode
, sattr
, fattr
);
4021 nfs_setsecurity(inode
, fattr
, label
);
4023 nfs4_label_free(label
);
4027 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
4028 const struct qstr
*name
, struct nfs_fh
*fhandle
,
4029 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4031 struct nfs_server
*server
= NFS_SERVER(dir
);
4033 struct nfs4_lookup_arg args
= {
4034 .bitmask
= server
->attr_bitmask
,
4035 .dir_fh
= NFS_FH(dir
),
4038 struct nfs4_lookup_res res
= {
4044 struct rpc_message msg
= {
4045 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
4050 args
.bitmask
= nfs4_bitmask(server
, label
);
4052 nfs_fattr_init(fattr
);
4054 dprintk("NFS call lookup %s\n", name
->name
);
4055 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4056 dprintk("NFS reply lookup: %d\n", status
);
4060 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
4062 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4063 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
4064 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4068 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
4069 const struct qstr
*name
, struct nfs_fh
*fhandle
,
4070 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4072 struct nfs4_exception exception
= { };
4073 struct rpc_clnt
*client
= *clnt
;
4076 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
4077 trace_nfs4_lookup(dir
, name
, err
);
4079 case -NFS4ERR_BADNAME
:
4082 case -NFS4ERR_MOVED
:
4083 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
4084 if (err
== -NFS4ERR_MOVED
)
4085 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
4087 case -NFS4ERR_WRONGSEC
:
4089 if (client
!= *clnt
)
4091 client
= nfs4_negotiate_security(client
, dir
, name
);
4093 return PTR_ERR(client
);
4095 exception
.retry
= 1;
4098 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
4100 } while (exception
.retry
);
4105 else if (client
!= *clnt
)
4106 rpc_shutdown_client(client
);
4111 static int nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
4112 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
4113 struct nfs4_label
*label
)
4116 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
4118 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
4119 if (client
!= NFS_CLIENT(dir
)) {
4120 rpc_shutdown_client(client
);
4121 nfs_fixup_secinfo_attributes(fattr
);
4127 nfs4_proc_lookup_mountpoint(struct inode
*dir
, const struct qstr
*name
,
4128 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
4130 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
4133 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
4135 return ERR_PTR(status
);
4136 return (client
== NFS_CLIENT(dir
)) ? rpc_clone_client(client
) : client
;
4139 static int _nfs4_proc_lookupp(struct inode
*inode
,
4140 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
4141 struct nfs4_label
*label
)
4143 struct rpc_clnt
*clnt
= NFS_CLIENT(inode
);
4144 struct nfs_server
*server
= NFS_SERVER(inode
);
4146 struct nfs4_lookupp_arg args
= {
4147 .bitmask
= server
->attr_bitmask
,
4148 .fh
= NFS_FH(inode
),
4150 struct nfs4_lookupp_res res
= {
4156 struct rpc_message msg
= {
4157 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUPP
],
4162 args
.bitmask
= nfs4_bitmask(server
, label
);
4164 nfs_fattr_init(fattr
);
4166 dprintk("NFS call lookupp ino=0x%lx\n", inode
->i_ino
);
4167 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
4169 dprintk("NFS reply lookupp: %d\n", status
);
4173 static int nfs4_proc_lookupp(struct inode
*inode
, struct nfs_fh
*fhandle
,
4174 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4176 struct nfs4_exception exception
= { };
4179 err
= _nfs4_proc_lookupp(inode
, fhandle
, fattr
, label
);
4180 trace_nfs4_lookupp(inode
, err
);
4181 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4183 } while (exception
.retry
);
4187 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
4189 struct nfs_server
*server
= NFS_SERVER(inode
);
4190 struct nfs4_accessargs args
= {
4191 .fh
= NFS_FH(inode
),
4192 .access
= entry
->mask
,
4194 struct nfs4_accessres res
= {
4197 struct rpc_message msg
= {
4198 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
4201 .rpc_cred
= entry
->cred
,
4205 if (!nfs4_have_delegation(inode
, FMODE_READ
)) {
4206 res
.fattr
= nfs_alloc_fattr();
4207 if (res
.fattr
== NULL
)
4209 args
.bitmask
= server
->cache_consistency_bitmask
;
4211 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4213 nfs_access_set_mask(entry
, res
.access
);
4215 nfs_refresh_inode(inode
, res
.fattr
);
4217 nfs_free_fattr(res
.fattr
);
4221 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
4223 struct nfs4_exception exception
= { };
4226 err
= _nfs4_proc_access(inode
, entry
);
4227 trace_nfs4_access(inode
, err
);
4228 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4230 } while (exception
.retry
);
4235 * TODO: For the time being, we don't try to get any attributes
4236 * along with any of the zero-copy operations READ, READDIR,
4239 * In the case of the first three, we want to put the GETATTR
4240 * after the read-type operation -- this is because it is hard
4241 * to predict the length of a GETATTR response in v4, and thus
4242 * align the READ data correctly. This means that the GETATTR
4243 * may end up partially falling into the page cache, and we should
4244 * shift it into the 'tail' of the xdr_buf before processing.
4245 * To do this efficiently, we need to know the total length
4246 * of data received, which doesn't seem to be available outside
4249 * In the case of WRITE, we also want to put the GETATTR after
4250 * the operation -- in this case because we want to make sure
4251 * we get the post-operation mtime and size.
4253 * Both of these changes to the XDR layer would in fact be quite
4254 * minor, but I decided to leave them for a subsequent patch.
4256 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
4257 unsigned int pgbase
, unsigned int pglen
)
4259 struct nfs4_readlink args
= {
4260 .fh
= NFS_FH(inode
),
4265 struct nfs4_readlink_res res
;
4266 struct rpc_message msg
= {
4267 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
4272 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4275 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
4276 unsigned int pgbase
, unsigned int pglen
)
4278 struct nfs4_exception exception
= { };
4281 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
4282 trace_nfs4_readlink(inode
, err
);
4283 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4285 } while (exception
.retry
);
4290 * This is just for mknod. open(O_CREAT) will always do ->open_context().
4293 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
4296 struct nfs_server
*server
= NFS_SERVER(dir
);
4297 struct nfs4_label l
, *ilabel
= NULL
;
4298 struct nfs_open_context
*ctx
;
4299 struct nfs4_state
*state
;
4302 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
, NULL
);
4304 return PTR_ERR(ctx
);
4306 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4308 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4309 sattr
->ia_mode
&= ~current_umask();
4310 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
, NULL
);
4311 if (IS_ERR(state
)) {
4312 status
= PTR_ERR(state
);
4316 nfs4_label_release_security(ilabel
);
4317 put_nfs_open_context(ctx
);
4322 _nfs4_proc_remove(struct inode
*dir
, const struct qstr
*name
, u32 ftype
)
4324 struct nfs_server
*server
= NFS_SERVER(dir
);
4325 struct nfs_removeargs args
= {
4329 struct nfs_removeres res
= {
4332 struct rpc_message msg
= {
4333 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
4337 unsigned long timestamp
= jiffies
;
4340 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
4342 spin_lock(&dir
->i_lock
);
4343 update_changeattr_locked(dir
, &res
.cinfo
, timestamp
, 0);
4344 /* Removing a directory decrements nlink in the parent */
4345 if (ftype
== NF4DIR
&& dir
->i_nlink
> 2)
4346 nfs4_dec_nlink_locked(dir
);
4347 spin_unlock(&dir
->i_lock
);
4352 static int nfs4_proc_remove(struct inode
*dir
, struct dentry
*dentry
)
4354 struct nfs4_exception exception
= { };
4355 struct inode
*inode
= d_inode(dentry
);
4359 if (inode
->i_nlink
== 1)
4360 nfs4_inode_return_delegation(inode
);
4362 nfs4_inode_make_writeable(inode
);
4365 err
= _nfs4_proc_remove(dir
, &dentry
->d_name
, NF4REG
);
4366 trace_nfs4_remove(dir
, &dentry
->d_name
, err
);
4367 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4369 } while (exception
.retry
);
4373 static int nfs4_proc_rmdir(struct inode
*dir
, const struct qstr
*name
)
4375 struct nfs4_exception exception
= { };
4379 err
= _nfs4_proc_remove(dir
, name
, NF4DIR
);
4380 trace_nfs4_remove(dir
, name
, err
);
4381 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4383 } while (exception
.retry
);
4387 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
,
4388 struct dentry
*dentry
,
4389 struct inode
*inode
)
4391 struct nfs_removeargs
*args
= msg
->rpc_argp
;
4392 struct nfs_removeres
*res
= msg
->rpc_resp
;
4394 res
->server
= NFS_SB(dentry
->d_sb
);
4395 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
4396 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1, 0);
4398 nfs_fattr_init(res
->dir_attr
);
4401 nfs4_inode_return_delegation(inode
);
4404 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
4406 nfs4_setup_sequence(NFS_SB(data
->dentry
->d_sb
)->nfs_client
,
4407 &data
->args
.seq_args
,
4412 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
4414 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
4415 struct nfs_removeres
*res
= &data
->res
;
4417 if (!nfs4_sequence_done(task
, &res
->seq_res
))
4419 if (nfs4_async_handle_error(task
, res
->server
, NULL
,
4420 &data
->timeout
) == -EAGAIN
)
4422 if (task
->tk_status
== 0)
4423 update_changeattr(dir
, &res
->cinfo
,
4424 res
->dir_attr
->time_start
, 0);
4428 static void nfs4_proc_rename_setup(struct rpc_message
*msg
,
4429 struct dentry
*old_dentry
,
4430 struct dentry
*new_dentry
)
4432 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
4433 struct nfs_renameres
*res
= msg
->rpc_resp
;
4434 struct inode
*old_inode
= d_inode(old_dentry
);
4435 struct inode
*new_inode
= d_inode(new_dentry
);
4438 nfs4_inode_make_writeable(old_inode
);
4440 nfs4_inode_return_delegation(new_inode
);
4441 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
4442 res
->server
= NFS_SB(old_dentry
->d_sb
);
4443 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1, 0);
4446 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
4448 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
)->nfs_client
,
4449 &data
->args
.seq_args
,
4454 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
4455 struct inode
*new_dir
)
4457 struct nfs_renamedata
*data
= task
->tk_calldata
;
4458 struct nfs_renameres
*res
= &data
->res
;
4460 if (!nfs4_sequence_done(task
, &res
->seq_res
))
4462 if (nfs4_async_handle_error(task
, res
->server
, NULL
, &data
->timeout
) == -EAGAIN
)
4465 if (task
->tk_status
== 0) {
4466 if (new_dir
!= old_dir
) {
4467 /* Note: If we moved a directory, nlink will change */
4468 update_changeattr(old_dir
, &res
->old_cinfo
,
4469 res
->old_fattr
->time_start
,
4470 NFS_INO_INVALID_OTHER
);
4471 update_changeattr(new_dir
, &res
->new_cinfo
,
4472 res
->new_fattr
->time_start
,
4473 NFS_INO_INVALID_OTHER
);
4475 update_changeattr(old_dir
, &res
->old_cinfo
,
4476 res
->old_fattr
->time_start
,
4482 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
4484 struct nfs_server
*server
= NFS_SERVER(inode
);
4485 __u32 bitmask
[NFS4_BITMASK_SZ
];
4486 struct nfs4_link_arg arg
= {
4487 .fh
= NFS_FH(inode
),
4488 .dir_fh
= NFS_FH(dir
),
4492 struct nfs4_link_res res
= {
4496 struct rpc_message msg
= {
4497 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
4501 int status
= -ENOMEM
;
4503 res
.fattr
= nfs_alloc_fattr();
4504 if (res
.fattr
== NULL
)
4507 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
4508 if (IS_ERR(res
.label
)) {
4509 status
= PTR_ERR(res
.label
);
4513 nfs4_inode_make_writeable(inode
);
4514 nfs4_bitmap_copy_adjust_setattr(bitmask
, nfs4_bitmask(server
, res
.label
), inode
);
4516 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4518 update_changeattr(dir
, &res
.cinfo
, res
.fattr
->time_start
, 0);
4519 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
4521 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
4525 nfs4_label_free(res
.label
);
4528 nfs_free_fattr(res
.fattr
);
4532 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
4534 struct nfs4_exception exception
= { };
4537 err
= nfs4_handle_exception(NFS_SERVER(inode
),
4538 _nfs4_proc_link(inode
, dir
, name
),
4540 } while (exception
.retry
);
4544 struct nfs4_createdata
{
4545 struct rpc_message msg
;
4546 struct nfs4_create_arg arg
;
4547 struct nfs4_create_res res
;
4549 struct nfs_fattr fattr
;
4550 struct nfs4_label
*label
;
4553 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
4554 const struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
4556 struct nfs4_createdata
*data
;
4558 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
4560 struct nfs_server
*server
= NFS_SERVER(dir
);
4562 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
4563 if (IS_ERR(data
->label
))
4566 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
4567 data
->msg
.rpc_argp
= &data
->arg
;
4568 data
->msg
.rpc_resp
= &data
->res
;
4569 data
->arg
.dir_fh
= NFS_FH(dir
);
4570 data
->arg
.server
= server
;
4571 data
->arg
.name
= name
;
4572 data
->arg
.attrs
= sattr
;
4573 data
->arg
.ftype
= ftype
;
4574 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
4575 data
->arg
.umask
= current_umask();
4576 data
->res
.server
= server
;
4577 data
->res
.fh
= &data
->fh
;
4578 data
->res
.fattr
= &data
->fattr
;
4579 data
->res
.label
= data
->label
;
4580 nfs_fattr_init(data
->res
.fattr
);
4588 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
4590 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
4591 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
4593 spin_lock(&dir
->i_lock
);
4594 update_changeattr_locked(dir
, &data
->res
.dir_cinfo
,
4595 data
->res
.fattr
->time_start
, 0);
4596 /* Creating a directory bumps nlink in the parent */
4597 if (data
->arg
.ftype
== NF4DIR
)
4598 nfs4_inc_nlink_locked(dir
);
4599 spin_unlock(&dir
->i_lock
);
4600 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
4605 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
4607 nfs4_label_free(data
->label
);
4611 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
4612 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
4613 struct nfs4_label
*label
)
4615 struct nfs4_createdata
*data
;
4616 int status
= -ENAMETOOLONG
;
4618 if (len
> NFS4_MAXPATHLEN
)
4622 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
4626 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
4627 data
->arg
.u
.symlink
.pages
= &page
;
4628 data
->arg
.u
.symlink
.len
= len
;
4629 data
->arg
.label
= label
;
4631 status
= nfs4_do_create(dir
, dentry
, data
);
4633 nfs4_free_createdata(data
);
4638 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
4639 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
4641 struct nfs4_exception exception
= { };
4642 struct nfs4_label l
, *label
= NULL
;
4645 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4648 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
4649 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
4650 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4652 } while (exception
.retry
);
4654 nfs4_label_release_security(label
);
4658 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
4659 struct iattr
*sattr
, struct nfs4_label
*label
)
4661 struct nfs4_createdata
*data
;
4662 int status
= -ENOMEM
;
4664 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
4668 data
->arg
.label
= label
;
4669 status
= nfs4_do_create(dir
, dentry
, data
);
4671 nfs4_free_createdata(data
);
4676 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
4677 struct iattr
*sattr
)
4679 struct nfs_server
*server
= NFS_SERVER(dir
);
4680 struct nfs4_exception exception
= { };
4681 struct nfs4_label l
, *label
= NULL
;
4684 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4686 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4687 sattr
->ia_mode
&= ~current_umask();
4689 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
4690 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
4691 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4693 } while (exception
.retry
);
4694 nfs4_label_release_security(label
);
4699 static int _nfs4_proc_readdir(struct dentry
*dentry
, const struct cred
*cred
,
4700 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
4702 struct inode
*dir
= d_inode(dentry
);
4703 struct nfs4_readdir_arg args
= {
4708 .bitmask
= NFS_SERVER(d_inode(dentry
))->attr_bitmask
,
4711 struct nfs4_readdir_res res
;
4712 struct rpc_message msg
= {
4713 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
4720 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__
,
4722 (unsigned long long)cookie
);
4723 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
4724 res
.pgbase
= args
.pgbase
;
4725 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4727 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
4728 status
+= args
.pgbase
;
4731 nfs_invalidate_atime(dir
);
4733 dprintk("%s: returns %d\n", __func__
, status
);
4737 static int nfs4_proc_readdir(struct dentry
*dentry
, const struct cred
*cred
,
4738 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
4740 struct nfs4_exception exception
= { };
4743 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
4744 pages
, count
, plus
);
4745 trace_nfs4_readdir(d_inode(dentry
), err
);
4746 err
= nfs4_handle_exception(NFS_SERVER(d_inode(dentry
)), err
,
4748 } while (exception
.retry
);
4752 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
4753 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
4755 struct nfs4_createdata
*data
;
4756 int mode
= sattr
->ia_mode
;
4757 int status
= -ENOMEM
;
4759 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
4764 data
->arg
.ftype
= NF4FIFO
;
4765 else if (S_ISBLK(mode
)) {
4766 data
->arg
.ftype
= NF4BLK
;
4767 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
4768 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
4770 else if (S_ISCHR(mode
)) {
4771 data
->arg
.ftype
= NF4CHR
;
4772 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
4773 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
4774 } else if (!S_ISSOCK(mode
)) {
4779 data
->arg
.label
= label
;
4780 status
= nfs4_do_create(dir
, dentry
, data
);
4782 nfs4_free_createdata(data
);
4787 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
4788 struct iattr
*sattr
, dev_t rdev
)
4790 struct nfs_server
*server
= NFS_SERVER(dir
);
4791 struct nfs4_exception exception
= { };
4792 struct nfs4_label l
, *label
= NULL
;
4795 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4797 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4798 sattr
->ia_mode
&= ~current_umask();
4800 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
4801 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
4802 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4804 } while (exception
.retry
);
4806 nfs4_label_release_security(label
);
4811 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4812 struct nfs_fsstat
*fsstat
)
4814 struct nfs4_statfs_arg args
= {
4816 .bitmask
= server
->attr_bitmask
,
4818 struct nfs4_statfs_res res
= {
4821 struct rpc_message msg
= {
4822 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
4827 nfs_fattr_init(fsstat
->fattr
);
4828 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4831 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
4833 struct nfs4_exception exception
= { };
4836 err
= nfs4_handle_exception(server
,
4837 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
4839 } while (exception
.retry
);
4843 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4844 struct nfs_fsinfo
*fsinfo
)
4846 struct nfs4_fsinfo_arg args
= {
4848 .bitmask
= server
->attr_bitmask
,
4850 struct nfs4_fsinfo_res res
= {
4853 struct rpc_message msg
= {
4854 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
4859 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4862 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4864 struct nfs4_exception exception
= { };
4865 unsigned long now
= jiffies
;
4869 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4870 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
4872 nfs4_set_lease_period(server
->nfs_client
,
4873 fsinfo
->lease_time
* HZ
,
4877 err
= nfs4_handle_exception(server
, err
, &exception
);
4878 } while (exception
.retry
);
4882 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4886 nfs_fattr_init(fsinfo
->fattr
);
4887 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4889 /* block layout checks this! */
4890 server
->pnfs_blksize
= fsinfo
->blksize
;
4891 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
);
4897 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4898 struct nfs_pathconf
*pathconf
)
4900 struct nfs4_pathconf_arg args
= {
4902 .bitmask
= server
->attr_bitmask
,
4904 struct nfs4_pathconf_res res
= {
4905 .pathconf
= pathconf
,
4907 struct rpc_message msg
= {
4908 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
4913 /* None of the pathconf attributes are mandatory to implement */
4914 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
4915 memset(pathconf
, 0, sizeof(*pathconf
));
4919 nfs_fattr_init(pathconf
->fattr
);
4920 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4923 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4924 struct nfs_pathconf
*pathconf
)
4926 struct nfs4_exception exception
= { };
4930 err
= nfs4_handle_exception(server
,
4931 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
4933 } while (exception
.retry
);
4937 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
4938 const struct nfs_open_context
*ctx
,
4939 const struct nfs_lock_context
*l_ctx
,
4942 return nfs4_select_rw_stateid(ctx
->state
, fmode
, l_ctx
, stateid
, NULL
);
4944 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
4946 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
4947 const struct nfs_open_context
*ctx
,
4948 const struct nfs_lock_context
*l_ctx
,
4951 nfs4_stateid current_stateid
;
4953 /* If the current stateid represents a lost lock, then exit */
4954 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
) == -EIO
)
4956 return nfs4_stateid_match(stateid
, ¤t_stateid
);
4959 static bool nfs4_error_stateid_expired(int err
)
4962 case -NFS4ERR_DELEG_REVOKED
:
4963 case -NFS4ERR_ADMIN_REVOKED
:
4964 case -NFS4ERR_BAD_STATEID
:
4965 case -NFS4ERR_STALE_STATEID
:
4966 case -NFS4ERR_OLD_STATEID
:
4967 case -NFS4ERR_OPENMODE
:
4968 case -NFS4ERR_EXPIRED
:
4974 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4976 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4978 trace_nfs4_read(hdr
, task
->tk_status
);
4979 if (task
->tk_status
< 0) {
4980 struct nfs4_exception exception
= {
4981 .inode
= hdr
->inode
,
4982 .state
= hdr
->args
.context
->state
,
4983 .stateid
= &hdr
->args
.stateid
,
4985 task
->tk_status
= nfs4_async_handle_exception(task
,
4986 server
, task
->tk_status
, &exception
);
4987 if (exception
.retry
) {
4988 rpc_restart_call_prepare(task
);
4993 if (task
->tk_status
> 0)
4994 renew_lease(server
, hdr
->timestamp
);
4998 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
4999 struct nfs_pgio_args
*args
)
5002 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
5003 nfs4_stateid_is_current(&args
->stateid
,
5008 rpc_restart_call_prepare(task
);
5012 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
5015 dprintk("--> %s\n", __func__
);
5017 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
5019 if (nfs4_read_stateid_changed(task
, &hdr
->args
))
5021 if (task
->tk_status
> 0)
5022 nfs_invalidate_atime(hdr
->inode
);
5023 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
5024 nfs4_read_done_cb(task
, hdr
);
5027 static void nfs4_proc_read_setup(struct nfs_pgio_header
*hdr
,
5028 struct rpc_message
*msg
)
5030 hdr
->timestamp
= jiffies
;
5031 if (!hdr
->pgio_done_cb
)
5032 hdr
->pgio_done_cb
= nfs4_read_done_cb
;
5033 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
5034 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 0, 0);
5037 static int nfs4_proc_pgio_rpc_prepare(struct rpc_task
*task
,
5038 struct nfs_pgio_header
*hdr
)
5040 if (nfs4_setup_sequence(NFS_SERVER(hdr
->inode
)->nfs_client
,
5041 &hdr
->args
.seq_args
,
5045 if (nfs4_set_rw_stateid(&hdr
->args
.stateid
, hdr
->args
.context
,
5046 hdr
->args
.lock_context
,
5047 hdr
->rw_mode
) == -EIO
)
5049 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
)))
5054 static int nfs4_write_done_cb(struct rpc_task
*task
,
5055 struct nfs_pgio_header
*hdr
)
5057 struct inode
*inode
= hdr
->inode
;
5059 trace_nfs4_write(hdr
, task
->tk_status
);
5060 if (task
->tk_status
< 0) {
5061 struct nfs4_exception exception
= {
5062 .inode
= hdr
->inode
,
5063 .state
= hdr
->args
.context
->state
,
5064 .stateid
= &hdr
->args
.stateid
,
5066 task
->tk_status
= nfs4_async_handle_exception(task
,
5067 NFS_SERVER(inode
), task
->tk_status
,
5069 if (exception
.retry
) {
5070 rpc_restart_call_prepare(task
);
5074 if (task
->tk_status
>= 0) {
5075 renew_lease(NFS_SERVER(inode
), hdr
->timestamp
);
5076 nfs_writeback_update_inode(hdr
);
5081 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
5082 struct nfs_pgio_args
*args
)
5085 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
5086 nfs4_stateid_is_current(&args
->stateid
,
5091 rpc_restart_call_prepare(task
);
5095 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
5097 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
5099 if (nfs4_write_stateid_changed(task
, &hdr
->args
))
5101 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
5102 nfs4_write_done_cb(task
, hdr
);
5106 bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header
*hdr
)
5108 /* Don't request attributes for pNFS or O_DIRECT writes */
5109 if (hdr
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
5111 /* Otherwise, request attributes if and only if we don't hold
5114 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
5117 static void nfs4_proc_write_setup(struct nfs_pgio_header
*hdr
,
5118 struct rpc_message
*msg
,
5119 struct rpc_clnt
**clnt
)
5121 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
5123 if (!nfs4_write_need_cache_consistency_data(hdr
)) {
5124 hdr
->args
.bitmask
= NULL
;
5125 hdr
->res
.fattr
= NULL
;
5127 hdr
->args
.bitmask
= server
->cache_consistency_bitmask
;
5129 if (!hdr
->pgio_done_cb
)
5130 hdr
->pgio_done_cb
= nfs4_write_done_cb
;
5131 hdr
->res
.server
= server
;
5132 hdr
->timestamp
= jiffies
;
5134 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
5135 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 1, 0);
5136 nfs4_state_protect_write(server
->nfs_client
, clnt
, msg
, hdr
);
5139 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5141 nfs4_setup_sequence(NFS_SERVER(data
->inode
)->nfs_client
,
5142 &data
->args
.seq_args
,
5147 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5149 struct inode
*inode
= data
->inode
;
5151 trace_nfs4_commit(data
, task
->tk_status
);
5152 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
),
5153 NULL
, NULL
) == -EAGAIN
) {
5154 rpc_restart_call_prepare(task
);
5160 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5162 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5164 return data
->commit_done_cb(task
, data
);
5167 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
,
5168 struct rpc_clnt
**clnt
)
5170 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
5172 if (data
->commit_done_cb
== NULL
)
5173 data
->commit_done_cb
= nfs4_commit_done_cb
;
5174 data
->res
.server
= server
;
5175 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
5176 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
5177 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_COMMIT
, clnt
, msg
);
5180 static int _nfs4_proc_commit(struct file
*dst
, struct nfs_commitargs
*args
,
5181 struct nfs_commitres
*res
)
5183 struct inode
*dst_inode
= file_inode(dst
);
5184 struct nfs_server
*server
= NFS_SERVER(dst_inode
);
5185 struct rpc_message msg
= {
5186 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
],
5191 args
->fh
= NFS_FH(dst_inode
);
5192 return nfs4_call_sync(server
->client
, server
, &msg
,
5193 &args
->seq_args
, &res
->seq_res
, 1);
5196 int nfs4_proc_commit(struct file
*dst
, __u64 offset
, __u32 count
, struct nfs_commitres
*res
)
5198 struct nfs_commitargs args
= {
5202 struct nfs_server
*dst_server
= NFS_SERVER(file_inode(dst
));
5203 struct nfs4_exception exception
= { };
5207 status
= _nfs4_proc_commit(dst
, &args
, res
);
5208 status
= nfs4_handle_exception(dst_server
, status
, &exception
);
5209 } while (exception
.retry
);
5214 struct nfs4_renewdata
{
5215 struct nfs_client
*client
;
5216 unsigned long timestamp
;
5220 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
5221 * standalone procedure for queueing an asynchronous RENEW.
5223 static void nfs4_renew_release(void *calldata
)
5225 struct nfs4_renewdata
*data
= calldata
;
5226 struct nfs_client
*clp
= data
->client
;
5228 if (refcount_read(&clp
->cl_count
) > 1)
5229 nfs4_schedule_state_renewal(clp
);
5230 nfs_put_client(clp
);
5234 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
5236 struct nfs4_renewdata
*data
= calldata
;
5237 struct nfs_client
*clp
= data
->client
;
5238 unsigned long timestamp
= data
->timestamp
;
5240 trace_nfs4_renew_async(clp
, task
->tk_status
);
5241 switch (task
->tk_status
) {
5244 case -NFS4ERR_LEASE_MOVED
:
5245 nfs4_schedule_lease_moved_recovery(clp
);
5248 /* Unless we're shutting down, schedule state recovery! */
5249 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
5251 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
5252 nfs4_schedule_lease_recovery(clp
);
5255 nfs4_schedule_path_down_recovery(clp
);
5257 do_renew_lease(clp
, timestamp
);
5260 static const struct rpc_call_ops nfs4_renew_ops
= {
5261 .rpc_call_done
= nfs4_renew_done
,
5262 .rpc_release
= nfs4_renew_release
,
5265 static int nfs4_proc_async_renew(struct nfs_client
*clp
, const struct cred
*cred
, unsigned renew_flags
)
5267 struct rpc_message msg
= {
5268 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
5272 struct nfs4_renewdata
*data
;
5274 if (renew_flags
== 0)
5276 if (!refcount_inc_not_zero(&clp
->cl_count
))
5278 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5280 nfs_put_client(clp
);
5284 data
->timestamp
= jiffies
;
5285 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
5286 &nfs4_renew_ops
, data
);
5289 static int nfs4_proc_renew(struct nfs_client
*clp
, const struct cred
*cred
)
5291 struct rpc_message msg
= {
5292 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
5296 unsigned long now
= jiffies
;
5299 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5302 do_renew_lease(clp
, now
);
5306 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
5308 return server
->caps
& NFS_CAP_ACLS
;
5311 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
5312 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
5315 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
5317 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
5318 struct page
**pages
)
5320 struct page
*newpage
, **spages
;
5326 len
= min_t(size_t, PAGE_SIZE
, buflen
);
5327 newpage
= alloc_page(GFP_KERNEL
);
5329 if (newpage
== NULL
)
5331 memcpy(page_address(newpage
), buf
, len
);
5336 } while (buflen
!= 0);
5342 __free_page(spages
[rc
-1]);
5346 struct nfs4_cached_acl
{
5352 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
5354 struct nfs_inode
*nfsi
= NFS_I(inode
);
5356 spin_lock(&inode
->i_lock
);
5357 kfree(nfsi
->nfs4_acl
);
5358 nfsi
->nfs4_acl
= acl
;
5359 spin_unlock(&inode
->i_lock
);
5362 static void nfs4_zap_acl_attr(struct inode
*inode
)
5364 nfs4_set_cached_acl(inode
, NULL
);
5367 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
5369 struct nfs_inode
*nfsi
= NFS_I(inode
);
5370 struct nfs4_cached_acl
*acl
;
5373 spin_lock(&inode
->i_lock
);
5374 acl
= nfsi
->nfs4_acl
;
5377 if (buf
== NULL
) /* user is just asking for length */
5379 if (acl
->cached
== 0)
5381 ret
= -ERANGE
; /* see getxattr(2) man page */
5382 if (acl
->len
> buflen
)
5384 memcpy(buf
, acl
->data
, acl
->len
);
5388 spin_unlock(&inode
->i_lock
);
5392 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
5394 struct nfs4_cached_acl
*acl
;
5395 size_t buflen
= sizeof(*acl
) + acl_len
;
5397 if (buflen
<= PAGE_SIZE
) {
5398 acl
= kmalloc(buflen
, GFP_KERNEL
);
5402 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
5404 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
5411 nfs4_set_cached_acl(inode
, acl
);
5415 * The getxattr API returns the required buffer length when called with a
5416 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
5417 * the required buf. On a NULL buf, we send a page of data to the server
5418 * guessing that the ACL request can be serviced by a page. If so, we cache
5419 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
5420 * the cache. If not so, we throw away the page, and cache the required
5421 * length. The next getxattr call will then produce another round trip to
5422 * the server, this time with the input buf of the required size.
5424 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
5426 struct page
*pages
[NFS4ACL_MAXPAGES
+ 1] = {NULL
, };
5427 struct nfs_getaclargs args
= {
5428 .fh
= NFS_FH(inode
),
5432 struct nfs_getaclres res
= {
5435 struct rpc_message msg
= {
5436 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
5440 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
) + 1;
5441 int ret
= -ENOMEM
, i
;
5443 if (npages
> ARRAY_SIZE(pages
))
5446 for (i
= 0; i
< npages
; i
++) {
5447 pages
[i
] = alloc_page(GFP_KERNEL
);
5452 /* for decoding across pages */
5453 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
5454 if (!res
.acl_scratch
)
5457 args
.acl_len
= npages
* PAGE_SIZE
;
5459 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
5460 __func__
, buf
, buflen
, npages
, args
.acl_len
);
5461 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
5462 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5466 /* Handle the case where the passed-in buffer is too short */
5467 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
5468 /* Did the user only issue a request for the acl length? */
5474 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
5476 if (res
.acl_len
> buflen
) {
5480 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
5485 for (i
= 0; i
< npages
; i
++)
5487 __free_page(pages
[i
]);
5488 if (res
.acl_scratch
)
5489 __free_page(res
.acl_scratch
);
5493 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
5495 struct nfs4_exception exception
= { };
5498 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
5499 trace_nfs4_get_acl(inode
, ret
);
5502 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
5503 } while (exception
.retry
);
5507 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
5509 struct nfs_server
*server
= NFS_SERVER(inode
);
5512 if (!nfs4_server_supports_acls(server
))
5514 ret
= nfs_revalidate_inode(server
, inode
);
5517 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
5518 nfs_zap_acl_cache(inode
);
5519 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
5521 /* -ENOENT is returned if there is no ACL or if there is an ACL
5522 * but no cached acl data, just the acl length */
5524 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
5527 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
5529 struct nfs_server
*server
= NFS_SERVER(inode
);
5530 struct page
*pages
[NFS4ACL_MAXPAGES
];
5531 struct nfs_setaclargs arg
= {
5532 .fh
= NFS_FH(inode
),
5536 struct nfs_setaclres res
;
5537 struct rpc_message msg
= {
5538 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
5542 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
5545 if (!nfs4_server_supports_acls(server
))
5547 if (npages
> ARRAY_SIZE(pages
))
5549 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
);
5552 nfs4_inode_make_writeable(inode
);
5553 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5556 * Free each page after tx, so the only ref left is
5557 * held by the network stack
5560 put_page(pages
[i
-1]);
5563 * Acl update can result in inode attribute update.
5564 * so mark the attribute cache invalid.
5566 spin_lock(&inode
->i_lock
);
5567 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_CHANGE
5568 | NFS_INO_INVALID_CTIME
5569 | NFS_INO_REVAL_FORCED
;
5570 spin_unlock(&inode
->i_lock
);
5571 nfs_access_zap_cache(inode
);
5572 nfs_zap_acl_cache(inode
);
5576 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
5578 struct nfs4_exception exception
= { };
5581 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
5582 trace_nfs4_set_acl(inode
, err
);
5583 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5585 } while (exception
.retry
);
5589 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5590 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
5593 struct nfs_server
*server
= NFS_SERVER(inode
);
5594 struct nfs_fattr fattr
;
5595 struct nfs4_label label
= {0, 0, buflen
, buf
};
5597 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
5598 struct nfs4_getattr_arg arg
= {
5599 .fh
= NFS_FH(inode
),
5602 struct nfs4_getattr_res res
= {
5607 struct rpc_message msg
= {
5608 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
5614 nfs_fattr_init(&fattr
);
5616 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 0);
5619 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
5621 if (buflen
< label
.len
)
5626 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
5629 struct nfs4_exception exception
= { };
5632 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
5636 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
5637 trace_nfs4_get_security_label(inode
, err
);
5638 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5640 } while (exception
.retry
);
5644 static int _nfs4_do_set_security_label(struct inode
*inode
,
5645 struct nfs4_label
*ilabel
,
5646 struct nfs_fattr
*fattr
,
5647 struct nfs4_label
*olabel
)
5650 struct iattr sattr
= {0};
5651 struct nfs_server
*server
= NFS_SERVER(inode
);
5652 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
5653 struct nfs_setattrargs arg
= {
5654 .fh
= NFS_FH(inode
),
5660 struct nfs_setattrres res
= {
5665 struct rpc_message msg
= {
5666 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
5672 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
5674 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5676 dprintk("%s failed: %d\n", __func__
, status
);
5681 static int nfs4_do_set_security_label(struct inode
*inode
,
5682 struct nfs4_label
*ilabel
,
5683 struct nfs_fattr
*fattr
,
5684 struct nfs4_label
*olabel
)
5686 struct nfs4_exception exception
= { };
5690 err
= _nfs4_do_set_security_label(inode
, ilabel
,
5692 trace_nfs4_set_security_label(inode
, err
);
5693 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5695 } while (exception
.retry
);
5700 nfs4_set_security_label(struct inode
*inode
, const void *buf
, size_t buflen
)
5702 struct nfs4_label ilabel
, *olabel
= NULL
;
5703 struct nfs_fattr fattr
;
5706 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
5709 nfs_fattr_init(&fattr
);
5713 ilabel
.label
= (char *)buf
;
5714 ilabel
.len
= buflen
;
5716 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
5717 if (IS_ERR(olabel
)) {
5718 status
= -PTR_ERR(olabel
);
5722 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
5724 nfs_setsecurity(inode
, &fattr
, olabel
);
5726 nfs4_label_free(olabel
);
5730 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
5733 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
5734 nfs4_verifier
*bootverf
)
5738 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
5739 /* An impossible timestamp guarantees this value
5740 * will never match a generated boot time. */
5741 verf
[0] = cpu_to_be32(U32_MAX
);
5742 verf
[1] = cpu_to_be32(U32_MAX
);
5744 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
5745 u64 ns
= ktime_to_ns(nn
->boot_time
);
5747 verf
[0] = cpu_to_be32(ns
>> 32);
5748 verf
[1] = cpu_to_be32(ns
);
5750 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
5754 nfs4_init_nonuniform_client_string(struct nfs_client
*clp
)
5759 if (clp
->cl_owner_id
!= NULL
)
5764 strlen(clp
->cl_rpcclient
->cl_nodename
) +
5766 strlen(rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_ADDR
)) +
5769 if (nfs4_client_id_uniquifier
[0] != '\0')
5770 len
+= strlen(nfs4_client_id_uniquifier
) + 1;
5771 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5775 * Since this string is allocated at mount time, and held until the
5776 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5777 * about a memory-reclaim deadlock.
5779 str
= kmalloc(len
, GFP_KERNEL
);
5784 if (nfs4_client_id_uniquifier
[0] != '\0')
5785 scnprintf(str
, len
, "Linux NFSv4.0 %s/%s/%s",
5786 clp
->cl_rpcclient
->cl_nodename
,
5787 nfs4_client_id_uniquifier
,
5788 rpc_peeraddr2str(clp
->cl_rpcclient
,
5791 scnprintf(str
, len
, "Linux NFSv4.0 %s/%s",
5792 clp
->cl_rpcclient
->cl_nodename
,
5793 rpc_peeraddr2str(clp
->cl_rpcclient
,
5797 clp
->cl_owner_id
= str
;
5802 nfs4_init_uniquifier_client_string(struct nfs_client
*clp
)
5807 len
= 10 + 10 + 1 + 10 + 1 +
5808 strlen(nfs4_client_id_uniquifier
) + 1 +
5809 strlen(clp
->cl_rpcclient
->cl_nodename
) + 1;
5811 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5815 * Since this string is allocated at mount time, and held until the
5816 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5817 * about a memory-reclaim deadlock.
5819 str
= kmalloc(len
, GFP_KERNEL
);
5823 scnprintf(str
, len
, "Linux NFSv%u.%u %s/%s",
5824 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
5825 nfs4_client_id_uniquifier
,
5826 clp
->cl_rpcclient
->cl_nodename
);
5827 clp
->cl_owner_id
= str
;
5832 nfs4_init_uniform_client_string(struct nfs_client
*clp
)
5837 if (clp
->cl_owner_id
!= NULL
)
5840 if (nfs4_client_id_uniquifier
[0] != '\0')
5841 return nfs4_init_uniquifier_client_string(clp
);
5843 len
= 10 + 10 + 1 + 10 + 1 +
5844 strlen(clp
->cl_rpcclient
->cl_nodename
) + 1;
5846 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5850 * Since this string is allocated at mount time, and held until the
5851 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5852 * about a memory-reclaim deadlock.
5854 str
= kmalloc(len
, GFP_KERNEL
);
5858 scnprintf(str
, len
, "Linux NFSv%u.%u %s",
5859 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
5860 clp
->cl_rpcclient
->cl_nodename
);
5861 clp
->cl_owner_id
= str
;
5866 * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback
5867 * services. Advertise one based on the address family of the
5871 nfs4_init_callback_netid(const struct nfs_client
*clp
, char *buf
, size_t len
)
5873 if (strchr(clp
->cl_ipaddr
, ':') != NULL
)
5874 return scnprintf(buf
, len
, "tcp6");
5876 return scnprintf(buf
, len
, "tcp");
5879 static void nfs4_setclientid_done(struct rpc_task
*task
, void *calldata
)
5881 struct nfs4_setclientid
*sc
= calldata
;
5883 if (task
->tk_status
== 0)
5884 sc
->sc_cred
= get_rpccred(task
->tk_rqstp
->rq_cred
);
5887 static const struct rpc_call_ops nfs4_setclientid_ops
= {
5888 .rpc_call_done
= nfs4_setclientid_done
,
5892 * nfs4_proc_setclientid - Negotiate client ID
5893 * @clp: state data structure
5894 * @program: RPC program for NFSv4 callback service
5895 * @port: IP port number for NFS4 callback service
5896 * @cred: credential to use for this call
5897 * @res: where to place the result
5899 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5901 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
5902 unsigned short port
, const struct cred
*cred
,
5903 struct nfs4_setclientid_res
*res
)
5905 nfs4_verifier sc_verifier
;
5906 struct nfs4_setclientid setclientid
= {
5907 .sc_verifier
= &sc_verifier
,
5911 struct rpc_message msg
= {
5912 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
5913 .rpc_argp
= &setclientid
,
5917 struct rpc_task
*task
;
5918 struct rpc_task_setup task_setup_data
= {
5919 .rpc_client
= clp
->cl_rpcclient
,
5920 .rpc_message
= &msg
,
5921 .callback_ops
= &nfs4_setclientid_ops
,
5922 .callback_data
= &setclientid
,
5923 .flags
= RPC_TASK_TIMEOUT
,
5927 /* nfs_client_id4 */
5928 nfs4_init_boot_verifier(clp
, &sc_verifier
);
5930 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
5931 status
= nfs4_init_uniform_client_string(clp
);
5933 status
= nfs4_init_nonuniform_client_string(clp
);
5939 setclientid
.sc_netid_len
=
5940 nfs4_init_callback_netid(clp
,
5941 setclientid
.sc_netid
,
5942 sizeof(setclientid
.sc_netid
));
5943 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
5944 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
5945 clp
->cl_ipaddr
, port
>> 8, port
& 255);
5947 dprintk("NFS call setclientid auth=%s, '%s'\n",
5948 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5950 task
= rpc_run_task(&task_setup_data
);
5952 status
= PTR_ERR(task
);
5955 status
= task
->tk_status
;
5956 if (setclientid
.sc_cred
) {
5957 clp
->cl_acceptor
= rpcauth_stringify_acceptor(setclientid
.sc_cred
);
5958 put_rpccred(setclientid
.sc_cred
);
5962 trace_nfs4_setclientid(clp
, status
);
5963 dprintk("NFS reply setclientid: %d\n", status
);
5968 * nfs4_proc_setclientid_confirm - Confirm client ID
5969 * @clp: state data structure
5970 * @arg: result of a previous SETCLIENTID
5971 * @cred: credential to use for this call
5973 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5975 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
5976 struct nfs4_setclientid_res
*arg
,
5977 const struct cred
*cred
)
5979 struct rpc_message msg
= {
5980 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
5986 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
5987 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5989 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5990 trace_nfs4_setclientid_confirm(clp
, status
);
5991 dprintk("NFS reply setclientid_confirm: %d\n", status
);
5995 struct nfs4_delegreturndata
{
5996 struct nfs4_delegreturnargs args
;
5997 struct nfs4_delegreturnres res
;
5999 nfs4_stateid stateid
;
6000 unsigned long timestamp
;
6002 struct nfs4_layoutreturn_args arg
;
6003 struct nfs4_layoutreturn_res res
;
6004 struct nfs4_xdr_opaque_data ld_private
;
6008 struct nfs_fattr fattr
;
6010 struct inode
*inode
;
6013 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
6015 struct nfs4_delegreturndata
*data
= calldata
;
6016 struct nfs4_exception exception
= {
6017 .inode
= data
->inode
,
6018 .stateid
= &data
->stateid
,
6021 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
6024 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
6026 /* Handle Layoutreturn errors */
6027 if (data
->args
.lr_args
&& task
->tk_status
!= 0) {
6028 switch(data
->res
.lr_ret
) {
6030 data
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
6033 data
->args
.lr_args
= NULL
;
6034 data
->res
.lr_res
= NULL
;
6036 case -NFS4ERR_OLD_STATEID
:
6037 if (nfs4_layoutreturn_refresh_stateid(&data
->args
.lr_args
->stateid
,
6038 &data
->args
.lr_args
->range
,
6042 case -NFS4ERR_ADMIN_REVOKED
:
6043 case -NFS4ERR_DELEG_REVOKED
:
6044 case -NFS4ERR_EXPIRED
:
6045 case -NFS4ERR_BAD_STATEID
:
6046 case -NFS4ERR_UNKNOWN_LAYOUTTYPE
:
6047 case -NFS4ERR_WRONG_CRED
:
6048 data
->args
.lr_args
= NULL
;
6049 data
->res
.lr_res
= NULL
;
6054 switch (task
->tk_status
) {
6056 renew_lease(data
->res
.server
, data
->timestamp
);
6058 case -NFS4ERR_ADMIN_REVOKED
:
6059 case -NFS4ERR_DELEG_REVOKED
:
6060 case -NFS4ERR_EXPIRED
:
6061 nfs4_free_revoked_stateid(data
->res
.server
,
6063 task
->tk_msg
.rpc_cred
);
6065 case -NFS4ERR_BAD_STATEID
:
6066 case -NFS4ERR_STALE_STATEID
:
6067 task
->tk_status
= 0;
6069 case -NFS4ERR_OLD_STATEID
:
6070 if (nfs4_refresh_delegation_stateid(&data
->stateid
, data
->inode
))
6072 task
->tk_status
= 0;
6074 case -NFS4ERR_ACCESS
:
6075 if (data
->args
.bitmask
) {
6076 data
->args
.bitmask
= NULL
;
6077 data
->res
.fattr
= NULL
;
6082 task
->tk_status
= nfs4_async_handle_exception(task
,
6083 data
->res
.server
, task
->tk_status
,
6085 if (exception
.retry
)
6088 data
->rpc_status
= task
->tk_status
;
6091 data
->res
.lr_ret
= 0;
6093 task
->tk_status
= 0;
6094 rpc_restart_call_prepare(task
);
6097 static void nfs4_delegreturn_release(void *calldata
)
6099 struct nfs4_delegreturndata
*data
= calldata
;
6100 struct inode
*inode
= data
->inode
;
6104 pnfs_roc_release(&data
->lr
.arg
, &data
->lr
.res
,
6106 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
6107 nfs_iput_and_deactive(inode
);
6112 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
6114 struct nfs4_delegreturndata
*d_data
;
6115 struct pnfs_layout_hdr
*lo
;
6117 d_data
= (struct nfs4_delegreturndata
*)data
;
6119 if (!d_data
->lr
.roc
&& nfs4_wait_on_layoutreturn(d_data
->inode
, task
))
6122 lo
= d_data
->args
.lr_args
? d_data
->args
.lr_args
->layout
: NULL
;
6123 if (lo
&& !pnfs_layout_is_valid(lo
)) {
6124 d_data
->args
.lr_args
= NULL
;
6125 d_data
->res
.lr_res
= NULL
;
6128 nfs4_setup_sequence(d_data
->res
.server
->nfs_client
,
6129 &d_data
->args
.seq_args
,
6130 &d_data
->res
.seq_res
,
6134 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
6135 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
6136 .rpc_call_done
= nfs4_delegreturn_done
,
6137 .rpc_release
= nfs4_delegreturn_release
,
6140 static int _nfs4_proc_delegreturn(struct inode
*inode
, const struct cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
6142 struct nfs4_delegreturndata
*data
;
6143 struct nfs_server
*server
= NFS_SERVER(inode
);
6144 struct rpc_task
*task
;
6145 struct rpc_message msg
= {
6146 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
6149 struct rpc_task_setup task_setup_data
= {
6150 .rpc_client
= server
->client
,
6151 .rpc_message
= &msg
,
6152 .callback_ops
= &nfs4_delegreturn_ops
,
6153 .flags
= RPC_TASK_ASYNC
,
6157 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
6160 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
6162 nfs4_state_protect(server
->nfs_client
,
6163 NFS_SP4_MACH_CRED_CLEANUP
,
6164 &task_setup_data
.rpc_client
, &msg
);
6166 data
->args
.fhandle
= &data
->fh
;
6167 data
->args
.stateid
= &data
->stateid
;
6168 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
6169 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
6170 nfs4_stateid_copy(&data
->stateid
, stateid
);
6171 data
->res
.fattr
= &data
->fattr
;
6172 data
->res
.server
= server
;
6173 data
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
6174 data
->lr
.arg
.ld_private
= &data
->lr
.ld_private
;
6175 nfs_fattr_init(data
->res
.fattr
);
6176 data
->timestamp
= jiffies
;
6177 data
->rpc_status
= 0;
6178 data
->lr
.roc
= pnfs_roc(inode
, &data
->lr
.arg
, &data
->lr
.res
, cred
);
6179 data
->inode
= nfs_igrab_and_active(inode
);
6182 data
->args
.lr_args
= &data
->lr
.arg
;
6183 data
->res
.lr_res
= &data
->lr
.res
;
6185 } else if (data
->lr
.roc
) {
6186 pnfs_roc_release(&data
->lr
.arg
, &data
->lr
.res
, 0);
6187 data
->lr
.roc
= false;
6190 task_setup_data
.callback_data
= data
;
6191 msg
.rpc_argp
= &data
->args
;
6192 msg
.rpc_resp
= &data
->res
;
6193 task
= rpc_run_task(&task_setup_data
);
6195 return PTR_ERR(task
);
6198 status
= rpc_wait_for_completion_task(task
);
6201 status
= data
->rpc_status
;
6207 int nfs4_proc_delegreturn(struct inode
*inode
, const struct cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
6209 struct nfs_server
*server
= NFS_SERVER(inode
);
6210 struct nfs4_exception exception
= { };
6213 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
6214 trace_nfs4_delegreturn(inode
, stateid
, err
);
6216 case -NFS4ERR_STALE_STATEID
:
6217 case -NFS4ERR_EXPIRED
:
6221 err
= nfs4_handle_exception(server
, err
, &exception
);
6222 } while (exception
.retry
);
6226 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6228 struct inode
*inode
= state
->inode
;
6229 struct nfs_server
*server
= NFS_SERVER(inode
);
6230 struct nfs_client
*clp
= server
->nfs_client
;
6231 struct nfs_lockt_args arg
= {
6232 .fh
= NFS_FH(inode
),
6235 struct nfs_lockt_res res
= {
6238 struct rpc_message msg
= {
6239 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
6242 .rpc_cred
= state
->owner
->so_cred
,
6244 struct nfs4_lock_state
*lsp
;
6247 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
6248 status
= nfs4_set_lock_state(state
, request
);
6251 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6252 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6253 arg
.lock_owner
.s_dev
= server
->s_dev
;
6254 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
6257 request
->fl_type
= F_UNLCK
;
6259 case -NFS4ERR_DENIED
:
6262 request
->fl_ops
->fl_release_private(request
);
6263 request
->fl_ops
= NULL
;
6268 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6270 struct nfs4_exception exception
= { };
6274 err
= _nfs4_proc_getlk(state
, cmd
, request
);
6275 trace_nfs4_get_lock(request
, state
, cmd
, err
);
6276 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
6278 } while (exception
.retry
);
6282 struct nfs4_unlockdata
{
6283 struct nfs_locku_args arg
;
6284 struct nfs_locku_res res
;
6285 struct nfs4_lock_state
*lsp
;
6286 struct nfs_open_context
*ctx
;
6287 struct nfs_lock_context
*l_ctx
;
6288 struct file_lock fl
;
6289 struct nfs_server
*server
;
6290 unsigned long timestamp
;
6293 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
6294 struct nfs_open_context
*ctx
,
6295 struct nfs4_lock_state
*lsp
,
6296 struct nfs_seqid
*seqid
)
6298 struct nfs4_unlockdata
*p
;
6299 struct inode
*inode
= lsp
->ls_state
->inode
;
6301 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
6304 p
->arg
.fh
= NFS_FH(inode
);
6306 p
->arg
.seqid
= seqid
;
6307 p
->res
.seqid
= seqid
;
6309 refcount_inc(&lsp
->ls_count
);
6310 /* Ensure we don't close file until we're done freeing locks! */
6311 p
->ctx
= get_nfs_open_context(ctx
);
6312 p
->l_ctx
= nfs_get_lock_context(ctx
);
6313 locks_init_lock(&p
->fl
);
6314 locks_copy_lock(&p
->fl
, fl
);
6315 p
->server
= NFS_SERVER(inode
);
6319 static void nfs4_locku_release_calldata(void *data
)
6321 struct nfs4_unlockdata
*calldata
= data
;
6322 nfs_free_seqid(calldata
->arg
.seqid
);
6323 nfs4_put_lock_state(calldata
->lsp
);
6324 nfs_put_lock_context(calldata
->l_ctx
);
6325 put_nfs_open_context(calldata
->ctx
);
6329 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
6331 struct nfs4_unlockdata
*calldata
= data
;
6332 struct nfs4_exception exception
= {
6333 .inode
= calldata
->lsp
->ls_state
->inode
,
6334 .stateid
= &calldata
->arg
.stateid
,
6337 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
6339 switch (task
->tk_status
) {
6341 renew_lease(calldata
->server
, calldata
->timestamp
);
6342 locks_lock_inode_wait(calldata
->lsp
->ls_state
->inode
, &calldata
->fl
);
6343 if (nfs4_update_lock_stateid(calldata
->lsp
,
6344 &calldata
->res
.stateid
))
6347 case -NFS4ERR_ADMIN_REVOKED
:
6348 case -NFS4ERR_EXPIRED
:
6349 nfs4_free_revoked_stateid(calldata
->server
,
6350 &calldata
->arg
.stateid
,
6351 task
->tk_msg
.rpc_cred
);
6353 case -NFS4ERR_BAD_STATEID
:
6354 case -NFS4ERR_OLD_STATEID
:
6355 case -NFS4ERR_STALE_STATEID
:
6356 if (!nfs4_stateid_match(&calldata
->arg
.stateid
,
6357 &calldata
->lsp
->ls_stateid
))
6358 rpc_restart_call_prepare(task
);
6361 task
->tk_status
= nfs4_async_handle_exception(task
,
6362 calldata
->server
, task
->tk_status
,
6364 if (exception
.retry
)
6365 rpc_restart_call_prepare(task
);
6367 nfs_release_seqid(calldata
->arg
.seqid
);
6370 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
6372 struct nfs4_unlockdata
*calldata
= data
;
6374 if (test_bit(NFS_CONTEXT_UNLOCK
, &calldata
->l_ctx
->open_context
->flags
) &&
6375 nfs_async_iocounter_wait(task
, calldata
->l_ctx
))
6378 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
6380 nfs4_stateid_copy(&calldata
->arg
.stateid
, &calldata
->lsp
->ls_stateid
);
6381 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
6382 /* Note: exit _without_ running nfs4_locku_done */
6385 calldata
->timestamp
= jiffies
;
6386 if (nfs4_setup_sequence(calldata
->server
->nfs_client
,
6387 &calldata
->arg
.seq_args
,
6388 &calldata
->res
.seq_res
,
6390 nfs_release_seqid(calldata
->arg
.seqid
);
6393 task
->tk_action
= NULL
;
6395 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
6398 static const struct rpc_call_ops nfs4_locku_ops
= {
6399 .rpc_call_prepare
= nfs4_locku_prepare
,
6400 .rpc_call_done
= nfs4_locku_done
,
6401 .rpc_release
= nfs4_locku_release_calldata
,
6404 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
6405 struct nfs_open_context
*ctx
,
6406 struct nfs4_lock_state
*lsp
,
6407 struct nfs_seqid
*seqid
)
6409 struct nfs4_unlockdata
*data
;
6410 struct rpc_message msg
= {
6411 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
6412 .rpc_cred
= ctx
->cred
,
6414 struct rpc_task_setup task_setup_data
= {
6415 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
6416 .rpc_message
= &msg
,
6417 .callback_ops
= &nfs4_locku_ops
,
6418 .workqueue
= nfsiod_workqueue
,
6419 .flags
= RPC_TASK_ASYNC
,
6422 nfs4_state_protect(NFS_SERVER(lsp
->ls_state
->inode
)->nfs_client
,
6423 NFS_SP4_MACH_CRED_CLEANUP
, &task_setup_data
.rpc_client
, &msg
);
6425 /* Ensure this is an unlock - when canceling a lock, the
6426 * canceled lock is passed in, and it won't be an unlock.
6428 fl
->fl_type
= F_UNLCK
;
6429 if (fl
->fl_flags
& FL_CLOSE
)
6430 set_bit(NFS_CONTEXT_UNLOCK
, &ctx
->flags
);
6432 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
6434 nfs_free_seqid(seqid
);
6435 return ERR_PTR(-ENOMEM
);
6438 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1, 0);
6439 msg
.rpc_argp
= &data
->arg
;
6440 msg
.rpc_resp
= &data
->res
;
6441 task_setup_data
.callback_data
= data
;
6442 return rpc_run_task(&task_setup_data
);
6445 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6447 struct inode
*inode
= state
->inode
;
6448 struct nfs4_state_owner
*sp
= state
->owner
;
6449 struct nfs_inode
*nfsi
= NFS_I(inode
);
6450 struct nfs_seqid
*seqid
;
6451 struct nfs4_lock_state
*lsp
;
6452 struct rpc_task
*task
;
6453 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
6455 unsigned char fl_flags
= request
->fl_flags
;
6457 status
= nfs4_set_lock_state(state
, request
);
6458 /* Unlock _before_ we do the RPC call */
6459 request
->fl_flags
|= FL_EXISTS
;
6460 /* Exclude nfs_delegation_claim_locks() */
6461 mutex_lock(&sp
->so_delegreturn_mutex
);
6462 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
6463 down_read(&nfsi
->rwsem
);
6464 if (locks_lock_inode_wait(inode
, request
) == -ENOENT
) {
6465 up_read(&nfsi
->rwsem
);
6466 mutex_unlock(&sp
->so_delegreturn_mutex
);
6469 up_read(&nfsi
->rwsem
);
6470 mutex_unlock(&sp
->so_delegreturn_mutex
);
6473 /* Is this a delegated lock? */
6474 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6475 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
6477 alloc_seqid
= NFS_SERVER(inode
)->nfs_client
->cl_mvops
->alloc_seqid
;
6478 seqid
= alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
6482 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
6483 status
= PTR_ERR(task
);
6486 status
= rpc_wait_for_completion_task(task
);
6489 request
->fl_flags
= fl_flags
;
6490 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
6494 struct nfs4_lockdata
{
6495 struct nfs_lock_args arg
;
6496 struct nfs_lock_res res
;
6497 struct nfs4_lock_state
*lsp
;
6498 struct nfs_open_context
*ctx
;
6499 struct file_lock fl
;
6500 unsigned long timestamp
;
6503 struct nfs_server
*server
;
6506 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
6507 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
6510 struct nfs4_lockdata
*p
;
6511 struct inode
*inode
= lsp
->ls_state
->inode
;
6512 struct nfs_server
*server
= NFS_SERVER(inode
);
6513 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
6515 p
= kzalloc(sizeof(*p
), gfp_mask
);
6519 p
->arg
.fh
= NFS_FH(inode
);
6521 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
6522 if (IS_ERR(p
->arg
.open_seqid
))
6524 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
6525 p
->arg
.lock_seqid
= alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
6526 if (IS_ERR(p
->arg
.lock_seqid
))
6527 goto out_free_seqid
;
6528 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
6529 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6530 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
6531 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
6534 refcount_inc(&lsp
->ls_count
);
6535 p
->ctx
= get_nfs_open_context(ctx
);
6536 locks_init_lock(&p
->fl
);
6537 locks_copy_lock(&p
->fl
, fl
);
6540 nfs_free_seqid(p
->arg
.open_seqid
);
6546 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
6548 struct nfs4_lockdata
*data
= calldata
;
6549 struct nfs4_state
*state
= data
->lsp
->ls_state
;
6551 dprintk("%s: begin!\n", __func__
);
6552 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
6554 /* Do we need to do an open_to_lock_owner? */
6555 if (!test_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
)) {
6556 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
6557 goto out_release_lock_seqid
;
6559 nfs4_stateid_copy(&data
->arg
.open_stateid
,
6560 &state
->open_stateid
);
6561 data
->arg
.new_lock_owner
= 1;
6562 data
->res
.open_seqid
= data
->arg
.open_seqid
;
6564 data
->arg
.new_lock_owner
= 0;
6565 nfs4_stateid_copy(&data
->arg
.lock_stateid
,
6566 &data
->lsp
->ls_stateid
);
6568 if (!nfs4_valid_open_stateid(state
)) {
6569 data
->rpc_status
= -EBADF
;
6570 task
->tk_action
= NULL
;
6571 goto out_release_open_seqid
;
6573 data
->timestamp
= jiffies
;
6574 if (nfs4_setup_sequence(data
->server
->nfs_client
,
6575 &data
->arg
.seq_args
,
6579 out_release_open_seqid
:
6580 nfs_release_seqid(data
->arg
.open_seqid
);
6581 out_release_lock_seqid
:
6582 nfs_release_seqid(data
->arg
.lock_seqid
);
6584 nfs4_sequence_done(task
, &data
->res
.seq_res
);
6585 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
6588 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
6590 struct nfs4_lockdata
*data
= calldata
;
6591 struct nfs4_lock_state
*lsp
= data
->lsp
;
6593 dprintk("%s: begin!\n", __func__
);
6595 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
6598 data
->rpc_status
= task
->tk_status
;
6599 switch (task
->tk_status
) {
6601 renew_lease(NFS_SERVER(d_inode(data
->ctx
->dentry
)),
6603 if (data
->arg
.new_lock
&& !data
->cancelled
) {
6604 data
->fl
.fl_flags
&= ~(FL_SLEEP
| FL_ACCESS
);
6605 if (locks_lock_inode_wait(lsp
->ls_state
->inode
, &data
->fl
) < 0)
6608 if (data
->arg
.new_lock_owner
!= 0) {
6609 nfs_confirm_seqid(&lsp
->ls_seqid
, 0);
6610 nfs4_stateid_copy(&lsp
->ls_stateid
, &data
->res
.stateid
);
6611 set_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
6612 } else if (!nfs4_update_lock_stateid(lsp
, &data
->res
.stateid
))
6615 case -NFS4ERR_BAD_STATEID
:
6616 case -NFS4ERR_OLD_STATEID
:
6617 case -NFS4ERR_STALE_STATEID
:
6618 case -NFS4ERR_EXPIRED
:
6619 if (data
->arg
.new_lock_owner
!= 0) {
6620 if (!nfs4_stateid_match(&data
->arg
.open_stateid
,
6621 &lsp
->ls_state
->open_stateid
))
6623 } else if (!nfs4_stateid_match(&data
->arg
.lock_stateid
,
6628 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
6631 if (!data
->cancelled
)
6632 rpc_restart_call_prepare(task
);
6636 static void nfs4_lock_release(void *calldata
)
6638 struct nfs4_lockdata
*data
= calldata
;
6640 dprintk("%s: begin!\n", __func__
);
6641 nfs_free_seqid(data
->arg
.open_seqid
);
6642 if (data
->cancelled
&& data
->rpc_status
== 0) {
6643 struct rpc_task
*task
;
6644 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
6645 data
->arg
.lock_seqid
);
6647 rpc_put_task_async(task
);
6648 dprintk("%s: cancelling lock!\n", __func__
);
6650 nfs_free_seqid(data
->arg
.lock_seqid
);
6651 nfs4_put_lock_state(data
->lsp
);
6652 put_nfs_open_context(data
->ctx
);
6654 dprintk("%s: done!\n", __func__
);
6657 static const struct rpc_call_ops nfs4_lock_ops
= {
6658 .rpc_call_prepare
= nfs4_lock_prepare
,
6659 .rpc_call_done
= nfs4_lock_done
,
6660 .rpc_release
= nfs4_lock_release
,
6663 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
6666 case -NFS4ERR_ADMIN_REVOKED
:
6667 case -NFS4ERR_EXPIRED
:
6668 case -NFS4ERR_BAD_STATEID
:
6669 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
6670 if (new_lock_owner
!= 0 ||
6671 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
6672 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
6674 case -NFS4ERR_STALE_STATEID
:
6675 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
6676 nfs4_schedule_lease_recovery(server
->nfs_client
);
6680 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
6682 struct nfs4_lockdata
*data
;
6683 struct rpc_task
*task
;
6684 struct rpc_message msg
= {
6685 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
6686 .rpc_cred
= state
->owner
->so_cred
,
6688 struct rpc_task_setup task_setup_data
= {
6689 .rpc_client
= NFS_CLIENT(state
->inode
),
6690 .rpc_message
= &msg
,
6691 .callback_ops
= &nfs4_lock_ops
,
6692 .workqueue
= nfsiod_workqueue
,
6693 .flags
= RPC_TASK_ASYNC
,
6697 dprintk("%s: begin!\n", __func__
);
6698 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
6699 fl
->fl_u
.nfs4_fl
.owner
,
6700 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
6704 data
->arg
.block
= 1;
6705 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1,
6706 recovery_type
> NFS_LOCK_NEW
);
6707 msg
.rpc_argp
= &data
->arg
;
6708 msg
.rpc_resp
= &data
->res
;
6709 task_setup_data
.callback_data
= data
;
6710 if (recovery_type
> NFS_LOCK_NEW
) {
6711 if (recovery_type
== NFS_LOCK_RECLAIM
)
6712 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
6714 data
->arg
.new_lock
= 1;
6715 task
= rpc_run_task(&task_setup_data
);
6717 return PTR_ERR(task
);
6718 ret
= rpc_wait_for_completion_task(task
);
6720 ret
= data
->rpc_status
;
6722 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
6723 data
->arg
.new_lock_owner
, ret
);
6725 data
->cancelled
= true;
6727 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
6728 trace_nfs4_set_lock(fl
, state
, &data
->res
.stateid
, cmd
, ret
);
6732 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
6734 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6735 struct nfs4_exception exception
= {
6736 .inode
= state
->inode
,
6741 /* Cache the lock if possible... */
6742 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
6744 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
6745 if (err
!= -NFS4ERR_DELAY
)
6747 nfs4_handle_exception(server
, err
, &exception
);
6748 } while (exception
.retry
);
6752 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
6754 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6755 struct nfs4_exception exception
= {
6756 .inode
= state
->inode
,
6760 err
= nfs4_set_lock_state(state
, request
);
6763 if (!recover_lost_locks
) {
6764 set_bit(NFS_LOCK_LOST
, &request
->fl_u
.nfs4_fl
.owner
->ls_flags
);
6768 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
6770 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
6774 case -NFS4ERR_GRACE
:
6775 case -NFS4ERR_DELAY
:
6776 nfs4_handle_exception(server
, err
, &exception
);
6779 } while (exception
.retry
);
6784 #if defined(CONFIG_NFS_V4_1)
6785 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
6787 struct nfs4_lock_state
*lsp
;
6790 status
= nfs4_set_lock_state(state
, request
);
6793 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6794 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) ||
6795 test_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
))
6797 return nfs4_lock_expired(state
, request
);
6801 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6803 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
6804 struct nfs4_state_owner
*sp
= state
->owner
;
6805 unsigned char fl_flags
= request
->fl_flags
;
6808 request
->fl_flags
|= FL_ACCESS
;
6809 status
= locks_lock_inode_wait(state
->inode
, request
);
6812 mutex_lock(&sp
->so_delegreturn_mutex
);
6813 down_read(&nfsi
->rwsem
);
6814 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
6815 /* Yes: cache locks! */
6816 /* ...but avoid races with delegation recall... */
6817 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
6818 status
= locks_lock_inode_wait(state
->inode
, request
);
6819 up_read(&nfsi
->rwsem
);
6820 mutex_unlock(&sp
->so_delegreturn_mutex
);
6823 up_read(&nfsi
->rwsem
);
6824 mutex_unlock(&sp
->so_delegreturn_mutex
);
6825 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
6827 request
->fl_flags
= fl_flags
;
6831 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6833 struct nfs4_exception exception
= {
6835 .inode
= state
->inode
,
6840 err
= _nfs4_proc_setlk(state
, cmd
, request
);
6841 if (err
== -NFS4ERR_DENIED
)
6843 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
6845 } while (exception
.retry
);
6849 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
6850 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
6853 nfs4_retry_setlk_simple(struct nfs4_state
*state
, int cmd
,
6854 struct file_lock
*request
)
6856 int status
= -ERESTARTSYS
;
6857 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
6859 while(!signalled()) {
6860 status
= nfs4_proc_setlk(state
, cmd
, request
);
6861 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
6863 freezable_schedule_timeout_interruptible(timeout
);
6865 timeout
= min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT
, timeout
);
6866 status
= -ERESTARTSYS
;
6871 #ifdef CONFIG_NFS_V4_1
6872 struct nfs4_lock_waiter
{
6873 struct task_struct
*task
;
6874 struct inode
*inode
;
6875 struct nfs_lowner
*owner
;
6880 nfs4_wake_lock_waiter(wait_queue_entry_t
*wait
, unsigned int mode
, int flags
, void *key
)
6883 struct nfs4_lock_waiter
*waiter
= wait
->private;
6885 /* NULL key means to wake up everyone */
6887 struct cb_notify_lock_args
*cbnl
= key
;
6888 struct nfs_lowner
*lowner
= &cbnl
->cbnl_owner
,
6889 *wowner
= waiter
->owner
;
6891 /* Only wake if the callback was for the same owner. */
6892 if (lowner
->id
!= wowner
->id
|| lowner
->s_dev
!= wowner
->s_dev
)
6895 /* Make sure it's for the right inode */
6896 if (nfs_compare_fh(NFS_FH(waiter
->inode
), &cbnl
->cbnl_fh
))
6899 waiter
->notified
= true;
6902 /* override "private" so we can use default_wake_function */
6903 wait
->private = waiter
->task
;
6904 ret
= autoremove_wake_function(wait
, mode
, flags
, key
);
6905 wait
->private = waiter
;
6910 nfs4_retry_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6912 int status
= -ERESTARTSYS
;
6913 unsigned long flags
;
6914 struct nfs4_lock_state
*lsp
= request
->fl_u
.nfs4_fl
.owner
;
6915 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6916 struct nfs_client
*clp
= server
->nfs_client
;
6917 wait_queue_head_t
*q
= &clp
->cl_lock_waitq
;
6918 struct nfs_lowner owner
= { .clientid
= clp
->cl_clientid
,
6919 .id
= lsp
->ls_seqid
.owner_id
,
6920 .s_dev
= server
->s_dev
};
6921 struct nfs4_lock_waiter waiter
= { .task
= current
,
6922 .inode
= state
->inode
,
6924 .notified
= false };
6925 wait_queue_entry_t wait
;
6927 /* Don't bother with waitqueue if we don't expect a callback */
6928 if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK
, &state
->flags
))
6929 return nfs4_retry_setlk_simple(state
, cmd
, request
);
6932 wait
.private = &waiter
;
6933 wait
.func
= nfs4_wake_lock_waiter
;
6934 add_wait_queue(q
, &wait
);
6936 while(!signalled()) {
6937 waiter
.notified
= false;
6938 status
= nfs4_proc_setlk(state
, cmd
, request
);
6939 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
6942 status
= -ERESTARTSYS
;
6943 spin_lock_irqsave(&q
->lock
, flags
);
6944 if (waiter
.notified
) {
6945 spin_unlock_irqrestore(&q
->lock
, flags
);
6948 set_current_state(TASK_INTERRUPTIBLE
);
6949 spin_unlock_irqrestore(&q
->lock
, flags
);
6951 freezable_schedule_timeout(NFS4_LOCK_MAXTIMEOUT
);
6954 finish_wait(q
, &wait
);
6957 #else /* !CONFIG_NFS_V4_1 */
6959 nfs4_retry_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6961 return nfs4_retry_setlk_simple(state
, cmd
, request
);
6966 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
6968 struct nfs_open_context
*ctx
;
6969 struct nfs4_state
*state
;
6972 /* verify open state */
6973 ctx
= nfs_file_open_context(filp
);
6976 if (IS_GETLK(cmd
)) {
6978 return nfs4_proc_getlk(state
, F_GETLK
, request
);
6982 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
6985 if (request
->fl_type
== F_UNLCK
) {
6987 return nfs4_proc_unlck(state
, cmd
, request
);
6994 if ((request
->fl_flags
& FL_POSIX
) &&
6995 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
6999 * Don't rely on the VFS having checked the file open mode,
7000 * since it won't do this for flock() locks.
7002 switch (request
->fl_type
) {
7004 if (!(filp
->f_mode
& FMODE_READ
))
7008 if (!(filp
->f_mode
& FMODE_WRITE
))
7012 status
= nfs4_set_lock_state(state
, request
);
7016 return nfs4_retry_setlk(state
, cmd
, request
);
7019 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
7021 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
7024 err
= nfs4_set_lock_state(state
, fl
);
7027 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
7028 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, fl
, err
);
7031 struct nfs_release_lockowner_data
{
7032 struct nfs4_lock_state
*lsp
;
7033 struct nfs_server
*server
;
7034 struct nfs_release_lockowner_args args
;
7035 struct nfs_release_lockowner_res res
;
7036 unsigned long timestamp
;
7039 static void nfs4_release_lockowner_prepare(struct rpc_task
*task
, void *calldata
)
7041 struct nfs_release_lockowner_data
*data
= calldata
;
7042 struct nfs_server
*server
= data
->server
;
7043 nfs4_setup_sequence(server
->nfs_client
, &data
->args
.seq_args
,
7044 &data
->res
.seq_res
, task
);
7045 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
7046 data
->timestamp
= jiffies
;
7049 static void nfs4_release_lockowner_done(struct rpc_task
*task
, void *calldata
)
7051 struct nfs_release_lockowner_data
*data
= calldata
;
7052 struct nfs_server
*server
= data
->server
;
7054 nfs40_sequence_done(task
, &data
->res
.seq_res
);
7056 switch (task
->tk_status
) {
7058 renew_lease(server
, data
->timestamp
);
7060 case -NFS4ERR_STALE_CLIENTID
:
7061 case -NFS4ERR_EXPIRED
:
7062 nfs4_schedule_lease_recovery(server
->nfs_client
);
7064 case -NFS4ERR_LEASE_MOVED
:
7065 case -NFS4ERR_DELAY
:
7066 if (nfs4_async_handle_error(task
, server
,
7067 NULL
, NULL
) == -EAGAIN
)
7068 rpc_restart_call_prepare(task
);
7072 static void nfs4_release_lockowner_release(void *calldata
)
7074 struct nfs_release_lockowner_data
*data
= calldata
;
7075 nfs4_free_lock_state(data
->server
, data
->lsp
);
7079 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
7080 .rpc_call_prepare
= nfs4_release_lockowner_prepare
,
7081 .rpc_call_done
= nfs4_release_lockowner_done
,
7082 .rpc_release
= nfs4_release_lockowner_release
,
7086 nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
7088 struct nfs_release_lockowner_data
*data
;
7089 struct rpc_message msg
= {
7090 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
7093 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
7096 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
7100 data
->server
= server
;
7101 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
7102 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
7103 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
7105 msg
.rpc_argp
= &data
->args
;
7106 msg
.rpc_resp
= &data
->res
;
7107 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0, 0);
7108 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
7111 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
7113 static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler
*handler
,
7114 struct dentry
*unused
, struct inode
*inode
,
7115 const char *key
, const void *buf
,
7116 size_t buflen
, int flags
)
7118 return nfs4_proc_set_acl(inode
, buf
, buflen
);
7121 static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler
*handler
,
7122 struct dentry
*unused
, struct inode
*inode
,
7123 const char *key
, void *buf
, size_t buflen
)
7125 return nfs4_proc_get_acl(inode
, buf
, buflen
);
7128 static bool nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
)
7130 return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry
)));
7133 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7135 static int nfs4_xattr_set_nfs4_label(const struct xattr_handler
*handler
,
7136 struct dentry
*unused
, struct inode
*inode
,
7137 const char *key
, const void *buf
,
7138 size_t buflen
, int flags
)
7140 if (security_ismaclabel(key
))
7141 return nfs4_set_security_label(inode
, buf
, buflen
);
7146 static int nfs4_xattr_get_nfs4_label(const struct xattr_handler
*handler
,
7147 struct dentry
*unused
, struct inode
*inode
,
7148 const char *key
, void *buf
, size_t buflen
)
7150 if (security_ismaclabel(key
))
7151 return nfs4_get_security_label(inode
, buf
, buflen
);
7156 nfs4_listxattr_nfs4_label(struct inode
*inode
, char *list
, size_t list_len
)
7160 if (nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
)) {
7161 len
= security_inode_listsecurity(inode
, list
, list_len
);
7162 if (list_len
&& len
> list_len
)
7168 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
7169 .prefix
= XATTR_SECURITY_PREFIX
,
7170 .get
= nfs4_xattr_get_nfs4_label
,
7171 .set
= nfs4_xattr_set_nfs4_label
,
7177 nfs4_listxattr_nfs4_label(struct inode
*inode
, char *list
, size_t list_len
)
7185 * nfs_fhget will use either the mounted_on_fileid or the fileid
7187 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
7189 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
7190 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
7191 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
7192 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
7195 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
7196 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
7197 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
7201 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
7202 const struct qstr
*name
,
7203 struct nfs4_fs_locations
*fs_locations
,
7206 struct nfs_server
*server
= NFS_SERVER(dir
);
7208 struct nfs4_fs_locations_arg args
= {
7209 .dir_fh
= NFS_FH(dir
),
7214 struct nfs4_fs_locations_res res
= {
7215 .fs_locations
= fs_locations
,
7217 struct rpc_message msg
= {
7218 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7224 dprintk("%s: start\n", __func__
);
7226 bitmask
[0] = nfs4_fattr_bitmap
[0] | FATTR4_WORD0_FS_LOCATIONS
;
7227 bitmask
[1] = nfs4_fattr_bitmap
[1];
7229 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
7230 * is not supported */
7231 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
7232 bitmask
[0] &= ~FATTR4_WORD0_FILEID
;
7234 bitmask
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
7236 nfs_fattr_init(&fs_locations
->fattr
);
7237 fs_locations
->server
= server
;
7238 fs_locations
->nlocations
= 0;
7239 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7240 dprintk("%s: returned status = %d\n", __func__
, status
);
7244 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
7245 const struct qstr
*name
,
7246 struct nfs4_fs_locations
*fs_locations
,
7249 struct nfs4_exception exception
= { };
7252 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
7253 fs_locations
, page
);
7254 trace_nfs4_get_fs_locations(dir
, name
, err
);
7255 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
7257 } while (exception
.retry
);
7262 * This operation also signals the server that this client is
7263 * performing migration recovery. The server can stop returning
7264 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
7265 * appended to this compound to identify the client ID which is
7266 * performing recovery.
7268 static int _nfs40_proc_get_locations(struct inode
*inode
,
7269 struct nfs4_fs_locations
*locations
,
7270 struct page
*page
, const struct cred
*cred
)
7272 struct nfs_server
*server
= NFS_SERVER(inode
);
7273 struct rpc_clnt
*clnt
= server
->client
;
7275 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
7277 struct nfs4_fs_locations_arg args
= {
7278 .clientid
= server
->nfs_client
->cl_clientid
,
7279 .fh
= NFS_FH(inode
),
7282 .migration
= 1, /* skip LOOKUP */
7283 .renew
= 1, /* append RENEW */
7285 struct nfs4_fs_locations_res res
= {
7286 .fs_locations
= locations
,
7290 struct rpc_message msg
= {
7291 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7296 unsigned long now
= jiffies
;
7299 nfs_fattr_init(&locations
->fattr
);
7300 locations
->server
= server
;
7301 locations
->nlocations
= 0;
7303 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7304 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7305 &args
.seq_args
, &res
.seq_res
);
7309 renew_lease(server
, now
);
7313 #ifdef CONFIG_NFS_V4_1
7316 * This operation also signals the server that this client is
7317 * performing migration recovery. The server can stop asserting
7318 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
7319 * performing this operation is identified in the SEQUENCE
7320 * operation in this compound.
7322 * When the client supports GETATTR(fs_locations_info), it can
7323 * be plumbed in here.
7325 static int _nfs41_proc_get_locations(struct inode
*inode
,
7326 struct nfs4_fs_locations
*locations
,
7327 struct page
*page
, const struct cred
*cred
)
7329 struct nfs_server
*server
= NFS_SERVER(inode
);
7330 struct rpc_clnt
*clnt
= server
->client
;
7332 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
7334 struct nfs4_fs_locations_arg args
= {
7335 .fh
= NFS_FH(inode
),
7338 .migration
= 1, /* skip LOOKUP */
7340 struct nfs4_fs_locations_res res
= {
7341 .fs_locations
= locations
,
7344 struct rpc_message msg
= {
7345 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7352 nfs_fattr_init(&locations
->fattr
);
7353 locations
->server
= server
;
7354 locations
->nlocations
= 0;
7356 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7357 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7358 &args
.seq_args
, &res
.seq_res
);
7359 if (status
== NFS4_OK
&&
7360 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
7361 status
= -NFS4ERR_LEASE_MOVED
;
7365 #endif /* CONFIG_NFS_V4_1 */
7368 * nfs4_proc_get_locations - discover locations for a migrated FSID
7369 * @inode: inode on FSID that is migrating
7370 * @locations: result of query
7372 * @cred: credential to use for this operation
7374 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
7375 * operation failed, or a negative errno if a local error occurred.
7377 * On success, "locations" is filled in, but if the server has
7378 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
7381 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
7382 * from this client that require migration recovery.
7384 int nfs4_proc_get_locations(struct inode
*inode
,
7385 struct nfs4_fs_locations
*locations
,
7386 struct page
*page
, const struct cred
*cred
)
7388 struct nfs_server
*server
= NFS_SERVER(inode
);
7389 struct nfs_client
*clp
= server
->nfs_client
;
7390 const struct nfs4_mig_recovery_ops
*ops
=
7391 clp
->cl_mvops
->mig_recovery_ops
;
7392 struct nfs4_exception exception
= { };
7395 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
7396 (unsigned long long)server
->fsid
.major
,
7397 (unsigned long long)server
->fsid
.minor
,
7399 nfs_display_fhandle(NFS_FH(inode
), __func__
);
7402 status
= ops
->get_locations(inode
, locations
, page
, cred
);
7403 if (status
!= -NFS4ERR_DELAY
)
7405 nfs4_handle_exception(server
, status
, &exception
);
7406 } while (exception
.retry
);
7411 * This operation also signals the server that this client is
7412 * performing "lease moved" recovery. The server can stop
7413 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
7414 * is appended to this compound to identify the client ID which is
7415 * performing recovery.
7417 static int _nfs40_proc_fsid_present(struct inode
*inode
, const struct cred
*cred
)
7419 struct nfs_server
*server
= NFS_SERVER(inode
);
7420 struct nfs_client
*clp
= NFS_SERVER(inode
)->nfs_client
;
7421 struct rpc_clnt
*clnt
= server
->client
;
7422 struct nfs4_fsid_present_arg args
= {
7423 .fh
= NFS_FH(inode
),
7424 .clientid
= clp
->cl_clientid
,
7425 .renew
= 1, /* append RENEW */
7427 struct nfs4_fsid_present_res res
= {
7430 struct rpc_message msg
= {
7431 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
7436 unsigned long now
= jiffies
;
7439 res
.fh
= nfs_alloc_fhandle();
7443 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7444 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7445 &args
.seq_args
, &res
.seq_res
);
7446 nfs_free_fhandle(res
.fh
);
7450 do_renew_lease(clp
, now
);
7454 #ifdef CONFIG_NFS_V4_1
7457 * This operation also signals the server that this client is
7458 * performing "lease moved" recovery. The server can stop asserting
7459 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
7460 * this operation is identified in the SEQUENCE operation in this
7463 static int _nfs41_proc_fsid_present(struct inode
*inode
, const struct cred
*cred
)
7465 struct nfs_server
*server
= NFS_SERVER(inode
);
7466 struct rpc_clnt
*clnt
= server
->client
;
7467 struct nfs4_fsid_present_arg args
= {
7468 .fh
= NFS_FH(inode
),
7470 struct nfs4_fsid_present_res res
= {
7472 struct rpc_message msg
= {
7473 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
7480 res
.fh
= nfs_alloc_fhandle();
7484 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7485 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7486 &args
.seq_args
, &res
.seq_res
);
7487 nfs_free_fhandle(res
.fh
);
7488 if (status
== NFS4_OK
&&
7489 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
7490 status
= -NFS4ERR_LEASE_MOVED
;
7494 #endif /* CONFIG_NFS_V4_1 */
7497 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
7498 * @inode: inode on FSID to check
7499 * @cred: credential to use for this operation
7501 * Server indicates whether the FSID is present, moved, or not
7502 * recognized. This operation is necessary to clear a LEASE_MOVED
7503 * condition for this client ID.
7505 * Returns NFS4_OK if the FSID is present on this server,
7506 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
7507 * NFS4ERR code if some error occurred on the server, or a
7508 * negative errno if a local failure occurred.
7510 int nfs4_proc_fsid_present(struct inode
*inode
, const struct cred
*cred
)
7512 struct nfs_server
*server
= NFS_SERVER(inode
);
7513 struct nfs_client
*clp
= server
->nfs_client
;
7514 const struct nfs4_mig_recovery_ops
*ops
=
7515 clp
->cl_mvops
->mig_recovery_ops
;
7516 struct nfs4_exception exception
= { };
7519 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
7520 (unsigned long long)server
->fsid
.major
,
7521 (unsigned long long)server
->fsid
.minor
,
7523 nfs_display_fhandle(NFS_FH(inode
), __func__
);
7526 status
= ops
->fsid_present(inode
, cred
);
7527 if (status
!= -NFS4ERR_DELAY
)
7529 nfs4_handle_exception(server
, status
, &exception
);
7530 } while (exception
.retry
);
7535 * If 'use_integrity' is true and the state managment nfs_client
7536 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
7537 * and the machine credential as per RFC3530bis and RFC5661 Security
7538 * Considerations sections. Otherwise, just use the user cred with the
7539 * filesystem's rpc_client.
7541 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
7544 struct nfs4_secinfo_arg args
= {
7545 .dir_fh
= NFS_FH(dir
),
7548 struct nfs4_secinfo_res res
= {
7551 struct rpc_message msg
= {
7552 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
7556 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
7557 const struct cred
*cred
= NULL
;
7559 if (use_integrity
) {
7560 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
7561 cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
7562 msg
.rpc_cred
= cred
;
7565 dprintk("NFS call secinfo %s\n", name
->name
);
7567 nfs4_state_protect(NFS_SERVER(dir
)->nfs_client
,
7568 NFS_SP4_MACH_CRED_SECINFO
, &clnt
, &msg
);
7570 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
7572 dprintk("NFS reply secinfo: %d\n", status
);
7579 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
7580 struct nfs4_secinfo_flavors
*flavors
)
7582 struct nfs4_exception exception
= { };
7585 err
= -NFS4ERR_WRONGSEC
;
7587 /* try to use integrity protection with machine cred */
7588 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
7589 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
7592 * if unable to use integrity protection, or SECINFO with
7593 * integrity protection returns NFS4ERR_WRONGSEC (which is
7594 * disallowed by spec, but exists in deployed servers) use
7595 * the current filesystem's rpc_client and the user cred.
7597 if (err
== -NFS4ERR_WRONGSEC
)
7598 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
7600 trace_nfs4_secinfo(dir
, name
, err
);
7601 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
7603 } while (exception
.retry
);
7607 #ifdef CONFIG_NFS_V4_1
7609 * Check the exchange flags returned by the server for invalid flags, having
7610 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
7613 static int nfs4_check_cl_exchange_flags(u32 flags
)
7615 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
7617 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
7618 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
7620 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
7624 return -NFS4ERR_INVAL
;
7628 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
7629 struct nfs41_server_scope
*b
)
7631 if (a
->server_scope_sz
!= b
->server_scope_sz
)
7633 return memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0;
7637 nfs4_bind_one_conn_to_session_done(struct rpc_task
*task
, void *calldata
)
7641 static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops
= {
7642 .rpc_call_done
= &nfs4_bind_one_conn_to_session_done
,
7646 * nfs4_proc_bind_one_conn_to_session()
7648 * The 4.1 client currently uses the same TCP connection for the
7649 * fore and backchannel.
7652 int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt
*clnt
,
7653 struct rpc_xprt
*xprt
,
7654 struct nfs_client
*clp
,
7655 const struct cred
*cred
)
7658 struct nfs41_bind_conn_to_session_args args
= {
7660 .dir
= NFS4_CDFC4_FORE_OR_BOTH
,
7662 struct nfs41_bind_conn_to_session_res res
;
7663 struct rpc_message msg
= {
7665 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
7670 struct rpc_task_setup task_setup_data
= {
7673 .callback_ops
= &nfs4_bind_one_conn_to_session_ops
,
7674 .rpc_message
= &msg
,
7675 .flags
= RPC_TASK_TIMEOUT
,
7677 struct rpc_task
*task
;
7679 nfs4_copy_sessionid(&args
.sessionid
, &clp
->cl_session
->sess_id
);
7680 if (!(clp
->cl_session
->flags
& SESSION4_BACK_CHAN
))
7681 args
.dir
= NFS4_CDFC4_FORE
;
7683 /* Do not set the backchannel flag unless this is clnt->cl_xprt */
7684 if (xprt
!= rcu_access_pointer(clnt
->cl_xprt
))
7685 args
.dir
= NFS4_CDFC4_FORE
;
7687 task
= rpc_run_task(&task_setup_data
);
7688 if (!IS_ERR(task
)) {
7689 status
= task
->tk_status
;
7692 status
= PTR_ERR(task
);
7693 trace_nfs4_bind_conn_to_session(clp
, status
);
7695 if (memcmp(res
.sessionid
.data
,
7696 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
7697 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
7700 if ((res
.dir
& args
.dir
) != res
.dir
|| res
.dir
== 0) {
7701 dprintk("NFS: %s: Unexpected direction from server\n",
7705 if (res
.use_conn_in_rdma_mode
!= args
.use_conn_in_rdma_mode
) {
7706 dprintk("NFS: %s: Server returned RDMA mode = true\n",
7715 struct rpc_bind_conn_calldata
{
7716 struct nfs_client
*clp
;
7717 const struct cred
*cred
;
7721 nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt
*clnt
,
7722 struct rpc_xprt
*xprt
,
7725 struct rpc_bind_conn_calldata
*p
= calldata
;
7727 return nfs4_proc_bind_one_conn_to_session(clnt
, xprt
, p
->clp
, p
->cred
);
7730 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, const struct cred
*cred
)
7732 struct rpc_bind_conn_calldata data
= {
7736 return rpc_clnt_iterate_for_each_xprt(clp
->cl_rpcclient
,
7737 nfs4_proc_bind_conn_to_session_callback
, &data
);
7741 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
7742 * and operations we'd like to see to enable certain features in the allow map
7744 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request
= {
7745 .how
= SP4_MACH_CRED
,
7746 .enforce
.u
.words
= {
7747 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
7748 1 << (OP_EXCHANGE_ID
- 32) |
7749 1 << (OP_CREATE_SESSION
- 32) |
7750 1 << (OP_DESTROY_SESSION
- 32) |
7751 1 << (OP_DESTROY_CLIENTID
- 32)
7754 [0] = 1 << (OP_CLOSE
) |
7755 1 << (OP_OPEN_DOWNGRADE
) |
7757 1 << (OP_DELEGRETURN
) |
7759 [1] = 1 << (OP_SECINFO
- 32) |
7760 1 << (OP_SECINFO_NO_NAME
- 32) |
7761 1 << (OP_LAYOUTRETURN
- 32) |
7762 1 << (OP_TEST_STATEID
- 32) |
7763 1 << (OP_FREE_STATEID
- 32) |
7764 1 << (OP_WRITE
- 32)
7769 * Select the state protection mode for client `clp' given the server results
7770 * from exchange_id in `sp'.
7772 * Returns 0 on success, negative errno otherwise.
7774 static int nfs4_sp4_select_mode(struct nfs_client
*clp
,
7775 struct nfs41_state_protection
*sp
)
7777 static const u32 supported_enforce
[NFS4_OP_MAP_NUM_WORDS
] = {
7778 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
7779 1 << (OP_EXCHANGE_ID
- 32) |
7780 1 << (OP_CREATE_SESSION
- 32) |
7781 1 << (OP_DESTROY_SESSION
- 32) |
7782 1 << (OP_DESTROY_CLIENTID
- 32)
7784 unsigned long flags
= 0;
7788 if (sp
->how
== SP4_MACH_CRED
) {
7789 /* Print state protect result */
7790 dfprintk(MOUNT
, "Server SP4_MACH_CRED support:\n");
7791 for (i
= 0; i
<= LAST_NFS4_OP
; i
++) {
7792 if (test_bit(i
, sp
->enforce
.u
.longs
))
7793 dfprintk(MOUNT
, " enforce op %d\n", i
);
7794 if (test_bit(i
, sp
->allow
.u
.longs
))
7795 dfprintk(MOUNT
, " allow op %d\n", i
);
7798 /* make sure nothing is on enforce list that isn't supported */
7799 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++) {
7800 if (sp
->enforce
.u
.words
[i
] & ~supported_enforce
[i
]) {
7801 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
7808 * Minimal mode - state operations are allowed to use machine
7809 * credential. Note this already happens by default, so the
7810 * client doesn't have to do anything more than the negotiation.
7812 * NOTE: we don't care if EXCHANGE_ID is in the list -
7813 * we're already using the machine cred for exchange_id
7814 * and will never use a different cred.
7816 if (test_bit(OP_BIND_CONN_TO_SESSION
, sp
->enforce
.u
.longs
) &&
7817 test_bit(OP_CREATE_SESSION
, sp
->enforce
.u
.longs
) &&
7818 test_bit(OP_DESTROY_SESSION
, sp
->enforce
.u
.longs
) &&
7819 test_bit(OP_DESTROY_CLIENTID
, sp
->enforce
.u
.longs
)) {
7820 dfprintk(MOUNT
, "sp4_mach_cred:\n");
7821 dfprintk(MOUNT
, " minimal mode enabled\n");
7822 __set_bit(NFS_SP4_MACH_CRED_MINIMAL
, &flags
);
7824 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
7829 if (test_bit(OP_CLOSE
, sp
->allow
.u
.longs
) &&
7830 test_bit(OP_OPEN_DOWNGRADE
, sp
->allow
.u
.longs
) &&
7831 test_bit(OP_DELEGRETURN
, sp
->allow
.u
.longs
) &&
7832 test_bit(OP_LOCKU
, sp
->allow
.u
.longs
)) {
7833 dfprintk(MOUNT
, " cleanup mode enabled\n");
7834 __set_bit(NFS_SP4_MACH_CRED_CLEANUP
, &flags
);
7837 if (test_bit(OP_LAYOUTRETURN
, sp
->allow
.u
.longs
)) {
7838 dfprintk(MOUNT
, " pnfs cleanup mode enabled\n");
7839 __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP
, &flags
);
7842 if (test_bit(OP_SECINFO
, sp
->allow
.u
.longs
) &&
7843 test_bit(OP_SECINFO_NO_NAME
, sp
->allow
.u
.longs
)) {
7844 dfprintk(MOUNT
, " secinfo mode enabled\n");
7845 __set_bit(NFS_SP4_MACH_CRED_SECINFO
, &flags
);
7848 if (test_bit(OP_TEST_STATEID
, sp
->allow
.u
.longs
) &&
7849 test_bit(OP_FREE_STATEID
, sp
->allow
.u
.longs
)) {
7850 dfprintk(MOUNT
, " stateid mode enabled\n");
7851 __set_bit(NFS_SP4_MACH_CRED_STATEID
, &flags
);
7854 if (test_bit(OP_WRITE
, sp
->allow
.u
.longs
)) {
7855 dfprintk(MOUNT
, " write mode enabled\n");
7856 __set_bit(NFS_SP4_MACH_CRED_WRITE
, &flags
);
7859 if (test_bit(OP_COMMIT
, sp
->allow
.u
.longs
)) {
7860 dfprintk(MOUNT
, " commit mode enabled\n");
7861 __set_bit(NFS_SP4_MACH_CRED_COMMIT
, &flags
);
7865 clp
->cl_sp4_flags
= flags
;
7869 struct nfs41_exchange_id_data
{
7870 struct nfs41_exchange_id_res res
;
7871 struct nfs41_exchange_id_args args
;
7874 static void nfs4_exchange_id_release(void *data
)
7876 struct nfs41_exchange_id_data
*cdata
=
7877 (struct nfs41_exchange_id_data
*)data
;
7879 nfs_put_client(cdata
->args
.client
);
7880 kfree(cdata
->res
.impl_id
);
7881 kfree(cdata
->res
.server_scope
);
7882 kfree(cdata
->res
.server_owner
);
7886 static const struct rpc_call_ops nfs4_exchange_id_call_ops
= {
7887 .rpc_release
= nfs4_exchange_id_release
,
7891 * _nfs4_proc_exchange_id()
7893 * Wrapper for EXCHANGE_ID operation.
7895 static struct rpc_task
*
7896 nfs4_run_exchange_id(struct nfs_client
*clp
, const struct cred
*cred
,
7897 u32 sp4_how
, struct rpc_xprt
*xprt
)
7899 struct rpc_message msg
= {
7900 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
7903 struct rpc_task_setup task_setup_data
= {
7904 .rpc_client
= clp
->cl_rpcclient
,
7905 .callback_ops
= &nfs4_exchange_id_call_ops
,
7906 .rpc_message
= &msg
,
7907 .flags
= RPC_TASK_TIMEOUT
,
7909 struct nfs41_exchange_id_data
*calldata
;
7912 if (!refcount_inc_not_zero(&clp
->cl_count
))
7913 return ERR_PTR(-EIO
);
7916 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7920 nfs4_init_boot_verifier(clp
, &calldata
->args
.verifier
);
7922 status
= nfs4_init_uniform_client_string(clp
);
7926 calldata
->res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
7929 if (unlikely(calldata
->res
.server_owner
== NULL
))
7932 calldata
->res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
7934 if (unlikely(calldata
->res
.server_scope
== NULL
))
7935 goto out_server_owner
;
7937 calldata
->res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
7938 if (unlikely(calldata
->res
.impl_id
== NULL
))
7939 goto out_server_scope
;
7943 calldata
->args
.state_protect
.how
= SP4_NONE
;
7947 calldata
->args
.state_protect
= nfs4_sp4_mach_cred_request
;
7957 task_setup_data
.rpc_xprt
= xprt
;
7958 task_setup_data
.flags
|= RPC_TASK_SOFTCONN
;
7959 memcpy(calldata
->args
.verifier
.data
, clp
->cl_confirm
.data
,
7960 sizeof(calldata
->args
.verifier
.data
));
7962 calldata
->args
.client
= clp
;
7963 calldata
->args
.flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
7964 EXCHGID4_FLAG_BIND_PRINC_STATEID
;
7965 #ifdef CONFIG_NFS_V4_1_MIGRATION
7966 calldata
->args
.flags
|= EXCHGID4_FLAG_SUPP_MOVED_MIGR
;
7968 msg
.rpc_argp
= &calldata
->args
;
7969 msg
.rpc_resp
= &calldata
->res
;
7970 task_setup_data
.callback_data
= calldata
;
7972 return rpc_run_task(&task_setup_data
);
7975 kfree(calldata
->res
.impl_id
);
7977 kfree(calldata
->res
.server_scope
);
7979 kfree(calldata
->res
.server_owner
);
7983 nfs_put_client(clp
);
7984 return ERR_PTR(status
);
7988 * _nfs4_proc_exchange_id()
7990 * Wrapper for EXCHANGE_ID operation.
7992 static int _nfs4_proc_exchange_id(struct nfs_client
*clp
, const struct cred
*cred
,
7995 struct rpc_task
*task
;
7996 struct nfs41_exchange_id_args
*argp
;
7997 struct nfs41_exchange_id_res
*resp
;
8000 task
= nfs4_run_exchange_id(clp
, cred
, sp4_how
, NULL
);
8002 return PTR_ERR(task
);
8004 argp
= task
->tk_msg
.rpc_argp
;
8005 resp
= task
->tk_msg
.rpc_resp
;
8006 status
= task
->tk_status
;
8010 status
= nfs4_check_cl_exchange_flags(resp
->flags
);
8014 status
= nfs4_sp4_select_mode(clp
, &resp
->state_protect
);
8018 clp
->cl_clientid
= resp
->clientid
;
8019 clp
->cl_exchange_flags
= resp
->flags
;
8020 clp
->cl_seqid
= resp
->seqid
;
8021 /* Client ID is not confirmed */
8022 if (!(resp
->flags
& EXCHGID4_FLAG_CONFIRMED_R
))
8023 clear_bit(NFS4_SESSION_ESTABLISHED
,
8024 &clp
->cl_session
->session_state
);
8026 if (clp
->cl_serverscope
!= NULL
&&
8027 !nfs41_same_server_scope(clp
->cl_serverscope
,
8028 resp
->server_scope
)) {
8029 dprintk("%s: server_scope mismatch detected\n",
8031 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
8034 swap(clp
->cl_serverowner
, resp
->server_owner
);
8035 swap(clp
->cl_serverscope
, resp
->server_scope
);
8036 swap(clp
->cl_implid
, resp
->impl_id
);
8038 /* Save the EXCHANGE_ID verifier session trunk tests */
8039 memcpy(clp
->cl_confirm
.data
, argp
->verifier
.data
,
8040 sizeof(clp
->cl_confirm
.data
));
8042 trace_nfs4_exchange_id(clp
, status
);
8048 * nfs4_proc_exchange_id()
8050 * Returns zero, a negative errno, or a negative NFS4ERR status code.
8052 * Since the clientid has expired, all compounds using sessions
8053 * associated with the stale clientid will be returning
8054 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
8055 * be in some phase of session reset.
8057 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
8059 int nfs4_proc_exchange_id(struct nfs_client
*clp
, const struct cred
*cred
)
8061 rpc_authflavor_t authflavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
8064 /* try SP4_MACH_CRED if krb5i/p */
8065 if (authflavor
== RPC_AUTH_GSS_KRB5I
||
8066 authflavor
== RPC_AUTH_GSS_KRB5P
) {
8067 status
= _nfs4_proc_exchange_id(clp
, cred
, SP4_MACH_CRED
);
8073 return _nfs4_proc_exchange_id(clp
, cred
, SP4_NONE
);
8077 * nfs4_test_session_trunk
8079 * This is an add_xprt_test() test function called from
8080 * rpc_clnt_setup_test_and_add_xprt.
8082 * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt
8083 * and is dereferrenced in nfs4_exchange_id_release
8085 * Upon success, add the new transport to the rpc_clnt
8087 * @clnt: struct rpc_clnt to get new transport
8088 * @xprt: the rpc_xprt to test
8089 * @data: call data for _nfs4_proc_exchange_id.
8091 void nfs4_test_session_trunk(struct rpc_clnt
*clnt
, struct rpc_xprt
*xprt
,
8094 struct nfs4_add_xprt_data
*adata
= (struct nfs4_add_xprt_data
*)data
;
8095 struct rpc_task
*task
;
8100 dprintk("--> %s try %s\n", __func__
,
8101 xprt
->address_strings
[RPC_DISPLAY_ADDR
]);
8103 sp4_how
= (adata
->clp
->cl_sp4_flags
== 0 ? SP4_NONE
: SP4_MACH_CRED
);
8105 /* Test connection for session trunking. Async exchange_id call */
8106 task
= nfs4_run_exchange_id(adata
->clp
, adata
->cred
, sp4_how
, xprt
);
8110 status
= task
->tk_status
;
8112 status
= nfs4_detect_session_trunking(adata
->clp
,
8113 task
->tk_msg
.rpc_resp
, xprt
);
8116 rpc_clnt_xprt_switch_add_xprt(clnt
, xprt
);
8120 EXPORT_SYMBOL_GPL(nfs4_test_session_trunk
);
8122 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
8123 const struct cred
*cred
)
8125 struct rpc_message msg
= {
8126 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
8132 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8133 trace_nfs4_destroy_clientid(clp
, status
);
8135 dprintk("NFS: Got error %d from the server %s on "
8136 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
8140 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
8141 const struct cred
*cred
)
8146 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
8147 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
8149 case -NFS4ERR_DELAY
:
8150 case -NFS4ERR_CLIENTID_BUSY
:
8160 int nfs4_destroy_clientid(struct nfs_client
*clp
)
8162 const struct cred
*cred
;
8165 if (clp
->cl_mvops
->minor_version
< 1)
8167 if (clp
->cl_exchange_flags
== 0)
8169 if (clp
->cl_preserve_clid
)
8171 cred
= nfs4_get_clid_cred(clp
);
8172 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
8176 case -NFS4ERR_STALE_CLIENTID
:
8177 clp
->cl_exchange_flags
= 0;
8183 struct nfs4_get_lease_time_data
{
8184 struct nfs4_get_lease_time_args
*args
;
8185 struct nfs4_get_lease_time_res
*res
;
8186 struct nfs_client
*clp
;
8189 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
8192 struct nfs4_get_lease_time_data
*data
=
8193 (struct nfs4_get_lease_time_data
*)calldata
;
8195 dprintk("--> %s\n", __func__
);
8196 /* just setup sequence, do not trigger session recovery
8197 since we're invoked within one */
8198 nfs4_setup_sequence(data
->clp
,
8199 &data
->args
->la_seq_args
,
8200 &data
->res
->lr_seq_res
,
8202 dprintk("<-- %s\n", __func__
);
8206 * Called from nfs4_state_manager thread for session setup, so don't recover
8207 * from sequence operation or clientid errors.
8209 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
8211 struct nfs4_get_lease_time_data
*data
=
8212 (struct nfs4_get_lease_time_data
*)calldata
;
8214 dprintk("--> %s\n", __func__
);
8215 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
8217 switch (task
->tk_status
) {
8218 case -NFS4ERR_DELAY
:
8219 case -NFS4ERR_GRACE
:
8220 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
8221 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
8222 task
->tk_status
= 0;
8224 case -NFS4ERR_RETRY_UNCACHED_REP
:
8225 rpc_restart_call_prepare(task
);
8228 dprintk("<-- %s\n", __func__
);
8231 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
8232 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
8233 .rpc_call_done
= nfs4_get_lease_time_done
,
8236 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
8238 struct rpc_task
*task
;
8239 struct nfs4_get_lease_time_args args
;
8240 struct nfs4_get_lease_time_res res
= {
8241 .lr_fsinfo
= fsinfo
,
8243 struct nfs4_get_lease_time_data data
= {
8248 struct rpc_message msg
= {
8249 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
8253 struct rpc_task_setup task_setup
= {
8254 .rpc_client
= clp
->cl_rpcclient
,
8255 .rpc_message
= &msg
,
8256 .callback_ops
= &nfs4_get_lease_time_ops
,
8257 .callback_data
= &data
,
8258 .flags
= RPC_TASK_TIMEOUT
,
8262 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0, 1);
8263 task
= rpc_run_task(&task_setup
);
8266 return PTR_ERR(task
);
8268 status
= task
->tk_status
;
8274 * Initialize the values to be used by the client in CREATE_SESSION
8275 * If nfs4_init_session set the fore channel request and response sizes,
8278 * Set the back channel max_resp_sz_cached to zero to force the client to
8279 * always set csa_cachethis to FALSE because the current implementation
8280 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
8282 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
,
8283 struct rpc_clnt
*clnt
)
8285 unsigned int max_rqst_sz
, max_resp_sz
;
8286 unsigned int max_bc_payload
= rpc_max_bc_payload(clnt
);
8288 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
8289 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
8291 /* Fore channel attributes */
8292 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
8293 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
8294 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
8295 args
->fc_attrs
.max_reqs
= max_session_slots
;
8297 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
8298 "max_ops=%u max_reqs=%u\n",
8300 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
8301 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
8303 /* Back channel attributes */
8304 args
->bc_attrs
.max_rqst_sz
= max_bc_payload
;
8305 args
->bc_attrs
.max_resp_sz
= max_bc_payload
;
8306 args
->bc_attrs
.max_resp_sz_cached
= 0;
8307 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
8308 args
->bc_attrs
.max_reqs
= max_t(unsigned short, max_session_cb_slots
, 1);
8310 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
8311 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
8313 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
8314 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
8315 args
->bc_attrs
.max_reqs
);
8318 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
,
8319 struct nfs41_create_session_res
*res
)
8321 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
8322 struct nfs4_channel_attrs
*rcvd
= &res
->fc_attrs
;
8324 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
8327 * Our requested max_ops is the minimum we need; we're not
8328 * prepared to break up compounds into smaller pieces than that.
8329 * So, no point even trying to continue if the server won't
8332 if (rcvd
->max_ops
< sent
->max_ops
)
8334 if (rcvd
->max_reqs
== 0)
8336 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
8337 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
8341 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
,
8342 struct nfs41_create_session_res
*res
)
8344 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
8345 struct nfs4_channel_attrs
*rcvd
= &res
->bc_attrs
;
8347 if (!(res
->flags
& SESSION4_BACK_CHAN
))
8349 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
8351 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
8353 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
8355 if (rcvd
->max_ops
> sent
->max_ops
)
8357 if (rcvd
->max_reqs
> sent
->max_reqs
)
8363 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
8364 struct nfs41_create_session_res
*res
)
8368 ret
= nfs4_verify_fore_channel_attrs(args
, res
);
8371 return nfs4_verify_back_channel_attrs(args
, res
);
8374 static void nfs4_update_session(struct nfs4_session
*session
,
8375 struct nfs41_create_session_res
*res
)
8377 nfs4_copy_sessionid(&session
->sess_id
, &res
->sessionid
);
8378 /* Mark client id and session as being confirmed */
8379 session
->clp
->cl_exchange_flags
|= EXCHGID4_FLAG_CONFIRMED_R
;
8380 set_bit(NFS4_SESSION_ESTABLISHED
, &session
->session_state
);
8381 session
->flags
= res
->flags
;
8382 memcpy(&session
->fc_attrs
, &res
->fc_attrs
, sizeof(session
->fc_attrs
));
8383 if (res
->flags
& SESSION4_BACK_CHAN
)
8384 memcpy(&session
->bc_attrs
, &res
->bc_attrs
,
8385 sizeof(session
->bc_attrs
));
8388 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
8389 const struct cred
*cred
)
8391 struct nfs4_session
*session
= clp
->cl_session
;
8392 struct nfs41_create_session_args args
= {
8394 .clientid
= clp
->cl_clientid
,
8395 .seqid
= clp
->cl_seqid
,
8396 .cb_program
= NFS4_CALLBACK
,
8398 struct nfs41_create_session_res res
;
8400 struct rpc_message msg
= {
8401 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
8408 nfs4_init_channel_attrs(&args
, clp
->cl_rpcclient
);
8409 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
8411 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8412 trace_nfs4_create_session(clp
, status
);
8415 case -NFS4ERR_STALE_CLIENTID
:
8416 case -NFS4ERR_DELAY
:
8425 /* Verify the session's negotiated channel_attrs values */
8426 status
= nfs4_verify_channel_attrs(&args
, &res
);
8427 /* Increment the clientid slot sequence id */
8430 nfs4_update_session(session
, &res
);
8437 * Issues a CREATE_SESSION operation to the server.
8438 * It is the responsibility of the caller to verify the session is
8439 * expired before calling this routine.
8441 int nfs4_proc_create_session(struct nfs_client
*clp
, const struct cred
*cred
)
8445 struct nfs4_session
*session
= clp
->cl_session
;
8447 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
8449 status
= _nfs4_proc_create_session(clp
, cred
);
8453 /* Init or reset the session slot tables */
8454 status
= nfs4_setup_session_slot_tables(session
);
8455 dprintk("slot table setup returned %d\n", status
);
8459 ptr
= (unsigned *)&session
->sess_id
.data
[0];
8460 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
8461 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
8463 dprintk("<-- %s\n", __func__
);
8468 * Issue the over-the-wire RPC DESTROY_SESSION.
8469 * The caller must serialize access to this routine.
8471 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
8472 const struct cred
*cred
)
8474 struct rpc_message msg
= {
8475 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
8476 .rpc_argp
= session
,
8481 dprintk("--> nfs4_proc_destroy_session\n");
8483 /* session is still being setup */
8484 if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED
, &session
->session_state
))
8487 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8488 trace_nfs4_destroy_session(session
->clp
, status
);
8491 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
8492 "Session has been destroyed regardless...\n", status
);
8494 dprintk("<-- nfs4_proc_destroy_session\n");
8499 * Renew the cl_session lease.
8501 struct nfs4_sequence_data
{
8502 struct nfs_client
*clp
;
8503 struct nfs4_sequence_args args
;
8504 struct nfs4_sequence_res res
;
8507 static void nfs41_sequence_release(void *data
)
8509 struct nfs4_sequence_data
*calldata
= data
;
8510 struct nfs_client
*clp
= calldata
->clp
;
8512 if (refcount_read(&clp
->cl_count
) > 1)
8513 nfs4_schedule_state_renewal(clp
);
8514 nfs_put_client(clp
);
8518 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
8520 switch(task
->tk_status
) {
8521 case -NFS4ERR_DELAY
:
8522 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
8525 nfs4_schedule_lease_recovery(clp
);
8530 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
8532 struct nfs4_sequence_data
*calldata
= data
;
8533 struct nfs_client
*clp
= calldata
->clp
;
8535 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
8538 trace_nfs4_sequence(clp
, task
->tk_status
);
8539 if (task
->tk_status
< 0) {
8540 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
8541 if (refcount_read(&clp
->cl_count
) == 1)
8544 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
8545 rpc_restart_call_prepare(task
);
8549 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
8551 dprintk("<-- %s\n", __func__
);
8554 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
8556 struct nfs4_sequence_data
*calldata
= data
;
8557 struct nfs_client
*clp
= calldata
->clp
;
8558 struct nfs4_sequence_args
*args
;
8559 struct nfs4_sequence_res
*res
;
8561 args
= task
->tk_msg
.rpc_argp
;
8562 res
= task
->tk_msg
.rpc_resp
;
8564 nfs4_setup_sequence(clp
, args
, res
, task
);
8567 static const struct rpc_call_ops nfs41_sequence_ops
= {
8568 .rpc_call_done
= nfs41_sequence_call_done
,
8569 .rpc_call_prepare
= nfs41_sequence_prepare
,
8570 .rpc_release
= nfs41_sequence_release
,
8573 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
8574 const struct cred
*cred
,
8575 struct nfs4_slot
*slot
,
8578 struct nfs4_sequence_data
*calldata
;
8579 struct rpc_message msg
= {
8580 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
8583 struct rpc_task_setup task_setup_data
= {
8584 .rpc_client
= clp
->cl_rpcclient
,
8585 .rpc_message
= &msg
,
8586 .callback_ops
= &nfs41_sequence_ops
,
8587 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
8589 struct rpc_task
*ret
;
8591 ret
= ERR_PTR(-EIO
);
8592 if (!refcount_inc_not_zero(&clp
->cl_count
))
8595 ret
= ERR_PTR(-ENOMEM
);
8596 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
8597 if (calldata
== NULL
)
8599 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0, is_privileged
);
8600 nfs4_sequence_attach_slot(&calldata
->args
, &calldata
->res
, slot
);
8601 msg
.rpc_argp
= &calldata
->args
;
8602 msg
.rpc_resp
= &calldata
->res
;
8603 calldata
->clp
= clp
;
8604 task_setup_data
.callback_data
= calldata
;
8606 ret
= rpc_run_task(&task_setup_data
);
8611 nfs_put_client(clp
);
8613 nfs41_release_slot(slot
);
8617 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, const struct cred
*cred
, unsigned renew_flags
)
8619 struct rpc_task
*task
;
8622 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
8624 task
= _nfs41_proc_sequence(clp
, cred
, NULL
, false);
8626 ret
= PTR_ERR(task
);
8628 rpc_put_task_async(task
);
8629 dprintk("<-- %s status=%d\n", __func__
, ret
);
8633 static int nfs4_proc_sequence(struct nfs_client
*clp
, const struct cred
*cred
)
8635 struct rpc_task
*task
;
8638 task
= _nfs41_proc_sequence(clp
, cred
, NULL
, true);
8640 ret
= PTR_ERR(task
);
8643 ret
= rpc_wait_for_completion_task(task
);
8645 ret
= task
->tk_status
;
8648 dprintk("<-- %s status=%d\n", __func__
, ret
);
8652 struct nfs4_reclaim_complete_data
{
8653 struct nfs_client
*clp
;
8654 struct nfs41_reclaim_complete_args arg
;
8655 struct nfs41_reclaim_complete_res res
;
8658 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
8660 struct nfs4_reclaim_complete_data
*calldata
= data
;
8662 nfs4_setup_sequence(calldata
->clp
,
8663 &calldata
->arg
.seq_args
,
8664 &calldata
->res
.seq_res
,
8668 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
8670 switch(task
->tk_status
) {
8672 wake_up_all(&clp
->cl_lock_waitq
);
8674 case -NFS4ERR_COMPLETE_ALREADY
:
8675 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
8677 case -NFS4ERR_DELAY
:
8678 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
8680 case -NFS4ERR_RETRY_UNCACHED_REP
:
8682 case -NFS4ERR_BADSESSION
:
8683 case -NFS4ERR_DEADSESSION
:
8684 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
8685 nfs4_schedule_session_recovery(clp
->cl_session
,
8689 nfs4_schedule_lease_recovery(clp
);
8694 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
8696 struct nfs4_reclaim_complete_data
*calldata
= data
;
8697 struct nfs_client
*clp
= calldata
->clp
;
8698 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
8700 dprintk("--> %s\n", __func__
);
8701 if (!nfs41_sequence_done(task
, res
))
8704 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
8705 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
8706 rpc_restart_call_prepare(task
);
8709 dprintk("<-- %s\n", __func__
);
8712 static void nfs4_free_reclaim_complete_data(void *data
)
8714 struct nfs4_reclaim_complete_data
*calldata
= data
;
8719 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
8720 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
8721 .rpc_call_done
= nfs4_reclaim_complete_done
,
8722 .rpc_release
= nfs4_free_reclaim_complete_data
,
8726 * Issue a global reclaim complete.
8728 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
8729 const struct cred
*cred
)
8731 struct nfs4_reclaim_complete_data
*calldata
;
8732 struct rpc_task
*task
;
8733 struct rpc_message msg
= {
8734 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
8737 struct rpc_task_setup task_setup_data
= {
8738 .rpc_client
= clp
->cl_rpcclient
,
8739 .rpc_message
= &msg
,
8740 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
8741 .flags
= RPC_TASK_ASYNC
,
8743 int status
= -ENOMEM
;
8745 dprintk("--> %s\n", __func__
);
8746 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
8747 if (calldata
== NULL
)
8749 calldata
->clp
= clp
;
8750 calldata
->arg
.one_fs
= 0;
8752 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0, 1);
8753 msg
.rpc_argp
= &calldata
->arg
;
8754 msg
.rpc_resp
= &calldata
->res
;
8755 task_setup_data
.callback_data
= calldata
;
8756 task
= rpc_run_task(&task_setup_data
);
8758 status
= PTR_ERR(task
);
8761 status
= rpc_wait_for_completion_task(task
);
8763 status
= task
->tk_status
;
8766 dprintk("<-- %s status=%d\n", __func__
, status
);
8771 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
8773 struct nfs4_layoutget
*lgp
= calldata
;
8774 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
8776 dprintk("--> %s\n", __func__
);
8777 nfs4_setup_sequence(server
->nfs_client
, &lgp
->args
.seq_args
,
8778 &lgp
->res
.seq_res
, task
);
8779 dprintk("<-- %s\n", __func__
);
8782 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
8784 struct nfs4_layoutget
*lgp
= calldata
;
8786 dprintk("--> %s\n", __func__
);
8787 nfs41_sequence_process(task
, &lgp
->res
.seq_res
);
8788 dprintk("<-- %s\n", __func__
);
8792 nfs4_layoutget_handle_exception(struct rpc_task
*task
,
8793 struct nfs4_layoutget
*lgp
, struct nfs4_exception
*exception
)
8795 struct inode
*inode
= lgp
->args
.inode
;
8796 struct nfs_server
*server
= NFS_SERVER(inode
);
8797 struct pnfs_layout_hdr
*lo
;
8798 int nfs4err
= task
->tk_status
;
8799 int err
, status
= 0;
8802 dprintk("--> %s tk_status => %d\n", __func__
, -task
->tk_status
);
8804 nfs4_sequence_free_slot(&lgp
->res
.seq_res
);
8811 * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs
8812 * on the file. set tk_status to -ENODATA to tell upper layer to
8815 case -NFS4ERR_LAYOUTUNAVAILABLE
:
8819 * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of
8820 * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3).
8822 case -NFS4ERR_BADLAYOUT
:
8823 status
= -EOVERFLOW
;
8826 * NFS4ERR_LAYOUTTRYLATER is a conflict with another client
8827 * (or clients) writing to the same RAID stripe except when
8828 * the minlength argument is 0 (see RFC5661 section 18.43.3).
8830 * Treat it like we would RECALLCONFLICT -- we retry for a little
8831 * while, and then eventually give up.
8833 case -NFS4ERR_LAYOUTTRYLATER
:
8834 if (lgp
->args
.minlength
== 0) {
8835 status
= -EOVERFLOW
;
8840 case -NFS4ERR_RECALLCONFLICT
:
8841 status
= -ERECALLCONFLICT
;
8843 case -NFS4ERR_DELEG_REVOKED
:
8844 case -NFS4ERR_ADMIN_REVOKED
:
8845 case -NFS4ERR_EXPIRED
:
8846 case -NFS4ERR_BAD_STATEID
:
8847 exception
->timeout
= 0;
8848 spin_lock(&inode
->i_lock
);
8849 lo
= NFS_I(inode
)->layout
;
8850 /* If the open stateid was bad, then recover it. */
8851 if (!lo
|| test_bit(NFS_LAYOUT_INVALID_STID
, &lo
->plh_flags
) ||
8852 !nfs4_stateid_match_other(&lgp
->args
.stateid
, &lo
->plh_stateid
)) {
8853 spin_unlock(&inode
->i_lock
);
8854 exception
->state
= lgp
->args
.ctx
->state
;
8855 exception
->stateid
= &lgp
->args
.stateid
;
8860 * Mark the bad layout state as invalid, then retry
8862 pnfs_mark_layout_stateid_invalid(lo
, &head
);
8863 spin_unlock(&inode
->i_lock
);
8864 nfs_commit_inode(inode
, 0);
8865 pnfs_free_lseg_list(&head
);
8870 err
= nfs4_handle_exception(server
, nfs4err
, exception
);
8872 if (exception
->retry
)
8878 dprintk("<-- %s\n", __func__
);
8882 size_t max_response_pages(struct nfs_server
*server
)
8884 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
8885 return nfs_page_array_len(0, max_resp_sz
);
8888 static void nfs4_layoutget_release(void *calldata
)
8890 struct nfs4_layoutget
*lgp
= calldata
;
8892 dprintk("--> %s\n", __func__
);
8893 nfs4_sequence_free_slot(&lgp
->res
.seq_res
);
8894 pnfs_layoutget_free(lgp
);
8895 dprintk("<-- %s\n", __func__
);
8898 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
8899 .rpc_call_prepare
= nfs4_layoutget_prepare
,
8900 .rpc_call_done
= nfs4_layoutget_done
,
8901 .rpc_release
= nfs4_layoutget_release
,
8904 struct pnfs_layout_segment
*
8905 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, long *timeout
)
8907 struct inode
*inode
= lgp
->args
.inode
;
8908 struct nfs_server
*server
= NFS_SERVER(inode
);
8909 struct rpc_task
*task
;
8910 struct rpc_message msg
= {
8911 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
8912 .rpc_argp
= &lgp
->args
,
8913 .rpc_resp
= &lgp
->res
,
8914 .rpc_cred
= lgp
->cred
,
8916 struct rpc_task_setup task_setup_data
= {
8917 .rpc_client
= server
->client
,
8918 .rpc_message
= &msg
,
8919 .callback_ops
= &nfs4_layoutget_call_ops
,
8920 .callback_data
= lgp
,
8921 .flags
= RPC_TASK_ASYNC
,
8923 struct pnfs_layout_segment
*lseg
= NULL
;
8924 struct nfs4_exception exception
= {
8926 .timeout
= *timeout
,
8930 dprintk("--> %s\n", __func__
);
8932 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
8933 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
8935 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0, 0);
8937 task
= rpc_run_task(&task_setup_data
);
8939 return ERR_CAST(task
);
8940 status
= rpc_wait_for_completion_task(task
);
8944 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
8945 if (task
->tk_status
< 0 || lgp
->res
.layoutp
->len
== 0) {
8946 status
= nfs4_layoutget_handle_exception(task
, lgp
, &exception
);
8947 *timeout
= exception
.timeout
;
8949 lseg
= pnfs_layout_process(lgp
);
8951 trace_nfs4_layoutget(lgp
->args
.ctx
,
8958 dprintk("<-- %s status=%d\n", __func__
, status
);
8960 return ERR_PTR(status
);
8965 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
8967 struct nfs4_layoutreturn
*lrp
= calldata
;
8969 dprintk("--> %s\n", __func__
);
8970 nfs4_setup_sequence(lrp
->clp
,
8971 &lrp
->args
.seq_args
,
8974 if (!pnfs_layout_is_valid(lrp
->args
.layout
))
8978 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
8980 struct nfs4_layoutreturn
*lrp
= calldata
;
8981 struct nfs_server
*server
;
8983 dprintk("--> %s\n", __func__
);
8985 if (!nfs41_sequence_process(task
, &lrp
->res
.seq_res
))
8988 server
= NFS_SERVER(lrp
->args
.inode
);
8989 switch (task
->tk_status
) {
8990 case -NFS4ERR_OLD_STATEID
:
8991 if (nfs4_layoutreturn_refresh_stateid(&lrp
->args
.stateid
,
8997 task
->tk_status
= 0;
9001 case -NFS4ERR_DELAY
:
9002 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) != -EAGAIN
)
9006 dprintk("<-- %s\n", __func__
);
9009 task
->tk_status
= 0;
9010 nfs4_sequence_free_slot(&lrp
->res
.seq_res
);
9011 rpc_restart_call_prepare(task
);
9014 static void nfs4_layoutreturn_release(void *calldata
)
9016 struct nfs4_layoutreturn
*lrp
= calldata
;
9017 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
9019 dprintk("--> %s\n", __func__
);
9020 pnfs_layoutreturn_free_lsegs(lo
, &lrp
->args
.stateid
, &lrp
->args
.range
,
9021 lrp
->res
.lrs_present
? &lrp
->res
.stateid
: NULL
);
9022 nfs4_sequence_free_slot(&lrp
->res
.seq_res
);
9023 if (lrp
->ld_private
.ops
&& lrp
->ld_private
.ops
->free
)
9024 lrp
->ld_private
.ops
->free(&lrp
->ld_private
);
9025 pnfs_put_layout_hdr(lrp
->args
.layout
);
9026 nfs_iput_and_deactive(lrp
->inode
);
9028 dprintk("<-- %s\n", __func__
);
9031 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
9032 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
9033 .rpc_call_done
= nfs4_layoutreturn_done
,
9034 .rpc_release
= nfs4_layoutreturn_release
,
9037 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
, bool sync
)
9039 struct rpc_task
*task
;
9040 struct rpc_message msg
= {
9041 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
9042 .rpc_argp
= &lrp
->args
,
9043 .rpc_resp
= &lrp
->res
,
9044 .rpc_cred
= lrp
->cred
,
9046 struct rpc_task_setup task_setup_data
= {
9047 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
9048 .rpc_message
= &msg
,
9049 .callback_ops
= &nfs4_layoutreturn_call_ops
,
9050 .callback_data
= lrp
,
9054 nfs4_state_protect(NFS_SERVER(lrp
->args
.inode
)->nfs_client
,
9055 NFS_SP4_MACH_CRED_PNFS_CLEANUP
,
9056 &task_setup_data
.rpc_client
, &msg
);
9058 dprintk("--> %s\n", __func__
);
9060 lrp
->inode
= nfs_igrab_and_active(lrp
->args
.inode
);
9062 nfs4_layoutreturn_release(lrp
);
9065 task_setup_data
.flags
|= RPC_TASK_ASYNC
;
9067 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1, 0);
9068 task
= rpc_run_task(&task_setup_data
);
9070 return PTR_ERR(task
);
9072 status
= task
->tk_status
;
9073 trace_nfs4_layoutreturn(lrp
->args
.inode
, &lrp
->args
.stateid
, status
);
9074 dprintk("<-- %s status=%d\n", __func__
, status
);
9080 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
9081 struct pnfs_device
*pdev
,
9082 const struct cred
*cred
)
9084 struct nfs4_getdeviceinfo_args args
= {
9086 .notify_types
= NOTIFY_DEVICEID4_CHANGE
|
9087 NOTIFY_DEVICEID4_DELETE
,
9089 struct nfs4_getdeviceinfo_res res
= {
9092 struct rpc_message msg
= {
9093 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
9100 dprintk("--> %s\n", __func__
);
9101 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
9102 if (res
.notification
& ~args
.notify_types
)
9103 dprintk("%s: unsupported notification\n", __func__
);
9104 if (res
.notification
!= args
.notify_types
)
9107 dprintk("<-- %s status=%d\n", __func__
, status
);
9112 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
9113 struct pnfs_device
*pdev
,
9114 const struct cred
*cred
)
9116 struct nfs4_exception exception
= { };
9120 err
= nfs4_handle_exception(server
,
9121 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
9123 } while (exception
.retry
);
9126 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
9128 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
9130 struct nfs4_layoutcommit_data
*data
= calldata
;
9131 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
9133 nfs4_setup_sequence(server
->nfs_client
,
9134 &data
->args
.seq_args
,
9140 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
9142 struct nfs4_layoutcommit_data
*data
= calldata
;
9143 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
9145 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
9148 switch (task
->tk_status
) { /* Just ignore these failures */
9149 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
9150 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
9151 case -NFS4ERR_BADLAYOUT
: /* no layout */
9152 case -NFS4ERR_GRACE
: /* loca_recalim always false */
9153 task
->tk_status
= 0;
9157 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) == -EAGAIN
) {
9158 rpc_restart_call_prepare(task
);
9164 static void nfs4_layoutcommit_release(void *calldata
)
9166 struct nfs4_layoutcommit_data
*data
= calldata
;
9168 pnfs_cleanup_layoutcommit(data
);
9169 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
9171 put_cred(data
->cred
);
9172 nfs_iput_and_deactive(data
->inode
);
9176 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
9177 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
9178 .rpc_call_done
= nfs4_layoutcommit_done
,
9179 .rpc_release
= nfs4_layoutcommit_release
,
9183 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
9185 struct rpc_message msg
= {
9186 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
9187 .rpc_argp
= &data
->args
,
9188 .rpc_resp
= &data
->res
,
9189 .rpc_cred
= data
->cred
,
9191 struct rpc_task_setup task_setup_data
= {
9192 .task
= &data
->task
,
9193 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
9194 .rpc_message
= &msg
,
9195 .callback_ops
= &nfs4_layoutcommit_ops
,
9196 .callback_data
= data
,
9198 struct rpc_task
*task
;
9201 dprintk("NFS: initiating layoutcommit call. sync %d "
9202 "lbw: %llu inode %lu\n", sync
,
9203 data
->args
.lastbytewritten
,
9204 data
->args
.inode
->i_ino
);
9207 data
->inode
= nfs_igrab_and_active(data
->args
.inode
);
9208 if (data
->inode
== NULL
) {
9209 nfs4_layoutcommit_release(data
);
9212 task_setup_data
.flags
= RPC_TASK_ASYNC
;
9214 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
9215 task
= rpc_run_task(&task_setup_data
);
9217 return PTR_ERR(task
);
9219 status
= task
->tk_status
;
9220 trace_nfs4_layoutcommit(data
->args
.inode
, &data
->args
.stateid
, status
);
9221 dprintk("%s: status %d\n", __func__
, status
);
9227 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
9228 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
9231 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9232 struct nfs_fsinfo
*info
,
9233 struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
9235 struct nfs41_secinfo_no_name_args args
= {
9236 .style
= SECINFO_STYLE_CURRENT_FH
,
9238 struct nfs4_secinfo_res res
= {
9241 struct rpc_message msg
= {
9242 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
9246 struct rpc_clnt
*clnt
= server
->client
;
9247 const struct cred
*cred
= NULL
;
9250 if (use_integrity
) {
9251 clnt
= server
->nfs_client
->cl_rpcclient
;
9252 cred
= nfs4_get_clid_cred(server
->nfs_client
);
9253 msg
.rpc_cred
= cred
;
9256 dprintk("--> %s\n", __func__
);
9257 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
9259 dprintk("<-- %s status=%d\n", __func__
, status
);
9267 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9268 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
9270 struct nfs4_exception exception
= { };
9273 /* first try using integrity protection */
9274 err
= -NFS4ERR_WRONGSEC
;
9276 /* try to use integrity protection with machine cred */
9277 if (_nfs4_is_integrity_protected(server
->nfs_client
))
9278 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
9282 * if unable to use integrity protection, or SECINFO with
9283 * integrity protection returns NFS4ERR_WRONGSEC (which is
9284 * disallowed by spec, but exists in deployed servers) use
9285 * the current filesystem's rpc_client and the user cred.
9287 if (err
== -NFS4ERR_WRONGSEC
)
9288 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
9293 case -NFS4ERR_WRONGSEC
:
9297 err
= nfs4_handle_exception(server
, err
, &exception
);
9299 } while (exception
.retry
);
9305 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9306 struct nfs_fsinfo
*info
)
9310 rpc_authflavor_t flavor
= RPC_AUTH_MAXFLAVOR
;
9311 struct nfs4_secinfo_flavors
*flavors
;
9312 struct nfs4_secinfo4
*secinfo
;
9315 page
= alloc_page(GFP_KERNEL
);
9321 flavors
= page_address(page
);
9322 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
9325 * Fall back on "guess and check" method if
9326 * the server doesn't support SECINFO_NO_NAME
9328 if (err
== -NFS4ERR_WRONGSEC
|| err
== -ENOTSUPP
) {
9329 err
= nfs4_find_root_sec(server
, fhandle
, info
);
9335 for (i
= 0; i
< flavors
->num_flavors
; i
++) {
9336 secinfo
= &flavors
->flavors
[i
];
9338 switch (secinfo
->flavor
) {
9342 flavor
= rpcauth_get_pseudoflavor(secinfo
->flavor
,
9343 &secinfo
->flavor_info
);
9346 flavor
= RPC_AUTH_MAXFLAVOR
;
9350 if (!nfs_auth_info_match(&server
->auth_info
, flavor
))
9351 flavor
= RPC_AUTH_MAXFLAVOR
;
9353 if (flavor
!= RPC_AUTH_MAXFLAVOR
) {
9354 err
= nfs4_lookup_root_sec(server
, fhandle
,
9361 if (flavor
== RPC_AUTH_MAXFLAVOR
)
9372 static int _nfs41_test_stateid(struct nfs_server
*server
,
9373 nfs4_stateid
*stateid
,
9374 const struct cred
*cred
)
9377 struct nfs41_test_stateid_args args
= {
9380 struct nfs41_test_stateid_res res
;
9381 struct rpc_message msg
= {
9382 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
9387 struct rpc_clnt
*rpc_client
= server
->client
;
9389 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
9392 dprintk("NFS call test_stateid %p\n", stateid
);
9393 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
9394 status
= nfs4_call_sync_sequence(rpc_client
, server
, &msg
,
9395 &args
.seq_args
, &res
.seq_res
);
9396 if (status
!= NFS_OK
) {
9397 dprintk("NFS reply test_stateid: failed, %d\n", status
);
9400 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
9404 static void nfs4_handle_delay_or_session_error(struct nfs_server
*server
,
9405 int err
, struct nfs4_exception
*exception
)
9407 exception
->retry
= 0;
9409 case -NFS4ERR_DELAY
:
9410 case -NFS4ERR_RETRY_UNCACHED_REP
:
9411 nfs4_handle_exception(server
, err
, exception
);
9413 case -NFS4ERR_BADSESSION
:
9414 case -NFS4ERR_BADSLOT
:
9415 case -NFS4ERR_BAD_HIGH_SLOT
:
9416 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
9417 case -NFS4ERR_DEADSESSION
:
9418 nfs4_do_handle_exception(server
, err
, exception
);
9423 * nfs41_test_stateid - perform a TEST_STATEID operation
9425 * @server: server / transport on which to perform the operation
9426 * @stateid: state ID to test
9429 * Returns NFS_OK if the server recognizes that "stateid" is valid.
9430 * Otherwise a negative NFS4ERR value is returned if the operation
9431 * failed or the state ID is not currently valid.
9433 static int nfs41_test_stateid(struct nfs_server
*server
,
9434 nfs4_stateid
*stateid
,
9435 const struct cred
*cred
)
9437 struct nfs4_exception exception
= { };
9440 err
= _nfs41_test_stateid(server
, stateid
, cred
);
9441 nfs4_handle_delay_or_session_error(server
, err
, &exception
);
9442 } while (exception
.retry
);
9446 struct nfs_free_stateid_data
{
9447 struct nfs_server
*server
;
9448 struct nfs41_free_stateid_args args
;
9449 struct nfs41_free_stateid_res res
;
9452 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
9454 struct nfs_free_stateid_data
*data
= calldata
;
9455 nfs4_setup_sequence(data
->server
->nfs_client
,
9456 &data
->args
.seq_args
,
9461 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
9463 struct nfs_free_stateid_data
*data
= calldata
;
9465 nfs41_sequence_done(task
, &data
->res
.seq_res
);
9467 switch (task
->tk_status
) {
9468 case -NFS4ERR_DELAY
:
9469 if (nfs4_async_handle_error(task
, data
->server
, NULL
, NULL
) == -EAGAIN
)
9470 rpc_restart_call_prepare(task
);
9474 static void nfs41_free_stateid_release(void *calldata
)
9479 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
9480 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
9481 .rpc_call_done
= nfs41_free_stateid_done
,
9482 .rpc_release
= nfs41_free_stateid_release
,
9486 * nfs41_free_stateid - perform a FREE_STATEID operation
9488 * @server: server / transport on which to perform the operation
9489 * @stateid: state ID to release
9491 * @privileged: set to true if this call needs to be privileged
9493 * Note: this function is always asynchronous.
9495 static int nfs41_free_stateid(struct nfs_server
*server
,
9496 const nfs4_stateid
*stateid
,
9497 const struct cred
*cred
,
9500 struct rpc_message msg
= {
9501 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
9504 struct rpc_task_setup task_setup
= {
9505 .rpc_client
= server
->client
,
9506 .rpc_message
= &msg
,
9507 .callback_ops
= &nfs41_free_stateid_ops
,
9508 .flags
= RPC_TASK_ASYNC
,
9510 struct nfs_free_stateid_data
*data
;
9511 struct rpc_task
*task
;
9513 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
9514 &task_setup
.rpc_client
, &msg
);
9516 dprintk("NFS call free_stateid %p\n", stateid
);
9517 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
9520 data
->server
= server
;
9521 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
9523 task_setup
.callback_data
= data
;
9525 msg
.rpc_argp
= &data
->args
;
9526 msg
.rpc_resp
= &data
->res
;
9527 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, privileged
);
9528 task
= rpc_run_task(&task_setup
);
9530 return PTR_ERR(task
);
9536 nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
9538 const struct cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
9540 nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
9541 nfs4_free_lock_state(server
, lsp
);
9544 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
9545 const nfs4_stateid
*s2
)
9547 if (s1
->type
!= s2
->type
)
9550 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
9553 if (s1
->seqid
== s2
->seqid
)
9556 return s1
->seqid
== 0 || s2
->seqid
== 0;
9559 #endif /* CONFIG_NFS_V4_1 */
9561 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
9562 const nfs4_stateid
*s2
)
9564 return nfs4_stateid_match(s1
, s2
);
9568 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
9569 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
9570 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
9571 .recover_open
= nfs4_open_reclaim
,
9572 .recover_lock
= nfs4_lock_reclaim
,
9573 .establish_clid
= nfs4_init_clientid
,
9574 .detect_trunking
= nfs40_discover_server_trunking
,
9577 #if defined(CONFIG_NFS_V4_1)
9578 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
9579 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
9580 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
9581 .recover_open
= nfs4_open_reclaim
,
9582 .recover_lock
= nfs4_lock_reclaim
,
9583 .establish_clid
= nfs41_init_clientid
,
9584 .reclaim_complete
= nfs41_proc_reclaim_complete
,
9585 .detect_trunking
= nfs41_discover_server_trunking
,
9587 #endif /* CONFIG_NFS_V4_1 */
9589 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
9590 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
9591 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
9592 .recover_open
= nfs40_open_expired
,
9593 .recover_lock
= nfs4_lock_expired
,
9594 .establish_clid
= nfs4_init_clientid
,
9597 #if defined(CONFIG_NFS_V4_1)
9598 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
9599 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
9600 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
9601 .recover_open
= nfs41_open_expired
,
9602 .recover_lock
= nfs41_lock_expired
,
9603 .establish_clid
= nfs41_init_clientid
,
9605 #endif /* CONFIG_NFS_V4_1 */
9607 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
9608 .sched_state_renewal
= nfs4_proc_async_renew
,
9609 .get_state_renewal_cred
= nfs4_get_renew_cred
,
9610 .renew_lease
= nfs4_proc_renew
,
9613 #if defined(CONFIG_NFS_V4_1)
9614 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
9615 .sched_state_renewal
= nfs41_proc_async_sequence
,
9616 .get_state_renewal_cred
= nfs4_get_machine_cred
,
9617 .renew_lease
= nfs4_proc_sequence
,
9621 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops
= {
9622 .get_locations
= _nfs40_proc_get_locations
,
9623 .fsid_present
= _nfs40_proc_fsid_present
,
9626 #if defined(CONFIG_NFS_V4_1)
9627 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops
= {
9628 .get_locations
= _nfs41_proc_get_locations
,
9629 .fsid_present
= _nfs41_proc_fsid_present
,
9631 #endif /* CONFIG_NFS_V4_1 */
9633 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
9635 .init_caps
= NFS_CAP_READDIRPLUS
9636 | NFS_CAP_ATOMIC_OPEN
9637 | NFS_CAP_POSIX_LOCK
,
9638 .init_client
= nfs40_init_client
,
9639 .shutdown_client
= nfs40_shutdown_client
,
9640 .match_stateid
= nfs4_match_stateid
,
9641 .find_root_sec
= nfs4_find_root_sec
,
9642 .free_lock_state
= nfs4_release_lockowner
,
9643 .test_and_free_expired
= nfs40_test_and_free_expired_stateid
,
9644 .alloc_seqid
= nfs_alloc_seqid
,
9645 .call_sync_ops
= &nfs40_call_sync_ops
,
9646 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
9647 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
9648 .state_renewal_ops
= &nfs40_state_renewal_ops
,
9649 .mig_recovery_ops
= &nfs40_mig_recovery_ops
,
9652 #if defined(CONFIG_NFS_V4_1)
9653 static struct nfs_seqid
*
9654 nfs_alloc_no_seqid(struct nfs_seqid_counter
*arg1
, gfp_t arg2
)
9659 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
9661 .init_caps
= NFS_CAP_READDIRPLUS
9662 | NFS_CAP_ATOMIC_OPEN
9663 | NFS_CAP_POSIX_LOCK
9664 | NFS_CAP_STATEID_NFSV41
9665 | NFS_CAP_ATOMIC_OPEN_V1
9667 .init_client
= nfs41_init_client
,
9668 .shutdown_client
= nfs41_shutdown_client
,
9669 .match_stateid
= nfs41_match_stateid
,
9670 .find_root_sec
= nfs41_find_root_sec
,
9671 .free_lock_state
= nfs41_free_lock_state
,
9672 .test_and_free_expired
= nfs41_test_and_free_expired_stateid
,
9673 .alloc_seqid
= nfs_alloc_no_seqid
,
9674 .session_trunk
= nfs4_test_session_trunk
,
9675 .call_sync_ops
= &nfs41_call_sync_ops
,
9676 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
9677 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
9678 .state_renewal_ops
= &nfs41_state_renewal_ops
,
9679 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
9683 #if defined(CONFIG_NFS_V4_2)
9684 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
9686 .init_caps
= NFS_CAP_READDIRPLUS
9687 | NFS_CAP_ATOMIC_OPEN
9688 | NFS_CAP_POSIX_LOCK
9689 | NFS_CAP_STATEID_NFSV41
9690 | NFS_CAP_ATOMIC_OPEN_V1
9694 | NFS_CAP_OFFLOAD_CANCEL
9695 | NFS_CAP_DEALLOCATE
9697 | NFS_CAP_LAYOUTSTATS
9699 .init_client
= nfs41_init_client
,
9700 .shutdown_client
= nfs41_shutdown_client
,
9701 .match_stateid
= nfs41_match_stateid
,
9702 .find_root_sec
= nfs41_find_root_sec
,
9703 .free_lock_state
= nfs41_free_lock_state
,
9704 .call_sync_ops
= &nfs41_call_sync_ops
,
9705 .test_and_free_expired
= nfs41_test_and_free_expired_stateid
,
9706 .alloc_seqid
= nfs_alloc_no_seqid
,
9707 .session_trunk
= nfs4_test_session_trunk
,
9708 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
9709 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
9710 .state_renewal_ops
= &nfs41_state_renewal_ops
,
9711 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
9715 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
9716 [0] = &nfs_v4_0_minor_ops
,
9717 #if defined(CONFIG_NFS_V4_1)
9718 [1] = &nfs_v4_1_minor_ops
,
9720 #if defined(CONFIG_NFS_V4_2)
9721 [2] = &nfs_v4_2_minor_ops
,
9725 static ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *list
, size_t size
)
9727 ssize_t error
, error2
;
9729 error
= generic_listxattr(dentry
, list
, size
);
9737 error2
= nfs4_listxattr_nfs4_label(d_inode(dentry
), list
, size
);
9740 return error
+ error2
;
9743 static const struct inode_operations nfs4_dir_inode_operations
= {
9744 .create
= nfs_create
,
9745 .lookup
= nfs_lookup
,
9746 .atomic_open
= nfs_atomic_open
,
9748 .unlink
= nfs_unlink
,
9749 .symlink
= nfs_symlink
,
9753 .rename
= nfs_rename
,
9754 .permission
= nfs_permission
,
9755 .getattr
= nfs_getattr
,
9756 .setattr
= nfs_setattr
,
9757 .listxattr
= nfs4_listxattr
,
9760 static const struct inode_operations nfs4_file_inode_operations
= {
9761 .permission
= nfs_permission
,
9762 .getattr
= nfs_getattr
,
9763 .setattr
= nfs_setattr
,
9764 .listxattr
= nfs4_listxattr
,
9767 const struct nfs_rpc_ops nfs_v4_clientops
= {
9768 .version
= 4, /* protocol version */
9769 .dentry_ops
= &nfs4_dentry_operations
,
9770 .dir_inode_ops
= &nfs4_dir_inode_operations
,
9771 .file_inode_ops
= &nfs4_file_inode_operations
,
9772 .file_ops
= &nfs4_file_operations
,
9773 .getroot
= nfs4_proc_get_root
,
9774 .submount
= nfs4_submount
,
9775 .try_mount
= nfs4_try_mount
,
9776 .getattr
= nfs4_proc_getattr
,
9777 .setattr
= nfs4_proc_setattr
,
9778 .lookup
= nfs4_proc_lookup
,
9779 .lookupp
= nfs4_proc_lookupp
,
9780 .access
= nfs4_proc_access
,
9781 .readlink
= nfs4_proc_readlink
,
9782 .create
= nfs4_proc_create
,
9783 .remove
= nfs4_proc_remove
,
9784 .unlink_setup
= nfs4_proc_unlink_setup
,
9785 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
9786 .unlink_done
= nfs4_proc_unlink_done
,
9787 .rename_setup
= nfs4_proc_rename_setup
,
9788 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
9789 .rename_done
= nfs4_proc_rename_done
,
9790 .link
= nfs4_proc_link
,
9791 .symlink
= nfs4_proc_symlink
,
9792 .mkdir
= nfs4_proc_mkdir
,
9793 .rmdir
= nfs4_proc_rmdir
,
9794 .readdir
= nfs4_proc_readdir
,
9795 .mknod
= nfs4_proc_mknod
,
9796 .statfs
= nfs4_proc_statfs
,
9797 .fsinfo
= nfs4_proc_fsinfo
,
9798 .pathconf
= nfs4_proc_pathconf
,
9799 .set_capabilities
= nfs4_server_capabilities
,
9800 .decode_dirent
= nfs4_decode_dirent
,
9801 .pgio_rpc_prepare
= nfs4_proc_pgio_rpc_prepare
,
9802 .read_setup
= nfs4_proc_read_setup
,
9803 .read_done
= nfs4_read_done
,
9804 .write_setup
= nfs4_proc_write_setup
,
9805 .write_done
= nfs4_write_done
,
9806 .commit_setup
= nfs4_proc_commit_setup
,
9807 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
9808 .commit_done
= nfs4_commit_done
,
9809 .lock
= nfs4_proc_lock
,
9810 .clear_acl_cache
= nfs4_zap_acl_attr
,
9811 .close_context
= nfs4_close_context
,
9812 .open_context
= nfs4_atomic_open
,
9813 .have_delegation
= nfs4_have_delegation
,
9814 .alloc_client
= nfs4_alloc_client
,
9815 .init_client
= nfs4_init_client
,
9816 .free_client
= nfs4_free_client
,
9817 .create_server
= nfs4_create_server
,
9818 .clone_server
= nfs_clone_server
,
9821 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
9822 .name
= XATTR_NAME_NFSV4_ACL
,
9823 .list
= nfs4_xattr_list_nfs4_acl
,
9824 .get
= nfs4_xattr_get_nfs4_acl
,
9825 .set
= nfs4_xattr_set_nfs4_acl
,
9828 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
9829 &nfs4_xattr_nfs4_acl_handler
,
9830 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
9831 &nfs4_xattr_nfs4_label_handler
,