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 memset(res, 0, sizeof(*res));
484 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
485 tbl = &session->fc_slot_table;
487 spin_lock(&tbl->slot_tbl_lock);
488 if (test_bit(NFS4CLNT_SESSION_DRAINING, &session->clp->cl_state) &&
489 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
491 * The state manager will wait until the slot table is empty.
492 * Schedule the reset thread
494 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
495 spin_unlock(&tbl->slot_tbl_lock);
496 dprintk("%s Schedule Session Reset\n", __func__);
500 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
501 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
502 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
503 spin_unlock(&tbl->slot_tbl_lock);
504 dprintk("%s enforce FIFO order\n", __func__);
508 slotid = nfs4_find_slot(tbl);
509 if (slotid == NFS4_MAX_SLOT_TABLE) {
510 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
511 spin_unlock(&tbl->slot_tbl_lock);
512 dprintk("<-- %s: no free slots\n", __func__);
515 spin_unlock(&tbl->slot_tbl_lock);
517 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
518 slot = tbl->slots + slotid;
519 args->sa_session = session;
520 args->sa_slotid = slotid;
521 args->sa_cache_this = cache_reply;
523 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
525 res->sr_session = session;
526 res->sr_slotid = slotid;
527 res->sr_renewal_time = jiffies;
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,
551 if (ret && ret != -EAGAIN) {
552 /* terminate rpc task */
553 task->tk_status = ret;
554 task->tk_action = NULL;
557 dprintk("<-- %s status=%d\n", __func__, ret);
561 struct nfs41_call_sync_data {
562 struct nfs_client *clp;
563 struct nfs4_sequence_args *seq_args;
564 struct nfs4_sequence_res *seq_res;
568 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
570 struct nfs41_call_sync_data *data = calldata;
572 dprintk("--> %s data->clp->cl_session %p\n", __func__,
573 data->clp->cl_session);
574 if (nfs4_setup_sequence(data->clp, data->seq_args,
575 data->seq_res, data->cache_reply, task))
577 rpc_call_start(task);
580 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
582 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
583 nfs41_call_sync_prepare(task, calldata);
586 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
588 struct nfs41_call_sync_data *data = calldata;
590 nfs41_sequence_done(data->clp, data->seq_res, task->tk_status);
593 struct rpc_call_ops nfs41_call_sync_ops = {
594 .rpc_call_prepare = nfs41_call_sync_prepare,
595 .rpc_call_done = nfs41_call_sync_done,
598 struct rpc_call_ops nfs41_call_priv_sync_ops = {
599 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
600 .rpc_call_done = nfs41_call_sync_done,
603 static int nfs4_call_sync_sequence(struct nfs_client *clp,
604 struct rpc_clnt *clnt,
605 struct rpc_message *msg,
606 struct nfs4_sequence_args *args,
607 struct nfs4_sequence_res *res,
612 struct rpc_task *task;
613 struct nfs41_call_sync_data data = {
617 .cache_reply = cache_reply,
619 struct rpc_task_setup task_setup = {
622 .callback_ops = &nfs41_call_sync_ops,
623 .callback_data = &data
626 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
628 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
629 task = rpc_run_task(&task_setup);
633 ret = task->tk_status;
639 int _nfs4_call_sync_session(struct nfs_server *server,
640 struct rpc_message *msg,
641 struct nfs4_sequence_args *args,
642 struct nfs4_sequence_res *res,
645 return nfs4_call_sync_sequence(server->nfs_client, server->client,
646 msg, args, res, cache_reply, 0);
649 #endif /* CONFIG_NFS_V4_1 */
651 int _nfs4_call_sync(struct nfs_server *server,
652 struct rpc_message *msg,
653 struct nfs4_sequence_args *args,
654 struct nfs4_sequence_res *res,
657 args->sa_session = res->sr_session = NULL;
658 return rpc_call_sync(server->client, msg, 0);
661 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
662 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
663 &(res)->seq_res, (cache_reply))
665 static void nfs4_sequence_done(const struct nfs_server *server,
666 struct nfs4_sequence_res *res, int rpc_status)
668 #ifdef CONFIG_NFS_V4_1
669 if (nfs4_has_session(server->nfs_client))
670 nfs41_sequence_done(server->nfs_client, res, rpc_status);
671 #endif /* CONFIG_NFS_V4_1 */
674 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
676 struct nfs_inode *nfsi = NFS_I(dir);
678 spin_lock(&dir->i_lock);
679 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
680 if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
681 nfs_force_lookup_revalidate(dir);
682 nfsi->change_attr = cinfo->after;
683 spin_unlock(&dir->i_lock);
686 struct nfs4_opendata {
688 struct nfs_openargs o_arg;
689 struct nfs_openres o_res;
690 struct nfs_open_confirmargs c_arg;
691 struct nfs_open_confirmres c_res;
692 struct nfs_fattr f_attr;
693 struct nfs_fattr dir_attr;
696 struct nfs4_state_owner *owner;
697 struct nfs4_state *state;
699 unsigned long timestamp;
700 unsigned int rpc_done : 1;
706 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
708 p->o_res.f_attr = &p->f_attr;
709 p->o_res.dir_attr = &p->dir_attr;
710 p->o_res.seqid = p->o_arg.seqid;
711 p->c_res.seqid = p->c_arg.seqid;
712 p->o_res.server = p->o_arg.server;
713 nfs_fattr_init(&p->f_attr);
714 nfs_fattr_init(&p->dir_attr);
715 p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
718 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
719 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
720 const struct iattr *attrs)
722 struct dentry *parent = dget_parent(path->dentry);
723 struct inode *dir = parent->d_inode;
724 struct nfs_server *server = NFS_SERVER(dir);
725 struct nfs4_opendata *p;
727 p = kzalloc(sizeof(*p), GFP_KERNEL);
730 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
731 if (p->o_arg.seqid == NULL)
737 atomic_inc(&sp->so_count);
738 p->o_arg.fh = NFS_FH(dir);
739 p->o_arg.open_flags = flags;
740 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
741 p->o_arg.clientid = server->nfs_client->cl_clientid;
742 p->o_arg.id = sp->so_owner_id.id;
743 p->o_arg.name = &p->path.dentry->d_name;
744 p->o_arg.server = server;
745 p->o_arg.bitmask = server->attr_bitmask;
746 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
747 if (flags & O_EXCL) {
748 if (nfs4_has_persistent_session(server->nfs_client)) {
750 p->o_arg.u.attrs = &p->attrs;
751 memcpy(&p->attrs, attrs, sizeof(p->attrs));
752 } else { /* EXCLUSIVE4_1 */
753 u32 *s = (u32 *) p->o_arg.u.verifier.data;
757 } else if (flags & O_CREAT) {
758 p->o_arg.u.attrs = &p->attrs;
759 memcpy(&p->attrs, attrs, sizeof(p->attrs));
761 p->c_arg.fh = &p->o_res.fh;
762 p->c_arg.stateid = &p->o_res.stateid;
763 p->c_arg.seqid = p->o_arg.seqid;
764 nfs4_init_opendata_res(p);
774 static void nfs4_opendata_free(struct kref *kref)
776 struct nfs4_opendata *p = container_of(kref,
777 struct nfs4_opendata, kref);
779 nfs_free_seqid(p->o_arg.seqid);
780 if (p->state != NULL)
781 nfs4_put_open_state(p->state);
782 nfs4_put_state_owner(p->owner);
788 static void nfs4_opendata_put(struct nfs4_opendata *p)
791 kref_put(&p->kref, nfs4_opendata_free);
794 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
798 ret = rpc_wait_for_completion_task(task);
802 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
806 if (open_mode & O_EXCL)
808 switch (mode & (FMODE_READ|FMODE_WRITE)) {
810 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
811 && state->n_rdonly != 0;
814 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
815 && state->n_wronly != 0;
817 case FMODE_READ|FMODE_WRITE:
818 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
819 && state->n_rdwr != 0;
825 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
827 if ((delegation->type & fmode) != fmode)
829 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
831 nfs_mark_delegation_referenced(delegation);
835 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
844 case FMODE_READ|FMODE_WRITE:
847 nfs4_state_set_mode_locked(state, state->state | fmode);
850 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
852 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
853 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
854 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
857 set_bit(NFS_O_RDONLY_STATE, &state->flags);
860 set_bit(NFS_O_WRONLY_STATE, &state->flags);
862 case FMODE_READ|FMODE_WRITE:
863 set_bit(NFS_O_RDWR_STATE, &state->flags);
867 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
869 write_seqlock(&state->seqlock);
870 nfs_set_open_stateid_locked(state, stateid, fmode);
871 write_sequnlock(&state->seqlock);
874 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
877 * Protect the call to nfs4_state_set_mode_locked and
878 * serialise the stateid update
880 write_seqlock(&state->seqlock);
881 if (deleg_stateid != NULL) {
882 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
883 set_bit(NFS_DELEGATED_STATE, &state->flags);
885 if (open_stateid != NULL)
886 nfs_set_open_stateid_locked(state, open_stateid, fmode);
887 write_sequnlock(&state->seqlock);
888 spin_lock(&state->owner->so_lock);
889 update_open_stateflags(state, fmode);
890 spin_unlock(&state->owner->so_lock);
893 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
895 struct nfs_inode *nfsi = NFS_I(state->inode);
896 struct nfs_delegation *deleg_cur;
899 fmode &= (FMODE_READ|FMODE_WRITE);
902 deleg_cur = rcu_dereference(nfsi->delegation);
903 if (deleg_cur == NULL)
906 spin_lock(&deleg_cur->lock);
907 if (nfsi->delegation != deleg_cur ||
908 (deleg_cur->type & fmode) != fmode)
909 goto no_delegation_unlock;
911 if (delegation == NULL)
912 delegation = &deleg_cur->stateid;
913 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
914 goto no_delegation_unlock;
916 nfs_mark_delegation_referenced(deleg_cur);
917 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
919 no_delegation_unlock:
920 spin_unlock(&deleg_cur->lock);
924 if (!ret && open_stateid != NULL) {
925 __update_open_stateid(state, open_stateid, NULL, fmode);
933 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
935 struct nfs_delegation *delegation;
938 delegation = rcu_dereference(NFS_I(inode)->delegation);
939 if (delegation == NULL || (delegation->type & fmode) == fmode) {
944 nfs_inode_return_delegation(inode);
947 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
949 struct nfs4_state *state = opendata->state;
950 struct nfs_inode *nfsi = NFS_I(state->inode);
951 struct nfs_delegation *delegation;
952 int open_mode = opendata->o_arg.open_flags & O_EXCL;
953 fmode_t fmode = opendata->o_arg.fmode;
954 nfs4_stateid stateid;
958 if (can_open_cached(state, fmode, open_mode)) {
959 spin_lock(&state->owner->so_lock);
960 if (can_open_cached(state, fmode, open_mode)) {
961 update_open_stateflags(state, fmode);
962 spin_unlock(&state->owner->so_lock);
963 goto out_return_state;
965 spin_unlock(&state->owner->so_lock);
968 delegation = rcu_dereference(nfsi->delegation);
969 if (delegation == NULL ||
970 !can_open_delegated(delegation, fmode)) {
974 /* Save the delegation */
975 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
977 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
982 /* Try to update the stateid using the delegation */
983 if (update_open_stateid(state, NULL, &stateid, fmode))
984 goto out_return_state;
989 atomic_inc(&state->count);
993 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
996 struct nfs4_state *state = NULL;
997 struct nfs_delegation *delegation;
1000 if (!data->rpc_done) {
1001 state = nfs4_try_open_cached(data);
1006 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1008 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1009 ret = PTR_ERR(inode);
1013 state = nfs4_get_open_state(inode, data->owner);
1016 if (data->o_res.delegation_type != 0) {
1017 int delegation_flags = 0;
1020 delegation = rcu_dereference(NFS_I(inode)->delegation);
1022 delegation_flags = delegation->flags;
1024 if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1025 nfs_inode_set_delegation(state->inode,
1026 data->owner->so_cred,
1029 nfs_inode_reclaim_delegation(state->inode,
1030 data->owner->so_cred,
1034 update_open_stateid(state, &data->o_res.stateid, NULL,
1042 return ERR_PTR(ret);
1045 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1047 struct nfs_inode *nfsi = NFS_I(state->inode);
1048 struct nfs_open_context *ctx;
1050 spin_lock(&state->inode->i_lock);
1051 list_for_each_entry(ctx, &nfsi->open_files, list) {
1052 if (ctx->state != state)
1054 get_nfs_open_context(ctx);
1055 spin_unlock(&state->inode->i_lock);
1058 spin_unlock(&state->inode->i_lock);
1059 return ERR_PTR(-ENOENT);
1062 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1064 struct nfs4_opendata *opendata;
1066 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL);
1067 if (opendata == NULL)
1068 return ERR_PTR(-ENOMEM);
1069 opendata->state = state;
1070 atomic_inc(&state->count);
1074 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1076 struct nfs4_state *newstate;
1079 opendata->o_arg.open_flags = 0;
1080 opendata->o_arg.fmode = fmode;
1081 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1082 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1083 nfs4_init_opendata_res(opendata);
1084 ret = _nfs4_recover_proc_open(opendata);
1087 newstate = nfs4_opendata_to_nfs4_state(opendata);
1088 if (IS_ERR(newstate))
1089 return PTR_ERR(newstate);
1090 nfs4_close_state(&opendata->path, newstate, fmode);
1095 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1097 struct nfs4_state *newstate;
1100 /* memory barrier prior to reading state->n_* */
1101 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1103 if (state->n_rdwr != 0) {
1104 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1107 if (newstate != state)
1110 if (state->n_wronly != 0) {
1111 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1114 if (newstate != state)
1117 if (state->n_rdonly != 0) {
1118 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1121 if (newstate != state)
1125 * We may have performed cached opens for all three recoveries.
1126 * Check if we need to update the current stateid.
1128 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1129 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
1130 write_seqlock(&state->seqlock);
1131 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1132 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
1133 write_sequnlock(&state->seqlock);
1140 * reclaim state on the server after a reboot.
1142 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1144 struct nfs_delegation *delegation;
1145 struct nfs4_opendata *opendata;
1146 fmode_t delegation_type = 0;
1149 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1150 if (IS_ERR(opendata))
1151 return PTR_ERR(opendata);
1152 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1153 opendata->o_arg.fh = NFS_FH(state->inode);
1155 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1156 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1157 delegation_type = delegation->type;
1159 opendata->o_arg.u.delegation_type = delegation_type;
1160 status = nfs4_open_recover(opendata, state);
1161 nfs4_opendata_put(opendata);
1165 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1167 struct nfs_server *server = NFS_SERVER(state->inode);
1168 struct nfs4_exception exception = { };
1171 err = _nfs4_do_open_reclaim(ctx, state);
1172 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
1174 nfs4_handle_exception(server, err, &exception);
1175 } while (exception.retry);
1179 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1181 struct nfs_open_context *ctx;
1184 ctx = nfs4_state_find_open_context(state);
1186 return PTR_ERR(ctx);
1187 ret = nfs4_do_open_reclaim(ctx, state);
1188 put_nfs_open_context(ctx);
1192 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1194 struct nfs4_opendata *opendata;
1197 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1198 if (IS_ERR(opendata))
1199 return PTR_ERR(opendata);
1200 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1201 memcpy(opendata->o_arg.u.delegation.data, stateid->data,
1202 sizeof(opendata->o_arg.u.delegation.data));
1203 ret = nfs4_open_recover(opendata, state);
1204 nfs4_opendata_put(opendata);
1208 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1210 struct nfs4_exception exception = { };
1211 struct nfs_server *server = NFS_SERVER(state->inode);
1214 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1220 case -NFS4ERR_BADSESSION:
1221 case -NFS4ERR_BADSLOT:
1222 case -NFS4ERR_BAD_HIGH_SLOT:
1223 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1224 case -NFS4ERR_DEADSESSION:
1225 nfs4_schedule_state_recovery(
1226 server->nfs_client);
1228 case -NFS4ERR_STALE_CLIENTID:
1229 case -NFS4ERR_STALE_STATEID:
1230 case -NFS4ERR_EXPIRED:
1231 /* Don't recall a delegation if it was lost */
1232 nfs4_schedule_state_recovery(server->nfs_client);
1236 * The show must go on: exit, but mark the
1237 * stateid as needing recovery.
1239 case -NFS4ERR_ADMIN_REVOKED:
1240 case -NFS4ERR_BAD_STATEID:
1241 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
1246 err = nfs4_handle_exception(server, err, &exception);
1247 } while (exception.retry);
1252 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1254 struct nfs4_opendata *data = calldata;
1256 data->rpc_status = task->tk_status;
1257 if (RPC_ASSASSINATED(task))
1259 if (data->rpc_status == 0) {
1260 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1261 sizeof(data->o_res.stateid.data));
1262 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1263 renew_lease(data->o_res.server, data->timestamp);
1268 static void nfs4_open_confirm_release(void *calldata)
1270 struct nfs4_opendata *data = calldata;
1271 struct nfs4_state *state = NULL;
1273 /* If this request hasn't been cancelled, do nothing */
1274 if (data->cancelled == 0)
1276 /* In case of error, no cleanup! */
1277 if (!data->rpc_done)
1279 state = nfs4_opendata_to_nfs4_state(data);
1281 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1283 nfs4_opendata_put(data);
1286 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1287 .rpc_call_done = nfs4_open_confirm_done,
1288 .rpc_release = nfs4_open_confirm_release,
1292 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1294 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1296 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1297 struct rpc_task *task;
1298 struct rpc_message msg = {
1299 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1300 .rpc_argp = &data->c_arg,
1301 .rpc_resp = &data->c_res,
1302 .rpc_cred = data->owner->so_cred,
1304 struct rpc_task_setup task_setup_data = {
1305 .rpc_client = server->client,
1306 .rpc_message = &msg,
1307 .callback_ops = &nfs4_open_confirm_ops,
1308 .callback_data = data,
1309 .workqueue = nfsiod_workqueue,
1310 .flags = RPC_TASK_ASYNC,
1314 kref_get(&data->kref);
1316 data->rpc_status = 0;
1317 data->timestamp = jiffies;
1318 task = rpc_run_task(&task_setup_data);
1320 return PTR_ERR(task);
1321 status = nfs4_wait_for_completion_rpc_task(task);
1323 data->cancelled = 1;
1326 status = data->rpc_status;
1331 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1333 struct nfs4_opendata *data = calldata;
1334 struct nfs4_state_owner *sp = data->owner;
1336 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1339 * Check if we still need to send an OPEN call, or if we can use
1340 * a delegation instead.
1342 if (data->state != NULL) {
1343 struct nfs_delegation *delegation;
1345 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1348 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1349 if (delegation != NULL &&
1350 test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
1356 /* Update sequence id. */
1357 data->o_arg.id = sp->so_owner_id.id;
1358 data->o_arg.clientid = sp->so_client->cl_clientid;
1359 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1360 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1361 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1363 data->timestamp = jiffies;
1364 if (nfs4_setup_sequence(data->o_arg.server->nfs_client,
1365 &data->o_arg.seq_args,
1366 &data->o_res.seq_res, 1, task))
1368 rpc_call_start(task);
1371 task->tk_action = NULL;
1375 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1377 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1378 nfs4_open_prepare(task, calldata);
1381 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1383 struct nfs4_opendata *data = calldata;
1385 data->rpc_status = task->tk_status;
1387 nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res,
1390 if (RPC_ASSASSINATED(task))
1392 if (task->tk_status == 0) {
1393 switch (data->o_res.f_attr->mode & S_IFMT) {
1397 data->rpc_status = -ELOOP;
1400 data->rpc_status = -EISDIR;
1403 data->rpc_status = -ENOTDIR;
1405 renew_lease(data->o_res.server, data->timestamp);
1406 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1407 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1412 static void nfs4_open_release(void *calldata)
1414 struct nfs4_opendata *data = calldata;
1415 struct nfs4_state *state = NULL;
1417 /* If this request hasn't been cancelled, do nothing */
1418 if (data->cancelled == 0)
1420 /* In case of error, no cleanup! */
1421 if (data->rpc_status != 0 || !data->rpc_done)
1423 /* In case we need an open_confirm, no cleanup! */
1424 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1426 state = nfs4_opendata_to_nfs4_state(data);
1428 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1430 nfs4_opendata_put(data);
1433 static const struct rpc_call_ops nfs4_open_ops = {
1434 .rpc_call_prepare = nfs4_open_prepare,
1435 .rpc_call_done = nfs4_open_done,
1436 .rpc_release = nfs4_open_release,
1439 static const struct rpc_call_ops nfs4_recover_open_ops = {
1440 .rpc_call_prepare = nfs4_recover_open_prepare,
1441 .rpc_call_done = nfs4_open_done,
1442 .rpc_release = nfs4_open_release,
1445 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1447 struct inode *dir = data->dir->d_inode;
1448 struct nfs_server *server = NFS_SERVER(dir);
1449 struct nfs_openargs *o_arg = &data->o_arg;
1450 struct nfs_openres *o_res = &data->o_res;
1451 struct rpc_task *task;
1452 struct rpc_message msg = {
1453 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1456 .rpc_cred = data->owner->so_cred,
1458 struct rpc_task_setup task_setup_data = {
1459 .rpc_client = server->client,
1460 .rpc_message = &msg,
1461 .callback_ops = &nfs4_open_ops,
1462 .callback_data = data,
1463 .workqueue = nfsiod_workqueue,
1464 .flags = RPC_TASK_ASYNC,
1468 kref_get(&data->kref);
1470 data->rpc_status = 0;
1471 data->cancelled = 0;
1473 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1474 task = rpc_run_task(&task_setup_data);
1476 return PTR_ERR(task);
1477 status = nfs4_wait_for_completion_rpc_task(task);
1479 data->cancelled = 1;
1482 status = data->rpc_status;
1488 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1490 struct inode *dir = data->dir->d_inode;
1491 struct nfs_openres *o_res = &data->o_res;
1494 status = nfs4_run_open_task(data, 1);
1495 if (status != 0 || !data->rpc_done)
1498 nfs_refresh_inode(dir, o_res->dir_attr);
1500 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1501 status = _nfs4_proc_open_confirm(data);
1510 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1512 static int _nfs4_proc_open(struct nfs4_opendata *data)
1514 struct inode *dir = data->dir->d_inode;
1515 struct nfs_server *server = NFS_SERVER(dir);
1516 struct nfs_openargs *o_arg = &data->o_arg;
1517 struct nfs_openres *o_res = &data->o_res;
1520 status = nfs4_run_open_task(data, 0);
1521 if (status != 0 || !data->rpc_done)
1524 if (o_arg->open_flags & O_CREAT) {
1525 update_changeattr(dir, &o_res->cinfo);
1526 nfs_post_op_update_inode(dir, o_res->dir_attr);
1528 nfs_refresh_inode(dir, o_res->dir_attr);
1529 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1530 server->caps &= ~NFS_CAP_POSIX_LOCK;
1531 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1532 status = _nfs4_proc_open_confirm(data);
1536 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1537 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1541 static int nfs4_recover_expired_lease(struct nfs_server *server)
1543 struct nfs_client *clp = server->nfs_client;
1547 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1548 ret = nfs4_wait_clnt_recover(clp);
1551 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1552 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1554 nfs4_schedule_state_recovery(clp);
1562 * reclaim state on the server after a network partition.
1563 * Assumes caller holds the appropriate lock
1565 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1567 struct nfs4_opendata *opendata;
1570 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1571 if (IS_ERR(opendata))
1572 return PTR_ERR(opendata);
1573 ret = nfs4_open_recover(opendata, state);
1575 d_drop(ctx->path.dentry);
1576 nfs4_opendata_put(opendata);
1580 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1582 struct nfs_server *server = NFS_SERVER(state->inode);
1583 struct nfs4_exception exception = { };
1587 err = _nfs4_open_expired(ctx, state);
1591 case -NFS4ERR_GRACE:
1592 case -NFS4ERR_DELAY:
1594 nfs4_handle_exception(server, err, &exception);
1597 } while (exception.retry);
1602 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1604 struct nfs_open_context *ctx;
1607 ctx = nfs4_state_find_open_context(state);
1609 return PTR_ERR(ctx);
1610 ret = nfs4_do_open_expired(ctx, state);
1611 put_nfs_open_context(ctx);
1616 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1617 * fields corresponding to attributes that were used to store the verifier.
1618 * Make sure we clobber those fields in the later setattr call
1620 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1622 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1623 !(sattr->ia_valid & ATTR_ATIME_SET))
1624 sattr->ia_valid |= ATTR_ATIME;
1626 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1627 !(sattr->ia_valid & ATTR_MTIME_SET))
1628 sattr->ia_valid |= ATTR_MTIME;
1632 * Returns a referenced nfs4_state
1634 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)
1636 struct nfs4_state_owner *sp;
1637 struct nfs4_state *state = NULL;
1638 struct nfs_server *server = NFS_SERVER(dir);
1639 struct nfs4_opendata *opendata;
1642 /* Protect against reboot recovery conflicts */
1644 if (!(sp = nfs4_get_state_owner(server, cred))) {
1645 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1648 status = nfs4_recover_expired_lease(server);
1650 goto err_put_state_owner;
1651 if (path->dentry->d_inode != NULL)
1652 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1654 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr);
1655 if (opendata == NULL)
1656 goto err_put_state_owner;
1658 if (path->dentry->d_inode != NULL)
1659 opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
1661 status = _nfs4_proc_open(opendata);
1663 goto err_opendata_put;
1665 state = nfs4_opendata_to_nfs4_state(opendata);
1666 status = PTR_ERR(state);
1668 goto err_opendata_put;
1669 if (server->caps & NFS_CAP_POSIX_LOCK)
1670 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1672 if (opendata->o_arg.open_flags & O_EXCL) {
1673 nfs4_exclusive_attrset(opendata, sattr);
1675 nfs_fattr_init(opendata->o_res.f_attr);
1676 status = nfs4_do_setattr(state->inode, cred,
1677 opendata->o_res.f_attr, sattr,
1680 nfs_setattr_update_inode(state->inode, sattr);
1681 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1683 nfs4_opendata_put(opendata);
1684 nfs4_put_state_owner(sp);
1688 nfs4_opendata_put(opendata);
1689 err_put_state_owner:
1690 nfs4_put_state_owner(sp);
1697 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)
1699 struct nfs4_exception exception = { };
1700 struct nfs4_state *res;
1704 status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
1707 /* NOTE: BAD_SEQID means the server and client disagree about the
1708 * book-keeping w.r.t. state-changing operations
1709 * (OPEN/CLOSE/LOCK/LOCKU...)
1710 * It is actually a sign of a bug on the client or on the server.
1712 * If we receive a BAD_SEQID error in the particular case of
1713 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1714 * have unhashed the old state_owner for us, and that we can
1715 * therefore safely retry using a new one. We should still warn
1716 * the user though...
1718 if (status == -NFS4ERR_BAD_SEQID) {
1719 printk(KERN_WARNING "NFS: v4 server %s "
1720 " returned a bad sequence-id error!\n",
1721 NFS_SERVER(dir)->nfs_client->cl_hostname);
1722 exception.retry = 1;
1726 * BAD_STATEID on OPEN means that the server cancelled our
1727 * state before it received the OPEN_CONFIRM.
1728 * Recover by retrying the request as per the discussion
1729 * on Page 181 of RFC3530.
1731 if (status == -NFS4ERR_BAD_STATEID) {
1732 exception.retry = 1;
1735 if (status == -EAGAIN) {
1736 /* We must have found a delegation */
1737 exception.retry = 1;
1740 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1741 status, &exception));
1742 } while (exception.retry);
1746 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1747 struct nfs_fattr *fattr, struct iattr *sattr,
1748 struct nfs4_state *state)
1750 struct nfs_server *server = NFS_SERVER(inode);
1751 struct nfs_setattrargs arg = {
1752 .fh = NFS_FH(inode),
1755 .bitmask = server->attr_bitmask,
1757 struct nfs_setattrres res = {
1761 struct rpc_message msg = {
1762 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1767 unsigned long timestamp = jiffies;
1770 nfs_fattr_init(fattr);
1772 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1773 /* Use that stateid */
1774 } else if (state != NULL) {
1775 nfs4_copy_stateid(&arg.stateid, state, current->files);
1777 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1779 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
1780 if (status == 0 && state != NULL)
1781 renew_lease(server, timestamp);
1785 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1786 struct nfs_fattr *fattr, struct iattr *sattr,
1787 struct nfs4_state *state)
1789 struct nfs_server *server = NFS_SERVER(inode);
1790 struct nfs4_exception exception = { };
1793 err = nfs4_handle_exception(server,
1794 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1796 } while (exception.retry);
1800 struct nfs4_closedata {
1802 struct inode *inode;
1803 struct nfs4_state *state;
1804 struct nfs_closeargs arg;
1805 struct nfs_closeres res;
1806 struct nfs_fattr fattr;
1807 unsigned long timestamp;
1810 static void nfs4_free_closedata(void *data)
1812 struct nfs4_closedata *calldata = data;
1813 struct nfs4_state_owner *sp = calldata->state->owner;
1815 nfs4_put_open_state(calldata->state);
1816 nfs_free_seqid(calldata->arg.seqid);
1817 nfs4_put_state_owner(sp);
1818 path_put(&calldata->path);
1822 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1825 spin_lock(&state->owner->so_lock);
1826 if (!(fmode & FMODE_READ))
1827 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1828 if (!(fmode & FMODE_WRITE))
1829 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1830 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1831 spin_unlock(&state->owner->so_lock);
1834 static void nfs4_close_done(struct rpc_task *task, void *data)
1836 struct nfs4_closedata *calldata = data;
1837 struct nfs4_state *state = calldata->state;
1838 struct nfs_server *server = NFS_SERVER(calldata->inode);
1840 nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status);
1841 if (RPC_ASSASSINATED(task))
1843 /* hmm. we are done with the inode, and in the process of freeing
1844 * the state_owner. we keep this around to process errors
1846 switch (task->tk_status) {
1848 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1849 renew_lease(server, calldata->timestamp);
1850 nfs4_close_clear_stateid_flags(state,
1851 calldata->arg.fmode);
1853 case -NFS4ERR_STALE_STATEID:
1854 case -NFS4ERR_OLD_STATEID:
1855 case -NFS4ERR_BAD_STATEID:
1856 case -NFS4ERR_EXPIRED:
1857 if (calldata->arg.fmode == 0)
1860 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1861 rpc_restart_call_prepare(task);
1863 nfs_release_seqid(calldata->arg.seqid);
1864 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1867 static void nfs4_close_prepare(struct rpc_task *task, void *data)
1869 struct nfs4_closedata *calldata = data;
1870 struct nfs4_state *state = calldata->state;
1873 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1876 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1877 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1878 spin_lock(&state->owner->so_lock);
1879 /* Calculate the change in open mode */
1880 if (state->n_rdwr == 0) {
1881 if (state->n_rdonly == 0) {
1882 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1883 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1884 calldata->arg.fmode &= ~FMODE_READ;
1886 if (state->n_wronly == 0) {
1887 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1888 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1889 calldata->arg.fmode &= ~FMODE_WRITE;
1892 spin_unlock(&state->owner->so_lock);
1895 /* Note: exit _without_ calling nfs4_close_done */
1896 task->tk_action = NULL;
1900 if (calldata->arg.fmode == 0)
1901 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1903 nfs_fattr_init(calldata->res.fattr);
1904 calldata->timestamp = jiffies;
1905 if (nfs4_setup_sequence((NFS_SERVER(calldata->inode))->nfs_client,
1906 &calldata->arg.seq_args, &calldata->res.seq_res,
1909 rpc_call_start(task);
1912 static const struct rpc_call_ops nfs4_close_ops = {
1913 .rpc_call_prepare = nfs4_close_prepare,
1914 .rpc_call_done = nfs4_close_done,
1915 .rpc_release = nfs4_free_closedata,
1919 * It is possible for data to be read/written from a mem-mapped file
1920 * after the sys_close call (which hits the vfs layer as a flush).
1921 * This means that we can't safely call nfsv4 close on a file until
1922 * the inode is cleared. This in turn means that we are not good
1923 * NFSv4 citizens - we do not indicate to the server to update the file's
1924 * share state even when we are done with one of the three share
1925 * stateid's in the inode.
1927 * NOTE: Caller must be holding the sp->so_owner semaphore!
1929 int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1931 struct nfs_server *server = NFS_SERVER(state->inode);
1932 struct nfs4_closedata *calldata;
1933 struct nfs4_state_owner *sp = state->owner;
1934 struct rpc_task *task;
1935 struct rpc_message msg = {
1936 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
1937 .rpc_cred = state->owner->so_cred,
1939 struct rpc_task_setup task_setup_data = {
1940 .rpc_client = server->client,
1941 .rpc_message = &msg,
1942 .callback_ops = &nfs4_close_ops,
1943 .workqueue = nfsiod_workqueue,
1944 .flags = RPC_TASK_ASYNC,
1946 int status = -ENOMEM;
1948 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
1949 if (calldata == NULL)
1951 calldata->inode = state->inode;
1952 calldata->state = state;
1953 calldata->arg.fh = NFS_FH(state->inode);
1954 calldata->arg.stateid = &state->open_stateid;
1955 /* Serialization for the sequence id */
1956 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
1957 if (calldata->arg.seqid == NULL)
1958 goto out_free_calldata;
1959 calldata->arg.fmode = 0;
1960 calldata->arg.bitmask = server->cache_consistency_bitmask;
1961 calldata->res.fattr = &calldata->fattr;
1962 calldata->res.seqid = calldata->arg.seqid;
1963 calldata->res.server = server;
1964 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
1966 calldata->path = *path;
1968 msg.rpc_argp = &calldata->arg,
1969 msg.rpc_resp = &calldata->res,
1970 task_setup_data.callback_data = calldata;
1971 task = rpc_run_task(&task_setup_data);
1973 return PTR_ERR(task);
1976 status = rpc_wait_for_completion_task(task);
1982 nfs4_put_open_state(state);
1983 nfs4_put_state_owner(sp);
1987 static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode)
1992 /* If the open_intent is for execute, we have an extra check to make */
1993 if (fmode & FMODE_EXEC) {
1994 ret = nfs_may_open(state->inode,
1995 state->owner->so_cred,
1996 nd->intent.open.flags);
2000 filp = lookup_instantiate_filp(nd, path->dentry, NULL);
2001 if (!IS_ERR(filp)) {
2002 struct nfs_open_context *ctx;
2003 ctx = nfs_file_open_context(filp);
2007 ret = PTR_ERR(filp);
2009 nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
2014 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
2016 struct path path = {
2017 .mnt = nd->path.mnt,
2020 struct dentry *parent;
2022 struct rpc_cred *cred;
2023 struct nfs4_state *state;
2025 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
2027 if (nd->flags & LOOKUP_CREATE) {
2028 attr.ia_mode = nd->intent.open.create_mode;
2029 attr.ia_valid = ATTR_MODE;
2030 if (!IS_POSIXACL(dir))
2031 attr.ia_mode &= ~current_umask();
2034 BUG_ON(nd->intent.open.flags & O_CREAT);
2037 cred = rpc_lookup_cred();
2039 return (struct dentry *)cred;
2040 parent = dentry->d_parent;
2041 /* Protect against concurrent sillydeletes */
2042 nfs_block_sillyrename(parent);
2043 state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred);
2045 if (IS_ERR(state)) {
2046 if (PTR_ERR(state) == -ENOENT) {
2047 d_add(dentry, NULL);
2048 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2050 nfs_unblock_sillyrename(parent);
2051 return (struct dentry *)state;
2053 res = d_add_unique(dentry, igrab(state->inode));
2056 nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
2057 nfs_unblock_sillyrename(parent);
2058 nfs4_intent_set_file(nd, &path, state, fmode);
2063 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
2065 struct path path = {
2066 .mnt = nd->path.mnt,
2069 struct rpc_cred *cred;
2070 struct nfs4_state *state;
2071 fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
2073 cred = rpc_lookup_cred();
2075 return PTR_ERR(cred);
2076 state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
2078 if (IS_ERR(state)) {
2079 switch (PTR_ERR(state)) {
2085 return PTR_ERR(state);
2090 if (state->inode == dentry->d_inode) {
2091 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2092 nfs4_intent_set_file(nd, &path, state, fmode);
2095 nfs4_close_sync(&path, state, fmode);
2101 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2103 if (ctx->state == NULL)
2106 nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
2108 nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
2111 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2113 struct nfs4_server_caps_arg args = {
2116 struct nfs4_server_caps_res res = {};
2117 struct rpc_message msg = {
2118 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2124 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2126 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2127 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2128 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2129 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2130 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2131 NFS_CAP_CTIME|NFS_CAP_MTIME);
2132 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2133 server->caps |= NFS_CAP_ACLS;
2134 if (res.has_links != 0)
2135 server->caps |= NFS_CAP_HARDLINKS;
2136 if (res.has_symlinks != 0)
2137 server->caps |= NFS_CAP_SYMLINKS;
2138 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2139 server->caps |= NFS_CAP_FILEID;
2140 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2141 server->caps |= NFS_CAP_MODE;
2142 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2143 server->caps |= NFS_CAP_NLINK;
2144 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2145 server->caps |= NFS_CAP_OWNER;
2146 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2147 server->caps |= NFS_CAP_OWNER_GROUP;
2148 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2149 server->caps |= NFS_CAP_ATIME;
2150 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2151 server->caps |= NFS_CAP_CTIME;
2152 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2153 server->caps |= NFS_CAP_MTIME;
2155 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2156 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2157 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2158 server->acl_bitmask = res.acl_bitmask;
2164 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2166 struct nfs4_exception exception = { };
2169 err = nfs4_handle_exception(server,
2170 _nfs4_server_capabilities(server, fhandle),
2172 } while (exception.retry);
2176 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2177 struct nfs_fsinfo *info)
2179 struct nfs4_lookup_root_arg args = {
2180 .bitmask = nfs4_fattr_bitmap,
2182 struct nfs4_lookup_res res = {
2184 .fattr = info->fattr,
2187 struct rpc_message msg = {
2188 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2193 nfs_fattr_init(info->fattr);
2194 return nfs4_call_sync(server, &msg, &args, &res, 0);
2197 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2198 struct nfs_fsinfo *info)
2200 struct nfs4_exception exception = { };
2203 err = nfs4_handle_exception(server,
2204 _nfs4_lookup_root(server, fhandle, info),
2206 } while (exception.retry);
2211 * get the file handle for the "/" directory on the server
2213 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2214 struct nfs_fsinfo *info)
2218 status = nfs4_lookup_root(server, fhandle, info);
2220 status = nfs4_server_capabilities(server, fhandle);
2222 status = nfs4_do_fsinfo(server, fhandle, info);
2223 return nfs4_map_errors(status);
2227 * Get locations and (maybe) other attributes of a referral.
2228 * Note that we'll actually follow the referral later when
2229 * we detect fsid mismatch in inode revalidation
2231 static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
2233 int status = -ENOMEM;
2234 struct page *page = NULL;
2235 struct nfs4_fs_locations *locations = NULL;
2237 page = alloc_page(GFP_KERNEL);
2240 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2241 if (locations == NULL)
2244 status = nfs4_proc_fs_locations(dir, name, locations, page);
2247 /* Make sure server returned a different fsid for the referral */
2248 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2249 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
2254 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2255 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
2257 fattr->mode = S_IFDIR;
2258 memset(fhandle, 0, sizeof(struct nfs_fh));
2267 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2269 struct nfs4_getattr_arg args = {
2271 .bitmask = server->attr_bitmask,
2273 struct nfs4_getattr_res res = {
2277 struct rpc_message msg = {
2278 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2283 nfs_fattr_init(fattr);
2284 return nfs4_call_sync(server, &msg, &args, &res, 0);
2287 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2289 struct nfs4_exception exception = { };
2292 err = nfs4_handle_exception(server,
2293 _nfs4_proc_getattr(server, fhandle, fattr),
2295 } while (exception.retry);
2300 * The file is not closed if it is opened due to the a request to change
2301 * the size of the file. The open call will not be needed once the
2302 * VFS layer lookup-intents are implemented.
2304 * Close is called when the inode is destroyed.
2305 * If we haven't opened the file for O_WRONLY, we
2306 * need to in the size_change case to obtain a stateid.
2309 * Because OPEN is always done by name in nfsv4, it is
2310 * possible that we opened a different file by the same
2311 * name. We can recognize this race condition, but we
2312 * can't do anything about it besides returning an error.
2314 * This will be fixed with VFS changes (lookup-intent).
2317 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2318 struct iattr *sattr)
2320 struct inode *inode = dentry->d_inode;
2321 struct rpc_cred *cred = NULL;
2322 struct nfs4_state *state = NULL;
2325 nfs_fattr_init(fattr);
2327 /* Search for an existing open(O_WRITE) file */
2328 if (sattr->ia_valid & ATTR_FILE) {
2329 struct nfs_open_context *ctx;
2331 ctx = nfs_file_open_context(sattr->ia_file);
2338 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2340 nfs_setattr_update_inode(inode, sattr);
2344 static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh,
2345 const struct qstr *name, struct nfs_fh *fhandle,
2346 struct nfs_fattr *fattr)
2349 struct nfs4_lookup_arg args = {
2350 .bitmask = server->attr_bitmask,
2354 struct nfs4_lookup_res res = {
2359 struct rpc_message msg = {
2360 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2365 nfs_fattr_init(fattr);
2367 dprintk("NFS call lookupfh %s\n", name->name);
2368 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2369 dprintk("NFS reply lookupfh: %d\n", status);
2373 static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
2374 struct qstr *name, struct nfs_fh *fhandle,
2375 struct nfs_fattr *fattr)
2377 struct nfs4_exception exception = { };
2380 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
2382 if (err == -NFS4ERR_MOVED) {
2386 err = nfs4_handle_exception(server, err, &exception);
2387 } while (exception.retry);
2391 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name,
2392 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2396 dprintk("NFS call lookup %s\n", name->name);
2397 status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
2398 if (status == -NFS4ERR_MOVED)
2399 status = nfs4_get_referral(dir, name, fattr, fhandle);
2400 dprintk("NFS reply lookup: %d\n", status);
2404 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2406 struct nfs4_exception exception = { };
2409 err = nfs4_handle_exception(NFS_SERVER(dir),
2410 _nfs4_proc_lookup(dir, name, fhandle, fattr),
2412 } while (exception.retry);
2416 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2418 struct nfs_server *server = NFS_SERVER(inode);
2419 struct nfs4_accessargs args = {
2420 .fh = NFS_FH(inode),
2421 .bitmask = server->attr_bitmask,
2423 struct nfs4_accessres res = {
2426 struct rpc_message msg = {
2427 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2430 .rpc_cred = entry->cred,
2432 int mode = entry->mask;
2436 * Determine which access bits we want to ask for...
2438 if (mode & MAY_READ)
2439 args.access |= NFS4_ACCESS_READ;
2440 if (S_ISDIR(inode->i_mode)) {
2441 if (mode & MAY_WRITE)
2442 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2443 if (mode & MAY_EXEC)
2444 args.access |= NFS4_ACCESS_LOOKUP;
2446 if (mode & MAY_WRITE)
2447 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2448 if (mode & MAY_EXEC)
2449 args.access |= NFS4_ACCESS_EXECUTE;
2452 res.fattr = nfs_alloc_fattr();
2453 if (res.fattr == NULL)
2456 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2459 if (res.access & NFS4_ACCESS_READ)
2460 entry->mask |= MAY_READ;
2461 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2462 entry->mask |= MAY_WRITE;
2463 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2464 entry->mask |= MAY_EXEC;
2465 nfs_refresh_inode(inode, res.fattr);
2467 nfs_free_fattr(res.fattr);
2471 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2473 struct nfs4_exception exception = { };
2476 err = nfs4_handle_exception(NFS_SERVER(inode),
2477 _nfs4_proc_access(inode, entry),
2479 } while (exception.retry);
2484 * TODO: For the time being, we don't try to get any attributes
2485 * along with any of the zero-copy operations READ, READDIR,
2488 * In the case of the first three, we want to put the GETATTR
2489 * after the read-type operation -- this is because it is hard
2490 * to predict the length of a GETATTR response in v4, and thus
2491 * align the READ data correctly. This means that the GETATTR
2492 * may end up partially falling into the page cache, and we should
2493 * shift it into the 'tail' of the xdr_buf before processing.
2494 * To do this efficiently, we need to know the total length
2495 * of data received, which doesn't seem to be available outside
2498 * In the case of WRITE, we also want to put the GETATTR after
2499 * the operation -- in this case because we want to make sure
2500 * we get the post-operation mtime and size. This means that
2501 * we can't use xdr_encode_pages() as written: we need a variant
2502 * of it which would leave room in the 'tail' iovec.
2504 * Both of these changes to the XDR layer would in fact be quite
2505 * minor, but I decided to leave them for a subsequent patch.
2507 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2508 unsigned int pgbase, unsigned int pglen)
2510 struct nfs4_readlink args = {
2511 .fh = NFS_FH(inode),
2516 struct nfs4_readlink_res res;
2517 struct rpc_message msg = {
2518 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2523 return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
2526 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2527 unsigned int pgbase, unsigned int pglen)
2529 struct nfs4_exception exception = { };
2532 err = nfs4_handle_exception(NFS_SERVER(inode),
2533 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2535 } while (exception.retry);
2541 * We will need to arrange for the VFS layer to provide an atomic open.
2542 * Until then, this create/open method is prone to inefficiency and race
2543 * conditions due to the lookup, create, and open VFS calls from sys_open()
2544 * placed on the wire.
2546 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2547 * The file will be opened again in the subsequent VFS open call
2548 * (nfs4_proc_file_open).
2550 * The open for read will just hang around to be used by any process that
2551 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2555 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2556 int flags, struct nameidata *nd)
2558 struct path path = {
2559 .mnt = nd->path.mnt,
2562 struct nfs4_state *state;
2563 struct rpc_cred *cred;
2564 fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE);
2567 cred = rpc_lookup_cred();
2569 status = PTR_ERR(cred);
2572 state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred);
2574 if (IS_ERR(state)) {
2575 status = PTR_ERR(state);
2578 d_add(dentry, igrab(state->inode));
2579 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2580 if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
2581 status = nfs4_intent_set_file(nd, &path, state, fmode);
2583 nfs4_close_sync(&path, state, fmode);
2590 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2592 struct nfs_server *server = NFS_SERVER(dir);
2593 struct nfs_removeargs args = {
2595 .name.len = name->len,
2596 .name.name = name->name,
2597 .bitmask = server->attr_bitmask,
2599 struct nfs_removeres res = {
2602 struct rpc_message msg = {
2603 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2607 int status = -ENOMEM;
2609 res.dir_attr = nfs_alloc_fattr();
2610 if (res.dir_attr == NULL)
2613 status = nfs4_call_sync(server, &msg, &args, &res, 1);
2615 update_changeattr(dir, &res.cinfo);
2616 nfs_post_op_update_inode(dir, res.dir_attr);
2618 nfs_free_fattr(res.dir_attr);
2623 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2625 struct nfs4_exception exception = { };
2628 err = nfs4_handle_exception(NFS_SERVER(dir),
2629 _nfs4_proc_remove(dir, name),
2631 } while (exception.retry);
2635 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2637 struct nfs_server *server = NFS_SERVER(dir);
2638 struct nfs_removeargs *args = msg->rpc_argp;
2639 struct nfs_removeres *res = msg->rpc_resp;
2641 args->bitmask = server->cache_consistency_bitmask;
2642 res->server = server;
2643 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2646 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2648 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2650 nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
2651 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2653 update_changeattr(dir, &res->cinfo);
2654 nfs_post_op_update_inode(dir, res->dir_attr);
2658 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2659 struct inode *new_dir, struct qstr *new_name)
2661 struct nfs_server *server = NFS_SERVER(old_dir);
2662 struct nfs4_rename_arg arg = {
2663 .old_dir = NFS_FH(old_dir),
2664 .new_dir = NFS_FH(new_dir),
2665 .old_name = old_name,
2666 .new_name = new_name,
2667 .bitmask = server->attr_bitmask,
2669 struct nfs4_rename_res res = {
2672 struct rpc_message msg = {
2673 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2677 int status = -ENOMEM;
2679 res.old_fattr = nfs_alloc_fattr();
2680 res.new_fattr = nfs_alloc_fattr();
2681 if (res.old_fattr == NULL || res.new_fattr == NULL)
2684 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2686 update_changeattr(old_dir, &res.old_cinfo);
2687 nfs_post_op_update_inode(old_dir, res.old_fattr);
2688 update_changeattr(new_dir, &res.new_cinfo);
2689 nfs_post_op_update_inode(new_dir, res.new_fattr);
2692 nfs_free_fattr(res.new_fattr);
2693 nfs_free_fattr(res.old_fattr);
2697 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2698 struct inode *new_dir, struct qstr *new_name)
2700 struct nfs4_exception exception = { };
2703 err = nfs4_handle_exception(NFS_SERVER(old_dir),
2704 _nfs4_proc_rename(old_dir, old_name,
2707 } while (exception.retry);
2711 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2713 struct nfs_server *server = NFS_SERVER(inode);
2714 struct nfs4_link_arg arg = {
2715 .fh = NFS_FH(inode),
2716 .dir_fh = NFS_FH(dir),
2718 .bitmask = server->attr_bitmask,
2720 struct nfs4_link_res res = {
2723 struct rpc_message msg = {
2724 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2728 int status = -ENOMEM;
2730 res.fattr = nfs_alloc_fattr();
2731 res.dir_attr = nfs_alloc_fattr();
2732 if (res.fattr == NULL || res.dir_attr == NULL)
2735 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2737 update_changeattr(dir, &res.cinfo);
2738 nfs_post_op_update_inode(dir, res.dir_attr);
2739 nfs_post_op_update_inode(inode, res.fattr);
2742 nfs_free_fattr(res.dir_attr);
2743 nfs_free_fattr(res.fattr);
2747 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2749 struct nfs4_exception exception = { };
2752 err = nfs4_handle_exception(NFS_SERVER(inode),
2753 _nfs4_proc_link(inode, dir, name),
2755 } while (exception.retry);
2759 struct nfs4_createdata {
2760 struct rpc_message msg;
2761 struct nfs4_create_arg arg;
2762 struct nfs4_create_res res;
2764 struct nfs_fattr fattr;
2765 struct nfs_fattr dir_fattr;
2768 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2769 struct qstr *name, struct iattr *sattr, u32 ftype)
2771 struct nfs4_createdata *data;
2773 data = kzalloc(sizeof(*data), GFP_KERNEL);
2775 struct nfs_server *server = NFS_SERVER(dir);
2777 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2778 data->msg.rpc_argp = &data->arg;
2779 data->msg.rpc_resp = &data->res;
2780 data->arg.dir_fh = NFS_FH(dir);
2781 data->arg.server = server;
2782 data->arg.name = name;
2783 data->arg.attrs = sattr;
2784 data->arg.ftype = ftype;
2785 data->arg.bitmask = server->attr_bitmask;
2786 data->res.server = server;
2787 data->res.fh = &data->fh;
2788 data->res.fattr = &data->fattr;
2789 data->res.dir_fattr = &data->dir_fattr;
2790 nfs_fattr_init(data->res.fattr);
2791 nfs_fattr_init(data->res.dir_fattr);
2796 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2798 int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg,
2799 &data->arg, &data->res, 1);
2801 update_changeattr(dir, &data->res.dir_cinfo);
2802 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2803 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2808 static void nfs4_free_createdata(struct nfs4_createdata *data)
2813 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2814 struct page *page, unsigned int len, struct iattr *sattr)
2816 struct nfs4_createdata *data;
2817 int status = -ENAMETOOLONG;
2819 if (len > NFS4_MAXPATHLEN)
2823 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2827 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2828 data->arg.u.symlink.pages = &page;
2829 data->arg.u.symlink.len = len;
2831 status = nfs4_do_create(dir, dentry, data);
2833 nfs4_free_createdata(data);
2838 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2839 struct page *page, unsigned int len, struct iattr *sattr)
2841 struct nfs4_exception exception = { };
2844 err = nfs4_handle_exception(NFS_SERVER(dir),
2845 _nfs4_proc_symlink(dir, dentry, page,
2848 } while (exception.retry);
2852 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2853 struct iattr *sattr)
2855 struct nfs4_createdata *data;
2856 int status = -ENOMEM;
2858 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2862 status = nfs4_do_create(dir, dentry, data);
2864 nfs4_free_createdata(data);
2869 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2870 struct iattr *sattr)
2872 struct nfs4_exception exception = { };
2875 err = nfs4_handle_exception(NFS_SERVER(dir),
2876 _nfs4_proc_mkdir(dir, dentry, sattr),
2878 } while (exception.retry);
2882 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2883 u64 cookie, struct page *page, unsigned int count, int plus)
2885 struct inode *dir = dentry->d_inode;
2886 struct nfs4_readdir_arg args = {
2891 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2893 struct nfs4_readdir_res res;
2894 struct rpc_message msg = {
2895 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2902 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
2903 dentry->d_parent->d_name.name,
2904 dentry->d_name.name,
2905 (unsigned long long)cookie);
2906 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2907 res.pgbase = args.pgbase;
2908 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2910 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2912 nfs_invalidate_atime(dir);
2914 dprintk("%s: returns %d\n", __func__, status);
2918 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2919 u64 cookie, struct page *page, unsigned int count, int plus)
2921 struct nfs4_exception exception = { };
2924 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2925 _nfs4_proc_readdir(dentry, cred, cookie,
2928 } while (exception.retry);
2932 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2933 struct iattr *sattr, dev_t rdev)
2935 struct nfs4_createdata *data;
2936 int mode = sattr->ia_mode;
2937 int status = -ENOMEM;
2939 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2940 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2942 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
2947 data->arg.ftype = NF4FIFO;
2948 else if (S_ISBLK(mode)) {
2949 data->arg.ftype = NF4BLK;
2950 data->arg.u.device.specdata1 = MAJOR(rdev);
2951 data->arg.u.device.specdata2 = MINOR(rdev);
2953 else if (S_ISCHR(mode)) {
2954 data->arg.ftype = NF4CHR;
2955 data->arg.u.device.specdata1 = MAJOR(rdev);
2956 data->arg.u.device.specdata2 = MINOR(rdev);
2959 status = nfs4_do_create(dir, dentry, data);
2961 nfs4_free_createdata(data);
2966 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2967 struct iattr *sattr, dev_t rdev)
2969 struct nfs4_exception exception = { };
2972 err = nfs4_handle_exception(NFS_SERVER(dir),
2973 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2975 } while (exception.retry);
2979 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2980 struct nfs_fsstat *fsstat)
2982 struct nfs4_statfs_arg args = {
2984 .bitmask = server->attr_bitmask,
2986 struct nfs4_statfs_res res = {
2989 struct rpc_message msg = {
2990 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2995 nfs_fattr_init(fsstat->fattr);
2996 return nfs4_call_sync(server, &msg, &args, &res, 0);
2999 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3001 struct nfs4_exception exception = { };
3004 err = nfs4_handle_exception(server,
3005 _nfs4_proc_statfs(server, fhandle, fsstat),
3007 } while (exception.retry);
3011 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3012 struct nfs_fsinfo *fsinfo)
3014 struct nfs4_fsinfo_arg args = {
3016 .bitmask = server->attr_bitmask,
3018 struct nfs4_fsinfo_res res = {
3021 struct rpc_message msg = {
3022 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3027 return nfs4_call_sync(server, &msg, &args, &res, 0);
3030 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3032 struct nfs4_exception exception = { };
3036 err = nfs4_handle_exception(server,
3037 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3039 } while (exception.retry);
3043 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3045 nfs_fattr_init(fsinfo->fattr);
3046 return nfs4_do_fsinfo(server, fhandle, fsinfo);
3049 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3050 struct nfs_pathconf *pathconf)
3052 struct nfs4_pathconf_arg args = {
3054 .bitmask = server->attr_bitmask,
3056 struct nfs4_pathconf_res res = {
3057 .pathconf = pathconf,
3059 struct rpc_message msg = {
3060 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3065 /* None of the pathconf attributes are mandatory to implement */
3066 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3067 memset(pathconf, 0, sizeof(*pathconf));
3071 nfs_fattr_init(pathconf->fattr);
3072 return nfs4_call_sync(server, &msg, &args, &res, 0);
3075 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3076 struct nfs_pathconf *pathconf)
3078 struct nfs4_exception exception = { };
3082 err = nfs4_handle_exception(server,
3083 _nfs4_proc_pathconf(server, fhandle, pathconf),
3085 } while (exception.retry);
3089 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3091 struct nfs_server *server = NFS_SERVER(data->inode);
3093 dprintk("--> %s\n", __func__);
3095 nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
3097 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3098 nfs_restart_rpc(task, server->nfs_client);
3102 nfs_invalidate_atime(data->inode);
3103 if (task->tk_status > 0)
3104 renew_lease(server, data->timestamp);
3108 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3110 data->timestamp = jiffies;
3111 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3114 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3116 struct inode *inode = data->inode;
3118 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3121 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3122 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3125 if (task->tk_status >= 0) {
3126 renew_lease(NFS_SERVER(inode), data->timestamp);
3127 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
3132 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3134 struct nfs_server *server = NFS_SERVER(data->inode);
3136 data->args.bitmask = server->cache_consistency_bitmask;
3137 data->res.server = server;
3138 data->timestamp = jiffies;
3140 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3143 static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3145 struct inode *inode = data->inode;
3147 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3149 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3150 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3153 nfs_refresh_inode(inode, data->res.fattr);
3157 static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
3159 struct nfs_server *server = NFS_SERVER(data->inode);
3161 data->args.bitmask = server->cache_consistency_bitmask;
3162 data->res.server = server;
3163 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3166 struct nfs4_renewdata {
3167 struct nfs_client *client;
3168 unsigned long timestamp;
3172 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3173 * standalone procedure for queueing an asynchronous RENEW.
3175 static void nfs4_renew_release(void *calldata)
3177 struct nfs4_renewdata *data = calldata;
3178 struct nfs_client *clp = data->client;
3180 if (atomic_read(&clp->cl_count) > 1)
3181 nfs4_schedule_state_renewal(clp);
3182 nfs_put_client(clp);
3186 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3188 struct nfs4_renewdata *data = calldata;
3189 struct nfs_client *clp = data->client;
3190 unsigned long timestamp = data->timestamp;
3192 if (task->tk_status < 0) {
3193 /* Unless we're shutting down, schedule state recovery! */
3194 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
3195 nfs4_schedule_state_recovery(clp);
3198 spin_lock(&clp->cl_lock);
3199 if (time_before(clp->cl_last_renewal,timestamp))
3200 clp->cl_last_renewal = timestamp;
3201 spin_unlock(&clp->cl_lock);
3204 static const struct rpc_call_ops nfs4_renew_ops = {
3205 .rpc_call_done = nfs4_renew_done,
3206 .rpc_release = nfs4_renew_release,
3209 int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3211 struct rpc_message msg = {
3212 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3216 struct nfs4_renewdata *data;
3218 if (!atomic_inc_not_zero(&clp->cl_count))
3220 data = kmalloc(sizeof(*data), GFP_KERNEL);
3224 data->timestamp = jiffies;
3225 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3226 &nfs4_renew_ops, data);
3229 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3231 struct rpc_message msg = {
3232 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3236 unsigned long now = jiffies;
3239 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3242 spin_lock(&clp->cl_lock);
3243 if (time_before(clp->cl_last_renewal,now))
3244 clp->cl_last_renewal = now;
3245 spin_unlock(&clp->cl_lock);
3249 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3251 return (server->caps & NFS_CAP_ACLS)
3252 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3253 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3256 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3257 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3260 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3262 static void buf_to_pages(const void *buf, size_t buflen,
3263 struct page **pages, unsigned int *pgbase)
3265 const void *p = buf;
3267 *pgbase = offset_in_page(buf);
3269 while (p < buf + buflen) {
3270 *(pages++) = virt_to_page(p);
3271 p += PAGE_CACHE_SIZE;
3275 struct nfs4_cached_acl {
3281 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3283 struct nfs_inode *nfsi = NFS_I(inode);
3285 spin_lock(&inode->i_lock);
3286 kfree(nfsi->nfs4_acl);
3287 nfsi->nfs4_acl = acl;
3288 spin_unlock(&inode->i_lock);
3291 static void nfs4_zap_acl_attr(struct inode *inode)
3293 nfs4_set_cached_acl(inode, NULL);
3296 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3298 struct nfs_inode *nfsi = NFS_I(inode);
3299 struct nfs4_cached_acl *acl;
3302 spin_lock(&inode->i_lock);
3303 acl = nfsi->nfs4_acl;
3306 if (buf == NULL) /* user is just asking for length */
3308 if (acl->cached == 0)
3310 ret = -ERANGE; /* see getxattr(2) man page */
3311 if (acl->len > buflen)
3313 memcpy(buf, acl->data, acl->len);
3317 spin_unlock(&inode->i_lock);
3321 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
3323 struct nfs4_cached_acl *acl;
3325 if (buf && acl_len <= PAGE_SIZE) {
3326 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3330 memcpy(acl->data, buf, acl_len);
3332 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3339 nfs4_set_cached_acl(inode, acl);
3342 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3344 struct page *pages[NFS4ACL_MAXPAGES];
3345 struct nfs_getaclargs args = {
3346 .fh = NFS_FH(inode),
3350 struct nfs_getaclres res = {
3354 struct rpc_message msg = {
3355 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3359 struct page *localpage = NULL;
3362 if (buflen < PAGE_SIZE) {
3363 /* As long as we're doing a round trip to the server anyway,
3364 * let's be prepared for a page of acl data. */
3365 localpage = alloc_page(GFP_KERNEL);
3366 resp_buf = page_address(localpage);
3367 if (localpage == NULL)
3369 args.acl_pages[0] = localpage;
3370 args.acl_pgbase = 0;
3371 args.acl_len = PAGE_SIZE;
3374 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
3376 ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
3379 if (res.acl_len > args.acl_len)
3380 nfs4_write_cached_acl(inode, NULL, res.acl_len);
3382 nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
3385 if (res.acl_len > buflen)
3388 memcpy(buf, resp_buf, res.acl_len);
3393 __free_page(localpage);
3397 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3399 struct nfs4_exception exception = { };
3402 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3405 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3406 } while (exception.retry);
3410 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3412 struct nfs_server *server = NFS_SERVER(inode);
3415 if (!nfs4_server_supports_acls(server))
3417 ret = nfs_revalidate_inode(server, inode);
3420 ret = nfs4_read_cached_acl(inode, buf, buflen);
3423 return nfs4_get_acl_uncached(inode, buf, buflen);
3426 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3428 struct nfs_server *server = NFS_SERVER(inode);
3429 struct page *pages[NFS4ACL_MAXPAGES];
3430 struct nfs_setaclargs arg = {
3431 .fh = NFS_FH(inode),
3435 struct nfs_setaclres res;
3436 struct rpc_message msg = {
3437 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3443 if (!nfs4_server_supports_acls(server))
3445 nfs_inode_return_delegation(inode);
3446 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3447 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3448 nfs_access_zap_cache(inode);
3449 nfs_zap_acl_cache(inode);
3453 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3455 struct nfs4_exception exception = { };
3458 err = nfs4_handle_exception(NFS_SERVER(inode),
3459 __nfs4_proc_set_acl(inode, buf, buflen),
3461 } while (exception.retry);
3466 _nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs_client *clp, struct nfs4_state *state)
3468 if (!clp || task->tk_status >= 0)
3470 switch(task->tk_status) {
3471 case -NFS4ERR_ADMIN_REVOKED:
3472 case -NFS4ERR_BAD_STATEID:
3473 case -NFS4ERR_OPENMODE:
3476 nfs4_state_mark_reclaim_nograce(clp, state);
3477 goto do_state_recovery;
3478 case -NFS4ERR_STALE_STATEID:
3481 nfs4_state_mark_reclaim_reboot(clp, state);
3482 case -NFS4ERR_STALE_CLIENTID:
3483 case -NFS4ERR_EXPIRED:
3484 goto do_state_recovery;
3485 #if defined(CONFIG_NFS_V4_1)
3486 case -NFS4ERR_BADSESSION:
3487 case -NFS4ERR_BADSLOT:
3488 case -NFS4ERR_BAD_HIGH_SLOT:
3489 case -NFS4ERR_DEADSESSION:
3490 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3491 case -NFS4ERR_SEQ_FALSE_RETRY:
3492 case -NFS4ERR_SEQ_MISORDERED:
3493 dprintk("%s ERROR %d, Reset session\n", __func__,
3495 nfs4_schedule_state_recovery(clp);
3496 task->tk_status = 0;
3498 #endif /* CONFIG_NFS_V4_1 */
3499 case -NFS4ERR_DELAY:
3501 nfs_inc_server_stats(server, NFSIOS_DELAY);
3502 case -NFS4ERR_GRACE:
3504 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3505 task->tk_status = 0;
3507 case -NFS4ERR_OLD_STATEID:
3508 task->tk_status = 0;
3511 task->tk_status = nfs4_map_errors(task->tk_status);
3514 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3515 nfs4_schedule_state_recovery(clp);
3516 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3517 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3518 task->tk_status = 0;
3523 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3525 return _nfs4_async_handle_error(task, server, server->nfs_client, state);
3528 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3529 unsigned short port, struct rpc_cred *cred,
3530 struct nfs4_setclientid_res *res)
3532 nfs4_verifier sc_verifier;
3533 struct nfs4_setclientid setclientid = {
3534 .sc_verifier = &sc_verifier,
3537 struct rpc_message msg = {
3538 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3539 .rpc_argp = &setclientid,
3547 p = (__be32*)sc_verifier.data;
3548 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3549 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3552 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3553 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3555 rpc_peeraddr2str(clp->cl_rpcclient,
3557 rpc_peeraddr2str(clp->cl_rpcclient,
3559 clp->cl_rpcclient->cl_auth->au_ops->au_name,
3560 clp->cl_id_uniquifier);
3561 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
3562 sizeof(setclientid.sc_netid),
3563 rpc_peeraddr2str(clp->cl_rpcclient,
3564 RPC_DISPLAY_NETID));
3565 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3566 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3567 clp->cl_ipaddr, port >> 8, port & 255);
3569 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3570 if (status != -NFS4ERR_CLID_INUSE)
3575 ssleep(clp->cl_lease_time + 1);
3577 if (++clp->cl_id_uniquifier == 0)
3583 static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3584 struct nfs4_setclientid_res *arg,
3585 struct rpc_cred *cred)
3587 struct nfs_fsinfo fsinfo;
3588 struct rpc_message msg = {
3589 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3591 .rpc_resp = &fsinfo,
3598 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3600 spin_lock(&clp->cl_lock);
3601 clp->cl_lease_time = fsinfo.lease_time * HZ;
3602 clp->cl_last_renewal = now;
3603 spin_unlock(&clp->cl_lock);
3608 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3609 struct nfs4_setclientid_res *arg,
3610 struct rpc_cred *cred)
3615 err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
3619 case -NFS4ERR_RESOURCE:
3620 /* The IBM lawyers misread another document! */
3621 case -NFS4ERR_DELAY:
3623 err = nfs4_delay(clp->cl_rpcclient, &timeout);
3629 struct nfs4_delegreturndata {
3630 struct nfs4_delegreturnargs args;
3631 struct nfs4_delegreturnres res;
3633 nfs4_stateid stateid;
3634 unsigned long timestamp;
3635 struct nfs_fattr fattr;
3639 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3641 struct nfs4_delegreturndata *data = calldata;
3643 nfs4_sequence_done(data->res.server, &data->res.seq_res,
3646 switch (task->tk_status) {
3647 case -NFS4ERR_STALE_STATEID:
3648 case -NFS4ERR_EXPIRED:
3650 renew_lease(data->res.server, data->timestamp);
3653 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3655 nfs_restart_rpc(task, data->res.server->nfs_client);
3659 data->rpc_status = task->tk_status;
3662 static void nfs4_delegreturn_release(void *calldata)
3667 #if defined(CONFIG_NFS_V4_1)
3668 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3670 struct nfs4_delegreturndata *d_data;
3672 d_data = (struct nfs4_delegreturndata *)data;
3674 if (nfs4_setup_sequence(d_data->res.server->nfs_client,
3675 &d_data->args.seq_args,
3676 &d_data->res.seq_res, 1, task))
3678 rpc_call_start(task);
3680 #endif /* CONFIG_NFS_V4_1 */
3682 static const struct rpc_call_ops nfs4_delegreturn_ops = {
3683 #if defined(CONFIG_NFS_V4_1)
3684 .rpc_call_prepare = nfs4_delegreturn_prepare,
3685 #endif /* CONFIG_NFS_V4_1 */
3686 .rpc_call_done = nfs4_delegreturn_done,
3687 .rpc_release = nfs4_delegreturn_release,
3690 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3692 struct nfs4_delegreturndata *data;
3693 struct nfs_server *server = NFS_SERVER(inode);
3694 struct rpc_task *task;
3695 struct rpc_message msg = {
3696 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
3699 struct rpc_task_setup task_setup_data = {
3700 .rpc_client = server->client,
3701 .rpc_message = &msg,
3702 .callback_ops = &nfs4_delegreturn_ops,
3703 .flags = RPC_TASK_ASYNC,
3707 data = kzalloc(sizeof(*data), GFP_KERNEL);
3710 data->args.fhandle = &data->fh;
3711 data->args.stateid = &data->stateid;
3712 data->args.bitmask = server->attr_bitmask;
3713 nfs_copy_fh(&data->fh, NFS_FH(inode));
3714 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3715 data->res.fattr = &data->fattr;
3716 data->res.server = server;
3717 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3718 nfs_fattr_init(data->res.fattr);
3719 data->timestamp = jiffies;
3720 data->rpc_status = 0;
3722 task_setup_data.callback_data = data;
3723 msg.rpc_argp = &data->args,
3724 msg.rpc_resp = &data->res,
3725 task = rpc_run_task(&task_setup_data);
3727 return PTR_ERR(task);
3730 status = nfs4_wait_for_completion_rpc_task(task);
3733 status = data->rpc_status;
3736 nfs_refresh_inode(inode, &data->fattr);
3742 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3744 struct nfs_server *server = NFS_SERVER(inode);
3745 struct nfs4_exception exception = { };
3748 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
3750 case -NFS4ERR_STALE_STATEID:
3751 case -NFS4ERR_EXPIRED:
3755 err = nfs4_handle_exception(server, err, &exception);
3756 } while (exception.retry);
3760 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3761 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3764 * sleep, with exponential backoff, and retry the LOCK operation.
3766 static unsigned long
3767 nfs4_set_lock_task_retry(unsigned long timeout)
3769 schedule_timeout_killable(timeout);
3771 if (timeout > NFS4_LOCK_MAXTIMEOUT)
3772 return NFS4_LOCK_MAXTIMEOUT;
3776 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3778 struct inode *inode = state->inode;
3779 struct nfs_server *server = NFS_SERVER(inode);
3780 struct nfs_client *clp = server->nfs_client;
3781 struct nfs_lockt_args arg = {
3782 .fh = NFS_FH(inode),
3785 struct nfs_lockt_res res = {
3788 struct rpc_message msg = {
3789 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
3792 .rpc_cred = state->owner->so_cred,
3794 struct nfs4_lock_state *lsp;
3797 arg.lock_owner.clientid = clp->cl_clientid;
3798 status = nfs4_set_lock_state(state, request);
3801 lsp = request->fl_u.nfs4_fl.owner;
3802 arg.lock_owner.id = lsp->ls_id.id;
3803 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
3806 request->fl_type = F_UNLCK;
3808 case -NFS4ERR_DENIED:
3811 request->fl_ops->fl_release_private(request);
3816 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3818 struct nfs4_exception exception = { };
3822 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3823 _nfs4_proc_getlk(state, cmd, request),
3825 } while (exception.retry);
3829 static int do_vfs_lock(struct file *file, struct file_lock *fl)
3832 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3834 res = posix_lock_file_wait(file, fl);
3837 res = flock_lock_file_wait(file, fl);
3845 struct nfs4_unlockdata {
3846 struct nfs_locku_args arg;
3847 struct nfs_locku_res res;
3848 struct nfs4_lock_state *lsp;
3849 struct nfs_open_context *ctx;
3850 struct file_lock fl;
3851 const struct nfs_server *server;
3852 unsigned long timestamp;
3855 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3856 struct nfs_open_context *ctx,
3857 struct nfs4_lock_state *lsp,
3858 struct nfs_seqid *seqid)
3860 struct nfs4_unlockdata *p;
3861 struct inode *inode = lsp->ls_state->inode;
3863 p = kzalloc(sizeof(*p), GFP_KERNEL);
3866 p->arg.fh = NFS_FH(inode);
3868 p->arg.seqid = seqid;
3869 p->res.seqid = seqid;
3870 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3871 p->arg.stateid = &lsp->ls_stateid;
3873 atomic_inc(&lsp->ls_count);
3874 /* Ensure we don't close file until we're done freeing locks! */
3875 p->ctx = get_nfs_open_context(ctx);
3876 memcpy(&p->fl, fl, sizeof(p->fl));
3877 p->server = NFS_SERVER(inode);
3881 static void nfs4_locku_release_calldata(void *data)
3883 struct nfs4_unlockdata *calldata = data;
3884 nfs_free_seqid(calldata->arg.seqid);
3885 nfs4_put_lock_state(calldata->lsp);
3886 put_nfs_open_context(calldata->ctx);
3890 static void nfs4_locku_done(struct rpc_task *task, void *data)
3892 struct nfs4_unlockdata *calldata = data;
3894 nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
3896 if (RPC_ASSASSINATED(task))
3898 switch (task->tk_status) {
3900 memcpy(calldata->lsp->ls_stateid.data,
3901 calldata->res.stateid.data,
3902 sizeof(calldata->lsp->ls_stateid.data));
3903 renew_lease(calldata->server, calldata->timestamp);
3905 case -NFS4ERR_BAD_STATEID:
3906 case -NFS4ERR_OLD_STATEID:
3907 case -NFS4ERR_STALE_STATEID:
3908 case -NFS4ERR_EXPIRED:
3911 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
3912 nfs_restart_rpc(task,
3913 calldata->server->nfs_client);
3917 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
3919 struct nfs4_unlockdata *calldata = data;
3921 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
3923 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
3924 /* Note: exit _without_ running nfs4_locku_done */
3925 task->tk_action = NULL;
3928 calldata->timestamp = jiffies;
3929 if (nfs4_setup_sequence(calldata->server->nfs_client,
3930 &calldata->arg.seq_args,
3931 &calldata->res.seq_res, 1, task))
3933 rpc_call_start(task);
3936 static const struct rpc_call_ops nfs4_locku_ops = {
3937 .rpc_call_prepare = nfs4_locku_prepare,
3938 .rpc_call_done = nfs4_locku_done,
3939 .rpc_release = nfs4_locku_release_calldata,
3942 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3943 struct nfs_open_context *ctx,
3944 struct nfs4_lock_state *lsp,
3945 struct nfs_seqid *seqid)
3947 struct nfs4_unlockdata *data;
3948 struct rpc_message msg = {
3949 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
3950 .rpc_cred = ctx->cred,
3952 struct rpc_task_setup task_setup_data = {
3953 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
3954 .rpc_message = &msg,
3955 .callback_ops = &nfs4_locku_ops,
3956 .workqueue = nfsiod_workqueue,
3957 .flags = RPC_TASK_ASYNC,
3960 /* Ensure this is an unlock - when canceling a lock, the
3961 * canceled lock is passed in, and it won't be an unlock.
3963 fl->fl_type = F_UNLCK;
3965 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
3967 nfs_free_seqid(seqid);
3968 return ERR_PTR(-ENOMEM);
3971 msg.rpc_argp = &data->arg,
3972 msg.rpc_resp = &data->res,
3973 task_setup_data.callback_data = data;
3974 return rpc_run_task(&task_setup_data);
3977 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
3979 struct nfs_inode *nfsi = NFS_I(state->inode);
3980 struct nfs_seqid *seqid;
3981 struct nfs4_lock_state *lsp;
3982 struct rpc_task *task;
3984 unsigned char fl_flags = request->fl_flags;
3986 status = nfs4_set_lock_state(state, request);
3987 /* Unlock _before_ we do the RPC call */
3988 request->fl_flags |= FL_EXISTS;
3989 down_read(&nfsi->rwsem);
3990 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
3991 up_read(&nfsi->rwsem);
3994 up_read(&nfsi->rwsem);
3997 /* Is this a delegated lock? */
3998 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4000 lsp = request->fl_u.nfs4_fl.owner;
4001 seqid = nfs_alloc_seqid(&lsp->ls_seqid);
4005 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4006 status = PTR_ERR(task);
4009 status = nfs4_wait_for_completion_rpc_task(task);
4012 request->fl_flags = fl_flags;
4016 struct nfs4_lockdata {
4017 struct nfs_lock_args arg;
4018 struct nfs_lock_res res;
4019 struct nfs4_lock_state *lsp;
4020 struct nfs_open_context *ctx;
4021 struct file_lock fl;
4022 unsigned long timestamp;
4025 struct nfs_server *server;
4028 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4029 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp)
4031 struct nfs4_lockdata *p;
4032 struct inode *inode = lsp->ls_state->inode;
4033 struct nfs_server *server = NFS_SERVER(inode);
4035 p = kzalloc(sizeof(*p), GFP_KERNEL);
4039 p->arg.fh = NFS_FH(inode);
4041 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid);
4042 if (p->arg.open_seqid == NULL)
4044 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
4045 if (p->arg.lock_seqid == NULL)
4046 goto out_free_seqid;
4047 p->arg.lock_stateid = &lsp->ls_stateid;
4048 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4049 p->arg.lock_owner.id = lsp->ls_id.id;
4050 p->res.lock_seqid = p->arg.lock_seqid;
4051 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4054 atomic_inc(&lsp->ls_count);
4055 p->ctx = get_nfs_open_context(ctx);
4056 memcpy(&p->fl, fl, sizeof(p->fl));
4059 nfs_free_seqid(p->arg.open_seqid);
4065 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4067 struct nfs4_lockdata *data = calldata;
4068 struct nfs4_state *state = data->lsp->ls_state;
4070 dprintk("%s: begin!\n", __func__);
4071 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4073 /* Do we need to do an open_to_lock_owner? */
4074 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4075 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4077 data->arg.open_stateid = &state->stateid;
4078 data->arg.new_lock_owner = 1;
4079 data->res.open_seqid = data->arg.open_seqid;
4081 data->arg.new_lock_owner = 0;
4082 data->timestamp = jiffies;
4083 if (nfs4_setup_sequence(data->server->nfs_client, &data->arg.seq_args,
4084 &data->res.seq_res, 1, task))
4086 rpc_call_start(task);
4087 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4090 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4092 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4093 nfs4_lock_prepare(task, calldata);
4096 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4098 struct nfs4_lockdata *data = calldata;
4100 dprintk("%s: begin!\n", __func__);
4102 nfs4_sequence_done(data->server, &data->res.seq_res,
4105 data->rpc_status = task->tk_status;
4106 if (RPC_ASSASSINATED(task))
4108 if (data->arg.new_lock_owner != 0) {
4109 if (data->rpc_status == 0)
4110 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4114 if (data->rpc_status == 0) {
4115 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
4116 sizeof(data->lsp->ls_stateid.data));
4117 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4118 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
4121 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4124 static void nfs4_lock_release(void *calldata)
4126 struct nfs4_lockdata *data = calldata;
4128 dprintk("%s: begin!\n", __func__);
4129 nfs_free_seqid(data->arg.open_seqid);
4130 if (data->cancelled != 0) {
4131 struct rpc_task *task;
4132 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4133 data->arg.lock_seqid);
4136 dprintk("%s: cancelling lock!\n", __func__);
4138 nfs_free_seqid(data->arg.lock_seqid);
4139 nfs4_put_lock_state(data->lsp);
4140 put_nfs_open_context(data->ctx);
4142 dprintk("%s: done!\n", __func__);
4145 static const struct rpc_call_ops nfs4_lock_ops = {
4146 .rpc_call_prepare = nfs4_lock_prepare,
4147 .rpc_call_done = nfs4_lock_done,
4148 .rpc_release = nfs4_lock_release,
4151 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4152 .rpc_call_prepare = nfs4_recover_lock_prepare,
4153 .rpc_call_done = nfs4_lock_done,
4154 .rpc_release = nfs4_lock_release,
4157 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4159 struct nfs_client *clp = server->nfs_client;
4160 struct nfs4_state *state = lsp->ls_state;
4163 case -NFS4ERR_ADMIN_REVOKED:
4164 case -NFS4ERR_BAD_STATEID:
4165 case -NFS4ERR_EXPIRED:
4166 if (new_lock_owner != 0 ||
4167 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4168 nfs4_state_mark_reclaim_nograce(clp, state);
4169 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4171 case -NFS4ERR_STALE_STATEID:
4172 if (new_lock_owner != 0 ||
4173 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4174 nfs4_state_mark_reclaim_reboot(clp, state);
4175 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4179 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4181 struct nfs4_lockdata *data;
4182 struct rpc_task *task;
4183 struct rpc_message msg = {
4184 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4185 .rpc_cred = state->owner->so_cred,
4187 struct rpc_task_setup task_setup_data = {
4188 .rpc_client = NFS_CLIENT(state->inode),
4189 .rpc_message = &msg,
4190 .callback_ops = &nfs4_lock_ops,
4191 .workqueue = nfsiod_workqueue,
4192 .flags = RPC_TASK_ASYNC,
4196 dprintk("%s: begin!\n", __func__);
4197 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4198 fl->fl_u.nfs4_fl.owner);
4202 data->arg.block = 1;
4203 if (recovery_type > NFS_LOCK_NEW) {
4204 if (recovery_type == NFS_LOCK_RECLAIM)
4205 data->arg.reclaim = NFS_LOCK_RECLAIM;
4206 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4208 msg.rpc_argp = &data->arg,
4209 msg.rpc_resp = &data->res,
4210 task_setup_data.callback_data = data;
4211 task = rpc_run_task(&task_setup_data);
4213 return PTR_ERR(task);
4214 ret = nfs4_wait_for_completion_rpc_task(task);
4216 ret = data->rpc_status;
4218 nfs4_handle_setlk_error(data->server, data->lsp,
4219 data->arg.new_lock_owner, ret);
4221 data->cancelled = 1;
4223 dprintk("%s: done, ret = %d!\n", __func__, ret);
4227 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4229 struct nfs_server *server = NFS_SERVER(state->inode);
4230 struct nfs4_exception exception = { };
4234 /* Cache the lock if possible... */
4235 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4237 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4238 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
4240 nfs4_handle_exception(server, err, &exception);
4241 } while (exception.retry);
4245 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4247 struct nfs_server *server = NFS_SERVER(state->inode);
4248 struct nfs4_exception exception = { };
4251 err = nfs4_set_lock_state(state, request);
4255 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4257 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4261 case -NFS4ERR_GRACE:
4262 case -NFS4ERR_DELAY:
4264 nfs4_handle_exception(server, err, &exception);
4267 } while (exception.retry);
4272 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4274 struct nfs_inode *nfsi = NFS_I(state->inode);
4275 unsigned char fl_flags = request->fl_flags;
4276 int status = -ENOLCK;
4278 if ((fl_flags & FL_POSIX) &&
4279 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4281 /* Is this a delegated open? */
4282 status = nfs4_set_lock_state(state, request);
4285 request->fl_flags |= FL_ACCESS;
4286 status = do_vfs_lock(request->fl_file, request);
4289 down_read(&nfsi->rwsem);
4290 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4291 /* Yes: cache locks! */
4292 /* ...but avoid races with delegation recall... */
4293 request->fl_flags = fl_flags & ~FL_SLEEP;
4294 status = do_vfs_lock(request->fl_file, request);
4297 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4300 /* Note: we always want to sleep here! */
4301 request->fl_flags = fl_flags | FL_SLEEP;
4302 if (do_vfs_lock(request->fl_file, request) < 0)
4303 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
4305 up_read(&nfsi->rwsem);
4307 request->fl_flags = fl_flags;
4311 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4313 struct nfs4_exception exception = { };
4317 err = _nfs4_proc_setlk(state, cmd, request);
4318 if (err == -NFS4ERR_DENIED)
4320 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4322 } while (exception.retry);
4327 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4329 struct nfs_open_context *ctx;
4330 struct nfs4_state *state;
4331 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4334 /* verify open state */
4335 ctx = nfs_file_open_context(filp);
4338 if (request->fl_start < 0 || request->fl_end < 0)
4341 if (IS_GETLK(cmd)) {
4343 return nfs4_proc_getlk(state, F_GETLK, request);
4347 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4350 if (request->fl_type == F_UNLCK) {
4352 return nfs4_proc_unlck(state, cmd, request);
4359 status = nfs4_proc_setlk(state, cmd, request);
4360 if ((status != -EAGAIN) || IS_SETLK(cmd))
4362 timeout = nfs4_set_lock_task_retry(timeout);
4363 status = -ERESTARTSYS;
4366 } while(status < 0);
4370 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4372 struct nfs_server *server = NFS_SERVER(state->inode);
4373 struct nfs4_exception exception = { };
4376 err = nfs4_set_lock_state(state, fl);
4380 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4383 printk(KERN_ERR "%s: unhandled error %d.\n",
4388 case -NFS4ERR_EXPIRED:
4389 case -NFS4ERR_STALE_CLIENTID:
4390 case -NFS4ERR_STALE_STATEID:
4391 case -NFS4ERR_BADSESSION:
4392 case -NFS4ERR_BADSLOT:
4393 case -NFS4ERR_BAD_HIGH_SLOT:
4394 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4395 case -NFS4ERR_DEADSESSION:
4396 nfs4_schedule_state_recovery(server->nfs_client);
4400 * The show must go on: exit, but mark the
4401 * stateid as needing recovery.
4403 case -NFS4ERR_ADMIN_REVOKED:
4404 case -NFS4ERR_BAD_STATEID:
4405 case -NFS4ERR_OPENMODE:
4406 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
4410 case -NFS4ERR_DENIED:
4411 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4414 case -NFS4ERR_DELAY:
4418 err = nfs4_handle_exception(server, err, &exception);
4419 } while (exception.retry);
4424 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4426 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
4427 size_t buflen, int flags)
4429 struct inode *inode = dentry->d_inode;
4431 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4434 return nfs4_proc_set_acl(inode, buf, buflen);
4437 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4438 * and that's what we'll do for e.g. user attributes that haven't been set.
4439 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4440 * attributes in kernel-managed attribute namespaces. */
4441 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
4444 struct inode *inode = dentry->d_inode;
4446 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4449 return nfs4_proc_get_acl(inode, buf, buflen);
4452 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
4454 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
4456 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4458 if (buf && buflen < len)
4461 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
4465 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4467 if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
4468 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4469 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
4472 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4473 NFS_ATTR_FATTR_NLINK;
4474 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4478 int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4479 struct nfs4_fs_locations *fs_locations, struct page *page)
4481 struct nfs_server *server = NFS_SERVER(dir);
4483 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
4484 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
4486 struct nfs4_fs_locations_arg args = {
4487 .dir_fh = NFS_FH(dir),
4492 struct nfs4_fs_locations_res res = {
4493 .fs_locations = fs_locations,
4495 struct rpc_message msg = {
4496 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
4502 dprintk("%s: start\n", __func__);
4503 nfs_fattr_init(&fs_locations->fattr);
4504 fs_locations->server = server;
4505 fs_locations->nlocations = 0;
4506 status = nfs4_call_sync(server, &msg, &args, &res, 0);
4507 nfs_fixup_referral_attributes(&fs_locations->fattr);
4508 dprintk("%s: returned status = %d\n", __func__, status);
4512 #ifdef CONFIG_NFS_V4_1
4514 * nfs4_proc_exchange_id()
4516 * Since the clientid has expired, all compounds using sessions
4517 * associated with the stale clientid will be returning
4518 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4519 * be in some phase of session reset.
4521 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4523 nfs4_verifier verifier;
4524 struct nfs41_exchange_id_args args = {
4526 .flags = clp->cl_exchange_flags,
4528 struct nfs41_exchange_id_res res = {
4532 struct rpc_message msg = {
4533 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
4540 dprintk("--> %s\n", __func__);
4541 BUG_ON(clp == NULL);
4543 /* Remove server-only flags */
4544 args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
4546 p = (u32 *)verifier.data;
4547 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4548 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4549 args.verifier = &verifier;
4552 args.id_len = scnprintf(args.id, sizeof(args.id),
4555 rpc_peeraddr2str(clp->cl_rpcclient,
4557 clp->cl_id_uniquifier);
4559 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4561 if (status != -NFS4ERR_CLID_INUSE)
4567 if (++clp->cl_id_uniquifier == 0)
4571 dprintk("<-- %s status= %d\n", __func__, status);
4575 struct nfs4_get_lease_time_data {
4576 struct nfs4_get_lease_time_args *args;
4577 struct nfs4_get_lease_time_res *res;
4578 struct nfs_client *clp;
4581 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4585 struct nfs4_get_lease_time_data *data =
4586 (struct nfs4_get_lease_time_data *)calldata;
4588 dprintk("--> %s\n", __func__);
4589 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4590 /* just setup sequence, do not trigger session recovery
4591 since we're invoked within one */
4592 ret = nfs41_setup_sequence(data->clp->cl_session,
4593 &data->args->la_seq_args,
4594 &data->res->lr_seq_res, 0, task);
4596 BUG_ON(ret == -EAGAIN);
4597 rpc_call_start(task);
4598 dprintk("<-- %s\n", __func__);
4602 * Called from nfs4_state_manager thread for session setup, so don't recover
4603 * from sequence operation or clientid errors.
4605 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4607 struct nfs4_get_lease_time_data *data =
4608 (struct nfs4_get_lease_time_data *)calldata;
4610 dprintk("--> %s\n", __func__);
4611 nfs41_sequence_done(data->clp, &data->res->lr_seq_res, task->tk_status);
4612 switch (task->tk_status) {
4613 case -NFS4ERR_DELAY:
4614 case -NFS4ERR_GRACE:
4616 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4617 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4618 task->tk_status = 0;
4619 nfs_restart_rpc(task, data->clp);
4622 dprintk("<-- %s\n", __func__);
4625 struct rpc_call_ops nfs4_get_lease_time_ops = {
4626 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4627 .rpc_call_done = nfs4_get_lease_time_done,
4630 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4632 struct rpc_task *task;
4633 struct nfs4_get_lease_time_args args;
4634 struct nfs4_get_lease_time_res res = {
4635 .lr_fsinfo = fsinfo,
4637 struct nfs4_get_lease_time_data data = {
4642 struct rpc_message msg = {
4643 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
4647 struct rpc_task_setup task_setup = {
4648 .rpc_client = clp->cl_rpcclient,
4649 .rpc_message = &msg,
4650 .callback_ops = &nfs4_get_lease_time_ops,
4651 .callback_data = &data
4655 res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4656 dprintk("--> %s\n", __func__);
4657 task = rpc_run_task(&task_setup);
4660 status = PTR_ERR(task);
4662 status = task->tk_status;
4665 dprintk("<-- %s return %d\n", __func__, status);
4671 * Reset a slot table
4673 static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4676 struct nfs4_slot *new = NULL;
4680 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4681 max_reqs, tbl->max_slots);
4683 /* Does the newly negotiated max_reqs match the existing slot table? */
4684 if (max_reqs != tbl->max_slots) {
4686 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4693 spin_lock(&tbl->slot_tbl_lock);
4696 tbl->max_slots = max_reqs;
4698 for (i = 0; i < tbl->max_slots; ++i)
4699 tbl->slots[i].seq_nr = ivalue;
4700 spin_unlock(&tbl->slot_tbl_lock);
4701 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4702 tbl, tbl->slots, tbl->max_slots);
4704 dprintk("<-- %s: return %d\n", __func__, ret);
4709 * Reset the forechannel and backchannel slot tables
4711 static int nfs4_reset_slot_tables(struct nfs4_session *session)
4715 status = nfs4_reset_slot_table(&session->fc_slot_table,
4716 session->fc_attrs.max_reqs, 1);
4720 status = nfs4_reset_slot_table(&session->bc_slot_table,
4721 session->bc_attrs.max_reqs, 0);
4725 /* Destroy the slot table */
4726 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4728 if (session->fc_slot_table.slots != NULL) {
4729 kfree(session->fc_slot_table.slots);
4730 session->fc_slot_table.slots = NULL;
4732 if (session->bc_slot_table.slots != NULL) {
4733 kfree(session->bc_slot_table.slots);
4734 session->bc_slot_table.slots = NULL;
4740 * Initialize slot table
4742 static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4743 int max_slots, int ivalue)
4745 struct nfs4_slot *slot;
4748 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
4750 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4752 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL);
4757 spin_lock(&tbl->slot_tbl_lock);
4758 tbl->max_slots = max_slots;
4760 tbl->highest_used_slotid = -1; /* no slot is currently used */
4761 spin_unlock(&tbl->slot_tbl_lock);
4762 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4763 tbl, tbl->slots, tbl->max_slots);
4765 dprintk("<-- %s: return %d\n", __func__, ret);
4770 * Initialize the forechannel and backchannel tables
4772 static int nfs4_init_slot_tables(struct nfs4_session *session)
4774 struct nfs4_slot_table *tbl;
4777 tbl = &session->fc_slot_table;
4778 if (tbl->slots == NULL) {
4779 status = nfs4_init_slot_table(tbl,
4780 session->fc_attrs.max_reqs, 1);
4785 tbl = &session->bc_slot_table;
4786 if (tbl->slots == NULL) {
4787 status = nfs4_init_slot_table(tbl,
4788 session->bc_attrs.max_reqs, 0);
4790 nfs4_destroy_slot_tables(session);
4796 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4798 struct nfs4_session *session;
4799 struct nfs4_slot_table *tbl;
4801 session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL);
4806 * The create session reply races with the server back
4807 * channel probe. Mark the client NFS_CS_SESSION_INITING
4808 * so that the client back channel can find the
4811 clp->cl_cons_state = NFS_CS_SESSION_INITING;
4812 init_completion(&session->complete);
4814 tbl = &session->fc_slot_table;
4815 tbl->highest_used_slotid = -1;
4816 spin_lock_init(&tbl->slot_tbl_lock);
4817 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
4819 tbl = &session->bc_slot_table;
4820 tbl->highest_used_slotid = -1;
4821 spin_lock_init(&tbl->slot_tbl_lock);
4822 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
4828 void nfs4_destroy_session(struct nfs4_session *session)
4830 nfs4_proc_destroy_session(session);
4831 dprintk("%s Destroy backchannel for xprt %p\n",
4832 __func__, session->clp->cl_rpcclient->cl_xprt);
4833 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
4834 NFS41_BC_MIN_CALLBACKS);
4835 nfs4_destroy_slot_tables(session);
4840 * Initialize the values to be used by the client in CREATE_SESSION
4841 * If nfs4_init_session set the fore channel request and response sizes,
4844 * Set the back channel max_resp_sz_cached to zero to force the client to
4845 * always set csa_cachethis to FALSE because the current implementation
4846 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4848 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4850 struct nfs4_session *session = args->client->cl_session;
4851 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
4852 mxresp_sz = session->fc_attrs.max_resp_sz;
4855 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
4857 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
4858 /* Fore channel attributes */
4859 args->fc_attrs.headerpadsz = 0;
4860 args->fc_attrs.max_rqst_sz = mxrqst_sz;
4861 args->fc_attrs.max_resp_sz = mxresp_sz;
4862 args->fc_attrs.max_ops = NFS4_MAX_OPS;
4863 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
4865 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4866 "max_ops=%u max_reqs=%u\n",
4868 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
4869 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
4871 /* Back channel attributes */
4872 args->bc_attrs.headerpadsz = 0;
4873 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
4874 args->bc_attrs.max_resp_sz = PAGE_SIZE;
4875 args->bc_attrs.max_resp_sz_cached = 0;
4876 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
4877 args->bc_attrs.max_reqs = 1;
4879 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4880 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4882 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
4883 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
4884 args->bc_attrs.max_reqs);
4887 static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd)
4891 printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. "
4892 "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd);
4896 #define _verify_fore_channel_attr(_name_) \
4897 _verify_channel_attr("fore", #_name_, \
4898 args->fc_attrs._name_, \
4899 session->fc_attrs._name_)
4901 #define _verify_back_channel_attr(_name_) \
4902 _verify_channel_attr("back", #_name_, \
4903 args->bc_attrs._name_, \
4904 session->bc_attrs._name_)
4907 * The server is not allowed to increase the fore channel header pad size,
4908 * maximum response size, or maximum number of operations.
4910 * The back channel attributes are only negotiatied down: We send what the
4911 * (back channel) server insists upon.
4913 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
4914 struct nfs4_session *session)
4918 ret |= _verify_fore_channel_attr(headerpadsz);
4919 ret |= _verify_fore_channel_attr(max_resp_sz);
4920 ret |= _verify_fore_channel_attr(max_ops);
4922 ret |= _verify_back_channel_attr(headerpadsz);
4923 ret |= _verify_back_channel_attr(max_rqst_sz);
4924 ret |= _verify_back_channel_attr(max_resp_sz);
4925 ret |= _verify_back_channel_attr(max_resp_sz_cached);
4926 ret |= _verify_back_channel_attr(max_ops);
4927 ret |= _verify_back_channel_attr(max_reqs);
4932 static int _nfs4_proc_create_session(struct nfs_client *clp)
4934 struct nfs4_session *session = clp->cl_session;
4935 struct nfs41_create_session_args args = {
4937 .cb_program = NFS4_CALLBACK,
4939 struct nfs41_create_session_res res = {
4942 struct rpc_message msg = {
4943 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
4949 nfs4_init_channel_attrs(&args);
4950 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
4952 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
4955 /* Verify the session's negotiated channel_attrs values */
4956 status = nfs4_verify_channel_attrs(&args, session);
4958 /* Increment the clientid slot sequence id */
4966 * Issues a CREATE_SESSION operation to the server.
4967 * It is the responsibility of the caller to verify the session is
4968 * expired before calling this routine.
4970 int nfs4_proc_create_session(struct nfs_client *clp)
4974 struct nfs4_session *session = clp->cl_session;
4976 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
4978 status = _nfs4_proc_create_session(clp);
4982 /* Init and reset the fore channel */
4983 status = nfs4_init_slot_tables(session);
4984 dprintk("slot table initialization returned %d\n", status);
4987 status = nfs4_reset_slot_tables(session);
4988 dprintk("slot table reset returned %d\n", status);
4992 ptr = (unsigned *)&session->sess_id.data[0];
4993 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
4994 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
4996 dprintk("<-- %s\n", __func__);
5001 * Issue the over-the-wire RPC DESTROY_SESSION.
5002 * The caller must serialize access to this routine.
5004 int nfs4_proc_destroy_session(struct nfs4_session *session)
5007 struct rpc_message msg;
5009 dprintk("--> nfs4_proc_destroy_session\n");
5011 /* session is still being setup */
5012 if (session->clp->cl_cons_state != NFS_CS_READY)
5015 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
5016 msg.rpc_argp = session;
5017 msg.rpc_resp = NULL;
5018 msg.rpc_cred = NULL;
5019 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
5023 "Got error %d from the server on DESTROY_SESSION. "
5024 "Session has been destroyed regardless...\n", status);
5026 dprintk("<-- nfs4_proc_destroy_session\n");
5030 int nfs4_init_session(struct nfs_server *server)
5032 struct nfs_client *clp = server->nfs_client;
5033 struct nfs4_session *session;
5034 unsigned int rsize, wsize;
5037 if (!nfs4_has_session(clp))
5040 rsize = server->rsize;
5042 rsize = NFS_MAX_FILE_IO_SIZE;
5043 wsize = server->wsize;
5045 wsize = NFS_MAX_FILE_IO_SIZE;
5047 session = clp->cl_session;
5048 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5049 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5051 ret = nfs4_recover_expired_lease(server);
5053 ret = nfs4_check_client_ready(clp);
5058 * Renew the cl_session lease.
5060 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5062 struct nfs4_sequence_args args;
5063 struct nfs4_sequence_res res;
5065 struct rpc_message msg = {
5066 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5072 args.sa_cache_this = 0;
5074 return nfs4_call_sync_sequence(clp, clp->cl_rpcclient, &msg, &args,
5075 &res, args.sa_cache_this, 1);
5078 static void nfs41_sequence_release(void *data)
5080 struct nfs_client *clp = (struct nfs_client *)data;
5082 if (atomic_read(&clp->cl_count) > 1)
5083 nfs4_schedule_state_renewal(clp);
5084 nfs_put_client(clp);
5087 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5089 struct nfs_client *clp = (struct nfs_client *)data;
5091 nfs41_sequence_done(clp, task->tk_msg.rpc_resp, task->tk_status);
5093 if (task->tk_status < 0) {
5094 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5095 if (atomic_read(&clp->cl_count) == 1)
5098 if (_nfs4_async_handle_error(task, NULL, clp, NULL)
5100 nfs_restart_rpc(task, clp);
5104 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5106 kfree(task->tk_msg.rpc_argp);
5107 kfree(task->tk_msg.rpc_resp);
5109 dprintk("<-- %s\n", __func__);
5112 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5114 struct nfs_client *clp;
5115 struct nfs4_sequence_args *args;
5116 struct nfs4_sequence_res *res;
5118 clp = (struct nfs_client *)data;
5119 args = task->tk_msg.rpc_argp;
5120 res = task->tk_msg.rpc_resp;
5122 if (nfs4_setup_sequence(clp, args, res, 0, task))
5124 rpc_call_start(task);
5127 static const struct rpc_call_ops nfs41_sequence_ops = {
5128 .rpc_call_done = nfs41_sequence_call_done,
5129 .rpc_call_prepare = nfs41_sequence_prepare,
5130 .rpc_release = nfs41_sequence_release,
5133 static int nfs41_proc_async_sequence(struct nfs_client *clp,
5134 struct rpc_cred *cred)
5136 struct nfs4_sequence_args *args;
5137 struct nfs4_sequence_res *res;
5138 struct rpc_message msg = {
5139 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5143 if (!atomic_inc_not_zero(&clp->cl_count))
5145 args = kzalloc(sizeof(*args), GFP_KERNEL);
5146 res = kzalloc(sizeof(*res), GFP_KERNEL);
5147 if (!args || !res) {
5150 nfs_put_client(clp);
5153 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
5154 msg.rpc_argp = args;
5157 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
5158 &nfs41_sequence_ops, (void *)clp);
5161 struct nfs4_reclaim_complete_data {
5162 struct nfs_client *clp;
5163 struct nfs41_reclaim_complete_args arg;
5164 struct nfs41_reclaim_complete_res res;
5167 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5169 struct nfs4_reclaim_complete_data *calldata = data;
5171 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5172 if (nfs4_setup_sequence(calldata->clp, &calldata->arg.seq_args,
5173 &calldata->res.seq_res, 0, task))
5176 rpc_call_start(task);
5179 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5181 struct nfs4_reclaim_complete_data *calldata = data;
5182 struct nfs_client *clp = calldata->clp;
5183 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5185 dprintk("--> %s\n", __func__);
5186 nfs41_sequence_done(clp, res, task->tk_status);
5187 switch (task->tk_status) {
5189 case -NFS4ERR_COMPLETE_ALREADY:
5191 case -NFS4ERR_BADSESSION:
5192 case -NFS4ERR_DEADSESSION:
5194 * Handle the session error, but do not retry the operation, as
5195 * we have no way of telling whether the clientid had to be
5196 * reset before we got our reply. If reset, a new wave of
5197 * reclaim operations will follow, containing their own reclaim
5198 * complete. We don't want our retry to get on the way of
5199 * recovery by incorrectly indicating to the server that we're
5200 * done reclaiming state since the process had to be restarted.
5202 _nfs4_async_handle_error(task, NULL, clp, NULL);
5205 if (_nfs4_async_handle_error(
5206 task, NULL, clp, NULL) == -EAGAIN) {
5207 rpc_restart_call_prepare(task);
5212 dprintk("<-- %s\n", __func__);
5215 static void nfs4_free_reclaim_complete_data(void *data)
5217 struct nfs4_reclaim_complete_data *calldata = data;
5222 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5223 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5224 .rpc_call_done = nfs4_reclaim_complete_done,
5225 .rpc_release = nfs4_free_reclaim_complete_data,
5229 * Issue a global reclaim complete.
5231 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5233 struct nfs4_reclaim_complete_data *calldata;
5234 struct rpc_task *task;
5235 struct rpc_message msg = {
5236 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5238 struct rpc_task_setup task_setup_data = {
5239 .rpc_client = clp->cl_rpcclient,
5240 .rpc_message = &msg,
5241 .callback_ops = &nfs4_reclaim_complete_call_ops,
5242 .flags = RPC_TASK_ASYNC,
5244 int status = -ENOMEM;
5246 dprintk("--> %s\n", __func__);
5247 calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
5248 if (calldata == NULL)
5250 calldata->clp = clp;
5251 calldata->arg.one_fs = 0;
5252 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5254 msg.rpc_argp = &calldata->arg;
5255 msg.rpc_resp = &calldata->res;
5256 task_setup_data.callback_data = calldata;
5257 task = rpc_run_task(&task_setup_data);
5259 status = PTR_ERR(task);
5265 dprintk("<-- %s status=%d\n", __func__, status);
5268 #endif /* CONFIG_NFS_V4_1 */
5270 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
5271 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5272 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5273 .recover_open = nfs4_open_reclaim,
5274 .recover_lock = nfs4_lock_reclaim,
5275 .establish_clid = nfs4_init_clientid,
5276 .get_clid_cred = nfs4_get_setclientid_cred,
5279 #if defined(CONFIG_NFS_V4_1)
5280 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
5281 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5282 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5283 .recover_open = nfs4_open_reclaim,
5284 .recover_lock = nfs4_lock_reclaim,
5285 .establish_clid = nfs41_init_clientid,
5286 .get_clid_cred = nfs4_get_exchange_id_cred,
5287 .reclaim_complete = nfs41_proc_reclaim_complete,
5289 #endif /* CONFIG_NFS_V4_1 */
5291 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
5292 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5293 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5294 .recover_open = nfs4_open_expired,
5295 .recover_lock = nfs4_lock_expired,
5296 .establish_clid = nfs4_init_clientid,
5297 .get_clid_cred = nfs4_get_setclientid_cred,
5300 #if defined(CONFIG_NFS_V4_1)
5301 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
5302 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5303 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5304 .recover_open = nfs4_open_expired,
5305 .recover_lock = nfs4_lock_expired,
5306 .establish_clid = nfs41_init_clientid,
5307 .get_clid_cred = nfs4_get_exchange_id_cred,
5309 #endif /* CONFIG_NFS_V4_1 */
5311 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
5312 .sched_state_renewal = nfs4_proc_async_renew,
5313 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
5314 .renew_lease = nfs4_proc_renew,
5317 #if defined(CONFIG_NFS_V4_1)
5318 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
5319 .sched_state_renewal = nfs41_proc_async_sequence,
5320 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
5321 .renew_lease = nfs4_proc_sequence,
5326 * Per minor version reboot and network partition recovery ops
5329 struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[] = {
5330 &nfs40_reboot_recovery_ops,
5331 #if defined(CONFIG_NFS_V4_1)
5332 &nfs41_reboot_recovery_ops,
5336 struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[] = {
5337 &nfs40_nograce_recovery_ops,
5338 #if defined(CONFIG_NFS_V4_1)
5339 &nfs41_nograce_recovery_ops,
5343 struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[] = {
5344 &nfs40_state_renewal_ops,
5345 #if defined(CONFIG_NFS_V4_1)
5346 &nfs41_state_renewal_ops,
5350 static const struct inode_operations nfs4_file_inode_operations = {
5351 .permission = nfs_permission,
5352 .getattr = nfs_getattr,
5353 .setattr = nfs_setattr,
5354 .getxattr = nfs4_getxattr,
5355 .setxattr = nfs4_setxattr,
5356 .listxattr = nfs4_listxattr,
5359 const struct nfs_rpc_ops nfs_v4_clientops = {
5360 .version = 4, /* protocol version */
5361 .dentry_ops = &nfs4_dentry_operations,
5362 .dir_inode_ops = &nfs4_dir_inode_operations,
5363 .file_inode_ops = &nfs4_file_inode_operations,
5364 .getroot = nfs4_proc_get_root,
5365 .getattr = nfs4_proc_getattr,
5366 .setattr = nfs4_proc_setattr,
5367 .lookupfh = nfs4_proc_lookupfh,
5368 .lookup = nfs4_proc_lookup,
5369 .access = nfs4_proc_access,
5370 .readlink = nfs4_proc_readlink,
5371 .create = nfs4_proc_create,
5372 .remove = nfs4_proc_remove,
5373 .unlink_setup = nfs4_proc_unlink_setup,
5374 .unlink_done = nfs4_proc_unlink_done,
5375 .rename = nfs4_proc_rename,
5376 .link = nfs4_proc_link,
5377 .symlink = nfs4_proc_symlink,
5378 .mkdir = nfs4_proc_mkdir,
5379 .rmdir = nfs4_proc_remove,
5380 .readdir = nfs4_proc_readdir,
5381 .mknod = nfs4_proc_mknod,
5382 .statfs = nfs4_proc_statfs,
5383 .fsinfo = nfs4_proc_fsinfo,
5384 .pathconf = nfs4_proc_pathconf,
5385 .set_capabilities = nfs4_server_capabilities,
5386 .decode_dirent = nfs4_decode_dirent,
5387 .read_setup = nfs4_proc_read_setup,
5388 .read_done = nfs4_read_done,
5389 .write_setup = nfs4_proc_write_setup,
5390 .write_done = nfs4_write_done,
5391 .commit_setup = nfs4_proc_commit_setup,
5392 .commit_done = nfs4_commit_done,
5393 .lock = nfs4_proc_lock,
5394 .clear_acl_cache = nfs4_zap_acl_attr,
5395 .close_context = nfs4_close_context,