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/xattr.h>
56 #include <linux/utsname.h>
57 #include <linux/freezer.h>
60 #include "delegation.h"
66 #include "nfs4session.h"
69 #include "nfs4trace.h"
71 #define NFSDBG_FACILITY NFSDBG_PROC
73 #define NFS4_POLL_RETRY_MIN (HZ/10)
74 #define NFS4_POLL_RETRY_MAX (15*HZ)
77 static int _nfs4_proc_open(struct nfs4_opendata *data);
78 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
79 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
80 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
81 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
82 static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label);
83 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label);
84 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
85 struct nfs_fattr *fattr, struct iattr *sattr,
86 struct nfs4_state *state, struct nfs4_label *ilabel,
87 struct nfs4_label *olabel);
88 #ifdef CONFIG_NFS_V4_1
89 static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *,
91 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *,
95 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
96 static inline struct nfs4_label *
97 nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
98 struct iattr *sattr, struct nfs4_label *label)
105 if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0)
108 if (NFS_SERVER(dir)->nfs_client->cl_minorversion < 2)
111 err = security_dentry_init_security(dentry, sattr->ia_mode,
112 &dentry->d_name, (void **)&label->label, &label->len);
119 nfs4_label_release_security(struct nfs4_label *label)
122 security_release_secctx(label->label, label->len);
124 static inline u32 *nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label)
127 return server->attr_bitmask;
129 return server->attr_bitmask_nl;
132 static inline struct nfs4_label *
133 nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
134 struct iattr *sattr, struct nfs4_label *l)
137 nfs4_label_release_security(struct nfs4_label *label)
140 nfs4_bitmask(struct nfs_server *server, struct nfs4_label *label)
141 { return server->attr_bitmask; }
144 /* Prevent leaks of NFSv4 errors into userland */
145 static int nfs4_map_errors(int err)
150 case -NFS4ERR_RESOURCE:
151 case -NFS4ERR_LAYOUTTRYLATER:
152 case -NFS4ERR_RECALLCONFLICT:
154 case -NFS4ERR_WRONGSEC:
156 case -NFS4ERR_BADOWNER:
157 case -NFS4ERR_BADNAME:
159 case -NFS4ERR_SHARE_DENIED:
161 case -NFS4ERR_MINOR_VERS_MISMATCH:
162 return -EPROTONOSUPPORT;
163 case -NFS4ERR_ACCESS:
165 case -NFS4ERR_FILE_OPEN:
168 dprintk("%s could not handle NFSv4 error %d\n",
176 * This is our standard bitmap for GETATTR requests.
178 const u32 nfs4_fattr_bitmap[3] = {
180 | FATTR4_WORD0_CHANGE
183 | FATTR4_WORD0_FILEID,
185 | FATTR4_WORD1_NUMLINKS
187 | FATTR4_WORD1_OWNER_GROUP
188 | FATTR4_WORD1_RAWDEV
189 | FATTR4_WORD1_SPACE_USED
190 | FATTR4_WORD1_TIME_ACCESS
191 | FATTR4_WORD1_TIME_METADATA
192 | FATTR4_WORD1_TIME_MODIFY,
193 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
194 FATTR4_WORD2_SECURITY_LABEL
198 static const u32 nfs4_pnfs_open_bitmap[3] = {
200 | FATTR4_WORD0_CHANGE
203 | FATTR4_WORD0_FILEID,
205 | FATTR4_WORD1_NUMLINKS
207 | FATTR4_WORD1_OWNER_GROUP
208 | FATTR4_WORD1_RAWDEV
209 | FATTR4_WORD1_SPACE_USED
210 | FATTR4_WORD1_TIME_ACCESS
211 | FATTR4_WORD1_TIME_METADATA
212 | FATTR4_WORD1_TIME_MODIFY,
213 FATTR4_WORD2_MDSTHRESHOLD
216 static const u32 nfs4_open_noattr_bitmap[3] = {
218 | FATTR4_WORD0_CHANGE
219 | FATTR4_WORD0_FILEID,
222 const u32 nfs4_statfs_bitmap[3] = {
223 FATTR4_WORD0_FILES_AVAIL
224 | FATTR4_WORD0_FILES_FREE
225 | FATTR4_WORD0_FILES_TOTAL,
226 FATTR4_WORD1_SPACE_AVAIL
227 | FATTR4_WORD1_SPACE_FREE
228 | FATTR4_WORD1_SPACE_TOTAL
231 const u32 nfs4_pathconf_bitmap[3] = {
233 | FATTR4_WORD0_MAXNAME,
237 const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE
238 | FATTR4_WORD0_MAXREAD
239 | FATTR4_WORD0_MAXWRITE
240 | FATTR4_WORD0_LEASE_TIME,
241 FATTR4_WORD1_TIME_DELTA
242 | FATTR4_WORD1_FS_LAYOUT_TYPES,
243 FATTR4_WORD2_LAYOUT_BLKSIZE
246 const u32 nfs4_fs_locations_bitmap[3] = {
248 | FATTR4_WORD0_CHANGE
251 | FATTR4_WORD0_FILEID
252 | FATTR4_WORD0_FS_LOCATIONS,
254 | FATTR4_WORD1_NUMLINKS
256 | FATTR4_WORD1_OWNER_GROUP
257 | FATTR4_WORD1_RAWDEV
258 | FATTR4_WORD1_SPACE_USED
259 | FATTR4_WORD1_TIME_ACCESS
260 | FATTR4_WORD1_TIME_METADATA
261 | FATTR4_WORD1_TIME_MODIFY
262 | FATTR4_WORD1_MOUNTED_ON_FILEID,
265 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
266 struct nfs4_readdir_arg *readdir)
271 readdir->cookie = cookie;
272 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
277 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
282 * NFSv4 servers do not return entries for '.' and '..'
283 * Therefore, we fake these entries here. We let '.'
284 * have cookie 0 and '..' have cookie 1. Note that
285 * when talking to the server, we always send cookie 0
288 start = p = kmap_atomic(*readdir->pages);
291 *p++ = xdr_one; /* next */
292 *p++ = xdr_zero; /* cookie, first word */
293 *p++ = xdr_one; /* cookie, second word */
294 *p++ = xdr_one; /* entry len */
295 memcpy(p, ".\0\0\0", 4); /* entry */
297 *p++ = xdr_one; /* bitmap length */
298 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
299 *p++ = htonl(8); /* attribute buffer length */
300 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
303 *p++ = xdr_one; /* next */
304 *p++ = xdr_zero; /* cookie, first word */
305 *p++ = xdr_two; /* cookie, second word */
306 *p++ = xdr_two; /* entry len */
307 memcpy(p, "..\0\0", 4); /* entry */
309 *p++ = xdr_one; /* bitmap length */
310 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
311 *p++ = htonl(8); /* attribute buffer length */
312 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
314 readdir->pgbase = (char *)p - (char *)start;
315 readdir->count -= readdir->pgbase;
316 kunmap_atomic(start);
319 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
326 *timeout = NFS4_POLL_RETRY_MIN;
327 if (*timeout > NFS4_POLL_RETRY_MAX)
328 *timeout = NFS4_POLL_RETRY_MAX;
329 freezable_schedule_timeout_killable_unsafe(*timeout);
330 if (fatal_signal_pending(current))
336 /* This is the error handling routine for processes that are allowed
339 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
341 struct nfs_client *clp = server->nfs_client;
342 struct nfs4_state *state = exception->state;
343 struct inode *inode = exception->inode;
346 exception->retry = 0;
350 case -NFS4ERR_OPENMODE:
351 if (inode && nfs4_have_delegation(inode, FMODE_READ)) {
352 nfs4_inode_return_delegation(inode);
353 exception->retry = 1;
358 ret = nfs4_schedule_stateid_recovery(server, state);
361 goto wait_on_recovery;
362 case -NFS4ERR_DELEG_REVOKED:
363 case -NFS4ERR_ADMIN_REVOKED:
364 case -NFS4ERR_BAD_STATEID:
365 if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) {
366 nfs_remove_bad_delegation(inode);
367 exception->retry = 1;
372 ret = nfs4_schedule_stateid_recovery(server, state);
375 goto wait_on_recovery;
376 case -NFS4ERR_EXPIRED:
378 ret = nfs4_schedule_stateid_recovery(server, state);
382 case -NFS4ERR_STALE_STATEID:
383 case -NFS4ERR_STALE_CLIENTID:
384 nfs4_schedule_lease_recovery(clp);
385 goto wait_on_recovery;
386 #if defined(CONFIG_NFS_V4_1)
387 case -NFS4ERR_BADSESSION:
388 case -NFS4ERR_BADSLOT:
389 case -NFS4ERR_BAD_HIGH_SLOT:
390 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
391 case -NFS4ERR_DEADSESSION:
392 case -NFS4ERR_SEQ_FALSE_RETRY:
393 case -NFS4ERR_SEQ_MISORDERED:
394 dprintk("%s ERROR: %d Reset session\n", __func__,
396 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
397 goto wait_on_recovery;
398 #endif /* defined(CONFIG_NFS_V4_1) */
399 case -NFS4ERR_FILE_OPEN:
400 if (exception->timeout > HZ) {
401 /* We have retried a decent amount, time to
409 ret = nfs4_delay(server->client, &exception->timeout);
412 case -NFS4ERR_RETRY_UNCACHED_REP:
413 case -NFS4ERR_OLD_STATEID:
414 exception->retry = 1;
416 case -NFS4ERR_BADOWNER:
417 /* The following works around a Linux server bug! */
418 case -NFS4ERR_BADNAME:
419 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
420 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
421 exception->retry = 1;
422 printk(KERN_WARNING "NFS: v4 server %s "
423 "does not accept raw "
425 "Reenabling the idmapper.\n",
426 server->nfs_client->cl_hostname);
429 /* We failed to handle the error */
430 return nfs4_map_errors(ret);
432 ret = nfs4_wait_clnt_recover(clp);
434 exception->retry = 1;
439 * Return 'true' if 'clp' is using an rpc_client that is integrity protected
440 * or 'false' otherwise.
442 static bool _nfs4_is_integrity_protected(struct nfs_client *clp)
444 rpc_authflavor_t flavor = clp->cl_rpcclient->cl_auth->au_flavor;
446 if (flavor == RPC_AUTH_GSS_KRB5I ||
447 flavor == RPC_AUTH_GSS_KRB5P)
453 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
455 spin_lock(&clp->cl_lock);
456 if (time_before(clp->cl_last_renewal,timestamp))
457 clp->cl_last_renewal = timestamp;
458 spin_unlock(&clp->cl_lock);
461 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
463 do_renew_lease(server->nfs_client, timestamp);
466 #if defined(CONFIG_NFS_V4_1)
468 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
470 struct nfs4_session *session;
471 struct nfs4_slot_table *tbl;
472 bool send_new_highest_used_slotid = false;
475 /* just wake up the next guy waiting since
476 * we may have not consumed a slot after all */
477 dprintk("%s: No slot\n", __func__);
480 tbl = res->sr_slot->table;
481 session = tbl->session;
483 spin_lock(&tbl->slot_tbl_lock);
484 /* Be nice to the server: try to ensure that the last transmitted
485 * value for highest_user_slotid <= target_highest_slotid
487 if (tbl->highest_used_slotid > tbl->target_highest_slotid)
488 send_new_highest_used_slotid = true;
490 if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) {
491 send_new_highest_used_slotid = false;
494 nfs4_free_slot(tbl, res->sr_slot);
496 if (tbl->highest_used_slotid != NFS4_NO_SLOT)
497 send_new_highest_used_slotid = false;
499 spin_unlock(&tbl->slot_tbl_lock);
501 if (send_new_highest_used_slotid)
502 nfs41_server_notify_highest_slotid_update(session->clp);
505 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
507 struct nfs4_session *session;
508 struct nfs4_slot *slot;
509 struct nfs_client *clp;
510 bool interrupted = false;
513 /* don't increment the sequence number if the task wasn't sent */
514 if (!RPC_WAS_SENT(task))
518 session = slot->table->session;
520 if (slot->interrupted) {
521 slot->interrupted = 0;
525 trace_nfs4_sequence_done(session, res);
526 /* Check the SEQUENCE operation status */
527 switch (res->sr_status) {
529 /* Update the slot's sequence and clientid lease timer */
532 do_renew_lease(clp, res->sr_timestamp);
533 /* Check sequence flags */
534 if (res->sr_status_flags != 0)
535 nfs4_schedule_lease_recovery(clp);
536 nfs41_update_target_slotid(slot->table, slot, res);
540 * sr_status remains 1 if an RPC level error occurred.
541 * The server may or may not have processed the sequence
543 * Mark the slot as having hosted an interrupted RPC call.
545 slot->interrupted = 1;
548 /* The server detected a resend of the RPC call and
549 * returned NFS4ERR_DELAY as per Section 2.10.6.2
552 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
557 case -NFS4ERR_BADSLOT:
559 * The slot id we used was probably retired. Try again
560 * using a different slot id.
563 case -NFS4ERR_SEQ_MISORDERED:
565 * Was the last operation on this sequence interrupted?
566 * If so, retry after bumping the sequence number.
573 * Could this slot have been previously retired?
574 * If so, then the server may be expecting seq_nr = 1!
576 if (slot->seq_nr != 1) {
581 case -NFS4ERR_SEQ_FALSE_RETRY:
585 /* Just update the slot sequence no. */
589 /* The session may be reset by one of the error handlers. */
590 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
591 nfs41_sequence_free_slot(res);
594 if (rpc_restart_call_prepare(task)) {
600 if (!rpc_restart_call(task))
602 rpc_delay(task, NFS4_POLL_RETRY_MAX);
606 static int nfs4_sequence_done(struct rpc_task *task,
607 struct nfs4_sequence_res *res)
609 if (res->sr_slot == NULL)
611 return nfs41_sequence_done(task, res);
614 static void nfs41_init_sequence(struct nfs4_sequence_args *args,
615 struct nfs4_sequence_res *res, int cache_reply)
617 args->sa_slot = NULL;
618 args->sa_cache_this = 0;
619 args->sa_privileged = 0;
621 args->sa_cache_this = 1;
625 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
627 args->sa_privileged = 1;
630 int nfs41_setup_sequence(struct nfs4_session *session,
631 struct nfs4_sequence_args *args,
632 struct nfs4_sequence_res *res,
633 struct rpc_task *task)
635 struct nfs4_slot *slot;
636 struct nfs4_slot_table *tbl;
638 dprintk("--> %s\n", __func__);
639 /* slot already allocated? */
640 if (res->sr_slot != NULL)
643 tbl = &session->fc_slot_table;
645 task->tk_timeout = 0;
647 spin_lock(&tbl->slot_tbl_lock);
648 if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state) &&
649 !args->sa_privileged) {
650 /* The state manager will wait until the slot table is empty */
651 dprintk("%s session is draining\n", __func__);
655 slot = nfs4_alloc_slot(tbl);
657 /* If out of memory, try again in 1/4 second */
658 if (slot == ERR_PTR(-ENOMEM))
659 task->tk_timeout = HZ >> 2;
660 dprintk("<-- %s: no free slots\n", __func__);
663 spin_unlock(&tbl->slot_tbl_lock);
665 args->sa_slot = slot;
667 dprintk("<-- %s slotid=%d seqid=%d\n", __func__,
668 slot->slot_nr, slot->seq_nr);
671 res->sr_timestamp = jiffies;
672 res->sr_status_flags = 0;
674 * sr_status is only set in decode_sequence, and so will remain
675 * set to 1 if an rpc level failure occurs.
678 trace_nfs4_setup_sequence(session, args);
680 rpc_call_start(task);
683 /* Privileged tasks are queued with top priority */
684 if (args->sa_privileged)
685 rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task,
686 NULL, RPC_PRIORITY_PRIVILEGED);
688 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
689 spin_unlock(&tbl->slot_tbl_lock);
692 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
694 int nfs4_setup_sequence(const struct nfs_server *server,
695 struct nfs4_sequence_args *args,
696 struct nfs4_sequence_res *res,
697 struct rpc_task *task)
699 struct nfs4_session *session = nfs4_get_session(server);
702 if (session == NULL) {
703 rpc_call_start(task);
707 dprintk("--> %s clp %p session %p sr_slot %d\n",
708 __func__, session->clp, session, res->sr_slot ?
709 res->sr_slot->slot_nr : -1);
711 ret = nfs41_setup_sequence(session, args, res, task);
713 dprintk("<-- %s status=%d\n", __func__, ret);
717 struct nfs41_call_sync_data {
718 const struct nfs_server *seq_server;
719 struct nfs4_sequence_args *seq_args;
720 struct nfs4_sequence_res *seq_res;
723 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
725 struct nfs41_call_sync_data *data = calldata;
726 struct nfs4_session *session = nfs4_get_session(data->seq_server);
728 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
730 nfs41_setup_sequence(session, data->seq_args, data->seq_res, task);
733 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
735 struct nfs41_call_sync_data *data = calldata;
737 nfs41_sequence_done(task, data->seq_res);
740 static const struct rpc_call_ops nfs41_call_sync_ops = {
741 .rpc_call_prepare = nfs41_call_sync_prepare,
742 .rpc_call_done = nfs41_call_sync_done,
745 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
746 struct nfs_server *server,
747 struct rpc_message *msg,
748 struct nfs4_sequence_args *args,
749 struct nfs4_sequence_res *res)
752 struct rpc_task *task;
753 struct nfs41_call_sync_data data = {
754 .seq_server = server,
758 struct rpc_task_setup task_setup = {
761 .callback_ops = &nfs41_call_sync_ops,
762 .callback_data = &data
765 task = rpc_run_task(&task_setup);
769 ret = task->tk_status;
777 void nfs41_init_sequence(struct nfs4_sequence_args *args,
778 struct nfs4_sequence_res *res, int cache_reply)
782 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
787 static int nfs4_sequence_done(struct rpc_task *task,
788 struct nfs4_sequence_res *res)
792 #endif /* CONFIG_NFS_V4_1 */
795 int _nfs4_call_sync(struct rpc_clnt *clnt,
796 struct nfs_server *server,
797 struct rpc_message *msg,
798 struct nfs4_sequence_args *args,
799 struct nfs4_sequence_res *res)
801 return rpc_call_sync(clnt, msg, 0);
805 int nfs4_call_sync(struct rpc_clnt *clnt,
806 struct nfs_server *server,
807 struct rpc_message *msg,
808 struct nfs4_sequence_args *args,
809 struct nfs4_sequence_res *res,
812 nfs41_init_sequence(args, res, cache_reply);
813 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
817 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
819 struct nfs_inode *nfsi = NFS_I(dir);
821 spin_lock(&dir->i_lock);
822 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
823 if (!cinfo->atomic || cinfo->before != dir->i_version)
824 nfs_force_lookup_revalidate(dir);
825 dir->i_version = cinfo->after;
826 nfs_fscache_invalidate(dir);
827 spin_unlock(&dir->i_lock);
830 struct nfs4_opendata {
832 struct nfs_openargs o_arg;
833 struct nfs_openres o_res;
834 struct nfs_open_confirmargs c_arg;
835 struct nfs_open_confirmres c_res;
836 struct nfs4_string owner_name;
837 struct nfs4_string group_name;
838 struct nfs_fattr f_attr;
839 struct nfs4_label *f_label;
841 struct dentry *dentry;
842 struct nfs4_state_owner *owner;
843 struct nfs4_state *state;
845 unsigned long timestamp;
846 unsigned int rpc_done : 1;
847 unsigned int is_recover : 1;
852 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server,
853 int err, struct nfs4_exception *exception)
857 if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1))
859 server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1;
860 exception->retry = 1;
864 static enum open_claim_type4
865 nfs4_map_atomic_open_claim(struct nfs_server *server,
866 enum open_claim_type4 claim)
868 if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
873 case NFS4_OPEN_CLAIM_FH:
874 return NFS4_OPEN_CLAIM_NULL;
875 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
876 return NFS4_OPEN_CLAIM_DELEGATE_CUR;
877 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
878 return NFS4_OPEN_CLAIM_DELEGATE_PREV;
882 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
884 p->o_res.f_attr = &p->f_attr;
885 p->o_res.f_label = p->f_label;
886 p->o_res.seqid = p->o_arg.seqid;
887 p->c_res.seqid = p->c_arg.seqid;
888 p->o_res.server = p->o_arg.server;
889 p->o_res.access_request = p->o_arg.access;
890 nfs_fattr_init(&p->f_attr);
891 nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name);
894 static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
895 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
896 const struct iattr *attrs,
897 struct nfs4_label *label,
898 enum open_claim_type4 claim,
901 struct dentry *parent = dget_parent(dentry);
902 struct inode *dir = parent->d_inode;
903 struct nfs_server *server = NFS_SERVER(dir);
904 struct nfs4_opendata *p;
906 p = kzalloc(sizeof(*p), gfp_mask);
910 p->f_label = nfs4_label_alloc(server, gfp_mask);
911 if (IS_ERR(p->f_label))
914 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
915 if (p->o_arg.seqid == NULL)
917 nfs_sb_active(dentry->d_sb);
918 p->dentry = dget(dentry);
921 atomic_inc(&sp->so_count);
922 p->o_arg.open_flags = flags;
923 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
924 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
925 * will return permission denied for all bits until close */
926 if (!(flags & O_EXCL)) {
927 /* ask server to check for all possible rights as results
929 p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
930 NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
932 p->o_arg.clientid = server->nfs_client->cl_clientid;
933 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
934 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
935 p->o_arg.name = &dentry->d_name;
936 p->o_arg.server = server;
937 p->o_arg.bitmask = nfs4_bitmask(server, label);
938 p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
939 p->o_arg.label = label;
940 p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
941 switch (p->o_arg.claim) {
942 case NFS4_OPEN_CLAIM_NULL:
943 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
944 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
945 p->o_arg.fh = NFS_FH(dir);
947 case NFS4_OPEN_CLAIM_PREVIOUS:
948 case NFS4_OPEN_CLAIM_FH:
949 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
950 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
951 p->o_arg.fh = NFS_FH(dentry->d_inode);
953 if (attrs != NULL && attrs->ia_valid != 0) {
956 p->o_arg.u.attrs = &p->attrs;
957 memcpy(&p->attrs, attrs, sizeof(p->attrs));
960 verf[1] = current->pid;
961 memcpy(p->o_arg.u.verifier.data, verf,
962 sizeof(p->o_arg.u.verifier.data));
964 p->c_arg.fh = &p->o_res.fh;
965 p->c_arg.stateid = &p->o_res.stateid;
966 p->c_arg.seqid = p->o_arg.seqid;
967 nfs4_init_opendata_res(p);
972 nfs4_label_free(p->f_label);
980 static void nfs4_opendata_free(struct kref *kref)
982 struct nfs4_opendata *p = container_of(kref,
983 struct nfs4_opendata, kref);
984 struct super_block *sb = p->dentry->d_sb;
986 nfs_free_seqid(p->o_arg.seqid);
987 if (p->state != NULL)
988 nfs4_put_open_state(p->state);
989 nfs4_put_state_owner(p->owner);
991 nfs4_label_free(p->f_label);
996 nfs_fattr_free_names(&p->f_attr);
1000 static void nfs4_opendata_put(struct nfs4_opendata *p)
1003 kref_put(&p->kref, nfs4_opendata_free);
1006 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
1010 ret = rpc_wait_for_completion_task(task);
1014 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
1018 if (open_mode & (O_EXCL|O_TRUNC))
1020 switch (mode & (FMODE_READ|FMODE_WRITE)) {
1022 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
1023 && state->n_rdonly != 0;
1026 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
1027 && state->n_wronly != 0;
1029 case FMODE_READ|FMODE_WRITE:
1030 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
1031 && state->n_rdwr != 0;
1037 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
1039 if (delegation == NULL)
1041 if ((delegation->type & fmode) != fmode)
1043 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
1045 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
1047 nfs_mark_delegation_referenced(delegation);
1051 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
1060 case FMODE_READ|FMODE_WRITE:
1063 nfs4_state_set_mode_locked(state, state->state | fmode);
1066 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
1068 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1069 nfs4_stateid_copy(&state->stateid, stateid);
1070 nfs4_stateid_copy(&state->open_stateid, stateid);
1071 set_bit(NFS_OPEN_STATE, &state->flags);
1074 set_bit(NFS_O_RDONLY_STATE, &state->flags);
1077 set_bit(NFS_O_WRONLY_STATE, &state->flags);
1079 case FMODE_READ|FMODE_WRITE:
1080 set_bit(NFS_O_RDWR_STATE, &state->flags);
1084 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
1086 write_seqlock(&state->seqlock);
1087 nfs_set_open_stateid_locked(state, stateid, fmode);
1088 write_sequnlock(&state->seqlock);
1091 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
1094 * Protect the call to nfs4_state_set_mode_locked and
1095 * serialise the stateid update
1097 write_seqlock(&state->seqlock);
1098 if (deleg_stateid != NULL) {
1099 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1100 set_bit(NFS_DELEGATED_STATE, &state->flags);
1102 if (open_stateid != NULL)
1103 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1104 write_sequnlock(&state->seqlock);
1105 spin_lock(&state->owner->so_lock);
1106 update_open_stateflags(state, fmode);
1107 spin_unlock(&state->owner->so_lock);
1110 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
1112 struct nfs_inode *nfsi = NFS_I(state->inode);
1113 struct nfs_delegation *deleg_cur;
1116 fmode &= (FMODE_READ|FMODE_WRITE);
1119 deleg_cur = rcu_dereference(nfsi->delegation);
1120 if (deleg_cur == NULL)
1123 spin_lock(&deleg_cur->lock);
1124 if (rcu_dereference(nfsi->delegation) != deleg_cur ||
1125 test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) ||
1126 (deleg_cur->type & fmode) != fmode)
1127 goto no_delegation_unlock;
1129 if (delegation == NULL)
1130 delegation = &deleg_cur->stateid;
1131 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1132 goto no_delegation_unlock;
1134 nfs_mark_delegation_referenced(deleg_cur);
1135 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1137 no_delegation_unlock:
1138 spin_unlock(&deleg_cur->lock);
1142 if (!ret && open_stateid != NULL) {
1143 __update_open_stateid(state, open_stateid, NULL, fmode);
1151 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
1153 struct nfs_delegation *delegation;
1156 delegation = rcu_dereference(NFS_I(inode)->delegation);
1157 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1162 nfs4_inode_return_delegation(inode);
1165 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1167 struct nfs4_state *state = opendata->state;
1168 struct nfs_inode *nfsi = NFS_I(state->inode);
1169 struct nfs_delegation *delegation;
1170 int open_mode = opendata->o_arg.open_flags;
1171 fmode_t fmode = opendata->o_arg.fmode;
1172 nfs4_stateid stateid;
1176 if (can_open_cached(state, fmode, open_mode)) {
1177 spin_lock(&state->owner->so_lock);
1178 if (can_open_cached(state, fmode, open_mode)) {
1179 update_open_stateflags(state, fmode);
1180 spin_unlock(&state->owner->so_lock);
1181 goto out_return_state;
1183 spin_unlock(&state->owner->so_lock);
1186 delegation = rcu_dereference(nfsi->delegation);
1187 if (!can_open_delegated(delegation, fmode)) {
1191 /* Save the delegation */
1192 nfs4_stateid_copy(&stateid, &delegation->stateid);
1194 nfs_release_seqid(opendata->o_arg.seqid);
1195 if (!opendata->is_recover) {
1196 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1202 /* Try to update the stateid using the delegation */
1203 if (update_open_stateid(state, NULL, &stateid, fmode))
1204 goto out_return_state;
1207 return ERR_PTR(ret);
1209 atomic_inc(&state->count);
1214 nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
1216 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
1217 struct nfs_delegation *delegation;
1218 int delegation_flags = 0;
1221 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1223 delegation_flags = delegation->flags;
1225 if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) {
1226 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1227 "returning a delegation for "
1228 "OPEN(CLAIM_DELEGATE_CUR)\n",
1230 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1231 nfs_inode_set_delegation(state->inode,
1232 data->owner->so_cred,
1235 nfs_inode_reclaim_delegation(state->inode,
1236 data->owner->so_cred,
1241 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1242 * and update the nfs4_state.
1244 static struct nfs4_state *
1245 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)
1247 struct inode *inode = data->state->inode;
1248 struct nfs4_state *state = data->state;
1251 if (!data->rpc_done) {
1252 ret = data->rpc_status;
1257 if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) ||
1258 !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) ||
1259 !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE))
1263 state = nfs4_get_open_state(inode, data->owner);
1267 ret = nfs_refresh_inode(inode, &data->f_attr);
1271 nfs_setsecurity(inode, &data->f_attr, data->f_label);
1273 if (data->o_res.delegation_type != 0)
1274 nfs4_opendata_check_deleg(data, state);
1275 update_open_stateid(state, &data->o_res.stateid, NULL,
1280 return ERR_PTR(ret);
1284 static struct nfs4_state *
1285 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1287 struct inode *inode;
1288 struct nfs4_state *state = NULL;
1291 if (!data->rpc_done) {
1292 state = nfs4_try_open_cached(data);
1297 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1299 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr, data->f_label);
1300 ret = PTR_ERR(inode);
1304 state = nfs4_get_open_state(inode, data->owner);
1307 if (data->o_res.delegation_type != 0)
1308 nfs4_opendata_check_deleg(data, state);
1309 update_open_stateid(state, &data->o_res.stateid, NULL,
1313 nfs_release_seqid(data->o_arg.seqid);
1318 return ERR_PTR(ret);
1321 static struct nfs4_state *
1322 nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1324 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS)
1325 return _nfs4_opendata_reclaim_to_nfs4_state(data);
1326 return _nfs4_opendata_to_nfs4_state(data);
1329 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1331 struct nfs_inode *nfsi = NFS_I(state->inode);
1332 struct nfs_open_context *ctx;
1334 spin_lock(&state->inode->i_lock);
1335 list_for_each_entry(ctx, &nfsi->open_files, list) {
1336 if (ctx->state != state)
1338 get_nfs_open_context(ctx);
1339 spin_unlock(&state->inode->i_lock);
1342 spin_unlock(&state->inode->i_lock);
1343 return ERR_PTR(-ENOENT);
1346 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx,
1347 struct nfs4_state *state, enum open_claim_type4 claim)
1349 struct nfs4_opendata *opendata;
1351 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0,
1352 NULL, NULL, claim, GFP_NOFS);
1353 if (opendata == NULL)
1354 return ERR_PTR(-ENOMEM);
1355 opendata->state = state;
1356 atomic_inc(&state->count);
1360 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1362 struct nfs4_state *newstate;
1365 opendata->o_arg.open_flags = 0;
1366 opendata->o_arg.fmode = fmode;
1367 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1368 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1369 nfs4_init_opendata_res(opendata);
1370 ret = _nfs4_recover_proc_open(opendata);
1373 newstate = nfs4_opendata_to_nfs4_state(opendata);
1374 if (IS_ERR(newstate))
1375 return PTR_ERR(newstate);
1376 nfs4_close_state(newstate, fmode);
1381 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1383 struct nfs4_state *newstate;
1386 /* memory barrier prior to reading state->n_* */
1387 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1388 clear_bit(NFS_OPEN_STATE, &state->flags);
1390 if (state->n_rdwr != 0) {
1391 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1392 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1395 if (newstate != state)
1398 if (state->n_wronly != 0) {
1399 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1400 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1403 if (newstate != state)
1406 if (state->n_rdonly != 0) {
1407 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1408 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1411 if (newstate != state)
1415 * We may have performed cached opens for all three recoveries.
1416 * Check if we need to update the current stateid.
1418 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1419 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1420 write_seqlock(&state->seqlock);
1421 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1422 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1423 write_sequnlock(&state->seqlock);
1430 * reclaim state on the server after a reboot.
1432 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1434 struct nfs_delegation *delegation;
1435 struct nfs4_opendata *opendata;
1436 fmode_t delegation_type = 0;
1439 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1440 NFS4_OPEN_CLAIM_PREVIOUS);
1441 if (IS_ERR(opendata))
1442 return PTR_ERR(opendata);
1444 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1445 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1446 delegation_type = delegation->type;
1448 opendata->o_arg.u.delegation_type = delegation_type;
1449 status = nfs4_open_recover(opendata, state);
1450 nfs4_opendata_put(opendata);
1454 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1456 struct nfs_server *server = NFS_SERVER(state->inode);
1457 struct nfs4_exception exception = { };
1460 err = _nfs4_do_open_reclaim(ctx, state);
1461 trace_nfs4_open_reclaim(ctx, 0, err);
1462 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1464 if (err != -NFS4ERR_DELAY)
1466 nfs4_handle_exception(server, err, &exception);
1467 } while (exception.retry);
1471 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1473 struct nfs_open_context *ctx;
1476 ctx = nfs4_state_find_open_context(state);
1479 ret = nfs4_do_open_reclaim(ctx, state);
1480 put_nfs_open_context(ctx);
1484 static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct nfs4_state *state, const nfs4_stateid *stateid, int err)
1488 printk(KERN_ERR "NFS: %s: unhandled error "
1489 "%d.\n", __func__, err);
1494 case -NFS4ERR_BADSESSION:
1495 case -NFS4ERR_BADSLOT:
1496 case -NFS4ERR_BAD_HIGH_SLOT:
1497 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1498 case -NFS4ERR_DEADSESSION:
1499 set_bit(NFS_DELEGATED_STATE, &state->flags);
1500 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
1502 case -NFS4ERR_STALE_CLIENTID:
1503 case -NFS4ERR_STALE_STATEID:
1504 set_bit(NFS_DELEGATED_STATE, &state->flags);
1505 case -NFS4ERR_EXPIRED:
1506 /* Don't recall a delegation if it was lost */
1507 nfs4_schedule_lease_recovery(server->nfs_client);
1509 case -NFS4ERR_DELEG_REVOKED:
1510 case -NFS4ERR_ADMIN_REVOKED:
1511 case -NFS4ERR_BAD_STATEID:
1512 case -NFS4ERR_OPENMODE:
1513 nfs_inode_find_state_and_recover(state->inode,
1515 nfs4_schedule_stateid_recovery(server, state);
1517 case -NFS4ERR_DELAY:
1518 case -NFS4ERR_GRACE:
1519 set_bit(NFS_DELEGATED_STATE, &state->flags);
1523 case -NFS4ERR_DENIED:
1524 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
1530 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1532 struct nfs_server *server = NFS_SERVER(state->inode);
1533 struct nfs4_opendata *opendata;
1536 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1537 NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1538 if (IS_ERR(opendata))
1539 return PTR_ERR(opendata);
1540 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1541 err = nfs4_open_recover(opendata, state);
1542 nfs4_opendata_put(opendata);
1543 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
1546 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1548 struct nfs4_opendata *data = calldata;
1550 data->rpc_status = task->tk_status;
1551 if (data->rpc_status == 0) {
1552 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1553 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1554 renew_lease(data->o_res.server, data->timestamp);
1559 static void nfs4_open_confirm_release(void *calldata)
1561 struct nfs4_opendata *data = calldata;
1562 struct nfs4_state *state = NULL;
1564 /* If this request hasn't been cancelled, do nothing */
1565 if (data->cancelled == 0)
1567 /* In case of error, no cleanup! */
1568 if (!data->rpc_done)
1570 state = nfs4_opendata_to_nfs4_state(data);
1572 nfs4_close_state(state, data->o_arg.fmode);
1574 nfs4_opendata_put(data);
1577 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1578 .rpc_call_done = nfs4_open_confirm_done,
1579 .rpc_release = nfs4_open_confirm_release,
1583 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1585 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1587 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1588 struct rpc_task *task;
1589 struct rpc_message msg = {
1590 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1591 .rpc_argp = &data->c_arg,
1592 .rpc_resp = &data->c_res,
1593 .rpc_cred = data->owner->so_cred,
1595 struct rpc_task_setup task_setup_data = {
1596 .rpc_client = server->client,
1597 .rpc_message = &msg,
1598 .callback_ops = &nfs4_open_confirm_ops,
1599 .callback_data = data,
1600 .workqueue = nfsiod_workqueue,
1601 .flags = RPC_TASK_ASYNC,
1605 kref_get(&data->kref);
1607 data->rpc_status = 0;
1608 data->timestamp = jiffies;
1609 task = rpc_run_task(&task_setup_data);
1611 return PTR_ERR(task);
1612 status = nfs4_wait_for_completion_rpc_task(task);
1614 data->cancelled = 1;
1617 status = data->rpc_status;
1622 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1624 struct nfs4_opendata *data = calldata;
1625 struct nfs4_state_owner *sp = data->owner;
1626 struct nfs_client *clp = sp->so_server->nfs_client;
1628 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1631 * Check if we still need to send an OPEN call, or if we can use
1632 * a delegation instead.
1634 if (data->state != NULL) {
1635 struct nfs_delegation *delegation;
1637 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1640 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1641 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1642 data->o_arg.claim != NFS4_OPEN_CLAIM_DELEG_CUR_FH &&
1643 can_open_delegated(delegation, data->o_arg.fmode))
1644 goto unlock_no_action;
1647 /* Update client id. */
1648 data->o_arg.clientid = clp->cl_clientid;
1649 switch (data->o_arg.claim) {
1650 case NFS4_OPEN_CLAIM_PREVIOUS:
1651 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1652 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
1653 data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1654 case NFS4_OPEN_CLAIM_FH:
1655 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1656 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1658 data->timestamp = jiffies;
1659 if (nfs4_setup_sequence(data->o_arg.server,
1660 &data->o_arg.seq_args,
1661 &data->o_res.seq_res,
1663 nfs_release_seqid(data->o_arg.seqid);
1665 /* Set the create mode (note dependency on the session type) */
1666 data->o_arg.createmode = NFS4_CREATE_UNCHECKED;
1667 if (data->o_arg.open_flags & O_EXCL) {
1668 data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE;
1669 if (nfs4_has_persistent_session(clp))
1670 data->o_arg.createmode = NFS4_CREATE_GUARDED;
1671 else if (clp->cl_mvops->minor_version > 0)
1672 data->o_arg.createmode = NFS4_CREATE_EXCLUSIVE4_1;
1678 task->tk_action = NULL;
1680 nfs4_sequence_done(task, &data->o_res.seq_res);
1683 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1685 struct nfs4_opendata *data = calldata;
1687 data->rpc_status = task->tk_status;
1689 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1692 if (task->tk_status == 0) {
1693 if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) {
1694 switch (data->o_res.f_attr->mode & S_IFMT) {
1698 data->rpc_status = -ELOOP;
1701 data->rpc_status = -EISDIR;
1704 data->rpc_status = -ENOTDIR;
1707 renew_lease(data->o_res.server, data->timestamp);
1708 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1709 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1714 static void nfs4_open_release(void *calldata)
1716 struct nfs4_opendata *data = calldata;
1717 struct nfs4_state *state = NULL;
1719 /* If this request hasn't been cancelled, do nothing */
1720 if (data->cancelled == 0)
1722 /* In case of error, no cleanup! */
1723 if (data->rpc_status != 0 || !data->rpc_done)
1725 /* In case we need an open_confirm, no cleanup! */
1726 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1728 state = nfs4_opendata_to_nfs4_state(data);
1730 nfs4_close_state(state, data->o_arg.fmode);
1732 nfs4_opendata_put(data);
1735 static const struct rpc_call_ops nfs4_open_ops = {
1736 .rpc_call_prepare = nfs4_open_prepare,
1737 .rpc_call_done = nfs4_open_done,
1738 .rpc_release = nfs4_open_release,
1741 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1743 struct inode *dir = data->dir->d_inode;
1744 struct nfs_server *server = NFS_SERVER(dir);
1745 struct nfs_openargs *o_arg = &data->o_arg;
1746 struct nfs_openres *o_res = &data->o_res;
1747 struct rpc_task *task;
1748 struct rpc_message msg = {
1749 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1752 .rpc_cred = data->owner->so_cred,
1754 struct rpc_task_setup task_setup_data = {
1755 .rpc_client = server->client,
1756 .rpc_message = &msg,
1757 .callback_ops = &nfs4_open_ops,
1758 .callback_data = data,
1759 .workqueue = nfsiod_workqueue,
1760 .flags = RPC_TASK_ASYNC,
1764 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1765 kref_get(&data->kref);
1767 data->rpc_status = 0;
1768 data->cancelled = 0;
1769 data->is_recover = 0;
1771 nfs4_set_sequence_privileged(&o_arg->seq_args);
1772 data->is_recover = 1;
1774 task = rpc_run_task(&task_setup_data);
1776 return PTR_ERR(task);
1777 status = nfs4_wait_for_completion_rpc_task(task);
1779 data->cancelled = 1;
1782 status = data->rpc_status;
1788 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1790 struct inode *dir = data->dir->d_inode;
1791 struct nfs_openres *o_res = &data->o_res;
1794 status = nfs4_run_open_task(data, 1);
1795 if (status != 0 || !data->rpc_done)
1798 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1800 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1801 status = _nfs4_proc_open_confirm(data);
1809 static int nfs4_opendata_access(struct rpc_cred *cred,
1810 struct nfs4_opendata *opendata,
1811 struct nfs4_state *state, fmode_t fmode,
1814 struct nfs_access_entry cache;
1817 /* access call failed or for some reason the server doesn't
1818 * support any access modes -- defer access call until later */
1819 if (opendata->o_res.access_supported == 0)
1823 /* don't check MAY_WRITE - a newly created file may not have
1824 * write mode bits, but POSIX allows the creating process to write.
1825 * use openflags to check for exec, because fmode won't
1826 * always have FMODE_EXEC set when file open for exec. */
1827 if (openflags & __FMODE_EXEC) {
1828 /* ONLY check for exec rights */
1830 } else if (fmode & FMODE_READ)
1834 cache.jiffies = jiffies;
1835 nfs_access_set_mask(&cache, opendata->o_res.access_result);
1836 nfs_access_add_cache(state->inode, &cache);
1838 if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0)
1841 /* even though OPEN succeeded, access is denied. Close the file */
1842 nfs4_close_state(state, fmode);
1847 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1849 static int _nfs4_proc_open(struct nfs4_opendata *data)
1851 struct inode *dir = data->dir->d_inode;
1852 struct nfs_server *server = NFS_SERVER(dir);
1853 struct nfs_openargs *o_arg = &data->o_arg;
1854 struct nfs_openres *o_res = &data->o_res;
1857 status = nfs4_run_open_task(data, 0);
1858 if (!data->rpc_done)
1861 if (status == -NFS4ERR_BADNAME &&
1862 !(o_arg->open_flags & O_CREAT))
1867 nfs_fattr_map_and_free_names(server, &data->f_attr);
1869 if (o_arg->open_flags & O_CREAT)
1870 update_changeattr(dir, &o_res->cinfo);
1871 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1872 server->caps &= ~NFS_CAP_POSIX_LOCK;
1873 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1874 status = _nfs4_proc_open_confirm(data);
1878 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1879 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr, o_res->f_label);
1883 static int nfs4_recover_expired_lease(struct nfs_server *server)
1885 return nfs4_client_recover_expired_lease(server->nfs_client);
1890 * reclaim state on the server after a network partition.
1891 * Assumes caller holds the appropriate lock
1893 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1895 struct nfs4_opendata *opendata;
1898 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1899 NFS4_OPEN_CLAIM_FH);
1900 if (IS_ERR(opendata))
1901 return PTR_ERR(opendata);
1902 ret = nfs4_open_recover(opendata, state);
1904 d_drop(ctx->dentry);
1905 nfs4_opendata_put(opendata);
1909 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1911 struct nfs_server *server = NFS_SERVER(state->inode);
1912 struct nfs4_exception exception = { };
1916 err = _nfs4_open_expired(ctx, state);
1917 trace_nfs4_open_expired(ctx, 0, err);
1918 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1923 case -NFS4ERR_GRACE:
1924 case -NFS4ERR_DELAY:
1925 nfs4_handle_exception(server, err, &exception);
1928 } while (exception.retry);
1933 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1935 struct nfs_open_context *ctx;
1938 ctx = nfs4_state_find_open_context(state);
1941 ret = nfs4_do_open_expired(ctx, state);
1942 put_nfs_open_context(ctx);
1946 #if defined(CONFIG_NFS_V4_1)
1947 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
1949 struct nfs_server *server = NFS_SERVER(state->inode);
1950 nfs4_stateid *stateid = &state->stateid;
1951 struct nfs_delegation *delegation;
1952 struct rpc_cred *cred = NULL;
1953 int status = -NFS4ERR_BAD_STATEID;
1955 /* If a state reset has been done, test_stateid is unneeded */
1956 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1959 /* Get the delegation credential for use by test/free_stateid */
1961 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1962 if (delegation != NULL &&
1963 nfs4_stateid_match(&delegation->stateid, stateid)) {
1964 cred = get_rpccred(delegation->cred);
1966 status = nfs41_test_stateid(server, stateid, cred);
1967 trace_nfs4_test_delegation_stateid(state, NULL, status);
1971 if (status != NFS_OK) {
1972 /* Free the stateid unless the server explicitly
1973 * informs us the stateid is unrecognized. */
1974 if (status != -NFS4ERR_BAD_STATEID)
1975 nfs41_free_stateid(server, stateid, cred);
1976 nfs_remove_bad_delegation(state->inode);
1978 write_seqlock(&state->seqlock);
1979 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1980 write_sequnlock(&state->seqlock);
1981 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1989 * nfs41_check_open_stateid - possibly free an open stateid
1991 * @state: NFSv4 state for an inode
1993 * Returns NFS_OK if recovery for this stateid is now finished.
1994 * Otherwise a negative NFS4ERR value is returned.
1996 static int nfs41_check_open_stateid(struct nfs4_state *state)
1998 struct nfs_server *server = NFS_SERVER(state->inode);
1999 nfs4_stateid *stateid = &state->open_stateid;
2000 struct rpc_cred *cred = state->owner->so_cred;
2003 /* If a state reset has been done, test_stateid is unneeded */
2004 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
2005 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
2006 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
2007 return -NFS4ERR_BAD_STATEID;
2009 status = nfs41_test_stateid(server, stateid, cred);
2010 trace_nfs4_test_open_stateid(state, NULL, status);
2011 if (status != NFS_OK) {
2012 /* Free the stateid unless the server explicitly
2013 * informs us the stateid is unrecognized. */
2014 if (status != -NFS4ERR_BAD_STATEID)
2015 nfs41_free_stateid(server, stateid, cred);
2017 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2018 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2019 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2020 clear_bit(NFS_OPEN_STATE, &state->flags);
2025 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
2029 nfs41_clear_delegation_stateid(state);
2030 status = nfs41_check_open_stateid(state);
2031 if (status != NFS_OK)
2032 status = nfs4_open_expired(sp, state);
2038 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
2039 * fields corresponding to attributes that were used to store the verifier.
2040 * Make sure we clobber those fields in the later setattr call
2042 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
2044 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
2045 !(sattr->ia_valid & ATTR_ATIME_SET))
2046 sattr->ia_valid |= ATTR_ATIME;
2048 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
2049 !(sattr->ia_valid & ATTR_MTIME_SET))
2050 sattr->ia_valid |= ATTR_MTIME;
2053 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2056 struct nfs_open_context *ctx)
2058 struct nfs4_state_owner *sp = opendata->owner;
2059 struct nfs_server *server = sp->so_server;
2060 struct dentry *dentry;
2061 struct nfs4_state *state;
2065 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
2067 ret = _nfs4_proc_open(opendata);
2071 state = nfs4_opendata_to_nfs4_state(opendata);
2072 ret = PTR_ERR(state);
2075 if (server->caps & NFS_CAP_POSIX_LOCK)
2076 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
2078 dentry = opendata->dentry;
2079 if (dentry->d_inode == NULL) {
2080 /* FIXME: Is this d_drop() ever needed? */
2082 dentry = d_add_unique(dentry, igrab(state->inode));
2083 if (dentry == NULL) {
2084 dentry = opendata->dentry;
2085 } else if (dentry != ctx->dentry) {
2087 ctx->dentry = dget(dentry);
2089 nfs_set_verifier(dentry,
2090 nfs_save_change_attribute(opendata->dir->d_inode));
2093 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
2098 if (dentry->d_inode == state->inode) {
2099 nfs_inode_attach_open_context(ctx);
2100 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
2101 nfs4_schedule_stateid_recovery(server, state);
2108 * Returns a referenced nfs4_state
2110 static int _nfs4_do_open(struct inode *dir,
2111 struct nfs_open_context *ctx,
2113 struct iattr *sattr,
2114 struct nfs4_label *label)
2116 struct nfs4_state_owner *sp;
2117 struct nfs4_state *state = NULL;
2118 struct nfs_server *server = NFS_SERVER(dir);
2119 struct nfs4_opendata *opendata;
2120 struct dentry *dentry = ctx->dentry;
2121 struct rpc_cred *cred = ctx->cred;
2122 struct nfs4_threshold **ctx_th = &ctx->mdsthreshold;
2123 fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC);
2124 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
2125 struct nfs4_label *olabel = NULL;
2128 /* Protect against reboot recovery conflicts */
2130 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
2132 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
2135 status = nfs4_recover_expired_lease(server);
2137 goto err_put_state_owner;
2138 if (dentry->d_inode != NULL)
2139 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
2141 if (dentry->d_inode)
2142 claim = NFS4_OPEN_CLAIM_FH;
2143 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
2144 label, claim, GFP_KERNEL);
2145 if (opendata == NULL)
2146 goto err_put_state_owner;
2149 olabel = nfs4_label_alloc(server, GFP_KERNEL);
2150 if (IS_ERR(olabel)) {
2151 status = PTR_ERR(olabel);
2152 goto err_opendata_put;
2156 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
2157 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
2158 if (!opendata->f_attr.mdsthreshold)
2159 goto err_free_label;
2160 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
2162 if (dentry->d_inode != NULL)
2163 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
2165 status = _nfs4_open_and_get_state(opendata, fmode, flags, ctx);
2167 goto err_free_label;
2170 if ((opendata->o_arg.open_flags & O_EXCL) &&
2171 (opendata->o_arg.createmode != NFS4_CREATE_GUARDED)) {
2172 nfs4_exclusive_attrset(opendata, sattr);
2174 nfs_fattr_init(opendata->o_res.f_attr);
2175 status = nfs4_do_setattr(state->inode, cred,
2176 opendata->o_res.f_attr, sattr,
2177 state, label, olabel);
2179 nfs_setattr_update_inode(state->inode, sattr);
2180 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
2181 nfs_setsecurity(state->inode, opendata->o_res.f_attr, olabel);
2185 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
2186 *ctx_th = opendata->f_attr.mdsthreshold;
2188 kfree(opendata->f_attr.mdsthreshold);
2189 opendata->f_attr.mdsthreshold = NULL;
2191 nfs4_label_free(olabel);
2193 nfs4_opendata_put(opendata);
2194 nfs4_put_state_owner(sp);
2197 nfs4_label_free(olabel);
2199 kfree(opendata->f_attr.mdsthreshold);
2200 nfs4_opendata_put(opendata);
2201 err_put_state_owner:
2202 nfs4_put_state_owner(sp);
2208 static struct nfs4_state *nfs4_do_open(struct inode *dir,
2209 struct nfs_open_context *ctx,
2211 struct iattr *sattr,
2212 struct nfs4_label *label)
2214 struct nfs_server *server = NFS_SERVER(dir);
2215 struct nfs4_exception exception = { };
2216 struct nfs4_state *res;
2220 status = _nfs4_do_open(dir, ctx, flags, sattr, label);
2222 trace_nfs4_open_file(ctx, flags, status);
2225 /* NOTE: BAD_SEQID means the server and client disagree about the
2226 * book-keeping w.r.t. state-changing operations
2227 * (OPEN/CLOSE/LOCK/LOCKU...)
2228 * It is actually a sign of a bug on the client or on the server.
2230 * If we receive a BAD_SEQID error in the particular case of
2231 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2232 * have unhashed the old state_owner for us, and that we can
2233 * therefore safely retry using a new one. We should still warn
2234 * the user though...
2236 if (status == -NFS4ERR_BAD_SEQID) {
2237 pr_warn_ratelimited("NFS: v4 server %s "
2238 " returned a bad sequence-id error!\n",
2239 NFS_SERVER(dir)->nfs_client->cl_hostname);
2240 exception.retry = 1;
2244 * BAD_STATEID on OPEN means that the server cancelled our
2245 * state before it received the OPEN_CONFIRM.
2246 * Recover by retrying the request as per the discussion
2247 * on Page 181 of RFC3530.
2249 if (status == -NFS4ERR_BAD_STATEID) {
2250 exception.retry = 1;
2253 if (status == -EAGAIN) {
2254 /* We must have found a delegation */
2255 exception.retry = 1;
2258 if (nfs4_clear_cap_atomic_open_v1(server, status, &exception))
2260 res = ERR_PTR(nfs4_handle_exception(server,
2261 status, &exception));
2262 } while (exception.retry);
2266 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2267 struct nfs_fattr *fattr, struct iattr *sattr,
2268 struct nfs4_state *state, struct nfs4_label *ilabel,
2269 struct nfs4_label *olabel)
2271 struct nfs_server *server = NFS_SERVER(inode);
2272 struct nfs_setattrargs arg = {
2273 .fh = NFS_FH(inode),
2276 .bitmask = server->attr_bitmask,
2279 struct nfs_setattrres res = {
2284 struct rpc_message msg = {
2285 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2290 unsigned long timestamp = jiffies;
2295 arg.bitmask = nfs4_bitmask(server, ilabel);
2297 arg.bitmask = nfs4_bitmask(server, olabel);
2299 nfs_fattr_init(fattr);
2301 /* Servers should only apply open mode checks for file size changes */
2302 truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false;
2303 fmode = truncate ? FMODE_WRITE : FMODE_READ;
2305 if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
2306 /* Use that stateid */
2307 } else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) {
2308 struct nfs_lockowner lockowner = {
2309 .l_owner = current->files,
2310 .l_pid = current->tgid,
2312 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2315 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2317 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2318 if (status == 0 && state != NULL)
2319 renew_lease(server, timestamp);
2323 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2324 struct nfs_fattr *fattr, struct iattr *sattr,
2325 struct nfs4_state *state, struct nfs4_label *ilabel,
2326 struct nfs4_label *olabel)
2328 struct nfs_server *server = NFS_SERVER(inode);
2329 struct nfs4_exception exception = {
2335 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state, ilabel, olabel);
2336 trace_nfs4_setattr(inode, err);
2338 case -NFS4ERR_OPENMODE:
2339 if (!(sattr->ia_valid & ATTR_SIZE)) {
2340 pr_warn_once("NFSv4: server %s is incorrectly "
2341 "applying open mode checks to "
2342 "a SETATTR that is not "
2343 "changing file size.\n",
2344 server->nfs_client->cl_hostname);
2346 if (state && !(state->state & FMODE_WRITE)) {
2348 if (sattr->ia_valid & ATTR_OPEN)
2353 err = nfs4_handle_exception(server, err, &exception);
2354 } while (exception.retry);
2359 struct nfs4_closedata {
2360 struct inode *inode;
2361 struct nfs4_state *state;
2362 struct nfs_closeargs arg;
2363 struct nfs_closeres res;
2364 struct nfs_fattr fattr;
2365 unsigned long timestamp;
2370 static void nfs4_free_closedata(void *data)
2372 struct nfs4_closedata *calldata = data;
2373 struct nfs4_state_owner *sp = calldata->state->owner;
2374 struct super_block *sb = calldata->state->inode->i_sb;
2377 pnfs_roc_release(calldata->state->inode);
2378 nfs4_put_open_state(calldata->state);
2379 nfs_free_seqid(calldata->arg.seqid);
2380 nfs4_put_state_owner(sp);
2381 nfs_sb_deactive(sb);
2385 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2388 spin_lock(&state->owner->so_lock);
2389 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2390 switch (fmode & (FMODE_READ|FMODE_WRITE)) {
2392 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2395 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2398 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2399 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2400 clear_bit(NFS_OPEN_STATE, &state->flags);
2402 spin_unlock(&state->owner->so_lock);
2405 static void nfs4_close_done(struct rpc_task *task, void *data)
2407 struct nfs4_closedata *calldata = data;
2408 struct nfs4_state *state = calldata->state;
2409 struct nfs_server *server = NFS_SERVER(calldata->inode);
2411 dprintk("%s: begin!\n", __func__);
2412 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2414 trace_nfs4_close(state, &calldata->arg, &calldata->res, task->tk_status);
2415 /* hmm. we are done with the inode, and in the process of freeing
2416 * the state_owner. we keep this around to process errors
2418 switch (task->tk_status) {
2421 pnfs_roc_set_barrier(state->inode,
2422 calldata->roc_barrier);
2423 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2424 renew_lease(server, calldata->timestamp);
2425 nfs4_close_clear_stateid_flags(state,
2426 calldata->arg.fmode);
2428 case -NFS4ERR_STALE_STATEID:
2429 case -NFS4ERR_OLD_STATEID:
2430 case -NFS4ERR_BAD_STATEID:
2431 case -NFS4ERR_EXPIRED:
2432 if (calldata->arg.fmode == 0)
2435 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2436 rpc_restart_call_prepare(task);
2438 nfs_release_seqid(calldata->arg.seqid);
2439 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2440 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2443 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2445 struct nfs4_closedata *calldata = data;
2446 struct nfs4_state *state = calldata->state;
2447 struct inode *inode = calldata->inode;
2450 dprintk("%s: begin!\n", __func__);
2451 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2454 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2455 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2456 spin_lock(&state->owner->so_lock);
2457 /* Calculate the change in open mode */
2458 if (state->n_rdwr == 0) {
2459 if (state->n_rdonly == 0) {
2460 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2461 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2462 calldata->arg.fmode &= ~FMODE_READ;
2464 if (state->n_wronly == 0) {
2465 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2466 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2467 calldata->arg.fmode &= ~FMODE_WRITE;
2470 if (!nfs4_valid_open_stateid(state))
2472 spin_unlock(&state->owner->so_lock);
2475 /* Note: exit _without_ calling nfs4_close_done */
2479 if (calldata->arg.fmode == 0) {
2480 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2481 if (calldata->roc &&
2482 pnfs_roc_drain(inode, &calldata->roc_barrier, task)) {
2483 nfs_release_seqid(calldata->arg.seqid);
2488 nfs_fattr_init(calldata->res.fattr);
2489 calldata->timestamp = jiffies;
2490 if (nfs4_setup_sequence(NFS_SERVER(inode),
2491 &calldata->arg.seq_args,
2492 &calldata->res.seq_res,
2494 nfs_release_seqid(calldata->arg.seqid);
2495 dprintk("%s: done!\n", __func__);
2498 task->tk_action = NULL;
2500 nfs4_sequence_done(task, &calldata->res.seq_res);
2503 static const struct rpc_call_ops nfs4_close_ops = {
2504 .rpc_call_prepare = nfs4_close_prepare,
2505 .rpc_call_done = nfs4_close_done,
2506 .rpc_release = nfs4_free_closedata,
2510 * It is possible for data to be read/written from a mem-mapped file
2511 * after the sys_close call (which hits the vfs layer as a flush).
2512 * This means that we can't safely call nfsv4 close on a file until
2513 * the inode is cleared. This in turn means that we are not good
2514 * NFSv4 citizens - we do not indicate to the server to update the file's
2515 * share state even when we are done with one of the three share
2516 * stateid's in the inode.
2518 * NOTE: Caller must be holding the sp->so_owner semaphore!
2520 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
2522 struct nfs_server *server = NFS_SERVER(state->inode);
2523 struct nfs4_closedata *calldata;
2524 struct nfs4_state_owner *sp = state->owner;
2525 struct rpc_task *task;
2526 struct rpc_message msg = {
2527 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2528 .rpc_cred = state->owner->so_cred,
2530 struct rpc_task_setup task_setup_data = {
2531 .rpc_client = server->client,
2532 .rpc_message = &msg,
2533 .callback_ops = &nfs4_close_ops,
2534 .workqueue = nfsiod_workqueue,
2535 .flags = RPC_TASK_ASYNC,
2537 int status = -ENOMEM;
2539 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2540 if (calldata == NULL)
2542 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2543 calldata->inode = state->inode;
2544 calldata->state = state;
2545 calldata->arg.fh = NFS_FH(state->inode);
2546 calldata->arg.stateid = &state->open_stateid;
2547 /* Serialization for the sequence id */
2548 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2549 if (calldata->arg.seqid == NULL)
2550 goto out_free_calldata;
2551 calldata->arg.fmode = 0;
2552 calldata->arg.bitmask = server->cache_consistency_bitmask;
2553 calldata->res.fattr = &calldata->fattr;
2554 calldata->res.seqid = calldata->arg.seqid;
2555 calldata->res.server = server;
2556 calldata->roc = pnfs_roc(state->inode);
2557 nfs_sb_active(calldata->inode->i_sb);
2559 msg.rpc_argp = &calldata->arg;
2560 msg.rpc_resp = &calldata->res;
2561 task_setup_data.callback_data = calldata;
2562 task = rpc_run_task(&task_setup_data);
2564 return PTR_ERR(task);
2567 status = rpc_wait_for_completion_task(task);
2573 nfs4_put_open_state(state);
2574 nfs4_put_state_owner(sp);
2578 static struct inode *
2579 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2581 struct nfs4_state *state;
2582 struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL;
2584 label = nfs4_label_init_security(dir, ctx->dentry, attr, &l);
2586 /* Protect against concurrent sillydeletes */
2587 state = nfs4_do_open(dir, ctx, open_flags, attr, label);
2589 nfs4_label_release_security(label);
2592 return ERR_CAST(state);
2593 return state->inode;
2596 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2598 if (ctx->state == NULL)
2601 nfs4_close_sync(ctx->state, ctx->mode);
2603 nfs4_close_state(ctx->state, ctx->mode);
2606 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2608 struct nfs4_server_caps_arg args = {
2611 struct nfs4_server_caps_res res = {};
2612 struct rpc_message msg = {
2613 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2619 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2621 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2622 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2623 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2624 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2625 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2626 NFS_CAP_CTIME|NFS_CAP_MTIME);
2627 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2628 server->caps |= NFS_CAP_ACLS;
2629 if (res.has_links != 0)
2630 server->caps |= NFS_CAP_HARDLINKS;
2631 if (res.has_symlinks != 0)
2632 server->caps |= NFS_CAP_SYMLINKS;
2633 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2634 server->caps |= NFS_CAP_FILEID;
2635 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2636 server->caps |= NFS_CAP_MODE;
2637 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2638 server->caps |= NFS_CAP_NLINK;
2639 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2640 server->caps |= NFS_CAP_OWNER;
2641 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2642 server->caps |= NFS_CAP_OWNER_GROUP;
2643 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2644 server->caps |= NFS_CAP_ATIME;
2645 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2646 server->caps |= NFS_CAP_CTIME;
2647 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2648 server->caps |= NFS_CAP_MTIME;
2649 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
2650 if (res.attr_bitmask[2] & FATTR4_WORD2_SECURITY_LABEL)
2651 server->caps |= NFS_CAP_SECURITY_LABEL;
2653 memcpy(server->attr_bitmask_nl, res.attr_bitmask,
2654 sizeof(server->attr_bitmask));
2656 if (server->caps & NFS_CAP_SECURITY_LABEL) {
2657 server->attr_bitmask_nl[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
2658 res.attr_bitmask[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
2660 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2661 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2662 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2663 server->acl_bitmask = res.acl_bitmask;
2664 server->fh_expire_type = res.fh_expire_type;
2670 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2672 struct nfs4_exception exception = { };
2675 err = nfs4_handle_exception(server,
2676 _nfs4_server_capabilities(server, fhandle),
2678 } while (exception.retry);
2682 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2683 struct nfs_fsinfo *info)
2686 struct nfs4_lookup_root_arg args = {
2689 struct nfs4_lookup_res res = {
2691 .fattr = info->fattr,
2694 struct rpc_message msg = {
2695 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2700 bitmask[0] = nfs4_fattr_bitmap[0];
2701 bitmask[1] = nfs4_fattr_bitmap[1];
2703 * Process the label in the upcoming getfattr
2705 bitmask[2] = nfs4_fattr_bitmap[2] & ~FATTR4_WORD2_SECURITY_LABEL;
2707 nfs_fattr_init(info->fattr);
2708 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2711 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2712 struct nfs_fsinfo *info)
2714 struct nfs4_exception exception = { };
2717 err = _nfs4_lookup_root(server, fhandle, info);
2718 trace_nfs4_lookup_root(server, fhandle, info->fattr, err);
2721 case -NFS4ERR_WRONGSEC:
2724 err = nfs4_handle_exception(server, err, &exception);
2726 } while (exception.retry);
2731 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2732 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2734 struct rpc_auth_create_args auth_args = {
2735 .pseudoflavor = flavor,
2737 struct rpc_auth *auth;
2740 auth = rpcauth_create(&auth_args, server->client);
2745 ret = nfs4_lookup_root(server, fhandle, info);
2751 * Retry pseudoroot lookup with various security flavors. We do this when:
2753 * NFSv4.0: the PUTROOTFH operation returns NFS4ERR_WRONGSEC
2754 * NFSv4.1: the server does not support the SECINFO_NO_NAME operation
2756 * Returns zero on success, or a negative NFS4ERR value, or a
2757 * negative errno value.
2759 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2760 struct nfs_fsinfo *info)
2762 /* Per 3530bis 15.33.5 */
2763 static const rpc_authflavor_t flav_array[] = {
2767 RPC_AUTH_UNIX, /* courtesy */
2770 int status = -EPERM;
2773 for (i = 0; i < ARRAY_SIZE(flav_array); i++) {
2774 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2775 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2781 * -EACCESS could mean that the user doesn't have correct permissions
2782 * to access the mount. It could also mean that we tried to mount
2783 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2784 * existing mount programs don't handle -EACCES very well so it should
2785 * be mapped to -EPERM instead.
2787 if (status == -EACCES)
2792 static int nfs4_do_find_root_sec(struct nfs_server *server,
2793 struct nfs_fh *fhandle, struct nfs_fsinfo *info)
2795 int mv = server->nfs_client->cl_minorversion;
2796 return nfs_v4_minor_ops[mv]->find_root_sec(server, fhandle, info);
2800 * nfs4_proc_get_rootfh - get file handle for server's pseudoroot
2801 * @server: initialized nfs_server handle
2802 * @fhandle: we fill in the pseudo-fs root file handle
2803 * @info: we fill in an FSINFO struct
2805 * Returns zero on success, or a negative errno.
2807 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2808 struct nfs_fsinfo *info)
2812 status = nfs4_lookup_root(server, fhandle, info);
2813 if ((status == -NFS4ERR_WRONGSEC) &&
2814 !(server->flags & NFS_MOUNT_SECFLAVOUR))
2815 status = nfs4_do_find_root_sec(server, fhandle, info);
2818 status = nfs4_server_capabilities(server, fhandle);
2820 status = nfs4_do_fsinfo(server, fhandle, info);
2822 return nfs4_map_errors(status);
2825 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2826 struct nfs_fsinfo *info)
2829 struct nfs_fattr *fattr = info->fattr;
2830 struct nfs4_label *label = NULL;
2832 error = nfs4_server_capabilities(server, mntfh);
2834 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2838 label = nfs4_label_alloc(server, GFP_KERNEL);
2840 return PTR_ERR(label);
2842 error = nfs4_proc_getattr(server, mntfh, fattr, label);
2844 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2845 goto err_free_label;
2848 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2849 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2850 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2853 nfs4_label_free(label);
2859 * Get locations and (maybe) other attributes of a referral.
2860 * Note that we'll actually follow the referral later when
2861 * we detect fsid mismatch in inode revalidation
2863 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2864 const struct qstr *name, struct nfs_fattr *fattr,
2865 struct nfs_fh *fhandle)
2867 int status = -ENOMEM;
2868 struct page *page = NULL;
2869 struct nfs4_fs_locations *locations = NULL;
2871 page = alloc_page(GFP_KERNEL);
2874 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2875 if (locations == NULL)
2878 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2881 /* Make sure server returned a different fsid for the referral */
2882 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2883 dprintk("%s: server did not return a different fsid for"
2884 " a referral at %s\n", __func__, name->name);
2888 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2889 nfs_fixup_referral_attributes(&locations->fattr);
2891 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2892 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2893 memset(fhandle, 0, sizeof(struct nfs_fh));
2901 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
2902 struct nfs_fattr *fattr, struct nfs4_label *label)
2904 struct nfs4_getattr_arg args = {
2906 .bitmask = server->attr_bitmask,
2908 struct nfs4_getattr_res res = {
2913 struct rpc_message msg = {
2914 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2919 args.bitmask = nfs4_bitmask(server, label);
2921 nfs_fattr_init(fattr);
2922 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2925 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
2926 struct nfs_fattr *fattr, struct nfs4_label *label)
2928 struct nfs4_exception exception = { };
2931 err = _nfs4_proc_getattr(server, fhandle, fattr, label);
2932 trace_nfs4_getattr(server, fhandle, fattr, err);
2933 err = nfs4_handle_exception(server, err,
2935 } while (exception.retry);
2940 * The file is not closed if it is opened due to the a request to change
2941 * the size of the file. The open call will not be needed once the
2942 * VFS layer lookup-intents are implemented.
2944 * Close is called when the inode is destroyed.
2945 * If we haven't opened the file for O_WRONLY, we
2946 * need to in the size_change case to obtain a stateid.
2949 * Because OPEN is always done by name in nfsv4, it is
2950 * possible that we opened a different file by the same
2951 * name. We can recognize this race condition, but we
2952 * can't do anything about it besides returning an error.
2954 * This will be fixed with VFS changes (lookup-intent).
2957 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2958 struct iattr *sattr)
2960 struct inode *inode = dentry->d_inode;
2961 struct rpc_cred *cred = NULL;
2962 struct nfs4_state *state = NULL;
2963 struct nfs4_label *label = NULL;
2966 if (pnfs_ld_layoutret_on_setattr(inode))
2967 pnfs_commit_and_return_layout(inode);
2969 nfs_fattr_init(fattr);
2971 /* Deal with open(O_TRUNC) */
2972 if (sattr->ia_valid & ATTR_OPEN)
2973 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME);
2975 /* Optimization: if the end result is no change, don't RPC */
2976 if ((sattr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
2979 /* Search for an existing open(O_WRITE) file */
2980 if (sattr->ia_valid & ATTR_FILE) {
2981 struct nfs_open_context *ctx;
2983 ctx = nfs_file_open_context(sattr->ia_file);
2990 label = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
2992 return PTR_ERR(label);
2994 status = nfs4_do_setattr(inode, cred, fattr, sattr, state, NULL, label);
2996 nfs_setattr_update_inode(inode, sattr);
2997 nfs_setsecurity(inode, fattr, label);
2999 nfs4_label_free(label);
3003 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
3004 const struct qstr *name, struct nfs_fh *fhandle,
3005 struct nfs_fattr *fattr, struct nfs4_label *label)
3007 struct nfs_server *server = NFS_SERVER(dir);
3009 struct nfs4_lookup_arg args = {
3010 .bitmask = server->attr_bitmask,
3011 .dir_fh = NFS_FH(dir),
3014 struct nfs4_lookup_res res = {
3020 struct rpc_message msg = {
3021 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
3026 args.bitmask = nfs4_bitmask(server, label);
3028 nfs_fattr_init(fattr);
3030 dprintk("NFS call lookup %s\n", name->name);
3031 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
3032 dprintk("NFS reply lookup: %d\n", status);
3036 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
3038 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
3039 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
3040 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
3044 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
3045 struct qstr *name, struct nfs_fh *fhandle,
3046 struct nfs_fattr *fattr, struct nfs4_label *label)
3048 struct nfs4_exception exception = { };
3049 struct rpc_clnt *client = *clnt;
3052 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr, label);
3053 trace_nfs4_lookup(dir, name, err);
3055 case -NFS4ERR_BADNAME:
3058 case -NFS4ERR_MOVED:
3059 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
3061 case -NFS4ERR_WRONGSEC:
3063 if (client != *clnt)
3066 client = nfs4_create_sec_client(client, dir, name);
3068 return PTR_ERR(client);
3070 exception.retry = 1;
3073 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
3075 } while (exception.retry);
3080 else if (client != *clnt)
3081 rpc_shutdown_client(client);
3086 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
3087 struct nfs_fh *fhandle, struct nfs_fattr *fattr,
3088 struct nfs4_label *label)
3091 struct rpc_clnt *client = NFS_CLIENT(dir);
3093 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, label);
3094 if (client != NFS_CLIENT(dir)) {
3095 rpc_shutdown_client(client);
3096 nfs_fixup_secinfo_attributes(fattr);
3102 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
3103 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
3106 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
3108 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr, NULL);
3110 rpc_shutdown_client(client);
3111 return ERR_PTR(status);
3116 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
3118 struct nfs_server *server = NFS_SERVER(inode);
3119 struct nfs4_accessargs args = {
3120 .fh = NFS_FH(inode),
3121 .bitmask = server->cache_consistency_bitmask,
3123 struct nfs4_accessres res = {
3126 struct rpc_message msg = {
3127 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
3130 .rpc_cred = entry->cred,
3132 int mode = entry->mask;
3136 * Determine which access bits we want to ask for...
3138 if (mode & MAY_READ)
3139 args.access |= NFS4_ACCESS_READ;
3140 if (S_ISDIR(inode->i_mode)) {
3141 if (mode & MAY_WRITE)
3142 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
3143 if (mode & MAY_EXEC)
3144 args.access |= NFS4_ACCESS_LOOKUP;
3146 if (mode & MAY_WRITE)
3147 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
3148 if (mode & MAY_EXEC)
3149 args.access |= NFS4_ACCESS_EXECUTE;
3152 res.fattr = nfs_alloc_fattr();
3153 if (res.fattr == NULL)
3156 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3158 nfs_access_set_mask(entry, res.access);
3159 nfs_refresh_inode(inode, res.fattr);
3161 nfs_free_fattr(res.fattr);
3165 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
3167 struct nfs4_exception exception = { };
3170 err = _nfs4_proc_access(inode, entry);
3171 trace_nfs4_access(inode, err);
3172 err = nfs4_handle_exception(NFS_SERVER(inode), err,
3174 } while (exception.retry);
3179 * TODO: For the time being, we don't try to get any attributes
3180 * along with any of the zero-copy operations READ, READDIR,
3183 * In the case of the first three, we want to put the GETATTR
3184 * after the read-type operation -- this is because it is hard
3185 * to predict the length of a GETATTR response in v4, and thus
3186 * align the READ data correctly. This means that the GETATTR
3187 * may end up partially falling into the page cache, and we should
3188 * shift it into the 'tail' of the xdr_buf before processing.
3189 * To do this efficiently, we need to know the total length
3190 * of data received, which doesn't seem to be available outside
3193 * In the case of WRITE, we also want to put the GETATTR after
3194 * the operation -- in this case because we want to make sure
3195 * we get the post-operation mtime and size.
3197 * Both of these changes to the XDR layer would in fact be quite
3198 * minor, but I decided to leave them for a subsequent patch.
3200 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
3201 unsigned int pgbase, unsigned int pglen)
3203 struct nfs4_readlink args = {
3204 .fh = NFS_FH(inode),
3209 struct nfs4_readlink_res res;
3210 struct rpc_message msg = {
3211 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
3216 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
3219 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
3220 unsigned int pgbase, unsigned int pglen)
3222 struct nfs4_exception exception = { };
3225 err = _nfs4_proc_readlink(inode, page, pgbase, pglen);
3226 trace_nfs4_readlink(inode, err);
3227 err = nfs4_handle_exception(NFS_SERVER(inode), err,
3229 } while (exception.retry);
3234 * This is just for mknod. open(O_CREAT) will always do ->open_context().
3237 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
3240 struct nfs4_label l, *ilabel = NULL;
3241 struct nfs_open_context *ctx;
3242 struct nfs4_state *state;
3245 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
3247 return PTR_ERR(ctx);
3249 ilabel = nfs4_label_init_security(dir, dentry, sattr, &l);
3251 sattr->ia_mode &= ~current_umask();
3252 state = nfs4_do_open(dir, ctx, flags, sattr, ilabel);
3253 if (IS_ERR(state)) {
3254 status = PTR_ERR(state);
3258 nfs4_label_release_security(ilabel);
3259 put_nfs_open_context(ctx);
3263 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
3265 struct nfs_server *server = NFS_SERVER(dir);
3266 struct nfs_removeargs args = {
3270 struct nfs_removeres res = {
3273 struct rpc_message msg = {
3274 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
3280 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
3282 update_changeattr(dir, &res.cinfo);
3286 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
3288 struct nfs4_exception exception = { };
3291 err = _nfs4_proc_remove(dir, name);
3292 trace_nfs4_remove(dir, name, err);
3293 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3295 } while (exception.retry);
3299 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
3301 struct nfs_server *server = NFS_SERVER(dir);
3302 struct nfs_removeargs *args = msg->rpc_argp;
3303 struct nfs_removeres *res = msg->rpc_resp;
3305 res->server = server;
3306 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
3307 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
3309 nfs_fattr_init(res->dir_attr);
3312 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
3314 nfs4_setup_sequence(NFS_SERVER(data->dir),
3315 &data->args.seq_args,
3320 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
3322 struct nfs_unlinkdata *data = task->tk_calldata;
3323 struct nfs_removeres *res = &data->res;
3325 if (!nfs4_sequence_done(task, &res->seq_res))
3327 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3329 update_changeattr(dir, &res->cinfo);
3333 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
3335 struct nfs_server *server = NFS_SERVER(dir);
3336 struct nfs_renameargs *arg = msg->rpc_argp;
3337 struct nfs_renameres *res = msg->rpc_resp;
3339 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
3340 res->server = server;
3341 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
3344 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
3346 nfs4_setup_sequence(NFS_SERVER(data->old_dir),
3347 &data->args.seq_args,
3352 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
3353 struct inode *new_dir)
3355 struct nfs_renamedata *data = task->tk_calldata;
3356 struct nfs_renameres *res = &data->res;
3358 if (!nfs4_sequence_done(task, &res->seq_res))
3360 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3363 update_changeattr(old_dir, &res->old_cinfo);
3364 update_changeattr(new_dir, &res->new_cinfo);
3368 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3369 struct inode *new_dir, struct qstr *new_name)
3371 struct nfs_server *server = NFS_SERVER(old_dir);
3372 struct nfs_renameargs arg = {
3373 .old_dir = NFS_FH(old_dir),
3374 .new_dir = NFS_FH(new_dir),
3375 .old_name = old_name,
3376 .new_name = new_name,
3378 struct nfs_renameres res = {
3381 struct rpc_message msg = {
3382 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3386 int status = -ENOMEM;
3388 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3390 update_changeattr(old_dir, &res.old_cinfo);
3391 update_changeattr(new_dir, &res.new_cinfo);
3396 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3397 struct inode *new_dir, struct qstr *new_name)
3399 struct nfs4_exception exception = { };
3402 err = _nfs4_proc_rename(old_dir, old_name,
3404 trace_nfs4_rename(old_dir, old_name, new_dir, new_name, err);
3405 err = nfs4_handle_exception(NFS_SERVER(old_dir), err,
3407 } while (exception.retry);
3411 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3413 struct nfs_server *server = NFS_SERVER(inode);
3414 struct nfs4_link_arg arg = {
3415 .fh = NFS_FH(inode),
3416 .dir_fh = NFS_FH(dir),
3418 .bitmask = server->attr_bitmask,
3420 struct nfs4_link_res res = {
3424 struct rpc_message msg = {
3425 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3429 int status = -ENOMEM;
3431 res.fattr = nfs_alloc_fattr();
3432 if (res.fattr == NULL)
3435 res.label = nfs4_label_alloc(server, GFP_KERNEL);
3436 if (IS_ERR(res.label)) {
3437 status = PTR_ERR(res.label);
3440 arg.bitmask = nfs4_bitmask(server, res.label);
3442 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3444 update_changeattr(dir, &res.cinfo);
3445 status = nfs_post_op_update_inode(inode, res.fattr);
3447 nfs_setsecurity(inode, res.fattr, res.label);
3451 nfs4_label_free(res.label);
3454 nfs_free_fattr(res.fattr);
3458 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3460 struct nfs4_exception exception = { };
3463 err = nfs4_handle_exception(NFS_SERVER(inode),
3464 _nfs4_proc_link(inode, dir, name),
3466 } while (exception.retry);
3470 struct nfs4_createdata {
3471 struct rpc_message msg;
3472 struct nfs4_create_arg arg;
3473 struct nfs4_create_res res;
3475 struct nfs_fattr fattr;
3476 struct nfs4_label *label;
3479 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3480 struct qstr *name, struct iattr *sattr, u32 ftype)
3482 struct nfs4_createdata *data;
3484 data = kzalloc(sizeof(*data), GFP_KERNEL);
3486 struct nfs_server *server = NFS_SERVER(dir);
3488 data->label = nfs4_label_alloc(server, GFP_KERNEL);
3489 if (IS_ERR(data->label))
3492 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3493 data->msg.rpc_argp = &data->arg;
3494 data->msg.rpc_resp = &data->res;
3495 data->arg.dir_fh = NFS_FH(dir);
3496 data->arg.server = server;
3497 data->arg.name = name;
3498 data->arg.attrs = sattr;
3499 data->arg.ftype = ftype;
3500 data->arg.bitmask = nfs4_bitmask(server, data->label);
3501 data->res.server = server;
3502 data->res.fh = &data->fh;
3503 data->res.fattr = &data->fattr;
3504 data->res.label = data->label;
3505 nfs_fattr_init(data->res.fattr);
3513 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3515 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3516 &data->arg.seq_args, &data->res.seq_res, 1);
3518 update_changeattr(dir, &data->res.dir_cinfo);
3519 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr, data->res.label);
3524 static void nfs4_free_createdata(struct nfs4_createdata *data)
3526 nfs4_label_free(data->label);
3530 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3531 struct page *page, unsigned int len, struct iattr *sattr,
3532 struct nfs4_label *label)
3534 struct nfs4_createdata *data;
3535 int status = -ENAMETOOLONG;
3537 if (len > NFS4_MAXPATHLEN)
3541 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3545 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3546 data->arg.u.symlink.pages = &page;
3547 data->arg.u.symlink.len = len;
3548 data->arg.label = label;
3550 status = nfs4_do_create(dir, dentry, data);
3552 nfs4_free_createdata(data);
3557 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3558 struct page *page, unsigned int len, struct iattr *sattr)
3560 struct nfs4_exception exception = { };
3561 struct nfs4_label l, *label = NULL;
3564 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3567 err = _nfs4_proc_symlink(dir, dentry, page, len, sattr, label);
3568 trace_nfs4_symlink(dir, &dentry->d_name, err);
3569 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3571 } while (exception.retry);
3573 nfs4_label_release_security(label);
3577 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3578 struct iattr *sattr, struct nfs4_label *label)
3580 struct nfs4_createdata *data;
3581 int status = -ENOMEM;
3583 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3587 data->arg.label = label;
3588 status = nfs4_do_create(dir, dentry, data);
3590 nfs4_free_createdata(data);
3595 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3596 struct iattr *sattr)
3598 struct nfs4_exception exception = { };
3599 struct nfs4_label l, *label = NULL;
3602 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3604 sattr->ia_mode &= ~current_umask();
3606 err = _nfs4_proc_mkdir(dir, dentry, sattr, label);
3607 trace_nfs4_mkdir(dir, &dentry->d_name, err);
3608 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3610 } while (exception.retry);
3611 nfs4_label_release_security(label);
3616 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3617 u64 cookie, struct page **pages, unsigned int count, int plus)
3619 struct inode *dir = dentry->d_inode;
3620 struct nfs4_readdir_arg args = {
3625 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3628 struct nfs4_readdir_res res;
3629 struct rpc_message msg = {
3630 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3637 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3638 dentry->d_parent->d_name.name,
3639 dentry->d_name.name,
3640 (unsigned long long)cookie);
3641 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3642 res.pgbase = args.pgbase;
3643 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3645 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3646 status += args.pgbase;
3649 nfs_invalidate_atime(dir);
3651 dprintk("%s: returns %d\n", __func__, status);
3655 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3656 u64 cookie, struct page **pages, unsigned int count, int plus)
3658 struct nfs4_exception exception = { };
3661 err = _nfs4_proc_readdir(dentry, cred, cookie,
3662 pages, count, plus);
3663 trace_nfs4_readdir(dentry->d_inode, err);
3664 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode), err,
3666 } while (exception.retry);
3670 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3671 struct iattr *sattr, struct nfs4_label *label, dev_t rdev)
3673 struct nfs4_createdata *data;
3674 int mode = sattr->ia_mode;
3675 int status = -ENOMEM;
3677 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3682 data->arg.ftype = NF4FIFO;
3683 else if (S_ISBLK(mode)) {
3684 data->arg.ftype = NF4BLK;
3685 data->arg.u.device.specdata1 = MAJOR(rdev);
3686 data->arg.u.device.specdata2 = MINOR(rdev);
3688 else if (S_ISCHR(mode)) {
3689 data->arg.ftype = NF4CHR;
3690 data->arg.u.device.specdata1 = MAJOR(rdev);
3691 data->arg.u.device.specdata2 = MINOR(rdev);
3692 } else if (!S_ISSOCK(mode)) {
3697 data->arg.label = label;
3698 status = nfs4_do_create(dir, dentry, data);
3700 nfs4_free_createdata(data);
3705 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3706 struct iattr *sattr, dev_t rdev)
3708 struct nfs4_exception exception = { };
3709 struct nfs4_label l, *label = NULL;
3712 label = nfs4_label_init_security(dir, dentry, sattr, &l);
3714 sattr->ia_mode &= ~current_umask();
3716 err = _nfs4_proc_mknod(dir, dentry, sattr, label, rdev);
3717 trace_nfs4_mknod(dir, &dentry->d_name, err);
3718 err = nfs4_handle_exception(NFS_SERVER(dir), err,
3720 } while (exception.retry);
3722 nfs4_label_release_security(label);
3727 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3728 struct nfs_fsstat *fsstat)
3730 struct nfs4_statfs_arg args = {
3732 .bitmask = server->attr_bitmask,
3734 struct nfs4_statfs_res res = {
3737 struct rpc_message msg = {
3738 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3743 nfs_fattr_init(fsstat->fattr);
3744 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3747 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3749 struct nfs4_exception exception = { };
3752 err = nfs4_handle_exception(server,
3753 _nfs4_proc_statfs(server, fhandle, fsstat),
3755 } while (exception.retry);
3759 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3760 struct nfs_fsinfo *fsinfo)
3762 struct nfs4_fsinfo_arg args = {
3764 .bitmask = server->attr_bitmask,
3766 struct nfs4_fsinfo_res res = {
3769 struct rpc_message msg = {
3770 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3775 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3778 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3780 struct nfs4_exception exception = { };
3781 unsigned long now = jiffies;
3785 err = _nfs4_do_fsinfo(server, fhandle, fsinfo);
3786 trace_nfs4_fsinfo(server, fhandle, fsinfo->fattr, err);
3788 struct nfs_client *clp = server->nfs_client;
3790 spin_lock(&clp->cl_lock);
3791 clp->cl_lease_time = fsinfo->lease_time * HZ;
3792 clp->cl_last_renewal = now;
3793 spin_unlock(&clp->cl_lock);
3796 err = nfs4_handle_exception(server, err, &exception);
3797 } while (exception.retry);
3801 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3805 nfs_fattr_init(fsinfo->fattr);
3806 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3808 /* block layout checks this! */
3809 server->pnfs_blksize = fsinfo->blksize;
3810 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3816 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3817 struct nfs_pathconf *pathconf)
3819 struct nfs4_pathconf_arg args = {
3821 .bitmask = server->attr_bitmask,
3823 struct nfs4_pathconf_res res = {
3824 .pathconf = pathconf,
3826 struct rpc_message msg = {
3827 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3832 /* None of the pathconf attributes are mandatory to implement */
3833 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3834 memset(pathconf, 0, sizeof(*pathconf));
3838 nfs_fattr_init(pathconf->fattr);
3839 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3842 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3843 struct nfs_pathconf *pathconf)
3845 struct nfs4_exception exception = { };
3849 err = nfs4_handle_exception(server,
3850 _nfs4_proc_pathconf(server, fhandle, pathconf),
3852 } while (exception.retry);
3856 int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3857 const struct nfs_open_context *ctx,
3858 const struct nfs_lock_context *l_ctx,
3861 const struct nfs_lockowner *lockowner = NULL;
3864 lockowner = &l_ctx->lockowner;
3865 return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner);
3867 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid);
3869 static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
3870 const struct nfs_open_context *ctx,
3871 const struct nfs_lock_context *l_ctx,
3874 nfs4_stateid current_stateid;
3876 if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode))
3878 return nfs4_stateid_match(stateid, ¤t_stateid);
3881 static bool nfs4_error_stateid_expired(int err)
3884 case -NFS4ERR_DELEG_REVOKED:
3885 case -NFS4ERR_ADMIN_REVOKED:
3886 case -NFS4ERR_BAD_STATEID:
3887 case -NFS4ERR_STALE_STATEID:
3888 case -NFS4ERR_OLD_STATEID:
3889 case -NFS4ERR_OPENMODE:
3890 case -NFS4ERR_EXPIRED:
3896 void __nfs4_read_done_cb(struct nfs_read_data *data)
3898 nfs_invalidate_atime(data->header->inode);
3901 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3903 struct nfs_server *server = NFS_SERVER(data->header->inode);
3905 trace_nfs4_read(data, task->tk_status);
3906 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3907 rpc_restart_call_prepare(task);
3911 __nfs4_read_done_cb(data);
3912 if (task->tk_status > 0)
3913 renew_lease(server, data->timestamp);
3917 static bool nfs4_read_stateid_changed(struct rpc_task *task,
3918 struct nfs_readargs *args)
3921 if (!nfs4_error_stateid_expired(task->tk_status) ||
3922 nfs4_stateid_is_current(&args->stateid,
3927 rpc_restart_call_prepare(task);
3931 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3934 dprintk("--> %s\n", __func__);
3936 if (!nfs4_sequence_done(task, &data->res.seq_res))
3938 if (nfs4_read_stateid_changed(task, &data->args))
3940 return data->read_done_cb ? data->read_done_cb(task, data) :
3941 nfs4_read_done_cb(task, data);
3944 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3946 data->timestamp = jiffies;
3947 data->read_done_cb = nfs4_read_done_cb;
3948 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3949 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3952 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3954 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3955 &data->args.seq_args,
3959 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3960 data->args.lock_context, FMODE_READ);
3963 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3965 struct inode *inode = data->header->inode;
3967 trace_nfs4_write(data, task->tk_status);
3968 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3969 rpc_restart_call_prepare(task);
3972 if (task->tk_status >= 0) {
3973 renew_lease(NFS_SERVER(inode), data->timestamp);
3974 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
3979 static bool nfs4_write_stateid_changed(struct rpc_task *task,
3980 struct nfs_writeargs *args)
3983 if (!nfs4_error_stateid_expired(task->tk_status) ||
3984 nfs4_stateid_is_current(&args->stateid,
3989 rpc_restart_call_prepare(task);
3993 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3995 if (!nfs4_sequence_done(task, &data->res.seq_res))
3997 if (nfs4_write_stateid_changed(task, &data->args))
3999 return data->write_done_cb ? data->write_done_cb(task, data) :
4000 nfs4_write_done_cb(task, data);
4004 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
4006 const struct nfs_pgio_header *hdr = data->header;
4008 /* Don't request attributes for pNFS or O_DIRECT writes */
4009 if (data->ds_clp != NULL || hdr->dreq != NULL)
4011 /* Otherwise, request attributes if and only if we don't hold
4014 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
4017 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
4019 struct nfs_server *server = NFS_SERVER(data->header->inode);
4021 if (!nfs4_write_need_cache_consistency_data(data)) {
4022 data->args.bitmask = NULL;
4023 data->res.fattr = NULL;
4025 data->args.bitmask = server->cache_consistency_bitmask;
4027 if (!data->write_done_cb)
4028 data->write_done_cb = nfs4_write_done_cb;
4029 data->res.server = server;
4030 data->timestamp = jiffies;
4032 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
4033 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4036 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
4038 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
4039 &data->args.seq_args,
4043 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
4044 data->args.lock_context, FMODE_WRITE);
4047 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
4049 nfs4_setup_sequence(NFS_SERVER(data->inode),
4050 &data->args.seq_args,
4055 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
4057 struct inode *inode = data->inode;
4059 trace_nfs4_commit(data, task->tk_status);
4060 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
4061 rpc_restart_call_prepare(task);
4067 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
4069 if (!nfs4_sequence_done(task, &data->res.seq_res))
4071 return data->commit_done_cb(task, data);
4074 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
4076 struct nfs_server *server = NFS_SERVER(data->inode);
4078 if (data->commit_done_cb == NULL)
4079 data->commit_done_cb = nfs4_commit_done_cb;
4080 data->res.server = server;
4081 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
4082 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4085 struct nfs4_renewdata {
4086 struct nfs_client *client;
4087 unsigned long timestamp;
4091 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
4092 * standalone procedure for queueing an asynchronous RENEW.
4094 static void nfs4_renew_release(void *calldata)
4096 struct nfs4_renewdata *data = calldata;
4097 struct nfs_client *clp = data->client;
4099 if (atomic_read(&clp->cl_count) > 1)
4100 nfs4_schedule_state_renewal(clp);
4101 nfs_put_client(clp);
4105 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
4107 struct nfs4_renewdata *data = calldata;
4108 struct nfs_client *clp = data->client;
4109 unsigned long timestamp = data->timestamp;
4111 trace_nfs4_renew_async(clp, task->tk_status);
4112 if (task->tk_status < 0) {
4113 /* Unless we're shutting down, schedule state recovery! */
4114 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
4116 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
4117 nfs4_schedule_lease_recovery(clp);
4120 nfs4_schedule_path_down_recovery(clp);
4122 do_renew_lease(clp, timestamp);
4125 static const struct rpc_call_ops nfs4_renew_ops = {
4126 .rpc_call_done = nfs4_renew_done,
4127 .rpc_release = nfs4_renew_release,
4130 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
4132 struct rpc_message msg = {
4133 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
4137 struct nfs4_renewdata *data;
4139 if (renew_flags == 0)
4141 if (!atomic_inc_not_zero(&clp->cl_count))
4143 data = kmalloc(sizeof(*data), GFP_NOFS);
4147 data->timestamp = jiffies;
4148 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT,
4149 &nfs4_renew_ops, data);
4152 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
4154 struct rpc_message msg = {
4155 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
4159 unsigned long now = jiffies;
4162 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4165 do_renew_lease(clp, now);
4169 static inline int nfs4_server_supports_acls(struct nfs_server *server)
4171 return (server->caps & NFS_CAP_ACLS)
4172 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
4173 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
4176 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
4177 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
4180 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
4182 static int buf_to_pages_noslab(const void *buf, size_t buflen,
4183 struct page **pages, unsigned int *pgbase)
4185 struct page *newpage, **spages;
4191 len = min_t(size_t, PAGE_SIZE, buflen);
4192 newpage = alloc_page(GFP_KERNEL);
4194 if (newpage == NULL)
4196 memcpy(page_address(newpage), buf, len);
4201 } while (buflen != 0);
4207 __free_page(spages[rc-1]);
4211 struct nfs4_cached_acl {
4217 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
4219 struct nfs_inode *nfsi = NFS_I(inode);
4221 spin_lock(&inode->i_lock);
4222 kfree(nfsi->nfs4_acl);
4223 nfsi->nfs4_acl = acl;
4224 spin_unlock(&inode->i_lock);
4227 static void nfs4_zap_acl_attr(struct inode *inode)
4229 nfs4_set_cached_acl(inode, NULL);
4232 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
4234 struct nfs_inode *nfsi = NFS_I(inode);
4235 struct nfs4_cached_acl *acl;
4238 spin_lock(&inode->i_lock);
4239 acl = nfsi->nfs4_acl;
4242 if (buf == NULL) /* user is just asking for length */
4244 if (acl->cached == 0)
4246 ret = -ERANGE; /* see getxattr(2) man page */
4247 if (acl->len > buflen)
4249 memcpy(buf, acl->data, acl->len);
4253 spin_unlock(&inode->i_lock);
4257 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
4259 struct nfs4_cached_acl *acl;
4260 size_t buflen = sizeof(*acl) + acl_len;
4262 if (buflen <= PAGE_SIZE) {
4263 acl = kmalloc(buflen, GFP_KERNEL);
4267 _copy_from_pages(acl->data, pages, pgbase, acl_len);
4269 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
4276 nfs4_set_cached_acl(inode, acl);
4280 * The getxattr API returns the required buffer length when called with a
4281 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
4282 * the required buf. On a NULL buf, we send a page of data to the server
4283 * guessing that the ACL request can be serviced by a page. If so, we cache
4284 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
4285 * the cache. If not so, we throw away the page, and cache the required
4286 * length. The next getxattr call will then produce another round trip to
4287 * the server, this time with the input buf of the required size.
4289 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4291 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
4292 struct nfs_getaclargs args = {
4293 .fh = NFS_FH(inode),
4297 struct nfs_getaclres res = {
4300 struct rpc_message msg = {
4301 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
4305 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4306 int ret = -ENOMEM, i;
4308 /* As long as we're doing a round trip to the server anyway,
4309 * let's be prepared for a page of acl data. */
4312 if (npages > ARRAY_SIZE(pages))
4315 for (i = 0; i < npages; i++) {
4316 pages[i] = alloc_page(GFP_KERNEL);
4321 /* for decoding across pages */
4322 res.acl_scratch = alloc_page(GFP_KERNEL);
4323 if (!res.acl_scratch)
4326 args.acl_len = npages * PAGE_SIZE;
4327 args.acl_pgbase = 0;
4329 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
4330 __func__, buf, buflen, npages, args.acl_len);
4331 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
4332 &msg, &args.seq_args, &res.seq_res, 0);
4336 /* Handle the case where the passed-in buffer is too short */
4337 if (res.acl_flags & NFS4_ACL_TRUNC) {
4338 /* Did the user only issue a request for the acl length? */
4344 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
4346 if (res.acl_len > buflen) {
4350 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
4355 for (i = 0; i < npages; i++)
4357 __free_page(pages[i]);
4358 if (res.acl_scratch)
4359 __free_page(res.acl_scratch);
4363 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4365 struct nfs4_exception exception = { };
4368 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
4369 trace_nfs4_get_acl(inode, ret);
4372 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
4373 } while (exception.retry);
4377 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
4379 struct nfs_server *server = NFS_SERVER(inode);
4382 if (!nfs4_server_supports_acls(server))
4384 ret = nfs_revalidate_inode(server, inode);
4387 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
4388 nfs_zap_acl_cache(inode);
4389 ret = nfs4_read_cached_acl(inode, buf, buflen);
4391 /* -ENOENT is returned if there is no ACL or if there is an ACL
4392 * but no cached acl data, just the acl length */
4394 return nfs4_get_acl_uncached(inode, buf, buflen);
4397 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4399 struct nfs_server *server = NFS_SERVER(inode);
4400 struct page *pages[NFS4ACL_MAXPAGES];
4401 struct nfs_setaclargs arg = {
4402 .fh = NFS_FH(inode),
4406 struct nfs_setaclres res;
4407 struct rpc_message msg = {
4408 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
4412 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4415 if (!nfs4_server_supports_acls(server))
4417 if (npages > ARRAY_SIZE(pages))
4419 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
4422 nfs4_inode_return_delegation(inode);
4423 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4426 * Free each page after tx, so the only ref left is
4427 * held by the network stack
4430 put_page(pages[i-1]);
4433 * Acl update can result in inode attribute update.
4434 * so mark the attribute cache invalid.
4436 spin_lock(&inode->i_lock);
4437 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
4438 spin_unlock(&inode->i_lock);
4439 nfs_access_zap_cache(inode);
4440 nfs_zap_acl_cache(inode);
4444 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4446 struct nfs4_exception exception = { };
4449 err = __nfs4_proc_set_acl(inode, buf, buflen);
4450 trace_nfs4_set_acl(inode, err);
4451 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4453 } while (exception.retry);
4457 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
4458 static int _nfs4_get_security_label(struct inode *inode, void *buf,
4461 struct nfs_server *server = NFS_SERVER(inode);
4462 struct nfs_fattr fattr;
4463 struct nfs4_label label = {0, 0, buflen, buf};
4465 u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
4466 struct nfs4_getattr_arg args = {
4467 .fh = NFS_FH(inode),
4470 struct nfs4_getattr_res res = {
4475 struct rpc_message msg = {
4476 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
4482 nfs_fattr_init(&fattr);
4484 ret = rpc_call_sync(server->client, &msg, 0);
4487 if (!(fattr.valid & NFS_ATTR_FATTR_V4_SECURITY_LABEL))
4489 if (buflen < label.len)
4494 static int nfs4_get_security_label(struct inode *inode, void *buf,
4497 struct nfs4_exception exception = { };
4500 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
4504 err = _nfs4_get_security_label(inode, buf, buflen);
4505 trace_nfs4_get_security_label(inode, err);
4506 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4508 } while (exception.retry);
4512 static int _nfs4_do_set_security_label(struct inode *inode,
4513 struct nfs4_label *ilabel,
4514 struct nfs_fattr *fattr,
4515 struct nfs4_label *olabel)
4518 struct iattr sattr = {0};
4519 struct nfs_server *server = NFS_SERVER(inode);
4520 const u32 bitmask[3] = { 0, 0, FATTR4_WORD2_SECURITY_LABEL };
4521 struct nfs_setattrargs args = {
4522 .fh = NFS_FH(inode),
4528 struct nfs_setattrres res = {
4533 struct rpc_message msg = {
4534 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
4540 nfs4_stateid_copy(&args.stateid, &zero_stateid);
4542 status = rpc_call_sync(server->client, &msg, 0);
4544 dprintk("%s failed: %d\n", __func__, status);
4549 static int nfs4_do_set_security_label(struct inode *inode,
4550 struct nfs4_label *ilabel,
4551 struct nfs_fattr *fattr,
4552 struct nfs4_label *olabel)
4554 struct nfs4_exception exception = { };
4558 err = _nfs4_do_set_security_label(inode, ilabel,
4560 trace_nfs4_set_security_label(inode, err);
4561 err = nfs4_handle_exception(NFS_SERVER(inode), err,
4563 } while (exception.retry);
4568 nfs4_set_security_label(struct dentry *dentry, const void *buf, size_t buflen)
4570 struct nfs4_label ilabel, *olabel = NULL;
4571 struct nfs_fattr fattr;
4572 struct rpc_cred *cred;
4573 struct inode *inode = dentry->d_inode;
4576 if (!nfs_server_capable(inode, NFS_CAP_SECURITY_LABEL))
4579 nfs_fattr_init(&fattr);
4583 ilabel.label = (char *)buf;
4584 ilabel.len = buflen;
4586 cred = rpc_lookup_cred();
4588 return PTR_ERR(cred);
4590 olabel = nfs4_label_alloc(NFS_SERVER(inode), GFP_KERNEL);
4591 if (IS_ERR(olabel)) {
4592 status = -PTR_ERR(olabel);
4596 status = nfs4_do_set_security_label(inode, &ilabel, &fattr, olabel);
4598 nfs_setsecurity(inode, &fattr, olabel);
4600 nfs4_label_free(olabel);
4605 #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
4609 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
4611 struct nfs_client *clp = server->nfs_client;
4613 if (task->tk_status >= 0)
4615 switch(task->tk_status) {
4616 case -NFS4ERR_DELEG_REVOKED:
4617 case -NFS4ERR_ADMIN_REVOKED:
4618 case -NFS4ERR_BAD_STATEID:
4621 nfs_remove_bad_delegation(state->inode);
4622 case -NFS4ERR_OPENMODE:
4625 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4626 goto stateid_invalid;
4627 goto wait_on_recovery;
4628 case -NFS4ERR_EXPIRED:
4629 if (state != NULL) {
4630 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4631 goto stateid_invalid;
4633 case -NFS4ERR_STALE_STATEID:
4634 case -NFS4ERR_STALE_CLIENTID:
4635 nfs4_schedule_lease_recovery(clp);
4636 goto wait_on_recovery;
4637 #if defined(CONFIG_NFS_V4_1)
4638 case -NFS4ERR_BADSESSION:
4639 case -NFS4ERR_BADSLOT:
4640 case -NFS4ERR_BAD_HIGH_SLOT:
4641 case -NFS4ERR_DEADSESSION:
4642 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4643 case -NFS4ERR_SEQ_FALSE_RETRY:
4644 case -NFS4ERR_SEQ_MISORDERED:
4645 dprintk("%s ERROR %d, Reset session\n", __func__,
4647 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
4648 task->tk_status = 0;
4650 #endif /* CONFIG_NFS_V4_1 */
4651 case -NFS4ERR_DELAY:
4652 nfs_inc_server_stats(server, NFSIOS_DELAY);
4653 case -NFS4ERR_GRACE:
4654 rpc_delay(task, NFS4_POLL_RETRY_MAX);
4655 task->tk_status = 0;
4657 case -NFS4ERR_RETRY_UNCACHED_REP:
4658 case -NFS4ERR_OLD_STATEID:
4659 task->tk_status = 0;
4662 task->tk_status = nfs4_map_errors(task->tk_status);
4665 task->tk_status = -EIO;
4668 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
4669 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4670 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
4671 task->tk_status = 0;
4675 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
4676 nfs4_verifier *bootverf)
4680 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4681 /* An impossible timestamp guarantees this value
4682 * will never match a generated boot time. */
4684 verf[1] = cpu_to_be32(NSEC_PER_SEC + 1);
4686 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4687 verf[0] = cpu_to_be32(nn->boot_time.tv_sec);
4688 verf[1] = cpu_to_be32(nn->boot_time.tv_nsec);
4690 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4694 nfs4_init_nonuniform_client_string(const struct nfs_client *clp,
4695 char *buf, size_t len)
4697 unsigned int result;
4700 result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s",
4702 rpc_peeraddr2str(clp->cl_rpcclient,
4704 rpc_peeraddr2str(clp->cl_rpcclient,
4705 RPC_DISPLAY_PROTO));
4711 nfs4_init_uniform_client_string(const struct nfs_client *clp,
4712 char *buf, size_t len)
4714 const char *nodename = clp->cl_rpcclient->cl_nodename;
4716 if (nfs4_client_id_uniquifier[0] != '\0')
4717 return scnprintf(buf, len, "Linux NFSv%u.%u %s/%s",
4718 clp->rpc_ops->version,
4719 clp->cl_minorversion,
4720 nfs4_client_id_uniquifier,
4722 return scnprintf(buf, len, "Linux NFSv%u.%u %s",
4723 clp->rpc_ops->version, clp->cl_minorversion,
4728 * nfs4_proc_setclientid - Negotiate client ID
4729 * @clp: state data structure
4730 * @program: RPC program for NFSv4 callback service
4731 * @port: IP port number for NFS4 callback service
4732 * @cred: RPC credential to use for this call
4733 * @res: where to place the result
4735 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4737 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4738 unsigned short port, struct rpc_cred *cred,
4739 struct nfs4_setclientid_res *res)
4741 nfs4_verifier sc_verifier;
4742 struct nfs4_setclientid setclientid = {
4743 .sc_verifier = &sc_verifier,
4745 .sc_cb_ident = clp->cl_cb_ident,
4747 struct rpc_message msg = {
4748 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4749 .rpc_argp = &setclientid,
4755 /* nfs_client_id4 */
4756 nfs4_init_boot_verifier(clp, &sc_verifier);
4757 if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
4758 setclientid.sc_name_len =
4759 nfs4_init_uniform_client_string(clp,
4760 setclientid.sc_name,
4761 sizeof(setclientid.sc_name));
4763 setclientid.sc_name_len =
4764 nfs4_init_nonuniform_client_string(clp,
4765 setclientid.sc_name,
4766 sizeof(setclientid.sc_name));
4769 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4770 sizeof(setclientid.sc_netid), "%s",
4771 rpc_peeraddr2str(clp->cl_rpcclient,
4772 RPC_DISPLAY_NETID));
4774 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4775 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4776 clp->cl_ipaddr, port >> 8, port & 255);
4778 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4779 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4780 setclientid.sc_name_len, setclientid.sc_name);
4781 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4782 trace_nfs4_setclientid(clp, status);
4783 dprintk("NFS reply setclientid: %d\n", status);
4788 * nfs4_proc_setclientid_confirm - Confirm client ID
4789 * @clp: state data structure
4790 * @res: result of a previous SETCLIENTID
4791 * @cred: RPC credential to use for this call
4793 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4795 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4796 struct nfs4_setclientid_res *arg,
4797 struct rpc_cred *cred)
4799 struct rpc_message msg = {
4800 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4806 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4807 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4809 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4810 trace_nfs4_setclientid_confirm(clp, status);
4811 dprintk("NFS reply setclientid_confirm: %d\n", status);
4815 struct nfs4_delegreturndata {
4816 struct nfs4_delegreturnargs args;
4817 struct nfs4_delegreturnres res;
4819 nfs4_stateid stateid;
4820 unsigned long timestamp;
4821 struct nfs_fattr fattr;
4825 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4827 struct nfs4_delegreturndata *data = calldata;
4829 if (!nfs4_sequence_done(task, &data->res.seq_res))
4832 trace_nfs4_delegreturn_exit(&data->args, &data->res, task->tk_status);
4833 switch (task->tk_status) {
4834 case -NFS4ERR_STALE_STATEID:
4835 case -NFS4ERR_EXPIRED:
4837 renew_lease(data->res.server, data->timestamp);
4840 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4842 rpc_restart_call_prepare(task);
4846 data->rpc_status = task->tk_status;
4849 static void nfs4_delegreturn_release(void *calldata)
4854 #if defined(CONFIG_NFS_V4_1)
4855 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4857 struct nfs4_delegreturndata *d_data;
4859 d_data = (struct nfs4_delegreturndata *)data;
4861 nfs4_setup_sequence(d_data->res.server,
4862 &d_data->args.seq_args,
4863 &d_data->res.seq_res,
4866 #endif /* CONFIG_NFS_V4_1 */
4868 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4869 #if defined(CONFIG_NFS_V4_1)
4870 .rpc_call_prepare = nfs4_delegreturn_prepare,
4871 #endif /* CONFIG_NFS_V4_1 */
4872 .rpc_call_done = nfs4_delegreturn_done,
4873 .rpc_release = nfs4_delegreturn_release,
4876 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4878 struct nfs4_delegreturndata *data;
4879 struct nfs_server *server = NFS_SERVER(inode);
4880 struct rpc_task *task;
4881 struct rpc_message msg = {
4882 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
4885 struct rpc_task_setup task_setup_data = {
4886 .rpc_client = server->client,
4887 .rpc_message = &msg,
4888 .callback_ops = &nfs4_delegreturn_ops,
4889 .flags = RPC_TASK_ASYNC,
4893 data = kzalloc(sizeof(*data), GFP_NOFS);
4896 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4897 data->args.fhandle = &data->fh;
4898 data->args.stateid = &data->stateid;
4899 data->args.bitmask = server->cache_consistency_bitmask;
4900 nfs_copy_fh(&data->fh, NFS_FH(inode));
4901 nfs4_stateid_copy(&data->stateid, stateid);
4902 data->res.fattr = &data->fattr;
4903 data->res.server = server;
4904 nfs_fattr_init(data->res.fattr);
4905 data->timestamp = jiffies;
4906 data->rpc_status = 0;
4908 task_setup_data.callback_data = data;
4909 msg.rpc_argp = &data->args;
4910 msg.rpc_resp = &data->res;
4911 task = rpc_run_task(&task_setup_data);
4913 return PTR_ERR(task);
4916 status = nfs4_wait_for_completion_rpc_task(task);
4919 status = data->rpc_status;
4921 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4923 nfs_refresh_inode(inode, &data->fattr);
4929 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4931 struct nfs_server *server = NFS_SERVER(inode);
4932 struct nfs4_exception exception = { };
4935 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4936 trace_nfs4_delegreturn(inode, err);
4938 case -NFS4ERR_STALE_STATEID:
4939 case -NFS4ERR_EXPIRED:
4943 err = nfs4_handle_exception(server, err, &exception);
4944 } while (exception.retry);
4948 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4949 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4952 * sleep, with exponential backoff, and retry the LOCK operation.
4954 static unsigned long
4955 nfs4_set_lock_task_retry(unsigned long timeout)
4957 freezable_schedule_timeout_killable_unsafe(timeout);
4959 if (timeout > NFS4_LOCK_MAXTIMEOUT)
4960 return NFS4_LOCK_MAXTIMEOUT;
4964 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4966 struct inode *inode = state->inode;
4967 struct nfs_server *server = NFS_SERVER(inode);
4968 struct nfs_client *clp = server->nfs_client;
4969 struct nfs_lockt_args arg = {
4970 .fh = NFS_FH(inode),
4973 struct nfs_lockt_res res = {
4976 struct rpc_message msg = {
4977 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
4980 .rpc_cred = state->owner->so_cred,
4982 struct nfs4_lock_state *lsp;
4985 arg.lock_owner.clientid = clp->cl_clientid;
4986 status = nfs4_set_lock_state(state, request);
4989 lsp = request->fl_u.nfs4_fl.owner;
4990 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4991 arg.lock_owner.s_dev = server->s_dev;
4992 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4995 request->fl_type = F_UNLCK;
4997 case -NFS4ERR_DENIED:
5000 request->fl_ops->fl_release_private(request);
5005 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5007 struct nfs4_exception exception = { };
5011 err = _nfs4_proc_getlk(state, cmd, request);
5012 trace_nfs4_get_lock(request, state, cmd, err);
5013 err = nfs4_handle_exception(NFS_SERVER(state->inode), err,
5015 } while (exception.retry);
5019 static int do_vfs_lock(struct file *file, struct file_lock *fl)
5022 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
5024 res = posix_lock_file_wait(file, fl);
5027 res = flock_lock_file_wait(file, fl);
5035 struct nfs4_unlockdata {
5036 struct nfs_locku_args arg;
5037 struct nfs_locku_res res;
5038 struct nfs4_lock_state *lsp;
5039 struct nfs_open_context *ctx;
5040 struct file_lock fl;
5041 const struct nfs_server *server;
5042 unsigned long timestamp;
5045 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
5046 struct nfs_open_context *ctx,
5047 struct nfs4_lock_state *lsp,
5048 struct nfs_seqid *seqid)
5050 struct nfs4_unlockdata *p;
5051 struct inode *inode = lsp->ls_state->inode;
5053 p = kzalloc(sizeof(*p), GFP_NOFS);
5056 p->arg.fh = NFS_FH(inode);
5058 p->arg.seqid = seqid;
5059 p->res.seqid = seqid;
5060 p->arg.stateid = &lsp->ls_stateid;
5062 atomic_inc(&lsp->ls_count);
5063 /* Ensure we don't close file until we're done freeing locks! */
5064 p->ctx = get_nfs_open_context(ctx);
5065 memcpy(&p->fl, fl, sizeof(p->fl));
5066 p->server = NFS_SERVER(inode);
5070 static void nfs4_locku_release_calldata(void *data)
5072 struct nfs4_unlockdata *calldata = data;
5073 nfs_free_seqid(calldata->arg.seqid);
5074 nfs4_put_lock_state(calldata->lsp);
5075 put_nfs_open_context(calldata->ctx);
5079 static void nfs4_locku_done(struct rpc_task *task, void *data)
5081 struct nfs4_unlockdata *calldata = data;
5083 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
5085 switch (task->tk_status) {
5087 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
5088 &calldata->res.stateid);
5089 renew_lease(calldata->server, calldata->timestamp);
5091 case -NFS4ERR_BAD_STATEID:
5092 case -NFS4ERR_OLD_STATEID:
5093 case -NFS4ERR_STALE_STATEID:
5094 case -NFS4ERR_EXPIRED:
5097 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
5098 rpc_restart_call_prepare(task);
5100 nfs_release_seqid(calldata->arg.seqid);
5103 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
5105 struct nfs4_unlockdata *calldata = data;
5107 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
5109 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
5110 /* Note: exit _without_ running nfs4_locku_done */
5113 calldata->timestamp = jiffies;
5114 if (nfs4_setup_sequence(calldata->server,
5115 &calldata->arg.seq_args,
5116 &calldata->res.seq_res,
5118 nfs_release_seqid(calldata->arg.seqid);
5121 task->tk_action = NULL;
5123 nfs4_sequence_done(task, &calldata->res.seq_res);
5126 static const struct rpc_call_ops nfs4_locku_ops = {
5127 .rpc_call_prepare = nfs4_locku_prepare,
5128 .rpc_call_done = nfs4_locku_done,
5129 .rpc_release = nfs4_locku_release_calldata,
5132 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
5133 struct nfs_open_context *ctx,
5134 struct nfs4_lock_state *lsp,
5135 struct nfs_seqid *seqid)
5137 struct nfs4_unlockdata *data;
5138 struct rpc_message msg = {
5139 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
5140 .rpc_cred = ctx->cred,
5142 struct rpc_task_setup task_setup_data = {
5143 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
5144 .rpc_message = &msg,
5145 .callback_ops = &nfs4_locku_ops,
5146 .workqueue = nfsiod_workqueue,
5147 .flags = RPC_TASK_ASYNC,
5150 /* Ensure this is an unlock - when canceling a lock, the
5151 * canceled lock is passed in, and it won't be an unlock.
5153 fl->fl_type = F_UNLCK;
5155 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
5157 nfs_free_seqid(seqid);
5158 return ERR_PTR(-ENOMEM);
5161 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
5162 msg.rpc_argp = &data->arg;
5163 msg.rpc_resp = &data->res;
5164 task_setup_data.callback_data = data;
5165 return rpc_run_task(&task_setup_data);
5168 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
5170 struct inode *inode = state->inode;
5171 struct nfs4_state_owner *sp = state->owner;
5172 struct nfs_inode *nfsi = NFS_I(inode);
5173 struct nfs_seqid *seqid;
5174 struct nfs4_lock_state *lsp;
5175 struct rpc_task *task;
5177 unsigned char fl_flags = request->fl_flags;
5179 status = nfs4_set_lock_state(state, request);
5180 /* Unlock _before_ we do the RPC call */
5181 request->fl_flags |= FL_EXISTS;
5182 /* Exclude nfs_delegation_claim_locks() */
5183 mutex_lock(&sp->so_delegreturn_mutex);
5184 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
5185 down_read(&nfsi->rwsem);
5186 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
5187 up_read(&nfsi->rwsem);
5188 mutex_unlock(&sp->so_delegreturn_mutex);
5191 up_read(&nfsi->rwsem);
5192 mutex_unlock(&sp->so_delegreturn_mutex);
5195 /* Is this a delegated lock? */
5196 lsp = request->fl_u.nfs4_fl.owner;
5197 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) == 0)
5199 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
5203 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
5204 status = PTR_ERR(task);
5207 status = nfs4_wait_for_completion_rpc_task(task);
5210 request->fl_flags = fl_flags;
5211 trace_nfs4_unlock(request, state, F_SETLK, status);
5215 struct nfs4_lockdata {
5216 struct nfs_lock_args arg;
5217 struct nfs_lock_res res;
5218 struct nfs4_lock_state *lsp;
5219 struct nfs_open_context *ctx;
5220 struct file_lock fl;
5221 unsigned long timestamp;
5224 struct nfs_server *server;
5227 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
5228 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
5231 struct nfs4_lockdata *p;
5232 struct inode *inode = lsp->ls_state->inode;
5233 struct nfs_server *server = NFS_SERVER(inode);
5235 p = kzalloc(sizeof(*p), gfp_mask);
5239 p->arg.fh = NFS_FH(inode);
5241 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
5242 if (p->arg.open_seqid == NULL)
5244 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
5245 if (p->arg.lock_seqid == NULL)
5246 goto out_free_seqid;
5247 p->arg.lock_stateid = &lsp->ls_stateid;
5248 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
5249 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
5250 p->arg.lock_owner.s_dev = server->s_dev;
5251 p->res.lock_seqid = p->arg.lock_seqid;
5254 atomic_inc(&lsp->ls_count);
5255 p->ctx = get_nfs_open_context(ctx);
5256 memcpy(&p->fl, fl, sizeof(p->fl));
5259 nfs_free_seqid(p->arg.open_seqid);
5265 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
5267 struct nfs4_lockdata *data = calldata;
5268 struct nfs4_state *state = data->lsp->ls_state;
5270 dprintk("%s: begin!\n", __func__);
5271 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
5273 /* Do we need to do an open_to_lock_owner? */
5274 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
5275 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) {
5276 goto out_release_lock_seqid;
5278 data->arg.open_stateid = &state->open_stateid;
5279 data->arg.new_lock_owner = 1;
5280 data->res.open_seqid = data->arg.open_seqid;
5282 data->arg.new_lock_owner = 0;
5283 if (!nfs4_valid_open_stateid(state)) {
5284 data->rpc_status = -EBADF;
5285 task->tk_action = NULL;
5286 goto out_release_open_seqid;
5288 data->timestamp = jiffies;
5289 if (nfs4_setup_sequence(data->server,
5290 &data->arg.seq_args,
5294 out_release_open_seqid:
5295 nfs_release_seqid(data->arg.open_seqid);
5296 out_release_lock_seqid:
5297 nfs_release_seqid(data->arg.lock_seqid);
5299 nfs4_sequence_done(task, &data->res.seq_res);
5300 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
5303 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
5305 struct nfs4_lockdata *data = calldata;
5307 dprintk("%s: begin!\n", __func__);
5309 if (!nfs4_sequence_done(task, &data->res.seq_res))
5312 data->rpc_status = task->tk_status;
5313 if (data->arg.new_lock_owner != 0) {
5314 if (data->rpc_status == 0)
5315 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
5319 if (data->rpc_status == 0) {
5320 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
5321 set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags);
5322 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
5325 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
5328 static void nfs4_lock_release(void *calldata)
5330 struct nfs4_lockdata *data = calldata;
5332 dprintk("%s: begin!\n", __func__);
5333 nfs_free_seqid(data->arg.open_seqid);
5334 if (data->cancelled != 0) {
5335 struct rpc_task *task;
5336 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
5337 data->arg.lock_seqid);
5339 rpc_put_task_async(task);
5340 dprintk("%s: cancelling lock!\n", __func__);
5342 nfs_free_seqid(data->arg.lock_seqid);
5343 nfs4_put_lock_state(data->lsp);
5344 put_nfs_open_context(data->ctx);
5346 dprintk("%s: done!\n", __func__);
5349 static const struct rpc_call_ops nfs4_lock_ops = {
5350 .rpc_call_prepare = nfs4_lock_prepare,
5351 .rpc_call_done = nfs4_lock_done,
5352 .rpc_release = nfs4_lock_release,
5355 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
5358 case -NFS4ERR_ADMIN_REVOKED:
5359 case -NFS4ERR_BAD_STATEID:
5360 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
5361 if (new_lock_owner != 0 ||
5362 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
5363 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
5365 case -NFS4ERR_STALE_STATEID:
5366 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
5367 case -NFS4ERR_EXPIRED:
5368 nfs4_schedule_lease_recovery(server->nfs_client);
5372 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
5374 struct nfs4_lockdata *data;
5375 struct rpc_task *task;
5376 struct rpc_message msg = {
5377 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
5378 .rpc_cred = state->owner->so_cred,
5380 struct rpc_task_setup task_setup_data = {
5381 .rpc_client = NFS_CLIENT(state->inode),
5382 .rpc_message = &msg,
5383 .callback_ops = &nfs4_lock_ops,
5384 .workqueue = nfsiod_workqueue,
5385 .flags = RPC_TASK_ASYNC,
5389 dprintk("%s: begin!\n", __func__);
5390 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
5391 fl->fl_u.nfs4_fl.owner,
5392 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
5396 data->arg.block = 1;
5397 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
5398 msg.rpc_argp = &data->arg;
5399 msg.rpc_resp = &data->res;
5400 task_setup_data.callback_data = data;
5401 if (recovery_type > NFS_LOCK_NEW) {
5402 if (recovery_type == NFS_LOCK_RECLAIM)
5403 data->arg.reclaim = NFS_LOCK_RECLAIM;
5404 nfs4_set_sequence_privileged(&data->arg.seq_args);
5406 task = rpc_run_task(&task_setup_data);
5408 return PTR_ERR(task);
5409 ret = nfs4_wait_for_completion_rpc_task(task);
5411 ret = data->rpc_status;
5413 nfs4_handle_setlk_error(data->server, data->lsp,
5414 data->arg.new_lock_owner, ret);
5416 data->cancelled = 1;
5418 dprintk("%s: done, ret = %d!\n", __func__, ret);
5422 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
5424 struct nfs_server *server = NFS_SERVER(state->inode);
5425 struct nfs4_exception exception = {
5426 .inode = state->inode,
5431 /* Cache the lock if possible... */
5432 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
5434 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
5435 trace_nfs4_lock_reclaim(request, state, F_SETLK, err);
5436 if (err != -NFS4ERR_DELAY)
5438 nfs4_handle_exception(server, err, &exception);
5439 } while (exception.retry);
5443 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
5445 struct nfs_server *server = NFS_SERVER(state->inode);
5446 struct nfs4_exception exception = {
5447 .inode = state->inode,
5451 err = nfs4_set_lock_state(state, request);
5455 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
5457 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
5458 trace_nfs4_lock_expired(request, state, F_SETLK, err);
5462 case -NFS4ERR_GRACE:
5463 case -NFS4ERR_DELAY:
5464 nfs4_handle_exception(server, err, &exception);
5467 } while (exception.retry);
5472 #if defined(CONFIG_NFS_V4_1)
5474 * nfs41_check_expired_locks - possibly free a lock stateid
5476 * @state: NFSv4 state for an inode
5478 * Returns NFS_OK if recovery for this stateid is now finished.
5479 * Otherwise a negative NFS4ERR value is returned.
5481 static int nfs41_check_expired_locks(struct nfs4_state *state)
5483 int status, ret = -NFS4ERR_BAD_STATEID;
5484 struct nfs4_lock_state *lsp;
5485 struct nfs_server *server = NFS_SERVER(state->inode);
5487 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
5488 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
5489 struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
5491 status = nfs41_test_stateid(server,
5494 trace_nfs4_test_lock_stateid(state, lsp, status);
5495 if (status != NFS_OK) {
5496 /* Free the stateid unless the server
5497 * informs us the stateid is unrecognized. */
5498 if (status != -NFS4ERR_BAD_STATEID)
5499 nfs41_free_stateid(server,
5502 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
5511 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
5513 int status = NFS_OK;
5515 if (test_bit(LK_STATE_IN_USE, &state->flags))
5516 status = nfs41_check_expired_locks(state);
5517 if (status != NFS_OK)
5518 status = nfs4_lock_expired(state, request);
5523 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5525 struct nfs4_state_owner *sp = state->owner;
5526 struct nfs_inode *nfsi = NFS_I(state->inode);
5527 unsigned char fl_flags = request->fl_flags;
5529 int status = -ENOLCK;
5531 if ((fl_flags & FL_POSIX) &&
5532 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
5534 /* Is this a delegated open? */
5535 status = nfs4_set_lock_state(state, request);
5538 request->fl_flags |= FL_ACCESS;
5539 status = do_vfs_lock(request->fl_file, request);
5542 down_read(&nfsi->rwsem);
5543 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
5544 /* Yes: cache locks! */
5545 /* ...but avoid races with delegation recall... */
5546 request->fl_flags = fl_flags & ~FL_SLEEP;
5547 status = do_vfs_lock(request->fl_file, request);
5550 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
5551 up_read(&nfsi->rwsem);
5552 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
5555 down_read(&nfsi->rwsem);
5556 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
5557 status = -NFS4ERR_DELAY;
5560 /* Note: we always want to sleep here! */
5561 request->fl_flags = fl_flags | FL_SLEEP;
5562 if (do_vfs_lock(request->fl_file, request) < 0)
5563 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
5564 "manager!\n", __func__);
5566 up_read(&nfsi->rwsem);
5568 request->fl_flags = fl_flags;
5572 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5574 struct nfs4_exception exception = {
5576 .inode = state->inode,
5581 err = _nfs4_proc_setlk(state, cmd, request);
5582 trace_nfs4_set_lock(request, state, cmd, err);
5583 if (err == -NFS4ERR_DENIED)
5585 err = nfs4_handle_exception(NFS_SERVER(state->inode),
5587 } while (exception.retry);
5592 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
5594 struct nfs_open_context *ctx;
5595 struct nfs4_state *state;
5596 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
5599 /* verify open state */
5600 ctx = nfs_file_open_context(filp);
5603 if (request->fl_start < 0 || request->fl_end < 0)
5606 if (IS_GETLK(cmd)) {
5608 return nfs4_proc_getlk(state, F_GETLK, request);
5612 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
5615 if (request->fl_type == F_UNLCK) {
5617 return nfs4_proc_unlck(state, cmd, request);
5624 * Don't rely on the VFS having checked the file open mode,
5625 * since it won't do this for flock() locks.
5627 switch (request->fl_type) {
5629 if (!(filp->f_mode & FMODE_READ))
5633 if (!(filp->f_mode & FMODE_WRITE))
5638 status = nfs4_proc_setlk(state, cmd, request);
5639 if ((status != -EAGAIN) || IS_SETLK(cmd))
5641 timeout = nfs4_set_lock_task_retry(timeout);
5642 status = -ERESTARTSYS;
5645 } while(status < 0);
5649 int nfs4_lock_delegation_recall(struct file_lock *fl, struct nfs4_state *state, const nfs4_stateid *stateid)
5651 struct nfs_server *server = NFS_SERVER(state->inode);
5654 err = nfs4_set_lock_state(state, fl);
5657 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
5658 return nfs4_handle_delegation_recall_error(server, state, stateid, err);
5661 struct nfs_release_lockowner_data {
5662 struct nfs4_lock_state *lsp;
5663 struct nfs_server *server;
5664 struct nfs_release_lockowner_args args;
5667 static void nfs4_release_lockowner_release(void *calldata)
5669 struct nfs_release_lockowner_data *data = calldata;
5670 nfs4_free_lock_state(data->server, data->lsp);
5674 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5675 .rpc_release = nfs4_release_lockowner_release,
5678 static int nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp)
5680 struct nfs_release_lockowner_data *data;
5681 struct rpc_message msg = {
5682 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5685 if (server->nfs_client->cl_mvops->minor_version != 0)
5687 data = kmalloc(sizeof(*data), GFP_NOFS);
5691 data->server = server;
5692 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5693 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5694 data->args.lock_owner.s_dev = server->s_dev;
5695 msg.rpc_argp = &data->args;
5696 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5700 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5702 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5703 const void *buf, size_t buflen,
5704 int flags, int type)
5706 if (strcmp(key, "") != 0)
5709 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5712 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5713 void *buf, size_t buflen, int type)
5715 if (strcmp(key, "") != 0)
5718 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5721 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5722 size_t list_len, const char *name,
5723 size_t name_len, int type)
5725 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5727 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5730 if (list && len <= list_len)
5731 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5735 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
5736 static inline int nfs4_server_supports_labels(struct nfs_server *server)
5738 return server->caps & NFS_CAP_SECURITY_LABEL;
5741 static int nfs4_xattr_set_nfs4_label(struct dentry *dentry, const char *key,
5742 const void *buf, size_t buflen,
5743 int flags, int type)
5745 if (security_ismaclabel(key))
5746 return nfs4_set_security_label(dentry, buf, buflen);
5751 static int nfs4_xattr_get_nfs4_label(struct dentry *dentry, const char *key,
5752 void *buf, size_t buflen, int type)
5754 if (security_ismaclabel(key))
5755 return nfs4_get_security_label(dentry->d_inode, buf, buflen);
5759 static size_t nfs4_xattr_list_nfs4_label(struct dentry *dentry, char *list,
5760 size_t list_len, const char *name,
5761 size_t name_len, int type)
5765 if (nfs_server_capable(dentry->d_inode, NFS_CAP_SECURITY_LABEL)) {
5766 len = security_inode_listsecurity(dentry->d_inode, NULL, 0);
5767 if (list && len <= list_len)
5768 security_inode_listsecurity(dentry->d_inode, list, len);
5773 static const struct xattr_handler nfs4_xattr_nfs4_label_handler = {
5774 .prefix = XATTR_SECURITY_PREFIX,
5775 .list = nfs4_xattr_list_nfs4_label,
5776 .get = nfs4_xattr_get_nfs4_label,
5777 .set = nfs4_xattr_set_nfs4_label,
5783 * nfs_fhget will use either the mounted_on_fileid or the fileid
5785 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5787 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5788 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5789 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5790 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5793 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5794 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5795 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5799 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5800 const struct qstr *name,
5801 struct nfs4_fs_locations *fs_locations,
5804 struct nfs_server *server = NFS_SERVER(dir);
5806 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5808 struct nfs4_fs_locations_arg args = {
5809 .dir_fh = NFS_FH(dir),
5814 struct nfs4_fs_locations_res res = {
5815 .fs_locations = fs_locations,
5817 struct rpc_message msg = {
5818 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5824 dprintk("%s: start\n", __func__);
5826 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5827 * is not supported */
5828 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5829 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5831 bitmask[0] |= FATTR4_WORD0_FILEID;
5833 nfs_fattr_init(&fs_locations->fattr);
5834 fs_locations->server = server;
5835 fs_locations->nlocations = 0;
5836 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5837 dprintk("%s: returned status = %d\n", __func__, status);
5841 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5842 const struct qstr *name,
5843 struct nfs4_fs_locations *fs_locations,
5846 struct nfs4_exception exception = { };
5849 err = _nfs4_proc_fs_locations(client, dir, name,
5850 fs_locations, page);
5851 trace_nfs4_get_fs_locations(dir, name, err);
5852 err = nfs4_handle_exception(NFS_SERVER(dir), err,
5854 } while (exception.retry);
5859 * If 'use_integrity' is true and the state managment nfs_client
5860 * cl_rpcclient is using krb5i/p, use the integrity protected cl_rpcclient
5861 * and the machine credential as per RFC3530bis and RFC5661 Security
5862 * Considerations sections. Otherwise, just use the user cred with the
5863 * filesystem's rpc_client.
5865 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors, bool use_integrity)
5868 struct nfs4_secinfo_arg args = {
5869 .dir_fh = NFS_FH(dir),
5872 struct nfs4_secinfo_res res = {
5875 struct rpc_message msg = {
5876 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
5880 struct rpc_clnt *clnt = NFS_SERVER(dir)->client;
5882 if (use_integrity) {
5883 clnt = NFS_SERVER(dir)->nfs_client->cl_rpcclient;
5884 msg.rpc_cred = nfs4_get_clid_cred(NFS_SERVER(dir)->nfs_client);
5887 dprintk("NFS call secinfo %s\n", name->name);
5888 status = nfs4_call_sync(clnt, NFS_SERVER(dir), &msg, &args.seq_args,
5890 dprintk("NFS reply secinfo: %d\n", status);
5893 put_rpccred(msg.rpc_cred);
5898 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
5899 struct nfs4_secinfo_flavors *flavors)
5901 struct nfs4_exception exception = { };
5904 err = -NFS4ERR_WRONGSEC;
5906 /* try to use integrity protection with machine cred */
5907 if (_nfs4_is_integrity_protected(NFS_SERVER(dir)->nfs_client))
5908 err = _nfs4_proc_secinfo(dir, name, flavors, true);
5911 * if unable to use integrity protection, or SECINFO with
5912 * integrity protection returns NFS4ERR_WRONGSEC (which is
5913 * disallowed by spec, but exists in deployed servers) use
5914 * the current filesystem's rpc_client and the user cred.
5916 if (err == -NFS4ERR_WRONGSEC)
5917 err = _nfs4_proc_secinfo(dir, name, flavors, false);
5919 trace_nfs4_secinfo(dir, name, err);
5920 err = nfs4_handle_exception(NFS_SERVER(dir), err,
5922 } while (exception.retry);
5926 #ifdef CONFIG_NFS_V4_1
5928 * Check the exchange flags returned by the server for invalid flags, having
5929 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5932 static int nfs4_check_cl_exchange_flags(u32 flags)
5934 if (flags & ~EXCHGID4_FLAG_MASK_R)
5936 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
5937 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
5939 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
5943 return -NFS4ERR_INVAL;
5947 nfs41_same_server_scope(struct nfs41_server_scope *a,
5948 struct nfs41_server_scope *b)
5950 if (a->server_scope_sz == b->server_scope_sz &&
5951 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5958 * nfs4_proc_bind_conn_to_session()
5960 * The 4.1 client currently uses the same TCP connection for the
5961 * fore and backchannel.
5963 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
5966 struct nfs41_bind_conn_to_session_res res;
5967 struct rpc_message msg = {
5969 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
5975 dprintk("--> %s\n", __func__);
5977 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5978 if (unlikely(res.session == NULL)) {
5983 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5984 trace_nfs4_bind_conn_to_session(clp, status);
5986 if (memcmp(res.session->sess_id.data,
5987 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
5988 dprintk("NFS: %s: Session ID mismatch\n", __func__);
5992 if (res.dir != NFS4_CDFS4_BOTH) {
5993 dprintk("NFS: %s: Unexpected direction from server\n",
5998 if (res.use_conn_in_rdma_mode) {
5999 dprintk("NFS: %s: Server returned RDMA mode = true\n",
6008 dprintk("<-- %s status= %d\n", __func__, status);
6013 * nfs4_proc_exchange_id()
6015 * Returns zero, a negative errno, or a negative NFS4ERR status code.
6017 * Since the clientid has expired, all compounds using sessions
6018 * associated with the stale clientid will be returning
6019 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
6020 * be in some phase of session reset.
6022 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
6024 nfs4_verifier verifier;
6025 struct nfs41_exchange_id_args args = {
6026 .verifier = &verifier,
6028 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER |
6029 EXCHGID4_FLAG_BIND_PRINC_STATEID,
6031 struct nfs41_exchange_id_res res = {
6035 struct rpc_message msg = {
6036 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
6042 nfs4_init_boot_verifier(clp, &verifier);
6043 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
6045 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
6046 clp->cl_rpcclient->cl_auth->au_ops->au_name,
6047 args.id_len, args.id);
6049 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
6051 if (unlikely(res.server_owner == NULL)) {
6056 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
6058 if (unlikely(res.server_scope == NULL)) {
6060 goto out_server_owner;
6063 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
6064 if (unlikely(res.impl_id == NULL)) {
6066 goto out_server_scope;
6069 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6070 trace_nfs4_exchange_id(clp, status);
6072 status = nfs4_check_cl_exchange_flags(res.flags);
6075 clp->cl_clientid = res.clientid;
6076 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
6077 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
6078 clp->cl_seqid = res.seqid;
6080 kfree(clp->cl_serverowner);
6081 clp->cl_serverowner = res.server_owner;
6082 res.server_owner = NULL;
6084 /* use the most recent implementation id */
6085 kfree(clp->cl_implid);
6086 clp->cl_implid = res.impl_id;
6088 if (clp->cl_serverscope != NULL &&
6089 !nfs41_same_server_scope(clp->cl_serverscope,
6090 res.server_scope)) {
6091 dprintk("%s: server_scope mismatch detected\n",
6093 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
6094 kfree(clp->cl_serverscope);
6095 clp->cl_serverscope = NULL;
6098 if (clp->cl_serverscope == NULL) {
6099 clp->cl_serverscope = res.server_scope;
6106 kfree(res.server_owner);
6108 kfree(res.server_scope);
6110 if (clp->cl_implid != NULL)
6111 dprintk("NFS reply exchange_id: Server Implementation ID: "
6112 "domain: %s, name: %s, date: %llu,%u\n",
6113 clp->cl_implid->domain, clp->cl_implid->name,
6114 clp->cl_implid->date.seconds,
6115 clp->cl_implid->date.nseconds);
6116 dprintk("NFS reply exchange_id: %d\n", status);
6120 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
6121 struct rpc_cred *cred)
6123 struct rpc_message msg = {
6124 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
6130 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6131 trace_nfs4_destroy_clientid(clp, status);
6133 dprintk("NFS: Got error %d from the server %s on "
6134 "DESTROY_CLIENTID.", status, clp->cl_hostname);
6138 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
6139 struct rpc_cred *cred)
6144 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
6145 ret = _nfs4_proc_destroy_clientid(clp, cred);
6147 case -NFS4ERR_DELAY:
6148 case -NFS4ERR_CLIENTID_BUSY:
6158 int nfs4_destroy_clientid(struct nfs_client *clp)
6160 struct rpc_cred *cred;
6163 if (clp->cl_mvops->minor_version < 1)
6165 if (clp->cl_exchange_flags == 0)
6167 if (clp->cl_preserve_clid)
6169 cred = nfs4_get_clid_cred(clp);
6170 ret = nfs4_proc_destroy_clientid(clp, cred);
6175 case -NFS4ERR_STALE_CLIENTID:
6176 clp->cl_exchange_flags = 0;
6182 struct nfs4_get_lease_time_data {
6183 struct nfs4_get_lease_time_args *args;
6184 struct nfs4_get_lease_time_res *res;
6185 struct nfs_client *clp;
6188 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
6191 struct nfs4_get_lease_time_data *data =
6192 (struct nfs4_get_lease_time_data *)calldata;
6194 dprintk("--> %s\n", __func__);
6195 /* just setup sequence, do not trigger session recovery
6196 since we're invoked within one */
6197 nfs41_setup_sequence(data->clp->cl_session,
6198 &data->args->la_seq_args,
6199 &data->res->lr_seq_res,
6201 dprintk("<-- %s\n", __func__);
6205 * Called from nfs4_state_manager thread for session setup, so don't recover
6206 * from sequence operation or clientid errors.
6208 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
6210 struct nfs4_get_lease_time_data *data =
6211 (struct nfs4_get_lease_time_data *)calldata;
6213 dprintk("--> %s\n", __func__);
6214 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
6216 switch (task->tk_status) {
6217 case -NFS4ERR_DELAY:
6218 case -NFS4ERR_GRACE:
6219 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
6220 rpc_delay(task, NFS4_POLL_RETRY_MIN);
6221 task->tk_status = 0;
6223 case -NFS4ERR_RETRY_UNCACHED_REP:
6224 rpc_restart_call_prepare(task);
6227 dprintk("<-- %s\n", __func__);
6230 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
6231 .rpc_call_prepare = nfs4_get_lease_time_prepare,
6232 .rpc_call_done = nfs4_get_lease_time_done,
6235 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
6237 struct rpc_task *task;
6238 struct nfs4_get_lease_time_args args;
6239 struct nfs4_get_lease_time_res res = {
6240 .lr_fsinfo = fsinfo,
6242 struct nfs4_get_lease_time_data data = {
6247 struct rpc_message msg = {
6248 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
6252 struct rpc_task_setup task_setup = {
6253 .rpc_client = clp->cl_rpcclient,
6254 .rpc_message = &msg,
6255 .callback_ops = &nfs4_get_lease_time_ops,
6256 .callback_data = &data,
6257 .flags = RPC_TASK_TIMEOUT,
6261 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
6262 nfs4_set_sequence_privileged(&args.la_seq_args);
6263 dprintk("--> %s\n", __func__);
6264 task = rpc_run_task(&task_setup);
6267 status = PTR_ERR(task);
6269 status = task->tk_status;
6272 dprintk("<-- %s return %d\n", __func__, status);
6278 * Initialize the values to be used by the client in CREATE_SESSION
6279 * If nfs4_init_session set the fore channel request and response sizes,
6282 * Set the back channel max_resp_sz_cached to zero to force the client to
6283 * always set csa_cachethis to FALSE because the current implementation
6284 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
6286 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
6288 unsigned int max_rqst_sz, max_resp_sz;
6290 max_rqst_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxwrite_overhead;
6291 max_resp_sz = NFS_MAX_FILE_IO_SIZE + nfs41_maxread_overhead;
6293 /* Fore channel attributes */
6294 args->fc_attrs.max_rqst_sz = max_rqst_sz;
6295 args->fc_attrs.max_resp_sz = max_resp_sz;
6296 args->fc_attrs.max_ops = NFS4_MAX_OPS;
6297 args->fc_attrs.max_reqs = max_session_slots;
6299 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
6300 "max_ops=%u max_reqs=%u\n",
6302 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
6303 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
6305 /* Back channel attributes */
6306 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
6307 args->bc_attrs.max_resp_sz = PAGE_SIZE;
6308 args->bc_attrs.max_resp_sz_cached = 0;
6309 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
6310 args->bc_attrs.max_reqs = 1;
6312 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
6313 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
6315 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
6316 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
6317 args->bc_attrs.max_reqs);
6320 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
6322 struct nfs4_channel_attrs *sent = &args->fc_attrs;
6323 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
6325 if (rcvd->max_resp_sz > sent->max_resp_sz)
6328 * Our requested max_ops is the minimum we need; we're not
6329 * prepared to break up compounds into smaller pieces than that.
6330 * So, no point even trying to continue if the server won't
6333 if (rcvd->max_ops < sent->max_ops)
6335 if (rcvd->max_reqs == 0)
6337 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
6338 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
6342 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
6344 struct nfs4_channel_attrs *sent = &args->bc_attrs;
6345 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
6347 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
6349 if (rcvd->max_resp_sz < sent->max_resp_sz)
6351 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
6353 /* These would render the backchannel useless: */
6354 if (rcvd->max_ops != sent->max_ops)
6356 if (rcvd->max_reqs != sent->max_reqs)
6361 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
6362 struct nfs4_session *session)
6366 ret = nfs4_verify_fore_channel_attrs(args, session);
6369 return nfs4_verify_back_channel_attrs(args, session);
6372 static int _nfs4_proc_create_session(struct nfs_client *clp,
6373 struct rpc_cred *cred)
6375 struct nfs4_session *session = clp->cl_session;
6376 struct nfs41_create_session_args args = {
6378 .cb_program = NFS4_CALLBACK,
6380 struct nfs41_create_session_res res = {
6383 struct rpc_message msg = {
6384 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
6391 nfs4_init_channel_attrs(&args);
6392 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
6394 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6395 trace_nfs4_create_session(clp, status);
6398 /* Verify the session's negotiated channel_attrs values */
6399 status = nfs4_verify_channel_attrs(&args, session);
6400 /* Increment the clientid slot sequence id */
6408 * Issues a CREATE_SESSION operation to the server.
6409 * It is the responsibility of the caller to verify the session is
6410 * expired before calling this routine.
6412 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
6416 struct nfs4_session *session = clp->cl_session;
6418 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
6420 status = _nfs4_proc_create_session(clp, cred);
6424 /* Init or reset the session slot tables */
6425 status = nfs4_setup_session_slot_tables(session);
6426 dprintk("slot table setup returned %d\n", status);
6430 ptr = (unsigned *)&session->sess_id.data[0];
6431 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
6432 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
6434 dprintk("<-- %s\n", __func__);
6439 * Issue the over-the-wire RPC DESTROY_SESSION.
6440 * The caller must serialize access to this routine.
6442 int nfs4_proc_destroy_session(struct nfs4_session *session,
6443 struct rpc_cred *cred)
6445 struct rpc_message msg = {
6446 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
6447 .rpc_argp = session,
6452 dprintk("--> nfs4_proc_destroy_session\n");
6454 /* session is still being setup */
6455 if (session->clp->cl_cons_state != NFS_CS_READY)
6458 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
6459 trace_nfs4_destroy_session(session->clp, status);
6462 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
6463 "Session has been destroyed regardless...\n", status);
6465 dprintk("<-- nfs4_proc_destroy_session\n");
6470 * Renew the cl_session lease.
6472 struct nfs4_sequence_data {
6473 struct nfs_client *clp;
6474 struct nfs4_sequence_args args;
6475 struct nfs4_sequence_res res;
6478 static void nfs41_sequence_release(void *data)
6480 struct nfs4_sequence_data *calldata = data;
6481 struct nfs_client *clp = calldata->clp;
6483 if (atomic_read(&clp->cl_count) > 1)
6484 nfs4_schedule_state_renewal(clp);
6485 nfs_put_client(clp);
6489 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6491 switch(task->tk_status) {
6492 case -NFS4ERR_DELAY:
6493 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6496 nfs4_schedule_lease_recovery(clp);
6501 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
6503 struct nfs4_sequence_data *calldata = data;
6504 struct nfs_client *clp = calldata->clp;
6506 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
6509 trace_nfs4_sequence(clp, task->tk_status);
6510 if (task->tk_status < 0) {
6511 dprintk("%s ERROR %d\n", __func__, task->tk_status);
6512 if (atomic_read(&clp->cl_count) == 1)
6515 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
6516 rpc_restart_call_prepare(task);
6520 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
6522 dprintk("<-- %s\n", __func__);
6525 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
6527 struct nfs4_sequence_data *calldata = data;
6528 struct nfs_client *clp = calldata->clp;
6529 struct nfs4_sequence_args *args;
6530 struct nfs4_sequence_res *res;
6532 args = task->tk_msg.rpc_argp;
6533 res = task->tk_msg.rpc_resp;
6535 nfs41_setup_sequence(clp->cl_session, args, res, task);
6538 static const struct rpc_call_ops nfs41_sequence_ops = {
6539 .rpc_call_done = nfs41_sequence_call_done,
6540 .rpc_call_prepare = nfs41_sequence_prepare,
6541 .rpc_release = nfs41_sequence_release,
6544 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
6545 struct rpc_cred *cred,
6548 struct nfs4_sequence_data *calldata;
6549 struct rpc_message msg = {
6550 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
6553 struct rpc_task_setup task_setup_data = {
6554 .rpc_client = clp->cl_rpcclient,
6555 .rpc_message = &msg,
6556 .callback_ops = &nfs41_sequence_ops,
6557 .flags = RPC_TASK_ASYNC | RPC_TASK_TIMEOUT,
6560 if (!atomic_inc_not_zero(&clp->cl_count))
6561 return ERR_PTR(-EIO);
6562 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6563 if (calldata == NULL) {
6564 nfs_put_client(clp);
6565 return ERR_PTR(-ENOMEM);
6567 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
6569 nfs4_set_sequence_privileged(&calldata->args);
6570 msg.rpc_argp = &calldata->args;
6571 msg.rpc_resp = &calldata->res;
6572 calldata->clp = clp;
6573 task_setup_data.callback_data = calldata;
6575 return rpc_run_task(&task_setup_data);
6578 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
6580 struct rpc_task *task;
6583 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
6585 task = _nfs41_proc_sequence(clp, cred, false);
6587 ret = PTR_ERR(task);
6589 rpc_put_task_async(task);
6590 dprintk("<-- %s status=%d\n", __func__, ret);
6594 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
6596 struct rpc_task *task;
6599 task = _nfs41_proc_sequence(clp, cred, true);
6601 ret = PTR_ERR(task);
6604 ret = rpc_wait_for_completion_task(task);
6606 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
6608 if (task->tk_status == 0)
6609 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
6610 ret = task->tk_status;
6614 dprintk("<-- %s status=%d\n", __func__, ret);
6618 struct nfs4_reclaim_complete_data {
6619 struct nfs_client *clp;
6620 struct nfs41_reclaim_complete_args arg;
6621 struct nfs41_reclaim_complete_res res;
6624 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
6626 struct nfs4_reclaim_complete_data *calldata = data;
6628 nfs41_setup_sequence(calldata->clp->cl_session,
6629 &calldata->arg.seq_args,
6630 &calldata->res.seq_res,
6634 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6636 switch(task->tk_status) {
6638 case -NFS4ERR_COMPLETE_ALREADY:
6639 case -NFS4ERR_WRONG_CRED: /* What to do here? */
6641 case -NFS4ERR_DELAY:
6642 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6644 case -NFS4ERR_RETRY_UNCACHED_REP:
6647 nfs4_schedule_lease_recovery(clp);
6652 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
6654 struct nfs4_reclaim_complete_data *calldata = data;
6655 struct nfs_client *clp = calldata->clp;
6656 struct nfs4_sequence_res *res = &calldata->res.seq_res;
6658 dprintk("--> %s\n", __func__);
6659 if (!nfs41_sequence_done(task, res))
6662 trace_nfs4_reclaim_complete(clp, task->tk_status);
6663 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
6664 rpc_restart_call_prepare(task);
6667 dprintk("<-- %s\n", __func__);
6670 static void nfs4_free_reclaim_complete_data(void *data)
6672 struct nfs4_reclaim_complete_data *calldata = data;
6677 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6678 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
6679 .rpc_call_done = nfs4_reclaim_complete_done,
6680 .rpc_release = nfs4_free_reclaim_complete_data,
6684 * Issue a global reclaim complete.
6686 static int nfs41_proc_reclaim_complete(struct nfs_client *clp,
6687 struct rpc_cred *cred)
6689 struct nfs4_reclaim_complete_data *calldata;
6690 struct rpc_task *task;
6691 struct rpc_message msg = {
6692 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
6695 struct rpc_task_setup task_setup_data = {
6696 .rpc_client = clp->cl_rpcclient,
6697 .rpc_message = &msg,
6698 .callback_ops = &nfs4_reclaim_complete_call_ops,
6699 .flags = RPC_TASK_ASYNC,
6701 int status = -ENOMEM;
6703 dprintk("--> %s\n", __func__);
6704 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6705 if (calldata == NULL)
6707 calldata->clp = clp;
6708 calldata->arg.one_fs = 0;
6710 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6711 nfs4_set_sequence_privileged(&calldata->arg.seq_args);
6712 msg.rpc_argp = &calldata->arg;
6713 msg.rpc_resp = &calldata->res;
6714 task_setup_data.callback_data = calldata;
6715 task = rpc_run_task(&task_setup_data);
6717 status = PTR_ERR(task);
6720 status = nfs4_wait_for_completion_rpc_task(task);
6722 status = task->tk_status;
6726 dprintk("<-- %s status=%d\n", __func__, status);
6731 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
6733 struct nfs4_layoutget *lgp = calldata;
6734 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6735 struct nfs4_session *session = nfs4_get_session(server);
6737 dprintk("--> %s\n", __func__);
6738 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6739 * right now covering the LAYOUTGET we are about to send.
6740 * However, that is not so catastrophic, and there seems
6741 * to be no way to prevent it completely.
6743 if (nfs41_setup_sequence(session, &lgp->args.seq_args,
6744 &lgp->res.seq_res, task))
6746 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
6747 NFS_I(lgp->args.inode)->layout,
6748 lgp->args.ctx->state)) {
6749 rpc_exit(task, NFS4_OK);
6753 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
6755 struct nfs4_layoutget *lgp = calldata;
6756 struct inode *inode = lgp->args.inode;
6757 struct nfs_server *server = NFS_SERVER(inode);
6758 struct pnfs_layout_hdr *lo;
6759 struct nfs4_state *state = NULL;
6760 unsigned long timeo, giveup;
6762 dprintk("--> %s\n", __func__);
6764 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
6767 switch (task->tk_status) {
6770 case -NFS4ERR_LAYOUTTRYLATER:
6771 case -NFS4ERR_RECALLCONFLICT:
6772 timeo = rpc_get_timeout(task->tk_client);
6773 giveup = lgp->args.timestamp + timeo;
6774 if (time_after(giveup, jiffies))
6775 task->tk_status = -NFS4ERR_DELAY;
6777 case -NFS4ERR_EXPIRED:
6778 case -NFS4ERR_BAD_STATEID:
6779 spin_lock(&inode->i_lock);
6780 lo = NFS_I(inode)->layout;
6781 if (!lo || list_empty(&lo->plh_segs)) {
6782 spin_unlock(&inode->i_lock);
6783 /* If the open stateid was bad, then recover it. */
6784 state = lgp->args.ctx->state;
6788 pnfs_mark_matching_lsegs_invalid(lo, &head, NULL);
6789 spin_unlock(&inode->i_lock);
6790 /* Mark the bad layout state as invalid, then
6791 * retry using the open stateid. */
6792 pnfs_free_lseg_list(&head);
6795 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
6796 rpc_restart_call_prepare(task);
6798 dprintk("<-- %s\n", __func__);
6801 static size_t max_response_pages(struct nfs_server *server)
6803 u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
6804 return nfs_page_array_len(0, max_resp_sz);
6807 static void nfs4_free_pages(struct page **pages, size_t size)
6814 for (i = 0; i < size; i++) {
6817 __free_page(pages[i]);
6822 static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
6824 struct page **pages;
6827 pages = kcalloc(size, sizeof(struct page *), gfp_flags);
6829 dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
6833 for (i = 0; i < size; i++) {
6834 pages[i] = alloc_page(gfp_flags);
6836 dprintk("%s: failed to allocate page\n", __func__);
6837 nfs4_free_pages(pages, size);
6845 static void nfs4_layoutget_release(void *calldata)
6847 struct nfs4_layoutget *lgp = calldata;
6848 struct inode *inode = lgp->args.inode;
6849 struct nfs_server *server = NFS_SERVER(inode);
6850 size_t max_pages = max_response_pages(server);
6852 dprintk("--> %s\n", __func__);
6853 nfs4_free_pages(lgp->args.layout.pages, max_pages);
6854 pnfs_put_layout_hdr(NFS_I(inode)->layout);
6855 put_nfs_open_context(lgp->args.ctx);
6857 dprintk("<-- %s\n", __func__);
6860 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6861 .rpc_call_prepare = nfs4_layoutget_prepare,
6862 .rpc_call_done = nfs4_layoutget_done,
6863 .rpc_release = nfs4_layoutget_release,
6866 struct pnfs_layout_segment *
6867 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)
6869 struct inode *inode = lgp->args.inode;
6870 struct nfs_server *server = NFS_SERVER(inode);
6871 size_t max_pages = max_response_pages(server);
6872 struct rpc_task *task;
6873 struct rpc_message msg = {
6874 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
6875 .rpc_argp = &lgp->args,
6876 .rpc_resp = &lgp->res,
6877 .rpc_cred = lgp->cred,
6879 struct rpc_task_setup task_setup_data = {
6880 .rpc_client = server->client,
6881 .rpc_message = &msg,
6882 .callback_ops = &nfs4_layoutget_call_ops,
6883 .callback_data = lgp,
6884 .flags = RPC_TASK_ASYNC,
6886 struct pnfs_layout_segment *lseg = NULL;
6889 dprintk("--> %s\n", __func__);
6891 lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
6892 if (!lgp->args.layout.pages) {
6893 nfs4_layoutget_release(lgp);
6894 return ERR_PTR(-ENOMEM);
6896 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
6897 lgp->args.timestamp = jiffies;
6899 lgp->res.layoutp = &lgp->args.layout;
6900 lgp->res.seq_res.sr_slot = NULL;
6901 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
6903 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6904 pnfs_get_layout_hdr(NFS_I(inode)->layout);
6906 task = rpc_run_task(&task_setup_data);
6908 return ERR_CAST(task);
6909 status = nfs4_wait_for_completion_rpc_task(task);
6911 status = task->tk_status;
6912 trace_nfs4_layoutget(lgp->args.ctx,
6916 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6917 if (status == 0 && lgp->res.layoutp->len)
6918 lseg = pnfs_layout_process(lgp);
6920 dprintk("<-- %s status=%d\n", __func__, status);
6922 return ERR_PTR(status);
6927 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
6929 struct nfs4_layoutreturn *lrp = calldata;
6931 dprintk("--> %s\n", __func__);
6932 nfs41_setup_sequence(lrp->clp->cl_session,
6933 &lrp->args.seq_args,
6938 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
6940 struct nfs4_layoutreturn *lrp = calldata;
6941 struct nfs_server *server;
6943 dprintk("--> %s\n", __func__);
6945 if (!nfs41_sequence_done(task, &lrp->res.seq_res))
6948 server = NFS_SERVER(lrp->args.inode);
6949 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6950 rpc_restart_call_prepare(task);
6953 dprintk("<-- %s\n", __func__);
6956 static void nfs4_layoutreturn_release(void *calldata)
6958 struct nfs4_layoutreturn *lrp = calldata;
6959 struct pnfs_layout_hdr *lo = lrp->args.layout;
6961 dprintk("--> %s\n", __func__);
6962 spin_lock(&lo->plh_inode->i_lock);
6963 if (lrp->res.lrs_present)
6964 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
6965 lo->plh_block_lgets--;
6966 spin_unlock(&lo->plh_inode->i_lock);
6967 pnfs_put_layout_hdr(lrp->args.layout);
6969 dprintk("<-- %s\n", __func__);
6972 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6973 .rpc_call_prepare = nfs4_layoutreturn_prepare,
6974 .rpc_call_done = nfs4_layoutreturn_done,
6975 .rpc_release = nfs4_layoutreturn_release,
6978 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
6980 struct rpc_task *task;
6981 struct rpc_message msg = {
6982 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
6983 .rpc_argp = &lrp->args,
6984 .rpc_resp = &lrp->res,
6985 .rpc_cred = lrp->cred,
6987 struct rpc_task_setup task_setup_data = {
6988 .rpc_client = NFS_SERVER(lrp->args.inode)->client,
6989 .rpc_message = &msg,
6990 .callback_ops = &nfs4_layoutreturn_call_ops,
6991 .callback_data = lrp,
6995 dprintk("--> %s\n", __func__);
6996 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
6997 task = rpc_run_task(&task_setup_data);
6999 return PTR_ERR(task);
7000 status = task->tk_status;
7001 trace_nfs4_layoutreturn(lrp->args.inode, status);
7002 dprintk("<-- %s status=%d\n", __func__, status);
7008 * Retrieve the list of Data Server devices from the MDS.
7010 static int _nfs4_getdevicelist(struct nfs_server *server,
7011 const struct nfs_fh *fh,
7012 struct pnfs_devicelist *devlist)
7014 struct nfs4_getdevicelist_args args = {
7016 .layoutclass = server->pnfs_curr_ld->id,
7018 struct nfs4_getdevicelist_res res = {
7021 struct rpc_message msg = {
7022 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
7028 dprintk("--> %s\n", __func__);
7029 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
7031 dprintk("<-- %s status=%d\n", __func__, status);
7035 int nfs4_proc_getdevicelist(struct nfs_server *server,
7036 const struct nfs_fh *fh,
7037 struct pnfs_devicelist *devlist)
7039 struct nfs4_exception exception = { };
7043 err = nfs4_handle_exception(server,
7044 _nfs4_getdevicelist(server, fh, devlist),
7046 } while (exception.retry);
7048 dprintk("%s: err=%d, num_devs=%u\n", __func__,
7049 err, devlist->num_devs);
7053 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
7056 _nfs4_proc_getdeviceinfo(struct nfs_server *server,
7057 struct pnfs_device *pdev,
7058 struct rpc_cred *cred)
7060 struct nfs4_getdeviceinfo_args args = {
7063 struct nfs4_getdeviceinfo_res res = {
7066 struct rpc_message msg = {
7067 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
7074 dprintk("--> %s\n", __func__);
7075 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
7076 dprintk("<-- %s status=%d\n", __func__, status);
7081 int nfs4_proc_getdeviceinfo(struct nfs_server *server,
7082 struct pnfs_device *pdev,
7083 struct rpc_cred *cred)
7085 struct nfs4_exception exception = { };
7089 err = nfs4_handle_exception(server,
7090 _nfs4_proc_getdeviceinfo(server, pdev, cred),
7092 } while (exception.retry);
7095 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
7097 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
7099 struct nfs4_layoutcommit_data *data = calldata;
7100 struct nfs_server *server = NFS_SERVER(data->args.inode);
7101 struct nfs4_session *session = nfs4_get_session(server);
7103 nfs41_setup_sequence(session,
7104 &data->args.seq_args,
7110 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
7112 struct nfs4_layoutcommit_data *data = calldata;
7113 struct nfs_server *server = NFS_SERVER(data->args.inode);
7115 if (!nfs41_sequence_done(task, &data->res.seq_res))
7118 switch (task->tk_status) { /* Just ignore these failures */
7119 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
7120 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
7121 case -NFS4ERR_BADLAYOUT: /* no layout */
7122 case -NFS4ERR_GRACE: /* loca_recalim always false */
7123 task->tk_status = 0;
7126 nfs_post_op_update_inode_force_wcc(data->args.inode,
7130 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
7131 rpc_restart_call_prepare(task);
7137 static void nfs4_layoutcommit_release(void *calldata)
7139 struct nfs4_layoutcommit_data *data = calldata;
7141 pnfs_cleanup_layoutcommit(data);
7142 put_rpccred(data->cred);
7146 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
7147 .rpc_call_prepare = nfs4_layoutcommit_prepare,
7148 .rpc_call_done = nfs4_layoutcommit_done,
7149 .rpc_release = nfs4_layoutcommit_release,
7153 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
7155 struct rpc_message msg = {
7156 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
7157 .rpc_argp = &data->args,
7158 .rpc_resp = &data->res,
7159 .rpc_cred = data->cred,
7161 struct rpc_task_setup task_setup_data = {
7162 .task = &data->task,
7163 .rpc_client = NFS_CLIENT(data->args.inode),
7164 .rpc_message = &msg,
7165 .callback_ops = &nfs4_layoutcommit_ops,
7166 .callback_data = data,
7167 .flags = RPC_TASK_ASYNC,
7169 struct rpc_task *task;
7172 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
7173 "lbw: %llu inode %lu\n",
7174 data->task.tk_pid, sync,
7175 data->args.lastbytewritten,
7176 data->args.inode->i_ino);
7178 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
7179 task = rpc_run_task(&task_setup_data);
7181 return PTR_ERR(task);
7184 status = nfs4_wait_for_completion_rpc_task(task);
7187 status = task->tk_status;
7188 trace_nfs4_layoutcommit(data->args.inode, status);
7190 dprintk("%s: status %d\n", __func__, status);
7196 * Use the state managment nfs_client cl_rpcclient, which uses krb5i (if
7197 * possible) as per RFC3530bis and RFC5661 Security Considerations sections
7200 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
7201 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
7203 struct nfs41_secinfo_no_name_args args = {
7204 .style = SECINFO_STYLE_CURRENT_FH,
7206 struct nfs4_secinfo_res res = {
7209 struct rpc_message msg = {
7210 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
7214 return nfs4_call_sync(server->nfs_client->cl_rpcclient, server, &msg,
7215 &args.seq_args, &res.seq_res, 0);
7219 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
7220 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
7222 struct nfs4_exception exception = { };
7225 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
7228 case -NFS4ERR_WRONGSEC:
7229 case -NFS4ERR_NOTSUPP:
7232 err = nfs4_handle_exception(server, err, &exception);
7234 } while (exception.retry);
7240 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
7241 struct nfs_fsinfo *info)
7245 rpc_authflavor_t flavor;
7246 struct nfs4_secinfo_flavors *flavors;
7248 page = alloc_page(GFP_KERNEL);
7254 flavors = page_address(page);
7255 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
7258 * Fall back on "guess and check" method if
7259 * the server doesn't support SECINFO_NO_NAME
7261 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
7262 err = nfs4_find_root_sec(server, fhandle, info);
7268 flavor = nfs_find_best_sec(flavors);
7270 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
7280 static int _nfs41_test_stateid(struct nfs_server *server,
7281 nfs4_stateid *stateid,
7282 struct rpc_cred *cred)
7285 struct nfs41_test_stateid_args args = {
7288 struct nfs41_test_stateid_res res;
7289 struct rpc_message msg = {
7290 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
7296 dprintk("NFS call test_stateid %p\n", stateid);
7297 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
7298 nfs4_set_sequence_privileged(&args.seq_args);
7299 status = nfs4_call_sync_sequence(server->client, server, &msg,
7300 &args.seq_args, &res.seq_res);
7301 if (status != NFS_OK) {
7302 dprintk("NFS reply test_stateid: failed, %d\n", status);
7305 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
7310 * nfs41_test_stateid - perform a TEST_STATEID operation
7312 * @server: server / transport on which to perform the operation
7313 * @stateid: state ID to test
7316 * Returns NFS_OK if the server recognizes that "stateid" is valid.
7317 * Otherwise a negative NFS4ERR value is returned if the operation
7318 * failed or the state ID is not currently valid.
7320 static int nfs41_test_stateid(struct nfs_server *server,
7321 nfs4_stateid *stateid,
7322 struct rpc_cred *cred)
7324 struct nfs4_exception exception = { };
7327 err = _nfs41_test_stateid(server, stateid, cred);
7328 if (err != -NFS4ERR_DELAY)
7330 nfs4_handle_exception(server, err, &exception);
7331 } while (exception.retry);
7335 struct nfs_free_stateid_data {
7336 struct nfs_server *server;
7337 struct nfs41_free_stateid_args args;
7338 struct nfs41_free_stateid_res res;
7341 static void nfs41_free_stateid_prepare(struct rpc_task *task, void *calldata)
7343 struct nfs_free_stateid_data *data = calldata;
7344 nfs41_setup_sequence(nfs4_get_session(data->server),
7345 &data->args.seq_args,
7350 static void nfs41_free_stateid_done(struct rpc_task *task, void *calldata)
7352 struct nfs_free_stateid_data *data = calldata;
7354 nfs41_sequence_done(task, &data->res.seq_res);
7356 switch (task->tk_status) {
7357 case -NFS4ERR_DELAY:
7358 if (nfs4_async_handle_error(task, data->server, NULL) == -EAGAIN)
7359 rpc_restart_call_prepare(task);
7363 static void nfs41_free_stateid_release(void *calldata)
7368 static const struct rpc_call_ops nfs41_free_stateid_ops = {
7369 .rpc_call_prepare = nfs41_free_stateid_prepare,
7370 .rpc_call_done = nfs41_free_stateid_done,
7371 .rpc_release = nfs41_free_stateid_release,
7374 static struct rpc_task *_nfs41_free_stateid(struct nfs_server *server,
7375 nfs4_stateid *stateid,
7376 struct rpc_cred *cred,
7379 struct rpc_message msg = {
7380 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
7383 struct rpc_task_setup task_setup = {
7384 .rpc_client = server->client,
7385 .rpc_message = &msg,
7386 .callback_ops = &nfs41_free_stateid_ops,
7387 .flags = RPC_TASK_ASYNC,
7389 struct nfs_free_stateid_data *data;
7391 dprintk("NFS call free_stateid %p\n", stateid);
7392 data = kmalloc(sizeof(*data), GFP_NOFS);
7394 return ERR_PTR(-ENOMEM);
7395 data->server = server;
7396 nfs4_stateid_copy(&data->args.stateid, stateid);
7398 task_setup.callback_data = data;
7400 msg.rpc_argp = &data->args;
7401 msg.rpc_resp = &data->res;
7402 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
7404 nfs4_set_sequence_privileged(&data->args.seq_args);
7406 return rpc_run_task(&task_setup);
7410 * nfs41_free_stateid - perform a FREE_STATEID operation
7412 * @server: server / transport on which to perform the operation
7413 * @stateid: state ID to release
7416 * Returns NFS_OK if the server freed "stateid". Otherwise a
7417 * negative NFS4ERR value is returned.
7419 static int nfs41_free_stateid(struct nfs_server *server,
7420 nfs4_stateid *stateid,
7421 struct rpc_cred *cred)
7423 struct rpc_task *task;
7426 task = _nfs41_free_stateid(server, stateid, cred, true);
7428 return PTR_ERR(task);
7429 ret = rpc_wait_for_completion_task(task);
7431 ret = task->tk_status;
7436 static int nfs41_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
7438 struct rpc_task *task;
7439 struct rpc_cred *cred = lsp->ls_state->owner->so_cred;
7441 task = _nfs41_free_stateid(server, &lsp->ls_stateid, cred, false);
7442 nfs4_free_lock_state(server, lsp);
7444 return PTR_ERR(task);
7449 static bool nfs41_match_stateid(const nfs4_stateid *s1,
7450 const nfs4_stateid *s2)
7452 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
7455 if (s1->seqid == s2->seqid)
7457 if (s1->seqid == 0 || s2->seqid == 0)
7463 #endif /* CONFIG_NFS_V4_1 */
7465 static bool nfs4_match_stateid(const nfs4_stateid *s1,
7466 const nfs4_stateid *s2)
7468 return nfs4_stateid_match(s1, s2);
7472 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
7473 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
7474 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
7475 .recover_open = nfs4_open_reclaim,
7476 .recover_lock = nfs4_lock_reclaim,
7477 .establish_clid = nfs4_init_clientid,
7478 .detect_trunking = nfs40_discover_server_trunking,
7481 #if defined(CONFIG_NFS_V4_1)
7482 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
7483 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
7484 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
7485 .recover_open = nfs4_open_reclaim,
7486 .recover_lock = nfs4_lock_reclaim,
7487 .establish_clid = nfs41_init_clientid,
7488 .reclaim_complete = nfs41_proc_reclaim_complete,
7489 .detect_trunking = nfs41_discover_server_trunking,
7491 #endif /* CONFIG_NFS_V4_1 */
7493 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
7494 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
7495 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
7496 .recover_open = nfs4_open_expired,
7497 .recover_lock = nfs4_lock_expired,
7498 .establish_clid = nfs4_init_clientid,
7501 #if defined(CONFIG_NFS_V4_1)
7502 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
7503 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
7504 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
7505 .recover_open = nfs41_open_expired,
7506 .recover_lock = nfs41_lock_expired,
7507 .establish_clid = nfs41_init_clientid,
7509 #endif /* CONFIG_NFS_V4_1 */
7511 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
7512 .sched_state_renewal = nfs4_proc_async_renew,
7513 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
7514 .renew_lease = nfs4_proc_renew,
7517 #if defined(CONFIG_NFS_V4_1)
7518 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
7519 .sched_state_renewal = nfs41_proc_async_sequence,
7520 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
7521 .renew_lease = nfs4_proc_sequence,
7525 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
7527 .init_caps = NFS_CAP_READDIRPLUS
7528 | NFS_CAP_ATOMIC_OPEN
7529 | NFS_CAP_CHANGE_ATTR
7530 | NFS_CAP_POSIX_LOCK,
7531 .call_sync = _nfs4_call_sync,
7532 .match_stateid = nfs4_match_stateid,
7533 .find_root_sec = nfs4_find_root_sec,
7534 .free_lock_state = nfs4_release_lockowner,
7535 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
7536 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
7537 .state_renewal_ops = &nfs40_state_renewal_ops,
7540 #if defined(CONFIG_NFS_V4_1)
7541 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
7543 .init_caps = NFS_CAP_READDIRPLUS
7544 | NFS_CAP_ATOMIC_OPEN
7545 | NFS_CAP_CHANGE_ATTR
7546 | NFS_CAP_POSIX_LOCK
7547 | NFS_CAP_STATEID_NFSV41
7548 | NFS_CAP_ATOMIC_OPEN_V1,
7549 .call_sync = nfs4_call_sync_sequence,
7550 .match_stateid = nfs41_match_stateid,
7551 .find_root_sec = nfs41_find_root_sec,
7552 .free_lock_state = nfs41_free_lock_state,
7553 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
7554 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
7555 .state_renewal_ops = &nfs41_state_renewal_ops,
7559 #if defined(CONFIG_NFS_V4_2)
7560 static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
7562 .init_caps = NFS_CAP_READDIRPLUS
7563 | NFS_CAP_ATOMIC_OPEN
7564 | NFS_CAP_CHANGE_ATTR
7565 | NFS_CAP_POSIX_LOCK
7566 | NFS_CAP_STATEID_NFSV41
7567 | NFS_CAP_ATOMIC_OPEN_V1,
7568 .call_sync = nfs4_call_sync_sequence,
7569 .match_stateid = nfs41_match_stateid,
7570 .find_root_sec = nfs41_find_root_sec,
7571 .free_lock_state = nfs41_free_lock_state,
7572 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
7573 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
7574 .state_renewal_ops = &nfs41_state_renewal_ops,
7578 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
7579 [0] = &nfs_v4_0_minor_ops,
7580 #if defined(CONFIG_NFS_V4_1)
7581 [1] = &nfs_v4_1_minor_ops,
7583 #if defined(CONFIG_NFS_V4_2)
7584 [2] = &nfs_v4_2_minor_ops,
7588 static const struct inode_operations nfs4_dir_inode_operations = {
7589 .create = nfs_create,
7590 .lookup = nfs_lookup,
7591 .atomic_open = nfs_atomic_open,
7593 .unlink = nfs_unlink,
7594 .symlink = nfs_symlink,
7598 .rename = nfs_rename,
7599 .permission = nfs_permission,
7600 .getattr = nfs_getattr,
7601 .setattr = nfs_setattr,
7602 .getxattr = generic_getxattr,
7603 .setxattr = generic_setxattr,
7604 .listxattr = generic_listxattr,
7605 .removexattr = generic_removexattr,
7608 static const struct inode_operations nfs4_file_inode_operations = {
7609 .permission = nfs_permission,
7610 .getattr = nfs_getattr,
7611 .setattr = nfs_setattr,
7612 .getxattr = generic_getxattr,
7613 .setxattr = generic_setxattr,
7614 .listxattr = generic_listxattr,
7615 .removexattr = generic_removexattr,
7618 const struct nfs_rpc_ops nfs_v4_clientops = {
7619 .version = 4, /* protocol version */
7620 .dentry_ops = &nfs4_dentry_operations,
7621 .dir_inode_ops = &nfs4_dir_inode_operations,
7622 .file_inode_ops = &nfs4_file_inode_operations,
7623 .file_ops = &nfs4_file_operations,
7624 .getroot = nfs4_proc_get_root,
7625 .submount = nfs4_submount,
7626 .try_mount = nfs4_try_mount,
7627 .getattr = nfs4_proc_getattr,
7628 .setattr = nfs4_proc_setattr,
7629 .lookup = nfs4_proc_lookup,
7630 .access = nfs4_proc_access,
7631 .readlink = nfs4_proc_readlink,
7632 .create = nfs4_proc_create,
7633 .remove = nfs4_proc_remove,
7634 .unlink_setup = nfs4_proc_unlink_setup,
7635 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
7636 .unlink_done = nfs4_proc_unlink_done,
7637 .rename = nfs4_proc_rename,
7638 .rename_setup = nfs4_proc_rename_setup,
7639 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
7640 .rename_done = nfs4_proc_rename_done,
7641 .link = nfs4_proc_link,
7642 .symlink = nfs4_proc_symlink,
7643 .mkdir = nfs4_proc_mkdir,
7644 .rmdir = nfs4_proc_remove,
7645 .readdir = nfs4_proc_readdir,
7646 .mknod = nfs4_proc_mknod,
7647 .statfs = nfs4_proc_statfs,
7648 .fsinfo = nfs4_proc_fsinfo,
7649 .pathconf = nfs4_proc_pathconf,
7650 .set_capabilities = nfs4_server_capabilities,
7651 .decode_dirent = nfs4_decode_dirent,
7652 .read_setup = nfs4_proc_read_setup,
7653 .read_pageio_init = pnfs_pageio_init_read,
7654 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
7655 .read_done = nfs4_read_done,
7656 .write_setup = nfs4_proc_write_setup,
7657 .write_pageio_init = pnfs_pageio_init_write,
7658 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
7659 .write_done = nfs4_write_done,
7660 .commit_setup = nfs4_proc_commit_setup,
7661 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
7662 .commit_done = nfs4_commit_done,
7663 .lock = nfs4_proc_lock,
7664 .clear_acl_cache = nfs4_zap_acl_attr,
7665 .close_context = nfs4_close_context,
7666 .open_context = nfs4_atomic_open,
7667 .have_delegation = nfs4_have_delegation,
7668 .return_delegation = nfs4_inode_return_delegation,
7669 .alloc_client = nfs4_alloc_client,
7670 .init_client = nfs4_init_client,
7671 .free_client = nfs4_free_client,
7672 .create_server = nfs4_create_server,
7673 .clone_server = nfs_clone_server,
7676 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
7677 .prefix = XATTR_NAME_NFSV4_ACL,
7678 .list = nfs4_xattr_list_nfs4_acl,
7679 .get = nfs4_xattr_get_nfs4_acl,
7680 .set = nfs4_xattr_set_nfs4_acl,
7683 const struct xattr_handler *nfs4_xattr_handlers[] = {
7684 &nfs4_xattr_nfs4_acl_handler,
7685 #ifdef CONFIG_NFS_V4_SECURITY_LABEL
7686 &nfs4_xattr_nfs4_label_handler,