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(NFS4_SESSION_DRAINING, &ses->session_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(struct nfs4_sequence_res *res)
375 struct nfs4_slot_table *tbl;
377 tbl = &res->sr_session->fc_slot_table;
378 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE) {
379 /* just wake up the next guy waiting since
380 * we may have not consumed a slot after all */
381 dprintk("%s: No slot\n", __func__);
385 spin_lock(&tbl->slot_tbl_lock);
386 nfs4_free_slot(tbl, res->sr_slotid);
387 nfs41_check_drain_session_complete(res->sr_session);
388 spin_unlock(&tbl->slot_tbl_lock);
389 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
392 static void nfs41_sequence_done(struct nfs4_sequence_res *res)
394 unsigned long timestamp;
395 struct nfs4_slot_table *tbl;
396 struct nfs4_slot *slot;
399 * sr_status remains 1 if an RPC level error occurred. The server
400 * may or may not have processed the sequence operation..
401 * Proceed as if the server received and processed the sequence
404 if (res->sr_status == 1)
405 res->sr_status = NFS_OK;
407 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
408 if (res->sr_slotid == NFS4_MAX_SLOT_TABLE)
411 /* Check the SEQUENCE operation status */
412 if (res->sr_status == 0) {
413 struct nfs_client *clp = res->sr_session->clp;
414 tbl = &res->sr_session->fc_slot_table;
415 slot = tbl->slots + res->sr_slotid;
416 /* Update the slot's sequence and clientid lease timer */
418 timestamp = res->sr_renewal_time;
419 spin_lock(&clp->cl_lock);
420 if (time_before(clp->cl_last_renewal, timestamp))
421 clp->cl_last_renewal = timestamp;
422 spin_unlock(&clp->cl_lock);
423 /* Check sequence flags */
424 if (atomic_read(&clp->cl_count) > 1)
425 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
428 /* The session may be reset by one of the error handlers. */
429 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
430 nfs41_sequence_free_slot(res);
433 static void nfs4_sequence_done(const struct nfs_server *server,
434 struct nfs4_sequence_res *res, int rpc_status)
436 if (res->sr_session != NULL)
437 nfs41_sequence_done(res);
441 * nfs4_find_slot - efficiently look for a free slot
443 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
444 * If found, we mark the slot as used, update the highest_used_slotid,
445 * and respectively set up the sequence operation args.
446 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
448 * Note: must be called with under the slot_tbl_lock.
451 nfs4_find_slot(struct nfs4_slot_table *tbl)
454 u8 ret_id = NFS4_MAX_SLOT_TABLE;
455 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
457 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
458 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
460 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
461 if (slotid >= tbl->max_slots)
463 __set_bit(slotid, tbl->used_slots);
464 if (slotid > tbl->highest_used_slotid)
465 tbl->highest_used_slotid = slotid;
468 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
469 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
473 static int nfs41_setup_sequence(struct nfs4_session *session,
474 struct nfs4_sequence_args *args,
475 struct nfs4_sequence_res *res,
477 struct rpc_task *task)
479 struct nfs4_slot *slot;
480 struct nfs4_slot_table *tbl;
483 dprintk("--> %s\n", __func__);
484 /* slot already allocated? */
485 if (res->sr_slotid != NFS4_MAX_SLOT_TABLE)
488 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
489 tbl = &session->fc_slot_table;
491 spin_lock(&tbl->slot_tbl_lock);
492 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
493 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
495 * The state manager will wait until the slot table is empty.
496 * Schedule the reset thread
498 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
499 spin_unlock(&tbl->slot_tbl_lock);
500 dprintk("%s Schedule Session Reset\n", __func__);
504 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
505 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
506 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
507 spin_unlock(&tbl->slot_tbl_lock);
508 dprintk("%s enforce FIFO order\n", __func__);
512 slotid = nfs4_find_slot(tbl);
513 if (slotid == NFS4_MAX_SLOT_TABLE) {
514 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
515 spin_unlock(&tbl->slot_tbl_lock);
516 dprintk("<-- %s: no free slots\n", __func__);
519 spin_unlock(&tbl->slot_tbl_lock);
521 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
522 slot = tbl->slots + slotid;
523 args->sa_session = session;
524 args->sa_slotid = slotid;
525 args->sa_cache_this = cache_reply;
527 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
529 res->sr_session = session;
530 res->sr_slotid = slotid;
531 res->sr_renewal_time = jiffies;
532 res->sr_status_flags = 0;
534 * sr_status is only set in decode_sequence, and so will remain
535 * set to 1 if an rpc level failure occurs.
541 int nfs4_setup_sequence(const struct nfs_server *server,
542 struct nfs4_sequence_args *args,
543 struct nfs4_sequence_res *res,
545 struct rpc_task *task)
547 struct nfs4_session *session = nfs4_get_session(server);
550 if (session == NULL) {
551 args->sa_session = NULL;
552 res->sr_session = NULL;
556 dprintk("--> %s clp %p session %p sr_slotid %d\n",
557 __func__, session->clp, session, res->sr_slotid);
559 ret = nfs41_setup_sequence(session, args, res, cache_reply,
562 dprintk("<-- %s status=%d\n", __func__, ret);
566 struct nfs41_call_sync_data {
567 const struct nfs_server *seq_server;
568 struct nfs4_sequence_args *seq_args;
569 struct nfs4_sequence_res *seq_res;
573 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
575 struct nfs41_call_sync_data *data = calldata;
577 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
579 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
580 data->seq_res, data->cache_reply, task))
582 rpc_call_start(task);
585 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
587 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
588 nfs41_call_sync_prepare(task, calldata);
591 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
593 struct nfs41_call_sync_data *data = calldata;
595 nfs41_sequence_done(data->seq_res);
598 struct rpc_call_ops nfs41_call_sync_ops = {
599 .rpc_call_prepare = nfs41_call_sync_prepare,
600 .rpc_call_done = nfs41_call_sync_done,
603 struct rpc_call_ops nfs41_call_priv_sync_ops = {
604 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
605 .rpc_call_done = nfs41_call_sync_done,
608 static int nfs4_call_sync_sequence(struct nfs_server *server,
609 struct rpc_message *msg,
610 struct nfs4_sequence_args *args,
611 struct nfs4_sequence_res *res,
616 struct rpc_task *task;
617 struct nfs41_call_sync_data data = {
618 .seq_server = server,
621 .cache_reply = cache_reply,
623 struct rpc_task_setup task_setup = {
624 .rpc_client = server->client,
626 .callback_ops = &nfs41_call_sync_ops,
627 .callback_data = &data
630 res->sr_slotid = NFS4_MAX_SLOT_TABLE;
632 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
633 task = rpc_run_task(&task_setup);
637 ret = task->tk_status;
643 int _nfs4_call_sync_session(struct nfs_server *server,
644 struct rpc_message *msg,
645 struct nfs4_sequence_args *args,
646 struct nfs4_sequence_res *res,
649 return nfs4_call_sync_sequence(server, msg, args, res, cache_reply, 0);
653 static void nfs4_sequence_done(const struct nfs_server *server,
654 struct nfs4_sequence_res *res, int rpc_status)
657 #endif /* CONFIG_NFS_V4_1 */
659 int _nfs4_call_sync(struct nfs_server *server,
660 struct rpc_message *msg,
661 struct nfs4_sequence_args *args,
662 struct nfs4_sequence_res *res,
665 args->sa_session = res->sr_session = NULL;
666 return rpc_call_sync(server->client, msg, 0);
669 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
670 (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \
671 &(res)->seq_res, (cache_reply))
673 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
675 struct nfs_inode *nfsi = NFS_I(dir);
677 spin_lock(&dir->i_lock);
678 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
679 if (!cinfo->atomic || cinfo->before != nfsi->change_attr)
680 nfs_force_lookup_revalidate(dir);
681 nfsi->change_attr = cinfo->after;
682 spin_unlock(&dir->i_lock);
685 struct nfs4_opendata {
687 struct nfs_openargs o_arg;
688 struct nfs_openres o_res;
689 struct nfs_open_confirmargs c_arg;
690 struct nfs_open_confirmres c_res;
691 struct nfs_fattr f_attr;
692 struct nfs_fattr dir_attr;
695 struct nfs4_state_owner *owner;
696 struct nfs4_state *state;
698 unsigned long timestamp;
699 unsigned int rpc_done : 1;
705 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
707 p->o_res.f_attr = &p->f_attr;
708 p->o_res.dir_attr = &p->dir_attr;
709 p->o_res.seqid = p->o_arg.seqid;
710 p->c_res.seqid = p->c_arg.seqid;
711 p->o_res.server = p->o_arg.server;
712 nfs_fattr_init(&p->f_attr);
713 nfs_fattr_init(&p->dir_attr);
714 p->o_res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
717 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
718 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
719 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_mask);
730 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
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_CREAT) {
750 p->o_arg.u.attrs = &p->attrs;
751 memcpy(&p->attrs, attrs, sizeof(p->attrs));
752 s = (u32 *) p->o_arg.u.verifier.data;
756 p->c_arg.fh = &p->o_res.fh;
757 p->c_arg.stateid = &p->o_res.stateid;
758 p->c_arg.seqid = p->o_arg.seqid;
759 nfs4_init_opendata_res(p);
769 static void nfs4_opendata_free(struct kref *kref)
771 struct nfs4_opendata *p = container_of(kref,
772 struct nfs4_opendata, kref);
774 nfs_free_seqid(p->o_arg.seqid);
775 if (p->state != NULL)
776 nfs4_put_open_state(p->state);
777 nfs4_put_state_owner(p->owner);
783 static void nfs4_opendata_put(struct nfs4_opendata *p)
786 kref_put(&p->kref, nfs4_opendata_free);
789 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
793 ret = rpc_wait_for_completion_task(task);
797 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
801 if (open_mode & O_EXCL)
803 switch (mode & (FMODE_READ|FMODE_WRITE)) {
805 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
806 && state->n_rdonly != 0;
809 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
810 && state->n_wronly != 0;
812 case FMODE_READ|FMODE_WRITE:
813 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
814 && state->n_rdwr != 0;
820 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
822 if ((delegation->type & fmode) != fmode)
824 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
826 nfs_mark_delegation_referenced(delegation);
830 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
839 case FMODE_READ|FMODE_WRITE:
842 nfs4_state_set_mode_locked(state, state->state | fmode);
845 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
847 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
848 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data));
849 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data));
852 set_bit(NFS_O_RDONLY_STATE, &state->flags);
855 set_bit(NFS_O_WRONLY_STATE, &state->flags);
857 case FMODE_READ|FMODE_WRITE:
858 set_bit(NFS_O_RDWR_STATE, &state->flags);
862 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
864 write_seqlock(&state->seqlock);
865 nfs_set_open_stateid_locked(state, stateid, fmode);
866 write_sequnlock(&state->seqlock);
869 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
872 * Protect the call to nfs4_state_set_mode_locked and
873 * serialise the stateid update
875 write_seqlock(&state->seqlock);
876 if (deleg_stateid != NULL) {
877 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data));
878 set_bit(NFS_DELEGATED_STATE, &state->flags);
880 if (open_stateid != NULL)
881 nfs_set_open_stateid_locked(state, open_stateid, fmode);
882 write_sequnlock(&state->seqlock);
883 spin_lock(&state->owner->so_lock);
884 update_open_stateflags(state, fmode);
885 spin_unlock(&state->owner->so_lock);
888 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
890 struct nfs_inode *nfsi = NFS_I(state->inode);
891 struct nfs_delegation *deleg_cur;
894 fmode &= (FMODE_READ|FMODE_WRITE);
897 deleg_cur = rcu_dereference(nfsi->delegation);
898 if (deleg_cur == NULL)
901 spin_lock(&deleg_cur->lock);
902 if (nfsi->delegation != deleg_cur ||
903 (deleg_cur->type & fmode) != fmode)
904 goto no_delegation_unlock;
906 if (delegation == NULL)
907 delegation = &deleg_cur->stateid;
908 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0)
909 goto no_delegation_unlock;
911 nfs_mark_delegation_referenced(deleg_cur);
912 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
914 no_delegation_unlock:
915 spin_unlock(&deleg_cur->lock);
919 if (!ret && open_stateid != NULL) {
920 __update_open_stateid(state, open_stateid, NULL, fmode);
928 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
930 struct nfs_delegation *delegation;
933 delegation = rcu_dereference(NFS_I(inode)->delegation);
934 if (delegation == NULL || (delegation->type & fmode) == fmode) {
939 nfs_inode_return_delegation(inode);
942 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
944 struct nfs4_state *state = opendata->state;
945 struct nfs_inode *nfsi = NFS_I(state->inode);
946 struct nfs_delegation *delegation;
947 int open_mode = opendata->o_arg.open_flags & O_EXCL;
948 fmode_t fmode = opendata->o_arg.fmode;
949 nfs4_stateid stateid;
953 if (can_open_cached(state, fmode, open_mode)) {
954 spin_lock(&state->owner->so_lock);
955 if (can_open_cached(state, fmode, open_mode)) {
956 update_open_stateflags(state, fmode);
957 spin_unlock(&state->owner->so_lock);
958 goto out_return_state;
960 spin_unlock(&state->owner->so_lock);
963 delegation = rcu_dereference(nfsi->delegation);
964 if (delegation == NULL ||
965 !can_open_delegated(delegation, fmode)) {
969 /* Save the delegation */
970 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
972 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
977 /* Try to update the stateid using the delegation */
978 if (update_open_stateid(state, NULL, &stateid, fmode))
979 goto out_return_state;
984 atomic_inc(&state->count);
988 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
991 struct nfs4_state *state = NULL;
992 struct nfs_delegation *delegation;
995 if (!data->rpc_done) {
996 state = nfs4_try_open_cached(data);
1001 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1003 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1004 ret = PTR_ERR(inode);
1008 state = nfs4_get_open_state(inode, data->owner);
1011 if (data->o_res.delegation_type != 0) {
1012 int delegation_flags = 0;
1015 delegation = rcu_dereference(NFS_I(inode)->delegation);
1017 delegation_flags = delegation->flags;
1019 if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1020 nfs_inode_set_delegation(state->inode,
1021 data->owner->so_cred,
1024 nfs_inode_reclaim_delegation(state->inode,
1025 data->owner->so_cred,
1029 update_open_stateid(state, &data->o_res.stateid, NULL,
1037 return ERR_PTR(ret);
1040 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1042 struct nfs_inode *nfsi = NFS_I(state->inode);
1043 struct nfs_open_context *ctx;
1045 spin_lock(&state->inode->i_lock);
1046 list_for_each_entry(ctx, &nfsi->open_files, list) {
1047 if (ctx->state != state)
1049 get_nfs_open_context(ctx);
1050 spin_unlock(&state->inode->i_lock);
1053 spin_unlock(&state->inode->i_lock);
1054 return ERR_PTR(-ENOENT);
1057 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1059 struct nfs4_opendata *opendata;
1061 opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS);
1062 if (opendata == NULL)
1063 return ERR_PTR(-ENOMEM);
1064 opendata->state = state;
1065 atomic_inc(&state->count);
1069 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1071 struct nfs4_state *newstate;
1074 opendata->o_arg.open_flags = 0;
1075 opendata->o_arg.fmode = fmode;
1076 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1077 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1078 nfs4_init_opendata_res(opendata);
1079 ret = _nfs4_recover_proc_open(opendata);
1082 newstate = nfs4_opendata_to_nfs4_state(opendata);
1083 if (IS_ERR(newstate))
1084 return PTR_ERR(newstate);
1085 nfs4_close_state(&opendata->path, newstate, fmode);
1090 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1092 struct nfs4_state *newstate;
1095 /* memory barrier prior to reading state->n_* */
1096 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1098 if (state->n_rdwr != 0) {
1099 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1102 if (newstate != state)
1105 if (state->n_wronly != 0) {
1106 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1109 if (newstate != state)
1112 if (state->n_rdonly != 0) {
1113 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1116 if (newstate != state)
1120 * We may have performed cached opens for all three recoveries.
1121 * Check if we need to update the current stateid.
1123 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1124 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) {
1125 write_seqlock(&state->seqlock);
1126 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1127 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data));
1128 write_sequnlock(&state->seqlock);
1135 * reclaim state on the server after a reboot.
1137 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1139 struct nfs_delegation *delegation;
1140 struct nfs4_opendata *opendata;
1141 fmode_t delegation_type = 0;
1144 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1145 if (IS_ERR(opendata))
1146 return PTR_ERR(opendata);
1147 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1148 opendata->o_arg.fh = NFS_FH(state->inode);
1150 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1151 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1152 delegation_type = delegation->type;
1154 opendata->o_arg.u.delegation_type = delegation_type;
1155 status = nfs4_open_recover(opendata, state);
1156 nfs4_opendata_put(opendata);
1160 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1162 struct nfs_server *server = NFS_SERVER(state->inode);
1163 struct nfs4_exception exception = { };
1166 err = _nfs4_do_open_reclaim(ctx, state);
1167 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
1169 nfs4_handle_exception(server, err, &exception);
1170 } while (exception.retry);
1174 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1176 struct nfs_open_context *ctx;
1179 ctx = nfs4_state_find_open_context(state);
1181 return PTR_ERR(ctx);
1182 ret = nfs4_do_open_reclaim(ctx, state);
1183 put_nfs_open_context(ctx);
1187 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1189 struct nfs4_opendata *opendata;
1192 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1193 if (IS_ERR(opendata))
1194 return PTR_ERR(opendata);
1195 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1196 memcpy(opendata->o_arg.u.delegation.data, stateid->data,
1197 sizeof(opendata->o_arg.u.delegation.data));
1198 ret = nfs4_open_recover(opendata, state);
1199 nfs4_opendata_put(opendata);
1203 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1205 struct nfs4_exception exception = { };
1206 struct nfs_server *server = NFS_SERVER(state->inode);
1209 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1215 case -NFS4ERR_BADSESSION:
1216 case -NFS4ERR_BADSLOT:
1217 case -NFS4ERR_BAD_HIGH_SLOT:
1218 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1219 case -NFS4ERR_DEADSESSION:
1220 nfs4_schedule_state_recovery(
1221 server->nfs_client);
1223 case -NFS4ERR_STALE_CLIENTID:
1224 case -NFS4ERR_STALE_STATEID:
1225 case -NFS4ERR_EXPIRED:
1226 /* Don't recall a delegation if it was lost */
1227 nfs4_schedule_state_recovery(server->nfs_client);
1231 * The show must go on: exit, but mark the
1232 * stateid as needing recovery.
1234 case -NFS4ERR_ADMIN_REVOKED:
1235 case -NFS4ERR_BAD_STATEID:
1236 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
1241 err = nfs4_handle_exception(server, err, &exception);
1242 } while (exception.retry);
1247 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1249 struct nfs4_opendata *data = calldata;
1251 data->rpc_status = task->tk_status;
1252 if (RPC_ASSASSINATED(task))
1254 if (data->rpc_status == 0) {
1255 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
1256 sizeof(data->o_res.stateid.data));
1257 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1258 renew_lease(data->o_res.server, data->timestamp);
1263 static void nfs4_open_confirm_release(void *calldata)
1265 struct nfs4_opendata *data = calldata;
1266 struct nfs4_state *state = NULL;
1268 /* If this request hasn't been cancelled, do nothing */
1269 if (data->cancelled == 0)
1271 /* In case of error, no cleanup! */
1272 if (!data->rpc_done)
1274 state = nfs4_opendata_to_nfs4_state(data);
1276 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1278 nfs4_opendata_put(data);
1281 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1282 .rpc_call_done = nfs4_open_confirm_done,
1283 .rpc_release = nfs4_open_confirm_release,
1287 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1289 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1291 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1292 struct rpc_task *task;
1293 struct rpc_message msg = {
1294 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1295 .rpc_argp = &data->c_arg,
1296 .rpc_resp = &data->c_res,
1297 .rpc_cred = data->owner->so_cred,
1299 struct rpc_task_setup task_setup_data = {
1300 .rpc_client = server->client,
1301 .rpc_message = &msg,
1302 .callback_ops = &nfs4_open_confirm_ops,
1303 .callback_data = data,
1304 .workqueue = nfsiod_workqueue,
1305 .flags = RPC_TASK_ASYNC,
1309 kref_get(&data->kref);
1311 data->rpc_status = 0;
1312 data->timestamp = jiffies;
1313 task = rpc_run_task(&task_setup_data);
1315 return PTR_ERR(task);
1316 status = nfs4_wait_for_completion_rpc_task(task);
1318 data->cancelled = 1;
1321 status = data->rpc_status;
1326 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1328 struct nfs4_opendata *data = calldata;
1329 struct nfs4_state_owner *sp = data->owner;
1331 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1334 * Check if we still need to send an OPEN call, or if we can use
1335 * a delegation instead.
1337 if (data->state != NULL) {
1338 struct nfs_delegation *delegation;
1340 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1343 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1344 if (delegation != NULL &&
1345 test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) {
1351 /* Update sequence id. */
1352 data->o_arg.id = sp->so_owner_id.id;
1353 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1354 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1355 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1356 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1358 data->timestamp = jiffies;
1359 if (nfs4_setup_sequence(data->o_arg.server,
1360 &data->o_arg.seq_args,
1361 &data->o_res.seq_res, 1, task))
1363 rpc_call_start(task);
1366 task->tk_action = NULL;
1370 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1372 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1373 nfs4_open_prepare(task, calldata);
1376 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1378 struct nfs4_opendata *data = calldata;
1380 data->rpc_status = task->tk_status;
1382 nfs4_sequence_done(data->o_arg.server, &data->o_res.seq_res,
1385 if (RPC_ASSASSINATED(task))
1387 if (task->tk_status == 0) {
1388 switch (data->o_res.f_attr->mode & S_IFMT) {
1392 data->rpc_status = -ELOOP;
1395 data->rpc_status = -EISDIR;
1398 data->rpc_status = -ENOTDIR;
1400 renew_lease(data->o_res.server, data->timestamp);
1401 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1402 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1407 static void nfs4_open_release(void *calldata)
1409 struct nfs4_opendata *data = calldata;
1410 struct nfs4_state *state = NULL;
1412 /* If this request hasn't been cancelled, do nothing */
1413 if (data->cancelled == 0)
1415 /* In case of error, no cleanup! */
1416 if (data->rpc_status != 0 || !data->rpc_done)
1418 /* In case we need an open_confirm, no cleanup! */
1419 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1421 state = nfs4_opendata_to_nfs4_state(data);
1423 nfs4_close_state(&data->path, state, data->o_arg.fmode);
1425 nfs4_opendata_put(data);
1428 static const struct rpc_call_ops nfs4_open_ops = {
1429 .rpc_call_prepare = nfs4_open_prepare,
1430 .rpc_call_done = nfs4_open_done,
1431 .rpc_release = nfs4_open_release,
1434 static const struct rpc_call_ops nfs4_recover_open_ops = {
1435 .rpc_call_prepare = nfs4_recover_open_prepare,
1436 .rpc_call_done = nfs4_open_done,
1437 .rpc_release = nfs4_open_release,
1440 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1442 struct inode *dir = data->dir->d_inode;
1443 struct nfs_server *server = NFS_SERVER(dir);
1444 struct nfs_openargs *o_arg = &data->o_arg;
1445 struct nfs_openres *o_res = &data->o_res;
1446 struct rpc_task *task;
1447 struct rpc_message msg = {
1448 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1451 .rpc_cred = data->owner->so_cred,
1453 struct rpc_task_setup task_setup_data = {
1454 .rpc_client = server->client,
1455 .rpc_message = &msg,
1456 .callback_ops = &nfs4_open_ops,
1457 .callback_data = data,
1458 .workqueue = nfsiod_workqueue,
1459 .flags = RPC_TASK_ASYNC,
1463 kref_get(&data->kref);
1465 data->rpc_status = 0;
1466 data->cancelled = 0;
1468 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1469 task = rpc_run_task(&task_setup_data);
1471 return PTR_ERR(task);
1472 status = nfs4_wait_for_completion_rpc_task(task);
1474 data->cancelled = 1;
1477 status = data->rpc_status;
1483 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1485 struct inode *dir = data->dir->d_inode;
1486 struct nfs_openres *o_res = &data->o_res;
1489 status = nfs4_run_open_task(data, 1);
1490 if (status != 0 || !data->rpc_done)
1493 nfs_refresh_inode(dir, o_res->dir_attr);
1495 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1496 status = _nfs4_proc_open_confirm(data);
1505 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1507 static int _nfs4_proc_open(struct nfs4_opendata *data)
1509 struct inode *dir = data->dir->d_inode;
1510 struct nfs_server *server = NFS_SERVER(dir);
1511 struct nfs_openargs *o_arg = &data->o_arg;
1512 struct nfs_openres *o_res = &data->o_res;
1515 status = nfs4_run_open_task(data, 0);
1516 if (status != 0 || !data->rpc_done)
1519 if (o_arg->open_flags & O_CREAT) {
1520 update_changeattr(dir, &o_res->cinfo);
1521 nfs_post_op_update_inode(dir, o_res->dir_attr);
1523 nfs_refresh_inode(dir, o_res->dir_attr);
1524 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1525 server->caps &= ~NFS_CAP_POSIX_LOCK;
1526 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1527 status = _nfs4_proc_open_confirm(data);
1531 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1532 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1536 static int nfs4_recover_expired_lease(struct nfs_server *server)
1538 struct nfs_client *clp = server->nfs_client;
1542 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1543 ret = nfs4_wait_clnt_recover(clp);
1546 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1547 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1549 nfs4_schedule_state_recovery(clp);
1557 * reclaim state on the server after a network partition.
1558 * Assumes caller holds the appropriate lock
1560 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1562 struct nfs4_opendata *opendata;
1565 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1566 if (IS_ERR(opendata))
1567 return PTR_ERR(opendata);
1568 ret = nfs4_open_recover(opendata, state);
1570 d_drop(ctx->path.dentry);
1571 nfs4_opendata_put(opendata);
1575 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1577 struct nfs_server *server = NFS_SERVER(state->inode);
1578 struct nfs4_exception exception = { };
1582 err = _nfs4_open_expired(ctx, state);
1586 case -NFS4ERR_GRACE:
1587 case -NFS4ERR_DELAY:
1589 nfs4_handle_exception(server, err, &exception);
1592 } while (exception.retry);
1597 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1599 struct nfs_open_context *ctx;
1602 ctx = nfs4_state_find_open_context(state);
1604 return PTR_ERR(ctx);
1605 ret = nfs4_do_open_expired(ctx, state);
1606 put_nfs_open_context(ctx);
1611 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1612 * fields corresponding to attributes that were used to store the verifier.
1613 * Make sure we clobber those fields in the later setattr call
1615 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1617 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1618 !(sattr->ia_valid & ATTR_ATIME_SET))
1619 sattr->ia_valid |= ATTR_ATIME;
1621 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1622 !(sattr->ia_valid & ATTR_MTIME_SET))
1623 sattr->ia_valid |= ATTR_MTIME;
1627 * Returns a referenced nfs4_state
1629 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)
1631 struct nfs4_state_owner *sp;
1632 struct nfs4_state *state = NULL;
1633 struct nfs_server *server = NFS_SERVER(dir);
1634 struct nfs4_opendata *opendata;
1637 /* Protect against reboot recovery conflicts */
1639 if (!(sp = nfs4_get_state_owner(server, cred))) {
1640 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1643 status = nfs4_recover_expired_lease(server);
1645 goto err_put_state_owner;
1646 if (path->dentry->d_inode != NULL)
1647 nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
1649 opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL);
1650 if (opendata == NULL)
1651 goto err_put_state_owner;
1653 if (path->dentry->d_inode != NULL)
1654 opendata->state = nfs4_get_open_state(path->dentry->d_inode, sp);
1656 status = _nfs4_proc_open(opendata);
1658 goto err_opendata_put;
1660 state = nfs4_opendata_to_nfs4_state(opendata);
1661 status = PTR_ERR(state);
1663 goto err_opendata_put;
1664 if (server->caps & NFS_CAP_POSIX_LOCK)
1665 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1667 if (opendata->o_arg.open_flags & O_EXCL) {
1668 nfs4_exclusive_attrset(opendata, sattr);
1670 nfs_fattr_init(opendata->o_res.f_attr);
1671 status = nfs4_do_setattr(state->inode, cred,
1672 opendata->o_res.f_attr, sattr,
1675 nfs_setattr_update_inode(state->inode, sattr);
1676 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1678 nfs4_opendata_put(opendata);
1679 nfs4_put_state_owner(sp);
1683 nfs4_opendata_put(opendata);
1684 err_put_state_owner:
1685 nfs4_put_state_owner(sp);
1692 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)
1694 struct nfs4_exception exception = { };
1695 struct nfs4_state *res;
1699 status = _nfs4_do_open(dir, path, fmode, flags, sattr, cred, &res);
1702 /* NOTE: BAD_SEQID means the server and client disagree about the
1703 * book-keeping w.r.t. state-changing operations
1704 * (OPEN/CLOSE/LOCK/LOCKU...)
1705 * It is actually a sign of a bug on the client or on the server.
1707 * If we receive a BAD_SEQID error in the particular case of
1708 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1709 * have unhashed the old state_owner for us, and that we can
1710 * therefore safely retry using a new one. We should still warn
1711 * the user though...
1713 if (status == -NFS4ERR_BAD_SEQID) {
1714 printk(KERN_WARNING "NFS: v4 server %s "
1715 " returned a bad sequence-id error!\n",
1716 NFS_SERVER(dir)->nfs_client->cl_hostname);
1717 exception.retry = 1;
1721 * BAD_STATEID on OPEN means that the server cancelled our
1722 * state before it received the OPEN_CONFIRM.
1723 * Recover by retrying the request as per the discussion
1724 * on Page 181 of RFC3530.
1726 if (status == -NFS4ERR_BAD_STATEID) {
1727 exception.retry = 1;
1730 if (status == -EAGAIN) {
1731 /* We must have found a delegation */
1732 exception.retry = 1;
1735 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1736 status, &exception));
1737 } while (exception.retry);
1741 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1742 struct nfs_fattr *fattr, struct iattr *sattr,
1743 struct nfs4_state *state)
1745 struct nfs_server *server = NFS_SERVER(inode);
1746 struct nfs_setattrargs arg = {
1747 .fh = NFS_FH(inode),
1750 .bitmask = server->attr_bitmask,
1752 struct nfs_setattrres res = {
1756 struct rpc_message msg = {
1757 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
1762 unsigned long timestamp = jiffies;
1765 nfs_fattr_init(fattr);
1767 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) {
1768 /* Use that stateid */
1769 } else if (state != NULL) {
1770 nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
1772 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
1774 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
1775 if (status == 0 && state != NULL)
1776 renew_lease(server, timestamp);
1780 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1781 struct nfs_fattr *fattr, struct iattr *sattr,
1782 struct nfs4_state *state)
1784 struct nfs_server *server = NFS_SERVER(inode);
1785 struct nfs4_exception exception = { };
1788 err = nfs4_handle_exception(server,
1789 _nfs4_do_setattr(inode, cred, fattr, sattr, state),
1791 } while (exception.retry);
1795 struct nfs4_closedata {
1797 struct inode *inode;
1798 struct nfs4_state *state;
1799 struct nfs_closeargs arg;
1800 struct nfs_closeres res;
1801 struct nfs_fattr fattr;
1802 unsigned long timestamp;
1805 static void nfs4_free_closedata(void *data)
1807 struct nfs4_closedata *calldata = data;
1808 struct nfs4_state_owner *sp = calldata->state->owner;
1810 nfs4_put_open_state(calldata->state);
1811 nfs_free_seqid(calldata->arg.seqid);
1812 nfs4_put_state_owner(sp);
1813 path_put(&calldata->path);
1817 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
1820 spin_lock(&state->owner->so_lock);
1821 if (!(fmode & FMODE_READ))
1822 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1823 if (!(fmode & FMODE_WRITE))
1824 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1825 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1826 spin_unlock(&state->owner->so_lock);
1829 static void nfs4_close_done(struct rpc_task *task, void *data)
1831 struct nfs4_closedata *calldata = data;
1832 struct nfs4_state *state = calldata->state;
1833 struct nfs_server *server = NFS_SERVER(calldata->inode);
1835 nfs4_sequence_done(server, &calldata->res.seq_res, task->tk_status);
1836 if (RPC_ASSASSINATED(task))
1838 /* hmm. we are done with the inode, and in the process of freeing
1839 * the state_owner. we keep this around to process errors
1841 switch (task->tk_status) {
1843 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
1844 renew_lease(server, calldata->timestamp);
1845 nfs4_close_clear_stateid_flags(state,
1846 calldata->arg.fmode);
1848 case -NFS4ERR_STALE_STATEID:
1849 case -NFS4ERR_OLD_STATEID:
1850 case -NFS4ERR_BAD_STATEID:
1851 case -NFS4ERR_EXPIRED:
1852 if (calldata->arg.fmode == 0)
1855 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
1856 rpc_restart_call_prepare(task);
1858 nfs_release_seqid(calldata->arg.seqid);
1859 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
1862 static void nfs4_close_prepare(struct rpc_task *task, void *data)
1864 struct nfs4_closedata *calldata = data;
1865 struct nfs4_state *state = calldata->state;
1868 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1871 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
1872 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
1873 spin_lock(&state->owner->so_lock);
1874 /* Calculate the change in open mode */
1875 if (state->n_rdwr == 0) {
1876 if (state->n_rdonly == 0) {
1877 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
1878 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1879 calldata->arg.fmode &= ~FMODE_READ;
1881 if (state->n_wronly == 0) {
1882 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
1883 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
1884 calldata->arg.fmode &= ~FMODE_WRITE;
1887 spin_unlock(&state->owner->so_lock);
1890 /* Note: exit _without_ calling nfs4_close_done */
1891 task->tk_action = NULL;
1895 if (calldata->arg.fmode == 0)
1896 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
1898 nfs_fattr_init(calldata->res.fattr);
1899 calldata->timestamp = jiffies;
1900 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
1901 &calldata->arg.seq_args, &calldata->res.seq_res,
1904 rpc_call_start(task);
1907 static const struct rpc_call_ops nfs4_close_ops = {
1908 .rpc_call_prepare = nfs4_close_prepare,
1909 .rpc_call_done = nfs4_close_done,
1910 .rpc_release = nfs4_free_closedata,
1914 * It is possible for data to be read/written from a mem-mapped file
1915 * after the sys_close call (which hits the vfs layer as a flush).
1916 * This means that we can't safely call nfsv4 close on a file until
1917 * the inode is cleared. This in turn means that we are not good
1918 * NFSv4 citizens - we do not indicate to the server to update the file's
1919 * share state even when we are done with one of the three share
1920 * stateid's in the inode.
1922 * NOTE: Caller must be holding the sp->so_owner semaphore!
1924 int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait)
1926 struct nfs_server *server = NFS_SERVER(state->inode);
1927 struct nfs4_closedata *calldata;
1928 struct nfs4_state_owner *sp = state->owner;
1929 struct rpc_task *task;
1930 struct rpc_message msg = {
1931 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
1932 .rpc_cred = state->owner->so_cred,
1934 struct rpc_task_setup task_setup_data = {
1935 .rpc_client = server->client,
1936 .rpc_message = &msg,
1937 .callback_ops = &nfs4_close_ops,
1938 .workqueue = nfsiod_workqueue,
1939 .flags = RPC_TASK_ASYNC,
1941 int status = -ENOMEM;
1943 calldata = kzalloc(sizeof(*calldata), gfp_mask);
1944 if (calldata == NULL)
1946 calldata->inode = state->inode;
1947 calldata->state = state;
1948 calldata->arg.fh = NFS_FH(state->inode);
1949 calldata->arg.stateid = &state->open_stateid;
1950 /* Serialization for the sequence id */
1951 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
1952 if (calldata->arg.seqid == NULL)
1953 goto out_free_calldata;
1954 calldata->arg.fmode = 0;
1955 calldata->arg.bitmask = server->cache_consistency_bitmask;
1956 calldata->res.fattr = &calldata->fattr;
1957 calldata->res.seqid = calldata->arg.seqid;
1958 calldata->res.server = server;
1959 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
1961 calldata->path = *path;
1963 msg.rpc_argp = &calldata->arg,
1964 msg.rpc_resp = &calldata->res,
1965 task_setup_data.callback_data = calldata;
1966 task = rpc_run_task(&task_setup_data);
1968 return PTR_ERR(task);
1971 status = rpc_wait_for_completion_task(task);
1977 nfs4_put_open_state(state);
1978 nfs4_put_state_owner(sp);
1982 static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct nfs4_state *state, fmode_t fmode)
1987 /* If the open_intent is for execute, we have an extra check to make */
1988 if (fmode & FMODE_EXEC) {
1989 ret = nfs_may_open(state->inode,
1990 state->owner->so_cred,
1991 nd->intent.open.flags);
1995 filp = lookup_instantiate_filp(nd, path->dentry, NULL);
1996 if (!IS_ERR(filp)) {
1997 struct nfs_open_context *ctx;
1998 ctx = nfs_file_open_context(filp);
2002 ret = PTR_ERR(filp);
2004 nfs4_close_sync(path, state, fmode & (FMODE_READ|FMODE_WRITE));
2009 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
2011 struct path path = {
2012 .mnt = nd->path.mnt,
2015 struct dentry *parent;
2017 struct rpc_cred *cred;
2018 struct nfs4_state *state;
2020 fmode_t fmode = nd->intent.open.flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
2022 if (nd->flags & LOOKUP_CREATE) {
2023 attr.ia_mode = nd->intent.open.create_mode;
2024 attr.ia_valid = ATTR_MODE;
2025 if (!IS_POSIXACL(dir))
2026 attr.ia_mode &= ~current_umask();
2029 BUG_ON(nd->intent.open.flags & O_CREAT);
2032 cred = rpc_lookup_cred();
2034 return (struct dentry *)cred;
2035 parent = dentry->d_parent;
2036 /* Protect against concurrent sillydeletes */
2037 nfs_block_sillyrename(parent);
2038 state = nfs4_do_open(dir, &path, fmode, nd->intent.open.flags, &attr, cred);
2040 if (IS_ERR(state)) {
2041 if (PTR_ERR(state) == -ENOENT) {
2042 d_add(dentry, NULL);
2043 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2045 nfs_unblock_sillyrename(parent);
2046 return (struct dentry *)state;
2048 res = d_add_unique(dentry, igrab(state->inode));
2051 nfs_set_verifier(path.dentry, nfs_save_change_attribute(dir));
2052 nfs_unblock_sillyrename(parent);
2053 nfs4_intent_set_file(nd, &path, state, fmode);
2058 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
2060 struct path path = {
2061 .mnt = nd->path.mnt,
2064 struct rpc_cred *cred;
2065 struct nfs4_state *state;
2066 fmode_t fmode = openflags & (FMODE_READ | FMODE_WRITE);
2068 cred = rpc_lookup_cred();
2070 return PTR_ERR(cred);
2071 state = nfs4_do_open(dir, &path, fmode, openflags, NULL, cred);
2073 if (IS_ERR(state)) {
2074 switch (PTR_ERR(state)) {
2080 return PTR_ERR(state);
2085 if (state->inode == dentry->d_inode) {
2086 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2087 nfs4_intent_set_file(nd, &path, state, fmode);
2090 nfs4_close_sync(&path, state, fmode);
2096 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2098 if (ctx->state == NULL)
2101 nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
2103 nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
2106 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2108 struct nfs4_server_caps_arg args = {
2111 struct nfs4_server_caps_res res = {};
2112 struct rpc_message msg = {
2113 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2119 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2121 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2122 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2123 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2124 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2125 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2126 NFS_CAP_CTIME|NFS_CAP_MTIME);
2127 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2128 server->caps |= NFS_CAP_ACLS;
2129 if (res.has_links != 0)
2130 server->caps |= NFS_CAP_HARDLINKS;
2131 if (res.has_symlinks != 0)
2132 server->caps |= NFS_CAP_SYMLINKS;
2133 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2134 server->caps |= NFS_CAP_FILEID;
2135 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2136 server->caps |= NFS_CAP_MODE;
2137 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2138 server->caps |= NFS_CAP_NLINK;
2139 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2140 server->caps |= NFS_CAP_OWNER;
2141 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2142 server->caps |= NFS_CAP_OWNER_GROUP;
2143 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2144 server->caps |= NFS_CAP_ATIME;
2145 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2146 server->caps |= NFS_CAP_CTIME;
2147 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2148 server->caps |= NFS_CAP_MTIME;
2150 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2151 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2152 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2153 server->acl_bitmask = res.acl_bitmask;
2159 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2161 struct nfs4_exception exception = { };
2164 err = nfs4_handle_exception(server,
2165 _nfs4_server_capabilities(server, fhandle),
2167 } while (exception.retry);
2171 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2172 struct nfs_fsinfo *info)
2174 struct nfs4_lookup_root_arg args = {
2175 .bitmask = nfs4_fattr_bitmap,
2177 struct nfs4_lookup_res res = {
2179 .fattr = info->fattr,
2182 struct rpc_message msg = {
2183 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2188 nfs_fattr_init(info->fattr);
2189 return nfs4_call_sync(server, &msg, &args, &res, 0);
2192 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2193 struct nfs_fsinfo *info)
2195 struct nfs4_exception exception = { };
2198 err = nfs4_handle_exception(server,
2199 _nfs4_lookup_root(server, fhandle, info),
2201 } while (exception.retry);
2206 * get the file handle for the "/" directory on the server
2208 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2209 struct nfs_fsinfo *info)
2213 status = nfs4_lookup_root(server, fhandle, info);
2215 status = nfs4_server_capabilities(server, fhandle);
2217 status = nfs4_do_fsinfo(server, fhandle, info);
2218 return nfs4_map_errors(status);
2222 * Get locations and (maybe) other attributes of a referral.
2223 * Note that we'll actually follow the referral later when
2224 * we detect fsid mismatch in inode revalidation
2226 static int nfs4_get_referral(struct inode *dir, const struct qstr *name, struct nfs_fattr *fattr, struct nfs_fh *fhandle)
2228 int status = -ENOMEM;
2229 struct page *page = NULL;
2230 struct nfs4_fs_locations *locations = NULL;
2232 page = alloc_page(GFP_KERNEL);
2235 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2236 if (locations == NULL)
2239 status = nfs4_proc_fs_locations(dir, name, locations, page);
2242 /* Make sure server returned a different fsid for the referral */
2243 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2244 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__, name->name);
2249 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2250 fattr->valid |= NFS_ATTR_FATTR_V4_REFERRAL;
2252 fattr->mode = S_IFDIR;
2253 memset(fhandle, 0, sizeof(struct nfs_fh));
2262 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2264 struct nfs4_getattr_arg args = {
2266 .bitmask = server->attr_bitmask,
2268 struct nfs4_getattr_res res = {
2272 struct rpc_message msg = {
2273 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2278 nfs_fattr_init(fattr);
2279 return nfs4_call_sync(server, &msg, &args, &res, 0);
2282 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2284 struct nfs4_exception exception = { };
2287 err = nfs4_handle_exception(server,
2288 _nfs4_proc_getattr(server, fhandle, fattr),
2290 } while (exception.retry);
2295 * The file is not closed if it is opened due to the a request to change
2296 * the size of the file. The open call will not be needed once the
2297 * VFS layer lookup-intents are implemented.
2299 * Close is called when the inode is destroyed.
2300 * If we haven't opened the file for O_WRONLY, we
2301 * need to in the size_change case to obtain a stateid.
2304 * Because OPEN is always done by name in nfsv4, it is
2305 * possible that we opened a different file by the same
2306 * name. We can recognize this race condition, but we
2307 * can't do anything about it besides returning an error.
2309 * This will be fixed with VFS changes (lookup-intent).
2312 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2313 struct iattr *sattr)
2315 struct inode *inode = dentry->d_inode;
2316 struct rpc_cred *cred = NULL;
2317 struct nfs4_state *state = NULL;
2320 nfs_fattr_init(fattr);
2322 /* Search for an existing open(O_WRITE) file */
2323 if (sattr->ia_valid & ATTR_FILE) {
2324 struct nfs_open_context *ctx;
2326 ctx = nfs_file_open_context(sattr->ia_file);
2333 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2335 nfs_setattr_update_inode(inode, sattr);
2339 static int _nfs4_proc_lookupfh(struct nfs_server *server, const struct nfs_fh *dirfh,
2340 const struct qstr *name, struct nfs_fh *fhandle,
2341 struct nfs_fattr *fattr)
2344 struct nfs4_lookup_arg args = {
2345 .bitmask = server->attr_bitmask,
2349 struct nfs4_lookup_res res = {
2354 struct rpc_message msg = {
2355 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2360 nfs_fattr_init(fattr);
2362 dprintk("NFS call lookupfh %s\n", name->name);
2363 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2364 dprintk("NFS reply lookupfh: %d\n", status);
2368 static int nfs4_proc_lookupfh(struct nfs_server *server, struct nfs_fh *dirfh,
2369 struct qstr *name, struct nfs_fh *fhandle,
2370 struct nfs_fattr *fattr)
2372 struct nfs4_exception exception = { };
2375 err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
2377 if (err == -NFS4ERR_MOVED) {
2381 err = nfs4_handle_exception(server, err, &exception);
2382 } while (exception.retry);
2386 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name,
2387 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2391 dprintk("NFS call lookup %s\n", name->name);
2392 status = _nfs4_proc_lookupfh(NFS_SERVER(dir), NFS_FH(dir), name, fhandle, fattr);
2393 if (status == -NFS4ERR_MOVED)
2394 status = nfs4_get_referral(dir, name, fattr, fhandle);
2395 dprintk("NFS reply lookup: %d\n", status);
2399 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2401 struct nfs4_exception exception = { };
2404 err = nfs4_handle_exception(NFS_SERVER(dir),
2405 _nfs4_proc_lookup(dir, name, fhandle, fattr),
2407 } while (exception.retry);
2411 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2413 struct nfs_server *server = NFS_SERVER(inode);
2414 struct nfs4_accessargs args = {
2415 .fh = NFS_FH(inode),
2416 .bitmask = server->attr_bitmask,
2418 struct nfs4_accessres res = {
2421 struct rpc_message msg = {
2422 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2425 .rpc_cred = entry->cred,
2427 int mode = entry->mask;
2431 * Determine which access bits we want to ask for...
2433 if (mode & MAY_READ)
2434 args.access |= NFS4_ACCESS_READ;
2435 if (S_ISDIR(inode->i_mode)) {
2436 if (mode & MAY_WRITE)
2437 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2438 if (mode & MAY_EXEC)
2439 args.access |= NFS4_ACCESS_LOOKUP;
2441 if (mode & MAY_WRITE)
2442 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2443 if (mode & MAY_EXEC)
2444 args.access |= NFS4_ACCESS_EXECUTE;
2447 res.fattr = nfs_alloc_fattr();
2448 if (res.fattr == NULL)
2451 status = nfs4_call_sync(server, &msg, &args, &res, 0);
2454 if (res.access & NFS4_ACCESS_READ)
2455 entry->mask |= MAY_READ;
2456 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2457 entry->mask |= MAY_WRITE;
2458 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2459 entry->mask |= MAY_EXEC;
2460 nfs_refresh_inode(inode, res.fattr);
2462 nfs_free_fattr(res.fattr);
2466 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2468 struct nfs4_exception exception = { };
2471 err = nfs4_handle_exception(NFS_SERVER(inode),
2472 _nfs4_proc_access(inode, entry),
2474 } while (exception.retry);
2479 * TODO: For the time being, we don't try to get any attributes
2480 * along with any of the zero-copy operations READ, READDIR,
2483 * In the case of the first three, we want to put the GETATTR
2484 * after the read-type operation -- this is because it is hard
2485 * to predict the length of a GETATTR response in v4, and thus
2486 * align the READ data correctly. This means that the GETATTR
2487 * may end up partially falling into the page cache, and we should
2488 * shift it into the 'tail' of the xdr_buf before processing.
2489 * To do this efficiently, we need to know the total length
2490 * of data received, which doesn't seem to be available outside
2493 * In the case of WRITE, we also want to put the GETATTR after
2494 * the operation -- in this case because we want to make sure
2495 * we get the post-operation mtime and size. This means that
2496 * we can't use xdr_encode_pages() as written: we need a variant
2497 * of it which would leave room in the 'tail' iovec.
2499 * Both of these changes to the XDR layer would in fact be quite
2500 * minor, but I decided to leave them for a subsequent patch.
2502 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2503 unsigned int pgbase, unsigned int pglen)
2505 struct nfs4_readlink args = {
2506 .fh = NFS_FH(inode),
2511 struct nfs4_readlink_res res;
2512 struct rpc_message msg = {
2513 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2518 return nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
2521 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2522 unsigned int pgbase, unsigned int pglen)
2524 struct nfs4_exception exception = { };
2527 err = nfs4_handle_exception(NFS_SERVER(inode),
2528 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2530 } while (exception.retry);
2536 * We will need to arrange for the VFS layer to provide an atomic open.
2537 * Until then, this create/open method is prone to inefficiency and race
2538 * conditions due to the lookup, create, and open VFS calls from sys_open()
2539 * placed on the wire.
2541 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2542 * The file will be opened again in the subsequent VFS open call
2543 * (nfs4_proc_file_open).
2545 * The open for read will just hang around to be used by any process that
2546 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2550 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2551 int flags, struct nameidata *nd)
2553 struct path path = {
2554 .mnt = nd->path.mnt,
2557 struct nfs4_state *state;
2558 struct rpc_cred *cred;
2559 fmode_t fmode = flags & (FMODE_READ | FMODE_WRITE);
2562 cred = rpc_lookup_cred();
2564 status = PTR_ERR(cred);
2567 state = nfs4_do_open(dir, &path, fmode, flags, sattr, cred);
2569 if (IS_ERR(state)) {
2570 status = PTR_ERR(state);
2573 d_add(dentry, igrab(state->inode));
2574 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2575 if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
2576 status = nfs4_intent_set_file(nd, &path, state, fmode);
2578 nfs4_close_sync(&path, state, fmode);
2585 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2587 struct nfs_server *server = NFS_SERVER(dir);
2588 struct nfs_removeargs args = {
2590 .name.len = name->len,
2591 .name.name = name->name,
2592 .bitmask = server->attr_bitmask,
2594 struct nfs_removeres res = {
2597 struct rpc_message msg = {
2598 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2602 int status = -ENOMEM;
2604 res.dir_attr = nfs_alloc_fattr();
2605 if (res.dir_attr == NULL)
2608 status = nfs4_call_sync(server, &msg, &args, &res, 1);
2610 update_changeattr(dir, &res.cinfo);
2611 nfs_post_op_update_inode(dir, res.dir_attr);
2613 nfs_free_fattr(res.dir_attr);
2618 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2620 struct nfs4_exception exception = { };
2623 err = nfs4_handle_exception(NFS_SERVER(dir),
2624 _nfs4_proc_remove(dir, name),
2626 } while (exception.retry);
2630 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2632 struct nfs_server *server = NFS_SERVER(dir);
2633 struct nfs_removeargs *args = msg->rpc_argp;
2634 struct nfs_removeres *res = msg->rpc_resp;
2636 args->bitmask = server->cache_consistency_bitmask;
2637 res->server = server;
2638 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2641 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2643 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2645 nfs4_sequence_done(res->server, &res->seq_res, task->tk_status);
2646 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2648 update_changeattr(dir, &res->cinfo);
2649 nfs_post_op_update_inode(dir, res->dir_attr);
2653 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2654 struct inode *new_dir, struct qstr *new_name)
2656 struct nfs_server *server = NFS_SERVER(old_dir);
2657 struct nfs4_rename_arg arg = {
2658 .old_dir = NFS_FH(old_dir),
2659 .new_dir = NFS_FH(new_dir),
2660 .old_name = old_name,
2661 .new_name = new_name,
2662 .bitmask = server->attr_bitmask,
2664 struct nfs4_rename_res res = {
2667 struct rpc_message msg = {
2668 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
2672 int status = -ENOMEM;
2674 res.old_fattr = nfs_alloc_fattr();
2675 res.new_fattr = nfs_alloc_fattr();
2676 if (res.old_fattr == NULL || res.new_fattr == NULL)
2679 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2681 update_changeattr(old_dir, &res.old_cinfo);
2682 nfs_post_op_update_inode(old_dir, res.old_fattr);
2683 update_changeattr(new_dir, &res.new_cinfo);
2684 nfs_post_op_update_inode(new_dir, res.new_fattr);
2687 nfs_free_fattr(res.new_fattr);
2688 nfs_free_fattr(res.old_fattr);
2692 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2693 struct inode *new_dir, struct qstr *new_name)
2695 struct nfs4_exception exception = { };
2698 err = nfs4_handle_exception(NFS_SERVER(old_dir),
2699 _nfs4_proc_rename(old_dir, old_name,
2702 } while (exception.retry);
2706 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2708 struct nfs_server *server = NFS_SERVER(inode);
2709 struct nfs4_link_arg arg = {
2710 .fh = NFS_FH(inode),
2711 .dir_fh = NFS_FH(dir),
2713 .bitmask = server->attr_bitmask,
2715 struct nfs4_link_res res = {
2718 struct rpc_message msg = {
2719 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
2723 int status = -ENOMEM;
2725 res.fattr = nfs_alloc_fattr();
2726 res.dir_attr = nfs_alloc_fattr();
2727 if (res.fattr == NULL || res.dir_attr == NULL)
2730 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
2732 update_changeattr(dir, &res.cinfo);
2733 nfs_post_op_update_inode(dir, res.dir_attr);
2734 nfs_post_op_update_inode(inode, res.fattr);
2737 nfs_free_fattr(res.dir_attr);
2738 nfs_free_fattr(res.fattr);
2742 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
2744 struct nfs4_exception exception = { };
2747 err = nfs4_handle_exception(NFS_SERVER(inode),
2748 _nfs4_proc_link(inode, dir, name),
2750 } while (exception.retry);
2754 struct nfs4_createdata {
2755 struct rpc_message msg;
2756 struct nfs4_create_arg arg;
2757 struct nfs4_create_res res;
2759 struct nfs_fattr fattr;
2760 struct nfs_fattr dir_fattr;
2763 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
2764 struct qstr *name, struct iattr *sattr, u32 ftype)
2766 struct nfs4_createdata *data;
2768 data = kzalloc(sizeof(*data), GFP_KERNEL);
2770 struct nfs_server *server = NFS_SERVER(dir);
2772 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
2773 data->msg.rpc_argp = &data->arg;
2774 data->msg.rpc_resp = &data->res;
2775 data->arg.dir_fh = NFS_FH(dir);
2776 data->arg.server = server;
2777 data->arg.name = name;
2778 data->arg.attrs = sattr;
2779 data->arg.ftype = ftype;
2780 data->arg.bitmask = server->attr_bitmask;
2781 data->res.server = server;
2782 data->res.fh = &data->fh;
2783 data->res.fattr = &data->fattr;
2784 data->res.dir_fattr = &data->dir_fattr;
2785 nfs_fattr_init(data->res.fattr);
2786 nfs_fattr_init(data->res.dir_fattr);
2791 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
2793 int status = nfs4_call_sync(NFS_SERVER(dir), &data->msg,
2794 &data->arg, &data->res, 1);
2796 update_changeattr(dir, &data->res.dir_cinfo);
2797 nfs_post_op_update_inode(dir, data->res.dir_fattr);
2798 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
2803 static void nfs4_free_createdata(struct nfs4_createdata *data)
2808 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2809 struct page *page, unsigned int len, struct iattr *sattr)
2811 struct nfs4_createdata *data;
2812 int status = -ENAMETOOLONG;
2814 if (len > NFS4_MAXPATHLEN)
2818 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
2822 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
2823 data->arg.u.symlink.pages = &page;
2824 data->arg.u.symlink.len = len;
2826 status = nfs4_do_create(dir, dentry, data);
2828 nfs4_free_createdata(data);
2833 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
2834 struct page *page, unsigned int len, struct iattr *sattr)
2836 struct nfs4_exception exception = { };
2839 err = nfs4_handle_exception(NFS_SERVER(dir),
2840 _nfs4_proc_symlink(dir, dentry, page,
2843 } while (exception.retry);
2847 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2848 struct iattr *sattr)
2850 struct nfs4_createdata *data;
2851 int status = -ENOMEM;
2853 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
2857 status = nfs4_do_create(dir, dentry, data);
2859 nfs4_free_createdata(data);
2864 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
2865 struct iattr *sattr)
2867 struct nfs4_exception exception = { };
2870 err = nfs4_handle_exception(NFS_SERVER(dir),
2871 _nfs4_proc_mkdir(dir, dentry, sattr),
2873 } while (exception.retry);
2877 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2878 u64 cookie, struct page *page, unsigned int count, int plus)
2880 struct inode *dir = dentry->d_inode;
2881 struct nfs4_readdir_arg args = {
2886 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
2888 struct nfs4_readdir_res res;
2889 struct rpc_message msg = {
2890 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
2897 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
2898 dentry->d_parent->d_name.name,
2899 dentry->d_name.name,
2900 (unsigned long long)cookie);
2901 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
2902 res.pgbase = args.pgbase;
2903 status = nfs4_call_sync(NFS_SERVER(dir), &msg, &args, &res, 0);
2905 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
2907 nfs_invalidate_atime(dir);
2909 dprintk("%s: returns %d\n", __func__, status);
2913 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
2914 u64 cookie, struct page *page, unsigned int count, int plus)
2916 struct nfs4_exception exception = { };
2919 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
2920 _nfs4_proc_readdir(dentry, cred, cookie,
2923 } while (exception.retry);
2927 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2928 struct iattr *sattr, dev_t rdev)
2930 struct nfs4_createdata *data;
2931 int mode = sattr->ia_mode;
2932 int status = -ENOMEM;
2934 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
2935 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
2937 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
2942 data->arg.ftype = NF4FIFO;
2943 else if (S_ISBLK(mode)) {
2944 data->arg.ftype = NF4BLK;
2945 data->arg.u.device.specdata1 = MAJOR(rdev);
2946 data->arg.u.device.specdata2 = MINOR(rdev);
2948 else if (S_ISCHR(mode)) {
2949 data->arg.ftype = NF4CHR;
2950 data->arg.u.device.specdata1 = MAJOR(rdev);
2951 data->arg.u.device.specdata2 = MINOR(rdev);
2954 status = nfs4_do_create(dir, dentry, data);
2956 nfs4_free_createdata(data);
2961 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2962 struct iattr *sattr, dev_t rdev)
2964 struct nfs4_exception exception = { };
2967 err = nfs4_handle_exception(NFS_SERVER(dir),
2968 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2970 } while (exception.retry);
2974 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2975 struct nfs_fsstat *fsstat)
2977 struct nfs4_statfs_arg args = {
2979 .bitmask = server->attr_bitmask,
2981 struct nfs4_statfs_res res = {
2984 struct rpc_message msg = {
2985 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2990 nfs_fattr_init(fsstat->fattr);
2991 return nfs4_call_sync(server, &msg, &args, &res, 0);
2994 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
2996 struct nfs4_exception exception = { };
2999 err = nfs4_handle_exception(server,
3000 _nfs4_proc_statfs(server, fhandle, fsstat),
3002 } while (exception.retry);
3006 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3007 struct nfs_fsinfo *fsinfo)
3009 struct nfs4_fsinfo_arg args = {
3011 .bitmask = server->attr_bitmask,
3013 struct nfs4_fsinfo_res res = {
3016 struct rpc_message msg = {
3017 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3022 return nfs4_call_sync(server, &msg, &args, &res, 0);
3025 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3027 struct nfs4_exception exception = { };
3031 err = nfs4_handle_exception(server,
3032 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3034 } while (exception.retry);
3038 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3040 nfs_fattr_init(fsinfo->fattr);
3041 return nfs4_do_fsinfo(server, fhandle, fsinfo);
3044 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3045 struct nfs_pathconf *pathconf)
3047 struct nfs4_pathconf_arg args = {
3049 .bitmask = server->attr_bitmask,
3051 struct nfs4_pathconf_res res = {
3052 .pathconf = pathconf,
3054 struct rpc_message msg = {
3055 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3060 /* None of the pathconf attributes are mandatory to implement */
3061 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3062 memset(pathconf, 0, sizeof(*pathconf));
3066 nfs_fattr_init(pathconf->fattr);
3067 return nfs4_call_sync(server, &msg, &args, &res, 0);
3070 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3071 struct nfs_pathconf *pathconf)
3073 struct nfs4_exception exception = { };
3077 err = nfs4_handle_exception(server,
3078 _nfs4_proc_pathconf(server, fhandle, pathconf),
3080 } while (exception.retry);
3084 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3086 struct nfs_server *server = NFS_SERVER(data->inode);
3088 dprintk("--> %s\n", __func__);
3090 nfs4_sequence_done(server, &data->res.seq_res, task->tk_status);
3092 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3093 nfs_restart_rpc(task, server->nfs_client);
3097 nfs_invalidate_atime(data->inode);
3098 if (task->tk_status > 0)
3099 renew_lease(server, data->timestamp);
3103 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3105 data->timestamp = jiffies;
3106 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3109 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3111 struct inode *inode = data->inode;
3113 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3116 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3117 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3120 if (task->tk_status >= 0) {
3121 renew_lease(NFS_SERVER(inode), data->timestamp);
3122 nfs_post_op_update_inode_force_wcc(inode, data->res.fattr);
3127 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3129 struct nfs_server *server = NFS_SERVER(data->inode);
3131 data->args.bitmask = server->cache_consistency_bitmask;
3132 data->res.server = server;
3133 data->timestamp = jiffies;
3135 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3138 static int nfs4_commit_done(struct rpc_task *task, struct nfs_write_data *data)
3140 struct inode *inode = data->inode;
3142 nfs4_sequence_done(NFS_SERVER(inode), &data->res.seq_res,
3144 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3145 nfs_restart_rpc(task, NFS_SERVER(inode)->nfs_client);
3148 nfs_refresh_inode(inode, data->res.fattr);
3152 static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
3154 struct nfs_server *server = NFS_SERVER(data->inode);
3156 data->args.bitmask = server->cache_consistency_bitmask;
3157 data->res.server = server;
3158 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3161 struct nfs4_renewdata {
3162 struct nfs_client *client;
3163 unsigned long timestamp;
3167 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3168 * standalone procedure for queueing an asynchronous RENEW.
3170 static void nfs4_renew_release(void *calldata)
3172 struct nfs4_renewdata *data = calldata;
3173 struct nfs_client *clp = data->client;
3175 if (atomic_read(&clp->cl_count) > 1)
3176 nfs4_schedule_state_renewal(clp);
3177 nfs_put_client(clp);
3181 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3183 struct nfs4_renewdata *data = calldata;
3184 struct nfs_client *clp = data->client;
3185 unsigned long timestamp = data->timestamp;
3187 if (task->tk_status < 0) {
3188 /* Unless we're shutting down, schedule state recovery! */
3189 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) != 0)
3190 nfs4_schedule_state_recovery(clp);
3193 spin_lock(&clp->cl_lock);
3194 if (time_before(clp->cl_last_renewal,timestamp))
3195 clp->cl_last_renewal = timestamp;
3196 spin_unlock(&clp->cl_lock);
3199 static const struct rpc_call_ops nfs4_renew_ops = {
3200 .rpc_call_done = nfs4_renew_done,
3201 .rpc_release = nfs4_renew_release,
3204 int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
3206 struct rpc_message msg = {
3207 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3211 struct nfs4_renewdata *data;
3213 if (!atomic_inc_not_zero(&clp->cl_count))
3215 data = kmalloc(sizeof(*data), GFP_KERNEL);
3219 data->timestamp = jiffies;
3220 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3221 &nfs4_renew_ops, data);
3224 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3226 struct rpc_message msg = {
3227 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3231 unsigned long now = jiffies;
3234 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3237 spin_lock(&clp->cl_lock);
3238 if (time_before(clp->cl_last_renewal,now))
3239 clp->cl_last_renewal = now;
3240 spin_unlock(&clp->cl_lock);
3244 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3246 return (server->caps & NFS_CAP_ACLS)
3247 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3248 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3251 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3252 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3255 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3257 static void buf_to_pages(const void *buf, size_t buflen,
3258 struct page **pages, unsigned int *pgbase)
3260 const void *p = buf;
3262 *pgbase = offset_in_page(buf);
3264 while (p < buf + buflen) {
3265 *(pages++) = virt_to_page(p);
3266 p += PAGE_CACHE_SIZE;
3270 struct nfs4_cached_acl {
3276 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3278 struct nfs_inode *nfsi = NFS_I(inode);
3280 spin_lock(&inode->i_lock);
3281 kfree(nfsi->nfs4_acl);
3282 nfsi->nfs4_acl = acl;
3283 spin_unlock(&inode->i_lock);
3286 static void nfs4_zap_acl_attr(struct inode *inode)
3288 nfs4_set_cached_acl(inode, NULL);
3291 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3293 struct nfs_inode *nfsi = NFS_I(inode);
3294 struct nfs4_cached_acl *acl;
3297 spin_lock(&inode->i_lock);
3298 acl = nfsi->nfs4_acl;
3301 if (buf == NULL) /* user is just asking for length */
3303 if (acl->cached == 0)
3305 ret = -ERANGE; /* see getxattr(2) man page */
3306 if (acl->len > buflen)
3308 memcpy(buf, acl->data, acl->len);
3312 spin_unlock(&inode->i_lock);
3316 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
3318 struct nfs4_cached_acl *acl;
3320 if (buf && acl_len <= PAGE_SIZE) {
3321 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3325 memcpy(acl->data, buf, acl_len);
3327 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3334 nfs4_set_cached_acl(inode, acl);
3337 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3339 struct page *pages[NFS4ACL_MAXPAGES];
3340 struct nfs_getaclargs args = {
3341 .fh = NFS_FH(inode),
3345 struct nfs_getaclres res = {
3349 struct rpc_message msg = {
3350 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3354 struct page *localpage = NULL;
3357 if (buflen < PAGE_SIZE) {
3358 /* As long as we're doing a round trip to the server anyway,
3359 * let's be prepared for a page of acl data. */
3360 localpage = alloc_page(GFP_KERNEL);
3361 resp_buf = page_address(localpage);
3362 if (localpage == NULL)
3364 args.acl_pages[0] = localpage;
3365 args.acl_pgbase = 0;
3366 args.acl_len = PAGE_SIZE;
3369 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
3371 ret = nfs4_call_sync(NFS_SERVER(inode), &msg, &args, &res, 0);
3374 if (res.acl_len > args.acl_len)
3375 nfs4_write_cached_acl(inode, NULL, res.acl_len);
3377 nfs4_write_cached_acl(inode, resp_buf, res.acl_len);
3380 if (res.acl_len > buflen)
3383 memcpy(buf, resp_buf, res.acl_len);
3388 __free_page(localpage);
3392 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3394 struct nfs4_exception exception = { };
3397 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3400 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3401 } while (exception.retry);
3405 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3407 struct nfs_server *server = NFS_SERVER(inode);
3410 if (!nfs4_server_supports_acls(server))
3412 ret = nfs_revalidate_inode(server, inode);
3415 ret = nfs4_read_cached_acl(inode, buf, buflen);
3418 return nfs4_get_acl_uncached(inode, buf, buflen);
3421 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3423 struct nfs_server *server = NFS_SERVER(inode);
3424 struct page *pages[NFS4ACL_MAXPAGES];
3425 struct nfs_setaclargs arg = {
3426 .fh = NFS_FH(inode),
3430 struct nfs_setaclres res;
3431 struct rpc_message msg = {
3432 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3438 if (!nfs4_server_supports_acls(server))
3440 nfs_inode_return_delegation(inode);
3441 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3442 ret = nfs4_call_sync(server, &msg, &arg, &res, 1);
3443 nfs_access_zap_cache(inode);
3444 nfs_zap_acl_cache(inode);
3448 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3450 struct nfs4_exception exception = { };
3453 err = nfs4_handle_exception(NFS_SERVER(inode),
3454 __nfs4_proc_set_acl(inode, buf, buflen),
3456 } while (exception.retry);
3461 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3463 struct nfs_client *clp = server->nfs_client;
3465 if (task->tk_status >= 0)
3467 switch(task->tk_status) {
3468 case -NFS4ERR_ADMIN_REVOKED:
3469 case -NFS4ERR_BAD_STATEID:
3470 case -NFS4ERR_OPENMODE:
3473 nfs4_state_mark_reclaim_nograce(clp, state);
3474 goto do_state_recovery;
3475 case -NFS4ERR_STALE_STATEID:
3478 nfs4_state_mark_reclaim_reboot(clp, state);
3479 case -NFS4ERR_STALE_CLIENTID:
3480 case -NFS4ERR_EXPIRED:
3481 goto do_state_recovery;
3482 #if defined(CONFIG_NFS_V4_1)
3483 case -NFS4ERR_BADSESSION:
3484 case -NFS4ERR_BADSLOT:
3485 case -NFS4ERR_BAD_HIGH_SLOT:
3486 case -NFS4ERR_DEADSESSION:
3487 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3488 case -NFS4ERR_SEQ_FALSE_RETRY:
3489 case -NFS4ERR_SEQ_MISORDERED:
3490 dprintk("%s ERROR %d, Reset session\n", __func__,
3492 nfs4_schedule_state_recovery(clp);
3493 task->tk_status = 0;
3495 #endif /* CONFIG_NFS_V4_1 */
3496 case -NFS4ERR_DELAY:
3497 nfs_inc_server_stats(server, NFSIOS_DELAY);
3498 case -NFS4ERR_GRACE:
3500 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3501 task->tk_status = 0;
3503 case -NFS4ERR_OLD_STATEID:
3504 task->tk_status = 0;
3507 task->tk_status = nfs4_map_errors(task->tk_status);
3510 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3511 nfs4_schedule_state_recovery(clp);
3512 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3513 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3514 task->tk_status = 0;
3518 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3519 unsigned short port, struct rpc_cred *cred,
3520 struct nfs4_setclientid_res *res)
3522 nfs4_verifier sc_verifier;
3523 struct nfs4_setclientid setclientid = {
3524 .sc_verifier = &sc_verifier,
3527 struct rpc_message msg = {
3528 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
3529 .rpc_argp = &setclientid,
3537 p = (__be32*)sc_verifier.data;
3538 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3539 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3542 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3543 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3545 rpc_peeraddr2str(clp->cl_rpcclient,
3547 rpc_peeraddr2str(clp->cl_rpcclient,
3549 clp->cl_rpcclient->cl_auth->au_ops->au_name,
3550 clp->cl_id_uniquifier);
3551 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
3552 sizeof(setclientid.sc_netid),
3553 rpc_peeraddr2str(clp->cl_rpcclient,
3554 RPC_DISPLAY_NETID));
3555 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3556 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3557 clp->cl_ipaddr, port >> 8, port & 255);
3559 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3560 if (status != -NFS4ERR_CLID_INUSE)
3565 ssleep(clp->cl_lease_time + 1);
3567 if (++clp->cl_id_uniquifier == 0)
3573 static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3574 struct nfs4_setclientid_res *arg,
3575 struct rpc_cred *cred)
3577 struct nfs_fsinfo fsinfo;
3578 struct rpc_message msg = {
3579 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
3581 .rpc_resp = &fsinfo,
3588 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3590 spin_lock(&clp->cl_lock);
3591 clp->cl_lease_time = fsinfo.lease_time * HZ;
3592 clp->cl_last_renewal = now;
3593 spin_unlock(&clp->cl_lock);
3598 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
3599 struct nfs4_setclientid_res *arg,
3600 struct rpc_cred *cred)
3605 err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
3609 case -NFS4ERR_RESOURCE:
3610 /* The IBM lawyers misread another document! */
3611 case -NFS4ERR_DELAY:
3613 err = nfs4_delay(clp->cl_rpcclient, &timeout);
3619 struct nfs4_delegreturndata {
3620 struct nfs4_delegreturnargs args;
3621 struct nfs4_delegreturnres res;
3623 nfs4_stateid stateid;
3624 unsigned long timestamp;
3625 struct nfs_fattr fattr;
3629 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
3631 struct nfs4_delegreturndata *data = calldata;
3633 nfs4_sequence_done(data->res.server, &data->res.seq_res,
3636 switch (task->tk_status) {
3637 case -NFS4ERR_STALE_STATEID:
3638 case -NFS4ERR_EXPIRED:
3640 renew_lease(data->res.server, data->timestamp);
3643 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
3645 nfs_restart_rpc(task, data->res.server->nfs_client);
3649 data->rpc_status = task->tk_status;
3652 static void nfs4_delegreturn_release(void *calldata)
3657 #if defined(CONFIG_NFS_V4_1)
3658 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3660 struct nfs4_delegreturndata *d_data;
3662 d_data = (struct nfs4_delegreturndata *)data;
3664 if (nfs4_setup_sequence(d_data->res.server,
3665 &d_data->args.seq_args,
3666 &d_data->res.seq_res, 1, task))
3668 rpc_call_start(task);
3670 #endif /* CONFIG_NFS_V4_1 */
3672 static const struct rpc_call_ops nfs4_delegreturn_ops = {
3673 #if defined(CONFIG_NFS_V4_1)
3674 .rpc_call_prepare = nfs4_delegreturn_prepare,
3675 #endif /* CONFIG_NFS_V4_1 */
3676 .rpc_call_done = nfs4_delegreturn_done,
3677 .rpc_release = nfs4_delegreturn_release,
3680 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3682 struct nfs4_delegreturndata *data;
3683 struct nfs_server *server = NFS_SERVER(inode);
3684 struct rpc_task *task;
3685 struct rpc_message msg = {
3686 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
3689 struct rpc_task_setup task_setup_data = {
3690 .rpc_client = server->client,
3691 .rpc_message = &msg,
3692 .callback_ops = &nfs4_delegreturn_ops,
3693 .flags = RPC_TASK_ASYNC,
3697 data = kzalloc(sizeof(*data), GFP_NOFS);
3700 data->args.fhandle = &data->fh;
3701 data->args.stateid = &data->stateid;
3702 data->args.bitmask = server->attr_bitmask;
3703 nfs_copy_fh(&data->fh, NFS_FH(inode));
3704 memcpy(&data->stateid, stateid, sizeof(data->stateid));
3705 data->res.fattr = &data->fattr;
3706 data->res.server = server;
3707 data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3708 nfs_fattr_init(data->res.fattr);
3709 data->timestamp = jiffies;
3710 data->rpc_status = 0;
3712 task_setup_data.callback_data = data;
3713 msg.rpc_argp = &data->args,
3714 msg.rpc_resp = &data->res,
3715 task = rpc_run_task(&task_setup_data);
3717 return PTR_ERR(task);
3720 status = nfs4_wait_for_completion_rpc_task(task);
3723 status = data->rpc_status;
3726 nfs_refresh_inode(inode, &data->fattr);
3732 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
3734 struct nfs_server *server = NFS_SERVER(inode);
3735 struct nfs4_exception exception = { };
3738 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
3740 case -NFS4ERR_STALE_STATEID:
3741 case -NFS4ERR_EXPIRED:
3745 err = nfs4_handle_exception(server, err, &exception);
3746 } while (exception.retry);
3750 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3751 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3754 * sleep, with exponential backoff, and retry the LOCK operation.
3756 static unsigned long
3757 nfs4_set_lock_task_retry(unsigned long timeout)
3759 schedule_timeout_killable(timeout);
3761 if (timeout > NFS4_LOCK_MAXTIMEOUT)
3762 return NFS4_LOCK_MAXTIMEOUT;
3766 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3768 struct inode *inode = state->inode;
3769 struct nfs_server *server = NFS_SERVER(inode);
3770 struct nfs_client *clp = server->nfs_client;
3771 struct nfs_lockt_args arg = {
3772 .fh = NFS_FH(inode),
3775 struct nfs_lockt_res res = {
3778 struct rpc_message msg = {
3779 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
3782 .rpc_cred = state->owner->so_cred,
3784 struct nfs4_lock_state *lsp;
3787 arg.lock_owner.clientid = clp->cl_clientid;
3788 status = nfs4_set_lock_state(state, request);
3791 lsp = request->fl_u.nfs4_fl.owner;
3792 arg.lock_owner.id = lsp->ls_id.id;
3793 status = nfs4_call_sync(server, &msg, &arg, &res, 1);
3796 request->fl_type = F_UNLCK;
3798 case -NFS4ERR_DENIED:
3801 request->fl_ops->fl_release_private(request);
3806 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3808 struct nfs4_exception exception = { };
3812 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3813 _nfs4_proc_getlk(state, cmd, request),
3815 } while (exception.retry);
3819 static int do_vfs_lock(struct file *file, struct file_lock *fl)
3822 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
3824 res = posix_lock_file_wait(file, fl);
3827 res = flock_lock_file_wait(file, fl);
3835 struct nfs4_unlockdata {
3836 struct nfs_locku_args arg;
3837 struct nfs_locku_res res;
3838 struct nfs4_lock_state *lsp;
3839 struct nfs_open_context *ctx;
3840 struct file_lock fl;
3841 const struct nfs_server *server;
3842 unsigned long timestamp;
3845 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3846 struct nfs_open_context *ctx,
3847 struct nfs4_lock_state *lsp,
3848 struct nfs_seqid *seqid)
3850 struct nfs4_unlockdata *p;
3851 struct inode *inode = lsp->ls_state->inode;
3853 p = kzalloc(sizeof(*p), GFP_NOFS);
3856 p->arg.fh = NFS_FH(inode);
3858 p->arg.seqid = seqid;
3859 p->res.seqid = seqid;
3860 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
3861 p->arg.stateid = &lsp->ls_stateid;
3863 atomic_inc(&lsp->ls_count);
3864 /* Ensure we don't close file until we're done freeing locks! */
3865 p->ctx = get_nfs_open_context(ctx);
3866 memcpy(&p->fl, fl, sizeof(p->fl));
3867 p->server = NFS_SERVER(inode);
3871 static void nfs4_locku_release_calldata(void *data)
3873 struct nfs4_unlockdata *calldata = data;
3874 nfs_free_seqid(calldata->arg.seqid);
3875 nfs4_put_lock_state(calldata->lsp);
3876 put_nfs_open_context(calldata->ctx);
3880 static void nfs4_locku_done(struct rpc_task *task, void *data)
3882 struct nfs4_unlockdata *calldata = data;
3884 nfs4_sequence_done(calldata->server, &calldata->res.seq_res,
3886 if (RPC_ASSASSINATED(task))
3888 switch (task->tk_status) {
3890 memcpy(calldata->lsp->ls_stateid.data,
3891 calldata->res.stateid.data,
3892 sizeof(calldata->lsp->ls_stateid.data));
3893 renew_lease(calldata->server, calldata->timestamp);
3895 case -NFS4ERR_BAD_STATEID:
3896 case -NFS4ERR_OLD_STATEID:
3897 case -NFS4ERR_STALE_STATEID:
3898 case -NFS4ERR_EXPIRED:
3901 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
3902 nfs_restart_rpc(task,
3903 calldata->server->nfs_client);
3907 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
3909 struct nfs4_unlockdata *calldata = data;
3911 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
3913 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
3914 /* Note: exit _without_ running nfs4_locku_done */
3915 task->tk_action = NULL;
3918 calldata->timestamp = jiffies;
3919 if (nfs4_setup_sequence(calldata->server,
3920 &calldata->arg.seq_args,
3921 &calldata->res.seq_res, 1, task))
3923 rpc_call_start(task);
3926 static const struct rpc_call_ops nfs4_locku_ops = {
3927 .rpc_call_prepare = nfs4_locku_prepare,
3928 .rpc_call_done = nfs4_locku_done,
3929 .rpc_release = nfs4_locku_release_calldata,
3932 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3933 struct nfs_open_context *ctx,
3934 struct nfs4_lock_state *lsp,
3935 struct nfs_seqid *seqid)
3937 struct nfs4_unlockdata *data;
3938 struct rpc_message msg = {
3939 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
3940 .rpc_cred = ctx->cred,
3942 struct rpc_task_setup task_setup_data = {
3943 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
3944 .rpc_message = &msg,
3945 .callback_ops = &nfs4_locku_ops,
3946 .workqueue = nfsiod_workqueue,
3947 .flags = RPC_TASK_ASYNC,
3950 /* Ensure this is an unlock - when canceling a lock, the
3951 * canceled lock is passed in, and it won't be an unlock.
3953 fl->fl_type = F_UNLCK;
3955 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
3957 nfs_free_seqid(seqid);
3958 return ERR_PTR(-ENOMEM);
3961 msg.rpc_argp = &data->arg,
3962 msg.rpc_resp = &data->res,
3963 task_setup_data.callback_data = data;
3964 return rpc_run_task(&task_setup_data);
3967 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
3969 struct nfs_inode *nfsi = NFS_I(state->inode);
3970 struct nfs_seqid *seqid;
3971 struct nfs4_lock_state *lsp;
3972 struct rpc_task *task;
3974 unsigned char fl_flags = request->fl_flags;
3976 status = nfs4_set_lock_state(state, request);
3977 /* Unlock _before_ we do the RPC call */
3978 request->fl_flags |= FL_EXISTS;
3979 down_read(&nfsi->rwsem);
3980 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
3981 up_read(&nfsi->rwsem);
3984 up_read(&nfsi->rwsem);
3987 /* Is this a delegated lock? */
3988 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
3990 lsp = request->fl_u.nfs4_fl.owner;
3991 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
3995 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
3996 status = PTR_ERR(task);
3999 status = nfs4_wait_for_completion_rpc_task(task);
4002 request->fl_flags = fl_flags;
4006 struct nfs4_lockdata {
4007 struct nfs_lock_args arg;
4008 struct nfs_lock_res res;
4009 struct nfs4_lock_state *lsp;
4010 struct nfs_open_context *ctx;
4011 struct file_lock fl;
4012 unsigned long timestamp;
4015 struct nfs_server *server;
4018 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4019 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4022 struct nfs4_lockdata *p;
4023 struct inode *inode = lsp->ls_state->inode;
4024 struct nfs_server *server = NFS_SERVER(inode);
4026 p = kzalloc(sizeof(*p), gfp_mask);
4030 p->arg.fh = NFS_FH(inode);
4032 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4033 if (p->arg.open_seqid == NULL)
4035 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4036 if (p->arg.lock_seqid == NULL)
4037 goto out_free_seqid;
4038 p->arg.lock_stateid = &lsp->ls_stateid;
4039 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4040 p->arg.lock_owner.id = lsp->ls_id.id;
4041 p->res.lock_seqid = p->arg.lock_seqid;
4042 p->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4045 atomic_inc(&lsp->ls_count);
4046 p->ctx = get_nfs_open_context(ctx);
4047 memcpy(&p->fl, fl, sizeof(p->fl));
4050 nfs_free_seqid(p->arg.open_seqid);
4056 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4058 struct nfs4_lockdata *data = calldata;
4059 struct nfs4_state *state = data->lsp->ls_state;
4061 dprintk("%s: begin!\n", __func__);
4062 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4064 /* Do we need to do an open_to_lock_owner? */
4065 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4066 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4068 data->arg.open_stateid = &state->stateid;
4069 data->arg.new_lock_owner = 1;
4070 data->res.open_seqid = data->arg.open_seqid;
4072 data->arg.new_lock_owner = 0;
4073 data->timestamp = jiffies;
4074 if (nfs4_setup_sequence(data->server,
4075 &data->arg.seq_args,
4076 &data->res.seq_res, 1, task))
4078 rpc_call_start(task);
4079 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4082 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4084 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4085 nfs4_lock_prepare(task, calldata);
4088 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4090 struct nfs4_lockdata *data = calldata;
4092 dprintk("%s: begin!\n", __func__);
4094 nfs4_sequence_done(data->server, &data->res.seq_res,
4097 data->rpc_status = task->tk_status;
4098 if (RPC_ASSASSINATED(task))
4100 if (data->arg.new_lock_owner != 0) {
4101 if (data->rpc_status == 0)
4102 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4106 if (data->rpc_status == 0) {
4107 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data,
4108 sizeof(data->lsp->ls_stateid.data));
4109 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4110 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
4113 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4116 static void nfs4_lock_release(void *calldata)
4118 struct nfs4_lockdata *data = calldata;
4120 dprintk("%s: begin!\n", __func__);
4121 nfs_free_seqid(data->arg.open_seqid);
4122 if (data->cancelled != 0) {
4123 struct rpc_task *task;
4124 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4125 data->arg.lock_seqid);
4128 dprintk("%s: cancelling lock!\n", __func__);
4130 nfs_free_seqid(data->arg.lock_seqid);
4131 nfs4_put_lock_state(data->lsp);
4132 put_nfs_open_context(data->ctx);
4134 dprintk("%s: done!\n", __func__);
4137 static const struct rpc_call_ops nfs4_lock_ops = {
4138 .rpc_call_prepare = nfs4_lock_prepare,
4139 .rpc_call_done = nfs4_lock_done,
4140 .rpc_release = nfs4_lock_release,
4143 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4144 .rpc_call_prepare = nfs4_recover_lock_prepare,
4145 .rpc_call_done = nfs4_lock_done,
4146 .rpc_release = nfs4_lock_release,
4149 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4151 struct nfs_client *clp = server->nfs_client;
4152 struct nfs4_state *state = lsp->ls_state;
4155 case -NFS4ERR_ADMIN_REVOKED:
4156 case -NFS4ERR_BAD_STATEID:
4157 case -NFS4ERR_EXPIRED:
4158 if (new_lock_owner != 0 ||
4159 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4160 nfs4_state_mark_reclaim_nograce(clp, state);
4161 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4163 case -NFS4ERR_STALE_STATEID:
4164 if (new_lock_owner != 0 ||
4165 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4166 nfs4_state_mark_reclaim_reboot(clp, state);
4167 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4171 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4173 struct nfs4_lockdata *data;
4174 struct rpc_task *task;
4175 struct rpc_message msg = {
4176 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4177 .rpc_cred = state->owner->so_cred,
4179 struct rpc_task_setup task_setup_data = {
4180 .rpc_client = NFS_CLIENT(state->inode),
4181 .rpc_message = &msg,
4182 .callback_ops = &nfs4_lock_ops,
4183 .workqueue = nfsiod_workqueue,
4184 .flags = RPC_TASK_ASYNC,
4188 dprintk("%s: begin!\n", __func__);
4189 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4190 fl->fl_u.nfs4_fl.owner,
4191 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4195 data->arg.block = 1;
4196 if (recovery_type > NFS_LOCK_NEW) {
4197 if (recovery_type == NFS_LOCK_RECLAIM)
4198 data->arg.reclaim = NFS_LOCK_RECLAIM;
4199 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4201 msg.rpc_argp = &data->arg,
4202 msg.rpc_resp = &data->res,
4203 task_setup_data.callback_data = data;
4204 task = rpc_run_task(&task_setup_data);
4206 return PTR_ERR(task);
4207 ret = nfs4_wait_for_completion_rpc_task(task);
4209 ret = data->rpc_status;
4211 nfs4_handle_setlk_error(data->server, data->lsp,
4212 data->arg.new_lock_owner, ret);
4214 data->cancelled = 1;
4216 dprintk("%s: done, ret = %d!\n", __func__, ret);
4220 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4222 struct nfs_server *server = NFS_SERVER(state->inode);
4223 struct nfs4_exception exception = { };
4227 /* Cache the lock if possible... */
4228 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4230 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4231 if (err != -NFS4ERR_DELAY && err != -EKEYEXPIRED)
4233 nfs4_handle_exception(server, err, &exception);
4234 } while (exception.retry);
4238 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4240 struct nfs_server *server = NFS_SERVER(state->inode);
4241 struct nfs4_exception exception = { };
4244 err = nfs4_set_lock_state(state, request);
4248 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4250 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4254 case -NFS4ERR_GRACE:
4255 case -NFS4ERR_DELAY:
4257 nfs4_handle_exception(server, err, &exception);
4260 } while (exception.retry);
4265 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4267 struct nfs_inode *nfsi = NFS_I(state->inode);
4268 unsigned char fl_flags = request->fl_flags;
4269 int status = -ENOLCK;
4271 if ((fl_flags & FL_POSIX) &&
4272 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4274 /* Is this a delegated open? */
4275 status = nfs4_set_lock_state(state, request);
4278 request->fl_flags |= FL_ACCESS;
4279 status = do_vfs_lock(request->fl_file, request);
4282 down_read(&nfsi->rwsem);
4283 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4284 /* Yes: cache locks! */
4285 /* ...but avoid races with delegation recall... */
4286 request->fl_flags = fl_flags & ~FL_SLEEP;
4287 status = do_vfs_lock(request->fl_file, request);
4290 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4293 /* Note: we always want to sleep here! */
4294 request->fl_flags = fl_flags | FL_SLEEP;
4295 if (do_vfs_lock(request->fl_file, request) < 0)
4296 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__);
4298 up_read(&nfsi->rwsem);
4300 request->fl_flags = fl_flags;
4304 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4306 struct nfs4_exception exception = { };
4310 err = _nfs4_proc_setlk(state, cmd, request);
4311 if (err == -NFS4ERR_DENIED)
4313 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4315 } while (exception.retry);
4320 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4322 struct nfs_open_context *ctx;
4323 struct nfs4_state *state;
4324 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4327 /* verify open state */
4328 ctx = nfs_file_open_context(filp);
4331 if (request->fl_start < 0 || request->fl_end < 0)
4334 if (IS_GETLK(cmd)) {
4336 return nfs4_proc_getlk(state, F_GETLK, request);
4340 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4343 if (request->fl_type == F_UNLCK) {
4345 return nfs4_proc_unlck(state, cmd, request);
4352 status = nfs4_proc_setlk(state, cmd, request);
4353 if ((status != -EAGAIN) || IS_SETLK(cmd))
4355 timeout = nfs4_set_lock_task_retry(timeout);
4356 status = -ERESTARTSYS;
4359 } while(status < 0);
4363 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4365 struct nfs_server *server = NFS_SERVER(state->inode);
4366 struct nfs4_exception exception = { };
4369 err = nfs4_set_lock_state(state, fl);
4373 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4376 printk(KERN_ERR "%s: unhandled error %d.\n",
4381 case -NFS4ERR_EXPIRED:
4382 case -NFS4ERR_STALE_CLIENTID:
4383 case -NFS4ERR_STALE_STATEID:
4384 case -NFS4ERR_BADSESSION:
4385 case -NFS4ERR_BADSLOT:
4386 case -NFS4ERR_BAD_HIGH_SLOT:
4387 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4388 case -NFS4ERR_DEADSESSION:
4389 nfs4_schedule_state_recovery(server->nfs_client);
4393 * The show must go on: exit, but mark the
4394 * stateid as needing recovery.
4396 case -NFS4ERR_ADMIN_REVOKED:
4397 case -NFS4ERR_BAD_STATEID:
4398 case -NFS4ERR_OPENMODE:
4399 nfs4_state_mark_reclaim_nograce(server->nfs_client, state);
4403 case -NFS4ERR_DENIED:
4404 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4407 case -NFS4ERR_DELAY:
4411 err = nfs4_handle_exception(server, err, &exception);
4412 } while (exception.retry);
4417 static void nfs4_release_lockowner_release(void *calldata)
4422 const struct rpc_call_ops nfs4_release_lockowner_ops = {
4423 .rpc_release = nfs4_release_lockowner_release,
4426 void nfs4_release_lockowner(const struct nfs4_lock_state *lsp)
4428 struct nfs_server *server = lsp->ls_state->owner->so_server;
4429 struct nfs_release_lockowner_args *args;
4430 struct rpc_message msg = {
4431 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
4434 if (server->nfs_client->cl_mvops->minor_version != 0)
4436 args = kmalloc(sizeof(*args), GFP_NOFS);
4439 args->lock_owner.clientid = server->nfs_client->cl_clientid;
4440 args->lock_owner.id = lsp->ls_id.id;
4441 msg.rpc_argp = args;
4442 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args);
4445 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4447 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
4448 size_t buflen, int flags)
4450 struct inode *inode = dentry->d_inode;
4452 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4455 return nfs4_proc_set_acl(inode, buf, buflen);
4458 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4459 * and that's what we'll do for e.g. user attributes that haven't been set.
4460 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4461 * attributes in kernel-managed attribute namespaces. */
4462 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
4465 struct inode *inode = dentry->d_inode;
4467 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
4470 return nfs4_proc_get_acl(inode, buf, buflen);
4473 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
4475 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
4477 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
4479 if (buf && buflen < len)
4482 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
4486 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4488 if (!((fattr->valid & NFS_ATTR_FATTR_FILEID) &&
4489 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4490 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)))
4493 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4494 NFS_ATTR_FATTR_NLINK;
4495 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4499 int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
4500 struct nfs4_fs_locations *fs_locations, struct page *page)
4502 struct nfs_server *server = NFS_SERVER(dir);
4504 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
4505 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID,
4507 struct nfs4_fs_locations_arg args = {
4508 .dir_fh = NFS_FH(dir),
4513 struct nfs4_fs_locations_res res = {
4514 .fs_locations = fs_locations,
4516 struct rpc_message msg = {
4517 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
4523 dprintk("%s: start\n", __func__);
4524 nfs_fattr_init(&fs_locations->fattr);
4525 fs_locations->server = server;
4526 fs_locations->nlocations = 0;
4527 status = nfs4_call_sync(server, &msg, &args, &res, 0);
4528 nfs_fixup_referral_attributes(&fs_locations->fattr);
4529 dprintk("%s: returned status = %d\n", __func__, status);
4533 #ifdef CONFIG_NFS_V4_1
4535 * nfs4_proc_exchange_id()
4537 * Since the clientid has expired, all compounds using sessions
4538 * associated with the stale clientid will be returning
4539 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4540 * be in some phase of session reset.
4542 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4544 nfs4_verifier verifier;
4545 struct nfs41_exchange_id_args args = {
4547 .flags = clp->cl_exchange_flags,
4549 struct nfs41_exchange_id_res res = {
4553 struct rpc_message msg = {
4554 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
4561 dprintk("--> %s\n", __func__);
4562 BUG_ON(clp == NULL);
4564 /* Remove server-only flags */
4565 args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R;
4567 p = (u32 *)verifier.data;
4568 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4569 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4570 args.verifier = &verifier;
4573 args.id_len = scnprintf(args.id, sizeof(args.id),
4576 rpc_peeraddr2str(clp->cl_rpcclient,
4578 clp->cl_id_uniquifier);
4580 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
4582 if (status != -NFS4ERR_CLID_INUSE)
4588 if (++clp->cl_id_uniquifier == 0)
4592 dprintk("<-- %s status= %d\n", __func__, status);
4596 struct nfs4_get_lease_time_data {
4597 struct nfs4_get_lease_time_args *args;
4598 struct nfs4_get_lease_time_res *res;
4599 struct nfs_client *clp;
4602 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4606 struct nfs4_get_lease_time_data *data =
4607 (struct nfs4_get_lease_time_data *)calldata;
4609 dprintk("--> %s\n", __func__);
4610 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4611 /* just setup sequence, do not trigger session recovery
4612 since we're invoked within one */
4613 ret = nfs41_setup_sequence(data->clp->cl_session,
4614 &data->args->la_seq_args,
4615 &data->res->lr_seq_res, 0, task);
4617 BUG_ON(ret == -EAGAIN);
4618 rpc_call_start(task);
4619 dprintk("<-- %s\n", __func__);
4623 * Called from nfs4_state_manager thread for session setup, so don't recover
4624 * from sequence operation or clientid errors.
4626 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4628 struct nfs4_get_lease_time_data *data =
4629 (struct nfs4_get_lease_time_data *)calldata;
4631 dprintk("--> %s\n", __func__);
4632 nfs41_sequence_done(&data->res->lr_seq_res);
4633 switch (task->tk_status) {
4634 case -NFS4ERR_DELAY:
4635 case -NFS4ERR_GRACE:
4637 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
4638 rpc_delay(task, NFS4_POLL_RETRY_MIN);
4639 task->tk_status = 0;
4640 nfs_restart_rpc(task, data->clp);
4643 dprintk("<-- %s\n", __func__);
4646 struct rpc_call_ops nfs4_get_lease_time_ops = {
4647 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4648 .rpc_call_done = nfs4_get_lease_time_done,
4651 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4653 struct rpc_task *task;
4654 struct nfs4_get_lease_time_args args;
4655 struct nfs4_get_lease_time_res res = {
4656 .lr_fsinfo = fsinfo,
4658 struct nfs4_get_lease_time_data data = {
4663 struct rpc_message msg = {
4664 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
4668 struct rpc_task_setup task_setup = {
4669 .rpc_client = clp->cl_rpcclient,
4670 .rpc_message = &msg,
4671 .callback_ops = &nfs4_get_lease_time_ops,
4672 .callback_data = &data
4676 res.lr_seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
4677 dprintk("--> %s\n", __func__);
4678 task = rpc_run_task(&task_setup);
4681 status = PTR_ERR(task);
4683 status = task->tk_status;
4686 dprintk("<-- %s return %d\n", __func__, status);
4692 * Reset a slot table
4694 static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
4697 struct nfs4_slot *new = NULL;
4701 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
4702 max_reqs, tbl->max_slots);
4704 /* Does the newly negotiated max_reqs match the existing slot table? */
4705 if (max_reqs != tbl->max_slots) {
4707 new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
4714 spin_lock(&tbl->slot_tbl_lock);
4717 tbl->max_slots = max_reqs;
4719 for (i = 0; i < tbl->max_slots; ++i)
4720 tbl->slots[i].seq_nr = ivalue;
4721 spin_unlock(&tbl->slot_tbl_lock);
4722 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4723 tbl, tbl->slots, tbl->max_slots);
4725 dprintk("<-- %s: return %d\n", __func__, ret);
4730 * Reset the forechannel and backchannel slot tables
4732 static int nfs4_reset_slot_tables(struct nfs4_session *session)
4736 status = nfs4_reset_slot_table(&session->fc_slot_table,
4737 session->fc_attrs.max_reqs, 1);
4741 status = nfs4_reset_slot_table(&session->bc_slot_table,
4742 session->bc_attrs.max_reqs, 0);
4746 /* Destroy the slot table */
4747 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
4749 if (session->fc_slot_table.slots != NULL) {
4750 kfree(session->fc_slot_table.slots);
4751 session->fc_slot_table.slots = NULL;
4753 if (session->bc_slot_table.slots != NULL) {
4754 kfree(session->bc_slot_table.slots);
4755 session->bc_slot_table.slots = NULL;
4761 * Initialize slot table
4763 static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
4764 int max_slots, int ivalue)
4766 struct nfs4_slot *slot;
4769 BUG_ON(max_slots > NFS4_MAX_SLOT_TABLE);
4771 dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
4773 slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
4778 spin_lock(&tbl->slot_tbl_lock);
4779 tbl->max_slots = max_slots;
4781 tbl->highest_used_slotid = -1; /* no slot is currently used */
4782 spin_unlock(&tbl->slot_tbl_lock);
4783 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
4784 tbl, tbl->slots, tbl->max_slots);
4786 dprintk("<-- %s: return %d\n", __func__, ret);
4791 * Initialize the forechannel and backchannel tables
4793 static int nfs4_init_slot_tables(struct nfs4_session *session)
4795 struct nfs4_slot_table *tbl;
4798 tbl = &session->fc_slot_table;
4799 if (tbl->slots == NULL) {
4800 status = nfs4_init_slot_table(tbl,
4801 session->fc_attrs.max_reqs, 1);
4806 tbl = &session->bc_slot_table;
4807 if (tbl->slots == NULL) {
4808 status = nfs4_init_slot_table(tbl,
4809 session->bc_attrs.max_reqs, 0);
4811 nfs4_destroy_slot_tables(session);
4817 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
4819 struct nfs4_session *session;
4820 struct nfs4_slot_table *tbl;
4822 session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
4826 init_completion(&session->complete);
4828 tbl = &session->fc_slot_table;
4829 tbl->highest_used_slotid = -1;
4830 spin_lock_init(&tbl->slot_tbl_lock);
4831 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
4833 tbl = &session->bc_slot_table;
4834 tbl->highest_used_slotid = -1;
4835 spin_lock_init(&tbl->slot_tbl_lock);
4836 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
4838 session->session_state = 1<<NFS4_SESSION_INITING;
4844 void nfs4_destroy_session(struct nfs4_session *session)
4846 nfs4_proc_destroy_session(session);
4847 dprintk("%s Destroy backchannel for xprt %p\n",
4848 __func__, session->clp->cl_rpcclient->cl_xprt);
4849 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt,
4850 NFS41_BC_MIN_CALLBACKS);
4851 nfs4_destroy_slot_tables(session);
4856 * Initialize the values to be used by the client in CREATE_SESSION
4857 * If nfs4_init_session set the fore channel request and response sizes,
4860 * Set the back channel max_resp_sz_cached to zero to force the client to
4861 * always set csa_cachethis to FALSE because the current implementation
4862 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4864 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
4866 struct nfs4_session *session = args->client->cl_session;
4867 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
4868 mxresp_sz = session->fc_attrs.max_resp_sz;
4871 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
4873 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
4874 /* Fore channel attributes */
4875 args->fc_attrs.headerpadsz = 0;
4876 args->fc_attrs.max_rqst_sz = mxrqst_sz;
4877 args->fc_attrs.max_resp_sz = mxresp_sz;
4878 args->fc_attrs.max_ops = NFS4_MAX_OPS;
4879 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs;
4881 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4882 "max_ops=%u max_reqs=%u\n",
4884 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
4885 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
4887 /* Back channel attributes */
4888 args->bc_attrs.headerpadsz = 0;
4889 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
4890 args->bc_attrs.max_resp_sz = PAGE_SIZE;
4891 args->bc_attrs.max_resp_sz_cached = 0;
4892 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
4893 args->bc_attrs.max_reqs = 1;
4895 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4896 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4898 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
4899 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
4900 args->bc_attrs.max_reqs);
4903 static int _verify_channel_attr(char *chan, char *attr_name, u32 sent, u32 rcvd)
4907 printk(KERN_WARNING "%s: Session INVALID: %s channel %s increased. "
4908 "sent=%u rcvd=%u\n", __func__, chan, attr_name, sent, rcvd);
4912 #define _verify_fore_channel_attr(_name_) \
4913 _verify_channel_attr("fore", #_name_, \
4914 args->fc_attrs._name_, \
4915 session->fc_attrs._name_)
4917 #define _verify_back_channel_attr(_name_) \
4918 _verify_channel_attr("back", #_name_, \
4919 args->bc_attrs._name_, \
4920 session->bc_attrs._name_)
4923 * The server is not allowed to increase the fore channel header pad size,
4924 * maximum response size, or maximum number of operations.
4926 * The back channel attributes are only negotiatied down: We send what the
4927 * (back channel) server insists upon.
4929 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
4930 struct nfs4_session *session)
4934 ret |= _verify_fore_channel_attr(headerpadsz);
4935 ret |= _verify_fore_channel_attr(max_resp_sz);
4936 ret |= _verify_fore_channel_attr(max_ops);
4938 ret |= _verify_back_channel_attr(headerpadsz);
4939 ret |= _verify_back_channel_attr(max_rqst_sz);
4940 ret |= _verify_back_channel_attr(max_resp_sz);
4941 ret |= _verify_back_channel_attr(max_resp_sz_cached);
4942 ret |= _verify_back_channel_attr(max_ops);
4943 ret |= _verify_back_channel_attr(max_reqs);
4948 static int _nfs4_proc_create_session(struct nfs_client *clp)
4950 struct nfs4_session *session = clp->cl_session;
4951 struct nfs41_create_session_args args = {
4953 .cb_program = NFS4_CALLBACK,
4955 struct nfs41_create_session_res res = {
4958 struct rpc_message msg = {
4959 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
4965 nfs4_init_channel_attrs(&args);
4966 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
4968 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
4971 /* Verify the session's negotiated channel_attrs values */
4972 status = nfs4_verify_channel_attrs(&args, session);
4974 /* Increment the clientid slot sequence id */
4982 * Issues a CREATE_SESSION operation to the server.
4983 * It is the responsibility of the caller to verify the session is
4984 * expired before calling this routine.
4986 int nfs4_proc_create_session(struct nfs_client *clp)
4990 struct nfs4_session *session = clp->cl_session;
4992 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
4994 status = _nfs4_proc_create_session(clp);
4998 /* Init and reset the fore channel */
4999 status = nfs4_init_slot_tables(session);
5000 dprintk("slot table initialization returned %d\n", status);
5003 status = nfs4_reset_slot_tables(session);
5004 dprintk("slot table reset returned %d\n", status);
5008 ptr = (unsigned *)&session->sess_id.data[0];
5009 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5010 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5012 dprintk("<-- %s\n", __func__);
5017 * Issue the over-the-wire RPC DESTROY_SESSION.
5018 * The caller must serialize access to this routine.
5020 int nfs4_proc_destroy_session(struct nfs4_session *session)
5023 struct rpc_message msg;
5025 dprintk("--> nfs4_proc_destroy_session\n");
5027 /* session is still being setup */
5028 if (session->clp->cl_cons_state != NFS_CS_READY)
5031 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION];
5032 msg.rpc_argp = session;
5033 msg.rpc_resp = NULL;
5034 msg.rpc_cred = NULL;
5035 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, 0);
5039 "Got error %d from the server on DESTROY_SESSION. "
5040 "Session has been destroyed regardless...\n", status);
5042 dprintk("<-- nfs4_proc_destroy_session\n");
5046 int nfs4_init_session(struct nfs_server *server)
5048 struct nfs_client *clp = server->nfs_client;
5049 struct nfs4_session *session;
5050 unsigned int rsize, wsize;
5053 if (!nfs4_has_session(clp))
5056 session = clp->cl_session;
5057 if (!test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state))
5060 rsize = server->rsize;
5062 rsize = NFS_MAX_FILE_IO_SIZE;
5063 wsize = server->wsize;
5065 wsize = NFS_MAX_FILE_IO_SIZE;
5067 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5068 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5070 ret = nfs4_recover_expired_lease(server);
5072 ret = nfs4_check_client_ready(clp);
5077 * Renew the cl_session lease.
5079 struct nfs4_sequence_data {
5080 struct nfs_client *clp;
5081 struct nfs4_sequence_args args;
5082 struct nfs4_sequence_res res;
5085 static void nfs41_sequence_release(void *data)
5087 struct nfs4_sequence_data *calldata = data;
5088 struct nfs_client *clp = calldata->clp;
5090 if (atomic_read(&clp->cl_count) > 1)
5091 nfs4_schedule_state_renewal(clp);
5092 nfs_put_client(clp);
5096 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5098 switch(task->tk_status) {
5099 case -NFS4ERR_DELAY:
5101 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5104 nfs4_schedule_state_recovery(clp);
5109 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5111 struct nfs4_sequence_data *calldata = data;
5112 struct nfs_client *clp = calldata->clp;
5114 nfs41_sequence_done(task->tk_msg.rpc_resp);
5116 if (task->tk_status < 0) {
5117 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5118 if (atomic_read(&clp->cl_count) == 1)
5121 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5122 rpc_restart_call_prepare(task);
5126 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5128 dprintk("<-- %s\n", __func__);
5131 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5133 struct nfs4_sequence_data *calldata = data;
5134 struct nfs_client *clp = calldata->clp;
5135 struct nfs4_sequence_args *args;
5136 struct nfs4_sequence_res *res;
5138 args = task->tk_msg.rpc_argp;
5139 res = task->tk_msg.rpc_resp;
5141 if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task))
5143 rpc_call_start(task);
5146 static const struct rpc_call_ops nfs41_sequence_ops = {
5147 .rpc_call_done = nfs41_sequence_call_done,
5148 .rpc_call_prepare = nfs41_sequence_prepare,
5149 .rpc_release = nfs41_sequence_release,
5152 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5154 struct nfs4_sequence_data *calldata;
5155 struct rpc_message msg = {
5156 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5159 struct rpc_task_setup task_setup_data = {
5160 .rpc_client = clp->cl_rpcclient,
5161 .rpc_message = &msg,
5162 .callback_ops = &nfs41_sequence_ops,
5163 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
5166 if (!atomic_inc_not_zero(&clp->cl_count))
5167 return ERR_PTR(-EIO);
5168 calldata = kmalloc(sizeof(*calldata), GFP_NOFS);
5169 if (calldata == NULL) {
5170 nfs_put_client(clp);
5171 return ERR_PTR(-ENOMEM);
5173 calldata->res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5174 msg.rpc_argp = &calldata->args;
5175 msg.rpc_resp = &calldata->res;
5176 calldata->clp = clp;
5177 task_setup_data.callback_data = calldata;
5179 return rpc_run_task(&task_setup_data);
5182 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5184 struct rpc_task *task;
5187 task = _nfs41_proc_sequence(clp, cred);
5189 ret = PTR_ERR(task);
5192 dprintk("<-- %s status=%d\n", __func__, ret);
5196 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5198 struct rpc_task *task;
5201 task = _nfs41_proc_sequence(clp, cred);
5203 ret = PTR_ERR(task);
5206 ret = rpc_wait_for_completion_task(task);
5208 ret = task->tk_status;
5211 dprintk("<-- %s status=%d\n", __func__, ret);
5215 struct nfs4_reclaim_complete_data {
5216 struct nfs_client *clp;
5217 struct nfs41_reclaim_complete_args arg;
5218 struct nfs41_reclaim_complete_res res;
5221 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5223 struct nfs4_reclaim_complete_data *calldata = data;
5225 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5226 if (nfs41_setup_sequence(calldata->clp->cl_session,
5227 &calldata->arg.seq_args,
5228 &calldata->res.seq_res, 0, task))
5231 rpc_call_start(task);
5234 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5236 switch(task->tk_status) {
5238 case -NFS4ERR_COMPLETE_ALREADY:
5239 case -NFS4ERR_WRONG_CRED: /* What to do here? */
5241 case -NFS4ERR_DELAY:
5243 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5246 nfs4_schedule_state_recovery(clp);
5251 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
5253 struct nfs4_reclaim_complete_data *calldata = data;
5254 struct nfs_client *clp = calldata->clp;
5255 struct nfs4_sequence_res *res = &calldata->res.seq_res;
5257 dprintk("--> %s\n", __func__);
5258 nfs41_sequence_done(res);
5260 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
5261 rpc_restart_call_prepare(task);
5264 dprintk("<-- %s\n", __func__);
5267 static void nfs4_free_reclaim_complete_data(void *data)
5269 struct nfs4_reclaim_complete_data *calldata = data;
5274 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
5275 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
5276 .rpc_call_done = nfs4_reclaim_complete_done,
5277 .rpc_release = nfs4_free_reclaim_complete_data,
5281 * Issue a global reclaim complete.
5283 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5285 struct nfs4_reclaim_complete_data *calldata;
5286 struct rpc_task *task;
5287 struct rpc_message msg = {
5288 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
5290 struct rpc_task_setup task_setup_data = {
5291 .rpc_client = clp->cl_rpcclient,
5292 .rpc_message = &msg,
5293 .callback_ops = &nfs4_reclaim_complete_call_ops,
5294 .flags = RPC_TASK_ASYNC,
5296 int status = -ENOMEM;
5298 dprintk("--> %s\n", __func__);
5299 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5300 if (calldata == NULL)
5302 calldata->clp = clp;
5303 calldata->arg.one_fs = 0;
5304 calldata->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
5306 msg.rpc_argp = &calldata->arg;
5307 msg.rpc_resp = &calldata->res;
5308 task_setup_data.callback_data = calldata;
5309 task = rpc_run_task(&task_setup_data);
5311 status = PTR_ERR(task);
5317 dprintk("<-- %s status=%d\n", __func__, status);
5320 #endif /* CONFIG_NFS_V4_1 */
5322 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
5323 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5324 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5325 .recover_open = nfs4_open_reclaim,
5326 .recover_lock = nfs4_lock_reclaim,
5327 .establish_clid = nfs4_init_clientid,
5328 .get_clid_cred = nfs4_get_setclientid_cred,
5331 #if defined(CONFIG_NFS_V4_1)
5332 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
5333 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
5334 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
5335 .recover_open = nfs4_open_reclaim,
5336 .recover_lock = nfs4_lock_reclaim,
5337 .establish_clid = nfs41_init_clientid,
5338 .get_clid_cred = nfs4_get_exchange_id_cred,
5339 .reclaim_complete = nfs41_proc_reclaim_complete,
5341 #endif /* CONFIG_NFS_V4_1 */
5343 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
5344 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5345 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5346 .recover_open = nfs4_open_expired,
5347 .recover_lock = nfs4_lock_expired,
5348 .establish_clid = nfs4_init_clientid,
5349 .get_clid_cred = nfs4_get_setclientid_cred,
5352 #if defined(CONFIG_NFS_V4_1)
5353 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
5354 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
5355 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
5356 .recover_open = nfs4_open_expired,
5357 .recover_lock = nfs4_lock_expired,
5358 .establish_clid = nfs41_init_clientid,
5359 .get_clid_cred = nfs4_get_exchange_id_cred,
5361 #endif /* CONFIG_NFS_V4_1 */
5363 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
5364 .sched_state_renewal = nfs4_proc_async_renew,
5365 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
5366 .renew_lease = nfs4_proc_renew,
5369 #if defined(CONFIG_NFS_V4_1)
5370 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
5371 .sched_state_renewal = nfs41_proc_async_sequence,
5372 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
5373 .renew_lease = nfs4_proc_sequence,
5377 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
5379 .call_sync = _nfs4_call_sync,
5380 .validate_stateid = nfs4_validate_delegation_stateid,
5381 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
5382 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
5383 .state_renewal_ops = &nfs40_state_renewal_ops,
5386 #if defined(CONFIG_NFS_V4_1)
5387 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
5389 .call_sync = _nfs4_call_sync_session,
5390 .validate_stateid = nfs41_validate_delegation_stateid,
5391 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
5392 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
5393 .state_renewal_ops = &nfs41_state_renewal_ops,
5397 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
5398 [0] = &nfs_v4_0_minor_ops,
5399 #if defined(CONFIG_NFS_V4_1)
5400 [1] = &nfs_v4_1_minor_ops,
5404 static const struct inode_operations nfs4_file_inode_operations = {
5405 .permission = nfs_permission,
5406 .getattr = nfs_getattr,
5407 .setattr = nfs_setattr,
5408 .getxattr = nfs4_getxattr,
5409 .setxattr = nfs4_setxattr,
5410 .listxattr = nfs4_listxattr,
5413 const struct nfs_rpc_ops nfs_v4_clientops = {
5414 .version = 4, /* protocol version */
5415 .dentry_ops = &nfs4_dentry_operations,
5416 .dir_inode_ops = &nfs4_dir_inode_operations,
5417 .file_inode_ops = &nfs4_file_inode_operations,
5418 .getroot = nfs4_proc_get_root,
5419 .getattr = nfs4_proc_getattr,
5420 .setattr = nfs4_proc_setattr,
5421 .lookupfh = nfs4_proc_lookupfh,
5422 .lookup = nfs4_proc_lookup,
5423 .access = nfs4_proc_access,
5424 .readlink = nfs4_proc_readlink,
5425 .create = nfs4_proc_create,
5426 .remove = nfs4_proc_remove,
5427 .unlink_setup = nfs4_proc_unlink_setup,
5428 .unlink_done = nfs4_proc_unlink_done,
5429 .rename = nfs4_proc_rename,
5430 .link = nfs4_proc_link,
5431 .symlink = nfs4_proc_symlink,
5432 .mkdir = nfs4_proc_mkdir,
5433 .rmdir = nfs4_proc_remove,
5434 .readdir = nfs4_proc_readdir,
5435 .mknod = nfs4_proc_mknod,
5436 .statfs = nfs4_proc_statfs,
5437 .fsinfo = nfs4_proc_fsinfo,
5438 .pathconf = nfs4_proc_pathconf,
5439 .set_capabilities = nfs4_server_capabilities,
5440 .decode_dirent = nfs4_decode_dirent,
5441 .read_setup = nfs4_proc_read_setup,
5442 .read_done = nfs4_read_done,
5443 .write_setup = nfs4_proc_write_setup,
5444 .write_done = nfs4_write_done,
5445 .commit_setup = nfs4_proc_commit_setup,
5446 .commit_done = nfs4_commit_done,
5447 .lock = nfs4_proc_lock,
5448 .clear_acl_cache = nfs4_zap_acl_attr,
5449 .close_context = nfs4_close_context,