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/utsname.h>
40 #include <linux/delay.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/nfs.h>
45 #include <linux/nfs4.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/nfs_page.h>
48 #include <linux/smp_lock.h>
49 #include <linux/namei.h>
50 #include <linux/mount.h>
53 #include "delegation.h"
55 #define NFSDBG_FACILITY NFSDBG_PROC
57 #define NFS4_POLL_RETRY_MIN (1*HZ)
58 #define NFS4_POLL_RETRY_MAX (15*HZ)
60 static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid);
61 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
62 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *);
63 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
64 static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
65 extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
66 extern struct rpc_procinfo nfs4_procedures[];
68 /* Prevent leaks of NFSv4 errors into userland */
69 int nfs4_map_errors(int err)
72 dprintk("%s could not handle NFSv4 error %d\n",
80 * This is our standard bitmap for GETATTR requests.
82 const u32 nfs4_fattr_bitmap[2] = {
87 | FATTR4_WORD0_FILEID,
89 | FATTR4_WORD1_NUMLINKS
91 | FATTR4_WORD1_OWNER_GROUP
93 | FATTR4_WORD1_SPACE_USED
94 | FATTR4_WORD1_TIME_ACCESS
95 | FATTR4_WORD1_TIME_METADATA
96 | FATTR4_WORD1_TIME_MODIFY
99 const u32 nfs4_statfs_bitmap[2] = {
100 FATTR4_WORD0_FILES_AVAIL
101 | FATTR4_WORD0_FILES_FREE
102 | FATTR4_WORD0_FILES_TOTAL,
103 FATTR4_WORD1_SPACE_AVAIL
104 | FATTR4_WORD1_SPACE_FREE
105 | FATTR4_WORD1_SPACE_TOTAL
108 const u32 nfs4_pathconf_bitmap[2] = {
110 | FATTR4_WORD0_MAXNAME,
114 const u32 nfs4_fsinfo_bitmap[2] = { FATTR4_WORD0_MAXFILESIZE
115 | FATTR4_WORD0_MAXREAD
116 | FATTR4_WORD0_MAXWRITE
117 | FATTR4_WORD0_LEASE_TIME,
121 static void nfs4_setup_readdir(u64 cookie, u32 *verifier, struct dentry *dentry,
122 struct nfs4_readdir_arg *readdir)
126 BUG_ON(readdir->count < 80);
128 readdir->cookie = cookie;
129 memcpy(&readdir->verifier, verifier, sizeof(readdir->verifier));
134 memset(&readdir->verifier, 0, sizeof(readdir->verifier));
139 * NFSv4 servers do not return entries for '.' and '..'
140 * Therefore, we fake these entries here. We let '.'
141 * have cookie 0 and '..' have cookie 1. Note that
142 * when talking to the server, we always send cookie 0
145 start = p = (u32 *)kmap_atomic(*readdir->pages, KM_USER0);
148 *p++ = xdr_one; /* next */
149 *p++ = xdr_zero; /* cookie, first word */
150 *p++ = xdr_one; /* cookie, second word */
151 *p++ = xdr_one; /* entry len */
152 memcpy(p, ".\0\0\0", 4); /* entry */
154 *p++ = xdr_one; /* bitmap length */
155 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
156 *p++ = htonl(8); /* attribute buffer length */
157 p = xdr_encode_hyper(p, dentry->d_inode->i_ino);
160 *p++ = xdr_one; /* next */
161 *p++ = xdr_zero; /* cookie, first word */
162 *p++ = xdr_two; /* cookie, second word */
163 *p++ = xdr_two; /* entry len */
164 memcpy(p, "..\0\0", 4); /* entry */
166 *p++ = xdr_one; /* bitmap length */
167 *p++ = htonl(FATTR4_WORD0_FILEID); /* bitmap */
168 *p++ = htonl(8); /* attribute buffer length */
169 p = xdr_encode_hyper(p, dentry->d_parent->d_inode->i_ino);
171 readdir->pgbase = (char *)p - (char *)start;
172 readdir->count -= readdir->pgbase;
173 kunmap_atomic(start, KM_USER0);
177 renew_lease(struct nfs_server *server, unsigned long timestamp)
179 struct nfs4_client *clp = server->nfs4_state;
180 spin_lock(&clp->cl_lock);
181 if (time_before(clp->cl_last_renewal,timestamp))
182 clp->cl_last_renewal = timestamp;
183 spin_unlock(&clp->cl_lock);
186 static void update_changeattr(struct inode *inode, struct nfs4_change_info *cinfo)
188 struct nfs_inode *nfsi = NFS_I(inode);
190 spin_lock(&inode->i_lock);
191 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
192 if (cinfo->before == nfsi->change_attr && cinfo->atomic)
193 nfsi->change_attr = cinfo->after;
194 spin_unlock(&inode->i_lock);
197 /* Helper for asynchronous RPC calls */
198 static int nfs4_call_async(struct rpc_clnt *clnt, rpc_action tk_begin,
199 rpc_action tk_exit, void *calldata)
201 struct rpc_task *task;
203 if (!(task = rpc_new_task(clnt, tk_exit, RPC_TASK_ASYNC)))
206 task->tk_calldata = calldata;
207 task->tk_action = tk_begin;
212 static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, int open_flags)
214 struct inode *inode = state->inode;
216 open_flags &= (FMODE_READ|FMODE_WRITE);
217 /* Protect against nfs4_find_state() */
218 spin_lock(&state->owner->so_lock);
219 spin_lock(&inode->i_lock);
220 memcpy(&state->stateid, stateid, sizeof(state->stateid));
221 if ((open_flags & FMODE_WRITE))
223 if (open_flags & FMODE_READ)
225 nfs4_state_set_mode_locked(state, state->state | open_flags);
226 spin_unlock(&inode->i_lock);
227 spin_unlock(&state->owner->so_lock);
232 * reclaim state on the server after a reboot.
234 static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
236 struct inode *inode = state->inode;
237 struct nfs_server *server = NFS_SERVER(inode);
238 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
239 struct nfs_openargs o_arg = {
242 .open_flags = state->state,
243 .clientid = server->nfs4_state->cl_clientid,
244 .claim = NFS4_OPEN_CLAIM_PREVIOUS,
245 .bitmask = server->attr_bitmask,
247 struct nfs_openres o_res = {
248 .server = server, /* Grrr */
250 struct rpc_message msg = {
251 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
254 .rpc_cred = sp->so_cred,
258 if (delegation != NULL) {
259 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
260 memcpy(&state->stateid, &delegation->stateid,
261 sizeof(state->stateid));
262 set_bit(NFS_DELEGATED_STATE, &state->flags);
265 o_arg.u.delegation_type = delegation->type;
267 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
268 if (o_arg.seqid == NULL)
270 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
271 /* Confirm the sequence as being established */
272 nfs_confirm_seqid(&sp->so_seqid, status);
273 nfs_increment_open_seqid(status, o_arg.seqid);
275 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
276 if (o_res.delegation_type != 0) {
277 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
278 /* Did the server issue an immediate delegation recall? */
280 nfs_async_inode_return_delegation(inode, &o_res.stateid);
283 nfs_free_seqid(o_arg.seqid);
284 clear_bit(NFS_DELEGATED_STATE, &state->flags);
285 /* Ensure we update the inode attributes */
290 static int nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
292 struct nfs_server *server = NFS_SERVER(state->inode);
293 struct nfs4_exception exception = { };
296 err = _nfs4_open_reclaim(sp, state);
297 if (err != -NFS4ERR_DELAY)
299 nfs4_handle_exception(server, err, &exception);
300 } while (exception.retry);
304 static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
306 struct nfs4_state_owner *sp = state->owner;
307 struct inode *inode = dentry->d_inode;
308 struct nfs_server *server = NFS_SERVER(inode);
309 struct dentry *parent = dget_parent(dentry);
310 struct nfs_openargs arg = {
311 .fh = NFS_FH(parent->d_inode),
312 .clientid = server->nfs4_state->cl_clientid,
313 .name = &dentry->d_name,
316 .bitmask = server->attr_bitmask,
317 .claim = NFS4_OPEN_CLAIM_DELEGATE_CUR,
319 struct nfs_openres res = {
322 struct rpc_message msg = {
323 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR],
326 .rpc_cred = sp->so_cred,
330 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
332 if (state->state == 0)
334 arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
336 if (arg.seqid == NULL)
338 arg.open_flags = state->state;
339 memcpy(arg.u.delegation.data, state->stateid.data, sizeof(arg.u.delegation.data));
340 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
341 nfs_increment_open_seqid(status, arg.seqid);
344 if(res.rflags & NFS4_OPEN_RESULT_CONFIRM) {
345 status = _nfs4_proc_open_confirm(server->client, NFS_FH(inode),
346 sp, &res.stateid, arg.seqid);
350 nfs_confirm_seqid(&sp->so_seqid, 0);
352 memcpy(state->stateid.data, res.stateid.data,
353 sizeof(state->stateid.data));
354 clear_bit(NFS_DELEGATED_STATE, &state->flags);
357 nfs_free_seqid(arg.seqid);
363 int nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state *state)
365 struct nfs4_exception exception = { };
366 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
369 err = _nfs4_open_delegation_recall(dentry, state);
373 case -NFS4ERR_STALE_CLIENTID:
374 case -NFS4ERR_STALE_STATEID:
375 case -NFS4ERR_EXPIRED:
376 /* Don't recall a delegation if it was lost */
377 nfs4_schedule_state_recovery(server->nfs4_state);
380 err = nfs4_handle_exception(server, err, &exception);
381 } while (exception.retry);
385 static int _nfs4_proc_open_confirm(struct rpc_clnt *clnt, const struct nfs_fh *fh, struct nfs4_state_owner *sp, nfs4_stateid *stateid, struct nfs_seqid *seqid)
387 struct nfs_open_confirmargs arg = {
392 struct nfs_open_confirmres res;
393 struct rpc_message msg = {
394 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_CONFIRM],
397 .rpc_cred = sp->so_cred,
401 status = rpc_call_sync(clnt, &msg, RPC_TASK_NOINTR);
402 /* Confirm the sequence as being established */
403 nfs_confirm_seqid(&sp->so_seqid, status);
404 nfs_increment_open_seqid(status, seqid);
406 memcpy(stateid, &res.stateid, sizeof(*stateid));
410 static int _nfs4_proc_open(struct inode *dir, struct nfs4_state_owner *sp, struct nfs_openargs *o_arg, struct nfs_openres *o_res)
412 struct nfs_server *server = NFS_SERVER(dir);
413 struct rpc_message msg = {
414 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN],
417 .rpc_cred = sp->so_cred,
421 /* Update sequence id. The caller must serialize! */
422 o_arg->id = sp->so_id;
423 o_arg->clientid = sp->so_client->cl_clientid;
425 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
427 /* OPEN on anything except a regular file is disallowed in NFSv4 */
428 switch (o_res->f_attr->mode & S_IFMT) {
442 nfs_increment_open_seqid(status, o_arg->seqid);
445 if (o_arg->open_flags & O_CREAT) {
446 update_changeattr(dir, &o_res->cinfo);
447 nfs_post_op_update_inode(dir, o_res->dir_attr);
449 nfs_refresh_inode(dir, o_res->dir_attr);
450 if(o_res->rflags & NFS4_OPEN_RESULT_CONFIRM) {
451 status = _nfs4_proc_open_confirm(server->client, &o_res->fh,
452 sp, &o_res->stateid, o_arg->seqid);
456 nfs_confirm_seqid(&sp->so_seqid, 0);
457 if (!(o_res->f_attr->valid & NFS_ATTR_FATTR))
458 status = server->rpc_ops->getattr(server, &o_res->fh, o_res->f_attr);
463 static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
465 struct nfs_access_entry cache;
469 if (openflags & FMODE_READ)
471 if (openflags & FMODE_WRITE)
473 status = nfs_access_get_cached(inode, cred, &cache);
477 /* Be clever: ask server to check for all possible rights */
478 cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
480 cache.jiffies = jiffies;
481 status = _nfs4_proc_access(inode, &cache);
484 nfs_access_add_cache(inode, &cache);
486 if ((cache.mask & mask) == mask)
493 * reclaim state on the server after a network partition.
494 * Assumes caller holds the appropriate lock
496 static int _nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
498 struct dentry *parent = dget_parent(dentry);
499 struct inode *dir = parent->d_inode;
500 struct inode *inode = state->inode;
501 struct nfs_server *server = NFS_SERVER(dir);
502 struct nfs_delegation *delegation = NFS_I(inode)->delegation;
503 struct nfs_fattr f_attr, dir_attr;
504 struct nfs_openargs o_arg = {
506 .open_flags = state->state,
507 .name = &dentry->d_name,
508 .bitmask = server->attr_bitmask,
509 .claim = NFS4_OPEN_CLAIM_NULL,
511 struct nfs_openres o_res = {
513 .dir_attr = &dir_attr,
518 if (delegation != NULL && !(delegation->flags & NFS_DELEGATION_NEED_RECLAIM)) {
519 status = _nfs4_do_access(inode, sp->so_cred, state->state);
522 memcpy(&state->stateid, &delegation->stateid, sizeof(state->stateid));
523 set_bit(NFS_DELEGATED_STATE, &state->flags);
526 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
528 if (o_arg.seqid == NULL)
530 nfs_fattr_init(&f_attr);
531 nfs_fattr_init(&dir_attr);
532 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
535 /* Check if files differ */
536 if ((f_attr.mode & S_IFMT) != (inode->i_mode & S_IFMT))
538 /* Has the file handle changed? */
539 if (nfs_compare_fh(&o_res.fh, NFS_FH(inode)) != 0) {
540 /* Verify if the change attributes are the same */
541 if (f_attr.change_attr != NFS_I(inode)->change_attr)
543 if (nfs_size_to_loff_t(f_attr.size) != inode->i_size)
545 /* Lets just pretend that this is the same file */
546 nfs_copy_fh(NFS_FH(inode), &o_res.fh);
547 NFS_I(inode)->fileid = f_attr.fileid;
549 memcpy(&state->stateid, &o_res.stateid, sizeof(state->stateid));
550 if (o_res.delegation_type != 0) {
551 if (!(delegation->flags & NFS_DELEGATION_NEED_RECLAIM))
552 nfs_inode_set_delegation(inode, sp->so_cred, &o_res);
554 nfs_inode_reclaim_delegation(inode, sp->so_cred, &o_res);
557 nfs_free_seqid(o_arg.seqid);
558 clear_bit(NFS_DELEGATED_STATE, &state->flags);
564 /* Invalidate the state owner so we don't ever use it again */
565 nfs4_drop_state_owner(sp);
567 /* Should we be trying to close that stateid? */
571 static inline int nfs4_do_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state, struct dentry *dentry)
573 struct nfs_server *server = NFS_SERVER(dentry->d_inode);
574 struct nfs4_exception exception = { };
578 err = _nfs4_open_expired(sp, state, dentry);
579 if (err == -NFS4ERR_DELAY)
580 nfs4_handle_exception(server, err, &exception);
581 } while (exception.retry);
585 static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
587 struct nfs_inode *nfsi = NFS_I(state->inode);
588 struct nfs_open_context *ctx;
591 spin_lock(&state->inode->i_lock);
592 list_for_each_entry(ctx, &nfsi->open_files, list) {
593 if (ctx->state != state)
595 get_nfs_open_context(ctx);
596 spin_unlock(&state->inode->i_lock);
597 status = nfs4_do_open_expired(sp, state, ctx->dentry);
598 put_nfs_open_context(ctx);
601 spin_unlock(&state->inode->i_lock);
606 * Returns an nfs4_state + an extra reference to the inode
608 static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred, struct nfs4_state **res)
610 struct nfs_delegation *delegation;
611 struct nfs_server *server = NFS_SERVER(inode);
612 struct nfs4_client *clp = server->nfs4_state;
613 struct nfs_inode *nfsi = NFS_I(inode);
614 struct nfs4_state_owner *sp = NULL;
615 struct nfs4_state *state = NULL;
616 int open_flags = flags & (FMODE_READ|FMODE_WRITE);
619 /* Protect against reboot recovery - NOTE ORDER! */
620 down_read(&clp->cl_sem);
621 /* Protect against delegation recall */
622 down_read(&nfsi->rwsem);
623 delegation = NFS_I(inode)->delegation;
625 if (delegation == NULL || (delegation->type & open_flags) != open_flags)
628 if (!(sp = nfs4_get_state_owner(server, cred))) {
629 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
632 state = nfs4_get_open_state(inode, sp);
637 if ((state->state & open_flags) == open_flags) {
638 spin_lock(&inode->i_lock);
639 if (open_flags & FMODE_READ)
641 if (open_flags & FMODE_WRITE)
643 spin_unlock(&inode->i_lock);
645 } else if (state->state != 0)
649 err = _nfs4_do_access(inode, cred, open_flags);
653 set_bit(NFS_DELEGATED_STATE, &state->flags);
654 update_open_stateid(state, &delegation->stateid, open_flags);
656 nfs4_put_state_owner(sp);
657 up_read(&nfsi->rwsem);
658 up_read(&clp->cl_sem);
665 nfs4_put_open_state(state);
666 nfs4_put_state_owner(sp);
668 up_read(&nfsi->rwsem);
669 up_read(&clp->cl_sem);
671 nfs_inode_return_delegation(inode);
675 static struct nfs4_state *nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred *cred)
677 struct nfs4_exception exception = { };
678 struct nfs4_state *res;
682 err = _nfs4_open_delegated(inode, flags, cred, &res);
685 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode),
687 } while (exception.retry);
692 * Returns an nfs4_state + an referenced inode
694 static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred, struct nfs4_state **res)
696 struct nfs4_state_owner *sp;
697 struct nfs4_state *state = NULL;
698 struct nfs_server *server = NFS_SERVER(dir);
699 struct nfs4_client *clp = server->nfs4_state;
700 struct inode *inode = NULL;
702 struct nfs_fattr f_attr, dir_attr;
703 struct nfs_openargs o_arg = {
706 .name = &dentry->d_name,
708 .bitmask = server->attr_bitmask,
709 .claim = NFS4_OPEN_CLAIM_NULL,
711 struct nfs_openres o_res = {
713 .dir_attr = &dir_attr,
717 /* Protect against reboot recovery conflicts */
718 down_read(&clp->cl_sem);
720 if (!(sp = nfs4_get_state_owner(server, cred))) {
721 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
724 if (flags & O_EXCL) {
725 u32 *p = (u32 *) o_arg.u.verifier.data;
729 o_arg.u.attrs = sattr;
730 /* Serialization for the sequence id */
732 o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
733 if (o_arg.seqid == NULL)
735 nfs_fattr_init(&f_attr);
736 nfs_fattr_init(&dir_attr);
737 status = _nfs4_proc_open(dir, sp, &o_arg, &o_res);
742 inode = nfs_fhget(dir->i_sb, &o_res.fh, &f_attr);
745 state = nfs4_get_open_state(inode, sp);
748 update_open_stateid(state, &o_res.stateid, flags);
749 if (o_res.delegation_type != 0)
750 nfs_inode_set_delegation(inode, cred, &o_res);
751 nfs_free_seqid(o_arg.seqid);
752 nfs4_put_state_owner(sp);
753 up_read(&clp->cl_sem);
759 nfs4_put_open_state(state);
760 nfs_free_seqid(o_arg.seqid);
761 nfs4_put_state_owner(sp);
763 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
764 up_read(&clp->cl_sem);
772 static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, struct iattr *sattr, struct rpc_cred *cred)
774 struct nfs4_exception exception = { };
775 struct nfs4_state *res;
779 status = _nfs4_do_open(dir, dentry, flags, sattr, cred, &res);
782 /* NOTE: BAD_SEQID means the server and client disagree about the
783 * book-keeping w.r.t. state-changing operations
784 * (OPEN/CLOSE/LOCK/LOCKU...)
785 * It is actually a sign of a bug on the client or on the server.
787 * If we receive a BAD_SEQID error in the particular case of
788 * doing an OPEN, we assume that nfs_increment_open_seqid() will
789 * have unhashed the old state_owner for us, and that we can
790 * therefore safely retry using a new one. We should still warn
793 if (status == -NFS4ERR_BAD_SEQID) {
794 printk(KERN_WARNING "NFS: v4 server returned a bad sequence-id error!\n");
799 * BAD_STATEID on OPEN means that the server cancelled our
800 * state before it received the OPEN_CONFIRM.
801 * Recover by retrying the request as per the discussion
802 * on Page 181 of RFC3530.
804 if (status == -NFS4ERR_BAD_STATEID) {
808 res = ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir),
809 status, &exception));
810 } while (exception.retry);
814 static int _nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
815 struct nfs_fh *fhandle, struct iattr *sattr,
816 struct nfs4_state *state)
818 struct nfs_setattrargs arg = {
822 .bitmask = server->attr_bitmask,
824 struct nfs_setattrres res = {
828 struct rpc_message msg = {
829 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETATTR],
835 nfs_fattr_init(fattr);
838 msg.rpc_cred = state->owner->so_cred;
839 nfs4_copy_stateid(&arg.stateid, state, current->files);
841 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid));
843 status = rpc_call_sync(server->client, &msg, 0);
847 static int nfs4_do_setattr(struct nfs_server *server, struct nfs_fattr *fattr,
848 struct nfs_fh *fhandle, struct iattr *sattr,
849 struct nfs4_state *state)
851 struct nfs4_exception exception = { };
854 err = nfs4_handle_exception(server,
855 _nfs4_do_setattr(server, fattr, fhandle, sattr,
858 } while (exception.retry);
862 struct nfs4_closedata {
864 struct nfs4_state *state;
865 struct nfs_closeargs arg;
866 struct nfs_closeres res;
867 struct nfs_fattr fattr;
870 static void nfs4_free_closedata(struct nfs4_closedata *calldata)
872 struct nfs4_state *state = calldata->state;
873 struct nfs4_state_owner *sp = state->owner;
875 nfs4_put_open_state(calldata->state);
876 nfs_free_seqid(calldata->arg.seqid);
877 nfs4_put_state_owner(sp);
881 static void nfs4_close_done(struct rpc_task *task)
883 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
884 struct nfs4_state *state = calldata->state;
885 struct nfs_server *server = NFS_SERVER(calldata->inode);
887 /* hmm. we are done with the inode, and in the process of freeing
888 * the state_owner. we keep this around to process errors
890 nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
891 switch (task->tk_status) {
893 memcpy(&state->stateid, &calldata->res.stateid,
894 sizeof(state->stateid));
896 case -NFS4ERR_STALE_STATEID:
897 case -NFS4ERR_EXPIRED:
898 nfs4_schedule_state_recovery(server->nfs4_state);
901 if (nfs4_async_handle_error(task, server) == -EAGAIN) {
902 rpc_restart_call(task);
906 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
907 nfs4_free_closedata(calldata);
910 static void nfs4_close_begin(struct rpc_task *task)
912 struct nfs4_closedata *calldata = (struct nfs4_closedata *)task->tk_calldata;
913 struct nfs4_state *state = calldata->state;
914 struct rpc_message msg = {
915 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE],
916 .rpc_argp = &calldata->arg,
917 .rpc_resp = &calldata->res,
918 .rpc_cred = state->owner->so_cred,
920 int mode = 0, old_mode;
923 status = nfs_wait_on_sequence(calldata->arg.seqid, task);
926 /* Recalculate the new open mode in case someone reopened the file
927 * while we were waiting in line to be scheduled.
929 spin_lock(&state->owner->so_lock);
930 spin_lock(&calldata->inode->i_lock);
931 mode = old_mode = state->state;
932 if (state->nreaders == 0)
934 if (state->nwriters == 0)
935 mode &= ~FMODE_WRITE;
936 nfs4_state_set_mode_locked(state, mode);
937 spin_unlock(&calldata->inode->i_lock);
938 spin_unlock(&state->owner->so_lock);
939 if (mode == old_mode || test_bit(NFS_DELEGATED_STATE, &state->flags)) {
940 nfs4_free_closedata(calldata);
941 task->tk_exit = NULL;
945 nfs_fattr_init(calldata->res.fattr);
947 msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_DOWNGRADE];
948 calldata->arg.open_flags = mode;
949 rpc_call_setup(task, &msg, 0);
953 * It is possible for data to be read/written from a mem-mapped file
954 * after the sys_close call (which hits the vfs layer as a flush).
955 * This means that we can't safely call nfsv4 close on a file until
956 * the inode is cleared. This in turn means that we are not good
957 * NFSv4 citizens - we do not indicate to the server to update the file's
958 * share state even when we are done with one of the three share
959 * stateid's in the inode.
961 * NOTE: Caller must be holding the sp->so_owner semaphore!
963 int nfs4_do_close(struct inode *inode, struct nfs4_state *state)
965 struct nfs_server *server = NFS_SERVER(inode);
966 struct nfs4_closedata *calldata;
967 int status = -ENOMEM;
969 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
970 if (calldata == NULL)
972 calldata->inode = inode;
973 calldata->state = state;
974 calldata->arg.fh = NFS_FH(inode);
975 calldata->arg.stateid = &state->stateid;
976 /* Serialization for the sequence id */
977 calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
978 if (calldata->arg.seqid == NULL)
979 goto out_free_calldata;
980 calldata->arg.bitmask = server->attr_bitmask;
981 calldata->res.fattr = &calldata->fattr;
982 calldata->res.server = server;
984 status = nfs4_call_async(server->client, nfs4_close_begin,
985 nfs4_close_done, calldata);
989 nfs_free_seqid(calldata->arg.seqid);
996 static void nfs4_intent_set_file(struct nameidata *nd, struct dentry *dentry, struct nfs4_state *state)
1000 filp = lookup_instantiate_filp(nd, dentry, NULL);
1001 if (!IS_ERR(filp)) {
1002 struct nfs_open_context *ctx;
1003 ctx = (struct nfs_open_context *)filp->private_data;
1006 nfs4_close_state(state, nd->intent.open.flags);
1010 nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1013 struct rpc_cred *cred;
1014 struct nfs4_state *state;
1017 if (nd->flags & LOOKUP_CREATE) {
1018 attr.ia_mode = nd->intent.open.create_mode;
1019 attr.ia_valid = ATTR_MODE;
1020 if (!IS_POSIXACL(dir))
1021 attr.ia_mode &= ~current->fs->umask;
1024 BUG_ON(nd->intent.open.flags & O_CREAT);
1027 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1029 return (struct dentry *)cred;
1030 state = nfs4_do_open(dir, dentry, nd->intent.open.flags, &attr, cred);
1032 if (IS_ERR(state)) {
1033 if (PTR_ERR(state) == -ENOENT)
1034 d_add(dentry, NULL);
1035 return (struct dentry *)state;
1037 res = d_add_unique(dentry, state->inode);
1040 nfs4_intent_set_file(nd, dentry, state);
1045 nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, struct nameidata *nd)
1047 struct rpc_cred *cred;
1048 struct nfs4_state *state;
1049 struct inode *inode;
1051 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1053 return PTR_ERR(cred);
1054 state = nfs4_open_delegated(dentry->d_inode, openflags, cred);
1056 state = nfs4_do_open(dir, dentry, openflags, NULL, cred);
1058 if (IS_ERR(state)) {
1059 switch (PTR_ERR(state)) {
1065 lookup_instantiate_filp(nd, (struct dentry *)state, NULL);
1068 if (dentry->d_inode == NULL)
1073 inode = state->inode;
1075 if (inode == dentry->d_inode) {
1076 nfs4_intent_set_file(nd, dentry, state);
1079 nfs4_close_state(state, openflags);
1086 static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1088 struct nfs4_server_caps_res res = {};
1089 struct rpc_message msg = {
1090 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SERVER_CAPS],
1091 .rpc_argp = fhandle,
1096 status = rpc_call_sync(server->client, &msg, 0);
1098 memcpy(server->attr_bitmask, res.attr_bitmask, sizeof(server->attr_bitmask));
1099 if (res.attr_bitmask[0] & FATTR4_WORD0_ACL)
1100 server->caps |= NFS_CAP_ACLS;
1101 if (res.has_links != 0)
1102 server->caps |= NFS_CAP_HARDLINKS;
1103 if (res.has_symlinks != 0)
1104 server->caps |= NFS_CAP_SYMLINKS;
1105 server->acl_bitmask = res.acl_bitmask;
1110 static int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
1112 struct nfs4_exception exception = { };
1115 err = nfs4_handle_exception(server,
1116 _nfs4_server_capabilities(server, fhandle),
1118 } while (exception.retry);
1122 static int _nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1123 struct nfs_fsinfo *info)
1125 struct nfs4_lookup_root_arg args = {
1126 .bitmask = nfs4_fattr_bitmap,
1128 struct nfs4_lookup_res res = {
1130 .fattr = info->fattr,
1133 struct rpc_message msg = {
1134 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP_ROOT],
1138 nfs_fattr_init(info->fattr);
1139 return rpc_call_sync(server->client, &msg, 0);
1142 static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
1143 struct nfs_fsinfo *info)
1145 struct nfs4_exception exception = { };
1148 err = nfs4_handle_exception(server,
1149 _nfs4_lookup_root(server, fhandle, info),
1151 } while (exception.retry);
1155 static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
1156 struct nfs_fsinfo *info)
1158 struct nfs_fattr * fattr = info->fattr;
1161 struct nfs4_lookup_arg args = {
1164 .bitmask = nfs4_fattr_bitmap,
1166 struct nfs4_lookup_res res = {
1171 struct rpc_message msg = {
1172 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1179 * Now we do a separate LOOKUP for each component of the mount path.
1180 * The LOOKUPs are done separately so that we can conveniently
1181 * catch an ERR_WRONGSEC if it occurs along the way...
1183 status = nfs4_lookup_root(server, fhandle, info);
1187 p = server->mnt_path;
1189 struct nfs4_exception exception = { };
1196 while (*p && (*p != '/'))
1201 nfs_fattr_init(fattr);
1202 status = nfs4_handle_exception(server,
1203 rpc_call_sync(server->client, &msg, 0),
1205 } while (exception.retry);
1208 if (status == -ENOENT) {
1209 printk(KERN_NOTICE "NFS: mount path %s does not exist!\n", server->mnt_path);
1210 printk(KERN_NOTICE "NFS: suggestion: try mounting '/' instead.\n");
1215 status = nfs4_server_capabilities(server, fhandle);
1217 status = nfs4_do_fsinfo(server, fhandle, info);
1222 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1224 struct nfs4_getattr_arg args = {
1226 .bitmask = server->attr_bitmask,
1228 struct nfs4_getattr_res res = {
1232 struct rpc_message msg = {
1233 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETATTR],
1238 nfs_fattr_init(fattr);
1239 return rpc_call_sync(server->client, &msg, 0);
1242 static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1244 struct nfs4_exception exception = { };
1247 err = nfs4_handle_exception(server,
1248 _nfs4_proc_getattr(server, fhandle, fattr),
1250 } while (exception.retry);
1255 * The file is not closed if it is opened due to the a request to change
1256 * the size of the file. The open call will not be needed once the
1257 * VFS layer lookup-intents are implemented.
1259 * Close is called when the inode is destroyed.
1260 * If we haven't opened the file for O_WRONLY, we
1261 * need to in the size_change case to obtain a stateid.
1264 * Because OPEN is always done by name in nfsv4, it is
1265 * possible that we opened a different file by the same
1266 * name. We can recognize this race condition, but we
1267 * can't do anything about it besides returning an error.
1269 * This will be fixed with VFS changes (lookup-intent).
1272 nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1273 struct iattr *sattr)
1275 struct rpc_cred *cred;
1276 struct inode *inode = dentry->d_inode;
1277 struct nfs4_state *state;
1280 nfs_fattr_init(fattr);
1282 cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);
1284 return PTR_ERR(cred);
1285 /* Search for an existing WRITE delegation first */
1286 state = nfs4_open_delegated(inode, FMODE_WRITE, cred);
1287 if (!IS_ERR(state)) {
1288 /* NB: nfs4_open_delegated() bumps the inode->i_count */
1291 /* Search for an existing open(O_WRITE) stateid */
1292 state = nfs4_find_state(inode, cred, FMODE_WRITE);
1295 status = nfs4_do_setattr(NFS_SERVER(inode), fattr,
1296 NFS_FH(inode), sattr, state);
1298 nfs_setattr_update_inode(inode, sattr);
1300 nfs4_close_state(state, FMODE_WRITE);
1305 static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,
1306 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1309 struct nfs_server *server = NFS_SERVER(dir);
1310 struct nfs4_lookup_arg args = {
1311 .bitmask = server->attr_bitmask,
1312 .dir_fh = NFS_FH(dir),
1315 struct nfs4_lookup_res res = {
1320 struct rpc_message msg = {
1321 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],
1326 nfs_fattr_init(fattr);
1328 dprintk("NFS call lookup %s\n", name->name);
1329 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1330 dprintk("NFS reply lookup: %d\n", status);
1334 static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
1336 struct nfs4_exception exception = { };
1339 err = nfs4_handle_exception(NFS_SERVER(dir),
1340 _nfs4_proc_lookup(dir, name, fhandle, fattr),
1342 } while (exception.retry);
1346 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1348 struct nfs4_accessargs args = {
1349 .fh = NFS_FH(inode),
1351 struct nfs4_accessres res = { 0 };
1352 struct rpc_message msg = {
1353 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
1356 .rpc_cred = entry->cred,
1358 int mode = entry->mask;
1362 * Determine which access bits we want to ask for...
1364 if (mode & MAY_READ)
1365 args.access |= NFS4_ACCESS_READ;
1366 if (S_ISDIR(inode->i_mode)) {
1367 if (mode & MAY_WRITE)
1368 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;
1369 if (mode & MAY_EXEC)
1370 args.access |= NFS4_ACCESS_LOOKUP;
1372 if (mode & MAY_WRITE)
1373 args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;
1374 if (mode & MAY_EXEC)
1375 args.access |= NFS4_ACCESS_EXECUTE;
1377 status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1380 if (res.access & NFS4_ACCESS_READ)
1381 entry->mask |= MAY_READ;
1382 if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))
1383 entry->mask |= MAY_WRITE;
1384 if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
1385 entry->mask |= MAY_EXEC;
1390 static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
1392 struct nfs4_exception exception = { };
1395 err = nfs4_handle_exception(NFS_SERVER(inode),
1396 _nfs4_proc_access(inode, entry),
1398 } while (exception.retry);
1403 * TODO: For the time being, we don't try to get any attributes
1404 * along with any of the zero-copy operations READ, READDIR,
1407 * In the case of the first three, we want to put the GETATTR
1408 * after the read-type operation -- this is because it is hard
1409 * to predict the length of a GETATTR response in v4, and thus
1410 * align the READ data correctly. This means that the GETATTR
1411 * may end up partially falling into the page cache, and we should
1412 * shift it into the 'tail' of the xdr_buf before processing.
1413 * To do this efficiently, we need to know the total length
1414 * of data received, which doesn't seem to be available outside
1417 * In the case of WRITE, we also want to put the GETATTR after
1418 * the operation -- in this case because we want to make sure
1419 * we get the post-operation mtime and size. This means that
1420 * we can't use xdr_encode_pages() as written: we need a variant
1421 * of it which would leave room in the 'tail' iovec.
1423 * Both of these changes to the XDR layer would in fact be quite
1424 * minor, but I decided to leave them for a subsequent patch.
1426 static int _nfs4_proc_readlink(struct inode *inode, struct page *page,
1427 unsigned int pgbase, unsigned int pglen)
1429 struct nfs4_readlink args = {
1430 .fh = NFS_FH(inode),
1435 struct rpc_message msg = {
1436 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],
1441 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
1444 static int nfs4_proc_readlink(struct inode *inode, struct page *page,
1445 unsigned int pgbase, unsigned int pglen)
1447 struct nfs4_exception exception = { };
1450 err = nfs4_handle_exception(NFS_SERVER(inode),
1451 _nfs4_proc_readlink(inode, page, pgbase, pglen),
1453 } while (exception.retry);
1457 static int _nfs4_proc_read(struct nfs_read_data *rdata)
1459 int flags = rdata->flags;
1460 struct inode *inode = rdata->inode;
1461 struct nfs_fattr *fattr = rdata->res.fattr;
1462 struct nfs_server *server = NFS_SERVER(inode);
1463 struct rpc_message msg = {
1464 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
1465 .rpc_argp = &rdata->args,
1466 .rpc_resp = &rdata->res,
1467 .rpc_cred = rdata->cred,
1469 unsigned long timestamp = jiffies;
1472 dprintk("NFS call read %d @ %Ld\n", rdata->args.count,
1473 (long long) rdata->args.offset);
1475 nfs_fattr_init(fattr);
1476 status = rpc_call_sync(server->client, &msg, flags);
1478 renew_lease(server, timestamp);
1479 dprintk("NFS reply read: %d\n", status);
1483 static int nfs4_proc_read(struct nfs_read_data *rdata)
1485 struct nfs4_exception exception = { };
1488 err = nfs4_handle_exception(NFS_SERVER(rdata->inode),
1489 _nfs4_proc_read(rdata),
1491 } while (exception.retry);
1495 static int _nfs4_proc_write(struct nfs_write_data *wdata)
1497 int rpcflags = wdata->flags;
1498 struct inode *inode = wdata->inode;
1499 struct nfs_fattr *fattr = wdata->res.fattr;
1500 struct nfs_server *server = NFS_SERVER(inode);
1501 struct rpc_message msg = {
1502 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
1503 .rpc_argp = &wdata->args,
1504 .rpc_resp = &wdata->res,
1505 .rpc_cred = wdata->cred,
1509 dprintk("NFS call write %d @ %Ld\n", wdata->args.count,
1510 (long long) wdata->args.offset);
1512 nfs_fattr_init(fattr);
1513 status = rpc_call_sync(server->client, &msg, rpcflags);
1514 dprintk("NFS reply write: %d\n", status);
1518 static int nfs4_proc_write(struct nfs_write_data *wdata)
1520 struct nfs4_exception exception = { };
1523 err = nfs4_handle_exception(NFS_SERVER(wdata->inode),
1524 _nfs4_proc_write(wdata),
1526 } while (exception.retry);
1530 static int _nfs4_proc_commit(struct nfs_write_data *cdata)
1532 struct inode *inode = cdata->inode;
1533 struct nfs_fattr *fattr = cdata->res.fattr;
1534 struct nfs_server *server = NFS_SERVER(inode);
1535 struct rpc_message msg = {
1536 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
1537 .rpc_argp = &cdata->args,
1538 .rpc_resp = &cdata->res,
1539 .rpc_cred = cdata->cred,
1543 dprintk("NFS call commit %d @ %Ld\n", cdata->args.count,
1544 (long long) cdata->args.offset);
1546 nfs_fattr_init(fattr);
1547 status = rpc_call_sync(server->client, &msg, 0);
1548 dprintk("NFS reply commit: %d\n", status);
1552 static int nfs4_proc_commit(struct nfs_write_data *cdata)
1554 struct nfs4_exception exception = { };
1557 err = nfs4_handle_exception(NFS_SERVER(cdata->inode),
1558 _nfs4_proc_commit(cdata),
1560 } while (exception.retry);
1566 * We will need to arrange for the VFS layer to provide an atomic open.
1567 * Until then, this create/open method is prone to inefficiency and race
1568 * conditions due to the lookup, create, and open VFS calls from sys_open()
1569 * placed on the wire.
1571 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1572 * The file will be opened again in the subsequent VFS open call
1573 * (nfs4_proc_file_open).
1575 * The open for read will just hang around to be used by any process that
1576 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1580 nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1581 int flags, struct nameidata *nd)
1583 struct nfs4_state *state;
1584 struct rpc_cred *cred;
1587 cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);
1589 status = PTR_ERR(cred);
1592 state = nfs4_do_open(dir, dentry, flags, sattr, cred);
1594 if (IS_ERR(state)) {
1595 status = PTR_ERR(state);
1598 d_instantiate(dentry, state->inode);
1599 if (flags & O_EXCL) {
1600 struct nfs_fattr fattr;
1601 status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,
1602 NFS_FH(state->inode), sattr, state);
1604 nfs_setattr_update_inode(state->inode, sattr);
1606 if (status == 0 && nd != NULL && (nd->flags & LOOKUP_OPEN))
1607 nfs4_intent_set_file(nd, dentry, state);
1609 nfs4_close_state(state, flags);
1614 static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
1616 struct nfs_server *server = NFS_SERVER(dir);
1617 struct nfs4_remove_arg args = {
1620 .bitmask = server->attr_bitmask,
1622 struct nfs_fattr dir_attr;
1623 struct nfs4_remove_res res = {
1625 .dir_attr = &dir_attr,
1627 struct rpc_message msg = {
1628 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE],
1634 nfs_fattr_init(res.dir_attr);
1635 status = rpc_call_sync(server->client, &msg, 0);
1637 update_changeattr(dir, &res.cinfo);
1638 nfs_post_op_update_inode(dir, res.dir_attr);
1643 static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
1645 struct nfs4_exception exception = { };
1648 err = nfs4_handle_exception(NFS_SERVER(dir),
1649 _nfs4_proc_remove(dir, name),
1651 } while (exception.retry);
1655 struct unlink_desc {
1656 struct nfs4_remove_arg args;
1657 struct nfs4_remove_res res;
1658 struct nfs_fattr dir_attr;
1661 static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,
1664 struct nfs_server *server = NFS_SERVER(dir->d_inode);
1665 struct unlink_desc *up;
1667 up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);
1671 up->args.fh = NFS_FH(dir->d_inode);
1672 up->args.name = name;
1673 up->args.bitmask = server->attr_bitmask;
1674 up->res.server = server;
1675 up->res.dir_attr = &up->dir_attr;
1677 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
1678 msg->rpc_argp = &up->args;
1679 msg->rpc_resp = &up->res;
1683 static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task)
1685 struct rpc_message *msg = &task->tk_msg;
1686 struct unlink_desc *up;
1688 if (msg->rpc_resp != NULL) {
1689 up = container_of(msg->rpc_resp, struct unlink_desc, res);
1690 update_changeattr(dir->d_inode, &up->res.cinfo);
1691 nfs_post_op_update_inode(dir->d_inode, up->res.dir_attr);
1693 msg->rpc_resp = NULL;
1694 msg->rpc_argp = NULL;
1699 static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1700 struct inode *new_dir, struct qstr *new_name)
1702 struct nfs_server *server = NFS_SERVER(old_dir);
1703 struct nfs4_rename_arg arg = {
1704 .old_dir = NFS_FH(old_dir),
1705 .new_dir = NFS_FH(new_dir),
1706 .old_name = old_name,
1707 .new_name = new_name,
1708 .bitmask = server->attr_bitmask,
1710 struct nfs_fattr old_fattr, new_fattr;
1711 struct nfs4_rename_res res = {
1713 .old_fattr = &old_fattr,
1714 .new_fattr = &new_fattr,
1716 struct rpc_message msg = {
1717 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
1723 nfs_fattr_init(res.old_fattr);
1724 nfs_fattr_init(res.new_fattr);
1725 status = rpc_call_sync(server->client, &msg, 0);
1728 update_changeattr(old_dir, &res.old_cinfo);
1729 nfs_post_op_update_inode(old_dir, res.old_fattr);
1730 update_changeattr(new_dir, &res.new_cinfo);
1731 nfs_post_op_update_inode(new_dir, res.new_fattr);
1736 static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
1737 struct inode *new_dir, struct qstr *new_name)
1739 struct nfs4_exception exception = { };
1742 err = nfs4_handle_exception(NFS_SERVER(old_dir),
1743 _nfs4_proc_rename(old_dir, old_name,
1746 } while (exception.retry);
1750 static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1752 struct nfs_server *server = NFS_SERVER(inode);
1753 struct nfs4_link_arg arg = {
1754 .fh = NFS_FH(inode),
1755 .dir_fh = NFS_FH(dir),
1757 .bitmask = server->attr_bitmask,
1759 struct nfs_fattr fattr, dir_attr;
1760 struct nfs4_link_res res = {
1763 .dir_attr = &dir_attr,
1765 struct rpc_message msg = {
1766 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
1772 nfs_fattr_init(res.fattr);
1773 nfs_fattr_init(res.dir_attr);
1774 status = rpc_call_sync(server->client, &msg, 0);
1776 update_changeattr(dir, &res.cinfo);
1777 nfs_post_op_update_inode(dir, res.dir_attr);
1778 nfs_refresh_inode(inode, res.fattr);
1784 static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
1786 struct nfs4_exception exception = { };
1789 err = nfs4_handle_exception(NFS_SERVER(inode),
1790 _nfs4_proc_link(inode, dir, name),
1792 } while (exception.retry);
1796 static int _nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1797 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1798 struct nfs_fattr *fattr)
1800 struct nfs_server *server = NFS_SERVER(dir);
1801 struct nfs_fattr dir_fattr;
1802 struct nfs4_create_arg arg = {
1803 .dir_fh = NFS_FH(dir),
1808 .bitmask = server->attr_bitmask,
1810 struct nfs4_create_res res = {
1814 .dir_fattr = &dir_fattr,
1816 struct rpc_message msg = {
1817 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SYMLINK],
1823 if (path->len > NFS4_MAXPATHLEN)
1824 return -ENAMETOOLONG;
1825 arg.u.symlink = path;
1826 nfs_fattr_init(fattr);
1827 nfs_fattr_init(&dir_fattr);
1829 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1831 update_changeattr(dir, &res.dir_cinfo);
1832 nfs_post_op_update_inode(dir, res.dir_fattr);
1836 static int nfs4_proc_symlink(struct inode *dir, struct qstr *name,
1837 struct qstr *path, struct iattr *sattr, struct nfs_fh *fhandle,
1838 struct nfs_fattr *fattr)
1840 struct nfs4_exception exception = { };
1843 err = nfs4_handle_exception(NFS_SERVER(dir),
1844 _nfs4_proc_symlink(dir, name, path, sattr,
1847 } while (exception.retry);
1851 static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1852 struct iattr *sattr)
1854 struct nfs_server *server = NFS_SERVER(dir);
1855 struct nfs_fh fhandle;
1856 struct nfs_fattr fattr, dir_fattr;
1857 struct nfs4_create_arg arg = {
1858 .dir_fh = NFS_FH(dir),
1860 .name = &dentry->d_name,
1863 .bitmask = server->attr_bitmask,
1865 struct nfs4_create_res res = {
1869 .dir_fattr = &dir_fattr,
1871 struct rpc_message msg = {
1872 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1878 nfs_fattr_init(&fattr);
1879 nfs_fattr_init(&dir_fattr);
1881 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1883 update_changeattr(dir, &res.dir_cinfo);
1884 nfs_post_op_update_inode(dir, res.dir_fattr);
1885 status = nfs_instantiate(dentry, &fhandle, &fattr);
1890 static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
1891 struct iattr *sattr)
1893 struct nfs4_exception exception = { };
1896 err = nfs4_handle_exception(NFS_SERVER(dir),
1897 _nfs4_proc_mkdir(dir, dentry, sattr),
1899 } while (exception.retry);
1903 static int _nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1904 u64 cookie, struct page *page, unsigned int count, int plus)
1906 struct inode *dir = dentry->d_inode;
1907 struct nfs4_readdir_arg args = {
1912 .bitmask = NFS_SERVER(dentry->d_inode)->attr_bitmask,
1914 struct nfs4_readdir_res res;
1915 struct rpc_message msg = {
1916 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READDIR],
1923 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__,
1924 dentry->d_parent->d_name.name,
1925 dentry->d_name.name,
1926 (unsigned long long)cookie);
1928 nfs4_setup_readdir(cookie, NFS_COOKIEVERF(dir), dentry, &args);
1929 res.pgbase = args.pgbase;
1930 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
1932 memcpy(NFS_COOKIEVERF(dir), res.verifier.data, NFS4_VERIFIER_SIZE);
1934 dprintk("%s: returns %d\n", __FUNCTION__, status);
1938 static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
1939 u64 cookie, struct page *page, unsigned int count, int plus)
1941 struct nfs4_exception exception = { };
1944 err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
1945 _nfs4_proc_readdir(dentry, cred, cookie,
1948 } while (exception.retry);
1952 static int _nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
1953 struct iattr *sattr, dev_t rdev)
1955 struct nfs_server *server = NFS_SERVER(dir);
1957 struct nfs_fattr fattr, dir_fattr;
1958 struct nfs4_create_arg arg = {
1959 .dir_fh = NFS_FH(dir),
1961 .name = &dentry->d_name,
1963 .bitmask = server->attr_bitmask,
1965 struct nfs4_create_res res = {
1969 .dir_fattr = &dir_fattr,
1971 struct rpc_message msg = {
1972 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CREATE],
1977 int mode = sattr->ia_mode;
1979 nfs_fattr_init(&fattr);
1980 nfs_fattr_init(&dir_fattr);
1982 BUG_ON(!(sattr->ia_valid & ATTR_MODE));
1983 BUG_ON(!S_ISFIFO(mode) && !S_ISBLK(mode) && !S_ISCHR(mode) && !S_ISSOCK(mode));
1985 arg.ftype = NF4FIFO;
1986 else if (S_ISBLK(mode)) {
1988 arg.u.device.specdata1 = MAJOR(rdev);
1989 arg.u.device.specdata2 = MINOR(rdev);
1991 else if (S_ISCHR(mode)) {
1993 arg.u.device.specdata1 = MAJOR(rdev);
1994 arg.u.device.specdata2 = MINOR(rdev);
1997 arg.ftype = NF4SOCK;
1999 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
2001 update_changeattr(dir, &res.dir_cinfo);
2002 nfs_post_op_update_inode(dir, res.dir_fattr);
2003 status = nfs_instantiate(dentry, &fh, &fattr);
2008 static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
2009 struct iattr *sattr, dev_t rdev)
2011 struct nfs4_exception exception = { };
2014 err = nfs4_handle_exception(NFS_SERVER(dir),
2015 _nfs4_proc_mknod(dir, dentry, sattr, rdev),
2017 } while (exception.retry);
2021 static int _nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
2022 struct nfs_fsstat *fsstat)
2024 struct nfs4_statfs_arg args = {
2026 .bitmask = server->attr_bitmask,
2028 struct rpc_message msg = {
2029 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_STATFS],
2034 nfs_fattr_init(fsstat->fattr);
2035 return rpc_call_sync(server->client, &msg, 0);
2038 static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
2040 struct nfs4_exception exception = { };
2043 err = nfs4_handle_exception(server,
2044 _nfs4_proc_statfs(server, fhandle, fsstat),
2046 } while (exception.retry);
2050 static int _nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle,
2051 struct nfs_fsinfo *fsinfo)
2053 struct nfs4_fsinfo_arg args = {
2055 .bitmask = server->attr_bitmask,
2057 struct rpc_message msg = {
2058 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_FSINFO],
2063 return rpc_call_sync(server->client, &msg, 0);
2066 static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
2068 struct nfs4_exception exception = { };
2072 err = nfs4_handle_exception(server,
2073 _nfs4_do_fsinfo(server, fhandle, fsinfo),
2075 } while (exception.retry);
2079 static int nfs4_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
2081 nfs_fattr_init(fsinfo->fattr);
2082 return nfs4_do_fsinfo(server, fhandle, fsinfo);
2085 static int _nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
2086 struct nfs_pathconf *pathconf)
2088 struct nfs4_pathconf_arg args = {
2090 .bitmask = server->attr_bitmask,
2092 struct rpc_message msg = {
2093 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_PATHCONF],
2095 .rpc_resp = pathconf,
2098 /* None of the pathconf attributes are mandatory to implement */
2099 if ((args.bitmask[0] & nfs4_pathconf_bitmap[0]) == 0) {
2100 memset(pathconf, 0, sizeof(*pathconf));
2104 nfs_fattr_init(pathconf->fattr);
2105 return rpc_call_sync(server->client, &msg, 0);
2108 static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
2109 struct nfs_pathconf *pathconf)
2111 struct nfs4_exception exception = { };
2115 err = nfs4_handle_exception(server,
2116 _nfs4_proc_pathconf(server, fhandle, pathconf),
2118 } while (exception.retry);
2123 nfs4_read_done(struct rpc_task *task)
2125 struct nfs_read_data *data = (struct nfs_read_data *) task->tk_calldata;
2126 struct inode *inode = data->inode;
2128 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2129 rpc_restart_call(task);
2132 if (task->tk_status > 0)
2133 renew_lease(NFS_SERVER(inode), data->timestamp);
2134 /* Call back common NFS readpage processing */
2135 nfs_readpage_result(task);
2139 nfs4_proc_read_setup(struct nfs_read_data *data)
2141 struct rpc_task *task = &data->task;
2142 struct rpc_message msg = {
2143 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ],
2144 .rpc_argp = &data->args,
2145 .rpc_resp = &data->res,
2146 .rpc_cred = data->cred,
2148 struct inode *inode = data->inode;
2151 data->timestamp = jiffies;
2153 /* N.B. Do we need to test? Never called for swapfile inode */
2154 flags = RPC_TASK_ASYNC | (IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0);
2156 /* Finalize the task. */
2157 rpc_init_task(task, NFS_CLIENT(inode), nfs4_read_done, flags);
2158 rpc_call_setup(task, &msg, 0);
2162 nfs4_write_done(struct rpc_task *task)
2164 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2165 struct inode *inode = data->inode;
2167 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2168 rpc_restart_call(task);
2171 if (task->tk_status >= 0) {
2172 renew_lease(NFS_SERVER(inode), data->timestamp);
2173 nfs_post_op_update_inode(inode, data->res.fattr);
2175 /* Call back common NFS writeback processing */
2176 nfs_writeback_done(task);
2180 nfs4_proc_write_setup(struct nfs_write_data *data, int how)
2182 struct rpc_task *task = &data->task;
2183 struct rpc_message msg = {
2184 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE],
2185 .rpc_argp = &data->args,
2186 .rpc_resp = &data->res,
2187 .rpc_cred = data->cred,
2189 struct inode *inode = data->inode;
2190 struct nfs_server *server = NFS_SERVER(inode);
2194 if (how & FLUSH_STABLE) {
2195 if (!NFS_I(inode)->ncommit)
2196 stable = NFS_FILE_SYNC;
2198 stable = NFS_DATA_SYNC;
2200 stable = NFS_UNSTABLE;
2201 data->args.stable = stable;
2202 data->args.bitmask = server->attr_bitmask;
2203 data->res.server = server;
2205 data->timestamp = jiffies;
2207 /* Set the initial flags for the task. */
2208 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2210 /* Finalize the task. */
2211 rpc_init_task(task, NFS_CLIENT(inode), nfs4_write_done, flags);
2212 rpc_call_setup(task, &msg, 0);
2216 nfs4_commit_done(struct rpc_task *task)
2218 struct nfs_write_data *data = (struct nfs_write_data *) task->tk_calldata;
2219 struct inode *inode = data->inode;
2221 if (nfs4_async_handle_error(task, NFS_SERVER(inode)) == -EAGAIN) {
2222 rpc_restart_call(task);
2225 if (task->tk_status >= 0)
2226 nfs_post_op_update_inode(inode, data->res.fattr);
2227 /* Call back common NFS writeback processing */
2228 nfs_commit_done(task);
2232 nfs4_proc_commit_setup(struct nfs_write_data *data, int how)
2234 struct rpc_task *task = &data->task;
2235 struct rpc_message msg = {
2236 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
2237 .rpc_argp = &data->args,
2238 .rpc_resp = &data->res,
2239 .rpc_cred = data->cred,
2241 struct inode *inode = data->inode;
2242 struct nfs_server *server = NFS_SERVER(inode);
2245 data->args.bitmask = server->attr_bitmask;
2246 data->res.server = server;
2248 /* Set the initial flags for the task. */
2249 flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
2251 /* Finalize the task. */
2252 rpc_init_task(task, NFS_CLIENT(inode), nfs4_commit_done, flags);
2253 rpc_call_setup(task, &msg, 0);
2257 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2258 * standalone procedure for queueing an asynchronous RENEW.
2261 renew_done(struct rpc_task *task)
2263 struct nfs4_client *clp = (struct nfs4_client *)task->tk_msg.rpc_argp;
2264 unsigned long timestamp = (unsigned long)task->tk_calldata;
2266 if (task->tk_status < 0) {
2267 switch (task->tk_status) {
2268 case -NFS4ERR_STALE_CLIENTID:
2269 case -NFS4ERR_EXPIRED:
2270 case -NFS4ERR_CB_PATH_DOWN:
2271 nfs4_schedule_state_recovery(clp);
2275 spin_lock(&clp->cl_lock);
2276 if (time_before(clp->cl_last_renewal,timestamp))
2277 clp->cl_last_renewal = timestamp;
2278 spin_unlock(&clp->cl_lock);
2282 nfs4_proc_async_renew(struct nfs4_client *clp)
2284 struct rpc_message msg = {
2285 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2287 .rpc_cred = clp->cl_cred,
2290 return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
2291 renew_done, (void *)jiffies);
2295 nfs4_proc_renew(struct nfs4_client *clp)
2297 struct rpc_message msg = {
2298 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENEW],
2300 .rpc_cred = clp->cl_cred,
2302 unsigned long now = jiffies;
2305 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2308 spin_lock(&clp->cl_lock);
2309 if (time_before(clp->cl_last_renewal,now))
2310 clp->cl_last_renewal = now;
2311 spin_unlock(&clp->cl_lock);
2315 static inline int nfs4_server_supports_acls(struct nfs_server *server)
2317 return (server->caps & NFS_CAP_ACLS)
2318 && (server->acl_bitmask & ACL4_SUPPORT_ALLOW_ACL)
2319 && (server->acl_bitmask & ACL4_SUPPORT_DENY_ACL);
2322 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2323 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2326 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2328 static void buf_to_pages(const void *buf, size_t buflen,
2329 struct page **pages, unsigned int *pgbase)
2331 const void *p = buf;
2333 *pgbase = offset_in_page(buf);
2335 while (p < buf + buflen) {
2336 *(pages++) = virt_to_page(p);
2337 p += PAGE_CACHE_SIZE;
2341 struct nfs4_cached_acl {
2347 static void nfs4_set_cached_acl(struct inode *inode, struct nfs4_cached_acl *acl)
2349 struct nfs_inode *nfsi = NFS_I(inode);
2351 spin_lock(&inode->i_lock);
2352 kfree(nfsi->nfs4_acl);
2353 nfsi->nfs4_acl = acl;
2354 spin_unlock(&inode->i_lock);
2357 static void nfs4_zap_acl_attr(struct inode *inode)
2359 nfs4_set_cached_acl(inode, NULL);
2362 static inline ssize_t nfs4_read_cached_acl(struct inode *inode, char *buf, size_t buflen)
2364 struct nfs_inode *nfsi = NFS_I(inode);
2365 struct nfs4_cached_acl *acl;
2368 spin_lock(&inode->i_lock);
2369 acl = nfsi->nfs4_acl;
2372 if (buf == NULL) /* user is just asking for length */
2374 if (acl->cached == 0)
2376 ret = -ERANGE; /* see getxattr(2) man page */
2377 if (acl->len > buflen)
2379 memcpy(buf, acl->data, acl->len);
2383 spin_unlock(&inode->i_lock);
2387 static void nfs4_write_cached_acl(struct inode *inode, const char *buf, size_t acl_len)
2389 struct nfs4_cached_acl *acl;
2391 if (buf && acl_len <= PAGE_SIZE) {
2392 acl = kmalloc(sizeof(*acl) + acl_len, GFP_KERNEL);
2396 memcpy(acl->data, buf, acl_len);
2398 acl = kmalloc(sizeof(*acl), GFP_KERNEL);
2405 nfs4_set_cached_acl(inode, acl);
2408 static inline ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
2410 struct page *pages[NFS4ACL_MAXPAGES];
2411 struct nfs_getaclargs args = {
2412 .fh = NFS_FH(inode),
2416 size_t resp_len = buflen;
2418 struct rpc_message msg = {
2419 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_GETACL],
2421 .rpc_resp = &resp_len,
2423 struct page *localpage = NULL;
2426 if (buflen < PAGE_SIZE) {
2427 /* As long as we're doing a round trip to the server anyway,
2428 * let's be prepared for a page of acl data. */
2429 localpage = alloc_page(GFP_KERNEL);
2430 resp_buf = page_address(localpage);
2431 if (localpage == NULL)
2433 args.acl_pages[0] = localpage;
2434 args.acl_pgbase = 0;
2435 resp_len = args.acl_len = PAGE_SIZE;
2438 buf_to_pages(buf, buflen, args.acl_pages, &args.acl_pgbase);
2440 ret = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2443 if (resp_len > args.acl_len)
2444 nfs4_write_cached_acl(inode, NULL, resp_len);
2446 nfs4_write_cached_acl(inode, resp_buf, resp_len);
2449 if (resp_len > buflen)
2452 memcpy(buf, resp_buf, resp_len);
2457 __free_page(localpage);
2461 static ssize_t nfs4_proc_get_acl(struct inode *inode, void *buf, size_t buflen)
2463 struct nfs_server *server = NFS_SERVER(inode);
2466 if (!nfs4_server_supports_acls(server))
2468 ret = nfs_revalidate_inode(server, inode);
2471 ret = nfs4_read_cached_acl(inode, buf, buflen);
2474 return nfs4_get_acl_uncached(inode, buf, buflen);
2477 static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
2479 struct nfs_server *server = NFS_SERVER(inode);
2480 struct page *pages[NFS4ACL_MAXPAGES];
2481 struct nfs_setaclargs arg = {
2482 .fh = NFS_FH(inode),
2486 struct rpc_message msg = {
2487 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETACL],
2493 if (!nfs4_server_supports_acls(server))
2495 nfs_inode_return_delegation(inode);
2496 buf_to_pages(buf, buflen, arg.acl_pages, &arg.acl_pgbase);
2497 ret = rpc_call_sync(NFS_SERVER(inode)->client, &msg, 0);
2499 nfs4_write_cached_acl(inode, buf, buflen);
2504 nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
2506 struct nfs4_client *clp = server->nfs4_state;
2508 if (!clp || task->tk_status >= 0)
2510 switch(task->tk_status) {
2511 case -NFS4ERR_STALE_CLIENTID:
2512 case -NFS4ERR_STALE_STATEID:
2513 case -NFS4ERR_EXPIRED:
2514 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL);
2515 nfs4_schedule_state_recovery(clp);
2516 if (test_bit(NFS4CLNT_OK, &clp->cl_state))
2517 rpc_wake_up_task(task);
2518 task->tk_status = 0;
2520 case -NFS4ERR_GRACE:
2521 case -NFS4ERR_DELAY:
2522 rpc_delay(task, NFS4_POLL_RETRY_MAX);
2523 task->tk_status = 0;
2525 case -NFS4ERR_OLD_STATEID:
2526 task->tk_status = 0;
2529 task->tk_status = nfs4_map_errors(task->tk_status);
2533 static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs4_client *clp)
2537 int interruptible, res = 0;
2541 rpc_clnt_sigmask(clnt, &oldset);
2542 interruptible = TASK_UNINTERRUPTIBLE;
2544 interruptible = TASK_INTERRUPTIBLE;
2545 prepare_to_wait(&clp->cl_waitq, &wait, interruptible);
2546 nfs4_schedule_state_recovery(clp);
2547 if (clnt->cl_intr && signalled())
2549 else if (!test_bit(NFS4CLNT_OK, &clp->cl_state))
2551 finish_wait(&clp->cl_waitq, &wait);
2552 rpc_clnt_sigunmask(clnt, &oldset);
2556 static int nfs4_delay(struct rpc_clnt *clnt, long *timeout)
2564 *timeout = NFS4_POLL_RETRY_MIN;
2565 if (*timeout > NFS4_POLL_RETRY_MAX)
2566 *timeout = NFS4_POLL_RETRY_MAX;
2567 rpc_clnt_sigmask(clnt, &oldset);
2568 if (clnt->cl_intr) {
2569 schedule_timeout_interruptible(*timeout);
2573 schedule_timeout_uninterruptible(*timeout);
2574 rpc_clnt_sigunmask(clnt, &oldset);
2579 /* This is the error handling routine for processes that are allowed
2582 int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception)
2584 struct nfs4_client *clp = server->nfs4_state;
2585 int ret = errorcode;
2587 exception->retry = 0;
2591 case -NFS4ERR_STALE_CLIENTID:
2592 case -NFS4ERR_STALE_STATEID:
2593 case -NFS4ERR_EXPIRED:
2594 ret = nfs4_wait_clnt_recover(server->client, clp);
2596 exception->retry = 1;
2598 case -NFS4ERR_GRACE:
2599 case -NFS4ERR_DELAY:
2600 ret = nfs4_delay(server->client, &exception->timeout);
2602 exception->retry = 1;
2604 case -NFS4ERR_OLD_STATEID:
2606 exception->retry = 1;
2608 /* We failed to handle the error */
2609 return nfs4_map_errors(ret);
2612 int nfs4_proc_setclientid(struct nfs4_client *clp, u32 program, unsigned short port)
2614 nfs4_verifier sc_verifier;
2615 struct nfs4_setclientid setclientid = {
2616 .sc_verifier = &sc_verifier,
2619 struct rpc_message msg = {
2620 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
2621 .rpc_argp = &setclientid,
2623 .rpc_cred = clp->cl_cred,
2629 p = (u32*)sc_verifier.data;
2630 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
2631 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
2634 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
2635 sizeof(setclientid.sc_name), "%s/%u.%u.%u.%u %s %u",
2636 clp->cl_ipaddr, NIPQUAD(clp->cl_addr.s_addr),
2637 clp->cl_cred->cr_ops->cr_name,
2638 clp->cl_id_uniquifier);
2639 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
2640 sizeof(setclientid.sc_netid), "tcp");
2641 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
2642 sizeof(setclientid.sc_uaddr), "%s.%d.%d",
2643 clp->cl_ipaddr, port >> 8, port & 255);
2645 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2646 if (status != -NFS4ERR_CLID_INUSE)
2651 ssleep(clp->cl_lease_time + 1);
2653 if (++clp->cl_id_uniquifier == 0)
2660 nfs4_proc_setclientid_confirm(struct nfs4_client *clp)
2662 struct nfs_fsinfo fsinfo;
2663 struct rpc_message msg = {
2664 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
2666 .rpc_resp = &fsinfo,
2667 .rpc_cred = clp->cl_cred,
2673 status = rpc_call_sync(clp->cl_rpcclient, &msg, 0);
2675 spin_lock(&clp->cl_lock);
2676 clp->cl_lease_time = fsinfo.lease_time * HZ;
2677 clp->cl_last_renewal = now;
2678 spin_unlock(&clp->cl_lock);
2683 static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2685 struct nfs4_delegreturnargs args = {
2686 .fhandle = NFS_FH(inode),
2689 struct rpc_message msg = {
2690 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DELEGRETURN],
2695 return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
2698 int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid)
2700 struct nfs_server *server = NFS_SERVER(inode);
2701 struct nfs4_exception exception = { };
2704 err = _nfs4_proc_delegreturn(inode, cred, stateid);
2706 case -NFS4ERR_STALE_STATEID:
2707 case -NFS4ERR_EXPIRED:
2708 nfs4_schedule_state_recovery(server->nfs4_state);
2712 err = nfs4_handle_exception(server, err, &exception);
2713 } while (exception.retry);
2717 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2718 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
2721 * sleep, with exponential backoff, and retry the LOCK operation.
2723 static unsigned long
2724 nfs4_set_lock_task_retry(unsigned long timeout)
2726 schedule_timeout_interruptible(timeout);
2728 if (timeout > NFS4_LOCK_MAXTIMEOUT)
2729 return NFS4_LOCK_MAXTIMEOUT;
2734 nfs4_lck_type(int cmd, struct file_lock *request)
2737 switch (request->fl_type) {
2739 return IS_SETLKW(cmd) ? NFS4_READW_LT : NFS4_READ_LT;
2741 return IS_SETLKW(cmd) ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
2743 return NFS4_WRITE_LT;
2749 static inline uint64_t
2750 nfs4_lck_length(struct file_lock *request)
2752 if (request->fl_end == OFFSET_MAX)
2753 return ~(uint64_t)0;
2754 return request->fl_end - request->fl_start + 1;
2757 static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2759 struct inode *inode = state->inode;
2760 struct nfs_server *server = NFS_SERVER(inode);
2761 struct nfs4_client *clp = server->nfs4_state;
2762 struct nfs_lockargs arg = {
2763 .fh = NFS_FH(inode),
2764 .type = nfs4_lck_type(cmd, request),
2765 .offset = request->fl_start,
2766 .length = nfs4_lck_length(request),
2768 struct nfs_lockres res = {
2771 struct rpc_message msg = {
2772 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKT],
2775 .rpc_cred = state->owner->so_cred,
2777 struct nfs_lowner nlo;
2778 struct nfs4_lock_state *lsp;
2781 down_read(&clp->cl_sem);
2782 nlo.clientid = clp->cl_clientid;
2783 status = nfs4_set_lock_state(state, request);
2786 lsp = request->fl_u.nfs4_fl.owner;
2787 nlo.id = lsp->ls_id;
2789 status = rpc_call_sync(server->client, &msg, 0);
2791 request->fl_type = F_UNLCK;
2792 } else if (status == -NFS4ERR_DENIED) {
2793 int64_t len, start, end;
2794 start = res.u.denied.offset;
2795 len = res.u.denied.length;
2796 end = start + len - 1;
2797 if (end < 0 || len == 0)
2798 request->fl_end = OFFSET_MAX;
2800 request->fl_end = (loff_t)end;
2801 request->fl_start = (loff_t)start;
2802 request->fl_type = F_WRLCK;
2803 if (res.u.denied.type & 1)
2804 request->fl_type = F_RDLCK;
2805 request->fl_pid = 0;
2809 up_read(&clp->cl_sem);
2813 static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
2815 struct nfs4_exception exception = { };
2819 err = nfs4_handle_exception(NFS_SERVER(state->inode),
2820 _nfs4_proc_getlk(state, cmd, request),
2822 } while (exception.retry);
2826 static int do_vfs_lock(struct file *file, struct file_lock *fl)
2829 switch (fl->fl_flags & (FL_POSIX|FL_FLOCK)) {
2831 res = posix_lock_file_wait(file, fl);
2834 res = flock_lock_file_wait(file, fl);
2840 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n",
2845 struct nfs4_unlockdata {
2846 struct nfs_lockargs arg;
2847 struct nfs_locku_opargs luargs;
2848 struct nfs_lockres res;
2849 struct nfs4_lock_state *lsp;
2850 struct nfs_open_context *ctx;
2852 struct completion completion;
2855 static void nfs4_locku_release_calldata(struct nfs4_unlockdata *calldata)
2857 if (atomic_dec_and_test(&calldata->refcount)) {
2858 nfs_free_seqid(calldata->luargs.seqid);
2859 nfs4_put_lock_state(calldata->lsp);
2860 put_nfs_open_context(calldata->ctx);
2865 static void nfs4_locku_complete(struct nfs4_unlockdata *calldata)
2867 complete(&calldata->completion);
2868 nfs4_locku_release_calldata(calldata);
2871 static void nfs4_locku_done(struct rpc_task *task)
2873 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
2875 nfs_increment_lock_seqid(task->tk_status, calldata->luargs.seqid);
2876 switch (task->tk_status) {
2878 memcpy(calldata->lsp->ls_stateid.data,
2879 calldata->res.u.stateid.data,
2880 sizeof(calldata->lsp->ls_stateid.data));
2882 case -NFS4ERR_STALE_STATEID:
2883 case -NFS4ERR_EXPIRED:
2884 nfs4_schedule_state_recovery(calldata->res.server->nfs4_state);
2887 if (nfs4_async_handle_error(task, calldata->res.server) == -EAGAIN) {
2888 rpc_restart_call(task);
2892 nfs4_locku_complete(calldata);
2895 static void nfs4_locku_begin(struct rpc_task *task)
2897 struct nfs4_unlockdata *calldata = (struct nfs4_unlockdata *)task->tk_calldata;
2898 struct rpc_message msg = {
2899 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCKU],
2900 .rpc_argp = &calldata->arg,
2901 .rpc_resp = &calldata->res,
2902 .rpc_cred = calldata->lsp->ls_state->owner->so_cred,
2906 status = nfs_wait_on_sequence(calldata->luargs.seqid, task);
2909 if ((calldata->lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0) {
2910 nfs4_locku_complete(calldata);
2911 task->tk_exit = NULL;
2915 rpc_call_setup(task, &msg, 0);
2918 static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *request)
2920 struct nfs4_unlockdata *calldata;
2921 struct inode *inode = state->inode;
2922 struct nfs_server *server = NFS_SERVER(inode);
2923 struct nfs4_lock_state *lsp;
2926 status = nfs4_set_lock_state(state, request);
2929 lsp = request->fl_u.nfs4_fl.owner;
2930 /* We might have lost the locks! */
2931 if ((lsp->ls_flags & NFS_LOCK_INITIALIZED) == 0)
2933 calldata = kmalloc(sizeof(*calldata), GFP_KERNEL);
2934 if (calldata == NULL)
2936 calldata->luargs.seqid = nfs_alloc_seqid(&lsp->ls_seqid);
2937 if (calldata->luargs.seqid == NULL) {
2941 calldata->luargs.stateid = &lsp->ls_stateid;
2942 calldata->arg.fh = NFS_FH(inode);
2943 calldata->arg.type = nfs4_lck_type(cmd, request);
2944 calldata->arg.offset = request->fl_start;
2945 calldata->arg.length = nfs4_lck_length(request);
2946 calldata->arg.u.locku = &calldata->luargs;
2947 calldata->res.server = server;
2948 calldata->lsp = lsp;
2949 atomic_inc(&lsp->ls_count);
2951 /* Ensure we don't close file until we're done freeing locks! */
2952 calldata->ctx = get_nfs_open_context((struct nfs_open_context*)request->fl_file->private_data);
2954 atomic_set(&calldata->refcount, 2);
2955 init_completion(&calldata->completion);
2957 status = nfs4_call_async(NFS_SERVER(inode)->client, nfs4_locku_begin,
2958 nfs4_locku_done, calldata);
2960 wait_for_completion_interruptible(&calldata->completion);
2961 do_vfs_lock(request->fl_file, request);
2962 nfs4_locku_release_calldata(calldata);
2966 static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *request, int reclaim)
2968 struct inode *inode = state->inode;
2969 struct nfs_server *server = NFS_SERVER(inode);
2970 struct nfs4_lock_state *lsp = request->fl_u.nfs4_fl.owner;
2971 struct nfs_lock_opargs largs = {
2972 .lock_stateid = &lsp->ls_stateid,
2973 .open_stateid = &state->stateid,
2975 .clientid = server->nfs4_state->cl_clientid,
2980 struct nfs_lockargs arg = {
2981 .fh = NFS_FH(inode),
2982 .type = nfs4_lck_type(cmd, request),
2983 .offset = request->fl_start,
2984 .length = nfs4_lck_length(request),
2989 struct nfs_lockres res = {
2992 struct rpc_message msg = {
2993 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOCK],
2996 .rpc_cred = state->owner->so_cred,
2998 int status = -ENOMEM;
3000 largs.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
3001 if (largs.lock_seqid == NULL)
3003 if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
3004 struct nfs4_state_owner *owner = state->owner;
3006 largs.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
3007 if (largs.open_seqid == NULL)
3009 largs.new_lock_owner = 1;
3010 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
3011 /* increment open seqid on success, and seqid mutating errors */
3012 if (largs.new_lock_owner != 0) {
3013 nfs_increment_open_seqid(status, largs.open_seqid);
3015 nfs_confirm_seqid(&lsp->ls_seqid, 0);
3017 nfs_free_seqid(largs.open_seqid);
3019 status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
3020 /* increment lock seqid on success, and seqid mutating errors*/
3021 nfs_increment_lock_seqid(status, largs.lock_seqid);
3022 /* save the returned stateid. */
3024 memcpy(lsp->ls_stateid.data, res.u.stateid.data,
3025 sizeof(lsp->ls_stateid.data));
3026 lsp->ls_flags |= NFS_LOCK_INITIALIZED;
3027 } else if (status == -NFS4ERR_DENIED)
3030 nfs_free_seqid(largs.lock_seqid);
3034 static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
3036 struct nfs_server *server = NFS_SERVER(state->inode);
3037 struct nfs4_exception exception = { };
3041 err = _nfs4_do_setlk(state, F_SETLK, request, 1);
3042 if (err != -NFS4ERR_DELAY)
3044 nfs4_handle_exception(server, err, &exception);
3045 } while (exception.retry);
3049 static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
3051 struct nfs_server *server = NFS_SERVER(state->inode);
3052 struct nfs4_exception exception = { };
3056 err = _nfs4_do_setlk(state, F_SETLK, request, 0);
3057 if (err != -NFS4ERR_DELAY)
3059 nfs4_handle_exception(server, err, &exception);
3060 } while (exception.retry);
3064 static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3066 struct nfs4_client *clp = state->owner->so_client;
3069 down_read(&clp->cl_sem);
3070 status = nfs4_set_lock_state(state, request);
3072 status = _nfs4_do_setlk(state, cmd, request, 0);
3074 /* Note: we always want to sleep here! */
3075 request->fl_flags |= FL_SLEEP;
3076 if (do_vfs_lock(request->fl_file, request) < 0)
3077 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
3079 up_read(&clp->cl_sem);
3083 static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
3085 struct nfs4_exception exception = { };
3089 err = nfs4_handle_exception(NFS_SERVER(state->inode),
3090 _nfs4_proc_setlk(state, cmd, request),
3092 } while (exception.retry);
3097 nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
3099 struct nfs_open_context *ctx;
3100 struct nfs4_state *state;
3101 unsigned long timeout = NFS4_LOCK_MINTIMEOUT;
3104 /* verify open state */
3105 ctx = (struct nfs_open_context *)filp->private_data;
3108 if (request->fl_start < 0 || request->fl_end < 0)
3112 return nfs4_proc_getlk(state, F_GETLK, request);
3114 if (!(IS_SETLK(cmd) || IS_SETLKW(cmd)))
3117 if (request->fl_type == F_UNLCK)
3118 return nfs4_proc_unlck(state, cmd, request);
3121 status = nfs4_proc_setlk(state, cmd, request);
3122 if ((status != -EAGAIN) || IS_SETLK(cmd))
3124 timeout = nfs4_set_lock_task_retry(timeout);
3125 status = -ERESTARTSYS;
3128 } while(status < 0);
3133 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3135 int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf,
3136 size_t buflen, int flags)
3138 struct inode *inode = dentry->d_inode;
3140 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3143 if (!S_ISREG(inode->i_mode) &&
3144 (!S_ISDIR(inode->i_mode) || inode->i_mode & S_ISVTX))
3147 return nfs4_proc_set_acl(inode, buf, buflen);
3150 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
3151 * and that's what we'll do for e.g. user attributes that haven't been set.
3152 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3153 * attributes in kernel-managed attribute namespaces. */
3154 ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf,
3157 struct inode *inode = dentry->d_inode;
3159 if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0)
3162 return nfs4_proc_get_acl(inode, buf, buflen);
3165 ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen)
3167 size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1;
3169 if (buf && buflen < len)
3172 memcpy(buf, XATTR_NAME_NFSV4_ACL, len);
3176 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
3177 .recover_open = nfs4_open_reclaim,
3178 .recover_lock = nfs4_lock_reclaim,
3181 struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops = {
3182 .recover_open = nfs4_open_expired,
3183 .recover_lock = nfs4_lock_expired,
3186 static struct inode_operations nfs4_file_inode_operations = {
3187 .permission = nfs_permission,
3188 .getattr = nfs_getattr,
3189 .setattr = nfs_setattr,
3190 .getxattr = nfs4_getxattr,
3191 .setxattr = nfs4_setxattr,
3192 .listxattr = nfs4_listxattr,
3195 struct nfs_rpc_ops nfs_v4_clientops = {
3196 .version = 4, /* protocol version */
3197 .dentry_ops = &nfs4_dentry_operations,
3198 .dir_inode_ops = &nfs4_dir_inode_operations,
3199 .file_inode_ops = &nfs4_file_inode_operations,
3200 .getroot = nfs4_proc_get_root,
3201 .getattr = nfs4_proc_getattr,
3202 .setattr = nfs4_proc_setattr,
3203 .lookup = nfs4_proc_lookup,
3204 .access = nfs4_proc_access,
3205 .readlink = nfs4_proc_readlink,
3206 .read = nfs4_proc_read,
3207 .write = nfs4_proc_write,
3208 .commit = nfs4_proc_commit,
3209 .create = nfs4_proc_create,
3210 .remove = nfs4_proc_remove,
3211 .unlink_setup = nfs4_proc_unlink_setup,
3212 .unlink_done = nfs4_proc_unlink_done,
3213 .rename = nfs4_proc_rename,
3214 .link = nfs4_proc_link,
3215 .symlink = nfs4_proc_symlink,
3216 .mkdir = nfs4_proc_mkdir,
3217 .rmdir = nfs4_proc_remove,
3218 .readdir = nfs4_proc_readdir,
3219 .mknod = nfs4_proc_mknod,
3220 .statfs = nfs4_proc_statfs,
3221 .fsinfo = nfs4_proc_fsinfo,
3222 .pathconf = nfs4_proc_pathconf,
3223 .decode_dirent = nfs4_decode_dirent,
3224 .read_setup = nfs4_proc_read_setup,
3225 .write_setup = nfs4_proc_write_setup,
3226 .commit_setup = nfs4_proc_commit_setup,
3227 .file_open = nfs_open,
3228 .file_release = nfs_release,
3229 .lock = nfs4_proc_lock,
3230 .clear_acl_cache = nfs4_zap_acl_attr,