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
*, long *);
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 long nfs4_update_delay(long *timeout
)
321 return NFS4_POLL_RETRY_MAX
;
323 *timeout
= NFS4_POLL_RETRY_MIN
;
324 if (*timeout
> NFS4_POLL_RETRY_MAX
)
325 *timeout
= NFS4_POLL_RETRY_MAX
;
331 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
337 freezable_schedule_timeout_killable_unsafe(
338 nfs4_update_delay(timeout
));
339 if (fatal_signal_pending(current
))
344 /* This is the error handling routine for processes that are allowed
347 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
349 struct nfs_client
*clp
= server
->nfs_client
;
350 struct nfs4_state
*state
= exception
->state
;
351 struct inode
*inode
= exception
->inode
;
354 exception
->retry
= 0;
358 case -NFS4ERR_OPENMODE
:
359 if (inode
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
360 nfs4_inode_return_delegation(inode
);
361 exception
->retry
= 1;
366 ret
= nfs4_schedule_stateid_recovery(server
, state
);
369 goto wait_on_recovery
;
370 case -NFS4ERR_DELEG_REVOKED
:
371 case -NFS4ERR_ADMIN_REVOKED
:
372 case -NFS4ERR_BAD_STATEID
:
373 if (inode
!= NULL
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
374 nfs_remove_bad_delegation(inode
);
375 exception
->retry
= 1;
380 ret
= nfs4_schedule_stateid_recovery(server
, state
);
383 goto wait_on_recovery
;
384 case -NFS4ERR_EXPIRED
:
386 ret
= nfs4_schedule_stateid_recovery(server
, state
);
390 case -NFS4ERR_STALE_STATEID
:
391 case -NFS4ERR_STALE_CLIENTID
:
392 nfs4_schedule_lease_recovery(clp
);
393 goto wait_on_recovery
;
395 ret
= nfs4_schedule_migration_recovery(server
);
398 goto wait_on_recovery
;
399 case -NFS4ERR_LEASE_MOVED
:
400 nfs4_schedule_lease_moved_recovery(clp
);
401 goto wait_on_recovery
;
402 #if defined(CONFIG_NFS_V4_1)
403 case -NFS4ERR_BADSESSION
:
404 case -NFS4ERR_BADSLOT
:
405 case -NFS4ERR_BAD_HIGH_SLOT
:
406 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
407 case -NFS4ERR_DEADSESSION
:
408 case -NFS4ERR_SEQ_FALSE_RETRY
:
409 case -NFS4ERR_SEQ_MISORDERED
:
410 dprintk("%s ERROR: %d Reset session\n", __func__
,
412 nfs4_schedule_session_recovery(clp
->cl_session
, errorcode
);
413 goto wait_on_recovery
;
414 #endif /* defined(CONFIG_NFS_V4_1) */
415 case -NFS4ERR_FILE_OPEN
:
416 if (exception
->timeout
> HZ
) {
417 /* We have retried a decent amount, time to
425 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
428 case -NFS4ERR_RETRY_UNCACHED_REP
:
429 case -NFS4ERR_OLD_STATEID
:
430 exception
->retry
= 1;
432 case -NFS4ERR_BADOWNER
:
433 /* The following works around a Linux server bug! */
434 case -NFS4ERR_BADNAME
:
435 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
436 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
437 exception
->retry
= 1;
438 printk(KERN_WARNING
"NFS: v4 server %s "
439 "does not accept raw "
441 "Reenabling the idmapper.\n",
442 server
->nfs_client
->cl_hostname
);
445 /* We failed to handle the error */
446 return nfs4_map_errors(ret
);
448 ret
= nfs4_wait_clnt_recover(clp
);
449 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
452 exception
->retry
= 1;
457 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
458 * or 'false' otherwise.
460 static bool _nfs4_is_integrity_protected(struct nfs_client
*clp
)
462 rpc_authflavor_t flavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
464 if (flavor
== RPC_AUTH_GSS_KRB5I
||
465 flavor
== RPC_AUTH_GSS_KRB5P
)
471 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
473 spin_lock(&clp
->cl_lock
);
474 if (time_before(clp
->cl_last_renewal
,timestamp
))
475 clp
->cl_last_renewal
= timestamp
;
476 spin_unlock(&clp
->cl_lock
);
479 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
481 do_renew_lease(server
->nfs_client
, timestamp
);
484 struct nfs4_call_sync_data
{
485 const struct nfs_server
*seq_server
;
486 struct nfs4_sequence_args
*seq_args
;
487 struct nfs4_sequence_res
*seq_res
;
490 static void nfs4_init_sequence(struct nfs4_sequence_args
*args
,
491 struct nfs4_sequence_res
*res
, int cache_reply
)
493 args
->sa_slot
= NULL
;
494 args
->sa_cache_this
= cache_reply
;
495 args
->sa_privileged
= 0;
500 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
502 args
->sa_privileged
= 1;
505 static int nfs40_setup_sequence(const struct nfs_server
*server
,
506 struct nfs4_sequence_args
*args
,
507 struct nfs4_sequence_res
*res
,
508 struct rpc_task
*task
)
510 struct nfs4_slot_table
*tbl
= server
->nfs_client
->cl_slot_tbl
;
511 struct nfs4_slot
*slot
;
513 /* slot already allocated? */
514 if (res
->sr_slot
!= NULL
)
517 spin_lock(&tbl
->slot_tbl_lock
);
518 if (nfs4_slot_tbl_draining(tbl
) && !args
->sa_privileged
)
521 slot
= nfs4_alloc_slot(tbl
);
523 if (slot
== ERR_PTR(-ENOMEM
))
524 task
->tk_timeout
= HZ
>> 2;
527 spin_unlock(&tbl
->slot_tbl_lock
);
529 args
->sa_slot
= slot
;
533 rpc_call_start(task
);
537 if (args
->sa_privileged
)
538 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
539 NULL
, RPC_PRIORITY_PRIVILEGED
);
541 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
542 spin_unlock(&tbl
->slot_tbl_lock
);
546 static int nfs40_sequence_done(struct rpc_task
*task
,
547 struct nfs4_sequence_res
*res
)
549 struct nfs4_slot
*slot
= res
->sr_slot
;
550 struct nfs4_slot_table
*tbl
;
556 spin_lock(&tbl
->slot_tbl_lock
);
557 if (!nfs41_wake_and_assign_slot(tbl
, slot
))
558 nfs4_free_slot(tbl
, slot
);
559 spin_unlock(&tbl
->slot_tbl_lock
);
566 #if defined(CONFIG_NFS_V4_1)
568 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
570 struct nfs4_session
*session
;
571 struct nfs4_slot_table
*tbl
;
572 struct nfs4_slot
*slot
= res
->sr_slot
;
573 bool send_new_highest_used_slotid
= false;
576 session
= tbl
->session
;
578 spin_lock(&tbl
->slot_tbl_lock
);
579 /* Be nice to the server: try to ensure that the last transmitted
580 * value for highest_user_slotid <= target_highest_slotid
582 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
583 send_new_highest_used_slotid
= true;
585 if (nfs41_wake_and_assign_slot(tbl
, slot
)) {
586 send_new_highest_used_slotid
= false;
589 nfs4_free_slot(tbl
, slot
);
591 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
592 send_new_highest_used_slotid
= false;
594 spin_unlock(&tbl
->slot_tbl_lock
);
596 if (send_new_highest_used_slotid
)
597 nfs41_server_notify_highest_slotid_update(session
->clp
);
600 int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
602 struct nfs4_session
*session
;
603 struct nfs4_slot
*slot
= res
->sr_slot
;
604 struct nfs_client
*clp
;
605 bool interrupted
= false;
610 /* don't increment the sequence number if the task wasn't sent */
611 if (!RPC_WAS_SENT(task
))
614 session
= slot
->table
->session
;
616 if (slot
->interrupted
) {
617 slot
->interrupted
= 0;
621 trace_nfs4_sequence_done(session
, res
);
622 /* Check the SEQUENCE operation status */
623 switch (res
->sr_status
) {
625 /* Update the slot's sequence and clientid lease timer */
628 do_renew_lease(clp
, res
->sr_timestamp
);
629 /* Check sequence flags */
630 if (res
->sr_status_flags
!= 0)
631 nfs4_schedule_lease_recovery(clp
);
632 nfs41_update_target_slotid(slot
->table
, slot
, res
);
636 * sr_status remains 1 if an RPC level error occurred.
637 * The server may or may not have processed the sequence
639 * Mark the slot as having hosted an interrupted RPC call.
641 slot
->interrupted
= 1;
644 /* The server detected a resend of the RPC call and
645 * returned NFS4ERR_DELAY as per Section 2.10.6.2
648 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
653 case -NFS4ERR_BADSLOT
:
655 * The slot id we used was probably retired. Try again
656 * using a different slot id.
659 case -NFS4ERR_SEQ_MISORDERED
:
661 * Was the last operation on this sequence interrupted?
662 * If so, retry after bumping the sequence number.
669 * Could this slot have been previously retired?
670 * If so, then the server may be expecting seq_nr = 1!
672 if (slot
->seq_nr
!= 1) {
677 case -NFS4ERR_SEQ_FALSE_RETRY
:
681 /* Just update the slot sequence no. */
685 /* The session may be reset by one of the error handlers. */
686 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
687 nfs41_sequence_free_slot(res
);
691 if (rpc_restart_call_prepare(task
)) {
697 if (!rpc_restart_call(task
))
699 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
702 EXPORT_SYMBOL_GPL(nfs41_sequence_done
);
704 static int nfs4_sequence_done(struct rpc_task
*task
,
705 struct nfs4_sequence_res
*res
)
707 if (res
->sr_slot
== NULL
)
709 if (!res
->sr_slot
->table
->session
)
710 return nfs40_sequence_done(task
, res
);
711 return nfs41_sequence_done(task
, res
);
714 int nfs41_setup_sequence(struct nfs4_session
*session
,
715 struct nfs4_sequence_args
*args
,
716 struct nfs4_sequence_res
*res
,
717 struct rpc_task
*task
)
719 struct nfs4_slot
*slot
;
720 struct nfs4_slot_table
*tbl
;
722 dprintk("--> %s\n", __func__
);
723 /* slot already allocated? */
724 if (res
->sr_slot
!= NULL
)
727 tbl
= &session
->fc_slot_table
;
729 task
->tk_timeout
= 0;
731 spin_lock(&tbl
->slot_tbl_lock
);
732 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
733 !args
->sa_privileged
) {
734 /* The state manager will wait until the slot table is empty */
735 dprintk("%s session is draining\n", __func__
);
739 slot
= nfs4_alloc_slot(tbl
);
741 /* If out of memory, try again in 1/4 second */
742 if (slot
== ERR_PTR(-ENOMEM
))
743 task
->tk_timeout
= HZ
>> 2;
744 dprintk("<-- %s: no free slots\n", __func__
);
747 spin_unlock(&tbl
->slot_tbl_lock
);
749 args
->sa_slot
= slot
;
751 dprintk("<-- %s slotid=%u seqid=%u\n", __func__
,
752 slot
->slot_nr
, slot
->seq_nr
);
755 res
->sr_timestamp
= jiffies
;
756 res
->sr_status_flags
= 0;
758 * sr_status is only set in decode_sequence, and so will remain
759 * set to 1 if an rpc level failure occurs.
762 trace_nfs4_setup_sequence(session
, args
);
764 rpc_call_start(task
);
767 /* Privileged tasks are queued with top priority */
768 if (args
->sa_privileged
)
769 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
770 NULL
, RPC_PRIORITY_PRIVILEGED
);
772 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
773 spin_unlock(&tbl
->slot_tbl_lock
);
776 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
778 static int nfs4_setup_sequence(const struct nfs_server
*server
,
779 struct nfs4_sequence_args
*args
,
780 struct nfs4_sequence_res
*res
,
781 struct rpc_task
*task
)
783 struct nfs4_session
*session
= nfs4_get_session(server
);
787 return nfs40_setup_sequence(server
, args
, res
, task
);
789 dprintk("--> %s clp %p session %p sr_slot %u\n",
790 __func__
, session
->clp
, session
, res
->sr_slot
?
791 res
->sr_slot
->slot_nr
: NFS4_NO_SLOT
);
793 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
795 dprintk("<-- %s status=%d\n", __func__
, ret
);
799 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
801 struct nfs4_call_sync_data
*data
= calldata
;
802 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
804 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
806 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
809 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
811 struct nfs4_call_sync_data
*data
= calldata
;
813 nfs41_sequence_done(task
, data
->seq_res
);
816 static const struct rpc_call_ops nfs41_call_sync_ops
= {
817 .rpc_call_prepare
= nfs41_call_sync_prepare
,
818 .rpc_call_done
= nfs41_call_sync_done
,
821 #else /* !CONFIG_NFS_V4_1 */
823 static int nfs4_setup_sequence(const struct nfs_server
*server
,
824 struct nfs4_sequence_args
*args
,
825 struct nfs4_sequence_res
*res
,
826 struct rpc_task
*task
)
828 return nfs40_setup_sequence(server
, args
, res
, task
);
831 static int nfs4_sequence_done(struct rpc_task
*task
,
832 struct nfs4_sequence_res
*res
)
834 return nfs40_sequence_done(task
, res
);
837 #endif /* !CONFIG_NFS_V4_1 */
839 static void nfs40_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
841 struct nfs4_call_sync_data
*data
= calldata
;
842 nfs4_setup_sequence(data
->seq_server
,
843 data
->seq_args
, data
->seq_res
, task
);
846 static void nfs40_call_sync_done(struct rpc_task
*task
, void *calldata
)
848 struct nfs4_call_sync_data
*data
= calldata
;
849 nfs4_sequence_done(task
, data
->seq_res
);
852 static const struct rpc_call_ops nfs40_call_sync_ops
= {
853 .rpc_call_prepare
= nfs40_call_sync_prepare
,
854 .rpc_call_done
= nfs40_call_sync_done
,
857 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
858 struct nfs_server
*server
,
859 struct rpc_message
*msg
,
860 struct nfs4_sequence_args
*args
,
861 struct nfs4_sequence_res
*res
)
864 struct rpc_task
*task
;
865 struct nfs_client
*clp
= server
->nfs_client
;
866 struct nfs4_call_sync_data data
= {
867 .seq_server
= server
,
871 struct rpc_task_setup task_setup
= {
874 .callback_ops
= clp
->cl_mvops
->call_sync_ops
,
875 .callback_data
= &data
878 task
= rpc_run_task(&task_setup
);
882 ret
= task
->tk_status
;
889 int nfs4_call_sync(struct rpc_clnt
*clnt
,
890 struct nfs_server
*server
,
891 struct rpc_message
*msg
,
892 struct nfs4_sequence_args
*args
,
893 struct nfs4_sequence_res
*res
,
896 nfs4_init_sequence(args
, res
, cache_reply
);
897 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
);
900 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
902 struct nfs_inode
*nfsi
= NFS_I(dir
);
904 spin_lock(&dir
->i_lock
);
905 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
906 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
907 nfs_force_lookup_revalidate(dir
);
908 dir
->i_version
= cinfo
->after
;
909 nfs_fscache_invalidate(dir
);
910 spin_unlock(&dir
->i_lock
);
913 struct nfs4_opendata
{
915 struct nfs_openargs o_arg
;
916 struct nfs_openres o_res
;
917 struct nfs_open_confirmargs c_arg
;
918 struct nfs_open_confirmres c_res
;
919 struct nfs4_string owner_name
;
920 struct nfs4_string group_name
;
921 struct nfs_fattr f_attr
;
922 struct nfs4_label
*f_label
;
924 struct dentry
*dentry
;
925 struct nfs4_state_owner
*owner
;
926 struct nfs4_state
*state
;
928 unsigned long timestamp
;
929 unsigned int rpc_done
: 1;
930 unsigned int file_created
: 1;
931 unsigned int is_recover
: 1;
936 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
937 int err
, struct nfs4_exception
*exception
)
941 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
943 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
944 exception
->retry
= 1;
948 static enum open_claim_type4
949 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
950 enum open_claim_type4 claim
)
952 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
957 case NFS4_OPEN_CLAIM_FH
:
958 return NFS4_OPEN_CLAIM_NULL
;
959 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
960 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
961 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
962 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
966 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
968 p
->o_res
.f_attr
= &p
->f_attr
;
969 p
->o_res
.f_label
= p
->f_label
;
970 p
->o_res
.seqid
= p
->o_arg
.seqid
;
971 p
->c_res
.seqid
= p
->c_arg
.seqid
;
972 p
->o_res
.server
= p
->o_arg
.server
;
973 p
->o_res
.access_request
= p
->o_arg
.access
;
974 nfs_fattr_init(&p
->f_attr
);
975 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
978 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
979 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
980 const struct iattr
*attrs
,
981 struct nfs4_label
*label
,
982 enum open_claim_type4 claim
,
985 struct dentry
*parent
= dget_parent(dentry
);
986 struct inode
*dir
= parent
->d_inode
;
987 struct nfs_server
*server
= NFS_SERVER(dir
);
988 struct nfs4_opendata
*p
;
990 p
= kzalloc(sizeof(*p
), gfp_mask
);
994 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
995 if (IS_ERR(p
->f_label
))
998 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
999 if (p
->o_arg
.seqid
== NULL
)
1000 goto err_free_label
;
1001 nfs_sb_active(dentry
->d_sb
);
1002 p
->dentry
= dget(dentry
);
1005 atomic_inc(&sp
->so_count
);
1006 p
->o_arg
.open_flags
= flags
;
1007 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
1008 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
1009 * will return permission denied for all bits until close */
1010 if (!(flags
& O_EXCL
)) {
1011 /* ask server to check for all possible rights as results
1013 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
1014 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
1016 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
1017 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
1018 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
1019 p
->o_arg
.name
= &dentry
->d_name
;
1020 p
->o_arg
.server
= server
;
1021 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
1022 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
1023 p
->o_arg
.label
= label
;
1024 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
1025 switch (p
->o_arg
.claim
) {
1026 case NFS4_OPEN_CLAIM_NULL
:
1027 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1028 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1029 p
->o_arg
.fh
= NFS_FH(dir
);
1031 case NFS4_OPEN_CLAIM_PREVIOUS
:
1032 case NFS4_OPEN_CLAIM_FH
:
1033 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1034 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1035 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
1037 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
1040 p
->o_arg
.u
.attrs
= &p
->attrs
;
1041 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
1044 verf
[1] = current
->pid
;
1045 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
1046 sizeof(p
->o_arg
.u
.verifier
.data
));
1048 p
->c_arg
.fh
= &p
->o_res
.fh
;
1049 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
1050 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
1051 nfs4_init_opendata_res(p
);
1052 kref_init(&p
->kref
);
1056 nfs4_label_free(p
->f_label
);
1064 static void nfs4_opendata_free(struct kref
*kref
)
1066 struct nfs4_opendata
*p
= container_of(kref
,
1067 struct nfs4_opendata
, kref
);
1068 struct super_block
*sb
= p
->dentry
->d_sb
;
1070 nfs_free_seqid(p
->o_arg
.seqid
);
1071 if (p
->state
!= NULL
)
1072 nfs4_put_open_state(p
->state
);
1073 nfs4_put_state_owner(p
->owner
);
1075 nfs4_label_free(p
->f_label
);
1079 nfs_sb_deactive(sb
);
1080 nfs_fattr_free_names(&p
->f_attr
);
1081 kfree(p
->f_attr
.mdsthreshold
);
1085 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1088 kref_put(&p
->kref
, nfs4_opendata_free
);
1091 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
1095 ret
= rpc_wait_for_completion_task(task
);
1099 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1103 if (open_mode
& (O_EXCL
|O_TRUNC
))
1105 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1107 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1108 && state
->n_rdonly
!= 0;
1111 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1112 && state
->n_wronly
!= 0;
1114 case FMODE_READ
|FMODE_WRITE
:
1115 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1116 && state
->n_rdwr
!= 0;
1122 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1124 if (delegation
== NULL
)
1126 if ((delegation
->type
& fmode
) != fmode
)
1128 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1130 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1132 nfs_mark_delegation_referenced(delegation
);
1136 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1145 case FMODE_READ
|FMODE_WRITE
:
1148 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1151 static void nfs_test_and_clear_all_open_stateid(struct nfs4_state
*state
)
1153 struct nfs_client
*clp
= state
->owner
->so_server
->nfs_client
;
1154 bool need_recover
= false;
1156 if (test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
) && state
->n_rdonly
)
1157 need_recover
= true;
1158 if (test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
) && state
->n_wronly
)
1159 need_recover
= true;
1160 if (test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
) && state
->n_rdwr
)
1161 need_recover
= true;
1163 nfs4_state_mark_reclaim_nograce(clp
, state
);
1166 static bool nfs_need_update_open_stateid(struct nfs4_state
*state
,
1167 nfs4_stateid
*stateid
)
1169 if (test_and_set_bit(NFS_OPEN_STATE
, &state
->flags
) == 0)
1171 if (!nfs4_stateid_match_other(stateid
, &state
->open_stateid
)) {
1172 nfs_test_and_clear_all_open_stateid(state
);
1175 if (nfs4_stateid_is_newer(stateid
, &state
->open_stateid
))
1180 static void nfs_clear_open_stateid_locked(struct nfs4_state
*state
,
1181 nfs4_stateid
*stateid
, fmode_t fmode
)
1183 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1184 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
1186 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1189 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1192 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1193 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1194 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1196 if (stateid
== NULL
)
1198 if (!nfs_need_update_open_stateid(state
, stateid
))
1200 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1201 nfs4_stateid_copy(&state
->stateid
, stateid
);
1202 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1205 static void nfs_clear_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1207 write_seqlock(&state
->seqlock
);
1208 nfs_clear_open_stateid_locked(state
, stateid
, fmode
);
1209 write_sequnlock(&state
->seqlock
);
1210 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1211 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1214 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1218 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1221 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1223 case FMODE_READ
|FMODE_WRITE
:
1224 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1226 if (!nfs_need_update_open_stateid(state
, stateid
))
1228 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1229 nfs4_stateid_copy(&state
->stateid
, stateid
);
1230 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1233 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1236 * Protect the call to nfs4_state_set_mode_locked and
1237 * serialise the stateid update
1239 write_seqlock(&state
->seqlock
);
1240 if (deleg_stateid
!= NULL
) {
1241 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1242 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1244 if (open_stateid
!= NULL
)
1245 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1246 write_sequnlock(&state
->seqlock
);
1247 spin_lock(&state
->owner
->so_lock
);
1248 update_open_stateflags(state
, fmode
);
1249 spin_unlock(&state
->owner
->so_lock
);
1252 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1254 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1255 struct nfs_delegation
*deleg_cur
;
1258 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1261 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1262 if (deleg_cur
== NULL
)
1265 spin_lock(&deleg_cur
->lock
);
1266 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1267 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1268 (deleg_cur
->type
& fmode
) != fmode
)
1269 goto no_delegation_unlock
;
1271 if (delegation
== NULL
)
1272 delegation
= &deleg_cur
->stateid
;
1273 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1274 goto no_delegation_unlock
;
1276 nfs_mark_delegation_referenced(deleg_cur
);
1277 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1279 no_delegation_unlock
:
1280 spin_unlock(&deleg_cur
->lock
);
1284 if (!ret
&& open_stateid
!= NULL
) {
1285 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1288 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
))
1289 nfs4_schedule_state_manager(state
->owner
->so_server
->nfs_client
);
1295 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1297 struct nfs_delegation
*delegation
;
1300 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1301 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1306 nfs4_inode_return_delegation(inode
);
1309 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1311 struct nfs4_state
*state
= opendata
->state
;
1312 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1313 struct nfs_delegation
*delegation
;
1314 int open_mode
= opendata
->o_arg
.open_flags
;
1315 fmode_t fmode
= opendata
->o_arg
.fmode
;
1316 nfs4_stateid stateid
;
1320 spin_lock(&state
->owner
->so_lock
);
1321 if (can_open_cached(state
, fmode
, open_mode
)) {
1322 update_open_stateflags(state
, fmode
);
1323 spin_unlock(&state
->owner
->so_lock
);
1324 goto out_return_state
;
1326 spin_unlock(&state
->owner
->so_lock
);
1328 delegation
= rcu_dereference(nfsi
->delegation
);
1329 if (!can_open_delegated(delegation
, fmode
)) {
1333 /* Save the delegation */
1334 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1336 nfs_release_seqid(opendata
->o_arg
.seqid
);
1337 if (!opendata
->is_recover
) {
1338 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1344 /* Try to update the stateid using the delegation */
1345 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1346 goto out_return_state
;
1349 return ERR_PTR(ret
);
1351 atomic_inc(&state
->count
);
1356 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1358 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1359 struct nfs_delegation
*delegation
;
1360 int delegation_flags
= 0;
1363 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1365 delegation_flags
= delegation
->flags
;
1367 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1368 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1369 "returning a delegation for "
1370 "OPEN(CLAIM_DELEGATE_CUR)\n",
1372 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1373 nfs_inode_set_delegation(state
->inode
,
1374 data
->owner
->so_cred
,
1377 nfs_inode_reclaim_delegation(state
->inode
,
1378 data
->owner
->so_cred
,
1383 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1384 * and update the nfs4_state.
1386 static struct nfs4_state
*
1387 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1389 struct inode
*inode
= data
->state
->inode
;
1390 struct nfs4_state
*state
= data
->state
;
1393 if (!data
->rpc_done
) {
1394 if (data
->rpc_status
) {
1395 ret
= data
->rpc_status
;
1398 /* cached opens have already been processed */
1402 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1406 if (data
->o_res
.delegation_type
!= 0)
1407 nfs4_opendata_check_deleg(data
, state
);
1409 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1411 atomic_inc(&state
->count
);
1415 return ERR_PTR(ret
);
1419 static struct nfs4_state
*
1420 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1422 struct inode
*inode
;
1423 struct nfs4_state
*state
= NULL
;
1426 if (!data
->rpc_done
) {
1427 state
= nfs4_try_open_cached(data
);
1432 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1434 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1435 ret
= PTR_ERR(inode
);
1439 state
= nfs4_get_open_state(inode
, data
->owner
);
1442 if (data
->o_res
.delegation_type
!= 0)
1443 nfs4_opendata_check_deleg(data
, state
);
1444 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1448 nfs_release_seqid(data
->o_arg
.seqid
);
1453 return ERR_PTR(ret
);
1456 static struct nfs4_state
*
1457 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1459 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1460 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1461 return _nfs4_opendata_to_nfs4_state(data
);
1464 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1466 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1467 struct nfs_open_context
*ctx
;
1469 spin_lock(&state
->inode
->i_lock
);
1470 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1471 if (ctx
->state
!= state
)
1473 get_nfs_open_context(ctx
);
1474 spin_unlock(&state
->inode
->i_lock
);
1477 spin_unlock(&state
->inode
->i_lock
);
1478 return ERR_PTR(-ENOENT
);
1481 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1482 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1484 struct nfs4_opendata
*opendata
;
1486 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1487 NULL
, NULL
, claim
, GFP_NOFS
);
1488 if (opendata
== NULL
)
1489 return ERR_PTR(-ENOMEM
);
1490 opendata
->state
= state
;
1491 atomic_inc(&state
->count
);
1495 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1497 struct nfs4_state
*newstate
;
1500 opendata
->o_arg
.open_flags
= 0;
1501 opendata
->o_arg
.fmode
= fmode
;
1502 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1503 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1504 nfs4_init_opendata_res(opendata
);
1505 ret
= _nfs4_recover_proc_open(opendata
);
1508 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1509 if (IS_ERR(newstate
))
1510 return PTR_ERR(newstate
);
1511 nfs4_close_state(newstate
, fmode
);
1516 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1518 struct nfs4_state
*newstate
;
1521 /* Don't trigger recovery in nfs_test_and_clear_all_open_stateid */
1522 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1523 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1524 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1525 /* memory barrier prior to reading state->n_* */
1526 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1527 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1529 if (state
->n_rdwr
!= 0) {
1530 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1533 if (newstate
!= state
)
1536 if (state
->n_wronly
!= 0) {
1537 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1540 if (newstate
!= state
)
1543 if (state
->n_rdonly
!= 0) {
1544 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1547 if (newstate
!= state
)
1551 * We may have performed cached opens for all three recoveries.
1552 * Check if we need to update the current stateid.
1554 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1555 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1556 write_seqlock(&state
->seqlock
);
1557 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1558 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1559 write_sequnlock(&state
->seqlock
);
1566 * reclaim state on the server after a reboot.
1568 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1570 struct nfs_delegation
*delegation
;
1571 struct nfs4_opendata
*opendata
;
1572 fmode_t delegation_type
= 0;
1575 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1576 NFS4_OPEN_CLAIM_PREVIOUS
);
1577 if (IS_ERR(opendata
))
1578 return PTR_ERR(opendata
);
1580 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1581 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1582 delegation_type
= delegation
->type
;
1584 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1585 status
= nfs4_open_recover(opendata
, state
);
1586 nfs4_opendata_put(opendata
);
1590 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1592 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1593 struct nfs4_exception exception
= { };
1596 err
= _nfs4_do_open_reclaim(ctx
, state
);
1597 trace_nfs4_open_reclaim(ctx
, 0, err
);
1598 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1600 if (err
!= -NFS4ERR_DELAY
)
1602 nfs4_handle_exception(server
, err
, &exception
);
1603 } while (exception
.retry
);
1607 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1609 struct nfs_open_context
*ctx
;
1612 ctx
= nfs4_state_find_open_context(state
);
1615 ret
= nfs4_do_open_reclaim(ctx
, state
);
1616 put_nfs_open_context(ctx
);
1620 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1624 printk(KERN_ERR
"NFS: %s: unhandled error "
1625 "%d.\n", __func__
, err
);
1630 case -NFS4ERR_BADSESSION
:
1631 case -NFS4ERR_BADSLOT
:
1632 case -NFS4ERR_BAD_HIGH_SLOT
:
1633 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1634 case -NFS4ERR_DEADSESSION
:
1635 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1636 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1638 case -NFS4ERR_STALE_CLIENTID
:
1639 case -NFS4ERR_STALE_STATEID
:
1640 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1641 case -NFS4ERR_EXPIRED
:
1642 /* Don't recall a delegation if it was lost */
1643 nfs4_schedule_lease_recovery(server
->nfs_client
);
1645 case -NFS4ERR_MOVED
:
1646 nfs4_schedule_migration_recovery(server
);
1648 case -NFS4ERR_LEASE_MOVED
:
1649 nfs4_schedule_lease_moved_recovery(server
->nfs_client
);
1651 case -NFS4ERR_DELEG_REVOKED
:
1652 case -NFS4ERR_ADMIN_REVOKED
:
1653 case -NFS4ERR_BAD_STATEID
:
1654 case -NFS4ERR_OPENMODE
:
1655 nfs_inode_find_state_and_recover(state
->inode
,
1657 nfs4_schedule_stateid_recovery(server
, state
);
1659 case -NFS4ERR_DELAY
:
1660 case -NFS4ERR_GRACE
:
1661 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1665 case -NFS4ERR_DENIED
:
1666 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1672 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1674 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1675 struct nfs4_opendata
*opendata
;
1678 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1679 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1680 if (IS_ERR(opendata
))
1681 return PTR_ERR(opendata
);
1682 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1683 err
= nfs4_open_recover(opendata
, state
);
1684 nfs4_opendata_put(opendata
);
1685 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1688 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
1690 struct nfs4_opendata
*data
= calldata
;
1692 nfs40_setup_sequence(data
->o_arg
.server
, &data
->c_arg
.seq_args
,
1693 &data
->c_res
.seq_res
, task
);
1696 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1698 struct nfs4_opendata
*data
= calldata
;
1700 nfs40_sequence_done(task
, &data
->c_res
.seq_res
);
1702 data
->rpc_status
= task
->tk_status
;
1703 if (data
->rpc_status
== 0) {
1704 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1705 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1706 renew_lease(data
->o_res
.server
, data
->timestamp
);
1711 static void nfs4_open_confirm_release(void *calldata
)
1713 struct nfs4_opendata
*data
= calldata
;
1714 struct nfs4_state
*state
= NULL
;
1716 /* If this request hasn't been cancelled, do nothing */
1717 if (data
->cancelled
== 0)
1719 /* In case of error, no cleanup! */
1720 if (!data
->rpc_done
)
1722 state
= nfs4_opendata_to_nfs4_state(data
);
1724 nfs4_close_state(state
, data
->o_arg
.fmode
);
1726 nfs4_opendata_put(data
);
1729 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1730 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
1731 .rpc_call_done
= nfs4_open_confirm_done
,
1732 .rpc_release
= nfs4_open_confirm_release
,
1736 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1738 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1740 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1741 struct rpc_task
*task
;
1742 struct rpc_message msg
= {
1743 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1744 .rpc_argp
= &data
->c_arg
,
1745 .rpc_resp
= &data
->c_res
,
1746 .rpc_cred
= data
->owner
->so_cred
,
1748 struct rpc_task_setup task_setup_data
= {
1749 .rpc_client
= server
->client
,
1750 .rpc_message
= &msg
,
1751 .callback_ops
= &nfs4_open_confirm_ops
,
1752 .callback_data
= data
,
1753 .workqueue
= nfsiod_workqueue
,
1754 .flags
= RPC_TASK_ASYNC
,
1758 nfs4_init_sequence(&data
->c_arg
.seq_args
, &data
->c_res
.seq_res
, 1);
1759 kref_get(&data
->kref
);
1761 data
->rpc_status
= 0;
1762 data
->timestamp
= jiffies
;
1763 task
= rpc_run_task(&task_setup_data
);
1765 return PTR_ERR(task
);
1766 status
= nfs4_wait_for_completion_rpc_task(task
);
1768 data
->cancelled
= 1;
1771 status
= data
->rpc_status
;
1776 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1778 struct nfs4_opendata
*data
= calldata
;
1779 struct nfs4_state_owner
*sp
= data
->owner
;
1780 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1782 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1785 * Check if we still need to send an OPEN call, or if we can use
1786 * a delegation instead.
1788 if (data
->state
!= NULL
) {
1789 struct nfs_delegation
*delegation
;
1791 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1794 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1795 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1796 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1797 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1798 goto unlock_no_action
;
1801 /* Update client id. */
1802 data
->o_arg
.clientid
= clp
->cl_clientid
;
1803 switch (data
->o_arg
.claim
) {
1804 case NFS4_OPEN_CLAIM_PREVIOUS
:
1805 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1806 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1807 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1808 case NFS4_OPEN_CLAIM_FH
:
1809 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1810 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1812 data
->timestamp
= jiffies
;
1813 if (nfs4_setup_sequence(data
->o_arg
.server
,
1814 &data
->o_arg
.seq_args
,
1815 &data
->o_res
.seq_res
,
1817 nfs_release_seqid(data
->o_arg
.seqid
);
1819 /* Set the create mode (note dependency on the session type) */
1820 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1821 if (data
->o_arg
.open_flags
& O_EXCL
) {
1822 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1823 if (nfs4_has_persistent_session(clp
))
1824 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1825 else if (clp
->cl_mvops
->minor_version
> 0)
1826 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1832 task
->tk_action
= NULL
;
1834 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1837 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1839 struct nfs4_opendata
*data
= calldata
;
1841 data
->rpc_status
= task
->tk_status
;
1843 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1846 if (task
->tk_status
== 0) {
1847 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1848 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1852 data
->rpc_status
= -ELOOP
;
1855 data
->rpc_status
= -EISDIR
;
1858 data
->rpc_status
= -ENOTDIR
;
1861 renew_lease(data
->o_res
.server
, data
->timestamp
);
1862 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1863 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1868 static void nfs4_open_release(void *calldata
)
1870 struct nfs4_opendata
*data
= calldata
;
1871 struct nfs4_state
*state
= NULL
;
1873 /* If this request hasn't been cancelled, do nothing */
1874 if (data
->cancelled
== 0)
1876 /* In case of error, no cleanup! */
1877 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1879 /* In case we need an open_confirm, no cleanup! */
1880 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1882 state
= nfs4_opendata_to_nfs4_state(data
);
1884 nfs4_close_state(state
, data
->o_arg
.fmode
);
1886 nfs4_opendata_put(data
);
1889 static const struct rpc_call_ops nfs4_open_ops
= {
1890 .rpc_call_prepare
= nfs4_open_prepare
,
1891 .rpc_call_done
= nfs4_open_done
,
1892 .rpc_release
= nfs4_open_release
,
1895 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1897 struct inode
*dir
= data
->dir
->d_inode
;
1898 struct nfs_server
*server
= NFS_SERVER(dir
);
1899 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1900 struct nfs_openres
*o_res
= &data
->o_res
;
1901 struct rpc_task
*task
;
1902 struct rpc_message msg
= {
1903 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1906 .rpc_cred
= data
->owner
->so_cred
,
1908 struct rpc_task_setup task_setup_data
= {
1909 .rpc_client
= server
->client
,
1910 .rpc_message
= &msg
,
1911 .callback_ops
= &nfs4_open_ops
,
1912 .callback_data
= data
,
1913 .workqueue
= nfsiod_workqueue
,
1914 .flags
= RPC_TASK_ASYNC
,
1918 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1919 kref_get(&data
->kref
);
1921 data
->rpc_status
= 0;
1922 data
->cancelled
= 0;
1923 data
->is_recover
= 0;
1925 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1926 data
->is_recover
= 1;
1928 task
= rpc_run_task(&task_setup_data
);
1930 return PTR_ERR(task
);
1931 status
= nfs4_wait_for_completion_rpc_task(task
);
1933 data
->cancelled
= 1;
1936 status
= data
->rpc_status
;
1942 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1944 struct inode
*dir
= data
->dir
->d_inode
;
1945 struct nfs_openres
*o_res
= &data
->o_res
;
1948 status
= nfs4_run_open_task(data
, 1);
1949 if (status
!= 0 || !data
->rpc_done
)
1952 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1954 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1955 status
= _nfs4_proc_open_confirm(data
);
1964 * Additional permission checks in order to distinguish between an
1965 * open for read, and an open for execute. This works around the
1966 * fact that NFSv4 OPEN treats read and execute permissions as being
1968 * Note that in the non-execute case, we want to turn off permission
1969 * checking if we just created a new file (POSIX open() semantics).
1971 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1972 struct nfs4_opendata
*opendata
,
1973 struct nfs4_state
*state
, fmode_t fmode
,
1976 struct nfs_access_entry cache
;
1979 /* access call failed or for some reason the server doesn't
1980 * support any access modes -- defer access call until later */
1981 if (opendata
->o_res
.access_supported
== 0)
1986 * Use openflags to check for exec, because fmode won't
1987 * always have FMODE_EXEC set when file open for exec.
1989 if (openflags
& __FMODE_EXEC
) {
1990 /* ONLY check for exec rights */
1992 } else if ((fmode
& FMODE_READ
) && !opendata
->file_created
)
1996 cache
.jiffies
= jiffies
;
1997 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1998 nfs_access_add_cache(state
->inode
, &cache
);
2000 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
2003 /* even though OPEN succeeded, access is denied. Close the file */
2004 nfs4_close_state(state
, fmode
);
2009 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
2011 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
2013 struct inode
*dir
= data
->dir
->d_inode
;
2014 struct nfs_server
*server
= NFS_SERVER(dir
);
2015 struct nfs_openargs
*o_arg
= &data
->o_arg
;
2016 struct nfs_openres
*o_res
= &data
->o_res
;
2019 status
= nfs4_run_open_task(data
, 0);
2020 if (!data
->rpc_done
)
2023 if (status
== -NFS4ERR_BADNAME
&&
2024 !(o_arg
->open_flags
& O_CREAT
))
2029 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
2031 if (o_arg
->open_flags
& O_CREAT
) {
2032 update_changeattr(dir
, &o_res
->cinfo
);
2033 if (o_arg
->open_flags
& O_EXCL
)
2034 data
->file_created
= 1;
2035 else if (o_res
->cinfo
.before
!= o_res
->cinfo
.after
)
2036 data
->file_created
= 1;
2038 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
2039 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
2040 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
2041 status
= _nfs4_proc_open_confirm(data
);
2045 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
2046 nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
2050 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
2052 return nfs4_client_recover_expired_lease(server
->nfs_client
);
2057 * reclaim state on the server after a network partition.
2058 * Assumes caller holds the appropriate lock
2060 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2062 struct nfs4_opendata
*opendata
;
2065 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
2066 NFS4_OPEN_CLAIM_FH
);
2067 if (IS_ERR(opendata
))
2068 return PTR_ERR(opendata
);
2069 ret
= nfs4_open_recover(opendata
, state
);
2071 d_drop(ctx
->dentry
);
2072 nfs4_opendata_put(opendata
);
2076 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2078 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2079 struct nfs4_exception exception
= { };
2083 err
= _nfs4_open_expired(ctx
, state
);
2084 trace_nfs4_open_expired(ctx
, 0, err
);
2085 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2090 case -NFS4ERR_GRACE
:
2091 case -NFS4ERR_DELAY
:
2092 nfs4_handle_exception(server
, err
, &exception
);
2095 } while (exception
.retry
);
2100 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2102 struct nfs_open_context
*ctx
;
2105 ctx
= nfs4_state_find_open_context(state
);
2108 ret
= nfs4_do_open_expired(ctx
, state
);
2109 put_nfs_open_context(ctx
);
2113 #if defined(CONFIG_NFS_V4_1)
2114 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
2116 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2117 nfs4_stateid
*stateid
= &state
->stateid
;
2118 struct nfs_delegation
*delegation
;
2119 struct rpc_cred
*cred
= NULL
;
2120 int status
= -NFS4ERR_BAD_STATEID
;
2122 /* If a state reset has been done, test_stateid is unneeded */
2123 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
2126 /* Get the delegation credential for use by test/free_stateid */
2128 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2129 if (delegation
!= NULL
&&
2130 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
2131 cred
= get_rpccred(delegation
->cred
);
2133 status
= nfs41_test_stateid(server
, stateid
, cred
);
2134 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
2138 if (status
!= NFS_OK
) {
2139 /* Free the stateid unless the server explicitly
2140 * informs us the stateid is unrecognized. */
2141 if (status
!= -NFS4ERR_BAD_STATEID
)
2142 nfs41_free_stateid(server
, stateid
, cred
);
2143 nfs_remove_bad_delegation(state
->inode
);
2145 write_seqlock(&state
->seqlock
);
2146 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
2147 write_sequnlock(&state
->seqlock
);
2148 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2156 * nfs41_check_open_stateid - possibly free an open stateid
2158 * @state: NFSv4 state for an inode
2160 * Returns NFS_OK if recovery for this stateid is now finished.
2161 * Otherwise a negative NFS4ERR value is returned.
2163 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2165 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2166 nfs4_stateid
*stateid
= &state
->open_stateid
;
2167 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2170 /* If a state reset has been done, test_stateid is unneeded */
2171 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
2172 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
2173 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
2174 return -NFS4ERR_BAD_STATEID
;
2176 status
= nfs41_test_stateid(server
, stateid
, cred
);
2177 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2178 if (status
!= NFS_OK
) {
2179 /* Free the stateid unless the server explicitly
2180 * informs us the stateid is unrecognized. */
2181 if (status
!= -NFS4ERR_BAD_STATEID
)
2182 nfs41_free_stateid(server
, stateid
, cred
);
2184 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2185 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2186 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2187 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2192 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2196 nfs41_clear_delegation_stateid(state
);
2197 status
= nfs41_check_open_stateid(state
);
2198 if (status
!= NFS_OK
)
2199 status
= nfs4_open_expired(sp
, state
);
2205 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2206 * fields corresponding to attributes that were used to store the verifier.
2207 * Make sure we clobber those fields in the later setattr call
2209 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2211 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2212 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2213 sattr
->ia_valid
|= ATTR_ATIME
;
2215 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2216 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2217 sattr
->ia_valid
|= ATTR_MTIME
;
2220 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2223 struct nfs_open_context
*ctx
)
2225 struct nfs4_state_owner
*sp
= opendata
->owner
;
2226 struct nfs_server
*server
= sp
->so_server
;
2227 struct dentry
*dentry
;
2228 struct nfs4_state
*state
;
2232 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2234 ret
= _nfs4_proc_open(opendata
);
2236 if (ret
== -ENOENT
) {
2237 dentry
= opendata
->dentry
;
2238 if (dentry
->d_inode
)
2240 else if (d_unhashed(dentry
))
2241 d_add(dentry
, NULL
);
2243 nfs_set_verifier(dentry
,
2244 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2249 state
= nfs4_opendata_to_nfs4_state(opendata
);
2250 ret
= PTR_ERR(state
);
2253 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2254 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2256 dentry
= opendata
->dentry
;
2257 if (dentry
->d_inode
== NULL
) {
2258 /* FIXME: Is this d_drop() ever needed? */
2260 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2261 if (dentry
== NULL
) {
2262 dentry
= opendata
->dentry
;
2263 } else if (dentry
!= ctx
->dentry
) {
2265 ctx
->dentry
= dget(dentry
);
2267 nfs_set_verifier(dentry
,
2268 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2271 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2276 if (dentry
->d_inode
== state
->inode
) {
2277 nfs_inode_attach_open_context(ctx
);
2278 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2279 nfs4_schedule_stateid_recovery(server
, state
);
2286 * Returns a referenced nfs4_state
2288 static int _nfs4_do_open(struct inode
*dir
,
2289 struct nfs_open_context
*ctx
,
2291 struct iattr
*sattr
,
2292 struct nfs4_label
*label
,
2295 struct nfs4_state_owner
*sp
;
2296 struct nfs4_state
*state
= NULL
;
2297 struct nfs_server
*server
= NFS_SERVER(dir
);
2298 struct nfs4_opendata
*opendata
;
2299 struct dentry
*dentry
= ctx
->dentry
;
2300 struct rpc_cred
*cred
= ctx
->cred
;
2301 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2302 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2303 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2304 struct nfs4_label
*olabel
= NULL
;
2307 /* Protect against reboot recovery conflicts */
2309 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2311 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2314 status
= nfs4_recover_expired_lease(server
);
2316 goto err_put_state_owner
;
2317 if (dentry
->d_inode
!= NULL
)
2318 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2320 if (dentry
->d_inode
)
2321 claim
= NFS4_OPEN_CLAIM_FH
;
2322 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2323 label
, claim
, GFP_KERNEL
);
2324 if (opendata
== NULL
)
2325 goto err_put_state_owner
;
2328 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2329 if (IS_ERR(olabel
)) {
2330 status
= PTR_ERR(olabel
);
2331 goto err_opendata_put
;
2335 if (server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2336 if (!opendata
->f_attr
.mdsthreshold
) {
2337 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2338 if (!opendata
->f_attr
.mdsthreshold
)
2339 goto err_free_label
;
2341 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2343 if (dentry
->d_inode
!= NULL
)
2344 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2346 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2348 goto err_free_label
;
2351 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2352 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2353 nfs4_exclusive_attrset(opendata
, sattr
);
2355 nfs_fattr_init(opendata
->o_res
.f_attr
);
2356 status
= nfs4_do_setattr(state
->inode
, cred
,
2357 opendata
->o_res
.f_attr
, sattr
,
2358 state
, label
, olabel
);
2360 nfs_setattr_update_inode(state
->inode
, sattr
);
2361 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2362 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2365 if (opendata
->file_created
)
2366 *opened
|= FILE_CREATED
;
2368 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
)) {
2369 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2370 opendata
->f_attr
.mdsthreshold
= NULL
;
2373 nfs4_label_free(olabel
);
2375 nfs4_opendata_put(opendata
);
2376 nfs4_put_state_owner(sp
);
2379 nfs4_label_free(olabel
);
2381 nfs4_opendata_put(opendata
);
2382 err_put_state_owner
:
2383 nfs4_put_state_owner(sp
);
2389 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2390 struct nfs_open_context
*ctx
,
2392 struct iattr
*sattr
,
2393 struct nfs4_label
*label
,
2396 struct nfs_server
*server
= NFS_SERVER(dir
);
2397 struct nfs4_exception exception
= { };
2398 struct nfs4_state
*res
;
2402 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
, opened
);
2404 trace_nfs4_open_file(ctx
, flags
, status
);
2407 /* NOTE: BAD_SEQID means the server and client disagree about the
2408 * book-keeping w.r.t. state-changing operations
2409 * (OPEN/CLOSE/LOCK/LOCKU...)
2410 * It is actually a sign of a bug on the client or on the server.
2412 * If we receive a BAD_SEQID error in the particular case of
2413 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2414 * have unhashed the old state_owner for us, and that we can
2415 * therefore safely retry using a new one. We should still warn
2416 * the user though...
2418 if (status
== -NFS4ERR_BAD_SEQID
) {
2419 pr_warn_ratelimited("NFS: v4 server %s "
2420 " returned a bad sequence-id error!\n",
2421 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2422 exception
.retry
= 1;
2426 * BAD_STATEID on OPEN means that the server cancelled our
2427 * state before it received the OPEN_CONFIRM.
2428 * Recover by retrying the request as per the discussion
2429 * on Page 181 of RFC3530.
2431 if (status
== -NFS4ERR_BAD_STATEID
) {
2432 exception
.retry
= 1;
2435 if (status
== -EAGAIN
) {
2436 /* We must have found a delegation */
2437 exception
.retry
= 1;
2440 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2442 res
= ERR_PTR(nfs4_handle_exception(server
,
2443 status
, &exception
));
2444 } while (exception
.retry
);
2448 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2449 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2450 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2451 struct nfs4_label
*olabel
)
2453 struct nfs_server
*server
= NFS_SERVER(inode
);
2454 struct nfs_setattrargs arg
= {
2455 .fh
= NFS_FH(inode
),
2458 .bitmask
= server
->attr_bitmask
,
2461 struct nfs_setattrres res
= {
2466 struct rpc_message msg
= {
2467 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2472 unsigned long timestamp
= jiffies
;
2477 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2479 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2481 nfs_fattr_init(fattr
);
2483 /* Servers should only apply open mode checks for file size changes */
2484 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2485 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2487 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2488 /* Use that stateid */
2489 } else if (truncate
&& state
!= NULL
) {
2490 struct nfs_lockowner lockowner
= {
2491 .l_owner
= current
->files
,
2492 .l_pid
= current
->tgid
,
2494 if (!nfs4_valid_open_stateid(state
))
2496 if (nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2497 &lockowner
) == -EIO
)
2500 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2502 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2503 if (status
== 0 && state
!= NULL
)
2504 renew_lease(server
, timestamp
);
2508 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2509 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2510 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2511 struct nfs4_label
*olabel
)
2513 struct nfs_server
*server
= NFS_SERVER(inode
);
2514 struct nfs4_exception exception
= {
2520 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2521 trace_nfs4_setattr(inode
, err
);
2523 case -NFS4ERR_OPENMODE
:
2524 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2525 pr_warn_once("NFSv4: server %s is incorrectly "
2526 "applying open mode checks to "
2527 "a SETATTR that is not "
2528 "changing file size.\n",
2529 server
->nfs_client
->cl_hostname
);
2531 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2533 if (sattr
->ia_valid
& ATTR_OPEN
)
2538 err
= nfs4_handle_exception(server
, err
, &exception
);
2539 } while (exception
.retry
);
2544 struct nfs4_closedata
{
2545 struct inode
*inode
;
2546 struct nfs4_state
*state
;
2547 struct nfs_closeargs arg
;
2548 struct nfs_closeres res
;
2549 struct nfs_fattr fattr
;
2550 unsigned long timestamp
;
2555 static void nfs4_free_closedata(void *data
)
2557 struct nfs4_closedata
*calldata
= data
;
2558 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2559 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2562 pnfs_roc_release(calldata
->state
->inode
);
2563 nfs4_put_open_state(calldata
->state
);
2564 nfs_free_seqid(calldata
->arg
.seqid
);
2565 nfs4_put_state_owner(sp
);
2566 nfs_sb_deactive(sb
);
2570 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2572 struct nfs4_closedata
*calldata
= data
;
2573 struct nfs4_state
*state
= calldata
->state
;
2574 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2575 nfs4_stateid
*res_stateid
= NULL
;
2577 dprintk("%s: begin!\n", __func__
);
2578 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2580 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2581 /* hmm. we are done with the inode, and in the process of freeing
2582 * the state_owner. we keep this around to process errors
2584 switch (task
->tk_status
) {
2586 res_stateid
= &calldata
->res
.stateid
;
2587 if (calldata
->arg
.fmode
== 0 && calldata
->roc
)
2588 pnfs_roc_set_barrier(state
->inode
,
2589 calldata
->roc_barrier
);
2590 renew_lease(server
, calldata
->timestamp
);
2592 case -NFS4ERR_ADMIN_REVOKED
:
2593 case -NFS4ERR_STALE_STATEID
:
2594 case -NFS4ERR_OLD_STATEID
:
2595 case -NFS4ERR_BAD_STATEID
:
2596 case -NFS4ERR_EXPIRED
:
2597 if (calldata
->arg
.fmode
== 0)
2600 if (nfs4_async_handle_error(task
, server
, state
, NULL
) == -EAGAIN
) {
2601 rpc_restart_call_prepare(task
);
2605 nfs_clear_open_stateid(state
, res_stateid
, calldata
->arg
.fmode
);
2607 nfs_release_seqid(calldata
->arg
.seqid
);
2608 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2609 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2612 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2614 struct nfs4_closedata
*calldata
= data
;
2615 struct nfs4_state
*state
= calldata
->state
;
2616 struct inode
*inode
= calldata
->inode
;
2617 bool is_rdonly
, is_wronly
, is_rdwr
;
2620 dprintk("%s: begin!\n", __func__
);
2621 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2624 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2625 spin_lock(&state
->owner
->so_lock
);
2626 is_rdwr
= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2627 is_rdonly
= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2628 is_wronly
= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2629 /* Calculate the change in open mode */
2630 calldata
->arg
.fmode
= 0;
2631 if (state
->n_rdwr
== 0) {
2632 if (state
->n_rdonly
== 0)
2633 call_close
|= is_rdonly
;
2635 calldata
->arg
.fmode
|= FMODE_READ
;
2636 if (state
->n_wronly
== 0)
2637 call_close
|= is_wronly
;
2639 calldata
->arg
.fmode
|= FMODE_WRITE
;
2641 calldata
->arg
.fmode
|= FMODE_READ
|FMODE_WRITE
;
2643 if (calldata
->arg
.fmode
== 0)
2644 call_close
|= is_rdwr
;
2646 if (!nfs4_valid_open_stateid(state
))
2648 spin_unlock(&state
->owner
->so_lock
);
2651 /* Note: exit _without_ calling nfs4_close_done */
2655 if (calldata
->arg
.fmode
== 0) {
2656 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2657 if (calldata
->roc
&&
2658 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2659 nfs_release_seqid(calldata
->arg
.seqid
);
2664 nfs_fattr_init(calldata
->res
.fattr
);
2665 calldata
->timestamp
= jiffies
;
2666 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2667 &calldata
->arg
.seq_args
,
2668 &calldata
->res
.seq_res
,
2670 nfs_release_seqid(calldata
->arg
.seqid
);
2671 dprintk("%s: done!\n", __func__
);
2674 task
->tk_action
= NULL
;
2676 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2679 static const struct rpc_call_ops nfs4_close_ops
= {
2680 .rpc_call_prepare
= nfs4_close_prepare
,
2681 .rpc_call_done
= nfs4_close_done
,
2682 .rpc_release
= nfs4_free_closedata
,
2685 static bool nfs4_state_has_opener(struct nfs4_state
*state
)
2687 /* first check existing openers */
2688 if (test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0 &&
2689 state
->n_rdonly
!= 0)
2692 if (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0 &&
2693 state
->n_wronly
!= 0)
2696 if (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0 &&
2703 static bool nfs4_roc(struct inode
*inode
)
2705 struct nfs_inode
*nfsi
= NFS_I(inode
);
2706 struct nfs_open_context
*ctx
;
2707 struct nfs4_state
*state
;
2709 spin_lock(&inode
->i_lock
);
2710 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
2714 if (nfs4_state_has_opener(state
)) {
2715 spin_unlock(&inode
->i_lock
);
2719 spin_unlock(&inode
->i_lock
);
2721 if (nfs4_check_delegation(inode
, FMODE_READ
))
2724 return pnfs_roc(inode
);
2728 * It is possible for data to be read/written from a mem-mapped file
2729 * after the sys_close call (which hits the vfs layer as a flush).
2730 * This means that we can't safely call nfsv4 close on a file until
2731 * the inode is cleared. This in turn means that we are not good
2732 * NFSv4 citizens - we do not indicate to the server to update the file's
2733 * share state even when we are done with one of the three share
2734 * stateid's in the inode.
2736 * NOTE: Caller must be holding the sp->so_owner semaphore!
2738 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2740 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2741 struct nfs4_closedata
*calldata
;
2742 struct nfs4_state_owner
*sp
= state
->owner
;
2743 struct rpc_task
*task
;
2744 struct rpc_message msg
= {
2745 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2746 .rpc_cred
= state
->owner
->so_cred
,
2748 struct rpc_task_setup task_setup_data
= {
2749 .rpc_client
= server
->client
,
2750 .rpc_message
= &msg
,
2751 .callback_ops
= &nfs4_close_ops
,
2752 .workqueue
= nfsiod_workqueue
,
2753 .flags
= RPC_TASK_ASYNC
,
2755 int status
= -ENOMEM
;
2757 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_CLEANUP
,
2758 &task_setup_data
.rpc_client
, &msg
);
2760 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2761 if (calldata
== NULL
)
2763 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2764 calldata
->inode
= state
->inode
;
2765 calldata
->state
= state
;
2766 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2767 calldata
->arg
.stateid
= &state
->open_stateid
;
2768 /* Serialization for the sequence id */
2769 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2770 if (calldata
->arg
.seqid
== NULL
)
2771 goto out_free_calldata
;
2772 calldata
->arg
.fmode
= 0;
2773 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2774 calldata
->res
.fattr
= &calldata
->fattr
;
2775 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2776 calldata
->res
.server
= server
;
2777 calldata
->roc
= nfs4_roc(state
->inode
);
2778 nfs_sb_active(calldata
->inode
->i_sb
);
2780 msg
.rpc_argp
= &calldata
->arg
;
2781 msg
.rpc_resp
= &calldata
->res
;
2782 task_setup_data
.callback_data
= calldata
;
2783 task
= rpc_run_task(&task_setup_data
);
2785 return PTR_ERR(task
);
2788 status
= rpc_wait_for_completion_task(task
);
2794 nfs4_put_open_state(state
);
2795 nfs4_put_state_owner(sp
);
2799 static struct inode
*
2800 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
,
2801 int open_flags
, struct iattr
*attr
, int *opened
)
2803 struct nfs4_state
*state
;
2804 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2806 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2808 /* Protect against concurrent sillydeletes */
2809 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
, opened
);
2811 nfs4_label_release_security(label
);
2814 return ERR_CAST(state
);
2815 return state
->inode
;
2818 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2820 if (ctx
->state
== NULL
)
2823 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2825 nfs4_close_state(ctx
->state
, ctx
->mode
);
2828 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
2829 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
2830 #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_SECURITY_LABEL - 1UL)
2832 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2834 struct nfs4_server_caps_arg args
= {
2837 struct nfs4_server_caps_res res
= {};
2838 struct rpc_message msg
= {
2839 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2845 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2847 /* Sanity check the server answers */
2848 switch (server
->nfs_client
->cl_minorversion
) {
2850 res
.attr_bitmask
[1] &= FATTR4_WORD1_NFS40_MASK
;
2851 res
.attr_bitmask
[2] = 0;
2854 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS41_MASK
;
2857 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS42_MASK
;
2859 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2860 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2861 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2862 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2863 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2864 NFS_CAP_CTIME
|NFS_CAP_MTIME
|
2865 NFS_CAP_SECURITY_LABEL
);
2866 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
&&
2867 res
.acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
2868 server
->caps
|= NFS_CAP_ACLS
;
2869 if (res
.has_links
!= 0)
2870 server
->caps
|= NFS_CAP_HARDLINKS
;
2871 if (res
.has_symlinks
!= 0)
2872 server
->caps
|= NFS_CAP_SYMLINKS
;
2873 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2874 server
->caps
|= NFS_CAP_FILEID
;
2875 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2876 server
->caps
|= NFS_CAP_MODE
;
2877 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2878 server
->caps
|= NFS_CAP_NLINK
;
2879 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2880 server
->caps
|= NFS_CAP_OWNER
;
2881 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2882 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2883 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2884 server
->caps
|= NFS_CAP_ATIME
;
2885 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2886 server
->caps
|= NFS_CAP_CTIME
;
2887 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2888 server
->caps
|= NFS_CAP_MTIME
;
2889 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2890 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2891 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2893 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2894 sizeof(server
->attr_bitmask
));
2895 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2897 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2898 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2899 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2900 server
->cache_consistency_bitmask
[2] = 0;
2901 server
->acl_bitmask
= res
.acl_bitmask
;
2902 server
->fh_expire_type
= res
.fh_expire_type
;
2908 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2910 struct nfs4_exception exception
= { };
2913 err
= nfs4_handle_exception(server
,
2914 _nfs4_server_capabilities(server
, fhandle
),
2916 } while (exception
.retry
);
2920 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2921 struct nfs_fsinfo
*info
)
2924 struct nfs4_lookup_root_arg args
= {
2927 struct nfs4_lookup_res res
= {
2929 .fattr
= info
->fattr
,
2932 struct rpc_message msg
= {
2933 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2938 bitmask
[0] = nfs4_fattr_bitmap
[0];
2939 bitmask
[1] = nfs4_fattr_bitmap
[1];
2941 * Process the label in the upcoming getfattr
2943 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2945 nfs_fattr_init(info
->fattr
);
2946 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2949 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2950 struct nfs_fsinfo
*info
)
2952 struct nfs4_exception exception
= { };
2955 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2956 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2959 case -NFS4ERR_WRONGSEC
:
2962 err
= nfs4_handle_exception(server
, err
, &exception
);
2964 } while (exception
.retry
);
2969 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2970 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2972 struct rpc_auth_create_args auth_args
= {
2973 .pseudoflavor
= flavor
,
2975 struct rpc_auth
*auth
;
2978 auth
= rpcauth_create(&auth_args
, server
->client
);
2983 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2989 * Retry pseudoroot lookup with various security flavors. We do this when:
2991 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2992 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2994 * Returns zero on success, or a negative NFS4ERR value, or a
2995 * negative errno value.
2997 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2998 struct nfs_fsinfo
*info
)
3000 /* Per 3530bis 15.33.5 */
3001 static const rpc_authflavor_t flav_array
[] = {
3005 RPC_AUTH_UNIX
, /* courtesy */
3008 int status
= -EPERM
;
3011 if (server
->auth_info
.flavor_len
> 0) {
3012 /* try each flavor specified by user */
3013 for (i
= 0; i
< server
->auth_info
.flavor_len
; i
++) {
3014 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3015 server
->auth_info
.flavors
[i
]);
3016 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3021 /* no flavors specified by user, try default list */
3022 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
3023 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
3025 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
3032 * -EACCESS could mean that the user doesn't have correct permissions
3033 * to access the mount. It could also mean that we tried to mount
3034 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
3035 * existing mount programs don't handle -EACCES very well so it should
3036 * be mapped to -EPERM instead.
3038 if (status
== -EACCES
)
3043 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
3044 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
3046 int mv
= server
->nfs_client
->cl_minorversion
;
3047 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
3051 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
3052 * @server: initialized nfs_server handle
3053 * @fhandle: we fill in the pseudo-fs root file handle
3054 * @info: we fill in an FSINFO struct
3055 * @auth_probe: probe the auth flavours
3057 * Returns zero on success, or a negative errno.
3059 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3060 struct nfs_fsinfo
*info
,
3065 switch (auth_probe
) {
3067 status
= nfs4_lookup_root(server
, fhandle
, info
);
3068 if (status
!= -NFS4ERR_WRONGSEC
)
3071 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
3075 status
= nfs4_server_capabilities(server
, fhandle
);
3077 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
3079 return nfs4_map_errors(status
);
3082 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
3083 struct nfs_fsinfo
*info
)
3086 struct nfs_fattr
*fattr
= info
->fattr
;
3087 struct nfs4_label
*label
= NULL
;
3089 error
= nfs4_server_capabilities(server
, mntfh
);
3091 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
3095 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3097 return PTR_ERR(label
);
3099 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
3101 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
3102 goto err_free_label
;
3105 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
3106 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
3107 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
3110 nfs4_label_free(label
);
3116 * Get locations and (maybe) other attributes of a referral.
3117 * Note that we'll actually follow the referral later when
3118 * we detect fsid mismatch in inode revalidation
3120 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
3121 const struct qstr
*name
, struct nfs_fattr
*fattr
,
3122 struct nfs_fh
*fhandle
)
3124 int status
= -ENOMEM
;
3125 struct page
*page
= NULL
;
3126 struct nfs4_fs_locations
*locations
= NULL
;
3128 page
= alloc_page(GFP_KERNEL
);
3131 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
3132 if (locations
== NULL
)
3135 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
3140 * If the fsid didn't change, this is a migration event, not a
3141 * referral. Cause us to drop into the exception handler, which
3142 * will kick off migration recovery.
3144 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
3145 dprintk("%s: server did not return a different fsid for"
3146 " a referral at %s\n", __func__
, name
->name
);
3147 status
= -NFS4ERR_MOVED
;
3150 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3151 nfs_fixup_referral_attributes(&locations
->fattr
);
3153 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3154 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
3155 memset(fhandle
, 0, sizeof(struct nfs_fh
));
3163 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3164 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3166 struct nfs4_getattr_arg args
= {
3168 .bitmask
= server
->attr_bitmask
,
3170 struct nfs4_getattr_res res
= {
3175 struct rpc_message msg
= {
3176 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
3181 args
.bitmask
= nfs4_bitmask(server
, label
);
3183 nfs_fattr_init(fattr
);
3184 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3187 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3188 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3190 struct nfs4_exception exception
= { };
3193 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
3194 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
3195 err
= nfs4_handle_exception(server
, err
,
3197 } while (exception
.retry
);
3202 * The file is not closed if it is opened due to the a request to change
3203 * the size of the file. The open call will not be needed once the
3204 * VFS layer lookup-intents are implemented.
3206 * Close is called when the inode is destroyed.
3207 * If we haven't opened the file for O_WRONLY, we
3208 * need to in the size_change case to obtain a stateid.
3211 * Because OPEN is always done by name in nfsv4, it is
3212 * possible that we opened a different file by the same
3213 * name. We can recognize this race condition, but we
3214 * can't do anything about it besides returning an error.
3216 * This will be fixed with VFS changes (lookup-intent).
3219 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
3220 struct iattr
*sattr
)
3222 struct inode
*inode
= dentry
->d_inode
;
3223 struct rpc_cred
*cred
= NULL
;
3224 struct nfs4_state
*state
= NULL
;
3225 struct nfs4_label
*label
= NULL
;
3228 if (pnfs_ld_layoutret_on_setattr(inode
) &&
3229 sattr
->ia_valid
& ATTR_SIZE
&&
3230 sattr
->ia_size
< i_size_read(inode
))
3231 pnfs_commit_and_return_layout(inode
);
3233 nfs_fattr_init(fattr
);
3235 /* Deal with open(O_TRUNC) */
3236 if (sattr
->ia_valid
& ATTR_OPEN
)
3237 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
3239 /* Optimization: if the end result is no change, don't RPC */
3240 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
3243 /* Search for an existing open(O_WRITE) file */
3244 if (sattr
->ia_valid
& ATTR_FILE
) {
3245 struct nfs_open_context
*ctx
;
3247 ctx
= nfs_file_open_context(sattr
->ia_file
);
3254 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
3256 return PTR_ERR(label
);
3258 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
3260 nfs_setattr_update_inode(inode
, sattr
);
3261 nfs_setsecurity(inode
, fattr
, label
);
3263 nfs4_label_free(label
);
3267 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
3268 const struct qstr
*name
, struct nfs_fh
*fhandle
,
3269 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3271 struct nfs_server
*server
= NFS_SERVER(dir
);
3273 struct nfs4_lookup_arg args
= {
3274 .bitmask
= server
->attr_bitmask
,
3275 .dir_fh
= NFS_FH(dir
),
3278 struct nfs4_lookup_res res
= {
3284 struct rpc_message msg
= {
3285 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3290 args
.bitmask
= nfs4_bitmask(server
, label
);
3292 nfs_fattr_init(fattr
);
3294 dprintk("NFS call lookup %s\n", name
->name
);
3295 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3296 dprintk("NFS reply lookup: %d\n", status
);
3300 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3302 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3303 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3304 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3308 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3309 struct qstr
*name
, struct nfs_fh
*fhandle
,
3310 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3312 struct nfs4_exception exception
= { };
3313 struct rpc_clnt
*client
= *clnt
;
3316 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3317 trace_nfs4_lookup(dir
, name
, err
);
3319 case -NFS4ERR_BADNAME
:
3322 case -NFS4ERR_MOVED
:
3323 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3325 case -NFS4ERR_WRONGSEC
:
3327 if (client
!= *clnt
)
3329 client
= nfs4_negotiate_security(client
, dir
, name
);
3331 return PTR_ERR(client
);
3333 exception
.retry
= 1;
3336 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3338 } while (exception
.retry
);
3343 else if (client
!= *clnt
)
3344 rpc_shutdown_client(client
);
3349 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3350 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3351 struct nfs4_label
*label
)
3354 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3356 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3357 if (client
!= NFS_CLIENT(dir
)) {
3358 rpc_shutdown_client(client
);
3359 nfs_fixup_secinfo_attributes(fattr
);
3365 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3366 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3368 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3371 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3373 return ERR_PTR(status
);
3374 return (client
== NFS_CLIENT(dir
)) ? rpc_clone_client(client
) : client
;
3377 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3379 struct nfs_server
*server
= NFS_SERVER(inode
);
3380 struct nfs4_accessargs args
= {
3381 .fh
= NFS_FH(inode
),
3382 .bitmask
= server
->cache_consistency_bitmask
,
3384 struct nfs4_accessres res
= {
3387 struct rpc_message msg
= {
3388 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3391 .rpc_cred
= entry
->cred
,
3393 int mode
= entry
->mask
;
3397 * Determine which access bits we want to ask for...
3399 if (mode
& MAY_READ
)
3400 args
.access
|= NFS4_ACCESS_READ
;
3401 if (S_ISDIR(inode
->i_mode
)) {
3402 if (mode
& MAY_WRITE
)
3403 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3404 if (mode
& MAY_EXEC
)
3405 args
.access
|= NFS4_ACCESS_LOOKUP
;
3407 if (mode
& MAY_WRITE
)
3408 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3409 if (mode
& MAY_EXEC
)
3410 args
.access
|= NFS4_ACCESS_EXECUTE
;
3413 res
.fattr
= nfs_alloc_fattr();
3414 if (res
.fattr
== NULL
)
3417 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3419 nfs_access_set_mask(entry
, res
.access
);
3420 nfs_refresh_inode(inode
, res
.fattr
);
3422 nfs_free_fattr(res
.fattr
);
3426 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3428 struct nfs4_exception exception
= { };
3431 err
= _nfs4_proc_access(inode
, entry
);
3432 trace_nfs4_access(inode
, err
);
3433 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3435 } while (exception
.retry
);
3440 * TODO: For the time being, we don't try to get any attributes
3441 * along with any of the zero-copy operations READ, READDIR,
3444 * In the case of the first three, we want to put the GETATTR
3445 * after the read-type operation -- this is because it is hard
3446 * to predict the length of a GETATTR response in v4, and thus
3447 * align the READ data correctly. This means that the GETATTR
3448 * may end up partially falling into the page cache, and we should
3449 * shift it into the 'tail' of the xdr_buf before processing.
3450 * To do this efficiently, we need to know the total length
3451 * of data received, which doesn't seem to be available outside
3454 * In the case of WRITE, we also want to put the GETATTR after
3455 * the operation -- in this case because we want to make sure
3456 * we get the post-operation mtime and size.
3458 * Both of these changes to the XDR layer would in fact be quite
3459 * minor, but I decided to leave them for a subsequent patch.
3461 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3462 unsigned int pgbase
, unsigned int pglen
)
3464 struct nfs4_readlink args
= {
3465 .fh
= NFS_FH(inode
),
3470 struct nfs4_readlink_res res
;
3471 struct rpc_message msg
= {
3472 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3477 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3480 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3481 unsigned int pgbase
, unsigned int pglen
)
3483 struct nfs4_exception exception
= { };
3486 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3487 trace_nfs4_readlink(inode
, err
);
3488 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3490 } while (exception
.retry
);
3495 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3498 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3501 struct nfs4_label l
, *ilabel
= NULL
;
3502 struct nfs_open_context
*ctx
;
3503 struct nfs4_state
*state
;
3507 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3509 return PTR_ERR(ctx
);
3511 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3513 sattr
->ia_mode
&= ~current_umask();
3514 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
, &opened
);
3515 if (IS_ERR(state
)) {
3516 status
= PTR_ERR(state
);
3520 nfs4_label_release_security(ilabel
);
3521 put_nfs_open_context(ctx
);
3525 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3527 struct nfs_server
*server
= NFS_SERVER(dir
);
3528 struct nfs_removeargs args
= {
3532 struct nfs_removeres res
= {
3535 struct rpc_message msg
= {
3536 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3542 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3544 update_changeattr(dir
, &res
.cinfo
);
3548 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3550 struct nfs4_exception exception
= { };
3553 err
= _nfs4_proc_remove(dir
, name
);
3554 trace_nfs4_remove(dir
, name
, err
);
3555 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3557 } while (exception
.retry
);
3561 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3563 struct nfs_server
*server
= NFS_SERVER(dir
);
3564 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3565 struct nfs_removeres
*res
= msg
->rpc_resp
;
3567 res
->server
= server
;
3568 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3569 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3571 nfs_fattr_init(res
->dir_attr
);
3574 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3576 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3577 &data
->args
.seq_args
,
3582 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3584 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3585 struct nfs_removeres
*res
= &data
->res
;
3587 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3589 if (nfs4_async_handle_error(task
, res
->server
, NULL
,
3590 &data
->timeout
) == -EAGAIN
)
3592 update_changeattr(dir
, &res
->cinfo
);
3596 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3598 struct nfs_server
*server
= NFS_SERVER(dir
);
3599 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3600 struct nfs_renameres
*res
= msg
->rpc_resp
;
3602 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3603 res
->server
= server
;
3604 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3607 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3609 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3610 &data
->args
.seq_args
,
3615 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3616 struct inode
*new_dir
)
3618 struct nfs_renamedata
*data
= task
->tk_calldata
;
3619 struct nfs_renameres
*res
= &data
->res
;
3621 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3623 if (nfs4_async_handle_error(task
, res
->server
, NULL
, &data
->timeout
) == -EAGAIN
)
3626 update_changeattr(old_dir
, &res
->old_cinfo
);
3627 update_changeattr(new_dir
, &res
->new_cinfo
);
3631 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3633 struct nfs_server
*server
= NFS_SERVER(inode
);
3634 struct nfs4_link_arg arg
= {
3635 .fh
= NFS_FH(inode
),
3636 .dir_fh
= NFS_FH(dir
),
3638 .bitmask
= server
->attr_bitmask
,
3640 struct nfs4_link_res res
= {
3644 struct rpc_message msg
= {
3645 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3649 int status
= -ENOMEM
;
3651 res
.fattr
= nfs_alloc_fattr();
3652 if (res
.fattr
== NULL
)
3655 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3656 if (IS_ERR(res
.label
)) {
3657 status
= PTR_ERR(res
.label
);
3660 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3662 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3664 update_changeattr(dir
, &res
.cinfo
);
3665 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3667 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3671 nfs4_label_free(res
.label
);
3674 nfs_free_fattr(res
.fattr
);
3678 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3680 struct nfs4_exception exception
= { };
3683 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3684 _nfs4_proc_link(inode
, dir
, name
),
3686 } while (exception
.retry
);
3690 struct nfs4_createdata
{
3691 struct rpc_message msg
;
3692 struct nfs4_create_arg arg
;
3693 struct nfs4_create_res res
;
3695 struct nfs_fattr fattr
;
3696 struct nfs4_label
*label
;
3699 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3700 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3702 struct nfs4_createdata
*data
;
3704 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3706 struct nfs_server
*server
= NFS_SERVER(dir
);
3708 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3709 if (IS_ERR(data
->label
))
3712 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3713 data
->msg
.rpc_argp
= &data
->arg
;
3714 data
->msg
.rpc_resp
= &data
->res
;
3715 data
->arg
.dir_fh
= NFS_FH(dir
);
3716 data
->arg
.server
= server
;
3717 data
->arg
.name
= name
;
3718 data
->arg
.attrs
= sattr
;
3719 data
->arg
.ftype
= ftype
;
3720 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3721 data
->res
.server
= server
;
3722 data
->res
.fh
= &data
->fh
;
3723 data
->res
.fattr
= &data
->fattr
;
3724 data
->res
.label
= data
->label
;
3725 nfs_fattr_init(data
->res
.fattr
);
3733 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3735 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3736 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3738 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3739 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3744 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3746 nfs4_label_free(data
->label
);
3750 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3751 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3752 struct nfs4_label
*label
)
3754 struct nfs4_createdata
*data
;
3755 int status
= -ENAMETOOLONG
;
3757 if (len
> NFS4_MAXPATHLEN
)
3761 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3765 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3766 data
->arg
.u
.symlink
.pages
= &page
;
3767 data
->arg
.u
.symlink
.len
= len
;
3768 data
->arg
.label
= label
;
3770 status
= nfs4_do_create(dir
, dentry
, data
);
3772 nfs4_free_createdata(data
);
3777 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3778 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3780 struct nfs4_exception exception
= { };
3781 struct nfs4_label l
, *label
= NULL
;
3784 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3787 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3788 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3789 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3791 } while (exception
.retry
);
3793 nfs4_label_release_security(label
);
3797 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3798 struct iattr
*sattr
, struct nfs4_label
*label
)
3800 struct nfs4_createdata
*data
;
3801 int status
= -ENOMEM
;
3803 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3807 data
->arg
.label
= label
;
3808 status
= nfs4_do_create(dir
, dentry
, data
);
3810 nfs4_free_createdata(data
);
3815 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3816 struct iattr
*sattr
)
3818 struct nfs4_exception exception
= { };
3819 struct nfs4_label l
, *label
= NULL
;
3822 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3824 sattr
->ia_mode
&= ~current_umask();
3826 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3827 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3828 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3830 } while (exception
.retry
);
3831 nfs4_label_release_security(label
);
3836 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3837 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3839 struct inode
*dir
= dentry
->d_inode
;
3840 struct nfs4_readdir_arg args
= {
3845 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3848 struct nfs4_readdir_res res
;
3849 struct rpc_message msg
= {
3850 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3857 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__
,
3859 (unsigned long long)cookie
);
3860 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3861 res
.pgbase
= args
.pgbase
;
3862 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3864 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3865 status
+= args
.pgbase
;
3868 nfs_invalidate_atime(dir
);
3870 dprintk("%s: returns %d\n", __func__
, status
);
3874 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3875 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3877 struct nfs4_exception exception
= { };
3880 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3881 pages
, count
, plus
);
3882 trace_nfs4_readdir(dentry
->d_inode
, err
);
3883 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3885 } while (exception
.retry
);
3889 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3890 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3892 struct nfs4_createdata
*data
;
3893 int mode
= sattr
->ia_mode
;
3894 int status
= -ENOMEM
;
3896 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3901 data
->arg
.ftype
= NF4FIFO
;
3902 else if (S_ISBLK(mode
)) {
3903 data
->arg
.ftype
= NF4BLK
;
3904 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3905 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3907 else if (S_ISCHR(mode
)) {
3908 data
->arg
.ftype
= NF4CHR
;
3909 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3910 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3911 } else if (!S_ISSOCK(mode
)) {
3916 data
->arg
.label
= label
;
3917 status
= nfs4_do_create(dir
, dentry
, data
);
3919 nfs4_free_createdata(data
);
3924 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3925 struct iattr
*sattr
, dev_t rdev
)
3927 struct nfs4_exception exception
= { };
3928 struct nfs4_label l
, *label
= NULL
;
3931 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3933 sattr
->ia_mode
&= ~current_umask();
3935 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3936 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3937 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3939 } while (exception
.retry
);
3941 nfs4_label_release_security(label
);
3946 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3947 struct nfs_fsstat
*fsstat
)
3949 struct nfs4_statfs_arg args
= {
3951 .bitmask
= server
->attr_bitmask
,
3953 struct nfs4_statfs_res res
= {
3956 struct rpc_message msg
= {
3957 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3962 nfs_fattr_init(fsstat
->fattr
);
3963 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3966 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3968 struct nfs4_exception exception
= { };
3971 err
= nfs4_handle_exception(server
,
3972 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3974 } while (exception
.retry
);
3978 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3979 struct nfs_fsinfo
*fsinfo
)
3981 struct nfs4_fsinfo_arg args
= {
3983 .bitmask
= server
->attr_bitmask
,
3985 struct nfs4_fsinfo_res res
= {
3988 struct rpc_message msg
= {
3989 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3994 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3997 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3999 struct nfs4_exception exception
= { };
4000 unsigned long now
= jiffies
;
4004 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4005 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
4007 struct nfs_client
*clp
= server
->nfs_client
;
4009 spin_lock(&clp
->cl_lock
);
4010 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
4011 clp
->cl_last_renewal
= now
;
4012 spin_unlock(&clp
->cl_lock
);
4015 err
= nfs4_handle_exception(server
, err
, &exception
);
4016 } while (exception
.retry
);
4020 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
4024 nfs_fattr_init(fsinfo
->fattr
);
4025 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
4027 /* block layout checks this! */
4028 server
->pnfs_blksize
= fsinfo
->blksize
;
4029 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
4035 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4036 struct nfs_pathconf
*pathconf
)
4038 struct nfs4_pathconf_arg args
= {
4040 .bitmask
= server
->attr_bitmask
,
4042 struct nfs4_pathconf_res res
= {
4043 .pathconf
= pathconf
,
4045 struct rpc_message msg
= {
4046 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
4051 /* None of the pathconf attributes are mandatory to implement */
4052 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
4053 memset(pathconf
, 0, sizeof(*pathconf
));
4057 nfs_fattr_init(pathconf
->fattr
);
4058 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4061 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
4062 struct nfs_pathconf
*pathconf
)
4064 struct nfs4_exception exception
= { };
4068 err
= nfs4_handle_exception(server
,
4069 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
4071 } while (exception
.retry
);
4075 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
4076 const struct nfs_open_context
*ctx
,
4077 const struct nfs_lock_context
*l_ctx
,
4080 const struct nfs_lockowner
*lockowner
= NULL
;
4083 lockowner
= &l_ctx
->lockowner
;
4084 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
4086 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
4088 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
4089 const struct nfs_open_context
*ctx
,
4090 const struct nfs_lock_context
*l_ctx
,
4093 nfs4_stateid current_stateid
;
4095 /* If the current stateid represents a lost lock, then exit */
4096 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
) == -EIO
)
4098 return nfs4_stateid_match(stateid
, ¤t_stateid
);
4101 static bool nfs4_error_stateid_expired(int err
)
4104 case -NFS4ERR_DELEG_REVOKED
:
4105 case -NFS4ERR_ADMIN_REVOKED
:
4106 case -NFS4ERR_BAD_STATEID
:
4107 case -NFS4ERR_STALE_STATEID
:
4108 case -NFS4ERR_OLD_STATEID
:
4109 case -NFS4ERR_OPENMODE
:
4110 case -NFS4ERR_EXPIRED
:
4116 void __nfs4_read_done_cb(struct nfs_pgio_header
*hdr
)
4118 nfs_invalidate_atime(hdr
->inode
);
4121 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4123 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4125 trace_nfs4_read(hdr
, task
->tk_status
);
4126 if (nfs4_async_handle_error(task
, server
,
4127 hdr
->args
.context
->state
,
4129 rpc_restart_call_prepare(task
);
4133 __nfs4_read_done_cb(hdr
);
4134 if (task
->tk_status
> 0)
4135 renew_lease(server
, hdr
->timestamp
);
4139 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
4140 struct nfs_pgio_args
*args
)
4143 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4144 nfs4_stateid_is_current(&args
->stateid
,
4149 rpc_restart_call_prepare(task
);
4153 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4156 dprintk("--> %s\n", __func__
);
4158 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
4160 if (nfs4_read_stateid_changed(task
, &hdr
->args
))
4162 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
4163 nfs4_read_done_cb(task
, hdr
);
4166 static void nfs4_proc_read_setup(struct nfs_pgio_header
*hdr
,
4167 struct rpc_message
*msg
)
4169 hdr
->timestamp
= jiffies
;
4170 hdr
->pgio_done_cb
= nfs4_read_done_cb
;
4171 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
4172 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 0);
4175 static int nfs4_proc_pgio_rpc_prepare(struct rpc_task
*task
,
4176 struct nfs_pgio_header
*hdr
)
4178 if (nfs4_setup_sequence(NFS_SERVER(hdr
->inode
),
4179 &hdr
->args
.seq_args
,
4183 if (nfs4_set_rw_stateid(&hdr
->args
.stateid
, hdr
->args
.context
,
4184 hdr
->args
.lock_context
,
4185 hdr
->rw_ops
->rw_mode
) == -EIO
)
4187 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &hdr
->args
.context
->flags
)))
4192 static int nfs4_write_done_cb(struct rpc_task
*task
,
4193 struct nfs_pgio_header
*hdr
)
4195 struct inode
*inode
= hdr
->inode
;
4197 trace_nfs4_write(hdr
, task
->tk_status
);
4198 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
),
4199 hdr
->args
.context
->state
,
4201 rpc_restart_call_prepare(task
);
4204 if (task
->tk_status
>= 0) {
4205 renew_lease(NFS_SERVER(inode
), hdr
->timestamp
);
4206 nfs_post_op_update_inode_force_wcc(inode
, &hdr
->fattr
);
4211 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
4212 struct nfs_pgio_args
*args
)
4215 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4216 nfs4_stateid_is_current(&args
->stateid
,
4221 rpc_restart_call_prepare(task
);
4225 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_pgio_header
*hdr
)
4227 if (!nfs4_sequence_done(task
, &hdr
->res
.seq_res
))
4229 if (nfs4_write_stateid_changed(task
, &hdr
->args
))
4231 return hdr
->pgio_done_cb
? hdr
->pgio_done_cb(task
, hdr
) :
4232 nfs4_write_done_cb(task
, hdr
);
4236 bool nfs4_write_need_cache_consistency_data(struct nfs_pgio_header
*hdr
)
4238 /* Don't request attributes for pNFS or O_DIRECT writes */
4239 if (hdr
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
4241 /* Otherwise, request attributes if and only if we don't hold
4244 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
4247 static void nfs4_proc_write_setup(struct nfs_pgio_header
*hdr
,
4248 struct rpc_message
*msg
)
4250 struct nfs_server
*server
= NFS_SERVER(hdr
->inode
);
4252 if (!nfs4_write_need_cache_consistency_data(hdr
)) {
4253 hdr
->args
.bitmask
= NULL
;
4254 hdr
->res
.fattr
= NULL
;
4256 hdr
->args
.bitmask
= server
->cache_consistency_bitmask
;
4258 if (!hdr
->pgio_done_cb
)
4259 hdr
->pgio_done_cb
= nfs4_write_done_cb
;
4260 hdr
->res
.server
= server
;
4261 hdr
->timestamp
= jiffies
;
4263 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4264 nfs4_init_sequence(&hdr
->args
.seq_args
, &hdr
->res
.seq_res
, 1);
4267 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4269 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4270 &data
->args
.seq_args
,
4275 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4277 struct inode
*inode
= data
->inode
;
4279 trace_nfs4_commit(data
, task
->tk_status
);
4280 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
),
4281 NULL
, NULL
) == -EAGAIN
) {
4282 rpc_restart_call_prepare(task
);
4288 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4290 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4292 return data
->commit_done_cb(task
, data
);
4295 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4297 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4299 if (data
->commit_done_cb
== NULL
)
4300 data
->commit_done_cb
= nfs4_commit_done_cb
;
4301 data
->res
.server
= server
;
4302 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4303 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4306 struct nfs4_renewdata
{
4307 struct nfs_client
*client
;
4308 unsigned long timestamp
;
4312 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4313 * standalone procedure for queueing an asynchronous RENEW.
4315 static void nfs4_renew_release(void *calldata
)
4317 struct nfs4_renewdata
*data
= calldata
;
4318 struct nfs_client
*clp
= data
->client
;
4320 if (atomic_read(&clp
->cl_count
) > 1)
4321 nfs4_schedule_state_renewal(clp
);
4322 nfs_put_client(clp
);
4326 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4328 struct nfs4_renewdata
*data
= calldata
;
4329 struct nfs_client
*clp
= data
->client
;
4330 unsigned long timestamp
= data
->timestamp
;
4332 trace_nfs4_renew_async(clp
, task
->tk_status
);
4333 switch (task
->tk_status
) {
4336 case -NFS4ERR_LEASE_MOVED
:
4337 nfs4_schedule_lease_moved_recovery(clp
);
4340 /* Unless we're shutting down, schedule state recovery! */
4341 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4343 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4344 nfs4_schedule_lease_recovery(clp
);
4347 nfs4_schedule_path_down_recovery(clp
);
4349 do_renew_lease(clp
, timestamp
);
4352 static const struct rpc_call_ops nfs4_renew_ops
= {
4353 .rpc_call_done
= nfs4_renew_done
,
4354 .rpc_release
= nfs4_renew_release
,
4357 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4359 struct rpc_message msg
= {
4360 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4364 struct nfs4_renewdata
*data
;
4366 if (renew_flags
== 0)
4368 if (!atomic_inc_not_zero(&clp
->cl_count
))
4370 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4374 data
->timestamp
= jiffies
;
4375 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4376 &nfs4_renew_ops
, data
);
4379 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4381 struct rpc_message msg
= {
4382 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4386 unsigned long now
= jiffies
;
4389 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4392 do_renew_lease(clp
, now
);
4396 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4398 return server
->caps
& NFS_CAP_ACLS
;
4401 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4402 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4405 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4407 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4408 struct page
**pages
, unsigned int *pgbase
)
4410 struct page
*newpage
, **spages
;
4416 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4417 newpage
= alloc_page(GFP_KERNEL
);
4419 if (newpage
== NULL
)
4421 memcpy(page_address(newpage
), buf
, len
);
4426 } while (buflen
!= 0);
4432 __free_page(spages
[rc
-1]);
4436 struct nfs4_cached_acl
{
4442 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4444 struct nfs_inode
*nfsi
= NFS_I(inode
);
4446 spin_lock(&inode
->i_lock
);
4447 kfree(nfsi
->nfs4_acl
);
4448 nfsi
->nfs4_acl
= acl
;
4449 spin_unlock(&inode
->i_lock
);
4452 static void nfs4_zap_acl_attr(struct inode
*inode
)
4454 nfs4_set_cached_acl(inode
, NULL
);
4457 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4459 struct nfs_inode
*nfsi
= NFS_I(inode
);
4460 struct nfs4_cached_acl
*acl
;
4463 spin_lock(&inode
->i_lock
);
4464 acl
= nfsi
->nfs4_acl
;
4467 if (buf
== NULL
) /* user is just asking for length */
4469 if (acl
->cached
== 0)
4471 ret
= -ERANGE
; /* see getxattr(2) man page */
4472 if (acl
->len
> buflen
)
4474 memcpy(buf
, acl
->data
, acl
->len
);
4478 spin_unlock(&inode
->i_lock
);
4482 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4484 struct nfs4_cached_acl
*acl
;
4485 size_t buflen
= sizeof(*acl
) + acl_len
;
4487 if (buflen
<= PAGE_SIZE
) {
4488 acl
= kmalloc(buflen
, GFP_KERNEL
);
4492 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4494 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4501 nfs4_set_cached_acl(inode
, acl
);
4505 * The getxattr API returns the required buffer length when called with a
4506 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4507 * the required buf. On a NULL buf, we send a page of data to the server
4508 * guessing that the ACL request can be serviced by a page. If so, we cache
4509 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4510 * the cache. If not so, we throw away the page, and cache the required
4511 * length. The next getxattr call will then produce another round trip to
4512 * the server, this time with the input buf of the required size.
4514 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4516 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4517 struct nfs_getaclargs args
= {
4518 .fh
= NFS_FH(inode
),
4522 struct nfs_getaclres res
= {
4525 struct rpc_message msg
= {
4526 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4530 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4531 int ret
= -ENOMEM
, i
;
4533 /* As long as we're doing a round trip to the server anyway,
4534 * let's be prepared for a page of acl data. */
4537 if (npages
> ARRAY_SIZE(pages
))
4540 for (i
= 0; i
< npages
; i
++) {
4541 pages
[i
] = alloc_page(GFP_KERNEL
);
4546 /* for decoding across pages */
4547 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4548 if (!res
.acl_scratch
)
4551 args
.acl_len
= npages
* PAGE_SIZE
;
4552 args
.acl_pgbase
= 0;
4554 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4555 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4556 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4557 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4561 /* Handle the case where the passed-in buffer is too short */
4562 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4563 /* Did the user only issue a request for the acl length? */
4569 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4571 if (res
.acl_len
> buflen
) {
4575 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4580 for (i
= 0; i
< npages
; i
++)
4582 __free_page(pages
[i
]);
4583 if (res
.acl_scratch
)
4584 __free_page(res
.acl_scratch
);
4588 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4590 struct nfs4_exception exception
= { };
4593 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4594 trace_nfs4_get_acl(inode
, ret
);
4597 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4598 } while (exception
.retry
);
4602 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4604 struct nfs_server
*server
= NFS_SERVER(inode
);
4607 if (!nfs4_server_supports_acls(server
))
4609 ret
= nfs_revalidate_inode(server
, inode
);
4612 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4613 nfs_zap_acl_cache(inode
);
4614 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4616 /* -ENOENT is returned if there is no ACL or if there is an ACL
4617 * but no cached acl data, just the acl length */
4619 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4622 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4624 struct nfs_server
*server
= NFS_SERVER(inode
);
4625 struct page
*pages
[NFS4ACL_MAXPAGES
];
4626 struct nfs_setaclargs arg
= {
4627 .fh
= NFS_FH(inode
),
4631 struct nfs_setaclres res
;
4632 struct rpc_message msg
= {
4633 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4637 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4640 if (!nfs4_server_supports_acls(server
))
4642 if (npages
> ARRAY_SIZE(pages
))
4644 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4647 nfs4_inode_return_delegation(inode
);
4648 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4651 * Free each page after tx, so the only ref left is
4652 * held by the network stack
4655 put_page(pages
[i
-1]);
4658 * Acl update can result in inode attribute update.
4659 * so mark the attribute cache invalid.
4661 spin_lock(&inode
->i_lock
);
4662 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4663 spin_unlock(&inode
->i_lock
);
4664 nfs_access_zap_cache(inode
);
4665 nfs_zap_acl_cache(inode
);
4669 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4671 struct nfs4_exception exception
= { };
4674 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4675 trace_nfs4_set_acl(inode
, err
);
4676 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4678 } while (exception
.retry
);
4682 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4683 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4686 struct nfs_server
*server
= NFS_SERVER(inode
);
4687 struct nfs_fattr fattr
;
4688 struct nfs4_label label
= {0, 0, buflen
, buf
};
4690 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4691 struct nfs4_getattr_arg arg
= {
4692 .fh
= NFS_FH(inode
),
4695 struct nfs4_getattr_res res
= {
4700 struct rpc_message msg
= {
4701 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4707 nfs_fattr_init(&fattr
);
4709 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 0);
4712 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4714 if (buflen
< label
.len
)
4719 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4722 struct nfs4_exception exception
= { };
4725 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4729 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4730 trace_nfs4_get_security_label(inode
, err
);
4731 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4733 } while (exception
.retry
);
4737 static int _nfs4_do_set_security_label(struct inode
*inode
,
4738 struct nfs4_label
*ilabel
,
4739 struct nfs_fattr
*fattr
,
4740 struct nfs4_label
*olabel
)
4743 struct iattr sattr
= {0};
4744 struct nfs_server
*server
= NFS_SERVER(inode
);
4745 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4746 struct nfs_setattrargs arg
= {
4747 .fh
= NFS_FH(inode
),
4753 struct nfs_setattrres res
= {
4758 struct rpc_message msg
= {
4759 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4765 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
4767 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4769 dprintk("%s failed: %d\n", __func__
, status
);
4774 static int nfs4_do_set_security_label(struct inode
*inode
,
4775 struct nfs4_label
*ilabel
,
4776 struct nfs_fattr
*fattr
,
4777 struct nfs4_label
*olabel
)
4779 struct nfs4_exception exception
= { };
4783 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4785 trace_nfs4_set_security_label(inode
, err
);
4786 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4788 } while (exception
.retry
);
4793 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4795 struct nfs4_label ilabel
, *olabel
= NULL
;
4796 struct nfs_fattr fattr
;
4797 struct rpc_cred
*cred
;
4798 struct inode
*inode
= dentry
->d_inode
;
4801 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4804 nfs_fattr_init(&fattr
);
4808 ilabel
.label
= (char *)buf
;
4809 ilabel
.len
= buflen
;
4811 cred
= rpc_lookup_cred();
4813 return PTR_ERR(cred
);
4815 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4816 if (IS_ERR(olabel
)) {
4817 status
= -PTR_ERR(olabel
);
4821 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4823 nfs_setsecurity(inode
, &fattr
, olabel
);
4825 nfs4_label_free(olabel
);
4830 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4834 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
,
4835 struct nfs4_state
*state
, long *timeout
)
4837 struct nfs_client
*clp
= server
->nfs_client
;
4839 if (task
->tk_status
>= 0)
4841 switch(task
->tk_status
) {
4842 case -NFS4ERR_DELEG_REVOKED
:
4843 case -NFS4ERR_ADMIN_REVOKED
:
4844 case -NFS4ERR_BAD_STATEID
:
4847 nfs_remove_bad_delegation(state
->inode
);
4848 case -NFS4ERR_OPENMODE
:
4851 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4852 goto recovery_failed
;
4853 goto wait_on_recovery
;
4854 case -NFS4ERR_EXPIRED
:
4855 if (state
!= NULL
) {
4856 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4857 goto recovery_failed
;
4859 case -NFS4ERR_STALE_STATEID
:
4860 case -NFS4ERR_STALE_CLIENTID
:
4861 nfs4_schedule_lease_recovery(clp
);
4862 goto wait_on_recovery
;
4863 case -NFS4ERR_MOVED
:
4864 if (nfs4_schedule_migration_recovery(server
) < 0)
4865 goto recovery_failed
;
4866 goto wait_on_recovery
;
4867 case -NFS4ERR_LEASE_MOVED
:
4868 nfs4_schedule_lease_moved_recovery(clp
);
4869 goto wait_on_recovery
;
4870 #if defined(CONFIG_NFS_V4_1)
4871 case -NFS4ERR_BADSESSION
:
4872 case -NFS4ERR_BADSLOT
:
4873 case -NFS4ERR_BAD_HIGH_SLOT
:
4874 case -NFS4ERR_DEADSESSION
:
4875 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4876 case -NFS4ERR_SEQ_FALSE_RETRY
:
4877 case -NFS4ERR_SEQ_MISORDERED
:
4878 dprintk("%s ERROR %d, Reset session\n", __func__
,
4880 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4881 goto wait_on_recovery
;
4882 #endif /* CONFIG_NFS_V4_1 */
4883 case -NFS4ERR_DELAY
:
4884 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4885 rpc_delay(task
, nfs4_update_delay(timeout
));
4887 case -NFS4ERR_GRACE
:
4888 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4889 case -NFS4ERR_RETRY_UNCACHED_REP
:
4890 case -NFS4ERR_OLD_STATEID
:
4893 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4896 task
->tk_status
= -EIO
;
4899 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4900 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4901 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4902 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
4903 goto recovery_failed
;
4905 task
->tk_status
= 0;
4909 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4910 nfs4_verifier
*bootverf
)
4914 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4915 /* An impossible timestamp guarantees this value
4916 * will never match a generated boot time. */
4918 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4920 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4921 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4922 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4924 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4928 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4929 char *buf
, size_t len
)
4931 unsigned int result
;
4934 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4936 rpc_peeraddr2str(clp
->cl_rpcclient
,
4938 rpc_peeraddr2str(clp
->cl_rpcclient
,
4939 RPC_DISPLAY_PROTO
));
4945 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4946 char *buf
, size_t len
)
4948 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4950 if (nfs4_client_id_uniquifier
[0] != '\0')
4951 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4952 clp
->rpc_ops
->version
,
4953 clp
->cl_minorversion
,
4954 nfs4_client_id_uniquifier
,
4956 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4957 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4962 * nfs4_callback_up_net() starts only "tcp" and "tcp6" callback
4963 * services. Advertise one based on the address family of the
4967 nfs4_init_callback_netid(const struct nfs_client
*clp
, char *buf
, size_t len
)
4969 if (strchr(clp
->cl_ipaddr
, ':') != NULL
)
4970 return scnprintf(buf
, len
, "tcp6");
4972 return scnprintf(buf
, len
, "tcp");
4975 static void nfs4_setclientid_done(struct rpc_task
*task
, void *calldata
)
4977 struct nfs4_setclientid
*sc
= calldata
;
4979 if (task
->tk_status
== 0)
4980 sc
->sc_cred
= get_rpccred(task
->tk_rqstp
->rq_cred
);
4983 static const struct rpc_call_ops nfs4_setclientid_ops
= {
4984 .rpc_call_done
= nfs4_setclientid_done
,
4988 * nfs4_proc_setclientid - Negotiate client ID
4989 * @clp: state data structure
4990 * @program: RPC program for NFSv4 callback service
4991 * @port: IP port number for NFS4 callback service
4992 * @cred: RPC credential to use for this call
4993 * @res: where to place the result
4995 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4997 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4998 unsigned short port
, struct rpc_cred
*cred
,
4999 struct nfs4_setclientid_res
*res
)
5001 nfs4_verifier sc_verifier
;
5002 struct nfs4_setclientid setclientid
= {
5003 .sc_verifier
= &sc_verifier
,
5005 .sc_cb_ident
= clp
->cl_cb_ident
,
5007 struct rpc_message msg
= {
5008 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
5009 .rpc_argp
= &setclientid
,
5013 struct rpc_task
*task
;
5014 struct rpc_task_setup task_setup_data
= {
5015 .rpc_client
= clp
->cl_rpcclient
,
5016 .rpc_message
= &msg
,
5017 .callback_ops
= &nfs4_setclientid_ops
,
5018 .callback_data
= &setclientid
,
5019 .flags
= RPC_TASK_TIMEOUT
,
5023 /* nfs_client_id4 */
5024 nfs4_init_boot_verifier(clp
, &sc_verifier
);
5025 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
5026 setclientid
.sc_name_len
=
5027 nfs4_init_uniform_client_string(clp
,
5028 setclientid
.sc_name
,
5029 sizeof(setclientid
.sc_name
));
5031 setclientid
.sc_name_len
=
5032 nfs4_init_nonuniform_client_string(clp
,
5033 setclientid
.sc_name
,
5034 sizeof(setclientid
.sc_name
));
5036 setclientid
.sc_netid_len
=
5037 nfs4_init_callback_netid(clp
,
5038 setclientid
.sc_netid
,
5039 sizeof(setclientid
.sc_netid
));
5040 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
5041 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
5042 clp
->cl_ipaddr
, port
>> 8, port
& 255);
5044 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
5045 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5046 setclientid
.sc_name_len
, setclientid
.sc_name
);
5047 task
= rpc_run_task(&task_setup_data
);
5049 status
= PTR_ERR(task
);
5052 status
= task
->tk_status
;
5053 if (setclientid
.sc_cred
) {
5054 clp
->cl_acceptor
= rpcauth_stringify_acceptor(setclientid
.sc_cred
);
5055 put_rpccred(setclientid
.sc_cred
);
5059 trace_nfs4_setclientid(clp
, status
);
5060 dprintk("NFS reply setclientid: %d\n", status
);
5065 * nfs4_proc_setclientid_confirm - Confirm client ID
5066 * @clp: state data structure
5067 * @res: result of a previous SETCLIENTID
5068 * @cred: RPC credential to use for this call
5070 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5072 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
5073 struct nfs4_setclientid_res
*arg
,
5074 struct rpc_cred
*cred
)
5076 struct rpc_message msg
= {
5077 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
5083 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
5084 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
5086 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5087 trace_nfs4_setclientid_confirm(clp
, status
);
5088 dprintk("NFS reply setclientid_confirm: %d\n", status
);
5092 struct nfs4_delegreturndata
{
5093 struct nfs4_delegreturnargs args
;
5094 struct nfs4_delegreturnres res
;
5096 nfs4_stateid stateid
;
5097 unsigned long timestamp
;
5098 struct nfs_fattr fattr
;
5100 struct inode
*inode
;
5105 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
5107 struct nfs4_delegreturndata
*data
= calldata
;
5109 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5112 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
5113 switch (task
->tk_status
) {
5115 renew_lease(data
->res
.server
, data
->timestamp
);
5116 case -NFS4ERR_ADMIN_REVOKED
:
5117 case -NFS4ERR_DELEG_REVOKED
:
5118 case -NFS4ERR_BAD_STATEID
:
5119 case -NFS4ERR_OLD_STATEID
:
5120 case -NFS4ERR_STALE_STATEID
:
5121 case -NFS4ERR_EXPIRED
:
5122 task
->tk_status
= 0;
5124 pnfs_roc_set_barrier(data
->inode
, data
->roc_barrier
);
5127 if (nfs4_async_handle_error(task
, data
->res
.server
,
5128 NULL
, NULL
) == -EAGAIN
) {
5129 rpc_restart_call_prepare(task
);
5133 data
->rpc_status
= task
->tk_status
;
5136 static void nfs4_delegreturn_release(void *calldata
)
5138 struct nfs4_delegreturndata
*data
= calldata
;
5141 pnfs_roc_release(data
->inode
);
5145 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
5147 struct nfs4_delegreturndata
*d_data
;
5149 d_data
= (struct nfs4_delegreturndata
*)data
;
5152 pnfs_roc_drain(d_data
->inode
, &d_data
->roc_barrier
, task
))
5155 nfs4_setup_sequence(d_data
->res
.server
,
5156 &d_data
->args
.seq_args
,
5157 &d_data
->res
.seq_res
,
5161 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
5162 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
5163 .rpc_call_done
= nfs4_delegreturn_done
,
5164 .rpc_release
= nfs4_delegreturn_release
,
5167 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5169 struct nfs4_delegreturndata
*data
;
5170 struct nfs_server
*server
= NFS_SERVER(inode
);
5171 struct rpc_task
*task
;
5172 struct rpc_message msg
= {
5173 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
5176 struct rpc_task_setup task_setup_data
= {
5177 .rpc_client
= server
->client
,
5178 .rpc_message
= &msg
,
5179 .callback_ops
= &nfs4_delegreturn_ops
,
5180 .flags
= RPC_TASK_ASYNC
,
5184 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
5187 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
5188 data
->args
.fhandle
= &data
->fh
;
5189 data
->args
.stateid
= &data
->stateid
;
5190 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
5191 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
5192 nfs4_stateid_copy(&data
->stateid
, stateid
);
5193 data
->res
.fattr
= &data
->fattr
;
5194 data
->res
.server
= server
;
5195 nfs_fattr_init(data
->res
.fattr
);
5196 data
->timestamp
= jiffies
;
5197 data
->rpc_status
= 0;
5198 data
->inode
= inode
;
5199 data
->roc
= list_empty(&NFS_I(inode
)->open_files
) ?
5200 pnfs_roc(inode
) : false;
5202 task_setup_data
.callback_data
= data
;
5203 msg
.rpc_argp
= &data
->args
;
5204 msg
.rpc_resp
= &data
->res
;
5205 task
= rpc_run_task(&task_setup_data
);
5207 return PTR_ERR(task
);
5210 status
= nfs4_wait_for_completion_rpc_task(task
);
5213 status
= data
->rpc_status
;
5215 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
5217 nfs_refresh_inode(inode
, &data
->fattr
);
5223 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5225 struct nfs_server
*server
= NFS_SERVER(inode
);
5226 struct nfs4_exception exception
= { };
5229 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
5230 trace_nfs4_delegreturn(inode
, err
);
5232 case -NFS4ERR_STALE_STATEID
:
5233 case -NFS4ERR_EXPIRED
:
5237 err
= nfs4_handle_exception(server
, err
, &exception
);
5238 } while (exception
.retry
);
5242 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
5243 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
5246 * sleep, with exponential backoff, and retry the LOCK operation.
5248 static unsigned long
5249 nfs4_set_lock_task_retry(unsigned long timeout
)
5251 freezable_schedule_timeout_killable_unsafe(timeout
);
5253 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
5254 return NFS4_LOCK_MAXTIMEOUT
;
5258 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5260 struct inode
*inode
= state
->inode
;
5261 struct nfs_server
*server
= NFS_SERVER(inode
);
5262 struct nfs_client
*clp
= server
->nfs_client
;
5263 struct nfs_lockt_args arg
= {
5264 .fh
= NFS_FH(inode
),
5267 struct nfs_lockt_res res
= {
5270 struct rpc_message msg
= {
5271 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
5274 .rpc_cred
= state
->owner
->so_cred
,
5276 struct nfs4_lock_state
*lsp
;
5279 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
5280 status
= nfs4_set_lock_state(state
, request
);
5283 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5284 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5285 arg
.lock_owner
.s_dev
= server
->s_dev
;
5286 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5289 request
->fl_type
= F_UNLCK
;
5291 case -NFS4ERR_DENIED
:
5294 request
->fl_ops
->fl_release_private(request
);
5295 request
->fl_ops
= NULL
;
5300 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5302 struct nfs4_exception exception
= { };
5306 err
= _nfs4_proc_getlk(state
, cmd
, request
);
5307 trace_nfs4_get_lock(request
, state
, cmd
, err
);
5308 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
5310 } while (exception
.retry
);
5314 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5317 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5319 res
= posix_lock_file_wait(file
, fl
);
5322 res
= flock_lock_file_wait(file
, fl
);
5330 struct nfs4_unlockdata
{
5331 struct nfs_locku_args arg
;
5332 struct nfs_locku_res res
;
5333 struct nfs4_lock_state
*lsp
;
5334 struct nfs_open_context
*ctx
;
5335 struct file_lock fl
;
5336 const struct nfs_server
*server
;
5337 unsigned long timestamp
;
5340 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5341 struct nfs_open_context
*ctx
,
5342 struct nfs4_lock_state
*lsp
,
5343 struct nfs_seqid
*seqid
)
5345 struct nfs4_unlockdata
*p
;
5346 struct inode
*inode
= lsp
->ls_state
->inode
;
5348 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5351 p
->arg
.fh
= NFS_FH(inode
);
5353 p
->arg
.seqid
= seqid
;
5354 p
->res
.seqid
= seqid
;
5355 p
->arg
.stateid
= &lsp
->ls_stateid
;
5357 atomic_inc(&lsp
->ls_count
);
5358 /* Ensure we don't close file until we're done freeing locks! */
5359 p
->ctx
= get_nfs_open_context(ctx
);
5360 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5361 p
->server
= NFS_SERVER(inode
);
5365 static void nfs4_locku_release_calldata(void *data
)
5367 struct nfs4_unlockdata
*calldata
= data
;
5368 nfs_free_seqid(calldata
->arg
.seqid
);
5369 nfs4_put_lock_state(calldata
->lsp
);
5370 put_nfs_open_context(calldata
->ctx
);
5374 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5376 struct nfs4_unlockdata
*calldata
= data
;
5378 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5380 switch (task
->tk_status
) {
5382 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5383 &calldata
->res
.stateid
);
5384 renew_lease(calldata
->server
, calldata
->timestamp
);
5386 case -NFS4ERR_BAD_STATEID
:
5387 case -NFS4ERR_OLD_STATEID
:
5388 case -NFS4ERR_STALE_STATEID
:
5389 case -NFS4ERR_EXPIRED
:
5392 if (nfs4_async_handle_error(task
, calldata
->server
,
5393 NULL
, NULL
) == -EAGAIN
)
5394 rpc_restart_call_prepare(task
);
5396 nfs_release_seqid(calldata
->arg
.seqid
);
5399 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5401 struct nfs4_unlockdata
*calldata
= data
;
5403 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5405 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5406 /* Note: exit _without_ running nfs4_locku_done */
5409 calldata
->timestamp
= jiffies
;
5410 if (nfs4_setup_sequence(calldata
->server
,
5411 &calldata
->arg
.seq_args
,
5412 &calldata
->res
.seq_res
,
5414 nfs_release_seqid(calldata
->arg
.seqid
);
5417 task
->tk_action
= NULL
;
5419 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5422 static const struct rpc_call_ops nfs4_locku_ops
= {
5423 .rpc_call_prepare
= nfs4_locku_prepare
,
5424 .rpc_call_done
= nfs4_locku_done
,
5425 .rpc_release
= nfs4_locku_release_calldata
,
5428 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5429 struct nfs_open_context
*ctx
,
5430 struct nfs4_lock_state
*lsp
,
5431 struct nfs_seqid
*seqid
)
5433 struct nfs4_unlockdata
*data
;
5434 struct rpc_message msg
= {
5435 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5436 .rpc_cred
= ctx
->cred
,
5438 struct rpc_task_setup task_setup_data
= {
5439 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5440 .rpc_message
= &msg
,
5441 .callback_ops
= &nfs4_locku_ops
,
5442 .workqueue
= nfsiod_workqueue
,
5443 .flags
= RPC_TASK_ASYNC
,
5446 nfs4_state_protect(NFS_SERVER(lsp
->ls_state
->inode
)->nfs_client
,
5447 NFS_SP4_MACH_CRED_CLEANUP
, &task_setup_data
.rpc_client
, &msg
);
5449 /* Ensure this is an unlock - when canceling a lock, the
5450 * canceled lock is passed in, and it won't be an unlock.
5452 fl
->fl_type
= F_UNLCK
;
5454 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5456 nfs_free_seqid(seqid
);
5457 return ERR_PTR(-ENOMEM
);
5460 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5461 msg
.rpc_argp
= &data
->arg
;
5462 msg
.rpc_resp
= &data
->res
;
5463 task_setup_data
.callback_data
= data
;
5464 return rpc_run_task(&task_setup_data
);
5467 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5469 struct inode
*inode
= state
->inode
;
5470 struct nfs4_state_owner
*sp
= state
->owner
;
5471 struct nfs_inode
*nfsi
= NFS_I(inode
);
5472 struct nfs_seqid
*seqid
;
5473 struct nfs4_lock_state
*lsp
;
5474 struct rpc_task
*task
;
5476 unsigned char fl_flags
= request
->fl_flags
;
5478 status
= nfs4_set_lock_state(state
, request
);
5479 /* Unlock _before_ we do the RPC call */
5480 request
->fl_flags
|= FL_EXISTS
;
5481 /* Exclude nfs_delegation_claim_locks() */
5482 mutex_lock(&sp
->so_delegreturn_mutex
);
5483 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5484 down_read(&nfsi
->rwsem
);
5485 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5486 up_read(&nfsi
->rwsem
);
5487 mutex_unlock(&sp
->so_delegreturn_mutex
);
5490 up_read(&nfsi
->rwsem
);
5491 mutex_unlock(&sp
->so_delegreturn_mutex
);
5494 /* Is this a delegated lock? */
5495 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5496 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5498 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5502 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5503 status
= PTR_ERR(task
);
5506 status
= nfs4_wait_for_completion_rpc_task(task
);
5509 request
->fl_flags
= fl_flags
;
5510 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5514 struct nfs4_lockdata
{
5515 struct nfs_lock_args arg
;
5516 struct nfs_lock_res res
;
5517 struct nfs4_lock_state
*lsp
;
5518 struct nfs_open_context
*ctx
;
5519 struct file_lock fl
;
5520 unsigned long timestamp
;
5523 struct nfs_server
*server
;
5526 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5527 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5530 struct nfs4_lockdata
*p
;
5531 struct inode
*inode
= lsp
->ls_state
->inode
;
5532 struct nfs_server
*server
= NFS_SERVER(inode
);
5534 p
= kzalloc(sizeof(*p
), gfp_mask
);
5538 p
->arg
.fh
= NFS_FH(inode
);
5540 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5541 if (p
->arg
.open_seqid
== NULL
)
5543 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5544 if (p
->arg
.lock_seqid
== NULL
)
5545 goto out_free_seqid
;
5546 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5547 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5548 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5549 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5550 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5553 atomic_inc(&lsp
->ls_count
);
5554 p
->ctx
= get_nfs_open_context(ctx
);
5555 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5558 nfs_free_seqid(p
->arg
.open_seqid
);
5564 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5566 struct nfs4_lockdata
*data
= calldata
;
5567 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5569 dprintk("%s: begin!\n", __func__
);
5570 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5572 /* Do we need to do an open_to_lock_owner? */
5573 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5574 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5575 goto out_release_lock_seqid
;
5577 data
->arg
.open_stateid
= &state
->open_stateid
;
5578 data
->arg
.new_lock_owner
= 1;
5579 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5581 data
->arg
.new_lock_owner
= 0;
5582 if (!nfs4_valid_open_stateid(state
)) {
5583 data
->rpc_status
= -EBADF
;
5584 task
->tk_action
= NULL
;
5585 goto out_release_open_seqid
;
5587 data
->timestamp
= jiffies
;
5588 if (nfs4_setup_sequence(data
->server
,
5589 &data
->arg
.seq_args
,
5593 out_release_open_seqid
:
5594 nfs_release_seqid(data
->arg
.open_seqid
);
5595 out_release_lock_seqid
:
5596 nfs_release_seqid(data
->arg
.lock_seqid
);
5598 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5599 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5602 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5604 struct nfs4_lockdata
*data
= calldata
;
5606 dprintk("%s: begin!\n", __func__
);
5608 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5611 data
->rpc_status
= task
->tk_status
;
5612 if (data
->arg
.new_lock_owner
!= 0) {
5613 if (data
->rpc_status
== 0)
5614 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5618 if (data
->rpc_status
== 0) {
5619 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5620 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5621 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5624 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5627 static void nfs4_lock_release(void *calldata
)
5629 struct nfs4_lockdata
*data
= calldata
;
5631 dprintk("%s: begin!\n", __func__
);
5632 nfs_free_seqid(data
->arg
.open_seqid
);
5633 if (data
->cancelled
!= 0) {
5634 struct rpc_task
*task
;
5635 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5636 data
->arg
.lock_seqid
);
5638 rpc_put_task_async(task
);
5639 dprintk("%s: cancelling lock!\n", __func__
);
5641 nfs_free_seqid(data
->arg
.lock_seqid
);
5642 nfs4_put_lock_state(data
->lsp
);
5643 put_nfs_open_context(data
->ctx
);
5645 dprintk("%s: done!\n", __func__
);
5648 static const struct rpc_call_ops nfs4_lock_ops
= {
5649 .rpc_call_prepare
= nfs4_lock_prepare
,
5650 .rpc_call_done
= nfs4_lock_done
,
5651 .rpc_release
= nfs4_lock_release
,
5654 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5657 case -NFS4ERR_ADMIN_REVOKED
:
5658 case -NFS4ERR_BAD_STATEID
:
5659 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5660 if (new_lock_owner
!= 0 ||
5661 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5662 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5664 case -NFS4ERR_STALE_STATEID
:
5665 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5666 case -NFS4ERR_EXPIRED
:
5667 nfs4_schedule_lease_recovery(server
->nfs_client
);
5671 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5673 struct nfs4_lockdata
*data
;
5674 struct rpc_task
*task
;
5675 struct rpc_message msg
= {
5676 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5677 .rpc_cred
= state
->owner
->so_cred
,
5679 struct rpc_task_setup task_setup_data
= {
5680 .rpc_client
= NFS_CLIENT(state
->inode
),
5681 .rpc_message
= &msg
,
5682 .callback_ops
= &nfs4_lock_ops
,
5683 .workqueue
= nfsiod_workqueue
,
5684 .flags
= RPC_TASK_ASYNC
,
5688 dprintk("%s: begin!\n", __func__
);
5689 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5690 fl
->fl_u
.nfs4_fl
.owner
,
5691 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5695 data
->arg
.block
= 1;
5696 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5697 msg
.rpc_argp
= &data
->arg
;
5698 msg
.rpc_resp
= &data
->res
;
5699 task_setup_data
.callback_data
= data
;
5700 if (recovery_type
> NFS_LOCK_NEW
) {
5701 if (recovery_type
== NFS_LOCK_RECLAIM
)
5702 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5703 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5705 task
= rpc_run_task(&task_setup_data
);
5707 return PTR_ERR(task
);
5708 ret
= nfs4_wait_for_completion_rpc_task(task
);
5710 ret
= data
->rpc_status
;
5712 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5713 data
->arg
.new_lock_owner
, ret
);
5715 data
->cancelled
= 1;
5717 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5721 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5723 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5724 struct nfs4_exception exception
= {
5725 .inode
= state
->inode
,
5730 /* Cache the lock if possible... */
5731 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5733 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5734 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5735 if (err
!= -NFS4ERR_DELAY
)
5737 nfs4_handle_exception(server
, err
, &exception
);
5738 } while (exception
.retry
);
5742 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5744 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5745 struct nfs4_exception exception
= {
5746 .inode
= state
->inode
,
5750 err
= nfs4_set_lock_state(state
, request
);
5753 if (!recover_lost_locks
) {
5754 set_bit(NFS_LOCK_LOST
, &request
->fl_u
.nfs4_fl
.owner
->ls_flags
);
5758 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5760 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5761 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5765 case -NFS4ERR_GRACE
:
5766 case -NFS4ERR_DELAY
:
5767 nfs4_handle_exception(server
, err
, &exception
);
5770 } while (exception
.retry
);
5775 #if defined(CONFIG_NFS_V4_1)
5777 * nfs41_check_expired_locks - possibly free a lock stateid
5779 * @state: NFSv4 state for an inode
5781 * Returns NFS_OK if recovery for this stateid is now finished.
5782 * Otherwise a negative NFS4ERR value is returned.
5784 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5786 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5787 struct nfs4_lock_state
*lsp
;
5788 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5790 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5791 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5792 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5794 status
= nfs41_test_stateid(server
,
5797 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
5798 if (status
!= NFS_OK
) {
5799 /* Free the stateid unless the server
5800 * informs us the stateid is unrecognized. */
5801 if (status
!= -NFS4ERR_BAD_STATEID
)
5802 nfs41_free_stateid(server
,
5805 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5814 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5816 int status
= NFS_OK
;
5818 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5819 status
= nfs41_check_expired_locks(state
);
5820 if (status
!= NFS_OK
)
5821 status
= nfs4_lock_expired(state
, request
);
5826 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5828 struct nfs4_state_owner
*sp
= state
->owner
;
5829 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5830 unsigned char fl_flags
= request
->fl_flags
;
5832 int status
= -ENOLCK
;
5834 if ((fl_flags
& FL_POSIX
) &&
5835 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5837 /* Is this a delegated open? */
5838 status
= nfs4_set_lock_state(state
, request
);
5841 request
->fl_flags
|= FL_ACCESS
;
5842 status
= do_vfs_lock(request
->fl_file
, request
);
5845 down_read(&nfsi
->rwsem
);
5846 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5847 /* Yes: cache locks! */
5848 /* ...but avoid races with delegation recall... */
5849 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5850 status
= do_vfs_lock(request
->fl_file
, request
);
5853 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5854 up_read(&nfsi
->rwsem
);
5855 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5858 down_read(&nfsi
->rwsem
);
5859 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5860 status
= -NFS4ERR_DELAY
;
5863 /* Note: we always want to sleep here! */
5864 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5865 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5866 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5867 "manager!\n", __func__
);
5869 up_read(&nfsi
->rwsem
);
5871 request
->fl_flags
= fl_flags
;
5875 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5877 struct nfs4_exception exception
= {
5879 .inode
= state
->inode
,
5884 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5885 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5886 if (err
== -NFS4ERR_DENIED
)
5888 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5890 } while (exception
.retry
);
5895 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5897 struct nfs_open_context
*ctx
;
5898 struct nfs4_state
*state
;
5899 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5902 /* verify open state */
5903 ctx
= nfs_file_open_context(filp
);
5906 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5909 if (IS_GETLK(cmd
)) {
5911 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5915 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5918 if (request
->fl_type
== F_UNLCK
) {
5920 return nfs4_proc_unlck(state
, cmd
, request
);
5927 * Don't rely on the VFS having checked the file open mode,
5928 * since it won't do this for flock() locks.
5930 switch (request
->fl_type
) {
5932 if (!(filp
->f_mode
& FMODE_READ
))
5936 if (!(filp
->f_mode
& FMODE_WRITE
))
5941 status
= nfs4_proc_setlk(state
, cmd
, request
);
5942 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5944 timeout
= nfs4_set_lock_task_retry(timeout
);
5945 status
= -ERESTARTSYS
;
5948 } while(status
< 0);
5952 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5954 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5957 err
= nfs4_set_lock_state(state
, fl
);
5960 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5961 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5964 struct nfs_release_lockowner_data
{
5965 struct nfs4_lock_state
*lsp
;
5966 struct nfs_server
*server
;
5967 struct nfs_release_lockowner_args args
;
5968 struct nfs_release_lockowner_res res
;
5969 unsigned long timestamp
;
5972 static void nfs4_release_lockowner_prepare(struct rpc_task
*task
, void *calldata
)
5974 struct nfs_release_lockowner_data
*data
= calldata
;
5975 struct nfs_server
*server
= data
->server
;
5976 nfs40_setup_sequence(server
, &data
->args
.seq_args
,
5977 &data
->res
.seq_res
, task
);
5978 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5979 data
->timestamp
= jiffies
;
5982 static void nfs4_release_lockowner_done(struct rpc_task
*task
, void *calldata
)
5984 struct nfs_release_lockowner_data
*data
= calldata
;
5985 struct nfs_server
*server
= data
->server
;
5987 nfs40_sequence_done(task
, &data
->res
.seq_res
);
5989 switch (task
->tk_status
) {
5991 renew_lease(server
, data
->timestamp
);
5993 case -NFS4ERR_STALE_CLIENTID
:
5994 case -NFS4ERR_EXPIRED
:
5995 nfs4_schedule_lease_recovery(server
->nfs_client
);
5997 case -NFS4ERR_LEASE_MOVED
:
5998 case -NFS4ERR_DELAY
:
5999 if (nfs4_async_handle_error(task
, server
,
6000 NULL
, NULL
) == -EAGAIN
)
6001 rpc_restart_call_prepare(task
);
6005 static void nfs4_release_lockowner_release(void *calldata
)
6007 struct nfs_release_lockowner_data
*data
= calldata
;
6008 nfs4_free_lock_state(data
->server
, data
->lsp
);
6012 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
6013 .rpc_call_prepare
= nfs4_release_lockowner_prepare
,
6014 .rpc_call_done
= nfs4_release_lockowner_done
,
6015 .rpc_release
= nfs4_release_lockowner_release
,
6019 nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
6021 struct nfs_release_lockowner_data
*data
;
6022 struct rpc_message msg
= {
6023 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
6026 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
6029 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
6033 data
->server
= server
;
6034 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
6035 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
6036 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
6038 msg
.rpc_argp
= &data
->args
;
6039 msg
.rpc_resp
= &data
->res
;
6040 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
6041 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
6044 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
6046 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
6047 const void *buf
, size_t buflen
,
6048 int flags
, int type
)
6050 if (strcmp(key
, "") != 0)
6053 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
6056 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
6057 void *buf
, size_t buflen
, int type
)
6059 if (strcmp(key
, "") != 0)
6062 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
6065 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
6066 size_t list_len
, const char *name
,
6067 size_t name_len
, int type
)
6069 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
6071 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
6074 if (list
&& len
<= list_len
)
6075 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
6079 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
6080 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
6082 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
6085 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
6086 const void *buf
, size_t buflen
,
6087 int flags
, int type
)
6089 if (security_ismaclabel(key
))
6090 return nfs4_set_security_label(dentry
, buf
, buflen
);
6095 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
6096 void *buf
, size_t buflen
, int type
)
6098 if (security_ismaclabel(key
))
6099 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
6103 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
6104 size_t list_len
, const char *name
,
6105 size_t name_len
, int type
)
6109 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
6110 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
6111 if (list
&& len
<= list_len
)
6112 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
6117 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
6118 .prefix
= XATTR_SECURITY_PREFIX
,
6119 .list
= nfs4_xattr_list_nfs4_label
,
6120 .get
= nfs4_xattr_get_nfs4_label
,
6121 .set
= nfs4_xattr_set_nfs4_label
,
6127 * nfs_fhget will use either the mounted_on_fileid or the fileid
6129 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
6131 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
6132 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
6133 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
6134 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
6137 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
6138 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
6139 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
6143 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
6144 const struct qstr
*name
,
6145 struct nfs4_fs_locations
*fs_locations
,
6148 struct nfs_server
*server
= NFS_SERVER(dir
);
6150 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6152 struct nfs4_fs_locations_arg args
= {
6153 .dir_fh
= NFS_FH(dir
),
6158 struct nfs4_fs_locations_res res
= {
6159 .fs_locations
= fs_locations
,
6161 struct rpc_message msg
= {
6162 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6168 dprintk("%s: start\n", __func__
);
6170 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
6171 * is not supported */
6172 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
6173 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
6175 bitmask
[0] |= FATTR4_WORD0_FILEID
;
6177 nfs_fattr_init(&fs_locations
->fattr
);
6178 fs_locations
->server
= server
;
6179 fs_locations
->nlocations
= 0;
6180 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
6181 dprintk("%s: returned status = %d\n", __func__
, status
);
6185 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
6186 const struct qstr
*name
,
6187 struct nfs4_fs_locations
*fs_locations
,
6190 struct nfs4_exception exception
= { };
6193 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
6194 fs_locations
, page
);
6195 trace_nfs4_get_fs_locations(dir
, name
, err
);
6196 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6198 } while (exception
.retry
);
6203 * This operation also signals the server that this client is
6204 * performing migration recovery. The server can stop returning
6205 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
6206 * appended to this compound to identify the client ID which is
6207 * performing recovery.
6209 static int _nfs40_proc_get_locations(struct inode
*inode
,
6210 struct nfs4_fs_locations
*locations
,
6211 struct page
*page
, struct rpc_cred
*cred
)
6213 struct nfs_server
*server
= NFS_SERVER(inode
);
6214 struct rpc_clnt
*clnt
= server
->client
;
6216 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6218 struct nfs4_fs_locations_arg args
= {
6219 .clientid
= server
->nfs_client
->cl_clientid
,
6220 .fh
= NFS_FH(inode
),
6223 .migration
= 1, /* skip LOOKUP */
6224 .renew
= 1, /* append RENEW */
6226 struct nfs4_fs_locations_res res
= {
6227 .fs_locations
= locations
,
6231 struct rpc_message msg
= {
6232 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6237 unsigned long now
= jiffies
;
6240 nfs_fattr_init(&locations
->fattr
);
6241 locations
->server
= server
;
6242 locations
->nlocations
= 0;
6244 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6245 nfs4_set_sequence_privileged(&args
.seq_args
);
6246 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6247 &args
.seq_args
, &res
.seq_res
);
6251 renew_lease(server
, now
);
6255 #ifdef CONFIG_NFS_V4_1
6258 * This operation also signals the server that this client is
6259 * performing migration recovery. The server can stop asserting
6260 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
6261 * performing this operation is identified in the SEQUENCE
6262 * operation in this compound.
6264 * When the client supports GETATTR(fs_locations_info), it can
6265 * be plumbed in here.
6267 static int _nfs41_proc_get_locations(struct inode
*inode
,
6268 struct nfs4_fs_locations
*locations
,
6269 struct page
*page
, struct rpc_cred
*cred
)
6271 struct nfs_server
*server
= NFS_SERVER(inode
);
6272 struct rpc_clnt
*clnt
= server
->client
;
6274 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6276 struct nfs4_fs_locations_arg args
= {
6277 .fh
= NFS_FH(inode
),
6280 .migration
= 1, /* skip LOOKUP */
6282 struct nfs4_fs_locations_res res
= {
6283 .fs_locations
= locations
,
6286 struct rpc_message msg
= {
6287 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6294 nfs_fattr_init(&locations
->fattr
);
6295 locations
->server
= server
;
6296 locations
->nlocations
= 0;
6298 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6299 nfs4_set_sequence_privileged(&args
.seq_args
);
6300 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6301 &args
.seq_args
, &res
.seq_res
);
6302 if (status
== NFS4_OK
&&
6303 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6304 status
= -NFS4ERR_LEASE_MOVED
;
6308 #endif /* CONFIG_NFS_V4_1 */
6311 * nfs4_proc_get_locations - discover locations for a migrated FSID
6312 * @inode: inode on FSID that is migrating
6313 * @locations: result of query
6315 * @cred: credential to use for this operation
6317 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
6318 * operation failed, or a negative errno if a local error occurred.
6320 * On success, "locations" is filled in, but if the server has
6321 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
6324 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
6325 * from this client that require migration recovery.
6327 int nfs4_proc_get_locations(struct inode
*inode
,
6328 struct nfs4_fs_locations
*locations
,
6329 struct page
*page
, struct rpc_cred
*cred
)
6331 struct nfs_server
*server
= NFS_SERVER(inode
);
6332 struct nfs_client
*clp
= server
->nfs_client
;
6333 const struct nfs4_mig_recovery_ops
*ops
=
6334 clp
->cl_mvops
->mig_recovery_ops
;
6335 struct nfs4_exception exception
= { };
6338 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6339 (unsigned long long)server
->fsid
.major
,
6340 (unsigned long long)server
->fsid
.minor
,
6342 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6345 status
= ops
->get_locations(inode
, locations
, page
, cred
);
6346 if (status
!= -NFS4ERR_DELAY
)
6348 nfs4_handle_exception(server
, status
, &exception
);
6349 } while (exception
.retry
);
6354 * This operation also signals the server that this client is
6355 * performing "lease moved" recovery. The server can stop
6356 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
6357 * is appended to this compound to identify the client ID which is
6358 * performing recovery.
6360 static int _nfs40_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6362 struct nfs_server
*server
= NFS_SERVER(inode
);
6363 struct nfs_client
*clp
= NFS_SERVER(inode
)->nfs_client
;
6364 struct rpc_clnt
*clnt
= server
->client
;
6365 struct nfs4_fsid_present_arg args
= {
6366 .fh
= NFS_FH(inode
),
6367 .clientid
= clp
->cl_clientid
,
6368 .renew
= 1, /* append RENEW */
6370 struct nfs4_fsid_present_res res
= {
6373 struct rpc_message msg
= {
6374 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6379 unsigned long now
= jiffies
;
6382 res
.fh
= nfs_alloc_fhandle();
6386 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6387 nfs4_set_sequence_privileged(&args
.seq_args
);
6388 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6389 &args
.seq_args
, &res
.seq_res
);
6390 nfs_free_fhandle(res
.fh
);
6394 do_renew_lease(clp
, now
);
6398 #ifdef CONFIG_NFS_V4_1
6401 * This operation also signals the server that this client is
6402 * performing "lease moved" recovery. The server can stop asserting
6403 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
6404 * this operation is identified in the SEQUENCE operation in this
6407 static int _nfs41_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6409 struct nfs_server
*server
= NFS_SERVER(inode
);
6410 struct rpc_clnt
*clnt
= server
->client
;
6411 struct nfs4_fsid_present_arg args
= {
6412 .fh
= NFS_FH(inode
),
6414 struct nfs4_fsid_present_res res
= {
6416 struct rpc_message msg
= {
6417 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6424 res
.fh
= nfs_alloc_fhandle();
6428 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6429 nfs4_set_sequence_privileged(&args
.seq_args
);
6430 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6431 &args
.seq_args
, &res
.seq_res
);
6432 nfs_free_fhandle(res
.fh
);
6433 if (status
== NFS4_OK
&&
6434 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6435 status
= -NFS4ERR_LEASE_MOVED
;
6439 #endif /* CONFIG_NFS_V4_1 */
6442 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
6443 * @inode: inode on FSID to check
6444 * @cred: credential to use for this operation
6446 * Server indicates whether the FSID is present, moved, or not
6447 * recognized. This operation is necessary to clear a LEASE_MOVED
6448 * condition for this client ID.
6450 * Returns NFS4_OK if the FSID is present on this server,
6451 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
6452 * NFS4ERR code if some error occurred on the server, or a
6453 * negative errno if a local failure occurred.
6455 int nfs4_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6457 struct nfs_server
*server
= NFS_SERVER(inode
);
6458 struct nfs_client
*clp
= server
->nfs_client
;
6459 const struct nfs4_mig_recovery_ops
*ops
=
6460 clp
->cl_mvops
->mig_recovery_ops
;
6461 struct nfs4_exception exception
= { };
6464 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6465 (unsigned long long)server
->fsid
.major
,
6466 (unsigned long long)server
->fsid
.minor
,
6468 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6471 status
= ops
->fsid_present(inode
, cred
);
6472 if (status
!= -NFS4ERR_DELAY
)
6474 nfs4_handle_exception(server
, status
, &exception
);
6475 } while (exception
.retry
);
6480 * If 'use_integrity' is true and the state managment nfs_client
6481 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
6482 * and the machine credential as per RFC3530bis and RFC5661 Security
6483 * Considerations sections. Otherwise, just use the user cred with the
6484 * filesystem's rpc_client.
6486 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
6489 struct nfs4_secinfo_arg args
= {
6490 .dir_fh
= NFS_FH(dir
),
6493 struct nfs4_secinfo_res res
= {
6496 struct rpc_message msg
= {
6497 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
6501 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
6502 struct rpc_cred
*cred
= NULL
;
6504 if (use_integrity
) {
6505 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
6506 cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
6507 msg
.rpc_cred
= cred
;
6510 dprintk("NFS call secinfo %s\n", name
->name
);
6512 nfs4_state_protect(NFS_SERVER(dir
)->nfs_client
,
6513 NFS_SP4_MACH_CRED_SECINFO
, &clnt
, &msg
);
6515 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
6517 dprintk("NFS reply secinfo: %d\n", status
);
6525 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
6526 struct nfs4_secinfo_flavors
*flavors
)
6528 struct nfs4_exception exception
= { };
6531 err
= -NFS4ERR_WRONGSEC
;
6533 /* try to use integrity protection with machine cred */
6534 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
6535 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
6538 * if unable to use integrity protection, or SECINFO with
6539 * integrity protection returns NFS4ERR_WRONGSEC (which is
6540 * disallowed by spec, but exists in deployed servers) use
6541 * the current filesystem's rpc_client and the user cred.
6543 if (err
== -NFS4ERR_WRONGSEC
)
6544 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
6546 trace_nfs4_secinfo(dir
, name
, err
);
6547 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6549 } while (exception
.retry
);
6553 #ifdef CONFIG_NFS_V4_1
6555 * Check the exchange flags returned by the server for invalid flags, having
6556 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
6559 static int nfs4_check_cl_exchange_flags(u32 flags
)
6561 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
6563 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
6564 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
6566 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
6570 return -NFS4ERR_INVAL
;
6574 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
6575 struct nfs41_server_scope
*b
)
6577 if (a
->server_scope_sz
== b
->server_scope_sz
&&
6578 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
6585 * nfs4_proc_bind_conn_to_session()
6587 * The 4.1 client currently uses the same TCP connection for the
6588 * fore and backchannel.
6590 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6593 struct nfs41_bind_conn_to_session_res res
;
6594 struct rpc_message msg
= {
6596 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
6602 dprintk("--> %s\n", __func__
);
6604 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
6605 if (unlikely(res
.session
== NULL
)) {
6610 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6611 trace_nfs4_bind_conn_to_session(clp
, status
);
6613 if (memcmp(res
.session
->sess_id
.data
,
6614 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
6615 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
6619 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
6620 dprintk("NFS: %s: Unexpected direction from server\n",
6625 if (res
.use_conn_in_rdma_mode
) {
6626 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6635 dprintk("<-- %s status= %d\n", __func__
, status
);
6640 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
6641 * and operations we'd like to see to enable certain features in the allow map
6643 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request
= {
6644 .how
= SP4_MACH_CRED
,
6645 .enforce
.u
.words
= {
6646 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6647 1 << (OP_EXCHANGE_ID
- 32) |
6648 1 << (OP_CREATE_SESSION
- 32) |
6649 1 << (OP_DESTROY_SESSION
- 32) |
6650 1 << (OP_DESTROY_CLIENTID
- 32)
6653 [0] = 1 << (OP_CLOSE
) |
6656 [1] = 1 << (OP_SECINFO
- 32) |
6657 1 << (OP_SECINFO_NO_NAME
- 32) |
6658 1 << (OP_TEST_STATEID
- 32) |
6659 1 << (OP_FREE_STATEID
- 32) |
6660 1 << (OP_WRITE
- 32)
6665 * Select the state protection mode for client `clp' given the server results
6666 * from exchange_id in `sp'.
6668 * Returns 0 on success, negative errno otherwise.
6670 static int nfs4_sp4_select_mode(struct nfs_client
*clp
,
6671 struct nfs41_state_protection
*sp
)
6673 static const u32 supported_enforce
[NFS4_OP_MAP_NUM_WORDS
] = {
6674 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6675 1 << (OP_EXCHANGE_ID
- 32) |
6676 1 << (OP_CREATE_SESSION
- 32) |
6677 1 << (OP_DESTROY_SESSION
- 32) |
6678 1 << (OP_DESTROY_CLIENTID
- 32)
6682 if (sp
->how
== SP4_MACH_CRED
) {
6683 /* Print state protect result */
6684 dfprintk(MOUNT
, "Server SP4_MACH_CRED support:\n");
6685 for (i
= 0; i
<= LAST_NFS4_OP
; i
++) {
6686 if (test_bit(i
, sp
->enforce
.u
.longs
))
6687 dfprintk(MOUNT
, " enforce op %d\n", i
);
6688 if (test_bit(i
, sp
->allow
.u
.longs
))
6689 dfprintk(MOUNT
, " allow op %d\n", i
);
6692 /* make sure nothing is on enforce list that isn't supported */
6693 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++) {
6694 if (sp
->enforce
.u
.words
[i
] & ~supported_enforce
[i
]) {
6695 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6701 * Minimal mode - state operations are allowed to use machine
6702 * credential. Note this already happens by default, so the
6703 * client doesn't have to do anything more than the negotiation.
6705 * NOTE: we don't care if EXCHANGE_ID is in the list -
6706 * we're already using the machine cred for exchange_id
6707 * and will never use a different cred.
6709 if (test_bit(OP_BIND_CONN_TO_SESSION
, sp
->enforce
.u
.longs
) &&
6710 test_bit(OP_CREATE_SESSION
, sp
->enforce
.u
.longs
) &&
6711 test_bit(OP_DESTROY_SESSION
, sp
->enforce
.u
.longs
) &&
6712 test_bit(OP_DESTROY_CLIENTID
, sp
->enforce
.u
.longs
)) {
6713 dfprintk(MOUNT
, "sp4_mach_cred:\n");
6714 dfprintk(MOUNT
, " minimal mode enabled\n");
6715 set_bit(NFS_SP4_MACH_CRED_MINIMAL
, &clp
->cl_sp4_flags
);
6717 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6721 if (test_bit(OP_CLOSE
, sp
->allow
.u
.longs
) &&
6722 test_bit(OP_LOCKU
, sp
->allow
.u
.longs
)) {
6723 dfprintk(MOUNT
, " cleanup mode enabled\n");
6724 set_bit(NFS_SP4_MACH_CRED_CLEANUP
, &clp
->cl_sp4_flags
);
6727 if (test_bit(OP_SECINFO
, sp
->allow
.u
.longs
) &&
6728 test_bit(OP_SECINFO_NO_NAME
, sp
->allow
.u
.longs
)) {
6729 dfprintk(MOUNT
, " secinfo mode enabled\n");
6730 set_bit(NFS_SP4_MACH_CRED_SECINFO
, &clp
->cl_sp4_flags
);
6733 if (test_bit(OP_TEST_STATEID
, sp
->allow
.u
.longs
) &&
6734 test_bit(OP_FREE_STATEID
, sp
->allow
.u
.longs
)) {
6735 dfprintk(MOUNT
, " stateid mode enabled\n");
6736 set_bit(NFS_SP4_MACH_CRED_STATEID
, &clp
->cl_sp4_flags
);
6739 if (test_bit(OP_WRITE
, sp
->allow
.u
.longs
)) {
6740 dfprintk(MOUNT
, " write mode enabled\n");
6741 set_bit(NFS_SP4_MACH_CRED_WRITE
, &clp
->cl_sp4_flags
);
6744 if (test_bit(OP_COMMIT
, sp
->allow
.u
.longs
)) {
6745 dfprintk(MOUNT
, " commit mode enabled\n");
6746 set_bit(NFS_SP4_MACH_CRED_COMMIT
, &clp
->cl_sp4_flags
);
6754 * _nfs4_proc_exchange_id()
6756 * Wrapper for EXCHANGE_ID operation.
6758 static int _nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
,
6761 nfs4_verifier verifier
;
6762 struct nfs41_exchange_id_args args
= {
6763 .verifier
= &verifier
,
6765 #ifdef CONFIG_NFS_V4_1_MIGRATION
6766 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6767 EXCHGID4_FLAG_BIND_PRINC_STATEID
|
6768 EXCHGID4_FLAG_SUPP_MOVED_MIGR
,
6770 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6771 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
6774 struct nfs41_exchange_id_res res
= {
6778 struct rpc_message msg
= {
6779 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
6785 nfs4_init_boot_verifier(clp
, &verifier
);
6786 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
6788 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6789 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
6790 args
.id_len
, args
.id
);
6792 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6794 if (unlikely(res
.server_owner
== NULL
)) {
6799 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6801 if (unlikely(res
.server_scope
== NULL
)) {
6803 goto out_server_owner
;
6806 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6807 if (unlikely(res
.impl_id
== NULL
)) {
6809 goto out_server_scope
;
6814 args
.state_protect
.how
= SP4_NONE
;
6818 args
.state_protect
= nfs4_sp4_mach_cred_request
;
6825 goto out_server_scope
;
6828 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6829 trace_nfs4_exchange_id(clp
, status
);
6831 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6834 status
= nfs4_sp4_select_mode(clp
, &res
.state_protect
);
6837 clp
->cl_clientid
= res
.clientid
;
6838 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6839 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6840 clp
->cl_seqid
= res
.seqid
;
6842 kfree(clp
->cl_serverowner
);
6843 clp
->cl_serverowner
= res
.server_owner
;
6844 res
.server_owner
= NULL
;
6846 /* use the most recent implementation id */
6847 kfree(clp
->cl_implid
);
6848 clp
->cl_implid
= res
.impl_id
;
6850 if (clp
->cl_serverscope
!= NULL
&&
6851 !nfs41_same_server_scope(clp
->cl_serverscope
,
6852 res
.server_scope
)) {
6853 dprintk("%s: server_scope mismatch detected\n",
6855 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6856 kfree(clp
->cl_serverscope
);
6857 clp
->cl_serverscope
= NULL
;
6860 if (clp
->cl_serverscope
== NULL
) {
6861 clp
->cl_serverscope
= res
.server_scope
;
6868 kfree(res
.server_owner
);
6870 kfree(res
.server_scope
);
6872 if (clp
->cl_implid
!= NULL
)
6873 dprintk("NFS reply exchange_id: Server Implementation ID: "
6874 "domain: %s, name: %s, date: %llu,%u\n",
6875 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6876 clp
->cl_implid
->date
.seconds
,
6877 clp
->cl_implid
->date
.nseconds
);
6878 dprintk("NFS reply exchange_id: %d\n", status
);
6883 * nfs4_proc_exchange_id()
6885 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6887 * Since the clientid has expired, all compounds using sessions
6888 * associated with the stale clientid will be returning
6889 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6890 * be in some phase of session reset.
6892 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
6894 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6896 rpc_authflavor_t authflavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
6899 /* try SP4_MACH_CRED if krb5i/p */
6900 if (authflavor
== RPC_AUTH_GSS_KRB5I
||
6901 authflavor
== RPC_AUTH_GSS_KRB5P
) {
6902 status
= _nfs4_proc_exchange_id(clp
, cred
, SP4_MACH_CRED
);
6908 return _nfs4_proc_exchange_id(clp
, cred
, SP4_NONE
);
6911 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6912 struct rpc_cred
*cred
)
6914 struct rpc_message msg
= {
6915 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6921 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6922 trace_nfs4_destroy_clientid(clp
, status
);
6924 dprintk("NFS: Got error %d from the server %s on "
6925 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6929 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6930 struct rpc_cred
*cred
)
6935 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6936 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6938 case -NFS4ERR_DELAY
:
6939 case -NFS4ERR_CLIENTID_BUSY
:
6949 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6951 struct rpc_cred
*cred
;
6954 if (clp
->cl_mvops
->minor_version
< 1)
6956 if (clp
->cl_exchange_flags
== 0)
6958 if (clp
->cl_preserve_clid
)
6960 cred
= nfs4_get_clid_cred(clp
);
6961 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6966 case -NFS4ERR_STALE_CLIENTID
:
6967 clp
->cl_exchange_flags
= 0;
6973 struct nfs4_get_lease_time_data
{
6974 struct nfs4_get_lease_time_args
*args
;
6975 struct nfs4_get_lease_time_res
*res
;
6976 struct nfs_client
*clp
;
6979 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6982 struct nfs4_get_lease_time_data
*data
=
6983 (struct nfs4_get_lease_time_data
*)calldata
;
6985 dprintk("--> %s\n", __func__
);
6986 /* just setup sequence, do not trigger session recovery
6987 since we're invoked within one */
6988 nfs41_setup_sequence(data
->clp
->cl_session
,
6989 &data
->args
->la_seq_args
,
6990 &data
->res
->lr_seq_res
,
6992 dprintk("<-- %s\n", __func__
);
6996 * Called from nfs4_state_manager thread for session setup, so don't recover
6997 * from sequence operation or clientid errors.
6999 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
7001 struct nfs4_get_lease_time_data
*data
=
7002 (struct nfs4_get_lease_time_data
*)calldata
;
7004 dprintk("--> %s\n", __func__
);
7005 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
7007 switch (task
->tk_status
) {
7008 case -NFS4ERR_DELAY
:
7009 case -NFS4ERR_GRACE
:
7010 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
7011 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
7012 task
->tk_status
= 0;
7014 case -NFS4ERR_RETRY_UNCACHED_REP
:
7015 rpc_restart_call_prepare(task
);
7018 dprintk("<-- %s\n", __func__
);
7021 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
7022 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
7023 .rpc_call_done
= nfs4_get_lease_time_done
,
7026 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
7028 struct rpc_task
*task
;
7029 struct nfs4_get_lease_time_args args
;
7030 struct nfs4_get_lease_time_res res
= {
7031 .lr_fsinfo
= fsinfo
,
7033 struct nfs4_get_lease_time_data data
= {
7038 struct rpc_message msg
= {
7039 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
7043 struct rpc_task_setup task_setup
= {
7044 .rpc_client
= clp
->cl_rpcclient
,
7045 .rpc_message
= &msg
,
7046 .callback_ops
= &nfs4_get_lease_time_ops
,
7047 .callback_data
= &data
,
7048 .flags
= RPC_TASK_TIMEOUT
,
7052 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
7053 nfs4_set_sequence_privileged(&args
.la_seq_args
);
7054 dprintk("--> %s\n", __func__
);
7055 task
= rpc_run_task(&task_setup
);
7058 status
= PTR_ERR(task
);
7060 status
= task
->tk_status
;
7063 dprintk("<-- %s return %d\n", __func__
, status
);
7069 * Initialize the values to be used by the client in CREATE_SESSION
7070 * If nfs4_init_session set the fore channel request and response sizes,
7073 * Set the back channel max_resp_sz_cached to zero to force the client to
7074 * always set csa_cachethis to FALSE because the current implementation
7075 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
7077 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
7079 unsigned int max_rqst_sz
, max_resp_sz
;
7081 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
7082 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
7084 /* Fore channel attributes */
7085 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
7086 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
7087 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
7088 args
->fc_attrs
.max_reqs
= max_session_slots
;
7090 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
7091 "max_ops=%u max_reqs=%u\n",
7093 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
7094 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
7096 /* Back channel attributes */
7097 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
7098 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
7099 args
->bc_attrs
.max_resp_sz_cached
= 0;
7100 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
7101 args
->bc_attrs
.max_reqs
= 1;
7103 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
7104 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
7106 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
7107 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
7108 args
->bc_attrs
.max_reqs
);
7111 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
7113 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
7114 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
7116 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
7119 * Our requested max_ops is the minimum we need; we're not
7120 * prepared to break up compounds into smaller pieces than that.
7121 * So, no point even trying to continue if the server won't
7124 if (rcvd
->max_ops
< sent
->max_ops
)
7126 if (rcvd
->max_reqs
== 0)
7128 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
7129 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
7133 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
7135 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
7136 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
7138 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
7140 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
7142 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
7144 /* These would render the backchannel useless: */
7145 if (rcvd
->max_ops
!= sent
->max_ops
)
7147 if (rcvd
->max_reqs
!= sent
->max_reqs
)
7152 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
7153 struct nfs4_session
*session
)
7157 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
7160 return nfs4_verify_back_channel_attrs(args
, session
);
7163 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
7164 struct rpc_cred
*cred
)
7166 struct nfs4_session
*session
= clp
->cl_session
;
7167 struct nfs41_create_session_args args
= {
7169 .cb_program
= NFS4_CALLBACK
,
7171 struct nfs41_create_session_res res
= {
7174 struct rpc_message msg
= {
7175 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
7182 nfs4_init_channel_attrs(&args
);
7183 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
7185 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7186 trace_nfs4_create_session(clp
, status
);
7189 /* Verify the session's negotiated channel_attrs values */
7190 status
= nfs4_verify_channel_attrs(&args
, session
);
7191 /* Increment the clientid slot sequence id */
7199 * Issues a CREATE_SESSION operation to the server.
7200 * It is the responsibility of the caller to verify the session is
7201 * expired before calling this routine.
7203 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7207 struct nfs4_session
*session
= clp
->cl_session
;
7209 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
7211 status
= _nfs4_proc_create_session(clp
, cred
);
7215 /* Init or reset the session slot tables */
7216 status
= nfs4_setup_session_slot_tables(session
);
7217 dprintk("slot table setup returned %d\n", status
);
7221 ptr
= (unsigned *)&session
->sess_id
.data
[0];
7222 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
7223 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
7225 dprintk("<-- %s\n", __func__
);
7230 * Issue the over-the-wire RPC DESTROY_SESSION.
7231 * The caller must serialize access to this routine.
7233 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
7234 struct rpc_cred
*cred
)
7236 struct rpc_message msg
= {
7237 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
7238 .rpc_argp
= session
,
7243 dprintk("--> nfs4_proc_destroy_session\n");
7245 /* session is still being setup */
7246 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
7249 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7250 trace_nfs4_destroy_session(session
->clp
, status
);
7253 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
7254 "Session has been destroyed regardless...\n", status
);
7256 dprintk("<-- nfs4_proc_destroy_session\n");
7261 * Renew the cl_session lease.
7263 struct nfs4_sequence_data
{
7264 struct nfs_client
*clp
;
7265 struct nfs4_sequence_args args
;
7266 struct nfs4_sequence_res res
;
7269 static void nfs41_sequence_release(void *data
)
7271 struct nfs4_sequence_data
*calldata
= data
;
7272 struct nfs_client
*clp
= calldata
->clp
;
7274 if (atomic_read(&clp
->cl_count
) > 1)
7275 nfs4_schedule_state_renewal(clp
);
7276 nfs_put_client(clp
);
7280 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7282 switch(task
->tk_status
) {
7283 case -NFS4ERR_DELAY
:
7284 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7287 nfs4_schedule_lease_recovery(clp
);
7292 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
7294 struct nfs4_sequence_data
*calldata
= data
;
7295 struct nfs_client
*clp
= calldata
->clp
;
7297 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
7300 trace_nfs4_sequence(clp
, task
->tk_status
);
7301 if (task
->tk_status
< 0) {
7302 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
7303 if (atomic_read(&clp
->cl_count
) == 1)
7306 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
7307 rpc_restart_call_prepare(task
);
7311 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
7313 dprintk("<-- %s\n", __func__
);
7316 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
7318 struct nfs4_sequence_data
*calldata
= data
;
7319 struct nfs_client
*clp
= calldata
->clp
;
7320 struct nfs4_sequence_args
*args
;
7321 struct nfs4_sequence_res
*res
;
7323 args
= task
->tk_msg
.rpc_argp
;
7324 res
= task
->tk_msg
.rpc_resp
;
7326 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
7329 static const struct rpc_call_ops nfs41_sequence_ops
= {
7330 .rpc_call_done
= nfs41_sequence_call_done
,
7331 .rpc_call_prepare
= nfs41_sequence_prepare
,
7332 .rpc_release
= nfs41_sequence_release
,
7335 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
7336 struct rpc_cred
*cred
,
7339 struct nfs4_sequence_data
*calldata
;
7340 struct rpc_message msg
= {
7341 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
7344 struct rpc_task_setup task_setup_data
= {
7345 .rpc_client
= clp
->cl_rpcclient
,
7346 .rpc_message
= &msg
,
7347 .callback_ops
= &nfs41_sequence_ops
,
7348 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
7351 if (!atomic_inc_not_zero(&clp
->cl_count
))
7352 return ERR_PTR(-EIO
);
7353 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7354 if (calldata
== NULL
) {
7355 nfs_put_client(clp
);
7356 return ERR_PTR(-ENOMEM
);
7358 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0);
7360 nfs4_set_sequence_privileged(&calldata
->args
);
7361 msg
.rpc_argp
= &calldata
->args
;
7362 msg
.rpc_resp
= &calldata
->res
;
7363 calldata
->clp
= clp
;
7364 task_setup_data
.callback_data
= calldata
;
7366 return rpc_run_task(&task_setup_data
);
7369 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
7371 struct rpc_task
*task
;
7374 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
7376 task
= _nfs41_proc_sequence(clp
, cred
, false);
7378 ret
= PTR_ERR(task
);
7380 rpc_put_task_async(task
);
7381 dprintk("<-- %s status=%d\n", __func__
, ret
);
7385 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7387 struct rpc_task
*task
;
7390 task
= _nfs41_proc_sequence(clp
, cred
, true);
7392 ret
= PTR_ERR(task
);
7395 ret
= rpc_wait_for_completion_task(task
);
7397 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
7399 if (task
->tk_status
== 0)
7400 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
7401 ret
= task
->tk_status
;
7405 dprintk("<-- %s status=%d\n", __func__
, ret
);
7409 struct nfs4_reclaim_complete_data
{
7410 struct nfs_client
*clp
;
7411 struct nfs41_reclaim_complete_args arg
;
7412 struct nfs41_reclaim_complete_res res
;
7415 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
7417 struct nfs4_reclaim_complete_data
*calldata
= data
;
7419 nfs41_setup_sequence(calldata
->clp
->cl_session
,
7420 &calldata
->arg
.seq_args
,
7421 &calldata
->res
.seq_res
,
7425 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7427 switch(task
->tk_status
) {
7429 case -NFS4ERR_COMPLETE_ALREADY
:
7430 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
7432 case -NFS4ERR_DELAY
:
7433 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7435 case -NFS4ERR_RETRY_UNCACHED_REP
:
7438 nfs4_schedule_lease_recovery(clp
);
7443 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
7445 struct nfs4_reclaim_complete_data
*calldata
= data
;
7446 struct nfs_client
*clp
= calldata
->clp
;
7447 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
7449 dprintk("--> %s\n", __func__
);
7450 if (!nfs41_sequence_done(task
, res
))
7453 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
7454 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
7455 rpc_restart_call_prepare(task
);
7458 dprintk("<-- %s\n", __func__
);
7461 static void nfs4_free_reclaim_complete_data(void *data
)
7463 struct nfs4_reclaim_complete_data
*calldata
= data
;
7468 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
7469 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
7470 .rpc_call_done
= nfs4_reclaim_complete_done
,
7471 .rpc_release
= nfs4_free_reclaim_complete_data
,
7475 * Issue a global reclaim complete.
7477 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
7478 struct rpc_cred
*cred
)
7480 struct nfs4_reclaim_complete_data
*calldata
;
7481 struct rpc_task
*task
;
7482 struct rpc_message msg
= {
7483 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
7486 struct rpc_task_setup task_setup_data
= {
7487 .rpc_client
= clp
->cl_rpcclient
,
7488 .rpc_message
= &msg
,
7489 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
7490 .flags
= RPC_TASK_ASYNC
,
7492 int status
= -ENOMEM
;
7494 dprintk("--> %s\n", __func__
);
7495 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7496 if (calldata
== NULL
)
7498 calldata
->clp
= clp
;
7499 calldata
->arg
.one_fs
= 0;
7501 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
7502 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
7503 msg
.rpc_argp
= &calldata
->arg
;
7504 msg
.rpc_resp
= &calldata
->res
;
7505 task_setup_data
.callback_data
= calldata
;
7506 task
= rpc_run_task(&task_setup_data
);
7508 status
= PTR_ERR(task
);
7511 status
= nfs4_wait_for_completion_rpc_task(task
);
7513 status
= task
->tk_status
;
7517 dprintk("<-- %s status=%d\n", __func__
, status
);
7522 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
7524 struct nfs4_layoutget
*lgp
= calldata
;
7525 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
7526 struct nfs4_session
*session
= nfs4_get_session(server
);
7528 dprintk("--> %s\n", __func__
);
7529 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
7530 * right now covering the LAYOUTGET we are about to send.
7531 * However, that is not so catastrophic, and there seems
7532 * to be no way to prevent it completely.
7534 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
7535 &lgp
->res
.seq_res
, task
))
7537 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
7538 NFS_I(lgp
->args
.inode
)->layout
,
7539 lgp
->args
.ctx
->state
)) {
7540 rpc_exit(task
, NFS4_OK
);
7544 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
7546 struct nfs4_layoutget
*lgp
= calldata
;
7547 struct inode
*inode
= lgp
->args
.inode
;
7548 struct nfs_server
*server
= NFS_SERVER(inode
);
7549 struct pnfs_layout_hdr
*lo
;
7550 struct nfs4_state
*state
= NULL
;
7551 unsigned long timeo
, now
, giveup
;
7553 dprintk("--> %s tk_status => %d\n", __func__
, -task
->tk_status
);
7555 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
7558 switch (task
->tk_status
) {
7562 * NFS4ERR_LAYOUTTRYLATER is a conflict with another client
7563 * (or clients) writing to the same RAID stripe
7565 case -NFS4ERR_LAYOUTTRYLATER
:
7567 * NFS4ERR_RECALLCONFLICT is when conflict with self (must recall
7568 * existing layout before getting a new one).
7570 case -NFS4ERR_RECALLCONFLICT
:
7571 timeo
= rpc_get_timeout(task
->tk_client
);
7572 giveup
= lgp
->args
.timestamp
+ timeo
;
7574 if (time_after(giveup
, now
)) {
7575 unsigned long delay
;
7578 * - Not less then NFS4_POLL_RETRY_MIN.
7579 * - One last time a jiffie before we give up
7580 * - exponential backoff (time_now minus start_attempt)
7582 delay
= max_t(unsigned long, NFS4_POLL_RETRY_MIN
,
7583 min((giveup
- now
- 1),
7584 now
- lgp
->args
.timestamp
));
7586 dprintk("%s: NFS4ERR_RECALLCONFLICT waiting %lu\n",
7588 rpc_delay(task
, delay
);
7589 task
->tk_status
= 0;
7590 rpc_restart_call_prepare(task
);
7591 goto out
; /* Do not call nfs4_async_handle_error() */
7594 case -NFS4ERR_EXPIRED
:
7595 case -NFS4ERR_BAD_STATEID
:
7596 spin_lock(&inode
->i_lock
);
7597 lo
= NFS_I(inode
)->layout
;
7598 if (!lo
|| list_empty(&lo
->plh_segs
)) {
7599 spin_unlock(&inode
->i_lock
);
7600 /* If the open stateid was bad, then recover it. */
7601 state
= lgp
->args
.ctx
->state
;
7606 * Mark the bad layout state as invalid, then retry
7607 * with the current stateid.
7609 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
7610 spin_unlock(&inode
->i_lock
);
7611 pnfs_free_lseg_list(&head
);
7613 task
->tk_status
= 0;
7614 rpc_restart_call_prepare(task
);
7617 if (nfs4_async_handle_error(task
, server
, state
, NULL
) == -EAGAIN
)
7618 rpc_restart_call_prepare(task
);
7620 dprintk("<-- %s\n", __func__
);
7623 static size_t max_response_pages(struct nfs_server
*server
)
7625 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
7626 return nfs_page_array_len(0, max_resp_sz
);
7629 static void nfs4_free_pages(struct page
**pages
, size_t size
)
7636 for (i
= 0; i
< size
; i
++) {
7639 __free_page(pages
[i
]);
7644 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
7646 struct page
**pages
;
7649 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
7651 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
7655 for (i
= 0; i
< size
; i
++) {
7656 pages
[i
] = alloc_page(gfp_flags
);
7658 dprintk("%s: failed to allocate page\n", __func__
);
7659 nfs4_free_pages(pages
, size
);
7667 static void nfs4_layoutget_release(void *calldata
)
7669 struct nfs4_layoutget
*lgp
= calldata
;
7670 struct inode
*inode
= lgp
->args
.inode
;
7671 struct nfs_server
*server
= NFS_SERVER(inode
);
7672 size_t max_pages
= max_response_pages(server
);
7674 dprintk("--> %s\n", __func__
);
7675 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
7676 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
7677 put_nfs_open_context(lgp
->args
.ctx
);
7679 dprintk("<-- %s\n", __func__
);
7682 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
7683 .rpc_call_prepare
= nfs4_layoutget_prepare
,
7684 .rpc_call_done
= nfs4_layoutget_done
,
7685 .rpc_release
= nfs4_layoutget_release
,
7688 struct pnfs_layout_segment
*
7689 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
7691 struct inode
*inode
= lgp
->args
.inode
;
7692 struct nfs_server
*server
= NFS_SERVER(inode
);
7693 size_t max_pages
= max_response_pages(server
);
7694 struct rpc_task
*task
;
7695 struct rpc_message msg
= {
7696 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
7697 .rpc_argp
= &lgp
->args
,
7698 .rpc_resp
= &lgp
->res
,
7699 .rpc_cred
= lgp
->cred
,
7701 struct rpc_task_setup task_setup_data
= {
7702 .rpc_client
= server
->client
,
7703 .rpc_message
= &msg
,
7704 .callback_ops
= &nfs4_layoutget_call_ops
,
7705 .callback_data
= lgp
,
7706 .flags
= RPC_TASK_ASYNC
,
7708 struct pnfs_layout_segment
*lseg
= NULL
;
7711 dprintk("--> %s\n", __func__
);
7713 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
7714 if (!lgp
->args
.layout
.pages
) {
7715 nfs4_layoutget_release(lgp
);
7716 return ERR_PTR(-ENOMEM
);
7718 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
7719 lgp
->args
.timestamp
= jiffies
;
7721 lgp
->res
.layoutp
= &lgp
->args
.layout
;
7722 lgp
->res
.seq_res
.sr_slot
= NULL
;
7723 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
7725 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
7726 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
7728 task
= rpc_run_task(&task_setup_data
);
7730 return ERR_CAST(task
);
7731 status
= nfs4_wait_for_completion_rpc_task(task
);
7733 status
= task
->tk_status
;
7734 trace_nfs4_layoutget(lgp
->args
.ctx
,
7738 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
7739 if (status
== 0 && lgp
->res
.layoutp
->len
)
7740 lseg
= pnfs_layout_process(lgp
);
7742 dprintk("<-- %s status=%d\n", __func__
, status
);
7744 return ERR_PTR(status
);
7749 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
7751 struct nfs4_layoutreturn
*lrp
= calldata
;
7753 dprintk("--> %s\n", __func__
);
7754 nfs41_setup_sequence(lrp
->clp
->cl_session
,
7755 &lrp
->args
.seq_args
,
7760 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
7762 struct nfs4_layoutreturn
*lrp
= calldata
;
7763 struct nfs_server
*server
;
7765 dprintk("--> %s\n", __func__
);
7767 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
7770 server
= NFS_SERVER(lrp
->args
.inode
);
7771 switch (task
->tk_status
) {
7773 task
->tk_status
= 0;
7776 case -NFS4ERR_DELAY
:
7777 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) != -EAGAIN
)
7779 rpc_restart_call_prepare(task
);
7782 dprintk("<-- %s\n", __func__
);
7785 static void nfs4_layoutreturn_release(void *calldata
)
7787 struct nfs4_layoutreturn
*lrp
= calldata
;
7788 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
7790 dprintk("--> %s\n", __func__
);
7791 spin_lock(&lo
->plh_inode
->i_lock
);
7792 if (lrp
->res
.lrs_present
)
7793 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
7794 lo
->plh_block_lgets
--;
7795 spin_unlock(&lo
->plh_inode
->i_lock
);
7796 pnfs_put_layout_hdr(lrp
->args
.layout
);
7798 dprintk("<-- %s\n", __func__
);
7801 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
7802 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
7803 .rpc_call_done
= nfs4_layoutreturn_done
,
7804 .rpc_release
= nfs4_layoutreturn_release
,
7807 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
7809 struct rpc_task
*task
;
7810 struct rpc_message msg
= {
7811 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
7812 .rpc_argp
= &lrp
->args
,
7813 .rpc_resp
= &lrp
->res
,
7814 .rpc_cred
= lrp
->cred
,
7816 struct rpc_task_setup task_setup_data
= {
7817 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
7818 .rpc_message
= &msg
,
7819 .callback_ops
= &nfs4_layoutreturn_call_ops
,
7820 .callback_data
= lrp
,
7824 dprintk("--> %s\n", __func__
);
7825 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
7826 task
= rpc_run_task(&task_setup_data
);
7828 return PTR_ERR(task
);
7829 status
= task
->tk_status
;
7830 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
7831 dprintk("<-- %s status=%d\n", __func__
, status
);
7837 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7838 struct pnfs_device
*pdev
,
7839 struct rpc_cred
*cred
)
7841 struct nfs4_getdeviceinfo_args args
= {
7844 struct nfs4_getdeviceinfo_res res
= {
7847 struct rpc_message msg
= {
7848 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7855 dprintk("--> %s\n", __func__
);
7856 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7857 dprintk("<-- %s status=%d\n", __func__
, status
);
7862 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7863 struct pnfs_device
*pdev
,
7864 struct rpc_cred
*cred
)
7866 struct nfs4_exception exception
= { };
7870 err
= nfs4_handle_exception(server
,
7871 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7873 } while (exception
.retry
);
7876 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7878 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7880 struct nfs4_layoutcommit_data
*data
= calldata
;
7881 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7882 struct nfs4_session
*session
= nfs4_get_session(server
);
7884 nfs41_setup_sequence(session
,
7885 &data
->args
.seq_args
,
7891 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7893 struct nfs4_layoutcommit_data
*data
= calldata
;
7894 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7896 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7899 switch (task
->tk_status
) { /* Just ignore these failures */
7900 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7901 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7902 case -NFS4ERR_BADLAYOUT
: /* no layout */
7903 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7904 task
->tk_status
= 0;
7908 if (nfs4_async_handle_error(task
, server
, NULL
, NULL
) == -EAGAIN
) {
7909 rpc_restart_call_prepare(task
);
7915 static void nfs4_layoutcommit_release(void *calldata
)
7917 struct nfs4_layoutcommit_data
*data
= calldata
;
7919 pnfs_cleanup_layoutcommit(data
);
7920 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7922 put_rpccred(data
->cred
);
7926 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7927 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7928 .rpc_call_done
= nfs4_layoutcommit_done
,
7929 .rpc_release
= nfs4_layoutcommit_release
,
7933 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7935 struct rpc_message msg
= {
7936 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7937 .rpc_argp
= &data
->args
,
7938 .rpc_resp
= &data
->res
,
7939 .rpc_cred
= data
->cred
,
7941 struct rpc_task_setup task_setup_data
= {
7942 .task
= &data
->task
,
7943 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7944 .rpc_message
= &msg
,
7945 .callback_ops
= &nfs4_layoutcommit_ops
,
7946 .callback_data
= data
,
7947 .flags
= RPC_TASK_ASYNC
,
7949 struct rpc_task
*task
;
7952 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7953 "lbw: %llu inode %lu\n",
7954 data
->task
.tk_pid
, sync
,
7955 data
->args
.lastbytewritten
,
7956 data
->args
.inode
->i_ino
);
7958 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7959 task
= rpc_run_task(&task_setup_data
);
7961 return PTR_ERR(task
);
7964 status
= nfs4_wait_for_completion_rpc_task(task
);
7967 status
= task
->tk_status
;
7968 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7970 dprintk("%s: status %d\n", __func__
, status
);
7976 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7977 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7980 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7981 struct nfs_fsinfo
*info
,
7982 struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
7984 struct nfs41_secinfo_no_name_args args
= {
7985 .style
= SECINFO_STYLE_CURRENT_FH
,
7987 struct nfs4_secinfo_res res
= {
7990 struct rpc_message msg
= {
7991 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
7995 struct rpc_clnt
*clnt
= server
->client
;
7996 struct rpc_cred
*cred
= NULL
;
7999 if (use_integrity
) {
8000 clnt
= server
->nfs_client
->cl_rpcclient
;
8001 cred
= nfs4_get_clid_cred(server
->nfs_client
);
8002 msg
.rpc_cred
= cred
;
8005 dprintk("--> %s\n", __func__
);
8006 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
8008 dprintk("<-- %s status=%d\n", __func__
, status
);
8017 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
8018 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
8020 struct nfs4_exception exception
= { };
8023 /* first try using integrity protection */
8024 err
= -NFS4ERR_WRONGSEC
;
8026 /* try to use integrity protection with machine cred */
8027 if (_nfs4_is_integrity_protected(server
->nfs_client
))
8028 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
8032 * if unable to use integrity protection, or SECINFO with
8033 * integrity protection returns NFS4ERR_WRONGSEC (which is
8034 * disallowed by spec, but exists in deployed servers) use
8035 * the current filesystem's rpc_client and the user cred.
8037 if (err
== -NFS4ERR_WRONGSEC
)
8038 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
8043 case -NFS4ERR_WRONGSEC
:
8047 err
= nfs4_handle_exception(server
, err
, &exception
);
8049 } while (exception
.retry
);
8055 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
8056 struct nfs_fsinfo
*info
)
8060 rpc_authflavor_t flavor
= RPC_AUTH_MAXFLAVOR
;
8061 struct nfs4_secinfo_flavors
*flavors
;
8062 struct nfs4_secinfo4
*secinfo
;
8065 page
= alloc_page(GFP_KERNEL
);
8071 flavors
= page_address(page
);
8072 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
8075 * Fall back on "guess and check" method if
8076 * the server doesn't support SECINFO_NO_NAME
8078 if (err
== -NFS4ERR_WRONGSEC
|| err
== -ENOTSUPP
) {
8079 err
= nfs4_find_root_sec(server
, fhandle
, info
);
8085 for (i
= 0; i
< flavors
->num_flavors
; i
++) {
8086 secinfo
= &flavors
->flavors
[i
];
8088 switch (secinfo
->flavor
) {
8092 flavor
= rpcauth_get_pseudoflavor(secinfo
->flavor
,
8093 &secinfo
->flavor_info
);
8096 flavor
= RPC_AUTH_MAXFLAVOR
;
8100 if (!nfs_auth_info_match(&server
->auth_info
, flavor
))
8101 flavor
= RPC_AUTH_MAXFLAVOR
;
8103 if (flavor
!= RPC_AUTH_MAXFLAVOR
) {
8104 err
= nfs4_lookup_root_sec(server
, fhandle
,
8111 if (flavor
== RPC_AUTH_MAXFLAVOR
)
8122 static int _nfs41_test_stateid(struct nfs_server
*server
,
8123 nfs4_stateid
*stateid
,
8124 struct rpc_cred
*cred
)
8127 struct nfs41_test_stateid_args args
= {
8130 struct nfs41_test_stateid_res res
;
8131 struct rpc_message msg
= {
8132 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
8137 struct rpc_clnt
*rpc_client
= server
->client
;
8139 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8142 dprintk("NFS call test_stateid %p\n", stateid
);
8143 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
8144 nfs4_set_sequence_privileged(&args
.seq_args
);
8145 status
= nfs4_call_sync_sequence(rpc_client
, server
, &msg
,
8146 &args
.seq_args
, &res
.seq_res
);
8147 if (status
!= NFS_OK
) {
8148 dprintk("NFS reply test_stateid: failed, %d\n", status
);
8151 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
8156 * nfs41_test_stateid - perform a TEST_STATEID operation
8158 * @server: server / transport on which to perform the operation
8159 * @stateid: state ID to test
8162 * Returns NFS_OK if the server recognizes that "stateid" is valid.
8163 * Otherwise a negative NFS4ERR value is returned if the operation
8164 * failed or the state ID is not currently valid.
8166 static int nfs41_test_stateid(struct nfs_server
*server
,
8167 nfs4_stateid
*stateid
,
8168 struct rpc_cred
*cred
)
8170 struct nfs4_exception exception
= { };
8173 err
= _nfs41_test_stateid(server
, stateid
, cred
);
8174 if (err
!= -NFS4ERR_DELAY
)
8176 nfs4_handle_exception(server
, err
, &exception
);
8177 } while (exception
.retry
);
8181 struct nfs_free_stateid_data
{
8182 struct nfs_server
*server
;
8183 struct nfs41_free_stateid_args args
;
8184 struct nfs41_free_stateid_res res
;
8187 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
8189 struct nfs_free_stateid_data
*data
= calldata
;
8190 nfs41_setup_sequence(nfs4_get_session(data
->server
),
8191 &data
->args
.seq_args
,
8196 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
8198 struct nfs_free_stateid_data
*data
= calldata
;
8200 nfs41_sequence_done(task
, &data
->res
.seq_res
);
8202 switch (task
->tk_status
) {
8203 case -NFS4ERR_DELAY
:
8204 if (nfs4_async_handle_error(task
, data
->server
, NULL
, NULL
) == -EAGAIN
)
8205 rpc_restart_call_prepare(task
);
8209 static void nfs41_free_stateid_release(void *calldata
)
8214 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
8215 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
8216 .rpc_call_done
= nfs41_free_stateid_done
,
8217 .rpc_release
= nfs41_free_stateid_release
,
8220 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
8221 nfs4_stateid
*stateid
,
8222 struct rpc_cred
*cred
,
8225 struct rpc_message msg
= {
8226 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
8229 struct rpc_task_setup task_setup
= {
8230 .rpc_client
= server
->client
,
8231 .rpc_message
= &msg
,
8232 .callback_ops
= &nfs41_free_stateid_ops
,
8233 .flags
= RPC_TASK_ASYNC
,
8235 struct nfs_free_stateid_data
*data
;
8237 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8238 &task_setup
.rpc_client
, &msg
);
8240 dprintk("NFS call free_stateid %p\n", stateid
);
8241 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
8243 return ERR_PTR(-ENOMEM
);
8244 data
->server
= server
;
8245 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
8247 task_setup
.callback_data
= data
;
8249 msg
.rpc_argp
= &data
->args
;
8250 msg
.rpc_resp
= &data
->res
;
8251 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
8253 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
8255 return rpc_run_task(&task_setup
);
8259 * nfs41_free_stateid - perform a FREE_STATEID operation
8261 * @server: server / transport on which to perform the operation
8262 * @stateid: state ID to release
8265 * Returns NFS_OK if the server freed "stateid". Otherwise a
8266 * negative NFS4ERR value is returned.
8268 static int nfs41_free_stateid(struct nfs_server
*server
,
8269 nfs4_stateid
*stateid
,
8270 struct rpc_cred
*cred
)
8272 struct rpc_task
*task
;
8275 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
8277 return PTR_ERR(task
);
8278 ret
= rpc_wait_for_completion_task(task
);
8280 ret
= task
->tk_status
;
8286 nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
8288 struct rpc_task
*task
;
8289 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
8291 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
8292 nfs4_free_lock_state(server
, lsp
);
8298 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
8299 const nfs4_stateid
*s2
)
8301 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
8304 if (s1
->seqid
== s2
->seqid
)
8306 if (s1
->seqid
== 0 || s2
->seqid
== 0)
8312 #endif /* CONFIG_NFS_V4_1 */
8314 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
8315 const nfs4_stateid
*s2
)
8317 return nfs4_stateid_match(s1
, s2
);
8321 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
8322 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8323 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8324 .recover_open
= nfs4_open_reclaim
,
8325 .recover_lock
= nfs4_lock_reclaim
,
8326 .establish_clid
= nfs4_init_clientid
,
8327 .detect_trunking
= nfs40_discover_server_trunking
,
8330 #if defined(CONFIG_NFS_V4_1)
8331 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
8332 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8333 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8334 .recover_open
= nfs4_open_reclaim
,
8335 .recover_lock
= nfs4_lock_reclaim
,
8336 .establish_clid
= nfs41_init_clientid
,
8337 .reclaim_complete
= nfs41_proc_reclaim_complete
,
8338 .detect_trunking
= nfs41_discover_server_trunking
,
8340 #endif /* CONFIG_NFS_V4_1 */
8342 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
8343 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8344 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8345 .recover_open
= nfs4_open_expired
,
8346 .recover_lock
= nfs4_lock_expired
,
8347 .establish_clid
= nfs4_init_clientid
,
8350 #if defined(CONFIG_NFS_V4_1)
8351 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
8352 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8353 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8354 .recover_open
= nfs41_open_expired
,
8355 .recover_lock
= nfs41_lock_expired
,
8356 .establish_clid
= nfs41_init_clientid
,
8358 #endif /* CONFIG_NFS_V4_1 */
8360 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
8361 .sched_state_renewal
= nfs4_proc_async_renew
,
8362 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
8363 .renew_lease
= nfs4_proc_renew
,
8366 #if defined(CONFIG_NFS_V4_1)
8367 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
8368 .sched_state_renewal
= nfs41_proc_async_sequence
,
8369 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
8370 .renew_lease
= nfs4_proc_sequence
,
8374 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops
= {
8375 .get_locations
= _nfs40_proc_get_locations
,
8376 .fsid_present
= _nfs40_proc_fsid_present
,
8379 #if defined(CONFIG_NFS_V4_1)
8380 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops
= {
8381 .get_locations
= _nfs41_proc_get_locations
,
8382 .fsid_present
= _nfs41_proc_fsid_present
,
8384 #endif /* CONFIG_NFS_V4_1 */
8386 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
8388 .init_caps
= NFS_CAP_READDIRPLUS
8389 | NFS_CAP_ATOMIC_OPEN
8390 | NFS_CAP_CHANGE_ATTR
8391 | NFS_CAP_POSIX_LOCK
,
8392 .init_client
= nfs40_init_client
,
8393 .shutdown_client
= nfs40_shutdown_client
,
8394 .match_stateid
= nfs4_match_stateid
,
8395 .find_root_sec
= nfs4_find_root_sec
,
8396 .free_lock_state
= nfs4_release_lockowner
,
8397 .call_sync_ops
= &nfs40_call_sync_ops
,
8398 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
8399 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
8400 .state_renewal_ops
= &nfs40_state_renewal_ops
,
8401 .mig_recovery_ops
= &nfs40_mig_recovery_ops
,
8404 #if defined(CONFIG_NFS_V4_1)
8405 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
8407 .init_caps
= NFS_CAP_READDIRPLUS
8408 | NFS_CAP_ATOMIC_OPEN
8409 | NFS_CAP_CHANGE_ATTR
8410 | NFS_CAP_POSIX_LOCK
8411 | NFS_CAP_STATEID_NFSV41
8412 | NFS_CAP_ATOMIC_OPEN_V1
,
8413 .init_client
= nfs41_init_client
,
8414 .shutdown_client
= nfs41_shutdown_client
,
8415 .match_stateid
= nfs41_match_stateid
,
8416 .find_root_sec
= nfs41_find_root_sec
,
8417 .free_lock_state
= nfs41_free_lock_state
,
8418 .call_sync_ops
= &nfs41_call_sync_ops
,
8419 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8420 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8421 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8422 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
8426 #if defined(CONFIG_NFS_V4_2)
8427 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
8429 .init_caps
= NFS_CAP_READDIRPLUS
8430 | NFS_CAP_ATOMIC_OPEN
8431 | NFS_CAP_CHANGE_ATTR
8432 | NFS_CAP_POSIX_LOCK
8433 | NFS_CAP_STATEID_NFSV41
8434 | NFS_CAP_ATOMIC_OPEN_V1
,
8435 .init_client
= nfs41_init_client
,
8436 .shutdown_client
= nfs41_shutdown_client
,
8437 .match_stateid
= nfs41_match_stateid
,
8438 .find_root_sec
= nfs41_find_root_sec
,
8439 .free_lock_state
= nfs41_free_lock_state
,
8440 .call_sync_ops
= &nfs41_call_sync_ops
,
8441 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8442 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8443 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8447 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
8448 [0] = &nfs_v4_0_minor_ops
,
8449 #if defined(CONFIG_NFS_V4_1)
8450 [1] = &nfs_v4_1_minor_ops
,
8452 #if defined(CONFIG_NFS_V4_2)
8453 [2] = &nfs_v4_2_minor_ops
,
8457 static const struct inode_operations nfs4_dir_inode_operations
= {
8458 .create
= nfs_create
,
8459 .lookup
= nfs_lookup
,
8460 .atomic_open
= nfs_atomic_open
,
8462 .unlink
= nfs_unlink
,
8463 .symlink
= nfs_symlink
,
8467 .rename
= nfs_rename
,
8468 .permission
= nfs_permission
,
8469 .getattr
= nfs_getattr
,
8470 .setattr
= nfs_setattr
,
8471 .getxattr
= generic_getxattr
,
8472 .setxattr
= generic_setxattr
,
8473 .listxattr
= generic_listxattr
,
8474 .removexattr
= generic_removexattr
,
8477 static const struct inode_operations nfs4_file_inode_operations
= {
8478 .permission
= nfs_permission
,
8479 .getattr
= nfs_getattr
,
8480 .setattr
= nfs_setattr
,
8481 .getxattr
= generic_getxattr
,
8482 .setxattr
= generic_setxattr
,
8483 .listxattr
= generic_listxattr
,
8484 .removexattr
= generic_removexattr
,
8487 const struct nfs_rpc_ops nfs_v4_clientops
= {
8488 .version
= 4, /* protocol version */
8489 .dentry_ops
= &nfs4_dentry_operations
,
8490 .dir_inode_ops
= &nfs4_dir_inode_operations
,
8491 .file_inode_ops
= &nfs4_file_inode_operations
,
8492 .file_ops
= &nfs4_file_operations
,
8493 .getroot
= nfs4_proc_get_root
,
8494 .submount
= nfs4_submount
,
8495 .try_mount
= nfs4_try_mount
,
8496 .getattr
= nfs4_proc_getattr
,
8497 .setattr
= nfs4_proc_setattr
,
8498 .lookup
= nfs4_proc_lookup
,
8499 .access
= nfs4_proc_access
,
8500 .readlink
= nfs4_proc_readlink
,
8501 .create
= nfs4_proc_create
,
8502 .remove
= nfs4_proc_remove
,
8503 .unlink_setup
= nfs4_proc_unlink_setup
,
8504 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
8505 .unlink_done
= nfs4_proc_unlink_done
,
8506 .rename_setup
= nfs4_proc_rename_setup
,
8507 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
8508 .rename_done
= nfs4_proc_rename_done
,
8509 .link
= nfs4_proc_link
,
8510 .symlink
= nfs4_proc_symlink
,
8511 .mkdir
= nfs4_proc_mkdir
,
8512 .rmdir
= nfs4_proc_remove
,
8513 .readdir
= nfs4_proc_readdir
,
8514 .mknod
= nfs4_proc_mknod
,
8515 .statfs
= nfs4_proc_statfs
,
8516 .fsinfo
= nfs4_proc_fsinfo
,
8517 .pathconf
= nfs4_proc_pathconf
,
8518 .set_capabilities
= nfs4_server_capabilities
,
8519 .decode_dirent
= nfs4_decode_dirent
,
8520 .pgio_rpc_prepare
= nfs4_proc_pgio_rpc_prepare
,
8521 .read_setup
= nfs4_proc_read_setup
,
8522 .read_done
= nfs4_read_done
,
8523 .write_setup
= nfs4_proc_write_setup
,
8524 .write_done
= nfs4_write_done
,
8525 .commit_setup
= nfs4_proc_commit_setup
,
8526 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
8527 .commit_done
= nfs4_commit_done
,
8528 .lock
= nfs4_proc_lock
,
8529 .clear_acl_cache
= nfs4_zap_acl_attr
,
8530 .close_context
= nfs4_close_context
,
8531 .open_context
= nfs4_atomic_open
,
8532 .have_delegation
= nfs4_have_delegation
,
8533 .return_delegation
= nfs4_inode_return_delegation
,
8534 .alloc_client
= nfs4_alloc_client
,
8535 .init_client
= nfs4_init_client
,
8536 .free_client
= nfs4_free_client
,
8537 .create_server
= nfs4_create_server
,
8538 .clone_server
= nfs_clone_server
,
8541 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
8542 .prefix
= XATTR_NAME_NFSV4_ACL
,
8543 .list
= nfs4_xattr_list_nfs4_acl
,
8544 .get
= nfs4_xattr_get_nfs4_acl
,
8545 .set
= nfs4_xattr_set_nfs4_acl
,
8548 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
8549 &nfs4_xattr_nfs4_acl_handler
,
8550 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
8551 &nfs4_xattr_nfs4_label_handler
,