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:
309 nfs_remove_bad_delegation(state->inode);
310 ret = nfs4_schedule_stateid_recovery(server, state);
313 goto wait_on_recovery;
314 case -NFS4ERR_EXPIRED:
316 ret = nfs4_schedule_stateid_recovery(server, state);
320 case -NFS4ERR_STALE_STATEID:
321 case -NFS4ERR_STALE_CLIENTID:
322 nfs4_schedule_lease_recovery(clp);
323 goto wait_on_recovery;
324 #if defined(CONFIG_NFS_V4_1)
325 case -NFS4ERR_BADSESSION:
326 case -NFS4ERR_BADSLOT:
327 case -NFS4ERR_BAD_HIGH_SLOT:
328 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
329 case -NFS4ERR_DEADSESSION:
330 case -NFS4ERR_SEQ_FALSE_RETRY:
331 case -NFS4ERR_SEQ_MISORDERED:
332 dprintk("%s ERROR: %d Reset session\n", __func__,
334 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
335 goto wait_on_recovery;
336 #endif /* defined(CONFIG_NFS_V4_1) */
337 case -NFS4ERR_FILE_OPEN:
338 if (exception->timeout > HZ) {
339 /* We have retried a decent amount, time to
347 ret = nfs4_delay(server->client, &exception->timeout);
350 case -NFS4ERR_RETRY_UNCACHED_REP:
351 case -NFS4ERR_OLD_STATEID:
352 exception->retry = 1;
354 case -NFS4ERR_BADOWNER:
355 /* The following works around a Linux server bug! */
356 case -NFS4ERR_BADNAME:
357 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
358 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
359 exception->retry = 1;
360 printk(KERN_WARNING "NFS: v4 server %s "
361 "does not accept raw "
363 "Reenabling the idmapper.\n",
364 server->nfs_client->cl_hostname);
367 /* We failed to handle the error */
368 return nfs4_map_errors(ret);
370 ret = nfs4_wait_clnt_recover(clp);
372 exception->retry = 1;
377 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
379 spin_lock(&clp->cl_lock);
380 if (time_before(clp->cl_last_renewal,timestamp))
381 clp->cl_last_renewal = timestamp;
382 spin_unlock(&clp->cl_lock);
385 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
387 do_renew_lease(server->nfs_client, timestamp);
390 #if defined(CONFIG_NFS_V4_1)
392 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
394 struct nfs4_session *session;
395 struct nfs4_slot_table *tbl;
396 bool send_new_highest_used_slotid = false;
399 /* just wake up the next guy waiting since
400 * we may have not consumed a slot after all */
401 dprintk("%s: No slot\n", __func__);
404 tbl = res->sr_slot->table;
405 session = tbl->session;
407 spin_lock(&tbl->slot_tbl_lock);
408 /* Be nice to the server: try to ensure that the last transmitted
409 * value for highest_user_slotid <= target_highest_slotid
411 if (tbl->highest_used_slotid > tbl->target_highest_slotid)
412 send_new_highest_used_slotid = true;
414 if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) {
415 send_new_highest_used_slotid = false;
418 nfs4_free_slot(tbl, res->sr_slot);
420 if (tbl->highest_used_slotid != NFS4_NO_SLOT)
421 send_new_highest_used_slotid = false;
423 spin_unlock(&tbl->slot_tbl_lock);
425 if (send_new_highest_used_slotid)
426 nfs41_server_notify_highest_slotid_update(session->clp);
429 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
431 struct nfs4_session *session;
432 struct nfs4_slot *slot;
433 struct nfs_client *clp;
434 bool interrupted = false;
437 /* don't increment the sequence number if the task wasn't sent */
438 if (!RPC_WAS_SENT(task))
442 session = slot->table->session;
444 if (slot->interrupted) {
445 slot->interrupted = 0;
449 /* Check the SEQUENCE operation status */
450 switch (res->sr_status) {
452 /* Update the slot's sequence and clientid lease timer */
455 do_renew_lease(clp, res->sr_timestamp);
456 /* Check sequence flags */
457 if (res->sr_status_flags != 0)
458 nfs4_schedule_lease_recovery(clp);
459 nfs41_update_target_slotid(slot->table, slot, res);
463 * sr_status remains 1 if an RPC level error occurred.
464 * The server may or may not have processed the sequence
466 * Mark the slot as having hosted an interrupted RPC call.
468 slot->interrupted = 1;
471 /* The server detected a resend of the RPC call and
472 * returned NFS4ERR_DELAY as per Section 2.10.6.2
475 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
480 case -NFS4ERR_BADSLOT:
482 * The slot id we used was probably retired. Try again
483 * using a different slot id.
486 case -NFS4ERR_SEQ_MISORDERED:
488 * Was the last operation on this sequence interrupted?
489 * If so, retry after bumping the sequence number.
496 * Could this slot have been previously retired?
497 * If so, then the server may be expecting seq_nr = 1!
499 if (slot->seq_nr != 1) {
504 case -NFS4ERR_SEQ_FALSE_RETRY:
508 /* Just update the slot sequence no. */
512 /* The session may be reset by one of the error handlers. */
513 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
514 nfs41_sequence_free_slot(res);
517 if (rpc_restart_call_prepare(task)) {
523 if (!rpc_restart_call(task))
525 rpc_delay(task, NFS4_POLL_RETRY_MAX);
529 static int nfs4_sequence_done(struct rpc_task *task,
530 struct nfs4_sequence_res *res)
532 if (res->sr_slot == NULL)
534 return nfs41_sequence_done(task, res);
537 static void nfs41_init_sequence(struct nfs4_sequence_args *args,
538 struct nfs4_sequence_res *res, int cache_reply)
540 args->sa_slot = NULL;
541 args->sa_cache_this = 0;
542 args->sa_privileged = 0;
544 args->sa_cache_this = 1;
548 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
550 args->sa_privileged = 1;
553 int nfs41_setup_sequence(struct nfs4_session *session,
554 struct nfs4_sequence_args *args,
555 struct nfs4_sequence_res *res,
556 struct rpc_task *task)
558 struct nfs4_slot *slot;
559 struct nfs4_slot_table *tbl;
561 dprintk("--> %s\n", __func__);
562 /* slot already allocated? */
563 if (res->sr_slot != NULL)
566 tbl = &session->fc_slot_table;
568 task->tk_timeout = 0;
570 spin_lock(&tbl->slot_tbl_lock);
571 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
572 !args->sa_privileged) {
573 /* The state manager will wait until the slot table is empty */
574 dprintk("%s session is draining\n", __func__);
578 slot = nfs4_alloc_slot(tbl);
580 /* If out of memory, try again in 1/4 second */
581 if (slot == ERR_PTR(-ENOMEM))
582 task->tk_timeout = HZ >> 2;
583 dprintk("<-- %s: no free slots\n", __func__);
586 spin_unlock(&tbl->slot_tbl_lock);
588 args->sa_slot = slot;
590 dprintk("<-- %s slotid=%d seqid=%d\n", __func__,
591 slot->slot_nr, slot->seq_nr);
594 res->sr_timestamp = jiffies;
595 res->sr_status_flags = 0;
597 * sr_status is only set in decode_sequence, and so will remain
598 * set to 1 if an rpc level failure occurs.
602 rpc_call_start(task);
605 /* Privileged tasks are queued with top priority */
606 if (args->sa_privileged)
607 rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task,
608 NULL, RPC_PRIORITY_PRIVILEGED);
610 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
611 spin_unlock(&tbl->slot_tbl_lock);
614 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
616 int nfs4_setup_sequence(const struct nfs_server *server,
617 struct nfs4_sequence_args *args,
618 struct nfs4_sequence_res *res,
619 struct rpc_task *task)
621 struct nfs4_session *session = nfs4_get_session(server);
624 if (session == NULL) {
625 rpc_call_start(task);
629 dprintk("--> %s clp %p session %p sr_slot %d\n",
630 __func__, session->clp, session, res->sr_slot ?
631 res->sr_slot->slot_nr : -1);
633 ret = nfs41_setup_sequence(session, args, res, task);
635 dprintk("<-- %s status=%d\n", __func__, ret);
639 struct nfs41_call_sync_data {
640 const struct nfs_server *seq_server;
641 struct nfs4_sequence_args *seq_args;
642 struct nfs4_sequence_res *seq_res;
645 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
647 struct nfs41_call_sync_data *data = calldata;
648 struct nfs4_session *session = nfs4_get_session(data->seq_server);
650 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
652 nfs41_setup_sequence(session, data->seq_args, data->seq_res, task);
655 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
657 struct nfs41_call_sync_data *data = calldata;
659 nfs41_sequence_done(task, data->seq_res);
662 static const struct rpc_call_ops nfs41_call_sync_ops = {
663 .rpc_call_prepare = nfs41_call_sync_prepare,
664 .rpc_call_done = nfs41_call_sync_done,
667 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
668 struct nfs_server *server,
669 struct rpc_message *msg,
670 struct nfs4_sequence_args *args,
671 struct nfs4_sequence_res *res)
674 struct rpc_task *task;
675 struct nfs41_call_sync_data data = {
676 .seq_server = server,
680 struct rpc_task_setup task_setup = {
683 .callback_ops = &nfs41_call_sync_ops,
684 .callback_data = &data
687 task = rpc_run_task(&task_setup);
691 ret = task->tk_status;
699 void nfs41_init_sequence(struct nfs4_sequence_args *args,
700 struct nfs4_sequence_res *res, int cache_reply)
704 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
709 static int nfs4_sequence_done(struct rpc_task *task,
710 struct nfs4_sequence_res *res)
714 #endif /* CONFIG_NFS_V4_1 */
717 int _nfs4_call_sync(struct rpc_clnt *clnt,
718 struct nfs_server *server,
719 struct rpc_message *msg,
720 struct nfs4_sequence_args *args,
721 struct nfs4_sequence_res *res)
723 return rpc_call_sync(clnt, msg, 0);
727 int nfs4_call_sync(struct rpc_clnt *clnt,
728 struct nfs_server *server,
729 struct rpc_message *msg,
730 struct nfs4_sequence_args *args,
731 struct nfs4_sequence_res *res,
734 nfs41_init_sequence(args, res, cache_reply);
735 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
739 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
741 struct nfs_inode *nfsi = NFS_I(dir);
743 spin_lock(&dir->i_lock);
744 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
745 if (!cinfo->atomic || cinfo->before != dir->i_version)
746 nfs_force_lookup_revalidate(dir);
747 dir->i_version = cinfo->after;
748 nfs_fscache_invalidate(dir);
749 spin_unlock(&dir->i_lock);
752 struct nfs4_opendata {
754 struct nfs_openargs o_arg;
755 struct nfs_openres o_res;
756 struct nfs_open_confirmargs c_arg;
757 struct nfs_open_confirmres c_res;
758 struct nfs4_string owner_name;
759 struct nfs4_string group_name;
760 struct nfs_fattr f_attr;
762 struct dentry *dentry;
763 struct nfs4_state_owner *owner;
764 struct nfs4_state *state;
766 unsigned long timestamp;
767 unsigned int rpc_done : 1;
772 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server,
773 int err, struct nfs4_exception *exception)
777 if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1))
779 server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1;
780 exception->retry = 1;
784 static enum open_claim_type4
785 nfs4_map_atomic_open_claim(struct nfs_server *server,
786 enum open_claim_type4 claim)
788 if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
793 case NFS4_OPEN_CLAIM_FH:
794 return NFS4_OPEN_CLAIM_NULL;
795 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
796 return NFS4_OPEN_CLAIM_DELEGATE_CUR;
797 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
798 return NFS4_OPEN_CLAIM_DELEGATE_PREV;
802 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
804 p->o_res.f_attr = &p->f_attr;
805 p->o_res.seqid = p->o_arg.seqid;
806 p->c_res.seqid = p->c_arg.seqid;
807 p->o_res.server = p->o_arg.server;
808 p->o_res.access_request = p->o_arg.access;
809 nfs_fattr_init(&p->f_attr);
810 nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name);
813 static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
814 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
815 const struct iattr *attrs,
816 enum open_claim_type4 claim,
819 struct dentry *parent = dget_parent(dentry);
820 struct inode *dir = parent->d_inode;
821 struct nfs_server *server = NFS_SERVER(dir);
822 struct nfs4_opendata *p;
824 p = kzalloc(sizeof(*p), gfp_mask);
827 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
828 if (p->o_arg.seqid == NULL)
830 nfs_sb_active(dentry->d_sb);
831 p->dentry = dget(dentry);
834 atomic_inc(&sp->so_count);
835 p->o_arg.open_flags = flags;
836 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
837 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
838 * will return permission denied for all bits until close */
839 if (!(flags & O_EXCL)) {
840 /* ask server to check for all possible rights as results
842 p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
843 NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
845 p->o_arg.clientid = server->nfs_client->cl_clientid;
846 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
847 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
848 p->o_arg.name = &dentry->d_name;
849 p->o_arg.server = server;
850 p->o_arg.bitmask = server->attr_bitmask;
851 p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
852 p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
853 switch (p->o_arg.claim) {
854 case NFS4_OPEN_CLAIM_NULL:
855 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
856 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
857 p->o_arg.fh = NFS_FH(dir);
859 case NFS4_OPEN_CLAIM_PREVIOUS:
860 case NFS4_OPEN_CLAIM_FH:
861 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
862 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
863 p->o_arg.fh = NFS_FH(dentry->d_inode);
865 if (attrs != NULL && attrs->ia_valid != 0) {
868 p->o_arg.u.attrs = &p->attrs;
869 memcpy(&p->attrs, attrs, sizeof(p->attrs));
872 verf[1] = current->pid;
873 memcpy(p->o_arg.u.verifier.data, verf,
874 sizeof(p->o_arg.u.verifier.data));
876 p->c_arg.fh = &p->o_res.fh;
877 p->c_arg.stateid = &p->o_res.stateid;
878 p->c_arg.seqid = p->o_arg.seqid;
879 nfs4_init_opendata_res(p);
889 static void nfs4_opendata_free(struct kref *kref)
891 struct nfs4_opendata *p = container_of(kref,
892 struct nfs4_opendata, kref);
893 struct super_block *sb = p->dentry->d_sb;
895 nfs_free_seqid(p->o_arg.seqid);
896 if (p->state != NULL)
897 nfs4_put_open_state(p->state);
898 nfs4_put_state_owner(p->owner);
902 nfs_fattr_free_names(&p->f_attr);
906 static void nfs4_opendata_put(struct nfs4_opendata *p)
909 kref_put(&p->kref, nfs4_opendata_free);
912 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
916 ret = rpc_wait_for_completion_task(task);
920 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
924 if (open_mode & (O_EXCL|O_TRUNC))
926 switch (mode & (FMODE_READ|FMODE_WRITE)) {
928 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
929 && state->n_rdonly != 0;
932 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
933 && state->n_wronly != 0;
935 case FMODE_READ|FMODE_WRITE:
936 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
937 && state->n_rdwr != 0;
943 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
945 if (delegation == NULL)
947 if ((delegation->type & fmode) != fmode)
949 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
951 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
953 nfs_mark_delegation_referenced(delegation);
957 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
966 case FMODE_READ|FMODE_WRITE:
969 nfs4_state_set_mode_locked(state, state->state | fmode);
972 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
974 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
975 nfs4_stateid_copy(&state->stateid, stateid);
976 nfs4_stateid_copy(&state->open_stateid, stateid);
979 set_bit(NFS_O_RDONLY_STATE, &state->flags);
982 set_bit(NFS_O_WRONLY_STATE, &state->flags);
984 case FMODE_READ|FMODE_WRITE:
985 set_bit(NFS_O_RDWR_STATE, &state->flags);
989 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
991 write_seqlock(&state->seqlock);
992 nfs_set_open_stateid_locked(state, stateid, fmode);
993 write_sequnlock(&state->seqlock);
996 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
999 * Protect the call to nfs4_state_set_mode_locked and
1000 * serialise the stateid update
1002 write_seqlock(&state->seqlock);
1003 if (deleg_stateid != NULL) {
1004 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1005 set_bit(NFS_DELEGATED_STATE, &state->flags);
1007 if (open_stateid != NULL)
1008 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1009 write_sequnlock(&state->seqlock);
1010 spin_lock(&state->owner->so_lock);
1011 update_open_stateflags(state, fmode);
1012 spin_unlock(&state->owner->so_lock);
1015 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
1017 struct nfs_inode *nfsi = NFS_I(state->inode);
1018 struct nfs_delegation *deleg_cur;
1021 fmode &= (FMODE_READ|FMODE_WRITE);
1024 deleg_cur = rcu_dereference(nfsi->delegation);
1025 if (deleg_cur == NULL)
1028 spin_lock(&deleg_cur->lock);
1029 if (nfsi->delegation != deleg_cur ||
1030 test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) ||
1031 (deleg_cur->type & fmode) != fmode)
1032 goto no_delegation_unlock;
1034 if (delegation == NULL)
1035 delegation = &deleg_cur->stateid;
1036 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1037 goto no_delegation_unlock;
1039 nfs_mark_delegation_referenced(deleg_cur);
1040 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1042 no_delegation_unlock:
1043 spin_unlock(&deleg_cur->lock);
1047 if (!ret && open_stateid != NULL) {
1048 __update_open_stateid(state, open_stateid, NULL, fmode);
1056 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
1058 struct nfs_delegation *delegation;
1061 delegation = rcu_dereference(NFS_I(inode)->delegation);
1062 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1067 nfs4_inode_return_delegation(inode);
1070 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1072 struct nfs4_state *state = opendata->state;
1073 struct nfs_inode *nfsi = NFS_I(state->inode);
1074 struct nfs_delegation *delegation;
1075 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1076 fmode_t fmode = opendata->o_arg.fmode;
1077 nfs4_stateid stateid;
1081 if (can_open_cached(state, fmode, open_mode)) {
1082 spin_lock(&state->owner->so_lock);
1083 if (can_open_cached(state, fmode, open_mode)) {
1084 update_open_stateflags(state, fmode);
1085 spin_unlock(&state->owner->so_lock);
1086 goto out_return_state;
1088 spin_unlock(&state->owner->so_lock);
1091 delegation = rcu_dereference(nfsi->delegation);
1092 if (!can_open_delegated(delegation, fmode)) {
1096 /* Save the delegation */
1097 nfs4_stateid_copy(&stateid, &delegation->stateid);
1099 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1104 /* Try to update the stateid using the delegation */
1105 if (update_open_stateid(state, NULL, &stateid, fmode))
1106 goto out_return_state;
1109 return ERR_PTR(ret);
1111 atomic_inc(&state->count);
1116 nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
1118 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
1119 struct nfs_delegation *delegation;
1120 int delegation_flags = 0;
1123 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1125 delegation_flags = delegation->flags;
1127 if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) {
1128 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1129 "returning a delegation for "
1130 "OPEN(CLAIM_DELEGATE_CUR)\n",
1132 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1133 nfs_inode_set_delegation(state->inode,
1134 data->owner->so_cred,
1137 nfs_inode_reclaim_delegation(state->inode,
1138 data->owner->so_cred,
1143 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1144 * and update the nfs4_state.
1146 static struct nfs4_state *
1147 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)
1149 struct inode *inode = data->state->inode;
1150 struct nfs4_state *state = data->state;
1153 if (!data->rpc_done) {
1154 ret = data->rpc_status;
1159 if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) ||
1160 !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) ||
1161 !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE))
1165 state = nfs4_get_open_state(inode, data->owner);
1169 ret = nfs_refresh_inode(inode, &data->f_attr);
1173 if (data->o_res.delegation_type != 0)
1174 nfs4_opendata_check_deleg(data, state);
1175 update_open_stateid(state, &data->o_res.stateid, NULL,
1180 return ERR_PTR(ret);
1184 static struct nfs4_state *
1185 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1187 struct inode *inode;
1188 struct nfs4_state *state = NULL;
1191 if (!data->rpc_done) {
1192 state = nfs4_try_open_cached(data);
1197 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1199 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1200 ret = PTR_ERR(inode);
1204 state = nfs4_get_open_state(inode, data->owner);
1207 if (data->o_res.delegation_type != 0)
1208 nfs4_opendata_check_deleg(data, state);
1209 update_open_stateid(state, &data->o_res.stateid, NULL,
1213 nfs_release_seqid(data->o_arg.seqid);
1218 return ERR_PTR(ret);
1221 static struct nfs4_state *
1222 nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1224 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS)
1225 return _nfs4_opendata_reclaim_to_nfs4_state(data);
1226 return _nfs4_opendata_to_nfs4_state(data);
1229 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1231 struct nfs_inode *nfsi = NFS_I(state->inode);
1232 struct nfs_open_context *ctx;
1234 spin_lock(&state->inode->i_lock);
1235 list_for_each_entry(ctx, &nfsi->open_files, list) {
1236 if (ctx->state != state)
1238 get_nfs_open_context(ctx);
1239 spin_unlock(&state->inode->i_lock);
1242 spin_unlock(&state->inode->i_lock);
1243 return ERR_PTR(-ENOENT);
1246 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx,
1247 struct nfs4_state *state, enum open_claim_type4 claim)
1249 struct nfs4_opendata *opendata;
1251 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0,
1252 NULL, claim, GFP_NOFS);
1253 if (opendata == NULL)
1254 return ERR_PTR(-ENOMEM);
1255 opendata->state = state;
1256 atomic_inc(&state->count);
1260 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1262 struct nfs4_state *newstate;
1265 opendata->o_arg.open_flags = 0;
1266 opendata->o_arg.fmode = fmode;
1267 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1268 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1269 nfs4_init_opendata_res(opendata);
1270 ret = _nfs4_recover_proc_open(opendata);
1273 newstate = nfs4_opendata_to_nfs4_state(opendata);
1274 if (IS_ERR(newstate))
1275 return PTR_ERR(newstate);
1276 nfs4_close_state(newstate, fmode);
1281 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1283 struct nfs4_state *newstate;
1286 /* memory barrier prior to reading state->n_* */
1287 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1289 if (state->n_rdwr != 0) {
1290 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1291 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1294 if (newstate != state)
1297 if (state->n_wronly != 0) {
1298 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1299 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1302 if (newstate != state)
1305 if (state->n_rdonly != 0) {
1306 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1307 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1310 if (newstate != state)
1314 * We may have performed cached opens for all three recoveries.
1315 * Check if we need to update the current stateid.
1317 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1318 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1319 write_seqlock(&state->seqlock);
1320 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1321 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1322 write_sequnlock(&state->seqlock);
1329 * reclaim state on the server after a reboot.
1331 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1333 struct nfs_delegation *delegation;
1334 struct nfs4_opendata *opendata;
1335 fmode_t delegation_type = 0;
1338 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1339 NFS4_OPEN_CLAIM_PREVIOUS);
1340 if (IS_ERR(opendata))
1341 return PTR_ERR(opendata);
1343 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1344 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1345 delegation_type = delegation->type;
1347 opendata->o_arg.u.delegation_type = delegation_type;
1348 status = nfs4_open_recover(opendata, state);
1349 nfs4_opendata_put(opendata);
1353 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1355 struct nfs_server *server = NFS_SERVER(state->inode);
1356 struct nfs4_exception exception = { };
1359 err = _nfs4_do_open_reclaim(ctx, state);
1360 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1362 if (err != -NFS4ERR_DELAY)
1364 nfs4_handle_exception(server, err, &exception);
1365 } while (exception.retry);
1369 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1371 struct nfs_open_context *ctx;
1374 ctx = nfs4_state_find_open_context(state);
1377 ret = nfs4_do_open_reclaim(ctx, state);
1378 put_nfs_open_context(ctx);
1382 static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err)
1386 printk(KERN_ERR "NFS: %s: unhandled error "
1387 "%d.\n", __func__, err);
1392 case -NFS4ERR_BADSESSION:
1393 case -NFS4ERR_BADSLOT:
1394 case -NFS4ERR_BAD_HIGH_SLOT:
1395 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1396 case -NFS4ERR_DEADSESSION:
1397 set_bit(NFS_DELEGATED_STATE, &state->flags);
1398 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
1400 case -NFS4ERR_STALE_CLIENTID:
1401 case -NFS4ERR_STALE_STATEID:
1402 set_bit(NFS_DELEGATED_STATE, &state->flags);
1403 case -NFS4ERR_EXPIRED:
1404 /* Don't recall a delegation if it was lost */
1405 nfs4_schedule_lease_recovery(server->nfs_client);
1407 case -NFS4ERR_DELEG_REVOKED:
1408 case -NFS4ERR_ADMIN_REVOKED:
1409 case -NFS4ERR_BAD_STATEID:
1410 case -NFS4ERR_OPENMODE:
1411 nfs_inode_find_state_and_recover(state->inode,
1413 nfs4_schedule_stateid_recovery(server, state);
1415 case -NFS4ERR_DELAY:
1416 case -NFS4ERR_GRACE:
1417 set_bit(NFS_DELEGATED_STATE, &state->flags);
1421 case -NFS4ERR_DENIED:
1422 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1428 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1430 struct nfs_server *server = NFS_SERVER(state->inode);
1431 struct nfs4_opendata *opendata;
1434 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1435 NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1436 if (IS_ERR(opendata))
1437 return PTR_ERR(opendata);
1438 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1439 err = nfs4_open_recover(opendata, state);
1440 nfs4_opendata_put(opendata);
1441 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
1444 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1446 struct nfs4_opendata *data = calldata;
1448 data->rpc_status = task->tk_status;
1449 if (data->rpc_status == 0) {
1450 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1451 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1452 renew_lease(data->o_res.server, data->timestamp);
1457 static void nfs4_open_confirm_release(void *calldata)
1459 struct nfs4_opendata *data = calldata;
1460 struct nfs4_state *state = NULL;
1462 /* If this request hasn't been cancelled, do nothing */
1463 if (data->cancelled == 0)
1465 /* In case of error, no cleanup! */
1466 if (!data->rpc_done)
1468 state = nfs4_opendata_to_nfs4_state(data);
1470 nfs4_close_state(state, data->o_arg.fmode);
1472 nfs4_opendata_put(data);
1475 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1476 .rpc_call_done = nfs4_open_confirm_done,
1477 .rpc_release = nfs4_open_confirm_release,
1481 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1483 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1485 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1486 struct rpc_task *task;
1487 struct rpc_message msg = {
1488 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1489 .rpc_argp = &data->c_arg,
1490 .rpc_resp = &data->c_res,
1491 .rpc_cred = data->owner->so_cred,
1493 struct rpc_task_setup task_setup_data = {
1494 .rpc_client = server->client,
1495 .rpc_message = &msg,
1496 .callback_ops = &nfs4_open_confirm_ops,
1497 .callback_data = data,
1498 .workqueue = nfsiod_workqueue,
1499 .flags = RPC_TASK_ASYNC,
1503 kref_get(&data->kref);
1505 data->rpc_status = 0;
1506 data->timestamp = jiffies;
1507 task = rpc_run_task(&task_setup_data);
1509 return PTR_ERR(task);
1510 status = nfs4_wait_for_completion_rpc_task(task);
1512 data->cancelled = 1;
1515 status = data->rpc_status;
1520 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1522 struct nfs4_opendata *data = calldata;
1523 struct nfs4_state_owner *sp = data->owner;
1525 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1528 * Check if we still need to send an OPEN call, or if we can use
1529 * a delegation instead.
1531 if (data->state != NULL) {
1532 struct nfs_delegation *delegation;
1534 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1537 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1538 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1539 can_open_delegated(delegation, data->o_arg.fmode))
1540 goto unlock_no_action;
1543 /* Update client id. */
1544 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1545 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1546 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1547 data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1548 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1550 data->timestamp = jiffies;
1551 if (nfs4_setup_sequence(data->o_arg.server,
1552 &data->o_arg.seq_args,
1553 &data->o_res.seq_res,
1555 nfs_release_seqid(data->o_arg.seqid);
1560 task->tk_action = NULL;
1562 nfs4_sequence_done(task, &data->o_res.seq_res);
1565 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1567 struct nfs4_opendata *data = calldata;
1569 data->rpc_status = task->tk_status;
1571 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1574 if (task->tk_status == 0) {
1575 if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) {
1576 switch (data->o_res.f_attr->mode & S_IFMT) {
1580 data->rpc_status = -ELOOP;
1583 data->rpc_status = -EISDIR;
1586 data->rpc_status = -ENOTDIR;
1589 renew_lease(data->o_res.server, data->timestamp);
1590 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1591 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1596 static void nfs4_open_release(void *calldata)
1598 struct nfs4_opendata *data = calldata;
1599 struct nfs4_state *state = NULL;
1601 /* If this request hasn't been cancelled, do nothing */
1602 if (data->cancelled == 0)
1604 /* In case of error, no cleanup! */
1605 if (data->rpc_status != 0 || !data->rpc_done)
1607 /* In case we need an open_confirm, no cleanup! */
1608 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1610 state = nfs4_opendata_to_nfs4_state(data);
1612 nfs4_close_state(state, data->o_arg.fmode);
1614 nfs4_opendata_put(data);
1617 static const struct rpc_call_ops nfs4_open_ops = {
1618 .rpc_call_prepare = nfs4_open_prepare,
1619 .rpc_call_done = nfs4_open_done,
1620 .rpc_release = nfs4_open_release,
1623 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1625 struct inode *dir = data->dir->d_inode;
1626 struct nfs_server *server = NFS_SERVER(dir);
1627 struct nfs_openargs *o_arg = &data->o_arg;
1628 struct nfs_openres *o_res = &data->o_res;
1629 struct rpc_task *task;
1630 struct rpc_message msg = {
1631 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1634 .rpc_cred = data->owner->so_cred,
1636 struct rpc_task_setup task_setup_data = {
1637 .rpc_client = server->client,
1638 .rpc_message = &msg,
1639 .callback_ops = &nfs4_open_ops,
1640 .callback_data = data,
1641 .workqueue = nfsiod_workqueue,
1642 .flags = RPC_TASK_ASYNC,
1646 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1647 kref_get(&data->kref);
1649 data->rpc_status = 0;
1650 data->cancelled = 0;
1652 nfs4_set_sequence_privileged(&o_arg->seq_args);
1653 task = rpc_run_task(&task_setup_data);
1655 return PTR_ERR(task);
1656 status = nfs4_wait_for_completion_rpc_task(task);
1658 data->cancelled = 1;
1661 status = data->rpc_status;
1667 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1669 struct inode *dir = data->dir->d_inode;
1670 struct nfs_openres *o_res = &data->o_res;
1673 status = nfs4_run_open_task(data, 1);
1674 if (status != 0 || !data->rpc_done)
1677 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1679 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1680 status = _nfs4_proc_open_confirm(data);
1688 static int nfs4_opendata_access(struct rpc_cred *cred,
1689 struct nfs4_opendata *opendata,
1690 struct nfs4_state *state, fmode_t fmode,
1693 struct nfs_access_entry cache;
1696 /* access call failed or for some reason the server doesn't
1697 * support any access modes -- defer access call until later */
1698 if (opendata->o_res.access_supported == 0)
1702 /* don't check MAY_WRITE - a newly created file may not have
1703 * write mode bits, but POSIX allows the creating process to write.
1704 * use openflags to check for exec, because fmode won't
1705 * always have FMODE_EXEC set when file open for exec. */
1706 if (openflags & __FMODE_EXEC) {
1707 /* ONLY check for exec rights */
1709 } else if (fmode & FMODE_READ)
1713 cache.jiffies = jiffies;
1714 nfs_access_set_mask(&cache, opendata->o_res.access_result);
1715 nfs_access_add_cache(state->inode, &cache);
1717 if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0)
1720 /* even though OPEN succeeded, access is denied. Close the file */
1721 nfs4_close_state(state, fmode);
1726 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1728 static int _nfs4_proc_open(struct nfs4_opendata *data)
1730 struct inode *dir = data->dir->d_inode;
1731 struct nfs_server *server = NFS_SERVER(dir);
1732 struct nfs_openargs *o_arg = &data->o_arg;
1733 struct nfs_openres *o_res = &data->o_res;
1736 status = nfs4_run_open_task(data, 0);
1737 if (!data->rpc_done)
1740 if (status == -NFS4ERR_BADNAME &&
1741 !(o_arg->open_flags & O_CREAT))
1746 nfs_fattr_map_and_free_names(server, &data->f_attr);
1748 if (o_arg->open_flags & O_CREAT)
1749 update_changeattr(dir, &o_res->cinfo);
1750 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1751 server->caps &= ~NFS_CAP_POSIX_LOCK;
1752 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1753 status = _nfs4_proc_open_confirm(data);
1757 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1758 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1762 static int nfs4_recover_expired_lease(struct nfs_server *server)
1764 return nfs4_client_recover_expired_lease(server->nfs_client);
1769 * reclaim state on the server after a network partition.
1770 * Assumes caller holds the appropriate lock
1772 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1774 struct nfs4_opendata *opendata;
1777 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1778 NFS4_OPEN_CLAIM_FH);
1779 if (IS_ERR(opendata))
1780 return PTR_ERR(opendata);
1781 ret = nfs4_open_recover(opendata, state);
1783 d_drop(ctx->dentry);
1784 nfs4_opendata_put(opendata);
1788 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1790 struct nfs_server *server = NFS_SERVER(state->inode);
1791 struct nfs4_exception exception = { };
1795 err = _nfs4_open_expired(ctx, state);
1796 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1801 case -NFS4ERR_GRACE:
1802 case -NFS4ERR_DELAY:
1803 nfs4_handle_exception(server, err, &exception);
1806 } while (exception.retry);
1811 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1813 struct nfs_open_context *ctx;
1816 ctx = nfs4_state_find_open_context(state);
1819 ret = nfs4_do_open_expired(ctx, state);
1820 put_nfs_open_context(ctx);
1824 #if defined(CONFIG_NFS_V4_1)
1825 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
1827 struct nfs_server *server = NFS_SERVER(state->inode);
1828 nfs4_stateid *stateid = &state->stateid;
1831 /* If a state reset has been done, test_stateid is unneeded */
1832 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1835 status = nfs41_test_stateid(server, stateid);
1836 if (status != NFS_OK) {
1837 /* Free the stateid unless the server explicitly
1838 * informs us the stateid is unrecognized. */
1839 if (status != -NFS4ERR_BAD_STATEID)
1840 nfs41_free_stateid(server, stateid);
1841 nfs_remove_bad_delegation(state->inode);
1843 write_seqlock(&state->seqlock);
1844 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1845 write_sequnlock(&state->seqlock);
1846 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1851 * nfs41_check_open_stateid - possibly free an open stateid
1853 * @state: NFSv4 state for an inode
1855 * Returns NFS_OK if recovery for this stateid is now finished.
1856 * Otherwise a negative NFS4ERR value is returned.
1858 static int nfs41_check_open_stateid(struct nfs4_state *state)
1860 struct nfs_server *server = NFS_SERVER(state->inode);
1861 nfs4_stateid *stateid = &state->open_stateid;
1864 /* If a state reset has been done, test_stateid is unneeded */
1865 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
1866 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
1867 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
1868 return -NFS4ERR_BAD_STATEID;
1870 status = nfs41_test_stateid(server, stateid);
1871 if (status != NFS_OK) {
1872 /* Free the stateid unless the server explicitly
1873 * informs us the stateid is unrecognized. */
1874 if (status != -NFS4ERR_BAD_STATEID)
1875 nfs41_free_stateid(server, stateid);
1877 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1878 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1879 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1884 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1888 nfs41_clear_delegation_stateid(state);
1889 status = nfs41_check_open_stateid(state);
1890 if (status != NFS_OK)
1891 status = nfs4_open_expired(sp, state);
1897 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1898 * fields corresponding to attributes that were used to store the verifier.
1899 * Make sure we clobber those fields in the later setattr call
1901 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1903 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1904 !(sattr->ia_valid & ATTR_ATIME_SET))
1905 sattr->ia_valid |= ATTR_ATIME;
1907 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1908 !(sattr->ia_valid & ATTR_MTIME_SET))
1909 sattr->ia_valid |= ATTR_MTIME;
1912 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
1915 struct nfs4_state **res)
1917 struct nfs4_state_owner *sp = opendata->owner;
1918 struct nfs_server *server = sp->so_server;
1919 struct nfs4_state *state;
1923 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
1925 ret = _nfs4_proc_open(opendata);
1929 state = nfs4_opendata_to_nfs4_state(opendata);
1930 ret = PTR_ERR(state);
1933 if (server->caps & NFS_CAP_POSIX_LOCK)
1934 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1936 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
1940 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
1941 nfs4_schedule_stateid_recovery(server, state);
1948 * Returns a referenced nfs4_state
1950 static int _nfs4_do_open(struct inode *dir,
1951 struct dentry *dentry,
1954 struct iattr *sattr,
1955 struct rpc_cred *cred,
1956 struct nfs4_state **res,
1957 struct nfs4_threshold **ctx_th)
1959 struct nfs4_state_owner *sp;
1960 struct nfs4_state *state = NULL;
1961 struct nfs_server *server = NFS_SERVER(dir);
1962 struct nfs4_opendata *opendata;
1963 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
1966 /* Protect against reboot recovery conflicts */
1968 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1970 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1973 status = nfs4_recover_expired_lease(server);
1975 goto err_put_state_owner;
1976 if (dentry->d_inode != NULL)
1977 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
1979 if (dentry->d_inode)
1980 claim = NFS4_OPEN_CLAIM_FH;
1981 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
1983 if (opendata == NULL)
1984 goto err_put_state_owner;
1986 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
1987 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
1988 if (!opendata->f_attr.mdsthreshold)
1989 goto err_opendata_put;
1990 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
1992 if (dentry->d_inode != NULL)
1993 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
1995 status = _nfs4_open_and_get_state(opendata, fmode, flags, &state);
1997 goto err_opendata_put;
1999 if (opendata->o_arg.open_flags & O_EXCL) {
2000 nfs4_exclusive_attrset(opendata, sattr);
2002 nfs_fattr_init(opendata->o_res.f_attr);
2003 status = nfs4_do_setattr(state->inode, cred,
2004 opendata->o_res.f_attr, sattr,
2007 nfs_setattr_update_inode(state->inode, sattr);
2008 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
2011 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
2012 *ctx_th = opendata->f_attr.mdsthreshold;
2014 kfree(opendata->f_attr.mdsthreshold);
2015 opendata->f_attr.mdsthreshold = NULL;
2017 nfs4_opendata_put(opendata);
2018 nfs4_put_state_owner(sp);
2022 kfree(opendata->f_attr.mdsthreshold);
2023 nfs4_opendata_put(opendata);
2024 err_put_state_owner:
2025 nfs4_put_state_owner(sp);
2032 static struct nfs4_state *nfs4_do_open(struct inode *dir,
2033 struct dentry *dentry,
2036 struct iattr *sattr,
2037 struct rpc_cred *cred,
2038 struct nfs4_threshold **ctx_th)
2040 struct nfs_server *server = NFS_SERVER(dir);
2041 struct nfs4_exception exception = { };
2042 struct nfs4_state *res;
2045 fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC;
2047 status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred,
2051 /* NOTE: BAD_SEQID means the server and client disagree about the
2052 * book-keeping w.r.t. state-changing operations
2053 * (OPEN/CLOSE/LOCK/LOCKU...)
2054 * It is actually a sign of a bug on the client or on the server.
2056 * If we receive a BAD_SEQID error in the particular case of
2057 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2058 * have unhashed the old state_owner for us, and that we can
2059 * therefore safely retry using a new one. We should still warn
2060 * the user though...
2062 if (status == -NFS4ERR_BAD_SEQID) {
2063 pr_warn_ratelimited("NFS: v4 server %s "
2064 " returned a bad sequence-id error!\n",
2065 NFS_SERVER(dir)->nfs_client->cl_hostname);
2066 exception.retry = 1;
2070 * BAD_STATEID on OPEN means that the server cancelled our
2071 * state before it received the OPEN_CONFIRM.
2072 * Recover by retrying the request as per the discussion
2073 * on Page 181 of RFC3530.
2075 if (status == -NFS4ERR_BAD_STATEID) {
2076 exception.retry = 1;
2079 if (status == -EAGAIN) {
2080 /* We must have found a delegation */
2081 exception.retry = 1;
2084 if (nfs4_clear_cap_atomic_open_v1(server, status, &exception))
2086 res = ERR_PTR(nfs4_handle_exception(server,
2087 status, &exception));
2088 } while (exception.retry);
2092 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2093 struct nfs_fattr *fattr, struct iattr *sattr,
2094 struct nfs4_state *state)
2096 struct nfs_server *server = NFS_SERVER(inode);
2097 struct nfs_setattrargs arg = {
2098 .fh = NFS_FH(inode),
2101 .bitmask = server->attr_bitmask,
2103 struct nfs_setattrres res = {
2107 struct rpc_message msg = {
2108 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2113 unsigned long timestamp = jiffies;
2116 nfs_fattr_init(fattr);
2118 if (state != NULL && nfs4_valid_open_stateid(state)) {
2119 struct nfs_lockowner lockowner = {
2120 .l_owner = current->files,
2121 .l_pid = current->tgid,
2123 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2125 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
2127 /* Use that stateid */
2129 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2131 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2132 if (status == 0 && state != NULL)
2133 renew_lease(server, timestamp);
2137 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2138 struct nfs_fattr *fattr, struct iattr *sattr,
2139 struct nfs4_state *state)
2141 struct nfs_server *server = NFS_SERVER(inode);
2142 struct nfs4_exception exception = {
2148 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
2150 case -NFS4ERR_OPENMODE:
2151 if (state && !(state->state & FMODE_WRITE)) {
2153 if (sattr->ia_valid & ATTR_OPEN)
2158 err = nfs4_handle_exception(server, err, &exception);
2159 } while (exception.retry);
2164 struct nfs4_closedata {
2165 struct inode *inode;
2166 struct nfs4_state *state;
2167 struct nfs_closeargs arg;
2168 struct nfs_closeres res;
2169 struct nfs_fattr fattr;
2170 unsigned long timestamp;
2175 static void nfs4_free_closedata(void *data)
2177 struct nfs4_closedata *calldata = data;
2178 struct nfs4_state_owner *sp = calldata->state->owner;
2179 struct super_block *sb = calldata->state->inode->i_sb;
2182 pnfs_roc_release(calldata->state->inode);
2183 nfs4_put_open_state(calldata->state);
2184 nfs_free_seqid(calldata->arg.seqid);
2185 nfs4_put_state_owner(sp);
2186 nfs_sb_deactive(sb);
2190 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2193 spin_lock(&state->owner->so_lock);
2194 if (!(fmode & FMODE_READ))
2195 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2196 if (!(fmode & FMODE_WRITE))
2197 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2198 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2199 spin_unlock(&state->owner->so_lock);
2202 static void nfs4_close_done(struct rpc_task *task, void *data)
2204 struct nfs4_closedata *calldata = data;
2205 struct nfs4_state *state = calldata->state;
2206 struct nfs_server *server = NFS_SERVER(calldata->inode);
2208 dprintk("%s: begin!\n", __func__);
2209 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2211 /* hmm. we are done with the inode, and in the process of freeing
2212 * the state_owner. we keep this around to process errors
2214 switch (task->tk_status) {
2217 pnfs_roc_set_barrier(state->inode,
2218 calldata->roc_barrier);
2219 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2220 renew_lease(server, calldata->timestamp);
2221 nfs4_close_clear_stateid_flags(state,
2222 calldata->arg.fmode);
2224 case -NFS4ERR_STALE_STATEID:
2225 case -NFS4ERR_OLD_STATEID:
2226 case -NFS4ERR_BAD_STATEID:
2227 case -NFS4ERR_EXPIRED:
2228 if (calldata->arg.fmode == 0)
2231 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2232 rpc_restart_call_prepare(task);
2234 nfs_release_seqid(calldata->arg.seqid);
2235 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2236 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2239 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2241 struct nfs4_closedata *calldata = data;
2242 struct nfs4_state *state = calldata->state;
2243 struct inode *inode = calldata->inode;
2246 dprintk("%s: begin!\n", __func__);
2247 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2250 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2251 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2252 spin_lock(&state->owner->so_lock);
2253 /* Calculate the change in open mode */
2254 if (state->n_rdwr == 0) {
2255 if (state->n_rdonly == 0) {
2256 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2257 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2258 calldata->arg.fmode &= ~FMODE_READ;
2260 if (state->n_wronly == 0) {
2261 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2262 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2263 calldata->arg.fmode &= ~FMODE_WRITE;
2266 if (!nfs4_valid_open_stateid(state))
2268 spin_unlock(&state->owner->so_lock);
2271 /* Note: exit _without_ calling nfs4_close_done */
2275 if (calldata->arg.fmode == 0) {
2276 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2277 if (calldata->roc &&
2278 pnfs_roc_drain(inode, &calldata->roc_barrier, task))
2282 nfs_fattr_init(calldata->res.fattr);
2283 calldata->timestamp = jiffies;
2284 if (nfs4_setup_sequence(NFS_SERVER(inode),
2285 &calldata->arg.seq_args,
2286 &calldata->res.seq_res,
2288 nfs_release_seqid(calldata->arg.seqid);
2289 dprintk("%s: done!\n", __func__);
2292 task->tk_action = NULL;
2294 nfs4_sequence_done(task, &calldata->res.seq_res);
2297 static const struct rpc_call_ops nfs4_close_ops = {
2298 .rpc_call_prepare = nfs4_close_prepare,
2299 .rpc_call_done = nfs4_close_done,
2300 .rpc_release = nfs4_free_closedata,
2304 * It is possible for data to be read/written from a mem-mapped file
2305 * after the sys_close call (which hits the vfs layer as a flush).
2306 * This means that we can't safely call nfsv4 close on a file until
2307 * the inode is cleared. This in turn means that we are not good
2308 * NFSv4 citizens - we do not indicate to the server to update the file's
2309 * share state even when we are done with one of the three share
2310 * stateid's in the inode.
2312 * NOTE: Caller must be holding the sp->so_owner semaphore!
2314 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
2316 struct nfs_server *server = NFS_SERVER(state->inode);
2317 struct nfs4_closedata *calldata;
2318 struct nfs4_state_owner *sp = state->owner;
2319 struct rpc_task *task;
2320 struct rpc_message msg = {
2321 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2322 .rpc_cred = state->owner->so_cred,
2324 struct rpc_task_setup task_setup_data = {
2325 .rpc_client = server->client,
2326 .rpc_message = &msg,
2327 .callback_ops = &nfs4_close_ops,
2328 .workqueue = nfsiod_workqueue,
2329 .flags = RPC_TASK_ASYNC,
2331 int status = -ENOMEM;
2333 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2334 if (calldata == NULL)
2336 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2337 calldata->inode = state->inode;
2338 calldata->state = state;
2339 calldata->arg.fh = NFS_FH(state->inode);
2340 calldata->arg.stateid = &state->open_stateid;
2341 /* Serialization for the sequence id */
2342 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2343 if (calldata->arg.seqid == NULL)
2344 goto out_free_calldata;
2345 calldata->arg.fmode = 0;
2346 calldata->arg.bitmask = server->cache_consistency_bitmask;
2347 calldata->res.fattr = &calldata->fattr;
2348 calldata->res.seqid = calldata->arg.seqid;
2349 calldata->res.server = server;
2350 calldata->roc = pnfs_roc(state->inode);
2351 nfs_sb_active(calldata->inode->i_sb);
2353 msg.rpc_argp = &calldata->arg;
2354 msg.rpc_resp = &calldata->res;
2355 task_setup_data.callback_data = calldata;
2356 task = rpc_run_task(&task_setup_data);
2358 return PTR_ERR(task);
2361 status = rpc_wait_for_completion_task(task);
2367 nfs4_put_open_state(state);
2368 nfs4_put_state_owner(sp);
2372 static struct inode *
2373 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2375 struct nfs4_state *state;
2377 /* Protect against concurrent sillydeletes */
2378 state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr,
2379 ctx->cred, &ctx->mdsthreshold);
2381 return ERR_CAST(state);
2383 return igrab(state->inode);
2386 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2388 if (ctx->state == NULL)
2391 nfs4_close_sync(ctx->state, ctx->mode);
2393 nfs4_close_state(ctx->state, ctx->mode);
2396 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2398 struct nfs4_server_caps_arg args = {
2401 struct nfs4_server_caps_res res = {};
2402 struct rpc_message msg = {
2403 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2409 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2411 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2412 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2413 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2414 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2415 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2416 NFS_CAP_CTIME|NFS_CAP_MTIME);
2417 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2418 server->caps |= NFS_CAP_ACLS;
2419 if (res.has_links != 0)
2420 server->caps |= NFS_CAP_HARDLINKS;
2421 if (res.has_symlinks != 0)
2422 server->caps |= NFS_CAP_SYMLINKS;
2423 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2424 server->caps |= NFS_CAP_FILEID;
2425 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2426 server->caps |= NFS_CAP_MODE;
2427 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2428 server->caps |= NFS_CAP_NLINK;
2429 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2430 server->caps |= NFS_CAP_OWNER;
2431 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2432 server->caps |= NFS_CAP_OWNER_GROUP;
2433 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2434 server->caps |= NFS_CAP_ATIME;
2435 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2436 server->caps |= NFS_CAP_CTIME;
2437 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2438 server->caps |= NFS_CAP_MTIME;
2440 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2441 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2442 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2443 server->acl_bitmask = res.acl_bitmask;
2444 server->fh_expire_type = res.fh_expire_type;
2450 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2452 struct nfs4_exception exception = { };
2455 err = nfs4_handle_exception(server,
2456 _nfs4_server_capabilities(server, fhandle),
2458 } while (exception.retry);
2462 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2463 struct nfs_fsinfo *info)
2465 struct nfs4_lookup_root_arg args = {
2466 .bitmask = nfs4_fattr_bitmap,
2468 struct nfs4_lookup_res res = {
2470 .fattr = info->fattr,
2473 struct rpc_message msg = {
2474 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2479 nfs_fattr_init(info->fattr);
2480 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2483 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2484 struct nfs_fsinfo *info)
2486 struct nfs4_exception exception = { };
2489 err = _nfs4_lookup_root(server, fhandle, info);
2492 case -NFS4ERR_WRONGSEC:
2495 err = nfs4_handle_exception(server, err, &exception);
2497 } while (exception.retry);
2502 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2503 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2505 struct rpc_auth *auth;
2508 auth = rpcauth_create(flavor, server->client);
2513 ret = nfs4_lookup_root(server, fhandle, info);
2518 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2519 struct nfs_fsinfo *info)
2521 int i, len, status = 0;
2522 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS];
2524 len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array));
2528 for (i = 0; i < len; i++) {
2529 /* AUTH_UNIX is the default flavor if none was specified,
2530 * thus has already been tried. */
2531 if (flav_array[i] == RPC_AUTH_UNIX)
2534 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2535 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2540 * -EACCESS could mean that the user doesn't have correct permissions
2541 * to access the mount. It could also mean that we tried to mount
2542 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2543 * existing mount programs don't handle -EACCES very well so it should
2544 * be mapped to -EPERM instead.
2546 if (status == -EACCES)
2552 * get the file handle for the "/" directory on the server
2554 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2555 struct nfs_fsinfo *info)
2557 int minor_version = server->nfs_client->cl_minorversion;
2558 int status = nfs4_lookup_root(server, fhandle, info);
2559 if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR))
2561 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2562 * by nfs4_map_errors() as this function exits.
2564 status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info);
2566 status = nfs4_server_capabilities(server, fhandle);
2568 status = nfs4_do_fsinfo(server, fhandle, info);
2569 return nfs4_map_errors(status);
2572 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2573 struct nfs_fsinfo *info)
2576 struct nfs_fattr *fattr = info->fattr;
2578 error = nfs4_server_capabilities(server, mntfh);
2580 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2584 error = nfs4_proc_getattr(server, mntfh, fattr);
2586 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2590 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2591 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2592 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2598 * Get locations and (maybe) other attributes of a referral.
2599 * Note that we'll actually follow the referral later when
2600 * we detect fsid mismatch in inode revalidation
2602 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2603 const struct qstr *name, struct nfs_fattr *fattr,
2604 struct nfs_fh *fhandle)
2606 int status = -ENOMEM;
2607 struct page *page = NULL;
2608 struct nfs4_fs_locations *locations = NULL;
2610 page = alloc_page(GFP_KERNEL);
2613 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2614 if (locations == NULL)
2617 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2620 /* Make sure server returned a different fsid for the referral */
2621 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2622 dprintk("%s: server did not return a different fsid for"
2623 " a referral at %s\n", __func__, name->name);
2627 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2628 nfs_fixup_referral_attributes(&locations->fattr);
2630 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2631 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2632 memset(fhandle, 0, sizeof(struct nfs_fh));
2640 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2642 struct nfs4_getattr_arg args = {
2644 .bitmask = server->attr_bitmask,
2646 struct nfs4_getattr_res res = {
2650 struct rpc_message msg = {
2651 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2656 nfs_fattr_init(fattr);
2657 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2660 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2662 struct nfs4_exception exception = { };
2665 err = nfs4_handle_exception(server,
2666 _nfs4_proc_getattr(server, fhandle, fattr),
2668 } while (exception.retry);
2673 * The file is not closed if it is opened due to the a request to change
2674 * the size of the file. The open call will not be needed once the
2675 * VFS layer lookup-intents are implemented.
2677 * Close is called when the inode is destroyed.
2678 * If we haven't opened the file for O_WRONLY, we
2679 * need to in the size_change case to obtain a stateid.
2682 * Because OPEN is always done by name in nfsv4, it is
2683 * possible that we opened a different file by the same
2684 * name. We can recognize this race condition, but we
2685 * can't do anything about it besides returning an error.
2687 * This will be fixed with VFS changes (lookup-intent).
2690 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2691 struct iattr *sattr)
2693 struct inode *inode = dentry->d_inode;
2694 struct rpc_cred *cred = NULL;
2695 struct nfs4_state *state = NULL;
2698 if (pnfs_ld_layoutret_on_setattr(inode))
2699 pnfs_commit_and_return_layout(inode);
2701 nfs_fattr_init(fattr);
2703 /* Deal with open(O_TRUNC) */
2704 if (sattr->ia_valid & ATTR_OPEN)
2705 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2707 /* Optimization: if the end result is no change, don't RPC */
2708 if ((sattr->ia_valid & ~(ATTR_FILE)) == 0)
2711 /* Search for an existing open(O_WRITE) file */
2712 if (sattr->ia_valid & ATTR_FILE) {
2713 struct nfs_open_context *ctx;
2715 ctx = nfs_file_open_context(sattr->ia_file);
2722 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2724 nfs_setattr_update_inode(inode, sattr);
2728 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2729 const struct qstr *name, struct nfs_fh *fhandle,
2730 struct nfs_fattr *fattr)
2732 struct nfs_server *server = NFS_SERVER(dir);
2734 struct nfs4_lookup_arg args = {
2735 .bitmask = server->attr_bitmask,
2736 .dir_fh = NFS_FH(dir),
2739 struct nfs4_lookup_res res = {
2744 struct rpc_message msg = {
2745 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2750 nfs_fattr_init(fattr);
2752 dprintk("NFS call lookup %s\n", name->name);
2753 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2754 dprintk("NFS reply lookup: %d\n", status);
2758 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
2760 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2761 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
2762 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2766 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
2767 struct qstr *name, struct nfs_fh *fhandle,
2768 struct nfs_fattr *fattr)
2770 struct nfs4_exception exception = { };
2771 struct rpc_clnt *client = *clnt;
2774 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2776 case -NFS4ERR_BADNAME:
2779 case -NFS4ERR_MOVED:
2780 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2782 case -NFS4ERR_WRONGSEC:
2784 if (client != *clnt)
2787 client = nfs4_create_sec_client(client, dir, name);
2789 return PTR_ERR(client);
2791 exception.retry = 1;
2794 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2796 } while (exception.retry);
2801 else if (client != *clnt)
2802 rpc_shutdown_client(client);
2807 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
2808 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2811 struct rpc_clnt *client = NFS_CLIENT(dir);
2813 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2814 if (client != NFS_CLIENT(dir)) {
2815 rpc_shutdown_client(client);
2816 nfs_fixup_secinfo_attributes(fattr);
2822 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
2823 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2826 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
2828 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2830 rpc_shutdown_client(client);
2831 return ERR_PTR(status);
2836 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2838 struct nfs_server *server = NFS_SERVER(inode);
2839 struct nfs4_accessargs args = {
2840 .fh = NFS_FH(inode),
2841 .bitmask = server->cache_consistency_bitmask,
2843 struct nfs4_accessres res = {
2846 struct rpc_message msg = {
2847 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2850 .rpc_cred = entry->cred,
2852 int mode = entry->mask;
2856 * Determine which access bits we want to ask for...
2858 if (mode & MAY_READ)
2859 args.access |= NFS4_ACCESS_READ;
2860 if (S_ISDIR(inode->i_mode)) {
2861 if (mode & MAY_WRITE)
2862 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2863 if (mode & MAY_EXEC)
2864 args.access |= NFS4_ACCESS_LOOKUP;
2866 if (mode & MAY_WRITE)
2867 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2868 if (mode & MAY_EXEC)
2869 args.access |= NFS4_ACCESS_EXECUTE;
2872 res.fattr = nfs_alloc_fattr();
2873 if (res.fattr == NULL)
2876 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2878 nfs_access_set_mask(entry, res.access);
2879 nfs_refresh_inode(inode, res.fattr);
2881 nfs_free_fattr(res.fattr);
2885 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2887 struct nfs4_exception exception = { };
2890 err = nfs4_handle_exception(NFS_SERVER(inode),
2891 _nfs4_proc_access(inode, entry),
2893 } while (exception.retry);
2898 * TODO: For the time being, we don't try to get any attributes
2899 * along with any of the zero-copy operations READ, READDIR,
2902 * In the case of the first three, we want to put the GETATTR
2903 * after the read-type operation -- this is because it is hard
2904 * to predict the length of a GETATTR response in v4, and thus
2905 * align the READ data correctly. This means that the GETATTR
2906 * may end up partially falling into the page cache, and we should
2907 * shift it into the 'tail' of the xdr_buf before processing.
2908 * To do this efficiently, we need to know the total length
2909 * of data received, which doesn't seem to be available outside
2912 * In the case of WRITE, we also want to put the GETATTR after
2913 * the operation -- in this case because we want to make sure
2914 * we get the post-operation mtime and size.
2916 * Both of these changes to the XDR layer would in fact be quite
2917 * minor, but I decided to leave them for a subsequent patch.
2919 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2920 unsigned int pgbase, unsigned int pglen)
2922 struct nfs4_readlink args = {
2923 .fh = NFS_FH(inode),
2928 struct nfs4_readlink_res res;
2929 struct rpc_message msg = {
2930 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2935 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2938 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2939 unsigned int pgbase, unsigned int pglen)
2941 struct nfs4_exception exception = { };
2944 err = nfs4_handle_exception(NFS_SERVER(inode),
2945 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2947 } while (exception.retry);
2952 * This is just for mknod. open(O_CREAT) will always do ->open_context().
2955 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2958 struct nfs_open_context *ctx;
2959 struct nfs4_state *state;
2962 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
2964 return PTR_ERR(ctx);
2966 sattr->ia_mode &= ~current_umask();
2967 state = nfs4_do_open(dir, dentry, ctx->mode,
2968 flags, sattr, ctx->cred,
2969 &ctx->mdsthreshold);
2971 if (IS_ERR(state)) {
2972 status = PTR_ERR(state);
2975 d_add(dentry, igrab(state->inode));
2976 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2979 put_nfs_open_context(ctx);
2983 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2985 struct nfs_server *server = NFS_SERVER(dir);
2986 struct nfs_removeargs args = {
2990 struct nfs_removeres res = {
2993 struct rpc_message msg = {
2994 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
3000 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
3002 update_changeattr(dir, &res.cinfo);
3006 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
3008 struct nfs4_exception exception = { };
3011 err = nfs4_handle_exception(NFS_SERVER(dir),
3012 _nfs4_proc_remove(dir, name),
3014 } while (exception.retry);
3018 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
3020 struct nfs_server *server = NFS_SERVER(dir);
3021 struct nfs_removeargs *args = msg->rpc_argp;
3022 struct nfs_removeres *res = msg->rpc_resp;
3024 res->server = server;
3025 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
3026 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
3029 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
3031 nfs4_setup_sequence(NFS_SERVER(data->dir),
3032 &data->args.seq_args,
3037 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
3039 struct nfs_removeres *res = task->tk_msg.rpc_resp;
3041 if (!nfs4_sequence_done(task, &res->seq_res))
3043 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3045 update_changeattr(dir, &res->cinfo);
3049 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
3051 struct nfs_server *server = NFS_SERVER(dir);
3052 struct nfs_renameargs *arg = msg->rpc_argp;
3053 struct nfs_renameres *res = msg->rpc_resp;
3055 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
3056 res->server = server;
3057 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
3060 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
3062 nfs4_setup_sequence(NFS_SERVER(data->old_dir),
3063 &data->args.seq_args,
3068 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
3069 struct inode *new_dir)
3071 struct nfs_renameres *res = task->tk_msg.rpc_resp;
3073 if (!nfs4_sequence_done(task, &res->seq_res))
3075 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3078 update_changeattr(old_dir, &res->old_cinfo);
3079 update_changeattr(new_dir, &res->new_cinfo);
3083 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3084 struct inode *new_dir, struct qstr *new_name)
3086 struct nfs_server *server = NFS_SERVER(old_dir);
3087 struct nfs_renameargs arg = {
3088 .old_dir = NFS_FH(old_dir),
3089 .new_dir = NFS_FH(new_dir),
3090 .old_name = old_name,
3091 .new_name = new_name,
3093 struct nfs_renameres res = {
3096 struct rpc_message msg = {
3097 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3101 int status = -ENOMEM;
3103 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3105 update_changeattr(old_dir, &res.old_cinfo);
3106 update_changeattr(new_dir, &res.new_cinfo);
3111 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3112 struct inode *new_dir, struct qstr *new_name)
3114 struct nfs4_exception exception = { };
3117 err = nfs4_handle_exception(NFS_SERVER(old_dir),
3118 _nfs4_proc_rename(old_dir, old_name,
3121 } while (exception.retry);
3125 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3127 struct nfs_server *server = NFS_SERVER(inode);
3128 struct nfs4_link_arg arg = {
3129 .fh = NFS_FH(inode),
3130 .dir_fh = NFS_FH(dir),
3132 .bitmask = server->attr_bitmask,
3134 struct nfs4_link_res res = {
3137 struct rpc_message msg = {
3138 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3142 int status = -ENOMEM;
3144 res.fattr = nfs_alloc_fattr();
3145 if (res.fattr == NULL)
3148 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3150 update_changeattr(dir, &res.cinfo);
3151 nfs_post_op_update_inode(inode, res.fattr);
3154 nfs_free_fattr(res.fattr);
3158 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3160 struct nfs4_exception exception = { };
3163 err = nfs4_handle_exception(NFS_SERVER(inode),
3164 _nfs4_proc_link(inode, dir, name),
3166 } while (exception.retry);
3170 struct nfs4_createdata {
3171 struct rpc_message msg;
3172 struct nfs4_create_arg arg;
3173 struct nfs4_create_res res;
3175 struct nfs_fattr fattr;
3178 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3179 struct qstr *name, struct iattr *sattr, u32 ftype)
3181 struct nfs4_createdata *data;
3183 data = kzalloc(sizeof(*data), GFP_KERNEL);
3185 struct nfs_server *server = NFS_SERVER(dir);
3187 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3188 data->msg.rpc_argp = &data->arg;
3189 data->msg.rpc_resp = &data->res;
3190 data->arg.dir_fh = NFS_FH(dir);
3191 data->arg.server = server;
3192 data->arg.name = name;
3193 data->arg.attrs = sattr;
3194 data->arg.ftype = ftype;
3195 data->arg.bitmask = server->attr_bitmask;
3196 data->res.server = server;
3197 data->res.fh = &data->fh;
3198 data->res.fattr = &data->fattr;
3199 nfs_fattr_init(data->res.fattr);
3204 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3206 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3207 &data->arg.seq_args, &data->res.seq_res, 1);
3209 update_changeattr(dir, &data->res.dir_cinfo);
3210 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
3215 static void nfs4_free_createdata(struct nfs4_createdata *data)
3220 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3221 struct page *page, unsigned int len, struct iattr *sattr)
3223 struct nfs4_createdata *data;
3224 int status = -ENAMETOOLONG;
3226 if (len > NFS4_MAXPATHLEN)
3230 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3234 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3235 data->arg.u.symlink.pages = &page;
3236 data->arg.u.symlink.len = len;
3238 status = nfs4_do_create(dir, dentry, data);
3240 nfs4_free_createdata(data);
3245 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3246 struct page *page, unsigned int len, struct iattr *sattr)
3248 struct nfs4_exception exception = { };
3251 err = nfs4_handle_exception(NFS_SERVER(dir),
3252 _nfs4_proc_symlink(dir, dentry, page,
3255 } while (exception.retry);
3259 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3260 struct iattr *sattr)
3262 struct nfs4_createdata *data;
3263 int status = -ENOMEM;
3265 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3269 status = nfs4_do_create(dir, dentry, data);
3271 nfs4_free_createdata(data);
3276 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3277 struct iattr *sattr)
3279 struct nfs4_exception exception = { };
3282 sattr->ia_mode &= ~current_umask();
3284 err = nfs4_handle_exception(NFS_SERVER(dir),
3285 _nfs4_proc_mkdir(dir, dentry, sattr),
3287 } while (exception.retry);
3291 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3292 u64 cookie, struct page **pages, unsigned int count, int plus)
3294 struct inode *dir = dentry->d_inode;
3295 struct nfs4_readdir_arg args = {
3300 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3303 struct nfs4_readdir_res res;
3304 struct rpc_message msg = {
3305 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3312 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3313 dentry->d_parent->d_name.name,
3314 dentry->d_name.name,
3315 (unsigned long long)cookie);
3316 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3317 res.pgbase = args.pgbase;
3318 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3320 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3321 status += args.pgbase;
3324 nfs_invalidate_atime(dir);
3326 dprintk("%s: returns %d\n", __func__, status);
3330 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3331 u64 cookie, struct page **pages, unsigned int count, int plus)
3333 struct nfs4_exception exception = { };
3336 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
3337 _nfs4_proc_readdir(dentry, cred, cookie,
3338 pages, count, plus),
3340 } while (exception.retry);
3344 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3345 struct iattr *sattr, dev_t rdev)
3347 struct nfs4_createdata *data;
3348 int mode = sattr->ia_mode;
3349 int status = -ENOMEM;
3351 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3356 data->arg.ftype = NF4FIFO;
3357 else if (S_ISBLK(mode)) {
3358 data->arg.ftype = NF4BLK;
3359 data->arg.u.device.specdata1 = MAJOR(rdev);
3360 data->arg.u.device.specdata2 = MINOR(rdev);
3362 else if (S_ISCHR(mode)) {
3363 data->arg.ftype = NF4CHR;
3364 data->arg.u.device.specdata1 = MAJOR(rdev);
3365 data->arg.u.device.specdata2 = MINOR(rdev);
3366 } else if (!S_ISSOCK(mode)) {
3371 status = nfs4_do_create(dir, dentry, data);
3373 nfs4_free_createdata(data);
3378 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3379 struct iattr *sattr, dev_t rdev)
3381 struct nfs4_exception exception = { };
3384 sattr->ia_mode &= ~current_umask();
3386 err = nfs4_handle_exception(NFS_SERVER(dir),
3387 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3389 } while (exception.retry);
3393 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3394 struct nfs_fsstat *fsstat)
3396 struct nfs4_statfs_arg args = {
3398 .bitmask = server->attr_bitmask,
3400 struct nfs4_statfs_res res = {
3403 struct rpc_message msg = {
3404 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3409 nfs_fattr_init(fsstat->fattr);
3410 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3413 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3415 struct nfs4_exception exception = { };
3418 err = nfs4_handle_exception(server,
3419 _nfs4_proc_statfs(server, fhandle, fsstat),
3421 } while (exception.retry);
3425 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3426 struct nfs_fsinfo *fsinfo)
3428 struct nfs4_fsinfo_arg args = {
3430 .bitmask = server->attr_bitmask,
3432 struct nfs4_fsinfo_res res = {
3435 struct rpc_message msg = {
3436 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3441 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3444 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3446 struct nfs4_exception exception = { };
3450 err = nfs4_handle_exception(server,
3451 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3453 } while (exception.retry);
3457 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3461 nfs_fattr_init(fsinfo->fattr);
3462 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3464 /* block layout checks this! */
3465 server->pnfs_blksize = fsinfo->blksize;
3466 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3472 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3473 struct nfs_pathconf *pathconf)
3475 struct nfs4_pathconf_arg args = {
3477 .bitmask = server->attr_bitmask,
3479 struct nfs4_pathconf_res res = {
3480 .pathconf = pathconf,
3482 struct rpc_message msg = {
3483 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3488 /* None of the pathconf attributes are mandatory to implement */
3489 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3490 memset(pathconf, 0, sizeof(*pathconf));
3494 nfs_fattr_init(pathconf->fattr);
3495 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3498 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3499 struct nfs_pathconf *pathconf)
3501 struct nfs4_exception exception = { };
3505 err = nfs4_handle_exception(server,
3506 _nfs4_proc_pathconf(server, fhandle, pathconf),
3508 } while (exception.retry);
3512 int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3513 const struct nfs_open_context *ctx,
3514 const struct nfs_lock_context *l_ctx,
3517 const struct nfs_lockowner *lockowner = NULL;
3520 lockowner = &l_ctx->lockowner;
3521 return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner);
3523 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid);
3525 static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
3526 const struct nfs_open_context *ctx,
3527 const struct nfs_lock_context *l_ctx,
3530 nfs4_stateid current_stateid;
3532 if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode))
3534 return nfs4_stateid_match(stateid, ¤t_stateid);
3537 static bool nfs4_error_stateid_expired(int err)
3540 case -NFS4ERR_DELEG_REVOKED:
3541 case -NFS4ERR_ADMIN_REVOKED:
3542 case -NFS4ERR_BAD_STATEID:
3543 case -NFS4ERR_STALE_STATEID:
3544 case -NFS4ERR_OLD_STATEID:
3545 case -NFS4ERR_OPENMODE:
3546 case -NFS4ERR_EXPIRED:
3552 void __nfs4_read_done_cb(struct nfs_read_data *data)
3554 nfs_invalidate_atime(data->header->inode);
3557 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3559 struct nfs_server *server = NFS_SERVER(data->header->inode);
3561 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3562 rpc_restart_call_prepare(task);
3566 __nfs4_read_done_cb(data);
3567 if (task->tk_status > 0)
3568 renew_lease(server, data->timestamp);
3572 static bool nfs4_read_stateid_changed(struct rpc_task *task,
3573 struct nfs_readargs *args)
3576 if (!nfs4_error_stateid_expired(task->tk_status) ||
3577 nfs4_stateid_is_current(&args->stateid,
3582 rpc_restart_call_prepare(task);
3586 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3589 dprintk("--> %s\n", __func__);
3591 if (!nfs4_sequence_done(task, &data->res.seq_res))
3593 if (nfs4_read_stateid_changed(task, &data->args))
3595 return data->read_done_cb ? data->read_done_cb(task, data) :
3596 nfs4_read_done_cb(task, data);
3599 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3601 data->timestamp = jiffies;
3602 data->read_done_cb = nfs4_read_done_cb;
3603 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3604 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3607 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3609 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3610 &data->args.seq_args,
3614 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3615 data->args.lock_context, FMODE_READ);
3618 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3620 struct inode *inode = data->header->inode;
3622 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3623 rpc_restart_call_prepare(task);
3626 if (task->tk_status >= 0) {
3627 renew_lease(NFS_SERVER(inode), data->timestamp);
3628 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
3633 static bool nfs4_write_stateid_changed(struct rpc_task *task,
3634 struct nfs_writeargs *args)
3637 if (!nfs4_error_stateid_expired(task->tk_status) ||
3638 nfs4_stateid_is_current(&args->stateid,
3643 rpc_restart_call_prepare(task);
3647 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3649 if (!nfs4_sequence_done(task, &data->res.seq_res))
3651 if (nfs4_write_stateid_changed(task, &data->args))
3653 return data->write_done_cb ? data->write_done_cb(task, data) :
3654 nfs4_write_done_cb(task, data);
3658 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
3660 const struct nfs_pgio_header *hdr = data->header;
3662 /* Don't request attributes for pNFS or O_DIRECT writes */
3663 if (data->ds_clp != NULL || hdr->dreq != NULL)
3665 /* Otherwise, request attributes if and only if we don't hold
3668 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
3671 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3673 struct nfs_server *server = NFS_SERVER(data->header->inode);
3675 if (!nfs4_write_need_cache_consistency_data(data)) {
3676 data->args.bitmask = NULL;
3677 data->res.fattr = NULL;
3679 data->args.bitmask = server->cache_consistency_bitmask;
3681 if (!data->write_done_cb)
3682 data->write_done_cb = nfs4_write_done_cb;
3683 data->res.server = server;
3684 data->timestamp = jiffies;
3686 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3687 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3690 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3692 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3693 &data->args.seq_args,
3697 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3698 data->args.lock_context, FMODE_WRITE);
3701 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
3703 nfs4_setup_sequence(NFS_SERVER(data->inode),
3704 &data->args.seq_args,
3709 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
3711 struct inode *inode = data->inode;
3713 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3714 rpc_restart_call_prepare(task);
3720 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
3722 if (!nfs4_sequence_done(task, &data->res.seq_res))
3724 return data->commit_done_cb(task, data);
3727 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
3729 struct nfs_server *server = NFS_SERVER(data->inode);
3731 if (data->commit_done_cb == NULL)
3732 data->commit_done_cb = nfs4_commit_done_cb;
3733 data->res.server = server;
3734 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3735 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3738 struct nfs4_renewdata {
3739 struct nfs_client *client;
3740 unsigned long timestamp;
3744 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3745 * standalone procedure for queueing an asynchronous RENEW.
3747 static void nfs4_renew_release(void *calldata)
3749 struct nfs4_renewdata *data = calldata;
3750 struct nfs_client *clp = data->client;
3752 if (atomic_read(&clp->cl_count) > 1)
3753 nfs4_schedule_state_renewal(clp);
3754 nfs_put_client(clp);
3758 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3760 struct nfs4_renewdata *data = calldata;
3761 struct nfs_client *clp = data->client;
3762 unsigned long timestamp = data->timestamp;
3764 if (task->tk_status < 0) {
3765 /* Unless we're shutting down, schedule state recovery! */
3766 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
3768 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
3769 nfs4_schedule_lease_recovery(clp);
3772 nfs4_schedule_path_down_recovery(clp);
3774 do_renew_lease(clp, timestamp);
3777 static const struct rpc_call_ops nfs4_renew_ops = {
3778 .rpc_call_done = nfs4_renew_done,
3779 .rpc_release = nfs4_renew_release,
3782 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
3784 struct rpc_message msg = {
3785 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3789 struct nfs4_renewdata *data;
3791 if (renew_flags == 0)
3793 if (!atomic_inc_not_zero(&clp->cl_count))
3795 data = kmalloc(sizeof(*data), GFP_NOFS);
3799 data->timestamp = jiffies;
3800 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3801 &nfs4_renew_ops, data);
3804 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3806 struct rpc_message msg = {
3807 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3811 unsigned long now = jiffies;
3814 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3817 do_renew_lease(clp, now);
3821 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3823 return (server->caps & NFS_CAP_ACLS)
3824 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3825 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3828 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
3829 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
3832 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
3834 static int buf_to_pages_noslab(const void *buf, size_t buflen,
3835 struct page **pages, unsigned int *pgbase)
3837 struct page *newpage, **spages;
3843 len = min_t(size_t, PAGE_SIZE, buflen);
3844 newpage = alloc_page(GFP_KERNEL);
3846 if (newpage == NULL)
3848 memcpy(page_address(newpage), buf, len);
3853 } while (buflen != 0);
3859 __free_page(spages[rc-1]);
3863 struct nfs4_cached_acl {
3869 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3871 struct nfs_inode *nfsi = NFS_I(inode);
3873 spin_lock(&inode->i_lock);
3874 kfree(nfsi->nfs4_acl);
3875 nfsi->nfs4_acl = acl;
3876 spin_unlock(&inode->i_lock);
3879 static void nfs4_zap_acl_attr(struct inode *inode)
3881 nfs4_set_cached_acl(inode, NULL);
3884 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3886 struct nfs_inode *nfsi = NFS_I(inode);
3887 struct nfs4_cached_acl *acl;
3890 spin_lock(&inode->i_lock);
3891 acl = nfsi->nfs4_acl;
3894 if (buf == NULL) /* user is just asking for length */
3896 if (acl->cached == 0)
3898 ret = -ERANGE; /* see getxattr(2) man page */
3899 if (acl->len > buflen)
3901 memcpy(buf, acl->data, acl->len);
3905 spin_unlock(&inode->i_lock);
3909 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
3911 struct nfs4_cached_acl *acl;
3912 size_t buflen = sizeof(*acl) + acl_len;
3914 if (buflen <= PAGE_SIZE) {
3915 acl = kmalloc(buflen, GFP_KERNEL);
3919 _copy_from_pages(acl->data, pages, pgbase, acl_len);
3921 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3928 nfs4_set_cached_acl(inode, acl);
3932 * The getxattr API returns the required buffer length when called with a
3933 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
3934 * the required buf. On a NULL buf, we send a page of data to the server
3935 * guessing that the ACL request can be serviced by a page. If so, we cache
3936 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
3937 * the cache. If not so, we throw away the page, and cache the required
3938 * length. The next getxattr call will then produce another round trip to
3939 * the server, this time with the input buf of the required size.
3941 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3943 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
3944 struct nfs_getaclargs args = {
3945 .fh = NFS_FH(inode),
3949 struct nfs_getaclres res = {
3952 struct rpc_message msg = {
3953 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3957 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
3958 int ret = -ENOMEM, i;
3960 /* As long as we're doing a round trip to the server anyway,
3961 * let's be prepared for a page of acl data. */
3964 if (npages > ARRAY_SIZE(pages))
3967 for (i = 0; i < npages; i++) {
3968 pages[i] = alloc_page(GFP_KERNEL);
3973 /* for decoding across pages */
3974 res.acl_scratch = alloc_page(GFP_KERNEL);
3975 if (!res.acl_scratch)
3978 args.acl_len = npages * PAGE_SIZE;
3979 args.acl_pgbase = 0;
3981 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3982 __func__, buf, buflen, npages, args.acl_len);
3983 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
3984 &msg, &args.seq_args, &res.seq_res, 0);
3988 /* Handle the case where the passed-in buffer is too short */
3989 if (res.acl_flags & NFS4_ACL_TRUNC) {
3990 /* Did the user only issue a request for the acl length? */
3996 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
3998 if (res.acl_len > buflen) {
4002 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
4007 for (i = 0; i < npages; i++)
4009 __free_page(pages[i]);
4010 if (res.acl_scratch)
4011 __free_page(res.acl_scratch);
4015 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4017 struct nfs4_exception exception = { };
4020 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
4023 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
4024 } while (exception.retry);
4028 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
4030 struct nfs_server *server = NFS_SERVER(inode);
4033 if (!nfs4_server_supports_acls(server))
4035 ret = nfs_revalidate_inode(server, inode);
4038 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
4039 nfs_zap_acl_cache(inode);
4040 ret = nfs4_read_cached_acl(inode, buf, buflen);
4042 /* -ENOENT is returned if there is no ACL or if there is an ACL
4043 * but no cached acl data, just the acl length */
4045 return nfs4_get_acl_uncached(inode, buf, buflen);
4048 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4050 struct nfs_server *server = NFS_SERVER(inode);
4051 struct page *pages[NFS4ACL_MAXPAGES];
4052 struct nfs_setaclargs arg = {
4053 .fh = NFS_FH(inode),
4057 struct nfs_setaclres res;
4058 struct rpc_message msg = {
4059 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
4063 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4066 if (!nfs4_server_supports_acls(server))
4068 if (npages > ARRAY_SIZE(pages))
4070 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
4073 nfs4_inode_return_delegation(inode);
4074 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4077 * Free each page after tx, so the only ref left is
4078 * held by the network stack
4081 put_page(pages[i-1]);
4084 * Acl update can result in inode attribute update.
4085 * so mark the attribute cache invalid.
4087 spin_lock(&inode->i_lock);
4088 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
4089 spin_unlock(&inode->i_lock);
4090 nfs_access_zap_cache(inode);
4091 nfs_zap_acl_cache(inode);
4095 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4097 struct nfs4_exception exception = { };
4100 err = nfs4_handle_exception(NFS_SERVER(inode),
4101 __nfs4_proc_set_acl(inode, buf, buflen),
4103 } while (exception.retry);
4108 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
4110 struct nfs_client *clp = server->nfs_client;
4112 if (task->tk_status >= 0)
4114 switch(task->tk_status) {
4115 case -NFS4ERR_DELEG_REVOKED:
4116 case -NFS4ERR_ADMIN_REVOKED:
4117 case -NFS4ERR_BAD_STATEID:
4120 nfs_remove_bad_delegation(state->inode);
4121 case -NFS4ERR_OPENMODE:
4124 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4125 goto stateid_invalid;
4126 goto wait_on_recovery;
4127 case -NFS4ERR_EXPIRED:
4128 if (state != NULL) {
4129 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4130 goto stateid_invalid;
4132 case -NFS4ERR_STALE_STATEID:
4133 case -NFS4ERR_STALE_CLIENTID:
4134 nfs4_schedule_lease_recovery(clp);
4135 goto wait_on_recovery;
4136 #if defined(CONFIG_NFS_V4_1)
4137 case -NFS4ERR_BADSESSION:
4138 case -NFS4ERR_BADSLOT:
4139 case -NFS4ERR_BAD_HIGH_SLOT:
4140 case -NFS4ERR_DEADSESSION:
4141 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4142 case -NFS4ERR_SEQ_FALSE_RETRY:
4143 case -NFS4ERR_SEQ_MISORDERED:
4144 dprintk("%s ERROR %d, Reset session\n", __func__,
4146 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
4147 task->tk_status = 0;
4149 #endif /* CONFIG_NFS_V4_1 */
4150 case -NFS4ERR_DELAY:
4151 nfs_inc_server_stats(server, NFSIOS_DELAY);
4152 case -NFS4ERR_GRACE:
4153 rpc_delay(task, NFS4_POLL_RETRY_MAX);
4154 task->tk_status = 0;
4156 case -NFS4ERR_RETRY_UNCACHED_REP:
4157 case -NFS4ERR_OLD_STATEID:
4158 task->tk_status = 0;
4161 task->tk_status = nfs4_map_errors(task->tk_status);
4164 task->tk_status = -EIO;
4167 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
4168 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4169 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
4170 task->tk_status = 0;
4174 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
4175 nfs4_verifier *bootverf)
4179 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4180 /* An impossible timestamp guarantees this value
4181 * will never match a generated boot time. */
4183 verf[1] = (__be32)(NSEC_PER_SEC + 1);
4185 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4186 verf[0] = (__be32)nn->boot_time.tv_sec;
4187 verf[1] = (__be32)nn->boot_time.tv_nsec;
4189 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4193 nfs4_init_nonuniform_client_string(const struct nfs_client *clp,
4194 char *buf, size_t len)
4196 unsigned int result;
4199 result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s",
4201 rpc_peeraddr2str(clp->cl_rpcclient,
4203 rpc_peeraddr2str(clp->cl_rpcclient,
4204 RPC_DISPLAY_PROTO));
4210 nfs4_init_uniform_client_string(const struct nfs_client *clp,
4211 char *buf, size_t len)
4213 char *nodename = clp->cl_rpcclient->cl_nodename;
4215 if (nfs4_client_id_uniquifier[0] != '\0')
4216 nodename = nfs4_client_id_uniquifier;
4217 return scnprintf(buf, len, "Linux NFSv%u.%u %s",
4218 clp->rpc_ops->version, clp->cl_minorversion,
4223 * nfs4_proc_setclientid - Negotiate client ID
4224 * @clp: state data structure
4225 * @program: RPC program for NFSv4 callback service
4226 * @port: IP port number for NFS4 callback service
4227 * @cred: RPC credential to use for this call
4228 * @res: where to place the result
4230 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4232 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4233 unsigned short port, struct rpc_cred *cred,
4234 struct nfs4_setclientid_res *res)
4236 nfs4_verifier sc_verifier;
4237 struct nfs4_setclientid setclientid = {
4238 .sc_verifier = &sc_verifier,
4240 .sc_cb_ident = clp->cl_cb_ident,
4242 struct rpc_message msg = {
4243 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4244 .rpc_argp = &setclientid,
4250 /* nfs_client_id4 */
4251 nfs4_init_boot_verifier(clp, &sc_verifier);
4252 if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
4253 setclientid.sc_name_len =
4254 nfs4_init_uniform_client_string(clp,
4255 setclientid.sc_name,
4256 sizeof(setclientid.sc_name));
4258 setclientid.sc_name_len =
4259 nfs4_init_nonuniform_client_string(clp,
4260 setclientid.sc_name,
4261 sizeof(setclientid.sc_name));
4264 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4265 sizeof(setclientid.sc_netid),
4266 rpc_peeraddr2str(clp->cl_rpcclient,
4267 RPC_DISPLAY_NETID));
4269 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4270 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4271 clp->cl_ipaddr, port >> 8, port & 255);
4273 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4274 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4275 setclientid.sc_name_len, setclientid.sc_name);
4276 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4277 dprintk("NFS reply setclientid: %d\n", status);
4282 * nfs4_proc_setclientid_confirm - Confirm client ID
4283 * @clp: state data structure
4284 * @res: result of a previous SETCLIENTID
4285 * @cred: RPC credential to use for this call
4287 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4289 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4290 struct nfs4_setclientid_res *arg,
4291 struct rpc_cred *cred)
4293 struct nfs_fsinfo fsinfo;
4294 struct rpc_message msg = {
4295 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4297 .rpc_resp = &fsinfo,
4303 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4304 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4307 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4309 spin_lock(&clp->cl_lock);
4310 clp->cl_lease_time = fsinfo.lease_time * HZ;
4311 clp->cl_last_renewal = now;
4312 spin_unlock(&clp->cl_lock);
4314 dprintk("NFS reply setclientid_confirm: %d\n", status);
4318 struct nfs4_delegreturndata {
4319 struct nfs4_delegreturnargs args;
4320 struct nfs4_delegreturnres res;
4322 nfs4_stateid stateid;
4323 unsigned long timestamp;
4324 struct nfs_fattr fattr;
4328 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4330 struct nfs4_delegreturndata *data = calldata;
4332 if (!nfs4_sequence_done(task, &data->res.seq_res))
4335 switch (task->tk_status) {
4336 case -NFS4ERR_STALE_STATEID:
4337 case -NFS4ERR_EXPIRED:
4339 renew_lease(data->res.server, data->timestamp);
4342 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4344 rpc_restart_call_prepare(task);
4348 data->rpc_status = task->tk_status;
4351 static void nfs4_delegreturn_release(void *calldata)
4356 #if defined(CONFIG_NFS_V4_1)
4357 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4359 struct nfs4_delegreturndata *d_data;
4361 d_data = (struct nfs4_delegreturndata *)data;
4363 nfs4_setup_sequence(d_data->res.server,
4364 &d_data->args.seq_args,
4365 &d_data->res.seq_res,
4368 #endif /* CONFIG_NFS_V4_1 */
4370 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4371 #if defined(CONFIG_NFS_V4_1)
4372 .rpc_call_prepare = nfs4_delegreturn_prepare,
4373 #endif /* CONFIG_NFS_V4_1 */
4374 .rpc_call_done = nfs4_delegreturn_done,
4375 .rpc_release = nfs4_delegreturn_release,
4378 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4380 struct nfs4_delegreturndata *data;
4381 struct nfs_server *server = NFS_SERVER(inode);
4382 struct rpc_task *task;
4383 struct rpc_message msg = {
4384 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
4387 struct rpc_task_setup task_setup_data = {
4388 .rpc_client = server->client,
4389 .rpc_message = &msg,
4390 .callback_ops = &nfs4_delegreturn_ops,
4391 .flags = RPC_TASK_ASYNC,
4395 data = kzalloc(sizeof(*data), GFP_NOFS);
4398 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4399 data->args.fhandle = &data->fh;
4400 data->args.stateid = &data->stateid;
4401 data->args.bitmask = server->cache_consistency_bitmask;
4402 nfs_copy_fh(&data->fh, NFS_FH(inode));
4403 nfs4_stateid_copy(&data->stateid, stateid);
4404 data->res.fattr = &data->fattr;
4405 data->res.server = server;
4406 nfs_fattr_init(data->res.fattr);
4407 data->timestamp = jiffies;
4408 data->rpc_status = 0;
4410 task_setup_data.callback_data = data;
4411 msg.rpc_argp = &data->args;
4412 msg.rpc_resp = &data->res;
4413 task = rpc_run_task(&task_setup_data);
4415 return PTR_ERR(task);
4418 status = nfs4_wait_for_completion_rpc_task(task);
4421 status = data->rpc_status;
4423 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4425 nfs_refresh_inode(inode, &data->fattr);
4431 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4433 struct nfs_server *server = NFS_SERVER(inode);
4434 struct nfs4_exception exception = { };
4437 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4439 case -NFS4ERR_STALE_STATEID:
4440 case -NFS4ERR_EXPIRED:
4444 err = nfs4_handle_exception(server, err, &exception);
4445 } while (exception.retry);
4449 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4450 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4453 * sleep, with exponential backoff, and retry the LOCK operation.
4455 static unsigned long
4456 nfs4_set_lock_task_retry(unsigned long timeout)
4458 freezable_schedule_timeout_killable(timeout);
4460 if (timeout > NFS4_LOCK_MAXTIMEOUT)
4461 return NFS4_LOCK_MAXTIMEOUT;
4465 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4467 struct inode *inode = state->inode;
4468 struct nfs_server *server = NFS_SERVER(inode);
4469 struct nfs_client *clp = server->nfs_client;
4470 struct nfs_lockt_args arg = {
4471 .fh = NFS_FH(inode),
4474 struct nfs_lockt_res res = {
4477 struct rpc_message msg = {
4478 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
4481 .rpc_cred = state->owner->so_cred,
4483 struct nfs4_lock_state *lsp;
4486 arg.lock_owner.clientid = clp->cl_clientid;
4487 status = nfs4_set_lock_state(state, request);
4490 lsp = request->fl_u.nfs4_fl.owner;
4491 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4492 arg.lock_owner.s_dev = server->s_dev;
4493 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4496 request->fl_type = F_UNLCK;
4498 case -NFS4ERR_DENIED:
4501 request->fl_ops->fl_release_private(request);
4506 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4508 struct nfs4_exception exception = { };
4512 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4513 _nfs4_proc_getlk(state, cmd, request),
4515 } while (exception.retry);
4519 static int do_vfs_lock(struct file *file, struct file_lock *fl)
4522 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
4524 res = posix_lock_file_wait(file, fl);
4527 res = flock_lock_file_wait(file, fl);
4535 struct nfs4_unlockdata {
4536 struct nfs_locku_args arg;
4537 struct nfs_locku_res res;
4538 struct nfs4_lock_state *lsp;
4539 struct nfs_open_context *ctx;
4540 struct file_lock fl;
4541 const struct nfs_server *server;
4542 unsigned long timestamp;
4545 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
4546 struct nfs_open_context *ctx,
4547 struct nfs4_lock_state *lsp,
4548 struct nfs_seqid *seqid)
4550 struct nfs4_unlockdata *p;
4551 struct inode *inode = lsp->ls_state->inode;
4553 p = kzalloc(sizeof(*p), GFP_NOFS);
4556 p->arg.fh = NFS_FH(inode);
4558 p->arg.seqid = seqid;
4559 p->res.seqid = seqid;
4560 p->arg.stateid = &lsp->ls_stateid;
4562 atomic_inc(&lsp->ls_count);
4563 /* Ensure we don't close file until we're done freeing locks! */
4564 p->ctx = get_nfs_open_context(ctx);
4565 memcpy(&p->fl, fl, sizeof(p->fl));
4566 p->server = NFS_SERVER(inode);
4570 static void nfs4_locku_release_calldata(void *data)
4572 struct nfs4_unlockdata *calldata = data;
4573 nfs_free_seqid(calldata->arg.seqid);
4574 nfs4_put_lock_state(calldata->lsp);
4575 put_nfs_open_context(calldata->ctx);
4579 static void nfs4_locku_done(struct rpc_task *task, void *data)
4581 struct nfs4_unlockdata *calldata = data;
4583 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
4585 switch (task->tk_status) {
4587 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4588 &calldata->res.stateid);
4589 renew_lease(calldata->server, calldata->timestamp);
4591 case -NFS4ERR_BAD_STATEID:
4592 case -NFS4ERR_OLD_STATEID:
4593 case -NFS4ERR_STALE_STATEID:
4594 case -NFS4ERR_EXPIRED:
4597 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
4598 rpc_restart_call_prepare(task);
4600 nfs_release_seqid(calldata->arg.seqid);
4603 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4605 struct nfs4_unlockdata *calldata = data;
4607 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
4609 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
4610 /* Note: exit _without_ running nfs4_locku_done */
4613 calldata->timestamp = jiffies;
4614 if (nfs4_setup_sequence(calldata->server,
4615 &calldata->arg.seq_args,
4616 &calldata->res.seq_res,
4618 nfs_release_seqid(calldata->arg.seqid);
4621 task->tk_action = NULL;
4623 nfs4_sequence_done(task, &calldata->res.seq_res);
4626 static const struct rpc_call_ops nfs4_locku_ops = {
4627 .rpc_call_prepare = nfs4_locku_prepare,
4628 .rpc_call_done = nfs4_locku_done,
4629 .rpc_release = nfs4_locku_release_calldata,
4632 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4633 struct nfs_open_context *ctx,
4634 struct nfs4_lock_state *lsp,
4635 struct nfs_seqid *seqid)
4637 struct nfs4_unlockdata *data;
4638 struct rpc_message msg = {
4639 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
4640 .rpc_cred = ctx->cred,
4642 struct rpc_task_setup task_setup_data = {
4643 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4644 .rpc_message = &msg,
4645 .callback_ops = &nfs4_locku_ops,
4646 .workqueue = nfsiod_workqueue,
4647 .flags = RPC_TASK_ASYNC,
4650 /* Ensure this is an unlock - when canceling a lock, the
4651 * canceled lock is passed in, and it won't be an unlock.
4653 fl->fl_type = F_UNLCK;
4655 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4657 nfs_free_seqid(seqid);
4658 return ERR_PTR(-ENOMEM);
4661 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4662 msg.rpc_argp = &data->arg;
4663 msg.rpc_resp = &data->res;
4664 task_setup_data.callback_data = data;
4665 return rpc_run_task(&task_setup_data);
4668 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
4670 struct inode *inode = state->inode;
4671 struct nfs4_state_owner *sp = state->owner;
4672 struct nfs_inode *nfsi = NFS_I(inode);
4673 struct nfs_seqid *seqid;
4674 struct nfs4_lock_state *lsp;
4675 struct rpc_task *task;
4677 unsigned char fl_flags = request->fl_flags;
4679 status = nfs4_set_lock_state(state, request);
4680 /* Unlock _before_ we do the RPC call */
4681 request->fl_flags |= FL_EXISTS;
4682 /* Exclude nfs_delegation_claim_locks() */
4683 mutex_lock(&sp->so_delegreturn_mutex);
4684 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
4685 down_read(&nfsi->rwsem);
4686 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
4687 up_read(&nfsi->rwsem);
4688 mutex_unlock(&sp->so_delegreturn_mutex);
4691 up_read(&nfsi->rwsem);
4692 mutex_unlock(&sp->so_delegreturn_mutex);
4695 /* Is this a delegated lock? */
4696 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4698 lsp = request->fl_u.nfs4_fl.owner;
4699 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4703 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4704 status = PTR_ERR(task);
4707 status = nfs4_wait_for_completion_rpc_task(task);
4710 request->fl_flags = fl_flags;
4714 struct nfs4_lockdata {
4715 struct nfs_lock_args arg;
4716 struct nfs_lock_res res;
4717 struct nfs4_lock_state *lsp;
4718 struct nfs_open_context *ctx;
4719 struct file_lock fl;
4720 unsigned long timestamp;
4723 struct nfs_server *server;
4726 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4727 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4730 struct nfs4_lockdata *p;
4731 struct inode *inode = lsp->ls_state->inode;
4732 struct nfs_server *server = NFS_SERVER(inode);
4734 p = kzalloc(sizeof(*p), gfp_mask);
4738 p->arg.fh = NFS_FH(inode);
4740 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4741 if (p->arg.open_seqid == NULL)
4743 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4744 if (p->arg.lock_seqid == NULL)
4745 goto out_free_seqid;
4746 p->arg.lock_stateid = &lsp->ls_stateid;
4747 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4748 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4749 p->arg.lock_owner.s_dev = server->s_dev;
4750 p->res.lock_seqid = p->arg.lock_seqid;
4753 atomic_inc(&lsp->ls_count);
4754 p->ctx = get_nfs_open_context(ctx);
4755 memcpy(&p->fl, fl, sizeof(p->fl));
4758 nfs_free_seqid(p->arg.open_seqid);
4764 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4766 struct nfs4_lockdata *data = calldata;
4767 struct nfs4_state *state = data->lsp->ls_state;
4769 dprintk("%s: begin!\n", __func__);
4770 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4772 /* Do we need to do an open_to_lock_owner? */
4773 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4774 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) {
4775 goto out_release_lock_seqid;
4777 data->arg.open_stateid = &state->stateid;
4778 data->arg.new_lock_owner = 1;
4779 data->res.open_seqid = data->arg.open_seqid;
4781 data->arg.new_lock_owner = 0;
4782 if (!nfs4_valid_open_stateid(state)) {
4783 data->rpc_status = -EBADF;
4784 task->tk_action = NULL;
4785 goto out_release_open_seqid;
4787 data->timestamp = jiffies;
4788 if (nfs4_setup_sequence(data->server,
4789 &data->arg.seq_args,
4793 out_release_open_seqid:
4794 nfs_release_seqid(data->arg.open_seqid);
4795 out_release_lock_seqid:
4796 nfs_release_seqid(data->arg.lock_seqid);
4798 nfs4_sequence_done(task, &data->res.seq_res);
4799 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4802 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4804 struct nfs4_lockdata *data = calldata;
4806 dprintk("%s: begin!\n", __func__);
4808 if (!nfs4_sequence_done(task, &data->res.seq_res))
4811 data->rpc_status = task->tk_status;
4812 if (data->arg.new_lock_owner != 0) {
4813 if (data->rpc_status == 0)
4814 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4818 if (data->rpc_status == 0) {
4819 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4820 set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags);
4821 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4824 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4827 static void nfs4_lock_release(void *calldata)
4829 struct nfs4_lockdata *data = calldata;
4831 dprintk("%s: begin!\n", __func__);
4832 nfs_free_seqid(data->arg.open_seqid);
4833 if (data->cancelled != 0) {
4834 struct rpc_task *task;
4835 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4836 data->arg.lock_seqid);
4838 rpc_put_task_async(task);
4839 dprintk("%s: cancelling lock!\n", __func__);
4841 nfs_free_seqid(data->arg.lock_seqid);
4842 nfs4_put_lock_state(data->lsp);
4843 put_nfs_open_context(data->ctx);
4845 dprintk("%s: done!\n", __func__);
4848 static const struct rpc_call_ops nfs4_lock_ops = {
4849 .rpc_call_prepare = nfs4_lock_prepare,
4850 .rpc_call_done = nfs4_lock_done,
4851 .rpc_release = nfs4_lock_release,
4854 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4857 case -NFS4ERR_ADMIN_REVOKED:
4858 case -NFS4ERR_BAD_STATEID:
4859 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4860 if (new_lock_owner != 0 ||
4861 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
4862 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
4864 case -NFS4ERR_STALE_STATEID:
4865 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4866 case -NFS4ERR_EXPIRED:
4867 nfs4_schedule_lease_recovery(server->nfs_client);
4871 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4873 struct nfs4_lockdata *data;
4874 struct rpc_task *task;
4875 struct rpc_message msg = {
4876 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4877 .rpc_cred = state->owner->so_cred,
4879 struct rpc_task_setup task_setup_data = {
4880 .rpc_client = NFS_CLIENT(state->inode),
4881 .rpc_message = &msg,
4882 .callback_ops = &nfs4_lock_ops,
4883 .workqueue = nfsiod_workqueue,
4884 .flags = RPC_TASK_ASYNC,
4888 dprintk("%s: begin!\n", __func__);
4889 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4890 fl->fl_u.nfs4_fl.owner,
4891 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4895 data->arg.block = 1;
4896 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4897 msg.rpc_argp = &data->arg;
4898 msg.rpc_resp = &data->res;
4899 task_setup_data.callback_data = data;
4900 if (recovery_type > NFS_LOCK_NEW) {
4901 if (recovery_type == NFS_LOCK_RECLAIM)
4902 data->arg.reclaim = NFS_LOCK_RECLAIM;
4903 nfs4_set_sequence_privileged(&data->arg.seq_args);
4905 task = rpc_run_task(&task_setup_data);
4907 return PTR_ERR(task);
4908 ret = nfs4_wait_for_completion_rpc_task(task);
4910 ret = data->rpc_status;
4912 nfs4_handle_setlk_error(data->server, data->lsp,
4913 data->arg.new_lock_owner, ret);
4915 data->cancelled = 1;
4917 dprintk("%s: done, ret = %d!\n", __func__, ret);
4921 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4923 struct nfs_server *server = NFS_SERVER(state->inode);
4924 struct nfs4_exception exception = {
4925 .inode = state->inode,
4930 /* Cache the lock if possible... */
4931 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4933 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4934 if (err != -NFS4ERR_DELAY)
4936 nfs4_handle_exception(server, err, &exception);
4937 } while (exception.retry);
4941 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4943 struct nfs_server *server = NFS_SERVER(state->inode);
4944 struct nfs4_exception exception = {
4945 .inode = state->inode,
4949 err = nfs4_set_lock_state(state, request);
4953 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4955 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4959 case -NFS4ERR_GRACE:
4960 case -NFS4ERR_DELAY:
4961 nfs4_handle_exception(server, err, &exception);
4964 } while (exception.retry);
4969 #if defined(CONFIG_NFS_V4_1)
4971 * nfs41_check_expired_locks - possibly free a lock stateid
4973 * @state: NFSv4 state for an inode
4975 * Returns NFS_OK if recovery for this stateid is now finished.
4976 * Otherwise a negative NFS4ERR value is returned.
4978 static int nfs41_check_expired_locks(struct nfs4_state *state)
4980 int status, ret = -NFS4ERR_BAD_STATEID;
4981 struct nfs4_lock_state *lsp;
4982 struct nfs_server *server = NFS_SERVER(state->inode);
4984 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4985 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
4986 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4987 if (status != NFS_OK) {
4988 /* Free the stateid unless the server
4989 * informs us the stateid is unrecognized. */
4990 if (status != -NFS4ERR_BAD_STATEID)
4991 nfs41_free_stateid(server,
4993 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
5002 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
5004 int status = NFS_OK;
5006 if (test_bit(LK_STATE_IN_USE, &state->flags))
5007 status = nfs41_check_expired_locks(state);
5008 if (status != NFS_OK)
5009 status = nfs4_lock_expired(state, request);
5014 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5016 struct nfs4_state_owner *sp = state->owner;
5017 struct nfs_inode *nfsi = NFS_I(state->inode);
5018 unsigned char fl_flags = request->fl_flags;
5020 int status = -ENOLCK;
5022 if ((fl_flags & FL_POSIX) &&
5023 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
5025 /* Is this a delegated open? */
5026 status = nfs4_set_lock_state(state, request);
5029 request->fl_flags |= FL_ACCESS;
5030 status = do_vfs_lock(request->fl_file, request);
5033 down_read(&nfsi->rwsem);
5034 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
5035 /* Yes: cache locks! */
5036 /* ...but avoid races with delegation recall... */
5037 request->fl_flags = fl_flags & ~FL_SLEEP;
5038 status = do_vfs_lock(request->fl_file, request);
5041 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
5042 up_read(&nfsi->rwsem);
5043 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
5046 down_read(&nfsi->rwsem);
5047 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
5048 status = -NFS4ERR_DELAY;
5051 /* Note: we always want to sleep here! */
5052 request->fl_flags = fl_flags | FL_SLEEP;
5053 if (do_vfs_lock(request->fl_file, request) < 0)
5054 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
5055 "manager!\n", __func__);
5057 up_read(&nfsi->rwsem);
5059 request->fl_flags = fl_flags;
5063 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5065 struct nfs4_exception exception = {
5067 .inode = state->inode,
5072 err = _nfs4_proc_setlk(state, cmd, request);
5073 if (err == -NFS4ERR_DENIED)
5075 err = nfs4_handle_exception(NFS_SERVER(state->inode),
5077 } while (exception.retry);
5082 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
5084 struct nfs_open_context *ctx;
5085 struct nfs4_state *state;
5086 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
5089 /* verify open state */
5090 ctx = nfs_file_open_context(filp);
5093 if (request->fl_start < 0 || request->fl_end < 0)
5096 if (IS_GETLK(cmd)) {
5098 return nfs4_proc_getlk(state, F_GETLK, request);
5102 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
5105 if (request->fl_type == F_UNLCK) {
5107 return nfs4_proc_unlck(state, cmd, request);
5114 * Don't rely on the VFS having checked the file open mode,
5115 * since it won't do this for flock() locks.
5117 switch (request->fl_type) {
5119 if (!(filp->f_mode & FMODE_READ))
5123 if (!(filp->f_mode & FMODE_WRITE))
5128 status = nfs4_proc_setlk(state, cmd, request);
5129 if ((status != -EAGAIN) || IS_SETLK(cmd))
5131 timeout = nfs4_set_lock_task_retry(timeout);
5132 status = -ERESTARTSYS;
5135 } while(status < 0);
5139 int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid)
5141 struct nfs_server *server = NFS_SERVER(state->inode);
5144 err = nfs4_set_lock_state(state, fl);
5147 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
5148 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
5151 struct nfs_release_lockowner_data {
5152 struct nfs4_lock_state *lsp;
5153 struct nfs_server *server;
5154 struct nfs_release_lockowner_args args;
5157 static void nfs4_release_lockowner_release(void *calldata)
5159 struct nfs_release_lockowner_data *data = calldata;
5160 nfs4_free_lock_state(data->server, data->lsp);
5164 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5165 .rpc_release = nfs4_release_lockowner_release,
5168 int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
5170 struct nfs_server *server = lsp->ls_state->owner->so_server;
5171 struct nfs_release_lockowner_data *data;
5172 struct rpc_message msg = {
5173 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5176 if (server->nfs_client->cl_mvops->minor_version != 0)
5178 data = kmalloc(sizeof(*data), GFP_NOFS);
5182 data->server = server;
5183 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5184 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5185 data->args.lock_owner.s_dev = server->s_dev;
5186 msg.rpc_argp = &data->args;
5187 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5191 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5193 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5194 const void *buf, size_t buflen,
5195 int flags, int type)
5197 if (strcmp(key, "") != 0)
5200 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5203 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5204 void *buf, size_t buflen, int type)
5206 if (strcmp(key, "") != 0)
5209 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5212 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5213 size_t list_len, const char *name,
5214 size_t name_len, int type)
5216 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5218 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5221 if (list && len <= list_len)
5222 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5227 * nfs_fhget will use either the mounted_on_fileid or the fileid
5229 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5231 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5232 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5233 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5234 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5237 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5238 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5239 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5243 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5244 const struct qstr *name,
5245 struct nfs4_fs_locations *fs_locations,
5248 struct nfs_server *server = NFS_SERVER(dir);
5250 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5252 struct nfs4_fs_locations_arg args = {
5253 .dir_fh = NFS_FH(dir),
5258 struct nfs4_fs_locations_res res = {
5259 .fs_locations = fs_locations,
5261 struct rpc_message msg = {
5262 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5268 dprintk("%s: start\n", __func__);
5270 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5271 * is not supported */
5272 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5273 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5275 bitmask[0] |= FATTR4_WORD0_FILEID;
5277 nfs_fattr_init(&fs_locations->fattr);
5278 fs_locations->server = server;
5279 fs_locations->nlocations = 0;
5280 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5281 dprintk("%s: returned status = %d\n", __func__, status);
5285 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5286 const struct qstr *name,
5287 struct nfs4_fs_locations *fs_locations,
5290 struct nfs4_exception exception = { };
5293 err = nfs4_handle_exception(NFS_SERVER(dir),
5294 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5296 } while (exception.retry);
5300 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
5303 struct nfs4_secinfo_arg args = {
5304 .dir_fh = NFS_FH(dir),
5307 struct nfs4_secinfo_res res = {
5310 struct rpc_message msg = {
5311 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
5316 dprintk("NFS call secinfo %s\n", name->name);
5317 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
5318 dprintk("NFS reply secinfo: %d\n", status);
5322 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
5323 struct nfs4_secinfo_flavors *flavors)
5325 struct nfs4_exception exception = { };
5328 err = nfs4_handle_exception(NFS_SERVER(dir),
5329 _nfs4_proc_secinfo(dir, name, flavors),
5331 } while (exception.retry);
5335 #ifdef CONFIG_NFS_V4_1
5337 * Check the exchange flags returned by the server for invalid flags, having
5338 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5341 static int nfs4_check_cl_exchange_flags(u32 flags)
5343 if (flags & ~EXCHGID4_FLAG_MASK_R)
5345 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
5346 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
5348 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
5352 return -NFS4ERR_INVAL;
5356 nfs41_same_server_scope(struct nfs41_server_scope *a,
5357 struct nfs41_server_scope *b)
5359 if (a->server_scope_sz == b->server_scope_sz &&
5360 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5367 * nfs4_proc_bind_conn_to_session()
5369 * The 4.1 client currently uses the same TCP connection for the
5370 * fore and backchannel.
5372 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
5375 struct nfs41_bind_conn_to_session_res res;
5376 struct rpc_message msg = {
5378 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
5384 dprintk("--> %s\n", __func__);
5386 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5387 if (unlikely(res.session == NULL)) {
5392 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5394 if (memcmp(res.session->sess_id.data,
5395 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
5396 dprintk("NFS: %s: Session ID mismatch\n", __func__);
5400 if (res.dir != NFS4_CDFS4_BOTH) {
5401 dprintk("NFS: %s: Unexpected direction from server\n",
5406 if (res.use_conn_in_rdma_mode) {
5407 dprintk("NFS: %s: Server returned RDMA mode = true\n",
5416 dprintk("<-- %s status= %d\n", __func__, status);
5421 * nfs4_proc_exchange_id()
5423 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5425 * Since the clientid has expired, all compounds using sessions
5426 * associated with the stale clientid will be returning
5427 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
5428 * be in some phase of session reset.
5430 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
5432 nfs4_verifier verifier;
5433 struct nfs41_exchange_id_args args = {
5434 .verifier = &verifier,
5436 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
5438 struct nfs41_exchange_id_res res = {
5442 struct rpc_message msg = {
5443 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
5449 nfs4_init_boot_verifier(clp, &verifier);
5450 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
5452 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
5453 clp->cl_rpcclient->cl_auth->au_ops->au_name,
5454 args.id_len, args.id);
5456 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
5458 if (unlikely(res.server_owner == NULL)) {
5463 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
5465 if (unlikely(res.server_scope == NULL)) {
5467 goto out_server_owner;
5470 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
5471 if (unlikely(res.impl_id == NULL)) {
5473 goto out_server_scope;
5476 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5478 status = nfs4_check_cl_exchange_flags(res.flags);
5481 clp->cl_clientid = res.clientid;
5482 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
5483 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
5484 clp->cl_seqid = res.seqid;
5486 kfree(clp->cl_serverowner);
5487 clp->cl_serverowner = res.server_owner;
5488 res.server_owner = NULL;
5490 /* use the most recent implementation id */
5491 kfree(clp->cl_implid);
5492 clp->cl_implid = res.impl_id;
5494 if (clp->cl_serverscope != NULL &&
5495 !nfs41_same_server_scope(clp->cl_serverscope,
5496 res.server_scope)) {
5497 dprintk("%s: server_scope mismatch detected\n",
5499 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
5500 kfree(clp->cl_serverscope);
5501 clp->cl_serverscope = NULL;
5504 if (clp->cl_serverscope == NULL) {
5505 clp->cl_serverscope = res.server_scope;
5512 kfree(res.server_owner);
5514 kfree(res.server_scope);
5516 if (clp->cl_implid != NULL)
5517 dprintk("NFS reply exchange_id: Server Implementation ID: "
5518 "domain: %s, name: %s, date: %llu,%u\n",
5519 clp->cl_implid->domain, clp->cl_implid->name,
5520 clp->cl_implid->date.seconds,
5521 clp->cl_implid->date.nseconds);
5522 dprintk("NFS reply exchange_id: %d\n", status);
5526 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
5527 struct rpc_cred *cred)
5529 struct rpc_message msg = {
5530 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
5536 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5538 dprintk("NFS: Got error %d from the server %s on "
5539 "DESTROY_CLIENTID.", status, clp->cl_hostname);
5543 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
5544 struct rpc_cred *cred)
5549 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
5550 ret = _nfs4_proc_destroy_clientid(clp, cred);
5552 case -NFS4ERR_DELAY:
5553 case -NFS4ERR_CLIENTID_BUSY:
5563 int nfs4_destroy_clientid(struct nfs_client *clp)
5565 struct rpc_cred *cred;
5568 if (clp->cl_mvops->minor_version < 1)
5570 if (clp->cl_exchange_flags == 0)
5572 if (clp->cl_preserve_clid)
5574 cred = nfs4_get_exchange_id_cred(clp);
5575 ret = nfs4_proc_destroy_clientid(clp, cred);
5580 case -NFS4ERR_STALE_CLIENTID:
5581 clp->cl_exchange_flags = 0;
5587 struct nfs4_get_lease_time_data {
5588 struct nfs4_get_lease_time_args *args;
5589 struct nfs4_get_lease_time_res *res;
5590 struct nfs_client *clp;
5593 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
5596 struct nfs4_get_lease_time_data *data =
5597 (struct nfs4_get_lease_time_data *)calldata;
5599 dprintk("--> %s\n", __func__);
5600 /* just setup sequence, do not trigger session recovery
5601 since we're invoked within one */
5602 nfs41_setup_sequence(data->clp->cl_session,
5603 &data->args->la_seq_args,
5604 &data->res->lr_seq_res,
5606 dprintk("<-- %s\n", __func__);
5610 * Called from nfs4_state_manager thread for session setup, so don't recover
5611 * from sequence operation or clientid errors.
5613 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
5615 struct nfs4_get_lease_time_data *data =
5616 (struct nfs4_get_lease_time_data *)calldata;
5618 dprintk("--> %s\n", __func__);
5619 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
5621 switch (task->tk_status) {
5622 case -NFS4ERR_DELAY:
5623 case -NFS4ERR_GRACE:
5624 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
5625 rpc_delay(task, NFS4_POLL_RETRY_MIN);
5626 task->tk_status = 0;
5628 case -NFS4ERR_RETRY_UNCACHED_REP:
5629 rpc_restart_call_prepare(task);
5632 dprintk("<-- %s\n", __func__);
5635 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
5636 .rpc_call_prepare = nfs4_get_lease_time_prepare,
5637 .rpc_call_done = nfs4_get_lease_time_done,
5640 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
5642 struct rpc_task *task;
5643 struct nfs4_get_lease_time_args args;
5644 struct nfs4_get_lease_time_res res = {
5645 .lr_fsinfo = fsinfo,
5647 struct nfs4_get_lease_time_data data = {
5652 struct rpc_message msg = {
5653 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
5657 struct rpc_task_setup task_setup = {
5658 .rpc_client = clp->cl_rpcclient,
5659 .rpc_message = &msg,
5660 .callback_ops = &nfs4_get_lease_time_ops,
5661 .callback_data = &data,
5662 .flags = RPC_TASK_TIMEOUT,
5666 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
5667 nfs4_set_sequence_privileged(&args.la_seq_args);
5668 dprintk("--> %s\n", __func__);
5669 task = rpc_run_task(&task_setup);
5672 status = PTR_ERR(task);
5674 status = task->tk_status;
5677 dprintk("<-- %s return %d\n", __func__, status);
5683 * Initialize the values to be used by the client in CREATE_SESSION
5684 * If nfs4_init_session set the fore channel request and response sizes,
5687 * Set the back channel max_resp_sz_cached to zero to force the client to
5688 * always set csa_cachethis to FALSE because the current implementation
5689 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5691 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5693 struct nfs4_session *session = args->client->cl_session;
5694 unsigned int mxrqst_sz = session->fc_target_max_rqst_sz,
5695 mxresp_sz = session->fc_target_max_resp_sz;
5698 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
5700 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
5701 /* Fore channel attributes */
5702 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5703 args->fc_attrs.max_resp_sz = mxresp_sz;
5704 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5705 args->fc_attrs.max_reqs = max_session_slots;
5707 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5708 "max_ops=%u max_reqs=%u\n",
5710 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5711 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5713 /* Back channel attributes */
5714 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
5715 args->bc_attrs.max_resp_sz = PAGE_SIZE;
5716 args->bc_attrs.max_resp_sz_cached = 0;
5717 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
5718 args->bc_attrs.max_reqs = 1;
5720 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5721 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5723 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5724 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5725 args->bc_attrs.max_reqs);
5728 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5730 struct nfs4_channel_attrs *sent = &args->fc_attrs;
5731 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
5733 if (rcvd->max_resp_sz > sent->max_resp_sz)
5736 * Our requested max_ops is the minimum we need; we're not
5737 * prepared to break up compounds into smaller pieces than that.
5738 * So, no point even trying to continue if the server won't
5741 if (rcvd->max_ops < sent->max_ops)
5743 if (rcvd->max_reqs == 0)
5745 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5746 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5750 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5752 struct nfs4_channel_attrs *sent = &args->bc_attrs;
5753 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
5755 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
5757 if (rcvd->max_resp_sz < sent->max_resp_sz)
5759 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5761 /* These would render the backchannel useless: */
5762 if (rcvd->max_ops != sent->max_ops)
5764 if (rcvd->max_reqs != sent->max_reqs)
5769 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
5770 struct nfs4_session *session)
5774 ret = nfs4_verify_fore_channel_attrs(args, session);
5777 return nfs4_verify_back_channel_attrs(args, session);
5780 static int _nfs4_proc_create_session(struct nfs_client *clp,
5781 struct rpc_cred *cred)
5783 struct nfs4_session *session = clp->cl_session;
5784 struct nfs41_create_session_args args = {
5786 .cb_program = NFS4_CALLBACK,
5788 struct nfs41_create_session_res res = {
5791 struct rpc_message msg = {
5792 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
5799 nfs4_init_channel_attrs(&args);
5800 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
5802 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5805 /* Verify the session's negotiated channel_attrs values */
5806 status = nfs4_verify_channel_attrs(&args, session);
5807 /* Increment the clientid slot sequence id */
5815 * Issues a CREATE_SESSION operation to the server.
5816 * It is the responsibility of the caller to verify the session is
5817 * expired before calling this routine.
5819 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
5823 struct nfs4_session *session = clp->cl_session;
5825 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
5827 status = _nfs4_proc_create_session(clp, cred);
5831 /* Init or reset the session slot tables */
5832 status = nfs4_setup_session_slot_tables(session);
5833 dprintk("slot table setup returned %d\n", status);
5837 ptr = (unsigned *)&session->sess_id.data[0];
5838 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5839 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5841 dprintk("<-- %s\n", __func__);
5846 * Issue the over-the-wire RPC DESTROY_SESSION.
5847 * The caller must serialize access to this routine.
5849 int nfs4_proc_destroy_session(struct nfs4_session *session,
5850 struct rpc_cred *cred)
5852 struct rpc_message msg = {
5853 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
5854 .rpc_argp = session,
5859 dprintk("--> nfs4_proc_destroy_session\n");
5861 /* session is still being setup */
5862 if (session->clp->cl_cons_state != NFS_CS_READY)
5865 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5868 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
5869 "Session has been destroyed regardless...\n", status);
5871 dprintk("<-- nfs4_proc_destroy_session\n");
5876 * Renew the cl_session lease.
5878 struct nfs4_sequence_data {
5879 struct nfs_client *clp;
5880 struct nfs4_sequence_args args;
5881 struct nfs4_sequence_res res;
5884 static void nfs41_sequence_release(void *data)
5886 struct nfs4_sequence_data *calldata = data;
5887 struct nfs_client *clp = calldata->clp;
5889 if (atomic_read(&clp->cl_count) > 1)
5890 nfs4_schedule_state_renewal(clp);
5891 nfs_put_client(clp);
5895 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5897 switch(task->tk_status) {
5898 case -NFS4ERR_DELAY:
5899 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5902 nfs4_schedule_lease_recovery(clp);
5907 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5909 struct nfs4_sequence_data *calldata = data;
5910 struct nfs_client *clp = calldata->clp;
5912 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5915 if (task->tk_status < 0) {
5916 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5917 if (atomic_read(&clp->cl_count) == 1)
5920 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5921 rpc_restart_call_prepare(task);
5925 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5927 dprintk("<-- %s\n", __func__);
5930 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5932 struct nfs4_sequence_data *calldata = data;
5933 struct nfs_client *clp = calldata->clp;
5934 struct nfs4_sequence_args *args;
5935 struct nfs4_sequence_res *res;
5937 args = task->tk_msg.rpc_argp;
5938 res = task->tk_msg.rpc_resp;
5940 nfs41_setup_sequence(clp->cl_session, args, res, task);
5943 static const struct rpc_call_ops nfs41_sequence_ops = {
5944 .rpc_call_done = nfs41_sequence_call_done,
5945 .rpc_call_prepare = nfs41_sequence_prepare,
5946 .rpc_release = nfs41_sequence_release,
5949 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
5950 struct rpc_cred *cred,
5953 struct nfs4_sequence_data *calldata;
5954 struct rpc_message msg = {
5955 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5958 struct rpc_task_setup task_setup_data = {
5959 .rpc_client = clp->cl_rpcclient,
5960 .rpc_message = &msg,
5961 .callback_ops = &nfs41_sequence_ops,
5962 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
5965 if (!atomic_inc_not_zero(&clp->cl_count))
5966 return ERR_PTR(-EIO);
5967 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5968 if (calldata == NULL) {
5969 nfs_put_client(clp);
5970 return ERR_PTR(-ENOMEM);
5972 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
5974 nfs4_set_sequence_privileged(&calldata->args);
5975 msg.rpc_argp = &calldata->args;
5976 msg.rpc_resp = &calldata->res;
5977 calldata->clp = clp;
5978 task_setup_data.callback_data = calldata;
5980 return rpc_run_task(&task_setup_data);
5983 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
5985 struct rpc_task *task;
5988 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
5990 task = _nfs41_proc_sequence(clp, cred, false);
5992 ret = PTR_ERR(task);
5994 rpc_put_task_async(task);
5995 dprintk("<-- %s status=%d\n", __func__, ret);
5999 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
6001 struct rpc_task *task;
6004 task = _nfs41_proc_sequence(clp, cred, true);
6006 ret = PTR_ERR(task);
6009 ret = rpc_wait_for_completion_task(task);
6011 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
6013 if (task->tk_status == 0)
6014 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
6015 ret = task->tk_status;
6019 dprintk("<-- %s status=%d\n", __func__, ret);
6023 struct nfs4_reclaim_complete_data {
6024 struct nfs_client *clp;
6025 struct nfs41_reclaim_complete_args arg;
6026 struct nfs41_reclaim_complete_res res;
6029 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
6031 struct nfs4_reclaim_complete_data *calldata = data;
6033 nfs41_setup_sequence(calldata->clp->cl_session,
6034 &calldata->arg.seq_args,
6035 &calldata->res.seq_res,
6039 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6041 switch(task->tk_status) {
6043 case -NFS4ERR_COMPLETE_ALREADY:
6044 case -NFS4ERR_WRONG_CRED: /* What to do here? */
6046 case -NFS4ERR_DELAY:
6047 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6049 case -NFS4ERR_RETRY_UNCACHED_REP:
6052 nfs4_schedule_lease_recovery(clp);
6057 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
6059 struct nfs4_reclaim_complete_data *calldata = data;
6060 struct nfs_client *clp = calldata->clp;
6061 struct nfs4_sequence_res *res = &calldata->res.seq_res;
6063 dprintk("--> %s\n", __func__);
6064 if (!nfs41_sequence_done(task, res))
6067 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
6068 rpc_restart_call_prepare(task);
6071 dprintk("<-- %s\n", __func__);
6074 static void nfs4_free_reclaim_complete_data(void *data)
6076 struct nfs4_reclaim_complete_data *calldata = data;
6081 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6082 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
6083 .rpc_call_done = nfs4_reclaim_complete_done,
6084 .rpc_release = nfs4_free_reclaim_complete_data,
6088 * Issue a global reclaim complete.
6090 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
6092 struct nfs4_reclaim_complete_data *calldata;
6093 struct rpc_task *task;
6094 struct rpc_message msg = {
6095 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
6097 struct rpc_task_setup task_setup_data = {
6098 .rpc_client = clp->cl_rpcclient,
6099 .rpc_message = &msg,
6100 .callback_ops = &nfs4_reclaim_complete_call_ops,
6101 .flags = RPC_TASK_ASYNC,
6103 int status = -ENOMEM;
6105 dprintk("--> %s\n", __func__);
6106 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6107 if (calldata == NULL)
6109 calldata->clp = clp;
6110 calldata->arg.one_fs = 0;
6112 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6113 nfs4_set_sequence_privileged(&calldata->arg.seq_args);
6114 msg.rpc_argp = &calldata->arg;
6115 msg.rpc_resp = &calldata->res;
6116 task_setup_data.callback_data = calldata;
6117 task = rpc_run_task(&task_setup_data);
6119 status = PTR_ERR(task);
6122 status = nfs4_wait_for_completion_rpc_task(task);
6124 status = task->tk_status;
6128 dprintk("<-- %s status=%d\n", __func__, status);
6133 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
6135 struct nfs4_layoutget *lgp = calldata;
6136 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6137 struct nfs4_session *session = nfs4_get_session(server);
6139 dprintk("--> %s\n", __func__);
6140 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6141 * right now covering the LAYOUTGET we are about to send.
6142 * However, that is not so catastrophic, and there seems
6143 * to be no way to prevent it completely.
6145 if (nfs41_setup_sequence(session, &lgp->args.seq_args,
6146 &lgp->res.seq_res, task))
6148 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
6149 NFS_I(lgp->args.inode)->layout,
6150 lgp->args.ctx->state)) {
6151 rpc_exit(task, NFS4_OK);
6155 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
6157 struct nfs4_layoutget *lgp = calldata;
6158 struct inode *inode = lgp->args.inode;
6159 struct nfs_server *server = NFS_SERVER(inode);
6160 struct pnfs_layout_hdr *lo;
6161 struct nfs4_state *state = NULL;
6162 unsigned long timeo, giveup;
6164 dprintk("--> %s\n", __func__);
6166 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
6169 switch (task->tk_status) {
6172 case -NFS4ERR_LAYOUTTRYLATER:
6173 case -NFS4ERR_RECALLCONFLICT:
6174 timeo = rpc_get_timeout(task->tk_client);
6175 giveup = lgp->args.timestamp + timeo;
6176 if (time_after(giveup, jiffies))
6177 task->tk_status = -NFS4ERR_DELAY;
6179 case -NFS4ERR_EXPIRED:
6180 case -NFS4ERR_BAD_STATEID:
6181 spin_lock(&inode->i_lock);
6182 lo = NFS_I(inode)->layout;
6183 if (!lo || list_empty(&lo->plh_segs)) {
6184 spin_unlock(&inode->i_lock);
6185 /* If the open stateid was bad, then recover it. */
6186 state = lgp->args.ctx->state;
6190 pnfs_mark_matching_lsegs_invalid(lo, &head, NULL);
6191 spin_unlock(&inode->i_lock);
6192 /* Mark the bad layout state as invalid, then
6193 * retry using the open stateid. */
6194 pnfs_free_lseg_list(&head);
6197 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
6198 rpc_restart_call_prepare(task);
6200 dprintk("<-- %s\n", __func__);
6203 static size_t max_response_pages(struct nfs_server *server)
6205 u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
6206 return nfs_page_array_len(0, max_resp_sz);
6209 static void nfs4_free_pages(struct page **pages, size_t size)
6216 for (i = 0; i < size; i++) {
6219 __free_page(pages[i]);
6224 static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
6226 struct page **pages;
6229 pages = kcalloc(size, sizeof(struct page *), gfp_flags);
6231 dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
6235 for (i = 0; i < size; i++) {
6236 pages[i] = alloc_page(gfp_flags);
6238 dprintk("%s: failed to allocate page\n", __func__);
6239 nfs4_free_pages(pages, size);
6247 static void nfs4_layoutget_release(void *calldata)
6249 struct nfs4_layoutget *lgp = calldata;
6250 struct inode *inode = lgp->args.inode;
6251 struct nfs_server *server = NFS_SERVER(inode);
6252 size_t max_pages = max_response_pages(server);
6254 dprintk("--> %s\n", __func__);
6255 nfs4_free_pages(lgp->args.layout.pages, max_pages);
6256 pnfs_put_layout_hdr(NFS_I(inode)->layout);
6257 put_nfs_open_context(lgp->args.ctx);
6259 dprintk("<-- %s\n", __func__);
6262 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6263 .rpc_call_prepare = nfs4_layoutget_prepare,
6264 .rpc_call_done = nfs4_layoutget_done,
6265 .rpc_release = nfs4_layoutget_release,
6268 struct pnfs_layout_segment *
6269 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)
6271 struct inode *inode = lgp->args.inode;
6272 struct nfs_server *server = NFS_SERVER(inode);
6273 size_t max_pages = max_response_pages(server);
6274 struct rpc_task *task;
6275 struct rpc_message msg = {
6276 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
6277 .rpc_argp = &lgp->args,
6278 .rpc_resp = &lgp->res,
6280 struct rpc_task_setup task_setup_data = {
6281 .rpc_client = server->client,
6282 .rpc_message = &msg,
6283 .callback_ops = &nfs4_layoutget_call_ops,
6284 .callback_data = lgp,
6285 .flags = RPC_TASK_ASYNC,
6287 struct pnfs_layout_segment *lseg = NULL;
6290 dprintk("--> %s\n", __func__);
6292 lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
6293 if (!lgp->args.layout.pages) {
6294 nfs4_layoutget_release(lgp);
6295 return ERR_PTR(-ENOMEM);
6297 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
6298 lgp->args.timestamp = jiffies;
6300 lgp->res.layoutp = &lgp->args.layout;
6301 lgp->res.seq_res.sr_slot = NULL;
6302 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
6304 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6305 pnfs_get_layout_hdr(NFS_I(inode)->layout);
6307 task = rpc_run_task(&task_setup_data);
6309 return ERR_CAST(task);
6310 status = nfs4_wait_for_completion_rpc_task(task);
6312 status = task->tk_status;
6313 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6314 if (status == 0 && lgp->res.layoutp->len)
6315 lseg = pnfs_layout_process(lgp);
6317 dprintk("<-- %s status=%d\n", __func__, status);
6319 return ERR_PTR(status);
6324 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
6326 struct nfs4_layoutreturn *lrp = calldata;
6328 dprintk("--> %s\n", __func__);
6329 nfs41_setup_sequence(lrp->clp->cl_session,
6330 &lrp->args.seq_args,
6335 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
6337 struct nfs4_layoutreturn *lrp = calldata;
6338 struct nfs_server *server;
6340 dprintk("--> %s\n", __func__);
6342 if (!nfs41_sequence_done(task, &lrp->res.seq_res))
6345 server = NFS_SERVER(lrp->args.inode);
6346 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6347 rpc_restart_call_prepare(task);
6350 dprintk("<-- %s\n", __func__);
6353 static void nfs4_layoutreturn_release(void *calldata)
6355 struct nfs4_layoutreturn *lrp = calldata;
6356 struct pnfs_layout_hdr *lo = lrp->args.layout;
6358 dprintk("--> %s\n", __func__);
6359 spin_lock(&lo->plh_inode->i_lock);
6360 if (lrp->res.lrs_present)
6361 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
6362 lo->plh_block_lgets--;
6363 spin_unlock(&lo->plh_inode->i_lock);
6364 pnfs_put_layout_hdr(lrp->args.layout);
6366 dprintk("<-- %s\n", __func__);
6369 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6370 .rpc_call_prepare = nfs4_layoutreturn_prepare,
6371 .rpc_call_done = nfs4_layoutreturn_done,
6372 .rpc_release = nfs4_layoutreturn_release,
6375 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
6377 struct rpc_task *task;
6378 struct rpc_message msg = {
6379 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
6380 .rpc_argp = &lrp->args,
6381 .rpc_resp = &lrp->res,
6383 struct rpc_task_setup task_setup_data = {
6384 .rpc_client = lrp->clp->cl_rpcclient,
6385 .rpc_message = &msg,
6386 .callback_ops = &nfs4_layoutreturn_call_ops,
6387 .callback_data = lrp,
6391 dprintk("--> %s\n", __func__);
6392 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
6393 task = rpc_run_task(&task_setup_data);
6395 return PTR_ERR(task);
6396 status = task->tk_status;
6397 dprintk("<-- %s status=%d\n", __func__, status);
6403 * Retrieve the list of Data Server devices from the MDS.
6405 static int _nfs4_getdevicelist(struct nfs_server *server,
6406 const struct nfs_fh *fh,
6407 struct pnfs_devicelist *devlist)
6409 struct nfs4_getdevicelist_args args = {
6411 .layoutclass = server->pnfs_curr_ld->id,
6413 struct nfs4_getdevicelist_res res = {
6416 struct rpc_message msg = {
6417 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
6423 dprintk("--> %s\n", __func__);
6424 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
6426 dprintk("<-- %s status=%d\n", __func__, status);
6430 int nfs4_proc_getdevicelist(struct nfs_server *server,
6431 const struct nfs_fh *fh,
6432 struct pnfs_devicelist *devlist)
6434 struct nfs4_exception exception = { };
6438 err = nfs4_handle_exception(server,
6439 _nfs4_getdevicelist(server, fh, devlist),
6441 } while (exception.retry);
6443 dprintk("%s: err=%d, num_devs=%u\n", __func__,
6444 err, devlist->num_devs);
6448 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
6451 _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6453 struct nfs4_getdeviceinfo_args args = {
6456 struct nfs4_getdeviceinfo_res res = {
6459 struct rpc_message msg = {
6460 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
6466 dprintk("--> %s\n", __func__);
6467 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6468 dprintk("<-- %s status=%d\n", __func__, status);
6473 int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6475 struct nfs4_exception exception = { };
6479 err = nfs4_handle_exception(server,
6480 _nfs4_proc_getdeviceinfo(server, pdev),
6482 } while (exception.retry);
6485 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
6487 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
6489 struct nfs4_layoutcommit_data *data = calldata;
6490 struct nfs_server *server = NFS_SERVER(data->args.inode);
6491 struct nfs4_session *session = nfs4_get_session(server);
6493 nfs41_setup_sequence(session,
6494 &data->args.seq_args,
6500 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
6502 struct nfs4_layoutcommit_data *data = calldata;
6503 struct nfs_server *server = NFS_SERVER(data->args.inode);
6505 if (!nfs41_sequence_done(task, &data->res.seq_res))
6508 switch (task->tk_status) { /* Just ignore these failures */
6509 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
6510 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
6511 case -NFS4ERR_BADLAYOUT: /* no layout */
6512 case -NFS4ERR_GRACE: /* loca_recalim always false */
6513 task->tk_status = 0;
6516 nfs_post_op_update_inode_force_wcc(data->args.inode,
6520 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6521 rpc_restart_call_prepare(task);
6527 static void nfs4_layoutcommit_release(void *calldata)
6529 struct nfs4_layoutcommit_data *data = calldata;
6531 pnfs_cleanup_layoutcommit(data);
6532 put_rpccred(data->cred);
6536 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
6537 .rpc_call_prepare = nfs4_layoutcommit_prepare,
6538 .rpc_call_done = nfs4_layoutcommit_done,
6539 .rpc_release = nfs4_layoutcommit_release,
6543 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
6545 struct rpc_message msg = {
6546 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
6547 .rpc_argp = &data->args,
6548 .rpc_resp = &data->res,
6549 .rpc_cred = data->cred,
6551 struct rpc_task_setup task_setup_data = {
6552 .task = &data->task,
6553 .rpc_client = NFS_CLIENT(data->args.inode),
6554 .rpc_message = &msg,
6555 .callback_ops = &nfs4_layoutcommit_ops,
6556 .callback_data = data,
6557 .flags = RPC_TASK_ASYNC,
6559 struct rpc_task *task;
6562 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
6563 "lbw: %llu inode %lu\n",
6564 data->task.tk_pid, sync,
6565 data->args.lastbytewritten,
6566 data->args.inode->i_ino);
6568 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6569 task = rpc_run_task(&task_setup_data);
6571 return PTR_ERR(task);
6574 status = nfs4_wait_for_completion_rpc_task(task);
6577 status = task->tk_status;
6579 dprintk("%s: status %d\n", __func__, status);
6585 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6586 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6588 struct nfs41_secinfo_no_name_args args = {
6589 .style = SECINFO_STYLE_CURRENT_FH,
6591 struct nfs4_secinfo_res res = {
6594 struct rpc_message msg = {
6595 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
6599 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6603 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6604 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6606 struct nfs4_exception exception = { };
6609 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6612 case -NFS4ERR_WRONGSEC:
6613 case -NFS4ERR_NOTSUPP:
6616 err = nfs4_handle_exception(server, err, &exception);
6618 } while (exception.retry);
6624 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
6625 struct nfs_fsinfo *info)
6629 rpc_authflavor_t flavor;
6630 struct nfs4_secinfo_flavors *flavors;
6632 page = alloc_page(GFP_KERNEL);
6638 flavors = page_address(page);
6639 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6642 * Fall back on "guess and check" method if
6643 * the server doesn't support SECINFO_NO_NAME
6645 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
6646 err = nfs4_find_root_sec(server, fhandle, info);
6652 flavor = nfs_find_best_sec(flavors);
6654 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
6664 static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6667 struct nfs41_test_stateid_args args = {
6670 struct nfs41_test_stateid_res res;
6671 struct rpc_message msg = {
6672 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
6677 dprintk("NFS call test_stateid %p\n", stateid);
6678 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6679 nfs4_set_sequence_privileged(&args.seq_args);
6680 status = nfs4_call_sync_sequence(server->client, server, &msg,
6681 &args.seq_args, &res.seq_res);
6682 if (status != NFS_OK) {
6683 dprintk("NFS reply test_stateid: failed, %d\n", status);
6686 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
6691 * nfs41_test_stateid - perform a TEST_STATEID operation
6693 * @server: server / transport on which to perform the operation
6694 * @stateid: state ID to test
6696 * Returns NFS_OK if the server recognizes that "stateid" is valid.
6697 * Otherwise a negative NFS4ERR value is returned if the operation
6698 * failed or the state ID is not currently valid.
6700 static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6702 struct nfs4_exception exception = { };
6705 err = _nfs41_test_stateid(server, stateid);
6706 if (err != -NFS4ERR_DELAY)
6708 nfs4_handle_exception(server, err, &exception);
6709 } while (exception.retry);
6713 static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6715 struct nfs41_free_stateid_args args = {
6718 struct nfs41_free_stateid_res res;
6719 struct rpc_message msg = {
6720 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
6726 dprintk("NFS call free_stateid %p\n", stateid);
6727 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6728 nfs4_set_sequence_privileged(&args.seq_args);
6729 status = nfs4_call_sync_sequence(server->client, server, &msg,
6730 &args.seq_args, &res.seq_res);
6731 dprintk("NFS reply free_stateid: %d\n", status);
6736 * nfs41_free_stateid - perform a FREE_STATEID operation
6738 * @server: server / transport on which to perform the operation
6739 * @stateid: state ID to release
6741 * Returns NFS_OK if the server freed "stateid". Otherwise a
6742 * negative NFS4ERR value is returned.
6744 static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6746 struct nfs4_exception exception = { };
6749 err = _nfs4_free_stateid(server, stateid);
6750 if (err != -NFS4ERR_DELAY)
6752 nfs4_handle_exception(server, err, &exception);
6753 } while (exception.retry);
6757 static bool nfs41_match_stateid(const nfs4_stateid *s1,
6758 const nfs4_stateid *s2)
6760 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6763 if (s1->seqid == s2->seqid)
6765 if (s1->seqid == 0 || s2->seqid == 0)
6771 #endif /* CONFIG_NFS_V4_1 */
6773 static bool nfs4_match_stateid(const nfs4_stateid *s1,
6774 const nfs4_stateid *s2)
6776 return nfs4_stateid_match(s1, s2);
6780 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6781 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6782 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6783 .recover_open = nfs4_open_reclaim,
6784 .recover_lock = nfs4_lock_reclaim,
6785 .establish_clid = nfs4_init_clientid,
6786 .get_clid_cred = nfs4_get_setclientid_cred,
6787 .detect_trunking = nfs40_discover_server_trunking,
6790 #if defined(CONFIG_NFS_V4_1)
6791 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6792 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6793 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6794 .recover_open = nfs4_open_reclaim,
6795 .recover_lock = nfs4_lock_reclaim,
6796 .establish_clid = nfs41_init_clientid,
6797 .get_clid_cred = nfs4_get_exchange_id_cred,
6798 .reclaim_complete = nfs41_proc_reclaim_complete,
6799 .detect_trunking = nfs41_discover_server_trunking,
6801 #endif /* CONFIG_NFS_V4_1 */
6803 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6804 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6805 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6806 .recover_open = nfs4_open_expired,
6807 .recover_lock = nfs4_lock_expired,
6808 .establish_clid = nfs4_init_clientid,
6809 .get_clid_cred = nfs4_get_setclientid_cred,
6812 #if defined(CONFIG_NFS_V4_1)
6813 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6814 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6815 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6816 .recover_open = nfs41_open_expired,
6817 .recover_lock = nfs41_lock_expired,
6818 .establish_clid = nfs41_init_clientid,
6819 .get_clid_cred = nfs4_get_exchange_id_cred,
6821 #endif /* CONFIG_NFS_V4_1 */
6823 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6824 .sched_state_renewal = nfs4_proc_async_renew,
6825 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6826 .renew_lease = nfs4_proc_renew,
6829 #if defined(CONFIG_NFS_V4_1)
6830 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6831 .sched_state_renewal = nfs41_proc_async_sequence,
6832 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6833 .renew_lease = nfs4_proc_sequence,
6837 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6839 .init_caps = NFS_CAP_READDIRPLUS
6840 | NFS_CAP_ATOMIC_OPEN
6841 | NFS_CAP_CHANGE_ATTR
6842 | NFS_CAP_POSIX_LOCK,
6843 .call_sync = _nfs4_call_sync,
6844 .match_stateid = nfs4_match_stateid,
6845 .find_root_sec = nfs4_find_root_sec,
6846 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6847 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
6848 .state_renewal_ops = &nfs40_state_renewal_ops,
6851 #if defined(CONFIG_NFS_V4_1)
6852 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6854 .init_caps = NFS_CAP_READDIRPLUS
6855 | NFS_CAP_ATOMIC_OPEN
6856 | NFS_CAP_CHANGE_ATTR
6857 | NFS_CAP_POSIX_LOCK
6858 | NFS_CAP_STATEID_NFSV41
6859 | NFS_CAP_ATOMIC_OPEN_V1,
6860 .call_sync = nfs4_call_sync_sequence,
6861 .match_stateid = nfs41_match_stateid,
6862 .find_root_sec = nfs41_find_root_sec,
6863 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6864 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
6865 .state_renewal_ops = &nfs41_state_renewal_ops,
6869 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
6870 [0] = &nfs_v4_0_minor_ops,
6871 #if defined(CONFIG_NFS_V4_1)
6872 [1] = &nfs_v4_1_minor_ops,
6876 const struct inode_operations nfs4_dir_inode_operations = {
6877 .create = nfs_create,
6878 .lookup = nfs_lookup,
6879 .atomic_open = nfs_atomic_open,
6881 .unlink = nfs_unlink,
6882 .symlink = nfs_symlink,
6886 .rename = nfs_rename,
6887 .permission = nfs_permission,
6888 .getattr = nfs_getattr,
6889 .setattr = nfs_setattr,
6890 .getxattr = generic_getxattr,
6891 .setxattr = generic_setxattr,
6892 .listxattr = generic_listxattr,
6893 .removexattr = generic_removexattr,
6896 static const struct inode_operations nfs4_file_inode_operations = {
6897 .permission = nfs_permission,
6898 .getattr = nfs_getattr,
6899 .setattr = nfs_setattr,
6900 .getxattr = generic_getxattr,
6901 .setxattr = generic_setxattr,
6902 .listxattr = generic_listxattr,
6903 .removexattr = generic_removexattr,
6906 const struct nfs_rpc_ops nfs_v4_clientops = {
6907 .version = 4, /* protocol version */
6908 .dentry_ops = &nfs4_dentry_operations,
6909 .dir_inode_ops = &nfs4_dir_inode_operations,
6910 .file_inode_ops = &nfs4_file_inode_operations,
6911 .file_ops = &nfs4_file_operations,
6912 .getroot = nfs4_proc_get_root,
6913 .submount = nfs4_submount,
6914 .try_mount = nfs4_try_mount,
6915 .getattr = nfs4_proc_getattr,
6916 .setattr = nfs4_proc_setattr,
6917 .lookup = nfs4_proc_lookup,
6918 .access = nfs4_proc_access,
6919 .readlink = nfs4_proc_readlink,
6920 .create = nfs4_proc_create,
6921 .remove = nfs4_proc_remove,
6922 .unlink_setup = nfs4_proc_unlink_setup,
6923 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6924 .unlink_done = nfs4_proc_unlink_done,
6925 .rename = nfs4_proc_rename,
6926 .rename_setup = nfs4_proc_rename_setup,
6927 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6928 .rename_done = nfs4_proc_rename_done,
6929 .link = nfs4_proc_link,
6930 .symlink = nfs4_proc_symlink,
6931 .mkdir = nfs4_proc_mkdir,
6932 .rmdir = nfs4_proc_remove,
6933 .readdir = nfs4_proc_readdir,
6934 .mknod = nfs4_proc_mknod,
6935 .statfs = nfs4_proc_statfs,
6936 .fsinfo = nfs4_proc_fsinfo,
6937 .pathconf = nfs4_proc_pathconf,
6938 .set_capabilities = nfs4_server_capabilities,
6939 .decode_dirent = nfs4_decode_dirent,
6940 .read_setup = nfs4_proc_read_setup,
6941 .read_pageio_init = pnfs_pageio_init_read,
6942 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6943 .read_done = nfs4_read_done,
6944 .write_setup = nfs4_proc_write_setup,
6945 .write_pageio_init = pnfs_pageio_init_write,
6946 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6947 .write_done = nfs4_write_done,
6948 .commit_setup = nfs4_proc_commit_setup,
6949 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
6950 .commit_done = nfs4_commit_done,
6951 .lock = nfs4_proc_lock,
6952 .clear_acl_cache = nfs4_zap_acl_attr,
6953 .close_context = nfs4_close_context,
6954 .open_context = nfs4_atomic_open,
6955 .have_delegation = nfs4_have_delegation,
6956 .return_delegation = nfs4_inode_return_delegation,
6957 .alloc_client = nfs4_alloc_client,
6958 .init_client = nfs4_init_client,
6959 .free_client = nfs4_free_client,
6960 .create_server = nfs4_create_server,
6961 .clone_server = nfs_clone_server,
6964 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
6965 .prefix = XATTR_NAME_NFSV4_ACL,
6966 .list = nfs4_xattr_list_nfs4_acl,
6967 .get = nfs4_xattr_get_nfs4_acl,
6968 .set = nfs4_xattr_set_nfs4_acl,
6971 const struct xattr_handler *nfs4_xattr_handlers[] = {
6972 &nfs4_xattr_nfs4_acl_handler,