4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/ratelimit.h>
43 #include <linux/printk.h>
44 #include <linux/slab.h>
45 #include <linux/sunrpc/clnt.h>
46 #include <linux/nfs.h>
47 #include <linux/nfs4.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/nfs_page.h>
50 #include <linux/nfs_mount.h>
51 #include <linux/namei.h>
52 #include <linux/mount.h>
53 #include <linux/module.h>
54 #include <linux/nfs_idmap.h>
55 #include <linux/sunrpc/bc_xprt.h>
56 #include <linux/xattr.h>
57 #include <linux/utsname.h>
58 #include <linux/freezer.h>
61 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_PROC
70 #define NFS4_POLL_RETRY_MIN (HZ/10)
71 #define NFS4_POLL_RETRY_MAX (15*HZ)
73 #define NFS4_MAX_LOOP_ON_RECOVER (10)
75 static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
78 static int _nfs4_proc_open(struct nfs4_opendata *data);
79 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
80 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
81 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
82 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
83 static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *);
84 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
85 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
86 struct nfs_fattr *fattr, struct iattr *sattr,
87 struct nfs4_state *state);
88 #ifdef CONFIG_NFS_V4_1
89 static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *);
90 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *);
92 /* Prevent leaks of NFSv4 errors into userland */
93 static int nfs4_map_errors(int err)
98 case -NFS4ERR_RESOURCE:
100 case -NFS4ERR_WRONGSEC:
102 case -NFS4ERR_BADOWNER:
103 case -NFS4ERR_BADNAME:
105 case -NFS4ERR_SHARE_DENIED:
107 case -NFS4ERR_MINOR_VERS_MISMATCH:
108 return -EPROTONOSUPPORT;
110 dprintk("%s could not handle NFSv4 error %d\n",
118 * This is our standard bitmap for GETATTR requests.
120 const u32 nfs4_fattr_bitmap[3] = {
122 | FATTR4_WORD0_CHANGE
125 | FATTR4_WORD0_FILEID,
127 | FATTR4_WORD1_NUMLINKS
129 | FATTR4_WORD1_OWNER_GROUP
130 | FATTR4_WORD1_RAWDEV
131 | FATTR4_WORD1_SPACE_USED
132 | FATTR4_WORD1_TIME_ACCESS
133 | FATTR4_WORD1_TIME_METADATA
134 | FATTR4_WORD1_TIME_MODIFY
137 static const u32 nfs4_pnfs_open_bitmap[3] = {
139 | FATTR4_WORD0_CHANGE
142 | FATTR4_WORD0_FILEID,
144 | FATTR4_WORD1_NUMLINKS
146 | FATTR4_WORD1_OWNER_GROUP
147 | FATTR4_WORD1_RAWDEV
148 | FATTR4_WORD1_SPACE_USED
149 | FATTR4_WORD1_TIME_ACCESS
150 | FATTR4_WORD1_TIME_METADATA
151 | FATTR4_WORD1_TIME_MODIFY,
152 FATTR4_WORD2_MDSTHRESHOLD
155 const u32 nfs4_statfs_bitmap[2] = {
156 FATTR4_WORD0_FILES_AVAIL
157 | FATTR4_WORD0_FILES_FREE
158 | FATTR4_WORD0_FILES_TOTAL,
159 FATTR4_WORD1_SPACE_AVAIL
160 | FATTR4_WORD1_SPACE_FREE
161 | FATTR4_WORD1_SPACE_TOTAL
164 const u32 nfs4_pathconf_bitmap[2] = {
166 | FATTR4_WORD0_MAXNAME,
170 const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE
171 | FATTR4_WORD0_MAXREAD
172 | FATTR4_WORD0_MAXWRITE
173 | FATTR4_WORD0_LEASE_TIME,
174 FATTR4_WORD1_TIME_DELTA
175 | FATTR4_WORD1_FS_LAYOUT_TYPES,
176 FATTR4_WORD2_LAYOUT_BLKSIZE
179 const u32 nfs4_fs_locations_bitmap[2] = {
181 | FATTR4_WORD0_CHANGE
184 | FATTR4_WORD0_FILEID
185 | FATTR4_WORD0_FS_LOCATIONS,
187 | FATTR4_WORD1_NUMLINKS
189 | FATTR4_WORD1_OWNER_GROUP
190 | FATTR4_WORD1_RAWDEV
191 | FATTR4_WORD1_SPACE_USED
192 | FATTR4_WORD1_TIME_ACCESS
193 | FATTR4_WORD1_TIME_METADATA
194 | FATTR4_WORD1_TIME_MODIFY
195 | FATTR4_WORD1_MOUNTED_ON_FILEID
198 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
199 struct nfs4_readdir_arg *readdir)
203 BUG_ON(readdir->count < 80);
205 readdir->cookie = cookie;
206 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
211 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
216 * NFSv4 servers do not return entries for '.' and '..'
217 * Therefore, we fake these entries here. We let '.'
218 * have cookie 0 and '..' have cookie 1. Note that
219 * when talking to the server, we always send cookie 0
222 start = p = kmap_atomic(*readdir->pages);
225 *p++ = xdr_one; /* next */
226 *p++ = xdr_zero; /* cookie, first word */
227 *p++ = xdr_one; /* cookie, second word */
228 *p++ = xdr_one; /* entry len */
229 memcpy(p, ".\0\0\0", 4); /* entry */
231 *p++ = xdr_one; /* bitmap length */
232 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
233 *p++ = htonl(8); /* attribute buffer length */
234 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
237 *p++ = xdr_one; /* next */
238 *p++ = xdr_zero; /* cookie, first word */
239 *p++ = xdr_two; /* cookie, second word */
240 *p++ = xdr_two; /* entry len */
241 memcpy(p, "..\0\0", 4); /* entry */
243 *p++ = xdr_one; /* bitmap length */
244 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
245 *p++ = htonl(8); /* attribute buffer length */
246 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
248 readdir->pgbase = (char *)p - (char *)start;
249 readdir->count -= readdir->pgbase;
250 kunmap_atomic(start);
253 static int nfs4_wait_clnt_recover(struct nfs_client *clp)
259 res = wait_on_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING,
260 nfs_wait_bit_killable, TASK_KILLABLE);
264 if (clp->cl_cons_state < 0)
265 return clp->cl_cons_state;
269 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
276 *timeout = NFS4_POLL_RETRY_MIN;
277 if (*timeout > NFS4_POLL_RETRY_MAX)
278 *timeout = NFS4_POLL_RETRY_MAX;
279 freezable_schedule_timeout_killable(*timeout);
280 if (fatal_signal_pending(current))
286 /* This is the error handling routine for processes that are allowed
289 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
291 struct nfs_client *clp = server->nfs_client;
292 struct nfs4_state *state = exception->state;
293 struct inode *inode = exception->inode;
296 exception->retry = 0;
300 case -NFS4ERR_OPENMODE:
301 if (inode && nfs4_have_delegation(inode, FMODE_READ)) {
302 nfs4_inode_return_delegation(inode);
303 exception->retry = 1;
308 nfs4_schedule_stateid_recovery(server, state);
309 goto wait_on_recovery;
310 case -NFS4ERR_DELEG_REVOKED:
311 case -NFS4ERR_ADMIN_REVOKED:
312 case -NFS4ERR_BAD_STATEID:
315 nfs_remove_bad_delegation(state->inode);
316 nfs4_schedule_stateid_recovery(server, state);
317 goto wait_on_recovery;
318 case -NFS4ERR_EXPIRED:
320 nfs4_schedule_stateid_recovery(server, state);
321 case -NFS4ERR_STALE_STATEID:
322 case -NFS4ERR_STALE_CLIENTID:
323 nfs4_schedule_lease_recovery(clp);
324 goto wait_on_recovery;
325 #if defined(CONFIG_NFS_V4_1)
326 case -NFS4ERR_BADSESSION:
327 case -NFS4ERR_BADSLOT:
328 case -NFS4ERR_BAD_HIGH_SLOT:
329 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
330 case -NFS4ERR_DEADSESSION:
331 case -NFS4ERR_SEQ_FALSE_RETRY:
332 case -NFS4ERR_SEQ_MISORDERED:
333 dprintk("%s ERROR: %d Reset session\n", __func__,
335 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
336 exception->retry = 1;
338 #endif /* defined(CONFIG_NFS_V4_1) */
339 case -NFS4ERR_FILE_OPEN:
340 if (exception->timeout > HZ) {
341 /* We have retried a decent amount, time to
350 ret = nfs4_delay(server->client, &exception->timeout);
353 case -NFS4ERR_RETRY_UNCACHED_REP:
354 case -NFS4ERR_OLD_STATEID:
355 exception->retry = 1;
357 case -NFS4ERR_BADOWNER:
358 /* The following works around a Linux server bug! */
359 case -NFS4ERR_BADNAME:
360 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
361 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
362 exception->retry = 1;
363 printk(KERN_WARNING "NFS: v4 server %s "
364 "does not accept raw "
366 "Reenabling the idmapper.\n",
367 server->nfs_client->cl_hostname);
370 /* We failed to handle the error */
371 return nfs4_map_errors(ret);
373 ret = nfs4_wait_clnt_recover(clp);
375 exception->retry = 1;
380 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
382 spin_lock(&clp->cl_lock);
383 if (time_before(clp->cl_last_renewal,timestamp))
384 clp->cl_last_renewal = timestamp;
385 spin_unlock(&clp->cl_lock);
388 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
390 do_renew_lease(server->nfs_client, timestamp);
393 #if defined(CONFIG_NFS_V4_1)
396 * nfs4_free_slot - free a slot and efficiently update slot table.
398 * freeing a slot is trivially done by clearing its respective bit
400 * If the freed slotid equals highest_used_slotid we want to update it
401 * so that the server would be able to size down the slot table if needed,
402 * otherwise we know that the highest_used_slotid is still in use.
403 * When updating highest_used_slotid there may be "holes" in the bitmap
404 * so we need to scan down from highest_used_slotid to 0 looking for the now
405 * highest slotid in use.
406 * If none found, highest_used_slotid is set to NFS4_NO_SLOT.
408 * Must be called while holding tbl->slot_tbl_lock
411 nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid)
413 BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE);
414 /* clear used bit in bitmap */
415 __clear_bit(slotid, tbl->used_slots);
417 /* update highest_used_slotid when it is freed */
418 if (slotid == tbl->highest_used_slotid) {
419 slotid = find_last_bit(tbl->used_slots, tbl->max_slots);
420 if (slotid < tbl->max_slots)
421 tbl->highest_used_slotid = slotid;
423 tbl->highest_used_slotid = NFS4_NO_SLOT;
425 dprintk("%s: slotid %u highest_used_slotid %d\n", __func__,
426 slotid, tbl->highest_used_slotid);
429 bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy)
431 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
436 * Signal state manager thread if session fore channel is drained
438 static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
440 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
441 rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq,
442 nfs4_set_task_privileged, NULL);
446 if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
449 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__);
450 complete(&ses->fc_slot_table.complete);
454 * Signal state manager thread if session back channel is drained
456 void nfs4_check_drain_bc_complete(struct nfs4_session *ses)
458 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
459 ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
461 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__);
462 complete(&ses->bc_slot_table.complete);
465 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
467 struct nfs4_slot_table *tbl;
469 tbl = &res->sr_session->fc_slot_table;
471 /* just wake up the next guy waiting since
472 * we may have not consumed a slot after all */
473 dprintk("%s: No slot\n", __func__);
477 spin_lock(&tbl->slot_tbl_lock);
478 nfs4_free_slot(tbl, res->sr_slot - tbl->slots);
479 nfs4_check_drain_fc_complete(res->sr_session);
480 spin_unlock(&tbl->slot_tbl_lock);
484 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
486 unsigned long timestamp;
487 struct nfs_client *clp;
490 * sr_status remains 1 if an RPC level error occurred. The server
491 * may or may not have processed the sequence operation..
492 * Proceed as if the server received and processed the sequence
495 if (res->sr_status == 1)
496 res->sr_status = NFS_OK;
498 /* don't increment the sequence number if the task wasn't sent */
499 if (!RPC_WAS_SENT(task))
502 /* Check the SEQUENCE operation status */
503 switch (res->sr_status) {
505 /* Update the slot's sequence and clientid lease timer */
506 ++res->sr_slot->seq_nr;
507 timestamp = res->sr_renewal_time;
508 clp = res->sr_session->clp;
509 do_renew_lease(clp, timestamp);
510 /* Check sequence flags */
511 if (res->sr_status_flags != 0)
512 nfs4_schedule_lease_recovery(clp);
515 /* The server detected a resend of the RPC call and
516 * returned NFS4ERR_DELAY as per Section 2.10.6.2
519 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
521 res->sr_slot - res->sr_session->fc_slot_table.slots,
522 res->sr_slot->seq_nr);
525 /* Just update the slot sequence no. */
526 ++res->sr_slot->seq_nr;
529 /* The session may be reset by one of the error handlers. */
530 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
531 nfs41_sequence_free_slot(res);
534 if (!rpc_restart_call(task))
536 rpc_delay(task, NFS4_POLL_RETRY_MAX);
540 static int nfs4_sequence_done(struct rpc_task *task,
541 struct nfs4_sequence_res *res)
543 if (res->sr_session == NULL)
545 return nfs41_sequence_done(task, res);
549 * nfs4_find_slot - efficiently look for a free slot
551 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
552 * If found, we mark the slot as used, update the highest_used_slotid,
553 * and respectively set up the sequence operation args.
554 * The slot number is returned if found, or NFS4_NO_SLOT otherwise.
556 * Note: must be called with under the slot_tbl_lock.
559 nfs4_find_slot(struct nfs4_slot_table *tbl)
562 u32 ret_id = NFS4_NO_SLOT;
564 dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
565 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
567 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
568 if (slotid >= tbl->max_slots)
570 __set_bit(slotid, tbl->used_slots);
571 if (slotid > tbl->highest_used_slotid ||
572 tbl->highest_used_slotid == NFS4_NO_SLOT)
573 tbl->highest_used_slotid = slotid;
576 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
577 __func__, tbl->used_slots[0], tbl->highest_used_slotid, ret_id);
581 static void nfs41_init_sequence(struct nfs4_sequence_args *args,
582 struct nfs4_sequence_res *res, int cache_reply)
584 args->sa_session = NULL;
585 args->sa_cache_this = 0;
587 args->sa_cache_this = 1;
588 res->sr_session = NULL;
592 int nfs41_setup_sequence(struct nfs4_session *session,
593 struct nfs4_sequence_args *args,
594 struct nfs4_sequence_res *res,
595 struct rpc_task *task)
597 struct nfs4_slot *slot;
598 struct nfs4_slot_table *tbl;
601 dprintk("--> %s\n", __func__);
602 /* slot already allocated? */
603 if (res->sr_slot != NULL)
606 tbl = &session->fc_slot_table;
608 spin_lock(&tbl->slot_tbl_lock);
609 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
610 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
611 /* The state manager will wait until the slot table is empty */
612 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
613 spin_unlock(&tbl->slot_tbl_lock);
614 dprintk("%s session is draining\n", __func__);
618 if (!rpc_queue_empty(&tbl->slot_tbl_waitq) &&
619 !rpc_task_has_priority(task, RPC_PRIORITY_PRIVILEGED)) {
620 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
621 spin_unlock(&tbl->slot_tbl_lock);
622 dprintk("%s enforce FIFO order\n", __func__);
626 slotid = nfs4_find_slot(tbl);
627 if (slotid == NFS4_NO_SLOT) {
628 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
629 spin_unlock(&tbl->slot_tbl_lock);
630 dprintk("<-- %s: no free slots\n", __func__);
633 spin_unlock(&tbl->slot_tbl_lock);
635 rpc_task_set_priority(task, RPC_PRIORITY_NORMAL);
636 slot = tbl->slots + slotid;
637 args->sa_session = session;
638 args->sa_slotid = slotid;
640 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
642 res->sr_session = session;
644 res->sr_renewal_time = jiffies;
645 res->sr_status_flags = 0;
647 * sr_status is only set in decode_sequence, and so will remain
648 * set to 1 if an rpc level failure occurs.
653 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
655 int nfs4_setup_sequence(const struct nfs_server *server,
656 struct nfs4_sequence_args *args,
657 struct nfs4_sequence_res *res,
658 struct rpc_task *task)
660 struct nfs4_session *session = nfs4_get_session(server);
666 dprintk("--> %s clp %p session %p sr_slot %td\n",
667 __func__, session->clp, session, res->sr_slot ?
668 res->sr_slot - session->fc_slot_table.slots : -1);
670 ret = nfs41_setup_sequence(session, args, res, task);
672 dprintk("<-- %s status=%d\n", __func__, ret);
676 struct nfs41_call_sync_data {
677 const struct nfs_server *seq_server;
678 struct nfs4_sequence_args *seq_args;
679 struct nfs4_sequence_res *seq_res;
682 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
684 struct nfs41_call_sync_data *data = calldata;
686 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
688 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
689 data->seq_res, task))
691 rpc_call_start(task);
694 static void nfs41_call_priv_sync_prepare(struct rpc_task *task, void *calldata)
696 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
697 nfs41_call_sync_prepare(task, calldata);
700 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
702 struct nfs41_call_sync_data *data = calldata;
704 nfs41_sequence_done(task, data->seq_res);
707 static const struct rpc_call_ops nfs41_call_sync_ops = {
708 .rpc_call_prepare = nfs41_call_sync_prepare,
709 .rpc_call_done = nfs41_call_sync_done,
712 static const struct rpc_call_ops nfs41_call_priv_sync_ops = {
713 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
714 .rpc_call_done = nfs41_call_sync_done,
717 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
718 struct nfs_server *server,
719 struct rpc_message *msg,
720 struct nfs4_sequence_args *args,
721 struct nfs4_sequence_res *res,
725 struct rpc_task *task;
726 struct nfs41_call_sync_data data = {
727 .seq_server = server,
731 struct rpc_task_setup task_setup = {
734 .callback_ops = &nfs41_call_sync_ops,
735 .callback_data = &data
739 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
740 task = rpc_run_task(&task_setup);
744 ret = task->tk_status;
750 int _nfs4_call_sync_session(struct rpc_clnt *clnt,
751 struct nfs_server *server,
752 struct rpc_message *msg,
753 struct nfs4_sequence_args *args,
754 struct nfs4_sequence_res *res,
757 nfs41_init_sequence(args, res, cache_reply);
758 return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0);
763 void nfs41_init_sequence(struct nfs4_sequence_args *args,
764 struct nfs4_sequence_res *res, int cache_reply)
768 static int nfs4_sequence_done(struct rpc_task *task,
769 struct nfs4_sequence_res *res)
773 #endif /* CONFIG_NFS_V4_1 */
775 int _nfs4_call_sync(struct rpc_clnt *clnt,
776 struct nfs_server *server,
777 struct rpc_message *msg,
778 struct nfs4_sequence_args *args,
779 struct nfs4_sequence_res *res,
782 nfs41_init_sequence(args, res, cache_reply);
783 return rpc_call_sync(clnt, msg, 0);
787 int nfs4_call_sync(struct rpc_clnt *clnt,
788 struct nfs_server *server,
789 struct rpc_message *msg,
790 struct nfs4_sequence_args *args,
791 struct nfs4_sequence_res *res,
794 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
795 args, res, cache_reply);
798 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
800 struct nfs_inode *nfsi = NFS_I(dir);
802 spin_lock(&dir->i_lock);
803 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
804 if (!cinfo->atomic || cinfo->before != dir->i_version)
805 nfs_force_lookup_revalidate(dir);
806 dir->i_version = cinfo->after;
807 spin_unlock(&dir->i_lock);
810 struct nfs4_opendata {
812 struct nfs_openargs o_arg;
813 struct nfs_openres o_res;
814 struct nfs_open_confirmargs c_arg;
815 struct nfs_open_confirmres c_res;
816 struct nfs4_string owner_name;
817 struct nfs4_string group_name;
818 struct nfs_fattr f_attr;
820 struct dentry *dentry;
821 struct nfs4_state_owner *owner;
822 struct nfs4_state *state;
824 unsigned long timestamp;
825 unsigned int rpc_done : 1;
831 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
833 p->o_res.f_attr = &p->f_attr;
834 p->o_res.seqid = p->o_arg.seqid;
835 p->c_res.seqid = p->c_arg.seqid;
836 p->o_res.server = p->o_arg.server;
837 nfs_fattr_init(&p->f_attr);
838 nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name);
841 static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
842 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
843 const struct iattr *attrs,
846 struct dentry *parent = dget_parent(dentry);
847 struct inode *dir = parent->d_inode;
848 struct nfs_server *server = NFS_SERVER(dir);
849 struct nfs4_opendata *p;
851 p = kzalloc(sizeof(*p), gfp_mask);
854 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
855 if (p->o_arg.seqid == NULL)
857 nfs_sb_active(dentry->d_sb);
858 p->dentry = dget(dentry);
861 atomic_inc(&sp->so_count);
862 p->o_arg.fh = NFS_FH(dir);
863 p->o_arg.open_flags = flags;
864 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
865 p->o_arg.clientid = server->nfs_client->cl_clientid;
866 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
867 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
868 p->o_arg.name = &dentry->d_name;
869 p->o_arg.server = server;
870 p->o_arg.bitmask = server->attr_bitmask;
871 p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
872 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
873 if (attrs != NULL && attrs->ia_valid != 0) {
876 p->o_arg.u.attrs = &p->attrs;
877 memcpy(&p->attrs, attrs, sizeof(p->attrs));
880 verf[1] = current->pid;
881 memcpy(p->o_arg.u.verifier.data, verf,
882 sizeof(p->o_arg.u.verifier.data));
884 p->c_arg.fh = &p->o_res.fh;
885 p->c_arg.stateid = &p->o_res.stateid;
886 p->c_arg.seqid = p->o_arg.seqid;
887 nfs4_init_opendata_res(p);
897 static void nfs4_opendata_free(struct kref *kref)
899 struct nfs4_opendata *p = container_of(kref,
900 struct nfs4_opendata, kref);
901 struct super_block *sb = p->dentry->d_sb;
903 nfs_free_seqid(p->o_arg.seqid);
904 if (p->state != NULL)
905 nfs4_put_open_state(p->state);
906 nfs4_put_state_owner(p->owner);
910 nfs_fattr_free_names(&p->f_attr);
914 static void nfs4_opendata_put(struct nfs4_opendata *p)
917 kref_put(&p->kref, nfs4_opendata_free);
920 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
924 ret = rpc_wait_for_completion_task(task);
928 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
932 if (open_mode & (O_EXCL|O_TRUNC))
934 switch (mode & (FMODE_READ|FMODE_WRITE)) {
936 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
937 && state->n_rdonly != 0;
940 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
941 && state->n_wronly != 0;
943 case FMODE_READ|FMODE_WRITE:
944 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
945 && state->n_rdwr != 0;
951 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
953 if (delegation == NULL)
955 if ((delegation->type & fmode) != fmode)
957 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
959 nfs_mark_delegation_referenced(delegation);
963 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
972 case FMODE_READ|FMODE_WRITE:
975 nfs4_state_set_mode_locked(state, state->state | fmode);
978 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
980 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
981 nfs4_stateid_copy(&state->stateid, stateid);
982 nfs4_stateid_copy(&state->open_stateid, stateid);
985 set_bit(NFS_O_RDONLY_STATE, &state->flags);
988 set_bit(NFS_O_WRONLY_STATE, &state->flags);
990 case FMODE_READ|FMODE_WRITE:
991 set_bit(NFS_O_RDWR_STATE, &state->flags);
995 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
997 write_seqlock(&state->seqlock);
998 nfs_set_open_stateid_locked(state, stateid, fmode);
999 write_sequnlock(&state->seqlock);
1002 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
1005 * Protect the call to nfs4_state_set_mode_locked and
1006 * serialise the stateid update
1008 write_seqlock(&state->seqlock);
1009 if (deleg_stateid != NULL) {
1010 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1011 set_bit(NFS_DELEGATED_STATE, &state->flags);
1013 if (open_stateid != NULL)
1014 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1015 write_sequnlock(&state->seqlock);
1016 spin_lock(&state->owner->so_lock);
1017 update_open_stateflags(state, fmode);
1018 spin_unlock(&state->owner->so_lock);
1021 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
1023 struct nfs_inode *nfsi = NFS_I(state->inode);
1024 struct nfs_delegation *deleg_cur;
1027 fmode &= (FMODE_READ|FMODE_WRITE);
1030 deleg_cur = rcu_dereference(nfsi->delegation);
1031 if (deleg_cur == NULL)
1034 spin_lock(&deleg_cur->lock);
1035 if (nfsi->delegation != deleg_cur ||
1036 (deleg_cur->type & fmode) != fmode)
1037 goto no_delegation_unlock;
1039 if (delegation == NULL)
1040 delegation = &deleg_cur->stateid;
1041 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1042 goto no_delegation_unlock;
1044 nfs_mark_delegation_referenced(deleg_cur);
1045 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1047 no_delegation_unlock:
1048 spin_unlock(&deleg_cur->lock);
1052 if (!ret && open_stateid != NULL) {
1053 __update_open_stateid(state, open_stateid, NULL, fmode);
1061 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
1063 struct nfs_delegation *delegation;
1066 delegation = rcu_dereference(NFS_I(inode)->delegation);
1067 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1072 nfs4_inode_return_delegation(inode);
1075 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1077 struct nfs4_state *state = opendata->state;
1078 struct nfs_inode *nfsi = NFS_I(state->inode);
1079 struct nfs_delegation *delegation;
1080 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1081 fmode_t fmode = opendata->o_arg.fmode;
1082 nfs4_stateid stateid;
1086 if (can_open_cached(state, fmode, open_mode)) {
1087 spin_lock(&state->owner->so_lock);
1088 if (can_open_cached(state, fmode, open_mode)) {
1089 update_open_stateflags(state, fmode);
1090 spin_unlock(&state->owner->so_lock);
1091 goto out_return_state;
1093 spin_unlock(&state->owner->so_lock);
1096 delegation = rcu_dereference(nfsi->delegation);
1097 if (!can_open_delegated(delegation, fmode)) {
1101 /* Save the delegation */
1102 nfs4_stateid_copy(&stateid, &delegation->stateid);
1104 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1109 /* Try to update the stateid using the delegation */
1110 if (update_open_stateid(state, NULL, &stateid, fmode))
1111 goto out_return_state;
1114 return ERR_PTR(ret);
1116 atomic_inc(&state->count);
1120 static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1122 struct inode *inode;
1123 struct nfs4_state *state = NULL;
1124 struct nfs_delegation *delegation;
1127 if (!data->rpc_done) {
1128 state = nfs4_try_open_cached(data);
1133 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1135 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1136 ret = PTR_ERR(inode);
1140 state = nfs4_get_open_state(inode, data->owner);
1143 if (data->o_res.delegation_type != 0) {
1144 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1145 int delegation_flags = 0;
1148 delegation = rcu_dereference(NFS_I(inode)->delegation);
1150 delegation_flags = delegation->flags;
1152 if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) {
1153 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1154 "returning a delegation for "
1155 "OPEN(CLAIM_DELEGATE_CUR)\n",
1157 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1158 nfs_inode_set_delegation(state->inode,
1159 data->owner->so_cred,
1162 nfs_inode_reclaim_delegation(state->inode,
1163 data->owner->so_cred,
1167 update_open_stateid(state, &data->o_res.stateid, NULL,
1175 return ERR_PTR(ret);
1178 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1180 struct nfs_inode *nfsi = NFS_I(state->inode);
1181 struct nfs_open_context *ctx;
1183 spin_lock(&state->inode->i_lock);
1184 list_for_each_entry(ctx, &nfsi->open_files, list) {
1185 if (ctx->state != state)
1187 get_nfs_open_context(ctx);
1188 spin_unlock(&state->inode->i_lock);
1191 spin_unlock(&state->inode->i_lock);
1192 return ERR_PTR(-ENOENT);
1195 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx, struct nfs4_state *state)
1197 struct nfs4_opendata *opendata;
1199 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0, NULL, GFP_NOFS);
1200 if (opendata == NULL)
1201 return ERR_PTR(-ENOMEM);
1202 opendata->state = state;
1203 atomic_inc(&state->count);
1207 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1209 struct nfs4_state *newstate;
1212 opendata->o_arg.open_flags = 0;
1213 opendata->o_arg.fmode = fmode;
1214 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1215 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1216 nfs4_init_opendata_res(opendata);
1217 ret = _nfs4_recover_proc_open(opendata);
1220 newstate = nfs4_opendata_to_nfs4_state(opendata);
1221 if (IS_ERR(newstate))
1222 return PTR_ERR(newstate);
1223 nfs4_close_state(newstate, fmode);
1228 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1230 struct nfs4_state *newstate;
1233 /* memory barrier prior to reading state->n_* */
1234 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1236 if (state->n_rdwr != 0) {
1237 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1238 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1241 if (newstate != state)
1244 if (state->n_wronly != 0) {
1245 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1246 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1249 if (newstate != state)
1252 if (state->n_rdonly != 0) {
1253 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1254 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1257 if (newstate != state)
1261 * We may have performed cached opens for all three recoveries.
1262 * Check if we need to update the current stateid.
1264 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1265 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1266 write_seqlock(&state->seqlock);
1267 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1268 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1269 write_sequnlock(&state->seqlock);
1276 * reclaim state on the server after a reboot.
1278 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1280 struct nfs_delegation *delegation;
1281 struct nfs4_opendata *opendata;
1282 fmode_t delegation_type = 0;
1285 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1286 if (IS_ERR(opendata))
1287 return PTR_ERR(opendata);
1288 opendata->o_arg.claim = NFS4_OPEN_CLAIM_PREVIOUS;
1289 opendata->o_arg.fh = NFS_FH(state->inode);
1291 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1292 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1293 delegation_type = delegation->type;
1295 opendata->o_arg.u.delegation_type = delegation_type;
1296 status = nfs4_open_recover(opendata, state);
1297 nfs4_opendata_put(opendata);
1301 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1303 struct nfs_server *server = NFS_SERVER(state->inode);
1304 struct nfs4_exception exception = { };
1307 err = _nfs4_do_open_reclaim(ctx, state);
1308 if (err != -NFS4ERR_DELAY)
1310 nfs4_handle_exception(server, err, &exception);
1311 } while (exception.retry);
1315 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1317 struct nfs_open_context *ctx;
1320 ctx = nfs4_state_find_open_context(state);
1322 return PTR_ERR(ctx);
1323 ret = nfs4_do_open_reclaim(ctx, state);
1324 put_nfs_open_context(ctx);
1328 static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1330 struct nfs4_opendata *opendata;
1333 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1334 if (IS_ERR(opendata))
1335 return PTR_ERR(opendata);
1336 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1337 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1338 ret = nfs4_open_recover(opendata, state);
1339 nfs4_opendata_put(opendata);
1343 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1345 struct nfs4_exception exception = { };
1346 struct nfs_server *server = NFS_SERVER(state->inode);
1349 err = _nfs4_open_delegation_recall(ctx, state, stateid);
1355 case -NFS4ERR_BADSESSION:
1356 case -NFS4ERR_BADSLOT:
1357 case -NFS4ERR_BAD_HIGH_SLOT:
1358 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1359 case -NFS4ERR_DEADSESSION:
1360 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
1362 case -NFS4ERR_STALE_CLIENTID:
1363 case -NFS4ERR_STALE_STATEID:
1364 case -NFS4ERR_EXPIRED:
1365 /* Don't recall a delegation if it was lost */
1366 nfs4_schedule_lease_recovery(server->nfs_client);
1370 * The show must go on: exit, but mark the
1371 * stateid as needing recovery.
1373 case -NFS4ERR_DELEG_REVOKED:
1374 case -NFS4ERR_ADMIN_REVOKED:
1375 case -NFS4ERR_BAD_STATEID:
1376 nfs_inode_find_state_and_recover(state->inode,
1378 nfs4_schedule_stateid_recovery(server, state);
1381 * User RPCSEC_GSS context has expired.
1382 * We cannot recover this stateid now, so
1383 * skip it and allow recovery thread to
1390 err = nfs4_handle_exception(server, err, &exception);
1391 } while (exception.retry);
1396 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1398 struct nfs4_opendata *data = calldata;
1400 data->rpc_status = task->tk_status;
1401 if (data->rpc_status == 0) {
1402 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1403 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1404 renew_lease(data->o_res.server, data->timestamp);
1409 static void nfs4_open_confirm_release(void *calldata)
1411 struct nfs4_opendata *data = calldata;
1412 struct nfs4_state *state = NULL;
1414 /* If this request hasn't been cancelled, do nothing */
1415 if (data->cancelled == 0)
1417 /* In case of error, no cleanup! */
1418 if (!data->rpc_done)
1420 state = nfs4_opendata_to_nfs4_state(data);
1422 nfs4_close_state(state, data->o_arg.fmode);
1424 nfs4_opendata_put(data);
1427 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1428 .rpc_call_done = nfs4_open_confirm_done,
1429 .rpc_release = nfs4_open_confirm_release,
1433 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1435 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1437 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1438 struct rpc_task *task;
1439 struct rpc_message msg = {
1440 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1441 .rpc_argp = &data->c_arg,
1442 .rpc_resp = &data->c_res,
1443 .rpc_cred = data->owner->so_cred,
1445 struct rpc_task_setup task_setup_data = {
1446 .rpc_client = server->client,
1447 .rpc_message = &msg,
1448 .callback_ops = &nfs4_open_confirm_ops,
1449 .callback_data = data,
1450 .workqueue = nfsiod_workqueue,
1451 .flags = RPC_TASK_ASYNC,
1455 kref_get(&data->kref);
1457 data->rpc_status = 0;
1458 data->timestamp = jiffies;
1459 task = rpc_run_task(&task_setup_data);
1461 return PTR_ERR(task);
1462 status = nfs4_wait_for_completion_rpc_task(task);
1464 data->cancelled = 1;
1467 status = data->rpc_status;
1472 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1474 struct nfs4_opendata *data = calldata;
1475 struct nfs4_state_owner *sp = data->owner;
1477 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1480 * Check if we still need to send an OPEN call, or if we can use
1481 * a delegation instead.
1483 if (data->state != NULL) {
1484 struct nfs_delegation *delegation;
1486 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1489 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1490 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1491 can_open_delegated(delegation, data->o_arg.fmode))
1492 goto unlock_no_action;
1495 /* Update client id. */
1496 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1497 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1498 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1499 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1501 data->timestamp = jiffies;
1502 if (nfs4_setup_sequence(data->o_arg.server,
1503 &data->o_arg.seq_args,
1504 &data->o_res.seq_res, task))
1506 rpc_call_start(task);
1511 task->tk_action = NULL;
1515 static void nfs4_recover_open_prepare(struct rpc_task *task, void *calldata)
1517 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
1518 nfs4_open_prepare(task, calldata);
1521 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1523 struct nfs4_opendata *data = calldata;
1525 data->rpc_status = task->tk_status;
1527 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1530 if (task->tk_status == 0) {
1531 switch (data->o_res.f_attr->mode & S_IFMT) {
1535 data->rpc_status = -ELOOP;
1538 data->rpc_status = -EISDIR;
1541 data->rpc_status = -ENOTDIR;
1543 renew_lease(data->o_res.server, data->timestamp);
1544 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1545 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1550 static void nfs4_open_release(void *calldata)
1552 struct nfs4_opendata *data = calldata;
1553 struct nfs4_state *state = NULL;
1555 /* If this request hasn't been cancelled, do nothing */
1556 if (data->cancelled == 0)
1558 /* In case of error, no cleanup! */
1559 if (data->rpc_status != 0 || !data->rpc_done)
1561 /* In case we need an open_confirm, no cleanup! */
1562 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1564 state = nfs4_opendata_to_nfs4_state(data);
1566 nfs4_close_state(state, data->o_arg.fmode);
1568 nfs4_opendata_put(data);
1571 static const struct rpc_call_ops nfs4_open_ops = {
1572 .rpc_call_prepare = nfs4_open_prepare,
1573 .rpc_call_done = nfs4_open_done,
1574 .rpc_release = nfs4_open_release,
1577 static const struct rpc_call_ops nfs4_recover_open_ops = {
1578 .rpc_call_prepare = nfs4_recover_open_prepare,
1579 .rpc_call_done = nfs4_open_done,
1580 .rpc_release = nfs4_open_release,
1583 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1585 struct inode *dir = data->dir->d_inode;
1586 struct nfs_server *server = NFS_SERVER(dir);
1587 struct nfs_openargs *o_arg = &data->o_arg;
1588 struct nfs_openres *o_res = &data->o_res;
1589 struct rpc_task *task;
1590 struct rpc_message msg = {
1591 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1594 .rpc_cred = data->owner->so_cred,
1596 struct rpc_task_setup task_setup_data = {
1597 .rpc_client = server->client,
1598 .rpc_message = &msg,
1599 .callback_ops = &nfs4_open_ops,
1600 .callback_data = data,
1601 .workqueue = nfsiod_workqueue,
1602 .flags = RPC_TASK_ASYNC,
1606 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1607 kref_get(&data->kref);
1609 data->rpc_status = 0;
1610 data->cancelled = 0;
1612 task_setup_data.callback_ops = &nfs4_recover_open_ops;
1613 task = rpc_run_task(&task_setup_data);
1615 return PTR_ERR(task);
1616 status = nfs4_wait_for_completion_rpc_task(task);
1618 data->cancelled = 1;
1621 status = data->rpc_status;
1627 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1629 struct inode *dir = data->dir->d_inode;
1630 struct nfs_openres *o_res = &data->o_res;
1633 status = nfs4_run_open_task(data, 1);
1634 if (status != 0 || !data->rpc_done)
1637 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1639 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1640 status = _nfs4_proc_open_confirm(data);
1649 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1651 static int _nfs4_proc_open(struct nfs4_opendata *data)
1653 struct inode *dir = data->dir->d_inode;
1654 struct nfs_server *server = NFS_SERVER(dir);
1655 struct nfs_openargs *o_arg = &data->o_arg;
1656 struct nfs_openres *o_res = &data->o_res;
1659 status = nfs4_run_open_task(data, 0);
1660 if (!data->rpc_done)
1663 if (status == -NFS4ERR_BADNAME &&
1664 !(o_arg->open_flags & O_CREAT))
1669 nfs_fattr_map_and_free_names(server, &data->f_attr);
1671 if (o_arg->open_flags & O_CREAT)
1672 update_changeattr(dir, &o_res->cinfo);
1673 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1674 server->caps &= ~NFS_CAP_POSIX_LOCK;
1675 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1676 status = _nfs4_proc_open_confirm(data);
1680 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1681 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1685 static int nfs4_client_recover_expired_lease(struct nfs_client *clp)
1690 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
1691 ret = nfs4_wait_clnt_recover(clp);
1694 if (!test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) &&
1695 !test_bit(NFS4CLNT_CHECK_LEASE,&clp->cl_state))
1697 nfs4_schedule_state_manager(clp);
1703 static int nfs4_recover_expired_lease(struct nfs_server *server)
1705 return nfs4_client_recover_expired_lease(server->nfs_client);
1710 * reclaim state on the server after a network partition.
1711 * Assumes caller holds the appropriate lock
1713 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1715 struct nfs4_opendata *opendata;
1718 opendata = nfs4_open_recoverdata_alloc(ctx, state);
1719 if (IS_ERR(opendata))
1720 return PTR_ERR(opendata);
1721 ret = nfs4_open_recover(opendata, state);
1723 d_drop(ctx->dentry);
1724 nfs4_opendata_put(opendata);
1728 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1730 struct nfs_server *server = NFS_SERVER(state->inode);
1731 struct nfs4_exception exception = { };
1735 err = _nfs4_open_expired(ctx, state);
1739 case -NFS4ERR_GRACE:
1740 case -NFS4ERR_DELAY:
1741 nfs4_handle_exception(server, err, &exception);
1744 } while (exception.retry);
1749 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1751 struct nfs_open_context *ctx;
1754 ctx = nfs4_state_find_open_context(state);
1756 return PTR_ERR(ctx);
1757 ret = nfs4_do_open_expired(ctx, state);
1758 put_nfs_open_context(ctx);
1762 #if defined(CONFIG_NFS_V4_1)
1763 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
1765 struct nfs_server *server = NFS_SERVER(state->inode);
1766 nfs4_stateid *stateid = &state->stateid;
1769 /* If a state reset has been done, test_stateid is unneeded */
1770 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1773 status = nfs41_test_stateid(server, stateid);
1774 if (status != NFS_OK) {
1775 /* Free the stateid unless the server explicitly
1776 * informs us the stateid is unrecognized. */
1777 if (status != -NFS4ERR_BAD_STATEID)
1778 nfs41_free_stateid(server, stateid);
1780 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1785 * nfs41_check_open_stateid - possibly free an open stateid
1787 * @state: NFSv4 state for an inode
1789 * Returns NFS_OK if recovery for this stateid is now finished.
1790 * Otherwise a negative NFS4ERR value is returned.
1792 static int nfs41_check_open_stateid(struct nfs4_state *state)
1794 struct nfs_server *server = NFS_SERVER(state->inode);
1795 nfs4_stateid *stateid = &state->stateid;
1798 /* If a state reset has been done, test_stateid is unneeded */
1799 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
1800 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
1801 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
1802 return -NFS4ERR_BAD_STATEID;
1804 status = nfs41_test_stateid(server, stateid);
1805 if (status != NFS_OK) {
1806 /* Free the stateid unless the server explicitly
1807 * informs us the stateid is unrecognized. */
1808 if (status != -NFS4ERR_BAD_STATEID)
1809 nfs41_free_stateid(server, stateid);
1811 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1812 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1813 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1818 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1822 nfs41_clear_delegation_stateid(state);
1823 status = nfs41_check_open_stateid(state);
1824 if (status != NFS_OK)
1825 status = nfs4_open_expired(sp, state);
1831 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1832 * fields corresponding to attributes that were used to store the verifier.
1833 * Make sure we clobber those fields in the later setattr call
1835 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1837 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1838 !(sattr->ia_valid & ATTR_ATIME_SET))
1839 sattr->ia_valid |= ATTR_ATIME;
1841 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1842 !(sattr->ia_valid & ATTR_MTIME_SET))
1843 sattr->ia_valid |= ATTR_MTIME;
1847 * Returns a referenced nfs4_state
1849 static int _nfs4_do_open(struct inode *dir,
1850 struct dentry *dentry,
1853 struct iattr *sattr,
1854 struct rpc_cred *cred,
1855 struct nfs4_state **res,
1856 struct nfs4_threshold **ctx_th)
1858 struct nfs4_state_owner *sp;
1859 struct nfs4_state *state = NULL;
1860 struct nfs_server *server = NFS_SERVER(dir);
1861 struct nfs4_opendata *opendata;
1864 /* Protect against reboot recovery conflicts */
1866 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1868 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1871 status = nfs4_recover_expired_lease(server);
1873 goto err_put_state_owner;
1874 if (dentry->d_inode != NULL)
1875 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
1877 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr, GFP_KERNEL);
1878 if (opendata == NULL)
1879 goto err_put_state_owner;
1881 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
1882 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
1883 if (!opendata->f_attr.mdsthreshold)
1884 goto err_opendata_put;
1885 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
1887 if (dentry->d_inode != NULL)
1888 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
1890 status = _nfs4_proc_open(opendata);
1892 goto err_opendata_put;
1894 state = nfs4_opendata_to_nfs4_state(opendata);
1895 status = PTR_ERR(state);
1897 goto err_opendata_put;
1898 if (server->caps & NFS_CAP_POSIX_LOCK)
1899 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1901 if (opendata->o_arg.open_flags & O_EXCL) {
1902 nfs4_exclusive_attrset(opendata, sattr);
1904 nfs_fattr_init(opendata->o_res.f_attr);
1905 status = nfs4_do_setattr(state->inode, cred,
1906 opendata->o_res.f_attr, sattr,
1909 nfs_setattr_update_inode(state->inode, sattr);
1910 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
1913 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
1914 *ctx_th = opendata->f_attr.mdsthreshold;
1916 kfree(opendata->f_attr.mdsthreshold);
1917 opendata->f_attr.mdsthreshold = NULL;
1919 nfs4_opendata_put(opendata);
1920 nfs4_put_state_owner(sp);
1924 kfree(opendata->f_attr.mdsthreshold);
1925 nfs4_opendata_put(opendata);
1926 err_put_state_owner:
1927 nfs4_put_state_owner(sp);
1934 static struct nfs4_state *nfs4_do_open(struct inode *dir,
1935 struct dentry *dentry,
1938 struct iattr *sattr,
1939 struct rpc_cred *cred,
1940 struct nfs4_threshold **ctx_th)
1942 struct nfs4_exception exception = { };
1943 struct nfs4_state *res;
1946 fmode &= FMODE_READ|FMODE_WRITE;
1948 status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred,
1952 /* NOTE: BAD_SEQID means the server and client disagree about the
1953 * book-keeping w.r.t. state-changing operations
1954 * (OPEN/CLOSE/LOCK/LOCKU...)
1955 * It is actually a sign of a bug on the client or on the server.
1957 * If we receive a BAD_SEQID error in the particular case of
1958 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1959 * have unhashed the old state_owner for us, and that we can
1960 * therefore safely retry using a new one. We should still warn
1961 * the user though...
1963 if (status == -NFS4ERR_BAD_SEQID) {
1964 pr_warn_ratelimited("NFS: v4 server %s "
1965 " returned a bad sequence-id error!\n",
1966 NFS_SERVER(dir)->nfs_client->cl_hostname);
1967 exception.retry = 1;
1971 * BAD_STATEID on OPEN means that the server cancelled our
1972 * state before it received the OPEN_CONFIRM.
1973 * Recover by retrying the request as per the discussion
1974 * on Page 181 of RFC3530.
1976 if (status == -NFS4ERR_BAD_STATEID) {
1977 exception.retry = 1;
1980 if (status == -EAGAIN) {
1981 /* We must have found a delegation */
1982 exception.retry = 1;
1985 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
1986 status, &exception));
1987 } while (exception.retry);
1991 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1992 struct nfs_fattr *fattr, struct iattr *sattr,
1993 struct nfs4_state *state)
1995 struct nfs_server *server = NFS_SERVER(inode);
1996 struct nfs_setattrargs arg = {
1997 .fh = NFS_FH(inode),
2000 .bitmask = server->attr_bitmask,
2002 struct nfs_setattrres res = {
2006 struct rpc_message msg = {
2007 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2012 unsigned long timestamp = jiffies;
2015 nfs_fattr_init(fattr);
2017 if (state != NULL) {
2018 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2019 current->files, current->tgid);
2020 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
2022 /* Use that stateid */
2024 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2026 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2027 if (status == 0 && state != NULL)
2028 renew_lease(server, timestamp);
2032 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2033 struct nfs_fattr *fattr, struct iattr *sattr,
2034 struct nfs4_state *state)
2036 struct nfs_server *server = NFS_SERVER(inode);
2037 struct nfs4_exception exception = {
2043 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
2045 case -NFS4ERR_OPENMODE:
2046 if (state && !(state->state & FMODE_WRITE)) {
2048 if (sattr->ia_valid & ATTR_OPEN)
2053 err = nfs4_handle_exception(server, err, &exception);
2054 } while (exception.retry);
2059 struct nfs4_closedata {
2060 struct inode *inode;
2061 struct nfs4_state *state;
2062 struct nfs_closeargs arg;
2063 struct nfs_closeres res;
2064 struct nfs_fattr fattr;
2065 unsigned long timestamp;
2070 static void nfs4_free_closedata(void *data)
2072 struct nfs4_closedata *calldata = data;
2073 struct nfs4_state_owner *sp = calldata->state->owner;
2074 struct super_block *sb = calldata->state->inode->i_sb;
2077 pnfs_roc_release(calldata->state->inode);
2078 nfs4_put_open_state(calldata->state);
2079 nfs_free_seqid(calldata->arg.seqid);
2080 nfs4_put_state_owner(sp);
2081 nfs_sb_deactive(sb);
2085 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2088 spin_lock(&state->owner->so_lock);
2089 if (!(fmode & FMODE_READ))
2090 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2091 if (!(fmode & FMODE_WRITE))
2092 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2093 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2094 spin_unlock(&state->owner->so_lock);
2097 static void nfs4_close_done(struct rpc_task *task, void *data)
2099 struct nfs4_closedata *calldata = data;
2100 struct nfs4_state *state = calldata->state;
2101 struct nfs_server *server = NFS_SERVER(calldata->inode);
2103 dprintk("%s: begin!\n", __func__);
2104 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2106 /* hmm. we are done with the inode, and in the process of freeing
2107 * the state_owner. we keep this around to process errors
2109 switch (task->tk_status) {
2112 pnfs_roc_set_barrier(state->inode,
2113 calldata->roc_barrier);
2114 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2115 renew_lease(server, calldata->timestamp);
2116 nfs4_close_clear_stateid_flags(state,
2117 calldata->arg.fmode);
2119 case -NFS4ERR_STALE_STATEID:
2120 case -NFS4ERR_OLD_STATEID:
2121 case -NFS4ERR_BAD_STATEID:
2122 case -NFS4ERR_EXPIRED:
2123 if (calldata->arg.fmode == 0)
2126 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2127 rpc_restart_call_prepare(task);
2129 nfs_release_seqid(calldata->arg.seqid);
2130 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2131 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2134 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2136 struct nfs4_closedata *calldata = data;
2137 struct nfs4_state *state = calldata->state;
2140 dprintk("%s: begin!\n", __func__);
2141 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2144 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2145 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2146 spin_lock(&state->owner->so_lock);
2147 /* Calculate the change in open mode */
2148 if (state->n_rdwr == 0) {
2149 if (state->n_rdonly == 0) {
2150 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2151 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2152 calldata->arg.fmode &= ~FMODE_READ;
2154 if (state->n_wronly == 0) {
2155 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2156 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2157 calldata->arg.fmode &= ~FMODE_WRITE;
2160 spin_unlock(&state->owner->so_lock);
2163 /* Note: exit _without_ calling nfs4_close_done */
2164 task->tk_action = NULL;
2168 if (calldata->arg.fmode == 0) {
2169 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2170 if (calldata->roc &&
2171 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) {
2172 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq,
2178 nfs_fattr_init(calldata->res.fattr);
2179 calldata->timestamp = jiffies;
2180 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
2181 &calldata->arg.seq_args,
2182 &calldata->res.seq_res,
2185 rpc_call_start(task);
2187 dprintk("%s: done!\n", __func__);
2190 static const struct rpc_call_ops nfs4_close_ops = {
2191 .rpc_call_prepare = nfs4_close_prepare,
2192 .rpc_call_done = nfs4_close_done,
2193 .rpc_release = nfs4_free_closedata,
2197 * It is possible for data to be read/written from a mem-mapped file
2198 * after the sys_close call (which hits the vfs layer as a flush).
2199 * This means that we can't safely call nfsv4 close on a file until
2200 * the inode is cleared. This in turn means that we are not good
2201 * NFSv4 citizens - we do not indicate to the server to update the file's
2202 * share state even when we are done with one of the three share
2203 * stateid's in the inode.
2205 * NOTE: Caller must be holding the sp->so_owner semaphore!
2207 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc)
2209 struct nfs_server *server = NFS_SERVER(state->inode);
2210 struct nfs4_closedata *calldata;
2211 struct nfs4_state_owner *sp = state->owner;
2212 struct rpc_task *task;
2213 struct rpc_message msg = {
2214 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2215 .rpc_cred = state->owner->so_cred,
2217 struct rpc_task_setup task_setup_data = {
2218 .rpc_client = server->client,
2219 .rpc_message = &msg,
2220 .callback_ops = &nfs4_close_ops,
2221 .workqueue = nfsiod_workqueue,
2222 .flags = RPC_TASK_ASYNC,
2224 int status = -ENOMEM;
2226 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2227 if (calldata == NULL)
2229 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2230 calldata->inode = state->inode;
2231 calldata->state = state;
2232 calldata->arg.fh = NFS_FH(state->inode);
2233 calldata->arg.stateid = &state->open_stateid;
2234 /* Serialization for the sequence id */
2235 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2236 if (calldata->arg.seqid == NULL)
2237 goto out_free_calldata;
2238 calldata->arg.fmode = 0;
2239 calldata->arg.bitmask = server->cache_consistency_bitmask;
2240 calldata->res.fattr = &calldata->fattr;
2241 calldata->res.seqid = calldata->arg.seqid;
2242 calldata->res.server = server;
2243 calldata->roc = roc;
2244 nfs_sb_active(calldata->inode->i_sb);
2246 msg.rpc_argp = &calldata->arg;
2247 msg.rpc_resp = &calldata->res;
2248 task_setup_data.callback_data = calldata;
2249 task = rpc_run_task(&task_setup_data);
2251 return PTR_ERR(task);
2254 status = rpc_wait_for_completion_task(task);
2261 pnfs_roc_release(state->inode);
2262 nfs4_put_open_state(state);
2263 nfs4_put_state_owner(sp);
2267 static struct inode *
2268 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2270 struct nfs4_state *state;
2272 /* Protect against concurrent sillydeletes */
2273 state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr,
2274 ctx->cred, &ctx->mdsthreshold);
2276 return ERR_CAST(state);
2278 return igrab(state->inode);
2281 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2283 if (ctx->state == NULL)
2286 nfs4_close_sync(ctx->state, ctx->mode);
2288 nfs4_close_state(ctx->state, ctx->mode);
2291 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2293 struct nfs4_server_caps_arg args = {
2296 struct nfs4_server_caps_res res = {};
2297 struct rpc_message msg = {
2298 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2304 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2306 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2307 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2308 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2309 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2310 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2311 NFS_CAP_CTIME|NFS_CAP_MTIME);
2312 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2313 server->caps |= NFS_CAP_ACLS;
2314 if (res.has_links != 0)
2315 server->caps |= NFS_CAP_HARDLINKS;
2316 if (res.has_symlinks != 0)
2317 server->caps |= NFS_CAP_SYMLINKS;
2318 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2319 server->caps |= NFS_CAP_FILEID;
2320 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2321 server->caps |= NFS_CAP_MODE;
2322 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2323 server->caps |= NFS_CAP_NLINK;
2324 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2325 server->caps |= NFS_CAP_OWNER;
2326 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2327 server->caps |= NFS_CAP_OWNER_GROUP;
2328 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2329 server->caps |= NFS_CAP_ATIME;
2330 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2331 server->caps |= NFS_CAP_CTIME;
2332 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2333 server->caps |= NFS_CAP_MTIME;
2335 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2336 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2337 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2338 server->acl_bitmask = res.acl_bitmask;
2339 server->fh_expire_type = res.fh_expire_type;
2345 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2347 struct nfs4_exception exception = { };
2350 err = nfs4_handle_exception(server,
2351 _nfs4_server_capabilities(server, fhandle),
2353 } while (exception.retry);
2357 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2358 struct nfs_fsinfo *info)
2360 struct nfs4_lookup_root_arg args = {
2361 .bitmask = nfs4_fattr_bitmap,
2363 struct nfs4_lookup_res res = {
2365 .fattr = info->fattr,
2368 struct rpc_message msg = {
2369 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2374 nfs_fattr_init(info->fattr);
2375 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2378 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2379 struct nfs_fsinfo *info)
2381 struct nfs4_exception exception = { };
2384 err = _nfs4_lookup_root(server, fhandle, info);
2387 case -NFS4ERR_WRONGSEC:
2390 err = nfs4_handle_exception(server, err, &exception);
2392 } while (exception.retry);
2397 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2398 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2400 struct rpc_auth *auth;
2403 auth = rpcauth_create(flavor, server->client);
2408 ret = nfs4_lookup_root(server, fhandle, info);
2413 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2414 struct nfs_fsinfo *info)
2416 int i, len, status = 0;
2417 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS];
2419 len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array));
2422 for (i = 0; i < len; i++) {
2423 /* AUTH_UNIX is the default flavor if none was specified,
2424 * thus has already been tried. */
2425 if (flav_array[i] == RPC_AUTH_UNIX)
2428 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2429 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2434 * -EACCESS could mean that the user doesn't have correct permissions
2435 * to access the mount. It could also mean that we tried to mount
2436 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2437 * existing mount programs don't handle -EACCES very well so it should
2438 * be mapped to -EPERM instead.
2440 if (status == -EACCES)
2446 * get the file handle for the "/" directory on the server
2448 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2449 struct nfs_fsinfo *info)
2451 int minor_version = server->nfs_client->cl_minorversion;
2452 int status = nfs4_lookup_root(server, fhandle, info);
2453 if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR))
2455 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2456 * by nfs4_map_errors() as this function exits.
2458 status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info);
2460 status = nfs4_server_capabilities(server, fhandle);
2462 status = nfs4_do_fsinfo(server, fhandle, info);
2463 return nfs4_map_errors(status);
2466 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2467 struct nfs_fsinfo *info)
2470 struct nfs_fattr *fattr = info->fattr;
2472 error = nfs4_server_capabilities(server, mntfh);
2474 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2478 error = nfs4_proc_getattr(server, mntfh, fattr);
2480 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2484 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2485 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2486 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2492 * Get locations and (maybe) other attributes of a referral.
2493 * Note that we'll actually follow the referral later when
2494 * we detect fsid mismatch in inode revalidation
2496 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2497 const struct qstr *name, struct nfs_fattr *fattr,
2498 struct nfs_fh *fhandle)
2500 int status = -ENOMEM;
2501 struct page *page = NULL;
2502 struct nfs4_fs_locations *locations = NULL;
2504 page = alloc_page(GFP_KERNEL);
2507 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2508 if (locations == NULL)
2511 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2514 /* Make sure server returned a different fsid for the referral */
2515 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2516 dprintk("%s: server did not return a different fsid for"
2517 " a referral at %s\n", __func__, name->name);
2521 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2522 nfs_fixup_referral_attributes(&locations->fattr);
2524 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2525 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2526 memset(fhandle, 0, sizeof(struct nfs_fh));
2534 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2536 struct nfs4_getattr_arg args = {
2538 .bitmask = server->attr_bitmask,
2540 struct nfs4_getattr_res res = {
2544 struct rpc_message msg = {
2545 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2550 nfs_fattr_init(fattr);
2551 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2554 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2556 struct nfs4_exception exception = { };
2559 err = nfs4_handle_exception(server,
2560 _nfs4_proc_getattr(server, fhandle, fattr),
2562 } while (exception.retry);
2567 * The file is not closed if it is opened due to the a request to change
2568 * the size of the file. The open call will not be needed once the
2569 * VFS layer lookup-intents are implemented.
2571 * Close is called when the inode is destroyed.
2572 * If we haven't opened the file for O_WRONLY, we
2573 * need to in the size_change case to obtain a stateid.
2576 * Because OPEN is always done by name in nfsv4, it is
2577 * possible that we opened a different file by the same
2578 * name. We can recognize this race condition, but we
2579 * can't do anything about it besides returning an error.
2581 * This will be fixed with VFS changes (lookup-intent).
2584 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2585 struct iattr *sattr)
2587 struct inode *inode = dentry->d_inode;
2588 struct rpc_cred *cred = NULL;
2589 struct nfs4_state *state = NULL;
2592 if (pnfs_ld_layoutret_on_setattr(inode))
2593 pnfs_return_layout(inode);
2595 nfs_fattr_init(fattr);
2597 /* Deal with open(O_TRUNC) */
2598 if (sattr->ia_valid & ATTR_OPEN)
2599 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2601 /* Optimization: if the end result is no change, don't RPC */
2602 if ((sattr->ia_valid & ~(ATTR_FILE)) == 0)
2605 /* Search for an existing open(O_WRITE) file */
2606 if (sattr->ia_valid & ATTR_FILE) {
2607 struct nfs_open_context *ctx;
2609 ctx = nfs_file_open_context(sattr->ia_file);
2616 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2618 nfs_setattr_update_inode(inode, sattr);
2622 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2623 const struct qstr *name, struct nfs_fh *fhandle,
2624 struct nfs_fattr *fattr)
2626 struct nfs_server *server = NFS_SERVER(dir);
2628 struct nfs4_lookup_arg args = {
2629 .bitmask = server->attr_bitmask,
2630 .dir_fh = NFS_FH(dir),
2633 struct nfs4_lookup_res res = {
2638 struct rpc_message msg = {
2639 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2644 nfs_fattr_init(fattr);
2646 dprintk("NFS call lookup %s\n", name->name);
2647 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2648 dprintk("NFS reply lookup: %d\n", status);
2652 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
2654 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2655 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
2656 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2660 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
2661 struct qstr *name, struct nfs_fh *fhandle,
2662 struct nfs_fattr *fattr)
2664 struct nfs4_exception exception = { };
2665 struct rpc_clnt *client = *clnt;
2668 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2670 case -NFS4ERR_BADNAME:
2673 case -NFS4ERR_MOVED:
2674 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2676 case -NFS4ERR_WRONGSEC:
2678 if (client != *clnt)
2681 client = nfs4_create_sec_client(client, dir, name);
2683 return PTR_ERR(client);
2685 exception.retry = 1;
2688 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2690 } while (exception.retry);
2695 else if (client != *clnt)
2696 rpc_shutdown_client(client);
2701 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
2702 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2705 struct rpc_clnt *client = NFS_CLIENT(dir);
2707 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2708 if (client != NFS_CLIENT(dir)) {
2709 rpc_shutdown_client(client);
2710 nfs_fixup_secinfo_attributes(fattr);
2716 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
2717 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2720 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
2722 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2724 rpc_shutdown_client(client);
2725 return ERR_PTR(status);
2730 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2732 struct nfs_server *server = NFS_SERVER(inode);
2733 struct nfs4_accessargs args = {
2734 .fh = NFS_FH(inode),
2735 .bitmask = server->cache_consistency_bitmask,
2737 struct nfs4_accessres res = {
2740 struct rpc_message msg = {
2741 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2744 .rpc_cred = entry->cred,
2746 int mode = entry->mask;
2750 * Determine which access bits we want to ask for...
2752 if (mode & MAY_READ)
2753 args.access |= NFS4_ACCESS_READ;
2754 if (S_ISDIR(inode->i_mode)) {
2755 if (mode & MAY_WRITE)
2756 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2757 if (mode & MAY_EXEC)
2758 args.access |= NFS4_ACCESS_LOOKUP;
2760 if (mode & MAY_WRITE)
2761 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2762 if (mode & MAY_EXEC)
2763 args.access |= NFS4_ACCESS_EXECUTE;
2766 res.fattr = nfs_alloc_fattr();
2767 if (res.fattr == NULL)
2770 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2773 if (res.access & NFS4_ACCESS_READ)
2774 entry->mask |= MAY_READ;
2775 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
2776 entry->mask |= MAY_WRITE;
2777 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
2778 entry->mask |= MAY_EXEC;
2779 nfs_refresh_inode(inode, res.fattr);
2781 nfs_free_fattr(res.fattr);
2785 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2787 struct nfs4_exception exception = { };
2790 err = nfs4_handle_exception(NFS_SERVER(inode),
2791 _nfs4_proc_access(inode, entry),
2793 } while (exception.retry);
2798 * TODO: For the time being, we don't try to get any attributes
2799 * along with any of the zero-copy operations READ, READDIR,
2802 * In the case of the first three, we want to put the GETATTR
2803 * after the read-type operation -- this is because it is hard
2804 * to predict the length of a GETATTR response in v4, and thus
2805 * align the READ data correctly. This means that the GETATTR
2806 * may end up partially falling into the page cache, and we should
2807 * shift it into the 'tail' of the xdr_buf before processing.
2808 * To do this efficiently, we need to know the total length
2809 * of data received, which doesn't seem to be available outside
2812 * In the case of WRITE, we also want to put the GETATTR after
2813 * the operation -- in this case because we want to make sure
2814 * we get the post-operation mtime and size.
2816 * Both of these changes to the XDR layer would in fact be quite
2817 * minor, but I decided to leave them for a subsequent patch.
2819 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2820 unsigned int pgbase, unsigned int pglen)
2822 struct nfs4_readlink args = {
2823 .fh = NFS_FH(inode),
2828 struct nfs4_readlink_res res;
2829 struct rpc_message msg = {
2830 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2835 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2838 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2839 unsigned int pgbase, unsigned int pglen)
2841 struct nfs4_exception exception = { };
2844 err = nfs4_handle_exception(NFS_SERVER(inode),
2845 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2847 } while (exception.retry);
2852 * This is just for mknod. open(O_CREAT) will always do ->open_context().
2855 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2858 struct nfs_open_context *ctx;
2859 struct nfs4_state *state;
2862 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
2864 return PTR_ERR(ctx);
2866 sattr->ia_mode &= ~current_umask();
2867 state = nfs4_do_open(dir, dentry, ctx->mode,
2868 flags, sattr, ctx->cred,
2869 &ctx->mdsthreshold);
2871 if (IS_ERR(state)) {
2872 status = PTR_ERR(state);
2875 d_add(dentry, igrab(state->inode));
2876 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2879 put_nfs_open_context(ctx);
2883 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2885 struct nfs_server *server = NFS_SERVER(dir);
2886 struct nfs_removeargs args = {
2890 struct nfs_removeres res = {
2893 struct rpc_message msg = {
2894 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2900 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
2902 update_changeattr(dir, &res.cinfo);
2906 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2908 struct nfs4_exception exception = { };
2911 err = nfs4_handle_exception(NFS_SERVER(dir),
2912 _nfs4_proc_remove(dir, name),
2914 } while (exception.retry);
2918 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2920 struct nfs_server *server = NFS_SERVER(dir);
2921 struct nfs_removeargs *args = msg->rpc_argp;
2922 struct nfs_removeres *res = msg->rpc_resp;
2924 res->server = server;
2925 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2926 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
2929 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
2931 if (nfs4_setup_sequence(NFS_SERVER(data->dir),
2932 &data->args.seq_args,
2936 rpc_call_start(task);
2939 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
2941 struct nfs_removeres *res = task->tk_msg.rpc_resp;
2943 if (!nfs4_sequence_done(task, &res->seq_res))
2945 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2947 update_changeattr(dir, &res->cinfo);
2951 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
2953 struct nfs_server *server = NFS_SERVER(dir);
2954 struct nfs_renameargs *arg = msg->rpc_argp;
2955 struct nfs_renameres *res = msg->rpc_resp;
2957 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
2958 res->server = server;
2959 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
2962 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
2964 if (nfs4_setup_sequence(NFS_SERVER(data->old_dir),
2965 &data->args.seq_args,
2969 rpc_call_start(task);
2972 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
2973 struct inode *new_dir)
2975 struct nfs_renameres *res = task->tk_msg.rpc_resp;
2977 if (!nfs4_sequence_done(task, &res->seq_res))
2979 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
2982 update_changeattr(old_dir, &res->old_cinfo);
2983 update_changeattr(new_dir, &res->new_cinfo);
2987 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
2988 struct inode *new_dir, struct qstr *new_name)
2990 struct nfs_server *server = NFS_SERVER(old_dir);
2991 struct nfs_renameargs arg = {
2992 .old_dir = NFS_FH(old_dir),
2993 .new_dir = NFS_FH(new_dir),
2994 .old_name = old_name,
2995 .new_name = new_name,
2997 struct nfs_renameres res = {
3000 struct rpc_message msg = {
3001 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3005 int status = -ENOMEM;
3007 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3009 update_changeattr(old_dir, &res.old_cinfo);
3010 update_changeattr(new_dir, &res.new_cinfo);
3015 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3016 struct inode *new_dir, struct qstr *new_name)
3018 struct nfs4_exception exception = { };
3021 err = nfs4_handle_exception(NFS_SERVER(old_dir),
3022 _nfs4_proc_rename(old_dir, old_name,
3025 } while (exception.retry);
3029 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3031 struct nfs_server *server = NFS_SERVER(inode);
3032 struct nfs4_link_arg arg = {
3033 .fh = NFS_FH(inode),
3034 .dir_fh = NFS_FH(dir),
3036 .bitmask = server->attr_bitmask,
3038 struct nfs4_link_res res = {
3041 struct rpc_message msg = {
3042 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3046 int status = -ENOMEM;
3048 res.fattr = nfs_alloc_fattr();
3049 if (res.fattr == NULL)
3052 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3054 update_changeattr(dir, &res.cinfo);
3055 nfs_post_op_update_inode(inode, res.fattr);
3058 nfs_free_fattr(res.fattr);
3062 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3064 struct nfs4_exception exception = { };
3067 err = nfs4_handle_exception(NFS_SERVER(inode),
3068 _nfs4_proc_link(inode, dir, name),
3070 } while (exception.retry);
3074 struct nfs4_createdata {
3075 struct rpc_message msg;
3076 struct nfs4_create_arg arg;
3077 struct nfs4_create_res res;
3079 struct nfs_fattr fattr;
3082 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3083 struct qstr *name, struct iattr *sattr, u32 ftype)
3085 struct nfs4_createdata *data;
3087 data = kzalloc(sizeof(*data), GFP_KERNEL);
3089 struct nfs_server *server = NFS_SERVER(dir);
3091 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3092 data->msg.rpc_argp = &data->arg;
3093 data->msg.rpc_resp = &data->res;
3094 data->arg.dir_fh = NFS_FH(dir);
3095 data->arg.server = server;
3096 data->arg.name = name;
3097 data->arg.attrs = sattr;
3098 data->arg.ftype = ftype;
3099 data->arg.bitmask = server->attr_bitmask;
3100 data->res.server = server;
3101 data->res.fh = &data->fh;
3102 data->res.fattr = &data->fattr;
3103 nfs_fattr_init(data->res.fattr);
3108 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3110 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3111 &data->arg.seq_args, &data->res.seq_res, 1);
3113 update_changeattr(dir, &data->res.dir_cinfo);
3114 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
3119 static void nfs4_free_createdata(struct nfs4_createdata *data)
3124 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3125 struct page *page, unsigned int len, struct iattr *sattr)
3127 struct nfs4_createdata *data;
3128 int status = -ENAMETOOLONG;
3130 if (len > NFS4_MAXPATHLEN)
3134 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3138 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3139 data->arg.u.symlink.pages = &page;
3140 data->arg.u.symlink.len = len;
3142 status = nfs4_do_create(dir, dentry, data);
3144 nfs4_free_createdata(data);
3149 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3150 struct page *page, unsigned int len, struct iattr *sattr)
3152 struct nfs4_exception exception = { };
3155 err = nfs4_handle_exception(NFS_SERVER(dir),
3156 _nfs4_proc_symlink(dir, dentry, page,
3159 } while (exception.retry);
3163 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3164 struct iattr *sattr)
3166 struct nfs4_createdata *data;
3167 int status = -ENOMEM;
3169 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3173 status = nfs4_do_create(dir, dentry, data);
3175 nfs4_free_createdata(data);
3180 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3181 struct iattr *sattr)
3183 struct nfs4_exception exception = { };
3186 sattr->ia_mode &= ~current_umask();
3188 err = nfs4_handle_exception(NFS_SERVER(dir),
3189 _nfs4_proc_mkdir(dir, dentry, sattr),
3191 } while (exception.retry);
3195 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3196 u64 cookie, struct page **pages, unsigned int count, int plus)
3198 struct inode *dir = dentry->d_inode;
3199 struct nfs4_readdir_arg args = {
3204 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3207 struct nfs4_readdir_res res;
3208 struct rpc_message msg = {
3209 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3216 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3217 dentry->d_parent->d_name.name,
3218 dentry->d_name.name,
3219 (unsigned long long)cookie);
3220 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
3221 res.pgbase = args.pgbase;
3222 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3224 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
3225 status += args.pgbase;
3228 nfs_invalidate_atime(dir);
3230 dprintk("%s: returns %d\n", __func__, status);
3234 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3235 u64 cookie, struct page **pages, unsigned int count, int plus)
3237 struct nfs4_exception exception = { };
3240 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
3241 _nfs4_proc_readdir(dentry, cred, cookie,
3242 pages, count, plus),
3244 } while (exception.retry);
3248 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3249 struct iattr *sattr, dev_t rdev)
3251 struct nfs4_createdata *data;
3252 int mode = sattr->ia_mode;
3253 int status = -ENOMEM;
3255 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
3256 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
3258 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3263 data->arg.ftype = NF4FIFO;
3264 else if (S_ISBLK(mode)) {
3265 data->arg.ftype = NF4BLK;
3266 data->arg.u.device.specdata1 = MAJOR(rdev);
3267 data->arg.u.device.specdata2 = MINOR(rdev);
3269 else if (S_ISCHR(mode)) {
3270 data->arg.ftype = NF4CHR;
3271 data->arg.u.device.specdata1 = MAJOR(rdev);
3272 data->arg.u.device.specdata2 = MINOR(rdev);
3275 status = nfs4_do_create(dir, dentry, data);
3277 nfs4_free_createdata(data);
3282 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3283 struct iattr *sattr, dev_t rdev)
3285 struct nfs4_exception exception = { };
3288 sattr->ia_mode &= ~current_umask();
3290 err = nfs4_handle_exception(NFS_SERVER(dir),
3291 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3293 } while (exception.retry);
3297 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3298 struct nfs_fsstat *fsstat)
3300 struct nfs4_statfs_arg args = {
3302 .bitmask = server->attr_bitmask,
3304 struct nfs4_statfs_res res = {
3307 struct rpc_message msg = {
3308 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3313 nfs_fattr_init(fsstat->fattr);
3314 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3317 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3319 struct nfs4_exception exception = { };
3322 err = nfs4_handle_exception(server,
3323 _nfs4_proc_statfs(server, fhandle, fsstat),
3325 } while (exception.retry);
3329 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3330 struct nfs_fsinfo *fsinfo)
3332 struct nfs4_fsinfo_arg args = {
3334 .bitmask = server->attr_bitmask,
3336 struct nfs4_fsinfo_res res = {
3339 struct rpc_message msg = {
3340 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3345 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3348 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3350 struct nfs4_exception exception = { };
3354 err = nfs4_handle_exception(server,
3355 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3357 } while (exception.retry);
3361 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3365 nfs_fattr_init(fsinfo->fattr);
3366 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3368 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3373 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3374 struct nfs_pathconf *pathconf)
3376 struct nfs4_pathconf_arg args = {
3378 .bitmask = server->attr_bitmask,
3380 struct nfs4_pathconf_res res = {
3381 .pathconf = pathconf,
3383 struct rpc_message msg = {
3384 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3389 /* None of the pathconf attributes are mandatory to implement */
3390 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3391 memset(pathconf, 0, sizeof(*pathconf));
3395 nfs_fattr_init(pathconf->fattr);
3396 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3399 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3400 struct nfs_pathconf *pathconf)
3402 struct nfs4_exception exception = { };
3406 err = nfs4_handle_exception(server,
3407 _nfs4_proc_pathconf(server, fhandle, pathconf),
3409 } while (exception.retry);
3413 void __nfs4_read_done_cb(struct nfs_read_data *data)
3415 nfs_invalidate_atime(data->header->inode);
3418 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3420 struct nfs_server *server = NFS_SERVER(data->header->inode);
3422 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3423 rpc_restart_call_prepare(task);
3427 __nfs4_read_done_cb(data);
3428 if (task->tk_status > 0)
3429 renew_lease(server, data->timestamp);
3433 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3436 dprintk("--> %s\n", __func__);
3438 if (!nfs4_sequence_done(task, &data->res.seq_res))
3441 return data->read_done_cb ? data->read_done_cb(task, data) :
3442 nfs4_read_done_cb(task, data);
3445 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3447 data->timestamp = jiffies;
3448 data->read_done_cb = nfs4_read_done_cb;
3449 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3450 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3453 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3455 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3456 &data->args.seq_args,
3460 rpc_call_start(task);
3463 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3465 struct inode *inode = data->header->inode;
3467 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3468 rpc_restart_call_prepare(task);
3471 if (task->tk_status >= 0) {
3472 renew_lease(NFS_SERVER(inode), data->timestamp);
3473 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
3478 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3480 if (!nfs4_sequence_done(task, &data->res.seq_res))
3482 return data->write_done_cb ? data->write_done_cb(task, data) :
3483 nfs4_write_done_cb(task, data);
3487 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
3489 const struct nfs_pgio_header *hdr = data->header;
3491 /* Don't request attributes for pNFS or O_DIRECT writes */
3492 if (data->ds_clp != NULL || hdr->dreq != NULL)
3494 /* Otherwise, request attributes if and only if we don't hold
3497 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
3500 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3502 struct nfs_server *server = NFS_SERVER(data->header->inode);
3504 if (!nfs4_write_need_cache_consistency_data(data)) {
3505 data->args.bitmask = NULL;
3506 data->res.fattr = NULL;
3508 data->args.bitmask = server->cache_consistency_bitmask;
3510 if (!data->write_done_cb)
3511 data->write_done_cb = nfs4_write_done_cb;
3512 data->res.server = server;
3513 data->timestamp = jiffies;
3515 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3516 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3519 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3521 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3522 &data->args.seq_args,
3526 rpc_call_start(task);
3529 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
3531 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
3532 &data->args.seq_args,
3536 rpc_call_start(task);
3539 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
3541 struct inode *inode = data->inode;
3543 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3544 rpc_restart_call_prepare(task);
3550 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
3552 if (!nfs4_sequence_done(task, &data->res.seq_res))
3554 return data->commit_done_cb(task, data);
3557 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
3559 struct nfs_server *server = NFS_SERVER(data->inode);
3561 if (data->commit_done_cb == NULL)
3562 data->commit_done_cb = nfs4_commit_done_cb;
3563 data->res.server = server;
3564 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3565 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3568 struct nfs4_renewdata {
3569 struct nfs_client *client;
3570 unsigned long timestamp;
3574 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3575 * standalone procedure for queueing an asynchronous RENEW.
3577 static void nfs4_renew_release(void *calldata)
3579 struct nfs4_renewdata *data = calldata;
3580 struct nfs_client *clp = data->client;
3582 if (atomic_read(&clp->cl_count) > 1)
3583 nfs4_schedule_state_renewal(clp);
3584 nfs_put_client(clp);
3588 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3590 struct nfs4_renewdata *data = calldata;
3591 struct nfs_client *clp = data->client;
3592 unsigned long timestamp = data->timestamp;
3594 if (task->tk_status < 0) {
3595 /* Unless we're shutting down, schedule state recovery! */
3596 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
3598 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
3599 nfs4_schedule_lease_recovery(clp);
3602 nfs4_schedule_path_down_recovery(clp);
3604 do_renew_lease(clp, timestamp);
3607 static const struct rpc_call_ops nfs4_renew_ops = {
3608 .rpc_call_done = nfs4_renew_done,
3609 .rpc_release = nfs4_renew_release,
3612 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
3614 struct rpc_message msg = {
3615 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3619 struct nfs4_renewdata *data;
3621 if (renew_flags == 0)
3623 if (!atomic_inc_not_zero(&clp->cl_count))
3625 data = kmalloc(sizeof(*data), GFP_NOFS);
3629 data->timestamp = jiffies;
3630 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3631 &nfs4_renew_ops, data);
3634 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3636 struct rpc_message msg = {
3637 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3641 unsigned long now = jiffies;
3644 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3647 do_renew_lease(clp, now);
3651 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3653 return (server->caps & NFS_CAP_ACLS)
3654 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3655 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3658 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3659 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3662 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3664 static int buf_to_pages_noslab(const void *buf, size_t buflen,
3665 struct page **pages, unsigned int *pgbase)
3667 struct page *newpage, **spages;
3673 len = min_t(size_t, PAGE_CACHE_SIZE, buflen);
3674 newpage = alloc_page(GFP_KERNEL);
3676 if (newpage == NULL)
3678 memcpy(page_address(newpage), buf, len);
3683 } while (buflen != 0);
3689 __free_page(spages[rc-1]);
3693 struct nfs4_cached_acl {
3699 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3701 struct nfs_inode *nfsi = NFS_I(inode);
3703 spin_lock(&inode->i_lock);
3704 kfree(nfsi->nfs4_acl);
3705 nfsi->nfs4_acl = acl;
3706 spin_unlock(&inode->i_lock);
3709 static void nfs4_zap_acl_attr(struct inode *inode)
3711 nfs4_set_cached_acl(inode, NULL);
3714 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3716 struct nfs_inode *nfsi = NFS_I(inode);
3717 struct nfs4_cached_acl *acl;
3720 spin_lock(&inode->i_lock);
3721 acl = nfsi->nfs4_acl;
3724 if (buf == NULL) /* user is just asking for length */
3726 if (acl->cached == 0)
3728 ret = -ERANGE; /* see getxattr(2) man page */
3729 if (acl->len > buflen)
3731 memcpy(buf, acl->data, acl->len);
3735 spin_unlock(&inode->i_lock);
3739 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
3741 struct nfs4_cached_acl *acl;
3743 if (pages && acl_len <= PAGE_SIZE) {
3744 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
3748 _copy_from_pages(acl->data, pages, pgbase, acl_len);
3750 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3757 nfs4_set_cached_acl(inode, acl);
3761 * The getxattr API returns the required buffer length when called with a
3762 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
3763 * the required buf. On a NULL buf, we send a page of data to the server
3764 * guessing that the ACL request can be serviced by a page. If so, we cache
3765 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
3766 * the cache. If not so, we throw away the page, and cache the required
3767 * length. The next getxattr call will then produce another round trip to
3768 * the server, this time with the input buf of the required size.
3770 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3772 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
3773 struct nfs_getaclargs args = {
3774 .fh = NFS_FH(inode),
3778 struct nfs_getaclres res = {
3781 struct rpc_message msg = {
3782 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3786 int ret = -ENOMEM, npages, i;
3789 npages = (buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
3790 /* As long as we're doing a round trip to the server anyway,
3791 * let's be prepared for a page of acl data. */
3795 /* Add an extra page to handle the bitmap returned */
3798 for (i = 0; i < npages; i++) {
3799 pages[i] = alloc_page(GFP_KERNEL);
3804 /* for decoding across pages */
3805 res.acl_scratch = alloc_page(GFP_KERNEL);
3806 if (!res.acl_scratch)
3809 args.acl_len = npages * PAGE_SIZE;
3810 args.acl_pgbase = 0;
3812 /* Let decode_getfacl know not to fail if the ACL data is larger than
3813 * the page we send as a guess */
3815 res.acl_flags |= NFS4_ACL_LEN_REQUEST;
3817 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3818 __func__, buf, buflen, npages, args.acl_len);
3819 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
3820 &msg, &args.seq_args, &res.seq_res, 0);
3824 acl_len = res.acl_len - res.acl_data_offset;
3825 if (acl_len > args.acl_len)
3826 nfs4_write_cached_acl(inode, NULL, 0, acl_len);
3828 nfs4_write_cached_acl(inode, pages, res.acl_data_offset,
3832 if (acl_len > buflen)
3834 _copy_from_pages(buf, pages, res.acl_data_offset,
3839 for (i = 0; i < npages; i++)
3841 __free_page(pages[i]);
3842 if (res.acl_scratch)
3843 __free_page(res.acl_scratch);
3847 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3849 struct nfs4_exception exception = { };
3852 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
3855 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
3856 } while (exception.retry);
3860 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
3862 struct nfs_server *server = NFS_SERVER(inode);
3865 if (!nfs4_server_supports_acls(server))
3867 ret = nfs_revalidate_inode(server, inode);
3870 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
3871 nfs_zap_acl_cache(inode);
3872 ret = nfs4_read_cached_acl(inode, buf, buflen);
3874 /* -ENOENT is returned if there is no ACL or if there is an ACL
3875 * but no cached acl data, just the acl length */
3877 return nfs4_get_acl_uncached(inode, buf, buflen);
3880 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3882 struct nfs_server *server = NFS_SERVER(inode);
3883 struct page *pages[NFS4ACL_MAXPAGES];
3884 struct nfs_setaclargs arg = {
3885 .fh = NFS_FH(inode),
3889 struct nfs_setaclres res;
3890 struct rpc_message msg = {
3891 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
3897 if (!nfs4_server_supports_acls(server))
3899 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
3902 nfs4_inode_return_delegation(inode);
3903 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3906 * Free each page after tx, so the only ref left is
3907 * held by the network stack
3910 put_page(pages[i-1]);
3913 * Acl update can result in inode attribute update.
3914 * so mark the attribute cache invalid.
3916 spin_lock(&inode->i_lock);
3917 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
3918 spin_unlock(&inode->i_lock);
3919 nfs_access_zap_cache(inode);
3920 nfs_zap_acl_cache(inode);
3924 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
3926 struct nfs4_exception exception = { };
3929 err = nfs4_handle_exception(NFS_SERVER(inode),
3930 __nfs4_proc_set_acl(inode, buf, buflen),
3932 } while (exception.retry);
3937 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
3939 struct nfs_client *clp = server->nfs_client;
3941 if (task->tk_status >= 0)
3943 switch(task->tk_status) {
3944 case -NFS4ERR_DELEG_REVOKED:
3945 case -NFS4ERR_ADMIN_REVOKED:
3946 case -NFS4ERR_BAD_STATEID:
3949 nfs_remove_bad_delegation(state->inode);
3950 case -NFS4ERR_OPENMODE:
3953 nfs4_schedule_stateid_recovery(server, state);
3954 goto wait_on_recovery;
3955 case -NFS4ERR_EXPIRED:
3957 nfs4_schedule_stateid_recovery(server, state);
3958 case -NFS4ERR_STALE_STATEID:
3959 case -NFS4ERR_STALE_CLIENTID:
3960 nfs4_schedule_lease_recovery(clp);
3961 goto wait_on_recovery;
3962 #if defined(CONFIG_NFS_V4_1)
3963 case -NFS4ERR_BADSESSION:
3964 case -NFS4ERR_BADSLOT:
3965 case -NFS4ERR_BAD_HIGH_SLOT:
3966 case -NFS4ERR_DEADSESSION:
3967 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
3968 case -NFS4ERR_SEQ_FALSE_RETRY:
3969 case -NFS4ERR_SEQ_MISORDERED:
3970 dprintk("%s ERROR %d, Reset session\n", __func__,
3972 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
3973 task->tk_status = 0;
3975 #endif /* CONFIG_NFS_V4_1 */
3976 case -NFS4ERR_DELAY:
3977 nfs_inc_server_stats(server, NFSIOS_DELAY);
3978 case -NFS4ERR_GRACE:
3980 rpc_delay(task, NFS4_POLL_RETRY_MAX);
3981 task->tk_status = 0;
3983 case -NFS4ERR_RETRY_UNCACHED_REP:
3984 case -NFS4ERR_OLD_STATEID:
3985 task->tk_status = 0;
3988 task->tk_status = nfs4_map_errors(task->tk_status);
3991 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
3992 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
3993 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
3994 task->tk_status = 0;
3998 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
3999 nfs4_verifier *bootverf)
4003 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4004 /* An impossible timestamp guarantees this value
4005 * will never match a generated boot time. */
4007 verf[1] = (__be32)(NSEC_PER_SEC + 1);
4009 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4010 verf[0] = (__be32)nn->boot_time.tv_sec;
4011 verf[1] = (__be32)nn->boot_time.tv_nsec;
4013 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4017 * nfs4_proc_setclientid - Negotiate client ID
4018 * @clp: state data structure
4019 * @program: RPC program for NFSv4 callback service
4020 * @port: IP port number for NFS4 callback service
4021 * @cred: RPC credential to use for this call
4022 * @res: where to place the result
4024 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4026 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4027 unsigned short port, struct rpc_cred *cred,
4028 struct nfs4_setclientid_res *res)
4030 nfs4_verifier sc_verifier;
4031 struct nfs4_setclientid setclientid = {
4032 .sc_verifier = &sc_verifier,
4034 .sc_cb_ident = clp->cl_cb_ident,
4036 struct rpc_message msg = {
4037 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4038 .rpc_argp = &setclientid,
4044 /* nfs_client_id4 */
4045 nfs4_init_boot_verifier(clp, &sc_verifier);
4047 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
4048 sizeof(setclientid.sc_name), "%s/%s %s",
4050 rpc_peeraddr2str(clp->cl_rpcclient,
4052 rpc_peeraddr2str(clp->cl_rpcclient,
4053 RPC_DISPLAY_PROTO));
4055 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4056 sizeof(setclientid.sc_netid),
4057 rpc_peeraddr2str(clp->cl_rpcclient,
4058 RPC_DISPLAY_NETID));
4060 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4061 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4062 clp->cl_ipaddr, port >> 8, port & 255);
4064 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4065 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4066 setclientid.sc_name_len, setclientid.sc_name);
4067 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4068 dprintk("NFS reply setclientid: %d\n", status);
4073 * nfs4_proc_setclientid_confirm - Confirm client ID
4074 * @clp: state data structure
4075 * @res: result of a previous SETCLIENTID
4076 * @cred: RPC credential to use for this call
4078 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4080 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4081 struct nfs4_setclientid_res *arg,
4082 struct rpc_cred *cred)
4084 struct nfs_fsinfo fsinfo;
4085 struct rpc_message msg = {
4086 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4088 .rpc_resp = &fsinfo,
4094 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4095 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4098 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4100 spin_lock(&clp->cl_lock);
4101 clp->cl_lease_time = fsinfo.lease_time * HZ;
4102 clp->cl_last_renewal = now;
4103 spin_unlock(&clp->cl_lock);
4105 dprintk("NFS reply setclientid_confirm: %d\n", status);
4109 struct nfs4_delegreturndata {
4110 struct nfs4_delegreturnargs args;
4111 struct nfs4_delegreturnres res;
4113 nfs4_stateid stateid;
4114 unsigned long timestamp;
4115 struct nfs_fattr fattr;
4119 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4121 struct nfs4_delegreturndata *data = calldata;
4123 if (!nfs4_sequence_done(task, &data->res.seq_res))
4126 switch (task->tk_status) {
4127 case -NFS4ERR_STALE_STATEID:
4128 case -NFS4ERR_EXPIRED:
4130 renew_lease(data->res.server, data->timestamp);
4133 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4135 rpc_restart_call_prepare(task);
4139 data->rpc_status = task->tk_status;
4142 static void nfs4_delegreturn_release(void *calldata)
4147 #if defined(CONFIG_NFS_V4_1)
4148 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4150 struct nfs4_delegreturndata *d_data;
4152 d_data = (struct nfs4_delegreturndata *)data;
4154 if (nfs4_setup_sequence(d_data->res.server,
4155 &d_data->args.seq_args,
4156 &d_data->res.seq_res, task))
4158 rpc_call_start(task);
4160 #endif /* CONFIG_NFS_V4_1 */
4162 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4163 #if defined(CONFIG_NFS_V4_1)
4164 .rpc_call_prepare = nfs4_delegreturn_prepare,
4165 #endif /* CONFIG_NFS_V4_1 */
4166 .rpc_call_done = nfs4_delegreturn_done,
4167 .rpc_release = nfs4_delegreturn_release,
4170 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4172 struct nfs4_delegreturndata *data;
4173 struct nfs_server *server = NFS_SERVER(inode);
4174 struct rpc_task *task;
4175 struct rpc_message msg = {
4176 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
4179 struct rpc_task_setup task_setup_data = {
4180 .rpc_client = server->client,
4181 .rpc_message = &msg,
4182 .callback_ops = &nfs4_delegreturn_ops,
4183 .flags = RPC_TASK_ASYNC,
4187 data = kzalloc(sizeof(*data), GFP_NOFS);
4190 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4191 data->args.fhandle = &data->fh;
4192 data->args.stateid = &data->stateid;
4193 data->args.bitmask = server->cache_consistency_bitmask;
4194 nfs_copy_fh(&data->fh, NFS_FH(inode));
4195 nfs4_stateid_copy(&data->stateid, stateid);
4196 data->res.fattr = &data->fattr;
4197 data->res.server = server;
4198 nfs_fattr_init(data->res.fattr);
4199 data->timestamp = jiffies;
4200 data->rpc_status = 0;
4202 task_setup_data.callback_data = data;
4203 msg.rpc_argp = &data->args;
4204 msg.rpc_resp = &data->res;
4205 task = rpc_run_task(&task_setup_data);
4207 return PTR_ERR(task);
4210 status = nfs4_wait_for_completion_rpc_task(task);
4213 status = data->rpc_status;
4215 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4217 nfs_refresh_inode(inode, &data->fattr);
4223 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4225 struct nfs_server *server = NFS_SERVER(inode);
4226 struct nfs4_exception exception = { };
4229 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4231 case -NFS4ERR_STALE_STATEID:
4232 case -NFS4ERR_EXPIRED:
4236 err = nfs4_handle_exception(server, err, &exception);
4237 } while (exception.retry);
4241 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4242 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4245 * sleep, with exponential backoff, and retry the LOCK operation.
4247 static unsigned long
4248 nfs4_set_lock_task_retry(unsigned long timeout)
4250 freezable_schedule_timeout_killable(timeout);
4252 if (timeout > NFS4_LOCK_MAXTIMEOUT)
4253 return NFS4_LOCK_MAXTIMEOUT;
4257 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4259 struct inode *inode = state->inode;
4260 struct nfs_server *server = NFS_SERVER(inode);
4261 struct nfs_client *clp = server->nfs_client;
4262 struct nfs_lockt_args arg = {
4263 .fh = NFS_FH(inode),
4266 struct nfs_lockt_res res = {
4269 struct rpc_message msg = {
4270 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
4273 .rpc_cred = state->owner->so_cred,
4275 struct nfs4_lock_state *lsp;
4278 arg.lock_owner.clientid = clp->cl_clientid;
4279 status = nfs4_set_lock_state(state, request);
4282 lsp = request->fl_u.nfs4_fl.owner;
4283 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4284 arg.lock_owner.s_dev = server->s_dev;
4285 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4288 request->fl_type = F_UNLCK;
4290 case -NFS4ERR_DENIED:
4293 request->fl_ops->fl_release_private(request);
4298 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4300 struct nfs4_exception exception = { };
4304 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4305 _nfs4_proc_getlk(state, cmd, request),
4307 } while (exception.retry);
4311 static int do_vfs_lock(struct file *file, struct file_lock *fl)
4314 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
4316 res = posix_lock_file_wait(file, fl);
4319 res = flock_lock_file_wait(file, fl);
4327 struct nfs4_unlockdata {
4328 struct nfs_locku_args arg;
4329 struct nfs_locku_res res;
4330 struct nfs4_lock_state *lsp;
4331 struct nfs_open_context *ctx;
4332 struct file_lock fl;
4333 const struct nfs_server *server;
4334 unsigned long timestamp;
4337 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
4338 struct nfs_open_context *ctx,
4339 struct nfs4_lock_state *lsp,
4340 struct nfs_seqid *seqid)
4342 struct nfs4_unlockdata *p;
4343 struct inode *inode = lsp->ls_state->inode;
4345 p = kzalloc(sizeof(*p), GFP_NOFS);
4348 p->arg.fh = NFS_FH(inode);
4350 p->arg.seqid = seqid;
4351 p->res.seqid = seqid;
4352 p->arg.stateid = &lsp->ls_stateid;
4354 atomic_inc(&lsp->ls_count);
4355 /* Ensure we don't close file until we're done freeing locks! */
4356 p->ctx = get_nfs_open_context(ctx);
4357 memcpy(&p->fl, fl, sizeof(p->fl));
4358 p->server = NFS_SERVER(inode);
4362 static void nfs4_locku_release_calldata(void *data)
4364 struct nfs4_unlockdata *calldata = data;
4365 nfs_free_seqid(calldata->arg.seqid);
4366 nfs4_put_lock_state(calldata->lsp);
4367 put_nfs_open_context(calldata->ctx);
4371 static void nfs4_locku_done(struct rpc_task *task, void *data)
4373 struct nfs4_unlockdata *calldata = data;
4375 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
4377 switch (task->tk_status) {
4379 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4380 &calldata->res.stateid);
4381 renew_lease(calldata->server, calldata->timestamp);
4383 case -NFS4ERR_BAD_STATEID:
4384 case -NFS4ERR_OLD_STATEID:
4385 case -NFS4ERR_STALE_STATEID:
4386 case -NFS4ERR_EXPIRED:
4389 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
4390 rpc_restart_call_prepare(task);
4394 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4396 struct nfs4_unlockdata *calldata = data;
4398 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
4400 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
4401 /* Note: exit _without_ running nfs4_locku_done */
4402 task->tk_action = NULL;
4405 calldata->timestamp = jiffies;
4406 if (nfs4_setup_sequence(calldata->server,
4407 &calldata->arg.seq_args,
4408 &calldata->res.seq_res, task))
4410 rpc_call_start(task);
4413 static const struct rpc_call_ops nfs4_locku_ops = {
4414 .rpc_call_prepare = nfs4_locku_prepare,
4415 .rpc_call_done = nfs4_locku_done,
4416 .rpc_release = nfs4_locku_release_calldata,
4419 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4420 struct nfs_open_context *ctx,
4421 struct nfs4_lock_state *lsp,
4422 struct nfs_seqid *seqid)
4424 struct nfs4_unlockdata *data;
4425 struct rpc_message msg = {
4426 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
4427 .rpc_cred = ctx->cred,
4429 struct rpc_task_setup task_setup_data = {
4430 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4431 .rpc_message = &msg,
4432 .callback_ops = &nfs4_locku_ops,
4433 .workqueue = nfsiod_workqueue,
4434 .flags = RPC_TASK_ASYNC,
4437 /* Ensure this is an unlock - when canceling a lock, the
4438 * canceled lock is passed in, and it won't be an unlock.
4440 fl->fl_type = F_UNLCK;
4442 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4444 nfs_free_seqid(seqid);
4445 return ERR_PTR(-ENOMEM);
4448 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4449 msg.rpc_argp = &data->arg;
4450 msg.rpc_resp = &data->res;
4451 task_setup_data.callback_data = data;
4452 return rpc_run_task(&task_setup_data);
4455 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
4457 struct nfs_inode *nfsi = NFS_I(state->inode);
4458 struct nfs_seqid *seqid;
4459 struct nfs4_lock_state *lsp;
4460 struct rpc_task *task;
4462 unsigned char fl_flags = request->fl_flags;
4464 status = nfs4_set_lock_state(state, request);
4465 /* Unlock _before_ we do the RPC call */
4466 request->fl_flags |= FL_EXISTS;
4467 down_read(&nfsi->rwsem);
4468 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
4469 up_read(&nfsi->rwsem);
4472 up_read(&nfsi->rwsem);
4475 /* Is this a delegated lock? */
4476 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4478 lsp = request->fl_u.nfs4_fl.owner;
4479 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4483 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4484 status = PTR_ERR(task);
4487 status = nfs4_wait_for_completion_rpc_task(task);
4490 request->fl_flags = fl_flags;
4494 struct nfs4_lockdata {
4495 struct nfs_lock_args arg;
4496 struct nfs_lock_res res;
4497 struct nfs4_lock_state *lsp;
4498 struct nfs_open_context *ctx;
4499 struct file_lock fl;
4500 unsigned long timestamp;
4503 struct nfs_server *server;
4506 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4507 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4510 struct nfs4_lockdata *p;
4511 struct inode *inode = lsp->ls_state->inode;
4512 struct nfs_server *server = NFS_SERVER(inode);
4514 p = kzalloc(sizeof(*p), gfp_mask);
4518 p->arg.fh = NFS_FH(inode);
4520 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4521 if (p->arg.open_seqid == NULL)
4523 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4524 if (p->arg.lock_seqid == NULL)
4525 goto out_free_seqid;
4526 p->arg.lock_stateid = &lsp->ls_stateid;
4527 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4528 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4529 p->arg.lock_owner.s_dev = server->s_dev;
4530 p->res.lock_seqid = p->arg.lock_seqid;
4533 atomic_inc(&lsp->ls_count);
4534 p->ctx = get_nfs_open_context(ctx);
4535 memcpy(&p->fl, fl, sizeof(p->fl));
4538 nfs_free_seqid(p->arg.open_seqid);
4544 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4546 struct nfs4_lockdata *data = calldata;
4547 struct nfs4_state *state = data->lsp->ls_state;
4549 dprintk("%s: begin!\n", __func__);
4550 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4552 /* Do we need to do an open_to_lock_owner? */
4553 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4554 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
4556 data->arg.open_stateid = &state->stateid;
4557 data->arg.new_lock_owner = 1;
4558 data->res.open_seqid = data->arg.open_seqid;
4560 data->arg.new_lock_owner = 0;
4561 data->timestamp = jiffies;
4562 if (nfs4_setup_sequence(data->server,
4563 &data->arg.seq_args,
4564 &data->res.seq_res, task))
4566 rpc_call_start(task);
4567 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4570 static void nfs4_recover_lock_prepare(struct rpc_task *task, void *calldata)
4572 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
4573 nfs4_lock_prepare(task, calldata);
4576 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4578 struct nfs4_lockdata *data = calldata;
4580 dprintk("%s: begin!\n", __func__);
4582 if (!nfs4_sequence_done(task, &data->res.seq_res))
4585 data->rpc_status = task->tk_status;
4586 if (data->arg.new_lock_owner != 0) {
4587 if (data->rpc_status == 0)
4588 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4592 if (data->rpc_status == 0) {
4593 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4594 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4595 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4598 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4601 static void nfs4_lock_release(void *calldata)
4603 struct nfs4_lockdata *data = calldata;
4605 dprintk("%s: begin!\n", __func__);
4606 nfs_free_seqid(data->arg.open_seqid);
4607 if (data->cancelled != 0) {
4608 struct rpc_task *task;
4609 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4610 data->arg.lock_seqid);
4612 rpc_put_task_async(task);
4613 dprintk("%s: cancelling lock!\n", __func__);
4615 nfs_free_seqid(data->arg.lock_seqid);
4616 nfs4_put_lock_state(data->lsp);
4617 put_nfs_open_context(data->ctx);
4619 dprintk("%s: done!\n", __func__);
4622 static const struct rpc_call_ops nfs4_lock_ops = {
4623 .rpc_call_prepare = nfs4_lock_prepare,
4624 .rpc_call_done = nfs4_lock_done,
4625 .rpc_release = nfs4_lock_release,
4628 static const struct rpc_call_ops nfs4_recover_lock_ops = {
4629 .rpc_call_prepare = nfs4_recover_lock_prepare,
4630 .rpc_call_done = nfs4_lock_done,
4631 .rpc_release = nfs4_lock_release,
4634 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4637 case -NFS4ERR_ADMIN_REVOKED:
4638 case -NFS4ERR_BAD_STATEID:
4639 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4640 if (new_lock_owner != 0 ||
4641 (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
4642 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
4644 case -NFS4ERR_STALE_STATEID:
4645 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4646 case -NFS4ERR_EXPIRED:
4647 nfs4_schedule_lease_recovery(server->nfs_client);
4651 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4653 struct nfs4_lockdata *data;
4654 struct rpc_task *task;
4655 struct rpc_message msg = {
4656 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4657 .rpc_cred = state->owner->so_cred,
4659 struct rpc_task_setup task_setup_data = {
4660 .rpc_client = NFS_CLIENT(state->inode),
4661 .rpc_message = &msg,
4662 .callback_ops = &nfs4_lock_ops,
4663 .workqueue = nfsiod_workqueue,
4664 .flags = RPC_TASK_ASYNC,
4668 dprintk("%s: begin!\n", __func__);
4669 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4670 fl->fl_u.nfs4_fl.owner,
4671 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4675 data->arg.block = 1;
4676 if (recovery_type > NFS_LOCK_NEW) {
4677 if (recovery_type == NFS_LOCK_RECLAIM)
4678 data->arg.reclaim = NFS_LOCK_RECLAIM;
4679 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4681 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4682 msg.rpc_argp = &data->arg;
4683 msg.rpc_resp = &data->res;
4684 task_setup_data.callback_data = data;
4685 task = rpc_run_task(&task_setup_data);
4687 return PTR_ERR(task);
4688 ret = nfs4_wait_for_completion_rpc_task(task);
4690 ret = data->rpc_status;
4692 nfs4_handle_setlk_error(data->server, data->lsp,
4693 data->arg.new_lock_owner, ret);
4695 data->cancelled = 1;
4697 dprintk("%s: done, ret = %d!\n", __func__, ret);
4701 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4703 struct nfs_server *server = NFS_SERVER(state->inode);
4704 struct nfs4_exception exception = {
4705 .inode = state->inode,
4710 /* Cache the lock if possible... */
4711 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4713 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4714 if (err != -NFS4ERR_DELAY)
4716 nfs4_handle_exception(server, err, &exception);
4717 } while (exception.retry);
4721 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4723 struct nfs_server *server = NFS_SERVER(state->inode);
4724 struct nfs4_exception exception = {
4725 .inode = state->inode,
4729 err = nfs4_set_lock_state(state, request);
4733 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4735 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4739 case -NFS4ERR_GRACE:
4740 case -NFS4ERR_DELAY:
4741 nfs4_handle_exception(server, err, &exception);
4744 } while (exception.retry);
4749 #if defined(CONFIG_NFS_V4_1)
4751 * nfs41_check_expired_locks - possibly free a lock stateid
4753 * @state: NFSv4 state for an inode
4755 * Returns NFS_OK if recovery for this stateid is now finished.
4756 * Otherwise a negative NFS4ERR value is returned.
4758 static int nfs41_check_expired_locks(struct nfs4_state *state)
4760 int status, ret = -NFS4ERR_BAD_STATEID;
4761 struct nfs4_lock_state *lsp;
4762 struct nfs_server *server = NFS_SERVER(state->inode);
4764 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4765 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) {
4766 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4767 if (status != NFS_OK) {
4768 /* Free the stateid unless the server
4769 * informs us the stateid is unrecognized. */
4770 if (status != -NFS4ERR_BAD_STATEID)
4771 nfs41_free_stateid(server,
4773 lsp->ls_flags &= ~NFS_LOCK_INITIALIZED;
4782 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
4784 int status = NFS_OK;
4786 if (test_bit(LK_STATE_IN_USE, &state->flags))
4787 status = nfs41_check_expired_locks(state);
4788 if (status != NFS_OK)
4789 status = nfs4_lock_expired(state, request);
4794 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4796 struct nfs_inode *nfsi = NFS_I(state->inode);
4797 unsigned char fl_flags = request->fl_flags;
4798 int status = -ENOLCK;
4800 if ((fl_flags & FL_POSIX) &&
4801 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
4803 /* Is this a delegated open? */
4804 status = nfs4_set_lock_state(state, request);
4807 request->fl_flags |= FL_ACCESS;
4808 status = do_vfs_lock(request->fl_file, request);
4811 down_read(&nfsi->rwsem);
4812 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
4813 /* Yes: cache locks! */
4814 /* ...but avoid races with delegation recall... */
4815 request->fl_flags = fl_flags & ~FL_SLEEP;
4816 status = do_vfs_lock(request->fl_file, request);
4819 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
4822 /* Note: we always want to sleep here! */
4823 request->fl_flags = fl_flags | FL_SLEEP;
4824 if (do_vfs_lock(request->fl_file, request) < 0)
4825 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
4826 "manager!\n", __func__);
4828 up_read(&nfsi->rwsem);
4830 request->fl_flags = fl_flags;
4834 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4836 struct nfs4_exception exception = {
4838 .inode = state->inode,
4843 err = _nfs4_proc_setlk(state, cmd, request);
4844 if (err == -NFS4ERR_DENIED)
4846 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4848 } while (exception.retry);
4853 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4855 struct nfs_open_context *ctx;
4856 struct nfs4_state *state;
4857 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
4860 /* verify open state */
4861 ctx = nfs_file_open_context(filp);
4864 if (request->fl_start < 0 || request->fl_end < 0)
4867 if (IS_GETLK(cmd)) {
4869 return nfs4_proc_getlk(state, F_GETLK, request);
4873 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
4876 if (request->fl_type == F_UNLCK) {
4878 return nfs4_proc_unlck(state, cmd, request);
4885 * Don't rely on the VFS having checked the file open mode,
4886 * since it won't do this for flock() locks.
4888 switch (request->fl_type) {
4890 if (!(filp->f_mode & FMODE_READ))
4894 if (!(filp->f_mode & FMODE_WRITE))
4899 status = nfs4_proc_setlk(state, cmd, request);
4900 if ((status != -EAGAIN) || IS_SETLK(cmd))
4902 timeout = nfs4_set_lock_task_retry(timeout);
4903 status = -ERESTARTSYS;
4906 } while(status < 0);
4910 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4912 struct nfs_server *server = NFS_SERVER(state->inode);
4913 struct nfs4_exception exception = { };
4916 err = nfs4_set_lock_state(state, fl);
4920 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4923 printk(KERN_ERR "NFS: %s: unhandled error "
4924 "%d.\n", __func__, err);
4928 case -NFS4ERR_EXPIRED:
4929 nfs4_schedule_stateid_recovery(server, state);
4930 case -NFS4ERR_STALE_CLIENTID:
4931 case -NFS4ERR_STALE_STATEID:
4932 nfs4_schedule_lease_recovery(server->nfs_client);
4934 case -NFS4ERR_BADSESSION:
4935 case -NFS4ERR_BADSLOT:
4936 case -NFS4ERR_BAD_HIGH_SLOT:
4937 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4938 case -NFS4ERR_DEADSESSION:
4939 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
4943 * The show must go on: exit, but mark the
4944 * stateid as needing recovery.
4946 case -NFS4ERR_DELEG_REVOKED:
4947 case -NFS4ERR_ADMIN_REVOKED:
4948 case -NFS4ERR_BAD_STATEID:
4949 case -NFS4ERR_OPENMODE:
4950 nfs4_schedule_stateid_recovery(server, state);
4955 * User RPCSEC_GSS context has expired.
4956 * We cannot recover this stateid now, so
4957 * skip it and allow recovery thread to
4963 case -NFS4ERR_DENIED:
4964 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4967 case -NFS4ERR_DELAY:
4970 err = nfs4_handle_exception(server, err, &exception);
4971 } while (exception.retry);
4976 struct nfs_release_lockowner_data {
4977 struct nfs4_lock_state *lsp;
4978 struct nfs_server *server;
4979 struct nfs_release_lockowner_args args;
4982 static void nfs4_release_lockowner_release(void *calldata)
4984 struct nfs_release_lockowner_data *data = calldata;
4985 nfs4_free_lock_state(data->server, data->lsp);
4989 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
4990 .rpc_release = nfs4_release_lockowner_release,
4993 int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
4995 struct nfs_server *server = lsp->ls_state->owner->so_server;
4996 struct nfs_release_lockowner_data *data;
4997 struct rpc_message msg = {
4998 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5001 if (server->nfs_client->cl_mvops->minor_version != 0)
5003 data = kmalloc(sizeof(*data), GFP_NOFS);
5007 data->server = server;
5008 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5009 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5010 data->args.lock_owner.s_dev = server->s_dev;
5011 msg.rpc_argp = &data->args;
5012 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5016 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5018 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5019 const void *buf, size_t buflen,
5020 int flags, int type)
5022 if (strcmp(key, "") != 0)
5025 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5028 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5029 void *buf, size_t buflen, int type)
5031 if (strcmp(key, "") != 0)
5034 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5037 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5038 size_t list_len, const char *name,
5039 size_t name_len, int type)
5041 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5043 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5046 if (list && len <= list_len)
5047 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5052 * nfs_fhget will use either the mounted_on_fileid or the fileid
5054 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5056 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5057 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5058 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5059 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5062 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5063 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5064 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5068 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5069 const struct qstr *name,
5070 struct nfs4_fs_locations *fs_locations,
5073 struct nfs_server *server = NFS_SERVER(dir);
5075 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5077 struct nfs4_fs_locations_arg args = {
5078 .dir_fh = NFS_FH(dir),
5083 struct nfs4_fs_locations_res res = {
5084 .fs_locations = fs_locations,
5086 struct rpc_message msg = {
5087 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5093 dprintk("%s: start\n", __func__);
5095 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5096 * is not supported */
5097 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5098 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5100 bitmask[0] |= FATTR4_WORD0_FILEID;
5102 nfs_fattr_init(&fs_locations->fattr);
5103 fs_locations->server = server;
5104 fs_locations->nlocations = 0;
5105 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5106 dprintk("%s: returned status = %d\n", __func__, status);
5110 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5111 const struct qstr *name,
5112 struct nfs4_fs_locations *fs_locations,
5115 struct nfs4_exception exception = { };
5118 err = nfs4_handle_exception(NFS_SERVER(dir),
5119 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5121 } while (exception.retry);
5125 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
5128 struct nfs4_secinfo_arg args = {
5129 .dir_fh = NFS_FH(dir),
5132 struct nfs4_secinfo_res res = {
5135 struct rpc_message msg = {
5136 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
5141 dprintk("NFS call secinfo %s\n", name->name);
5142 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
5143 dprintk("NFS reply secinfo: %d\n", status);
5147 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
5148 struct nfs4_secinfo_flavors *flavors)
5150 struct nfs4_exception exception = { };
5153 err = nfs4_handle_exception(NFS_SERVER(dir),
5154 _nfs4_proc_secinfo(dir, name, flavors),
5156 } while (exception.retry);
5160 #ifdef CONFIG_NFS_V4_1
5162 * Check the exchange flags returned by the server for invalid flags, having
5163 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5166 static int nfs4_check_cl_exchange_flags(u32 flags)
5168 if (flags & ~EXCHGID4_FLAG_MASK_R)
5170 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
5171 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
5173 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
5177 return -NFS4ERR_INVAL;
5181 nfs41_same_server_scope(struct nfs41_server_scope *a,
5182 struct nfs41_server_scope *b)
5184 if (a->server_scope_sz == b->server_scope_sz &&
5185 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5192 * nfs4_proc_bind_conn_to_session()
5194 * The 4.1 client currently uses the same TCP connection for the
5195 * fore and backchannel.
5197 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
5200 struct nfs41_bind_conn_to_session_res res;
5201 struct rpc_message msg = {
5203 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
5209 dprintk("--> %s\n", __func__);
5210 BUG_ON(clp == NULL);
5212 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5213 if (unlikely(res.session == NULL)) {
5218 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5220 if (memcmp(res.session->sess_id.data,
5221 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
5222 dprintk("NFS: %s: Session ID mismatch\n", __func__);
5226 if (res.dir != NFS4_CDFS4_BOTH) {
5227 dprintk("NFS: %s: Unexpected direction from server\n",
5232 if (res.use_conn_in_rdma_mode) {
5233 dprintk("NFS: %s: Server returned RDMA mode = true\n",
5242 dprintk("<-- %s status= %d\n", __func__, status);
5247 * nfs4_proc_exchange_id()
5249 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5251 * Since the clientid has expired, all compounds using sessions
5252 * associated with the stale clientid will be returning
5253 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
5254 * be in some phase of session reset.
5256 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
5258 nfs4_verifier verifier;
5259 struct nfs41_exchange_id_args args = {
5260 .verifier = &verifier,
5262 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
5264 struct nfs41_exchange_id_res res = {
5268 struct rpc_message msg = {
5269 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
5275 nfs4_init_boot_verifier(clp, &verifier);
5276 args.id_len = scnprintf(args.id, sizeof(args.id),
5279 clp->cl_rpcclient->cl_nodename);
5280 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
5281 clp->cl_rpcclient->cl_auth->au_ops->au_name,
5282 args.id_len, args.id);
5284 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
5286 if (unlikely(res.server_owner == NULL)) {
5291 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
5293 if (unlikely(res.server_scope == NULL)) {
5295 goto out_server_owner;
5298 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
5299 if (unlikely(res.impl_id == NULL)) {
5301 goto out_server_scope;
5304 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5306 status = nfs4_check_cl_exchange_flags(res.flags);
5309 clp->cl_clientid = res.clientid;
5310 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
5311 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
5312 clp->cl_seqid = res.seqid;
5314 kfree(clp->cl_serverowner);
5315 clp->cl_serverowner = res.server_owner;
5316 res.server_owner = NULL;
5318 /* use the most recent implementation id */
5319 kfree(clp->cl_implid);
5320 clp->cl_implid = res.impl_id;
5322 if (clp->cl_serverscope != NULL &&
5323 !nfs41_same_server_scope(clp->cl_serverscope,
5324 res.server_scope)) {
5325 dprintk("%s: server_scope mismatch detected\n",
5327 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
5328 kfree(clp->cl_serverscope);
5329 clp->cl_serverscope = NULL;
5332 if (clp->cl_serverscope == NULL) {
5333 clp->cl_serverscope = res.server_scope;
5340 kfree(res.server_owner);
5342 kfree(res.server_scope);
5344 if (clp->cl_implid != NULL)
5345 dprintk("NFS reply exchange_id: Server Implementation ID: "
5346 "domain: %s, name: %s, date: %llu,%u\n",
5347 clp->cl_implid->domain, clp->cl_implid->name,
5348 clp->cl_implid->date.seconds,
5349 clp->cl_implid->date.nseconds);
5350 dprintk("NFS reply exchange_id: %d\n", status);
5354 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
5355 struct rpc_cred *cred)
5357 struct rpc_message msg = {
5358 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
5364 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5366 dprintk("NFS: Got error %d from the server %s on "
5367 "DESTROY_CLIENTID.", status, clp->cl_hostname);
5371 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
5372 struct rpc_cred *cred)
5377 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
5378 ret = _nfs4_proc_destroy_clientid(clp, cred);
5380 case -NFS4ERR_DELAY:
5381 case -NFS4ERR_CLIENTID_BUSY:
5391 int nfs4_destroy_clientid(struct nfs_client *clp)
5393 struct rpc_cred *cred;
5396 if (clp->cl_mvops->minor_version < 1)
5398 if (clp->cl_exchange_flags == 0)
5400 cred = nfs4_get_exchange_id_cred(clp);
5401 ret = nfs4_proc_destroy_clientid(clp, cred);
5406 case -NFS4ERR_STALE_CLIENTID:
5407 clp->cl_exchange_flags = 0;
5413 struct nfs4_get_lease_time_data {
5414 struct nfs4_get_lease_time_args *args;
5415 struct nfs4_get_lease_time_res *res;
5416 struct nfs_client *clp;
5419 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
5423 struct nfs4_get_lease_time_data *data =
5424 (struct nfs4_get_lease_time_data *)calldata;
5426 dprintk("--> %s\n", __func__);
5427 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5428 /* just setup sequence, do not trigger session recovery
5429 since we're invoked within one */
5430 ret = nfs41_setup_sequence(data->clp->cl_session,
5431 &data->args->la_seq_args,
5432 &data->res->lr_seq_res, task);
5434 BUG_ON(ret == -EAGAIN);
5435 rpc_call_start(task);
5436 dprintk("<-- %s\n", __func__);
5440 * Called from nfs4_state_manager thread for session setup, so don't recover
5441 * from sequence operation or clientid errors.
5443 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
5445 struct nfs4_get_lease_time_data *data =
5446 (struct nfs4_get_lease_time_data *)calldata;
5448 dprintk("--> %s\n", __func__);
5449 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
5451 switch (task->tk_status) {
5452 case -NFS4ERR_DELAY:
5453 case -NFS4ERR_GRACE:
5454 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
5455 rpc_delay(task, NFS4_POLL_RETRY_MIN);
5456 task->tk_status = 0;
5458 case -NFS4ERR_RETRY_UNCACHED_REP:
5459 rpc_restart_call_prepare(task);
5462 dprintk("<-- %s\n", __func__);
5465 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
5466 .rpc_call_prepare = nfs4_get_lease_time_prepare,
5467 .rpc_call_done = nfs4_get_lease_time_done,
5470 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
5472 struct rpc_task *task;
5473 struct nfs4_get_lease_time_args args;
5474 struct nfs4_get_lease_time_res res = {
5475 .lr_fsinfo = fsinfo,
5477 struct nfs4_get_lease_time_data data = {
5482 struct rpc_message msg = {
5483 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
5487 struct rpc_task_setup task_setup = {
5488 .rpc_client = clp->cl_rpcclient,
5489 .rpc_message = &msg,
5490 .callback_ops = &nfs4_get_lease_time_ops,
5491 .callback_data = &data,
5492 .flags = RPC_TASK_TIMEOUT,
5496 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
5497 dprintk("--> %s\n", __func__);
5498 task = rpc_run_task(&task_setup);
5501 status = PTR_ERR(task);
5503 status = task->tk_status;
5506 dprintk("<-- %s return %d\n", __func__, status);
5511 static struct nfs4_slot *nfs4_alloc_slots(u32 max_slots, gfp_t gfp_flags)
5513 return kcalloc(max_slots, sizeof(struct nfs4_slot), gfp_flags);
5516 static void nfs4_add_and_init_slots(struct nfs4_slot_table *tbl,
5517 struct nfs4_slot *new,
5521 struct nfs4_slot *old = NULL;
5524 spin_lock(&tbl->slot_tbl_lock);
5528 tbl->max_slots = max_slots;
5530 tbl->highest_used_slotid = -1; /* no slot is currently used */
5531 for (i = 0; i < tbl->max_slots; i++)
5532 tbl->slots[i].seq_nr = ivalue;
5533 spin_unlock(&tbl->slot_tbl_lock);
5538 * (re)Initialise a slot table
5540 static int nfs4_realloc_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
5543 struct nfs4_slot *new = NULL;
5546 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__,
5547 max_reqs, tbl->max_slots);
5549 /* Does the newly negotiated max_reqs match the existing slot table? */
5550 if (max_reqs != tbl->max_slots) {
5551 new = nfs4_alloc_slots(max_reqs, GFP_NOFS);
5557 nfs4_add_and_init_slots(tbl, new, max_reqs, ivalue);
5558 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__,
5559 tbl, tbl->slots, tbl->max_slots);
5561 dprintk("<-- %s: return %d\n", __func__, ret);
5565 /* Destroy the slot table */
5566 static void nfs4_destroy_slot_tables(struct nfs4_session *session)
5568 if (session->fc_slot_table.slots != NULL) {
5569 kfree(session->fc_slot_table.slots);
5570 session->fc_slot_table.slots = NULL;
5572 if (session->bc_slot_table.slots != NULL) {
5573 kfree(session->bc_slot_table.slots);
5574 session->bc_slot_table.slots = NULL;
5580 * Initialize or reset the forechannel and backchannel tables
5582 static int nfs4_setup_session_slot_tables(struct nfs4_session *ses)
5584 struct nfs4_slot_table *tbl;
5587 dprintk("--> %s\n", __func__);
5589 tbl = &ses->fc_slot_table;
5590 status = nfs4_realloc_slot_table(tbl, ses->fc_attrs.max_reqs, 1);
5591 if (status) /* -ENOMEM */
5594 tbl = &ses->bc_slot_table;
5595 status = nfs4_realloc_slot_table(tbl, ses->bc_attrs.max_reqs, 0);
5596 if (status && tbl->slots == NULL)
5597 /* Fore and back channel share a connection so get
5598 * both slot tables or neither */
5599 nfs4_destroy_slot_tables(ses);
5603 struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5605 struct nfs4_session *session;
5606 struct nfs4_slot_table *tbl;
5608 session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5612 tbl = &session->fc_slot_table;
5613 tbl->highest_used_slotid = NFS4_NO_SLOT;
5614 spin_lock_init(&tbl->slot_tbl_lock);
5615 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
5616 init_completion(&tbl->complete);
5618 tbl = &session->bc_slot_table;
5619 tbl->highest_used_slotid = NFS4_NO_SLOT;
5620 spin_lock_init(&tbl->slot_tbl_lock);
5621 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
5622 init_completion(&tbl->complete);
5624 session->session_state = 1<<NFS4_SESSION_INITING;
5630 void nfs4_destroy_session(struct nfs4_session *session)
5632 struct rpc_xprt *xprt;
5633 struct rpc_cred *cred;
5635 cred = nfs4_get_exchange_id_cred(session->clp);
5636 nfs4_proc_destroy_session(session, cred);
5641 xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
5643 dprintk("%s Destroy backchannel for xprt %p\n",
5645 xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
5646 nfs4_destroy_slot_tables(session);
5651 * Initialize the values to be used by the client in CREATE_SESSION
5652 * If nfs4_init_session set the fore channel request and response sizes,
5655 * Set the back channel max_resp_sz_cached to zero to force the client to
5656 * always set csa_cachethis to FALSE because the current implementation
5657 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5659 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5661 struct nfs4_session *session = args->client->cl_session;
5662 unsigned int mxrqst_sz = session->fc_attrs.max_rqst_sz,
5663 mxresp_sz = session->fc_attrs.max_resp_sz;
5666 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
5668 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
5669 /* Fore channel attributes */
5670 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5671 args->fc_attrs.max_resp_sz = mxresp_sz;
5672 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5673 args->fc_attrs.max_reqs = max_session_slots;
5675 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5676 "max_ops=%u max_reqs=%u\n",
5678 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5679 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5681 /* Back channel attributes */
5682 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
5683 args->bc_attrs.max_resp_sz = PAGE_SIZE;
5684 args->bc_attrs.max_resp_sz_cached = 0;
5685 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
5686 args->bc_attrs.max_reqs = 1;
5688 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5689 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5691 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5692 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5693 args->bc_attrs.max_reqs);
5696 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5698 struct nfs4_channel_attrs *sent = &args->fc_attrs;
5699 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
5701 if (rcvd->max_resp_sz > sent->max_resp_sz)
5704 * Our requested max_ops is the minimum we need; we're not
5705 * prepared to break up compounds into smaller pieces than that.
5706 * So, no point even trying to continue if the server won't
5709 if (rcvd->max_ops < sent->max_ops)
5711 if (rcvd->max_reqs == 0)
5713 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5714 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5718 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5720 struct nfs4_channel_attrs *sent = &args->bc_attrs;
5721 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
5723 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
5725 if (rcvd->max_resp_sz < sent->max_resp_sz)
5727 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5729 /* These would render the backchannel useless: */
5730 if (rcvd->max_ops != sent->max_ops)
5732 if (rcvd->max_reqs != sent->max_reqs)
5737 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
5738 struct nfs4_session *session)
5742 ret = nfs4_verify_fore_channel_attrs(args, session);
5745 return nfs4_verify_back_channel_attrs(args, session);
5748 static int _nfs4_proc_create_session(struct nfs_client *clp,
5749 struct rpc_cred *cred)
5751 struct nfs4_session *session = clp->cl_session;
5752 struct nfs41_create_session_args args = {
5754 .cb_program = NFS4_CALLBACK,
5756 struct nfs41_create_session_res res = {
5759 struct rpc_message msg = {
5760 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
5767 nfs4_init_channel_attrs(&args);
5768 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
5770 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5773 /* Verify the session's negotiated channel_attrs values */
5774 status = nfs4_verify_channel_attrs(&args, session);
5776 /* Increment the clientid slot sequence id */
5784 * Issues a CREATE_SESSION operation to the server.
5785 * It is the responsibility of the caller to verify the session is
5786 * expired before calling this routine.
5788 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
5792 struct nfs4_session *session = clp->cl_session;
5794 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
5796 status = _nfs4_proc_create_session(clp, cred);
5800 /* Init or reset the session slot tables */
5801 status = nfs4_setup_session_slot_tables(session);
5802 dprintk("slot table setup returned %d\n", status);
5806 ptr = (unsigned *)&session->sess_id.data[0];
5807 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5808 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5810 dprintk("<-- %s\n", __func__);
5815 * Issue the over-the-wire RPC DESTROY_SESSION.
5816 * The caller must serialize access to this routine.
5818 int nfs4_proc_destroy_session(struct nfs4_session *session,
5819 struct rpc_cred *cred)
5821 struct rpc_message msg = {
5822 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
5823 .rpc_argp = session,
5828 dprintk("--> nfs4_proc_destroy_session\n");
5830 /* session is still being setup */
5831 if (session->clp->cl_cons_state != NFS_CS_READY)
5834 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5837 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
5838 "Session has been destroyed regardless...\n", status);
5840 dprintk("<-- nfs4_proc_destroy_session\n");
5845 * With sessions, the client is not marked ready until after a
5846 * successful EXCHANGE_ID and CREATE_SESSION.
5848 * Map errors cl_cons_state errors to EPROTONOSUPPORT to indicate
5849 * other versions of NFS can be tried.
5851 static int nfs41_check_session_ready(struct nfs_client *clp)
5855 if (clp->cl_cons_state == NFS_CS_SESSION_INITING) {
5856 ret = nfs4_client_recover_expired_lease(clp);
5860 if (clp->cl_cons_state < NFS_CS_READY)
5861 return -EPROTONOSUPPORT;
5866 int nfs4_init_session(struct nfs_server *server)
5868 struct nfs_client *clp = server->nfs_client;
5869 struct nfs4_session *session;
5870 unsigned int rsize, wsize;
5872 if (!nfs4_has_session(clp))
5875 session = clp->cl_session;
5876 spin_lock(&clp->cl_lock);
5877 if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) {
5879 rsize = server->rsize;
5881 rsize = NFS_MAX_FILE_IO_SIZE;
5882 wsize = server->wsize;
5884 wsize = NFS_MAX_FILE_IO_SIZE;
5886 session->fc_attrs.max_rqst_sz = wsize + nfs41_maxwrite_overhead;
5887 session->fc_attrs.max_resp_sz = rsize + nfs41_maxread_overhead;
5889 spin_unlock(&clp->cl_lock);
5891 return nfs41_check_session_ready(clp);
5894 int nfs4_init_ds_session(struct nfs_client *clp, unsigned long lease_time)
5896 struct nfs4_session *session = clp->cl_session;
5899 spin_lock(&clp->cl_lock);
5900 if (test_and_clear_bit(NFS4_SESSION_INITING, &session->session_state)) {
5902 * Do not set NFS_CS_CHECK_LEASE_TIME instead set the
5903 * DS lease to be equal to the MDS lease.
5905 clp->cl_lease_time = lease_time;
5906 clp->cl_last_renewal = jiffies;
5908 spin_unlock(&clp->cl_lock);
5910 ret = nfs41_check_session_ready(clp);
5913 /* Test for the DS role */
5914 if (!is_ds_client(clp))
5918 EXPORT_SYMBOL_GPL(nfs4_init_ds_session);
5922 * Renew the cl_session lease.
5924 struct nfs4_sequence_data {
5925 struct nfs_client *clp;
5926 struct nfs4_sequence_args args;
5927 struct nfs4_sequence_res res;
5930 static void nfs41_sequence_release(void *data)
5932 struct nfs4_sequence_data *calldata = data;
5933 struct nfs_client *clp = calldata->clp;
5935 if (atomic_read(&clp->cl_count) > 1)
5936 nfs4_schedule_state_renewal(clp);
5937 nfs_put_client(clp);
5941 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5943 switch(task->tk_status) {
5944 case -NFS4ERR_DELAY:
5945 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5948 nfs4_schedule_lease_recovery(clp);
5953 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5955 struct nfs4_sequence_data *calldata = data;
5956 struct nfs_client *clp = calldata->clp;
5958 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5961 if (task->tk_status < 0) {
5962 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5963 if (atomic_read(&clp->cl_count) == 1)
5966 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5967 rpc_restart_call_prepare(task);
5971 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5973 dprintk("<-- %s\n", __func__);
5976 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5978 struct nfs4_sequence_data *calldata = data;
5979 struct nfs_client *clp = calldata->clp;
5980 struct nfs4_sequence_args *args;
5981 struct nfs4_sequence_res *res;
5983 args = task->tk_msg.rpc_argp;
5984 res = task->tk_msg.rpc_resp;
5986 if (nfs41_setup_sequence(clp->cl_session, args, res, task))
5988 rpc_call_start(task);
5991 static const struct rpc_call_ops nfs41_sequence_ops = {
5992 .rpc_call_done = nfs41_sequence_call_done,
5993 .rpc_call_prepare = nfs41_sequence_prepare,
5994 .rpc_release = nfs41_sequence_release,
5997 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
5999 struct nfs4_sequence_data *calldata;
6000 struct rpc_message msg = {
6001 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
6004 struct rpc_task_setup task_setup_data = {
6005 .rpc_client = clp->cl_rpcclient,
6006 .rpc_message = &msg,
6007 .callback_ops = &nfs41_sequence_ops,
6008 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
6011 if (!atomic_inc_not_zero(&clp->cl_count))
6012 return ERR_PTR(-EIO);
6013 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6014 if (calldata == NULL) {
6015 nfs_put_client(clp);
6016 return ERR_PTR(-ENOMEM);
6018 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
6019 msg.rpc_argp = &calldata->args;
6020 msg.rpc_resp = &calldata->res;
6021 calldata->clp = clp;
6022 task_setup_data.callback_data = calldata;
6024 return rpc_run_task(&task_setup_data);
6027 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
6029 struct rpc_task *task;
6032 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
6034 task = _nfs41_proc_sequence(clp, cred);
6036 ret = PTR_ERR(task);
6038 rpc_put_task_async(task);
6039 dprintk("<-- %s status=%d\n", __func__, ret);
6043 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
6045 struct rpc_task *task;
6048 task = _nfs41_proc_sequence(clp, cred);
6050 ret = PTR_ERR(task);
6053 ret = rpc_wait_for_completion_task(task);
6055 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
6057 if (task->tk_status == 0)
6058 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
6059 ret = task->tk_status;
6063 dprintk("<-- %s status=%d\n", __func__, ret);
6067 struct nfs4_reclaim_complete_data {
6068 struct nfs_client *clp;
6069 struct nfs41_reclaim_complete_args arg;
6070 struct nfs41_reclaim_complete_res res;
6073 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
6075 struct nfs4_reclaim_complete_data *calldata = data;
6077 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
6078 if (nfs41_setup_sequence(calldata->clp->cl_session,
6079 &calldata->arg.seq_args,
6080 &calldata->res.seq_res, task))
6083 rpc_call_start(task);
6086 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6088 switch(task->tk_status) {
6090 case -NFS4ERR_COMPLETE_ALREADY:
6091 case -NFS4ERR_WRONG_CRED: /* What to do here? */
6093 case -NFS4ERR_DELAY:
6094 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6096 case -NFS4ERR_RETRY_UNCACHED_REP:
6099 nfs4_schedule_lease_recovery(clp);
6104 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
6106 struct nfs4_reclaim_complete_data *calldata = data;
6107 struct nfs_client *clp = calldata->clp;
6108 struct nfs4_sequence_res *res = &calldata->res.seq_res;
6110 dprintk("--> %s\n", __func__);
6111 if (!nfs41_sequence_done(task, res))
6114 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
6115 rpc_restart_call_prepare(task);
6118 dprintk("<-- %s\n", __func__);
6121 static void nfs4_free_reclaim_complete_data(void *data)
6123 struct nfs4_reclaim_complete_data *calldata = data;
6128 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6129 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
6130 .rpc_call_done = nfs4_reclaim_complete_done,
6131 .rpc_release = nfs4_free_reclaim_complete_data,
6135 * Issue a global reclaim complete.
6137 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
6139 struct nfs4_reclaim_complete_data *calldata;
6140 struct rpc_task *task;
6141 struct rpc_message msg = {
6142 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
6144 struct rpc_task_setup task_setup_data = {
6145 .rpc_client = clp->cl_rpcclient,
6146 .rpc_message = &msg,
6147 .callback_ops = &nfs4_reclaim_complete_call_ops,
6148 .flags = RPC_TASK_ASYNC,
6150 int status = -ENOMEM;
6152 dprintk("--> %s\n", __func__);
6153 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6154 if (calldata == NULL)
6156 calldata->clp = clp;
6157 calldata->arg.one_fs = 0;
6159 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6160 msg.rpc_argp = &calldata->arg;
6161 msg.rpc_resp = &calldata->res;
6162 task_setup_data.callback_data = calldata;
6163 task = rpc_run_task(&task_setup_data);
6165 status = PTR_ERR(task);
6168 status = nfs4_wait_for_completion_rpc_task(task);
6170 status = task->tk_status;
6174 dprintk("<-- %s status=%d\n", __func__, status);
6179 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
6181 struct nfs4_layoutget *lgp = calldata;
6182 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6184 dprintk("--> %s\n", __func__);
6185 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6186 * right now covering the LAYOUTGET we are about to send.
6187 * However, that is not so catastrophic, and there seems
6188 * to be no way to prevent it completely.
6190 if (nfs4_setup_sequence(server, &lgp->args.seq_args,
6191 &lgp->res.seq_res, task))
6193 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
6194 NFS_I(lgp->args.inode)->layout,
6195 lgp->args.ctx->state)) {
6196 rpc_exit(task, NFS4_OK);
6199 rpc_call_start(task);
6202 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
6204 struct nfs4_layoutget *lgp = calldata;
6205 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6207 dprintk("--> %s\n", __func__);
6209 if (!nfs4_sequence_done(task, &lgp->res.seq_res))
6212 switch (task->tk_status) {
6215 case -NFS4ERR_LAYOUTTRYLATER:
6216 case -NFS4ERR_RECALLCONFLICT:
6217 task->tk_status = -NFS4ERR_DELAY;
6220 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6221 rpc_restart_call_prepare(task);
6225 dprintk("<-- %s\n", __func__);
6228 static void nfs4_layoutget_release(void *calldata)
6230 struct nfs4_layoutget *lgp = calldata;
6232 dprintk("--> %s\n", __func__);
6233 put_nfs_open_context(lgp->args.ctx);
6235 dprintk("<-- %s\n", __func__);
6238 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6239 .rpc_call_prepare = nfs4_layoutget_prepare,
6240 .rpc_call_done = nfs4_layoutget_done,
6241 .rpc_release = nfs4_layoutget_release,
6244 int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)
6246 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6247 struct rpc_task *task;
6248 struct rpc_message msg = {
6249 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
6250 .rpc_argp = &lgp->args,
6251 .rpc_resp = &lgp->res,
6253 struct rpc_task_setup task_setup_data = {
6254 .rpc_client = server->client,
6255 .rpc_message = &msg,
6256 .callback_ops = &nfs4_layoutget_call_ops,
6257 .callback_data = lgp,
6258 .flags = RPC_TASK_ASYNC,
6262 dprintk("--> %s\n", __func__);
6264 lgp->res.layoutp = &lgp->args.layout;
6265 lgp->res.seq_res.sr_slot = NULL;
6266 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
6267 task = rpc_run_task(&task_setup_data);
6269 return PTR_ERR(task);
6270 status = nfs4_wait_for_completion_rpc_task(task);
6272 status = task->tk_status;
6274 status = pnfs_layout_process(lgp);
6276 dprintk("<-- %s status=%d\n", __func__, status);
6281 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
6283 struct nfs4_layoutreturn *lrp = calldata;
6285 dprintk("--> %s\n", __func__);
6286 if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args,
6287 &lrp->res.seq_res, task))
6289 rpc_call_start(task);
6292 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
6294 struct nfs4_layoutreturn *lrp = calldata;
6295 struct nfs_server *server;
6296 struct pnfs_layout_hdr *lo = lrp->args.layout;
6298 dprintk("--> %s\n", __func__);
6300 if (!nfs4_sequence_done(task, &lrp->res.seq_res))
6303 server = NFS_SERVER(lrp->args.inode);
6304 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6305 rpc_restart_call_prepare(task);
6308 spin_lock(&lo->plh_inode->i_lock);
6309 if (task->tk_status == 0) {
6310 if (lrp->res.lrs_present) {
6311 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
6313 BUG_ON(!list_empty(&lo->plh_segs));
6315 lo->plh_block_lgets--;
6316 spin_unlock(&lo->plh_inode->i_lock);
6317 dprintk("<-- %s\n", __func__);
6320 static void nfs4_layoutreturn_release(void *calldata)
6322 struct nfs4_layoutreturn *lrp = calldata;
6324 dprintk("--> %s\n", __func__);
6325 put_layout_hdr(lrp->args.layout);
6327 dprintk("<-- %s\n", __func__);
6330 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6331 .rpc_call_prepare = nfs4_layoutreturn_prepare,
6332 .rpc_call_done = nfs4_layoutreturn_done,
6333 .rpc_release = nfs4_layoutreturn_release,
6336 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
6338 struct rpc_task *task;
6339 struct rpc_message msg = {
6340 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
6341 .rpc_argp = &lrp->args,
6342 .rpc_resp = &lrp->res,
6344 struct rpc_task_setup task_setup_data = {
6345 .rpc_client = lrp->clp->cl_rpcclient,
6346 .rpc_message = &msg,
6347 .callback_ops = &nfs4_layoutreturn_call_ops,
6348 .callback_data = lrp,
6352 dprintk("--> %s\n", __func__);
6353 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
6354 task = rpc_run_task(&task_setup_data);
6356 return PTR_ERR(task);
6357 status = task->tk_status;
6358 dprintk("<-- %s status=%d\n", __func__, status);
6364 * Retrieve the list of Data Server devices from the MDS.
6366 static int _nfs4_getdevicelist(struct nfs_server *server,
6367 const struct nfs_fh *fh,
6368 struct pnfs_devicelist *devlist)
6370 struct nfs4_getdevicelist_args args = {
6372 .layoutclass = server->pnfs_curr_ld->id,
6374 struct nfs4_getdevicelist_res res = {
6377 struct rpc_message msg = {
6378 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
6384 dprintk("--> %s\n", __func__);
6385 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
6387 dprintk("<-- %s status=%d\n", __func__, status);
6391 int nfs4_proc_getdevicelist(struct nfs_server *server,
6392 const struct nfs_fh *fh,
6393 struct pnfs_devicelist *devlist)
6395 struct nfs4_exception exception = { };
6399 err = nfs4_handle_exception(server,
6400 _nfs4_getdevicelist(server, fh, devlist),
6402 } while (exception.retry);
6404 dprintk("%s: err=%d, num_devs=%u\n", __func__,
6405 err, devlist->num_devs);
6409 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
6412 _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6414 struct nfs4_getdeviceinfo_args args = {
6417 struct nfs4_getdeviceinfo_res res = {
6420 struct rpc_message msg = {
6421 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
6427 dprintk("--> %s\n", __func__);
6428 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6429 dprintk("<-- %s status=%d\n", __func__, status);
6434 int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6436 struct nfs4_exception exception = { };
6440 err = nfs4_handle_exception(server,
6441 _nfs4_proc_getdeviceinfo(server, pdev),
6443 } while (exception.retry);
6446 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
6448 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
6450 struct nfs4_layoutcommit_data *data = calldata;
6451 struct nfs_server *server = NFS_SERVER(data->args.inode);
6453 if (nfs4_setup_sequence(server, &data->args.seq_args,
6454 &data->res.seq_res, task))
6456 rpc_call_start(task);
6460 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
6462 struct nfs4_layoutcommit_data *data = calldata;
6463 struct nfs_server *server = NFS_SERVER(data->args.inode);
6465 if (!nfs4_sequence_done(task, &data->res.seq_res))
6468 switch (task->tk_status) { /* Just ignore these failures */
6469 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
6470 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
6471 case -NFS4ERR_BADLAYOUT: /* no layout */
6472 case -NFS4ERR_GRACE: /* loca_recalim always false */
6473 task->tk_status = 0;
6476 nfs_post_op_update_inode_force_wcc(data->args.inode,
6480 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6481 rpc_restart_call_prepare(task);
6487 static void nfs4_layoutcommit_release(void *calldata)
6489 struct nfs4_layoutcommit_data *data = calldata;
6490 struct pnfs_layout_segment *lseg, *tmp;
6491 unsigned long *bitlock = &NFS_I(data->args.inode)->flags;
6493 pnfs_cleanup_layoutcommit(data);
6494 /* Matched by references in pnfs_set_layoutcommit */
6495 list_for_each_entry_safe(lseg, tmp, &data->lseg_list, pls_lc_list) {
6496 list_del_init(&lseg->pls_lc_list);
6497 if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT,
6502 clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock);
6503 smp_mb__after_clear_bit();
6504 wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
6506 put_rpccred(data->cred);
6510 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
6511 .rpc_call_prepare = nfs4_layoutcommit_prepare,
6512 .rpc_call_done = nfs4_layoutcommit_done,
6513 .rpc_release = nfs4_layoutcommit_release,
6517 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
6519 struct rpc_message msg = {
6520 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
6521 .rpc_argp = &data->args,
6522 .rpc_resp = &data->res,
6523 .rpc_cred = data->cred,
6525 struct rpc_task_setup task_setup_data = {
6526 .task = &data->task,
6527 .rpc_client = NFS_CLIENT(data->args.inode),
6528 .rpc_message = &msg,
6529 .callback_ops = &nfs4_layoutcommit_ops,
6530 .callback_data = data,
6531 .flags = RPC_TASK_ASYNC,
6533 struct rpc_task *task;
6536 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
6537 "lbw: %llu inode %lu\n",
6538 data->task.tk_pid, sync,
6539 data->args.lastbytewritten,
6540 data->args.inode->i_ino);
6542 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6543 task = rpc_run_task(&task_setup_data);
6545 return PTR_ERR(task);
6548 status = nfs4_wait_for_completion_rpc_task(task);
6551 status = task->tk_status;
6553 dprintk("%s: status %d\n", __func__, status);
6559 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6560 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6562 struct nfs41_secinfo_no_name_args args = {
6563 .style = SECINFO_STYLE_CURRENT_FH,
6565 struct nfs4_secinfo_res res = {
6568 struct rpc_message msg = {
6569 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
6573 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6577 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6578 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6580 struct nfs4_exception exception = { };
6583 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6586 case -NFS4ERR_WRONGSEC:
6587 case -NFS4ERR_NOTSUPP:
6590 err = nfs4_handle_exception(server, err, &exception);
6592 } while (exception.retry);
6598 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
6599 struct nfs_fsinfo *info)
6603 rpc_authflavor_t flavor;
6604 struct nfs4_secinfo_flavors *flavors;
6606 page = alloc_page(GFP_KERNEL);
6612 flavors = page_address(page);
6613 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6616 * Fall back on "guess and check" method if
6617 * the server doesn't support SECINFO_NO_NAME
6619 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
6620 err = nfs4_find_root_sec(server, fhandle, info);
6626 flavor = nfs_find_best_sec(flavors);
6628 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
6638 static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6641 struct nfs41_test_stateid_args args = {
6644 struct nfs41_test_stateid_res res;
6645 struct rpc_message msg = {
6646 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
6651 dprintk("NFS call test_stateid %p\n", stateid);
6652 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6653 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
6654 if (status != NFS_OK) {
6655 dprintk("NFS reply test_stateid: failed, %d\n", status);
6658 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
6663 * nfs41_test_stateid - perform a TEST_STATEID operation
6665 * @server: server / transport on which to perform the operation
6666 * @stateid: state ID to test
6668 * Returns NFS_OK if the server recognizes that "stateid" is valid.
6669 * Otherwise a negative NFS4ERR value is returned if the operation
6670 * failed or the state ID is not currently valid.
6672 static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6674 struct nfs4_exception exception = { };
6677 err = _nfs41_test_stateid(server, stateid);
6678 if (err != -NFS4ERR_DELAY)
6680 nfs4_handle_exception(server, err, &exception);
6681 } while (exception.retry);
6685 static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6687 struct nfs41_free_stateid_args args = {
6690 struct nfs41_free_stateid_res res;
6691 struct rpc_message msg = {
6692 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
6698 dprintk("NFS call free_stateid %p\n", stateid);
6699 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6700 status = nfs4_call_sync_sequence(server->client, server, &msg,
6701 &args.seq_args, &res.seq_res, 1);
6702 dprintk("NFS reply free_stateid: %d\n", status);
6707 * nfs41_free_stateid - perform a FREE_STATEID operation
6709 * @server: server / transport on which to perform the operation
6710 * @stateid: state ID to release
6712 * Returns NFS_OK if the server freed "stateid". Otherwise a
6713 * negative NFS4ERR value is returned.
6715 static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6717 struct nfs4_exception exception = { };
6720 err = _nfs4_free_stateid(server, stateid);
6721 if (err != -NFS4ERR_DELAY)
6723 nfs4_handle_exception(server, err, &exception);
6724 } while (exception.retry);
6728 static bool nfs41_match_stateid(const nfs4_stateid *s1,
6729 const nfs4_stateid *s2)
6731 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6734 if (s1->seqid == s2->seqid)
6736 if (s1->seqid == 0 || s2->seqid == 0)
6742 #endif /* CONFIG_NFS_V4_1 */
6744 static bool nfs4_match_stateid(const nfs4_stateid *s1,
6745 const nfs4_stateid *s2)
6747 return nfs4_stateid_match(s1, s2);
6751 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6752 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6753 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6754 .recover_open = nfs4_open_reclaim,
6755 .recover_lock = nfs4_lock_reclaim,
6756 .establish_clid = nfs4_init_clientid,
6757 .get_clid_cred = nfs4_get_setclientid_cred,
6760 #if defined(CONFIG_NFS_V4_1)
6761 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6762 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6763 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6764 .recover_open = nfs4_open_reclaim,
6765 .recover_lock = nfs4_lock_reclaim,
6766 .establish_clid = nfs41_init_clientid,
6767 .get_clid_cred = nfs4_get_exchange_id_cred,
6768 .reclaim_complete = nfs41_proc_reclaim_complete,
6770 #endif /* CONFIG_NFS_V4_1 */
6772 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6773 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6774 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6775 .recover_open = nfs4_open_expired,
6776 .recover_lock = nfs4_lock_expired,
6777 .establish_clid = nfs4_init_clientid,
6778 .get_clid_cred = nfs4_get_setclientid_cred,
6781 #if defined(CONFIG_NFS_V4_1)
6782 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6783 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6784 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6785 .recover_open = nfs41_open_expired,
6786 .recover_lock = nfs41_lock_expired,
6787 .establish_clid = nfs41_init_clientid,
6788 .get_clid_cred = nfs4_get_exchange_id_cred,
6790 #endif /* CONFIG_NFS_V4_1 */
6792 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6793 .sched_state_renewal = nfs4_proc_async_renew,
6794 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6795 .renew_lease = nfs4_proc_renew,
6798 #if defined(CONFIG_NFS_V4_1)
6799 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6800 .sched_state_renewal = nfs41_proc_async_sequence,
6801 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6802 .renew_lease = nfs4_proc_sequence,
6806 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6808 .call_sync = _nfs4_call_sync,
6809 .match_stateid = nfs4_match_stateid,
6810 .find_root_sec = nfs4_find_root_sec,
6811 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6812 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
6813 .state_renewal_ops = &nfs40_state_renewal_ops,
6816 #if defined(CONFIG_NFS_V4_1)
6817 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6819 .call_sync = _nfs4_call_sync_session,
6820 .match_stateid = nfs41_match_stateid,
6821 .find_root_sec = nfs41_find_root_sec,
6822 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6823 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
6824 .state_renewal_ops = &nfs41_state_renewal_ops,
6828 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
6829 [0] = &nfs_v4_0_minor_ops,
6830 #if defined(CONFIG_NFS_V4_1)
6831 [1] = &nfs_v4_1_minor_ops,
6835 const struct inode_operations nfs4_dir_inode_operations = {
6836 .create = nfs_create,
6837 .lookup = nfs_lookup,
6838 .atomic_open = nfs_atomic_open,
6840 .unlink = nfs_unlink,
6841 .symlink = nfs_symlink,
6845 .rename = nfs_rename,
6846 .permission = nfs_permission,
6847 .getattr = nfs_getattr,
6848 .setattr = nfs_setattr,
6849 .getxattr = generic_getxattr,
6850 .setxattr = generic_setxattr,
6851 .listxattr = generic_listxattr,
6852 .removexattr = generic_removexattr,
6855 static const struct inode_operations nfs4_file_inode_operations = {
6856 .permission = nfs_permission,
6857 .getattr = nfs_getattr,
6858 .setattr = nfs_setattr,
6859 .getxattr = generic_getxattr,
6860 .setxattr = generic_setxattr,
6861 .listxattr = generic_listxattr,
6862 .removexattr = generic_removexattr,
6865 const struct nfs_rpc_ops nfs_v4_clientops = {
6866 .version = 4, /* protocol version */
6867 .dentry_ops = &nfs4_dentry_operations,
6868 .dir_inode_ops = &nfs4_dir_inode_operations,
6869 .file_inode_ops = &nfs4_file_inode_operations,
6870 .file_ops = &nfs4_file_operations,
6871 .getroot = nfs4_proc_get_root,
6872 .submount = nfs4_submount,
6873 .getattr = nfs4_proc_getattr,
6874 .setattr = nfs4_proc_setattr,
6875 .lookup = nfs4_proc_lookup,
6876 .access = nfs4_proc_access,
6877 .readlink = nfs4_proc_readlink,
6878 .create = nfs4_proc_create,
6879 .remove = nfs4_proc_remove,
6880 .unlink_setup = nfs4_proc_unlink_setup,
6881 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6882 .unlink_done = nfs4_proc_unlink_done,
6883 .rename = nfs4_proc_rename,
6884 .rename_setup = nfs4_proc_rename_setup,
6885 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6886 .rename_done = nfs4_proc_rename_done,
6887 .link = nfs4_proc_link,
6888 .symlink = nfs4_proc_symlink,
6889 .mkdir = nfs4_proc_mkdir,
6890 .rmdir = nfs4_proc_remove,
6891 .readdir = nfs4_proc_readdir,
6892 .mknod = nfs4_proc_mknod,
6893 .statfs = nfs4_proc_statfs,
6894 .fsinfo = nfs4_proc_fsinfo,
6895 .pathconf = nfs4_proc_pathconf,
6896 .set_capabilities = nfs4_server_capabilities,
6897 .decode_dirent = nfs4_decode_dirent,
6898 .read_setup = nfs4_proc_read_setup,
6899 .read_pageio_init = pnfs_pageio_init_read,
6900 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6901 .read_done = nfs4_read_done,
6902 .write_setup = nfs4_proc_write_setup,
6903 .write_pageio_init = pnfs_pageio_init_write,
6904 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6905 .write_done = nfs4_write_done,
6906 .commit_setup = nfs4_proc_commit_setup,
6907 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
6908 .commit_done = nfs4_commit_done,
6909 .lock = nfs4_proc_lock,
6910 .clear_acl_cache = nfs4_zap_acl_attr,
6911 .close_context = nfs4_close_context,
6912 .open_context = nfs4_atomic_open,
6913 .have_delegation = nfs4_have_delegation,
6914 .return_delegation = nfs4_inode_return_delegation,
6915 .alloc_client = nfs4_alloc_client,
6916 .init_client = nfs4_init_client,
6917 .free_client = nfs4_free_client,
6920 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
6921 .prefix = XATTR_NAME_NFSV4_ACL,
6922 .list = nfs4_xattr_list_nfs4_acl,
6923 .get = nfs4_xattr_get_nfs4_acl,
6924 .set = nfs4_xattr_set_nfs4_acl,
6927 const struct xattr_handler *nfs4_xattr_handlers[] = {
6928 &nfs4_xattr_nfs4_acl_handler,
6932 module_param(max_session_slots, ushort, 0644);
6933 MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
6934 "requests the client will negotiate");