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 #if defined(CONFIG_NFS_V4_1)
474 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
476 struct nfs4_session
*session
;
477 struct nfs4_slot_table
*tbl
;
478 bool send_new_highest_used_slotid
= false;
481 /* just wake up the next guy waiting since
482 * we may have not consumed a slot after all */
483 dprintk("%s: No slot\n", __func__
);
486 tbl
= res
->sr_slot
->table
;
487 session
= tbl
->session
;
489 spin_lock(&tbl
->slot_tbl_lock
);
490 /* Be nice to the server: try to ensure that the last transmitted
491 * value for highest_user_slotid <= target_highest_slotid
493 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
494 send_new_highest_used_slotid
= true;
496 if (nfs41_wake_and_assign_slot(tbl
, res
->sr_slot
)) {
497 send_new_highest_used_slotid
= false;
500 nfs4_free_slot(tbl
, res
->sr_slot
);
502 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
503 send_new_highest_used_slotid
= false;
505 spin_unlock(&tbl
->slot_tbl_lock
);
507 if (send_new_highest_used_slotid
)
508 nfs41_server_notify_highest_slotid_update(session
->clp
);
511 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
513 struct nfs4_session
*session
;
514 struct nfs4_slot
*slot
;
515 struct nfs_client
*clp
;
516 bool interrupted
= false;
519 /* don't increment the sequence number if the task wasn't sent */
520 if (!RPC_WAS_SENT(task
))
524 session
= slot
->table
->session
;
526 if (slot
->interrupted
) {
527 slot
->interrupted
= 0;
531 trace_nfs4_sequence_done(session
, res
);
532 /* Check the SEQUENCE operation status */
533 switch (res
->sr_status
) {
535 /* Update the slot's sequence and clientid lease timer */
538 do_renew_lease(clp
, res
->sr_timestamp
);
539 /* Check sequence flags */
540 if (res
->sr_status_flags
!= 0)
541 nfs4_schedule_lease_recovery(clp
);
542 nfs41_update_target_slotid(slot
->table
, slot
, res
);
546 * sr_status remains 1 if an RPC level error occurred.
547 * The server may or may not have processed the sequence
549 * Mark the slot as having hosted an interrupted RPC call.
551 slot
->interrupted
= 1;
554 /* The server detected a resend of the RPC call and
555 * returned NFS4ERR_DELAY as per Section 2.10.6.2
558 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
563 case -NFS4ERR_BADSLOT
:
565 * The slot id we used was probably retired. Try again
566 * using a different slot id.
569 case -NFS4ERR_SEQ_MISORDERED
:
571 * Was the last operation on this sequence interrupted?
572 * If so, retry after bumping the sequence number.
579 * Could this slot have been previously retired?
580 * If so, then the server may be expecting seq_nr = 1!
582 if (slot
->seq_nr
!= 1) {
587 case -NFS4ERR_SEQ_FALSE_RETRY
:
591 /* Just update the slot sequence no. */
595 /* The session may be reset by one of the error handlers. */
596 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
597 nfs41_sequence_free_slot(res
);
600 if (rpc_restart_call_prepare(task
)) {
606 if (!rpc_restart_call(task
))
608 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
612 static int nfs4_sequence_done(struct rpc_task
*task
,
613 struct nfs4_sequence_res
*res
)
615 if (res
->sr_slot
== NULL
)
617 return nfs41_sequence_done(task
, res
);
620 static void nfs41_init_sequence(struct nfs4_sequence_args
*args
,
621 struct nfs4_sequence_res
*res
, int cache_reply
)
623 args
->sa_slot
= NULL
;
624 args
->sa_cache_this
= 0;
625 args
->sa_privileged
= 0;
627 args
->sa_cache_this
= 1;
631 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
633 args
->sa_privileged
= 1;
636 int nfs41_setup_sequence(struct nfs4_session
*session
,
637 struct nfs4_sequence_args
*args
,
638 struct nfs4_sequence_res
*res
,
639 struct rpc_task
*task
)
641 struct nfs4_slot
*slot
;
642 struct nfs4_slot_table
*tbl
;
644 dprintk("--> %s\n", __func__
);
645 /* slot already allocated? */
646 if (res
->sr_slot
!= NULL
)
649 tbl
= &session
->fc_slot_table
;
651 task
->tk_timeout
= 0;
653 spin_lock(&tbl
->slot_tbl_lock
);
654 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
655 !args
->sa_privileged
) {
656 /* The state manager will wait until the slot table is empty */
657 dprintk("%s session is draining\n", __func__
);
661 slot
= nfs4_alloc_slot(tbl
);
663 /* If out of memory, try again in 1/4 second */
664 if (slot
== ERR_PTR(-ENOMEM
))
665 task
->tk_timeout
= HZ
>> 2;
666 dprintk("<-- %s: no free slots\n", __func__
);
669 spin_unlock(&tbl
->slot_tbl_lock
);
671 args
->sa_slot
= slot
;
673 dprintk("<-- %s slotid=%u seqid=%u\n", __func__
,
674 slot
->slot_nr
, slot
->seq_nr
);
677 res
->sr_timestamp
= jiffies
;
678 res
->sr_status_flags
= 0;
680 * sr_status is only set in decode_sequence, and so will remain
681 * set to 1 if an rpc level failure occurs.
684 trace_nfs4_setup_sequence(session
, args
);
686 rpc_call_start(task
);
689 /* Privileged tasks are queued with top priority */
690 if (args
->sa_privileged
)
691 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
692 NULL
, RPC_PRIORITY_PRIVILEGED
);
694 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
695 spin_unlock(&tbl
->slot_tbl_lock
);
698 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
700 static int nfs4_setup_sequence(const struct nfs_server
*server
,
701 struct nfs4_sequence_args
*args
,
702 struct nfs4_sequence_res
*res
,
703 struct rpc_task
*task
)
705 struct nfs4_session
*session
= nfs4_get_session(server
);
708 if (session
== NULL
) {
709 rpc_call_start(task
);
713 dprintk("--> %s clp %p session %p sr_slot %u\n",
714 __func__
, session
->clp
, session
, res
->sr_slot
?
715 res
->sr_slot
->slot_nr
: NFS4_NO_SLOT
);
717 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
719 dprintk("<-- %s status=%d\n", __func__
, ret
);
723 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
725 struct nfs4_call_sync_data
*data
= calldata
;
726 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
728 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
730 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
733 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
735 struct nfs4_call_sync_data
*data
= calldata
;
737 nfs41_sequence_done(task
, data
->seq_res
);
740 static const struct rpc_call_ops nfs41_call_sync_ops
= {
741 .rpc_call_prepare
= nfs41_call_sync_prepare
,
742 .rpc_call_done
= nfs41_call_sync_done
,
745 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
746 struct nfs_server
*server
,
747 struct rpc_message
*msg
,
748 struct nfs4_sequence_args
*args
,
749 struct nfs4_sequence_res
*res
)
752 struct rpc_task
*task
;
753 struct nfs4_call_sync_data data
= {
754 .seq_server
= server
,
758 struct rpc_task_setup task_setup
= {
761 .callback_ops
= &nfs41_call_sync_ops
,
762 .callback_data
= &data
765 task
= rpc_run_task(&task_setup
);
769 ret
= task
->tk_status
;
777 void nfs41_init_sequence(struct nfs4_sequence_args
*args
,
778 struct nfs4_sequence_res
*res
, int cache_reply
)
782 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
786 static int nfs4_setup_sequence(const struct nfs_server
*server
,
787 struct nfs4_sequence_args
*args
,
788 struct nfs4_sequence_res
*res
,
789 struct rpc_task
*task
)
791 rpc_call_start(task
);
795 static int nfs4_sequence_done(struct rpc_task
*task
,
796 struct nfs4_sequence_res
*res
)
800 #endif /* CONFIG_NFS_V4_1 */
803 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
804 struct nfs_server
*server
,
805 struct rpc_message
*msg
,
806 struct nfs4_sequence_args
*args
,
807 struct nfs4_sequence_res
*res
)
809 return rpc_call_sync(clnt
, msg
, 0);
813 int nfs4_call_sync(struct rpc_clnt
*clnt
,
814 struct nfs_server
*server
,
815 struct rpc_message
*msg
,
816 struct nfs4_sequence_args
*args
,
817 struct nfs4_sequence_res
*res
,
820 nfs41_init_sequence(args
, res
, cache_reply
);
821 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
825 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
827 struct nfs_inode
*nfsi
= NFS_I(dir
);
829 spin_lock(&dir
->i_lock
);
830 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
831 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
832 nfs_force_lookup_revalidate(dir
);
833 dir
->i_version
= cinfo
->after
;
834 nfs_fscache_invalidate(dir
);
835 spin_unlock(&dir
->i_lock
);
838 struct nfs4_opendata
{
840 struct nfs_openargs o_arg
;
841 struct nfs_openres o_res
;
842 struct nfs_open_confirmargs c_arg
;
843 struct nfs_open_confirmres c_res
;
844 struct nfs4_string owner_name
;
845 struct nfs4_string group_name
;
846 struct nfs_fattr f_attr
;
847 struct nfs4_label
*f_label
;
849 struct dentry
*dentry
;
850 struct nfs4_state_owner
*owner
;
851 struct nfs4_state
*state
;
853 unsigned long timestamp
;
854 unsigned int rpc_done
: 1;
855 unsigned int is_recover
: 1;
860 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
861 int err
, struct nfs4_exception
*exception
)
865 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
867 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
868 exception
->retry
= 1;
872 static enum open_claim_type4
873 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
874 enum open_claim_type4 claim
)
876 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
881 case NFS4_OPEN_CLAIM_FH
:
882 return NFS4_OPEN_CLAIM_NULL
;
883 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
884 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
885 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
886 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
890 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
892 p
->o_res
.f_attr
= &p
->f_attr
;
893 p
->o_res
.f_label
= p
->f_label
;
894 p
->o_res
.seqid
= p
->o_arg
.seqid
;
895 p
->c_res
.seqid
= p
->c_arg
.seqid
;
896 p
->o_res
.server
= p
->o_arg
.server
;
897 p
->o_res
.access_request
= p
->o_arg
.access
;
898 nfs_fattr_init(&p
->f_attr
);
899 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
902 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
903 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
904 const struct iattr
*attrs
,
905 struct nfs4_label
*label
,
906 enum open_claim_type4 claim
,
909 struct dentry
*parent
= dget_parent(dentry
);
910 struct inode
*dir
= parent
->d_inode
;
911 struct nfs_server
*server
= NFS_SERVER(dir
);
912 struct nfs4_opendata
*p
;
914 p
= kzalloc(sizeof(*p
), gfp_mask
);
918 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
919 if (IS_ERR(p
->f_label
))
922 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
923 if (p
->o_arg
.seqid
== NULL
)
925 nfs_sb_active(dentry
->d_sb
);
926 p
->dentry
= dget(dentry
);
929 atomic_inc(&sp
->so_count
);
930 p
->o_arg
.open_flags
= flags
;
931 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
932 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
933 * will return permission denied for all bits until close */
934 if (!(flags
& O_EXCL
)) {
935 /* ask server to check for all possible rights as results
937 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
938 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
940 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
941 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
942 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
943 p
->o_arg
.name
= &dentry
->d_name
;
944 p
->o_arg
.server
= server
;
945 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
946 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
947 p
->o_arg
.label
= label
;
948 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
949 switch (p
->o_arg
.claim
) {
950 case NFS4_OPEN_CLAIM_NULL
:
951 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
952 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
953 p
->o_arg
.fh
= NFS_FH(dir
);
955 case NFS4_OPEN_CLAIM_PREVIOUS
:
956 case NFS4_OPEN_CLAIM_FH
:
957 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
958 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
959 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
961 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
964 p
->o_arg
.u
.attrs
= &p
->attrs
;
965 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
968 verf
[1] = current
->pid
;
969 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
970 sizeof(p
->o_arg
.u
.verifier
.data
));
972 p
->c_arg
.fh
= &p
->o_res
.fh
;
973 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
974 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
975 nfs4_init_opendata_res(p
);
980 nfs4_label_free(p
->f_label
);
988 static void nfs4_opendata_free(struct kref
*kref
)
990 struct nfs4_opendata
*p
= container_of(kref
,
991 struct nfs4_opendata
, kref
);
992 struct super_block
*sb
= p
->dentry
->d_sb
;
994 nfs_free_seqid(p
->o_arg
.seqid
);
995 if (p
->state
!= NULL
)
996 nfs4_put_open_state(p
->state
);
997 nfs4_put_state_owner(p
->owner
);
999 nfs4_label_free(p
->f_label
);
1003 nfs_sb_deactive(sb
);
1004 nfs_fattr_free_names(&p
->f_attr
);
1008 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1011 kref_put(&p
->kref
, nfs4_opendata_free
);
1014 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
1018 ret
= rpc_wait_for_completion_task(task
);
1022 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1026 if (open_mode
& (O_EXCL
|O_TRUNC
))
1028 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1030 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1031 && state
->n_rdonly
!= 0;
1034 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1035 && state
->n_wronly
!= 0;
1037 case FMODE_READ
|FMODE_WRITE
:
1038 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1039 && state
->n_rdwr
!= 0;
1045 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1047 if (delegation
== NULL
)
1049 if ((delegation
->type
& fmode
) != fmode
)
1051 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1053 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1055 nfs_mark_delegation_referenced(delegation
);
1059 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1068 case FMODE_READ
|FMODE_WRITE
:
1071 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1074 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1076 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1077 nfs4_stateid_copy(&state
->stateid
, stateid
);
1078 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1079 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1082 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1085 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1087 case FMODE_READ
|FMODE_WRITE
:
1088 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1092 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1094 write_seqlock(&state
->seqlock
);
1095 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
1096 write_sequnlock(&state
->seqlock
);
1099 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1102 * Protect the call to nfs4_state_set_mode_locked and
1103 * serialise the stateid update
1105 write_seqlock(&state
->seqlock
);
1106 if (deleg_stateid
!= NULL
) {
1107 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1108 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1110 if (open_stateid
!= NULL
)
1111 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1112 write_sequnlock(&state
->seqlock
);
1113 spin_lock(&state
->owner
->so_lock
);
1114 update_open_stateflags(state
, fmode
);
1115 spin_unlock(&state
->owner
->so_lock
);
1118 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1120 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1121 struct nfs_delegation
*deleg_cur
;
1124 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1127 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1128 if (deleg_cur
== NULL
)
1131 spin_lock(&deleg_cur
->lock
);
1132 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1133 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1134 (deleg_cur
->type
& fmode
) != fmode
)
1135 goto no_delegation_unlock
;
1137 if (delegation
== NULL
)
1138 delegation
= &deleg_cur
->stateid
;
1139 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1140 goto no_delegation_unlock
;
1142 nfs_mark_delegation_referenced(deleg_cur
);
1143 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1145 no_delegation_unlock
:
1146 spin_unlock(&deleg_cur
->lock
);
1150 if (!ret
&& open_stateid
!= NULL
) {
1151 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1159 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1161 struct nfs_delegation
*delegation
;
1164 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1165 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1170 nfs4_inode_return_delegation(inode
);
1173 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1175 struct nfs4_state
*state
= opendata
->state
;
1176 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1177 struct nfs_delegation
*delegation
;
1178 int open_mode
= opendata
->o_arg
.open_flags
;
1179 fmode_t fmode
= opendata
->o_arg
.fmode
;
1180 nfs4_stateid stateid
;
1184 if (can_open_cached(state
, fmode
, open_mode
)) {
1185 spin_lock(&state
->owner
->so_lock
);
1186 if (can_open_cached(state
, fmode
, open_mode
)) {
1187 update_open_stateflags(state
, fmode
);
1188 spin_unlock(&state
->owner
->so_lock
);
1189 goto out_return_state
;
1191 spin_unlock(&state
->owner
->so_lock
);
1194 delegation
= rcu_dereference(nfsi
->delegation
);
1195 if (!can_open_delegated(delegation
, fmode
)) {
1199 /* Save the delegation */
1200 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1202 nfs_release_seqid(opendata
->o_arg
.seqid
);
1203 if (!opendata
->is_recover
) {
1204 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1210 /* Try to update the stateid using the delegation */
1211 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1212 goto out_return_state
;
1215 return ERR_PTR(ret
);
1217 atomic_inc(&state
->count
);
1222 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1224 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1225 struct nfs_delegation
*delegation
;
1226 int delegation_flags
= 0;
1229 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1231 delegation_flags
= delegation
->flags
;
1233 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1234 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1235 "returning a delegation for "
1236 "OPEN(CLAIM_DELEGATE_CUR)\n",
1238 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1239 nfs_inode_set_delegation(state
->inode
,
1240 data
->owner
->so_cred
,
1243 nfs_inode_reclaim_delegation(state
->inode
,
1244 data
->owner
->so_cred
,
1249 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1250 * and update the nfs4_state.
1252 static struct nfs4_state
*
1253 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1255 struct inode
*inode
= data
->state
->inode
;
1256 struct nfs4_state
*state
= data
->state
;
1259 if (!data
->rpc_done
) {
1260 ret
= data
->rpc_status
;
1265 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR_TYPE
) ||
1266 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_FILEID
) ||
1267 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_CHANGE
))
1271 state
= nfs4_get_open_state(inode
, data
->owner
);
1275 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1279 nfs_setsecurity(inode
, &data
->f_attr
, data
->f_label
);
1281 if (data
->o_res
.delegation_type
!= 0)
1282 nfs4_opendata_check_deleg(data
, state
);
1283 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1288 return ERR_PTR(ret
);
1292 static struct nfs4_state
*
1293 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1295 struct inode
*inode
;
1296 struct nfs4_state
*state
= NULL
;
1299 if (!data
->rpc_done
) {
1300 state
= nfs4_try_open_cached(data
);
1305 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1307 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1308 ret
= PTR_ERR(inode
);
1312 state
= nfs4_get_open_state(inode
, data
->owner
);
1315 if (data
->o_res
.delegation_type
!= 0)
1316 nfs4_opendata_check_deleg(data
, state
);
1317 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1321 nfs_release_seqid(data
->o_arg
.seqid
);
1326 return ERR_PTR(ret
);
1329 static struct nfs4_state
*
1330 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1332 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1333 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1334 return _nfs4_opendata_to_nfs4_state(data
);
1337 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1339 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1340 struct nfs_open_context
*ctx
;
1342 spin_lock(&state
->inode
->i_lock
);
1343 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1344 if (ctx
->state
!= state
)
1346 get_nfs_open_context(ctx
);
1347 spin_unlock(&state
->inode
->i_lock
);
1350 spin_unlock(&state
->inode
->i_lock
);
1351 return ERR_PTR(-ENOENT
);
1354 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1355 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1357 struct nfs4_opendata
*opendata
;
1359 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1360 NULL
, NULL
, claim
, GFP_NOFS
);
1361 if (opendata
== NULL
)
1362 return ERR_PTR(-ENOMEM
);
1363 opendata
->state
= state
;
1364 atomic_inc(&state
->count
);
1368 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1370 struct nfs4_state
*newstate
;
1373 opendata
->o_arg
.open_flags
= 0;
1374 opendata
->o_arg
.fmode
= fmode
;
1375 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1376 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1377 nfs4_init_opendata_res(opendata
);
1378 ret
= _nfs4_recover_proc_open(opendata
);
1381 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1382 if (IS_ERR(newstate
))
1383 return PTR_ERR(newstate
);
1384 nfs4_close_state(newstate
, fmode
);
1389 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1391 struct nfs4_state
*newstate
;
1394 /* memory barrier prior to reading state->n_* */
1395 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1396 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1398 if (state
->n_rdwr
!= 0) {
1399 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1400 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1403 if (newstate
!= state
)
1406 if (state
->n_wronly
!= 0) {
1407 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1408 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1411 if (newstate
!= state
)
1414 if (state
->n_rdonly
!= 0) {
1415 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1416 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1419 if (newstate
!= state
)
1423 * We may have performed cached opens for all three recoveries.
1424 * Check if we need to update the current stateid.
1426 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1427 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1428 write_seqlock(&state
->seqlock
);
1429 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1430 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1431 write_sequnlock(&state
->seqlock
);
1438 * reclaim state on the server after a reboot.
1440 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1442 struct nfs_delegation
*delegation
;
1443 struct nfs4_opendata
*opendata
;
1444 fmode_t delegation_type
= 0;
1447 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1448 NFS4_OPEN_CLAIM_PREVIOUS
);
1449 if (IS_ERR(opendata
))
1450 return PTR_ERR(opendata
);
1452 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1453 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1454 delegation_type
= delegation
->type
;
1456 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1457 status
= nfs4_open_recover(opendata
, state
);
1458 nfs4_opendata_put(opendata
);
1462 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1464 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1465 struct nfs4_exception exception
= { };
1468 err
= _nfs4_do_open_reclaim(ctx
, state
);
1469 trace_nfs4_open_reclaim(ctx
, 0, err
);
1470 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1472 if (err
!= -NFS4ERR_DELAY
)
1474 nfs4_handle_exception(server
, err
, &exception
);
1475 } while (exception
.retry
);
1479 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1481 struct nfs_open_context
*ctx
;
1484 ctx
= nfs4_state_find_open_context(state
);
1487 ret
= nfs4_do_open_reclaim(ctx
, state
);
1488 put_nfs_open_context(ctx
);
1492 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1496 printk(KERN_ERR
"NFS: %s: unhandled error "
1497 "%d.\n", __func__
, err
);
1502 case -NFS4ERR_BADSESSION
:
1503 case -NFS4ERR_BADSLOT
:
1504 case -NFS4ERR_BAD_HIGH_SLOT
:
1505 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1506 case -NFS4ERR_DEADSESSION
:
1507 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1508 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1510 case -NFS4ERR_STALE_CLIENTID
:
1511 case -NFS4ERR_STALE_STATEID
:
1512 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1513 case -NFS4ERR_EXPIRED
:
1514 /* Don't recall a delegation if it was lost */
1515 nfs4_schedule_lease_recovery(server
->nfs_client
);
1517 case -NFS4ERR_DELEG_REVOKED
:
1518 case -NFS4ERR_ADMIN_REVOKED
:
1519 case -NFS4ERR_BAD_STATEID
:
1520 case -NFS4ERR_OPENMODE
:
1521 nfs_inode_find_state_and_recover(state
->inode
,
1523 nfs4_schedule_stateid_recovery(server
, state
);
1525 case -NFS4ERR_DELAY
:
1526 case -NFS4ERR_GRACE
:
1527 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1531 case -NFS4ERR_DENIED
:
1532 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1538 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1540 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1541 struct nfs4_opendata
*opendata
;
1544 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1545 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1546 if (IS_ERR(opendata
))
1547 return PTR_ERR(opendata
);
1548 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1549 err
= nfs4_open_recover(opendata
, state
);
1550 nfs4_opendata_put(opendata
);
1551 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1554 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1556 struct nfs4_opendata
*data
= calldata
;
1558 data
->rpc_status
= task
->tk_status
;
1559 if (data
->rpc_status
== 0) {
1560 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1561 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1562 renew_lease(data
->o_res
.server
, data
->timestamp
);
1567 static void nfs4_open_confirm_release(void *calldata
)
1569 struct nfs4_opendata
*data
= calldata
;
1570 struct nfs4_state
*state
= NULL
;
1572 /* If this request hasn't been cancelled, do nothing */
1573 if (data
->cancelled
== 0)
1575 /* In case of error, no cleanup! */
1576 if (!data
->rpc_done
)
1578 state
= nfs4_opendata_to_nfs4_state(data
);
1580 nfs4_close_state(state
, data
->o_arg
.fmode
);
1582 nfs4_opendata_put(data
);
1585 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1586 .rpc_call_done
= nfs4_open_confirm_done
,
1587 .rpc_release
= nfs4_open_confirm_release
,
1591 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1593 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1595 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1596 struct rpc_task
*task
;
1597 struct rpc_message msg
= {
1598 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1599 .rpc_argp
= &data
->c_arg
,
1600 .rpc_resp
= &data
->c_res
,
1601 .rpc_cred
= data
->owner
->so_cred
,
1603 struct rpc_task_setup task_setup_data
= {
1604 .rpc_client
= server
->client
,
1605 .rpc_message
= &msg
,
1606 .callback_ops
= &nfs4_open_confirm_ops
,
1607 .callback_data
= data
,
1608 .workqueue
= nfsiod_workqueue
,
1609 .flags
= RPC_TASK_ASYNC
,
1613 kref_get(&data
->kref
);
1615 data
->rpc_status
= 0;
1616 data
->timestamp
= jiffies
;
1617 task
= rpc_run_task(&task_setup_data
);
1619 return PTR_ERR(task
);
1620 status
= nfs4_wait_for_completion_rpc_task(task
);
1622 data
->cancelled
= 1;
1625 status
= data
->rpc_status
;
1630 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1632 struct nfs4_opendata
*data
= calldata
;
1633 struct nfs4_state_owner
*sp
= data
->owner
;
1634 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1636 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1639 * Check if we still need to send an OPEN call, or if we can use
1640 * a delegation instead.
1642 if (data
->state
!= NULL
) {
1643 struct nfs_delegation
*delegation
;
1645 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1648 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1649 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1650 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1651 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1652 goto unlock_no_action
;
1655 /* Update client id. */
1656 data
->o_arg
.clientid
= clp
->cl_clientid
;
1657 switch (data
->o_arg
.claim
) {
1658 case NFS4_OPEN_CLAIM_PREVIOUS
:
1659 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1660 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1661 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1662 case NFS4_OPEN_CLAIM_FH
:
1663 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1664 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1666 data
->timestamp
= jiffies
;
1667 if (nfs4_setup_sequence(data
->o_arg
.server
,
1668 &data
->o_arg
.seq_args
,
1669 &data
->o_res
.seq_res
,
1671 nfs_release_seqid(data
->o_arg
.seqid
);
1673 /* Set the create mode (note dependency on the session type) */
1674 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1675 if (data
->o_arg
.open_flags
& O_EXCL
) {
1676 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1677 if (nfs4_has_persistent_session(clp
))
1678 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1679 else if (clp
->cl_mvops
->minor_version
> 0)
1680 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1686 task
->tk_action
= NULL
;
1688 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1691 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1693 struct nfs4_opendata
*data
= calldata
;
1695 data
->rpc_status
= task
->tk_status
;
1697 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1700 if (task
->tk_status
== 0) {
1701 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1702 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1706 data
->rpc_status
= -ELOOP
;
1709 data
->rpc_status
= -EISDIR
;
1712 data
->rpc_status
= -ENOTDIR
;
1715 renew_lease(data
->o_res
.server
, data
->timestamp
);
1716 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1717 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1722 static void nfs4_open_release(void *calldata
)
1724 struct nfs4_opendata
*data
= calldata
;
1725 struct nfs4_state
*state
= NULL
;
1727 /* If this request hasn't been cancelled, do nothing */
1728 if (data
->cancelled
== 0)
1730 /* In case of error, no cleanup! */
1731 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1733 /* In case we need an open_confirm, no cleanup! */
1734 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1736 state
= nfs4_opendata_to_nfs4_state(data
);
1738 nfs4_close_state(state
, data
->o_arg
.fmode
);
1740 nfs4_opendata_put(data
);
1743 static const struct rpc_call_ops nfs4_open_ops
= {
1744 .rpc_call_prepare
= nfs4_open_prepare
,
1745 .rpc_call_done
= nfs4_open_done
,
1746 .rpc_release
= nfs4_open_release
,
1749 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1751 struct inode
*dir
= data
->dir
->d_inode
;
1752 struct nfs_server
*server
= NFS_SERVER(dir
);
1753 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1754 struct nfs_openres
*o_res
= &data
->o_res
;
1755 struct rpc_task
*task
;
1756 struct rpc_message msg
= {
1757 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1760 .rpc_cred
= data
->owner
->so_cred
,
1762 struct rpc_task_setup task_setup_data
= {
1763 .rpc_client
= server
->client
,
1764 .rpc_message
= &msg
,
1765 .callback_ops
= &nfs4_open_ops
,
1766 .callback_data
= data
,
1767 .workqueue
= nfsiod_workqueue
,
1768 .flags
= RPC_TASK_ASYNC
,
1772 nfs41_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1773 kref_get(&data
->kref
);
1775 data
->rpc_status
= 0;
1776 data
->cancelled
= 0;
1777 data
->is_recover
= 0;
1779 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1780 data
->is_recover
= 1;
1782 task
= rpc_run_task(&task_setup_data
);
1784 return PTR_ERR(task
);
1785 status
= nfs4_wait_for_completion_rpc_task(task
);
1787 data
->cancelled
= 1;
1790 status
= data
->rpc_status
;
1796 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1798 struct inode
*dir
= data
->dir
->d_inode
;
1799 struct nfs_openres
*o_res
= &data
->o_res
;
1802 status
= nfs4_run_open_task(data
, 1);
1803 if (status
!= 0 || !data
->rpc_done
)
1806 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1808 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1809 status
= _nfs4_proc_open_confirm(data
);
1817 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1818 struct nfs4_opendata
*opendata
,
1819 struct nfs4_state
*state
, fmode_t fmode
,
1822 struct nfs_access_entry cache
;
1825 /* access call failed or for some reason the server doesn't
1826 * support any access modes -- defer access call until later */
1827 if (opendata
->o_res
.access_supported
== 0)
1831 /* don't check MAY_WRITE - a newly created file may not have
1832 * write mode bits, but POSIX allows the creating process to write.
1833 * use openflags to check for exec, because fmode won't
1834 * always have FMODE_EXEC set when file open for exec. */
1835 if (openflags
& __FMODE_EXEC
) {
1836 /* ONLY check for exec rights */
1838 } else if (fmode
& FMODE_READ
)
1842 cache
.jiffies
= jiffies
;
1843 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1844 nfs_access_add_cache(state
->inode
, &cache
);
1846 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
1849 /* even though OPEN succeeded, access is denied. Close the file */
1850 nfs4_close_state(state
, fmode
);
1855 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1857 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1859 struct inode
*dir
= data
->dir
->d_inode
;
1860 struct nfs_server
*server
= NFS_SERVER(dir
);
1861 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1862 struct nfs_openres
*o_res
= &data
->o_res
;
1865 status
= nfs4_run_open_task(data
, 0);
1866 if (!data
->rpc_done
)
1869 if (status
== -NFS4ERR_BADNAME
&&
1870 !(o_arg
->open_flags
& O_CREAT
))
1875 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
1877 if (o_arg
->open_flags
& O_CREAT
)
1878 update_changeattr(dir
, &o_res
->cinfo
);
1879 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1880 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1881 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1882 status
= _nfs4_proc_open_confirm(data
);
1886 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1887 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
1891 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1893 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1898 * reclaim state on the server after a network partition.
1899 * Assumes caller holds the appropriate lock
1901 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1903 struct nfs4_opendata
*opendata
;
1906 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1907 NFS4_OPEN_CLAIM_FH
);
1908 if (IS_ERR(opendata
))
1909 return PTR_ERR(opendata
);
1910 ret
= nfs4_open_recover(opendata
, state
);
1912 d_drop(ctx
->dentry
);
1913 nfs4_opendata_put(opendata
);
1917 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1919 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1920 struct nfs4_exception exception
= { };
1924 err
= _nfs4_open_expired(ctx
, state
);
1925 trace_nfs4_open_expired(ctx
, 0, err
);
1926 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1931 case -NFS4ERR_GRACE
:
1932 case -NFS4ERR_DELAY
:
1933 nfs4_handle_exception(server
, err
, &exception
);
1936 } while (exception
.retry
);
1941 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1943 struct nfs_open_context
*ctx
;
1946 ctx
= nfs4_state_find_open_context(state
);
1949 ret
= nfs4_do_open_expired(ctx
, state
);
1950 put_nfs_open_context(ctx
);
1954 #if defined(CONFIG_NFS_V4_1)
1955 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
1957 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1958 nfs4_stateid
*stateid
= &state
->stateid
;
1959 struct nfs_delegation
*delegation
;
1960 struct rpc_cred
*cred
= NULL
;
1961 int status
= -NFS4ERR_BAD_STATEID
;
1963 /* If a state reset has been done, test_stateid is unneeded */
1964 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1967 /* Get the delegation credential for use by test/free_stateid */
1969 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1970 if (delegation
!= NULL
&&
1971 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
1972 cred
= get_rpccred(delegation
->cred
);
1974 status
= nfs41_test_stateid(server
, stateid
, cred
);
1975 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
1979 if (status
!= NFS_OK
) {
1980 /* Free the stateid unless the server explicitly
1981 * informs us the stateid is unrecognized. */
1982 if (status
!= -NFS4ERR_BAD_STATEID
)
1983 nfs41_free_stateid(server
, stateid
, cred
);
1984 nfs_remove_bad_delegation(state
->inode
);
1986 write_seqlock(&state
->seqlock
);
1987 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1988 write_sequnlock(&state
->seqlock
);
1989 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1997 * nfs41_check_open_stateid - possibly free an open stateid
1999 * @state: NFSv4 state for an inode
2001 * Returns NFS_OK if recovery for this stateid is now finished.
2002 * Otherwise a negative NFS4ERR value is returned.
2004 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2006 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2007 nfs4_stateid
*stateid
= &state
->open_stateid
;
2008 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2011 /* If a state reset has been done, test_stateid is unneeded */
2012 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
2013 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
2014 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
2015 return -NFS4ERR_BAD_STATEID
;
2017 status
= nfs41_test_stateid(server
, stateid
, cred
);
2018 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2019 if (status
!= NFS_OK
) {
2020 /* Free the stateid unless the server explicitly
2021 * informs us the stateid is unrecognized. */
2022 if (status
!= -NFS4ERR_BAD_STATEID
)
2023 nfs41_free_stateid(server
, stateid
, cred
);
2025 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2026 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2027 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2028 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2033 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2037 nfs41_clear_delegation_stateid(state
);
2038 status
= nfs41_check_open_stateid(state
);
2039 if (status
!= NFS_OK
)
2040 status
= nfs4_open_expired(sp
, state
);
2046 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2047 * fields corresponding to attributes that were used to store the verifier.
2048 * Make sure we clobber those fields in the later setattr call
2050 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2052 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2053 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2054 sattr
->ia_valid
|= ATTR_ATIME
;
2056 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2057 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2058 sattr
->ia_valid
|= ATTR_MTIME
;
2061 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2064 struct nfs_open_context
*ctx
)
2066 struct nfs4_state_owner
*sp
= opendata
->owner
;
2067 struct nfs_server
*server
= sp
->so_server
;
2068 struct dentry
*dentry
;
2069 struct nfs4_state
*state
;
2073 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2075 ret
= _nfs4_proc_open(opendata
);
2079 state
= nfs4_opendata_to_nfs4_state(opendata
);
2080 ret
= PTR_ERR(state
);
2083 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2084 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2086 dentry
= opendata
->dentry
;
2087 if (dentry
->d_inode
== NULL
) {
2088 /* FIXME: Is this d_drop() ever needed? */
2090 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2091 if (dentry
== NULL
) {
2092 dentry
= opendata
->dentry
;
2093 } else if (dentry
!= ctx
->dentry
) {
2095 ctx
->dentry
= dget(dentry
);
2097 nfs_set_verifier(dentry
,
2098 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2101 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2106 if (dentry
->d_inode
== state
->inode
) {
2107 nfs_inode_attach_open_context(ctx
);
2108 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2109 nfs4_schedule_stateid_recovery(server
, state
);
2116 * Returns a referenced nfs4_state
2118 static int _nfs4_do_open(struct inode
*dir
,
2119 struct nfs_open_context
*ctx
,
2121 struct iattr
*sattr
,
2122 struct nfs4_label
*label
)
2124 struct nfs4_state_owner
*sp
;
2125 struct nfs4_state
*state
= NULL
;
2126 struct nfs_server
*server
= NFS_SERVER(dir
);
2127 struct nfs4_opendata
*opendata
;
2128 struct dentry
*dentry
= ctx
->dentry
;
2129 struct rpc_cred
*cred
= ctx
->cred
;
2130 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2131 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2132 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2133 struct nfs4_label
*olabel
= NULL
;
2136 /* Protect against reboot recovery conflicts */
2138 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2140 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2143 status
= nfs4_recover_expired_lease(server
);
2145 goto err_put_state_owner
;
2146 if (dentry
->d_inode
!= NULL
)
2147 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2149 if (dentry
->d_inode
)
2150 claim
= NFS4_OPEN_CLAIM_FH
;
2151 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2152 label
, claim
, GFP_KERNEL
);
2153 if (opendata
== NULL
)
2154 goto err_put_state_owner
;
2157 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2158 if (IS_ERR(olabel
)) {
2159 status
= PTR_ERR(olabel
);
2160 goto err_opendata_put
;
2164 if (ctx_th
&& server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2165 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2166 if (!opendata
->f_attr
.mdsthreshold
)
2167 goto err_free_label
;
2168 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2170 if (dentry
->d_inode
!= NULL
)
2171 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2173 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2175 goto err_free_label
;
2178 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2179 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2180 nfs4_exclusive_attrset(opendata
, sattr
);
2182 nfs_fattr_init(opendata
->o_res
.f_attr
);
2183 status
= nfs4_do_setattr(state
->inode
, cred
,
2184 opendata
->o_res
.f_attr
, sattr
,
2185 state
, label
, olabel
);
2187 nfs_setattr_update_inode(state
->inode
, sattr
);
2188 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2189 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2193 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
))
2194 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2196 kfree(opendata
->f_attr
.mdsthreshold
);
2197 opendata
->f_attr
.mdsthreshold
= NULL
;
2199 nfs4_label_free(olabel
);
2201 nfs4_opendata_put(opendata
);
2202 nfs4_put_state_owner(sp
);
2205 nfs4_label_free(olabel
);
2207 kfree(opendata
->f_attr
.mdsthreshold
);
2208 nfs4_opendata_put(opendata
);
2209 err_put_state_owner
:
2210 nfs4_put_state_owner(sp
);
2216 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2217 struct nfs_open_context
*ctx
,
2219 struct iattr
*sattr
,
2220 struct nfs4_label
*label
)
2222 struct nfs_server
*server
= NFS_SERVER(dir
);
2223 struct nfs4_exception exception
= { };
2224 struct nfs4_state
*res
;
2228 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
);
2230 trace_nfs4_open_file(ctx
, flags
, status
);
2233 /* NOTE: BAD_SEQID means the server and client disagree about the
2234 * book-keeping w.r.t. state-changing operations
2235 * (OPEN/CLOSE/LOCK/LOCKU...)
2236 * It is actually a sign of a bug on the client or on the server.
2238 * If we receive a BAD_SEQID error in the particular case of
2239 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2240 * have unhashed the old state_owner for us, and that we can
2241 * therefore safely retry using a new one. We should still warn
2242 * the user though...
2244 if (status
== -NFS4ERR_BAD_SEQID
) {
2245 pr_warn_ratelimited("NFS: v4 server %s "
2246 " returned a bad sequence-id error!\n",
2247 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2248 exception
.retry
= 1;
2252 * BAD_STATEID on OPEN means that the server cancelled our
2253 * state before it received the OPEN_CONFIRM.
2254 * Recover by retrying the request as per the discussion
2255 * on Page 181 of RFC3530.
2257 if (status
== -NFS4ERR_BAD_STATEID
) {
2258 exception
.retry
= 1;
2261 if (status
== -EAGAIN
) {
2262 /* We must have found a delegation */
2263 exception
.retry
= 1;
2266 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2268 res
= ERR_PTR(nfs4_handle_exception(server
,
2269 status
, &exception
));
2270 } while (exception
.retry
);
2274 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2275 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2276 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2277 struct nfs4_label
*olabel
)
2279 struct nfs_server
*server
= NFS_SERVER(inode
);
2280 struct nfs_setattrargs arg
= {
2281 .fh
= NFS_FH(inode
),
2284 .bitmask
= server
->attr_bitmask
,
2287 struct nfs_setattrres res
= {
2292 struct rpc_message msg
= {
2293 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2298 unsigned long timestamp
= jiffies
;
2303 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2305 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2307 nfs_fattr_init(fattr
);
2309 /* Servers should only apply open mode checks for file size changes */
2310 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2311 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2313 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2314 /* Use that stateid */
2315 } else if (truncate
&& state
!= NULL
&& nfs4_valid_open_stateid(state
)) {
2316 struct nfs_lockowner lockowner
= {
2317 .l_owner
= current
->files
,
2318 .l_pid
= current
->tgid
,
2320 nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2323 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2325 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2326 if (status
== 0 && state
!= NULL
)
2327 renew_lease(server
, timestamp
);
2331 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2332 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2333 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2334 struct nfs4_label
*olabel
)
2336 struct nfs_server
*server
= NFS_SERVER(inode
);
2337 struct nfs4_exception exception
= {
2343 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2344 trace_nfs4_setattr(inode
, err
);
2346 case -NFS4ERR_OPENMODE
:
2347 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2348 pr_warn_once("NFSv4: server %s is incorrectly "
2349 "applying open mode checks to "
2350 "a SETATTR that is not "
2351 "changing file size.\n",
2352 server
->nfs_client
->cl_hostname
);
2354 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2356 if (sattr
->ia_valid
& ATTR_OPEN
)
2361 err
= nfs4_handle_exception(server
, err
, &exception
);
2362 } while (exception
.retry
);
2367 struct nfs4_closedata
{
2368 struct inode
*inode
;
2369 struct nfs4_state
*state
;
2370 struct nfs_closeargs arg
;
2371 struct nfs_closeres res
;
2372 struct nfs_fattr fattr
;
2373 unsigned long timestamp
;
2378 static void nfs4_free_closedata(void *data
)
2380 struct nfs4_closedata
*calldata
= data
;
2381 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2382 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2385 pnfs_roc_release(calldata
->state
->inode
);
2386 nfs4_put_open_state(calldata
->state
);
2387 nfs_free_seqid(calldata
->arg
.seqid
);
2388 nfs4_put_state_owner(sp
);
2389 nfs_sb_deactive(sb
);
2393 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
2396 spin_lock(&state
->owner
->so_lock
);
2397 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2398 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
2400 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2403 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2406 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2407 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2408 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2410 spin_unlock(&state
->owner
->so_lock
);
2413 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2415 struct nfs4_closedata
*calldata
= data
;
2416 struct nfs4_state
*state
= calldata
->state
;
2417 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2419 dprintk("%s: begin!\n", __func__
);
2420 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2422 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2423 /* hmm. we are done with the inode, and in the process of freeing
2424 * the state_owner. we keep this around to process errors
2426 switch (task
->tk_status
) {
2429 pnfs_roc_set_barrier(state
->inode
,
2430 calldata
->roc_barrier
);
2431 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
2432 renew_lease(server
, calldata
->timestamp
);
2433 nfs4_close_clear_stateid_flags(state
,
2434 calldata
->arg
.fmode
);
2436 case -NFS4ERR_STALE_STATEID
:
2437 case -NFS4ERR_OLD_STATEID
:
2438 case -NFS4ERR_BAD_STATEID
:
2439 case -NFS4ERR_EXPIRED
:
2440 if (calldata
->arg
.fmode
== 0)
2443 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
2444 rpc_restart_call_prepare(task
);
2446 nfs_release_seqid(calldata
->arg
.seqid
);
2447 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2448 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2451 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2453 struct nfs4_closedata
*calldata
= data
;
2454 struct nfs4_state
*state
= calldata
->state
;
2455 struct inode
*inode
= calldata
->inode
;
2458 dprintk("%s: begin!\n", __func__
);
2459 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2462 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2463 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
2464 spin_lock(&state
->owner
->so_lock
);
2465 /* Calculate the change in open mode */
2466 if (state
->n_rdwr
== 0) {
2467 if (state
->n_rdonly
== 0) {
2468 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2469 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2470 calldata
->arg
.fmode
&= ~FMODE_READ
;
2472 if (state
->n_wronly
== 0) {
2473 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2474 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2475 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2478 if (!nfs4_valid_open_stateid(state
))
2480 spin_unlock(&state
->owner
->so_lock
);
2483 /* Note: exit _without_ calling nfs4_close_done */
2487 if (calldata
->arg
.fmode
== 0) {
2488 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2489 if (calldata
->roc
&&
2490 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2491 nfs_release_seqid(calldata
->arg
.seqid
);
2496 nfs_fattr_init(calldata
->res
.fattr
);
2497 calldata
->timestamp
= jiffies
;
2498 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2499 &calldata
->arg
.seq_args
,
2500 &calldata
->res
.seq_res
,
2502 nfs_release_seqid(calldata
->arg
.seqid
);
2503 dprintk("%s: done!\n", __func__
);
2506 task
->tk_action
= NULL
;
2508 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2511 static const struct rpc_call_ops nfs4_close_ops
= {
2512 .rpc_call_prepare
= nfs4_close_prepare
,
2513 .rpc_call_done
= nfs4_close_done
,
2514 .rpc_release
= nfs4_free_closedata
,
2518 * It is possible for data to be read/written from a mem-mapped file
2519 * after the sys_close call (which hits the vfs layer as a flush).
2520 * This means that we can't safely call nfsv4 close on a file until
2521 * the inode is cleared. This in turn means that we are not good
2522 * NFSv4 citizens - we do not indicate to the server to update the file's
2523 * share state even when we are done with one of the three share
2524 * stateid's in the inode.
2526 * NOTE: Caller must be holding the sp->so_owner semaphore!
2528 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2530 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2531 struct nfs4_closedata
*calldata
;
2532 struct nfs4_state_owner
*sp
= state
->owner
;
2533 struct rpc_task
*task
;
2534 struct rpc_message msg
= {
2535 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2536 .rpc_cred
= state
->owner
->so_cred
,
2538 struct rpc_task_setup task_setup_data
= {
2539 .rpc_client
= server
->client
,
2540 .rpc_message
= &msg
,
2541 .callback_ops
= &nfs4_close_ops
,
2542 .workqueue
= nfsiod_workqueue
,
2543 .flags
= RPC_TASK_ASYNC
,
2545 int status
= -ENOMEM
;
2547 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2548 if (calldata
== NULL
)
2550 nfs41_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2551 calldata
->inode
= state
->inode
;
2552 calldata
->state
= state
;
2553 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2554 calldata
->arg
.stateid
= &state
->open_stateid
;
2555 /* Serialization for the sequence id */
2556 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2557 if (calldata
->arg
.seqid
== NULL
)
2558 goto out_free_calldata
;
2559 calldata
->arg
.fmode
= 0;
2560 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2561 calldata
->res
.fattr
= &calldata
->fattr
;
2562 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2563 calldata
->res
.server
= server
;
2564 calldata
->roc
= pnfs_roc(state
->inode
);
2565 nfs_sb_active(calldata
->inode
->i_sb
);
2567 msg
.rpc_argp
= &calldata
->arg
;
2568 msg
.rpc_resp
= &calldata
->res
;
2569 task_setup_data
.callback_data
= calldata
;
2570 task
= rpc_run_task(&task_setup_data
);
2572 return PTR_ERR(task
);
2575 status
= rpc_wait_for_completion_task(task
);
2581 nfs4_put_open_state(state
);
2582 nfs4_put_state_owner(sp
);
2586 static struct inode
*
2587 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2589 struct nfs4_state
*state
;
2590 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2592 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2594 /* Protect against concurrent sillydeletes */
2595 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
);
2597 nfs4_label_release_security(label
);
2600 return ERR_CAST(state
);
2601 return state
->inode
;
2604 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2606 if (ctx
->state
== NULL
)
2609 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2611 nfs4_close_state(ctx
->state
, ctx
->mode
);
2614 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2616 struct nfs4_server_caps_arg args
= {
2619 struct nfs4_server_caps_res res
= {};
2620 struct rpc_message msg
= {
2621 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2627 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2629 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2630 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2631 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2632 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2633 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2634 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2635 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2636 server
->caps
|= NFS_CAP_ACLS
;
2637 if (res
.has_links
!= 0)
2638 server
->caps
|= NFS_CAP_HARDLINKS
;
2639 if (res
.has_symlinks
!= 0)
2640 server
->caps
|= NFS_CAP_SYMLINKS
;
2641 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2642 server
->caps
|= NFS_CAP_FILEID
;
2643 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2644 server
->caps
|= NFS_CAP_MODE
;
2645 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2646 server
->caps
|= NFS_CAP_NLINK
;
2647 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2648 server
->caps
|= NFS_CAP_OWNER
;
2649 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2650 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2651 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2652 server
->caps
|= NFS_CAP_ATIME
;
2653 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2654 server
->caps
|= NFS_CAP_CTIME
;
2655 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2656 server
->caps
|= NFS_CAP_MTIME
;
2657 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2658 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2659 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2661 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2662 sizeof(server
->attr_bitmask
));
2664 if (server
->caps
& NFS_CAP_SECURITY_LABEL
) {
2665 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2666 res
.attr_bitmask
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2668 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2669 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2670 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2671 server
->acl_bitmask
= res
.acl_bitmask
;
2672 server
->fh_expire_type
= res
.fh_expire_type
;
2678 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2680 struct nfs4_exception exception
= { };
2683 err
= nfs4_handle_exception(server
,
2684 _nfs4_server_capabilities(server
, fhandle
),
2686 } while (exception
.retry
);
2690 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2691 struct nfs_fsinfo
*info
)
2694 struct nfs4_lookup_root_arg args
= {
2697 struct nfs4_lookup_res res
= {
2699 .fattr
= info
->fattr
,
2702 struct rpc_message msg
= {
2703 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2708 bitmask
[0] = nfs4_fattr_bitmap
[0];
2709 bitmask
[1] = nfs4_fattr_bitmap
[1];
2711 * Process the label in the upcoming getfattr
2713 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2715 nfs_fattr_init(info
->fattr
);
2716 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2719 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2720 struct nfs_fsinfo
*info
)
2722 struct nfs4_exception exception
= { };
2725 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2726 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2729 case -NFS4ERR_WRONGSEC
:
2732 err
= nfs4_handle_exception(server
, err
, &exception
);
2734 } while (exception
.retry
);
2739 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2740 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2742 struct rpc_auth_create_args auth_args
= {
2743 .pseudoflavor
= flavor
,
2745 struct rpc_auth
*auth
;
2748 auth
= rpcauth_create(&auth_args
, server
->client
);
2753 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2759 * Retry pseudoroot lookup with various security flavors. We do this when:
2761 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2762 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2764 * Returns zero on success, or a negative NFS4ERR value, or a
2765 * negative errno value.
2767 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2768 struct nfs_fsinfo
*info
)
2770 /* Per 3530bis 15.33.5 */
2771 static const rpc_authflavor_t flav_array
[] = {
2775 RPC_AUTH_UNIX
, /* courtesy */
2778 int status
= -EPERM
;
2781 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
2782 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2783 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2789 * -EACCESS could mean that the user doesn't have correct permissions
2790 * to access the mount. It could also mean that we tried to mount
2791 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2792 * existing mount programs don't handle -EACCES very well so it should
2793 * be mapped to -EPERM instead.
2795 if (status
== -EACCES
)
2800 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
2801 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
2803 int mv
= server
->nfs_client
->cl_minorversion
;
2804 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
2808 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2809 * @server: initialized nfs_server handle
2810 * @fhandle: we fill in the pseudo-fs root file handle
2811 * @info: we fill in an FSINFO struct
2813 * Returns zero on success, or a negative errno.
2815 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2816 struct nfs_fsinfo
*info
)
2820 status
= nfs4_lookup_root(server
, fhandle
, info
);
2821 if ((status
== -NFS4ERR_WRONGSEC
) &&
2822 !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2823 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
2826 status
= nfs4_server_capabilities(server
, fhandle
);
2828 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2830 return nfs4_map_errors(status
);
2833 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
2834 struct nfs_fsinfo
*info
)
2837 struct nfs_fattr
*fattr
= info
->fattr
;
2838 struct nfs4_label
*label
= NULL
;
2840 error
= nfs4_server_capabilities(server
, mntfh
);
2842 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
2846 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
2848 return PTR_ERR(label
);
2850 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
2852 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
2853 goto err_free_label
;
2856 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
2857 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
2858 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
2861 nfs4_label_free(label
);
2867 * Get locations and (maybe) other attributes of a referral.
2868 * Note that we'll actually follow the referral later when
2869 * we detect fsid mismatch in inode revalidation
2871 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
2872 const struct qstr
*name
, struct nfs_fattr
*fattr
,
2873 struct nfs_fh
*fhandle
)
2875 int status
= -ENOMEM
;
2876 struct page
*page
= NULL
;
2877 struct nfs4_fs_locations
*locations
= NULL
;
2879 page
= alloc_page(GFP_KERNEL
);
2882 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2883 if (locations
== NULL
)
2886 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
2889 /* Make sure server returned a different fsid for the referral */
2890 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2891 dprintk("%s: server did not return a different fsid for"
2892 " a referral at %s\n", __func__
, name
->name
);
2896 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2897 nfs_fixup_referral_attributes(&locations
->fattr
);
2899 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2900 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2901 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2909 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2910 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2912 struct nfs4_getattr_arg args
= {
2914 .bitmask
= server
->attr_bitmask
,
2916 struct nfs4_getattr_res res
= {
2921 struct rpc_message msg
= {
2922 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2927 args
.bitmask
= nfs4_bitmask(server
, label
);
2929 nfs_fattr_init(fattr
);
2930 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2933 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2934 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2936 struct nfs4_exception exception
= { };
2939 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
2940 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
2941 err
= nfs4_handle_exception(server
, err
,
2943 } while (exception
.retry
);
2948 * The file is not closed if it is opened due to the a request to change
2949 * the size of the file. The open call will not be needed once the
2950 * VFS layer lookup-intents are implemented.
2952 * Close is called when the inode is destroyed.
2953 * If we haven't opened the file for O_WRONLY, we
2954 * need to in the size_change case to obtain a stateid.
2957 * Because OPEN is always done by name in nfsv4, it is
2958 * possible that we opened a different file by the same
2959 * name. We can recognize this race condition, but we
2960 * can't do anything about it besides returning an error.
2962 * This will be fixed with VFS changes (lookup-intent).
2965 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2966 struct iattr
*sattr
)
2968 struct inode
*inode
= dentry
->d_inode
;
2969 struct rpc_cred
*cred
= NULL
;
2970 struct nfs4_state
*state
= NULL
;
2971 struct nfs4_label
*label
= NULL
;
2974 if (pnfs_ld_layoutret_on_setattr(inode
))
2975 pnfs_commit_and_return_layout(inode
);
2977 nfs_fattr_init(fattr
);
2979 /* Deal with open(O_TRUNC) */
2980 if (sattr
->ia_valid
& ATTR_OPEN
)
2981 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
2983 /* Optimization: if the end result is no change, don't RPC */
2984 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
2987 /* Search for an existing open(O_WRITE) file */
2988 if (sattr
->ia_valid
& ATTR_FILE
) {
2989 struct nfs_open_context
*ctx
;
2991 ctx
= nfs_file_open_context(sattr
->ia_file
);
2998 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
3000 return PTR_ERR(label
);
3002 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
3004 nfs_setattr_update_inode(inode
, sattr
);
3005 nfs_setsecurity(inode
, fattr
, label
);
3007 nfs4_label_free(label
);
3011 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
3012 const struct qstr
*name
, struct nfs_fh
*fhandle
,
3013 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3015 struct nfs_server
*server
= NFS_SERVER(dir
);
3017 struct nfs4_lookup_arg args
= {
3018 .bitmask
= server
->attr_bitmask
,
3019 .dir_fh
= NFS_FH(dir
),
3022 struct nfs4_lookup_res res
= {
3028 struct rpc_message msg
= {
3029 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3034 args
.bitmask
= nfs4_bitmask(server
, label
);
3036 nfs_fattr_init(fattr
);
3038 dprintk("NFS call lookup %s\n", name
->name
);
3039 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3040 dprintk("NFS reply lookup: %d\n", status
);
3044 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3046 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3047 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3048 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3052 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3053 struct qstr
*name
, struct nfs_fh
*fhandle
,
3054 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3056 struct nfs4_exception exception
= { };
3057 struct rpc_clnt
*client
= *clnt
;
3060 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3061 trace_nfs4_lookup(dir
, name
, err
);
3063 case -NFS4ERR_BADNAME
:
3066 case -NFS4ERR_MOVED
:
3067 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3069 case -NFS4ERR_WRONGSEC
:
3071 if (client
!= *clnt
)
3074 client
= nfs4_create_sec_client(client
, dir
, name
);
3076 return PTR_ERR(client
);
3078 exception
.retry
= 1;
3081 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3083 } while (exception
.retry
);
3088 else if (client
!= *clnt
)
3089 rpc_shutdown_client(client
);
3094 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3095 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3096 struct nfs4_label
*label
)
3099 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3101 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3102 if (client
!= NFS_CLIENT(dir
)) {
3103 rpc_shutdown_client(client
);
3104 nfs_fixup_secinfo_attributes(fattr
);
3110 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3111 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3114 struct rpc_clnt
*client
= rpc_clone_client(NFS_CLIENT(dir
));
3116 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3118 rpc_shutdown_client(client
);
3119 return ERR_PTR(status
);
3124 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3126 struct nfs_server
*server
= NFS_SERVER(inode
);
3127 struct nfs4_accessargs args
= {
3128 .fh
= NFS_FH(inode
),
3129 .bitmask
= server
->cache_consistency_bitmask
,
3131 struct nfs4_accessres res
= {
3134 struct rpc_message msg
= {
3135 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3138 .rpc_cred
= entry
->cred
,
3140 int mode
= entry
->mask
;
3144 * Determine which access bits we want to ask for...
3146 if (mode
& MAY_READ
)
3147 args
.access
|= NFS4_ACCESS_READ
;
3148 if (S_ISDIR(inode
->i_mode
)) {
3149 if (mode
& MAY_WRITE
)
3150 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3151 if (mode
& MAY_EXEC
)
3152 args
.access
|= NFS4_ACCESS_LOOKUP
;
3154 if (mode
& MAY_WRITE
)
3155 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3156 if (mode
& MAY_EXEC
)
3157 args
.access
|= NFS4_ACCESS_EXECUTE
;
3160 res
.fattr
= nfs_alloc_fattr();
3161 if (res
.fattr
== NULL
)
3164 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3166 nfs_access_set_mask(entry
, res
.access
);
3167 nfs_refresh_inode(inode
, res
.fattr
);
3169 nfs_free_fattr(res
.fattr
);
3173 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3175 struct nfs4_exception exception
= { };
3178 err
= _nfs4_proc_access(inode
, entry
);
3179 trace_nfs4_access(inode
, err
);
3180 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3182 } while (exception
.retry
);
3187 * TODO: For the time being, we don't try to get any attributes
3188 * along with any of the zero-copy operations READ, READDIR,
3191 * In the case of the first three, we want to put the GETATTR
3192 * after the read-type operation -- this is because it is hard
3193 * to predict the length of a GETATTR response in v4, and thus
3194 * align the READ data correctly. This means that the GETATTR
3195 * may end up partially falling into the page cache, and we should
3196 * shift it into the 'tail' of the xdr_buf before processing.
3197 * To do this efficiently, we need to know the total length
3198 * of data received, which doesn't seem to be available outside
3201 * In the case of WRITE, we also want to put the GETATTR after
3202 * the operation -- in this case because we want to make sure
3203 * we get the post-operation mtime and size.
3205 * Both of these changes to the XDR layer would in fact be quite
3206 * minor, but I decided to leave them for a subsequent patch.
3208 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3209 unsigned int pgbase
, unsigned int pglen
)
3211 struct nfs4_readlink args
= {
3212 .fh
= NFS_FH(inode
),
3217 struct nfs4_readlink_res res
;
3218 struct rpc_message msg
= {
3219 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3224 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3227 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3228 unsigned int pgbase
, unsigned int pglen
)
3230 struct nfs4_exception exception
= { };
3233 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3234 trace_nfs4_readlink(inode
, err
);
3235 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3237 } while (exception
.retry
);
3242 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3245 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3248 struct nfs4_label l
, *ilabel
= NULL
;
3249 struct nfs_open_context
*ctx
;
3250 struct nfs4_state
*state
;
3253 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3255 return PTR_ERR(ctx
);
3257 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3259 sattr
->ia_mode
&= ~current_umask();
3260 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
);
3261 if (IS_ERR(state
)) {
3262 status
= PTR_ERR(state
);
3266 nfs4_label_release_security(ilabel
);
3267 put_nfs_open_context(ctx
);
3271 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3273 struct nfs_server
*server
= NFS_SERVER(dir
);
3274 struct nfs_removeargs args
= {
3278 struct nfs_removeres res
= {
3281 struct rpc_message msg
= {
3282 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3288 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3290 update_changeattr(dir
, &res
.cinfo
);
3294 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3296 struct nfs4_exception exception
= { };
3299 err
= _nfs4_proc_remove(dir
, name
);
3300 trace_nfs4_remove(dir
, name
, err
);
3301 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3303 } while (exception
.retry
);
3307 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3309 struct nfs_server
*server
= NFS_SERVER(dir
);
3310 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3311 struct nfs_removeres
*res
= msg
->rpc_resp
;
3313 res
->server
= server
;
3314 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3315 nfs41_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3317 nfs_fattr_init(res
->dir_attr
);
3320 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3322 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3323 &data
->args
.seq_args
,
3328 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3330 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3331 struct nfs_removeres
*res
= &data
->res
;
3333 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3335 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3337 update_changeattr(dir
, &res
->cinfo
);
3341 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3343 struct nfs_server
*server
= NFS_SERVER(dir
);
3344 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3345 struct nfs_renameres
*res
= msg
->rpc_resp
;
3347 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3348 res
->server
= server
;
3349 nfs41_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3352 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3354 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3355 &data
->args
.seq_args
,
3360 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3361 struct inode
*new_dir
)
3363 struct nfs_renamedata
*data
= task
->tk_calldata
;
3364 struct nfs_renameres
*res
= &data
->res
;
3366 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3368 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3371 update_changeattr(old_dir
, &res
->old_cinfo
);
3372 update_changeattr(new_dir
, &res
->new_cinfo
);
3376 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3377 struct inode
*new_dir
, struct qstr
*new_name
)
3379 struct nfs_server
*server
= NFS_SERVER(old_dir
);
3380 struct nfs_renameargs arg
= {
3381 .old_dir
= NFS_FH(old_dir
),
3382 .new_dir
= NFS_FH(new_dir
),
3383 .old_name
= old_name
,
3384 .new_name
= new_name
,
3386 struct nfs_renameres res
= {
3389 struct rpc_message msg
= {
3390 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
3394 int status
= -ENOMEM
;
3396 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3398 update_changeattr(old_dir
, &res
.old_cinfo
);
3399 update_changeattr(new_dir
, &res
.new_cinfo
);
3404 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3405 struct inode
*new_dir
, struct qstr
*new_name
)
3407 struct nfs4_exception exception
= { };
3410 err
= _nfs4_proc_rename(old_dir
, old_name
,
3412 trace_nfs4_rename(old_dir
, old_name
, new_dir
, new_name
, err
);
3413 err
= nfs4_handle_exception(NFS_SERVER(old_dir
), err
,
3415 } while (exception
.retry
);
3419 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3421 struct nfs_server
*server
= NFS_SERVER(inode
);
3422 struct nfs4_link_arg arg
= {
3423 .fh
= NFS_FH(inode
),
3424 .dir_fh
= NFS_FH(dir
),
3426 .bitmask
= server
->attr_bitmask
,
3428 struct nfs4_link_res res
= {
3432 struct rpc_message msg
= {
3433 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3437 int status
= -ENOMEM
;
3439 res
.fattr
= nfs_alloc_fattr();
3440 if (res
.fattr
== NULL
)
3443 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3444 if (IS_ERR(res
.label
)) {
3445 status
= PTR_ERR(res
.label
);
3448 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3450 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3452 update_changeattr(dir
, &res
.cinfo
);
3453 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3455 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3459 nfs4_label_free(res
.label
);
3462 nfs_free_fattr(res
.fattr
);
3466 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3468 struct nfs4_exception exception
= { };
3471 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3472 _nfs4_proc_link(inode
, dir
, name
),
3474 } while (exception
.retry
);
3478 struct nfs4_createdata
{
3479 struct rpc_message msg
;
3480 struct nfs4_create_arg arg
;
3481 struct nfs4_create_res res
;
3483 struct nfs_fattr fattr
;
3484 struct nfs4_label
*label
;
3487 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3488 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3490 struct nfs4_createdata
*data
;
3492 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3494 struct nfs_server
*server
= NFS_SERVER(dir
);
3496 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3497 if (IS_ERR(data
->label
))
3500 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3501 data
->msg
.rpc_argp
= &data
->arg
;
3502 data
->msg
.rpc_resp
= &data
->res
;
3503 data
->arg
.dir_fh
= NFS_FH(dir
);
3504 data
->arg
.server
= server
;
3505 data
->arg
.name
= name
;
3506 data
->arg
.attrs
= sattr
;
3507 data
->arg
.ftype
= ftype
;
3508 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3509 data
->res
.server
= server
;
3510 data
->res
.fh
= &data
->fh
;
3511 data
->res
.fattr
= &data
->fattr
;
3512 data
->res
.label
= data
->label
;
3513 nfs_fattr_init(data
->res
.fattr
);
3521 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3523 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3524 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3526 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3527 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3532 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3534 nfs4_label_free(data
->label
);
3538 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3539 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3540 struct nfs4_label
*label
)
3542 struct nfs4_createdata
*data
;
3543 int status
= -ENAMETOOLONG
;
3545 if (len
> NFS4_MAXPATHLEN
)
3549 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3553 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3554 data
->arg
.u
.symlink
.pages
= &page
;
3555 data
->arg
.u
.symlink
.len
= len
;
3556 data
->arg
.label
= label
;
3558 status
= nfs4_do_create(dir
, dentry
, data
);
3560 nfs4_free_createdata(data
);
3565 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3566 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3568 struct nfs4_exception exception
= { };
3569 struct nfs4_label l
, *label
= NULL
;
3572 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3575 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3576 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3577 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3579 } while (exception
.retry
);
3581 nfs4_label_release_security(label
);
3585 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3586 struct iattr
*sattr
, struct nfs4_label
*label
)
3588 struct nfs4_createdata
*data
;
3589 int status
= -ENOMEM
;
3591 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3595 data
->arg
.label
= label
;
3596 status
= nfs4_do_create(dir
, dentry
, data
);
3598 nfs4_free_createdata(data
);
3603 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3604 struct iattr
*sattr
)
3606 struct nfs4_exception exception
= { };
3607 struct nfs4_label l
, *label
= NULL
;
3610 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3612 sattr
->ia_mode
&= ~current_umask();
3614 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3615 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3616 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3618 } while (exception
.retry
);
3619 nfs4_label_release_security(label
);
3624 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3625 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3627 struct inode
*dir
= dentry
->d_inode
;
3628 struct nfs4_readdir_arg args
= {
3633 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3636 struct nfs4_readdir_res res
;
3637 struct rpc_message msg
= {
3638 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3645 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
3646 dentry
->d_parent
->d_name
.name
,
3647 dentry
->d_name
.name
,
3648 (unsigned long long)cookie
);
3649 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3650 res
.pgbase
= args
.pgbase
;
3651 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3653 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3654 status
+= args
.pgbase
;
3657 nfs_invalidate_atime(dir
);
3659 dprintk("%s: returns %d\n", __func__
, status
);
3663 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3664 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3666 struct nfs4_exception exception
= { };
3669 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3670 pages
, count
, plus
);
3671 trace_nfs4_readdir(dentry
->d_inode
, err
);
3672 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3674 } while (exception
.retry
);
3678 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3679 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3681 struct nfs4_createdata
*data
;
3682 int mode
= sattr
->ia_mode
;
3683 int status
= -ENOMEM
;
3685 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3690 data
->arg
.ftype
= NF4FIFO
;
3691 else if (S_ISBLK(mode
)) {
3692 data
->arg
.ftype
= NF4BLK
;
3693 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3694 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3696 else if (S_ISCHR(mode
)) {
3697 data
->arg
.ftype
= NF4CHR
;
3698 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3699 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3700 } else if (!S_ISSOCK(mode
)) {
3705 data
->arg
.label
= label
;
3706 status
= nfs4_do_create(dir
, dentry
, data
);
3708 nfs4_free_createdata(data
);
3713 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3714 struct iattr
*sattr
, dev_t rdev
)
3716 struct nfs4_exception exception
= { };
3717 struct nfs4_label l
, *label
= NULL
;
3720 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3722 sattr
->ia_mode
&= ~current_umask();
3724 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3725 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3726 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3728 } while (exception
.retry
);
3730 nfs4_label_release_security(label
);
3735 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3736 struct nfs_fsstat
*fsstat
)
3738 struct nfs4_statfs_arg args
= {
3740 .bitmask
= server
->attr_bitmask
,
3742 struct nfs4_statfs_res res
= {
3745 struct rpc_message msg
= {
3746 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3751 nfs_fattr_init(fsstat
->fattr
);
3752 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3755 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3757 struct nfs4_exception exception
= { };
3760 err
= nfs4_handle_exception(server
,
3761 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3763 } while (exception
.retry
);
3767 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3768 struct nfs_fsinfo
*fsinfo
)
3770 struct nfs4_fsinfo_arg args
= {
3772 .bitmask
= server
->attr_bitmask
,
3774 struct nfs4_fsinfo_res res
= {
3777 struct rpc_message msg
= {
3778 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3783 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3786 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3788 struct nfs4_exception exception
= { };
3789 unsigned long now
= jiffies
;
3793 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3794 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
3796 struct nfs_client
*clp
= server
->nfs_client
;
3798 spin_lock(&clp
->cl_lock
);
3799 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
3800 clp
->cl_last_renewal
= now
;
3801 spin_unlock(&clp
->cl_lock
);
3804 err
= nfs4_handle_exception(server
, err
, &exception
);
3805 } while (exception
.retry
);
3809 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3813 nfs_fattr_init(fsinfo
->fattr
);
3814 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3816 /* block layout checks this! */
3817 server
->pnfs_blksize
= fsinfo
->blksize
;
3818 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
3824 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3825 struct nfs_pathconf
*pathconf
)
3827 struct nfs4_pathconf_arg args
= {
3829 .bitmask
= server
->attr_bitmask
,
3831 struct nfs4_pathconf_res res
= {
3832 .pathconf
= pathconf
,
3834 struct rpc_message msg
= {
3835 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3840 /* None of the pathconf attributes are mandatory to implement */
3841 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3842 memset(pathconf
, 0, sizeof(*pathconf
));
3846 nfs_fattr_init(pathconf
->fattr
);
3847 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3850 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3851 struct nfs_pathconf
*pathconf
)
3853 struct nfs4_exception exception
= { };
3857 err
= nfs4_handle_exception(server
,
3858 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3860 } while (exception
.retry
);
3864 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
3865 const struct nfs_open_context
*ctx
,
3866 const struct nfs_lock_context
*l_ctx
,
3869 const struct nfs_lockowner
*lockowner
= NULL
;
3872 lockowner
= &l_ctx
->lockowner
;
3873 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
3875 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
3877 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
3878 const struct nfs_open_context
*ctx
,
3879 const struct nfs_lock_context
*l_ctx
,
3882 nfs4_stateid current_stateid
;
3884 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
))
3886 return nfs4_stateid_match(stateid
, ¤t_stateid
);
3889 static bool nfs4_error_stateid_expired(int err
)
3892 case -NFS4ERR_DELEG_REVOKED
:
3893 case -NFS4ERR_ADMIN_REVOKED
:
3894 case -NFS4ERR_BAD_STATEID
:
3895 case -NFS4ERR_STALE_STATEID
:
3896 case -NFS4ERR_OLD_STATEID
:
3897 case -NFS4ERR_OPENMODE
:
3898 case -NFS4ERR_EXPIRED
:
3904 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3906 nfs_invalidate_atime(data
->header
->inode
);
3909 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3911 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
3913 trace_nfs4_read(data
, task
->tk_status
);
3914 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3915 rpc_restart_call_prepare(task
);
3919 __nfs4_read_done_cb(data
);
3920 if (task
->tk_status
> 0)
3921 renew_lease(server
, data
->timestamp
);
3925 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
3926 struct nfs_readargs
*args
)
3929 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3930 nfs4_stateid_is_current(&args
->stateid
,
3935 rpc_restart_call_prepare(task
);
3939 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3942 dprintk("--> %s\n", __func__
);
3944 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3946 if (nfs4_read_stateid_changed(task
, &data
->args
))
3948 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3949 nfs4_read_done_cb(task
, data
);
3952 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3954 data
->timestamp
= jiffies
;
3955 data
->read_done_cb
= nfs4_read_done_cb
;
3956 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3957 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
3960 static void nfs4_proc_read_rpc_prepare(struct rpc_task
*task
, struct nfs_read_data
*data
)
3962 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
3963 &data
->args
.seq_args
,
3967 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
3968 data
->args
.lock_context
, FMODE_READ
);
3971 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3973 struct inode
*inode
= data
->header
->inode
;
3975 trace_nfs4_write(data
, task
->tk_status
);
3976 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3977 rpc_restart_call_prepare(task
);
3980 if (task
->tk_status
>= 0) {
3981 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3982 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
3987 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
3988 struct nfs_writeargs
*args
)
3991 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3992 nfs4_stateid_is_current(&args
->stateid
,
3997 rpc_restart_call_prepare(task
);
4001 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
4003 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4005 if (nfs4_write_stateid_changed(task
, &data
->args
))
4007 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
4008 nfs4_write_done_cb(task
, data
);
4012 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data
*data
)
4014 const struct nfs_pgio_header
*hdr
= data
->header
;
4016 /* Don't request attributes for pNFS or O_DIRECT writes */
4017 if (data
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
4019 /* Otherwise, request attributes if and only if we don't hold
4022 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
4025 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
4027 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
4029 if (!nfs4_write_need_cache_consistency_data(data
)) {
4030 data
->args
.bitmask
= NULL
;
4031 data
->res
.fattr
= NULL
;
4033 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4035 if (!data
->write_done_cb
)
4036 data
->write_done_cb
= nfs4_write_done_cb
;
4037 data
->res
.server
= server
;
4038 data
->timestamp
= jiffies
;
4040 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4041 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4044 static void nfs4_proc_write_rpc_prepare(struct rpc_task
*task
, struct nfs_write_data
*data
)
4046 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
4047 &data
->args
.seq_args
,
4051 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
4052 data
->args
.lock_context
, FMODE_WRITE
);
4055 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4057 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4058 &data
->args
.seq_args
,
4063 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4065 struct inode
*inode
= data
->inode
;
4067 trace_nfs4_commit(data
, task
->tk_status
);
4068 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
4069 rpc_restart_call_prepare(task
);
4075 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4077 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4079 return data
->commit_done_cb(task
, data
);
4082 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4084 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4086 if (data
->commit_done_cb
== NULL
)
4087 data
->commit_done_cb
= nfs4_commit_done_cb
;
4088 data
->res
.server
= server
;
4089 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4090 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4093 struct nfs4_renewdata
{
4094 struct nfs_client
*client
;
4095 unsigned long timestamp
;
4099 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4100 * standalone procedure for queueing an asynchronous RENEW.
4102 static void nfs4_renew_release(void *calldata
)
4104 struct nfs4_renewdata
*data
= calldata
;
4105 struct nfs_client
*clp
= data
->client
;
4107 if (atomic_read(&clp
->cl_count
) > 1)
4108 nfs4_schedule_state_renewal(clp
);
4109 nfs_put_client(clp
);
4113 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4115 struct nfs4_renewdata
*data
= calldata
;
4116 struct nfs_client
*clp
= data
->client
;
4117 unsigned long timestamp
= data
->timestamp
;
4119 trace_nfs4_renew_async(clp
, task
->tk_status
);
4120 if (task
->tk_status
< 0) {
4121 /* Unless we're shutting down, schedule state recovery! */
4122 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4124 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4125 nfs4_schedule_lease_recovery(clp
);
4128 nfs4_schedule_path_down_recovery(clp
);
4130 do_renew_lease(clp
, timestamp
);
4133 static const struct rpc_call_ops nfs4_renew_ops
= {
4134 .rpc_call_done
= nfs4_renew_done
,
4135 .rpc_release
= nfs4_renew_release
,
4138 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4140 struct rpc_message msg
= {
4141 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4145 struct nfs4_renewdata
*data
;
4147 if (renew_flags
== 0)
4149 if (!atomic_inc_not_zero(&clp
->cl_count
))
4151 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4155 data
->timestamp
= jiffies
;
4156 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4157 &nfs4_renew_ops
, data
);
4160 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4162 struct rpc_message msg
= {
4163 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4167 unsigned long now
= jiffies
;
4170 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4173 do_renew_lease(clp
, now
);
4177 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4179 return (server
->caps
& NFS_CAP_ACLS
)
4180 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
4181 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
4184 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4185 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4188 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4190 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4191 struct page
**pages
, unsigned int *pgbase
)
4193 struct page
*newpage
, **spages
;
4199 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4200 newpage
= alloc_page(GFP_KERNEL
);
4202 if (newpage
== NULL
)
4204 memcpy(page_address(newpage
), buf
, len
);
4209 } while (buflen
!= 0);
4215 __free_page(spages
[rc
-1]);
4219 struct nfs4_cached_acl
{
4225 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4227 struct nfs_inode
*nfsi
= NFS_I(inode
);
4229 spin_lock(&inode
->i_lock
);
4230 kfree(nfsi
->nfs4_acl
);
4231 nfsi
->nfs4_acl
= acl
;
4232 spin_unlock(&inode
->i_lock
);
4235 static void nfs4_zap_acl_attr(struct inode
*inode
)
4237 nfs4_set_cached_acl(inode
, NULL
);
4240 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4242 struct nfs_inode
*nfsi
= NFS_I(inode
);
4243 struct nfs4_cached_acl
*acl
;
4246 spin_lock(&inode
->i_lock
);
4247 acl
= nfsi
->nfs4_acl
;
4250 if (buf
== NULL
) /* user is just asking for length */
4252 if (acl
->cached
== 0)
4254 ret
= -ERANGE
; /* see getxattr(2) man page */
4255 if (acl
->len
> buflen
)
4257 memcpy(buf
, acl
->data
, acl
->len
);
4261 spin_unlock(&inode
->i_lock
);
4265 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4267 struct nfs4_cached_acl
*acl
;
4268 size_t buflen
= sizeof(*acl
) + acl_len
;
4270 if (buflen
<= PAGE_SIZE
) {
4271 acl
= kmalloc(buflen
, GFP_KERNEL
);
4275 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4277 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4284 nfs4_set_cached_acl(inode
, acl
);
4288 * The getxattr API returns the required buffer length when called with a
4289 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4290 * the required buf. On a NULL buf, we send a page of data to the server
4291 * guessing that the ACL request can be serviced by a page. If so, we cache
4292 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4293 * the cache. If not so, we throw away the page, and cache the required
4294 * length. The next getxattr call will then produce another round trip to
4295 * the server, this time with the input buf of the required size.
4297 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4299 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4300 struct nfs_getaclargs args
= {
4301 .fh
= NFS_FH(inode
),
4305 struct nfs_getaclres res
= {
4308 struct rpc_message msg
= {
4309 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4313 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4314 int ret
= -ENOMEM
, i
;
4316 /* As long as we're doing a round trip to the server anyway,
4317 * let's be prepared for a page of acl data. */
4320 if (npages
> ARRAY_SIZE(pages
))
4323 for (i
= 0; i
< npages
; i
++) {
4324 pages
[i
] = alloc_page(GFP_KERNEL
);
4329 /* for decoding across pages */
4330 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4331 if (!res
.acl_scratch
)
4334 args
.acl_len
= npages
* PAGE_SIZE
;
4335 args
.acl_pgbase
= 0;
4337 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4338 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4339 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4340 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4344 /* Handle the case where the passed-in buffer is too short */
4345 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4346 /* Did the user only issue a request for the acl length? */
4352 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4354 if (res
.acl_len
> buflen
) {
4358 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4363 for (i
= 0; i
< npages
; i
++)
4365 __free_page(pages
[i
]);
4366 if (res
.acl_scratch
)
4367 __free_page(res
.acl_scratch
);
4371 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4373 struct nfs4_exception exception
= { };
4376 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4377 trace_nfs4_get_acl(inode
, ret
);
4380 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4381 } while (exception
.retry
);
4385 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4387 struct nfs_server
*server
= NFS_SERVER(inode
);
4390 if (!nfs4_server_supports_acls(server
))
4392 ret
= nfs_revalidate_inode(server
, inode
);
4395 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4396 nfs_zap_acl_cache(inode
);
4397 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4399 /* -ENOENT is returned if there is no ACL or if there is an ACL
4400 * but no cached acl data, just the acl length */
4402 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4405 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4407 struct nfs_server
*server
= NFS_SERVER(inode
);
4408 struct page
*pages
[NFS4ACL_MAXPAGES
];
4409 struct nfs_setaclargs arg
= {
4410 .fh
= NFS_FH(inode
),
4414 struct nfs_setaclres res
;
4415 struct rpc_message msg
= {
4416 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4420 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4423 if (!nfs4_server_supports_acls(server
))
4425 if (npages
> ARRAY_SIZE(pages
))
4427 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4430 nfs4_inode_return_delegation(inode
);
4431 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4434 * Free each page after tx, so the only ref left is
4435 * held by the network stack
4438 put_page(pages
[i
-1]);
4441 * Acl update can result in inode attribute update.
4442 * so mark the attribute cache invalid.
4444 spin_lock(&inode
->i_lock
);
4445 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4446 spin_unlock(&inode
->i_lock
);
4447 nfs_access_zap_cache(inode
);
4448 nfs_zap_acl_cache(inode
);
4452 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4454 struct nfs4_exception exception
= { };
4457 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4458 trace_nfs4_set_acl(inode
, err
);
4459 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4461 } while (exception
.retry
);
4465 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4466 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4469 struct nfs_server
*server
= NFS_SERVER(inode
);
4470 struct nfs_fattr fattr
;
4471 struct nfs4_label label
= {0, 0, buflen
, buf
};
4473 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4474 struct nfs4_getattr_arg args
= {
4475 .fh
= NFS_FH(inode
),
4478 struct nfs4_getattr_res res
= {
4483 struct rpc_message msg
= {
4484 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4490 nfs_fattr_init(&fattr
);
4492 ret
= rpc_call_sync(server
->client
, &msg
, 0);
4495 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4497 if (buflen
< label
.len
)
4502 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4505 struct nfs4_exception exception
= { };
4508 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4512 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4513 trace_nfs4_get_security_label(inode
, err
);
4514 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4516 } while (exception
.retry
);
4520 static int _nfs4_do_set_security_label(struct inode
*inode
,
4521 struct nfs4_label
*ilabel
,
4522 struct nfs_fattr
*fattr
,
4523 struct nfs4_label
*olabel
)
4526 struct iattr sattr
= {0};
4527 struct nfs_server
*server
= NFS_SERVER(inode
);
4528 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4529 struct nfs_setattrargs args
= {
4530 .fh
= NFS_FH(inode
),
4536 struct nfs_setattrres res
= {
4541 struct rpc_message msg
= {
4542 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4548 nfs4_stateid_copy(&args
.stateid
, &zero_stateid
);
4550 status
= rpc_call_sync(server
->client
, &msg
, 0);
4552 dprintk("%s failed: %d\n", __func__
, status
);
4557 static int nfs4_do_set_security_label(struct inode
*inode
,
4558 struct nfs4_label
*ilabel
,
4559 struct nfs_fattr
*fattr
,
4560 struct nfs4_label
*olabel
)
4562 struct nfs4_exception exception
= { };
4566 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4568 trace_nfs4_set_security_label(inode
, err
);
4569 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4571 } while (exception
.retry
);
4576 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4578 struct nfs4_label ilabel
, *olabel
= NULL
;
4579 struct nfs_fattr fattr
;
4580 struct rpc_cred
*cred
;
4581 struct inode
*inode
= dentry
->d_inode
;
4584 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4587 nfs_fattr_init(&fattr
);
4591 ilabel
.label
= (char *)buf
;
4592 ilabel
.len
= buflen
;
4594 cred
= rpc_lookup_cred();
4596 return PTR_ERR(cred
);
4598 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4599 if (IS_ERR(olabel
)) {
4600 status
= -PTR_ERR(olabel
);
4604 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4606 nfs_setsecurity(inode
, &fattr
, olabel
);
4608 nfs4_label_free(olabel
);
4613 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4617 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
4619 struct nfs_client
*clp
= server
->nfs_client
;
4621 if (task
->tk_status
>= 0)
4623 switch(task
->tk_status
) {
4624 case -NFS4ERR_DELEG_REVOKED
:
4625 case -NFS4ERR_ADMIN_REVOKED
:
4626 case -NFS4ERR_BAD_STATEID
:
4629 nfs_remove_bad_delegation(state
->inode
);
4630 case -NFS4ERR_OPENMODE
:
4633 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4634 goto stateid_invalid
;
4635 goto wait_on_recovery
;
4636 case -NFS4ERR_EXPIRED
:
4637 if (state
!= NULL
) {
4638 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4639 goto stateid_invalid
;
4641 case -NFS4ERR_STALE_STATEID
:
4642 case -NFS4ERR_STALE_CLIENTID
:
4643 nfs4_schedule_lease_recovery(clp
);
4644 goto wait_on_recovery
;
4645 #if defined(CONFIG_NFS_V4_1)
4646 case -NFS4ERR_BADSESSION
:
4647 case -NFS4ERR_BADSLOT
:
4648 case -NFS4ERR_BAD_HIGH_SLOT
:
4649 case -NFS4ERR_DEADSESSION
:
4650 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4651 case -NFS4ERR_SEQ_FALSE_RETRY
:
4652 case -NFS4ERR_SEQ_MISORDERED
:
4653 dprintk("%s ERROR %d, Reset session\n", __func__
,
4655 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4656 task
->tk_status
= 0;
4658 #endif /* CONFIG_NFS_V4_1 */
4659 case -NFS4ERR_DELAY
:
4660 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4661 case -NFS4ERR_GRACE
:
4662 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4663 task
->tk_status
= 0;
4665 case -NFS4ERR_RETRY_UNCACHED_REP
:
4666 case -NFS4ERR_OLD_STATEID
:
4667 task
->tk_status
= 0;
4670 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4673 task
->tk_status
= -EIO
;
4676 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4677 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4678 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4679 task
->tk_status
= 0;
4683 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4684 nfs4_verifier
*bootverf
)
4688 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4689 /* An impossible timestamp guarantees this value
4690 * will never match a generated boot time. */
4692 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4694 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4695 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4696 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4698 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4702 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4703 char *buf
, size_t len
)
4705 unsigned int result
;
4708 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4710 rpc_peeraddr2str(clp
->cl_rpcclient
,
4712 rpc_peeraddr2str(clp
->cl_rpcclient
,
4713 RPC_DISPLAY_PROTO
));
4719 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4720 char *buf
, size_t len
)
4722 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4724 if (nfs4_client_id_uniquifier
[0] != '\0')
4725 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4726 clp
->rpc_ops
->version
,
4727 clp
->cl_minorversion
,
4728 nfs4_client_id_uniquifier
,
4730 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4731 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4736 * nfs4_proc_setclientid - Negotiate client ID
4737 * @clp: state data structure
4738 * @program: RPC program for NFSv4 callback service
4739 * @port: IP port number for NFS4 callback service
4740 * @cred: RPC credential to use for this call
4741 * @res: where to place the result
4743 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4745 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4746 unsigned short port
, struct rpc_cred
*cred
,
4747 struct nfs4_setclientid_res
*res
)
4749 nfs4_verifier sc_verifier
;
4750 struct nfs4_setclientid setclientid
= {
4751 .sc_verifier
= &sc_verifier
,
4753 .sc_cb_ident
= clp
->cl_cb_ident
,
4755 struct rpc_message msg
= {
4756 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
4757 .rpc_argp
= &setclientid
,
4763 /* nfs_client_id4 */
4764 nfs4_init_boot_verifier(clp
, &sc_verifier
);
4765 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
4766 setclientid
.sc_name_len
=
4767 nfs4_init_uniform_client_string(clp
,
4768 setclientid
.sc_name
,
4769 sizeof(setclientid
.sc_name
));
4771 setclientid
.sc_name_len
=
4772 nfs4_init_nonuniform_client_string(clp
,
4773 setclientid
.sc_name
,
4774 sizeof(setclientid
.sc_name
));
4777 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
4778 sizeof(setclientid
.sc_netid
), "%s",
4779 rpc_peeraddr2str(clp
->cl_rpcclient
,
4780 RPC_DISPLAY_NETID
));
4782 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
4783 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
4784 clp
->cl_ipaddr
, port
>> 8, port
& 255);
4786 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4787 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4788 setclientid
.sc_name_len
, setclientid
.sc_name
);
4789 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4790 trace_nfs4_setclientid(clp
, status
);
4791 dprintk("NFS reply setclientid: %d\n", status
);
4796 * nfs4_proc_setclientid_confirm - Confirm client ID
4797 * @clp: state data structure
4798 * @res: result of a previous SETCLIENTID
4799 * @cred: RPC credential to use for this call
4801 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4803 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
4804 struct nfs4_setclientid_res
*arg
,
4805 struct rpc_cred
*cred
)
4807 struct rpc_message msg
= {
4808 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
4814 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4815 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4817 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4818 trace_nfs4_setclientid_confirm(clp
, status
);
4819 dprintk("NFS reply setclientid_confirm: %d\n", status
);
4823 struct nfs4_delegreturndata
{
4824 struct nfs4_delegreturnargs args
;
4825 struct nfs4_delegreturnres res
;
4827 nfs4_stateid stateid
;
4828 unsigned long timestamp
;
4829 struct nfs_fattr fattr
;
4833 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
4835 struct nfs4_delegreturndata
*data
= calldata
;
4837 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4840 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
4841 switch (task
->tk_status
) {
4842 case -NFS4ERR_STALE_STATEID
:
4843 case -NFS4ERR_EXPIRED
:
4845 renew_lease(data
->res
.server
, data
->timestamp
);
4848 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
4850 rpc_restart_call_prepare(task
);
4854 data
->rpc_status
= task
->tk_status
;
4857 static void nfs4_delegreturn_release(void *calldata
)
4862 #if defined(CONFIG_NFS_V4_1)
4863 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
4865 struct nfs4_delegreturndata
*d_data
;
4867 d_data
= (struct nfs4_delegreturndata
*)data
;
4869 nfs4_setup_sequence(d_data
->res
.server
,
4870 &d_data
->args
.seq_args
,
4871 &d_data
->res
.seq_res
,
4874 #endif /* CONFIG_NFS_V4_1 */
4876 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
4877 #if defined(CONFIG_NFS_V4_1)
4878 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
4879 #endif /* CONFIG_NFS_V4_1 */
4880 .rpc_call_done
= nfs4_delegreturn_done
,
4881 .rpc_release
= nfs4_delegreturn_release
,
4884 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4886 struct nfs4_delegreturndata
*data
;
4887 struct nfs_server
*server
= NFS_SERVER(inode
);
4888 struct rpc_task
*task
;
4889 struct rpc_message msg
= {
4890 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
4893 struct rpc_task_setup task_setup_data
= {
4894 .rpc_client
= server
->client
,
4895 .rpc_message
= &msg
,
4896 .callback_ops
= &nfs4_delegreturn_ops
,
4897 .flags
= RPC_TASK_ASYNC
,
4901 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
4904 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4905 data
->args
.fhandle
= &data
->fh
;
4906 data
->args
.stateid
= &data
->stateid
;
4907 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4908 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
4909 nfs4_stateid_copy(&data
->stateid
, stateid
);
4910 data
->res
.fattr
= &data
->fattr
;
4911 data
->res
.server
= server
;
4912 nfs_fattr_init(data
->res
.fattr
);
4913 data
->timestamp
= jiffies
;
4914 data
->rpc_status
= 0;
4916 task_setup_data
.callback_data
= data
;
4917 msg
.rpc_argp
= &data
->args
;
4918 msg
.rpc_resp
= &data
->res
;
4919 task
= rpc_run_task(&task_setup_data
);
4921 return PTR_ERR(task
);
4924 status
= nfs4_wait_for_completion_rpc_task(task
);
4927 status
= data
->rpc_status
;
4929 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
4931 nfs_refresh_inode(inode
, &data
->fattr
);
4937 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4939 struct nfs_server
*server
= NFS_SERVER(inode
);
4940 struct nfs4_exception exception
= { };
4943 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
4944 trace_nfs4_delegreturn(inode
, err
);
4946 case -NFS4ERR_STALE_STATEID
:
4947 case -NFS4ERR_EXPIRED
:
4951 err
= nfs4_handle_exception(server
, err
, &exception
);
4952 } while (exception
.retry
);
4956 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4957 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4960 * sleep, with exponential backoff, and retry the LOCK operation.
4962 static unsigned long
4963 nfs4_set_lock_task_retry(unsigned long timeout
)
4965 freezable_schedule_timeout_killable_unsafe(timeout
);
4967 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
4968 return NFS4_LOCK_MAXTIMEOUT
;
4972 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4974 struct inode
*inode
= state
->inode
;
4975 struct nfs_server
*server
= NFS_SERVER(inode
);
4976 struct nfs_client
*clp
= server
->nfs_client
;
4977 struct nfs_lockt_args arg
= {
4978 .fh
= NFS_FH(inode
),
4981 struct nfs_lockt_res res
= {
4984 struct rpc_message msg
= {
4985 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
4988 .rpc_cred
= state
->owner
->so_cred
,
4990 struct nfs4_lock_state
*lsp
;
4993 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
4994 status
= nfs4_set_lock_state(state
, request
);
4997 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4998 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
4999 arg
.lock_owner
.s_dev
= server
->s_dev
;
5000 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5003 request
->fl_type
= F_UNLCK
;
5005 case -NFS4ERR_DENIED
:
5008 request
->fl_ops
->fl_release_private(request
);
5013 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5015 struct nfs4_exception exception
= { };
5019 err
= _nfs4_proc_getlk(state
, cmd
, request
);
5020 trace_nfs4_get_lock(request
, state
, cmd
, err
);
5021 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
5023 } while (exception
.retry
);
5027 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5030 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5032 res
= posix_lock_file_wait(file
, fl
);
5035 res
= flock_lock_file_wait(file
, fl
);
5043 struct nfs4_unlockdata
{
5044 struct nfs_locku_args arg
;
5045 struct nfs_locku_res res
;
5046 struct nfs4_lock_state
*lsp
;
5047 struct nfs_open_context
*ctx
;
5048 struct file_lock fl
;
5049 const struct nfs_server
*server
;
5050 unsigned long timestamp
;
5053 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5054 struct nfs_open_context
*ctx
,
5055 struct nfs4_lock_state
*lsp
,
5056 struct nfs_seqid
*seqid
)
5058 struct nfs4_unlockdata
*p
;
5059 struct inode
*inode
= lsp
->ls_state
->inode
;
5061 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5064 p
->arg
.fh
= NFS_FH(inode
);
5066 p
->arg
.seqid
= seqid
;
5067 p
->res
.seqid
= seqid
;
5068 p
->arg
.stateid
= &lsp
->ls_stateid
;
5070 atomic_inc(&lsp
->ls_count
);
5071 /* Ensure we don't close file until we're done freeing locks! */
5072 p
->ctx
= get_nfs_open_context(ctx
);
5073 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5074 p
->server
= NFS_SERVER(inode
);
5078 static void nfs4_locku_release_calldata(void *data
)
5080 struct nfs4_unlockdata
*calldata
= data
;
5081 nfs_free_seqid(calldata
->arg
.seqid
);
5082 nfs4_put_lock_state(calldata
->lsp
);
5083 put_nfs_open_context(calldata
->ctx
);
5087 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5089 struct nfs4_unlockdata
*calldata
= data
;
5091 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5093 switch (task
->tk_status
) {
5095 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5096 &calldata
->res
.stateid
);
5097 renew_lease(calldata
->server
, calldata
->timestamp
);
5099 case -NFS4ERR_BAD_STATEID
:
5100 case -NFS4ERR_OLD_STATEID
:
5101 case -NFS4ERR_STALE_STATEID
:
5102 case -NFS4ERR_EXPIRED
:
5105 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
5106 rpc_restart_call_prepare(task
);
5108 nfs_release_seqid(calldata
->arg
.seqid
);
5111 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5113 struct nfs4_unlockdata
*calldata
= data
;
5115 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5117 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5118 /* Note: exit _without_ running nfs4_locku_done */
5121 calldata
->timestamp
= jiffies
;
5122 if (nfs4_setup_sequence(calldata
->server
,
5123 &calldata
->arg
.seq_args
,
5124 &calldata
->res
.seq_res
,
5126 nfs_release_seqid(calldata
->arg
.seqid
);
5129 task
->tk_action
= NULL
;
5131 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5134 static const struct rpc_call_ops nfs4_locku_ops
= {
5135 .rpc_call_prepare
= nfs4_locku_prepare
,
5136 .rpc_call_done
= nfs4_locku_done
,
5137 .rpc_release
= nfs4_locku_release_calldata
,
5140 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5141 struct nfs_open_context
*ctx
,
5142 struct nfs4_lock_state
*lsp
,
5143 struct nfs_seqid
*seqid
)
5145 struct nfs4_unlockdata
*data
;
5146 struct rpc_message msg
= {
5147 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5148 .rpc_cred
= ctx
->cred
,
5150 struct rpc_task_setup task_setup_data
= {
5151 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5152 .rpc_message
= &msg
,
5153 .callback_ops
= &nfs4_locku_ops
,
5154 .workqueue
= nfsiod_workqueue
,
5155 .flags
= RPC_TASK_ASYNC
,
5158 /* Ensure this is an unlock - when canceling a lock, the
5159 * canceled lock is passed in, and it won't be an unlock.
5161 fl
->fl_type
= F_UNLCK
;
5163 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5165 nfs_free_seqid(seqid
);
5166 return ERR_PTR(-ENOMEM
);
5169 nfs41_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5170 msg
.rpc_argp
= &data
->arg
;
5171 msg
.rpc_resp
= &data
->res
;
5172 task_setup_data
.callback_data
= data
;
5173 return rpc_run_task(&task_setup_data
);
5176 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5178 struct inode
*inode
= state
->inode
;
5179 struct nfs4_state_owner
*sp
= state
->owner
;
5180 struct nfs_inode
*nfsi
= NFS_I(inode
);
5181 struct nfs_seqid
*seqid
;
5182 struct nfs4_lock_state
*lsp
;
5183 struct rpc_task
*task
;
5185 unsigned char fl_flags
= request
->fl_flags
;
5187 status
= nfs4_set_lock_state(state
, request
);
5188 /* Unlock _before_ we do the RPC call */
5189 request
->fl_flags
|= FL_EXISTS
;
5190 /* Exclude nfs_delegation_claim_locks() */
5191 mutex_lock(&sp
->so_delegreturn_mutex
);
5192 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5193 down_read(&nfsi
->rwsem
);
5194 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5195 up_read(&nfsi
->rwsem
);
5196 mutex_unlock(&sp
->so_delegreturn_mutex
);
5199 up_read(&nfsi
->rwsem
);
5200 mutex_unlock(&sp
->so_delegreturn_mutex
);
5203 /* Is this a delegated lock? */
5204 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5205 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5207 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5211 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5212 status
= PTR_ERR(task
);
5215 status
= nfs4_wait_for_completion_rpc_task(task
);
5218 request
->fl_flags
= fl_flags
;
5219 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5223 struct nfs4_lockdata
{
5224 struct nfs_lock_args arg
;
5225 struct nfs_lock_res res
;
5226 struct nfs4_lock_state
*lsp
;
5227 struct nfs_open_context
*ctx
;
5228 struct file_lock fl
;
5229 unsigned long timestamp
;
5232 struct nfs_server
*server
;
5235 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5236 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5239 struct nfs4_lockdata
*p
;
5240 struct inode
*inode
= lsp
->ls_state
->inode
;
5241 struct nfs_server
*server
= NFS_SERVER(inode
);
5243 p
= kzalloc(sizeof(*p
), gfp_mask
);
5247 p
->arg
.fh
= NFS_FH(inode
);
5249 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5250 if (p
->arg
.open_seqid
== NULL
)
5252 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5253 if (p
->arg
.lock_seqid
== NULL
)
5254 goto out_free_seqid
;
5255 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5256 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5257 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5258 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5259 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5262 atomic_inc(&lsp
->ls_count
);
5263 p
->ctx
= get_nfs_open_context(ctx
);
5264 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5267 nfs_free_seqid(p
->arg
.open_seqid
);
5273 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5275 struct nfs4_lockdata
*data
= calldata
;
5276 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5278 dprintk("%s: begin!\n", __func__
);
5279 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5281 /* Do we need to do an open_to_lock_owner? */
5282 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5283 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5284 goto out_release_lock_seqid
;
5286 data
->arg
.open_stateid
= &state
->open_stateid
;
5287 data
->arg
.new_lock_owner
= 1;
5288 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5290 data
->arg
.new_lock_owner
= 0;
5291 if (!nfs4_valid_open_stateid(state
)) {
5292 data
->rpc_status
= -EBADF
;
5293 task
->tk_action
= NULL
;
5294 goto out_release_open_seqid
;
5296 data
->timestamp
= jiffies
;
5297 if (nfs4_setup_sequence(data
->server
,
5298 &data
->arg
.seq_args
,
5302 out_release_open_seqid
:
5303 nfs_release_seqid(data
->arg
.open_seqid
);
5304 out_release_lock_seqid
:
5305 nfs_release_seqid(data
->arg
.lock_seqid
);
5307 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5308 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5311 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5313 struct nfs4_lockdata
*data
= calldata
;
5315 dprintk("%s: begin!\n", __func__
);
5317 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5320 data
->rpc_status
= task
->tk_status
;
5321 if (data
->arg
.new_lock_owner
!= 0) {
5322 if (data
->rpc_status
== 0)
5323 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5327 if (data
->rpc_status
== 0) {
5328 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5329 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5330 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5333 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5336 static void nfs4_lock_release(void *calldata
)
5338 struct nfs4_lockdata
*data
= calldata
;
5340 dprintk("%s: begin!\n", __func__
);
5341 nfs_free_seqid(data
->arg
.open_seqid
);
5342 if (data
->cancelled
!= 0) {
5343 struct rpc_task
*task
;
5344 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5345 data
->arg
.lock_seqid
);
5347 rpc_put_task_async(task
);
5348 dprintk("%s: cancelling lock!\n", __func__
);
5350 nfs_free_seqid(data
->arg
.lock_seqid
);
5351 nfs4_put_lock_state(data
->lsp
);
5352 put_nfs_open_context(data
->ctx
);
5354 dprintk("%s: done!\n", __func__
);
5357 static const struct rpc_call_ops nfs4_lock_ops
= {
5358 .rpc_call_prepare
= nfs4_lock_prepare
,
5359 .rpc_call_done
= nfs4_lock_done
,
5360 .rpc_release
= nfs4_lock_release
,
5363 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5366 case -NFS4ERR_ADMIN_REVOKED
:
5367 case -NFS4ERR_BAD_STATEID
:
5368 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5369 if (new_lock_owner
!= 0 ||
5370 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5371 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5373 case -NFS4ERR_STALE_STATEID
:
5374 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5375 case -NFS4ERR_EXPIRED
:
5376 nfs4_schedule_lease_recovery(server
->nfs_client
);
5380 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5382 struct nfs4_lockdata
*data
;
5383 struct rpc_task
*task
;
5384 struct rpc_message msg
= {
5385 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5386 .rpc_cred
= state
->owner
->so_cred
,
5388 struct rpc_task_setup task_setup_data
= {
5389 .rpc_client
= NFS_CLIENT(state
->inode
),
5390 .rpc_message
= &msg
,
5391 .callback_ops
= &nfs4_lock_ops
,
5392 .workqueue
= nfsiod_workqueue
,
5393 .flags
= RPC_TASK_ASYNC
,
5397 dprintk("%s: begin!\n", __func__
);
5398 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5399 fl
->fl_u
.nfs4_fl
.owner
,
5400 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5404 data
->arg
.block
= 1;
5405 nfs41_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5406 msg
.rpc_argp
= &data
->arg
;
5407 msg
.rpc_resp
= &data
->res
;
5408 task_setup_data
.callback_data
= data
;
5409 if (recovery_type
> NFS_LOCK_NEW
) {
5410 if (recovery_type
== NFS_LOCK_RECLAIM
)
5411 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5412 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5414 task
= rpc_run_task(&task_setup_data
);
5416 return PTR_ERR(task
);
5417 ret
= nfs4_wait_for_completion_rpc_task(task
);
5419 ret
= data
->rpc_status
;
5421 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5422 data
->arg
.new_lock_owner
, ret
);
5424 data
->cancelled
= 1;
5426 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5430 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5432 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5433 struct nfs4_exception exception
= {
5434 .inode
= state
->inode
,
5439 /* Cache the lock if possible... */
5440 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5442 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5443 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5444 if (err
!= -NFS4ERR_DELAY
)
5446 nfs4_handle_exception(server
, err
, &exception
);
5447 } while (exception
.retry
);
5451 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5453 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5454 struct nfs4_exception exception
= {
5455 .inode
= state
->inode
,
5459 err
= nfs4_set_lock_state(state
, request
);
5463 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5465 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5466 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5470 case -NFS4ERR_GRACE
:
5471 case -NFS4ERR_DELAY
:
5472 nfs4_handle_exception(server
, err
, &exception
);
5475 } while (exception
.retry
);
5480 #if defined(CONFIG_NFS_V4_1)
5482 * nfs41_check_expired_locks - possibly free a lock stateid
5484 * @state: NFSv4 state for an inode
5486 * Returns NFS_OK if recovery for this stateid is now finished.
5487 * Otherwise a negative NFS4ERR value is returned.
5489 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5491 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5492 struct nfs4_lock_state
*lsp
;
5493 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5495 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5496 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5497 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5499 status
= nfs41_test_stateid(server
,
5502 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
5503 if (status
!= NFS_OK
) {
5504 /* Free the stateid unless the server
5505 * informs us the stateid is unrecognized. */
5506 if (status
!= -NFS4ERR_BAD_STATEID
)
5507 nfs41_free_stateid(server
,
5510 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5519 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5521 int status
= NFS_OK
;
5523 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5524 status
= nfs41_check_expired_locks(state
);
5525 if (status
!= NFS_OK
)
5526 status
= nfs4_lock_expired(state
, request
);
5531 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5533 struct nfs4_state_owner
*sp
= state
->owner
;
5534 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5535 unsigned char fl_flags
= request
->fl_flags
;
5537 int status
= -ENOLCK
;
5539 if ((fl_flags
& FL_POSIX
) &&
5540 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5542 /* Is this a delegated open? */
5543 status
= nfs4_set_lock_state(state
, request
);
5546 request
->fl_flags
|= FL_ACCESS
;
5547 status
= do_vfs_lock(request
->fl_file
, request
);
5550 down_read(&nfsi
->rwsem
);
5551 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5552 /* Yes: cache locks! */
5553 /* ...but avoid races with delegation recall... */
5554 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5555 status
= do_vfs_lock(request
->fl_file
, request
);
5558 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5559 up_read(&nfsi
->rwsem
);
5560 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5563 down_read(&nfsi
->rwsem
);
5564 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5565 status
= -NFS4ERR_DELAY
;
5568 /* Note: we always want to sleep here! */
5569 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5570 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5571 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5572 "manager!\n", __func__
);
5574 up_read(&nfsi
->rwsem
);
5576 request
->fl_flags
= fl_flags
;
5580 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5582 struct nfs4_exception exception
= {
5584 .inode
= state
->inode
,
5589 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5590 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5591 if (err
== -NFS4ERR_DENIED
)
5593 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5595 } while (exception
.retry
);
5600 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5602 struct nfs_open_context
*ctx
;
5603 struct nfs4_state
*state
;
5604 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5607 /* verify open state */
5608 ctx
= nfs_file_open_context(filp
);
5611 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5614 if (IS_GETLK(cmd
)) {
5616 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5620 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5623 if (request
->fl_type
== F_UNLCK
) {
5625 return nfs4_proc_unlck(state
, cmd
, request
);
5632 * Don't rely on the VFS having checked the file open mode,
5633 * since it won't do this for flock() locks.
5635 switch (request
->fl_type
) {
5637 if (!(filp
->f_mode
& FMODE_READ
))
5641 if (!(filp
->f_mode
& FMODE_WRITE
))
5646 status
= nfs4_proc_setlk(state
, cmd
, request
);
5647 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5649 timeout
= nfs4_set_lock_task_retry(timeout
);
5650 status
= -ERESTARTSYS
;
5653 } while(status
< 0);
5657 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5659 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5662 err
= nfs4_set_lock_state(state
, fl
);
5665 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5666 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5669 struct nfs_release_lockowner_data
{
5670 struct nfs4_lock_state
*lsp
;
5671 struct nfs_server
*server
;
5672 struct nfs_release_lockowner_args args
;
5675 static void nfs4_release_lockowner_release(void *calldata
)
5677 struct nfs_release_lockowner_data
*data
= calldata
;
5678 nfs4_free_lock_state(data
->server
, data
->lsp
);
5682 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
5683 .rpc_release
= nfs4_release_lockowner_release
,
5686 static int nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
5688 struct nfs_release_lockowner_data
*data
;
5689 struct rpc_message msg
= {
5690 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
5693 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
5695 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5699 data
->server
= server
;
5700 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5701 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5702 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
5703 msg
.rpc_argp
= &data
->args
;
5704 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
5708 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5710 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
5711 const void *buf
, size_t buflen
,
5712 int flags
, int type
)
5714 if (strcmp(key
, "") != 0)
5717 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
5720 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
5721 void *buf
, size_t buflen
, int type
)
5723 if (strcmp(key
, "") != 0)
5726 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
5729 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
5730 size_t list_len
, const char *name
,
5731 size_t name_len
, int type
)
5733 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
5735 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
5738 if (list
&& len
<= list_len
)
5739 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
5743 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5744 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
5746 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
5749 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
5750 const void *buf
, size_t buflen
,
5751 int flags
, int type
)
5753 if (security_ismaclabel(key
))
5754 return nfs4_set_security_label(dentry
, buf
, buflen
);
5759 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
5760 void *buf
, size_t buflen
, int type
)
5762 if (security_ismaclabel(key
))
5763 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
5767 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
5768 size_t list_len
, const char *name
,
5769 size_t name_len
, int type
)
5773 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
5774 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
5775 if (list
&& len
<= list_len
)
5776 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
5781 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
5782 .prefix
= XATTR_SECURITY_PREFIX
,
5783 .list
= nfs4_xattr_list_nfs4_label
,
5784 .get
= nfs4_xattr_get_nfs4_label
,
5785 .set
= nfs4_xattr_set_nfs4_label
,
5791 * nfs_fhget will use either the mounted_on_fileid or the fileid
5793 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
5795 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
5796 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
5797 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
5798 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
5801 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
5802 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
5803 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
5807 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5808 const struct qstr
*name
,
5809 struct nfs4_fs_locations
*fs_locations
,
5812 struct nfs_server
*server
= NFS_SERVER(dir
);
5814 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
5816 struct nfs4_fs_locations_arg args
= {
5817 .dir_fh
= NFS_FH(dir
),
5822 struct nfs4_fs_locations_res res
= {
5823 .fs_locations
= fs_locations
,
5825 struct rpc_message msg
= {
5826 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
5832 dprintk("%s: start\n", __func__
);
5834 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5835 * is not supported */
5836 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
5837 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
5839 bitmask
[0] |= FATTR4_WORD0_FILEID
;
5841 nfs_fattr_init(&fs_locations
->fattr
);
5842 fs_locations
->server
= server
;
5843 fs_locations
->nlocations
= 0;
5844 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5845 dprintk("%s: returned status = %d\n", __func__
, status
);
5849 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5850 const struct qstr
*name
,
5851 struct nfs4_fs_locations
*fs_locations
,
5854 struct nfs4_exception exception
= { };
5857 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
5858 fs_locations
, page
);
5859 trace_nfs4_get_fs_locations(dir
, name
, err
);
5860 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5862 } while (exception
.retry
);
5867 * If 'use_integrity' is true and the state managment nfs_client
5868 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
5869 * and the machine credential as per RFC3530bis and RFC5661 Security
5870 * Considerations sections. Otherwise, just use the user cred with the
5871 * filesystem's rpc_client.
5873 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
5876 struct nfs4_secinfo_arg args
= {
5877 .dir_fh
= NFS_FH(dir
),
5880 struct nfs4_secinfo_res res
= {
5883 struct rpc_message msg
= {
5884 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
5888 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
5890 if (use_integrity
) {
5891 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
5892 msg
.rpc_cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
5895 dprintk("NFS call secinfo %s\n", name
->name
);
5896 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
5898 dprintk("NFS reply secinfo: %d\n", status
);
5901 put_rpccred(msg
.rpc_cred
);
5906 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
5907 struct nfs4_secinfo_flavors
*flavors
)
5909 struct nfs4_exception exception
= { };
5912 err
= -NFS4ERR_WRONGSEC
;
5914 /* try to use integrity protection with machine cred */
5915 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
5916 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
5919 * if unable to use integrity protection, or SECINFO with
5920 * integrity protection returns NFS4ERR_WRONGSEC (which is
5921 * disallowed by spec, but exists in deployed servers) use
5922 * the current filesystem's rpc_client and the user cred.
5924 if (err
== -NFS4ERR_WRONGSEC
)
5925 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
5927 trace_nfs4_secinfo(dir
, name
, err
);
5928 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5930 } while (exception
.retry
);
5934 #ifdef CONFIG_NFS_V4_1
5936 * Check the exchange flags returned by the server for invalid flags, having
5937 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5940 static int nfs4_check_cl_exchange_flags(u32 flags
)
5942 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
5944 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
5945 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
5947 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
5951 return -NFS4ERR_INVAL
;
5955 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
5956 struct nfs41_server_scope
*b
)
5958 if (a
->server_scope_sz
== b
->server_scope_sz
&&
5959 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
5966 * nfs4_proc_bind_conn_to_session()
5968 * The 4.1 client currently uses the same TCP connection for the
5969 * fore and backchannel.
5971 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5974 struct nfs41_bind_conn_to_session_res res
;
5975 struct rpc_message msg
= {
5977 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
5983 dprintk("--> %s\n", __func__
);
5985 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5986 if (unlikely(res
.session
== NULL
)) {
5991 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5992 trace_nfs4_bind_conn_to_session(clp
, status
);
5994 if (memcmp(res
.session
->sess_id
.data
,
5995 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
5996 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
6000 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
6001 dprintk("NFS: %s: Unexpected direction from server\n",
6006 if (res
.use_conn_in_rdma_mode
) {
6007 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6016 dprintk("<-- %s status= %d\n", __func__
, status
);
6021 * nfs4_proc_exchange_id()
6023 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6025 * Since the clientid has expired, all compounds using sessions
6026 * associated with the stale clientid will be returning
6027 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6028 * be in some phase of session reset.
6030 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6032 nfs4_verifier verifier
;
6033 struct nfs41_exchange_id_args args
= {
6034 .verifier
= &verifier
,
6036 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6037 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
6039 struct nfs41_exchange_id_res res
= {
6043 struct rpc_message msg
= {
6044 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
6050 nfs4_init_boot_verifier(clp
, &verifier
);
6051 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
6053 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6054 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
6055 args
.id_len
, args
.id
);
6057 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6059 if (unlikely(res
.server_owner
== NULL
)) {
6064 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6066 if (unlikely(res
.server_scope
== NULL
)) {
6068 goto out_server_owner
;
6071 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6072 if (unlikely(res
.impl_id
== NULL
)) {
6074 goto out_server_scope
;
6077 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6078 trace_nfs4_exchange_id(clp
, status
);
6080 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6083 clp
->cl_clientid
= res
.clientid
;
6084 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6085 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6086 clp
->cl_seqid
= res
.seqid
;
6088 kfree(clp
->cl_serverowner
);
6089 clp
->cl_serverowner
= res
.server_owner
;
6090 res
.server_owner
= NULL
;
6092 /* use the most recent implementation id */
6093 kfree(clp
->cl_implid
);
6094 clp
->cl_implid
= res
.impl_id
;
6096 if (clp
->cl_serverscope
!= NULL
&&
6097 !nfs41_same_server_scope(clp
->cl_serverscope
,
6098 res
.server_scope
)) {
6099 dprintk("%s: server_scope mismatch detected\n",
6101 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6102 kfree(clp
->cl_serverscope
);
6103 clp
->cl_serverscope
= NULL
;
6106 if (clp
->cl_serverscope
== NULL
) {
6107 clp
->cl_serverscope
= res
.server_scope
;
6114 kfree(res
.server_owner
);
6116 kfree(res
.server_scope
);
6118 if (clp
->cl_implid
!= NULL
)
6119 dprintk("NFS reply exchange_id: Server Implementation ID: "
6120 "domain: %s, name: %s, date: %llu,%u\n",
6121 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6122 clp
->cl_implid
->date
.seconds
,
6123 clp
->cl_implid
->date
.nseconds
);
6124 dprintk("NFS reply exchange_id: %d\n", status
);
6128 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6129 struct rpc_cred
*cred
)
6131 struct rpc_message msg
= {
6132 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6138 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6139 trace_nfs4_destroy_clientid(clp
, status
);
6141 dprintk("NFS: Got error %d from the server %s on "
6142 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6146 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6147 struct rpc_cred
*cred
)
6152 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6153 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6155 case -NFS4ERR_DELAY
:
6156 case -NFS4ERR_CLIENTID_BUSY
:
6166 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6168 struct rpc_cred
*cred
;
6171 if (clp
->cl_mvops
->minor_version
< 1)
6173 if (clp
->cl_exchange_flags
== 0)
6175 if (clp
->cl_preserve_clid
)
6177 cred
= nfs4_get_clid_cred(clp
);
6178 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6183 case -NFS4ERR_STALE_CLIENTID
:
6184 clp
->cl_exchange_flags
= 0;
6190 struct nfs4_get_lease_time_data
{
6191 struct nfs4_get_lease_time_args
*args
;
6192 struct nfs4_get_lease_time_res
*res
;
6193 struct nfs_client
*clp
;
6196 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6199 struct nfs4_get_lease_time_data
*data
=
6200 (struct nfs4_get_lease_time_data
*)calldata
;
6202 dprintk("--> %s\n", __func__
);
6203 /* just setup sequence, do not trigger session recovery
6204 since we're invoked within one */
6205 nfs41_setup_sequence(data
->clp
->cl_session
,
6206 &data
->args
->la_seq_args
,
6207 &data
->res
->lr_seq_res
,
6209 dprintk("<-- %s\n", __func__
);
6213 * Called from nfs4_state_manager thread for session setup, so don't recover
6214 * from sequence operation or clientid errors.
6216 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
6218 struct nfs4_get_lease_time_data
*data
=
6219 (struct nfs4_get_lease_time_data
*)calldata
;
6221 dprintk("--> %s\n", __func__
);
6222 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
6224 switch (task
->tk_status
) {
6225 case -NFS4ERR_DELAY
:
6226 case -NFS4ERR_GRACE
:
6227 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
6228 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
6229 task
->tk_status
= 0;
6231 case -NFS4ERR_RETRY_UNCACHED_REP
:
6232 rpc_restart_call_prepare(task
);
6235 dprintk("<-- %s\n", __func__
);
6238 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
6239 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
6240 .rpc_call_done
= nfs4_get_lease_time_done
,
6243 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
6245 struct rpc_task
*task
;
6246 struct nfs4_get_lease_time_args args
;
6247 struct nfs4_get_lease_time_res res
= {
6248 .lr_fsinfo
= fsinfo
,
6250 struct nfs4_get_lease_time_data data
= {
6255 struct rpc_message msg
= {
6256 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
6260 struct rpc_task_setup task_setup
= {
6261 .rpc_client
= clp
->cl_rpcclient
,
6262 .rpc_message
= &msg
,
6263 .callback_ops
= &nfs4_get_lease_time_ops
,
6264 .callback_data
= &data
,
6265 .flags
= RPC_TASK_TIMEOUT
,
6269 nfs41_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
6270 nfs4_set_sequence_privileged(&args
.la_seq_args
);
6271 dprintk("--> %s\n", __func__
);
6272 task
= rpc_run_task(&task_setup
);
6275 status
= PTR_ERR(task
);
6277 status
= task
->tk_status
;
6280 dprintk("<-- %s return %d\n", __func__
, status
);
6286 * Initialize the values to be used by the client in CREATE_SESSION
6287 * If nfs4_init_session set the fore channel request and response sizes,
6290 * Set the back channel max_resp_sz_cached to zero to force the client to
6291 * always set csa_cachethis to FALSE because the current implementation
6292 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6294 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
6296 unsigned int max_rqst_sz
, max_resp_sz
;
6298 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
6299 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
6301 /* Fore channel attributes */
6302 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
6303 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
6304 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
6305 args
->fc_attrs
.max_reqs
= max_session_slots
;
6307 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6308 "max_ops=%u max_reqs=%u\n",
6310 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
6311 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
6313 /* Back channel attributes */
6314 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
6315 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
6316 args
->bc_attrs
.max_resp_sz_cached
= 0;
6317 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
6318 args
->bc_attrs
.max_reqs
= 1;
6320 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6321 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6323 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
6324 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
6325 args
->bc_attrs
.max_reqs
);
6328 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6330 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
6331 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
6333 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
6336 * Our requested max_ops is the minimum we need; we're not
6337 * prepared to break up compounds into smaller pieces than that.
6338 * So, no point even trying to continue if the server won't
6341 if (rcvd
->max_ops
< sent
->max_ops
)
6343 if (rcvd
->max_reqs
== 0)
6345 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
6346 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
6350 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6352 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
6353 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
6355 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
6357 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
6359 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
6361 /* These would render the backchannel useless: */
6362 if (rcvd
->max_ops
!= sent
->max_ops
)
6364 if (rcvd
->max_reqs
!= sent
->max_reqs
)
6369 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
6370 struct nfs4_session
*session
)
6374 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
6377 return nfs4_verify_back_channel_attrs(args
, session
);
6380 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
6381 struct rpc_cred
*cred
)
6383 struct nfs4_session
*session
= clp
->cl_session
;
6384 struct nfs41_create_session_args args
= {
6386 .cb_program
= NFS4_CALLBACK
,
6388 struct nfs41_create_session_res res
= {
6391 struct rpc_message msg
= {
6392 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
6399 nfs4_init_channel_attrs(&args
);
6400 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
6402 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6403 trace_nfs4_create_session(clp
, status
);
6406 /* Verify the session's negotiated channel_attrs values */
6407 status
= nfs4_verify_channel_attrs(&args
, session
);
6408 /* Increment the clientid slot sequence id */
6416 * Issues a CREATE_SESSION operation to the server.
6417 * It is the responsibility of the caller to verify the session is
6418 * expired before calling this routine.
6420 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6424 struct nfs4_session
*session
= clp
->cl_session
;
6426 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
6428 status
= _nfs4_proc_create_session(clp
, cred
);
6432 /* Init or reset the session slot tables */
6433 status
= nfs4_setup_session_slot_tables(session
);
6434 dprintk("slot table setup returned %d\n", status
);
6438 ptr
= (unsigned *)&session
->sess_id
.data
[0];
6439 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
6440 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
6442 dprintk("<-- %s\n", __func__
);
6447 * Issue the over-the-wire RPC DESTROY_SESSION.
6448 * The caller must serialize access to this routine.
6450 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
6451 struct rpc_cred
*cred
)
6453 struct rpc_message msg
= {
6454 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
6455 .rpc_argp
= session
,
6460 dprintk("--> nfs4_proc_destroy_session\n");
6462 /* session is still being setup */
6463 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
6466 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6467 trace_nfs4_destroy_session(session
->clp
, status
);
6470 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
6471 "Session has been destroyed regardless...\n", status
);
6473 dprintk("<-- nfs4_proc_destroy_session\n");
6478 * Renew the cl_session lease.
6480 struct nfs4_sequence_data
{
6481 struct nfs_client
*clp
;
6482 struct nfs4_sequence_args args
;
6483 struct nfs4_sequence_res res
;
6486 static void nfs41_sequence_release(void *data
)
6488 struct nfs4_sequence_data
*calldata
= data
;
6489 struct nfs_client
*clp
= calldata
->clp
;
6491 if (atomic_read(&clp
->cl_count
) > 1)
6492 nfs4_schedule_state_renewal(clp
);
6493 nfs_put_client(clp
);
6497 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6499 switch(task
->tk_status
) {
6500 case -NFS4ERR_DELAY
:
6501 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6504 nfs4_schedule_lease_recovery(clp
);
6509 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
6511 struct nfs4_sequence_data
*calldata
= data
;
6512 struct nfs_client
*clp
= calldata
->clp
;
6514 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
6517 trace_nfs4_sequence(clp
, task
->tk_status
);
6518 if (task
->tk_status
< 0) {
6519 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
6520 if (atomic_read(&clp
->cl_count
) == 1)
6523 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
6524 rpc_restart_call_prepare(task
);
6528 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
6530 dprintk("<-- %s\n", __func__
);
6533 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
6535 struct nfs4_sequence_data
*calldata
= data
;
6536 struct nfs_client
*clp
= calldata
->clp
;
6537 struct nfs4_sequence_args
*args
;
6538 struct nfs4_sequence_res
*res
;
6540 args
= task
->tk_msg
.rpc_argp
;
6541 res
= task
->tk_msg
.rpc_resp
;
6543 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
6546 static const struct rpc_call_ops nfs41_sequence_ops
= {
6547 .rpc_call_done
= nfs41_sequence_call_done
,
6548 .rpc_call_prepare
= nfs41_sequence_prepare
,
6549 .rpc_release
= nfs41_sequence_release
,
6552 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
6553 struct rpc_cred
*cred
,
6556 struct nfs4_sequence_data
*calldata
;
6557 struct rpc_message msg
= {
6558 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
6561 struct rpc_task_setup task_setup_data
= {
6562 .rpc_client
= clp
->cl_rpcclient
,
6563 .rpc_message
= &msg
,
6564 .callback_ops
= &nfs41_sequence_ops
,
6565 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
6568 if (!atomic_inc_not_zero(&clp
->cl_count
))
6569 return ERR_PTR(-EIO
);
6570 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6571 if (calldata
== NULL
) {
6572 nfs_put_client(clp
);
6573 return ERR_PTR(-ENOMEM
);
6575 nfs41_init_sequence(&calldata
->args
, &calldata
->res
, 0);
6577 nfs4_set_sequence_privileged(&calldata
->args
);
6578 msg
.rpc_argp
= &calldata
->args
;
6579 msg
.rpc_resp
= &calldata
->res
;
6580 calldata
->clp
= clp
;
6581 task_setup_data
.callback_data
= calldata
;
6583 return rpc_run_task(&task_setup_data
);
6586 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
6588 struct rpc_task
*task
;
6591 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
6593 task
= _nfs41_proc_sequence(clp
, cred
, false);
6595 ret
= PTR_ERR(task
);
6597 rpc_put_task_async(task
);
6598 dprintk("<-- %s status=%d\n", __func__
, ret
);
6602 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6604 struct rpc_task
*task
;
6607 task
= _nfs41_proc_sequence(clp
, cred
, true);
6609 ret
= PTR_ERR(task
);
6612 ret
= rpc_wait_for_completion_task(task
);
6614 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
6616 if (task
->tk_status
== 0)
6617 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
6618 ret
= task
->tk_status
;
6622 dprintk("<-- %s status=%d\n", __func__
, ret
);
6626 struct nfs4_reclaim_complete_data
{
6627 struct nfs_client
*clp
;
6628 struct nfs41_reclaim_complete_args arg
;
6629 struct nfs41_reclaim_complete_res res
;
6632 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
6634 struct nfs4_reclaim_complete_data
*calldata
= data
;
6636 nfs41_setup_sequence(calldata
->clp
->cl_session
,
6637 &calldata
->arg
.seq_args
,
6638 &calldata
->res
.seq_res
,
6642 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6644 switch(task
->tk_status
) {
6646 case -NFS4ERR_COMPLETE_ALREADY
:
6647 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
6649 case -NFS4ERR_DELAY
:
6650 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6652 case -NFS4ERR_RETRY_UNCACHED_REP
:
6655 nfs4_schedule_lease_recovery(clp
);
6660 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
6662 struct nfs4_reclaim_complete_data
*calldata
= data
;
6663 struct nfs_client
*clp
= calldata
->clp
;
6664 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
6666 dprintk("--> %s\n", __func__
);
6667 if (!nfs41_sequence_done(task
, res
))
6670 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
6671 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
6672 rpc_restart_call_prepare(task
);
6675 dprintk("<-- %s\n", __func__
);
6678 static void nfs4_free_reclaim_complete_data(void *data
)
6680 struct nfs4_reclaim_complete_data
*calldata
= data
;
6685 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
6686 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
6687 .rpc_call_done
= nfs4_reclaim_complete_done
,
6688 .rpc_release
= nfs4_free_reclaim_complete_data
,
6692 * Issue a global reclaim complete.
6694 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
6695 struct rpc_cred
*cred
)
6697 struct nfs4_reclaim_complete_data
*calldata
;
6698 struct rpc_task
*task
;
6699 struct rpc_message msg
= {
6700 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
6703 struct rpc_task_setup task_setup_data
= {
6704 .rpc_client
= clp
->cl_rpcclient
,
6705 .rpc_message
= &msg
,
6706 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
6707 .flags
= RPC_TASK_ASYNC
,
6709 int status
= -ENOMEM
;
6711 dprintk("--> %s\n", __func__
);
6712 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6713 if (calldata
== NULL
)
6715 calldata
->clp
= clp
;
6716 calldata
->arg
.one_fs
= 0;
6718 nfs41_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
6719 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
6720 msg
.rpc_argp
= &calldata
->arg
;
6721 msg
.rpc_resp
= &calldata
->res
;
6722 task_setup_data
.callback_data
= calldata
;
6723 task
= rpc_run_task(&task_setup_data
);
6725 status
= PTR_ERR(task
);
6728 status
= nfs4_wait_for_completion_rpc_task(task
);
6730 status
= task
->tk_status
;
6734 dprintk("<-- %s status=%d\n", __func__
, status
);
6739 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
6741 struct nfs4_layoutget
*lgp
= calldata
;
6742 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
6743 struct nfs4_session
*session
= nfs4_get_session(server
);
6745 dprintk("--> %s\n", __func__
);
6746 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6747 * right now covering the LAYOUTGET we are about to send.
6748 * However, that is not so catastrophic, and there seems
6749 * to be no way to prevent it completely.
6751 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
6752 &lgp
->res
.seq_res
, task
))
6754 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
6755 NFS_I(lgp
->args
.inode
)->layout
,
6756 lgp
->args
.ctx
->state
)) {
6757 rpc_exit(task
, NFS4_OK
);
6761 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
6763 struct nfs4_layoutget
*lgp
= calldata
;
6764 struct inode
*inode
= lgp
->args
.inode
;
6765 struct nfs_server
*server
= NFS_SERVER(inode
);
6766 struct pnfs_layout_hdr
*lo
;
6767 struct nfs4_state
*state
= NULL
;
6768 unsigned long timeo
, giveup
;
6770 dprintk("--> %s\n", __func__
);
6772 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
6775 switch (task
->tk_status
) {
6778 case -NFS4ERR_LAYOUTTRYLATER
:
6779 case -NFS4ERR_RECALLCONFLICT
:
6780 timeo
= rpc_get_timeout(task
->tk_client
);
6781 giveup
= lgp
->args
.timestamp
+ timeo
;
6782 if (time_after(giveup
, jiffies
))
6783 task
->tk_status
= -NFS4ERR_DELAY
;
6785 case -NFS4ERR_EXPIRED
:
6786 case -NFS4ERR_BAD_STATEID
:
6787 spin_lock(&inode
->i_lock
);
6788 lo
= NFS_I(inode
)->layout
;
6789 if (!lo
|| list_empty(&lo
->plh_segs
)) {
6790 spin_unlock(&inode
->i_lock
);
6791 /* If the open stateid was bad, then recover it. */
6792 state
= lgp
->args
.ctx
->state
;
6796 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
6797 spin_unlock(&inode
->i_lock
);
6798 /* Mark the bad layout state as invalid, then
6799 * retry using the open stateid. */
6800 pnfs_free_lseg_list(&head
);
6803 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
6804 rpc_restart_call_prepare(task
);
6806 dprintk("<-- %s\n", __func__
);
6809 static size_t max_response_pages(struct nfs_server
*server
)
6811 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
6812 return nfs_page_array_len(0, max_resp_sz
);
6815 static void nfs4_free_pages(struct page
**pages
, size_t size
)
6822 for (i
= 0; i
< size
; i
++) {
6825 __free_page(pages
[i
]);
6830 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
6832 struct page
**pages
;
6835 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
6837 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
6841 for (i
= 0; i
< size
; i
++) {
6842 pages
[i
] = alloc_page(gfp_flags
);
6844 dprintk("%s: failed to allocate page\n", __func__
);
6845 nfs4_free_pages(pages
, size
);
6853 static void nfs4_layoutget_release(void *calldata
)
6855 struct nfs4_layoutget
*lgp
= calldata
;
6856 struct inode
*inode
= lgp
->args
.inode
;
6857 struct nfs_server
*server
= NFS_SERVER(inode
);
6858 size_t max_pages
= max_response_pages(server
);
6860 dprintk("--> %s\n", __func__
);
6861 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
6862 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
6863 put_nfs_open_context(lgp
->args
.ctx
);
6865 dprintk("<-- %s\n", __func__
);
6868 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
6869 .rpc_call_prepare
= nfs4_layoutget_prepare
,
6870 .rpc_call_done
= nfs4_layoutget_done
,
6871 .rpc_release
= nfs4_layoutget_release
,
6874 struct pnfs_layout_segment
*
6875 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
6877 struct inode
*inode
= lgp
->args
.inode
;
6878 struct nfs_server
*server
= NFS_SERVER(inode
);
6879 size_t max_pages
= max_response_pages(server
);
6880 struct rpc_task
*task
;
6881 struct rpc_message msg
= {
6882 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
6883 .rpc_argp
= &lgp
->args
,
6884 .rpc_resp
= &lgp
->res
,
6885 .rpc_cred
= lgp
->cred
,
6887 struct rpc_task_setup task_setup_data
= {
6888 .rpc_client
= server
->client
,
6889 .rpc_message
= &msg
,
6890 .callback_ops
= &nfs4_layoutget_call_ops
,
6891 .callback_data
= lgp
,
6892 .flags
= RPC_TASK_ASYNC
,
6894 struct pnfs_layout_segment
*lseg
= NULL
;
6897 dprintk("--> %s\n", __func__
);
6899 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
6900 if (!lgp
->args
.layout
.pages
) {
6901 nfs4_layoutget_release(lgp
);
6902 return ERR_PTR(-ENOMEM
);
6904 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
6905 lgp
->args
.timestamp
= jiffies
;
6907 lgp
->res
.layoutp
= &lgp
->args
.layout
;
6908 lgp
->res
.seq_res
.sr_slot
= NULL
;
6909 nfs41_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
6911 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6912 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
6914 task
= rpc_run_task(&task_setup_data
);
6916 return ERR_CAST(task
);
6917 status
= nfs4_wait_for_completion_rpc_task(task
);
6919 status
= task
->tk_status
;
6920 trace_nfs4_layoutget(lgp
->args
.ctx
,
6924 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6925 if (status
== 0 && lgp
->res
.layoutp
->len
)
6926 lseg
= pnfs_layout_process(lgp
);
6928 dprintk("<-- %s status=%d\n", __func__
, status
);
6930 return ERR_PTR(status
);
6935 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
6937 struct nfs4_layoutreturn
*lrp
= calldata
;
6939 dprintk("--> %s\n", __func__
);
6940 nfs41_setup_sequence(lrp
->clp
->cl_session
,
6941 &lrp
->args
.seq_args
,
6946 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
6948 struct nfs4_layoutreturn
*lrp
= calldata
;
6949 struct nfs_server
*server
;
6951 dprintk("--> %s\n", __func__
);
6953 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
6956 server
= NFS_SERVER(lrp
->args
.inode
);
6957 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
6958 rpc_restart_call_prepare(task
);
6961 dprintk("<-- %s\n", __func__
);
6964 static void nfs4_layoutreturn_release(void *calldata
)
6966 struct nfs4_layoutreturn
*lrp
= calldata
;
6967 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
6969 dprintk("--> %s\n", __func__
);
6970 spin_lock(&lo
->plh_inode
->i_lock
);
6971 if (lrp
->res
.lrs_present
)
6972 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
6973 lo
->plh_block_lgets
--;
6974 spin_unlock(&lo
->plh_inode
->i_lock
);
6975 pnfs_put_layout_hdr(lrp
->args
.layout
);
6977 dprintk("<-- %s\n", __func__
);
6980 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
6981 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
6982 .rpc_call_done
= nfs4_layoutreturn_done
,
6983 .rpc_release
= nfs4_layoutreturn_release
,
6986 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
6988 struct rpc_task
*task
;
6989 struct rpc_message msg
= {
6990 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
6991 .rpc_argp
= &lrp
->args
,
6992 .rpc_resp
= &lrp
->res
,
6993 .rpc_cred
= lrp
->cred
,
6995 struct rpc_task_setup task_setup_data
= {
6996 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
6997 .rpc_message
= &msg
,
6998 .callback_ops
= &nfs4_layoutreturn_call_ops
,
6999 .callback_data
= lrp
,
7003 dprintk("--> %s\n", __func__
);
7004 nfs41_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
7005 task
= rpc_run_task(&task_setup_data
);
7007 return PTR_ERR(task
);
7008 status
= task
->tk_status
;
7009 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
7010 dprintk("<-- %s status=%d\n", __func__
, status
);
7016 * Retrieve the list of Data Server devices from the MDS.
7018 static int _nfs4_getdevicelist(struct nfs_server
*server
,
7019 const struct nfs_fh
*fh
,
7020 struct pnfs_devicelist
*devlist
)
7022 struct nfs4_getdevicelist_args args
= {
7024 .layoutclass
= server
->pnfs_curr_ld
->id
,
7026 struct nfs4_getdevicelist_res res
= {
7029 struct rpc_message msg
= {
7030 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
7036 dprintk("--> %s\n", __func__
);
7037 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
7039 dprintk("<-- %s status=%d\n", __func__
, status
);
7043 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
7044 const struct nfs_fh
*fh
,
7045 struct pnfs_devicelist
*devlist
)
7047 struct nfs4_exception exception
= { };
7051 err
= nfs4_handle_exception(server
,
7052 _nfs4_getdevicelist(server
, fh
, devlist
),
7054 } while (exception
.retry
);
7056 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
7057 err
, devlist
->num_devs
);
7061 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
7064 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7065 struct pnfs_device
*pdev
,
7066 struct rpc_cred
*cred
)
7068 struct nfs4_getdeviceinfo_args args
= {
7071 struct nfs4_getdeviceinfo_res res
= {
7074 struct rpc_message msg
= {
7075 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7082 dprintk("--> %s\n", __func__
);
7083 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7084 dprintk("<-- %s status=%d\n", __func__
, status
);
7089 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7090 struct pnfs_device
*pdev
,
7091 struct rpc_cred
*cred
)
7093 struct nfs4_exception exception
= { };
7097 err
= nfs4_handle_exception(server
,
7098 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7100 } while (exception
.retry
);
7103 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7105 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7107 struct nfs4_layoutcommit_data
*data
= calldata
;
7108 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7109 struct nfs4_session
*session
= nfs4_get_session(server
);
7111 nfs41_setup_sequence(session
,
7112 &data
->args
.seq_args
,
7118 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7120 struct nfs4_layoutcommit_data
*data
= calldata
;
7121 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7123 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7126 switch (task
->tk_status
) { /* Just ignore these failures */
7127 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7128 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7129 case -NFS4ERR_BADLAYOUT
: /* no layout */
7130 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7131 task
->tk_status
= 0;
7134 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7138 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7139 rpc_restart_call_prepare(task
);
7145 static void nfs4_layoutcommit_release(void *calldata
)
7147 struct nfs4_layoutcommit_data
*data
= calldata
;
7149 pnfs_cleanup_layoutcommit(data
);
7150 put_rpccred(data
->cred
);
7154 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7155 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7156 .rpc_call_done
= nfs4_layoutcommit_done
,
7157 .rpc_release
= nfs4_layoutcommit_release
,
7161 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7163 struct rpc_message msg
= {
7164 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7165 .rpc_argp
= &data
->args
,
7166 .rpc_resp
= &data
->res
,
7167 .rpc_cred
= data
->cred
,
7169 struct rpc_task_setup task_setup_data
= {
7170 .task
= &data
->task
,
7171 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7172 .rpc_message
= &msg
,
7173 .callback_ops
= &nfs4_layoutcommit_ops
,
7174 .callback_data
= data
,
7175 .flags
= RPC_TASK_ASYNC
,
7177 struct rpc_task
*task
;
7180 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7181 "lbw: %llu inode %lu\n",
7182 data
->task
.tk_pid
, sync
,
7183 data
->args
.lastbytewritten
,
7184 data
->args
.inode
->i_ino
);
7186 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7187 task
= rpc_run_task(&task_setup_data
);
7189 return PTR_ERR(task
);
7192 status
= nfs4_wait_for_completion_rpc_task(task
);
7195 status
= task
->tk_status
;
7196 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7198 dprintk("%s: status %d\n", __func__
, status
);
7204 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7205 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7208 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7209 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7211 struct nfs41_secinfo_no_name_args args
= {
7212 .style
= SECINFO_STYLE_CURRENT_FH
,
7214 struct nfs4_secinfo_res res
= {
7217 struct rpc_message msg
= {
7218 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
7222 return nfs4_call_sync(server
->nfs_client
->cl_rpcclient
, server
, &msg
,
7223 &args
.seq_args
, &res
.seq_res
, 0);
7227 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7228 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7230 struct nfs4_exception exception
= { };
7233 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7236 case -NFS4ERR_WRONGSEC
:
7237 case -NFS4ERR_NOTSUPP
:
7240 err
= nfs4_handle_exception(server
, err
, &exception
);
7242 } while (exception
.retry
);
7248 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7249 struct nfs_fsinfo
*info
)
7253 rpc_authflavor_t flavor
;
7254 struct nfs4_secinfo_flavors
*flavors
;
7256 page
= alloc_page(GFP_KERNEL
);
7262 flavors
= page_address(page
);
7263 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7266 * Fall back on "guess and check" method if
7267 * the server doesn't support SECINFO_NO_NAME
7269 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
7270 err
= nfs4_find_root_sec(server
, fhandle
, info
);
7276 flavor
= nfs_find_best_sec(flavors
);
7278 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
7288 static int _nfs41_test_stateid(struct nfs_server
*server
,
7289 nfs4_stateid
*stateid
,
7290 struct rpc_cred
*cred
)
7293 struct nfs41_test_stateid_args args
= {
7296 struct nfs41_test_stateid_res res
;
7297 struct rpc_message msg
= {
7298 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
7304 dprintk("NFS call test_stateid %p\n", stateid
);
7305 nfs41_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
7306 nfs4_set_sequence_privileged(&args
.seq_args
);
7307 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
,
7308 &args
.seq_args
, &res
.seq_res
);
7309 if (status
!= NFS_OK
) {
7310 dprintk("NFS reply test_stateid: failed, %d\n", status
);
7313 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
7318 * nfs41_test_stateid - perform a TEST_STATEID operation
7320 * @server: server / transport on which to perform the operation
7321 * @stateid: state ID to test
7324 * Returns NFS_OK if the server recognizes that "stateid" is valid.
7325 * Otherwise a negative NFS4ERR value is returned if the operation
7326 * failed or the state ID is not currently valid.
7328 static int nfs41_test_stateid(struct nfs_server
*server
,
7329 nfs4_stateid
*stateid
,
7330 struct rpc_cred
*cred
)
7332 struct nfs4_exception exception
= { };
7335 err
= _nfs41_test_stateid(server
, stateid
, cred
);
7336 if (err
!= -NFS4ERR_DELAY
)
7338 nfs4_handle_exception(server
, err
, &exception
);
7339 } while (exception
.retry
);
7343 struct nfs_free_stateid_data
{
7344 struct nfs_server
*server
;
7345 struct nfs41_free_stateid_args args
;
7346 struct nfs41_free_stateid_res res
;
7349 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
7351 struct nfs_free_stateid_data
*data
= calldata
;
7352 nfs41_setup_sequence(nfs4_get_session(data
->server
),
7353 &data
->args
.seq_args
,
7358 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
7360 struct nfs_free_stateid_data
*data
= calldata
;
7362 nfs41_sequence_done(task
, &data
->res
.seq_res
);
7364 switch (task
->tk_status
) {
7365 case -NFS4ERR_DELAY
:
7366 if (nfs4_async_handle_error(task
, data
->server
, NULL
) == -EAGAIN
)
7367 rpc_restart_call_prepare(task
);
7371 static void nfs41_free_stateid_release(void *calldata
)
7376 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
7377 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
7378 .rpc_call_done
= nfs41_free_stateid_done
,
7379 .rpc_release
= nfs41_free_stateid_release
,
7382 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
7383 nfs4_stateid
*stateid
,
7384 struct rpc_cred
*cred
,
7387 struct rpc_message msg
= {
7388 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
7391 struct rpc_task_setup task_setup
= {
7392 .rpc_client
= server
->client
,
7393 .rpc_message
= &msg
,
7394 .callback_ops
= &nfs41_free_stateid_ops
,
7395 .flags
= RPC_TASK_ASYNC
,
7397 struct nfs_free_stateid_data
*data
;
7399 dprintk("NFS call free_stateid %p\n", stateid
);
7400 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
7402 return ERR_PTR(-ENOMEM
);
7403 data
->server
= server
;
7404 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
7406 task_setup
.callback_data
= data
;
7408 msg
.rpc_argp
= &data
->args
;
7409 msg
.rpc_resp
= &data
->res
;
7410 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
7412 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
7414 return rpc_run_task(&task_setup
);
7418 * nfs41_free_stateid - perform a FREE_STATEID operation
7420 * @server: server / transport on which to perform the operation
7421 * @stateid: state ID to release
7424 * Returns NFS_OK if the server freed "stateid". Otherwise a
7425 * negative NFS4ERR value is returned.
7427 static int nfs41_free_stateid(struct nfs_server
*server
,
7428 nfs4_stateid
*stateid
,
7429 struct rpc_cred
*cred
)
7431 struct rpc_task
*task
;
7434 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
7436 return PTR_ERR(task
);
7437 ret
= rpc_wait_for_completion_task(task
);
7439 ret
= task
->tk_status
;
7444 static int nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
7446 struct rpc_task
*task
;
7447 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
7449 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
7450 nfs4_free_lock_state(server
, lsp
);
7452 return PTR_ERR(task
);
7457 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
7458 const nfs4_stateid
*s2
)
7460 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
7463 if (s1
->seqid
== s2
->seqid
)
7465 if (s1
->seqid
== 0 || s2
->seqid
== 0)
7471 #endif /* CONFIG_NFS_V4_1 */
7473 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
7474 const nfs4_stateid
*s2
)
7476 return nfs4_stateid_match(s1
, s2
);
7480 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
7481 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7482 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7483 .recover_open
= nfs4_open_reclaim
,
7484 .recover_lock
= nfs4_lock_reclaim
,
7485 .establish_clid
= nfs4_init_clientid
,
7486 .detect_trunking
= nfs40_discover_server_trunking
,
7489 #if defined(CONFIG_NFS_V4_1)
7490 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
7491 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7492 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7493 .recover_open
= nfs4_open_reclaim
,
7494 .recover_lock
= nfs4_lock_reclaim
,
7495 .establish_clid
= nfs41_init_clientid
,
7496 .reclaim_complete
= nfs41_proc_reclaim_complete
,
7497 .detect_trunking
= nfs41_discover_server_trunking
,
7499 #endif /* CONFIG_NFS_V4_1 */
7501 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
7502 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7503 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7504 .recover_open
= nfs4_open_expired
,
7505 .recover_lock
= nfs4_lock_expired
,
7506 .establish_clid
= nfs4_init_clientid
,
7509 #if defined(CONFIG_NFS_V4_1)
7510 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
7511 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7512 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7513 .recover_open
= nfs41_open_expired
,
7514 .recover_lock
= nfs41_lock_expired
,
7515 .establish_clid
= nfs41_init_clientid
,
7517 #endif /* CONFIG_NFS_V4_1 */
7519 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
7520 .sched_state_renewal
= nfs4_proc_async_renew
,
7521 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
7522 .renew_lease
= nfs4_proc_renew
,
7525 #if defined(CONFIG_NFS_V4_1)
7526 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
7527 .sched_state_renewal
= nfs41_proc_async_sequence
,
7528 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
7529 .renew_lease
= nfs4_proc_sequence
,
7533 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
7535 .init_caps
= NFS_CAP_READDIRPLUS
7536 | NFS_CAP_ATOMIC_OPEN
7537 | NFS_CAP_CHANGE_ATTR
7538 | NFS_CAP_POSIX_LOCK
,
7539 .call_sync
= _nfs4_call_sync
,
7540 .match_stateid
= nfs4_match_stateid
,
7541 .find_root_sec
= nfs4_find_root_sec
,
7542 .free_lock_state
= nfs4_release_lockowner
,
7543 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
7544 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
7545 .state_renewal_ops
= &nfs40_state_renewal_ops
,
7548 #if defined(CONFIG_NFS_V4_1)
7549 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
7551 .init_caps
= NFS_CAP_READDIRPLUS
7552 | NFS_CAP_ATOMIC_OPEN
7553 | NFS_CAP_CHANGE_ATTR
7554 | NFS_CAP_POSIX_LOCK
7555 | NFS_CAP_STATEID_NFSV41
7556 | NFS_CAP_ATOMIC_OPEN_V1
,
7557 .call_sync
= nfs4_call_sync_sequence
,
7558 .match_stateid
= nfs41_match_stateid
,
7559 .find_root_sec
= nfs41_find_root_sec
,
7560 .free_lock_state
= nfs41_free_lock_state
,
7561 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7562 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7563 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7567 #if defined(CONFIG_NFS_V4_2)
7568 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
7570 .init_caps
= NFS_CAP_READDIRPLUS
7571 | NFS_CAP_ATOMIC_OPEN
7572 | NFS_CAP_CHANGE_ATTR
7573 | NFS_CAP_POSIX_LOCK
7574 | NFS_CAP_STATEID_NFSV41
7575 | NFS_CAP_ATOMIC_OPEN_V1
,
7576 .call_sync
= nfs4_call_sync_sequence
,
7577 .match_stateid
= nfs41_match_stateid
,
7578 .find_root_sec
= nfs41_find_root_sec
,
7579 .free_lock_state
= nfs41_free_lock_state
,
7580 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7581 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7582 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7586 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
7587 [0] = &nfs_v4_0_minor_ops
,
7588 #if defined(CONFIG_NFS_V4_1)
7589 [1] = &nfs_v4_1_minor_ops
,
7591 #if defined(CONFIG_NFS_V4_2)
7592 [2] = &nfs_v4_2_minor_ops
,
7596 static const struct inode_operations nfs4_dir_inode_operations
= {
7597 .create
= nfs_create
,
7598 .lookup
= nfs_lookup
,
7599 .atomic_open
= nfs_atomic_open
,
7601 .unlink
= nfs_unlink
,
7602 .symlink
= nfs_symlink
,
7606 .rename
= nfs_rename
,
7607 .permission
= nfs_permission
,
7608 .getattr
= nfs_getattr
,
7609 .setattr
= nfs_setattr
,
7610 .getxattr
= generic_getxattr
,
7611 .setxattr
= generic_setxattr
,
7612 .listxattr
= generic_listxattr
,
7613 .removexattr
= generic_removexattr
,
7616 static const struct inode_operations nfs4_file_inode_operations
= {
7617 .permission
= nfs_permission
,
7618 .getattr
= nfs_getattr
,
7619 .setattr
= nfs_setattr
,
7620 .getxattr
= generic_getxattr
,
7621 .setxattr
= generic_setxattr
,
7622 .listxattr
= generic_listxattr
,
7623 .removexattr
= generic_removexattr
,
7626 const struct nfs_rpc_ops nfs_v4_clientops
= {
7627 .version
= 4, /* protocol version */
7628 .dentry_ops
= &nfs4_dentry_operations
,
7629 .dir_inode_ops
= &nfs4_dir_inode_operations
,
7630 .file_inode_ops
= &nfs4_file_inode_operations
,
7631 .file_ops
= &nfs4_file_operations
,
7632 .getroot
= nfs4_proc_get_root
,
7633 .submount
= nfs4_submount
,
7634 .try_mount
= nfs4_try_mount
,
7635 .getattr
= nfs4_proc_getattr
,
7636 .setattr
= nfs4_proc_setattr
,
7637 .lookup
= nfs4_proc_lookup
,
7638 .access
= nfs4_proc_access
,
7639 .readlink
= nfs4_proc_readlink
,
7640 .create
= nfs4_proc_create
,
7641 .remove
= nfs4_proc_remove
,
7642 .unlink_setup
= nfs4_proc_unlink_setup
,
7643 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
7644 .unlink_done
= nfs4_proc_unlink_done
,
7645 .rename
= nfs4_proc_rename
,
7646 .rename_setup
= nfs4_proc_rename_setup
,
7647 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
7648 .rename_done
= nfs4_proc_rename_done
,
7649 .link
= nfs4_proc_link
,
7650 .symlink
= nfs4_proc_symlink
,
7651 .mkdir
= nfs4_proc_mkdir
,
7652 .rmdir
= nfs4_proc_remove
,
7653 .readdir
= nfs4_proc_readdir
,
7654 .mknod
= nfs4_proc_mknod
,
7655 .statfs
= nfs4_proc_statfs
,
7656 .fsinfo
= nfs4_proc_fsinfo
,
7657 .pathconf
= nfs4_proc_pathconf
,
7658 .set_capabilities
= nfs4_server_capabilities
,
7659 .decode_dirent
= nfs4_decode_dirent
,
7660 .read_setup
= nfs4_proc_read_setup
,
7661 .read_pageio_init
= pnfs_pageio_init_read
,
7662 .read_rpc_prepare
= nfs4_proc_read_rpc_prepare
,
7663 .read_done
= nfs4_read_done
,
7664 .write_setup
= nfs4_proc_write_setup
,
7665 .write_pageio_init
= pnfs_pageio_init_write
,
7666 .write_rpc_prepare
= nfs4_proc_write_rpc_prepare
,
7667 .write_done
= nfs4_write_done
,
7668 .commit_setup
= nfs4_proc_commit_setup
,
7669 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
7670 .commit_done
= nfs4_commit_done
,
7671 .lock
= nfs4_proc_lock
,
7672 .clear_acl_cache
= nfs4_zap_acl_attr
,
7673 .close_context
= nfs4_close_context
,
7674 .open_context
= nfs4_atomic_open
,
7675 .have_delegation
= nfs4_have_delegation
,
7676 .return_delegation
= nfs4_inode_return_delegation
,
7677 .alloc_client
= nfs4_alloc_client
,
7678 .init_client
= nfs4_init_client
,
7679 .free_client
= nfs4_free_client
,
7680 .create_server
= nfs4_create_server
,
7681 .clone_server
= nfs_clone_server
,
7684 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
7685 .prefix
= XATTR_NAME_NFSV4_ACL
,
7686 .list
= nfs4_xattr_list_nfs4_acl
,
7687 .get
= nfs4_xattr_get_nfs4_acl
,
7688 .set
= nfs4_xattr_set_nfs4_acl
,
7691 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
7692 &nfs4_xattr_nfs4_acl_handler
,
7693 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7694 &nfs4_xattr_nfs4_label_handler
,