4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/ratelimit.h>
43 #include <linux/printk.h>
44 #include <linux/slab.h>
45 #include <linux/sunrpc/clnt.h>
46 #include <linux/nfs.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/nfs_page.h>
50 #include <linux/nfs_mount.h>
51 #include <linux/namei.h>
52 #include <linux/mount.h>
53 #include <linux/module.h>
54 #include <linux/nfs_idmap.h>
55 #include <linux/xattr.h>
56 #include <linux/utsname.h>
57 #include <linux/freezer.h>
60 #include "delegation.h"
66 #include "nfs4session.h"
69 #include "nfs4trace.h"
71 #define NFSDBG_FACILITY NFSDBG_PROC
73 #define NFS4_POLL_RETRY_MIN (HZ/10)
74 #define NFS4_POLL_RETRY_MAX (15*HZ)
77 static int _nfs4_proc_open(struct nfs4_opendata *data);
78 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
79 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
80 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
81 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
82 static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label);
83 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label);
84 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
85 struct nfs_fattr *fattr, struct iattr *sattr,
86 struct nfs4_state *state, struct nfs4_label *ilabel,
87 struct nfs4_label *olabel);
88 #ifdef CONFIG_NFS_V4_1
89 static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *,
91 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *,
95 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
96 static inline struct nfs4_label *
97 nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
98 struct iattr *sattr, struct nfs4_label *label)
105 if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0)
108 if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2)
111 err = security_dentry_init_security(dentry, sattr->ia_mode,
112 &dentry->d_name, (void **)&label->label, &label->len);
119 nfs4_label_release_security(struct nfs4_label *label)
122 security_release_secctx(label->label, label->len);
124 static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label)
127 return server->attr_bitmask;
129 return server->attr_bitmask_nl;
132 static inline struct nfs4_label *
133 nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
134 struct iattr *sattr, struct nfs4_label *l)
137 nfs4_label_release_security(struct nfs4_label *label)
140 nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label)
141 { return server->attr_bitmask; }
144 /* Prevent leaks of NFSv4 errors into userland */
145 static int nfs4_map_errors(int err)
150 case -NFS4ERR_RESOURCE:
151 case -NFS4ERR_LAYOUTTRYLATER:
152 case -NFS4ERR_RECALLCONFLICT:
154 case -NFS4ERR_WRONGSEC:
155 case -NFS4ERR_WRONG_CRED:
157 case -NFS4ERR_BADOWNER:
158 case -NFS4ERR_BADNAME:
160 case -NFS4ERR_SHARE_DENIED:
162 case -NFS4ERR_MINOR_VERS_MISMATCH:
163 return -EPROTONOSUPPORT;
164 case -NFS4ERR_ACCESS:
166 case -NFS4ERR_FILE_OPEN:
169 dprintk("%s could not handle NFSv4 error %d\n",
177 * This is our standard bitmap for GETATTR requests.
179 const u32 nfs4_fattr_bitmap[3] = {
181 | FATTR4_WORD0_CHANGE
184 | FATTR4_WORD0_FILEID,
186 | FATTR4_WORD1_NUMLINKS
188 | FATTR4_WORD1_OWNER_GROUP
189 | FATTR4_WORD1_RAWDEV
190 | FATTR4_WORD1_SPACE_USED
191 | FATTR4_WORD1_TIME_ACCESS
192 | FATTR4_WORD1_TIME_METADATA
193 | FATTR4_WORD1_TIME_MODIFY,
194 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
195 FATTR4_WORD2_SECURITY_LABEL
199 static const u32 nfs4_pnfs_open_bitmap[3] = {
201 | FATTR4_WORD0_CHANGE
204 | FATTR4_WORD0_FILEID,
206 | FATTR4_WORD1_NUMLINKS
208 | FATTR4_WORD1_OWNER_GROUP
209 | FATTR4_WORD1_RAWDEV
210 | FATTR4_WORD1_SPACE_USED
211 | FATTR4_WORD1_TIME_ACCESS
212 | FATTR4_WORD1_TIME_METADATA
213 | FATTR4_WORD1_TIME_MODIFY,
214 FATTR4_WORD2_MDSTHRESHOLD
217 static const u32 nfs4_open_noattr_bitmap[3] = {
219 | FATTR4_WORD0_CHANGE
220 | FATTR4_WORD0_FILEID,
223 const u32 nfs4_statfs_bitmap[3] = {
224 FATTR4_WORD0_FILES_AVAIL
225 | FATTR4_WORD0_FILES_FREE
226 | FATTR4_WORD0_FILES_TOTAL,
227 FATTR4_WORD1_SPACE_AVAIL
228 | FATTR4_WORD1_SPACE_FREE
229 | FATTR4_WORD1_SPACE_TOTAL
232 const u32 nfs4_pathconf_bitmap[3] = {
234 | FATTR4_WORD0_MAXNAME,
238 const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE
239 | FATTR4_WORD0_MAXREAD
240 | FATTR4_WORD0_MAXWRITE
241 | FATTR4_WORD0_LEASE_TIME,
242 FATTR4_WORD1_TIME_DELTA
243 | FATTR4_WORD1_FS_LAYOUT_TYPES,
244 FATTR4_WORD2_LAYOUT_BLKSIZE
247 const u32 nfs4_fs_locations_bitmap[3] = {
249 | FATTR4_WORD0_CHANGE
252 | FATTR4_WORD0_FILEID
253 | FATTR4_WORD0_FS_LOCATIONS,
255 | FATTR4_WORD1_NUMLINKS
257 | FATTR4_WORD1_OWNER_GROUP
258 | FATTR4_WORD1_RAWDEV
259 | FATTR4_WORD1_SPACE_USED
260 | FATTR4_WORD1_TIME_ACCESS
261 | FATTR4_WORD1_TIME_METADATA
262 | FATTR4_WORD1_TIME_MODIFY
263 | FATTR4_WORD1_MOUNTED_ON_FILEID,
266 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
267 struct nfs4_readdir_arg *readdir)
272 readdir->cookie = cookie;
273 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
278 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
283 * NFSv4 servers do not return entries for '.' and '..'
284 * Therefore, we fake these entries here. We let '.'
285 * have cookie 0 and '..' have cookie 1. Note that
286 * when talking to the server, we always send cookie 0
289 start = p = kmap_atomic(*readdir->pages);
292 *p++ = xdr_one; /* next */
293 *p++ = xdr_zero; /* cookie, first word */
294 *p++ = xdr_one; /* cookie, second word */
295 *p++ = xdr_one; /* entry len */
296 memcpy(p, ".\0\0\0", 4); /* entry */
298 *p++ = xdr_one; /* bitmap length */
299 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
300 *p++ = htonl(8); /* attribute buffer length */
301 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
304 *p++ = xdr_one; /* next */
305 *p++ = xdr_zero; /* cookie, first word */
306 *p++ = xdr_two; /* cookie, second word */
307 *p++ = xdr_two; /* entry len */
308 memcpy(p, "..\0\0", 4); /* entry */
310 *p++ = xdr_one; /* bitmap length */
311 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
312 *p++ = htonl(8); /* attribute buffer length */
313 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
315 readdir->pgbase = (char *)p - (char *)start;
316 readdir->count -= readdir->pgbase;
317 kunmap_atomic(start);
320 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
327 *timeout = NFS4_POLL_RETRY_MIN;
328 if (*timeout > NFS4_POLL_RETRY_MAX)
329 *timeout = NFS4_POLL_RETRY_MAX;
330 freezable_schedule_timeout_killable_unsafe(*timeout);
331 if (fatal_signal_pending(current))
337 /* This is the error handling routine for processes that are allowed
340 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
342 struct nfs_client *clp = server->nfs_client;
343 struct nfs4_state *state = exception->state;
344 struct inode *inode = exception->inode;
347 exception->retry = 0;
351 case -NFS4ERR_OPENMODE:
352 if (inode && nfs4_have_delegation(inode, FMODE_READ)) {
353 nfs4_inode_return_delegation(inode);
354 exception->retry = 1;
359 ret = nfs4_schedule_stateid_recovery(server, state);
362 goto wait_on_recovery;
363 case -NFS4ERR_DELEG_REVOKED:
364 case -NFS4ERR_ADMIN_REVOKED:
365 case -NFS4ERR_BAD_STATEID:
366 if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) {
367 nfs_remove_bad_delegation(inode);
368 exception->retry = 1;
373 ret = nfs4_schedule_stateid_recovery(server, state);
376 goto wait_on_recovery;
377 case -NFS4ERR_EXPIRED:
379 ret = nfs4_schedule_stateid_recovery(server, state);
383 case -NFS4ERR_STALE_STATEID:
384 case -NFS4ERR_STALE_CLIENTID:
385 nfs4_schedule_lease_recovery(clp);
386 goto wait_on_recovery;
388 ret = nfs4_schedule_migration_recovery(server);
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_DELEG_REVOKED:
1582 case -NFS4ERR_ADMIN_REVOKED:
1583 case -NFS4ERR_BAD_STATEID:
1584 case -NFS4ERR_OPENMODE:
1585 nfs_inode_find_state_and_recover(state->inode,
1587 nfs4_schedule_stateid_recovery(server, state);
1589 case -NFS4ERR_DELAY:
1590 case -NFS4ERR_GRACE:
1591 set_bit(NFS_DELEGATED_STATE, &state->flags);
1595 case -NFS4ERR_DENIED:
1596 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1602 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1604 struct nfs_server *server = NFS_SERVER(state->inode);
1605 struct nfs4_opendata *opendata;
1608 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1609 NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1610 if (IS_ERR(opendata))
1611 return PTR_ERR(opendata);
1612 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1613 err = nfs4_open_recover(opendata, state);
1614 nfs4_opendata_put(opendata);
1615 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
1618 static void nfs4_open_confirm_prepare(struct rpc_task *task, void *calldata)
1620 struct nfs4_opendata *data = calldata;
1622 nfs40_setup_sequence(data->o_arg.server, &data->o_arg.seq_args,
1623 &data->o_res.seq_res, task);
1626 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1628 struct nfs4_opendata *data = calldata;
1630 nfs40_sequence_done(task, &data->o_res.seq_res);
1632 data->rpc_status = task->tk_status;
1633 if (data->rpc_status == 0) {
1634 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1635 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1636 renew_lease(data->o_res.server, data->timestamp);
1641 static void nfs4_open_confirm_release(void *calldata)
1643 struct nfs4_opendata *data = calldata;
1644 struct nfs4_state *state = NULL;
1646 /* If this request hasn't been cancelled, do nothing */
1647 if (data->cancelled == 0)
1649 /* In case of error, no cleanup! */
1650 if (!data->rpc_done)
1652 state = nfs4_opendata_to_nfs4_state(data);
1654 nfs4_close_state(state, data->o_arg.fmode);
1656 nfs4_opendata_put(data);
1659 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1660 .rpc_call_prepare = nfs4_open_confirm_prepare,
1661 .rpc_call_done = nfs4_open_confirm_done,
1662 .rpc_release = nfs4_open_confirm_release,
1666 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1668 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1670 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1671 struct rpc_task *task;
1672 struct rpc_message msg = {
1673 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1674 .rpc_argp = &data->c_arg,
1675 .rpc_resp = &data->c_res,
1676 .rpc_cred = data->owner->so_cred,
1678 struct rpc_task_setup task_setup_data = {
1679 .rpc_client = server->client,
1680 .rpc_message = &msg,
1681 .callback_ops = &nfs4_open_confirm_ops,
1682 .callback_data = data,
1683 .workqueue = nfsiod_workqueue,
1684 .flags = RPC_TASK_ASYNC,
1688 nfs4_init_sequence(&data->o_arg.seq_args, &data->o_res.seq_res, 1);
1689 kref_get(&data->kref);
1691 data->rpc_status = 0;
1692 data->timestamp = jiffies;
1693 task = rpc_run_task(&task_setup_data);
1695 return PTR_ERR(task);
1696 status = nfs4_wait_for_completion_rpc_task(task);
1698 data->cancelled = 1;
1701 status = data->rpc_status;
1706 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1708 struct nfs4_opendata *data = calldata;
1709 struct nfs4_state_owner *sp = data->owner;
1710 struct nfs_client *clp = sp->so_server->nfs_client;
1712 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1715 * Check if we still need to send an OPEN call, or if we can use
1716 * a delegation instead.
1718 if (data->state != NULL) {
1719 struct nfs_delegation *delegation;
1721 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1724 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1725 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1726 data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH &&
1727 can_open_delegated(delegation, data->o_arg.fmode))
1728 goto unlock_no_action;
1731 /* Update client id. */
1732 data->o_arg.clientid = clp->cl_clientid;
1733 switch (data->o_arg.claim) {
1734 case NFS4_OPEN_CLAIM_PREVIOUS:
1735 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1736 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
1737 data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1738 case NFS4_OPEN_CLAIM_FH:
1739 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1740 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1742 data->timestamp = jiffies;
1743 if (nfs4_setup_sequence(data->o_arg.server,
1744 &data->o_arg.seq_args,
1745 &data->o_res.seq_res,
1747 nfs_release_seqid(data->o_arg.seqid);
1749 /* Set the create mode (note dependency on the session type) */
1750 data->o_arg.createmode = NFS4_CREATE_UNCHECKED;
1751 if (data->o_arg.open_flags & O_EXCL) {
1752 data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE;
1753 if (nfs4_has_persistent_session(clp))
1754 data->o_arg.createmode = NFS4_CREATE_GUARDED;
1755 else if (clp->cl_mvops->minor_version > 0)
1756 data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1;
1762 task->tk_action = NULL;
1764 nfs4_sequence_done(task, &data->o_res.seq_res);
1767 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1769 struct nfs4_opendata *data = calldata;
1771 data->rpc_status = task->tk_status;
1773 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1776 if (task->tk_status == 0) {
1777 if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) {
1778 switch (data->o_res.f_attr->mode & S_IFMT) {
1782 data->rpc_status = -ELOOP;
1785 data->rpc_status = -EISDIR;
1788 data->rpc_status = -ENOTDIR;
1791 renew_lease(data->o_res.server, data->timestamp);
1792 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1793 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1798 static void nfs4_open_release(void *calldata)
1800 struct nfs4_opendata *data = calldata;
1801 struct nfs4_state *state = NULL;
1803 /* If this request hasn't been cancelled, do nothing */
1804 if (data->cancelled == 0)
1806 /* In case of error, no cleanup! */
1807 if (data->rpc_status != 0 || !data->rpc_done)
1809 /* In case we need an open_confirm, no cleanup! */
1810 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1812 state = nfs4_opendata_to_nfs4_state(data);
1814 nfs4_close_state(state, data->o_arg.fmode);
1816 nfs4_opendata_put(data);
1819 static const struct rpc_call_ops nfs4_open_ops = {
1820 .rpc_call_prepare = nfs4_open_prepare,
1821 .rpc_call_done = nfs4_open_done,
1822 .rpc_release = nfs4_open_release,
1825 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1827 struct inode *dir = data->dir->d_inode;
1828 struct nfs_server *server = NFS_SERVER(dir);
1829 struct nfs_openargs *o_arg = &data->o_arg;
1830 struct nfs_openres *o_res = &data->o_res;
1831 struct rpc_task *task;
1832 struct rpc_message msg = {
1833 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1836 .rpc_cred = data->owner->so_cred,
1838 struct rpc_task_setup task_setup_data = {
1839 .rpc_client = server->client,
1840 .rpc_message = &msg,
1841 .callback_ops = &nfs4_open_ops,
1842 .callback_data = data,
1843 .workqueue = nfsiod_workqueue,
1844 .flags = RPC_TASK_ASYNC,
1848 nfs4_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1849 kref_get(&data->kref);
1851 data->rpc_status = 0;
1852 data->cancelled = 0;
1853 data->is_recover = 0;
1855 nfs4_set_sequence_privileged(&o_arg->seq_args);
1856 data->is_recover = 1;
1858 task = rpc_run_task(&task_setup_data);
1860 return PTR_ERR(task);
1861 status = nfs4_wait_for_completion_rpc_task(task);
1863 data->cancelled = 1;
1866 status = data->rpc_status;
1872 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1874 struct inode *dir = data->dir->d_inode;
1875 struct nfs_openres *o_res = &data->o_res;
1878 status = nfs4_run_open_task(data, 1);
1879 if (status != 0 || !data->rpc_done)
1882 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1884 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1885 status = _nfs4_proc_open_confirm(data);
1893 static int nfs4_opendata_access(struct rpc_cred *cred,
1894 struct nfs4_opendata *opendata,
1895 struct nfs4_state *state, fmode_t fmode,
1898 struct nfs_access_entry cache;
1901 /* access call failed or for some reason the server doesn't
1902 * support any access modes -- defer access call until later */
1903 if (opendata->o_res.access_supported == 0)
1907 /* don't check MAY_WRITE - a newly created file may not have
1908 * write mode bits, but POSIX allows the creating process to write.
1909 * use openflags to check for exec, because fmode won't
1910 * always have FMODE_EXEC set when file open for exec. */
1911 if (openflags & __FMODE_EXEC) {
1912 /* ONLY check for exec rights */
1914 } else if (fmode & FMODE_READ)
1918 cache.jiffies = jiffies;
1919 nfs_access_set_mask(&cache, opendata->o_res.access_result);
1920 nfs_access_add_cache(state->inode, &cache);
1922 if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0)
1925 /* even though OPEN succeeded, access is denied. Close the file */
1926 nfs4_close_state(state, fmode);
1931 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1933 static int _nfs4_proc_open(struct nfs4_opendata *data)
1935 struct inode *dir = data->dir->d_inode;
1936 struct nfs_server *server = NFS_SERVER(dir);
1937 struct nfs_openargs *o_arg = &data->o_arg;
1938 struct nfs_openres *o_res = &data->o_res;
1941 status = nfs4_run_open_task(data, 0);
1942 if (!data->rpc_done)
1945 if (status == -NFS4ERR_BADNAME &&
1946 !(o_arg->open_flags & O_CREAT))
1951 nfs_fattr_map_and_free_names(server, &data->f_attr);
1953 if (o_arg->open_flags & O_CREAT) {
1954 update_changeattr(dir, &o_res->cinfo);
1955 if (o_arg->open_flags & O_EXCL)
1956 data->file_created = 1;
1957 else if (o_res->cinfo.before != o_res->cinfo.after)
1958 data->file_created = 1;
1960 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1961 server->caps &= ~NFS_CAP_POSIX_LOCK;
1962 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1963 status = _nfs4_proc_open_confirm(data);
1967 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1968 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label);
1972 static int nfs4_recover_expired_lease(struct nfs_server *server)
1974 return nfs4_client_recover_expired_lease(server->nfs_client);
1979 * reclaim state on the server after a network partition.
1980 * Assumes caller holds the appropriate lock
1982 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1984 struct nfs4_opendata *opendata;
1987 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1988 NFS4_OPEN_CLAIM_FH);
1989 if (IS_ERR(opendata))
1990 return PTR_ERR(opendata);
1991 ret = nfs4_open_recover(opendata, state);
1993 d_drop(ctx->dentry);
1994 nfs4_opendata_put(opendata);
1998 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
2000 struct nfs_server *server = NFS_SERVER(state->inode);
2001 struct nfs4_exception exception = { };
2005 err = _nfs4_open_expired(ctx, state);
2006 trace_nfs4_open_expired(ctx, 0, err);
2007 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
2012 case -NFS4ERR_GRACE:
2013 case -NFS4ERR_DELAY:
2014 nfs4_handle_exception(server, err, &exception);
2017 } while (exception.retry);
2022 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
2024 struct nfs_open_context *ctx;
2027 ctx = nfs4_state_find_open_context(state);
2030 ret = nfs4_do_open_expired(ctx, state);
2031 put_nfs_open_context(ctx);
2035 #if defined(CONFIG_NFS_V4_1)
2036 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
2038 struct nfs_server *server = NFS_SERVER(state->inode);
2039 nfs4_stateid *stateid = &state->stateid;
2040 struct nfs_delegation *delegation;
2041 struct rpc_cred *cred = NULL;
2042 int status = -NFS4ERR_BAD_STATEID;
2044 /* If a state reset has been done, test_stateid is unneeded */
2045 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
2048 /* Get the delegation credential for use by test/free_stateid */
2050 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
2051 if (delegation != NULL &&
2052 nfs4_stateid_match(&delegation->stateid, stateid)) {
2053 cred = get_rpccred(delegation->cred);
2055 status = nfs41_test_stateid(server, stateid, cred);
2056 trace_nfs4_test_delegation_stateid(state, NULL, status);
2060 if (status != NFS_OK) {
2061 /* Free the stateid unless the server explicitly
2062 * informs us the stateid is unrecognized. */
2063 if (status != -NFS4ERR_BAD_STATEID)
2064 nfs41_free_stateid(server, stateid, cred);
2065 nfs_remove_bad_delegation(state->inode);
2067 write_seqlock(&state->seqlock);
2068 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
2069 write_sequnlock(&state->seqlock);
2070 clear_bit(NFS_DELEGATED_STATE, &state->flags);
2078 * nfs41_check_open_stateid - possibly free an open stateid
2080 * @state: NFSv4 state for an inode
2082 * Returns NFS_OK if recovery for this stateid is now finished.
2083 * Otherwise a negative NFS4ERR value is returned.
2085 static int nfs41_check_open_stateid(struct nfs4_state *state)
2087 struct nfs_server *server = NFS_SERVER(state->inode);
2088 nfs4_stateid *stateid = &state->open_stateid;
2089 struct rpc_cred *cred = state->owner->so_cred;
2092 /* If a state reset has been done, test_stateid is unneeded */
2093 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
2094 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
2095 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
2096 return -NFS4ERR_BAD_STATEID;
2098 status = nfs41_test_stateid(server, stateid, cred);
2099 trace_nfs4_test_open_stateid(state, NULL, status);
2100 if (status != NFS_OK) {
2101 /* Free the stateid unless the server explicitly
2102 * informs us the stateid is unrecognized. */
2103 if (status != -NFS4ERR_BAD_STATEID)
2104 nfs41_free_stateid(server, stateid, cred);
2106 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2107 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2108 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2109 clear_bit(NFS_OPEN_STATE, &state->flags);
2114 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
2118 nfs41_clear_delegation_stateid(state);
2119 status = nfs41_check_open_stateid(state);
2120 if (status != NFS_OK)
2121 status = nfs4_open_expired(sp, state);
2127 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2128 * fields corresponding to attributes that were used to store the verifier.
2129 * Make sure we clobber those fields in the later setattr call
2131 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
2133 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
2134 !(sattr->ia_valid & ATTR_ATIME_SET))
2135 sattr->ia_valid |= ATTR_ATIME;
2137 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
2138 !(sattr->ia_valid & ATTR_MTIME_SET))
2139 sattr->ia_valid |= ATTR_MTIME;
2142 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2145 struct nfs_open_context *ctx)
2147 struct nfs4_state_owner *sp = opendata->owner;
2148 struct nfs_server *server = sp->so_server;
2149 struct dentry *dentry;
2150 struct nfs4_state *state;
2154 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
2156 ret = _nfs4_proc_open(opendata);
2160 state = nfs4_opendata_to_nfs4_state(opendata);
2161 ret = PTR_ERR(state);
2164 if (server->caps & NFS_CAP_POSIX_LOCK)
2165 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
2167 dentry = opendata->dentry;
2168 if (dentry->d_inode == NULL) {
2169 /* FIXME: Is this d_drop() ever needed? */
2171 dentry = d_add_unique(dentry, igrab(state->inode));
2172 if (dentry == NULL) {
2173 dentry = opendata->dentry;
2174 } else if (dentry != ctx->dentry) {
2176 ctx->dentry = dget(dentry);
2178 nfs_set_verifier(dentry,
2179 nfs_save_change_attribute(opendata->dir->d_inode));
2182 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
2187 if (dentry->d_inode == state->inode) {
2188 nfs_inode_attach_open_context(ctx);
2189 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
2190 nfs4_schedule_stateid_recovery(server, state);
2197 * Returns a referenced nfs4_state
2199 static int _nfs4_do_open(struct inode *dir,
2200 struct nfs_open_context *ctx,
2202 struct iattr *sattr,
2203 struct nfs4_label *label,
2206 struct nfs4_state_owner *sp;
2207 struct nfs4_state *state = NULL;
2208 struct nfs_server *server = NFS_SERVER(dir);
2209 struct nfs4_opendata *opendata;
2210 struct dentry *dentry = ctx->dentry;
2211 struct rpc_cred *cred = ctx->cred;
2212 struct nfs4_threshold **ctx_th = &ctx->mdsthreshold;
2213 fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC);
2214 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
2215 struct nfs4_label *olabel = NULL;
2218 /* Protect against reboot recovery conflicts */
2220 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
2222 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2225 status = nfs4_recover_expired_lease(server);
2227 goto err_put_state_owner;
2228 if (dentry->d_inode != NULL)
2229 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
2231 if (dentry->d_inode)
2232 claim = NFS4_OPEN_CLAIM_FH;
2233 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
2234 label, claim, GFP_KERNEL);
2235 if (opendata == NULL)
2236 goto err_put_state_owner;
2239 olabel = nfs4_label_alloc(server, GFP_KERNEL);
2240 if (IS_ERR(olabel)) {
2241 status = PTR_ERR(olabel);
2242 goto err_opendata_put;
2246 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
2247 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
2248 if (!opendata->f_attr.mdsthreshold)
2249 goto err_free_label;
2250 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
2252 if (dentry->d_inode != NULL)
2253 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
2255 status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx);
2257 goto err_free_label;
2260 if ((opendata->o_arg.open_flags & O_EXCL) &&
2261 (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) {
2262 nfs4_exclusive_attrset(opendata, sattr);
2264 nfs_fattr_init(opendata->o_res.f_attr);
2265 status = nfs4_do_setattr(state->inode, cred,
2266 opendata->o_res.f_attr, sattr,
2267 state, label, olabel);
2269 nfs_setattr_update_inode(state->inode, sattr);
2270 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
2271 nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel);
2274 if (opendata->file_created)
2275 *opened |= FILE_CREATED;
2277 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
2278 *ctx_th = opendata->f_attr.mdsthreshold;
2280 kfree(opendata->f_attr.mdsthreshold);
2281 opendata->f_attr.mdsthreshold = NULL;
2283 nfs4_label_free(olabel);
2285 nfs4_opendata_put(opendata);
2286 nfs4_put_state_owner(sp);
2289 nfs4_label_free(olabel);
2291 kfree(opendata->f_attr.mdsthreshold);
2292 nfs4_opendata_put(opendata);
2293 err_put_state_owner:
2294 nfs4_put_state_owner(sp);
2300 static struct nfs4_state *nfs4_do_open(struct inode *dir,
2301 struct nfs_open_context *ctx,
2303 struct iattr *sattr,
2304 struct nfs4_label *label,
2307 struct nfs_server *server = NFS_SERVER(dir);
2308 struct nfs4_exception exception = { };
2309 struct nfs4_state *res;
2313 status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened);
2315 trace_nfs4_open_file(ctx, flags, status);
2318 /* NOTE: BAD_SEQID means the server and client disagree about the
2319 * book-keeping w.r.t. state-changing operations
2320 * (OPEN/CLOSE/LOCK/LOCKU...)
2321 * It is actually a sign of a bug on the client or on the server.
2323 * If we receive a BAD_SEQID error in the particular case of
2324 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2325 * have unhashed the old state_owner for us, and that we can
2326 * therefore safely retry using a new one. We should still warn
2327 * the user though...
2329 if (status == -NFS4ERR_BAD_SEQID) {
2330 pr_warn_ratelimited("NFS: v4 server %s "
2331 " returned a bad sequence-id error!\n",
2332 NFS_SERVER(dir)->nfs_client->cl_hostname);
2333 exception.retry = 1;
2337 * BAD_STATEID on OPEN means that the server cancelled our
2338 * state before it received the OPEN_CONFIRM.
2339 * Recover by retrying the request as per the discussion
2340 * on Page 181 of RFC3530.
2342 if (status == -NFS4ERR_BAD_STATEID) {
2343 exception.retry = 1;
2346 if (status == -EAGAIN) {
2347 /* We must have found a delegation */
2348 exception.retry = 1;
2351 if (nfs4_clear_cap_atomic_open_v1(server, status, &exception))
2353 res = ERR_PTR(nfs4_handle_exception(server,
2354 status, &exception));
2355 } while (exception.retry);
2359 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2360 struct nfs_fattr *fattr, struct iattr *sattr,
2361 struct nfs4_state *state, struct nfs4_label *ilabel,
2362 struct nfs4_label *olabel)
2364 struct nfs_server *server = NFS_SERVER(inode);
2365 struct nfs_setattrargs arg = {
2366 .fh = NFS_FH(inode),
2369 .bitmask = server->attr_bitmask,
2372 struct nfs_setattrres res = {
2377 struct rpc_message msg = {
2378 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2383 unsigned long timestamp = jiffies;
2388 arg.bitmask = nfs4_bitmask(server, ilabel);
2390 arg.bitmask = nfs4_bitmask(server, olabel);
2392 nfs_fattr_init(fattr);
2394 /* Servers should only apply open mode checks for file size changes */
2395 truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false;
2396 fmode = truncate ? FMODE_WRITE : FMODE_READ;
2398 if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
2399 /* Use that stateid */
2400 } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) {
2401 struct nfs_lockowner lockowner = {
2402 .l_owner = current->files,
2403 .l_pid = current->tgid,
2405 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2408 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2410 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2411 if (status == 0 && state != NULL)
2412 renew_lease(server, timestamp);
2416 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2417 struct nfs_fattr *fattr, struct iattr *sattr,
2418 struct nfs4_state *state, struct nfs4_label *ilabel,
2419 struct nfs4_label *olabel)
2421 struct nfs_server *server = NFS_SERVER(inode);
2422 struct nfs4_exception exception = {
2428 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel);
2429 trace_nfs4_setattr(inode, err);
2431 case -NFS4ERR_OPENMODE:
2432 if (!(sattr->ia_valid & ATTR_SIZE)) {
2433 pr_warn_once("NFSv4: server %s is incorrectly "
2434 "applying open mode checks to "
2435 "a SETATTR that is not "
2436 "changing file size.\n",
2437 server->nfs_client->cl_hostname);
2439 if (state && !(state->state & FMODE_WRITE)) {
2441 if (sattr->ia_valid & ATTR_OPEN)
2446 err = nfs4_handle_exception(server, err, &exception);
2447 } while (exception.retry);
2452 struct nfs4_closedata {
2453 struct inode *inode;
2454 struct nfs4_state *state;
2455 struct nfs_closeargs arg;
2456 struct nfs_closeres res;
2457 struct nfs_fattr fattr;
2458 unsigned long timestamp;
2463 static void nfs4_free_closedata(void *data)
2465 struct nfs4_closedata *calldata = data;
2466 struct nfs4_state_owner *sp = calldata->state->owner;
2467 struct super_block *sb = calldata->state->inode->i_sb;
2470 pnfs_roc_release(calldata->state->inode);
2471 nfs4_put_open_state(calldata->state);
2472 nfs_free_seqid(calldata->arg.seqid);
2473 nfs4_put_state_owner(sp);
2474 nfs_sb_deactive(sb);
2478 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2481 spin_lock(&state->owner->so_lock);
2482 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2483 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
2485 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2488 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2491 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2492 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2493 clear_bit(NFS_OPEN_STATE, &state->flags);
2495 spin_unlock(&state->owner->so_lock);
2498 static void nfs4_close_done(struct rpc_task *task, void *data)
2500 struct nfs4_closedata *calldata = data;
2501 struct nfs4_state *state = calldata->state;
2502 struct nfs_server *server = NFS_SERVER(calldata->inode);
2504 dprintk("%s: begin!\n", __func__);
2505 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2507 trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status);
2508 /* hmm. we are done with the inode, and in the process of freeing
2509 * the state_owner. we keep this around to process errors
2511 switch (task->tk_status) {
2514 pnfs_roc_set_barrier(state->inode,
2515 calldata->roc_barrier);
2516 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2517 renew_lease(server, calldata->timestamp);
2518 nfs4_close_clear_stateid_flags(state,
2519 calldata->arg.fmode);
2521 case -NFS4ERR_STALE_STATEID:
2522 case -NFS4ERR_OLD_STATEID:
2523 case -NFS4ERR_BAD_STATEID:
2524 case -NFS4ERR_EXPIRED:
2525 if (calldata->arg.fmode == 0)
2528 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2529 rpc_restart_call_prepare(task);
2531 nfs_release_seqid(calldata->arg.seqid);
2532 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2533 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2536 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2538 struct nfs4_closedata *calldata = data;
2539 struct nfs4_state *state = calldata->state;
2540 struct inode *inode = calldata->inode;
2543 dprintk("%s: begin!\n", __func__);
2544 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2547 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2548 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2549 spin_lock(&state->owner->so_lock);
2550 /* Calculate the change in open mode */
2551 if (state->n_rdwr == 0) {
2552 if (state->n_rdonly == 0) {
2553 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2554 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2555 calldata->arg.fmode &= ~FMODE_READ;
2557 if (state->n_wronly == 0) {
2558 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2559 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2560 calldata->arg.fmode &= ~FMODE_WRITE;
2563 if (!nfs4_valid_open_stateid(state))
2565 spin_unlock(&state->owner->so_lock);
2568 /* Note: exit _without_ calling nfs4_close_done */
2572 if (calldata->arg.fmode == 0) {
2573 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2574 if (calldata->roc &&
2575 pnfs_roc_drain(inode, &calldata->roc_barrier, task)) {
2576 nfs_release_seqid(calldata->arg.seqid);
2581 nfs_fattr_init(calldata->res.fattr);
2582 calldata->timestamp = jiffies;
2583 if (nfs4_setup_sequence(NFS_SERVER(inode),
2584 &calldata->arg.seq_args,
2585 &calldata->res.seq_res,
2587 nfs_release_seqid(calldata->arg.seqid);
2588 dprintk("%s: done!\n", __func__);
2591 task->tk_action = NULL;
2593 nfs4_sequence_done(task, &calldata->res.seq_res);
2596 static const struct rpc_call_ops nfs4_close_ops = {
2597 .rpc_call_prepare = nfs4_close_prepare,
2598 .rpc_call_done = nfs4_close_done,
2599 .rpc_release = nfs4_free_closedata,
2603 * It is possible for data to be read/written from a mem-mapped file
2604 * after the sys_close call (which hits the vfs layer as a flush).
2605 * This means that we can't safely call nfsv4 close on a file until
2606 * the inode is cleared. This in turn means that we are not good
2607 * NFSv4 citizens - we do not indicate to the server to update the file's
2608 * share state even when we are done with one of the three share
2609 * stateid's in the inode.
2611 * NOTE: Caller must be holding the sp->so_owner semaphore!
2613 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
2615 struct nfs_server *server = NFS_SERVER(state->inode);
2616 struct nfs4_closedata *calldata;
2617 struct nfs4_state_owner *sp = state->owner;
2618 struct rpc_task *task;
2619 struct rpc_message msg = {
2620 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2621 .rpc_cred = state->owner->so_cred,
2623 struct rpc_task_setup task_setup_data = {
2624 .rpc_client = server->client,
2625 .rpc_message = &msg,
2626 .callback_ops = &nfs4_close_ops,
2627 .workqueue = nfsiod_workqueue,
2628 .flags = RPC_TASK_ASYNC,
2630 int status = -ENOMEM;
2632 nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_CLEANUP,
2633 &task_setup_data.rpc_client, &msg);
2635 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2636 if (calldata == NULL)
2638 nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2639 calldata->inode = state->inode;
2640 calldata->state = state;
2641 calldata->arg.fh = NFS_FH(state->inode);
2642 calldata->arg.stateid = &state->open_stateid;
2643 /* Serialization for the sequence id */
2644 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2645 if (calldata->arg.seqid == NULL)
2646 goto out_free_calldata;
2647 calldata->arg.fmode = 0;
2648 calldata->arg.bitmask = server->cache_consistency_bitmask;
2649 calldata->res.fattr = &calldata->fattr;
2650 calldata->res.seqid = calldata->arg.seqid;
2651 calldata->res.server = server;
2652 calldata->roc = pnfs_roc(state->inode);
2653 nfs_sb_active(calldata->inode->i_sb);
2655 msg.rpc_argp = &calldata->arg;
2656 msg.rpc_resp = &calldata->res;
2657 task_setup_data.callback_data = calldata;
2658 task = rpc_run_task(&task_setup_data);
2660 return PTR_ERR(task);
2663 status = rpc_wait_for_completion_task(task);
2669 nfs4_put_open_state(state);
2670 nfs4_put_state_owner(sp);
2674 static struct inode *
2675 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx,
2676 int open_flags, struct iattr *attr, int *opened)
2678 struct nfs4_state *state;
2679 struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL;
2681 label = nfs4_label_init_security(dir, ctx->dentry, attr, &l);
2683 /* Protect against concurrent sillydeletes */
2684 state = nfs4_do_open(dir, ctx, open_flags, attr, label, opened);
2686 nfs4_label_release_security(label);
2689 return ERR_CAST(state);
2690 return state->inode;
2693 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2695 if (ctx->state == NULL)
2698 nfs4_close_sync(ctx->state, ctx->mode);
2700 nfs4_close_state(ctx->state, ctx->mode);
2703 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2705 struct nfs4_server_caps_arg args = {
2708 struct nfs4_server_caps_res res = {};
2709 struct rpc_message msg = {
2710 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2716 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2718 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2719 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2720 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2721 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2722 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2723 NFS_CAP_CTIME|NFS_CAP_MTIME);
2724 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2725 server->caps |= NFS_CAP_ACLS;
2726 if (res.has_links != 0)
2727 server->caps |= NFS_CAP_HARDLINKS;
2728 if (res.has_symlinks != 0)
2729 server->caps |= NFS_CAP_SYMLINKS;
2730 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2731 server->caps |= NFS_CAP_FILEID;
2732 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2733 server->caps |= NFS_CAP_MODE;
2734 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2735 server->caps |= NFS_CAP_NLINK;
2736 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2737 server->caps |= NFS_CAP_OWNER;
2738 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2739 server->caps |= NFS_CAP_OWNER_GROUP;
2740 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2741 server->caps |= NFS_CAP_ATIME;
2742 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2743 server->caps |= NFS_CAP_CTIME;
2744 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2745 server->caps |= NFS_CAP_MTIME;
2746 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2747 if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL)
2748 server->caps |= NFS_CAP_SECURITY_LABEL;
2750 memcpy(server->attr_bitmask_nl, res.attr_bitmask,
2751 sizeof(server->attr_bitmask));
2753 if (server->caps & NFS_CAP_SECURITY_LABEL) {
2754 server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
2755 res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
2757 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2758 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2759 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2760 server->acl_bitmask = res.acl_bitmask;
2761 server->fh_expire_type = res.fh_expire_type;
2767 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2769 struct nfs4_exception exception = { };
2772 err = nfs4_handle_exception(server,
2773 _nfs4_server_capabilities(server, fhandle),
2775 } while (exception.retry);
2779 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2780 struct nfs_fsinfo *info)
2783 struct nfs4_lookup_root_arg args = {
2786 struct nfs4_lookup_res res = {
2788 .fattr = info->fattr,
2791 struct rpc_message msg = {
2792 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2797 bitmask[0] = nfs4_fattr_bitmap[0];
2798 bitmask[1] = nfs4_fattr_bitmap[1];
2800 * Process the label in the upcoming getfattr
2802 bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL;
2804 nfs_fattr_init(info->fattr);
2805 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2808 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2809 struct nfs_fsinfo *info)
2811 struct nfs4_exception exception = { };
2814 err = _nfs4_lookup_root(server, fhandle, info);
2815 trace_nfs4_lookup_root(server, fhandle, info->fattr, err);
2818 case -NFS4ERR_WRONGSEC:
2821 err = nfs4_handle_exception(server, err, &exception);
2823 } while (exception.retry);
2828 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2829 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2831 struct rpc_auth_create_args auth_args = {
2832 .pseudoflavor = flavor,
2834 struct rpc_auth *auth;
2837 auth = rpcauth_create(&auth_args, server->client);
2842 ret = nfs4_lookup_root(server, fhandle, info);
2848 * Retry pseudoroot lookup with various security flavors. We do this when:
2850 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2851 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2853 * Returns zero on success, or a negative NFS4ERR value, or a
2854 * negative errno value.
2856 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2857 struct nfs_fsinfo *info)
2859 /* Per 3530bis 15.33.5 */
2860 static const rpc_authflavor_t flav_array[] = {
2864 RPC_AUTH_UNIX, /* courtesy */
2867 int status = -EPERM;
2870 for (i = 0; i < ARRAY_SIZE(flav_array); i++) {
2871 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2872 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2878 * -EACCESS could mean that the user doesn't have correct permissions
2879 * to access the mount. It could also mean that we tried to mount
2880 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2881 * existing mount programs don't handle -EACCES very well so it should
2882 * be mapped to -EPERM instead.
2884 if (status == -EACCES)
2889 static int nfs4_do_find_root_sec(struct nfs_server *server,
2890 struct nfs_fh *fhandle, struct nfs_fsinfo *info)
2892 int mv = server->nfs_client->cl_minorversion;
2893 return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info);
2897 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2898 * @server: initialized nfs_server handle
2899 * @fhandle: we fill in the pseudo-fs root file handle
2900 * @info: we fill in an FSINFO struct
2901 * @auth_probe: probe the auth flavours
2903 * Returns zero on success, or a negative errno.
2905 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2906 struct nfs_fsinfo *info,
2911 switch (auth_probe) {
2913 status = nfs4_lookup_root(server, fhandle, info);
2914 if (status != -NFS4ERR_WRONGSEC)
2916 /* Did user force a 'sec=' mount option? */
2917 if (server->flags & NFS_MOUNT_SECFLAVOUR)
2920 status = nfs4_do_find_root_sec(server, fhandle, info);
2924 status = nfs4_server_capabilities(server, fhandle);
2926 status = nfs4_do_fsinfo(server, fhandle, info);
2928 return nfs4_map_errors(status);
2931 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2932 struct nfs_fsinfo *info)
2935 struct nfs_fattr *fattr = info->fattr;
2936 struct nfs4_label *label = NULL;
2938 error = nfs4_server_capabilities(server, mntfh);
2940 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2944 label = nfs4_label_alloc(server, GFP_KERNEL);
2946 return PTR_ERR(label);
2948 error = nfs4_proc_getattr(server, mntfh, fattr, label);
2950 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2951 goto err_free_label;
2954 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2955 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2956 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2959 nfs4_label_free(label);
2965 * Get locations and (maybe) other attributes of a referral.
2966 * Note that we'll actually follow the referral later when
2967 * we detect fsid mismatch in inode revalidation
2969 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2970 const struct qstr *name, struct nfs_fattr *fattr,
2971 struct nfs_fh *fhandle)
2973 int status = -ENOMEM;
2974 struct page *page = NULL;
2975 struct nfs4_fs_locations *locations = NULL;
2977 page = alloc_page(GFP_KERNEL);
2980 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2981 if (locations == NULL)
2984 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2989 * If the fsid didn't change, this is a migration event, not a
2990 * referral. Cause us to drop into the exception handler, which
2991 * will kick off migration recovery.
2993 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2994 dprintk("%s: server did not return a different fsid for"
2995 " a referral at %s\n", __func__, name->name);
2996 status = -NFS4ERR_MOVED;
2999 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
3000 nfs_fixup_referral_attributes(&locations->fattr);
3002 /* replace the lookup nfs_fattr with the locations nfs_fattr */
3003 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
3004 memset(fhandle, 0, sizeof(struct nfs_fh));
3012 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
3013 struct nfs_fattr *fattr, struct nfs4_label *label)
3015 struct nfs4_getattr_arg args = {
3017 .bitmask = server->attr_bitmask,
3019 struct nfs4_getattr_res res = {
3024 struct rpc_message msg = {
3025 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
3030 args.bitmask = nfs4_bitmask(server, label);
3032 nfs_fattr_init(fattr);
3033 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3036 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
3037 struct nfs_fattr *fattr, struct nfs4_label *label)
3039 struct nfs4_exception exception = { };
3042 err = _nfs4_proc_getattr(server, fhandle, fattr, label);
3043 trace_nfs4_getattr(server, fhandle, fattr, err);
3044 err = nfs4_handle_exception(server, err,
3046 } while (exception.retry);
3051 * The file is not closed if it is opened due to the a request to change
3052 * the size of the file. The open call will not be needed once the
3053 * VFS layer lookup-intents are implemented.
3055 * Close is called when the inode is destroyed.
3056 * If we haven't opened the file for O_WRONLY, we
3057 * need to in the size_change case to obtain a stateid.
3060 * Because OPEN is always done by name in nfsv4, it is
3061 * possible that we opened a different file by the same
3062 * name. We can recognize this race condition, but we
3063 * can't do anything about it besides returning an error.
3065 * This will be fixed with VFS changes (lookup-intent).
3068 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
3069 struct iattr *sattr)
3071 struct inode *inode = dentry->d_inode;
3072 struct rpc_cred *cred = NULL;
3073 struct nfs4_state *state = NULL;
3074 struct nfs4_label *label = NULL;
3077 if (pnfs_ld_layoutret_on_setattr(inode))
3078 pnfs_commit_and_return_layout(inode);
3080 nfs_fattr_init(fattr);
3082 /* Deal with open(O_TRUNC) */
3083 if (sattr->ia_valid & ATTR_OPEN)
3084 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME);
3086 /* Optimization: if the end result is no change, don't RPC */
3087 if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
3090 /* Search for an existing open(O_WRITE) file */
3091 if (sattr->ia_valid & ATTR_FILE) {
3092 struct nfs_open_context *ctx;
3094 ctx = nfs_file_open_context(sattr->ia_file);
3101 label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
3103 return PTR_ERR(label);
3105 status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label);
3107 nfs_setattr_update_inode(inode, sattr);
3108 nfs_setsecurity(inode, fattr, label);
3110 nfs4_label_free(label);
3114 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
3115 const struct qstr *name, struct nfs_fh *fhandle,
3116 struct nfs_fattr *fattr, struct nfs4_label *label)
3118 struct nfs_server *server = NFS_SERVER(dir);
3120 struct nfs4_lookup_arg args = {
3121 .bitmask = server->attr_bitmask,
3122 .dir_fh = NFS_FH(dir),
3125 struct nfs4_lookup_res res = {
3131 struct rpc_message msg = {
3132 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
3137 args.bitmask = nfs4_bitmask(server, label);
3139 nfs_fattr_init(fattr);
3141 dprintk("NFS call lookup %s\n", name->name);
3142 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
3143 dprintk("NFS reply lookup: %d\n", status);
3147 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
3149 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
3150 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
3151 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
3155 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
3156 struct qstr *name, struct nfs_fh *fhandle,
3157 struct nfs_fattr *fattr, struct nfs4_label *label)
3159 struct nfs4_exception exception = { };
3160 struct rpc_clnt *client = *clnt;
3163 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label);
3164 trace_nfs4_lookup(dir, name, err);
3166 case -NFS4ERR_BADNAME:
3169 case -NFS4ERR_MOVED:
3170 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
3172 case -NFS4ERR_WRONGSEC:
3174 if (client != *clnt)
3176 /* No security negotiation if the user specified 'sec=' */
3177 if (NFS_SERVER(dir)->flags & NFS_MOUNT_SECFLAVOUR)
3179 client = nfs4_create_sec_client(client, dir, name);
3181 return PTR_ERR(client);
3183 exception.retry = 1;
3186 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
3188 } while (exception.retry);
3193 else if (client != *clnt)
3194 rpc_shutdown_client(client);
3199 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
3200 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
3201 struct nfs4_label *label)
3204 struct rpc_clnt *client = NFS_CLIENT(dir);
3206 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label);
3207 if (client != NFS_CLIENT(dir)) {
3208 rpc_shutdown_client(client);
3209 nfs_fixup_secinfo_attributes(fattr);
3215 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
3216 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
3218 struct rpc_clnt *client = NFS_CLIENT(dir);
3221 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL);
3223 return ERR_PTR(status);
3224 return (client == NFS_CLIENT(dir)) ? rpc_clone_client(client) : client;
3227 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
3229 struct nfs_server *server = NFS_SERVER(inode);
3230 struct nfs4_accessargs args = {
3231 .fh = NFS_FH(inode),
3232 .bitmask = server->cache_consistency_bitmask,
3234 struct nfs4_accessres res = {
3237 struct rpc_message msg = {
3238 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
3241 .rpc_cred = entry->cred,
3243 int mode = entry->mask;
3247 * Determine which access bits we want to ask for...
3249 if (mode & MAY_READ)
3250 args.access |= NFS4_ACCESS_READ;
3251 if (S_ISDIR(inode->i_mode)) {
3252 if (mode & MAY_WRITE)
3253 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
3254 if (mode & MAY_EXEC)
3255 args.access |= NFS4_ACCESS_LOOKUP;
3257 if (mode & MAY_WRITE)
3258 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
3259 if (mode & MAY_EXEC)
3260 args.access |= NFS4_ACCESS_EXECUTE;
3263 res.fattr = nfs_alloc_fattr();
3264 if (res.fattr == NULL)
3267 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3269 nfs_access_set_mask(entry, res.access);
3270 nfs_refresh_inode(inode, res.fattr);
3272 nfs_free_fattr(res.fattr);
3276 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
3278 struct nfs4_exception exception = { };
3281 err = _nfs4_proc_access(inode, entry);
3282 trace_nfs4_access(inode, err);
3283 err = nfs4_handle_exception(NFS_SERVER(inode), err,
3285 } while (exception.retry);
3290 * TODO: For the time being, we don't try to get any attributes
3291 * along with any of the zero-copy operations READ, READDIR,
3294 * In the case of the first three, we want to put the GETATTR
3295 * after the read-type operation -- this is because it is hard
3296 * to predict the length of a GETATTR response in v4, and thus
3297 * align the READ data correctly. This means that the GETATTR
3298 * may end up partially falling into the page cache, and we should
3299 * shift it into the 'tail' of the xdr_buf before processing.
3300 * To do this efficiently, we need to know the total length
3301 * of data received, which doesn't seem to be available outside
3304 * In the case of WRITE, we also want to put the GETATTR after
3305 * the operation -- in this case because we want to make sure
3306 * we get the post-operation mtime and size.
3308 * Both of these changes to the XDR layer would in fact be quite
3309 * minor, but I decided to leave them for a subsequent patch.
3311 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
3312 unsigned int pgbase, unsigned int pglen)
3314 struct nfs4_readlink args = {
3315 .fh = NFS_FH(inode),
3320 struct nfs4_readlink_res res;
3321 struct rpc_message msg = {
3322 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
3327 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
3330 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
3331 unsigned int pgbase, unsigned int pglen)
3333 struct nfs4_exception exception = { };
3336 err = _nfs4_proc_readlink(inode, page, pgbase, pglen);
3337 trace_nfs4_readlink(inode, err);
3338 err = nfs4_handle_exception(NFS_SERVER(inode), err,
3340 } while (exception.retry);
3345 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3348 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
3351 struct nfs4_label l, *ilabel = NULL;
3352 struct nfs_open_context *ctx;
3353 struct nfs4_state *state;
3357 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
3359 return PTR_ERR(ctx);
3361 ilabel = nfs4_label_init_security(dir, dentry, sattr, &l);
3363 sattr->ia_mode &= ~current_umask();
3364 state = nfs4_do_open(dir, ctx, flags, sattr, ilabel, &opened);
3365 if (IS_ERR(state)) {
3366 status = PTR_ERR(state);
3370 nfs4_label_release_security(ilabel);
3371 put_nfs_open_context(ctx);
3375 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
3377 struct nfs_server *server = NFS_SERVER(dir);
3378 struct nfs_removeargs args = {
3382 struct nfs_removeres res = {
3385 struct rpc_message msg = {
3386 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
3392 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
3394 update_changeattr(dir, &res.cinfo);
3398 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
3400 struct nfs4_exception exception = { };
3403 err = _nfs4_proc_remove(dir, name);
3404 trace_nfs4_remove(dir, name, err);
3405 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3407 } while (exception.retry);
3411 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
3413 struct nfs_server *server = NFS_SERVER(dir);
3414 struct nfs_removeargs *args = msg->rpc_argp;
3415 struct nfs_removeres *res = msg->rpc_resp;
3417 res->server = server;
3418 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
3419 nfs4_init_sequence(&args->seq_args, &res->seq_res, 1);
3421 nfs_fattr_init(res->dir_attr);
3424 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
3426 nfs4_setup_sequence(NFS_SERVER(data->dir),
3427 &data->args.seq_args,
3432 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
3434 struct nfs_unlinkdata *data = task->tk_calldata;
3435 struct nfs_removeres *res = &data->res;
3437 if (!nfs4_sequence_done(task, &res->seq_res))
3439 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3441 update_changeattr(dir, &res->cinfo);
3445 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
3447 struct nfs_server *server = NFS_SERVER(dir);
3448 struct nfs_renameargs *arg = msg->rpc_argp;
3449 struct nfs_renameres *res = msg->rpc_resp;
3451 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
3452 res->server = server;
3453 nfs4_init_sequence(&arg->seq_args, &res->seq_res, 1);
3456 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
3458 nfs4_setup_sequence(NFS_SERVER(data->old_dir),
3459 &data->args.seq_args,
3464 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
3465 struct inode *new_dir)
3467 struct nfs_renamedata *data = task->tk_calldata;
3468 struct nfs_renameres *res = &data->res;
3470 if (!nfs4_sequence_done(task, &res->seq_res))
3472 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3475 update_changeattr(old_dir, &res->old_cinfo);
3476 update_changeattr(new_dir, &res->new_cinfo);
3480 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3481 struct inode *new_dir, struct qstr *new_name)
3483 struct nfs_server *server = NFS_SERVER(old_dir);
3484 struct nfs_renameargs arg = {
3485 .old_dir = NFS_FH(old_dir),
3486 .new_dir = NFS_FH(new_dir),
3487 .old_name = old_name,
3488 .new_name = new_name,
3490 struct nfs_renameres res = {
3493 struct rpc_message msg = {
3494 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3498 int status = -ENOMEM;
3500 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3502 update_changeattr(old_dir, &res.old_cinfo);
3503 update_changeattr(new_dir, &res.new_cinfo);
3508 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3509 struct inode *new_dir, struct qstr *new_name)
3511 struct nfs4_exception exception = { };
3514 err = _nfs4_proc_rename(old_dir, old_name,
3516 trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err);
3517 err = nfs4_handle_exception(NFS_SERVER(old_dir), err,
3519 } while (exception.retry);
3523 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3525 struct nfs_server *server = NFS_SERVER(inode);
3526 struct nfs4_link_arg arg = {
3527 .fh = NFS_FH(inode),
3528 .dir_fh = NFS_FH(dir),
3530 .bitmask = server->attr_bitmask,
3532 struct nfs4_link_res res = {
3536 struct rpc_message msg = {
3537 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3541 int status = -ENOMEM;
3543 res.fattr = nfs_alloc_fattr();
3544 if (res.fattr == NULL)
3547 res.label = nfs4_label_alloc(server, GFP_KERNEL);
3548 if (IS_ERR(res.label)) {
3549 status = PTR_ERR(res.label);
3552 arg.bitmask = nfs4_bitmask(server, res.label);
3554 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3556 update_changeattr(dir, &res.cinfo);
3557 status = nfs_post_op_update_inode(inode, res.fattr);
3559 nfs_setsecurity(inode, res.fattr, res.label);
3563 nfs4_label_free(res.label);
3566 nfs_free_fattr(res.fattr);
3570 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3572 struct nfs4_exception exception = { };
3575 err = nfs4_handle_exception(NFS_SERVER(inode),
3576 _nfs4_proc_link(inode, dir, name),
3578 } while (exception.retry);
3582 struct nfs4_createdata {
3583 struct rpc_message msg;
3584 struct nfs4_create_arg arg;
3585 struct nfs4_create_res res;
3587 struct nfs_fattr fattr;
3588 struct nfs4_label *label;
3591 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3592 struct qstr *name, struct iattr *sattr, u32 ftype)
3594 struct nfs4_createdata *data;
3596 data = kzalloc(sizeof(*data), GFP_KERNEL);
3598 struct nfs_server *server = NFS_SERVER(dir);
3600 data->label = nfs4_label_alloc(server, GFP_KERNEL);
3601 if (IS_ERR(data->label))
3604 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3605 data->msg.rpc_argp = &data->arg;
3606 data->msg.rpc_resp = &data->res;
3607 data->arg.dir_fh = NFS_FH(dir);
3608 data->arg.server = server;
3609 data->arg.name = name;
3610 data->arg.attrs = sattr;
3611 data->arg.ftype = ftype;
3612 data->arg.bitmask = nfs4_bitmask(server, data->label);
3613 data->res.server = server;
3614 data->res.fh = &data->fh;
3615 data->res.fattr = &data->fattr;
3616 data->res.label = data->label;
3617 nfs_fattr_init(data->res.fattr);
3625 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3627 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3628 &data->arg.seq_args, &data->res.seq_res, 1);
3630 update_changeattr(dir, &data->res.dir_cinfo);
3631 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label);
3636 static void nfs4_free_createdata(struct nfs4_createdata *data)
3638 nfs4_label_free(data->label);
3642 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3643 struct page *page, unsigned int len, struct iattr *sattr,
3644 struct nfs4_label *label)
3646 struct nfs4_createdata *data;
3647 int status = -ENAMETOOLONG;
3649 if (len > NFS4_MAXPATHLEN)
3653 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3657 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3658 data->arg.u.symlink.pages = &page;
3659 data->arg.u.symlink.len = len;
3660 data->arg.label = label;
3662 status = nfs4_do_create(dir, dentry, data);
3664 nfs4_free_createdata(data);
3669 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3670 struct page *page, unsigned int len, struct iattr *sattr)
3672 struct nfs4_exception exception = { };
3673 struct nfs4_label l, *label = NULL;
3676 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3679 err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label);
3680 trace_nfs4_symlink(dir, &dentry->d_name, err);
3681 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3683 } while (exception.retry);
3685 nfs4_label_release_security(label);
3689 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3690 struct iattr *sattr, struct nfs4_label *label)
3692 struct nfs4_createdata *data;
3693 int status = -ENOMEM;
3695 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3699 data->arg.label = label;
3700 status = nfs4_do_create(dir, dentry, data);
3702 nfs4_free_createdata(data);
3707 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3708 struct iattr *sattr)
3710 struct nfs4_exception exception = { };
3711 struct nfs4_label l, *label = NULL;
3714 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3716 sattr->ia_mode &= ~current_umask();
3718 err = _nfs4_proc_mkdir(dir, dentry, sattr, label);
3719 trace_nfs4_mkdir(dir, &dentry->d_name, err);
3720 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3722 } while (exception.retry);
3723 nfs4_label_release_security(label);
3728 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3729 u64 cookie, struct page **pages, unsigned int count, int plus)
3731 struct inode *dir = dentry->d_inode;
3732 struct nfs4_readdir_arg args = {
3737 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3740 struct nfs4_readdir_res res;
3741 struct rpc_message msg = {
3742 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3749 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3750 dentry->d_parent->d_name.name,
3751 dentry->d_name.name,
3752 (unsigned long long)cookie);
3753 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3754 res.pgbase = args.pgbase;
3755 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3757 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3758 status += args.pgbase;
3761 nfs_invalidate_atime(dir);
3763 dprintk("%s: returns %d\n", __func__, status);
3767 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3768 u64 cookie, struct page **pages, unsigned int count, int plus)
3770 struct nfs4_exception exception = { };
3773 err = _nfs4_proc_readdir(dentry, cred, cookie,
3774 pages, count, plus);
3775 trace_nfs4_readdir(dentry->d_inode, err);
3776 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err,
3778 } while (exception.retry);
3782 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3783 struct iattr *sattr, struct nfs4_label *label, dev_t rdev)
3785 struct nfs4_createdata *data;
3786 int mode = sattr->ia_mode;
3787 int status = -ENOMEM;
3789 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3794 data->arg.ftype = NF4FIFO;
3795 else if (S_ISBLK(mode)) {
3796 data->arg.ftype = NF4BLK;
3797 data->arg.u.device.specdata1 = MAJOR(rdev);
3798 data->arg.u.device.specdata2 = MINOR(rdev);
3800 else if (S_ISCHR(mode)) {
3801 data->arg.ftype = NF4CHR;
3802 data->arg.u.device.specdata1 = MAJOR(rdev);
3803 data->arg.u.device.specdata2 = MINOR(rdev);
3804 } else if (!S_ISSOCK(mode)) {
3809 data->arg.label = label;
3810 status = nfs4_do_create(dir, dentry, data);
3812 nfs4_free_createdata(data);
3817 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3818 struct iattr *sattr, dev_t rdev)
3820 struct nfs4_exception exception = { };
3821 struct nfs4_label l, *label = NULL;
3824 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3826 sattr->ia_mode &= ~current_umask();
3828 err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev);
3829 trace_nfs4_mknod(dir, &dentry->d_name, err);
3830 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3832 } while (exception.retry);
3834 nfs4_label_release_security(label);
3839 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3840 struct nfs_fsstat *fsstat)
3842 struct nfs4_statfs_arg args = {
3844 .bitmask = server->attr_bitmask,
3846 struct nfs4_statfs_res res = {
3849 struct rpc_message msg = {
3850 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3855 nfs_fattr_init(fsstat->fattr);
3856 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3859 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3861 struct nfs4_exception exception = { };
3864 err = nfs4_handle_exception(server,
3865 _nfs4_proc_statfs(server, fhandle, fsstat),
3867 } while (exception.retry);
3871 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3872 struct nfs_fsinfo *fsinfo)
3874 struct nfs4_fsinfo_arg args = {
3876 .bitmask = server->attr_bitmask,
3878 struct nfs4_fsinfo_res res = {
3881 struct rpc_message msg = {
3882 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3887 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3890 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3892 struct nfs4_exception exception = { };
3893 unsigned long now = jiffies;
3897 err = _nfs4_do_fsinfo(server, fhandle, fsinfo);
3898 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err);
3900 struct nfs_client *clp = server->nfs_client;
3902 spin_lock(&clp->cl_lock);
3903 clp->cl_lease_time = fsinfo->lease_time * HZ;
3904 clp->cl_last_renewal = now;
3905 spin_unlock(&clp->cl_lock);
3908 err = nfs4_handle_exception(server, err, &exception);
3909 } while (exception.retry);
3913 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3917 nfs_fattr_init(fsinfo->fattr);
3918 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3920 /* block layout checks this! */
3921 server->pnfs_blksize = fsinfo->blksize;
3922 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3928 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3929 struct nfs_pathconf *pathconf)
3931 struct nfs4_pathconf_arg args = {
3933 .bitmask = server->attr_bitmask,
3935 struct nfs4_pathconf_res res = {
3936 .pathconf = pathconf,
3938 struct rpc_message msg = {
3939 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3944 /* None of the pathconf attributes are mandatory to implement */
3945 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3946 memset(pathconf, 0, sizeof(*pathconf));
3950 nfs_fattr_init(pathconf->fattr);
3951 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3954 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3955 struct nfs_pathconf *pathconf)
3957 struct nfs4_exception exception = { };
3961 err = nfs4_handle_exception(server,
3962 _nfs4_proc_pathconf(server, fhandle, pathconf),
3964 } while (exception.retry);
3968 int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3969 const struct nfs_open_context *ctx,
3970 const struct nfs_lock_context *l_ctx,
3973 const struct nfs_lockowner *lockowner = NULL;
3976 lockowner = &l_ctx->lockowner;
3977 return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner);
3979 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid);
3981 static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
3982 const struct nfs_open_context *ctx,
3983 const struct nfs_lock_context *l_ctx,
3986 nfs4_stateid current_stateid;
3988 if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode))
3990 return nfs4_stateid_match(stateid, ¤t_stateid);
3993 static bool nfs4_error_stateid_expired(int err)
3996 case -NFS4ERR_DELEG_REVOKED:
3997 case -NFS4ERR_ADMIN_REVOKED:
3998 case -NFS4ERR_BAD_STATEID:
3999 case -NFS4ERR_STALE_STATEID:
4000 case -NFS4ERR_OLD_STATEID:
4001 case -NFS4ERR_OPENMODE:
4002 case -NFS4ERR_EXPIRED:
4008 void __nfs4_read_done_cb(struct nfs_read_data *data)
4010 nfs_invalidate_atime(data->header->inode);
4013 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
4015 struct nfs_server *server = NFS_SERVER(data->header->inode);
4017 trace_nfs4_read(data, task->tk_status);
4018 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
4019 rpc_restart_call_prepare(task);
4023 __nfs4_read_done_cb(data);
4024 if (task->tk_status > 0)
4025 renew_lease(server, data->timestamp);
4029 static bool nfs4_read_stateid_changed(struct rpc_task *task,
4030 struct nfs_readargs *args)
4033 if (!nfs4_error_stateid_expired(task->tk_status) ||
4034 nfs4_stateid_is_current(&args->stateid,
4039 rpc_restart_call_prepare(task);
4043 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
4046 dprintk("--> %s\n", __func__);
4048 if (!nfs4_sequence_done(task, &data->res.seq_res))
4050 if (nfs4_read_stateid_changed(task, &data->args))
4052 return data->read_done_cb ? data->read_done_cb(task, data) :
4053 nfs4_read_done_cb(task, data);
4056 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
4058 data->timestamp = jiffies;
4059 data->read_done_cb = nfs4_read_done_cb;
4060 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
4061 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
4064 static int nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
4066 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
4067 &data->args.seq_args,
4071 if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
4072 data->args.lock_context, FMODE_READ) == -EIO)
4074 if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags)))
4079 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
4081 struct inode *inode = data->header->inode;
4083 trace_nfs4_write(data, task->tk_status);
4084 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
4085 rpc_restart_call_prepare(task);
4088 if (task->tk_status >= 0) {
4089 renew_lease(NFS_SERVER(inode), data->timestamp);
4090 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4095 static bool nfs4_write_stateid_changed(struct rpc_task *task,
4096 struct nfs_writeargs *args)
4099 if (!nfs4_error_stateid_expired(task->tk_status) ||
4100 nfs4_stateid_is_current(&args->stateid,
4105 rpc_restart_call_prepare(task);
4109 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
4111 if (!nfs4_sequence_done(task, &data->res.seq_res))
4113 if (nfs4_write_stateid_changed(task, &data->args))
4115 return data->write_done_cb ? data->write_done_cb(task, data) :
4116 nfs4_write_done_cb(task, data);
4120 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
4122 const struct nfs_pgio_header *hdr = data->header;
4124 /* Don't request attributes for pNFS or O_DIRECT writes */
4125 if (data->ds_clp != NULL || hdr->dreq != NULL)
4127 /* Otherwise, request attributes if and only if we don't hold
4130 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
4133 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
4135 struct nfs_server *server = NFS_SERVER(data->header->inode);
4137 if (!nfs4_write_need_cache_consistency_data(data)) {
4138 data->args.bitmask = NULL;
4139 data->res.fattr = NULL;
4141 data->args.bitmask = server->cache_consistency_bitmask;
4143 if (!data->write_done_cb)
4144 data->write_done_cb = nfs4_write_done_cb;
4145 data->res.server = server;
4146 data->timestamp = jiffies;
4148 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
4149 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4152 static int nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
4154 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
4155 &data->args.seq_args,
4159 if (nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
4160 data->args.lock_context, FMODE_WRITE) == -EIO)
4162 if (unlikely(test_bit(NFS_CONTEXT_BAD, &data->args.context->flags)))
4167 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
4169 nfs4_setup_sequence(NFS_SERVER(data->inode),
4170 &data->args.seq_args,
4175 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
4177 struct inode *inode = data->inode;
4179 trace_nfs4_commit(data, task->tk_status);
4180 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
4181 rpc_restart_call_prepare(task);
4187 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
4189 if (!nfs4_sequence_done(task, &data->res.seq_res))
4191 return data->commit_done_cb(task, data);
4194 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
4196 struct nfs_server *server = NFS_SERVER(data->inode);
4198 if (data->commit_done_cb == NULL)
4199 data->commit_done_cb = nfs4_commit_done_cb;
4200 data->res.server = server;
4201 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
4202 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4205 struct nfs4_renewdata {
4206 struct nfs_client *client;
4207 unsigned long timestamp;
4211 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4212 * standalone procedure for queueing an asynchronous RENEW.
4214 static void nfs4_renew_release(void *calldata)
4216 struct nfs4_renewdata *data = calldata;
4217 struct nfs_client *clp = data->client;
4219 if (atomic_read(&clp->cl_count) > 1)
4220 nfs4_schedule_state_renewal(clp);
4221 nfs_put_client(clp);
4225 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
4227 struct nfs4_renewdata *data = calldata;
4228 struct nfs_client *clp = data->client;
4229 unsigned long timestamp = data->timestamp;
4231 trace_nfs4_renew_async(clp, task->tk_status);
4232 if (task->tk_status < 0) {
4233 /* Unless we're shutting down, schedule state recovery! */
4234 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
4236 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
4237 nfs4_schedule_lease_recovery(clp);
4240 nfs4_schedule_path_down_recovery(clp);
4242 do_renew_lease(clp, timestamp);
4245 static const struct rpc_call_ops nfs4_renew_ops = {
4246 .rpc_call_done = nfs4_renew_done,
4247 .rpc_release = nfs4_renew_release,
4250 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
4252 struct rpc_message msg = {
4253 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
4257 struct nfs4_renewdata *data;
4259 if (renew_flags == 0)
4261 if (!atomic_inc_not_zero(&clp->cl_count))
4263 data = kmalloc(sizeof(*data), GFP_NOFS);
4267 data->timestamp = jiffies;
4268 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT,
4269 &nfs4_renew_ops, data);
4272 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
4274 struct rpc_message msg = {
4275 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
4279 unsigned long now = jiffies;
4282 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4285 do_renew_lease(clp, now);
4289 static inline int nfs4_server_supports_acls(struct nfs_server *server)
4291 return (server->caps & NFS_CAP_ACLS)
4292 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
4293 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
4296 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4297 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4300 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4302 static int buf_to_pages_noslab(const void *buf, size_t buflen,
4303 struct page **pages, unsigned int *pgbase)
4305 struct page *newpage, **spages;
4311 len = min_t(size_t, PAGE_SIZE, buflen);
4312 newpage = alloc_page(GFP_KERNEL);
4314 if (newpage == NULL)
4316 memcpy(page_address(newpage), buf, len);
4321 } while (buflen != 0);
4327 __free_page(spages[rc-1]);
4331 struct nfs4_cached_acl {
4337 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
4339 struct nfs_inode *nfsi = NFS_I(inode);
4341 spin_lock(&inode->i_lock);
4342 kfree(nfsi->nfs4_acl);
4343 nfsi->nfs4_acl = acl;
4344 spin_unlock(&inode->i_lock);
4347 static void nfs4_zap_acl_attr(struct inode *inode)
4349 nfs4_set_cached_acl(inode, NULL);
4352 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
4354 struct nfs_inode *nfsi = NFS_I(inode);
4355 struct nfs4_cached_acl *acl;
4358 spin_lock(&inode->i_lock);
4359 acl = nfsi->nfs4_acl;
4362 if (buf == NULL) /* user is just asking for length */
4364 if (acl->cached == 0)
4366 ret = -ERANGE; /* see getxattr(2) man page */
4367 if (acl->len > buflen)
4369 memcpy(buf, acl->data, acl->len);
4373 spin_unlock(&inode->i_lock);
4377 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
4379 struct nfs4_cached_acl *acl;
4380 size_t buflen = sizeof(*acl) + acl_len;
4382 if (buflen <= PAGE_SIZE) {
4383 acl = kmalloc(buflen, GFP_KERNEL);
4387 _copy_from_pages(acl->data, pages, pgbase, acl_len);
4389 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
4396 nfs4_set_cached_acl(inode, acl);
4400 * The getxattr API returns the required buffer length when called with a
4401 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4402 * the required buf. On a NULL buf, we send a page of data to the server
4403 * guessing that the ACL request can be serviced by a page. If so, we cache
4404 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4405 * the cache. If not so, we throw away the page, and cache the required
4406 * length. The next getxattr call will then produce another round trip to
4407 * the server, this time with the input buf of the required size.
4409 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4411 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
4412 struct nfs_getaclargs args = {
4413 .fh = NFS_FH(inode),
4417 struct nfs_getaclres res = {
4420 struct rpc_message msg = {
4421 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
4425 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4426 int ret = -ENOMEM, i;
4428 /* As long as we're doing a round trip to the server anyway,
4429 * let's be prepared for a page of acl data. */
4432 if (npages > ARRAY_SIZE(pages))
4435 for (i = 0; i < npages; i++) {
4436 pages[i] = alloc_page(GFP_KERNEL);
4441 /* for decoding across pages */
4442 res.acl_scratch = alloc_page(GFP_KERNEL);
4443 if (!res.acl_scratch)
4446 args.acl_len = npages * PAGE_SIZE;
4447 args.acl_pgbase = 0;
4449 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4450 __func__, buf, buflen, npages, args.acl_len);
4451 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
4452 &msg, &args.seq_args, &res.seq_res, 0);
4456 /* Handle the case where the passed-in buffer is too short */
4457 if (res.acl_flags & NFS4_ACL_TRUNC) {
4458 /* Did the user only issue a request for the acl length? */
4464 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
4466 if (res.acl_len > buflen) {
4470 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
4475 for (i = 0; i < npages; i++)
4477 __free_page(pages[i]);
4478 if (res.acl_scratch)
4479 __free_page(res.acl_scratch);
4483 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4485 struct nfs4_exception exception = { };
4488 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
4489 trace_nfs4_get_acl(inode, ret);
4492 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
4493 } while (exception.retry);
4497 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
4499 struct nfs_server *server = NFS_SERVER(inode);
4502 if (!nfs4_server_supports_acls(server))
4504 ret = nfs_revalidate_inode(server, inode);
4507 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
4508 nfs_zap_acl_cache(inode);
4509 ret = nfs4_read_cached_acl(inode, buf, buflen);
4511 /* -ENOENT is returned if there is no ACL or if there is an ACL
4512 * but no cached acl data, just the acl length */
4514 return nfs4_get_acl_uncached(inode, buf, buflen);
4517 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4519 struct nfs_server *server = NFS_SERVER(inode);
4520 struct page *pages[NFS4ACL_MAXPAGES];
4521 struct nfs_setaclargs arg = {
4522 .fh = NFS_FH(inode),
4526 struct nfs_setaclres res;
4527 struct rpc_message msg = {
4528 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
4532 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4535 if (!nfs4_server_supports_acls(server))
4537 if (npages > ARRAY_SIZE(pages))
4539 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
4542 nfs4_inode_return_delegation(inode);
4543 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4546 * Free each page after tx, so the only ref left is
4547 * held by the network stack
4550 put_page(pages[i-1]);
4553 * Acl update can result in inode attribute update.
4554 * so mark the attribute cache invalid.
4556 spin_lock(&inode->i_lock);
4557 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
4558 spin_unlock(&inode->i_lock);
4559 nfs_access_zap_cache(inode);
4560 nfs_zap_acl_cache(inode);
4564 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4566 struct nfs4_exception exception = { };
4569 err = __nfs4_proc_set_acl(inode, buf, buflen);
4570 trace_nfs4_set_acl(inode, err);
4571 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4573 } while (exception.retry);
4577 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4578 static int _nfs4_get_security_label(struct inode *inode, void *buf,
4581 struct nfs_server *server = NFS_SERVER(inode);
4582 struct nfs_fattr fattr;
4583 struct nfs4_label label = {0, 0, buflen, buf};
4585 u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
4586 struct nfs4_getattr_arg args = {
4587 .fh = NFS_FH(inode),
4590 struct nfs4_getattr_res res = {
4595 struct rpc_message msg = {
4596 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
4602 nfs_fattr_init(&fattr);
4604 ret = rpc_call_sync(server->client, &msg, 0);
4607 if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL))
4609 if (buflen < label.len)
4614 static int nfs4_get_security_label(struct inode *inode, void *buf,
4617 struct nfs4_exception exception = { };
4620 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
4624 err = _nfs4_get_security_label(inode, buf, buflen);
4625 trace_nfs4_get_security_label(inode, err);
4626 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4628 } while (exception.retry);
4632 static int _nfs4_do_set_security_label(struct inode *inode,
4633 struct nfs4_label *ilabel,
4634 struct nfs_fattr *fattr,
4635 struct nfs4_label *olabel)
4638 struct iattr sattr = {0};
4639 struct nfs_server *server = NFS_SERVER(inode);
4640 const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
4641 struct nfs_setattrargs args = {
4642 .fh = NFS_FH(inode),
4648 struct nfs_setattrres res = {
4653 struct rpc_message msg = {
4654 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
4660 nfs4_stateid_copy(&args.stateid, &zero_stateid);
4662 status = rpc_call_sync(server->client, &msg, 0);
4664 dprintk("%s failed: %d\n", __func__, status);
4669 static int nfs4_do_set_security_label(struct inode *inode,
4670 struct nfs4_label *ilabel,
4671 struct nfs_fattr *fattr,
4672 struct nfs4_label *olabel)
4674 struct nfs4_exception exception = { };
4678 err = _nfs4_do_set_security_label(inode, ilabel,
4680 trace_nfs4_set_security_label(inode, err);
4681 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4683 } while (exception.retry);
4688 nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen)
4690 struct nfs4_label ilabel, *olabel = NULL;
4691 struct nfs_fattr fattr;
4692 struct rpc_cred *cred;
4693 struct inode *inode = dentry->d_inode;
4696 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
4699 nfs_fattr_init(&fattr);
4703 ilabel.label = (char *)buf;
4704 ilabel.len = buflen;
4706 cred = rpc_lookup_cred();
4708 return PTR_ERR(cred);
4710 olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
4711 if (IS_ERR(olabel)) {
4712 status = -PTR_ERR(olabel);
4716 status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel);
4718 nfs_setsecurity(inode, &fattr, olabel);
4720 nfs4_label_free(olabel);
4725 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4729 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
4731 struct nfs_client *clp = server->nfs_client;
4733 if (task->tk_status >= 0)
4735 switch(task->tk_status) {
4736 case -NFS4ERR_DELEG_REVOKED:
4737 case -NFS4ERR_ADMIN_REVOKED:
4738 case -NFS4ERR_BAD_STATEID:
4741 nfs_remove_bad_delegation(state->inode);
4742 case -NFS4ERR_OPENMODE:
4745 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4746 goto recovery_failed;
4747 goto wait_on_recovery;
4748 case -NFS4ERR_EXPIRED:
4749 if (state != NULL) {
4750 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4751 goto recovery_failed;
4753 case -NFS4ERR_STALE_STATEID:
4754 case -NFS4ERR_STALE_CLIENTID:
4755 nfs4_schedule_lease_recovery(clp);
4756 goto wait_on_recovery;
4757 case -NFS4ERR_MOVED:
4758 if (nfs4_schedule_migration_recovery(server) < 0)
4759 goto recovery_failed;
4760 goto wait_on_recovery;
4761 #if defined(CONFIG_NFS_V4_1)
4762 case -NFS4ERR_BADSESSION:
4763 case -NFS4ERR_BADSLOT:
4764 case -NFS4ERR_BAD_HIGH_SLOT:
4765 case -NFS4ERR_DEADSESSION:
4766 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4767 case -NFS4ERR_SEQ_FALSE_RETRY:
4768 case -NFS4ERR_SEQ_MISORDERED:
4769 dprintk("%s ERROR %d, Reset session\n", __func__,
4771 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
4773 #endif /* CONFIG_NFS_V4_1 */
4774 case -NFS4ERR_DELAY:
4775 nfs_inc_server_stats(server, NFSIOS_DELAY);
4776 case -NFS4ERR_GRACE:
4777 rpc_delay(task, NFS4_POLL_RETRY_MAX);
4778 case -NFS4ERR_RETRY_UNCACHED_REP:
4779 case -NFS4ERR_OLD_STATEID:
4782 task->tk_status = nfs4_map_errors(task->tk_status);
4785 task->tk_status = -EIO;
4788 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
4789 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4790 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
4791 if (test_bit(NFS_MIG_FAILED, &server->mig_status))
4792 goto recovery_failed;
4794 task->tk_status = 0;
4798 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
4799 nfs4_verifier *bootverf)
4803 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4804 /* An impossible timestamp guarantees this value
4805 * will never match a generated boot time. */
4807 verf[1] = cpu_to_be32(NSEC_PER_SEC + 1);
4809 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4810 verf[0] = cpu_to_be32(nn->boot_time.tv_sec);
4811 verf[1] = cpu_to_be32(nn->boot_time.tv_nsec);
4813 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4817 nfs4_init_nonuniform_client_string(const struct nfs_client *clp,
4818 char *buf, size_t len)
4820 unsigned int result;
4823 result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s",
4825 rpc_peeraddr2str(clp->cl_rpcclient,
4827 rpc_peeraddr2str(clp->cl_rpcclient,
4828 RPC_DISPLAY_PROTO));
4834 nfs4_init_uniform_client_string(const struct nfs_client *clp,
4835 char *buf, size_t len)
4837 const char *nodename = clp->cl_rpcclient->cl_nodename;
4839 if (nfs4_client_id_uniquifier[0] != '\0')
4840 return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s",
4841 clp->rpc_ops->version,
4842 clp->cl_minorversion,
4843 nfs4_client_id_uniquifier,
4845 return scnprintf(buf, len, "Linux NFSv%u.%u %s",
4846 clp->rpc_ops->version, clp->cl_minorversion,
4851 * nfs4_proc_setclientid - Negotiate client ID
4852 * @clp: state data structure
4853 * @program: RPC program for NFSv4 callback service
4854 * @port: IP port number for NFS4 callback service
4855 * @cred: RPC credential to use for this call
4856 * @res: where to place the result
4858 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4860 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4861 unsigned short port, struct rpc_cred *cred,
4862 struct nfs4_setclientid_res *res)
4864 nfs4_verifier sc_verifier;
4865 struct nfs4_setclientid setclientid = {
4866 .sc_verifier = &sc_verifier,
4868 .sc_cb_ident = clp->cl_cb_ident,
4870 struct rpc_message msg = {
4871 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4872 .rpc_argp = &setclientid,
4878 /* nfs_client_id4 */
4879 nfs4_init_boot_verifier(clp, &sc_verifier);
4880 if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
4881 setclientid.sc_name_len =
4882 nfs4_init_uniform_client_string(clp,
4883 setclientid.sc_name,
4884 sizeof(setclientid.sc_name));
4886 setclientid.sc_name_len =
4887 nfs4_init_nonuniform_client_string(clp,
4888 setclientid.sc_name,
4889 sizeof(setclientid.sc_name));
4892 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4893 sizeof(setclientid.sc_netid), "%s",
4894 rpc_peeraddr2str(clp->cl_rpcclient,
4895 RPC_DISPLAY_NETID));
4897 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4898 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4899 clp->cl_ipaddr, port >> 8, port & 255);
4901 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4902 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4903 setclientid.sc_name_len, setclientid.sc_name);
4904 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4905 trace_nfs4_setclientid(clp, status);
4906 dprintk("NFS reply setclientid: %d\n", status);
4911 * nfs4_proc_setclientid_confirm - Confirm client ID
4912 * @clp: state data structure
4913 * @res: result of a previous SETCLIENTID
4914 * @cred: RPC credential to use for this call
4916 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4918 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4919 struct nfs4_setclientid_res *arg,
4920 struct rpc_cred *cred)
4922 struct rpc_message msg = {
4923 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4929 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4930 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4932 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4933 trace_nfs4_setclientid_confirm(clp, status);
4934 dprintk("NFS reply setclientid_confirm: %d\n", status);
4938 struct nfs4_delegreturndata {
4939 struct nfs4_delegreturnargs args;
4940 struct nfs4_delegreturnres res;
4942 nfs4_stateid stateid;
4943 unsigned long timestamp;
4944 struct nfs_fattr fattr;
4948 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4950 struct nfs4_delegreturndata *data = calldata;
4952 if (!nfs4_sequence_done(task, &data->res.seq_res))
4955 trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status);
4956 switch (task->tk_status) {
4957 case -NFS4ERR_STALE_STATEID:
4958 case -NFS4ERR_EXPIRED:
4960 renew_lease(data->res.server, data->timestamp);
4963 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4965 rpc_restart_call_prepare(task);
4969 data->rpc_status = task->tk_status;
4972 static void nfs4_delegreturn_release(void *calldata)
4977 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4979 struct nfs4_delegreturndata *d_data;
4981 d_data = (struct nfs4_delegreturndata *)data;
4983 nfs4_setup_sequence(d_data->res.server,
4984 &d_data->args.seq_args,
4985 &d_data->res.seq_res,
4989 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4990 .rpc_call_prepare = nfs4_delegreturn_prepare,
4991 .rpc_call_done = nfs4_delegreturn_done,
4992 .rpc_release = nfs4_delegreturn_release,
4995 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4997 struct nfs4_delegreturndata *data;
4998 struct nfs_server *server = NFS_SERVER(inode);
4999 struct rpc_task *task;
5000 struct rpc_message msg = {
5001 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
5004 struct rpc_task_setup task_setup_data = {
5005 .rpc_client = server->client,
5006 .rpc_message = &msg,
5007 .callback_ops = &nfs4_delegreturn_ops,
5008 .flags = RPC_TASK_ASYNC,
5012 data = kzalloc(sizeof(*data), GFP_NOFS);
5015 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
5016 data->args.fhandle = &data->fh;
5017 data->args.stateid = &data->stateid;
5018 data->args.bitmask = server->cache_consistency_bitmask;
5019 nfs_copy_fh(&data->fh, NFS_FH(inode));
5020 nfs4_stateid_copy(&data->stateid, stateid);
5021 data->res.fattr = &data->fattr;
5022 data->res.server = server;
5023 nfs_fattr_init(data->res.fattr);
5024 data->timestamp = jiffies;
5025 data->rpc_status = 0;
5027 task_setup_data.callback_data = data;
5028 msg.rpc_argp = &data->args;
5029 msg.rpc_resp = &data->res;
5030 task = rpc_run_task(&task_setup_data);
5032 return PTR_ERR(task);
5035 status = nfs4_wait_for_completion_rpc_task(task);
5038 status = data->rpc_status;
5040 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
5042 nfs_refresh_inode(inode, &data->fattr);
5048 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
5050 struct nfs_server *server = NFS_SERVER(inode);
5051 struct nfs4_exception exception = { };
5054 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
5055 trace_nfs4_delegreturn(inode, err);
5057 case -NFS4ERR_STALE_STATEID:
5058 case -NFS4ERR_EXPIRED:
5062 err = nfs4_handle_exception(server, err, &exception);
5063 } while (exception.retry);
5067 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
5068 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
5071 * sleep, with exponential backoff, and retry the LOCK operation.
5073 static unsigned long
5074 nfs4_set_lock_task_retry(unsigned long timeout)
5076 freezable_schedule_timeout_killable_unsafe(timeout);
5078 if (timeout > NFS4_LOCK_MAXTIMEOUT)
5079 return NFS4_LOCK_MAXTIMEOUT;
5083 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5085 struct inode *inode = state->inode;
5086 struct nfs_server *server = NFS_SERVER(inode);
5087 struct nfs_client *clp = server->nfs_client;
5088 struct nfs_lockt_args arg = {
5089 .fh = NFS_FH(inode),
5092 struct nfs_lockt_res res = {
5095 struct rpc_message msg = {
5096 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
5099 .rpc_cred = state->owner->so_cred,
5101 struct nfs4_lock_state *lsp;
5104 arg.lock_owner.clientid = clp->cl_clientid;
5105 status = nfs4_set_lock_state(state, request);
5108 lsp = request->fl_u.nfs4_fl.owner;
5109 arg.lock_owner.id = lsp->ls_seqid.owner_id;
5110 arg.lock_owner.s_dev = server->s_dev;
5111 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
5114 request->fl_type = F_UNLCK;
5116 case -NFS4ERR_DENIED:
5119 request->fl_ops->fl_release_private(request);
5120 request->fl_ops = NULL;
5125 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5127 struct nfs4_exception exception = { };
5131 err = _nfs4_proc_getlk(state, cmd, request);
5132 trace_nfs4_get_lock(request, state, cmd, err);
5133 err = nfs4_handle_exception(NFS_SERVER(state->inode), err,
5135 } while (exception.retry);
5139 static int do_vfs_lock(struct file *file, struct file_lock *fl)
5142 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
5144 res = posix_lock_file_wait(file, fl);
5147 res = flock_lock_file_wait(file, fl);
5155 struct nfs4_unlockdata {
5156 struct nfs_locku_args arg;
5157 struct nfs_locku_res res;
5158 struct nfs4_lock_state *lsp;
5159 struct nfs_open_context *ctx;
5160 struct file_lock fl;
5161 const struct nfs_server *server;
5162 unsigned long timestamp;
5165 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
5166 struct nfs_open_context *ctx,
5167 struct nfs4_lock_state *lsp,
5168 struct nfs_seqid *seqid)
5170 struct nfs4_unlockdata *p;
5171 struct inode *inode = lsp->ls_state->inode;
5173 p = kzalloc(sizeof(*p), GFP_NOFS);
5176 p->arg.fh = NFS_FH(inode);
5178 p->arg.seqid = seqid;
5179 p->res.seqid = seqid;
5180 p->arg.stateid = &lsp->ls_stateid;
5182 atomic_inc(&lsp->ls_count);
5183 /* Ensure we don't close file until we're done freeing locks! */
5184 p->ctx = get_nfs_open_context(ctx);
5185 memcpy(&p->fl, fl, sizeof(p->fl));
5186 p->server = NFS_SERVER(inode);
5190 static void nfs4_locku_release_calldata(void *data)
5192 struct nfs4_unlockdata *calldata = data;
5193 nfs_free_seqid(calldata->arg.seqid);
5194 nfs4_put_lock_state(calldata->lsp);
5195 put_nfs_open_context(calldata->ctx);
5199 static void nfs4_locku_done(struct rpc_task *task, void *data)
5201 struct nfs4_unlockdata *calldata = data;
5203 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
5205 switch (task->tk_status) {
5207 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
5208 &calldata->res.stateid);
5209 renew_lease(calldata->server, calldata->timestamp);
5211 case -NFS4ERR_BAD_STATEID:
5212 case -NFS4ERR_OLD_STATEID:
5213 case -NFS4ERR_STALE_STATEID:
5214 case -NFS4ERR_EXPIRED:
5217 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
5218 rpc_restart_call_prepare(task);
5220 nfs_release_seqid(calldata->arg.seqid);
5223 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
5225 struct nfs4_unlockdata *calldata = data;
5227 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
5229 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
5230 /* Note: exit _without_ running nfs4_locku_done */
5233 calldata->timestamp = jiffies;
5234 if (nfs4_setup_sequence(calldata->server,
5235 &calldata->arg.seq_args,
5236 &calldata->res.seq_res,
5238 nfs_release_seqid(calldata->arg.seqid);
5241 task->tk_action = NULL;
5243 nfs4_sequence_done(task, &calldata->res.seq_res);
5246 static const struct rpc_call_ops nfs4_locku_ops = {
5247 .rpc_call_prepare = nfs4_locku_prepare,
5248 .rpc_call_done = nfs4_locku_done,
5249 .rpc_release = nfs4_locku_release_calldata,
5252 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
5253 struct nfs_open_context *ctx,
5254 struct nfs4_lock_state *lsp,
5255 struct nfs_seqid *seqid)
5257 struct nfs4_unlockdata *data;
5258 struct rpc_message msg = {
5259 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
5260 .rpc_cred = ctx->cred,
5262 struct rpc_task_setup task_setup_data = {
5263 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
5264 .rpc_message = &msg,
5265 .callback_ops = &nfs4_locku_ops,
5266 .workqueue = nfsiod_workqueue,
5267 .flags = RPC_TASK_ASYNC,
5270 nfs4_state_protect(NFS_SERVER(lsp->ls_state->inode)->nfs_client,
5271 NFS_SP4_MACH_CRED_CLEANUP, &task_setup_data.rpc_client, &msg);
5273 /* Ensure this is an unlock - when canceling a lock, the
5274 * canceled lock is passed in, and it won't be an unlock.
5276 fl->fl_type = F_UNLCK;
5278 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
5280 nfs_free_seqid(seqid);
5281 return ERR_PTR(-ENOMEM);
5284 nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
5285 msg.rpc_argp = &data->arg;
5286 msg.rpc_resp = &data->res;
5287 task_setup_data.callback_data = data;
5288 return rpc_run_task(&task_setup_data);
5291 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
5293 struct inode *inode = state->inode;
5294 struct nfs4_state_owner *sp = state->owner;
5295 struct nfs_inode *nfsi = NFS_I(inode);
5296 struct nfs_seqid *seqid;
5297 struct nfs4_lock_state *lsp;
5298 struct rpc_task *task;
5300 unsigned char fl_flags = request->fl_flags;
5302 status = nfs4_set_lock_state(state, request);
5303 /* Unlock _before_ we do the RPC call */
5304 request->fl_flags |= FL_EXISTS;
5305 /* Exclude nfs_delegation_claim_locks() */
5306 mutex_lock(&sp->so_delegreturn_mutex);
5307 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5308 down_read(&nfsi->rwsem);
5309 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
5310 up_read(&nfsi->rwsem);
5311 mutex_unlock(&sp->so_delegreturn_mutex);
5314 up_read(&nfsi->rwsem);
5315 mutex_unlock(&sp->so_delegreturn_mutex);
5318 /* Is this a delegated lock? */
5319 lsp = request->fl_u.nfs4_fl.owner;
5320 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0)
5322 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
5326 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
5327 status = PTR_ERR(task);
5330 status = nfs4_wait_for_completion_rpc_task(task);
5333 request->fl_flags = fl_flags;
5334 trace_nfs4_unlock(request, state, F_SETLK, status);
5338 struct nfs4_lockdata {
5339 struct nfs_lock_args arg;
5340 struct nfs_lock_res res;
5341 struct nfs4_lock_state *lsp;
5342 struct nfs_open_context *ctx;
5343 struct file_lock fl;
5344 unsigned long timestamp;
5347 struct nfs_server *server;
5350 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
5351 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
5354 struct nfs4_lockdata *p;
5355 struct inode *inode = lsp->ls_state->inode;
5356 struct nfs_server *server = NFS_SERVER(inode);
5358 p = kzalloc(sizeof(*p), gfp_mask);
5362 p->arg.fh = NFS_FH(inode);
5364 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
5365 if (p->arg.open_seqid == NULL)
5367 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
5368 if (p->arg.lock_seqid == NULL)
5369 goto out_free_seqid;
5370 p->arg.lock_stateid = &lsp->ls_stateid;
5371 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
5372 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
5373 p->arg.lock_owner.s_dev = server->s_dev;
5374 p->res.lock_seqid = p->arg.lock_seqid;
5377 atomic_inc(&lsp->ls_count);
5378 p->ctx = get_nfs_open_context(ctx);
5379 memcpy(&p->fl, fl, sizeof(p->fl));
5382 nfs_free_seqid(p->arg.open_seqid);
5388 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
5390 struct nfs4_lockdata *data = calldata;
5391 struct nfs4_state *state = data->lsp->ls_state;
5393 dprintk("%s: begin!\n", __func__);
5394 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
5396 /* Do we need to do an open_to_lock_owner? */
5397 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
5398 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) {
5399 goto out_release_lock_seqid;
5401 data->arg.open_stateid = &state->open_stateid;
5402 data->arg.new_lock_owner = 1;
5403 data->res.open_seqid = data->arg.open_seqid;
5405 data->arg.new_lock_owner = 0;
5406 if (!nfs4_valid_open_stateid(state)) {
5407 data->rpc_status = -EBADF;
5408 task->tk_action = NULL;
5409 goto out_release_open_seqid;
5411 data->timestamp = jiffies;
5412 if (nfs4_setup_sequence(data->server,
5413 &data->arg.seq_args,
5417 out_release_open_seqid:
5418 nfs_release_seqid(data->arg.open_seqid);
5419 out_release_lock_seqid:
5420 nfs_release_seqid(data->arg.lock_seqid);
5422 nfs4_sequence_done(task, &data->res.seq_res);
5423 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
5426 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
5428 struct nfs4_lockdata *data = calldata;
5430 dprintk("%s: begin!\n", __func__);
5432 if (!nfs4_sequence_done(task, &data->res.seq_res))
5435 data->rpc_status = task->tk_status;
5436 if (data->arg.new_lock_owner != 0) {
5437 if (data->rpc_status == 0)
5438 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
5442 if (data->rpc_status == 0) {
5443 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
5444 set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags);
5445 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
5448 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
5451 static void nfs4_lock_release(void *calldata)
5453 struct nfs4_lockdata *data = calldata;
5455 dprintk("%s: begin!\n", __func__);
5456 nfs_free_seqid(data->arg.open_seqid);
5457 if (data->cancelled != 0) {
5458 struct rpc_task *task;
5459 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
5460 data->arg.lock_seqid);
5462 rpc_put_task_async(task);
5463 dprintk("%s: cancelling lock!\n", __func__);
5465 nfs_free_seqid(data->arg.lock_seqid);
5466 nfs4_put_lock_state(data->lsp);
5467 put_nfs_open_context(data->ctx);
5469 dprintk("%s: done!\n", __func__);
5472 static const struct rpc_call_ops nfs4_lock_ops = {
5473 .rpc_call_prepare = nfs4_lock_prepare,
5474 .rpc_call_done = nfs4_lock_done,
5475 .rpc_release = nfs4_lock_release,
5478 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
5481 case -NFS4ERR_ADMIN_REVOKED:
5482 case -NFS4ERR_BAD_STATEID:
5483 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
5484 if (new_lock_owner != 0 ||
5485 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
5486 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
5488 case -NFS4ERR_STALE_STATEID:
5489 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
5490 case -NFS4ERR_EXPIRED:
5491 nfs4_schedule_lease_recovery(server->nfs_client);
5495 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
5497 struct nfs4_lockdata *data;
5498 struct rpc_task *task;
5499 struct rpc_message msg = {
5500 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
5501 .rpc_cred = state->owner->so_cred,
5503 struct rpc_task_setup task_setup_data = {
5504 .rpc_client = NFS_CLIENT(state->inode),
5505 .rpc_message = &msg,
5506 .callback_ops = &nfs4_lock_ops,
5507 .workqueue = nfsiod_workqueue,
5508 .flags = RPC_TASK_ASYNC,
5512 dprintk("%s: begin!\n", __func__);
5513 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
5514 fl->fl_u.nfs4_fl.owner,
5515 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
5519 data->arg.block = 1;
5520 nfs4_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
5521 msg.rpc_argp = &data->arg;
5522 msg.rpc_resp = &data->res;
5523 task_setup_data.callback_data = data;
5524 if (recovery_type > NFS_LOCK_NEW) {
5525 if (recovery_type == NFS_LOCK_RECLAIM)
5526 data->arg.reclaim = NFS_LOCK_RECLAIM;
5527 nfs4_set_sequence_privileged(&data->arg.seq_args);
5529 task = rpc_run_task(&task_setup_data);
5531 return PTR_ERR(task);
5532 ret = nfs4_wait_for_completion_rpc_task(task);
5534 ret = data->rpc_status;
5536 nfs4_handle_setlk_error(data->server, data->lsp,
5537 data->arg.new_lock_owner, ret);
5539 data->cancelled = 1;
5541 dprintk("%s: done, ret = %d!\n", __func__, ret);
5545 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
5547 struct nfs_server *server = NFS_SERVER(state->inode);
5548 struct nfs4_exception exception = {
5549 .inode = state->inode,
5554 /* Cache the lock if possible... */
5555 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
5557 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
5558 trace_nfs4_lock_reclaim(request, state, F_SETLK, err);
5559 if (err != -NFS4ERR_DELAY)
5561 nfs4_handle_exception(server, err, &exception);
5562 } while (exception.retry);
5566 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
5568 struct nfs_server *server = NFS_SERVER(state->inode);
5569 struct nfs4_exception exception = {
5570 .inode = state->inode,
5574 err = nfs4_set_lock_state(state, request);
5577 if (!recover_lost_locks) {
5578 set_bit(NFS_LOCK_LOST, &request->fl_u.nfs4_fl.owner->ls_flags);
5582 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
5584 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
5585 trace_nfs4_lock_expired(request, state, F_SETLK, err);
5589 case -NFS4ERR_GRACE:
5590 case -NFS4ERR_DELAY:
5591 nfs4_handle_exception(server, err, &exception);
5594 } while (exception.retry);
5599 #if defined(CONFIG_NFS_V4_1)
5601 * nfs41_check_expired_locks - possibly free a lock stateid
5603 * @state: NFSv4 state for an inode
5605 * Returns NFS_OK if recovery for this stateid is now finished.
5606 * Otherwise a negative NFS4ERR value is returned.
5608 static int nfs41_check_expired_locks(struct nfs4_state *state)
5610 int status, ret = -NFS4ERR_BAD_STATEID;
5611 struct nfs4_lock_state *lsp;
5612 struct nfs_server *server = NFS_SERVER(state->inode);
5614 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
5615 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
5616 struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
5618 status = nfs41_test_stateid(server,
5621 trace_nfs4_test_lock_stateid(state, lsp, status);
5622 if (status != NFS_OK) {
5623 /* Free the stateid unless the server
5624 * informs us the stateid is unrecognized. */
5625 if (status != -NFS4ERR_BAD_STATEID)
5626 nfs41_free_stateid(server,
5629 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
5638 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
5640 int status = NFS_OK;
5642 if (test_bit(LK_STATE_IN_USE, &state->flags))
5643 status = nfs41_check_expired_locks(state);
5644 if (status != NFS_OK)
5645 status = nfs4_lock_expired(state, request);
5650 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5652 struct nfs4_state_owner *sp = state->owner;
5653 struct nfs_inode *nfsi = NFS_I(state->inode);
5654 unsigned char fl_flags = request->fl_flags;
5656 int status = -ENOLCK;
5658 if ((fl_flags & FL_POSIX) &&
5659 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
5661 /* Is this a delegated open? */
5662 status = nfs4_set_lock_state(state, request);
5665 request->fl_flags |= FL_ACCESS;
5666 status = do_vfs_lock(request->fl_file, request);
5669 down_read(&nfsi->rwsem);
5670 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
5671 /* Yes: cache locks! */
5672 /* ...but avoid races with delegation recall... */
5673 request->fl_flags = fl_flags & ~FL_SLEEP;
5674 status = do_vfs_lock(request->fl_file, request);
5677 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
5678 up_read(&nfsi->rwsem);
5679 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
5682 down_read(&nfsi->rwsem);
5683 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
5684 status = -NFS4ERR_DELAY;
5687 /* Note: we always want to sleep here! */
5688 request->fl_flags = fl_flags | FL_SLEEP;
5689 if (do_vfs_lock(request->fl_file, request) < 0)
5690 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
5691 "manager!\n", __func__);
5693 up_read(&nfsi->rwsem);
5695 request->fl_flags = fl_flags;
5699 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5701 struct nfs4_exception exception = {
5703 .inode = state->inode,
5708 err = _nfs4_proc_setlk(state, cmd, request);
5709 trace_nfs4_set_lock(request, state, cmd, err);
5710 if (err == -NFS4ERR_DENIED)
5712 err = nfs4_handle_exception(NFS_SERVER(state->inode),
5714 } while (exception.retry);
5719 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
5721 struct nfs_open_context *ctx;
5722 struct nfs4_state *state;
5723 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
5726 /* verify open state */
5727 ctx = nfs_file_open_context(filp);
5730 if (request->fl_start < 0 || request->fl_end < 0)
5733 if (IS_GETLK(cmd)) {
5735 return nfs4_proc_getlk(state, F_GETLK, request);
5739 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
5742 if (request->fl_type == F_UNLCK) {
5744 return nfs4_proc_unlck(state, cmd, request);
5751 * Don't rely on the VFS having checked the file open mode,
5752 * since it won't do this for flock() locks.
5754 switch (request->fl_type) {
5756 if (!(filp->f_mode & FMODE_READ))
5760 if (!(filp->f_mode & FMODE_WRITE))
5765 status = nfs4_proc_setlk(state, cmd, request);
5766 if ((status != -EAGAIN) || IS_SETLK(cmd))
5768 timeout = nfs4_set_lock_task_retry(timeout);
5769 status = -ERESTARTSYS;
5772 } while(status < 0);
5776 int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid)
5778 struct nfs_server *server = NFS_SERVER(state->inode);
5781 err = nfs4_set_lock_state(state, fl);
5784 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
5785 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
5788 struct nfs_release_lockowner_data {
5789 struct nfs4_lock_state *lsp;
5790 struct nfs_server *server;
5791 struct nfs_release_lockowner_args args;
5792 struct nfs4_sequence_args seq_args;
5793 struct nfs4_sequence_res seq_res;
5796 static void nfs4_release_lockowner_prepare(struct rpc_task *task, void *calldata)
5798 struct nfs_release_lockowner_data *data = calldata;
5799 nfs40_setup_sequence(data->server,
5800 &data->seq_args, &data->seq_res, task);
5803 static void nfs4_release_lockowner_done(struct rpc_task *task, void *calldata)
5805 struct nfs_release_lockowner_data *data = calldata;
5806 nfs40_sequence_done(task, &data->seq_res);
5809 static void nfs4_release_lockowner_release(void *calldata)
5811 struct nfs_release_lockowner_data *data = calldata;
5812 nfs4_free_lock_state(data->server, data->lsp);
5816 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5817 .rpc_call_prepare = nfs4_release_lockowner_prepare,
5818 .rpc_call_done = nfs4_release_lockowner_done,
5819 .rpc_release = nfs4_release_lockowner_release,
5822 static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp)
5824 struct nfs_release_lockowner_data *data;
5825 struct rpc_message msg = {
5826 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5829 if (server->nfs_client->cl_mvops->minor_version != 0)
5832 data = kmalloc(sizeof(*data), GFP_NOFS);
5835 nfs4_init_sequence(&data->seq_args, &data->seq_res, 0);
5837 data->server = server;
5838 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5839 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5840 data->args.lock_owner.s_dev = server->s_dev;
5842 msg.rpc_argp = &data->args;
5843 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5847 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5849 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5850 const void *buf, size_t buflen,
5851 int flags, int type)
5853 if (strcmp(key, "") != 0)
5856 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5859 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5860 void *buf, size_t buflen, int type)
5862 if (strcmp(key, "") != 0)
5865 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5868 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5869 size_t list_len, const char *name,
5870 size_t name_len, int type)
5872 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5874 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5877 if (list && len <= list_len)
5878 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5882 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5883 static inline int nfs4_server_supports_labels(struct nfs_server *server)
5885 return server->caps & NFS_CAP_SECURITY_LABEL;
5888 static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key,
5889 const void *buf, size_t buflen,
5890 int flags, int type)
5892 if (security_ismaclabel(key))
5893 return nfs4_set_security_label(dentry, buf, buflen);
5898 static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key,
5899 void *buf, size_t buflen, int type)
5901 if (security_ismaclabel(key))
5902 return nfs4_get_security_label(dentry->d_inode, buf, buflen);
5906 static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list,
5907 size_t list_len, const char *name,
5908 size_t name_len, int type)
5912 if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) {
5913 len = security_inode_listsecurity(dentry->d_inode, NULL, 0);
5914 if (list && len <= list_len)
5915 security_inode_listsecurity(dentry->d_inode, list, len);
5920 static const struct xattr_handler nfs4_xattr_nfs4_label_handler = {
5921 .prefix = XATTR_SECURITY_PREFIX,
5922 .list = nfs4_xattr_list_nfs4_label,
5923 .get = nfs4_xattr_get_nfs4_label,
5924 .set = nfs4_xattr_set_nfs4_label,
5930 * nfs_fhget will use either the mounted_on_fileid or the fileid
5932 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5934 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5935 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5936 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5937 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5940 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5941 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5942 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5946 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5947 const struct qstr *name,
5948 struct nfs4_fs_locations *fs_locations,
5951 struct nfs_server *server = NFS_SERVER(dir);
5953 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5955 struct nfs4_fs_locations_arg args = {
5956 .dir_fh = NFS_FH(dir),
5961 struct nfs4_fs_locations_res res = {
5962 .fs_locations = fs_locations,
5964 struct rpc_message msg = {
5965 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5971 dprintk("%s: start\n", __func__);
5973 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5974 * is not supported */
5975 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5976 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5978 bitmask[0] |= FATTR4_WORD0_FILEID;
5980 nfs_fattr_init(&fs_locations->fattr);
5981 fs_locations->server = server;
5982 fs_locations->nlocations = 0;
5983 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5984 dprintk("%s: returned status = %d\n", __func__, status);
5988 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5989 const struct qstr *name,
5990 struct nfs4_fs_locations *fs_locations,
5993 struct nfs4_exception exception = { };
5996 err = _nfs4_proc_fs_locations(client, dir, name,
5997 fs_locations, page);
5998 trace_nfs4_get_fs_locations(dir, name, err);
5999 err = nfs4_handle_exception(NFS_SERVER(dir), err,
6001 } while (exception.retry);
6006 * This operation also signals the server that this client is
6007 * performing migration recovery. The server can stop returning
6008 * NFS4ERR_LEASE_MOVED to this client. A RENEW operation is
6009 * appended to this compound to identify the client ID which is
6010 * performing recovery.
6012 static int _nfs40_proc_get_locations(struct inode *inode,
6013 struct nfs4_fs_locations *locations,
6014 struct page *page, struct rpc_cred *cred)
6016 struct nfs_server *server = NFS_SERVER(inode);
6017 struct rpc_clnt *clnt = server->client;
6019 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
6021 struct nfs4_fs_locations_arg args = {
6022 .clientid = server->nfs_client->cl_clientid,
6023 .fh = NFS_FH(inode),
6026 .migration = 1, /* skip LOOKUP */
6027 .renew = 1, /* append RENEW */
6029 struct nfs4_fs_locations_res res = {
6030 .fs_locations = locations,
6034 struct rpc_message msg = {
6035 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
6040 unsigned long now = jiffies;
6043 nfs_fattr_init(&locations->fattr);
6044 locations->server = server;
6045 locations->nlocations = 0;
6047 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0);
6048 nfs4_set_sequence_privileged(&args.seq_args);
6049 status = nfs4_call_sync_sequence(clnt, server, &msg,
6050 &args.seq_args, &res.seq_res);
6054 renew_lease(server, now);
6058 #ifdef CONFIG_NFS_V4_1
6061 * This operation also signals the server that this client is
6062 * performing migration recovery. The server can stop asserting
6063 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID
6064 * performing this operation is identified in the SEQUENCE
6065 * operation in this compound.
6067 * When the client supports GETATTR(fs_locations_info), it can
6068 * be plumbed in here.
6070 static int _nfs41_proc_get_locations(struct inode *inode,
6071 struct nfs4_fs_locations *locations,
6072 struct page *page, struct rpc_cred *cred)
6074 struct nfs_server *server = NFS_SERVER(inode);
6075 struct rpc_clnt *clnt = server->client;
6077 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
6079 struct nfs4_fs_locations_arg args = {
6080 .fh = NFS_FH(inode),
6083 .migration = 1, /* skip LOOKUP */
6085 struct nfs4_fs_locations_res res = {
6086 .fs_locations = locations,
6089 struct rpc_message msg = {
6090 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
6097 nfs_fattr_init(&locations->fattr);
6098 locations->server = server;
6099 locations->nlocations = 0;
6101 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0);
6102 nfs4_set_sequence_privileged(&args.seq_args);
6103 status = nfs4_call_sync_sequence(clnt, server, &msg,
6104 &args.seq_args, &res.seq_res);
6105 if (status == NFS4_OK &&
6106 res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED)
6107 status = -NFS4ERR_LEASE_MOVED;
6111 #endif /* CONFIG_NFS_V4_1 */
6114 * nfs4_proc_get_locations - discover locations for a migrated FSID
6115 * @inode: inode on FSID that is migrating
6116 * @locations: result of query
6118 * @cred: credential to use for this operation
6120 * Returns NFS4_OK on success, a negative NFS4ERR status code if the
6121 * operation failed, or a negative errno if a local error occurred.
6123 * On success, "locations" is filled in, but if the server has
6124 * no locations information, NFS_ATTR_FATTR_V4_LOCATIONS is not
6127 * -NFS4ERR_LEASE_MOVED is returned if the server still has leases
6128 * from this client that require migration recovery.
6130 int nfs4_proc_get_locations(struct inode *inode,
6131 struct nfs4_fs_locations *locations,
6132 struct page *page, struct rpc_cred *cred)
6134 struct nfs_server *server = NFS_SERVER(inode);
6135 struct nfs_client *clp = server->nfs_client;
6136 const struct nfs4_mig_recovery_ops *ops =
6137 clp->cl_mvops->mig_recovery_ops;
6138 struct nfs4_exception exception = { };
6141 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__,
6142 (unsigned long long)server->fsid.major,
6143 (unsigned long long)server->fsid.minor,
6145 nfs_display_fhandle(NFS_FH(inode), __func__);
6148 status = ops->get_locations(inode, locations, page, cred);
6149 if (status != -NFS4ERR_DELAY)
6151 nfs4_handle_exception(server, status, &exception);
6152 } while (exception.retry);
6157 * This operation also signals the server that this client is
6158 * performing "lease moved" recovery. The server can stop
6159 * returning NFS4ERR_LEASE_MOVED to this client. A RENEW operation
6160 * is appended to this compound to identify the client ID which is
6161 * performing recovery.
6163 static int _nfs40_proc_fsid_present(struct inode *inode, struct rpc_cred *cred)
6165 struct nfs_server *server = NFS_SERVER(inode);
6166 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
6167 struct rpc_clnt *clnt = server->client;
6168 struct nfs4_fsid_present_arg args = {
6169 .fh = NFS_FH(inode),
6170 .clientid = clp->cl_clientid,
6171 .renew = 1, /* append RENEW */
6173 struct nfs4_fsid_present_res res = {
6176 struct rpc_message msg = {
6177 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT],
6182 unsigned long now = jiffies;
6185 res.fh = nfs_alloc_fhandle();
6189 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0);
6190 nfs4_set_sequence_privileged(&args.seq_args);
6191 status = nfs4_call_sync_sequence(clnt, server, &msg,
6192 &args.seq_args, &res.seq_res);
6193 nfs_free_fhandle(res.fh);
6197 do_renew_lease(clp, now);
6201 #ifdef CONFIG_NFS_V4_1
6204 * This operation also signals the server that this client is
6205 * performing "lease moved" recovery. The server can stop asserting
6206 * SEQ4_STATUS_LEASE_MOVED for this client. The client ID performing
6207 * this operation is identified in the SEQUENCE operation in this
6210 static int _nfs41_proc_fsid_present(struct inode *inode, struct rpc_cred *cred)
6212 struct nfs_server *server = NFS_SERVER(inode);
6213 struct rpc_clnt *clnt = server->client;
6214 struct nfs4_fsid_present_arg args = {
6215 .fh = NFS_FH(inode),
6217 struct nfs4_fsid_present_res res = {
6219 struct rpc_message msg = {
6220 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSID_PRESENT],
6227 res.fh = nfs_alloc_fhandle();
6231 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0);
6232 nfs4_set_sequence_privileged(&args.seq_args);
6233 status = nfs4_call_sync_sequence(clnt, server, &msg,
6234 &args.seq_args, &res.seq_res);
6235 nfs_free_fhandle(res.fh);
6236 if (status == NFS4_OK &&
6237 res.seq_res.sr_status_flags & SEQ4_STATUS_LEASE_MOVED)
6238 status = -NFS4ERR_LEASE_MOVED;
6242 #endif /* CONFIG_NFS_V4_1 */
6245 * nfs4_proc_fsid_present - Is this FSID present or absent on server?
6246 * @inode: inode on FSID to check
6247 * @cred: credential to use for this operation
6249 * Server indicates whether the FSID is present, moved, or not
6250 * recognized. This operation is necessary to clear a LEASE_MOVED
6251 * condition for this client ID.
6253 * Returns NFS4_OK if the FSID is present on this server,
6254 * -NFS4ERR_MOVED if the FSID is no longer present, a negative
6255 * NFS4ERR code if some error occurred on the server, or a
6256 * negative errno if a local failure occurred.
6258 int nfs4_proc_fsid_present(struct inode *inode, struct rpc_cred *cred)
6260 struct nfs_server *server = NFS_SERVER(inode);
6261 struct nfs_client *clp = server->nfs_client;
6262 const struct nfs4_mig_recovery_ops *ops =
6263 clp->cl_mvops->mig_recovery_ops;
6264 struct nfs4_exception exception = { };
6267 dprintk("%s: FSID %llx:%llx on \"%s\"\n", __func__,
6268 (unsigned long long)server->fsid.major,
6269 (unsigned long long)server->fsid.minor,
6271 nfs_display_fhandle(NFS_FH(inode), __func__);
6274 status = ops->fsid_present(inode, cred);
6275 if (status != -NFS4ERR_DELAY)
6277 nfs4_handle_exception(server, status, &exception);
6278 } while (exception.retry);
6283 * If 'use_integrity' is true and the state managment nfs_client
6284 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
6285 * and the machine credential as per RFC3530bis and RFC5661 Security
6286 * Considerations sections. Otherwise, just use the user cred with the
6287 * filesystem's rpc_client.
6289 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity)
6292 struct nfs4_secinfo_arg args = {
6293 .dir_fh = NFS_FH(dir),
6296 struct nfs4_secinfo_res res = {
6299 struct rpc_message msg = {
6300 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
6304 struct rpc_clnt *clnt = NFS_SERVER(dir)->client;
6305 struct rpc_cred *cred = NULL;
6307 if (use_integrity) {
6308 clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient;
6309 cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client);
6310 msg.rpc_cred = cred;
6313 dprintk("NFS call secinfo %s\n", name->name);
6315 nfs4_state_protect(NFS_SERVER(dir)->nfs_client,
6316 NFS_SP4_MACH_CRED_SECINFO, &clnt, &msg);
6318 status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args,
6320 dprintk("NFS reply secinfo: %d\n", status);
6328 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
6329 struct nfs4_secinfo_flavors *flavors)
6331 struct nfs4_exception exception = { };
6334 err = -NFS4ERR_WRONGSEC;
6336 /* try to use integrity protection with machine cred */
6337 if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client))
6338 err = _nfs4_proc_secinfo(dir, name, flavors, true);
6341 * if unable to use integrity protection, or SECINFO with
6342 * integrity protection returns NFS4ERR_WRONGSEC (which is
6343 * disallowed by spec, but exists in deployed servers) use
6344 * the current filesystem's rpc_client and the user cred.
6346 if (err == -NFS4ERR_WRONGSEC)
6347 err = _nfs4_proc_secinfo(dir, name, flavors, false);
6349 trace_nfs4_secinfo(dir, name, err);
6350 err = nfs4_handle_exception(NFS_SERVER(dir), err,
6352 } while (exception.retry);
6356 #ifdef CONFIG_NFS_V4_1
6358 * Check the exchange flags returned by the server for invalid flags, having
6359 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
6362 static int nfs4_check_cl_exchange_flags(u32 flags)
6364 if (flags & ~EXCHGID4_FLAG_MASK_R)
6366 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
6367 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
6369 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
6373 return -NFS4ERR_INVAL;
6377 nfs41_same_server_scope(struct nfs41_server_scope *a,
6378 struct nfs41_server_scope *b)
6380 if (a->server_scope_sz == b->server_scope_sz &&
6381 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
6388 * nfs4_proc_bind_conn_to_session()
6390 * The 4.1 client currently uses the same TCP connection for the
6391 * fore and backchannel.
6393 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
6396 struct nfs41_bind_conn_to_session_res res;
6397 struct rpc_message msg = {
6399 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
6405 dprintk("--> %s\n", __func__);
6407 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
6408 if (unlikely(res.session == NULL)) {
6413 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6414 trace_nfs4_bind_conn_to_session(clp, status);
6416 if (memcmp(res.session->sess_id.data,
6417 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
6418 dprintk("NFS: %s: Session ID mismatch\n", __func__);
6422 if (res.dir != NFS4_CDFS4_BOTH) {
6423 dprintk("NFS: %s: Unexpected direction from server\n",
6428 if (res.use_conn_in_rdma_mode) {
6429 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6438 dprintk("<-- %s status= %d\n", __func__, status);
6443 * Minimum set of SP4_MACH_CRED operations from RFC 5661 in the enforce map
6444 * and operations we'd like to see to enable certain features in the allow map
6446 static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = {
6447 .how = SP4_MACH_CRED,
6448 .enforce.u.words = {
6449 [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) |
6450 1 << (OP_EXCHANGE_ID - 32) |
6451 1 << (OP_CREATE_SESSION - 32) |
6452 1 << (OP_DESTROY_SESSION - 32) |
6453 1 << (OP_DESTROY_CLIENTID - 32)
6456 [0] = 1 << (OP_CLOSE) |
6459 [1] = 1 << (OP_SECINFO - 32) |
6460 1 << (OP_SECINFO_NO_NAME - 32) |
6461 1 << (OP_TEST_STATEID - 32) |
6462 1 << (OP_FREE_STATEID - 32) |
6463 1 << (OP_WRITE - 32)
6468 * Select the state protection mode for client `clp' given the server results
6469 * from exchange_id in `sp'.
6471 * Returns 0 on success, negative errno otherwise.
6473 static int nfs4_sp4_select_mode(struct nfs_client *clp,
6474 struct nfs41_state_protection *sp)
6476 static const u32 supported_enforce[NFS4_OP_MAP_NUM_WORDS] = {
6477 [1] = 1 << (OP_BIND_CONN_TO_SESSION - 32) |
6478 1 << (OP_EXCHANGE_ID - 32) |
6479 1 << (OP_CREATE_SESSION - 32) |
6480 1 << (OP_DESTROY_SESSION - 32) |
6481 1 << (OP_DESTROY_CLIENTID - 32)
6485 if (sp->how == SP4_MACH_CRED) {
6486 /* Print state protect result */
6487 dfprintk(MOUNT, "Server SP4_MACH_CRED support:\n");
6488 for (i = 0; i <= LAST_NFS4_OP; i++) {
6489 if (test_bit(i, sp->enforce.u.longs))
6490 dfprintk(MOUNT, " enforce op %d\n", i);
6491 if (test_bit(i, sp->allow.u.longs))
6492 dfprintk(MOUNT, " allow op %d\n", i);
6495 /* make sure nothing is on enforce list that isn't supported */
6496 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++) {
6497 if (sp->enforce.u.words[i] & ~supported_enforce[i]) {
6498 dfprintk(MOUNT, "sp4_mach_cred: disabled\n");
6504 * Minimal mode - state operations are allowed to use machine
6505 * credential. Note this already happens by default, so the
6506 * client doesn't have to do anything more than the negotiation.
6508 * NOTE: we don't care if EXCHANGE_ID is in the list -
6509 * we're already using the machine cred for exchange_id
6510 * and will never use a different cred.
6512 if (test_bit(OP_BIND_CONN_TO_SESSION, sp->enforce.u.longs) &&
6513 test_bit(OP_CREATE_SESSION, sp->enforce.u.longs) &&
6514 test_bit(OP_DESTROY_SESSION, sp->enforce.u.longs) &&
6515 test_bit(OP_DESTROY_CLIENTID, sp->enforce.u.longs)) {
6516 dfprintk(MOUNT, "sp4_mach_cred:\n");
6517 dfprintk(MOUNT, " minimal mode enabled\n");
6518 set_bit(NFS_SP4_MACH_CRED_MINIMAL, &clp->cl_sp4_flags);
6520 dfprintk(MOUNT, "sp4_mach_cred: disabled\n");
6524 if (test_bit(OP_CLOSE, sp->allow.u.longs) &&
6525 test_bit(OP_LOCKU, sp->allow.u.longs)) {
6526 dfprintk(MOUNT, " cleanup mode enabled\n");
6527 set_bit(NFS_SP4_MACH_CRED_CLEANUP, &clp->cl_sp4_flags);
6530 if (test_bit(OP_SECINFO, sp->allow.u.longs) &&
6531 test_bit(OP_SECINFO_NO_NAME, sp->allow.u.longs)) {
6532 dfprintk(MOUNT, " secinfo mode enabled\n");
6533 set_bit(NFS_SP4_MACH_CRED_SECINFO, &clp->cl_sp4_flags);
6536 if (test_bit(OP_TEST_STATEID, sp->allow.u.longs) &&
6537 test_bit(OP_FREE_STATEID, sp->allow.u.longs)) {
6538 dfprintk(MOUNT, " stateid mode enabled\n");
6539 set_bit(NFS_SP4_MACH_CRED_STATEID, &clp->cl_sp4_flags);
6542 if (test_bit(OP_WRITE, sp->allow.u.longs)) {
6543 dfprintk(MOUNT, " write mode enabled\n");
6544 set_bit(NFS_SP4_MACH_CRED_WRITE, &clp->cl_sp4_flags);
6547 if (test_bit(OP_COMMIT, sp->allow.u.longs)) {
6548 dfprintk(MOUNT, " commit mode enabled\n");
6549 set_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags);
6557 * _nfs4_proc_exchange_id()
6559 * Wrapper for EXCHANGE_ID operation.
6561 static int _nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred,
6564 nfs4_verifier verifier;
6565 struct nfs41_exchange_id_args args = {
6566 .verifier = &verifier,
6568 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER |
6569 EXCHGID4_FLAG_BIND_PRINC_STATEID,
6571 struct nfs41_exchange_id_res res = {
6575 struct rpc_message msg = {
6576 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
6582 nfs4_init_boot_verifier(clp, &verifier);
6583 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
6585 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6586 clp->cl_rpcclient->cl_auth->au_ops->au_name,
6587 args.id_len, args.id);
6589 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
6591 if (unlikely(res.server_owner == NULL)) {
6596 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
6598 if (unlikely(res.server_scope == NULL)) {
6600 goto out_server_owner;
6603 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
6604 if (unlikely(res.impl_id == NULL)) {
6606 goto out_server_scope;
6611 args.state_protect.how = SP4_NONE;
6615 args.state_protect = nfs4_sp4_mach_cred_request;
6622 goto out_server_scope;
6625 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6626 trace_nfs4_exchange_id(clp, status);
6628 status = nfs4_check_cl_exchange_flags(res.flags);
6631 status = nfs4_sp4_select_mode(clp, &res.state_protect);
6634 clp->cl_clientid = res.clientid;
6635 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
6636 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
6637 clp->cl_seqid = res.seqid;
6639 kfree(clp->cl_serverowner);
6640 clp->cl_serverowner = res.server_owner;
6641 res.server_owner = NULL;
6643 /* use the most recent implementation id */
6644 kfree(clp->cl_implid);
6645 clp->cl_implid = res.impl_id;
6647 if (clp->cl_serverscope != NULL &&
6648 !nfs41_same_server_scope(clp->cl_serverscope,
6649 res.server_scope)) {
6650 dprintk("%s: server_scope mismatch detected\n",
6652 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
6653 kfree(clp->cl_serverscope);
6654 clp->cl_serverscope = NULL;
6657 if (clp->cl_serverscope == NULL) {
6658 clp->cl_serverscope = res.server_scope;
6665 kfree(res.server_owner);
6667 kfree(res.server_scope);
6669 if (clp->cl_implid != NULL)
6670 dprintk("NFS reply exchange_id: Server Implementation ID: "
6671 "domain: %s, name: %s, date: %llu,%u\n",
6672 clp->cl_implid->domain, clp->cl_implid->name,
6673 clp->cl_implid->date.seconds,
6674 clp->cl_implid->date.nseconds);
6675 dprintk("NFS reply exchange_id: %d\n", status);
6680 * nfs4_proc_exchange_id()
6682 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6684 * Since the clientid has expired, all compounds using sessions
6685 * associated with the stale clientid will be returning
6686 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6687 * be in some phase of session reset.
6689 * Will attempt to negotiate SP4_MACH_CRED if krb5i / krb5p auth is used.
6691 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
6693 rpc_authflavor_t authflavor = clp->cl_rpcclient->cl_auth->au_flavor;
6696 /* try SP4_MACH_CRED if krb5i/p */
6697 if (authflavor == RPC_AUTH_GSS_KRB5I ||
6698 authflavor == RPC_AUTH_GSS_KRB5P) {
6699 status = _nfs4_proc_exchange_id(clp, cred, SP4_MACH_CRED);
6705 return _nfs4_proc_exchange_id(clp, cred, SP4_NONE);
6708 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
6709 struct rpc_cred *cred)
6711 struct rpc_message msg = {
6712 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
6718 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6719 trace_nfs4_destroy_clientid(clp, status);
6721 dprintk("NFS: Got error %d from the server %s on "
6722 "DESTROY_CLIENTID.", status, clp->cl_hostname);
6726 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
6727 struct rpc_cred *cred)
6732 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
6733 ret = _nfs4_proc_destroy_clientid(clp, cred);
6735 case -NFS4ERR_DELAY:
6736 case -NFS4ERR_CLIENTID_BUSY:
6746 int nfs4_destroy_clientid(struct nfs_client *clp)
6748 struct rpc_cred *cred;
6751 if (clp->cl_mvops->minor_version < 1)
6753 if (clp->cl_exchange_flags == 0)
6755 if (clp->cl_preserve_clid)
6757 cred = nfs4_get_clid_cred(clp);
6758 ret = nfs4_proc_destroy_clientid(clp, cred);
6763 case -NFS4ERR_STALE_CLIENTID:
6764 clp->cl_exchange_flags = 0;
6770 struct nfs4_get_lease_time_data {
6771 struct nfs4_get_lease_time_args *args;
6772 struct nfs4_get_lease_time_res *res;
6773 struct nfs_client *clp;
6776 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
6779 struct nfs4_get_lease_time_data *data =
6780 (struct nfs4_get_lease_time_data *)calldata;
6782 dprintk("--> %s\n", __func__);
6783 /* just setup sequence, do not trigger session recovery
6784 since we're invoked within one */
6785 nfs41_setup_sequence(data->clp->cl_session,
6786 &data->args->la_seq_args,
6787 &data->res->lr_seq_res,
6789 dprintk("<-- %s\n", __func__);
6793 * Called from nfs4_state_manager thread for session setup, so don't recover
6794 * from sequence operation or clientid errors.
6796 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
6798 struct nfs4_get_lease_time_data *data =
6799 (struct nfs4_get_lease_time_data *)calldata;
6801 dprintk("--> %s\n", __func__);
6802 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
6804 switch (task->tk_status) {
6805 case -NFS4ERR_DELAY:
6806 case -NFS4ERR_GRACE:
6807 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
6808 rpc_delay(task, NFS4_POLL_RETRY_MIN);
6809 task->tk_status = 0;
6811 case -NFS4ERR_RETRY_UNCACHED_REP:
6812 rpc_restart_call_prepare(task);
6815 dprintk("<-- %s\n", __func__);
6818 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
6819 .rpc_call_prepare = nfs4_get_lease_time_prepare,
6820 .rpc_call_done = nfs4_get_lease_time_done,
6823 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
6825 struct rpc_task *task;
6826 struct nfs4_get_lease_time_args args;
6827 struct nfs4_get_lease_time_res res = {
6828 .lr_fsinfo = fsinfo,
6830 struct nfs4_get_lease_time_data data = {
6835 struct rpc_message msg = {
6836 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
6840 struct rpc_task_setup task_setup = {
6841 .rpc_client = clp->cl_rpcclient,
6842 .rpc_message = &msg,
6843 .callback_ops = &nfs4_get_lease_time_ops,
6844 .callback_data = &data,
6845 .flags = RPC_TASK_TIMEOUT,
6849 nfs4_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
6850 nfs4_set_sequence_privileged(&args.la_seq_args);
6851 dprintk("--> %s\n", __func__);
6852 task = rpc_run_task(&task_setup);
6855 status = PTR_ERR(task);
6857 status = task->tk_status;
6860 dprintk("<-- %s return %d\n", __func__, status);
6866 * Initialize the values to be used by the client in CREATE_SESSION
6867 * If nfs4_init_session set the fore channel request and response sizes,
6870 * Set the back channel max_resp_sz_cached to zero to force the client to
6871 * always set csa_cachethis to FALSE because the current implementation
6872 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6874 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
6876 unsigned int max_rqst_sz, max_resp_sz;
6878 max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead;
6879 max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead;
6881 /* Fore channel attributes */
6882 args->fc_attrs.max_rqst_sz = max_rqst_sz;
6883 args->fc_attrs.max_resp_sz = max_resp_sz;
6884 args->fc_attrs.max_ops = NFS4_MAX_OPS;
6885 args->fc_attrs.max_reqs = max_session_slots;
6887 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6888 "max_ops=%u max_reqs=%u\n",
6890 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
6891 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
6893 /* Back channel attributes */
6894 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
6895 args->bc_attrs.max_resp_sz = PAGE_SIZE;
6896 args->bc_attrs.max_resp_sz_cached = 0;
6897 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
6898 args->bc_attrs.max_reqs = 1;
6900 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6901 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6903 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
6904 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
6905 args->bc_attrs.max_reqs);
6908 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
6910 struct nfs4_channel_attrs *sent = &args->fc_attrs;
6911 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
6913 if (rcvd->max_resp_sz > sent->max_resp_sz)
6916 * Our requested max_ops is the minimum we need; we're not
6917 * prepared to break up compounds into smaller pieces than that.
6918 * So, no point even trying to continue if the server won't
6921 if (rcvd->max_ops < sent->max_ops)
6923 if (rcvd->max_reqs == 0)
6925 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
6926 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
6930 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
6932 struct nfs4_channel_attrs *sent = &args->bc_attrs;
6933 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
6935 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
6937 if (rcvd->max_resp_sz < sent->max_resp_sz)
6939 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
6941 /* These would render the backchannel useless: */
6942 if (rcvd->max_ops != sent->max_ops)
6944 if (rcvd->max_reqs != sent->max_reqs)
6949 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
6950 struct nfs4_session *session)
6954 ret = nfs4_verify_fore_channel_attrs(args, session);
6957 return nfs4_verify_back_channel_attrs(args, session);
6960 static int _nfs4_proc_create_session(struct nfs_client *clp,
6961 struct rpc_cred *cred)
6963 struct nfs4_session *session = clp->cl_session;
6964 struct nfs41_create_session_args args = {
6966 .cb_program = NFS4_CALLBACK,
6968 struct nfs41_create_session_res res = {
6971 struct rpc_message msg = {
6972 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
6979 nfs4_init_channel_attrs(&args);
6980 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
6982 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6983 trace_nfs4_create_session(clp, status);
6986 /* Verify the session's negotiated channel_attrs values */
6987 status = nfs4_verify_channel_attrs(&args, session);
6988 /* Increment the clientid slot sequence id */
6996 * Issues a CREATE_SESSION operation to the server.
6997 * It is the responsibility of the caller to verify the session is
6998 * expired before calling this routine.
7000 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
7004 struct nfs4_session *session = clp->cl_session;
7006 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
7008 status = _nfs4_proc_create_session(clp, cred);
7012 /* Init or reset the session slot tables */
7013 status = nfs4_setup_session_slot_tables(session);
7014 dprintk("slot table setup returned %d\n", status);
7018 ptr = (unsigned *)&session->sess_id.data[0];
7019 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
7020 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
7022 dprintk("<-- %s\n", __func__);
7027 * Issue the over-the-wire RPC DESTROY_SESSION.
7028 * The caller must serialize access to this routine.
7030 int nfs4_proc_destroy_session(struct nfs4_session *session,
7031 struct rpc_cred *cred)
7033 struct rpc_message msg = {
7034 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
7035 .rpc_argp = session,
7040 dprintk("--> nfs4_proc_destroy_session\n");
7042 /* session is still being setup */
7043 if (session->clp->cl_cons_state != NFS_CS_READY)
7046 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
7047 trace_nfs4_destroy_session(session->clp, status);
7050 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
7051 "Session has been destroyed regardless...\n", status);
7053 dprintk("<-- nfs4_proc_destroy_session\n");
7058 * Renew the cl_session lease.
7060 struct nfs4_sequence_data {
7061 struct nfs_client *clp;
7062 struct nfs4_sequence_args args;
7063 struct nfs4_sequence_res res;
7066 static void nfs41_sequence_release(void *data)
7068 struct nfs4_sequence_data *calldata = data;
7069 struct nfs_client *clp = calldata->clp;
7071 if (atomic_read(&clp->cl_count) > 1)
7072 nfs4_schedule_state_renewal(clp);
7073 nfs_put_client(clp);
7077 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
7079 switch(task->tk_status) {
7080 case -NFS4ERR_DELAY:
7081 rpc_delay(task, NFS4_POLL_RETRY_MAX);
7084 nfs4_schedule_lease_recovery(clp);
7089 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
7091 struct nfs4_sequence_data *calldata = data;
7092 struct nfs_client *clp = calldata->clp;
7094 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
7097 trace_nfs4_sequence(clp, task->tk_status);
7098 if (task->tk_status < 0) {
7099 dprintk("%s ERROR %d\n", __func__, task->tk_status);
7100 if (atomic_read(&clp->cl_count) == 1)
7103 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
7104 rpc_restart_call_prepare(task);
7108 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
7110 dprintk("<-- %s\n", __func__);
7113 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
7115 struct nfs4_sequence_data *calldata = data;
7116 struct nfs_client *clp = calldata->clp;
7117 struct nfs4_sequence_args *args;
7118 struct nfs4_sequence_res *res;
7120 args = task->tk_msg.rpc_argp;
7121 res = task->tk_msg.rpc_resp;
7123 nfs41_setup_sequence(clp->cl_session, args, res, task);
7126 static const struct rpc_call_ops nfs41_sequence_ops = {
7127 .rpc_call_done = nfs41_sequence_call_done,
7128 .rpc_call_prepare = nfs41_sequence_prepare,
7129 .rpc_release = nfs41_sequence_release,
7132 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
7133 struct rpc_cred *cred,
7136 struct nfs4_sequence_data *calldata;
7137 struct rpc_message msg = {
7138 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
7141 struct rpc_task_setup task_setup_data = {
7142 .rpc_client = clp->cl_rpcclient,
7143 .rpc_message = &msg,
7144 .callback_ops = &nfs41_sequence_ops,
7145 .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT,
7148 if (!atomic_inc_not_zero(&clp->cl_count))
7149 return ERR_PTR(-EIO);
7150 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
7151 if (calldata == NULL) {
7152 nfs_put_client(clp);
7153 return ERR_PTR(-ENOMEM);
7155 nfs4_init_sequence(&calldata->args, &calldata->res, 0);
7157 nfs4_set_sequence_privileged(&calldata->args);
7158 msg.rpc_argp = &calldata->args;
7159 msg.rpc_resp = &calldata->res;
7160 calldata->clp = clp;
7161 task_setup_data.callback_data = calldata;
7163 return rpc_run_task(&task_setup_data);
7166 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
7168 struct rpc_task *task;
7171 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
7173 task = _nfs41_proc_sequence(clp, cred, false);
7175 ret = PTR_ERR(task);
7177 rpc_put_task_async(task);
7178 dprintk("<-- %s status=%d\n", __func__, ret);
7182 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
7184 struct rpc_task *task;
7187 task = _nfs41_proc_sequence(clp, cred, true);
7189 ret = PTR_ERR(task);
7192 ret = rpc_wait_for_completion_task(task);
7194 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
7196 if (task->tk_status == 0)
7197 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
7198 ret = task->tk_status;
7202 dprintk("<-- %s status=%d\n", __func__, ret);
7206 struct nfs4_reclaim_complete_data {
7207 struct nfs_client *clp;
7208 struct nfs41_reclaim_complete_args arg;
7209 struct nfs41_reclaim_complete_res res;
7212 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
7214 struct nfs4_reclaim_complete_data *calldata = data;
7216 nfs41_setup_sequence(calldata->clp->cl_session,
7217 &calldata->arg.seq_args,
7218 &calldata->res.seq_res,
7222 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
7224 switch(task->tk_status) {
7226 case -NFS4ERR_COMPLETE_ALREADY:
7227 case -NFS4ERR_WRONG_CRED: /* What to do here? */
7229 case -NFS4ERR_DELAY:
7230 rpc_delay(task, NFS4_POLL_RETRY_MAX);
7232 case -NFS4ERR_RETRY_UNCACHED_REP:
7235 nfs4_schedule_lease_recovery(clp);
7240 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
7242 struct nfs4_reclaim_complete_data *calldata = data;
7243 struct nfs_client *clp = calldata->clp;
7244 struct nfs4_sequence_res *res = &calldata->res.seq_res;
7246 dprintk("--> %s\n", __func__);
7247 if (!nfs41_sequence_done(task, res))
7250 trace_nfs4_reclaim_complete(clp, task->tk_status);
7251 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
7252 rpc_restart_call_prepare(task);
7255 dprintk("<-- %s\n", __func__);
7258 static void nfs4_free_reclaim_complete_data(void *data)
7260 struct nfs4_reclaim_complete_data *calldata = data;
7265 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
7266 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
7267 .rpc_call_done = nfs4_reclaim_complete_done,
7268 .rpc_release = nfs4_free_reclaim_complete_data,
7272 * Issue a global reclaim complete.
7274 static int nfs41_proc_reclaim_complete(struct nfs_client *clp,
7275 struct rpc_cred *cred)
7277 struct nfs4_reclaim_complete_data *calldata;
7278 struct rpc_task *task;
7279 struct rpc_message msg = {
7280 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
7283 struct rpc_task_setup task_setup_data = {
7284 .rpc_client = clp->cl_rpcclient,
7285 .rpc_message = &msg,
7286 .callback_ops = &nfs4_reclaim_complete_call_ops,
7287 .flags = RPC_TASK_ASYNC,
7289 int status = -ENOMEM;
7291 dprintk("--> %s\n", __func__);
7292 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
7293 if (calldata == NULL)
7295 calldata->clp = clp;
7296 calldata->arg.one_fs = 0;
7298 nfs4_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
7299 nfs4_set_sequence_privileged(&calldata->arg.seq_args);
7300 msg.rpc_argp = &calldata->arg;
7301 msg.rpc_resp = &calldata->res;
7302 task_setup_data.callback_data = calldata;
7303 task = rpc_run_task(&task_setup_data);
7305 status = PTR_ERR(task);
7308 status = nfs4_wait_for_completion_rpc_task(task);
7310 status = task->tk_status;
7314 dprintk("<-- %s status=%d\n", __func__, status);
7319 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
7321 struct nfs4_layoutget *lgp = calldata;
7322 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
7323 struct nfs4_session *session = nfs4_get_session(server);
7325 dprintk("--> %s\n", __func__);
7326 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
7327 * right now covering the LAYOUTGET we are about to send.
7328 * However, that is not so catastrophic, and there seems
7329 * to be no way to prevent it completely.
7331 if (nfs41_setup_sequence(session, &lgp->args.seq_args,
7332 &lgp->res.seq_res, task))
7334 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
7335 NFS_I(lgp->args.inode)->layout,
7336 lgp->args.ctx->state)) {
7337 rpc_exit(task, NFS4_OK);
7341 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
7343 struct nfs4_layoutget *lgp = calldata;
7344 struct inode *inode = lgp->args.inode;
7345 struct nfs_server *server = NFS_SERVER(inode);
7346 struct pnfs_layout_hdr *lo;
7347 struct nfs4_state *state = NULL;
7348 unsigned long timeo, giveup;
7350 dprintk("--> %s\n", __func__);
7352 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
7355 switch (task->tk_status) {
7358 case -NFS4ERR_LAYOUTTRYLATER:
7359 case -NFS4ERR_RECALLCONFLICT:
7360 timeo = rpc_get_timeout(task->tk_client);
7361 giveup = lgp->args.timestamp + timeo;
7362 if (time_after(giveup, jiffies))
7363 task->tk_status = -NFS4ERR_DELAY;
7365 case -NFS4ERR_EXPIRED:
7366 case -NFS4ERR_BAD_STATEID:
7367 spin_lock(&inode->i_lock);
7368 lo = NFS_I(inode)->layout;
7369 if (!lo || list_empty(&lo->plh_segs)) {
7370 spin_unlock(&inode->i_lock);
7371 /* If the open stateid was bad, then recover it. */
7372 state = lgp->args.ctx->state;
7376 pnfs_mark_matching_lsegs_invalid(lo, &head, NULL);
7377 spin_unlock(&inode->i_lock);
7378 /* Mark the bad layout state as invalid, then
7379 * retry using the open stateid. */
7380 pnfs_free_lseg_list(&head);
7383 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
7384 rpc_restart_call_prepare(task);
7386 dprintk("<-- %s\n", __func__);
7389 static size_t max_response_pages(struct nfs_server *server)
7391 u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
7392 return nfs_page_array_len(0, max_resp_sz);
7395 static void nfs4_free_pages(struct page **pages, size_t size)
7402 for (i = 0; i < size; i++) {
7405 __free_page(pages[i]);
7410 static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
7412 struct page **pages;
7415 pages = kcalloc(size, sizeof(struct page *), gfp_flags);
7417 dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
7421 for (i = 0; i < size; i++) {
7422 pages[i] = alloc_page(gfp_flags);
7424 dprintk("%s: failed to allocate page\n", __func__);
7425 nfs4_free_pages(pages, size);
7433 static void nfs4_layoutget_release(void *calldata)
7435 struct nfs4_layoutget *lgp = calldata;
7436 struct inode *inode = lgp->args.inode;
7437 struct nfs_server *server = NFS_SERVER(inode);
7438 size_t max_pages = max_response_pages(server);
7440 dprintk("--> %s\n", __func__);
7441 nfs4_free_pages(lgp->args.layout.pages, max_pages);
7442 pnfs_put_layout_hdr(NFS_I(inode)->layout);
7443 put_nfs_open_context(lgp->args.ctx);
7445 dprintk("<-- %s\n", __func__);
7448 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
7449 .rpc_call_prepare = nfs4_layoutget_prepare,
7450 .rpc_call_done = nfs4_layoutget_done,
7451 .rpc_release = nfs4_layoutget_release,
7454 struct pnfs_layout_segment *
7455 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)
7457 struct inode *inode = lgp->args.inode;
7458 struct nfs_server *server = NFS_SERVER(inode);
7459 size_t max_pages = max_response_pages(server);
7460 struct rpc_task *task;
7461 struct rpc_message msg = {
7462 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
7463 .rpc_argp = &lgp->args,
7464 .rpc_resp = &lgp->res,
7465 .rpc_cred = lgp->cred,
7467 struct rpc_task_setup task_setup_data = {
7468 .rpc_client = server->client,
7469 .rpc_message = &msg,
7470 .callback_ops = &nfs4_layoutget_call_ops,
7471 .callback_data = lgp,
7472 .flags = RPC_TASK_ASYNC,
7474 struct pnfs_layout_segment *lseg = NULL;
7477 dprintk("--> %s\n", __func__);
7479 lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
7480 if (!lgp->args.layout.pages) {
7481 nfs4_layoutget_release(lgp);
7482 return ERR_PTR(-ENOMEM);
7484 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
7485 lgp->args.timestamp = jiffies;
7487 lgp->res.layoutp = &lgp->args.layout;
7488 lgp->res.seq_res.sr_slot = NULL;
7489 nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
7491 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
7492 pnfs_get_layout_hdr(NFS_I(inode)->layout);
7494 task = rpc_run_task(&task_setup_data);
7496 return ERR_CAST(task);
7497 status = nfs4_wait_for_completion_rpc_task(task);
7499 status = task->tk_status;
7500 trace_nfs4_layoutget(lgp->args.ctx,
7504 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
7505 if (status == 0 && lgp->res.layoutp->len)
7506 lseg = pnfs_layout_process(lgp);
7508 dprintk("<-- %s status=%d\n", __func__, status);
7510 return ERR_PTR(status);
7515 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
7517 struct nfs4_layoutreturn *lrp = calldata;
7519 dprintk("--> %s\n", __func__);
7520 nfs41_setup_sequence(lrp->clp->cl_session,
7521 &lrp->args.seq_args,
7526 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
7528 struct nfs4_layoutreturn *lrp = calldata;
7529 struct nfs_server *server;
7531 dprintk("--> %s\n", __func__);
7533 if (!nfs41_sequence_done(task, &lrp->res.seq_res))
7536 server = NFS_SERVER(lrp->args.inode);
7537 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
7538 rpc_restart_call_prepare(task);
7541 dprintk("<-- %s\n", __func__);
7544 static void nfs4_layoutreturn_release(void *calldata)
7546 struct nfs4_layoutreturn *lrp = calldata;
7547 struct pnfs_layout_hdr *lo = lrp->args.layout;
7549 dprintk("--> %s\n", __func__);
7550 spin_lock(&lo->plh_inode->i_lock);
7551 if (lrp->res.lrs_present)
7552 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
7553 lo->plh_block_lgets--;
7554 spin_unlock(&lo->plh_inode->i_lock);
7555 pnfs_put_layout_hdr(lrp->args.layout);
7557 dprintk("<-- %s\n", __func__);
7560 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
7561 .rpc_call_prepare = nfs4_layoutreturn_prepare,
7562 .rpc_call_done = nfs4_layoutreturn_done,
7563 .rpc_release = nfs4_layoutreturn_release,
7566 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
7568 struct rpc_task *task;
7569 struct rpc_message msg = {
7570 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
7571 .rpc_argp = &lrp->args,
7572 .rpc_resp = &lrp->res,
7573 .rpc_cred = lrp->cred,
7575 struct rpc_task_setup task_setup_data = {
7576 .rpc_client = NFS_SERVER(lrp->args.inode)->client,
7577 .rpc_message = &msg,
7578 .callback_ops = &nfs4_layoutreturn_call_ops,
7579 .callback_data = lrp,
7583 dprintk("--> %s\n", __func__);
7584 nfs4_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
7585 task = rpc_run_task(&task_setup_data);
7587 return PTR_ERR(task);
7588 status = task->tk_status;
7589 trace_nfs4_layoutreturn(lrp->args.inode, status);
7590 dprintk("<-- %s status=%d\n", __func__, status);
7596 * Retrieve the list of Data Server devices from the MDS.
7598 static int _nfs4_getdevicelist(struct nfs_server *server,
7599 const struct nfs_fh *fh,
7600 struct pnfs_devicelist *devlist)
7602 struct nfs4_getdevicelist_args args = {
7604 .layoutclass = server->pnfs_curr_ld->id,
7606 struct nfs4_getdevicelist_res res = {
7609 struct rpc_message msg = {
7610 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
7616 dprintk("--> %s\n", __func__);
7617 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
7619 dprintk("<-- %s status=%d\n", __func__, status);
7623 int nfs4_proc_getdevicelist(struct nfs_server *server,
7624 const struct nfs_fh *fh,
7625 struct pnfs_devicelist *devlist)
7627 struct nfs4_exception exception = { };
7631 err = nfs4_handle_exception(server,
7632 _nfs4_getdevicelist(server, fh, devlist),
7634 } while (exception.retry);
7636 dprintk("%s: err=%d, num_devs=%u\n", __func__,
7637 err, devlist->num_devs);
7641 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
7644 _nfs4_proc_getdeviceinfo(struct nfs_server *server,
7645 struct pnfs_device *pdev,
7646 struct rpc_cred *cred)
7648 struct nfs4_getdeviceinfo_args args = {
7651 struct nfs4_getdeviceinfo_res res = {
7654 struct rpc_message msg = {
7655 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
7662 dprintk("--> %s\n", __func__);
7663 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
7664 dprintk("<-- %s status=%d\n", __func__, status);
7669 int nfs4_proc_getdeviceinfo(struct nfs_server *server,
7670 struct pnfs_device *pdev,
7671 struct rpc_cred *cred)
7673 struct nfs4_exception exception = { };
7677 err = nfs4_handle_exception(server,
7678 _nfs4_proc_getdeviceinfo(server, pdev, cred),
7680 } while (exception.retry);
7683 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
7685 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
7687 struct nfs4_layoutcommit_data *data = calldata;
7688 struct nfs_server *server = NFS_SERVER(data->args.inode);
7689 struct nfs4_session *session = nfs4_get_session(server);
7691 nfs41_setup_sequence(session,
7692 &data->args.seq_args,
7698 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
7700 struct nfs4_layoutcommit_data *data = calldata;
7701 struct nfs_server *server = NFS_SERVER(data->args.inode);
7703 if (!nfs41_sequence_done(task, &data->res.seq_res))
7706 switch (task->tk_status) { /* Just ignore these failures */
7707 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
7708 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
7709 case -NFS4ERR_BADLAYOUT: /* no layout */
7710 case -NFS4ERR_GRACE: /* loca_recalim always false */
7711 task->tk_status = 0;
7714 nfs_post_op_update_inode_force_wcc(data->args.inode,
7718 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
7719 rpc_restart_call_prepare(task);
7725 static void nfs4_layoutcommit_release(void *calldata)
7727 struct nfs4_layoutcommit_data *data = calldata;
7729 pnfs_cleanup_layoutcommit(data);
7730 put_rpccred(data->cred);
7734 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
7735 .rpc_call_prepare = nfs4_layoutcommit_prepare,
7736 .rpc_call_done = nfs4_layoutcommit_done,
7737 .rpc_release = nfs4_layoutcommit_release,
7741 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
7743 struct rpc_message msg = {
7744 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
7745 .rpc_argp = &data->args,
7746 .rpc_resp = &data->res,
7747 .rpc_cred = data->cred,
7749 struct rpc_task_setup task_setup_data = {
7750 .task = &data->task,
7751 .rpc_client = NFS_CLIENT(data->args.inode),
7752 .rpc_message = &msg,
7753 .callback_ops = &nfs4_layoutcommit_ops,
7754 .callback_data = data,
7755 .flags = RPC_TASK_ASYNC,
7757 struct rpc_task *task;
7760 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7761 "lbw: %llu inode %lu\n",
7762 data->task.tk_pid, sync,
7763 data->args.lastbytewritten,
7764 data->args.inode->i_ino);
7766 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
7767 task = rpc_run_task(&task_setup_data);
7769 return PTR_ERR(task);
7772 status = nfs4_wait_for_completion_rpc_task(task);
7775 status = task->tk_status;
7776 trace_nfs4_layoutcommit(data->args.inode, status);
7778 dprintk("%s: status %d\n", __func__, status);
7784 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7785 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7788 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
7789 struct nfs_fsinfo *info,
7790 struct nfs4_secinfo_flavors *flavors, bool use_integrity)
7792 struct nfs41_secinfo_no_name_args args = {
7793 .style = SECINFO_STYLE_CURRENT_FH,
7795 struct nfs4_secinfo_res res = {
7798 struct rpc_message msg = {
7799 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
7803 struct rpc_clnt *clnt = server->client;
7804 struct rpc_cred *cred = NULL;
7807 if (use_integrity) {
7808 clnt = server->nfs_client->cl_rpcclient;
7809 cred = nfs4_get_clid_cred(server->nfs_client);
7810 msg.rpc_cred = cred;
7813 dprintk("--> %s\n", __func__);
7814 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args,
7816 dprintk("<-- %s status=%d\n", __func__, status);
7825 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
7826 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
7828 struct nfs4_exception exception = { };
7831 /* first try using integrity protection */
7832 err = -NFS4ERR_WRONGSEC;
7834 /* try to use integrity protection with machine cred */
7835 if (_nfs4_is_integrity_protected(server->nfs_client))
7836 err = _nfs41_proc_secinfo_no_name(server, fhandle, info,
7840 * if unable to use integrity protection, or SECINFO with
7841 * integrity protection returns NFS4ERR_WRONGSEC (which is
7842 * disallowed by spec, but exists in deployed servers) use
7843 * the current filesystem's rpc_client and the user cred.
7845 if (err == -NFS4ERR_WRONGSEC)
7846 err = _nfs41_proc_secinfo_no_name(server, fhandle, info,
7851 case -NFS4ERR_WRONGSEC:
7852 case -NFS4ERR_NOTSUPP:
7855 err = nfs4_handle_exception(server, err, &exception);
7857 } while (exception.retry);
7863 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
7864 struct nfs_fsinfo *info)
7868 rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
7869 struct nfs4_secinfo_flavors *flavors;
7870 struct nfs4_secinfo4 *secinfo;
7873 page = alloc_page(GFP_KERNEL);
7879 flavors = page_address(page);
7880 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
7883 * Fall back on "guess and check" method if
7884 * the server doesn't support SECINFO_NO_NAME
7886 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
7887 err = nfs4_find_root_sec(server, fhandle, info);
7893 for (i = 0; i < flavors->num_flavors; i++) {
7894 secinfo = &flavors->flavors[i];
7896 switch (secinfo->flavor) {
7900 flavor = rpcauth_get_pseudoflavor(secinfo->flavor,
7901 &secinfo->flavor_info);
7904 flavor = RPC_AUTH_MAXFLAVOR;
7908 if (flavor != RPC_AUTH_MAXFLAVOR) {
7909 err = nfs4_lookup_root_sec(server, fhandle,
7916 if (flavor == RPC_AUTH_MAXFLAVOR)
7927 static int _nfs41_test_stateid(struct nfs_server *server,
7928 nfs4_stateid *stateid,
7929 struct rpc_cred *cred)
7932 struct nfs41_test_stateid_args args = {
7935 struct nfs41_test_stateid_res res;
7936 struct rpc_message msg = {
7937 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
7942 struct rpc_clnt *rpc_client = server->client;
7944 nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID,
7947 dprintk("NFS call test_stateid %p\n", stateid);
7948 nfs4_init_sequence(&args.seq_args, &res.seq_res, 0);
7949 nfs4_set_sequence_privileged(&args.seq_args);
7950 status = nfs4_call_sync_sequence(rpc_client, server, &msg,
7951 &args.seq_args, &res.seq_res);
7952 if (status != NFS_OK) {
7953 dprintk("NFS reply test_stateid: failed, %d\n", status);
7956 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
7961 * nfs41_test_stateid - perform a TEST_STATEID operation
7963 * @server: server / transport on which to perform the operation
7964 * @stateid: state ID to test
7967 * Returns NFS_OK if the server recognizes that "stateid" is valid.
7968 * Otherwise a negative NFS4ERR value is returned if the operation
7969 * failed or the state ID is not currently valid.
7971 static int nfs41_test_stateid(struct nfs_server *server,
7972 nfs4_stateid *stateid,
7973 struct rpc_cred *cred)
7975 struct nfs4_exception exception = { };
7978 err = _nfs41_test_stateid(server, stateid, cred);
7979 if (err != -NFS4ERR_DELAY)
7981 nfs4_handle_exception(server, err, &exception);
7982 } while (exception.retry);
7986 struct nfs_free_stateid_data {
7987 struct nfs_server *server;
7988 struct nfs41_free_stateid_args args;
7989 struct nfs41_free_stateid_res res;
7992 static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata)
7994 struct nfs_free_stateid_data *data = calldata;
7995 nfs41_setup_sequence(nfs4_get_session(data->server),
7996 &data->args.seq_args,
8001 static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata)
8003 struct nfs_free_stateid_data *data = calldata;
8005 nfs41_sequence_done(task, &data->res.seq_res);
8007 switch (task->tk_status) {
8008 case -NFS4ERR_DELAY:
8009 if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN)
8010 rpc_restart_call_prepare(task);
8014 static void nfs41_free_stateid_release(void *calldata)
8019 static const struct rpc_call_ops nfs41_free_stateid_ops = {
8020 .rpc_call_prepare = nfs41_free_stateid_prepare,
8021 .rpc_call_done = nfs41_free_stateid_done,
8022 .rpc_release = nfs41_free_stateid_release,
8025 static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server,
8026 nfs4_stateid *stateid,
8027 struct rpc_cred *cred,
8030 struct rpc_message msg = {
8031 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
8034 struct rpc_task_setup task_setup = {
8035 .rpc_client = server->client,
8036 .rpc_message = &msg,
8037 .callback_ops = &nfs41_free_stateid_ops,
8038 .flags = RPC_TASK_ASYNC,
8040 struct nfs_free_stateid_data *data;
8042 nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_STATEID,
8043 &task_setup.rpc_client, &msg);
8045 dprintk("NFS call free_stateid %p\n", stateid);
8046 data = kmalloc(sizeof(*data), GFP_NOFS);
8048 return ERR_PTR(-ENOMEM);
8049 data->server = server;
8050 nfs4_stateid_copy(&data->args.stateid, stateid);
8052 task_setup.callback_data = data;
8054 msg.rpc_argp = &data->args;
8055 msg.rpc_resp = &data->res;
8056 nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
8058 nfs4_set_sequence_privileged(&data->args.seq_args);
8060 return rpc_run_task(&task_setup);
8064 * nfs41_free_stateid - perform a FREE_STATEID operation
8066 * @server: server / transport on which to perform the operation
8067 * @stateid: state ID to release
8070 * Returns NFS_OK if the server freed "stateid". Otherwise a
8071 * negative NFS4ERR value is returned.
8073 static int nfs41_free_stateid(struct nfs_server *server,
8074 nfs4_stateid *stateid,
8075 struct rpc_cred *cred)
8077 struct rpc_task *task;
8080 task = _nfs41_free_stateid(server, stateid, cred, true);
8082 return PTR_ERR(task);
8083 ret = rpc_wait_for_completion_task(task);
8085 ret = task->tk_status;
8090 static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
8092 struct rpc_task *task;
8093 struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
8095 task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false);
8096 nfs4_free_lock_state(server, lsp);
8098 return PTR_ERR(task);
8103 static bool nfs41_match_stateid(const nfs4_stateid *s1,
8104 const nfs4_stateid *s2)
8106 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
8109 if (s1->seqid == s2->seqid)
8111 if (s1->seqid == 0 || s2->seqid == 0)
8117 #endif /* CONFIG_NFS_V4_1 */
8119 static bool nfs4_match_stateid(const nfs4_stateid *s1,
8120 const nfs4_stateid *s2)
8122 return nfs4_stateid_match(s1, s2);
8126 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
8127 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
8128 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
8129 .recover_open = nfs4_open_reclaim,
8130 .recover_lock = nfs4_lock_reclaim,
8131 .establish_clid = nfs4_init_clientid,
8132 .detect_trunking = nfs40_discover_server_trunking,
8135 #if defined(CONFIG_NFS_V4_1)
8136 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
8137 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
8138 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
8139 .recover_open = nfs4_open_reclaim,
8140 .recover_lock = nfs4_lock_reclaim,
8141 .establish_clid = nfs41_init_clientid,
8142 .reclaim_complete = nfs41_proc_reclaim_complete,
8143 .detect_trunking = nfs41_discover_server_trunking,
8145 #endif /* CONFIG_NFS_V4_1 */
8147 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
8148 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
8149 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
8150 .recover_open = nfs4_open_expired,
8151 .recover_lock = nfs4_lock_expired,
8152 .establish_clid = nfs4_init_clientid,
8155 #if defined(CONFIG_NFS_V4_1)
8156 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
8157 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
8158 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
8159 .recover_open = nfs41_open_expired,
8160 .recover_lock = nfs41_lock_expired,
8161 .establish_clid = nfs41_init_clientid,
8163 #endif /* CONFIG_NFS_V4_1 */
8165 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
8166 .sched_state_renewal = nfs4_proc_async_renew,
8167 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
8168 .renew_lease = nfs4_proc_renew,
8171 #if defined(CONFIG_NFS_V4_1)
8172 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
8173 .sched_state_renewal = nfs41_proc_async_sequence,
8174 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
8175 .renew_lease = nfs4_proc_sequence,
8179 static const struct nfs4_mig_recovery_ops nfs40_mig_recovery_ops = {
8180 .get_locations = _nfs40_proc_get_locations,
8181 .fsid_present = _nfs40_proc_fsid_present,
8184 #if defined(CONFIG_NFS_V4_1)
8185 static const struct nfs4_mig_recovery_ops nfs41_mig_recovery_ops = {
8186 .get_locations = _nfs41_proc_get_locations,
8187 .fsid_present = _nfs41_proc_fsid_present,
8189 #endif /* CONFIG_NFS_V4_1 */
8191 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
8193 .init_caps = NFS_CAP_READDIRPLUS
8194 | NFS_CAP_ATOMIC_OPEN
8195 | NFS_CAP_CHANGE_ATTR
8196 | NFS_CAP_POSIX_LOCK,
8197 .init_client = nfs40_init_client,
8198 .shutdown_client = nfs40_shutdown_client,
8199 .match_stateid = nfs4_match_stateid,
8200 .find_root_sec = nfs4_find_root_sec,
8201 .free_lock_state = nfs4_release_lockowner,
8202 .call_sync_ops = &nfs40_call_sync_ops,
8203 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
8204 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
8205 .state_renewal_ops = &nfs40_state_renewal_ops,
8206 .mig_recovery_ops = &nfs40_mig_recovery_ops,
8209 #if defined(CONFIG_NFS_V4_1)
8210 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
8212 .init_caps = NFS_CAP_READDIRPLUS
8213 | NFS_CAP_ATOMIC_OPEN
8214 | NFS_CAP_CHANGE_ATTR
8215 | NFS_CAP_POSIX_LOCK
8216 | NFS_CAP_STATEID_NFSV41
8217 | NFS_CAP_ATOMIC_OPEN_V1,
8218 .init_client = nfs41_init_client,
8219 .shutdown_client = nfs41_shutdown_client,
8220 .match_stateid = nfs41_match_stateid,
8221 .find_root_sec = nfs41_find_root_sec,
8222 .free_lock_state = nfs41_free_lock_state,
8223 .call_sync_ops = &nfs41_call_sync_ops,
8224 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
8225 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
8226 .state_renewal_ops = &nfs41_state_renewal_ops,
8227 .mig_recovery_ops = &nfs41_mig_recovery_ops,
8231 #if defined(CONFIG_NFS_V4_2)
8232 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
8234 .init_caps = NFS_CAP_READDIRPLUS
8235 | NFS_CAP_ATOMIC_OPEN
8236 | NFS_CAP_CHANGE_ATTR
8237 | NFS_CAP_POSIX_LOCK
8238 | NFS_CAP_STATEID_NFSV41
8239 | NFS_CAP_ATOMIC_OPEN_V1,
8240 .init_client = nfs41_init_client,
8241 .shutdown_client = nfs41_shutdown_client,
8242 .match_stateid = nfs41_match_stateid,
8243 .find_root_sec = nfs41_find_root_sec,
8244 .free_lock_state = nfs41_free_lock_state,
8245 .call_sync_ops = &nfs41_call_sync_ops,
8246 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
8247 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
8248 .state_renewal_ops = &nfs41_state_renewal_ops,
8252 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
8253 [0] = &nfs_v4_0_minor_ops,
8254 #if defined(CONFIG_NFS_V4_1)
8255 [1] = &nfs_v4_1_minor_ops,
8257 #if defined(CONFIG_NFS_V4_2)
8258 [2] = &nfs_v4_2_minor_ops,
8262 static const struct inode_operations nfs4_dir_inode_operations = {
8263 .create = nfs_create,
8264 .lookup = nfs_lookup,
8265 .atomic_open = nfs_atomic_open,
8267 .unlink = nfs_unlink,
8268 .symlink = nfs_symlink,
8272 .rename = nfs_rename,
8273 .permission = nfs_permission,
8274 .getattr = nfs_getattr,
8275 .setattr = nfs_setattr,
8276 .getxattr = generic_getxattr,
8277 .setxattr = generic_setxattr,
8278 .listxattr = generic_listxattr,
8279 .removexattr = generic_removexattr,
8282 static const struct inode_operations nfs4_file_inode_operations = {
8283 .permission = nfs_permission,
8284 .getattr = nfs_getattr,
8285 .setattr = nfs_setattr,
8286 .getxattr = generic_getxattr,
8287 .setxattr = generic_setxattr,
8288 .listxattr = generic_listxattr,
8289 .removexattr = generic_removexattr,
8292 const struct nfs_rpc_ops nfs_v4_clientops = {
8293 .version = 4, /* protocol version */
8294 .dentry_ops = &nfs4_dentry_operations,
8295 .dir_inode_ops = &nfs4_dir_inode_operations,
8296 .file_inode_ops = &nfs4_file_inode_operations,
8297 .file_ops = &nfs4_file_operations,
8298 .getroot = nfs4_proc_get_root,
8299 .submount = nfs4_submount,
8300 .try_mount = nfs4_try_mount,
8301 .getattr = nfs4_proc_getattr,
8302 .setattr = nfs4_proc_setattr,
8303 .lookup = nfs4_proc_lookup,
8304 .access = nfs4_proc_access,
8305 .readlink = nfs4_proc_readlink,
8306 .create = nfs4_proc_create,
8307 .remove = nfs4_proc_remove,
8308 .unlink_setup = nfs4_proc_unlink_setup,
8309 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
8310 .unlink_done = nfs4_proc_unlink_done,
8311 .rename = nfs4_proc_rename,
8312 .rename_setup = nfs4_proc_rename_setup,
8313 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
8314 .rename_done = nfs4_proc_rename_done,
8315 .link = nfs4_proc_link,
8316 .symlink = nfs4_proc_symlink,
8317 .mkdir = nfs4_proc_mkdir,
8318 .rmdir = nfs4_proc_remove,
8319 .readdir = nfs4_proc_readdir,
8320 .mknod = nfs4_proc_mknod,
8321 .statfs = nfs4_proc_statfs,
8322 .fsinfo = nfs4_proc_fsinfo,
8323 .pathconf = nfs4_proc_pathconf,
8324 .set_capabilities = nfs4_server_capabilities,
8325 .decode_dirent = nfs4_decode_dirent,
8326 .read_setup = nfs4_proc_read_setup,
8327 .read_pageio_init = pnfs_pageio_init_read,
8328 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
8329 .read_done = nfs4_read_done,
8330 .write_setup = nfs4_proc_write_setup,
8331 .write_pageio_init = pnfs_pageio_init_write,
8332 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
8333 .write_done = nfs4_write_done,
8334 .commit_setup = nfs4_proc_commit_setup,
8335 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
8336 .commit_done = nfs4_commit_done,
8337 .lock = nfs4_proc_lock,
8338 .clear_acl_cache = nfs4_zap_acl_attr,
8339 .close_context = nfs4_close_context,
8340 .open_context = nfs4_atomic_open,
8341 .have_delegation = nfs4_have_delegation,
8342 .return_delegation = nfs4_inode_return_delegation,
8343 .alloc_client = nfs4_alloc_client,
8344 .init_client = nfs4_init_client,
8345 .free_client = nfs4_free_client,
8346 .create_server = nfs4_create_server,
8347 .clone_server = nfs_clone_server,
8350 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
8351 .prefix = XATTR_NAME_NFSV4_ACL,
8352 .list = nfs4_xattr_list_nfs4_acl,
8353 .get = nfs4_xattr_get_nfs4_acl,
8354 .set = nfs4_xattr_set_nfs4_acl,
8357 const struct xattr_handler *nfs4_xattr_handlers[] = {
8358 &nfs4_xattr_nfs4_acl_handler,
8359 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
8360 &nfs4_xattr_nfs4_label_handler,