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/slab.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/nfs.h>
45 #include <linux/nfs4.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/nfs_page.h>
48 #include <linux/namei.h>
49 #include <linux/mount.h>
50 #include <linux/module.h>
51 #include <linux/sunrpc/bc_xprt.h>
54 #include "delegation.h"
59 #define NFSDBG_FACILITY NFSDBG_PROC
61 #define NFS4_POLL_RETRY_MIN (HZ/10)
62 #define NFS4_POLL_RETRY_MAX (15*HZ)
64 #define NFS4_MAX_LOOP_ON_RECOVER (10)
67 static int _nfs4_proc_open(struct nfs4_opendata *data);
68 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
69 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
70 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
71 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
72 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
74 /* Prevent leaks of NFSv4 errors into userland */
75 static int nfs4_map_errors(int err)
80 case -NFS4ERR_RESOURCE:
83 dprintk("%s could not handle NFSv4 error %d\n",
91 * This is our standard bitmap for GETATTR requests.
93 const u32 nfs4_fattr_bitmap[2] = {
98 | FATTR4_WORD0_FILEID,
100 | FATTR4_WORD1_NUMLINKS
102 | FATTR4_WORD1_OWNER_GROUP
103 | FATTR4_WORD1_RAWDEV
104 | FATTR4_WORD1_SPACE_USED
105 | FATTR4_WORD1_TIME_ACCESS
106 | FATTR4_WORD1_TIME_METADATA
107 | FATTR4_WORD1_TIME_MODIFY
110 const u32 nfs4_statfs_bitmap[2] = {
111 FATTR4_WORD0_FILES_AVAIL
112 | FATTR4_WORD0_FILES_FREE
113 | FATTR4_WORD0_FILES_TOTAL,
114 FATTR4_WORD1_SPACE_AVAIL
115 | FATTR4_WORD1_SPACE_FREE
116 | FATTR4_WORD1_SPACE_TOTAL
119 const u32 nfs4_pathconf_bitmap[2] = {
121 | FATTR4_WORD0_MAXNAME,
125 const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
126 | FATTR4_WORD0_MAXREAD
127 | FATTR4_WORD0_MAXWRITE
128 | FATTR4_WORD0_LEASE_TIME,
132 const u32 nfs4_fs_locations_bitmap[2] = {
134 | FATTR4_WORD0_CHANGE
137 | FATTR4_WORD0_FILEID
138 | FATTR4_WORD0_FS_LOCATIONS,
140 | FATTR4_WORD1_NUMLINKS
142 | FATTR4_WORD1_OWNER_GROUP
143 | FATTR4_WORD1_RAWDEV
144 | FATTR4_WORD1_SPACE_USED
145 | FATTR4_WORD1_TIME_ACCESS
146 | FATTR4_WORD1_TIME_METADATA
147 | FATTR4_WORD1_TIME_MODIFY
148 | FATTR4_WORD1_MOUNTED_ON_FILEID
151 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
152 struct nfs4_readdir_arg *readdir)
156 BUG_ON(readdir->count < 80);
158 readdir->cookie = cookie;
159 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
164 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
169 * NFSv4 servers do not return entries for '.' and '..'
170 * Therefore, we fake these entries here. We let '.'
171 * have cookie 0 and '..' have cookie 1. Note that
172 * when talking to the server, we always send cookie 0
175 start = p = kmap_atomic(*readdir->pages, KM_USER0);
178 *p++ = xdr_one; /* next */
179 *p++ = xdr_zero; /* cookie, first word */
180 *p++ = xdr_one; /* cookie, second word */
181 *p++ = xdr_one; /* entry len */
182 memcpy(p, ".\0\0\0", 4); /* entry */
184 *p++ = xdr_one; /* bitmap length */
185 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
186 *p++ = htonl(8); /* attribute buffer length */
187 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
190 *p++ = xdr_one; /* next */
191 *p++ = xdr_zero; /* cookie, first word */
192 *p++ = xdr_two; /* cookie, second word */
193 *p++ = xdr_two; /* entry len */
194 memcpy(p, "..\0\0", 4); /* entry */
196 *p++ = xdr_one; /* bitmap length */
197 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
198 *p++ = htonl(8); /* attribute buffer length */
199 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
201 readdir->pgbase = (char *)p - (char *)start;
202 readdir->count -= readdir->pgbase;
203 kunmap_atomic(start, KM_USER0);
206 static int nfs4_wait_clnt_recover(struct nfs_client *clp)
212 res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
213 nfs_wait_bit_killable, TASK_KILLABLE);
217 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
224 *timeout = NFS4_POLL_RETRY_MIN;
225 if (*timeout > NFS4_POLL_RETRY_MAX)
226 *timeout = NFS4_POLL_RETRY_MAX;
227 schedule_timeout_killable(*timeout);
228 if (fatal_signal_pending(current))
234 /* This is the error handling routine for processes that are allowed
237 static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
239 struct nfs_client *clp = server->nfs_client;
240 struct nfs4_state *state = exception->state;
243 exception->retry = 0;
247 case -NFS4ERR_ADMIN_REVOKED:
248 case -NFS4ERR_BAD_STATEID:
249 case -NFS4ERR_OPENMODE:
252 nfs4_state_mark_reclaim_nograce(clp, state);
253 goto do_state_recovery;
254 case -NFS4ERR_STALE_STATEID:
257 nfs4_state_mark_reclaim_reboot(clp, state);
258 case -NFS4ERR_STALE_CLIENTID:
259 case -NFS4ERR_EXPIRED:
260 goto do_state_recovery;
261 #if defined(CONFIG_NFS_V4_1)
262 case -NFS4ERR_BADSESSION:
263 case -NFS4ERR_BADSLOT:
264 case -NFS4ERR_BAD_HIGH_SLOT:
265 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
266 case -NFS4ERR_DEADSESSION:
267 case -NFS4ERR_SEQ_FALSE_RETRY:
268 case -NFS4ERR_SEQ_MISORDERED:
269 dprintk("%s ERROR: %d Reset session\n", __func__,
271 nfs4_schedule_state_recovery(clp);
272 exception->retry = 1;
274 #endif /* defined(CONFIG_NFS_V4_1) */
275 case -NFS4ERR_FILE_OPEN:
276 if (exception->timeout > HZ) {
277 /* We have retried a decent amount, time to
286 ret = nfs4_delay(server->client, &exception->timeout);
289 case -NFS4ERR_OLD_STATEID:
290 exception->retry = 1;
292 /* We failed to handle the error */
293 return nfs4_map_errors(ret);
295 nfs4_schedule_state_recovery(clp);
296 ret = nfs4_wait_clnt_recover(clp);
298 exception->retry = 1;
303 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
305 struct nfs_client *clp = server->nfs_client;
306 spin_lock(&clp->cl_lock);
307 if (time_before(clp->cl_last_renewal,timestamp))
308 clp->cl_last_renewal = timestamp;
309 spin_unlock(&clp->cl_lock);
312 #if defined(CONFIG_NFS_V4_1)
315 * nfs4_free_slot - free a slot and efficiently update slot table.
317 * freeing a slot is trivially done by clearing its respective bit
319 * If the freed slotid equals highest_used_slotid we want to update it
320 * so that the server would be able to size down the slot table if needed,
321 * otherwise we know that the highest_used_slotid is still in use.
322 * When updating highest_used_slotid there may be "holes" in the bitmap
323 * so we need to scan down from highest_used_slotid to 0 looking for the now
324 * highest slotid in use.
325 * If none found, highest_used_slotid is set to -1.
327 * Must be called while holding tbl->slot_tbl_lock
330 nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
332 int slotid = free_slotid;
334 /* clear used bit in bitmap */
335 __clear_bit(slotid, tbl->used_slots);
337 /* update highest_used_slotid when it is freed */
338 if (slotid == tbl->highest_used_slotid) {
339 slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
340 if (slotid < tbl->max_slots)
341 tbl->highest_used_slotid = slotid;
343 tbl->highest_used_slotid = -1;
345 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__,
346 free_slotid, tbl->highest_used_slotid);
350 * Signal state manager thread if session is drained
352 static void nfs41_check_drain_session_complete(struct nfs4_session *ses)
354 struct rpc_task *task;
356 if (!test_bit(NFS4CLNT_SESSION_DRAINING, &ses->clp->cl_state)) {
357 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq);
359 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
363 if (ses->fc_slot_table.highest_used_slotid != -1)
366 dprintk("%s COMPLETE: Session Drained\n", __func__);
367 complete(&ses->complete);
370 static void nfs41_sequence_free_slot(const struct nfs_client *clp,
371 struct nfs4_sequence_res *res)
373 struct nfs4_slot_table *tbl;
375 tbl = &clp->cl_session->fc_slot_table;
376 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) {
377 /* just wake up the next guy waiting since
378 * we may have not consumed a slot after all */
379 dprintk("%s: No slot\n", __func__);
383 spin_lock(&tbl->slot_tbl_lock);
384 nfs4_free_slot(tbl, res->sr_slotid);
385 nfs41_check_drain_session_complete(clp->cl_session);
386 spin_unlock(&tbl->slot_tbl_lock);
387 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
390 static void nfs41_sequence_done(struct nfs_client *clp,
391 struct nfs4_sequence_res *res,
394 unsigned long timestamp;
395 struct nfs4_slot_table *tbl;
396 struct nfs4_slot *slot;
399 * sr_status remains 1 if an RPC level error occurred. The server
400 * may or may not have processed the sequence operation..
401 * Proceed as if the server received and processed the sequence
404 if (res->sr_status == 1)
405 res->sr_status = NFS_OK;
407 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
408 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE)
411 /* Check the SEQUENCE operation status */
412 if (res->sr_status == 0) {
413 tbl = &clp->cl_session->fc_slot_table;
414 slot = tbl->slots + res->sr_slotid;
415 /* Update the slot's sequence and clientid lease timer */
417 timestamp = res->sr_renewal_time;
418 spin_lock(&clp->cl_lock);
419 if (time_before(clp->cl_last_renewal, timestamp))
420 clp->cl_last_renewal = timestamp;
421 spin_unlock(&clp->cl_lock);
422 /* Check sequence flags */
423 if (atomic_read(&clp->cl_count) > 1)
424 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
427 /* The session may be reset by one of the error handlers. */
428 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
429 nfs41_sequence_free_slot(clp, res);
433 * nfs4_find_slot - efficiently look for a free slot
435 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
436 * If found, we mark the slot as used, update the highest_used_slotid,
437 * and respectively set up the sequence operation args.
438 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
440 * Note: must be called with under the slot_tbl_lock.
443 nfs4_find_slot(struct nfs4_slot_table *tbl)
446 u8 ret_id = NFS4_MAX_SLOT_TABLE;
447 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
449 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
450 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
452 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
453 if (slotid >= tbl->max_slots)
455 __set_bit(slotid, tbl->used_slots);
456 if (slotid > tbl->highest_used_slotid)
457 tbl->highest_used_slotid = slotid;
460 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
461 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
465 static int nfs41_setup_sequence(struct nfs4_session *session,
466 struct nfs4_sequence_args *args,
467 struct nfs4_sequence_res *res,
469 struct rpc_task *task)
471 struct nfs4_slot *slot;
472 struct nfs4_slot_table *tbl;
475 dprintk("--> %s\n", __func__);
476 /* slot already allocated? */
477 if (res->sr_slotid != NFS4_MAX_SLOT_TABLE)
480 memset(res, 0, sizeof(*res));
481 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
482 tbl = &session->fc_slot_table;
484 spin_lock(&tbl->slot_tbl_lock);
485 if (test_bit(NFS4CLNT_SESSION_DRAINING, &session->clp->cl_state) &&
486 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
488 * The state manager will wait until the slot table is empty.
489 * Schedule the reset thread
491 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
492 spin_unlock(&tbl->slot_tbl_lock);
493 dprintk("%s Schedule Session Reset\n", __func__);
497 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
498 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
499 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
500 spin_unlock(&tbl->slot_tbl_lock);
501 dprintk("%s enforce FIFO order\n", __func__);
505 slotid = nfs4_find_slot(tbl);
506 if (slotid == NFS4_MAX_SLOT_TABLE) {
507 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
508 spin_unlock(&tbl->slot_tbl_lock);
509 dprintk("<-- %s: no free slots\n", __func__);
512 spin_unlock(&tbl->slot_tbl_lock);
514 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
515 slot = tbl->slots + slotid;
516 args->sa_session = session;
517 args->sa_slotid = slotid;
518 args->sa_cache_this = cache_reply;
520 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
522 res->sr_session = session;
523 res->sr_slotid = slotid;
524 res->sr_renewal_time = jiffies;
526 * sr_status is only set in decode_sequence, and so will remain
527 * set to 1 if an rpc level failure occurs.
533 int nfs4_setup_sequence(struct nfs_client *clp,
534 struct nfs4_sequence_args *args,
535 struct nfs4_sequence_res *res,
537 struct rpc_task *task)
541 dprintk("--> %s clp %p session %p sr_slotid %d\n",
542 __func__, clp, clp->cl_session, res->sr_slotid);
544 if (!nfs4_has_session(clp))
546 ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply,
548 if (ret && ret != -EAGAIN) {
549 /* terminate rpc task */
550 task->tk_status = ret;
551 task->tk_action = NULL;
554 dprintk("<-- %s status=%d\n", __func__, ret);
558 struct nfs41_call_sync_data {
559 struct nfs_client *clp;
560 struct nfs4_sequence_args *seq_args;
561 struct nfs4_sequence_res *seq_res;
565 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
567 struct nfs41_call_sync_data *data = calldata;
569 dprintk("--> %s data->clp->cl_session %p\n", __func__,
570 data->clp->cl_session);
571 if (nfs4_setup_sequence(data->clp, data->seq_args,
572 data->seq_res, data->cache_reply, task))
574 rpc_call_start(task);
577 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
579 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
580 nfs41_call_sync_prepare(task, calldata);
583 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
585 struct nfs41_call_sync_data *data = calldata;
587 nfs41_sequence_done(data->clp, data->seq_res, task->tk_status);
590 struct rpc_call_ops nfs41_call_sync_ops = {
591 .rpc_call_prepare = nfs41_call_sync_prepare,
592 .rpc_call_done = nfs41_call_sync_done,
595 struct rpc_call_ops nfs41_call_priv_sync_ops = {
596 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
597 .rpc_call_done = nfs41_call_sync_done,
600 static int nfs4_call_sync_sequence(struct nfs_client *clp,
601 struct rpc_clnt *clnt,
602 struct rpc_message *msg,
603 struct nfs4_sequence_args *args,
604 struct nfs4_sequence_res *res,
609 struct rpc_task *task;
610 struct nfs41_call_sync_data data = {
614 .cache_reply = cache_reply,
616 struct rpc_task_setup task_setup = {
619 .callback_ops = &nfs41_call_sync_ops,
620 .callback_data = &data
623 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
625 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
626 task = rpc_run_task(&task_setup);
630 ret = task->tk_status;
636 int _nfs4_call_sync_session(struct nfs_server *server,
637 struct rpc_message *msg,
638 struct nfs4_sequence_args *args,
639 struct nfs4_sequence_res *res,
642 return nfs4_call_sync_sequence(server->nfs_client, server->client,
643 msg, args, res, cache_reply, 0);
646 #endif /* CONFIG_NFS_V4_1 */
648 int _nfs4_call_sync(struct nfs_server *server,
649 struct rpc_message *msg,
650 struct nfs4_sequence_args *args,
651 struct nfs4_sequence_res *res,
654 args->sa_session = res->sr_session = NULL;
655 return rpc_call_sync(server->client, msg, 0);
658 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
659 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
660 &(res)->seq_res, (cache_reply))
662 static void nfs4_sequence_done(const struct nfs_server *server,
663 struct nfs4_sequence_res *res, int rpc_status)
665 #ifdef CONFIG_NFS_V4_1
666 if (nfs4_has_session(server->nfs_client))
667 nfs41_sequence_done(server->nfs_client, res, rpc_status);
668 #endif /* CONFIG_NFS_V4_1 */
671 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
673 struct nfs_inode *nfsi = NFS_I(dir);
675 spin_lock(&dir->i_lock);
676 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
677 if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
678 nfs_force_lookup_revalidate(dir);
679 nfsi->change_attr = cinfo->after;
680 spin_unlock(&dir->i_lock);
683 struct nfs4_opendata {
685 struct nfs_openargs o_arg;
686 struct nfs_openres o_res;
687 struct nfs_open_confirmargs c_arg;
688 struct nfs_open_confirmres c_res;
689 struct nfs_fattr f_attr;
690 struct nfs_fattr dir_attr;
693 struct nfs4_state_owner *owner;
694 struct nfs4_state *state;
696 unsigned long timestamp;
697 unsigned int rpc_done : 1;
703 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
705 p->o_res.f_attr = &p->f_attr;
706 p->o_res.dir_attr = &p->dir_attr;
707 p->o_res.seqid = p->o_arg.seqid;
708 p->c_res.seqid = p->c_arg.seqid;
709 p->o_res.server = p->o_arg.server;
710 nfs_fattr_init(&p->f_attr);
711 nfs_fattr_init(&p->dir_attr);
712 p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
715 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
716 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
717 const struct iattr *attrs)
719 struct dentry *parent = dget_parent(path->dentry);
720 struct inode *dir = parent->d_inode;
721 struct nfs_server *server = NFS_SERVER(dir);
722 struct nfs4_opendata *p;
724 p = kzalloc(sizeof(*p), GFP_KERNEL);
727 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
728 if (p->o_arg.seqid == NULL)
734 atomic_inc(&sp->so_count);
735 p->o_arg.fh = NFS_FH(dir);
736 p->o_arg.open_flags = flags;
737 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
738 p->o_arg.clientid = server->nfs_client->cl_clientid;
739 p->o_arg.id = sp->so_owner_id.id;
740 p->o_arg.name = &p->path.dentry->d_name;
741 p->o_arg.server = server;
742 p->o_arg.bitmask = server->attr_bitmask;
743 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
744 if (flags & O_EXCL) {
745 if (nfs4_has_persistent_session(server->nfs_client)) {
747 p->o_arg.u.attrs = &p->attrs;
748 memcpy(&p->attrs, attrs, sizeof(p->attrs));
749 } else { /* EXCLUSIVE4_1 */
750 u32 *s = (u32 *) p->o_arg.u.verifier.data;
754 } else if (flags & O_CREAT) {
755 p->o_arg.u.attrs = &p->attrs;
756 memcpy(&p->attrs, attrs, sizeof(p->attrs));
758 p->c_arg.fh = &p->o_res.fh;
759 p->c_arg.stateid = &p->o_res.stateid;
760 p->c_arg.seqid = p->o_arg.seqid;
761 nfs4_init_opendata_res(p);
771 static void nfs4_opendata_free(struct kref *kref)
773 struct nfs4_opendata *p = container_of(kref,
774 struct nfs4_opendata, kref);
776 nfs_free_seqid(p->o_arg.seqid);
777 if (p->state != NULL)
778 nfs4_put_open_state(p->state);
779 nfs4_put_state_owner(p->owner);
785 static void nfs4_opendata_put(struct nfs4_opendata *p)
788 kref_put(&p->kref, nfs4_opendata_free);
791 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
795 ret = rpc_wait_for_completion_task(task);
799 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
803 if (open_mode & O_EXCL)
805 switch (mode & (FMODE_READ|FMODE_WRITE)) {
807 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
808 && state->n_rdonly != 0;
811 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
812 && state->n_wronly != 0;
814 case FMODE_READ|FMODE_WRITE:
815 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
816 && state->n_rdwr != 0;
822 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
824 if ((delegation->type & fmode) != fmode)
826 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
828 nfs_mark_delegation_referenced(delegation);
832 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
841 case FMODE_READ|FMODE_WRITE:
844 nfs4_state_set_mode_locked(state, state->state | fmode);
847 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
849 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
850 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
851 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
854 set_bit(NFS_O_RDONLY_STATE, &state->flags);
857 set_bit(NFS_O_WRONLY_STATE, &state->flags);
859 case FMODE_READ|FMODE_WRITE:
860 set_bit(NFS_O_RDWR_STATE, &state->flags);
864 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
866 write_seqlock(&state->seqlock);
867 nfs_set_open_stateid_locked(state, stateid, fmode);
868 write_sequnlock(&state->seqlock);
871 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
874 * Protect the call to nfs4_state_set_mode_locked and
875 * serialise the stateid update
877 write_seqlock(&state->seqlock);
878 if (deleg_stateid != NULL) {
879 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
880 set_bit(NFS_DELEGATED_STATE, &state->flags);
882 if (open_stateid != NULL)
883 nfs_set_open_stateid_locked(state, open_stateid, fmode);
884 write_sequnlock(&state->seqlock);
885 spin_lock(&state->owner->so_lock);
886 update_open_stateflags(state, fmode);
887 spin_unlock(&state->owner->so_lock);
890 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
892 struct nfs_inode *nfsi = NFS_I(state->inode);
893 struct nfs_delegation *deleg_cur;
896 fmode &= (FMODE_READ|FMODE_WRITE);
899 deleg_cur = rcu_dereference(nfsi->delegation);
900 if (deleg_cur == NULL)
903 spin_lock(&deleg_cur->lock);
904 if (nfsi->delegation != deleg_cur ||
905 (deleg_cur->type & fmode) != fmode)
906 goto no_delegation_unlock;
908 if (delegation == NULL)
909 delegation = &deleg_cur->stateid;
910 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
911 goto no_delegation_unlock;
913 nfs_mark_delegation_referenced(deleg_cur);
914 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
916 no_delegation_unlock:
917 spin_unlock(&deleg_cur->lock);
921 if (!ret && open_stateid != NULL) {
922 __update_open_stateid(state, open_stateid, NULL, fmode);
930 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
932 struct nfs_delegation *delegation;
935 delegation = rcu_dereference(NFS_I(inode)->delegation);
936 if (delegation == NULL || (delegation->type & fmode) == fmode) {
941 nfs_inode_return_delegation(inode);
944 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
946 struct nfs4_state *state = opendata->state;
947 struct nfs_inode *nfsi = NFS_I(state->inode);
948 struct nfs_delegation *delegation;
949 int open_mode = opendata->o_arg.open_flags & O_EXCL;
950 fmode_t fmode = opendata->o_arg.fmode;
951 nfs4_stateid stateid;
955 if (can_open_cached(state, fmode, open_mode)) {
956 spin_lock(&state->owner->so_lock);
957 if (can_open_cached(state, fmode, open_mode)) {
958 update_open_stateflags(state, fmode);
959 spin_unlock(&state->owner->so_lock);
960 goto out_return_state;
962 spin_unlock(&state->owner->so_lock);
965 delegation = rcu_dereference(nfsi->delegation);
966 if (delegation == NULL ||
967 !can_open_delegated(delegation, fmode)) {
971 /* Save the delegation */
972 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
974 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
979 /* Try to update the stateid using the delegation */
980 if (update_open_stateid(state, NULL, &stateid, fmode))
981 goto out_return_state;
986 atomic_inc(&state->count);
990 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
993 struct nfs4_state *state = NULL;
994 struct nfs_delegation *delegation;
997 if (!data->rpc_done) {
998 state = nfs4_try_open_cached(data);
1003 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1005 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1006 ret = PTR_ERR(inode);
1010 state = nfs4_get_open_state(inode, data->owner);
1013 if (data->o_res.delegation_type != 0) {
1014 int delegation_flags = 0;
1017 delegation = rcu_dereference(NFS_I(inode)->delegation);
1019 delegation_flags = delegation->flags;
1021 if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1022 nfs_inode_set_delegation(state->inode,
1023 data->owner->so_cred,
1026 nfs_inode_reclaim_delegation(state->inode,
1027 data->owner->so_cred,
1031 update_open_stateid(state, &data->o_res.stateid, NULL,
1039 return ERR_PTR(ret);
1042 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1044 struct nfs_inode *nfsi = NFS_I(state->inode);
1045 struct nfs_open_context *ctx;
1047 spin_lock(&state->inode->i_lock);
1048 list_for_each_entry(ctx, &nfsi->open_files, list) {
1049 if (ctx->state != state)
1051 get_nfs_open_context(ctx);
1052 spin_unlock(&state->inode->i_lock);
1055 spin_unlock(&state->inode->i_lock);
1056 return ERR_PTR(-ENOENT);
1059 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1061 struct nfs4_opendata *opendata;
1063 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL);
1064 if (opendata == NULL)
1065 return ERR_PTR(-ENOMEM);
1066 opendata->state = state;
1067 atomic_inc(&state->count);
1071 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1073 struct nfs4_state *newstate;
1076 opendata->o_arg.open_flags = 0;
1077 opendata->o_arg.fmode = fmode;
1078 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1079 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1080 nfs4_init_opendata_res(opendata);
1081 ret = _nfs4_recover_proc_open(opendata);
1084 newstate = nfs4_opendata_to_nfs4_state(opendata);
1085 if (IS_ERR(newstate))
1086 return PTR_ERR(newstate);
1087 nfs4_close_state(&opendata->path, newstate, fmode);
1092 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1094 struct nfs4_state *newstate;
1097 /* memory barrier prior to reading state->n_* */
1098 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1100 if (state->n_rdwr != 0) {
1101 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1104 if (newstate != state)
1107 if (state->n_wronly != 0) {
1108 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1111 if (newstate != state)
1114 if (state->n_rdonly != 0) {
1115 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1118 if (newstate != state)
1122 * We may have performed cached opens for all three recoveries.
1123 * Check if we need to update the current stateid.
1125 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1126 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
1127 write_seqlock(&state->seqlock);
1128 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1129 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
1130 write_sequnlock(&state->seqlock);
1137 * reclaim state on the server after a reboot.
1139 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1141 struct nfs_delegation *delegation;
1142 struct nfs4_opendata *opendata;
1143 fmode_t delegation_type = 0;
1146 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1147 if (IS_ERR(opendata))
1148 return PTR_ERR(opendata);
1149 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1150 opendata->o_arg.fh = NFS_FH(state->inode);
1152 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1153 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1154 delegation_type = delegation->type;
1156 opendata->o_arg.u.delegation_type = delegation_type;
1157 status = nfs4_open_recover(opendata, state);
1158 nfs4_opendata_put(opendata);
1162 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1164 struct nfs_server *server = NFS_SERVER(state->inode);
1165 struct nfs4_exception exception = { };
1168 err = _nfs4_do_open_reclaim(ctx, state);
1169 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
1171 nfs4_handle_exception(server, err, &exception);
1172 } while (exception.retry);
1176 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1178 struct nfs_open_context *ctx;
1181 ctx = nfs4_state_find_open_context(state);
1183 return PTR_ERR(ctx);
1184 ret = nfs4_do_open_reclaim(ctx, state);
1185 put_nfs_open_context(ctx);
1189 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1191 struct nfs4_opendata *opendata;
1194 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1195 if (IS_ERR(opendata))
1196 return PTR_ERR(opendata);
1197 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1198 memcpy(opendata->o_arg.u.delegation.data, stateid->data,
1199 sizeof(opendata->o_arg.u.delegation.data));
1200 ret = nfs4_open_recover(opendata, state);
1201 nfs4_opendata_put(opendata);
1205 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1207 struct nfs4_exception exception = { };
1208 struct nfs_server *server = NFS_SERVER(state->inode);
1211 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1217 case -NFS4ERR_BADSESSION:
1218 case -NFS4ERR_BADSLOT:
1219 case -NFS4ERR_BAD_HIGH_SLOT:
1220 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1221 case -NFS4ERR_DEADSESSION:
1222 nfs4_schedule_state_recovery(
1223 server->nfs_client);
1225 case -NFS4ERR_STALE_CLIENTID:
1226 case -NFS4ERR_STALE_STATEID:
1227 case -NFS4ERR_EXPIRED:
1228 /* Don't recall a delegation if it was lost */
1229 nfs4_schedule_state_recovery(server->nfs_client);
1233 * The show must go on: exit, but mark the
1234 * stateid as needing recovery.
1236 case -NFS4ERR_ADMIN_REVOKED:
1237 case -NFS4ERR_BAD_STATEID:
1238 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
1243 err = nfs4_handle_exception(server, err, &exception);
1244 } while (exception.retry);
1249 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1251 struct nfs4_opendata *data = calldata;
1253 data->rpc_status = task->tk_status;
1254 if (RPC_ASSASSINATED(task))
1256 if (data->rpc_status == 0) {
1257 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1258 sizeof(data->o_res.stateid.data));
1259 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1260 renew_lease(data->o_res.server, data->timestamp);
1265 static void nfs4_open_confirm_release(void *calldata)
1267 struct nfs4_opendata *data = calldata;
1268 struct nfs4_state *state = NULL;
1270 /* If this request hasn't been cancelled, do nothing */
1271 if (data->cancelled == 0)
1273 /* In case of error, no cleanup! */
1274 if (!data->rpc_done)
1276 state = nfs4_opendata_to_nfs4_state(data);
1278 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1280 nfs4_opendata_put(data);
1283 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1284 .rpc_call_done = nfs4_open_confirm_done,
1285 .rpc_release = nfs4_open_confirm_release,
1289 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1291 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1293 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1294 struct rpc_task *task;
1295 struct rpc_message msg = {
1296 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1297 .rpc_argp = &data->c_arg,
1298 .rpc_resp = &data->c_res,
1299 .rpc_cred = data->owner->so_cred,
1301 struct rpc_task_setup task_setup_data = {
1302 .rpc_client = server->client,
1303 .rpc_message = &msg,
1304 .callback_ops = &nfs4_open_confirm_ops,
1305 .callback_data = data,
1306 .workqueue = nfsiod_workqueue,
1307 .flags = RPC_TASK_ASYNC,
1311 kref_get(&data->kref);
1313 data->rpc_status = 0;
1314 data->timestamp = jiffies;
1315 task = rpc_run_task(&task_setup_data);
1317 return PTR_ERR(task);
1318 status = nfs4_wait_for_completion_rpc_task(task);
1320 data->cancelled = 1;
1323 status = data->rpc_status;
1328 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1330 struct nfs4_opendata *data = calldata;
1331 struct nfs4_state_owner *sp = data->owner;
1333 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1336 * Check if we still need to send an OPEN call, or if we can use
1337 * a delegation instead.
1339 if (data->state != NULL) {
1340 struct nfs_delegation *delegation;
1342 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1345 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1346 if (delegation != NULL &&
1347 test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
1353 /* Update sequence id. */
1354 data->o_arg.id = sp->so_owner_id.id;
1355 data->o_arg.clientid = sp->so_client->cl_clientid;
1356 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1357 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1358 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1360 data->timestamp = jiffies;
1361 if (nfs4_setup_sequence(data->o_arg.server->nfs_client,
1362 &data->o_arg.seq_args,
1363 &data->o_res.seq_res, 1, task))
1365 rpc_call_start(task);
1368 task->tk_action = NULL;
1372 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1374 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1375 nfs4_open_prepare(task, calldata);
1378 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1380 struct nfs4_opendata *data = calldata;
1382 data->rpc_status = task->tk_status;
1384 nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res,
1387 if (RPC_ASSASSINATED(task))
1389 if (task->tk_status == 0) {
1390 switch (data->o_res.f_attr->mode & S_IFMT) {
1394 data->rpc_status = -ELOOP;
1397 data->rpc_status = -EISDIR;
1400 data->rpc_status = -ENOTDIR;
1402 renew_lease(data->o_res.server, data->timestamp);
1403 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1404 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1409 static void nfs4_open_release(void *calldata)
1411 struct nfs4_opendata *data = calldata;
1412 struct nfs4_state *state = NULL;
1414 /* If this request hasn't been cancelled, do nothing */
1415 if (data->cancelled == 0)
1417 /* In case of error, no cleanup! */
1418 if (data->rpc_status != 0 || !data->rpc_done)
1420 /* In case we need an open_confirm, no cleanup! */
1421 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1423 state = nfs4_opendata_to_nfs4_state(data);
1425 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1427 nfs4_opendata_put(data);
1430 static const struct rpc_call_ops nfs4_open_ops = {
1431 .rpc_call_prepare = nfs4_open_prepare,
1432 .rpc_call_done = nfs4_open_done,
1433 .rpc_release = nfs4_open_release,
1436 static const struct rpc_call_ops nfs4_recover_open_ops = {
1437 .rpc_call_prepare = nfs4_recover_open_prepare,
1438 .rpc_call_done = nfs4_open_done,
1439 .rpc_release = nfs4_open_release,
1442 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1444 struct inode *dir = data->dir->d_inode;
1445 struct nfs_server *server = NFS_SERVER(dir);
1446 struct nfs_openargs *o_arg = &data->o_arg;
1447 struct nfs_openres *o_res = &data->o_res;
1448 struct rpc_task *task;
1449 struct rpc_message msg = {
1450 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1453 .rpc_cred = data->owner->so_cred,
1455 struct rpc_task_setup task_setup_data = {
1456 .rpc_client = server->client,
1457 .rpc_message = &msg,
1458 .callback_ops = &nfs4_open_ops,
1459 .callback_data = data,
1460 .workqueue = nfsiod_workqueue,
1461 .flags = RPC_TASK_ASYNC,
1465 kref_get(&data->kref);
1467 data->rpc_status = 0;
1468 data->cancelled = 0;
1470 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1471 task = rpc_run_task(&task_setup_data);
1473 return PTR_ERR(task);
1474 status = nfs4_wait_for_completion_rpc_task(task);
1476 data->cancelled = 1;
1479 status = data->rpc_status;
1485 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1487 struct inode *dir = data->dir->d_inode;
1488 struct nfs_openres *o_res = &data->o_res;
1491 status = nfs4_run_open_task(data, 1);
1492 if (status != 0 || !data->rpc_done)
1495 nfs_refresh_inode(dir, o_res->dir_attr);
1497 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1498 status = _nfs4_proc_open_confirm(data);
1507 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1509 static int _nfs4_proc_open(struct nfs4_opendata *data)
1511 struct inode *dir = data->dir->d_inode;
1512 struct nfs_server *server = NFS_SERVER(dir);
1513 struct nfs_openargs *o_arg = &data->o_arg;
1514 struct nfs_openres *o_res = &data->o_res;
1517 status = nfs4_run_open_task(data, 0);
1518 if (status != 0 || !data->rpc_done)
1521 if (o_arg->open_flags & O_CREAT) {
1522 update_changeattr(dir, &o_res->cinfo);
1523 nfs_post_op_update_inode(dir, o_res->dir_attr);
1525 nfs_refresh_inode(dir, o_res->dir_attr);
1526 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1527 server->caps &= ~NFS_CAP_POSIX_LOCK;
1528 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1529 status = _nfs4_proc_open_confirm(data);
1533 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1534 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1538 static int nfs4_recover_expired_lease(struct nfs_server *server)
1540 struct nfs_client *clp = server->nfs_client;
1544 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1545 ret = nfs4_wait_clnt_recover(clp);
1548 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1549 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1551 nfs4_schedule_state_recovery(clp);
1559 * reclaim state on the server after a network partition.
1560 * Assumes caller holds the appropriate lock
1562 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1564 struct nfs4_opendata *opendata;
1567 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1568 if (IS_ERR(opendata))
1569 return PTR_ERR(opendata);
1570 ret = nfs4_open_recover(opendata, state);
1572 d_drop(ctx->path.dentry);
1573 nfs4_opendata_put(opendata);
1577 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1579 struct nfs_server *server = NFS_SERVER(state->inode);
1580 struct nfs4_exception exception = { };
1584 err = _nfs4_open_expired(ctx, state);
1588 case -NFS4ERR_GRACE:
1589 case -NFS4ERR_DELAY:
1591 nfs4_handle_exception(server, err, &exception);
1594 } while (exception.retry);
1599 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1601 struct nfs_open_context *ctx;
1604 ctx = nfs4_state_find_open_context(state);
1606 return PTR_ERR(ctx);
1607 ret = nfs4_do_open_expired(ctx, state);
1608 put_nfs_open_context(ctx);
1613 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1614 * fields corresponding to attributes that were used to store the verifier.
1615 * Make sure we clobber those fields in the later setattr call
1617 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1619 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1620 !(sattr->ia_valid & ATTR_ATIME_SET))
1621 sattr->ia_valid |= ATTR_ATIME;
1623 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1624 !(sattr->ia_valid & ATTR_MTIME_SET))
1625 sattr->ia_valid |= ATTR_MTIME;
1629 * Returns a referenced nfs4_state
1631 static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
1633 struct nfs4_state_owner *sp;
1634 struct nfs4_state *state = NULL;
1635 struct nfs_server *server = NFS_SERVER(dir);
1636 struct nfs4_opendata *opendata;
1639 /* Protect against reboot recovery conflicts */
1641 if (!(sp = nfs4_get_state_owner(server, cred))) {
1642 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1645 status = nfs4_recover_expired_lease(server);
1647 goto err_put_state_owner;
1648 if (path->dentry->d_inode != NULL)
1649 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1651 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr);
1652 if (opendata == NULL)
1653 goto err_put_state_owner;
1655 if (path->dentry->d_inode != NULL)
1656 opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
1658 status = _nfs4_proc_open(opendata);
1660 goto err_opendata_put;
1662 if (opendata->o_arg.open_flags & O_EXCL)
1663 nfs4_exclusive_attrset(opendata, sattr);
1665 state = nfs4_opendata_to_nfs4_state(opendata);
1666 status = PTR_ERR(state);
1668 goto err_opendata_put;
1669 if (server->caps & NFS_CAP_POSIX_LOCK)
1670 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1671 nfs4_opendata_put(opendata);
1672 nfs4_put_state_owner(sp);
1676 nfs4_opendata_put(opendata);
1677 err_put_state_owner:
1678 nfs4_put_state_owner(sp);
1685 static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, int flags, struct iattr *sattr, struct rpc_cred *cred)
1687 struct nfs4_exception exception = { };
1688 struct nfs4_state *res;
1692 status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
1695 /* NOTE: BAD_SEQID means the server and client disagree about the
1696 * book-keeping w.r.t. state-changing operations
1697 * (OPEN/CLOSE/LOCK/LOCKU...)
1698 * It is actually a sign of a bug on the client or on the server.
1700 * If we receive a BAD_SEQID error in the particular case of
1701 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1702 * have unhashed the old state_owner for us, and that we can
1703 * therefore safely retry using a new one. We should still warn
1704 * the user though...
1706 if (status == -NFS4ERR_BAD_SEQID) {
1707 printk(KERN_WARNING "NFS: v4 server %s "
1708 " returned a bad sequence-id error!\n",
1709 NFS_SERVER(dir)->nfs_client->cl_hostname);
1710 exception.retry = 1;
1714 * BAD_STATEID on OPEN means that the server cancelled our
1715 * state before it received the OPEN_CONFIRM.
1716 * Recover by retrying the request as per the discussion
1717 * on Page 181 of RFC3530.
1719 if (status == -NFS4ERR_BAD_STATEID) {
1720 exception.retry = 1;
1723 if (status == -EAGAIN) {
1724 /* We must have found a delegation */
1725 exception.retry = 1;
1728 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1729 status, &exception));
1730 } while (exception.retry);
1734 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1735 struct nfs_fattr *fattr, struct iattr *sattr,
1736 struct nfs4_state *state)
1738 struct nfs_server *server = NFS_SERVER(inode);
1739 struct nfs_setattrargs arg = {
1740 .fh = NFS_FH(inode),
1743 .bitmask = server->attr_bitmask,
1745 struct nfs_setattrres res = {
1749 struct rpc_message msg = {
1750 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1755 unsigned long timestamp = jiffies;
1758 nfs_fattr_init(fattr);
1760 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1761 /* Use that stateid */
1762 } else if (state != NULL) {
1763 nfs4_copy_stateid(&arg.stateid, state, current->files);
1765 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1767 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
1768 if (status == 0 && state != NULL)
1769 renew_lease(server, timestamp);
1773 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1774 struct nfs_fattr *fattr, struct iattr *sattr,
1775 struct nfs4_state *state)
1777 struct nfs_server *server = NFS_SERVER(inode);
1778 struct nfs4_exception exception = { };
1781 err = nfs4_handle_exception(server,
1782 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1784 } while (exception.retry);
1788 struct nfs4_closedata {
1790 struct inode *inode;
1791 struct nfs4_state *state;
1792 struct nfs_closeargs arg;
1793 struct nfs_closeres res;
1794 struct nfs_fattr fattr;
1795 unsigned long timestamp;
1798 static void nfs4_free_closedata(void *data)
1800 struct nfs4_closedata *calldata = data;
1801 struct nfs4_state_owner *sp = calldata->state->owner;
1803 nfs4_put_open_state(calldata->state);
1804 nfs_free_seqid(calldata->arg.seqid);
1805 nfs4_put_state_owner(sp);
1806 path_put(&calldata->path);
1810 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1813 spin_lock(&state->owner->so_lock);
1814 if (!(fmode & FMODE_READ))
1815 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1816 if (!(fmode & FMODE_WRITE))
1817 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1818 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1819 spin_unlock(&state->owner->so_lock);
1822 static void nfs4_close_done(struct rpc_task *task, void *data)
1824 struct nfs4_closedata *calldata = data;
1825 struct nfs4_state *state = calldata->state;
1826 struct nfs_server *server = NFS_SERVER(calldata->inode);
1828 nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status);
1829 if (RPC_ASSASSINATED(task))
1831 /* hmm. we are done with the inode, and in the process of freeing
1832 * the state_owner. we keep this around to process errors
1834 switch (task->tk_status) {
1836 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1837 renew_lease(server, calldata->timestamp);
1838 nfs4_close_clear_stateid_flags(state,
1839 calldata->arg.fmode);
1841 case -NFS4ERR_STALE_STATEID:
1842 case -NFS4ERR_OLD_STATEID:
1843 case -NFS4ERR_BAD_STATEID:
1844 case -NFS4ERR_EXPIRED:
1845 if (calldata->arg.fmode == 0)
1848 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1849 rpc_restart_call_prepare(task);
1851 nfs_release_seqid(calldata->arg.seqid);
1852 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1855 static void nfs4_close_prepare(struct rpc_task *task, void *data)
1857 struct nfs4_closedata *calldata = data;
1858 struct nfs4_state *state = calldata->state;
1861 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1864 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1865 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1866 spin_lock(&state->owner->so_lock);
1867 /* Calculate the change in open mode */
1868 if (state->n_rdwr == 0) {
1869 if (state->n_rdonly == 0) {
1870 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1871 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1872 calldata->arg.fmode &= ~FMODE_READ;
1874 if (state->n_wronly == 0) {
1875 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1876 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1877 calldata->arg.fmode &= ~FMODE_WRITE;
1880 spin_unlock(&state->owner->so_lock);
1883 /* Note: exit _without_ calling nfs4_close_done */
1884 task->tk_action = NULL;
1888 if (calldata->arg.fmode == 0)
1889 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1891 nfs_fattr_init(calldata->res.fattr);
1892 calldata->timestamp = jiffies;
1893 if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client,
1894 &calldata->arg.seq_args, &calldata->res.seq_res,
1897 rpc_call_start(task);
1900 static const struct rpc_call_ops nfs4_close_ops = {
1901 .rpc_call_prepare = nfs4_close_prepare,
1902 .rpc_call_done = nfs4_close_done,
1903 .rpc_release = nfs4_free_closedata,
1907 * It is possible for data to be read/written from a mem-mapped file
1908 * after the sys_close call (which hits the vfs layer as a flush).
1909 * This means that we can't safely call nfsv4 close on a file until
1910 * the inode is cleared. This in turn means that we are not good
1911 * NFSv4 citizens - we do not indicate to the server to update the file's
1912 * share state even when we are done with one of the three share
1913 * stateid's in the inode.
1915 * NOTE: Caller must be holding the sp->so_owner semaphore!
1917 int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1919 struct nfs_server *server = NFS_SERVER(state->inode);
1920 struct nfs4_closedata *calldata;
1921 struct nfs4_state_owner *sp = state->owner;
1922 struct rpc_task *task;
1923 struct rpc_message msg = {
1924 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
1925 .rpc_cred = state->owner->so_cred,
1927 struct rpc_task_setup task_setup_data = {
1928 .rpc_client = server->client,
1929 .rpc_message = &msg,
1930 .callback_ops = &nfs4_close_ops,
1931 .workqueue = nfsiod_workqueue,
1932 .flags = RPC_TASK_ASYNC,
1934 int status = -ENOMEM;
1936 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
1937 if (calldata == NULL)
1939 calldata->inode = state->inode;
1940 calldata->state = state;
1941 calldata->arg.fh = NFS_FH(state->inode);
1942 calldata->arg.stateid = &state->open_stateid;
1943 /* Serialization for the sequence id */
1944 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
1945 if (calldata->arg.seqid == NULL)
1946 goto out_free_calldata;
1947 calldata->arg.fmode = 0;
1948 calldata->arg.bitmask = server->cache_consistency_bitmask;
1949 calldata->res.fattr = &calldata->fattr;
1950 calldata->res.seqid = calldata->arg.seqid;
1951 calldata->res.server = server;
1952 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
1954 calldata->path = *path;
1956 msg.rpc_argp = &calldata->arg,
1957 msg.rpc_resp = &calldata->res,
1958 task_setup_data.callback_data = calldata;
1959 task = rpc_run_task(&task_setup_data);
1961 return PTR_ERR(task);
1964 status = rpc_wait_for_completion_task(task);
1970 nfs4_put_open_state(state);
1971 nfs4_put_state_owner(sp);
1975 static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode)
1980 /* If the open_intent is for execute, we have an extra check to make */
1981 if (fmode & FMODE_EXEC) {
1982 ret = nfs_may_open(state->inode,
1983 state->owner->so_cred,
1984 nd->intent.open.flags);
1988 filp = lookup_instantiate_filp(nd, path->dentry, NULL);
1989 if (!IS_ERR(filp)) {
1990 struct nfs_open_context *ctx;
1991 ctx = nfs_file_open_context(filp);
1995 ret = PTR_ERR(filp);
1997 nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
2002 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
2004 struct path path = {
2005 .mnt = nd->path.mnt,
2008 struct dentry *parent;
2010 struct rpc_cred *cred;
2011 struct nfs4_state *state;
2013 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
2015 if (nd->flags & LOOKUP_CREATE) {
2016 attr.ia_mode = nd->intent.open.create_mode;
2017 attr.ia_valid = ATTR_MODE;
2018 if (!IS_POSIXACL(dir))
2019 attr.ia_mode &= ~current_umask();
2022 BUG_ON(nd->intent.open.flags & O_CREAT);
2025 cred = rpc_lookup_cred();
2027 return (struct dentry *)cred;
2028 parent = dentry->d_parent;
2029 /* Protect against concurrent sillydeletes */
2030 nfs_block_sillyrename(parent);
2031 state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred);
2033 if (IS_ERR(state)) {
2034 if (PTR_ERR(state) == -ENOENT) {
2035 d_add(dentry, NULL);
2036 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2038 nfs_unblock_sillyrename(parent);
2039 return (struct dentry *)state;
2041 res = d_add_unique(dentry, igrab(state->inode));
2044 nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
2045 nfs_unblock_sillyrename(parent);
2046 nfs4_intent_set_file(nd, &path, state, fmode);
2051 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
2053 struct path path = {
2054 .mnt = nd->path.mnt,
2057 struct rpc_cred *cred;
2058 struct nfs4_state *state;
2059 fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
2061 cred = rpc_lookup_cred();
2063 return PTR_ERR(cred);
2064 state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
2066 if (IS_ERR(state)) {
2067 switch (PTR_ERR(state)) {
2073 return PTR_ERR(state);
2078 if (state->inode == dentry->d_inode) {
2079 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2080 nfs4_intent_set_file(nd, &path, state, fmode);
2083 nfs4_close_sync(&path, state, fmode);
2089 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2091 if (ctx->state == NULL)
2094 nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
2096 nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
2099 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2101 struct nfs4_server_caps_arg args = {
2104 struct nfs4_server_caps_res res = {};
2105 struct rpc_message msg = {
2106 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2112 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2114 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2115 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2116 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2117 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2118 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2119 NFS_CAP_CTIME|NFS_CAP_MTIME);
2120 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2121 server->caps |= NFS_CAP_ACLS;
2122 if (res.has_links != 0)
2123 server->caps |= NFS_CAP_HARDLINKS;
2124 if (res.has_symlinks != 0)
2125 server->caps |= NFS_CAP_SYMLINKS;
2126 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2127 server->caps |= NFS_CAP_FILEID;
2128 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2129 server->caps |= NFS_CAP_MODE;
2130 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2131 server->caps |= NFS_CAP_NLINK;
2132 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2133 server->caps |= NFS_CAP_OWNER;
2134 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2135 server->caps |= NFS_CAP_OWNER_GROUP;
2136 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2137 server->caps |= NFS_CAP_ATIME;
2138 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2139 server->caps |= NFS_CAP_CTIME;
2140 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2141 server->caps |= NFS_CAP_MTIME;
2143 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2144 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2145 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2146 server->acl_bitmask = res.acl_bitmask;
2152 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2154 struct nfs4_exception exception = { };
2157 err = nfs4_handle_exception(server,
2158 _nfs4_server_capabilities(server, fhandle),
2160 } while (exception.retry);
2164 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2165 struct nfs_fsinfo *info)
2167 struct nfs4_lookup_root_arg args = {
2168 .bitmask = nfs4_fattr_bitmap,
2170 struct nfs4_lookup_res res = {
2172 .fattr = info->fattr,
2175 struct rpc_message msg = {
2176 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2181 nfs_fattr_init(info->fattr);
2182 return nfs4_call_sync(server, &msg, &args, &res, 0);
2185 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2186 struct nfs_fsinfo *info)
2188 struct nfs4_exception exception = { };
2191 err = nfs4_handle_exception(server,
2192 _nfs4_lookup_root(server, fhandle, info),
2194 } while (exception.retry);
2199 * get the file handle for the "/" directory on the server
2201 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2202 struct nfs_fsinfo *info)
2206 status = nfs4_lookup_root(server, fhandle, info);
2208 status = nfs4_server_capabilities(server, fhandle);
2210 status = nfs4_do_fsinfo(server, fhandle, info);
2211 return nfs4_map_errors(status);
2215 * Get locations and (maybe) other attributes of a referral.
2216 * Note that we'll actually follow the referral later when
2217 * we detect fsid mismatch in inode revalidation
2219 static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
2221 int status = -ENOMEM;
2222 struct page *page = NULL;
2223 struct nfs4_fs_locations *locations = NULL;
2225 page = alloc_page(GFP_KERNEL);
2228 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2229 if (locations == NULL)
2232 status = nfs4_proc_fs_locations(dir, name, locations, page);
2235 /* Make sure server returned a different fsid for the referral */
2236 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2237 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
2242 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2243 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
2245 fattr->mode = S_IFDIR;
2246 memset(fhandle, 0, sizeof(struct nfs_fh));
2255 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2257 struct nfs4_getattr_arg args = {
2259 .bitmask = server->attr_bitmask,
2261 struct nfs4_getattr_res res = {
2265 struct rpc_message msg = {
2266 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2271 nfs_fattr_init(fattr);
2272 return nfs4_call_sync(server, &msg, &args, &res, 0);
2275 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2277 struct nfs4_exception exception = { };
2280 err = nfs4_handle_exception(server,
2281 _nfs4_proc_getattr(server, fhandle, fattr),
2283 } while (exception.retry);
2288 * The file is not closed if it is opened due to the a request to change
2289 * the size of the file. The open call will not be needed once the
2290 * VFS layer lookup-intents are implemented.
2292 * Close is called when the inode is destroyed.
2293 * If we haven't opened the file for O_WRONLY, we
2294 * need to in the size_change case to obtain a stateid.
2297 * Because OPEN is always done by name in nfsv4, it is
2298 * possible that we opened a different file by the same
2299 * name. We can recognize this race condition, but we
2300 * can't do anything about it besides returning an error.
2302 * This will be fixed with VFS changes (lookup-intent).
2305 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2306 struct iattr *sattr)
2308 struct inode *inode = dentry->d_inode;
2309 struct rpc_cred *cred = NULL;
2310 struct nfs4_state *state = NULL;
2313 nfs_fattr_init(fattr);
2315 /* Search for an existing open(O_WRITE) file */
2316 if (sattr->ia_valid & ATTR_FILE) {
2317 struct nfs_open_context *ctx;
2319 ctx = nfs_file_open_context(sattr->ia_file);
2326 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2328 nfs_setattr_update_inode(inode, sattr);
2332 static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh,
2333 const struct qstr *name, struct nfs_fh *fhandle,
2334 struct nfs_fattr *fattr)
2337 struct nfs4_lookup_arg args = {
2338 .bitmask = server->attr_bitmask,
2342 struct nfs4_lookup_res res = {
2347 struct rpc_message msg = {
2348 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2353 nfs_fattr_init(fattr);
2355 dprintk("NFS call lookupfh %s\n", name->name);
2356 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2357 dprintk("NFS reply lookupfh: %d\n", status);
2361 static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
2362 struct qstr *name, struct nfs_fh *fhandle,
2363 struct nfs_fattr *fattr)
2365 struct nfs4_exception exception = { };
2368 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
2370 if (err == -NFS4ERR_MOVED) {
2374 err = nfs4_handle_exception(server, err, &exception);
2375 } while (exception.retry);
2379 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name,
2380 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2384 dprintk("NFS call lookup %s\n", name->name);
2385 status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
2386 if (status == -NFS4ERR_MOVED)
2387 status = nfs4_get_referral(dir, name, fattr, fhandle);
2388 dprintk("NFS reply lookup: %d\n", status);
2392 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2394 struct nfs4_exception exception = { };
2397 err = nfs4_handle_exception(NFS_SERVER(dir),
2398 _nfs4_proc_lookup(dir, name, fhandle, fattr),
2400 } while (exception.retry);
2404 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2406 struct nfs_server *server = NFS_SERVER(inode);
2407 struct nfs4_accessargs args = {
2408 .fh = NFS_FH(inode),
2409 .bitmask = server->attr_bitmask,
2411 struct nfs4_accessres res = {
2414 struct rpc_message msg = {
2415 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2418 .rpc_cred = entry->cred,
2420 int mode = entry->mask;
2424 * Determine which access bits we want to ask for...
2426 if (mode & MAY_READ)
2427 args.access |= NFS4_ACCESS_READ;
2428 if (S_ISDIR(inode->i_mode)) {
2429 if (mode & MAY_WRITE)
2430 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2431 if (mode & MAY_EXEC)
2432 args.access |= NFS4_ACCESS_LOOKUP;
2434 if (mode & MAY_WRITE)
2435 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2436 if (mode & MAY_EXEC)
2437 args.access |= NFS4_ACCESS_EXECUTE;
2440 res.fattr = nfs_alloc_fattr();
2441 if (res.fattr == NULL)
2444 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2447 if (res.access & NFS4_ACCESS_READ)
2448 entry->mask |= MAY_READ;
2449 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2450 entry->mask |= MAY_WRITE;
2451 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2452 entry->mask |= MAY_EXEC;
2453 nfs_refresh_inode(inode, res.fattr);
2455 nfs_free_fattr(res.fattr);
2459 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2461 struct nfs4_exception exception = { };
2464 err = nfs4_handle_exception(NFS_SERVER(inode),
2465 _nfs4_proc_access(inode, entry),
2467 } while (exception.retry);
2472 * TODO: For the time being, we don't try to get any attributes
2473 * along with any of the zero-copy operations READ, READDIR,
2476 * In the case of the first three, we want to put the GETATTR
2477 * after the read-type operation -- this is because it is hard
2478 * to predict the length of a GETATTR response in v4, and thus
2479 * align the READ data correctly. This means that the GETATTR
2480 * may end up partially falling into the page cache, and we should
2481 * shift it into the 'tail' of the xdr_buf before processing.
2482 * To do this efficiently, we need to know the total length
2483 * of data received, which doesn't seem to be available outside
2486 * In the case of WRITE, we also want to put the GETATTR after
2487 * the operation -- in this case because we want to make sure
2488 * we get the post-operation mtime and size. This means that
2489 * we can't use xdr_encode_pages() as written: we need a variant
2490 * of it which would leave room in the 'tail' iovec.
2492 * Both of these changes to the XDR layer would in fact be quite
2493 * minor, but I decided to leave them for a subsequent patch.
2495 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2496 unsigned int pgbase, unsigned int pglen)
2498 struct nfs4_readlink args = {
2499 .fh = NFS_FH(inode),
2504 struct nfs4_readlink_res res;
2505 struct rpc_message msg = {
2506 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2511 return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
2514 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2515 unsigned int pgbase, unsigned int pglen)
2517 struct nfs4_exception exception = { };
2520 err = nfs4_handle_exception(NFS_SERVER(inode),
2521 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2523 } while (exception.retry);
2529 * We will need to arrange for the VFS layer to provide an atomic open.
2530 * Until then, this create/open method is prone to inefficiency and race
2531 * conditions due to the lookup, create, and open VFS calls from sys_open()
2532 * placed on the wire.
2534 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2535 * The file will be opened again in the subsequent VFS open call
2536 * (nfs4_proc_file_open).
2538 * The open for read will just hang around to be used by any process that
2539 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2543 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2544 int flags, struct nameidata *nd)
2546 struct path path = {
2547 .mnt = nd->path.mnt,
2550 struct nfs4_state *state;
2551 struct rpc_cred *cred;
2552 fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE);
2555 cred = rpc_lookup_cred();
2557 status = PTR_ERR(cred);
2560 state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred);
2562 if (IS_ERR(state)) {
2563 status = PTR_ERR(state);
2566 d_add(dentry, igrab(state->inode));
2567 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2568 if (flags & O_EXCL) {
2569 struct nfs_fattr fattr;
2570 status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state);
2572 nfs_setattr_update_inode(state->inode, sattr);
2573 nfs_post_op_update_inode(state->inode, &fattr);
2575 if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
2576 status = nfs4_intent_set_file(nd, &path, state, fmode);
2578 nfs4_close_sync(&path, state, fmode);
2585 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2587 struct nfs_server *server = NFS_SERVER(dir);
2588 struct nfs_removeargs args = {
2590 .name.len = name->len,
2591 .name.name = name->name,
2592 .bitmask = server->attr_bitmask,
2594 struct nfs_removeres res = {
2597 struct rpc_message msg = {
2598 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2604 nfs_fattr_init(&res.dir_attr);
2605 status = nfs4_call_sync(server, &msg, &args, &res, 1);
2607 update_changeattr(dir, &res.cinfo);
2608 nfs_post_op_update_inode(dir, &res.dir_attr);
2613 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2615 struct nfs4_exception exception = { };
2618 err = nfs4_handle_exception(NFS_SERVER(dir),
2619 _nfs4_proc_remove(dir, name),
2621 } while (exception.retry);
2625 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2627 struct nfs_server *server = NFS_SERVER(dir);
2628 struct nfs_removeargs *args = msg->rpc_argp;
2629 struct nfs_removeres *res = msg->rpc_resp;
2631 args->bitmask = server->cache_consistency_bitmask;
2632 res->server = server;
2633 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2636 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2638 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2640 nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
2641 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2643 update_changeattr(dir, &res->cinfo);
2644 nfs_post_op_update_inode(dir, &res->dir_attr);
2648 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2649 struct inode *new_dir, struct qstr *new_name)
2651 struct nfs_server *server = NFS_SERVER(old_dir);
2652 struct nfs4_rename_arg arg = {
2653 .old_dir = NFS_FH(old_dir),
2654 .new_dir = NFS_FH(new_dir),
2655 .old_name = old_name,
2656 .new_name = new_name,
2657 .bitmask = server->attr_bitmask,
2659 struct nfs_fattr old_fattr, new_fattr;
2660 struct nfs4_rename_res res = {
2662 .old_fattr = &old_fattr,
2663 .new_fattr = &new_fattr,
2665 struct rpc_message msg = {
2666 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2672 nfs_fattr_init(res.old_fattr);
2673 nfs_fattr_init(res.new_fattr);
2674 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2677 update_changeattr(old_dir, &res.old_cinfo);
2678 nfs_post_op_update_inode(old_dir, res.old_fattr);
2679 update_changeattr(new_dir, &res.new_cinfo);
2680 nfs_post_op_update_inode(new_dir, res.new_fattr);
2685 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2686 struct inode *new_dir, struct qstr *new_name)
2688 struct nfs4_exception exception = { };
2691 err = nfs4_handle_exception(NFS_SERVER(old_dir),
2692 _nfs4_proc_rename(old_dir, old_name,
2695 } while (exception.retry);
2699 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2701 struct nfs_server *server = NFS_SERVER(inode);
2702 struct nfs4_link_arg arg = {
2703 .fh = NFS_FH(inode),
2704 .dir_fh = NFS_FH(dir),
2706 .bitmask = server->attr_bitmask,
2708 struct nfs_fattr fattr, dir_attr;
2709 struct nfs4_link_res res = {
2712 .dir_attr = &dir_attr,
2714 struct rpc_message msg = {
2715 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2721 nfs_fattr_init(res.fattr);
2722 nfs_fattr_init(res.dir_attr);
2723 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2725 update_changeattr(dir, &res.cinfo);
2726 nfs_post_op_update_inode(dir, res.dir_attr);
2727 nfs_post_op_update_inode(inode, res.fattr);
2733 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2735 struct nfs4_exception exception = { };
2738 err = nfs4_handle_exception(NFS_SERVER(inode),
2739 _nfs4_proc_link(inode, dir, name),
2741 } while (exception.retry);
2745 struct nfs4_createdata {
2746 struct rpc_message msg;
2747 struct nfs4_create_arg arg;
2748 struct nfs4_create_res res;
2750 struct nfs_fattr fattr;
2751 struct nfs_fattr dir_fattr;
2754 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2755 struct qstr *name, struct iattr *sattr, u32 ftype)
2757 struct nfs4_createdata *data;
2759 data = kzalloc(sizeof(*data), GFP_KERNEL);
2761 struct nfs_server *server = NFS_SERVER(dir);
2763 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2764 data->msg.rpc_argp = &data->arg;
2765 data->msg.rpc_resp = &data->res;
2766 data->arg.dir_fh = NFS_FH(dir);
2767 data->arg.server = server;
2768 data->arg.name = name;
2769 data->arg.attrs = sattr;
2770 data->arg.ftype = ftype;
2771 data->arg.bitmask = server->attr_bitmask;
2772 data->res.server = server;
2773 data->res.fh = &data->fh;
2774 data->res.fattr = &data->fattr;
2775 data->res.dir_fattr = &data->dir_fattr;
2776 nfs_fattr_init(data->res.fattr);
2777 nfs_fattr_init(data->res.dir_fattr);
2782 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2784 int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg,
2785 &data->arg, &data->res, 1);
2787 update_changeattr(dir, &data->res.dir_cinfo);
2788 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2789 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2794 static void nfs4_free_createdata(struct nfs4_createdata *data)
2799 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2800 struct page *page, unsigned int len, struct iattr *sattr)
2802 struct nfs4_createdata *data;
2803 int status = -ENAMETOOLONG;
2805 if (len > NFS4_MAXPATHLEN)
2809 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2813 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2814 data->arg.u.symlink.pages = &page;
2815 data->arg.u.symlink.len = len;
2817 status = nfs4_do_create(dir, dentry, data);
2819 nfs4_free_createdata(data);
2824 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2825 struct page *page, unsigned int len, struct iattr *sattr)
2827 struct nfs4_exception exception = { };
2830 err = nfs4_handle_exception(NFS_SERVER(dir),
2831 _nfs4_proc_symlink(dir, dentry, page,
2834 } while (exception.retry);
2838 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2839 struct iattr *sattr)
2841 struct nfs4_createdata *data;
2842 int status = -ENOMEM;
2844 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2848 status = nfs4_do_create(dir, dentry, data);
2850 nfs4_free_createdata(data);
2855 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2856 struct iattr *sattr)
2858 struct nfs4_exception exception = { };
2861 err = nfs4_handle_exception(NFS_SERVER(dir),
2862 _nfs4_proc_mkdir(dir, dentry, sattr),
2864 } while (exception.retry);
2868 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2869 u64 cookie, struct page *page, unsigned int count, int plus)
2871 struct inode *dir = dentry->d_inode;
2872 struct nfs4_readdir_arg args = {
2877 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2879 struct nfs4_readdir_res res;
2880 struct rpc_message msg = {
2881 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2888 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
2889 dentry->d_parent->d_name.name,
2890 dentry->d_name.name,
2891 (unsigned long long)cookie);
2892 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2893 res.pgbase = args.pgbase;
2894 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2896 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2898 nfs_invalidate_atime(dir);
2900 dprintk("%s: returns %d\n", __func__, status);
2904 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2905 u64 cookie, struct page *page, unsigned int count, int plus)
2907 struct nfs4_exception exception = { };
2910 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2911 _nfs4_proc_readdir(dentry, cred, cookie,
2914 } while (exception.retry);
2918 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2919 struct iattr *sattr, dev_t rdev)
2921 struct nfs4_createdata *data;
2922 int mode = sattr->ia_mode;
2923 int status = -ENOMEM;
2925 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2926 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2928 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
2933 data->arg.ftype = NF4FIFO;
2934 else if (S_ISBLK(mode)) {
2935 data->arg.ftype = NF4BLK;
2936 data->arg.u.device.specdata1 = MAJOR(rdev);
2937 data->arg.u.device.specdata2 = MINOR(rdev);
2939 else if (S_ISCHR(mode)) {
2940 data->arg.ftype = NF4CHR;
2941 data->arg.u.device.specdata1 = MAJOR(rdev);
2942 data->arg.u.device.specdata2 = MINOR(rdev);
2945 status = nfs4_do_create(dir, dentry, data);
2947 nfs4_free_createdata(data);
2952 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2953 struct iattr *sattr, dev_t rdev)
2955 struct nfs4_exception exception = { };
2958 err = nfs4_handle_exception(NFS_SERVER(dir),
2959 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2961 } while (exception.retry);
2965 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2966 struct nfs_fsstat *fsstat)
2968 struct nfs4_statfs_arg args = {
2970 .bitmask = server->attr_bitmask,
2972 struct nfs4_statfs_res res = {
2975 struct rpc_message msg = {
2976 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2981 nfs_fattr_init(fsstat->fattr);
2982 return nfs4_call_sync(server, &msg, &args, &res, 0);
2985 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
2987 struct nfs4_exception exception = { };
2990 err = nfs4_handle_exception(server,
2991 _nfs4_proc_statfs(server, fhandle, fsstat),
2993 } while (exception.retry);
2997 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
2998 struct nfs_fsinfo *fsinfo)
3000 struct nfs4_fsinfo_arg args = {
3002 .bitmask = server->attr_bitmask,
3004 struct nfs4_fsinfo_res res = {
3007 struct rpc_message msg = {
3008 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3013 return nfs4_call_sync(server, &msg, &args, &res, 0);
3016 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3018 struct nfs4_exception exception = { };
3022 err = nfs4_handle_exception(server,
3023 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3025 } while (exception.retry);
3029 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3031 nfs_fattr_init(fsinfo->fattr);
3032 return nfs4_do_fsinfo(server, fhandle, fsinfo);
3035 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3036 struct nfs_pathconf *pathconf)
3038 struct nfs4_pathconf_arg args = {
3040 .bitmask = server->attr_bitmask,
3042 struct nfs4_pathconf_res res = {
3043 .pathconf = pathconf,
3045 struct rpc_message msg = {
3046 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3051 /* None of the pathconf attributes are mandatory to implement */
3052 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3053 memset(pathconf, 0, sizeof(*pathconf));
3057 nfs_fattr_init(pathconf->fattr);
3058 return nfs4_call_sync(server, &msg, &args, &res, 0);
3061 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3062 struct nfs_pathconf *pathconf)
3064 struct nfs4_exception exception = { };
3068 err = nfs4_handle_exception(server,
3069 _nfs4_proc_pathconf(server, fhandle, pathconf),
3071 } while (exception.retry);
3075 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3077 struct nfs_server *server = NFS_SERVER(data->inode);
3079 dprintk("--> %s\n", __func__);
3081 nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
3083 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3084 nfs_restart_rpc(task, server->nfs_client);
3088 nfs_invalidate_atime(data->inode);
3089 if (task->tk_status > 0)
3090 renew_lease(server, data->timestamp);
3094 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3096 data->timestamp = jiffies;
3097 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3100 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3102 struct inode *inode = data->inode;
3104 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3107 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3108 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3111 if (task->tk_status >= 0) {
3112 renew_lease(NFS_SERVER(inode), data->timestamp);
3113 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
3118 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3120 struct nfs_server *server = NFS_SERVER(data->inode);
3122 data->args.bitmask = server->cache_consistency_bitmask;
3123 data->res.server = server;
3124 data->timestamp = jiffies;
3126 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3129 static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3131 struct inode *inode = data->inode;
3133 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3135 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3136 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3139 nfs_refresh_inode(inode, data->res.fattr);
3143 static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
3145 struct nfs_server *server = NFS_SERVER(data->inode);
3147 data->args.bitmask = server->cache_consistency_bitmask;
3148 data->res.server = server;
3149 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3153 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3154 * standalone procedure for queueing an asynchronous RENEW.
3156 static void nfs4_renew_release(void *data)
3158 struct nfs_client *clp = data;
3160 if (atomic_read(&clp->cl_count) > 1)
3161 nfs4_schedule_state_renewal(clp);
3162 nfs_put_client(clp);
3165 static void nfs4_renew_done(struct rpc_task *task, void *data)
3167 struct nfs_client *clp = data;
3168 unsigned long timestamp = task->tk_start;
3170 if (task->tk_status < 0) {
3171 /* Unless we're shutting down, schedule state recovery! */
3172 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
3173 nfs4_schedule_state_recovery(clp);
3176 spin_lock(&clp->cl_lock);
3177 if (time_before(clp->cl_last_renewal,timestamp))
3178 clp->cl_last_renewal = timestamp;
3179 spin_unlock(&clp->cl_lock);
3182 static const struct rpc_call_ops nfs4_renew_ops = {
3183 .rpc_call_done = nfs4_renew_done,
3184 .rpc_release = nfs4_renew_release,
3187 int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3189 struct rpc_message msg = {
3190 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3195 if (!atomic_inc_not_zero(&clp->cl_count))
3197 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3198 &nfs4_renew_ops, clp);
3201 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3203 struct rpc_message msg = {
3204 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3208 unsigned long now = jiffies;
3211 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3214 spin_lock(&clp->cl_lock);
3215 if (time_before(clp->cl_last_renewal,now))
3216 clp->cl_last_renewal = now;
3217 spin_unlock(&clp->cl_lock);
3221 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3223 return (server->caps & NFS_CAP_ACLS)
3224 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3225 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3228 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3229 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3232 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3234 static void buf_to_pages(const void *buf, size_t buflen,
3235 struct page **pages, unsigned int *pgbase)
3237 const void *p = buf;
3239 *pgbase = offset_in_page(buf);
3241 while (p < buf + buflen) {
3242 *(pages++) = virt_to_page(p);
3243 p += PAGE_CACHE_SIZE;
3247 struct nfs4_cached_acl {
3253 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3255 struct nfs_inode *nfsi = NFS_I(inode);
3257 spin_lock(&inode->i_lock);
3258 kfree(nfsi->nfs4_acl);
3259 nfsi->nfs4_acl = acl;
3260 spin_unlock(&inode->i_lock);
3263 static void nfs4_zap_acl_attr(struct inode *inode)
3265 nfs4_set_cached_acl(inode, NULL);
3268 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3270 struct nfs_inode *nfsi = NFS_I(inode);
3271 struct nfs4_cached_acl *acl;
3274 spin_lock(&inode->i_lock);
3275 acl = nfsi->nfs4_acl;
3278 if (buf == NULL) /* user is just asking for length */
3280 if (acl->cached == 0)
3282 ret = -ERANGE; /* see getxattr(2) man page */
3283 if (acl->len > buflen)
3285 memcpy(buf, acl->data, acl->len);
3289 spin_unlock(&inode->i_lock);
3293 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
3295 struct nfs4_cached_acl *acl;
3297 if (buf && acl_len <= PAGE_SIZE) {
3298 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3302 memcpy(acl->data, buf, acl_len);
3304 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3311 nfs4_set_cached_acl(inode, acl);
3314 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3316 struct page *pages[NFS4ACL_MAXPAGES];
3317 struct nfs_getaclargs args = {
3318 .fh = NFS_FH(inode),
3322 struct nfs_getaclres res = {
3326 struct rpc_message msg = {
3327 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3331 struct page *localpage = NULL;
3334 if (buflen < PAGE_SIZE) {
3335 /* As long as we're doing a round trip to the server anyway,
3336 * let's be prepared for a page of acl data. */
3337 localpage = alloc_page(GFP_KERNEL);
3338 resp_buf = page_address(localpage);
3339 if (localpage == NULL)
3341 args.acl_pages[0] = localpage;
3342 args.acl_pgbase = 0;
3343 args.acl_len = PAGE_SIZE;
3346 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
3348 ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
3351 if (res.acl_len > args.acl_len)
3352 nfs4_write_cached_acl(inode, NULL, res.acl_len);
3354 nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
3357 if (res.acl_len > buflen)
3360 memcpy(buf, resp_buf, res.acl_len);
3365 __free_page(localpage);
3369 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3371 struct nfs4_exception exception = { };
3374 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3377 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3378 } while (exception.retry);
3382 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3384 struct nfs_server *server = NFS_SERVER(inode);
3387 if (!nfs4_server_supports_acls(server))
3389 ret = nfs_revalidate_inode(server, inode);
3392 ret = nfs4_read_cached_acl(inode, buf, buflen);
3395 return nfs4_get_acl_uncached(inode, buf, buflen);
3398 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3400 struct nfs_server *server = NFS_SERVER(inode);
3401 struct page *pages[NFS4ACL_MAXPAGES];
3402 struct nfs_setaclargs arg = {
3403 .fh = NFS_FH(inode),
3407 struct nfs_setaclres res;
3408 struct rpc_message msg = {
3409 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3415 if (!nfs4_server_supports_acls(server))
3417 nfs_inode_return_delegation(inode);
3418 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3419 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3420 nfs_access_zap_cache(inode);
3421 nfs_zap_acl_cache(inode);
3425 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3427 struct nfs4_exception exception = { };
3430 err = nfs4_handle_exception(NFS_SERVER(inode),
3431 __nfs4_proc_set_acl(inode, buf, buflen),
3433 } while (exception.retry);
3438 _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state)
3440 if (!clp || task->tk_status >= 0)
3442 switch(task->tk_status) {
3443 case -NFS4ERR_ADMIN_REVOKED:
3444 case -NFS4ERR_BAD_STATEID:
3445 case -NFS4ERR_OPENMODE:
3448 nfs4_state_mark_reclaim_nograce(clp, state);
3449 goto do_state_recovery;
3450 case -NFS4ERR_STALE_STATEID:
3453 nfs4_state_mark_reclaim_reboot(clp, state);
3454 case -NFS4ERR_STALE_CLIENTID:
3455 case -NFS4ERR_EXPIRED:
3456 goto do_state_recovery;
3457 #if defined(CONFIG_NFS_V4_1)
3458 case -NFS4ERR_BADSESSION:
3459 case -NFS4ERR_BADSLOT:
3460 case -NFS4ERR_BAD_HIGH_SLOT:
3461 case -NFS4ERR_DEADSESSION:
3462 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3463 case -NFS4ERR_SEQ_FALSE_RETRY:
3464 case -NFS4ERR_SEQ_MISORDERED:
3465 dprintk("%s ERROR %d, Reset session\n", __func__,
3467 nfs4_schedule_state_recovery(clp);
3468 task->tk_status = 0;
3470 #endif /* CONFIG_NFS_V4_1 */
3471 case -NFS4ERR_DELAY:
3473 nfs_inc_server_stats(server, NFSIOS_DELAY);
3474 case -NFS4ERR_GRACE:
3476 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3477 task->tk_status = 0;
3479 case -NFS4ERR_OLD_STATEID:
3480 task->tk_status = 0;
3483 task->tk_status = nfs4_map_errors(task->tk_status);
3486 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3487 nfs4_schedule_state_recovery(clp);
3488 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3489 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3490 task->tk_status = 0;
3495 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3497 return _nfs4_async_handle_error(task, server, server->nfs_client, state);
3500 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
3502 nfs4_verifier sc_verifier;
3503 struct nfs4_setclientid setclientid = {
3504 .sc_verifier = &sc_verifier,
3507 struct rpc_message msg = {
3508 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3509 .rpc_argp = &setclientid,
3517 p = (__be32*)sc_verifier.data;
3518 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3519 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3522 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3523 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3525 rpc_peeraddr2str(clp->cl_rpcclient,
3527 rpc_peeraddr2str(clp->cl_rpcclient,
3529 clp->cl_rpcclient->cl_auth->au_ops->au_name,
3530 clp->cl_id_uniquifier);
3531 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
3532 sizeof(setclientid.sc_netid),
3533 rpc_peeraddr2str(clp->cl_rpcclient,
3534 RPC_DISPLAY_NETID));
3535 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3536 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3537 clp->cl_ipaddr, port >> 8, port & 255);
3539 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3540 if (status != -NFS4ERR_CLID_INUSE)
3545 ssleep(clp->cl_lease_time + 1);
3547 if (++clp->cl_id_uniquifier == 0)
3553 static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
3555 struct nfs_fsinfo fsinfo;
3556 struct rpc_message msg = {
3557 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3559 .rpc_resp = &fsinfo,
3566 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3568 spin_lock(&clp->cl_lock);
3569 clp->cl_lease_time = fsinfo.lease_time * HZ;
3570 clp->cl_last_renewal = now;
3571 spin_unlock(&clp->cl_lock);
3576 int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
3581 err = _nfs4_proc_setclientid_confirm(clp, cred);
3585 case -NFS4ERR_RESOURCE:
3586 /* The IBM lawyers misread another document! */
3587 case -NFS4ERR_DELAY:
3589 err = nfs4_delay(clp->cl_rpcclient, &timeout);
3595 struct nfs4_delegreturndata {
3596 struct nfs4_delegreturnargs args;
3597 struct nfs4_delegreturnres res;
3599 nfs4_stateid stateid;
3600 unsigned long timestamp;
3601 struct nfs_fattr fattr;
3605 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3607 struct nfs4_delegreturndata *data = calldata;
3609 nfs4_sequence_done(data->res.server, &data->res.seq_res,
3612 switch (task->tk_status) {
3613 case -NFS4ERR_STALE_STATEID:
3614 case -NFS4ERR_EXPIRED:
3616 renew_lease(data->res.server, data->timestamp);
3619 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3621 nfs_restart_rpc(task, data->res.server->nfs_client);
3625 data->rpc_status = task->tk_status;
3628 static void nfs4_delegreturn_release(void *calldata)
3633 #if defined(CONFIG_NFS_V4_1)
3634 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3636 struct nfs4_delegreturndata *d_data;
3638 d_data = (struct nfs4_delegreturndata *)data;
3640 if (nfs4_setup_sequence(d_data->res.server->nfs_client,
3641 &d_data->args.seq_args,
3642 &d_data->res.seq_res, 1, task))
3644 rpc_call_start(task);
3646 #endif /* CONFIG_NFS_V4_1 */
3648 static const struct rpc_call_ops nfs4_delegreturn_ops = {
3649 #if defined(CONFIG_NFS_V4_1)
3650 .rpc_call_prepare = nfs4_delegreturn_prepare,
3651 #endif /* CONFIG_NFS_V4_1 */
3652 .rpc_call_done = nfs4_delegreturn_done,
3653 .rpc_release = nfs4_delegreturn_release,
3656 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3658 struct nfs4_delegreturndata *data;
3659 struct nfs_server *server = NFS_SERVER(inode);
3660 struct rpc_task *task;
3661 struct rpc_message msg = {
3662 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
3665 struct rpc_task_setup task_setup_data = {
3666 .rpc_client = server->client,
3667 .rpc_message = &msg,
3668 .callback_ops = &nfs4_delegreturn_ops,
3669 .flags = RPC_TASK_ASYNC,
3673 data = kzalloc(sizeof(*data), GFP_KERNEL);
3676 data->args.fhandle = &data->fh;
3677 data->args.stateid = &data->stateid;
3678 data->args.bitmask = server->attr_bitmask;
3679 nfs_copy_fh(&data->fh, NFS_FH(inode));
3680 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3681 data->res.fattr = &data->fattr;
3682 data->res.server = server;
3683 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3684 nfs_fattr_init(data->res.fattr);
3685 data->timestamp = jiffies;
3686 data->rpc_status = 0;
3688 task_setup_data.callback_data = data;
3689 msg.rpc_argp = &data->args,
3690 msg.rpc_resp = &data->res,
3691 task = rpc_run_task(&task_setup_data);
3693 return PTR_ERR(task);
3696 status = nfs4_wait_for_completion_rpc_task(task);
3699 status = data->rpc_status;
3702 nfs_refresh_inode(inode, &data->fattr);
3708 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3710 struct nfs_server *server = NFS_SERVER(inode);
3711 struct nfs4_exception exception = { };
3714 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
3716 case -NFS4ERR_STALE_STATEID:
3717 case -NFS4ERR_EXPIRED:
3721 err = nfs4_handle_exception(server, err, &exception);
3722 } while (exception.retry);
3726 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3727 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3730 * sleep, with exponential backoff, and retry the LOCK operation.
3732 static unsigned long
3733 nfs4_set_lock_task_retry(unsigned long timeout)
3735 schedule_timeout_killable(timeout);
3737 if (timeout > NFS4_LOCK_MAXTIMEOUT)
3738 return NFS4_LOCK_MAXTIMEOUT;
3742 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3744 struct inode *inode = state->inode;
3745 struct nfs_server *server = NFS_SERVER(inode);
3746 struct nfs_client *clp = server->nfs_client;
3747 struct nfs_lockt_args arg = {
3748 .fh = NFS_FH(inode),
3751 struct nfs_lockt_res res = {
3754 struct rpc_message msg = {
3755 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
3758 .rpc_cred = state->owner->so_cred,
3760 struct nfs4_lock_state *lsp;
3763 arg.lock_owner.clientid = clp->cl_clientid;
3764 status = nfs4_set_lock_state(state, request);
3767 lsp = request->fl_u.nfs4_fl.owner;
3768 arg.lock_owner.id = lsp->ls_id.id;
3769 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
3772 request->fl_type = F_UNLCK;
3774 case -NFS4ERR_DENIED:
3777 request->fl_ops->fl_release_private(request);
3782 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3784 struct nfs4_exception exception = { };
3788 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3789 _nfs4_proc_getlk(state, cmd, request),
3791 } while (exception.retry);
3795 static int do_vfs_lock(struct file *file, struct file_lock *fl)
3798 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3800 res = posix_lock_file_wait(file, fl);
3803 res = flock_lock_file_wait(file, fl);
3811 struct nfs4_unlockdata {
3812 struct nfs_locku_args arg;
3813 struct nfs_locku_res res;
3814 struct nfs4_lock_state *lsp;
3815 struct nfs_open_context *ctx;
3816 struct file_lock fl;
3817 const struct nfs_server *server;
3818 unsigned long timestamp;
3821 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3822 struct nfs_open_context *ctx,
3823 struct nfs4_lock_state *lsp,
3824 struct nfs_seqid *seqid)
3826 struct nfs4_unlockdata *p;
3827 struct inode *inode = lsp->ls_state->inode;
3829 p = kzalloc(sizeof(*p), GFP_KERNEL);
3832 p->arg.fh = NFS_FH(inode);
3834 p->arg.seqid = seqid;
3835 p->res.seqid = seqid;
3836 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3837 p->arg.stateid = &lsp->ls_stateid;
3839 atomic_inc(&lsp->ls_count);
3840 /* Ensure we don't close file until we're done freeing locks! */
3841 p->ctx = get_nfs_open_context(ctx);
3842 memcpy(&p->fl, fl, sizeof(p->fl));
3843 p->server = NFS_SERVER(inode);
3847 static void nfs4_locku_release_calldata(void *data)
3849 struct nfs4_unlockdata *calldata = data;
3850 nfs_free_seqid(calldata->arg.seqid);
3851 nfs4_put_lock_state(calldata->lsp);
3852 put_nfs_open_context(calldata->ctx);
3856 static void nfs4_locku_done(struct rpc_task *task, void *data)
3858 struct nfs4_unlockdata *calldata = data;
3860 nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
3862 if (RPC_ASSASSINATED(task))
3864 switch (task->tk_status) {
3866 memcpy(calldata->lsp->ls_stateid.data,
3867 calldata->res.stateid.data,
3868 sizeof(calldata->lsp->ls_stateid.data));
3869 renew_lease(calldata->server, calldata->timestamp);
3871 case -NFS4ERR_BAD_STATEID:
3872 case -NFS4ERR_OLD_STATEID:
3873 case -NFS4ERR_STALE_STATEID:
3874 case -NFS4ERR_EXPIRED:
3877 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
3878 nfs_restart_rpc(task,
3879 calldata->server->nfs_client);
3883 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
3885 struct nfs4_unlockdata *calldata = data;
3887 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
3889 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
3890 /* Note: exit _without_ running nfs4_locku_done */
3891 task->tk_action = NULL;
3894 calldata->timestamp = jiffies;
3895 if (nfs4_setup_sequence(calldata->server->nfs_client,
3896 &calldata->arg.seq_args,
3897 &calldata->res.seq_res, 1, task))
3899 rpc_call_start(task);
3902 static const struct rpc_call_ops nfs4_locku_ops = {
3903 .rpc_call_prepare = nfs4_locku_prepare,
3904 .rpc_call_done = nfs4_locku_done,
3905 .rpc_release = nfs4_locku_release_calldata,
3908 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3909 struct nfs_open_context *ctx,
3910 struct nfs4_lock_state *lsp,
3911 struct nfs_seqid *seqid)
3913 struct nfs4_unlockdata *data;
3914 struct rpc_message msg = {
3915 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
3916 .rpc_cred = ctx->cred,
3918 struct rpc_task_setup task_setup_data = {
3919 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
3920 .rpc_message = &msg,
3921 .callback_ops = &nfs4_locku_ops,
3922 .workqueue = nfsiod_workqueue,
3923 .flags = RPC_TASK_ASYNC,
3926 /* Ensure this is an unlock - when canceling a lock, the
3927 * canceled lock is passed in, and it won't be an unlock.
3929 fl->fl_type = F_UNLCK;
3931 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
3933 nfs_free_seqid(seqid);
3934 return ERR_PTR(-ENOMEM);
3937 msg.rpc_argp = &data->arg,
3938 msg.rpc_resp = &data->res,
3939 task_setup_data.callback_data = data;
3940 return rpc_run_task(&task_setup_data);
3943 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
3945 struct nfs_inode *nfsi = NFS_I(state->inode);
3946 struct nfs_seqid *seqid;
3947 struct nfs4_lock_state *lsp;
3948 struct rpc_task *task;
3950 unsigned char fl_flags = request->fl_flags;
3952 status = nfs4_set_lock_state(state, request);
3953 /* Unlock _before_ we do the RPC call */
3954 request->fl_flags |= FL_EXISTS;
3955 down_read(&nfsi->rwsem);
3956 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
3957 up_read(&nfsi->rwsem);
3960 up_read(&nfsi->rwsem);
3963 /* Is this a delegated lock? */
3964 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
3966 lsp = request->fl_u.nfs4_fl.owner;
3967 seqid = nfs_alloc_seqid(&lsp->ls_seqid);
3971 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
3972 status = PTR_ERR(task);
3975 status = nfs4_wait_for_completion_rpc_task(task);
3978 request->fl_flags = fl_flags;
3982 struct nfs4_lockdata {
3983 struct nfs_lock_args arg;
3984 struct nfs_lock_res res;
3985 struct nfs4_lock_state *lsp;
3986 struct nfs_open_context *ctx;
3987 struct file_lock fl;
3988 unsigned long timestamp;
3991 struct nfs_server *server;
3994 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
3995 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp)
3997 struct nfs4_lockdata *p;
3998 struct inode *inode = lsp->ls_state->inode;
3999 struct nfs_server *server = NFS_SERVER(inode);
4001 p = kzalloc(sizeof(*p), GFP_KERNEL);
4005 p->arg.fh = NFS_FH(inode);
4007 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid);
4008 if (p->arg.open_seqid == NULL)
4010 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
4011 if (p->arg.lock_seqid == NULL)
4012 goto out_free_seqid;
4013 p->arg.lock_stateid = &lsp->ls_stateid;
4014 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4015 p->arg.lock_owner.id = lsp->ls_id.id;
4016 p->res.lock_seqid = p->arg.lock_seqid;
4017 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4020 atomic_inc(&lsp->ls_count);
4021 p->ctx = get_nfs_open_context(ctx);
4022 memcpy(&p->fl, fl, sizeof(p->fl));
4025 nfs_free_seqid(p->arg.open_seqid);
4031 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4033 struct nfs4_lockdata *data = calldata;
4034 struct nfs4_state *state = data->lsp->ls_state;
4036 dprintk("%s: begin!\n", __func__);
4037 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4039 /* Do we need to do an open_to_lock_owner? */
4040 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4041 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4043 data->arg.open_stateid = &state->stateid;
4044 data->arg.new_lock_owner = 1;
4045 data->res.open_seqid = data->arg.open_seqid;
4047 data->arg.new_lock_owner = 0;
4048 data->timestamp = jiffies;
4049 if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args,
4050 &data->res.seq_res, 1, task))
4052 rpc_call_start(task);
4053 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4056 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4058 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4059 nfs4_lock_prepare(task, calldata);
4062 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4064 struct nfs4_lockdata *data = calldata;
4066 dprintk("%s: begin!\n", __func__);
4068 nfs4_sequence_done(data->server, &data->res.seq_res,
4071 data->rpc_status = task->tk_status;
4072 if (RPC_ASSASSINATED(task))
4074 if (data->arg.new_lock_owner != 0) {
4075 if (data->rpc_status == 0)
4076 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4080 if (data->rpc_status == 0) {
4081 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
4082 sizeof(data->lsp->ls_stateid.data));
4083 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4084 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
4087 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4090 static void nfs4_lock_release(void *calldata)
4092 struct nfs4_lockdata *data = calldata;
4094 dprintk("%s: begin!\n", __func__);
4095 nfs_free_seqid(data->arg.open_seqid);
4096 if (data->cancelled != 0) {
4097 struct rpc_task *task;
4098 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4099 data->arg.lock_seqid);
4102 dprintk("%s: cancelling lock!\n", __func__);
4104 nfs_free_seqid(data->arg.lock_seqid);
4105 nfs4_put_lock_state(data->lsp);
4106 put_nfs_open_context(data->ctx);
4108 dprintk("%s: done!\n", __func__);
4111 static const struct rpc_call_ops nfs4_lock_ops = {
4112 .rpc_call_prepare = nfs4_lock_prepare,
4113 .rpc_call_done = nfs4_lock_done,
4114 .rpc_release = nfs4_lock_release,
4117 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4118 .rpc_call_prepare = nfs4_recover_lock_prepare,
4119 .rpc_call_done = nfs4_lock_done,
4120 .rpc_release = nfs4_lock_release,
4123 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4125 struct nfs_client *clp = server->nfs_client;
4126 struct nfs4_state *state = lsp->ls_state;
4129 case -NFS4ERR_ADMIN_REVOKED:
4130 case -NFS4ERR_BAD_STATEID:
4131 case -NFS4ERR_EXPIRED:
4132 if (new_lock_owner != 0 ||
4133 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4134 nfs4_state_mark_reclaim_nograce(clp, state);
4135 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4137 case -NFS4ERR_STALE_STATEID:
4138 if (new_lock_owner != 0 ||
4139 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4140 nfs4_state_mark_reclaim_reboot(clp, state);
4141 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4145 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4147 struct nfs4_lockdata *data;
4148 struct rpc_task *task;
4149 struct rpc_message msg = {
4150 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4151 .rpc_cred = state->owner->so_cred,
4153 struct rpc_task_setup task_setup_data = {
4154 .rpc_client = NFS_CLIENT(state->inode),
4155 .rpc_message = &msg,
4156 .callback_ops = &nfs4_lock_ops,
4157 .workqueue = nfsiod_workqueue,
4158 .flags = RPC_TASK_ASYNC,
4162 dprintk("%s: begin!\n", __func__);
4163 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4164 fl->fl_u.nfs4_fl.owner);
4168 data->arg.block = 1;
4169 if (recovery_type > NFS_LOCK_NEW) {
4170 if (recovery_type == NFS_LOCK_RECLAIM)
4171 data->arg.reclaim = NFS_LOCK_RECLAIM;
4172 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4174 msg.rpc_argp = &data->arg,
4175 msg.rpc_resp = &data->res,
4176 task_setup_data.callback_data = data;
4177 task = rpc_run_task(&task_setup_data);
4179 return PTR_ERR(task);
4180 ret = nfs4_wait_for_completion_rpc_task(task);
4182 ret = data->rpc_status;
4184 nfs4_handle_setlk_error(data->server, data->lsp,
4185 data->arg.new_lock_owner, ret);
4187 data->cancelled = 1;
4189 dprintk("%s: done, ret = %d!\n", __func__, ret);
4193 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4195 struct nfs_server *server = NFS_SERVER(state->inode);
4196 struct nfs4_exception exception = { };
4200 /* Cache the lock if possible... */
4201 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4203 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4204 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
4206 nfs4_handle_exception(server, err, &exception);
4207 } while (exception.retry);
4211 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4213 struct nfs_server *server = NFS_SERVER(state->inode);
4214 struct nfs4_exception exception = { };
4217 err = nfs4_set_lock_state(state, request);
4221 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4223 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4227 case -NFS4ERR_GRACE:
4228 case -NFS4ERR_DELAY:
4230 nfs4_handle_exception(server, err, &exception);
4233 } while (exception.retry);
4238 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4240 struct nfs_inode *nfsi = NFS_I(state->inode);
4241 unsigned char fl_flags = request->fl_flags;
4242 int status = -ENOLCK;
4244 if ((fl_flags & FL_POSIX) &&
4245 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4247 /* Is this a delegated open? */
4248 status = nfs4_set_lock_state(state, request);
4251 request->fl_flags |= FL_ACCESS;
4252 status = do_vfs_lock(request->fl_file, request);
4255 down_read(&nfsi->rwsem);
4256 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4257 /* Yes: cache locks! */
4258 /* ...but avoid races with delegation recall... */
4259 request->fl_flags = fl_flags & ~FL_SLEEP;
4260 status = do_vfs_lock(request->fl_file, request);
4263 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4266 /* Note: we always want to sleep here! */
4267 request->fl_flags = fl_flags | FL_SLEEP;
4268 if (do_vfs_lock(request->fl_file, request) < 0)
4269 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
4271 up_read(&nfsi->rwsem);
4273 request->fl_flags = fl_flags;
4277 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4279 struct nfs4_exception exception = { };
4283 err = _nfs4_proc_setlk(state, cmd, request);
4284 if (err == -NFS4ERR_DENIED)
4286 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4288 } while (exception.retry);
4293 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4295 struct nfs_open_context *ctx;
4296 struct nfs4_state *state;
4297 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4300 /* verify open state */
4301 ctx = nfs_file_open_context(filp);
4304 if (request->fl_start < 0 || request->fl_end < 0)
4307 if (IS_GETLK(cmd)) {
4309 return nfs4_proc_getlk(state, F_GETLK, request);
4313 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4316 if (request->fl_type == F_UNLCK) {
4318 return nfs4_proc_unlck(state, cmd, request);
4325 status = nfs4_proc_setlk(state, cmd, request);
4326 if ((status != -EAGAIN) || IS_SETLK(cmd))
4328 timeout = nfs4_set_lock_task_retry(timeout);
4329 status = -ERESTARTSYS;
4332 } while(status < 0);
4336 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4338 struct nfs_server *server = NFS_SERVER(state->inode);
4339 struct nfs4_exception exception = { };
4342 err = nfs4_set_lock_state(state, fl);
4346 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4349 printk(KERN_ERR "%s: unhandled error %d.\n",
4354 case -NFS4ERR_EXPIRED:
4355 case -NFS4ERR_STALE_CLIENTID:
4356 case -NFS4ERR_STALE_STATEID:
4357 case -NFS4ERR_BADSESSION:
4358 case -NFS4ERR_BADSLOT:
4359 case -NFS4ERR_BAD_HIGH_SLOT:
4360 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4361 case -NFS4ERR_DEADSESSION:
4362 nfs4_schedule_state_recovery(server->nfs_client);
4366 * The show must go on: exit, but mark the
4367 * stateid as needing recovery.
4369 case -NFS4ERR_ADMIN_REVOKED:
4370 case -NFS4ERR_BAD_STATEID:
4371 case -NFS4ERR_OPENMODE:
4372 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
4376 case -NFS4ERR_DENIED:
4377 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4380 case -NFS4ERR_DELAY:
4384 err = nfs4_handle_exception(server, err, &exception);
4385 } while (exception.retry);
4390 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4392 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
4393 size_t buflen, int flags)
4395 struct inode *inode = dentry->d_inode;
4397 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4400 return nfs4_proc_set_acl(inode, buf, buflen);
4403 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4404 * and that's what we'll do for e.g. user attributes that haven't been set.
4405 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4406 * attributes in kernel-managed attribute namespaces. */
4407 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
4410 struct inode *inode = dentry->d_inode;
4412 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4415 return nfs4_proc_get_acl(inode, buf, buflen);
4418 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
4420 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
4422 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4424 if (buf && buflen < len)
4427 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
4431 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4433 if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
4434 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4435 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
4438 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4439 NFS_ATTR_FATTR_NLINK;
4440 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4444 int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4445 struct nfs4_fs_locations *fs_locations, struct page *page)
4447 struct nfs_server *server = NFS_SERVER(dir);
4449 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
4450 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
4452 struct nfs4_fs_locations_arg args = {
4453 .dir_fh = NFS_FH(dir),
4458 struct nfs4_fs_locations_res res = {
4459 .fs_locations = fs_locations,
4461 struct rpc_message msg = {
4462 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
4468 dprintk("%s: start\n", __func__);
4469 nfs_fattr_init(&fs_locations->fattr);
4470 fs_locations->server = server;
4471 fs_locations->nlocations = 0;
4472 status = nfs4_call_sync(server, &msg, &args, &res, 0);
4473 nfs_fixup_referral_attributes(&fs_locations->fattr);
4474 dprintk("%s: returned status = %d\n", __func__, status);
4478 #ifdef CONFIG_NFS_V4_1
4480 * nfs4_proc_exchange_id()
4482 * Since the clientid has expired, all compounds using sessions
4483 * associated with the stale clientid will be returning
4484 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4485 * be in some phase of session reset.
4487 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4489 nfs4_verifier verifier;
4490 struct nfs41_exchange_id_args args = {
4492 .flags = clp->cl_exchange_flags,
4494 struct nfs41_exchange_id_res res = {
4498 struct rpc_message msg = {
4499 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
4506 dprintk("--> %s\n", __func__);
4507 BUG_ON(clp == NULL);
4509 /* Remove server-only flags */
4510 args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
4512 p = (u32 *)verifier.data;
4513 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4514 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4515 args.verifier = &verifier;
4518 args.id_len = scnprintf(args.id, sizeof(args.id),
4521 rpc_peeraddr2str(clp->cl_rpcclient,
4523 clp->cl_id_uniquifier);
4525 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4527 if (status != -NFS4ERR_CLID_INUSE)
4533 if (++clp->cl_id_uniquifier == 0)
4537 dprintk("<-- %s status= %d\n", __func__, status);
4541 struct nfs4_get_lease_time_data {
4542 struct nfs4_get_lease_time_args *args;
4543 struct nfs4_get_lease_time_res *res;
4544 struct nfs_client *clp;
4547 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4551 struct nfs4_get_lease_time_data *data =
4552 (struct nfs4_get_lease_time_data *)calldata;
4554 dprintk("--> %s\n", __func__);
4555 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4556 /* just setup sequence, do not trigger session recovery
4557 since we're invoked within one */
4558 ret = nfs41_setup_sequence(data->clp->cl_session,
4559 &data->args->la_seq_args,
4560 &data->res->lr_seq_res, 0, task);
4562 BUG_ON(ret == -EAGAIN);
4563 rpc_call_start(task);
4564 dprintk("<-- %s\n", __func__);
4568 * Called from nfs4_state_manager thread for session setup, so don't recover
4569 * from sequence operation or clientid errors.
4571 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4573 struct nfs4_get_lease_time_data *data =
4574 (struct nfs4_get_lease_time_data *)calldata;
4576 dprintk("--> %s\n", __func__);
4577 nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status);
4578 switch (task->tk_status) {
4579 case -NFS4ERR_DELAY:
4580 case -NFS4ERR_GRACE:
4582 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4583 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4584 task->tk_status = 0;
4585 nfs_restart_rpc(task, data->clp);
4588 dprintk("<-- %s\n", __func__);
4591 struct rpc_call_ops nfs4_get_lease_time_ops = {
4592 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4593 .rpc_call_done = nfs4_get_lease_time_done,
4596 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4598 struct rpc_task *task;
4599 struct nfs4_get_lease_time_args args;
4600 struct nfs4_get_lease_time_res res = {
4601 .lr_fsinfo = fsinfo,
4603 struct nfs4_get_lease_time_data data = {
4608 struct rpc_message msg = {
4609 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
4613 struct rpc_task_setup task_setup = {
4614 .rpc_client = clp->cl_rpcclient,
4615 .rpc_message = &msg,
4616 .callback_ops = &nfs4_get_lease_time_ops,
4617 .callback_data = &data
4621 res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4622 dprintk("--> %s\n", __func__);
4623 task = rpc_run_task(&task_setup);
4626 status = PTR_ERR(task);
4628 status = task->tk_status;
4631 dprintk("<-- %s return %d\n", __func__, status);
4637 * Reset a slot table
4639 static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4642 struct nfs4_slot *new = NULL;
4646 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4647 max_reqs, tbl->max_slots);
4649 /* Does the newly negotiated max_reqs match the existing slot table? */
4650 if (max_reqs != tbl->max_slots) {
4652 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4659 spin_lock(&tbl->slot_tbl_lock);
4662 tbl->max_slots = max_reqs;
4664 for (i = 0; i < tbl->max_slots; ++i)
4665 tbl->slots[i].seq_nr = ivalue;
4666 spin_unlock(&tbl->slot_tbl_lock);
4667 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4668 tbl, tbl->slots, tbl->max_slots);
4670 dprintk("<-- %s: return %d\n", __func__, ret);
4675 * Reset the forechannel and backchannel slot tables
4677 static int nfs4_reset_slot_tables(struct nfs4_session *session)
4681 status = nfs4_reset_slot_table(&session->fc_slot_table,
4682 session->fc_attrs.max_reqs, 1);
4686 status = nfs4_reset_slot_table(&session->bc_slot_table,
4687 session->bc_attrs.max_reqs, 0);
4691 /* Destroy the slot table */
4692 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4694 if (session->fc_slot_table.slots != NULL) {
4695 kfree(session->fc_slot_table.slots);
4696 session->fc_slot_table.slots = NULL;
4698 if (session->bc_slot_table.slots != NULL) {
4699 kfree(session->bc_slot_table.slots);
4700 session->bc_slot_table.slots = NULL;
4706 * Initialize slot table
4708 static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4709 int max_slots, int ivalue)
4711 struct nfs4_slot *slot;
4714 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
4716 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4718 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL);
4723 spin_lock(&tbl->slot_tbl_lock);
4724 tbl->max_slots = max_slots;
4726 tbl->highest_used_slotid = -1; /* no slot is currently used */
4727 spin_unlock(&tbl->slot_tbl_lock);
4728 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4729 tbl, tbl->slots, tbl->max_slots);
4731 dprintk("<-- %s: return %d\n", __func__, ret);
4736 * Initialize the forechannel and backchannel tables
4738 static int nfs4_init_slot_tables(struct nfs4_session *session)
4740 struct nfs4_slot_table *tbl;
4743 tbl = &session->fc_slot_table;
4744 if (tbl->slots == NULL) {
4745 status = nfs4_init_slot_table(tbl,
4746 session->fc_attrs.max_reqs, 1);
4751 tbl = &session->bc_slot_table;
4752 if (tbl->slots == NULL) {
4753 status = nfs4_init_slot_table(tbl,
4754 session->bc_attrs.max_reqs, 0);
4756 nfs4_destroy_slot_tables(session);
4762 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4764 struct nfs4_session *session;
4765 struct nfs4_slot_table *tbl;
4767 session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL);
4772 * The create session reply races with the server back
4773 * channel probe. Mark the client NFS_CS_SESSION_INITING
4774 * so that the client back channel can find the
4777 clp->cl_cons_state = NFS_CS_SESSION_INITING;
4778 init_completion(&session->complete);
4780 tbl = &session->fc_slot_table;
4781 tbl->highest_used_slotid = -1;
4782 spin_lock_init(&tbl->slot_tbl_lock);
4783 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
4785 tbl = &session->bc_slot_table;
4786 tbl->highest_used_slotid = -1;
4787 spin_lock_init(&tbl->slot_tbl_lock);
4788 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
4794 void nfs4_destroy_session(struct nfs4_session *session)
4796 nfs4_proc_destroy_session(session);
4797 dprintk("%s Destroy backchannel for xprt %p\n",
4798 __func__, session->clp->cl_rpcclient->cl_xprt);
4799 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
4800 NFS41_BC_MIN_CALLBACKS);
4801 nfs4_destroy_slot_tables(session);
4806 * Initialize the values to be used by the client in CREATE_SESSION
4807 * If nfs4_init_session set the fore channel request and response sizes,
4810 * Set the back channel max_resp_sz_cached to zero to force the client to
4811 * always set csa_cachethis to FALSE because the current implementation
4812 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4814 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4816 struct nfs4_session *session = args->client->cl_session;
4817 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
4818 mxresp_sz = session->fc_attrs.max_resp_sz;
4821 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
4823 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
4824 /* Fore channel attributes */
4825 args->fc_attrs.headerpadsz = 0;
4826 args->fc_attrs.max_rqst_sz = mxrqst_sz;
4827 args->fc_attrs.max_resp_sz = mxresp_sz;
4828 args->fc_attrs.max_ops = NFS4_MAX_OPS;
4829 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
4831 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4832 "max_ops=%u max_reqs=%u\n",
4834 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
4835 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
4837 /* Back channel attributes */
4838 args->bc_attrs.headerpadsz = 0;
4839 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
4840 args->bc_attrs.max_resp_sz = PAGE_SIZE;
4841 args->bc_attrs.max_resp_sz_cached = 0;
4842 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
4843 args->bc_attrs.max_reqs = 1;
4845 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4846 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4848 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
4849 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
4850 args->bc_attrs.max_reqs);
4853 static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd)
4857 printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. "
4858 "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd);
4862 #define _verify_fore_channel_attr(_name_) \
4863 _verify_channel_attr("fore", #_name_, \
4864 args->fc_attrs._name_, \
4865 session->fc_attrs._name_)
4867 #define _verify_back_channel_attr(_name_) \
4868 _verify_channel_attr("back", #_name_, \
4869 args->bc_attrs._name_, \
4870 session->bc_attrs._name_)
4873 * The server is not allowed to increase the fore channel header pad size,
4874 * maximum response size, or maximum number of operations.
4876 * The back channel attributes are only negotiatied down: We send what the
4877 * (back channel) server insists upon.
4879 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
4880 struct nfs4_session *session)
4884 ret |= _verify_fore_channel_attr(headerpadsz);
4885 ret |= _verify_fore_channel_attr(max_resp_sz);
4886 ret |= _verify_fore_channel_attr(max_ops);
4888 ret |= _verify_back_channel_attr(headerpadsz);
4889 ret |= _verify_back_channel_attr(max_rqst_sz);
4890 ret |= _verify_back_channel_attr(max_resp_sz);
4891 ret |= _verify_back_channel_attr(max_resp_sz_cached);
4892 ret |= _verify_back_channel_attr(max_ops);
4893 ret |= _verify_back_channel_attr(max_reqs);
4898 static int _nfs4_proc_create_session(struct nfs_client *clp)
4900 struct nfs4_session *session = clp->cl_session;
4901 struct nfs41_create_session_args args = {
4903 .cb_program = NFS4_CALLBACK,
4905 struct nfs41_create_session_res res = {
4908 struct rpc_message msg = {
4909 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
4915 nfs4_init_channel_attrs(&args);
4916 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
4918 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
4921 /* Verify the session's negotiated channel_attrs values */
4922 status = nfs4_verify_channel_attrs(&args, session);
4924 /* Increment the clientid slot sequence id */
4932 * Issues a CREATE_SESSION operation to the server.
4933 * It is the responsibility of the caller to verify the session is
4934 * expired before calling this routine.
4936 int nfs4_proc_create_session(struct nfs_client *clp)
4940 struct nfs4_session *session = clp->cl_session;
4942 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
4944 status = _nfs4_proc_create_session(clp);
4948 /* Init and reset the fore channel */
4949 status = nfs4_init_slot_tables(session);
4950 dprintk("slot table initialization returned %d\n", status);
4953 status = nfs4_reset_slot_tables(session);
4954 dprintk("slot table reset returned %d\n", status);
4958 ptr = (unsigned *)&session->sess_id.data[0];
4959 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
4960 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
4962 dprintk("<-- %s\n", __func__);
4967 * Issue the over-the-wire RPC DESTROY_SESSION.
4968 * The caller must serialize access to this routine.
4970 int nfs4_proc_destroy_session(struct nfs4_session *session)
4973 struct rpc_message msg;
4975 dprintk("--> nfs4_proc_destroy_session\n");
4977 /* session is still being setup */
4978 if (session->clp->cl_cons_state != NFS_CS_READY)
4981 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
4982 msg.rpc_argp = session;
4983 msg.rpc_resp = NULL;
4984 msg.rpc_cred = NULL;
4985 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
4989 "Got error %d from the server on DESTROY_SESSION. "
4990 "Session has been destroyed regardless...\n", status);
4992 dprintk("<-- nfs4_proc_destroy_session\n");
4996 int nfs4_init_session(struct nfs_server *server)
4998 struct nfs_client *clp = server->nfs_client;
4999 struct nfs4_session *session;
5000 unsigned int rsize, wsize;
5003 if (!nfs4_has_session(clp))
5006 rsize = server->rsize;
5008 rsize = NFS_MAX_FILE_IO_SIZE;
5009 wsize = server->wsize;
5011 wsize = NFS_MAX_FILE_IO_SIZE;
5013 session = clp->cl_session;
5014 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5015 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5017 ret = nfs4_recover_expired_lease(server);
5019 ret = nfs4_check_client_ready(clp);
5024 * Renew the cl_session lease.
5026 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5028 struct nfs4_sequence_args args;
5029 struct nfs4_sequence_res res;
5031 struct rpc_message msg = {
5032 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5038 args.sa_cache_this = 0;
5040 return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args,
5041 &res, args.sa_cache_this, 1);
5044 static void nfs41_sequence_release(void *data)
5046 struct nfs_client *clp = (struct nfs_client *)data;
5048 if (atomic_read(&clp->cl_count) > 1)
5049 nfs4_schedule_state_renewal(clp);
5050 nfs_put_client(clp);
5053 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5055 struct nfs_client *clp = (struct nfs_client *)data;
5057 nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status);
5059 if (task->tk_status < 0) {
5060 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5061 if (atomic_read(&clp->cl_count) == 1)
5064 if (_nfs4_async_handle_error(task, NULL, clp, NULL)
5066 nfs_restart_rpc(task, clp);
5070 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5072 kfree(task->tk_msg.rpc_argp);
5073 kfree(task->tk_msg.rpc_resp);
5075 dprintk("<-- %s\n", __func__);
5078 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5080 struct nfs_client *clp;
5081 struct nfs4_sequence_args *args;
5082 struct nfs4_sequence_res *res;
5084 clp = (struct nfs_client *)data;
5085 args = task->tk_msg.rpc_argp;
5086 res = task->tk_msg.rpc_resp;
5088 if (nfs4_setup_sequence(clp, args, res, 0, task))
5090 rpc_call_start(task);
5093 static const struct rpc_call_ops nfs41_sequence_ops = {
5094 .rpc_call_done = nfs41_sequence_call_done,
5095 .rpc_call_prepare = nfs41_sequence_prepare,
5096 .rpc_release = nfs41_sequence_release,
5099 static int nfs41_proc_async_sequence(struct nfs_client *clp,
5100 struct rpc_cred *cred)
5102 struct nfs4_sequence_args *args;
5103 struct nfs4_sequence_res *res;
5104 struct rpc_message msg = {
5105 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5109 if (!atomic_inc_not_zero(&clp->cl_count))
5111 args = kzalloc(sizeof(*args), GFP_KERNEL);
5112 res = kzalloc(sizeof(*res), GFP_KERNEL);
5113 if (!args || !res) {
5116 nfs_put_client(clp);
5119 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
5120 msg.rpc_argp = args;
5123 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
5124 &nfs41_sequence_ops, (void *)clp);
5127 struct nfs4_reclaim_complete_data {
5128 struct nfs_client *clp;
5129 struct nfs41_reclaim_complete_args arg;
5130 struct nfs41_reclaim_complete_res res;
5133 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5135 struct nfs4_reclaim_complete_data *calldata = data;
5137 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5138 if (nfs4_setup_sequence(calldata->clp, &calldata->arg.seq_args,
5139 &calldata->res.seq_res, 0, task))
5142 rpc_call_start(task);
5145 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5147 struct nfs4_reclaim_complete_data *calldata = data;
5148 struct nfs_client *clp = calldata->clp;
5149 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5151 dprintk("--> %s\n", __func__);
5152 nfs41_sequence_done(clp, res, task->tk_status);
5153 switch (task->tk_status) {
5155 case -NFS4ERR_COMPLETE_ALREADY:
5157 case -NFS4ERR_BADSESSION:
5158 case -NFS4ERR_DEADSESSION:
5160 * Handle the session error, but do not retry the operation, as
5161 * we have no way of telling whether the clientid had to be
5162 * reset before we got our reply. If reset, a new wave of
5163 * reclaim operations will follow, containing their own reclaim
5164 * complete. We don't want our retry to get on the way of
5165 * recovery by incorrectly indicating to the server that we're
5166 * done reclaiming state since the process had to be restarted.
5168 _nfs4_async_handle_error(task, NULL, clp, NULL);
5171 if (_nfs4_async_handle_error(
5172 task, NULL, clp, NULL) == -EAGAIN) {
5173 rpc_restart_call_prepare(task);
5178 dprintk("<-- %s\n", __func__);
5181 static void nfs4_free_reclaim_complete_data(void *data)
5183 struct nfs4_reclaim_complete_data *calldata = data;
5188 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5189 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5190 .rpc_call_done = nfs4_reclaim_complete_done,
5191 .rpc_release = nfs4_free_reclaim_complete_data,
5195 * Issue a global reclaim complete.
5197 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5199 struct nfs4_reclaim_complete_data *calldata;
5200 struct rpc_task *task;
5201 struct rpc_message msg = {
5202 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5204 struct rpc_task_setup task_setup_data = {
5205 .rpc_client = clp->cl_rpcclient,
5206 .rpc_message = &msg,
5207 .callback_ops = &nfs4_reclaim_complete_call_ops,
5208 .flags = RPC_TASK_ASYNC,
5210 int status = -ENOMEM;
5212 dprintk("--> %s\n", __func__);
5213 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
5214 if (calldata == NULL)
5216 calldata->clp = clp;
5217 calldata->arg.one_fs = 0;
5218 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5220 msg.rpc_argp = &calldata->arg;
5221 msg.rpc_resp = &calldata->res;
5222 task_setup_data.callback_data = calldata;
5223 task = rpc_run_task(&task_setup_data);
5225 status = PTR_ERR(task);
5231 dprintk("<-- %s status=%d\n", __func__, status);
5234 #endif /* CONFIG_NFS_V4_1 */
5236 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
5237 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5238 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5239 .recover_open = nfs4_open_reclaim,
5240 .recover_lock = nfs4_lock_reclaim,
5241 .establish_clid = nfs4_init_clientid,
5242 .get_clid_cred = nfs4_get_setclientid_cred,
5245 #if defined(CONFIG_NFS_V4_1)
5246 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
5247 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5248 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5249 .recover_open = nfs4_open_reclaim,
5250 .recover_lock = nfs4_lock_reclaim,
5251 .establish_clid = nfs41_init_clientid,
5252 .get_clid_cred = nfs4_get_exchange_id_cred,
5253 .reclaim_complete = nfs41_proc_reclaim_complete,
5255 #endif /* CONFIG_NFS_V4_1 */
5257 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
5258 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5259 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5260 .recover_open = nfs4_open_expired,
5261 .recover_lock = nfs4_lock_expired,
5262 .establish_clid = nfs4_init_clientid,
5263 .get_clid_cred = nfs4_get_setclientid_cred,
5266 #if defined(CONFIG_NFS_V4_1)
5267 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
5268 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5269 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5270 .recover_open = nfs4_open_expired,
5271 .recover_lock = nfs4_lock_expired,
5272 .establish_clid = nfs41_init_clientid,
5273 .get_clid_cred = nfs4_get_exchange_id_cred,
5275 #endif /* CONFIG_NFS_V4_1 */
5277 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
5278 .sched_state_renewal = nfs4_proc_async_renew,
5279 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
5280 .renew_lease = nfs4_proc_renew,
5283 #if defined(CONFIG_NFS_V4_1)
5284 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
5285 .sched_state_renewal = nfs41_proc_async_sequence,
5286 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
5287 .renew_lease = nfs4_proc_sequence,
5292 * Per minor version reboot and network partition recovery ops
5295 struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = {
5296 &nfs40_reboot_recovery_ops,
5297 #if defined(CONFIG_NFS_V4_1)
5298 &nfs41_reboot_recovery_ops,
5302 struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = {
5303 &nfs40_nograce_recovery_ops,
5304 #if defined(CONFIG_NFS_V4_1)
5305 &nfs41_nograce_recovery_ops,
5309 struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = {
5310 &nfs40_state_renewal_ops,
5311 #if defined(CONFIG_NFS_V4_1)
5312 &nfs41_state_renewal_ops,
5316 static const struct inode_operations nfs4_file_inode_operations = {
5317 .permission = nfs_permission,
5318 .getattr = nfs_getattr,
5319 .setattr = nfs_setattr,
5320 .getxattr = nfs4_getxattr,
5321 .setxattr = nfs4_setxattr,
5322 .listxattr = nfs4_listxattr,
5325 const struct nfs_rpc_ops nfs_v4_clientops = {
5326 .version = 4, /* protocol version */
5327 .dentry_ops = &nfs4_dentry_operations,
5328 .dir_inode_ops = &nfs4_dir_inode_operations,
5329 .file_inode_ops = &nfs4_file_inode_operations,
5330 .getroot = nfs4_proc_get_root,
5331 .getattr = nfs4_proc_getattr,
5332 .setattr = nfs4_proc_setattr,
5333 .lookupfh = nfs4_proc_lookupfh,
5334 .lookup = nfs4_proc_lookup,
5335 .access = nfs4_proc_access,
5336 .readlink = nfs4_proc_readlink,
5337 .create = nfs4_proc_create,
5338 .remove = nfs4_proc_remove,
5339 .unlink_setup = nfs4_proc_unlink_setup,
5340 .unlink_done = nfs4_proc_unlink_done,
5341 .rename = nfs4_proc_rename,
5342 .link = nfs4_proc_link,
5343 .symlink = nfs4_proc_symlink,
5344 .mkdir = nfs4_proc_mkdir,
5345 .rmdir = nfs4_proc_remove,
5346 .readdir = nfs4_proc_readdir,
5347 .mknod = nfs4_proc_mknod,
5348 .statfs = nfs4_proc_statfs,
5349 .fsinfo = nfs4_proc_fsinfo,
5350 .pathconf = nfs4_proc_pathconf,
5351 .set_capabilities = nfs4_server_capabilities,
5352 .decode_dirent = nfs4_decode_dirent,
5353 .read_setup = nfs4_proc_read_setup,
5354 .read_done = nfs4_read_done,
5355 .write_setup = nfs4_proc_write_setup,
5356 .write_done = nfs4_write_done,
5357 .commit_setup = nfs4_proc_commit_setup,
5358 .commit_done = nfs4_commit_done,
5359 .lock = nfs4_proc_lock,
5360 .clear_acl_cache = nfs4_zap_acl_attr,
5361 .close_context = nfs4_close_context,