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
, struct rpc_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 struct rpc_cred
*cred
,
103 struct nfs4_slot
*slot
,
105 static int nfs41_test_stateid(struct nfs_server
*, nfs4_stateid
*,
107 static int nfs41_free_stateid(struct nfs_server
*, const nfs4_stateid
*,
108 struct rpc_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 struct rpc_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 struct rpc_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 struct rpc_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
, struct rpc_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
, struct rpc_cred
*cred
)
945 slot
->interrupted
= 0;
948 #endif /* !CONFIG_NFS_V4_1 */
950 static void nfs41_sequence_res_init(struct nfs4_sequence_res
*res
)
952 res
->sr_timestamp
= jiffies
;
953 res
->sr_status_flags
= 0;
958 void nfs4_sequence_attach_slot(struct nfs4_sequence_args
*args
,
959 struct nfs4_sequence_res
*res
,
960 struct nfs4_slot
*slot
)
964 slot
->privileged
= args
->sa_privileged
? 1 : 0;
965 args
->sa_slot
= slot
;
970 int nfs4_setup_sequence(struct nfs_client
*client
,
971 struct nfs4_sequence_args
*args
,
972 struct nfs4_sequence_res
*res
,
973 struct rpc_task
*task
)
975 struct nfs4_session
*session
= nfs4_get_session(client
);
976 struct nfs4_slot_table
*tbl
= client
->cl_slot_tbl
;
977 struct nfs4_slot
*slot
;
979 /* slot already allocated? */
980 if (res
->sr_slot
!= NULL
)
984 tbl
= &session
->fc_slot_table
;
985 task
->tk_timeout
= 0;
989 spin_lock(&tbl
->slot_tbl_lock
);
990 /* The state manager will wait until the slot table is empty */
991 if (nfs4_slot_tbl_draining(tbl
) && !args
->sa_privileged
)
994 slot
= nfs4_alloc_slot(tbl
);
996 /* Try again in 1/4 second */
997 if (slot
== ERR_PTR(-ENOMEM
))
998 task
->tk_timeout
= HZ
>> 2;
1001 spin_unlock(&tbl
->slot_tbl_lock
);
1003 if (likely(!slot
->interrupted
))
1005 nfs4_sequence_process_interrupted(client
,
1006 slot
, task
->tk_msg
.rpc_cred
);
1009 nfs4_sequence_attach_slot(args
, res
, slot
);
1011 trace_nfs4_setup_sequence(session
, args
);
1013 nfs41_sequence_res_init(res
);
1014 rpc_call_start(task
);
1018 if (args
->sa_privileged
)
1019 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
1020 NULL
, RPC_PRIORITY_PRIVILEGED
);
1022 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
1023 spin_unlock(&tbl
->slot_tbl_lock
);
1026 EXPORT_SYMBOL_GPL(nfs4_setup_sequence
);
1028 static void nfs40_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
1030 struct nfs4_call_sync_data
*data
= calldata
;
1031 nfs4_setup_sequence(data
->seq_server
->nfs_client
,
1032 data
->seq_args
, data
->seq_res
, task
);
1035 static void nfs40_call_sync_done(struct rpc_task
*task
, void *calldata
)
1037 struct nfs4_call_sync_data
*data
= calldata
;
1038 nfs4_sequence_done(task
, data
->seq_res
);
1041 static const struct rpc_call_ops nfs40_call_sync_ops
= {
1042 .rpc_call_prepare
= nfs40_call_sync_prepare
,
1043 .rpc_call_done
= nfs40_call_sync_done
,
1046 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
1047 struct nfs_server
*server
,
1048 struct rpc_message
*msg
,
1049 struct nfs4_sequence_args
*args
,
1050 struct nfs4_sequence_res
*res
)
1053 struct rpc_task
*task
;
1054 struct nfs_client
*clp
= server
->nfs_client
;
1055 struct nfs4_call_sync_data data
= {
1056 .seq_server
= server
,
1060 struct rpc_task_setup task_setup
= {
1063 .callback_ops
= clp
->cl_mvops
->call_sync_ops
,
1064 .callback_data
= &data
1067 task
= rpc_run_task(&task_setup
);
1069 ret
= PTR_ERR(task
);
1071 ret
= task
->tk_status
;
1077 int nfs4_call_sync(struct rpc_clnt
*clnt
,
1078 struct nfs_server
*server
,
1079 struct rpc_message
*msg
,
1080 struct nfs4_sequence_args
*args
,
1081 struct nfs4_sequence_res
*res
,
1084 nfs4_init_sequence(args
, res
, cache_reply
, 0);
1085 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
);
1089 nfs4_inc_nlink_locked(struct inode
*inode
)
1091 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_OTHER
;
1096 nfs4_dec_nlink_locked(struct inode
*inode
)
1098 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_OTHER
;
1103 update_changeattr_locked(struct inode
*dir
, struct nfs4_change_info
*cinfo
,
1104 unsigned long timestamp
, unsigned long cache_validity
)
1106 struct nfs_inode
*nfsi
= NFS_I(dir
);
1108 nfsi
->cache_validity
|= NFS_INO_INVALID_CTIME
1109 | NFS_INO_INVALID_MTIME
1110 | NFS_INO_INVALID_DATA
1112 if (cinfo
->atomic
&& cinfo
->before
== inode_peek_iversion_raw(dir
)) {
1113 nfsi
->cache_validity
&= ~NFS_INO_REVAL_PAGECACHE
;
1114 nfsi
->attrtimeo_timestamp
= jiffies
;
1116 nfs_force_lookup_revalidate(dir
);
1117 if (cinfo
->before
!= inode_peek_iversion_raw(dir
))
1118 nfsi
->cache_validity
|= NFS_INO_INVALID_ACCESS
|
1119 NFS_INO_INVALID_ACL
;
1121 inode_set_iversion_raw(dir
, cinfo
->after
);
1122 nfsi
->read_cache_jiffies
= timestamp
;
1123 nfsi
->attr_gencount
= nfs_inc_attr_generation_counter();
1124 nfsi
->cache_validity
&= ~NFS_INO_INVALID_CHANGE
;
1125 nfs_fscache_invalidate(dir
);
1129 update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
,
1130 unsigned long timestamp
, unsigned long cache_validity
)
1132 spin_lock(&dir
->i_lock
);
1133 update_changeattr_locked(dir
, cinfo
, timestamp
, cache_validity
);
1134 spin_unlock(&dir
->i_lock
);
1137 struct nfs4_open_createattrs
{
1138 struct nfs4_label
*label
;
1139 struct iattr
*sattr
;
1140 const __u32 verf
[2];
1143 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
1144 int err
, struct nfs4_exception
*exception
)
1148 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
1150 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
1151 exception
->retry
= 1;
1156 nfs4_map_atomic_open_share(struct nfs_server
*server
,
1157 fmode_t fmode
, int openflags
)
1161 switch (fmode
& (FMODE_READ
| FMODE_WRITE
)) {
1163 res
= NFS4_SHARE_ACCESS_READ
;
1166 res
= NFS4_SHARE_ACCESS_WRITE
;
1168 case FMODE_READ
|FMODE_WRITE
:
1169 res
= NFS4_SHARE_ACCESS_BOTH
;
1171 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
1173 /* Want no delegation if we're using O_DIRECT */
1174 if (openflags
& O_DIRECT
)
1175 res
|= NFS4_SHARE_WANT_NO_DELEG
;
1180 static enum open_claim_type4
1181 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
1182 enum open_claim_type4 claim
)
1184 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
1189 case NFS4_OPEN_CLAIM_FH
:
1190 return NFS4_OPEN_CLAIM_NULL
;
1191 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1192 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1193 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1194 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
1198 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
1200 p
->o_res
.f_attr
= &p
->f_attr
;
1201 p
->o_res
.f_label
= p
->f_label
;
1202 p
->o_res
.seqid
= p
->o_arg
.seqid
;
1203 p
->c_res
.seqid
= p
->c_arg
.seqid
;
1204 p
->o_res
.server
= p
->o_arg
.server
;
1205 p
->o_res
.access_request
= p
->o_arg
.access
;
1206 nfs_fattr_init(&p
->f_attr
);
1207 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
1210 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
1211 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
1212 const struct nfs4_open_createattrs
*c
,
1213 enum open_claim_type4 claim
,
1216 struct dentry
*parent
= dget_parent(dentry
);
1217 struct inode
*dir
= d_inode(parent
);
1218 struct nfs_server
*server
= NFS_SERVER(dir
);
1219 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
1220 struct nfs4_label
*label
= (c
!= NULL
) ? c
->label
: NULL
;
1221 struct nfs4_opendata
*p
;
1223 p
= kzalloc(sizeof(*p
), gfp_mask
);
1227 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
1228 if (IS_ERR(p
->f_label
))
1231 p
->a_label
= nfs4_label_alloc(server
, gfp_mask
);
1232 if (IS_ERR(p
->a_label
))
1235 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
1236 p
->o_arg
.seqid
= alloc_seqid(&sp
->so_seqid
, gfp_mask
);
1237 if (IS_ERR(p
->o_arg
.seqid
))
1238 goto err_free_label
;
1239 nfs_sb_active(dentry
->d_sb
);
1240 p
->dentry
= dget(dentry
);
1243 atomic_inc(&sp
->so_count
);
1244 p
->o_arg
.open_flags
= flags
;
1245 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
1246 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
1247 p
->o_arg
.share_access
= nfs4_map_atomic_open_share(server
,
1249 if (flags
& O_CREAT
) {
1250 p
->o_arg
.umask
= current_umask();
1251 p
->o_arg
.label
= nfs4_label_copy(p
->a_label
, label
);
1252 if (c
->sattr
!= NULL
&& c
->sattr
->ia_valid
!= 0) {
1253 p
->o_arg
.u
.attrs
= &p
->attrs
;
1254 memcpy(&p
->attrs
, c
->sattr
, sizeof(p
->attrs
));
1256 memcpy(p
->o_arg
.u
.verifier
.data
, c
->verf
,
1257 sizeof(p
->o_arg
.u
.verifier
.data
));
1260 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
1261 * will return permission denied for all bits until close */
1262 if (!(flags
& O_EXCL
)) {
1263 /* ask server to check for all possible rights as results
1265 switch (p
->o_arg
.claim
) {
1268 case NFS4_OPEN_CLAIM_NULL
:
1269 case NFS4_OPEN_CLAIM_FH
:
1270 p
->o_arg
.access
= NFS4_ACCESS_READ
|
1271 NFS4_ACCESS_MODIFY
|
1272 NFS4_ACCESS_EXTEND
|
1273 NFS4_ACCESS_EXECUTE
;
1276 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
1277 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
1278 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
1279 p
->o_arg
.name
= &dentry
->d_name
;
1280 p
->o_arg
.server
= server
;
1281 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
1282 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
1283 switch (p
->o_arg
.claim
) {
1284 case NFS4_OPEN_CLAIM_NULL
:
1285 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1286 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1287 p
->o_arg
.fh
= NFS_FH(dir
);
1289 case NFS4_OPEN_CLAIM_PREVIOUS
:
1290 case NFS4_OPEN_CLAIM_FH
:
1291 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1292 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1293 p
->o_arg
.fh
= NFS_FH(d_inode(dentry
));
1295 p
->c_arg
.fh
= &p
->o_res
.fh
;
1296 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
1297 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
1298 nfs4_init_opendata_res(p
);
1299 kref_init(&p
->kref
);
1303 nfs4_label_free(p
->a_label
);
1305 nfs4_label_free(p
->f_label
);
1313 static void nfs4_opendata_free(struct kref
*kref
)
1315 struct nfs4_opendata
*p
= container_of(kref
,
1316 struct nfs4_opendata
, kref
);
1317 struct super_block
*sb
= p
->dentry
->d_sb
;
1319 nfs4_lgopen_release(p
->lgp
);
1320 nfs_free_seqid(p
->o_arg
.seqid
);
1321 nfs4_sequence_free_slot(&p
->o_res
.seq_res
);
1322 if (p
->state
!= NULL
)
1323 nfs4_put_open_state(p
->state
);
1324 nfs4_put_state_owner(p
->owner
);
1326 nfs4_label_free(p
->a_label
);
1327 nfs4_label_free(p
->f_label
);
1331 nfs_sb_deactive(sb
);
1332 nfs_fattr_free_names(&p
->f_attr
);
1333 kfree(p
->f_attr
.mdsthreshold
);
1337 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1340 kref_put(&p
->kref
, nfs4_opendata_free
);
1343 static bool nfs4_mode_match_open_stateid(struct nfs4_state
*state
,
1346 switch(fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1347 case FMODE_READ
|FMODE_WRITE
:
1348 return state
->n_rdwr
!= 0;
1350 return state
->n_wronly
!= 0;
1352 return state
->n_rdonly
!= 0;
1358 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
,
1359 int open_mode
, enum open_claim_type4 claim
)
1363 if (open_mode
& (O_EXCL
|O_TRUNC
))
1366 case NFS4_OPEN_CLAIM_NULL
:
1367 case NFS4_OPEN_CLAIM_FH
:
1372 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1374 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1375 && state
->n_rdonly
!= 0;
1378 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1379 && state
->n_wronly
!= 0;
1381 case FMODE_READ
|FMODE_WRITE
:
1382 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1383 && state
->n_rdwr
!= 0;
1389 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
,
1390 enum open_claim_type4 claim
)
1392 if (delegation
== NULL
)
1394 if ((delegation
->type
& fmode
) != fmode
)
1397 case NFS4_OPEN_CLAIM_NULL
:
1398 case NFS4_OPEN_CLAIM_FH
:
1400 case NFS4_OPEN_CLAIM_PREVIOUS
:
1401 if (!test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1407 nfs_mark_delegation_referenced(delegation
);
1411 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1420 case FMODE_READ
|FMODE_WRITE
:
1423 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1426 #ifdef CONFIG_NFS_V4_1
1427 static bool nfs_open_stateid_recover_openmode(struct nfs4_state
*state
)
1429 if (state
->n_rdonly
&& !test_bit(NFS_O_RDONLY_STATE
, &state
->flags
))
1431 if (state
->n_wronly
&& !test_bit(NFS_O_WRONLY_STATE
, &state
->flags
))
1433 if (state
->n_rdwr
&& !test_bit(NFS_O_RDWR_STATE
, &state
->flags
))
1437 #endif /* CONFIG_NFS_V4_1 */
1439 static void nfs_state_log_update_open_stateid(struct nfs4_state
*state
)
1441 if (test_and_clear_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
))
1442 wake_up_all(&state
->waitq
);
1445 static void nfs_state_log_out_of_order_open_stateid(struct nfs4_state
*state
,
1446 const nfs4_stateid
*stateid
)
1448 u32 state_seqid
= be32_to_cpu(state
->open_stateid
.seqid
);
1449 u32 stateid_seqid
= be32_to_cpu(stateid
->seqid
);
1451 if (stateid_seqid
== state_seqid
+ 1U ||
1452 (stateid_seqid
== 1U && state_seqid
== 0xffffffffU
))
1453 nfs_state_log_update_open_stateid(state
);
1455 set_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
);
1458 static void nfs_test_and_clear_all_open_stateid(struct nfs4_state
*state
)
1460 struct nfs_client
*clp
= state
->owner
->so_server
->nfs_client
;
1461 bool need_recover
= false;
1463 if (test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
) && state
->n_rdonly
)
1464 need_recover
= true;
1465 if (test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
) && state
->n_wronly
)
1466 need_recover
= true;
1467 if (test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
) && state
->n_rdwr
)
1468 need_recover
= true;
1470 nfs4_state_mark_reclaim_nograce(clp
, state
);
1474 * Check for whether or not the caller may update the open stateid
1475 * to the value passed in by stateid.
1477 * Note: This function relies heavily on the server implementing
1478 * RFC7530 Section 9.1.4.2, and RFC5661 Section 8.2.2
1480 * i.e. The stateid seqids have to be initialised to 1, and
1481 * are then incremented on every state transition.
1483 static bool nfs_need_update_open_stateid(struct nfs4_state
*state
,
1484 const nfs4_stateid
*stateid
)
1486 if (test_bit(NFS_OPEN_STATE
, &state
->flags
) == 0 ||
1487 !nfs4_stateid_match_other(stateid
, &state
->open_stateid
)) {
1488 if (stateid
->seqid
== cpu_to_be32(1))
1489 nfs_state_log_update_open_stateid(state
);
1491 set_bit(NFS_STATE_CHANGE_WAIT
, &state
->flags
);
1495 if (nfs4_stateid_is_newer(stateid
, &state
->open_stateid
)) {
1496 nfs_state_log_out_of_order_open_stateid(state
, stateid
);
1502 static void nfs_resync_open_stateid_locked(struct nfs4_state
*state
)
1504 if (!(state
->n_wronly
|| state
->n_rdonly
|| state
->n_rdwr
))
1506 if (state
->n_wronly
)
1507 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1508 if (state
->n_rdonly
)
1509 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1511 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1512 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1515 static void nfs_clear_open_stateid_locked(struct nfs4_state
*state
,
1516 nfs4_stateid
*stateid
, fmode_t fmode
)
1518 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1519 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1521 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1524 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1527 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1528 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1529 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1531 if (stateid
== NULL
)
1533 /* Handle OPEN+OPEN_DOWNGRADE races */
1534 if (nfs4_stateid_match_other(stateid
, &state
->open_stateid
) &&
1535 !nfs4_stateid_is_newer(stateid
, &state
->open_stateid
)) {
1536 nfs_resync_open_stateid_locked(state
);
1539 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1540 nfs4_stateid_copy(&state
->stateid
, stateid
);
1541 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1542 trace_nfs4_open_stateid_update(state
->inode
, stateid
, 0);
1544 nfs_state_log_update_open_stateid(state
);
1547 static void nfs_clear_open_stateid(struct nfs4_state
*state
,
1548 nfs4_stateid
*arg_stateid
,
1549 nfs4_stateid
*stateid
, fmode_t fmode
)
1551 write_seqlock(&state
->seqlock
);
1552 /* Ignore, if the CLOSE argment doesn't match the current stateid */
1553 if (nfs4_state_match_open_stateid_other(state
, arg_stateid
))
1554 nfs_clear_open_stateid_locked(state
, stateid
, fmode
);
1555 write_sequnlock(&state
->seqlock
);
1556 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1557 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1560 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
,
1561 const nfs4_stateid
*stateid
, nfs4_stateid
*freeme
)
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_delegation
*delegation
;
1753 int open_mode
= opendata
->o_arg
.open_flags
;
1754 fmode_t fmode
= opendata
->o_arg
.fmode
;
1755 enum open_claim_type4 claim
= opendata
->o_arg
.claim
;
1756 nfs4_stateid stateid
;
1760 spin_lock(&state
->owner
->so_lock
);
1761 if (can_open_cached(state
, fmode
, open_mode
, claim
)) {
1762 update_open_stateflags(state
, fmode
);
1763 spin_unlock(&state
->owner
->so_lock
);
1764 goto out_return_state
;
1766 spin_unlock(&state
->owner
->so_lock
);
1768 delegation
= nfs4_get_valid_delegation(state
->inode
);
1769 if (!can_open_delegated(delegation
, fmode
, claim
)) {
1773 /* Save the delegation */
1774 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1776 nfs_release_seqid(opendata
->o_arg
.seqid
);
1777 if (!opendata
->is_recover
) {
1778 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1784 /* Try to update the stateid using the delegation */
1785 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1786 goto out_return_state
;
1789 return ERR_PTR(ret
);
1791 atomic_inc(&state
->count
);
1796 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1798 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1799 struct nfs_delegation
*delegation
;
1800 int delegation_flags
= 0;
1803 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1805 delegation_flags
= delegation
->flags
;
1807 switch (data
->o_arg
.claim
) {
1810 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1811 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1812 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1813 "returning a delegation for "
1814 "OPEN(CLAIM_DELEGATE_CUR)\n",
1818 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1819 nfs_inode_set_delegation(state
->inode
,
1820 data
->owner
->so_cred
,
1821 data
->o_res
.delegation_type
,
1822 &data
->o_res
.delegation
,
1823 data
->o_res
.pagemod_limit
);
1825 nfs_inode_reclaim_delegation(state
->inode
,
1826 data
->owner
->so_cred
,
1827 data
->o_res
.delegation_type
,
1828 &data
->o_res
.delegation
,
1829 data
->o_res
.pagemod_limit
);
1831 if (data
->o_res
.do_recall
)
1832 nfs_async_inode_return_delegation(state
->inode
,
1833 &data
->o_res
.delegation
);
1837 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1838 * and update the nfs4_state.
1840 static struct nfs4_state
*
1841 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1843 struct inode
*inode
= data
->state
->inode
;
1844 struct nfs4_state
*state
= data
->state
;
1847 if (!data
->rpc_done
) {
1848 if (data
->rpc_status
)
1849 return ERR_PTR(data
->rpc_status
);
1850 /* cached opens have already been processed */
1854 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1856 return ERR_PTR(ret
);
1858 if (data
->o_res
.delegation_type
!= 0)
1859 nfs4_opendata_check_deleg(data
, state
);
1861 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1863 atomic_inc(&state
->count
);
1868 static struct inode
*
1869 nfs4_opendata_get_inode(struct nfs4_opendata
*data
)
1871 struct inode
*inode
;
1873 switch (data
->o_arg
.claim
) {
1874 case NFS4_OPEN_CLAIM_NULL
:
1875 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1876 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1877 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1878 return ERR_PTR(-EAGAIN
);
1879 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
,
1880 &data
->f_attr
, data
->f_label
);
1883 inode
= d_inode(data
->dentry
);
1885 nfs_refresh_inode(inode
, &data
->f_attr
);
1890 static struct nfs4_state
*
1891 nfs4_opendata_find_nfs4_state(struct nfs4_opendata
*data
)
1893 struct nfs4_state
*state
;
1894 struct inode
*inode
;
1896 inode
= nfs4_opendata_get_inode(data
);
1898 return ERR_CAST(inode
);
1899 if (data
->state
!= NULL
&& data
->state
->inode
== inode
) {
1900 state
= data
->state
;
1901 atomic_inc(&state
->count
);
1903 state
= nfs4_get_open_state(inode
, data
->owner
);
1906 state
= ERR_PTR(-ENOMEM
);
1910 static struct nfs4_state
*
1911 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1913 struct nfs4_state
*state
;
1915 if (!data
->rpc_done
) {
1916 state
= nfs4_try_open_cached(data
);
1917 trace_nfs4_cached_open(data
->state
);
1921 state
= nfs4_opendata_find_nfs4_state(data
);
1925 if (data
->o_res
.delegation_type
!= 0)
1926 nfs4_opendata_check_deleg(data
, state
);
1927 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1930 nfs_release_seqid(data
->o_arg
.seqid
);
1934 static struct nfs4_state
*
1935 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1937 struct nfs4_state
*ret
;
1939 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1940 ret
=_nfs4_opendata_reclaim_to_nfs4_state(data
);
1942 ret
= _nfs4_opendata_to_nfs4_state(data
);
1943 nfs4_sequence_free_slot(&data
->o_res
.seq_res
);
1947 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1949 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1950 struct nfs_open_context
*ctx
;
1952 spin_lock(&state
->inode
->i_lock
);
1953 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1954 if (ctx
->state
!= state
)
1956 get_nfs_open_context(ctx
);
1957 spin_unlock(&state
->inode
->i_lock
);
1960 spin_unlock(&state
->inode
->i_lock
);
1961 return ERR_PTR(-ENOENT
);
1964 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1965 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1967 struct nfs4_opendata
*opendata
;
1969 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1970 NULL
, claim
, GFP_NOFS
);
1971 if (opendata
== NULL
)
1972 return ERR_PTR(-ENOMEM
);
1973 opendata
->state
= state
;
1974 atomic_inc(&state
->count
);
1978 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
,
1981 struct nfs4_state
*newstate
;
1984 if (!nfs4_mode_match_open_stateid(opendata
->state
, fmode
))
1986 opendata
->o_arg
.open_flags
= 0;
1987 opendata
->o_arg
.fmode
= fmode
;
1988 opendata
->o_arg
.share_access
= nfs4_map_atomic_open_share(
1989 NFS_SB(opendata
->dentry
->d_sb
),
1991 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1992 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1993 nfs4_init_opendata_res(opendata
);
1994 ret
= _nfs4_recover_proc_open(opendata
);
1997 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1998 if (IS_ERR(newstate
))
1999 return PTR_ERR(newstate
);
2000 if (newstate
!= opendata
->state
)
2002 nfs4_close_state(newstate
, fmode
);
2006 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
2010 /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */
2011 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2012 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2013 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2014 /* memory barrier prior to reading state->n_* */
2015 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2016 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2018 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
);
2021 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
);
2024 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
);
2028 * We may have performed cached opens for all three recoveries.
2029 * Check if we need to update the current stateid.
2031 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
2032 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
2033 write_seqlock(&state
->seqlock
);
2034 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
2035 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
2036 write_sequnlock(&state
->seqlock
);
2043 * reclaim state on the server after a reboot.
2045 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2047 struct nfs_delegation
*delegation
;
2048 struct nfs4_opendata
*opendata
;
2049 fmode_t delegation_type
= 0;
2052 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2053 NFS4_OPEN_CLAIM_PREVIOUS
);
2054 if (IS_ERR(opendata
))
2055 return PTR_ERR(opendata
);
2057 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2058 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
2059 delegation_type
= delegation
->type
;
2061 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
2062 status
= nfs4_open_recover(opendata
, state
);
2063 nfs4_opendata_put(opendata
);
2067 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2069 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2070 struct nfs4_exception exception
= { };
2073 err
= _nfs4_do_open_reclaim(ctx
, state
);
2074 trace_nfs4_open_reclaim(ctx
, 0, err
);
2075 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2077 if (err
!= -NFS4ERR_DELAY
)
2079 nfs4_handle_exception(server
, err
, &exception
);
2080 } while (exception
.retry
);
2084 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2086 struct nfs_open_context
*ctx
;
2089 ctx
= nfs4_state_find_open_context(state
);
2092 ret
= nfs4_do_open_reclaim(ctx
, state
);
2093 put_nfs_open_context(ctx
);
2097 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
)
2101 printk(KERN_ERR
"NFS: %s: unhandled error "
2102 "%d.\n", __func__
, err
);
2108 case -NFS4ERR_BADSESSION
:
2109 case -NFS4ERR_BADSLOT
:
2110 case -NFS4ERR_BAD_HIGH_SLOT
:
2111 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
2112 case -NFS4ERR_DEADSESSION
:
2113 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
2115 case -NFS4ERR_STALE_CLIENTID
:
2116 case -NFS4ERR_STALE_STATEID
:
2117 /* Don't recall a delegation if it was lost */
2118 nfs4_schedule_lease_recovery(server
->nfs_client
);
2120 case -NFS4ERR_MOVED
:
2121 nfs4_schedule_migration_recovery(server
);
2123 case -NFS4ERR_LEASE_MOVED
:
2124 nfs4_schedule_lease_moved_recovery(server
->nfs_client
);
2126 case -NFS4ERR_DELEG_REVOKED
:
2127 case -NFS4ERR_ADMIN_REVOKED
:
2128 case -NFS4ERR_EXPIRED
:
2129 case -NFS4ERR_BAD_STATEID
:
2130 case -NFS4ERR_OPENMODE
:
2131 nfs_inode_find_state_and_recover(state
->inode
,
2133 nfs4_schedule_stateid_recovery(server
, state
);
2135 case -NFS4ERR_DELAY
:
2136 case -NFS4ERR_GRACE
:
2140 case -NFS4ERR_DENIED
:
2142 struct nfs4_lock_state
*lsp
= fl
->fl_u
.nfs4_fl
.owner
;
2144 set_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
);
2151 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
,
2152 struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
2154 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2155 struct nfs4_opendata
*opendata
;
2158 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2159 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
2160 if (IS_ERR(opendata
))
2161 return PTR_ERR(opendata
);
2162 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
2163 if (!test_bit(NFS_O_RDWR_STATE
, &state
->flags
)) {
2164 err
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
);
2168 if (!test_bit(NFS_O_WRONLY_STATE
, &state
->flags
)) {
2169 err
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
);
2173 if (!test_bit(NFS_O_RDONLY_STATE
, &state
->flags
)) {
2174 err
= nfs4_open_recover_helper(opendata
, FMODE_READ
);
2178 nfs_state_clear_delegation(state
);
2180 nfs4_opendata_put(opendata
);
2181 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, NULL
, err
);
2184 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
2186 struct nfs4_opendata
*data
= calldata
;
2188 nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
2189 &data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, task
);
2192 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
2194 struct nfs4_opendata
*data
= calldata
;
2196 nfs40_sequence_done(task
, &data
->c_res
.seq_res
);
2198 data
->rpc_status
= task
->tk_status
;
2199 if (data
->rpc_status
== 0) {
2200 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
2201 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
2202 renew_lease(data
->o_res
.server
, data
->timestamp
);
2203 data
->rpc_done
= true;
2207 static void nfs4_open_confirm_release(void *calldata
)
2209 struct nfs4_opendata
*data
= calldata
;
2210 struct nfs4_state
*state
= NULL
;
2212 /* If this request hasn't been cancelled, do nothing */
2213 if (!data
->cancelled
)
2215 /* In case of error, no cleanup! */
2216 if (!data
->rpc_done
)
2218 state
= nfs4_opendata_to_nfs4_state(data
);
2220 nfs4_close_state(state
, data
->o_arg
.fmode
);
2222 nfs4_opendata_put(data
);
2225 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
2226 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
2227 .rpc_call_done
= nfs4_open_confirm_done
,
2228 .rpc_release
= nfs4_open_confirm_release
,
2232 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
2234 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
2236 struct nfs_server
*server
= NFS_SERVER(d_inode(data
->dir
));
2237 struct rpc_task
*task
;
2238 struct rpc_message msg
= {
2239 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
2240 .rpc_argp
= &data
->c_arg
,
2241 .rpc_resp
= &data
->c_res
,
2242 .rpc_cred
= data
->owner
->so_cred
,
2244 struct rpc_task_setup task_setup_data
= {
2245 .rpc_client
= server
->client
,
2246 .rpc_message
= &msg
,
2247 .callback_ops
= &nfs4_open_confirm_ops
,
2248 .callback_data
= data
,
2249 .workqueue
= nfsiod_workqueue
,
2250 .flags
= RPC_TASK_ASYNC
,
2254 nfs4_init_sequence(&data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, 1,
2256 kref_get(&data
->kref
);
2257 data
->rpc_done
= false;
2258 data
->rpc_status
= 0;
2259 data
->timestamp
= jiffies
;
2260 task
= rpc_run_task(&task_setup_data
);
2262 return PTR_ERR(task
);
2263 status
= rpc_wait_for_completion_task(task
);
2265 data
->cancelled
= true;
2268 status
= data
->rpc_status
;
2273 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
2275 struct nfs4_opendata
*data
= calldata
;
2276 struct nfs4_state_owner
*sp
= data
->owner
;
2277 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
2278 enum open_claim_type4 claim
= data
->o_arg
.claim
;
2280 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
2283 * Check if we still need to send an OPEN call, or if we can use
2284 * a delegation instead.
2286 if (data
->state
!= NULL
) {
2287 struct nfs_delegation
*delegation
;
2289 if (can_open_cached(data
->state
, data
->o_arg
.fmode
,
2290 data
->o_arg
.open_flags
, claim
))
2293 delegation
= nfs4_get_valid_delegation(data
->state
->inode
);
2294 if (can_open_delegated(delegation
, data
->o_arg
.fmode
, claim
))
2295 goto unlock_no_action
;
2298 /* Update client id. */
2299 data
->o_arg
.clientid
= clp
->cl_clientid
;
2303 case NFS4_OPEN_CLAIM_PREVIOUS
:
2304 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
2305 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
2306 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
2308 case NFS4_OPEN_CLAIM_FH
:
2309 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
2311 data
->timestamp
= jiffies
;
2312 if (nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
2313 &data
->o_arg
.seq_args
,
2314 &data
->o_res
.seq_res
,
2316 nfs_release_seqid(data
->o_arg
.seqid
);
2318 /* Set the create mode (note dependency on the session type) */
2319 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
2320 if (data
->o_arg
.open_flags
& O_EXCL
) {
2321 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
2322 if (nfs4_has_persistent_session(clp
))
2323 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
2324 else if (clp
->cl_mvops
->minor_version
> 0)
2325 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
2329 trace_nfs4_cached_open(data
->state
);
2332 task
->tk_action
= NULL
;
2334 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
2337 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
2339 struct nfs4_opendata
*data
= calldata
;
2341 data
->rpc_status
= task
->tk_status
;
2343 if (!nfs4_sequence_process(task
, &data
->o_res
.seq_res
))
2346 if (task
->tk_status
== 0) {
2347 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
2348 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
2352 data
->rpc_status
= -ELOOP
;
2355 data
->rpc_status
= -EISDIR
;
2358 data
->rpc_status
= -ENOTDIR
;
2361 renew_lease(data
->o_res
.server
, data
->timestamp
);
2362 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
2363 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
2365 data
->rpc_done
= true;
2368 static void nfs4_open_release(void *calldata
)
2370 struct nfs4_opendata
*data
= calldata
;
2371 struct nfs4_state
*state
= NULL
;
2373 /* If this request hasn't been cancelled, do nothing */
2374 if (!data
->cancelled
)
2376 /* In case of error, no cleanup! */
2377 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
2379 /* In case we need an open_confirm, no cleanup! */
2380 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
2382 state
= nfs4_opendata_to_nfs4_state(data
);
2384 nfs4_close_state(state
, data
->o_arg
.fmode
);
2386 nfs4_opendata_put(data
);
2389 static const struct rpc_call_ops nfs4_open_ops
= {
2390 .rpc_call_prepare
= nfs4_open_prepare
,
2391 .rpc_call_done
= nfs4_open_done
,
2392 .rpc_release
= nfs4_open_release
,
2395 static int nfs4_run_open_task(struct nfs4_opendata
*data
,
2396 struct nfs_open_context
*ctx
)
2398 struct inode
*dir
= d_inode(data
->dir
);
2399 struct nfs_server
*server
= NFS_SERVER(dir
);
2400 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2401 struct nfs_openres
*o_res
= &data
->o_res
;
2402 struct rpc_task
*task
;
2403 struct rpc_message msg
= {
2404 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
2407 .rpc_cred
= data
->owner
->so_cred
,
2409 struct rpc_task_setup task_setup_data
= {
2410 .rpc_client
= server
->client
,
2411 .rpc_message
= &msg
,
2412 .callback_ops
= &nfs4_open_ops
,
2413 .callback_data
= data
,
2414 .workqueue
= nfsiod_workqueue
,
2415 .flags
= RPC_TASK_ASYNC
,
2419 kref_get(&data
->kref
);
2420 data
->rpc_done
= false;
2421 data
->rpc_status
= 0;
2422 data
->cancelled
= false;
2423 data
->is_recover
= false;
2425 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1, 1);
2426 data
->is_recover
= true;
2428 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1, 0);
2429 pnfs_lgopen_prepare(data
, ctx
);
2431 task
= rpc_run_task(&task_setup_data
);
2433 return PTR_ERR(task
);
2434 status
= rpc_wait_for_completion_task(task
);
2436 data
->cancelled
= true;
2439 status
= data
->rpc_status
;
2445 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
2447 struct inode
*dir
= d_inode(data
->dir
);
2448 struct nfs_openres
*o_res
= &data
->o_res
;
2451 status
= nfs4_run_open_task(data
, NULL
);
2452 if (status
!= 0 || !data
->rpc_done
)
2455 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
2457 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
)
2458 status
= _nfs4_proc_open_confirm(data
);
2464 * Additional permission checks in order to distinguish between an
2465 * open for read, and an open for execute. This works around the
2466 * fact that NFSv4 OPEN treats read and execute permissions as being
2468 * Note that in the non-execute case, we want to turn off permission
2469 * checking if we just created a new file (POSIX open() semantics).
2471 static int nfs4_opendata_access(struct rpc_cred
*cred
,
2472 struct nfs4_opendata
*opendata
,
2473 struct nfs4_state
*state
, fmode_t fmode
,
2476 struct nfs_access_entry cache
;
2479 /* access call failed or for some reason the server doesn't
2480 * support any access modes -- defer access call until later */
2481 if (opendata
->o_res
.access_supported
== 0)
2486 * Use openflags to check for exec, because fmode won't
2487 * always have FMODE_EXEC set when file open for exec.
2489 if (openflags
& __FMODE_EXEC
) {
2490 /* ONLY check for exec rights */
2491 if (S_ISDIR(state
->inode
->i_mode
))
2492 mask
= NFS4_ACCESS_LOOKUP
;
2494 mask
= NFS4_ACCESS_EXECUTE
;
2495 } else if ((fmode
& FMODE_READ
) && !opendata
->file_created
)
2496 mask
= NFS4_ACCESS_READ
;
2499 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
2500 nfs_access_add_cache(state
->inode
, &cache
);
2502 flags
= NFS4_ACCESS_READ
| NFS4_ACCESS_EXECUTE
| NFS4_ACCESS_LOOKUP
;
2503 if ((mask
& ~cache
.mask
& flags
) == 0)
2510 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
2512 static int _nfs4_proc_open(struct nfs4_opendata
*data
,
2513 struct nfs_open_context
*ctx
)
2515 struct inode
*dir
= d_inode(data
->dir
);
2516 struct nfs_server
*server
= NFS_SERVER(dir
);
2517 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2518 struct nfs_openres
*o_res
= &data
->o_res
;
2521 status
= nfs4_run_open_task(data
, ctx
);
2522 if (!data
->rpc_done
)
2525 if (status
== -NFS4ERR_BADNAME
&&
2526 !(o_arg
->open_flags
& O_CREAT
))
2531 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
2533 if (o_arg
->open_flags
& O_CREAT
) {
2534 if (o_arg
->open_flags
& O_EXCL
)
2535 data
->file_created
= true;
2536 else if (o_res
->cinfo
.before
!= o_res
->cinfo
.after
)
2537 data
->file_created
= true;
2538 if (data
->file_created
||
2539 inode_peek_iversion_raw(dir
) != o_res
->cinfo
.after
)
2540 update_changeattr(dir
, &o_res
->cinfo
,
2541 o_res
->f_attr
->time_start
, 0);
2543 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
2544 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
2545 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
2546 status
= _nfs4_proc_open_confirm(data
);
2550 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
)) {
2551 nfs4_sequence_free_slot(&o_res
->seq_res
);
2552 nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
,
2553 o_res
->f_label
, NULL
);
2560 * reclaim state on the server after a network partition.
2561 * Assumes caller holds the appropriate lock
2563 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2565 struct nfs4_opendata
*opendata
;
2568 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2569 NFS4_OPEN_CLAIM_FH
);
2570 if (IS_ERR(opendata
))
2571 return PTR_ERR(opendata
);
2572 ret
= nfs4_open_recover(opendata
, state
);
2574 d_drop(ctx
->dentry
);
2575 nfs4_opendata_put(opendata
);
2579 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2581 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2582 struct nfs4_exception exception
= { };
2586 err
= _nfs4_open_expired(ctx
, state
);
2587 trace_nfs4_open_expired(ctx
, 0, err
);
2588 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2593 case -NFS4ERR_GRACE
:
2594 case -NFS4ERR_DELAY
:
2595 nfs4_handle_exception(server
, err
, &exception
);
2598 } while (exception
.retry
);
2603 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2605 struct nfs_open_context
*ctx
;
2608 ctx
= nfs4_state_find_open_context(state
);
2611 ret
= nfs4_do_open_expired(ctx
, state
);
2612 put_nfs_open_context(ctx
);
2616 static void nfs_finish_clear_delegation_stateid(struct nfs4_state
*state
,
2617 const nfs4_stateid
*stateid
)
2619 nfs_remove_bad_delegation(state
->inode
, stateid
);
2620 nfs_state_clear_delegation(state
);
2623 static void nfs40_clear_delegation_stateid(struct nfs4_state
*state
)
2625 if (rcu_access_pointer(NFS_I(state
->inode
)->delegation
) != NULL
)
2626 nfs_finish_clear_delegation_stateid(state
, NULL
);
2629 static int nfs40_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2631 /* NFSv4.0 doesn't allow for delegation recovery on open expire */
2632 nfs40_clear_delegation_stateid(state
);
2633 return nfs4_open_expired(sp
, state
);
2636 static int nfs40_test_and_free_expired_stateid(struct nfs_server
*server
,
2637 nfs4_stateid
*stateid
,
2638 struct rpc_cred
*cred
)
2640 return -NFS4ERR_BAD_STATEID
;
2643 #if defined(CONFIG_NFS_V4_1)
2644 static int nfs41_test_and_free_expired_stateid(struct nfs_server
*server
,
2645 nfs4_stateid
*stateid
,
2646 struct rpc_cred
*cred
)
2650 switch (stateid
->type
) {
2653 case NFS4_INVALID_STATEID_TYPE
:
2654 case NFS4_SPECIAL_STATEID_TYPE
:
2655 return -NFS4ERR_BAD_STATEID
;
2656 case NFS4_REVOKED_STATEID_TYPE
:
2660 status
= nfs41_test_stateid(server
, stateid
, cred
);
2662 case -NFS4ERR_EXPIRED
:
2663 case -NFS4ERR_ADMIN_REVOKED
:
2664 case -NFS4ERR_DELEG_REVOKED
:
2670 /* Ack the revoked state to the server */
2671 nfs41_free_stateid(server
, stateid
, cred
, true);
2672 return -NFS4ERR_EXPIRED
;
2675 static void nfs41_check_delegation_stateid(struct nfs4_state
*state
)
2677 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2678 nfs4_stateid stateid
;
2679 struct nfs_delegation
*delegation
;
2680 struct rpc_cred
*cred
;
2683 /* Get the delegation credential for use by test/free_stateid */
2685 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2686 if (delegation
== NULL
) {
2688 nfs_state_clear_delegation(state
);
2692 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
2693 if (test_bit(NFS_DELEGATION_REVOKED
, &delegation
->flags
)) {
2695 nfs_state_clear_delegation(state
);
2699 if (!test_and_clear_bit(NFS_DELEGATION_TEST_EXPIRED
,
2700 &delegation
->flags
)) {
2705 cred
= get_rpccred(delegation
->cred
);
2707 status
= nfs41_test_and_free_expired_stateid(server
, &stateid
, cred
);
2708 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
2709 if (status
== -NFS4ERR_EXPIRED
|| status
== -NFS4ERR_BAD_STATEID
)
2710 nfs_finish_clear_delegation_stateid(state
, &stateid
);
2716 * nfs41_check_expired_locks - possibly free a lock stateid
2718 * @state: NFSv4 state for an inode
2720 * Returns NFS_OK if recovery for this stateid is now finished.
2721 * Otherwise a negative NFS4ERR value is returned.
2723 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
2725 int status
, ret
= NFS_OK
;
2726 struct nfs4_lock_state
*lsp
, *prev
= NULL
;
2727 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2729 if (!test_bit(LK_STATE_IN_USE
, &state
->flags
))
2732 spin_lock(&state
->state_lock
);
2733 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
2734 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
2735 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
2737 refcount_inc(&lsp
->ls_count
);
2738 spin_unlock(&state
->state_lock
);
2740 nfs4_put_lock_state(prev
);
2743 status
= nfs41_test_and_free_expired_stateid(server
,
2746 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
2747 if (status
== -NFS4ERR_EXPIRED
||
2748 status
== -NFS4ERR_BAD_STATEID
) {
2749 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
2750 lsp
->ls_stateid
.type
= NFS4_INVALID_STATEID_TYPE
;
2751 if (!recover_lost_locks
)
2752 set_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
);
2753 } else if (status
!= NFS_OK
) {
2755 nfs4_put_lock_state(prev
);
2758 spin_lock(&state
->state_lock
);
2761 spin_unlock(&state
->state_lock
);
2762 nfs4_put_lock_state(prev
);
2768 * nfs41_check_open_stateid - possibly free an open stateid
2770 * @state: NFSv4 state for an inode
2772 * Returns NFS_OK if recovery for this stateid is now finished.
2773 * Otherwise a negative NFS4ERR value is returned.
2775 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2777 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2778 nfs4_stateid
*stateid
= &state
->open_stateid
;
2779 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2782 if (test_bit(NFS_OPEN_STATE
, &state
->flags
) == 0) {
2783 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0) {
2784 if (nfs4_have_delegation(state
->inode
, state
->state
))
2786 return -NFS4ERR_OPENMODE
;
2788 return -NFS4ERR_BAD_STATEID
;
2790 status
= nfs41_test_and_free_expired_stateid(server
, stateid
, cred
);
2791 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2792 if (status
== -NFS4ERR_EXPIRED
|| status
== -NFS4ERR_BAD_STATEID
) {
2793 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2794 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2795 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2796 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2797 stateid
->type
= NFS4_INVALID_STATEID_TYPE
;
2800 if (nfs_open_stateid_recover_openmode(state
))
2801 return -NFS4ERR_OPENMODE
;
2805 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2809 nfs41_check_delegation_stateid(state
);
2810 status
= nfs41_check_expired_locks(state
);
2811 if (status
!= NFS_OK
)
2813 status
= nfs41_check_open_stateid(state
);
2814 if (status
!= NFS_OK
)
2815 status
= nfs4_open_expired(sp
, state
);
2821 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2822 * fields corresponding to attributes that were used to store the verifier.
2823 * Make sure we clobber those fields in the later setattr call
2825 static unsigned nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
,
2826 struct iattr
*sattr
, struct nfs4_label
**label
)
2828 const __u32
*bitmask
= opendata
->o_arg
.server
->exclcreat_bitmask
;
2833 for (i
= 0; i
< ARRAY_SIZE(attrset
); i
++) {
2834 attrset
[i
] = opendata
->o_res
.attrset
[i
];
2835 if (opendata
->o_arg
.createmode
== NFS4_CREATE_EXCLUSIVE4_1
)
2836 attrset
[i
] &= ~bitmask
[i
];
2839 ret
= (opendata
->o_arg
.createmode
== NFS4_CREATE_EXCLUSIVE
) ?
2840 sattr
->ia_valid
: 0;
2842 if ((attrset
[1] & (FATTR4_WORD1_TIME_ACCESS
|FATTR4_WORD1_TIME_ACCESS_SET
))) {
2843 if (sattr
->ia_valid
& ATTR_ATIME_SET
)
2844 ret
|= ATTR_ATIME_SET
;
2849 if ((attrset
[1] & (FATTR4_WORD1_TIME_MODIFY
|FATTR4_WORD1_TIME_MODIFY_SET
))) {
2850 if (sattr
->ia_valid
& ATTR_MTIME_SET
)
2851 ret
|= ATTR_MTIME_SET
;
2856 if (!(attrset
[2] & FATTR4_WORD2_SECURITY_LABEL
))
2861 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2864 struct nfs_open_context
*ctx
)
2866 struct nfs4_state_owner
*sp
= opendata
->owner
;
2867 struct nfs_server
*server
= sp
->so_server
;
2868 struct dentry
*dentry
;
2869 struct nfs4_state
*state
;
2873 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2875 ret
= _nfs4_proc_open(opendata
, ctx
);
2879 state
= _nfs4_opendata_to_nfs4_state(opendata
);
2880 ret
= PTR_ERR(state
);
2884 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2885 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2886 if (opendata
->o_res
.rflags
& NFS4_OPEN_RESULT_MAY_NOTIFY_LOCK
)
2887 set_bit(NFS_STATE_MAY_NOTIFY_LOCK
, &state
->flags
);
2889 dentry
= opendata
->dentry
;
2890 if (d_really_is_negative(dentry
)) {
2891 struct dentry
*alias
;
2893 alias
= d_exact_alias(dentry
, state
->inode
);
2895 alias
= d_splice_alias(igrab(state
->inode
), dentry
);
2896 /* d_splice_alias() can't fail here - it's a non-directory */
2899 ctx
->dentry
= dentry
= alias
;
2901 nfs_set_verifier(dentry
,
2902 nfs_save_change_attribute(d_inode(opendata
->dir
)));
2905 /* Parse layoutget results before we check for access */
2906 pnfs_parse_lgopen(state
->inode
, opendata
->lgp
, ctx
);
2908 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2912 if (d_inode(dentry
) == state
->inode
) {
2913 nfs_inode_attach_open_context(ctx
);
2914 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2915 nfs4_schedule_stateid_recovery(server
, state
);
2919 if (!opendata
->cancelled
)
2920 nfs4_sequence_free_slot(&opendata
->o_res
.seq_res
);
2925 * Returns a referenced nfs4_state
2927 static int _nfs4_do_open(struct inode
*dir
,
2928 struct nfs_open_context
*ctx
,
2930 const struct nfs4_open_createattrs
*c
,
2933 struct nfs4_state_owner
*sp
;
2934 struct nfs4_state
*state
= NULL
;
2935 struct nfs_server
*server
= NFS_SERVER(dir
);
2936 struct nfs4_opendata
*opendata
;
2937 struct dentry
*dentry
= ctx
->dentry
;
2938 struct rpc_cred
*cred
= ctx
->cred
;
2939 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2940 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2941 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2942 struct iattr
*sattr
= c
->sattr
;
2943 struct nfs4_label
*label
= c
->label
;
2944 struct nfs4_label
*olabel
= NULL
;
2947 /* Protect against reboot recovery conflicts */
2949 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2951 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2954 status
= nfs4_client_recover_expired_lease(server
->nfs_client
);
2956 goto err_put_state_owner
;
2957 if (d_really_is_positive(dentry
))
2958 nfs4_return_incompatible_delegation(d_inode(dentry
), fmode
);
2960 if (d_really_is_positive(dentry
))
2961 claim
= NFS4_OPEN_CLAIM_FH
;
2962 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
,
2963 c
, claim
, GFP_KERNEL
);
2964 if (opendata
== NULL
)
2965 goto err_put_state_owner
;
2968 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2969 if (IS_ERR(olabel
)) {
2970 status
= PTR_ERR(olabel
);
2971 goto err_opendata_put
;
2975 if (server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2976 if (!opendata
->f_attr
.mdsthreshold
) {
2977 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2978 if (!opendata
->f_attr
.mdsthreshold
)
2979 goto err_free_label
;
2981 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2983 if (d_really_is_positive(dentry
))
2984 opendata
->state
= nfs4_get_open_state(d_inode(dentry
), sp
);
2986 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2988 goto err_free_label
;
2991 if ((opendata
->o_arg
.open_flags
& (O_CREAT
|O_EXCL
)) == (O_CREAT
|O_EXCL
) &&
2992 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2993 unsigned attrs
= nfs4_exclusive_attrset(opendata
, sattr
, &label
);
2995 * send create attributes which was not set by open
2996 * with an extra setattr.
2998 if (attrs
|| label
) {
2999 unsigned ia_old
= sattr
->ia_valid
;
3001 sattr
->ia_valid
= attrs
;
3002 nfs_fattr_init(opendata
->o_res
.f_attr
);
3003 status
= nfs4_do_setattr(state
->inode
, cred
,
3004 opendata
->o_res
.f_attr
, sattr
,
3005 ctx
, label
, olabel
);
3007 nfs_setattr_update_inode(state
->inode
, sattr
,
3008 opendata
->o_res
.f_attr
);
3009 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
3011 sattr
->ia_valid
= ia_old
;
3014 if (opened
&& opendata
->file_created
)
3017 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
)) {
3018 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
3019 opendata
->f_attr
.mdsthreshold
= NULL
;
3022 nfs4_label_free(olabel
);
3024 nfs4_opendata_put(opendata
);
3025 nfs4_put_state_owner(sp
);
3028 nfs4_label_free(olabel
);
3030 nfs4_opendata_put(opendata
);
3031 err_put_state_owner
:
3032 nfs4_put_state_owner(sp
);
3038 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
3039 struct nfs_open_context
*ctx
,
3041 struct iattr
*sattr
,
3042 struct nfs4_label
*label
,
3045 struct nfs_server
*server
= NFS_SERVER(dir
);
3046 struct nfs4_exception exception
= { };
3047 struct nfs4_state
*res
;
3048 struct nfs4_open_createattrs c
= {
3052 [0] = (__u32
)jiffies
,
3053 [1] = (__u32
)current
->pid
,
3059 status
= _nfs4_do_open(dir
, ctx
, flags
, &c
, opened
);
3061 trace_nfs4_open_file(ctx
, flags
, status
);
3064 /* NOTE: BAD_SEQID means the server and client disagree about the
3065 * book-keeping w.r.t. state-changing operations
3066 * (OPEN/CLOSE/LOCK/LOCKU...)
3067 * It is actually a sign of a bug on the client or on the server.
3069 * If we receive a BAD_SEQID error in the particular case of
3070 * doing an OPEN, we assume that nfs_increment_open_seqid() will
3071 * have unhashed the old state_owner for us, and that we can
3072 * therefore safely retry using a new one. We should still warn
3073 * the user though...
3075 if (status
== -NFS4ERR_BAD_SEQID
) {
3076 pr_warn_ratelimited("NFS: v4 server %s "
3077 " returned a bad sequence-id error!\n",
3078 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
3079 exception
.retry
= 1;
3083 * BAD_STATEID on OPEN means that the server cancelled our
3084 * state before it received the OPEN_CONFIRM.
3085 * Recover by retrying the request as per the discussion
3086 * on Page 181 of RFC3530.
3088 if (status
== -NFS4ERR_BAD_STATEID
) {
3089 exception
.retry
= 1;
3092 if (status
== -NFS4ERR_EXPIRED
) {
3093 nfs4_schedule_lease_recovery(server
->nfs_client
);
3094 exception
.retry
= 1;
3097 if (status
== -EAGAIN
) {
3098 /* We must have found a delegation */
3099 exception
.retry
= 1;
3102 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
3104 res
= ERR_PTR(nfs4_handle_exception(server
,
3105 status
, &exception
));
3106 } while (exception
.retry
);
3110 static int _nfs4_do_setattr(struct inode
*inode
,
3111 struct nfs_setattrargs
*arg
,
3112 struct nfs_setattrres
*res
,
3113 struct rpc_cred
*cred
,
3114 struct nfs_open_context
*ctx
)
3116 struct nfs_server
*server
= NFS_SERVER(inode
);
3117 struct rpc_message msg
= {
3118 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
3123 struct rpc_cred
*delegation_cred
= NULL
;
3124 unsigned long timestamp
= jiffies
;
3128 nfs_fattr_init(res
->fattr
);
3130 /* Servers should only apply open mode checks for file size changes */
3131 truncate
= (arg
->iap
->ia_valid
& ATTR_SIZE
) ? true : false;
3135 if (nfs4_copy_delegation_stateid(inode
, FMODE_WRITE
, &arg
->stateid
, &delegation_cred
)) {
3136 /* Use that stateid */
3137 } else if (ctx
!= NULL
&& ctx
->state
) {
3138 struct nfs_lock_context
*l_ctx
;
3139 if (!nfs4_valid_open_stateid(ctx
->state
))
3141 l_ctx
= nfs_get_lock_context(ctx
);
3143 return PTR_ERR(l_ctx
);
3144 status
= nfs4_select_rw_stateid(ctx
->state
, FMODE_WRITE
, l_ctx
,
3145 &arg
->stateid
, &delegation_cred
);
3146 nfs_put_lock_context(l_ctx
);
3151 nfs4_stateid_copy(&arg
->stateid
, &zero_stateid
);
3153 if (delegation_cred
)
3154 msg
.rpc_cred
= delegation_cred
;
3156 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
->seq_args
, &res
->seq_res
, 1);
3158 put_rpccred(delegation_cred
);
3159 if (status
== 0 && ctx
!= NULL
)
3160 renew_lease(server
, timestamp
);
3161 trace_nfs4_setattr(inode
, &arg
->stateid
, status
);
3165 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
3166 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
3167 struct nfs_open_context
*ctx
, struct nfs4_label
*ilabel
,
3168 struct nfs4_label
*olabel
)
3170 struct nfs_server
*server
= NFS_SERVER(inode
);
3171 __u32 bitmask
[NFS4_BITMASK_SZ
];
3172 struct nfs4_state
*state
= ctx
? ctx
->state
: NULL
;
3173 struct nfs_setattrargs arg
= {
3174 .fh
= NFS_FH(inode
),
3180 struct nfs_setattrres res
= {
3185 struct nfs4_exception exception
= {
3188 .stateid
= &arg
.stateid
,
3193 nfs4_bitmap_copy_adjust_setattr(bitmask
,
3194 nfs4_bitmask(server
, olabel
),
3197 err
= _nfs4_do_setattr(inode
, &arg
, &res
, cred
, ctx
);
3199 case -NFS4ERR_OPENMODE
:
3200 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
3201 pr_warn_once("NFSv4: server %s is incorrectly "
3202 "applying open mode checks to "
3203 "a SETATTR that is not "
3204 "changing file size.\n",
3205 server
->nfs_client
->cl_hostname
);
3207 if (state
&& !(state
->state
& FMODE_WRITE
)) {
3209 if (sattr
->ia_valid
& ATTR_OPEN
)
3214 err
= nfs4_handle_exception(server
, err
, &exception
);
3215 } while (exception
.retry
);
3221 nfs4_wait_on_layoutreturn(struct inode
*inode
, struct rpc_task
*task
)
3223 if (inode
== NULL
|| !nfs_have_layout(inode
))
3226 return pnfs_wait_on_layoutreturn(inode
, task
);
3229 struct nfs4_closedata
{
3230 struct inode
*inode
;
3231 struct nfs4_state
*state
;
3232 struct nfs_closeargs arg
;
3233 struct nfs_closeres res
;
3235 struct nfs4_layoutreturn_args arg
;
3236 struct nfs4_layoutreturn_res res
;
3237 struct nfs4_xdr_opaque_data ld_private
;
3241 struct nfs_fattr fattr
;
3242 unsigned long timestamp
;
3245 static void nfs4_free_closedata(void *data
)
3247 struct nfs4_closedata
*calldata
= data
;
3248 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
3249 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
3251 if (calldata
->lr
.roc
)
3252 pnfs_roc_release(&calldata
->lr
.arg
, &calldata
->lr
.res
,
3253 calldata
->res
.lr_ret
);
3254 nfs4_put_open_state(calldata
->state
);
3255 nfs_free_seqid(calldata
->arg
.seqid
);
3256 nfs4_put_state_owner(sp
);
3257 nfs_sb_deactive(sb
);
3261 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
3263 struct nfs4_closedata
*calldata
= data
;
3264 struct nfs4_state
*state
= calldata
->state
;
3265 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
3266 nfs4_stateid
*res_stateid
= NULL
;
3267 struct nfs4_exception exception
= {
3269 .inode
= calldata
->inode
,
3270 .stateid
= &calldata
->arg
.stateid
,
3273 dprintk("%s: begin!\n", __func__
);
3274 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
3276 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
3278 /* Handle Layoutreturn errors */
3279 if (calldata
->arg
.lr_args
&& task
->tk_status
!= 0) {
3280 switch (calldata
->res
.lr_ret
) {
3282 calldata
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
3285 calldata
->arg
.lr_args
= NULL
;
3286 calldata
->res
.lr_res
= NULL
;
3288 case -NFS4ERR_OLD_STATEID
:
3289 if (nfs4_layoutreturn_refresh_stateid(&calldata
->arg
.lr_args
->stateid
,
3290 &calldata
->arg
.lr_args
->range
,
3294 case -NFS4ERR_ADMIN_REVOKED
:
3295 case -NFS4ERR_DELEG_REVOKED
:
3296 case -NFS4ERR_EXPIRED
:
3297 case -NFS4ERR_BAD_STATEID
:
3298 case -NFS4ERR_UNKNOWN_LAYOUTTYPE
:
3299 case -NFS4ERR_WRONG_CRED
:
3300 calldata
->arg
.lr_args
= NULL
;
3301 calldata
->res
.lr_res
= NULL
;
3306 /* hmm. we are done with the inode, and in the process of freeing
3307 * the state_owner. we keep this around to process errors
3309 switch (task
->tk_status
) {
3311 res_stateid
= &calldata
->res
.stateid
;
3312 renew_lease(server
, calldata
->timestamp
);
3314 case -NFS4ERR_ACCESS
:
3315 if (calldata
->arg
.bitmask
!= NULL
) {
3316 calldata
->arg
.bitmask
= NULL
;
3317 calldata
->res
.fattr
= NULL
;
3322 case -NFS4ERR_OLD_STATEID
:
3323 /* Did we race with OPEN? */
3324 if (nfs4_refresh_open_stateid(&calldata
->arg
.stateid
,
3328 case -NFS4ERR_ADMIN_REVOKED
:
3329 case -NFS4ERR_STALE_STATEID
:
3330 case -NFS4ERR_EXPIRED
:
3331 nfs4_free_revoked_stateid(server
,
3332 &calldata
->arg
.stateid
,
3333 task
->tk_msg
.rpc_cred
);
3335 case -NFS4ERR_BAD_STATEID
:
3338 task
->tk_status
= nfs4_async_handle_exception(task
,
3339 server
, task
->tk_status
, &exception
);
3340 if (exception
.retry
)
3343 nfs_clear_open_stateid(state
, &calldata
->arg
.stateid
,
3344 res_stateid
, calldata
->arg
.fmode
);
3346 task
->tk_status
= 0;
3347 nfs_release_seqid(calldata
->arg
.seqid
);
3348 nfs_refresh_inode(calldata
->inode
, &calldata
->fattr
);
3349 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
3352 calldata
->res
.lr_ret
= 0;
3354 task
->tk_status
= 0;
3355 rpc_restart_call_prepare(task
);
3359 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
3361 struct nfs4_closedata
*calldata
= data
;
3362 struct nfs4_state
*state
= calldata
->state
;
3363 struct inode
*inode
= calldata
->inode
;
3364 struct pnfs_layout_hdr
*lo
;
3365 bool is_rdonly
, is_wronly
, is_rdwr
;
3368 dprintk("%s: begin!\n", __func__
);
3369 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3372 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
3373 spin_lock(&state
->owner
->so_lock
);
3374 is_rdwr
= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
3375 is_rdonly
= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
3376 is_wronly
= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
3377 /* Calculate the change in open mode */
3378 calldata
->arg
.fmode
= 0;
3379 if (state
->n_rdwr
== 0) {
3380 if (state
->n_rdonly
== 0)
3381 call_close
|= is_rdonly
;
3383 calldata
->arg
.fmode
|= FMODE_READ
;
3384 if (state
->n_wronly
== 0)
3385 call_close
|= is_wronly
;
3387 calldata
->arg
.fmode
|= FMODE_WRITE
;
3388 if (calldata
->arg
.fmode
!= (FMODE_READ
|FMODE_WRITE
))
3389 call_close
|= is_rdwr
;
3391 calldata
->arg
.fmode
|= FMODE_READ
|FMODE_WRITE
;
3393 if (!nfs4_valid_open_stateid(state
) ||
3394 !nfs4_refresh_open_stateid(&calldata
->arg
.stateid
, state
))
3396 spin_unlock(&state
->owner
->so_lock
);
3399 /* Note: exit _without_ calling nfs4_close_done */
3403 if (!calldata
->lr
.roc
&& nfs4_wait_on_layoutreturn(inode
, task
)) {
3404 nfs_release_seqid(calldata
->arg
.seqid
);
3408 lo
= calldata
->arg
.lr_args
? calldata
->arg
.lr_args
->layout
: NULL
;
3409 if (lo
&& !pnfs_layout_is_valid(lo
)) {
3410 calldata
->arg
.lr_args
= NULL
;
3411 calldata
->res
.lr_res
= NULL
;
3414 if (calldata
->arg
.fmode
== 0)
3415 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
3417 if (calldata
->arg
.fmode
== 0 || calldata
->arg
.fmode
== FMODE_READ
) {
3418 /* Close-to-open cache consistency revalidation */
3419 if (!nfs4_have_delegation(inode
, FMODE_READ
))
3420 calldata
->arg
.bitmask
= NFS_SERVER(inode
)->cache_consistency_bitmask
;
3422 calldata
->arg
.bitmask
= NULL
;
3425 calldata
->arg
.share_access
=
3426 nfs4_map_atomic_open_share(NFS_SERVER(inode
),
3427 calldata
->arg
.fmode
, 0);
3429 if (calldata
->res
.fattr
== NULL
)
3430 calldata
->arg
.bitmask
= NULL
;
3431 else if (calldata
->arg
.bitmask
== NULL
)
3432 calldata
->res
.fattr
= NULL
;
3433 calldata
->timestamp
= jiffies
;
3434 if (nfs4_setup_sequence(NFS_SERVER(inode
)->nfs_client
,
3435 &calldata
->arg
.seq_args
,
3436 &calldata
->res
.seq_res
,
3438 nfs_release_seqid(calldata
->arg
.seqid
);
3439 dprintk("%s: done!\n", __func__
);
3442 task
->tk_action
= NULL
;
3444 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
3447 static const struct rpc_call_ops nfs4_close_ops
= {
3448 .rpc_call_prepare
= nfs4_close_prepare
,
3449 .rpc_call_done
= nfs4_close_done
,
3450 .rpc_release
= nfs4_free_closedata
,
3454 * It is possible for data to be read/written from a mem-mapped file
3455 * after the sys_close call (which hits the vfs layer as a flush).
3456 * This means that we can't safely call nfsv4 close on a file until
3457 * the inode is cleared. This in turn means that we are not good
3458 * NFSv4 citizens - we do not indicate to the server to update the file's
3459 * share state even when we are done with one of the three share
3460 * stateid's in the inode.
3462 * NOTE: Caller must be holding the sp->so_owner semaphore!
3464 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
3466 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3467 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
3468 struct nfs4_closedata
*calldata
;
3469 struct nfs4_state_owner
*sp
= state
->owner
;
3470 struct rpc_task
*task
;
3471 struct rpc_message msg
= {
3472 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
3473 .rpc_cred
= state
->owner
->so_cred
,
3475 struct rpc_task_setup task_setup_data
= {
3476 .rpc_client
= server
->client
,
3477 .rpc_message
= &msg
,
3478 .callback_ops
= &nfs4_close_ops
,
3479 .workqueue
= nfsiod_workqueue
,
3480 .flags
= RPC_TASK_ASYNC
,
3482 int status
= -ENOMEM
;
3484 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_CLEANUP
,
3485 &task_setup_data
.rpc_client
, &msg
);
3487 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
3488 if (calldata
== NULL
)
3490 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1, 0);
3491 calldata
->inode
= state
->inode
;
3492 calldata
->state
= state
;
3493 calldata
->arg
.fh
= NFS_FH(state
->inode
);
3494 if (!nfs4_copy_open_stateid(&calldata
->arg
.stateid
, state
))
3495 goto out_free_calldata
;
3496 /* Serialization for the sequence id */
3497 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
3498 calldata
->arg
.seqid
= alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
3499 if (IS_ERR(calldata
->arg
.seqid
))
3500 goto out_free_calldata
;
3501 nfs_fattr_init(&calldata
->fattr
);
3502 calldata
->arg
.fmode
= 0;
3503 calldata
->lr
.arg
.ld_private
= &calldata
->lr
.ld_private
;
3504 calldata
->res
.fattr
= &calldata
->fattr
;
3505 calldata
->res
.seqid
= calldata
->arg
.seqid
;
3506 calldata
->res
.server
= server
;
3507 calldata
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
3508 calldata
->lr
.roc
= pnfs_roc(state
->inode
,
3509 &calldata
->lr
.arg
, &calldata
->lr
.res
, msg
.rpc_cred
);
3510 if (calldata
->lr
.roc
) {
3511 calldata
->arg
.lr_args
= &calldata
->lr
.arg
;
3512 calldata
->res
.lr_res
= &calldata
->lr
.res
;
3514 nfs_sb_active(calldata
->inode
->i_sb
);
3516 msg
.rpc_argp
= &calldata
->arg
;
3517 msg
.rpc_resp
= &calldata
->res
;
3518 task_setup_data
.callback_data
= calldata
;
3519 task
= rpc_run_task(&task_setup_data
);
3521 return PTR_ERR(task
);
3524 status
= rpc_wait_for_completion_task(task
);
3530 nfs4_put_open_state(state
);
3531 nfs4_put_state_owner(sp
);
3535 static struct inode
*
3536 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
,
3537 int open_flags
, struct iattr
*attr
, int *opened
)
3539 struct nfs4_state
*state
;
3540 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
3542 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
3544 /* Protect against concurrent sillydeletes */
3545 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
, opened
);
3547 nfs4_label_release_security(label
);
3550 return ERR_CAST(state
);
3551 return state
->inode
;
3554 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
3556 if (ctx
->state
== NULL
)
3559 nfs4_close_sync(ctx
->state
, ctx
->mode
);
3561 nfs4_close_state(ctx
->state
, ctx
->mode
);
3564 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
3565 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
3566 #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_MODE_UMASK - 1UL)
3568 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
3570 u32 bitmask
[3] = {}, minorversion
= server
->nfs_client
->cl_minorversion
;
3571 struct nfs4_server_caps_arg args
= {
3575 struct nfs4_server_caps_res res
= {};
3576 struct rpc_message msg
= {
3577 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
3584 bitmask
[0] = FATTR4_WORD0_SUPPORTED_ATTRS
|
3585 FATTR4_WORD0_FH_EXPIRE_TYPE
|
3586 FATTR4_WORD0_LINK_SUPPORT
|
3587 FATTR4_WORD0_SYMLINK_SUPPORT
|
3588 FATTR4_WORD0_ACLSUPPORT
;
3590 bitmask
[2] = FATTR4_WORD2_SUPPATTR_EXCLCREAT
;
3592 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3594 /* Sanity check the server answers */
3595 switch (minorversion
) {
3597 res
.attr_bitmask
[1] &= FATTR4_WORD1_NFS40_MASK
;
3598 res
.attr_bitmask
[2] = 0;
3601 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS41_MASK
;
3604 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS42_MASK
;
3606 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
3607 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
3608 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
3609 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
3610 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
3611 NFS_CAP_CTIME
|NFS_CAP_MTIME
|
3612 NFS_CAP_SECURITY_LABEL
);
3613 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
&&
3614 res
.acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3615 server
->caps
|= NFS_CAP_ACLS
;
3616 if (res
.has_links
!= 0)
3617 server
->caps
|= NFS_CAP_HARDLINKS
;
3618 if (res
.has_symlinks
!= 0)
3619 server
->caps
|= NFS_CAP_SYMLINKS
;
3620 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
3621 server
->caps
|= NFS_CAP_FILEID
;
3622 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
3623 server
->caps
|= NFS_CAP_MODE
;
3624 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
3625 server
->caps
|= NFS_CAP_NLINK
;
3626 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
3627 server
->caps
|= NFS_CAP_OWNER
;
3628 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
3629 server
->caps
|= NFS_CAP_OWNER_GROUP
;
3630 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
3631 server
->caps
|= NFS_CAP_ATIME
;
3632 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
3633 server
->caps
|= NFS_CAP_CTIME
;
3634 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
3635 server
->caps
|= NFS_CAP_MTIME
;
3636 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
3637 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
3638 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
3640 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
3641 sizeof(server
->attr_bitmask
));
3642 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
3644 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
3645 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
3646 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
3647 server
->cache_consistency_bitmask
[2] = 0;
3649 /* Avoid a regression due to buggy server */
3650 for (i
= 0; i
< ARRAY_SIZE(res
.exclcreat_bitmask
); i
++)
3651 res
.exclcreat_bitmask
[i
] &= res
.attr_bitmask
[i
];
3652 memcpy(server
->exclcreat_bitmask
, res
.exclcreat_bitmask
,
3653 sizeof(server
->exclcreat_bitmask
));
3655 server
->acl_bitmask
= res
.acl_bitmask
;
3656 server
->fh_expire_type
= res
.fh_expire_type
;
3662 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
3664 struct nfs4_exception exception
= { };
3667 err
= nfs4_handle_exception(server
,
3668 _nfs4_server_capabilities(server
, fhandle
),
3670 } while (exception
.retry
);
3674 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3675 struct nfs_fsinfo
*info
)
3678 struct nfs4_lookup_root_arg args
= {
3681 struct nfs4_lookup_res res
= {
3683 .fattr
= info
->fattr
,
3686 struct rpc_message msg
= {
3687 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
3692 bitmask
[0] = nfs4_fattr_bitmap
[0];
3693 bitmask
[1] = nfs4_fattr_bitmap
[1];
3695 * Process the label in the upcoming getfattr
3697 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
3699 nfs_fattr_init(info
->fattr
);
3700 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3703 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3704 struct nfs_fsinfo
*info
)
3706 struct nfs4_exception exception
= { };
3709 err
= _nfs4_lookup_root(server
, fhandle
, info
);
3710 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
3713 case -NFS4ERR_WRONGSEC
:
3716 err
= nfs4_handle_exception(server
, err
, &exception
);
3718 } while (exception
.retry
);
3723 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3724 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
3726 struct rpc_auth_create_args auth_args
= {
3727 .pseudoflavor
= flavor
,
3729 struct rpc_auth
*auth
;
3731 auth
= rpcauth_create(&auth_args
, server
->client
);
3734 return nfs4_lookup_root(server
, fhandle
, info
);
3738 * Retry pseudoroot lookup with various security flavors. We do this when:
3740 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
3741 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
3743 * Returns zero on success, or a negative NFS4ERR value, or a
3744 * negative errno value.
3746 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3747 struct nfs_fsinfo
*info
)
3749 /* Per 3530bis 15.33.5 */
3750 static const rpc_authflavor_t flav_array
[] = {
3754 RPC_AUTH_UNIX
, /* courtesy */
3757 int status
= -EPERM
;
3760 if (server
->auth_info
.flavor_len
> 0) {
3761 /* try each flavor specified by user */
3762 for (i
= 0; i
< server
->auth_info
.flavor_len
; i
++) {
3763 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3764 server
->auth_info
.flavors
[i
]);
3765 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3770 /* no flavors specified by user, try default list */
3771 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
3772 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3774 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3781 * -EACCESS could mean that the user doesn't have correct permissions
3782 * to access the mount. It could also mean that we tried to mount
3783 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
3784 * existing mount programs don't handle -EACCES very well so it should
3785 * be mapped to -EPERM instead.
3787 if (status
== -EACCES
)
3793 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
3794 * @server: initialized nfs_server handle
3795 * @fhandle: we fill in the pseudo-fs root file handle
3796 * @info: we fill in an FSINFO struct
3797 * @auth_probe: probe the auth flavours
3799 * Returns zero on success, or a negative errno.
3801 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3802 struct nfs_fsinfo
*info
,
3808 status
= nfs4_lookup_root(server
, fhandle
, info
);
3810 if (auth_probe
|| status
== NFS4ERR_WRONGSEC
)
3811 status
= server
->nfs_client
->cl_mvops
->find_root_sec(server
,
3815 status
= nfs4_server_capabilities(server
, fhandle
);
3817 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
3819 return nfs4_map_errors(status
);
3822 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
3823 struct nfs_fsinfo
*info
)
3826 struct nfs_fattr
*fattr
= info
->fattr
;
3827 struct nfs4_label
*label
= NULL
;
3829 error
= nfs4_server_capabilities(server
, mntfh
);
3831 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
3835 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3837 return PTR_ERR(label
);
3839 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
, NULL
);
3841 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
3842 goto err_free_label
;
3845 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
3846 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
3847 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
3850 nfs4_label_free(label
);
3856 * Get locations and (maybe) other attributes of a referral.
3857 * Note that we'll actually follow the referral later when
3858 * we detect fsid mismatch in inode revalidation
3860 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
3861 const struct qstr
*name
, struct nfs_fattr
*fattr
,
3862 struct nfs_fh
*fhandle
)
3864 int status
= -ENOMEM
;
3865 struct page
*page
= NULL
;
3866 struct nfs4_fs_locations
*locations
= NULL
;
3868 page
= alloc_page(GFP_KERNEL
);
3871 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
3872 if (locations
== NULL
)
3875 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
3880 * If the fsid didn't change, this is a migration event, not a
3881 * referral. Cause us to drop into the exception handler, which
3882 * will kick off migration recovery.
3884 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
3885 dprintk("%s: server did not return a different fsid for"
3886 " a referral at %s\n", __func__
, name
->name
);
3887 status
= -NFS4ERR_MOVED
;
3890 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3891 nfs_fixup_referral_attributes(&locations
->fattr
);
3893 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3894 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
3895 memset(fhandle
, 0, sizeof(struct nfs_fh
));
3903 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3904 struct nfs_fattr
*fattr
, struct nfs4_label
*label
,
3905 struct inode
*inode
)
3907 __u32 bitmask
[NFS4_BITMASK_SZ
];
3908 struct nfs4_getattr_arg args
= {
3912 struct nfs4_getattr_res res
= {
3917 struct rpc_message msg
= {
3918 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
3923 nfs4_bitmap_copy_adjust(bitmask
, nfs4_bitmask(server
, label
), inode
);
3925 nfs_fattr_init(fattr
);
3926 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3929 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3930 struct nfs_fattr
*fattr
, struct nfs4_label
*label
,
3931 struct inode
*inode
)
3933 struct nfs4_exception exception
= { };
3936 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
, inode
);
3937 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
3938 err
= nfs4_handle_exception(server
, err
,
3940 } while (exception
.retry
);
3945 * The file is not closed if it is opened due to the a request to change
3946 * the size of the file. The open call will not be needed once the
3947 * VFS layer lookup-intents are implemented.
3949 * Close is called when the inode is destroyed.
3950 * If we haven't opened the file for O_WRONLY, we
3951 * need to in the size_change case to obtain a stateid.
3954 * Because OPEN is always done by name in nfsv4, it is
3955 * possible that we opened a different file by the same
3956 * name. We can recognize this race condition, but we
3957 * can't do anything about it besides returning an error.
3959 * This will be fixed with VFS changes (lookup-intent).
3962 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
3963 struct iattr
*sattr
)
3965 struct inode
*inode
= d_inode(dentry
);
3966 struct rpc_cred
*cred
= NULL
;
3967 struct nfs_open_context
*ctx
= NULL
;
3968 struct nfs4_label
*label
= NULL
;
3971 if (pnfs_ld_layoutret_on_setattr(inode
) &&
3972 sattr
->ia_valid
& ATTR_SIZE
&&
3973 sattr
->ia_size
< i_size_read(inode
))
3974 pnfs_commit_and_return_layout(inode
);
3976 nfs_fattr_init(fattr
);
3978 /* Deal with open(O_TRUNC) */
3979 if (sattr
->ia_valid
& ATTR_OPEN
)
3980 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
3982 /* Optimization: if the end result is no change, don't RPC */
3983 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
3986 /* Search for an existing open(O_WRITE) file */
3987 if (sattr
->ia_valid
& ATTR_FILE
) {
3989 ctx
= nfs_file_open_context(sattr
->ia_file
);
3994 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
3996 return PTR_ERR(label
);
3998 /* Return any delegations if we're going to change ACLs */
3999 if ((sattr
->ia_valid
& (ATTR_MODE
|ATTR_UID
|ATTR_GID
)) != 0)
4000 nfs4_inode_make_writeable(inode
);
4002 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, ctx
, NULL
, label
);
4004 nfs_setattr_update_inode(inode
, sattr
, fattr
);
4005 nfs_setsecurity(inode
, fattr
, label
);
4007 nfs4_label_free(label
);
4011 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
4012 const struct qstr
*name
, struct nfs_fh
*fhandle
,
4013 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4015 struct nfs_server
*server
= NFS_SERVER(dir
);
4017 struct nfs4_lookup_arg args
= {
4018 .bitmask
= server
->attr_bitmask
,
4019 .dir_fh
= NFS_FH(dir
),
4022 struct nfs4_lookup_res res
= {
4028 struct rpc_message msg
= {
4029 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
4034 args
.bitmask
= nfs4_bitmask(server
, label
);
4036 nfs_fattr_init(fattr
);
4038 dprintk("NFS call lookup %s\n", name
->name
);
4039 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4040 dprintk("NFS reply lookup: %d\n", status
);
4044 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
4046 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4047 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
4048 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4052 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
4053 const struct qstr
*name
, struct nfs_fh
*fhandle
,
4054 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4056 struct nfs4_exception exception
= { };
4057 struct rpc_clnt
*client
= *clnt
;
4060 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
4061 trace_nfs4_lookup(dir
, name
, err
);
4063 case -NFS4ERR_BADNAME
:
4066 case -NFS4ERR_MOVED
:
4067 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
4068 if (err
== -NFS4ERR_MOVED
)
4069 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
4071 case -NFS4ERR_WRONGSEC
:
4073 if (client
!= *clnt
)
4075 client
= nfs4_negotiate_security(client
, dir
, name
);
4077 return PTR_ERR(client
);
4079 exception
.retry
= 1;
4082 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
4084 } while (exception
.retry
);
4089 else if (client
!= *clnt
)
4090 rpc_shutdown_client(client
);
4095 static int nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
4096 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
4097 struct nfs4_label
*label
)
4100 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
4102 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
4103 if (client
!= NFS_CLIENT(dir
)) {
4104 rpc_shutdown_client(client
);
4105 nfs_fixup_secinfo_attributes(fattr
);
4111 nfs4_proc_lookup_mountpoint(struct inode
*dir
, const struct qstr
*name
,
4112 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
4114 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
4117 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
4119 return ERR_PTR(status
);
4120 return (client
== NFS_CLIENT(dir
)) ? rpc_clone_client(client
) : client
;
4123 static int _nfs4_proc_lookupp(struct inode
*inode
,
4124 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
4125 struct nfs4_label
*label
)
4127 struct rpc_clnt
*clnt
= NFS_CLIENT(inode
);
4128 struct nfs_server
*server
= NFS_SERVER(inode
);
4130 struct nfs4_lookupp_arg args
= {
4131 .bitmask
= server
->attr_bitmask
,
4132 .fh
= NFS_FH(inode
),
4134 struct nfs4_lookupp_res res
= {
4140 struct rpc_message msg
= {
4141 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUPP
],
4146 args
.bitmask
= nfs4_bitmask(server
, label
);
4148 nfs_fattr_init(fattr
);
4150 dprintk("NFS call lookupp ino=0x%lx\n", inode
->i_ino
);
4151 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
4153 dprintk("NFS reply lookupp: %d\n", status
);
4157 static int nfs4_proc_lookupp(struct inode
*inode
, struct nfs_fh
*fhandle
,
4158 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
4160 struct nfs4_exception exception
= { };
4163 err
= _nfs4_proc_lookupp(inode
, fhandle
, fattr
, label
);
4164 trace_nfs4_lookupp(inode
, err
);
4165 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4167 } while (exception
.retry
);
4171 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
4173 struct nfs_server
*server
= NFS_SERVER(inode
);
4174 struct nfs4_accessargs args
= {
4175 .fh
= NFS_FH(inode
),
4176 .access
= entry
->mask
,
4178 struct nfs4_accessres res
= {
4181 struct rpc_message msg
= {
4182 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
4185 .rpc_cred
= entry
->cred
,
4189 if (!nfs4_have_delegation(inode
, FMODE_READ
)) {
4190 res
.fattr
= nfs_alloc_fattr();
4191 if (res
.fattr
== NULL
)
4193 args
.bitmask
= server
->cache_consistency_bitmask
;
4196 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4198 nfs_access_set_mask(entry
, res
.access
);
4200 nfs_refresh_inode(inode
, res
.fattr
);
4202 nfs_free_fattr(res
.fattr
);
4206 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
4208 struct nfs4_exception exception
= { };
4211 err
= _nfs4_proc_access(inode
, entry
);
4212 trace_nfs4_access(inode
, err
);
4213 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4215 } while (exception
.retry
);
4220 * TODO: For the time being, we don't try to get any attributes
4221 * along with any of the zero-copy operations READ, READDIR,
4224 * In the case of the first three, we want to put the GETATTR
4225 * after the read-type operation -- this is because it is hard
4226 * to predict the length of a GETATTR response in v4, and thus
4227 * align the READ data correctly. This means that the GETATTR
4228 * may end up partially falling into the page cache, and we should
4229 * shift it into the 'tail' of the xdr_buf before processing.
4230 * To do this efficiently, we need to know the total length
4231 * of data received, which doesn't seem to be available outside
4234 * In the case of WRITE, we also want to put the GETATTR after
4235 * the operation -- in this case because we want to make sure
4236 * we get the post-operation mtime and size.
4238 * Both of these changes to the XDR layer would in fact be quite
4239 * minor, but I decided to leave them for a subsequent patch.
4241 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
4242 unsigned int pgbase
, unsigned int pglen
)
4244 struct nfs4_readlink args
= {
4245 .fh
= NFS_FH(inode
),
4250 struct nfs4_readlink_res res
;
4251 struct rpc_message msg
= {
4252 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
4257 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4260 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
4261 unsigned int pgbase
, unsigned int pglen
)
4263 struct nfs4_exception exception
= { };
4266 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
4267 trace_nfs4_readlink(inode
, err
);
4268 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4270 } while (exception
.retry
);
4275 * This is just for mknod. open(O_CREAT) will always do ->open_context().
4278 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
4281 struct nfs_server
*server
= NFS_SERVER(dir
);
4282 struct nfs4_label l
, *ilabel
= NULL
;
4283 struct nfs_open_context
*ctx
;
4284 struct nfs4_state
*state
;
4287 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
, NULL
);
4289 return PTR_ERR(ctx
);
4291 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4293 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4294 sattr
->ia_mode
&= ~current_umask();
4295 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
, NULL
);
4296 if (IS_ERR(state
)) {
4297 status
= PTR_ERR(state
);
4301 nfs4_label_release_security(ilabel
);
4302 put_nfs_open_context(ctx
);
4307 _nfs4_proc_remove(struct inode
*dir
, const struct qstr
*name
, u32 ftype
)
4309 struct nfs_server
*server
= NFS_SERVER(dir
);
4310 struct nfs_removeargs args
= {
4314 struct nfs_removeres res
= {
4317 struct rpc_message msg
= {
4318 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
4322 unsigned long timestamp
= jiffies
;
4325 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
4327 spin_lock(&dir
->i_lock
);
4328 update_changeattr_locked(dir
, &res
.cinfo
, timestamp
, 0);
4329 /* Removing a directory decrements nlink in the parent */
4330 if (ftype
== NF4DIR
&& dir
->i_nlink
> 2)
4331 nfs4_dec_nlink_locked(dir
);
4332 spin_unlock(&dir
->i_lock
);
4337 static int nfs4_proc_remove(struct inode
*dir
, struct dentry
*dentry
)
4339 struct nfs4_exception exception
= { };
4340 struct inode
*inode
= d_inode(dentry
);
4344 if (inode
->i_nlink
== 1)
4345 nfs4_inode_return_delegation(inode
);
4347 nfs4_inode_make_writeable(inode
);
4350 err
= _nfs4_proc_remove(dir
, &dentry
->d_name
, NF4REG
);
4351 trace_nfs4_remove(dir
, &dentry
->d_name
, err
);
4352 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4354 } while (exception
.retry
);
4358 static int nfs4_proc_rmdir(struct inode
*dir
, const struct qstr
*name
)
4360 struct nfs4_exception exception
= { };
4364 err
= _nfs4_proc_remove(dir
, name
, NF4DIR
);
4365 trace_nfs4_remove(dir
, name
, err
);
4366 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4368 } while (exception
.retry
);
4372 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
,
4373 struct dentry
*dentry
,
4374 struct inode
*inode
)
4376 struct nfs_removeargs
*args
= msg
->rpc_argp
;
4377 struct nfs_removeres
*res
= msg
->rpc_resp
;
4379 res
->server
= NFS_SB(dentry
->d_sb
);
4380 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
4381 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1, 0);
4383 nfs_fattr_init(res
->dir_attr
);
4386 nfs4_inode_return_delegation(inode
);
4389 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
4391 nfs4_setup_sequence(NFS_SB(data
->dentry
->d_sb
)->nfs_client
,
4392 &data
->args
.seq_args
,
4397 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
4399 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
4400 struct nfs_removeres
*res
= &data
->res
;
4402 if (!nfs4_sequence_done(task
, &res
->seq_res
))
4404 if (nfs4_async_handle_error(task
, res
->server
, NULL
,
4405 &data
->timeout
) == -EAGAIN
)
4407 if (task
->tk_status
== 0)
4408 update_changeattr(dir
, &res
->cinfo
,
4409 res
->dir_attr
->time_start
, 0);
4413 static void nfs4_proc_rename_setup(struct rpc_message
*msg
,
4414 struct dentry
*old_dentry
,
4415 struct dentry
*new_dentry
)
4417 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
4418 struct nfs_renameres
*res
= msg
->rpc_resp
;
4419 struct inode
*old_inode
= d_inode(old_dentry
);
4420 struct inode
*new_inode
= d_inode(new_dentry
);
4423 nfs4_inode_make_writeable(old_inode
);
4425 nfs4_inode_return_delegation(new_inode
);
4426 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
4427 res
->server
= NFS_SB(old_dentry
->d_sb
);
4428 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1, 0);
4431 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
4433 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
)->nfs_client
,
4434 &data
->args
.seq_args
,
4439 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
4440 struct inode
*new_dir
)
4442 struct nfs_renamedata
*data
= task
->tk_calldata
;
4443 struct nfs_renameres
*res
= &data
->res
;
4445 if (!nfs4_sequence_done(task
, &res
->seq_res
))
4447 if (nfs4_async_handle_error(task
, res
->server
, NULL
, &data
->timeout
) == -EAGAIN
)
4450 if (task
->tk_status
== 0) {
4451 if (new_dir
!= old_dir
) {
4452 /* Note: If we moved a directory, nlink will change */
4453 update_changeattr(old_dir
, &res
->old_cinfo
,
4454 res
->old_fattr
->time_start
,
4455 NFS_INO_INVALID_OTHER
);
4456 update_changeattr(new_dir
, &res
->new_cinfo
,
4457 res
->new_fattr
->time_start
,
4458 NFS_INO_INVALID_OTHER
);
4460 update_changeattr(old_dir
, &res
->old_cinfo
,
4461 res
->old_fattr
->time_start
,
4467 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
4469 struct nfs_server
*server
= NFS_SERVER(inode
);
4470 __u32 bitmask
[NFS4_BITMASK_SZ
];
4471 struct nfs4_link_arg arg
= {
4472 .fh
= NFS_FH(inode
),
4473 .dir_fh
= NFS_FH(dir
),
4477 struct nfs4_link_res res
= {
4481 struct rpc_message msg
= {
4482 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
4486 int status
= -ENOMEM
;
4488 res
.fattr
= nfs_alloc_fattr();
4489 if (res
.fattr
== NULL
)
4492 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
4493 if (IS_ERR(res
.label
)) {
4494 status
= PTR_ERR(res
.label
);
4498 nfs4_inode_make_writeable(inode
);
4499 nfs4_bitmap_copy_adjust_setattr(bitmask
, nfs4_bitmask(server
, res
.label
), inode
);
4501 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4503 update_changeattr(dir
, &res
.cinfo
, res
.fattr
->time_start
, 0);
4504 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
4506 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
4510 nfs4_label_free(res
.label
);
4513 nfs_free_fattr(res
.fattr
);
4517 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, const struct qstr
*name
)
4519 struct nfs4_exception exception
= { };
4522 err
= nfs4_handle_exception(NFS_SERVER(inode
),
4523 _nfs4_proc_link(inode
, dir
, name
),
4525 } while (exception
.retry
);
4529 struct nfs4_createdata
{
4530 struct rpc_message msg
;
4531 struct nfs4_create_arg arg
;
4532 struct nfs4_create_res res
;
4534 struct nfs_fattr fattr
;
4535 struct nfs4_label
*label
;
4538 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
4539 const struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
4541 struct nfs4_createdata
*data
;
4543 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
4545 struct nfs_server
*server
= NFS_SERVER(dir
);
4547 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
4548 if (IS_ERR(data
->label
))
4551 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
4552 data
->msg
.rpc_argp
= &data
->arg
;
4553 data
->msg
.rpc_resp
= &data
->res
;
4554 data
->arg
.dir_fh
= NFS_FH(dir
);
4555 data
->arg
.server
= server
;
4556 data
->arg
.name
= name
;
4557 data
->arg
.attrs
= sattr
;
4558 data
->arg
.ftype
= ftype
;
4559 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
4560 data
->arg
.umask
= current_umask();
4561 data
->res
.server
= server
;
4562 data
->res
.fh
= &data
->fh
;
4563 data
->res
.fattr
= &data
->fattr
;
4564 data
->res
.label
= data
->label
;
4565 nfs_fattr_init(data
->res
.fattr
);
4573 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
4575 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
4576 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
4578 spin_lock(&dir
->i_lock
);
4579 update_changeattr_locked(dir
, &data
->res
.dir_cinfo
,
4580 data
->res
.fattr
->time_start
, 0);
4581 /* Creating a directory bumps nlink in the parent */
4582 if (data
->arg
.ftype
== NF4DIR
)
4583 nfs4_inc_nlink_locked(dir
);
4584 spin_unlock(&dir
->i_lock
);
4585 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
4590 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
4592 nfs4_label_free(data
->label
);
4596 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
4597 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
4598 struct nfs4_label
*label
)
4600 struct nfs4_createdata
*data
;
4601 int status
= -ENAMETOOLONG
;
4603 if (len
> NFS4_MAXPATHLEN
)
4607 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
4611 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
4612 data
->arg
.u
.symlink
.pages
= &page
;
4613 data
->arg
.u
.symlink
.len
= len
;
4614 data
->arg
.label
= label
;
4616 status
= nfs4_do_create(dir
, dentry
, data
);
4618 nfs4_free_createdata(data
);
4623 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
4624 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
4626 struct nfs4_exception exception
= { };
4627 struct nfs4_label l
, *label
= NULL
;
4630 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4633 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
4634 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
4635 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4637 } while (exception
.retry
);
4639 nfs4_label_release_security(label
);
4643 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
4644 struct iattr
*sattr
, struct nfs4_label
*label
)
4646 struct nfs4_createdata
*data
;
4647 int status
= -ENOMEM
;
4649 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
4653 data
->arg
.label
= label
;
4654 status
= nfs4_do_create(dir
, dentry
, data
);
4656 nfs4_free_createdata(data
);
4661 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
4662 struct iattr
*sattr
)
4664 struct nfs_server
*server
= NFS_SERVER(dir
);
4665 struct nfs4_exception exception
= { };
4666 struct nfs4_label l
, *label
= NULL
;
4669 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4671 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4672 sattr
->ia_mode
&= ~current_umask();
4674 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
4675 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
4676 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4678 } while (exception
.retry
);
4679 nfs4_label_release_security(label
);
4684 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
4685 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
4687 struct inode
*dir
= d_inode(dentry
);
4688 struct nfs4_readdir_arg args
= {
4693 .bitmask
= NFS_SERVER(d_inode(dentry
))->attr_bitmask
,
4696 struct nfs4_readdir_res res
;
4697 struct rpc_message msg
= {
4698 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
4705 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__
,
4707 (unsigned long long)cookie
);
4708 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
4709 res
.pgbase
= args
.pgbase
;
4710 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4712 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
4713 status
+= args
.pgbase
;
4716 nfs_invalidate_atime(dir
);
4718 dprintk("%s: returns %d\n", __func__
, status
);
4722 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
4723 u64 cookie
, struct page
**pages
, unsigned int count
, bool plus
)
4725 struct nfs4_exception exception
= { };
4728 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
4729 pages
, count
, plus
);
4730 trace_nfs4_readdir(d_inode(dentry
), err
);
4731 err
= nfs4_handle_exception(NFS_SERVER(d_inode(dentry
)), err
,
4733 } while (exception
.retry
);
4737 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
4738 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
4740 struct nfs4_createdata
*data
;
4741 int mode
= sattr
->ia_mode
;
4742 int status
= -ENOMEM
;
4744 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
4749 data
->arg
.ftype
= NF4FIFO
;
4750 else if (S_ISBLK(mode
)) {
4751 data
->arg
.ftype
= NF4BLK
;
4752 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
4753 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
4755 else if (S_ISCHR(mode
)) {
4756 data
->arg
.ftype
= NF4CHR
;
4757 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
4758 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
4759 } else if (!S_ISSOCK(mode
)) {
4764 data
->arg
.label
= label
;
4765 status
= nfs4_do_create(dir
, dentry
, data
);
4767 nfs4_free_createdata(data
);
4772 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
4773 struct iattr
*sattr
, dev_t rdev
)
4775 struct nfs_server
*server
= NFS_SERVER(dir
);
4776 struct nfs4_exception exception
= { };
4777 struct nfs4_label l
, *label
= NULL
;
4780 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
4782 if (!(server
->attr_bitmask
[2] & FATTR4_WORD2_MODE_UMASK
))
4783 sattr
->ia_mode
&= ~current_umask();
4785 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
4786 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
4787 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
4789 } while (exception
.retry
);
4791 nfs4_label_release_security(label
);
4796 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4797 struct nfs_fsstat
*fsstat
)
4799 struct nfs4_statfs_arg args
= {
4801 .bitmask
= server
->attr_bitmask
,
4803 struct nfs4_statfs_res res
= {
4806 struct rpc_message msg
= {
4807 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
4812 nfs_fattr_init(fsstat
->fattr
);
4813 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4816 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
4818 struct nfs4_exception exception
= { };
4821 err
= nfs4_handle_exception(server
,
4822 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
4824 } while (exception
.retry
);
4828 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4829 struct nfs_fsinfo
*fsinfo
)
4831 struct nfs4_fsinfo_arg args
= {
4833 .bitmask
= server
->attr_bitmask
,
4835 struct nfs4_fsinfo_res res
= {
4838 struct rpc_message msg
= {
4839 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
4844 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4847 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4849 struct nfs4_exception exception
= { };
4850 unsigned long now
= jiffies
;
4854 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4855 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
4857 nfs4_set_lease_period(server
->nfs_client
,
4858 fsinfo
->lease_time
* HZ
,
4862 err
= nfs4_handle_exception(server
, err
, &exception
);
4863 } while (exception
.retry
);
4867 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4871 nfs_fattr_init(fsinfo
->fattr
);
4872 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4874 /* block layout checks this! */
4875 server
->pnfs_blksize
= fsinfo
->blksize
;
4876 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
);
4882 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4883 struct nfs_pathconf
*pathconf
)
4885 struct nfs4_pathconf_arg args
= {
4887 .bitmask
= server
->attr_bitmask
,
4889 struct nfs4_pathconf_res res
= {
4890 .pathconf
= pathconf
,
4892 struct rpc_message msg
= {
4893 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
4898 /* None of the pathconf attributes are mandatory to implement */
4899 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
4900 memset(pathconf
, 0, sizeof(*pathconf
));
4904 nfs_fattr_init(pathconf
->fattr
);
4905 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4908 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4909 struct nfs_pathconf
*pathconf
)
4911 struct nfs4_exception exception
= { };
4915 err
= nfs4_handle_exception(server
,
4916 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
4918 } while (exception
.retry
);
4922 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
4923 const struct nfs_open_context
*ctx
,
4924 const struct nfs_lock_context
*l_ctx
,
4927 return nfs4_select_rw_stateid(ctx
->state
, fmode
, l_ctx
, stateid
, NULL
);
4929 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
4931 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
4932 const struct nfs_open_context
*ctx
,
4933 const struct nfs_lock_context
*l_ctx
,
4936 nfs4_stateid current_stateid
;
4938 /* If the current stateid represents a lost lock, then exit */
4939 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
) == -EIO
)
4941 return nfs4_stateid_match(stateid
, ¤t_stateid
);
4944 static bool nfs4_error_stateid_expired(int err
)
4947 case -NFS4ERR_DELEG_REVOKED
:
4948 case -NFS4ERR_ADMIN_REVOKED
:
4949 case -NFS4ERR_BAD_STATEID
:
4950 case -NFS4ERR_STALE_STATEID
:
4951 case -NFS4ERR_OLD_STATEID
:
4952 case -NFS4ERR_OPENMODE
:
4953 case -NFS4ERR_EXPIRED
:
4959 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4961 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4963 trace_nfs4_read(hdr
, task
->tk_status
);
4964 if (task
->tk_status
< 0) {
4965 struct nfs4_exception exception
= {
4966 .inode
= hdr
->inode
,
4967 .state
= hdr
->args
.context
->state
,
4968 .stateid
= &hdr
->args
.stateid
,
4970 task
->tk_status
= nfs4_async_handle_exception(task
,
4971 server
, task
->tk_status
, &exception
);
4972 if (exception
.retry
) {
4973 rpc_restart_call_prepare(task
);
4978 if (task
->tk_status
> 0)
4979 renew_lease(server
, hdr
->timestamp
);
4983 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
4984 struct nfs_pgio_args
*args
)
4987 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4988 nfs4_stateid_is_current(&args
->stateid
,
4993 rpc_restart_call_prepare(task
);
4997 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
5000 dprintk("--> %s\n", __func__
);
5002 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
5004 if (nfs4_read_stateid_changed(task
, &hdr
->args
))
5006 if (task
->tk_status
> 0)
5007 nfs_invalidate_atime(hdr
->inode
);
5008 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
5009 nfs4_read_done_cb(task
, hdr
);
5012 static void nfs4_proc_read_setup(struct nfs_pgio_header
*hdr
,
5013 struct rpc_message
*msg
)
5015 hdr
->timestamp
= jiffies
;
5016 if (!hdr
->pgio_done_cb
)
5017 hdr
->pgio_done_cb
= nfs4_read_done_cb
;
5018 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
5019 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 0, 0);
5022 static int nfs4_proc_pgio_rpc_prepare(struct rpc_task
*task
,
5023 struct nfs_pgio_header
*hdr
)
5025 if (nfs4_setup_sequence(NFS_SERVER(hdr
->inode
)->nfs_client
,
5026 &hdr
->args
.seq_args
,
5030 if (nfs4_set_rw_stateid(&hdr
->args
.stateid
, hdr
->args
.context
,
5031 hdr
->args
.lock_context
,
5032 hdr
->rw_mode
) == -EIO
)
5034 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
)))
5039 static int nfs4_write_done_cb(struct rpc_task
*task
,
5040 struct nfs_pgio_header
*hdr
)
5042 struct inode
*inode
= hdr
->inode
;
5044 trace_nfs4_write(hdr
, task
->tk_status
);
5045 if (task
->tk_status
< 0) {
5046 struct nfs4_exception exception
= {
5047 .inode
= hdr
->inode
,
5048 .state
= hdr
->args
.context
->state
,
5049 .stateid
= &hdr
->args
.stateid
,
5051 task
->tk_status
= nfs4_async_handle_exception(task
,
5052 NFS_SERVER(inode
), task
->tk_status
,
5054 if (exception
.retry
) {
5055 rpc_restart_call_prepare(task
);
5059 if (task
->tk_status
>= 0) {
5060 renew_lease(NFS_SERVER(inode
), hdr
->timestamp
);
5061 nfs_writeback_update_inode(hdr
);
5066 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
5067 struct nfs_pgio_args
*args
)
5070 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
5071 nfs4_stateid_is_current(&args
->stateid
,
5076 rpc_restart_call_prepare(task
);
5080 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
5082 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
5084 if (nfs4_write_stateid_changed(task
, &hdr
->args
))
5086 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
5087 nfs4_write_done_cb(task
, hdr
);
5091 bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header
*hdr
)
5093 /* Don't request attributes for pNFS or O_DIRECT writes */
5094 if (hdr
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
5096 /* Otherwise, request attributes if and only if we don't hold
5099 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
5102 static void nfs4_proc_write_setup(struct nfs_pgio_header
*hdr
,
5103 struct rpc_message
*msg
,
5104 struct rpc_clnt
**clnt
)
5106 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
5108 if (!nfs4_write_need_cache_consistency_data(hdr
)) {
5109 hdr
->args
.bitmask
= NULL
;
5110 hdr
->res
.fattr
= NULL
;
5112 hdr
->args
.bitmask
= server
->cache_consistency_bitmask
;
5114 if (!hdr
->pgio_done_cb
)
5115 hdr
->pgio_done_cb
= nfs4_write_done_cb
;
5116 hdr
->res
.server
= server
;
5117 hdr
->timestamp
= jiffies
;
5119 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
5120 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 0, 0);
5121 nfs4_state_protect_write(server
->nfs_client
, clnt
, msg
, hdr
);
5124 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5126 nfs4_setup_sequence(NFS_SERVER(data
->inode
)->nfs_client
,
5127 &data
->args
.seq_args
,
5132 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5134 struct inode
*inode
= data
->inode
;
5136 trace_nfs4_commit(data
, task
->tk_status
);
5137 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
),
5138 NULL
, NULL
) == -EAGAIN
) {
5139 rpc_restart_call_prepare(task
);
5145 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
5147 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5149 return data
->commit_done_cb(task
, data
);
5152 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
,
5153 struct rpc_clnt
**clnt
)
5155 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
5157 if (data
->commit_done_cb
== NULL
)
5158 data
->commit_done_cb
= nfs4_commit_done_cb
;
5159 data
->res
.server
= server
;
5160 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
5161 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
5162 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_COMMIT
, clnt
, msg
);
5165 static int _nfs4_proc_commit(struct file
*dst
, struct nfs_commitargs
*args
,
5166 struct nfs_commitres
*res
)
5168 struct inode
*dst_inode
= file_inode(dst
);
5169 struct nfs_server
*server
= NFS_SERVER(dst_inode
);
5170 struct rpc_message msg
= {
5171 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
],
5176 args
->fh
= NFS_FH(dst_inode
);
5177 return nfs4_call_sync(server
->client
, server
, &msg
,
5178 &args
->seq_args
, &res
->seq_res
, 1);
5181 int nfs4_proc_commit(struct file
*dst
, __u64 offset
, __u32 count
, struct nfs_commitres
*res
)
5183 struct nfs_commitargs args
= {
5187 struct nfs_server
*dst_server
= NFS_SERVER(file_inode(dst
));
5188 struct nfs4_exception exception
= { };
5192 status
= _nfs4_proc_commit(dst
, &args
, res
);
5193 status
= nfs4_handle_exception(dst_server
, status
, &exception
);
5194 } while (exception
.retry
);
5199 struct nfs4_renewdata
{
5200 struct nfs_client
*client
;
5201 unsigned long timestamp
;
5205 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
5206 * standalone procedure for queueing an asynchronous RENEW.
5208 static void nfs4_renew_release(void *calldata
)
5210 struct nfs4_renewdata
*data
= calldata
;
5211 struct nfs_client
*clp
= data
->client
;
5213 if (refcount_read(&clp
->cl_count
) > 1)
5214 nfs4_schedule_state_renewal(clp
);
5215 nfs_put_client(clp
);
5219 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
5221 struct nfs4_renewdata
*data
= calldata
;
5222 struct nfs_client
*clp
= data
->client
;
5223 unsigned long timestamp
= data
->timestamp
;
5225 trace_nfs4_renew_async(clp
, task
->tk_status
);
5226 switch (task
->tk_status
) {
5229 case -NFS4ERR_LEASE_MOVED
:
5230 nfs4_schedule_lease_moved_recovery(clp
);
5233 /* Unless we're shutting down, schedule state recovery! */
5234 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
5236 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
5237 nfs4_schedule_lease_recovery(clp
);
5240 nfs4_schedule_path_down_recovery(clp
);
5242 do_renew_lease(clp
, timestamp
);
5245 static const struct rpc_call_ops nfs4_renew_ops
= {
5246 .rpc_call_done
= nfs4_renew_done
,
5247 .rpc_release
= nfs4_renew_release
,
5250 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
5252 struct rpc_message msg
= {
5253 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
5257 struct nfs4_renewdata
*data
;
5259 if (renew_flags
== 0)
5261 if (!refcount_inc_not_zero(&clp
->cl_count
))
5263 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5265 nfs_put_client(clp
);
5269 data
->timestamp
= jiffies
;
5270 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
5271 &nfs4_renew_ops
, data
);
5274 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5276 struct rpc_message msg
= {
5277 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
5281 unsigned long now
= jiffies
;
5284 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5287 do_renew_lease(clp
, now
);
5291 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
5293 return server
->caps
& NFS_CAP_ACLS
;
5296 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
5297 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
5300 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
5302 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
5303 struct page
**pages
)
5305 struct page
*newpage
, **spages
;
5311 len
= min_t(size_t, PAGE_SIZE
, buflen
);
5312 newpage
= alloc_page(GFP_KERNEL
);
5314 if (newpage
== NULL
)
5316 memcpy(page_address(newpage
), buf
, len
);
5321 } while (buflen
!= 0);
5327 __free_page(spages
[rc
-1]);
5331 struct nfs4_cached_acl
{
5337 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
5339 struct nfs_inode
*nfsi
= NFS_I(inode
);
5341 spin_lock(&inode
->i_lock
);
5342 kfree(nfsi
->nfs4_acl
);
5343 nfsi
->nfs4_acl
= acl
;
5344 spin_unlock(&inode
->i_lock
);
5347 static void nfs4_zap_acl_attr(struct inode
*inode
)
5349 nfs4_set_cached_acl(inode
, NULL
);
5352 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
5354 struct nfs_inode
*nfsi
= NFS_I(inode
);
5355 struct nfs4_cached_acl
*acl
;
5358 spin_lock(&inode
->i_lock
);
5359 acl
= nfsi
->nfs4_acl
;
5362 if (buf
== NULL
) /* user is just asking for length */
5364 if (acl
->cached
== 0)
5366 ret
= -ERANGE
; /* see getxattr(2) man page */
5367 if (acl
->len
> buflen
)
5369 memcpy(buf
, acl
->data
, acl
->len
);
5373 spin_unlock(&inode
->i_lock
);
5377 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
5379 struct nfs4_cached_acl
*acl
;
5380 size_t buflen
= sizeof(*acl
) + acl_len
;
5382 if (buflen
<= PAGE_SIZE
) {
5383 acl
= kmalloc(buflen
, GFP_KERNEL
);
5387 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
5389 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
5396 nfs4_set_cached_acl(inode
, acl
);
5400 * The getxattr API returns the required buffer length when called with a
5401 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
5402 * the required buf. On a NULL buf, we send a page of data to the server
5403 * guessing that the ACL request can be serviced by a page. If so, we cache
5404 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
5405 * the cache. If not so, we throw away the page, and cache the required
5406 * length. The next getxattr call will then produce another round trip to
5407 * the server, this time with the input buf of the required size.
5409 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
5411 struct page
*pages
[NFS4ACL_MAXPAGES
+ 1] = {NULL
, };
5412 struct nfs_getaclargs args
= {
5413 .fh
= NFS_FH(inode
),
5417 struct nfs_getaclres res
= {
5420 struct rpc_message msg
= {
5421 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
5425 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
) + 1;
5426 int ret
= -ENOMEM
, i
;
5428 if (npages
> ARRAY_SIZE(pages
))
5431 for (i
= 0; i
< npages
; i
++) {
5432 pages
[i
] = alloc_page(GFP_KERNEL
);
5437 /* for decoding across pages */
5438 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
5439 if (!res
.acl_scratch
)
5442 args
.acl_len
= npages
* PAGE_SIZE
;
5444 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
5445 __func__
, buf
, buflen
, npages
, args
.acl_len
);
5446 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
5447 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5451 /* Handle the case where the passed-in buffer is too short */
5452 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
5453 /* Did the user only issue a request for the acl length? */
5459 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
5461 if (res
.acl_len
> buflen
) {
5465 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
5470 for (i
= 0; i
< npages
; i
++)
5472 __free_page(pages
[i
]);
5473 if (res
.acl_scratch
)
5474 __free_page(res
.acl_scratch
);
5478 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
5480 struct nfs4_exception exception
= { };
5483 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
5484 trace_nfs4_get_acl(inode
, ret
);
5487 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
5488 } while (exception
.retry
);
5492 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
5494 struct nfs_server
*server
= NFS_SERVER(inode
);
5497 if (!nfs4_server_supports_acls(server
))
5499 ret
= nfs_revalidate_inode(server
, inode
);
5502 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
5503 nfs_zap_acl_cache(inode
);
5504 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
5506 /* -ENOENT is returned if there is no ACL or if there is an ACL
5507 * but no cached acl data, just the acl length */
5509 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
5512 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
5514 struct nfs_server
*server
= NFS_SERVER(inode
);
5515 struct page
*pages
[NFS4ACL_MAXPAGES
];
5516 struct nfs_setaclargs arg
= {
5517 .fh
= NFS_FH(inode
),
5521 struct nfs_setaclres res
;
5522 struct rpc_message msg
= {
5523 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
5527 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
5530 if (!nfs4_server_supports_acls(server
))
5532 if (npages
> ARRAY_SIZE(pages
))
5534 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
);
5537 nfs4_inode_make_writeable(inode
);
5538 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5541 * Free each page after tx, so the only ref left is
5542 * held by the network stack
5545 put_page(pages
[i
-1]);
5548 * Acl update can result in inode attribute update.
5549 * so mark the attribute cache invalid.
5551 spin_lock(&inode
->i_lock
);
5552 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_CHANGE
5553 | NFS_INO_INVALID_CTIME
5554 | NFS_INO_REVAL_FORCED
;
5555 spin_unlock(&inode
->i_lock
);
5556 nfs_access_zap_cache(inode
);
5557 nfs_zap_acl_cache(inode
);
5561 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
5563 struct nfs4_exception exception
= { };
5566 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
5567 trace_nfs4_set_acl(inode
, err
);
5568 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5570 } while (exception
.retry
);
5574 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5575 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
5578 struct nfs_server
*server
= NFS_SERVER(inode
);
5579 struct nfs_fattr fattr
;
5580 struct nfs4_label label
= {0, 0, buflen
, buf
};
5582 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
5583 struct nfs4_getattr_arg arg
= {
5584 .fh
= NFS_FH(inode
),
5587 struct nfs4_getattr_res res
= {
5592 struct rpc_message msg
= {
5593 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
5599 nfs_fattr_init(&fattr
);
5601 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 0);
5604 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
5606 if (buflen
< label
.len
)
5611 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
5614 struct nfs4_exception exception
= { };
5617 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
5621 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
5622 trace_nfs4_get_security_label(inode
, err
);
5623 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5625 } while (exception
.retry
);
5629 static int _nfs4_do_set_security_label(struct inode
*inode
,
5630 struct nfs4_label
*ilabel
,
5631 struct nfs_fattr
*fattr
,
5632 struct nfs4_label
*olabel
)
5635 struct iattr sattr
= {0};
5636 struct nfs_server
*server
= NFS_SERVER(inode
);
5637 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
5638 struct nfs_setattrargs arg
= {
5639 .fh
= NFS_FH(inode
),
5645 struct nfs_setattrres res
= {
5650 struct rpc_message msg
= {
5651 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
5657 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
5659 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5661 dprintk("%s failed: %d\n", __func__
, status
);
5666 static int nfs4_do_set_security_label(struct inode
*inode
,
5667 struct nfs4_label
*ilabel
,
5668 struct nfs_fattr
*fattr
,
5669 struct nfs4_label
*olabel
)
5671 struct nfs4_exception exception
= { };
5675 err
= _nfs4_do_set_security_label(inode
, ilabel
,
5677 trace_nfs4_set_security_label(inode
, err
);
5678 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
5680 } while (exception
.retry
);
5685 nfs4_set_security_label(struct inode
*inode
, const void *buf
, size_t buflen
)
5687 struct nfs4_label ilabel
, *olabel
= NULL
;
5688 struct nfs_fattr fattr
;
5689 struct rpc_cred
*cred
;
5692 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
5695 nfs_fattr_init(&fattr
);
5699 ilabel
.label
= (char *)buf
;
5700 ilabel
.len
= buflen
;
5702 cred
= rpc_lookup_cred();
5704 return PTR_ERR(cred
);
5706 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
5707 if (IS_ERR(olabel
)) {
5708 status
= -PTR_ERR(olabel
);
5712 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
5714 nfs_setsecurity(inode
, &fattr
, olabel
);
5716 nfs4_label_free(olabel
);
5721 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
5724 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
5725 nfs4_verifier
*bootverf
)
5729 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
5730 /* An impossible timestamp guarantees this value
5731 * will never match a generated boot time. */
5732 verf
[0] = cpu_to_be32(U32_MAX
);
5733 verf
[1] = cpu_to_be32(U32_MAX
);
5735 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
5736 u64 ns
= ktime_to_ns(nn
->boot_time
);
5738 verf
[0] = cpu_to_be32(ns
>> 32);
5739 verf
[1] = cpu_to_be32(ns
);
5741 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
5745 nfs4_init_nonuniform_client_string(struct nfs_client
*clp
)
5750 if (clp
->cl_owner_id
!= NULL
)
5755 strlen(clp
->cl_rpcclient
->cl_nodename
) +
5757 strlen(rpc_peeraddr2str(clp
->cl_rpcclient
, RPC_DISPLAY_ADDR
)) +
5760 if (nfs4_client_id_uniquifier
[0] != '\0')
5761 len
+= strlen(nfs4_client_id_uniquifier
) + 1;
5762 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5766 * Since this string is allocated at mount time, and held until the
5767 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5768 * about a memory-reclaim deadlock.
5770 str
= kmalloc(len
, GFP_KERNEL
);
5775 if (nfs4_client_id_uniquifier
[0] != '\0')
5776 scnprintf(str
, len
, "Linux NFSv4.0 %s/%s/%s",
5777 clp
->cl_rpcclient
->cl_nodename
,
5778 nfs4_client_id_uniquifier
,
5779 rpc_peeraddr2str(clp
->cl_rpcclient
,
5782 scnprintf(str
, len
, "Linux NFSv4.0 %s/%s",
5783 clp
->cl_rpcclient
->cl_nodename
,
5784 rpc_peeraddr2str(clp
->cl_rpcclient
,
5788 clp
->cl_owner_id
= str
;
5793 nfs4_init_uniquifier_client_string(struct nfs_client
*clp
)
5798 len
= 10 + 10 + 1 + 10 + 1 +
5799 strlen(nfs4_client_id_uniquifier
) + 1 +
5800 strlen(clp
->cl_rpcclient
->cl_nodename
) + 1;
5802 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5806 * Since this string is allocated at mount time, and held until the
5807 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5808 * about a memory-reclaim deadlock.
5810 str
= kmalloc(len
, GFP_KERNEL
);
5814 scnprintf(str
, len
, "Linux NFSv%u.%u %s/%s",
5815 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
5816 nfs4_client_id_uniquifier
,
5817 clp
->cl_rpcclient
->cl_nodename
);
5818 clp
->cl_owner_id
= str
;
5823 nfs4_init_uniform_client_string(struct nfs_client
*clp
)
5828 if (clp
->cl_owner_id
!= NULL
)
5831 if (nfs4_client_id_uniquifier
[0] != '\0')
5832 return nfs4_init_uniquifier_client_string(clp
);
5834 len
= 10 + 10 + 1 + 10 + 1 +
5835 strlen(clp
->cl_rpcclient
->cl_nodename
) + 1;
5837 if (len
> NFS4_OPAQUE_LIMIT
+ 1)
5841 * Since this string is allocated at mount time, and held until the
5842 * nfs_client is destroyed, we can use GFP_KERNEL here w/o worrying
5843 * about a memory-reclaim deadlock.
5845 str
= kmalloc(len
, GFP_KERNEL
);
5849 scnprintf(str
, len
, "Linux NFSv%u.%u %s",
5850 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
5851 clp
->cl_rpcclient
->cl_nodename
);
5852 clp
->cl_owner_id
= str
;
5857 * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback
5858 * services. Advertise one based on the address family of the
5862 nfs4_init_callback_netid(const struct nfs_client
*clp
, char *buf
, size_t len
)
5864 if (strchr(clp
->cl_ipaddr
, ':') != NULL
)
5865 return scnprintf(buf
, len
, "tcp6");
5867 return scnprintf(buf
, len
, "tcp");
5870 static void nfs4_setclientid_done(struct rpc_task
*task
, void *calldata
)
5872 struct nfs4_setclientid
*sc
= calldata
;
5874 if (task
->tk_status
== 0)
5875 sc
->sc_cred
= get_rpccred(task
->tk_rqstp
->rq_cred
);
5878 static const struct rpc_call_ops nfs4_setclientid_ops
= {
5879 .rpc_call_done
= nfs4_setclientid_done
,
5883 * nfs4_proc_setclientid - Negotiate client ID
5884 * @clp: state data structure
5885 * @program: RPC program for NFSv4 callback service
5886 * @port: IP port number for NFS4 callback service
5887 * @cred: RPC credential to use for this call
5888 * @res: where to place the result
5890 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5892 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
5893 unsigned short port
, struct rpc_cred
*cred
,
5894 struct nfs4_setclientid_res
*res
)
5896 nfs4_verifier sc_verifier
;
5897 struct nfs4_setclientid setclientid
= {
5898 .sc_verifier
= &sc_verifier
,
5902 struct rpc_message msg
= {
5903 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
5904 .rpc_argp
= &setclientid
,
5908 struct rpc_task
*task
;
5909 struct rpc_task_setup task_setup_data
= {
5910 .rpc_client
= clp
->cl_rpcclient
,
5911 .rpc_message
= &msg
,
5912 .callback_ops
= &nfs4_setclientid_ops
,
5913 .callback_data
= &setclientid
,
5914 .flags
= RPC_TASK_TIMEOUT
,
5918 /* nfs_client_id4 */
5919 nfs4_init_boot_verifier(clp
, &sc_verifier
);
5921 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
5922 status
= nfs4_init_uniform_client_string(clp
);
5924 status
= nfs4_init_nonuniform_client_string(clp
);
5930 setclientid
.sc_netid_len
=
5931 nfs4_init_callback_netid(clp
,
5932 setclientid
.sc_netid
,
5933 sizeof(setclientid
.sc_netid
));
5934 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
5935 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
5936 clp
->cl_ipaddr
, port
>> 8, port
& 255);
5938 dprintk("NFS call setclientid auth=%s, '%s'\n",
5939 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5941 task
= rpc_run_task(&task_setup_data
);
5943 status
= PTR_ERR(task
);
5946 status
= task
->tk_status
;
5947 if (setclientid
.sc_cred
) {
5948 kfree(clp
->cl_acceptor
);
5949 clp
->cl_acceptor
= rpcauth_stringify_acceptor(setclientid
.sc_cred
);
5950 put_rpccred(setclientid
.sc_cred
);
5954 trace_nfs4_setclientid(clp
, status
);
5955 dprintk("NFS reply setclientid: %d\n", status
);
5960 * nfs4_proc_setclientid_confirm - Confirm client ID
5961 * @clp: state data structure
5962 * @res: result of a previous SETCLIENTID
5963 * @cred: RPC credential to use for this call
5965 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5967 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
5968 struct nfs4_setclientid_res
*arg
,
5969 struct rpc_cred
*cred
)
5971 struct rpc_message msg
= {
5972 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
5978 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
5979 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5981 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5982 trace_nfs4_setclientid_confirm(clp
, status
);
5983 dprintk("NFS reply setclientid_confirm: %d\n", status
);
5987 struct nfs4_delegreturndata
{
5988 struct nfs4_delegreturnargs args
;
5989 struct nfs4_delegreturnres res
;
5991 nfs4_stateid stateid
;
5992 unsigned long timestamp
;
5994 struct nfs4_layoutreturn_args arg
;
5995 struct nfs4_layoutreturn_res res
;
5996 struct nfs4_xdr_opaque_data ld_private
;
6000 struct nfs_fattr fattr
;
6002 struct inode
*inode
;
6005 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
6007 struct nfs4_delegreturndata
*data
= calldata
;
6008 struct nfs4_exception exception
= {
6009 .inode
= data
->inode
,
6010 .stateid
= &data
->stateid
,
6013 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
6016 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
6018 /* Handle Layoutreturn errors */
6019 if (data
->args
.lr_args
&& task
->tk_status
!= 0) {
6020 switch(data
->res
.lr_ret
) {
6022 data
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
6025 data
->args
.lr_args
= NULL
;
6026 data
->res
.lr_res
= NULL
;
6028 case -NFS4ERR_OLD_STATEID
:
6029 if (nfs4_layoutreturn_refresh_stateid(&data
->args
.lr_args
->stateid
,
6030 &data
->args
.lr_args
->range
,
6034 case -NFS4ERR_ADMIN_REVOKED
:
6035 case -NFS4ERR_DELEG_REVOKED
:
6036 case -NFS4ERR_EXPIRED
:
6037 case -NFS4ERR_BAD_STATEID
:
6038 case -NFS4ERR_UNKNOWN_LAYOUTTYPE
:
6039 case -NFS4ERR_WRONG_CRED
:
6040 data
->args
.lr_args
= NULL
;
6041 data
->res
.lr_res
= NULL
;
6046 switch (task
->tk_status
) {
6048 renew_lease(data
->res
.server
, data
->timestamp
);
6050 case -NFS4ERR_ADMIN_REVOKED
:
6051 case -NFS4ERR_DELEG_REVOKED
:
6052 case -NFS4ERR_EXPIRED
:
6053 nfs4_free_revoked_stateid(data
->res
.server
,
6055 task
->tk_msg
.rpc_cred
);
6057 case -NFS4ERR_BAD_STATEID
:
6058 case -NFS4ERR_STALE_STATEID
:
6059 task
->tk_status
= 0;
6061 case -NFS4ERR_OLD_STATEID
:
6062 if (nfs4_refresh_delegation_stateid(&data
->stateid
, data
->inode
))
6064 task
->tk_status
= 0;
6066 case -NFS4ERR_ACCESS
:
6067 if (data
->args
.bitmask
) {
6068 data
->args
.bitmask
= NULL
;
6069 data
->res
.fattr
= NULL
;
6074 task
->tk_status
= nfs4_async_handle_exception(task
,
6075 data
->res
.server
, task
->tk_status
,
6077 if (exception
.retry
)
6080 data
->rpc_status
= task
->tk_status
;
6083 data
->res
.lr_ret
= 0;
6085 task
->tk_status
= 0;
6086 rpc_restart_call_prepare(task
);
6089 static void nfs4_delegreturn_release(void *calldata
)
6091 struct nfs4_delegreturndata
*data
= calldata
;
6092 struct inode
*inode
= data
->inode
;
6096 pnfs_roc_release(&data
->lr
.arg
, &data
->lr
.res
,
6098 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
6099 nfs_iput_and_deactive(inode
);
6104 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
6106 struct nfs4_delegreturndata
*d_data
;
6107 struct pnfs_layout_hdr
*lo
;
6109 d_data
= (struct nfs4_delegreturndata
*)data
;
6111 if (!d_data
->lr
.roc
&& nfs4_wait_on_layoutreturn(d_data
->inode
, task
)) {
6112 nfs4_sequence_done(task
, &d_data
->res
.seq_res
);
6116 lo
= d_data
->args
.lr_args
? d_data
->args
.lr_args
->layout
: NULL
;
6117 if (lo
&& !pnfs_layout_is_valid(lo
)) {
6118 d_data
->args
.lr_args
= NULL
;
6119 d_data
->res
.lr_res
= NULL
;
6122 nfs4_setup_sequence(d_data
->res
.server
->nfs_client
,
6123 &d_data
->args
.seq_args
,
6124 &d_data
->res
.seq_res
,
6128 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
6129 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
6130 .rpc_call_done
= nfs4_delegreturn_done
,
6131 .rpc_release
= nfs4_delegreturn_release
,
6134 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
6136 struct nfs4_delegreturndata
*data
;
6137 struct nfs_server
*server
= NFS_SERVER(inode
);
6138 struct rpc_task
*task
;
6139 struct rpc_message msg
= {
6140 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
6143 struct rpc_task_setup task_setup_data
= {
6144 .rpc_client
= server
->client
,
6145 .rpc_message
= &msg
,
6146 .callback_ops
= &nfs4_delegreturn_ops
,
6147 .flags
= RPC_TASK_ASYNC
,
6151 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
6154 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
6156 nfs4_state_protect(server
->nfs_client
,
6157 NFS_SP4_MACH_CRED_CLEANUP
,
6158 &task_setup_data
.rpc_client
, &msg
);
6160 data
->args
.fhandle
= &data
->fh
;
6161 data
->args
.stateid
= &data
->stateid
;
6162 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
6163 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
6164 nfs4_stateid_copy(&data
->stateid
, stateid
);
6165 data
->res
.fattr
= &data
->fattr
;
6166 data
->res
.server
= server
;
6167 data
->res
.lr_ret
= -NFS4ERR_NOMATCHING_LAYOUT
;
6168 data
->lr
.arg
.ld_private
= &data
->lr
.ld_private
;
6169 nfs_fattr_init(data
->res
.fattr
);
6170 data
->timestamp
= jiffies
;
6171 data
->rpc_status
= 0;
6172 data
->lr
.roc
= pnfs_roc(inode
, &data
->lr
.arg
, &data
->lr
.res
, cred
);
6173 data
->inode
= nfs_igrab_and_active(inode
);
6176 data
->args
.lr_args
= &data
->lr
.arg
;
6177 data
->res
.lr_res
= &data
->lr
.res
;
6179 } else if (data
->lr
.roc
) {
6180 pnfs_roc_release(&data
->lr
.arg
, &data
->lr
.res
, 0);
6181 data
->lr
.roc
= false;
6184 task_setup_data
.callback_data
= data
;
6185 msg
.rpc_argp
= &data
->args
;
6186 msg
.rpc_resp
= &data
->res
;
6187 task
= rpc_run_task(&task_setup_data
);
6189 return PTR_ERR(task
);
6192 status
= rpc_wait_for_completion_task(task
);
6195 status
= data
->rpc_status
;
6201 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
6203 struct nfs_server
*server
= NFS_SERVER(inode
);
6204 struct nfs4_exception exception
= { };
6207 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
6208 trace_nfs4_delegreturn(inode
, stateid
, err
);
6210 case -NFS4ERR_STALE_STATEID
:
6211 case -NFS4ERR_EXPIRED
:
6215 err
= nfs4_handle_exception(server
, err
, &exception
);
6216 } while (exception
.retry
);
6220 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6222 struct inode
*inode
= state
->inode
;
6223 struct nfs_server
*server
= NFS_SERVER(inode
);
6224 struct nfs_client
*clp
= server
->nfs_client
;
6225 struct nfs_lockt_args arg
= {
6226 .fh
= NFS_FH(inode
),
6229 struct nfs_lockt_res res
= {
6232 struct rpc_message msg
= {
6233 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
6236 .rpc_cred
= state
->owner
->so_cred
,
6238 struct nfs4_lock_state
*lsp
;
6241 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
6242 status
= nfs4_set_lock_state(state
, request
);
6245 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6246 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6247 arg
.lock_owner
.s_dev
= server
->s_dev
;
6248 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
6251 request
->fl_type
= F_UNLCK
;
6253 case -NFS4ERR_DENIED
:
6256 request
->fl_ops
->fl_release_private(request
);
6257 request
->fl_ops
= NULL
;
6262 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6264 struct nfs4_exception exception
= { };
6268 err
= _nfs4_proc_getlk(state
, cmd
, request
);
6269 trace_nfs4_get_lock(request
, state
, cmd
, err
);
6270 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
6272 } while (exception
.retry
);
6276 struct nfs4_unlockdata
{
6277 struct nfs_locku_args arg
;
6278 struct nfs_locku_res res
;
6279 struct nfs4_lock_state
*lsp
;
6280 struct nfs_open_context
*ctx
;
6281 struct nfs_lock_context
*l_ctx
;
6282 struct file_lock fl
;
6283 struct nfs_server
*server
;
6284 unsigned long timestamp
;
6287 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
6288 struct nfs_open_context
*ctx
,
6289 struct nfs4_lock_state
*lsp
,
6290 struct nfs_seqid
*seqid
)
6292 struct nfs4_unlockdata
*p
;
6293 struct inode
*inode
= lsp
->ls_state
->inode
;
6295 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
6298 p
->arg
.fh
= NFS_FH(inode
);
6300 p
->arg
.seqid
= seqid
;
6301 p
->res
.seqid
= seqid
;
6303 refcount_inc(&lsp
->ls_count
);
6304 /* Ensure we don't close file until we're done freeing locks! */
6305 p
->ctx
= get_nfs_open_context(ctx
);
6306 p
->l_ctx
= nfs_get_lock_context(ctx
);
6307 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
6308 p
->server
= NFS_SERVER(inode
);
6312 static void nfs4_locku_release_calldata(void *data
)
6314 struct nfs4_unlockdata
*calldata
= data
;
6315 nfs_free_seqid(calldata
->arg
.seqid
);
6316 nfs4_put_lock_state(calldata
->lsp
);
6317 nfs_put_lock_context(calldata
->l_ctx
);
6318 put_nfs_open_context(calldata
->ctx
);
6322 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
6324 struct nfs4_unlockdata
*calldata
= data
;
6325 struct nfs4_exception exception
= {
6326 .inode
= calldata
->lsp
->ls_state
->inode
,
6327 .stateid
= &calldata
->arg
.stateid
,
6330 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
6332 switch (task
->tk_status
) {
6334 renew_lease(calldata
->server
, calldata
->timestamp
);
6335 locks_lock_inode_wait(calldata
->lsp
->ls_state
->inode
, &calldata
->fl
);
6336 if (nfs4_update_lock_stateid(calldata
->lsp
,
6337 &calldata
->res
.stateid
))
6340 case -NFS4ERR_ADMIN_REVOKED
:
6341 case -NFS4ERR_EXPIRED
:
6342 nfs4_free_revoked_stateid(calldata
->server
,
6343 &calldata
->arg
.stateid
,
6344 task
->tk_msg
.rpc_cred
);
6346 case -NFS4ERR_BAD_STATEID
:
6347 case -NFS4ERR_OLD_STATEID
:
6348 case -NFS4ERR_STALE_STATEID
:
6349 if (!nfs4_stateid_match(&calldata
->arg
.stateid
,
6350 &calldata
->lsp
->ls_stateid
))
6351 rpc_restart_call_prepare(task
);
6354 task
->tk_status
= nfs4_async_handle_exception(task
,
6355 calldata
->server
, task
->tk_status
,
6357 if (exception
.retry
)
6358 rpc_restart_call_prepare(task
);
6360 nfs_release_seqid(calldata
->arg
.seqid
);
6363 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
6365 struct nfs4_unlockdata
*calldata
= data
;
6367 if (test_bit(NFS_CONTEXT_UNLOCK
, &calldata
->l_ctx
->open_context
->flags
) &&
6368 nfs_async_iocounter_wait(task
, calldata
->l_ctx
))
6371 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
6373 nfs4_stateid_copy(&calldata
->arg
.stateid
, &calldata
->lsp
->ls_stateid
);
6374 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
6375 /* Note: exit _without_ running nfs4_locku_done */
6378 calldata
->timestamp
= jiffies
;
6379 if (nfs4_setup_sequence(calldata
->server
->nfs_client
,
6380 &calldata
->arg
.seq_args
,
6381 &calldata
->res
.seq_res
,
6383 nfs_release_seqid(calldata
->arg
.seqid
);
6386 task
->tk_action
= NULL
;
6388 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
6391 static const struct rpc_call_ops nfs4_locku_ops
= {
6392 .rpc_call_prepare
= nfs4_locku_prepare
,
6393 .rpc_call_done
= nfs4_locku_done
,
6394 .rpc_release
= nfs4_locku_release_calldata
,
6397 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
6398 struct nfs_open_context
*ctx
,
6399 struct nfs4_lock_state
*lsp
,
6400 struct nfs_seqid
*seqid
)
6402 struct nfs4_unlockdata
*data
;
6403 struct rpc_message msg
= {
6404 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
6405 .rpc_cred
= ctx
->cred
,
6407 struct rpc_task_setup task_setup_data
= {
6408 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
6409 .rpc_message
= &msg
,
6410 .callback_ops
= &nfs4_locku_ops
,
6411 .workqueue
= nfsiod_workqueue
,
6412 .flags
= RPC_TASK_ASYNC
,
6415 nfs4_state_protect(NFS_SERVER(lsp
->ls_state
->inode
)->nfs_client
,
6416 NFS_SP4_MACH_CRED_CLEANUP
, &task_setup_data
.rpc_client
, &msg
);
6418 /* Ensure this is an unlock - when canceling a lock, the
6419 * canceled lock is passed in, and it won't be an unlock.
6421 fl
->fl_type
= F_UNLCK
;
6422 if (fl
->fl_flags
& FL_CLOSE
)
6423 set_bit(NFS_CONTEXT_UNLOCK
, &ctx
->flags
);
6425 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
6427 nfs_free_seqid(seqid
);
6428 return ERR_PTR(-ENOMEM
);
6431 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1, 0);
6432 msg
.rpc_argp
= &data
->arg
;
6433 msg
.rpc_resp
= &data
->res
;
6434 task_setup_data
.callback_data
= data
;
6435 return rpc_run_task(&task_setup_data
);
6438 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6440 struct inode
*inode
= state
->inode
;
6441 struct nfs4_state_owner
*sp
= state
->owner
;
6442 struct nfs_inode
*nfsi
= NFS_I(inode
);
6443 struct nfs_seqid
*seqid
;
6444 struct nfs4_lock_state
*lsp
;
6445 struct rpc_task
*task
;
6446 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
6448 unsigned char fl_flags
= request
->fl_flags
;
6450 status
= nfs4_set_lock_state(state
, request
);
6451 /* Unlock _before_ we do the RPC call */
6452 request
->fl_flags
|= FL_EXISTS
;
6453 /* Exclude nfs_delegation_claim_locks() */
6454 mutex_lock(&sp
->so_delegreturn_mutex
);
6455 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
6456 down_read(&nfsi
->rwsem
);
6457 if (locks_lock_inode_wait(inode
, request
) == -ENOENT
) {
6458 up_read(&nfsi
->rwsem
);
6459 mutex_unlock(&sp
->so_delegreturn_mutex
);
6462 up_read(&nfsi
->rwsem
);
6463 mutex_unlock(&sp
->so_delegreturn_mutex
);
6466 /* Is this a delegated lock? */
6467 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6468 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
6470 alloc_seqid
= NFS_SERVER(inode
)->nfs_client
->cl_mvops
->alloc_seqid
;
6471 seqid
= alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
6475 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
6476 status
= PTR_ERR(task
);
6479 status
= rpc_wait_for_completion_task(task
);
6482 request
->fl_flags
= fl_flags
;
6483 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
6487 struct nfs4_lockdata
{
6488 struct nfs_lock_args arg
;
6489 struct nfs_lock_res res
;
6490 struct nfs4_lock_state
*lsp
;
6491 struct nfs_open_context
*ctx
;
6492 struct file_lock fl
;
6493 unsigned long timestamp
;
6496 struct nfs_server
*server
;
6499 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
6500 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
6503 struct nfs4_lockdata
*p
;
6504 struct inode
*inode
= lsp
->ls_state
->inode
;
6505 struct nfs_server
*server
= NFS_SERVER(inode
);
6506 struct nfs_seqid
*(*alloc_seqid
)(struct nfs_seqid_counter
*, gfp_t
);
6508 p
= kzalloc(sizeof(*p
), gfp_mask
);
6512 p
->arg
.fh
= NFS_FH(inode
);
6514 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
6515 if (IS_ERR(p
->arg
.open_seqid
))
6517 alloc_seqid
= server
->nfs_client
->cl_mvops
->alloc_seqid
;
6518 p
->arg
.lock_seqid
= alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
6519 if (IS_ERR(p
->arg
.lock_seqid
))
6520 goto out_free_seqid
;
6521 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
6522 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6523 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
6524 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
6527 refcount_inc(&lsp
->ls_count
);
6528 p
->ctx
= get_nfs_open_context(ctx
);
6529 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
6532 nfs_free_seqid(p
->arg
.open_seqid
);
6538 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
6540 struct nfs4_lockdata
*data
= calldata
;
6541 struct nfs4_state
*state
= data
->lsp
->ls_state
;
6543 dprintk("%s: begin!\n", __func__
);
6544 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
6546 /* Do we need to do an open_to_lock_owner? */
6547 if (!test_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
)) {
6548 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
6549 goto out_release_lock_seqid
;
6551 nfs4_stateid_copy(&data
->arg
.open_stateid
,
6552 &state
->open_stateid
);
6553 data
->arg
.new_lock_owner
= 1;
6554 data
->res
.open_seqid
= data
->arg
.open_seqid
;
6556 data
->arg
.new_lock_owner
= 0;
6557 nfs4_stateid_copy(&data
->arg
.lock_stateid
,
6558 &data
->lsp
->ls_stateid
);
6560 if (!nfs4_valid_open_stateid(state
)) {
6561 data
->rpc_status
= -EBADF
;
6562 task
->tk_action
= NULL
;
6563 goto out_release_open_seqid
;
6565 data
->timestamp
= jiffies
;
6566 if (nfs4_setup_sequence(data
->server
->nfs_client
,
6567 &data
->arg
.seq_args
,
6571 out_release_open_seqid
:
6572 nfs_release_seqid(data
->arg
.open_seqid
);
6573 out_release_lock_seqid
:
6574 nfs_release_seqid(data
->arg
.lock_seqid
);
6576 nfs4_sequence_done(task
, &data
->res
.seq_res
);
6577 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
6580 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
6582 struct nfs4_lockdata
*data
= calldata
;
6583 struct nfs4_lock_state
*lsp
= data
->lsp
;
6585 dprintk("%s: begin!\n", __func__
);
6587 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
6590 data
->rpc_status
= task
->tk_status
;
6591 switch (task
->tk_status
) {
6593 renew_lease(NFS_SERVER(d_inode(data
->ctx
->dentry
)),
6595 if (data
->arg
.new_lock
&& !data
->cancelled
) {
6596 data
->fl
.fl_flags
&= ~(FL_SLEEP
| FL_ACCESS
);
6597 if (locks_lock_inode_wait(lsp
->ls_state
->inode
, &data
->fl
) < 0)
6600 if (data
->arg
.new_lock_owner
!= 0) {
6601 nfs_confirm_seqid(&lsp
->ls_seqid
, 0);
6602 nfs4_stateid_copy(&lsp
->ls_stateid
, &data
->res
.stateid
);
6603 set_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
6604 } else if (!nfs4_update_lock_stateid(lsp
, &data
->res
.stateid
))
6607 case -NFS4ERR_BAD_STATEID
:
6608 case -NFS4ERR_OLD_STATEID
:
6609 case -NFS4ERR_STALE_STATEID
:
6610 case -NFS4ERR_EXPIRED
:
6611 if (data
->arg
.new_lock_owner
!= 0) {
6612 if (!nfs4_stateid_match(&data
->arg
.open_stateid
,
6613 &lsp
->ls_state
->open_stateid
))
6615 } else if (!nfs4_stateid_match(&data
->arg
.lock_stateid
,
6620 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
6623 if (!data
->cancelled
)
6624 rpc_restart_call_prepare(task
);
6628 static void nfs4_lock_release(void *calldata
)
6630 struct nfs4_lockdata
*data
= calldata
;
6632 dprintk("%s: begin!\n", __func__
);
6633 nfs_free_seqid(data
->arg
.open_seqid
);
6634 if (data
->cancelled
&& data
->rpc_status
== 0) {
6635 struct rpc_task
*task
;
6636 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
6637 data
->arg
.lock_seqid
);
6639 rpc_put_task_async(task
);
6640 dprintk("%s: cancelling lock!\n", __func__
);
6642 nfs_free_seqid(data
->arg
.lock_seqid
);
6643 nfs4_put_lock_state(data
->lsp
);
6644 put_nfs_open_context(data
->ctx
);
6646 dprintk("%s: done!\n", __func__
);
6649 static const struct rpc_call_ops nfs4_lock_ops
= {
6650 .rpc_call_prepare
= nfs4_lock_prepare
,
6651 .rpc_call_done
= nfs4_lock_done
,
6652 .rpc_release
= nfs4_lock_release
,
6655 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
6658 case -NFS4ERR_ADMIN_REVOKED
:
6659 case -NFS4ERR_EXPIRED
:
6660 case -NFS4ERR_BAD_STATEID
:
6661 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
6662 if (new_lock_owner
!= 0 ||
6663 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
6664 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
6666 case -NFS4ERR_STALE_STATEID
:
6667 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
6668 nfs4_schedule_lease_recovery(server
->nfs_client
);
6672 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
6674 struct nfs4_lockdata
*data
;
6675 struct rpc_task
*task
;
6676 struct rpc_message msg
= {
6677 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
6678 .rpc_cred
= state
->owner
->so_cred
,
6680 struct rpc_task_setup task_setup_data
= {
6681 .rpc_client
= NFS_CLIENT(state
->inode
),
6682 .rpc_message
= &msg
,
6683 .callback_ops
= &nfs4_lock_ops
,
6684 .workqueue
= nfsiod_workqueue
,
6685 .flags
= RPC_TASK_ASYNC
,
6689 dprintk("%s: begin!\n", __func__
);
6690 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
6691 fl
->fl_u
.nfs4_fl
.owner
,
6692 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
6696 data
->arg
.block
= 1;
6697 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1,
6698 recovery_type
> NFS_LOCK_NEW
);
6699 msg
.rpc_argp
= &data
->arg
;
6700 msg
.rpc_resp
= &data
->res
;
6701 task_setup_data
.callback_data
= data
;
6702 if (recovery_type
> NFS_LOCK_NEW
) {
6703 if (recovery_type
== NFS_LOCK_RECLAIM
)
6704 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
6706 data
->arg
.new_lock
= 1;
6707 task
= rpc_run_task(&task_setup_data
);
6709 return PTR_ERR(task
);
6710 ret
= rpc_wait_for_completion_task(task
);
6712 ret
= data
->rpc_status
;
6714 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
6715 data
->arg
.new_lock_owner
, ret
);
6717 data
->cancelled
= true;
6719 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
6720 trace_nfs4_set_lock(fl
, state
, &data
->res
.stateid
, cmd
, ret
);
6724 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
6726 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6727 struct nfs4_exception exception
= {
6728 .inode
= state
->inode
,
6733 /* Cache the lock if possible... */
6734 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
6736 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
6737 if (err
!= -NFS4ERR_DELAY
)
6739 nfs4_handle_exception(server
, err
, &exception
);
6740 } while (exception
.retry
);
6744 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
6746 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6747 struct nfs4_exception exception
= {
6748 .inode
= state
->inode
,
6752 err
= nfs4_set_lock_state(state
, request
);
6755 if (!recover_lost_locks
) {
6756 set_bit(NFS_LOCK_LOST
, &request
->fl_u
.nfs4_fl
.owner
->ls_flags
);
6760 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
6762 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
6766 case -NFS4ERR_GRACE
:
6767 case -NFS4ERR_DELAY
:
6768 nfs4_handle_exception(server
, err
, &exception
);
6771 } while (exception
.retry
);
6776 #if defined(CONFIG_NFS_V4_1)
6777 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
6779 struct nfs4_lock_state
*lsp
;
6782 status
= nfs4_set_lock_state(state
, request
);
6785 lsp
= request
->fl_u
.nfs4_fl
.owner
;
6786 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) ||
6787 test_bit(NFS_LOCK_LOST
, &lsp
->ls_flags
))
6789 return nfs4_lock_expired(state
, request
);
6793 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6795 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
6796 struct nfs4_state_owner
*sp
= state
->owner
;
6797 unsigned char fl_flags
= request
->fl_flags
;
6800 request
->fl_flags
|= FL_ACCESS
;
6801 status
= locks_lock_inode_wait(state
->inode
, request
);
6804 mutex_lock(&sp
->so_delegreturn_mutex
);
6805 down_read(&nfsi
->rwsem
);
6806 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
6807 /* Yes: cache locks! */
6808 /* ...but avoid races with delegation recall... */
6809 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
6810 status
= locks_lock_inode_wait(state
->inode
, request
);
6811 up_read(&nfsi
->rwsem
);
6812 mutex_unlock(&sp
->so_delegreturn_mutex
);
6815 up_read(&nfsi
->rwsem
);
6816 mutex_unlock(&sp
->so_delegreturn_mutex
);
6817 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
6819 request
->fl_flags
= fl_flags
;
6823 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6825 struct nfs4_exception exception
= {
6827 .inode
= state
->inode
,
6832 err
= _nfs4_proc_setlk(state
, cmd
, request
);
6833 if (err
== -NFS4ERR_DENIED
)
6835 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
6837 } while (exception
.retry
);
6841 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
6842 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
6845 nfs4_retry_setlk_simple(struct nfs4_state
*state
, int cmd
,
6846 struct file_lock
*request
)
6848 int status
= -ERESTARTSYS
;
6849 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
6851 while(!signalled()) {
6852 status
= nfs4_proc_setlk(state
, cmd
, request
);
6853 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
6855 freezable_schedule_timeout_interruptible(timeout
);
6857 timeout
= min_t(unsigned long, NFS4_LOCK_MAXTIMEOUT
, timeout
);
6858 status
= -ERESTARTSYS
;
6863 #ifdef CONFIG_NFS_V4_1
6864 struct nfs4_lock_waiter
{
6865 struct task_struct
*task
;
6866 struct inode
*inode
;
6867 struct nfs_lowner
*owner
;
6871 nfs4_wake_lock_waiter(wait_queue_entry_t
*wait
, unsigned int mode
, int flags
, void *key
)
6874 struct nfs4_lock_waiter
*waiter
= wait
->private;
6876 /* NULL key means to wake up everyone */
6878 struct cb_notify_lock_args
*cbnl
= key
;
6879 struct nfs_lowner
*lowner
= &cbnl
->cbnl_owner
,
6880 *wowner
= waiter
->owner
;
6882 /* Only wake if the callback was for the same owner. */
6883 if (lowner
->id
!= wowner
->id
|| lowner
->s_dev
!= wowner
->s_dev
)
6886 /* Make sure it's for the right inode */
6887 if (nfs_compare_fh(NFS_FH(waiter
->inode
), &cbnl
->cbnl_fh
))
6891 /* override "private" so we can use default_wake_function */
6892 wait
->private = waiter
->task
;
6893 ret
= woken_wake_function(wait
, mode
, flags
, key
);
6895 list_del_init(&wait
->entry
);
6896 wait
->private = waiter
;
6901 nfs4_retry_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6903 int status
= -ERESTARTSYS
;
6904 struct nfs4_lock_state
*lsp
= request
->fl_u
.nfs4_fl
.owner
;
6905 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
6906 struct nfs_client
*clp
= server
->nfs_client
;
6907 wait_queue_head_t
*q
= &clp
->cl_lock_waitq
;
6908 struct nfs_lowner owner
= { .clientid
= clp
->cl_clientid
,
6909 .id
= lsp
->ls_seqid
.owner_id
,
6910 .s_dev
= server
->s_dev
};
6911 struct nfs4_lock_waiter waiter
= { .task
= current
,
6912 .inode
= state
->inode
,
6914 wait_queue_entry_t wait
;
6916 /* Don't bother with waitqueue if we don't expect a callback */
6917 if (!test_bit(NFS_STATE_MAY_NOTIFY_LOCK
, &state
->flags
))
6918 return nfs4_retry_setlk_simple(state
, cmd
, request
);
6921 wait
.private = &waiter
;
6922 wait
.func
= nfs4_wake_lock_waiter
;
6924 while(!signalled()) {
6925 add_wait_queue(q
, &wait
);
6926 status
= nfs4_proc_setlk(state
, cmd
, request
);
6927 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
)) {
6928 finish_wait(q
, &wait
);
6932 status
= -ERESTARTSYS
;
6933 freezer_do_not_count();
6934 wait_woken(&wait
, TASK_INTERRUPTIBLE
, NFS4_LOCK_MAXTIMEOUT
);
6936 finish_wait(q
, &wait
);
6941 #else /* !CONFIG_NFS_V4_1 */
6943 nfs4_retry_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
6945 return nfs4_retry_setlk_simple(state
, cmd
, request
);
6950 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
6952 struct nfs_open_context
*ctx
;
6953 struct nfs4_state
*state
;
6956 /* verify open state */
6957 ctx
= nfs_file_open_context(filp
);
6960 if (IS_GETLK(cmd
)) {
6962 return nfs4_proc_getlk(state
, F_GETLK
, request
);
6966 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
6969 if (request
->fl_type
== F_UNLCK
) {
6971 return nfs4_proc_unlck(state
, cmd
, request
);
6978 if ((request
->fl_flags
& FL_POSIX
) &&
6979 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
6983 * Don't rely on the VFS having checked the file open mode,
6984 * since it won't do this for flock() locks.
6986 switch (request
->fl_type
) {
6988 if (!(filp
->f_mode
& FMODE_READ
))
6992 if (!(filp
->f_mode
& FMODE_WRITE
))
6996 status
= nfs4_set_lock_state(state
, request
);
7000 return nfs4_retry_setlk(state
, cmd
, request
);
7003 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
7005 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
7008 err
= nfs4_set_lock_state(state
, fl
);
7011 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
7012 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, fl
, err
);
7015 struct nfs_release_lockowner_data
{
7016 struct nfs4_lock_state
*lsp
;
7017 struct nfs_server
*server
;
7018 struct nfs_release_lockowner_args args
;
7019 struct nfs_release_lockowner_res res
;
7020 unsigned long timestamp
;
7023 static void nfs4_release_lockowner_prepare(struct rpc_task
*task
, void *calldata
)
7025 struct nfs_release_lockowner_data
*data
= calldata
;
7026 struct nfs_server
*server
= data
->server
;
7027 nfs4_setup_sequence(server
->nfs_client
, &data
->args
.seq_args
,
7028 &data
->res
.seq_res
, task
);
7029 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
7030 data
->timestamp
= jiffies
;
7033 static void nfs4_release_lockowner_done(struct rpc_task
*task
, void *calldata
)
7035 struct nfs_release_lockowner_data
*data
= calldata
;
7036 struct nfs_server
*server
= data
->server
;
7038 nfs40_sequence_done(task
, &data
->res
.seq_res
);
7040 switch (task
->tk_status
) {
7042 renew_lease(server
, data
->timestamp
);
7044 case -NFS4ERR_STALE_CLIENTID
:
7045 case -NFS4ERR_EXPIRED
:
7046 nfs4_schedule_lease_recovery(server
->nfs_client
);
7048 case -NFS4ERR_LEASE_MOVED
:
7049 case -NFS4ERR_DELAY
:
7050 if (nfs4_async_handle_error(task
, server
,
7051 NULL
, NULL
) == -EAGAIN
)
7052 rpc_restart_call_prepare(task
);
7056 static void nfs4_release_lockowner_release(void *calldata
)
7058 struct nfs_release_lockowner_data
*data
= calldata
;
7059 nfs4_free_lock_state(data
->server
, data
->lsp
);
7063 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
7064 .rpc_call_prepare
= nfs4_release_lockowner_prepare
,
7065 .rpc_call_done
= nfs4_release_lockowner_done
,
7066 .rpc_release
= nfs4_release_lockowner_release
,
7070 nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
7072 struct nfs_release_lockowner_data
*data
;
7073 struct rpc_message msg
= {
7074 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
7077 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
7080 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
7084 data
->server
= server
;
7085 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
7086 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
7087 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
7089 msg
.rpc_argp
= &data
->args
;
7090 msg
.rpc_resp
= &data
->res
;
7091 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0, 0);
7092 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
7095 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
7097 static int nfs4_xattr_set_nfs4_acl(const struct xattr_handler
*handler
,
7098 struct dentry
*unused
, struct inode
*inode
,
7099 const char *key
, const void *buf
,
7100 size_t buflen
, int flags
)
7102 return nfs4_proc_set_acl(inode
, buf
, buflen
);
7105 static int nfs4_xattr_get_nfs4_acl(const struct xattr_handler
*handler
,
7106 struct dentry
*unused
, struct inode
*inode
,
7107 const char *key
, void *buf
, size_t buflen
)
7109 return nfs4_proc_get_acl(inode
, buf
, buflen
);
7112 static bool nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
)
7114 return nfs4_server_supports_acls(NFS_SERVER(d_inode(dentry
)));
7117 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7119 static int nfs4_xattr_set_nfs4_label(const struct xattr_handler
*handler
,
7120 struct dentry
*unused
, struct inode
*inode
,
7121 const char *key
, const void *buf
,
7122 size_t buflen
, int flags
)
7124 if (security_ismaclabel(key
))
7125 return nfs4_set_security_label(inode
, buf
, buflen
);
7130 static int nfs4_xattr_get_nfs4_label(const struct xattr_handler
*handler
,
7131 struct dentry
*unused
, struct inode
*inode
,
7132 const char *key
, void *buf
, size_t buflen
)
7134 if (security_ismaclabel(key
))
7135 return nfs4_get_security_label(inode
, buf
, buflen
);
7140 nfs4_listxattr_nfs4_label(struct inode
*inode
, char *list
, size_t list_len
)
7144 if (nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
)) {
7145 len
= security_inode_listsecurity(inode
, list
, list_len
);
7146 if (list_len
&& len
> list_len
)
7152 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
7153 .prefix
= XATTR_SECURITY_PREFIX
,
7154 .get
= nfs4_xattr_get_nfs4_label
,
7155 .set
= nfs4_xattr_set_nfs4_label
,
7161 nfs4_listxattr_nfs4_label(struct inode
*inode
, char *list
, size_t list_len
)
7169 * nfs_fhget will use either the mounted_on_fileid or the fileid
7171 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
7173 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
7174 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
7175 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
7176 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
7179 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
7180 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
7181 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
7185 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
7186 const struct qstr
*name
,
7187 struct nfs4_fs_locations
*fs_locations
,
7190 struct nfs_server
*server
= NFS_SERVER(dir
);
7192 struct nfs4_fs_locations_arg args
= {
7193 .dir_fh
= NFS_FH(dir
),
7198 struct nfs4_fs_locations_res res
= {
7199 .fs_locations
= fs_locations
,
7201 struct rpc_message msg
= {
7202 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7208 dprintk("%s: start\n", __func__
);
7210 bitmask
[0] = nfs4_fattr_bitmap
[0] | FATTR4_WORD0_FS_LOCATIONS
;
7211 bitmask
[1] = nfs4_fattr_bitmap
[1];
7213 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
7214 * is not supported */
7215 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
7216 bitmask
[0] &= ~FATTR4_WORD0_FILEID
;
7218 bitmask
[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID
;
7220 nfs_fattr_init(&fs_locations
->fattr
);
7221 fs_locations
->server
= server
;
7222 fs_locations
->nlocations
= 0;
7223 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7224 dprintk("%s: returned status = %d\n", __func__
, status
);
7228 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
7229 const struct qstr
*name
,
7230 struct nfs4_fs_locations
*fs_locations
,
7233 struct nfs4_exception exception
= { };
7236 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
7237 fs_locations
, page
);
7238 trace_nfs4_get_fs_locations(dir
, name
, err
);
7239 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
7241 } while (exception
.retry
);
7246 * This operation also signals the server that this client is
7247 * performing migration recovery. The server can stop returning
7248 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
7249 * appended to this compound to identify the client ID which is
7250 * performing recovery.
7252 static int _nfs40_proc_get_locations(struct inode
*inode
,
7253 struct nfs4_fs_locations
*locations
,
7254 struct page
*page
, struct rpc_cred
*cred
)
7256 struct nfs_server
*server
= NFS_SERVER(inode
);
7257 struct rpc_clnt
*clnt
= server
->client
;
7259 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
7261 struct nfs4_fs_locations_arg args
= {
7262 .clientid
= server
->nfs_client
->cl_clientid
,
7263 .fh
= NFS_FH(inode
),
7266 .migration
= 1, /* skip LOOKUP */
7267 .renew
= 1, /* append RENEW */
7269 struct nfs4_fs_locations_res res
= {
7270 .fs_locations
= locations
,
7274 struct rpc_message msg
= {
7275 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7280 unsigned long now
= jiffies
;
7283 nfs_fattr_init(&locations
->fattr
);
7284 locations
->server
= server
;
7285 locations
->nlocations
= 0;
7287 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7288 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7289 &args
.seq_args
, &res
.seq_res
);
7293 renew_lease(server
, now
);
7297 #ifdef CONFIG_NFS_V4_1
7300 * This operation also signals the server that this client is
7301 * performing migration recovery. The server can stop asserting
7302 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
7303 * performing this operation is identified in the SEQUENCE
7304 * operation in this compound.
7306 * When the client supports GETATTR(fs_locations_info), it can
7307 * be plumbed in here.
7309 static int _nfs41_proc_get_locations(struct inode
*inode
,
7310 struct nfs4_fs_locations
*locations
,
7311 struct page
*page
, struct rpc_cred
*cred
)
7313 struct nfs_server
*server
= NFS_SERVER(inode
);
7314 struct rpc_clnt
*clnt
= server
->client
;
7316 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
7318 struct nfs4_fs_locations_arg args
= {
7319 .fh
= NFS_FH(inode
),
7322 .migration
= 1, /* skip LOOKUP */
7324 struct nfs4_fs_locations_res res
= {
7325 .fs_locations
= locations
,
7328 struct rpc_message msg
= {
7329 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
7336 nfs_fattr_init(&locations
->fattr
);
7337 locations
->server
= server
;
7338 locations
->nlocations
= 0;
7340 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7341 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7342 &args
.seq_args
, &res
.seq_res
);
7343 if (status
== NFS4_OK
&&
7344 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
7345 status
= -NFS4ERR_LEASE_MOVED
;
7349 #endif /* CONFIG_NFS_V4_1 */
7352 * nfs4_proc_get_locations - discover locations for a migrated FSID
7353 * @inode: inode on FSID that is migrating
7354 * @locations: result of query
7356 * @cred: credential to use for this operation
7358 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
7359 * operation failed, or a negative errno if a local error occurred.
7361 * On success, "locations" is filled in, but if the server has
7362 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
7365 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
7366 * from this client that require migration recovery.
7368 int nfs4_proc_get_locations(struct inode
*inode
,
7369 struct nfs4_fs_locations
*locations
,
7370 struct page
*page
, struct rpc_cred
*cred
)
7372 struct nfs_server
*server
= NFS_SERVER(inode
);
7373 struct nfs_client
*clp
= server
->nfs_client
;
7374 const struct nfs4_mig_recovery_ops
*ops
=
7375 clp
->cl_mvops
->mig_recovery_ops
;
7376 struct nfs4_exception exception
= { };
7379 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
7380 (unsigned long long)server
->fsid
.major
,
7381 (unsigned long long)server
->fsid
.minor
,
7383 nfs_display_fhandle(NFS_FH(inode
), __func__
);
7386 status
= ops
->get_locations(inode
, locations
, page
, cred
);
7387 if (status
!= -NFS4ERR_DELAY
)
7389 nfs4_handle_exception(server
, status
, &exception
);
7390 } while (exception
.retry
);
7395 * This operation also signals the server that this client is
7396 * performing "lease moved" recovery. The server can stop
7397 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
7398 * is appended to this compound to identify the client ID which is
7399 * performing recovery.
7401 static int _nfs40_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
7403 struct nfs_server
*server
= NFS_SERVER(inode
);
7404 struct nfs_client
*clp
= NFS_SERVER(inode
)->nfs_client
;
7405 struct rpc_clnt
*clnt
= server
->client
;
7406 struct nfs4_fsid_present_arg args
= {
7407 .fh
= NFS_FH(inode
),
7408 .clientid
= clp
->cl_clientid
,
7409 .renew
= 1, /* append RENEW */
7411 struct nfs4_fsid_present_res res
= {
7414 struct rpc_message msg
= {
7415 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
7420 unsigned long now
= jiffies
;
7423 res
.fh
= nfs_alloc_fhandle();
7427 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7428 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7429 &args
.seq_args
, &res
.seq_res
);
7430 nfs_free_fhandle(res
.fh
);
7434 do_renew_lease(clp
, now
);
7438 #ifdef CONFIG_NFS_V4_1
7441 * This operation also signals the server that this client is
7442 * performing "lease moved" recovery. The server can stop asserting
7443 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
7444 * this operation is identified in the SEQUENCE operation in this
7447 static int _nfs41_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
7449 struct nfs_server
*server
= NFS_SERVER(inode
);
7450 struct rpc_clnt
*clnt
= server
->client
;
7451 struct nfs4_fsid_present_arg args
= {
7452 .fh
= NFS_FH(inode
),
7454 struct nfs4_fsid_present_res res
= {
7456 struct rpc_message msg
= {
7457 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
7464 res
.fh
= nfs_alloc_fhandle();
7468 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
7469 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
7470 &args
.seq_args
, &res
.seq_res
);
7471 nfs_free_fhandle(res
.fh
);
7472 if (status
== NFS4_OK
&&
7473 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
7474 status
= -NFS4ERR_LEASE_MOVED
;
7478 #endif /* CONFIG_NFS_V4_1 */
7481 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
7482 * @inode: inode on FSID to check
7483 * @cred: credential to use for this operation
7485 * Server indicates whether the FSID is present, moved, or not
7486 * recognized. This operation is necessary to clear a LEASE_MOVED
7487 * condition for this client ID.
7489 * Returns NFS4_OK if the FSID is present on this server,
7490 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
7491 * NFS4ERR code if some error occurred on the server, or a
7492 * negative errno if a local failure occurred.
7494 int nfs4_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
7496 struct nfs_server
*server
= NFS_SERVER(inode
);
7497 struct nfs_client
*clp
= server
->nfs_client
;
7498 const struct nfs4_mig_recovery_ops
*ops
=
7499 clp
->cl_mvops
->mig_recovery_ops
;
7500 struct nfs4_exception exception
= { };
7503 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
7504 (unsigned long long)server
->fsid
.major
,
7505 (unsigned long long)server
->fsid
.minor
,
7507 nfs_display_fhandle(NFS_FH(inode
), __func__
);
7510 status
= ops
->fsid_present(inode
, cred
);
7511 if (status
!= -NFS4ERR_DELAY
)
7513 nfs4_handle_exception(server
, status
, &exception
);
7514 } while (exception
.retry
);
7519 * If 'use_integrity' is true and the state managment nfs_client
7520 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
7521 * and the machine credential as per RFC3530bis and RFC5661 Security
7522 * Considerations sections. Otherwise, just use the user cred with the
7523 * filesystem's rpc_client.
7525 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
7528 struct nfs4_secinfo_arg args
= {
7529 .dir_fh
= NFS_FH(dir
),
7532 struct nfs4_secinfo_res res
= {
7535 struct rpc_message msg
= {
7536 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
7540 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
7541 struct rpc_cred
*cred
= NULL
;
7543 if (use_integrity
) {
7544 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
7545 cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
7546 msg
.rpc_cred
= cred
;
7549 dprintk("NFS call secinfo %s\n", name
->name
);
7551 nfs4_state_protect(NFS_SERVER(dir
)->nfs_client
,
7552 NFS_SP4_MACH_CRED_SECINFO
, &clnt
, &msg
);
7554 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
7556 dprintk("NFS reply secinfo: %d\n", status
);
7564 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
7565 struct nfs4_secinfo_flavors
*flavors
)
7567 struct nfs4_exception exception
= { };
7570 err
= -NFS4ERR_WRONGSEC
;
7572 /* try to use integrity protection with machine cred */
7573 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
7574 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
7577 * if unable to use integrity protection, or SECINFO with
7578 * integrity protection returns NFS4ERR_WRONGSEC (which is
7579 * disallowed by spec, but exists in deployed servers) use
7580 * the current filesystem's rpc_client and the user cred.
7582 if (err
== -NFS4ERR_WRONGSEC
)
7583 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
7585 trace_nfs4_secinfo(dir
, name
, err
);
7586 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
7588 } while (exception
.retry
);
7592 #ifdef CONFIG_NFS_V4_1
7594 * Check the exchange flags returned by the server for invalid flags, having
7595 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
7598 static int nfs4_check_cl_exchange_flags(u32 flags
)
7600 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
7602 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
7603 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
7605 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
7609 return -NFS4ERR_INVAL
;
7613 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
7614 struct nfs41_server_scope
*b
)
7616 if (a
->server_scope_sz
!= b
->server_scope_sz
)
7618 return memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0;
7622 nfs4_bind_one_conn_to_session_done(struct rpc_task
*task
, void *calldata
)
7626 static const struct rpc_call_ops nfs4_bind_one_conn_to_session_ops
= {
7627 .rpc_call_done
= nfs4_bind_one_conn_to_session_done
,
7631 * nfs4_proc_bind_one_conn_to_session()
7633 * The 4.1 client currently uses the same TCP connection for the
7634 * fore and backchannel.
7637 int nfs4_proc_bind_one_conn_to_session(struct rpc_clnt
*clnt
,
7638 struct rpc_xprt
*xprt
,
7639 struct nfs_client
*clp
,
7640 struct rpc_cred
*cred
)
7643 struct nfs41_bind_conn_to_session_args args
= {
7645 .dir
= NFS4_CDFC4_FORE_OR_BOTH
,
7647 struct nfs41_bind_conn_to_session_res res
;
7648 struct rpc_message msg
= {
7650 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
7655 struct rpc_task_setup task_setup_data
= {
7658 .callback_ops
= &nfs4_bind_one_conn_to_session_ops
,
7659 .rpc_message
= &msg
,
7660 .flags
= RPC_TASK_TIMEOUT
,
7662 struct rpc_task
*task
;
7664 nfs4_copy_sessionid(&args
.sessionid
, &clp
->cl_session
->sess_id
);
7665 if (!(clp
->cl_session
->flags
& SESSION4_BACK_CHAN
))
7666 args
.dir
= NFS4_CDFC4_FORE
;
7668 /* Do not set the backchannel flag unless this is clnt->cl_xprt */
7669 if (xprt
!= rcu_access_pointer(clnt
->cl_xprt
))
7670 args
.dir
= NFS4_CDFC4_FORE
;
7672 task
= rpc_run_task(&task_setup_data
);
7673 if (!IS_ERR(task
)) {
7674 status
= task
->tk_status
;
7677 status
= PTR_ERR(task
);
7678 trace_nfs4_bind_conn_to_session(clp
, status
);
7680 if (memcmp(res
.sessionid
.data
,
7681 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
7682 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
7685 if ((res
.dir
& args
.dir
) != res
.dir
|| res
.dir
== 0) {
7686 dprintk("NFS: %s: Unexpected direction from server\n",
7690 if (res
.use_conn_in_rdma_mode
!= args
.use_conn_in_rdma_mode
) {
7691 dprintk("NFS: %s: Server returned RDMA mode = true\n",
7700 struct rpc_bind_conn_calldata
{
7701 struct nfs_client
*clp
;
7702 struct rpc_cred
*cred
;
7706 nfs4_proc_bind_conn_to_session_callback(struct rpc_clnt
*clnt
,
7707 struct rpc_xprt
*xprt
,
7710 struct rpc_bind_conn_calldata
*p
= calldata
;
7712 return nfs4_proc_bind_one_conn_to_session(clnt
, xprt
, p
->clp
, p
->cred
);
7715 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7717 struct rpc_bind_conn_calldata data
= {
7721 return rpc_clnt_iterate_for_each_xprt(clp
->cl_rpcclient
,
7722 nfs4_proc_bind_conn_to_session_callback
, &data
);
7726 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
7727 * and operations we'd like to see to enable certain features in the allow map
7729 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request
= {
7730 .how
= SP4_MACH_CRED
,
7731 .enforce
.u
.words
= {
7732 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
7733 1 << (OP_EXCHANGE_ID
- 32) |
7734 1 << (OP_CREATE_SESSION
- 32) |
7735 1 << (OP_DESTROY_SESSION
- 32) |
7736 1 << (OP_DESTROY_CLIENTID
- 32)
7739 [0] = 1 << (OP_CLOSE
) |
7740 1 << (OP_OPEN_DOWNGRADE
) |
7742 1 << (OP_DELEGRETURN
) |
7744 [1] = 1 << (OP_SECINFO
- 32) |
7745 1 << (OP_SECINFO_NO_NAME
- 32) |
7746 1 << (OP_LAYOUTRETURN
- 32) |
7747 1 << (OP_TEST_STATEID
- 32) |
7748 1 << (OP_FREE_STATEID
- 32) |
7749 1 << (OP_WRITE
- 32)
7754 * Select the state protection mode for client `clp' given the server results
7755 * from exchange_id in `sp'.
7757 * Returns 0 on success, negative errno otherwise.
7759 static int nfs4_sp4_select_mode(struct nfs_client
*clp
,
7760 struct nfs41_state_protection
*sp
)
7762 static const u32 supported_enforce
[NFS4_OP_MAP_NUM_WORDS
] = {
7763 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
7764 1 << (OP_EXCHANGE_ID
- 32) |
7765 1 << (OP_CREATE_SESSION
- 32) |
7766 1 << (OP_DESTROY_SESSION
- 32) |
7767 1 << (OP_DESTROY_CLIENTID
- 32)
7769 unsigned long flags
= 0;
7773 if (sp
->how
== SP4_MACH_CRED
) {
7774 /* Print state protect result */
7775 dfprintk(MOUNT
, "Server SP4_MACH_CRED support:\n");
7776 for (i
= 0; i
<= LAST_NFS4_OP
; i
++) {
7777 if (test_bit(i
, sp
->enforce
.u
.longs
))
7778 dfprintk(MOUNT
, " enforce op %d\n", i
);
7779 if (test_bit(i
, sp
->allow
.u
.longs
))
7780 dfprintk(MOUNT
, " allow op %d\n", i
);
7783 /* make sure nothing is on enforce list that isn't supported */
7784 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++) {
7785 if (sp
->enforce
.u
.words
[i
] & ~supported_enforce
[i
]) {
7786 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
7793 * Minimal mode - state operations are allowed to use machine
7794 * credential. Note this already happens by default, so the
7795 * client doesn't have to do anything more than the negotiation.
7797 * NOTE: we don't care if EXCHANGE_ID is in the list -
7798 * we're already using the machine cred for exchange_id
7799 * and will never use a different cred.
7801 if (test_bit(OP_BIND_CONN_TO_SESSION
, sp
->enforce
.u
.longs
) &&
7802 test_bit(OP_CREATE_SESSION
, sp
->enforce
.u
.longs
) &&
7803 test_bit(OP_DESTROY_SESSION
, sp
->enforce
.u
.longs
) &&
7804 test_bit(OP_DESTROY_CLIENTID
, sp
->enforce
.u
.longs
)) {
7805 dfprintk(MOUNT
, "sp4_mach_cred:\n");
7806 dfprintk(MOUNT
, " minimal mode enabled\n");
7807 __set_bit(NFS_SP4_MACH_CRED_MINIMAL
, &flags
);
7809 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
7814 if (test_bit(OP_CLOSE
, sp
->allow
.u
.longs
) &&
7815 test_bit(OP_OPEN_DOWNGRADE
, sp
->allow
.u
.longs
) &&
7816 test_bit(OP_DELEGRETURN
, sp
->allow
.u
.longs
) &&
7817 test_bit(OP_LOCKU
, sp
->allow
.u
.longs
)) {
7818 dfprintk(MOUNT
, " cleanup mode enabled\n");
7819 __set_bit(NFS_SP4_MACH_CRED_CLEANUP
, &flags
);
7822 if (test_bit(OP_LAYOUTRETURN
, sp
->allow
.u
.longs
)) {
7823 dfprintk(MOUNT
, " pnfs cleanup mode enabled\n");
7824 __set_bit(NFS_SP4_MACH_CRED_PNFS_CLEANUP
, &flags
);
7827 if (test_bit(OP_SECINFO
, sp
->allow
.u
.longs
) &&
7828 test_bit(OP_SECINFO_NO_NAME
, sp
->allow
.u
.longs
)) {
7829 dfprintk(MOUNT
, " secinfo mode enabled\n");
7830 __set_bit(NFS_SP4_MACH_CRED_SECINFO
, &flags
);
7833 if (test_bit(OP_TEST_STATEID
, sp
->allow
.u
.longs
) &&
7834 test_bit(OP_FREE_STATEID
, sp
->allow
.u
.longs
)) {
7835 dfprintk(MOUNT
, " stateid mode enabled\n");
7836 __set_bit(NFS_SP4_MACH_CRED_STATEID
, &flags
);
7839 if (test_bit(OP_WRITE
, sp
->allow
.u
.longs
)) {
7840 dfprintk(MOUNT
, " write mode enabled\n");
7841 __set_bit(NFS_SP4_MACH_CRED_WRITE
, &flags
);
7844 if (test_bit(OP_COMMIT
, sp
->allow
.u
.longs
)) {
7845 dfprintk(MOUNT
, " commit mode enabled\n");
7846 __set_bit(NFS_SP4_MACH_CRED_COMMIT
, &flags
);
7850 clp
->cl_sp4_flags
= flags
;
7854 struct nfs41_exchange_id_data
{
7855 struct nfs41_exchange_id_res res
;
7856 struct nfs41_exchange_id_args args
;
7859 static void nfs4_exchange_id_release(void *data
)
7861 struct nfs41_exchange_id_data
*cdata
=
7862 (struct nfs41_exchange_id_data
*)data
;
7864 nfs_put_client(cdata
->args
.client
);
7865 kfree(cdata
->res
.impl_id
);
7866 kfree(cdata
->res
.server_scope
);
7867 kfree(cdata
->res
.server_owner
);
7871 static const struct rpc_call_ops nfs4_exchange_id_call_ops
= {
7872 .rpc_release
= nfs4_exchange_id_release
,
7876 * _nfs4_proc_exchange_id()
7878 * Wrapper for EXCHANGE_ID operation.
7880 static struct rpc_task
*
7881 nfs4_run_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
,
7882 u32 sp4_how
, struct rpc_xprt
*xprt
)
7884 struct rpc_message msg
= {
7885 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
7888 struct rpc_task_setup task_setup_data
= {
7889 .rpc_client
= clp
->cl_rpcclient
,
7890 .callback_ops
= &nfs4_exchange_id_call_ops
,
7891 .rpc_message
= &msg
,
7892 .flags
= RPC_TASK_TIMEOUT
,
7894 struct nfs41_exchange_id_data
*calldata
;
7897 if (!refcount_inc_not_zero(&clp
->cl_count
))
7898 return ERR_PTR(-EIO
);
7901 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7905 nfs4_init_boot_verifier(clp
, &calldata
->args
.verifier
);
7907 status
= nfs4_init_uniform_client_string(clp
);
7911 calldata
->res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
7914 if (unlikely(calldata
->res
.server_owner
== NULL
))
7917 calldata
->res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
7919 if (unlikely(calldata
->res
.server_scope
== NULL
))
7920 goto out_server_owner
;
7922 calldata
->res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
7923 if (unlikely(calldata
->res
.impl_id
== NULL
))
7924 goto out_server_scope
;
7928 calldata
->args
.state_protect
.how
= SP4_NONE
;
7932 calldata
->args
.state_protect
= nfs4_sp4_mach_cred_request
;
7942 task_setup_data
.rpc_xprt
= xprt
;
7943 task_setup_data
.flags
|= RPC_TASK_SOFTCONN
;
7944 memcpy(calldata
->args
.verifier
.data
, clp
->cl_confirm
.data
,
7945 sizeof(calldata
->args
.verifier
.data
));
7947 calldata
->args
.client
= clp
;
7948 calldata
->args
.flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
7949 EXCHGID4_FLAG_BIND_PRINC_STATEID
;
7950 #ifdef CONFIG_NFS_V4_1_MIGRATION
7951 calldata
->args
.flags
|= EXCHGID4_FLAG_SUPP_MOVED_MIGR
;
7953 msg
.rpc_argp
= &calldata
->args
;
7954 msg
.rpc_resp
= &calldata
->res
;
7955 task_setup_data
.callback_data
= calldata
;
7957 return rpc_run_task(&task_setup_data
);
7960 kfree(calldata
->res
.impl_id
);
7962 kfree(calldata
->res
.server_scope
);
7964 kfree(calldata
->res
.server_owner
);
7968 nfs_put_client(clp
);
7969 return ERR_PTR(status
);
7973 * _nfs4_proc_exchange_id()
7975 * Wrapper for EXCHANGE_ID operation.
7977 static int _nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
,
7980 struct rpc_task
*task
;
7981 struct nfs41_exchange_id_args
*argp
;
7982 struct nfs41_exchange_id_res
*resp
;
7985 task
= nfs4_run_exchange_id(clp
, cred
, sp4_how
, NULL
);
7987 return PTR_ERR(task
);
7989 argp
= task
->tk_msg
.rpc_argp
;
7990 resp
= task
->tk_msg
.rpc_resp
;
7991 status
= task
->tk_status
;
7995 status
= nfs4_check_cl_exchange_flags(resp
->flags
);
7999 status
= nfs4_sp4_select_mode(clp
, &resp
->state_protect
);
8003 clp
->cl_clientid
= resp
->clientid
;
8004 clp
->cl_exchange_flags
= resp
->flags
;
8005 clp
->cl_seqid
= resp
->seqid
;
8006 /* Client ID is not confirmed */
8007 if (!(resp
->flags
& EXCHGID4_FLAG_CONFIRMED_R
))
8008 clear_bit(NFS4_SESSION_ESTABLISHED
,
8009 &clp
->cl_session
->session_state
);
8011 if (clp
->cl_serverscope
!= NULL
&&
8012 !nfs41_same_server_scope(clp
->cl_serverscope
,
8013 resp
->server_scope
)) {
8014 dprintk("%s: server_scope mismatch detected\n",
8016 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
8019 swap(clp
->cl_serverowner
, resp
->server_owner
);
8020 swap(clp
->cl_serverscope
, resp
->server_scope
);
8021 swap(clp
->cl_implid
, resp
->impl_id
);
8023 /* Save the EXCHANGE_ID verifier session trunk tests */
8024 memcpy(clp
->cl_confirm
.data
, argp
->verifier
.data
,
8025 sizeof(clp
->cl_confirm
.data
));
8027 trace_nfs4_exchange_id(clp
, status
);
8033 * nfs4_proc_exchange_id()
8035 * Returns zero, a negative errno, or a negative NFS4ERR status code.
8037 * Since the clientid has expired, all compounds using sessions
8038 * associated with the stale clientid will be returning
8039 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
8040 * be in some phase of session reset.
8042 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
8044 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
8046 rpc_authflavor_t authflavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
8049 /* try SP4_MACH_CRED if krb5i/p */
8050 if (authflavor
== RPC_AUTH_GSS_KRB5I
||
8051 authflavor
== RPC_AUTH_GSS_KRB5P
) {
8052 status
= _nfs4_proc_exchange_id(clp
, cred
, SP4_MACH_CRED
);
8058 return _nfs4_proc_exchange_id(clp
, cred
, SP4_NONE
);
8062 * nfs4_test_session_trunk
8064 * This is an add_xprt_test() test function called from
8065 * rpc_clnt_setup_test_and_add_xprt.
8067 * The rpc_xprt_switch is referrenced by rpc_clnt_setup_test_and_add_xprt
8068 * and is dereferrenced in nfs4_exchange_id_release
8070 * Upon success, add the new transport to the rpc_clnt
8072 * @clnt: struct rpc_clnt to get new transport
8073 * @xprt: the rpc_xprt to test
8074 * @data: call data for _nfs4_proc_exchange_id.
8076 int nfs4_test_session_trunk(struct rpc_clnt
*clnt
, struct rpc_xprt
*xprt
,
8079 struct nfs4_add_xprt_data
*adata
= (struct nfs4_add_xprt_data
*)data
;
8080 struct rpc_task
*task
;
8085 dprintk("--> %s try %s\n", __func__
,
8086 xprt
->address_strings
[RPC_DISPLAY_ADDR
]);
8088 sp4_how
= (adata
->clp
->cl_sp4_flags
== 0 ? SP4_NONE
: SP4_MACH_CRED
);
8090 /* Test connection for session trunking. Async exchange_id call */
8091 task
= nfs4_run_exchange_id(adata
->clp
, adata
->cred
, sp4_how
, xprt
);
8093 return PTR_ERR(task
);
8095 status
= task
->tk_status
;
8097 status
= nfs4_detect_session_trunking(adata
->clp
,
8098 task
->tk_msg
.rpc_resp
, xprt
);
8103 EXPORT_SYMBOL_GPL(nfs4_test_session_trunk
);
8105 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
8106 struct rpc_cred
*cred
)
8108 struct rpc_message msg
= {
8109 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
8115 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8116 trace_nfs4_destroy_clientid(clp
, status
);
8118 dprintk("NFS: Got error %d from the server %s on "
8119 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
8123 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
8124 struct rpc_cred
*cred
)
8129 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
8130 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
8132 case -NFS4ERR_DELAY
:
8133 case -NFS4ERR_CLIENTID_BUSY
:
8143 int nfs4_destroy_clientid(struct nfs_client
*clp
)
8145 struct rpc_cred
*cred
;
8148 if (clp
->cl_mvops
->minor_version
< 1)
8150 if (clp
->cl_exchange_flags
== 0)
8152 if (clp
->cl_preserve_clid
)
8154 cred
= nfs4_get_clid_cred(clp
);
8155 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
8160 case -NFS4ERR_STALE_CLIENTID
:
8161 clp
->cl_exchange_flags
= 0;
8167 struct nfs4_get_lease_time_data
{
8168 struct nfs4_get_lease_time_args
*args
;
8169 struct nfs4_get_lease_time_res
*res
;
8170 struct nfs_client
*clp
;
8173 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
8176 struct nfs4_get_lease_time_data
*data
=
8177 (struct nfs4_get_lease_time_data
*)calldata
;
8179 dprintk("--> %s\n", __func__
);
8180 /* just setup sequence, do not trigger session recovery
8181 since we're invoked within one */
8182 nfs4_setup_sequence(data
->clp
,
8183 &data
->args
->la_seq_args
,
8184 &data
->res
->lr_seq_res
,
8186 dprintk("<-- %s\n", __func__
);
8190 * Called from nfs4_state_manager thread for session setup, so don't recover
8191 * from sequence operation or clientid errors.
8193 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
8195 struct nfs4_get_lease_time_data
*data
=
8196 (struct nfs4_get_lease_time_data
*)calldata
;
8198 dprintk("--> %s\n", __func__
);
8199 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
8201 switch (task
->tk_status
) {
8202 case -NFS4ERR_DELAY
:
8203 case -NFS4ERR_GRACE
:
8204 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
8205 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
8206 task
->tk_status
= 0;
8208 case -NFS4ERR_RETRY_UNCACHED_REP
:
8209 rpc_restart_call_prepare(task
);
8212 dprintk("<-- %s\n", __func__
);
8215 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
8216 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
8217 .rpc_call_done
= nfs4_get_lease_time_done
,
8220 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
8222 struct rpc_task
*task
;
8223 struct nfs4_get_lease_time_args args
;
8224 struct nfs4_get_lease_time_res res
= {
8225 .lr_fsinfo
= fsinfo
,
8227 struct nfs4_get_lease_time_data data
= {
8232 struct rpc_message msg
= {
8233 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
8237 struct rpc_task_setup task_setup
= {
8238 .rpc_client
= clp
->cl_rpcclient
,
8239 .rpc_message
= &msg
,
8240 .callback_ops
= &nfs4_get_lease_time_ops
,
8241 .callback_data
= &data
,
8242 .flags
= RPC_TASK_TIMEOUT
,
8246 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0, 1);
8247 task
= rpc_run_task(&task_setup
);
8250 return PTR_ERR(task
);
8252 status
= task
->tk_status
;
8258 * Initialize the values to be used by the client in CREATE_SESSION
8259 * If nfs4_init_session set the fore channel request and response sizes,
8262 * Set the back channel max_resp_sz_cached to zero to force the client to
8263 * always set csa_cachethis to FALSE because the current implementation
8264 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
8266 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
,
8267 struct rpc_clnt
*clnt
)
8269 unsigned int max_rqst_sz
, max_resp_sz
;
8270 unsigned int max_bc_payload
= rpc_max_bc_payload(clnt
);
8272 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
8273 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
8275 /* Fore channel attributes */
8276 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
8277 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
8278 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
8279 args
->fc_attrs
.max_reqs
= max_session_slots
;
8281 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
8282 "max_ops=%u max_reqs=%u\n",
8284 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
8285 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
8287 /* Back channel attributes */
8288 args
->bc_attrs
.max_rqst_sz
= max_bc_payload
;
8289 args
->bc_attrs
.max_resp_sz
= max_bc_payload
;
8290 args
->bc_attrs
.max_resp_sz_cached
= 0;
8291 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
8292 args
->bc_attrs
.max_reqs
= max_t(unsigned short, max_session_cb_slots
, 1);
8294 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
8295 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
8297 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
8298 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
8299 args
->bc_attrs
.max_reqs
);
8302 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
,
8303 struct nfs41_create_session_res
*res
)
8305 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
8306 struct nfs4_channel_attrs
*rcvd
= &res
->fc_attrs
;
8308 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
8311 * Our requested max_ops is the minimum we need; we're not
8312 * prepared to break up compounds into smaller pieces than that.
8313 * So, no point even trying to continue if the server won't
8316 if (rcvd
->max_ops
< sent
->max_ops
)
8318 if (rcvd
->max_reqs
== 0)
8320 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
8321 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
8325 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
,
8326 struct nfs41_create_session_res
*res
)
8328 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
8329 struct nfs4_channel_attrs
*rcvd
= &res
->bc_attrs
;
8331 if (!(res
->flags
& SESSION4_BACK_CHAN
))
8333 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
8335 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
8337 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
8339 if (rcvd
->max_ops
> sent
->max_ops
)
8341 if (rcvd
->max_reqs
> sent
->max_reqs
)
8347 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
8348 struct nfs41_create_session_res
*res
)
8352 ret
= nfs4_verify_fore_channel_attrs(args
, res
);
8355 return nfs4_verify_back_channel_attrs(args
, res
);
8358 static void nfs4_update_session(struct nfs4_session
*session
,
8359 struct nfs41_create_session_res
*res
)
8361 nfs4_copy_sessionid(&session
->sess_id
, &res
->sessionid
);
8362 /* Mark client id and session as being confirmed */
8363 session
->clp
->cl_exchange_flags
|= EXCHGID4_FLAG_CONFIRMED_R
;
8364 set_bit(NFS4_SESSION_ESTABLISHED
, &session
->session_state
);
8365 session
->flags
= res
->flags
;
8366 memcpy(&session
->fc_attrs
, &res
->fc_attrs
, sizeof(session
->fc_attrs
));
8367 if (res
->flags
& SESSION4_BACK_CHAN
)
8368 memcpy(&session
->bc_attrs
, &res
->bc_attrs
,
8369 sizeof(session
->bc_attrs
));
8372 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
8373 struct rpc_cred
*cred
)
8375 struct nfs4_session
*session
= clp
->cl_session
;
8376 struct nfs41_create_session_args args
= {
8378 .clientid
= clp
->cl_clientid
,
8379 .seqid
= clp
->cl_seqid
,
8380 .cb_program
= NFS4_CALLBACK
,
8382 struct nfs41_create_session_res res
;
8384 struct rpc_message msg
= {
8385 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
8392 nfs4_init_channel_attrs(&args
, clp
->cl_rpcclient
);
8393 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
8395 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8396 trace_nfs4_create_session(clp
, status
);
8399 case -NFS4ERR_STALE_CLIENTID
:
8400 case -NFS4ERR_DELAY
:
8409 /* Verify the session's negotiated channel_attrs values */
8410 status
= nfs4_verify_channel_attrs(&args
, &res
);
8411 /* Increment the clientid slot sequence id */
8414 nfs4_update_session(session
, &res
);
8421 * Issues a CREATE_SESSION operation to the server.
8422 * It is the responsibility of the caller to verify the session is
8423 * expired before calling this routine.
8425 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
8429 struct nfs4_session
*session
= clp
->cl_session
;
8431 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
8433 status
= _nfs4_proc_create_session(clp
, cred
);
8437 /* Init or reset the session slot tables */
8438 status
= nfs4_setup_session_slot_tables(session
);
8439 dprintk("slot table setup returned %d\n", status
);
8443 ptr
= (unsigned *)&session
->sess_id
.data
[0];
8444 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
8445 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
8447 dprintk("<-- %s\n", __func__
);
8452 * Issue the over-the-wire RPC DESTROY_SESSION.
8453 * The caller must serialize access to this routine.
8455 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
8456 struct rpc_cred
*cred
)
8458 struct rpc_message msg
= {
8459 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
8460 .rpc_argp
= session
,
8465 dprintk("--> nfs4_proc_destroy_session\n");
8467 /* session is still being setup */
8468 if (!test_and_clear_bit(NFS4_SESSION_ESTABLISHED
, &session
->session_state
))
8471 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
8472 trace_nfs4_destroy_session(session
->clp
, status
);
8475 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
8476 "Session has been destroyed regardless...\n", status
);
8478 dprintk("<-- nfs4_proc_destroy_session\n");
8483 * Renew the cl_session lease.
8485 struct nfs4_sequence_data
{
8486 struct nfs_client
*clp
;
8487 struct nfs4_sequence_args args
;
8488 struct nfs4_sequence_res res
;
8491 static void nfs41_sequence_release(void *data
)
8493 struct nfs4_sequence_data
*calldata
= data
;
8494 struct nfs_client
*clp
= calldata
->clp
;
8496 if (refcount_read(&clp
->cl_count
) > 1)
8497 nfs4_schedule_state_renewal(clp
);
8498 nfs_put_client(clp
);
8502 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
8504 switch(task
->tk_status
) {
8505 case -NFS4ERR_DELAY
:
8506 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
8509 nfs4_schedule_lease_recovery(clp
);
8514 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
8516 struct nfs4_sequence_data
*calldata
= data
;
8517 struct nfs_client
*clp
= calldata
->clp
;
8519 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
8522 trace_nfs4_sequence(clp
, task
->tk_status
);
8523 if (task
->tk_status
< 0) {
8524 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
8525 if (refcount_read(&clp
->cl_count
) == 1)
8528 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
8529 rpc_restart_call_prepare(task
);
8533 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
8535 dprintk("<-- %s\n", __func__
);
8538 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
8540 struct nfs4_sequence_data
*calldata
= data
;
8541 struct nfs_client
*clp
= calldata
->clp
;
8542 struct nfs4_sequence_args
*args
;
8543 struct nfs4_sequence_res
*res
;
8545 args
= task
->tk_msg
.rpc_argp
;
8546 res
= task
->tk_msg
.rpc_resp
;
8548 nfs4_setup_sequence(clp
, args
, res
, task
);
8551 static const struct rpc_call_ops nfs41_sequence_ops
= {
8552 .rpc_call_done
= nfs41_sequence_call_done
,
8553 .rpc_call_prepare
= nfs41_sequence_prepare
,
8554 .rpc_release
= nfs41_sequence_release
,
8557 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
8558 struct rpc_cred
*cred
,
8559 struct nfs4_slot
*slot
,
8562 struct nfs4_sequence_data
*calldata
;
8563 struct rpc_message msg
= {
8564 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
8567 struct rpc_task_setup task_setup_data
= {
8568 .rpc_client
= clp
->cl_rpcclient
,
8569 .rpc_message
= &msg
,
8570 .callback_ops
= &nfs41_sequence_ops
,
8571 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
8573 struct rpc_task
*ret
;
8575 ret
= ERR_PTR(-EIO
);
8576 if (!refcount_inc_not_zero(&clp
->cl_count
))
8579 ret
= ERR_PTR(-ENOMEM
);
8580 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
8581 if (calldata
== NULL
)
8583 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0, is_privileged
);
8584 nfs4_sequence_attach_slot(&calldata
->args
, &calldata
->res
, slot
);
8585 msg
.rpc_argp
= &calldata
->args
;
8586 msg
.rpc_resp
= &calldata
->res
;
8587 calldata
->clp
= clp
;
8588 task_setup_data
.callback_data
= calldata
;
8590 ret
= rpc_run_task(&task_setup_data
);
8595 nfs_put_client(clp
);
8597 nfs41_release_slot(slot
);
8601 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
8603 struct rpc_task
*task
;
8606 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
8608 task
= _nfs41_proc_sequence(clp
, cred
, NULL
, false);
8610 ret
= PTR_ERR(task
);
8612 rpc_put_task_async(task
);
8613 dprintk("<-- %s status=%d\n", __func__
, ret
);
8617 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
8619 struct rpc_task
*task
;
8622 task
= _nfs41_proc_sequence(clp
, cred
, NULL
, true);
8624 ret
= PTR_ERR(task
);
8627 ret
= rpc_wait_for_completion_task(task
);
8629 ret
= task
->tk_status
;
8632 dprintk("<-- %s status=%d\n", __func__
, ret
);
8636 struct nfs4_reclaim_complete_data
{
8637 struct nfs_client
*clp
;
8638 struct nfs41_reclaim_complete_args arg
;
8639 struct nfs41_reclaim_complete_res res
;
8642 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
8644 struct nfs4_reclaim_complete_data
*calldata
= data
;
8646 nfs4_setup_sequence(calldata
->clp
,
8647 &calldata
->arg
.seq_args
,
8648 &calldata
->res
.seq_res
,
8652 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
8654 switch(task
->tk_status
) {
8656 wake_up_all(&clp
->cl_lock_waitq
);
8658 case -NFS4ERR_COMPLETE_ALREADY
:
8659 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
8661 case -NFS4ERR_DELAY
:
8662 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
8664 case -NFS4ERR_RETRY_UNCACHED_REP
:
8666 case -NFS4ERR_BADSESSION
:
8667 case -NFS4ERR_DEADSESSION
:
8668 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
8669 nfs4_schedule_session_recovery(clp
->cl_session
,
8673 nfs4_schedule_lease_recovery(clp
);
8678 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
8680 struct nfs4_reclaim_complete_data
*calldata
= data
;
8681 struct nfs_client
*clp
= calldata
->clp
;
8682 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
8684 dprintk("--> %s\n", __func__
);
8685 if (!nfs41_sequence_done(task
, res
))
8688 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
8689 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
8690 rpc_restart_call_prepare(task
);
8693 dprintk("<-- %s\n", __func__
);
8696 static void nfs4_free_reclaim_complete_data(void *data
)
8698 struct nfs4_reclaim_complete_data
*calldata
= data
;
8703 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
8704 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
8705 .rpc_call_done
= nfs4_reclaim_complete_done
,
8706 .rpc_release
= nfs4_free_reclaim_complete_data
,
8710 * Issue a global reclaim complete.
8712 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
8713 struct rpc_cred
*cred
)
8715 struct nfs4_reclaim_complete_data
*calldata
;
8716 struct rpc_task
*task
;
8717 struct rpc_message msg
= {
8718 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
8721 struct rpc_task_setup task_setup_data
= {
8722 .rpc_client
= clp
->cl_rpcclient
,
8723 .rpc_message
= &msg
,
8724 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
8725 .flags
= RPC_TASK_ASYNC
,
8727 int status
= -ENOMEM
;
8729 dprintk("--> %s\n", __func__
);
8730 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
8731 if (calldata
== NULL
)
8733 calldata
->clp
= clp
;
8734 calldata
->arg
.one_fs
= 0;
8736 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0, 1);
8737 msg
.rpc_argp
= &calldata
->arg
;
8738 msg
.rpc_resp
= &calldata
->res
;
8739 task_setup_data
.callback_data
= calldata
;
8740 task
= rpc_run_task(&task_setup_data
);
8742 status
= PTR_ERR(task
);
8745 status
= rpc_wait_for_completion_task(task
);
8747 status
= task
->tk_status
;
8750 dprintk("<-- %s status=%d\n", __func__
, status
);
8755 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
8757 struct nfs4_layoutget
*lgp
= calldata
;
8758 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
8760 dprintk("--> %s\n", __func__
);
8761 nfs4_setup_sequence(server
->nfs_client
, &lgp
->args
.seq_args
,
8762 &lgp
->res
.seq_res
, task
);
8763 dprintk("<-- %s\n", __func__
);
8766 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
8768 struct nfs4_layoutget
*lgp
= calldata
;
8770 dprintk("--> %s\n", __func__
);
8771 nfs41_sequence_process(task
, &lgp
->res
.seq_res
);
8772 dprintk("<-- %s\n", __func__
);
8776 nfs4_layoutget_handle_exception(struct rpc_task
*task
,
8777 struct nfs4_layoutget
*lgp
, struct nfs4_exception
*exception
)
8779 struct inode
*inode
= lgp
->args
.inode
;
8780 struct nfs_server
*server
= NFS_SERVER(inode
);
8781 struct pnfs_layout_hdr
*lo
;
8782 int nfs4err
= task
->tk_status
;
8783 int err
, status
= 0;
8786 dprintk("--> %s tk_status => %d\n", __func__
, -task
->tk_status
);
8788 nfs4_sequence_free_slot(&lgp
->res
.seq_res
);
8795 * NFS4ERR_LAYOUTUNAVAILABLE means we are not supposed to use pnfs
8796 * on the file. set tk_status to -ENODATA to tell upper layer to
8799 case -NFS4ERR_LAYOUTUNAVAILABLE
:
8803 * NFS4ERR_BADLAYOUT means the MDS cannot return a layout of
8804 * length lgp->args.minlength != 0 (see RFC5661 section 18.43.3).
8806 case -NFS4ERR_BADLAYOUT
:
8807 status
= -EOVERFLOW
;
8810 * NFS4ERR_LAYOUTTRYLATER is a conflict with another client
8811 * (or clients) writing to the same RAID stripe except when
8812 * the minlength argument is 0 (see RFC5661 section 18.43.3).
8814 * Treat it like we would RECALLCONFLICT -- we retry for a little
8815 * while, and then eventually give up.
8817 case -NFS4ERR_LAYOUTTRYLATER
:
8818 if (lgp
->args
.minlength
== 0) {
8819 status
= -EOVERFLOW
;
8824 case -NFS4ERR_RECALLCONFLICT
:
8825 status
= -ERECALLCONFLICT
;
8827 case -NFS4ERR_DELEG_REVOKED
:
8828 case -NFS4ERR_ADMIN_REVOKED
:
8829 case -NFS4ERR_EXPIRED
:
8830 case -NFS4ERR_BAD_STATEID
:
8831 exception
->timeout
= 0;
8832 spin_lock(&inode
->i_lock
);
8833 lo
= NFS_I(inode
)->layout
;
8834 /* If the open stateid was bad, then recover it. */
8835 if (!lo
|| test_bit(NFS_LAYOUT_INVALID_STID
, &lo
->plh_flags
) ||
8836 !nfs4_stateid_match_other(&lgp
->args
.stateid
, &lo
->plh_stateid
)) {
8837 spin_unlock(&inode
->i_lock
);
8838 exception
->state
= lgp
->args
.ctx
->state
;
8839 exception
->stateid
= &lgp
->args
.stateid
;
8844 * Mark the bad layout state as invalid, then retry
8846 pnfs_mark_layout_stateid_invalid(lo
, &head
);
8847 spin_unlock(&inode
->i_lock
);
8848 nfs_commit_inode(inode
, 0);
8849 pnfs_free_lseg_list(&head
);
8854 err
= nfs4_handle_exception(server
, nfs4err
, exception
);
8856 if (exception
->retry
)
8862 dprintk("<-- %s\n", __func__
);
8866 size_t max_response_pages(struct nfs_server
*server
)
8868 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
8869 return nfs_page_array_len(0, max_resp_sz
);
8872 static void nfs4_layoutget_release(void *calldata
)
8874 struct nfs4_layoutget
*lgp
= calldata
;
8876 dprintk("--> %s\n", __func__
);
8877 nfs4_sequence_free_slot(&lgp
->res
.seq_res
);
8878 pnfs_layoutget_free(lgp
);
8879 dprintk("<-- %s\n", __func__
);
8882 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
8883 .rpc_call_prepare
= nfs4_layoutget_prepare
,
8884 .rpc_call_done
= nfs4_layoutget_done
,
8885 .rpc_release
= nfs4_layoutget_release
,
8888 struct pnfs_layout_segment
*
8889 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, long *timeout
)
8891 struct inode
*inode
= lgp
->args
.inode
;
8892 struct nfs_server
*server
= NFS_SERVER(inode
);
8893 struct rpc_task
*task
;
8894 struct rpc_message msg
= {
8895 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
8896 .rpc_argp
= &lgp
->args
,
8897 .rpc_resp
= &lgp
->res
,
8898 .rpc_cred
= lgp
->cred
,
8900 struct rpc_task_setup task_setup_data
= {
8901 .rpc_client
= server
->client
,
8902 .rpc_message
= &msg
,
8903 .callback_ops
= &nfs4_layoutget_call_ops
,
8904 .callback_data
= lgp
,
8905 .flags
= RPC_TASK_ASYNC
,
8907 struct pnfs_layout_segment
*lseg
= NULL
;
8908 struct nfs4_exception exception
= {
8910 .timeout
= *timeout
,
8914 dprintk("--> %s\n", __func__
);
8916 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
8917 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
8919 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0, 0);
8921 task
= rpc_run_task(&task_setup_data
);
8923 return ERR_CAST(task
);
8924 status
= rpc_wait_for_completion_task(task
);
8928 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
8929 if (task
->tk_status
< 0 || lgp
->res
.layoutp
->len
== 0) {
8930 status
= nfs4_layoutget_handle_exception(task
, lgp
, &exception
);
8931 *timeout
= exception
.timeout
;
8933 lseg
= pnfs_layout_process(lgp
);
8935 trace_nfs4_layoutget(lgp
->args
.ctx
,
8942 dprintk("<-- %s status=%d\n", __func__
, status
);
8944 return ERR_PTR(status
);
8949 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
8951 struct nfs4_layoutreturn
*lrp
= calldata
;
8953 dprintk("--> %s\n", __func__
);
8954 nfs4_setup_sequence(lrp
->clp
,
8955 &lrp
->args
.seq_args
,
8958 if (!pnfs_layout_is_valid(lrp
->args
.layout
))
8962 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
8964 struct nfs4_layoutreturn
*lrp
= calldata
;
8965 struct nfs_server
*server
;
8967 dprintk("--> %s\n", __func__
);
8969 if (!nfs41_sequence_process(task
, &lrp
->res
.seq_res
))
8972 server
= NFS_SERVER(lrp
->args
.inode
);
8973 switch (task
->tk_status
) {
8974 case -NFS4ERR_OLD_STATEID
:
8975 if (nfs4_layoutreturn_refresh_stateid(&lrp
->args
.stateid
,
8981 task
->tk_status
= 0;
8985 case -NFS4ERR_DELAY
:
8986 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) != -EAGAIN
)
8990 dprintk("<-- %s\n", __func__
);
8993 task
->tk_status
= 0;
8994 nfs4_sequence_free_slot(&lrp
->res
.seq_res
);
8995 rpc_restart_call_prepare(task
);
8998 static void nfs4_layoutreturn_release(void *calldata
)
9000 struct nfs4_layoutreturn
*lrp
= calldata
;
9001 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
9003 dprintk("--> %s\n", __func__
);
9004 pnfs_layoutreturn_free_lsegs(lo
, &lrp
->args
.stateid
, &lrp
->args
.range
,
9005 lrp
->res
.lrs_present
? &lrp
->res
.stateid
: NULL
);
9006 nfs4_sequence_free_slot(&lrp
->res
.seq_res
);
9007 if (lrp
->ld_private
.ops
&& lrp
->ld_private
.ops
->free
)
9008 lrp
->ld_private
.ops
->free(&lrp
->ld_private
);
9009 pnfs_put_layout_hdr(lrp
->args
.layout
);
9010 nfs_iput_and_deactive(lrp
->inode
);
9012 dprintk("<-- %s\n", __func__
);
9015 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
9016 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
9017 .rpc_call_done
= nfs4_layoutreturn_done
,
9018 .rpc_release
= nfs4_layoutreturn_release
,
9021 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
, bool sync
)
9023 struct rpc_task
*task
;
9024 struct rpc_message msg
= {
9025 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
9026 .rpc_argp
= &lrp
->args
,
9027 .rpc_resp
= &lrp
->res
,
9028 .rpc_cred
= lrp
->cred
,
9030 struct rpc_task_setup task_setup_data
= {
9031 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
9032 .rpc_message
= &msg
,
9033 .callback_ops
= &nfs4_layoutreturn_call_ops
,
9034 .callback_data
= lrp
,
9038 nfs4_state_protect(NFS_SERVER(lrp
->args
.inode
)->nfs_client
,
9039 NFS_SP4_MACH_CRED_PNFS_CLEANUP
,
9040 &task_setup_data
.rpc_client
, &msg
);
9042 dprintk("--> %s\n", __func__
);
9044 lrp
->inode
= nfs_igrab_and_active(lrp
->args
.inode
);
9046 nfs4_layoutreturn_release(lrp
);
9049 task_setup_data
.flags
|= RPC_TASK_ASYNC
;
9051 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1, 0);
9052 task
= rpc_run_task(&task_setup_data
);
9054 return PTR_ERR(task
);
9056 status
= task
->tk_status
;
9057 trace_nfs4_layoutreturn(lrp
->args
.inode
, &lrp
->args
.stateid
, status
);
9058 dprintk("<-- %s status=%d\n", __func__
, status
);
9064 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
9065 struct pnfs_device
*pdev
,
9066 struct rpc_cred
*cred
)
9068 struct nfs4_getdeviceinfo_args args
= {
9070 .notify_types
= NOTIFY_DEVICEID4_CHANGE
|
9071 NOTIFY_DEVICEID4_DELETE
,
9073 struct nfs4_getdeviceinfo_res res
= {
9076 struct rpc_message msg
= {
9077 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
9084 dprintk("--> %s\n", __func__
);
9085 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
9086 if (res
.notification
& ~args
.notify_types
)
9087 dprintk("%s: unsupported notification\n", __func__
);
9088 if (res
.notification
!= args
.notify_types
)
9091 dprintk("<-- %s status=%d\n", __func__
, status
);
9096 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
9097 struct pnfs_device
*pdev
,
9098 struct rpc_cred
*cred
)
9100 struct nfs4_exception exception
= { };
9104 err
= nfs4_handle_exception(server
,
9105 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
9107 } while (exception
.retry
);
9110 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
9112 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
9114 struct nfs4_layoutcommit_data
*data
= calldata
;
9115 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
9117 nfs4_setup_sequence(server
->nfs_client
,
9118 &data
->args
.seq_args
,
9124 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
9126 struct nfs4_layoutcommit_data
*data
= calldata
;
9127 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
9129 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
9132 switch (task
->tk_status
) { /* Just ignore these failures */
9133 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
9134 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
9135 case -NFS4ERR_BADLAYOUT
: /* no layout */
9136 case -NFS4ERR_GRACE
: /* loca_recalim always false */
9137 task
->tk_status
= 0;
9141 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) == -EAGAIN
) {
9142 rpc_restart_call_prepare(task
);
9148 static void nfs4_layoutcommit_release(void *calldata
)
9150 struct nfs4_layoutcommit_data
*data
= calldata
;
9152 pnfs_cleanup_layoutcommit(data
);
9153 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
9155 put_rpccred(data
->cred
);
9156 nfs_iput_and_deactive(data
->inode
);
9160 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
9161 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
9162 .rpc_call_done
= nfs4_layoutcommit_done
,
9163 .rpc_release
= nfs4_layoutcommit_release
,
9167 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
9169 struct rpc_message msg
= {
9170 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
9171 .rpc_argp
= &data
->args
,
9172 .rpc_resp
= &data
->res
,
9173 .rpc_cred
= data
->cred
,
9175 struct rpc_task_setup task_setup_data
= {
9176 .task
= &data
->task
,
9177 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
9178 .rpc_message
= &msg
,
9179 .callback_ops
= &nfs4_layoutcommit_ops
,
9180 .callback_data
= data
,
9182 struct rpc_task
*task
;
9185 dprintk("NFS: initiating layoutcommit call. sync %d "
9186 "lbw: %llu inode %lu\n", sync
,
9187 data
->args
.lastbytewritten
,
9188 data
->args
.inode
->i_ino
);
9191 data
->inode
= nfs_igrab_and_active(data
->args
.inode
);
9192 if (data
->inode
== NULL
) {
9193 nfs4_layoutcommit_release(data
);
9196 task_setup_data
.flags
= RPC_TASK_ASYNC
;
9198 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, 0);
9199 task
= rpc_run_task(&task_setup_data
);
9201 return PTR_ERR(task
);
9203 status
= task
->tk_status
;
9204 trace_nfs4_layoutcommit(data
->args
.inode
, &data
->args
.stateid
, status
);
9205 dprintk("%s: status %d\n", __func__
, status
);
9211 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
9212 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
9215 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9216 struct nfs_fsinfo
*info
,
9217 struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
9219 struct nfs41_secinfo_no_name_args args
= {
9220 .style
= SECINFO_STYLE_CURRENT_FH
,
9222 struct nfs4_secinfo_res res
= {
9225 struct rpc_message msg
= {
9226 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
9230 struct rpc_clnt
*clnt
= server
->client
;
9231 struct rpc_cred
*cred
= NULL
;
9234 if (use_integrity
) {
9235 clnt
= server
->nfs_client
->cl_rpcclient
;
9236 cred
= nfs4_get_clid_cred(server
->nfs_client
);
9237 msg
.rpc_cred
= cred
;
9240 dprintk("--> %s\n", __func__
);
9241 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
9243 dprintk("<-- %s status=%d\n", __func__
, status
);
9252 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9253 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
9255 struct nfs4_exception exception
= { };
9258 /* first try using integrity protection */
9259 err
= -NFS4ERR_WRONGSEC
;
9261 /* try to use integrity protection with machine cred */
9262 if (_nfs4_is_integrity_protected(server
->nfs_client
))
9263 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
9267 * if unable to use integrity protection, or SECINFO with
9268 * integrity protection returns NFS4ERR_WRONGSEC (which is
9269 * disallowed by spec, but exists in deployed servers) use
9270 * the current filesystem's rpc_client and the user cred.
9272 if (err
== -NFS4ERR_WRONGSEC
)
9273 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
9278 case -NFS4ERR_WRONGSEC
:
9282 err
= nfs4_handle_exception(server
, err
, &exception
);
9284 } while (exception
.retry
);
9290 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
9291 struct nfs_fsinfo
*info
)
9295 rpc_authflavor_t flavor
= RPC_AUTH_MAXFLAVOR
;
9296 struct nfs4_secinfo_flavors
*flavors
;
9297 struct nfs4_secinfo4
*secinfo
;
9300 page
= alloc_page(GFP_KERNEL
);
9306 flavors
= page_address(page
);
9307 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
9310 * Fall back on "guess and check" method if
9311 * the server doesn't support SECINFO_NO_NAME
9313 if (err
== -NFS4ERR_WRONGSEC
|| err
== -ENOTSUPP
) {
9314 err
= nfs4_find_root_sec(server
, fhandle
, info
);
9320 for (i
= 0; i
< flavors
->num_flavors
; i
++) {
9321 secinfo
= &flavors
->flavors
[i
];
9323 switch (secinfo
->flavor
) {
9327 flavor
= rpcauth_get_pseudoflavor(secinfo
->flavor
,
9328 &secinfo
->flavor_info
);
9331 flavor
= RPC_AUTH_MAXFLAVOR
;
9335 if (!nfs_auth_info_match(&server
->auth_info
, flavor
))
9336 flavor
= RPC_AUTH_MAXFLAVOR
;
9338 if (flavor
!= RPC_AUTH_MAXFLAVOR
) {
9339 err
= nfs4_lookup_root_sec(server
, fhandle
,
9346 if (flavor
== RPC_AUTH_MAXFLAVOR
)
9357 static int _nfs41_test_stateid(struct nfs_server
*server
,
9358 nfs4_stateid
*stateid
,
9359 struct rpc_cred
*cred
)
9362 struct nfs41_test_stateid_args args
= {
9365 struct nfs41_test_stateid_res res
;
9366 struct rpc_message msg
= {
9367 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
9372 struct rpc_clnt
*rpc_client
= server
->client
;
9374 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
9377 dprintk("NFS call test_stateid %p\n", stateid
);
9378 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0, 1);
9379 status
= nfs4_call_sync_sequence(rpc_client
, server
, &msg
,
9380 &args
.seq_args
, &res
.seq_res
);
9381 if (status
!= NFS_OK
) {
9382 dprintk("NFS reply test_stateid: failed, %d\n", status
);
9385 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
9389 static void nfs4_handle_delay_or_session_error(struct nfs_server
*server
,
9390 int err
, struct nfs4_exception
*exception
)
9392 exception
->retry
= 0;
9394 case -NFS4ERR_DELAY
:
9395 case -NFS4ERR_RETRY_UNCACHED_REP
:
9396 nfs4_handle_exception(server
, err
, exception
);
9398 case -NFS4ERR_BADSESSION
:
9399 case -NFS4ERR_BADSLOT
:
9400 case -NFS4ERR_BAD_HIGH_SLOT
:
9401 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
9402 case -NFS4ERR_DEADSESSION
:
9403 nfs4_do_handle_exception(server
, err
, exception
);
9408 * nfs41_test_stateid - perform a TEST_STATEID operation
9410 * @server: server / transport on which to perform the operation
9411 * @stateid: state ID to test
9414 * Returns NFS_OK if the server recognizes that "stateid" is valid.
9415 * Otherwise a negative NFS4ERR value is returned if the operation
9416 * failed or the state ID is not currently valid.
9418 static int nfs41_test_stateid(struct nfs_server
*server
,
9419 nfs4_stateid
*stateid
,
9420 struct rpc_cred
*cred
)
9422 struct nfs4_exception exception
= { };
9425 err
= _nfs41_test_stateid(server
, stateid
, cred
);
9426 nfs4_handle_delay_or_session_error(server
, err
, &exception
);
9427 } while (exception
.retry
);
9431 struct nfs_free_stateid_data
{
9432 struct nfs_server
*server
;
9433 struct nfs41_free_stateid_args args
;
9434 struct nfs41_free_stateid_res res
;
9437 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
9439 struct nfs_free_stateid_data
*data
= calldata
;
9440 nfs4_setup_sequence(data
->server
->nfs_client
,
9441 &data
->args
.seq_args
,
9446 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
9448 struct nfs_free_stateid_data
*data
= calldata
;
9450 nfs41_sequence_done(task
, &data
->res
.seq_res
);
9452 switch (task
->tk_status
) {
9453 case -NFS4ERR_DELAY
:
9454 if (nfs4_async_handle_error(task
, data
->server
, NULL
, NULL
) == -EAGAIN
)
9455 rpc_restart_call_prepare(task
);
9459 static void nfs41_free_stateid_release(void *calldata
)
9464 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
9465 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
9466 .rpc_call_done
= nfs41_free_stateid_done
,
9467 .rpc_release
= nfs41_free_stateid_release
,
9471 * nfs41_free_stateid - perform a FREE_STATEID operation
9473 * @server: server / transport on which to perform the operation
9474 * @stateid: state ID to release
9476 * @is_recovery: set to true if this call needs to be privileged
9478 * Note: this function is always asynchronous.
9480 static int nfs41_free_stateid(struct nfs_server
*server
,
9481 const nfs4_stateid
*stateid
,
9482 struct rpc_cred
*cred
,
9485 struct rpc_message msg
= {
9486 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
9489 struct rpc_task_setup task_setup
= {
9490 .rpc_client
= server
->client
,
9491 .rpc_message
= &msg
,
9492 .callback_ops
= &nfs41_free_stateid_ops
,
9493 .flags
= RPC_TASK_ASYNC
,
9495 struct nfs_free_stateid_data
*data
;
9496 struct rpc_task
*task
;
9498 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
9499 &task_setup
.rpc_client
, &msg
);
9501 dprintk("NFS call free_stateid %p\n", stateid
);
9502 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
9505 data
->server
= server
;
9506 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
9508 task_setup
.callback_data
= data
;
9510 msg
.rpc_argp
= &data
->args
;
9511 msg
.rpc_resp
= &data
->res
;
9512 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1, privileged
);
9513 task
= rpc_run_task(&task_setup
);
9515 return PTR_ERR(task
);
9521 nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
9523 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
9525 nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
9526 nfs4_free_lock_state(server
, lsp
);
9529 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
9530 const nfs4_stateid
*s2
)
9532 if (s1
->type
!= s2
->type
)
9535 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
9538 if (s1
->seqid
== s2
->seqid
)
9541 return s1
->seqid
== 0 || s2
->seqid
== 0;
9544 #endif /* CONFIG_NFS_V4_1 */
9546 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
9547 const nfs4_stateid
*s2
)
9549 return nfs4_stateid_match(s1
, s2
);
9553 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
9554 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
9555 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
9556 .recover_open
= nfs4_open_reclaim
,
9557 .recover_lock
= nfs4_lock_reclaim
,
9558 .establish_clid
= nfs4_init_clientid
,
9559 .detect_trunking
= nfs40_discover_server_trunking
,
9562 #if defined(CONFIG_NFS_V4_1)
9563 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
9564 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
9565 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
9566 .recover_open
= nfs4_open_reclaim
,
9567 .recover_lock
= nfs4_lock_reclaim
,
9568 .establish_clid
= nfs41_init_clientid
,
9569 .reclaim_complete
= nfs41_proc_reclaim_complete
,
9570 .detect_trunking
= nfs41_discover_server_trunking
,
9572 #endif /* CONFIG_NFS_V4_1 */
9574 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
9575 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
9576 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
9577 .recover_open
= nfs40_open_expired
,
9578 .recover_lock
= nfs4_lock_expired
,
9579 .establish_clid
= nfs4_init_clientid
,
9582 #if defined(CONFIG_NFS_V4_1)
9583 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
9584 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
9585 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
9586 .recover_open
= nfs41_open_expired
,
9587 .recover_lock
= nfs41_lock_expired
,
9588 .establish_clid
= nfs41_init_clientid
,
9590 #endif /* CONFIG_NFS_V4_1 */
9592 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
9593 .sched_state_renewal
= nfs4_proc_async_renew
,
9594 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
9595 .renew_lease
= nfs4_proc_renew
,
9598 #if defined(CONFIG_NFS_V4_1)
9599 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
9600 .sched_state_renewal
= nfs41_proc_async_sequence
,
9601 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
9602 .renew_lease
= nfs4_proc_sequence
,
9606 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops
= {
9607 .get_locations
= _nfs40_proc_get_locations
,
9608 .fsid_present
= _nfs40_proc_fsid_present
,
9611 #if defined(CONFIG_NFS_V4_1)
9612 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops
= {
9613 .get_locations
= _nfs41_proc_get_locations
,
9614 .fsid_present
= _nfs41_proc_fsid_present
,
9616 #endif /* CONFIG_NFS_V4_1 */
9618 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
9620 .init_caps
= NFS_CAP_READDIRPLUS
9621 | NFS_CAP_ATOMIC_OPEN
9622 | NFS_CAP_POSIX_LOCK
,
9623 .init_client
= nfs40_init_client
,
9624 .shutdown_client
= nfs40_shutdown_client
,
9625 .match_stateid
= nfs4_match_stateid
,
9626 .find_root_sec
= nfs4_find_root_sec
,
9627 .free_lock_state
= nfs4_release_lockowner
,
9628 .test_and_free_expired
= nfs40_test_and_free_expired_stateid
,
9629 .alloc_seqid
= nfs_alloc_seqid
,
9630 .call_sync_ops
= &nfs40_call_sync_ops
,
9631 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
9632 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
9633 .state_renewal_ops
= &nfs40_state_renewal_ops
,
9634 .mig_recovery_ops
= &nfs40_mig_recovery_ops
,
9637 #if defined(CONFIG_NFS_V4_1)
9638 static struct nfs_seqid
*
9639 nfs_alloc_no_seqid(struct nfs_seqid_counter
*arg1
, gfp_t arg2
)
9644 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
9646 .init_caps
= NFS_CAP_READDIRPLUS
9647 | NFS_CAP_ATOMIC_OPEN
9648 | NFS_CAP_POSIX_LOCK
9649 | NFS_CAP_STATEID_NFSV41
9650 | NFS_CAP_ATOMIC_OPEN_V1
9652 .init_client
= nfs41_init_client
,
9653 .shutdown_client
= nfs41_shutdown_client
,
9654 .match_stateid
= nfs41_match_stateid
,
9655 .find_root_sec
= nfs41_find_root_sec
,
9656 .free_lock_state
= nfs41_free_lock_state
,
9657 .test_and_free_expired
= nfs41_test_and_free_expired_stateid
,
9658 .alloc_seqid
= nfs_alloc_no_seqid
,
9659 .session_trunk
= nfs4_test_session_trunk
,
9660 .call_sync_ops
= &nfs41_call_sync_ops
,
9661 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
9662 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
9663 .state_renewal_ops
= &nfs41_state_renewal_ops
,
9664 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
9668 #if defined(CONFIG_NFS_V4_2)
9669 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
9671 .init_caps
= NFS_CAP_READDIRPLUS
9672 | NFS_CAP_ATOMIC_OPEN
9673 | NFS_CAP_POSIX_LOCK
9674 | NFS_CAP_STATEID_NFSV41
9675 | NFS_CAP_ATOMIC_OPEN_V1
9679 | NFS_CAP_OFFLOAD_CANCEL
9680 | NFS_CAP_DEALLOCATE
9682 | NFS_CAP_LAYOUTSTATS
9684 .init_client
= nfs41_init_client
,
9685 .shutdown_client
= nfs41_shutdown_client
,
9686 .match_stateid
= nfs41_match_stateid
,
9687 .find_root_sec
= nfs41_find_root_sec
,
9688 .free_lock_state
= nfs41_free_lock_state
,
9689 .call_sync_ops
= &nfs41_call_sync_ops
,
9690 .test_and_free_expired
= nfs41_test_and_free_expired_stateid
,
9691 .alloc_seqid
= nfs_alloc_no_seqid
,
9692 .session_trunk
= nfs4_test_session_trunk
,
9693 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
9694 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
9695 .state_renewal_ops
= &nfs41_state_renewal_ops
,
9696 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
9700 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
9701 [0] = &nfs_v4_0_minor_ops
,
9702 #if defined(CONFIG_NFS_V4_1)
9703 [1] = &nfs_v4_1_minor_ops
,
9705 #if defined(CONFIG_NFS_V4_2)
9706 [2] = &nfs_v4_2_minor_ops
,
9710 static ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *list
, size_t size
)
9712 ssize_t error
, error2
;
9714 error
= generic_listxattr(dentry
, list
, size
);
9722 error2
= nfs4_listxattr_nfs4_label(d_inode(dentry
), list
, size
);
9725 return error
+ error2
;
9728 static const struct inode_operations nfs4_dir_inode_operations
= {
9729 .create
= nfs_create
,
9730 .lookup
= nfs_lookup
,
9731 .atomic_open
= nfs_atomic_open
,
9733 .unlink
= nfs_unlink
,
9734 .symlink
= nfs_symlink
,
9738 .rename
= nfs_rename
,
9739 .permission
= nfs_permission
,
9740 .getattr
= nfs_getattr
,
9741 .setattr
= nfs_setattr
,
9742 .listxattr
= nfs4_listxattr
,
9745 static const struct inode_operations nfs4_file_inode_operations
= {
9746 .permission
= nfs_permission
,
9747 .getattr
= nfs_getattr
,
9748 .setattr
= nfs_setattr
,
9749 .listxattr
= nfs4_listxattr
,
9752 const struct nfs_rpc_ops nfs_v4_clientops
= {
9753 .version
= 4, /* protocol version */
9754 .dentry_ops
= &nfs4_dentry_operations
,
9755 .dir_inode_ops
= &nfs4_dir_inode_operations
,
9756 .file_inode_ops
= &nfs4_file_inode_operations
,
9757 .file_ops
= &nfs4_file_operations
,
9758 .getroot
= nfs4_proc_get_root
,
9759 .submount
= nfs4_submount
,
9760 .try_mount
= nfs4_try_mount
,
9761 .getattr
= nfs4_proc_getattr
,
9762 .setattr
= nfs4_proc_setattr
,
9763 .lookup
= nfs4_proc_lookup
,
9764 .lookupp
= nfs4_proc_lookupp
,
9765 .access
= nfs4_proc_access
,
9766 .readlink
= nfs4_proc_readlink
,
9767 .create
= nfs4_proc_create
,
9768 .remove
= nfs4_proc_remove
,
9769 .unlink_setup
= nfs4_proc_unlink_setup
,
9770 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
9771 .unlink_done
= nfs4_proc_unlink_done
,
9772 .rename_setup
= nfs4_proc_rename_setup
,
9773 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
9774 .rename_done
= nfs4_proc_rename_done
,
9775 .link
= nfs4_proc_link
,
9776 .symlink
= nfs4_proc_symlink
,
9777 .mkdir
= nfs4_proc_mkdir
,
9778 .rmdir
= nfs4_proc_rmdir
,
9779 .readdir
= nfs4_proc_readdir
,
9780 .mknod
= nfs4_proc_mknod
,
9781 .statfs
= nfs4_proc_statfs
,
9782 .fsinfo
= nfs4_proc_fsinfo
,
9783 .pathconf
= nfs4_proc_pathconf
,
9784 .set_capabilities
= nfs4_server_capabilities
,
9785 .decode_dirent
= nfs4_decode_dirent
,
9786 .pgio_rpc_prepare
= nfs4_proc_pgio_rpc_prepare
,
9787 .read_setup
= nfs4_proc_read_setup
,
9788 .read_done
= nfs4_read_done
,
9789 .write_setup
= nfs4_proc_write_setup
,
9790 .write_done
= nfs4_write_done
,
9791 .commit_setup
= nfs4_proc_commit_setup
,
9792 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
9793 .commit_done
= nfs4_commit_done
,
9794 .lock
= nfs4_proc_lock
,
9795 .clear_acl_cache
= nfs4_zap_acl_attr
,
9796 .close_context
= nfs4_close_context
,
9797 .open_context
= nfs4_atomic_open
,
9798 .have_delegation
= nfs4_have_delegation
,
9799 .alloc_client
= nfs4_alloc_client
,
9800 .init_client
= nfs4_init_client
,
9801 .free_client
= nfs4_free_client
,
9802 .create_server
= nfs4_create_server
,
9803 .clone_server
= nfs_clone_server
,
9806 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
9807 .name
= XATTR_NAME_NFSV4_ACL
,
9808 .list
= nfs4_xattr_list_nfs4_acl
,
9809 .get
= nfs4_xattr_get_nfs4_acl
,
9810 .set
= nfs4_xattr_set_nfs4_acl
,
9813 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
9814 &nfs4_xattr_nfs4_acl_handler
,
9815 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
9816 &nfs4_xattr_nfs4_label_handler
,