4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/ratelimit.h>
43 #include <linux/printk.h>
44 #include <linux/slab.h>
45 #include <linux/sunrpc/clnt.h>
46 #include <linux/nfs.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/nfs_page.h>
50 #include <linux/nfs_mount.h>
51 #include <linux/namei.h>
52 #include <linux/mount.h>
53 #include <linux/module.h>
54 #include <linux/nfs_idmap.h>
55 #include <linux/xattr.h>
56 #include <linux/utsname.h>
57 #include <linux/freezer.h>
60 #include "delegation.h"
66 #include "nfs4session.h"
69 #include "nfs4trace.h"
71 #define NFSDBG_FACILITY NFSDBG_PROC
73 #define NFS4_POLL_RETRY_MIN (HZ/10)
74 #define NFS4_POLL_RETRY_MAX (15*HZ)
77 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
78 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
79 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
80 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
81 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
82 static int nfs4_proc_getattr(struct nfs_server
*, struct nfs_fh
*, struct nfs_fattr
*, struct nfs4_label
*label
);
83 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
, struct nfs4_label
*label
);
84 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
85 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
86 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
87 struct nfs4_label
*olabel
);
88 #ifdef CONFIG_NFS_V4_1
89 static int nfs41_test_stateid(struct nfs_server
*, nfs4_stateid
*,
91 static int nfs41_free_stateid(struct nfs_server
*, nfs4_stateid
*,
95 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
96 static inline struct nfs4_label
*
97 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
98 struct iattr
*sattr
, struct nfs4_label
*label
)
105 if (nfs_server_capable(dir
, NFS_CAP_SECURITY_LABEL
) == 0)
108 err
= security_dentry_init_security(dentry
, sattr
->ia_mode
,
109 &dentry
->d_name
, (void **)&label
->label
, &label
->len
);
116 nfs4_label_release_security(struct nfs4_label
*label
)
119 security_release_secctx(label
->label
, label
->len
);
121 static inline u32
*nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
124 return server
->attr_bitmask
;
126 return server
->attr_bitmask_nl
;
129 static inline struct nfs4_label
*
130 nfs4_label_init_security(struct inode
*dir
, struct dentry
*dentry
,
131 struct iattr
*sattr
, struct nfs4_label
*l
)
134 nfs4_label_release_security(struct nfs4_label
*label
)
137 nfs4_bitmask(struct nfs_server
*server
, struct nfs4_label
*label
)
138 { return server
->attr_bitmask
; }
141 /* Prevent leaks of NFSv4 errors into userland */
142 static int nfs4_map_errors(int err
)
147 case -NFS4ERR_RESOURCE
:
148 case -NFS4ERR_LAYOUTTRYLATER
:
149 case -NFS4ERR_RECALLCONFLICT
:
151 case -NFS4ERR_WRONGSEC
:
152 case -NFS4ERR_WRONG_CRED
:
154 case -NFS4ERR_BADOWNER
:
155 case -NFS4ERR_BADNAME
:
157 case -NFS4ERR_SHARE_DENIED
:
159 case -NFS4ERR_MINOR_VERS_MISMATCH
:
160 return -EPROTONOSUPPORT
;
161 case -NFS4ERR_ACCESS
:
163 case -NFS4ERR_FILE_OPEN
:
166 dprintk("%s could not handle NFSv4 error %d\n",
174 * This is our standard bitmap for GETATTR requests.
176 const u32 nfs4_fattr_bitmap
[3] = {
178 | FATTR4_WORD0_CHANGE
181 | FATTR4_WORD0_FILEID
,
183 | FATTR4_WORD1_NUMLINKS
185 | FATTR4_WORD1_OWNER_GROUP
186 | FATTR4_WORD1_RAWDEV
187 | FATTR4_WORD1_SPACE_USED
188 | FATTR4_WORD1_TIME_ACCESS
189 | FATTR4_WORD1_TIME_METADATA
190 | FATTR4_WORD1_TIME_MODIFY
,
191 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
192 FATTR4_WORD2_SECURITY_LABEL
196 static const u32 nfs4_pnfs_open_bitmap
[3] = {
198 | FATTR4_WORD0_CHANGE
201 | FATTR4_WORD0_FILEID
,
203 | FATTR4_WORD1_NUMLINKS
205 | FATTR4_WORD1_OWNER_GROUP
206 | FATTR4_WORD1_RAWDEV
207 | FATTR4_WORD1_SPACE_USED
208 | FATTR4_WORD1_TIME_ACCESS
209 | FATTR4_WORD1_TIME_METADATA
210 | FATTR4_WORD1_TIME_MODIFY
,
211 FATTR4_WORD2_MDSTHRESHOLD
214 static const u32 nfs4_open_noattr_bitmap
[3] = {
216 | FATTR4_WORD0_CHANGE
217 | FATTR4_WORD0_FILEID
,
220 const u32 nfs4_statfs_bitmap
[3] = {
221 FATTR4_WORD0_FILES_AVAIL
222 | FATTR4_WORD0_FILES_FREE
223 | FATTR4_WORD0_FILES_TOTAL
,
224 FATTR4_WORD1_SPACE_AVAIL
225 | FATTR4_WORD1_SPACE_FREE
226 | FATTR4_WORD1_SPACE_TOTAL
229 const u32 nfs4_pathconf_bitmap
[3] = {
231 | FATTR4_WORD0_MAXNAME
,
235 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
236 | FATTR4_WORD0_MAXREAD
237 | FATTR4_WORD0_MAXWRITE
238 | FATTR4_WORD0_LEASE_TIME
,
239 FATTR4_WORD1_TIME_DELTA
240 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
241 FATTR4_WORD2_LAYOUT_BLKSIZE
244 const u32 nfs4_fs_locations_bitmap
[3] = {
246 | FATTR4_WORD0_CHANGE
249 | FATTR4_WORD0_FILEID
250 | FATTR4_WORD0_FS_LOCATIONS
,
252 | FATTR4_WORD1_NUMLINKS
254 | FATTR4_WORD1_OWNER_GROUP
255 | FATTR4_WORD1_RAWDEV
256 | FATTR4_WORD1_SPACE_USED
257 | FATTR4_WORD1_TIME_ACCESS
258 | FATTR4_WORD1_TIME_METADATA
259 | FATTR4_WORD1_TIME_MODIFY
260 | FATTR4_WORD1_MOUNTED_ON_FILEID
,
263 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
264 struct nfs4_readdir_arg
*readdir
)
269 readdir
->cookie
= cookie
;
270 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
275 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
280 * NFSv4 servers do not return entries for '.' and '..'
281 * Therefore, we fake these entries here. We let '.'
282 * have cookie 0 and '..' have cookie 1. Note that
283 * when talking to the server, we always send cookie 0
286 start
= p
= kmap_atomic(*readdir
->pages
);
289 *p
++ = xdr_one
; /* next */
290 *p
++ = xdr_zero
; /* cookie, first word */
291 *p
++ = xdr_one
; /* cookie, second word */
292 *p
++ = xdr_one
; /* entry len */
293 memcpy(p
, ".\0\0\0", 4); /* entry */
295 *p
++ = xdr_one
; /* bitmap length */
296 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
297 *p
++ = htonl(8); /* attribute buffer length */
298 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
301 *p
++ = xdr_one
; /* next */
302 *p
++ = xdr_zero
; /* cookie, first word */
303 *p
++ = xdr_two
; /* cookie, second word */
304 *p
++ = xdr_two
; /* entry len */
305 memcpy(p
, "..\0\0", 4); /* entry */
307 *p
++ = xdr_one
; /* bitmap length */
308 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
309 *p
++ = htonl(8); /* attribute buffer length */
310 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
312 readdir
->pgbase
= (char *)p
- (char *)start
;
313 readdir
->count
-= readdir
->pgbase
;
314 kunmap_atomic(start
);
317 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
324 *timeout
= NFS4_POLL_RETRY_MIN
;
325 if (*timeout
> NFS4_POLL_RETRY_MAX
)
326 *timeout
= NFS4_POLL_RETRY_MAX
;
327 freezable_schedule_timeout_killable_unsafe(*timeout
);
328 if (fatal_signal_pending(current
))
334 /* This is the error handling routine for processes that are allowed
337 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
339 struct nfs_client
*clp
= server
->nfs_client
;
340 struct nfs4_state
*state
= exception
->state
;
341 struct inode
*inode
= exception
->inode
;
344 exception
->retry
= 0;
348 case -NFS4ERR_OPENMODE
:
349 if (inode
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
350 nfs4_inode_return_delegation(inode
);
351 exception
->retry
= 1;
356 ret
= nfs4_schedule_stateid_recovery(server
, state
);
359 goto wait_on_recovery
;
360 case -NFS4ERR_DELEG_REVOKED
:
361 case -NFS4ERR_ADMIN_REVOKED
:
362 case -NFS4ERR_BAD_STATEID
:
363 if (inode
!= NULL
&& nfs4_have_delegation(inode
, FMODE_READ
)) {
364 nfs_remove_bad_delegation(inode
);
365 exception
->retry
= 1;
370 ret
= nfs4_schedule_stateid_recovery(server
, state
);
373 goto wait_on_recovery
;
374 case -NFS4ERR_EXPIRED
:
376 ret
= nfs4_schedule_stateid_recovery(server
, state
);
380 case -NFS4ERR_STALE_STATEID
:
381 case -NFS4ERR_STALE_CLIENTID
:
382 nfs4_schedule_lease_recovery(clp
);
383 goto wait_on_recovery
;
385 ret
= nfs4_schedule_migration_recovery(server
);
388 goto wait_on_recovery
;
389 case -NFS4ERR_LEASE_MOVED
:
390 nfs4_schedule_lease_moved_recovery(clp
);
391 goto wait_on_recovery
;
392 #if defined(CONFIG_NFS_V4_1)
393 case -NFS4ERR_BADSESSION
:
394 case -NFS4ERR_BADSLOT
:
395 case -NFS4ERR_BAD_HIGH_SLOT
:
396 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
397 case -NFS4ERR_DEADSESSION
:
398 case -NFS4ERR_SEQ_FALSE_RETRY
:
399 case -NFS4ERR_SEQ_MISORDERED
:
400 dprintk("%s ERROR: %d Reset session\n", __func__
,
402 nfs4_schedule_session_recovery(clp
->cl_session
, errorcode
);
403 goto wait_on_recovery
;
404 #endif /* defined(CONFIG_NFS_V4_1) */
405 case -NFS4ERR_FILE_OPEN
:
406 if (exception
->timeout
> HZ
) {
407 /* We have retried a decent amount, time to
415 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
418 case -NFS4ERR_RETRY_UNCACHED_REP
:
419 case -NFS4ERR_OLD_STATEID
:
420 exception
->retry
= 1;
422 case -NFS4ERR_BADOWNER
:
423 /* The following works around a Linux server bug! */
424 case -NFS4ERR_BADNAME
:
425 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
426 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
427 exception
->retry
= 1;
428 printk(KERN_WARNING
"NFS: v4 server %s "
429 "does not accept raw "
431 "Reenabling the idmapper.\n",
432 server
->nfs_client
->cl_hostname
);
435 /* We failed to handle the error */
436 return nfs4_map_errors(ret
);
438 ret
= nfs4_wait_clnt_recover(clp
);
439 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
442 exception
->retry
= 1;
447 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
448 * or 'false' otherwise.
450 static bool _nfs4_is_integrity_protected(struct nfs_client
*clp
)
452 rpc_authflavor_t flavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
454 if (flavor
== RPC_AUTH_GSS_KRB5I
||
455 flavor
== RPC_AUTH_GSS_KRB5P
)
461 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
463 spin_lock(&clp
->cl_lock
);
464 if (time_before(clp
->cl_last_renewal
,timestamp
))
465 clp
->cl_last_renewal
= timestamp
;
466 spin_unlock(&clp
->cl_lock
);
469 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
471 do_renew_lease(server
->nfs_client
, timestamp
);
474 struct nfs4_call_sync_data
{
475 const struct nfs_server
*seq_server
;
476 struct nfs4_sequence_args
*seq_args
;
477 struct nfs4_sequence_res
*seq_res
;
480 static void nfs4_init_sequence(struct nfs4_sequence_args
*args
,
481 struct nfs4_sequence_res
*res
, int cache_reply
)
483 args
->sa_slot
= NULL
;
484 args
->sa_cache_this
= cache_reply
;
485 args
->sa_privileged
= 0;
490 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args
*args
)
492 args
->sa_privileged
= 1;
495 static int nfs40_setup_sequence(const struct nfs_server
*server
,
496 struct nfs4_sequence_args
*args
,
497 struct nfs4_sequence_res
*res
,
498 struct rpc_task
*task
)
500 struct nfs4_slot_table
*tbl
= server
->nfs_client
->cl_slot_tbl
;
501 struct nfs4_slot
*slot
;
503 /* slot already allocated? */
504 if (res
->sr_slot
!= NULL
)
507 spin_lock(&tbl
->slot_tbl_lock
);
508 if (nfs4_slot_tbl_draining(tbl
) && !args
->sa_privileged
)
511 slot
= nfs4_alloc_slot(tbl
);
513 if (slot
== ERR_PTR(-ENOMEM
))
514 task
->tk_timeout
= HZ
>> 2;
517 spin_unlock(&tbl
->slot_tbl_lock
);
519 args
->sa_slot
= slot
;
523 rpc_call_start(task
);
527 if (args
->sa_privileged
)
528 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
529 NULL
, RPC_PRIORITY_PRIVILEGED
);
531 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
532 spin_unlock(&tbl
->slot_tbl_lock
);
536 static int nfs40_sequence_done(struct rpc_task
*task
,
537 struct nfs4_sequence_res
*res
)
539 struct nfs4_slot
*slot
= res
->sr_slot
;
540 struct nfs4_slot_table
*tbl
;
542 if (!RPC_WAS_SENT(task
))
546 spin_lock(&tbl
->slot_tbl_lock
);
547 if (!nfs41_wake_and_assign_slot(tbl
, slot
))
548 nfs4_free_slot(tbl
, slot
);
549 spin_unlock(&tbl
->slot_tbl_lock
);
556 #if defined(CONFIG_NFS_V4_1)
558 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
560 struct nfs4_session
*session
;
561 struct nfs4_slot_table
*tbl
;
562 bool send_new_highest_used_slotid
= false;
565 /* just wake up the next guy waiting since
566 * we may have not consumed a slot after all */
567 dprintk("%s: No slot\n", __func__
);
570 tbl
= res
->sr_slot
->table
;
571 session
= tbl
->session
;
573 spin_lock(&tbl
->slot_tbl_lock
);
574 /* Be nice to the server: try to ensure that the last transmitted
575 * value for highest_user_slotid <= target_highest_slotid
577 if (tbl
->highest_used_slotid
> tbl
->target_highest_slotid
)
578 send_new_highest_used_slotid
= true;
580 if (nfs41_wake_and_assign_slot(tbl
, res
->sr_slot
)) {
581 send_new_highest_used_slotid
= false;
584 nfs4_free_slot(tbl
, res
->sr_slot
);
586 if (tbl
->highest_used_slotid
!= NFS4_NO_SLOT
)
587 send_new_highest_used_slotid
= false;
589 spin_unlock(&tbl
->slot_tbl_lock
);
591 if (send_new_highest_used_slotid
)
592 nfs41_server_notify_highest_slotid_update(session
->clp
);
595 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
597 struct nfs4_session
*session
;
598 struct nfs4_slot
*slot
;
599 struct nfs_client
*clp
;
600 bool interrupted
= false;
603 /* don't increment the sequence number if the task wasn't sent */
604 if (!RPC_WAS_SENT(task
))
608 session
= slot
->table
->session
;
610 if (slot
->interrupted
) {
611 slot
->interrupted
= 0;
615 trace_nfs4_sequence_done(session
, res
);
616 /* Check the SEQUENCE operation status */
617 switch (res
->sr_status
) {
619 /* Update the slot's sequence and clientid lease timer */
622 do_renew_lease(clp
, res
->sr_timestamp
);
623 /* Check sequence flags */
624 if (res
->sr_status_flags
!= 0)
625 nfs4_schedule_lease_recovery(clp
);
626 nfs41_update_target_slotid(slot
->table
, slot
, res
);
630 * sr_status remains 1 if an RPC level error occurred.
631 * The server may or may not have processed the sequence
633 * Mark the slot as having hosted an interrupted RPC call.
635 slot
->interrupted
= 1;
638 /* The server detected a resend of the RPC call and
639 * returned NFS4ERR_DELAY as per Section 2.10.6.2
642 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
647 case -NFS4ERR_BADSLOT
:
649 * The slot id we used was probably retired. Try again
650 * using a different slot id.
653 case -NFS4ERR_SEQ_MISORDERED
:
655 * Was the last operation on this sequence interrupted?
656 * If so, retry after bumping the sequence number.
663 * Could this slot have been previously retired?
664 * If so, then the server may be expecting seq_nr = 1!
666 if (slot
->seq_nr
!= 1) {
671 case -NFS4ERR_SEQ_FALSE_RETRY
:
675 /* Just update the slot sequence no. */
679 /* The session may be reset by one of the error handlers. */
680 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
681 nfs41_sequence_free_slot(res
);
684 if (rpc_restart_call_prepare(task
)) {
690 if (!rpc_restart_call(task
))
692 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
696 static int nfs4_sequence_done(struct rpc_task
*task
,
697 struct nfs4_sequence_res
*res
)
699 if (res
->sr_slot
== NULL
)
701 if (!res
->sr_slot
->table
->session
)
702 return nfs40_sequence_done(task
, res
);
703 return nfs41_sequence_done(task
, res
);
706 int nfs41_setup_sequence(struct nfs4_session
*session
,
707 struct nfs4_sequence_args
*args
,
708 struct nfs4_sequence_res
*res
,
709 struct rpc_task
*task
)
711 struct nfs4_slot
*slot
;
712 struct nfs4_slot_table
*tbl
;
714 dprintk("--> %s\n", __func__
);
715 /* slot already allocated? */
716 if (res
->sr_slot
!= NULL
)
719 tbl
= &session
->fc_slot_table
;
721 task
->tk_timeout
= 0;
723 spin_lock(&tbl
->slot_tbl_lock
);
724 if (test_bit(NFS4_SLOT_TBL_DRAINING
, &tbl
->slot_tbl_state
) &&
725 !args
->sa_privileged
) {
726 /* The state manager will wait until the slot table is empty */
727 dprintk("%s session is draining\n", __func__
);
731 slot
= nfs4_alloc_slot(tbl
);
733 /* If out of memory, try again in 1/4 second */
734 if (slot
== ERR_PTR(-ENOMEM
))
735 task
->tk_timeout
= HZ
>> 2;
736 dprintk("<-- %s: no free slots\n", __func__
);
739 spin_unlock(&tbl
->slot_tbl_lock
);
741 args
->sa_slot
= slot
;
743 dprintk("<-- %s slotid=%u seqid=%u\n", __func__
,
744 slot
->slot_nr
, slot
->seq_nr
);
747 res
->sr_timestamp
= jiffies
;
748 res
->sr_status_flags
= 0;
750 * sr_status is only set in decode_sequence, and so will remain
751 * set to 1 if an rpc level failure occurs.
754 trace_nfs4_setup_sequence(session
, args
);
756 rpc_call_start(task
);
759 /* Privileged tasks are queued with top priority */
760 if (args
->sa_privileged
)
761 rpc_sleep_on_priority(&tbl
->slot_tbl_waitq
, task
,
762 NULL
, RPC_PRIORITY_PRIVILEGED
);
764 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
765 spin_unlock(&tbl
->slot_tbl_lock
);
768 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
770 static int nfs4_setup_sequence(const struct nfs_server
*server
,
771 struct nfs4_sequence_args
*args
,
772 struct nfs4_sequence_res
*res
,
773 struct rpc_task
*task
)
775 struct nfs4_session
*session
= nfs4_get_session(server
);
779 return nfs40_setup_sequence(server
, args
, res
, task
);
781 dprintk("--> %s clp %p session %p sr_slot %u\n",
782 __func__
, session
->clp
, session
, res
->sr_slot
?
783 res
->sr_slot
->slot_nr
: NFS4_NO_SLOT
);
785 ret
= nfs41_setup_sequence(session
, args
, res
, task
);
787 dprintk("<-- %s status=%d\n", __func__
, ret
);
791 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
793 struct nfs4_call_sync_data
*data
= calldata
;
794 struct nfs4_session
*session
= nfs4_get_session(data
->seq_server
);
796 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
798 nfs41_setup_sequence(session
, data
->seq_args
, data
->seq_res
, task
);
801 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
803 struct nfs4_call_sync_data
*data
= calldata
;
805 nfs41_sequence_done(task
, data
->seq_res
);
808 static const struct rpc_call_ops nfs41_call_sync_ops
= {
809 .rpc_call_prepare
= nfs41_call_sync_prepare
,
810 .rpc_call_done
= nfs41_call_sync_done
,
813 #else /* !CONFIG_NFS_V4_1 */
815 static int nfs4_setup_sequence(const struct nfs_server
*server
,
816 struct nfs4_sequence_args
*args
,
817 struct nfs4_sequence_res
*res
,
818 struct rpc_task
*task
)
820 return nfs40_setup_sequence(server
, args
, res
, task
);
823 static int nfs4_sequence_done(struct rpc_task
*task
,
824 struct nfs4_sequence_res
*res
)
826 return nfs40_sequence_done(task
, res
);
829 #endif /* !CONFIG_NFS_V4_1 */
831 static void nfs40_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
833 struct nfs4_call_sync_data
*data
= calldata
;
834 nfs4_setup_sequence(data
->seq_server
,
835 data
->seq_args
, data
->seq_res
, task
);
838 static void nfs40_call_sync_done(struct rpc_task
*task
, void *calldata
)
840 struct nfs4_call_sync_data
*data
= calldata
;
841 nfs4_sequence_done(task
, data
->seq_res
);
844 static const struct rpc_call_ops nfs40_call_sync_ops
= {
845 .rpc_call_prepare
= nfs40_call_sync_prepare
,
846 .rpc_call_done
= nfs40_call_sync_done
,
849 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
850 struct nfs_server
*server
,
851 struct rpc_message
*msg
,
852 struct nfs4_sequence_args
*args
,
853 struct nfs4_sequence_res
*res
)
856 struct rpc_task
*task
;
857 struct nfs_client
*clp
= server
->nfs_client
;
858 struct nfs4_call_sync_data data
= {
859 .seq_server
= server
,
863 struct rpc_task_setup task_setup
= {
866 .callback_ops
= clp
->cl_mvops
->call_sync_ops
,
867 .callback_data
= &data
870 task
= rpc_run_task(&task_setup
);
874 ret
= task
->tk_status
;
881 int nfs4_call_sync(struct rpc_clnt
*clnt
,
882 struct nfs_server
*server
,
883 struct rpc_message
*msg
,
884 struct nfs4_sequence_args
*args
,
885 struct nfs4_sequence_res
*res
,
888 nfs4_init_sequence(args
, res
, cache_reply
);
889 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
);
892 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
894 struct nfs_inode
*nfsi
= NFS_I(dir
);
896 spin_lock(&dir
->i_lock
);
897 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_INVALID_DATA
;
898 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
899 nfs_force_lookup_revalidate(dir
);
900 dir
->i_version
= cinfo
->after
;
901 nfs_fscache_invalidate(dir
);
902 spin_unlock(&dir
->i_lock
);
905 struct nfs4_opendata
{
907 struct nfs_openargs o_arg
;
908 struct nfs_openres o_res
;
909 struct nfs_open_confirmargs c_arg
;
910 struct nfs_open_confirmres c_res
;
911 struct nfs4_string owner_name
;
912 struct nfs4_string group_name
;
913 struct nfs_fattr f_attr
;
914 struct nfs4_label
*f_label
;
916 struct dentry
*dentry
;
917 struct nfs4_state_owner
*owner
;
918 struct nfs4_state
*state
;
920 unsigned long timestamp
;
921 unsigned int rpc_done
: 1;
922 unsigned int file_created
: 1;
923 unsigned int is_recover
: 1;
928 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server
*server
,
929 int err
, struct nfs4_exception
*exception
)
933 if (!(server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
))
935 server
->caps
&= ~NFS_CAP_ATOMIC_OPEN_V1
;
936 exception
->retry
= 1;
940 static enum open_claim_type4
941 nfs4_map_atomic_open_claim(struct nfs_server
*server
,
942 enum open_claim_type4 claim
)
944 if (server
->caps
& NFS_CAP_ATOMIC_OPEN_V1
)
949 case NFS4_OPEN_CLAIM_FH
:
950 return NFS4_OPEN_CLAIM_NULL
;
951 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
952 return NFS4_OPEN_CLAIM_DELEGATE_CUR
;
953 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
954 return NFS4_OPEN_CLAIM_DELEGATE_PREV
;
958 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
960 p
->o_res
.f_attr
= &p
->f_attr
;
961 p
->o_res
.f_label
= p
->f_label
;
962 p
->o_res
.seqid
= p
->o_arg
.seqid
;
963 p
->c_res
.seqid
= p
->c_arg
.seqid
;
964 p
->o_res
.server
= p
->o_arg
.server
;
965 p
->o_res
.access_request
= p
->o_arg
.access
;
966 nfs_fattr_init(&p
->f_attr
);
967 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
970 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
971 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
972 const struct iattr
*attrs
,
973 struct nfs4_label
*label
,
974 enum open_claim_type4 claim
,
977 struct dentry
*parent
= dget_parent(dentry
);
978 struct inode
*dir
= parent
->d_inode
;
979 struct nfs_server
*server
= NFS_SERVER(dir
);
980 struct nfs4_opendata
*p
;
982 p
= kzalloc(sizeof(*p
), gfp_mask
);
986 p
->f_label
= nfs4_label_alloc(server
, gfp_mask
);
987 if (IS_ERR(p
->f_label
))
990 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
991 if (p
->o_arg
.seqid
== NULL
)
993 nfs_sb_active(dentry
->d_sb
);
994 p
->dentry
= dget(dentry
);
997 atomic_inc(&sp
->so_count
);
998 p
->o_arg
.open_flags
= flags
;
999 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
1000 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
1001 * will return permission denied for all bits until close */
1002 if (!(flags
& O_EXCL
)) {
1003 /* ask server to check for all possible rights as results
1005 p
->o_arg
.access
= NFS4_ACCESS_READ
| NFS4_ACCESS_MODIFY
|
1006 NFS4_ACCESS_EXTEND
| NFS4_ACCESS_EXECUTE
;
1008 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
1009 p
->o_arg
.id
.create_time
= ktime_to_ns(sp
->so_seqid
.create_time
);
1010 p
->o_arg
.id
.uniquifier
= sp
->so_seqid
.owner_id
;
1011 p
->o_arg
.name
= &dentry
->d_name
;
1012 p
->o_arg
.server
= server
;
1013 p
->o_arg
.bitmask
= nfs4_bitmask(server
, label
);
1014 p
->o_arg
.open_bitmap
= &nfs4_fattr_bitmap
[0];
1015 p
->o_arg
.label
= label
;
1016 p
->o_arg
.claim
= nfs4_map_atomic_open_claim(server
, claim
);
1017 switch (p
->o_arg
.claim
) {
1018 case NFS4_OPEN_CLAIM_NULL
:
1019 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1020 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1021 p
->o_arg
.fh
= NFS_FH(dir
);
1023 case NFS4_OPEN_CLAIM_PREVIOUS
:
1024 case NFS4_OPEN_CLAIM_FH
:
1025 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1026 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1027 p
->o_arg
.fh
= NFS_FH(dentry
->d_inode
);
1029 if (attrs
!= NULL
&& attrs
->ia_valid
!= 0) {
1032 p
->o_arg
.u
.attrs
= &p
->attrs
;
1033 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
1036 verf
[1] = current
->pid
;
1037 memcpy(p
->o_arg
.u
.verifier
.data
, verf
,
1038 sizeof(p
->o_arg
.u
.verifier
.data
));
1040 p
->c_arg
.fh
= &p
->o_res
.fh
;
1041 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
1042 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
1043 nfs4_init_opendata_res(p
);
1044 kref_init(&p
->kref
);
1048 nfs4_label_free(p
->f_label
);
1056 static void nfs4_opendata_free(struct kref
*kref
)
1058 struct nfs4_opendata
*p
= container_of(kref
,
1059 struct nfs4_opendata
, kref
);
1060 struct super_block
*sb
= p
->dentry
->d_sb
;
1062 nfs_free_seqid(p
->o_arg
.seqid
);
1063 if (p
->state
!= NULL
)
1064 nfs4_put_open_state(p
->state
);
1065 nfs4_put_state_owner(p
->owner
);
1067 nfs4_label_free(p
->f_label
);
1071 nfs_sb_deactive(sb
);
1072 nfs_fattr_free_names(&p
->f_attr
);
1076 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
1079 kref_put(&p
->kref
, nfs4_opendata_free
);
1082 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
1086 ret
= rpc_wait_for_completion_task(task
);
1090 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
1094 if (open_mode
& (O_EXCL
|O_TRUNC
))
1096 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
1098 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
1099 && state
->n_rdonly
!= 0;
1102 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
1103 && state
->n_wronly
!= 0;
1105 case FMODE_READ
|FMODE_WRITE
:
1106 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
1107 && state
->n_rdwr
!= 0;
1113 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
1115 if (delegation
== NULL
)
1117 if ((delegation
->type
& fmode
) != fmode
)
1119 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
1121 if (test_bit(NFS_DELEGATION_RETURNING
, &delegation
->flags
))
1123 nfs_mark_delegation_referenced(delegation
);
1127 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
1136 case FMODE_READ
|FMODE_WRITE
:
1139 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
1142 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1144 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1145 nfs4_stateid_copy(&state
->stateid
, stateid
);
1146 nfs4_stateid_copy(&state
->open_stateid
, stateid
);
1147 set_bit(NFS_OPEN_STATE
, &state
->flags
);
1150 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1153 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1155 case FMODE_READ
|FMODE_WRITE
:
1156 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1160 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
1162 write_seqlock(&state
->seqlock
);
1163 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
1164 write_sequnlock(&state
->seqlock
);
1167 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
1170 * Protect the call to nfs4_state_set_mode_locked and
1171 * serialise the stateid update
1173 write_seqlock(&state
->seqlock
);
1174 if (deleg_stateid
!= NULL
) {
1175 nfs4_stateid_copy(&state
->stateid
, deleg_stateid
);
1176 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1178 if (open_stateid
!= NULL
)
1179 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
1180 write_sequnlock(&state
->seqlock
);
1181 spin_lock(&state
->owner
->so_lock
);
1182 update_open_stateflags(state
, fmode
);
1183 spin_unlock(&state
->owner
->so_lock
);
1186 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
1188 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1189 struct nfs_delegation
*deleg_cur
;
1192 fmode
&= (FMODE_READ
|FMODE_WRITE
);
1195 deleg_cur
= rcu_dereference(nfsi
->delegation
);
1196 if (deleg_cur
== NULL
)
1199 spin_lock(&deleg_cur
->lock
);
1200 if (rcu_dereference(nfsi
->delegation
) != deleg_cur
||
1201 test_bit(NFS_DELEGATION_RETURNING
, &deleg_cur
->flags
) ||
1202 (deleg_cur
->type
& fmode
) != fmode
)
1203 goto no_delegation_unlock
;
1205 if (delegation
== NULL
)
1206 delegation
= &deleg_cur
->stateid
;
1207 else if (!nfs4_stateid_match(&deleg_cur
->stateid
, delegation
))
1208 goto no_delegation_unlock
;
1210 nfs_mark_delegation_referenced(deleg_cur
);
1211 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
1213 no_delegation_unlock
:
1214 spin_unlock(&deleg_cur
->lock
);
1218 if (!ret
&& open_stateid
!= NULL
) {
1219 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1227 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1229 struct nfs_delegation
*delegation
;
1232 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1233 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1238 nfs4_inode_return_delegation(inode
);
1241 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1243 struct nfs4_state
*state
= opendata
->state
;
1244 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1245 struct nfs_delegation
*delegation
;
1246 int open_mode
= opendata
->o_arg
.open_flags
;
1247 fmode_t fmode
= opendata
->o_arg
.fmode
;
1248 nfs4_stateid stateid
;
1252 if (can_open_cached(state
, fmode
, open_mode
)) {
1253 spin_lock(&state
->owner
->so_lock
);
1254 if (can_open_cached(state
, fmode
, open_mode
)) {
1255 update_open_stateflags(state
, fmode
);
1256 spin_unlock(&state
->owner
->so_lock
);
1257 goto out_return_state
;
1259 spin_unlock(&state
->owner
->so_lock
);
1262 delegation
= rcu_dereference(nfsi
->delegation
);
1263 if (!can_open_delegated(delegation
, fmode
)) {
1267 /* Save the delegation */
1268 nfs4_stateid_copy(&stateid
, &delegation
->stateid
);
1270 nfs_release_seqid(opendata
->o_arg
.seqid
);
1271 if (!opendata
->is_recover
) {
1272 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1278 /* Try to update the stateid using the delegation */
1279 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1280 goto out_return_state
;
1283 return ERR_PTR(ret
);
1285 atomic_inc(&state
->count
);
1290 nfs4_opendata_check_deleg(struct nfs4_opendata
*data
, struct nfs4_state
*state
)
1292 struct nfs_client
*clp
= NFS_SERVER(state
->inode
)->nfs_client
;
1293 struct nfs_delegation
*delegation
;
1294 int delegation_flags
= 0;
1297 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1299 delegation_flags
= delegation
->flags
;
1301 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1302 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1303 "returning a delegation for "
1304 "OPEN(CLAIM_DELEGATE_CUR)\n",
1306 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1307 nfs_inode_set_delegation(state
->inode
,
1308 data
->owner
->so_cred
,
1311 nfs_inode_reclaim_delegation(state
->inode
,
1312 data
->owner
->so_cred
,
1317 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1318 * and update the nfs4_state.
1320 static struct nfs4_state
*
1321 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata
*data
)
1323 struct inode
*inode
= data
->state
->inode
;
1324 struct nfs4_state
*state
= data
->state
;
1327 if (!data
->rpc_done
) {
1328 if (data
->rpc_status
) {
1329 ret
= data
->rpc_status
;
1332 /* cached opens have already been processed */
1336 ret
= nfs_refresh_inode(inode
, &data
->f_attr
);
1340 if (data
->o_res
.delegation_type
!= 0)
1341 nfs4_opendata_check_deleg(data
, state
);
1343 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1345 atomic_inc(&state
->count
);
1349 return ERR_PTR(ret
);
1353 static struct nfs4_state
*
1354 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1356 struct inode
*inode
;
1357 struct nfs4_state
*state
= NULL
;
1360 if (!data
->rpc_done
) {
1361 state
= nfs4_try_open_cached(data
);
1366 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1368 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
, data
->f_label
);
1369 ret
= PTR_ERR(inode
);
1373 state
= nfs4_get_open_state(inode
, data
->owner
);
1376 if (data
->o_res
.delegation_type
!= 0)
1377 nfs4_opendata_check_deleg(data
, state
);
1378 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1382 nfs_release_seqid(data
->o_arg
.seqid
);
1387 return ERR_PTR(ret
);
1390 static struct nfs4_state
*
1391 nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1393 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
1394 return _nfs4_opendata_reclaim_to_nfs4_state(data
);
1395 return _nfs4_opendata_to_nfs4_state(data
);
1398 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1400 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1401 struct nfs_open_context
*ctx
;
1403 spin_lock(&state
->inode
->i_lock
);
1404 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1405 if (ctx
->state
!= state
)
1407 get_nfs_open_context(ctx
);
1408 spin_unlock(&state
->inode
->i_lock
);
1411 spin_unlock(&state
->inode
->i_lock
);
1412 return ERR_PTR(-ENOENT
);
1415 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
,
1416 struct nfs4_state
*state
, enum open_claim_type4 claim
)
1418 struct nfs4_opendata
*opendata
;
1420 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0,
1421 NULL
, NULL
, claim
, GFP_NOFS
);
1422 if (opendata
== NULL
)
1423 return ERR_PTR(-ENOMEM
);
1424 opendata
->state
= state
;
1425 atomic_inc(&state
->count
);
1429 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1431 struct nfs4_state
*newstate
;
1434 opendata
->o_arg
.open_flags
= 0;
1435 opendata
->o_arg
.fmode
= fmode
;
1436 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1437 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1438 nfs4_init_opendata_res(opendata
);
1439 ret
= _nfs4_recover_proc_open(opendata
);
1442 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1443 if (IS_ERR(newstate
))
1444 return PTR_ERR(newstate
);
1445 nfs4_close_state(newstate
, fmode
);
1450 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1452 struct nfs4_state
*newstate
;
1455 /* memory barrier prior to reading state->n_* */
1456 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1457 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
1459 if (state
->n_rdwr
!= 0) {
1460 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1461 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1464 if (newstate
!= state
)
1467 if (state
->n_wronly
!= 0) {
1468 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1469 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1472 if (newstate
!= state
)
1475 if (state
->n_rdonly
!= 0) {
1476 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1477 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1480 if (newstate
!= state
)
1484 * We may have performed cached opens for all three recoveries.
1485 * Check if we need to update the current stateid.
1487 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1488 !nfs4_stateid_match(&state
->stateid
, &state
->open_stateid
)) {
1489 write_seqlock(&state
->seqlock
);
1490 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1491 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
1492 write_sequnlock(&state
->seqlock
);
1499 * reclaim state on the server after a reboot.
1501 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1503 struct nfs_delegation
*delegation
;
1504 struct nfs4_opendata
*opendata
;
1505 fmode_t delegation_type
= 0;
1508 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1509 NFS4_OPEN_CLAIM_PREVIOUS
);
1510 if (IS_ERR(opendata
))
1511 return PTR_ERR(opendata
);
1513 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1514 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1515 delegation_type
= delegation
->type
;
1517 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1518 status
= nfs4_open_recover(opendata
, state
);
1519 nfs4_opendata_put(opendata
);
1523 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1525 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1526 struct nfs4_exception exception
= { };
1529 err
= _nfs4_do_open_reclaim(ctx
, state
);
1530 trace_nfs4_open_reclaim(ctx
, 0, err
);
1531 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
1533 if (err
!= -NFS4ERR_DELAY
)
1535 nfs4_handle_exception(server
, err
, &exception
);
1536 } while (exception
.retry
);
1540 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1542 struct nfs_open_context
*ctx
;
1545 ctx
= nfs4_state_find_open_context(state
);
1548 ret
= nfs4_do_open_reclaim(ctx
, state
);
1549 put_nfs_open_context(ctx
);
1553 static int nfs4_handle_delegation_recall_error(struct nfs_server
*server
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
, int err
)
1557 printk(KERN_ERR
"NFS: %s: unhandled error "
1558 "%d.\n", __func__
, err
);
1563 case -NFS4ERR_BADSESSION
:
1564 case -NFS4ERR_BADSLOT
:
1565 case -NFS4ERR_BAD_HIGH_SLOT
:
1566 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1567 case -NFS4ERR_DEADSESSION
:
1568 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1569 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
, err
);
1571 case -NFS4ERR_STALE_CLIENTID
:
1572 case -NFS4ERR_STALE_STATEID
:
1573 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1574 case -NFS4ERR_EXPIRED
:
1575 /* Don't recall a delegation if it was lost */
1576 nfs4_schedule_lease_recovery(server
->nfs_client
);
1578 case -NFS4ERR_MOVED
:
1579 nfs4_schedule_migration_recovery(server
);
1581 case -NFS4ERR_LEASE_MOVED
:
1582 nfs4_schedule_lease_moved_recovery(server
->nfs_client
);
1584 case -NFS4ERR_DELEG_REVOKED
:
1585 case -NFS4ERR_ADMIN_REVOKED
:
1586 case -NFS4ERR_BAD_STATEID
:
1587 case -NFS4ERR_OPENMODE
:
1588 nfs_inode_find_state_and_recover(state
->inode
,
1590 nfs4_schedule_stateid_recovery(server
, state
);
1592 case -NFS4ERR_DELAY
:
1593 case -NFS4ERR_GRACE
:
1594 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1598 case -NFS4ERR_DENIED
:
1599 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1605 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1607 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1608 struct nfs4_opendata
*opendata
;
1611 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1612 NFS4_OPEN_CLAIM_DELEG_CUR_FH
);
1613 if (IS_ERR(opendata
))
1614 return PTR_ERR(opendata
);
1615 nfs4_stateid_copy(&opendata
->o_arg
.u
.delegation
, stateid
);
1616 err
= nfs4_open_recover(opendata
, state
);
1617 nfs4_opendata_put(opendata
);
1618 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
1621 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
1623 struct nfs4_opendata
*data
= calldata
;
1625 nfs40_setup_sequence(data
->o_arg
.server
, &data
->o_arg
.seq_args
,
1626 &data
->o_res
.seq_res
, task
);
1629 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1631 struct nfs4_opendata
*data
= calldata
;
1633 nfs40_sequence_done(task
, &data
->o_res
.seq_res
);
1635 data
->rpc_status
= task
->tk_status
;
1636 if (data
->rpc_status
== 0) {
1637 nfs4_stateid_copy(&data
->o_res
.stateid
, &data
->c_res
.stateid
);
1638 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1639 renew_lease(data
->o_res
.server
, data
->timestamp
);
1644 static void nfs4_open_confirm_release(void *calldata
)
1646 struct nfs4_opendata
*data
= calldata
;
1647 struct nfs4_state
*state
= NULL
;
1649 /* If this request hasn't been cancelled, do nothing */
1650 if (data
->cancelled
== 0)
1652 /* In case of error, no cleanup! */
1653 if (!data
->rpc_done
)
1655 state
= nfs4_opendata_to_nfs4_state(data
);
1657 nfs4_close_state(state
, data
->o_arg
.fmode
);
1659 nfs4_opendata_put(data
);
1662 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1663 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
1664 .rpc_call_done
= nfs4_open_confirm_done
,
1665 .rpc_release
= nfs4_open_confirm_release
,
1669 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1671 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1673 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1674 struct rpc_task
*task
;
1675 struct rpc_message msg
= {
1676 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1677 .rpc_argp
= &data
->c_arg
,
1678 .rpc_resp
= &data
->c_res
,
1679 .rpc_cred
= data
->owner
->so_cred
,
1681 struct rpc_task_setup task_setup_data
= {
1682 .rpc_client
= server
->client
,
1683 .rpc_message
= &msg
,
1684 .callback_ops
= &nfs4_open_confirm_ops
,
1685 .callback_data
= data
,
1686 .workqueue
= nfsiod_workqueue
,
1687 .flags
= RPC_TASK_ASYNC
,
1691 nfs4_init_sequence(&data
->o_arg
.seq_args
, &data
->o_res
.seq_res
, 1);
1692 kref_get(&data
->kref
);
1694 data
->rpc_status
= 0;
1695 data
->timestamp
= jiffies
;
1696 task
= rpc_run_task(&task_setup_data
);
1698 return PTR_ERR(task
);
1699 status
= nfs4_wait_for_completion_rpc_task(task
);
1701 data
->cancelled
= 1;
1704 status
= data
->rpc_status
;
1709 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1711 struct nfs4_opendata
*data
= calldata
;
1712 struct nfs4_state_owner
*sp
= data
->owner
;
1713 struct nfs_client
*clp
= sp
->so_server
->nfs_client
;
1715 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1718 * Check if we still need to send an OPEN call, or if we can use
1719 * a delegation instead.
1721 if (data
->state
!= NULL
) {
1722 struct nfs_delegation
*delegation
;
1724 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1727 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1728 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1729 data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEG_CUR_FH
&&
1730 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1731 goto unlock_no_action
;
1734 /* Update client id. */
1735 data
->o_arg
.clientid
= clp
->cl_clientid
;
1736 switch (data
->o_arg
.claim
) {
1737 case NFS4_OPEN_CLAIM_PREVIOUS
:
1738 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1739 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1740 data
->o_arg
.open_bitmap
= &nfs4_open_noattr_bitmap
[0];
1741 case NFS4_OPEN_CLAIM_FH
:
1742 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1743 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1745 data
->timestamp
= jiffies
;
1746 if (nfs4_setup_sequence(data
->o_arg
.server
,
1747 &data
->o_arg
.seq_args
,
1748 &data
->o_res
.seq_res
,
1750 nfs_release_seqid(data
->o_arg
.seqid
);
1752 /* Set the create mode (note dependency on the session type) */
1753 data
->o_arg
.createmode
= NFS4_CREATE_UNCHECKED
;
1754 if (data
->o_arg
.open_flags
& O_EXCL
) {
1755 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE
;
1756 if (nfs4_has_persistent_session(clp
))
1757 data
->o_arg
.createmode
= NFS4_CREATE_GUARDED
;
1758 else if (clp
->cl_mvops
->minor_version
> 0)
1759 data
->o_arg
.createmode
= NFS4_CREATE_EXCLUSIVE4_1
;
1765 task
->tk_action
= NULL
;
1767 nfs4_sequence_done(task
, &data
->o_res
.seq_res
);
1770 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1772 struct nfs4_opendata
*data
= calldata
;
1774 data
->rpc_status
= task
->tk_status
;
1776 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1779 if (task
->tk_status
== 0) {
1780 if (data
->o_res
.f_attr
->valid
& NFS_ATTR_FATTR_TYPE
) {
1781 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1785 data
->rpc_status
= -ELOOP
;
1788 data
->rpc_status
= -EISDIR
;
1791 data
->rpc_status
= -ENOTDIR
;
1794 renew_lease(data
->o_res
.server
, data
->timestamp
);
1795 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1796 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1801 static void nfs4_open_release(void *calldata
)
1803 struct nfs4_opendata
*data
= calldata
;
1804 struct nfs4_state
*state
= NULL
;
1806 /* If this request hasn't been cancelled, do nothing */
1807 if (data
->cancelled
== 0)
1809 /* In case of error, no cleanup! */
1810 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1812 /* In case we need an open_confirm, no cleanup! */
1813 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1815 state
= nfs4_opendata_to_nfs4_state(data
);
1817 nfs4_close_state(state
, data
->o_arg
.fmode
);
1819 nfs4_opendata_put(data
);
1822 static const struct rpc_call_ops nfs4_open_ops
= {
1823 .rpc_call_prepare
= nfs4_open_prepare
,
1824 .rpc_call_done
= nfs4_open_done
,
1825 .rpc_release
= nfs4_open_release
,
1828 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1830 struct inode
*dir
= data
->dir
->d_inode
;
1831 struct nfs_server
*server
= NFS_SERVER(dir
);
1832 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1833 struct nfs_openres
*o_res
= &data
->o_res
;
1834 struct rpc_task
*task
;
1835 struct rpc_message msg
= {
1836 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1839 .rpc_cred
= data
->owner
->so_cred
,
1841 struct rpc_task_setup task_setup_data
= {
1842 .rpc_client
= server
->client
,
1843 .rpc_message
= &msg
,
1844 .callback_ops
= &nfs4_open_ops
,
1845 .callback_data
= data
,
1846 .workqueue
= nfsiod_workqueue
,
1847 .flags
= RPC_TASK_ASYNC
,
1851 nfs4_init_sequence(&o_arg
->seq_args
, &o_res
->seq_res
, 1);
1852 kref_get(&data
->kref
);
1854 data
->rpc_status
= 0;
1855 data
->cancelled
= 0;
1856 data
->is_recover
= 0;
1858 nfs4_set_sequence_privileged(&o_arg
->seq_args
);
1859 data
->is_recover
= 1;
1861 task
= rpc_run_task(&task_setup_data
);
1863 return PTR_ERR(task
);
1864 status
= nfs4_wait_for_completion_rpc_task(task
);
1866 data
->cancelled
= 1;
1869 status
= data
->rpc_status
;
1875 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1877 struct inode
*dir
= data
->dir
->d_inode
;
1878 struct nfs_openres
*o_res
= &data
->o_res
;
1881 status
= nfs4_run_open_task(data
, 1);
1882 if (status
!= 0 || !data
->rpc_done
)
1885 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1887 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1888 status
= _nfs4_proc_open_confirm(data
);
1896 static int nfs4_opendata_access(struct rpc_cred
*cred
,
1897 struct nfs4_opendata
*opendata
,
1898 struct nfs4_state
*state
, fmode_t fmode
,
1901 struct nfs_access_entry cache
;
1904 /* access call failed or for some reason the server doesn't
1905 * support any access modes -- defer access call until later */
1906 if (opendata
->o_res
.access_supported
== 0)
1910 /* don't check MAY_WRITE - a newly created file may not have
1911 * write mode bits, but POSIX allows the creating process to write.
1912 * use openflags to check for exec, because fmode won't
1913 * always have FMODE_EXEC set when file open for exec. */
1914 if (openflags
& __FMODE_EXEC
) {
1915 /* ONLY check for exec rights */
1917 } else if (fmode
& FMODE_READ
)
1921 cache
.jiffies
= jiffies
;
1922 nfs_access_set_mask(&cache
, opendata
->o_res
.access_result
);
1923 nfs_access_add_cache(state
->inode
, &cache
);
1925 if ((mask
& ~cache
.mask
& (MAY_READ
| MAY_EXEC
)) == 0)
1928 /* even though OPEN succeeded, access is denied. Close the file */
1929 nfs4_close_state(state
, fmode
);
1934 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1936 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1938 struct inode
*dir
= data
->dir
->d_inode
;
1939 struct nfs_server
*server
= NFS_SERVER(dir
);
1940 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1941 struct nfs_openres
*o_res
= &data
->o_res
;
1944 status
= nfs4_run_open_task(data
, 0);
1945 if (!data
->rpc_done
)
1948 if (status
== -NFS4ERR_BADNAME
&&
1949 !(o_arg
->open_flags
& O_CREAT
))
1954 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
1956 if (o_arg
->open_flags
& O_CREAT
) {
1957 update_changeattr(dir
, &o_res
->cinfo
);
1958 if (o_arg
->open_flags
& O_EXCL
)
1959 data
->file_created
= 1;
1960 else if (o_res
->cinfo
.before
!= o_res
->cinfo
.after
)
1961 data
->file_created
= 1;
1963 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1964 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1965 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1966 status
= _nfs4_proc_open_confirm(data
);
1970 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1971 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
, o_res
->f_label
);
1975 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1977 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1982 * reclaim state on the server after a network partition.
1983 * Assumes caller holds the appropriate lock
1985 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1987 struct nfs4_opendata
*opendata
;
1990 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
,
1991 NFS4_OPEN_CLAIM_FH
);
1992 if (IS_ERR(opendata
))
1993 return PTR_ERR(opendata
);
1994 ret
= nfs4_open_recover(opendata
, state
);
1996 d_drop(ctx
->dentry
);
1997 nfs4_opendata_put(opendata
);
2001 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
2003 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2004 struct nfs4_exception exception
= { };
2008 err
= _nfs4_open_expired(ctx
, state
);
2009 trace_nfs4_open_expired(ctx
, 0, err
);
2010 if (nfs4_clear_cap_atomic_open_v1(server
, err
, &exception
))
2015 case -NFS4ERR_GRACE
:
2016 case -NFS4ERR_DELAY
:
2017 nfs4_handle_exception(server
, err
, &exception
);
2020 } while (exception
.retry
);
2025 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2027 struct nfs_open_context
*ctx
;
2030 ctx
= nfs4_state_find_open_context(state
);
2033 ret
= nfs4_do_open_expired(ctx
, state
);
2034 put_nfs_open_context(ctx
);
2038 #if defined(CONFIG_NFS_V4_1)
2039 static void nfs41_clear_delegation_stateid(struct nfs4_state
*state
)
2041 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2042 nfs4_stateid
*stateid
= &state
->stateid
;
2043 struct nfs_delegation
*delegation
;
2044 struct rpc_cred
*cred
= NULL
;
2045 int status
= -NFS4ERR_BAD_STATEID
;
2047 /* If a state reset has been done, test_stateid is unneeded */
2048 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
2051 /* Get the delegation credential for use by test/free_stateid */
2053 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
2054 if (delegation
!= NULL
&&
2055 nfs4_stateid_match(&delegation
->stateid
, stateid
)) {
2056 cred
= get_rpccred(delegation
->cred
);
2058 status
= nfs41_test_stateid(server
, stateid
, cred
);
2059 trace_nfs4_test_delegation_stateid(state
, NULL
, status
);
2063 if (status
!= NFS_OK
) {
2064 /* Free the stateid unless the server explicitly
2065 * informs us the stateid is unrecognized. */
2066 if (status
!= -NFS4ERR_BAD_STATEID
)
2067 nfs41_free_stateid(server
, stateid
, cred
);
2068 nfs_remove_bad_delegation(state
->inode
);
2070 write_seqlock(&state
->seqlock
);
2071 nfs4_stateid_copy(&state
->stateid
, &state
->open_stateid
);
2072 write_sequnlock(&state
->seqlock
);
2073 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
2081 * nfs41_check_open_stateid - possibly free an open stateid
2083 * @state: NFSv4 state for an inode
2085 * Returns NFS_OK if recovery for this stateid is now finished.
2086 * Otherwise a negative NFS4ERR value is returned.
2088 static int nfs41_check_open_stateid(struct nfs4_state
*state
)
2090 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2091 nfs4_stateid
*stateid
= &state
->open_stateid
;
2092 struct rpc_cred
*cred
= state
->owner
->so_cred
;
2095 /* If a state reset has been done, test_stateid is unneeded */
2096 if ((test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) == 0) &&
2097 (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) == 0) &&
2098 (test_bit(NFS_O_RDWR_STATE
, &state
->flags
) == 0))
2099 return -NFS4ERR_BAD_STATEID
;
2101 status
= nfs41_test_stateid(server
, stateid
, cred
);
2102 trace_nfs4_test_open_stateid(state
, NULL
, status
);
2103 if (status
!= NFS_OK
) {
2104 /* Free the stateid unless the server explicitly
2105 * informs us the stateid is unrecognized. */
2106 if (status
!= -NFS4ERR_BAD_STATEID
)
2107 nfs41_free_stateid(server
, stateid
, cred
);
2109 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2110 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2111 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2112 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2117 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
2121 nfs41_clear_delegation_stateid(state
);
2122 status
= nfs41_check_open_stateid(state
);
2123 if (status
!= NFS_OK
)
2124 status
= nfs4_open_expired(sp
, state
);
2130 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2131 * fields corresponding to attributes that were used to store the verifier.
2132 * Make sure we clobber those fields in the later setattr call
2134 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
2136 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
2137 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
2138 sattr
->ia_valid
|= ATTR_ATIME
;
2140 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
2141 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
2142 sattr
->ia_valid
|= ATTR_MTIME
;
2145 static int _nfs4_open_and_get_state(struct nfs4_opendata
*opendata
,
2148 struct nfs_open_context
*ctx
)
2150 struct nfs4_state_owner
*sp
= opendata
->owner
;
2151 struct nfs_server
*server
= sp
->so_server
;
2152 struct dentry
*dentry
;
2153 struct nfs4_state
*state
;
2157 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
2159 ret
= _nfs4_proc_open(opendata
);
2163 state
= nfs4_opendata_to_nfs4_state(opendata
);
2164 ret
= PTR_ERR(state
);
2167 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
2168 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
2170 dentry
= opendata
->dentry
;
2171 if (dentry
->d_inode
== NULL
) {
2172 /* FIXME: Is this d_drop() ever needed? */
2174 dentry
= d_add_unique(dentry
, igrab(state
->inode
));
2175 if (dentry
== NULL
) {
2176 dentry
= opendata
->dentry
;
2177 } else if (dentry
!= ctx
->dentry
) {
2179 ctx
->dentry
= dget(dentry
);
2181 nfs_set_verifier(dentry
,
2182 nfs_save_change_attribute(opendata
->dir
->d_inode
));
2185 ret
= nfs4_opendata_access(sp
->so_cred
, opendata
, state
, fmode
, flags
);
2190 if (dentry
->d_inode
== state
->inode
) {
2191 nfs_inode_attach_open_context(ctx
);
2192 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
))
2193 nfs4_schedule_stateid_recovery(server
, state
);
2200 * Returns a referenced nfs4_state
2202 static int _nfs4_do_open(struct inode
*dir
,
2203 struct nfs_open_context
*ctx
,
2205 struct iattr
*sattr
,
2206 struct nfs4_label
*label
,
2209 struct nfs4_state_owner
*sp
;
2210 struct nfs4_state
*state
= NULL
;
2211 struct nfs_server
*server
= NFS_SERVER(dir
);
2212 struct nfs4_opendata
*opendata
;
2213 struct dentry
*dentry
= ctx
->dentry
;
2214 struct rpc_cred
*cred
= ctx
->cred
;
2215 struct nfs4_threshold
**ctx_th
= &ctx
->mdsthreshold
;
2216 fmode_t fmode
= ctx
->mode
& (FMODE_READ
|FMODE_WRITE
|FMODE_EXEC
);
2217 enum open_claim_type4 claim
= NFS4_OPEN_CLAIM_NULL
;
2218 struct nfs4_label
*olabel
= NULL
;
2221 /* Protect against reboot recovery conflicts */
2223 sp
= nfs4_get_state_owner(server
, cred
, GFP_KERNEL
);
2225 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2228 status
= nfs4_recover_expired_lease(server
);
2230 goto err_put_state_owner
;
2231 if (dentry
->d_inode
!= NULL
)
2232 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
2234 if (dentry
->d_inode
)
2235 claim
= NFS4_OPEN_CLAIM_FH
;
2236 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
,
2237 label
, claim
, GFP_KERNEL
);
2238 if (opendata
== NULL
)
2239 goto err_put_state_owner
;
2242 olabel
= nfs4_label_alloc(server
, GFP_KERNEL
);
2243 if (IS_ERR(olabel
)) {
2244 status
= PTR_ERR(olabel
);
2245 goto err_opendata_put
;
2249 if (ctx_th
&& server
->attr_bitmask
[2] & FATTR4_WORD2_MDSTHRESHOLD
) {
2250 opendata
->f_attr
.mdsthreshold
= pnfs_mdsthreshold_alloc();
2251 if (!opendata
->f_attr
.mdsthreshold
)
2252 goto err_free_label
;
2253 opendata
->o_arg
.open_bitmap
= &nfs4_pnfs_open_bitmap
[0];
2255 if (dentry
->d_inode
!= NULL
)
2256 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
2258 status
= _nfs4_open_and_get_state(opendata
, fmode
, flags
, ctx
);
2260 goto err_free_label
;
2263 if ((opendata
->o_arg
.open_flags
& O_EXCL
) &&
2264 (opendata
->o_arg
.createmode
!= NFS4_CREATE_GUARDED
)) {
2265 nfs4_exclusive_attrset(opendata
, sattr
);
2267 nfs_fattr_init(opendata
->o_res
.f_attr
);
2268 status
= nfs4_do_setattr(state
->inode
, cred
,
2269 opendata
->o_res
.f_attr
, sattr
,
2270 state
, label
, olabel
);
2272 nfs_setattr_update_inode(state
->inode
, sattr
);
2273 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
2274 nfs_setsecurity(state
->inode
, opendata
->o_res
.f_attr
, olabel
);
2277 if (opendata
->file_created
)
2278 *opened
|= FILE_CREATED
;
2280 if (pnfs_use_threshold(ctx_th
, opendata
->f_attr
.mdsthreshold
, server
))
2281 *ctx_th
= opendata
->f_attr
.mdsthreshold
;
2283 kfree(opendata
->f_attr
.mdsthreshold
);
2284 opendata
->f_attr
.mdsthreshold
= NULL
;
2286 nfs4_label_free(olabel
);
2288 nfs4_opendata_put(opendata
);
2289 nfs4_put_state_owner(sp
);
2292 nfs4_label_free(olabel
);
2294 kfree(opendata
->f_attr
.mdsthreshold
);
2295 nfs4_opendata_put(opendata
);
2296 err_put_state_owner
:
2297 nfs4_put_state_owner(sp
);
2303 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
,
2304 struct nfs_open_context
*ctx
,
2306 struct iattr
*sattr
,
2307 struct nfs4_label
*label
,
2310 struct nfs_server
*server
= NFS_SERVER(dir
);
2311 struct nfs4_exception exception
= { };
2312 struct nfs4_state
*res
;
2316 status
= _nfs4_do_open(dir
, ctx
, flags
, sattr
, label
, opened
);
2318 trace_nfs4_open_file(ctx
, flags
, status
);
2321 /* NOTE: BAD_SEQID means the server and client disagree about the
2322 * book-keeping w.r.t. state-changing operations
2323 * (OPEN/CLOSE/LOCK/LOCKU...)
2324 * It is actually a sign of a bug on the client or on the server.
2326 * If we receive a BAD_SEQID error in the particular case of
2327 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2328 * have unhashed the old state_owner for us, and that we can
2329 * therefore safely retry using a new one. We should still warn
2330 * the user though...
2332 if (status
== -NFS4ERR_BAD_SEQID
) {
2333 pr_warn_ratelimited("NFS: v4 server %s "
2334 " returned a bad sequence-id error!\n",
2335 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
2336 exception
.retry
= 1;
2340 * BAD_STATEID on OPEN means that the server cancelled our
2341 * state before it received the OPEN_CONFIRM.
2342 * Recover by retrying the request as per the discussion
2343 * on Page 181 of RFC3530.
2345 if (status
== -NFS4ERR_BAD_STATEID
) {
2346 exception
.retry
= 1;
2349 if (status
== -EAGAIN
) {
2350 /* We must have found a delegation */
2351 exception
.retry
= 1;
2354 if (nfs4_clear_cap_atomic_open_v1(server
, status
, &exception
))
2356 res
= ERR_PTR(nfs4_handle_exception(server
,
2357 status
, &exception
));
2358 } while (exception
.retry
);
2362 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2363 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2364 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2365 struct nfs4_label
*olabel
)
2367 struct nfs_server
*server
= NFS_SERVER(inode
);
2368 struct nfs_setattrargs arg
= {
2369 .fh
= NFS_FH(inode
),
2372 .bitmask
= server
->attr_bitmask
,
2375 struct nfs_setattrres res
= {
2380 struct rpc_message msg
= {
2381 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
2386 unsigned long timestamp
= jiffies
;
2391 arg
.bitmask
= nfs4_bitmask(server
, ilabel
);
2393 arg
.bitmask
= nfs4_bitmask(server
, olabel
);
2395 nfs_fattr_init(fattr
);
2397 /* Servers should only apply open mode checks for file size changes */
2398 truncate
= (sattr
->ia_valid
& ATTR_SIZE
) ? true : false;
2399 fmode
= truncate
? FMODE_WRITE
: FMODE_READ
;
2401 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
, fmode
)) {
2402 /* Use that stateid */
2403 } else if (truncate
&& state
!= NULL
&& nfs4_valid_open_stateid(state
)) {
2404 struct nfs_lockowner lockowner
= {
2405 .l_owner
= current
->files
,
2406 .l_pid
= current
->tgid
,
2408 nfs4_select_rw_stateid(&arg
.stateid
, state
, FMODE_WRITE
,
2411 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
2413 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2414 if (status
== 0 && state
!= NULL
)
2415 renew_lease(server
, timestamp
);
2419 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
2420 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
2421 struct nfs4_state
*state
, struct nfs4_label
*ilabel
,
2422 struct nfs4_label
*olabel
)
2424 struct nfs_server
*server
= NFS_SERVER(inode
);
2425 struct nfs4_exception exception
= {
2431 err
= _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, ilabel
, olabel
);
2432 trace_nfs4_setattr(inode
, err
);
2434 case -NFS4ERR_OPENMODE
:
2435 if (!(sattr
->ia_valid
& ATTR_SIZE
)) {
2436 pr_warn_once("NFSv4: server %s is incorrectly "
2437 "applying open mode checks to "
2438 "a SETATTR that is not "
2439 "changing file size.\n",
2440 server
->nfs_client
->cl_hostname
);
2442 if (state
&& !(state
->state
& FMODE_WRITE
)) {
2444 if (sattr
->ia_valid
& ATTR_OPEN
)
2449 err
= nfs4_handle_exception(server
, err
, &exception
);
2450 } while (exception
.retry
);
2455 struct nfs4_closedata
{
2456 struct inode
*inode
;
2457 struct nfs4_state
*state
;
2458 struct nfs_closeargs arg
;
2459 struct nfs_closeres res
;
2460 struct nfs_fattr fattr
;
2461 unsigned long timestamp
;
2466 static void nfs4_free_closedata(void *data
)
2468 struct nfs4_closedata
*calldata
= data
;
2469 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
2470 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
2473 pnfs_roc_release(calldata
->state
->inode
);
2474 nfs4_put_open_state(calldata
->state
);
2475 nfs_free_seqid(calldata
->arg
.seqid
);
2476 nfs4_put_state_owner(sp
);
2477 nfs_sb_deactive(sb
);
2481 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
2484 spin_lock(&state
->owner
->so_lock
);
2485 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2486 switch (fmode
& (FMODE_READ
|FMODE_WRITE
)) {
2488 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2491 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2494 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2495 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2496 clear_bit(NFS_OPEN_STATE
, &state
->flags
);
2498 spin_unlock(&state
->owner
->so_lock
);
2501 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
2503 struct nfs4_closedata
*calldata
= data
;
2504 struct nfs4_state
*state
= calldata
->state
;
2505 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
2507 dprintk("%s: begin!\n", __func__
);
2508 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
2510 trace_nfs4_close(state
, &calldata
->arg
, &calldata
->res
, task
->tk_status
);
2511 /* hmm. we are done with the inode, and in the process of freeing
2512 * the state_owner. we keep this around to process errors
2514 switch (task
->tk_status
) {
2517 pnfs_roc_set_barrier(state
->inode
,
2518 calldata
->roc_barrier
);
2519 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
2520 renew_lease(server
, calldata
->timestamp
);
2521 nfs4_close_clear_stateid_flags(state
,
2522 calldata
->arg
.fmode
);
2524 case -NFS4ERR_STALE_STATEID
:
2525 case -NFS4ERR_OLD_STATEID
:
2526 case -NFS4ERR_BAD_STATEID
:
2527 case -NFS4ERR_EXPIRED
:
2528 if (calldata
->arg
.fmode
== 0)
2531 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
2532 rpc_restart_call_prepare(task
);
2534 nfs_release_seqid(calldata
->arg
.seqid
);
2535 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
2536 dprintk("%s: done, ret = %d!\n", __func__
, task
->tk_status
);
2539 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
2541 struct nfs4_closedata
*calldata
= data
;
2542 struct nfs4_state
*state
= calldata
->state
;
2543 struct inode
*inode
= calldata
->inode
;
2546 dprintk("%s: begin!\n", __func__
);
2547 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
2550 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
2551 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
2552 spin_lock(&state
->owner
->so_lock
);
2553 /* Calculate the change in open mode */
2554 if (state
->n_rdwr
== 0) {
2555 if (state
->n_rdonly
== 0) {
2556 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2557 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2558 calldata
->arg
.fmode
&= ~FMODE_READ
;
2560 if (state
->n_wronly
== 0) {
2561 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2562 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2563 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2566 if (!nfs4_valid_open_stateid(state
))
2568 spin_unlock(&state
->owner
->so_lock
);
2571 /* Note: exit _without_ calling nfs4_close_done */
2575 if (calldata
->arg
.fmode
== 0) {
2576 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2577 if (calldata
->roc
&&
2578 pnfs_roc_drain(inode
, &calldata
->roc_barrier
, task
)) {
2579 nfs_release_seqid(calldata
->arg
.seqid
);
2584 nfs_fattr_init(calldata
->res
.fattr
);
2585 calldata
->timestamp
= jiffies
;
2586 if (nfs4_setup_sequence(NFS_SERVER(inode
),
2587 &calldata
->arg
.seq_args
,
2588 &calldata
->res
.seq_res
,
2590 nfs_release_seqid(calldata
->arg
.seqid
);
2591 dprintk("%s: done!\n", __func__
);
2594 task
->tk_action
= NULL
;
2596 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
2599 static const struct rpc_call_ops nfs4_close_ops
= {
2600 .rpc_call_prepare
= nfs4_close_prepare
,
2601 .rpc_call_done
= nfs4_close_done
,
2602 .rpc_release
= nfs4_free_closedata
,
2606 * It is possible for data to be read/written from a mem-mapped file
2607 * after the sys_close call (which hits the vfs layer as a flush).
2608 * This means that we can't safely call nfsv4 close on a file until
2609 * the inode is cleared. This in turn means that we are not good
2610 * NFSv4 citizens - we do not indicate to the server to update the file's
2611 * share state even when we are done with one of the three share
2612 * stateid's in the inode.
2614 * NOTE: Caller must be holding the sp->so_owner semaphore!
2616 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
)
2618 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2619 struct nfs4_closedata
*calldata
;
2620 struct nfs4_state_owner
*sp
= state
->owner
;
2621 struct rpc_task
*task
;
2622 struct rpc_message msg
= {
2623 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2624 .rpc_cred
= state
->owner
->so_cred
,
2626 struct rpc_task_setup task_setup_data
= {
2627 .rpc_client
= server
->client
,
2628 .rpc_message
= &msg
,
2629 .callback_ops
= &nfs4_close_ops
,
2630 .workqueue
= nfsiod_workqueue
,
2631 .flags
= RPC_TASK_ASYNC
,
2633 int status
= -ENOMEM
;
2635 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_CLEANUP
,
2636 &task_setup_data
.rpc_client
, &msg
);
2638 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2639 if (calldata
== NULL
)
2641 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 1);
2642 calldata
->inode
= state
->inode
;
2643 calldata
->state
= state
;
2644 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2645 calldata
->arg
.stateid
= &state
->open_stateid
;
2646 /* Serialization for the sequence id */
2647 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2648 if (calldata
->arg
.seqid
== NULL
)
2649 goto out_free_calldata
;
2650 calldata
->arg
.fmode
= 0;
2651 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2652 calldata
->res
.fattr
= &calldata
->fattr
;
2653 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2654 calldata
->res
.server
= server
;
2655 calldata
->roc
= pnfs_roc(state
->inode
);
2656 nfs_sb_active(calldata
->inode
->i_sb
);
2658 msg
.rpc_argp
= &calldata
->arg
;
2659 msg
.rpc_resp
= &calldata
->res
;
2660 task_setup_data
.callback_data
= calldata
;
2661 task
= rpc_run_task(&task_setup_data
);
2663 return PTR_ERR(task
);
2666 status
= rpc_wait_for_completion_task(task
);
2672 nfs4_put_open_state(state
);
2673 nfs4_put_state_owner(sp
);
2677 static struct inode
*
2678 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
,
2679 int open_flags
, struct iattr
*attr
, int *opened
)
2681 struct nfs4_state
*state
;
2682 struct nfs4_label l
= {0, 0, 0, NULL
}, *label
= NULL
;
2684 label
= nfs4_label_init_security(dir
, ctx
->dentry
, attr
, &l
);
2686 /* Protect against concurrent sillydeletes */
2687 state
= nfs4_do_open(dir
, ctx
, open_flags
, attr
, label
, opened
);
2689 nfs4_label_release_security(label
);
2692 return ERR_CAST(state
);
2693 return state
->inode
;
2696 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2698 if (ctx
->state
== NULL
)
2701 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2703 nfs4_close_state(ctx
->state
, ctx
->mode
);
2706 #define FATTR4_WORD1_NFS40_MASK (2*FATTR4_WORD1_MOUNTED_ON_FILEID - 1UL)
2707 #define FATTR4_WORD2_NFS41_MASK (2*FATTR4_WORD2_SUPPATTR_EXCLCREAT - 1UL)
2708 #define FATTR4_WORD2_NFS42_MASK (2*FATTR4_WORD2_CHANGE_SECURITY_LABEL - 1UL)
2710 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2712 struct nfs4_server_caps_arg args
= {
2715 struct nfs4_server_caps_res res
= {};
2716 struct rpc_message msg
= {
2717 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2723 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2725 /* Sanity check the server answers */
2726 switch (server
->nfs_client
->cl_minorversion
) {
2728 res
.attr_bitmask
[1] &= FATTR4_WORD1_NFS40_MASK
;
2729 res
.attr_bitmask
[2] = 0;
2732 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS41_MASK
;
2735 res
.attr_bitmask
[2] &= FATTR4_WORD2_NFS42_MASK
;
2737 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2738 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2739 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2740 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2741 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2742 NFS_CAP_CTIME
|NFS_CAP_MTIME
|
2743 NFS_CAP_SECURITY_LABEL
);
2744 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2745 server
->caps
|= NFS_CAP_ACLS
;
2746 if (res
.has_links
!= 0)
2747 server
->caps
|= NFS_CAP_HARDLINKS
;
2748 if (res
.has_symlinks
!= 0)
2749 server
->caps
|= NFS_CAP_SYMLINKS
;
2750 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2751 server
->caps
|= NFS_CAP_FILEID
;
2752 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2753 server
->caps
|= NFS_CAP_MODE
;
2754 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2755 server
->caps
|= NFS_CAP_NLINK
;
2756 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2757 server
->caps
|= NFS_CAP_OWNER
;
2758 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2759 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2760 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2761 server
->caps
|= NFS_CAP_ATIME
;
2762 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2763 server
->caps
|= NFS_CAP_CTIME
;
2764 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2765 server
->caps
|= NFS_CAP_MTIME
;
2766 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2767 if (res
.attr_bitmask
[2] & FATTR4_WORD2_SECURITY_LABEL
)
2768 server
->caps
|= NFS_CAP_SECURITY_LABEL
;
2770 memcpy(server
->attr_bitmask_nl
, res
.attr_bitmask
,
2771 sizeof(server
->attr_bitmask
));
2772 server
->attr_bitmask_nl
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2774 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2775 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2776 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2777 server
->cache_consistency_bitmask
[2] = 0;
2778 server
->acl_bitmask
= res
.acl_bitmask
;
2779 server
->fh_expire_type
= res
.fh_expire_type
;
2785 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2787 struct nfs4_exception exception
= { };
2790 err
= nfs4_handle_exception(server
,
2791 _nfs4_server_capabilities(server
, fhandle
),
2793 } while (exception
.retry
);
2797 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2798 struct nfs_fsinfo
*info
)
2801 struct nfs4_lookup_root_arg args
= {
2804 struct nfs4_lookup_res res
= {
2806 .fattr
= info
->fattr
,
2809 struct rpc_message msg
= {
2810 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2815 bitmask
[0] = nfs4_fattr_bitmap
[0];
2816 bitmask
[1] = nfs4_fattr_bitmap
[1];
2818 * Process the label in the upcoming getfattr
2820 bitmask
[2] = nfs4_fattr_bitmap
[2] & ~FATTR4_WORD2_SECURITY_LABEL
;
2822 nfs_fattr_init(info
->fattr
);
2823 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2826 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2827 struct nfs_fsinfo
*info
)
2829 struct nfs4_exception exception
= { };
2832 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2833 trace_nfs4_lookup_root(server
, fhandle
, info
->fattr
, err
);
2836 case -NFS4ERR_WRONGSEC
:
2839 err
= nfs4_handle_exception(server
, err
, &exception
);
2841 } while (exception
.retry
);
2846 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2847 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2849 struct rpc_auth_create_args auth_args
= {
2850 .pseudoflavor
= flavor
,
2852 struct rpc_auth
*auth
;
2855 auth
= rpcauth_create(&auth_args
, server
->client
);
2860 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2866 * Retry pseudoroot lookup with various security flavors. We do this when:
2868 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2869 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2871 * Returns zero on success, or a negative NFS4ERR value, or a
2872 * negative errno value.
2874 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2875 struct nfs_fsinfo
*info
)
2877 /* Per 3530bis 15.33.5 */
2878 static const rpc_authflavor_t flav_array
[] = {
2882 RPC_AUTH_UNIX
, /* courtesy */
2885 int status
= -EPERM
;
2888 if (server
->auth_info
.flavor_len
> 0) {
2889 /* try each flavor specified by user */
2890 for (i
= 0; i
< server
->auth_info
.flavor_len
; i
++) {
2891 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
2892 server
->auth_info
.flavors
[i
]);
2893 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2898 /* no flavors specified by user, try default list */
2899 for (i
= 0; i
< ARRAY_SIZE(flav_array
); i
++) {
2900 status
= nfs4_lookup_root_sec(server
, fhandle
, info
,
2902 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2909 * -EACCESS could mean that the user doesn't have correct permissions
2910 * to access the mount. It could also mean that we tried to mount
2911 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2912 * existing mount programs don't handle -EACCES very well so it should
2913 * be mapped to -EPERM instead.
2915 if (status
== -EACCES
)
2920 static int nfs4_do_find_root_sec(struct nfs_server
*server
,
2921 struct nfs_fh
*fhandle
, struct nfs_fsinfo
*info
)
2923 int mv
= server
->nfs_client
->cl_minorversion
;
2924 return nfs_v4_minor_ops
[mv
]->find_root_sec(server
, fhandle
, info
);
2928 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2929 * @server: initialized nfs_server handle
2930 * @fhandle: we fill in the pseudo-fs root file handle
2931 * @info: we fill in an FSINFO struct
2932 * @auth_probe: probe the auth flavours
2934 * Returns zero on success, or a negative errno.
2936 int nfs4_proc_get_rootfh(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2937 struct nfs_fsinfo
*info
,
2942 switch (auth_probe
) {
2944 status
= nfs4_lookup_root(server
, fhandle
, info
);
2945 if (status
!= -NFS4ERR_WRONGSEC
)
2948 status
= nfs4_do_find_root_sec(server
, fhandle
, info
);
2952 status
= nfs4_server_capabilities(server
, fhandle
);
2954 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2956 return nfs4_map_errors(status
);
2959 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*mntfh
,
2960 struct nfs_fsinfo
*info
)
2963 struct nfs_fattr
*fattr
= info
->fattr
;
2964 struct nfs4_label
*label
= NULL
;
2966 error
= nfs4_server_capabilities(server
, mntfh
);
2968 dprintk("nfs4_get_root: getcaps error = %d\n", -error
);
2972 label
= nfs4_label_alloc(server
, GFP_KERNEL
);
2974 return PTR_ERR(label
);
2976 error
= nfs4_proc_getattr(server
, mntfh
, fattr
, label
);
2978 dprintk("nfs4_get_root: getattr error = %d\n", -error
);
2979 goto err_free_label
;
2982 if (fattr
->valid
& NFS_ATTR_FATTR_FSID
&&
2983 !nfs_fsid_equal(&server
->fsid
, &fattr
->fsid
))
2984 memcpy(&server
->fsid
, &fattr
->fsid
, sizeof(server
->fsid
));
2987 nfs4_label_free(label
);
2993 * Get locations and (maybe) other attributes of a referral.
2994 * Note that we'll actually follow the referral later when
2995 * we detect fsid mismatch in inode revalidation
2997 static int nfs4_get_referral(struct rpc_clnt
*client
, struct inode
*dir
,
2998 const struct qstr
*name
, struct nfs_fattr
*fattr
,
2999 struct nfs_fh
*fhandle
)
3001 int status
= -ENOMEM
;
3002 struct page
*page
= NULL
;
3003 struct nfs4_fs_locations
*locations
= NULL
;
3005 page
= alloc_page(GFP_KERNEL
);
3008 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
3009 if (locations
== NULL
)
3012 status
= nfs4_proc_fs_locations(client
, dir
, name
, locations
, page
);
3017 * If the fsid didn't change, this is a migration event, not a
3018 * referral. Cause us to drop into the exception handler, which
3019 * will kick off migration recovery.
3021 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
3022 dprintk("%s: server did not return a different fsid for"
3023 " a referral at %s\n", __func__
, name
->name
);
3024 status
= -NFS4ERR_MOVED
;
3027 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3028 nfs_fixup_referral_attributes(&locations
->fattr
);
3030 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3031 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
3032 memset(fhandle
, 0, sizeof(struct nfs_fh
));
3040 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3041 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3043 struct nfs4_getattr_arg args
= {
3045 .bitmask
= server
->attr_bitmask
,
3047 struct nfs4_getattr_res res
= {
3052 struct rpc_message msg
= {
3053 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
3058 args
.bitmask
= nfs4_bitmask(server
, label
);
3060 nfs_fattr_init(fattr
);
3061 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3064 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3065 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3067 struct nfs4_exception exception
= { };
3070 err
= _nfs4_proc_getattr(server
, fhandle
, fattr
, label
);
3071 trace_nfs4_getattr(server
, fhandle
, fattr
, err
);
3072 err
= nfs4_handle_exception(server
, err
,
3074 } while (exception
.retry
);
3079 * The file is not closed if it is opened due to the a request to change
3080 * the size of the file. The open call will not be needed once the
3081 * VFS layer lookup-intents are implemented.
3083 * Close is called when the inode is destroyed.
3084 * If we haven't opened the file for O_WRONLY, we
3085 * need to in the size_change case to obtain a stateid.
3088 * Because OPEN is always done by name in nfsv4, it is
3089 * possible that we opened a different file by the same
3090 * name. We can recognize this race condition, but we
3091 * can't do anything about it besides returning an error.
3093 * This will be fixed with VFS changes (lookup-intent).
3096 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
3097 struct iattr
*sattr
)
3099 struct inode
*inode
= dentry
->d_inode
;
3100 struct rpc_cred
*cred
= NULL
;
3101 struct nfs4_state
*state
= NULL
;
3102 struct nfs4_label
*label
= NULL
;
3105 if (pnfs_ld_layoutret_on_setattr(inode
))
3106 pnfs_commit_and_return_layout(inode
);
3108 nfs_fattr_init(fattr
);
3110 /* Deal with open(O_TRUNC) */
3111 if (sattr
->ia_valid
& ATTR_OPEN
)
3112 sattr
->ia_valid
&= ~(ATTR_MTIME
|ATTR_CTIME
);
3114 /* Optimization: if the end result is no change, don't RPC */
3115 if ((sattr
->ia_valid
& ~(ATTR_FILE
|ATTR_OPEN
)) == 0)
3118 /* Search for an existing open(O_WRITE) file */
3119 if (sattr
->ia_valid
& ATTR_FILE
) {
3120 struct nfs_open_context
*ctx
;
3122 ctx
= nfs_file_open_context(sattr
->ia_file
);
3129 label
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
3131 return PTR_ERR(label
);
3133 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
, NULL
, label
);
3135 nfs_setattr_update_inode(inode
, sattr
);
3136 nfs_setsecurity(inode
, fattr
, label
);
3138 nfs4_label_free(label
);
3142 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
3143 const struct qstr
*name
, struct nfs_fh
*fhandle
,
3144 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3146 struct nfs_server
*server
= NFS_SERVER(dir
);
3148 struct nfs4_lookup_arg args
= {
3149 .bitmask
= server
->attr_bitmask
,
3150 .dir_fh
= NFS_FH(dir
),
3153 struct nfs4_lookup_res res
= {
3159 struct rpc_message msg
= {
3160 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
3165 args
.bitmask
= nfs4_bitmask(server
, label
);
3167 nfs_fattr_init(fattr
);
3169 dprintk("NFS call lookup %s\n", name
->name
);
3170 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3171 dprintk("NFS reply lookup: %d\n", status
);
3175 static void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
)
3177 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
3178 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_MOUNTPOINT
;
3179 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
3183 static int nfs4_proc_lookup_common(struct rpc_clnt
**clnt
, struct inode
*dir
,
3184 struct qstr
*name
, struct nfs_fh
*fhandle
,
3185 struct nfs_fattr
*fattr
, struct nfs4_label
*label
)
3187 struct nfs4_exception exception
= { };
3188 struct rpc_clnt
*client
= *clnt
;
3191 err
= _nfs4_proc_lookup(client
, dir
, name
, fhandle
, fattr
, label
);
3192 trace_nfs4_lookup(dir
, name
, err
);
3194 case -NFS4ERR_BADNAME
:
3197 case -NFS4ERR_MOVED
:
3198 err
= nfs4_get_referral(client
, dir
, name
, fattr
, fhandle
);
3200 case -NFS4ERR_WRONGSEC
:
3202 if (client
!= *clnt
)
3204 client
= nfs4_create_sec_client(client
, dir
, name
);
3206 return PTR_ERR(client
);
3208 exception
.retry
= 1;
3211 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
, &exception
);
3213 } while (exception
.retry
);
3218 else if (client
!= *clnt
)
3219 rpc_shutdown_client(client
);
3224 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
3225 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
,
3226 struct nfs4_label
*label
)
3229 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3231 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, label
);
3232 if (client
!= NFS_CLIENT(dir
)) {
3233 rpc_shutdown_client(client
);
3234 nfs_fixup_secinfo_attributes(fattr
);
3240 nfs4_proc_lookup_mountpoint(struct inode
*dir
, struct qstr
*name
,
3241 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
3243 struct rpc_clnt
*client
= NFS_CLIENT(dir
);
3246 status
= nfs4_proc_lookup_common(&client
, dir
, name
, fhandle
, fattr
, NULL
);
3248 return ERR_PTR(status
);
3249 return (client
== NFS_CLIENT(dir
)) ? rpc_clone_client(client
) : client
;
3252 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3254 struct nfs_server
*server
= NFS_SERVER(inode
);
3255 struct nfs4_accessargs args
= {
3256 .fh
= NFS_FH(inode
),
3257 .bitmask
= server
->cache_consistency_bitmask
,
3259 struct nfs4_accessres res
= {
3262 struct rpc_message msg
= {
3263 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
3266 .rpc_cred
= entry
->cred
,
3268 int mode
= entry
->mask
;
3272 * Determine which access bits we want to ask for...
3274 if (mode
& MAY_READ
)
3275 args
.access
|= NFS4_ACCESS_READ
;
3276 if (S_ISDIR(inode
->i_mode
)) {
3277 if (mode
& MAY_WRITE
)
3278 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
3279 if (mode
& MAY_EXEC
)
3280 args
.access
|= NFS4_ACCESS_LOOKUP
;
3282 if (mode
& MAY_WRITE
)
3283 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
3284 if (mode
& MAY_EXEC
)
3285 args
.access
|= NFS4_ACCESS_EXECUTE
;
3288 res
.fattr
= nfs_alloc_fattr();
3289 if (res
.fattr
== NULL
)
3292 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3294 nfs_access_set_mask(entry
, res
.access
);
3295 nfs_refresh_inode(inode
, res
.fattr
);
3297 nfs_free_fattr(res
.fattr
);
3301 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
3303 struct nfs4_exception exception
= { };
3306 err
= _nfs4_proc_access(inode
, entry
);
3307 trace_nfs4_access(inode
, err
);
3308 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3310 } while (exception
.retry
);
3315 * TODO: For the time being, we don't try to get any attributes
3316 * along with any of the zero-copy operations READ, READDIR,
3319 * In the case of the first three, we want to put the GETATTR
3320 * after the read-type operation -- this is because it is hard
3321 * to predict the length of a GETATTR response in v4, and thus
3322 * align the READ data correctly. This means that the GETATTR
3323 * may end up partially falling into the page cache, and we should
3324 * shift it into the 'tail' of the xdr_buf before processing.
3325 * To do this efficiently, we need to know the total length
3326 * of data received, which doesn't seem to be available outside
3329 * In the case of WRITE, we also want to put the GETATTR after
3330 * the operation -- in this case because we want to make sure
3331 * we get the post-operation mtime and size.
3333 * Both of these changes to the XDR layer would in fact be quite
3334 * minor, but I decided to leave them for a subsequent patch.
3336 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3337 unsigned int pgbase
, unsigned int pglen
)
3339 struct nfs4_readlink args
= {
3340 .fh
= NFS_FH(inode
),
3345 struct nfs4_readlink_res res
;
3346 struct rpc_message msg
= {
3347 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
3352 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3355 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
3356 unsigned int pgbase
, unsigned int pglen
)
3358 struct nfs4_exception exception
= { };
3361 err
= _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
);
3362 trace_nfs4_readlink(inode
, err
);
3363 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
3365 } while (exception
.retry
);
3370 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3373 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
3376 struct nfs4_label l
, *ilabel
= NULL
;
3377 struct nfs_open_context
*ctx
;
3378 struct nfs4_state
*state
;
3382 ctx
= alloc_nfs_open_context(dentry
, FMODE_READ
);
3384 return PTR_ERR(ctx
);
3386 ilabel
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3388 sattr
->ia_mode
&= ~current_umask();
3389 state
= nfs4_do_open(dir
, ctx
, flags
, sattr
, ilabel
, &opened
);
3390 if (IS_ERR(state
)) {
3391 status
= PTR_ERR(state
);
3395 nfs4_label_release_security(ilabel
);
3396 put_nfs_open_context(ctx
);
3400 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3402 struct nfs_server
*server
= NFS_SERVER(dir
);
3403 struct nfs_removeargs args
= {
3407 struct nfs_removeres res
= {
3410 struct rpc_message msg
= {
3411 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
3417 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
3419 update_changeattr(dir
, &res
.cinfo
);
3423 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
3425 struct nfs4_exception exception
= { };
3428 err
= _nfs4_proc_remove(dir
, name
);
3429 trace_nfs4_remove(dir
, name
, err
);
3430 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3432 } while (exception
.retry
);
3436 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
3438 struct nfs_server
*server
= NFS_SERVER(dir
);
3439 struct nfs_removeargs
*args
= msg
->rpc_argp
;
3440 struct nfs_removeres
*res
= msg
->rpc_resp
;
3442 res
->server
= server
;
3443 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
3444 nfs4_init_sequence(&args
->seq_args
, &res
->seq_res
, 1);
3446 nfs_fattr_init(res
->dir_attr
);
3449 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task
*task
, struct nfs_unlinkdata
*data
)
3451 nfs4_setup_sequence(NFS_SERVER(data
->dir
),
3452 &data
->args
.seq_args
,
3457 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
3459 struct nfs_unlinkdata
*data
= task
->tk_calldata
;
3460 struct nfs_removeres
*res
= &data
->res
;
3462 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3464 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3466 update_changeattr(dir
, &res
->cinfo
);
3470 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
3472 struct nfs_server
*server
= NFS_SERVER(dir
);
3473 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
3474 struct nfs_renameres
*res
= msg
->rpc_resp
;
3476 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
3477 res
->server
= server
;
3478 nfs4_init_sequence(&arg
->seq_args
, &res
->seq_res
, 1);
3481 static void nfs4_proc_rename_rpc_prepare(struct rpc_task
*task
, struct nfs_renamedata
*data
)
3483 nfs4_setup_sequence(NFS_SERVER(data
->old_dir
),
3484 &data
->args
.seq_args
,
3489 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
3490 struct inode
*new_dir
)
3492 struct nfs_renamedata
*data
= task
->tk_calldata
;
3493 struct nfs_renameres
*res
= &data
->res
;
3495 if (!nfs4_sequence_done(task
, &res
->seq_res
))
3497 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
3500 update_changeattr(old_dir
, &res
->old_cinfo
);
3501 update_changeattr(new_dir
, &res
->new_cinfo
);
3505 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3506 struct inode
*new_dir
, struct qstr
*new_name
)
3508 struct nfs_server
*server
= NFS_SERVER(old_dir
);
3509 struct nfs_renameargs arg
= {
3510 .old_dir
= NFS_FH(old_dir
),
3511 .new_dir
= NFS_FH(new_dir
),
3512 .old_name
= old_name
,
3513 .new_name
= new_name
,
3515 struct nfs_renameres res
= {
3518 struct rpc_message msg
= {
3519 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
3523 int status
= -ENOMEM
;
3525 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3527 update_changeattr(old_dir
, &res
.old_cinfo
);
3528 update_changeattr(new_dir
, &res
.new_cinfo
);
3533 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
3534 struct inode
*new_dir
, struct qstr
*new_name
)
3536 struct nfs4_exception exception
= { };
3539 err
= _nfs4_proc_rename(old_dir
, old_name
,
3541 trace_nfs4_rename(old_dir
, old_name
, new_dir
, new_name
, err
);
3542 err
= nfs4_handle_exception(NFS_SERVER(old_dir
), err
,
3544 } while (exception
.retry
);
3548 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3550 struct nfs_server
*server
= NFS_SERVER(inode
);
3551 struct nfs4_link_arg arg
= {
3552 .fh
= NFS_FH(inode
),
3553 .dir_fh
= NFS_FH(dir
),
3555 .bitmask
= server
->attr_bitmask
,
3557 struct nfs4_link_res res
= {
3561 struct rpc_message msg
= {
3562 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
3566 int status
= -ENOMEM
;
3568 res
.fattr
= nfs_alloc_fattr();
3569 if (res
.fattr
== NULL
)
3572 res
.label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3573 if (IS_ERR(res
.label
)) {
3574 status
= PTR_ERR(res
.label
);
3577 arg
.bitmask
= nfs4_bitmask(server
, res
.label
);
3579 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3581 update_changeattr(dir
, &res
.cinfo
);
3582 status
= nfs_post_op_update_inode(inode
, res
.fattr
);
3584 nfs_setsecurity(inode
, res
.fattr
, res
.label
);
3588 nfs4_label_free(res
.label
);
3591 nfs_free_fattr(res
.fattr
);
3595 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
3597 struct nfs4_exception exception
= { };
3600 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3601 _nfs4_proc_link(inode
, dir
, name
),
3603 } while (exception
.retry
);
3607 struct nfs4_createdata
{
3608 struct rpc_message msg
;
3609 struct nfs4_create_arg arg
;
3610 struct nfs4_create_res res
;
3612 struct nfs_fattr fattr
;
3613 struct nfs4_label
*label
;
3616 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
3617 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
3619 struct nfs4_createdata
*data
;
3621 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3623 struct nfs_server
*server
= NFS_SERVER(dir
);
3625 data
->label
= nfs4_label_alloc(server
, GFP_KERNEL
);
3626 if (IS_ERR(data
->label
))
3629 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
3630 data
->msg
.rpc_argp
= &data
->arg
;
3631 data
->msg
.rpc_resp
= &data
->res
;
3632 data
->arg
.dir_fh
= NFS_FH(dir
);
3633 data
->arg
.server
= server
;
3634 data
->arg
.name
= name
;
3635 data
->arg
.attrs
= sattr
;
3636 data
->arg
.ftype
= ftype
;
3637 data
->arg
.bitmask
= nfs4_bitmask(server
, data
->label
);
3638 data
->res
.server
= server
;
3639 data
->res
.fh
= &data
->fh
;
3640 data
->res
.fattr
= &data
->fattr
;
3641 data
->res
.label
= data
->label
;
3642 nfs_fattr_init(data
->res
.fattr
);
3650 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
3652 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
3653 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
3655 update_changeattr(dir
, &data
->res
.dir_cinfo
);
3656 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
, data
->res
.label
);
3661 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
3663 nfs4_label_free(data
->label
);
3667 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3668 struct page
*page
, unsigned int len
, struct iattr
*sattr
,
3669 struct nfs4_label
*label
)
3671 struct nfs4_createdata
*data
;
3672 int status
= -ENAMETOOLONG
;
3674 if (len
> NFS4_MAXPATHLEN
)
3678 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
3682 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
3683 data
->arg
.u
.symlink
.pages
= &page
;
3684 data
->arg
.u
.symlink
.len
= len
;
3685 data
->arg
.label
= label
;
3687 status
= nfs4_do_create(dir
, dentry
, data
);
3689 nfs4_free_createdata(data
);
3694 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
3695 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
3697 struct nfs4_exception exception
= { };
3698 struct nfs4_label l
, *label
= NULL
;
3701 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3704 err
= _nfs4_proc_symlink(dir
, dentry
, page
, len
, sattr
, label
);
3705 trace_nfs4_symlink(dir
, &dentry
->d_name
, err
);
3706 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3708 } while (exception
.retry
);
3710 nfs4_label_release_security(label
);
3714 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3715 struct iattr
*sattr
, struct nfs4_label
*label
)
3717 struct nfs4_createdata
*data
;
3718 int status
= -ENOMEM
;
3720 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
3724 data
->arg
.label
= label
;
3725 status
= nfs4_do_create(dir
, dentry
, data
);
3727 nfs4_free_createdata(data
);
3732 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
3733 struct iattr
*sattr
)
3735 struct nfs4_exception exception
= { };
3736 struct nfs4_label l
, *label
= NULL
;
3739 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3741 sattr
->ia_mode
&= ~current_umask();
3743 err
= _nfs4_proc_mkdir(dir
, dentry
, sattr
, label
);
3744 trace_nfs4_mkdir(dir
, &dentry
->d_name
, err
);
3745 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3747 } while (exception
.retry
);
3748 nfs4_label_release_security(label
);
3753 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3754 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3756 struct inode
*dir
= dentry
->d_inode
;
3757 struct nfs4_readdir_arg args
= {
3762 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3765 struct nfs4_readdir_res res
;
3766 struct rpc_message msg
= {
3767 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3774 dprintk("%s: dentry = %pd2, cookie = %Lu\n", __func__
,
3776 (unsigned long long)cookie
);
3777 nfs4_setup_readdir(cookie
, NFS_I(dir
)->cookieverf
, dentry
, &args
);
3778 res
.pgbase
= args
.pgbase
;
3779 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3781 memcpy(NFS_I(dir
)->cookieverf
, res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3782 status
+= args
.pgbase
;
3785 nfs_invalidate_atime(dir
);
3787 dprintk("%s: returns %d\n", __func__
, status
);
3791 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3792 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3794 struct nfs4_exception exception
= { };
3797 err
= _nfs4_proc_readdir(dentry
, cred
, cookie
,
3798 pages
, count
, plus
);
3799 trace_nfs4_readdir(dentry
->d_inode
, err
);
3800 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
), err
,
3802 } while (exception
.retry
);
3806 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3807 struct iattr
*sattr
, struct nfs4_label
*label
, dev_t rdev
)
3809 struct nfs4_createdata
*data
;
3810 int mode
= sattr
->ia_mode
;
3811 int status
= -ENOMEM
;
3813 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3818 data
->arg
.ftype
= NF4FIFO
;
3819 else if (S_ISBLK(mode
)) {
3820 data
->arg
.ftype
= NF4BLK
;
3821 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3822 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3824 else if (S_ISCHR(mode
)) {
3825 data
->arg
.ftype
= NF4CHR
;
3826 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3827 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3828 } else if (!S_ISSOCK(mode
)) {
3833 data
->arg
.label
= label
;
3834 status
= nfs4_do_create(dir
, dentry
, data
);
3836 nfs4_free_createdata(data
);
3841 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3842 struct iattr
*sattr
, dev_t rdev
)
3844 struct nfs4_exception exception
= { };
3845 struct nfs4_label l
, *label
= NULL
;
3848 label
= nfs4_label_init_security(dir
, dentry
, sattr
, &l
);
3850 sattr
->ia_mode
&= ~current_umask();
3852 err
= _nfs4_proc_mknod(dir
, dentry
, sattr
, label
, rdev
);
3853 trace_nfs4_mknod(dir
, &dentry
->d_name
, err
);
3854 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
3856 } while (exception
.retry
);
3858 nfs4_label_release_security(label
);
3863 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3864 struct nfs_fsstat
*fsstat
)
3866 struct nfs4_statfs_arg args
= {
3868 .bitmask
= server
->attr_bitmask
,
3870 struct nfs4_statfs_res res
= {
3873 struct rpc_message msg
= {
3874 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3879 nfs_fattr_init(fsstat
->fattr
);
3880 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3883 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3885 struct nfs4_exception exception
= { };
3888 err
= nfs4_handle_exception(server
,
3889 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3891 } while (exception
.retry
);
3895 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3896 struct nfs_fsinfo
*fsinfo
)
3898 struct nfs4_fsinfo_arg args
= {
3900 .bitmask
= server
->attr_bitmask
,
3902 struct nfs4_fsinfo_res res
= {
3905 struct rpc_message msg
= {
3906 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3911 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3914 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3916 struct nfs4_exception exception
= { };
3917 unsigned long now
= jiffies
;
3921 err
= _nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3922 trace_nfs4_fsinfo(server
, fhandle
, fsinfo
->fattr
, err
);
3924 struct nfs_client
*clp
= server
->nfs_client
;
3926 spin_lock(&clp
->cl_lock
);
3927 clp
->cl_lease_time
= fsinfo
->lease_time
* HZ
;
3928 clp
->cl_last_renewal
= now
;
3929 spin_unlock(&clp
->cl_lock
);
3932 err
= nfs4_handle_exception(server
, err
, &exception
);
3933 } while (exception
.retry
);
3937 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3941 nfs_fattr_init(fsinfo
->fattr
);
3942 error
= nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3944 /* block layout checks this! */
3945 server
->pnfs_blksize
= fsinfo
->blksize
;
3946 set_pnfs_layoutdriver(server
, fhandle
, fsinfo
->layouttype
);
3952 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3953 struct nfs_pathconf
*pathconf
)
3955 struct nfs4_pathconf_arg args
= {
3957 .bitmask
= server
->attr_bitmask
,
3959 struct nfs4_pathconf_res res
= {
3960 .pathconf
= pathconf
,
3962 struct rpc_message msg
= {
3963 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3968 /* None of the pathconf attributes are mandatory to implement */
3969 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3970 memset(pathconf
, 0, sizeof(*pathconf
));
3974 nfs_fattr_init(pathconf
->fattr
);
3975 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3978 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3979 struct nfs_pathconf
*pathconf
)
3981 struct nfs4_exception exception
= { };
3985 err
= nfs4_handle_exception(server
,
3986 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3988 } while (exception
.retry
);
3992 int nfs4_set_rw_stateid(nfs4_stateid
*stateid
,
3993 const struct nfs_open_context
*ctx
,
3994 const struct nfs_lock_context
*l_ctx
,
3997 const struct nfs_lockowner
*lockowner
= NULL
;
4000 lockowner
= &l_ctx
->lockowner
;
4001 return nfs4_select_rw_stateid(stateid
, ctx
->state
, fmode
, lockowner
);
4003 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid
);
4005 static bool nfs4_stateid_is_current(nfs4_stateid
*stateid
,
4006 const struct nfs_open_context
*ctx
,
4007 const struct nfs_lock_context
*l_ctx
,
4010 nfs4_stateid current_stateid
;
4012 if (nfs4_set_rw_stateid(¤t_stateid
, ctx
, l_ctx
, fmode
))
4014 return nfs4_stateid_match(stateid
, ¤t_stateid
);
4017 static bool nfs4_error_stateid_expired(int err
)
4020 case -NFS4ERR_DELEG_REVOKED
:
4021 case -NFS4ERR_ADMIN_REVOKED
:
4022 case -NFS4ERR_BAD_STATEID
:
4023 case -NFS4ERR_STALE_STATEID
:
4024 case -NFS4ERR_OLD_STATEID
:
4025 case -NFS4ERR_OPENMODE
:
4026 case -NFS4ERR_EXPIRED
:
4032 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
4034 nfs_invalidate_atime(data
->header
->inode
);
4037 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
4039 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
4041 trace_nfs4_read(data
, task
->tk_status
);
4042 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
4043 rpc_restart_call_prepare(task
);
4047 __nfs4_read_done_cb(data
);
4048 if (task
->tk_status
> 0)
4049 renew_lease(server
, data
->timestamp
);
4053 static bool nfs4_read_stateid_changed(struct rpc_task
*task
,
4054 struct nfs_readargs
*args
)
4057 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4058 nfs4_stateid_is_current(&args
->stateid
,
4063 rpc_restart_call_prepare(task
);
4067 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
4070 dprintk("--> %s\n", __func__
);
4072 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4074 if (nfs4_read_stateid_changed(task
, &data
->args
))
4076 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
4077 nfs4_read_done_cb(task
, data
);
4080 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
4082 data
->timestamp
= jiffies
;
4083 data
->read_done_cb
= nfs4_read_done_cb
;
4084 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
4085 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
4088 static int nfs4_proc_read_rpc_prepare(struct rpc_task
*task
, struct nfs_read_data
*data
)
4090 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
4091 &data
->args
.seq_args
,
4095 if (nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
4096 data
->args
.lock_context
, FMODE_READ
) == -EIO
)
4098 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &data
->args
.context
->flags
)))
4103 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
4105 struct inode
*inode
= data
->header
->inode
;
4107 trace_nfs4_write(data
, task
->tk_status
);
4108 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
4109 rpc_restart_call_prepare(task
);
4112 if (task
->tk_status
>= 0) {
4113 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
4114 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
4119 static bool nfs4_write_stateid_changed(struct rpc_task
*task
,
4120 struct nfs_writeargs
*args
)
4123 if (!nfs4_error_stateid_expired(task
->tk_status
) ||
4124 nfs4_stateid_is_current(&args
->stateid
,
4129 rpc_restart_call_prepare(task
);
4133 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
4135 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4137 if (nfs4_write_stateid_changed(task
, &data
->args
))
4139 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
4140 nfs4_write_done_cb(task
, data
);
4144 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data
*data
)
4146 const struct nfs_pgio_header
*hdr
= data
->header
;
4148 /* Don't request attributes for pNFS or O_DIRECT writes */
4149 if (data
->ds_clp
!= NULL
|| hdr
->dreq
!= NULL
)
4151 /* Otherwise, request attributes if and only if we don't hold
4154 return nfs4_have_delegation(hdr
->inode
, FMODE_READ
) == 0;
4157 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
4159 struct nfs_server
*server
= NFS_SERVER(data
->header
->inode
);
4161 if (!nfs4_write_need_cache_consistency_data(data
)) {
4162 data
->args
.bitmask
= NULL
;
4163 data
->res
.fattr
= NULL
;
4165 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
4167 if (!data
->write_done_cb
)
4168 data
->write_done_cb
= nfs4_write_done_cb
;
4169 data
->res
.server
= server
;
4170 data
->timestamp
= jiffies
;
4172 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
4173 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4176 static int nfs4_proc_write_rpc_prepare(struct rpc_task
*task
, struct nfs_write_data
*data
)
4178 if (nfs4_setup_sequence(NFS_SERVER(data
->header
->inode
),
4179 &data
->args
.seq_args
,
4183 if (nfs4_set_rw_stateid(&data
->args
.stateid
, data
->args
.context
,
4184 data
->args
.lock_context
, FMODE_WRITE
) == -EIO
)
4186 if (unlikely(test_bit(NFS_CONTEXT_BAD
, &data
->args
.context
->flags
)))
4191 static void nfs4_proc_commit_rpc_prepare(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4193 nfs4_setup_sequence(NFS_SERVER(data
->inode
),
4194 &data
->args
.seq_args
,
4199 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4201 struct inode
*inode
= data
->inode
;
4203 trace_nfs4_commit(data
, task
->tk_status
);
4204 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
4205 rpc_restart_call_prepare(task
);
4211 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_commit_data
*data
)
4213 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4215 return data
->commit_done_cb(task
, data
);
4218 static void nfs4_proc_commit_setup(struct nfs_commit_data
*data
, struct rpc_message
*msg
)
4220 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
4222 if (data
->commit_done_cb
== NULL
)
4223 data
->commit_done_cb
= nfs4_commit_done_cb
;
4224 data
->res
.server
= server
;
4225 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
4226 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
4229 struct nfs4_renewdata
{
4230 struct nfs_client
*client
;
4231 unsigned long timestamp
;
4235 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4236 * standalone procedure for queueing an asynchronous RENEW.
4238 static void nfs4_renew_release(void *calldata
)
4240 struct nfs4_renewdata
*data
= calldata
;
4241 struct nfs_client
*clp
= data
->client
;
4243 if (atomic_read(&clp
->cl_count
) > 1)
4244 nfs4_schedule_state_renewal(clp
);
4245 nfs_put_client(clp
);
4249 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
4251 struct nfs4_renewdata
*data
= calldata
;
4252 struct nfs_client
*clp
= data
->client
;
4253 unsigned long timestamp
= data
->timestamp
;
4255 trace_nfs4_renew_async(clp
, task
->tk_status
);
4256 switch (task
->tk_status
) {
4259 case -NFS4ERR_LEASE_MOVED
:
4260 nfs4_schedule_lease_moved_recovery(clp
);
4263 /* Unless we're shutting down, schedule state recovery! */
4264 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
4266 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
4267 nfs4_schedule_lease_recovery(clp
);
4270 nfs4_schedule_path_down_recovery(clp
);
4272 do_renew_lease(clp
, timestamp
);
4275 static const struct rpc_call_ops nfs4_renew_ops
= {
4276 .rpc_call_done
= nfs4_renew_done
,
4277 .rpc_release
= nfs4_renew_release
,
4280 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
4282 struct rpc_message msg
= {
4283 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4287 struct nfs4_renewdata
*data
;
4289 if (renew_flags
== 0)
4291 if (!atomic_inc_not_zero(&clp
->cl_count
))
4293 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
4297 data
->timestamp
= jiffies
;
4298 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
,
4299 &nfs4_renew_ops
, data
);
4302 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4304 struct rpc_message msg
= {
4305 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
4309 unsigned long now
= jiffies
;
4312 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4315 do_renew_lease(clp
, now
);
4319 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
4321 return (server
->caps
& NFS_CAP_ACLS
)
4322 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
4323 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
4326 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4327 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4330 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4332 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
4333 struct page
**pages
, unsigned int *pgbase
)
4335 struct page
*newpage
, **spages
;
4341 len
= min_t(size_t, PAGE_SIZE
, buflen
);
4342 newpage
= alloc_page(GFP_KERNEL
);
4344 if (newpage
== NULL
)
4346 memcpy(page_address(newpage
), buf
, len
);
4351 } while (buflen
!= 0);
4357 __free_page(spages
[rc
-1]);
4361 struct nfs4_cached_acl
{
4367 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
4369 struct nfs_inode
*nfsi
= NFS_I(inode
);
4371 spin_lock(&inode
->i_lock
);
4372 kfree(nfsi
->nfs4_acl
);
4373 nfsi
->nfs4_acl
= acl
;
4374 spin_unlock(&inode
->i_lock
);
4377 static void nfs4_zap_acl_attr(struct inode
*inode
)
4379 nfs4_set_cached_acl(inode
, NULL
);
4382 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
4384 struct nfs_inode
*nfsi
= NFS_I(inode
);
4385 struct nfs4_cached_acl
*acl
;
4388 spin_lock(&inode
->i_lock
);
4389 acl
= nfsi
->nfs4_acl
;
4392 if (buf
== NULL
) /* user is just asking for length */
4394 if (acl
->cached
== 0)
4396 ret
= -ERANGE
; /* see getxattr(2) man page */
4397 if (acl
->len
> buflen
)
4399 memcpy(buf
, acl
->data
, acl
->len
);
4403 spin_unlock(&inode
->i_lock
);
4407 static void nfs4_write_cached_acl(struct inode
*inode
, struct page
**pages
, size_t pgbase
, size_t acl_len
)
4409 struct nfs4_cached_acl
*acl
;
4410 size_t buflen
= sizeof(*acl
) + acl_len
;
4412 if (buflen
<= PAGE_SIZE
) {
4413 acl
= kmalloc(buflen
, GFP_KERNEL
);
4417 _copy_from_pages(acl
->data
, pages
, pgbase
, acl_len
);
4419 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
4426 nfs4_set_cached_acl(inode
, acl
);
4430 * The getxattr API returns the required buffer length when called with a
4431 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4432 * the required buf. On a NULL buf, we send a page of data to the server
4433 * guessing that the ACL request can be serviced by a page. If so, we cache
4434 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4435 * the cache. If not so, we throw away the page, and cache the required
4436 * length. The next getxattr call will then produce another round trip to
4437 * the server, this time with the input buf of the required size.
4439 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4441 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
4442 struct nfs_getaclargs args
= {
4443 .fh
= NFS_FH(inode
),
4447 struct nfs_getaclres res
= {
4450 struct rpc_message msg
= {
4451 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
4455 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4456 int ret
= -ENOMEM
, i
;
4458 /* As long as we're doing a round trip to the server anyway,
4459 * let's be prepared for a page of acl data. */
4462 if (npages
> ARRAY_SIZE(pages
))
4465 for (i
= 0; i
< npages
; i
++) {
4466 pages
[i
] = alloc_page(GFP_KERNEL
);
4471 /* for decoding across pages */
4472 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
4473 if (!res
.acl_scratch
)
4476 args
.acl_len
= npages
* PAGE_SIZE
;
4477 args
.acl_pgbase
= 0;
4479 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4480 __func__
, buf
, buflen
, npages
, args
.acl_len
);
4481 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
4482 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4486 /* Handle the case where the passed-in buffer is too short */
4487 if (res
.acl_flags
& NFS4_ACL_TRUNC
) {
4488 /* Did the user only issue a request for the acl length? */
4494 nfs4_write_cached_acl(inode
, pages
, res
.acl_data_offset
, res
.acl_len
);
4496 if (res
.acl_len
> buflen
) {
4500 _copy_from_pages(buf
, pages
, res
.acl_data_offset
, res
.acl_len
);
4505 for (i
= 0; i
< npages
; i
++)
4507 __free_page(pages
[i
]);
4508 if (res
.acl_scratch
)
4509 __free_page(res
.acl_scratch
);
4513 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
4515 struct nfs4_exception exception
= { };
4518 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
4519 trace_nfs4_get_acl(inode
, ret
);
4522 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
4523 } while (exception
.retry
);
4527 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
4529 struct nfs_server
*server
= NFS_SERVER(inode
);
4532 if (!nfs4_server_supports_acls(server
))
4534 ret
= nfs_revalidate_inode(server
, inode
);
4537 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
4538 nfs_zap_acl_cache(inode
);
4539 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
4541 /* -ENOENT is returned if there is no ACL or if there is an ACL
4542 * but no cached acl data, just the acl length */
4544 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
4547 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4549 struct nfs_server
*server
= NFS_SERVER(inode
);
4550 struct page
*pages
[NFS4ACL_MAXPAGES
];
4551 struct nfs_setaclargs arg
= {
4552 .fh
= NFS_FH(inode
),
4556 struct nfs_setaclres res
;
4557 struct rpc_message msg
= {
4558 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
4562 unsigned int npages
= DIV_ROUND_UP(buflen
, PAGE_SIZE
);
4565 if (!nfs4_server_supports_acls(server
))
4567 if (npages
> ARRAY_SIZE(pages
))
4569 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
4572 nfs4_inode_return_delegation(inode
);
4573 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4576 * Free each page after tx, so the only ref left is
4577 * held by the network stack
4580 put_page(pages
[i
-1]);
4583 * Acl update can result in inode attribute update.
4584 * so mark the attribute cache invalid.
4586 spin_lock(&inode
->i_lock
);
4587 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
4588 spin_unlock(&inode
->i_lock
);
4589 nfs_access_zap_cache(inode
);
4590 nfs_zap_acl_cache(inode
);
4594 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
4596 struct nfs4_exception exception
= { };
4599 err
= __nfs4_proc_set_acl(inode
, buf
, buflen
);
4600 trace_nfs4_set_acl(inode
, err
);
4601 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4603 } while (exception
.retry
);
4607 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4608 static int _nfs4_get_security_label(struct inode
*inode
, void *buf
,
4611 struct nfs_server
*server
= NFS_SERVER(inode
);
4612 struct nfs_fattr fattr
;
4613 struct nfs4_label label
= {0, 0, buflen
, buf
};
4615 u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4616 struct nfs4_getattr_arg arg
= {
4617 .fh
= NFS_FH(inode
),
4620 struct nfs4_getattr_res res
= {
4625 struct rpc_message msg
= {
4626 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
4632 nfs_fattr_init(&fattr
);
4634 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 0);
4637 if (!(fattr
.valid
& NFS_ATTR_FATTR_V4_SECURITY_LABEL
))
4639 if (buflen
< label
.len
)
4644 static int nfs4_get_security_label(struct inode
*inode
, void *buf
,
4647 struct nfs4_exception exception
= { };
4650 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4654 err
= _nfs4_get_security_label(inode
, buf
, buflen
);
4655 trace_nfs4_get_security_label(inode
, err
);
4656 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4658 } while (exception
.retry
);
4662 static int _nfs4_do_set_security_label(struct inode
*inode
,
4663 struct nfs4_label
*ilabel
,
4664 struct nfs_fattr
*fattr
,
4665 struct nfs4_label
*olabel
)
4668 struct iattr sattr
= {0};
4669 struct nfs_server
*server
= NFS_SERVER(inode
);
4670 const u32 bitmask
[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL
};
4671 struct nfs_setattrargs arg
= {
4672 .fh
= NFS_FH(inode
),
4678 struct nfs_setattrres res
= {
4683 struct rpc_message msg
= {
4684 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
4690 nfs4_stateid_copy(&arg
.stateid
, &zero_stateid
);
4692 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4694 dprintk("%s failed: %d\n", __func__
, status
);
4699 static int nfs4_do_set_security_label(struct inode
*inode
,
4700 struct nfs4_label
*ilabel
,
4701 struct nfs_fattr
*fattr
,
4702 struct nfs4_label
*olabel
)
4704 struct nfs4_exception exception
= { };
4708 err
= _nfs4_do_set_security_label(inode
, ilabel
,
4710 trace_nfs4_set_security_label(inode
, err
);
4711 err
= nfs4_handle_exception(NFS_SERVER(inode
), err
,
4713 } while (exception
.retry
);
4718 nfs4_set_security_label(struct dentry
*dentry
, const void *buf
, size_t buflen
)
4720 struct nfs4_label ilabel
, *olabel
= NULL
;
4721 struct nfs_fattr fattr
;
4722 struct rpc_cred
*cred
;
4723 struct inode
*inode
= dentry
->d_inode
;
4726 if (!nfs_server_capable(inode
, NFS_CAP_SECURITY_LABEL
))
4729 nfs_fattr_init(&fattr
);
4733 ilabel
.label
= (char *)buf
;
4734 ilabel
.len
= buflen
;
4736 cred
= rpc_lookup_cred();
4738 return PTR_ERR(cred
);
4740 olabel
= nfs4_label_alloc(NFS_SERVER(inode
), GFP_KERNEL
);
4741 if (IS_ERR(olabel
)) {
4742 status
= -PTR_ERR(olabel
);
4746 status
= nfs4_do_set_security_label(inode
, &ilabel
, &fattr
, olabel
);
4748 nfs_setsecurity(inode
, &fattr
, olabel
);
4750 nfs4_label_free(olabel
);
4755 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4759 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
4761 struct nfs_client
*clp
= server
->nfs_client
;
4763 if (task
->tk_status
>= 0)
4765 switch(task
->tk_status
) {
4766 case -NFS4ERR_DELEG_REVOKED
:
4767 case -NFS4ERR_ADMIN_REVOKED
:
4768 case -NFS4ERR_BAD_STATEID
:
4771 nfs_remove_bad_delegation(state
->inode
);
4772 case -NFS4ERR_OPENMODE
:
4775 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4776 goto recovery_failed
;
4777 goto wait_on_recovery
;
4778 case -NFS4ERR_EXPIRED
:
4779 if (state
!= NULL
) {
4780 if (nfs4_schedule_stateid_recovery(server
, state
) < 0)
4781 goto recovery_failed
;
4783 case -NFS4ERR_STALE_STATEID
:
4784 case -NFS4ERR_STALE_CLIENTID
:
4785 nfs4_schedule_lease_recovery(clp
);
4786 goto wait_on_recovery
;
4787 case -NFS4ERR_MOVED
:
4788 if (nfs4_schedule_migration_recovery(server
) < 0)
4789 goto recovery_failed
;
4790 goto wait_on_recovery
;
4791 case -NFS4ERR_LEASE_MOVED
:
4792 nfs4_schedule_lease_moved_recovery(clp
);
4793 goto wait_on_recovery
;
4794 #if defined(CONFIG_NFS_V4_1)
4795 case -NFS4ERR_BADSESSION
:
4796 case -NFS4ERR_BADSLOT
:
4797 case -NFS4ERR_BAD_HIGH_SLOT
:
4798 case -NFS4ERR_DEADSESSION
:
4799 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4800 case -NFS4ERR_SEQ_FALSE_RETRY
:
4801 case -NFS4ERR_SEQ_MISORDERED
:
4802 dprintk("%s ERROR %d, Reset session\n", __func__
,
4804 nfs4_schedule_session_recovery(clp
->cl_session
, task
->tk_status
);
4806 #endif /* CONFIG_NFS_V4_1 */
4807 case -NFS4ERR_DELAY
:
4808 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
4809 case -NFS4ERR_GRACE
:
4810 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
4811 case -NFS4ERR_RETRY_UNCACHED_REP
:
4812 case -NFS4ERR_OLD_STATEID
:
4815 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
4818 task
->tk_status
= -EIO
;
4821 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
4822 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
4823 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
4824 if (test_bit(NFS_MIG_FAILED
, &server
->mig_status
))
4825 goto recovery_failed
;
4827 task
->tk_status
= 0;
4831 static void nfs4_init_boot_verifier(const struct nfs_client
*clp
,
4832 nfs4_verifier
*bootverf
)
4836 if (test_bit(NFS4CLNT_PURGE_STATE
, &clp
->cl_state
)) {
4837 /* An impossible timestamp guarantees this value
4838 * will never match a generated boot time. */
4840 verf
[1] = cpu_to_be32(NSEC_PER_SEC
+ 1);
4842 struct nfs_net
*nn
= net_generic(clp
->cl_net
, nfs_net_id
);
4843 verf
[0] = cpu_to_be32(nn
->boot_time
.tv_sec
);
4844 verf
[1] = cpu_to_be32(nn
->boot_time
.tv_nsec
);
4846 memcpy(bootverf
->data
, verf
, sizeof(bootverf
->data
));
4850 nfs4_init_nonuniform_client_string(const struct nfs_client
*clp
,
4851 char *buf
, size_t len
)
4853 unsigned int result
;
4856 result
= scnprintf(buf
, len
, "Linux NFSv4.0 %s/%s %s",
4858 rpc_peeraddr2str(clp
->cl_rpcclient
,
4860 rpc_peeraddr2str(clp
->cl_rpcclient
,
4861 RPC_DISPLAY_PROTO
));
4867 nfs4_init_uniform_client_string(const struct nfs_client
*clp
,
4868 char *buf
, size_t len
)
4870 const char *nodename
= clp
->cl_rpcclient
->cl_nodename
;
4872 if (nfs4_client_id_uniquifier
[0] != '\0')
4873 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s/%s",
4874 clp
->rpc_ops
->version
,
4875 clp
->cl_minorversion
,
4876 nfs4_client_id_uniquifier
,
4878 return scnprintf(buf
, len
, "Linux NFSv%u.%u %s",
4879 clp
->rpc_ops
->version
, clp
->cl_minorversion
,
4884 * nfs4_proc_setclientid - Negotiate client ID
4885 * @clp: state data structure
4886 * @program: RPC program for NFSv4 callback service
4887 * @port: IP port number for NFS4 callback service
4888 * @cred: RPC credential to use for this call
4889 * @res: where to place the result
4891 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4893 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
4894 unsigned short port
, struct rpc_cred
*cred
,
4895 struct nfs4_setclientid_res
*res
)
4897 nfs4_verifier sc_verifier
;
4898 struct nfs4_setclientid setclientid
= {
4899 .sc_verifier
= &sc_verifier
,
4901 .sc_cb_ident
= clp
->cl_cb_ident
,
4903 struct rpc_message msg
= {
4904 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
4905 .rpc_argp
= &setclientid
,
4911 /* nfs_client_id4 */
4912 nfs4_init_boot_verifier(clp
, &sc_verifier
);
4913 if (test_bit(NFS_CS_MIGRATION
, &clp
->cl_flags
))
4914 setclientid
.sc_name_len
=
4915 nfs4_init_uniform_client_string(clp
,
4916 setclientid
.sc_name
,
4917 sizeof(setclientid
.sc_name
));
4919 setclientid
.sc_name_len
=
4920 nfs4_init_nonuniform_client_string(clp
,
4921 setclientid
.sc_name
,
4922 sizeof(setclientid
.sc_name
));
4925 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
4926 sizeof(setclientid
.sc_netid
), "%s",
4927 rpc_peeraddr2str(clp
->cl_rpcclient
,
4928 RPC_DISPLAY_NETID
));
4930 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
4931 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
4932 clp
->cl_ipaddr
, port
>> 8, port
& 255);
4934 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4935 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4936 setclientid
.sc_name_len
, setclientid
.sc_name
);
4937 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4938 trace_nfs4_setclientid(clp
, status
);
4939 dprintk("NFS reply setclientid: %d\n", status
);
4944 * nfs4_proc_setclientid_confirm - Confirm client ID
4945 * @clp: state data structure
4946 * @res: result of a previous SETCLIENTID
4947 * @cred: RPC credential to use for this call
4949 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4951 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
4952 struct nfs4_setclientid_res
*arg
,
4953 struct rpc_cred
*cred
)
4955 struct rpc_message msg
= {
4956 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
4962 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4963 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
4965 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4966 trace_nfs4_setclientid_confirm(clp
, status
);
4967 dprintk("NFS reply setclientid_confirm: %d\n", status
);
4971 struct nfs4_delegreturndata
{
4972 struct nfs4_delegreturnargs args
;
4973 struct nfs4_delegreturnres res
;
4975 nfs4_stateid stateid
;
4976 unsigned long timestamp
;
4977 struct nfs_fattr fattr
;
4981 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
4983 struct nfs4_delegreturndata
*data
= calldata
;
4985 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4988 trace_nfs4_delegreturn_exit(&data
->args
, &data
->res
, task
->tk_status
);
4989 switch (task
->tk_status
) {
4990 case -NFS4ERR_STALE_STATEID
:
4991 case -NFS4ERR_EXPIRED
:
4993 renew_lease(data
->res
.server
, data
->timestamp
);
4996 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
4998 rpc_restart_call_prepare(task
);
5002 data
->rpc_status
= task
->tk_status
;
5005 static void nfs4_delegreturn_release(void *calldata
)
5010 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
5012 struct nfs4_delegreturndata
*d_data
;
5014 d_data
= (struct nfs4_delegreturndata
*)data
;
5016 nfs4_setup_sequence(d_data
->res
.server
,
5017 &d_data
->args
.seq_args
,
5018 &d_data
->res
.seq_res
,
5022 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
5023 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
5024 .rpc_call_done
= nfs4_delegreturn_done
,
5025 .rpc_release
= nfs4_delegreturn_release
,
5028 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5030 struct nfs4_delegreturndata
*data
;
5031 struct nfs_server
*server
= NFS_SERVER(inode
);
5032 struct rpc_task
*task
;
5033 struct rpc_message msg
= {
5034 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
5037 struct rpc_task_setup task_setup_data
= {
5038 .rpc_client
= server
->client
,
5039 .rpc_message
= &msg
,
5040 .callback_ops
= &nfs4_delegreturn_ops
,
5041 .flags
= RPC_TASK_ASYNC
,
5045 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
5048 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
5049 data
->args
.fhandle
= &data
->fh
;
5050 data
->args
.stateid
= &data
->stateid
;
5051 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
5052 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
5053 nfs4_stateid_copy(&data
->stateid
, stateid
);
5054 data
->res
.fattr
= &data
->fattr
;
5055 data
->res
.server
= server
;
5056 nfs_fattr_init(data
->res
.fattr
);
5057 data
->timestamp
= jiffies
;
5058 data
->rpc_status
= 0;
5060 task_setup_data
.callback_data
= data
;
5061 msg
.rpc_argp
= &data
->args
;
5062 msg
.rpc_resp
= &data
->res
;
5063 task
= rpc_run_task(&task_setup_data
);
5065 return PTR_ERR(task
);
5068 status
= nfs4_wait_for_completion_rpc_task(task
);
5071 status
= data
->rpc_status
;
5073 nfs_post_op_update_inode_force_wcc(inode
, &data
->fattr
);
5075 nfs_refresh_inode(inode
, &data
->fattr
);
5081 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
5083 struct nfs_server
*server
= NFS_SERVER(inode
);
5084 struct nfs4_exception exception
= { };
5087 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
5088 trace_nfs4_delegreturn(inode
, err
);
5090 case -NFS4ERR_STALE_STATEID
:
5091 case -NFS4ERR_EXPIRED
:
5095 err
= nfs4_handle_exception(server
, err
, &exception
);
5096 } while (exception
.retry
);
5100 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
5101 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
5104 * sleep, with exponential backoff, and retry the LOCK operation.
5106 static unsigned long
5107 nfs4_set_lock_task_retry(unsigned long timeout
)
5109 freezable_schedule_timeout_killable_unsafe(timeout
);
5111 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
5112 return NFS4_LOCK_MAXTIMEOUT
;
5116 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5118 struct inode
*inode
= state
->inode
;
5119 struct nfs_server
*server
= NFS_SERVER(inode
);
5120 struct nfs_client
*clp
= server
->nfs_client
;
5121 struct nfs_lockt_args arg
= {
5122 .fh
= NFS_FH(inode
),
5125 struct nfs_lockt_res res
= {
5128 struct rpc_message msg
= {
5129 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
5132 .rpc_cred
= state
->owner
->so_cred
,
5134 struct nfs4_lock_state
*lsp
;
5137 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
5138 status
= nfs4_set_lock_state(state
, request
);
5141 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5142 arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5143 arg
.lock_owner
.s_dev
= server
->s_dev
;
5144 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
5147 request
->fl_type
= F_UNLCK
;
5149 case -NFS4ERR_DENIED
:
5152 request
->fl_ops
->fl_release_private(request
);
5153 request
->fl_ops
= NULL
;
5158 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5160 struct nfs4_exception exception
= { };
5164 err
= _nfs4_proc_getlk(state
, cmd
, request
);
5165 trace_nfs4_get_lock(request
, state
, cmd
, err
);
5166 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
), err
,
5168 } while (exception
.retry
);
5172 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
5175 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
5177 res
= posix_lock_file_wait(file
, fl
);
5180 res
= flock_lock_file_wait(file
, fl
);
5188 struct nfs4_unlockdata
{
5189 struct nfs_locku_args arg
;
5190 struct nfs_locku_res res
;
5191 struct nfs4_lock_state
*lsp
;
5192 struct nfs_open_context
*ctx
;
5193 struct file_lock fl
;
5194 const struct nfs_server
*server
;
5195 unsigned long timestamp
;
5198 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
5199 struct nfs_open_context
*ctx
,
5200 struct nfs4_lock_state
*lsp
,
5201 struct nfs_seqid
*seqid
)
5203 struct nfs4_unlockdata
*p
;
5204 struct inode
*inode
= lsp
->ls_state
->inode
;
5206 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
5209 p
->arg
.fh
= NFS_FH(inode
);
5211 p
->arg
.seqid
= seqid
;
5212 p
->res
.seqid
= seqid
;
5213 p
->arg
.stateid
= &lsp
->ls_stateid
;
5215 atomic_inc(&lsp
->ls_count
);
5216 /* Ensure we don't close file until we're done freeing locks! */
5217 p
->ctx
= get_nfs_open_context(ctx
);
5218 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5219 p
->server
= NFS_SERVER(inode
);
5223 static void nfs4_locku_release_calldata(void *data
)
5225 struct nfs4_unlockdata
*calldata
= data
;
5226 nfs_free_seqid(calldata
->arg
.seqid
);
5227 nfs4_put_lock_state(calldata
->lsp
);
5228 put_nfs_open_context(calldata
->ctx
);
5232 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
5234 struct nfs4_unlockdata
*calldata
= data
;
5236 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
5238 switch (task
->tk_status
) {
5240 nfs4_stateid_copy(&calldata
->lsp
->ls_stateid
,
5241 &calldata
->res
.stateid
);
5242 renew_lease(calldata
->server
, calldata
->timestamp
);
5244 case -NFS4ERR_BAD_STATEID
:
5245 case -NFS4ERR_OLD_STATEID
:
5246 case -NFS4ERR_STALE_STATEID
:
5247 case -NFS4ERR_EXPIRED
:
5250 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
5251 rpc_restart_call_prepare(task
);
5253 nfs_release_seqid(calldata
->arg
.seqid
);
5256 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
5258 struct nfs4_unlockdata
*calldata
= data
;
5260 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
5262 if (test_bit(NFS_LOCK_INITIALIZED
, &calldata
->lsp
->ls_flags
) == 0) {
5263 /* Note: exit _without_ running nfs4_locku_done */
5266 calldata
->timestamp
= jiffies
;
5267 if (nfs4_setup_sequence(calldata
->server
,
5268 &calldata
->arg
.seq_args
,
5269 &calldata
->res
.seq_res
,
5271 nfs_release_seqid(calldata
->arg
.seqid
);
5274 task
->tk_action
= NULL
;
5276 nfs4_sequence_done(task
, &calldata
->res
.seq_res
);
5279 static const struct rpc_call_ops nfs4_locku_ops
= {
5280 .rpc_call_prepare
= nfs4_locku_prepare
,
5281 .rpc_call_done
= nfs4_locku_done
,
5282 .rpc_release
= nfs4_locku_release_calldata
,
5285 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
5286 struct nfs_open_context
*ctx
,
5287 struct nfs4_lock_state
*lsp
,
5288 struct nfs_seqid
*seqid
)
5290 struct nfs4_unlockdata
*data
;
5291 struct rpc_message msg
= {
5292 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
5293 .rpc_cred
= ctx
->cred
,
5295 struct rpc_task_setup task_setup_data
= {
5296 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
5297 .rpc_message
= &msg
,
5298 .callback_ops
= &nfs4_locku_ops
,
5299 .workqueue
= nfsiod_workqueue
,
5300 .flags
= RPC_TASK_ASYNC
,
5303 nfs4_state_protect(NFS_SERVER(lsp
->ls_state
->inode
)->nfs_client
,
5304 NFS_SP4_MACH_CRED_CLEANUP
, &task_setup_data
.rpc_client
, &msg
);
5306 /* Ensure this is an unlock - when canceling a lock, the
5307 * canceled lock is passed in, and it won't be an unlock.
5309 fl
->fl_type
= F_UNLCK
;
5311 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
5313 nfs_free_seqid(seqid
);
5314 return ERR_PTR(-ENOMEM
);
5317 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5318 msg
.rpc_argp
= &data
->arg
;
5319 msg
.rpc_resp
= &data
->res
;
5320 task_setup_data
.callback_data
= data
;
5321 return rpc_run_task(&task_setup_data
);
5324 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5326 struct inode
*inode
= state
->inode
;
5327 struct nfs4_state_owner
*sp
= state
->owner
;
5328 struct nfs_inode
*nfsi
= NFS_I(inode
);
5329 struct nfs_seqid
*seqid
;
5330 struct nfs4_lock_state
*lsp
;
5331 struct rpc_task
*task
;
5333 unsigned char fl_flags
= request
->fl_flags
;
5335 status
= nfs4_set_lock_state(state
, request
);
5336 /* Unlock _before_ we do the RPC call */
5337 request
->fl_flags
|= FL_EXISTS
;
5338 /* Exclude nfs_delegation_claim_locks() */
5339 mutex_lock(&sp
->so_delegreturn_mutex
);
5340 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5341 down_read(&nfsi
->rwsem
);
5342 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
5343 up_read(&nfsi
->rwsem
);
5344 mutex_unlock(&sp
->so_delegreturn_mutex
);
5347 up_read(&nfsi
->rwsem
);
5348 mutex_unlock(&sp
->so_delegreturn_mutex
);
5351 /* Is this a delegated lock? */
5352 lsp
= request
->fl_u
.nfs4_fl
.owner
;
5353 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) == 0)
5355 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
5359 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
5360 status
= PTR_ERR(task
);
5363 status
= nfs4_wait_for_completion_rpc_task(task
);
5366 request
->fl_flags
= fl_flags
;
5367 trace_nfs4_unlock(request
, state
, F_SETLK
, status
);
5371 struct nfs4_lockdata
{
5372 struct nfs_lock_args arg
;
5373 struct nfs_lock_res res
;
5374 struct nfs4_lock_state
*lsp
;
5375 struct nfs_open_context
*ctx
;
5376 struct file_lock fl
;
5377 unsigned long timestamp
;
5380 struct nfs_server
*server
;
5383 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
5384 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
5387 struct nfs4_lockdata
*p
;
5388 struct inode
*inode
= lsp
->ls_state
->inode
;
5389 struct nfs_server
*server
= NFS_SERVER(inode
);
5391 p
= kzalloc(sizeof(*p
), gfp_mask
);
5395 p
->arg
.fh
= NFS_FH(inode
);
5397 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
5398 if (p
->arg
.open_seqid
== NULL
)
5400 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
5401 if (p
->arg
.lock_seqid
== NULL
)
5402 goto out_free_seqid
;
5403 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
5404 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5405 p
->arg
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5406 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
5407 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
5410 atomic_inc(&lsp
->ls_count
);
5411 p
->ctx
= get_nfs_open_context(ctx
);
5412 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
5415 nfs_free_seqid(p
->arg
.open_seqid
);
5421 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
5423 struct nfs4_lockdata
*data
= calldata
;
5424 struct nfs4_state
*state
= data
->lsp
->ls_state
;
5426 dprintk("%s: begin!\n", __func__
);
5427 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
5429 /* Do we need to do an open_to_lock_owner? */
5430 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
5431 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0) {
5432 goto out_release_lock_seqid
;
5434 data
->arg
.open_stateid
= &state
->open_stateid
;
5435 data
->arg
.new_lock_owner
= 1;
5436 data
->res
.open_seqid
= data
->arg
.open_seqid
;
5438 data
->arg
.new_lock_owner
= 0;
5439 if (!nfs4_valid_open_stateid(state
)) {
5440 data
->rpc_status
= -EBADF
;
5441 task
->tk_action
= NULL
;
5442 goto out_release_open_seqid
;
5444 data
->timestamp
= jiffies
;
5445 if (nfs4_setup_sequence(data
->server
,
5446 &data
->arg
.seq_args
,
5450 out_release_open_seqid
:
5451 nfs_release_seqid(data
->arg
.open_seqid
);
5452 out_release_lock_seqid
:
5453 nfs_release_seqid(data
->arg
.lock_seqid
);
5455 nfs4_sequence_done(task
, &data
->res
.seq_res
);
5456 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
5459 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
5461 struct nfs4_lockdata
*data
= calldata
;
5463 dprintk("%s: begin!\n", __func__
);
5465 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5468 data
->rpc_status
= task
->tk_status
;
5469 if (data
->arg
.new_lock_owner
!= 0) {
5470 if (data
->rpc_status
== 0)
5471 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
5475 if (data
->rpc_status
== 0) {
5476 nfs4_stateid_copy(&data
->lsp
->ls_stateid
, &data
->res
.stateid
);
5477 set_bit(NFS_LOCK_INITIALIZED
, &data
->lsp
->ls_flags
);
5478 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
5481 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
5484 static void nfs4_lock_release(void *calldata
)
5486 struct nfs4_lockdata
*data
= calldata
;
5488 dprintk("%s: begin!\n", __func__
);
5489 nfs_free_seqid(data
->arg
.open_seqid
);
5490 if (data
->cancelled
!= 0) {
5491 struct rpc_task
*task
;
5492 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
5493 data
->arg
.lock_seqid
);
5495 rpc_put_task_async(task
);
5496 dprintk("%s: cancelling lock!\n", __func__
);
5498 nfs_free_seqid(data
->arg
.lock_seqid
);
5499 nfs4_put_lock_state(data
->lsp
);
5500 put_nfs_open_context(data
->ctx
);
5502 dprintk("%s: done!\n", __func__
);
5505 static const struct rpc_call_ops nfs4_lock_ops
= {
5506 .rpc_call_prepare
= nfs4_lock_prepare
,
5507 .rpc_call_done
= nfs4_lock_done
,
5508 .rpc_release
= nfs4_lock_release
,
5511 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
5514 case -NFS4ERR_ADMIN_REVOKED
:
5515 case -NFS4ERR_BAD_STATEID
:
5516 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5517 if (new_lock_owner
!= 0 ||
5518 test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
) != 0)
5519 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
5521 case -NFS4ERR_STALE_STATEID
:
5522 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
5523 case -NFS4ERR_EXPIRED
:
5524 nfs4_schedule_lease_recovery(server
->nfs_client
);
5528 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
5530 struct nfs4_lockdata
*data
;
5531 struct rpc_task
*task
;
5532 struct rpc_message msg
= {
5533 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
5534 .rpc_cred
= state
->owner
->so_cred
,
5536 struct rpc_task_setup task_setup_data
= {
5537 .rpc_client
= NFS_CLIENT(state
->inode
),
5538 .rpc_message
= &msg
,
5539 .callback_ops
= &nfs4_lock_ops
,
5540 .workqueue
= nfsiod_workqueue
,
5541 .flags
= RPC_TASK_ASYNC
,
5545 dprintk("%s: begin!\n", __func__
);
5546 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
5547 fl
->fl_u
.nfs4_fl
.owner
,
5548 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
5552 data
->arg
.block
= 1;
5553 nfs4_init_sequence(&data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
5554 msg
.rpc_argp
= &data
->arg
;
5555 msg
.rpc_resp
= &data
->res
;
5556 task_setup_data
.callback_data
= data
;
5557 if (recovery_type
> NFS_LOCK_NEW
) {
5558 if (recovery_type
== NFS_LOCK_RECLAIM
)
5559 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
5560 nfs4_set_sequence_privileged(&data
->arg
.seq_args
);
5562 task
= rpc_run_task(&task_setup_data
);
5564 return PTR_ERR(task
);
5565 ret
= nfs4_wait_for_completion_rpc_task(task
);
5567 ret
= data
->rpc_status
;
5569 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
5570 data
->arg
.new_lock_owner
, ret
);
5572 data
->cancelled
= 1;
5574 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
5578 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
5580 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5581 struct nfs4_exception exception
= {
5582 .inode
= state
->inode
,
5587 /* Cache the lock if possible... */
5588 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5590 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
5591 trace_nfs4_lock_reclaim(request
, state
, F_SETLK
, err
);
5592 if (err
!= -NFS4ERR_DELAY
)
5594 nfs4_handle_exception(server
, err
, &exception
);
5595 } while (exception
.retry
);
5599 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5601 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5602 struct nfs4_exception exception
= {
5603 .inode
= state
->inode
,
5607 err
= nfs4_set_lock_state(state
, request
);
5610 if (!recover_lost_locks
) {
5611 set_bit(NFS_LOCK_LOST
, &request
->fl_u
.nfs4_fl
.owner
->ls_flags
);
5615 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
5617 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
5618 trace_nfs4_lock_expired(request
, state
, F_SETLK
, err
);
5622 case -NFS4ERR_GRACE
:
5623 case -NFS4ERR_DELAY
:
5624 nfs4_handle_exception(server
, err
, &exception
);
5627 } while (exception
.retry
);
5632 #if defined(CONFIG_NFS_V4_1)
5634 * nfs41_check_expired_locks - possibly free a lock stateid
5636 * @state: NFSv4 state for an inode
5638 * Returns NFS_OK if recovery for this stateid is now finished.
5639 * Otherwise a negative NFS4ERR value is returned.
5641 static int nfs41_check_expired_locks(struct nfs4_state
*state
)
5643 int status
, ret
= -NFS4ERR_BAD_STATEID
;
5644 struct nfs4_lock_state
*lsp
;
5645 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5647 list_for_each_entry(lsp
, &state
->lock_states
, ls_locks
) {
5648 if (test_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
)) {
5649 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
5651 status
= nfs41_test_stateid(server
,
5654 trace_nfs4_test_lock_stateid(state
, lsp
, status
);
5655 if (status
!= NFS_OK
) {
5656 /* Free the stateid unless the server
5657 * informs us the stateid is unrecognized. */
5658 if (status
!= -NFS4ERR_BAD_STATEID
)
5659 nfs41_free_stateid(server
,
5662 clear_bit(NFS_LOCK_INITIALIZED
, &lsp
->ls_flags
);
5671 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
5673 int status
= NFS_OK
;
5675 if (test_bit(LK_STATE_IN_USE
, &state
->flags
))
5676 status
= nfs41_check_expired_locks(state
);
5677 if (status
!= NFS_OK
)
5678 status
= nfs4_lock_expired(state
, request
);
5683 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5685 struct nfs4_state_owner
*sp
= state
->owner
;
5686 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
5687 unsigned char fl_flags
= request
->fl_flags
;
5689 int status
= -ENOLCK
;
5691 if ((fl_flags
& FL_POSIX
) &&
5692 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
5694 /* Is this a delegated open? */
5695 status
= nfs4_set_lock_state(state
, request
);
5698 request
->fl_flags
|= FL_ACCESS
;
5699 status
= do_vfs_lock(request
->fl_file
, request
);
5702 down_read(&nfsi
->rwsem
);
5703 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
5704 /* Yes: cache locks! */
5705 /* ...but avoid races with delegation recall... */
5706 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
5707 status
= do_vfs_lock(request
->fl_file
, request
);
5710 seq
= raw_seqcount_begin(&sp
->so_reclaim_seqcount
);
5711 up_read(&nfsi
->rwsem
);
5712 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
5715 down_read(&nfsi
->rwsem
);
5716 if (read_seqcount_retry(&sp
->so_reclaim_seqcount
, seq
)) {
5717 status
= -NFS4ERR_DELAY
;
5720 /* Note: we always want to sleep here! */
5721 request
->fl_flags
= fl_flags
| FL_SLEEP
;
5722 if (do_vfs_lock(request
->fl_file
, request
) < 0)
5723 printk(KERN_WARNING
"NFS: %s: VFS is out of sync with lock "
5724 "manager!\n", __func__
);
5726 up_read(&nfsi
->rwsem
);
5728 request
->fl_flags
= fl_flags
;
5732 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
5734 struct nfs4_exception exception
= {
5736 .inode
= state
->inode
,
5741 err
= _nfs4_proc_setlk(state
, cmd
, request
);
5742 trace_nfs4_set_lock(request
, state
, cmd
, err
);
5743 if (err
== -NFS4ERR_DENIED
)
5745 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
5747 } while (exception
.retry
);
5752 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
5754 struct nfs_open_context
*ctx
;
5755 struct nfs4_state
*state
;
5756 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
5759 /* verify open state */
5760 ctx
= nfs_file_open_context(filp
);
5763 if (request
->fl_start
< 0 || request
->fl_end
< 0)
5766 if (IS_GETLK(cmd
)) {
5768 return nfs4_proc_getlk(state
, F_GETLK
, request
);
5772 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
5775 if (request
->fl_type
== F_UNLCK
) {
5777 return nfs4_proc_unlck(state
, cmd
, request
);
5784 * Don't rely on the VFS having checked the file open mode,
5785 * since it won't do this for flock() locks.
5787 switch (request
->fl_type
) {
5789 if (!(filp
->f_mode
& FMODE_READ
))
5793 if (!(filp
->f_mode
& FMODE_WRITE
))
5798 status
= nfs4_proc_setlk(state
, cmd
, request
);
5799 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
5801 timeout
= nfs4_set_lock_task_retry(timeout
);
5802 status
= -ERESTARTSYS
;
5805 } while(status
< 0);
5809 int nfs4_lock_delegation_recall(struct file_lock
*fl
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
5811 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
5814 err
= nfs4_set_lock_state(state
, fl
);
5817 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
5818 return nfs4_handle_delegation_recall_error(server
, state
, stateid
, err
);
5821 struct nfs_release_lockowner_data
{
5822 struct nfs4_lock_state
*lsp
;
5823 struct nfs_server
*server
;
5824 struct nfs_release_lockowner_args args
;
5825 struct nfs4_sequence_args seq_args
;
5826 struct nfs4_sequence_res seq_res
;
5827 unsigned long timestamp
;
5830 static void nfs4_release_lockowner_prepare(struct rpc_task
*task
, void *calldata
)
5832 struct nfs_release_lockowner_data
*data
= calldata
;
5833 nfs40_setup_sequence(data
->server
,
5834 &data
->seq_args
, &data
->seq_res
, task
);
5835 data
->timestamp
= jiffies
;
5838 static void nfs4_release_lockowner_done(struct rpc_task
*task
, void *calldata
)
5840 struct nfs_release_lockowner_data
*data
= calldata
;
5841 struct nfs_server
*server
= data
->server
;
5843 nfs40_sequence_done(task
, &data
->seq_res
);
5845 switch (task
->tk_status
) {
5847 renew_lease(server
, data
->timestamp
);
5849 case -NFS4ERR_STALE_CLIENTID
:
5850 case -NFS4ERR_EXPIRED
:
5851 case -NFS4ERR_LEASE_MOVED
:
5852 case -NFS4ERR_DELAY
:
5853 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
)
5854 rpc_restart_call_prepare(task
);
5858 static void nfs4_release_lockowner_release(void *calldata
)
5860 struct nfs_release_lockowner_data
*data
= calldata
;
5861 nfs4_free_lock_state(data
->server
, data
->lsp
);
5865 static const struct rpc_call_ops nfs4_release_lockowner_ops
= {
5866 .rpc_call_prepare
= nfs4_release_lockowner_prepare
,
5867 .rpc_call_done
= nfs4_release_lockowner_done
,
5868 .rpc_release
= nfs4_release_lockowner_release
,
5871 static int nfs4_release_lockowner(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
5873 struct nfs_release_lockowner_data
*data
;
5874 struct rpc_message msg
= {
5875 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
5878 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
5881 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
5884 nfs4_init_sequence(&data
->seq_args
, &data
->seq_res
, 0);
5886 data
->server
= server
;
5887 data
->args
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
5888 data
->args
.lock_owner
.id
= lsp
->ls_seqid
.owner_id
;
5889 data
->args
.lock_owner
.s_dev
= server
->s_dev
;
5891 msg
.rpc_argp
= &data
->args
;
5892 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, data
);
5896 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5898 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
5899 const void *buf
, size_t buflen
,
5900 int flags
, int type
)
5902 if (strcmp(key
, "") != 0)
5905 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
5908 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
5909 void *buf
, size_t buflen
, int type
)
5911 if (strcmp(key
, "") != 0)
5914 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
5917 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
5918 size_t list_len
, const char *name
,
5919 size_t name_len
, int type
)
5921 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
5923 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
5926 if (list
&& len
<= list_len
)
5927 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
5931 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5932 static inline int nfs4_server_supports_labels(struct nfs_server
*server
)
5934 return server
->caps
& NFS_CAP_SECURITY_LABEL
;
5937 static int nfs4_xattr_set_nfs4_label(struct dentry
*dentry
, const char *key
,
5938 const void *buf
, size_t buflen
,
5939 int flags
, int type
)
5941 if (security_ismaclabel(key
))
5942 return nfs4_set_security_label(dentry
, buf
, buflen
);
5947 static int nfs4_xattr_get_nfs4_label(struct dentry
*dentry
, const char *key
,
5948 void *buf
, size_t buflen
, int type
)
5950 if (security_ismaclabel(key
))
5951 return nfs4_get_security_label(dentry
->d_inode
, buf
, buflen
);
5955 static size_t nfs4_xattr_list_nfs4_label(struct dentry
*dentry
, char *list
,
5956 size_t list_len
, const char *name
,
5957 size_t name_len
, int type
)
5961 if (nfs_server_capable(dentry
->d_inode
, NFS_CAP_SECURITY_LABEL
)) {
5962 len
= security_inode_listsecurity(dentry
->d_inode
, NULL
, 0);
5963 if (list
&& len
<= list_len
)
5964 security_inode_listsecurity(dentry
->d_inode
, list
, len
);
5969 static const struct xattr_handler nfs4_xattr_nfs4_label_handler
= {
5970 .prefix
= XATTR_SECURITY_PREFIX
,
5971 .list
= nfs4_xattr_list_nfs4_label
,
5972 .get
= nfs4_xattr_get_nfs4_label
,
5973 .set
= nfs4_xattr_set_nfs4_label
,
5979 * nfs_fhget will use either the mounted_on_fileid or the fileid
5981 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
5983 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
5984 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
5985 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
5986 (fattr
->valid
& NFS_ATTR_FATTR_V4_LOCATIONS
)))
5989 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
5990 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_V4_REFERRAL
;
5991 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
5995 static int _nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
5996 const struct qstr
*name
,
5997 struct nfs4_fs_locations
*fs_locations
,
6000 struct nfs_server
*server
= NFS_SERVER(dir
);
6002 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6004 struct nfs4_fs_locations_arg args
= {
6005 .dir_fh
= NFS_FH(dir
),
6010 struct nfs4_fs_locations_res res
= {
6011 .fs_locations
= fs_locations
,
6013 struct rpc_message msg
= {
6014 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6020 dprintk("%s: start\n", __func__
);
6022 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
6023 * is not supported */
6024 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
6025 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
6027 bitmask
[0] |= FATTR4_WORD0_FILEID
;
6029 nfs_fattr_init(&fs_locations
->fattr
);
6030 fs_locations
->server
= server
;
6031 fs_locations
->nlocations
= 0;
6032 status
= nfs4_call_sync(client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
6033 dprintk("%s: returned status = %d\n", __func__
, status
);
6037 int nfs4_proc_fs_locations(struct rpc_clnt
*client
, struct inode
*dir
,
6038 const struct qstr
*name
,
6039 struct nfs4_fs_locations
*fs_locations
,
6042 struct nfs4_exception exception
= { };
6045 err
= _nfs4_proc_fs_locations(client
, dir
, name
,
6046 fs_locations
, page
);
6047 trace_nfs4_get_fs_locations(dir
, name
, err
);
6048 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6050 } while (exception
.retry
);
6055 * This operation also signals the server that this client is
6056 * performing migration recovery. The server can stop returning
6057 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
6058 * appended to this compound to identify the client ID which is
6059 * performing recovery.
6061 static int _nfs40_proc_get_locations(struct inode
*inode
,
6062 struct nfs4_fs_locations
*locations
,
6063 struct page
*page
, struct rpc_cred
*cred
)
6065 struct nfs_server
*server
= NFS_SERVER(inode
);
6066 struct rpc_clnt
*clnt
= server
->client
;
6068 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6070 struct nfs4_fs_locations_arg args
= {
6071 .clientid
= server
->nfs_client
->cl_clientid
,
6072 .fh
= NFS_FH(inode
),
6075 .migration
= 1, /* skip LOOKUP */
6076 .renew
= 1, /* append RENEW */
6078 struct nfs4_fs_locations_res res
= {
6079 .fs_locations
= locations
,
6083 struct rpc_message msg
= {
6084 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6089 unsigned long now
= jiffies
;
6092 nfs_fattr_init(&locations
->fattr
);
6093 locations
->server
= server
;
6094 locations
->nlocations
= 0;
6096 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6097 nfs4_set_sequence_privileged(&args
.seq_args
);
6098 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6099 &args
.seq_args
, &res
.seq_res
);
6103 renew_lease(server
, now
);
6107 #ifdef CONFIG_NFS_V4_1
6110 * This operation also signals the server that this client is
6111 * performing migration recovery. The server can stop asserting
6112 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
6113 * performing this operation is identified in the SEQUENCE
6114 * operation in this compound.
6116 * When the client supports GETATTR(fs_locations_info), it can
6117 * be plumbed in here.
6119 static int _nfs41_proc_get_locations(struct inode
*inode
,
6120 struct nfs4_fs_locations
*locations
,
6121 struct page
*page
, struct rpc_cred
*cred
)
6123 struct nfs_server
*server
= NFS_SERVER(inode
);
6124 struct rpc_clnt
*clnt
= server
->client
;
6126 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
6128 struct nfs4_fs_locations_arg args
= {
6129 .fh
= NFS_FH(inode
),
6132 .migration
= 1, /* skip LOOKUP */
6134 struct nfs4_fs_locations_res res
= {
6135 .fs_locations
= locations
,
6138 struct rpc_message msg
= {
6139 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
6146 nfs_fattr_init(&locations
->fattr
);
6147 locations
->server
= server
;
6148 locations
->nlocations
= 0;
6150 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6151 nfs4_set_sequence_privileged(&args
.seq_args
);
6152 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6153 &args
.seq_args
, &res
.seq_res
);
6154 if (status
== NFS4_OK
&&
6155 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6156 status
= -NFS4ERR_LEASE_MOVED
;
6160 #endif /* CONFIG_NFS_V4_1 */
6163 * nfs4_proc_get_locations - discover locations for a migrated FSID
6164 * @inode: inode on FSID that is migrating
6165 * @locations: result of query
6167 * @cred: credential to use for this operation
6169 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
6170 * operation failed, or a negative errno if a local error occurred.
6172 * On success, "locations" is filled in, but if the server has
6173 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
6176 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
6177 * from this client that require migration recovery.
6179 int nfs4_proc_get_locations(struct inode
*inode
,
6180 struct nfs4_fs_locations
*locations
,
6181 struct page
*page
, struct rpc_cred
*cred
)
6183 struct nfs_server
*server
= NFS_SERVER(inode
);
6184 struct nfs_client
*clp
= server
->nfs_client
;
6185 const struct nfs4_mig_recovery_ops
*ops
=
6186 clp
->cl_mvops
->mig_recovery_ops
;
6187 struct nfs4_exception exception
= { };
6190 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6191 (unsigned long long)server
->fsid
.major
,
6192 (unsigned long long)server
->fsid
.minor
,
6194 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6197 status
= ops
->get_locations(inode
, locations
, page
, cred
);
6198 if (status
!= -NFS4ERR_DELAY
)
6200 nfs4_handle_exception(server
, status
, &exception
);
6201 } while (exception
.retry
);
6206 * This operation also signals the server that this client is
6207 * performing "lease moved" recovery. The server can stop
6208 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
6209 * is appended to this compound to identify the client ID which is
6210 * performing recovery.
6212 static int _nfs40_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6214 struct nfs_server
*server
= NFS_SERVER(inode
);
6215 struct nfs_client
*clp
= NFS_SERVER(inode
)->nfs_client
;
6216 struct rpc_clnt
*clnt
= server
->client
;
6217 struct nfs4_fsid_present_arg args
= {
6218 .fh
= NFS_FH(inode
),
6219 .clientid
= clp
->cl_clientid
,
6220 .renew
= 1, /* append RENEW */
6222 struct nfs4_fsid_present_res res
= {
6225 struct rpc_message msg
= {
6226 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6231 unsigned long now
= jiffies
;
6234 res
.fh
= nfs_alloc_fhandle();
6238 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6239 nfs4_set_sequence_privileged(&args
.seq_args
);
6240 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6241 &args
.seq_args
, &res
.seq_res
);
6242 nfs_free_fhandle(res
.fh
);
6246 do_renew_lease(clp
, now
);
6250 #ifdef CONFIG_NFS_V4_1
6253 * This operation also signals the server that this client is
6254 * performing "lease moved" recovery. The server can stop asserting
6255 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
6256 * this operation is identified in the SEQUENCE operation in this
6259 static int _nfs41_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6261 struct nfs_server
*server
= NFS_SERVER(inode
);
6262 struct rpc_clnt
*clnt
= server
->client
;
6263 struct nfs4_fsid_present_arg args
= {
6264 .fh
= NFS_FH(inode
),
6266 struct nfs4_fsid_present_res res
= {
6268 struct rpc_message msg
= {
6269 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSID_PRESENT
],
6276 res
.fh
= nfs_alloc_fhandle();
6280 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
6281 nfs4_set_sequence_privileged(&args
.seq_args
);
6282 status
= nfs4_call_sync_sequence(clnt
, server
, &msg
,
6283 &args
.seq_args
, &res
.seq_res
);
6284 nfs_free_fhandle(res
.fh
);
6285 if (status
== NFS4_OK
&&
6286 res
.seq_res
.sr_status_flags
& SEQ4_STATUS_LEASE_MOVED
)
6287 status
= -NFS4ERR_LEASE_MOVED
;
6291 #endif /* CONFIG_NFS_V4_1 */
6294 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
6295 * @inode: inode on FSID to check
6296 * @cred: credential to use for this operation
6298 * Server indicates whether the FSID is present, moved, or not
6299 * recognized. This operation is necessary to clear a LEASE_MOVED
6300 * condition for this client ID.
6302 * Returns NFS4_OK if the FSID is present on this server,
6303 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
6304 * NFS4ERR code if some error occurred on the server, or a
6305 * negative errno if a local failure occurred.
6307 int nfs4_proc_fsid_present(struct inode
*inode
, struct rpc_cred
*cred
)
6309 struct nfs_server
*server
= NFS_SERVER(inode
);
6310 struct nfs_client
*clp
= server
->nfs_client
;
6311 const struct nfs4_mig_recovery_ops
*ops
=
6312 clp
->cl_mvops
->mig_recovery_ops
;
6313 struct nfs4_exception exception
= { };
6316 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__
,
6317 (unsigned long long)server
->fsid
.major
,
6318 (unsigned long long)server
->fsid
.minor
,
6320 nfs_display_fhandle(NFS_FH(inode
), __func__
);
6323 status
= ops
->fsid_present(inode
, cred
);
6324 if (status
!= -NFS4ERR_DELAY
)
6326 nfs4_handle_exception(server
, status
, &exception
);
6327 } while (exception
.retry
);
6332 * If 'use_integrity' is true and the state managment nfs_client
6333 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
6334 * and the machine credential as per RFC3530bis and RFC5661 Security
6335 * Considerations sections. Otherwise, just use the user cred with the
6336 * filesystem's rpc_client.
6338 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
6341 struct nfs4_secinfo_arg args
= {
6342 .dir_fh
= NFS_FH(dir
),
6345 struct nfs4_secinfo_res res
= {
6348 struct rpc_message msg
= {
6349 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
6353 struct rpc_clnt
*clnt
= NFS_SERVER(dir
)->client
;
6354 struct rpc_cred
*cred
= NULL
;
6356 if (use_integrity
) {
6357 clnt
= NFS_SERVER(dir
)->nfs_client
->cl_rpcclient
;
6358 cred
= nfs4_get_clid_cred(NFS_SERVER(dir
)->nfs_client
);
6359 msg
.rpc_cred
= cred
;
6362 dprintk("NFS call secinfo %s\n", name
->name
);
6364 nfs4_state_protect(NFS_SERVER(dir
)->nfs_client
,
6365 NFS_SP4_MACH_CRED_SECINFO
, &clnt
, &msg
);
6367 status
= nfs4_call_sync(clnt
, NFS_SERVER(dir
), &msg
, &args
.seq_args
,
6369 dprintk("NFS reply secinfo: %d\n", status
);
6377 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
,
6378 struct nfs4_secinfo_flavors
*flavors
)
6380 struct nfs4_exception exception
= { };
6383 err
= -NFS4ERR_WRONGSEC
;
6385 /* try to use integrity protection with machine cred */
6386 if (_nfs4_is_integrity_protected(NFS_SERVER(dir
)->nfs_client
))
6387 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, true);
6390 * if unable to use integrity protection, or SECINFO with
6391 * integrity protection returns NFS4ERR_WRONGSEC (which is
6392 * disallowed by spec, but exists in deployed servers) use
6393 * the current filesystem's rpc_client and the user cred.
6395 if (err
== -NFS4ERR_WRONGSEC
)
6396 err
= _nfs4_proc_secinfo(dir
, name
, flavors
, false);
6398 trace_nfs4_secinfo(dir
, name
, err
);
6399 err
= nfs4_handle_exception(NFS_SERVER(dir
), err
,
6401 } while (exception
.retry
);
6405 #ifdef CONFIG_NFS_V4_1
6407 * Check the exchange flags returned by the server for invalid flags, having
6408 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
6411 static int nfs4_check_cl_exchange_flags(u32 flags
)
6413 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
6415 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
6416 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
6418 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
6422 return -NFS4ERR_INVAL
;
6426 nfs41_same_server_scope(struct nfs41_server_scope
*a
,
6427 struct nfs41_server_scope
*b
)
6429 if (a
->server_scope_sz
== b
->server_scope_sz
&&
6430 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
6437 * nfs4_proc_bind_conn_to_session()
6439 * The 4.1 client currently uses the same TCP connection for the
6440 * fore and backchannel.
6442 int nfs4_proc_bind_conn_to_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6445 struct nfs41_bind_conn_to_session_res res
;
6446 struct rpc_message msg
= {
6448 &nfs4_procedures
[NFSPROC4_CLNT_BIND_CONN_TO_SESSION
],
6454 dprintk("--> %s\n", __func__
);
6456 res
.session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
6457 if (unlikely(res
.session
== NULL
)) {
6462 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6463 trace_nfs4_bind_conn_to_session(clp
, status
);
6465 if (memcmp(res
.session
->sess_id
.data
,
6466 clp
->cl_session
->sess_id
.data
, NFS4_MAX_SESSIONID_LEN
)) {
6467 dprintk("NFS: %s: Session ID mismatch\n", __func__
);
6471 if (res
.dir
!= NFS4_CDFS4_BOTH
) {
6472 dprintk("NFS: %s: Unexpected direction from server\n",
6477 if (res
.use_conn_in_rdma_mode
) {
6478 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6487 dprintk("<-- %s status= %d\n", __func__
, status
);
6492 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
6493 * and operations we'd like to see to enable certain features in the allow map
6495 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request
= {
6496 .how
= SP4_MACH_CRED
,
6497 .enforce
.u
.words
= {
6498 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6499 1 << (OP_EXCHANGE_ID
- 32) |
6500 1 << (OP_CREATE_SESSION
- 32) |
6501 1 << (OP_DESTROY_SESSION
- 32) |
6502 1 << (OP_DESTROY_CLIENTID
- 32)
6505 [0] = 1 << (OP_CLOSE
) |
6508 [1] = 1 << (OP_SECINFO
- 32) |
6509 1 << (OP_SECINFO_NO_NAME
- 32) |
6510 1 << (OP_TEST_STATEID
- 32) |
6511 1 << (OP_FREE_STATEID
- 32) |
6512 1 << (OP_WRITE
- 32)
6517 * Select the state protection mode for client `clp' given the server results
6518 * from exchange_id in `sp'.
6520 * Returns 0 on success, negative errno otherwise.
6522 static int nfs4_sp4_select_mode(struct nfs_client
*clp
,
6523 struct nfs41_state_protection
*sp
)
6525 static const u32 supported_enforce
[NFS4_OP_MAP_NUM_WORDS
] = {
6526 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
6527 1 << (OP_EXCHANGE_ID
- 32) |
6528 1 << (OP_CREATE_SESSION
- 32) |
6529 1 << (OP_DESTROY_SESSION
- 32) |
6530 1 << (OP_DESTROY_CLIENTID
- 32)
6534 if (sp
->how
== SP4_MACH_CRED
) {
6535 /* Print state protect result */
6536 dfprintk(MOUNT
, "Server SP4_MACH_CRED support:\n");
6537 for (i
= 0; i
<= LAST_NFS4_OP
; i
++) {
6538 if (test_bit(i
, sp
->enforce
.u
.longs
))
6539 dfprintk(MOUNT
, " enforce op %d\n", i
);
6540 if (test_bit(i
, sp
->allow
.u
.longs
))
6541 dfprintk(MOUNT
, " allow op %d\n", i
);
6544 /* make sure nothing is on enforce list that isn't supported */
6545 for (i
= 0; i
< NFS4_OP_MAP_NUM_WORDS
; i
++) {
6546 if (sp
->enforce
.u
.words
[i
] & ~supported_enforce
[i
]) {
6547 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6553 * Minimal mode - state operations are allowed to use machine
6554 * credential. Note this already happens by default, so the
6555 * client doesn't have to do anything more than the negotiation.
6557 * NOTE: we don't care if EXCHANGE_ID is in the list -
6558 * we're already using the machine cred for exchange_id
6559 * and will never use a different cred.
6561 if (test_bit(OP_BIND_CONN_TO_SESSION
, sp
->enforce
.u
.longs
) &&
6562 test_bit(OP_CREATE_SESSION
, sp
->enforce
.u
.longs
) &&
6563 test_bit(OP_DESTROY_SESSION
, sp
->enforce
.u
.longs
) &&
6564 test_bit(OP_DESTROY_CLIENTID
, sp
->enforce
.u
.longs
)) {
6565 dfprintk(MOUNT
, "sp4_mach_cred:\n");
6566 dfprintk(MOUNT
, " minimal mode enabled\n");
6567 set_bit(NFS_SP4_MACH_CRED_MINIMAL
, &clp
->cl_sp4_flags
);
6569 dfprintk(MOUNT
, "sp4_mach_cred: disabled\n");
6573 if (test_bit(OP_CLOSE
, sp
->allow
.u
.longs
) &&
6574 test_bit(OP_LOCKU
, sp
->allow
.u
.longs
)) {
6575 dfprintk(MOUNT
, " cleanup mode enabled\n");
6576 set_bit(NFS_SP4_MACH_CRED_CLEANUP
, &clp
->cl_sp4_flags
);
6579 if (test_bit(OP_SECINFO
, sp
->allow
.u
.longs
) &&
6580 test_bit(OP_SECINFO_NO_NAME
, sp
->allow
.u
.longs
)) {
6581 dfprintk(MOUNT
, " secinfo mode enabled\n");
6582 set_bit(NFS_SP4_MACH_CRED_SECINFO
, &clp
->cl_sp4_flags
);
6585 if (test_bit(OP_TEST_STATEID
, sp
->allow
.u
.longs
) &&
6586 test_bit(OP_FREE_STATEID
, sp
->allow
.u
.longs
)) {
6587 dfprintk(MOUNT
, " stateid mode enabled\n");
6588 set_bit(NFS_SP4_MACH_CRED_STATEID
, &clp
->cl_sp4_flags
);
6591 if (test_bit(OP_WRITE
, sp
->allow
.u
.longs
)) {
6592 dfprintk(MOUNT
, " write mode enabled\n");
6593 set_bit(NFS_SP4_MACH_CRED_WRITE
, &clp
->cl_sp4_flags
);
6596 if (test_bit(OP_COMMIT
, sp
->allow
.u
.longs
)) {
6597 dfprintk(MOUNT
, " commit mode enabled\n");
6598 set_bit(NFS_SP4_MACH_CRED_COMMIT
, &clp
->cl_sp4_flags
);
6606 * _nfs4_proc_exchange_id()
6608 * Wrapper for EXCHANGE_ID operation.
6610 static int _nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
,
6613 nfs4_verifier verifier
;
6614 struct nfs41_exchange_id_args args
= {
6615 .verifier
= &verifier
,
6617 #ifdef CONFIG_NFS_V4_1_MIGRATION
6618 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6619 EXCHGID4_FLAG_BIND_PRINC_STATEID
|
6620 EXCHGID4_FLAG_SUPP_MOVED_MIGR
,
6622 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
|
6623 EXCHGID4_FLAG_BIND_PRINC_STATEID
,
6626 struct nfs41_exchange_id_res res
= {
6630 struct rpc_message msg
= {
6631 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
6637 nfs4_init_boot_verifier(clp
, &verifier
);
6638 args
.id_len
= nfs4_init_uniform_client_string(clp
, args
.id
,
6640 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6641 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
6642 args
.id_len
, args
.id
);
6644 res
.server_owner
= kzalloc(sizeof(struct nfs41_server_owner
),
6646 if (unlikely(res
.server_owner
== NULL
)) {
6651 res
.server_scope
= kzalloc(sizeof(struct nfs41_server_scope
),
6653 if (unlikely(res
.server_scope
== NULL
)) {
6655 goto out_server_owner
;
6658 res
.impl_id
= kzalloc(sizeof(struct nfs41_impl_id
), GFP_NOFS
);
6659 if (unlikely(res
.impl_id
== NULL
)) {
6661 goto out_server_scope
;
6666 args
.state_protect
.how
= SP4_NONE
;
6670 args
.state_protect
= nfs4_sp4_mach_cred_request
;
6677 goto out_server_scope
;
6680 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6681 trace_nfs4_exchange_id(clp
, status
);
6683 status
= nfs4_check_cl_exchange_flags(res
.flags
);
6686 status
= nfs4_sp4_select_mode(clp
, &res
.state_protect
);
6689 clp
->cl_clientid
= res
.clientid
;
6690 clp
->cl_exchange_flags
= (res
.flags
& ~EXCHGID4_FLAG_CONFIRMED_R
);
6691 if (!(res
.flags
& EXCHGID4_FLAG_CONFIRMED_R
))
6692 clp
->cl_seqid
= res
.seqid
;
6694 kfree(clp
->cl_serverowner
);
6695 clp
->cl_serverowner
= res
.server_owner
;
6696 res
.server_owner
= NULL
;
6698 /* use the most recent implementation id */
6699 kfree(clp
->cl_implid
);
6700 clp
->cl_implid
= res
.impl_id
;
6702 if (clp
->cl_serverscope
!= NULL
&&
6703 !nfs41_same_server_scope(clp
->cl_serverscope
,
6704 res
.server_scope
)) {
6705 dprintk("%s: server_scope mismatch detected\n",
6707 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
6708 kfree(clp
->cl_serverscope
);
6709 clp
->cl_serverscope
= NULL
;
6712 if (clp
->cl_serverscope
== NULL
) {
6713 clp
->cl_serverscope
= res
.server_scope
;
6720 kfree(res
.server_owner
);
6722 kfree(res
.server_scope
);
6724 if (clp
->cl_implid
!= NULL
)
6725 dprintk("NFS reply exchange_id: Server Implementation ID: "
6726 "domain: %s, name: %s, date: %llu,%u\n",
6727 clp
->cl_implid
->domain
, clp
->cl_implid
->name
,
6728 clp
->cl_implid
->date
.seconds
,
6729 clp
->cl_implid
->date
.nseconds
);
6730 dprintk("NFS reply exchange_id: %d\n", status
);
6735 * nfs4_proc_exchange_id()
6737 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6739 * Since the clientid has expired, all compounds using sessions
6740 * associated with the stale clientid will be returning
6741 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6742 * be in some phase of session reset.
6744 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
6746 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
6748 rpc_authflavor_t authflavor
= clp
->cl_rpcclient
->cl_auth
->au_flavor
;
6751 /* try SP4_MACH_CRED if krb5i/p */
6752 if (authflavor
== RPC_AUTH_GSS_KRB5I
||
6753 authflavor
== RPC_AUTH_GSS_KRB5P
) {
6754 status
= _nfs4_proc_exchange_id(clp
, cred
, SP4_MACH_CRED
);
6760 return _nfs4_proc_exchange_id(clp
, cred
, SP4_NONE
);
6763 static int _nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6764 struct rpc_cred
*cred
)
6766 struct rpc_message msg
= {
6767 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_CLIENTID
],
6773 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
6774 trace_nfs4_destroy_clientid(clp
, status
);
6776 dprintk("NFS: Got error %d from the server %s on "
6777 "DESTROY_CLIENTID.", status
, clp
->cl_hostname
);
6781 static int nfs4_proc_destroy_clientid(struct nfs_client
*clp
,
6782 struct rpc_cred
*cred
)
6787 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
6788 ret
= _nfs4_proc_destroy_clientid(clp
, cred
);
6790 case -NFS4ERR_DELAY
:
6791 case -NFS4ERR_CLIENTID_BUSY
:
6801 int nfs4_destroy_clientid(struct nfs_client
*clp
)
6803 struct rpc_cred
*cred
;
6806 if (clp
->cl_mvops
->minor_version
< 1)
6808 if (clp
->cl_exchange_flags
== 0)
6810 if (clp
->cl_preserve_clid
)
6812 cred
= nfs4_get_clid_cred(clp
);
6813 ret
= nfs4_proc_destroy_clientid(clp
, cred
);
6818 case -NFS4ERR_STALE_CLIENTID
:
6819 clp
->cl_exchange_flags
= 0;
6825 struct nfs4_get_lease_time_data
{
6826 struct nfs4_get_lease_time_args
*args
;
6827 struct nfs4_get_lease_time_res
*res
;
6828 struct nfs_client
*clp
;
6831 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
6834 struct nfs4_get_lease_time_data
*data
=
6835 (struct nfs4_get_lease_time_data
*)calldata
;
6837 dprintk("--> %s\n", __func__
);
6838 /* just setup sequence, do not trigger session recovery
6839 since we're invoked within one */
6840 nfs41_setup_sequence(data
->clp
->cl_session
,
6841 &data
->args
->la_seq_args
,
6842 &data
->res
->lr_seq_res
,
6844 dprintk("<-- %s\n", __func__
);
6848 * Called from nfs4_state_manager thread for session setup, so don't recover
6849 * from sequence operation or clientid errors.
6851 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
6853 struct nfs4_get_lease_time_data
*data
=
6854 (struct nfs4_get_lease_time_data
*)calldata
;
6856 dprintk("--> %s\n", __func__
);
6857 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
6859 switch (task
->tk_status
) {
6860 case -NFS4ERR_DELAY
:
6861 case -NFS4ERR_GRACE
:
6862 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
6863 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
6864 task
->tk_status
= 0;
6866 case -NFS4ERR_RETRY_UNCACHED_REP
:
6867 rpc_restart_call_prepare(task
);
6870 dprintk("<-- %s\n", __func__
);
6873 static const struct rpc_call_ops nfs4_get_lease_time_ops
= {
6874 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
6875 .rpc_call_done
= nfs4_get_lease_time_done
,
6878 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
6880 struct rpc_task
*task
;
6881 struct nfs4_get_lease_time_args args
;
6882 struct nfs4_get_lease_time_res res
= {
6883 .lr_fsinfo
= fsinfo
,
6885 struct nfs4_get_lease_time_data data
= {
6890 struct rpc_message msg
= {
6891 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
6895 struct rpc_task_setup task_setup
= {
6896 .rpc_client
= clp
->cl_rpcclient
,
6897 .rpc_message
= &msg
,
6898 .callback_ops
= &nfs4_get_lease_time_ops
,
6899 .callback_data
= &data
,
6900 .flags
= RPC_TASK_TIMEOUT
,
6904 nfs4_init_sequence(&args
.la_seq_args
, &res
.lr_seq_res
, 0);
6905 nfs4_set_sequence_privileged(&args
.la_seq_args
);
6906 dprintk("--> %s\n", __func__
);
6907 task
= rpc_run_task(&task_setup
);
6910 status
= PTR_ERR(task
);
6912 status
= task
->tk_status
;
6915 dprintk("<-- %s return %d\n", __func__
, status
);
6921 * Initialize the values to be used by the client in CREATE_SESSION
6922 * If nfs4_init_session set the fore channel request and response sizes,
6925 * Set the back channel max_resp_sz_cached to zero to force the client to
6926 * always set csa_cachethis to FALSE because the current implementation
6927 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6929 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
6931 unsigned int max_rqst_sz
, max_resp_sz
;
6933 max_rqst_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxwrite_overhead
;
6934 max_resp_sz
= NFS_MAX_FILE_IO_SIZE
+ nfs41_maxread_overhead
;
6936 /* Fore channel attributes */
6937 args
->fc_attrs
.max_rqst_sz
= max_rqst_sz
;
6938 args
->fc_attrs
.max_resp_sz
= max_resp_sz
;
6939 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
6940 args
->fc_attrs
.max_reqs
= max_session_slots
;
6942 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6943 "max_ops=%u max_reqs=%u\n",
6945 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
6946 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
6948 /* Back channel attributes */
6949 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
6950 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
6951 args
->bc_attrs
.max_resp_sz_cached
= 0;
6952 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
6953 args
->bc_attrs
.max_reqs
= 1;
6955 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6956 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6958 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
6959 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
6960 args
->bc_attrs
.max_reqs
);
6963 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6965 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
6966 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
6968 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
6971 * Our requested max_ops is the minimum we need; we're not
6972 * prepared to break up compounds into smaller pieces than that.
6973 * So, no point even trying to continue if the server won't
6976 if (rcvd
->max_ops
< sent
->max_ops
)
6978 if (rcvd
->max_reqs
== 0)
6980 if (rcvd
->max_reqs
> NFS4_MAX_SLOT_TABLE
)
6981 rcvd
->max_reqs
= NFS4_MAX_SLOT_TABLE
;
6985 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
6987 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
6988 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
6990 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
6992 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
6994 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
6996 /* These would render the backchannel useless: */
6997 if (rcvd
->max_ops
!= sent
->max_ops
)
6999 if (rcvd
->max_reqs
!= sent
->max_reqs
)
7004 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
7005 struct nfs4_session
*session
)
7009 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
7012 return nfs4_verify_back_channel_attrs(args
, session
);
7015 static int _nfs4_proc_create_session(struct nfs_client
*clp
,
7016 struct rpc_cred
*cred
)
7018 struct nfs4_session
*session
= clp
->cl_session
;
7019 struct nfs41_create_session_args args
= {
7021 .cb_program
= NFS4_CALLBACK
,
7023 struct nfs41_create_session_res res
= {
7026 struct rpc_message msg
= {
7027 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
7034 nfs4_init_channel_attrs(&args
);
7035 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
7037 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7038 trace_nfs4_create_session(clp
, status
);
7041 /* Verify the session's negotiated channel_attrs values */
7042 status
= nfs4_verify_channel_attrs(&args
, session
);
7043 /* Increment the clientid slot sequence id */
7051 * Issues a CREATE_SESSION operation to the server.
7052 * It is the responsibility of the caller to verify the session is
7053 * expired before calling this routine.
7055 int nfs4_proc_create_session(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7059 struct nfs4_session
*session
= clp
->cl_session
;
7061 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
7063 status
= _nfs4_proc_create_session(clp
, cred
);
7067 /* Init or reset the session slot tables */
7068 status
= nfs4_setup_session_slot_tables(session
);
7069 dprintk("slot table setup returned %d\n", status
);
7073 ptr
= (unsigned *)&session
->sess_id
.data
[0];
7074 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
7075 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
7077 dprintk("<-- %s\n", __func__
);
7082 * Issue the over-the-wire RPC DESTROY_SESSION.
7083 * The caller must serialize access to this routine.
7085 int nfs4_proc_destroy_session(struct nfs4_session
*session
,
7086 struct rpc_cred
*cred
)
7088 struct rpc_message msg
= {
7089 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
],
7090 .rpc_argp
= session
,
7095 dprintk("--> nfs4_proc_destroy_session\n");
7097 /* session is still being setup */
7098 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
7101 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
7102 trace_nfs4_destroy_session(session
->clp
, status
);
7105 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
7106 "Session has been destroyed regardless...\n", status
);
7108 dprintk("<-- nfs4_proc_destroy_session\n");
7113 * Renew the cl_session lease.
7115 struct nfs4_sequence_data
{
7116 struct nfs_client
*clp
;
7117 struct nfs4_sequence_args args
;
7118 struct nfs4_sequence_res res
;
7121 static void nfs41_sequence_release(void *data
)
7123 struct nfs4_sequence_data
*calldata
= data
;
7124 struct nfs_client
*clp
= calldata
->clp
;
7126 if (atomic_read(&clp
->cl_count
) > 1)
7127 nfs4_schedule_state_renewal(clp
);
7128 nfs_put_client(clp
);
7132 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7134 switch(task
->tk_status
) {
7135 case -NFS4ERR_DELAY
:
7136 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7139 nfs4_schedule_lease_recovery(clp
);
7144 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
7146 struct nfs4_sequence_data
*calldata
= data
;
7147 struct nfs_client
*clp
= calldata
->clp
;
7149 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
7152 trace_nfs4_sequence(clp
, task
->tk_status
);
7153 if (task
->tk_status
< 0) {
7154 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
7155 if (atomic_read(&clp
->cl_count
) == 1)
7158 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
7159 rpc_restart_call_prepare(task
);
7163 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
7165 dprintk("<-- %s\n", __func__
);
7168 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
7170 struct nfs4_sequence_data
*calldata
= data
;
7171 struct nfs_client
*clp
= calldata
->clp
;
7172 struct nfs4_sequence_args
*args
;
7173 struct nfs4_sequence_res
*res
;
7175 args
= task
->tk_msg
.rpc_argp
;
7176 res
= task
->tk_msg
.rpc_resp
;
7178 nfs41_setup_sequence(clp
->cl_session
, args
, res
, task
);
7181 static const struct rpc_call_ops nfs41_sequence_ops
= {
7182 .rpc_call_done
= nfs41_sequence_call_done
,
7183 .rpc_call_prepare
= nfs41_sequence_prepare
,
7184 .rpc_release
= nfs41_sequence_release
,
7187 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
,
7188 struct rpc_cred
*cred
,
7191 struct nfs4_sequence_data
*calldata
;
7192 struct rpc_message msg
= {
7193 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
7196 struct rpc_task_setup task_setup_data
= {
7197 .rpc_client
= clp
->cl_rpcclient
,
7198 .rpc_message
= &msg
,
7199 .callback_ops
= &nfs41_sequence_ops
,
7200 .flags
= RPC_TASK_ASYNC
| RPC_TASK_TIMEOUT
,
7203 if (!atomic_inc_not_zero(&clp
->cl_count
))
7204 return ERR_PTR(-EIO
);
7205 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7206 if (calldata
== NULL
) {
7207 nfs_put_client(clp
);
7208 return ERR_PTR(-ENOMEM
);
7210 nfs4_init_sequence(&calldata
->args
, &calldata
->res
, 0);
7212 nfs4_set_sequence_privileged(&calldata
->args
);
7213 msg
.rpc_argp
= &calldata
->args
;
7214 msg
.rpc_resp
= &calldata
->res
;
7215 calldata
->clp
= clp
;
7216 task_setup_data
.callback_data
= calldata
;
7218 return rpc_run_task(&task_setup_data
);
7221 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
7223 struct rpc_task
*task
;
7226 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
7228 task
= _nfs41_proc_sequence(clp
, cred
, false);
7230 ret
= PTR_ERR(task
);
7232 rpc_put_task_async(task
);
7233 dprintk("<-- %s status=%d\n", __func__
, ret
);
7237 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
7239 struct rpc_task
*task
;
7242 task
= _nfs41_proc_sequence(clp
, cred
, true);
7244 ret
= PTR_ERR(task
);
7247 ret
= rpc_wait_for_completion_task(task
);
7249 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
7251 if (task
->tk_status
== 0)
7252 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
7253 ret
= task
->tk_status
;
7257 dprintk("<-- %s status=%d\n", __func__
, ret
);
7261 struct nfs4_reclaim_complete_data
{
7262 struct nfs_client
*clp
;
7263 struct nfs41_reclaim_complete_args arg
;
7264 struct nfs41_reclaim_complete_res res
;
7267 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
7269 struct nfs4_reclaim_complete_data
*calldata
= data
;
7271 nfs41_setup_sequence(calldata
->clp
->cl_session
,
7272 &calldata
->arg
.seq_args
,
7273 &calldata
->res
.seq_res
,
7277 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
7279 switch(task
->tk_status
) {
7281 case -NFS4ERR_COMPLETE_ALREADY
:
7282 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
7284 case -NFS4ERR_DELAY
:
7285 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
7287 case -NFS4ERR_RETRY_UNCACHED_REP
:
7290 nfs4_schedule_lease_recovery(clp
);
7295 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
7297 struct nfs4_reclaim_complete_data
*calldata
= data
;
7298 struct nfs_client
*clp
= calldata
->clp
;
7299 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
7301 dprintk("--> %s\n", __func__
);
7302 if (!nfs41_sequence_done(task
, res
))
7305 trace_nfs4_reclaim_complete(clp
, task
->tk_status
);
7306 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
7307 rpc_restart_call_prepare(task
);
7310 dprintk("<-- %s\n", __func__
);
7313 static void nfs4_free_reclaim_complete_data(void *data
)
7315 struct nfs4_reclaim_complete_data
*calldata
= data
;
7320 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
7321 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
7322 .rpc_call_done
= nfs4_reclaim_complete_done
,
7323 .rpc_release
= nfs4_free_reclaim_complete_data
,
7327 * Issue a global reclaim complete.
7329 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
,
7330 struct rpc_cred
*cred
)
7332 struct nfs4_reclaim_complete_data
*calldata
;
7333 struct rpc_task
*task
;
7334 struct rpc_message msg
= {
7335 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
7338 struct rpc_task_setup task_setup_data
= {
7339 .rpc_client
= clp
->cl_rpcclient
,
7340 .rpc_message
= &msg
,
7341 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
7342 .flags
= RPC_TASK_ASYNC
,
7344 int status
= -ENOMEM
;
7346 dprintk("--> %s\n", __func__
);
7347 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
7348 if (calldata
== NULL
)
7350 calldata
->clp
= clp
;
7351 calldata
->arg
.one_fs
= 0;
7353 nfs4_init_sequence(&calldata
->arg
.seq_args
, &calldata
->res
.seq_res
, 0);
7354 nfs4_set_sequence_privileged(&calldata
->arg
.seq_args
);
7355 msg
.rpc_argp
= &calldata
->arg
;
7356 msg
.rpc_resp
= &calldata
->res
;
7357 task_setup_data
.callback_data
= calldata
;
7358 task
= rpc_run_task(&task_setup_data
);
7360 status
= PTR_ERR(task
);
7363 status
= nfs4_wait_for_completion_rpc_task(task
);
7365 status
= task
->tk_status
;
7369 dprintk("<-- %s status=%d\n", __func__
, status
);
7374 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
7376 struct nfs4_layoutget
*lgp
= calldata
;
7377 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
7378 struct nfs4_session
*session
= nfs4_get_session(server
);
7380 dprintk("--> %s\n", __func__
);
7381 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
7382 * right now covering the LAYOUTGET we are about to send.
7383 * However, that is not so catastrophic, and there seems
7384 * to be no way to prevent it completely.
7386 if (nfs41_setup_sequence(session
, &lgp
->args
.seq_args
,
7387 &lgp
->res
.seq_res
, task
))
7389 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
7390 NFS_I(lgp
->args
.inode
)->layout
,
7391 lgp
->args
.ctx
->state
)) {
7392 rpc_exit(task
, NFS4_OK
);
7396 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
7398 struct nfs4_layoutget
*lgp
= calldata
;
7399 struct inode
*inode
= lgp
->args
.inode
;
7400 struct nfs_server
*server
= NFS_SERVER(inode
);
7401 struct pnfs_layout_hdr
*lo
;
7402 struct nfs4_state
*state
= NULL
;
7403 unsigned long timeo
, giveup
;
7405 dprintk("--> %s\n", __func__
);
7407 if (!nfs41_sequence_done(task
, &lgp
->res
.seq_res
))
7410 switch (task
->tk_status
) {
7413 case -NFS4ERR_LAYOUTTRYLATER
:
7414 case -NFS4ERR_RECALLCONFLICT
:
7415 timeo
= rpc_get_timeout(task
->tk_client
);
7416 giveup
= lgp
->args
.timestamp
+ timeo
;
7417 if (time_after(giveup
, jiffies
))
7418 task
->tk_status
= -NFS4ERR_DELAY
;
7420 case -NFS4ERR_EXPIRED
:
7421 case -NFS4ERR_BAD_STATEID
:
7422 spin_lock(&inode
->i_lock
);
7423 lo
= NFS_I(inode
)->layout
;
7424 if (!lo
|| list_empty(&lo
->plh_segs
)) {
7425 spin_unlock(&inode
->i_lock
);
7426 /* If the open stateid was bad, then recover it. */
7427 state
= lgp
->args
.ctx
->state
;
7431 pnfs_mark_matching_lsegs_invalid(lo
, &head
, NULL
);
7432 spin_unlock(&inode
->i_lock
);
7433 /* Mark the bad layout state as invalid, then
7434 * retry using the open stateid. */
7435 pnfs_free_lseg_list(&head
);
7438 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
7439 rpc_restart_call_prepare(task
);
7441 dprintk("<-- %s\n", __func__
);
7444 static size_t max_response_pages(struct nfs_server
*server
)
7446 u32 max_resp_sz
= server
->nfs_client
->cl_session
->fc_attrs
.max_resp_sz
;
7447 return nfs_page_array_len(0, max_resp_sz
);
7450 static void nfs4_free_pages(struct page
**pages
, size_t size
)
7457 for (i
= 0; i
< size
; i
++) {
7460 __free_page(pages
[i
]);
7465 static struct page
**nfs4_alloc_pages(size_t size
, gfp_t gfp_flags
)
7467 struct page
**pages
;
7470 pages
= kcalloc(size
, sizeof(struct page
*), gfp_flags
);
7472 dprintk("%s: can't alloc array of %zu pages\n", __func__
, size
);
7476 for (i
= 0; i
< size
; i
++) {
7477 pages
[i
] = alloc_page(gfp_flags
);
7479 dprintk("%s: failed to allocate page\n", __func__
);
7480 nfs4_free_pages(pages
, size
);
7488 static void nfs4_layoutget_release(void *calldata
)
7490 struct nfs4_layoutget
*lgp
= calldata
;
7491 struct inode
*inode
= lgp
->args
.inode
;
7492 struct nfs_server
*server
= NFS_SERVER(inode
);
7493 size_t max_pages
= max_response_pages(server
);
7495 dprintk("--> %s\n", __func__
);
7496 nfs4_free_pages(lgp
->args
.layout
.pages
, max_pages
);
7497 pnfs_put_layout_hdr(NFS_I(inode
)->layout
);
7498 put_nfs_open_context(lgp
->args
.ctx
);
7500 dprintk("<-- %s\n", __func__
);
7503 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
7504 .rpc_call_prepare
= nfs4_layoutget_prepare
,
7505 .rpc_call_done
= nfs4_layoutget_done
,
7506 .rpc_release
= nfs4_layoutget_release
,
7509 struct pnfs_layout_segment
*
7510 nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
, gfp_t gfp_flags
)
7512 struct inode
*inode
= lgp
->args
.inode
;
7513 struct nfs_server
*server
= NFS_SERVER(inode
);
7514 size_t max_pages
= max_response_pages(server
);
7515 struct rpc_task
*task
;
7516 struct rpc_message msg
= {
7517 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
7518 .rpc_argp
= &lgp
->args
,
7519 .rpc_resp
= &lgp
->res
,
7520 .rpc_cred
= lgp
->cred
,
7522 struct rpc_task_setup task_setup_data
= {
7523 .rpc_client
= server
->client
,
7524 .rpc_message
= &msg
,
7525 .callback_ops
= &nfs4_layoutget_call_ops
,
7526 .callback_data
= lgp
,
7527 .flags
= RPC_TASK_ASYNC
,
7529 struct pnfs_layout_segment
*lseg
= NULL
;
7532 dprintk("--> %s\n", __func__
);
7534 lgp
->args
.layout
.pages
= nfs4_alloc_pages(max_pages
, gfp_flags
);
7535 if (!lgp
->args
.layout
.pages
) {
7536 nfs4_layoutget_release(lgp
);
7537 return ERR_PTR(-ENOMEM
);
7539 lgp
->args
.layout
.pglen
= max_pages
* PAGE_SIZE
;
7540 lgp
->args
.timestamp
= jiffies
;
7542 lgp
->res
.layoutp
= &lgp
->args
.layout
;
7543 lgp
->res
.seq_res
.sr_slot
= NULL
;
7544 nfs4_init_sequence(&lgp
->args
.seq_args
, &lgp
->res
.seq_res
, 0);
7546 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
7547 pnfs_get_layout_hdr(NFS_I(inode
)->layout
);
7549 task
= rpc_run_task(&task_setup_data
);
7551 return ERR_CAST(task
);
7552 status
= nfs4_wait_for_completion_rpc_task(task
);
7554 status
= task
->tk_status
;
7555 trace_nfs4_layoutget(lgp
->args
.ctx
,
7559 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
7560 if (status
== 0 && lgp
->res
.layoutp
->len
)
7561 lseg
= pnfs_layout_process(lgp
);
7563 dprintk("<-- %s status=%d\n", __func__
, status
);
7565 return ERR_PTR(status
);
7570 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
7572 struct nfs4_layoutreturn
*lrp
= calldata
;
7574 dprintk("--> %s\n", __func__
);
7575 nfs41_setup_sequence(lrp
->clp
->cl_session
,
7576 &lrp
->args
.seq_args
,
7581 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
7583 struct nfs4_layoutreturn
*lrp
= calldata
;
7584 struct nfs_server
*server
;
7586 dprintk("--> %s\n", __func__
);
7588 if (!nfs41_sequence_done(task
, &lrp
->res
.seq_res
))
7591 server
= NFS_SERVER(lrp
->args
.inode
);
7592 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7593 rpc_restart_call_prepare(task
);
7596 dprintk("<-- %s\n", __func__
);
7599 static void nfs4_layoutreturn_release(void *calldata
)
7601 struct nfs4_layoutreturn
*lrp
= calldata
;
7602 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
7604 dprintk("--> %s\n", __func__
);
7605 spin_lock(&lo
->plh_inode
->i_lock
);
7606 if (lrp
->res
.lrs_present
)
7607 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
7608 lo
->plh_block_lgets
--;
7609 spin_unlock(&lo
->plh_inode
->i_lock
);
7610 pnfs_put_layout_hdr(lrp
->args
.layout
);
7612 dprintk("<-- %s\n", __func__
);
7615 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
7616 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
7617 .rpc_call_done
= nfs4_layoutreturn_done
,
7618 .rpc_release
= nfs4_layoutreturn_release
,
7621 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
7623 struct rpc_task
*task
;
7624 struct rpc_message msg
= {
7625 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
7626 .rpc_argp
= &lrp
->args
,
7627 .rpc_resp
= &lrp
->res
,
7628 .rpc_cred
= lrp
->cred
,
7630 struct rpc_task_setup task_setup_data
= {
7631 .rpc_client
= NFS_SERVER(lrp
->args
.inode
)->client
,
7632 .rpc_message
= &msg
,
7633 .callback_ops
= &nfs4_layoutreturn_call_ops
,
7634 .callback_data
= lrp
,
7638 dprintk("--> %s\n", __func__
);
7639 nfs4_init_sequence(&lrp
->args
.seq_args
, &lrp
->res
.seq_res
, 1);
7640 task
= rpc_run_task(&task_setup_data
);
7642 return PTR_ERR(task
);
7643 status
= task
->tk_status
;
7644 trace_nfs4_layoutreturn(lrp
->args
.inode
, status
);
7645 dprintk("<-- %s status=%d\n", __func__
, status
);
7651 * Retrieve the list of Data Server devices from the MDS.
7653 static int _nfs4_getdevicelist(struct nfs_server
*server
,
7654 const struct nfs_fh
*fh
,
7655 struct pnfs_devicelist
*devlist
)
7657 struct nfs4_getdevicelist_args args
= {
7659 .layoutclass
= server
->pnfs_curr_ld
->id
,
7661 struct nfs4_getdevicelist_res res
= {
7664 struct rpc_message msg
= {
7665 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
7671 dprintk("--> %s\n", __func__
);
7672 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
7674 dprintk("<-- %s status=%d\n", __func__
, status
);
7678 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
7679 const struct nfs_fh
*fh
,
7680 struct pnfs_devicelist
*devlist
)
7682 struct nfs4_exception exception
= { };
7686 err
= nfs4_handle_exception(server
,
7687 _nfs4_getdevicelist(server
, fh
, devlist
),
7689 } while (exception
.retry
);
7691 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
7692 err
, devlist
->num_devs
);
7696 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
7699 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7700 struct pnfs_device
*pdev
,
7701 struct rpc_cred
*cred
)
7703 struct nfs4_getdeviceinfo_args args
= {
7706 struct nfs4_getdeviceinfo_res res
= {
7709 struct rpc_message msg
= {
7710 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
7717 dprintk("--> %s\n", __func__
);
7718 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
7719 dprintk("<-- %s status=%d\n", __func__
, status
);
7724 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
,
7725 struct pnfs_device
*pdev
,
7726 struct rpc_cred
*cred
)
7728 struct nfs4_exception exception
= { };
7732 err
= nfs4_handle_exception(server
,
7733 _nfs4_proc_getdeviceinfo(server
, pdev
, cred
),
7735 } while (exception
.retry
);
7738 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
7740 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
7742 struct nfs4_layoutcommit_data
*data
= calldata
;
7743 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7744 struct nfs4_session
*session
= nfs4_get_session(server
);
7746 nfs41_setup_sequence(session
,
7747 &data
->args
.seq_args
,
7753 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
7755 struct nfs4_layoutcommit_data
*data
= calldata
;
7756 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
7758 if (!nfs41_sequence_done(task
, &data
->res
.seq_res
))
7761 switch (task
->tk_status
) { /* Just ignore these failures */
7762 case -NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
7763 case -NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
7764 case -NFS4ERR_BADLAYOUT
: /* no layout */
7765 case -NFS4ERR_GRACE
: /* loca_recalim always false */
7766 task
->tk_status
= 0;
7769 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
7773 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
7774 rpc_restart_call_prepare(task
);
7780 static void nfs4_layoutcommit_release(void *calldata
)
7782 struct nfs4_layoutcommit_data
*data
= calldata
;
7784 pnfs_cleanup_layoutcommit(data
);
7785 put_rpccred(data
->cred
);
7789 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
7790 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
7791 .rpc_call_done
= nfs4_layoutcommit_done
,
7792 .rpc_release
= nfs4_layoutcommit_release
,
7796 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
7798 struct rpc_message msg
= {
7799 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
7800 .rpc_argp
= &data
->args
,
7801 .rpc_resp
= &data
->res
,
7802 .rpc_cred
= data
->cred
,
7804 struct rpc_task_setup task_setup_data
= {
7805 .task
= &data
->task
,
7806 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
7807 .rpc_message
= &msg
,
7808 .callback_ops
= &nfs4_layoutcommit_ops
,
7809 .callback_data
= data
,
7810 .flags
= RPC_TASK_ASYNC
,
7812 struct rpc_task
*task
;
7815 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7816 "lbw: %llu inode %lu\n",
7817 data
->task
.tk_pid
, sync
,
7818 data
->args
.lastbytewritten
,
7819 data
->args
.inode
->i_ino
);
7821 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 1);
7822 task
= rpc_run_task(&task_setup_data
);
7824 return PTR_ERR(task
);
7827 status
= nfs4_wait_for_completion_rpc_task(task
);
7830 status
= task
->tk_status
;
7831 trace_nfs4_layoutcommit(data
->args
.inode
, status
);
7833 dprintk("%s: status %d\n", __func__
, status
);
7839 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7840 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7843 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7844 struct nfs_fsinfo
*info
,
7845 struct nfs4_secinfo_flavors
*flavors
, bool use_integrity
)
7847 struct nfs41_secinfo_no_name_args args
= {
7848 .style
= SECINFO_STYLE_CURRENT_FH
,
7850 struct nfs4_secinfo_res res
= {
7853 struct rpc_message msg
= {
7854 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
7858 struct rpc_clnt
*clnt
= server
->client
;
7859 struct rpc_cred
*cred
= NULL
;
7862 if (use_integrity
) {
7863 clnt
= server
->nfs_client
->cl_rpcclient
;
7864 cred
= nfs4_get_clid_cred(server
->nfs_client
);
7865 msg
.rpc_cred
= cred
;
7868 dprintk("--> %s\n", __func__
);
7869 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
,
7871 dprintk("<-- %s status=%d\n", __func__
, status
);
7880 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7881 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
7883 struct nfs4_exception exception
= { };
7886 /* first try using integrity protection */
7887 err
= -NFS4ERR_WRONGSEC
;
7889 /* try to use integrity protection with machine cred */
7890 if (_nfs4_is_integrity_protected(server
->nfs_client
))
7891 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
7895 * if unable to use integrity protection, or SECINFO with
7896 * integrity protection returns NFS4ERR_WRONGSEC (which is
7897 * disallowed by spec, but exists in deployed servers) use
7898 * the current filesystem's rpc_client and the user cred.
7900 if (err
== -NFS4ERR_WRONGSEC
)
7901 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
,
7906 case -NFS4ERR_WRONGSEC
:
7907 case -NFS4ERR_NOTSUPP
:
7910 err
= nfs4_handle_exception(server
, err
, &exception
);
7912 } while (exception
.retry
);
7918 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
7919 struct nfs_fsinfo
*info
)
7923 rpc_authflavor_t flavor
= RPC_AUTH_MAXFLAVOR
;
7924 struct nfs4_secinfo_flavors
*flavors
;
7925 struct nfs4_secinfo4
*secinfo
;
7928 page
= alloc_page(GFP_KERNEL
);
7934 flavors
= page_address(page
);
7935 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
7938 * Fall back on "guess and check" method if
7939 * the server doesn't support SECINFO_NO_NAME
7941 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
7942 err
= nfs4_find_root_sec(server
, fhandle
, info
);
7948 for (i
= 0; i
< flavors
->num_flavors
; i
++) {
7949 secinfo
= &flavors
->flavors
[i
];
7951 switch (secinfo
->flavor
) {
7955 flavor
= rpcauth_get_pseudoflavor(secinfo
->flavor
,
7956 &secinfo
->flavor_info
);
7959 flavor
= RPC_AUTH_MAXFLAVOR
;
7963 if (!nfs_auth_info_match(&server
->auth_info
, flavor
))
7964 flavor
= RPC_AUTH_MAXFLAVOR
;
7966 if (flavor
!= RPC_AUTH_MAXFLAVOR
) {
7967 err
= nfs4_lookup_root_sec(server
, fhandle
,
7974 if (flavor
== RPC_AUTH_MAXFLAVOR
)
7985 static int _nfs41_test_stateid(struct nfs_server
*server
,
7986 nfs4_stateid
*stateid
,
7987 struct rpc_cred
*cred
)
7990 struct nfs41_test_stateid_args args
= {
7993 struct nfs41_test_stateid_res res
;
7994 struct rpc_message msg
= {
7995 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
8000 struct rpc_clnt
*rpc_client
= server
->client
;
8002 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8005 dprintk("NFS call test_stateid %p\n", stateid
);
8006 nfs4_init_sequence(&args
.seq_args
, &res
.seq_res
, 0);
8007 nfs4_set_sequence_privileged(&args
.seq_args
);
8008 status
= nfs4_call_sync_sequence(rpc_client
, server
, &msg
,
8009 &args
.seq_args
, &res
.seq_res
);
8010 if (status
!= NFS_OK
) {
8011 dprintk("NFS reply test_stateid: failed, %d\n", status
);
8014 dprintk("NFS reply test_stateid: succeeded, %d\n", -res
.status
);
8019 * nfs41_test_stateid - perform a TEST_STATEID operation
8021 * @server: server / transport on which to perform the operation
8022 * @stateid: state ID to test
8025 * Returns NFS_OK if the server recognizes that "stateid" is valid.
8026 * Otherwise a negative NFS4ERR value is returned if the operation
8027 * failed or the state ID is not currently valid.
8029 static int nfs41_test_stateid(struct nfs_server
*server
,
8030 nfs4_stateid
*stateid
,
8031 struct rpc_cred
*cred
)
8033 struct nfs4_exception exception
= { };
8036 err
= _nfs41_test_stateid(server
, stateid
, cred
);
8037 if (err
!= -NFS4ERR_DELAY
)
8039 nfs4_handle_exception(server
, err
, &exception
);
8040 } while (exception
.retry
);
8044 struct nfs_free_stateid_data
{
8045 struct nfs_server
*server
;
8046 struct nfs41_free_stateid_args args
;
8047 struct nfs41_free_stateid_res res
;
8050 static void nfs41_free_stateid_prepare(struct rpc_task
*task
, void *calldata
)
8052 struct nfs_free_stateid_data
*data
= calldata
;
8053 nfs41_setup_sequence(nfs4_get_session(data
->server
),
8054 &data
->args
.seq_args
,
8059 static void nfs41_free_stateid_done(struct rpc_task
*task
, void *calldata
)
8061 struct nfs_free_stateid_data
*data
= calldata
;
8063 nfs41_sequence_done(task
, &data
->res
.seq_res
);
8065 switch (task
->tk_status
) {
8066 case -NFS4ERR_DELAY
:
8067 if (nfs4_async_handle_error(task
, data
->server
, NULL
) == -EAGAIN
)
8068 rpc_restart_call_prepare(task
);
8072 static void nfs41_free_stateid_release(void *calldata
)
8077 static const struct rpc_call_ops nfs41_free_stateid_ops
= {
8078 .rpc_call_prepare
= nfs41_free_stateid_prepare
,
8079 .rpc_call_done
= nfs41_free_stateid_done
,
8080 .rpc_release
= nfs41_free_stateid_release
,
8083 static struct rpc_task
*_nfs41_free_stateid(struct nfs_server
*server
,
8084 nfs4_stateid
*stateid
,
8085 struct rpc_cred
*cred
,
8088 struct rpc_message msg
= {
8089 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
8092 struct rpc_task_setup task_setup
= {
8093 .rpc_client
= server
->client
,
8094 .rpc_message
= &msg
,
8095 .callback_ops
= &nfs41_free_stateid_ops
,
8096 .flags
= RPC_TASK_ASYNC
,
8098 struct nfs_free_stateid_data
*data
;
8100 nfs4_state_protect(server
->nfs_client
, NFS_SP4_MACH_CRED_STATEID
,
8101 &task_setup
.rpc_client
, &msg
);
8103 dprintk("NFS call free_stateid %p\n", stateid
);
8104 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
8106 return ERR_PTR(-ENOMEM
);
8107 data
->server
= server
;
8108 nfs4_stateid_copy(&data
->args
.stateid
, stateid
);
8110 task_setup
.callback_data
= data
;
8112 msg
.rpc_argp
= &data
->args
;
8113 msg
.rpc_resp
= &data
->res
;
8114 nfs4_init_sequence(&data
->args
.seq_args
, &data
->res
.seq_res
, 0);
8116 nfs4_set_sequence_privileged(&data
->args
.seq_args
);
8118 return rpc_run_task(&task_setup
);
8122 * nfs41_free_stateid - perform a FREE_STATEID operation
8124 * @server: server / transport on which to perform the operation
8125 * @stateid: state ID to release
8128 * Returns NFS_OK if the server freed "stateid". Otherwise a
8129 * negative NFS4ERR value is returned.
8131 static int nfs41_free_stateid(struct nfs_server
*server
,
8132 nfs4_stateid
*stateid
,
8133 struct rpc_cred
*cred
)
8135 struct rpc_task
*task
;
8138 task
= _nfs41_free_stateid(server
, stateid
, cred
, true);
8140 return PTR_ERR(task
);
8141 ret
= rpc_wait_for_completion_task(task
);
8143 ret
= task
->tk_status
;
8148 static int nfs41_free_lock_state(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
)
8150 struct rpc_task
*task
;
8151 struct rpc_cred
*cred
= lsp
->ls_state
->owner
->so_cred
;
8153 task
= _nfs41_free_stateid(server
, &lsp
->ls_stateid
, cred
, false);
8154 nfs4_free_lock_state(server
, lsp
);
8156 return PTR_ERR(task
);
8161 static bool nfs41_match_stateid(const nfs4_stateid
*s1
,
8162 const nfs4_stateid
*s2
)
8164 if (memcmp(s1
->other
, s2
->other
, sizeof(s1
->other
)) != 0)
8167 if (s1
->seqid
== s2
->seqid
)
8169 if (s1
->seqid
== 0 || s2
->seqid
== 0)
8175 #endif /* CONFIG_NFS_V4_1 */
8177 static bool nfs4_match_stateid(const nfs4_stateid
*s1
,
8178 const nfs4_stateid
*s2
)
8180 return nfs4_stateid_match(s1
, s2
);
8184 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
8185 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8186 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8187 .recover_open
= nfs4_open_reclaim
,
8188 .recover_lock
= nfs4_lock_reclaim
,
8189 .establish_clid
= nfs4_init_clientid
,
8190 .detect_trunking
= nfs40_discover_server_trunking
,
8193 #if defined(CONFIG_NFS_V4_1)
8194 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
8195 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
8196 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
8197 .recover_open
= nfs4_open_reclaim
,
8198 .recover_lock
= nfs4_lock_reclaim
,
8199 .establish_clid
= nfs41_init_clientid
,
8200 .reclaim_complete
= nfs41_proc_reclaim_complete
,
8201 .detect_trunking
= nfs41_discover_server_trunking
,
8203 #endif /* CONFIG_NFS_V4_1 */
8205 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
8206 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8207 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8208 .recover_open
= nfs4_open_expired
,
8209 .recover_lock
= nfs4_lock_expired
,
8210 .establish_clid
= nfs4_init_clientid
,
8213 #if defined(CONFIG_NFS_V4_1)
8214 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
8215 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
8216 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
8217 .recover_open
= nfs41_open_expired
,
8218 .recover_lock
= nfs41_lock_expired
,
8219 .establish_clid
= nfs41_init_clientid
,
8221 #endif /* CONFIG_NFS_V4_1 */
8223 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
8224 .sched_state_renewal
= nfs4_proc_async_renew
,
8225 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
8226 .renew_lease
= nfs4_proc_renew
,
8229 #if defined(CONFIG_NFS_V4_1)
8230 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
8231 .sched_state_renewal
= nfs41_proc_async_sequence
,
8232 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
8233 .renew_lease
= nfs4_proc_sequence
,
8237 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops
= {
8238 .get_locations
= _nfs40_proc_get_locations
,
8239 .fsid_present
= _nfs40_proc_fsid_present
,
8242 #if defined(CONFIG_NFS_V4_1)
8243 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops
= {
8244 .get_locations
= _nfs41_proc_get_locations
,
8245 .fsid_present
= _nfs41_proc_fsid_present
,
8247 #endif /* CONFIG_NFS_V4_1 */
8249 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
8251 .init_caps
= NFS_CAP_READDIRPLUS
8252 | NFS_CAP_ATOMIC_OPEN
8253 | NFS_CAP_CHANGE_ATTR
8254 | NFS_CAP_POSIX_LOCK
,
8255 .init_client
= nfs40_init_client
,
8256 .shutdown_client
= nfs40_shutdown_client
,
8257 .match_stateid
= nfs4_match_stateid
,
8258 .find_root_sec
= nfs4_find_root_sec
,
8259 .free_lock_state
= nfs4_release_lockowner
,
8260 .call_sync_ops
= &nfs40_call_sync_ops
,
8261 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
8262 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
8263 .state_renewal_ops
= &nfs40_state_renewal_ops
,
8264 .mig_recovery_ops
= &nfs40_mig_recovery_ops
,
8267 #if defined(CONFIG_NFS_V4_1)
8268 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
8270 .init_caps
= NFS_CAP_READDIRPLUS
8271 | NFS_CAP_ATOMIC_OPEN
8272 | NFS_CAP_CHANGE_ATTR
8273 | NFS_CAP_POSIX_LOCK
8274 | NFS_CAP_STATEID_NFSV41
8275 | NFS_CAP_ATOMIC_OPEN_V1
,
8276 .init_client
= nfs41_init_client
,
8277 .shutdown_client
= nfs41_shutdown_client
,
8278 .match_stateid
= nfs41_match_stateid
,
8279 .find_root_sec
= nfs41_find_root_sec
,
8280 .free_lock_state
= nfs41_free_lock_state
,
8281 .call_sync_ops
= &nfs41_call_sync_ops
,
8282 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8283 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8284 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8285 .mig_recovery_ops
= &nfs41_mig_recovery_ops
,
8289 #if defined(CONFIG_NFS_V4_2)
8290 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops
= {
8292 .init_caps
= NFS_CAP_READDIRPLUS
8293 | NFS_CAP_ATOMIC_OPEN
8294 | NFS_CAP_CHANGE_ATTR
8295 | NFS_CAP_POSIX_LOCK
8296 | NFS_CAP_STATEID_NFSV41
8297 | NFS_CAP_ATOMIC_OPEN_V1
,
8298 .init_client
= nfs41_init_client
,
8299 .shutdown_client
= nfs41_shutdown_client
,
8300 .match_stateid
= nfs41_match_stateid
,
8301 .find_root_sec
= nfs41_find_root_sec
,
8302 .free_lock_state
= nfs41_free_lock_state
,
8303 .call_sync_ops
= &nfs41_call_sync_ops
,
8304 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
8305 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
8306 .state_renewal_ops
= &nfs41_state_renewal_ops
,
8310 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
8311 [0] = &nfs_v4_0_minor_ops
,
8312 #if defined(CONFIG_NFS_V4_1)
8313 [1] = &nfs_v4_1_minor_ops
,
8315 #if defined(CONFIG_NFS_V4_2)
8316 [2] = &nfs_v4_2_minor_ops
,
8320 static const struct inode_operations nfs4_dir_inode_operations
= {
8321 .create
= nfs_create
,
8322 .lookup
= nfs_lookup
,
8323 .atomic_open
= nfs_atomic_open
,
8325 .unlink
= nfs_unlink
,
8326 .symlink
= nfs_symlink
,
8330 .rename
= nfs_rename
,
8331 .permission
= nfs_permission
,
8332 .getattr
= nfs_getattr
,
8333 .setattr
= nfs_setattr
,
8334 .getxattr
= generic_getxattr
,
8335 .setxattr
= generic_setxattr
,
8336 .listxattr
= generic_listxattr
,
8337 .removexattr
= generic_removexattr
,
8340 static const struct inode_operations nfs4_file_inode_operations
= {
8341 .permission
= nfs_permission
,
8342 .getattr
= nfs_getattr
,
8343 .setattr
= nfs_setattr
,
8344 .getxattr
= generic_getxattr
,
8345 .setxattr
= generic_setxattr
,
8346 .listxattr
= generic_listxattr
,
8347 .removexattr
= generic_removexattr
,
8350 const struct nfs_rpc_ops nfs_v4_clientops
= {
8351 .version
= 4, /* protocol version */
8352 .dentry_ops
= &nfs4_dentry_operations
,
8353 .dir_inode_ops
= &nfs4_dir_inode_operations
,
8354 .file_inode_ops
= &nfs4_file_inode_operations
,
8355 .file_ops
= &nfs4_file_operations
,
8356 .getroot
= nfs4_proc_get_root
,
8357 .submount
= nfs4_submount
,
8358 .try_mount
= nfs4_try_mount
,
8359 .getattr
= nfs4_proc_getattr
,
8360 .setattr
= nfs4_proc_setattr
,
8361 .lookup
= nfs4_proc_lookup
,
8362 .access
= nfs4_proc_access
,
8363 .readlink
= nfs4_proc_readlink
,
8364 .create
= nfs4_proc_create
,
8365 .remove
= nfs4_proc_remove
,
8366 .unlink_setup
= nfs4_proc_unlink_setup
,
8367 .unlink_rpc_prepare
= nfs4_proc_unlink_rpc_prepare
,
8368 .unlink_done
= nfs4_proc_unlink_done
,
8369 .rename
= nfs4_proc_rename
,
8370 .rename_setup
= nfs4_proc_rename_setup
,
8371 .rename_rpc_prepare
= nfs4_proc_rename_rpc_prepare
,
8372 .rename_done
= nfs4_proc_rename_done
,
8373 .link
= nfs4_proc_link
,
8374 .symlink
= nfs4_proc_symlink
,
8375 .mkdir
= nfs4_proc_mkdir
,
8376 .rmdir
= nfs4_proc_remove
,
8377 .readdir
= nfs4_proc_readdir
,
8378 .mknod
= nfs4_proc_mknod
,
8379 .statfs
= nfs4_proc_statfs
,
8380 .fsinfo
= nfs4_proc_fsinfo
,
8381 .pathconf
= nfs4_proc_pathconf
,
8382 .set_capabilities
= nfs4_server_capabilities
,
8383 .decode_dirent
= nfs4_decode_dirent
,
8384 .read_setup
= nfs4_proc_read_setup
,
8385 .read_pageio_init
= pnfs_pageio_init_read
,
8386 .read_rpc_prepare
= nfs4_proc_read_rpc_prepare
,
8387 .read_done
= nfs4_read_done
,
8388 .write_setup
= nfs4_proc_write_setup
,
8389 .write_pageio_init
= pnfs_pageio_init_write
,
8390 .write_rpc_prepare
= nfs4_proc_write_rpc_prepare
,
8391 .write_done
= nfs4_write_done
,
8392 .commit_setup
= nfs4_proc_commit_setup
,
8393 .commit_rpc_prepare
= nfs4_proc_commit_rpc_prepare
,
8394 .commit_done
= nfs4_commit_done
,
8395 .lock
= nfs4_proc_lock
,
8396 .clear_acl_cache
= nfs4_zap_acl_attr
,
8397 .close_context
= nfs4_close_context
,
8398 .open_context
= nfs4_atomic_open
,
8399 .have_delegation
= nfs4_have_delegation
,
8400 .return_delegation
= nfs4_inode_return_delegation
,
8401 .alloc_client
= nfs4_alloc_client
,
8402 .init_client
= nfs4_init_client
,
8403 .free_client
= nfs4_free_client
,
8404 .create_server
= nfs4_create_server
,
8405 .clone_server
= nfs_clone_server
,
8408 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
8409 .prefix
= XATTR_NAME_NFSV4_ACL
,
8410 .list
= nfs4_xattr_list_nfs4_acl
,
8411 .get
= nfs4_xattr_get_nfs4_acl
,
8412 .set
= nfs4_xattr_set_nfs4_acl
,
8415 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
8416 &nfs4_xattr_nfs4_acl_handler
,
8417 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
8418 &nfs4_xattr_nfs4_label_handler
,