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 #define NFSDBG_FACILITY NFSDBG_PROC
71 #define NFS4_POLL_RETRY_MIN (HZ/10)
72 #define NFS4_POLL_RETRY_MAX (15*HZ)
75 static int _nfs4_proc_open(struct nfs4_opendata *data);
76 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
77 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
78 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
79 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
80 static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *);
81 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
82 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
83 struct nfs_fattr *fattr, struct iattr *sattr,
84 struct nfs4_state *state);
85 #ifdef CONFIG_NFS_V4_1
86 static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *);
87 static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *);
89 /* Prevent leaks of NFSv4 errors into userland */
90 static int nfs4_map_errors(int err)
95 case -NFS4ERR_RESOURCE:
96 case -NFS4ERR_LAYOUTTRYLATER:
97 case -NFS4ERR_RECALLCONFLICT:
99 case -NFS4ERR_WRONGSEC:
101 case -NFS4ERR_BADOWNER:
102 case -NFS4ERR_BADNAME:
104 case -NFS4ERR_SHARE_DENIED:
106 case -NFS4ERR_MINOR_VERS_MISMATCH:
107 return -EPROTONOSUPPORT;
108 case -NFS4ERR_ACCESS:
110 case -NFS4ERR_FILE_OPEN:
113 dprintk("%s could not handle NFSv4 error %d\n",
121 * This is our standard bitmap for GETATTR requests.
123 const u32 nfs4_fattr_bitmap[3] = {
125 | FATTR4_WORD0_CHANGE
128 | FATTR4_WORD0_FILEID,
130 | FATTR4_WORD1_NUMLINKS
132 | FATTR4_WORD1_OWNER_GROUP
133 | FATTR4_WORD1_RAWDEV
134 | FATTR4_WORD1_SPACE_USED
135 | FATTR4_WORD1_TIME_ACCESS
136 | FATTR4_WORD1_TIME_METADATA
137 | FATTR4_WORD1_TIME_MODIFY
140 static const u32 nfs4_pnfs_open_bitmap[3] = {
142 | FATTR4_WORD0_CHANGE
145 | FATTR4_WORD0_FILEID,
147 | FATTR4_WORD1_NUMLINKS
149 | FATTR4_WORD1_OWNER_GROUP
150 | FATTR4_WORD1_RAWDEV
151 | FATTR4_WORD1_SPACE_USED
152 | FATTR4_WORD1_TIME_ACCESS
153 | FATTR4_WORD1_TIME_METADATA
154 | FATTR4_WORD1_TIME_MODIFY,
155 FATTR4_WORD2_MDSTHRESHOLD
158 static const u32 nfs4_open_noattr_bitmap[3] = {
160 | FATTR4_WORD0_CHANGE
161 | FATTR4_WORD0_FILEID,
164 const u32 nfs4_statfs_bitmap[2] = {
165 FATTR4_WORD0_FILES_AVAIL
166 | FATTR4_WORD0_FILES_FREE
167 | FATTR4_WORD0_FILES_TOTAL,
168 FATTR4_WORD1_SPACE_AVAIL
169 | FATTR4_WORD1_SPACE_FREE
170 | FATTR4_WORD1_SPACE_TOTAL
173 const u32 nfs4_pathconf_bitmap[2] = {
175 | FATTR4_WORD0_MAXNAME,
179 const u32 nfs4_fsinfo_bitmap[3] = { FATTR4_WORD0_MAXFILESIZE
180 | FATTR4_WORD0_MAXREAD
181 | FATTR4_WORD0_MAXWRITE
182 | FATTR4_WORD0_LEASE_TIME,
183 FATTR4_WORD1_TIME_DELTA
184 | FATTR4_WORD1_FS_LAYOUT_TYPES,
185 FATTR4_WORD2_LAYOUT_BLKSIZE
188 const u32 nfs4_fs_locations_bitmap[2] = {
190 | FATTR4_WORD0_CHANGE
193 | FATTR4_WORD0_FILEID
194 | FATTR4_WORD0_FS_LOCATIONS,
196 | FATTR4_WORD1_NUMLINKS
198 | FATTR4_WORD1_OWNER_GROUP
199 | FATTR4_WORD1_RAWDEV
200 | FATTR4_WORD1_SPACE_USED
201 | FATTR4_WORD1_TIME_ACCESS
202 | FATTR4_WORD1_TIME_METADATA
203 | FATTR4_WORD1_TIME_MODIFY
204 | FATTR4_WORD1_MOUNTED_ON_FILEID
207 static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
208 struct nfs4_readdir_arg *readdir)
213 readdir->cookie = cookie;
214 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
219 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
224 * NFSv4 servers do not return entries for '.' and '..'
225 * Therefore, we fake these entries here. We let '.'
226 * have cookie 0 and '..' have cookie 1. Note that
227 * when talking to the server, we always send cookie 0
230 start = p = kmap_atomic(*readdir->pages);
233 *p++ = xdr_one; /* next */
234 *p++ = xdr_zero; /* cookie, first word */
235 *p++ = xdr_one; /* cookie, second word */
236 *p++ = xdr_one; /* entry len */
237 memcpy(p, ".\0\0\0", 4); /* entry */
239 *p++ = xdr_one; /* bitmap length */
240 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
241 *p++ = htonl(8); /* attribute buffer length */
242 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_inode));
245 *p++ = xdr_one; /* next */
246 *p++ = xdr_zero; /* cookie, first word */
247 *p++ = xdr_two; /* cookie, second word */
248 *p++ = xdr_two; /* entry len */
249 memcpy(p, "..\0\0", 4); /* entry */
251 *p++ = xdr_one; /* bitmap length */
252 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
253 *p++ = htonl(8); /* attribute buffer length */
254 p = xdr_encode_hyper(p, NFS_FILEID(dentry->d_parent->d_inode));
256 readdir->pgbase = (char *)p - (char *)start;
257 readdir->count -= readdir->pgbase;
258 kunmap_atomic(start);
261 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
268 *timeout = NFS4_POLL_RETRY_MIN;
269 if (*timeout > NFS4_POLL_RETRY_MAX)
270 *timeout = NFS4_POLL_RETRY_MAX;
271 freezable_schedule_timeout_killable(*timeout);
272 if (fatal_signal_pending(current))
278 /* This is the error handling routine for processes that are allowed
281 static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
283 struct nfs_client *clp = server->nfs_client;
284 struct nfs4_state *state = exception->state;
285 struct inode *inode = exception->inode;
288 exception->retry = 0;
292 case -NFS4ERR_OPENMODE:
293 if (inode && nfs4_have_delegation(inode, FMODE_READ)) {
294 nfs4_inode_return_delegation(inode);
295 exception->retry = 1;
300 ret = nfs4_schedule_stateid_recovery(server, state);
303 goto wait_on_recovery;
304 case -NFS4ERR_DELEG_REVOKED:
305 case -NFS4ERR_ADMIN_REVOKED:
306 case -NFS4ERR_BAD_STATEID:
309 nfs_remove_bad_delegation(state->inode);
310 ret = nfs4_schedule_stateid_recovery(server, state);
313 goto wait_on_recovery;
314 case -NFS4ERR_EXPIRED:
316 ret = nfs4_schedule_stateid_recovery(server, state);
320 case -NFS4ERR_STALE_STATEID:
321 case -NFS4ERR_STALE_CLIENTID:
322 nfs4_schedule_lease_recovery(clp);
323 goto wait_on_recovery;
324 #if defined(CONFIG_NFS_V4_1)
325 case -NFS4ERR_BADSESSION:
326 case -NFS4ERR_BADSLOT:
327 case -NFS4ERR_BAD_HIGH_SLOT:
328 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
329 case -NFS4ERR_DEADSESSION:
330 case -NFS4ERR_SEQ_FALSE_RETRY:
331 case -NFS4ERR_SEQ_MISORDERED:
332 dprintk("%s ERROR: %d Reset session\n", __func__,
334 nfs4_schedule_session_recovery(clp->cl_session, errorcode);
335 goto wait_on_recovery;
336 #endif /* defined(CONFIG_NFS_V4_1) */
337 case -NFS4ERR_FILE_OPEN:
338 if (exception->timeout > HZ) {
339 /* We have retried a decent amount, time to
347 ret = nfs4_delay(server->client, &exception->timeout);
350 case -NFS4ERR_RETRY_UNCACHED_REP:
351 case -NFS4ERR_OLD_STATEID:
352 exception->retry = 1;
354 case -NFS4ERR_BADOWNER:
355 /* The following works around a Linux server bug! */
356 case -NFS4ERR_BADNAME:
357 if (server->caps & NFS_CAP_UIDGID_NOMAP) {
358 server->caps &= ~NFS_CAP_UIDGID_NOMAP;
359 exception->retry = 1;
360 printk(KERN_WARNING "NFS: v4 server %s "
361 "does not accept raw "
363 "Reenabling the idmapper.\n",
364 server->nfs_client->cl_hostname);
367 /* We failed to handle the error */
368 return nfs4_map_errors(ret);
370 ret = nfs4_wait_clnt_recover(clp);
372 exception->retry = 1;
377 static void do_renew_lease(struct nfs_client *clp, unsigned long timestamp)
379 spin_lock(&clp->cl_lock);
380 if (time_before(clp->cl_last_renewal,timestamp))
381 clp->cl_last_renewal = timestamp;
382 spin_unlock(&clp->cl_lock);
385 static void renew_lease(const struct nfs_server *server, unsigned long timestamp)
387 do_renew_lease(server->nfs_client, timestamp);
390 #if defined(CONFIG_NFS_V4_1)
392 static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res)
394 struct nfs4_session *session;
395 struct nfs4_slot_table *tbl;
396 bool send_new_highest_used_slotid = false;
399 /* just wake up the next guy waiting since
400 * we may have not consumed a slot after all */
401 dprintk("%s: No slot\n", __func__);
404 tbl = res->sr_slot->table;
405 session = tbl->session;
407 spin_lock(&tbl->slot_tbl_lock);
408 /* Be nice to the server: try to ensure that the last transmitted
409 * value for highest_user_slotid <= target_highest_slotid
411 if (tbl->highest_used_slotid > tbl->target_highest_slotid)
412 send_new_highest_used_slotid = true;
414 if (nfs41_wake_and_assign_slot(tbl, res->sr_slot)) {
415 send_new_highest_used_slotid = false;
418 nfs4_free_slot(tbl, res->sr_slot);
420 if (tbl->highest_used_slotid != NFS4_NO_SLOT)
421 send_new_highest_used_slotid = false;
423 spin_unlock(&tbl->slot_tbl_lock);
425 if (send_new_highest_used_slotid)
426 nfs41_server_notify_highest_slotid_update(session->clp);
429 static int nfs41_sequence_done(struct rpc_task *task, struct nfs4_sequence_res *res)
431 struct nfs4_session *session;
432 struct nfs4_slot *slot;
433 struct nfs_client *clp;
434 bool interrupted = false;
437 /* don't increment the sequence number if the task wasn't sent */
438 if (!RPC_WAS_SENT(task))
442 session = slot->table->session;
444 if (slot->interrupted) {
445 slot->interrupted = 0;
449 /* Check the SEQUENCE operation status */
450 switch (res->sr_status) {
452 /* Update the slot's sequence and clientid lease timer */
455 do_renew_lease(clp, res->sr_timestamp);
456 /* Check sequence flags */
457 if (res->sr_status_flags != 0)
458 nfs4_schedule_lease_recovery(clp);
459 nfs41_update_target_slotid(slot->table, slot, res);
463 * sr_status remains 1 if an RPC level error occurred.
464 * The server may or may not have processed the sequence
466 * Mark the slot as having hosted an interrupted RPC call.
468 slot->interrupted = 1;
471 /* The server detected a resend of the RPC call and
472 * returned NFS4ERR_DELAY as per Section 2.10.6.2
475 dprintk("%s: slot=%u seq=%u: Operation in progress\n",
480 case -NFS4ERR_BADSLOT:
482 * The slot id we used was probably retired. Try again
483 * using a different slot id.
486 case -NFS4ERR_SEQ_MISORDERED:
488 * Was the last operation on this sequence interrupted?
489 * If so, retry after bumping the sequence number.
496 * Could this slot have been previously retired?
497 * If so, then the server may be expecting seq_nr = 1!
499 if (slot->seq_nr != 1) {
504 case -NFS4ERR_SEQ_FALSE_RETRY:
508 /* Just update the slot sequence no. */
512 /* The session may be reset by one of the error handlers. */
513 dprintk("%s: Error %d free the slot \n", __func__, res->sr_status);
514 nfs41_sequence_free_slot(res);
517 if (rpc_restart_call_prepare(task)) {
523 if (!rpc_restart_call(task))
525 rpc_delay(task, NFS4_POLL_RETRY_MAX);
529 static int nfs4_sequence_done(struct rpc_task *task,
530 struct nfs4_sequence_res *res)
532 if (res->sr_slot == NULL)
534 return nfs41_sequence_done(task, res);
537 static void nfs41_init_sequence(struct nfs4_sequence_args *args,
538 struct nfs4_sequence_res *res, int cache_reply)
540 args->sa_slot = NULL;
541 args->sa_cache_this = 0;
542 args->sa_privileged = 0;
544 args->sa_cache_this = 1;
548 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
550 args->sa_privileged = 1;
553 int nfs41_setup_sequence(struct nfs4_session *session,
554 struct nfs4_sequence_args *args,
555 struct nfs4_sequence_res *res,
556 struct rpc_task *task)
558 struct nfs4_slot *slot;
559 struct nfs4_slot_table *tbl;
561 dprintk("--> %s\n", __func__);
562 /* slot already allocated? */
563 if (res->sr_slot != NULL)
566 tbl = &session->fc_slot_table;
568 task->tk_timeout = 0;
570 spin_lock(&tbl->slot_tbl_lock);
571 if (test_bit(NFS4_SESSION_DRAINING, &session->session_state) &&
572 !args->sa_privileged) {
573 /* The state manager will wait until the slot table is empty */
574 dprintk("%s session is draining\n", __func__);
578 slot = nfs4_alloc_slot(tbl);
580 /* If out of memory, try again in 1/4 second */
581 if (slot == ERR_PTR(-ENOMEM))
582 task->tk_timeout = HZ >> 2;
583 dprintk("<-- %s: no free slots\n", __func__);
586 spin_unlock(&tbl->slot_tbl_lock);
588 args->sa_slot = slot;
590 dprintk("<-- %s slotid=%d seqid=%d\n", __func__,
591 slot->slot_nr, slot->seq_nr);
594 res->sr_timestamp = jiffies;
595 res->sr_status_flags = 0;
597 * sr_status is only set in decode_sequence, and so will remain
598 * set to 1 if an rpc level failure occurs.
602 rpc_call_start(task);
605 /* Privileged tasks are queued with top priority */
606 if (args->sa_privileged)
607 rpc_sleep_on_priority(&tbl->slot_tbl_waitq, task,
608 NULL, RPC_PRIORITY_PRIVILEGED);
610 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
611 spin_unlock(&tbl->slot_tbl_lock);
614 EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
616 int nfs4_setup_sequence(const struct nfs_server *server,
617 struct nfs4_sequence_args *args,
618 struct nfs4_sequence_res *res,
619 struct rpc_task *task)
621 struct nfs4_session *session = nfs4_get_session(server);
624 if (session == NULL) {
625 rpc_call_start(task);
629 dprintk("--> %s clp %p session %p sr_slot %d\n",
630 __func__, session->clp, session, res->sr_slot ?
631 res->sr_slot->slot_nr : -1);
633 ret = nfs41_setup_sequence(session, args, res, task);
635 dprintk("<-- %s status=%d\n", __func__, ret);
639 struct nfs41_call_sync_data {
640 const struct nfs_server *seq_server;
641 struct nfs4_sequence_args *seq_args;
642 struct nfs4_sequence_res *seq_res;
645 static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
647 struct nfs41_call_sync_data *data = calldata;
648 struct nfs4_session *session = nfs4_get_session(data->seq_server);
650 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
652 nfs41_setup_sequence(session, data->seq_args, data->seq_res, task);
655 static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
657 struct nfs41_call_sync_data *data = calldata;
659 nfs41_sequence_done(task, data->seq_res);
662 static const struct rpc_call_ops nfs41_call_sync_ops = {
663 .rpc_call_prepare = nfs41_call_sync_prepare,
664 .rpc_call_done = nfs41_call_sync_done,
667 static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
668 struct nfs_server *server,
669 struct rpc_message *msg,
670 struct nfs4_sequence_args *args,
671 struct nfs4_sequence_res *res)
674 struct rpc_task *task;
675 struct nfs41_call_sync_data data = {
676 .seq_server = server,
680 struct rpc_task_setup task_setup = {
683 .callback_ops = &nfs41_call_sync_ops,
684 .callback_data = &data
687 task = rpc_run_task(&task_setup);
691 ret = task->tk_status;
699 void nfs41_init_sequence(struct nfs4_sequence_args *args,
700 struct nfs4_sequence_res *res, int cache_reply)
704 static void nfs4_set_sequence_privileged(struct nfs4_sequence_args *args)
709 static int nfs4_sequence_done(struct rpc_task *task,
710 struct nfs4_sequence_res *res)
714 #endif /* CONFIG_NFS_V4_1 */
717 int _nfs4_call_sync(struct rpc_clnt *clnt,
718 struct nfs_server *server,
719 struct rpc_message *msg,
720 struct nfs4_sequence_args *args,
721 struct nfs4_sequence_res *res)
723 return rpc_call_sync(clnt, msg, 0);
727 int nfs4_call_sync(struct rpc_clnt *clnt,
728 struct nfs_server *server,
729 struct rpc_message *msg,
730 struct nfs4_sequence_args *args,
731 struct nfs4_sequence_res *res,
734 nfs41_init_sequence(args, res, cache_reply);
735 return server->nfs_client->cl_mvops->call_sync(clnt, server, msg,
739 static void update_changeattr(struct inode *dir, struct nfs4_change_info *cinfo)
741 struct nfs_inode *nfsi = NFS_I(dir);
743 spin_lock(&dir->i_lock);
744 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
745 if (!cinfo->atomic || cinfo->before != dir->i_version)
746 nfs_force_lookup_revalidate(dir);
747 dir->i_version = cinfo->after;
748 nfs_fscache_invalidate(dir);
749 spin_unlock(&dir->i_lock);
752 struct nfs4_opendata {
754 struct nfs_openargs o_arg;
755 struct nfs_openres o_res;
756 struct nfs_open_confirmargs c_arg;
757 struct nfs_open_confirmres c_res;
758 struct nfs4_string owner_name;
759 struct nfs4_string group_name;
760 struct nfs_fattr f_attr;
762 struct dentry *dentry;
763 struct nfs4_state_owner *owner;
764 struct nfs4_state *state;
766 unsigned long timestamp;
767 unsigned int rpc_done : 1;
772 static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server,
773 int err, struct nfs4_exception *exception)
777 if (!(server->caps & NFS_CAP_ATOMIC_OPEN_V1))
779 server->caps &= ~NFS_CAP_ATOMIC_OPEN_V1;
780 exception->retry = 1;
784 static enum open_claim_type4
785 nfs4_map_atomic_open_claim(struct nfs_server *server,
786 enum open_claim_type4 claim)
788 if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
793 case NFS4_OPEN_CLAIM_FH:
794 return NFS4_OPEN_CLAIM_NULL;
795 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
796 return NFS4_OPEN_CLAIM_DELEGATE_CUR;
797 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
798 return NFS4_OPEN_CLAIM_DELEGATE_PREV;
802 static void nfs4_init_opendata_res(struct nfs4_opendata *p)
804 p->o_res.f_attr = &p->f_attr;
805 p->o_res.seqid = p->o_arg.seqid;
806 p->c_res.seqid = p->c_arg.seqid;
807 p->o_res.server = p->o_arg.server;
808 p->o_res.access_request = p->o_arg.access;
809 nfs_fattr_init(&p->f_attr);
810 nfs_fattr_init_names(&p->f_attr, &p->owner_name, &p->group_name);
813 static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
814 struct nfs4_state_owner *sp, fmode_t fmode, int flags,
815 const struct iattr *attrs,
816 enum open_claim_type4 claim,
819 struct dentry *parent = dget_parent(dentry);
820 struct inode *dir = parent->d_inode;
821 struct nfs_server *server = NFS_SERVER(dir);
822 struct nfs4_opendata *p;
824 p = kzalloc(sizeof(*p), gfp_mask);
827 p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
828 if (p->o_arg.seqid == NULL)
830 nfs_sb_active(dentry->d_sb);
831 p->dentry = dget(dentry);
834 atomic_inc(&sp->so_count);
835 p->o_arg.open_flags = flags;
836 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
837 /* don't put an ACCESS op in OPEN compound if O_EXCL, because ACCESS
838 * will return permission denied for all bits until close */
839 if (!(flags & O_EXCL)) {
840 /* ask server to check for all possible rights as results
842 p->o_arg.access = NFS4_ACCESS_READ | NFS4_ACCESS_MODIFY |
843 NFS4_ACCESS_EXTEND | NFS4_ACCESS_EXECUTE;
845 p->o_arg.clientid = server->nfs_client->cl_clientid;
846 p->o_arg.id.create_time = ktime_to_ns(sp->so_seqid.create_time);
847 p->o_arg.id.uniquifier = sp->so_seqid.owner_id;
848 p->o_arg.name = &dentry->d_name;
849 p->o_arg.server = server;
850 p->o_arg.bitmask = server->attr_bitmask;
851 p->o_arg.open_bitmap = &nfs4_fattr_bitmap[0];
852 p->o_arg.claim = nfs4_map_atomic_open_claim(server, claim);
853 switch (p->o_arg.claim) {
854 case NFS4_OPEN_CLAIM_NULL:
855 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
856 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
857 p->o_arg.fh = NFS_FH(dir);
859 case NFS4_OPEN_CLAIM_PREVIOUS:
860 case NFS4_OPEN_CLAIM_FH:
861 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
862 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
863 p->o_arg.fh = NFS_FH(dentry->d_inode);
865 if (attrs != NULL && attrs->ia_valid != 0) {
868 p->o_arg.u.attrs = &p->attrs;
869 memcpy(&p->attrs, attrs, sizeof(p->attrs));
872 verf[1] = current->pid;
873 memcpy(p->o_arg.u.verifier.data, verf,
874 sizeof(p->o_arg.u.verifier.data));
876 p->c_arg.fh = &p->o_res.fh;
877 p->c_arg.stateid = &p->o_res.stateid;
878 p->c_arg.seqid = p->o_arg.seqid;
879 nfs4_init_opendata_res(p);
889 static void nfs4_opendata_free(struct kref *kref)
891 struct nfs4_opendata *p = container_of(kref,
892 struct nfs4_opendata, kref);
893 struct super_block *sb = p->dentry->d_sb;
895 nfs_free_seqid(p->o_arg.seqid);
896 if (p->state != NULL)
897 nfs4_put_open_state(p->state);
898 nfs4_put_state_owner(p->owner);
902 nfs_fattr_free_names(&p->f_attr);
906 static void nfs4_opendata_put(struct nfs4_opendata *p)
909 kref_put(&p->kref, nfs4_opendata_free);
912 static int nfs4_wait_for_completion_rpc_task(struct rpc_task *task)
916 ret = rpc_wait_for_completion_task(task);
920 static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode)
924 if (open_mode & (O_EXCL|O_TRUNC))
926 switch (mode & (FMODE_READ|FMODE_WRITE)) {
928 ret |= test_bit(NFS_O_RDONLY_STATE, &state->flags) != 0
929 && state->n_rdonly != 0;
932 ret |= test_bit(NFS_O_WRONLY_STATE, &state->flags) != 0
933 && state->n_wronly != 0;
935 case FMODE_READ|FMODE_WRITE:
936 ret |= test_bit(NFS_O_RDWR_STATE, &state->flags) != 0
937 && state->n_rdwr != 0;
943 static int can_open_delegated(struct nfs_delegation *delegation, fmode_t fmode)
945 if (delegation == NULL)
947 if ((delegation->type & fmode) != fmode)
949 if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags))
951 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
953 nfs_mark_delegation_referenced(delegation);
957 static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
966 case FMODE_READ|FMODE_WRITE:
969 nfs4_state_set_mode_locked(state, state->state | fmode);
972 static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
974 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
975 nfs4_stateid_copy(&state->stateid, stateid);
976 nfs4_stateid_copy(&state->open_stateid, stateid);
979 set_bit(NFS_O_RDONLY_STATE, &state->flags);
982 set_bit(NFS_O_WRONLY_STATE, &state->flags);
984 case FMODE_READ|FMODE_WRITE:
985 set_bit(NFS_O_RDWR_STATE, &state->flags);
989 static void nfs_set_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
991 write_seqlock(&state->seqlock);
992 nfs_set_open_stateid_locked(state, stateid, fmode);
993 write_sequnlock(&state->seqlock);
996 static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, const nfs4_stateid *deleg_stateid, fmode_t fmode)
999 * Protect the call to nfs4_state_set_mode_locked and
1000 * serialise the stateid update
1002 write_seqlock(&state->seqlock);
1003 if (deleg_stateid != NULL) {
1004 nfs4_stateid_copy(&state->stateid, deleg_stateid);
1005 set_bit(NFS_DELEGATED_STATE, &state->flags);
1007 if (open_stateid != NULL)
1008 nfs_set_open_stateid_locked(state, open_stateid, fmode);
1009 write_sequnlock(&state->seqlock);
1010 spin_lock(&state->owner->so_lock);
1011 update_open_stateflags(state, fmode);
1012 spin_unlock(&state->owner->so_lock);
1015 static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stateid, nfs4_stateid *delegation, fmode_t fmode)
1017 struct nfs_inode *nfsi = NFS_I(state->inode);
1018 struct nfs_delegation *deleg_cur;
1021 fmode &= (FMODE_READ|FMODE_WRITE);
1024 deleg_cur = rcu_dereference(nfsi->delegation);
1025 if (deleg_cur == NULL)
1028 spin_lock(&deleg_cur->lock);
1029 if (nfsi->delegation != deleg_cur ||
1030 test_bit(NFS_DELEGATION_RETURNING, &deleg_cur->flags) ||
1031 (deleg_cur->type & fmode) != fmode)
1032 goto no_delegation_unlock;
1034 if (delegation == NULL)
1035 delegation = &deleg_cur->stateid;
1036 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
1037 goto no_delegation_unlock;
1039 nfs_mark_delegation_referenced(deleg_cur);
1040 __update_open_stateid(state, open_stateid, &deleg_cur->stateid, fmode);
1042 no_delegation_unlock:
1043 spin_unlock(&deleg_cur->lock);
1047 if (!ret && open_stateid != NULL) {
1048 __update_open_stateid(state, open_stateid, NULL, fmode);
1056 static void nfs4_return_incompatible_delegation(struct inode *inode, fmode_t fmode)
1058 struct nfs_delegation *delegation;
1061 delegation = rcu_dereference(NFS_I(inode)->delegation);
1062 if (delegation == NULL || (delegation->type & fmode) == fmode) {
1067 nfs4_inode_return_delegation(inode);
1070 static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1072 struct nfs4_state *state = opendata->state;
1073 struct nfs_inode *nfsi = NFS_I(state->inode);
1074 struct nfs_delegation *delegation;
1075 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1076 fmode_t fmode = opendata->o_arg.fmode;
1077 nfs4_stateid stateid;
1081 if (can_open_cached(state, fmode, open_mode)) {
1082 spin_lock(&state->owner->so_lock);
1083 if (can_open_cached(state, fmode, open_mode)) {
1084 update_open_stateflags(state, fmode);
1085 spin_unlock(&state->owner->so_lock);
1086 goto out_return_state;
1088 spin_unlock(&state->owner->so_lock);
1091 delegation = rcu_dereference(nfsi->delegation);
1092 if (!can_open_delegated(delegation, fmode)) {
1096 /* Save the delegation */
1097 nfs4_stateid_copy(&stateid, &delegation->stateid);
1099 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1104 /* Try to update the stateid using the delegation */
1105 if (update_open_stateid(state, NULL, &stateid, fmode))
1106 goto out_return_state;
1109 return ERR_PTR(ret);
1111 atomic_inc(&state->count);
1116 nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
1118 struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
1119 struct nfs_delegation *delegation;
1120 int delegation_flags = 0;
1123 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1125 delegation_flags = delegation->flags;
1127 if (data->o_arg.claim == NFS4_OPEN_CLAIM_DELEGATE_CUR) {
1128 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1129 "returning a delegation for "
1130 "OPEN(CLAIM_DELEGATE_CUR)\n",
1132 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1133 nfs_inode_set_delegation(state->inode,
1134 data->owner->so_cred,
1137 nfs_inode_reclaim_delegation(state->inode,
1138 data->owner->so_cred,
1143 * Check the inode attributes against the CLAIM_PREVIOUS returned attributes
1144 * and update the nfs4_state.
1146 static struct nfs4_state *
1147 _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)
1149 struct inode *inode = data->state->inode;
1150 struct nfs4_state *state = data->state;
1153 if (!data->rpc_done) {
1154 ret = data->rpc_status;
1159 if (!(data->f_attr.valid & NFS_ATTR_FATTR_TYPE) ||
1160 !(data->f_attr.valid & NFS_ATTR_FATTR_FILEID) ||
1161 !(data->f_attr.valid & NFS_ATTR_FATTR_CHANGE))
1165 state = nfs4_get_open_state(inode, data->owner);
1169 ret = nfs_refresh_inode(inode, &data->f_attr);
1173 if (data->o_res.delegation_type != 0)
1174 nfs4_opendata_check_deleg(data, state);
1175 update_open_stateid(state, &data->o_res.stateid, NULL,
1180 return ERR_PTR(ret);
1184 static struct nfs4_state *
1185 _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1187 struct inode *inode;
1188 struct nfs4_state *state = NULL;
1191 if (!data->rpc_done) {
1192 state = nfs4_try_open_cached(data);
1197 if (!(data->f_attr.valid & NFS_ATTR_FATTR))
1199 inode = nfs_fhget(data->dir->d_sb, &data->o_res.fh, &data->f_attr);
1200 ret = PTR_ERR(inode);
1204 state = nfs4_get_open_state(inode, data->owner);
1207 if (data->o_res.delegation_type != 0)
1208 nfs4_opendata_check_deleg(data, state);
1209 update_open_stateid(state, &data->o_res.stateid, NULL,
1213 nfs_release_seqid(data->o_arg.seqid);
1218 return ERR_PTR(ret);
1221 static struct nfs4_state *
1222 nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
1224 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS)
1225 return _nfs4_opendata_reclaim_to_nfs4_state(data);
1226 return _nfs4_opendata_to_nfs4_state(data);
1229 static struct nfs_open_context *nfs4_state_find_open_context(struct nfs4_state *state)
1231 struct nfs_inode *nfsi = NFS_I(state->inode);
1232 struct nfs_open_context *ctx;
1234 spin_lock(&state->inode->i_lock);
1235 list_for_each_entry(ctx, &nfsi->open_files, list) {
1236 if (ctx->state != state)
1238 get_nfs_open_context(ctx);
1239 spin_unlock(&state->inode->i_lock);
1242 spin_unlock(&state->inode->i_lock);
1243 return ERR_PTR(-ENOENT);
1246 static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context *ctx,
1247 struct nfs4_state *state, enum open_claim_type4 claim)
1249 struct nfs4_opendata *opendata;
1251 opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0,
1252 NULL, claim, GFP_NOFS);
1253 if (opendata == NULL)
1254 return ERR_PTR(-ENOMEM);
1255 opendata->state = state;
1256 atomic_inc(&state->count);
1260 static int nfs4_open_recover_helper(struct nfs4_opendata *opendata, fmode_t fmode, struct nfs4_state **res)
1262 struct nfs4_state *newstate;
1265 opendata->o_arg.open_flags = 0;
1266 opendata->o_arg.fmode = fmode;
1267 memset(&opendata->o_res, 0, sizeof(opendata->o_res));
1268 memset(&opendata->c_res, 0, sizeof(opendata->c_res));
1269 nfs4_init_opendata_res(opendata);
1270 ret = _nfs4_recover_proc_open(opendata);
1273 newstate = nfs4_opendata_to_nfs4_state(opendata);
1274 if (IS_ERR(newstate))
1275 return PTR_ERR(newstate);
1276 nfs4_close_state(newstate, fmode);
1281 static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *state)
1283 struct nfs4_state *newstate;
1286 /* memory barrier prior to reading state->n_* */
1287 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1289 if (state->n_rdwr != 0) {
1290 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1291 ret = nfs4_open_recover_helper(opendata, FMODE_READ|FMODE_WRITE, &newstate);
1294 if (newstate != state)
1297 if (state->n_wronly != 0) {
1298 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1299 ret = nfs4_open_recover_helper(opendata, FMODE_WRITE, &newstate);
1302 if (newstate != state)
1305 if (state->n_rdonly != 0) {
1306 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1307 ret = nfs4_open_recover_helper(opendata, FMODE_READ, &newstate);
1310 if (newstate != state)
1314 * We may have performed cached opens for all three recoveries.
1315 * Check if we need to update the current stateid.
1317 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1318 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1319 write_seqlock(&state->seqlock);
1320 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1321 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1322 write_sequnlock(&state->seqlock);
1329 * reclaim state on the server after a reboot.
1331 static int _nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1333 struct nfs_delegation *delegation;
1334 struct nfs4_opendata *opendata;
1335 fmode_t delegation_type = 0;
1338 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1339 NFS4_OPEN_CLAIM_PREVIOUS);
1340 if (IS_ERR(opendata))
1341 return PTR_ERR(opendata);
1343 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
1344 if (delegation != NULL && test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) != 0)
1345 delegation_type = delegation->type;
1347 opendata->o_arg.u.delegation_type = delegation_type;
1348 status = nfs4_open_recover(opendata, state);
1349 nfs4_opendata_put(opendata);
1353 static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
1355 struct nfs_server *server = NFS_SERVER(state->inode);
1356 struct nfs4_exception exception = { };
1359 err = _nfs4_do_open_reclaim(ctx, state);
1360 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1362 if (err != -NFS4ERR_DELAY)
1364 nfs4_handle_exception(server, err, &exception);
1365 } while (exception.retry);
1369 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
1371 struct nfs_open_context *ctx;
1374 ctx = nfs4_state_find_open_context(state);
1377 ret = nfs4_do_open_reclaim(ctx, state);
1378 put_nfs_open_context(ctx);
1382 int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
1384 struct nfs_server *server = NFS_SERVER(state->inode);
1385 struct nfs4_opendata *opendata;
1388 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1389 NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1390 if (IS_ERR(opendata))
1391 return PTR_ERR(opendata);
1392 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1393 err = nfs4_open_recover(opendata, state);
1394 nfs4_opendata_put(opendata);
1397 printk(KERN_ERR "NFS: %s: unhandled error "
1398 "%d.\n", __func__, err);
1403 case -NFS4ERR_BADSESSION:
1404 case -NFS4ERR_BADSLOT:
1405 case -NFS4ERR_BAD_HIGH_SLOT:
1406 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1407 case -NFS4ERR_DEADSESSION:
1408 set_bit(NFS_DELEGATED_STATE, &state->flags);
1409 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
1411 case -NFS4ERR_STALE_CLIENTID:
1412 case -NFS4ERR_STALE_STATEID:
1413 set_bit(NFS_DELEGATED_STATE, &state->flags);
1414 case -NFS4ERR_EXPIRED:
1415 /* Don't recall a delegation if it was lost */
1416 nfs4_schedule_lease_recovery(server->nfs_client);
1418 case -NFS4ERR_DELEG_REVOKED:
1419 case -NFS4ERR_ADMIN_REVOKED:
1420 case -NFS4ERR_BAD_STATEID:
1421 nfs_inode_find_state_and_recover(state->inode,
1423 nfs4_schedule_stateid_recovery(server, state);
1426 case -NFS4ERR_DELAY:
1427 case -NFS4ERR_GRACE:
1428 set_bit(NFS_DELEGATED_STATE, &state->flags);
1435 static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1437 struct nfs4_opendata *data = calldata;
1439 data->rpc_status = task->tk_status;
1440 if (data->rpc_status == 0) {
1441 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1442 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1443 renew_lease(data->o_res.server, data->timestamp);
1448 static void nfs4_open_confirm_release(void *calldata)
1450 struct nfs4_opendata *data = calldata;
1451 struct nfs4_state *state = NULL;
1453 /* If this request hasn't been cancelled, do nothing */
1454 if (data->cancelled == 0)
1456 /* In case of error, no cleanup! */
1457 if (!data->rpc_done)
1459 state = nfs4_opendata_to_nfs4_state(data);
1461 nfs4_close_state(state, data->o_arg.fmode);
1463 nfs4_opendata_put(data);
1466 static const struct rpc_call_ops nfs4_open_confirm_ops = {
1467 .rpc_call_done = nfs4_open_confirm_done,
1468 .rpc_release = nfs4_open_confirm_release,
1472 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1474 static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
1476 struct nfs_server *server = NFS_SERVER(data->dir->d_inode);
1477 struct rpc_task *task;
1478 struct rpc_message msg = {
1479 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
1480 .rpc_argp = &data->c_arg,
1481 .rpc_resp = &data->c_res,
1482 .rpc_cred = data->owner->so_cred,
1484 struct rpc_task_setup task_setup_data = {
1485 .rpc_client = server->client,
1486 .rpc_message = &msg,
1487 .callback_ops = &nfs4_open_confirm_ops,
1488 .callback_data = data,
1489 .workqueue = nfsiod_workqueue,
1490 .flags = RPC_TASK_ASYNC,
1494 kref_get(&data->kref);
1496 data->rpc_status = 0;
1497 data->timestamp = jiffies;
1498 task = rpc_run_task(&task_setup_data);
1500 return PTR_ERR(task);
1501 status = nfs4_wait_for_completion_rpc_task(task);
1503 data->cancelled = 1;
1506 status = data->rpc_status;
1511 static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1513 struct nfs4_opendata *data = calldata;
1514 struct nfs4_state_owner *sp = data->owner;
1516 if (nfs_wait_on_sequence(data->o_arg.seqid, task) != 0)
1519 * Check if we still need to send an OPEN call, or if we can use
1520 * a delegation instead.
1522 if (data->state != NULL) {
1523 struct nfs_delegation *delegation;
1525 if (can_open_cached(data->state, data->o_arg.fmode, data->o_arg.open_flags))
1528 delegation = rcu_dereference(NFS_I(data->state->inode)->delegation);
1529 if (data->o_arg.claim != NFS4_OPEN_CLAIM_DELEGATE_CUR &&
1530 can_open_delegated(delegation, data->o_arg.fmode))
1531 goto unlock_no_action;
1534 /* Update client id. */
1535 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1536 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1537 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
1538 data->o_arg.open_bitmap = &nfs4_open_noattr_bitmap[0];
1539 nfs_copy_fh(&data->o_res.fh, data->o_arg.fh);
1541 data->timestamp = jiffies;
1542 if (nfs4_setup_sequence(data->o_arg.server,
1543 &data->o_arg.seq_args,
1544 &data->o_res.seq_res,
1546 nfs_release_seqid(data->o_arg.seqid);
1551 task->tk_action = NULL;
1553 nfs4_sequence_done(task, &data->o_res.seq_res);
1556 static void nfs4_open_done(struct rpc_task *task, void *calldata)
1558 struct nfs4_opendata *data = calldata;
1560 data->rpc_status = task->tk_status;
1562 if (!nfs4_sequence_done(task, &data->o_res.seq_res))
1565 if (task->tk_status == 0) {
1566 if (data->o_res.f_attr->valid & NFS_ATTR_FATTR_TYPE) {
1567 switch (data->o_res.f_attr->mode & S_IFMT) {
1571 data->rpc_status = -ELOOP;
1574 data->rpc_status = -EISDIR;
1577 data->rpc_status = -ENOTDIR;
1580 renew_lease(data->o_res.server, data->timestamp);
1581 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
1582 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1587 static void nfs4_open_release(void *calldata)
1589 struct nfs4_opendata *data = calldata;
1590 struct nfs4_state *state = NULL;
1592 /* If this request hasn't been cancelled, do nothing */
1593 if (data->cancelled == 0)
1595 /* In case of error, no cleanup! */
1596 if (data->rpc_status != 0 || !data->rpc_done)
1598 /* In case we need an open_confirm, no cleanup! */
1599 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
1601 state = nfs4_opendata_to_nfs4_state(data);
1603 nfs4_close_state(state, data->o_arg.fmode);
1605 nfs4_opendata_put(data);
1608 static const struct rpc_call_ops nfs4_open_ops = {
1609 .rpc_call_prepare = nfs4_open_prepare,
1610 .rpc_call_done = nfs4_open_done,
1611 .rpc_release = nfs4_open_release,
1614 static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1616 struct inode *dir = data->dir->d_inode;
1617 struct nfs_server *server = NFS_SERVER(dir);
1618 struct nfs_openargs *o_arg = &data->o_arg;
1619 struct nfs_openres *o_res = &data->o_res;
1620 struct rpc_task *task;
1621 struct rpc_message msg = {
1622 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
1625 .rpc_cred = data->owner->so_cred,
1627 struct rpc_task_setup task_setup_data = {
1628 .rpc_client = server->client,
1629 .rpc_message = &msg,
1630 .callback_ops = &nfs4_open_ops,
1631 .callback_data = data,
1632 .workqueue = nfsiod_workqueue,
1633 .flags = RPC_TASK_ASYNC,
1637 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1638 kref_get(&data->kref);
1640 data->rpc_status = 0;
1641 data->cancelled = 0;
1643 nfs4_set_sequence_privileged(&o_arg->seq_args);
1644 task = rpc_run_task(&task_setup_data);
1646 return PTR_ERR(task);
1647 status = nfs4_wait_for_completion_rpc_task(task);
1649 data->cancelled = 1;
1652 status = data->rpc_status;
1658 static int _nfs4_recover_proc_open(struct nfs4_opendata *data)
1660 struct inode *dir = data->dir->d_inode;
1661 struct nfs_openres *o_res = &data->o_res;
1664 status = nfs4_run_open_task(data, 1);
1665 if (status != 0 || !data->rpc_done)
1668 nfs_fattr_map_and_free_names(NFS_SERVER(dir), &data->f_attr);
1670 if (o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1671 status = _nfs4_proc_open_confirm(data);
1679 static int nfs4_opendata_access(struct rpc_cred *cred,
1680 struct nfs4_opendata *opendata,
1681 struct nfs4_state *state, fmode_t fmode,
1684 struct nfs_access_entry cache;
1687 /* access call failed or for some reason the server doesn't
1688 * support any access modes -- defer access call until later */
1689 if (opendata->o_res.access_supported == 0)
1693 /* don't check MAY_WRITE - a newly created file may not have
1694 * write mode bits, but POSIX allows the creating process to write.
1695 * use openflags to check for exec, because fmode won't
1696 * always have FMODE_EXEC set when file open for exec. */
1697 if (openflags & __FMODE_EXEC) {
1698 /* ONLY check for exec rights */
1700 } else if (fmode & FMODE_READ)
1704 cache.jiffies = jiffies;
1705 nfs_access_set_mask(&cache, opendata->o_res.access_result);
1706 nfs_access_add_cache(state->inode, &cache);
1708 if ((mask & ~cache.mask & (MAY_READ | MAY_EXEC)) == 0)
1711 /* even though OPEN succeeded, access is denied. Close the file */
1712 nfs4_close_state(state, fmode);
1717 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1719 static int _nfs4_proc_open(struct nfs4_opendata *data)
1721 struct inode *dir = data->dir->d_inode;
1722 struct nfs_server *server = NFS_SERVER(dir);
1723 struct nfs_openargs *o_arg = &data->o_arg;
1724 struct nfs_openres *o_res = &data->o_res;
1727 status = nfs4_run_open_task(data, 0);
1728 if (!data->rpc_done)
1731 if (status == -NFS4ERR_BADNAME &&
1732 !(o_arg->open_flags & O_CREAT))
1737 nfs_fattr_map_and_free_names(server, &data->f_attr);
1739 if (o_arg->open_flags & O_CREAT)
1740 update_changeattr(dir, &o_res->cinfo);
1741 if ((o_res->rflags & NFS4_OPEN_RESULT_LOCKTYPE_POSIX) == 0)
1742 server->caps &= ~NFS_CAP_POSIX_LOCK;
1743 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
1744 status = _nfs4_proc_open_confirm(data);
1748 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
1749 _nfs4_proc_getattr(server, &o_res->fh, o_res->f_attr);
1753 static int nfs4_recover_expired_lease(struct nfs_server *server)
1755 return nfs4_client_recover_expired_lease(server->nfs_client);
1760 * reclaim state on the server after a network partition.
1761 * Assumes caller holds the appropriate lock
1763 static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1765 struct nfs4_opendata *opendata;
1768 opendata = nfs4_open_recoverdata_alloc(ctx, state,
1769 NFS4_OPEN_CLAIM_FH);
1770 if (IS_ERR(opendata))
1771 return PTR_ERR(opendata);
1772 ret = nfs4_open_recover(opendata, state);
1774 d_drop(ctx->dentry);
1775 nfs4_opendata_put(opendata);
1779 static int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
1781 struct nfs_server *server = NFS_SERVER(state->inode);
1782 struct nfs4_exception exception = { };
1786 err = _nfs4_open_expired(ctx, state);
1787 if (nfs4_clear_cap_atomic_open_v1(server, err, &exception))
1792 case -NFS4ERR_GRACE:
1793 case -NFS4ERR_DELAY:
1794 nfs4_handle_exception(server, err, &exception);
1797 } while (exception.retry);
1802 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1804 struct nfs_open_context *ctx;
1807 ctx = nfs4_state_find_open_context(state);
1810 ret = nfs4_do_open_expired(ctx, state);
1811 put_nfs_open_context(ctx);
1815 #if defined(CONFIG_NFS_V4_1)
1816 static void nfs41_clear_delegation_stateid(struct nfs4_state *state)
1818 struct nfs_server *server = NFS_SERVER(state->inode);
1819 nfs4_stateid *stateid = &state->stateid;
1822 /* If a state reset has been done, test_stateid is unneeded */
1823 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1826 status = nfs41_test_stateid(server, stateid);
1827 if (status != NFS_OK) {
1828 /* Free the stateid unless the server explicitly
1829 * informs us the stateid is unrecognized. */
1830 if (status != -NFS4ERR_BAD_STATEID)
1831 nfs41_free_stateid(server, stateid);
1832 nfs_remove_bad_delegation(state->inode);
1834 write_seqlock(&state->seqlock);
1835 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1836 write_sequnlock(&state->seqlock);
1837 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1842 * nfs41_check_open_stateid - possibly free an open stateid
1844 * @state: NFSv4 state for an inode
1846 * Returns NFS_OK if recovery for this stateid is now finished.
1847 * Otherwise a negative NFS4ERR value is returned.
1849 static int nfs41_check_open_stateid(struct nfs4_state *state)
1851 struct nfs_server *server = NFS_SERVER(state->inode);
1852 nfs4_stateid *stateid = &state->open_stateid;
1855 /* If a state reset has been done, test_stateid is unneeded */
1856 if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) &&
1857 (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) &&
1858 (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0))
1859 return -NFS4ERR_BAD_STATEID;
1861 status = nfs41_test_stateid(server, stateid);
1862 if (status != NFS_OK) {
1863 /* Free the stateid unless the server explicitly
1864 * informs us the stateid is unrecognized. */
1865 if (status != -NFS4ERR_BAD_STATEID)
1866 nfs41_free_stateid(server, stateid);
1868 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1869 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1870 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1875 static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1879 nfs41_clear_delegation_stateid(state);
1880 status = nfs41_check_open_stateid(state);
1881 if (status != NFS_OK)
1882 status = nfs4_open_expired(sp, state);
1888 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1889 * fields corresponding to attributes that were used to store the verifier.
1890 * Make sure we clobber those fields in the later setattr call
1892 static inline void nfs4_exclusive_attrset(struct nfs4_opendata *opendata, struct iattr *sattr)
1894 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_ACCESS) &&
1895 !(sattr->ia_valid & ATTR_ATIME_SET))
1896 sattr->ia_valid |= ATTR_ATIME;
1898 if ((opendata->o_res.attrset[1] & FATTR4_WORD1_TIME_MODIFY) &&
1899 !(sattr->ia_valid & ATTR_MTIME_SET))
1900 sattr->ia_valid |= ATTR_MTIME;
1903 static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
1906 struct nfs4_state **res)
1908 struct nfs4_state_owner *sp = opendata->owner;
1909 struct nfs_server *server = sp->so_server;
1910 struct nfs4_state *state;
1914 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
1916 ret = _nfs4_proc_open(opendata);
1920 state = nfs4_opendata_to_nfs4_state(opendata);
1921 ret = PTR_ERR(state);
1924 if (server->caps & NFS_CAP_POSIX_LOCK)
1925 set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
1927 ret = nfs4_opendata_access(sp->so_cred, opendata, state, fmode, flags);
1931 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
1932 nfs4_schedule_stateid_recovery(server, state);
1939 * Returns a referenced nfs4_state
1941 static int _nfs4_do_open(struct inode *dir,
1942 struct dentry *dentry,
1945 struct iattr *sattr,
1946 struct rpc_cred *cred,
1947 struct nfs4_state **res,
1948 struct nfs4_threshold **ctx_th)
1950 struct nfs4_state_owner *sp;
1951 struct nfs4_state *state = NULL;
1952 struct nfs_server *server = NFS_SERVER(dir);
1953 struct nfs4_opendata *opendata;
1954 enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
1957 /* Protect against reboot recovery conflicts */
1959 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1961 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1964 status = nfs4_recover_expired_lease(server);
1966 goto err_put_state_owner;
1967 if (dentry->d_inode != NULL)
1968 nfs4_return_incompatible_delegation(dentry->d_inode, fmode);
1970 if (dentry->d_inode)
1971 claim = NFS4_OPEN_CLAIM_FH;
1972 opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
1974 if (opendata == NULL)
1975 goto err_put_state_owner;
1977 if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
1978 opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
1979 if (!opendata->f_attr.mdsthreshold)
1980 goto err_opendata_put;
1981 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
1983 if (dentry->d_inode != NULL)
1984 opendata->state = nfs4_get_open_state(dentry->d_inode, sp);
1986 status = _nfs4_open_and_get_state(opendata, fmode, flags, &state);
1988 goto err_opendata_put;
1990 if (opendata->o_arg.open_flags & O_EXCL) {
1991 nfs4_exclusive_attrset(opendata, sattr);
1993 nfs_fattr_init(opendata->o_res.f_attr);
1994 status = nfs4_do_setattr(state->inode, cred,
1995 opendata->o_res.f_attr, sattr,
1998 nfs_setattr_update_inode(state->inode, sattr);
1999 nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
2002 if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
2003 *ctx_th = opendata->f_attr.mdsthreshold;
2005 kfree(opendata->f_attr.mdsthreshold);
2006 opendata->f_attr.mdsthreshold = NULL;
2008 nfs4_opendata_put(opendata);
2009 nfs4_put_state_owner(sp);
2013 kfree(opendata->f_attr.mdsthreshold);
2014 nfs4_opendata_put(opendata);
2015 err_put_state_owner:
2016 nfs4_put_state_owner(sp);
2023 static struct nfs4_state *nfs4_do_open(struct inode *dir,
2024 struct dentry *dentry,
2027 struct iattr *sattr,
2028 struct rpc_cred *cred,
2029 struct nfs4_threshold **ctx_th)
2031 struct nfs_server *server = NFS_SERVER(dir);
2032 struct nfs4_exception exception = { };
2033 struct nfs4_state *res;
2036 fmode &= FMODE_READ|FMODE_WRITE|FMODE_EXEC;
2038 status = _nfs4_do_open(dir, dentry, fmode, flags, sattr, cred,
2042 /* NOTE: BAD_SEQID means the server and client disagree about the
2043 * book-keeping w.r.t. state-changing operations
2044 * (OPEN/CLOSE/LOCK/LOCKU...)
2045 * It is actually a sign of a bug on the client or on the server.
2047 * If we receive a BAD_SEQID error in the particular case of
2048 * doing an OPEN, we assume that nfs_increment_open_seqid() will
2049 * have unhashed the old state_owner for us, and that we can
2050 * therefore safely retry using a new one. We should still warn
2051 * the user though...
2053 if (status == -NFS4ERR_BAD_SEQID) {
2054 pr_warn_ratelimited("NFS: v4 server %s "
2055 " returned a bad sequence-id error!\n",
2056 NFS_SERVER(dir)->nfs_client->cl_hostname);
2057 exception.retry = 1;
2061 * BAD_STATEID on OPEN means that the server cancelled our
2062 * state before it received the OPEN_CONFIRM.
2063 * Recover by retrying the request as per the discussion
2064 * on Page 181 of RFC3530.
2066 if (status == -NFS4ERR_BAD_STATEID) {
2067 exception.retry = 1;
2070 if (status == -EAGAIN) {
2071 /* We must have found a delegation */
2072 exception.retry = 1;
2075 if (nfs4_clear_cap_atomic_open_v1(server, status, &exception))
2077 res = ERR_PTR(nfs4_handle_exception(server,
2078 status, &exception));
2079 } while (exception.retry);
2083 static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2084 struct nfs_fattr *fattr, struct iattr *sattr,
2085 struct nfs4_state *state)
2087 struct nfs_server *server = NFS_SERVER(inode);
2088 struct nfs_setattrargs arg = {
2089 .fh = NFS_FH(inode),
2092 .bitmask = server->attr_bitmask,
2094 struct nfs_setattrres res = {
2098 struct rpc_message msg = {
2099 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
2104 unsigned long timestamp = jiffies;
2107 nfs_fattr_init(fattr);
2109 if (state != NULL && nfs4_valid_open_stateid(state)) {
2110 struct nfs_lockowner lockowner = {
2111 .l_owner = current->files,
2112 .l_pid = current->tgid,
2114 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
2116 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
2118 /* Use that stateid */
2120 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
2122 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
2123 if (status == 0 && state != NULL)
2124 renew_lease(server, timestamp);
2128 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
2129 struct nfs_fattr *fattr, struct iattr *sattr,
2130 struct nfs4_state *state)
2132 struct nfs_server *server = NFS_SERVER(inode);
2133 struct nfs4_exception exception = {
2139 err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
2141 case -NFS4ERR_OPENMODE:
2142 if (state && !(state->state & FMODE_WRITE)) {
2144 if (sattr->ia_valid & ATTR_OPEN)
2149 err = nfs4_handle_exception(server, err, &exception);
2150 } while (exception.retry);
2155 struct nfs4_closedata {
2156 struct inode *inode;
2157 struct nfs4_state *state;
2158 struct nfs_closeargs arg;
2159 struct nfs_closeres res;
2160 struct nfs_fattr fattr;
2161 unsigned long timestamp;
2166 static void nfs4_free_closedata(void *data)
2168 struct nfs4_closedata *calldata = data;
2169 struct nfs4_state_owner *sp = calldata->state->owner;
2170 struct super_block *sb = calldata->state->inode->i_sb;
2173 pnfs_roc_release(calldata->state->inode);
2174 nfs4_put_open_state(calldata->state);
2175 nfs_free_seqid(calldata->arg.seqid);
2176 nfs4_put_state_owner(sp);
2177 nfs_sb_deactive(sb);
2181 static void nfs4_close_clear_stateid_flags(struct nfs4_state *state,
2184 spin_lock(&state->owner->so_lock);
2185 if (!(fmode & FMODE_READ))
2186 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
2187 if (!(fmode & FMODE_WRITE))
2188 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
2189 clear_bit(NFS_O_RDWR_STATE, &state->flags);
2190 spin_unlock(&state->owner->so_lock);
2193 static void nfs4_close_done(struct rpc_task *task, void *data)
2195 struct nfs4_closedata *calldata = data;
2196 struct nfs4_state *state = calldata->state;
2197 struct nfs_server *server = NFS_SERVER(calldata->inode);
2199 dprintk("%s: begin!\n", __func__);
2200 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
2202 /* hmm. we are done with the inode, and in the process of freeing
2203 * the state_owner. we keep this around to process errors
2205 switch (task->tk_status) {
2208 pnfs_roc_set_barrier(state->inode,
2209 calldata->roc_barrier);
2210 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
2211 renew_lease(server, calldata->timestamp);
2212 nfs4_close_clear_stateid_flags(state,
2213 calldata->arg.fmode);
2215 case -NFS4ERR_STALE_STATEID:
2216 case -NFS4ERR_OLD_STATEID:
2217 case -NFS4ERR_BAD_STATEID:
2218 case -NFS4ERR_EXPIRED:
2219 if (calldata->arg.fmode == 0)
2222 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
2223 rpc_restart_call_prepare(task);
2225 nfs_release_seqid(calldata->arg.seqid);
2226 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2227 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
2230 static void nfs4_close_prepare(struct rpc_task *task, void *data)
2232 struct nfs4_closedata *calldata = data;
2233 struct nfs4_state *state = calldata->state;
2234 struct inode *inode = calldata->inode;
2237 dprintk("%s: begin!\n", __func__);
2238 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
2241 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
2242 calldata->arg.fmode = FMODE_READ|FMODE_WRITE;
2243 spin_lock(&state->owner->so_lock);
2244 /* Calculate the change in open mode */
2245 if (state->n_rdwr == 0) {
2246 if (state->n_rdonly == 0) {
2247 call_close |= test_bit(NFS_O_RDONLY_STATE, &state->flags);
2248 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2249 calldata->arg.fmode &= ~FMODE_READ;
2251 if (state->n_wronly == 0) {
2252 call_close |= test_bit(NFS_O_WRONLY_STATE, &state->flags);
2253 call_close |= test_bit(NFS_O_RDWR_STATE, &state->flags);
2254 calldata->arg.fmode &= ~FMODE_WRITE;
2257 if (!nfs4_valid_open_stateid(state))
2259 spin_unlock(&state->owner->so_lock);
2262 /* Note: exit _without_ calling nfs4_close_done */
2266 if (calldata->arg.fmode == 0) {
2267 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE];
2268 if (calldata->roc &&
2269 pnfs_roc_drain(inode, &calldata->roc_barrier, task))
2273 nfs_fattr_init(calldata->res.fattr);
2274 calldata->timestamp = jiffies;
2275 if (nfs4_setup_sequence(NFS_SERVER(inode),
2276 &calldata->arg.seq_args,
2277 &calldata->res.seq_res,
2279 nfs_release_seqid(calldata->arg.seqid);
2280 dprintk("%s: done!\n", __func__);
2283 task->tk_action = NULL;
2285 nfs4_sequence_done(task, &calldata->res.seq_res);
2288 static const struct rpc_call_ops nfs4_close_ops = {
2289 .rpc_call_prepare = nfs4_close_prepare,
2290 .rpc_call_done = nfs4_close_done,
2291 .rpc_release = nfs4_free_closedata,
2295 * It is possible for data to be read/written from a mem-mapped file
2296 * after the sys_close call (which hits the vfs layer as a flush).
2297 * This means that we can't safely call nfsv4 close on a file until
2298 * the inode is cleared. This in turn means that we are not good
2299 * NFSv4 citizens - we do not indicate to the server to update the file's
2300 * share state even when we are done with one of the three share
2301 * stateid's in the inode.
2303 * NOTE: Caller must be holding the sp->so_owner semaphore!
2305 int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait)
2307 struct nfs_server *server = NFS_SERVER(state->inode);
2308 struct nfs4_closedata *calldata;
2309 struct nfs4_state_owner *sp = state->owner;
2310 struct rpc_task *task;
2311 struct rpc_message msg = {
2312 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
2313 .rpc_cred = state->owner->so_cred,
2315 struct rpc_task_setup task_setup_data = {
2316 .rpc_client = server->client,
2317 .rpc_message = &msg,
2318 .callback_ops = &nfs4_close_ops,
2319 .workqueue = nfsiod_workqueue,
2320 .flags = RPC_TASK_ASYNC,
2322 int status = -ENOMEM;
2324 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2325 if (calldata == NULL)
2327 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2328 calldata->inode = state->inode;
2329 calldata->state = state;
2330 calldata->arg.fh = NFS_FH(state->inode);
2331 calldata->arg.stateid = &state->open_stateid;
2332 /* Serialization for the sequence id */
2333 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
2334 if (calldata->arg.seqid == NULL)
2335 goto out_free_calldata;
2336 calldata->arg.fmode = 0;
2337 calldata->arg.bitmask = server->cache_consistency_bitmask;
2338 calldata->res.fattr = &calldata->fattr;
2339 calldata->res.seqid = calldata->arg.seqid;
2340 calldata->res.server = server;
2341 calldata->roc = pnfs_roc(state->inode);
2342 nfs_sb_active(calldata->inode->i_sb);
2344 msg.rpc_argp = &calldata->arg;
2345 msg.rpc_resp = &calldata->res;
2346 task_setup_data.callback_data = calldata;
2347 task = rpc_run_task(&task_setup_data);
2349 return PTR_ERR(task);
2352 status = rpc_wait_for_completion_task(task);
2358 nfs4_put_open_state(state);
2359 nfs4_put_state_owner(sp);
2363 static struct inode *
2364 nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx, int open_flags, struct iattr *attr)
2366 struct nfs4_state *state;
2368 /* Protect against concurrent sillydeletes */
2369 state = nfs4_do_open(dir, ctx->dentry, ctx->mode, open_flags, attr,
2370 ctx->cred, &ctx->mdsthreshold);
2372 return ERR_CAST(state);
2374 return igrab(state->inode);
2377 static void nfs4_close_context(struct nfs_open_context *ctx, int is_sync)
2379 if (ctx->state == NULL)
2382 nfs4_close_sync(ctx->state, ctx->mode);
2384 nfs4_close_state(ctx->state, ctx->mode);
2387 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2389 struct nfs4_server_caps_arg args = {
2392 struct nfs4_server_caps_res res = {};
2393 struct rpc_message msg = {
2394 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
2400 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2402 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
2403 server->caps &= ~(NFS_CAP_ACLS|NFS_CAP_HARDLINKS|
2404 NFS_CAP_SYMLINKS|NFS_CAP_FILEID|
2405 NFS_CAP_MODE|NFS_CAP_NLINK|NFS_CAP_OWNER|
2406 NFS_CAP_OWNER_GROUP|NFS_CAP_ATIME|
2407 NFS_CAP_CTIME|NFS_CAP_MTIME);
2408 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
2409 server->caps |= NFS_CAP_ACLS;
2410 if (res.has_links != 0)
2411 server->caps |= NFS_CAP_HARDLINKS;
2412 if (res.has_symlinks != 0)
2413 server->caps |= NFS_CAP_SYMLINKS;
2414 if (res.attr_bitmask[0] & FATTR4_WORD0_FILEID)
2415 server->caps |= NFS_CAP_FILEID;
2416 if (res.attr_bitmask[1] & FATTR4_WORD1_MODE)
2417 server->caps |= NFS_CAP_MODE;
2418 if (res.attr_bitmask[1] & FATTR4_WORD1_NUMLINKS)
2419 server->caps |= NFS_CAP_NLINK;
2420 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER)
2421 server->caps |= NFS_CAP_OWNER;
2422 if (res.attr_bitmask[1] & FATTR4_WORD1_OWNER_GROUP)
2423 server->caps |= NFS_CAP_OWNER_GROUP;
2424 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_ACCESS)
2425 server->caps |= NFS_CAP_ATIME;
2426 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_METADATA)
2427 server->caps |= NFS_CAP_CTIME;
2428 if (res.attr_bitmask[1] & FATTR4_WORD1_TIME_MODIFY)
2429 server->caps |= NFS_CAP_MTIME;
2431 memcpy(server->cache_consistency_bitmask, res.attr_bitmask, sizeof(server->cache_consistency_bitmask));
2432 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2433 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2434 server->acl_bitmask = res.acl_bitmask;
2435 server->fh_expire_type = res.fh_expire_type;
2441 int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
2443 struct nfs4_exception exception = { };
2446 err = nfs4_handle_exception(server,
2447 _nfs4_server_capabilities(server, fhandle),
2449 } while (exception.retry);
2453 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2454 struct nfs_fsinfo *info)
2456 struct nfs4_lookup_root_arg args = {
2457 .bitmask = nfs4_fattr_bitmap,
2459 struct nfs4_lookup_res res = {
2461 .fattr = info->fattr,
2464 struct rpc_message msg = {
2465 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
2470 nfs_fattr_init(info->fattr);
2471 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2474 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
2475 struct nfs_fsinfo *info)
2477 struct nfs4_exception exception = { };
2480 err = _nfs4_lookup_root(server, fhandle, info);
2483 case -NFS4ERR_WRONGSEC:
2486 err = nfs4_handle_exception(server, err, &exception);
2488 } while (exception.retry);
2493 static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2494 struct nfs_fsinfo *info, rpc_authflavor_t flavor)
2496 struct rpc_auth *auth;
2499 auth = rpcauth_create(flavor, server->client);
2504 ret = nfs4_lookup_root(server, fhandle, info);
2509 static int nfs4_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
2510 struct nfs_fsinfo *info)
2512 int i, len, status = 0;
2513 rpc_authflavor_t flav_array[NFS_MAX_SECFLAVORS];
2515 len = rpcauth_list_flavors(flav_array, ARRAY_SIZE(flav_array));
2519 for (i = 0; i < len; i++) {
2520 /* AUTH_UNIX is the default flavor if none was specified,
2521 * thus has already been tried. */
2522 if (flav_array[i] == RPC_AUTH_UNIX)
2525 status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]);
2526 if (status == -NFS4ERR_WRONGSEC || status == -EACCES)
2531 * -EACCESS could mean that the user doesn't have correct permissions
2532 * to access the mount. It could also mean that we tried to mount
2533 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2534 * existing mount programs don't handle -EACCES very well so it should
2535 * be mapped to -EPERM instead.
2537 if (status == -EACCES)
2543 * get the file handle for the "/" directory on the server
2545 int nfs4_proc_get_rootfh(struct nfs_server *server, struct nfs_fh *fhandle,
2546 struct nfs_fsinfo *info)
2548 int minor_version = server->nfs_client->cl_minorversion;
2549 int status = nfs4_lookup_root(server, fhandle, info);
2550 if ((status == -NFS4ERR_WRONGSEC) && !(server->flags & NFS_MOUNT_SECFLAVOUR))
2552 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2553 * by nfs4_map_errors() as this function exits.
2555 status = nfs_v4_minor_ops[minor_version]->find_root_sec(server, fhandle, info);
2557 status = nfs4_server_capabilities(server, fhandle);
2559 status = nfs4_do_fsinfo(server, fhandle, info);
2560 return nfs4_map_errors(status);
2563 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *mntfh,
2564 struct nfs_fsinfo *info)
2567 struct nfs_fattr *fattr = info->fattr;
2569 error = nfs4_server_capabilities(server, mntfh);
2571 dprintk("nfs4_get_root: getcaps error = %d\n", -error);
2575 error = nfs4_proc_getattr(server, mntfh, fattr);
2577 dprintk("nfs4_get_root: getattr error = %d\n", -error);
2581 if (fattr->valid & NFS_ATTR_FATTR_FSID &&
2582 !nfs_fsid_equal(&server->fsid, &fattr->fsid))
2583 memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
2589 * Get locations and (maybe) other attributes of a referral.
2590 * Note that we'll actually follow the referral later when
2591 * we detect fsid mismatch in inode revalidation
2593 static int nfs4_get_referral(struct rpc_clnt *client, struct inode *dir,
2594 const struct qstr *name, struct nfs_fattr *fattr,
2595 struct nfs_fh *fhandle)
2597 int status = -ENOMEM;
2598 struct page *page = NULL;
2599 struct nfs4_fs_locations *locations = NULL;
2601 page = alloc_page(GFP_KERNEL);
2604 locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2605 if (locations == NULL)
2608 status = nfs4_proc_fs_locations(client, dir, name, locations, page);
2611 /* Make sure server returned a different fsid for the referral */
2612 if (nfs_fsid_equal(&NFS_SERVER(dir)->fsid, &locations->fattr.fsid)) {
2613 dprintk("%s: server did not return a different fsid for"
2614 " a referral at %s\n", __func__, name->name);
2618 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2619 nfs_fixup_referral_attributes(&locations->fattr);
2621 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2622 memcpy(fattr, &locations->fattr, sizeof(struct nfs_fattr));
2623 memset(fhandle, 0, sizeof(struct nfs_fh));
2631 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2633 struct nfs4_getattr_arg args = {
2635 .bitmask = server->attr_bitmask,
2637 struct nfs4_getattr_res res = {
2641 struct rpc_message msg = {
2642 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
2647 nfs_fattr_init(fattr);
2648 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2651 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2653 struct nfs4_exception exception = { };
2656 err = nfs4_handle_exception(server,
2657 _nfs4_proc_getattr(server, fhandle, fattr),
2659 } while (exception.retry);
2664 * The file is not closed if it is opened due to the a request to change
2665 * the size of the file. The open call will not be needed once the
2666 * VFS layer lookup-intents are implemented.
2668 * Close is called when the inode is destroyed.
2669 * If we haven't opened the file for O_WRONLY, we
2670 * need to in the size_change case to obtain a stateid.
2673 * Because OPEN is always done by name in nfsv4, it is
2674 * possible that we opened a different file by the same
2675 * name. We can recognize this race condition, but we
2676 * can't do anything about it besides returning an error.
2678 * This will be fixed with VFS changes (lookup-intent).
2681 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2682 struct iattr *sattr)
2684 struct inode *inode = dentry->d_inode;
2685 struct rpc_cred *cred = NULL;
2686 struct nfs4_state *state = NULL;
2689 if (pnfs_ld_layoutret_on_setattr(inode))
2690 pnfs_commit_and_return_layout(inode);
2692 nfs_fattr_init(fattr);
2694 /* Deal with open(O_TRUNC) */
2695 if (sattr->ia_valid & ATTR_OPEN)
2696 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2698 /* Optimization: if the end result is no change, don't RPC */
2699 if ((sattr->ia_valid & ~(ATTR_FILE)) == 0)
2702 /* Search for an existing open(O_WRITE) file */
2703 if (sattr->ia_valid & ATTR_FILE) {
2704 struct nfs_open_context *ctx;
2706 ctx = nfs_file_open_context(sattr->ia_file);
2713 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2715 nfs_setattr_update_inode(inode, sattr);
2719 static int _nfs4_proc_lookup(struct rpc_clnt *clnt, struct inode *dir,
2720 const struct qstr *name, struct nfs_fh *fhandle,
2721 struct nfs_fattr *fattr)
2723 struct nfs_server *server = NFS_SERVER(dir);
2725 struct nfs4_lookup_arg args = {
2726 .bitmask = server->attr_bitmask,
2727 .dir_fh = NFS_FH(dir),
2730 struct nfs4_lookup_res res = {
2735 struct rpc_message msg = {
2736 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
2741 nfs_fattr_init(fattr);
2743 dprintk("NFS call lookup %s\n", name->name);
2744 status = nfs4_call_sync(clnt, server, &msg, &args.seq_args, &res.seq_res, 0);
2745 dprintk("NFS reply lookup: %d\n", status);
2749 static void nfs_fixup_secinfo_attributes(struct nfs_fattr *fattr)
2751 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
2752 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_MOUNTPOINT;
2753 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
2757 static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir,
2758 struct qstr *name, struct nfs_fh *fhandle,
2759 struct nfs_fattr *fattr)
2761 struct nfs4_exception exception = { };
2762 struct rpc_clnt *client = *clnt;
2765 err = _nfs4_proc_lookup(client, dir, name, fhandle, fattr);
2767 case -NFS4ERR_BADNAME:
2770 case -NFS4ERR_MOVED:
2771 err = nfs4_get_referral(client, dir, name, fattr, fhandle);
2773 case -NFS4ERR_WRONGSEC:
2775 if (client != *clnt)
2778 client = nfs4_create_sec_client(client, dir, name);
2780 return PTR_ERR(client);
2782 exception.retry = 1;
2785 err = nfs4_handle_exception(NFS_SERVER(dir), err, &exception);
2787 } while (exception.retry);
2792 else if (client != *clnt)
2793 rpc_shutdown_client(client);
2798 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name,
2799 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2802 struct rpc_clnt *client = NFS_CLIENT(dir);
2804 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2805 if (client != NFS_CLIENT(dir)) {
2806 rpc_shutdown_client(client);
2807 nfs_fixup_secinfo_attributes(fattr);
2813 nfs4_proc_lookup_mountpoint(struct inode *dir, struct qstr *name,
2814 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
2817 struct rpc_clnt *client = rpc_clone_client(NFS_CLIENT(dir));
2819 status = nfs4_proc_lookup_common(&client, dir, name, fhandle, fattr);
2821 rpc_shutdown_client(client);
2822 return ERR_PTR(status);
2827 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2829 struct nfs_server *server = NFS_SERVER(inode);
2830 struct nfs4_accessargs args = {
2831 .fh = NFS_FH(inode),
2832 .bitmask = server->cache_consistency_bitmask,
2834 struct nfs4_accessres res = {
2837 struct rpc_message msg = {
2838 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
2841 .rpc_cred = entry->cred,
2843 int mode = entry->mask;
2847 * Determine which access bits we want to ask for...
2849 if (mode & MAY_READ)
2850 args.access |= NFS4_ACCESS_READ;
2851 if (S_ISDIR(inode->i_mode)) {
2852 if (mode & MAY_WRITE)
2853 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
2854 if (mode & MAY_EXEC)
2855 args.access |= NFS4_ACCESS_LOOKUP;
2857 if (mode & MAY_WRITE)
2858 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
2859 if (mode & MAY_EXEC)
2860 args.access |= NFS4_ACCESS_EXECUTE;
2863 res.fattr = nfs_alloc_fattr();
2864 if (res.fattr == NULL)
2867 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
2869 nfs_access_set_mask(entry, res.access);
2870 nfs_refresh_inode(inode, res.fattr);
2872 nfs_free_fattr(res.fattr);
2876 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
2878 struct nfs4_exception exception = { };
2881 err = nfs4_handle_exception(NFS_SERVER(inode),
2882 _nfs4_proc_access(inode, entry),
2884 } while (exception.retry);
2889 * TODO: For the time being, we don't try to get any attributes
2890 * along with any of the zero-copy operations READ, READDIR,
2893 * In the case of the first three, we want to put the GETATTR
2894 * after the read-type operation -- this is because it is hard
2895 * to predict the length of a GETATTR response in v4, and thus
2896 * align the READ data correctly. This means that the GETATTR
2897 * may end up partially falling into the page cache, and we should
2898 * shift it into the 'tail' of the xdr_buf before processing.
2899 * To do this efficiently, we need to know the total length
2900 * of data received, which doesn't seem to be available outside
2903 * In the case of WRITE, we also want to put the GETATTR after
2904 * the operation -- in this case because we want to make sure
2905 * we get the post-operation mtime and size.
2907 * Both of these changes to the XDR layer would in fact be quite
2908 * minor, but I decided to leave them for a subsequent patch.
2910 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
2911 unsigned int pgbase, unsigned int pglen)
2913 struct nfs4_readlink args = {
2914 .fh = NFS_FH(inode),
2919 struct nfs4_readlink_res res;
2920 struct rpc_message msg = {
2921 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
2926 return nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode), &msg, &args.seq_args, &res.seq_res, 0);
2929 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
2930 unsigned int pgbase, unsigned int pglen)
2932 struct nfs4_exception exception = { };
2935 err = nfs4_handle_exception(NFS_SERVER(inode),
2936 _nfs4_proc_readlink(inode, page, pgbase, pglen),
2938 } while (exception.retry);
2943 * This is just for mknod. open(O_CREAT) will always do ->open_context().
2946 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
2949 struct nfs_open_context *ctx;
2950 struct nfs4_state *state;
2953 ctx = alloc_nfs_open_context(dentry, FMODE_READ);
2955 return PTR_ERR(ctx);
2957 sattr->ia_mode &= ~current_umask();
2958 state = nfs4_do_open(dir, dentry, ctx->mode,
2959 flags, sattr, ctx->cred,
2960 &ctx->mdsthreshold);
2962 if (IS_ERR(state)) {
2963 status = PTR_ERR(state);
2966 d_add(dentry, igrab(state->inode));
2967 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
2970 put_nfs_open_context(ctx);
2974 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
2976 struct nfs_server *server = NFS_SERVER(dir);
2977 struct nfs_removeargs args = {
2981 struct nfs_removeres res = {
2984 struct rpc_message msg = {
2985 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
2991 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
2993 update_changeattr(dir, &res.cinfo);
2997 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
2999 struct nfs4_exception exception = { };
3002 err = nfs4_handle_exception(NFS_SERVER(dir),
3003 _nfs4_proc_remove(dir, name),
3005 } while (exception.retry);
3009 static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
3011 struct nfs_server *server = NFS_SERVER(dir);
3012 struct nfs_removeargs *args = msg->rpc_argp;
3013 struct nfs_removeres *res = msg->rpc_resp;
3015 res->server = server;
3016 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
3017 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
3020 static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
3022 nfs4_setup_sequence(NFS_SERVER(data->dir),
3023 &data->args.seq_args,
3028 static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
3030 struct nfs_removeres *res = task->tk_msg.rpc_resp;
3032 if (!nfs4_sequence_done(task, &res->seq_res))
3034 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3036 update_changeattr(dir, &res->cinfo);
3040 static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
3042 struct nfs_server *server = NFS_SERVER(dir);
3043 struct nfs_renameargs *arg = msg->rpc_argp;
3044 struct nfs_renameres *res = msg->rpc_resp;
3046 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
3047 res->server = server;
3048 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
3051 static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
3053 nfs4_setup_sequence(NFS_SERVER(data->old_dir),
3054 &data->args.seq_args,
3059 static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
3060 struct inode *new_dir)
3062 struct nfs_renameres *res = task->tk_msg.rpc_resp;
3064 if (!nfs4_sequence_done(task, &res->seq_res))
3066 if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
3069 update_changeattr(old_dir, &res->old_cinfo);
3070 update_changeattr(new_dir, &res->new_cinfo);
3074 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3075 struct inode *new_dir, struct qstr *new_name)
3077 struct nfs_server *server = NFS_SERVER(old_dir);
3078 struct nfs_renameargs arg = {
3079 .old_dir = NFS_FH(old_dir),
3080 .new_dir = NFS_FH(new_dir),
3081 .old_name = old_name,
3082 .new_name = new_name,
3084 struct nfs_renameres res = {
3087 struct rpc_message msg = {
3088 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
3092 int status = -ENOMEM;
3094 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3096 update_changeattr(old_dir, &res.old_cinfo);
3097 update_changeattr(new_dir, &res.new_cinfo);
3102 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
3103 struct inode *new_dir, struct qstr *new_name)
3105 struct nfs4_exception exception = { };
3108 err = nfs4_handle_exception(NFS_SERVER(old_dir),
3109 _nfs4_proc_rename(old_dir, old_name,
3112 } while (exception.retry);
3116 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3118 struct nfs_server *server = NFS_SERVER(inode);
3119 struct nfs4_link_arg arg = {
3120 .fh = NFS_FH(inode),
3121 .dir_fh = NFS_FH(dir),
3123 .bitmask = server->attr_bitmask,
3125 struct nfs4_link_res res = {
3128 struct rpc_message msg = {
3129 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
3133 int status = -ENOMEM;
3135 res.fattr = nfs_alloc_fattr();
3136 if (res.fattr == NULL)
3139 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
3141 update_changeattr(dir, &res.cinfo);
3142 nfs_post_op_update_inode(inode, res.fattr);
3145 nfs_free_fattr(res.fattr);
3149 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
3151 struct nfs4_exception exception = { };
3154 err = nfs4_handle_exception(NFS_SERVER(inode),
3155 _nfs4_proc_link(inode, dir, name),
3157 } while (exception.retry);
3161 struct nfs4_createdata {
3162 struct rpc_message msg;
3163 struct nfs4_create_arg arg;
3164 struct nfs4_create_res res;
3166 struct nfs_fattr fattr;
3169 static struct nfs4_createdata *nfs4_alloc_createdata(struct inode *dir,
3170 struct qstr *name, struct iattr *sattr, u32 ftype)
3172 struct nfs4_createdata *data;
3174 data = kzalloc(sizeof(*data), GFP_KERNEL);
3176 struct nfs_server *server = NFS_SERVER(dir);
3178 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE];
3179 data->msg.rpc_argp = &data->arg;
3180 data->msg.rpc_resp = &data->res;
3181 data->arg.dir_fh = NFS_FH(dir);
3182 data->arg.server = server;
3183 data->arg.name = name;
3184 data->arg.attrs = sattr;
3185 data->arg.ftype = ftype;
3186 data->arg.bitmask = server->attr_bitmask;
3187 data->res.server = server;
3188 data->res.fh = &data->fh;
3189 data->res.fattr = &data->fattr;
3190 nfs_fattr_init(data->res.fattr);
3195 static int nfs4_do_create(struct inode *dir, struct dentry *dentry, struct nfs4_createdata *data)
3197 int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg,
3198 &data->arg.seq_args, &data->res.seq_res, 1);
3200 update_changeattr(dir, &data->res.dir_cinfo);
3201 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
3206 static void nfs4_free_createdata(struct nfs4_createdata *data)
3211 static int _nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3212 struct page *page, unsigned int len, struct iattr *sattr)
3214 struct nfs4_createdata *data;
3215 int status = -ENAMETOOLONG;
3217 if (len > NFS4_MAXPATHLEN)
3221 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4LNK);
3225 data->msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK];
3226 data->arg.u.symlink.pages = &page;
3227 data->arg.u.symlink.len = len;
3229 status = nfs4_do_create(dir, dentry, data);
3231 nfs4_free_createdata(data);
3236 static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
3237 struct page *page, unsigned int len, struct iattr *sattr)
3239 struct nfs4_exception exception = { };
3242 err = nfs4_handle_exception(NFS_SERVER(dir),
3243 _nfs4_proc_symlink(dir, dentry, page,
3246 } while (exception.retry);
3250 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3251 struct iattr *sattr)
3253 struct nfs4_createdata *data;
3254 int status = -ENOMEM;
3256 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR);
3260 status = nfs4_do_create(dir, dentry, data);
3262 nfs4_free_createdata(data);
3267 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
3268 struct iattr *sattr)
3270 struct nfs4_exception exception = { };
3273 sattr->ia_mode &= ~current_umask();
3275 err = nfs4_handle_exception(NFS_SERVER(dir),
3276 _nfs4_proc_mkdir(dir, dentry, sattr),
3278 } while (exception.retry);
3282 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3283 u64 cookie, struct page **pages, unsigned int count, int plus)
3285 struct inode *dir = dentry->d_inode;
3286 struct nfs4_readdir_arg args = {
3291 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
3294 struct nfs4_readdir_res res;
3295 struct rpc_message msg = {
3296 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
3303 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__,
3304 dentry->d_parent->d_name.name,
3305 dentry->d_name.name,
3306 (unsigned long long)cookie);
3307 nfs4_setup_readdir(cookie, NFS_I(dir)->cookieverf, dentry, &args);
3308 res.pgbase = args.pgbase;
3309 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
3311 memcpy(NFS_I(dir)->cookieverf, res.verifier.data, NFS4_VERIFIER_SIZE);
3312 status += args.pgbase;
3315 nfs_invalidate_atime(dir);
3317 dprintk("%s: returns %d\n", __func__, status);
3321 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
3322 u64 cookie, struct page **pages, unsigned int count, int plus)
3324 struct nfs4_exception exception = { };
3327 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
3328 _nfs4_proc_readdir(dentry, cred, cookie,
3329 pages, count, plus),
3331 } while (exception.retry);
3335 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3336 struct iattr *sattr, dev_t rdev)
3338 struct nfs4_createdata *data;
3339 int mode = sattr->ia_mode;
3340 int status = -ENOMEM;
3342 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4SOCK);
3347 data->arg.ftype = NF4FIFO;
3348 else if (S_ISBLK(mode)) {
3349 data->arg.ftype = NF4BLK;
3350 data->arg.u.device.specdata1 = MAJOR(rdev);
3351 data->arg.u.device.specdata2 = MINOR(rdev);
3353 else if (S_ISCHR(mode)) {
3354 data->arg.ftype = NF4CHR;
3355 data->arg.u.device.specdata1 = MAJOR(rdev);
3356 data->arg.u.device.specdata2 = MINOR(rdev);
3357 } else if (!S_ISSOCK(mode)) {
3362 status = nfs4_do_create(dir, dentry, data);
3364 nfs4_free_createdata(data);
3369 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
3370 struct iattr *sattr, dev_t rdev)
3372 struct nfs4_exception exception = { };
3375 sattr->ia_mode &= ~current_umask();
3377 err = nfs4_handle_exception(NFS_SERVER(dir),
3378 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
3380 } while (exception.retry);
3384 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
3385 struct nfs_fsstat *fsstat)
3387 struct nfs4_statfs_arg args = {
3389 .bitmask = server->attr_bitmask,
3391 struct nfs4_statfs_res res = {
3394 struct rpc_message msg = {
3395 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
3400 nfs_fattr_init(fsstat->fattr);
3401 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3404 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
3406 struct nfs4_exception exception = { };
3409 err = nfs4_handle_exception(server,
3410 _nfs4_proc_statfs(server, fhandle, fsstat),
3412 } while (exception.retry);
3416 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
3417 struct nfs_fsinfo *fsinfo)
3419 struct nfs4_fsinfo_arg args = {
3421 .bitmask = server->attr_bitmask,
3423 struct nfs4_fsinfo_res res = {
3426 struct rpc_message msg = {
3427 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
3432 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3435 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3437 struct nfs4_exception exception = { };
3441 err = nfs4_handle_exception(server,
3442 _nfs4_do_fsinfo(server, fhandle, fsinfo),
3444 } while (exception.retry);
3448 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
3452 nfs_fattr_init(fsinfo->fattr);
3453 error = nfs4_do_fsinfo(server, fhandle, fsinfo);
3455 /* block layout checks this! */
3456 server->pnfs_blksize = fsinfo->blksize;
3457 set_pnfs_layoutdriver(server, fhandle, fsinfo->layouttype);
3463 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3464 struct nfs_pathconf *pathconf)
3466 struct nfs4_pathconf_arg args = {
3468 .bitmask = server->attr_bitmask,
3470 struct nfs4_pathconf_res res = {
3471 .pathconf = pathconf,
3473 struct rpc_message msg = {
3474 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
3479 /* None of the pathconf attributes are mandatory to implement */
3480 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
3481 memset(pathconf, 0, sizeof(*pathconf));
3485 nfs_fattr_init(pathconf->fattr);
3486 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
3489 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
3490 struct nfs_pathconf *pathconf)
3492 struct nfs4_exception exception = { };
3496 err = nfs4_handle_exception(server,
3497 _nfs4_proc_pathconf(server, fhandle, pathconf),
3499 } while (exception.retry);
3503 int nfs4_set_rw_stateid(nfs4_stateid *stateid,
3504 const struct nfs_open_context *ctx,
3505 const struct nfs_lock_context *l_ctx,
3508 const struct nfs_lockowner *lockowner = NULL;
3511 lockowner = &l_ctx->lockowner;
3512 return nfs4_select_rw_stateid(stateid, ctx->state, fmode, lockowner);
3514 EXPORT_SYMBOL_GPL(nfs4_set_rw_stateid);
3516 static bool nfs4_stateid_is_current(nfs4_stateid *stateid,
3517 const struct nfs_open_context *ctx,
3518 const struct nfs_lock_context *l_ctx,
3521 nfs4_stateid current_stateid;
3523 if (nfs4_set_rw_stateid(¤t_stateid, ctx, l_ctx, fmode))
3525 return nfs4_stateid_match(stateid, ¤t_stateid);
3528 static bool nfs4_error_stateid_expired(int err)
3531 case -NFS4ERR_DELEG_REVOKED:
3532 case -NFS4ERR_ADMIN_REVOKED:
3533 case -NFS4ERR_BAD_STATEID:
3534 case -NFS4ERR_STALE_STATEID:
3535 case -NFS4ERR_OLD_STATEID:
3536 case -NFS4ERR_OPENMODE:
3537 case -NFS4ERR_EXPIRED:
3543 void __nfs4_read_done_cb(struct nfs_read_data *data)
3545 nfs_invalidate_atime(data->header->inode);
3548 static int nfs4_read_done_cb(struct rpc_task *task, struct nfs_read_data *data)
3550 struct nfs_server *server = NFS_SERVER(data->header->inode);
3552 if (nfs4_async_handle_error(task, server, data->args.context->state) == -EAGAIN) {
3553 rpc_restart_call_prepare(task);
3557 __nfs4_read_done_cb(data);
3558 if (task->tk_status > 0)
3559 renew_lease(server, data->timestamp);
3563 static bool nfs4_read_stateid_changed(struct rpc_task *task,
3564 struct nfs_readargs *args)
3567 if (!nfs4_error_stateid_expired(task->tk_status) ||
3568 nfs4_stateid_is_current(&args->stateid,
3573 rpc_restart_call_prepare(task);
3577 static int nfs4_read_done(struct rpc_task *task, struct nfs_read_data *data)
3580 dprintk("--> %s\n", __func__);
3582 if (!nfs4_sequence_done(task, &data->res.seq_res))
3584 if (nfs4_read_stateid_changed(task, &data->args))
3586 return data->read_done_cb ? data->read_done_cb(task, data) :
3587 nfs4_read_done_cb(task, data);
3590 static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message *msg)
3592 data->timestamp = jiffies;
3593 data->read_done_cb = nfs4_read_done_cb;
3594 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3595 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3598 static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3600 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3601 &data->args.seq_args,
3605 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3606 data->args.lock_context, FMODE_READ);
3609 static int nfs4_write_done_cb(struct rpc_task *task, struct nfs_write_data *data)
3611 struct inode *inode = data->header->inode;
3613 if (nfs4_async_handle_error(task, NFS_SERVER(inode), data->args.context->state) == -EAGAIN) {
3614 rpc_restart_call_prepare(task);
3617 if (task->tk_status >= 0) {
3618 renew_lease(NFS_SERVER(inode), data->timestamp);
3619 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
3624 static bool nfs4_write_stateid_changed(struct rpc_task *task,
3625 struct nfs_writeargs *args)
3628 if (!nfs4_error_stateid_expired(task->tk_status) ||
3629 nfs4_stateid_is_current(&args->stateid,
3634 rpc_restart_call_prepare(task);
3638 static int nfs4_write_done(struct rpc_task *task, struct nfs_write_data *data)
3640 if (!nfs4_sequence_done(task, &data->res.seq_res))
3642 if (nfs4_write_stateid_changed(task, &data->args))
3644 return data->write_done_cb ? data->write_done_cb(task, data) :
3645 nfs4_write_done_cb(task, data);
3649 bool nfs4_write_need_cache_consistency_data(const struct nfs_write_data *data)
3651 const struct nfs_pgio_header *hdr = data->header;
3653 /* Don't request attributes for pNFS or O_DIRECT writes */
3654 if (data->ds_clp != NULL || hdr->dreq != NULL)
3656 /* Otherwise, request attributes if and only if we don't hold
3659 return nfs4_have_delegation(hdr->inode, FMODE_READ) == 0;
3662 static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_message *msg)
3664 struct nfs_server *server = NFS_SERVER(data->header->inode);
3666 if (!nfs4_write_need_cache_consistency_data(data)) {
3667 data->args.bitmask = NULL;
3668 data->res.fattr = NULL;
3670 data->args.bitmask = server->cache_consistency_bitmask;
3672 if (!data->write_done_cb)
3673 data->write_done_cb = nfs4_write_done_cb;
3674 data->res.server = server;
3675 data->timestamp = jiffies;
3677 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3678 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3681 static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3683 if (nfs4_setup_sequence(NFS_SERVER(data->header->inode),
3684 &data->args.seq_args,
3688 nfs4_set_rw_stateid(&data->args.stateid, data->args.context,
3689 data->args.lock_context, FMODE_WRITE);
3692 static void nfs4_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data)
3694 nfs4_setup_sequence(NFS_SERVER(data->inode),
3695 &data->args.seq_args,
3700 static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_commit_data *data)
3702 struct inode *inode = data->inode;
3704 if (nfs4_async_handle_error(task, NFS_SERVER(inode), NULL) == -EAGAIN) {
3705 rpc_restart_call_prepare(task);
3711 static int nfs4_commit_done(struct rpc_task *task, struct nfs_commit_data *data)
3713 if (!nfs4_sequence_done(task, &data->res.seq_res))
3715 return data->commit_done_cb(task, data);
3718 static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg)
3720 struct nfs_server *server = NFS_SERVER(data->inode);
3722 if (data->commit_done_cb == NULL)
3723 data->commit_done_cb = nfs4_commit_done_cb;
3724 data->res.server = server;
3725 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3726 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3729 struct nfs4_renewdata {
3730 struct nfs_client *client;
3731 unsigned long timestamp;
3735 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3736 * standalone procedure for queueing an asynchronous RENEW.
3738 static void nfs4_renew_release(void *calldata)
3740 struct nfs4_renewdata *data = calldata;
3741 struct nfs_client *clp = data->client;
3743 if (atomic_read(&clp->cl_count) > 1)
3744 nfs4_schedule_state_renewal(clp);
3745 nfs_put_client(clp);
3749 static void nfs4_renew_done(struct rpc_task *task, void *calldata)
3751 struct nfs4_renewdata *data = calldata;
3752 struct nfs_client *clp = data->client;
3753 unsigned long timestamp = data->timestamp;
3755 if (task->tk_status < 0) {
3756 /* Unless we're shutting down, schedule state recovery! */
3757 if (test_bit(NFS_CS_RENEWD, &clp->cl_res_state) == 0)
3759 if (task->tk_status != NFS4ERR_CB_PATH_DOWN) {
3760 nfs4_schedule_lease_recovery(clp);
3763 nfs4_schedule_path_down_recovery(clp);
3765 do_renew_lease(clp, timestamp);
3768 static const struct rpc_call_ops nfs4_renew_ops = {
3769 .rpc_call_done = nfs4_renew_done,
3770 .rpc_release = nfs4_renew_release,
3773 static int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
3775 struct rpc_message msg = {
3776 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3780 struct nfs4_renewdata *data;
3782 if (renew_flags == 0)
3784 if (!atomic_inc_not_zero(&clp->cl_count))
3786 data = kmalloc(sizeof(*data), GFP_NOFS);
3790 data->timestamp = jiffies;
3791 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
3792 &nfs4_renew_ops, data);
3795 static int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
3797 struct rpc_message msg = {
3798 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
3802 unsigned long now = jiffies;
3805 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
3808 do_renew_lease(clp, now);
3812 static inline int nfs4_server_supports_acls(struct nfs_server *server)
3814 return (server->caps & NFS_CAP_ACLS)
3815 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
3816 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
3819 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_SIZE, and that
3820 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_SIZE) bytes on
3823 #define NFS4ACL_MAXPAGES DIV_ROUND_UP(XATTR_SIZE_MAX, PAGE_SIZE)
3825 static int buf_to_pages_noslab(const void *buf, size_t buflen,
3826 struct page **pages, unsigned int *pgbase)
3828 struct page *newpage, **spages;
3834 len = min_t(size_t, PAGE_SIZE, buflen);
3835 newpage = alloc_page(GFP_KERNEL);
3837 if (newpage == NULL)
3839 memcpy(page_address(newpage), buf, len);
3844 } while (buflen != 0);
3850 __free_page(spages[rc-1]);
3854 struct nfs4_cached_acl {
3860 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
3862 struct nfs_inode *nfsi = NFS_I(inode);
3864 spin_lock(&inode->i_lock);
3865 kfree(nfsi->nfs4_acl);
3866 nfsi->nfs4_acl = acl;
3867 spin_unlock(&inode->i_lock);
3870 static void nfs4_zap_acl_attr(struct inode *inode)
3872 nfs4_set_cached_acl(inode, NULL);
3875 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
3877 struct nfs_inode *nfsi = NFS_I(inode);
3878 struct nfs4_cached_acl *acl;
3881 spin_lock(&inode->i_lock);
3882 acl = nfsi->nfs4_acl;
3885 if (buf == NULL) /* user is just asking for length */
3887 if (acl->cached == 0)
3889 ret = -ERANGE; /* see getxattr(2) man page */
3890 if (acl->len > buflen)
3892 memcpy(buf, acl->data, acl->len);
3896 spin_unlock(&inode->i_lock);
3900 static void nfs4_write_cached_acl(struct inode *inode, struct page **pages, size_t pgbase, size_t acl_len)
3902 struct nfs4_cached_acl *acl;
3903 size_t buflen = sizeof(*acl) + acl_len;
3905 if (buflen <= PAGE_SIZE) {
3906 acl = kmalloc(buflen, GFP_KERNEL);
3910 _copy_from_pages(acl->data, pages, pgbase, acl_len);
3912 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
3919 nfs4_set_cached_acl(inode, acl);
3923 * The getxattr API returns the required buffer length when called with a
3924 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
3925 * the required buf. On a NULL buf, we send a page of data to the server
3926 * guessing that the ACL request can be serviced by a page. If so, we cache
3927 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
3928 * the cache. If not so, we throw away the page, and cache the required
3929 * length. The next getxattr call will then produce another round trip to
3930 * the server, this time with the input buf of the required size.
3932 static ssize_t __nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
3934 struct page *pages[NFS4ACL_MAXPAGES] = {NULL, };
3935 struct nfs_getaclargs args = {
3936 .fh = NFS_FH(inode),
3940 struct nfs_getaclres res = {
3943 struct rpc_message msg = {
3944 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
3948 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
3949 int ret = -ENOMEM, i;
3951 /* As long as we're doing a round trip to the server anyway,
3952 * let's be prepared for a page of acl data. */
3955 if (npages > ARRAY_SIZE(pages))
3958 for (i = 0; i < npages; i++) {
3959 pages[i] = alloc_page(GFP_KERNEL);
3964 /* for decoding across pages */
3965 res.acl_scratch = alloc_page(GFP_KERNEL);
3966 if (!res.acl_scratch)
3969 args.acl_len = npages * PAGE_SIZE;
3970 args.acl_pgbase = 0;
3972 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3973 __func__, buf, buflen, npages, args.acl_len);
3974 ret = nfs4_call_sync(NFS_SERVER(inode)->client, NFS_SERVER(inode),
3975 &msg, &args.seq_args, &res.seq_res, 0);
3979 /* Handle the case where the passed-in buffer is too short */
3980 if (res.acl_flags & NFS4_ACL_TRUNC) {
3981 /* Did the user only issue a request for the acl length? */
3987 nfs4_write_cached_acl(inode, pages, res.acl_data_offset, res.acl_len);
3989 if (res.acl_len > buflen) {
3993 _copy_from_pages(buf, pages, res.acl_data_offset, res.acl_len);
3998 for (i = 0; i < npages; i++)
4000 __free_page(pages[i]);
4001 if (res.acl_scratch)
4002 __free_page(res.acl_scratch);
4006 static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
4008 struct nfs4_exception exception = { };
4011 ret = __nfs4_get_acl_uncached(inode, buf, buflen);
4014 ret = nfs4_handle_exception(NFS_SERVER(inode), ret, &exception);
4015 } while (exception.retry);
4019 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
4021 struct nfs_server *server = NFS_SERVER(inode);
4024 if (!nfs4_server_supports_acls(server))
4026 ret = nfs_revalidate_inode(server, inode);
4029 if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL)
4030 nfs_zap_acl_cache(inode);
4031 ret = nfs4_read_cached_acl(inode, buf, buflen);
4033 /* -ENOENT is returned if there is no ACL or if there is an ACL
4034 * but no cached acl data, just the acl length */
4036 return nfs4_get_acl_uncached(inode, buf, buflen);
4039 static int __nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4041 struct nfs_server *server = NFS_SERVER(inode);
4042 struct page *pages[NFS4ACL_MAXPAGES];
4043 struct nfs_setaclargs arg = {
4044 .fh = NFS_FH(inode),
4048 struct nfs_setaclres res;
4049 struct rpc_message msg = {
4050 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
4054 unsigned int npages = DIV_ROUND_UP(buflen, PAGE_SIZE);
4057 if (!nfs4_server_supports_acls(server))
4059 if (npages > ARRAY_SIZE(pages))
4061 i = buf_to_pages_noslab(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
4064 nfs4_inode_return_delegation(inode);
4065 ret = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4068 * Free each page after tx, so the only ref left is
4069 * held by the network stack
4072 put_page(pages[i-1]);
4075 * Acl update can result in inode attribute update.
4076 * so mark the attribute cache invalid.
4078 spin_lock(&inode->i_lock);
4079 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATTR;
4080 spin_unlock(&inode->i_lock);
4081 nfs_access_zap_cache(inode);
4082 nfs_zap_acl_cache(inode);
4086 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
4088 struct nfs4_exception exception = { };
4091 err = nfs4_handle_exception(NFS_SERVER(inode),
4092 __nfs4_proc_set_acl(inode, buf, buflen),
4094 } while (exception.retry);
4099 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, struct nfs4_state *state)
4101 struct nfs_client *clp = server->nfs_client;
4103 if (task->tk_status >= 0)
4105 switch(task->tk_status) {
4106 case -NFS4ERR_DELEG_REVOKED:
4107 case -NFS4ERR_ADMIN_REVOKED:
4108 case -NFS4ERR_BAD_STATEID:
4111 nfs_remove_bad_delegation(state->inode);
4112 case -NFS4ERR_OPENMODE:
4115 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4116 goto stateid_invalid;
4117 goto wait_on_recovery;
4118 case -NFS4ERR_EXPIRED:
4119 if (state != NULL) {
4120 if (nfs4_schedule_stateid_recovery(server, state) < 0)
4121 goto stateid_invalid;
4123 case -NFS4ERR_STALE_STATEID:
4124 case -NFS4ERR_STALE_CLIENTID:
4125 nfs4_schedule_lease_recovery(clp);
4126 goto wait_on_recovery;
4127 #if defined(CONFIG_NFS_V4_1)
4128 case -NFS4ERR_BADSESSION:
4129 case -NFS4ERR_BADSLOT:
4130 case -NFS4ERR_BAD_HIGH_SLOT:
4131 case -NFS4ERR_DEADSESSION:
4132 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
4133 case -NFS4ERR_SEQ_FALSE_RETRY:
4134 case -NFS4ERR_SEQ_MISORDERED:
4135 dprintk("%s ERROR %d, Reset session\n", __func__,
4137 nfs4_schedule_session_recovery(clp->cl_session, task->tk_status);
4138 task->tk_status = 0;
4140 #endif /* CONFIG_NFS_V4_1 */
4141 case -NFS4ERR_DELAY:
4142 nfs_inc_server_stats(server, NFSIOS_DELAY);
4143 case -NFS4ERR_GRACE:
4144 rpc_delay(task, NFS4_POLL_RETRY_MAX);
4145 task->tk_status = 0;
4147 case -NFS4ERR_RETRY_UNCACHED_REP:
4148 case -NFS4ERR_OLD_STATEID:
4149 task->tk_status = 0;
4152 task->tk_status = nfs4_map_errors(task->tk_status);
4155 task->tk_status = -EIO;
4158 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
4159 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
4160 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
4161 task->tk_status = 0;
4165 static void nfs4_init_boot_verifier(const struct nfs_client *clp,
4166 nfs4_verifier *bootverf)
4170 if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
4171 /* An impossible timestamp guarantees this value
4172 * will never match a generated boot time. */
4174 verf[1] = (__be32)(NSEC_PER_SEC + 1);
4176 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
4177 verf[0] = (__be32)nn->boot_time.tv_sec;
4178 verf[1] = (__be32)nn->boot_time.tv_nsec;
4180 memcpy(bootverf->data, verf, sizeof(bootverf->data));
4184 nfs4_init_nonuniform_client_string(const struct nfs_client *clp,
4185 char *buf, size_t len)
4187 unsigned int result;
4190 result = scnprintf(buf, len, "Linux NFSv4.0 %s/%s %s",
4192 rpc_peeraddr2str(clp->cl_rpcclient,
4194 rpc_peeraddr2str(clp->cl_rpcclient,
4195 RPC_DISPLAY_PROTO));
4201 nfs4_init_uniform_client_string(const struct nfs_client *clp,
4202 char *buf, size_t len)
4204 char *nodename = clp->cl_rpcclient->cl_nodename;
4206 if (nfs4_client_id_uniquifier[0] != '\0')
4207 nodename = nfs4_client_id_uniquifier;
4208 return scnprintf(buf, len, "Linux NFSv%u.%u %s",
4209 clp->rpc_ops->version, clp->cl_minorversion,
4214 * nfs4_proc_setclientid - Negotiate client ID
4215 * @clp: state data structure
4216 * @program: RPC program for NFSv4 callback service
4217 * @port: IP port number for NFS4 callback service
4218 * @cred: RPC credential to use for this call
4219 * @res: where to place the result
4221 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4223 int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
4224 unsigned short port, struct rpc_cred *cred,
4225 struct nfs4_setclientid_res *res)
4227 nfs4_verifier sc_verifier;
4228 struct nfs4_setclientid setclientid = {
4229 .sc_verifier = &sc_verifier,
4231 .sc_cb_ident = clp->cl_cb_ident,
4233 struct rpc_message msg = {
4234 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
4235 .rpc_argp = &setclientid,
4241 /* nfs_client_id4 */
4242 nfs4_init_boot_verifier(clp, &sc_verifier);
4243 if (test_bit(NFS_CS_MIGRATION, &clp->cl_flags))
4244 setclientid.sc_name_len =
4245 nfs4_init_uniform_client_string(clp,
4246 setclientid.sc_name,
4247 sizeof(setclientid.sc_name));
4249 setclientid.sc_name_len =
4250 nfs4_init_nonuniform_client_string(clp,
4251 setclientid.sc_name,
4252 sizeof(setclientid.sc_name));
4255 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
4256 sizeof(setclientid.sc_netid),
4257 rpc_peeraddr2str(clp->cl_rpcclient,
4258 RPC_DISPLAY_NETID));
4260 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
4261 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
4262 clp->cl_ipaddr, port >> 8, port & 255);
4264 dprintk("NFS call setclientid auth=%s, '%.*s'\n",
4265 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4266 setclientid.sc_name_len, setclientid.sc_name);
4267 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4268 dprintk("NFS reply setclientid: %d\n", status);
4273 * nfs4_proc_setclientid_confirm - Confirm client ID
4274 * @clp: state data structure
4275 * @res: result of a previous SETCLIENTID
4276 * @cred: RPC credential to use for this call
4278 * Returns zero, a negative errno, or a negative NFS4ERR status code.
4280 int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
4281 struct nfs4_setclientid_res *arg,
4282 struct rpc_cred *cred)
4284 struct nfs_fsinfo fsinfo;
4285 struct rpc_message msg = {
4286 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
4288 .rpc_resp = &fsinfo,
4294 dprintk("NFS call setclientid_confirm auth=%s, (client ID %llx)\n",
4295 clp->cl_rpcclient->cl_auth->au_ops->au_name,
4298 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4300 spin_lock(&clp->cl_lock);
4301 clp->cl_lease_time = fsinfo.lease_time * HZ;
4302 clp->cl_last_renewal = now;
4303 spin_unlock(&clp->cl_lock);
4305 dprintk("NFS reply setclientid_confirm: %d\n", status);
4309 struct nfs4_delegreturndata {
4310 struct nfs4_delegreturnargs args;
4311 struct nfs4_delegreturnres res;
4313 nfs4_stateid stateid;
4314 unsigned long timestamp;
4315 struct nfs_fattr fattr;
4319 static void nfs4_delegreturn_done(struct rpc_task *task, void *calldata)
4321 struct nfs4_delegreturndata *data = calldata;
4323 if (!nfs4_sequence_done(task, &data->res.seq_res))
4326 switch (task->tk_status) {
4327 case -NFS4ERR_STALE_STATEID:
4328 case -NFS4ERR_EXPIRED:
4330 renew_lease(data->res.server, data->timestamp);
4333 if (nfs4_async_handle_error(task, data->res.server, NULL) ==
4335 rpc_restart_call_prepare(task);
4339 data->rpc_status = task->tk_status;
4342 static void nfs4_delegreturn_release(void *calldata)
4347 #if defined(CONFIG_NFS_V4_1)
4348 static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
4350 struct nfs4_delegreturndata *d_data;
4352 d_data = (struct nfs4_delegreturndata *)data;
4354 nfs4_setup_sequence(d_data->res.server,
4355 &d_data->args.seq_args,
4356 &d_data->res.seq_res,
4359 #endif /* CONFIG_NFS_V4_1 */
4361 static const struct rpc_call_ops nfs4_delegreturn_ops = {
4362 #if defined(CONFIG_NFS_V4_1)
4363 .rpc_call_prepare = nfs4_delegreturn_prepare,
4364 #endif /* CONFIG_NFS_V4_1 */
4365 .rpc_call_done = nfs4_delegreturn_done,
4366 .rpc_release = nfs4_delegreturn_release,
4369 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4371 struct nfs4_delegreturndata *data;
4372 struct nfs_server *server = NFS_SERVER(inode);
4373 struct rpc_task *task;
4374 struct rpc_message msg = {
4375 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
4378 struct rpc_task_setup task_setup_data = {
4379 .rpc_client = server->client,
4380 .rpc_message = &msg,
4381 .callback_ops = &nfs4_delegreturn_ops,
4382 .flags = RPC_TASK_ASYNC,
4386 data = kzalloc(sizeof(*data), GFP_NOFS);
4389 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
4390 data->args.fhandle = &data->fh;
4391 data->args.stateid = &data->stateid;
4392 data->args.bitmask = server->cache_consistency_bitmask;
4393 nfs_copy_fh(&data->fh, NFS_FH(inode));
4394 nfs4_stateid_copy(&data->stateid, stateid);
4395 data->res.fattr = &data->fattr;
4396 data->res.server = server;
4397 nfs_fattr_init(data->res.fattr);
4398 data->timestamp = jiffies;
4399 data->rpc_status = 0;
4401 task_setup_data.callback_data = data;
4402 msg.rpc_argp = &data->args;
4403 msg.rpc_resp = &data->res;
4404 task = rpc_run_task(&task_setup_data);
4406 return PTR_ERR(task);
4409 status = nfs4_wait_for_completion_rpc_task(task);
4412 status = data->rpc_status;
4414 nfs_post_op_update_inode_force_wcc(inode, &data->fattr);
4416 nfs_refresh_inode(inode, &data->fattr);
4422 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
4424 struct nfs_server *server = NFS_SERVER(inode);
4425 struct nfs4_exception exception = { };
4428 err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
4430 case -NFS4ERR_STALE_STATEID:
4431 case -NFS4ERR_EXPIRED:
4435 err = nfs4_handle_exception(server, err, &exception);
4436 } while (exception.retry);
4440 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
4441 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
4444 * sleep, with exponential backoff, and retry the LOCK operation.
4446 static unsigned long
4447 nfs4_set_lock_task_retry(unsigned long timeout)
4449 freezable_schedule_timeout_killable(timeout);
4451 if (timeout > NFS4_LOCK_MAXTIMEOUT)
4452 return NFS4_LOCK_MAXTIMEOUT;
4456 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4458 struct inode *inode = state->inode;
4459 struct nfs_server *server = NFS_SERVER(inode);
4460 struct nfs_client *clp = server->nfs_client;
4461 struct nfs_lockt_args arg = {
4462 .fh = NFS_FH(inode),
4465 struct nfs_lockt_res res = {
4468 struct rpc_message msg = {
4469 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
4472 .rpc_cred = state->owner->so_cred,
4474 struct nfs4_lock_state *lsp;
4477 arg.lock_owner.clientid = clp->cl_clientid;
4478 status = nfs4_set_lock_state(state, request);
4481 lsp = request->fl_u.nfs4_fl.owner;
4482 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4483 arg.lock_owner.s_dev = server->s_dev;
4484 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4487 request->fl_type = F_UNLCK;
4489 case -NFS4ERR_DENIED:
4492 request->fl_ops->fl_release_private(request);
4497 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4499 struct nfs4_exception exception = { };
4503 err = nfs4_handle_exception(NFS_SERVER(state->inode),
4504 _nfs4_proc_getlk(state, cmd, request),
4506 } while (exception.retry);
4510 static int do_vfs_lock(struct file *file, struct file_lock *fl)
4513 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
4515 res = posix_lock_file_wait(file, fl);
4518 res = flock_lock_file_wait(file, fl);
4526 struct nfs4_unlockdata {
4527 struct nfs_locku_args arg;
4528 struct nfs_locku_res res;
4529 struct nfs4_lock_state *lsp;
4530 struct nfs_open_context *ctx;
4531 struct file_lock fl;
4532 const struct nfs_server *server;
4533 unsigned long timestamp;
4536 static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
4537 struct nfs_open_context *ctx,
4538 struct nfs4_lock_state *lsp,
4539 struct nfs_seqid *seqid)
4541 struct nfs4_unlockdata *p;
4542 struct inode *inode = lsp->ls_state->inode;
4544 p = kzalloc(sizeof(*p), GFP_NOFS);
4547 p->arg.fh = NFS_FH(inode);
4549 p->arg.seqid = seqid;
4550 p->res.seqid = seqid;
4551 p->arg.stateid = &lsp->ls_stateid;
4553 atomic_inc(&lsp->ls_count);
4554 /* Ensure we don't close file until we're done freeing locks! */
4555 p->ctx = get_nfs_open_context(ctx);
4556 memcpy(&p->fl, fl, sizeof(p->fl));
4557 p->server = NFS_SERVER(inode);
4561 static void nfs4_locku_release_calldata(void *data)
4563 struct nfs4_unlockdata *calldata = data;
4564 nfs_free_seqid(calldata->arg.seqid);
4565 nfs4_put_lock_state(calldata->lsp);
4566 put_nfs_open_context(calldata->ctx);
4570 static void nfs4_locku_done(struct rpc_task *task, void *data)
4572 struct nfs4_unlockdata *calldata = data;
4574 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
4576 switch (task->tk_status) {
4578 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4579 &calldata->res.stateid);
4580 renew_lease(calldata->server, calldata->timestamp);
4582 case -NFS4ERR_BAD_STATEID:
4583 case -NFS4ERR_OLD_STATEID:
4584 case -NFS4ERR_STALE_STATEID:
4585 case -NFS4ERR_EXPIRED:
4588 if (nfs4_async_handle_error(task, calldata->server, NULL) == -EAGAIN)
4589 rpc_restart_call_prepare(task);
4591 nfs_release_seqid(calldata->arg.seqid);
4594 static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4596 struct nfs4_unlockdata *calldata = data;
4598 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
4600 if (test_bit(NFS_LOCK_INITIALIZED, &calldata->lsp->ls_flags) == 0) {
4601 /* Note: exit _without_ running nfs4_locku_done */
4604 calldata->timestamp = jiffies;
4605 if (nfs4_setup_sequence(calldata->server,
4606 &calldata->arg.seq_args,
4607 &calldata->res.seq_res,
4609 nfs_release_seqid(calldata->arg.seqid);
4612 task->tk_action = NULL;
4614 nfs4_sequence_done(task, &calldata->res.seq_res);
4617 static const struct rpc_call_ops nfs4_locku_ops = {
4618 .rpc_call_prepare = nfs4_locku_prepare,
4619 .rpc_call_done = nfs4_locku_done,
4620 .rpc_release = nfs4_locku_release_calldata,
4623 static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4624 struct nfs_open_context *ctx,
4625 struct nfs4_lock_state *lsp,
4626 struct nfs_seqid *seqid)
4628 struct nfs4_unlockdata *data;
4629 struct rpc_message msg = {
4630 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
4631 .rpc_cred = ctx->cred,
4633 struct rpc_task_setup task_setup_data = {
4634 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
4635 .rpc_message = &msg,
4636 .callback_ops = &nfs4_locku_ops,
4637 .workqueue = nfsiod_workqueue,
4638 .flags = RPC_TASK_ASYNC,
4641 /* Ensure this is an unlock - when canceling a lock, the
4642 * canceled lock is passed in, and it won't be an unlock.
4644 fl->fl_type = F_UNLCK;
4646 data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
4648 nfs_free_seqid(seqid);
4649 return ERR_PTR(-ENOMEM);
4652 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4653 msg.rpc_argp = &data->arg;
4654 msg.rpc_resp = &data->res;
4655 task_setup_data.callback_data = data;
4656 return rpc_run_task(&task_setup_data);
4659 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
4661 struct inode *inode = state->inode;
4662 struct nfs4_state_owner *sp = state->owner;
4663 struct nfs_inode *nfsi = NFS_I(inode);
4664 struct nfs_seqid *seqid;
4665 struct nfs4_lock_state *lsp;
4666 struct rpc_task *task;
4668 unsigned char fl_flags = request->fl_flags;
4670 status = nfs4_set_lock_state(state, request);
4671 /* Unlock _before_ we do the RPC call */
4672 request->fl_flags |= FL_EXISTS;
4673 /* Exclude nfs_delegation_claim_locks() */
4674 mutex_lock(&sp->so_delegreturn_mutex);
4675 /* Exclude nfs4_reclaim_open_stateid() - note nesting! */
4676 down_read(&nfsi->rwsem);
4677 if (do_vfs_lock(request->fl_file, request) == -ENOENT) {
4678 up_read(&nfsi->rwsem);
4679 mutex_unlock(&sp->so_delegreturn_mutex);
4682 up_read(&nfsi->rwsem);
4683 mutex_unlock(&sp->so_delegreturn_mutex);
4686 /* Is this a delegated lock? */
4687 if (test_bit(NFS_DELEGATED_STATE, &state->flags))
4689 lsp = request->fl_u.nfs4_fl.owner;
4690 seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
4694 task = nfs4_do_unlck(request, nfs_file_open_context(request->fl_file), lsp, seqid);
4695 status = PTR_ERR(task);
4698 status = nfs4_wait_for_completion_rpc_task(task);
4701 request->fl_flags = fl_flags;
4705 struct nfs4_lockdata {
4706 struct nfs_lock_args arg;
4707 struct nfs_lock_res res;
4708 struct nfs4_lock_state *lsp;
4709 struct nfs_open_context *ctx;
4710 struct file_lock fl;
4711 unsigned long timestamp;
4714 struct nfs_server *server;
4717 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4718 struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
4721 struct nfs4_lockdata *p;
4722 struct inode *inode = lsp->ls_state->inode;
4723 struct nfs_server *server = NFS_SERVER(inode);
4725 p = kzalloc(sizeof(*p), gfp_mask);
4729 p->arg.fh = NFS_FH(inode);
4731 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
4732 if (p->arg.open_seqid == NULL)
4734 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
4735 if (p->arg.lock_seqid == NULL)
4736 goto out_free_seqid;
4737 p->arg.lock_stateid = &lsp->ls_stateid;
4738 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4739 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4740 p->arg.lock_owner.s_dev = server->s_dev;
4741 p->res.lock_seqid = p->arg.lock_seqid;
4744 atomic_inc(&lsp->ls_count);
4745 p->ctx = get_nfs_open_context(ctx);
4746 memcpy(&p->fl, fl, sizeof(p->fl));
4749 nfs_free_seqid(p->arg.open_seqid);
4755 static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4757 struct nfs4_lockdata *data = calldata;
4758 struct nfs4_state *state = data->lsp->ls_state;
4760 dprintk("%s: begin!\n", __func__);
4761 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
4763 /* Do we need to do an open_to_lock_owner? */
4764 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
4765 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0) {
4766 goto out_release_lock_seqid;
4768 data->arg.open_stateid = &state->stateid;
4769 data->arg.new_lock_owner = 1;
4770 data->res.open_seqid = data->arg.open_seqid;
4772 data->arg.new_lock_owner = 0;
4773 if (!nfs4_valid_open_stateid(state)) {
4774 data->rpc_status = -EBADF;
4775 task->tk_action = NULL;
4776 goto out_release_open_seqid;
4778 data->timestamp = jiffies;
4779 if (nfs4_setup_sequence(data->server,
4780 &data->arg.seq_args,
4784 out_release_open_seqid:
4785 nfs_release_seqid(data->arg.open_seqid);
4786 out_release_lock_seqid:
4787 nfs_release_seqid(data->arg.lock_seqid);
4789 nfs4_sequence_done(task, &data->res.seq_res);
4790 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
4793 static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4795 struct nfs4_lockdata *data = calldata;
4797 dprintk("%s: begin!\n", __func__);
4799 if (!nfs4_sequence_done(task, &data->res.seq_res))
4802 data->rpc_status = task->tk_status;
4803 if (data->arg.new_lock_owner != 0) {
4804 if (data->rpc_status == 0)
4805 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
4809 if (data->rpc_status == 0) {
4810 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4811 set_bit(NFS_LOCK_INITIALIZED, &data->lsp->ls_flags);
4812 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4815 dprintk("%s: done, ret = %d!\n", __func__, data->rpc_status);
4818 static void nfs4_lock_release(void *calldata)
4820 struct nfs4_lockdata *data = calldata;
4822 dprintk("%s: begin!\n", __func__);
4823 nfs_free_seqid(data->arg.open_seqid);
4824 if (data->cancelled != 0) {
4825 struct rpc_task *task;
4826 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
4827 data->arg.lock_seqid);
4829 rpc_put_task_async(task);
4830 dprintk("%s: cancelling lock!\n", __func__);
4832 nfs_free_seqid(data->arg.lock_seqid);
4833 nfs4_put_lock_state(data->lsp);
4834 put_nfs_open_context(data->ctx);
4836 dprintk("%s: done!\n", __func__);
4839 static const struct rpc_call_ops nfs4_lock_ops = {
4840 .rpc_call_prepare = nfs4_lock_prepare,
4841 .rpc_call_done = nfs4_lock_done,
4842 .rpc_release = nfs4_lock_release,
4845 static void nfs4_handle_setlk_error(struct nfs_server *server, struct nfs4_lock_state *lsp, int new_lock_owner, int error)
4848 case -NFS4ERR_ADMIN_REVOKED:
4849 case -NFS4ERR_BAD_STATEID:
4850 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4851 if (new_lock_owner != 0 ||
4852 test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0)
4853 nfs4_schedule_stateid_recovery(server, lsp->ls_state);
4855 case -NFS4ERR_STALE_STATEID:
4856 lsp->ls_seqid.flags &= ~NFS_SEQID_CONFIRMED;
4857 case -NFS4ERR_EXPIRED:
4858 nfs4_schedule_lease_recovery(server->nfs_client);
4862 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *fl, int recovery_type)
4864 struct nfs4_lockdata *data;
4865 struct rpc_task *task;
4866 struct rpc_message msg = {
4867 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
4868 .rpc_cred = state->owner->so_cred,
4870 struct rpc_task_setup task_setup_data = {
4871 .rpc_client = NFS_CLIENT(state->inode),
4872 .rpc_message = &msg,
4873 .callback_ops = &nfs4_lock_ops,
4874 .workqueue = nfsiod_workqueue,
4875 .flags = RPC_TASK_ASYNC,
4879 dprintk("%s: begin!\n", __func__);
4880 data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
4881 fl->fl_u.nfs4_fl.owner,
4882 recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
4886 data->arg.block = 1;
4887 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4888 msg.rpc_argp = &data->arg;
4889 msg.rpc_resp = &data->res;
4890 task_setup_data.callback_data = data;
4891 if (recovery_type > NFS_LOCK_NEW) {
4892 if (recovery_type == NFS_LOCK_RECLAIM)
4893 data->arg.reclaim = NFS_LOCK_RECLAIM;
4894 nfs4_set_sequence_privileged(&data->arg.seq_args);
4896 task = rpc_run_task(&task_setup_data);
4898 return PTR_ERR(task);
4899 ret = nfs4_wait_for_completion_rpc_task(task);
4901 ret = data->rpc_status;
4903 nfs4_handle_setlk_error(data->server, data->lsp,
4904 data->arg.new_lock_owner, ret);
4906 data->cancelled = 1;
4908 dprintk("%s: done, ret = %d!\n", __func__, ret);
4912 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
4914 struct nfs_server *server = NFS_SERVER(state->inode);
4915 struct nfs4_exception exception = {
4916 .inode = state->inode,
4921 /* Cache the lock if possible... */
4922 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4924 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_RECLAIM);
4925 if (err != -NFS4ERR_DELAY)
4927 nfs4_handle_exception(server, err, &exception);
4928 } while (exception.retry);
4932 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
4934 struct nfs_server *server = NFS_SERVER(state->inode);
4935 struct nfs4_exception exception = {
4936 .inode = state->inode,
4940 err = nfs4_set_lock_state(state, request);
4944 if (test_bit(NFS_DELEGATED_STATE, &state->flags) != 0)
4946 err = _nfs4_do_setlk(state, F_SETLK, request, NFS_LOCK_EXPIRED);
4950 case -NFS4ERR_GRACE:
4951 case -NFS4ERR_DELAY:
4952 nfs4_handle_exception(server, err, &exception);
4955 } while (exception.retry);
4960 #if defined(CONFIG_NFS_V4_1)
4962 * nfs41_check_expired_locks - possibly free a lock stateid
4964 * @state: NFSv4 state for an inode
4966 * Returns NFS_OK if recovery for this stateid is now finished.
4967 * Otherwise a negative NFS4ERR value is returned.
4969 static int nfs41_check_expired_locks(struct nfs4_state *state)
4971 int status, ret = -NFS4ERR_BAD_STATEID;
4972 struct nfs4_lock_state *lsp;
4973 struct nfs_server *server = NFS_SERVER(state->inode);
4975 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4976 if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
4977 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4978 if (status != NFS_OK) {
4979 /* Free the stateid unless the server
4980 * informs us the stateid is unrecognized. */
4981 if (status != -NFS4ERR_BAD_STATEID)
4982 nfs41_free_stateid(server,
4984 clear_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags);
4993 static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
4995 int status = NFS_OK;
4997 if (test_bit(LK_STATE_IN_USE, &state->flags))
4998 status = nfs41_check_expired_locks(state);
4999 if (status != NFS_OK)
5000 status = nfs4_lock_expired(state, request);
5005 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5007 struct nfs4_state_owner *sp = state->owner;
5008 struct nfs_inode *nfsi = NFS_I(state->inode);
5009 unsigned char fl_flags = request->fl_flags;
5011 int status = -ENOLCK;
5013 if ((fl_flags & FL_POSIX) &&
5014 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
5016 /* Is this a delegated open? */
5017 status = nfs4_set_lock_state(state, request);
5020 request->fl_flags |= FL_ACCESS;
5021 status = do_vfs_lock(request->fl_file, request);
5024 down_read(&nfsi->rwsem);
5025 if (test_bit(NFS_DELEGATED_STATE, &state->flags)) {
5026 /* Yes: cache locks! */
5027 /* ...but avoid races with delegation recall... */
5028 request->fl_flags = fl_flags & ~FL_SLEEP;
5029 status = do_vfs_lock(request->fl_file, request);
5032 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
5033 up_read(&nfsi->rwsem);
5034 status = _nfs4_do_setlk(state, cmd, request, NFS_LOCK_NEW);
5037 down_read(&nfsi->rwsem);
5038 if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq)) {
5039 status = -NFS4ERR_DELAY;
5042 /* Note: we always want to sleep here! */
5043 request->fl_flags = fl_flags | FL_SLEEP;
5044 if (do_vfs_lock(request->fl_file, request) < 0)
5045 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
5046 "manager!\n", __func__);
5048 up_read(&nfsi->rwsem);
5050 request->fl_flags = fl_flags;
5054 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
5056 struct nfs4_exception exception = {
5058 .inode = state->inode,
5063 err = _nfs4_proc_setlk(state, cmd, request);
5064 if (err == -NFS4ERR_DENIED)
5066 err = nfs4_handle_exception(NFS_SERVER(state->inode),
5068 } while (exception.retry);
5073 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
5075 struct nfs_open_context *ctx;
5076 struct nfs4_state *state;
5077 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
5080 /* verify open state */
5081 ctx = nfs_file_open_context(filp);
5084 if (request->fl_start < 0 || request->fl_end < 0)
5087 if (IS_GETLK(cmd)) {
5089 return nfs4_proc_getlk(state, F_GETLK, request);
5093 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
5096 if (request->fl_type == F_UNLCK) {
5098 return nfs4_proc_unlck(state, cmd, request);
5105 * Don't rely on the VFS having checked the file open mode,
5106 * since it won't do this for flock() locks.
5108 switch (request->fl_type) {
5110 if (!(filp->f_mode & FMODE_READ))
5114 if (!(filp->f_mode & FMODE_WRITE))
5119 status = nfs4_proc_setlk(state, cmd, request);
5120 if ((status != -EAGAIN) || IS_SETLK(cmd))
5122 timeout = nfs4_set_lock_task_retry(timeout);
5123 status = -ERESTARTSYS;
5126 } while(status < 0);
5130 int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
5132 struct nfs_server *server = NFS_SERVER(state->inode);
5135 err = nfs4_set_lock_state(state, fl);
5138 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
5141 printk(KERN_ERR "NFS: %s: unhandled error "
5142 "%d.\n", __func__, err);
5146 case -NFS4ERR_STALE_CLIENTID:
5147 case -NFS4ERR_STALE_STATEID:
5148 set_bit(NFS_DELEGATED_STATE, &state->flags);
5149 case -NFS4ERR_EXPIRED:
5150 nfs4_schedule_lease_recovery(server->nfs_client);
5152 case -NFS4ERR_BADSESSION:
5153 case -NFS4ERR_BADSLOT:
5154 case -NFS4ERR_BAD_HIGH_SLOT:
5155 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
5156 case -NFS4ERR_DEADSESSION:
5157 set_bit(NFS_DELEGATED_STATE, &state->flags);
5158 nfs4_schedule_session_recovery(server->nfs_client->cl_session, err);
5160 case -NFS4ERR_DELEG_REVOKED:
5161 case -NFS4ERR_ADMIN_REVOKED:
5162 case -NFS4ERR_BAD_STATEID:
5163 case -NFS4ERR_OPENMODE:
5164 nfs4_schedule_stateid_recovery(server, state);
5166 case -NFS4ERR_DELAY:
5167 case -NFS4ERR_GRACE:
5168 set_bit(NFS_DELEGATED_STATE, &state->flags);
5172 case -NFS4ERR_DENIED:
5173 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
5180 struct nfs_release_lockowner_data {
5181 struct nfs4_lock_state *lsp;
5182 struct nfs_server *server;
5183 struct nfs_release_lockowner_args args;
5186 static void nfs4_release_lockowner_release(void *calldata)
5188 struct nfs_release_lockowner_data *data = calldata;
5189 nfs4_free_lock_state(data->server, data->lsp);
5193 static const struct rpc_call_ops nfs4_release_lockowner_ops = {
5194 .rpc_release = nfs4_release_lockowner_release,
5197 int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
5199 struct nfs_server *server = lsp->ls_state->owner->so_server;
5200 struct nfs_release_lockowner_data *data;
5201 struct rpc_message msg = {
5202 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
5205 if (server->nfs_client->cl_mvops->minor_version != 0)
5207 data = kmalloc(sizeof(*data), GFP_NOFS);
5211 data->server = server;
5212 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
5213 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
5214 data->args.lock_owner.s_dev = server->s_dev;
5215 msg.rpc_argp = &data->args;
5216 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
5220 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
5222 static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key,
5223 const void *buf, size_t buflen,
5224 int flags, int type)
5226 if (strcmp(key, "") != 0)
5229 return nfs4_proc_set_acl(dentry->d_inode, buf, buflen);
5232 static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key,
5233 void *buf, size_t buflen, int type)
5235 if (strcmp(key, "") != 0)
5238 return nfs4_proc_get_acl(dentry->d_inode, buf, buflen);
5241 static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list,
5242 size_t list_len, const char *name,
5243 size_t name_len, int type)
5245 size_t len = sizeof(XATTR_NAME_NFSV4_ACL);
5247 if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode)))
5250 if (list && len <= list_len)
5251 memcpy(list, XATTR_NAME_NFSV4_ACL, len);
5256 * nfs_fhget will use either the mounted_on_fileid or the fileid
5258 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
5260 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
5261 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
5262 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
5263 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
5266 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
5267 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
5268 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
5272 static int _nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5273 const struct qstr *name,
5274 struct nfs4_fs_locations *fs_locations,
5277 struct nfs_server *server = NFS_SERVER(dir);
5279 [0] = FATTR4_WORD0_FSID | FATTR4_WORD0_FS_LOCATIONS,
5281 struct nfs4_fs_locations_arg args = {
5282 .dir_fh = NFS_FH(dir),
5287 struct nfs4_fs_locations_res res = {
5288 .fs_locations = fs_locations,
5290 struct rpc_message msg = {
5291 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FS_LOCATIONS],
5297 dprintk("%s: start\n", __func__);
5299 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
5300 * is not supported */
5301 if (NFS_SERVER(dir)->attr_bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)
5302 bitmask[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID;
5304 bitmask[0] |= FATTR4_WORD0_FILEID;
5306 nfs_fattr_init(&fs_locations->fattr);
5307 fs_locations->server = server;
5308 fs_locations->nlocations = 0;
5309 status = nfs4_call_sync(client, server, &msg, &args.seq_args, &res.seq_res, 0);
5310 dprintk("%s: returned status = %d\n", __func__, status);
5314 int nfs4_proc_fs_locations(struct rpc_clnt *client, struct inode *dir,
5315 const struct qstr *name,
5316 struct nfs4_fs_locations *fs_locations,
5319 struct nfs4_exception exception = { };
5322 err = nfs4_handle_exception(NFS_SERVER(dir),
5323 _nfs4_proc_fs_locations(client, dir, name, fs_locations, page),
5325 } while (exception.retry);
5329 static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors)
5332 struct nfs4_secinfo_arg args = {
5333 .dir_fh = NFS_FH(dir),
5336 struct nfs4_secinfo_res res = {
5339 struct rpc_message msg = {
5340 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO],
5345 dprintk("NFS call secinfo %s\n", name->name);
5346 status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &msg, &args.seq_args, &res.seq_res, 0);
5347 dprintk("NFS reply secinfo: %d\n", status);
5351 int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
5352 struct nfs4_secinfo_flavors *flavors)
5354 struct nfs4_exception exception = { };
5357 err = nfs4_handle_exception(NFS_SERVER(dir),
5358 _nfs4_proc_secinfo(dir, name, flavors),
5360 } while (exception.retry);
5364 #ifdef CONFIG_NFS_V4_1
5366 * Check the exchange flags returned by the server for invalid flags, having
5367 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
5370 static int nfs4_check_cl_exchange_flags(u32 flags)
5372 if (flags & ~EXCHGID4_FLAG_MASK_R)
5374 if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) &&
5375 (flags & EXCHGID4_FLAG_USE_NON_PNFS))
5377 if (!(flags & (EXCHGID4_FLAG_MASK_PNFS)))
5381 return -NFS4ERR_INVAL;
5385 nfs41_same_server_scope(struct nfs41_server_scope *a,
5386 struct nfs41_server_scope *b)
5388 if (a->server_scope_sz == b->server_scope_sz &&
5389 memcmp(a->server_scope, b->server_scope, a->server_scope_sz) == 0)
5396 * nfs4_proc_bind_conn_to_session()
5398 * The 4.1 client currently uses the same TCP connection for the
5399 * fore and backchannel.
5401 int nfs4_proc_bind_conn_to_session(struct nfs_client *clp, struct rpc_cred *cred)
5404 struct nfs41_bind_conn_to_session_res res;
5405 struct rpc_message msg = {
5407 &nfs4_procedures[NFSPROC4_CLNT_BIND_CONN_TO_SESSION],
5413 dprintk("--> %s\n", __func__);
5415 res.session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
5416 if (unlikely(res.session == NULL)) {
5421 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5423 if (memcmp(res.session->sess_id.data,
5424 clp->cl_session->sess_id.data, NFS4_MAX_SESSIONID_LEN)) {
5425 dprintk("NFS: %s: Session ID mismatch\n", __func__);
5429 if (res.dir != NFS4_CDFS4_BOTH) {
5430 dprintk("NFS: %s: Unexpected direction from server\n",
5435 if (res.use_conn_in_rdma_mode) {
5436 dprintk("NFS: %s: Server returned RDMA mode = true\n",
5445 dprintk("<-- %s status= %d\n", __func__, status);
5450 * nfs4_proc_exchange_id()
5452 * Returns zero, a negative errno, or a negative NFS4ERR status code.
5454 * Since the clientid has expired, all compounds using sessions
5455 * associated with the stale clientid will be returning
5456 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
5457 * be in some phase of session reset.
5459 int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
5461 nfs4_verifier verifier;
5462 struct nfs41_exchange_id_args args = {
5463 .verifier = &verifier,
5465 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
5467 struct nfs41_exchange_id_res res = {
5471 struct rpc_message msg = {
5472 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_EXCHANGE_ID],
5478 nfs4_init_boot_verifier(clp, &verifier);
5479 args.id_len = nfs4_init_uniform_client_string(clp, args.id,
5481 dprintk("NFS call exchange_id auth=%s, '%.*s'\n",
5482 clp->cl_rpcclient->cl_auth->au_ops->au_name,
5483 args.id_len, args.id);
5485 res.server_owner = kzalloc(sizeof(struct nfs41_server_owner),
5487 if (unlikely(res.server_owner == NULL)) {
5492 res.server_scope = kzalloc(sizeof(struct nfs41_server_scope),
5494 if (unlikely(res.server_scope == NULL)) {
5496 goto out_server_owner;
5499 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_NOFS);
5500 if (unlikely(res.impl_id == NULL)) {
5502 goto out_server_scope;
5505 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5507 status = nfs4_check_cl_exchange_flags(res.flags);
5510 clp->cl_clientid = res.clientid;
5511 clp->cl_exchange_flags = (res.flags & ~EXCHGID4_FLAG_CONFIRMED_R);
5512 if (!(res.flags & EXCHGID4_FLAG_CONFIRMED_R))
5513 clp->cl_seqid = res.seqid;
5515 kfree(clp->cl_serverowner);
5516 clp->cl_serverowner = res.server_owner;
5517 res.server_owner = NULL;
5519 /* use the most recent implementation id */
5520 kfree(clp->cl_implid);
5521 clp->cl_implid = res.impl_id;
5523 if (clp->cl_serverscope != NULL &&
5524 !nfs41_same_server_scope(clp->cl_serverscope,
5525 res.server_scope)) {
5526 dprintk("%s: server_scope mismatch detected\n",
5528 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH, &clp->cl_state);
5529 kfree(clp->cl_serverscope);
5530 clp->cl_serverscope = NULL;
5533 if (clp->cl_serverscope == NULL) {
5534 clp->cl_serverscope = res.server_scope;
5541 kfree(res.server_owner);
5543 kfree(res.server_scope);
5545 if (clp->cl_implid != NULL)
5546 dprintk("NFS reply exchange_id: Server Implementation ID: "
5547 "domain: %s, name: %s, date: %llu,%u\n",
5548 clp->cl_implid->domain, clp->cl_implid->name,
5549 clp->cl_implid->date.seconds,
5550 clp->cl_implid->date.nseconds);
5551 dprintk("NFS reply exchange_id: %d\n", status);
5555 static int _nfs4_proc_destroy_clientid(struct nfs_client *clp,
5556 struct rpc_cred *cred)
5558 struct rpc_message msg = {
5559 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_CLIENTID],
5565 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5567 dprintk("NFS: Got error %d from the server %s on "
5568 "DESTROY_CLIENTID.", status, clp->cl_hostname);
5572 static int nfs4_proc_destroy_clientid(struct nfs_client *clp,
5573 struct rpc_cred *cred)
5578 for (loop = NFS4_MAX_LOOP_ON_RECOVER; loop != 0; loop--) {
5579 ret = _nfs4_proc_destroy_clientid(clp, cred);
5581 case -NFS4ERR_DELAY:
5582 case -NFS4ERR_CLIENTID_BUSY:
5592 int nfs4_destroy_clientid(struct nfs_client *clp)
5594 struct rpc_cred *cred;
5597 if (clp->cl_mvops->minor_version < 1)
5599 if (clp->cl_exchange_flags == 0)
5601 if (clp->cl_preserve_clid)
5603 cred = nfs4_get_exchange_id_cred(clp);
5604 ret = nfs4_proc_destroy_clientid(clp, cred);
5609 case -NFS4ERR_STALE_CLIENTID:
5610 clp->cl_exchange_flags = 0;
5616 struct nfs4_get_lease_time_data {
5617 struct nfs4_get_lease_time_args *args;
5618 struct nfs4_get_lease_time_res *res;
5619 struct nfs_client *clp;
5622 static void nfs4_get_lease_time_prepare(struct rpc_task *task,
5625 struct nfs4_get_lease_time_data *data =
5626 (struct nfs4_get_lease_time_data *)calldata;
5628 dprintk("--> %s\n", __func__);
5629 /* just setup sequence, do not trigger session recovery
5630 since we're invoked within one */
5631 nfs41_setup_sequence(data->clp->cl_session,
5632 &data->args->la_seq_args,
5633 &data->res->lr_seq_res,
5635 dprintk("<-- %s\n", __func__);
5639 * Called from nfs4_state_manager thread for session setup, so don't recover
5640 * from sequence operation or clientid errors.
5642 static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
5644 struct nfs4_get_lease_time_data *data =
5645 (struct nfs4_get_lease_time_data *)calldata;
5647 dprintk("--> %s\n", __func__);
5648 if (!nfs41_sequence_done(task, &data->res->lr_seq_res))
5650 switch (task->tk_status) {
5651 case -NFS4ERR_DELAY:
5652 case -NFS4ERR_GRACE:
5653 dprintk("%s Retry: tk_status %d\n", __func__, task->tk_status);
5654 rpc_delay(task, NFS4_POLL_RETRY_MIN);
5655 task->tk_status = 0;
5657 case -NFS4ERR_RETRY_UNCACHED_REP:
5658 rpc_restart_call_prepare(task);
5661 dprintk("<-- %s\n", __func__);
5664 static const struct rpc_call_ops nfs4_get_lease_time_ops = {
5665 .rpc_call_prepare = nfs4_get_lease_time_prepare,
5666 .rpc_call_done = nfs4_get_lease_time_done,
5669 int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
5671 struct rpc_task *task;
5672 struct nfs4_get_lease_time_args args;
5673 struct nfs4_get_lease_time_res res = {
5674 .lr_fsinfo = fsinfo,
5676 struct nfs4_get_lease_time_data data = {
5681 struct rpc_message msg = {
5682 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GET_LEASE_TIME],
5686 struct rpc_task_setup task_setup = {
5687 .rpc_client = clp->cl_rpcclient,
5688 .rpc_message = &msg,
5689 .callback_ops = &nfs4_get_lease_time_ops,
5690 .callback_data = &data,
5691 .flags = RPC_TASK_TIMEOUT,
5695 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
5696 nfs4_set_sequence_privileged(&args.la_seq_args);
5697 dprintk("--> %s\n", __func__);
5698 task = rpc_run_task(&task_setup);
5701 status = PTR_ERR(task);
5703 status = task->tk_status;
5706 dprintk("<-- %s return %d\n", __func__, status);
5712 * Initialize the values to be used by the client in CREATE_SESSION
5713 * If nfs4_init_session set the fore channel request and response sizes,
5716 * Set the back channel max_resp_sz_cached to zero to force the client to
5717 * always set csa_cachethis to FALSE because the current implementation
5718 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5720 static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5722 struct nfs4_session *session = args->client->cl_session;
5723 unsigned int mxrqst_sz = session->fc_target_max_rqst_sz,
5724 mxresp_sz = session->fc_target_max_resp_sz;
5727 mxrqst_sz = NFS_MAX_FILE_IO_SIZE;
5729 mxresp_sz = NFS_MAX_FILE_IO_SIZE;
5730 /* Fore channel attributes */
5731 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5732 args->fc_attrs.max_resp_sz = mxresp_sz;
5733 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5734 args->fc_attrs.max_reqs = max_session_slots;
5736 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5737 "max_ops=%u max_reqs=%u\n",
5739 args->fc_attrs.max_rqst_sz, args->fc_attrs.max_resp_sz,
5740 args->fc_attrs.max_ops, args->fc_attrs.max_reqs);
5742 /* Back channel attributes */
5743 args->bc_attrs.max_rqst_sz = PAGE_SIZE;
5744 args->bc_attrs.max_resp_sz = PAGE_SIZE;
5745 args->bc_attrs.max_resp_sz_cached = 0;
5746 args->bc_attrs.max_ops = NFS4_MAX_BACK_CHANNEL_OPS;
5747 args->bc_attrs.max_reqs = 1;
5749 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5750 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5752 args->bc_attrs.max_rqst_sz, args->bc_attrs.max_resp_sz,
5753 args->bc_attrs.max_resp_sz_cached, args->bc_attrs.max_ops,
5754 args->bc_attrs.max_reqs);
5757 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5759 struct nfs4_channel_attrs *sent = &args->fc_attrs;
5760 struct nfs4_channel_attrs *rcvd = &session->fc_attrs;
5762 if (rcvd->max_resp_sz > sent->max_resp_sz)
5765 * Our requested max_ops is the minimum we need; we're not
5766 * prepared to break up compounds into smaller pieces than that.
5767 * So, no point even trying to continue if the server won't
5770 if (rcvd->max_ops < sent->max_ops)
5772 if (rcvd->max_reqs == 0)
5774 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5775 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5779 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args, struct nfs4_session *session)
5781 struct nfs4_channel_attrs *sent = &args->bc_attrs;
5782 struct nfs4_channel_attrs *rcvd = &session->bc_attrs;
5784 if (rcvd->max_rqst_sz > sent->max_rqst_sz)
5786 if (rcvd->max_resp_sz < sent->max_resp_sz)
5788 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5790 /* These would render the backchannel useless: */
5791 if (rcvd->max_ops != sent->max_ops)
5793 if (rcvd->max_reqs != sent->max_reqs)
5798 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args *args,
5799 struct nfs4_session *session)
5803 ret = nfs4_verify_fore_channel_attrs(args, session);
5806 return nfs4_verify_back_channel_attrs(args, session);
5809 static int _nfs4_proc_create_session(struct nfs_client *clp,
5810 struct rpc_cred *cred)
5812 struct nfs4_session *session = clp->cl_session;
5813 struct nfs41_create_session_args args = {
5815 .cb_program = NFS4_CALLBACK,
5817 struct nfs41_create_session_res res = {
5820 struct rpc_message msg = {
5821 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE_SESSION],
5828 nfs4_init_channel_attrs(&args);
5829 args.flags = (SESSION4_PERSIST | SESSION4_BACK_CHAN);
5831 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5834 /* Verify the session's negotiated channel_attrs values */
5835 status = nfs4_verify_channel_attrs(&args, session);
5836 /* Increment the clientid slot sequence id */
5844 * Issues a CREATE_SESSION operation to the server.
5845 * It is the responsibility of the caller to verify the session is
5846 * expired before calling this routine.
5848 int nfs4_proc_create_session(struct nfs_client *clp, struct rpc_cred *cred)
5852 struct nfs4_session *session = clp->cl_session;
5854 dprintk("--> %s clp=%p session=%p\n", __func__, clp, session);
5856 status = _nfs4_proc_create_session(clp, cred);
5860 /* Init or reset the session slot tables */
5861 status = nfs4_setup_session_slot_tables(session);
5862 dprintk("slot table setup returned %d\n", status);
5866 ptr = (unsigned *)&session->sess_id.data[0];
5867 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__,
5868 clp->cl_seqid, ptr[0], ptr[1], ptr[2], ptr[3]);
5870 dprintk("<-- %s\n", __func__);
5875 * Issue the over-the-wire RPC DESTROY_SESSION.
5876 * The caller must serialize access to this routine.
5878 int nfs4_proc_destroy_session(struct nfs4_session *session,
5879 struct rpc_cred *cred)
5881 struct rpc_message msg = {
5882 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DESTROY_SESSION],
5883 .rpc_argp = session,
5888 dprintk("--> nfs4_proc_destroy_session\n");
5890 /* session is still being setup */
5891 if (session->clp->cl_cons_state != NFS_CS_READY)
5894 status = rpc_call_sync(session->clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
5897 dprintk("NFS: Got error %d from the server on DESTROY_SESSION. "
5898 "Session has been destroyed regardless...\n", status);
5900 dprintk("<-- nfs4_proc_destroy_session\n");
5905 * Renew the cl_session lease.
5907 struct nfs4_sequence_data {
5908 struct nfs_client *clp;
5909 struct nfs4_sequence_args args;
5910 struct nfs4_sequence_res res;
5913 static void nfs41_sequence_release(void *data)
5915 struct nfs4_sequence_data *calldata = data;
5916 struct nfs_client *clp = calldata->clp;
5918 if (atomic_read(&clp->cl_count) > 1)
5919 nfs4_schedule_state_renewal(clp);
5920 nfs_put_client(clp);
5924 static int nfs41_sequence_handle_errors(struct rpc_task *task, struct nfs_client *clp)
5926 switch(task->tk_status) {
5927 case -NFS4ERR_DELAY:
5928 rpc_delay(task, NFS4_POLL_RETRY_MAX);
5931 nfs4_schedule_lease_recovery(clp);
5936 static void nfs41_sequence_call_done(struct rpc_task *task, void *data)
5938 struct nfs4_sequence_data *calldata = data;
5939 struct nfs_client *clp = calldata->clp;
5941 if (!nfs41_sequence_done(task, task->tk_msg.rpc_resp))
5944 if (task->tk_status < 0) {
5945 dprintk("%s ERROR %d\n", __func__, task->tk_status);
5946 if (atomic_read(&clp->cl_count) == 1)
5949 if (nfs41_sequence_handle_errors(task, clp) == -EAGAIN) {
5950 rpc_restart_call_prepare(task);
5954 dprintk("%s rpc_cred %p\n", __func__, task->tk_msg.rpc_cred);
5956 dprintk("<-- %s\n", __func__);
5959 static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5961 struct nfs4_sequence_data *calldata = data;
5962 struct nfs_client *clp = calldata->clp;
5963 struct nfs4_sequence_args *args;
5964 struct nfs4_sequence_res *res;
5966 args = task->tk_msg.rpc_argp;
5967 res = task->tk_msg.rpc_resp;
5969 nfs41_setup_sequence(clp->cl_session, args, res, task);
5972 static const struct rpc_call_ops nfs41_sequence_ops = {
5973 .rpc_call_done = nfs41_sequence_call_done,
5974 .rpc_call_prepare = nfs41_sequence_prepare,
5975 .rpc_release = nfs41_sequence_release,
5978 static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp,
5979 struct rpc_cred *cred,
5982 struct nfs4_sequence_data *calldata;
5983 struct rpc_message msg = {
5984 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEQUENCE],
5987 struct rpc_task_setup task_setup_data = {
5988 .rpc_client = clp->cl_rpcclient,
5989 .rpc_message = &msg,
5990 .callback_ops = &nfs41_sequence_ops,
5991 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFT,
5994 if (!atomic_inc_not_zero(&clp->cl_count))
5995 return ERR_PTR(-EIO);
5996 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
5997 if (calldata == NULL) {
5998 nfs_put_client(clp);
5999 return ERR_PTR(-ENOMEM);
6001 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
6003 nfs4_set_sequence_privileged(&calldata->args);
6004 msg.rpc_argp = &calldata->args;
6005 msg.rpc_resp = &calldata->res;
6006 calldata->clp = clp;
6007 task_setup_data.callback_data = calldata;
6009 return rpc_run_task(&task_setup_data);
6012 static int nfs41_proc_async_sequence(struct nfs_client *clp, struct rpc_cred *cred, unsigned renew_flags)
6014 struct rpc_task *task;
6017 if ((renew_flags & NFS4_RENEW_TIMEOUT) == 0)
6019 task = _nfs41_proc_sequence(clp, cred, false);
6021 ret = PTR_ERR(task);
6023 rpc_put_task_async(task);
6024 dprintk("<-- %s status=%d\n", __func__, ret);
6028 static int nfs4_proc_sequence(struct nfs_client *clp, struct rpc_cred *cred)
6030 struct rpc_task *task;
6033 task = _nfs41_proc_sequence(clp, cred, true);
6035 ret = PTR_ERR(task);
6038 ret = rpc_wait_for_completion_task(task);
6040 struct nfs4_sequence_res *res = task->tk_msg.rpc_resp;
6042 if (task->tk_status == 0)
6043 nfs41_handle_sequence_flag_errors(clp, res->sr_status_flags);
6044 ret = task->tk_status;
6048 dprintk("<-- %s status=%d\n", __func__, ret);
6052 struct nfs4_reclaim_complete_data {
6053 struct nfs_client *clp;
6054 struct nfs41_reclaim_complete_args arg;
6055 struct nfs41_reclaim_complete_res res;
6058 static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
6060 struct nfs4_reclaim_complete_data *calldata = data;
6062 nfs41_setup_sequence(calldata->clp->cl_session,
6063 &calldata->arg.seq_args,
6064 &calldata->res.seq_res,
6068 static int nfs41_reclaim_complete_handle_errors(struct rpc_task *task, struct nfs_client *clp)
6070 switch(task->tk_status) {
6072 case -NFS4ERR_COMPLETE_ALREADY:
6073 case -NFS4ERR_WRONG_CRED: /* What to do here? */
6075 case -NFS4ERR_DELAY:
6076 rpc_delay(task, NFS4_POLL_RETRY_MAX);
6078 case -NFS4ERR_RETRY_UNCACHED_REP:
6081 nfs4_schedule_lease_recovery(clp);
6086 static void nfs4_reclaim_complete_done(struct rpc_task *task, void *data)
6088 struct nfs4_reclaim_complete_data *calldata = data;
6089 struct nfs_client *clp = calldata->clp;
6090 struct nfs4_sequence_res *res = &calldata->res.seq_res;
6092 dprintk("--> %s\n", __func__);
6093 if (!nfs41_sequence_done(task, res))
6096 if (nfs41_reclaim_complete_handle_errors(task, clp) == -EAGAIN) {
6097 rpc_restart_call_prepare(task);
6100 dprintk("<-- %s\n", __func__);
6103 static void nfs4_free_reclaim_complete_data(void *data)
6105 struct nfs4_reclaim_complete_data *calldata = data;
6110 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops = {
6111 .rpc_call_prepare = nfs4_reclaim_complete_prepare,
6112 .rpc_call_done = nfs4_reclaim_complete_done,
6113 .rpc_release = nfs4_free_reclaim_complete_data,
6117 * Issue a global reclaim complete.
6119 static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
6121 struct nfs4_reclaim_complete_data *calldata;
6122 struct rpc_task *task;
6123 struct rpc_message msg = {
6124 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RECLAIM_COMPLETE],
6126 struct rpc_task_setup task_setup_data = {
6127 .rpc_client = clp->cl_rpcclient,
6128 .rpc_message = &msg,
6129 .callback_ops = &nfs4_reclaim_complete_call_ops,
6130 .flags = RPC_TASK_ASYNC,
6132 int status = -ENOMEM;
6134 dprintk("--> %s\n", __func__);
6135 calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
6136 if (calldata == NULL)
6138 calldata->clp = clp;
6139 calldata->arg.one_fs = 0;
6141 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
6142 nfs4_set_sequence_privileged(&calldata->arg.seq_args);
6143 msg.rpc_argp = &calldata->arg;
6144 msg.rpc_resp = &calldata->res;
6145 task_setup_data.callback_data = calldata;
6146 task = rpc_run_task(&task_setup_data);
6148 status = PTR_ERR(task);
6151 status = nfs4_wait_for_completion_rpc_task(task);
6153 status = task->tk_status;
6157 dprintk("<-- %s status=%d\n", __func__, status);
6162 nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
6164 struct nfs4_layoutget *lgp = calldata;
6165 struct nfs_server *server = NFS_SERVER(lgp->args.inode);
6166 struct nfs4_session *session = nfs4_get_session(server);
6168 dprintk("--> %s\n", __func__);
6169 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
6170 * right now covering the LAYOUTGET we are about to send.
6171 * However, that is not so catastrophic, and there seems
6172 * to be no way to prevent it completely.
6174 if (nfs41_setup_sequence(session, &lgp->args.seq_args,
6175 &lgp->res.seq_res, task))
6177 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
6178 NFS_I(lgp->args.inode)->layout,
6179 lgp->args.ctx->state)) {
6180 rpc_exit(task, NFS4_OK);
6184 static void nfs4_layoutget_done(struct rpc_task *task, void *calldata)
6186 struct nfs4_layoutget *lgp = calldata;
6187 struct inode *inode = lgp->args.inode;
6188 struct nfs_server *server = NFS_SERVER(inode);
6189 struct pnfs_layout_hdr *lo;
6190 struct nfs4_state *state = NULL;
6191 unsigned long timeo, giveup;
6193 dprintk("--> %s\n", __func__);
6195 if (!nfs41_sequence_done(task, &lgp->res.seq_res))
6198 switch (task->tk_status) {
6201 case -NFS4ERR_LAYOUTTRYLATER:
6202 case -NFS4ERR_RECALLCONFLICT:
6203 timeo = rpc_get_timeout(task->tk_client);
6204 giveup = lgp->args.timestamp + timeo;
6205 if (time_after(giveup, jiffies))
6206 task->tk_status = -NFS4ERR_DELAY;
6208 case -NFS4ERR_EXPIRED:
6209 case -NFS4ERR_BAD_STATEID:
6210 spin_lock(&inode->i_lock);
6211 lo = NFS_I(inode)->layout;
6212 if (!lo || list_empty(&lo->plh_segs)) {
6213 spin_unlock(&inode->i_lock);
6214 /* If the open stateid was bad, then recover it. */
6215 state = lgp->args.ctx->state;
6219 pnfs_mark_matching_lsegs_invalid(lo, &head, NULL);
6220 spin_unlock(&inode->i_lock);
6221 /* Mark the bad layout state as invalid, then
6222 * retry using the open stateid. */
6223 pnfs_free_lseg_list(&head);
6226 if (nfs4_async_handle_error(task, server, state) == -EAGAIN)
6227 rpc_restart_call_prepare(task);
6229 dprintk("<-- %s\n", __func__);
6232 static size_t max_response_pages(struct nfs_server *server)
6234 u32 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
6235 return nfs_page_array_len(0, max_resp_sz);
6238 static void nfs4_free_pages(struct page **pages, size_t size)
6245 for (i = 0; i < size; i++) {
6248 __free_page(pages[i]);
6253 static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
6255 struct page **pages;
6258 pages = kcalloc(size, sizeof(struct page *), gfp_flags);
6260 dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
6264 for (i = 0; i < size; i++) {
6265 pages[i] = alloc_page(gfp_flags);
6267 dprintk("%s: failed to allocate page\n", __func__);
6268 nfs4_free_pages(pages, size);
6276 static void nfs4_layoutget_release(void *calldata)
6278 struct nfs4_layoutget *lgp = calldata;
6279 struct inode *inode = lgp->args.inode;
6280 struct nfs_server *server = NFS_SERVER(inode);
6281 size_t max_pages = max_response_pages(server);
6283 dprintk("--> %s\n", __func__);
6284 nfs4_free_pages(lgp->args.layout.pages, max_pages);
6285 pnfs_put_layout_hdr(NFS_I(inode)->layout);
6286 put_nfs_open_context(lgp->args.ctx);
6288 dprintk("<-- %s\n", __func__);
6291 static const struct rpc_call_ops nfs4_layoutget_call_ops = {
6292 .rpc_call_prepare = nfs4_layoutget_prepare,
6293 .rpc_call_done = nfs4_layoutget_done,
6294 .rpc_release = nfs4_layoutget_release,
6297 struct pnfs_layout_segment *
6298 nfs4_proc_layoutget(struct nfs4_layoutget *lgp, gfp_t gfp_flags)
6300 struct inode *inode = lgp->args.inode;
6301 struct nfs_server *server = NFS_SERVER(inode);
6302 size_t max_pages = max_response_pages(server);
6303 struct rpc_task *task;
6304 struct rpc_message msg = {
6305 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTGET],
6306 .rpc_argp = &lgp->args,
6307 .rpc_resp = &lgp->res,
6309 struct rpc_task_setup task_setup_data = {
6310 .rpc_client = server->client,
6311 .rpc_message = &msg,
6312 .callback_ops = &nfs4_layoutget_call_ops,
6313 .callback_data = lgp,
6314 .flags = RPC_TASK_ASYNC,
6316 struct pnfs_layout_segment *lseg = NULL;
6319 dprintk("--> %s\n", __func__);
6321 lgp->args.layout.pages = nfs4_alloc_pages(max_pages, gfp_flags);
6322 if (!lgp->args.layout.pages) {
6323 nfs4_layoutget_release(lgp);
6324 return ERR_PTR(-ENOMEM);
6326 lgp->args.layout.pglen = max_pages * PAGE_SIZE;
6327 lgp->args.timestamp = jiffies;
6329 lgp->res.layoutp = &lgp->args.layout;
6330 lgp->res.seq_res.sr_slot = NULL;
6331 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
6333 /* nfs4_layoutget_release calls pnfs_put_layout_hdr */
6334 pnfs_get_layout_hdr(NFS_I(inode)->layout);
6336 task = rpc_run_task(&task_setup_data);
6338 return ERR_CAST(task);
6339 status = nfs4_wait_for_completion_rpc_task(task);
6341 status = task->tk_status;
6342 /* if layoutp->len is 0, nfs4_layoutget_prepare called rpc_exit */
6343 if (status == 0 && lgp->res.layoutp->len)
6344 lseg = pnfs_layout_process(lgp);
6346 dprintk("<-- %s status=%d\n", __func__, status);
6348 return ERR_PTR(status);
6353 nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
6355 struct nfs4_layoutreturn *lrp = calldata;
6357 dprintk("--> %s\n", __func__);
6358 nfs41_setup_sequence(lrp->clp->cl_session,
6359 &lrp->args.seq_args,
6364 static void nfs4_layoutreturn_done(struct rpc_task *task, void *calldata)
6366 struct nfs4_layoutreturn *lrp = calldata;
6367 struct nfs_server *server;
6369 dprintk("--> %s\n", __func__);
6371 if (!nfs41_sequence_done(task, &lrp->res.seq_res))
6374 server = NFS_SERVER(lrp->args.inode);
6375 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6376 rpc_restart_call_prepare(task);
6379 dprintk("<-- %s\n", __func__);
6382 static void nfs4_layoutreturn_release(void *calldata)
6384 struct nfs4_layoutreturn *lrp = calldata;
6385 struct pnfs_layout_hdr *lo = lrp->args.layout;
6387 dprintk("--> %s\n", __func__);
6388 spin_lock(&lo->plh_inode->i_lock);
6389 if (lrp->res.lrs_present)
6390 pnfs_set_layout_stateid(lo, &lrp->res.stateid, true);
6391 lo->plh_block_lgets--;
6392 spin_unlock(&lo->plh_inode->i_lock);
6393 pnfs_put_layout_hdr(lrp->args.layout);
6395 dprintk("<-- %s\n", __func__);
6398 static const struct rpc_call_ops nfs4_layoutreturn_call_ops = {
6399 .rpc_call_prepare = nfs4_layoutreturn_prepare,
6400 .rpc_call_done = nfs4_layoutreturn_done,
6401 .rpc_release = nfs4_layoutreturn_release,
6404 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
6406 struct rpc_task *task;
6407 struct rpc_message msg = {
6408 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTRETURN],
6409 .rpc_argp = &lrp->args,
6410 .rpc_resp = &lrp->res,
6412 struct rpc_task_setup task_setup_data = {
6413 .rpc_client = lrp->clp->cl_rpcclient,
6414 .rpc_message = &msg,
6415 .callback_ops = &nfs4_layoutreturn_call_ops,
6416 .callback_data = lrp,
6420 dprintk("--> %s\n", __func__);
6421 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
6422 task = rpc_run_task(&task_setup_data);
6424 return PTR_ERR(task);
6425 status = task->tk_status;
6426 dprintk("<-- %s status=%d\n", __func__, status);
6432 * Retrieve the list of Data Server devices from the MDS.
6434 static int _nfs4_getdevicelist(struct nfs_server *server,
6435 const struct nfs_fh *fh,
6436 struct pnfs_devicelist *devlist)
6438 struct nfs4_getdevicelist_args args = {
6440 .layoutclass = server->pnfs_curr_ld->id,
6442 struct nfs4_getdevicelist_res res = {
6445 struct rpc_message msg = {
6446 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICELIST],
6452 dprintk("--> %s\n", __func__);
6453 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
6455 dprintk("<-- %s status=%d\n", __func__, status);
6459 int nfs4_proc_getdevicelist(struct nfs_server *server,
6460 const struct nfs_fh *fh,
6461 struct pnfs_devicelist *devlist)
6463 struct nfs4_exception exception = { };
6467 err = nfs4_handle_exception(server,
6468 _nfs4_getdevicelist(server, fh, devlist),
6470 } while (exception.retry);
6472 dprintk("%s: err=%d, num_devs=%u\n", __func__,
6473 err, devlist->num_devs);
6477 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist);
6480 _nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6482 struct nfs4_getdeviceinfo_args args = {
6485 struct nfs4_getdeviceinfo_res res = {
6488 struct rpc_message msg = {
6489 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETDEVICEINFO],
6495 dprintk("--> %s\n", __func__);
6496 status = nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6497 dprintk("<-- %s status=%d\n", __func__, status);
6502 int nfs4_proc_getdeviceinfo(struct nfs_server *server, struct pnfs_device *pdev)
6504 struct nfs4_exception exception = { };
6508 err = nfs4_handle_exception(server,
6509 _nfs4_proc_getdeviceinfo(server, pdev),
6511 } while (exception.retry);
6514 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo);
6516 static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
6518 struct nfs4_layoutcommit_data *data = calldata;
6519 struct nfs_server *server = NFS_SERVER(data->args.inode);
6520 struct nfs4_session *session = nfs4_get_session(server);
6522 nfs41_setup_sequence(session,
6523 &data->args.seq_args,
6529 nfs4_layoutcommit_done(struct rpc_task *task, void *calldata)
6531 struct nfs4_layoutcommit_data *data = calldata;
6532 struct nfs_server *server = NFS_SERVER(data->args.inode);
6534 if (!nfs41_sequence_done(task, &data->res.seq_res))
6537 switch (task->tk_status) { /* Just ignore these failures */
6538 case -NFS4ERR_DELEG_REVOKED: /* layout was recalled */
6539 case -NFS4ERR_BADIOMODE: /* no IOMODE_RW layout for range */
6540 case -NFS4ERR_BADLAYOUT: /* no layout */
6541 case -NFS4ERR_GRACE: /* loca_recalim always false */
6542 task->tk_status = 0;
6545 nfs_post_op_update_inode_force_wcc(data->args.inode,
6549 if (nfs4_async_handle_error(task, server, NULL) == -EAGAIN) {
6550 rpc_restart_call_prepare(task);
6556 static void nfs4_layoutcommit_release(void *calldata)
6558 struct nfs4_layoutcommit_data *data = calldata;
6560 pnfs_cleanup_layoutcommit(data);
6561 put_rpccred(data->cred);
6565 static const struct rpc_call_ops nfs4_layoutcommit_ops = {
6566 .rpc_call_prepare = nfs4_layoutcommit_prepare,
6567 .rpc_call_done = nfs4_layoutcommit_done,
6568 .rpc_release = nfs4_layoutcommit_release,
6572 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
6574 struct rpc_message msg = {
6575 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTCOMMIT],
6576 .rpc_argp = &data->args,
6577 .rpc_resp = &data->res,
6578 .rpc_cred = data->cred,
6580 struct rpc_task_setup task_setup_data = {
6581 .task = &data->task,
6582 .rpc_client = NFS_CLIENT(data->args.inode),
6583 .rpc_message = &msg,
6584 .callback_ops = &nfs4_layoutcommit_ops,
6585 .callback_data = data,
6586 .flags = RPC_TASK_ASYNC,
6588 struct rpc_task *task;
6591 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
6592 "lbw: %llu inode %lu\n",
6593 data->task.tk_pid, sync,
6594 data->args.lastbytewritten,
6595 data->args.inode->i_ino);
6597 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6598 task = rpc_run_task(&task_setup_data);
6600 return PTR_ERR(task);
6603 status = nfs4_wait_for_completion_rpc_task(task);
6606 status = task->tk_status;
6608 dprintk("%s: status %d\n", __func__, status);
6614 _nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6615 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6617 struct nfs41_secinfo_no_name_args args = {
6618 .style = SECINFO_STYLE_CURRENT_FH,
6620 struct nfs4_secinfo_res res = {
6623 struct rpc_message msg = {
6624 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SECINFO_NO_NAME],
6628 return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
6632 nfs41_proc_secinfo_no_name(struct nfs_server *server, struct nfs_fh *fhandle,
6633 struct nfs_fsinfo *info, struct nfs4_secinfo_flavors *flavors)
6635 struct nfs4_exception exception = { };
6638 err = _nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6641 case -NFS4ERR_WRONGSEC:
6642 case -NFS4ERR_NOTSUPP:
6645 err = nfs4_handle_exception(server, err, &exception);
6647 } while (exception.retry);
6653 nfs41_find_root_sec(struct nfs_server *server, struct nfs_fh *fhandle,
6654 struct nfs_fsinfo *info)
6658 rpc_authflavor_t flavor;
6659 struct nfs4_secinfo_flavors *flavors;
6661 page = alloc_page(GFP_KERNEL);
6667 flavors = page_address(page);
6668 err = nfs41_proc_secinfo_no_name(server, fhandle, info, flavors);
6671 * Fall back on "guess and check" method if
6672 * the server doesn't support SECINFO_NO_NAME
6674 if (err == -NFS4ERR_WRONGSEC || err == -NFS4ERR_NOTSUPP) {
6675 err = nfs4_find_root_sec(server, fhandle, info);
6681 flavor = nfs_find_best_sec(flavors);
6683 err = nfs4_lookup_root_sec(server, fhandle, info, flavor);
6693 static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6696 struct nfs41_test_stateid_args args = {
6699 struct nfs41_test_stateid_res res;
6700 struct rpc_message msg = {
6701 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_TEST_STATEID],
6706 dprintk("NFS call test_stateid %p\n", stateid);
6707 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6708 nfs4_set_sequence_privileged(&args.seq_args);
6709 status = nfs4_call_sync_sequence(server->client, server, &msg,
6710 &args.seq_args, &res.seq_res);
6711 if (status != NFS_OK) {
6712 dprintk("NFS reply test_stateid: failed, %d\n", status);
6715 dprintk("NFS reply test_stateid: succeeded, %d\n", -res.status);
6720 * nfs41_test_stateid - perform a TEST_STATEID operation
6722 * @server: server / transport on which to perform the operation
6723 * @stateid: state ID to test
6725 * Returns NFS_OK if the server recognizes that "stateid" is valid.
6726 * Otherwise a negative NFS4ERR value is returned if the operation
6727 * failed or the state ID is not currently valid.
6729 static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6731 struct nfs4_exception exception = { };
6734 err = _nfs41_test_stateid(server, stateid);
6735 if (err != -NFS4ERR_DELAY)
6737 nfs4_handle_exception(server, err, &exception);
6738 } while (exception.retry);
6742 static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6744 struct nfs41_free_stateid_args args = {
6747 struct nfs41_free_stateid_res res;
6748 struct rpc_message msg = {
6749 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FREE_STATEID],
6755 dprintk("NFS call free_stateid %p\n", stateid);
6756 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6757 nfs4_set_sequence_privileged(&args.seq_args);
6758 status = nfs4_call_sync_sequence(server->client, server, &msg,
6759 &args.seq_args, &res.seq_res);
6760 dprintk("NFS reply free_stateid: %d\n", status);
6765 * nfs41_free_stateid - perform a FREE_STATEID operation
6767 * @server: server / transport on which to perform the operation
6768 * @stateid: state ID to release
6770 * Returns NFS_OK if the server freed "stateid". Otherwise a
6771 * negative NFS4ERR value is returned.
6773 static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6775 struct nfs4_exception exception = { };
6778 err = _nfs4_free_stateid(server, stateid);
6779 if (err != -NFS4ERR_DELAY)
6781 nfs4_handle_exception(server, err, &exception);
6782 } while (exception.retry);
6786 static bool nfs41_match_stateid(const nfs4_stateid *s1,
6787 const nfs4_stateid *s2)
6789 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6792 if (s1->seqid == s2->seqid)
6794 if (s1->seqid == 0 || s2->seqid == 0)
6800 #endif /* CONFIG_NFS_V4_1 */
6802 static bool nfs4_match_stateid(const nfs4_stateid *s1,
6803 const nfs4_stateid *s2)
6805 return nfs4_stateid_match(s1, s2);
6809 static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6810 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6811 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6812 .recover_open = nfs4_open_reclaim,
6813 .recover_lock = nfs4_lock_reclaim,
6814 .establish_clid = nfs4_init_clientid,
6815 .get_clid_cred = nfs4_get_setclientid_cred,
6816 .detect_trunking = nfs40_discover_server_trunking,
6819 #if defined(CONFIG_NFS_V4_1)
6820 static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6821 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6822 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6823 .recover_open = nfs4_open_reclaim,
6824 .recover_lock = nfs4_lock_reclaim,
6825 .establish_clid = nfs41_init_clientid,
6826 .get_clid_cred = nfs4_get_exchange_id_cred,
6827 .reclaim_complete = nfs41_proc_reclaim_complete,
6828 .detect_trunking = nfs41_discover_server_trunking,
6830 #endif /* CONFIG_NFS_V4_1 */
6832 static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6833 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6834 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6835 .recover_open = nfs4_open_expired,
6836 .recover_lock = nfs4_lock_expired,
6837 .establish_clid = nfs4_init_clientid,
6838 .get_clid_cred = nfs4_get_setclientid_cred,
6841 #if defined(CONFIG_NFS_V4_1)
6842 static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6843 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6844 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6845 .recover_open = nfs41_open_expired,
6846 .recover_lock = nfs41_lock_expired,
6847 .establish_clid = nfs41_init_clientid,
6848 .get_clid_cred = nfs4_get_exchange_id_cred,
6850 #endif /* CONFIG_NFS_V4_1 */
6852 static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6853 .sched_state_renewal = nfs4_proc_async_renew,
6854 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6855 .renew_lease = nfs4_proc_renew,
6858 #if defined(CONFIG_NFS_V4_1)
6859 static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6860 .sched_state_renewal = nfs41_proc_async_sequence,
6861 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6862 .renew_lease = nfs4_proc_sequence,
6866 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6868 .init_caps = NFS_CAP_READDIRPLUS
6869 | NFS_CAP_ATOMIC_OPEN
6870 | NFS_CAP_CHANGE_ATTR
6871 | NFS_CAP_POSIX_LOCK,
6872 .call_sync = _nfs4_call_sync,
6873 .match_stateid = nfs4_match_stateid,
6874 .find_root_sec = nfs4_find_root_sec,
6875 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6876 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
6877 .state_renewal_ops = &nfs40_state_renewal_ops,
6880 #if defined(CONFIG_NFS_V4_1)
6881 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6883 .init_caps = NFS_CAP_READDIRPLUS
6884 | NFS_CAP_ATOMIC_OPEN
6885 | NFS_CAP_CHANGE_ATTR
6886 | NFS_CAP_POSIX_LOCK
6887 | NFS_CAP_STATEID_NFSV41
6888 | NFS_CAP_ATOMIC_OPEN_V1,
6889 .call_sync = nfs4_call_sync_sequence,
6890 .match_stateid = nfs41_match_stateid,
6891 .find_root_sec = nfs41_find_root_sec,
6892 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6893 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
6894 .state_renewal_ops = &nfs41_state_renewal_ops,
6898 const struct nfs4_minor_version_ops *nfs_v4_minor_ops[] = {
6899 [0] = &nfs_v4_0_minor_ops,
6900 #if defined(CONFIG_NFS_V4_1)
6901 [1] = &nfs_v4_1_minor_ops,
6905 const struct inode_operations nfs4_dir_inode_operations = {
6906 .create = nfs_create,
6907 .lookup = nfs_lookup,
6908 .atomic_open = nfs_atomic_open,
6910 .unlink = nfs_unlink,
6911 .symlink = nfs_symlink,
6915 .rename = nfs_rename,
6916 .permission = nfs_permission,
6917 .getattr = nfs_getattr,
6918 .setattr = nfs_setattr,
6919 .getxattr = generic_getxattr,
6920 .setxattr = generic_setxattr,
6921 .listxattr = generic_listxattr,
6922 .removexattr = generic_removexattr,
6925 static const struct inode_operations nfs4_file_inode_operations = {
6926 .permission = nfs_permission,
6927 .getattr = nfs_getattr,
6928 .setattr = nfs_setattr,
6929 .getxattr = generic_getxattr,
6930 .setxattr = generic_setxattr,
6931 .listxattr = generic_listxattr,
6932 .removexattr = generic_removexattr,
6935 const struct nfs_rpc_ops nfs_v4_clientops = {
6936 .version = 4, /* protocol version */
6937 .dentry_ops = &nfs4_dentry_operations,
6938 .dir_inode_ops = &nfs4_dir_inode_operations,
6939 .file_inode_ops = &nfs4_file_inode_operations,
6940 .file_ops = &nfs4_file_operations,
6941 .getroot = nfs4_proc_get_root,
6942 .submount = nfs4_submount,
6943 .try_mount = nfs4_try_mount,
6944 .getattr = nfs4_proc_getattr,
6945 .setattr = nfs4_proc_setattr,
6946 .lookup = nfs4_proc_lookup,
6947 .access = nfs4_proc_access,
6948 .readlink = nfs4_proc_readlink,
6949 .create = nfs4_proc_create,
6950 .remove = nfs4_proc_remove,
6951 .unlink_setup = nfs4_proc_unlink_setup,
6952 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6953 .unlink_done = nfs4_proc_unlink_done,
6954 .rename = nfs4_proc_rename,
6955 .rename_setup = nfs4_proc_rename_setup,
6956 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6957 .rename_done = nfs4_proc_rename_done,
6958 .link = nfs4_proc_link,
6959 .symlink = nfs4_proc_symlink,
6960 .mkdir = nfs4_proc_mkdir,
6961 .rmdir = nfs4_proc_remove,
6962 .readdir = nfs4_proc_readdir,
6963 .mknod = nfs4_proc_mknod,
6964 .statfs = nfs4_proc_statfs,
6965 .fsinfo = nfs4_proc_fsinfo,
6966 .pathconf = nfs4_proc_pathconf,
6967 .set_capabilities = nfs4_server_capabilities,
6968 .decode_dirent = nfs4_decode_dirent,
6969 .read_setup = nfs4_proc_read_setup,
6970 .read_pageio_init = pnfs_pageio_init_read,
6971 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6972 .read_done = nfs4_read_done,
6973 .write_setup = nfs4_proc_write_setup,
6974 .write_pageio_init = pnfs_pageio_init_write,
6975 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6976 .write_done = nfs4_write_done,
6977 .commit_setup = nfs4_proc_commit_setup,
6978 .commit_rpc_prepare = nfs4_proc_commit_rpc_prepare,
6979 .commit_done = nfs4_commit_done,
6980 .lock = nfs4_proc_lock,
6981 .clear_acl_cache = nfs4_zap_acl_attr,
6982 .close_context = nfs4_close_context,
6983 .open_context = nfs4_atomic_open,
6984 .have_delegation = nfs4_have_delegation,
6985 .return_delegation = nfs4_inode_return_delegation,
6986 .alloc_client = nfs4_alloc_client,
6987 .init_client = nfs4_init_client,
6988 .free_client = nfs4_free_client,
6989 .create_server = nfs4_create_server,
6990 .clone_server = nfs_clone_server,
6993 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = {
6994 .prefix = XATTR_NAME_NFSV4_ACL,
6995 .list = nfs4_xattr_list_nfs4_acl,
6996 .get = nfs4_xattr_get_nfs4_acl,
6997 .set = nfs4_xattr_set_nfs4_acl,
7000 const struct xattr_handler *nfs4_xattr_handlers[] = {
7001 &nfs4_xattr_nfs4_acl_handler,