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);
73 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
74 struct nfs_fattr *fattr, struct iattr *sattr,
75 struct nfs4_state *state);
77 /* Prevent leaks of NFSv4 errors into userland */
78 static int nfs4_map_errors(int err)
83 case -NFS4ERR_RESOURCE:
86 dprintk("%s could not handle NFSv4 error %d\n",
94 * This is our standard bitmap for GETATTR requests.
96 const u32 nfs4_fattr_bitmap[2] = {
101 | FATTR4_WORD0_FILEID,
103 | FATTR4_WORD1_NUMLINKS
105 | FATTR4_WORD1_OWNER_GROUP
106 | FATTR4_WORD1_RAWDEV
107 | FATTR4_WORD1_SPACE_USED
108 | FATTR4_WORD1_TIME_ACCESS
109 | FATTR4_WORD1_TIME_METADATA
110 | FATTR4_WORD1_TIME_MODIFY
113 const u32 nfs4_statfs_bitmap[2] = {
114 FATTR4_WORD0_FILES_AVAIL
115 | FATTR4_WORD0_FILES_FREE
116 | FATTR4_WORD0_FILES_TOTAL,
117 FATTR4_WORD1_SPACE_AVAIL
118 | FATTR4_WORD1_SPACE_FREE
119 | FATTR4_WORD1_SPACE_TOTAL
122 const u32 nfs4_pathconf_bitmap[2] = {
124 | FATTR4_WORD0_MAXNAME,
128 const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
129 | FATTR4_WORD0_MAXREAD
130 | FATTR4_WORD0_MAXWRITE
131 | FATTR4_WORD0_LEASE_TIME,
135 const u32 nfs4_fs_locations_bitmap[2] = {
137 | FATTR4_WORD0_CHANGE
140 | FATTR4_WORD0_FILEID
141 | FATTR4_WORD0_FS_LOCATIONS,
143 | FATTR4_WORD1_NUMLINKS
145 | FATTR4_WORD1_OWNER_GROUP
146 | FATTR4_WORD1_RAWDEV
147 | FATTR4_WORD1_SPACE_USED
148 | FATTR4_WORD1_TIME_ACCESS
149 | FATTR4_WORD1_TIME_METADATA
150 | FATTR4_WORD1_TIME_MODIFY
151 | FATTR4_WORD1_MOUNTED_ON_FILEID
154 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
155 struct nfs4_readdir_arg *readdir)
159 BUG_ON(readdir->count < 80);
161 readdir->cookie = cookie;
162 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
167 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
172 * NFSv4 servers do not return entries for '.' and '..'
173 * Therefore, we fake these entries here. We let '.'
174 * have cookie 0 and '..' have cookie 1. Note that
175 * when talking to the server, we always send cookie 0
178 start = p = kmap_atomic(*readdir->pages, KM_USER0);
181 *p++ = xdr_one; /* next */
182 *p++ = xdr_zero; /* cookie, first word */
183 *p++ = xdr_one; /* cookie, second word */
184 *p++ = xdr_one; /* entry len */
185 memcpy(p, ".\0\0\0", 4); /* entry */
187 *p++ = xdr_one; /* bitmap length */
188 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
189 *p++ = htonl(8); /* attribute buffer length */
190 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
193 *p++ = xdr_one; /* next */
194 *p++ = xdr_zero; /* cookie, first word */
195 *p++ = xdr_two; /* cookie, second word */
196 *p++ = xdr_two; /* entry len */
197 memcpy(p, "..\0\0", 4); /* entry */
199 *p++ = xdr_one; /* bitmap length */
200 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
201 *p++ = htonl(8); /* attribute buffer length */
202 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
204 readdir->pgbase = (char *)p - (char *)start;
205 readdir->count -= readdir->pgbase;
206 kunmap_atomic(start, KM_USER0);
209 static int nfs4_wait_clnt_recover(struct nfs_client *clp)
215 res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
216 nfs_wait_bit_killable, TASK_KILLABLE);
220 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
227 *timeout = NFS4_POLL_RETRY_MIN;
228 if (*timeout > NFS4_POLL_RETRY_MAX)
229 *timeout = NFS4_POLL_RETRY_MAX;
230 schedule_timeout_killable(*timeout);
231 if (fatal_signal_pending(current))
237 /* This is the error handling routine for processes that are allowed
240 static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
242 struct nfs_client *clp = server->nfs_client;
243 struct nfs4_state *state = exception->state;
246 exception->retry = 0;
250 case -NFS4ERR_ADMIN_REVOKED:
251 case -NFS4ERR_BAD_STATEID:
252 case -NFS4ERR_OPENMODE:
255 nfs4_state_mark_reclaim_nograce(clp, state);
256 goto do_state_recovery;
257 case -NFS4ERR_STALE_STATEID:
260 nfs4_state_mark_reclaim_reboot(clp, state);
261 case -NFS4ERR_STALE_CLIENTID:
262 case -NFS4ERR_EXPIRED:
263 goto do_state_recovery;
264 #if defined(CONFIG_NFS_V4_1)
265 case -NFS4ERR_BADSESSION:
266 case -NFS4ERR_BADSLOT:
267 case -NFS4ERR_BAD_HIGH_SLOT:
268 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
269 case -NFS4ERR_DEADSESSION:
270 case -NFS4ERR_SEQ_FALSE_RETRY:
271 case -NFS4ERR_SEQ_MISORDERED:
272 dprintk("%s ERROR: %d Reset session\n", __func__,
274 nfs4_schedule_state_recovery(clp);
275 exception->retry = 1;
277 #endif /* defined(CONFIG_NFS_V4_1) */
278 case -NFS4ERR_FILE_OPEN:
279 if (exception->timeout > HZ) {
280 /* We have retried a decent amount, time to
289 ret = nfs4_delay(server->client, &exception->timeout);
292 case -NFS4ERR_OLD_STATEID:
293 exception->retry = 1;
295 /* We failed to handle the error */
296 return nfs4_map_errors(ret);
298 nfs4_schedule_state_recovery(clp);
299 ret = nfs4_wait_clnt_recover(clp);
301 exception->retry = 1;
306 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
308 struct nfs_client *clp = server->nfs_client;
309 spin_lock(&clp->cl_lock);
310 if (time_before(clp->cl_last_renewal,timestamp))
311 clp->cl_last_renewal = timestamp;
312 spin_unlock(&clp->cl_lock);
315 #if defined(CONFIG_NFS_V4_1)
318 * nfs4_free_slot - free a slot and efficiently update slot table.
320 * freeing a slot is trivially done by clearing its respective bit
322 * If the freed slotid equals highest_used_slotid we want to update it
323 * so that the server would be able to size down the slot table if needed,
324 * otherwise we know that the highest_used_slotid is still in use.
325 * When updating highest_used_slotid there may be "holes" in the bitmap
326 * so we need to scan down from highest_used_slotid to 0 looking for the now
327 * highest slotid in use.
328 * If none found, highest_used_slotid is set to -1.
330 * Must be called while holding tbl->slot_tbl_lock
333 nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
335 int slotid = free_slotid;
337 /* clear used bit in bitmap */
338 __clear_bit(slotid, tbl->used_slots);
340 /* update highest_used_slotid when it is freed */
341 if (slotid == tbl->highest_used_slotid) {
342 slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
343 if (slotid < tbl->max_slots)
344 tbl->highest_used_slotid = slotid;
346 tbl->highest_used_slotid = -1;
348 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__,
349 free_slotid, tbl->highest_used_slotid);
353 * Signal state manager thread if session is drained
355 static void nfs41_check_drain_session_complete(struct nfs4_session *ses)
357 struct rpc_task *task;
359 if (!test_bit(NFS4CLNT_SESSION_DRAINING, &ses->clp->cl_state)) {
360 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq);
362 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
366 if (ses->fc_slot_table.highest_used_slotid != -1)
369 dprintk("%s COMPLETE: Session Drained\n", __func__);
370 complete(&ses->complete);
373 static void nfs41_sequence_free_slot(const struct nfs_client *clp,
374 struct nfs4_sequence_res *res)
376 struct nfs4_slot_table *tbl;
378 tbl = &clp->cl_session->fc_slot_table;
379 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) {
380 /* just wake up the next guy waiting since
381 * we may have not consumed a slot after all */
382 dprintk("%s: No slot\n", __func__);
386 spin_lock(&tbl->slot_tbl_lock);
387 nfs4_free_slot(tbl, res->sr_slotid);
388 nfs41_check_drain_session_complete(clp->cl_session);
389 spin_unlock(&tbl->slot_tbl_lock);
390 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
393 static void nfs41_sequence_done(struct nfs_client *clp,
394 struct nfs4_sequence_res *res,
397 unsigned long timestamp;
398 struct nfs4_slot_table *tbl;
399 struct nfs4_slot *slot;
402 * sr_status remains 1 if an RPC level error occurred. The server
403 * may or may not have processed the sequence operation..
404 * Proceed as if the server received and processed the sequence
407 if (res->sr_status == 1)
408 res->sr_status = NFS_OK;
410 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
411 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE)
414 /* Check the SEQUENCE operation status */
415 if (res->sr_status == 0) {
416 tbl = &clp->cl_session->fc_slot_table;
417 slot = tbl->slots + res->sr_slotid;
418 /* Update the slot's sequence and clientid lease timer */
420 timestamp = res->sr_renewal_time;
421 spin_lock(&clp->cl_lock);
422 if (time_before(clp->cl_last_renewal, timestamp))
423 clp->cl_last_renewal = timestamp;
424 spin_unlock(&clp->cl_lock);
425 /* Check sequence flags */
426 if (atomic_read(&clp->cl_count) > 1)
427 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
430 /* The session may be reset by one of the error handlers. */
431 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
432 nfs41_sequence_free_slot(clp, res);
436 * nfs4_find_slot - efficiently look for a free slot
438 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
439 * If found, we mark the slot as used, update the highest_used_slotid,
440 * and respectively set up the sequence operation args.
441 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
443 * Note: must be called with under the slot_tbl_lock.
446 nfs4_find_slot(struct nfs4_slot_table *tbl)
449 u8 ret_id = NFS4_MAX_SLOT_TABLE;
450 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
452 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
453 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
455 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
456 if (slotid >= tbl->max_slots)
458 __set_bit(slotid, tbl->used_slots);
459 if (slotid > tbl->highest_used_slotid)
460 tbl->highest_used_slotid = slotid;
463 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
464 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
468 static int nfs41_setup_sequence(struct nfs4_session *session,
469 struct nfs4_sequence_args *args,
470 struct nfs4_sequence_res *res,
472 struct rpc_task *task)
474 struct nfs4_slot *slot;
475 struct nfs4_slot_table *tbl;
478 dprintk("--> %s\n", __func__);
479 /* slot already allocated? */
480 if (res->sr_slotid != NFS4_MAX_SLOT_TABLE)
483 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
484 tbl = &session->fc_slot_table;
486 spin_lock(&tbl->slot_tbl_lock);
487 if (test_bit(NFS4CLNT_SESSION_DRAINING, &session->clp->cl_state) &&
488 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
490 * The state manager will wait until the slot table is empty.
491 * Schedule the reset thread
493 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
494 spin_unlock(&tbl->slot_tbl_lock);
495 dprintk("%s Schedule Session Reset\n", __func__);
499 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
500 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
501 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
502 spin_unlock(&tbl->slot_tbl_lock);
503 dprintk("%s enforce FIFO order\n", __func__);
507 slotid = nfs4_find_slot(tbl);
508 if (slotid == NFS4_MAX_SLOT_TABLE) {
509 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
510 spin_unlock(&tbl->slot_tbl_lock);
511 dprintk("<-- %s: no free slots\n", __func__);
514 spin_unlock(&tbl->slot_tbl_lock);
516 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
517 slot = tbl->slots + slotid;
518 args->sa_session = session;
519 args->sa_slotid = slotid;
520 args->sa_cache_this = cache_reply;
522 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
524 res->sr_session = session;
525 res->sr_slotid = slotid;
526 res->sr_renewal_time = jiffies;
527 res->sr_status_flags = 0;
529 * sr_status is only set in decode_sequence, and so will remain
530 * set to 1 if an rpc level failure occurs.
536 int nfs4_setup_sequence(struct nfs_client *clp,
537 struct nfs4_sequence_args *args,
538 struct nfs4_sequence_res *res,
540 struct rpc_task *task)
544 dprintk("--> %s clp %p session %p sr_slotid %d\n",
545 __func__, clp, clp->cl_session, res->sr_slotid);
547 if (!nfs4_has_session(clp))
549 ret = nfs41_setup_sequence(clp->cl_session, args, res, cache_reply,
552 dprintk("<-- %s status=%d\n", __func__, ret);
556 struct nfs41_call_sync_data {
557 struct nfs_client *clp;
558 struct nfs4_sequence_args *seq_args;
559 struct nfs4_sequence_res *seq_res;
563 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
565 struct nfs41_call_sync_data *data = calldata;
567 dprintk("--> %s data->clp->cl_session %p\n", __func__,
568 data->clp->cl_session);
569 if (nfs4_setup_sequence(data->clp, data->seq_args,
570 data->seq_res, data->cache_reply, task))
572 rpc_call_start(task);
575 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
577 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
578 nfs41_call_sync_prepare(task, calldata);
581 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
583 struct nfs41_call_sync_data *data = calldata;
585 nfs41_sequence_done(data->clp, data->seq_res, task->tk_status);
588 struct rpc_call_ops nfs41_call_sync_ops = {
589 .rpc_call_prepare = nfs41_call_sync_prepare,
590 .rpc_call_done = nfs41_call_sync_done,
593 struct rpc_call_ops nfs41_call_priv_sync_ops = {
594 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
595 .rpc_call_done = nfs41_call_sync_done,
598 static int nfs4_call_sync_sequence(struct nfs_client *clp,
599 struct rpc_clnt *clnt,
600 struct rpc_message *msg,
601 struct nfs4_sequence_args *args,
602 struct nfs4_sequence_res *res,
607 struct rpc_task *task;
608 struct nfs41_call_sync_data data = {
612 .cache_reply = cache_reply,
614 struct rpc_task_setup task_setup = {
617 .callback_ops = &nfs41_call_sync_ops,
618 .callback_data = &data
621 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
623 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
624 task = rpc_run_task(&task_setup);
628 ret = task->tk_status;
634 int _nfs4_call_sync_session(struct nfs_server *server,
635 struct rpc_message *msg,
636 struct nfs4_sequence_args *args,
637 struct nfs4_sequence_res *res,
640 return nfs4_call_sync_sequence(server->nfs_client, server->client,
641 msg, args, res, cache_reply, 0);
644 #endif /* CONFIG_NFS_V4_1 */
646 int _nfs4_call_sync(struct nfs_server *server,
647 struct rpc_message *msg,
648 struct nfs4_sequence_args *args,
649 struct nfs4_sequence_res *res,
652 args->sa_session = res->sr_session = NULL;
653 return rpc_call_sync(server->client, msg, 0);
656 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
657 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
658 &(res)->seq_res, (cache_reply))
660 static void nfs4_sequence_done(const struct nfs_server *server,
661 struct nfs4_sequence_res *res, int rpc_status)
663 #ifdef CONFIG_NFS_V4_1
664 if (nfs4_has_session(server->nfs_client))
665 nfs41_sequence_done(server->nfs_client, res, rpc_status);
666 #endif /* CONFIG_NFS_V4_1 */
669 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
671 struct nfs_inode *nfsi = NFS_I(dir);
673 spin_lock(&dir->i_lock);
674 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
675 if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
676 nfs_force_lookup_revalidate(dir);
677 nfsi->change_attr = cinfo->after;
678 spin_unlock(&dir->i_lock);
681 struct nfs4_opendata {
683 struct nfs_openargs o_arg;
684 struct nfs_openres o_res;
685 struct nfs_open_confirmargs c_arg;
686 struct nfs_open_confirmres c_res;
687 struct nfs_fattr f_attr;
688 struct nfs_fattr dir_attr;
691 struct nfs4_state_owner *owner;
692 struct nfs4_state *state;
694 unsigned long timestamp;
695 unsigned int rpc_done : 1;
701 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
703 p->o_res.f_attr = &p->f_attr;
704 p->o_res.dir_attr = &p->dir_attr;
705 p->o_res.seqid = p->o_arg.seqid;
706 p->c_res.seqid = p->c_arg.seqid;
707 p->o_res.server = p->o_arg.server;
708 nfs_fattr_init(&p->f_attr);
709 nfs_fattr_init(&p->dir_attr);
710 p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
713 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
714 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
715 const struct iattr *attrs,
718 struct dentry *parent = dget_parent(path->dentry);
719 struct inode *dir = parent->d_inode;
720 struct nfs_server *server = NFS_SERVER(dir);
721 struct nfs4_opendata *p;
723 p = kzalloc(sizeof(*p), gfp_mask);
726 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
727 if (p->o_arg.seqid == NULL)
733 atomic_inc(&sp->so_count);
734 p->o_arg.fh = NFS_FH(dir);
735 p->o_arg.open_flags = flags;
736 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
737 p->o_arg.clientid = server->nfs_client->cl_clientid;
738 p->o_arg.id = sp->so_owner_id.id;
739 p->o_arg.name = &p->path.dentry->d_name;
740 p->o_arg.server = server;
741 p->o_arg.bitmask = server->attr_bitmask;
742 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
743 if (flags & O_EXCL) {
744 if (nfs4_has_persistent_session(server->nfs_client)) {
746 p->o_arg.u.attrs = &p->attrs;
747 memcpy(&p->attrs, attrs, sizeof(p->attrs));
748 } else { /* EXCLUSIVE4_1 */
749 u32 *s = (u32 *) p->o_arg.u.verifier.data;
753 } else if (flags & O_CREAT) {
754 p->o_arg.u.attrs = &p->attrs;
755 memcpy(&p->attrs, attrs, sizeof(p->attrs));
757 p->c_arg.fh = &p->o_res.fh;
758 p->c_arg.stateid = &p->o_res.stateid;
759 p->c_arg.seqid = p->o_arg.seqid;
760 nfs4_init_opendata_res(p);
770 static void nfs4_opendata_free(struct kref *kref)
772 struct nfs4_opendata *p = container_of(kref,
773 struct nfs4_opendata, kref);
775 nfs_free_seqid(p->o_arg.seqid);
776 if (p->state != NULL)
777 nfs4_put_open_state(p->state);
778 nfs4_put_state_owner(p->owner);
784 static void nfs4_opendata_put(struct nfs4_opendata *p)
787 kref_put(&p->kref, nfs4_opendata_free);
790 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
794 ret = rpc_wait_for_completion_task(task);
798 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
802 if (open_mode & O_EXCL)
804 switch (mode & (FMODE_READ|FMODE_WRITE)) {
806 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
807 && state->n_rdonly != 0;
810 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
811 && state->n_wronly != 0;
813 case FMODE_READ|FMODE_WRITE:
814 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
815 && state->n_rdwr != 0;
821 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
823 if ((delegation->type & fmode) != fmode)
825 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
827 nfs_mark_delegation_referenced(delegation);
831 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
840 case FMODE_READ|FMODE_WRITE:
843 nfs4_state_set_mode_locked(state, state->state | fmode);
846 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
848 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
849 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
850 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
853 set_bit(NFS_O_RDONLY_STATE, &state->flags);
856 set_bit(NFS_O_WRONLY_STATE, &state->flags);
858 case FMODE_READ|FMODE_WRITE:
859 set_bit(NFS_O_RDWR_STATE, &state->flags);
863 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
865 write_seqlock(&state->seqlock);
866 nfs_set_open_stateid_locked(state, stateid, fmode);
867 write_sequnlock(&state->seqlock);
870 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
873 * Protect the call to nfs4_state_set_mode_locked and
874 * serialise the stateid update
876 write_seqlock(&state->seqlock);
877 if (deleg_stateid != NULL) {
878 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
879 set_bit(NFS_DELEGATED_STATE, &state->flags);
881 if (open_stateid != NULL)
882 nfs_set_open_stateid_locked(state, open_stateid, fmode);
883 write_sequnlock(&state->seqlock);
884 spin_lock(&state->owner->so_lock);
885 update_open_stateflags(state, fmode);
886 spin_unlock(&state->owner->so_lock);
889 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
891 struct nfs_inode *nfsi = NFS_I(state->inode);
892 struct nfs_delegation *deleg_cur;
895 fmode &= (FMODE_READ|FMODE_WRITE);
898 deleg_cur = rcu_dereference(nfsi->delegation);
899 if (deleg_cur == NULL)
902 spin_lock(&deleg_cur->lock);
903 if (nfsi->delegation != deleg_cur ||
904 (deleg_cur->type & fmode) != fmode)
905 goto no_delegation_unlock;
907 if (delegation == NULL)
908 delegation = &deleg_cur->stateid;
909 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
910 goto no_delegation_unlock;
912 nfs_mark_delegation_referenced(deleg_cur);
913 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
915 no_delegation_unlock:
916 spin_unlock(&deleg_cur->lock);
920 if (!ret && open_stateid != NULL) {
921 __update_open_stateid(state, open_stateid, NULL, fmode);
929 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
931 struct nfs_delegation *delegation;
934 delegation = rcu_dereference(NFS_I(inode)->delegation);
935 if (delegation == NULL || (delegation->type & fmode) == fmode) {
940 nfs_inode_return_delegation(inode);
943 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
945 struct nfs4_state *state = opendata->state;
946 struct nfs_inode *nfsi = NFS_I(state->inode);
947 struct nfs_delegation *delegation;
948 int open_mode = opendata->o_arg.open_flags & O_EXCL;
949 fmode_t fmode = opendata->o_arg.fmode;
950 nfs4_stateid stateid;
954 if (can_open_cached(state, fmode, open_mode)) {
955 spin_lock(&state->owner->so_lock);
956 if (can_open_cached(state, fmode, open_mode)) {
957 update_open_stateflags(state, fmode);
958 spin_unlock(&state->owner->so_lock);
959 goto out_return_state;
961 spin_unlock(&state->owner->so_lock);
964 delegation = rcu_dereference(nfsi->delegation);
965 if (delegation == NULL ||
966 !can_open_delegated(delegation, fmode)) {
970 /* Save the delegation */
971 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
973 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
978 /* Try to update the stateid using the delegation */
979 if (update_open_stateid(state, NULL, &stateid, fmode))
980 goto out_return_state;
985 atomic_inc(&state->count);
989 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
992 struct nfs4_state *state = NULL;
993 struct nfs_delegation *delegation;
996 if (!data->rpc_done) {
997 state = nfs4_try_open_cached(data);
1002 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1004 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1005 ret = PTR_ERR(inode);
1009 state = nfs4_get_open_state(inode, data->owner);
1012 if (data->o_res.delegation_type != 0) {
1013 int delegation_flags = 0;
1016 delegation = rcu_dereference(NFS_I(inode)->delegation);
1018 delegation_flags = delegation->flags;
1020 if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1021 nfs_inode_set_delegation(state->inode,
1022 data->owner->so_cred,
1025 nfs_inode_reclaim_delegation(state->inode,
1026 data->owner->so_cred,
1030 update_open_stateid(state, &data->o_res.stateid, NULL,
1038 return ERR_PTR(ret);
1041 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1043 struct nfs_inode *nfsi = NFS_I(state->inode);
1044 struct nfs_open_context *ctx;
1046 spin_lock(&state->inode->i_lock);
1047 list_for_each_entry(ctx, &nfsi->open_files, list) {
1048 if (ctx->state != state)
1050 get_nfs_open_context(ctx);
1051 spin_unlock(&state->inode->i_lock);
1054 spin_unlock(&state->inode->i_lock);
1055 return ERR_PTR(-ENOENT);
1058 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1060 struct nfs4_opendata *opendata;
1062 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS);
1063 if (opendata == NULL)
1064 return ERR_PTR(-ENOMEM);
1065 opendata->state = state;
1066 atomic_inc(&state->count);
1070 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1072 struct nfs4_state *newstate;
1075 opendata->o_arg.open_flags = 0;
1076 opendata->o_arg.fmode = fmode;
1077 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1078 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1079 nfs4_init_opendata_res(opendata);
1080 ret = _nfs4_recover_proc_open(opendata);
1083 newstate = nfs4_opendata_to_nfs4_state(opendata);
1084 if (IS_ERR(newstate))
1085 return PTR_ERR(newstate);
1086 nfs4_close_state(&opendata->path, newstate, fmode);
1091 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1093 struct nfs4_state *newstate;
1096 /* memory barrier prior to reading state->n_* */
1097 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1099 if (state->n_rdwr != 0) {
1100 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1103 if (newstate != state)
1106 if (state->n_wronly != 0) {
1107 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1110 if (newstate != state)
1113 if (state->n_rdonly != 0) {
1114 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1117 if (newstate != state)
1121 * We may have performed cached opens for all three recoveries.
1122 * Check if we need to update the current stateid.
1124 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1125 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
1126 write_seqlock(&state->seqlock);
1127 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1128 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
1129 write_sequnlock(&state->seqlock);
1136 * reclaim state on the server after a reboot.
1138 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1140 struct nfs_delegation *delegation;
1141 struct nfs4_opendata *opendata;
1142 fmode_t delegation_type = 0;
1145 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1146 if (IS_ERR(opendata))
1147 return PTR_ERR(opendata);
1148 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1149 opendata->o_arg.fh = NFS_FH(state->inode);
1151 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1152 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1153 delegation_type = delegation->type;
1155 opendata->o_arg.u.delegation_type = delegation_type;
1156 status = nfs4_open_recover(opendata, state);
1157 nfs4_opendata_put(opendata);
1161 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1163 struct nfs_server *server = NFS_SERVER(state->inode);
1164 struct nfs4_exception exception = { };
1167 err = _nfs4_do_open_reclaim(ctx, state);
1168 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
1170 nfs4_handle_exception(server, err, &exception);
1171 } while (exception.retry);
1175 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1177 struct nfs_open_context *ctx;
1180 ctx = nfs4_state_find_open_context(state);
1182 return PTR_ERR(ctx);
1183 ret = nfs4_do_open_reclaim(ctx, state);
1184 put_nfs_open_context(ctx);
1188 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1190 struct nfs4_opendata *opendata;
1193 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1194 if (IS_ERR(opendata))
1195 return PTR_ERR(opendata);
1196 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1197 memcpy(opendata->o_arg.u.delegation.data, stateid->data,
1198 sizeof(opendata->o_arg.u.delegation.data));
1199 ret = nfs4_open_recover(opendata, state);
1200 nfs4_opendata_put(opendata);
1204 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1206 struct nfs4_exception exception = { };
1207 struct nfs_server *server = NFS_SERVER(state->inode);
1210 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1216 case -NFS4ERR_BADSESSION:
1217 case -NFS4ERR_BADSLOT:
1218 case -NFS4ERR_BAD_HIGH_SLOT:
1219 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1220 case -NFS4ERR_DEADSESSION:
1221 nfs4_schedule_state_recovery(
1222 server->nfs_client);
1224 case -NFS4ERR_STALE_CLIENTID:
1225 case -NFS4ERR_STALE_STATEID:
1226 case -NFS4ERR_EXPIRED:
1227 /* Don't recall a delegation if it was lost */
1228 nfs4_schedule_state_recovery(server->nfs_client);
1232 * The show must go on: exit, but mark the
1233 * stateid as needing recovery.
1235 case -NFS4ERR_ADMIN_REVOKED:
1236 case -NFS4ERR_BAD_STATEID:
1237 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
1242 err = nfs4_handle_exception(server, err, &exception);
1243 } while (exception.retry);
1248 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1250 struct nfs4_opendata *data = calldata;
1252 data->rpc_status = task->tk_status;
1253 if (RPC_ASSASSINATED(task))
1255 if (data->rpc_status == 0) {
1256 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1257 sizeof(data->o_res.stateid.data));
1258 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1259 renew_lease(data->o_res.server, data->timestamp);
1264 static void nfs4_open_confirm_release(void *calldata)
1266 struct nfs4_opendata *data = calldata;
1267 struct nfs4_state *state = NULL;
1269 /* If this request hasn't been cancelled, do nothing */
1270 if (data->cancelled == 0)
1272 /* In case of error, no cleanup! */
1273 if (!data->rpc_done)
1275 state = nfs4_opendata_to_nfs4_state(data);
1277 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1279 nfs4_opendata_put(data);
1282 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1283 .rpc_call_done = nfs4_open_confirm_done,
1284 .rpc_release = nfs4_open_confirm_release,
1288 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1290 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1292 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1293 struct rpc_task *task;
1294 struct rpc_message msg = {
1295 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1296 .rpc_argp = &data->c_arg,
1297 .rpc_resp = &data->c_res,
1298 .rpc_cred = data->owner->so_cred,
1300 struct rpc_task_setup task_setup_data = {
1301 .rpc_client = server->client,
1302 .rpc_message = &msg,
1303 .callback_ops = &nfs4_open_confirm_ops,
1304 .callback_data = data,
1305 .workqueue = nfsiod_workqueue,
1306 .flags = RPC_TASK_ASYNC,
1310 kref_get(&data->kref);
1312 data->rpc_status = 0;
1313 data->timestamp = jiffies;
1314 task = rpc_run_task(&task_setup_data);
1316 return PTR_ERR(task);
1317 status = nfs4_wait_for_completion_rpc_task(task);
1319 data->cancelled = 1;
1322 status = data->rpc_status;
1327 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1329 struct nfs4_opendata *data = calldata;
1330 struct nfs4_state_owner *sp = data->owner;
1332 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1335 * Check if we still need to send an OPEN call, or if we can use
1336 * a delegation instead.
1338 if (data->state != NULL) {
1339 struct nfs_delegation *delegation;
1341 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1344 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1345 if (delegation != NULL &&
1346 test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
1352 /* Update sequence id. */
1353 data->o_arg.id = sp->so_owner_id.id;
1354 data->o_arg.clientid = sp->so_client->cl_clientid;
1355 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1356 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1357 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1359 data->timestamp = jiffies;
1360 if (nfs4_setup_sequence(data->o_arg.server->nfs_client,
1361 &data->o_arg.seq_args,
1362 &data->o_res.seq_res, 1, task))
1364 rpc_call_start(task);
1367 task->tk_action = NULL;
1371 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1373 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1374 nfs4_open_prepare(task, calldata);
1377 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1379 struct nfs4_opendata *data = calldata;
1381 data->rpc_status = task->tk_status;
1383 nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res,
1386 if (RPC_ASSASSINATED(task))
1388 if (task->tk_status == 0) {
1389 switch (data->o_res.f_attr->mode & S_IFMT) {
1393 data->rpc_status = -ELOOP;
1396 data->rpc_status = -EISDIR;
1399 data->rpc_status = -ENOTDIR;
1401 renew_lease(data->o_res.server, data->timestamp);
1402 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1403 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1408 static void nfs4_open_release(void *calldata)
1410 struct nfs4_opendata *data = calldata;
1411 struct nfs4_state *state = NULL;
1413 /* If this request hasn't been cancelled, do nothing */
1414 if (data->cancelled == 0)
1416 /* In case of error, no cleanup! */
1417 if (data->rpc_status != 0 || !data->rpc_done)
1419 /* In case we need an open_confirm, no cleanup! */
1420 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1422 state = nfs4_opendata_to_nfs4_state(data);
1424 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1426 nfs4_opendata_put(data);
1429 static const struct rpc_call_ops nfs4_open_ops = {
1430 .rpc_call_prepare = nfs4_open_prepare,
1431 .rpc_call_done = nfs4_open_done,
1432 .rpc_release = nfs4_open_release,
1435 static const struct rpc_call_ops nfs4_recover_open_ops = {
1436 .rpc_call_prepare = nfs4_recover_open_prepare,
1437 .rpc_call_done = nfs4_open_done,
1438 .rpc_release = nfs4_open_release,
1441 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1443 struct inode *dir = data->dir->d_inode;
1444 struct nfs_server *server = NFS_SERVER(dir);
1445 struct nfs_openargs *o_arg = &data->o_arg;
1446 struct nfs_openres *o_res = &data->o_res;
1447 struct rpc_task *task;
1448 struct rpc_message msg = {
1449 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1452 .rpc_cred = data->owner->so_cred,
1454 struct rpc_task_setup task_setup_data = {
1455 .rpc_client = server->client,
1456 .rpc_message = &msg,
1457 .callback_ops = &nfs4_open_ops,
1458 .callback_data = data,
1459 .workqueue = nfsiod_workqueue,
1460 .flags = RPC_TASK_ASYNC,
1464 kref_get(&data->kref);
1466 data->rpc_status = 0;
1467 data->cancelled = 0;
1469 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1470 task = rpc_run_task(&task_setup_data);
1472 return PTR_ERR(task);
1473 status = nfs4_wait_for_completion_rpc_task(task);
1475 data->cancelled = 1;
1478 status = data->rpc_status;
1484 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1486 struct inode *dir = data->dir->d_inode;
1487 struct nfs_openres *o_res = &data->o_res;
1490 status = nfs4_run_open_task(data, 1);
1491 if (status != 0 || !data->rpc_done)
1494 nfs_refresh_inode(dir, o_res->dir_attr);
1496 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1497 status = _nfs4_proc_open_confirm(data);
1506 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1508 static int _nfs4_proc_open(struct nfs4_opendata *data)
1510 struct inode *dir = data->dir->d_inode;
1511 struct nfs_server *server = NFS_SERVER(dir);
1512 struct nfs_openargs *o_arg = &data->o_arg;
1513 struct nfs_openres *o_res = &data->o_res;
1516 status = nfs4_run_open_task(data, 0);
1517 if (status != 0 || !data->rpc_done)
1520 if (o_arg->open_flags & O_CREAT) {
1521 update_changeattr(dir, &o_res->cinfo);
1522 nfs_post_op_update_inode(dir, o_res->dir_attr);
1524 nfs_refresh_inode(dir, o_res->dir_attr);
1525 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1526 server->caps &= ~NFS_CAP_POSIX_LOCK;
1527 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1528 status = _nfs4_proc_open_confirm(data);
1532 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1533 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1537 static int nfs4_recover_expired_lease(struct nfs_server *server)
1539 struct nfs_client *clp = server->nfs_client;
1543 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1544 ret = nfs4_wait_clnt_recover(clp);
1547 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1548 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1550 nfs4_schedule_state_recovery(clp);
1558 * reclaim state on the server after a network partition.
1559 * Assumes caller holds the appropriate lock
1561 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1563 struct nfs4_opendata *opendata;
1566 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1567 if (IS_ERR(opendata))
1568 return PTR_ERR(opendata);
1569 ret = nfs4_open_recover(opendata, state);
1571 d_drop(ctx->path.dentry);
1572 nfs4_opendata_put(opendata);
1576 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1578 struct nfs_server *server = NFS_SERVER(state->inode);
1579 struct nfs4_exception exception = { };
1583 err = _nfs4_open_expired(ctx, state);
1587 case -NFS4ERR_GRACE:
1588 case -NFS4ERR_DELAY:
1590 nfs4_handle_exception(server, err, &exception);
1593 } while (exception.retry);
1598 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1600 struct nfs_open_context *ctx;
1603 ctx = nfs4_state_find_open_context(state);
1605 return PTR_ERR(ctx);
1606 ret = nfs4_do_open_expired(ctx, state);
1607 put_nfs_open_context(ctx);
1612 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1613 * fields corresponding to attributes that were used to store the verifier.
1614 * Make sure we clobber those fields in the later setattr call
1616 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1618 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1619 !(sattr->ia_valid & ATTR_ATIME_SET))
1620 sattr->ia_valid |= ATTR_ATIME;
1622 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1623 !(sattr->ia_valid & ATTR_MTIME_SET))
1624 sattr->ia_valid |= ATTR_MTIME;
1628 * Returns a referenced nfs4_state
1630 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)
1632 struct nfs4_state_owner *sp;
1633 struct nfs4_state *state = NULL;
1634 struct nfs_server *server = NFS_SERVER(dir);
1635 struct nfs4_opendata *opendata;
1638 /* Protect against reboot recovery conflicts */
1640 if (!(sp = nfs4_get_state_owner(server, cred))) {
1641 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1644 status = nfs4_recover_expired_lease(server);
1646 goto err_put_state_owner;
1647 if (path->dentry->d_inode != NULL)
1648 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1650 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL);
1651 if (opendata == NULL)
1652 goto err_put_state_owner;
1654 if (path->dentry->d_inode != NULL)
1655 opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
1657 status = _nfs4_proc_open(opendata);
1659 goto err_opendata_put;
1661 state = nfs4_opendata_to_nfs4_state(opendata);
1662 status = PTR_ERR(state);
1664 goto err_opendata_put;
1665 if (server->caps & NFS_CAP_POSIX_LOCK)
1666 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1668 if (opendata->o_arg.open_flags & O_EXCL) {
1669 nfs4_exclusive_attrset(opendata, sattr);
1671 nfs_fattr_init(opendata->o_res.f_attr);
1672 status = nfs4_do_setattr(state->inode, cred,
1673 opendata->o_res.f_attr, sattr,
1676 nfs_setattr_update_inode(state->inode, sattr);
1677 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1679 nfs4_opendata_put(opendata);
1680 nfs4_put_state_owner(sp);
1684 nfs4_opendata_put(opendata);
1685 err_put_state_owner:
1686 nfs4_put_state_owner(sp);
1693 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)
1695 struct nfs4_exception exception = { };
1696 struct nfs4_state *res;
1700 status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
1703 /* NOTE: BAD_SEQID means the server and client disagree about the
1704 * book-keeping w.r.t. state-changing operations
1705 * (OPEN/CLOSE/LOCK/LOCKU...)
1706 * It is actually a sign of a bug on the client or on the server.
1708 * If we receive a BAD_SEQID error in the particular case of
1709 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1710 * have unhashed the old state_owner for us, and that we can
1711 * therefore safely retry using a new one. We should still warn
1712 * the user though...
1714 if (status == -NFS4ERR_BAD_SEQID) {
1715 printk(KERN_WARNING "NFS: v4 server %s "
1716 " returned a bad sequence-id error!\n",
1717 NFS_SERVER(dir)->nfs_client->cl_hostname);
1718 exception.retry = 1;
1722 * BAD_STATEID on OPEN means that the server cancelled our
1723 * state before it received the OPEN_CONFIRM.
1724 * Recover by retrying the request as per the discussion
1725 * on Page 181 of RFC3530.
1727 if (status == -NFS4ERR_BAD_STATEID) {
1728 exception.retry = 1;
1731 if (status == -EAGAIN) {
1732 /* We must have found a delegation */
1733 exception.retry = 1;
1736 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1737 status, &exception));
1738 } while (exception.retry);
1742 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1743 struct nfs_fattr *fattr, struct iattr *sattr,
1744 struct nfs4_state *state)
1746 struct nfs_server *server = NFS_SERVER(inode);
1747 struct nfs_setattrargs arg = {
1748 .fh = NFS_FH(inode),
1751 .bitmask = server->attr_bitmask,
1753 struct nfs_setattrres res = {
1757 struct rpc_message msg = {
1758 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1763 unsigned long timestamp = jiffies;
1766 nfs_fattr_init(fattr);
1768 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1769 /* Use that stateid */
1770 } else if (state != NULL) {
1771 nfs4_copy_stateid(&arg.stateid, state, current->files);
1773 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1775 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
1776 if (status == 0 && state != NULL)
1777 renew_lease(server, timestamp);
1781 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1782 struct nfs_fattr *fattr, struct iattr *sattr,
1783 struct nfs4_state *state)
1785 struct nfs_server *server = NFS_SERVER(inode);
1786 struct nfs4_exception exception = { };
1789 err = nfs4_handle_exception(server,
1790 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1792 } while (exception.retry);
1796 struct nfs4_closedata {
1798 struct inode *inode;
1799 struct nfs4_state *state;
1800 struct nfs_closeargs arg;
1801 struct nfs_closeres res;
1802 struct nfs_fattr fattr;
1803 unsigned long timestamp;
1806 static void nfs4_free_closedata(void *data)
1808 struct nfs4_closedata *calldata = data;
1809 struct nfs4_state_owner *sp = calldata->state->owner;
1811 nfs4_put_open_state(calldata->state);
1812 nfs_free_seqid(calldata->arg.seqid);
1813 nfs4_put_state_owner(sp);
1814 path_put(&calldata->path);
1818 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1821 spin_lock(&state->owner->so_lock);
1822 if (!(fmode & FMODE_READ))
1823 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1824 if (!(fmode & FMODE_WRITE))
1825 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1826 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1827 spin_unlock(&state->owner->so_lock);
1830 static void nfs4_close_done(struct rpc_task *task, void *data)
1832 struct nfs4_closedata *calldata = data;
1833 struct nfs4_state *state = calldata->state;
1834 struct nfs_server *server = NFS_SERVER(calldata->inode);
1836 nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status);
1837 if (RPC_ASSASSINATED(task))
1839 /* hmm. we are done with the inode, and in the process of freeing
1840 * the state_owner. we keep this around to process errors
1842 switch (task->tk_status) {
1844 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1845 renew_lease(server, calldata->timestamp);
1846 nfs4_close_clear_stateid_flags(state,
1847 calldata->arg.fmode);
1849 case -NFS4ERR_STALE_STATEID:
1850 case -NFS4ERR_OLD_STATEID:
1851 case -NFS4ERR_BAD_STATEID:
1852 case -NFS4ERR_EXPIRED:
1853 if (calldata->arg.fmode == 0)
1856 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1857 rpc_restart_call_prepare(task);
1859 nfs_release_seqid(calldata->arg.seqid);
1860 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1863 static void nfs4_close_prepare(struct rpc_task *task, void *data)
1865 struct nfs4_closedata *calldata = data;
1866 struct nfs4_state *state = calldata->state;
1869 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1872 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1873 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1874 spin_lock(&state->owner->so_lock);
1875 /* Calculate the change in open mode */
1876 if (state->n_rdwr == 0) {
1877 if (state->n_rdonly == 0) {
1878 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1879 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1880 calldata->arg.fmode &= ~FMODE_READ;
1882 if (state->n_wronly == 0) {
1883 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1884 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1885 calldata->arg.fmode &= ~FMODE_WRITE;
1888 spin_unlock(&state->owner->so_lock);
1891 /* Note: exit _without_ calling nfs4_close_done */
1892 task->tk_action = NULL;
1896 if (calldata->arg.fmode == 0)
1897 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1899 nfs_fattr_init(calldata->res.fattr);
1900 calldata->timestamp = jiffies;
1901 if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client,
1902 &calldata->arg.seq_args, &calldata->res.seq_res,
1905 rpc_call_start(task);
1908 static const struct rpc_call_ops nfs4_close_ops = {
1909 .rpc_call_prepare = nfs4_close_prepare,
1910 .rpc_call_done = nfs4_close_done,
1911 .rpc_release = nfs4_free_closedata,
1915 * It is possible for data to be read/written from a mem-mapped file
1916 * after the sys_close call (which hits the vfs layer as a flush).
1917 * This means that we can't safely call nfsv4 close on a file until
1918 * the inode is cleared. This in turn means that we are not good
1919 * NFSv4 citizens - we do not indicate to the server to update the file's
1920 * share state even when we are done with one of the three share
1921 * stateid's in the inode.
1923 * NOTE: Caller must be holding the sp->so_owner semaphore!
1925 int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait)
1927 struct nfs_server *server = NFS_SERVER(state->inode);
1928 struct nfs4_closedata *calldata;
1929 struct nfs4_state_owner *sp = state->owner;
1930 struct rpc_task *task;
1931 struct rpc_message msg = {
1932 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
1933 .rpc_cred = state->owner->so_cred,
1935 struct rpc_task_setup task_setup_data = {
1936 .rpc_client = server->client,
1937 .rpc_message = &msg,
1938 .callback_ops = &nfs4_close_ops,
1939 .workqueue = nfsiod_workqueue,
1940 .flags = RPC_TASK_ASYNC,
1942 int status = -ENOMEM;
1944 calldata = kzalloc(sizeof(*calldata), gfp_mask);
1945 if (calldata == NULL)
1947 calldata->inode = state->inode;
1948 calldata->state = state;
1949 calldata->arg.fh = NFS_FH(state->inode);
1950 calldata->arg.stateid = &state->open_stateid;
1951 /* Serialization for the sequence id */
1952 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
1953 if (calldata->arg.seqid == NULL)
1954 goto out_free_calldata;
1955 calldata->arg.fmode = 0;
1956 calldata->arg.bitmask = server->cache_consistency_bitmask;
1957 calldata->res.fattr = &calldata->fattr;
1958 calldata->res.seqid = calldata->arg.seqid;
1959 calldata->res.server = server;
1960 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
1962 calldata->path = *path;
1964 msg.rpc_argp = &calldata->arg,
1965 msg.rpc_resp = &calldata->res,
1966 task_setup_data.callback_data = calldata;
1967 task = rpc_run_task(&task_setup_data);
1969 return PTR_ERR(task);
1972 status = rpc_wait_for_completion_task(task);
1978 nfs4_put_open_state(state);
1979 nfs4_put_state_owner(sp);
1983 static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode)
1988 /* If the open_intent is for execute, we have an extra check to make */
1989 if (fmode & FMODE_EXEC) {
1990 ret = nfs_may_open(state->inode,
1991 state->owner->so_cred,
1992 nd->intent.open.flags);
1996 filp = lookup_instantiate_filp(nd, path->dentry, NULL);
1997 if (!IS_ERR(filp)) {
1998 struct nfs_open_context *ctx;
1999 ctx = nfs_file_open_context(filp);
2003 ret = PTR_ERR(filp);
2005 nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
2010 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
2012 struct path path = {
2013 .mnt = nd->path.mnt,
2016 struct dentry *parent;
2018 struct rpc_cred *cred;
2019 struct nfs4_state *state;
2021 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
2023 if (nd->flags & LOOKUP_CREATE) {
2024 attr.ia_mode = nd->intent.open.create_mode;
2025 attr.ia_valid = ATTR_MODE;
2026 if (!IS_POSIXACL(dir))
2027 attr.ia_mode &= ~current_umask();
2030 BUG_ON(nd->intent.open.flags & O_CREAT);
2033 cred = rpc_lookup_cred();
2035 return (struct dentry *)cred;
2036 parent = dentry->d_parent;
2037 /* Protect against concurrent sillydeletes */
2038 nfs_block_sillyrename(parent);
2039 state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred);
2041 if (IS_ERR(state)) {
2042 if (PTR_ERR(state) == -ENOENT) {
2043 d_add(dentry, NULL);
2044 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2046 nfs_unblock_sillyrename(parent);
2047 return (struct dentry *)state;
2049 res = d_add_unique(dentry, igrab(state->inode));
2052 nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
2053 nfs_unblock_sillyrename(parent);
2054 nfs4_intent_set_file(nd, &path, state, fmode);
2059 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
2061 struct path path = {
2062 .mnt = nd->path.mnt,
2065 struct rpc_cred *cred;
2066 struct nfs4_state *state;
2067 fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
2069 cred = rpc_lookup_cred();
2071 return PTR_ERR(cred);
2072 state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
2074 if (IS_ERR(state)) {
2075 switch (PTR_ERR(state)) {
2081 return PTR_ERR(state);
2086 if (state->inode == dentry->d_inode) {
2087 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2088 nfs4_intent_set_file(nd, &path, state, fmode);
2091 nfs4_close_sync(&path, state, fmode);
2097 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2099 if (ctx->state == NULL)
2102 nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
2104 nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
2107 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2109 struct nfs4_server_caps_arg args = {
2112 struct nfs4_server_caps_res res = {};
2113 struct rpc_message msg = {
2114 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2120 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2122 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2123 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2124 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2125 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2126 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2127 NFS_CAP_CTIME|NFS_CAP_MTIME);
2128 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2129 server->caps |= NFS_CAP_ACLS;
2130 if (res.has_links != 0)
2131 server->caps |= NFS_CAP_HARDLINKS;
2132 if (res.has_symlinks != 0)
2133 server->caps |= NFS_CAP_SYMLINKS;
2134 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2135 server->caps |= NFS_CAP_FILEID;
2136 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2137 server->caps |= NFS_CAP_MODE;
2138 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2139 server->caps |= NFS_CAP_NLINK;
2140 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2141 server->caps |= NFS_CAP_OWNER;
2142 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2143 server->caps |= NFS_CAP_OWNER_GROUP;
2144 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2145 server->caps |= NFS_CAP_ATIME;
2146 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2147 server->caps |= NFS_CAP_CTIME;
2148 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2149 server->caps |= NFS_CAP_MTIME;
2151 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2152 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2153 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2154 server->acl_bitmask = res.acl_bitmask;
2160 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2162 struct nfs4_exception exception = { };
2165 err = nfs4_handle_exception(server,
2166 _nfs4_server_capabilities(server, fhandle),
2168 } while (exception.retry);
2172 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2173 struct nfs_fsinfo *info)
2175 struct nfs4_lookup_root_arg args = {
2176 .bitmask = nfs4_fattr_bitmap,
2178 struct nfs4_lookup_res res = {
2180 .fattr = info->fattr,
2183 struct rpc_message msg = {
2184 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2189 nfs_fattr_init(info->fattr);
2190 return nfs4_call_sync(server, &msg, &args, &res, 0);
2193 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2194 struct nfs_fsinfo *info)
2196 struct nfs4_exception exception = { };
2199 err = nfs4_handle_exception(server,
2200 _nfs4_lookup_root(server, fhandle, info),
2202 } while (exception.retry);
2207 * get the file handle for the "/" directory on the server
2209 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2210 struct nfs_fsinfo *info)
2214 status = nfs4_lookup_root(server, fhandle, info);
2216 status = nfs4_server_capabilities(server, fhandle);
2218 status = nfs4_do_fsinfo(server, fhandle, info);
2219 return nfs4_map_errors(status);
2223 * Get locations and (maybe) other attributes of a referral.
2224 * Note that we'll actually follow the referral later when
2225 * we detect fsid mismatch in inode revalidation
2227 static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
2229 int status = -ENOMEM;
2230 struct page *page = NULL;
2231 struct nfs4_fs_locations *locations = NULL;
2233 page = alloc_page(GFP_KERNEL);
2236 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2237 if (locations == NULL)
2240 status = nfs4_proc_fs_locations(dir, name, locations, page);
2243 /* Make sure server returned a different fsid for the referral */
2244 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2245 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
2250 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2251 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
2253 fattr->mode = S_IFDIR;
2254 memset(fhandle, 0, sizeof(struct nfs_fh));
2263 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2265 struct nfs4_getattr_arg args = {
2267 .bitmask = server->attr_bitmask,
2269 struct nfs4_getattr_res res = {
2273 struct rpc_message msg = {
2274 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2279 nfs_fattr_init(fattr);
2280 return nfs4_call_sync(server, &msg, &args, &res, 0);
2283 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2285 struct nfs4_exception exception = { };
2288 err = nfs4_handle_exception(server,
2289 _nfs4_proc_getattr(server, fhandle, fattr),
2291 } while (exception.retry);
2296 * The file is not closed if it is opened due to the a request to change
2297 * the size of the file. The open call will not be needed once the
2298 * VFS layer lookup-intents are implemented.
2300 * Close is called when the inode is destroyed.
2301 * If we haven't opened the file for O_WRONLY, we
2302 * need to in the size_change case to obtain a stateid.
2305 * Because OPEN is always done by name in nfsv4, it is
2306 * possible that we opened a different file by the same
2307 * name. We can recognize this race condition, but we
2308 * can't do anything about it besides returning an error.
2310 * This will be fixed with VFS changes (lookup-intent).
2313 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2314 struct iattr *sattr)
2316 struct inode *inode = dentry->d_inode;
2317 struct rpc_cred *cred = NULL;
2318 struct nfs4_state *state = NULL;
2321 nfs_fattr_init(fattr);
2323 /* Search for an existing open(O_WRITE) file */
2324 if (sattr->ia_valid & ATTR_FILE) {
2325 struct nfs_open_context *ctx;
2327 ctx = nfs_file_open_context(sattr->ia_file);
2334 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2336 nfs_setattr_update_inode(inode, sattr);
2340 static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh,
2341 const struct qstr *name, struct nfs_fh *fhandle,
2342 struct nfs_fattr *fattr)
2345 struct nfs4_lookup_arg args = {
2346 .bitmask = server->attr_bitmask,
2350 struct nfs4_lookup_res res = {
2355 struct rpc_message msg = {
2356 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2361 nfs_fattr_init(fattr);
2363 dprintk("NFS call lookupfh %s\n", name->name);
2364 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2365 dprintk("NFS reply lookupfh: %d\n", status);
2369 static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
2370 struct qstr *name, struct nfs_fh *fhandle,
2371 struct nfs_fattr *fattr)
2373 struct nfs4_exception exception = { };
2376 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
2378 if (err == -NFS4ERR_MOVED) {
2382 err = nfs4_handle_exception(server, err, &exception);
2383 } while (exception.retry);
2387 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name,
2388 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2392 dprintk("NFS call lookup %s\n", name->name);
2393 status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
2394 if (status == -NFS4ERR_MOVED)
2395 status = nfs4_get_referral(dir, name, fattr, fhandle);
2396 dprintk("NFS reply lookup: %d\n", status);
2400 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2402 struct nfs4_exception exception = { };
2405 err = nfs4_handle_exception(NFS_SERVER(dir),
2406 _nfs4_proc_lookup(dir, name, fhandle, fattr),
2408 } while (exception.retry);
2412 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2414 struct nfs_server *server = NFS_SERVER(inode);
2415 struct nfs4_accessargs args = {
2416 .fh = NFS_FH(inode),
2417 .bitmask = server->attr_bitmask,
2419 struct nfs4_accessres res = {
2422 struct rpc_message msg = {
2423 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2426 .rpc_cred = entry->cred,
2428 int mode = entry->mask;
2432 * Determine which access bits we want to ask for...
2434 if (mode & MAY_READ)
2435 args.access |= NFS4_ACCESS_READ;
2436 if (S_ISDIR(inode->i_mode)) {
2437 if (mode & MAY_WRITE)
2438 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2439 if (mode & MAY_EXEC)
2440 args.access |= NFS4_ACCESS_LOOKUP;
2442 if (mode & MAY_WRITE)
2443 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2444 if (mode & MAY_EXEC)
2445 args.access |= NFS4_ACCESS_EXECUTE;
2448 res.fattr = nfs_alloc_fattr();
2449 if (res.fattr == NULL)
2452 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2455 if (res.access & NFS4_ACCESS_READ)
2456 entry->mask |= MAY_READ;
2457 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2458 entry->mask |= MAY_WRITE;
2459 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2460 entry->mask |= MAY_EXEC;
2461 nfs_refresh_inode(inode, res.fattr);
2463 nfs_free_fattr(res.fattr);
2467 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2469 struct nfs4_exception exception = { };
2472 err = nfs4_handle_exception(NFS_SERVER(inode),
2473 _nfs4_proc_access(inode, entry),
2475 } while (exception.retry);
2480 * TODO: For the time being, we don't try to get any attributes
2481 * along with any of the zero-copy operations READ, READDIR,
2484 * In the case of the first three, we want to put the GETATTR
2485 * after the read-type operation -- this is because it is hard
2486 * to predict the length of a GETATTR response in v4, and thus
2487 * align the READ data correctly. This means that the GETATTR
2488 * may end up partially falling into the page cache, and we should
2489 * shift it into the 'tail' of the xdr_buf before processing.
2490 * To do this efficiently, we need to know the total length
2491 * of data received, which doesn't seem to be available outside
2494 * In the case of WRITE, we also want to put the GETATTR after
2495 * the operation -- in this case because we want to make sure
2496 * we get the post-operation mtime and size. This means that
2497 * we can't use xdr_encode_pages() as written: we need a variant
2498 * of it which would leave room in the 'tail' iovec.
2500 * Both of these changes to the XDR layer would in fact be quite
2501 * minor, but I decided to leave them for a subsequent patch.
2503 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2504 unsigned int pgbase, unsigned int pglen)
2506 struct nfs4_readlink args = {
2507 .fh = NFS_FH(inode),
2512 struct nfs4_readlink_res res;
2513 struct rpc_message msg = {
2514 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2519 return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
2522 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2523 unsigned int pgbase, unsigned int pglen)
2525 struct nfs4_exception exception = { };
2528 err = nfs4_handle_exception(NFS_SERVER(inode),
2529 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2531 } while (exception.retry);
2537 * We will need to arrange for the VFS layer to provide an atomic open.
2538 * Until then, this create/open method is prone to inefficiency and race
2539 * conditions due to the lookup, create, and open VFS calls from sys_open()
2540 * placed on the wire.
2542 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2543 * The file will be opened again in the subsequent VFS open call
2544 * (nfs4_proc_file_open).
2546 * The open for read will just hang around to be used by any process that
2547 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2551 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2552 int flags, struct nameidata *nd)
2554 struct path path = {
2555 .mnt = nd->path.mnt,
2558 struct nfs4_state *state;
2559 struct rpc_cred *cred;
2560 fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE);
2563 cred = rpc_lookup_cred();
2565 status = PTR_ERR(cred);
2568 state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred);
2570 if (IS_ERR(state)) {
2571 status = PTR_ERR(state);
2574 d_add(dentry, igrab(state->inode));
2575 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2576 if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
2577 status = nfs4_intent_set_file(nd, &path, state, fmode);
2579 nfs4_close_sync(&path, state, fmode);
2586 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2588 struct nfs_server *server = NFS_SERVER(dir);
2589 struct nfs_removeargs args = {
2591 .name.len = name->len,
2592 .name.name = name->name,
2593 .bitmask = server->attr_bitmask,
2595 struct nfs_removeres res = {
2598 struct rpc_message msg = {
2599 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2603 int status = -ENOMEM;
2605 res.dir_attr = nfs_alloc_fattr();
2606 if (res.dir_attr == NULL)
2609 status = nfs4_call_sync(server, &msg, &args, &res, 1);
2611 update_changeattr(dir, &res.cinfo);
2612 nfs_post_op_update_inode(dir, res.dir_attr);
2614 nfs_free_fattr(res.dir_attr);
2619 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2621 struct nfs4_exception exception = { };
2624 err = nfs4_handle_exception(NFS_SERVER(dir),
2625 _nfs4_proc_remove(dir, name),
2627 } while (exception.retry);
2631 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2633 struct nfs_server *server = NFS_SERVER(dir);
2634 struct nfs_removeargs *args = msg->rpc_argp;
2635 struct nfs_removeres *res = msg->rpc_resp;
2637 args->bitmask = server->cache_consistency_bitmask;
2638 res->server = server;
2639 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2642 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2644 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2646 nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
2647 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2649 update_changeattr(dir, &res->cinfo);
2650 nfs_post_op_update_inode(dir, res->dir_attr);
2654 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2655 struct inode *new_dir, struct qstr *new_name)
2657 struct nfs_server *server = NFS_SERVER(old_dir);
2658 struct nfs4_rename_arg arg = {
2659 .old_dir = NFS_FH(old_dir),
2660 .new_dir = NFS_FH(new_dir),
2661 .old_name = old_name,
2662 .new_name = new_name,
2663 .bitmask = server->attr_bitmask,
2665 struct nfs4_rename_res res = {
2668 struct rpc_message msg = {
2669 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2673 int status = -ENOMEM;
2675 res.old_fattr = nfs_alloc_fattr();
2676 res.new_fattr = nfs_alloc_fattr();
2677 if (res.old_fattr == NULL || res.new_fattr == NULL)
2680 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2682 update_changeattr(old_dir, &res.old_cinfo);
2683 nfs_post_op_update_inode(old_dir, res.old_fattr);
2684 update_changeattr(new_dir, &res.new_cinfo);
2685 nfs_post_op_update_inode(new_dir, res.new_fattr);
2688 nfs_free_fattr(res.new_fattr);
2689 nfs_free_fattr(res.old_fattr);
2693 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2694 struct inode *new_dir, struct qstr *new_name)
2696 struct nfs4_exception exception = { };
2699 err = nfs4_handle_exception(NFS_SERVER(old_dir),
2700 _nfs4_proc_rename(old_dir, old_name,
2703 } while (exception.retry);
2707 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2709 struct nfs_server *server = NFS_SERVER(inode);
2710 struct nfs4_link_arg arg = {
2711 .fh = NFS_FH(inode),
2712 .dir_fh = NFS_FH(dir),
2714 .bitmask = server->attr_bitmask,
2716 struct nfs4_link_res res = {
2719 struct rpc_message msg = {
2720 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2724 int status = -ENOMEM;
2726 res.fattr = nfs_alloc_fattr();
2727 res.dir_attr = nfs_alloc_fattr();
2728 if (res.fattr == NULL || res.dir_attr == NULL)
2731 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2733 update_changeattr(dir, &res.cinfo);
2734 nfs_post_op_update_inode(dir, res.dir_attr);
2735 nfs_post_op_update_inode(inode, res.fattr);
2738 nfs_free_fattr(res.dir_attr);
2739 nfs_free_fattr(res.fattr);
2743 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2745 struct nfs4_exception exception = { };
2748 err = nfs4_handle_exception(NFS_SERVER(inode),
2749 _nfs4_proc_link(inode, dir, name),
2751 } while (exception.retry);
2755 struct nfs4_createdata {
2756 struct rpc_message msg;
2757 struct nfs4_create_arg arg;
2758 struct nfs4_create_res res;
2760 struct nfs_fattr fattr;
2761 struct nfs_fattr dir_fattr;
2764 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2765 struct qstr *name, struct iattr *sattr, u32 ftype)
2767 struct nfs4_createdata *data;
2769 data = kzalloc(sizeof(*data), GFP_KERNEL);
2771 struct nfs_server *server = NFS_SERVER(dir);
2773 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2774 data->msg.rpc_argp = &data->arg;
2775 data->msg.rpc_resp = &data->res;
2776 data->arg.dir_fh = NFS_FH(dir);
2777 data->arg.server = server;
2778 data->arg.name = name;
2779 data->arg.attrs = sattr;
2780 data->arg.ftype = ftype;
2781 data->arg.bitmask = server->attr_bitmask;
2782 data->res.server = server;
2783 data->res.fh = &data->fh;
2784 data->res.fattr = &data->fattr;
2785 data->res.dir_fattr = &data->dir_fattr;
2786 nfs_fattr_init(data->res.fattr);
2787 nfs_fattr_init(data->res.dir_fattr);
2792 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2794 int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg,
2795 &data->arg, &data->res, 1);
2797 update_changeattr(dir, &data->res.dir_cinfo);
2798 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2799 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2804 static void nfs4_free_createdata(struct nfs4_createdata *data)
2809 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2810 struct page *page, unsigned int len, struct iattr *sattr)
2812 struct nfs4_createdata *data;
2813 int status = -ENAMETOOLONG;
2815 if (len > NFS4_MAXPATHLEN)
2819 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2823 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2824 data->arg.u.symlink.pages = &page;
2825 data->arg.u.symlink.len = len;
2827 status = nfs4_do_create(dir, dentry, data);
2829 nfs4_free_createdata(data);
2834 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2835 struct page *page, unsigned int len, struct iattr *sattr)
2837 struct nfs4_exception exception = { };
2840 err = nfs4_handle_exception(NFS_SERVER(dir),
2841 _nfs4_proc_symlink(dir, dentry, page,
2844 } while (exception.retry);
2848 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2849 struct iattr *sattr)
2851 struct nfs4_createdata *data;
2852 int status = -ENOMEM;
2854 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2858 status = nfs4_do_create(dir, dentry, data);
2860 nfs4_free_createdata(data);
2865 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2866 struct iattr *sattr)
2868 struct nfs4_exception exception = { };
2871 err = nfs4_handle_exception(NFS_SERVER(dir),
2872 _nfs4_proc_mkdir(dir, dentry, sattr),
2874 } while (exception.retry);
2878 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2879 u64 cookie, struct page *page, unsigned int count, int plus)
2881 struct inode *dir = dentry->d_inode;
2882 struct nfs4_readdir_arg args = {
2887 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2889 struct nfs4_readdir_res res;
2890 struct rpc_message msg = {
2891 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2898 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
2899 dentry->d_parent->d_name.name,
2900 dentry->d_name.name,
2901 (unsigned long long)cookie);
2902 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2903 res.pgbase = args.pgbase;
2904 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2906 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2908 nfs_invalidate_atime(dir);
2910 dprintk("%s: returns %d\n", __func__, status);
2914 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2915 u64 cookie, struct page *page, unsigned int count, int plus)
2917 struct nfs4_exception exception = { };
2920 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2921 _nfs4_proc_readdir(dentry, cred, cookie,
2924 } while (exception.retry);
2928 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2929 struct iattr *sattr, dev_t rdev)
2931 struct nfs4_createdata *data;
2932 int mode = sattr->ia_mode;
2933 int status = -ENOMEM;
2935 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2936 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2938 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
2943 data->arg.ftype = NF4FIFO;
2944 else if (S_ISBLK(mode)) {
2945 data->arg.ftype = NF4BLK;
2946 data->arg.u.device.specdata1 = MAJOR(rdev);
2947 data->arg.u.device.specdata2 = MINOR(rdev);
2949 else if (S_ISCHR(mode)) {
2950 data->arg.ftype = NF4CHR;
2951 data->arg.u.device.specdata1 = MAJOR(rdev);
2952 data->arg.u.device.specdata2 = MINOR(rdev);
2955 status = nfs4_do_create(dir, dentry, data);
2957 nfs4_free_createdata(data);
2962 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2963 struct iattr *sattr, dev_t rdev)
2965 struct nfs4_exception exception = { };
2968 err = nfs4_handle_exception(NFS_SERVER(dir),
2969 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2971 } while (exception.retry);
2975 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2976 struct nfs_fsstat *fsstat)
2978 struct nfs4_statfs_arg args = {
2980 .bitmask = server->attr_bitmask,
2982 struct nfs4_statfs_res res = {
2985 struct rpc_message msg = {
2986 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2991 nfs_fattr_init(fsstat->fattr);
2992 return nfs4_call_sync(server, &msg, &args, &res, 0);
2995 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
2997 struct nfs4_exception exception = { };
3000 err = nfs4_handle_exception(server,
3001 _nfs4_proc_statfs(server, fhandle, fsstat),
3003 } while (exception.retry);
3007 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3008 struct nfs_fsinfo *fsinfo)
3010 struct nfs4_fsinfo_arg args = {
3012 .bitmask = server->attr_bitmask,
3014 struct nfs4_fsinfo_res res = {
3017 struct rpc_message msg = {
3018 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3023 return nfs4_call_sync(server, &msg, &args, &res, 0);
3026 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3028 struct nfs4_exception exception = { };
3032 err = nfs4_handle_exception(server,
3033 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3035 } while (exception.retry);
3039 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3041 nfs_fattr_init(fsinfo->fattr);
3042 return nfs4_do_fsinfo(server, fhandle, fsinfo);
3045 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3046 struct nfs_pathconf *pathconf)
3048 struct nfs4_pathconf_arg args = {
3050 .bitmask = server->attr_bitmask,
3052 struct nfs4_pathconf_res res = {
3053 .pathconf = pathconf,
3055 struct rpc_message msg = {
3056 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3061 /* None of the pathconf attributes are mandatory to implement */
3062 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3063 memset(pathconf, 0, sizeof(*pathconf));
3067 nfs_fattr_init(pathconf->fattr);
3068 return nfs4_call_sync(server, &msg, &args, &res, 0);
3071 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3072 struct nfs_pathconf *pathconf)
3074 struct nfs4_exception exception = { };
3078 err = nfs4_handle_exception(server,
3079 _nfs4_proc_pathconf(server, fhandle, pathconf),
3081 } while (exception.retry);
3085 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3087 struct nfs_server *server = NFS_SERVER(data->inode);
3089 dprintk("--> %s\n", __func__);
3091 nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
3093 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3094 nfs_restart_rpc(task, server->nfs_client);
3098 nfs_invalidate_atime(data->inode);
3099 if (task->tk_status > 0)
3100 renew_lease(server, data->timestamp);
3104 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3106 data->timestamp = jiffies;
3107 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3110 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3112 struct inode *inode = data->inode;
3114 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3117 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3118 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3121 if (task->tk_status >= 0) {
3122 renew_lease(NFS_SERVER(inode), data->timestamp);
3123 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
3128 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3130 struct nfs_server *server = NFS_SERVER(data->inode);
3132 data->args.bitmask = server->cache_consistency_bitmask;
3133 data->res.server = server;
3134 data->timestamp = jiffies;
3136 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3139 static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3141 struct inode *inode = data->inode;
3143 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3145 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3146 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3149 nfs_refresh_inode(inode, data->res.fattr);
3153 static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
3155 struct nfs_server *server = NFS_SERVER(data->inode);
3157 data->args.bitmask = server->cache_consistency_bitmask;
3158 data->res.server = server;
3159 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3162 struct nfs4_renewdata {
3163 struct nfs_client *client;
3164 unsigned long timestamp;
3168 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3169 * standalone procedure for queueing an asynchronous RENEW.
3171 static void nfs4_renew_release(void *calldata)
3173 struct nfs4_renewdata *data = calldata;
3174 struct nfs_client *clp = data->client;
3176 if (atomic_read(&clp->cl_count) > 1)
3177 nfs4_schedule_state_renewal(clp);
3178 nfs_put_client(clp);
3182 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3184 struct nfs4_renewdata *data = calldata;
3185 struct nfs_client *clp = data->client;
3186 unsigned long timestamp = data->timestamp;
3188 if (task->tk_status < 0) {
3189 /* Unless we're shutting down, schedule state recovery! */
3190 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
3191 nfs4_schedule_state_recovery(clp);
3194 spin_lock(&clp->cl_lock);
3195 if (time_before(clp->cl_last_renewal,timestamp))
3196 clp->cl_last_renewal = timestamp;
3197 spin_unlock(&clp->cl_lock);
3200 static const struct rpc_call_ops nfs4_renew_ops = {
3201 .rpc_call_done = nfs4_renew_done,
3202 .rpc_release = nfs4_renew_release,
3205 int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3207 struct rpc_message msg = {
3208 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3212 struct nfs4_renewdata *data;
3214 if (!atomic_inc_not_zero(&clp->cl_count))
3216 data = kmalloc(sizeof(*data), GFP_KERNEL);
3220 data->timestamp = jiffies;
3221 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3222 &nfs4_renew_ops, data);
3225 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3227 struct rpc_message msg = {
3228 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3232 unsigned long now = jiffies;
3235 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3238 spin_lock(&clp->cl_lock);
3239 if (time_before(clp->cl_last_renewal,now))
3240 clp->cl_last_renewal = now;
3241 spin_unlock(&clp->cl_lock);
3245 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3247 return (server->caps & NFS_CAP_ACLS)
3248 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3249 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3252 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3253 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3256 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3258 static void buf_to_pages(const void *buf, size_t buflen,
3259 struct page **pages, unsigned int *pgbase)
3261 const void *p = buf;
3263 *pgbase = offset_in_page(buf);
3265 while (p < buf + buflen) {
3266 *(pages++) = virt_to_page(p);
3267 p += PAGE_CACHE_SIZE;
3271 struct nfs4_cached_acl {
3277 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3279 struct nfs_inode *nfsi = NFS_I(inode);
3281 spin_lock(&inode->i_lock);
3282 kfree(nfsi->nfs4_acl);
3283 nfsi->nfs4_acl = acl;
3284 spin_unlock(&inode->i_lock);
3287 static void nfs4_zap_acl_attr(struct inode *inode)
3289 nfs4_set_cached_acl(inode, NULL);
3292 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3294 struct nfs_inode *nfsi = NFS_I(inode);
3295 struct nfs4_cached_acl *acl;
3298 spin_lock(&inode->i_lock);
3299 acl = nfsi->nfs4_acl;
3302 if (buf == NULL) /* user is just asking for length */
3304 if (acl->cached == 0)
3306 ret = -ERANGE; /* see getxattr(2) man page */
3307 if (acl->len > buflen)
3309 memcpy(buf, acl->data, acl->len);
3313 spin_unlock(&inode->i_lock);
3317 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
3319 struct nfs4_cached_acl *acl;
3321 if (buf && acl_len <= PAGE_SIZE) {
3322 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3326 memcpy(acl->data, buf, acl_len);
3328 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3335 nfs4_set_cached_acl(inode, acl);
3338 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3340 struct page *pages[NFS4ACL_MAXPAGES];
3341 struct nfs_getaclargs args = {
3342 .fh = NFS_FH(inode),
3346 struct nfs_getaclres res = {
3350 struct rpc_message msg = {
3351 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3355 struct page *localpage = NULL;
3358 if (buflen < PAGE_SIZE) {
3359 /* As long as we're doing a round trip to the server anyway,
3360 * let's be prepared for a page of acl data. */
3361 localpage = alloc_page(GFP_KERNEL);
3362 resp_buf = page_address(localpage);
3363 if (localpage == NULL)
3365 args.acl_pages[0] = localpage;
3366 args.acl_pgbase = 0;
3367 args.acl_len = PAGE_SIZE;
3370 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
3372 ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
3375 if (res.acl_len > args.acl_len)
3376 nfs4_write_cached_acl(inode, NULL, res.acl_len);
3378 nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
3381 if (res.acl_len > buflen)
3384 memcpy(buf, resp_buf, res.acl_len);
3389 __free_page(localpage);
3393 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3395 struct nfs4_exception exception = { };
3398 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3401 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3402 } while (exception.retry);
3406 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3408 struct nfs_server *server = NFS_SERVER(inode);
3411 if (!nfs4_server_supports_acls(server))
3413 ret = nfs_revalidate_inode(server, inode);
3416 ret = nfs4_read_cached_acl(inode, buf, buflen);
3419 return nfs4_get_acl_uncached(inode, buf, buflen);
3422 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3424 struct nfs_server *server = NFS_SERVER(inode);
3425 struct page *pages[NFS4ACL_MAXPAGES];
3426 struct nfs_setaclargs arg = {
3427 .fh = NFS_FH(inode),
3431 struct nfs_setaclres res;
3432 struct rpc_message msg = {
3433 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3439 if (!nfs4_server_supports_acls(server))
3441 nfs_inode_return_delegation(inode);
3442 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3443 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3444 nfs_access_zap_cache(inode);
3445 nfs_zap_acl_cache(inode);
3449 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3451 struct nfs4_exception exception = { };
3454 err = nfs4_handle_exception(NFS_SERVER(inode),
3455 __nfs4_proc_set_acl(inode, buf, buflen),
3457 } while (exception.retry);
3462 _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state)
3464 if (!clp || task->tk_status >= 0)
3466 switch(task->tk_status) {
3467 case -NFS4ERR_ADMIN_REVOKED:
3468 case -NFS4ERR_BAD_STATEID:
3469 case -NFS4ERR_OPENMODE:
3472 nfs4_state_mark_reclaim_nograce(clp, state);
3473 goto do_state_recovery;
3474 case -NFS4ERR_STALE_STATEID:
3477 nfs4_state_mark_reclaim_reboot(clp, state);
3478 case -NFS4ERR_STALE_CLIENTID:
3479 case -NFS4ERR_EXPIRED:
3480 goto do_state_recovery;
3481 #if defined(CONFIG_NFS_V4_1)
3482 case -NFS4ERR_BADSESSION:
3483 case -NFS4ERR_BADSLOT:
3484 case -NFS4ERR_BAD_HIGH_SLOT:
3485 case -NFS4ERR_DEADSESSION:
3486 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3487 case -NFS4ERR_SEQ_FALSE_RETRY:
3488 case -NFS4ERR_SEQ_MISORDERED:
3489 dprintk("%s ERROR %d, Reset session\n", __func__,
3491 nfs4_schedule_state_recovery(clp);
3492 task->tk_status = 0;
3494 #endif /* CONFIG_NFS_V4_1 */
3495 case -NFS4ERR_DELAY:
3497 nfs_inc_server_stats(server, NFSIOS_DELAY);
3498 case -NFS4ERR_GRACE:
3500 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3501 task->tk_status = 0;
3503 case -NFS4ERR_OLD_STATEID:
3504 task->tk_status = 0;
3507 task->tk_status = nfs4_map_errors(task->tk_status);
3510 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3511 nfs4_schedule_state_recovery(clp);
3512 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3513 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3514 task->tk_status = 0;
3519 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3521 return _nfs4_async_handle_error(task, server, server->nfs_client, state);
3524 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3525 unsigned short port, struct rpc_cred *cred,
3526 struct nfs4_setclientid_res *res)
3528 nfs4_verifier sc_verifier;
3529 struct nfs4_setclientid setclientid = {
3530 .sc_verifier = &sc_verifier,
3533 struct rpc_message msg = {
3534 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3535 .rpc_argp = &setclientid,
3543 p = (__be32*)sc_verifier.data;
3544 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3545 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3548 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3549 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3551 rpc_peeraddr2str(clp->cl_rpcclient,
3553 rpc_peeraddr2str(clp->cl_rpcclient,
3555 clp->cl_rpcclient->cl_auth->au_ops->au_name,
3556 clp->cl_id_uniquifier);
3557 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
3558 sizeof(setclientid.sc_netid),
3559 rpc_peeraddr2str(clp->cl_rpcclient,
3560 RPC_DISPLAY_NETID));
3561 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3562 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3563 clp->cl_ipaddr, port >> 8, port & 255);
3565 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3566 if (status != -NFS4ERR_CLID_INUSE)
3571 ssleep(clp->cl_lease_time + 1);
3573 if (++clp->cl_id_uniquifier == 0)
3579 static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3580 struct nfs4_setclientid_res *arg,
3581 struct rpc_cred *cred)
3583 struct nfs_fsinfo fsinfo;
3584 struct rpc_message msg = {
3585 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3587 .rpc_resp = &fsinfo,
3594 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3596 spin_lock(&clp->cl_lock);
3597 clp->cl_lease_time = fsinfo.lease_time * HZ;
3598 clp->cl_last_renewal = now;
3599 spin_unlock(&clp->cl_lock);
3604 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3605 struct nfs4_setclientid_res *arg,
3606 struct rpc_cred *cred)
3611 err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
3615 case -NFS4ERR_RESOURCE:
3616 /* The IBM lawyers misread another document! */
3617 case -NFS4ERR_DELAY:
3619 err = nfs4_delay(clp->cl_rpcclient, &timeout);
3625 struct nfs4_delegreturndata {
3626 struct nfs4_delegreturnargs args;
3627 struct nfs4_delegreturnres res;
3629 nfs4_stateid stateid;
3630 unsigned long timestamp;
3631 struct nfs_fattr fattr;
3635 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3637 struct nfs4_delegreturndata *data = calldata;
3639 nfs4_sequence_done(data->res.server, &data->res.seq_res,
3642 switch (task->tk_status) {
3643 case -NFS4ERR_STALE_STATEID:
3644 case -NFS4ERR_EXPIRED:
3646 renew_lease(data->res.server, data->timestamp);
3649 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3651 nfs_restart_rpc(task, data->res.server->nfs_client);
3655 data->rpc_status = task->tk_status;
3658 static void nfs4_delegreturn_release(void *calldata)
3663 #if defined(CONFIG_NFS_V4_1)
3664 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3666 struct nfs4_delegreturndata *d_data;
3668 d_data = (struct nfs4_delegreturndata *)data;
3670 if (nfs4_setup_sequence(d_data->res.server->nfs_client,
3671 &d_data->args.seq_args,
3672 &d_data->res.seq_res, 1, task))
3674 rpc_call_start(task);
3676 #endif /* CONFIG_NFS_V4_1 */
3678 static const struct rpc_call_ops nfs4_delegreturn_ops = {
3679 #if defined(CONFIG_NFS_V4_1)
3680 .rpc_call_prepare = nfs4_delegreturn_prepare,
3681 #endif /* CONFIG_NFS_V4_1 */
3682 .rpc_call_done = nfs4_delegreturn_done,
3683 .rpc_release = nfs4_delegreturn_release,
3686 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3688 struct nfs4_delegreturndata *data;
3689 struct nfs_server *server = NFS_SERVER(inode);
3690 struct rpc_task *task;
3691 struct rpc_message msg = {
3692 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
3695 struct rpc_task_setup task_setup_data = {
3696 .rpc_client = server->client,
3697 .rpc_message = &msg,
3698 .callback_ops = &nfs4_delegreturn_ops,
3699 .flags = RPC_TASK_ASYNC,
3703 data = kzalloc(sizeof(*data), GFP_NOFS);
3706 data->args.fhandle = &data->fh;
3707 data->args.stateid = &data->stateid;
3708 data->args.bitmask = server->attr_bitmask;
3709 nfs_copy_fh(&data->fh, NFS_FH(inode));
3710 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3711 data->res.fattr = &data->fattr;
3712 data->res.server = server;
3713 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3714 nfs_fattr_init(data->res.fattr);
3715 data->timestamp = jiffies;
3716 data->rpc_status = 0;
3718 task_setup_data.callback_data = data;
3719 msg.rpc_argp = &data->args,
3720 msg.rpc_resp = &data->res,
3721 task = rpc_run_task(&task_setup_data);
3723 return PTR_ERR(task);
3726 status = nfs4_wait_for_completion_rpc_task(task);
3729 status = data->rpc_status;
3732 nfs_refresh_inode(inode, &data->fattr);
3738 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3740 struct nfs_server *server = NFS_SERVER(inode);
3741 struct nfs4_exception exception = { };
3744 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
3746 case -NFS4ERR_STALE_STATEID:
3747 case -NFS4ERR_EXPIRED:
3751 err = nfs4_handle_exception(server, err, &exception);
3752 } while (exception.retry);
3756 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3757 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3760 * sleep, with exponential backoff, and retry the LOCK operation.
3762 static unsigned long
3763 nfs4_set_lock_task_retry(unsigned long timeout)
3765 schedule_timeout_killable(timeout);
3767 if (timeout > NFS4_LOCK_MAXTIMEOUT)
3768 return NFS4_LOCK_MAXTIMEOUT;
3772 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3774 struct inode *inode = state->inode;
3775 struct nfs_server *server = NFS_SERVER(inode);
3776 struct nfs_client *clp = server->nfs_client;
3777 struct nfs_lockt_args arg = {
3778 .fh = NFS_FH(inode),
3781 struct nfs_lockt_res res = {
3784 struct rpc_message msg = {
3785 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
3788 .rpc_cred = state->owner->so_cred,
3790 struct nfs4_lock_state *lsp;
3793 arg.lock_owner.clientid = clp->cl_clientid;
3794 status = nfs4_set_lock_state(state, request);
3797 lsp = request->fl_u.nfs4_fl.owner;
3798 arg.lock_owner.id = lsp->ls_id.id;
3799 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
3802 request->fl_type = F_UNLCK;
3804 case -NFS4ERR_DENIED:
3807 request->fl_ops->fl_release_private(request);
3812 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3814 struct nfs4_exception exception = { };
3818 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3819 _nfs4_proc_getlk(state, cmd, request),
3821 } while (exception.retry);
3825 static int do_vfs_lock(struct file *file, struct file_lock *fl)
3828 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3830 res = posix_lock_file_wait(file, fl);
3833 res = flock_lock_file_wait(file, fl);
3841 struct nfs4_unlockdata {
3842 struct nfs_locku_args arg;
3843 struct nfs_locku_res res;
3844 struct nfs4_lock_state *lsp;
3845 struct nfs_open_context *ctx;
3846 struct file_lock fl;
3847 const struct nfs_server *server;
3848 unsigned long timestamp;
3851 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3852 struct nfs_open_context *ctx,
3853 struct nfs4_lock_state *lsp,
3854 struct nfs_seqid *seqid)
3856 struct nfs4_unlockdata *p;
3857 struct inode *inode = lsp->ls_state->inode;
3859 p = kzalloc(sizeof(*p), GFP_NOFS);
3862 p->arg.fh = NFS_FH(inode);
3864 p->arg.seqid = seqid;
3865 p->res.seqid = seqid;
3866 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3867 p->arg.stateid = &lsp->ls_stateid;
3869 atomic_inc(&lsp->ls_count);
3870 /* Ensure we don't close file until we're done freeing locks! */
3871 p->ctx = get_nfs_open_context(ctx);
3872 memcpy(&p->fl, fl, sizeof(p->fl));
3873 p->server = NFS_SERVER(inode);
3877 static void nfs4_locku_release_calldata(void *data)
3879 struct nfs4_unlockdata *calldata = data;
3880 nfs_free_seqid(calldata->arg.seqid);
3881 nfs4_put_lock_state(calldata->lsp);
3882 put_nfs_open_context(calldata->ctx);
3886 static void nfs4_locku_done(struct rpc_task *task, void *data)
3888 struct nfs4_unlockdata *calldata = data;
3890 nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
3892 if (RPC_ASSASSINATED(task))
3894 switch (task->tk_status) {
3896 memcpy(calldata->lsp->ls_stateid.data,
3897 calldata->res.stateid.data,
3898 sizeof(calldata->lsp->ls_stateid.data));
3899 renew_lease(calldata->server, calldata->timestamp);
3901 case -NFS4ERR_BAD_STATEID:
3902 case -NFS4ERR_OLD_STATEID:
3903 case -NFS4ERR_STALE_STATEID:
3904 case -NFS4ERR_EXPIRED:
3907 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
3908 nfs_restart_rpc(task,
3909 calldata->server->nfs_client);
3913 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
3915 struct nfs4_unlockdata *calldata = data;
3917 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
3919 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
3920 /* Note: exit _without_ running nfs4_locku_done */
3921 task->tk_action = NULL;
3924 calldata->timestamp = jiffies;
3925 if (nfs4_setup_sequence(calldata->server->nfs_client,
3926 &calldata->arg.seq_args,
3927 &calldata->res.seq_res, 1, task))
3929 rpc_call_start(task);
3932 static const struct rpc_call_ops nfs4_locku_ops = {
3933 .rpc_call_prepare = nfs4_locku_prepare,
3934 .rpc_call_done = nfs4_locku_done,
3935 .rpc_release = nfs4_locku_release_calldata,
3938 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3939 struct nfs_open_context *ctx,
3940 struct nfs4_lock_state *lsp,
3941 struct nfs_seqid *seqid)
3943 struct nfs4_unlockdata *data;
3944 struct rpc_message msg = {
3945 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
3946 .rpc_cred = ctx->cred,
3948 struct rpc_task_setup task_setup_data = {
3949 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
3950 .rpc_message = &msg,
3951 .callback_ops = &nfs4_locku_ops,
3952 .workqueue = nfsiod_workqueue,
3953 .flags = RPC_TASK_ASYNC,
3956 /* Ensure this is an unlock - when canceling a lock, the
3957 * canceled lock is passed in, and it won't be an unlock.
3959 fl->fl_type = F_UNLCK;
3961 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
3963 nfs_free_seqid(seqid);
3964 return ERR_PTR(-ENOMEM);
3967 msg.rpc_argp = &data->arg,
3968 msg.rpc_resp = &data->res,
3969 task_setup_data.callback_data = data;
3970 return rpc_run_task(&task_setup_data);
3973 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
3975 struct nfs_inode *nfsi = NFS_I(state->inode);
3976 struct nfs_seqid *seqid;
3977 struct nfs4_lock_state *lsp;
3978 struct rpc_task *task;
3980 unsigned char fl_flags = request->fl_flags;
3982 status = nfs4_set_lock_state(state, request);
3983 /* Unlock _before_ we do the RPC call */
3984 request->fl_flags |= FL_EXISTS;
3985 down_read(&nfsi->rwsem);
3986 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
3987 up_read(&nfsi->rwsem);
3990 up_read(&nfsi->rwsem);
3993 /* Is this a delegated lock? */
3994 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
3996 lsp = request->fl_u.nfs4_fl.owner;
3997 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4001 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4002 status = PTR_ERR(task);
4005 status = nfs4_wait_for_completion_rpc_task(task);
4008 request->fl_flags = fl_flags;
4012 struct nfs4_lockdata {
4013 struct nfs_lock_args arg;
4014 struct nfs_lock_res res;
4015 struct nfs4_lock_state *lsp;
4016 struct nfs_open_context *ctx;
4017 struct file_lock fl;
4018 unsigned long timestamp;
4021 struct nfs_server *server;
4024 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4025 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4028 struct nfs4_lockdata *p;
4029 struct inode *inode = lsp->ls_state->inode;
4030 struct nfs_server *server = NFS_SERVER(inode);
4032 p = kzalloc(sizeof(*p), gfp_mask);
4036 p->arg.fh = NFS_FH(inode);
4038 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4039 if (p->arg.open_seqid == NULL)
4041 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4042 if (p->arg.lock_seqid == NULL)
4043 goto out_free_seqid;
4044 p->arg.lock_stateid = &lsp->ls_stateid;
4045 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4046 p->arg.lock_owner.id = lsp->ls_id.id;
4047 p->res.lock_seqid = p->arg.lock_seqid;
4048 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4051 atomic_inc(&lsp->ls_count);
4052 p->ctx = get_nfs_open_context(ctx);
4053 memcpy(&p->fl, fl, sizeof(p->fl));
4056 nfs_free_seqid(p->arg.open_seqid);
4062 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4064 struct nfs4_lockdata *data = calldata;
4065 struct nfs4_state *state = data->lsp->ls_state;
4067 dprintk("%s: begin!\n", __func__);
4068 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4070 /* Do we need to do an open_to_lock_owner? */
4071 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4072 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4074 data->arg.open_stateid = &state->stateid;
4075 data->arg.new_lock_owner = 1;
4076 data->res.open_seqid = data->arg.open_seqid;
4078 data->arg.new_lock_owner = 0;
4079 data->timestamp = jiffies;
4080 if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args,
4081 &data->res.seq_res, 1, task))
4083 rpc_call_start(task);
4084 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4087 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4089 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4090 nfs4_lock_prepare(task, calldata);
4093 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4095 struct nfs4_lockdata *data = calldata;
4097 dprintk("%s: begin!\n", __func__);
4099 nfs4_sequence_done(data->server, &data->res.seq_res,
4102 data->rpc_status = task->tk_status;
4103 if (RPC_ASSASSINATED(task))
4105 if (data->arg.new_lock_owner != 0) {
4106 if (data->rpc_status == 0)
4107 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4111 if (data->rpc_status == 0) {
4112 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
4113 sizeof(data->lsp->ls_stateid.data));
4114 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4115 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
4118 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4121 static void nfs4_lock_release(void *calldata)
4123 struct nfs4_lockdata *data = calldata;
4125 dprintk("%s: begin!\n", __func__);
4126 nfs_free_seqid(data->arg.open_seqid);
4127 if (data->cancelled != 0) {
4128 struct rpc_task *task;
4129 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4130 data->arg.lock_seqid);
4133 dprintk("%s: cancelling lock!\n", __func__);
4135 nfs_free_seqid(data->arg.lock_seqid);
4136 nfs4_put_lock_state(data->lsp);
4137 put_nfs_open_context(data->ctx);
4139 dprintk("%s: done!\n", __func__);
4142 static const struct rpc_call_ops nfs4_lock_ops = {
4143 .rpc_call_prepare = nfs4_lock_prepare,
4144 .rpc_call_done = nfs4_lock_done,
4145 .rpc_release = nfs4_lock_release,
4148 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4149 .rpc_call_prepare = nfs4_recover_lock_prepare,
4150 .rpc_call_done = nfs4_lock_done,
4151 .rpc_release = nfs4_lock_release,
4154 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4156 struct nfs_client *clp = server->nfs_client;
4157 struct nfs4_state *state = lsp->ls_state;
4160 case -NFS4ERR_ADMIN_REVOKED:
4161 case -NFS4ERR_BAD_STATEID:
4162 case -NFS4ERR_EXPIRED:
4163 if (new_lock_owner != 0 ||
4164 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4165 nfs4_state_mark_reclaim_nograce(clp, state);
4166 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4168 case -NFS4ERR_STALE_STATEID:
4169 if (new_lock_owner != 0 ||
4170 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4171 nfs4_state_mark_reclaim_reboot(clp, state);
4172 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4176 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4178 struct nfs4_lockdata *data;
4179 struct rpc_task *task;
4180 struct rpc_message msg = {
4181 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4182 .rpc_cred = state->owner->so_cred,
4184 struct rpc_task_setup task_setup_data = {
4185 .rpc_client = NFS_CLIENT(state->inode),
4186 .rpc_message = &msg,
4187 .callback_ops = &nfs4_lock_ops,
4188 .workqueue = nfsiod_workqueue,
4189 .flags = RPC_TASK_ASYNC,
4193 dprintk("%s: begin!\n", __func__);
4194 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4195 fl->fl_u.nfs4_fl.owner,
4196 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4200 data->arg.block = 1;
4201 if (recovery_type > NFS_LOCK_NEW) {
4202 if (recovery_type == NFS_LOCK_RECLAIM)
4203 data->arg.reclaim = NFS_LOCK_RECLAIM;
4204 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4206 msg.rpc_argp = &data->arg,
4207 msg.rpc_resp = &data->res,
4208 task_setup_data.callback_data = data;
4209 task = rpc_run_task(&task_setup_data);
4211 return PTR_ERR(task);
4212 ret = nfs4_wait_for_completion_rpc_task(task);
4214 ret = data->rpc_status;
4216 nfs4_handle_setlk_error(data->server, data->lsp,
4217 data->arg.new_lock_owner, ret);
4219 data->cancelled = 1;
4221 dprintk("%s: done, ret = %d!\n", __func__, ret);
4225 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4227 struct nfs_server *server = NFS_SERVER(state->inode);
4228 struct nfs4_exception exception = { };
4232 /* Cache the lock if possible... */
4233 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4235 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4236 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
4238 nfs4_handle_exception(server, err, &exception);
4239 } while (exception.retry);
4243 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4245 struct nfs_server *server = NFS_SERVER(state->inode);
4246 struct nfs4_exception exception = { };
4249 err = nfs4_set_lock_state(state, request);
4253 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4255 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4259 case -NFS4ERR_GRACE:
4260 case -NFS4ERR_DELAY:
4262 nfs4_handle_exception(server, err, &exception);
4265 } while (exception.retry);
4270 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4272 struct nfs_inode *nfsi = NFS_I(state->inode);
4273 unsigned char fl_flags = request->fl_flags;
4274 int status = -ENOLCK;
4276 if ((fl_flags & FL_POSIX) &&
4277 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4279 /* Is this a delegated open? */
4280 status = nfs4_set_lock_state(state, request);
4283 request->fl_flags |= FL_ACCESS;
4284 status = do_vfs_lock(request->fl_file, request);
4287 down_read(&nfsi->rwsem);
4288 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4289 /* Yes: cache locks! */
4290 /* ...but avoid races with delegation recall... */
4291 request->fl_flags = fl_flags & ~FL_SLEEP;
4292 status = do_vfs_lock(request->fl_file, request);
4295 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4298 /* Note: we always want to sleep here! */
4299 request->fl_flags = fl_flags | FL_SLEEP;
4300 if (do_vfs_lock(request->fl_file, request) < 0)
4301 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
4303 up_read(&nfsi->rwsem);
4305 request->fl_flags = fl_flags;
4309 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4311 struct nfs4_exception exception = { };
4315 err = _nfs4_proc_setlk(state, cmd, request);
4316 if (err == -NFS4ERR_DENIED)
4318 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4320 } while (exception.retry);
4325 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4327 struct nfs_open_context *ctx;
4328 struct nfs4_state *state;
4329 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4332 /* verify open state */
4333 ctx = nfs_file_open_context(filp);
4336 if (request->fl_start < 0 || request->fl_end < 0)
4339 if (IS_GETLK(cmd)) {
4341 return nfs4_proc_getlk(state, F_GETLK, request);
4345 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4348 if (request->fl_type == F_UNLCK) {
4350 return nfs4_proc_unlck(state, cmd, request);
4357 status = nfs4_proc_setlk(state, cmd, request);
4358 if ((status != -EAGAIN) || IS_SETLK(cmd))
4360 timeout = nfs4_set_lock_task_retry(timeout);
4361 status = -ERESTARTSYS;
4364 } while(status < 0);
4368 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4370 struct nfs_server *server = NFS_SERVER(state->inode);
4371 struct nfs4_exception exception = { };
4374 err = nfs4_set_lock_state(state, fl);
4378 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4381 printk(KERN_ERR "%s: unhandled error %d.\n",
4386 case -NFS4ERR_EXPIRED:
4387 case -NFS4ERR_STALE_CLIENTID:
4388 case -NFS4ERR_STALE_STATEID:
4389 case -NFS4ERR_BADSESSION:
4390 case -NFS4ERR_BADSLOT:
4391 case -NFS4ERR_BAD_HIGH_SLOT:
4392 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4393 case -NFS4ERR_DEADSESSION:
4394 nfs4_schedule_state_recovery(server->nfs_client);
4398 * The show must go on: exit, but mark the
4399 * stateid as needing recovery.
4401 case -NFS4ERR_ADMIN_REVOKED:
4402 case -NFS4ERR_BAD_STATEID:
4403 case -NFS4ERR_OPENMODE:
4404 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
4408 case -NFS4ERR_DENIED:
4409 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4412 case -NFS4ERR_DELAY:
4416 err = nfs4_handle_exception(server, err, &exception);
4417 } while (exception.retry);
4422 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4424 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
4425 size_t buflen, int flags)
4427 struct inode *inode = dentry->d_inode;
4429 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4432 return nfs4_proc_set_acl(inode, buf, buflen);
4435 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4436 * and that's what we'll do for e.g. user attributes that haven't been set.
4437 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4438 * attributes in kernel-managed attribute namespaces. */
4439 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
4442 struct inode *inode = dentry->d_inode;
4444 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4447 return nfs4_proc_get_acl(inode, buf, buflen);
4450 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
4452 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
4454 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4456 if (buf && buflen < len)
4459 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
4463 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4465 if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
4466 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4467 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
4470 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4471 NFS_ATTR_FATTR_NLINK;
4472 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4476 int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4477 struct nfs4_fs_locations *fs_locations, struct page *page)
4479 struct nfs_server *server = NFS_SERVER(dir);
4481 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
4482 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
4484 struct nfs4_fs_locations_arg args = {
4485 .dir_fh = NFS_FH(dir),
4490 struct nfs4_fs_locations_res res = {
4491 .fs_locations = fs_locations,
4493 struct rpc_message msg = {
4494 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
4500 dprintk("%s: start\n", __func__);
4501 nfs_fattr_init(&fs_locations->fattr);
4502 fs_locations->server = server;
4503 fs_locations->nlocations = 0;
4504 status = nfs4_call_sync(server, &msg, &args, &res, 0);
4505 nfs_fixup_referral_attributes(&fs_locations->fattr);
4506 dprintk("%s: returned status = %d\n", __func__, status);
4510 #ifdef CONFIG_NFS_V4_1
4512 * nfs4_proc_exchange_id()
4514 * Since the clientid has expired, all compounds using sessions
4515 * associated with the stale clientid will be returning
4516 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4517 * be in some phase of session reset.
4519 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4521 nfs4_verifier verifier;
4522 struct nfs41_exchange_id_args args = {
4524 .flags = clp->cl_exchange_flags,
4526 struct nfs41_exchange_id_res res = {
4530 struct rpc_message msg = {
4531 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
4538 dprintk("--> %s\n", __func__);
4539 BUG_ON(clp == NULL);
4541 /* Remove server-only flags */
4542 args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
4544 p = (u32 *)verifier.data;
4545 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4546 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4547 args.verifier = &verifier;
4550 args.id_len = scnprintf(args.id, sizeof(args.id),
4553 rpc_peeraddr2str(clp->cl_rpcclient,
4555 clp->cl_id_uniquifier);
4557 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4559 if (status != -NFS4ERR_CLID_INUSE)
4565 if (++clp->cl_id_uniquifier == 0)
4569 dprintk("<-- %s status= %d\n", __func__, status);
4573 struct nfs4_get_lease_time_data {
4574 struct nfs4_get_lease_time_args *args;
4575 struct nfs4_get_lease_time_res *res;
4576 struct nfs_client *clp;
4579 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4583 struct nfs4_get_lease_time_data *data =
4584 (struct nfs4_get_lease_time_data *)calldata;
4586 dprintk("--> %s\n", __func__);
4587 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4588 /* just setup sequence, do not trigger session recovery
4589 since we're invoked within one */
4590 ret = nfs41_setup_sequence(data->clp->cl_session,
4591 &data->args->la_seq_args,
4592 &data->res->lr_seq_res, 0, task);
4594 BUG_ON(ret == -EAGAIN);
4595 rpc_call_start(task);
4596 dprintk("<-- %s\n", __func__);
4600 * Called from nfs4_state_manager thread for session setup, so don't recover
4601 * from sequence operation or clientid errors.
4603 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4605 struct nfs4_get_lease_time_data *data =
4606 (struct nfs4_get_lease_time_data *)calldata;
4608 dprintk("--> %s\n", __func__);
4609 nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status);
4610 switch (task->tk_status) {
4611 case -NFS4ERR_DELAY:
4612 case -NFS4ERR_GRACE:
4614 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4615 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4616 task->tk_status = 0;
4617 nfs_restart_rpc(task, data->clp);
4620 dprintk("<-- %s\n", __func__);
4623 struct rpc_call_ops nfs4_get_lease_time_ops = {
4624 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4625 .rpc_call_done = nfs4_get_lease_time_done,
4628 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4630 struct rpc_task *task;
4631 struct nfs4_get_lease_time_args args;
4632 struct nfs4_get_lease_time_res res = {
4633 .lr_fsinfo = fsinfo,
4635 struct nfs4_get_lease_time_data data = {
4640 struct rpc_message msg = {
4641 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
4645 struct rpc_task_setup task_setup = {
4646 .rpc_client = clp->cl_rpcclient,
4647 .rpc_message = &msg,
4648 .callback_ops = &nfs4_get_lease_time_ops,
4649 .callback_data = &data
4653 res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4654 dprintk("--> %s\n", __func__);
4655 task = rpc_run_task(&task_setup);
4658 status = PTR_ERR(task);
4660 status = task->tk_status;
4663 dprintk("<-- %s return %d\n", __func__, status);
4669 * Reset a slot table
4671 static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4674 struct nfs4_slot *new = NULL;
4678 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4679 max_reqs, tbl->max_slots);
4681 /* Does the newly negotiated max_reqs match the existing slot table? */
4682 if (max_reqs != tbl->max_slots) {
4684 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4691 spin_lock(&tbl->slot_tbl_lock);
4694 tbl->max_slots = max_reqs;
4696 for (i = 0; i < tbl->max_slots; ++i)
4697 tbl->slots[i].seq_nr = ivalue;
4698 spin_unlock(&tbl->slot_tbl_lock);
4699 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4700 tbl, tbl->slots, tbl->max_slots);
4702 dprintk("<-- %s: return %d\n", __func__, ret);
4707 * Reset the forechannel and backchannel slot tables
4709 static int nfs4_reset_slot_tables(struct nfs4_session *session)
4713 status = nfs4_reset_slot_table(&session->fc_slot_table,
4714 session->fc_attrs.max_reqs, 1);
4718 status = nfs4_reset_slot_table(&session->bc_slot_table,
4719 session->bc_attrs.max_reqs, 0);
4723 /* Destroy the slot table */
4724 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4726 if (session->fc_slot_table.slots != NULL) {
4727 kfree(session->fc_slot_table.slots);
4728 session->fc_slot_table.slots = NULL;
4730 if (session->bc_slot_table.slots != NULL) {
4731 kfree(session->bc_slot_table.slots);
4732 session->bc_slot_table.slots = NULL;
4738 * Initialize slot table
4740 static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4741 int max_slots, int ivalue)
4743 struct nfs4_slot *slot;
4746 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
4748 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4750 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
4755 spin_lock(&tbl->slot_tbl_lock);
4756 tbl->max_slots = max_slots;
4758 tbl->highest_used_slotid = -1; /* no slot is currently used */
4759 spin_unlock(&tbl->slot_tbl_lock);
4760 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4761 tbl, tbl->slots, tbl->max_slots);
4763 dprintk("<-- %s: return %d\n", __func__, ret);
4768 * Initialize the forechannel and backchannel tables
4770 static int nfs4_init_slot_tables(struct nfs4_session *session)
4772 struct nfs4_slot_table *tbl;
4775 tbl = &session->fc_slot_table;
4776 if (tbl->slots == NULL) {
4777 status = nfs4_init_slot_table(tbl,
4778 session->fc_attrs.max_reqs, 1);
4783 tbl = &session->bc_slot_table;
4784 if (tbl->slots == NULL) {
4785 status = nfs4_init_slot_table(tbl,
4786 session->bc_attrs.max_reqs, 0);
4788 nfs4_destroy_slot_tables(session);
4794 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4796 struct nfs4_session *session;
4797 struct nfs4_slot_table *tbl;
4799 session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
4804 * The create session reply races with the server back
4805 * channel probe. Mark the client NFS_CS_SESSION_INITING
4806 * so that the client back channel can find the
4809 clp->cl_cons_state = NFS_CS_SESSION_INITING;
4810 init_completion(&session->complete);
4812 tbl = &session->fc_slot_table;
4813 tbl->highest_used_slotid = -1;
4814 spin_lock_init(&tbl->slot_tbl_lock);
4815 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
4817 tbl = &session->bc_slot_table;
4818 tbl->highest_used_slotid = -1;
4819 spin_lock_init(&tbl->slot_tbl_lock);
4820 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
4826 void nfs4_destroy_session(struct nfs4_session *session)
4828 nfs4_proc_destroy_session(session);
4829 dprintk("%s Destroy backchannel for xprt %p\n",
4830 __func__, session->clp->cl_rpcclient->cl_xprt);
4831 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
4832 NFS41_BC_MIN_CALLBACKS);
4833 nfs4_destroy_slot_tables(session);
4838 * Initialize the values to be used by the client in CREATE_SESSION
4839 * If nfs4_init_session set the fore channel request and response sizes,
4842 * Set the back channel max_resp_sz_cached to zero to force the client to
4843 * always set csa_cachethis to FALSE because the current implementation
4844 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4846 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4848 struct nfs4_session *session = args->client->cl_session;
4849 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
4850 mxresp_sz = session->fc_attrs.max_resp_sz;
4853 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
4855 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
4856 /* Fore channel attributes */
4857 args->fc_attrs.headerpadsz = 0;
4858 args->fc_attrs.max_rqst_sz = mxrqst_sz;
4859 args->fc_attrs.max_resp_sz = mxresp_sz;
4860 args->fc_attrs.max_ops = NFS4_MAX_OPS;
4861 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
4863 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4864 "max_ops=%u max_reqs=%u\n",
4866 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
4867 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
4869 /* Back channel attributes */
4870 args->bc_attrs.headerpadsz = 0;
4871 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
4872 args->bc_attrs.max_resp_sz = PAGE_SIZE;
4873 args->bc_attrs.max_resp_sz_cached = 0;
4874 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
4875 args->bc_attrs.max_reqs = 1;
4877 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4878 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4880 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
4881 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
4882 args->bc_attrs.max_reqs);
4885 static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd)
4889 printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. "
4890 "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd);
4894 #define _verify_fore_channel_attr(_name_) \
4895 _verify_channel_attr("fore", #_name_, \
4896 args->fc_attrs._name_, \
4897 session->fc_attrs._name_)
4899 #define _verify_back_channel_attr(_name_) \
4900 _verify_channel_attr("back", #_name_, \
4901 args->bc_attrs._name_, \
4902 session->bc_attrs._name_)
4905 * The server is not allowed to increase the fore channel header pad size,
4906 * maximum response size, or maximum number of operations.
4908 * The back channel attributes are only negotiatied down: We send what the
4909 * (back channel) server insists upon.
4911 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
4912 struct nfs4_session *session)
4916 ret |= _verify_fore_channel_attr(headerpadsz);
4917 ret |= _verify_fore_channel_attr(max_resp_sz);
4918 ret |= _verify_fore_channel_attr(max_ops);
4920 ret |= _verify_back_channel_attr(headerpadsz);
4921 ret |= _verify_back_channel_attr(max_rqst_sz);
4922 ret |= _verify_back_channel_attr(max_resp_sz);
4923 ret |= _verify_back_channel_attr(max_resp_sz_cached);
4924 ret |= _verify_back_channel_attr(max_ops);
4925 ret |= _verify_back_channel_attr(max_reqs);
4930 static int _nfs4_proc_create_session(struct nfs_client *clp)
4932 struct nfs4_session *session = clp->cl_session;
4933 struct nfs41_create_session_args args = {
4935 .cb_program = NFS4_CALLBACK,
4937 struct nfs41_create_session_res res = {
4940 struct rpc_message msg = {
4941 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
4947 nfs4_init_channel_attrs(&args);
4948 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
4950 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
4953 /* Verify the session's negotiated channel_attrs values */
4954 status = nfs4_verify_channel_attrs(&args, session);
4956 /* Increment the clientid slot sequence id */
4964 * Issues a CREATE_SESSION operation to the server.
4965 * It is the responsibility of the caller to verify the session is
4966 * expired before calling this routine.
4968 int nfs4_proc_create_session(struct nfs_client *clp)
4972 struct nfs4_session *session = clp->cl_session;
4974 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
4976 status = _nfs4_proc_create_session(clp);
4980 /* Init and reset the fore channel */
4981 status = nfs4_init_slot_tables(session);
4982 dprintk("slot table initialization returned %d\n", status);
4985 status = nfs4_reset_slot_tables(session);
4986 dprintk("slot table reset returned %d\n", status);
4990 ptr = (unsigned *)&session->sess_id.data[0];
4991 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
4992 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
4994 dprintk("<-- %s\n", __func__);
4999 * Issue the over-the-wire RPC DESTROY_SESSION.
5000 * The caller must serialize access to this routine.
5002 int nfs4_proc_destroy_session(struct nfs4_session *session)
5005 struct rpc_message msg;
5007 dprintk("--> nfs4_proc_destroy_session\n");
5009 /* session is still being setup */
5010 if (session->clp->cl_cons_state != NFS_CS_READY)
5013 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
5014 msg.rpc_argp = session;
5015 msg.rpc_resp = NULL;
5016 msg.rpc_cred = NULL;
5017 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
5021 "Got error %d from the server on DESTROY_SESSION. "
5022 "Session has been destroyed regardless...\n", status);
5024 dprintk("<-- nfs4_proc_destroy_session\n");
5028 int nfs4_init_session(struct nfs_server *server)
5030 struct nfs_client *clp = server->nfs_client;
5031 struct nfs4_session *session;
5032 unsigned int rsize, wsize;
5035 if (!nfs4_has_session(clp))
5038 rsize = server->rsize;
5040 rsize = NFS_MAX_FILE_IO_SIZE;
5041 wsize = server->wsize;
5043 wsize = NFS_MAX_FILE_IO_SIZE;
5045 session = clp->cl_session;
5046 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5047 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5049 ret = nfs4_recover_expired_lease(server);
5051 ret = nfs4_check_client_ready(clp);
5056 * Renew the cl_session lease.
5058 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5060 struct nfs4_sequence_args args;
5061 struct nfs4_sequence_res res;
5063 struct rpc_message msg = {
5064 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5070 args.sa_cache_this = 0;
5072 return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args,
5073 &res, args.sa_cache_this, 1);
5076 struct nfs4_sequence_data {
5077 struct nfs_client *clp;
5078 struct nfs4_sequence_args args;
5079 struct nfs4_sequence_res res;
5082 static void nfs41_sequence_release(void *data)
5084 struct nfs4_sequence_data *calldata = data;
5085 struct nfs_client *clp = calldata->clp;
5087 if (atomic_read(&clp->cl_count) > 1)
5088 nfs4_schedule_state_renewal(clp);
5089 nfs_put_client(clp);
5093 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5095 struct nfs4_sequence_data *calldata = data;
5096 struct nfs_client *clp = calldata->clp;
5098 nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status);
5100 if (task->tk_status < 0) {
5101 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5102 if (atomic_read(&clp->cl_count) == 1)
5105 if (_nfs4_async_handle_error(task, NULL, clp, NULL)
5107 nfs_restart_rpc(task, clp);
5111 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5113 dprintk("<-- %s\n", __func__);
5116 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5118 struct nfs4_sequence_data *calldata = data;
5119 struct nfs_client *clp = calldata->clp;
5120 struct nfs4_sequence_args *args;
5121 struct nfs4_sequence_res *res;
5123 args = task->tk_msg.rpc_argp;
5124 res = task->tk_msg.rpc_resp;
5126 if (nfs4_setup_sequence(clp, args, res, 0, task))
5128 rpc_call_start(task);
5131 static const struct rpc_call_ops nfs41_sequence_ops = {
5132 .rpc_call_done = nfs41_sequence_call_done,
5133 .rpc_call_prepare = nfs41_sequence_prepare,
5134 .rpc_release = nfs41_sequence_release,
5137 static int nfs41_proc_async_sequence(struct nfs_client *clp,
5138 struct rpc_cred *cred)
5140 struct nfs4_sequence_data *calldata;
5141 struct rpc_message msg = {
5142 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5146 if (!atomic_inc_not_zero(&clp->cl_count))
5148 calldata = kmalloc(sizeof(*calldata), GFP_NOFS);
5149 if (calldata == NULL) {
5150 nfs_put_client(clp);
5153 calldata->res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5154 msg.rpc_argp = &calldata->args;
5155 msg.rpc_resp = &calldata->res;
5156 calldata->clp = clp;
5158 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
5159 &nfs41_sequence_ops, calldata);
5162 struct nfs4_reclaim_complete_data {
5163 struct nfs_client *clp;
5164 struct nfs41_reclaim_complete_args arg;
5165 struct nfs41_reclaim_complete_res res;
5168 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5170 struct nfs4_reclaim_complete_data *calldata = data;
5172 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5173 if (nfs4_setup_sequence(calldata->clp, &calldata->arg.seq_args,
5174 &calldata->res.seq_res, 0, task))
5177 rpc_call_start(task);
5180 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5182 struct nfs4_reclaim_complete_data *calldata = data;
5183 struct nfs_client *clp = calldata->clp;
5184 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5186 dprintk("--> %s\n", __func__);
5187 nfs41_sequence_done(clp, res, task->tk_status);
5188 switch (task->tk_status) {
5190 case -NFS4ERR_COMPLETE_ALREADY:
5192 case -NFS4ERR_BADSESSION:
5193 case -NFS4ERR_DEADSESSION:
5195 * Handle the session error, but do not retry the operation, as
5196 * we have no way of telling whether the clientid had to be
5197 * reset before we got our reply. If reset, a new wave of
5198 * reclaim operations will follow, containing their own reclaim
5199 * complete. We don't want our retry to get on the way of
5200 * recovery by incorrectly indicating to the server that we're
5201 * done reclaiming state since the process had to be restarted.
5203 _nfs4_async_handle_error(task, NULL, clp, NULL);
5206 if (_nfs4_async_handle_error(
5207 task, NULL, clp, NULL) == -EAGAIN) {
5208 rpc_restart_call_prepare(task);
5213 dprintk("<-- %s\n", __func__);
5216 static void nfs4_free_reclaim_complete_data(void *data)
5218 struct nfs4_reclaim_complete_data *calldata = data;
5223 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5224 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5225 .rpc_call_done = nfs4_reclaim_complete_done,
5226 .rpc_release = nfs4_free_reclaim_complete_data,
5230 * Issue a global reclaim complete.
5232 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5234 struct nfs4_reclaim_complete_data *calldata;
5235 struct rpc_task *task;
5236 struct rpc_message msg = {
5237 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5239 struct rpc_task_setup task_setup_data = {
5240 .rpc_client = clp->cl_rpcclient,
5241 .rpc_message = &msg,
5242 .callback_ops = &nfs4_reclaim_complete_call_ops,
5243 .flags = RPC_TASK_ASYNC,
5245 int status = -ENOMEM;
5247 dprintk("--> %s\n", __func__);
5248 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5249 if (calldata == NULL)
5251 calldata->clp = clp;
5252 calldata->arg.one_fs = 0;
5253 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5255 msg.rpc_argp = &calldata->arg;
5256 msg.rpc_resp = &calldata->res;
5257 task_setup_data.callback_data = calldata;
5258 task = rpc_run_task(&task_setup_data);
5260 status = PTR_ERR(task);
5266 dprintk("<-- %s status=%d\n", __func__, status);
5269 #endif /* CONFIG_NFS_V4_1 */
5271 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
5272 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5273 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5274 .recover_open = nfs4_open_reclaim,
5275 .recover_lock = nfs4_lock_reclaim,
5276 .establish_clid = nfs4_init_clientid,
5277 .get_clid_cred = nfs4_get_setclientid_cred,
5280 #if defined(CONFIG_NFS_V4_1)
5281 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
5282 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5283 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5284 .recover_open = nfs4_open_reclaim,
5285 .recover_lock = nfs4_lock_reclaim,
5286 .establish_clid = nfs41_init_clientid,
5287 .get_clid_cred = nfs4_get_exchange_id_cred,
5288 .reclaim_complete = nfs41_proc_reclaim_complete,
5290 #endif /* CONFIG_NFS_V4_1 */
5292 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
5293 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5294 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5295 .recover_open = nfs4_open_expired,
5296 .recover_lock = nfs4_lock_expired,
5297 .establish_clid = nfs4_init_clientid,
5298 .get_clid_cred = nfs4_get_setclientid_cred,
5301 #if defined(CONFIG_NFS_V4_1)
5302 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
5303 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5304 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5305 .recover_open = nfs4_open_expired,
5306 .recover_lock = nfs4_lock_expired,
5307 .establish_clid = nfs41_init_clientid,
5308 .get_clid_cred = nfs4_get_exchange_id_cred,
5310 #endif /* CONFIG_NFS_V4_1 */
5312 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
5313 .sched_state_renewal = nfs4_proc_async_renew,
5314 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
5315 .renew_lease = nfs4_proc_renew,
5318 #if defined(CONFIG_NFS_V4_1)
5319 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
5320 .sched_state_renewal = nfs41_proc_async_sequence,
5321 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
5322 .renew_lease = nfs4_proc_sequence,
5327 * Per minor version reboot and network partition recovery ops
5330 struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = {
5331 &nfs40_reboot_recovery_ops,
5332 #if defined(CONFIG_NFS_V4_1)
5333 &nfs41_reboot_recovery_ops,
5337 struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = {
5338 &nfs40_nograce_recovery_ops,
5339 #if defined(CONFIG_NFS_V4_1)
5340 &nfs41_nograce_recovery_ops,
5344 struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = {
5345 &nfs40_state_renewal_ops,
5346 #if defined(CONFIG_NFS_V4_1)
5347 &nfs41_state_renewal_ops,
5351 static const struct inode_operations nfs4_file_inode_operations = {
5352 .permission = nfs_permission,
5353 .getattr = nfs_getattr,
5354 .setattr = nfs_setattr,
5355 .getxattr = nfs4_getxattr,
5356 .setxattr = nfs4_setxattr,
5357 .listxattr = nfs4_listxattr,
5360 const struct nfs_rpc_ops nfs_v4_clientops = {
5361 .version = 4, /* protocol version */
5362 .dentry_ops = &nfs4_dentry_operations,
5363 .dir_inode_ops = &nfs4_dir_inode_operations,
5364 .file_inode_ops = &nfs4_file_inode_operations,
5365 .getroot = nfs4_proc_get_root,
5366 .getattr = nfs4_proc_getattr,
5367 .setattr = nfs4_proc_setattr,
5368 .lookupfh = nfs4_proc_lookupfh,
5369 .lookup = nfs4_proc_lookup,
5370 .access = nfs4_proc_access,
5371 .readlink = nfs4_proc_readlink,
5372 .create = nfs4_proc_create,
5373 .remove = nfs4_proc_remove,
5374 .unlink_setup = nfs4_proc_unlink_setup,
5375 .unlink_done = nfs4_proc_unlink_done,
5376 .rename = nfs4_proc_rename,
5377 .link = nfs4_proc_link,
5378 .symlink = nfs4_proc_symlink,
5379 .mkdir = nfs4_proc_mkdir,
5380 .rmdir = nfs4_proc_remove,
5381 .readdir = nfs4_proc_readdir,
5382 .mknod = nfs4_proc_mknod,
5383 .statfs = nfs4_proc_statfs,
5384 .fsinfo = nfs4_proc_fsinfo,
5385 .pathconf = nfs4_proc_pathconf,
5386 .set_capabilities = nfs4_server_capabilities,
5387 .decode_dirent = nfs4_decode_dirent,
5388 .read_setup = nfs4_proc_read_setup,
5389 .read_done = nfs4_read_done,
5390 .write_setup = nfs4_proc_write_setup,
5391 .write_done = nfs4_write_done,
5392 .commit_setup = nfs4_proc_commit_setup,
5393 .commit_done = nfs4_commit_done,
5394 .lock = nfs4_proc_lock,
5395 .clear_acl_cache = nfs4_zap_acl_attr,
5396 .close_context = nfs4_close_context,