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 #define NFSDBG_FACILITY NFSDBG_PROC
71 #define NFS4_POLL_RETRY_MIN (HZ/10)
72 #define NFS4_POLL_RETRY_MAX (15*HZ)
75 static int _nfs4_proc_open(struct nfs4_opendata *data);
76 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
77 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
78 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
79 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
80 static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *);
81 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
82 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
83 struct nfs_fattr *fattr, struct iattr *sattr,
84 struct nfs4_state *state);
85 #ifdef CONFIG_NFS_V4_1
86 static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *);
87 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *);
89 /* Prevent leaks of NFSv4 errors into userland */
90 static int nfs4_map_errors(int err)
95 case -NFS4ERR_RESOURCE:
96 case -NFS4ERR_LAYOUTTRYLATER:
97 case -NFS4ERR_RECALLCONFLICT:
99 case -NFS4ERR_WRONGSEC:
101 case -NFS4ERR_BADOWNER:
102 case -NFS4ERR_BADNAME:
104 case -NFS4ERR_SHARE_DENIED:
106 case -NFS4ERR_MINOR_VERS_MISMATCH:
107 return -EPROTONOSUPPORT;
108 case -NFS4ERR_ACCESS:
110 case -NFS4ERR_FILE_OPEN:
113 dprintk("%s could not handle NFSv4 error %d\n",
121 * This is our standard bitmap for GETATTR requests.
123 const u32 nfs4_fattr_bitmap[3] = {
125 | FATTR4_WORD0_CHANGE
128 | FATTR4_WORD0_FILEID,
130 | FATTR4_WORD1_NUMLINKS
132 | FATTR4_WORD1_OWNER_GROUP
133 | FATTR4_WORD1_RAWDEV
134 | FATTR4_WORD1_SPACE_USED
135 | FATTR4_WORD1_TIME_ACCESS
136 | FATTR4_WORD1_TIME_METADATA
137 | FATTR4_WORD1_TIME_MODIFY
140 static const u32 nfs4_pnfs_open_bitmap[3] = {
142 | FATTR4_WORD0_CHANGE
145 | FATTR4_WORD0_FILEID,
147 | FATTR4_WORD1_NUMLINKS
149 | FATTR4_WORD1_OWNER_GROUP
150 | FATTR4_WORD1_RAWDEV
151 | FATTR4_WORD1_SPACE_USED
152 | FATTR4_WORD1_TIME_ACCESS
153 | FATTR4_WORD1_TIME_METADATA
154 | FATTR4_WORD1_TIME_MODIFY,
155 FATTR4_WORD2_MDSTHRESHOLD
158 static const u32 nfs4_open_noattr_bitmap[3] = {
160 | FATTR4_WORD0_CHANGE
161 | FATTR4_WORD0_FILEID,
164 const u32 nfs4_statfs_bitmap[2] = {
165 FATTR4_WORD0_FILES_AVAIL
166 | FATTR4_WORD0_FILES_FREE
167 | FATTR4_WORD0_FILES_TOTAL,
168 FATTR4_WORD1_SPACE_AVAIL
169 | FATTR4_WORD1_SPACE_FREE
170 | FATTR4_WORD1_SPACE_TOTAL
173 const u32 nfs4_pathconf_bitmap[2] = {
175 | FATTR4_WORD0_MAXNAME,
179 const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE
180 | FATTR4_WORD0_MAXREAD
181 | FATTR4_WORD0_MAXWRITE
182 | FATTR4_WORD0_LEASE_TIME,
183 FATTR4_WORD1_TIME_DELTA
184 | FATTR4_WORD1_FS_LAYOUT_TYPES,
185 FATTR4_WORD2_LAYOUT_BLKSIZE
188 const u32 nfs4_fs_locations_bitmap[2] = {
190 | FATTR4_WORD0_CHANGE
193 | FATTR4_WORD0_FILEID
194 | FATTR4_WORD0_FS_LOCATIONS,
196 | FATTR4_WORD1_NUMLINKS
198 | FATTR4_WORD1_OWNER_GROUP
199 | FATTR4_WORD1_RAWDEV
200 | FATTR4_WORD1_SPACE_USED
201 | FATTR4_WORD1_TIME_ACCESS
202 | FATTR4_WORD1_TIME_METADATA
203 | FATTR4_WORD1_TIME_MODIFY
204 | FATTR4_WORD1_MOUNTED_ON_FILEID
207 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
208 struct nfs4_readdir_arg *readdir)
213 readdir->cookie = cookie;
214 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
219 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
224 * NFSv4 servers do not return entries for '.' and '..'
225 * Therefore, we fake these entries here. We let '.'
226 * have cookie 0 and '..' have cookie 1. Note that
227 * when talking to the server, we always send cookie 0
230 start = p = kmap_atomic(*readdir->pages);
233 *p++ = xdr_one; /* next */
234 *p++ = xdr_zero; /* cookie, first word */
235 *p++ = xdr_one; /* cookie, second word */
236 *p++ = xdr_one; /* entry len */
237 memcpy(p, ".\0\0\0", 4); /* entry */
239 *p++ = xdr_one; /* bitmap length */
240 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
241 *p++ = htonl(8); /* attribute buffer length */
242 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
245 *p++ = xdr_one; /* next */
246 *p++ = xdr_zero; /* cookie, first word */
247 *p++ = xdr_two; /* cookie, second word */
248 *p++ = xdr_two; /* entry len */
249 memcpy(p, "..\0\0", 4); /* entry */
251 *p++ = xdr_one; /* bitmap length */
252 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
253 *p++ = htonl(8); /* attribute buffer length */
254 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
256 readdir->pgbase = (char *)p - (char *)start;
257 readdir->count -= readdir->pgbase;
258 kunmap_atomic(start);
261 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
268 *timeout = NFS4_POLL_RETRY_MIN;
269 if (*timeout > NFS4_POLL_RETRY_MAX)
270 *timeout = NFS4_POLL_RETRY_MAX;
271 freezable_schedule_timeout_killable(*timeout);
272 if (fatal_signal_pending(current))
278 /* This is the error handling routine for processes that are allowed
281 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
283 struct nfs_client *clp = server->nfs_client;
284 struct nfs4_state *state = exception->state;
285 struct inode *inode = exception->inode;
288 exception->retry = 0;
292 case -NFS4ERR_OPENMODE:
293 if (inode && nfs4_have_delegation(inode, FMODE_READ)) {
294 nfs4_inode_return_delegation(inode);
295 exception->retry = 1;
300 ret = nfs4_schedule_stateid_recovery(server, state);
303 goto wait_on_recovery;
304 case -NFS4ERR_DELEG_REVOKED:
305 case -NFS4ERR_ADMIN_REVOKED:
306 case -NFS4ERR_BAD_STATEID:
307 if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) {
308 nfs_remove_bad_delegation(inode);
309 exception->retry = 1;
314 ret = nfs4_schedule_stateid_recovery(server, state);
317 goto wait_on_recovery;
318 case -NFS4ERR_EXPIRED:
320 ret = nfs4_schedule_stateid_recovery(server, state);
324 case -NFS4ERR_STALE_STATEID:
325 case -NFS4ERR_STALE_CLIENTID:
326 nfs4_schedule_lease_recovery(clp);
327 goto wait_on_recovery;
328 #if defined(CONFIG_NFS_V4_1)
329 case -NFS4ERR_BADSESSION:
330 case -NFS4ERR_BADSLOT:
331 case -NFS4ERR_BAD_HIGH_SLOT:
332 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
333 case -NFS4ERR_DEADSESSION:
334 case -NFS4ERR_SEQ_FALSE_RETRY:
335 case -NFS4ERR_SEQ_MISORDERED:
336 dprintk("%s ERROR: %d Reset session\n", __func__,
338 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
339 goto wait_on_recovery;
340 #endif /* defined(CONFIG_NFS_V4_1) */
341 case -NFS4ERR_FILE_OPEN:
342 if (exception->timeout > HZ) {
343 /* We have retried a decent amount, time to
351 ret = nfs4_delay(server->client, &exception->timeout);
354 case -NFS4ERR_RETRY_UNCACHED_REP:
355 case -NFS4ERR_OLD_STATEID:
356 exception->retry = 1;
358 case -NFS4ERR_BADOWNER:
359 /* The following works around a Linux server bug! */
360 case -NFS4ERR_BADNAME:
361 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
362 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
363 exception->retry = 1;
364 printk(KERN_WARNING "NFS: v4 server %s "
365 "does not accept raw "
367 "Reenabling the idmapper.\n",
368 server->nfs_client->cl_hostname);
371 /* We failed to handle the error */
372 return nfs4_map_errors(ret);
374 ret = nfs4_wait_clnt_recover(clp);
376 exception->retry = 1;
381 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
383 spin_lock(&clp->cl_lock);
384 if (time_before(clp->cl_last_renewal,timestamp))
385 clp->cl_last_renewal = timestamp;
386 spin_unlock(&clp->cl_lock);
389 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
391 do_renew_lease(server->nfs_client, timestamp);
394 #if defined(CONFIG_NFS_V4_1)
396 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
398 struct nfs4_session *session;
399 struct nfs4_slot_table *tbl;
400 bool send_new_highest_used_slotid = false;
403 /* just wake up the next guy waiting since
404 * we may have not consumed a slot after all */
405 dprintk("%s: No slot\n", __func__);
408 tbl = res->sr_slot->table;
409 session = tbl->session;
411 spin_lock(&tbl->slot_tbl_lock);
412 /* Be nice to the server: try to ensure that the last transmitted
413 * value for highest_user_slotid <= target_highest_slotid
415 if (tbl->highest_used_slotid > tbl->target_highest_slotid)
416 send_new_highest_used_slotid = true;
418 if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) {
419 send_new_highest_used_slotid = false;
422 nfs4_free_slot(tbl, res->sr_slot);
424 if (tbl->highest_used_slotid != NFS4_NO_SLOT)
425 send_new_highest_used_slotid = false;
427 spin_unlock(&tbl->slot_tbl_lock);
429 if (send_new_highest_used_slotid)
430 nfs41_server_notify_highest_slotid_update(session->clp);
433 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
435 struct nfs4_session *session;
436 struct nfs4_slot *slot;
437 struct nfs_client *clp;
438 bool interrupted = false;
441 /* don't increment the sequence number if the task wasn't sent */
442 if (!RPC_WAS_SENT(task))
446 session = slot->table->session;
448 if (slot->interrupted) {
449 slot->interrupted = 0;
453 /* Check the SEQUENCE operation status */
454 switch (res->sr_status) {
456 /* Update the slot's sequence and clientid lease timer */
459 do_renew_lease(clp, res->sr_timestamp);
460 /* Check sequence flags */
461 if (res->sr_status_flags != 0)
462 nfs4_schedule_lease_recovery(clp);
463 nfs41_update_target_slotid(slot->table, slot, res);
467 * sr_status remains 1 if an RPC level error occurred.
468 * The server may or may not have processed the sequence
470 * Mark the slot as having hosted an interrupted RPC call.
472 slot->interrupted = 1;
475 /* The server detected a resend of the RPC call and
476 * returned NFS4ERR_DELAY as per Section 2.10.6.2
479 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
484 case -NFS4ERR_BADSLOT:
486 * The slot id we used was probably retired. Try again
487 * using a different slot id.
490 case -NFS4ERR_SEQ_MISORDERED:
492 * Was the last operation on this sequence interrupted?
493 * If so, retry after bumping the sequence number.
500 * Could this slot have been previously retired?
501 * If so, then the server may be expecting seq_nr = 1!
503 if (slot->seq_nr != 1) {
508 case -NFS4ERR_SEQ_FALSE_RETRY:
512 /* Just update the slot sequence no. */
516 /* The session may be reset by one of the error handlers. */
517 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
518 nfs41_sequence_free_slot(res);
521 if (rpc_restart_call_prepare(task)) {
527 if (!rpc_restart_call(task))
529 rpc_delay(task, NFS4_POLL_RETRY_MAX);
533 static int nfs4_sequence_done(struct rpc_task *task,
534 struct nfs4_sequence_res *res)
536 if (res->sr_slot == NULL)
538 return nfs41_sequence_done(task, res);
541 static void nfs41_init_sequence(struct nfs4_sequence_args *args,
542 struct nfs4_sequence_res *res, int cache_reply)
544 args->sa_slot = NULL;
545 args->sa_cache_this = 0;
546 args->sa_privileged = 0;
548 args->sa_cache_this = 1;
552 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
554 args->sa_privileged = 1;
557 int nfs41_setup_sequence(struct nfs4_session *session,
558 struct nfs4_sequence_args *args,
559 struct nfs4_sequence_res *res,
560 struct rpc_task *task)
562 struct nfs4_slot *slot;
563 struct nfs4_slot_table *tbl;
565 dprintk("--> %s\n", __func__);
566 /* slot already allocated? */
567 if (res->sr_slot != NULL)
570 tbl = &session->fc_slot_table;
572 task->tk_timeout = 0;
574 spin_lock(&tbl->slot_tbl_lock);
575 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
576 !args->sa_privileged) {
577 /* The state manager will wait until the slot table is empty */
578 dprintk("%s session is draining\n", __func__);
582 slot = nfs4_alloc_slot(tbl);
584 /* If out of memory, try again in 1/4 second */
585 if (slot == ERR_PTR(-ENOMEM))
586 task->tk_timeout = HZ >> 2;
587 dprintk("<-- %s: no free slots\n", __func__);
590 spin_unlock(&tbl->slot_tbl_lock);
592 args->sa_slot = slot;
594 dprintk("<-- %s slotid=%d seqid=%d\n", __func__,
595 slot->slot_nr, slot->seq_nr);
598 res->sr_timestamp = jiffies;
599 res->sr_status_flags = 0;
601 * sr_status is only set in decode_sequence, and so will remain
602 * set to 1 if an rpc level failure occurs.
606 rpc_call_start(task);
609 /* Privileged tasks are queued with top priority */
610 if (args->sa_privileged)
611 rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task,
612 NULL, RPC_PRIORITY_PRIVILEGED);
614 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
615 spin_unlock(&tbl->slot_tbl_lock);
618 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
620 int nfs4_setup_sequence(const struct nfs_server *server,
621 struct nfs4_sequence_args *args,
622 struct nfs4_sequence_res *res,
623 struct rpc_task *task)
625 struct nfs4_session *session = nfs4_get_session(server);
628 if (session == NULL) {
629 rpc_call_start(task);
633 dprintk("--> %s clp %p session %p sr_slot %d\n",
634 __func__, session->clp, session, res->sr_slot ?
635 res->sr_slot->slot_nr : -1);
637 ret = nfs41_setup_sequence(session, args, res, task);
639 dprintk("<-- %s status=%d\n", __func__, ret);
643 struct nfs41_call_sync_data {
644 const struct nfs_server *seq_server;
645 struct nfs4_sequence_args *seq_args;
646 struct nfs4_sequence_res *seq_res;
649 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
651 struct nfs41_call_sync_data *data = calldata;
652 struct nfs4_session *session = nfs4_get_session(data->seq_server);
654 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
656 nfs41_setup_sequence(session, data->seq_args, data->seq_res, task);
659 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
661 struct nfs41_call_sync_data *data = calldata;
663 nfs41_sequence_done(task, data->seq_res);
666 static const struct rpc_call_ops nfs41_call_sync_ops = {
667 .rpc_call_prepare = nfs41_call_sync_prepare,
668 .rpc_call_done = nfs41_call_sync_done,
671 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
672 struct nfs_server *server,
673 struct rpc_message *msg,
674 struct nfs4_sequence_args *args,
675 struct nfs4_sequence_res *res)
678 struct rpc_task *task;
679 struct nfs41_call_sync_data data = {
680 .seq_server = server,
684 struct rpc_task_setup task_setup = {
687 .callback_ops = &nfs41_call_sync_ops,
688 .callback_data = &data
691 task = rpc_run_task(&task_setup);
695 ret = task->tk_status;
703 void nfs41_init_sequence(struct nfs4_sequence_args *args,
704 struct nfs4_sequence_res *res, int cache_reply)
708 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
713 static int nfs4_sequence_done(struct rpc_task *task,
714 struct nfs4_sequence_res *res)
718 #endif /* CONFIG_NFS_V4_1 */
721 int _nfs4_call_sync(struct rpc_clnt *clnt,
722 struct nfs_server *server,
723 struct rpc_message *msg,
724 struct nfs4_sequence_args *args,
725 struct nfs4_sequence_res *res)
727 return rpc_call_sync(clnt, msg, 0);
731 int nfs4_call_sync(struct rpc_clnt *clnt,
732 struct nfs_server *server,
733 struct rpc_message *msg,
734 struct nfs4_sequence_args *args,
735 struct nfs4_sequence_res *res,
738 nfs41_init_sequence(args, res, cache_reply);
739 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
743 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
745 struct nfs_inode *nfsi = NFS_I(dir);
747 spin_lock(&dir->i_lock);
748 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
749 if (!cinfo->atomic || cinfo->before != dir->i_version)
750 nfs_force_lookup_revalidate(dir);
751 dir->i_version = cinfo->after;
752 nfs_fscache_invalidate(dir);
753 spin_unlock(&dir->i_lock);
756 struct nfs4_opendata {
758 struct nfs_openargs o_arg;
759 struct nfs_openres o_res;
760 struct nfs_open_confirmargs c_arg;
761 struct nfs_open_confirmres c_res;
762 struct nfs4_string owner_name;
763 struct nfs4_string group_name;
764 struct nfs_fattr f_attr;
766 struct dentry *dentry;
767 struct nfs4_state_owner *owner;
768 struct nfs4_state *state;
770 unsigned long timestamp;
771 unsigned int rpc_done : 1;
776 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server,
777 int err, struct nfs4_exception *exception)
781 if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1))
783 server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1;
784 exception->retry = 1;
788 static enum open_claim_type4
789 nfs4_map_atomic_open_claim(struct nfs_server *server,
790 enum open_claim_type4 claim)
792 if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
797 case NFS4_OPEN_CLAIM_FH:
798 return NFS4_OPEN_CLAIM_NULL;
799 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
800 return NFS4_OPEN_CLAIM_DELEGATE_CUR;
801 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
802 return NFS4_OPEN_CLAIM_DELEGATE_PREV;
806 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
808 p->o_res.f_attr = &p->f_attr;
809 p->o_res.seqid = p->o_arg.seqid;
810 p->c_res.seqid = p->c_arg.seqid;
811 p->o_res.server = p->o_arg.server;
812 p->o_res.access_request = p->o_arg.access;
813 nfs_fattr_init(&p->f_attr);
814 nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name);
817 static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
818 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
819 const struct iattr *attrs,
820 enum open_claim_type4 claim,
823 struct dentry *parent = dget_parent(dentry);
824 struct inode *dir = parent->d_inode;
825 struct nfs_server *server = NFS_SERVER(dir);
826 struct nfs4_opendata *p;
828 p = kzalloc(sizeof(*p), gfp_mask);
831 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
832 if (p->o_arg.seqid == NULL)
834 nfs_sb_active(dentry->d_sb);
835 p->dentry = dget(dentry);
838 atomic_inc(&sp->so_count);
839 p->o_arg.open_flags = flags;
840 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
841 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
842 * will return permission denied for all bits until close */
843 if (!(flags & O_EXCL)) {
844 /* ask server to check for all possible rights as results
846 p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
847 NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
849 p->o_arg.clientid = server->nfs_client->cl_clientid;
850 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
851 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
852 p->o_arg.name = &dentry->d_name;
853 p->o_arg.server = server;
854 p->o_arg.bitmask = server->attr_bitmask;
855 p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
856 p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
857 switch (p->o_arg.claim) {
858 case NFS4_OPEN_CLAIM_NULL:
859 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
860 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
861 p->o_arg.fh = NFS_FH(dir);
863 case NFS4_OPEN_CLAIM_PREVIOUS:
864 case NFS4_OPEN_CLAIM_FH:
865 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
866 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
867 p->o_arg.fh = NFS_FH(dentry->d_inode);
869 if (attrs != NULL && attrs->ia_valid != 0) {
872 p->o_arg.u.attrs = &p->attrs;
873 memcpy(&p->attrs, attrs, sizeof(p->attrs));
876 verf[1] = current->pid;
877 memcpy(p->o_arg.u.verifier.data, verf,
878 sizeof(p->o_arg.u.verifier.data));
880 p->c_arg.fh = &p->o_res.fh;
881 p->c_arg.stateid = &p->o_res.stateid;
882 p->c_arg.seqid = p->o_arg.seqid;
883 nfs4_init_opendata_res(p);
893 static void nfs4_opendata_free(struct kref *kref)
895 struct nfs4_opendata *p = container_of(kref,
896 struct nfs4_opendata, kref);
897 struct super_block *sb = p->dentry->d_sb;
899 nfs_free_seqid(p->o_arg.seqid);
900 if (p->state != NULL)
901 nfs4_put_open_state(p->state);
902 nfs4_put_state_owner(p->owner);
906 nfs_fattr_free_names(&p->f_attr);
910 static void nfs4_opendata_put(struct nfs4_opendata *p)
913 kref_put(&p->kref, nfs4_opendata_free);
916 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
920 ret = rpc_wait_for_completion_task(task);
924 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
928 if (open_mode & (O_EXCL|O_TRUNC))
930 switch (mode & (FMODE_READ|FMODE_WRITE)) {
932 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
933 && state->n_rdonly != 0;
936 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
937 && state->n_wronly != 0;
939 case FMODE_READ|FMODE_WRITE:
940 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
941 && state->n_rdwr != 0;
947 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
949 if (delegation == NULL)
951 if ((delegation->type & fmode) != fmode)
953 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
955 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
957 nfs_mark_delegation_referenced(delegation);
961 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
970 case FMODE_READ|FMODE_WRITE:
973 nfs4_state_set_mode_locked(state, state->state | fmode);
976 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
978 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
979 nfs4_stateid_copy(&state->stateid, stateid);
980 nfs4_stateid_copy(&state->open_stateid, stateid);
983 set_bit(NFS_O_RDONLY_STATE, &state->flags);
986 set_bit(NFS_O_WRONLY_STATE, &state->flags);
988 case FMODE_READ|FMODE_WRITE:
989 set_bit(NFS_O_RDWR_STATE, &state->flags);
993 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
995 write_seqlock(&state->seqlock);
996 nfs_set_open_stateid_locked(state, stateid, fmode);
997 write_sequnlock(&state->seqlock);
1000 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
1003 * Protect the call to nfs4_state_set_mode_locked and
1004 * serialise the stateid update
1006 write_seqlock(&state->seqlock);
1007 if (deleg_stateid != NULL) {
1008 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1009 set_bit(NFS_DELEGATED_STATE, &state->flags);
1011 if (open_stateid != NULL)
1012 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1013 write_sequnlock(&state->seqlock);
1014 spin_lock(&state->owner->so_lock);
1015 update_open_stateflags(state, fmode);
1016 spin_unlock(&state->owner->so_lock);
1019 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
1021 struct nfs_inode *nfsi = NFS_I(state->inode);
1022 struct nfs_delegation *deleg_cur;
1025 fmode &= (FMODE_READ|FMODE_WRITE);
1028 deleg_cur = rcu_dereference(nfsi->delegation);
1029 if (deleg_cur == NULL)
1032 spin_lock(&deleg_cur->lock);
1033 if (nfsi->delegation != deleg_cur ||
1034 test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) ||
1035 (deleg_cur->type & fmode) != fmode)
1036 goto no_delegation_unlock;
1038 if (delegation == NULL)
1039 delegation = &deleg_cur->stateid;
1040 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1041 goto no_delegation_unlock;
1043 nfs_mark_delegation_referenced(deleg_cur);
1044 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1046 no_delegation_unlock:
1047 spin_unlock(&deleg_cur->lock);
1051 if (!ret && open_stateid != NULL) {
1052 __update_open_stateid(state, open_stateid, NULL, fmode);
1060 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
1062 struct nfs_delegation *delegation;
1065 delegation = rcu_dereference(NFS_I(inode)->delegation);
1066 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1071 nfs4_inode_return_delegation(inode);
1074 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1076 struct nfs4_state *state = opendata->state;
1077 struct nfs_inode *nfsi = NFS_I(state->inode);
1078 struct nfs_delegation *delegation;
1079 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1080 fmode_t fmode = opendata->o_arg.fmode;
1081 nfs4_stateid stateid;
1085 if (can_open_cached(state, fmode, open_mode)) {
1086 spin_lock(&state->owner->so_lock);
1087 if (can_open_cached(state, fmode, open_mode)) {
1088 update_open_stateflags(state, fmode);
1089 spin_unlock(&state->owner->so_lock);
1090 goto out_return_state;
1092 spin_unlock(&state->owner->so_lock);
1095 delegation = rcu_dereference(nfsi->delegation);
1096 if (!can_open_delegated(delegation, fmode)) {
1100 /* Save the delegation */
1101 nfs4_stateid_copy(&stateid, &delegation->stateid);
1103 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1108 /* Try to update the stateid using the delegation */
1109 if (update_open_stateid(state, NULL, &stateid, fmode))
1110 goto out_return_state;
1113 return ERR_PTR(ret);
1115 atomic_inc(&state->count);
1120 nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
1122 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
1123 struct nfs_delegation *delegation;
1124 int delegation_flags = 0;
1127 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1129 delegation_flags = delegation->flags;
1131 if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) {
1132 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1133 "returning a delegation for "
1134 "OPEN(CLAIM_DELEGATE_CUR)\n",
1136 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1137 nfs_inode_set_delegation(state->inode,
1138 data->owner->so_cred,
1141 nfs_inode_reclaim_delegation(state->inode,
1142 data->owner->so_cred,
1147 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1148 * and update the nfs4_state.
1150 static struct nfs4_state *
1151 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)
1153 struct inode *inode = data->state->inode;
1154 struct nfs4_state *state = data->state;
1157 if (!data->rpc_done) {
1158 ret = data->rpc_status;
1163 if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) ||
1164 !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) ||
1165 !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE))
1169 state = nfs4_get_open_state(inode, data->owner);
1173 ret = nfs_refresh_inode(inode, &data->f_attr);
1177 if (data->o_res.delegation_type != 0)
1178 nfs4_opendata_check_deleg(data, state);
1179 update_open_stateid(state, &data->o_res.stateid, NULL,
1184 return ERR_PTR(ret);
1188 static struct nfs4_state *
1189 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1191 struct inode *inode;
1192 struct nfs4_state *state = NULL;
1195 if (!data->rpc_done) {
1196 state = nfs4_try_open_cached(data);
1201 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1203 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1204 ret = PTR_ERR(inode);
1208 state = nfs4_get_open_state(inode, data->owner);
1211 if (data->o_res.delegation_type != 0)
1212 nfs4_opendata_check_deleg(data, state);
1213 update_open_stateid(state, &data->o_res.stateid, NULL,
1217 nfs_release_seqid(data->o_arg.seqid);
1222 return ERR_PTR(ret);
1225 static struct nfs4_state *
1226 nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1228 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS)
1229 return _nfs4_opendata_reclaim_to_nfs4_state(data);
1230 return _nfs4_opendata_to_nfs4_state(data);
1233 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1235 struct nfs_inode *nfsi = NFS_I(state->inode);
1236 struct nfs_open_context *ctx;
1238 spin_lock(&state->inode->i_lock);
1239 list_for_each_entry(ctx, &nfsi->open_files, list) {
1240 if (ctx->state != state)
1242 get_nfs_open_context(ctx);
1243 spin_unlock(&state->inode->i_lock);
1246 spin_unlock(&state->inode->i_lock);
1247 return ERR_PTR(-ENOENT);
1250 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx,
1251 struct nfs4_state *state, enum open_claim_type4 claim)
1253 struct nfs4_opendata *opendata;
1255 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0,
1256 NULL, claim, GFP_NOFS);
1257 if (opendata == NULL)
1258 return ERR_PTR(-ENOMEM);
1259 opendata->state = state;
1260 atomic_inc(&state->count);
1264 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1266 struct nfs4_state *newstate;
1269 opendata->o_arg.open_flags = 0;
1270 opendata->o_arg.fmode = fmode;
1271 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1272 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1273 nfs4_init_opendata_res(opendata);
1274 ret = _nfs4_recover_proc_open(opendata);
1277 newstate = nfs4_opendata_to_nfs4_state(opendata);
1278 if (IS_ERR(newstate))
1279 return PTR_ERR(newstate);
1280 nfs4_close_state(newstate, fmode);
1285 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1287 struct nfs4_state *newstate;
1290 /* memory barrier prior to reading state->n_* */
1291 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1293 if (state->n_rdwr != 0) {
1294 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1295 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1298 if (newstate != state)
1301 if (state->n_wronly != 0) {
1302 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1303 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1306 if (newstate != state)
1309 if (state->n_rdonly != 0) {
1310 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1311 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1314 if (newstate != state)
1318 * We may have performed cached opens for all three recoveries.
1319 * Check if we need to update the current stateid.
1321 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1322 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1323 write_seqlock(&state->seqlock);
1324 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1325 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1326 write_sequnlock(&state->seqlock);
1333 * reclaim state on the server after a reboot.
1335 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1337 struct nfs_delegation *delegation;
1338 struct nfs4_opendata *opendata;
1339 fmode_t delegation_type = 0;
1342 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1343 NFS4_OPEN_CLAIM_PREVIOUS);
1344 if (IS_ERR(opendata))
1345 return PTR_ERR(opendata);
1347 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1348 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1349 delegation_type = delegation->type;
1351 opendata->o_arg.u.delegation_type = delegation_type;
1352 status = nfs4_open_recover(opendata, state);
1353 nfs4_opendata_put(opendata);
1357 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1359 struct nfs_server *server = NFS_SERVER(state->inode);
1360 struct nfs4_exception exception = { };
1363 err = _nfs4_do_open_reclaim(ctx, state);
1364 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1366 if (err != -NFS4ERR_DELAY)
1368 nfs4_handle_exception(server, err, &exception);
1369 } while (exception.retry);
1373 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1375 struct nfs_open_context *ctx;
1378 ctx = nfs4_state_find_open_context(state);
1381 ret = nfs4_do_open_reclaim(ctx, state);
1382 put_nfs_open_context(ctx);
1386 static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err)
1390 printk(KERN_ERR "NFS: %s: unhandled error "
1391 "%d.\n", __func__, err);
1396 case -NFS4ERR_BADSESSION:
1397 case -NFS4ERR_BADSLOT:
1398 case -NFS4ERR_BAD_HIGH_SLOT:
1399 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1400 case -NFS4ERR_DEADSESSION:
1401 set_bit(NFS_DELEGATED_STATE, &state->flags);
1402 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
1404 case -NFS4ERR_STALE_CLIENTID:
1405 case -NFS4ERR_STALE_STATEID:
1406 set_bit(NFS_DELEGATED_STATE, &state->flags);
1407 case -NFS4ERR_EXPIRED:
1408 /* Don't recall a delegation if it was lost */
1409 nfs4_schedule_lease_recovery(server->nfs_client);
1411 case -NFS4ERR_DELEG_REVOKED:
1412 case -NFS4ERR_ADMIN_REVOKED:
1413 case -NFS4ERR_BAD_STATEID:
1414 case -NFS4ERR_OPENMODE:
1415 nfs_inode_find_state_and_recover(state->inode,
1417 nfs4_schedule_stateid_recovery(server, state);
1419 case -NFS4ERR_DELAY:
1420 case -NFS4ERR_GRACE:
1421 set_bit(NFS_DELEGATED_STATE, &state->flags);
1425 case -NFS4ERR_DENIED:
1426 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1432 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1434 struct nfs_server *server = NFS_SERVER(state->inode);
1435 struct nfs4_opendata *opendata;
1438 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1439 NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1440 if (IS_ERR(opendata))
1441 return PTR_ERR(opendata);
1442 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1443 err = nfs4_open_recover(opendata, state);
1444 nfs4_opendata_put(opendata);
1445 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
1448 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1450 struct nfs4_opendata *data = calldata;
1452 data->rpc_status = task->tk_status;
1453 if (data->rpc_status == 0) {
1454 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1455 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1456 renew_lease(data->o_res.server, data->timestamp);
1461 static void nfs4_open_confirm_release(void *calldata)
1463 struct nfs4_opendata *data = calldata;
1464 struct nfs4_state *state = NULL;
1466 /* If this request hasn't been cancelled, do nothing */
1467 if (data->cancelled == 0)
1469 /* In case of error, no cleanup! */
1470 if (!data->rpc_done)
1472 state = nfs4_opendata_to_nfs4_state(data);
1474 nfs4_close_state(state, data->o_arg.fmode);
1476 nfs4_opendata_put(data);
1479 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1480 .rpc_call_done = nfs4_open_confirm_done,
1481 .rpc_release = nfs4_open_confirm_release,
1485 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1487 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1489 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1490 struct rpc_task *task;
1491 struct rpc_message msg = {
1492 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1493 .rpc_argp = &data->c_arg,
1494 .rpc_resp = &data->c_res,
1495 .rpc_cred = data->owner->so_cred,
1497 struct rpc_task_setup task_setup_data = {
1498 .rpc_client = server->client,
1499 .rpc_message = &msg,
1500 .callback_ops = &nfs4_open_confirm_ops,
1501 .callback_data = data,
1502 .workqueue = nfsiod_workqueue,
1503 .flags = RPC_TASK_ASYNC,
1507 kref_get(&data->kref);
1509 data->rpc_status = 0;
1510 data->timestamp = jiffies;
1511 task = rpc_run_task(&task_setup_data);
1513 return PTR_ERR(task);
1514 status = nfs4_wait_for_completion_rpc_task(task);
1516 data->cancelled = 1;
1519 status = data->rpc_status;
1524 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1526 struct nfs4_opendata *data = calldata;
1527 struct nfs4_state_owner *sp = data->owner;
1529 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1532 * Check if we still need to send an OPEN call, or if we can use
1533 * a delegation instead.
1535 if (data->state != NULL) {
1536 struct nfs_delegation *delegation;
1538 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1541 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1542 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1543 can_open_delegated(delegation, data->o_arg.fmode))
1544 goto unlock_no_action;
1547 /* Update client id. */
1548 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1549 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1550 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1551 data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1552 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1554 data->timestamp = jiffies;
1555 if (nfs4_setup_sequence(data->o_arg.server,
1556 &data->o_arg.seq_args,
1557 &data->o_res.seq_res,
1559 nfs_release_seqid(data->o_arg.seqid);
1564 task->tk_action = NULL;
1566 nfs4_sequence_done(task, &data->o_res.seq_res);
1569 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1571 struct nfs4_opendata *data = calldata;
1573 data->rpc_status = task->tk_status;
1575 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1578 if (task->tk_status == 0) {
1579 if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) {
1580 switch (data->o_res.f_attr->mode & S_IFMT) {
1584 data->rpc_status = -ELOOP;
1587 data->rpc_status = -EISDIR;
1590 data->rpc_status = -ENOTDIR;
1593 renew_lease(data->o_res.server, data->timestamp);
1594 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1595 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1600 static void nfs4_open_release(void *calldata)
1602 struct nfs4_opendata *data = calldata;
1603 struct nfs4_state *state = NULL;
1605 /* If this request hasn't been cancelled, do nothing */
1606 if (data->cancelled == 0)
1608 /* In case of error, no cleanup! */
1609 if (data->rpc_status != 0 || !data->rpc_done)
1611 /* In case we need an open_confirm, no cleanup! */
1612 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1614 state = nfs4_opendata_to_nfs4_state(data);
1616 nfs4_close_state(state, data->o_arg.fmode);
1618 nfs4_opendata_put(data);
1621 static const struct rpc_call_ops nfs4_open_ops = {
1622 .rpc_call_prepare = nfs4_open_prepare,
1623 .rpc_call_done = nfs4_open_done,
1624 .rpc_release = nfs4_open_release,
1627 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1629 struct inode *dir = data->dir->d_inode;
1630 struct nfs_server *server = NFS_SERVER(dir);
1631 struct nfs_openargs *o_arg = &data->o_arg;
1632 struct nfs_openres *o_res = &data->o_res;
1633 struct rpc_task *task;
1634 struct rpc_message msg = {
1635 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1638 .rpc_cred = data->owner->so_cred,
1640 struct rpc_task_setup task_setup_data = {
1641 .rpc_client = server->client,
1642 .rpc_message = &msg,
1643 .callback_ops = &nfs4_open_ops,
1644 .callback_data = data,
1645 .workqueue = nfsiod_workqueue,
1646 .flags = RPC_TASK_ASYNC,
1650 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1651 kref_get(&data->kref);
1653 data->rpc_status = 0;
1654 data->cancelled = 0;
1656 nfs4_set_sequence_privileged(&o_arg->seq_args);
1657 task = rpc_run_task(&task_setup_data);
1659 return PTR_ERR(task);
1660 status = nfs4_wait_for_completion_rpc_task(task);
1662 data->cancelled = 1;
1665 status = data->rpc_status;
1671 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1673 struct inode *dir = data->dir->d_inode;
1674 struct nfs_openres *o_res = &data->o_res;
1677 status = nfs4_run_open_task(data, 1);
1678 if (status != 0 || !data->rpc_done)
1681 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1683 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1684 status = _nfs4_proc_open_confirm(data);
1692 static int nfs4_opendata_access(struct rpc_cred *cred,
1693 struct nfs4_opendata *opendata,
1694 struct nfs4_state *state, fmode_t fmode,
1697 struct nfs_access_entry cache;
1700 /* access call failed or for some reason the server doesn't
1701 * support any access modes -- defer access call until later */
1702 if (opendata->o_res.access_supported == 0)
1706 /* don't check MAY_WRITE - a newly created file may not have
1707 * write mode bits, but POSIX allows the creating process to write.
1708 * use openflags to check for exec, because fmode won't
1709 * always have FMODE_EXEC set when file open for exec. */
1710 if (openflags & __FMODE_EXEC) {
1711 /* ONLY check for exec rights */
1713 } else if (fmode & FMODE_READ)
1717 cache.jiffies = jiffies;
1718 nfs_access_set_mask(&cache, opendata->o_res.access_result);
1719 nfs_access_add_cache(state->inode, &cache);
1721 if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0)
1724 /* even though OPEN succeeded, access is denied. Close the file */
1725 nfs4_close_state(state, fmode);
1730 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1732 static int _nfs4_proc_open(struct nfs4_opendata *data)
1734 struct inode *dir = data->dir->d_inode;
1735 struct nfs_server *server = NFS_SERVER(dir);
1736 struct nfs_openargs *o_arg = &data->o_arg;
1737 struct nfs_openres *o_res = &data->o_res;
1740 status = nfs4_run_open_task(data, 0);
1741 if (!data->rpc_done)
1744 if (status == -NFS4ERR_BADNAME &&
1745 !(o_arg->open_flags & O_CREAT))
1750 nfs_fattr_map_and_free_names(server, &data->f_attr);
1752 if (o_arg->open_flags & O_CREAT)
1753 update_changeattr(dir, &o_res->cinfo);
1754 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1755 server->caps &= ~NFS_CAP_POSIX_LOCK;
1756 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1757 status = _nfs4_proc_open_confirm(data);
1761 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1762 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1766 static int nfs4_recover_expired_lease(struct nfs_server *server)
1768 return nfs4_client_recover_expired_lease(server->nfs_client);
1773 * reclaim state on the server after a network partition.
1774 * Assumes caller holds the appropriate lock
1776 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1778 struct nfs4_opendata *opendata;
1781 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1782 NFS4_OPEN_CLAIM_FH);
1783 if (IS_ERR(opendata))
1784 return PTR_ERR(opendata);
1785 ret = nfs4_open_recover(opendata, state);
1787 d_drop(ctx->dentry);
1788 nfs4_opendata_put(opendata);
1792 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1794 struct nfs_server *server = NFS_SERVER(state->inode);
1795 struct nfs4_exception exception = { };
1799 err = _nfs4_open_expired(ctx, state);
1800 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1805 case -NFS4ERR_GRACE:
1806 case -NFS4ERR_DELAY:
1807 nfs4_handle_exception(server, err, &exception);
1810 } while (exception.retry);
1815 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1817 struct nfs_open_context *ctx;
1820 ctx = nfs4_state_find_open_context(state);
1823 ret = nfs4_do_open_expired(ctx, state);
1824 put_nfs_open_context(ctx);
1828 #if defined(CONFIG_NFS_V4_1)
1829 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
1831 struct nfs_server *server = NFS_SERVER(state->inode);
1832 nfs4_stateid *stateid = &state->stateid;
1835 /* If a state reset has been done, test_stateid is unneeded */
1836 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1839 status = nfs41_test_stateid(server, stateid);
1840 if (status != NFS_OK) {
1841 /* Free the stateid unless the server explicitly
1842 * informs us the stateid is unrecognized. */
1843 if (status != -NFS4ERR_BAD_STATEID)
1844 nfs41_free_stateid(server, stateid);
1845 nfs_remove_bad_delegation(state->inode);
1847 write_seqlock(&state->seqlock);
1848 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1849 write_sequnlock(&state->seqlock);
1850 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1855 * nfs41_check_open_stateid - possibly free an open stateid
1857 * @state: NFSv4 state for an inode
1859 * Returns NFS_OK if recovery for this stateid is now finished.
1860 * Otherwise a negative NFS4ERR value is returned.
1862 static int nfs41_check_open_stateid(struct nfs4_state *state)
1864 struct nfs_server *server = NFS_SERVER(state->inode);
1865 nfs4_stateid *stateid = &state->open_stateid;
1868 /* If a state reset has been done, test_stateid is unneeded */
1869 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
1870 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
1871 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
1872 return -NFS4ERR_BAD_STATEID;
1874 status = nfs41_test_stateid(server, stateid);
1875 if (status != NFS_OK) {
1876 /* Free the stateid unless the server explicitly
1877 * informs us the stateid is unrecognized. */
1878 if (status != -NFS4ERR_BAD_STATEID)
1879 nfs41_free_stateid(server, stateid);
1881 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1882 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1883 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1888 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1892 nfs41_clear_delegation_stateid(state);
1893 status = nfs41_check_open_stateid(state);
1894 if (status != NFS_OK)
1895 status = nfs4_open_expired(sp, state);
1901 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1902 * fields corresponding to attributes that were used to store the verifier.
1903 * Make sure we clobber those fields in the later setattr call
1905 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1907 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1908 !(sattr->ia_valid & ATTR_ATIME_SET))
1909 sattr->ia_valid |= ATTR_ATIME;
1911 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1912 !(sattr->ia_valid & ATTR_MTIME_SET))
1913 sattr->ia_valid |= ATTR_MTIME;
1916 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
1919 struct nfs4_state **res)
1921 struct nfs4_state_owner *sp = opendata->owner;
1922 struct nfs_server *server = sp->so_server;
1923 struct nfs4_state *state;
1927 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
1929 ret = _nfs4_proc_open(opendata);
1933 state = nfs4_opendata_to_nfs4_state(opendata);
1934 ret = PTR_ERR(state);
1937 if (server->caps & NFS_CAP_POSIX_LOCK)
1938 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1940 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
1944 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
1945 nfs4_schedule_stateid_recovery(server, state);
1952 * Returns a referenced nfs4_state
1954 static int _nfs4_do_open(struct inode *dir,
1955 struct dentry *dentry,
1958 struct iattr *sattr,
1959 struct rpc_cred *cred,
1960 struct nfs4_state **res,
1961 struct nfs4_threshold **ctx_th)
1963 struct nfs4_state_owner *sp;
1964 struct nfs4_state *state = NULL;
1965 struct nfs_server *server = NFS_SERVER(dir);
1966 struct nfs4_opendata *opendata;
1967 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
1970 /* Protect against reboot recovery conflicts */
1972 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1974 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1977 status = nfs4_recover_expired_lease(server);
1979 goto err_put_state_owner;
1980 if (dentry->d_inode != NULL)
1981 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
1983 if (dentry->d_inode)
1984 claim = NFS4_OPEN_CLAIM_FH;
1985 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
1987 if (opendata == NULL)
1988 goto err_put_state_owner;
1990 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
1991 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
1992 if (!opendata->f_attr.mdsthreshold)
1993 goto err_opendata_put;
1994 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
1996 if (dentry->d_inode != NULL)
1997 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
1999 status = _nfs4_open_and_get_state(opendata, fmode, flags, &state);
2001 goto err_opendata_put;
2003 if (opendata->o_arg.open_flags & O_EXCL) {
2004 nfs4_exclusive_attrset(opendata, sattr);
2006 nfs_fattr_init(opendata->o_res.f_attr);
2007 status = nfs4_do_setattr(state->inode, cred,
2008 opendata->o_res.f_attr, sattr,
2011 nfs_setattr_update_inode(state->inode, sattr);
2012 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
2015 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
2016 *ctx_th = opendata->f_attr.mdsthreshold;
2018 kfree(opendata->f_attr.mdsthreshold);
2019 opendata->f_attr.mdsthreshold = NULL;
2021 nfs4_opendata_put(opendata);
2022 nfs4_put_state_owner(sp);
2026 kfree(opendata->f_attr.mdsthreshold);
2027 nfs4_opendata_put(opendata);
2028 err_put_state_owner:
2029 nfs4_put_state_owner(sp);
2036 static struct nfs4_state *nfs4_do_open(struct inode *dir,
2037 struct dentry *dentry,
2040 struct iattr *sattr,
2041 struct rpc_cred *cred,
2042 struct nfs4_threshold **ctx_th)
2044 struct nfs_server *server = NFS_SERVER(dir);
2045 struct nfs4_exception exception = { };
2046 struct nfs4_state *res;
2049 fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC;
2051 status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred,
2055 /* NOTE: BAD_SEQID means the server and client disagree about the
2056 * book-keeping w.r.t. state-changing operations
2057 * (OPEN/CLOSE/LOCK/LOCKU...)
2058 * It is actually a sign of a bug on the client or on the server.
2060 * If we receive a BAD_SEQID error in the particular case of
2061 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2062 * have unhashed the old state_owner for us, and that we can
2063 * therefore safely retry using a new one. We should still warn
2064 * the user though...
2066 if (status == -NFS4ERR_BAD_SEQID) {
2067 pr_warn_ratelimited("NFS: v4 server %s "
2068 " returned a bad sequence-id error!\n",
2069 NFS_SERVER(dir)->nfs_client->cl_hostname);
2070 exception.retry = 1;
2074 * BAD_STATEID on OPEN means that the server cancelled our
2075 * state before it received the OPEN_CONFIRM.
2076 * Recover by retrying the request as per the discussion
2077 * on Page 181 of RFC3530.
2079 if (status == -NFS4ERR_BAD_STATEID) {
2080 exception.retry = 1;
2083 if (status == -EAGAIN) {
2084 /* We must have found a delegation */
2085 exception.retry = 1;
2088 if (nfs4_clear_cap_atomic_open_v1(server, status, &exception))
2090 res = ERR_PTR(nfs4_handle_exception(server,
2091 status, &exception));
2092 } while (exception.retry);
2096 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2097 struct nfs_fattr *fattr, struct iattr *sattr,
2098 struct nfs4_state *state)
2100 struct nfs_server *server = NFS_SERVER(inode);
2101 struct nfs_setattrargs arg = {
2102 .fh = NFS_FH(inode),
2105 .bitmask = server->attr_bitmask,
2107 struct nfs_setattrres res = {
2111 struct rpc_message msg = {
2112 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2117 unsigned long timestamp = jiffies;
2120 nfs_fattr_init(fattr);
2122 if (state != NULL && nfs4_valid_open_stateid(state)) {
2123 struct nfs_lockowner lockowner = {
2124 .l_owner = current->files,
2125 .l_pid = current->tgid,
2127 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2129 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
2131 /* Use that stateid */
2133 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2135 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2136 if (status == 0 && state != NULL)
2137 renew_lease(server, timestamp);
2141 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2142 struct nfs_fattr *fattr, struct iattr *sattr,
2143 struct nfs4_state *state)
2145 struct nfs_server *server = NFS_SERVER(inode);
2146 struct nfs4_exception exception = {
2152 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
2154 case -NFS4ERR_OPENMODE:
2155 if (state && !(state->state & FMODE_WRITE)) {
2157 if (sattr->ia_valid & ATTR_OPEN)
2162 err = nfs4_handle_exception(server, err, &exception);
2163 } while (exception.retry);
2168 struct nfs4_closedata {
2169 struct inode *inode;
2170 struct nfs4_state *state;
2171 struct nfs_closeargs arg;
2172 struct nfs_closeres res;
2173 struct nfs_fattr fattr;
2174 unsigned long timestamp;
2179 static void nfs4_free_closedata(void *data)
2181 struct nfs4_closedata *calldata = data;
2182 struct nfs4_state_owner *sp = calldata->state->owner;
2183 struct super_block *sb = calldata->state->inode->i_sb;
2186 pnfs_roc_release(calldata->state->inode);
2187 nfs4_put_open_state(calldata->state);
2188 nfs_free_seqid(calldata->arg.seqid);
2189 nfs4_put_state_owner(sp);
2190 nfs_sb_deactive(sb);
2194 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2197 spin_lock(&state->owner->so_lock);
2198 if (!(fmode & FMODE_READ))
2199 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2200 if (!(fmode & FMODE_WRITE))
2201 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2202 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2203 spin_unlock(&state->owner->so_lock);
2206 static void nfs4_close_done(struct rpc_task *task, void *data)
2208 struct nfs4_closedata *calldata = data;
2209 struct nfs4_state *state = calldata->state;
2210 struct nfs_server *server = NFS_SERVER(calldata->inode);
2212 dprintk("%s: begin!\n", __func__);
2213 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2215 /* hmm. we are done with the inode, and in the process of freeing
2216 * the state_owner. we keep this around to process errors
2218 switch (task->tk_status) {
2221 pnfs_roc_set_barrier(state->inode,
2222 calldata->roc_barrier);
2223 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2224 renew_lease(server, calldata->timestamp);
2225 nfs4_close_clear_stateid_flags(state,
2226 calldata->arg.fmode);
2228 case -NFS4ERR_STALE_STATEID:
2229 case -NFS4ERR_OLD_STATEID:
2230 case -NFS4ERR_BAD_STATEID:
2231 case -NFS4ERR_EXPIRED:
2232 if (calldata->arg.fmode == 0)
2235 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2236 rpc_restart_call_prepare(task);
2238 nfs_release_seqid(calldata->arg.seqid);
2239 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2240 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2243 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2245 struct nfs4_closedata *calldata = data;
2246 struct nfs4_state *state = calldata->state;
2247 struct inode *inode = calldata->inode;
2250 dprintk("%s: begin!\n", __func__);
2251 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2254 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2255 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2256 spin_lock(&state->owner->so_lock);
2257 /* Calculate the change in open mode */
2258 if (state->n_rdwr == 0) {
2259 if (state->n_rdonly == 0) {
2260 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2261 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2262 calldata->arg.fmode &= ~FMODE_READ;
2264 if (state->n_wronly == 0) {
2265 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2266 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2267 calldata->arg.fmode &= ~FMODE_WRITE;
2270 if (!nfs4_valid_open_stateid(state))
2272 spin_unlock(&state->owner->so_lock);
2275 /* Note: exit _without_ calling nfs4_close_done */
2279 if (calldata->arg.fmode == 0) {
2280 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2281 if (calldata->roc &&
2282 pnfs_roc_drain(inode, &calldata->roc_barrier, task)) {
2283 nfs_release_seqid(calldata->arg.seqid);
2288 nfs_fattr_init(calldata->res.fattr);
2289 calldata->timestamp = jiffies;
2290 if (nfs4_setup_sequence(NFS_SERVER(inode),
2291 &calldata->arg.seq_args,
2292 &calldata->res.seq_res,
2294 nfs_release_seqid(calldata->arg.seqid);
2295 dprintk("%s: done!\n", __func__);
2298 task->tk_action = NULL;
2300 nfs4_sequence_done(task, &calldata->res.seq_res);
2303 static const struct rpc_call_ops nfs4_close_ops = {
2304 .rpc_call_prepare = nfs4_close_prepare,
2305 .rpc_call_done = nfs4_close_done,
2306 .rpc_release = nfs4_free_closedata,
2310 * It is possible for data to be read/written from a mem-mapped file
2311 * after the sys_close call (which hits the vfs layer as a flush).
2312 * This means that we can't safely call nfsv4 close on a file until
2313 * the inode is cleared. This in turn means that we are not good
2314 * NFSv4 citizens - we do not indicate to the server to update the file's
2315 * share state even when we are done with one of the three share
2316 * stateid's in the inode.
2318 * NOTE: Caller must be holding the sp->so_owner semaphore!
2320 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
2322 struct nfs_server *server = NFS_SERVER(state->inode);
2323 struct nfs4_closedata *calldata;
2324 struct nfs4_state_owner *sp = state->owner;
2325 struct rpc_task *task;
2326 struct rpc_message msg = {
2327 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2328 .rpc_cred = state->owner->so_cred,
2330 struct rpc_task_setup task_setup_data = {
2331 .rpc_client = server->client,
2332 .rpc_message = &msg,
2333 .callback_ops = &nfs4_close_ops,
2334 .workqueue = nfsiod_workqueue,
2335 .flags = RPC_TASK_ASYNC,
2337 int status = -ENOMEM;
2339 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2340 if (calldata == NULL)
2342 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2343 calldata->inode = state->inode;
2344 calldata->state = state;
2345 calldata->arg.fh = NFS_FH(state->inode);
2346 calldata->arg.stateid = &state->open_stateid;
2347 /* Serialization for the sequence id */
2348 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2349 if (calldata->arg.seqid == NULL)
2350 goto out_free_calldata;
2351 calldata->arg.fmode = 0;
2352 calldata->arg.bitmask = server->cache_consistency_bitmask;
2353 calldata->res.fattr = &calldata->fattr;
2354 calldata->res.seqid = calldata->arg.seqid;
2355 calldata->res.server = server;
2356 calldata->roc = pnfs_roc(state->inode);
2357 nfs_sb_active(calldata->inode->i_sb);
2359 msg.rpc_argp = &calldata->arg;
2360 msg.rpc_resp = &calldata->res;
2361 task_setup_data.callback_data = calldata;
2362 task = rpc_run_task(&task_setup_data);
2364 return PTR_ERR(task);
2367 status = rpc_wait_for_completion_task(task);
2373 nfs4_put_open_state(state);
2374 nfs4_put_state_owner(sp);
2378 static struct inode *
2379 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2381 struct nfs4_state *state;
2383 /* Protect against concurrent sillydeletes */
2384 state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr,
2385 ctx->cred, &ctx->mdsthreshold);
2387 return ERR_CAST(state);
2389 return igrab(state->inode);
2392 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2394 if (ctx->state == NULL)
2397 nfs4_close_sync(ctx->state, ctx->mode);
2399 nfs4_close_state(ctx->state, ctx->mode);
2402 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2404 struct nfs4_server_caps_arg args = {
2407 struct nfs4_server_caps_res res = {};
2408 struct rpc_message msg = {
2409 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2415 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2417 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2418 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2419 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2420 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2421 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2422 NFS_CAP_CTIME|NFS_CAP_MTIME);
2423 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2424 server->caps |= NFS_CAP_ACLS;
2425 if (res.has_links != 0)
2426 server->caps |= NFS_CAP_HARDLINKS;
2427 if (res.has_symlinks != 0)
2428 server->caps |= NFS_CAP_SYMLINKS;
2429 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2430 server->caps |= NFS_CAP_FILEID;
2431 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2432 server->caps |= NFS_CAP_MODE;
2433 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2434 server->caps |= NFS_CAP_NLINK;
2435 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2436 server->caps |= NFS_CAP_OWNER;
2437 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2438 server->caps |= NFS_CAP_OWNER_GROUP;
2439 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2440 server->caps |= NFS_CAP_ATIME;
2441 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2442 server->caps |= NFS_CAP_CTIME;
2443 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2444 server->caps |= NFS_CAP_MTIME;
2446 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2447 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2448 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2449 server->acl_bitmask = res.acl_bitmask;
2450 server->fh_expire_type = res.fh_expire_type;
2456 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2458 struct nfs4_exception exception = { };
2461 err = nfs4_handle_exception(server,
2462 _nfs4_server_capabilities(server, fhandle),
2464 } while (exception.retry);
2468 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2469 struct nfs_fsinfo *info)
2471 struct nfs4_lookup_root_arg args = {
2472 .bitmask = nfs4_fattr_bitmap,
2474 struct nfs4_lookup_res res = {
2476 .fattr = info->fattr,
2479 struct rpc_message msg = {
2480 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2485 nfs_fattr_init(info->fattr);
2486 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2489 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2490 struct nfs_fsinfo *info)
2492 struct nfs4_exception exception = { };
2495 err = _nfs4_lookup_root(server, fhandle, info);
2498 case -NFS4ERR_WRONGSEC:
2501 err = nfs4_handle_exception(server, err, &exception);
2503 } while (exception.retry);
2508 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2509 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2511 struct rpc_auth *auth;
2514 auth = rpcauth_create(flavor, server->client);
2519 ret = nfs4_lookup_root(server, fhandle, info);
2524 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2525 struct nfs_fsinfo *info)
2527 int i, len, status = 0;
2528 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS];
2530 len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array));
2534 for (i = 0; i < len; i++) {
2535 /* AUTH_UNIX is the default flavor if none was specified,
2536 * thus has already been tried. */
2537 if (flav_array[i] == RPC_AUTH_UNIX)
2540 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2541 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2546 * -EACCESS could mean that the user doesn't have correct permissions
2547 * to access the mount. It could also mean that we tried to mount
2548 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2549 * existing mount programs don't handle -EACCES very well so it should
2550 * be mapped to -EPERM instead.
2552 if (status == -EACCES)
2558 * get the file handle for the "/" directory on the server
2560 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2561 struct nfs_fsinfo *info)
2563 int minor_version = server->nfs_client->cl_minorversion;
2564 int status = nfs4_lookup_root(server, fhandle, info);
2565 if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR))
2567 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2568 * by nfs4_map_errors() as this function exits.
2570 status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info);
2572 status = nfs4_server_capabilities(server, fhandle);
2574 status = nfs4_do_fsinfo(server, fhandle, info);
2575 return nfs4_map_errors(status);
2578 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2579 struct nfs_fsinfo *info)
2582 struct nfs_fattr *fattr = info->fattr;
2584 error = nfs4_server_capabilities(server, mntfh);
2586 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2590 error = nfs4_proc_getattr(server, mntfh, fattr);
2592 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2596 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2597 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2598 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2604 * Get locations and (maybe) other attributes of a referral.
2605 * Note that we'll actually follow the referral later when
2606 * we detect fsid mismatch in inode revalidation
2608 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2609 const struct qstr *name, struct nfs_fattr *fattr,
2610 struct nfs_fh *fhandle)
2612 int status = -ENOMEM;
2613 struct page *page = NULL;
2614 struct nfs4_fs_locations *locations = NULL;
2616 page = alloc_page(GFP_KERNEL);
2619 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2620 if (locations == NULL)
2623 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2626 /* Make sure server returned a different fsid for the referral */
2627 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2628 dprintk("%s: server did not return a different fsid for"
2629 " a referral at %s\n", __func__, name->name);
2633 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2634 nfs_fixup_referral_attributes(&locations->fattr);
2636 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2637 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2638 memset(fhandle, 0, sizeof(struct nfs_fh));
2646 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2648 struct nfs4_getattr_arg args = {
2650 .bitmask = server->attr_bitmask,
2652 struct nfs4_getattr_res res = {
2656 struct rpc_message msg = {
2657 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2662 nfs_fattr_init(fattr);
2663 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2666 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2668 struct nfs4_exception exception = { };
2671 err = nfs4_handle_exception(server,
2672 _nfs4_proc_getattr(server, fhandle, fattr),
2674 } while (exception.retry);
2679 * The file is not closed if it is opened due to the a request to change
2680 * the size of the file. The open call will not be needed once the
2681 * VFS layer lookup-intents are implemented.
2683 * Close is called when the inode is destroyed.
2684 * If we haven't opened the file for O_WRONLY, we
2685 * need to in the size_change case to obtain a stateid.
2688 * Because OPEN is always done by name in nfsv4, it is
2689 * possible that we opened a different file by the same
2690 * name. We can recognize this race condition, but we
2691 * can't do anything about it besides returning an error.
2693 * This will be fixed with VFS changes (lookup-intent).
2696 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2697 struct iattr *sattr)
2699 struct inode *inode = dentry->d_inode;
2700 struct rpc_cred *cred = NULL;
2701 struct nfs4_state *state = NULL;
2704 if (pnfs_ld_layoutret_on_setattr(inode))
2705 pnfs_commit_and_return_layout(inode);
2707 nfs_fattr_init(fattr);
2709 /* Deal with open(O_TRUNC) */
2710 if (sattr->ia_valid & ATTR_OPEN)
2711 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2713 /* Optimization: if the end result is no change, don't RPC */
2714 if ((sattr->ia_valid & ~(ATTR_FILE)) == 0)
2717 /* Search for an existing open(O_WRITE) file */
2718 if (sattr->ia_valid & ATTR_FILE) {
2719 struct nfs_open_context *ctx;
2721 ctx = nfs_file_open_context(sattr->ia_file);
2728 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2730 nfs_setattr_update_inode(inode, sattr);
2734 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2735 const struct qstr *name, struct nfs_fh *fhandle,
2736 struct nfs_fattr *fattr)
2738 struct nfs_server *server = NFS_SERVER(dir);
2740 struct nfs4_lookup_arg args = {
2741 .bitmask = server->attr_bitmask,
2742 .dir_fh = NFS_FH(dir),
2745 struct nfs4_lookup_res res = {
2750 struct rpc_message msg = {
2751 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2756 nfs_fattr_init(fattr);
2758 dprintk("NFS call lookup %s\n", name->name);
2759 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2760 dprintk("NFS reply lookup: %d\n", status);
2764 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
2766 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2767 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
2768 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2772 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
2773 struct qstr *name, struct nfs_fh *fhandle,
2774 struct nfs_fattr *fattr)
2776 struct nfs4_exception exception = { };
2777 struct rpc_clnt *client = *clnt;
2780 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2782 case -NFS4ERR_BADNAME:
2785 case -NFS4ERR_MOVED:
2786 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2788 case -NFS4ERR_WRONGSEC:
2790 if (client != *clnt)
2793 client = nfs4_create_sec_client(client, dir, name);
2795 return PTR_ERR(client);
2797 exception.retry = 1;
2800 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2802 } while (exception.retry);
2807 else if (client != *clnt)
2808 rpc_shutdown_client(client);
2813 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
2814 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2817 struct rpc_clnt *client = NFS_CLIENT(dir);
2819 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2820 if (client != NFS_CLIENT(dir)) {
2821 rpc_shutdown_client(client);
2822 nfs_fixup_secinfo_attributes(fattr);
2828 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
2829 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2832 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
2834 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2836 rpc_shutdown_client(client);
2837 return ERR_PTR(status);
2842 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2844 struct nfs_server *server = NFS_SERVER(inode);
2845 struct nfs4_accessargs args = {
2846 .fh = NFS_FH(inode),
2847 .bitmask = server->cache_consistency_bitmask,
2849 struct nfs4_accessres res = {
2852 struct rpc_message msg = {
2853 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2856 .rpc_cred = entry->cred,
2858 int mode = entry->mask;
2862 * Determine which access bits we want to ask for...
2864 if (mode & MAY_READ)
2865 args.access |= NFS4_ACCESS_READ;
2866 if (S_ISDIR(inode->i_mode)) {
2867 if (mode & MAY_WRITE)
2868 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2869 if (mode & MAY_EXEC)
2870 args.access |= NFS4_ACCESS_LOOKUP;
2872 if (mode & MAY_WRITE)
2873 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2874 if (mode & MAY_EXEC)
2875 args.access |= NFS4_ACCESS_EXECUTE;
2878 res.fattr = nfs_alloc_fattr();
2879 if (res.fattr == NULL)
2882 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2884 nfs_access_set_mask(entry, res.access);
2885 nfs_refresh_inode(inode, res.fattr);
2887 nfs_free_fattr(res.fattr);
2891 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2893 struct nfs4_exception exception = { };
2896 err = nfs4_handle_exception(NFS_SERVER(inode),
2897 _nfs4_proc_access(inode, entry),
2899 } while (exception.retry);
2904 * TODO: For the time being, we don't try to get any attributes
2905 * along with any of the zero-copy operations READ, READDIR,
2908 * In the case of the first three, we want to put the GETATTR
2909 * after the read-type operation -- this is because it is hard
2910 * to predict the length of a GETATTR response in v4, and thus
2911 * align the READ data correctly. This means that the GETATTR
2912 * may end up partially falling into the page cache, and we should
2913 * shift it into the 'tail' of the xdr_buf before processing.
2914 * To do this efficiently, we need to know the total length
2915 * of data received, which doesn't seem to be available outside
2918 * In the case of WRITE, we also want to put the GETATTR after
2919 * the operation -- in this case because we want to make sure
2920 * we get the post-operation mtime and size.
2922 * Both of these changes to the XDR layer would in fact be quite
2923 * minor, but I decided to leave them for a subsequent patch.
2925 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2926 unsigned int pgbase, unsigned int pglen)
2928 struct nfs4_readlink args = {
2929 .fh = NFS_FH(inode),
2934 struct nfs4_readlink_res res;
2935 struct rpc_message msg = {
2936 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2941 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2944 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2945 unsigned int pgbase, unsigned int pglen)
2947 struct nfs4_exception exception = { };
2950 err = nfs4_handle_exception(NFS_SERVER(inode),
2951 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2953 } while (exception.retry);
2958 * This is just for mknod. open(O_CREAT) will always do ->open_context().
2961 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2964 struct nfs_open_context *ctx;
2965 struct nfs4_state *state;
2968 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
2970 return PTR_ERR(ctx);
2972 sattr->ia_mode &= ~current_umask();
2973 state = nfs4_do_open(dir, dentry, ctx->mode,
2974 flags, sattr, ctx->cred,
2975 &ctx->mdsthreshold);
2977 if (IS_ERR(state)) {
2978 status = PTR_ERR(state);
2981 d_add(dentry, igrab(state->inode));
2982 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2985 put_nfs_open_context(ctx);
2989 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2991 struct nfs_server *server = NFS_SERVER(dir);
2992 struct nfs_removeargs args = {
2996 struct nfs_removeres res = {
2999 struct rpc_message msg = {
3000 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
3006 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
3008 update_changeattr(dir, &res.cinfo);
3012 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
3014 struct nfs4_exception exception = { };
3017 err = nfs4_handle_exception(NFS_SERVER(dir),
3018 _nfs4_proc_remove(dir, name),
3020 } while (exception.retry);
3024 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
3026 struct nfs_server *server = NFS_SERVER(dir);
3027 struct nfs_removeargs *args = msg->rpc_argp;
3028 struct nfs_removeres *res = msg->rpc_resp;
3030 res->server = server;
3031 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
3032 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
3035 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
3037 nfs4_setup_sequence(NFS_SERVER(data->dir),
3038 &data->args.seq_args,
3043 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
3045 struct nfs_removeres *res = task->tk_msg.rpc_resp;
3047 if (!nfs4_sequence_done(task, &res->seq_res))
3049 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3051 update_changeattr(dir, &res->cinfo);
3055 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
3057 struct nfs_server *server = NFS_SERVER(dir);
3058 struct nfs_renameargs *arg = msg->rpc_argp;
3059 struct nfs_renameres *res = msg->rpc_resp;
3061 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
3062 res->server = server;
3063 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
3066 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
3068 nfs4_setup_sequence(NFS_SERVER(data->old_dir),
3069 &data->args.seq_args,
3074 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
3075 struct inode *new_dir)
3077 struct nfs_renameres *res = task->tk_msg.rpc_resp;
3079 if (!nfs4_sequence_done(task, &res->seq_res))
3081 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3084 update_changeattr(old_dir, &res->old_cinfo);
3085 update_changeattr(new_dir, &res->new_cinfo);
3089 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3090 struct inode *new_dir, struct qstr *new_name)
3092 struct nfs_server *server = NFS_SERVER(old_dir);
3093 struct nfs_renameargs arg = {
3094 .old_dir = NFS_FH(old_dir),
3095 .new_dir = NFS_FH(new_dir),
3096 .old_name = old_name,
3097 .new_name = new_name,
3099 struct nfs_renameres res = {
3102 struct rpc_message msg = {
3103 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3107 int status = -ENOMEM;
3109 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3111 update_changeattr(old_dir, &res.old_cinfo);
3112 update_changeattr(new_dir, &res.new_cinfo);
3117 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3118 struct inode *new_dir, struct qstr *new_name)
3120 struct nfs4_exception exception = { };
3123 err = nfs4_handle_exception(NFS_SERVER(old_dir),
3124 _nfs4_proc_rename(old_dir, old_name,
3127 } while (exception.retry);
3131 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3133 struct nfs_server *server = NFS_SERVER(inode);
3134 struct nfs4_link_arg arg = {
3135 .fh = NFS_FH(inode),
3136 .dir_fh = NFS_FH(dir),
3138 .bitmask = server->attr_bitmask,
3140 struct nfs4_link_res res = {
3143 struct rpc_message msg = {
3144 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3148 int status = -ENOMEM;
3150 res.fattr = nfs_alloc_fattr();
3151 if (res.fattr == NULL)
3154 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3156 update_changeattr(dir, &res.cinfo);
3157 nfs_post_op_update_inode(inode, res.fattr);
3160 nfs_free_fattr(res.fattr);
3164 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3166 struct nfs4_exception exception = { };
3169 err = nfs4_handle_exception(NFS_SERVER(inode),
3170 _nfs4_proc_link(inode, dir, name),
3172 } while (exception.retry);
3176 struct nfs4_createdata {
3177 struct rpc_message msg;
3178 struct nfs4_create_arg arg;
3179 struct nfs4_create_res res;
3181 struct nfs_fattr fattr;
3184 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3185 struct qstr *name, struct iattr *sattr, u32 ftype)
3187 struct nfs4_createdata *data;
3189 data = kzalloc(sizeof(*data), GFP_KERNEL);
3191 struct nfs_server *server = NFS_SERVER(dir);
3193 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3194 data->msg.rpc_argp = &data->arg;
3195 data->msg.rpc_resp = &data->res;
3196 data->arg.dir_fh = NFS_FH(dir);
3197 data->arg.server = server;
3198 data->arg.name = name;
3199 data->arg.attrs = sattr;
3200 data->arg.ftype = ftype;
3201 data->arg.bitmask = server->attr_bitmask;
3202 data->res.server = server;
3203 data->res.fh = &data->fh;
3204 data->res.fattr = &data->fattr;
3205 nfs_fattr_init(data->res.fattr);
3210 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3212 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3213 &data->arg.seq_args, &data->res.seq_res, 1);
3215 update_changeattr(dir, &data->res.dir_cinfo);
3216 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
3221 static void nfs4_free_createdata(struct nfs4_createdata *data)
3226 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3227 struct page *page, unsigned int len, struct iattr *sattr)
3229 struct nfs4_createdata *data;
3230 int status = -ENAMETOOLONG;
3232 if (len > NFS4_MAXPATHLEN)
3236 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3240 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3241 data->arg.u.symlink.pages = &page;
3242 data->arg.u.symlink.len = len;
3244 status = nfs4_do_create(dir, dentry, data);
3246 nfs4_free_createdata(data);
3251 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3252 struct page *page, unsigned int len, struct iattr *sattr)
3254 struct nfs4_exception exception = { };
3257 err = nfs4_handle_exception(NFS_SERVER(dir),
3258 _nfs4_proc_symlink(dir, dentry, page,
3261 } while (exception.retry);
3265 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3266 struct iattr *sattr)
3268 struct nfs4_createdata *data;
3269 int status = -ENOMEM;
3271 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3275 status = nfs4_do_create(dir, dentry, data);
3277 nfs4_free_createdata(data);
3282 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3283 struct iattr *sattr)
3285 struct nfs4_exception exception = { };
3288 sattr->ia_mode &= ~current_umask();
3290 err = nfs4_handle_exception(NFS_SERVER(dir),
3291 _nfs4_proc_mkdir(dir, dentry, sattr),
3293 } while (exception.retry);
3297 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3298 u64 cookie, struct page **pages, unsigned int count, int plus)
3300 struct inode *dir = dentry->d_inode;
3301 struct nfs4_readdir_arg args = {
3306 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3309 struct nfs4_readdir_res res;
3310 struct rpc_message msg = {
3311 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3318 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3319 dentry->d_parent->d_name.name,
3320 dentry->d_name.name,
3321 (unsigned long long)cookie);
3322 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3323 res.pgbase = args.pgbase;
3324 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3326 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3327 status += args.pgbase;
3330 nfs_invalidate_atime(dir);
3332 dprintk("%s: returns %d\n", __func__, status);
3336 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3337 u64 cookie, struct page **pages, unsigned int count, int plus)
3339 struct nfs4_exception exception = { };
3342 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
3343 _nfs4_proc_readdir(dentry, cred, cookie,
3344 pages, count, plus),
3346 } while (exception.retry);
3350 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3351 struct iattr *sattr, dev_t rdev)
3353 struct nfs4_createdata *data;
3354 int mode = sattr->ia_mode;
3355 int status = -ENOMEM;
3357 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3362 data->arg.ftype = NF4FIFO;
3363 else if (S_ISBLK(mode)) {
3364 data->arg.ftype = NF4BLK;
3365 data->arg.u.device.specdata1 = MAJOR(rdev);
3366 data->arg.u.device.specdata2 = MINOR(rdev);
3368 else if (S_ISCHR(mode)) {
3369 data->arg.ftype = NF4CHR;
3370 data->arg.u.device.specdata1 = MAJOR(rdev);
3371 data->arg.u.device.specdata2 = MINOR(rdev);
3372 } else if (!S_ISSOCK(mode)) {
3377 status = nfs4_do_create(dir, dentry, data);
3379 nfs4_free_createdata(data);
3384 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3385 struct iattr *sattr, dev_t rdev)
3387 struct nfs4_exception exception = { };
3390 sattr->ia_mode &= ~current_umask();
3392 err = nfs4_handle_exception(NFS_SERVER(dir),
3393 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3395 } while (exception.retry);
3399 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3400 struct nfs_fsstat *fsstat)
3402 struct nfs4_statfs_arg args = {
3404 .bitmask = server->attr_bitmask,
3406 struct nfs4_statfs_res res = {
3409 struct rpc_message msg = {
3410 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3415 nfs_fattr_init(fsstat->fattr);
3416 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3419 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3421 struct nfs4_exception exception = { };
3424 err = nfs4_handle_exception(server,
3425 _nfs4_proc_statfs(server, fhandle, fsstat),
3427 } while (exception.retry);
3431 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3432 struct nfs_fsinfo *fsinfo)
3434 struct nfs4_fsinfo_arg args = {
3436 .bitmask = server->attr_bitmask,
3438 struct nfs4_fsinfo_res res = {
3441 struct rpc_message msg = {
3442 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3447 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3450 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3452 struct nfs4_exception exception = { };
3456 err = nfs4_handle_exception(server,
3457 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3459 } while (exception.retry);
3463 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3467 nfs_fattr_init(fsinfo->fattr);
3468 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3470 /* block layout checks this! */
3471 server->pnfs_blksize = fsinfo->blksize;
3472 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3478 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3479 struct nfs_pathconf *pathconf)
3481 struct nfs4_pathconf_arg args = {
3483 .bitmask = server->attr_bitmask,
3485 struct nfs4_pathconf_res res = {
3486 .pathconf = pathconf,
3488 struct rpc_message msg = {
3489 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3494 /* None of the pathconf attributes are mandatory to implement */
3495 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3496 memset(pathconf, 0, sizeof(*pathconf));
3500 nfs_fattr_init(pathconf->fattr);
3501 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3504 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3505 struct nfs_pathconf *pathconf)
3507 struct nfs4_exception exception = { };
3511 err = nfs4_handle_exception(server,
3512 _nfs4_proc_pathconf(server, fhandle, pathconf),
3514 } while (exception.retry);
3518 int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3519 const struct nfs_open_context *ctx,
3520 const struct nfs_lock_context *l_ctx,
3523 const struct nfs_lockowner *lockowner = NULL;
3526 lockowner = &l_ctx->lockowner;
3527 return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner);
3529 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid);
3531 static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
3532 const struct nfs_open_context *ctx,
3533 const struct nfs_lock_context *l_ctx,
3536 nfs4_stateid current_stateid;
3538 if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode))
3540 return nfs4_stateid_match(stateid, ¤t_stateid);
3543 static bool nfs4_error_stateid_expired(int err)
3546 case -NFS4ERR_DELEG_REVOKED:
3547 case -NFS4ERR_ADMIN_REVOKED:
3548 case -NFS4ERR_BAD_STATEID:
3549 case -NFS4ERR_STALE_STATEID:
3550 case -NFS4ERR_OLD_STATEID:
3551 case -NFS4ERR_OPENMODE:
3552 case -NFS4ERR_EXPIRED:
3558 void __nfs4_read_done_cb(struct nfs_read_data *data)
3560 nfs_invalidate_atime(data->header->inode);
3563 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3565 struct nfs_server *server = NFS_SERVER(data->header->inode);
3567 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3568 rpc_restart_call_prepare(task);
3572 __nfs4_read_done_cb(data);
3573 if (task->tk_status > 0)
3574 renew_lease(server, data->timestamp);
3578 static bool nfs4_read_stateid_changed(struct rpc_task *task,
3579 struct nfs_readargs *args)
3582 if (!nfs4_error_stateid_expired(task->tk_status) ||
3583 nfs4_stateid_is_current(&args->stateid,
3588 rpc_restart_call_prepare(task);
3592 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3595 dprintk("--> %s\n", __func__);
3597 if (!nfs4_sequence_done(task, &data->res.seq_res))
3599 if (nfs4_read_stateid_changed(task, &data->args))
3601 return data->read_done_cb ? data->read_done_cb(task, data) :
3602 nfs4_read_done_cb(task, data);
3605 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3607 data->timestamp = jiffies;
3608 data->read_done_cb = nfs4_read_done_cb;
3609 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3610 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3613 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3615 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3616 &data->args.seq_args,
3620 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3621 data->args.lock_context, FMODE_READ);
3624 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3626 struct inode *inode = data->header->inode;
3628 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3629 rpc_restart_call_prepare(task);
3632 if (task->tk_status >= 0) {
3633 renew_lease(NFS_SERVER(inode), data->timestamp);
3634 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
3639 static bool nfs4_write_stateid_changed(struct rpc_task *task,
3640 struct nfs_writeargs *args)
3643 if (!nfs4_error_stateid_expired(task->tk_status) ||
3644 nfs4_stateid_is_current(&args->stateid,
3649 rpc_restart_call_prepare(task);
3653 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3655 if (!nfs4_sequence_done(task, &data->res.seq_res))
3657 if (nfs4_write_stateid_changed(task, &data->args))
3659 return data->write_done_cb ? data->write_done_cb(task, data) :
3660 nfs4_write_done_cb(task, data);
3664 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
3666 const struct nfs_pgio_header *hdr = data->header;
3668 /* Don't request attributes for pNFS or O_DIRECT writes */
3669 if (data->ds_clp != NULL || hdr->dreq != NULL)
3671 /* Otherwise, request attributes if and only if we don't hold
3674 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
3677 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3679 struct nfs_server *server = NFS_SERVER(data->header->inode);
3681 if (!nfs4_write_need_cache_consistency_data(data)) {
3682 data->args.bitmask = NULL;
3683 data->res.fattr = NULL;
3685 data->args.bitmask = server->cache_consistency_bitmask;
3687 if (!data->write_done_cb)
3688 data->write_done_cb = nfs4_write_done_cb;
3689 data->res.server = server;
3690 data->timestamp = jiffies;
3692 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3693 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3696 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3698 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3699 &data->args.seq_args,
3703 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3704 data->args.lock_context, FMODE_WRITE);
3707 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
3709 nfs4_setup_sequence(NFS_SERVER(data->inode),
3710 &data->args.seq_args,
3715 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
3717 struct inode *inode = data->inode;
3719 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3720 rpc_restart_call_prepare(task);
3726 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
3728 if (!nfs4_sequence_done(task, &data->res.seq_res))
3730 return data->commit_done_cb(task, data);
3733 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
3735 struct nfs_server *server = NFS_SERVER(data->inode);
3737 if (data->commit_done_cb == NULL)
3738 data->commit_done_cb = nfs4_commit_done_cb;
3739 data->res.server = server;
3740 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3741 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3744 struct nfs4_renewdata {
3745 struct nfs_client *client;
3746 unsigned long timestamp;
3750 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3751 * standalone procedure for queueing an asynchronous RENEW.
3753 static void nfs4_renew_release(void *calldata)
3755 struct nfs4_renewdata *data = calldata;
3756 struct nfs_client *clp = data->client;
3758 if (atomic_read(&clp->cl_count) > 1)
3759 nfs4_schedule_state_renewal(clp);
3760 nfs_put_client(clp);
3764 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3766 struct nfs4_renewdata *data = calldata;
3767 struct nfs_client *clp = data->client;
3768 unsigned long timestamp = data->timestamp;
3770 if (task->tk_status < 0) {
3771 /* Unless we're shutting down, schedule state recovery! */
3772 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
3774 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
3775 nfs4_schedule_lease_recovery(clp);
3778 nfs4_schedule_path_down_recovery(clp);
3780 do_renew_lease(clp, timestamp);
3783 static const struct rpc_call_ops nfs4_renew_ops = {
3784 .rpc_call_done = nfs4_renew_done,
3785 .rpc_release = nfs4_renew_release,
3788 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
3790 struct rpc_message msg = {
3791 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3795 struct nfs4_renewdata *data;
3797 if (renew_flags == 0)
3799 if (!atomic_inc_not_zero(&clp->cl_count))
3801 data = kmalloc(sizeof(*data), GFP_NOFS);
3805 data->timestamp = jiffies;
3806 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT,
3807 &nfs4_renew_ops, data);
3810 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3812 struct rpc_message msg = {
3813 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3817 unsigned long now = jiffies;
3820 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
3823 do_renew_lease(clp, now);
3827 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3829 return (server->caps & NFS_CAP_ACLS)
3830 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3831 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3834 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
3835 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
3838 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
3840 static int buf_to_pages_noslab(const void *buf, size_t buflen,
3841 struct page **pages, unsigned int *pgbase)
3843 struct page *newpage, **spages;
3849 len = min_t(size_t, PAGE_SIZE, buflen);
3850 newpage = alloc_page(GFP_KERNEL);
3852 if (newpage == NULL)
3854 memcpy(page_address(newpage), buf, len);
3859 } while (buflen != 0);
3865 __free_page(spages[rc-1]);
3869 struct nfs4_cached_acl {
3875 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3877 struct nfs_inode *nfsi = NFS_I(inode);
3879 spin_lock(&inode->i_lock);
3880 kfree(nfsi->nfs4_acl);
3881 nfsi->nfs4_acl = acl;
3882 spin_unlock(&inode->i_lock);
3885 static void nfs4_zap_acl_attr(struct inode *inode)
3887 nfs4_set_cached_acl(inode, NULL);
3890 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3892 struct nfs_inode *nfsi = NFS_I(inode);
3893 struct nfs4_cached_acl *acl;
3896 spin_lock(&inode->i_lock);
3897 acl = nfsi->nfs4_acl;
3900 if (buf == NULL) /* user is just asking for length */
3902 if (acl->cached == 0)
3904 ret = -ERANGE; /* see getxattr(2) man page */
3905 if (acl->len > buflen)
3907 memcpy(buf, acl->data, acl->len);
3911 spin_unlock(&inode->i_lock);
3915 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
3917 struct nfs4_cached_acl *acl;
3918 size_t buflen = sizeof(*acl) + acl_len;
3920 if (buflen <= PAGE_SIZE) {
3921 acl = kmalloc(buflen, GFP_KERNEL);
3925 _copy_from_pages(acl->data, pages, pgbase, acl_len);
3927 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3934 nfs4_set_cached_acl(inode, acl);
3938 * The getxattr API returns the required buffer length when called with a
3939 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
3940 * the required buf. On a NULL buf, we send a page of data to the server
3941 * guessing that the ACL request can be serviced by a page. If so, we cache
3942 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
3943 * the cache. If not so, we throw away the page, and cache the required
3944 * length. The next getxattr call will then produce another round trip to
3945 * the server, this time with the input buf of the required size.
3947 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3949 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
3950 struct nfs_getaclargs args = {
3951 .fh = NFS_FH(inode),
3955 struct nfs_getaclres res = {
3958 struct rpc_message msg = {
3959 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3963 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
3964 int ret = -ENOMEM, i;
3966 /* As long as we're doing a round trip to the server anyway,
3967 * let's be prepared for a page of acl data. */
3970 if (npages > ARRAY_SIZE(pages))
3973 for (i = 0; i < npages; i++) {
3974 pages[i] = alloc_page(GFP_KERNEL);
3979 /* for decoding across pages */
3980 res.acl_scratch = alloc_page(GFP_KERNEL);
3981 if (!res.acl_scratch)
3984 args.acl_len = npages * PAGE_SIZE;
3985 args.acl_pgbase = 0;
3987 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3988 __func__, buf, buflen, npages, args.acl_len);
3989 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
3990 &msg, &args.seq_args, &res.seq_res, 0);
3994 /* Handle the case where the passed-in buffer is too short */
3995 if (res.acl_flags & NFS4_ACL_TRUNC) {
3996 /* Did the user only issue a request for the acl length? */
4002 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
4004 if (res.acl_len > buflen) {
4008 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
4013 for (i = 0; i < npages; i++)
4015 __free_page(pages[i]);
4016 if (res.acl_scratch)
4017 __free_page(res.acl_scratch);
4021 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4023 struct nfs4_exception exception = { };
4026 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
4029 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
4030 } while (exception.retry);
4034 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
4036 struct nfs_server *server = NFS_SERVER(inode);
4039 if (!nfs4_server_supports_acls(server))
4041 ret = nfs_revalidate_inode(server, inode);
4044 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
4045 nfs_zap_acl_cache(inode);
4046 ret = nfs4_read_cached_acl(inode, buf, buflen);
4048 /* -ENOENT is returned if there is no ACL or if there is an ACL
4049 * but no cached acl data, just the acl length */
4051 return nfs4_get_acl_uncached(inode, buf, buflen);
4054 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4056 struct nfs_server *server = NFS_SERVER(inode);
4057 struct page *pages[NFS4ACL_MAXPAGES];
4058 struct nfs_setaclargs arg = {
4059 .fh = NFS_FH(inode),
4063 struct nfs_setaclres res;
4064 struct rpc_message msg = {
4065 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
4069 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4072 if (!nfs4_server_supports_acls(server))
4074 if (npages > ARRAY_SIZE(pages))
4076 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
4079 nfs4_inode_return_delegation(inode);
4080 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4083 * Free each page after tx, so the only ref left is
4084 * held by the network stack
4087 put_page(pages[i-1]);
4090 * Acl update can result in inode attribute update.
4091 * so mark the attribute cache invalid.
4093 spin_lock(&inode->i_lock);
4094 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
4095 spin_unlock(&inode->i_lock);
4096 nfs_access_zap_cache(inode);
4097 nfs_zap_acl_cache(inode);
4101 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4103 struct nfs4_exception exception = { };
4106 err = nfs4_handle_exception(NFS_SERVER(inode),
4107 __nfs4_proc_set_acl(inode, buf, buflen),
4109 } while (exception.retry);
4114 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
4116 struct nfs_client *clp = server->nfs_client;
4118 if (task->tk_status >= 0)
4120 switch(task->tk_status) {
4121 case -NFS4ERR_DELEG_REVOKED:
4122 case -NFS4ERR_ADMIN_REVOKED:
4123 case -NFS4ERR_BAD_STATEID:
4126 nfs_remove_bad_delegation(state->inode);
4127 case -NFS4ERR_OPENMODE:
4130 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4131 goto stateid_invalid;
4132 goto wait_on_recovery;
4133 case -NFS4ERR_EXPIRED:
4134 if (state != NULL) {
4135 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4136 goto stateid_invalid;
4138 case -NFS4ERR_STALE_STATEID:
4139 case -NFS4ERR_STALE_CLIENTID:
4140 nfs4_schedule_lease_recovery(clp);
4141 goto wait_on_recovery;
4142 #if defined(CONFIG_NFS_V4_1)
4143 case -NFS4ERR_BADSESSION:
4144 case -NFS4ERR_BADSLOT:
4145 case -NFS4ERR_BAD_HIGH_SLOT:
4146 case -NFS4ERR_DEADSESSION:
4147 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4148 case -NFS4ERR_SEQ_FALSE_RETRY:
4149 case -NFS4ERR_SEQ_MISORDERED:
4150 dprintk("%s ERROR %d, Reset session\n", __func__,
4152 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
4153 task->tk_status = 0;
4155 #endif /* CONFIG_NFS_V4_1 */
4156 case -NFS4ERR_DELAY:
4157 nfs_inc_server_stats(server, NFSIOS_DELAY);
4158 case -NFS4ERR_GRACE:
4159 rpc_delay(task, NFS4_POLL_RETRY_MAX);
4160 task->tk_status = 0;
4162 case -NFS4ERR_RETRY_UNCACHED_REP:
4163 case -NFS4ERR_OLD_STATEID:
4164 task->tk_status = 0;
4167 task->tk_status = nfs4_map_errors(task->tk_status);
4170 task->tk_status = -EIO;
4173 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
4174 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4175 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
4176 task->tk_status = 0;
4180 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
4181 nfs4_verifier *bootverf)
4185 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4186 /* An impossible timestamp guarantees this value
4187 * will never match a generated boot time. */
4189 verf[1] = (__be32)(NSEC_PER_SEC + 1);
4191 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4192 verf[0] = (__be32)nn->boot_time.tv_sec;
4193 verf[1] = (__be32)nn->boot_time.tv_nsec;
4195 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4199 nfs4_init_nonuniform_client_string(const struct nfs_client *clp,
4200 char *buf, size_t len)
4202 unsigned int result;
4205 result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s",
4207 rpc_peeraddr2str(clp->cl_rpcclient,
4209 rpc_peeraddr2str(clp->cl_rpcclient,
4210 RPC_DISPLAY_PROTO));
4216 nfs4_init_uniform_client_string(const struct nfs_client *clp,
4217 char *buf, size_t len)
4219 char *nodename = clp->cl_rpcclient->cl_nodename;
4221 if (nfs4_client_id_uniquifier[0] != '\0')
4222 nodename = nfs4_client_id_uniquifier;
4223 return scnprintf(buf, len, "Linux NFSv%u.%u %s",
4224 clp->rpc_ops->version, clp->cl_minorversion,
4229 * nfs4_proc_setclientid - Negotiate client ID
4230 * @clp: state data structure
4231 * @program: RPC program for NFSv4 callback service
4232 * @port: IP port number for NFS4 callback service
4233 * @cred: RPC credential to use for this call
4234 * @res: where to place the result
4236 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4238 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4239 unsigned short port, struct rpc_cred *cred,
4240 struct nfs4_setclientid_res *res)
4242 nfs4_verifier sc_verifier;
4243 struct nfs4_setclientid setclientid = {
4244 .sc_verifier = &sc_verifier,
4246 .sc_cb_ident = clp->cl_cb_ident,
4248 struct rpc_message msg = {
4249 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4250 .rpc_argp = &setclientid,
4256 /* nfs_client_id4 */
4257 nfs4_init_boot_verifier(clp, &sc_verifier);
4258 if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
4259 setclientid.sc_name_len =
4260 nfs4_init_uniform_client_string(clp,
4261 setclientid.sc_name,
4262 sizeof(setclientid.sc_name));
4264 setclientid.sc_name_len =
4265 nfs4_init_nonuniform_client_string(clp,
4266 setclientid.sc_name,
4267 sizeof(setclientid.sc_name));
4270 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4271 sizeof(setclientid.sc_netid),
4272 rpc_peeraddr2str(clp->cl_rpcclient,
4273 RPC_DISPLAY_NETID));
4275 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4276 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4277 clp->cl_ipaddr, port >> 8, port & 255);
4279 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4280 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4281 setclientid.sc_name_len, setclientid.sc_name);
4282 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4283 dprintk("NFS reply setclientid: %d\n", status);
4288 * nfs4_proc_setclientid_confirm - Confirm client ID
4289 * @clp: state data structure
4290 * @res: result of a previous SETCLIENTID
4291 * @cred: RPC credential to use for this call
4293 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4295 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4296 struct nfs4_setclientid_res *arg,
4297 struct rpc_cred *cred)
4299 struct nfs_fsinfo fsinfo;
4300 struct rpc_message msg = {
4301 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4303 .rpc_resp = &fsinfo,
4309 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4310 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4313 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4315 spin_lock(&clp->cl_lock);
4316 clp->cl_lease_time = fsinfo.lease_time * HZ;
4317 clp->cl_last_renewal = now;
4318 spin_unlock(&clp->cl_lock);
4320 dprintk("NFS reply setclientid_confirm: %d\n", status);
4324 struct nfs4_delegreturndata {
4325 struct nfs4_delegreturnargs args;
4326 struct nfs4_delegreturnres res;
4328 nfs4_stateid stateid;
4329 unsigned long timestamp;
4330 struct nfs_fattr fattr;
4334 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4336 struct nfs4_delegreturndata *data = calldata;
4338 if (!nfs4_sequence_done(task, &data->res.seq_res))
4341 switch (task->tk_status) {
4342 case -NFS4ERR_STALE_STATEID:
4343 case -NFS4ERR_EXPIRED:
4345 renew_lease(data->res.server, data->timestamp);
4348 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4350 rpc_restart_call_prepare(task);
4354 data->rpc_status = task->tk_status;
4357 static void nfs4_delegreturn_release(void *calldata)
4362 #if defined(CONFIG_NFS_V4_1)
4363 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4365 struct nfs4_delegreturndata *d_data;
4367 d_data = (struct nfs4_delegreturndata *)data;
4369 nfs4_setup_sequence(d_data->res.server,
4370 &d_data->args.seq_args,
4371 &d_data->res.seq_res,
4374 #endif /* CONFIG_NFS_V4_1 */
4376 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4377 #if defined(CONFIG_NFS_V4_1)
4378 .rpc_call_prepare = nfs4_delegreturn_prepare,
4379 #endif /* CONFIG_NFS_V4_1 */
4380 .rpc_call_done = nfs4_delegreturn_done,
4381 .rpc_release = nfs4_delegreturn_release,
4384 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4386 struct nfs4_delegreturndata *data;
4387 struct nfs_server *server = NFS_SERVER(inode);
4388 struct rpc_task *task;
4389 struct rpc_message msg = {
4390 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
4393 struct rpc_task_setup task_setup_data = {
4394 .rpc_client = server->client,
4395 .rpc_message = &msg,
4396 .callback_ops = &nfs4_delegreturn_ops,
4397 .flags = RPC_TASK_ASYNC,
4401 data = kzalloc(sizeof(*data), GFP_NOFS);
4404 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4405 data->args.fhandle = &data->fh;
4406 data->args.stateid = &data->stateid;
4407 data->args.bitmask = server->cache_consistency_bitmask;
4408 nfs_copy_fh(&data->fh, NFS_FH(inode));
4409 nfs4_stateid_copy(&data->stateid, stateid);
4410 data->res.fattr = &data->fattr;
4411 data->res.server = server;
4412 nfs_fattr_init(data->res.fattr);
4413 data->timestamp = jiffies;
4414 data->rpc_status = 0;
4416 task_setup_data.callback_data = data;
4417 msg.rpc_argp = &data->args;
4418 msg.rpc_resp = &data->res;
4419 task = rpc_run_task(&task_setup_data);
4421 return PTR_ERR(task);
4424 status = nfs4_wait_for_completion_rpc_task(task);
4427 status = data->rpc_status;
4429 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4431 nfs_refresh_inode(inode, &data->fattr);
4437 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4439 struct nfs_server *server = NFS_SERVER(inode);
4440 struct nfs4_exception exception = { };
4443 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4445 case -NFS4ERR_STALE_STATEID:
4446 case -NFS4ERR_EXPIRED:
4450 err = nfs4_handle_exception(server, err, &exception);
4451 } while (exception.retry);
4455 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4456 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4459 * sleep, with exponential backoff, and retry the LOCK operation.
4461 static unsigned long
4462 nfs4_set_lock_task_retry(unsigned long timeout)
4464 freezable_schedule_timeout_killable(timeout);
4466 if (timeout > NFS4_LOCK_MAXTIMEOUT)
4467 return NFS4_LOCK_MAXTIMEOUT;
4471 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4473 struct inode *inode = state->inode;
4474 struct nfs_server *server = NFS_SERVER(inode);
4475 struct nfs_client *clp = server->nfs_client;
4476 struct nfs_lockt_args arg = {
4477 .fh = NFS_FH(inode),
4480 struct nfs_lockt_res res = {
4483 struct rpc_message msg = {
4484 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
4487 .rpc_cred = state->owner->so_cred,
4489 struct nfs4_lock_state *lsp;
4492 arg.lock_owner.clientid = clp->cl_clientid;
4493 status = nfs4_set_lock_state(state, request);
4496 lsp = request->fl_u.nfs4_fl.owner;
4497 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4498 arg.lock_owner.s_dev = server->s_dev;
4499 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4502 request->fl_type = F_UNLCK;
4504 case -NFS4ERR_DENIED:
4507 request->fl_ops->fl_release_private(request);
4512 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4514 struct nfs4_exception exception = { };
4518 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4519 _nfs4_proc_getlk(state, cmd, request),
4521 } while (exception.retry);
4525 static int do_vfs_lock(struct file *file, struct file_lock *fl)
4528 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
4530 res = posix_lock_file_wait(file, fl);
4533 res = flock_lock_file_wait(file, fl);
4541 struct nfs4_unlockdata {
4542 struct nfs_locku_args arg;
4543 struct nfs_locku_res res;
4544 struct nfs4_lock_state *lsp;
4545 struct nfs_open_context *ctx;
4546 struct file_lock fl;
4547 const struct nfs_server *server;
4548 unsigned long timestamp;
4551 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
4552 struct nfs_open_context *ctx,
4553 struct nfs4_lock_state *lsp,
4554 struct nfs_seqid *seqid)
4556 struct nfs4_unlockdata *p;
4557 struct inode *inode = lsp->ls_state->inode;
4559 p = kzalloc(sizeof(*p), GFP_NOFS);
4562 p->arg.fh = NFS_FH(inode);
4564 p->arg.seqid = seqid;
4565 p->res.seqid = seqid;
4566 p->arg.stateid = &lsp->ls_stateid;
4568 atomic_inc(&lsp->ls_count);
4569 /* Ensure we don't close file until we're done freeing locks! */
4570 p->ctx = get_nfs_open_context(ctx);
4571 memcpy(&p->fl, fl, sizeof(p->fl));
4572 p->server = NFS_SERVER(inode);
4576 static void nfs4_locku_release_calldata(void *data)
4578 struct nfs4_unlockdata *calldata = data;
4579 nfs_free_seqid(calldata->arg.seqid);
4580 nfs4_put_lock_state(calldata->lsp);
4581 put_nfs_open_context(calldata->ctx);
4585 static void nfs4_locku_done(struct rpc_task *task, void *data)
4587 struct nfs4_unlockdata *calldata = data;
4589 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
4591 switch (task->tk_status) {
4593 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4594 &calldata->res.stateid);
4595 renew_lease(calldata->server, calldata->timestamp);
4597 case -NFS4ERR_BAD_STATEID:
4598 case -NFS4ERR_OLD_STATEID:
4599 case -NFS4ERR_STALE_STATEID:
4600 case -NFS4ERR_EXPIRED:
4603 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
4604 rpc_restart_call_prepare(task);
4606 nfs_release_seqid(calldata->arg.seqid);
4609 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4611 struct nfs4_unlockdata *calldata = data;
4613 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
4615 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
4616 /* Note: exit _without_ running nfs4_locku_done */
4619 calldata->timestamp = jiffies;
4620 if (nfs4_setup_sequence(calldata->server,
4621 &calldata->arg.seq_args,
4622 &calldata->res.seq_res,
4624 nfs_release_seqid(calldata->arg.seqid);
4627 task->tk_action = NULL;
4629 nfs4_sequence_done(task, &calldata->res.seq_res);
4632 static const struct rpc_call_ops nfs4_locku_ops = {
4633 .rpc_call_prepare = nfs4_locku_prepare,
4634 .rpc_call_done = nfs4_locku_done,
4635 .rpc_release = nfs4_locku_release_calldata,
4638 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4639 struct nfs_open_context *ctx,
4640 struct nfs4_lock_state *lsp,
4641 struct nfs_seqid *seqid)
4643 struct nfs4_unlockdata *data;
4644 struct rpc_message msg = {
4645 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
4646 .rpc_cred = ctx->cred,
4648 struct rpc_task_setup task_setup_data = {
4649 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4650 .rpc_message = &msg,
4651 .callback_ops = &nfs4_locku_ops,
4652 .workqueue = nfsiod_workqueue,
4653 .flags = RPC_TASK_ASYNC,
4656 /* Ensure this is an unlock - when canceling a lock, the
4657 * canceled lock is passed in, and it won't be an unlock.
4659 fl->fl_type = F_UNLCK;
4661 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4663 nfs_free_seqid(seqid);
4664 return ERR_PTR(-ENOMEM);
4667 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4668 msg.rpc_argp = &data->arg;
4669 msg.rpc_resp = &data->res;
4670 task_setup_data.callback_data = data;
4671 return rpc_run_task(&task_setup_data);
4674 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
4676 struct inode *inode = state->inode;
4677 struct nfs4_state_owner *sp = state->owner;
4678 struct nfs_inode *nfsi = NFS_I(inode);
4679 struct nfs_seqid *seqid;
4680 struct nfs4_lock_state *lsp;
4681 struct rpc_task *task;
4683 unsigned char fl_flags = request->fl_flags;
4685 status = nfs4_set_lock_state(state, request);
4686 /* Unlock _before_ we do the RPC call */
4687 request->fl_flags |= FL_EXISTS;
4688 /* Exclude nfs_delegation_claim_locks() */
4689 mutex_lock(&sp->so_delegreturn_mutex);
4690 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
4691 down_read(&nfsi->rwsem);
4692 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
4693 up_read(&nfsi->rwsem);
4694 mutex_unlock(&sp->so_delegreturn_mutex);
4697 up_read(&nfsi->rwsem);
4698 mutex_unlock(&sp->so_delegreturn_mutex);
4701 /* Is this a delegated lock? */
4702 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4704 lsp = request->fl_u.nfs4_fl.owner;
4705 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4709 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4710 status = PTR_ERR(task);
4713 status = nfs4_wait_for_completion_rpc_task(task);
4716 request->fl_flags = fl_flags;
4720 struct nfs4_lockdata {
4721 struct nfs_lock_args arg;
4722 struct nfs_lock_res res;
4723 struct nfs4_lock_state *lsp;
4724 struct nfs_open_context *ctx;
4725 struct file_lock fl;
4726 unsigned long timestamp;
4729 struct nfs_server *server;
4732 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4733 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4736 struct nfs4_lockdata *p;
4737 struct inode *inode = lsp->ls_state->inode;
4738 struct nfs_server *server = NFS_SERVER(inode);
4740 p = kzalloc(sizeof(*p), gfp_mask);
4744 p->arg.fh = NFS_FH(inode);
4746 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4747 if (p->arg.open_seqid == NULL)
4749 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4750 if (p->arg.lock_seqid == NULL)
4751 goto out_free_seqid;
4752 p->arg.lock_stateid = &lsp->ls_stateid;
4753 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4754 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4755 p->arg.lock_owner.s_dev = server->s_dev;
4756 p->res.lock_seqid = p->arg.lock_seqid;
4759 atomic_inc(&lsp->ls_count);
4760 p->ctx = get_nfs_open_context(ctx);
4761 memcpy(&p->fl, fl, sizeof(p->fl));
4764 nfs_free_seqid(p->arg.open_seqid);
4770 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4772 struct nfs4_lockdata *data = calldata;
4773 struct nfs4_state *state = data->lsp->ls_state;
4775 dprintk("%s: begin!\n", __func__);
4776 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4778 /* Do we need to do an open_to_lock_owner? */
4779 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4780 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) {
4781 goto out_release_lock_seqid;
4783 data->arg.open_stateid = &state->stateid;
4784 data->arg.new_lock_owner = 1;
4785 data->res.open_seqid = data->arg.open_seqid;
4787 data->arg.new_lock_owner = 0;
4788 if (!nfs4_valid_open_stateid(state)) {
4789 data->rpc_status = -EBADF;
4790 task->tk_action = NULL;
4791 goto out_release_open_seqid;
4793 data->timestamp = jiffies;
4794 if (nfs4_setup_sequence(data->server,
4795 &data->arg.seq_args,
4799 out_release_open_seqid:
4800 nfs_release_seqid(data->arg.open_seqid);
4801 out_release_lock_seqid:
4802 nfs_release_seqid(data->arg.lock_seqid);
4804 nfs4_sequence_done(task, &data->res.seq_res);
4805 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4808 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4810 struct nfs4_lockdata *data = calldata;
4812 dprintk("%s: begin!\n", __func__);
4814 if (!nfs4_sequence_done(task, &data->res.seq_res))
4817 data->rpc_status = task->tk_status;
4818 if (data->arg.new_lock_owner != 0) {
4819 if (data->rpc_status == 0)
4820 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4824 if (data->rpc_status == 0) {
4825 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4826 set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags);
4827 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4830 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4833 static void nfs4_lock_release(void *calldata)
4835 struct nfs4_lockdata *data = calldata;
4837 dprintk("%s: begin!\n", __func__);
4838 nfs_free_seqid(data->arg.open_seqid);
4839 if (data->cancelled != 0) {
4840 struct rpc_task *task;
4841 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4842 data->arg.lock_seqid);
4844 rpc_put_task_async(task);
4845 dprintk("%s: cancelling lock!\n", __func__);
4847 nfs_free_seqid(data->arg.lock_seqid);
4848 nfs4_put_lock_state(data->lsp);
4849 put_nfs_open_context(data->ctx);
4851 dprintk("%s: done!\n", __func__);
4854 static const struct rpc_call_ops nfs4_lock_ops = {
4855 .rpc_call_prepare = nfs4_lock_prepare,
4856 .rpc_call_done = nfs4_lock_done,
4857 .rpc_release = nfs4_lock_release,
4860 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4863 case -NFS4ERR_ADMIN_REVOKED:
4864 case -NFS4ERR_BAD_STATEID:
4865 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4866 if (new_lock_owner != 0 ||
4867 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
4868 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
4870 case -NFS4ERR_STALE_STATEID:
4871 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4872 case -NFS4ERR_EXPIRED:
4873 nfs4_schedule_lease_recovery(server->nfs_client);
4877 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4879 struct nfs4_lockdata *data;
4880 struct rpc_task *task;
4881 struct rpc_message msg = {
4882 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4883 .rpc_cred = state->owner->so_cred,
4885 struct rpc_task_setup task_setup_data = {
4886 .rpc_client = NFS_CLIENT(state->inode),
4887 .rpc_message = &msg,
4888 .callback_ops = &nfs4_lock_ops,
4889 .workqueue = nfsiod_workqueue,
4890 .flags = RPC_TASK_ASYNC,
4894 dprintk("%s: begin!\n", __func__);
4895 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4896 fl->fl_u.nfs4_fl.owner,
4897 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4901 data->arg.block = 1;
4902 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4903 msg.rpc_argp = &data->arg;
4904 msg.rpc_resp = &data->res;
4905 task_setup_data.callback_data = data;
4906 if (recovery_type > NFS_LOCK_NEW) {
4907 if (recovery_type == NFS_LOCK_RECLAIM)
4908 data->arg.reclaim = NFS_LOCK_RECLAIM;
4909 nfs4_set_sequence_privileged(&data->arg.seq_args);
4911 task = rpc_run_task(&task_setup_data);
4913 return PTR_ERR(task);
4914 ret = nfs4_wait_for_completion_rpc_task(task);
4916 ret = data->rpc_status;
4918 nfs4_handle_setlk_error(data->server, data->lsp,
4919 data->arg.new_lock_owner, ret);
4921 data->cancelled = 1;
4923 dprintk("%s: done, ret = %d!\n", __func__, ret);
4927 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4929 struct nfs_server *server = NFS_SERVER(state->inode);
4930 struct nfs4_exception exception = {
4931 .inode = state->inode,
4936 /* Cache the lock if possible... */
4937 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4939 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4940 if (err != -NFS4ERR_DELAY)
4942 nfs4_handle_exception(server, err, &exception);
4943 } while (exception.retry);
4947 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4949 struct nfs_server *server = NFS_SERVER(state->inode);
4950 struct nfs4_exception exception = {
4951 .inode = state->inode,
4955 err = nfs4_set_lock_state(state, request);
4959 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4961 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4965 case -NFS4ERR_GRACE:
4966 case -NFS4ERR_DELAY:
4967 nfs4_handle_exception(server, err, &exception);
4970 } while (exception.retry);
4975 #if defined(CONFIG_NFS_V4_1)
4977 * nfs41_check_expired_locks - possibly free a lock stateid
4979 * @state: NFSv4 state for an inode
4981 * Returns NFS_OK if recovery for this stateid is now finished.
4982 * Otherwise a negative NFS4ERR value is returned.
4984 static int nfs41_check_expired_locks(struct nfs4_state *state)
4986 int status, ret = -NFS4ERR_BAD_STATEID;
4987 struct nfs4_lock_state *lsp;
4988 struct nfs_server *server = NFS_SERVER(state->inode);
4990 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4991 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
4992 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4993 if (status != NFS_OK) {
4994 /* Free the stateid unless the server
4995 * informs us the stateid is unrecognized. */
4996 if (status != -NFS4ERR_BAD_STATEID)
4997 nfs41_free_stateid(server,
4999 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
5008 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
5010 int status = NFS_OK;
5012 if (test_bit(LK_STATE_IN_USE, &state->flags))
5013 status = nfs41_check_expired_locks(state);
5014 if (status != NFS_OK)
5015 status = nfs4_lock_expired(state, request);
5020 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5022 struct nfs4_state_owner *sp = state->owner;
5023 struct nfs_inode *nfsi = NFS_I(state->inode);
5024 unsigned char fl_flags = request->fl_flags;
5026 int status = -ENOLCK;
5028 if ((fl_flags & FL_POSIX) &&
5029 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
5031 /* Is this a delegated open? */
5032 status = nfs4_set_lock_state(state, request);
5035 request->fl_flags |= FL_ACCESS;
5036 status = do_vfs_lock(request->fl_file, request);
5039 down_read(&nfsi->rwsem);
5040 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
5041 /* Yes: cache locks! */
5042 /* ...but avoid races with delegation recall... */
5043 request->fl_flags = fl_flags & ~FL_SLEEP;
5044 status = do_vfs_lock(request->fl_file, request);
5047 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
5048 up_read(&nfsi->rwsem);
5049 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
5052 down_read(&nfsi->rwsem);
5053 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
5054 status = -NFS4ERR_DELAY;
5057 /* Note: we always want to sleep here! */
5058 request->fl_flags = fl_flags | FL_SLEEP;
5059 if (do_vfs_lock(request->fl_file, request) < 0)
5060 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
5061 "manager!\n", __func__);
5063 up_read(&nfsi->rwsem);
5065 request->fl_flags = fl_flags;
5069 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5071 struct nfs4_exception exception = {
5073 .inode = state->inode,
5078 err = _nfs4_proc_setlk(state, cmd, request);
5079 if (err == -NFS4ERR_DENIED)
5081 err = nfs4_handle_exception(NFS_SERVER(state->inode),
5083 } while (exception.retry);
5088 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
5090 struct nfs_open_context *ctx;
5091 struct nfs4_state *state;
5092 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
5095 /* verify open state */
5096 ctx = nfs_file_open_context(filp);
5099 if (request->fl_start < 0 || request->fl_end < 0)
5102 if (IS_GETLK(cmd)) {
5104 return nfs4_proc_getlk(state, F_GETLK, request);
5108 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
5111 if (request->fl_type == F_UNLCK) {
5113 return nfs4_proc_unlck(state, cmd, request);
5120 * Don't rely on the VFS having checked the file open mode,
5121 * since it won't do this for flock() locks.
5123 switch (request->fl_type) {
5125 if (!(filp->f_mode & FMODE_READ))
5129 if (!(filp->f_mode & FMODE_WRITE))
5134 status = nfs4_proc_setlk(state, cmd, request);
5135 if ((status != -EAGAIN) || IS_SETLK(cmd))
5137 timeout = nfs4_set_lock_task_retry(timeout);
5138 status = -ERESTARTSYS;
5141 } while(status < 0);
5145 int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid)
5147 struct nfs_server *server = NFS_SERVER(state->inode);
5150 err = nfs4_set_lock_state(state, fl);
5153 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
5154 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
5157 struct nfs_release_lockowner_data {
5158 struct nfs4_lock_state *lsp;
5159 struct nfs_server *server;
5160 struct nfs_release_lockowner_args args;
5163 static void nfs4_release_lockowner_release(void *calldata)
5165 struct nfs_release_lockowner_data *data = calldata;
5166 nfs4_free_lock_state(data->server, data->lsp);
5170 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5171 .rpc_release = nfs4_release_lockowner_release,
5174 int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
5176 struct nfs_server *server = lsp->ls_state->owner->so_server;
5177 struct nfs_release_lockowner_data *data;
5178 struct rpc_message msg = {
5179 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5182 if (server->nfs_client->cl_mvops->minor_version != 0)
5184 data = kmalloc(sizeof(*data), GFP_NOFS);
5188 data->server = server;
5189 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5190 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5191 data->args.lock_owner.s_dev = server->s_dev;
5192 msg.rpc_argp = &data->args;
5193 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5197 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5199 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5200 const void *buf, size_t buflen,
5201 int flags, int type)
5203 if (strcmp(key, "") != 0)
5206 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5209 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5210 void *buf, size_t buflen, int type)
5212 if (strcmp(key, "") != 0)
5215 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5218 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5219 size_t list_len, const char *name,
5220 size_t name_len, int type)
5222 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5224 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5227 if (list && len <= list_len)
5228 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5233 * nfs_fhget will use either the mounted_on_fileid or the fileid
5235 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5237 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5238 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5239 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5240 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5243 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5244 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5245 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5249 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5250 const struct qstr *name,
5251 struct nfs4_fs_locations *fs_locations,
5254 struct nfs_server *server = NFS_SERVER(dir);
5256 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5258 struct nfs4_fs_locations_arg args = {
5259 .dir_fh = NFS_FH(dir),
5264 struct nfs4_fs_locations_res res = {
5265 .fs_locations = fs_locations,
5267 struct rpc_message msg = {
5268 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5274 dprintk("%s: start\n", __func__);
5276 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5277 * is not supported */
5278 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5279 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5281 bitmask[0] |= FATTR4_WORD0_FILEID;
5283 nfs_fattr_init(&fs_locations->fattr);
5284 fs_locations->server = server;
5285 fs_locations->nlocations = 0;
5286 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5287 dprintk("%s: returned status = %d\n", __func__, status);
5291 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5292 const struct qstr *name,
5293 struct nfs4_fs_locations *fs_locations,
5296 struct nfs4_exception exception = { };
5299 err = nfs4_handle_exception(NFS_SERVER(dir),
5300 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5302 } while (exception.retry);
5306 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
5309 struct nfs4_secinfo_arg args = {
5310 .dir_fh = NFS_FH(dir),
5313 struct nfs4_secinfo_res res = {
5316 struct rpc_message msg = {
5317 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
5322 dprintk("NFS call secinfo %s\n", name->name);
5323 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
5324 dprintk("NFS reply secinfo: %d\n", status);
5328 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
5329 struct nfs4_secinfo_flavors *flavors)
5331 struct nfs4_exception exception = { };
5334 err = nfs4_handle_exception(NFS_SERVER(dir),
5335 _nfs4_proc_secinfo(dir, name, flavors),
5337 } while (exception.retry);
5341 #ifdef CONFIG_NFS_V4_1
5343 * Check the exchange flags returned by the server for invalid flags, having
5344 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5347 static int nfs4_check_cl_exchange_flags(u32 flags)
5349 if (flags & ~EXCHGID4_FLAG_MASK_R)
5351 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
5352 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
5354 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
5358 return -NFS4ERR_INVAL;
5362 nfs41_same_server_scope(struct nfs41_server_scope *a,
5363 struct nfs41_server_scope *b)
5365 if (a->server_scope_sz == b->server_scope_sz &&
5366 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5373 * nfs4_proc_bind_conn_to_session()
5375 * The 4.1 client currently uses the same TCP connection for the
5376 * fore and backchannel.
5378 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
5381 struct nfs41_bind_conn_to_session_res res;
5382 struct rpc_message msg = {
5384 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
5390 dprintk("--> %s\n", __func__);
5392 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5393 if (unlikely(res.session == NULL)) {
5398 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5400 if (memcmp(res.session->sess_id.data,
5401 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
5402 dprintk("NFS: %s: Session ID mismatch\n", __func__);
5406 if (res.dir != NFS4_CDFS4_BOTH) {
5407 dprintk("NFS: %s: Unexpected direction from server\n",
5412 if (res.use_conn_in_rdma_mode) {
5413 dprintk("NFS: %s: Server returned RDMA mode = true\n",
5422 dprintk("<-- %s status= %d\n", __func__, status);
5427 * nfs4_proc_exchange_id()
5429 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5431 * Since the clientid has expired, all compounds using sessions
5432 * associated with the stale clientid will be returning
5433 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
5434 * be in some phase of session reset.
5436 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
5438 nfs4_verifier verifier;
5439 struct nfs41_exchange_id_args args = {
5440 .verifier = &verifier,
5442 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
5444 struct nfs41_exchange_id_res res = {
5448 struct rpc_message msg = {
5449 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
5455 nfs4_init_boot_verifier(clp, &verifier);
5456 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
5458 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
5459 clp->cl_rpcclient->cl_auth->au_ops->au_name,
5460 args.id_len, args.id);
5462 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
5464 if (unlikely(res.server_owner == NULL)) {
5469 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
5471 if (unlikely(res.server_scope == NULL)) {
5473 goto out_server_owner;
5476 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
5477 if (unlikely(res.impl_id == NULL)) {
5479 goto out_server_scope;
5482 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5484 status = nfs4_check_cl_exchange_flags(res.flags);
5487 clp->cl_clientid = res.clientid;
5488 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
5489 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
5490 clp->cl_seqid = res.seqid;
5492 kfree(clp->cl_serverowner);
5493 clp->cl_serverowner = res.server_owner;
5494 res.server_owner = NULL;
5496 /* use the most recent implementation id */
5497 kfree(clp->cl_implid);
5498 clp->cl_implid = res.impl_id;
5500 if (clp->cl_serverscope != NULL &&
5501 !nfs41_same_server_scope(clp->cl_serverscope,
5502 res.server_scope)) {
5503 dprintk("%s: server_scope mismatch detected\n",
5505 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
5506 kfree(clp->cl_serverscope);
5507 clp->cl_serverscope = NULL;
5510 if (clp->cl_serverscope == NULL) {
5511 clp->cl_serverscope = res.server_scope;
5518 kfree(res.server_owner);
5520 kfree(res.server_scope);
5522 if (clp->cl_implid != NULL)
5523 dprintk("NFS reply exchange_id: Server Implementation ID: "
5524 "domain: %s, name: %s, date: %llu,%u\n",
5525 clp->cl_implid->domain, clp->cl_implid->name,
5526 clp->cl_implid->date.seconds,
5527 clp->cl_implid->date.nseconds);
5528 dprintk("NFS reply exchange_id: %d\n", status);
5532 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
5533 struct rpc_cred *cred)
5535 struct rpc_message msg = {
5536 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
5542 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5544 dprintk("NFS: Got error %d from the server %s on "
5545 "DESTROY_CLIENTID.", status, clp->cl_hostname);
5549 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
5550 struct rpc_cred *cred)
5555 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
5556 ret = _nfs4_proc_destroy_clientid(clp, cred);
5558 case -NFS4ERR_DELAY:
5559 case -NFS4ERR_CLIENTID_BUSY:
5569 int nfs4_destroy_clientid(struct nfs_client *clp)
5571 struct rpc_cred *cred;
5574 if (clp->cl_mvops->minor_version < 1)
5576 if (clp->cl_exchange_flags == 0)
5578 if (clp->cl_preserve_clid)
5580 cred = nfs4_get_exchange_id_cred(clp);
5581 ret = nfs4_proc_destroy_clientid(clp, cred);
5586 case -NFS4ERR_STALE_CLIENTID:
5587 clp->cl_exchange_flags = 0;
5593 struct nfs4_get_lease_time_data {
5594 struct nfs4_get_lease_time_args *args;
5595 struct nfs4_get_lease_time_res *res;
5596 struct nfs_client *clp;
5599 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
5602 struct nfs4_get_lease_time_data *data =
5603 (struct nfs4_get_lease_time_data *)calldata;
5605 dprintk("--> %s\n", __func__);
5606 /* just setup sequence, do not trigger session recovery
5607 since we're invoked within one */
5608 nfs41_setup_sequence(data->clp->cl_session,
5609 &data->args->la_seq_args,
5610 &data->res->lr_seq_res,
5612 dprintk("<-- %s\n", __func__);
5616 * Called from nfs4_state_manager thread for session setup, so don't recover
5617 * from sequence operation or clientid errors.
5619 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
5621 struct nfs4_get_lease_time_data *data =
5622 (struct nfs4_get_lease_time_data *)calldata;
5624 dprintk("--> %s\n", __func__);
5625 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
5627 switch (task->tk_status) {
5628 case -NFS4ERR_DELAY:
5629 case -NFS4ERR_GRACE:
5630 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
5631 rpc_delay(task, NFS4_POLL_RETRY_MIN);
5632 task->tk_status = 0;
5634 case -NFS4ERR_RETRY_UNCACHED_REP:
5635 rpc_restart_call_prepare(task);
5638 dprintk("<-- %s\n", __func__);
5641 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
5642 .rpc_call_prepare = nfs4_get_lease_time_prepare,
5643 .rpc_call_done = nfs4_get_lease_time_done,
5646 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
5648 struct rpc_task *task;
5649 struct nfs4_get_lease_time_args args;
5650 struct nfs4_get_lease_time_res res = {
5651 .lr_fsinfo = fsinfo,
5653 struct nfs4_get_lease_time_data data = {
5658 struct rpc_message msg = {
5659 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
5663 struct rpc_task_setup task_setup = {
5664 .rpc_client = clp->cl_rpcclient,
5665 .rpc_message = &msg,
5666 .callback_ops = &nfs4_get_lease_time_ops,
5667 .callback_data = &data,
5668 .flags = RPC_TASK_TIMEOUT,
5672 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
5673 nfs4_set_sequence_privileged(&args.la_seq_args);
5674 dprintk("--> %s\n", __func__);
5675 task = rpc_run_task(&task_setup);
5678 status = PTR_ERR(task);
5680 status = task->tk_status;
5683 dprintk("<-- %s return %d\n", __func__, status);
5689 * Initialize the values to be used by the client in CREATE_SESSION
5690 * If nfs4_init_session set the fore channel request and response sizes,
5693 * Set the back channel max_resp_sz_cached to zero to force the client to
5694 * always set csa_cachethis to FALSE because the current implementation
5695 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5697 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5699 struct nfs4_session *session = args->client->cl_session;
5700 unsigned int mxrqst_sz = session->fc_target_max_rqst_sz,
5701 mxresp_sz = session->fc_target_max_resp_sz;
5704 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
5706 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
5707 /* Fore channel attributes */
5708 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5709 args->fc_attrs.max_resp_sz = mxresp_sz;
5710 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5711 args->fc_attrs.max_reqs = max_session_slots;
5713 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5714 "max_ops=%u max_reqs=%u\n",
5716 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5717 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5719 /* Back channel attributes */
5720 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
5721 args->bc_attrs.max_resp_sz = PAGE_SIZE;
5722 args->bc_attrs.max_resp_sz_cached = 0;
5723 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
5724 args->bc_attrs.max_reqs = 1;
5726 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5727 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5729 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5730 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5731 args->bc_attrs.max_reqs);
5734 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5736 struct nfs4_channel_attrs *sent = &args->fc_attrs;
5737 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
5739 if (rcvd->max_resp_sz > sent->max_resp_sz)
5742 * Our requested max_ops is the minimum we need; we're not
5743 * prepared to break up compounds into smaller pieces than that.
5744 * So, no point even trying to continue if the server won't
5747 if (rcvd->max_ops < sent->max_ops)
5749 if (rcvd->max_reqs == 0)
5751 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5752 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5756 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5758 struct nfs4_channel_attrs *sent = &args->bc_attrs;
5759 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
5761 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
5763 if (rcvd->max_resp_sz < sent->max_resp_sz)
5765 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5767 /* These would render the backchannel useless: */
5768 if (rcvd->max_ops != sent->max_ops)
5770 if (rcvd->max_reqs != sent->max_reqs)
5775 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
5776 struct nfs4_session *session)
5780 ret = nfs4_verify_fore_channel_attrs(args, session);
5783 return nfs4_verify_back_channel_attrs(args, session);
5786 static int _nfs4_proc_create_session(struct nfs_client *clp,
5787 struct rpc_cred *cred)
5789 struct nfs4_session *session = clp->cl_session;
5790 struct nfs41_create_session_args args = {
5792 .cb_program = NFS4_CALLBACK,
5794 struct nfs41_create_session_res res = {
5797 struct rpc_message msg = {
5798 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
5805 nfs4_init_channel_attrs(&args);
5806 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
5808 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5811 /* Verify the session's negotiated channel_attrs values */
5812 status = nfs4_verify_channel_attrs(&args, session);
5813 /* Increment the clientid slot sequence id */
5821 * Issues a CREATE_SESSION operation to the server.
5822 * It is the responsibility of the caller to verify the session is
5823 * expired before calling this routine.
5825 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
5829 struct nfs4_session *session = clp->cl_session;
5831 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
5833 status = _nfs4_proc_create_session(clp, cred);
5837 /* Init or reset the session slot tables */
5838 status = nfs4_setup_session_slot_tables(session);
5839 dprintk("slot table setup returned %d\n", status);
5843 ptr = (unsigned *)&session->sess_id.data[0];
5844 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5845 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5847 dprintk("<-- %s\n", __func__);
5852 * Issue the over-the-wire RPC DESTROY_SESSION.
5853 * The caller must serialize access to this routine.
5855 int nfs4_proc_destroy_session(struct nfs4_session *session,
5856 struct rpc_cred *cred)
5858 struct rpc_message msg = {
5859 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
5860 .rpc_argp = session,
5865 dprintk("--> nfs4_proc_destroy_session\n");
5867 /* session is still being setup */
5868 if (session->clp->cl_cons_state != NFS_CS_READY)
5871 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5874 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
5875 "Session has been destroyed regardless...\n", status);
5877 dprintk("<-- nfs4_proc_destroy_session\n");
5882 * Renew the cl_session lease.
5884 struct nfs4_sequence_data {
5885 struct nfs_client *clp;
5886 struct nfs4_sequence_args args;
5887 struct nfs4_sequence_res res;
5890 static void nfs41_sequence_release(void *data)
5892 struct nfs4_sequence_data *calldata = data;
5893 struct nfs_client *clp = calldata->clp;
5895 if (atomic_read(&clp->cl_count) > 1)
5896 nfs4_schedule_state_renewal(clp);
5897 nfs_put_client(clp);
5901 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5903 switch(task->tk_status) {
5904 case -NFS4ERR_DELAY:
5905 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5908 nfs4_schedule_lease_recovery(clp);
5913 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5915 struct nfs4_sequence_data *calldata = data;
5916 struct nfs_client *clp = calldata->clp;
5918 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5921 if (task->tk_status < 0) {
5922 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5923 if (atomic_read(&clp->cl_count) == 1)
5926 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5927 rpc_restart_call_prepare(task);
5931 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5933 dprintk("<-- %s\n", __func__);
5936 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5938 struct nfs4_sequence_data *calldata = data;
5939 struct nfs_client *clp = calldata->clp;
5940 struct nfs4_sequence_args *args;
5941 struct nfs4_sequence_res *res;
5943 args = task->tk_msg.rpc_argp;
5944 res = task->tk_msg.rpc_resp;
5946 nfs41_setup_sequence(clp->cl_session, args, res, task);
5949 static const struct rpc_call_ops nfs41_sequence_ops = {
5950 .rpc_call_done = nfs41_sequence_call_done,
5951 .rpc_call_prepare = nfs41_sequence_prepare,
5952 .rpc_release = nfs41_sequence_release,
5955 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
5956 struct rpc_cred *cred,
5959 struct nfs4_sequence_data *calldata;
5960 struct rpc_message msg = {
5961 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5964 struct rpc_task_setup task_setup_data = {
5965 .rpc_client = clp->cl_rpcclient,
5966 .rpc_message = &msg,
5967 .callback_ops = &nfs41_sequence_ops,
5968 .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT,
5971 if (!atomic_inc_not_zero(&clp->cl_count))
5972 return ERR_PTR(-EIO);
5973 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5974 if (calldata == NULL) {
5975 nfs_put_client(clp);
5976 return ERR_PTR(-ENOMEM);
5978 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
5980 nfs4_set_sequence_privileged(&calldata->args);
5981 msg.rpc_argp = &calldata->args;
5982 msg.rpc_resp = &calldata->res;
5983 calldata->clp = clp;
5984 task_setup_data.callback_data = calldata;
5986 return rpc_run_task(&task_setup_data);
5989 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
5991 struct rpc_task *task;
5994 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
5996 task = _nfs41_proc_sequence(clp, cred, false);
5998 ret = PTR_ERR(task);
6000 rpc_put_task_async(task);
6001 dprintk("<-- %s status=%d\n", __func__, ret);
6005 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
6007 struct rpc_task *task;
6010 task = _nfs41_proc_sequence(clp, cred, true);
6012 ret = PTR_ERR(task);
6015 ret = rpc_wait_for_completion_task(task);
6017 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
6019 if (task->tk_status == 0)
6020 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
6021 ret = task->tk_status;
6025 dprintk("<-- %s status=%d\n", __func__, ret);
6029 struct nfs4_reclaim_complete_data {
6030 struct nfs_client *clp;
6031 struct nfs41_reclaim_complete_args arg;
6032 struct nfs41_reclaim_complete_res res;
6035 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
6037 struct nfs4_reclaim_complete_data *calldata = data;
6039 nfs41_setup_sequence(calldata->clp->cl_session,
6040 &calldata->arg.seq_args,
6041 &calldata->res.seq_res,
6045 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6047 switch(task->tk_status) {
6049 case -NFS4ERR_COMPLETE_ALREADY:
6050 case -NFS4ERR_WRONG_CRED: /* What to do here? */
6052 case -NFS4ERR_DELAY:
6053 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6055 case -NFS4ERR_RETRY_UNCACHED_REP:
6058 nfs4_schedule_lease_recovery(clp);
6063 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
6065 struct nfs4_reclaim_complete_data *calldata = data;
6066 struct nfs_client *clp = calldata->clp;
6067 struct nfs4_sequence_res *res = &calldata->res.seq_res;
6069 dprintk("--> %s\n", __func__);
6070 if (!nfs41_sequence_done(task, res))
6073 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
6074 rpc_restart_call_prepare(task);
6077 dprintk("<-- %s\n", __func__);
6080 static void nfs4_free_reclaim_complete_data(void *data)
6082 struct nfs4_reclaim_complete_data *calldata = data;
6087 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6088 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
6089 .rpc_call_done = nfs4_reclaim_complete_done,
6090 .rpc_release = nfs4_free_reclaim_complete_data,
6094 * Issue a global reclaim complete.
6096 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
6098 struct nfs4_reclaim_complete_data *calldata;
6099 struct rpc_task *task;
6100 struct rpc_message msg = {
6101 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
6103 struct rpc_task_setup task_setup_data = {
6104 .rpc_client = clp->cl_rpcclient,
6105 .rpc_message = &msg,
6106 .callback_ops = &nfs4_reclaim_complete_call_ops,
6107 .flags = RPC_TASK_ASYNC,
6109 int status = -ENOMEM;
6111 dprintk("--> %s\n", __func__);
6112 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6113 if (calldata == NULL)
6115 calldata->clp = clp;
6116 calldata->arg.one_fs = 0;
6118 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6119 nfs4_set_sequence_privileged(&calldata->arg.seq_args);
6120 msg.rpc_argp = &calldata->arg;
6121 msg.rpc_resp = &calldata->res;
6122 task_setup_data.callback_data = calldata;
6123 task = rpc_run_task(&task_setup_data);
6125 status = PTR_ERR(task);
6128 status = nfs4_wait_for_completion_rpc_task(task);
6130 status = task->tk_status;
6134 dprintk("<-- %s status=%d\n", __func__, status);
6139 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
6141 struct nfs4_layoutget *lgp = calldata;
6142 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6143 struct nfs4_session *session = nfs4_get_session(server);
6145 dprintk("--> %s\n", __func__);
6146 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6147 * right now covering the LAYOUTGET we are about to send.
6148 * However, that is not so catastrophic, and there seems
6149 * to be no way to prevent it completely.
6151 if (nfs41_setup_sequence(session, &lgp->args.seq_args,
6152 &lgp->res.seq_res, task))
6154 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
6155 NFS_I(lgp->args.inode)->layout,
6156 lgp->args.ctx->state)) {
6157 rpc_exit(task, NFS4_OK);
6161 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
6163 struct nfs4_layoutget *lgp = calldata;
6164 struct inode *inode = lgp->args.inode;
6165 struct nfs_server *server = NFS_SERVER(inode);
6166 struct pnfs_layout_hdr *lo;
6167 struct nfs4_state *state = NULL;
6168 unsigned long timeo, giveup;
6170 dprintk("--> %s\n", __func__);
6172 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
6175 switch (task->tk_status) {
6178 case -NFS4ERR_LAYOUTTRYLATER:
6179 case -NFS4ERR_RECALLCONFLICT:
6180 timeo = rpc_get_timeout(task->tk_client);
6181 giveup = lgp->args.timestamp + timeo;
6182 if (time_after(giveup, jiffies))
6183 task->tk_status = -NFS4ERR_DELAY;
6185 case -NFS4ERR_EXPIRED:
6186 case -NFS4ERR_BAD_STATEID:
6187 spin_lock(&inode->i_lock);
6188 lo = NFS_I(inode)->layout;
6189 if (!lo || list_empty(&lo->plh_segs)) {
6190 spin_unlock(&inode->i_lock);
6191 /* If the open stateid was bad, then recover it. */
6192 state = lgp->args.ctx->state;
6196 pnfs_mark_matching_lsegs_invalid(lo, &head, NULL);
6197 spin_unlock(&inode->i_lock);
6198 /* Mark the bad layout state as invalid, then
6199 * retry using the open stateid. */
6200 pnfs_free_lseg_list(&head);
6203 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
6204 rpc_restart_call_prepare(task);
6206 dprintk("<-- %s\n", __func__);
6209 static size_t max_response_pages(struct nfs_server *server)
6211 u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
6212 return nfs_page_array_len(0, max_resp_sz);
6215 static void nfs4_free_pages(struct page **pages, size_t size)
6222 for (i = 0; i < size; i++) {
6225 __free_page(pages[i]);
6230 static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
6232 struct page **pages;
6235 pages = kcalloc(size, sizeof(struct page *), gfp_flags);
6237 dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
6241 for (i = 0; i < size; i++) {
6242 pages[i] = alloc_page(gfp_flags);
6244 dprintk("%s: failed to allocate page\n", __func__);
6245 nfs4_free_pages(pages, size);
6253 static void nfs4_layoutget_release(void *calldata)
6255 struct nfs4_layoutget *lgp = calldata;
6256 struct inode *inode = lgp->args.inode;
6257 struct nfs_server *server = NFS_SERVER(inode);
6258 size_t max_pages = max_response_pages(server);
6260 dprintk("--> %s\n", __func__);
6261 nfs4_free_pages(lgp->args.layout.pages, max_pages);
6262 pnfs_put_layout_hdr(NFS_I(inode)->layout);
6263 put_nfs_open_context(lgp->args.ctx);
6265 dprintk("<-- %s\n", __func__);
6268 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6269 .rpc_call_prepare = nfs4_layoutget_prepare,
6270 .rpc_call_done = nfs4_layoutget_done,
6271 .rpc_release = nfs4_layoutget_release,
6274 struct pnfs_layout_segment *
6275 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)
6277 struct inode *inode = lgp->args.inode;
6278 struct nfs_server *server = NFS_SERVER(inode);
6279 size_t max_pages = max_response_pages(server);
6280 struct rpc_task *task;
6281 struct rpc_message msg = {
6282 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
6283 .rpc_argp = &lgp->args,
6284 .rpc_resp = &lgp->res,
6286 struct rpc_task_setup task_setup_data = {
6287 .rpc_client = server->client,
6288 .rpc_message = &msg,
6289 .callback_ops = &nfs4_layoutget_call_ops,
6290 .callback_data = lgp,
6291 .flags = RPC_TASK_ASYNC,
6293 struct pnfs_layout_segment *lseg = NULL;
6296 dprintk("--> %s\n", __func__);
6298 lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
6299 if (!lgp->args.layout.pages) {
6300 nfs4_layoutget_release(lgp);
6301 return ERR_PTR(-ENOMEM);
6303 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
6304 lgp->args.timestamp = jiffies;
6306 lgp->res.layoutp = &lgp->args.layout;
6307 lgp->res.seq_res.sr_slot = NULL;
6308 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
6310 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6311 pnfs_get_layout_hdr(NFS_I(inode)->layout);
6313 task = rpc_run_task(&task_setup_data);
6315 return ERR_CAST(task);
6316 status = nfs4_wait_for_completion_rpc_task(task);
6318 status = task->tk_status;
6319 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6320 if (status == 0 && lgp->res.layoutp->len)
6321 lseg = pnfs_layout_process(lgp);
6323 dprintk("<-- %s status=%d\n", __func__, status);
6325 return ERR_PTR(status);
6330 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
6332 struct nfs4_layoutreturn *lrp = calldata;
6334 dprintk("--> %s\n", __func__);
6335 nfs41_setup_sequence(lrp->clp->cl_session,
6336 &lrp->args.seq_args,
6341 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
6343 struct nfs4_layoutreturn *lrp = calldata;
6344 struct nfs_server *server;
6346 dprintk("--> %s\n", __func__);
6348 if (!nfs41_sequence_done(task, &lrp->res.seq_res))
6351 server = NFS_SERVER(lrp->args.inode);
6352 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6353 rpc_restart_call_prepare(task);
6356 dprintk("<-- %s\n", __func__);
6359 static void nfs4_layoutreturn_release(void *calldata)
6361 struct nfs4_layoutreturn *lrp = calldata;
6362 struct pnfs_layout_hdr *lo = lrp->args.layout;
6364 dprintk("--> %s\n", __func__);
6365 spin_lock(&lo->plh_inode->i_lock);
6366 if (lrp->res.lrs_present)
6367 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
6368 lo->plh_block_lgets--;
6369 spin_unlock(&lo->plh_inode->i_lock);
6370 pnfs_put_layout_hdr(lrp->args.layout);
6372 dprintk("<-- %s\n", __func__);
6375 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6376 .rpc_call_prepare = nfs4_layoutreturn_prepare,
6377 .rpc_call_done = nfs4_layoutreturn_done,
6378 .rpc_release = nfs4_layoutreturn_release,
6381 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
6383 struct rpc_task *task;
6384 struct rpc_message msg = {
6385 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
6386 .rpc_argp = &lrp->args,
6387 .rpc_resp = &lrp->res,
6389 struct rpc_task_setup task_setup_data = {
6390 .rpc_client = lrp->clp->cl_rpcclient,
6391 .rpc_message = &msg,
6392 .callback_ops = &nfs4_layoutreturn_call_ops,
6393 .callback_data = lrp,
6397 dprintk("--> %s\n", __func__);
6398 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
6399 task = rpc_run_task(&task_setup_data);
6401 return PTR_ERR(task);
6402 status = task->tk_status;
6403 dprintk("<-- %s status=%d\n", __func__, status);
6409 * Retrieve the list of Data Server devices from the MDS.
6411 static int _nfs4_getdevicelist(struct nfs_server *server,
6412 const struct nfs_fh *fh,
6413 struct pnfs_devicelist *devlist)
6415 struct nfs4_getdevicelist_args args = {
6417 .layoutclass = server->pnfs_curr_ld->id,
6419 struct nfs4_getdevicelist_res res = {
6422 struct rpc_message msg = {
6423 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
6429 dprintk("--> %s\n", __func__);
6430 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
6432 dprintk("<-- %s status=%d\n", __func__, status);
6436 int nfs4_proc_getdevicelist(struct nfs_server *server,
6437 const struct nfs_fh *fh,
6438 struct pnfs_devicelist *devlist)
6440 struct nfs4_exception exception = { };
6444 err = nfs4_handle_exception(server,
6445 _nfs4_getdevicelist(server, fh, devlist),
6447 } while (exception.retry);
6449 dprintk("%s: err=%d, num_devs=%u\n", __func__,
6450 err, devlist->num_devs);
6454 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
6457 _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6459 struct nfs4_getdeviceinfo_args args = {
6462 struct nfs4_getdeviceinfo_res res = {
6465 struct rpc_message msg = {
6466 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
6472 dprintk("--> %s\n", __func__);
6473 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6474 dprintk("<-- %s status=%d\n", __func__, status);
6479 int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6481 struct nfs4_exception exception = { };
6485 err = nfs4_handle_exception(server,
6486 _nfs4_proc_getdeviceinfo(server, pdev),
6488 } while (exception.retry);
6491 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
6493 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
6495 struct nfs4_layoutcommit_data *data = calldata;
6496 struct nfs_server *server = NFS_SERVER(data->args.inode);
6497 struct nfs4_session *session = nfs4_get_session(server);
6499 nfs41_setup_sequence(session,
6500 &data->args.seq_args,
6506 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
6508 struct nfs4_layoutcommit_data *data = calldata;
6509 struct nfs_server *server = NFS_SERVER(data->args.inode);
6511 if (!nfs41_sequence_done(task, &data->res.seq_res))
6514 switch (task->tk_status) { /* Just ignore these failures */
6515 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
6516 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
6517 case -NFS4ERR_BADLAYOUT: /* no layout */
6518 case -NFS4ERR_GRACE: /* loca_recalim always false */
6519 task->tk_status = 0;
6522 nfs_post_op_update_inode_force_wcc(data->args.inode,
6526 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6527 rpc_restart_call_prepare(task);
6533 static void nfs4_layoutcommit_release(void *calldata)
6535 struct nfs4_layoutcommit_data *data = calldata;
6537 pnfs_cleanup_layoutcommit(data);
6538 put_rpccred(data->cred);
6542 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
6543 .rpc_call_prepare = nfs4_layoutcommit_prepare,
6544 .rpc_call_done = nfs4_layoutcommit_done,
6545 .rpc_release = nfs4_layoutcommit_release,
6549 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
6551 struct rpc_message msg = {
6552 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
6553 .rpc_argp = &data->args,
6554 .rpc_resp = &data->res,
6555 .rpc_cred = data->cred,
6557 struct rpc_task_setup task_setup_data = {
6558 .task = &data->task,
6559 .rpc_client = NFS_CLIENT(data->args.inode),
6560 .rpc_message = &msg,
6561 .callback_ops = &nfs4_layoutcommit_ops,
6562 .callback_data = data,
6563 .flags = RPC_TASK_ASYNC,
6565 struct rpc_task *task;
6568 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
6569 "lbw: %llu inode %lu\n",
6570 data->task.tk_pid, sync,
6571 data->args.lastbytewritten,
6572 data->args.inode->i_ino);
6574 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6575 task = rpc_run_task(&task_setup_data);
6577 return PTR_ERR(task);
6580 status = nfs4_wait_for_completion_rpc_task(task);
6583 status = task->tk_status;
6585 dprintk("%s: status %d\n", __func__, status);
6591 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6592 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6594 struct nfs41_secinfo_no_name_args args = {
6595 .style = SECINFO_STYLE_CURRENT_FH,
6597 struct nfs4_secinfo_res res = {
6600 struct rpc_message msg = {
6601 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
6605 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6609 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6610 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6612 struct nfs4_exception exception = { };
6615 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6618 case -NFS4ERR_WRONGSEC:
6619 case -NFS4ERR_NOTSUPP:
6622 err = nfs4_handle_exception(server, err, &exception);
6624 } while (exception.retry);
6630 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
6631 struct nfs_fsinfo *info)
6635 rpc_authflavor_t flavor;
6636 struct nfs4_secinfo_flavors *flavors;
6638 page = alloc_page(GFP_KERNEL);
6644 flavors = page_address(page);
6645 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6648 * Fall back on "guess and check" method if
6649 * the server doesn't support SECINFO_NO_NAME
6651 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
6652 err = nfs4_find_root_sec(server, fhandle, info);
6658 flavor = nfs_find_best_sec(flavors);
6660 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
6670 static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6673 struct nfs41_test_stateid_args args = {
6676 struct nfs41_test_stateid_res res;
6677 struct rpc_message msg = {
6678 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
6683 dprintk("NFS call test_stateid %p\n", stateid);
6684 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6685 nfs4_set_sequence_privileged(&args.seq_args);
6686 status = nfs4_call_sync_sequence(server->client, server, &msg,
6687 &args.seq_args, &res.seq_res);
6688 if (status != NFS_OK) {
6689 dprintk("NFS reply test_stateid: failed, %d\n", status);
6692 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
6697 * nfs41_test_stateid - perform a TEST_STATEID operation
6699 * @server: server / transport on which to perform the operation
6700 * @stateid: state ID to test
6702 * Returns NFS_OK if the server recognizes that "stateid" is valid.
6703 * Otherwise a negative NFS4ERR value is returned if the operation
6704 * failed or the state ID is not currently valid.
6706 static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6708 struct nfs4_exception exception = { };
6711 err = _nfs41_test_stateid(server, stateid);
6712 if (err != -NFS4ERR_DELAY)
6714 nfs4_handle_exception(server, err, &exception);
6715 } while (exception.retry);
6719 static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6721 struct nfs41_free_stateid_args args = {
6724 struct nfs41_free_stateid_res res;
6725 struct rpc_message msg = {
6726 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
6732 dprintk("NFS call free_stateid %p\n", stateid);
6733 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6734 nfs4_set_sequence_privileged(&args.seq_args);
6735 status = nfs4_call_sync_sequence(server->client, server, &msg,
6736 &args.seq_args, &res.seq_res);
6737 dprintk("NFS reply free_stateid: %d\n", status);
6742 * nfs41_free_stateid - perform a FREE_STATEID operation
6744 * @server: server / transport on which to perform the operation
6745 * @stateid: state ID to release
6747 * Returns NFS_OK if the server freed "stateid". Otherwise a
6748 * negative NFS4ERR value is returned.
6750 static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6752 struct nfs4_exception exception = { };
6755 err = _nfs4_free_stateid(server, stateid);
6756 if (err != -NFS4ERR_DELAY)
6758 nfs4_handle_exception(server, err, &exception);
6759 } while (exception.retry);
6763 static bool nfs41_match_stateid(const nfs4_stateid *s1,
6764 const nfs4_stateid *s2)
6766 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6769 if (s1->seqid == s2->seqid)
6771 if (s1->seqid == 0 || s2->seqid == 0)
6777 #endif /* CONFIG_NFS_V4_1 */
6779 static bool nfs4_match_stateid(const nfs4_stateid *s1,
6780 const nfs4_stateid *s2)
6782 return nfs4_stateid_match(s1, s2);
6786 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6787 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6788 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6789 .recover_open = nfs4_open_reclaim,
6790 .recover_lock = nfs4_lock_reclaim,
6791 .establish_clid = nfs4_init_clientid,
6792 .get_clid_cred = nfs4_get_setclientid_cred,
6793 .detect_trunking = nfs40_discover_server_trunking,
6796 #if defined(CONFIG_NFS_V4_1)
6797 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6798 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6799 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6800 .recover_open = nfs4_open_reclaim,
6801 .recover_lock = nfs4_lock_reclaim,
6802 .establish_clid = nfs41_init_clientid,
6803 .get_clid_cred = nfs4_get_exchange_id_cred,
6804 .reclaim_complete = nfs41_proc_reclaim_complete,
6805 .detect_trunking = nfs41_discover_server_trunking,
6807 #endif /* CONFIG_NFS_V4_1 */
6809 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6810 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6811 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6812 .recover_open = nfs4_open_expired,
6813 .recover_lock = nfs4_lock_expired,
6814 .establish_clid = nfs4_init_clientid,
6815 .get_clid_cred = nfs4_get_setclientid_cred,
6818 #if defined(CONFIG_NFS_V4_1)
6819 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6820 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6821 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6822 .recover_open = nfs41_open_expired,
6823 .recover_lock = nfs41_lock_expired,
6824 .establish_clid = nfs41_init_clientid,
6825 .get_clid_cred = nfs4_get_exchange_id_cred,
6827 #endif /* CONFIG_NFS_V4_1 */
6829 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6830 .sched_state_renewal = nfs4_proc_async_renew,
6831 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6832 .renew_lease = nfs4_proc_renew,
6835 #if defined(CONFIG_NFS_V4_1)
6836 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6837 .sched_state_renewal = nfs41_proc_async_sequence,
6838 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6839 .renew_lease = nfs4_proc_sequence,
6843 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6845 .init_caps = NFS_CAP_READDIRPLUS
6846 | NFS_CAP_ATOMIC_OPEN
6847 | NFS_CAP_CHANGE_ATTR
6848 | NFS_CAP_POSIX_LOCK,
6849 .call_sync = _nfs4_call_sync,
6850 .match_stateid = nfs4_match_stateid,
6851 .find_root_sec = nfs4_find_root_sec,
6852 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6853 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
6854 .state_renewal_ops = &nfs40_state_renewal_ops,
6857 #if defined(CONFIG_NFS_V4_1)
6858 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6860 .init_caps = NFS_CAP_READDIRPLUS
6861 | NFS_CAP_ATOMIC_OPEN
6862 | NFS_CAP_CHANGE_ATTR
6863 | NFS_CAP_POSIX_LOCK
6864 | NFS_CAP_STATEID_NFSV41
6865 | NFS_CAP_ATOMIC_OPEN_V1,
6866 .call_sync = nfs4_call_sync_sequence,
6867 .match_stateid = nfs41_match_stateid,
6868 .find_root_sec = nfs41_find_root_sec,
6869 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6870 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
6871 .state_renewal_ops = &nfs41_state_renewal_ops,
6875 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
6876 [0] = &nfs_v4_0_minor_ops,
6877 #if defined(CONFIG_NFS_V4_1)
6878 [1] = &nfs_v4_1_minor_ops,
6882 const struct inode_operations nfs4_dir_inode_operations = {
6883 .create = nfs_create,
6884 .lookup = nfs_lookup,
6885 .atomic_open = nfs_atomic_open,
6887 .unlink = nfs_unlink,
6888 .symlink = nfs_symlink,
6892 .rename = nfs_rename,
6893 .permission = nfs_permission,
6894 .getattr = nfs_getattr,
6895 .setattr = nfs_setattr,
6896 .getxattr = generic_getxattr,
6897 .setxattr = generic_setxattr,
6898 .listxattr = generic_listxattr,
6899 .removexattr = generic_removexattr,
6902 static const struct inode_operations nfs4_file_inode_operations = {
6903 .permission = nfs_permission,
6904 .getattr = nfs_getattr,
6905 .setattr = nfs_setattr,
6906 .getxattr = generic_getxattr,
6907 .setxattr = generic_setxattr,
6908 .listxattr = generic_listxattr,
6909 .removexattr = generic_removexattr,
6912 const struct nfs_rpc_ops nfs_v4_clientops = {
6913 .version = 4, /* protocol version */
6914 .dentry_ops = &nfs4_dentry_operations,
6915 .dir_inode_ops = &nfs4_dir_inode_operations,
6916 .file_inode_ops = &nfs4_file_inode_operations,
6917 .file_ops = &nfs4_file_operations,
6918 .getroot = nfs4_proc_get_root,
6919 .submount = nfs4_submount,
6920 .try_mount = nfs4_try_mount,
6921 .getattr = nfs4_proc_getattr,
6922 .setattr = nfs4_proc_setattr,
6923 .lookup = nfs4_proc_lookup,
6924 .access = nfs4_proc_access,
6925 .readlink = nfs4_proc_readlink,
6926 .create = nfs4_proc_create,
6927 .remove = nfs4_proc_remove,
6928 .unlink_setup = nfs4_proc_unlink_setup,
6929 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6930 .unlink_done = nfs4_proc_unlink_done,
6931 .rename = nfs4_proc_rename,
6932 .rename_setup = nfs4_proc_rename_setup,
6933 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6934 .rename_done = nfs4_proc_rename_done,
6935 .link = nfs4_proc_link,
6936 .symlink = nfs4_proc_symlink,
6937 .mkdir = nfs4_proc_mkdir,
6938 .rmdir = nfs4_proc_remove,
6939 .readdir = nfs4_proc_readdir,
6940 .mknod = nfs4_proc_mknod,
6941 .statfs = nfs4_proc_statfs,
6942 .fsinfo = nfs4_proc_fsinfo,
6943 .pathconf = nfs4_proc_pathconf,
6944 .set_capabilities = nfs4_server_capabilities,
6945 .decode_dirent = nfs4_decode_dirent,
6946 .read_setup = nfs4_proc_read_setup,
6947 .read_pageio_init = pnfs_pageio_init_read,
6948 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6949 .read_done = nfs4_read_done,
6950 .write_setup = nfs4_proc_write_setup,
6951 .write_pageio_init = pnfs_pageio_init_write,
6952 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6953 .write_done = nfs4_write_done,
6954 .commit_setup = nfs4_proc_commit_setup,
6955 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
6956 .commit_done = nfs4_commit_done,
6957 .lock = nfs4_proc_lock,
6958 .clear_acl_cache = nfs4_zap_acl_attr,
6959 .close_context = nfs4_close_context,
6960 .open_context = nfs4_atomic_open,
6961 .have_delegation = nfs4_have_delegation,
6962 .return_delegation = nfs4_inode_return_delegation,
6963 .alloc_client = nfs4_alloc_client,
6964 .init_client = nfs4_init_client,
6965 .free_client = nfs4_free_client,
6966 .create_server = nfs4_create_server,
6967 .clone_server = nfs_clone_server,
6970 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
6971 .prefix = XATTR_NAME_NFSV4_ACL,
6972 .list = nfs4_xattr_list_nfs4_acl,
6973 .get = nfs4_xattr_get_nfs4_acl,
6974 .set = nfs4_xattr_set_nfs4_acl,
6977 const struct xattr_handler *nfs4_xattr_handlers[] = {
6978 &nfs4_xattr_nfs4_acl_handler,