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 err
= security_dentry_init_security(dentry
, sattr
->ia_mode
,
109 &dentry
->d_name
, (void **)&label
->label
, &label
->len
);
116 nfs4_label_release_security(struct nfs4_label
*label
)
119 security_release_secctx(label
->label
, label
->len
);
121 static inline u32
*nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
124 return server
->attr_bitmask
;
126 return server
->attr_bitmask_nl
;
129 static inline struct nfs4_label
*
130 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
131 struct iattr
*sattr
, struct nfs4_label
*l
)
134 nfs4_label_release_security(struct nfs4_label
*label
)
137 nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
138 { return server
->attr_bitmask
; }
141 /* Prevent leaks of NFSv4 errors into userland */
142 static int nfs4_map_errors(int err
)
147 case -NFS4ERR_RESOURCE
:
148 case -NFS4ERR_LAYOUTTRYLATER
:
149 case -NFS4ERR_RECALLCONFLICT
:
151 case -NFS4ERR_WRONGSEC
:
152 case -NFS4ERR_WRONG_CRED
:
154 case -NFS4ERR_BADOWNER
:
155 case -NFS4ERR_BADNAME
:
157 case -NFS4ERR_SHARE_DENIED
:
159 case -NFS4ERR_MINOR_VERS_MISMATCH
:
160 return -EPROTONOSUPPORT
;
161 case -NFS4ERR_ACCESS
:
163 case -NFS4ERR_FILE_OPEN
:
166 dprintk("%s could not handle NFSv4 error %d\n",
174 * This is our standard bitmap for GETATTR requests.
176 const u32 nfs4_fattr_bitmap
[3] = {
178 | FATTR4_WORD0_CHANGE
181 | FATTR4_WORD0_FILEID
,
183 | FATTR4_WORD1_NUMLINKS
185 | FATTR4_WORD1_OWNER_GROUP
186 | FATTR4_WORD1_RAWDEV
187 | FATTR4_WORD1_SPACE_USED
188 | FATTR4_WORD1_TIME_ACCESS
189 | FATTR4_WORD1_TIME_METADATA
190 | FATTR4_WORD1_TIME_MODIFY
,
191 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
192 FATTR4_WORD2_SECURITY_LABEL
196 static const u32 nfs4_pnfs_open_bitmap
[3] = {
198 | FATTR4_WORD0_CHANGE
201 | FATTR4_WORD0_FILEID
,
203 | FATTR4_WORD1_NUMLINKS
205 | FATTR4_WORD1_OWNER_GROUP
206 | FATTR4_WORD1_RAWDEV
207 | FATTR4_WORD1_SPACE_USED
208 | FATTR4_WORD1_TIME_ACCESS
209 | FATTR4_WORD1_TIME_METADATA
210 | FATTR4_WORD1_TIME_MODIFY
,
211 FATTR4_WORD2_MDSTHRESHOLD
214 static const u32 nfs4_open_noattr_bitmap
[3] = {
216 | FATTR4_WORD0_CHANGE
217 | FATTR4_WORD0_FILEID
,
220 const u32 nfs4_statfs_bitmap
[3] = {
221 FATTR4_WORD0_FILES_AVAIL
222 | FATTR4_WORD0_FILES_FREE
223 | FATTR4_WORD0_FILES_TOTAL
,
224 FATTR4_WORD1_SPACE_AVAIL
225 | FATTR4_WORD1_SPACE_FREE
226 | FATTR4_WORD1_SPACE_TOTAL
229 const u32 nfs4_pathconf_bitmap
[3] = {
231 | FATTR4_WORD0_MAXNAME
,
235 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
236 | FATTR4_WORD0_MAXREAD
237 | FATTR4_WORD0_MAXWRITE
238 | FATTR4_WORD0_LEASE_TIME
,
239 FATTR4_WORD1_TIME_DELTA
240 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
241 FATTR4_WORD2_LAYOUT_BLKSIZE
244 const u32 nfs4_fs_locations_bitmap
[3] = {
246 | FATTR4_WORD0_CHANGE
249 | FATTR4_WORD0_FILEID
250 | FATTR4_WORD0_FS_LOCATIONS
,
252 | FATTR4_WORD1_NUMLINKS
254 | FATTR4_WORD1_OWNER_GROUP
255 | FATTR4_WORD1_RAWDEV
256 | FATTR4_WORD1_SPACE_USED
257 | FATTR4_WORD1_TIME_ACCESS
258 | FATTR4_WORD1_TIME_METADATA
259 | FATTR4_WORD1_TIME_MODIFY
260 | FATTR4_WORD1_MOUNTED_ON_FILEID
,
263 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
264 struct nfs4_readdir_arg
*readdir
)
269 readdir
->cookie
= cookie
;
270 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
275 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
280 * NFSv4 servers do not return entries for '.' and '..'
281 * Therefore, we fake these entries here. We let '.'
282 * have cookie 0 and '..' have cookie 1. Note that
283 * when talking to the server, we always send cookie 0
286 start
= p
= kmap_atomic(*readdir
->pages
);
289 *p
++ = xdr_one
; /* next */
290 *p
++ = xdr_zero
; /* cookie, first word */
291 *p
++ = xdr_one
; /* cookie, second word */
292 *p
++ = xdr_one
; /* entry len */
293 memcpy(p
, ".\0\0\0", 4); /* entry */
295 *p
++ = xdr_one
; /* bitmap length */
296 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
297 *p
++ = htonl(8); /* attribute buffer length */
298 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
301 *p
++ = xdr_one
; /* next */
302 *p
++ = xdr_zero
; /* cookie, first word */
303 *p
++ = xdr_two
; /* cookie, second word */
304 *p
++ = xdr_two
; /* entry len */
305 memcpy(p
, "..\0\0", 4); /* entry */
307 *p
++ = xdr_one
; /* bitmap length */
308 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
309 *p
++ = htonl(8); /* attribute buffer length */
310 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
312 readdir
->pgbase
= (char *)p
- (char *)start
;
313 readdir
->count
-= readdir
->pgbase
;
314 kunmap_atomic(start
);
317 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
324 *timeout
= NFS4_POLL_RETRY_MIN
;
325 if (*timeout
> NFS4_POLL_RETRY_MAX
)
326 *timeout
= NFS4_POLL_RETRY_MAX
;
327 freezable_schedule_timeout_killable_unsafe(*timeout
);
328 if (fatal_signal_pending(current
))
334 /* This is the error handling routine for processes that are allowed
337 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
339 struct nfs_client
*clp
= server
->nfs_client
;
340 struct nfs4_state
*state
= exception
->state
;
341 struct inode
*inode
= exception
->inode
;
344 exception
->retry
= 0;
348 case -NFS4ERR_OPENMODE
:
349 if (inode
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
350 nfs4_inode_return_delegation(inode
);
351 exception
->retry
= 1;
356 ret
= nfs4_schedule_stateid_recovery(server
, state
);
359 goto wait_on_recovery
;
360 case -NFS4ERR_DELEG_REVOKED
:
361 case -NFS4ERR_ADMIN_REVOKED
:
362 case -NFS4ERR_BAD_STATEID
:
363 if (inode
!= NULL
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
364 nfs_remove_bad_delegation(inode
);
365 exception
->retry
= 1;
370 ret
= nfs4_schedule_stateid_recovery(server
, state
);
373 goto wait_on_recovery
;
374 case -NFS4ERR_EXPIRED
:
376 ret
= nfs4_schedule_stateid_recovery(server
, state
);
380 case -NFS4ERR_STALE_STATEID
:
381 case -NFS4ERR_STALE_CLIENTID
:
382 nfs4_schedule_lease_recovery(clp
);
383 goto wait_on_recovery
;
385 ret
= nfs4_schedule_migration_recovery(server
);
388 goto wait_on_recovery
;
389 case -NFS4ERR_LEASE_MOVED
:
390 nfs4_schedule_lease_moved_recovery(clp
);
391 goto wait_on_recovery
;
392 #if defined(CONFIG_NFS_V4_1)
393 case -NFS4ERR_BADSESSION
:
394 case -NFS4ERR_BADSLOT
:
395 case -NFS4ERR_BAD_HIGH_SLOT
:
396 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
397 case -NFS4ERR_DEADSESSION
:
398 case -NFS4ERR_SEQ_FALSE_RETRY
:
399 case -NFS4ERR_SEQ_MISORDERED
:
400 dprintk("%s ERROR: %d Reset session\n", __func__
,
402 nfs4_schedule_session_recovery(clp
->cl_session
, errorcode
);
403 goto wait_on_recovery
;
404 #endif /* defined(CONFIG_NFS_V4_1) */
405 case -NFS4ERR_FILE_OPEN
:
406 if (exception
->timeout
> HZ
) {
407 /* We have retried a decent amount, time to
415 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
418 case -NFS4ERR_RETRY_UNCACHED_REP
:
419 case -NFS4ERR_OLD_STATEID
:
420 exception
->retry
= 1;
422 case -NFS4ERR_BADOWNER
:
423 /* The following works around a Linux server bug! */
424 case -NFS4ERR_BADNAME
:
425 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
426 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
427 exception
->retry
= 1;
428 printk(KERN_WARNING
"NFS: v4 server %s "
429 "does not accept raw "
431 "Reenabling the idmapper.\n",
432 server
->nfs_client
->cl_hostname
);
435 /* We failed to handle the error */
436 return nfs4_map_errors(ret
);
438 ret
= nfs4_wait_clnt_recover(clp
);
439 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
442 exception
->retry
= 1;
447 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
448 * or 'false' otherwise.
450 static bool _nfs4_is_integrity_protected(struct nfs_client
*clp
)
452 rpc_authflavor_t flavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
454 if (flavor
== RPC_AUTH_GSS_KRB5I
||
455 flavor
== RPC_AUTH_GSS_KRB5P
)
461 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
463 spin_lock(&clp
->cl_lock
);
464 if (time_before(clp
->cl_last_renewal
,timestamp
))
465 clp
->cl_last_renewal
= timestamp
;
466 spin_unlock(&clp
->cl_lock
);
469 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
471 do_renew_lease(server
->nfs_client
, timestamp
);
474 struct nfs4_call_sync_data
{
475 const struct nfs_server
*seq_server
;
476 struct nfs4_sequence_args
*seq_args
;
477 struct nfs4_sequence_res
*seq_res
;
480 static void nfs4_init_sequence(struct nfs4_sequence_args
*args
,
481 struct nfs4_sequence_res
*res
, int cache_reply
)
483 args
->sa_slot
= NULL
;
484 args
->sa_cache_this
= cache_reply
;
485 args
->sa_privileged
= 0;
490 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
492 args
->sa_privileged
= 1;
495 static int nfs40_setup_sequence(const struct nfs_server
*server
,
496 struct nfs4_sequence_args
*args
,
497 struct nfs4_sequence_res
*res
,
498 struct rpc_task
*task
)
500 struct nfs4_slot_table
*tbl
= server
->nfs_client
->cl_slot_tbl
;
501 struct nfs4_slot
*slot
;
503 /* slot already allocated? */
504 if (res
->sr_slot
!= NULL
)
507 spin_lock(&tbl
->slot_tbl_lock
);
508 if (nfs4_slot_tbl_draining(tbl
) && !args
->sa_privileged
)
511 slot
= nfs4_alloc_slot(tbl
);
513 if (slot
== ERR_PTR(-ENOMEM
))
514 task
->tk_timeout
= HZ
>> 2;
517 spin_unlock(&tbl
->slot_tbl_lock
);
519 args
->sa_slot
= slot
;
523 rpc_call_start(task
);
527 if (args
->sa_privileged
)
528 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
529 NULL
, RPC_PRIORITY_PRIVILEGED
);
531 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
532 spin_unlock(&tbl
->slot_tbl_lock
);
536 static int nfs40_sequence_done(struct rpc_task
*task
,
537 struct nfs4_sequence_res
*res
)
539 struct nfs4_slot
*slot
= res
->sr_slot
;
540 struct nfs4_slot_table
*tbl
;
546 spin_lock(&tbl
->slot_tbl_lock
);
547 if (!nfs41_wake_and_assign_slot(tbl
, slot
))
548 nfs4_free_slot(tbl
, slot
);
549 spin_unlock(&tbl
->slot_tbl_lock
);
556 #if defined(CONFIG_NFS_V4_1)
558 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
560 struct nfs4_session
*session
;
561 struct nfs4_slot_table
*tbl
;
562 struct nfs4_slot
*slot
= res
->sr_slot
;
563 bool send_new_highest_used_slotid
= false;
566 session
= tbl
->session
;
568 spin_lock(&tbl
->slot_tbl_lock
);
569 /* Be nice to the server: try to ensure that the last transmitted
570 * value for highest_user_slotid <= target_highest_slotid
572 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
573 send_new_highest_used_slotid
= true;
575 if (nfs41_wake_and_assign_slot(tbl
, slot
)) {
576 send_new_highest_used_slotid
= false;
579 nfs4_free_slot(tbl
, slot
);
581 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
582 send_new_highest_used_slotid
= false;
584 spin_unlock(&tbl
->slot_tbl_lock
);
586 if (send_new_highest_used_slotid
)
587 nfs41_server_notify_highest_slotid_update(session
->clp
);
590 int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
592 struct nfs4_session
*session
;
593 struct nfs4_slot
*slot
= res
->sr_slot
;
594 struct nfs_client
*clp
;
595 bool interrupted
= false;
600 /* don't increment the sequence number if the task wasn't sent */
601 if (!RPC_WAS_SENT(task
))
604 session
= slot
->table
->session
;
606 if (slot
->interrupted
) {
607 slot
->interrupted
= 0;
611 trace_nfs4_sequence_done(session
, res
);
612 /* Check the SEQUENCE operation status */
613 switch (res
->sr_status
) {
615 /* Update the slot's sequence and clientid lease timer */
618 do_renew_lease(clp
, res
->sr_timestamp
);
619 /* Check sequence flags */
620 if (res
->sr_status_flags
!= 0)
621 nfs4_schedule_lease_recovery(clp
);
622 nfs41_update_target_slotid(slot
->table
, slot
, res
);
626 * sr_status remains 1 if an RPC level error occurred.
627 * The server may or may not have processed the sequence
629 * Mark the slot as having hosted an interrupted RPC call.
631 slot
->interrupted
= 1;
634 /* The server detected a resend of the RPC call and
635 * returned NFS4ERR_DELAY as per Section 2.10.6.2
638 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
643 case -NFS4ERR_BADSLOT
:
645 * The slot id we used was probably retired. Try again
646 * using a different slot id.
649 case -NFS4ERR_SEQ_MISORDERED
:
651 * Was the last operation on this sequence interrupted?
652 * If so, retry after bumping the sequence number.
659 * Could this slot have been previously retired?
660 * If so, then the server may be expecting seq_nr = 1!
662 if (slot
->seq_nr
!= 1) {
667 case -NFS4ERR_SEQ_FALSE_RETRY
:
671 /* Just update the slot sequence no. */
675 /* The session may be reset by one of the error handlers. */
676 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
677 nfs41_sequence_free_slot(res
);
681 if (rpc_restart_call_prepare(task
)) {
687 if (!rpc_restart_call(task
))
689 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
692 EXPORT_SYMBOL_GPL(nfs41_sequence_done
);
694 static int nfs4_sequence_done(struct rpc_task
*task
,
695 struct nfs4_sequence_res
*res
)
697 if (res
->sr_slot
== NULL
)
699 if (!res
->sr_slot
->table
->session
)
700 return nfs40_sequence_done(task
, res
);
701 return nfs41_sequence_done(task
, res
);
704 int nfs41_setup_sequence(struct nfs4_session
*session
,
705 struct nfs4_sequence_args
*args
,
706 struct nfs4_sequence_res
*res
,
707 struct rpc_task
*task
)
709 struct nfs4_slot
*slot
;
710 struct nfs4_slot_table
*tbl
;
712 dprintk("--> %s\n", __func__
);
713 /* slot already allocated? */
714 if (res
->sr_slot
!= NULL
)
717 tbl
= &session
->fc_slot_table
;
719 task
->tk_timeout
= 0;
721 spin_lock(&tbl
->slot_tbl_lock
);
722 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
723 !args
->sa_privileged
) {
724 /* The state manager will wait until the slot table is empty */
725 dprintk("%s session is draining\n", __func__
);
729 slot
= nfs4_alloc_slot(tbl
);
731 /* If out of memory, try again in 1/4 second */
732 if (slot
== ERR_PTR(-ENOMEM
))
733 task
->tk_timeout
= HZ
>> 2;
734 dprintk("<-- %s: no free slots\n", __func__
);
737 spin_unlock(&tbl
->slot_tbl_lock
);
739 args
->sa_slot
= slot
;
741 dprintk("<-- %s slotid=%u seqid=%u\n", __func__
,
742 slot
->slot_nr
, slot
->seq_nr
);
745 res
->sr_timestamp
= jiffies
;
746 res
->sr_status_flags
= 0;
748 * sr_status is only set in decode_sequence, and so will remain
749 * set to 1 if an rpc level failure occurs.
752 trace_nfs4_setup_sequence(session
, args
);
754 rpc_call_start(task
);
757 /* Privileged tasks are queued with top priority */
758 if (args
->sa_privileged
)
759 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
760 NULL
, RPC_PRIORITY_PRIVILEGED
);
762 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
763 spin_unlock(&tbl
->slot_tbl_lock
);
766 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
768 static int nfs4_setup_sequence(const struct nfs_server
*server
,
769 struct nfs4_sequence_args
*args
,
770 struct nfs4_sequence_res
*res
,
771 struct rpc_task
*task
)
773 struct nfs4_session
*session
= nfs4_get_session(server
);
777 return nfs40_setup_sequence(server
, args
, res
, task
);
779 dprintk("--> %s clp %p session %p sr_slot %u\n",
780 __func__
, session
->clp
, session
, res
->sr_slot
?
781 res
->sr_slot
->slot_nr
: NFS4_NO_SLOT
);
783 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
785 dprintk("<-- %s status=%d\n", __func__
, ret
);
789 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
791 struct nfs4_call_sync_data
*data
= calldata
;
792 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
794 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
796 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
799 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
801 struct nfs4_call_sync_data
*data
= calldata
;
803 nfs41_sequence_done(task
, data
->seq_res
);
806 static const struct rpc_call_ops nfs41_call_sync_ops
= {
807 .rpc_call_prepare
= nfs41_call_sync_prepare
,
808 .rpc_call_done
= nfs41_call_sync_done
,
811 #else /* !CONFIG_NFS_V4_1 */
813 static int nfs4_setup_sequence(const struct nfs_server
*server
,
814 struct nfs4_sequence_args
*args
,
815 struct nfs4_sequence_res
*res
,
816 struct rpc_task
*task
)
818 return nfs40_setup_sequence(server
, args
, res
, task
);
821 static int nfs4_sequence_done(struct rpc_task
*task
,
822 struct nfs4_sequence_res
*res
)
824 return nfs40_sequence_done(task
, res
);
827 #endif /* !CONFIG_NFS_V4_1 */
829 static void nfs40_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
831 struct nfs4_call_sync_data
*data
= calldata
;
832 nfs4_setup_sequence(data
->seq_server
,
833 data
->seq_args
, data
->seq_res
, task
);
836 static void nfs40_call_sync_done(struct rpc_task
*task
, void *calldata
)
838 struct nfs4_call_sync_data
*data
= calldata
;
839 nfs4_sequence_done(task
, data
->seq_res
);
842 static const struct rpc_call_ops nfs40_call_sync_ops
= {
843 .rpc_call_prepare
= nfs40_call_sync_prepare
,
844 .rpc_call_done
= nfs40_call_sync_done
,
847 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
848 struct nfs_server
*server
,
849 struct rpc_message
*msg
,
850 struct nfs4_sequence_args
*args
,
851 struct nfs4_sequence_res
*res
)
854 struct rpc_task
*task
;
855 struct nfs_client
*clp
= server
->nfs_client
;
856 struct nfs4_call_sync_data data
= {
857 .seq_server
= server
,
861 struct rpc_task_setup task_setup
= {
864 .callback_ops
= clp
->cl_mvops
->call_sync_ops
,
865 .callback_data
= &data
868 task
= rpc_run_task(&task_setup
);
872 ret
= task
->tk_status
;
878 int nfs4_call_sync(struct rpc_clnt
*clnt
,
879 struct nfs_server
*server
,
880 struct rpc_message
*msg
,
881 struct nfs4_sequence_args
*args
,
882 struct nfs4_sequence_res
*res
,
885 nfs4_init_sequence(args
, res
, cache_reply
);
886 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
);
889 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
891 struct nfs_inode
*nfsi
= NFS_I(dir
);
893 spin_lock(&dir
->i_lock
);
894 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
895 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
896 nfs_force_lookup_revalidate(dir
);
897 dir
->i_version
= cinfo
->after
;
898 nfs_fscache_invalidate(dir
);
899 spin_unlock(&dir
->i_lock
);
902 struct nfs4_opendata
{
904 struct nfs_openargs o_arg
;
905 struct nfs_openres o_res
;
906 struct nfs_open_confirmargs c_arg
;
907 struct nfs_open_confirmres c_res
;
908 struct nfs4_string owner_name
;
909 struct nfs4_string group_name
;
910 struct nfs_fattr f_attr
;
911 struct nfs4_label
*f_label
;
913 struct dentry
*dentry
;
914 struct nfs4_state_owner
*owner
;
915 struct nfs4_state
*state
;
917 unsigned long timestamp
;
918 unsigned int rpc_done
: 1;
919 unsigned int file_created
: 1;
920 unsigned int is_recover
: 1;
925 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
926 int err
, struct nfs4_exception
*exception
)
930 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
932 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
933 exception
->retry
= 1;
937 static enum open_claim_type4
938 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
939 enum open_claim_type4 claim
)
941 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
946 case NFS4_OPEN_CLAIM_FH
:
947 return NFS4_OPEN_CLAIM_NULL
;
948 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
949 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
950 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
951 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
955 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
957 p
->o_res
.f_attr
= &p
->f_attr
;
958 p
->o_res
.f_label
= p
->f_label
;
959 p
->o_res
.seqid
= p
->o_arg
.seqid
;
960 p
->c_res
.seqid
= p
->c_arg
.seqid
;
961 p
->o_res
.server
= p
->o_arg
.server
;
962 p
->o_res
.access_request
= p
->o_arg
.access
;
963 nfs_fattr_init(&p
->f_attr
);
964 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
967 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
968 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
969 const struct iattr
*attrs
,
970 struct nfs4_label
*label
,
971 enum open_claim_type4 claim
,
974 struct dentry
*parent
= dget_parent(dentry
);
975 struct inode
*dir
= parent
->d_inode
;
976 struct nfs_server
*server
= NFS_SERVER(dir
);
977 struct nfs4_opendata
*p
;
979 p
= kzalloc(sizeof(*p
), gfp_mask
);
983 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
984 if (IS_ERR(p
->f_label
))
987 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
988 if (p
->o_arg
.seqid
== NULL
)
990 nfs_sb_active(dentry
->d_sb
);
991 p
->dentry
= dget(dentry
);
994 atomic_inc(&sp
->so_count
);
995 p
->o_arg
.open_flags
= flags
;
996 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
997 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
998 * will return permission denied for all bits until close */
999 if (!(flags
& O_EXCL
)) {
1000 /* ask server to check for all possible rights as results
1002 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
1003 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
1005 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
1006 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
1007 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
1008 p
->o_arg
.name
= &dentry
->d_name
;
1009 p
->o_arg
.server
= server
;
1010 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
1011 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
1012 p
->o_arg
.label
= label
;
1013 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
1014 switch (p
->o_arg
.claim
) {
1015 case NFS4_OPEN_CLAIM_NULL
:
1016 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1017 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1018 p
->o_arg
.fh
= NFS_FH(dir
);
1020 case NFS4_OPEN_CLAIM_PREVIOUS
:
1021 case NFS4_OPEN_CLAIM_FH
:
1022 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1023 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1024 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
1026 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
1029 p
->o_arg
.u
.attrs
= &p
->attrs
;
1030 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
1033 verf
[1] = current
->pid
;
1034 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
1035 sizeof(p
->o_arg
.u
.verifier
.data
));
1037 p
->c_arg
.fh
= &p
->o_res
.fh
;
1038 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
1039 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
1040 nfs4_init_opendata_res(p
);
1041 kref_init(&p
->kref
);
1045 nfs4_label_free(p
->f_label
);
1053 static void nfs4_opendata_free(struct kref
*kref
)
1055 struct nfs4_opendata
*p
= container_of(kref
,
1056 struct nfs4_opendata
, kref
);
1057 struct super_block
*sb
= p
->dentry
->d_sb
;
1059 nfs_free_seqid(p
->o_arg
.seqid
);
1060 if (p
->state
!= NULL
)
1061 nfs4_put_open_state(p
->state
);
1062 nfs4_put_state_owner(p
->owner
);
1064 nfs4_label_free(p
->f_label
);
1068 nfs_sb_deactive(sb
);
1069 nfs_fattr_free_names(&p
->f_attr
);
1070 kfree(p
->f_attr
.mdsthreshold
);
1074 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1077 kref_put(&p
->kref
, nfs4_opendata_free
);
1080 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
1084 ret
= rpc_wait_for_completion_task(task
);
1088 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1092 if (open_mode
& (O_EXCL
|O_TRUNC
))
1094 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1096 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1097 && state
->n_rdonly
!= 0;
1100 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1101 && state
->n_wronly
!= 0;
1103 case FMODE_READ
|FMODE_WRITE
:
1104 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1105 && state
->n_rdwr
!= 0;
1111 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1113 if (delegation
== NULL
)
1115 if ((delegation
->type
& fmode
) != fmode
)
1117 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1119 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1121 nfs_mark_delegation_referenced(delegation
);
1125 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1134 case FMODE_READ
|FMODE_WRITE
:
1137 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1140 static void nfs_test_and_clear_all_open_stateid(struct nfs4_state
*state
)
1142 struct nfs_client
*clp
= state
->owner
->so_server
->nfs_client
;
1143 bool need_recover
= false;
1145 if (test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
) && state
->n_rdonly
)
1146 need_recover
= true;
1147 if (test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
) && state
->n_wronly
)
1148 need_recover
= true;
1149 if (test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
) && state
->n_rdwr
)
1150 need_recover
= true;
1152 nfs4_state_mark_reclaim_nograce(clp
, state
);
1155 static bool nfs_need_update_open_stateid(struct nfs4_state
*state
,
1156 nfs4_stateid
*stateid
)
1158 if (test_and_set_bit(NFS_OPEN_STATE
, &state
->flags
) == 0)
1160 if (!nfs4_stateid_match_other(stateid
, &state
->open_stateid
)) {
1161 nfs_test_and_clear_all_open_stateid(state
);
1164 if (nfs4_stateid_is_newer(stateid
, &state
->open_stateid
))
1169 static void nfs_clear_open_stateid_locked(struct nfs4_state
*state
,
1170 nfs4_stateid
*stateid
, fmode_t fmode
)
1172 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1173 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1175 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1178 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1181 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1182 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1183 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1185 if (stateid
== NULL
)
1187 if (!nfs_need_update_open_stateid(state
, stateid
))
1189 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1190 nfs4_stateid_copy(&state
->stateid
, stateid
);
1191 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1194 static void nfs_clear_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1196 write_seqlock(&state
->seqlock
);
1197 nfs_clear_open_stateid_locked(state
, stateid
, fmode
);
1198 write_sequnlock(&state
->seqlock
);
1199 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1200 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1203 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1207 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1210 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1212 case FMODE_READ
|FMODE_WRITE
:
1213 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1215 if (!nfs_need_update_open_stateid(state
, stateid
))
1217 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1218 nfs4_stateid_copy(&state
->stateid
, stateid
);
1219 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1222 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1225 * Protect the call to nfs4_state_set_mode_locked and
1226 * serialise the stateid update
1228 write_seqlock(&state
->seqlock
);
1229 if (deleg_stateid
!= NULL
) {
1230 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1231 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1233 if (open_stateid
!= NULL
)
1234 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1235 write_sequnlock(&state
->seqlock
);
1236 spin_lock(&state
->owner
->so_lock
);
1237 update_open_stateflags(state
, fmode
);
1238 spin_unlock(&state
->owner
->so_lock
);
1241 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1243 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1244 struct nfs_delegation
*deleg_cur
;
1247 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1250 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1251 if (deleg_cur
== NULL
)
1254 spin_lock(&deleg_cur
->lock
);
1255 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1256 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1257 (deleg_cur
->type
& fmode
) != fmode
)
1258 goto no_delegation_unlock
;
1260 if (delegation
== NULL
)
1261 delegation
= &deleg_cur
->stateid
;
1262 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1263 goto no_delegation_unlock
;
1265 nfs_mark_delegation_referenced(deleg_cur
);
1266 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1268 no_delegation_unlock
:
1269 spin_unlock(&deleg_cur
->lock
);
1273 if (!ret
&& open_stateid
!= NULL
) {
1274 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1277 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1278 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1284 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1286 struct nfs_delegation
*delegation
;
1289 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1290 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1295 nfs4_inode_return_delegation(inode
);
1298 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1300 struct nfs4_state
*state
= opendata
->state
;
1301 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1302 struct nfs_delegation
*delegation
;
1303 int open_mode
= opendata
->o_arg
.open_flags
;
1304 fmode_t fmode
= opendata
->o_arg
.fmode
;
1305 nfs4_stateid stateid
;
1309 if (can_open_cached(state
, fmode
, open_mode
)) {
1310 spin_lock(&state
->owner
->so_lock
);
1311 if (can_open_cached(state
, fmode
, open_mode
)) {
1312 update_open_stateflags(state
, fmode
);
1313 spin_unlock(&state
->owner
->so_lock
);
1314 goto out_return_state
;
1316 spin_unlock(&state
->owner
->so_lock
);
1319 delegation
= rcu_dereference(nfsi
->delegation
);
1320 if (!can_open_delegated(delegation
, fmode
)) {
1324 /* Save the delegation */
1325 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1327 nfs_release_seqid(opendata
->o_arg
.seqid
);
1328 if (!opendata
->is_recover
) {
1329 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1335 /* Try to update the stateid using the delegation */
1336 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1337 goto out_return_state
;
1340 return ERR_PTR(ret
);
1342 atomic_inc(&state
->count
);
1347 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1349 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1350 struct nfs_delegation
*delegation
;
1351 int delegation_flags
= 0;
1354 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1356 delegation_flags
= delegation
->flags
;
1358 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1359 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1360 "returning a delegation for "
1361 "OPEN(CLAIM_DELEGATE_CUR)\n",
1363 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1364 nfs_inode_set_delegation(state
->inode
,
1365 data
->owner
->so_cred
,
1368 nfs_inode_reclaim_delegation(state
->inode
,
1369 data
->owner
->so_cred
,
1374 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1375 * and update the nfs4_state.
1377 static struct nfs4_state
*
1378 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1380 struct inode
*inode
= data
->state
->inode
;
1381 struct nfs4_state
*state
= data
->state
;
1384 if (!data
->rpc_done
) {
1385 if (data
->rpc_status
) {
1386 ret
= data
->rpc_status
;
1389 /* cached opens have already been processed */
1393 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1397 if (data
->o_res
.delegation_type
!= 0)
1398 nfs4_opendata_check_deleg(data
, state
);
1400 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1402 atomic_inc(&state
->count
);
1406 return ERR_PTR(ret
);
1410 static struct nfs4_state
*
1411 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1413 struct inode
*inode
;
1414 struct nfs4_state
*state
= NULL
;
1417 if (!data
->rpc_done
) {
1418 state
= nfs4_try_open_cached(data
);
1423 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1425 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1426 ret
= PTR_ERR(inode
);
1430 state
= nfs4_get_open_state(inode
, data
->owner
);
1433 if (data
->o_res
.delegation_type
!= 0)
1434 nfs4_opendata_check_deleg(data
, state
);
1435 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1439 nfs_release_seqid(data
->o_arg
.seqid
);
1444 return ERR_PTR(ret
);
1447 static struct nfs4_state
*
1448 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1450 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1451 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1452 return _nfs4_opendata_to_nfs4_state(data
);
1455 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1457 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1458 struct nfs_open_context
*ctx
;
1460 spin_lock(&state
->inode
->i_lock
);
1461 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1462 if (ctx
->state
!= state
)
1464 get_nfs_open_context(ctx
);
1465 spin_unlock(&state
->inode
->i_lock
);
1468 spin_unlock(&state
->inode
->i_lock
);
1469 return ERR_PTR(-ENOENT
);
1472 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1473 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1475 struct nfs4_opendata
*opendata
;
1477 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1478 NULL
, NULL
, claim
, GFP_NOFS
);
1479 if (opendata
== NULL
)
1480 return ERR_PTR(-ENOMEM
);
1481 opendata
->state
= state
;
1482 atomic_inc(&state
->count
);
1486 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1488 struct nfs4_state
*newstate
;
1491 opendata
->o_arg
.open_flags
= 0;
1492 opendata
->o_arg
.fmode
= fmode
;
1493 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1494 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1495 nfs4_init_opendata_res(opendata
);
1496 ret
= _nfs4_recover_proc_open(opendata
);
1499 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1500 if (IS_ERR(newstate
))
1501 return PTR_ERR(newstate
);
1502 nfs4_close_state(newstate
, fmode
);
1507 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1509 struct nfs4_state
*newstate
;
1512 /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */
1513 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1514 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1515 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1516 /* memory barrier prior to reading state->n_* */
1517 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1518 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1520 if (state
->n_rdwr
!= 0) {
1521 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1524 if (newstate
!= state
)
1527 if (state
->n_wronly
!= 0) {
1528 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1531 if (newstate
!= state
)
1534 if (state
->n_rdonly
!= 0) {
1535 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1538 if (newstate
!= state
)
1542 * We may have performed cached opens for all three recoveries.
1543 * Check if we need to update the current stateid.
1545 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1546 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1547 write_seqlock(&state
->seqlock
);
1548 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1549 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1550 write_sequnlock(&state
->seqlock
);
1557 * reclaim state on the server after a reboot.
1559 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1561 struct nfs_delegation
*delegation
;
1562 struct nfs4_opendata
*opendata
;
1563 fmode_t delegation_type
= 0;
1566 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1567 NFS4_OPEN_CLAIM_PREVIOUS
);
1568 if (IS_ERR(opendata
))
1569 return PTR_ERR(opendata
);
1571 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1572 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1573 delegation_type
= delegation
->type
;
1575 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1576 status
= nfs4_open_recover(opendata
, state
);
1577 nfs4_opendata_put(opendata
);
1581 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1583 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1584 struct nfs4_exception exception
= { };
1587 err
= _nfs4_do_open_reclaim(ctx
, state
);
1588 trace_nfs4_open_reclaim(ctx
, 0, err
);
1589 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1591 if (err
!= -NFS4ERR_DELAY
)
1593 nfs4_handle_exception(server
, err
, &exception
);
1594 } while (exception
.retry
);
1598 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1600 struct nfs_open_context
*ctx
;
1603 ctx
= nfs4_state_find_open_context(state
);
1606 ret
= nfs4_do_open_reclaim(ctx
, state
);
1607 put_nfs_open_context(ctx
);
1611 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1615 printk(KERN_ERR
"NFS: %s: unhandled error "
1616 "%d.\n", __func__
, err
);
1621 case -NFS4ERR_BADSESSION
:
1622 case -NFS4ERR_BADSLOT
:
1623 case -NFS4ERR_BAD_HIGH_SLOT
:
1624 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1625 case -NFS4ERR_DEADSESSION
:
1626 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1627 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1629 case -NFS4ERR_STALE_CLIENTID
:
1630 case -NFS4ERR_STALE_STATEID
:
1631 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1632 case -NFS4ERR_EXPIRED
:
1633 /* Don't recall a delegation if it was lost */
1634 nfs4_schedule_lease_recovery(server
->nfs_client
);
1636 case -NFS4ERR_MOVED
:
1637 nfs4_schedule_migration_recovery(server
);
1639 case -NFS4ERR_LEASE_MOVED
:
1640 nfs4_schedule_lease_moved_recovery(server
->nfs_client
);
1642 case -NFS4ERR_DELEG_REVOKED
:
1643 case -NFS4ERR_ADMIN_REVOKED
:
1644 case -NFS4ERR_BAD_STATEID
:
1645 case -NFS4ERR_OPENMODE
:
1646 nfs_inode_find_state_and_recover(state
->inode
,
1648 nfs4_schedule_stateid_recovery(server
, state
);
1650 case -NFS4ERR_DELAY
:
1651 case -NFS4ERR_GRACE
:
1652 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1656 case -NFS4ERR_DENIED
:
1657 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1663 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1665 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1666 struct nfs4_opendata
*opendata
;
1669 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1670 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1671 if (IS_ERR(opendata
))
1672 return PTR_ERR(opendata
);
1673 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1674 err
= nfs4_open_recover(opendata
, state
);
1675 nfs4_opendata_put(opendata
);
1676 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1679 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
1681 struct nfs4_opendata
*data
= calldata
;
1683 nfs40_setup_sequence(data
->o_arg
.server
, &data
->c_arg
.seq_args
,
1684 &data
->c_res
.seq_res
, task
);
1687 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1689 struct nfs4_opendata
*data
= calldata
;
1691 nfs40_sequence_done(task
, &data
->c_res
.seq_res
);
1693 data
->rpc_status
= task
->tk_status
;
1694 if (data
->rpc_status
== 0) {
1695 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1696 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1697 renew_lease(data
->o_res
.server
, data
->timestamp
);
1702 static void nfs4_open_confirm_release(void *calldata
)
1704 struct nfs4_opendata
*data
= calldata
;
1705 struct nfs4_state
*state
= NULL
;
1707 /* If this request hasn't been cancelled, do nothing */
1708 if (data
->cancelled
== 0)
1710 /* In case of error, no cleanup! */
1711 if (!data
->rpc_done
)
1713 state
= nfs4_opendata_to_nfs4_state(data
);
1715 nfs4_close_state(state
, data
->o_arg
.fmode
);
1717 nfs4_opendata_put(data
);
1720 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1721 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
1722 .rpc_call_done
= nfs4_open_confirm_done
,
1723 .rpc_release
= nfs4_open_confirm_release
,
1727 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1729 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1731 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1732 struct rpc_task
*task
;
1733 struct rpc_message msg
= {
1734 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1735 .rpc_argp
= &data
->c_arg
,
1736 .rpc_resp
= &data
->c_res
,
1737 .rpc_cred
= data
->owner
->so_cred
,
1739 struct rpc_task_setup task_setup_data
= {
1740 .rpc_client
= server
->client
,
1741 .rpc_message
= &msg
,
1742 .callback_ops
= &nfs4_open_confirm_ops
,
1743 .callback_data
= data
,
1744 .workqueue
= nfsiod_workqueue
,
1745 .flags
= RPC_TASK_ASYNC
,
1749 nfs4_init_sequence(&data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, 1);
1750 kref_get(&data
->kref
);
1752 data
->rpc_status
= 0;
1753 data
->timestamp
= jiffies
;
1754 task
= rpc_run_task(&task_setup_data
);
1756 return PTR_ERR(task
);
1757 status
= nfs4_wait_for_completion_rpc_task(task
);
1759 data
->cancelled
= 1;
1762 status
= data
->rpc_status
;
1767 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1769 struct nfs4_opendata
*data
= calldata
;
1770 struct nfs4_state_owner
*sp
= data
->owner
;
1771 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1773 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1776 * Check if we still need to send an OPEN call, or if we can use
1777 * a delegation instead.
1779 if (data
->state
!= NULL
) {
1780 struct nfs_delegation
*delegation
;
1782 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1785 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1786 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1787 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1788 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1789 goto unlock_no_action
;
1792 /* Update client id. */
1793 data
->o_arg
.clientid
= clp
->cl_clientid
;
1794 switch (data
->o_arg
.claim
) {
1795 case NFS4_OPEN_CLAIM_PREVIOUS
:
1796 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1797 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1798 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1799 case NFS4_OPEN_CLAIM_FH
:
1800 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1801 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1803 data
->timestamp
= jiffies
;
1804 if (nfs4_setup_sequence(data
->o_arg
.server
,
1805 &data
->o_arg
.seq_args
,
1806 &data
->o_res
.seq_res
,
1808 nfs_release_seqid(data
->o_arg
.seqid
);
1810 /* Set the create mode (note dependency on the session type) */
1811 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1812 if (data
->o_arg
.open_flags
& O_EXCL
) {
1813 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1814 if (nfs4_has_persistent_session(clp
))
1815 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1816 else if (clp
->cl_mvops
->minor_version
> 0)
1817 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1823 task
->tk_action
= NULL
;
1825 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1828 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1830 struct nfs4_opendata
*data
= calldata
;
1832 data
->rpc_status
= task
->tk_status
;
1834 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1837 if (task
->tk_status
== 0) {
1838 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1839 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1843 data
->rpc_status
= -ELOOP
;
1846 data
->rpc_status
= -EISDIR
;
1849 data
->rpc_status
= -ENOTDIR
;
1852 renew_lease(data
->o_res
.server
, data
->timestamp
);
1853 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1854 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1859 static void nfs4_open_release(void *calldata
)
1861 struct nfs4_opendata
*data
= calldata
;
1862 struct nfs4_state
*state
= NULL
;
1864 /* If this request hasn't been cancelled, do nothing */
1865 if (data
->cancelled
== 0)
1867 /* In case of error, no cleanup! */
1868 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1870 /* In case we need an open_confirm, no cleanup! */
1871 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1873 state
= nfs4_opendata_to_nfs4_state(data
);
1875 nfs4_close_state(state
, data
->o_arg
.fmode
);
1877 nfs4_opendata_put(data
);
1880 static const struct rpc_call_ops nfs4_open_ops
= {
1881 .rpc_call_prepare
= nfs4_open_prepare
,
1882 .rpc_call_done
= nfs4_open_done
,
1883 .rpc_release
= nfs4_open_release
,
1886 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1888 struct inode
*dir
= data
->dir
->d_inode
;
1889 struct nfs_server
*server
= NFS_SERVER(dir
);
1890 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1891 struct nfs_openres
*o_res
= &data
->o_res
;
1892 struct rpc_task
*task
;
1893 struct rpc_message msg
= {
1894 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1897 .rpc_cred
= data
->owner
->so_cred
,
1899 struct rpc_task_setup task_setup_data
= {
1900 .rpc_client
= server
->client
,
1901 .rpc_message
= &msg
,
1902 .callback_ops
= &nfs4_open_ops
,
1903 .callback_data
= data
,
1904 .workqueue
= nfsiod_workqueue
,
1905 .flags
= RPC_TASK_ASYNC
,
1909 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1910 kref_get(&data
->kref
);
1912 data
->rpc_status
= 0;
1913 data
->cancelled
= 0;
1914 data
->is_recover
= 0;
1916 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1917 data
->is_recover
= 1;
1919 task
= rpc_run_task(&task_setup_data
);
1921 return PTR_ERR(task
);
1922 status
= nfs4_wait_for_completion_rpc_task(task
);
1924 data
->cancelled
= 1;
1927 status
= data
->rpc_status
;
1933 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1935 struct inode
*dir
= data
->dir
->d_inode
;
1936 struct nfs_openres
*o_res
= &data
->o_res
;
1939 status
= nfs4_run_open_task(data
, 1);
1940 if (status
!= 0 || !data
->rpc_done
)
1943 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1945 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1946 status
= _nfs4_proc_open_confirm(data
);
1955 * Additional permission checks in order to distinguish between an
1956 * open for read, and an open for execute. This works around the
1957 * fact that NFSv4 OPEN treats read and execute permissions as being
1959 * Note that in the non-execute case, we want to turn off permission
1960 * checking if we just created a new file (POSIX open() semantics).
1962 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1963 struct nfs4_opendata
*opendata
,
1964 struct nfs4_state
*state
, fmode_t fmode
,
1967 struct nfs_access_entry cache
;
1970 /* access call failed or for some reason the server doesn't
1971 * support any access modes -- defer access call until later */
1972 if (opendata
->o_res
.access_supported
== 0)
1977 * Use openflags to check for exec, because fmode won't
1978 * always have FMODE_EXEC set when file open for exec.
1980 if (openflags
& __FMODE_EXEC
) {
1981 /* ONLY check for exec rights */
1983 } else if ((fmode
& FMODE_READ
) && !opendata
->file_created
)
1987 cache
.jiffies
= jiffies
;
1988 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1989 nfs_access_add_cache(state
->inode
, &cache
);
1991 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
1994 /* even though OPEN succeeded, access is denied. Close the file */
1995 nfs4_close_state(state
, fmode
);
2000 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
2002 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
2004 struct inode
*dir
= data
->dir
->d_inode
;
2005 struct nfs_server
*server
= NFS_SERVER(dir
);
2006 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2007 struct nfs_openres
*o_res
= &data
->o_res
;
2010 status
= nfs4_run_open_task(data
, 0);
2011 if (!data
->rpc_done
)
2014 if (status
== -NFS4ERR_BADNAME
&&
2015 !(o_arg
->open_flags
& O_CREAT
))
2020 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
2022 if (o_arg
->open_flags
& O_CREAT
) {
2023 update_changeattr(dir
, &o_res
->cinfo
);
2024 if (o_arg
->open_flags
& O_EXCL
)
2025 data
->file_created
= 1;
2026 else if (o_res
->cinfo
.before
!= o_res
->cinfo
.after
)
2027 data
->file_created
= 1;
2029 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
2030 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
2031 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
2032 status
= _nfs4_proc_open_confirm(data
);
2036 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
2037 nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
2041 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
2043 return nfs4_client_recover_expired_lease(server
->nfs_client
);
2048 * reclaim state on the server after a network partition.
2049 * Assumes caller holds the appropriate lock
2051 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2053 struct nfs4_opendata
*opendata
;
2056 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2057 NFS4_OPEN_CLAIM_FH
);
2058 if (IS_ERR(opendata
))
2059 return PTR_ERR(opendata
);
2060 ret
= nfs4_open_recover(opendata
, state
);
2062 d_drop(ctx
->dentry
);
2063 nfs4_opendata_put(opendata
);
2067 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2069 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2070 struct nfs4_exception exception
= { };
2074 err
= _nfs4_open_expired(ctx
, state
);
2075 trace_nfs4_open_expired(ctx
, 0, err
);
2076 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2081 case -NFS4ERR_GRACE
:
2082 case -NFS4ERR_DELAY
:
2083 nfs4_handle_exception(server
, err
, &exception
);
2086 } while (exception
.retry
);
2091 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2093 struct nfs_open_context
*ctx
;
2096 ctx
= nfs4_state_find_open_context(state
);
2099 ret
= nfs4_do_open_expired(ctx
, state
);
2100 put_nfs_open_context(ctx
);
2104 #if defined(CONFIG_NFS_V4_1)
2105 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
2107 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2108 nfs4_stateid
*stateid
= &state
->stateid
;
2109 struct nfs_delegation
*delegation
;
2110 struct rpc_cred
*cred
= NULL
;
2111 int status
= -NFS4ERR_BAD_STATEID
;
2113 /* If a state reset has been done, test_stateid is unneeded */
2114 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
2117 /* Get the delegation credential for use by test/free_stateid */
2119 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2120 if (delegation
!= NULL
&&
2121 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
2122 cred
= get_rpccred(delegation
->cred
);
2124 status
= nfs41_test_stateid(server
, stateid
, cred
);
2125 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
2129 if (status
!= NFS_OK
) {
2130 /* Free the stateid unless the server explicitly
2131 * informs us the stateid is unrecognized. */
2132 if (status
!= -NFS4ERR_BAD_STATEID
)
2133 nfs41_free_stateid(server
, stateid
, cred
);
2134 nfs_remove_bad_delegation(state
->inode
);
2136 write_seqlock(&state
->seqlock
);
2137 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
2138 write_sequnlock(&state
->seqlock
);
2139 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2147 * nfs41_check_open_stateid - possibly free an open stateid
2149 * @state: NFSv4 state for an inode
2151 * Returns NFS_OK if recovery for this stateid is now finished.
2152 * Otherwise a negative NFS4ERR value is returned.
2154 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2156 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2157 nfs4_stateid
*stateid
= &state
->open_stateid
;
2158 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2161 /* If a state reset has been done, test_stateid is unneeded */
2162 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
2163 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
2164 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
2165 return -NFS4ERR_BAD_STATEID
;
2167 status
= nfs41_test_stateid(server
, stateid
, cred
);
2168 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2169 if (status
!= NFS_OK
) {
2170 /* Free the stateid unless the server explicitly
2171 * informs us the stateid is unrecognized. */
2172 if (status
!= -NFS4ERR_BAD_STATEID
)
2173 nfs41_free_stateid(server
, stateid
, cred
);
2175 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2176 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2177 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2178 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2183 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2187 nfs41_clear_delegation_stateid(state
);
2188 status
= nfs41_check_open_stateid(state
);
2189 if (status
!= NFS_OK
)
2190 status
= nfs4_open_expired(sp
, state
);
2196 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2197 * fields corresponding to attributes that were used to store the verifier.
2198 * Make sure we clobber those fields in the later setattr call
2200 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2202 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2203 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2204 sattr
->ia_valid
|= ATTR_ATIME
;
2206 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2207 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2208 sattr
->ia_valid
|= ATTR_MTIME
;
2211 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2214 struct nfs_open_context
*ctx
)
2216 struct nfs4_state_owner
*sp
= opendata
->owner
;
2217 struct nfs_server
*server
= sp
->so_server
;
2218 struct dentry
*dentry
;
2219 struct nfs4_state
*state
;
2223 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2225 ret
= _nfs4_proc_open(opendata
);
2227 if (ret
== -ENOENT
) {
2228 d_drop(opendata
->dentry
);
2229 d_add(opendata
->dentry
, NULL
);
2230 nfs_set_verifier(opendata
->dentry
,
2231 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2236 state
= nfs4_opendata_to_nfs4_state(opendata
);
2237 ret
= PTR_ERR(state
);
2240 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2241 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2243 dentry
= opendata
->dentry
;
2244 if (dentry
->d_inode
== NULL
) {
2245 /* FIXME: Is this d_drop() ever needed? */
2247 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2248 if (dentry
== NULL
) {
2249 dentry
= opendata
->dentry
;
2250 } else if (dentry
!= ctx
->dentry
) {
2252 ctx
->dentry
= dget(dentry
);
2254 nfs_set_verifier(dentry
,
2255 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2258 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2263 if (dentry
->d_inode
== state
->inode
) {
2264 nfs_inode_attach_open_context(ctx
);
2265 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2266 nfs4_schedule_stateid_recovery(server
, state
);
2273 * Returns a referenced nfs4_state
2275 static int _nfs4_do_open(struct inode
*dir
,
2276 struct nfs_open_context
*ctx
,
2278 struct iattr
*sattr
,
2279 struct nfs4_label
*label
,
2282 struct nfs4_state_owner
*sp
;
2283 struct nfs4_state
*state
= NULL
;
2284 struct nfs_server
*server
= NFS_SERVER(dir
);
2285 struct nfs4_opendata
*opendata
;
2286 struct dentry
*dentry
= ctx
->dentry
;
2287 struct rpc_cred
*cred
= ctx
->cred
;
2288 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2289 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2290 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2291 struct nfs4_label
*olabel
= NULL
;
2294 /* Protect against reboot recovery conflicts */
2296 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2298 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2301 status
= nfs4_recover_expired_lease(server
);
2303 goto err_put_state_owner
;
2304 if (dentry
->d_inode
!= NULL
)
2305 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2307 if (dentry
->d_inode
)
2308 claim
= NFS4_OPEN_CLAIM_FH
;
2309 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2310 label
, claim
, GFP_KERNEL
);
2311 if (opendata
== NULL
)
2312 goto err_put_state_owner
;
2315 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2316 if (IS_ERR(olabel
)) {
2317 status
= PTR_ERR(olabel
);
2318 goto err_opendata_put
;
2322 if (server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2323 if (!opendata
->f_attr
.mdsthreshold
) {
2324 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2325 if (!opendata
->f_attr
.mdsthreshold
)
2326 goto err_free_label
;
2328 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2330 if (dentry
->d_inode
!= NULL
)
2331 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2333 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2335 goto err_free_label
;
2338 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2339 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2340 nfs4_exclusive_attrset(opendata
, sattr
);
2342 nfs_fattr_init(opendata
->o_res
.f_attr
);
2343 status
= nfs4_do_setattr(state
->inode
, cred
,
2344 opendata
->o_res
.f_attr
, sattr
,
2345 state
, label
, olabel
);
2347 nfs_setattr_update_inode(state
->inode
, sattr
);
2348 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2349 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2352 if (opendata
->file_created
)
2353 *opened
|= FILE_CREATED
;
2355 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
)) {
2356 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2357 opendata
->f_attr
.mdsthreshold
= NULL
;
2360 nfs4_label_free(olabel
);
2362 nfs4_opendata_put(opendata
);
2363 nfs4_put_state_owner(sp
);
2366 nfs4_label_free(olabel
);
2368 nfs4_opendata_put(opendata
);
2369 err_put_state_owner
:
2370 nfs4_put_state_owner(sp
);
2376 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2377 struct nfs_open_context
*ctx
,
2379 struct iattr
*sattr
,
2380 struct nfs4_label
*label
,
2383 struct nfs_server
*server
= NFS_SERVER(dir
);
2384 struct nfs4_exception exception
= { };
2385 struct nfs4_state
*res
;
2389 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
, opened
);
2391 trace_nfs4_open_file(ctx
, flags
, status
);
2394 /* NOTE: BAD_SEQID means the server and client disagree about the
2395 * book-keeping w.r.t. state-changing operations
2396 * (OPEN/CLOSE/LOCK/LOCKU...)
2397 * It is actually a sign of a bug on the client or on the server.
2399 * If we receive a BAD_SEQID error in the particular case of
2400 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2401 * have unhashed the old state_owner for us, and that we can
2402 * therefore safely retry using a new one. We should still warn
2403 * the user though...
2405 if (status
== -NFS4ERR_BAD_SEQID
) {
2406 pr_warn_ratelimited("NFS: v4 server %s "
2407 " returned a bad sequence-id error!\n",
2408 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2409 exception
.retry
= 1;
2413 * BAD_STATEID on OPEN means that the server cancelled our
2414 * state before it received the OPEN_CONFIRM.
2415 * Recover by retrying the request as per the discussion
2416 * on Page 181 of RFC3530.
2418 if (status
== -NFS4ERR_BAD_STATEID
) {
2419 exception
.retry
= 1;
2422 if (status
== -EAGAIN
) {
2423 /* We must have found a delegation */
2424 exception
.retry
= 1;
2427 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2429 res
= ERR_PTR(nfs4_handle_exception(server
,
2430 status
, &exception
));
2431 } while (exception
.retry
);
2435 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2436 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2437 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2438 struct nfs4_label
*olabel
)
2440 struct nfs_server
*server
= NFS_SERVER(inode
);
2441 struct nfs_setattrargs arg
= {
2442 .fh
= NFS_FH(inode
),
2445 .bitmask
= server
->attr_bitmask
,
2448 struct nfs_setattrres res
= {
2453 struct rpc_message msg
= {
2454 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2459 unsigned long timestamp
= jiffies
;
2464 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2466 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2468 nfs_fattr_init(fattr
);
2470 /* Servers should only apply open mode checks for file size changes */
2471 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2472 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2474 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2475 /* Use that stateid */
2476 } else if (truncate
&& state
!= NULL
) {
2477 struct nfs_lockowner lockowner
= {
2478 .l_owner
= current
->files
,
2479 .l_pid
= current
->tgid
,
2481 if (!nfs4_valid_open_stateid(state
))
2483 if (nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2484 &lockowner
) == -EIO
)
2487 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2489 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2490 if (status
== 0 && state
!= NULL
)
2491 renew_lease(server
, timestamp
);
2495 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2496 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2497 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2498 struct nfs4_label
*olabel
)
2500 struct nfs_server
*server
= NFS_SERVER(inode
);
2501 struct nfs4_exception exception
= {
2507 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2508 trace_nfs4_setattr(inode
, err
);
2510 case -NFS4ERR_OPENMODE
:
2511 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2512 pr_warn_once("NFSv4: server %s is incorrectly "
2513 "applying open mode checks to "
2514 "a SETATTR that is not "
2515 "changing file size.\n",
2516 server
->nfs_client
->cl_hostname
);
2518 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2520 if (sattr
->ia_valid
& ATTR_OPEN
)
2525 err
= nfs4_handle_exception(server
, err
, &exception
);
2526 } while (exception
.retry
);
2531 struct nfs4_closedata
{
2532 struct inode
*inode
;
2533 struct nfs4_state
*state
;
2534 struct nfs_closeargs arg
;
2535 struct nfs_closeres res
;
2536 struct nfs_fattr fattr
;
2537 unsigned long timestamp
;
2542 static void nfs4_free_closedata(void *data
)
2544 struct nfs4_closedata
*calldata
= data
;
2545 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2546 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2549 pnfs_roc_release(calldata
->state
->inode
);
2550 nfs4_put_open_state(calldata
->state
);
2551 nfs_free_seqid(calldata
->arg
.seqid
);
2552 nfs4_put_state_owner(sp
);
2553 nfs_sb_deactive(sb
);
2557 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2559 struct nfs4_closedata
*calldata
= data
;
2560 struct nfs4_state
*state
= calldata
->state
;
2561 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2562 nfs4_stateid
*res_stateid
= NULL
;
2564 dprintk("%s: begin!\n", __func__
);
2565 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2567 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2568 /* hmm. we are done with the inode, and in the process of freeing
2569 * the state_owner. we keep this around to process errors
2571 switch (task
->tk_status
) {
2573 res_stateid
= &calldata
->res
.stateid
;
2574 if (calldata
->arg
.fmode
== 0 && calldata
->roc
)
2575 pnfs_roc_set_barrier(state
->inode
,
2576 calldata
->roc_barrier
);
2577 renew_lease(server
, calldata
->timestamp
);
2579 case -NFS4ERR_ADMIN_REVOKED
:
2580 case -NFS4ERR_STALE_STATEID
:
2581 case -NFS4ERR_OLD_STATEID
:
2582 case -NFS4ERR_BAD_STATEID
:
2583 case -NFS4ERR_EXPIRED
:
2584 if (calldata
->arg
.fmode
== 0)
2587 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
) {
2588 rpc_restart_call_prepare(task
);
2592 nfs_clear_open_stateid(state
, res_stateid
, calldata
->arg
.fmode
);
2594 nfs_release_seqid(calldata
->arg
.seqid
);
2595 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2596 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2599 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2601 struct nfs4_closedata
*calldata
= data
;
2602 struct nfs4_state
*state
= calldata
->state
;
2603 struct inode
*inode
= calldata
->inode
;
2604 bool is_rdonly
, is_wronly
, is_rdwr
;
2607 dprintk("%s: begin!\n", __func__
);
2608 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2611 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2612 spin_lock(&state
->owner
->so_lock
);
2613 is_rdwr
= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2614 is_rdonly
= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2615 is_wronly
= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2616 /* Calculate the current open share mode */
2617 calldata
->arg
.fmode
= 0;
2618 if (is_rdonly
|| is_rdwr
)
2619 calldata
->arg
.fmode
|= FMODE_READ
;
2620 if (is_wronly
|| is_rdwr
)
2621 calldata
->arg
.fmode
|= FMODE_WRITE
;
2622 /* Calculate the change in open mode */
2623 if (state
->n_rdwr
== 0) {
2624 if (state
->n_rdonly
== 0) {
2625 call_close
|= is_rdonly
|| is_rdwr
;
2626 calldata
->arg
.fmode
&= ~FMODE_READ
;
2628 if (state
->n_wronly
== 0) {
2629 call_close
|= is_wronly
|| is_rdwr
;
2630 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2633 if (!nfs4_valid_open_stateid(state
))
2635 spin_unlock(&state
->owner
->so_lock
);
2638 /* Note: exit _without_ calling nfs4_close_done */
2642 if (calldata
->arg
.fmode
== 0) {
2643 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2644 if (calldata
->roc
&&
2645 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2646 nfs_release_seqid(calldata
->arg
.seqid
);
2651 nfs_fattr_init(calldata
->res
.fattr
);
2652 calldata
->timestamp
= jiffies
;
2653 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2654 &calldata
->arg
.seq_args
,
2655 &calldata
->res
.seq_res
,
2657 nfs_release_seqid(calldata
->arg
.seqid
);
2658 dprintk("%s: done!\n", __func__
);
2661 task
->tk_action
= NULL
;
2663 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2666 static const struct rpc_call_ops nfs4_close_ops
= {
2667 .rpc_call_prepare
= nfs4_close_prepare
,
2668 .rpc_call_done
= nfs4_close_done
,
2669 .rpc_release
= nfs4_free_closedata
,
2672 static bool nfs4_state_has_opener(struct nfs4_state
*state
)
2674 /* first check existing openers */
2675 if (test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0 &&
2676 state
->n_rdonly
!= 0)
2679 if (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0 &&
2680 state
->n_wronly
!= 0)
2683 if (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0 &&
2690 static bool nfs4_roc(struct inode
*inode
)
2692 struct nfs_inode
*nfsi
= NFS_I(inode
);
2693 struct nfs_open_context
*ctx
;
2694 struct nfs4_state
*state
;
2696 spin_lock(&inode
->i_lock
);
2697 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
2701 if (nfs4_state_has_opener(state
)) {
2702 spin_unlock(&inode
->i_lock
);
2706 spin_unlock(&inode
->i_lock
);
2708 if (nfs4_check_delegation(inode
, FMODE_READ
))
2711 return pnfs_roc(inode
);
2715 * It is possible for data to be read/written from a mem-mapped file
2716 * after the sys_close call (which hits the vfs layer as a flush).
2717 * This means that we can't safely call nfsv4 close on a file until
2718 * the inode is cleared. This in turn means that we are not good
2719 * NFSv4 citizens - we do not indicate to the server to update the file's
2720 * share state even when we are done with one of the three share
2721 * stateid's in the inode.
2723 * NOTE: Caller must be holding the sp->so_owner semaphore!
2725 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2727 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2728 struct nfs4_closedata
*calldata
;
2729 struct nfs4_state_owner
*sp
= state
->owner
;
2730 struct rpc_task
*task
;
2731 struct rpc_message msg
= {
2732 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2733 .rpc_cred
= state
->owner
->so_cred
,
2735 struct rpc_task_setup task_setup_data
= {
2736 .rpc_client
= server
->client
,
2737 .rpc_message
= &msg
,
2738 .callback_ops
= &nfs4_close_ops
,
2739 .workqueue
= nfsiod_workqueue
,
2740 .flags
= RPC_TASK_ASYNC
,
2742 int status
= -ENOMEM
;
2744 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_CLEANUP
,
2745 &task_setup_data
.rpc_client
, &msg
);
2747 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2748 if (calldata
== NULL
)
2750 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2751 calldata
->inode
= state
->inode
;
2752 calldata
->state
= state
;
2753 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2754 calldata
->arg
.stateid
= &state
->open_stateid
;
2755 /* Serialization for the sequence id */
2756 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2757 if (calldata
->arg
.seqid
== NULL
)
2758 goto out_free_calldata
;
2759 calldata
->arg
.fmode
= 0;
2760 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2761 calldata
->res
.fattr
= &calldata
->fattr
;
2762 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2763 calldata
->res
.server
= server
;
2764 calldata
->roc
= nfs4_roc(state
->inode
);
2765 nfs_sb_active(calldata
->inode
->i_sb
);
2767 msg
.rpc_argp
= &calldata
->arg
;
2768 msg
.rpc_resp
= &calldata
->res
;
2769 task_setup_data
.callback_data
= calldata
;
2770 task
= rpc_run_task(&task_setup_data
);
2772 return PTR_ERR(task
);
2775 status
= rpc_wait_for_completion_task(task
);
2781 nfs4_put_open_state(state
);
2782 nfs4_put_state_owner(sp
);
2786 static struct inode
*
2787 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
,
2788 int open_flags
, struct iattr
*attr
, int *opened
)
2790 struct nfs4_state
*state
;
2791 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2793 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2795 /* Protect against concurrent sillydeletes */
2796 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
, opened
);
2798 nfs4_label_release_security(label
);
2801 return ERR_CAST(state
);
2802 return state
->inode
;
2805 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2807 if (ctx
->state
== NULL
)
2810 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2812 nfs4_close_state(ctx
->state
, ctx
->mode
);
2815 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
2816 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
2817 #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL)
2819 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2821 struct nfs4_server_caps_arg args
= {
2824 struct nfs4_server_caps_res res
= {};
2825 struct rpc_message msg
= {
2826 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2832 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2834 /* Sanity check the server answers */
2835 switch (server
->nfs_client
->cl_minorversion
) {
2837 res
.attr_bitmask
[1] &= FATTR4_WORD1_NFS40_MASK
;
2838 res
.attr_bitmask
[2] = 0;
2841 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS41_MASK
;
2844 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS42_MASK
;
2846 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2847 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2848 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2849 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2850 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2851 NFS_CAP_CTIME
|NFS_CAP_MTIME
|
2852 NFS_CAP_SECURITY_LABEL
);
2853 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
&&
2854 res
.acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
2855 server
->caps
|= NFS_CAP_ACLS
;
2856 if (res
.has_links
!= 0)
2857 server
->caps
|= NFS_CAP_HARDLINKS
;
2858 if (res
.has_symlinks
!= 0)
2859 server
->caps
|= NFS_CAP_SYMLINKS
;
2860 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2861 server
->caps
|= NFS_CAP_FILEID
;
2862 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2863 server
->caps
|= NFS_CAP_MODE
;
2864 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2865 server
->caps
|= NFS_CAP_NLINK
;
2866 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2867 server
->caps
|= NFS_CAP_OWNER
;
2868 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2869 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2870 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2871 server
->caps
|= NFS_CAP_ATIME
;
2872 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2873 server
->caps
|= NFS_CAP_CTIME
;
2874 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2875 server
->caps
|= NFS_CAP_MTIME
;
2876 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2877 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2878 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2880 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2881 sizeof(server
->attr_bitmask
));
2882 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2884 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2885 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2886 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2887 server
->cache_consistency_bitmask
[2] = 0;
2888 server
->acl_bitmask
= res
.acl_bitmask
;
2889 server
->fh_expire_type
= res
.fh_expire_type
;
2895 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2897 struct nfs4_exception exception
= { };
2900 err
= nfs4_handle_exception(server
,
2901 _nfs4_server_capabilities(server
, fhandle
),
2903 } while (exception
.retry
);
2907 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2908 struct nfs_fsinfo
*info
)
2911 struct nfs4_lookup_root_arg args
= {
2914 struct nfs4_lookup_res res
= {
2916 .fattr
= info
->fattr
,
2919 struct rpc_message msg
= {
2920 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2925 bitmask
[0] = nfs4_fattr_bitmap
[0];
2926 bitmask
[1] = nfs4_fattr_bitmap
[1];
2928 * Process the label in the upcoming getfattr
2930 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2932 nfs_fattr_init(info
->fattr
);
2933 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2936 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2937 struct nfs_fsinfo
*info
)
2939 struct nfs4_exception exception
= { };
2942 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2943 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2946 case -NFS4ERR_WRONGSEC
:
2949 err
= nfs4_handle_exception(server
, err
, &exception
);
2951 } while (exception
.retry
);
2956 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2957 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2959 struct rpc_auth_create_args auth_args
= {
2960 .pseudoflavor
= flavor
,
2962 struct rpc_auth
*auth
;
2965 auth
= rpcauth_create(&auth_args
, server
->client
);
2970 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2976 * Retry pseudoroot lookup with various security flavors. We do this when:
2978 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2979 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2981 * Returns zero on success, or a negative NFS4ERR value, or a
2982 * negative errno value.
2984 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2985 struct nfs_fsinfo
*info
)
2987 /* Per 3530bis 15.33.5 */
2988 static const rpc_authflavor_t flav_array
[] = {
2992 RPC_AUTH_UNIX
, /* courtesy */
2995 int status
= -EPERM
;
2998 if (server
->auth_info
.flavor_len
> 0) {
2999 /* try each flavor specified by user */
3000 for (i
= 0; i
< server
->auth_info
.flavor_len
; i
++) {
3001 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3002 server
->auth_info
.flavors
[i
]);
3003 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3008 /* no flavors specified by user, try default list */
3009 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
3010 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3012 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3019 * -EACCESS could mean that the user doesn't have correct permissions
3020 * to access the mount. It could also mean that we tried to mount
3021 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
3022 * existing mount programs don't handle -EACCES very well so it should
3023 * be mapped to -EPERM instead.
3025 if (status
== -EACCES
)
3030 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
3031 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
3033 int mv
= server
->nfs_client
->cl_minorversion
;
3034 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
3038 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
3039 * @server: initialized nfs_server handle
3040 * @fhandle: we fill in the pseudo-fs root file handle
3041 * @info: we fill in an FSINFO struct
3042 * @auth_probe: probe the auth flavours
3044 * Returns zero on success, or a negative errno.
3046 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3047 struct nfs_fsinfo
*info
,
3052 switch (auth_probe
) {
3054 status
= nfs4_lookup_root(server
, fhandle
, info
);
3055 if (status
!= -NFS4ERR_WRONGSEC
)
3058 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
3062 status
= nfs4_server_capabilities(server
, fhandle
);
3064 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
3066 return nfs4_map_errors(status
);
3069 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
3070 struct nfs_fsinfo
*info
)
3073 struct nfs_fattr
*fattr
= info
->fattr
;
3074 struct nfs4_label
*label
= NULL
;
3076 error
= nfs4_server_capabilities(server
, mntfh
);
3078 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
3082 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3084 return PTR_ERR(label
);
3086 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
3088 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
3089 goto err_free_label
;
3092 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
3093 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
3094 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
3097 nfs4_label_free(label
);
3103 * Get locations and (maybe) other attributes of a referral.
3104 * Note that we'll actually follow the referral later when
3105 * we detect fsid mismatch in inode revalidation
3107 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
3108 const struct qstr
*name
, struct nfs_fattr
*fattr
,
3109 struct nfs_fh
*fhandle
)
3111 int status
= -ENOMEM
;
3112 struct page
*page
= NULL
;
3113 struct nfs4_fs_locations
*locations
= NULL
;
3115 page
= alloc_page(GFP_KERNEL
);
3118 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
3119 if (locations
== NULL
)
3122 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
3127 * If the fsid didn't change, this is a migration event, not a
3128 * referral. Cause us to drop into the exception handler, which
3129 * will kick off migration recovery.
3131 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
3132 dprintk("%s: server did not return a different fsid for"
3133 " a referral at %s\n", __func__
, name
->name
);
3134 status
= -NFS4ERR_MOVED
;
3137 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3138 nfs_fixup_referral_attributes(&locations
->fattr
);
3140 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3141 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
3142 memset(fhandle
, 0, sizeof(struct nfs_fh
));
3150 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3151 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3153 struct nfs4_getattr_arg args
= {
3155 .bitmask
= server
->attr_bitmask
,
3157 struct nfs4_getattr_res res
= {
3162 struct rpc_message msg
= {
3163 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
3168 args
.bitmask
= nfs4_bitmask(server
, label
);
3170 nfs_fattr_init(fattr
);
3171 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3174 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3175 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3177 struct nfs4_exception exception
= { };
3180 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
3181 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
3182 err
= nfs4_handle_exception(server
, err
,
3184 } while (exception
.retry
);
3189 * The file is not closed if it is opened due to the a request to change
3190 * the size of the file. The open call will not be needed once the
3191 * VFS layer lookup-intents are implemented.
3193 * Close is called when the inode is destroyed.
3194 * If we haven't opened the file for O_WRONLY, we
3195 * need to in the size_change case to obtain a stateid.
3198 * Because OPEN is always done by name in nfsv4, it is
3199 * possible that we opened a different file by the same
3200 * name. We can recognize this race condition, but we
3201 * can't do anything about it besides returning an error.
3203 * This will be fixed with VFS changes (lookup-intent).
3206 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
3207 struct iattr
*sattr
)
3209 struct inode
*inode
= dentry
->d_inode
;
3210 struct rpc_cred
*cred
= NULL
;
3211 struct nfs4_state
*state
= NULL
;
3212 struct nfs4_label
*label
= NULL
;
3215 if (pnfs_ld_layoutret_on_setattr(inode
))
3216 pnfs_commit_and_return_layout(inode
);
3218 nfs_fattr_init(fattr
);
3220 /* Deal with open(O_TRUNC) */
3221 if (sattr
->ia_valid
& ATTR_OPEN
)
3222 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
3224 /* Optimization: if the end result is no change, don't RPC */
3225 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
3228 /* Search for an existing open(O_WRITE) file */
3229 if (sattr
->ia_valid
& ATTR_FILE
) {
3230 struct nfs_open_context
*ctx
;
3232 ctx
= nfs_file_open_context(sattr
->ia_file
);
3239 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
3241 return PTR_ERR(label
);
3243 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
3245 nfs_setattr_update_inode(inode
, sattr
);
3246 nfs_setsecurity(inode
, fattr
, label
);
3248 nfs4_label_free(label
);
3252 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
3253 const struct qstr
*name
, struct nfs_fh
*fhandle
,
3254 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3256 struct nfs_server
*server
= NFS_SERVER(dir
);
3258 struct nfs4_lookup_arg args
= {
3259 .bitmask
= server
->attr_bitmask
,
3260 .dir_fh
= NFS_FH(dir
),
3263 struct nfs4_lookup_res res
= {
3269 struct rpc_message msg
= {
3270 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3275 args
.bitmask
= nfs4_bitmask(server
, label
);
3277 nfs_fattr_init(fattr
);
3279 dprintk("NFS call lookup %s\n", name
->name
);
3280 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3281 dprintk("NFS reply lookup: %d\n", status
);
3285 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3287 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3288 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3289 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3293 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3294 struct qstr
*name
, struct nfs_fh
*fhandle
,
3295 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3297 struct nfs4_exception exception
= { };
3298 struct rpc_clnt
*client
= *clnt
;
3301 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3302 trace_nfs4_lookup(dir
, name
, err
);
3304 case -NFS4ERR_BADNAME
:
3307 case -NFS4ERR_MOVED
:
3308 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3310 case -NFS4ERR_WRONGSEC
:
3312 if (client
!= *clnt
)
3314 client
= nfs4_negotiate_security(client
, dir
, name
);
3316 return PTR_ERR(client
);
3318 exception
.retry
= 1;
3321 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3323 } while (exception
.retry
);
3328 else if (client
!= *clnt
)
3329 rpc_shutdown_client(client
);
3334 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3335 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3336 struct nfs4_label
*label
)
3339 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3341 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3342 if (client
!= NFS_CLIENT(dir
)) {
3343 rpc_shutdown_client(client
);
3344 nfs_fixup_secinfo_attributes(fattr
);
3350 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3351 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3353 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3356 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3358 return ERR_PTR(status
);
3359 return (client
== NFS_CLIENT(dir
)) ? rpc_clone_client(client
) : client
;
3362 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3364 struct nfs_server
*server
= NFS_SERVER(inode
);
3365 struct nfs4_accessargs args
= {
3366 .fh
= NFS_FH(inode
),
3367 .bitmask
= server
->cache_consistency_bitmask
,
3369 struct nfs4_accessres res
= {
3372 struct rpc_message msg
= {
3373 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3376 .rpc_cred
= entry
->cred
,
3378 int mode
= entry
->mask
;
3382 * Determine which access bits we want to ask for...
3384 if (mode
& MAY_READ
)
3385 args
.access
|= NFS4_ACCESS_READ
;
3386 if (S_ISDIR(inode
->i_mode
)) {
3387 if (mode
& MAY_WRITE
)
3388 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3389 if (mode
& MAY_EXEC
)
3390 args
.access
|= NFS4_ACCESS_LOOKUP
;
3392 if (mode
& MAY_WRITE
)
3393 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3394 if (mode
& MAY_EXEC
)
3395 args
.access
|= NFS4_ACCESS_EXECUTE
;
3398 res
.fattr
= nfs_alloc_fattr();
3399 if (res
.fattr
== NULL
)
3402 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3404 nfs_access_set_mask(entry
, res
.access
);
3405 nfs_refresh_inode(inode
, res
.fattr
);
3407 nfs_free_fattr(res
.fattr
);
3411 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3413 struct nfs4_exception exception
= { };
3416 err
= _nfs4_proc_access(inode
, entry
);
3417 trace_nfs4_access(inode
, err
);
3418 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3420 } while (exception
.retry
);
3425 * TODO: For the time being, we don't try to get any attributes
3426 * along with any of the zero-copy operations READ, READDIR,
3429 * In the case of the first three, we want to put the GETATTR
3430 * after the read-type operation -- this is because it is hard
3431 * to predict the length of a GETATTR response in v4, and thus
3432 * align the READ data correctly. This means that the GETATTR
3433 * may end up partially falling into the page cache, and we should
3434 * shift it into the 'tail' of the xdr_buf before processing.
3435 * To do this efficiently, we need to know the total length
3436 * of data received, which doesn't seem to be available outside
3439 * In the case of WRITE, we also want to put the GETATTR after
3440 * the operation -- in this case because we want to make sure
3441 * we get the post-operation mtime and size.
3443 * Both of these changes to the XDR layer would in fact be quite
3444 * minor, but I decided to leave them for a subsequent patch.
3446 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3447 unsigned int pgbase
, unsigned int pglen
)
3449 struct nfs4_readlink args
= {
3450 .fh
= NFS_FH(inode
),
3455 struct nfs4_readlink_res res
;
3456 struct rpc_message msg
= {
3457 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3462 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3465 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3466 unsigned int pgbase
, unsigned int pglen
)
3468 struct nfs4_exception exception
= { };
3471 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3472 trace_nfs4_readlink(inode
, err
);
3473 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3475 } while (exception
.retry
);
3480 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3483 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3486 struct nfs4_label l
, *ilabel
= NULL
;
3487 struct nfs_open_context
*ctx
;
3488 struct nfs4_state
*state
;
3492 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3494 return PTR_ERR(ctx
);
3496 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3498 sattr
->ia_mode
&= ~current_umask();
3499 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
, &opened
);
3500 if (IS_ERR(state
)) {
3501 status
= PTR_ERR(state
);
3505 nfs4_label_release_security(ilabel
);
3506 put_nfs_open_context(ctx
);
3510 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3512 struct nfs_server
*server
= NFS_SERVER(dir
);
3513 struct nfs_removeargs args
= {
3517 struct nfs_removeres res
= {
3520 struct rpc_message msg
= {
3521 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3527 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3529 update_changeattr(dir
, &res
.cinfo
);
3533 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3535 struct nfs4_exception exception
= { };
3538 err
= _nfs4_proc_remove(dir
, name
);
3539 trace_nfs4_remove(dir
, name
, err
);
3540 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3542 } while (exception
.retry
);
3546 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3548 struct nfs_server
*server
= NFS_SERVER(dir
);
3549 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3550 struct nfs_removeres
*res
= msg
->rpc_resp
;
3552 res
->server
= server
;
3553 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3554 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3556 nfs_fattr_init(res
->dir_attr
);
3559 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3561 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3562 &data
->args
.seq_args
,
3567 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3569 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3570 struct nfs_removeres
*res
= &data
->res
;
3572 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3574 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3576 update_changeattr(dir
, &res
->cinfo
);
3580 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3582 struct nfs_server
*server
= NFS_SERVER(dir
);
3583 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3584 struct nfs_renameres
*res
= msg
->rpc_resp
;
3586 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3587 res
->server
= server
;
3588 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3591 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3593 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3594 &data
->args
.seq_args
,
3599 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3600 struct inode
*new_dir
)
3602 struct nfs_renamedata
*data
= task
->tk_calldata
;
3603 struct nfs_renameres
*res
= &data
->res
;
3605 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3607 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3610 update_changeattr(old_dir
, &res
->old_cinfo
);
3611 update_changeattr(new_dir
, &res
->new_cinfo
);
3615 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3617 struct nfs_server
*server
= NFS_SERVER(inode
);
3618 struct nfs4_link_arg arg
= {
3619 .fh
= NFS_FH(inode
),
3620 .dir_fh
= NFS_FH(dir
),
3622 .bitmask
= server
->attr_bitmask
,
3624 struct nfs4_link_res res
= {
3628 struct rpc_message msg
= {
3629 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3633 int status
= -ENOMEM
;
3635 res
.fattr
= nfs_alloc_fattr();
3636 if (res
.fattr
== NULL
)
3639 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3640 if (IS_ERR(res
.label
)) {
3641 status
= PTR_ERR(res
.label
);
3644 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3646 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3648 update_changeattr(dir
, &res
.cinfo
);
3649 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3651 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3655 nfs4_label_free(res
.label
);
3658 nfs_free_fattr(res
.fattr
);
3662 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3664 struct nfs4_exception exception
= { };
3667 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3668 _nfs4_proc_link(inode
, dir
, name
),
3670 } while (exception
.retry
);
3674 struct nfs4_createdata
{
3675 struct rpc_message msg
;
3676 struct nfs4_create_arg arg
;
3677 struct nfs4_create_res res
;
3679 struct nfs_fattr fattr
;
3680 struct nfs4_label
*label
;
3683 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3684 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3686 struct nfs4_createdata
*data
;
3688 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3690 struct nfs_server
*server
= NFS_SERVER(dir
);
3692 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3693 if (IS_ERR(data
->label
))
3696 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3697 data
->msg
.rpc_argp
= &data
->arg
;
3698 data
->msg
.rpc_resp
= &data
->res
;
3699 data
->arg
.dir_fh
= NFS_FH(dir
);
3700 data
->arg
.server
= server
;
3701 data
->arg
.name
= name
;
3702 data
->arg
.attrs
= sattr
;
3703 data
->arg
.ftype
= ftype
;
3704 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3705 data
->res
.server
= server
;
3706 data
->res
.fh
= &data
->fh
;
3707 data
->res
.fattr
= &data
->fattr
;
3708 data
->res
.label
= data
->label
;
3709 nfs_fattr_init(data
->res
.fattr
);
3717 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3719 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3720 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3722 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3723 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3728 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3730 nfs4_label_free(data
->label
);
3734 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3735 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3736 struct nfs4_label
*label
)
3738 struct nfs4_createdata
*data
;
3739 int status
= -ENAMETOOLONG
;
3741 if (len
> NFS4_MAXPATHLEN
)
3745 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3749 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3750 data
->arg
.u
.symlink
.pages
= &page
;
3751 data
->arg
.u
.symlink
.len
= len
;
3752 data
->arg
.label
= label
;
3754 status
= nfs4_do_create(dir
, dentry
, data
);
3756 nfs4_free_createdata(data
);
3761 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3762 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3764 struct nfs4_exception exception
= { };
3765 struct nfs4_label l
, *label
= NULL
;
3768 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3771 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3772 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3773 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3775 } while (exception
.retry
);
3777 nfs4_label_release_security(label
);
3781 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3782 struct iattr
*sattr
, struct nfs4_label
*label
)
3784 struct nfs4_createdata
*data
;
3785 int status
= -ENOMEM
;
3787 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3791 data
->arg
.label
= label
;
3792 status
= nfs4_do_create(dir
, dentry
, data
);
3794 nfs4_free_createdata(data
);
3799 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3800 struct iattr
*sattr
)
3802 struct nfs4_exception exception
= { };
3803 struct nfs4_label l
, *label
= NULL
;
3806 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3808 sattr
->ia_mode
&= ~current_umask();
3810 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3811 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3812 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3814 } while (exception
.retry
);
3815 nfs4_label_release_security(label
);
3820 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3821 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3823 struct inode
*dir
= dentry
->d_inode
;
3824 struct nfs4_readdir_arg args
= {
3829 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3832 struct nfs4_readdir_res res
;
3833 struct rpc_message msg
= {
3834 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3841 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__
,
3843 (unsigned long long)cookie
);
3844 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3845 res
.pgbase
= args
.pgbase
;
3846 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3848 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3849 status
+= args
.pgbase
;
3852 nfs_invalidate_atime(dir
);
3854 dprintk("%s: returns %d\n", __func__
, status
);
3858 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3859 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3861 struct nfs4_exception exception
= { };
3864 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3865 pages
, count
, plus
);
3866 trace_nfs4_readdir(dentry
->d_inode
, err
);
3867 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3869 } while (exception
.retry
);
3873 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3874 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3876 struct nfs4_createdata
*data
;
3877 int mode
= sattr
->ia_mode
;
3878 int status
= -ENOMEM
;
3880 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3885 data
->arg
.ftype
= NF4FIFO
;
3886 else if (S_ISBLK(mode
)) {
3887 data
->arg
.ftype
= NF4BLK
;
3888 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3889 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3891 else if (S_ISCHR(mode
)) {
3892 data
->arg
.ftype
= NF4CHR
;
3893 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3894 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3895 } else if (!S_ISSOCK(mode
)) {
3900 data
->arg
.label
= label
;
3901 status
= nfs4_do_create(dir
, dentry
, data
);
3903 nfs4_free_createdata(data
);
3908 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3909 struct iattr
*sattr
, dev_t rdev
)
3911 struct nfs4_exception exception
= { };
3912 struct nfs4_label l
, *label
= NULL
;
3915 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3917 sattr
->ia_mode
&= ~current_umask();
3919 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3920 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3921 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3923 } while (exception
.retry
);
3925 nfs4_label_release_security(label
);
3930 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3931 struct nfs_fsstat
*fsstat
)
3933 struct nfs4_statfs_arg args
= {
3935 .bitmask
= server
->attr_bitmask
,
3937 struct nfs4_statfs_res res
= {
3940 struct rpc_message msg
= {
3941 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3946 nfs_fattr_init(fsstat
->fattr
);
3947 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3950 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3952 struct nfs4_exception exception
= { };
3955 err
= nfs4_handle_exception(server
,
3956 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3958 } while (exception
.retry
);
3962 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3963 struct nfs_fsinfo
*fsinfo
)
3965 struct nfs4_fsinfo_arg args
= {
3967 .bitmask
= server
->attr_bitmask
,
3969 struct nfs4_fsinfo_res res
= {
3972 struct rpc_message msg
= {
3973 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3978 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3981 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3983 struct nfs4_exception exception
= { };
3984 unsigned long now
= jiffies
;
3988 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3989 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
3991 struct nfs_client
*clp
= server
->nfs_client
;
3993 spin_lock(&clp
->cl_lock
);
3994 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
3995 clp
->cl_last_renewal
= now
;
3996 spin_unlock(&clp
->cl_lock
);
3999 err
= nfs4_handle_exception(server
, err
, &exception
);
4000 } while (exception
.retry
);
4004 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4008 nfs_fattr_init(fsinfo
->fattr
);
4009 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4011 /* block layout checks this! */
4012 server
->pnfs_blksize
= fsinfo
->blksize
;
4013 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
4019 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4020 struct nfs_pathconf
*pathconf
)
4022 struct nfs4_pathconf_arg args
= {
4024 .bitmask
= server
->attr_bitmask
,
4026 struct nfs4_pathconf_res res
= {
4027 .pathconf
= pathconf
,
4029 struct rpc_message msg
= {
4030 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
4035 /* None of the pathconf attributes are mandatory to implement */
4036 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
4037 memset(pathconf
, 0, sizeof(*pathconf
));
4041 nfs_fattr_init(pathconf
->fattr
);
4042 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4045 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4046 struct nfs_pathconf
*pathconf
)
4048 struct nfs4_exception exception
= { };
4052 err
= nfs4_handle_exception(server
,
4053 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
4055 } while (exception
.retry
);
4059 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
4060 const struct nfs_open_context
*ctx
,
4061 const struct nfs_lock_context
*l_ctx
,
4064 const struct nfs_lockowner
*lockowner
= NULL
;
4067 lockowner
= &l_ctx
->lockowner
;
4068 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
4070 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
4072 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
4073 const struct nfs_open_context
*ctx
,
4074 const struct nfs_lock_context
*l_ctx
,
4077 nfs4_stateid current_stateid
;
4079 /* If the current stateid represents a lost lock, then exit */
4080 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
) == -EIO
)
4082 return nfs4_stateid_match(stateid
, ¤t_stateid
);
4085 static bool nfs4_error_stateid_expired(int err
)
4088 case -NFS4ERR_DELEG_REVOKED
:
4089 case -NFS4ERR_ADMIN_REVOKED
:
4090 case -NFS4ERR_BAD_STATEID
:
4091 case -NFS4ERR_STALE_STATEID
:
4092 case -NFS4ERR_OLD_STATEID
:
4093 case -NFS4ERR_OPENMODE
:
4094 case -NFS4ERR_EXPIRED
:
4100 void __nfs4_read_done_cb(struct nfs_pgio_header
*hdr
)
4102 nfs_invalidate_atime(hdr
->inode
);
4105 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4107 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4109 trace_nfs4_read(hdr
, task
->tk_status
);
4110 if (nfs4_async_handle_error(task
, server
,
4111 hdr
->args
.context
->state
) == -EAGAIN
) {
4112 rpc_restart_call_prepare(task
);
4116 __nfs4_read_done_cb(hdr
);
4117 if (task
->tk_status
> 0)
4118 renew_lease(server
, hdr
->timestamp
);
4122 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
4123 struct nfs_pgio_args
*args
)
4126 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4127 nfs4_stateid_is_current(&args
->stateid
,
4132 rpc_restart_call_prepare(task
);
4136 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4139 dprintk("--> %s\n", __func__
);
4141 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
4143 if (nfs4_read_stateid_changed(task
, &hdr
->args
))
4145 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
4146 nfs4_read_done_cb(task
, hdr
);
4149 static void nfs4_proc_read_setup(struct nfs_pgio_header
*hdr
,
4150 struct rpc_message
*msg
)
4152 hdr
->timestamp
= jiffies
;
4153 hdr
->pgio_done_cb
= nfs4_read_done_cb
;
4154 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
4155 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 0);
4158 static int nfs4_proc_pgio_rpc_prepare(struct rpc_task
*task
,
4159 struct nfs_pgio_header
*hdr
)
4161 if (nfs4_setup_sequence(NFS_SERVER(hdr
->inode
),
4162 &hdr
->args
.seq_args
,
4166 if (nfs4_set_rw_stateid(&hdr
->args
.stateid
, hdr
->args
.context
,
4167 hdr
->args
.lock_context
,
4168 hdr
->rw_ops
->rw_mode
) == -EIO
)
4170 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
)))
4175 static int nfs4_write_done_cb(struct rpc_task
*task
,
4176 struct nfs_pgio_header
*hdr
)
4178 struct inode
*inode
= hdr
->inode
;
4180 trace_nfs4_write(hdr
, task
->tk_status
);
4181 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
),
4182 hdr
->args
.context
->state
) == -EAGAIN
) {
4183 rpc_restart_call_prepare(task
);
4186 if (task
->tk_status
>= 0) {
4187 renew_lease(NFS_SERVER(inode
), hdr
->timestamp
);
4188 nfs_post_op_update_inode_force_wcc(inode
, &hdr
->fattr
);
4193 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
4194 struct nfs_pgio_args
*args
)
4197 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4198 nfs4_stateid_is_current(&args
->stateid
,
4203 rpc_restart_call_prepare(task
);
4207 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4209 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
4211 if (nfs4_write_stateid_changed(task
, &hdr
->args
))
4213 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
4214 nfs4_write_done_cb(task
, hdr
);
4218 bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header
*hdr
)
4220 /* Don't request attributes for pNFS or O_DIRECT writes */
4221 if (hdr
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
4223 /* Otherwise, request attributes if and only if we don't hold
4226 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
4229 static void nfs4_proc_write_setup(struct nfs_pgio_header
*hdr
,
4230 struct rpc_message
*msg
)
4232 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4234 if (!nfs4_write_need_cache_consistency_data(hdr
)) {
4235 hdr
->args
.bitmask
= NULL
;
4236 hdr
->res
.fattr
= NULL
;
4238 hdr
->args
.bitmask
= server
->cache_consistency_bitmask
;
4240 if (!hdr
->pgio_done_cb
)
4241 hdr
->pgio_done_cb
= nfs4_write_done_cb
;
4242 hdr
->res
.server
= server
;
4243 hdr
->timestamp
= jiffies
;
4245 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4246 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 1);
4249 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4251 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4252 &data
->args
.seq_args
,
4257 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4259 struct inode
*inode
= data
->inode
;
4261 trace_nfs4_commit(data
, task
->tk_status
);
4262 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
4263 rpc_restart_call_prepare(task
);
4269 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4271 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4273 return data
->commit_done_cb(task
, data
);
4276 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4278 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4280 if (data
->commit_done_cb
== NULL
)
4281 data
->commit_done_cb
= nfs4_commit_done_cb
;
4282 data
->res
.server
= server
;
4283 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4284 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4287 struct nfs4_renewdata
{
4288 struct nfs_client
*client
;
4289 unsigned long timestamp
;
4293 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4294 * standalone procedure for queueing an asynchronous RENEW.
4296 static void nfs4_renew_release(void *calldata
)
4298 struct nfs4_renewdata
*data
= calldata
;
4299 struct nfs_client
*clp
= data
->client
;
4301 if (atomic_read(&clp
->cl_count
) > 1)
4302 nfs4_schedule_state_renewal(clp
);
4303 nfs_put_client(clp
);
4307 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4309 struct nfs4_renewdata
*data
= calldata
;
4310 struct nfs_client
*clp
= data
->client
;
4311 unsigned long timestamp
= data
->timestamp
;
4313 trace_nfs4_renew_async(clp
, task
->tk_status
);
4314 switch (task
->tk_status
) {
4317 case -NFS4ERR_LEASE_MOVED
:
4318 nfs4_schedule_lease_moved_recovery(clp
);
4321 /* Unless we're shutting down, schedule state recovery! */
4322 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4324 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4325 nfs4_schedule_lease_recovery(clp
);
4328 nfs4_schedule_path_down_recovery(clp
);
4330 do_renew_lease(clp
, timestamp
);
4333 static const struct rpc_call_ops nfs4_renew_ops
= {
4334 .rpc_call_done
= nfs4_renew_done
,
4335 .rpc_release
= nfs4_renew_release
,
4338 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4340 struct rpc_message msg
= {
4341 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4345 struct nfs4_renewdata
*data
;
4347 if (renew_flags
== 0)
4349 if (!atomic_inc_not_zero(&clp
->cl_count
))
4351 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4355 data
->timestamp
= jiffies
;
4356 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4357 &nfs4_renew_ops
, data
);
4360 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4362 struct rpc_message msg
= {
4363 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4367 unsigned long now
= jiffies
;
4370 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4373 do_renew_lease(clp
, now
);
4377 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4379 return server
->caps
& NFS_CAP_ACLS
;
4382 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4383 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4386 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4388 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4389 struct page
**pages
, unsigned int *pgbase
)
4391 struct page
*newpage
, **spages
;
4397 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4398 newpage
= alloc_page(GFP_KERNEL
);
4400 if (newpage
== NULL
)
4402 memcpy(page_address(newpage
), buf
, len
);
4407 } while (buflen
!= 0);
4413 __free_page(spages
[rc
-1]);
4417 struct nfs4_cached_acl
{
4423 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4425 struct nfs_inode
*nfsi
= NFS_I(inode
);
4427 spin_lock(&inode
->i_lock
);
4428 kfree(nfsi
->nfs4_acl
);
4429 nfsi
->nfs4_acl
= acl
;
4430 spin_unlock(&inode
->i_lock
);
4433 static void nfs4_zap_acl_attr(struct inode
*inode
)
4435 nfs4_set_cached_acl(inode
, NULL
);
4438 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4440 struct nfs_inode
*nfsi
= NFS_I(inode
);
4441 struct nfs4_cached_acl
*acl
;
4444 spin_lock(&inode
->i_lock
);
4445 acl
= nfsi
->nfs4_acl
;
4448 if (buf
== NULL
) /* user is just asking for length */
4450 if (acl
->cached
== 0)
4452 ret
= -ERANGE
; /* see getxattr(2) man page */
4453 if (acl
->len
> buflen
)
4455 memcpy(buf
, acl
->data
, acl
->len
);
4459 spin_unlock(&inode
->i_lock
);
4463 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4465 struct nfs4_cached_acl
*acl
;
4466 size_t buflen
= sizeof(*acl
) + acl_len
;
4468 if (buflen
<= PAGE_SIZE
) {
4469 acl
= kmalloc(buflen
, GFP_KERNEL
);
4473 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4475 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4482 nfs4_set_cached_acl(inode
, acl
);
4486 * The getxattr API returns the required buffer length when called with a
4487 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4488 * the required buf. On a NULL buf, we send a page of data to the server
4489 * guessing that the ACL request can be serviced by a page. If so, we cache
4490 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4491 * the cache. If not so, we throw away the page, and cache the required
4492 * length. The next getxattr call will then produce another round trip to
4493 * the server, this time with the input buf of the required size.
4495 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4497 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4498 struct nfs_getaclargs args
= {
4499 .fh
= NFS_FH(inode
),
4503 struct nfs_getaclres res
= {
4506 struct rpc_message msg
= {
4507 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4511 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4512 int ret
= -ENOMEM
, i
;
4514 /* As long as we're doing a round trip to the server anyway,
4515 * let's be prepared for a page of acl data. */
4518 if (npages
> ARRAY_SIZE(pages
))
4521 for (i
= 0; i
< npages
; i
++) {
4522 pages
[i
] = alloc_page(GFP_KERNEL
);
4527 /* for decoding across pages */
4528 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4529 if (!res
.acl_scratch
)
4532 args
.acl_len
= npages
* PAGE_SIZE
;
4533 args
.acl_pgbase
= 0;
4535 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4536 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4537 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4538 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4542 /* Handle the case where the passed-in buffer is too short */
4543 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4544 /* Did the user only issue a request for the acl length? */
4550 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4552 if (res
.acl_len
> buflen
) {
4556 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4561 for (i
= 0; i
< npages
; i
++)
4563 __free_page(pages
[i
]);
4564 if (res
.acl_scratch
)
4565 __free_page(res
.acl_scratch
);
4569 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4571 struct nfs4_exception exception
= { };
4574 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4575 trace_nfs4_get_acl(inode
, ret
);
4578 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4579 } while (exception
.retry
);
4583 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4585 struct nfs_server
*server
= NFS_SERVER(inode
);
4588 if (!nfs4_server_supports_acls(server
))
4590 ret
= nfs_revalidate_inode(server
, inode
);
4593 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4594 nfs_zap_acl_cache(inode
);
4595 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4597 /* -ENOENT is returned if there is no ACL or if there is an ACL
4598 * but no cached acl data, just the acl length */
4600 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4603 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4605 struct nfs_server
*server
= NFS_SERVER(inode
);
4606 struct page
*pages
[NFS4ACL_MAXPAGES
];
4607 struct nfs_setaclargs arg
= {
4608 .fh
= NFS_FH(inode
),
4612 struct nfs_setaclres res
;
4613 struct rpc_message msg
= {
4614 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4618 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4621 if (!nfs4_server_supports_acls(server
))
4623 if (npages
> ARRAY_SIZE(pages
))
4625 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4628 nfs4_inode_return_delegation(inode
);
4629 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4632 * Free each page after tx, so the only ref left is
4633 * held by the network stack
4636 put_page(pages
[i
-1]);
4639 * Acl update can result in inode attribute update.
4640 * so mark the attribute cache invalid.
4642 spin_lock(&inode
->i_lock
);
4643 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4644 spin_unlock(&inode
->i_lock
);
4645 nfs_access_zap_cache(inode
);
4646 nfs_zap_acl_cache(inode
);
4650 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4652 struct nfs4_exception exception
= { };
4655 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4656 trace_nfs4_set_acl(inode
, err
);
4657 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4659 } while (exception
.retry
);
4663 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4664 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4667 struct nfs_server
*server
= NFS_SERVER(inode
);
4668 struct nfs_fattr fattr
;
4669 struct nfs4_label label
= {0, 0, buflen
, buf
};
4671 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4672 struct nfs4_getattr_arg arg
= {
4673 .fh
= NFS_FH(inode
),
4676 struct nfs4_getattr_res res
= {
4681 struct rpc_message msg
= {
4682 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4688 nfs_fattr_init(&fattr
);
4690 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 0);
4693 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4695 if (buflen
< label
.len
)
4700 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4703 struct nfs4_exception exception
= { };
4706 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4710 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4711 trace_nfs4_get_security_label(inode
, err
);
4712 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4714 } while (exception
.retry
);
4718 static int _nfs4_do_set_security_label(struct inode
*inode
,
4719 struct nfs4_label
*ilabel
,
4720 struct nfs_fattr
*fattr
,
4721 struct nfs4_label
*olabel
)
4724 struct iattr sattr
= {0};
4725 struct nfs_server
*server
= NFS_SERVER(inode
);
4726 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4727 struct nfs_setattrargs arg
= {
4728 .fh
= NFS_FH(inode
),
4734 struct nfs_setattrres res
= {
4739 struct rpc_message msg
= {
4740 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4746 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
4748 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4750 dprintk("%s failed: %d\n", __func__
, status
);
4755 static int nfs4_do_set_security_label(struct inode
*inode
,
4756 struct nfs4_label
*ilabel
,
4757 struct nfs_fattr
*fattr
,
4758 struct nfs4_label
*olabel
)
4760 struct nfs4_exception exception
= { };
4764 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4766 trace_nfs4_set_security_label(inode
, err
);
4767 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4769 } while (exception
.retry
);
4774 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4776 struct nfs4_label ilabel
, *olabel
= NULL
;
4777 struct nfs_fattr fattr
;
4778 struct rpc_cred
*cred
;
4779 struct inode
*inode
= dentry
->d_inode
;
4782 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4785 nfs_fattr_init(&fattr
);
4789 ilabel
.label
= (char *)buf
;
4790 ilabel
.len
= buflen
;
4792 cred
= rpc_lookup_cred();
4794 return PTR_ERR(cred
);
4796 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4797 if (IS_ERR(olabel
)) {
4798 status
= -PTR_ERR(olabel
);
4802 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4804 nfs_setsecurity(inode
, &fattr
, olabel
);
4806 nfs4_label_free(olabel
);
4811 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4815 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
4817 struct nfs_client
*clp
= server
->nfs_client
;
4819 if (task
->tk_status
>= 0)
4821 switch(task
->tk_status
) {
4822 case -NFS4ERR_DELEG_REVOKED
:
4823 case -NFS4ERR_ADMIN_REVOKED
:
4824 case -NFS4ERR_BAD_STATEID
:
4827 nfs_remove_bad_delegation(state
->inode
);
4828 case -NFS4ERR_OPENMODE
:
4831 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4832 goto recovery_failed
;
4833 goto wait_on_recovery
;
4834 case -NFS4ERR_EXPIRED
:
4835 if (state
!= NULL
) {
4836 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4837 goto recovery_failed
;
4839 case -NFS4ERR_STALE_STATEID
:
4840 case -NFS4ERR_STALE_CLIENTID
:
4841 nfs4_schedule_lease_recovery(clp
);
4842 goto wait_on_recovery
;
4843 case -NFS4ERR_MOVED
:
4844 if (nfs4_schedule_migration_recovery(server
) < 0)
4845 goto recovery_failed
;
4846 goto wait_on_recovery
;
4847 case -NFS4ERR_LEASE_MOVED
:
4848 nfs4_schedule_lease_moved_recovery(clp
);
4849 goto wait_on_recovery
;
4850 #if defined(CONFIG_NFS_V4_1)
4851 case -NFS4ERR_BADSESSION
:
4852 case -NFS4ERR_BADSLOT
:
4853 case -NFS4ERR_BAD_HIGH_SLOT
:
4854 case -NFS4ERR_DEADSESSION
:
4855 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4856 case -NFS4ERR_SEQ_FALSE_RETRY
:
4857 case -NFS4ERR_SEQ_MISORDERED
:
4858 dprintk("%s ERROR %d, Reset session\n", __func__
,
4860 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4861 goto wait_on_recovery
;
4862 #endif /* CONFIG_NFS_V4_1 */
4863 case -NFS4ERR_DELAY
:
4864 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4865 case -NFS4ERR_GRACE
:
4866 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4867 case -NFS4ERR_RETRY_UNCACHED_REP
:
4868 case -NFS4ERR_OLD_STATEID
:
4871 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4874 task
->tk_status
= -EIO
;
4877 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4878 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4879 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4880 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
4881 goto recovery_failed
;
4883 task
->tk_status
= 0;
4887 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4888 nfs4_verifier
*bootverf
)
4892 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4893 /* An impossible timestamp guarantees this value
4894 * will never match a generated boot time. */
4896 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4898 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4899 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4900 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4902 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4906 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4907 char *buf
, size_t len
)
4909 unsigned int result
;
4912 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4914 rpc_peeraddr2str(clp
->cl_rpcclient
,
4916 rpc_peeraddr2str(clp
->cl_rpcclient
,
4917 RPC_DISPLAY_PROTO
));
4923 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4924 char *buf
, size_t len
)
4926 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4928 if (nfs4_client_id_uniquifier
[0] != '\0')
4929 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4930 clp
->rpc_ops
->version
,
4931 clp
->cl_minorversion
,
4932 nfs4_client_id_uniquifier
,
4934 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4935 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4940 * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback
4941 * services. Advertise one based on the address family of the
4945 nfs4_init_callback_netid(const struct nfs_client
*clp
, char *buf
, size_t len
)
4947 if (strchr(clp
->cl_ipaddr
, ':') != NULL
)
4948 return scnprintf(buf
, len
, "tcp6");
4950 return scnprintf(buf
, len
, "tcp");
4953 static void nfs4_setclientid_done(struct rpc_task
*task
, void *calldata
)
4955 struct nfs4_setclientid
*sc
= calldata
;
4957 if (task
->tk_status
== 0)
4958 sc
->sc_cred
= get_rpccred(task
->tk_rqstp
->rq_cred
);
4961 static const struct rpc_call_ops nfs4_setclientid_ops
= {
4962 .rpc_call_done
= nfs4_setclientid_done
,
4966 * nfs4_proc_setclientid - Negotiate client ID
4967 * @clp: state data structure
4968 * @program: RPC program for NFSv4 callback service
4969 * @port: IP port number for NFS4 callback service
4970 * @cred: RPC credential to use for this call
4971 * @res: where to place the result
4973 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4975 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4976 unsigned short port
, struct rpc_cred
*cred
,
4977 struct nfs4_setclientid_res
*res
)
4979 nfs4_verifier sc_verifier
;
4980 struct nfs4_setclientid setclientid
= {
4981 .sc_verifier
= &sc_verifier
,
4983 .sc_cb_ident
= clp
->cl_cb_ident
,
4985 struct rpc_message msg
= {
4986 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
4987 .rpc_argp
= &setclientid
,
4991 struct rpc_task
*task
;
4992 struct rpc_task_setup task_setup_data
= {
4993 .rpc_client
= clp
->cl_rpcclient
,
4994 .rpc_message
= &msg
,
4995 .callback_ops
= &nfs4_setclientid_ops
,
4996 .callback_data
= &setclientid
,
4997 .flags
= RPC_TASK_TIMEOUT
,
5001 /* nfs_client_id4 */
5002 nfs4_init_boot_verifier(clp
, &sc_verifier
);
5003 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
5004 setclientid
.sc_name_len
=
5005 nfs4_init_uniform_client_string(clp
,
5006 setclientid
.sc_name
,
5007 sizeof(setclientid
.sc_name
));
5009 setclientid
.sc_name_len
=
5010 nfs4_init_nonuniform_client_string(clp
,
5011 setclientid
.sc_name
,
5012 sizeof(setclientid
.sc_name
));
5014 setclientid
.sc_netid_len
=
5015 nfs4_init_callback_netid(clp
,
5016 setclientid
.sc_netid
,
5017 sizeof(setclientid
.sc_netid
));
5018 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
5019 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
5020 clp
->cl_ipaddr
, port
>> 8, port
& 255);
5022 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
5023 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5024 setclientid
.sc_name_len
, setclientid
.sc_name
);
5025 task
= rpc_run_task(&task_setup_data
);
5027 status
= PTR_ERR(task
);
5030 status
= task
->tk_status
;
5031 if (setclientid
.sc_cred
) {
5032 clp
->cl_acceptor
= rpcauth_stringify_acceptor(setclientid
.sc_cred
);
5033 put_rpccred(setclientid
.sc_cred
);
5037 trace_nfs4_setclientid(clp
, status
);
5038 dprintk("NFS reply setclientid: %d\n", status
);
5043 * nfs4_proc_setclientid_confirm - Confirm client ID
5044 * @clp: state data structure
5045 * @res: result of a previous SETCLIENTID
5046 * @cred: RPC credential to use for this call
5048 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5050 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
5051 struct nfs4_setclientid_res
*arg
,
5052 struct rpc_cred
*cred
)
5054 struct rpc_message msg
= {
5055 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
5061 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
5062 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5064 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5065 trace_nfs4_setclientid_confirm(clp
, status
);
5066 dprintk("NFS reply setclientid_confirm: %d\n", status
);
5070 struct nfs4_delegreturndata
{
5071 struct nfs4_delegreturnargs args
;
5072 struct nfs4_delegreturnres res
;
5074 nfs4_stateid stateid
;
5075 unsigned long timestamp
;
5076 struct nfs_fattr fattr
;
5078 struct inode
*inode
;
5083 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
5085 struct nfs4_delegreturndata
*data
= calldata
;
5087 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5090 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
5091 switch (task
->tk_status
) {
5093 renew_lease(data
->res
.server
, data
->timestamp
);
5094 case -NFS4ERR_ADMIN_REVOKED
:
5095 case -NFS4ERR_DELEG_REVOKED
:
5096 case -NFS4ERR_BAD_STATEID
:
5097 case -NFS4ERR_OLD_STATEID
:
5098 case -NFS4ERR_STALE_STATEID
:
5099 case -NFS4ERR_EXPIRED
:
5100 task
->tk_status
= 0;
5102 pnfs_roc_set_barrier(data
->inode
, data
->roc_barrier
);
5105 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
5107 rpc_restart_call_prepare(task
);
5111 data
->rpc_status
= task
->tk_status
;
5114 static void nfs4_delegreturn_release(void *calldata
)
5116 struct nfs4_delegreturndata
*data
= calldata
;
5119 pnfs_roc_release(data
->inode
);
5123 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
5125 struct nfs4_delegreturndata
*d_data
;
5127 d_data
= (struct nfs4_delegreturndata
*)data
;
5130 pnfs_roc_drain(d_data
->inode
, &d_data
->roc_barrier
, task
))
5133 nfs4_setup_sequence(d_data
->res
.server
,
5134 &d_data
->args
.seq_args
,
5135 &d_data
->res
.seq_res
,
5139 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
5140 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
5141 .rpc_call_done
= nfs4_delegreturn_done
,
5142 .rpc_release
= nfs4_delegreturn_release
,
5145 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5147 struct nfs4_delegreturndata
*data
;
5148 struct nfs_server
*server
= NFS_SERVER(inode
);
5149 struct rpc_task
*task
;
5150 struct rpc_message msg
= {
5151 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
5154 struct rpc_task_setup task_setup_data
= {
5155 .rpc_client
= server
->client
,
5156 .rpc_message
= &msg
,
5157 .callback_ops
= &nfs4_delegreturn_ops
,
5158 .flags
= RPC_TASK_ASYNC
,
5162 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
5165 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
5166 data
->args
.fhandle
= &data
->fh
;
5167 data
->args
.stateid
= &data
->stateid
;
5168 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
5169 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
5170 nfs4_stateid_copy(&data
->stateid
, stateid
);
5171 data
->res
.fattr
= &data
->fattr
;
5172 data
->res
.server
= server
;
5173 nfs_fattr_init(data
->res
.fattr
);
5174 data
->timestamp
= jiffies
;
5175 data
->rpc_status
= 0;
5176 data
->inode
= inode
;
5177 data
->roc
= list_empty(&NFS_I(inode
)->open_files
) ?
5178 pnfs_roc(inode
) : false;
5180 task_setup_data
.callback_data
= data
;
5181 msg
.rpc_argp
= &data
->args
;
5182 msg
.rpc_resp
= &data
->res
;
5183 task
= rpc_run_task(&task_setup_data
);
5185 return PTR_ERR(task
);
5188 status
= nfs4_wait_for_completion_rpc_task(task
);
5191 status
= data
->rpc_status
;
5193 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
5195 nfs_refresh_inode(inode
, &data
->fattr
);
5201 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5203 struct nfs_server
*server
= NFS_SERVER(inode
);
5204 struct nfs4_exception exception
= { };
5207 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
5208 trace_nfs4_delegreturn(inode
, err
);
5210 case -NFS4ERR_STALE_STATEID
:
5211 case -NFS4ERR_EXPIRED
:
5215 err
= nfs4_handle_exception(server
, err
, &exception
);
5216 } while (exception
.retry
);
5220 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
5221 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
5224 * sleep, with exponential backoff, and retry the LOCK operation.
5226 static unsigned long
5227 nfs4_set_lock_task_retry(unsigned long timeout
)
5229 freezable_schedule_timeout_killable_unsafe(timeout
);
5231 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
5232 return NFS4_LOCK_MAXTIMEOUT
;
5236 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5238 struct inode
*inode
= state
->inode
;
5239 struct nfs_server
*server
= NFS_SERVER(inode
);
5240 struct nfs_client
*clp
= server
->nfs_client
;
5241 struct nfs_lockt_args arg
= {
5242 .fh
= NFS_FH(inode
),
5245 struct nfs_lockt_res res
= {
5248 struct rpc_message msg
= {
5249 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
5252 .rpc_cred
= state
->owner
->so_cred
,
5254 struct nfs4_lock_state
*lsp
;
5257 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
5258 status
= nfs4_set_lock_state(state
, request
);
5261 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5262 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5263 arg
.lock_owner
.s_dev
= server
->s_dev
;
5264 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5267 request
->fl_type
= F_UNLCK
;
5269 case -NFS4ERR_DENIED
:
5272 request
->fl_ops
->fl_release_private(request
);
5273 request
->fl_ops
= NULL
;
5278 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5280 struct nfs4_exception exception
= { };
5284 err
= _nfs4_proc_getlk(state
, cmd
, request
);
5285 trace_nfs4_get_lock(request
, state
, cmd
, err
);
5286 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
5288 } while (exception
.retry
);
5292 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5295 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5297 res
= posix_lock_file_wait(file
, fl
);
5300 res
= flock_lock_file_wait(file
, fl
);
5308 struct nfs4_unlockdata
{
5309 struct nfs_locku_args arg
;
5310 struct nfs_locku_res res
;
5311 struct nfs4_lock_state
*lsp
;
5312 struct nfs_open_context
*ctx
;
5313 struct file_lock fl
;
5314 const struct nfs_server
*server
;
5315 unsigned long timestamp
;
5318 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5319 struct nfs_open_context
*ctx
,
5320 struct nfs4_lock_state
*lsp
,
5321 struct nfs_seqid
*seqid
)
5323 struct nfs4_unlockdata
*p
;
5324 struct inode
*inode
= lsp
->ls_state
->inode
;
5326 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5329 p
->arg
.fh
= NFS_FH(inode
);
5331 p
->arg
.seqid
= seqid
;
5332 p
->res
.seqid
= seqid
;
5333 p
->arg
.stateid
= &lsp
->ls_stateid
;
5335 atomic_inc(&lsp
->ls_count
);
5336 /* Ensure we don't close file until we're done freeing locks! */
5337 p
->ctx
= get_nfs_open_context(ctx
);
5338 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5339 p
->server
= NFS_SERVER(inode
);
5343 static void nfs4_locku_release_calldata(void *data
)
5345 struct nfs4_unlockdata
*calldata
= data
;
5346 nfs_free_seqid(calldata
->arg
.seqid
);
5347 nfs4_put_lock_state(calldata
->lsp
);
5348 put_nfs_open_context(calldata
->ctx
);
5352 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5354 struct nfs4_unlockdata
*calldata
= data
;
5356 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5358 switch (task
->tk_status
) {
5360 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5361 &calldata
->res
.stateid
);
5362 renew_lease(calldata
->server
, calldata
->timestamp
);
5364 case -NFS4ERR_BAD_STATEID
:
5365 case -NFS4ERR_OLD_STATEID
:
5366 case -NFS4ERR_STALE_STATEID
:
5367 case -NFS4ERR_EXPIRED
:
5370 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
5371 rpc_restart_call_prepare(task
);
5373 nfs_release_seqid(calldata
->arg
.seqid
);
5376 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5378 struct nfs4_unlockdata
*calldata
= data
;
5380 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5382 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5383 /* Note: exit _without_ running nfs4_locku_done */
5386 calldata
->timestamp
= jiffies
;
5387 if (nfs4_setup_sequence(calldata
->server
,
5388 &calldata
->arg
.seq_args
,
5389 &calldata
->res
.seq_res
,
5391 nfs_release_seqid(calldata
->arg
.seqid
);
5394 task
->tk_action
= NULL
;
5396 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5399 static const struct rpc_call_ops nfs4_locku_ops
= {
5400 .rpc_call_prepare
= nfs4_locku_prepare
,
5401 .rpc_call_done
= nfs4_locku_done
,
5402 .rpc_release
= nfs4_locku_release_calldata
,
5405 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5406 struct nfs_open_context
*ctx
,
5407 struct nfs4_lock_state
*lsp
,
5408 struct nfs_seqid
*seqid
)
5410 struct nfs4_unlockdata
*data
;
5411 struct rpc_message msg
= {
5412 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5413 .rpc_cred
= ctx
->cred
,
5415 struct rpc_task_setup task_setup_data
= {
5416 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5417 .rpc_message
= &msg
,
5418 .callback_ops
= &nfs4_locku_ops
,
5419 .workqueue
= nfsiod_workqueue
,
5420 .flags
= RPC_TASK_ASYNC
,
5423 nfs4_state_protect(NFS_SERVER(lsp
->ls_state
->inode
)->nfs_client
,
5424 NFS_SP4_MACH_CRED_CLEANUP
, &task_setup_data
.rpc_client
, &msg
);
5426 /* Ensure this is an unlock - when canceling a lock, the
5427 * canceled lock is passed in, and it won't be an unlock.
5429 fl
->fl_type
= F_UNLCK
;
5431 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5433 nfs_free_seqid(seqid
);
5434 return ERR_PTR(-ENOMEM
);
5437 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5438 msg
.rpc_argp
= &data
->arg
;
5439 msg
.rpc_resp
= &data
->res
;
5440 task_setup_data
.callback_data
= data
;
5441 return rpc_run_task(&task_setup_data
);
5444 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5446 struct inode
*inode
= state
->inode
;
5447 struct nfs4_state_owner
*sp
= state
->owner
;
5448 struct nfs_inode
*nfsi
= NFS_I(inode
);
5449 struct nfs_seqid
*seqid
;
5450 struct nfs4_lock_state
*lsp
;
5451 struct rpc_task
*task
;
5453 unsigned char fl_flags
= request
->fl_flags
;
5455 status
= nfs4_set_lock_state(state
, request
);
5456 /* Unlock _before_ we do the RPC call */
5457 request
->fl_flags
|= FL_EXISTS
;
5458 /* Exclude nfs_delegation_claim_locks() */
5459 mutex_lock(&sp
->so_delegreturn_mutex
);
5460 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5461 down_read(&nfsi
->rwsem
);
5462 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5463 up_read(&nfsi
->rwsem
);
5464 mutex_unlock(&sp
->so_delegreturn_mutex
);
5467 up_read(&nfsi
->rwsem
);
5468 mutex_unlock(&sp
->so_delegreturn_mutex
);
5471 /* Is this a delegated lock? */
5472 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5473 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5475 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5479 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5480 status
= PTR_ERR(task
);
5483 status
= nfs4_wait_for_completion_rpc_task(task
);
5486 request
->fl_flags
= fl_flags
;
5487 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5491 struct nfs4_lockdata
{
5492 struct nfs_lock_args arg
;
5493 struct nfs_lock_res res
;
5494 struct nfs4_lock_state
*lsp
;
5495 struct nfs_open_context
*ctx
;
5496 struct file_lock fl
;
5497 unsigned long timestamp
;
5500 struct nfs_server
*server
;
5503 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5504 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5507 struct nfs4_lockdata
*p
;
5508 struct inode
*inode
= lsp
->ls_state
->inode
;
5509 struct nfs_server
*server
= NFS_SERVER(inode
);
5511 p
= kzalloc(sizeof(*p
), gfp_mask
);
5515 p
->arg
.fh
= NFS_FH(inode
);
5517 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5518 if (p
->arg
.open_seqid
== NULL
)
5520 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5521 if (p
->arg
.lock_seqid
== NULL
)
5522 goto out_free_seqid
;
5523 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5524 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5525 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5526 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5527 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5530 atomic_inc(&lsp
->ls_count
);
5531 p
->ctx
= get_nfs_open_context(ctx
);
5532 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5535 nfs_free_seqid(p
->arg
.open_seqid
);
5541 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5543 struct nfs4_lockdata
*data
= calldata
;
5544 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5546 dprintk("%s: begin!\n", __func__
);
5547 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5549 /* Do we need to do an open_to_lock_owner? */
5550 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5551 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5552 goto out_release_lock_seqid
;
5554 data
->arg
.open_stateid
= &state
->open_stateid
;
5555 data
->arg
.new_lock_owner
= 1;
5556 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5558 data
->arg
.new_lock_owner
= 0;
5559 if (!nfs4_valid_open_stateid(state
)) {
5560 data
->rpc_status
= -EBADF
;
5561 task
->tk_action
= NULL
;
5562 goto out_release_open_seqid
;
5564 data
->timestamp
= jiffies
;
5565 if (nfs4_setup_sequence(data
->server
,
5566 &data
->arg
.seq_args
,
5570 out_release_open_seqid
:
5571 nfs_release_seqid(data
->arg
.open_seqid
);
5572 out_release_lock_seqid
:
5573 nfs_release_seqid(data
->arg
.lock_seqid
);
5575 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5576 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5579 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5581 struct nfs4_lockdata
*data
= calldata
;
5583 dprintk("%s: begin!\n", __func__
);
5585 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5588 data
->rpc_status
= task
->tk_status
;
5589 if (data
->arg
.new_lock_owner
!= 0) {
5590 if (data
->rpc_status
== 0)
5591 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5595 if (data
->rpc_status
== 0) {
5596 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5597 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5598 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5601 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5604 static void nfs4_lock_release(void *calldata
)
5606 struct nfs4_lockdata
*data
= calldata
;
5608 dprintk("%s: begin!\n", __func__
);
5609 nfs_free_seqid(data
->arg
.open_seqid
);
5610 if (data
->cancelled
!= 0) {
5611 struct rpc_task
*task
;
5612 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5613 data
->arg
.lock_seqid
);
5615 rpc_put_task_async(task
);
5616 dprintk("%s: cancelling lock!\n", __func__
);
5618 nfs_free_seqid(data
->arg
.lock_seqid
);
5619 nfs4_put_lock_state(data
->lsp
);
5620 put_nfs_open_context(data
->ctx
);
5622 dprintk("%s: done!\n", __func__
);
5625 static const struct rpc_call_ops nfs4_lock_ops
= {
5626 .rpc_call_prepare
= nfs4_lock_prepare
,
5627 .rpc_call_done
= nfs4_lock_done
,
5628 .rpc_release
= nfs4_lock_release
,
5631 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5634 case -NFS4ERR_ADMIN_REVOKED
:
5635 case -NFS4ERR_BAD_STATEID
:
5636 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5637 if (new_lock_owner
!= 0 ||
5638 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5639 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5641 case -NFS4ERR_STALE_STATEID
:
5642 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5643 case -NFS4ERR_EXPIRED
:
5644 nfs4_schedule_lease_recovery(server
->nfs_client
);
5648 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5650 struct nfs4_lockdata
*data
;
5651 struct rpc_task
*task
;
5652 struct rpc_message msg
= {
5653 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5654 .rpc_cred
= state
->owner
->so_cred
,
5656 struct rpc_task_setup task_setup_data
= {
5657 .rpc_client
= NFS_CLIENT(state
->inode
),
5658 .rpc_message
= &msg
,
5659 .callback_ops
= &nfs4_lock_ops
,
5660 .workqueue
= nfsiod_workqueue
,
5661 .flags
= RPC_TASK_ASYNC
,
5665 dprintk("%s: begin!\n", __func__
);
5666 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5667 fl
->fl_u
.nfs4_fl
.owner
,
5668 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5672 data
->arg
.block
= 1;
5673 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5674 msg
.rpc_argp
= &data
->arg
;
5675 msg
.rpc_resp
= &data
->res
;
5676 task_setup_data
.callback_data
= data
;
5677 if (recovery_type
> NFS_LOCK_NEW
) {
5678 if (recovery_type
== NFS_LOCK_RECLAIM
)
5679 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5680 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5682 task
= rpc_run_task(&task_setup_data
);
5684 return PTR_ERR(task
);
5685 ret
= nfs4_wait_for_completion_rpc_task(task
);
5687 ret
= data
->rpc_status
;
5689 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5690 data
->arg
.new_lock_owner
, ret
);
5692 data
->cancelled
= 1;
5694 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5698 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5700 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5701 struct nfs4_exception exception
= {
5702 .inode
= state
->inode
,
5707 /* Cache the lock if possible... */
5708 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5710 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5711 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5712 if (err
!= -NFS4ERR_DELAY
)
5714 nfs4_handle_exception(server
, err
, &exception
);
5715 } while (exception
.retry
);
5719 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5721 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5722 struct nfs4_exception exception
= {
5723 .inode
= state
->inode
,
5727 err
= nfs4_set_lock_state(state
, request
);
5730 if (!recover_lost_locks
) {
5731 set_bit(NFS_LOCK_LOST
, &request
->fl_u
.nfs4_fl
.owner
->ls_flags
);
5735 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5737 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5738 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5742 case -NFS4ERR_GRACE
:
5743 case -NFS4ERR_DELAY
:
5744 nfs4_handle_exception(server
, err
, &exception
);
5747 } while (exception
.retry
);
5752 #if defined(CONFIG_NFS_V4_1)
5754 * nfs41_check_expired_locks - possibly free a lock stateid
5756 * @state: NFSv4 state for an inode
5758 * Returns NFS_OK if recovery for this stateid is now finished.
5759 * Otherwise a negative NFS4ERR value is returned.
5761 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5763 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5764 struct nfs4_lock_state
*lsp
;
5765 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5767 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5768 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5769 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5771 status
= nfs41_test_stateid(server
,
5774 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
5775 if (status
!= NFS_OK
) {
5776 /* Free the stateid unless the server
5777 * informs us the stateid is unrecognized. */
5778 if (status
!= -NFS4ERR_BAD_STATEID
)
5779 nfs41_free_stateid(server
,
5782 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5791 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5793 int status
= NFS_OK
;
5795 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5796 status
= nfs41_check_expired_locks(state
);
5797 if (status
!= NFS_OK
)
5798 status
= nfs4_lock_expired(state
, request
);
5803 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5805 struct nfs4_state_owner
*sp
= state
->owner
;
5806 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5807 unsigned char fl_flags
= request
->fl_flags
;
5809 int status
= -ENOLCK
;
5811 if ((fl_flags
& FL_POSIX
) &&
5812 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5814 /* Is this a delegated open? */
5815 status
= nfs4_set_lock_state(state
, request
);
5818 request
->fl_flags
|= FL_ACCESS
;
5819 status
= do_vfs_lock(request
->fl_file
, request
);
5822 down_read(&nfsi
->rwsem
);
5823 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5824 /* Yes: cache locks! */
5825 /* ...but avoid races with delegation recall... */
5826 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5827 status
= do_vfs_lock(request
->fl_file
, request
);
5830 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5831 up_read(&nfsi
->rwsem
);
5832 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5835 down_read(&nfsi
->rwsem
);
5836 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5837 status
= -NFS4ERR_DELAY
;
5840 /* Note: we always want to sleep here! */
5841 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5842 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5843 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5844 "manager!\n", __func__
);
5846 up_read(&nfsi
->rwsem
);
5848 request
->fl_flags
= fl_flags
;
5852 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5854 struct nfs4_exception exception
= {
5856 .inode
= state
->inode
,
5861 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5862 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5863 if (err
== -NFS4ERR_DENIED
)
5865 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5867 } while (exception
.retry
);
5872 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5874 struct nfs_open_context
*ctx
;
5875 struct nfs4_state
*state
;
5876 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5879 /* verify open state */
5880 ctx
= nfs_file_open_context(filp
);
5883 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5886 if (IS_GETLK(cmd
)) {
5888 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5892 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5895 if (request
->fl_type
== F_UNLCK
) {
5897 return nfs4_proc_unlck(state
, cmd
, request
);
5904 * Don't rely on the VFS having checked the file open mode,
5905 * since it won't do this for flock() locks.
5907 switch (request
->fl_type
) {
5909 if (!(filp
->f_mode
& FMODE_READ
))
5913 if (!(filp
->f_mode
& FMODE_WRITE
))
5918 status
= nfs4_proc_setlk(state
, cmd
, request
);
5919 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5921 timeout
= nfs4_set_lock_task_retry(timeout
);
5922 status
= -ERESTARTSYS
;
5925 } while(status
< 0);
5929 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5931 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5934 err
= nfs4_set_lock_state(state
, fl
);
5937 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5938 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5941 struct nfs_release_lockowner_data
{
5942 struct nfs4_lock_state
*lsp
;
5943 struct nfs_server
*server
;
5944 struct nfs_release_lockowner_args args
;
5945 struct nfs_release_lockowner_res res
;
5946 unsigned long timestamp
;
5949 static void nfs4_release_lockowner_prepare(struct rpc_task
*task
, void *calldata
)
5951 struct nfs_release_lockowner_data
*data
= calldata
;
5952 struct nfs_server
*server
= data
->server
;
5953 nfs40_setup_sequence(server
, &data
->args
.seq_args
,
5954 &data
->res
.seq_res
, task
);
5955 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5956 data
->timestamp
= jiffies
;
5959 static void nfs4_release_lockowner_done(struct rpc_task
*task
, void *calldata
)
5961 struct nfs_release_lockowner_data
*data
= calldata
;
5962 struct nfs_server
*server
= data
->server
;
5964 nfs40_sequence_done(task
, &data
->res
.seq_res
);
5966 switch (task
->tk_status
) {
5968 renew_lease(server
, data
->timestamp
);
5970 case -NFS4ERR_STALE_CLIENTID
:
5971 case -NFS4ERR_EXPIRED
:
5972 nfs4_schedule_lease_recovery(server
->nfs_client
);
5974 case -NFS4ERR_LEASE_MOVED
:
5975 case -NFS4ERR_DELAY
:
5976 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
)
5977 rpc_restart_call_prepare(task
);
5981 static void nfs4_release_lockowner_release(void *calldata
)
5983 struct nfs_release_lockowner_data
*data
= calldata
;
5984 nfs4_free_lock_state(data
->server
, data
->lsp
);
5988 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
5989 .rpc_call_prepare
= nfs4_release_lockowner_prepare
,
5990 .rpc_call_done
= nfs4_release_lockowner_done
,
5991 .rpc_release
= nfs4_release_lockowner_release
,
5995 nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
5997 struct nfs_release_lockowner_data
*data
;
5998 struct rpc_message msg
= {
5999 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
6002 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
6005 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
6009 data
->server
= server
;
6010 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
6011 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6012 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
6014 msg
.rpc_argp
= &data
->args
;
6015 msg
.rpc_resp
= &data
->res
;
6016 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
6017 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
6020 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
6022 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
6023 const void *buf
, size_t buflen
,
6024 int flags
, int type
)
6026 if (strcmp(key
, "") != 0)
6029 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
6032 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
6033 void *buf
, size_t buflen
, int type
)
6035 if (strcmp(key
, "") != 0)
6038 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
6041 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
6042 size_t list_len
, const char *name
,
6043 size_t name_len
, int type
)
6045 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
6047 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
6050 if (list
&& len
<= list_len
)
6051 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
6055 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
6056 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
6058 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
6061 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
6062 const void *buf
, size_t buflen
,
6063 int flags
, int type
)
6065 if (security_ismaclabel(key
))
6066 return nfs4_set_security_label(dentry
, buf
, buflen
);
6071 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
6072 void *buf
, size_t buflen
, int type
)
6074 if (security_ismaclabel(key
))
6075 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
6079 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
6080 size_t list_len
, const char *name
,
6081 size_t name_len
, int type
)
6085 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
6086 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
6087 if (list
&& len
<= list_len
)
6088 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
6093 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
6094 .prefix
= XATTR_SECURITY_PREFIX
,
6095 .list
= nfs4_xattr_list_nfs4_label
,
6096 .get
= nfs4_xattr_get_nfs4_label
,
6097 .set
= nfs4_xattr_set_nfs4_label
,
6103 * nfs_fhget will use either the mounted_on_fileid or the fileid
6105 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
6107 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
6108 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
6109 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
6110 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
6113 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
6114 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
6115 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
6119 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
6120 const struct qstr
*name
,
6121 struct nfs4_fs_locations
*fs_locations
,
6124 struct nfs_server
*server
= NFS_SERVER(dir
);
6126 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6128 struct nfs4_fs_locations_arg args
= {
6129 .dir_fh
= NFS_FH(dir
),
6134 struct nfs4_fs_locations_res res
= {
6135 .fs_locations
= fs_locations
,
6137 struct rpc_message msg
= {
6138 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6144 dprintk("%s: start\n", __func__
);
6146 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
6147 * is not supported */
6148 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
6149 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
6151 bitmask
[0] |= FATTR4_WORD0_FILEID
;
6153 nfs_fattr_init(&fs_locations
->fattr
);
6154 fs_locations
->server
= server
;
6155 fs_locations
->nlocations
= 0;
6156 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
6157 dprintk("%s: returned status = %d\n", __func__
, status
);
6161 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
6162 const struct qstr
*name
,
6163 struct nfs4_fs_locations
*fs_locations
,
6166 struct nfs4_exception exception
= { };
6169 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
6170 fs_locations
, page
);
6171 trace_nfs4_get_fs_locations(dir
, name
, err
);
6172 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6174 } while (exception
.retry
);
6179 * This operation also signals the server that this client is
6180 * performing migration recovery. The server can stop returning
6181 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
6182 * appended to this compound to identify the client ID which is
6183 * performing recovery.
6185 static int _nfs40_proc_get_locations(struct inode
*inode
,
6186 struct nfs4_fs_locations
*locations
,
6187 struct page
*page
, struct rpc_cred
*cred
)
6189 struct nfs_server
*server
= NFS_SERVER(inode
);
6190 struct rpc_clnt
*clnt
= server
->client
;
6192 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6194 struct nfs4_fs_locations_arg args
= {
6195 .clientid
= server
->nfs_client
->cl_clientid
,
6196 .fh
= NFS_FH(inode
),
6199 .migration
= 1, /* skip LOOKUP */
6200 .renew
= 1, /* append RENEW */
6202 struct nfs4_fs_locations_res res
= {
6203 .fs_locations
= locations
,
6207 struct rpc_message msg
= {
6208 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6213 unsigned long now
= jiffies
;
6216 nfs_fattr_init(&locations
->fattr
);
6217 locations
->server
= server
;
6218 locations
->nlocations
= 0;
6220 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6221 nfs4_set_sequence_privileged(&args
.seq_args
);
6222 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6223 &args
.seq_args
, &res
.seq_res
);
6227 renew_lease(server
, now
);
6231 #ifdef CONFIG_NFS_V4_1
6234 * This operation also signals the server that this client is
6235 * performing migration recovery. The server can stop asserting
6236 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
6237 * performing this operation is identified in the SEQUENCE
6238 * operation in this compound.
6240 * When the client supports GETATTR(fs_locations_info), it can
6241 * be plumbed in here.
6243 static int _nfs41_proc_get_locations(struct inode
*inode
,
6244 struct nfs4_fs_locations
*locations
,
6245 struct page
*page
, struct rpc_cred
*cred
)
6247 struct nfs_server
*server
= NFS_SERVER(inode
);
6248 struct rpc_clnt
*clnt
= server
->client
;
6250 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6252 struct nfs4_fs_locations_arg args
= {
6253 .fh
= NFS_FH(inode
),
6256 .migration
= 1, /* skip LOOKUP */
6258 struct nfs4_fs_locations_res res
= {
6259 .fs_locations
= locations
,
6262 struct rpc_message msg
= {
6263 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6270 nfs_fattr_init(&locations
->fattr
);
6271 locations
->server
= server
;
6272 locations
->nlocations
= 0;
6274 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6275 nfs4_set_sequence_privileged(&args
.seq_args
);
6276 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6277 &args
.seq_args
, &res
.seq_res
);
6278 if (status
== NFS4_OK
&&
6279 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6280 status
= -NFS4ERR_LEASE_MOVED
;
6284 #endif /* CONFIG_NFS_V4_1 */
6287 * nfs4_proc_get_locations - discover locations for a migrated FSID
6288 * @inode: inode on FSID that is migrating
6289 * @locations: result of query
6291 * @cred: credential to use for this operation
6293 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
6294 * operation failed, or a negative errno if a local error occurred.
6296 * On success, "locations" is filled in, but if the server has
6297 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
6300 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
6301 * from this client that require migration recovery.
6303 int nfs4_proc_get_locations(struct inode
*inode
,
6304 struct nfs4_fs_locations
*locations
,
6305 struct page
*page
, struct rpc_cred
*cred
)
6307 struct nfs_server
*server
= NFS_SERVER(inode
);
6308 struct nfs_client
*clp
= server
->nfs_client
;
6309 const struct nfs4_mig_recovery_ops
*ops
=
6310 clp
->cl_mvops
->mig_recovery_ops
;
6311 struct nfs4_exception exception
= { };
6314 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6315 (unsigned long long)server
->fsid
.major
,
6316 (unsigned long long)server
->fsid
.minor
,
6318 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6321 status
= ops
->get_locations(inode
, locations
, page
, cred
);
6322 if (status
!= -NFS4ERR_DELAY
)
6324 nfs4_handle_exception(server
, status
, &exception
);
6325 } while (exception
.retry
);
6330 * This operation also signals the server that this client is
6331 * performing "lease moved" recovery. The server can stop
6332 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
6333 * is appended to this compound to identify the client ID which is
6334 * performing recovery.
6336 static int _nfs40_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6338 struct nfs_server
*server
= NFS_SERVER(inode
);
6339 struct nfs_client
*clp
= NFS_SERVER(inode
)->nfs_client
;
6340 struct rpc_clnt
*clnt
= server
->client
;
6341 struct nfs4_fsid_present_arg args
= {
6342 .fh
= NFS_FH(inode
),
6343 .clientid
= clp
->cl_clientid
,
6344 .renew
= 1, /* append RENEW */
6346 struct nfs4_fsid_present_res res
= {
6349 struct rpc_message msg
= {
6350 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6355 unsigned long now
= jiffies
;
6358 res
.fh
= nfs_alloc_fhandle();
6362 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6363 nfs4_set_sequence_privileged(&args
.seq_args
);
6364 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6365 &args
.seq_args
, &res
.seq_res
);
6366 nfs_free_fhandle(res
.fh
);
6370 do_renew_lease(clp
, now
);
6374 #ifdef CONFIG_NFS_V4_1
6377 * This operation also signals the server that this client is
6378 * performing "lease moved" recovery. The server can stop asserting
6379 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
6380 * this operation is identified in the SEQUENCE operation in this
6383 static int _nfs41_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6385 struct nfs_server
*server
= NFS_SERVER(inode
);
6386 struct rpc_clnt
*clnt
= server
->client
;
6387 struct nfs4_fsid_present_arg args
= {
6388 .fh
= NFS_FH(inode
),
6390 struct nfs4_fsid_present_res res
= {
6392 struct rpc_message msg
= {
6393 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6400 res
.fh
= nfs_alloc_fhandle();
6404 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6405 nfs4_set_sequence_privileged(&args
.seq_args
);
6406 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6407 &args
.seq_args
, &res
.seq_res
);
6408 nfs_free_fhandle(res
.fh
);
6409 if (status
== NFS4_OK
&&
6410 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6411 status
= -NFS4ERR_LEASE_MOVED
;
6415 #endif /* CONFIG_NFS_V4_1 */
6418 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
6419 * @inode: inode on FSID to check
6420 * @cred: credential to use for this operation
6422 * Server indicates whether the FSID is present, moved, or not
6423 * recognized. This operation is necessary to clear a LEASE_MOVED
6424 * condition for this client ID.
6426 * Returns NFS4_OK if the FSID is present on this server,
6427 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
6428 * NFS4ERR code if some error occurred on the server, or a
6429 * negative errno if a local failure occurred.
6431 int nfs4_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6433 struct nfs_server
*server
= NFS_SERVER(inode
);
6434 struct nfs_client
*clp
= server
->nfs_client
;
6435 const struct nfs4_mig_recovery_ops
*ops
=
6436 clp
->cl_mvops
->mig_recovery_ops
;
6437 struct nfs4_exception exception
= { };
6440 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6441 (unsigned long long)server
->fsid
.major
,
6442 (unsigned long long)server
->fsid
.minor
,
6444 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6447 status
= ops
->fsid_present(inode
, cred
);
6448 if (status
!= -NFS4ERR_DELAY
)
6450 nfs4_handle_exception(server
, status
, &exception
);
6451 } while (exception
.retry
);
6456 * If 'use_integrity' is true and the state managment nfs_client
6457 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
6458 * and the machine credential as per RFC3530bis and RFC5661 Security
6459 * Considerations sections. Otherwise, just use the user cred with the
6460 * filesystem's rpc_client.
6462 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
6465 struct nfs4_secinfo_arg args
= {
6466 .dir_fh
= NFS_FH(dir
),
6469 struct nfs4_secinfo_res res
= {
6472 struct rpc_message msg
= {
6473 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
6477 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
6478 struct rpc_cred
*cred
= NULL
;
6480 if (use_integrity
) {
6481 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
6482 cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
6483 msg
.rpc_cred
= cred
;
6486 dprintk("NFS call secinfo %s\n", name
->name
);
6488 nfs4_state_protect(NFS_SERVER(dir
)->nfs_client
,
6489 NFS_SP4_MACH_CRED_SECINFO
, &clnt
, &msg
);
6491 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
6493 dprintk("NFS reply secinfo: %d\n", status
);
6501 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
6502 struct nfs4_secinfo_flavors
*flavors
)
6504 struct nfs4_exception exception
= { };
6507 err
= -NFS4ERR_WRONGSEC
;
6509 /* try to use integrity protection with machine cred */
6510 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
6511 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
6514 * if unable to use integrity protection, or SECINFO with
6515 * integrity protection returns NFS4ERR_WRONGSEC (which is
6516 * disallowed by spec, but exists in deployed servers) use
6517 * the current filesystem's rpc_client and the user cred.
6519 if (err
== -NFS4ERR_WRONGSEC
)
6520 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
6522 trace_nfs4_secinfo(dir
, name
, err
);
6523 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6525 } while (exception
.retry
);
6529 #ifdef CONFIG_NFS_V4_1
6531 * Check the exchange flags returned by the server for invalid flags, having
6532 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
6535 static int nfs4_check_cl_exchange_flags(u32 flags
)
6537 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
6539 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
6540 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
6542 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
6546 return -NFS4ERR_INVAL
;
6550 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
6551 struct nfs41_server_scope
*b
)
6553 if (a
->server_scope_sz
== b
->server_scope_sz
&&
6554 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
6561 * nfs4_proc_bind_conn_to_session()
6563 * The 4.1 client currently uses the same TCP connection for the
6564 * fore and backchannel.
6566 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6569 struct nfs41_bind_conn_to_session_res res
;
6570 struct rpc_message msg
= {
6572 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
6578 dprintk("--> %s\n", __func__
);
6580 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
6581 if (unlikely(res
.session
== NULL
)) {
6586 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6587 trace_nfs4_bind_conn_to_session(clp
, status
);
6589 if (memcmp(res
.session
->sess_id
.data
,
6590 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
6591 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
6595 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
6596 dprintk("NFS: %s: Unexpected direction from server\n",
6601 if (res
.use_conn_in_rdma_mode
) {
6602 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6611 dprintk("<-- %s status= %d\n", __func__
, status
);
6616 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
6617 * and operations we'd like to see to enable certain features in the allow map
6619 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request
= {
6620 .how
= SP4_MACH_CRED
,
6621 .enforce
.u
.words
= {
6622 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6623 1 << (OP_EXCHANGE_ID
- 32) |
6624 1 << (OP_CREATE_SESSION
- 32) |
6625 1 << (OP_DESTROY_SESSION
- 32) |
6626 1 << (OP_DESTROY_CLIENTID
- 32)
6629 [0] = 1 << (OP_CLOSE
) |
6632 [1] = 1 << (OP_SECINFO
- 32) |
6633 1 << (OP_SECINFO_NO_NAME
- 32) |
6634 1 << (OP_TEST_STATEID
- 32) |
6635 1 << (OP_FREE_STATEID
- 32) |
6636 1 << (OP_WRITE
- 32)
6641 * Select the state protection mode for client `clp' given the server results
6642 * from exchange_id in `sp'.
6644 * Returns 0 on success, negative errno otherwise.
6646 static int nfs4_sp4_select_mode(struct nfs_client
*clp
,
6647 struct nfs41_state_protection
*sp
)
6649 static const u32 supported_enforce
[NFS4_OP_MAP_NUM_WORDS
] = {
6650 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6651 1 << (OP_EXCHANGE_ID
- 32) |
6652 1 << (OP_CREATE_SESSION
- 32) |
6653 1 << (OP_DESTROY_SESSION
- 32) |
6654 1 << (OP_DESTROY_CLIENTID
- 32)
6658 if (sp
->how
== SP4_MACH_CRED
) {
6659 /* Print state protect result */
6660 dfprintk(MOUNT
, "Server SP4_MACH_CRED support:\n");
6661 for (i
= 0; i
<= LAST_NFS4_OP
; i
++) {
6662 if (test_bit(i
, sp
->enforce
.u
.longs
))
6663 dfprintk(MOUNT
, " enforce op %d\n", i
);
6664 if (test_bit(i
, sp
->allow
.u
.longs
))
6665 dfprintk(MOUNT
, " allow op %d\n", i
);
6668 /* make sure nothing is on enforce list that isn't supported */
6669 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++) {
6670 if (sp
->enforce
.u
.words
[i
] & ~supported_enforce
[i
]) {
6671 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6677 * Minimal mode - state operations are allowed to use machine
6678 * credential. Note this already happens by default, so the
6679 * client doesn't have to do anything more than the negotiation.
6681 * NOTE: we don't care if EXCHANGE_ID is in the list -
6682 * we're already using the machine cred for exchange_id
6683 * and will never use a different cred.
6685 if (test_bit(OP_BIND_CONN_TO_SESSION
, sp
->enforce
.u
.longs
) &&
6686 test_bit(OP_CREATE_SESSION
, sp
->enforce
.u
.longs
) &&
6687 test_bit(OP_DESTROY_SESSION
, sp
->enforce
.u
.longs
) &&
6688 test_bit(OP_DESTROY_CLIENTID
, sp
->enforce
.u
.longs
)) {
6689 dfprintk(MOUNT
, "sp4_mach_cred:\n");
6690 dfprintk(MOUNT
, " minimal mode enabled\n");
6691 set_bit(NFS_SP4_MACH_CRED_MINIMAL
, &clp
->cl_sp4_flags
);
6693 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6697 if (test_bit(OP_CLOSE
, sp
->allow
.u
.longs
) &&
6698 test_bit(OP_LOCKU
, sp
->allow
.u
.longs
)) {
6699 dfprintk(MOUNT
, " cleanup mode enabled\n");
6700 set_bit(NFS_SP4_MACH_CRED_CLEANUP
, &clp
->cl_sp4_flags
);
6703 if (test_bit(OP_SECINFO
, sp
->allow
.u
.longs
) &&
6704 test_bit(OP_SECINFO_NO_NAME
, sp
->allow
.u
.longs
)) {
6705 dfprintk(MOUNT
, " secinfo mode enabled\n");
6706 set_bit(NFS_SP4_MACH_CRED_SECINFO
, &clp
->cl_sp4_flags
);
6709 if (test_bit(OP_TEST_STATEID
, sp
->allow
.u
.longs
) &&
6710 test_bit(OP_FREE_STATEID
, sp
->allow
.u
.longs
)) {
6711 dfprintk(MOUNT
, " stateid mode enabled\n");
6712 set_bit(NFS_SP4_MACH_CRED_STATEID
, &clp
->cl_sp4_flags
);
6715 if (test_bit(OP_WRITE
, sp
->allow
.u
.longs
)) {
6716 dfprintk(MOUNT
, " write mode enabled\n");
6717 set_bit(NFS_SP4_MACH_CRED_WRITE
, &clp
->cl_sp4_flags
);
6720 if (test_bit(OP_COMMIT
, sp
->allow
.u
.longs
)) {
6721 dfprintk(MOUNT
, " commit mode enabled\n");
6722 set_bit(NFS_SP4_MACH_CRED_COMMIT
, &clp
->cl_sp4_flags
);
6730 * _nfs4_proc_exchange_id()
6732 * Wrapper for EXCHANGE_ID operation.
6734 static int _nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
,
6737 nfs4_verifier verifier
;
6738 struct nfs41_exchange_id_args args
= {
6739 .verifier
= &verifier
,
6741 #ifdef CONFIG_NFS_V4_1_MIGRATION
6742 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6743 EXCHGID4_FLAG_BIND_PRINC_STATEID
|
6744 EXCHGID4_FLAG_SUPP_MOVED_MIGR
,
6746 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6747 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
6750 struct nfs41_exchange_id_res res
= {
6754 struct rpc_message msg
= {
6755 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
6761 nfs4_init_boot_verifier(clp
, &verifier
);
6762 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
6764 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6765 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
6766 args
.id_len
, args
.id
);
6768 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6770 if (unlikely(res
.server_owner
== NULL
)) {
6775 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6777 if (unlikely(res
.server_scope
== NULL
)) {
6779 goto out_server_owner
;
6782 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6783 if (unlikely(res
.impl_id
== NULL
)) {
6785 goto out_server_scope
;
6790 args
.state_protect
.how
= SP4_NONE
;
6794 args
.state_protect
= nfs4_sp4_mach_cred_request
;
6801 goto out_server_scope
;
6804 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6805 trace_nfs4_exchange_id(clp
, status
);
6807 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6810 status
= nfs4_sp4_select_mode(clp
, &res
.state_protect
);
6813 clp
->cl_clientid
= res
.clientid
;
6814 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6815 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6816 clp
->cl_seqid
= res
.seqid
;
6818 kfree(clp
->cl_serverowner
);
6819 clp
->cl_serverowner
= res
.server_owner
;
6820 res
.server_owner
= NULL
;
6822 /* use the most recent implementation id */
6823 kfree(clp
->cl_implid
);
6824 clp
->cl_implid
= res
.impl_id
;
6826 if (clp
->cl_serverscope
!= NULL
&&
6827 !nfs41_same_server_scope(clp
->cl_serverscope
,
6828 res
.server_scope
)) {
6829 dprintk("%s: server_scope mismatch detected\n",
6831 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6832 kfree(clp
->cl_serverscope
);
6833 clp
->cl_serverscope
= NULL
;
6836 if (clp
->cl_serverscope
== NULL
) {
6837 clp
->cl_serverscope
= res
.server_scope
;
6844 kfree(res
.server_owner
);
6846 kfree(res
.server_scope
);
6848 if (clp
->cl_implid
!= NULL
)
6849 dprintk("NFS reply exchange_id: Server Implementation ID: "
6850 "domain: %s, name: %s, date: %llu,%u\n",
6851 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6852 clp
->cl_implid
->date
.seconds
,
6853 clp
->cl_implid
->date
.nseconds
);
6854 dprintk("NFS reply exchange_id: %d\n", status
);
6859 * nfs4_proc_exchange_id()
6861 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6863 * Since the clientid has expired, all compounds using sessions
6864 * associated with the stale clientid will be returning
6865 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6866 * be in some phase of session reset.
6868 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
6870 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6872 rpc_authflavor_t authflavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
6875 /* try SP4_MACH_CRED if krb5i/p */
6876 if (authflavor
== RPC_AUTH_GSS_KRB5I
||
6877 authflavor
== RPC_AUTH_GSS_KRB5P
) {
6878 status
= _nfs4_proc_exchange_id(clp
, cred
, SP4_MACH_CRED
);
6884 return _nfs4_proc_exchange_id(clp
, cred
, SP4_NONE
);
6887 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6888 struct rpc_cred
*cred
)
6890 struct rpc_message msg
= {
6891 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6897 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6898 trace_nfs4_destroy_clientid(clp
, status
);
6900 dprintk("NFS: Got error %d from the server %s on "
6901 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6905 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6906 struct rpc_cred
*cred
)
6911 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6912 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6914 case -NFS4ERR_DELAY
:
6915 case -NFS4ERR_CLIENTID_BUSY
:
6925 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6927 struct rpc_cred
*cred
;
6930 if (clp
->cl_mvops
->minor_version
< 1)
6932 if (clp
->cl_exchange_flags
== 0)
6934 if (clp
->cl_preserve_clid
)
6936 cred
= nfs4_get_clid_cred(clp
);
6937 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6942 case -NFS4ERR_STALE_CLIENTID
:
6943 clp
->cl_exchange_flags
= 0;
6949 struct nfs4_get_lease_time_data
{
6950 struct nfs4_get_lease_time_args
*args
;
6951 struct nfs4_get_lease_time_res
*res
;
6952 struct nfs_client
*clp
;
6955 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6958 struct nfs4_get_lease_time_data
*data
=
6959 (struct nfs4_get_lease_time_data
*)calldata
;
6961 dprintk("--> %s\n", __func__
);
6962 /* just setup sequence, do not trigger session recovery
6963 since we're invoked within one */
6964 nfs41_setup_sequence(data
->clp
->cl_session
,
6965 &data
->args
->la_seq_args
,
6966 &data
->res
->lr_seq_res
,
6968 dprintk("<-- %s\n", __func__
);
6972 * Called from nfs4_state_manager thread for session setup, so don't recover
6973 * from sequence operation or clientid errors.
6975 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
6977 struct nfs4_get_lease_time_data
*data
=
6978 (struct nfs4_get_lease_time_data
*)calldata
;
6980 dprintk("--> %s\n", __func__
);
6981 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
6983 switch (task
->tk_status
) {
6984 case -NFS4ERR_DELAY
:
6985 case -NFS4ERR_GRACE
:
6986 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
6987 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
6988 task
->tk_status
= 0;
6990 case -NFS4ERR_RETRY_UNCACHED_REP
:
6991 rpc_restart_call_prepare(task
);
6994 dprintk("<-- %s\n", __func__
);
6997 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
6998 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
6999 .rpc_call_done
= nfs4_get_lease_time_done
,
7002 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
7004 struct rpc_task
*task
;
7005 struct nfs4_get_lease_time_args args
;
7006 struct nfs4_get_lease_time_res res
= {
7007 .lr_fsinfo
= fsinfo
,
7009 struct nfs4_get_lease_time_data data
= {
7014 struct rpc_message msg
= {
7015 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
7019 struct rpc_task_setup task_setup
= {
7020 .rpc_client
= clp
->cl_rpcclient
,
7021 .rpc_message
= &msg
,
7022 .callback_ops
= &nfs4_get_lease_time_ops
,
7023 .callback_data
= &data
,
7024 .flags
= RPC_TASK_TIMEOUT
,
7028 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
7029 nfs4_set_sequence_privileged(&args
.la_seq_args
);
7030 dprintk("--> %s\n", __func__
);
7031 task
= rpc_run_task(&task_setup
);
7034 status
= PTR_ERR(task
);
7036 status
= task
->tk_status
;
7039 dprintk("<-- %s return %d\n", __func__
, status
);
7045 * Initialize the values to be used by the client in CREATE_SESSION
7046 * If nfs4_init_session set the fore channel request and response sizes,
7049 * Set the back channel max_resp_sz_cached to zero to force the client to
7050 * always set csa_cachethis to FALSE because the current implementation
7051 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
7053 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
7055 unsigned int max_rqst_sz
, max_resp_sz
;
7057 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
7058 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
7060 /* Fore channel attributes */
7061 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
7062 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
7063 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
7064 args
->fc_attrs
.max_reqs
= max_session_slots
;
7066 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
7067 "max_ops=%u max_reqs=%u\n",
7069 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
7070 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
7072 /* Back channel attributes */
7073 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
7074 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
7075 args
->bc_attrs
.max_resp_sz_cached
= 0;
7076 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
7077 args
->bc_attrs
.max_reqs
= 1;
7079 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
7080 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
7082 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
7083 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
7084 args
->bc_attrs
.max_reqs
);
7087 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
7089 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
7090 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
7092 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
7095 * Our requested max_ops is the minimum we need; we're not
7096 * prepared to break up compounds into smaller pieces than that.
7097 * So, no point even trying to continue if the server won't
7100 if (rcvd
->max_ops
< sent
->max_ops
)
7102 if (rcvd
->max_reqs
== 0)
7104 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
7105 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
7109 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
7111 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
7112 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
7114 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
7116 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
7118 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
7120 /* These would render the backchannel useless: */
7121 if (rcvd
->max_ops
!= sent
->max_ops
)
7123 if (rcvd
->max_reqs
!= sent
->max_reqs
)
7128 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
7129 struct nfs4_session
*session
)
7133 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
7136 return nfs4_verify_back_channel_attrs(args
, session
);
7139 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
7140 struct rpc_cred
*cred
)
7142 struct nfs4_session
*session
= clp
->cl_session
;
7143 struct nfs41_create_session_args args
= {
7145 .cb_program
= NFS4_CALLBACK
,
7147 struct nfs41_create_session_res res
= {
7150 struct rpc_message msg
= {
7151 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
7158 nfs4_init_channel_attrs(&args
);
7159 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
7161 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7162 trace_nfs4_create_session(clp
, status
);
7165 /* Verify the session's negotiated channel_attrs values */
7166 status
= nfs4_verify_channel_attrs(&args
, session
);
7167 /* Increment the clientid slot sequence id */
7175 * Issues a CREATE_SESSION operation to the server.
7176 * It is the responsibility of the caller to verify the session is
7177 * expired before calling this routine.
7179 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7183 struct nfs4_session
*session
= clp
->cl_session
;
7185 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
7187 status
= _nfs4_proc_create_session(clp
, cred
);
7191 /* Init or reset the session slot tables */
7192 status
= nfs4_setup_session_slot_tables(session
);
7193 dprintk("slot table setup returned %d\n", status
);
7197 ptr
= (unsigned *)&session
->sess_id
.data
[0];
7198 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
7199 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
7201 dprintk("<-- %s\n", __func__
);
7206 * Issue the over-the-wire RPC DESTROY_SESSION.
7207 * The caller must serialize access to this routine.
7209 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
7210 struct rpc_cred
*cred
)
7212 struct rpc_message msg
= {
7213 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
7214 .rpc_argp
= session
,
7219 dprintk("--> nfs4_proc_destroy_session\n");
7221 /* session is still being setup */
7222 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
7225 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7226 trace_nfs4_destroy_session(session
->clp
, status
);
7229 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
7230 "Session has been destroyed regardless...\n", status
);
7232 dprintk("<-- nfs4_proc_destroy_session\n");
7237 * Renew the cl_session lease.
7239 struct nfs4_sequence_data
{
7240 struct nfs_client
*clp
;
7241 struct nfs4_sequence_args args
;
7242 struct nfs4_sequence_res res
;
7245 static void nfs41_sequence_release(void *data
)
7247 struct nfs4_sequence_data
*calldata
= data
;
7248 struct nfs_client
*clp
= calldata
->clp
;
7250 if (atomic_read(&clp
->cl_count
) > 1)
7251 nfs4_schedule_state_renewal(clp
);
7252 nfs_put_client(clp
);
7256 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7258 switch(task
->tk_status
) {
7259 case -NFS4ERR_DELAY
:
7260 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7263 nfs4_schedule_lease_recovery(clp
);
7268 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
7270 struct nfs4_sequence_data
*calldata
= data
;
7271 struct nfs_client
*clp
= calldata
->clp
;
7273 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
7276 trace_nfs4_sequence(clp
, task
->tk_status
);
7277 if (task
->tk_status
< 0) {
7278 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
7279 if (atomic_read(&clp
->cl_count
) == 1)
7282 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
7283 rpc_restart_call_prepare(task
);
7287 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
7289 dprintk("<-- %s\n", __func__
);
7292 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
7294 struct nfs4_sequence_data
*calldata
= data
;
7295 struct nfs_client
*clp
= calldata
->clp
;
7296 struct nfs4_sequence_args
*args
;
7297 struct nfs4_sequence_res
*res
;
7299 args
= task
->tk_msg
.rpc_argp
;
7300 res
= task
->tk_msg
.rpc_resp
;
7302 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
7305 static const struct rpc_call_ops nfs41_sequence_ops
= {
7306 .rpc_call_done
= nfs41_sequence_call_done
,
7307 .rpc_call_prepare
= nfs41_sequence_prepare
,
7308 .rpc_release
= nfs41_sequence_release
,
7311 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
7312 struct rpc_cred
*cred
,
7315 struct nfs4_sequence_data
*calldata
;
7316 struct rpc_message msg
= {
7317 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
7320 struct rpc_task_setup task_setup_data
= {
7321 .rpc_client
= clp
->cl_rpcclient
,
7322 .rpc_message
= &msg
,
7323 .callback_ops
= &nfs41_sequence_ops
,
7324 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
7327 if (!atomic_inc_not_zero(&clp
->cl_count
))
7328 return ERR_PTR(-EIO
);
7329 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7330 if (calldata
== NULL
) {
7331 nfs_put_client(clp
);
7332 return ERR_PTR(-ENOMEM
);
7334 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0);
7336 nfs4_set_sequence_privileged(&calldata
->args
);
7337 msg
.rpc_argp
= &calldata
->args
;
7338 msg
.rpc_resp
= &calldata
->res
;
7339 calldata
->clp
= clp
;
7340 task_setup_data
.callback_data
= calldata
;
7342 return rpc_run_task(&task_setup_data
);
7345 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
7347 struct rpc_task
*task
;
7350 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
7352 task
= _nfs41_proc_sequence(clp
, cred
, false);
7354 ret
= PTR_ERR(task
);
7356 rpc_put_task_async(task
);
7357 dprintk("<-- %s status=%d\n", __func__
, ret
);
7361 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7363 struct rpc_task
*task
;
7366 task
= _nfs41_proc_sequence(clp
, cred
, true);
7368 ret
= PTR_ERR(task
);
7371 ret
= rpc_wait_for_completion_task(task
);
7373 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
7375 if (task
->tk_status
== 0)
7376 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
7377 ret
= task
->tk_status
;
7381 dprintk("<-- %s status=%d\n", __func__
, ret
);
7385 struct nfs4_reclaim_complete_data
{
7386 struct nfs_client
*clp
;
7387 struct nfs41_reclaim_complete_args arg
;
7388 struct nfs41_reclaim_complete_res res
;
7391 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
7393 struct nfs4_reclaim_complete_data
*calldata
= data
;
7395 nfs41_setup_sequence(calldata
->clp
->cl_session
,
7396 &calldata
->arg
.seq_args
,
7397 &calldata
->res
.seq_res
,
7401 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7403 switch(task
->tk_status
) {
7405 case -NFS4ERR_COMPLETE_ALREADY
:
7406 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
7408 case -NFS4ERR_DELAY
:
7409 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7411 case -NFS4ERR_RETRY_UNCACHED_REP
:
7414 nfs4_schedule_lease_recovery(clp
);
7419 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
7421 struct nfs4_reclaim_complete_data
*calldata
= data
;
7422 struct nfs_client
*clp
= calldata
->clp
;
7423 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
7425 dprintk("--> %s\n", __func__
);
7426 if (!nfs41_sequence_done(task
, res
))
7429 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
7430 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
7431 rpc_restart_call_prepare(task
);
7434 dprintk("<-- %s\n", __func__
);
7437 static void nfs4_free_reclaim_complete_data(void *data
)
7439 struct nfs4_reclaim_complete_data
*calldata
= data
;
7444 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
7445 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
7446 .rpc_call_done
= nfs4_reclaim_complete_done
,
7447 .rpc_release
= nfs4_free_reclaim_complete_data
,
7451 * Issue a global reclaim complete.
7453 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
7454 struct rpc_cred
*cred
)
7456 struct nfs4_reclaim_complete_data
*calldata
;
7457 struct rpc_task
*task
;
7458 struct rpc_message msg
= {
7459 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
7462 struct rpc_task_setup task_setup_data
= {
7463 .rpc_client
= clp
->cl_rpcclient
,
7464 .rpc_message
= &msg
,
7465 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
7466 .flags
= RPC_TASK_ASYNC
,
7468 int status
= -ENOMEM
;
7470 dprintk("--> %s\n", __func__
);
7471 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7472 if (calldata
== NULL
)
7474 calldata
->clp
= clp
;
7475 calldata
->arg
.one_fs
= 0;
7477 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
7478 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
7479 msg
.rpc_argp
= &calldata
->arg
;
7480 msg
.rpc_resp
= &calldata
->res
;
7481 task_setup_data
.callback_data
= calldata
;
7482 task
= rpc_run_task(&task_setup_data
);
7484 status
= PTR_ERR(task
);
7487 status
= nfs4_wait_for_completion_rpc_task(task
);
7489 status
= task
->tk_status
;
7493 dprintk("<-- %s status=%d\n", __func__
, status
);
7498 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
7500 struct nfs4_layoutget
*lgp
= calldata
;
7501 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
7502 struct nfs4_session
*session
= nfs4_get_session(server
);
7504 dprintk("--> %s\n", __func__
);
7505 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
7506 * right now covering the LAYOUTGET we are about to send.
7507 * However, that is not so catastrophic, and there seems
7508 * to be no way to prevent it completely.
7510 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
7511 &lgp
->res
.seq_res
, task
))
7513 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
7514 NFS_I(lgp
->args
.inode
)->layout
,
7515 lgp
->args
.ctx
->state
)) {
7516 rpc_exit(task
, NFS4_OK
);
7520 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
7522 struct nfs4_layoutget
*lgp
= calldata
;
7523 struct inode
*inode
= lgp
->args
.inode
;
7524 struct nfs_server
*server
= NFS_SERVER(inode
);
7525 struct pnfs_layout_hdr
*lo
;
7526 struct nfs4_state
*state
= NULL
;
7527 unsigned long timeo
, now
, giveup
;
7529 dprintk("--> %s tk_status => %d\n", __func__
, -task
->tk_status
);
7531 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
7534 switch (task
->tk_status
) {
7538 * NFS4ERR_LAYOUTTRYLATER is a conflict with another client
7539 * (or clients) writing to the same RAID stripe
7541 case -NFS4ERR_LAYOUTTRYLATER
:
7543 * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall
7544 * existing layout before getting a new one).
7546 case -NFS4ERR_RECALLCONFLICT
:
7547 timeo
= rpc_get_timeout(task
->tk_client
);
7548 giveup
= lgp
->args
.timestamp
+ timeo
;
7550 if (time_after(giveup
, now
)) {
7551 unsigned long delay
;
7554 * - Not less then NFS4_POLL_RETRY_MIN.
7555 * - One last time a jiffie before we give up
7556 * - exponential backoff (time_now minus start_attempt)
7558 delay
= max_t(unsigned long, NFS4_POLL_RETRY_MIN
,
7559 min((giveup
- now
- 1),
7560 now
- lgp
->args
.timestamp
));
7562 dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n",
7564 rpc_delay(task
, delay
);
7565 task
->tk_status
= 0;
7566 rpc_restart_call_prepare(task
);
7567 goto out
; /* Do not call nfs4_async_handle_error() */
7570 case -NFS4ERR_EXPIRED
:
7571 case -NFS4ERR_BAD_STATEID
:
7572 spin_lock(&inode
->i_lock
);
7573 lo
= NFS_I(inode
)->layout
;
7574 if (!lo
|| list_empty(&lo
->plh_segs
)) {
7575 spin_unlock(&inode
->i_lock
);
7576 /* If the open stateid was bad, then recover it. */
7577 state
= lgp
->args
.ctx
->state
;
7581 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
7582 spin_unlock(&inode
->i_lock
);
7583 /* Mark the bad layout state as invalid, then
7584 * retry using the open stateid. */
7585 pnfs_free_lseg_list(&head
);
7588 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
7589 rpc_restart_call_prepare(task
);
7591 dprintk("<-- %s\n", __func__
);
7594 static size_t max_response_pages(struct nfs_server
*server
)
7596 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
7597 return nfs_page_array_len(0, max_resp_sz
);
7600 static void nfs4_free_pages(struct page
**pages
, size_t size
)
7607 for (i
= 0; i
< size
; i
++) {
7610 __free_page(pages
[i
]);
7615 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
7617 struct page
**pages
;
7620 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
7622 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
7626 for (i
= 0; i
< size
; i
++) {
7627 pages
[i
] = alloc_page(gfp_flags
);
7629 dprintk("%s: failed to allocate page\n", __func__
);
7630 nfs4_free_pages(pages
, size
);
7638 static void nfs4_layoutget_release(void *calldata
)
7640 struct nfs4_layoutget
*lgp
= calldata
;
7641 struct inode
*inode
= lgp
->args
.inode
;
7642 struct nfs_server
*server
= NFS_SERVER(inode
);
7643 size_t max_pages
= max_response_pages(server
);
7645 dprintk("--> %s\n", __func__
);
7646 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
7647 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
7648 put_nfs_open_context(lgp
->args
.ctx
);
7650 dprintk("<-- %s\n", __func__
);
7653 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
7654 .rpc_call_prepare
= nfs4_layoutget_prepare
,
7655 .rpc_call_done
= nfs4_layoutget_done
,
7656 .rpc_release
= nfs4_layoutget_release
,
7659 struct pnfs_layout_segment
*
7660 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
7662 struct inode
*inode
= lgp
->args
.inode
;
7663 struct nfs_server
*server
= NFS_SERVER(inode
);
7664 size_t max_pages
= max_response_pages(server
);
7665 struct rpc_task
*task
;
7666 struct rpc_message msg
= {
7667 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
7668 .rpc_argp
= &lgp
->args
,
7669 .rpc_resp
= &lgp
->res
,
7670 .rpc_cred
= lgp
->cred
,
7672 struct rpc_task_setup task_setup_data
= {
7673 .rpc_client
= server
->client
,
7674 .rpc_message
= &msg
,
7675 .callback_ops
= &nfs4_layoutget_call_ops
,
7676 .callback_data
= lgp
,
7677 .flags
= RPC_TASK_ASYNC
,
7679 struct pnfs_layout_segment
*lseg
= NULL
;
7682 dprintk("--> %s\n", __func__
);
7684 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
7685 if (!lgp
->args
.layout
.pages
) {
7686 nfs4_layoutget_release(lgp
);
7687 return ERR_PTR(-ENOMEM
);
7689 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
7690 lgp
->args
.timestamp
= jiffies
;
7692 lgp
->res
.layoutp
= &lgp
->args
.layout
;
7693 lgp
->res
.seq_res
.sr_slot
= NULL
;
7694 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
7696 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
7697 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
7699 task
= rpc_run_task(&task_setup_data
);
7701 return ERR_CAST(task
);
7702 status
= nfs4_wait_for_completion_rpc_task(task
);
7704 status
= task
->tk_status
;
7705 trace_nfs4_layoutget(lgp
->args
.ctx
,
7709 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
7710 if (status
== 0 && lgp
->res
.layoutp
->len
)
7711 lseg
= pnfs_layout_process(lgp
);
7713 dprintk("<-- %s status=%d\n", __func__
, status
);
7715 return ERR_PTR(status
);
7720 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
7722 struct nfs4_layoutreturn
*lrp
= calldata
;
7724 dprintk("--> %s\n", __func__
);
7725 nfs41_setup_sequence(lrp
->clp
->cl_session
,
7726 &lrp
->args
.seq_args
,
7731 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
7733 struct nfs4_layoutreturn
*lrp
= calldata
;
7734 struct nfs_server
*server
;
7736 dprintk("--> %s\n", __func__
);
7738 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
7741 server
= NFS_SERVER(lrp
->args
.inode
);
7742 switch (task
->tk_status
) {
7744 task
->tk_status
= 0;
7747 case -NFS4ERR_DELAY
:
7748 if (nfs4_async_handle_error(task
, server
, NULL
) != -EAGAIN
)
7750 rpc_restart_call_prepare(task
);
7753 dprintk("<-- %s\n", __func__
);
7756 static void nfs4_layoutreturn_release(void *calldata
)
7758 struct nfs4_layoutreturn
*lrp
= calldata
;
7759 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
7761 dprintk("--> %s\n", __func__
);
7762 spin_lock(&lo
->plh_inode
->i_lock
);
7763 if (lrp
->res
.lrs_present
)
7764 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
7765 lo
->plh_block_lgets
--;
7766 spin_unlock(&lo
->plh_inode
->i_lock
);
7767 pnfs_put_layout_hdr(lrp
->args
.layout
);
7769 dprintk("<-- %s\n", __func__
);
7772 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
7773 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
7774 .rpc_call_done
= nfs4_layoutreturn_done
,
7775 .rpc_release
= nfs4_layoutreturn_release
,
7778 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
7780 struct rpc_task
*task
;
7781 struct rpc_message msg
= {
7782 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
7783 .rpc_argp
= &lrp
->args
,
7784 .rpc_resp
= &lrp
->res
,
7785 .rpc_cred
= lrp
->cred
,
7787 struct rpc_task_setup task_setup_data
= {
7788 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
7789 .rpc_message
= &msg
,
7790 .callback_ops
= &nfs4_layoutreturn_call_ops
,
7791 .callback_data
= lrp
,
7795 dprintk("--> %s\n", __func__
);
7796 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
7797 task
= rpc_run_task(&task_setup_data
);
7799 return PTR_ERR(task
);
7800 status
= task
->tk_status
;
7801 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
7802 dprintk("<-- %s status=%d\n", __func__
, status
);
7808 * Retrieve the list of Data Server devices from the MDS.
7810 static int _nfs4_getdevicelist(struct nfs_server
*server
,
7811 const struct nfs_fh
*fh
,
7812 struct pnfs_devicelist
*devlist
)
7814 struct nfs4_getdevicelist_args args
= {
7816 .layoutclass
= server
->pnfs_curr_ld
->id
,
7818 struct nfs4_getdevicelist_res res
= {
7821 struct rpc_message msg
= {
7822 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
7828 dprintk("--> %s\n", __func__
);
7829 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
7831 dprintk("<-- %s status=%d\n", __func__
, status
);
7835 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
7836 const struct nfs_fh
*fh
,
7837 struct pnfs_devicelist
*devlist
)
7839 struct nfs4_exception exception
= { };
7843 err
= nfs4_handle_exception(server
,
7844 _nfs4_getdevicelist(server
, fh
, devlist
),
7846 } while (exception
.retry
);
7848 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
7849 err
, devlist
->num_devs
);
7853 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
7856 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7857 struct pnfs_device
*pdev
,
7858 struct rpc_cred
*cred
)
7860 struct nfs4_getdeviceinfo_args args
= {
7863 struct nfs4_getdeviceinfo_res res
= {
7866 struct rpc_message msg
= {
7867 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7874 dprintk("--> %s\n", __func__
);
7875 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7876 dprintk("<-- %s status=%d\n", __func__
, status
);
7881 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7882 struct pnfs_device
*pdev
,
7883 struct rpc_cred
*cred
)
7885 struct nfs4_exception exception
= { };
7889 err
= nfs4_handle_exception(server
,
7890 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7892 } while (exception
.retry
);
7895 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7897 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7899 struct nfs4_layoutcommit_data
*data
= calldata
;
7900 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7901 struct nfs4_session
*session
= nfs4_get_session(server
);
7903 nfs41_setup_sequence(session
,
7904 &data
->args
.seq_args
,
7910 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7912 struct nfs4_layoutcommit_data
*data
= calldata
;
7913 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7915 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7918 switch (task
->tk_status
) { /* Just ignore these failures */
7919 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7920 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7921 case -NFS4ERR_BADLAYOUT
: /* no layout */
7922 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7923 task
->tk_status
= 0;
7927 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7928 rpc_restart_call_prepare(task
);
7934 static void nfs4_layoutcommit_release(void *calldata
)
7936 struct nfs4_layoutcommit_data
*data
= calldata
;
7938 pnfs_cleanup_layoutcommit(data
);
7939 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7941 put_rpccred(data
->cred
);
7945 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7946 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7947 .rpc_call_done
= nfs4_layoutcommit_done
,
7948 .rpc_release
= nfs4_layoutcommit_release
,
7952 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7954 struct rpc_message msg
= {
7955 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7956 .rpc_argp
= &data
->args
,
7957 .rpc_resp
= &data
->res
,
7958 .rpc_cred
= data
->cred
,
7960 struct rpc_task_setup task_setup_data
= {
7961 .task
= &data
->task
,
7962 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7963 .rpc_message
= &msg
,
7964 .callback_ops
= &nfs4_layoutcommit_ops
,
7965 .callback_data
= data
,
7966 .flags
= RPC_TASK_ASYNC
,
7968 struct rpc_task
*task
;
7971 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7972 "lbw: %llu inode %lu\n",
7973 data
->task
.tk_pid
, sync
,
7974 data
->args
.lastbytewritten
,
7975 data
->args
.inode
->i_ino
);
7977 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7978 task
= rpc_run_task(&task_setup_data
);
7980 return PTR_ERR(task
);
7983 status
= nfs4_wait_for_completion_rpc_task(task
);
7986 status
= task
->tk_status
;
7987 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7989 dprintk("%s: status %d\n", __func__
, status
);
7995 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7996 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7999 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
8000 struct nfs_fsinfo
*info
,
8001 struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
8003 struct nfs41_secinfo_no_name_args args
= {
8004 .style
= SECINFO_STYLE_CURRENT_FH
,
8006 struct nfs4_secinfo_res res
= {
8009 struct rpc_message msg
= {
8010 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
8014 struct rpc_clnt
*clnt
= server
->client
;
8015 struct rpc_cred
*cred
= NULL
;
8018 if (use_integrity
) {
8019 clnt
= server
->nfs_client
->cl_rpcclient
;
8020 cred
= nfs4_get_clid_cred(server
->nfs_client
);
8021 msg
.rpc_cred
= cred
;
8024 dprintk("--> %s\n", __func__
);
8025 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
8027 dprintk("<-- %s status=%d\n", __func__
, status
);
8036 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
8037 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
8039 struct nfs4_exception exception
= { };
8042 /* first try using integrity protection */
8043 err
= -NFS4ERR_WRONGSEC
;
8045 /* try to use integrity protection with machine cred */
8046 if (_nfs4_is_integrity_protected(server
->nfs_client
))
8047 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
8051 * if unable to use integrity protection, or SECINFO with
8052 * integrity protection returns NFS4ERR_WRONGSEC (which is
8053 * disallowed by spec, but exists in deployed servers) use
8054 * the current filesystem's rpc_client and the user cred.
8056 if (err
== -NFS4ERR_WRONGSEC
)
8057 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
8062 case -NFS4ERR_WRONGSEC
:
8066 err
= nfs4_handle_exception(server
, err
, &exception
);
8068 } while (exception
.retry
);
8074 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
8075 struct nfs_fsinfo
*info
)
8079 rpc_authflavor_t flavor
= RPC_AUTH_MAXFLAVOR
;
8080 struct nfs4_secinfo_flavors
*flavors
;
8081 struct nfs4_secinfo4
*secinfo
;
8084 page
= alloc_page(GFP_KERNEL
);
8090 flavors
= page_address(page
);
8091 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
8094 * Fall back on "guess and check" method if
8095 * the server doesn't support SECINFO_NO_NAME
8097 if (err
== -NFS4ERR_WRONGSEC
|| err
== -ENOTSUPP
) {
8098 err
= nfs4_find_root_sec(server
, fhandle
, info
);
8104 for (i
= 0; i
< flavors
->num_flavors
; i
++) {
8105 secinfo
= &flavors
->flavors
[i
];
8107 switch (secinfo
->flavor
) {
8111 flavor
= rpcauth_get_pseudoflavor(secinfo
->flavor
,
8112 &secinfo
->flavor_info
);
8115 flavor
= RPC_AUTH_MAXFLAVOR
;
8119 if (!nfs_auth_info_match(&server
->auth_info
, flavor
))
8120 flavor
= RPC_AUTH_MAXFLAVOR
;
8122 if (flavor
!= RPC_AUTH_MAXFLAVOR
) {
8123 err
= nfs4_lookup_root_sec(server
, fhandle
,
8130 if (flavor
== RPC_AUTH_MAXFLAVOR
)
8141 static int _nfs41_test_stateid(struct nfs_server
*server
,
8142 nfs4_stateid
*stateid
,
8143 struct rpc_cred
*cred
)
8146 struct nfs41_test_stateid_args args
= {
8149 struct nfs41_test_stateid_res res
;
8150 struct rpc_message msg
= {
8151 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
8156 struct rpc_clnt
*rpc_client
= server
->client
;
8158 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8161 dprintk("NFS call test_stateid %p\n", stateid
);
8162 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
8163 nfs4_set_sequence_privileged(&args
.seq_args
);
8164 status
= nfs4_call_sync_sequence(rpc_client
, server
, &msg
,
8165 &args
.seq_args
, &res
.seq_res
);
8166 if (status
!= NFS_OK
) {
8167 dprintk("NFS reply test_stateid: failed, %d\n", status
);
8170 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
8175 * nfs41_test_stateid - perform a TEST_STATEID operation
8177 * @server: server / transport on which to perform the operation
8178 * @stateid: state ID to test
8181 * Returns NFS_OK if the server recognizes that "stateid" is valid.
8182 * Otherwise a negative NFS4ERR value is returned if the operation
8183 * failed or the state ID is not currently valid.
8185 static int nfs41_test_stateid(struct nfs_server
*server
,
8186 nfs4_stateid
*stateid
,
8187 struct rpc_cred
*cred
)
8189 struct nfs4_exception exception
= { };
8192 err
= _nfs41_test_stateid(server
, stateid
, cred
);
8193 if (err
!= -NFS4ERR_DELAY
)
8195 nfs4_handle_exception(server
, err
, &exception
);
8196 } while (exception
.retry
);
8200 struct nfs_free_stateid_data
{
8201 struct nfs_server
*server
;
8202 struct nfs41_free_stateid_args args
;
8203 struct nfs41_free_stateid_res res
;
8206 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
8208 struct nfs_free_stateid_data
*data
= calldata
;
8209 nfs41_setup_sequence(nfs4_get_session(data
->server
),
8210 &data
->args
.seq_args
,
8215 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
8217 struct nfs_free_stateid_data
*data
= calldata
;
8219 nfs41_sequence_done(task
, &data
->res
.seq_res
);
8221 switch (task
->tk_status
) {
8222 case -NFS4ERR_DELAY
:
8223 if (nfs4_async_handle_error(task
, data
->server
, NULL
) == -EAGAIN
)
8224 rpc_restart_call_prepare(task
);
8228 static void nfs41_free_stateid_release(void *calldata
)
8233 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
8234 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
8235 .rpc_call_done
= nfs41_free_stateid_done
,
8236 .rpc_release
= nfs41_free_stateid_release
,
8239 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
8240 nfs4_stateid
*stateid
,
8241 struct rpc_cred
*cred
,
8244 struct rpc_message msg
= {
8245 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
8248 struct rpc_task_setup task_setup
= {
8249 .rpc_client
= server
->client
,
8250 .rpc_message
= &msg
,
8251 .callback_ops
= &nfs41_free_stateid_ops
,
8252 .flags
= RPC_TASK_ASYNC
,
8254 struct nfs_free_stateid_data
*data
;
8256 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8257 &task_setup
.rpc_client
, &msg
);
8259 dprintk("NFS call free_stateid %p\n", stateid
);
8260 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
8262 return ERR_PTR(-ENOMEM
);
8263 data
->server
= server
;
8264 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
8266 task_setup
.callback_data
= data
;
8268 msg
.rpc_argp
= &data
->args
;
8269 msg
.rpc_resp
= &data
->res
;
8270 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
8272 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
8274 return rpc_run_task(&task_setup
);
8278 * nfs41_free_stateid - perform a FREE_STATEID operation
8280 * @server: server / transport on which to perform the operation
8281 * @stateid: state ID to release
8284 * Returns NFS_OK if the server freed "stateid". Otherwise a
8285 * negative NFS4ERR value is returned.
8287 static int nfs41_free_stateid(struct nfs_server
*server
,
8288 nfs4_stateid
*stateid
,
8289 struct rpc_cred
*cred
)
8291 struct rpc_task
*task
;
8294 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
8296 return PTR_ERR(task
);
8297 ret
= rpc_wait_for_completion_task(task
);
8299 ret
= task
->tk_status
;
8305 nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
8307 struct rpc_task
*task
;
8308 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
8310 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
8311 nfs4_free_lock_state(server
, lsp
);
8317 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
8318 const nfs4_stateid
*s2
)
8320 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
8323 if (s1
->seqid
== s2
->seqid
)
8325 if (s1
->seqid
== 0 || s2
->seqid
== 0)
8331 #endif /* CONFIG_NFS_V4_1 */
8333 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
8334 const nfs4_stateid
*s2
)
8336 return nfs4_stateid_match(s1
, s2
);
8340 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
8341 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8342 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8343 .recover_open
= nfs4_open_reclaim
,
8344 .recover_lock
= nfs4_lock_reclaim
,
8345 .establish_clid
= nfs4_init_clientid
,
8346 .detect_trunking
= nfs40_discover_server_trunking
,
8349 #if defined(CONFIG_NFS_V4_1)
8350 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
8351 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8352 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8353 .recover_open
= nfs4_open_reclaim
,
8354 .recover_lock
= nfs4_lock_reclaim
,
8355 .establish_clid
= nfs41_init_clientid
,
8356 .reclaim_complete
= nfs41_proc_reclaim_complete
,
8357 .detect_trunking
= nfs41_discover_server_trunking
,
8359 #endif /* CONFIG_NFS_V4_1 */
8361 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
8362 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8363 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8364 .recover_open
= nfs4_open_expired
,
8365 .recover_lock
= nfs4_lock_expired
,
8366 .establish_clid
= nfs4_init_clientid
,
8369 #if defined(CONFIG_NFS_V4_1)
8370 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
8371 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8372 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8373 .recover_open
= nfs41_open_expired
,
8374 .recover_lock
= nfs41_lock_expired
,
8375 .establish_clid
= nfs41_init_clientid
,
8377 #endif /* CONFIG_NFS_V4_1 */
8379 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
8380 .sched_state_renewal
= nfs4_proc_async_renew
,
8381 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
8382 .renew_lease
= nfs4_proc_renew
,
8385 #if defined(CONFIG_NFS_V4_1)
8386 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
8387 .sched_state_renewal
= nfs41_proc_async_sequence
,
8388 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
8389 .renew_lease
= nfs4_proc_sequence
,
8393 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops
= {
8394 .get_locations
= _nfs40_proc_get_locations
,
8395 .fsid_present
= _nfs40_proc_fsid_present
,
8398 #if defined(CONFIG_NFS_V4_1)
8399 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops
= {
8400 .get_locations
= _nfs41_proc_get_locations
,
8401 .fsid_present
= _nfs41_proc_fsid_present
,
8403 #endif /* CONFIG_NFS_V4_1 */
8405 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
8407 .init_caps
= NFS_CAP_READDIRPLUS
8408 | NFS_CAP_ATOMIC_OPEN
8409 | NFS_CAP_CHANGE_ATTR
8410 | NFS_CAP_POSIX_LOCK
,
8411 .init_client
= nfs40_init_client
,
8412 .shutdown_client
= nfs40_shutdown_client
,
8413 .match_stateid
= nfs4_match_stateid
,
8414 .find_root_sec
= nfs4_find_root_sec
,
8415 .free_lock_state
= nfs4_release_lockowner
,
8416 .call_sync_ops
= &nfs40_call_sync_ops
,
8417 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
8418 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
8419 .state_renewal_ops
= &nfs40_state_renewal_ops
,
8420 .mig_recovery_ops
= &nfs40_mig_recovery_ops
,
8423 #if defined(CONFIG_NFS_V4_1)
8424 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
8426 .init_caps
= NFS_CAP_READDIRPLUS
8427 | NFS_CAP_ATOMIC_OPEN
8428 | NFS_CAP_CHANGE_ATTR
8429 | NFS_CAP_POSIX_LOCK
8430 | NFS_CAP_STATEID_NFSV41
8431 | NFS_CAP_ATOMIC_OPEN_V1
8433 .init_client
= nfs41_init_client
,
8434 .shutdown_client
= nfs41_shutdown_client
,
8435 .match_stateid
= nfs41_match_stateid
,
8436 .find_root_sec
= nfs41_find_root_sec
,
8437 .free_lock_state
= nfs41_free_lock_state
,
8438 .call_sync_ops
= &nfs41_call_sync_ops
,
8439 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8440 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8441 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8442 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
8446 #if defined(CONFIG_NFS_V4_2)
8447 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
8449 .init_caps
= NFS_CAP_READDIRPLUS
8450 | NFS_CAP_ATOMIC_OPEN
8451 | NFS_CAP_CHANGE_ATTR
8452 | NFS_CAP_POSIX_LOCK
8453 | NFS_CAP_STATEID_NFSV41
8454 | NFS_CAP_ATOMIC_OPEN_V1
,
8455 .init_client
= nfs41_init_client
,
8456 .shutdown_client
= nfs41_shutdown_client
,
8457 .match_stateid
= nfs41_match_stateid
,
8458 .find_root_sec
= nfs41_find_root_sec
,
8459 .free_lock_state
= nfs41_free_lock_state
,
8460 .call_sync_ops
= &nfs41_call_sync_ops
,
8461 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8462 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8463 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8467 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
8468 [0] = &nfs_v4_0_minor_ops
,
8469 #if defined(CONFIG_NFS_V4_1)
8470 [1] = &nfs_v4_1_minor_ops
,
8472 #if defined(CONFIG_NFS_V4_2)
8473 [2] = &nfs_v4_2_minor_ops
,
8477 static const struct inode_operations nfs4_dir_inode_operations
= {
8478 .create
= nfs_create
,
8479 .lookup
= nfs_lookup
,
8480 .atomic_open
= nfs_atomic_open
,
8482 .unlink
= nfs_unlink
,
8483 .symlink
= nfs_symlink
,
8487 .rename
= nfs_rename
,
8488 .permission
= nfs_permission
,
8489 .getattr
= nfs_getattr
,
8490 .setattr
= nfs_setattr
,
8491 .getxattr
= generic_getxattr
,
8492 .setxattr
= generic_setxattr
,
8493 .listxattr
= generic_listxattr
,
8494 .removexattr
= generic_removexattr
,
8497 static const struct inode_operations nfs4_file_inode_operations
= {
8498 .permission
= nfs_permission
,
8499 .getattr
= nfs_getattr
,
8500 .setattr
= nfs_setattr
,
8501 .getxattr
= generic_getxattr
,
8502 .setxattr
= generic_setxattr
,
8503 .listxattr
= generic_listxattr
,
8504 .removexattr
= generic_removexattr
,
8507 const struct nfs_rpc_ops nfs_v4_clientops
= {
8508 .version
= 4, /* protocol version */
8509 .dentry_ops
= &nfs4_dentry_operations
,
8510 .dir_inode_ops
= &nfs4_dir_inode_operations
,
8511 .file_inode_ops
= &nfs4_file_inode_operations
,
8512 .file_ops
= &nfs4_file_operations
,
8513 .getroot
= nfs4_proc_get_root
,
8514 .submount
= nfs4_submount
,
8515 .try_mount
= nfs4_try_mount
,
8516 .getattr
= nfs4_proc_getattr
,
8517 .setattr
= nfs4_proc_setattr
,
8518 .lookup
= nfs4_proc_lookup
,
8519 .access
= nfs4_proc_access
,
8520 .readlink
= nfs4_proc_readlink
,
8521 .create
= nfs4_proc_create
,
8522 .remove
= nfs4_proc_remove
,
8523 .unlink_setup
= nfs4_proc_unlink_setup
,
8524 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
8525 .unlink_done
= nfs4_proc_unlink_done
,
8526 .rename_setup
= nfs4_proc_rename_setup
,
8527 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
8528 .rename_done
= nfs4_proc_rename_done
,
8529 .link
= nfs4_proc_link
,
8530 .symlink
= nfs4_proc_symlink
,
8531 .mkdir
= nfs4_proc_mkdir
,
8532 .rmdir
= nfs4_proc_remove
,
8533 .readdir
= nfs4_proc_readdir
,
8534 .mknod
= nfs4_proc_mknod
,
8535 .statfs
= nfs4_proc_statfs
,
8536 .fsinfo
= nfs4_proc_fsinfo
,
8537 .pathconf
= nfs4_proc_pathconf
,
8538 .set_capabilities
= nfs4_server_capabilities
,
8539 .decode_dirent
= nfs4_decode_dirent
,
8540 .pgio_rpc_prepare
= nfs4_proc_pgio_rpc_prepare
,
8541 .read_setup
= nfs4_proc_read_setup
,
8542 .read_done
= nfs4_read_done
,
8543 .write_setup
= nfs4_proc_write_setup
,
8544 .write_done
= nfs4_write_done
,
8545 .commit_setup
= nfs4_proc_commit_setup
,
8546 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
8547 .commit_done
= nfs4_commit_done
,
8548 .lock
= nfs4_proc_lock
,
8549 .clear_acl_cache
= nfs4_zap_acl_attr
,
8550 .close_context
= nfs4_close_context
,
8551 .open_context
= nfs4_atomic_open
,
8552 .have_delegation
= nfs4_have_delegation
,
8553 .return_delegation
= nfs4_inode_return_delegation
,
8554 .alloc_client
= nfs4_alloc_client
,
8555 .init_client
= nfs4_init_client
,
8556 .free_client
= nfs4_free_client
,
8557 .create_server
= nfs4_create_server
,
8558 .clone_server
= nfs_clone_server
,
8561 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
8562 .prefix
= XATTR_NAME_NFSV4_ACL
,
8563 .list
= nfs4_xattr_list_nfs4_acl
,
8564 .get
= nfs4_xattr_get_nfs4_acl
,
8565 .set
= nfs4_xattr_set_nfs4_acl
,
8568 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
8569 &nfs4_xattr_nfs4_acl_handler
,
8570 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
8571 &nfs4_xattr_nfs4_label_handler
,