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 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
441 spin_lock(&clp
->cl_lock
);
442 if (time_before(clp
->cl_last_renewal
,timestamp
))
443 clp
->cl_last_renewal
= timestamp
;
444 spin_unlock(&clp
->cl_lock
);
447 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
449 do_renew_lease(server
->nfs_client
, timestamp
);
452 #if defined(CONFIG_NFS_V4_1)
454 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
456 struct nfs4_session
*session
;
457 struct nfs4_slot_table
*tbl
;
458 bool send_new_highest_used_slotid
= false;
461 /* just wake up the next guy waiting since
462 * we may have not consumed a slot after all */
463 dprintk("%s: No slot\n", __func__
);
466 tbl
= res
->sr_slot
->table
;
467 session
= tbl
->session
;
469 spin_lock(&tbl
->slot_tbl_lock
);
470 /* Be nice to the server: try to ensure that the last transmitted
471 * value for highest_user_slotid <= target_highest_slotid
473 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
474 send_new_highest_used_slotid
= true;
476 if (nfs41_wake_and_assign_slot(tbl
, res
->sr_slot
)) {
477 send_new_highest_used_slotid
= false;
480 nfs4_free_slot(tbl
, res
->sr_slot
);
482 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
483 send_new_highest_used_slotid
= false;
485 spin_unlock(&tbl
->slot_tbl_lock
);
487 if (send_new_highest_used_slotid
)
488 nfs41_server_notify_highest_slotid_update(session
->clp
);
491 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
493 struct nfs4_session
*session
;
494 struct nfs4_slot
*slot
;
495 struct nfs_client
*clp
;
496 bool interrupted
= false;
499 /* don't increment the sequence number if the task wasn't sent */
500 if (!RPC_WAS_SENT(task
))
504 session
= slot
->table
->session
;
506 if (slot
->interrupted
) {
507 slot
->interrupted
= 0;
511 /* Check the SEQUENCE operation status */
512 switch (res
->sr_status
) {
514 /* Update the slot's sequence and clientid lease timer */
517 do_renew_lease(clp
, res
->sr_timestamp
);
518 /* Check sequence flags */
519 if (res
->sr_status_flags
!= 0)
520 nfs4_schedule_lease_recovery(clp
);
521 nfs41_update_target_slotid(slot
->table
, slot
, res
);
525 * sr_status remains 1 if an RPC level error occurred.
526 * The server may or may not have processed the sequence
528 * Mark the slot as having hosted an interrupted RPC call.
530 slot
->interrupted
= 1;
533 /* The server detected a resend of the RPC call and
534 * returned NFS4ERR_DELAY as per Section 2.10.6.2
537 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
542 case -NFS4ERR_BADSLOT
:
544 * The slot id we used was probably retired. Try again
545 * using a different slot id.
548 case -NFS4ERR_SEQ_MISORDERED
:
550 * Was the last operation on this sequence interrupted?
551 * If so, retry after bumping the sequence number.
558 * Could this slot have been previously retired?
559 * If so, then the server may be expecting seq_nr = 1!
561 if (slot
->seq_nr
!= 1) {
566 case -NFS4ERR_SEQ_FALSE_RETRY
:
570 /* Just update the slot sequence no. */
574 /* The session may be reset by one of the error handlers. */
575 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
576 nfs41_sequence_free_slot(res
);
579 if (rpc_restart_call_prepare(task
)) {
585 if (!rpc_restart_call(task
))
587 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
591 static int nfs4_sequence_done(struct rpc_task
*task
,
592 struct nfs4_sequence_res
*res
)
594 if (res
->sr_slot
== NULL
)
596 return nfs41_sequence_done(task
, res
);
599 static void nfs41_init_sequence(struct nfs4_sequence_args
*args
,
600 struct nfs4_sequence_res
*res
, int cache_reply
)
602 args
->sa_slot
= NULL
;
603 args
->sa_cache_this
= 0;
604 args
->sa_privileged
= 0;
606 args
->sa_cache_this
= 1;
610 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
612 args
->sa_privileged
= 1;
615 int nfs41_setup_sequence(struct nfs4_session
*session
,
616 struct nfs4_sequence_args
*args
,
617 struct nfs4_sequence_res
*res
,
618 struct rpc_task
*task
)
620 struct nfs4_slot
*slot
;
621 struct nfs4_slot_table
*tbl
;
623 dprintk("--> %s\n", __func__
);
624 /* slot already allocated? */
625 if (res
->sr_slot
!= NULL
)
628 tbl
= &session
->fc_slot_table
;
630 task
->tk_timeout
= 0;
632 spin_lock(&tbl
->slot_tbl_lock
);
633 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
634 !args
->sa_privileged
) {
635 /* The state manager will wait until the slot table is empty */
636 dprintk("%s session is draining\n", __func__
);
640 slot
= nfs4_alloc_slot(tbl
);
642 /* If out of memory, try again in 1/4 second */
643 if (slot
== ERR_PTR(-ENOMEM
))
644 task
->tk_timeout
= HZ
>> 2;
645 dprintk("<-- %s: no free slots\n", __func__
);
648 spin_unlock(&tbl
->slot_tbl_lock
);
650 args
->sa_slot
= slot
;
652 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
,
653 slot
->slot_nr
, slot
->seq_nr
);
656 res
->sr_timestamp
= jiffies
;
657 res
->sr_status_flags
= 0;
659 * sr_status is only set in decode_sequence, and so will remain
660 * set to 1 if an rpc level failure occurs.
664 rpc_call_start(task
);
667 /* Privileged tasks are queued with top priority */
668 if (args
->sa_privileged
)
669 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
670 NULL
, RPC_PRIORITY_PRIVILEGED
);
672 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
673 spin_unlock(&tbl
->slot_tbl_lock
);
676 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
678 int nfs4_setup_sequence(const struct nfs_server
*server
,
679 struct nfs4_sequence_args
*args
,
680 struct nfs4_sequence_res
*res
,
681 struct rpc_task
*task
)
683 struct nfs4_session
*session
= nfs4_get_session(server
);
686 if (session
== NULL
) {
687 rpc_call_start(task
);
691 dprintk("--> %s clp %p session %p sr_slot %d\n",
692 __func__
, session
->clp
, session
, res
->sr_slot
?
693 res
->sr_slot
->slot_nr
: -1);
695 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
697 dprintk("<-- %s status=%d\n", __func__
, ret
);
701 struct nfs41_call_sync_data
{
702 const struct nfs_server
*seq_server
;
703 struct nfs4_sequence_args
*seq_args
;
704 struct nfs4_sequence_res
*seq_res
;
707 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
709 struct nfs41_call_sync_data
*data
= calldata
;
710 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
712 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
714 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
717 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
719 struct nfs41_call_sync_data
*data
= calldata
;
721 nfs41_sequence_done(task
, data
->seq_res
);
724 static const struct rpc_call_ops nfs41_call_sync_ops
= {
725 .rpc_call_prepare
= nfs41_call_sync_prepare
,
726 .rpc_call_done
= nfs41_call_sync_done
,
729 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
730 struct nfs_server
*server
,
731 struct rpc_message
*msg
,
732 struct nfs4_sequence_args
*args
,
733 struct nfs4_sequence_res
*res
)
736 struct rpc_task
*task
;
737 struct nfs41_call_sync_data data
= {
738 .seq_server
= server
,
742 struct rpc_task_setup task_setup
= {
745 .callback_ops
= &nfs41_call_sync_ops
,
746 .callback_data
= &data
749 task
= rpc_run_task(&task_setup
);
753 ret
= task
->tk_status
;
761 void nfs41_init_sequence(struct nfs4_sequence_args
*args
,
762 struct nfs4_sequence_res
*res
, int cache_reply
)
766 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
771 static int nfs4_sequence_done(struct rpc_task
*task
,
772 struct nfs4_sequence_res
*res
)
776 #endif /* CONFIG_NFS_V4_1 */
779 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
780 struct nfs_server
*server
,
781 struct rpc_message
*msg
,
782 struct nfs4_sequence_args
*args
,
783 struct nfs4_sequence_res
*res
)
785 return rpc_call_sync(clnt
, msg
, 0);
789 int nfs4_call_sync(struct rpc_clnt
*clnt
,
790 struct nfs_server
*server
,
791 struct rpc_message
*msg
,
792 struct nfs4_sequence_args
*args
,
793 struct nfs4_sequence_res
*res
,
796 nfs41_init_sequence(args
, res
, cache_reply
);
797 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
801 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
803 struct nfs_inode
*nfsi
= NFS_I(dir
);
805 spin_lock(&dir
->i_lock
);
806 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
807 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
808 nfs_force_lookup_revalidate(dir
);
809 dir
->i_version
= cinfo
->after
;
810 nfs_fscache_invalidate(dir
);
811 spin_unlock(&dir
->i_lock
);
814 struct nfs4_opendata
{
816 struct nfs_openargs o_arg
;
817 struct nfs_openres o_res
;
818 struct nfs_open_confirmargs c_arg
;
819 struct nfs_open_confirmres c_res
;
820 struct nfs4_string owner_name
;
821 struct nfs4_string group_name
;
822 struct nfs_fattr f_attr
;
823 struct nfs4_label
*f_label
;
825 struct dentry
*dentry
;
826 struct nfs4_state_owner
*owner
;
827 struct nfs4_state
*state
;
829 unsigned long timestamp
;
830 unsigned int rpc_done
: 1;
831 unsigned int is_recover
: 1;
836 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
837 int err
, struct nfs4_exception
*exception
)
841 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
843 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
844 exception
->retry
= 1;
848 static enum open_claim_type4
849 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
850 enum open_claim_type4 claim
)
852 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
857 case NFS4_OPEN_CLAIM_FH
:
858 return NFS4_OPEN_CLAIM_NULL
;
859 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
860 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
861 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
862 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
866 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
868 p
->o_res
.f_attr
= &p
->f_attr
;
869 p
->o_res
.f_label
= p
->f_label
;
870 p
->o_res
.seqid
= p
->o_arg
.seqid
;
871 p
->c_res
.seqid
= p
->c_arg
.seqid
;
872 p
->o_res
.server
= p
->o_arg
.server
;
873 p
->o_res
.access_request
= p
->o_arg
.access
;
874 nfs_fattr_init(&p
->f_attr
);
875 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
878 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
879 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
880 const struct iattr
*attrs
,
881 struct nfs4_label
*label
,
882 enum open_claim_type4 claim
,
885 struct dentry
*parent
= dget_parent(dentry
);
886 struct inode
*dir
= parent
->d_inode
;
887 struct nfs_server
*server
= NFS_SERVER(dir
);
888 struct nfs4_opendata
*p
;
890 p
= kzalloc(sizeof(*p
), gfp_mask
);
894 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
895 if (IS_ERR(p
->f_label
))
898 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
899 if (p
->o_arg
.seqid
== NULL
)
901 nfs_sb_active(dentry
->d_sb
);
902 p
->dentry
= dget(dentry
);
905 atomic_inc(&sp
->so_count
);
906 p
->o_arg
.open_flags
= flags
;
907 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
908 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
909 * will return permission denied for all bits until close */
910 if (!(flags
& O_EXCL
)) {
911 /* ask server to check for all possible rights as results
913 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
914 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
916 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
917 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
918 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
919 p
->o_arg
.name
= &dentry
->d_name
;
920 p
->o_arg
.server
= server
;
921 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
922 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
923 p
->o_arg
.label
= label
;
924 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
925 switch (p
->o_arg
.claim
) {
926 case NFS4_OPEN_CLAIM_NULL
:
927 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
928 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
929 p
->o_arg
.fh
= NFS_FH(dir
);
931 case NFS4_OPEN_CLAIM_PREVIOUS
:
932 case NFS4_OPEN_CLAIM_FH
:
933 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
934 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
935 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
937 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
940 p
->o_arg
.u
.attrs
= &p
->attrs
;
941 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
944 verf
[1] = current
->pid
;
945 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
946 sizeof(p
->o_arg
.u
.verifier
.data
));
948 p
->c_arg
.fh
= &p
->o_res
.fh
;
949 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
950 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
951 nfs4_init_opendata_res(p
);
956 nfs4_label_free(p
->f_label
);
964 static void nfs4_opendata_free(struct kref
*kref
)
966 struct nfs4_opendata
*p
= container_of(kref
,
967 struct nfs4_opendata
, kref
);
968 struct super_block
*sb
= p
->dentry
->d_sb
;
970 nfs_free_seqid(p
->o_arg
.seqid
);
971 if (p
->state
!= NULL
)
972 nfs4_put_open_state(p
->state
);
973 nfs4_put_state_owner(p
->owner
);
975 nfs4_label_free(p
->f_label
);
980 nfs_fattr_free_names(&p
->f_attr
);
984 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
987 kref_put(&p
->kref
, nfs4_opendata_free
);
990 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
994 ret
= rpc_wait_for_completion_task(task
);
998 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1002 if (open_mode
& (O_EXCL
|O_TRUNC
))
1004 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1006 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1007 && state
->n_rdonly
!= 0;
1010 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1011 && state
->n_wronly
!= 0;
1013 case FMODE_READ
|FMODE_WRITE
:
1014 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1015 && state
->n_rdwr
!= 0;
1021 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1023 if (delegation
== NULL
)
1025 if ((delegation
->type
& fmode
) != fmode
)
1027 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1029 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1031 nfs_mark_delegation_referenced(delegation
);
1035 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1044 case FMODE_READ
|FMODE_WRITE
:
1047 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1050 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1052 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1053 nfs4_stateid_copy(&state
->stateid
, stateid
);
1054 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1055 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1058 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1061 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1063 case FMODE_READ
|FMODE_WRITE
:
1064 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1068 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1070 write_seqlock(&state
->seqlock
);
1071 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
1072 write_sequnlock(&state
->seqlock
);
1075 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1078 * Protect the call to nfs4_state_set_mode_locked and
1079 * serialise the stateid update
1081 write_seqlock(&state
->seqlock
);
1082 if (deleg_stateid
!= NULL
) {
1083 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1084 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1086 if (open_stateid
!= NULL
)
1087 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1088 write_sequnlock(&state
->seqlock
);
1089 spin_lock(&state
->owner
->so_lock
);
1090 update_open_stateflags(state
, fmode
);
1091 spin_unlock(&state
->owner
->so_lock
);
1094 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1096 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1097 struct nfs_delegation
*deleg_cur
;
1100 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1103 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1104 if (deleg_cur
== NULL
)
1107 spin_lock(&deleg_cur
->lock
);
1108 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1109 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1110 (deleg_cur
->type
& fmode
) != fmode
)
1111 goto no_delegation_unlock
;
1113 if (delegation
== NULL
)
1114 delegation
= &deleg_cur
->stateid
;
1115 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1116 goto no_delegation_unlock
;
1118 nfs_mark_delegation_referenced(deleg_cur
);
1119 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1121 no_delegation_unlock
:
1122 spin_unlock(&deleg_cur
->lock
);
1126 if (!ret
&& open_stateid
!= NULL
) {
1127 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1135 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1137 struct nfs_delegation
*delegation
;
1140 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1141 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1146 nfs4_inode_return_delegation(inode
);
1149 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1151 struct nfs4_state
*state
= opendata
->state
;
1152 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1153 struct nfs_delegation
*delegation
;
1154 int open_mode
= opendata
->o_arg
.open_flags
;
1155 fmode_t fmode
= opendata
->o_arg
.fmode
;
1156 nfs4_stateid stateid
;
1160 if (can_open_cached(state
, fmode
, open_mode
)) {
1161 spin_lock(&state
->owner
->so_lock
);
1162 if (can_open_cached(state
, fmode
, open_mode
)) {
1163 update_open_stateflags(state
, fmode
);
1164 spin_unlock(&state
->owner
->so_lock
);
1165 goto out_return_state
;
1167 spin_unlock(&state
->owner
->so_lock
);
1170 delegation
= rcu_dereference(nfsi
->delegation
);
1171 if (!can_open_delegated(delegation
, fmode
)) {
1175 /* Save the delegation */
1176 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1178 nfs_release_seqid(opendata
->o_arg
.seqid
);
1179 if (!opendata
->is_recover
) {
1180 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1186 /* Try to update the stateid using the delegation */
1187 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1188 goto out_return_state
;
1191 return ERR_PTR(ret
);
1193 atomic_inc(&state
->count
);
1198 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1200 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1201 struct nfs_delegation
*delegation
;
1202 int delegation_flags
= 0;
1205 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1207 delegation_flags
= delegation
->flags
;
1209 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1210 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1211 "returning a delegation for "
1212 "OPEN(CLAIM_DELEGATE_CUR)\n",
1214 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1215 nfs_inode_set_delegation(state
->inode
,
1216 data
->owner
->so_cred
,
1219 nfs_inode_reclaim_delegation(state
->inode
,
1220 data
->owner
->so_cred
,
1225 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1226 * and update the nfs4_state.
1228 static struct nfs4_state
*
1229 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1231 struct inode
*inode
= data
->state
->inode
;
1232 struct nfs4_state
*state
= data
->state
;
1235 if (!data
->rpc_done
) {
1236 ret
= data
->rpc_status
;
1241 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR_TYPE
) ||
1242 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_FILEID
) ||
1243 !(data
->f_attr
.valid
& NFS_ATTR_FATTR_CHANGE
))
1247 state
= nfs4_get_open_state(inode
, data
->owner
);
1251 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1255 nfs_setsecurity(inode
, &data
->f_attr
, data
->f_label
);
1257 if (data
->o_res
.delegation_type
!= 0)
1258 nfs4_opendata_check_deleg(data
, state
);
1259 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1264 return ERR_PTR(ret
);
1268 static struct nfs4_state
*
1269 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1271 struct inode
*inode
;
1272 struct nfs4_state
*state
= NULL
;
1275 if (!data
->rpc_done
) {
1276 state
= nfs4_try_open_cached(data
);
1281 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1283 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1284 ret
= PTR_ERR(inode
);
1288 state
= nfs4_get_open_state(inode
, data
->owner
);
1291 if (data
->o_res
.delegation_type
!= 0)
1292 nfs4_opendata_check_deleg(data
, state
);
1293 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1297 nfs_release_seqid(data
->o_arg
.seqid
);
1302 return ERR_PTR(ret
);
1305 static struct nfs4_state
*
1306 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1308 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1309 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1310 return _nfs4_opendata_to_nfs4_state(data
);
1313 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1315 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1316 struct nfs_open_context
*ctx
;
1318 spin_lock(&state
->inode
->i_lock
);
1319 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1320 if (ctx
->state
!= state
)
1322 get_nfs_open_context(ctx
);
1323 spin_unlock(&state
->inode
->i_lock
);
1326 spin_unlock(&state
->inode
->i_lock
);
1327 return ERR_PTR(-ENOENT
);
1330 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1331 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1333 struct nfs4_opendata
*opendata
;
1335 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1336 NULL
, NULL
, claim
, GFP_NOFS
);
1337 if (opendata
== NULL
)
1338 return ERR_PTR(-ENOMEM
);
1339 opendata
->state
= state
;
1340 atomic_inc(&state
->count
);
1344 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1346 struct nfs4_state
*newstate
;
1349 opendata
->o_arg
.open_flags
= 0;
1350 opendata
->o_arg
.fmode
= fmode
;
1351 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1352 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1353 nfs4_init_opendata_res(opendata
);
1354 ret
= _nfs4_recover_proc_open(opendata
);
1357 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1358 if (IS_ERR(newstate
))
1359 return PTR_ERR(newstate
);
1360 nfs4_close_state(newstate
, fmode
);
1365 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1367 struct nfs4_state
*newstate
;
1370 /* memory barrier prior to reading state->n_* */
1371 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1372 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1374 if (state
->n_rdwr
!= 0) {
1375 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1376 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1379 if (newstate
!= state
)
1382 if (state
->n_wronly
!= 0) {
1383 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1384 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1387 if (newstate
!= state
)
1390 if (state
->n_rdonly
!= 0) {
1391 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1392 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1395 if (newstate
!= state
)
1399 * We may have performed cached opens for all three recoveries.
1400 * Check if we need to update the current stateid.
1402 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1403 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1404 write_seqlock(&state
->seqlock
);
1405 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1406 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1407 write_sequnlock(&state
->seqlock
);
1414 * reclaim state on the server after a reboot.
1416 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1418 struct nfs_delegation
*delegation
;
1419 struct nfs4_opendata
*opendata
;
1420 fmode_t delegation_type
= 0;
1423 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1424 NFS4_OPEN_CLAIM_PREVIOUS
);
1425 if (IS_ERR(opendata
))
1426 return PTR_ERR(opendata
);
1428 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1429 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1430 delegation_type
= delegation
->type
;
1432 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1433 status
= nfs4_open_recover(opendata
, state
);
1434 nfs4_opendata_put(opendata
);
1438 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1440 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1441 struct nfs4_exception exception
= { };
1444 err
= _nfs4_do_open_reclaim(ctx
, state
);
1445 trace_nfs4_open_reclaim(ctx
, 0, err
);
1446 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1448 if (err
!= -NFS4ERR_DELAY
)
1450 nfs4_handle_exception(server
, err
, &exception
);
1451 } while (exception
.retry
);
1455 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1457 struct nfs_open_context
*ctx
;
1460 ctx
= nfs4_state_find_open_context(state
);
1463 ret
= nfs4_do_open_reclaim(ctx
, state
);
1464 put_nfs_open_context(ctx
);
1468 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1472 printk(KERN_ERR
"NFS: %s: unhandled error "
1473 "%d.\n", __func__
, err
);
1478 case -NFS4ERR_BADSESSION
:
1479 case -NFS4ERR_BADSLOT
:
1480 case -NFS4ERR_BAD_HIGH_SLOT
:
1481 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1482 case -NFS4ERR_DEADSESSION
:
1483 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1484 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1486 case -NFS4ERR_STALE_CLIENTID
:
1487 case -NFS4ERR_STALE_STATEID
:
1488 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1489 case -NFS4ERR_EXPIRED
:
1490 /* Don't recall a delegation if it was lost */
1491 nfs4_schedule_lease_recovery(server
->nfs_client
);
1493 case -NFS4ERR_DELEG_REVOKED
:
1494 case -NFS4ERR_ADMIN_REVOKED
:
1495 case -NFS4ERR_BAD_STATEID
:
1496 case -NFS4ERR_OPENMODE
:
1497 nfs_inode_find_state_and_recover(state
->inode
,
1499 nfs4_schedule_stateid_recovery(server
, state
);
1501 case -NFS4ERR_DELAY
:
1502 case -NFS4ERR_GRACE
:
1503 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1507 case -NFS4ERR_DENIED
:
1508 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1514 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1516 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1517 struct nfs4_opendata
*opendata
;
1520 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1521 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1522 if (IS_ERR(opendata
))
1523 return PTR_ERR(opendata
);
1524 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1525 err
= nfs4_open_recover(opendata
, state
);
1526 nfs4_opendata_put(opendata
);
1527 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1530 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1532 struct nfs4_opendata
*data
= calldata
;
1534 data
->rpc_status
= task
->tk_status
;
1535 if (data
->rpc_status
== 0) {
1536 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1537 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1538 renew_lease(data
->o_res
.server
, data
->timestamp
);
1543 static void nfs4_open_confirm_release(void *calldata
)
1545 struct nfs4_opendata
*data
= calldata
;
1546 struct nfs4_state
*state
= NULL
;
1548 /* If this request hasn't been cancelled, do nothing */
1549 if (data
->cancelled
== 0)
1551 /* In case of error, no cleanup! */
1552 if (!data
->rpc_done
)
1554 state
= nfs4_opendata_to_nfs4_state(data
);
1556 nfs4_close_state(state
, data
->o_arg
.fmode
);
1558 nfs4_opendata_put(data
);
1561 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1562 .rpc_call_done
= nfs4_open_confirm_done
,
1563 .rpc_release
= nfs4_open_confirm_release
,
1567 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1569 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1571 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1572 struct rpc_task
*task
;
1573 struct rpc_message msg
= {
1574 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1575 .rpc_argp
= &data
->c_arg
,
1576 .rpc_resp
= &data
->c_res
,
1577 .rpc_cred
= data
->owner
->so_cred
,
1579 struct rpc_task_setup task_setup_data
= {
1580 .rpc_client
= server
->client
,
1581 .rpc_message
= &msg
,
1582 .callback_ops
= &nfs4_open_confirm_ops
,
1583 .callback_data
= data
,
1584 .workqueue
= nfsiod_workqueue
,
1585 .flags
= RPC_TASK_ASYNC
,
1589 kref_get(&data
->kref
);
1591 data
->rpc_status
= 0;
1592 data
->timestamp
= jiffies
;
1593 task
= rpc_run_task(&task_setup_data
);
1595 return PTR_ERR(task
);
1596 status
= nfs4_wait_for_completion_rpc_task(task
);
1598 data
->cancelled
= 1;
1601 status
= data
->rpc_status
;
1606 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1608 struct nfs4_opendata
*data
= calldata
;
1609 struct nfs4_state_owner
*sp
= data
->owner
;
1610 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1612 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1615 * Check if we still need to send an OPEN call, or if we can use
1616 * a delegation instead.
1618 if (data
->state
!= NULL
) {
1619 struct nfs_delegation
*delegation
;
1621 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1624 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1625 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1626 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1627 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1628 goto unlock_no_action
;
1631 /* Update client id. */
1632 data
->o_arg
.clientid
= clp
->cl_clientid
;
1633 switch (data
->o_arg
.claim
) {
1634 case NFS4_OPEN_CLAIM_PREVIOUS
:
1635 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1636 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1637 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1638 case NFS4_OPEN_CLAIM_FH
:
1639 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1640 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1642 data
->timestamp
= jiffies
;
1643 if (nfs4_setup_sequence(data
->o_arg
.server
,
1644 &data
->o_arg
.seq_args
,
1645 &data
->o_res
.seq_res
,
1647 nfs_release_seqid(data
->o_arg
.seqid
);
1649 /* Set the create mode (note dependency on the session type) */
1650 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1651 if (data
->o_arg
.open_flags
& O_EXCL
) {
1652 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1653 if (nfs4_has_persistent_session(clp
))
1654 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1655 else if (clp
->cl_mvops
->minor_version
> 0)
1656 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1662 task
->tk_action
= NULL
;
1664 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1667 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1669 struct nfs4_opendata
*data
= calldata
;
1671 data
->rpc_status
= task
->tk_status
;
1673 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1676 if (task
->tk_status
== 0) {
1677 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1678 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1682 data
->rpc_status
= -ELOOP
;
1685 data
->rpc_status
= -EISDIR
;
1688 data
->rpc_status
= -ENOTDIR
;
1691 renew_lease(data
->o_res
.server
, data
->timestamp
);
1692 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1693 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1698 static void nfs4_open_release(void *calldata
)
1700 struct nfs4_opendata
*data
= calldata
;
1701 struct nfs4_state
*state
= NULL
;
1703 /* If this request hasn't been cancelled, do nothing */
1704 if (data
->cancelled
== 0)
1706 /* In case of error, no cleanup! */
1707 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1709 /* In case we need an open_confirm, no cleanup! */
1710 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1712 state
= nfs4_opendata_to_nfs4_state(data
);
1714 nfs4_close_state(state
, data
->o_arg
.fmode
);
1716 nfs4_opendata_put(data
);
1719 static const struct rpc_call_ops nfs4_open_ops
= {
1720 .rpc_call_prepare
= nfs4_open_prepare
,
1721 .rpc_call_done
= nfs4_open_done
,
1722 .rpc_release
= nfs4_open_release
,
1725 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1727 struct inode
*dir
= data
->dir
->d_inode
;
1728 struct nfs_server
*server
= NFS_SERVER(dir
);
1729 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1730 struct nfs_openres
*o_res
= &data
->o_res
;
1731 struct rpc_task
*task
;
1732 struct rpc_message msg
= {
1733 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1736 .rpc_cred
= data
->owner
->so_cred
,
1738 struct rpc_task_setup task_setup_data
= {
1739 .rpc_client
= server
->client
,
1740 .rpc_message
= &msg
,
1741 .callback_ops
= &nfs4_open_ops
,
1742 .callback_data
= data
,
1743 .workqueue
= nfsiod_workqueue
,
1744 .flags
= RPC_TASK_ASYNC
,
1748 nfs41_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1749 kref_get(&data
->kref
);
1751 data
->rpc_status
= 0;
1752 data
->cancelled
= 0;
1753 data
->is_recover
= 0;
1755 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1756 data
->is_recover
= 1;
1758 task
= rpc_run_task(&task_setup_data
);
1760 return PTR_ERR(task
);
1761 status
= nfs4_wait_for_completion_rpc_task(task
);
1763 data
->cancelled
= 1;
1766 status
= data
->rpc_status
;
1772 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1774 struct inode
*dir
= data
->dir
->d_inode
;
1775 struct nfs_openres
*o_res
= &data
->o_res
;
1778 status
= nfs4_run_open_task(data
, 1);
1779 if (status
!= 0 || !data
->rpc_done
)
1782 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1784 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1785 status
= _nfs4_proc_open_confirm(data
);
1793 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1794 struct nfs4_opendata
*opendata
,
1795 struct nfs4_state
*state
, fmode_t fmode
,
1798 struct nfs_access_entry cache
;
1801 /* access call failed or for some reason the server doesn't
1802 * support any access modes -- defer access call until later */
1803 if (opendata
->o_res
.access_supported
== 0)
1807 /* don't check MAY_WRITE - a newly created file may not have
1808 * write mode bits, but POSIX allows the creating process to write.
1809 * use openflags to check for exec, because fmode won't
1810 * always have FMODE_EXEC set when file open for exec. */
1811 if (openflags
& __FMODE_EXEC
) {
1812 /* ONLY check for exec rights */
1814 } else if (fmode
& FMODE_READ
)
1818 cache
.jiffies
= jiffies
;
1819 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1820 nfs_access_add_cache(state
->inode
, &cache
);
1822 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
1825 /* even though OPEN succeeded, access is denied. Close the file */
1826 nfs4_close_state(state
, fmode
);
1831 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1833 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1835 struct inode
*dir
= data
->dir
->d_inode
;
1836 struct nfs_server
*server
= NFS_SERVER(dir
);
1837 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1838 struct nfs_openres
*o_res
= &data
->o_res
;
1841 status
= nfs4_run_open_task(data
, 0);
1842 if (!data
->rpc_done
)
1845 if (status
== -NFS4ERR_BADNAME
&&
1846 !(o_arg
->open_flags
& O_CREAT
))
1851 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
1853 if (o_arg
->open_flags
& O_CREAT
)
1854 update_changeattr(dir
, &o_res
->cinfo
);
1855 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1856 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1857 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1858 status
= _nfs4_proc_open_confirm(data
);
1862 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1863 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
1867 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1869 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1874 * reclaim state on the server after a network partition.
1875 * Assumes caller holds the appropriate lock
1877 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1879 struct nfs4_opendata
*opendata
;
1882 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1883 NFS4_OPEN_CLAIM_FH
);
1884 if (IS_ERR(opendata
))
1885 return PTR_ERR(opendata
);
1886 ret
= nfs4_open_recover(opendata
, state
);
1888 d_drop(ctx
->dentry
);
1889 nfs4_opendata_put(opendata
);
1893 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1895 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1896 struct nfs4_exception exception
= { };
1900 err
= _nfs4_open_expired(ctx
, state
);
1901 trace_nfs4_open_expired(ctx
, 0, err
);
1902 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1907 case -NFS4ERR_GRACE
:
1908 case -NFS4ERR_DELAY
:
1909 nfs4_handle_exception(server
, err
, &exception
);
1912 } while (exception
.retry
);
1917 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1919 struct nfs_open_context
*ctx
;
1922 ctx
= nfs4_state_find_open_context(state
);
1925 ret
= nfs4_do_open_expired(ctx
, state
);
1926 put_nfs_open_context(ctx
);
1930 #if defined(CONFIG_NFS_V4_1)
1931 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
1933 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1934 nfs4_stateid
*stateid
= &state
->stateid
;
1935 struct nfs_delegation
*delegation
;
1936 struct rpc_cred
*cred
= NULL
;
1937 int status
= -NFS4ERR_BAD_STATEID
;
1939 /* If a state reset has been done, test_stateid is unneeded */
1940 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1943 /* Get the delegation credential for use by test/free_stateid */
1945 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1946 if (delegation
!= NULL
&&
1947 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
1948 cred
= get_rpccred(delegation
->cred
);
1950 status
= nfs41_test_stateid(server
, stateid
, cred
);
1954 if (status
!= NFS_OK
) {
1955 /* Free the stateid unless the server explicitly
1956 * informs us the stateid is unrecognized. */
1957 if (status
!= -NFS4ERR_BAD_STATEID
)
1958 nfs41_free_stateid(server
, stateid
, cred
);
1959 nfs_remove_bad_delegation(state
->inode
);
1961 write_seqlock(&state
->seqlock
);
1962 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1963 write_sequnlock(&state
->seqlock
);
1964 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1972 * nfs41_check_open_stateid - possibly free an open stateid
1974 * @state: NFSv4 state for an inode
1976 * Returns NFS_OK if recovery for this stateid is now finished.
1977 * Otherwise a negative NFS4ERR value is returned.
1979 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
1981 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1982 nfs4_stateid
*stateid
= &state
->open_stateid
;
1983 struct rpc_cred
*cred
= state
->owner
->so_cred
;
1986 /* If a state reset has been done, test_stateid is unneeded */
1987 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
1988 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
1989 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
1990 return -NFS4ERR_BAD_STATEID
;
1992 status
= nfs41_test_stateid(server
, stateid
, cred
);
1993 if (status
!= NFS_OK
) {
1994 /* Free the stateid unless the server explicitly
1995 * informs us the stateid is unrecognized. */
1996 if (status
!= -NFS4ERR_BAD_STATEID
)
1997 nfs41_free_stateid(server
, stateid
, cred
);
1999 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2000 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2001 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2002 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2007 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2011 nfs41_clear_delegation_stateid(state
);
2012 status
= nfs41_check_open_stateid(state
);
2013 if (status
!= NFS_OK
)
2014 status
= nfs4_open_expired(sp
, state
);
2020 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2021 * fields corresponding to attributes that were used to store the verifier.
2022 * Make sure we clobber those fields in the later setattr call
2024 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2026 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2027 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2028 sattr
->ia_valid
|= ATTR_ATIME
;
2030 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2031 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2032 sattr
->ia_valid
|= ATTR_MTIME
;
2035 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2038 struct nfs_open_context
*ctx
)
2040 struct nfs4_state_owner
*sp
= opendata
->owner
;
2041 struct nfs_server
*server
= sp
->so_server
;
2042 struct dentry
*dentry
;
2043 struct nfs4_state
*state
;
2047 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2049 ret
= _nfs4_proc_open(opendata
);
2053 state
= nfs4_opendata_to_nfs4_state(opendata
);
2054 ret
= PTR_ERR(state
);
2057 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2058 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2060 dentry
= opendata
->dentry
;
2061 if (dentry
->d_inode
== NULL
) {
2062 /* FIXME: Is this d_drop() ever needed? */
2064 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2065 if (dentry
== NULL
) {
2066 dentry
= opendata
->dentry
;
2067 } else if (dentry
!= ctx
->dentry
) {
2069 ctx
->dentry
= dget(dentry
);
2071 nfs_set_verifier(dentry
,
2072 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2075 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2080 if (dentry
->d_inode
== state
->inode
) {
2081 nfs_inode_attach_open_context(ctx
);
2082 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2083 nfs4_schedule_stateid_recovery(server
, state
);
2090 * Returns a referenced nfs4_state
2092 static int _nfs4_do_open(struct inode
*dir
,
2093 struct nfs_open_context
*ctx
,
2095 struct iattr
*sattr
,
2096 struct nfs4_label
*label
)
2098 struct nfs4_state_owner
*sp
;
2099 struct nfs4_state
*state
= NULL
;
2100 struct nfs_server
*server
= NFS_SERVER(dir
);
2101 struct nfs4_opendata
*opendata
;
2102 struct dentry
*dentry
= ctx
->dentry
;
2103 struct rpc_cred
*cred
= ctx
->cred
;
2104 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2105 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2106 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2107 struct nfs4_label
*olabel
= NULL
;
2110 /* Protect against reboot recovery conflicts */
2112 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2114 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2117 status
= nfs4_recover_expired_lease(server
);
2119 goto err_put_state_owner
;
2120 if (dentry
->d_inode
!= NULL
)
2121 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2123 if (dentry
->d_inode
)
2124 claim
= NFS4_OPEN_CLAIM_FH
;
2125 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2126 label
, claim
, GFP_KERNEL
);
2127 if (opendata
== NULL
)
2128 goto err_put_state_owner
;
2131 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2132 if (IS_ERR(olabel
)) {
2133 status
= PTR_ERR(olabel
);
2134 goto err_opendata_put
;
2138 if (ctx_th
&& server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2139 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2140 if (!opendata
->f_attr
.mdsthreshold
)
2141 goto err_free_label
;
2142 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2144 if (dentry
->d_inode
!= NULL
)
2145 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2147 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2149 goto err_free_label
;
2152 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2153 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2154 nfs4_exclusive_attrset(opendata
, sattr
);
2156 nfs_fattr_init(opendata
->o_res
.f_attr
);
2157 status
= nfs4_do_setattr(state
->inode
, cred
,
2158 opendata
->o_res
.f_attr
, sattr
,
2159 state
, label
, olabel
);
2161 nfs_setattr_update_inode(state
->inode
, sattr
);
2162 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2163 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2167 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
))
2168 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2170 kfree(opendata
->f_attr
.mdsthreshold
);
2171 opendata
->f_attr
.mdsthreshold
= NULL
;
2173 nfs4_label_free(olabel
);
2175 nfs4_opendata_put(opendata
);
2176 nfs4_put_state_owner(sp
);
2179 nfs4_label_free(olabel
);
2181 kfree(opendata
->f_attr
.mdsthreshold
);
2182 nfs4_opendata_put(opendata
);
2183 err_put_state_owner
:
2184 nfs4_put_state_owner(sp
);
2190 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2191 struct nfs_open_context
*ctx
,
2193 struct iattr
*sattr
,
2194 struct nfs4_label
*label
)
2196 struct nfs_server
*server
= NFS_SERVER(dir
);
2197 struct nfs4_exception exception
= { };
2198 struct nfs4_state
*res
;
2202 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
);
2204 trace_nfs4_open_file(ctx
, flags
, status
);
2207 /* NOTE: BAD_SEQID means the server and client disagree about the
2208 * book-keeping w.r.t. state-changing operations
2209 * (OPEN/CLOSE/LOCK/LOCKU...)
2210 * It is actually a sign of a bug on the client or on the server.
2212 * If we receive a BAD_SEQID error in the particular case of
2213 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2214 * have unhashed the old state_owner for us, and that we can
2215 * therefore safely retry using a new one. We should still warn
2216 * the user though...
2218 if (status
== -NFS4ERR_BAD_SEQID
) {
2219 pr_warn_ratelimited("NFS: v4 server %s "
2220 " returned a bad sequence-id error!\n",
2221 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2222 exception
.retry
= 1;
2226 * BAD_STATEID on OPEN means that the server cancelled our
2227 * state before it received the OPEN_CONFIRM.
2228 * Recover by retrying the request as per the discussion
2229 * on Page 181 of RFC3530.
2231 if (status
== -NFS4ERR_BAD_STATEID
) {
2232 exception
.retry
= 1;
2235 if (status
== -EAGAIN
) {
2236 /* We must have found a delegation */
2237 exception
.retry
= 1;
2240 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2242 res
= ERR_PTR(nfs4_handle_exception(server
,
2243 status
, &exception
));
2244 } while (exception
.retry
);
2248 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2249 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2250 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2251 struct nfs4_label
*olabel
)
2253 struct nfs_server
*server
= NFS_SERVER(inode
);
2254 struct nfs_setattrargs arg
= {
2255 .fh
= NFS_FH(inode
),
2258 .bitmask
= server
->attr_bitmask
,
2261 struct nfs_setattrres res
= {
2266 struct rpc_message msg
= {
2267 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2272 unsigned long timestamp
= jiffies
;
2277 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2279 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2281 nfs_fattr_init(fattr
);
2283 /* Servers should only apply open mode checks for file size changes */
2284 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2285 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2287 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2288 /* Use that stateid */
2289 } else if (truncate
&& state
!= NULL
&& nfs4_valid_open_stateid(state
)) {
2290 struct nfs_lockowner lockowner
= {
2291 .l_owner
= current
->files
,
2292 .l_pid
= current
->tgid
,
2294 nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2297 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2299 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2300 if (status
== 0 && state
!= NULL
)
2301 renew_lease(server
, timestamp
);
2305 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2306 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2307 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2308 struct nfs4_label
*olabel
)
2310 struct nfs_server
*server
= NFS_SERVER(inode
);
2311 struct nfs4_exception exception
= {
2317 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2318 trace_nfs4_setattr(inode
, err
);
2320 case -NFS4ERR_OPENMODE
:
2321 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2322 pr_warn_once("NFSv4: server %s is incorrectly "
2323 "applying open mode checks to "
2324 "a SETATTR that is not "
2325 "changing file size.\n",
2326 server
->nfs_client
->cl_hostname
);
2328 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2330 if (sattr
->ia_valid
& ATTR_OPEN
)
2335 err
= nfs4_handle_exception(server
, err
, &exception
);
2336 } while (exception
.retry
);
2341 struct nfs4_closedata
{
2342 struct inode
*inode
;
2343 struct nfs4_state
*state
;
2344 struct nfs_closeargs arg
;
2345 struct nfs_closeres res
;
2346 struct nfs_fattr fattr
;
2347 unsigned long timestamp
;
2352 static void nfs4_free_closedata(void *data
)
2354 struct nfs4_closedata
*calldata
= data
;
2355 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2356 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2359 pnfs_roc_release(calldata
->state
->inode
);
2360 nfs4_put_open_state(calldata
->state
);
2361 nfs_free_seqid(calldata
->arg
.seqid
);
2362 nfs4_put_state_owner(sp
);
2363 nfs_sb_deactive(sb
);
2367 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
2370 spin_lock(&state
->owner
->so_lock
);
2371 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2372 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
2374 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2377 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2380 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2381 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2382 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2384 spin_unlock(&state
->owner
->so_lock
);
2387 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2389 struct nfs4_closedata
*calldata
= data
;
2390 struct nfs4_state
*state
= calldata
->state
;
2391 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2393 dprintk("%s: begin!\n", __func__
);
2394 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2396 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2397 /* hmm. we are done with the inode, and in the process of freeing
2398 * the state_owner. we keep this around to process errors
2400 switch (task
->tk_status
) {
2403 pnfs_roc_set_barrier(state
->inode
,
2404 calldata
->roc_barrier
);
2405 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
2406 renew_lease(server
, calldata
->timestamp
);
2407 nfs4_close_clear_stateid_flags(state
,
2408 calldata
->arg
.fmode
);
2410 case -NFS4ERR_STALE_STATEID
:
2411 case -NFS4ERR_OLD_STATEID
:
2412 case -NFS4ERR_BAD_STATEID
:
2413 case -NFS4ERR_EXPIRED
:
2414 if (calldata
->arg
.fmode
== 0)
2417 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
2418 rpc_restart_call_prepare(task
);
2420 nfs_release_seqid(calldata
->arg
.seqid
);
2421 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2422 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2425 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2427 struct nfs4_closedata
*calldata
= data
;
2428 struct nfs4_state
*state
= calldata
->state
;
2429 struct inode
*inode
= calldata
->inode
;
2432 dprintk("%s: begin!\n", __func__
);
2433 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2436 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2437 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
2438 spin_lock(&state
->owner
->so_lock
);
2439 /* Calculate the change in open mode */
2440 if (state
->n_rdwr
== 0) {
2441 if (state
->n_rdonly
== 0) {
2442 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2443 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2444 calldata
->arg
.fmode
&= ~FMODE_READ
;
2446 if (state
->n_wronly
== 0) {
2447 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2448 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2449 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2452 if (!nfs4_valid_open_stateid(state
))
2454 spin_unlock(&state
->owner
->so_lock
);
2457 /* Note: exit _without_ calling nfs4_close_done */
2461 if (calldata
->arg
.fmode
== 0) {
2462 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2463 if (calldata
->roc
&&
2464 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2465 nfs_release_seqid(calldata
->arg
.seqid
);
2470 nfs_fattr_init(calldata
->res
.fattr
);
2471 calldata
->timestamp
= jiffies
;
2472 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2473 &calldata
->arg
.seq_args
,
2474 &calldata
->res
.seq_res
,
2476 nfs_release_seqid(calldata
->arg
.seqid
);
2477 dprintk("%s: done!\n", __func__
);
2480 task
->tk_action
= NULL
;
2482 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2485 static const struct rpc_call_ops nfs4_close_ops
= {
2486 .rpc_call_prepare
= nfs4_close_prepare
,
2487 .rpc_call_done
= nfs4_close_done
,
2488 .rpc_release
= nfs4_free_closedata
,
2492 * It is possible for data to be read/written from a mem-mapped file
2493 * after the sys_close call (which hits the vfs layer as a flush).
2494 * This means that we can't safely call nfsv4 close on a file until
2495 * the inode is cleared. This in turn means that we are not good
2496 * NFSv4 citizens - we do not indicate to the server to update the file's
2497 * share state even when we are done with one of the three share
2498 * stateid's in the inode.
2500 * NOTE: Caller must be holding the sp->so_owner semaphore!
2502 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2504 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2505 struct nfs4_closedata
*calldata
;
2506 struct nfs4_state_owner
*sp
= state
->owner
;
2507 struct rpc_task
*task
;
2508 struct rpc_message msg
= {
2509 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2510 .rpc_cred
= state
->owner
->so_cred
,
2512 struct rpc_task_setup task_setup_data
= {
2513 .rpc_client
= server
->client
,
2514 .rpc_message
= &msg
,
2515 .callback_ops
= &nfs4_close_ops
,
2516 .workqueue
= nfsiod_workqueue
,
2517 .flags
= RPC_TASK_ASYNC
,
2519 int status
= -ENOMEM
;
2521 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2522 if (calldata
== NULL
)
2524 nfs41_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2525 calldata
->inode
= state
->inode
;
2526 calldata
->state
= state
;
2527 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2528 calldata
->arg
.stateid
= &state
->open_stateid
;
2529 /* Serialization for the sequence id */
2530 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2531 if (calldata
->arg
.seqid
== NULL
)
2532 goto out_free_calldata
;
2533 calldata
->arg
.fmode
= 0;
2534 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2535 calldata
->res
.fattr
= &calldata
->fattr
;
2536 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2537 calldata
->res
.server
= server
;
2538 calldata
->roc
= pnfs_roc(state
->inode
);
2539 nfs_sb_active(calldata
->inode
->i_sb
);
2541 msg
.rpc_argp
= &calldata
->arg
;
2542 msg
.rpc_resp
= &calldata
->res
;
2543 task_setup_data
.callback_data
= calldata
;
2544 task
= rpc_run_task(&task_setup_data
);
2546 return PTR_ERR(task
);
2549 status
= rpc_wait_for_completion_task(task
);
2555 nfs4_put_open_state(state
);
2556 nfs4_put_state_owner(sp
);
2560 static struct inode
*
2561 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2563 struct nfs4_state
*state
;
2564 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2566 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2568 /* Protect against concurrent sillydeletes */
2569 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
);
2571 nfs4_label_release_security(label
);
2574 return ERR_CAST(state
);
2575 return state
->inode
;
2578 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2580 if (ctx
->state
== NULL
)
2583 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2585 nfs4_close_state(ctx
->state
, ctx
->mode
);
2588 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2590 struct nfs4_server_caps_arg args
= {
2593 struct nfs4_server_caps_res res
= {};
2594 struct rpc_message msg
= {
2595 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2601 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2603 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2604 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2605 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2606 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2607 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2608 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2609 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2610 server
->caps
|= NFS_CAP_ACLS
;
2611 if (res
.has_links
!= 0)
2612 server
->caps
|= NFS_CAP_HARDLINKS
;
2613 if (res
.has_symlinks
!= 0)
2614 server
->caps
|= NFS_CAP_SYMLINKS
;
2615 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2616 server
->caps
|= NFS_CAP_FILEID
;
2617 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2618 server
->caps
|= NFS_CAP_MODE
;
2619 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2620 server
->caps
|= NFS_CAP_NLINK
;
2621 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2622 server
->caps
|= NFS_CAP_OWNER
;
2623 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2624 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2625 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2626 server
->caps
|= NFS_CAP_ATIME
;
2627 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2628 server
->caps
|= NFS_CAP_CTIME
;
2629 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2630 server
->caps
|= NFS_CAP_MTIME
;
2631 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2632 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2633 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2635 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2636 sizeof(server
->attr_bitmask
));
2638 if (server
->caps
& NFS_CAP_SECURITY_LABEL
) {
2639 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2640 res
.attr_bitmask
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2642 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2643 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2644 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2645 server
->acl_bitmask
= res
.acl_bitmask
;
2646 server
->fh_expire_type
= res
.fh_expire_type
;
2652 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2654 struct nfs4_exception exception
= { };
2657 err
= nfs4_handle_exception(server
,
2658 _nfs4_server_capabilities(server
, fhandle
),
2660 } while (exception
.retry
);
2664 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2665 struct nfs_fsinfo
*info
)
2668 struct nfs4_lookup_root_arg args
= {
2671 struct nfs4_lookup_res res
= {
2673 .fattr
= info
->fattr
,
2676 struct rpc_message msg
= {
2677 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2682 bitmask
[0] = nfs4_fattr_bitmap
[0];
2683 bitmask
[1] = nfs4_fattr_bitmap
[1];
2685 * Process the label in the upcoming getfattr
2687 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2689 nfs_fattr_init(info
->fattr
);
2690 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2693 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2694 struct nfs_fsinfo
*info
)
2696 struct nfs4_exception exception
= { };
2699 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2700 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2703 case -NFS4ERR_WRONGSEC
:
2706 err
= nfs4_handle_exception(server
, err
, &exception
);
2708 } while (exception
.retry
);
2713 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2714 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2716 struct rpc_auth
*auth
;
2719 auth
= rpcauth_create(flavor
, server
->client
);
2724 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2730 * Retry pseudoroot lookup with various security flavors. We do this when:
2732 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2733 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2735 * Returns zero on success, or a negative NFS4ERR value, or a
2736 * negative errno value.
2738 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2739 struct nfs_fsinfo
*info
)
2741 /* Per 3530bis 15.33.5 */
2742 static const rpc_authflavor_t flav_array
[] = {
2746 RPC_AUTH_UNIX
, /* courtesy */
2749 int status
= -EPERM
;
2752 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
2753 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2754 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2760 * -EACCESS could mean that the user doesn't have correct permissions
2761 * to access the mount. It could also mean that we tried to mount
2762 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2763 * existing mount programs don't handle -EACCES very well so it should
2764 * be mapped to -EPERM instead.
2766 if (status
== -EACCES
)
2771 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
2772 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
2774 int mv
= server
->nfs_client
->cl_minorversion
;
2775 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
2779 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2780 * @server: initialized nfs_server handle
2781 * @fhandle: we fill in the pseudo-fs root file handle
2782 * @info: we fill in an FSINFO struct
2784 * Returns zero on success, or a negative errno.
2786 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2787 struct nfs_fsinfo
*info
)
2791 status
= nfs4_lookup_root(server
, fhandle
, info
);
2792 if ((status
== -NFS4ERR_WRONGSEC
) &&
2793 !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2794 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
2797 status
= nfs4_server_capabilities(server
, fhandle
);
2799 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2801 return nfs4_map_errors(status
);
2804 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
2805 struct nfs_fsinfo
*info
)
2808 struct nfs_fattr
*fattr
= info
->fattr
;
2809 struct nfs4_label
*label
= NULL
;
2811 error
= nfs4_server_capabilities(server
, mntfh
);
2813 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
2817 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
2819 return PTR_ERR(label
);
2821 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
2823 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
2824 goto err_free_label
;
2827 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
2828 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
2829 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
2832 nfs4_label_free(label
);
2838 * Get locations and (maybe) other attributes of a referral.
2839 * Note that we'll actually follow the referral later when
2840 * we detect fsid mismatch in inode revalidation
2842 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
2843 const struct qstr
*name
, struct nfs_fattr
*fattr
,
2844 struct nfs_fh
*fhandle
)
2846 int status
= -ENOMEM
;
2847 struct page
*page
= NULL
;
2848 struct nfs4_fs_locations
*locations
= NULL
;
2850 page
= alloc_page(GFP_KERNEL
);
2853 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2854 if (locations
== NULL
)
2857 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
2860 /* Make sure server returned a different fsid for the referral */
2861 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2862 dprintk("%s: server did not return a different fsid for"
2863 " a referral at %s\n", __func__
, name
->name
);
2867 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2868 nfs_fixup_referral_attributes(&locations
->fattr
);
2870 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2871 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2872 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2880 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2881 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2883 struct nfs4_getattr_arg args
= {
2885 .bitmask
= server
->attr_bitmask
,
2887 struct nfs4_getattr_res res
= {
2892 struct rpc_message msg
= {
2893 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2898 args
.bitmask
= nfs4_bitmask(server
, label
);
2900 nfs_fattr_init(fattr
);
2901 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2904 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2905 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2907 struct nfs4_exception exception
= { };
2910 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
2911 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
2912 err
= nfs4_handle_exception(server
, err
,
2914 } while (exception
.retry
);
2919 * The file is not closed if it is opened due to the a request to change
2920 * the size of the file. The open call will not be needed once the
2921 * VFS layer lookup-intents are implemented.
2923 * Close is called when the inode is destroyed.
2924 * If we haven't opened the file for O_WRONLY, we
2925 * need to in the size_change case to obtain a stateid.
2928 * Because OPEN is always done by name in nfsv4, it is
2929 * possible that we opened a different file by the same
2930 * name. We can recognize this race condition, but we
2931 * can't do anything about it besides returning an error.
2933 * This will be fixed with VFS changes (lookup-intent).
2936 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2937 struct iattr
*sattr
)
2939 struct inode
*inode
= dentry
->d_inode
;
2940 struct rpc_cred
*cred
= NULL
;
2941 struct nfs4_state
*state
= NULL
;
2942 struct nfs4_label
*label
= NULL
;
2945 if (pnfs_ld_layoutret_on_setattr(inode
))
2946 pnfs_commit_and_return_layout(inode
);
2948 nfs_fattr_init(fattr
);
2950 /* Deal with open(O_TRUNC) */
2951 if (sattr
->ia_valid
& ATTR_OPEN
)
2952 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
2954 /* Optimization: if the end result is no change, don't RPC */
2955 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
2958 /* Search for an existing open(O_WRITE) file */
2959 if (sattr
->ia_valid
& ATTR_FILE
) {
2960 struct nfs_open_context
*ctx
;
2962 ctx
= nfs_file_open_context(sattr
->ia_file
);
2969 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
2971 return PTR_ERR(label
);
2973 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
2975 nfs_setattr_update_inode(inode
, sattr
);
2976 nfs_setsecurity(inode
, fattr
, label
);
2978 nfs4_label_free(label
);
2982 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
2983 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2984 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
2986 struct nfs_server
*server
= NFS_SERVER(dir
);
2988 struct nfs4_lookup_arg args
= {
2989 .bitmask
= server
->attr_bitmask
,
2990 .dir_fh
= NFS_FH(dir
),
2993 struct nfs4_lookup_res res
= {
2999 struct rpc_message msg
= {
3000 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3005 args
.bitmask
= nfs4_bitmask(server
, label
);
3007 nfs_fattr_init(fattr
);
3009 dprintk("NFS call lookup %s\n", name
->name
);
3010 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3011 dprintk("NFS reply lookup: %d\n", status
);
3015 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3017 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3018 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3019 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3023 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3024 struct qstr
*name
, struct nfs_fh
*fhandle
,
3025 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3027 struct nfs4_exception exception
= { };
3028 struct rpc_clnt
*client
= *clnt
;
3031 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3032 trace_nfs4_lookup(dir
, name
, err
);
3034 case -NFS4ERR_BADNAME
:
3037 case -NFS4ERR_MOVED
:
3038 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3040 case -NFS4ERR_WRONGSEC
:
3042 if (client
!= *clnt
)
3045 client
= nfs4_create_sec_client(client
, dir
, name
);
3047 return PTR_ERR(client
);
3049 exception
.retry
= 1;
3052 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3054 } while (exception
.retry
);
3059 else if (client
!= *clnt
)
3060 rpc_shutdown_client(client
);
3065 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3066 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3067 struct nfs4_label
*label
)
3070 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3072 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3073 if (client
!= NFS_CLIENT(dir
)) {
3074 rpc_shutdown_client(client
);
3075 nfs_fixup_secinfo_attributes(fattr
);
3081 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3082 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3085 struct rpc_clnt
*client
= rpc_clone_client(NFS_CLIENT(dir
));
3087 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3089 rpc_shutdown_client(client
);
3090 return ERR_PTR(status
);
3095 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3097 struct nfs_server
*server
= NFS_SERVER(inode
);
3098 struct nfs4_accessargs args
= {
3099 .fh
= NFS_FH(inode
),
3100 .bitmask
= server
->cache_consistency_bitmask
,
3102 struct nfs4_accessres res
= {
3105 struct rpc_message msg
= {
3106 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3109 .rpc_cred
= entry
->cred
,
3111 int mode
= entry
->mask
;
3115 * Determine which access bits we want to ask for...
3117 if (mode
& MAY_READ
)
3118 args
.access
|= NFS4_ACCESS_READ
;
3119 if (S_ISDIR(inode
->i_mode
)) {
3120 if (mode
& MAY_WRITE
)
3121 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3122 if (mode
& MAY_EXEC
)
3123 args
.access
|= NFS4_ACCESS_LOOKUP
;
3125 if (mode
& MAY_WRITE
)
3126 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3127 if (mode
& MAY_EXEC
)
3128 args
.access
|= NFS4_ACCESS_EXECUTE
;
3131 res
.fattr
= nfs_alloc_fattr();
3132 if (res
.fattr
== NULL
)
3135 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3137 nfs_access_set_mask(entry
, res
.access
);
3138 nfs_refresh_inode(inode
, res
.fattr
);
3140 nfs_free_fattr(res
.fattr
);
3144 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3146 struct nfs4_exception exception
= { };
3149 err
= _nfs4_proc_access(inode
, entry
);
3150 trace_nfs4_access(inode
, err
);
3151 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3153 } while (exception
.retry
);
3158 * TODO: For the time being, we don't try to get any attributes
3159 * along with any of the zero-copy operations READ, READDIR,
3162 * In the case of the first three, we want to put the GETATTR
3163 * after the read-type operation -- this is because it is hard
3164 * to predict the length of a GETATTR response in v4, and thus
3165 * align the READ data correctly. This means that the GETATTR
3166 * may end up partially falling into the page cache, and we should
3167 * shift it into the 'tail' of the xdr_buf before processing.
3168 * To do this efficiently, we need to know the total length
3169 * of data received, which doesn't seem to be available outside
3172 * In the case of WRITE, we also want to put the GETATTR after
3173 * the operation -- in this case because we want to make sure
3174 * we get the post-operation mtime and size.
3176 * Both of these changes to the XDR layer would in fact be quite
3177 * minor, but I decided to leave them for a subsequent patch.
3179 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3180 unsigned int pgbase
, unsigned int pglen
)
3182 struct nfs4_readlink args
= {
3183 .fh
= NFS_FH(inode
),
3188 struct nfs4_readlink_res res
;
3189 struct rpc_message msg
= {
3190 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3195 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3198 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3199 unsigned int pgbase
, unsigned int pglen
)
3201 struct nfs4_exception exception
= { };
3204 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3205 trace_nfs4_readlink(inode
, err
);
3206 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3208 } while (exception
.retry
);
3213 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3216 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3219 struct nfs4_label l
, *ilabel
= NULL
;
3220 struct nfs_open_context
*ctx
;
3221 struct nfs4_state
*state
;
3224 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3226 return PTR_ERR(ctx
);
3228 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3230 sattr
->ia_mode
&= ~current_umask();
3231 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
);
3232 if (IS_ERR(state
)) {
3233 status
= PTR_ERR(state
);
3237 nfs4_label_release_security(ilabel
);
3238 put_nfs_open_context(ctx
);
3242 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3244 struct nfs_server
*server
= NFS_SERVER(dir
);
3245 struct nfs_removeargs args
= {
3249 struct nfs_removeres res
= {
3252 struct rpc_message msg
= {
3253 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3259 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3261 update_changeattr(dir
, &res
.cinfo
);
3265 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3267 struct nfs4_exception exception
= { };
3270 err
= _nfs4_proc_remove(dir
, name
);
3271 trace_nfs4_remove(dir
, name
, err
);
3272 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3274 } while (exception
.retry
);
3278 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3280 struct nfs_server
*server
= NFS_SERVER(dir
);
3281 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3282 struct nfs_removeres
*res
= msg
->rpc_resp
;
3284 res
->server
= server
;
3285 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3286 nfs41_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3288 nfs_fattr_init(res
->dir_attr
);
3291 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3293 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3294 &data
->args
.seq_args
,
3299 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3301 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3302 struct nfs_removeres
*res
= &data
->res
;
3304 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3306 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3308 update_changeattr(dir
, &res
->cinfo
);
3312 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3314 struct nfs_server
*server
= NFS_SERVER(dir
);
3315 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3316 struct nfs_renameres
*res
= msg
->rpc_resp
;
3318 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3319 res
->server
= server
;
3320 nfs41_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3323 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3325 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3326 &data
->args
.seq_args
,
3331 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3332 struct inode
*new_dir
)
3334 struct nfs_renamedata
*data
= task
->tk_calldata
;
3335 struct nfs_renameres
*res
= &data
->res
;
3337 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3339 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3342 update_changeattr(old_dir
, &res
->old_cinfo
);
3343 update_changeattr(new_dir
, &res
->new_cinfo
);
3347 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3348 struct inode
*new_dir
, struct qstr
*new_name
)
3350 struct nfs_server
*server
= NFS_SERVER(old_dir
);
3351 struct nfs_renameargs arg
= {
3352 .old_dir
= NFS_FH(old_dir
),
3353 .new_dir
= NFS_FH(new_dir
),
3354 .old_name
= old_name
,
3355 .new_name
= new_name
,
3357 struct nfs_renameres res
= {
3360 struct rpc_message msg
= {
3361 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
3365 int status
= -ENOMEM
;
3367 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3369 update_changeattr(old_dir
, &res
.old_cinfo
);
3370 update_changeattr(new_dir
, &res
.new_cinfo
);
3375 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3376 struct inode
*new_dir
, struct qstr
*new_name
)
3378 struct nfs4_exception exception
= { };
3381 err
= _nfs4_proc_rename(old_dir
, old_name
,
3383 trace_nfs4_rename(old_dir
, old_name
, new_dir
, new_name
, err
);
3384 err
= nfs4_handle_exception(NFS_SERVER(old_dir
), err
,
3386 } while (exception
.retry
);
3390 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3392 struct nfs_server
*server
= NFS_SERVER(inode
);
3393 struct nfs4_link_arg arg
= {
3394 .fh
= NFS_FH(inode
),
3395 .dir_fh
= NFS_FH(dir
),
3397 .bitmask
= server
->attr_bitmask
,
3399 struct nfs4_link_res res
= {
3403 struct rpc_message msg
= {
3404 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3408 int status
= -ENOMEM
;
3410 res
.fattr
= nfs_alloc_fattr();
3411 if (res
.fattr
== NULL
)
3414 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3415 if (IS_ERR(res
.label
)) {
3416 status
= PTR_ERR(res
.label
);
3419 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3421 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3423 update_changeattr(dir
, &res
.cinfo
);
3424 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3426 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3430 nfs4_label_free(res
.label
);
3433 nfs_free_fattr(res
.fattr
);
3437 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3439 struct nfs4_exception exception
= { };
3442 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3443 _nfs4_proc_link(inode
, dir
, name
),
3445 } while (exception
.retry
);
3449 struct nfs4_createdata
{
3450 struct rpc_message msg
;
3451 struct nfs4_create_arg arg
;
3452 struct nfs4_create_res res
;
3454 struct nfs_fattr fattr
;
3455 struct nfs4_label
*label
;
3458 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3459 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3461 struct nfs4_createdata
*data
;
3463 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3465 struct nfs_server
*server
= NFS_SERVER(dir
);
3467 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3468 if (IS_ERR(data
->label
))
3471 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3472 data
->msg
.rpc_argp
= &data
->arg
;
3473 data
->msg
.rpc_resp
= &data
->res
;
3474 data
->arg
.dir_fh
= NFS_FH(dir
);
3475 data
->arg
.server
= server
;
3476 data
->arg
.name
= name
;
3477 data
->arg
.attrs
= sattr
;
3478 data
->arg
.ftype
= ftype
;
3479 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3480 data
->res
.server
= server
;
3481 data
->res
.fh
= &data
->fh
;
3482 data
->res
.fattr
= &data
->fattr
;
3483 data
->res
.label
= data
->label
;
3484 nfs_fattr_init(data
->res
.fattr
);
3492 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3494 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3495 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3497 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3498 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3503 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3505 nfs4_label_free(data
->label
);
3509 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3510 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3511 struct nfs4_label
*label
)
3513 struct nfs4_createdata
*data
;
3514 int status
= -ENAMETOOLONG
;
3516 if (len
> NFS4_MAXPATHLEN
)
3520 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3524 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3525 data
->arg
.u
.symlink
.pages
= &page
;
3526 data
->arg
.u
.symlink
.len
= len
;
3527 data
->arg
.label
= label
;
3529 status
= nfs4_do_create(dir
, dentry
, data
);
3531 nfs4_free_createdata(data
);
3536 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3537 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3539 struct nfs4_exception exception
= { };
3540 struct nfs4_label l
, *label
= NULL
;
3543 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3546 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3547 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3548 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3550 } while (exception
.retry
);
3552 nfs4_label_release_security(label
);
3556 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3557 struct iattr
*sattr
, struct nfs4_label
*label
)
3559 struct nfs4_createdata
*data
;
3560 int status
= -ENOMEM
;
3562 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3566 data
->arg
.label
= label
;
3567 status
= nfs4_do_create(dir
, dentry
, data
);
3569 nfs4_free_createdata(data
);
3574 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3575 struct iattr
*sattr
)
3577 struct nfs4_exception exception
= { };
3578 struct nfs4_label l
, *label
= NULL
;
3581 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3583 sattr
->ia_mode
&= ~current_umask();
3585 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3586 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3587 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3589 } while (exception
.retry
);
3590 nfs4_label_release_security(label
);
3595 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3596 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3598 struct inode
*dir
= dentry
->d_inode
;
3599 struct nfs4_readdir_arg args
= {
3604 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3607 struct nfs4_readdir_res res
;
3608 struct rpc_message msg
= {
3609 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3616 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
3617 dentry
->d_parent
->d_name
.name
,
3618 dentry
->d_name
.name
,
3619 (unsigned long long)cookie
);
3620 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3621 res
.pgbase
= args
.pgbase
;
3622 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3624 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3625 status
+= args
.pgbase
;
3628 nfs_invalidate_atime(dir
);
3630 dprintk("%s: returns %d\n", __func__
, status
);
3634 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3635 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3637 struct nfs4_exception exception
= { };
3640 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3641 pages
, count
, plus
);
3642 trace_nfs4_readdir(dentry
->d_inode
, err
);
3643 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3645 } while (exception
.retry
);
3649 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3650 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3652 struct nfs4_createdata
*data
;
3653 int mode
= sattr
->ia_mode
;
3654 int status
= -ENOMEM
;
3656 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3661 data
->arg
.ftype
= NF4FIFO
;
3662 else if (S_ISBLK(mode
)) {
3663 data
->arg
.ftype
= NF4BLK
;
3664 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3665 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3667 else if (S_ISCHR(mode
)) {
3668 data
->arg
.ftype
= NF4CHR
;
3669 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3670 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3671 } else if (!S_ISSOCK(mode
)) {
3676 data
->arg
.label
= label
;
3677 status
= nfs4_do_create(dir
, dentry
, data
);
3679 nfs4_free_createdata(data
);
3684 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3685 struct iattr
*sattr
, dev_t rdev
)
3687 struct nfs4_exception exception
= { };
3688 struct nfs4_label l
, *label
= NULL
;
3691 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3693 sattr
->ia_mode
&= ~current_umask();
3695 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3696 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3697 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3699 } while (exception
.retry
);
3701 nfs4_label_release_security(label
);
3706 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3707 struct nfs_fsstat
*fsstat
)
3709 struct nfs4_statfs_arg args
= {
3711 .bitmask
= server
->attr_bitmask
,
3713 struct nfs4_statfs_res res
= {
3716 struct rpc_message msg
= {
3717 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3722 nfs_fattr_init(fsstat
->fattr
);
3723 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3726 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3728 struct nfs4_exception exception
= { };
3731 err
= nfs4_handle_exception(server
,
3732 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3734 } while (exception
.retry
);
3738 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3739 struct nfs_fsinfo
*fsinfo
)
3741 struct nfs4_fsinfo_arg args
= {
3743 .bitmask
= server
->attr_bitmask
,
3745 struct nfs4_fsinfo_res res
= {
3748 struct rpc_message msg
= {
3749 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3754 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3757 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3759 struct nfs4_exception exception
= { };
3760 unsigned long now
= jiffies
;
3764 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3765 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
3767 struct nfs_client
*clp
= server
->nfs_client
;
3769 spin_lock(&clp
->cl_lock
);
3770 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
3771 clp
->cl_last_renewal
= now
;
3772 spin_unlock(&clp
->cl_lock
);
3775 err
= nfs4_handle_exception(server
, err
, &exception
);
3776 } while (exception
.retry
);
3780 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3784 nfs_fattr_init(fsinfo
->fattr
);
3785 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3787 /* block layout checks this! */
3788 server
->pnfs_blksize
= fsinfo
->blksize
;
3789 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
3795 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3796 struct nfs_pathconf
*pathconf
)
3798 struct nfs4_pathconf_arg args
= {
3800 .bitmask
= server
->attr_bitmask
,
3802 struct nfs4_pathconf_res res
= {
3803 .pathconf
= pathconf
,
3805 struct rpc_message msg
= {
3806 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3811 /* None of the pathconf attributes are mandatory to implement */
3812 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3813 memset(pathconf
, 0, sizeof(*pathconf
));
3817 nfs_fattr_init(pathconf
->fattr
);
3818 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3821 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3822 struct nfs_pathconf
*pathconf
)
3824 struct nfs4_exception exception
= { };
3828 err
= nfs4_handle_exception(server
,
3829 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3831 } while (exception
.retry
);
3835 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
3836 const struct nfs_open_context
*ctx
,
3837 const struct nfs_lock_context
*l_ctx
,
3840 const struct nfs_lockowner
*lockowner
= NULL
;
3843 lockowner
= &l_ctx
->lockowner
;
3844 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
3846 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
3848 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
3849 const struct nfs_open_context
*ctx
,
3850 const struct nfs_lock_context
*l_ctx
,
3853 nfs4_stateid current_stateid
;
3855 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
))
3857 return nfs4_stateid_match(stateid
, ¤t_stateid
);
3860 static bool nfs4_error_stateid_expired(int err
)
3863 case -NFS4ERR_DELEG_REVOKED
:
3864 case -NFS4ERR_ADMIN_REVOKED
:
3865 case -NFS4ERR_BAD_STATEID
:
3866 case -NFS4ERR_STALE_STATEID
:
3867 case -NFS4ERR_OLD_STATEID
:
3868 case -NFS4ERR_OPENMODE
:
3869 case -NFS4ERR_EXPIRED
:
3875 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3877 nfs_invalidate_atime(data
->header
->inode
);
3880 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3882 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
3884 trace_nfs4_read(data
, task
->tk_status
);
3885 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3886 rpc_restart_call_prepare(task
);
3890 __nfs4_read_done_cb(data
);
3891 if (task
->tk_status
> 0)
3892 renew_lease(server
, data
->timestamp
);
3896 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
3897 struct nfs_readargs
*args
)
3900 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3901 nfs4_stateid_is_current(&args
->stateid
,
3906 rpc_restart_call_prepare(task
);
3910 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3913 dprintk("--> %s\n", __func__
);
3915 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3917 if (nfs4_read_stateid_changed(task
, &data
->args
))
3919 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3920 nfs4_read_done_cb(task
, data
);
3923 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3925 data
->timestamp
= jiffies
;
3926 data
->read_done_cb
= nfs4_read_done_cb
;
3927 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3928 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
3931 static void nfs4_proc_read_rpc_prepare(struct rpc_task
*task
, struct nfs_read_data
*data
)
3933 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
3934 &data
->args
.seq_args
,
3938 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
3939 data
->args
.lock_context
, FMODE_READ
);
3942 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3944 struct inode
*inode
= data
->header
->inode
;
3946 trace_nfs4_write(data
, task
->tk_status
);
3947 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3948 rpc_restart_call_prepare(task
);
3951 if (task
->tk_status
>= 0) {
3952 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3953 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
3958 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
3959 struct nfs_writeargs
*args
)
3962 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
3963 nfs4_stateid_is_current(&args
->stateid
,
3968 rpc_restart_call_prepare(task
);
3972 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3974 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3976 if (nfs4_write_stateid_changed(task
, &data
->args
))
3978 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
3979 nfs4_write_done_cb(task
, data
);
3983 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data
*data
)
3985 const struct nfs_pgio_header
*hdr
= data
->header
;
3987 /* Don't request attributes for pNFS or O_DIRECT writes */
3988 if (data
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
3990 /* Otherwise, request attributes if and only if we don't hold
3993 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
3996 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3998 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
4000 if (!nfs4_write_need_cache_consistency_data(data
)) {
4001 data
->args
.bitmask
= NULL
;
4002 data
->res
.fattr
= NULL
;
4004 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4006 if (!data
->write_done_cb
)
4007 data
->write_done_cb
= nfs4_write_done_cb
;
4008 data
->res
.server
= server
;
4009 data
->timestamp
= jiffies
;
4011 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4012 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4015 static void nfs4_proc_write_rpc_prepare(struct rpc_task
*task
, struct nfs_write_data
*data
)
4017 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
4018 &data
->args
.seq_args
,
4022 nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
4023 data
->args
.lock_context
, FMODE_WRITE
);
4026 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4028 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4029 &data
->args
.seq_args
,
4034 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4036 struct inode
*inode
= data
->inode
;
4038 trace_nfs4_commit(data
, task
->tk_status
);
4039 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
4040 rpc_restart_call_prepare(task
);
4046 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4048 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4050 return data
->commit_done_cb(task
, data
);
4053 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4055 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4057 if (data
->commit_done_cb
== NULL
)
4058 data
->commit_done_cb
= nfs4_commit_done_cb
;
4059 data
->res
.server
= server
;
4060 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4061 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4064 struct nfs4_renewdata
{
4065 struct nfs_client
*client
;
4066 unsigned long timestamp
;
4070 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4071 * standalone procedure for queueing an asynchronous RENEW.
4073 static void nfs4_renew_release(void *calldata
)
4075 struct nfs4_renewdata
*data
= calldata
;
4076 struct nfs_client
*clp
= data
->client
;
4078 if (atomic_read(&clp
->cl_count
) > 1)
4079 nfs4_schedule_state_renewal(clp
);
4080 nfs_put_client(clp
);
4084 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4086 struct nfs4_renewdata
*data
= calldata
;
4087 struct nfs_client
*clp
= data
->client
;
4088 unsigned long timestamp
= data
->timestamp
;
4090 trace_nfs4_renew_async(clp
, task
->tk_status
);
4091 if (task
->tk_status
< 0) {
4092 /* Unless we're shutting down, schedule state recovery! */
4093 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4095 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4096 nfs4_schedule_lease_recovery(clp
);
4099 nfs4_schedule_path_down_recovery(clp
);
4101 do_renew_lease(clp
, timestamp
);
4104 static const struct rpc_call_ops nfs4_renew_ops
= {
4105 .rpc_call_done
= nfs4_renew_done
,
4106 .rpc_release
= nfs4_renew_release
,
4109 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4111 struct rpc_message msg
= {
4112 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4116 struct nfs4_renewdata
*data
;
4118 if (renew_flags
== 0)
4120 if (!atomic_inc_not_zero(&clp
->cl_count
))
4122 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4126 data
->timestamp
= jiffies
;
4127 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4128 &nfs4_renew_ops
, data
);
4131 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4133 struct rpc_message msg
= {
4134 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4138 unsigned long now
= jiffies
;
4141 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4144 do_renew_lease(clp
, now
);
4148 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4150 return (server
->caps
& NFS_CAP_ACLS
)
4151 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
4152 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
4155 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4156 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4159 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4161 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4162 struct page
**pages
, unsigned int *pgbase
)
4164 struct page
*newpage
, **spages
;
4170 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4171 newpage
= alloc_page(GFP_KERNEL
);
4173 if (newpage
== NULL
)
4175 memcpy(page_address(newpage
), buf
, len
);
4180 } while (buflen
!= 0);
4186 __free_page(spages
[rc
-1]);
4190 struct nfs4_cached_acl
{
4196 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4198 struct nfs_inode
*nfsi
= NFS_I(inode
);
4200 spin_lock(&inode
->i_lock
);
4201 kfree(nfsi
->nfs4_acl
);
4202 nfsi
->nfs4_acl
= acl
;
4203 spin_unlock(&inode
->i_lock
);
4206 static void nfs4_zap_acl_attr(struct inode
*inode
)
4208 nfs4_set_cached_acl(inode
, NULL
);
4211 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4213 struct nfs_inode
*nfsi
= NFS_I(inode
);
4214 struct nfs4_cached_acl
*acl
;
4217 spin_lock(&inode
->i_lock
);
4218 acl
= nfsi
->nfs4_acl
;
4221 if (buf
== NULL
) /* user is just asking for length */
4223 if (acl
->cached
== 0)
4225 ret
= -ERANGE
; /* see getxattr(2) man page */
4226 if (acl
->len
> buflen
)
4228 memcpy(buf
, acl
->data
, acl
->len
);
4232 spin_unlock(&inode
->i_lock
);
4236 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4238 struct nfs4_cached_acl
*acl
;
4239 size_t buflen
= sizeof(*acl
) + acl_len
;
4241 if (buflen
<= PAGE_SIZE
) {
4242 acl
= kmalloc(buflen
, GFP_KERNEL
);
4246 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4248 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4255 nfs4_set_cached_acl(inode
, acl
);
4259 * The getxattr API returns the required buffer length when called with a
4260 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4261 * the required buf. On a NULL buf, we send a page of data to the server
4262 * guessing that the ACL request can be serviced by a page. If so, we cache
4263 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4264 * the cache. If not so, we throw away the page, and cache the required
4265 * length. The next getxattr call will then produce another round trip to
4266 * the server, this time with the input buf of the required size.
4268 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4270 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4271 struct nfs_getaclargs args
= {
4272 .fh
= NFS_FH(inode
),
4276 struct nfs_getaclres res
= {
4279 struct rpc_message msg
= {
4280 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4284 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4285 int ret
= -ENOMEM
, i
;
4287 /* As long as we're doing a round trip to the server anyway,
4288 * let's be prepared for a page of acl data. */
4291 if (npages
> ARRAY_SIZE(pages
))
4294 for (i
= 0; i
< npages
; i
++) {
4295 pages
[i
] = alloc_page(GFP_KERNEL
);
4300 /* for decoding across pages */
4301 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4302 if (!res
.acl_scratch
)
4305 args
.acl_len
= npages
* PAGE_SIZE
;
4306 args
.acl_pgbase
= 0;
4308 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4309 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4310 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4311 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4315 /* Handle the case where the passed-in buffer is too short */
4316 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4317 /* Did the user only issue a request for the acl length? */
4323 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4325 if (res
.acl_len
> buflen
) {
4329 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4334 for (i
= 0; i
< npages
; i
++)
4336 __free_page(pages
[i
]);
4337 if (res
.acl_scratch
)
4338 __free_page(res
.acl_scratch
);
4342 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4344 struct nfs4_exception exception
= { };
4347 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4348 trace_nfs4_get_acl(inode
, ret
);
4351 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4352 } while (exception
.retry
);
4356 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4358 struct nfs_server
*server
= NFS_SERVER(inode
);
4361 if (!nfs4_server_supports_acls(server
))
4363 ret
= nfs_revalidate_inode(server
, inode
);
4366 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4367 nfs_zap_acl_cache(inode
);
4368 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4370 /* -ENOENT is returned if there is no ACL or if there is an ACL
4371 * but no cached acl data, just the acl length */
4373 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4376 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4378 struct nfs_server
*server
= NFS_SERVER(inode
);
4379 struct page
*pages
[NFS4ACL_MAXPAGES
];
4380 struct nfs_setaclargs arg
= {
4381 .fh
= NFS_FH(inode
),
4385 struct nfs_setaclres res
;
4386 struct rpc_message msg
= {
4387 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4391 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4394 if (!nfs4_server_supports_acls(server
))
4396 if (npages
> ARRAY_SIZE(pages
))
4398 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4401 nfs4_inode_return_delegation(inode
);
4402 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4405 * Free each page after tx, so the only ref left is
4406 * held by the network stack
4409 put_page(pages
[i
-1]);
4412 * Acl update can result in inode attribute update.
4413 * so mark the attribute cache invalid.
4415 spin_lock(&inode
->i_lock
);
4416 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4417 spin_unlock(&inode
->i_lock
);
4418 nfs_access_zap_cache(inode
);
4419 nfs_zap_acl_cache(inode
);
4423 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4425 struct nfs4_exception exception
= { };
4428 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4429 trace_nfs4_set_acl(inode
, err
);
4430 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4432 } while (exception
.retry
);
4436 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4437 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4440 struct nfs_server
*server
= NFS_SERVER(inode
);
4441 struct nfs_fattr fattr
;
4442 struct nfs4_label label
= {0, 0, buflen
, buf
};
4444 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4445 struct nfs4_getattr_arg args
= {
4446 .fh
= NFS_FH(inode
),
4449 struct nfs4_getattr_res res
= {
4454 struct rpc_message msg
= {
4455 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4461 nfs_fattr_init(&fattr
);
4463 ret
= rpc_call_sync(server
->client
, &msg
, 0);
4466 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4468 if (buflen
< label
.len
)
4473 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4476 struct nfs4_exception exception
= { };
4479 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4483 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4484 trace_nfs4_get_security_label(inode
, err
);
4485 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4487 } while (exception
.retry
);
4491 static int _nfs4_do_set_security_label(struct inode
*inode
,
4492 struct nfs4_label
*ilabel
,
4493 struct nfs_fattr
*fattr
,
4494 struct nfs4_label
*olabel
)
4497 struct iattr sattr
= {0};
4498 struct nfs_server
*server
= NFS_SERVER(inode
);
4499 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4500 struct nfs_setattrargs args
= {
4501 .fh
= NFS_FH(inode
),
4507 struct nfs_setattrres res
= {
4512 struct rpc_message msg
= {
4513 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4519 nfs4_stateid_copy(&args
.stateid
, &zero_stateid
);
4521 status
= rpc_call_sync(server
->client
, &msg
, 0);
4523 dprintk("%s failed: %d\n", __func__
, status
);
4528 static int nfs4_do_set_security_label(struct inode
*inode
,
4529 struct nfs4_label
*ilabel
,
4530 struct nfs_fattr
*fattr
,
4531 struct nfs4_label
*olabel
)
4533 struct nfs4_exception exception
= { };
4537 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4539 trace_nfs4_set_security_label(inode
, err
);
4540 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4542 } while (exception
.retry
);
4547 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4549 struct nfs4_label ilabel
, *olabel
= NULL
;
4550 struct nfs_fattr fattr
;
4551 struct rpc_cred
*cred
;
4552 struct inode
*inode
= dentry
->d_inode
;
4555 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4558 nfs_fattr_init(&fattr
);
4562 ilabel
.label
= (char *)buf
;
4563 ilabel
.len
= buflen
;
4565 cred
= rpc_lookup_cred();
4567 return PTR_ERR(cred
);
4569 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4570 if (IS_ERR(olabel
)) {
4571 status
= -PTR_ERR(olabel
);
4575 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4577 nfs_setsecurity(inode
, &fattr
, olabel
);
4579 nfs4_label_free(olabel
);
4584 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4588 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
4590 struct nfs_client
*clp
= server
->nfs_client
;
4592 if (task
->tk_status
>= 0)
4594 switch(task
->tk_status
) {
4595 case -NFS4ERR_DELEG_REVOKED
:
4596 case -NFS4ERR_ADMIN_REVOKED
:
4597 case -NFS4ERR_BAD_STATEID
:
4600 nfs_remove_bad_delegation(state
->inode
);
4601 case -NFS4ERR_OPENMODE
:
4604 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4605 goto stateid_invalid
;
4606 goto wait_on_recovery
;
4607 case -NFS4ERR_EXPIRED
:
4608 if (state
!= NULL
) {
4609 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4610 goto stateid_invalid
;
4612 case -NFS4ERR_STALE_STATEID
:
4613 case -NFS4ERR_STALE_CLIENTID
:
4614 nfs4_schedule_lease_recovery(clp
);
4615 goto wait_on_recovery
;
4616 #if defined(CONFIG_NFS_V4_1)
4617 case -NFS4ERR_BADSESSION
:
4618 case -NFS4ERR_BADSLOT
:
4619 case -NFS4ERR_BAD_HIGH_SLOT
:
4620 case -NFS4ERR_DEADSESSION
:
4621 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4622 case -NFS4ERR_SEQ_FALSE_RETRY
:
4623 case -NFS4ERR_SEQ_MISORDERED
:
4624 dprintk("%s ERROR %d, Reset session\n", __func__
,
4626 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4627 task
->tk_status
= 0;
4629 #endif /* CONFIG_NFS_V4_1 */
4630 case -NFS4ERR_DELAY
:
4631 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4632 case -NFS4ERR_GRACE
:
4633 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4634 task
->tk_status
= 0;
4636 case -NFS4ERR_RETRY_UNCACHED_REP
:
4637 case -NFS4ERR_OLD_STATEID
:
4638 task
->tk_status
= 0;
4641 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4644 task
->tk_status
= -EIO
;
4647 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4648 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4649 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4650 task
->tk_status
= 0;
4654 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4655 nfs4_verifier
*bootverf
)
4659 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4660 /* An impossible timestamp guarantees this value
4661 * will never match a generated boot time. */
4663 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4665 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4666 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4667 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4669 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4673 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4674 char *buf
, size_t len
)
4676 unsigned int result
;
4679 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4681 rpc_peeraddr2str(clp
->cl_rpcclient
,
4683 rpc_peeraddr2str(clp
->cl_rpcclient
,
4684 RPC_DISPLAY_PROTO
));
4690 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4691 char *buf
, size_t len
)
4693 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4695 if (nfs4_client_id_uniquifier
[0] != '\0')
4696 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4697 clp
->rpc_ops
->version
,
4698 clp
->cl_minorversion
,
4699 nfs4_client_id_uniquifier
,
4701 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4702 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4707 * nfs4_proc_setclientid - Negotiate client ID
4708 * @clp: state data structure
4709 * @program: RPC program for NFSv4 callback service
4710 * @port: IP port number for NFS4 callback service
4711 * @cred: RPC credential to use for this call
4712 * @res: where to place the result
4714 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4716 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4717 unsigned short port
, struct rpc_cred
*cred
,
4718 struct nfs4_setclientid_res
*res
)
4720 nfs4_verifier sc_verifier
;
4721 struct nfs4_setclientid setclientid
= {
4722 .sc_verifier
= &sc_verifier
,
4724 .sc_cb_ident
= clp
->cl_cb_ident
,
4726 struct rpc_message msg
= {
4727 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
4728 .rpc_argp
= &setclientid
,
4734 /* nfs_client_id4 */
4735 nfs4_init_boot_verifier(clp
, &sc_verifier
);
4736 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
4737 setclientid
.sc_name_len
=
4738 nfs4_init_uniform_client_string(clp
,
4739 setclientid
.sc_name
,
4740 sizeof(setclientid
.sc_name
));
4742 setclientid
.sc_name_len
=
4743 nfs4_init_nonuniform_client_string(clp
,
4744 setclientid
.sc_name
,
4745 sizeof(setclientid
.sc_name
));
4748 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
4749 sizeof(setclientid
.sc_netid
), "%s",
4750 rpc_peeraddr2str(clp
->cl_rpcclient
,
4751 RPC_DISPLAY_NETID
));
4753 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
4754 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
4755 clp
->cl_ipaddr
, port
>> 8, port
& 255);
4757 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4758 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4759 setclientid
.sc_name_len
, setclientid
.sc_name
);
4760 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4761 trace_nfs4_setclientid(clp
, status
);
4762 dprintk("NFS reply setclientid: %d\n", status
);
4767 * nfs4_proc_setclientid_confirm - Confirm client ID
4768 * @clp: state data structure
4769 * @res: result of a previous SETCLIENTID
4770 * @cred: RPC credential to use for this call
4772 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4774 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
4775 struct nfs4_setclientid_res
*arg
,
4776 struct rpc_cred
*cred
)
4778 struct rpc_message msg
= {
4779 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
4785 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4786 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4788 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4789 trace_nfs4_setclientid_confirm(clp
, status
);
4790 dprintk("NFS reply setclientid_confirm: %d\n", status
);
4794 struct nfs4_delegreturndata
{
4795 struct nfs4_delegreturnargs args
;
4796 struct nfs4_delegreturnres res
;
4798 nfs4_stateid stateid
;
4799 unsigned long timestamp
;
4800 struct nfs_fattr fattr
;
4804 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
4806 struct nfs4_delegreturndata
*data
= calldata
;
4808 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4811 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
4812 switch (task
->tk_status
) {
4813 case -NFS4ERR_STALE_STATEID
:
4814 case -NFS4ERR_EXPIRED
:
4816 renew_lease(data
->res
.server
, data
->timestamp
);
4819 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
4821 rpc_restart_call_prepare(task
);
4825 data
->rpc_status
= task
->tk_status
;
4828 static void nfs4_delegreturn_release(void *calldata
)
4833 #if defined(CONFIG_NFS_V4_1)
4834 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
4836 struct nfs4_delegreturndata
*d_data
;
4838 d_data
= (struct nfs4_delegreturndata
*)data
;
4840 nfs4_setup_sequence(d_data
->res
.server
,
4841 &d_data
->args
.seq_args
,
4842 &d_data
->res
.seq_res
,
4845 #endif /* CONFIG_NFS_V4_1 */
4847 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
4848 #if defined(CONFIG_NFS_V4_1)
4849 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
4850 #endif /* CONFIG_NFS_V4_1 */
4851 .rpc_call_done
= nfs4_delegreturn_done
,
4852 .rpc_release
= nfs4_delegreturn_release
,
4855 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4857 struct nfs4_delegreturndata
*data
;
4858 struct nfs_server
*server
= NFS_SERVER(inode
);
4859 struct rpc_task
*task
;
4860 struct rpc_message msg
= {
4861 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
4864 struct rpc_task_setup task_setup_data
= {
4865 .rpc_client
= server
->client
,
4866 .rpc_message
= &msg
,
4867 .callback_ops
= &nfs4_delegreturn_ops
,
4868 .flags
= RPC_TASK_ASYNC
,
4872 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
4875 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4876 data
->args
.fhandle
= &data
->fh
;
4877 data
->args
.stateid
= &data
->stateid
;
4878 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4879 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
4880 nfs4_stateid_copy(&data
->stateid
, stateid
);
4881 data
->res
.fattr
= &data
->fattr
;
4882 data
->res
.server
= server
;
4883 nfs_fattr_init(data
->res
.fattr
);
4884 data
->timestamp
= jiffies
;
4885 data
->rpc_status
= 0;
4887 task_setup_data
.callback_data
= data
;
4888 msg
.rpc_argp
= &data
->args
;
4889 msg
.rpc_resp
= &data
->res
;
4890 task
= rpc_run_task(&task_setup_data
);
4892 return PTR_ERR(task
);
4895 status
= nfs4_wait_for_completion_rpc_task(task
);
4898 status
= data
->rpc_status
;
4900 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
4902 nfs_refresh_inode(inode
, &data
->fattr
);
4908 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
4910 struct nfs_server
*server
= NFS_SERVER(inode
);
4911 struct nfs4_exception exception
= { };
4914 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
4915 trace_nfs4_delegreturn(inode
, err
);
4917 case -NFS4ERR_STALE_STATEID
:
4918 case -NFS4ERR_EXPIRED
:
4922 err
= nfs4_handle_exception(server
, err
, &exception
);
4923 } while (exception
.retry
);
4927 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4928 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4931 * sleep, with exponential backoff, and retry the LOCK operation.
4933 static unsigned long
4934 nfs4_set_lock_task_retry(unsigned long timeout
)
4936 freezable_schedule_timeout_killable_unsafe(timeout
);
4938 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
4939 return NFS4_LOCK_MAXTIMEOUT
;
4943 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4945 struct inode
*inode
= state
->inode
;
4946 struct nfs_server
*server
= NFS_SERVER(inode
);
4947 struct nfs_client
*clp
= server
->nfs_client
;
4948 struct nfs_lockt_args arg
= {
4949 .fh
= NFS_FH(inode
),
4952 struct nfs_lockt_res res
= {
4955 struct rpc_message msg
= {
4956 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
4959 .rpc_cred
= state
->owner
->so_cred
,
4961 struct nfs4_lock_state
*lsp
;
4964 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
4965 status
= nfs4_set_lock_state(state
, request
);
4968 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4969 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
4970 arg
.lock_owner
.s_dev
= server
->s_dev
;
4971 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4974 request
->fl_type
= F_UNLCK
;
4976 case -NFS4ERR_DENIED
:
4979 request
->fl_ops
->fl_release_private(request
);
4984 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4986 struct nfs4_exception exception
= { };
4990 err
= _nfs4_proc_getlk(state
, cmd
, request
);
4991 trace_nfs4_get_lock(request
, state
, cmd
, err
);
4992 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
4994 } while (exception
.retry
);
4998 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5001 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5003 res
= posix_lock_file_wait(file
, fl
);
5006 res
= flock_lock_file_wait(file
, fl
);
5014 struct nfs4_unlockdata
{
5015 struct nfs_locku_args arg
;
5016 struct nfs_locku_res res
;
5017 struct nfs4_lock_state
*lsp
;
5018 struct nfs_open_context
*ctx
;
5019 struct file_lock fl
;
5020 const struct nfs_server
*server
;
5021 unsigned long timestamp
;
5024 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5025 struct nfs_open_context
*ctx
,
5026 struct nfs4_lock_state
*lsp
,
5027 struct nfs_seqid
*seqid
)
5029 struct nfs4_unlockdata
*p
;
5030 struct inode
*inode
= lsp
->ls_state
->inode
;
5032 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5035 p
->arg
.fh
= NFS_FH(inode
);
5037 p
->arg
.seqid
= seqid
;
5038 p
->res
.seqid
= seqid
;
5039 p
->arg
.stateid
= &lsp
->ls_stateid
;
5041 atomic_inc(&lsp
->ls_count
);
5042 /* Ensure we don't close file until we're done freeing locks! */
5043 p
->ctx
= get_nfs_open_context(ctx
);
5044 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5045 p
->server
= NFS_SERVER(inode
);
5049 static void nfs4_locku_release_calldata(void *data
)
5051 struct nfs4_unlockdata
*calldata
= data
;
5052 nfs_free_seqid(calldata
->arg
.seqid
);
5053 nfs4_put_lock_state(calldata
->lsp
);
5054 put_nfs_open_context(calldata
->ctx
);
5058 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5060 struct nfs4_unlockdata
*calldata
= data
;
5062 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5064 switch (task
->tk_status
) {
5066 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5067 &calldata
->res
.stateid
);
5068 renew_lease(calldata
->server
, calldata
->timestamp
);
5070 case -NFS4ERR_BAD_STATEID
:
5071 case -NFS4ERR_OLD_STATEID
:
5072 case -NFS4ERR_STALE_STATEID
:
5073 case -NFS4ERR_EXPIRED
:
5076 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
5077 rpc_restart_call_prepare(task
);
5079 nfs_release_seqid(calldata
->arg
.seqid
);
5082 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5084 struct nfs4_unlockdata
*calldata
= data
;
5086 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5088 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5089 /* Note: exit _without_ running nfs4_locku_done */
5092 calldata
->timestamp
= jiffies
;
5093 if (nfs4_setup_sequence(calldata
->server
,
5094 &calldata
->arg
.seq_args
,
5095 &calldata
->res
.seq_res
,
5097 nfs_release_seqid(calldata
->arg
.seqid
);
5100 task
->tk_action
= NULL
;
5102 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5105 static const struct rpc_call_ops nfs4_locku_ops
= {
5106 .rpc_call_prepare
= nfs4_locku_prepare
,
5107 .rpc_call_done
= nfs4_locku_done
,
5108 .rpc_release
= nfs4_locku_release_calldata
,
5111 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5112 struct nfs_open_context
*ctx
,
5113 struct nfs4_lock_state
*lsp
,
5114 struct nfs_seqid
*seqid
)
5116 struct nfs4_unlockdata
*data
;
5117 struct rpc_message msg
= {
5118 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5119 .rpc_cred
= ctx
->cred
,
5121 struct rpc_task_setup task_setup_data
= {
5122 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5123 .rpc_message
= &msg
,
5124 .callback_ops
= &nfs4_locku_ops
,
5125 .workqueue
= nfsiod_workqueue
,
5126 .flags
= RPC_TASK_ASYNC
,
5129 /* Ensure this is an unlock - when canceling a lock, the
5130 * canceled lock is passed in, and it won't be an unlock.
5132 fl
->fl_type
= F_UNLCK
;
5134 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5136 nfs_free_seqid(seqid
);
5137 return ERR_PTR(-ENOMEM
);
5140 nfs41_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5141 msg
.rpc_argp
= &data
->arg
;
5142 msg
.rpc_resp
= &data
->res
;
5143 task_setup_data
.callback_data
= data
;
5144 return rpc_run_task(&task_setup_data
);
5147 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5149 struct inode
*inode
= state
->inode
;
5150 struct nfs4_state_owner
*sp
= state
->owner
;
5151 struct nfs_inode
*nfsi
= NFS_I(inode
);
5152 struct nfs_seqid
*seqid
;
5153 struct nfs4_lock_state
*lsp
;
5154 struct rpc_task
*task
;
5156 unsigned char fl_flags
= request
->fl_flags
;
5158 status
= nfs4_set_lock_state(state
, request
);
5159 /* Unlock _before_ we do the RPC call */
5160 request
->fl_flags
|= FL_EXISTS
;
5161 /* Exclude nfs_delegation_claim_locks() */
5162 mutex_lock(&sp
->so_delegreturn_mutex
);
5163 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5164 down_read(&nfsi
->rwsem
);
5165 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5166 up_read(&nfsi
->rwsem
);
5167 mutex_unlock(&sp
->so_delegreturn_mutex
);
5170 up_read(&nfsi
->rwsem
);
5171 mutex_unlock(&sp
->so_delegreturn_mutex
);
5174 /* Is this a delegated lock? */
5175 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5176 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5178 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5182 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5183 status
= PTR_ERR(task
);
5186 status
= nfs4_wait_for_completion_rpc_task(task
);
5189 request
->fl_flags
= fl_flags
;
5190 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5194 struct nfs4_lockdata
{
5195 struct nfs_lock_args arg
;
5196 struct nfs_lock_res res
;
5197 struct nfs4_lock_state
*lsp
;
5198 struct nfs_open_context
*ctx
;
5199 struct file_lock fl
;
5200 unsigned long timestamp
;
5203 struct nfs_server
*server
;
5206 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5207 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5210 struct nfs4_lockdata
*p
;
5211 struct inode
*inode
= lsp
->ls_state
->inode
;
5212 struct nfs_server
*server
= NFS_SERVER(inode
);
5214 p
= kzalloc(sizeof(*p
), gfp_mask
);
5218 p
->arg
.fh
= NFS_FH(inode
);
5220 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5221 if (p
->arg
.open_seqid
== NULL
)
5223 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5224 if (p
->arg
.lock_seqid
== NULL
)
5225 goto out_free_seqid
;
5226 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5227 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5228 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5229 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5230 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5233 atomic_inc(&lsp
->ls_count
);
5234 p
->ctx
= get_nfs_open_context(ctx
);
5235 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5238 nfs_free_seqid(p
->arg
.open_seqid
);
5244 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5246 struct nfs4_lockdata
*data
= calldata
;
5247 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5249 dprintk("%s: begin!\n", __func__
);
5250 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5252 /* Do we need to do an open_to_lock_owner? */
5253 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5254 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5255 goto out_release_lock_seqid
;
5257 data
->arg
.open_stateid
= &state
->open_stateid
;
5258 data
->arg
.new_lock_owner
= 1;
5259 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5261 data
->arg
.new_lock_owner
= 0;
5262 if (!nfs4_valid_open_stateid(state
)) {
5263 data
->rpc_status
= -EBADF
;
5264 task
->tk_action
= NULL
;
5265 goto out_release_open_seqid
;
5267 data
->timestamp
= jiffies
;
5268 if (nfs4_setup_sequence(data
->server
,
5269 &data
->arg
.seq_args
,
5273 out_release_open_seqid
:
5274 nfs_release_seqid(data
->arg
.open_seqid
);
5275 out_release_lock_seqid
:
5276 nfs_release_seqid(data
->arg
.lock_seqid
);
5278 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5279 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5282 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5284 struct nfs4_lockdata
*data
= calldata
;
5286 dprintk("%s: begin!\n", __func__
);
5288 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5291 data
->rpc_status
= task
->tk_status
;
5292 if (data
->arg
.new_lock_owner
!= 0) {
5293 if (data
->rpc_status
== 0)
5294 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5298 if (data
->rpc_status
== 0) {
5299 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5300 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5301 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5304 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5307 static void nfs4_lock_release(void *calldata
)
5309 struct nfs4_lockdata
*data
= calldata
;
5311 dprintk("%s: begin!\n", __func__
);
5312 nfs_free_seqid(data
->arg
.open_seqid
);
5313 if (data
->cancelled
!= 0) {
5314 struct rpc_task
*task
;
5315 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5316 data
->arg
.lock_seqid
);
5318 rpc_put_task_async(task
);
5319 dprintk("%s: cancelling lock!\n", __func__
);
5321 nfs_free_seqid(data
->arg
.lock_seqid
);
5322 nfs4_put_lock_state(data
->lsp
);
5323 put_nfs_open_context(data
->ctx
);
5325 dprintk("%s: done!\n", __func__
);
5328 static const struct rpc_call_ops nfs4_lock_ops
= {
5329 .rpc_call_prepare
= nfs4_lock_prepare
,
5330 .rpc_call_done
= nfs4_lock_done
,
5331 .rpc_release
= nfs4_lock_release
,
5334 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5337 case -NFS4ERR_ADMIN_REVOKED
:
5338 case -NFS4ERR_BAD_STATEID
:
5339 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5340 if (new_lock_owner
!= 0 ||
5341 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5342 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5344 case -NFS4ERR_STALE_STATEID
:
5345 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5346 case -NFS4ERR_EXPIRED
:
5347 nfs4_schedule_lease_recovery(server
->nfs_client
);
5351 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5353 struct nfs4_lockdata
*data
;
5354 struct rpc_task
*task
;
5355 struct rpc_message msg
= {
5356 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5357 .rpc_cred
= state
->owner
->so_cred
,
5359 struct rpc_task_setup task_setup_data
= {
5360 .rpc_client
= NFS_CLIENT(state
->inode
),
5361 .rpc_message
= &msg
,
5362 .callback_ops
= &nfs4_lock_ops
,
5363 .workqueue
= nfsiod_workqueue
,
5364 .flags
= RPC_TASK_ASYNC
,
5368 dprintk("%s: begin!\n", __func__
);
5369 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5370 fl
->fl_u
.nfs4_fl
.owner
,
5371 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5375 data
->arg
.block
= 1;
5376 nfs41_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5377 msg
.rpc_argp
= &data
->arg
;
5378 msg
.rpc_resp
= &data
->res
;
5379 task_setup_data
.callback_data
= data
;
5380 if (recovery_type
> NFS_LOCK_NEW
) {
5381 if (recovery_type
== NFS_LOCK_RECLAIM
)
5382 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5383 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5385 task
= rpc_run_task(&task_setup_data
);
5387 return PTR_ERR(task
);
5388 ret
= nfs4_wait_for_completion_rpc_task(task
);
5390 ret
= data
->rpc_status
;
5392 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5393 data
->arg
.new_lock_owner
, ret
);
5395 data
->cancelled
= 1;
5397 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5401 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5403 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5404 struct nfs4_exception exception
= {
5405 .inode
= state
->inode
,
5410 /* Cache the lock if possible... */
5411 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5413 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5414 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5415 if (err
!= -NFS4ERR_DELAY
)
5417 nfs4_handle_exception(server
, err
, &exception
);
5418 } while (exception
.retry
);
5422 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5424 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5425 struct nfs4_exception exception
= {
5426 .inode
= state
->inode
,
5430 err
= nfs4_set_lock_state(state
, request
);
5434 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5436 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5437 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5441 case -NFS4ERR_GRACE
:
5442 case -NFS4ERR_DELAY
:
5443 nfs4_handle_exception(server
, err
, &exception
);
5446 } while (exception
.retry
);
5451 #if defined(CONFIG_NFS_V4_1)
5453 * nfs41_check_expired_locks - possibly free a lock stateid
5455 * @state: NFSv4 state for an inode
5457 * Returns NFS_OK if recovery for this stateid is now finished.
5458 * Otherwise a negative NFS4ERR value is returned.
5460 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5462 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5463 struct nfs4_lock_state
*lsp
;
5464 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5466 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5467 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5468 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5470 status
= nfs41_test_stateid(server
,
5473 if (status
!= NFS_OK
) {
5474 /* Free the stateid unless the server
5475 * informs us the stateid is unrecognized. */
5476 if (status
!= -NFS4ERR_BAD_STATEID
)
5477 nfs41_free_stateid(server
,
5480 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5489 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5491 int status
= NFS_OK
;
5493 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5494 status
= nfs41_check_expired_locks(state
);
5495 if (status
!= NFS_OK
)
5496 status
= nfs4_lock_expired(state
, request
);
5501 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5503 struct nfs4_state_owner
*sp
= state
->owner
;
5504 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5505 unsigned char fl_flags
= request
->fl_flags
;
5507 int status
= -ENOLCK
;
5509 if ((fl_flags
& FL_POSIX
) &&
5510 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5512 /* Is this a delegated open? */
5513 status
= nfs4_set_lock_state(state
, request
);
5516 request
->fl_flags
|= FL_ACCESS
;
5517 status
= do_vfs_lock(request
->fl_file
, request
);
5520 down_read(&nfsi
->rwsem
);
5521 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5522 /* Yes: cache locks! */
5523 /* ...but avoid races with delegation recall... */
5524 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5525 status
= do_vfs_lock(request
->fl_file
, request
);
5528 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5529 up_read(&nfsi
->rwsem
);
5530 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5533 down_read(&nfsi
->rwsem
);
5534 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5535 status
= -NFS4ERR_DELAY
;
5538 /* Note: we always want to sleep here! */
5539 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5540 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5541 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5542 "manager!\n", __func__
);
5544 up_read(&nfsi
->rwsem
);
5546 request
->fl_flags
= fl_flags
;
5550 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5552 struct nfs4_exception exception
= {
5554 .inode
= state
->inode
,
5559 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5560 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5561 if (err
== -NFS4ERR_DENIED
)
5563 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5565 } while (exception
.retry
);
5570 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5572 struct nfs_open_context
*ctx
;
5573 struct nfs4_state
*state
;
5574 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5577 /* verify open state */
5578 ctx
= nfs_file_open_context(filp
);
5581 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5584 if (IS_GETLK(cmd
)) {
5586 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5590 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5593 if (request
->fl_type
== F_UNLCK
) {
5595 return nfs4_proc_unlck(state
, cmd
, request
);
5602 * Don't rely on the VFS having checked the file open mode,
5603 * since it won't do this for flock() locks.
5605 switch (request
->fl_type
) {
5607 if (!(filp
->f_mode
& FMODE_READ
))
5611 if (!(filp
->f_mode
& FMODE_WRITE
))
5616 status
= nfs4_proc_setlk(state
, cmd
, request
);
5617 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5619 timeout
= nfs4_set_lock_task_retry(timeout
);
5620 status
= -ERESTARTSYS
;
5623 } while(status
< 0);
5627 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5629 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5632 err
= nfs4_set_lock_state(state
, fl
);
5635 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5636 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5639 struct nfs_release_lockowner_data
{
5640 struct nfs4_lock_state
*lsp
;
5641 struct nfs_server
*server
;
5642 struct nfs_release_lockowner_args args
;
5645 static void nfs4_release_lockowner_release(void *calldata
)
5647 struct nfs_release_lockowner_data
*data
= calldata
;
5648 nfs4_free_lock_state(data
->server
, data
->lsp
);
5652 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
5653 .rpc_release
= nfs4_release_lockowner_release
,
5656 static int nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
5658 struct nfs_release_lockowner_data
*data
;
5659 struct rpc_message msg
= {
5660 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
5663 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
5665 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5669 data
->server
= server
;
5670 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5671 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5672 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
5673 msg
.rpc_argp
= &data
->args
;
5674 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
5678 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5680 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
5681 const void *buf
, size_t buflen
,
5682 int flags
, int type
)
5684 if (strcmp(key
, "") != 0)
5687 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
5690 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
5691 void *buf
, size_t buflen
, int type
)
5693 if (strcmp(key
, "") != 0)
5696 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
5699 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
5700 size_t list_len
, const char *name
,
5701 size_t name_len
, int type
)
5703 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
5705 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
5708 if (list
&& len
<= list_len
)
5709 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
5713 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5714 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
5716 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
5719 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
5720 const void *buf
, size_t buflen
,
5721 int flags
, int type
)
5723 if (security_ismaclabel(key
))
5724 return nfs4_set_security_label(dentry
, buf
, buflen
);
5729 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
5730 void *buf
, size_t buflen
, int type
)
5732 if (security_ismaclabel(key
))
5733 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
5737 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
5738 size_t list_len
, const char *name
,
5739 size_t name_len
, int type
)
5743 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
5744 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
5745 if (list
&& len
<= list_len
)
5746 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
5751 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
5752 .prefix
= XATTR_SECURITY_PREFIX
,
5753 .list
= nfs4_xattr_list_nfs4_label
,
5754 .get
= nfs4_xattr_get_nfs4_label
,
5755 .set
= nfs4_xattr_set_nfs4_label
,
5761 * nfs_fhget will use either the mounted_on_fileid or the fileid
5763 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
5765 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
5766 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
5767 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
5768 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
5771 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
5772 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
5773 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
5777 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5778 const struct qstr
*name
,
5779 struct nfs4_fs_locations
*fs_locations
,
5782 struct nfs_server
*server
= NFS_SERVER(dir
);
5784 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
5786 struct nfs4_fs_locations_arg args
= {
5787 .dir_fh
= NFS_FH(dir
),
5792 struct nfs4_fs_locations_res res
= {
5793 .fs_locations
= fs_locations
,
5795 struct rpc_message msg
= {
5796 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
5802 dprintk("%s: start\n", __func__
);
5804 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5805 * is not supported */
5806 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
5807 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
5809 bitmask
[0] |= FATTR4_WORD0_FILEID
;
5811 nfs_fattr_init(&fs_locations
->fattr
);
5812 fs_locations
->server
= server
;
5813 fs_locations
->nlocations
= 0;
5814 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5815 dprintk("%s: returned status = %d\n", __func__
, status
);
5819 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5820 const struct qstr
*name
,
5821 struct nfs4_fs_locations
*fs_locations
,
5824 struct nfs4_exception exception
= { };
5827 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
5828 fs_locations
, page
);
5829 trace_nfs4_get_fs_locations(dir
, name
, err
);
5830 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5832 } while (exception
.retry
);
5837 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
5838 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
5840 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
5843 struct nfs4_secinfo_arg args
= {
5844 .dir_fh
= NFS_FH(dir
),
5847 struct nfs4_secinfo_res res
= {
5850 struct rpc_message msg
= {
5851 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
5855 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
5857 dprintk("NFS call secinfo %s\n", name
->name
);
5858 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5859 dprintk("NFS reply secinfo: %d\n", status
);
5863 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
5864 struct nfs4_secinfo_flavors
*flavors
)
5866 struct nfs4_exception exception
= { };
5869 err
= _nfs4_proc_secinfo(dir
, name
, flavors
);
5870 trace_nfs4_secinfo(dir
, name
, err
);
5871 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
5873 } while (exception
.retry
);
5877 #ifdef CONFIG_NFS_V4_1
5879 * Check the exchange flags returned by the server for invalid flags, having
5880 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5883 static int nfs4_check_cl_exchange_flags(u32 flags
)
5885 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
5887 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
5888 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
5890 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
5894 return -NFS4ERR_INVAL
;
5898 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
5899 struct nfs41_server_scope
*b
)
5901 if (a
->server_scope_sz
== b
->server_scope_sz
&&
5902 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
5909 * nfs4_proc_bind_conn_to_session()
5911 * The 4.1 client currently uses the same TCP connection for the
5912 * fore and backchannel.
5914 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5917 struct nfs41_bind_conn_to_session_res res
;
5918 struct rpc_message msg
= {
5920 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
5926 dprintk("--> %s\n", __func__
);
5928 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5929 if (unlikely(res
.session
== NULL
)) {
5934 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5935 trace_nfs4_bind_conn_to_session(clp
, status
);
5937 if (memcmp(res
.session
->sess_id
.data
,
5938 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
5939 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
5943 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
5944 dprintk("NFS: %s: Unexpected direction from server\n",
5949 if (res
.use_conn_in_rdma_mode
) {
5950 dprintk("NFS: %s: Server returned RDMA mode = true\n",
5959 dprintk("<-- %s status= %d\n", __func__
, status
);
5964 * nfs4_proc_exchange_id()
5966 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5968 * Since the clientid has expired, all compounds using sessions
5969 * associated with the stale clientid will be returning
5970 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
5971 * be in some phase of session reset.
5973 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5975 nfs4_verifier verifier
;
5976 struct nfs41_exchange_id_args args
= {
5977 .verifier
= &verifier
,
5979 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
5980 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
5982 struct nfs41_exchange_id_res res
= {
5986 struct rpc_message msg
= {
5987 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
5993 nfs4_init_boot_verifier(clp
, &verifier
);
5994 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
5996 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
5997 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5998 args
.id_len
, args
.id
);
6000 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6002 if (unlikely(res
.server_owner
== NULL
)) {
6007 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6009 if (unlikely(res
.server_scope
== NULL
)) {
6011 goto out_server_owner
;
6014 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6015 if (unlikely(res
.impl_id
== NULL
)) {
6017 goto out_server_scope
;
6020 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6021 trace_nfs4_exchange_id(clp
, status
);
6023 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6026 clp
->cl_clientid
= res
.clientid
;
6027 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6028 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6029 clp
->cl_seqid
= res
.seqid
;
6031 kfree(clp
->cl_serverowner
);
6032 clp
->cl_serverowner
= res
.server_owner
;
6033 res
.server_owner
= NULL
;
6035 /* use the most recent implementation id */
6036 kfree(clp
->cl_implid
);
6037 clp
->cl_implid
= res
.impl_id
;
6039 if (clp
->cl_serverscope
!= NULL
&&
6040 !nfs41_same_server_scope(clp
->cl_serverscope
,
6041 res
.server_scope
)) {
6042 dprintk("%s: server_scope mismatch detected\n",
6044 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6045 kfree(clp
->cl_serverscope
);
6046 clp
->cl_serverscope
= NULL
;
6049 if (clp
->cl_serverscope
== NULL
) {
6050 clp
->cl_serverscope
= res
.server_scope
;
6057 kfree(res
.server_owner
);
6059 kfree(res
.server_scope
);
6061 if (clp
->cl_implid
!= NULL
)
6062 dprintk("NFS reply exchange_id: Server Implementation ID: "
6063 "domain: %s, name: %s, date: %llu,%u\n",
6064 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6065 clp
->cl_implid
->date
.seconds
,
6066 clp
->cl_implid
->date
.nseconds
);
6067 dprintk("NFS reply exchange_id: %d\n", status
);
6071 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6072 struct rpc_cred
*cred
)
6074 struct rpc_message msg
= {
6075 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6081 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6082 trace_nfs4_destroy_clientid(clp
, status
);
6084 dprintk("NFS: Got error %d from the server %s on "
6085 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6089 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6090 struct rpc_cred
*cred
)
6095 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6096 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6098 case -NFS4ERR_DELAY
:
6099 case -NFS4ERR_CLIENTID_BUSY
:
6109 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6111 struct rpc_cred
*cred
;
6114 if (clp
->cl_mvops
->minor_version
< 1)
6116 if (clp
->cl_exchange_flags
== 0)
6118 if (clp
->cl_preserve_clid
)
6120 cred
= nfs4_get_clid_cred(clp
);
6121 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6126 case -NFS4ERR_STALE_CLIENTID
:
6127 clp
->cl_exchange_flags
= 0;
6133 struct nfs4_get_lease_time_data
{
6134 struct nfs4_get_lease_time_args
*args
;
6135 struct nfs4_get_lease_time_res
*res
;
6136 struct nfs_client
*clp
;
6139 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6142 struct nfs4_get_lease_time_data
*data
=
6143 (struct nfs4_get_lease_time_data
*)calldata
;
6145 dprintk("--> %s\n", __func__
);
6146 /* just setup sequence, do not trigger session recovery
6147 since we're invoked within one */
6148 nfs41_setup_sequence(data
->clp
->cl_session
,
6149 &data
->args
->la_seq_args
,
6150 &data
->res
->lr_seq_res
,
6152 dprintk("<-- %s\n", __func__
);
6156 * Called from nfs4_state_manager thread for session setup, so don't recover
6157 * from sequence operation or clientid errors.
6159 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
6161 struct nfs4_get_lease_time_data
*data
=
6162 (struct nfs4_get_lease_time_data
*)calldata
;
6164 dprintk("--> %s\n", __func__
);
6165 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
6167 switch (task
->tk_status
) {
6168 case -NFS4ERR_DELAY
:
6169 case -NFS4ERR_GRACE
:
6170 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
6171 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
6172 task
->tk_status
= 0;
6174 case -NFS4ERR_RETRY_UNCACHED_REP
:
6175 rpc_restart_call_prepare(task
);
6178 dprintk("<-- %s\n", __func__
);
6181 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
6182 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
6183 .rpc_call_done
= nfs4_get_lease_time_done
,
6186 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
6188 struct rpc_task
*task
;
6189 struct nfs4_get_lease_time_args args
;
6190 struct nfs4_get_lease_time_res res
= {
6191 .lr_fsinfo
= fsinfo
,
6193 struct nfs4_get_lease_time_data data
= {
6198 struct rpc_message msg
= {
6199 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
6203 struct rpc_task_setup task_setup
= {
6204 .rpc_client
= clp
->cl_rpcclient
,
6205 .rpc_message
= &msg
,
6206 .callback_ops
= &nfs4_get_lease_time_ops
,
6207 .callback_data
= &data
,
6208 .flags
= RPC_TASK_TIMEOUT
,
6212 nfs41_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
6213 nfs4_set_sequence_privileged(&args
.la_seq_args
);
6214 dprintk("--> %s\n", __func__
);
6215 task
= rpc_run_task(&task_setup
);
6218 status
= PTR_ERR(task
);
6220 status
= task
->tk_status
;
6223 dprintk("<-- %s return %d\n", __func__
, status
);
6229 * Initialize the values to be used by the client in CREATE_SESSION
6230 * If nfs4_init_session set the fore channel request and response sizes,
6233 * Set the back channel max_resp_sz_cached to zero to force the client to
6234 * always set csa_cachethis to FALSE because the current implementation
6235 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6237 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
6239 unsigned int max_rqst_sz
, max_resp_sz
;
6241 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
6242 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
6244 /* Fore channel attributes */
6245 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
6246 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
6247 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
6248 args
->fc_attrs
.max_reqs
= max_session_slots
;
6250 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6251 "max_ops=%u max_reqs=%u\n",
6253 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
6254 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
6256 /* Back channel attributes */
6257 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
6258 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
6259 args
->bc_attrs
.max_resp_sz_cached
= 0;
6260 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
6261 args
->bc_attrs
.max_reqs
= 1;
6263 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6264 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6266 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
6267 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
6268 args
->bc_attrs
.max_reqs
);
6271 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6273 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
6274 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
6276 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
6279 * Our requested max_ops is the minimum we need; we're not
6280 * prepared to break up compounds into smaller pieces than that.
6281 * So, no point even trying to continue if the server won't
6284 if (rcvd
->max_ops
< sent
->max_ops
)
6286 if (rcvd
->max_reqs
== 0)
6288 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
6289 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
6293 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6295 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
6296 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
6298 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
6300 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
6302 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
6304 /* These would render the backchannel useless: */
6305 if (rcvd
->max_ops
!= sent
->max_ops
)
6307 if (rcvd
->max_reqs
!= sent
->max_reqs
)
6312 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
6313 struct nfs4_session
*session
)
6317 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
6320 return nfs4_verify_back_channel_attrs(args
, session
);
6323 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
6324 struct rpc_cred
*cred
)
6326 struct nfs4_session
*session
= clp
->cl_session
;
6327 struct nfs41_create_session_args args
= {
6329 .cb_program
= NFS4_CALLBACK
,
6331 struct nfs41_create_session_res res
= {
6334 struct rpc_message msg
= {
6335 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
6342 nfs4_init_channel_attrs(&args
);
6343 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
6345 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6346 trace_nfs4_create_session(clp
, status
);
6349 /* Verify the session's negotiated channel_attrs values */
6350 status
= nfs4_verify_channel_attrs(&args
, session
);
6351 /* Increment the clientid slot sequence id */
6359 * Issues a CREATE_SESSION operation to the server.
6360 * It is the responsibility of the caller to verify the session is
6361 * expired before calling this routine.
6363 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6367 struct nfs4_session
*session
= clp
->cl_session
;
6369 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
6371 status
= _nfs4_proc_create_session(clp
, cred
);
6375 /* Init or reset the session slot tables */
6376 status
= nfs4_setup_session_slot_tables(session
);
6377 dprintk("slot table setup returned %d\n", status
);
6381 ptr
= (unsigned *)&session
->sess_id
.data
[0];
6382 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
6383 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
6385 dprintk("<-- %s\n", __func__
);
6390 * Issue the over-the-wire RPC DESTROY_SESSION.
6391 * The caller must serialize access to this routine.
6393 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
6394 struct rpc_cred
*cred
)
6396 struct rpc_message msg
= {
6397 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
6398 .rpc_argp
= session
,
6403 dprintk("--> nfs4_proc_destroy_session\n");
6405 /* session is still being setup */
6406 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
6409 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6410 trace_nfs4_destroy_session(session
->clp
, status
);
6413 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
6414 "Session has been destroyed regardless...\n", status
);
6416 dprintk("<-- nfs4_proc_destroy_session\n");
6421 * Renew the cl_session lease.
6423 struct nfs4_sequence_data
{
6424 struct nfs_client
*clp
;
6425 struct nfs4_sequence_args args
;
6426 struct nfs4_sequence_res res
;
6429 static void nfs41_sequence_release(void *data
)
6431 struct nfs4_sequence_data
*calldata
= data
;
6432 struct nfs_client
*clp
= calldata
->clp
;
6434 if (atomic_read(&clp
->cl_count
) > 1)
6435 nfs4_schedule_state_renewal(clp
);
6436 nfs_put_client(clp
);
6440 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6442 switch(task
->tk_status
) {
6443 case -NFS4ERR_DELAY
:
6444 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6447 nfs4_schedule_lease_recovery(clp
);
6452 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
6454 struct nfs4_sequence_data
*calldata
= data
;
6455 struct nfs_client
*clp
= calldata
->clp
;
6457 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
6460 trace_nfs4_sequence(clp
, task
->tk_status
);
6461 if (task
->tk_status
< 0) {
6462 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
6463 if (atomic_read(&clp
->cl_count
) == 1)
6466 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
6467 rpc_restart_call_prepare(task
);
6471 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
6473 dprintk("<-- %s\n", __func__
);
6476 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
6478 struct nfs4_sequence_data
*calldata
= data
;
6479 struct nfs_client
*clp
= calldata
->clp
;
6480 struct nfs4_sequence_args
*args
;
6481 struct nfs4_sequence_res
*res
;
6483 args
= task
->tk_msg
.rpc_argp
;
6484 res
= task
->tk_msg
.rpc_resp
;
6486 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
6489 static const struct rpc_call_ops nfs41_sequence_ops
= {
6490 .rpc_call_done
= nfs41_sequence_call_done
,
6491 .rpc_call_prepare
= nfs41_sequence_prepare
,
6492 .rpc_release
= nfs41_sequence_release
,
6495 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
6496 struct rpc_cred
*cred
,
6499 struct nfs4_sequence_data
*calldata
;
6500 struct rpc_message msg
= {
6501 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
6504 struct rpc_task_setup task_setup_data
= {
6505 .rpc_client
= clp
->cl_rpcclient
,
6506 .rpc_message
= &msg
,
6507 .callback_ops
= &nfs41_sequence_ops
,
6508 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
6511 if (!atomic_inc_not_zero(&clp
->cl_count
))
6512 return ERR_PTR(-EIO
);
6513 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6514 if (calldata
== NULL
) {
6515 nfs_put_client(clp
);
6516 return ERR_PTR(-ENOMEM
);
6518 nfs41_init_sequence(&calldata
->args
, &calldata
->res
, 0);
6520 nfs4_set_sequence_privileged(&calldata
->args
);
6521 msg
.rpc_argp
= &calldata
->args
;
6522 msg
.rpc_resp
= &calldata
->res
;
6523 calldata
->clp
= clp
;
6524 task_setup_data
.callback_data
= calldata
;
6526 return rpc_run_task(&task_setup_data
);
6529 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
6531 struct rpc_task
*task
;
6534 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
6536 task
= _nfs41_proc_sequence(clp
, cred
, false);
6538 ret
= PTR_ERR(task
);
6540 rpc_put_task_async(task
);
6541 dprintk("<-- %s status=%d\n", __func__
, ret
);
6545 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6547 struct rpc_task
*task
;
6550 task
= _nfs41_proc_sequence(clp
, cred
, true);
6552 ret
= PTR_ERR(task
);
6555 ret
= rpc_wait_for_completion_task(task
);
6557 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
6559 if (task
->tk_status
== 0)
6560 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
6561 ret
= task
->tk_status
;
6565 dprintk("<-- %s status=%d\n", __func__
, ret
);
6569 struct nfs4_reclaim_complete_data
{
6570 struct nfs_client
*clp
;
6571 struct nfs41_reclaim_complete_args arg
;
6572 struct nfs41_reclaim_complete_res res
;
6575 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
6577 struct nfs4_reclaim_complete_data
*calldata
= data
;
6579 nfs41_setup_sequence(calldata
->clp
->cl_session
,
6580 &calldata
->arg
.seq_args
,
6581 &calldata
->res
.seq_res
,
6585 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
6587 switch(task
->tk_status
) {
6589 case -NFS4ERR_COMPLETE_ALREADY
:
6590 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
6592 case -NFS4ERR_DELAY
:
6593 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
6595 case -NFS4ERR_RETRY_UNCACHED_REP
:
6598 nfs4_schedule_lease_recovery(clp
);
6603 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
6605 struct nfs4_reclaim_complete_data
*calldata
= data
;
6606 struct nfs_client
*clp
= calldata
->clp
;
6607 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
6609 dprintk("--> %s\n", __func__
);
6610 if (!nfs41_sequence_done(task
, res
))
6613 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
6614 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
6615 rpc_restart_call_prepare(task
);
6618 dprintk("<-- %s\n", __func__
);
6621 static void nfs4_free_reclaim_complete_data(void *data
)
6623 struct nfs4_reclaim_complete_data
*calldata
= data
;
6628 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
6629 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
6630 .rpc_call_done
= nfs4_reclaim_complete_done
,
6631 .rpc_release
= nfs4_free_reclaim_complete_data
,
6635 * Issue a global reclaim complete.
6637 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
6638 struct rpc_cred
*cred
)
6640 struct nfs4_reclaim_complete_data
*calldata
;
6641 struct rpc_task
*task
;
6642 struct rpc_message msg
= {
6643 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
6646 struct rpc_task_setup task_setup_data
= {
6647 .rpc_client
= clp
->cl_rpcclient
,
6648 .rpc_message
= &msg
,
6649 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
6650 .flags
= RPC_TASK_ASYNC
,
6652 int status
= -ENOMEM
;
6654 dprintk("--> %s\n", __func__
);
6655 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
6656 if (calldata
== NULL
)
6658 calldata
->clp
= clp
;
6659 calldata
->arg
.one_fs
= 0;
6661 nfs41_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
6662 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
6663 msg
.rpc_argp
= &calldata
->arg
;
6664 msg
.rpc_resp
= &calldata
->res
;
6665 task_setup_data
.callback_data
= calldata
;
6666 task
= rpc_run_task(&task_setup_data
);
6668 status
= PTR_ERR(task
);
6671 status
= nfs4_wait_for_completion_rpc_task(task
);
6673 status
= task
->tk_status
;
6677 dprintk("<-- %s status=%d\n", __func__
, status
);
6682 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
6684 struct nfs4_layoutget
*lgp
= calldata
;
6685 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
6686 struct nfs4_session
*session
= nfs4_get_session(server
);
6688 dprintk("--> %s\n", __func__
);
6689 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6690 * right now covering the LAYOUTGET we are about to send.
6691 * However, that is not so catastrophic, and there seems
6692 * to be no way to prevent it completely.
6694 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
6695 &lgp
->res
.seq_res
, task
))
6697 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
6698 NFS_I(lgp
->args
.inode
)->layout
,
6699 lgp
->args
.ctx
->state
)) {
6700 rpc_exit(task
, NFS4_OK
);
6704 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
6706 struct nfs4_layoutget
*lgp
= calldata
;
6707 struct inode
*inode
= lgp
->args
.inode
;
6708 struct nfs_server
*server
= NFS_SERVER(inode
);
6709 struct pnfs_layout_hdr
*lo
;
6710 struct nfs4_state
*state
= NULL
;
6711 unsigned long timeo
, giveup
;
6713 dprintk("--> %s\n", __func__
);
6715 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
6718 switch (task
->tk_status
) {
6721 case -NFS4ERR_LAYOUTTRYLATER
:
6722 case -NFS4ERR_RECALLCONFLICT
:
6723 timeo
= rpc_get_timeout(task
->tk_client
);
6724 giveup
= lgp
->args
.timestamp
+ timeo
;
6725 if (time_after(giveup
, jiffies
))
6726 task
->tk_status
= -NFS4ERR_DELAY
;
6728 case -NFS4ERR_EXPIRED
:
6729 case -NFS4ERR_BAD_STATEID
:
6730 spin_lock(&inode
->i_lock
);
6731 lo
= NFS_I(inode
)->layout
;
6732 if (!lo
|| list_empty(&lo
->plh_segs
)) {
6733 spin_unlock(&inode
->i_lock
);
6734 /* If the open stateid was bad, then recover it. */
6735 state
= lgp
->args
.ctx
->state
;
6739 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
6740 spin_unlock(&inode
->i_lock
);
6741 /* Mark the bad layout state as invalid, then
6742 * retry using the open stateid. */
6743 pnfs_free_lseg_list(&head
);
6746 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
6747 rpc_restart_call_prepare(task
);
6749 dprintk("<-- %s\n", __func__
);
6752 static size_t max_response_pages(struct nfs_server
*server
)
6754 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
6755 return nfs_page_array_len(0, max_resp_sz
);
6758 static void nfs4_free_pages(struct page
**pages
, size_t size
)
6765 for (i
= 0; i
< size
; i
++) {
6768 __free_page(pages
[i
]);
6773 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
6775 struct page
**pages
;
6778 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
6780 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
6784 for (i
= 0; i
< size
; i
++) {
6785 pages
[i
] = alloc_page(gfp_flags
);
6787 dprintk("%s: failed to allocate page\n", __func__
);
6788 nfs4_free_pages(pages
, size
);
6796 static void nfs4_layoutget_release(void *calldata
)
6798 struct nfs4_layoutget
*lgp
= calldata
;
6799 struct inode
*inode
= lgp
->args
.inode
;
6800 struct nfs_server
*server
= NFS_SERVER(inode
);
6801 size_t max_pages
= max_response_pages(server
);
6803 dprintk("--> %s\n", __func__
);
6804 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
6805 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
6806 put_nfs_open_context(lgp
->args
.ctx
);
6808 dprintk("<-- %s\n", __func__
);
6811 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
6812 .rpc_call_prepare
= nfs4_layoutget_prepare
,
6813 .rpc_call_done
= nfs4_layoutget_done
,
6814 .rpc_release
= nfs4_layoutget_release
,
6817 struct pnfs_layout_segment
*
6818 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
6820 struct inode
*inode
= lgp
->args
.inode
;
6821 struct nfs_server
*server
= NFS_SERVER(inode
);
6822 size_t max_pages
= max_response_pages(server
);
6823 struct rpc_task
*task
;
6824 struct rpc_message msg
= {
6825 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
6826 .rpc_argp
= &lgp
->args
,
6827 .rpc_resp
= &lgp
->res
,
6828 .rpc_cred
= lgp
->cred
,
6830 struct rpc_task_setup task_setup_data
= {
6831 .rpc_client
= server
->client
,
6832 .rpc_message
= &msg
,
6833 .callback_ops
= &nfs4_layoutget_call_ops
,
6834 .callback_data
= lgp
,
6835 .flags
= RPC_TASK_ASYNC
,
6837 struct pnfs_layout_segment
*lseg
= NULL
;
6840 dprintk("--> %s\n", __func__
);
6842 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
6843 if (!lgp
->args
.layout
.pages
) {
6844 nfs4_layoutget_release(lgp
);
6845 return ERR_PTR(-ENOMEM
);
6847 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
6848 lgp
->args
.timestamp
= jiffies
;
6850 lgp
->res
.layoutp
= &lgp
->args
.layout
;
6851 lgp
->res
.seq_res
.sr_slot
= NULL
;
6852 nfs41_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
6854 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6855 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
6857 task
= rpc_run_task(&task_setup_data
);
6859 return ERR_CAST(task
);
6860 status
= nfs4_wait_for_completion_rpc_task(task
);
6862 status
= task
->tk_status
;
6863 trace_nfs4_layoutget(lgp
->args
.ctx
,
6867 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6868 if (status
== 0 && lgp
->res
.layoutp
->len
)
6869 lseg
= pnfs_layout_process(lgp
);
6871 dprintk("<-- %s status=%d\n", __func__
, status
);
6873 return ERR_PTR(status
);
6878 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
6880 struct nfs4_layoutreturn
*lrp
= calldata
;
6882 dprintk("--> %s\n", __func__
);
6883 nfs41_setup_sequence(lrp
->clp
->cl_session
,
6884 &lrp
->args
.seq_args
,
6889 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
6891 struct nfs4_layoutreturn
*lrp
= calldata
;
6892 struct nfs_server
*server
;
6894 dprintk("--> %s\n", __func__
);
6896 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
6899 server
= NFS_SERVER(lrp
->args
.inode
);
6900 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
6901 rpc_restart_call_prepare(task
);
6904 dprintk("<-- %s\n", __func__
);
6907 static void nfs4_layoutreturn_release(void *calldata
)
6909 struct nfs4_layoutreturn
*lrp
= calldata
;
6910 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
6912 dprintk("--> %s\n", __func__
);
6913 spin_lock(&lo
->plh_inode
->i_lock
);
6914 if (lrp
->res
.lrs_present
)
6915 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
6916 lo
->plh_block_lgets
--;
6917 spin_unlock(&lo
->plh_inode
->i_lock
);
6918 pnfs_put_layout_hdr(lrp
->args
.layout
);
6920 dprintk("<-- %s\n", __func__
);
6923 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
6924 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
6925 .rpc_call_done
= nfs4_layoutreturn_done
,
6926 .rpc_release
= nfs4_layoutreturn_release
,
6929 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
6931 struct rpc_task
*task
;
6932 struct rpc_message msg
= {
6933 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
6934 .rpc_argp
= &lrp
->args
,
6935 .rpc_resp
= &lrp
->res
,
6936 .rpc_cred
= lrp
->cred
,
6938 struct rpc_task_setup task_setup_data
= {
6939 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
6940 .rpc_message
= &msg
,
6941 .callback_ops
= &nfs4_layoutreturn_call_ops
,
6942 .callback_data
= lrp
,
6946 dprintk("--> %s\n", __func__
);
6947 nfs41_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
6948 task
= rpc_run_task(&task_setup_data
);
6950 return PTR_ERR(task
);
6951 status
= task
->tk_status
;
6952 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
6953 dprintk("<-- %s status=%d\n", __func__
, status
);
6959 * Retrieve the list of Data Server devices from the MDS.
6961 static int _nfs4_getdevicelist(struct nfs_server
*server
,
6962 const struct nfs_fh
*fh
,
6963 struct pnfs_devicelist
*devlist
)
6965 struct nfs4_getdevicelist_args args
= {
6967 .layoutclass
= server
->pnfs_curr_ld
->id
,
6969 struct nfs4_getdevicelist_res res
= {
6972 struct rpc_message msg
= {
6973 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
6979 dprintk("--> %s\n", __func__
);
6980 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
6982 dprintk("<-- %s status=%d\n", __func__
, status
);
6986 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
6987 const struct nfs_fh
*fh
,
6988 struct pnfs_devicelist
*devlist
)
6990 struct nfs4_exception exception
= { };
6994 err
= nfs4_handle_exception(server
,
6995 _nfs4_getdevicelist(server
, fh
, devlist
),
6997 } while (exception
.retry
);
6999 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
7000 err
, devlist
->num_devs
);
7004 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
7007 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7008 struct pnfs_device
*pdev
,
7009 struct rpc_cred
*cred
)
7011 struct nfs4_getdeviceinfo_args args
= {
7014 struct nfs4_getdeviceinfo_res res
= {
7017 struct rpc_message msg
= {
7018 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7025 dprintk("--> %s\n", __func__
);
7026 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7027 dprintk("<-- %s status=%d\n", __func__
, status
);
7032 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7033 struct pnfs_device
*pdev
,
7034 struct rpc_cred
*cred
)
7036 struct nfs4_exception exception
= { };
7040 err
= nfs4_handle_exception(server
,
7041 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7043 } while (exception
.retry
);
7046 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7048 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7050 struct nfs4_layoutcommit_data
*data
= calldata
;
7051 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7052 struct nfs4_session
*session
= nfs4_get_session(server
);
7054 nfs41_setup_sequence(session
,
7055 &data
->args
.seq_args
,
7061 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7063 struct nfs4_layoutcommit_data
*data
= calldata
;
7064 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7066 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7069 switch (task
->tk_status
) { /* Just ignore these failures */
7070 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7071 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7072 case -NFS4ERR_BADLAYOUT
: /* no layout */
7073 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7074 task
->tk_status
= 0;
7077 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7081 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7082 rpc_restart_call_prepare(task
);
7088 static void nfs4_layoutcommit_release(void *calldata
)
7090 struct nfs4_layoutcommit_data
*data
= calldata
;
7092 pnfs_cleanup_layoutcommit(data
);
7093 put_rpccred(data
->cred
);
7097 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7098 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7099 .rpc_call_done
= nfs4_layoutcommit_done
,
7100 .rpc_release
= nfs4_layoutcommit_release
,
7104 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7106 struct rpc_message msg
= {
7107 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7108 .rpc_argp
= &data
->args
,
7109 .rpc_resp
= &data
->res
,
7110 .rpc_cred
= data
->cred
,
7112 struct rpc_task_setup task_setup_data
= {
7113 .task
= &data
->task
,
7114 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7115 .rpc_message
= &msg
,
7116 .callback_ops
= &nfs4_layoutcommit_ops
,
7117 .callback_data
= data
,
7118 .flags
= RPC_TASK_ASYNC
,
7120 struct rpc_task
*task
;
7123 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7124 "lbw: %llu inode %lu\n",
7125 data
->task
.tk_pid
, sync
,
7126 data
->args
.lastbytewritten
,
7127 data
->args
.inode
->i_ino
);
7129 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7130 task
= rpc_run_task(&task_setup_data
);
7132 return PTR_ERR(task
);
7135 status
= nfs4_wait_for_completion_rpc_task(task
);
7138 status
= task
->tk_status
;
7139 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7141 dprintk("%s: status %d\n", __func__
, status
);
7147 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7148 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7151 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7152 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7154 struct nfs41_secinfo_no_name_args args
= {
7155 .style
= SECINFO_STYLE_CURRENT_FH
,
7157 struct nfs4_secinfo_res res
= {
7160 struct rpc_message msg
= {
7161 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
7165 return nfs4_call_sync(server
->nfs_client
->cl_rpcclient
, server
, &msg
,
7166 &args
.seq_args
, &res
.seq_res
, 0);
7170 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7171 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7173 struct nfs4_exception exception
= { };
7176 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7179 case -NFS4ERR_WRONGSEC
:
7180 case -NFS4ERR_NOTSUPP
:
7183 err
= nfs4_handle_exception(server
, err
, &exception
);
7185 } while (exception
.retry
);
7191 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7192 struct nfs_fsinfo
*info
)
7196 rpc_authflavor_t flavor
;
7197 struct nfs4_secinfo_flavors
*flavors
;
7199 page
= alloc_page(GFP_KERNEL
);
7205 flavors
= page_address(page
);
7206 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7209 * Fall back on "guess and check" method if
7210 * the server doesn't support SECINFO_NO_NAME
7212 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
7213 err
= nfs4_find_root_sec(server
, fhandle
, info
);
7219 flavor
= nfs_find_best_sec(flavors
);
7221 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
7231 static int _nfs41_test_stateid(struct nfs_server
*server
,
7232 nfs4_stateid
*stateid
,
7233 struct rpc_cred
*cred
)
7236 struct nfs41_test_stateid_args args
= {
7239 struct nfs41_test_stateid_res res
;
7240 struct rpc_message msg
= {
7241 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
7247 dprintk("NFS call test_stateid %p\n", stateid
);
7248 nfs41_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
7249 nfs4_set_sequence_privileged(&args
.seq_args
);
7250 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
,
7251 &args
.seq_args
, &res
.seq_res
);
7252 if (status
!= NFS_OK
) {
7253 dprintk("NFS reply test_stateid: failed, %d\n", status
);
7256 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
7261 * nfs41_test_stateid - perform a TEST_STATEID operation
7263 * @server: server / transport on which to perform the operation
7264 * @stateid: state ID to test
7267 * Returns NFS_OK if the server recognizes that "stateid" is valid.
7268 * Otherwise a negative NFS4ERR value is returned if the operation
7269 * failed or the state ID is not currently valid.
7271 static int nfs41_test_stateid(struct nfs_server
*server
,
7272 nfs4_stateid
*stateid
,
7273 struct rpc_cred
*cred
)
7275 struct nfs4_exception exception
= { };
7278 err
= _nfs41_test_stateid(server
, stateid
, cred
);
7279 if (err
!= -NFS4ERR_DELAY
)
7281 nfs4_handle_exception(server
, err
, &exception
);
7282 } while (exception
.retry
);
7286 struct nfs_free_stateid_data
{
7287 struct nfs_server
*server
;
7288 struct nfs41_free_stateid_args args
;
7289 struct nfs41_free_stateid_res res
;
7292 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
7294 struct nfs_free_stateid_data
*data
= calldata
;
7295 nfs41_setup_sequence(nfs4_get_session(data
->server
),
7296 &data
->args
.seq_args
,
7301 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
7303 struct nfs_free_stateid_data
*data
= calldata
;
7305 nfs41_sequence_done(task
, &data
->res
.seq_res
);
7307 switch (task
->tk_status
) {
7308 case -NFS4ERR_DELAY
:
7309 if (nfs4_async_handle_error(task
, data
->server
, NULL
) == -EAGAIN
)
7310 rpc_restart_call_prepare(task
);
7314 static void nfs41_free_stateid_release(void *calldata
)
7319 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
7320 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
7321 .rpc_call_done
= nfs41_free_stateid_done
,
7322 .rpc_release
= nfs41_free_stateid_release
,
7325 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
7326 nfs4_stateid
*stateid
,
7327 struct rpc_cred
*cred
,
7330 struct rpc_message msg
= {
7331 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
7334 struct rpc_task_setup task_setup
= {
7335 .rpc_client
= server
->client
,
7336 .rpc_message
= &msg
,
7337 .callback_ops
= &nfs41_free_stateid_ops
,
7338 .flags
= RPC_TASK_ASYNC
,
7340 struct nfs_free_stateid_data
*data
;
7342 dprintk("NFS call free_stateid %p\n", stateid
);
7343 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
7345 return ERR_PTR(-ENOMEM
);
7346 data
->server
= server
;
7347 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
7349 task_setup
.callback_data
= data
;
7351 msg
.rpc_argp
= &data
->args
;
7352 msg
.rpc_resp
= &data
->res
;
7353 nfs41_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
7355 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
7357 return rpc_run_task(&task_setup
);
7361 * nfs41_free_stateid - perform a FREE_STATEID operation
7363 * @server: server / transport on which to perform the operation
7364 * @stateid: state ID to release
7367 * Returns NFS_OK if the server freed "stateid". Otherwise a
7368 * negative NFS4ERR value is returned.
7370 static int nfs41_free_stateid(struct nfs_server
*server
,
7371 nfs4_stateid
*stateid
,
7372 struct rpc_cred
*cred
)
7374 struct rpc_task
*task
;
7377 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
7379 return PTR_ERR(task
);
7380 ret
= rpc_wait_for_completion_task(task
);
7382 ret
= task
->tk_status
;
7387 static int nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
7389 struct rpc_task
*task
;
7390 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
7392 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
7393 nfs4_free_lock_state(server
, lsp
);
7395 return PTR_ERR(task
);
7400 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
7401 const nfs4_stateid
*s2
)
7403 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
7406 if (s1
->seqid
== s2
->seqid
)
7408 if (s1
->seqid
== 0 || s2
->seqid
== 0)
7414 #endif /* CONFIG_NFS_V4_1 */
7416 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
7417 const nfs4_stateid
*s2
)
7419 return nfs4_stateid_match(s1
, s2
);
7423 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
7424 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7425 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7426 .recover_open
= nfs4_open_reclaim
,
7427 .recover_lock
= nfs4_lock_reclaim
,
7428 .establish_clid
= nfs4_init_clientid
,
7429 .detect_trunking
= nfs40_discover_server_trunking
,
7432 #if defined(CONFIG_NFS_V4_1)
7433 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
7434 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
7435 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
7436 .recover_open
= nfs4_open_reclaim
,
7437 .recover_lock
= nfs4_lock_reclaim
,
7438 .establish_clid
= nfs41_init_clientid
,
7439 .reclaim_complete
= nfs41_proc_reclaim_complete
,
7440 .detect_trunking
= nfs41_discover_server_trunking
,
7442 #endif /* CONFIG_NFS_V4_1 */
7444 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
7445 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7446 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7447 .recover_open
= nfs4_open_expired
,
7448 .recover_lock
= nfs4_lock_expired
,
7449 .establish_clid
= nfs4_init_clientid
,
7452 #if defined(CONFIG_NFS_V4_1)
7453 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
7454 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
7455 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
7456 .recover_open
= nfs41_open_expired
,
7457 .recover_lock
= nfs41_lock_expired
,
7458 .establish_clid
= nfs41_init_clientid
,
7460 #endif /* CONFIG_NFS_V4_1 */
7462 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
7463 .sched_state_renewal
= nfs4_proc_async_renew
,
7464 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
7465 .renew_lease
= nfs4_proc_renew
,
7468 #if defined(CONFIG_NFS_V4_1)
7469 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
7470 .sched_state_renewal
= nfs41_proc_async_sequence
,
7471 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
7472 .renew_lease
= nfs4_proc_sequence
,
7476 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
7478 .init_caps
= NFS_CAP_READDIRPLUS
7479 | NFS_CAP_ATOMIC_OPEN
7480 | NFS_CAP_CHANGE_ATTR
7481 | NFS_CAP_POSIX_LOCK
,
7482 .call_sync
= _nfs4_call_sync
,
7483 .match_stateid
= nfs4_match_stateid
,
7484 .find_root_sec
= nfs4_find_root_sec
,
7485 .free_lock_state
= nfs4_release_lockowner
,
7486 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
7487 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
7488 .state_renewal_ops
= &nfs40_state_renewal_ops
,
7491 #if defined(CONFIG_NFS_V4_1)
7492 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
7494 .init_caps
= NFS_CAP_READDIRPLUS
7495 | NFS_CAP_ATOMIC_OPEN
7496 | NFS_CAP_CHANGE_ATTR
7497 | NFS_CAP_POSIX_LOCK
7498 | NFS_CAP_STATEID_NFSV41
7499 | NFS_CAP_ATOMIC_OPEN_V1
,
7500 .call_sync
= nfs4_call_sync_sequence
,
7501 .match_stateid
= nfs41_match_stateid
,
7502 .find_root_sec
= nfs41_find_root_sec
,
7503 .free_lock_state
= nfs41_free_lock_state
,
7504 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7505 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7506 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7510 #if defined(CONFIG_NFS_V4_2)
7511 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
7513 .init_caps
= NFS_CAP_READDIRPLUS
7514 | NFS_CAP_ATOMIC_OPEN
7515 | NFS_CAP_CHANGE_ATTR
7516 | NFS_CAP_POSIX_LOCK
7517 | NFS_CAP_STATEID_NFSV41
7518 | NFS_CAP_ATOMIC_OPEN_V1
,
7519 .call_sync
= nfs4_call_sync_sequence
,
7520 .match_stateid
= nfs41_match_stateid
,
7521 .find_root_sec
= nfs41_find_root_sec
,
7522 .free_lock_state
= nfs41_free_lock_state
,
7523 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
7524 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
7525 .state_renewal_ops
= &nfs41_state_renewal_ops
,
7529 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
7530 [0] = &nfs_v4_0_minor_ops
,
7531 #if defined(CONFIG_NFS_V4_1)
7532 [1] = &nfs_v4_1_minor_ops
,
7534 #if defined(CONFIG_NFS_V4_2)
7535 [2] = &nfs_v4_2_minor_ops
,
7539 static const struct inode_operations nfs4_dir_inode_operations
= {
7540 .create
= nfs_create
,
7541 .lookup
= nfs_lookup
,
7542 .atomic_open
= nfs_atomic_open
,
7544 .unlink
= nfs_unlink
,
7545 .symlink
= nfs_symlink
,
7549 .rename
= nfs_rename
,
7550 .permission
= nfs_permission
,
7551 .getattr
= nfs_getattr
,
7552 .setattr
= nfs_setattr
,
7553 .getxattr
= generic_getxattr
,
7554 .setxattr
= generic_setxattr
,
7555 .listxattr
= generic_listxattr
,
7556 .removexattr
= generic_removexattr
,
7559 static const struct inode_operations nfs4_file_inode_operations
= {
7560 .permission
= nfs_permission
,
7561 .getattr
= nfs_getattr
,
7562 .setattr
= nfs_setattr
,
7563 .getxattr
= generic_getxattr
,
7564 .setxattr
= generic_setxattr
,
7565 .listxattr
= generic_listxattr
,
7566 .removexattr
= generic_removexattr
,
7569 const struct nfs_rpc_ops nfs_v4_clientops
= {
7570 .version
= 4, /* protocol version */
7571 .dentry_ops
= &nfs4_dentry_operations
,
7572 .dir_inode_ops
= &nfs4_dir_inode_operations
,
7573 .file_inode_ops
= &nfs4_file_inode_operations
,
7574 .file_ops
= &nfs4_file_operations
,
7575 .getroot
= nfs4_proc_get_root
,
7576 .submount
= nfs4_submount
,
7577 .try_mount
= nfs4_try_mount
,
7578 .getattr
= nfs4_proc_getattr
,
7579 .setattr
= nfs4_proc_setattr
,
7580 .lookup
= nfs4_proc_lookup
,
7581 .access
= nfs4_proc_access
,
7582 .readlink
= nfs4_proc_readlink
,
7583 .create
= nfs4_proc_create
,
7584 .remove
= nfs4_proc_remove
,
7585 .unlink_setup
= nfs4_proc_unlink_setup
,
7586 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
7587 .unlink_done
= nfs4_proc_unlink_done
,
7588 .rename
= nfs4_proc_rename
,
7589 .rename_setup
= nfs4_proc_rename_setup
,
7590 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
7591 .rename_done
= nfs4_proc_rename_done
,
7592 .link
= nfs4_proc_link
,
7593 .symlink
= nfs4_proc_symlink
,
7594 .mkdir
= nfs4_proc_mkdir
,
7595 .rmdir
= nfs4_proc_remove
,
7596 .readdir
= nfs4_proc_readdir
,
7597 .mknod
= nfs4_proc_mknod
,
7598 .statfs
= nfs4_proc_statfs
,
7599 .fsinfo
= nfs4_proc_fsinfo
,
7600 .pathconf
= nfs4_proc_pathconf
,
7601 .set_capabilities
= nfs4_server_capabilities
,
7602 .decode_dirent
= nfs4_decode_dirent
,
7603 .read_setup
= nfs4_proc_read_setup
,
7604 .read_pageio_init
= pnfs_pageio_init_read
,
7605 .read_rpc_prepare
= nfs4_proc_read_rpc_prepare
,
7606 .read_done
= nfs4_read_done
,
7607 .write_setup
= nfs4_proc_write_setup
,
7608 .write_pageio_init
= pnfs_pageio_init_write
,
7609 .write_rpc_prepare
= nfs4_proc_write_rpc_prepare
,
7610 .write_done
= nfs4_write_done
,
7611 .commit_setup
= nfs4_proc_commit_setup
,
7612 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
7613 .commit_done
= nfs4_commit_done
,
7614 .lock
= nfs4_proc_lock
,
7615 .clear_acl_cache
= nfs4_zap_acl_attr
,
7616 .close_context
= nfs4_close_context
,
7617 .open_context
= nfs4_atomic_open
,
7618 .have_delegation
= nfs4_have_delegation
,
7619 .return_delegation
= nfs4_inode_return_delegation
,
7620 .alloc_client
= nfs4_alloc_client
,
7621 .init_client
= nfs4_init_client
,
7622 .free_client
= nfs4_free_client
,
7623 .create_server
= nfs4_create_server
,
7624 .clone_server
= nfs_clone_server
,
7627 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
7628 .prefix
= XATTR_NAME_NFSV4_ACL
,
7629 .list
= nfs4_xattr_list_nfs4_acl
,
7630 .get
= nfs4_xattr_get_nfs4_acl
,
7631 .set
= nfs4_xattr_set_nfs4_acl
,
7634 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
7635 &nfs4_xattr_nfs4_acl_handler
,
7636 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7637 &nfs4_xattr_nfs4_label_handler
,