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/nfs_idmap.h>
55 #include <linux/xattr.h>
56 #include <linux/utsname.h>
57 #include <linux/freezer.h>
60 #include "delegation.h"
66 #include "nfs4session.h"
69 #include "nfs4trace.h"
71 #define NFSDBG_FACILITY NFSDBG_PROC
73 #define NFS4_POLL_RETRY_MIN (HZ/10)
74 #define NFS4_POLL_RETRY_MAX (15*HZ)
77 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
78 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
79 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
80 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
81 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
82 static int nfs4_proc_getattr(struct nfs_server
*, struct nfs_fh
*, struct nfs_fattr
*, struct nfs4_label
*label
);
83 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
, struct nfs4_label
*label
);
84 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
85 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
86 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
87 struct nfs4_label
*olabel
);
88 #ifdef CONFIG_NFS_V4_1
89 static int nfs41_test_stateid(struct nfs_server
*, nfs4_stateid
*,
91 static int nfs41_free_stateid(struct nfs_server
*, nfs4_stateid
*,
95 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
96 static inline struct nfs4_label
*
97 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
98 struct iattr
*sattr
, struct nfs4_label
*label
)
105 if (nfs_server_capable(dir
, NFS_CAP_SECURITY_LABEL
) == 0)
108 if (NFS_SERVER(dir
)->nfs_client
->cl_minorversion
< 2)
111 err
= security_dentry_init_security(dentry
, sattr
->ia_mode
,
112 &dentry
->d_name
, (void **)&label
->label
, &label
->len
);
119 nfs4_label_release_security(struct nfs4_label
*label
)
122 security_release_secctx(label
->label
, label
->len
);
124 static inline u32
*nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
127 return server
->attr_bitmask
;
129 return server
->attr_bitmask_nl
;
132 static inline struct nfs4_label
*
133 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
134 struct iattr
*sattr
, struct nfs4_label
*l
)
137 nfs4_label_release_security(struct nfs4_label
*label
)
140 nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
141 { return server
->attr_bitmask
; }
144 /* Prevent leaks of NFSv4 errors into userland */
145 static int nfs4_map_errors(int err
)
150 case -NFS4ERR_RESOURCE
:
151 case -NFS4ERR_LAYOUTTRYLATER
:
152 case -NFS4ERR_RECALLCONFLICT
:
154 case -NFS4ERR_WRONGSEC
:
156 case -NFS4ERR_BADOWNER
:
157 case -NFS4ERR_BADNAME
:
159 case -NFS4ERR_SHARE_DENIED
:
161 case -NFS4ERR_MINOR_VERS_MISMATCH
:
162 return -EPROTONOSUPPORT
;
163 case -NFS4ERR_ACCESS
:
165 case -NFS4ERR_FILE_OPEN
:
168 dprintk("%s could not handle NFSv4 error %d\n",
176 * This is our standard bitmap for GETATTR requests.
178 const u32 nfs4_fattr_bitmap
[3] = {
180 | FATTR4_WORD0_CHANGE
183 | FATTR4_WORD0_FILEID
,
185 | FATTR4_WORD1_NUMLINKS
187 | FATTR4_WORD1_OWNER_GROUP
188 | FATTR4_WORD1_RAWDEV
189 | FATTR4_WORD1_SPACE_USED
190 | FATTR4_WORD1_TIME_ACCESS
191 | FATTR4_WORD1_TIME_METADATA
192 | FATTR4_WORD1_TIME_MODIFY
,
193 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
194 FATTR4_WORD2_SECURITY_LABEL
198 static const u32 nfs4_pnfs_open_bitmap
[3] = {
200 | FATTR4_WORD0_CHANGE
203 | FATTR4_WORD0_FILEID
,
205 | FATTR4_WORD1_NUMLINKS
207 | FATTR4_WORD1_OWNER_GROUP
208 | FATTR4_WORD1_RAWDEV
209 | FATTR4_WORD1_SPACE_USED
210 | FATTR4_WORD1_TIME_ACCESS
211 | FATTR4_WORD1_TIME_METADATA
212 | FATTR4_WORD1_TIME_MODIFY
,
213 FATTR4_WORD2_MDSTHRESHOLD
216 static const u32 nfs4_open_noattr_bitmap
[3] = {
218 | FATTR4_WORD0_CHANGE
219 | FATTR4_WORD0_FILEID
,
222 const u32 nfs4_statfs_bitmap
[3] = {
223 FATTR4_WORD0_FILES_AVAIL
224 | FATTR4_WORD0_FILES_FREE
225 | FATTR4_WORD0_FILES_TOTAL
,
226 FATTR4_WORD1_SPACE_AVAIL
227 | FATTR4_WORD1_SPACE_FREE
228 | FATTR4_WORD1_SPACE_TOTAL
231 const u32 nfs4_pathconf_bitmap
[3] = {
233 | FATTR4_WORD0_MAXNAME
,
237 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
238 | FATTR4_WORD0_MAXREAD
239 | FATTR4_WORD0_MAXWRITE
240 | FATTR4_WORD0_LEASE_TIME
,
241 FATTR4_WORD1_TIME_DELTA
242 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
243 FATTR4_WORD2_LAYOUT_BLKSIZE
246 const u32 nfs4_fs_locations_bitmap
[3] = {
248 | FATTR4_WORD0_CHANGE
251 | FATTR4_WORD0_FILEID
252 | FATTR4_WORD0_FS_LOCATIONS
,
254 | FATTR4_WORD1_NUMLINKS
256 | FATTR4_WORD1_OWNER_GROUP
257 | FATTR4_WORD1_RAWDEV
258 | FATTR4_WORD1_SPACE_USED
259 | FATTR4_WORD1_TIME_ACCESS
260 | FATTR4_WORD1_TIME_METADATA
261 | FATTR4_WORD1_TIME_MODIFY
262 | FATTR4_WORD1_MOUNTED_ON_FILEID
,
265 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
266 struct nfs4_readdir_arg
*readdir
)
271 readdir
->cookie
= cookie
;
272 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
277 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
282 * NFSv4 servers do not return entries for '.' and '..'
283 * Therefore, we fake these entries here. We let '.'
284 * have cookie 0 and '..' have cookie 1. Note that
285 * when talking to the server, we always send cookie 0
288 start
= p
= kmap_atomic(*readdir
->pages
);
291 *p
++ = xdr_one
; /* next */
292 *p
++ = xdr_zero
; /* cookie, first word */
293 *p
++ = xdr_one
; /* cookie, second word */
294 *p
++ = xdr_one
; /* entry len */
295 memcpy(p
, ".\0\0\0", 4); /* entry */
297 *p
++ = xdr_one
; /* bitmap length */
298 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
299 *p
++ = htonl(8); /* attribute buffer length */
300 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
303 *p
++ = xdr_one
; /* next */
304 *p
++ = xdr_zero
; /* cookie, first word */
305 *p
++ = xdr_two
; /* cookie, second word */
306 *p
++ = xdr_two
; /* entry len */
307 memcpy(p
, "..\0\0", 4); /* entry */
309 *p
++ = xdr_one
; /* bitmap length */
310 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
311 *p
++ = htonl(8); /* attribute buffer length */
312 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
314 readdir
->pgbase
= (char *)p
- (char *)start
;
315 readdir
->count
-= readdir
->pgbase
;
316 kunmap_atomic(start
);
319 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
326 *timeout
= NFS4_POLL_RETRY_MIN
;
327 if (*timeout
> NFS4_POLL_RETRY_MAX
)
328 *timeout
= NFS4_POLL_RETRY_MAX
;
329 freezable_schedule_timeout_killable_unsafe(*timeout
);
330 if (fatal_signal_pending(current
))
336 /* This is the error handling routine for processes that are allowed
339 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
341 struct nfs_client
*clp
= server
->nfs_client
;
342 struct nfs4_state
*state
= exception
->state
;
343 struct inode
*inode
= exception
->inode
;
346 exception
->retry
= 0;
350 case -NFS4ERR_OPENMODE
:
351 if (inode
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
352 nfs4_inode_return_delegation(inode
);
353 exception
->retry
= 1;
358 ret
= nfs4_schedule_stateid_recovery(server
, state
);
361 goto wait_on_recovery
;
362 case -NFS4ERR_DELEG_REVOKED
:
363 case -NFS4ERR_ADMIN_REVOKED
:
364 case -NFS4ERR_BAD_STATEID
:
365 if (inode
!= NULL
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
366 nfs_remove_bad_delegation(inode
);
367 exception
->retry
= 1;
372 ret
= nfs4_schedule_stateid_recovery(server
, state
);
375 goto wait_on_recovery
;
376 case -NFS4ERR_EXPIRED
:
378 ret
= nfs4_schedule_stateid_recovery(server
, state
);
382 case -NFS4ERR_STALE_STATEID
:
383 case -NFS4ERR_STALE_CLIENTID
:
384 nfs4_schedule_lease_recovery(clp
);
385 goto wait_on_recovery
;
386 #if defined(CONFIG_NFS_V4_1)
387 case -NFS4ERR_BADSESSION
:
388 case -NFS4ERR_BADSLOT
:
389 case -NFS4ERR_BAD_HIGH_SLOT
:
390 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
391 case -NFS4ERR_DEADSESSION
:
392 case -NFS4ERR_SEQ_FALSE_RETRY
:
393 case -NFS4ERR_SEQ_MISORDERED
:
394 dprintk("%s ERROR: %d Reset session\n", __func__
,
396 nfs4_schedule_session_recovery(clp
->cl_session
, errorcode
);
397 goto wait_on_recovery
;
398 #endif /* defined(CONFIG_NFS_V4_1) */
399 case -NFS4ERR_FILE_OPEN
:
400 if (exception
->timeout
> HZ
) {
401 /* We have retried a decent amount, time to
409 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
412 case -NFS4ERR_RETRY_UNCACHED_REP
:
413 case -NFS4ERR_OLD_STATEID
:
414 exception
->retry
= 1;
416 case -NFS4ERR_BADOWNER
:
417 /* The following works around a Linux server bug! */
418 case -NFS4ERR_BADNAME
:
419 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
420 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
421 exception
->retry
= 1;
422 printk(KERN_WARNING
"NFS: v4 server %s "
423 "does not accept raw "
425 "Reenabling the idmapper.\n",
426 server
->nfs_client
->cl_hostname
);
429 /* We failed to handle the error */
430 return nfs4_map_errors(ret
);
432 ret
= nfs4_wait_clnt_recover(clp
);
434 exception
->retry
= 1;
439 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
440 * or 'false' otherwise.
442 static bool _nfs4_is_integrity_protected(struct nfs_client
*clp
)
444 rpc_authflavor_t flavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
446 if (flavor
== RPC_AUTH_GSS_KRB5I
||
447 flavor
== RPC_AUTH_GSS_KRB5P
)
453 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
455 spin_lock(&clp
->cl_lock
);
456 if (time_before(clp
->cl_last_renewal
,timestamp
))
457 clp
->cl_last_renewal
= timestamp
;
458 spin_unlock(&clp
->cl_lock
);
461 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
463 do_renew_lease(server
->nfs_client
, timestamp
);
466 struct nfs4_call_sync_data
{
467 const struct nfs_server
*seq_server
;
468 struct nfs4_sequence_args
*seq_args
;
469 struct nfs4_sequence_res
*seq_res
;
472 static void nfs4_init_sequence(struct nfs4_sequence_args
*args
,
473 struct nfs4_sequence_res
*res
, int cache_reply
)
475 args
->sa_slot
= NULL
;
476 args
->sa_cache_this
= cache_reply
;
477 args
->sa_privileged
= 0;
482 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
484 args
->sa_privileged
= 1;
487 #if defined(CONFIG_NFS_V4_1)
489 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
491 struct nfs4_session
*session
;
492 struct nfs4_slot_table
*tbl
;
493 bool send_new_highest_used_slotid
= false;
496 /* just wake up the next guy waiting since
497 * we may have not consumed a slot after all */
498 dprintk("%s: No slot\n", __func__
);
501 tbl
= res
->sr_slot
->table
;
502 session
= tbl
->session
;
504 spin_lock(&tbl
->slot_tbl_lock
);
505 /* Be nice to the server: try to ensure that the last transmitted
506 * value for highest_user_slotid <= target_highest_slotid
508 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
509 send_new_highest_used_slotid
= true;
511 if (nfs41_wake_and_assign_slot(tbl
, res
->sr_slot
)) {
512 send_new_highest_used_slotid
= false;
515 nfs4_free_slot(tbl
, res
->sr_slot
);
517 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
518 send_new_highest_used_slotid
= false;
520 spin_unlock(&tbl
->slot_tbl_lock
);
522 if (send_new_highest_used_slotid
)
523 nfs41_server_notify_highest_slotid_update(session
->clp
);
526 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
528 struct nfs4_session
*session
;
529 struct nfs4_slot
*slot
;
530 struct nfs_client
*clp
;
531 bool interrupted
= false;
534 /* don't increment the sequence number if the task wasn't sent */
535 if (!RPC_WAS_SENT(task
))
539 session
= slot
->table
->session
;
541 if (slot
->interrupted
) {
542 slot
->interrupted
= 0;
546 trace_nfs4_sequence_done(session
, res
);
547 /* Check the SEQUENCE operation status */
548 switch (res
->sr_status
) {
550 /* Update the slot's sequence and clientid lease timer */
553 do_renew_lease(clp
, res
->sr_timestamp
);
554 /* Check sequence flags */
555 if (res
->sr_status_flags
!= 0)
556 nfs4_schedule_lease_recovery(clp
);
557 nfs41_update_target_slotid(slot
->table
, slot
, res
);
561 * sr_status remains 1 if an RPC level error occurred.
562 * The server may or may not have processed the sequence
564 * Mark the slot as having hosted an interrupted RPC call.
566 slot
->interrupted
= 1;
569 /* The server detected a resend of the RPC call and
570 * returned NFS4ERR_DELAY as per Section 2.10.6.2
573 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
578 case -NFS4ERR_BADSLOT
:
580 * The slot id we used was probably retired. Try again
581 * using a different slot id.
584 case -NFS4ERR_SEQ_MISORDERED
:
586 * Was the last operation on this sequence interrupted?
587 * If so, retry after bumping the sequence number.
594 * Could this slot have been previously retired?
595 * If so, then the server may be expecting seq_nr = 1!
597 if (slot
->seq_nr
!= 1) {
602 case -NFS4ERR_SEQ_FALSE_RETRY
:
606 /* Just update the slot sequence no. */
610 /* The session may be reset by one of the error handlers. */
611 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
612 nfs41_sequence_free_slot(res
);
615 if (rpc_restart_call_prepare(task
)) {
621 if (!rpc_restart_call(task
))
623 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
627 static int nfs4_sequence_done(struct rpc_task
*task
,
628 struct nfs4_sequence_res
*res
)
630 if (res
->sr_slot
== NULL
)
632 return nfs41_sequence_done(task
, res
);
635 int nfs41_setup_sequence(struct nfs4_session
*session
,
636 struct nfs4_sequence_args
*args
,
637 struct nfs4_sequence_res
*res
,
638 struct rpc_task
*task
)
640 struct nfs4_slot
*slot
;
641 struct nfs4_slot_table
*tbl
;
643 dprintk("--> %s\n", __func__
);
644 /* slot already allocated? */
645 if (res
->sr_slot
!= NULL
)
648 tbl
= &session
->fc_slot_table
;
650 task
->tk_timeout
= 0;
652 spin_lock(&tbl
->slot_tbl_lock
);
653 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
654 !args
->sa_privileged
) {
655 /* The state manager will wait until the slot table is empty */
656 dprintk("%s session is draining\n", __func__
);
660 slot
= nfs4_alloc_slot(tbl
);
662 /* If out of memory, try again in 1/4 second */
663 if (slot
== ERR_PTR(-ENOMEM
))
664 task
->tk_timeout
= HZ
>> 2;
665 dprintk("<-- %s: no free slots\n", __func__
);
668 spin_unlock(&tbl
->slot_tbl_lock
);
670 args
->sa_slot
= slot
;
672 dprintk("<-- %s slotid=%u seqid=%u\n", __func__
,
673 slot
->slot_nr
, slot
->seq_nr
);
676 res
->sr_timestamp
= jiffies
;
677 res
->sr_status_flags
= 0;
679 * sr_status is only set in decode_sequence, and so will remain
680 * set to 1 if an rpc level failure occurs.
683 trace_nfs4_setup_sequence(session
, args
);
685 rpc_call_start(task
);
688 /* Privileged tasks are queued with top priority */
689 if (args
->sa_privileged
)
690 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
691 NULL
, RPC_PRIORITY_PRIVILEGED
);
693 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
694 spin_unlock(&tbl
->slot_tbl_lock
);
697 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
699 static int nfs4_setup_sequence(const struct nfs_server
*server
,
700 struct nfs4_sequence_args
*args
,
701 struct nfs4_sequence_res
*res
,
702 struct rpc_task
*task
)
704 struct nfs4_session
*session
= nfs4_get_session(server
);
707 if (session
== NULL
) {
708 rpc_call_start(task
);
712 dprintk("--> %s clp %p session %p sr_slot %u\n",
713 __func__
, session
->clp
, session
, res
->sr_slot
?
714 res
->sr_slot
->slot_nr
: NFS4_NO_SLOT
);
716 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
718 dprintk("<-- %s status=%d\n", __func__
, ret
);
722 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
724 struct nfs4_call_sync_data
*data
= calldata
;
725 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
727 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
729 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
732 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
734 struct nfs4_call_sync_data
*data
= calldata
;
736 nfs41_sequence_done(task
, data
->seq_res
);
739 static const struct rpc_call_ops nfs41_call_sync_ops
= {
740 .rpc_call_prepare
= nfs41_call_sync_prepare
,
741 .rpc_call_done
= nfs41_call_sync_done
,
744 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
745 struct nfs_server
*server
,
746 struct rpc_message
*msg
,
747 struct nfs4_sequence_args
*args
,
748 struct nfs4_sequence_res
*res
)
751 struct rpc_task
*task
;
752 struct nfs4_call_sync_data data
= {
753 .seq_server
= server
,
757 struct rpc_task_setup task_setup
= {
760 .callback_ops
= &nfs41_call_sync_ops
,
761 .callback_data
= &data
764 task
= rpc_run_task(&task_setup
);
768 ret
= task
->tk_status
;
775 static int nfs4_setup_sequence(const struct nfs_server
*server
,
776 struct nfs4_sequence_args
*args
,
777 struct nfs4_sequence_res
*res
,
778 struct rpc_task
*task
)
780 rpc_call_start(task
);
784 static int nfs4_sequence_done(struct rpc_task
*task
,
785 struct nfs4_sequence_res
*res
)
789 #endif /* CONFIG_NFS_V4_1 */
792 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
793 struct nfs_server
*server
,
794 struct rpc_message
*msg
,
795 struct nfs4_sequence_args
*args
,
796 struct nfs4_sequence_res
*res
)
798 return rpc_call_sync(clnt
, msg
, 0);
802 int nfs4_call_sync(struct rpc_clnt
*clnt
,
803 struct nfs_server
*server
,
804 struct rpc_message
*msg
,
805 struct nfs4_sequence_args
*args
,
806 struct nfs4_sequence_res
*res
,
809 nfs4_init_sequence(args
, res
, cache_reply
);
810 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
814 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
816 struct nfs_inode
*nfsi
= NFS_I(dir
);
818 spin_lock(&dir
->i_lock
);
819 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
820 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
821 nfs_force_lookup_revalidate(dir
);
822 dir
->i_version
= cinfo
->after
;
823 nfs_fscache_invalidate(dir
);
824 spin_unlock(&dir
->i_lock
);
827 struct nfs4_opendata
{
829 struct nfs_openargs o_arg
;
830 struct nfs_openres o_res
;
831 struct nfs_open_confirmargs c_arg
;
832 struct nfs_open_confirmres c_res
;
833 struct nfs4_string owner_name
;
834 struct nfs4_string group_name
;
835 struct nfs_fattr f_attr
;
836 struct nfs4_label
*f_label
;
838 struct dentry
*dentry
;
839 struct nfs4_state_owner
*owner
;
840 struct nfs4_state
*state
;
842 unsigned long timestamp
;
843 unsigned int rpc_done
: 1;
844 unsigned int is_recover
: 1;
849 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
850 int err
, struct nfs4_exception
*exception
)
854 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
856 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
857 exception
->retry
= 1;
861 static enum open_claim_type4
862 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
863 enum open_claim_type4 claim
)
865 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
870 case NFS4_OPEN_CLAIM_FH
:
871 return NFS4_OPEN_CLAIM_NULL
;
872 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
873 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
874 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
875 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
879 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
881 p
->o_res
.f_attr
= &p
->f_attr
;
882 p
->o_res
.f_label
= p
->f_label
;
883 p
->o_res
.seqid
= p
->o_arg
.seqid
;
884 p
->c_res
.seqid
= p
->c_arg
.seqid
;
885 p
->o_res
.server
= p
->o_arg
.server
;
886 p
->o_res
.access_request
= p
->o_arg
.access
;
887 nfs_fattr_init(&p
->f_attr
);
888 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
891 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
892 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
893 const struct iattr
*attrs
,
894 struct nfs4_label
*label
,
895 enum open_claim_type4 claim
,
898 struct dentry
*parent
= dget_parent(dentry
);
899 struct inode
*dir
= parent
->d_inode
;
900 struct nfs_server
*server
= NFS_SERVER(dir
);
901 struct nfs4_opendata
*p
;
903 p
= kzalloc(sizeof(*p
), gfp_mask
);
907 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
908 if (IS_ERR(p
->f_label
))
911 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
912 if (p
->o_arg
.seqid
== NULL
)
914 nfs_sb_active(dentry
->d_sb
);
915 p
->dentry
= dget(dentry
);
918 atomic_inc(&sp
->so_count
);
919 p
->o_arg
.open_flags
= flags
;
920 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
921 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
922 * will return permission denied for all bits until close */
923 if (!(flags
& O_EXCL
)) {
924 /* ask server to check for all possible rights as results
926 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
927 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
929 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
930 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
931 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
932 p
->o_arg
.name
= &dentry
->d_name
;
933 p
->o_arg
.server
= server
;
934 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
935 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
936 p
->o_arg
.label
= label
;
937 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
938 switch (p
->o_arg
.claim
) {
939 case NFS4_OPEN_CLAIM_NULL
:
940 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
941 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
942 p
->o_arg
.fh
= NFS_FH(dir
);
944 case NFS4_OPEN_CLAIM_PREVIOUS
:
945 case NFS4_OPEN_CLAIM_FH
:
946 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
947 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
948 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
950 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
953 p
->o_arg
.u
.attrs
= &p
->attrs
;
954 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
957 verf
[1] = current
->pid
;
958 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
959 sizeof(p
->o_arg
.u
.verifier
.data
));
961 p
->c_arg
.fh
= &p
->o_res
.fh
;
962 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
963 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
964 nfs4_init_opendata_res(p
);
969 nfs4_label_free(p
->f_label
);
977 static void nfs4_opendata_free(struct kref
*kref
)
979 struct nfs4_opendata
*p
= container_of(kref
,
980 struct nfs4_opendata
, kref
);
981 struct super_block
*sb
= p
->dentry
->d_sb
;
983 nfs_free_seqid(p
->o_arg
.seqid
);
984 if (p
->state
!= NULL
)
985 nfs4_put_open_state(p
->state
);
986 nfs4_put_state_owner(p
->owner
);
988 nfs4_label_free(p
->f_label
);
993 nfs_fattr_free_names(&p
->f_attr
);
997 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1000 kref_put(&p
->kref
, nfs4_opendata_free
);
1003 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
1007 ret
= rpc_wait_for_completion_task(task
);
1011 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1015 if (open_mode
& (O_EXCL
|O_TRUNC
))
1017 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1019 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1020 && state
->n_rdonly
!= 0;
1023 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1024 && state
->n_wronly
!= 0;
1026 case FMODE_READ
|FMODE_WRITE
:
1027 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1028 && state
->n_rdwr
!= 0;
1034 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1036 if (delegation
== NULL
)
1038 if ((delegation
->type
& fmode
) != fmode
)
1040 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1042 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1044 nfs_mark_delegation_referenced(delegation
);
1048 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1057 case FMODE_READ
|FMODE_WRITE
:
1060 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1063 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1065 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1066 nfs4_stateid_copy(&state
->stateid
, stateid
);
1067 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1068 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1071 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1074 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1076 case FMODE_READ
|FMODE_WRITE
:
1077 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1081 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1083 write_seqlock(&state
->seqlock
);
1084 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
1085 write_sequnlock(&state
->seqlock
);
1088 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1091 * Protect the call to nfs4_state_set_mode_locked and
1092 * serialise the stateid update
1094 write_seqlock(&state
->seqlock
);
1095 if (deleg_stateid
!= NULL
) {
1096 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1097 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1099 if (open_stateid
!= NULL
)
1100 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1101 write_sequnlock(&state
->seqlock
);
1102 spin_lock(&state
->owner
->so_lock
);
1103 update_open_stateflags(state
, fmode
);
1104 spin_unlock(&state
->owner
->so_lock
);
1107 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1109 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1110 struct nfs_delegation
*deleg_cur
;
1113 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1116 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1117 if (deleg_cur
== NULL
)
1120 spin_lock(&deleg_cur
->lock
);
1121 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1122 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1123 (deleg_cur
->type
& fmode
) != fmode
)
1124 goto no_delegation_unlock
;
1126 if (delegation
== NULL
)
1127 delegation
= &deleg_cur
->stateid
;
1128 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1129 goto no_delegation_unlock
;
1131 nfs_mark_delegation_referenced(deleg_cur
);
1132 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1134 no_delegation_unlock
:
1135 spin_unlock(&deleg_cur
->lock
);
1139 if (!ret
&& open_stateid
!= NULL
) {
1140 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1148 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1150 struct nfs_delegation
*delegation
;
1153 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1154 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1159 nfs4_inode_return_delegation(inode
);
1162 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1164 struct nfs4_state
*state
= opendata
->state
;
1165 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1166 struct nfs_delegation
*delegation
;
1167 int open_mode
= opendata
->o_arg
.open_flags
;
1168 fmode_t fmode
= opendata
->o_arg
.fmode
;
1169 nfs4_stateid stateid
;
1173 if (can_open_cached(state
, fmode
, open_mode
)) {
1174 spin_lock(&state
->owner
->so_lock
);
1175 if (can_open_cached(state
, fmode
, open_mode
)) {
1176 update_open_stateflags(state
, fmode
);
1177 spin_unlock(&state
->owner
->so_lock
);
1178 goto out_return_state
;
1180 spin_unlock(&state
->owner
->so_lock
);
1183 delegation
= rcu_dereference(nfsi
->delegation
);
1184 if (!can_open_delegated(delegation
, fmode
)) {
1188 /* Save the delegation */
1189 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1191 nfs_release_seqid(opendata
->o_arg
.seqid
);
1192 if (!opendata
->is_recover
) {
1193 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1199 /* Try to update the stateid using the delegation */
1200 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1201 goto out_return_state
;
1204 return ERR_PTR(ret
);
1206 atomic_inc(&state
->count
);
1211 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1213 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1214 struct nfs_delegation
*delegation
;
1215 int delegation_flags
= 0;
1218 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1220 delegation_flags
= delegation
->flags
;
1222 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1223 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1224 "returning a delegation for "
1225 "OPEN(CLAIM_DELEGATE_CUR)\n",
1227 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1228 nfs_inode_set_delegation(state
->inode
,
1229 data
->owner
->so_cred
,
1232 nfs_inode_reclaim_delegation(state
->inode
,
1233 data
->owner
->so_cred
,
1238 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1239 * and update the nfs4_state.
1241 static struct nfs4_state
*
1242 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1244 struct inode
*inode
= data
->state
->inode
;
1245 struct nfs4_state
*state
= data
->state
;
1248 if (!data
->rpc_done
) {
1249 ret
= data
->rpc_status
;
1254 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR_TYPE
) ||
1255 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_FILEID
) ||
1256 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_CHANGE
))
1260 state
= nfs4_get_open_state(inode
, data
->owner
);
1264 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1268 nfs_setsecurity(inode
, &data
->f_attr
, data
->f_label
);
1270 if (data
->o_res
.delegation_type
!= 0)
1271 nfs4_opendata_check_deleg(data
, state
);
1272 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1277 return ERR_PTR(ret
);
1281 static struct nfs4_state
*
1282 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1284 struct inode
*inode
;
1285 struct nfs4_state
*state
= NULL
;
1288 if (!data
->rpc_done
) {
1289 state
= nfs4_try_open_cached(data
);
1294 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1296 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1297 ret
= PTR_ERR(inode
);
1301 state
= nfs4_get_open_state(inode
, data
->owner
);
1304 if (data
->o_res
.delegation_type
!= 0)
1305 nfs4_opendata_check_deleg(data
, state
);
1306 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1310 nfs_release_seqid(data
->o_arg
.seqid
);
1315 return ERR_PTR(ret
);
1318 static struct nfs4_state
*
1319 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1321 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1322 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1323 return _nfs4_opendata_to_nfs4_state(data
);
1326 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1328 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1329 struct nfs_open_context
*ctx
;
1331 spin_lock(&state
->inode
->i_lock
);
1332 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1333 if (ctx
->state
!= state
)
1335 get_nfs_open_context(ctx
);
1336 spin_unlock(&state
->inode
->i_lock
);
1339 spin_unlock(&state
->inode
->i_lock
);
1340 return ERR_PTR(-ENOENT
);
1343 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1344 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1346 struct nfs4_opendata
*opendata
;
1348 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1349 NULL
, NULL
, claim
, GFP_NOFS
);
1350 if (opendata
== NULL
)
1351 return ERR_PTR(-ENOMEM
);
1352 opendata
->state
= state
;
1353 atomic_inc(&state
->count
);
1357 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1359 struct nfs4_state
*newstate
;
1362 opendata
->o_arg
.open_flags
= 0;
1363 opendata
->o_arg
.fmode
= fmode
;
1364 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1365 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1366 nfs4_init_opendata_res(opendata
);
1367 ret
= _nfs4_recover_proc_open(opendata
);
1370 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1371 if (IS_ERR(newstate
))
1372 return PTR_ERR(newstate
);
1373 nfs4_close_state(newstate
, fmode
);
1378 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1380 struct nfs4_state
*newstate
;
1383 /* memory barrier prior to reading state->n_* */
1384 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1385 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1387 if (state
->n_rdwr
!= 0) {
1388 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1389 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1392 if (newstate
!= state
)
1395 if (state
->n_wronly
!= 0) {
1396 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1397 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1400 if (newstate
!= state
)
1403 if (state
->n_rdonly
!= 0) {
1404 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1405 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1408 if (newstate
!= state
)
1412 * We may have performed cached opens for all three recoveries.
1413 * Check if we need to update the current stateid.
1415 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1416 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1417 write_seqlock(&state
->seqlock
);
1418 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1419 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1420 write_sequnlock(&state
->seqlock
);
1427 * reclaim state on the server after a reboot.
1429 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1431 struct nfs_delegation
*delegation
;
1432 struct nfs4_opendata
*opendata
;
1433 fmode_t delegation_type
= 0;
1436 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1437 NFS4_OPEN_CLAIM_PREVIOUS
);
1438 if (IS_ERR(opendata
))
1439 return PTR_ERR(opendata
);
1441 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1442 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1443 delegation_type
= delegation
->type
;
1445 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1446 status
= nfs4_open_recover(opendata
, state
);
1447 nfs4_opendata_put(opendata
);
1451 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1453 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1454 struct nfs4_exception exception
= { };
1457 err
= _nfs4_do_open_reclaim(ctx
, state
);
1458 trace_nfs4_open_reclaim(ctx
, 0, err
);
1459 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1461 if (err
!= -NFS4ERR_DELAY
)
1463 nfs4_handle_exception(server
, err
, &exception
);
1464 } while (exception
.retry
);
1468 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1470 struct nfs_open_context
*ctx
;
1473 ctx
= nfs4_state_find_open_context(state
);
1476 ret
= nfs4_do_open_reclaim(ctx
, state
);
1477 put_nfs_open_context(ctx
);
1481 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1485 printk(KERN_ERR
"NFS: %s: unhandled error "
1486 "%d.\n", __func__
, err
);
1491 case -NFS4ERR_BADSESSION
:
1492 case -NFS4ERR_BADSLOT
:
1493 case -NFS4ERR_BAD_HIGH_SLOT
:
1494 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1495 case -NFS4ERR_DEADSESSION
:
1496 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1497 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1499 case -NFS4ERR_STALE_CLIENTID
:
1500 case -NFS4ERR_STALE_STATEID
:
1501 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1502 case -NFS4ERR_EXPIRED
:
1503 /* Don't recall a delegation if it was lost */
1504 nfs4_schedule_lease_recovery(server
->nfs_client
);
1506 case -NFS4ERR_DELEG_REVOKED
:
1507 case -NFS4ERR_ADMIN_REVOKED
:
1508 case -NFS4ERR_BAD_STATEID
:
1509 case -NFS4ERR_OPENMODE
:
1510 nfs_inode_find_state_and_recover(state
->inode
,
1512 nfs4_schedule_stateid_recovery(server
, state
);
1514 case -NFS4ERR_DELAY
:
1515 case -NFS4ERR_GRACE
:
1516 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1520 case -NFS4ERR_DENIED
:
1521 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1527 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1529 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1530 struct nfs4_opendata
*opendata
;
1533 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1534 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1535 if (IS_ERR(opendata
))
1536 return PTR_ERR(opendata
);
1537 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1538 err
= nfs4_open_recover(opendata
, state
);
1539 nfs4_opendata_put(opendata
);
1540 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1543 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1545 struct nfs4_opendata
*data
= calldata
;
1547 data
->rpc_status
= task
->tk_status
;
1548 if (data
->rpc_status
== 0) {
1549 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1550 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1551 renew_lease(data
->o_res
.server
, data
->timestamp
);
1556 static void nfs4_open_confirm_release(void *calldata
)
1558 struct nfs4_opendata
*data
= calldata
;
1559 struct nfs4_state
*state
= NULL
;
1561 /* If this request hasn't been cancelled, do nothing */
1562 if (data
->cancelled
== 0)
1564 /* In case of error, no cleanup! */
1565 if (!data
->rpc_done
)
1567 state
= nfs4_opendata_to_nfs4_state(data
);
1569 nfs4_close_state(state
, data
->o_arg
.fmode
);
1571 nfs4_opendata_put(data
);
1574 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1575 .rpc_call_done
= nfs4_open_confirm_done
,
1576 .rpc_release
= nfs4_open_confirm_release
,
1580 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1582 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1584 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1585 struct rpc_task
*task
;
1586 struct rpc_message msg
= {
1587 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1588 .rpc_argp
= &data
->c_arg
,
1589 .rpc_resp
= &data
->c_res
,
1590 .rpc_cred
= data
->owner
->so_cred
,
1592 struct rpc_task_setup task_setup_data
= {
1593 .rpc_client
= server
->client
,
1594 .rpc_message
= &msg
,
1595 .callback_ops
= &nfs4_open_confirm_ops
,
1596 .callback_data
= data
,
1597 .workqueue
= nfsiod_workqueue
,
1598 .flags
= RPC_TASK_ASYNC
,
1602 kref_get(&data
->kref
);
1604 data
->rpc_status
= 0;
1605 data
->timestamp
= jiffies
;
1606 task
= rpc_run_task(&task_setup_data
);
1608 return PTR_ERR(task
);
1609 status
= nfs4_wait_for_completion_rpc_task(task
);
1611 data
->cancelled
= 1;
1614 status
= data
->rpc_status
;
1619 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1621 struct nfs4_opendata
*data
= calldata
;
1622 struct nfs4_state_owner
*sp
= data
->owner
;
1623 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1625 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1628 * Check if we still need to send an OPEN call, or if we can use
1629 * a delegation instead.
1631 if (data
->state
!= NULL
) {
1632 struct nfs_delegation
*delegation
;
1634 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1637 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1638 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1639 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1640 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1641 goto unlock_no_action
;
1644 /* Update client id. */
1645 data
->o_arg
.clientid
= clp
->cl_clientid
;
1646 switch (data
->o_arg
.claim
) {
1647 case NFS4_OPEN_CLAIM_PREVIOUS
:
1648 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1649 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1650 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1651 case NFS4_OPEN_CLAIM_FH
:
1652 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1653 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1655 data
->timestamp
= jiffies
;
1656 if (nfs4_setup_sequence(data
->o_arg
.server
,
1657 &data
->o_arg
.seq_args
,
1658 &data
->o_res
.seq_res
,
1660 nfs_release_seqid(data
->o_arg
.seqid
);
1662 /* Set the create mode (note dependency on the session type) */
1663 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1664 if (data
->o_arg
.open_flags
& O_EXCL
) {
1665 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1666 if (nfs4_has_persistent_session(clp
))
1667 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1668 else if (clp
->cl_mvops
->minor_version
> 0)
1669 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1675 task
->tk_action
= NULL
;
1677 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1680 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1682 struct nfs4_opendata
*data
= calldata
;
1684 data
->rpc_status
= task
->tk_status
;
1686 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1689 if (task
->tk_status
== 0) {
1690 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1691 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1695 data
->rpc_status
= -ELOOP
;
1698 data
->rpc_status
= -EISDIR
;
1701 data
->rpc_status
= -ENOTDIR
;
1704 renew_lease(data
->o_res
.server
, data
->timestamp
);
1705 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1706 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1711 static void nfs4_open_release(void *calldata
)
1713 struct nfs4_opendata
*data
= calldata
;
1714 struct nfs4_state
*state
= NULL
;
1716 /* If this request hasn't been cancelled, do nothing */
1717 if (data
->cancelled
== 0)
1719 /* In case of error, no cleanup! */
1720 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1722 /* In case we need an open_confirm, no cleanup! */
1723 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1725 state
= nfs4_opendata_to_nfs4_state(data
);
1727 nfs4_close_state(state
, data
->o_arg
.fmode
);
1729 nfs4_opendata_put(data
);
1732 static const struct rpc_call_ops nfs4_open_ops
= {
1733 .rpc_call_prepare
= nfs4_open_prepare
,
1734 .rpc_call_done
= nfs4_open_done
,
1735 .rpc_release
= nfs4_open_release
,
1738 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1740 struct inode
*dir
= data
->dir
->d_inode
;
1741 struct nfs_server
*server
= NFS_SERVER(dir
);
1742 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1743 struct nfs_openres
*o_res
= &data
->o_res
;
1744 struct rpc_task
*task
;
1745 struct rpc_message msg
= {
1746 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1749 .rpc_cred
= data
->owner
->so_cred
,
1751 struct rpc_task_setup task_setup_data
= {
1752 .rpc_client
= server
->client
,
1753 .rpc_message
= &msg
,
1754 .callback_ops
= &nfs4_open_ops
,
1755 .callback_data
= data
,
1756 .workqueue
= nfsiod_workqueue
,
1757 .flags
= RPC_TASK_ASYNC
,
1761 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1762 kref_get(&data
->kref
);
1764 data
->rpc_status
= 0;
1765 data
->cancelled
= 0;
1766 data
->is_recover
= 0;
1768 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1769 data
->is_recover
= 1;
1771 task
= rpc_run_task(&task_setup_data
);
1773 return PTR_ERR(task
);
1774 status
= nfs4_wait_for_completion_rpc_task(task
);
1776 data
->cancelled
= 1;
1779 status
= data
->rpc_status
;
1785 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1787 struct inode
*dir
= data
->dir
->d_inode
;
1788 struct nfs_openres
*o_res
= &data
->o_res
;
1791 status
= nfs4_run_open_task(data
, 1);
1792 if (status
!= 0 || !data
->rpc_done
)
1795 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1797 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1798 status
= _nfs4_proc_open_confirm(data
);
1806 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1807 struct nfs4_opendata
*opendata
,
1808 struct nfs4_state
*state
, fmode_t fmode
,
1811 struct nfs_access_entry cache
;
1814 /* access call failed or for some reason the server doesn't
1815 * support any access modes -- defer access call until later */
1816 if (opendata
->o_res
.access_supported
== 0)
1820 /* don't check MAY_WRITE - a newly created file may not have
1821 * write mode bits, but POSIX allows the creating process to write.
1822 * use openflags to check for exec, because fmode won't
1823 * always have FMODE_EXEC set when file open for exec. */
1824 if (openflags
& __FMODE_EXEC
) {
1825 /* ONLY check for exec rights */
1827 } else if (fmode
& FMODE_READ
)
1831 cache
.jiffies
= jiffies
;
1832 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1833 nfs_access_add_cache(state
->inode
, &cache
);
1835 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
1838 /* even though OPEN succeeded, access is denied. Close the file */
1839 nfs4_close_state(state
, fmode
);
1844 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1846 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1848 struct inode
*dir
= data
->dir
->d_inode
;
1849 struct nfs_server
*server
= NFS_SERVER(dir
);
1850 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1851 struct nfs_openres
*o_res
= &data
->o_res
;
1854 status
= nfs4_run_open_task(data
, 0);
1855 if (!data
->rpc_done
)
1858 if (status
== -NFS4ERR_BADNAME
&&
1859 !(o_arg
->open_flags
& O_CREAT
))
1864 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
1866 if (o_arg
->open_flags
& O_CREAT
)
1867 update_changeattr(dir
, &o_res
->cinfo
);
1868 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1869 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1870 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1871 status
= _nfs4_proc_open_confirm(data
);
1875 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1876 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
1880 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1882 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1887 * reclaim state on the server after a network partition.
1888 * Assumes caller holds the appropriate lock
1890 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1892 struct nfs4_opendata
*opendata
;
1895 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1896 NFS4_OPEN_CLAIM_FH
);
1897 if (IS_ERR(opendata
))
1898 return PTR_ERR(opendata
);
1899 ret
= nfs4_open_recover(opendata
, state
);
1901 d_drop(ctx
->dentry
);
1902 nfs4_opendata_put(opendata
);
1906 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1908 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1909 struct nfs4_exception exception
= { };
1913 err
= _nfs4_open_expired(ctx
, state
);
1914 trace_nfs4_open_expired(ctx
, 0, err
);
1915 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1920 case -NFS4ERR_GRACE
:
1921 case -NFS4ERR_DELAY
:
1922 nfs4_handle_exception(server
, err
, &exception
);
1925 } while (exception
.retry
);
1930 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1932 struct nfs_open_context
*ctx
;
1935 ctx
= nfs4_state_find_open_context(state
);
1938 ret
= nfs4_do_open_expired(ctx
, state
);
1939 put_nfs_open_context(ctx
);
1943 #if defined(CONFIG_NFS_V4_1)
1944 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
1946 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1947 nfs4_stateid
*stateid
= &state
->stateid
;
1948 struct nfs_delegation
*delegation
;
1949 struct rpc_cred
*cred
= NULL
;
1950 int status
= -NFS4ERR_BAD_STATEID
;
1952 /* If a state reset has been done, test_stateid is unneeded */
1953 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1956 /* Get the delegation credential for use by test/free_stateid */
1958 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1959 if (delegation
!= NULL
&&
1960 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
1961 cred
= get_rpccred(delegation
->cred
);
1963 status
= nfs41_test_stateid(server
, stateid
, cred
);
1964 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
1968 if (status
!= NFS_OK
) {
1969 /* Free the stateid unless the server explicitly
1970 * informs us the stateid is unrecognized. */
1971 if (status
!= -NFS4ERR_BAD_STATEID
)
1972 nfs41_free_stateid(server
, stateid
, cred
);
1973 nfs_remove_bad_delegation(state
->inode
);
1975 write_seqlock(&state
->seqlock
);
1976 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1977 write_sequnlock(&state
->seqlock
);
1978 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1986 * nfs41_check_open_stateid - possibly free an open stateid
1988 * @state: NFSv4 state for an inode
1990 * Returns NFS_OK if recovery for this stateid is now finished.
1991 * Otherwise a negative NFS4ERR value is returned.
1993 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
1995 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1996 nfs4_stateid
*stateid
= &state
->open_stateid
;
1997 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2000 /* If a state reset has been done, test_stateid is unneeded */
2001 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
2002 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
2003 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
2004 return -NFS4ERR_BAD_STATEID
;
2006 status
= nfs41_test_stateid(server
, stateid
, cred
);
2007 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2008 if (status
!= NFS_OK
) {
2009 /* Free the stateid unless the server explicitly
2010 * informs us the stateid is unrecognized. */
2011 if (status
!= -NFS4ERR_BAD_STATEID
)
2012 nfs41_free_stateid(server
, stateid
, cred
);
2014 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2015 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2016 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2017 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2022 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2026 nfs41_clear_delegation_stateid(state
);
2027 status
= nfs41_check_open_stateid(state
);
2028 if (status
!= NFS_OK
)
2029 status
= nfs4_open_expired(sp
, state
);
2035 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2036 * fields corresponding to attributes that were used to store the verifier.
2037 * Make sure we clobber those fields in the later setattr call
2039 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2041 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2042 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2043 sattr
->ia_valid
|= ATTR_ATIME
;
2045 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2046 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2047 sattr
->ia_valid
|= ATTR_MTIME
;
2050 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2053 struct nfs_open_context
*ctx
)
2055 struct nfs4_state_owner
*sp
= opendata
->owner
;
2056 struct nfs_server
*server
= sp
->so_server
;
2057 struct dentry
*dentry
;
2058 struct nfs4_state
*state
;
2062 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2064 ret
= _nfs4_proc_open(opendata
);
2068 state
= nfs4_opendata_to_nfs4_state(opendata
);
2069 ret
= PTR_ERR(state
);
2072 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2073 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2075 dentry
= opendata
->dentry
;
2076 if (dentry
->d_inode
== NULL
) {
2077 /* FIXME: Is this d_drop() ever needed? */
2079 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2080 if (dentry
== NULL
) {
2081 dentry
= opendata
->dentry
;
2082 } else if (dentry
!= ctx
->dentry
) {
2084 ctx
->dentry
= dget(dentry
);
2086 nfs_set_verifier(dentry
,
2087 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2090 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2095 if (dentry
->d_inode
== state
->inode
) {
2096 nfs_inode_attach_open_context(ctx
);
2097 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2098 nfs4_schedule_stateid_recovery(server
, state
);
2105 * Returns a referenced nfs4_state
2107 static int _nfs4_do_open(struct inode
*dir
,
2108 struct nfs_open_context
*ctx
,
2110 struct iattr
*sattr
,
2111 struct nfs4_label
*label
)
2113 struct nfs4_state_owner
*sp
;
2114 struct nfs4_state
*state
= NULL
;
2115 struct nfs_server
*server
= NFS_SERVER(dir
);
2116 struct nfs4_opendata
*opendata
;
2117 struct dentry
*dentry
= ctx
->dentry
;
2118 struct rpc_cred
*cred
= ctx
->cred
;
2119 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2120 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2121 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2122 struct nfs4_label
*olabel
= NULL
;
2125 /* Protect against reboot recovery conflicts */
2127 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2129 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2132 status
= nfs4_recover_expired_lease(server
);
2134 goto err_put_state_owner
;
2135 if (dentry
->d_inode
!= NULL
)
2136 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2138 if (dentry
->d_inode
)
2139 claim
= NFS4_OPEN_CLAIM_FH
;
2140 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2141 label
, claim
, GFP_KERNEL
);
2142 if (opendata
== NULL
)
2143 goto err_put_state_owner
;
2146 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2147 if (IS_ERR(olabel
)) {
2148 status
= PTR_ERR(olabel
);
2149 goto err_opendata_put
;
2153 if (ctx_th
&& server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2154 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2155 if (!opendata
->f_attr
.mdsthreshold
)
2156 goto err_free_label
;
2157 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2159 if (dentry
->d_inode
!= NULL
)
2160 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2162 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2164 goto err_free_label
;
2167 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2168 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2169 nfs4_exclusive_attrset(opendata
, sattr
);
2171 nfs_fattr_init(opendata
->o_res
.f_attr
);
2172 status
= nfs4_do_setattr(state
->inode
, cred
,
2173 opendata
->o_res
.f_attr
, sattr
,
2174 state
, label
, olabel
);
2176 nfs_setattr_update_inode(state
->inode
, sattr
);
2177 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2178 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2182 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
))
2183 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2185 kfree(opendata
->f_attr
.mdsthreshold
);
2186 opendata
->f_attr
.mdsthreshold
= NULL
;
2188 nfs4_label_free(olabel
);
2190 nfs4_opendata_put(opendata
);
2191 nfs4_put_state_owner(sp
);
2194 nfs4_label_free(olabel
);
2196 kfree(opendata
->f_attr
.mdsthreshold
);
2197 nfs4_opendata_put(opendata
);
2198 err_put_state_owner
:
2199 nfs4_put_state_owner(sp
);
2205 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2206 struct nfs_open_context
*ctx
,
2208 struct iattr
*sattr
,
2209 struct nfs4_label
*label
)
2211 struct nfs_server
*server
= NFS_SERVER(dir
);
2212 struct nfs4_exception exception
= { };
2213 struct nfs4_state
*res
;
2217 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
);
2219 trace_nfs4_open_file(ctx
, flags
, status
);
2222 /* NOTE: BAD_SEQID means the server and client disagree about the
2223 * book-keeping w.r.t. state-changing operations
2224 * (OPEN/CLOSE/LOCK/LOCKU...)
2225 * It is actually a sign of a bug on the client or on the server.
2227 * If we receive a BAD_SEQID error in the particular case of
2228 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2229 * have unhashed the old state_owner for us, and that we can
2230 * therefore safely retry using a new one. We should still warn
2231 * the user though...
2233 if (status
== -NFS4ERR_BAD_SEQID
) {
2234 pr_warn_ratelimited("NFS: v4 server %s "
2235 " returned a bad sequence-id error!\n",
2236 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2237 exception
.retry
= 1;
2241 * BAD_STATEID on OPEN means that the server cancelled our
2242 * state before it received the OPEN_CONFIRM.
2243 * Recover by retrying the request as per the discussion
2244 * on Page 181 of RFC3530.
2246 if (status
== -NFS4ERR_BAD_STATEID
) {
2247 exception
.retry
= 1;
2250 if (status
== -EAGAIN
) {
2251 /* We must have found a delegation */
2252 exception
.retry
= 1;
2255 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2257 res
= ERR_PTR(nfs4_handle_exception(server
,
2258 status
, &exception
));
2259 } while (exception
.retry
);
2263 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2264 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2265 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2266 struct nfs4_label
*olabel
)
2268 struct nfs_server
*server
= NFS_SERVER(inode
);
2269 struct nfs_setattrargs arg
= {
2270 .fh
= NFS_FH(inode
),
2273 .bitmask
= server
->attr_bitmask
,
2276 struct nfs_setattrres res
= {
2281 struct rpc_message msg
= {
2282 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2287 unsigned long timestamp
= jiffies
;
2292 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2294 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2296 nfs_fattr_init(fattr
);
2298 /* Servers should only apply open mode checks for file size changes */
2299 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2300 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2302 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2303 /* Use that stateid */
2304 } else if (truncate
&& state
!= NULL
&& nfs4_valid_open_stateid(state
)) {
2305 struct nfs_lockowner lockowner
= {
2306 .l_owner
= current
->files
,
2307 .l_pid
= current
->tgid
,
2309 nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2312 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2314 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2315 if (status
== 0 && state
!= NULL
)
2316 renew_lease(server
, timestamp
);
2320 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2321 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2322 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2323 struct nfs4_label
*olabel
)
2325 struct nfs_server
*server
= NFS_SERVER(inode
);
2326 struct nfs4_exception exception
= {
2332 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2333 trace_nfs4_setattr(inode
, err
);
2335 case -NFS4ERR_OPENMODE
:
2336 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2337 pr_warn_once("NFSv4: server %s is incorrectly "
2338 "applying open mode checks to "
2339 "a SETATTR that is not "
2340 "changing file size.\n",
2341 server
->nfs_client
->cl_hostname
);
2343 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2345 if (sattr
->ia_valid
& ATTR_OPEN
)
2350 err
= nfs4_handle_exception(server
, err
, &exception
);
2351 } while (exception
.retry
);
2356 struct nfs4_closedata
{
2357 struct inode
*inode
;
2358 struct nfs4_state
*state
;
2359 struct nfs_closeargs arg
;
2360 struct nfs_closeres res
;
2361 struct nfs_fattr fattr
;
2362 unsigned long timestamp
;
2367 static void nfs4_free_closedata(void *data
)
2369 struct nfs4_closedata
*calldata
= data
;
2370 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2371 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2374 pnfs_roc_release(calldata
->state
->inode
);
2375 nfs4_put_open_state(calldata
->state
);
2376 nfs_free_seqid(calldata
->arg
.seqid
);
2377 nfs4_put_state_owner(sp
);
2378 nfs_sb_deactive(sb
);
2382 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
2385 spin_lock(&state
->owner
->so_lock
);
2386 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2387 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
2389 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2392 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2395 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2396 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2397 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2399 spin_unlock(&state
->owner
->so_lock
);
2402 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2404 struct nfs4_closedata
*calldata
= data
;
2405 struct nfs4_state
*state
= calldata
->state
;
2406 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2408 dprintk("%s: begin!\n", __func__
);
2409 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2411 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2412 /* hmm. we are done with the inode, and in the process of freeing
2413 * the state_owner. we keep this around to process errors
2415 switch (task
->tk_status
) {
2418 pnfs_roc_set_barrier(state
->inode
,
2419 calldata
->roc_barrier
);
2420 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
2421 renew_lease(server
, calldata
->timestamp
);
2422 nfs4_close_clear_stateid_flags(state
,
2423 calldata
->arg
.fmode
);
2425 case -NFS4ERR_STALE_STATEID
:
2426 case -NFS4ERR_OLD_STATEID
:
2427 case -NFS4ERR_BAD_STATEID
:
2428 case -NFS4ERR_EXPIRED
:
2429 if (calldata
->arg
.fmode
== 0)
2432 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
2433 rpc_restart_call_prepare(task
);
2435 nfs_release_seqid(calldata
->arg
.seqid
);
2436 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2437 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2440 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2442 struct nfs4_closedata
*calldata
= data
;
2443 struct nfs4_state
*state
= calldata
->state
;
2444 struct inode
*inode
= calldata
->inode
;
2447 dprintk("%s: begin!\n", __func__
);
2448 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2451 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2452 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
2453 spin_lock(&state
->owner
->so_lock
);
2454 /* Calculate the change in open mode */
2455 if (state
->n_rdwr
== 0) {
2456 if (state
->n_rdonly
== 0) {
2457 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2458 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2459 calldata
->arg
.fmode
&= ~FMODE_READ
;
2461 if (state
->n_wronly
== 0) {
2462 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2463 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2464 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2467 if (!nfs4_valid_open_stateid(state
))
2469 spin_unlock(&state
->owner
->so_lock
);
2472 /* Note: exit _without_ calling nfs4_close_done */
2476 if (calldata
->arg
.fmode
== 0) {
2477 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2478 if (calldata
->roc
&&
2479 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2480 nfs_release_seqid(calldata
->arg
.seqid
);
2485 nfs_fattr_init(calldata
->res
.fattr
);
2486 calldata
->timestamp
= jiffies
;
2487 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2488 &calldata
->arg
.seq_args
,
2489 &calldata
->res
.seq_res
,
2491 nfs_release_seqid(calldata
->arg
.seqid
);
2492 dprintk("%s: done!\n", __func__
);
2495 task
->tk_action
= NULL
;
2497 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2500 static const struct rpc_call_ops nfs4_close_ops
= {
2501 .rpc_call_prepare
= nfs4_close_prepare
,
2502 .rpc_call_done
= nfs4_close_done
,
2503 .rpc_release
= nfs4_free_closedata
,
2507 * It is possible for data to be read/written from a mem-mapped file
2508 * after the sys_close call (which hits the vfs layer as a flush).
2509 * This means that we can't safely call nfsv4 close on a file until
2510 * the inode is cleared. This in turn means that we are not good
2511 * NFSv4 citizens - we do not indicate to the server to update the file's
2512 * share state even when we are done with one of the three share
2513 * stateid's in the inode.
2515 * NOTE: Caller must be holding the sp->so_owner semaphore!
2517 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2519 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2520 struct nfs4_closedata
*calldata
;
2521 struct nfs4_state_owner
*sp
= state
->owner
;
2522 struct rpc_task
*task
;
2523 struct rpc_message msg
= {
2524 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2525 .rpc_cred
= state
->owner
->so_cred
,
2527 struct rpc_task_setup task_setup_data
= {
2528 .rpc_client
= server
->client
,
2529 .rpc_message
= &msg
,
2530 .callback_ops
= &nfs4_close_ops
,
2531 .workqueue
= nfsiod_workqueue
,
2532 .flags
= RPC_TASK_ASYNC
,
2534 int status
= -ENOMEM
;
2536 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2537 if (calldata
== NULL
)
2539 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2540 calldata
->inode
= state
->inode
;
2541 calldata
->state
= state
;
2542 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2543 calldata
->arg
.stateid
= &state
->open_stateid
;
2544 /* Serialization for the sequence id */
2545 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2546 if (calldata
->arg
.seqid
== NULL
)
2547 goto out_free_calldata
;
2548 calldata
->arg
.fmode
= 0;
2549 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2550 calldata
->res
.fattr
= &calldata
->fattr
;
2551 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2552 calldata
->res
.server
= server
;
2553 calldata
->roc
= pnfs_roc(state
->inode
);
2554 nfs_sb_active(calldata
->inode
->i_sb
);
2556 msg
.rpc_argp
= &calldata
->arg
;
2557 msg
.rpc_resp
= &calldata
->res
;
2558 task_setup_data
.callback_data
= calldata
;
2559 task
= rpc_run_task(&task_setup_data
);
2561 return PTR_ERR(task
);
2564 status
= rpc_wait_for_completion_task(task
);
2570 nfs4_put_open_state(state
);
2571 nfs4_put_state_owner(sp
);
2575 static struct inode
*
2576 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2578 struct nfs4_state
*state
;
2579 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2581 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2583 /* Protect against concurrent sillydeletes */
2584 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
);
2586 nfs4_label_release_security(label
);
2589 return ERR_CAST(state
);
2590 return state
->inode
;
2593 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2595 if (ctx
->state
== NULL
)
2598 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2600 nfs4_close_state(ctx
->state
, ctx
->mode
);
2603 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2605 struct nfs4_server_caps_arg args
= {
2608 struct nfs4_server_caps_res res
= {};
2609 struct rpc_message msg
= {
2610 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2616 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2618 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2619 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2620 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2621 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2622 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2623 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2624 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2625 server
->caps
|= NFS_CAP_ACLS
;
2626 if (res
.has_links
!= 0)
2627 server
->caps
|= NFS_CAP_HARDLINKS
;
2628 if (res
.has_symlinks
!= 0)
2629 server
->caps
|= NFS_CAP_SYMLINKS
;
2630 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2631 server
->caps
|= NFS_CAP_FILEID
;
2632 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2633 server
->caps
|= NFS_CAP_MODE
;
2634 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2635 server
->caps
|= NFS_CAP_NLINK
;
2636 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2637 server
->caps
|= NFS_CAP_OWNER
;
2638 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2639 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2640 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2641 server
->caps
|= NFS_CAP_ATIME
;
2642 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2643 server
->caps
|= NFS_CAP_CTIME
;
2644 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2645 server
->caps
|= NFS_CAP_MTIME
;
2646 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2647 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2648 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2650 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2651 sizeof(server
->attr_bitmask
));
2653 if (server
->caps
& NFS_CAP_SECURITY_LABEL
) {
2654 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2655 res
.attr_bitmask
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2657 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2658 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2659 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2660 server
->acl_bitmask
= res
.acl_bitmask
;
2661 server
->fh_expire_type
= res
.fh_expire_type
;
2667 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2669 struct nfs4_exception exception
= { };
2672 err
= nfs4_handle_exception(server
,
2673 _nfs4_server_capabilities(server
, fhandle
),
2675 } while (exception
.retry
);
2679 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2680 struct nfs_fsinfo
*info
)
2683 struct nfs4_lookup_root_arg args
= {
2686 struct nfs4_lookup_res res
= {
2688 .fattr
= info
->fattr
,
2691 struct rpc_message msg
= {
2692 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2697 bitmask
[0] = nfs4_fattr_bitmap
[0];
2698 bitmask
[1] = nfs4_fattr_bitmap
[1];
2700 * Process the label in the upcoming getfattr
2702 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2704 nfs_fattr_init(info
->fattr
);
2705 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2708 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2709 struct nfs_fsinfo
*info
)
2711 struct nfs4_exception exception
= { };
2714 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2715 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2718 case -NFS4ERR_WRONGSEC
:
2721 err
= nfs4_handle_exception(server
, err
, &exception
);
2723 } while (exception
.retry
);
2728 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2729 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2731 struct rpc_auth_create_args auth_args
= {
2732 .pseudoflavor
= flavor
,
2734 struct rpc_auth
*auth
;
2737 auth
= rpcauth_create(&auth_args
, server
->client
);
2742 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2748 * Retry pseudoroot lookup with various security flavors. We do this when:
2750 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2751 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2753 * Returns zero on success, or a negative NFS4ERR value, or a
2754 * negative errno value.
2756 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2757 struct nfs_fsinfo
*info
)
2759 /* Per 3530bis 15.33.5 */
2760 static const rpc_authflavor_t flav_array
[] = {
2764 RPC_AUTH_UNIX
, /* courtesy */
2767 int status
= -EPERM
;
2770 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
2771 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2772 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2778 * -EACCESS could mean that the user doesn't have correct permissions
2779 * to access the mount. It could also mean that we tried to mount
2780 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2781 * existing mount programs don't handle -EACCES very well so it should
2782 * be mapped to -EPERM instead.
2784 if (status
== -EACCES
)
2789 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
2790 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
2792 int mv
= server
->nfs_client
->cl_minorversion
;
2793 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
2797 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2798 * @server: initialized nfs_server handle
2799 * @fhandle: we fill in the pseudo-fs root file handle
2800 * @info: we fill in an FSINFO struct
2802 * Returns zero on success, or a negative errno.
2804 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2805 struct nfs_fsinfo
*info
)
2809 status
= nfs4_lookup_root(server
, fhandle
, info
);
2810 if ((status
== -NFS4ERR_WRONGSEC
) &&
2811 !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2812 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
2815 status
= nfs4_server_capabilities(server
, fhandle
);
2817 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2819 return nfs4_map_errors(status
);
2822 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
2823 struct nfs_fsinfo
*info
)
2826 struct nfs_fattr
*fattr
= info
->fattr
;
2827 struct nfs4_label
*label
= NULL
;
2829 error
= nfs4_server_capabilities(server
, mntfh
);
2831 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
2835 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
2837 return PTR_ERR(label
);
2839 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
2841 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
2842 goto err_free_label
;
2845 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
2846 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
2847 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
2850 nfs4_label_free(label
);
2856 * Get locations and (maybe) other attributes of a referral.
2857 * Note that we'll actually follow the referral later when
2858 * we detect fsid mismatch in inode revalidation
2860 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
2861 const struct qstr
*name
, struct nfs_fattr
*fattr
,
2862 struct nfs_fh
*fhandle
)
2864 int status
= -ENOMEM
;
2865 struct page
*page
= NULL
;
2866 struct nfs4_fs_locations
*locations
= NULL
;
2868 page
= alloc_page(GFP_KERNEL
);
2871 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2872 if (locations
== NULL
)
2875 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
2878 /* Make sure server returned a different fsid for the referral */
2879 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2880 dprintk("%s: server did not return a different fsid for"
2881 " a referral at %s\n", __func__
, name
->name
);
2885 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2886 nfs_fixup_referral_attributes(&locations
->fattr
);
2888 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2889 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2890 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2898 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2899 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2901 struct nfs4_getattr_arg args
= {
2903 .bitmask
= server
->attr_bitmask
,
2905 struct nfs4_getattr_res res
= {
2910 struct rpc_message msg
= {
2911 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2916 args
.bitmask
= nfs4_bitmask(server
, label
);
2918 nfs_fattr_init(fattr
);
2919 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2922 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2923 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2925 struct nfs4_exception exception
= { };
2928 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
2929 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
2930 err
= nfs4_handle_exception(server
, err
,
2932 } while (exception
.retry
);
2937 * The file is not closed if it is opened due to the a request to change
2938 * the size of the file. The open call will not be needed once the
2939 * VFS layer lookup-intents are implemented.
2941 * Close is called when the inode is destroyed.
2942 * If we haven't opened the file for O_WRONLY, we
2943 * need to in the size_change case to obtain a stateid.
2946 * Because OPEN is always done by name in nfsv4, it is
2947 * possible that we opened a different file by the same
2948 * name. We can recognize this race condition, but we
2949 * can't do anything about it besides returning an error.
2951 * This will be fixed with VFS changes (lookup-intent).
2954 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2955 struct iattr
*sattr
)
2957 struct inode
*inode
= dentry
->d_inode
;
2958 struct rpc_cred
*cred
= NULL
;
2959 struct nfs4_state
*state
= NULL
;
2960 struct nfs4_label
*label
= NULL
;
2963 if (pnfs_ld_layoutret_on_setattr(inode
))
2964 pnfs_commit_and_return_layout(inode
);
2966 nfs_fattr_init(fattr
);
2968 /* Deal with open(O_TRUNC) */
2969 if (sattr
->ia_valid
& ATTR_OPEN
)
2970 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
2972 /* Optimization: if the end result is no change, don't RPC */
2973 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
2976 /* Search for an existing open(O_WRITE) file */
2977 if (sattr
->ia_valid
& ATTR_FILE
) {
2978 struct nfs_open_context
*ctx
;
2980 ctx
= nfs_file_open_context(sattr
->ia_file
);
2987 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
2989 return PTR_ERR(label
);
2991 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
2993 nfs_setattr_update_inode(inode
, sattr
);
2994 nfs_setsecurity(inode
, fattr
, label
);
2996 nfs4_label_free(label
);
3000 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
3001 const struct qstr
*name
, struct nfs_fh
*fhandle
,
3002 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3004 struct nfs_server
*server
= NFS_SERVER(dir
);
3006 struct nfs4_lookup_arg args
= {
3007 .bitmask
= server
->attr_bitmask
,
3008 .dir_fh
= NFS_FH(dir
),
3011 struct nfs4_lookup_res res
= {
3017 struct rpc_message msg
= {
3018 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3023 args
.bitmask
= nfs4_bitmask(server
, label
);
3025 nfs_fattr_init(fattr
);
3027 dprintk("NFS call lookup %s\n", name
->name
);
3028 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3029 dprintk("NFS reply lookup: %d\n", status
);
3033 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3035 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3036 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3037 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3041 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3042 struct qstr
*name
, struct nfs_fh
*fhandle
,
3043 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3045 struct nfs4_exception exception
= { };
3046 struct rpc_clnt
*client
= *clnt
;
3049 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3050 trace_nfs4_lookup(dir
, name
, err
);
3052 case -NFS4ERR_BADNAME
:
3055 case -NFS4ERR_MOVED
:
3056 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3058 case -NFS4ERR_WRONGSEC
:
3060 if (client
!= *clnt
)
3063 client
= nfs4_create_sec_client(client
, dir
, name
);
3065 return PTR_ERR(client
);
3067 exception
.retry
= 1;
3070 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3072 } while (exception
.retry
);
3077 else if (client
!= *clnt
)
3078 rpc_shutdown_client(client
);
3083 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3084 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3085 struct nfs4_label
*label
)
3088 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3090 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3091 if (client
!= NFS_CLIENT(dir
)) {
3092 rpc_shutdown_client(client
);
3093 nfs_fixup_secinfo_attributes(fattr
);
3099 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3100 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3103 struct rpc_clnt
*client
= rpc_clone_client(NFS_CLIENT(dir
));
3105 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3107 rpc_shutdown_client(client
);
3108 return ERR_PTR(status
);
3113 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3115 struct nfs_server
*server
= NFS_SERVER(inode
);
3116 struct nfs4_accessargs args
= {
3117 .fh
= NFS_FH(inode
),
3118 .bitmask
= server
->cache_consistency_bitmask
,
3120 struct nfs4_accessres res
= {
3123 struct rpc_message msg
= {
3124 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3127 .rpc_cred
= entry
->cred
,
3129 int mode
= entry
->mask
;
3133 * Determine which access bits we want to ask for...
3135 if (mode
& MAY_READ
)
3136 args
.access
|= NFS4_ACCESS_READ
;
3137 if (S_ISDIR(inode
->i_mode
)) {
3138 if (mode
& MAY_WRITE
)
3139 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3140 if (mode
& MAY_EXEC
)
3141 args
.access
|= NFS4_ACCESS_LOOKUP
;
3143 if (mode
& MAY_WRITE
)
3144 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3145 if (mode
& MAY_EXEC
)
3146 args
.access
|= NFS4_ACCESS_EXECUTE
;
3149 res
.fattr
= nfs_alloc_fattr();
3150 if (res
.fattr
== NULL
)
3153 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3155 nfs_access_set_mask(entry
, res
.access
);
3156 nfs_refresh_inode(inode
, res
.fattr
);
3158 nfs_free_fattr(res
.fattr
);
3162 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3164 struct nfs4_exception exception
= { };
3167 err
= _nfs4_proc_access(inode
, entry
);
3168 trace_nfs4_access(inode
, err
);
3169 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3171 } while (exception
.retry
);
3176 * TODO: For the time being, we don't try to get any attributes
3177 * along with any of the zero-copy operations READ, READDIR,
3180 * In the case of the first three, we want to put the GETATTR
3181 * after the read-type operation -- this is because it is hard
3182 * to predict the length of a GETATTR response in v4, and thus
3183 * align the READ data correctly. This means that the GETATTR
3184 * may end up partially falling into the page cache, and we should
3185 * shift it into the 'tail' of the xdr_buf before processing.
3186 * To do this efficiently, we need to know the total length
3187 * of data received, which doesn't seem to be available outside
3190 * In the case of WRITE, we also want to put the GETATTR after
3191 * the operation -- in this case because we want to make sure
3192 * we get the post-operation mtime and size.
3194 * Both of these changes to the XDR layer would in fact be quite
3195 * minor, but I decided to leave them for a subsequent patch.
3197 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3198 unsigned int pgbase
, unsigned int pglen
)
3200 struct nfs4_readlink args
= {
3201 .fh
= NFS_FH(inode
),
3206 struct nfs4_readlink_res res
;
3207 struct rpc_message msg
= {
3208 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3213 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3216 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3217 unsigned int pgbase
, unsigned int pglen
)
3219 struct nfs4_exception exception
= { };
3222 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3223 trace_nfs4_readlink(inode
, err
);
3224 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3226 } while (exception
.retry
);
3231 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3234 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3237 struct nfs4_label l
, *ilabel
= NULL
;
3238 struct nfs_open_context
*ctx
;
3239 struct nfs4_state
*state
;
3242 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3244 return PTR_ERR(ctx
);
3246 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3248 sattr
->ia_mode
&= ~current_umask();
3249 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
);
3250 if (IS_ERR(state
)) {
3251 status
= PTR_ERR(state
);
3255 nfs4_label_release_security(ilabel
);
3256 put_nfs_open_context(ctx
);
3260 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3262 struct nfs_server
*server
= NFS_SERVER(dir
);
3263 struct nfs_removeargs args
= {
3267 struct nfs_removeres res
= {
3270 struct rpc_message msg
= {
3271 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3277 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3279 update_changeattr(dir
, &res
.cinfo
);
3283 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3285 struct nfs4_exception exception
= { };
3288 err
= _nfs4_proc_remove(dir
, name
);
3289 trace_nfs4_remove(dir
, name
, err
);
3290 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3292 } while (exception
.retry
);
3296 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3298 struct nfs_server
*server
= NFS_SERVER(dir
);
3299 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3300 struct nfs_removeres
*res
= msg
->rpc_resp
;
3302 res
->server
= server
;
3303 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3304 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3306 nfs_fattr_init(res
->dir_attr
);
3309 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3311 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3312 &data
->args
.seq_args
,
3317 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3319 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3320 struct nfs_removeres
*res
= &data
->res
;
3322 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3324 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3326 update_changeattr(dir
, &res
->cinfo
);
3330 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3332 struct nfs_server
*server
= NFS_SERVER(dir
);
3333 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3334 struct nfs_renameres
*res
= msg
->rpc_resp
;
3336 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3337 res
->server
= server
;
3338 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3341 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3343 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3344 &data
->args
.seq_args
,
3349 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3350 struct inode
*new_dir
)
3352 struct nfs_renamedata
*data
= task
->tk_calldata
;
3353 struct nfs_renameres
*res
= &data
->res
;
3355 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3357 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3360 update_changeattr(old_dir
, &res
->old_cinfo
);
3361 update_changeattr(new_dir
, &res
->new_cinfo
);
3365 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3366 struct inode
*new_dir
, struct qstr
*new_name
)
3368 struct nfs_server
*server
= NFS_SERVER(old_dir
);
3369 struct nfs_renameargs arg
= {
3370 .old_dir
= NFS_FH(old_dir
),
3371 .new_dir
= NFS_FH(new_dir
),
3372 .old_name
= old_name
,
3373 .new_name
= new_name
,
3375 struct nfs_renameres res
= {
3378 struct rpc_message msg
= {
3379 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
3383 int status
= -ENOMEM
;
3385 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3387 update_changeattr(old_dir
, &res
.old_cinfo
);
3388 update_changeattr(new_dir
, &res
.new_cinfo
);
3393 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3394 struct inode
*new_dir
, struct qstr
*new_name
)
3396 struct nfs4_exception exception
= { };
3399 err
= _nfs4_proc_rename(old_dir
, old_name
,
3401 trace_nfs4_rename(old_dir
, old_name
, new_dir
, new_name
, err
);
3402 err
= nfs4_handle_exception(NFS_SERVER(old_dir
), err
,
3404 } while (exception
.retry
);
3408 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3410 struct nfs_server
*server
= NFS_SERVER(inode
);
3411 struct nfs4_link_arg arg
= {
3412 .fh
= NFS_FH(inode
),
3413 .dir_fh
= NFS_FH(dir
),
3415 .bitmask
= server
->attr_bitmask
,
3417 struct nfs4_link_res res
= {
3421 struct rpc_message msg
= {
3422 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3426 int status
= -ENOMEM
;
3428 res
.fattr
= nfs_alloc_fattr();
3429 if (res
.fattr
== NULL
)
3432 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3433 if (IS_ERR(res
.label
)) {
3434 status
= PTR_ERR(res
.label
);
3437 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3439 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3441 update_changeattr(dir
, &res
.cinfo
);
3442 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3444 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3448 nfs4_label_free(res
.label
);
3451 nfs_free_fattr(res
.fattr
);
3455 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3457 struct nfs4_exception exception
= { };
3460 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3461 _nfs4_proc_link(inode
, dir
, name
),
3463 } while (exception
.retry
);
3467 struct nfs4_createdata
{
3468 struct rpc_message msg
;
3469 struct nfs4_create_arg arg
;
3470 struct nfs4_create_res res
;
3472 struct nfs_fattr fattr
;
3473 struct nfs4_label
*label
;
3476 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3477 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3479 struct nfs4_createdata
*data
;
3481 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3483 struct nfs_server
*server
= NFS_SERVER(dir
);
3485 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3486 if (IS_ERR(data
->label
))
3489 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3490 data
->msg
.rpc_argp
= &data
->arg
;
3491 data
->msg
.rpc_resp
= &data
->res
;
3492 data
->arg
.dir_fh
= NFS_FH(dir
);
3493 data
->arg
.server
= server
;
3494 data
->arg
.name
= name
;
3495 data
->arg
.attrs
= sattr
;
3496 data
->arg
.ftype
= ftype
;
3497 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3498 data
->res
.server
= server
;
3499 data
->res
.fh
= &data
->fh
;
3500 data
->res
.fattr
= &data
->fattr
;
3501 data
->res
.label
= data
->label
;
3502 nfs_fattr_init(data
->res
.fattr
);
3510 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3512 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3513 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3515 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3516 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3521 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3523 nfs4_label_free(data
->label
);
3527 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3528 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3529 struct nfs4_label
*label
)
3531 struct nfs4_createdata
*data
;
3532 int status
= -ENAMETOOLONG
;
3534 if (len
> NFS4_MAXPATHLEN
)
3538 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3542 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3543 data
->arg
.u
.symlink
.pages
= &page
;
3544 data
->arg
.u
.symlink
.len
= len
;
3545 data
->arg
.label
= label
;
3547 status
= nfs4_do_create(dir
, dentry
, data
);
3549 nfs4_free_createdata(data
);
3554 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3555 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3557 struct nfs4_exception exception
= { };
3558 struct nfs4_label l
, *label
= NULL
;
3561 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3564 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3565 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3566 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3568 } while (exception
.retry
);
3570 nfs4_label_release_security(label
);
3574 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3575 struct iattr
*sattr
, struct nfs4_label
*label
)
3577 struct nfs4_createdata
*data
;
3578 int status
= -ENOMEM
;
3580 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3584 data
->arg
.label
= label
;
3585 status
= nfs4_do_create(dir
, dentry
, data
);
3587 nfs4_free_createdata(data
);
3592 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3593 struct iattr
*sattr
)
3595 struct nfs4_exception exception
= { };
3596 struct nfs4_label l
, *label
= NULL
;
3599 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3601 sattr
->ia_mode
&= ~current_umask();
3603 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3604 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3605 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3607 } while (exception
.retry
);
3608 nfs4_label_release_security(label
);
3613 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3614 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3616 struct inode
*dir
= dentry
->d_inode
;
3617 struct nfs4_readdir_arg args
= {
3622 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3625 struct nfs4_readdir_res res
;
3626 struct rpc_message msg
= {
3627 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3634 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
3635 dentry
->d_parent
->d_name
.name
,
3636 dentry
->d_name
.name
,
3637 (unsigned long long)cookie
);
3638 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3639 res
.pgbase
= args
.pgbase
;
3640 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3642 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3643 status
+= args
.pgbase
;
3646 nfs_invalidate_atime(dir
);
3648 dprintk("%s: returns %d\n", __func__
, status
);
3652 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3653 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3655 struct nfs4_exception exception
= { };
3658 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3659 pages
, count
, plus
);
3660 trace_nfs4_readdir(dentry
->d_inode
, err
);
3661 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3663 } while (exception
.retry
);
3667 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3668 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3670 struct nfs4_createdata
*data
;
3671 int mode
= sattr
->ia_mode
;
3672 int status
= -ENOMEM
;
3674 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3679 data
->arg
.ftype
= NF4FIFO
;
3680 else if (S_ISBLK(mode
)) {
3681 data
->arg
.ftype
= NF4BLK
;
3682 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3683 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3685 else if (S_ISCHR(mode
)) {
3686 data
->arg
.ftype
= NF4CHR
;
3687 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3688 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3689 } else if (!S_ISSOCK(mode
)) {
3694 data
->arg
.label
= label
;
3695 status
= nfs4_do_create(dir
, dentry
, data
);
3697 nfs4_free_createdata(data
);
3702 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3703 struct iattr
*sattr
, dev_t rdev
)
3705 struct nfs4_exception exception
= { };
3706 struct nfs4_label l
, *label
= NULL
;
3709 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3711 sattr
->ia_mode
&= ~current_umask();
3713 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3714 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3715 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3717 } while (exception
.retry
);
3719 nfs4_label_release_security(label
);
3724 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3725 struct nfs_fsstat
*fsstat
)
3727 struct nfs4_statfs_arg args
= {
3729 .bitmask
= server
->attr_bitmask
,
3731 struct nfs4_statfs_res res
= {
3734 struct rpc_message msg
= {
3735 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3740 nfs_fattr_init(fsstat
->fattr
);
3741 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3744 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3746 struct nfs4_exception exception
= { };
3749 err
= nfs4_handle_exception(server
,
3750 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3752 } while (exception
.retry
);
3756 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3757 struct nfs_fsinfo
*fsinfo
)
3759 struct nfs4_fsinfo_arg args
= {
3761 .bitmask
= server
->attr_bitmask
,
3763 struct nfs4_fsinfo_res res
= {
3766 struct rpc_message msg
= {
3767 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3772 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3775 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3777 struct nfs4_exception exception
= { };
3778 unsigned long now
= jiffies
;
3782 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3783 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
3785 struct nfs_client
*clp
= server
->nfs_client
;
3787 spin_lock(&clp
->cl_lock
);
3788 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
3789 clp
->cl_last_renewal
= now
;
3790 spin_unlock(&clp
->cl_lock
);
3793 err
= nfs4_handle_exception(server
, err
, &exception
);
3794 } while (exception
.retry
);
3798 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3802 nfs_fattr_init(fsinfo
->fattr
);
3803 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3805 /* block layout checks this! */
3806 server
->pnfs_blksize
= fsinfo
->blksize
;
3807 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
3813 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3814 struct nfs_pathconf
*pathconf
)
3816 struct nfs4_pathconf_arg args
= {
3818 .bitmask
= server
->attr_bitmask
,
3820 struct nfs4_pathconf_res res
= {
3821 .pathconf
= pathconf
,
3823 struct rpc_message msg
= {
3824 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3829 /* None of the pathconf attributes are mandatory to implement */
3830 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3831 memset(pathconf
, 0, sizeof(*pathconf
));
3835 nfs_fattr_init(pathconf
->fattr
);
3836 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3839 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3840 struct nfs_pathconf
*pathconf
)
3842 struct nfs4_exception exception
= { };
3846 err
= nfs4_handle_exception(server
,
3847 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3849 } while (exception
.retry
);
3853 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
3854 const struct nfs_open_context
*ctx
,
3855 const struct nfs_lock_context
*l_ctx
,
3858 const struct nfs_lockowner
*lockowner
= NULL
;
3861 lockowner
= &l_ctx
->lockowner
;
3862 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
3864 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
3866 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
3867 const struct nfs_open_context
*ctx
,
3868 const struct nfs_lock_context
*l_ctx
,
3871 nfs4_stateid current_stateid
;
3873 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
))
3875 return nfs4_stateid_match(stateid
, ¤t_stateid
);
3878 static bool nfs4_error_stateid_expired(int err
)
3881 case -NFS4ERR_DELEG_REVOKED
:
3882 case -NFS4ERR_ADMIN_REVOKED
:
3883 case -NFS4ERR_BAD_STATEID
:
3884 case -NFS4ERR_STALE_STATEID
:
3885 case -NFS4ERR_OLD_STATEID
:
3886 case -NFS4ERR_OPENMODE
:
3887 case -NFS4ERR_EXPIRED
:
3893 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3895 nfs_invalidate_atime(data
->header
->inode
);
3898 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3900 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
3902 trace_nfs4_read(data
, task
->tk_status
);
3903 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3904 rpc_restart_call_prepare(task
);
3908 __nfs4_read_done_cb(data
);
3909 if (task
->tk_status
> 0)
3910 renew_lease(server
, data
->timestamp
);
3914 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
3915 struct nfs_readargs
*args
)
3918 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3919 nfs4_stateid_is_current(&args
->stateid
,
3924 rpc_restart_call_prepare(task
);
3928 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3931 dprintk("--> %s\n", __func__
);
3933 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3935 if (nfs4_read_stateid_changed(task
, &data
->args
))
3937 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3938 nfs4_read_done_cb(task
, data
);
3941 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3943 data
->timestamp
= jiffies
;
3944 data
->read_done_cb
= nfs4_read_done_cb
;
3945 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3946 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
3949 static void nfs4_proc_read_rpc_prepare(struct rpc_task
*task
, struct nfs_read_data
*data
)
3951 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
3952 &data
->args
.seq_args
,
3956 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
3957 data
->args
.lock_context
, FMODE_READ
);
3960 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3962 struct inode
*inode
= data
->header
->inode
;
3964 trace_nfs4_write(data
, task
->tk_status
);
3965 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3966 rpc_restart_call_prepare(task
);
3969 if (task
->tk_status
>= 0) {
3970 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3971 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
3976 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
3977 struct nfs_writeargs
*args
)
3980 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3981 nfs4_stateid_is_current(&args
->stateid
,
3986 rpc_restart_call_prepare(task
);
3990 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3992 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3994 if (nfs4_write_stateid_changed(task
, &data
->args
))
3996 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
3997 nfs4_write_done_cb(task
, data
);
4001 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data
*data
)
4003 const struct nfs_pgio_header
*hdr
= data
->header
;
4005 /* Don't request attributes for pNFS or O_DIRECT writes */
4006 if (data
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
4008 /* Otherwise, request attributes if and only if we don't hold
4011 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
4014 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
4016 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
4018 if (!nfs4_write_need_cache_consistency_data(data
)) {
4019 data
->args
.bitmask
= NULL
;
4020 data
->res
.fattr
= NULL
;
4022 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4024 if (!data
->write_done_cb
)
4025 data
->write_done_cb
= nfs4_write_done_cb
;
4026 data
->res
.server
= server
;
4027 data
->timestamp
= jiffies
;
4029 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4030 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4033 static void nfs4_proc_write_rpc_prepare(struct rpc_task
*task
, struct nfs_write_data
*data
)
4035 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
4036 &data
->args
.seq_args
,
4040 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
4041 data
->args
.lock_context
, FMODE_WRITE
);
4044 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4046 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4047 &data
->args
.seq_args
,
4052 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4054 struct inode
*inode
= data
->inode
;
4056 trace_nfs4_commit(data
, task
->tk_status
);
4057 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
4058 rpc_restart_call_prepare(task
);
4064 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4066 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4068 return data
->commit_done_cb(task
, data
);
4071 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4073 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4075 if (data
->commit_done_cb
== NULL
)
4076 data
->commit_done_cb
= nfs4_commit_done_cb
;
4077 data
->res
.server
= server
;
4078 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4079 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4082 struct nfs4_renewdata
{
4083 struct nfs_client
*client
;
4084 unsigned long timestamp
;
4088 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4089 * standalone procedure for queueing an asynchronous RENEW.
4091 static void nfs4_renew_release(void *calldata
)
4093 struct nfs4_renewdata
*data
= calldata
;
4094 struct nfs_client
*clp
= data
->client
;
4096 if (atomic_read(&clp
->cl_count
) > 1)
4097 nfs4_schedule_state_renewal(clp
);
4098 nfs_put_client(clp
);
4102 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4104 struct nfs4_renewdata
*data
= calldata
;
4105 struct nfs_client
*clp
= data
->client
;
4106 unsigned long timestamp
= data
->timestamp
;
4108 trace_nfs4_renew_async(clp
, task
->tk_status
);
4109 if (task
->tk_status
< 0) {
4110 /* Unless we're shutting down, schedule state recovery! */
4111 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4113 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4114 nfs4_schedule_lease_recovery(clp
);
4117 nfs4_schedule_path_down_recovery(clp
);
4119 do_renew_lease(clp
, timestamp
);
4122 static const struct rpc_call_ops nfs4_renew_ops
= {
4123 .rpc_call_done
= nfs4_renew_done
,
4124 .rpc_release
= nfs4_renew_release
,
4127 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4129 struct rpc_message msg
= {
4130 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4134 struct nfs4_renewdata
*data
;
4136 if (renew_flags
== 0)
4138 if (!atomic_inc_not_zero(&clp
->cl_count
))
4140 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4144 data
->timestamp
= jiffies
;
4145 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4146 &nfs4_renew_ops
, data
);
4149 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4151 struct rpc_message msg
= {
4152 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4156 unsigned long now
= jiffies
;
4159 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4162 do_renew_lease(clp
, now
);
4166 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4168 return (server
->caps
& NFS_CAP_ACLS
)
4169 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
4170 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
4173 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4174 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4177 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4179 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4180 struct page
**pages
, unsigned int *pgbase
)
4182 struct page
*newpage
, **spages
;
4188 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4189 newpage
= alloc_page(GFP_KERNEL
);
4191 if (newpage
== NULL
)
4193 memcpy(page_address(newpage
), buf
, len
);
4198 } while (buflen
!= 0);
4204 __free_page(spages
[rc
-1]);
4208 struct nfs4_cached_acl
{
4214 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4216 struct nfs_inode
*nfsi
= NFS_I(inode
);
4218 spin_lock(&inode
->i_lock
);
4219 kfree(nfsi
->nfs4_acl
);
4220 nfsi
->nfs4_acl
= acl
;
4221 spin_unlock(&inode
->i_lock
);
4224 static void nfs4_zap_acl_attr(struct inode
*inode
)
4226 nfs4_set_cached_acl(inode
, NULL
);
4229 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4231 struct nfs_inode
*nfsi
= NFS_I(inode
);
4232 struct nfs4_cached_acl
*acl
;
4235 spin_lock(&inode
->i_lock
);
4236 acl
= nfsi
->nfs4_acl
;
4239 if (buf
== NULL
) /* user is just asking for length */
4241 if (acl
->cached
== 0)
4243 ret
= -ERANGE
; /* see getxattr(2) man page */
4244 if (acl
->len
> buflen
)
4246 memcpy(buf
, acl
->data
, acl
->len
);
4250 spin_unlock(&inode
->i_lock
);
4254 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4256 struct nfs4_cached_acl
*acl
;
4257 size_t buflen
= sizeof(*acl
) + acl_len
;
4259 if (buflen
<= PAGE_SIZE
) {
4260 acl
= kmalloc(buflen
, GFP_KERNEL
);
4264 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4266 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4273 nfs4_set_cached_acl(inode
, acl
);
4277 * The getxattr API returns the required buffer length when called with a
4278 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4279 * the required buf. On a NULL buf, we send a page of data to the server
4280 * guessing that the ACL request can be serviced by a page. If so, we cache
4281 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4282 * the cache. If not so, we throw away the page, and cache the required
4283 * length. The next getxattr call will then produce another round trip to
4284 * the server, this time with the input buf of the required size.
4286 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4288 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4289 struct nfs_getaclargs args
= {
4290 .fh
= NFS_FH(inode
),
4294 struct nfs_getaclres res
= {
4297 struct rpc_message msg
= {
4298 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4302 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4303 int ret
= -ENOMEM
, i
;
4305 /* As long as we're doing a round trip to the server anyway,
4306 * let's be prepared for a page of acl data. */
4309 if (npages
> ARRAY_SIZE(pages
))
4312 for (i
= 0; i
< npages
; i
++) {
4313 pages
[i
] = alloc_page(GFP_KERNEL
);
4318 /* for decoding across pages */
4319 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4320 if (!res
.acl_scratch
)
4323 args
.acl_len
= npages
* PAGE_SIZE
;
4324 args
.acl_pgbase
= 0;
4326 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4327 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4328 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4329 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4333 /* Handle the case where the passed-in buffer is too short */
4334 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4335 /* Did the user only issue a request for the acl length? */
4341 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4343 if (res
.acl_len
> buflen
) {
4347 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4352 for (i
= 0; i
< npages
; i
++)
4354 __free_page(pages
[i
]);
4355 if (res
.acl_scratch
)
4356 __free_page(res
.acl_scratch
);
4360 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4362 struct nfs4_exception exception
= { };
4365 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4366 trace_nfs4_get_acl(inode
, ret
);
4369 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4370 } while (exception
.retry
);
4374 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4376 struct nfs_server
*server
= NFS_SERVER(inode
);
4379 if (!nfs4_server_supports_acls(server
))
4381 ret
= nfs_revalidate_inode(server
, inode
);
4384 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4385 nfs_zap_acl_cache(inode
);
4386 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4388 /* -ENOENT is returned if there is no ACL or if there is an ACL
4389 * but no cached acl data, just the acl length */
4391 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4394 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4396 struct nfs_server
*server
= NFS_SERVER(inode
);
4397 struct page
*pages
[NFS4ACL_MAXPAGES
];
4398 struct nfs_setaclargs arg
= {
4399 .fh
= NFS_FH(inode
),
4403 struct nfs_setaclres res
;
4404 struct rpc_message msg
= {
4405 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4409 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4412 if (!nfs4_server_supports_acls(server
))
4414 if (npages
> ARRAY_SIZE(pages
))
4416 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4419 nfs4_inode_return_delegation(inode
);
4420 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4423 * Free each page after tx, so the only ref left is
4424 * held by the network stack
4427 put_page(pages
[i
-1]);
4430 * Acl update can result in inode attribute update.
4431 * so mark the attribute cache invalid.
4433 spin_lock(&inode
->i_lock
);
4434 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4435 spin_unlock(&inode
->i_lock
);
4436 nfs_access_zap_cache(inode
);
4437 nfs_zap_acl_cache(inode
);
4441 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4443 struct nfs4_exception exception
= { };
4446 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4447 trace_nfs4_set_acl(inode
, err
);
4448 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4450 } while (exception
.retry
);
4454 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4455 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4458 struct nfs_server
*server
= NFS_SERVER(inode
);
4459 struct nfs_fattr fattr
;
4460 struct nfs4_label label
= {0, 0, buflen
, buf
};
4462 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4463 struct nfs4_getattr_arg args
= {
4464 .fh
= NFS_FH(inode
),
4467 struct nfs4_getattr_res res
= {
4472 struct rpc_message msg
= {
4473 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4479 nfs_fattr_init(&fattr
);
4481 ret
= rpc_call_sync(server
->client
, &msg
, 0);
4484 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4486 if (buflen
< label
.len
)
4491 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4494 struct nfs4_exception exception
= { };
4497 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4501 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4502 trace_nfs4_get_security_label(inode
, err
);
4503 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4505 } while (exception
.retry
);
4509 static int _nfs4_do_set_security_label(struct inode
*inode
,
4510 struct nfs4_label
*ilabel
,
4511 struct nfs_fattr
*fattr
,
4512 struct nfs4_label
*olabel
)
4515 struct iattr sattr
= {0};
4516 struct nfs_server
*server
= NFS_SERVER(inode
);
4517 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4518 struct nfs_setattrargs args
= {
4519 .fh
= NFS_FH(inode
),
4525 struct nfs_setattrres res
= {
4530 struct rpc_message msg
= {
4531 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4537 nfs4_stateid_copy(&args
.stateid
, &zero_stateid
);
4539 status
= rpc_call_sync(server
->client
, &msg
, 0);
4541 dprintk("%s failed: %d\n", __func__
, status
);
4546 static int nfs4_do_set_security_label(struct inode
*inode
,
4547 struct nfs4_label
*ilabel
,
4548 struct nfs_fattr
*fattr
,
4549 struct nfs4_label
*olabel
)
4551 struct nfs4_exception exception
= { };
4555 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4557 trace_nfs4_set_security_label(inode
, err
);
4558 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4560 } while (exception
.retry
);
4565 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4567 struct nfs4_label ilabel
, *olabel
= NULL
;
4568 struct nfs_fattr fattr
;
4569 struct rpc_cred
*cred
;
4570 struct inode
*inode
= dentry
->d_inode
;
4573 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4576 nfs_fattr_init(&fattr
);
4580 ilabel
.label
= (char *)buf
;
4581 ilabel
.len
= buflen
;
4583 cred
= rpc_lookup_cred();
4585 return PTR_ERR(cred
);
4587 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4588 if (IS_ERR(olabel
)) {
4589 status
= -PTR_ERR(olabel
);
4593 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4595 nfs_setsecurity(inode
, &fattr
, olabel
);
4597 nfs4_label_free(olabel
);
4602 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4606 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
4608 struct nfs_client
*clp
= server
->nfs_client
;
4610 if (task
->tk_status
>= 0)
4612 switch(task
->tk_status
) {
4613 case -NFS4ERR_DELEG_REVOKED
:
4614 case -NFS4ERR_ADMIN_REVOKED
:
4615 case -NFS4ERR_BAD_STATEID
:
4618 nfs_remove_bad_delegation(state
->inode
);
4619 case -NFS4ERR_OPENMODE
:
4622 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4623 goto stateid_invalid
;
4624 goto wait_on_recovery
;
4625 case -NFS4ERR_EXPIRED
:
4626 if (state
!= NULL
) {
4627 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4628 goto stateid_invalid
;
4630 case -NFS4ERR_STALE_STATEID
:
4631 case -NFS4ERR_STALE_CLIENTID
:
4632 nfs4_schedule_lease_recovery(clp
);
4633 goto wait_on_recovery
;
4634 #if defined(CONFIG_NFS_V4_1)
4635 case -NFS4ERR_BADSESSION
:
4636 case -NFS4ERR_BADSLOT
:
4637 case -NFS4ERR_BAD_HIGH_SLOT
:
4638 case -NFS4ERR_DEADSESSION
:
4639 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4640 case -NFS4ERR_SEQ_FALSE_RETRY
:
4641 case -NFS4ERR_SEQ_MISORDERED
:
4642 dprintk("%s ERROR %d, Reset session\n", __func__
,
4644 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4645 task
->tk_status
= 0;
4647 #endif /* CONFIG_NFS_V4_1 */
4648 case -NFS4ERR_DELAY
:
4649 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4650 case -NFS4ERR_GRACE
:
4651 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4652 task
->tk_status
= 0;
4654 case -NFS4ERR_RETRY_UNCACHED_REP
:
4655 case -NFS4ERR_OLD_STATEID
:
4656 task
->tk_status
= 0;
4659 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4662 task
->tk_status
= -EIO
;
4665 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4666 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4667 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4668 task
->tk_status
= 0;
4672 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4673 nfs4_verifier
*bootverf
)
4677 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4678 /* An impossible timestamp guarantees this value
4679 * will never match a generated boot time. */
4681 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4683 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4684 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4685 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4687 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4691 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4692 char *buf
, size_t len
)
4694 unsigned int result
;
4697 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4699 rpc_peeraddr2str(clp
->cl_rpcclient
,
4701 rpc_peeraddr2str(clp
->cl_rpcclient
,
4702 RPC_DISPLAY_PROTO
));
4708 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4709 char *buf
, size_t len
)
4711 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4713 if (nfs4_client_id_uniquifier
[0] != '\0')
4714 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4715 clp
->rpc_ops
->version
,
4716 clp
->cl_minorversion
,
4717 nfs4_client_id_uniquifier
,
4719 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4720 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4725 * nfs4_proc_setclientid - Negotiate client ID
4726 * @clp: state data structure
4727 * @program: RPC program for NFSv4 callback service
4728 * @port: IP port number for NFS4 callback service
4729 * @cred: RPC credential to use for this call
4730 * @res: where to place the result
4732 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4734 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4735 unsigned short port
, struct rpc_cred
*cred
,
4736 struct nfs4_setclientid_res
*res
)
4738 nfs4_verifier sc_verifier
;
4739 struct nfs4_setclientid setclientid
= {
4740 .sc_verifier
= &sc_verifier
,
4742 .sc_cb_ident
= clp
->cl_cb_ident
,
4744 struct rpc_message msg
= {
4745 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
4746 .rpc_argp
= &setclientid
,
4752 /* nfs_client_id4 */
4753 nfs4_init_boot_verifier(clp
, &sc_verifier
);
4754 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
4755 setclientid
.sc_name_len
=
4756 nfs4_init_uniform_client_string(clp
,
4757 setclientid
.sc_name
,
4758 sizeof(setclientid
.sc_name
));
4760 setclientid
.sc_name_len
=
4761 nfs4_init_nonuniform_client_string(clp
,
4762 setclientid
.sc_name
,
4763 sizeof(setclientid
.sc_name
));
4766 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
4767 sizeof(setclientid
.sc_netid
), "%s",
4768 rpc_peeraddr2str(clp
->cl_rpcclient
,
4769 RPC_DISPLAY_NETID
));
4771 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
4772 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
4773 clp
->cl_ipaddr
, port
>> 8, port
& 255);
4775 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4776 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4777 setclientid
.sc_name_len
, setclientid
.sc_name
);
4778 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4779 trace_nfs4_setclientid(clp
, status
);
4780 dprintk("NFS reply setclientid: %d\n", status
);
4785 * nfs4_proc_setclientid_confirm - Confirm client ID
4786 * @clp: state data structure
4787 * @res: result of a previous SETCLIENTID
4788 * @cred: RPC credential to use for this call
4790 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4792 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
4793 struct nfs4_setclientid_res
*arg
,
4794 struct rpc_cred
*cred
)
4796 struct rpc_message msg
= {
4797 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
4803 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4804 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4806 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4807 trace_nfs4_setclientid_confirm(clp
, status
);
4808 dprintk("NFS reply setclientid_confirm: %d\n", status
);
4812 struct nfs4_delegreturndata
{
4813 struct nfs4_delegreturnargs args
;
4814 struct nfs4_delegreturnres res
;
4816 nfs4_stateid stateid
;
4817 unsigned long timestamp
;
4818 struct nfs_fattr fattr
;
4822 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
4824 struct nfs4_delegreturndata
*data
= calldata
;
4826 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4829 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
4830 switch (task
->tk_status
) {
4831 case -NFS4ERR_STALE_STATEID
:
4832 case -NFS4ERR_EXPIRED
:
4834 renew_lease(data
->res
.server
, data
->timestamp
);
4837 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
4839 rpc_restart_call_prepare(task
);
4843 data
->rpc_status
= task
->tk_status
;
4846 static void nfs4_delegreturn_release(void *calldata
)
4851 #if defined(CONFIG_NFS_V4_1)
4852 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
4854 struct nfs4_delegreturndata
*d_data
;
4856 d_data
= (struct nfs4_delegreturndata
*)data
;
4858 nfs4_setup_sequence(d_data
->res
.server
,
4859 &d_data
->args
.seq_args
,
4860 &d_data
->res
.seq_res
,
4863 #endif /* CONFIG_NFS_V4_1 */
4865 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
4866 #if defined(CONFIG_NFS_V4_1)
4867 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
4868 #endif /* CONFIG_NFS_V4_1 */
4869 .rpc_call_done
= nfs4_delegreturn_done
,
4870 .rpc_release
= nfs4_delegreturn_release
,
4873 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4875 struct nfs4_delegreturndata
*data
;
4876 struct nfs_server
*server
= NFS_SERVER(inode
);
4877 struct rpc_task
*task
;
4878 struct rpc_message msg
= {
4879 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
4882 struct rpc_task_setup task_setup_data
= {
4883 .rpc_client
= server
->client
,
4884 .rpc_message
= &msg
,
4885 .callback_ops
= &nfs4_delegreturn_ops
,
4886 .flags
= RPC_TASK_ASYNC
,
4890 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
4893 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4894 data
->args
.fhandle
= &data
->fh
;
4895 data
->args
.stateid
= &data
->stateid
;
4896 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4897 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
4898 nfs4_stateid_copy(&data
->stateid
, stateid
);
4899 data
->res
.fattr
= &data
->fattr
;
4900 data
->res
.server
= server
;
4901 nfs_fattr_init(data
->res
.fattr
);
4902 data
->timestamp
= jiffies
;
4903 data
->rpc_status
= 0;
4905 task_setup_data
.callback_data
= data
;
4906 msg
.rpc_argp
= &data
->args
;
4907 msg
.rpc_resp
= &data
->res
;
4908 task
= rpc_run_task(&task_setup_data
);
4910 return PTR_ERR(task
);
4913 status
= nfs4_wait_for_completion_rpc_task(task
);
4916 status
= data
->rpc_status
;
4918 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
4920 nfs_refresh_inode(inode
, &data
->fattr
);
4926 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4928 struct nfs_server
*server
= NFS_SERVER(inode
);
4929 struct nfs4_exception exception
= { };
4932 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
4933 trace_nfs4_delegreturn(inode
, err
);
4935 case -NFS4ERR_STALE_STATEID
:
4936 case -NFS4ERR_EXPIRED
:
4940 err
= nfs4_handle_exception(server
, err
, &exception
);
4941 } while (exception
.retry
);
4945 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4946 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4949 * sleep, with exponential backoff, and retry the LOCK operation.
4951 static unsigned long
4952 nfs4_set_lock_task_retry(unsigned long timeout
)
4954 freezable_schedule_timeout_killable_unsafe(timeout
);
4956 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
4957 return NFS4_LOCK_MAXTIMEOUT
;
4961 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4963 struct inode
*inode
= state
->inode
;
4964 struct nfs_server
*server
= NFS_SERVER(inode
);
4965 struct nfs_client
*clp
= server
->nfs_client
;
4966 struct nfs_lockt_args arg
= {
4967 .fh
= NFS_FH(inode
),
4970 struct nfs_lockt_res res
= {
4973 struct rpc_message msg
= {
4974 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
4977 .rpc_cred
= state
->owner
->so_cred
,
4979 struct nfs4_lock_state
*lsp
;
4982 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
4983 status
= nfs4_set_lock_state(state
, request
);
4986 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4987 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
4988 arg
.lock_owner
.s_dev
= server
->s_dev
;
4989 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4992 request
->fl_type
= F_UNLCK
;
4994 case -NFS4ERR_DENIED
:
4997 request
->fl_ops
->fl_release_private(request
);
5002 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5004 struct nfs4_exception exception
= { };
5008 err
= _nfs4_proc_getlk(state
, cmd
, request
);
5009 trace_nfs4_get_lock(request
, state
, cmd
, err
);
5010 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
5012 } while (exception
.retry
);
5016 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5019 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5021 res
= posix_lock_file_wait(file
, fl
);
5024 res
= flock_lock_file_wait(file
, fl
);
5032 struct nfs4_unlockdata
{
5033 struct nfs_locku_args arg
;
5034 struct nfs_locku_res res
;
5035 struct nfs4_lock_state
*lsp
;
5036 struct nfs_open_context
*ctx
;
5037 struct file_lock fl
;
5038 const struct nfs_server
*server
;
5039 unsigned long timestamp
;
5042 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5043 struct nfs_open_context
*ctx
,
5044 struct nfs4_lock_state
*lsp
,
5045 struct nfs_seqid
*seqid
)
5047 struct nfs4_unlockdata
*p
;
5048 struct inode
*inode
= lsp
->ls_state
->inode
;
5050 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5053 p
->arg
.fh
= NFS_FH(inode
);
5055 p
->arg
.seqid
= seqid
;
5056 p
->res
.seqid
= seqid
;
5057 p
->arg
.stateid
= &lsp
->ls_stateid
;
5059 atomic_inc(&lsp
->ls_count
);
5060 /* Ensure we don't close file until we're done freeing locks! */
5061 p
->ctx
= get_nfs_open_context(ctx
);
5062 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5063 p
->server
= NFS_SERVER(inode
);
5067 static void nfs4_locku_release_calldata(void *data
)
5069 struct nfs4_unlockdata
*calldata
= data
;
5070 nfs_free_seqid(calldata
->arg
.seqid
);
5071 nfs4_put_lock_state(calldata
->lsp
);
5072 put_nfs_open_context(calldata
->ctx
);
5076 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5078 struct nfs4_unlockdata
*calldata
= data
;
5080 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5082 switch (task
->tk_status
) {
5084 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5085 &calldata
->res
.stateid
);
5086 renew_lease(calldata
->server
, calldata
->timestamp
);
5088 case -NFS4ERR_BAD_STATEID
:
5089 case -NFS4ERR_OLD_STATEID
:
5090 case -NFS4ERR_STALE_STATEID
:
5091 case -NFS4ERR_EXPIRED
:
5094 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
5095 rpc_restart_call_prepare(task
);
5097 nfs_release_seqid(calldata
->arg
.seqid
);
5100 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5102 struct nfs4_unlockdata
*calldata
= data
;
5104 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5106 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5107 /* Note: exit _without_ running nfs4_locku_done */
5110 calldata
->timestamp
= jiffies
;
5111 if (nfs4_setup_sequence(calldata
->server
,
5112 &calldata
->arg
.seq_args
,
5113 &calldata
->res
.seq_res
,
5115 nfs_release_seqid(calldata
->arg
.seqid
);
5118 task
->tk_action
= NULL
;
5120 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5123 static const struct rpc_call_ops nfs4_locku_ops
= {
5124 .rpc_call_prepare
= nfs4_locku_prepare
,
5125 .rpc_call_done
= nfs4_locku_done
,
5126 .rpc_release
= nfs4_locku_release_calldata
,
5129 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5130 struct nfs_open_context
*ctx
,
5131 struct nfs4_lock_state
*lsp
,
5132 struct nfs_seqid
*seqid
)
5134 struct nfs4_unlockdata
*data
;
5135 struct rpc_message msg
= {
5136 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5137 .rpc_cred
= ctx
->cred
,
5139 struct rpc_task_setup task_setup_data
= {
5140 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5141 .rpc_message
= &msg
,
5142 .callback_ops
= &nfs4_locku_ops
,
5143 .workqueue
= nfsiod_workqueue
,
5144 .flags
= RPC_TASK_ASYNC
,
5147 /* Ensure this is an unlock - when canceling a lock, the
5148 * canceled lock is passed in, and it won't be an unlock.
5150 fl
->fl_type
= F_UNLCK
;
5152 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5154 nfs_free_seqid(seqid
);
5155 return ERR_PTR(-ENOMEM
);
5158 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5159 msg
.rpc_argp
= &data
->arg
;
5160 msg
.rpc_resp
= &data
->res
;
5161 task_setup_data
.callback_data
= data
;
5162 return rpc_run_task(&task_setup_data
);
5165 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5167 struct inode
*inode
= state
->inode
;
5168 struct nfs4_state_owner
*sp
= state
->owner
;
5169 struct nfs_inode
*nfsi
= NFS_I(inode
);
5170 struct nfs_seqid
*seqid
;
5171 struct nfs4_lock_state
*lsp
;
5172 struct rpc_task
*task
;
5174 unsigned char fl_flags
= request
->fl_flags
;
5176 status
= nfs4_set_lock_state(state
, request
);
5177 /* Unlock _before_ we do the RPC call */
5178 request
->fl_flags
|= FL_EXISTS
;
5179 /* Exclude nfs_delegation_claim_locks() */
5180 mutex_lock(&sp
->so_delegreturn_mutex
);
5181 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5182 down_read(&nfsi
->rwsem
);
5183 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5184 up_read(&nfsi
->rwsem
);
5185 mutex_unlock(&sp
->so_delegreturn_mutex
);
5188 up_read(&nfsi
->rwsem
);
5189 mutex_unlock(&sp
->so_delegreturn_mutex
);
5192 /* Is this a delegated lock? */
5193 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5194 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5196 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5200 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5201 status
= PTR_ERR(task
);
5204 status
= nfs4_wait_for_completion_rpc_task(task
);
5207 request
->fl_flags
= fl_flags
;
5208 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5212 struct nfs4_lockdata
{
5213 struct nfs_lock_args arg
;
5214 struct nfs_lock_res res
;
5215 struct nfs4_lock_state
*lsp
;
5216 struct nfs_open_context
*ctx
;
5217 struct file_lock fl
;
5218 unsigned long timestamp
;
5221 struct nfs_server
*server
;
5224 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5225 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5228 struct nfs4_lockdata
*p
;
5229 struct inode
*inode
= lsp
->ls_state
->inode
;
5230 struct nfs_server
*server
= NFS_SERVER(inode
);
5232 p
= kzalloc(sizeof(*p
), gfp_mask
);
5236 p
->arg
.fh
= NFS_FH(inode
);
5238 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5239 if (p
->arg
.open_seqid
== NULL
)
5241 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5242 if (p
->arg
.lock_seqid
== NULL
)
5243 goto out_free_seqid
;
5244 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5245 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5246 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5247 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5248 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5251 atomic_inc(&lsp
->ls_count
);
5252 p
->ctx
= get_nfs_open_context(ctx
);
5253 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5256 nfs_free_seqid(p
->arg
.open_seqid
);
5262 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5264 struct nfs4_lockdata
*data
= calldata
;
5265 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5267 dprintk("%s: begin!\n", __func__
);
5268 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5270 /* Do we need to do an open_to_lock_owner? */
5271 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5272 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5273 goto out_release_lock_seqid
;
5275 data
->arg
.open_stateid
= &state
->open_stateid
;
5276 data
->arg
.new_lock_owner
= 1;
5277 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5279 data
->arg
.new_lock_owner
= 0;
5280 if (!nfs4_valid_open_stateid(state
)) {
5281 data
->rpc_status
= -EBADF
;
5282 task
->tk_action
= NULL
;
5283 goto out_release_open_seqid
;
5285 data
->timestamp
= jiffies
;
5286 if (nfs4_setup_sequence(data
->server
,
5287 &data
->arg
.seq_args
,
5291 out_release_open_seqid
:
5292 nfs_release_seqid(data
->arg
.open_seqid
);
5293 out_release_lock_seqid
:
5294 nfs_release_seqid(data
->arg
.lock_seqid
);
5296 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5297 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5300 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5302 struct nfs4_lockdata
*data
= calldata
;
5304 dprintk("%s: begin!\n", __func__
);
5306 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5309 data
->rpc_status
= task
->tk_status
;
5310 if (data
->arg
.new_lock_owner
!= 0) {
5311 if (data
->rpc_status
== 0)
5312 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5316 if (data
->rpc_status
== 0) {
5317 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5318 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5319 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5322 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5325 static void nfs4_lock_release(void *calldata
)
5327 struct nfs4_lockdata
*data
= calldata
;
5329 dprintk("%s: begin!\n", __func__
);
5330 nfs_free_seqid(data
->arg
.open_seqid
);
5331 if (data
->cancelled
!= 0) {
5332 struct rpc_task
*task
;
5333 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5334 data
->arg
.lock_seqid
);
5336 rpc_put_task_async(task
);
5337 dprintk("%s: cancelling lock!\n", __func__
);
5339 nfs_free_seqid(data
->arg
.lock_seqid
);
5340 nfs4_put_lock_state(data
->lsp
);
5341 put_nfs_open_context(data
->ctx
);
5343 dprintk("%s: done!\n", __func__
);
5346 static const struct rpc_call_ops nfs4_lock_ops
= {
5347 .rpc_call_prepare
= nfs4_lock_prepare
,
5348 .rpc_call_done
= nfs4_lock_done
,
5349 .rpc_release
= nfs4_lock_release
,
5352 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5355 case -NFS4ERR_ADMIN_REVOKED
:
5356 case -NFS4ERR_BAD_STATEID
:
5357 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5358 if (new_lock_owner
!= 0 ||
5359 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5360 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5362 case -NFS4ERR_STALE_STATEID
:
5363 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5364 case -NFS4ERR_EXPIRED
:
5365 nfs4_schedule_lease_recovery(server
->nfs_client
);
5369 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5371 struct nfs4_lockdata
*data
;
5372 struct rpc_task
*task
;
5373 struct rpc_message msg
= {
5374 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5375 .rpc_cred
= state
->owner
->so_cred
,
5377 struct rpc_task_setup task_setup_data
= {
5378 .rpc_client
= NFS_CLIENT(state
->inode
),
5379 .rpc_message
= &msg
,
5380 .callback_ops
= &nfs4_lock_ops
,
5381 .workqueue
= nfsiod_workqueue
,
5382 .flags
= RPC_TASK_ASYNC
,
5386 dprintk("%s: begin!\n", __func__
);
5387 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5388 fl
->fl_u
.nfs4_fl
.owner
,
5389 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5393 data
->arg
.block
= 1;
5394 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5395 msg
.rpc_argp
= &data
->arg
;
5396 msg
.rpc_resp
= &data
->res
;
5397 task_setup_data
.callback_data
= data
;
5398 if (recovery_type
> NFS_LOCK_NEW
) {
5399 if (recovery_type
== NFS_LOCK_RECLAIM
)
5400 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5401 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5403 task
= rpc_run_task(&task_setup_data
);
5405 return PTR_ERR(task
);
5406 ret
= nfs4_wait_for_completion_rpc_task(task
);
5408 ret
= data
->rpc_status
;
5410 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5411 data
->arg
.new_lock_owner
, ret
);
5413 data
->cancelled
= 1;
5415 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5419 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5421 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5422 struct nfs4_exception exception
= {
5423 .inode
= state
->inode
,
5428 /* Cache the lock if possible... */
5429 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5431 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5432 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5433 if (err
!= -NFS4ERR_DELAY
)
5435 nfs4_handle_exception(server
, err
, &exception
);
5436 } while (exception
.retry
);
5440 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5442 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5443 struct nfs4_exception exception
= {
5444 .inode
= state
->inode
,
5448 err
= nfs4_set_lock_state(state
, request
);
5452 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5454 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5455 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5459 case -NFS4ERR_GRACE
:
5460 case -NFS4ERR_DELAY
:
5461 nfs4_handle_exception(server
, err
, &exception
);
5464 } while (exception
.retry
);
5469 #if defined(CONFIG_NFS_V4_1)
5471 * nfs41_check_expired_locks - possibly free a lock stateid
5473 * @state: NFSv4 state for an inode
5475 * Returns NFS_OK if recovery for this stateid is now finished.
5476 * Otherwise a negative NFS4ERR value is returned.
5478 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5480 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5481 struct nfs4_lock_state
*lsp
;
5482 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5484 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5485 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5486 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5488 status
= nfs41_test_stateid(server
,
5491 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
5492 if (status
!= NFS_OK
) {
5493 /* Free the stateid unless the server
5494 * informs us the stateid is unrecognized. */
5495 if (status
!= -NFS4ERR_BAD_STATEID
)
5496 nfs41_free_stateid(server
,
5499 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5508 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5510 int status
= NFS_OK
;
5512 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5513 status
= nfs41_check_expired_locks(state
);
5514 if (status
!= NFS_OK
)
5515 status
= nfs4_lock_expired(state
, request
);
5520 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5522 struct nfs4_state_owner
*sp
= state
->owner
;
5523 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5524 unsigned char fl_flags
= request
->fl_flags
;
5526 int status
= -ENOLCK
;
5528 if ((fl_flags
& FL_POSIX
) &&
5529 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5531 /* Is this a delegated open? */
5532 status
= nfs4_set_lock_state(state
, request
);
5535 request
->fl_flags
|= FL_ACCESS
;
5536 status
= do_vfs_lock(request
->fl_file
, request
);
5539 down_read(&nfsi
->rwsem
);
5540 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5541 /* Yes: cache locks! */
5542 /* ...but avoid races with delegation recall... */
5543 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5544 status
= do_vfs_lock(request
->fl_file
, request
);
5547 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5548 up_read(&nfsi
->rwsem
);
5549 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5552 down_read(&nfsi
->rwsem
);
5553 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5554 status
= -NFS4ERR_DELAY
;
5557 /* Note: we always want to sleep here! */
5558 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5559 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5560 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5561 "manager!\n", __func__
);
5563 up_read(&nfsi
->rwsem
);
5565 request
->fl_flags
= fl_flags
;
5569 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5571 struct nfs4_exception exception
= {
5573 .inode
= state
->inode
,
5578 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5579 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5580 if (err
== -NFS4ERR_DENIED
)
5582 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5584 } while (exception
.retry
);
5589 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5591 struct nfs_open_context
*ctx
;
5592 struct nfs4_state
*state
;
5593 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5596 /* verify open state */
5597 ctx
= nfs_file_open_context(filp
);
5600 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5603 if (IS_GETLK(cmd
)) {
5605 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5609 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5612 if (request
->fl_type
== F_UNLCK
) {
5614 return nfs4_proc_unlck(state
, cmd
, request
);
5621 * Don't rely on the VFS having checked the file open mode,
5622 * since it won't do this for flock() locks.
5624 switch (request
->fl_type
) {
5626 if (!(filp
->f_mode
& FMODE_READ
))
5630 if (!(filp
->f_mode
& FMODE_WRITE
))
5635 status
= nfs4_proc_setlk(state
, cmd
, request
);
5636 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5638 timeout
= nfs4_set_lock_task_retry(timeout
);
5639 status
= -ERESTARTSYS
;
5642 } while(status
< 0);
5646 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5648 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5651 err
= nfs4_set_lock_state(state
, fl
);
5654 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5655 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5658 struct nfs_release_lockowner_data
{
5659 struct nfs4_lock_state
*lsp
;
5660 struct nfs_server
*server
;
5661 struct nfs_release_lockowner_args args
;
5664 static void nfs4_release_lockowner_release(void *calldata
)
5666 struct nfs_release_lockowner_data
*data
= calldata
;
5667 nfs4_free_lock_state(data
->server
, data
->lsp
);
5671 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
5672 .rpc_release
= nfs4_release_lockowner_release
,
5675 static int nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
5677 struct nfs_release_lockowner_data
*data
;
5678 struct rpc_message msg
= {
5679 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
5682 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
5684 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5688 data
->server
= server
;
5689 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5690 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5691 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
5692 msg
.rpc_argp
= &data
->args
;
5693 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
5697 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5699 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
5700 const void *buf
, size_t buflen
,
5701 int flags
, int type
)
5703 if (strcmp(key
, "") != 0)
5706 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
5709 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
5710 void *buf
, size_t buflen
, int type
)
5712 if (strcmp(key
, "") != 0)
5715 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
5718 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
5719 size_t list_len
, const char *name
,
5720 size_t name_len
, int type
)
5722 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
5724 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
5727 if (list
&& len
<= list_len
)
5728 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
5732 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5733 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
5735 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
5738 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
5739 const void *buf
, size_t buflen
,
5740 int flags
, int type
)
5742 if (security_ismaclabel(key
))
5743 return nfs4_set_security_label(dentry
, buf
, buflen
);
5748 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
5749 void *buf
, size_t buflen
, int type
)
5751 if (security_ismaclabel(key
))
5752 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
5756 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
5757 size_t list_len
, const char *name
,
5758 size_t name_len
, int type
)
5762 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
5763 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
5764 if (list
&& len
<= list_len
)
5765 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
5770 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
5771 .prefix
= XATTR_SECURITY_PREFIX
,
5772 .list
= nfs4_xattr_list_nfs4_label
,
5773 .get
= nfs4_xattr_get_nfs4_label
,
5774 .set
= nfs4_xattr_set_nfs4_label
,
5780 * nfs_fhget will use either the mounted_on_fileid or the fileid
5782 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
5784 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
5785 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
5786 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
5787 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
5790 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
5791 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
5792 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
5796 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5797 const struct qstr
*name
,
5798 struct nfs4_fs_locations
*fs_locations
,
5801 struct nfs_server
*server
= NFS_SERVER(dir
);
5803 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
5805 struct nfs4_fs_locations_arg args
= {
5806 .dir_fh
= NFS_FH(dir
),
5811 struct nfs4_fs_locations_res res
= {
5812 .fs_locations
= fs_locations
,
5814 struct rpc_message msg
= {
5815 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
5821 dprintk("%s: start\n", __func__
);
5823 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5824 * is not supported */
5825 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
5826 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
5828 bitmask
[0] |= FATTR4_WORD0_FILEID
;
5830 nfs_fattr_init(&fs_locations
->fattr
);
5831 fs_locations
->server
= server
;
5832 fs_locations
->nlocations
= 0;
5833 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5834 dprintk("%s: returned status = %d\n", __func__
, status
);
5838 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5839 const struct qstr
*name
,
5840 struct nfs4_fs_locations
*fs_locations
,
5843 struct nfs4_exception exception
= { };
5846 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
5847 fs_locations
, page
);
5848 trace_nfs4_get_fs_locations(dir
, name
, err
);
5849 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5851 } while (exception
.retry
);
5856 * If 'use_integrity' is true and the state managment nfs_client
5857 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
5858 * and the machine credential as per RFC3530bis and RFC5661 Security
5859 * Considerations sections. Otherwise, just use the user cred with the
5860 * filesystem's rpc_client.
5862 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
5865 struct nfs4_secinfo_arg args
= {
5866 .dir_fh
= NFS_FH(dir
),
5869 struct nfs4_secinfo_res res
= {
5872 struct rpc_message msg
= {
5873 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
5877 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
5879 if (use_integrity
) {
5880 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
5881 msg
.rpc_cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
5884 dprintk("NFS call secinfo %s\n", name
->name
);
5885 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
5887 dprintk("NFS reply secinfo: %d\n", status
);
5890 put_rpccred(msg
.rpc_cred
);
5895 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
5896 struct nfs4_secinfo_flavors
*flavors
)
5898 struct nfs4_exception exception
= { };
5901 err
= -NFS4ERR_WRONGSEC
;
5903 /* try to use integrity protection with machine cred */
5904 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
5905 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
5908 * if unable to use integrity protection, or SECINFO with
5909 * integrity protection returns NFS4ERR_WRONGSEC (which is
5910 * disallowed by spec, but exists in deployed servers) use
5911 * the current filesystem's rpc_client and the user cred.
5913 if (err
== -NFS4ERR_WRONGSEC
)
5914 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
5916 trace_nfs4_secinfo(dir
, name
, err
);
5917 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5919 } while (exception
.retry
);
5923 #ifdef CONFIG_NFS_V4_1
5925 * Check the exchange flags returned by the server for invalid flags, having
5926 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5929 static int nfs4_check_cl_exchange_flags(u32 flags
)
5931 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
5933 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
5934 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
5936 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
5940 return -NFS4ERR_INVAL
;
5944 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
5945 struct nfs41_server_scope
*b
)
5947 if (a
->server_scope_sz
== b
->server_scope_sz
&&
5948 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
5955 * nfs4_proc_bind_conn_to_session()
5957 * The 4.1 client currently uses the same TCP connection for the
5958 * fore and backchannel.
5960 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5963 struct nfs41_bind_conn_to_session_res res
;
5964 struct rpc_message msg
= {
5966 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
5972 dprintk("--> %s\n", __func__
);
5974 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5975 if (unlikely(res
.session
== NULL
)) {
5980 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5981 trace_nfs4_bind_conn_to_session(clp
, status
);
5983 if (memcmp(res
.session
->sess_id
.data
,
5984 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
5985 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
5989 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
5990 dprintk("NFS: %s: Unexpected direction from server\n",
5995 if (res
.use_conn_in_rdma_mode
) {
5996 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6005 dprintk("<-- %s status= %d\n", __func__
, status
);
6010 * nfs4_proc_exchange_id()
6012 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6014 * Since the clientid has expired, all compounds using sessions
6015 * associated with the stale clientid will be returning
6016 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6017 * be in some phase of session reset.
6019 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6021 nfs4_verifier verifier
;
6022 struct nfs41_exchange_id_args args
= {
6023 .verifier
= &verifier
,
6025 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6026 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
6028 struct nfs41_exchange_id_res res
= {
6032 struct rpc_message msg
= {
6033 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
6039 nfs4_init_boot_verifier(clp
, &verifier
);
6040 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
6042 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6043 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
6044 args
.id_len
, args
.id
);
6046 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6048 if (unlikely(res
.server_owner
== NULL
)) {
6053 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6055 if (unlikely(res
.server_scope
== NULL
)) {
6057 goto out_server_owner
;
6060 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6061 if (unlikely(res
.impl_id
== NULL
)) {
6063 goto out_server_scope
;
6066 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6067 trace_nfs4_exchange_id(clp
, status
);
6069 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6072 clp
->cl_clientid
= res
.clientid
;
6073 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6074 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6075 clp
->cl_seqid
= res
.seqid
;
6077 kfree(clp
->cl_serverowner
);
6078 clp
->cl_serverowner
= res
.server_owner
;
6079 res
.server_owner
= NULL
;
6081 /* use the most recent implementation id */
6082 kfree(clp
->cl_implid
);
6083 clp
->cl_implid
= res
.impl_id
;
6085 if (clp
->cl_serverscope
!= NULL
&&
6086 !nfs41_same_server_scope(clp
->cl_serverscope
,
6087 res
.server_scope
)) {
6088 dprintk("%s: server_scope mismatch detected\n",
6090 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6091 kfree(clp
->cl_serverscope
);
6092 clp
->cl_serverscope
= NULL
;
6095 if (clp
->cl_serverscope
== NULL
) {
6096 clp
->cl_serverscope
= res
.server_scope
;
6103 kfree(res
.server_owner
);
6105 kfree(res
.server_scope
);
6107 if (clp
->cl_implid
!= NULL
)
6108 dprintk("NFS reply exchange_id: Server Implementation ID: "
6109 "domain: %s, name: %s, date: %llu,%u\n",
6110 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6111 clp
->cl_implid
->date
.seconds
,
6112 clp
->cl_implid
->date
.nseconds
);
6113 dprintk("NFS reply exchange_id: %d\n", status
);
6117 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6118 struct rpc_cred
*cred
)
6120 struct rpc_message msg
= {
6121 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6127 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6128 trace_nfs4_destroy_clientid(clp
, status
);
6130 dprintk("NFS: Got error %d from the server %s on "
6131 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6135 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6136 struct rpc_cred
*cred
)
6141 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6142 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6144 case -NFS4ERR_DELAY
:
6145 case -NFS4ERR_CLIENTID_BUSY
:
6155 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6157 struct rpc_cred
*cred
;
6160 if (clp
->cl_mvops
->minor_version
< 1)
6162 if (clp
->cl_exchange_flags
== 0)
6164 if (clp
->cl_preserve_clid
)
6166 cred
= nfs4_get_clid_cred(clp
);
6167 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6172 case -NFS4ERR_STALE_CLIENTID
:
6173 clp
->cl_exchange_flags
= 0;
6179 struct nfs4_get_lease_time_data
{
6180 struct nfs4_get_lease_time_args
*args
;
6181 struct nfs4_get_lease_time_res
*res
;
6182 struct nfs_client
*clp
;
6185 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6188 struct nfs4_get_lease_time_data
*data
=
6189 (struct nfs4_get_lease_time_data
*)calldata
;
6191 dprintk("--> %s\n", __func__
);
6192 /* just setup sequence, do not trigger session recovery
6193 since we're invoked within one */
6194 nfs41_setup_sequence(data
->clp
->cl_session
,
6195 &data
->args
->la_seq_args
,
6196 &data
->res
->lr_seq_res
,
6198 dprintk("<-- %s\n", __func__
);
6202 * Called from nfs4_state_manager thread for session setup, so don't recover
6203 * from sequence operation or clientid errors.
6205 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
6207 struct nfs4_get_lease_time_data
*data
=
6208 (struct nfs4_get_lease_time_data
*)calldata
;
6210 dprintk("--> %s\n", __func__
);
6211 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
6213 switch (task
->tk_status
) {
6214 case -NFS4ERR_DELAY
:
6215 case -NFS4ERR_GRACE
:
6216 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
6217 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
6218 task
->tk_status
= 0;
6220 case -NFS4ERR_RETRY_UNCACHED_REP
:
6221 rpc_restart_call_prepare(task
);
6224 dprintk("<-- %s\n", __func__
);
6227 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
6228 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
6229 .rpc_call_done
= nfs4_get_lease_time_done
,
6232 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
6234 struct rpc_task
*task
;
6235 struct nfs4_get_lease_time_args args
;
6236 struct nfs4_get_lease_time_res res
= {
6237 .lr_fsinfo
= fsinfo
,
6239 struct nfs4_get_lease_time_data data
= {
6244 struct rpc_message msg
= {
6245 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
6249 struct rpc_task_setup task_setup
= {
6250 .rpc_client
= clp
->cl_rpcclient
,
6251 .rpc_message
= &msg
,
6252 .callback_ops
= &nfs4_get_lease_time_ops
,
6253 .callback_data
= &data
,
6254 .flags
= RPC_TASK_TIMEOUT
,
6258 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
6259 nfs4_set_sequence_privileged(&args
.la_seq_args
);
6260 dprintk("--> %s\n", __func__
);
6261 task
= rpc_run_task(&task_setup
);
6264 status
= PTR_ERR(task
);
6266 status
= task
->tk_status
;
6269 dprintk("<-- %s return %d\n", __func__
, status
);
6275 * Initialize the values to be used by the client in CREATE_SESSION
6276 * If nfs4_init_session set the fore channel request and response sizes,
6279 * Set the back channel max_resp_sz_cached to zero to force the client to
6280 * always set csa_cachethis to FALSE because the current implementation
6281 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6283 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
6285 unsigned int max_rqst_sz
, max_resp_sz
;
6287 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
6288 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
6290 /* Fore channel attributes */
6291 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
6292 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
6293 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
6294 args
->fc_attrs
.max_reqs
= max_session_slots
;
6296 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6297 "max_ops=%u max_reqs=%u\n",
6299 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
6300 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
6302 /* Back channel attributes */
6303 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
6304 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
6305 args
->bc_attrs
.max_resp_sz_cached
= 0;
6306 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
6307 args
->bc_attrs
.max_reqs
= 1;
6309 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6310 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6312 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
6313 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
6314 args
->bc_attrs
.max_reqs
);
6317 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6319 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
6320 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
6322 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
6325 * Our requested max_ops is the minimum we need; we're not
6326 * prepared to break up compounds into smaller pieces than that.
6327 * So, no point even trying to continue if the server won't
6330 if (rcvd
->max_ops
< sent
->max_ops
)
6332 if (rcvd
->max_reqs
== 0)
6334 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
6335 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
6339 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6341 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
6342 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
6344 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
6346 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
6348 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
6350 /* These would render the backchannel useless: */
6351 if (rcvd
->max_ops
!= sent
->max_ops
)
6353 if (rcvd
->max_reqs
!= sent
->max_reqs
)
6358 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
6359 struct nfs4_session
*session
)
6363 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
6366 return nfs4_verify_back_channel_attrs(args
, session
);
6369 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
6370 struct rpc_cred
*cred
)
6372 struct nfs4_session
*session
= clp
->cl_session
;
6373 struct nfs41_create_session_args args
= {
6375 .cb_program
= NFS4_CALLBACK
,
6377 struct nfs41_create_session_res res
= {
6380 struct rpc_message msg
= {
6381 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
6388 nfs4_init_channel_attrs(&args
);
6389 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
6391 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6392 trace_nfs4_create_session(clp
, status
);
6395 /* Verify the session's negotiated channel_attrs values */
6396 status
= nfs4_verify_channel_attrs(&args
, session
);
6397 /* Increment the clientid slot sequence id */
6405 * Issues a CREATE_SESSION operation to the server.
6406 * It is the responsibility of the caller to verify the session is
6407 * expired before calling this routine.
6409 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6413 struct nfs4_session
*session
= clp
->cl_session
;
6415 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
6417 status
= _nfs4_proc_create_session(clp
, cred
);
6421 /* Init or reset the session slot tables */
6422 status
= nfs4_setup_session_slot_tables(session
);
6423 dprintk("slot table setup returned %d\n", status
);
6427 ptr
= (unsigned *)&session
->sess_id
.data
[0];
6428 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
6429 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
6431 dprintk("<-- %s\n", __func__
);
6436 * Issue the over-the-wire RPC DESTROY_SESSION.
6437 * The caller must serialize access to this routine.
6439 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
6440 struct rpc_cred
*cred
)
6442 struct rpc_message msg
= {
6443 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
6444 .rpc_argp
= session
,
6449 dprintk("--> nfs4_proc_destroy_session\n");
6451 /* session is still being setup */
6452 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
6455 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6456 trace_nfs4_destroy_session(session
->clp
, status
);
6459 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
6460 "Session has been destroyed regardless...\n", status
);
6462 dprintk("<-- nfs4_proc_destroy_session\n");
6467 * Renew the cl_session lease.
6469 struct nfs4_sequence_data
{
6470 struct nfs_client
*clp
;
6471 struct nfs4_sequence_args args
;
6472 struct nfs4_sequence_res res
;
6475 static void nfs41_sequence_release(void *data
)
6477 struct nfs4_sequence_data
*calldata
= data
;
6478 struct nfs_client
*clp
= calldata
->clp
;
6480 if (atomic_read(&clp
->cl_count
) > 1)
6481 nfs4_schedule_state_renewal(clp
);
6482 nfs_put_client(clp
);
6486 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6488 switch(task
->tk_status
) {
6489 case -NFS4ERR_DELAY
:
6490 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6493 nfs4_schedule_lease_recovery(clp
);
6498 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
6500 struct nfs4_sequence_data
*calldata
= data
;
6501 struct nfs_client
*clp
= calldata
->clp
;
6503 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
6506 trace_nfs4_sequence(clp
, task
->tk_status
);
6507 if (task
->tk_status
< 0) {
6508 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
6509 if (atomic_read(&clp
->cl_count
) == 1)
6512 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
6513 rpc_restart_call_prepare(task
);
6517 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
6519 dprintk("<-- %s\n", __func__
);
6522 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
6524 struct nfs4_sequence_data
*calldata
= data
;
6525 struct nfs_client
*clp
= calldata
->clp
;
6526 struct nfs4_sequence_args
*args
;
6527 struct nfs4_sequence_res
*res
;
6529 args
= task
->tk_msg
.rpc_argp
;
6530 res
= task
->tk_msg
.rpc_resp
;
6532 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
6535 static const struct rpc_call_ops nfs41_sequence_ops
= {
6536 .rpc_call_done
= nfs41_sequence_call_done
,
6537 .rpc_call_prepare
= nfs41_sequence_prepare
,
6538 .rpc_release
= nfs41_sequence_release
,
6541 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
6542 struct rpc_cred
*cred
,
6545 struct nfs4_sequence_data
*calldata
;
6546 struct rpc_message msg
= {
6547 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
6550 struct rpc_task_setup task_setup_data
= {
6551 .rpc_client
= clp
->cl_rpcclient
,
6552 .rpc_message
= &msg
,
6553 .callback_ops
= &nfs41_sequence_ops
,
6554 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
6557 if (!atomic_inc_not_zero(&clp
->cl_count
))
6558 return ERR_PTR(-EIO
);
6559 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6560 if (calldata
== NULL
) {
6561 nfs_put_client(clp
);
6562 return ERR_PTR(-ENOMEM
);
6564 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0);
6566 nfs4_set_sequence_privileged(&calldata
->args
);
6567 msg
.rpc_argp
= &calldata
->args
;
6568 msg
.rpc_resp
= &calldata
->res
;
6569 calldata
->clp
= clp
;
6570 task_setup_data
.callback_data
= calldata
;
6572 return rpc_run_task(&task_setup_data
);
6575 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
6577 struct rpc_task
*task
;
6580 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
6582 task
= _nfs41_proc_sequence(clp
, cred
, false);
6584 ret
= PTR_ERR(task
);
6586 rpc_put_task_async(task
);
6587 dprintk("<-- %s status=%d\n", __func__
, ret
);
6591 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6593 struct rpc_task
*task
;
6596 task
= _nfs41_proc_sequence(clp
, cred
, true);
6598 ret
= PTR_ERR(task
);
6601 ret
= rpc_wait_for_completion_task(task
);
6603 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
6605 if (task
->tk_status
== 0)
6606 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
6607 ret
= task
->tk_status
;
6611 dprintk("<-- %s status=%d\n", __func__
, ret
);
6615 struct nfs4_reclaim_complete_data
{
6616 struct nfs_client
*clp
;
6617 struct nfs41_reclaim_complete_args arg
;
6618 struct nfs41_reclaim_complete_res res
;
6621 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
6623 struct nfs4_reclaim_complete_data
*calldata
= data
;
6625 nfs41_setup_sequence(calldata
->clp
->cl_session
,
6626 &calldata
->arg
.seq_args
,
6627 &calldata
->res
.seq_res
,
6631 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6633 switch(task
->tk_status
) {
6635 case -NFS4ERR_COMPLETE_ALREADY
:
6636 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
6638 case -NFS4ERR_DELAY
:
6639 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6641 case -NFS4ERR_RETRY_UNCACHED_REP
:
6644 nfs4_schedule_lease_recovery(clp
);
6649 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
6651 struct nfs4_reclaim_complete_data
*calldata
= data
;
6652 struct nfs_client
*clp
= calldata
->clp
;
6653 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
6655 dprintk("--> %s\n", __func__
);
6656 if (!nfs41_sequence_done(task
, res
))
6659 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
6660 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
6661 rpc_restart_call_prepare(task
);
6664 dprintk("<-- %s\n", __func__
);
6667 static void nfs4_free_reclaim_complete_data(void *data
)
6669 struct nfs4_reclaim_complete_data
*calldata
= data
;
6674 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
6675 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
6676 .rpc_call_done
= nfs4_reclaim_complete_done
,
6677 .rpc_release
= nfs4_free_reclaim_complete_data
,
6681 * Issue a global reclaim complete.
6683 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
6684 struct rpc_cred
*cred
)
6686 struct nfs4_reclaim_complete_data
*calldata
;
6687 struct rpc_task
*task
;
6688 struct rpc_message msg
= {
6689 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
6692 struct rpc_task_setup task_setup_data
= {
6693 .rpc_client
= clp
->cl_rpcclient
,
6694 .rpc_message
= &msg
,
6695 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
6696 .flags
= RPC_TASK_ASYNC
,
6698 int status
= -ENOMEM
;
6700 dprintk("--> %s\n", __func__
);
6701 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6702 if (calldata
== NULL
)
6704 calldata
->clp
= clp
;
6705 calldata
->arg
.one_fs
= 0;
6707 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
6708 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
6709 msg
.rpc_argp
= &calldata
->arg
;
6710 msg
.rpc_resp
= &calldata
->res
;
6711 task_setup_data
.callback_data
= calldata
;
6712 task
= rpc_run_task(&task_setup_data
);
6714 status
= PTR_ERR(task
);
6717 status
= nfs4_wait_for_completion_rpc_task(task
);
6719 status
= task
->tk_status
;
6723 dprintk("<-- %s status=%d\n", __func__
, status
);
6728 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
6730 struct nfs4_layoutget
*lgp
= calldata
;
6731 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
6732 struct nfs4_session
*session
= nfs4_get_session(server
);
6734 dprintk("--> %s\n", __func__
);
6735 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6736 * right now covering the LAYOUTGET we are about to send.
6737 * However, that is not so catastrophic, and there seems
6738 * to be no way to prevent it completely.
6740 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
6741 &lgp
->res
.seq_res
, task
))
6743 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
6744 NFS_I(lgp
->args
.inode
)->layout
,
6745 lgp
->args
.ctx
->state
)) {
6746 rpc_exit(task
, NFS4_OK
);
6750 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
6752 struct nfs4_layoutget
*lgp
= calldata
;
6753 struct inode
*inode
= lgp
->args
.inode
;
6754 struct nfs_server
*server
= NFS_SERVER(inode
);
6755 struct pnfs_layout_hdr
*lo
;
6756 struct nfs4_state
*state
= NULL
;
6757 unsigned long timeo
, giveup
;
6759 dprintk("--> %s\n", __func__
);
6761 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
6764 switch (task
->tk_status
) {
6767 case -NFS4ERR_LAYOUTTRYLATER
:
6768 case -NFS4ERR_RECALLCONFLICT
:
6769 timeo
= rpc_get_timeout(task
->tk_client
);
6770 giveup
= lgp
->args
.timestamp
+ timeo
;
6771 if (time_after(giveup
, jiffies
))
6772 task
->tk_status
= -NFS4ERR_DELAY
;
6774 case -NFS4ERR_EXPIRED
:
6775 case -NFS4ERR_BAD_STATEID
:
6776 spin_lock(&inode
->i_lock
);
6777 lo
= NFS_I(inode
)->layout
;
6778 if (!lo
|| list_empty(&lo
->plh_segs
)) {
6779 spin_unlock(&inode
->i_lock
);
6780 /* If the open stateid was bad, then recover it. */
6781 state
= lgp
->args
.ctx
->state
;
6785 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
6786 spin_unlock(&inode
->i_lock
);
6787 /* Mark the bad layout state as invalid, then
6788 * retry using the open stateid. */
6789 pnfs_free_lseg_list(&head
);
6792 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
6793 rpc_restart_call_prepare(task
);
6795 dprintk("<-- %s\n", __func__
);
6798 static size_t max_response_pages(struct nfs_server
*server
)
6800 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
6801 return nfs_page_array_len(0, max_resp_sz
);
6804 static void nfs4_free_pages(struct page
**pages
, size_t size
)
6811 for (i
= 0; i
< size
; i
++) {
6814 __free_page(pages
[i
]);
6819 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
6821 struct page
**pages
;
6824 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
6826 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
6830 for (i
= 0; i
< size
; i
++) {
6831 pages
[i
] = alloc_page(gfp_flags
);
6833 dprintk("%s: failed to allocate page\n", __func__
);
6834 nfs4_free_pages(pages
, size
);
6842 static void nfs4_layoutget_release(void *calldata
)
6844 struct nfs4_layoutget
*lgp
= calldata
;
6845 struct inode
*inode
= lgp
->args
.inode
;
6846 struct nfs_server
*server
= NFS_SERVER(inode
);
6847 size_t max_pages
= max_response_pages(server
);
6849 dprintk("--> %s\n", __func__
);
6850 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
6851 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
6852 put_nfs_open_context(lgp
->args
.ctx
);
6854 dprintk("<-- %s\n", __func__
);
6857 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
6858 .rpc_call_prepare
= nfs4_layoutget_prepare
,
6859 .rpc_call_done
= nfs4_layoutget_done
,
6860 .rpc_release
= nfs4_layoutget_release
,
6863 struct pnfs_layout_segment
*
6864 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
6866 struct inode
*inode
= lgp
->args
.inode
;
6867 struct nfs_server
*server
= NFS_SERVER(inode
);
6868 size_t max_pages
= max_response_pages(server
);
6869 struct rpc_task
*task
;
6870 struct rpc_message msg
= {
6871 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
6872 .rpc_argp
= &lgp
->args
,
6873 .rpc_resp
= &lgp
->res
,
6874 .rpc_cred
= lgp
->cred
,
6876 struct rpc_task_setup task_setup_data
= {
6877 .rpc_client
= server
->client
,
6878 .rpc_message
= &msg
,
6879 .callback_ops
= &nfs4_layoutget_call_ops
,
6880 .callback_data
= lgp
,
6881 .flags
= RPC_TASK_ASYNC
,
6883 struct pnfs_layout_segment
*lseg
= NULL
;
6886 dprintk("--> %s\n", __func__
);
6888 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
6889 if (!lgp
->args
.layout
.pages
) {
6890 nfs4_layoutget_release(lgp
);
6891 return ERR_PTR(-ENOMEM
);
6893 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
6894 lgp
->args
.timestamp
= jiffies
;
6896 lgp
->res
.layoutp
= &lgp
->args
.layout
;
6897 lgp
->res
.seq_res
.sr_slot
= NULL
;
6898 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
6900 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6901 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
6903 task
= rpc_run_task(&task_setup_data
);
6905 return ERR_CAST(task
);
6906 status
= nfs4_wait_for_completion_rpc_task(task
);
6908 status
= task
->tk_status
;
6909 trace_nfs4_layoutget(lgp
->args
.ctx
,
6913 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6914 if (status
== 0 && lgp
->res
.layoutp
->len
)
6915 lseg
= pnfs_layout_process(lgp
);
6917 dprintk("<-- %s status=%d\n", __func__
, status
);
6919 return ERR_PTR(status
);
6924 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
6926 struct nfs4_layoutreturn
*lrp
= calldata
;
6928 dprintk("--> %s\n", __func__
);
6929 nfs41_setup_sequence(lrp
->clp
->cl_session
,
6930 &lrp
->args
.seq_args
,
6935 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
6937 struct nfs4_layoutreturn
*lrp
= calldata
;
6938 struct nfs_server
*server
;
6940 dprintk("--> %s\n", __func__
);
6942 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
6945 server
= NFS_SERVER(lrp
->args
.inode
);
6946 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
6947 rpc_restart_call_prepare(task
);
6950 dprintk("<-- %s\n", __func__
);
6953 static void nfs4_layoutreturn_release(void *calldata
)
6955 struct nfs4_layoutreturn
*lrp
= calldata
;
6956 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
6958 dprintk("--> %s\n", __func__
);
6959 spin_lock(&lo
->plh_inode
->i_lock
);
6960 if (lrp
->res
.lrs_present
)
6961 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
6962 lo
->plh_block_lgets
--;
6963 spin_unlock(&lo
->plh_inode
->i_lock
);
6964 pnfs_put_layout_hdr(lrp
->args
.layout
);
6966 dprintk("<-- %s\n", __func__
);
6969 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
6970 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
6971 .rpc_call_done
= nfs4_layoutreturn_done
,
6972 .rpc_release
= nfs4_layoutreturn_release
,
6975 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
6977 struct rpc_task
*task
;
6978 struct rpc_message msg
= {
6979 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
6980 .rpc_argp
= &lrp
->args
,
6981 .rpc_resp
= &lrp
->res
,
6982 .rpc_cred
= lrp
->cred
,
6984 struct rpc_task_setup task_setup_data
= {
6985 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
6986 .rpc_message
= &msg
,
6987 .callback_ops
= &nfs4_layoutreturn_call_ops
,
6988 .callback_data
= lrp
,
6992 dprintk("--> %s\n", __func__
);
6993 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
6994 task
= rpc_run_task(&task_setup_data
);
6996 return PTR_ERR(task
);
6997 status
= task
->tk_status
;
6998 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
6999 dprintk("<-- %s status=%d\n", __func__
, status
);
7005 * Retrieve the list of Data Server devices from the MDS.
7007 static int _nfs4_getdevicelist(struct nfs_server
*server
,
7008 const struct nfs_fh
*fh
,
7009 struct pnfs_devicelist
*devlist
)
7011 struct nfs4_getdevicelist_args args
= {
7013 .layoutclass
= server
->pnfs_curr_ld
->id
,
7015 struct nfs4_getdevicelist_res res
= {
7018 struct rpc_message msg
= {
7019 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
7025 dprintk("--> %s\n", __func__
);
7026 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
7028 dprintk("<-- %s status=%d\n", __func__
, status
);
7032 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
7033 const struct nfs_fh
*fh
,
7034 struct pnfs_devicelist
*devlist
)
7036 struct nfs4_exception exception
= { };
7040 err
= nfs4_handle_exception(server
,
7041 _nfs4_getdevicelist(server
, fh
, devlist
),
7043 } while (exception
.retry
);
7045 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
7046 err
, devlist
->num_devs
);
7050 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
7053 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7054 struct pnfs_device
*pdev
,
7055 struct rpc_cred
*cred
)
7057 struct nfs4_getdeviceinfo_args args
= {
7060 struct nfs4_getdeviceinfo_res res
= {
7063 struct rpc_message msg
= {
7064 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7071 dprintk("--> %s\n", __func__
);
7072 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7073 dprintk("<-- %s status=%d\n", __func__
, status
);
7078 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7079 struct pnfs_device
*pdev
,
7080 struct rpc_cred
*cred
)
7082 struct nfs4_exception exception
= { };
7086 err
= nfs4_handle_exception(server
,
7087 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7089 } while (exception
.retry
);
7092 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7094 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7096 struct nfs4_layoutcommit_data
*data
= calldata
;
7097 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7098 struct nfs4_session
*session
= nfs4_get_session(server
);
7100 nfs41_setup_sequence(session
,
7101 &data
->args
.seq_args
,
7107 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7109 struct nfs4_layoutcommit_data
*data
= calldata
;
7110 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7112 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7115 switch (task
->tk_status
) { /* Just ignore these failures */
7116 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7117 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7118 case -NFS4ERR_BADLAYOUT
: /* no layout */
7119 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7120 task
->tk_status
= 0;
7123 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7127 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7128 rpc_restart_call_prepare(task
);
7134 static void nfs4_layoutcommit_release(void *calldata
)
7136 struct nfs4_layoutcommit_data
*data
= calldata
;
7138 pnfs_cleanup_layoutcommit(data
);
7139 put_rpccred(data
->cred
);
7143 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7144 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7145 .rpc_call_done
= nfs4_layoutcommit_done
,
7146 .rpc_release
= nfs4_layoutcommit_release
,
7150 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7152 struct rpc_message msg
= {
7153 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7154 .rpc_argp
= &data
->args
,
7155 .rpc_resp
= &data
->res
,
7156 .rpc_cred
= data
->cred
,
7158 struct rpc_task_setup task_setup_data
= {
7159 .task
= &data
->task
,
7160 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7161 .rpc_message
= &msg
,
7162 .callback_ops
= &nfs4_layoutcommit_ops
,
7163 .callback_data
= data
,
7164 .flags
= RPC_TASK_ASYNC
,
7166 struct rpc_task
*task
;
7169 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7170 "lbw: %llu inode %lu\n",
7171 data
->task
.tk_pid
, sync
,
7172 data
->args
.lastbytewritten
,
7173 data
->args
.inode
->i_ino
);
7175 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7176 task
= rpc_run_task(&task_setup_data
);
7178 return PTR_ERR(task
);
7181 status
= nfs4_wait_for_completion_rpc_task(task
);
7184 status
= task
->tk_status
;
7185 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7187 dprintk("%s: status %d\n", __func__
, status
);
7193 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7194 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7197 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7198 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7200 struct nfs41_secinfo_no_name_args args
= {
7201 .style
= SECINFO_STYLE_CURRENT_FH
,
7203 struct nfs4_secinfo_res res
= {
7206 struct rpc_message msg
= {
7207 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
7211 return nfs4_call_sync(server
->nfs_client
->cl_rpcclient
, server
, &msg
,
7212 &args
.seq_args
, &res
.seq_res
, 0);
7216 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7217 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7219 struct nfs4_exception exception
= { };
7222 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7225 case -NFS4ERR_WRONGSEC
:
7226 case -NFS4ERR_NOTSUPP
:
7229 err
= nfs4_handle_exception(server
, err
, &exception
);
7231 } while (exception
.retry
);
7237 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7238 struct nfs_fsinfo
*info
)
7242 rpc_authflavor_t flavor
;
7243 struct nfs4_secinfo_flavors
*flavors
;
7245 page
= alloc_page(GFP_KERNEL
);
7251 flavors
= page_address(page
);
7252 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7255 * Fall back on "guess and check" method if
7256 * the server doesn't support SECINFO_NO_NAME
7258 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
7259 err
= nfs4_find_root_sec(server
, fhandle
, info
);
7265 flavor
= nfs_find_best_sec(flavors
);
7267 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
7277 static int _nfs41_test_stateid(struct nfs_server
*server
,
7278 nfs4_stateid
*stateid
,
7279 struct rpc_cred
*cred
)
7282 struct nfs41_test_stateid_args args
= {
7285 struct nfs41_test_stateid_res res
;
7286 struct rpc_message msg
= {
7287 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
7293 dprintk("NFS call test_stateid %p\n", stateid
);
7294 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
7295 nfs4_set_sequence_privileged(&args
.seq_args
);
7296 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
,
7297 &args
.seq_args
, &res
.seq_res
);
7298 if (status
!= NFS_OK
) {
7299 dprintk("NFS reply test_stateid: failed, %d\n", status
);
7302 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
7307 * nfs41_test_stateid - perform a TEST_STATEID operation
7309 * @server: server / transport on which to perform the operation
7310 * @stateid: state ID to test
7313 * Returns NFS_OK if the server recognizes that "stateid" is valid.
7314 * Otherwise a negative NFS4ERR value is returned if the operation
7315 * failed or the state ID is not currently valid.
7317 static int nfs41_test_stateid(struct nfs_server
*server
,
7318 nfs4_stateid
*stateid
,
7319 struct rpc_cred
*cred
)
7321 struct nfs4_exception exception
= { };
7324 err
= _nfs41_test_stateid(server
, stateid
, cred
);
7325 if (err
!= -NFS4ERR_DELAY
)
7327 nfs4_handle_exception(server
, err
, &exception
);
7328 } while (exception
.retry
);
7332 struct nfs_free_stateid_data
{
7333 struct nfs_server
*server
;
7334 struct nfs41_free_stateid_args args
;
7335 struct nfs41_free_stateid_res res
;
7338 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
7340 struct nfs_free_stateid_data
*data
= calldata
;
7341 nfs41_setup_sequence(nfs4_get_session(data
->server
),
7342 &data
->args
.seq_args
,
7347 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
7349 struct nfs_free_stateid_data
*data
= calldata
;
7351 nfs41_sequence_done(task
, &data
->res
.seq_res
);
7353 switch (task
->tk_status
) {
7354 case -NFS4ERR_DELAY
:
7355 if (nfs4_async_handle_error(task
, data
->server
, NULL
) == -EAGAIN
)
7356 rpc_restart_call_prepare(task
);
7360 static void nfs41_free_stateid_release(void *calldata
)
7365 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
7366 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
7367 .rpc_call_done
= nfs41_free_stateid_done
,
7368 .rpc_release
= nfs41_free_stateid_release
,
7371 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
7372 nfs4_stateid
*stateid
,
7373 struct rpc_cred
*cred
,
7376 struct rpc_message msg
= {
7377 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
7380 struct rpc_task_setup task_setup
= {
7381 .rpc_client
= server
->client
,
7382 .rpc_message
= &msg
,
7383 .callback_ops
= &nfs41_free_stateid_ops
,
7384 .flags
= RPC_TASK_ASYNC
,
7386 struct nfs_free_stateid_data
*data
;
7388 dprintk("NFS call free_stateid %p\n", stateid
);
7389 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
7391 return ERR_PTR(-ENOMEM
);
7392 data
->server
= server
;
7393 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
7395 task_setup
.callback_data
= data
;
7397 msg
.rpc_argp
= &data
->args
;
7398 msg
.rpc_resp
= &data
->res
;
7399 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
7401 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
7403 return rpc_run_task(&task_setup
);
7407 * nfs41_free_stateid - perform a FREE_STATEID operation
7409 * @server: server / transport on which to perform the operation
7410 * @stateid: state ID to release
7413 * Returns NFS_OK if the server freed "stateid". Otherwise a
7414 * negative NFS4ERR value is returned.
7416 static int nfs41_free_stateid(struct nfs_server
*server
,
7417 nfs4_stateid
*stateid
,
7418 struct rpc_cred
*cred
)
7420 struct rpc_task
*task
;
7423 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
7425 return PTR_ERR(task
);
7426 ret
= rpc_wait_for_completion_task(task
);
7428 ret
= task
->tk_status
;
7433 static int nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
7435 struct rpc_task
*task
;
7436 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
7438 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
7439 nfs4_free_lock_state(server
, lsp
);
7441 return PTR_ERR(task
);
7446 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
7447 const nfs4_stateid
*s2
)
7449 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
7452 if (s1
->seqid
== s2
->seqid
)
7454 if (s1
->seqid
== 0 || s2
->seqid
== 0)
7460 #endif /* CONFIG_NFS_V4_1 */
7462 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
7463 const nfs4_stateid
*s2
)
7465 return nfs4_stateid_match(s1
, s2
);
7469 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
7470 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7471 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7472 .recover_open
= nfs4_open_reclaim
,
7473 .recover_lock
= nfs4_lock_reclaim
,
7474 .establish_clid
= nfs4_init_clientid
,
7475 .detect_trunking
= nfs40_discover_server_trunking
,
7478 #if defined(CONFIG_NFS_V4_1)
7479 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
7480 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7481 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7482 .recover_open
= nfs4_open_reclaim
,
7483 .recover_lock
= nfs4_lock_reclaim
,
7484 .establish_clid
= nfs41_init_clientid
,
7485 .reclaim_complete
= nfs41_proc_reclaim_complete
,
7486 .detect_trunking
= nfs41_discover_server_trunking
,
7488 #endif /* CONFIG_NFS_V4_1 */
7490 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
7491 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7492 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7493 .recover_open
= nfs4_open_expired
,
7494 .recover_lock
= nfs4_lock_expired
,
7495 .establish_clid
= nfs4_init_clientid
,
7498 #if defined(CONFIG_NFS_V4_1)
7499 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
7500 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7501 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7502 .recover_open
= nfs41_open_expired
,
7503 .recover_lock
= nfs41_lock_expired
,
7504 .establish_clid
= nfs41_init_clientid
,
7506 #endif /* CONFIG_NFS_V4_1 */
7508 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
7509 .sched_state_renewal
= nfs4_proc_async_renew
,
7510 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
7511 .renew_lease
= nfs4_proc_renew
,
7514 #if defined(CONFIG_NFS_V4_1)
7515 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
7516 .sched_state_renewal
= nfs41_proc_async_sequence
,
7517 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
7518 .renew_lease
= nfs4_proc_sequence
,
7522 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
7524 .init_caps
= NFS_CAP_READDIRPLUS
7525 | NFS_CAP_ATOMIC_OPEN
7526 | NFS_CAP_CHANGE_ATTR
7527 | NFS_CAP_POSIX_LOCK
,
7528 .call_sync
= _nfs4_call_sync
,
7529 .match_stateid
= nfs4_match_stateid
,
7530 .find_root_sec
= nfs4_find_root_sec
,
7531 .free_lock_state
= nfs4_release_lockowner
,
7532 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
7533 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
7534 .state_renewal_ops
= &nfs40_state_renewal_ops
,
7537 #if defined(CONFIG_NFS_V4_1)
7538 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
7540 .init_caps
= NFS_CAP_READDIRPLUS
7541 | NFS_CAP_ATOMIC_OPEN
7542 | NFS_CAP_CHANGE_ATTR
7543 | NFS_CAP_POSIX_LOCK
7544 | NFS_CAP_STATEID_NFSV41
7545 | NFS_CAP_ATOMIC_OPEN_V1
,
7546 .call_sync
= nfs4_call_sync_sequence
,
7547 .match_stateid
= nfs41_match_stateid
,
7548 .find_root_sec
= nfs41_find_root_sec
,
7549 .free_lock_state
= nfs41_free_lock_state
,
7550 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7551 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7552 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7556 #if defined(CONFIG_NFS_V4_2)
7557 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
7559 .init_caps
= NFS_CAP_READDIRPLUS
7560 | NFS_CAP_ATOMIC_OPEN
7561 | NFS_CAP_CHANGE_ATTR
7562 | NFS_CAP_POSIX_LOCK
7563 | NFS_CAP_STATEID_NFSV41
7564 | NFS_CAP_ATOMIC_OPEN_V1
,
7565 .call_sync
= nfs4_call_sync_sequence
,
7566 .match_stateid
= nfs41_match_stateid
,
7567 .find_root_sec
= nfs41_find_root_sec
,
7568 .free_lock_state
= nfs41_free_lock_state
,
7569 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7570 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7571 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7575 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
7576 [0] = &nfs_v4_0_minor_ops
,
7577 #if defined(CONFIG_NFS_V4_1)
7578 [1] = &nfs_v4_1_minor_ops
,
7580 #if defined(CONFIG_NFS_V4_2)
7581 [2] = &nfs_v4_2_minor_ops
,
7585 static const struct inode_operations nfs4_dir_inode_operations
= {
7586 .create
= nfs_create
,
7587 .lookup
= nfs_lookup
,
7588 .atomic_open
= nfs_atomic_open
,
7590 .unlink
= nfs_unlink
,
7591 .symlink
= nfs_symlink
,
7595 .rename
= nfs_rename
,
7596 .permission
= nfs_permission
,
7597 .getattr
= nfs_getattr
,
7598 .setattr
= nfs_setattr
,
7599 .getxattr
= generic_getxattr
,
7600 .setxattr
= generic_setxattr
,
7601 .listxattr
= generic_listxattr
,
7602 .removexattr
= generic_removexattr
,
7605 static const struct inode_operations nfs4_file_inode_operations
= {
7606 .permission
= nfs_permission
,
7607 .getattr
= nfs_getattr
,
7608 .setattr
= nfs_setattr
,
7609 .getxattr
= generic_getxattr
,
7610 .setxattr
= generic_setxattr
,
7611 .listxattr
= generic_listxattr
,
7612 .removexattr
= generic_removexattr
,
7615 const struct nfs_rpc_ops nfs_v4_clientops
= {
7616 .version
= 4, /* protocol version */
7617 .dentry_ops
= &nfs4_dentry_operations
,
7618 .dir_inode_ops
= &nfs4_dir_inode_operations
,
7619 .file_inode_ops
= &nfs4_file_inode_operations
,
7620 .file_ops
= &nfs4_file_operations
,
7621 .getroot
= nfs4_proc_get_root
,
7622 .submount
= nfs4_submount
,
7623 .try_mount
= nfs4_try_mount
,
7624 .getattr
= nfs4_proc_getattr
,
7625 .setattr
= nfs4_proc_setattr
,
7626 .lookup
= nfs4_proc_lookup
,
7627 .access
= nfs4_proc_access
,
7628 .readlink
= nfs4_proc_readlink
,
7629 .create
= nfs4_proc_create
,
7630 .remove
= nfs4_proc_remove
,
7631 .unlink_setup
= nfs4_proc_unlink_setup
,
7632 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
7633 .unlink_done
= nfs4_proc_unlink_done
,
7634 .rename
= nfs4_proc_rename
,
7635 .rename_setup
= nfs4_proc_rename_setup
,
7636 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
7637 .rename_done
= nfs4_proc_rename_done
,
7638 .link
= nfs4_proc_link
,
7639 .symlink
= nfs4_proc_symlink
,
7640 .mkdir
= nfs4_proc_mkdir
,
7641 .rmdir
= nfs4_proc_remove
,
7642 .readdir
= nfs4_proc_readdir
,
7643 .mknod
= nfs4_proc_mknod
,
7644 .statfs
= nfs4_proc_statfs
,
7645 .fsinfo
= nfs4_proc_fsinfo
,
7646 .pathconf
= nfs4_proc_pathconf
,
7647 .set_capabilities
= nfs4_server_capabilities
,
7648 .decode_dirent
= nfs4_decode_dirent
,
7649 .read_setup
= nfs4_proc_read_setup
,
7650 .read_pageio_init
= pnfs_pageio_init_read
,
7651 .read_rpc_prepare
= nfs4_proc_read_rpc_prepare
,
7652 .read_done
= nfs4_read_done
,
7653 .write_setup
= nfs4_proc_write_setup
,
7654 .write_pageio_init
= pnfs_pageio_init_write
,
7655 .write_rpc_prepare
= nfs4_proc_write_rpc_prepare
,
7656 .write_done
= nfs4_write_done
,
7657 .commit_setup
= nfs4_proc_commit_setup
,
7658 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
7659 .commit_done
= nfs4_commit_done
,
7660 .lock
= nfs4_proc_lock
,
7661 .clear_acl_cache
= nfs4_zap_acl_attr
,
7662 .close_context
= nfs4_close_context
,
7663 .open_context
= nfs4_atomic_open
,
7664 .have_delegation
= nfs4_have_delegation
,
7665 .return_delegation
= nfs4_inode_return_delegation
,
7666 .alloc_client
= nfs4_alloc_client
,
7667 .init_client
= nfs4_init_client
,
7668 .free_client
= nfs4_free_client
,
7669 .create_server
= nfs4_create_server
,
7670 .clone_server
= nfs_clone_server
,
7673 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
7674 .prefix
= XATTR_NAME_NFSV4_ACL
,
7675 .list
= nfs4_xattr_list_nfs4_acl
,
7676 .get
= nfs4_xattr_get_nfs4_acl
,
7677 .set
= nfs4_xattr_set_nfs4_acl
,
7680 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
7681 &nfs4_xattr_nfs4_acl_handler
,
7682 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7683 &nfs4_xattr_nfs4_label_handler
,