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"
57 #define NFSDBG_FACILITY NFSDBG_PROC
59 #define NFS4_POLL_RETRY_MIN (HZ/10)
60 #define NFS4_POLL_RETRY_MAX (15*HZ)
63 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
64 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
65 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*);
66 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
);
67 static int nfs4_wait_clnt_recover(struct rpc_clnt
*clnt
, struct nfs_client
*clp
);
68 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
69 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
71 /* Prevent leaks of NFSv4 errors into userland */
72 int nfs4_map_errors(int err
)
77 case -NFS4ERR_RESOURCE
:
80 dprintk("%s could not handle NFSv4 error %d\n",
88 * This is our standard bitmap for GETATTR requests.
90 const u32 nfs4_fattr_bitmap
[2] = {
95 | FATTR4_WORD0_FILEID
,
97 | FATTR4_WORD1_NUMLINKS
99 | FATTR4_WORD1_OWNER_GROUP
100 | FATTR4_WORD1_RAWDEV
101 | FATTR4_WORD1_SPACE_USED
102 | FATTR4_WORD1_TIME_ACCESS
103 | FATTR4_WORD1_TIME_METADATA
104 | FATTR4_WORD1_TIME_MODIFY
107 const u32 nfs4_statfs_bitmap
[2] = {
108 FATTR4_WORD0_FILES_AVAIL
109 | FATTR4_WORD0_FILES_FREE
110 | FATTR4_WORD0_FILES_TOTAL
,
111 FATTR4_WORD1_SPACE_AVAIL
112 | FATTR4_WORD1_SPACE_FREE
113 | FATTR4_WORD1_SPACE_TOTAL
116 const u32 nfs4_pathconf_bitmap
[2] = {
118 | FATTR4_WORD0_MAXNAME
,
122 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
123 | FATTR4_WORD0_MAXREAD
124 | FATTR4_WORD0_MAXWRITE
125 | FATTR4_WORD0_LEASE_TIME
,
129 const u32 nfs4_fs_locations_bitmap
[2] = {
131 | FATTR4_WORD0_CHANGE
134 | FATTR4_WORD0_FILEID
135 | FATTR4_WORD0_FS_LOCATIONS
,
137 | FATTR4_WORD1_NUMLINKS
139 | FATTR4_WORD1_OWNER_GROUP
140 | FATTR4_WORD1_RAWDEV
141 | FATTR4_WORD1_SPACE_USED
142 | FATTR4_WORD1_TIME_ACCESS
143 | FATTR4_WORD1_TIME_METADATA
144 | FATTR4_WORD1_TIME_MODIFY
145 | FATTR4_WORD1_MOUNTED_ON_FILEID
148 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
149 struct nfs4_readdir_arg
*readdir
)
153 BUG_ON(readdir
->count
< 80);
155 readdir
->cookie
= cookie
;
156 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
161 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
166 * NFSv4 servers do not return entries for '.' and '..'
167 * Therefore, we fake these entries here. We let '.'
168 * have cookie 0 and '..' have cookie 1. Note that
169 * when talking to the server, we always send cookie 0
172 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
175 *p
++ = xdr_one
; /* next */
176 *p
++ = xdr_zero
; /* cookie, first word */
177 *p
++ = xdr_one
; /* cookie, second word */
178 *p
++ = xdr_one
; /* entry len */
179 memcpy(p
, ".\0\0\0", 4); /* entry */
181 *p
++ = xdr_one
; /* bitmap length */
182 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
183 *p
++ = htonl(8); /* attribute buffer length */
184 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
187 *p
++ = xdr_one
; /* next */
188 *p
++ = xdr_zero
; /* cookie, first word */
189 *p
++ = xdr_two
; /* cookie, second word */
190 *p
++ = xdr_two
; /* entry len */
191 memcpy(p
, "..\0\0", 4); /* entry */
193 *p
++ = xdr_one
; /* bitmap length */
194 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
195 *p
++ = htonl(8); /* attribute buffer length */
196 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
198 readdir
->pgbase
= (char *)p
- (char *)start
;
199 readdir
->count
-= readdir
->pgbase
;
200 kunmap_atomic(start
, KM_USER0
);
203 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
205 struct nfs_client
*clp
= server
->nfs_client
;
206 spin_lock(&clp
->cl_lock
);
207 if (time_before(clp
->cl_last_renewal
,timestamp
))
208 clp
->cl_last_renewal
= timestamp
;
209 spin_unlock(&clp
->cl_lock
);
212 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
214 struct nfs_inode
*nfsi
= NFS_I(dir
);
216 spin_lock(&dir
->i_lock
);
217 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
218 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
219 nfs_force_lookup_revalidate(dir
);
220 nfsi
->change_attr
= cinfo
->after
;
221 spin_unlock(&dir
->i_lock
);
224 struct nfs4_opendata
{
226 struct nfs_openargs o_arg
;
227 struct nfs_openres o_res
;
228 struct nfs_open_confirmargs c_arg
;
229 struct nfs_open_confirmres c_res
;
230 struct nfs_fattr f_attr
;
231 struct nfs_fattr dir_attr
;
234 struct nfs4_state_owner
*owner
;
235 struct nfs4_state
*state
;
237 unsigned long timestamp
;
238 unsigned int rpc_done
: 1;
244 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
246 p
->o_res
.f_attr
= &p
->f_attr
;
247 p
->o_res
.dir_attr
= &p
->dir_attr
;
248 p
->o_res
.seqid
= p
->o_arg
.seqid
;
249 p
->c_res
.seqid
= p
->c_arg
.seqid
;
250 p
->o_res
.server
= p
->o_arg
.server
;
251 nfs_fattr_init(&p
->f_attr
);
252 nfs_fattr_init(&p
->dir_attr
);
255 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
256 struct nfs4_state_owner
*sp
, int flags
,
257 const struct iattr
*attrs
)
259 struct dentry
*parent
= dget_parent(path
->dentry
);
260 struct inode
*dir
= parent
->d_inode
;
261 struct nfs_server
*server
= NFS_SERVER(dir
);
262 struct nfs4_opendata
*p
;
264 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
267 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
268 if (p
->o_arg
.seqid
== NULL
)
270 p
->path
.mnt
= mntget(path
->mnt
);
271 p
->path
.dentry
= dget(path
->dentry
);
274 atomic_inc(&sp
->so_count
);
275 p
->o_arg
.fh
= NFS_FH(dir
);
276 p
->o_arg
.open_flags
= flags
,
277 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
278 p
->o_arg
.id
= sp
->so_owner_id
.id
;
279 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
280 p
->o_arg
.server
= server
;
281 p
->o_arg
.bitmask
= server
->attr_bitmask
;
282 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
283 if (flags
& O_EXCL
) {
284 u32
*s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
287 } else if (flags
& O_CREAT
) {
288 p
->o_arg
.u
.attrs
= &p
->attrs
;
289 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
291 p
->c_arg
.fh
= &p
->o_res
.fh
;
292 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
293 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
294 nfs4_init_opendata_res(p
);
304 static void nfs4_opendata_free(struct kref
*kref
)
306 struct nfs4_opendata
*p
= container_of(kref
,
307 struct nfs4_opendata
, kref
);
309 nfs_free_seqid(p
->o_arg
.seqid
);
310 if (p
->state
!= NULL
)
311 nfs4_put_open_state(p
->state
);
312 nfs4_put_state_owner(p
->owner
);
318 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
321 kref_put(&p
->kref
, nfs4_opendata_free
);
324 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
328 ret
= rpc_wait_for_completion_task(task
);
332 static int can_open_cached(struct nfs4_state
*state
, int mode
)
335 switch (mode
& (FMODE_READ
|FMODE_WRITE
|O_EXCL
)) {
337 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0;
340 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0;
342 case FMODE_READ
|FMODE_WRITE
:
343 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0;
348 static int can_open_delegated(struct nfs_delegation
*delegation
, mode_t open_flags
)
350 if ((delegation
->type
& open_flags
) != open_flags
)
352 if (delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
)
357 static void update_open_stateflags(struct nfs4_state
*state
, mode_t open_flags
)
359 switch (open_flags
) {
366 case FMODE_READ
|FMODE_WRITE
:
369 nfs4_state_set_mode_locked(state
, state
->state
| open_flags
);
372 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, int open_flags
)
374 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
375 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
376 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
377 switch (open_flags
) {
379 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
382 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
384 case FMODE_READ
|FMODE_WRITE
:
385 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
389 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, int open_flags
)
391 write_seqlock(&state
->seqlock
);
392 nfs_set_open_stateid_locked(state
, stateid
, open_flags
);
393 write_sequnlock(&state
->seqlock
);
396 static void update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*deleg_stateid
, int open_flags
)
398 open_flags
&= (FMODE_READ
|FMODE_WRITE
);
400 * Protect the call to nfs4_state_set_mode_locked and
401 * serialise the stateid update
403 write_seqlock(&state
->seqlock
);
404 if (deleg_stateid
!= NULL
) {
405 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
406 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
408 if (open_stateid
!= NULL
)
409 nfs_set_open_stateid_locked(state
, open_stateid
, open_flags
);
410 write_sequnlock(&state
->seqlock
);
411 spin_lock(&state
->owner
->so_lock
);
412 update_open_stateflags(state
, open_flags
);
413 spin_unlock(&state
->owner
->so_lock
);
416 static void nfs4_return_incompatible_delegation(struct inode
*inode
, mode_t open_flags
)
418 struct nfs_delegation
*delegation
;
421 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
422 if (delegation
== NULL
|| (delegation
->type
& open_flags
) == open_flags
) {
427 nfs_inode_return_delegation(inode
);
430 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
432 struct nfs4_state
*state
= opendata
->state
;
433 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
434 struct nfs_delegation
*delegation
;
435 int open_mode
= opendata
->o_arg
.open_flags
& (FMODE_READ
|FMODE_WRITE
|O_EXCL
);
436 nfs4_stateid stateid
;
440 delegation
= rcu_dereference(nfsi
->delegation
);
442 if (can_open_cached(state
, open_mode
)) {
443 spin_lock(&state
->owner
->so_lock
);
444 if (can_open_cached(state
, open_mode
)) {
445 update_open_stateflags(state
, open_mode
);
446 spin_unlock(&state
->owner
->so_lock
);
448 goto out_return_state
;
450 spin_unlock(&state
->owner
->so_lock
);
452 if (delegation
== NULL
)
454 if (!can_open_delegated(delegation
, open_mode
))
456 /* Save the delegation */
457 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
459 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
464 delegation
= rcu_dereference(nfsi
->delegation
);
465 /* If no delegation, try a cached open */
466 if (delegation
== NULL
)
468 /* Is the delegation still valid? */
469 if (memcmp(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
)) != 0)
472 update_open_stateid(state
, NULL
, &stateid
, open_mode
);
473 goto out_return_state
;
479 atomic_inc(&state
->count
);
483 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
486 struct nfs4_state
*state
= NULL
;
487 struct nfs_delegation
*delegation
;
488 nfs4_stateid
*deleg_stateid
= NULL
;
491 if (!data
->rpc_done
) {
492 state
= nfs4_try_open_cached(data
);
497 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
499 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
500 ret
= PTR_ERR(inode
);
504 state
= nfs4_get_open_state(inode
, data
->owner
);
507 if (data
->o_res
.delegation_type
!= 0) {
508 int delegation_flags
= 0;
511 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
513 delegation_flags
= delegation
->flags
;
515 if (!(delegation_flags
& NFS_DELEGATION_NEED_RECLAIM
))
516 nfs_inode_set_delegation(state
->inode
,
517 data
->owner
->so_cred
,
520 nfs_inode_reclaim_delegation(state
->inode
,
521 data
->owner
->so_cred
,
525 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
526 if (delegation
!= NULL
)
527 deleg_stateid
= &delegation
->stateid
;
528 update_open_stateid(state
, &data
->o_res
.stateid
, deleg_stateid
, data
->o_arg
.open_flags
);
539 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
541 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
542 struct nfs_open_context
*ctx
;
544 spin_lock(&state
->inode
->i_lock
);
545 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
546 if (ctx
->state
!= state
)
548 get_nfs_open_context(ctx
);
549 spin_unlock(&state
->inode
->i_lock
);
552 spin_unlock(&state
->inode
->i_lock
);
553 return ERR_PTR(-ENOENT
);
556 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
558 struct nfs4_opendata
*opendata
;
560 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, NULL
);
561 if (opendata
== NULL
)
562 return ERR_PTR(-ENOMEM
);
563 opendata
->state
= state
;
564 atomic_inc(&state
->count
);
568 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, mode_t openflags
, struct nfs4_state
**res
)
570 struct nfs4_state
*newstate
;
573 opendata
->o_arg
.open_flags
= openflags
;
574 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
575 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
576 nfs4_init_opendata_res(opendata
);
577 ret
= _nfs4_proc_open(opendata
);
580 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
581 if (IS_ERR(newstate
))
582 return PTR_ERR(newstate
);
583 nfs4_close_state(&opendata
->path
, newstate
, openflags
);
588 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
590 struct nfs4_state
*newstate
;
593 /* memory barrier prior to reading state->n_* */
594 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
596 if (state
->n_rdwr
!= 0) {
597 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
600 if (newstate
!= state
)
603 if (state
->n_wronly
!= 0) {
604 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
607 if (newstate
!= state
)
610 if (state
->n_rdonly
!= 0) {
611 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
614 if (newstate
!= state
)
618 * We may have performed cached opens for all three recoveries.
619 * Check if we need to update the current stateid.
621 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
622 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
623 write_seqlock(&state
->seqlock
);
624 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
625 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
626 write_sequnlock(&state
->seqlock
);
633 * reclaim state on the server after a reboot.
635 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
637 struct nfs_delegation
*delegation
;
638 struct nfs4_opendata
*opendata
;
639 int delegation_type
= 0;
642 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
643 if (IS_ERR(opendata
))
644 return PTR_ERR(opendata
);
645 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
646 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
648 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
649 if (delegation
!= NULL
&& (delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
) != 0)
650 delegation_type
= delegation
->type
;
652 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
653 status
= nfs4_open_recover(opendata
, state
);
654 nfs4_opendata_put(opendata
);
658 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
660 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
661 struct nfs4_exception exception
= { };
664 err
= _nfs4_do_open_reclaim(ctx
, state
);
665 if (err
!= -NFS4ERR_DELAY
)
667 nfs4_handle_exception(server
, err
, &exception
);
668 } while (exception
.retry
);
672 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
674 struct nfs_open_context
*ctx
;
677 ctx
= nfs4_state_find_open_context(state
);
680 ret
= nfs4_do_open_reclaim(ctx
, state
);
681 put_nfs_open_context(ctx
);
685 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
687 struct nfs4_opendata
*opendata
;
690 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
691 if (IS_ERR(opendata
))
692 return PTR_ERR(opendata
);
693 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
694 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
695 sizeof(opendata
->o_arg
.u
.delegation
.data
));
696 ret
= nfs4_open_recover(opendata
, state
);
697 nfs4_opendata_put(opendata
);
701 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
703 struct nfs4_exception exception
= { };
704 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
707 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
711 case -NFS4ERR_STALE_CLIENTID
:
712 case -NFS4ERR_STALE_STATEID
:
713 case -NFS4ERR_EXPIRED
:
714 /* Don't recall a delegation if it was lost */
715 nfs4_schedule_state_recovery(server
->nfs_client
);
718 err
= nfs4_handle_exception(server
, err
, &exception
);
719 } while (exception
.retry
);
723 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
725 struct nfs4_opendata
*data
= calldata
;
727 data
->rpc_status
= task
->tk_status
;
728 if (RPC_ASSASSINATED(task
))
730 if (data
->rpc_status
== 0) {
731 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
732 sizeof(data
->o_res
.stateid
.data
));
733 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
734 renew_lease(data
->o_res
.server
, data
->timestamp
);
739 static void nfs4_open_confirm_release(void *calldata
)
741 struct nfs4_opendata
*data
= calldata
;
742 struct nfs4_state
*state
= NULL
;
744 /* If this request hasn't been cancelled, do nothing */
745 if (data
->cancelled
== 0)
747 /* In case of error, no cleanup! */
750 state
= nfs4_opendata_to_nfs4_state(data
);
752 nfs4_close_state(&data
->path
, state
, data
->o_arg
.open_flags
);
754 nfs4_opendata_put(data
);
757 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
758 .rpc_call_done
= nfs4_open_confirm_done
,
759 .rpc_release
= nfs4_open_confirm_release
,
763 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
765 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
767 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
768 struct rpc_task
*task
;
769 struct rpc_message msg
= {
770 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
771 .rpc_argp
= &data
->c_arg
,
772 .rpc_resp
= &data
->c_res
,
773 .rpc_cred
= data
->owner
->so_cred
,
775 struct rpc_task_setup task_setup_data
= {
776 .rpc_client
= server
->client
,
778 .callback_ops
= &nfs4_open_confirm_ops
,
779 .callback_data
= data
,
780 .workqueue
= nfsiod_workqueue
,
781 .flags
= RPC_TASK_ASYNC
,
785 kref_get(&data
->kref
);
787 data
->rpc_status
= 0;
788 data
->timestamp
= jiffies
;
789 task
= rpc_run_task(&task_setup_data
);
791 return PTR_ERR(task
);
792 status
= nfs4_wait_for_completion_rpc_task(task
);
797 status
= data
->rpc_status
;
802 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
804 struct nfs4_opendata
*data
= calldata
;
805 struct nfs4_state_owner
*sp
= data
->owner
;
807 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
810 * Check if we still need to send an OPEN call, or if we can use
811 * a delegation instead.
813 if (data
->state
!= NULL
) {
814 struct nfs_delegation
*delegation
;
816 if (can_open_cached(data
->state
, data
->o_arg
.open_flags
& (FMODE_READ
|FMODE_WRITE
|O_EXCL
)))
819 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
820 if (delegation
!= NULL
&&
821 (delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
) == 0) {
827 /* Update sequence id. */
828 data
->o_arg
.id
= sp
->so_owner_id
.id
;
829 data
->o_arg
.clientid
= sp
->so_client
->cl_clientid
;
830 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
831 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
832 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
834 data
->timestamp
= jiffies
;
835 rpc_call_start(task
);
838 task
->tk_action
= NULL
;
842 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
844 struct nfs4_opendata
*data
= calldata
;
846 data
->rpc_status
= task
->tk_status
;
847 if (RPC_ASSASSINATED(task
))
849 if (task
->tk_status
== 0) {
850 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
854 data
->rpc_status
= -ELOOP
;
857 data
->rpc_status
= -EISDIR
;
860 data
->rpc_status
= -ENOTDIR
;
862 renew_lease(data
->o_res
.server
, data
->timestamp
);
863 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
864 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
869 static void nfs4_open_release(void *calldata
)
871 struct nfs4_opendata
*data
= calldata
;
872 struct nfs4_state
*state
= NULL
;
874 /* If this request hasn't been cancelled, do nothing */
875 if (data
->cancelled
== 0)
877 /* In case of error, no cleanup! */
878 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
880 /* In case we need an open_confirm, no cleanup! */
881 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
883 state
= nfs4_opendata_to_nfs4_state(data
);
885 nfs4_close_state(&data
->path
, state
, data
->o_arg
.open_flags
);
887 nfs4_opendata_put(data
);
890 static const struct rpc_call_ops nfs4_open_ops
= {
891 .rpc_call_prepare
= nfs4_open_prepare
,
892 .rpc_call_done
= nfs4_open_done
,
893 .rpc_release
= nfs4_open_release
,
897 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
899 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
901 struct inode
*dir
= data
->dir
->d_inode
;
902 struct nfs_server
*server
= NFS_SERVER(dir
);
903 struct nfs_openargs
*o_arg
= &data
->o_arg
;
904 struct nfs_openres
*o_res
= &data
->o_res
;
905 struct rpc_task
*task
;
906 struct rpc_message msg
= {
907 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
910 .rpc_cred
= data
->owner
->so_cred
,
912 struct rpc_task_setup task_setup_data
= {
913 .rpc_client
= server
->client
,
915 .callback_ops
= &nfs4_open_ops
,
916 .callback_data
= data
,
917 .workqueue
= nfsiod_workqueue
,
918 .flags
= RPC_TASK_ASYNC
,
922 kref_get(&data
->kref
);
924 data
->rpc_status
= 0;
926 task
= rpc_run_task(&task_setup_data
);
928 return PTR_ERR(task
);
929 status
= nfs4_wait_for_completion_rpc_task(task
);
934 status
= data
->rpc_status
;
936 if (status
!= 0 || !data
->rpc_done
)
939 if (o_res
->fh
.size
== 0)
940 _nfs4_proc_lookup(dir
, o_arg
->name
, &o_res
->fh
, o_res
->f_attr
);
942 if (o_arg
->open_flags
& O_CREAT
) {
943 update_changeattr(dir
, &o_res
->cinfo
);
944 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
946 nfs_refresh_inode(dir
, o_res
->dir_attr
);
947 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
948 status
= _nfs4_proc_open_confirm(data
);
952 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
953 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
957 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
959 struct nfs_client
*clp
= server
->nfs_client
;
963 ret
= nfs4_wait_clnt_recover(server
->client
, clp
);
966 if (!test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
968 nfs4_schedule_state_recovery(clp
);
975 * reclaim state on the server after a network partition.
976 * Assumes caller holds the appropriate lock
978 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
980 struct nfs4_opendata
*opendata
;
983 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
984 if (IS_ERR(opendata
))
985 return PTR_ERR(opendata
);
986 ret
= nfs4_open_recover(opendata
, state
);
988 d_drop(ctx
->path
.dentry
);
989 nfs4_opendata_put(opendata
);
993 static inline int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
995 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
996 struct nfs4_exception exception
= { };
1000 err
= _nfs4_open_expired(ctx
, state
);
1001 if (err
== -NFS4ERR_DELAY
)
1002 nfs4_handle_exception(server
, err
, &exception
);
1003 } while (exception
.retry
);
1007 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1009 struct nfs_open_context
*ctx
;
1012 ctx
= nfs4_state_find_open_context(state
);
1014 return PTR_ERR(ctx
);
1015 ret
= nfs4_do_open_expired(ctx
, state
);
1016 put_nfs_open_context(ctx
);
1021 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1022 * fields corresponding to attributes that were used to store the verifier.
1023 * Make sure we clobber those fields in the later setattr call
1025 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1027 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1028 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1029 sattr
->ia_valid
|= ATTR_ATIME
;
1031 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1032 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1033 sattr
->ia_valid
|= ATTR_MTIME
;
1037 * Returns a referenced nfs4_state
1039 static int _nfs4_do_open(struct inode
*dir
, struct path
*path
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
1041 struct nfs4_state_owner
*sp
;
1042 struct nfs4_state
*state
= NULL
;
1043 struct nfs_server
*server
= NFS_SERVER(dir
);
1044 struct nfs_client
*clp
= server
->nfs_client
;
1045 struct nfs4_opendata
*opendata
;
1048 /* Protect against reboot recovery conflicts */
1050 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1051 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1054 status
= nfs4_recover_expired_lease(server
);
1056 goto err_put_state_owner
;
1057 if (path
->dentry
->d_inode
!= NULL
)
1058 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, flags
& (FMODE_READ
|FMODE_WRITE
));
1059 down_read(&clp
->cl_sem
);
1061 opendata
= nfs4_opendata_alloc(path
, sp
, flags
, sattr
);
1062 if (opendata
== NULL
)
1063 goto err_release_rwsem
;
1065 if (path
->dentry
->d_inode
!= NULL
)
1066 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1068 status
= _nfs4_proc_open(opendata
);
1070 goto err_opendata_put
;
1072 if (opendata
->o_arg
.open_flags
& O_EXCL
)
1073 nfs4_exclusive_attrset(opendata
, sattr
);
1075 state
= nfs4_opendata_to_nfs4_state(opendata
);
1076 status
= PTR_ERR(state
);
1078 goto err_opendata_put
;
1079 nfs4_opendata_put(opendata
);
1080 nfs4_put_state_owner(sp
);
1081 up_read(&clp
->cl_sem
);
1085 nfs4_opendata_put(opendata
);
1087 up_read(&clp
->cl_sem
);
1088 err_put_state_owner
:
1089 nfs4_put_state_owner(sp
);
1096 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct path
*path
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
1098 struct nfs4_exception exception
= { };
1099 struct nfs4_state
*res
;
1103 status
= _nfs4_do_open(dir
, path
, flags
, sattr
, cred
, &res
);
1106 /* NOTE: BAD_SEQID means the server and client disagree about the
1107 * book-keeping w.r.t. state-changing operations
1108 * (OPEN/CLOSE/LOCK/LOCKU...)
1109 * It is actually a sign of a bug on the client or on the server.
1111 * If we receive a BAD_SEQID error in the particular case of
1112 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1113 * have unhashed the old state_owner for us, and that we can
1114 * therefore safely retry using a new one. We should still warn
1115 * the user though...
1117 if (status
== -NFS4ERR_BAD_SEQID
) {
1118 printk(KERN_WARNING
"NFS: v4 server %s "
1119 " returned a bad sequence-id error!\n",
1120 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1121 exception
.retry
= 1;
1125 * BAD_STATEID on OPEN means that the server cancelled our
1126 * state before it received the OPEN_CONFIRM.
1127 * Recover by retrying the request as per the discussion
1128 * on Page 181 of RFC3530.
1130 if (status
== -NFS4ERR_BAD_STATEID
) {
1131 exception
.retry
= 1;
1134 if (status
== -EAGAIN
) {
1135 /* We must have found a delegation */
1136 exception
.retry
= 1;
1139 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1140 status
, &exception
));
1141 } while (exception
.retry
);
1145 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1146 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1147 struct nfs4_state
*state
)
1149 struct nfs_server
*server
= NFS_SERVER(inode
);
1150 struct nfs_setattrargs arg
= {
1151 .fh
= NFS_FH(inode
),
1154 .bitmask
= server
->attr_bitmask
,
1156 struct nfs_setattrres res
= {
1160 struct rpc_message msg
= {
1161 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1166 unsigned long timestamp
= jiffies
;
1169 nfs_fattr_init(fattr
);
1171 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1172 /* Use that stateid */
1173 } else if (state
!= NULL
) {
1174 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
1176 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1178 status
= rpc_call_sync(server
->client
, &msg
, 0);
1179 if (status
== 0 && state
!= NULL
)
1180 renew_lease(server
, timestamp
);
1184 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1185 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1186 struct nfs4_state
*state
)
1188 struct nfs_server
*server
= NFS_SERVER(inode
);
1189 struct nfs4_exception exception
= { };
1192 err
= nfs4_handle_exception(server
,
1193 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1195 } while (exception
.retry
);
1199 struct nfs4_closedata
{
1201 struct inode
*inode
;
1202 struct nfs4_state
*state
;
1203 struct nfs_closeargs arg
;
1204 struct nfs_closeres res
;
1205 struct nfs_fattr fattr
;
1206 unsigned long timestamp
;
1209 static void nfs4_free_closedata(void *data
)
1211 struct nfs4_closedata
*calldata
= data
;
1212 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1214 nfs4_put_open_state(calldata
->state
);
1215 nfs_free_seqid(calldata
->arg
.seqid
);
1216 nfs4_put_state_owner(sp
);
1217 path_put(&calldata
->path
);
1221 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1223 struct nfs4_closedata
*calldata
= data
;
1224 struct nfs4_state
*state
= calldata
->state
;
1225 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1227 if (RPC_ASSASSINATED(task
))
1229 /* hmm. we are done with the inode, and in the process of freeing
1230 * the state_owner. we keep this around to process errors
1232 switch (task
->tk_status
) {
1234 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1235 renew_lease(server
, calldata
->timestamp
);
1237 case -NFS4ERR_STALE_STATEID
:
1238 case -NFS4ERR_EXPIRED
:
1241 if (nfs4_async_handle_error(task
, server
) == -EAGAIN
) {
1242 rpc_restart_call(task
);
1246 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1249 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1251 struct nfs4_closedata
*calldata
= data
;
1252 struct nfs4_state
*state
= calldata
->state
;
1253 int clear_rd
, clear_wr
, clear_rdwr
;
1255 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1258 clear_rd
= clear_wr
= clear_rdwr
= 0;
1259 spin_lock(&state
->owner
->so_lock
);
1260 /* Calculate the change in open mode */
1261 if (state
->n_rdwr
== 0) {
1262 if (state
->n_rdonly
== 0) {
1263 clear_rd
|= test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1264 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1266 if (state
->n_wronly
== 0) {
1267 clear_wr
|= test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1268 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1271 spin_unlock(&state
->owner
->so_lock
);
1272 if (!clear_rd
&& !clear_wr
&& !clear_rdwr
) {
1273 /* Note: exit _without_ calling nfs4_close_done */
1274 task
->tk_action
= NULL
;
1277 nfs_fattr_init(calldata
->res
.fattr
);
1278 if (test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0) {
1279 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1280 calldata
->arg
.open_flags
= FMODE_READ
;
1281 } else if (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0) {
1282 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1283 calldata
->arg
.open_flags
= FMODE_WRITE
;
1285 calldata
->timestamp
= jiffies
;
1286 rpc_call_start(task
);
1289 static const struct rpc_call_ops nfs4_close_ops
= {
1290 .rpc_call_prepare
= nfs4_close_prepare
,
1291 .rpc_call_done
= nfs4_close_done
,
1292 .rpc_release
= nfs4_free_closedata
,
1296 * It is possible for data to be read/written from a mem-mapped file
1297 * after the sys_close call (which hits the vfs layer as a flush).
1298 * This means that we can't safely call nfsv4 close on a file until
1299 * the inode is cleared. This in turn means that we are not good
1300 * NFSv4 citizens - we do not indicate to the server to update the file's
1301 * share state even when we are done with one of the three share
1302 * stateid's in the inode.
1304 * NOTE: Caller must be holding the sp->so_owner semaphore!
1306 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, int wait
)
1308 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1309 struct nfs4_closedata
*calldata
;
1310 struct nfs4_state_owner
*sp
= state
->owner
;
1311 struct rpc_task
*task
;
1312 struct rpc_message msg
= {
1313 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1314 .rpc_cred
= state
->owner
->so_cred
,
1316 struct rpc_task_setup task_setup_data
= {
1317 .rpc_client
= server
->client
,
1318 .rpc_message
= &msg
,
1319 .callback_ops
= &nfs4_close_ops
,
1320 .workqueue
= nfsiod_workqueue
,
1321 .flags
= RPC_TASK_ASYNC
,
1323 int status
= -ENOMEM
;
1325 calldata
= kmalloc(sizeof(*calldata
), GFP_KERNEL
);
1326 if (calldata
== NULL
)
1328 calldata
->inode
= state
->inode
;
1329 calldata
->state
= state
;
1330 calldata
->arg
.fh
= NFS_FH(state
->inode
);
1331 calldata
->arg
.stateid
= &state
->open_stateid
;
1332 /* Serialization for the sequence id */
1333 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
1334 if (calldata
->arg
.seqid
== NULL
)
1335 goto out_free_calldata
;
1336 calldata
->arg
.bitmask
= server
->attr_bitmask
;
1337 calldata
->res
.fattr
= &calldata
->fattr
;
1338 calldata
->res
.seqid
= calldata
->arg
.seqid
;
1339 calldata
->res
.server
= server
;
1340 calldata
->path
.mnt
= mntget(path
->mnt
);
1341 calldata
->path
.dentry
= dget(path
->dentry
);
1343 msg
.rpc_argp
= &calldata
->arg
,
1344 msg
.rpc_resp
= &calldata
->res
,
1345 task_setup_data
.callback_data
= calldata
;
1346 task
= rpc_run_task(&task_setup_data
);
1348 return PTR_ERR(task
);
1351 status
= rpc_wait_for_completion_task(task
);
1357 nfs4_put_open_state(state
);
1358 nfs4_put_state_owner(sp
);
1362 static int nfs4_intent_set_file(struct nameidata
*nd
, struct path
*path
, struct nfs4_state
*state
)
1367 /* If the open_intent is for execute, we have an extra check to make */
1368 if (nd
->intent
.open
.flags
& FMODE_EXEC
) {
1369 ret
= nfs_may_open(state
->inode
,
1370 state
->owner
->so_cred
,
1371 nd
->intent
.open
.flags
);
1375 filp
= lookup_instantiate_filp(nd
, path
->dentry
, NULL
);
1376 if (!IS_ERR(filp
)) {
1377 struct nfs_open_context
*ctx
;
1378 ctx
= nfs_file_open_context(filp
);
1382 ret
= PTR_ERR(filp
);
1384 nfs4_close_sync(path
, state
, nd
->intent
.open
.flags
);
1389 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
1391 struct path path
= {
1392 .mnt
= nd
->path
.mnt
,
1395 struct dentry
*parent
;
1397 struct rpc_cred
*cred
;
1398 struct nfs4_state
*state
;
1401 if (nd
->flags
& LOOKUP_CREATE
) {
1402 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
1403 attr
.ia_valid
= ATTR_MODE
;
1404 if (!IS_POSIXACL(dir
))
1405 attr
.ia_mode
&= ~current
->fs
->umask
;
1408 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
1411 cred
= rpc_lookup_cred();
1413 return (struct dentry
*)cred
;
1414 parent
= dentry
->d_parent
;
1415 /* Protect against concurrent sillydeletes */
1416 nfs_block_sillyrename(parent
);
1417 state
= nfs4_do_open(dir
, &path
, nd
->intent
.open
.flags
, &attr
, cred
);
1419 if (IS_ERR(state
)) {
1420 if (PTR_ERR(state
) == -ENOENT
) {
1421 d_add(dentry
, NULL
);
1422 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1424 nfs_unblock_sillyrename(parent
);
1425 return (struct dentry
*)state
;
1427 res
= d_add_unique(dentry
, igrab(state
->inode
));
1430 nfs_set_verifier(path
.dentry
, nfs_save_change_attribute(dir
));
1431 nfs_unblock_sillyrename(parent
);
1432 nfs4_intent_set_file(nd
, &path
, state
);
1437 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1439 struct path path
= {
1440 .mnt
= nd
->path
.mnt
,
1443 struct rpc_cred
*cred
;
1444 struct nfs4_state
*state
;
1446 cred
= rpc_lookup_cred();
1448 return PTR_ERR(cred
);
1449 state
= nfs4_do_open(dir
, &path
, openflags
, NULL
, cred
);
1451 if (IS_ERR(state
)) {
1452 switch (PTR_ERR(state
)) {
1458 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1464 if (state
->inode
== dentry
->d_inode
) {
1465 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1466 nfs4_intent_set_file(nd
, &path
, state
);
1469 nfs4_close_sync(&path
, state
, openflags
);
1476 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1478 struct nfs4_server_caps_res res
= {};
1479 struct rpc_message msg
= {
1480 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
1481 .rpc_argp
= fhandle
,
1486 status
= rpc_call_sync(server
->client
, &msg
, 0);
1488 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
1489 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
1490 server
->caps
|= NFS_CAP_ACLS
;
1491 if (res
.has_links
!= 0)
1492 server
->caps
|= NFS_CAP_HARDLINKS
;
1493 if (res
.has_symlinks
!= 0)
1494 server
->caps
|= NFS_CAP_SYMLINKS
;
1495 server
->acl_bitmask
= res
.acl_bitmask
;
1500 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1502 struct nfs4_exception exception
= { };
1505 err
= nfs4_handle_exception(server
,
1506 _nfs4_server_capabilities(server
, fhandle
),
1508 } while (exception
.retry
);
1512 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1513 struct nfs_fsinfo
*info
)
1515 struct nfs4_lookup_root_arg args
= {
1516 .bitmask
= nfs4_fattr_bitmap
,
1518 struct nfs4_lookup_res res
= {
1520 .fattr
= info
->fattr
,
1523 struct rpc_message msg
= {
1524 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
1528 nfs_fattr_init(info
->fattr
);
1529 return rpc_call_sync(server
->client
, &msg
, 0);
1532 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1533 struct nfs_fsinfo
*info
)
1535 struct nfs4_exception exception
= { };
1538 err
= nfs4_handle_exception(server
,
1539 _nfs4_lookup_root(server
, fhandle
, info
),
1541 } while (exception
.retry
);
1546 * get the file handle for the "/" directory on the server
1548 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1549 struct nfs_fsinfo
*info
)
1553 status
= nfs4_lookup_root(server
, fhandle
, info
);
1555 status
= nfs4_server_capabilities(server
, fhandle
);
1557 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
1558 return nfs4_map_errors(status
);
1562 * Get locations and (maybe) other attributes of a referral.
1563 * Note that we'll actually follow the referral later when
1564 * we detect fsid mismatch in inode revalidation
1566 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
1568 int status
= -ENOMEM
;
1569 struct page
*page
= NULL
;
1570 struct nfs4_fs_locations
*locations
= NULL
;
1572 page
= alloc_page(GFP_KERNEL
);
1575 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
1576 if (locations
== NULL
)
1579 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
1582 /* Make sure server returned a different fsid for the referral */
1583 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
1584 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
1589 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
1590 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
1592 fattr
->mode
= S_IFDIR
;
1593 memset(fhandle
, 0, sizeof(struct nfs_fh
));
1602 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1604 struct nfs4_getattr_arg args
= {
1606 .bitmask
= server
->attr_bitmask
,
1608 struct nfs4_getattr_res res
= {
1612 struct rpc_message msg
= {
1613 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
1618 nfs_fattr_init(fattr
);
1619 return rpc_call_sync(server
->client
, &msg
, 0);
1622 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1624 struct nfs4_exception exception
= { };
1627 err
= nfs4_handle_exception(server
,
1628 _nfs4_proc_getattr(server
, fhandle
, fattr
),
1630 } while (exception
.retry
);
1635 * The file is not closed if it is opened due to the a request to change
1636 * the size of the file. The open call will not be needed once the
1637 * VFS layer lookup-intents are implemented.
1639 * Close is called when the inode is destroyed.
1640 * If we haven't opened the file for O_WRONLY, we
1641 * need to in the size_change case to obtain a stateid.
1644 * Because OPEN is always done by name in nfsv4, it is
1645 * possible that we opened a different file by the same
1646 * name. We can recognize this race condition, but we
1647 * can't do anything about it besides returning an error.
1649 * This will be fixed with VFS changes (lookup-intent).
1652 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
1653 struct iattr
*sattr
)
1655 struct inode
*inode
= dentry
->d_inode
;
1656 struct rpc_cred
*cred
= NULL
;
1657 struct nfs4_state
*state
= NULL
;
1660 nfs_fattr_init(fattr
);
1662 /* Search for an existing open(O_WRITE) file */
1663 if (sattr
->ia_valid
& ATTR_FILE
) {
1664 struct nfs_open_context
*ctx
;
1666 ctx
= nfs_file_open_context(sattr
->ia_file
);
1671 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
1673 nfs_setattr_update_inode(inode
, sattr
);
1677 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
1678 const struct qstr
*name
, struct nfs_fh
*fhandle
,
1679 struct nfs_fattr
*fattr
)
1682 struct nfs4_lookup_arg args
= {
1683 .bitmask
= server
->attr_bitmask
,
1687 struct nfs4_lookup_res res
= {
1692 struct rpc_message msg
= {
1693 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
1698 nfs_fattr_init(fattr
);
1700 dprintk("NFS call lookupfh %s\n", name
->name
);
1701 status
= rpc_call_sync(server
->client
, &msg
, 0);
1702 dprintk("NFS reply lookupfh: %d\n", status
);
1706 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
1707 struct qstr
*name
, struct nfs_fh
*fhandle
,
1708 struct nfs_fattr
*fattr
)
1710 struct nfs4_exception exception
= { };
1713 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
1715 if (err
== -NFS4ERR_MOVED
) {
1719 err
= nfs4_handle_exception(server
, err
, &exception
);
1720 } while (exception
.retry
);
1724 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
1725 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1729 dprintk("NFS call lookup %s\n", name
->name
);
1730 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
1731 if (status
== -NFS4ERR_MOVED
)
1732 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
1733 dprintk("NFS reply lookup: %d\n", status
);
1737 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1739 struct nfs4_exception exception
= { };
1742 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1743 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
1745 } while (exception
.retry
);
1749 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1751 struct nfs_server
*server
= NFS_SERVER(inode
);
1752 struct nfs_fattr fattr
;
1753 struct nfs4_accessargs args
= {
1754 .fh
= NFS_FH(inode
),
1755 .bitmask
= server
->attr_bitmask
,
1757 struct nfs4_accessres res
= {
1761 struct rpc_message msg
= {
1762 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
1765 .rpc_cred
= entry
->cred
,
1767 int mode
= entry
->mask
;
1771 * Determine which access bits we want to ask for...
1773 if (mode
& MAY_READ
)
1774 args
.access
|= NFS4_ACCESS_READ
;
1775 if (S_ISDIR(inode
->i_mode
)) {
1776 if (mode
& MAY_WRITE
)
1777 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
1778 if (mode
& MAY_EXEC
)
1779 args
.access
|= NFS4_ACCESS_LOOKUP
;
1781 if (mode
& MAY_WRITE
)
1782 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
1783 if (mode
& MAY_EXEC
)
1784 args
.access
|= NFS4_ACCESS_EXECUTE
;
1786 nfs_fattr_init(&fattr
);
1787 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1790 if (res
.access
& NFS4_ACCESS_READ
)
1791 entry
->mask
|= MAY_READ
;
1792 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
1793 entry
->mask
|= MAY_WRITE
;
1794 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
1795 entry
->mask
|= MAY_EXEC
;
1796 nfs_refresh_inode(inode
, &fattr
);
1801 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1803 struct nfs4_exception exception
= { };
1806 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1807 _nfs4_proc_access(inode
, entry
),
1809 } while (exception
.retry
);
1814 * TODO: For the time being, we don't try to get any attributes
1815 * along with any of the zero-copy operations READ, READDIR,
1818 * In the case of the first three, we want to put the GETATTR
1819 * after the read-type operation -- this is because it is hard
1820 * to predict the length of a GETATTR response in v4, and thus
1821 * align the READ data correctly. This means that the GETATTR
1822 * may end up partially falling into the page cache, and we should
1823 * shift it into the 'tail' of the xdr_buf before processing.
1824 * To do this efficiently, we need to know the total length
1825 * of data received, which doesn't seem to be available outside
1828 * In the case of WRITE, we also want to put the GETATTR after
1829 * the operation -- in this case because we want to make sure
1830 * we get the post-operation mtime and size. This means that
1831 * we can't use xdr_encode_pages() as written: we need a variant
1832 * of it which would leave room in the 'tail' iovec.
1834 * Both of these changes to the XDR layer would in fact be quite
1835 * minor, but I decided to leave them for a subsequent patch.
1837 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1838 unsigned int pgbase
, unsigned int pglen
)
1840 struct nfs4_readlink args
= {
1841 .fh
= NFS_FH(inode
),
1846 struct rpc_message msg
= {
1847 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
1852 return rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1855 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1856 unsigned int pgbase
, unsigned int pglen
)
1858 struct nfs4_exception exception
= { };
1861 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1862 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
1864 } while (exception
.retry
);
1870 * We will need to arrange for the VFS layer to provide an atomic open.
1871 * Until then, this create/open method is prone to inefficiency and race
1872 * conditions due to the lookup, create, and open VFS calls from sys_open()
1873 * placed on the wire.
1875 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1876 * The file will be opened again in the subsequent VFS open call
1877 * (nfs4_proc_file_open).
1879 * The open for read will just hang around to be used by any process that
1880 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1884 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
1885 int flags
, struct nameidata
*nd
)
1887 struct path path
= {
1888 .mnt
= nd
->path
.mnt
,
1891 struct nfs4_state
*state
;
1892 struct rpc_cred
*cred
;
1895 cred
= rpc_lookup_cred();
1897 status
= PTR_ERR(cred
);
1900 state
= nfs4_do_open(dir
, &path
, flags
, sattr
, cred
);
1902 if (IS_ERR(state
)) {
1903 status
= PTR_ERR(state
);
1906 d_add(dentry
, igrab(state
->inode
));
1907 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1908 if (flags
& O_EXCL
) {
1909 struct nfs_fattr fattr
;
1910 status
= nfs4_do_setattr(state
->inode
, cred
, &fattr
, sattr
, state
);
1912 nfs_setattr_update_inode(state
->inode
, sattr
);
1913 nfs_post_op_update_inode(state
->inode
, &fattr
);
1915 if (status
== 0 && (nd
->flags
& LOOKUP_OPEN
) != 0)
1916 status
= nfs4_intent_set_file(nd
, &path
, state
);
1918 nfs4_close_sync(&path
, state
, flags
);
1925 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1927 struct nfs_server
*server
= NFS_SERVER(dir
);
1928 struct nfs_removeargs args
= {
1930 .name
.len
= name
->len
,
1931 .name
.name
= name
->name
,
1932 .bitmask
= server
->attr_bitmask
,
1934 struct nfs_removeres res
= {
1937 struct rpc_message msg
= {
1938 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
1944 nfs_fattr_init(&res
.dir_attr
);
1945 status
= rpc_call_sync(server
->client
, &msg
, 0);
1947 update_changeattr(dir
, &res
.cinfo
);
1948 nfs_post_op_update_inode(dir
, &res
.dir_attr
);
1953 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1955 struct nfs4_exception exception
= { };
1958 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1959 _nfs4_proc_remove(dir
, name
),
1961 } while (exception
.retry
);
1965 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
1967 struct nfs_server
*server
= NFS_SERVER(dir
);
1968 struct nfs_removeargs
*args
= msg
->rpc_argp
;
1969 struct nfs_removeres
*res
= msg
->rpc_resp
;
1971 args
->bitmask
= server
->attr_bitmask
;
1972 res
->server
= server
;
1973 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
1976 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
1978 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
1980 if (nfs4_async_handle_error(task
, res
->server
) == -EAGAIN
)
1982 update_changeattr(dir
, &res
->cinfo
);
1983 nfs_post_op_update_inode(dir
, &res
->dir_attr
);
1987 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
1988 struct inode
*new_dir
, struct qstr
*new_name
)
1990 struct nfs_server
*server
= NFS_SERVER(old_dir
);
1991 struct nfs4_rename_arg arg
= {
1992 .old_dir
= NFS_FH(old_dir
),
1993 .new_dir
= NFS_FH(new_dir
),
1994 .old_name
= old_name
,
1995 .new_name
= new_name
,
1996 .bitmask
= server
->attr_bitmask
,
1998 struct nfs_fattr old_fattr
, new_fattr
;
1999 struct nfs4_rename_res res
= {
2001 .old_fattr
= &old_fattr
,
2002 .new_fattr
= &new_fattr
,
2004 struct rpc_message msg
= {
2005 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2011 nfs_fattr_init(res
.old_fattr
);
2012 nfs_fattr_init(res
.new_fattr
);
2013 status
= rpc_call_sync(server
->client
, &msg
, 0);
2016 update_changeattr(old_dir
, &res
.old_cinfo
);
2017 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2018 update_changeattr(new_dir
, &res
.new_cinfo
);
2019 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2024 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2025 struct inode
*new_dir
, struct qstr
*new_name
)
2027 struct nfs4_exception exception
= { };
2030 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2031 _nfs4_proc_rename(old_dir
, old_name
,
2034 } while (exception
.retry
);
2038 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2040 struct nfs_server
*server
= NFS_SERVER(inode
);
2041 struct nfs4_link_arg arg
= {
2042 .fh
= NFS_FH(inode
),
2043 .dir_fh
= NFS_FH(dir
),
2045 .bitmask
= server
->attr_bitmask
,
2047 struct nfs_fattr fattr
, dir_attr
;
2048 struct nfs4_link_res res
= {
2051 .dir_attr
= &dir_attr
,
2053 struct rpc_message msg
= {
2054 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2060 nfs_fattr_init(res
.fattr
);
2061 nfs_fattr_init(res
.dir_attr
);
2062 status
= rpc_call_sync(server
->client
, &msg
, 0);
2064 update_changeattr(dir
, &res
.cinfo
);
2065 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2066 nfs_post_op_update_inode(inode
, res
.fattr
);
2072 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2074 struct nfs4_exception exception
= { };
2077 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2078 _nfs4_proc_link(inode
, dir
, name
),
2080 } while (exception
.retry
);
2084 struct nfs4_createdata
{
2085 struct rpc_message msg
;
2086 struct nfs4_create_arg arg
;
2087 struct nfs4_create_res res
;
2089 struct nfs_fattr fattr
;
2090 struct nfs_fattr dir_fattr
;
2093 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2094 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2096 struct nfs4_createdata
*data
;
2098 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2100 struct nfs_server
*server
= NFS_SERVER(dir
);
2102 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2103 data
->msg
.rpc_argp
= &data
->arg
;
2104 data
->msg
.rpc_resp
= &data
->res
;
2105 data
->arg
.dir_fh
= NFS_FH(dir
);
2106 data
->arg
.server
= server
;
2107 data
->arg
.name
= name
;
2108 data
->arg
.attrs
= sattr
;
2109 data
->arg
.ftype
= ftype
;
2110 data
->arg
.bitmask
= server
->attr_bitmask
;
2111 data
->res
.server
= server
;
2112 data
->res
.fh
= &data
->fh
;
2113 data
->res
.fattr
= &data
->fattr
;
2114 data
->res
.dir_fattr
= &data
->dir_fattr
;
2115 nfs_fattr_init(data
->res
.fattr
);
2116 nfs_fattr_init(data
->res
.dir_fattr
);
2121 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2123 int status
= rpc_call_sync(NFS_CLIENT(dir
), &data
->msg
, 0);
2125 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2126 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2127 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2132 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2137 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2138 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2140 struct nfs4_createdata
*data
;
2141 int status
= -ENAMETOOLONG
;
2143 if (len
> NFS4_MAXPATHLEN
)
2147 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2151 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2152 data
->arg
.u
.symlink
.pages
= &page
;
2153 data
->arg
.u
.symlink
.len
= len
;
2155 status
= nfs4_do_create(dir
, dentry
, data
);
2157 nfs4_free_createdata(data
);
2162 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2163 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2165 struct nfs4_exception exception
= { };
2168 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2169 _nfs4_proc_symlink(dir
, dentry
, page
,
2172 } while (exception
.retry
);
2176 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2177 struct iattr
*sattr
)
2179 struct nfs4_createdata
*data
;
2180 int status
= -ENOMEM
;
2182 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2186 status
= nfs4_do_create(dir
, dentry
, data
);
2188 nfs4_free_createdata(data
);
2193 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2194 struct iattr
*sattr
)
2196 struct nfs4_exception exception
= { };
2199 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2200 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2202 } while (exception
.retry
);
2206 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2207 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2209 struct inode
*dir
= dentry
->d_inode
;
2210 struct nfs4_readdir_arg args
= {
2215 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2217 struct nfs4_readdir_res res
;
2218 struct rpc_message msg
= {
2219 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2226 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2227 dentry
->d_parent
->d_name
.name
,
2228 dentry
->d_name
.name
,
2229 (unsigned long long)cookie
);
2230 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2231 res
.pgbase
= args
.pgbase
;
2232 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
2234 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2236 nfs_invalidate_atime(dir
);
2238 dprintk("%s: returns %d\n", __func__
, status
);
2242 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2243 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2245 struct nfs4_exception exception
= { };
2248 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2249 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2252 } while (exception
.retry
);
2256 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2257 struct iattr
*sattr
, dev_t rdev
)
2259 struct nfs4_createdata
*data
;
2260 int mode
= sattr
->ia_mode
;
2261 int status
= -ENOMEM
;
2263 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2264 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2266 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2271 data
->arg
.ftype
= NF4FIFO
;
2272 else if (S_ISBLK(mode
)) {
2273 data
->arg
.ftype
= NF4BLK
;
2274 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2275 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2277 else if (S_ISCHR(mode
)) {
2278 data
->arg
.ftype
= NF4CHR
;
2279 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2280 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2283 status
= nfs4_do_create(dir
, dentry
, data
);
2285 nfs4_free_createdata(data
);
2290 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2291 struct iattr
*sattr
, dev_t rdev
)
2293 struct nfs4_exception exception
= { };
2296 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2297 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2299 } while (exception
.retry
);
2303 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2304 struct nfs_fsstat
*fsstat
)
2306 struct nfs4_statfs_arg args
= {
2308 .bitmask
= server
->attr_bitmask
,
2310 struct rpc_message msg
= {
2311 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2316 nfs_fattr_init(fsstat
->fattr
);
2317 return rpc_call_sync(server
->client
, &msg
, 0);
2320 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2322 struct nfs4_exception exception
= { };
2325 err
= nfs4_handle_exception(server
,
2326 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2328 } while (exception
.retry
);
2332 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2333 struct nfs_fsinfo
*fsinfo
)
2335 struct nfs4_fsinfo_arg args
= {
2337 .bitmask
= server
->attr_bitmask
,
2339 struct rpc_message msg
= {
2340 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
2345 return rpc_call_sync(server
->client
, &msg
, 0);
2348 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2350 struct nfs4_exception exception
= { };
2354 err
= nfs4_handle_exception(server
,
2355 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
2357 } while (exception
.retry
);
2361 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2363 nfs_fattr_init(fsinfo
->fattr
);
2364 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2367 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2368 struct nfs_pathconf
*pathconf
)
2370 struct nfs4_pathconf_arg args
= {
2372 .bitmask
= server
->attr_bitmask
,
2374 struct rpc_message msg
= {
2375 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2377 .rpc_resp
= pathconf
,
2380 /* None of the pathconf attributes are mandatory to implement */
2381 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2382 memset(pathconf
, 0, sizeof(*pathconf
));
2386 nfs_fattr_init(pathconf
->fattr
);
2387 return rpc_call_sync(server
->client
, &msg
, 0);
2390 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2391 struct nfs_pathconf
*pathconf
)
2393 struct nfs4_exception exception
= { };
2397 err
= nfs4_handle_exception(server
,
2398 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2400 } while (exception
.retry
);
2404 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
2406 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2408 if (nfs4_async_handle_error(task
, server
) == -EAGAIN
) {
2409 rpc_restart_call(task
);
2413 nfs_invalidate_atime(data
->inode
);
2414 if (task
->tk_status
> 0)
2415 renew_lease(server
, data
->timestamp
);
2419 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
2421 data
->timestamp
= jiffies
;
2422 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
2425 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
2427 struct inode
*inode
= data
->inode
;
2429 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2430 rpc_restart_call(task
);
2433 if (task
->tk_status
>= 0) {
2434 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
2435 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
2440 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
2442 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2444 data
->args
.bitmask
= server
->attr_bitmask
;
2445 data
->res
.server
= server
;
2446 data
->timestamp
= jiffies
;
2448 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
2451 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
2453 struct inode
*inode
= data
->inode
;
2455 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2456 rpc_restart_call(task
);
2459 nfs_refresh_inode(inode
, data
->res
.fattr
);
2463 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
2465 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2467 data
->args
.bitmask
= server
->attr_bitmask
;
2468 data
->res
.server
= server
;
2469 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
2473 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2474 * standalone procedure for queueing an asynchronous RENEW.
2476 static void nfs4_renew_done(struct rpc_task
*task
, void *data
)
2478 struct nfs_client
*clp
= (struct nfs_client
*)task
->tk_msg
.rpc_argp
;
2479 unsigned long timestamp
= (unsigned long)data
;
2481 if (task
->tk_status
< 0) {
2482 switch (task
->tk_status
) {
2483 case -NFS4ERR_STALE_CLIENTID
:
2484 case -NFS4ERR_EXPIRED
:
2485 case -NFS4ERR_CB_PATH_DOWN
:
2486 nfs4_schedule_state_recovery(clp
);
2490 spin_lock(&clp
->cl_lock
);
2491 if (time_before(clp
->cl_last_renewal
,timestamp
))
2492 clp
->cl_last_renewal
= timestamp
;
2493 spin_unlock(&clp
->cl_lock
);
2496 static const struct rpc_call_ops nfs4_renew_ops
= {
2497 .rpc_call_done
= nfs4_renew_done
,
2500 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2502 struct rpc_message msg
= {
2503 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2508 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
2509 &nfs4_renew_ops
, (void *)jiffies
);
2512 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2514 struct rpc_message msg
= {
2515 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2519 unsigned long now
= jiffies
;
2522 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2525 spin_lock(&clp
->cl_lock
);
2526 if (time_before(clp
->cl_last_renewal
,now
))
2527 clp
->cl_last_renewal
= now
;
2528 spin_unlock(&clp
->cl_lock
);
2532 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
2534 return (server
->caps
& NFS_CAP_ACLS
)
2535 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
2536 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
2539 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2540 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2543 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2545 static void buf_to_pages(const void *buf
, size_t buflen
,
2546 struct page
**pages
, unsigned int *pgbase
)
2548 const void *p
= buf
;
2550 *pgbase
= offset_in_page(buf
);
2552 while (p
< buf
+ buflen
) {
2553 *(pages
++) = virt_to_page(p
);
2554 p
+= PAGE_CACHE_SIZE
;
2558 struct nfs4_cached_acl
{
2564 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
2566 struct nfs_inode
*nfsi
= NFS_I(inode
);
2568 spin_lock(&inode
->i_lock
);
2569 kfree(nfsi
->nfs4_acl
);
2570 nfsi
->nfs4_acl
= acl
;
2571 spin_unlock(&inode
->i_lock
);
2574 static void nfs4_zap_acl_attr(struct inode
*inode
)
2576 nfs4_set_cached_acl(inode
, NULL
);
2579 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
2581 struct nfs_inode
*nfsi
= NFS_I(inode
);
2582 struct nfs4_cached_acl
*acl
;
2585 spin_lock(&inode
->i_lock
);
2586 acl
= nfsi
->nfs4_acl
;
2589 if (buf
== NULL
) /* user is just asking for length */
2591 if (acl
->cached
== 0)
2593 ret
= -ERANGE
; /* see getxattr(2) man page */
2594 if (acl
->len
> buflen
)
2596 memcpy(buf
, acl
->data
, acl
->len
);
2600 spin_unlock(&inode
->i_lock
);
2604 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
2606 struct nfs4_cached_acl
*acl
;
2608 if (buf
&& acl_len
<= PAGE_SIZE
) {
2609 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
2613 memcpy(acl
->data
, buf
, acl_len
);
2615 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
2622 nfs4_set_cached_acl(inode
, acl
);
2625 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
2627 struct page
*pages
[NFS4ACL_MAXPAGES
];
2628 struct nfs_getaclargs args
= {
2629 .fh
= NFS_FH(inode
),
2633 size_t resp_len
= buflen
;
2635 struct rpc_message msg
= {
2636 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
2638 .rpc_resp
= &resp_len
,
2640 struct page
*localpage
= NULL
;
2643 if (buflen
< PAGE_SIZE
) {
2644 /* As long as we're doing a round trip to the server anyway,
2645 * let's be prepared for a page of acl data. */
2646 localpage
= alloc_page(GFP_KERNEL
);
2647 resp_buf
= page_address(localpage
);
2648 if (localpage
== NULL
)
2650 args
.acl_pages
[0] = localpage
;
2651 args
.acl_pgbase
= 0;
2652 resp_len
= args
.acl_len
= PAGE_SIZE
;
2655 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
2657 ret
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2660 if (resp_len
> args
.acl_len
)
2661 nfs4_write_cached_acl(inode
, NULL
, resp_len
);
2663 nfs4_write_cached_acl(inode
, resp_buf
, resp_len
);
2666 if (resp_len
> buflen
)
2669 memcpy(buf
, resp_buf
, resp_len
);
2674 __free_page(localpage
);
2678 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
2680 struct nfs4_exception exception
= { };
2683 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
2686 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
2687 } while (exception
.retry
);
2691 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
2693 struct nfs_server
*server
= NFS_SERVER(inode
);
2696 if (!nfs4_server_supports_acls(server
))
2698 ret
= nfs_revalidate_inode(server
, inode
);
2701 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
2702 nfs_zap_acl_cache(inode
);
2703 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
2706 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
2709 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
2711 struct nfs_server
*server
= NFS_SERVER(inode
);
2712 struct page
*pages
[NFS4ACL_MAXPAGES
];
2713 struct nfs_setaclargs arg
= {
2714 .fh
= NFS_FH(inode
),
2718 struct rpc_message msg
= {
2719 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
2725 if (!nfs4_server_supports_acls(server
))
2727 nfs_inode_return_delegation(inode
);
2728 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
2729 ret
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2730 nfs_access_zap_cache(inode
);
2731 nfs_zap_acl_cache(inode
);
2735 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
2737 struct nfs4_exception exception
= { };
2740 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2741 __nfs4_proc_set_acl(inode
, buf
, buflen
),
2743 } while (exception
.retry
);
2748 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
)
2750 struct nfs_client
*clp
= server
->nfs_client
;
2752 if (!clp
|| task
->tk_status
>= 0)
2754 switch(task
->tk_status
) {
2755 case -NFS4ERR_STALE_CLIENTID
:
2756 case -NFS4ERR_STALE_STATEID
:
2757 case -NFS4ERR_EXPIRED
:
2758 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
2759 nfs4_schedule_state_recovery(clp
);
2760 if (test_bit(NFS4CLNT_STATE_RECOVER
, &clp
->cl_state
) == 0)
2761 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
2762 task
->tk_status
= 0;
2764 case -NFS4ERR_DELAY
:
2765 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
2766 case -NFS4ERR_GRACE
:
2767 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
2768 task
->tk_status
= 0;
2770 case -NFS4ERR_OLD_STATEID
:
2771 task
->tk_status
= 0;
2774 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
2778 static int nfs4_wait_bit_killable(void *word
)
2780 if (fatal_signal_pending(current
))
2781 return -ERESTARTSYS
;
2786 static int nfs4_wait_clnt_recover(struct rpc_clnt
*clnt
, struct nfs_client
*clp
)
2792 rwsem_acquire(&clp
->cl_sem
.dep_map
, 0, 0, _RET_IP_
);
2794 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_STATE_RECOVER
,
2795 nfs4_wait_bit_killable
, TASK_KILLABLE
);
2797 rwsem_release(&clp
->cl_sem
.dep_map
, 1, _RET_IP_
);
2801 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
2808 *timeout
= NFS4_POLL_RETRY_MIN
;
2809 if (*timeout
> NFS4_POLL_RETRY_MAX
)
2810 *timeout
= NFS4_POLL_RETRY_MAX
;
2811 schedule_timeout_killable(*timeout
);
2812 if (fatal_signal_pending(current
))
2818 /* This is the error handling routine for processes that are allowed
2821 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
2823 struct nfs_client
*clp
= server
->nfs_client
;
2824 int ret
= errorcode
;
2826 exception
->retry
= 0;
2830 case -NFS4ERR_STALE_CLIENTID
:
2831 case -NFS4ERR_STALE_STATEID
:
2832 case -NFS4ERR_EXPIRED
:
2833 nfs4_schedule_state_recovery(clp
);
2834 ret
= nfs4_wait_clnt_recover(server
->client
, clp
);
2836 exception
->retry
= 1;
2838 case -NFS4ERR_FILE_OPEN
:
2839 case -NFS4ERR_GRACE
:
2840 case -NFS4ERR_DELAY
:
2841 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
2844 case -NFS4ERR_OLD_STATEID
:
2845 exception
->retry
= 1;
2847 /* We failed to handle the error */
2848 return nfs4_map_errors(ret
);
2851 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
, unsigned short port
, struct rpc_cred
*cred
)
2853 nfs4_verifier sc_verifier
;
2854 struct nfs4_setclientid setclientid
= {
2855 .sc_verifier
= &sc_verifier
,
2858 struct rpc_message msg
= {
2859 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
2860 .rpc_argp
= &setclientid
,
2868 p
= (__be32
*)sc_verifier
.data
;
2869 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
2870 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
2873 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
2874 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
2876 rpc_peeraddr2str(clp
->cl_rpcclient
,
2878 rpc_peeraddr2str(clp
->cl_rpcclient
,
2880 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
2881 clp
->cl_id_uniquifier
);
2882 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
2883 sizeof(setclientid
.sc_netid
),
2884 rpc_peeraddr2str(clp
->cl_rpcclient
,
2885 RPC_DISPLAY_NETID
));
2886 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
2887 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
2888 clp
->cl_ipaddr
, port
>> 8, port
& 255);
2890 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2891 if (status
!= -NFS4ERR_CLID_INUSE
)
2896 ssleep(clp
->cl_lease_time
+ 1);
2898 if (++clp
->cl_id_uniquifier
== 0)
2904 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2906 struct nfs_fsinfo fsinfo
;
2907 struct rpc_message msg
= {
2908 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
2910 .rpc_resp
= &fsinfo
,
2917 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2919 spin_lock(&clp
->cl_lock
);
2920 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
2921 clp
->cl_last_renewal
= now
;
2922 clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
2923 spin_unlock(&clp
->cl_lock
);
2928 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2933 err
= _nfs4_proc_setclientid_confirm(clp
, cred
);
2937 case -NFS4ERR_RESOURCE
:
2938 /* The IBM lawyers misread another document! */
2939 case -NFS4ERR_DELAY
:
2940 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
2946 struct nfs4_delegreturndata
{
2947 struct nfs4_delegreturnargs args
;
2948 struct nfs4_delegreturnres res
;
2950 nfs4_stateid stateid
;
2951 unsigned long timestamp
;
2952 struct nfs_fattr fattr
;
2956 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
2958 struct nfs4_delegreturndata
*data
= calldata
;
2959 data
->rpc_status
= task
->tk_status
;
2960 if (data
->rpc_status
== 0)
2961 renew_lease(data
->res
.server
, data
->timestamp
);
2964 static void nfs4_delegreturn_release(void *calldata
)
2969 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
2970 .rpc_call_done
= nfs4_delegreturn_done
,
2971 .rpc_release
= nfs4_delegreturn_release
,
2974 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
2976 struct nfs4_delegreturndata
*data
;
2977 struct nfs_server
*server
= NFS_SERVER(inode
);
2978 struct rpc_task
*task
;
2979 struct rpc_message msg
= {
2980 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
2983 struct rpc_task_setup task_setup_data
= {
2984 .rpc_client
= server
->client
,
2985 .rpc_message
= &msg
,
2986 .callback_ops
= &nfs4_delegreturn_ops
,
2987 .flags
= RPC_TASK_ASYNC
,
2991 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
2994 data
->args
.fhandle
= &data
->fh
;
2995 data
->args
.stateid
= &data
->stateid
;
2996 data
->args
.bitmask
= server
->attr_bitmask
;
2997 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
2998 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
2999 data
->res
.fattr
= &data
->fattr
;
3000 data
->res
.server
= server
;
3001 nfs_fattr_init(data
->res
.fattr
);
3002 data
->timestamp
= jiffies
;
3003 data
->rpc_status
= 0;
3005 task_setup_data
.callback_data
= data
;
3006 msg
.rpc_argp
= &data
->args
,
3007 msg
.rpc_resp
= &data
->res
,
3008 task
= rpc_run_task(&task_setup_data
);
3010 return PTR_ERR(task
);
3013 status
= nfs4_wait_for_completion_rpc_task(task
);
3016 status
= data
->rpc_status
;
3019 nfs_refresh_inode(inode
, &data
->fattr
);
3025 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3027 struct nfs_server
*server
= NFS_SERVER(inode
);
3028 struct nfs4_exception exception
= { };
3031 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3033 case -NFS4ERR_STALE_STATEID
:
3034 case -NFS4ERR_EXPIRED
:
3038 err
= nfs4_handle_exception(server
, err
, &exception
);
3039 } while (exception
.retry
);
3043 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3044 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3047 * sleep, with exponential backoff, and retry the LOCK operation.
3049 static unsigned long
3050 nfs4_set_lock_task_retry(unsigned long timeout
)
3052 schedule_timeout_killable(timeout
);
3054 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3055 return NFS4_LOCK_MAXTIMEOUT
;
3059 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3061 struct inode
*inode
= state
->inode
;
3062 struct nfs_server
*server
= NFS_SERVER(inode
);
3063 struct nfs_client
*clp
= server
->nfs_client
;
3064 struct nfs_lockt_args arg
= {
3065 .fh
= NFS_FH(inode
),
3068 struct nfs_lockt_res res
= {
3071 struct rpc_message msg
= {
3072 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3075 .rpc_cred
= state
->owner
->so_cred
,
3077 struct nfs4_lock_state
*lsp
;
3080 down_read(&clp
->cl_sem
);
3081 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3082 status
= nfs4_set_lock_state(state
, request
);
3085 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3086 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3087 status
= rpc_call_sync(server
->client
, &msg
, 0);
3090 request
->fl_type
= F_UNLCK
;
3092 case -NFS4ERR_DENIED
:
3095 request
->fl_ops
->fl_release_private(request
);
3097 up_read(&clp
->cl_sem
);
3101 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3103 struct nfs4_exception exception
= { };
3107 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3108 _nfs4_proc_getlk(state
, cmd
, request
),
3110 } while (exception
.retry
);
3114 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3117 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3119 res
= posix_lock_file_wait(file
, fl
);
3122 res
= flock_lock_file_wait(file
, fl
);
3130 struct nfs4_unlockdata
{
3131 struct nfs_locku_args arg
;
3132 struct nfs_locku_res res
;
3133 struct nfs4_lock_state
*lsp
;
3134 struct nfs_open_context
*ctx
;
3135 struct file_lock fl
;
3136 const struct nfs_server
*server
;
3137 unsigned long timestamp
;
3140 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3141 struct nfs_open_context
*ctx
,
3142 struct nfs4_lock_state
*lsp
,
3143 struct nfs_seqid
*seqid
)
3145 struct nfs4_unlockdata
*p
;
3146 struct inode
*inode
= lsp
->ls_state
->inode
;
3148 p
= kmalloc(sizeof(*p
), GFP_KERNEL
);
3151 p
->arg
.fh
= NFS_FH(inode
);
3153 p
->arg
.seqid
= seqid
;
3154 p
->res
.seqid
= seqid
;
3155 p
->arg
.stateid
= &lsp
->ls_stateid
;
3157 atomic_inc(&lsp
->ls_count
);
3158 /* Ensure we don't close file until we're done freeing locks! */
3159 p
->ctx
= get_nfs_open_context(ctx
);
3160 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3161 p
->server
= NFS_SERVER(inode
);
3165 static void nfs4_locku_release_calldata(void *data
)
3167 struct nfs4_unlockdata
*calldata
= data
;
3168 nfs_free_seqid(calldata
->arg
.seqid
);
3169 nfs4_put_lock_state(calldata
->lsp
);
3170 put_nfs_open_context(calldata
->ctx
);
3174 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3176 struct nfs4_unlockdata
*calldata
= data
;
3178 if (RPC_ASSASSINATED(task
))
3180 switch (task
->tk_status
) {
3182 memcpy(calldata
->lsp
->ls_stateid
.data
,
3183 calldata
->res
.stateid
.data
,
3184 sizeof(calldata
->lsp
->ls_stateid
.data
));
3185 renew_lease(calldata
->server
, calldata
->timestamp
);
3187 case -NFS4ERR_STALE_STATEID
:
3188 case -NFS4ERR_EXPIRED
:
3191 if (nfs4_async_handle_error(task
, calldata
->server
) == -EAGAIN
)
3192 rpc_restart_call(task
);
3196 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3198 struct nfs4_unlockdata
*calldata
= data
;
3200 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3202 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3203 /* Note: exit _without_ running nfs4_locku_done */
3204 task
->tk_action
= NULL
;
3207 calldata
->timestamp
= jiffies
;
3208 rpc_call_start(task
);
3211 static const struct rpc_call_ops nfs4_locku_ops
= {
3212 .rpc_call_prepare
= nfs4_locku_prepare
,
3213 .rpc_call_done
= nfs4_locku_done
,
3214 .rpc_release
= nfs4_locku_release_calldata
,
3217 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3218 struct nfs_open_context
*ctx
,
3219 struct nfs4_lock_state
*lsp
,
3220 struct nfs_seqid
*seqid
)
3222 struct nfs4_unlockdata
*data
;
3223 struct rpc_message msg
= {
3224 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3225 .rpc_cred
= ctx
->cred
,
3227 struct rpc_task_setup task_setup_data
= {
3228 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
3229 .rpc_message
= &msg
,
3230 .callback_ops
= &nfs4_locku_ops
,
3231 .workqueue
= nfsiod_workqueue
,
3232 .flags
= RPC_TASK_ASYNC
,
3235 /* Ensure this is an unlock - when canceling a lock, the
3236 * canceled lock is passed in, and it won't be an unlock.
3238 fl
->fl_type
= F_UNLCK
;
3240 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3242 nfs_free_seqid(seqid
);
3243 return ERR_PTR(-ENOMEM
);
3246 msg
.rpc_argp
= &data
->arg
,
3247 msg
.rpc_resp
= &data
->res
,
3248 task_setup_data
.callback_data
= data
;
3249 return rpc_run_task(&task_setup_data
);
3252 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3254 struct nfs_seqid
*seqid
;
3255 struct nfs4_lock_state
*lsp
;
3256 struct rpc_task
*task
;
3258 unsigned char fl_flags
= request
->fl_flags
;
3260 status
= nfs4_set_lock_state(state
, request
);
3261 /* Unlock _before_ we do the RPC call */
3262 request
->fl_flags
|= FL_EXISTS
;
3263 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
)
3267 /* Is this a delegated lock? */
3268 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
3270 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3271 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3275 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
3276 status
= PTR_ERR(task
);
3279 status
= nfs4_wait_for_completion_rpc_task(task
);
3282 request
->fl_flags
= fl_flags
;
3286 struct nfs4_lockdata
{
3287 struct nfs_lock_args arg
;
3288 struct nfs_lock_res res
;
3289 struct nfs4_lock_state
*lsp
;
3290 struct nfs_open_context
*ctx
;
3291 struct file_lock fl
;
3292 unsigned long timestamp
;
3297 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
3298 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
)
3300 struct nfs4_lockdata
*p
;
3301 struct inode
*inode
= lsp
->ls_state
->inode
;
3302 struct nfs_server
*server
= NFS_SERVER(inode
);
3304 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3308 p
->arg
.fh
= NFS_FH(inode
);
3310 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
);
3311 if (p
->arg
.open_seqid
== NULL
)
3313 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3314 if (p
->arg
.lock_seqid
== NULL
)
3315 goto out_free_seqid
;
3316 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
3317 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
3318 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3319 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
3321 atomic_inc(&lsp
->ls_count
);
3322 p
->ctx
= get_nfs_open_context(ctx
);
3323 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3326 nfs_free_seqid(p
->arg
.open_seqid
);
3332 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
3334 struct nfs4_lockdata
*data
= calldata
;
3335 struct nfs4_state
*state
= data
->lsp
->ls_state
;
3337 dprintk("%s: begin!\n", __func__
);
3338 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
3340 /* Do we need to do an open_to_lock_owner? */
3341 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
3342 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
3344 data
->arg
.open_stateid
= &state
->stateid
;
3345 data
->arg
.new_lock_owner
= 1;
3346 data
->res
.open_seqid
= data
->arg
.open_seqid
;
3348 data
->arg
.new_lock_owner
= 0;
3349 data
->timestamp
= jiffies
;
3350 rpc_call_start(task
);
3351 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
3354 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
3356 struct nfs4_lockdata
*data
= calldata
;
3358 dprintk("%s: begin!\n", __func__
);
3360 data
->rpc_status
= task
->tk_status
;
3361 if (RPC_ASSASSINATED(task
))
3363 if (data
->arg
.new_lock_owner
!= 0) {
3364 if (data
->rpc_status
== 0)
3365 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
3369 if (data
->rpc_status
== 0) {
3370 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
3371 sizeof(data
->lsp
->ls_stateid
.data
));
3372 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
3373 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
3376 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
3379 static void nfs4_lock_release(void *calldata
)
3381 struct nfs4_lockdata
*data
= calldata
;
3383 dprintk("%s: begin!\n", __func__
);
3384 nfs_free_seqid(data
->arg
.open_seqid
);
3385 if (data
->cancelled
!= 0) {
3386 struct rpc_task
*task
;
3387 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
3388 data
->arg
.lock_seqid
);
3391 dprintk("%s: cancelling lock!\n", __func__
);
3393 nfs_free_seqid(data
->arg
.lock_seqid
);
3394 nfs4_put_lock_state(data
->lsp
);
3395 put_nfs_open_context(data
->ctx
);
3397 dprintk("%s: done!\n", __func__
);
3400 static const struct rpc_call_ops nfs4_lock_ops
= {
3401 .rpc_call_prepare
= nfs4_lock_prepare
,
3402 .rpc_call_done
= nfs4_lock_done
,
3403 .rpc_release
= nfs4_lock_release
,
3406 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int reclaim
)
3408 struct nfs4_lockdata
*data
;
3409 struct rpc_task
*task
;
3410 struct rpc_message msg
= {
3411 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
3412 .rpc_cred
= state
->owner
->so_cred
,
3414 struct rpc_task_setup task_setup_data
= {
3415 .rpc_client
= NFS_CLIENT(state
->inode
),
3416 .rpc_message
= &msg
,
3417 .callback_ops
= &nfs4_lock_ops
,
3418 .workqueue
= nfsiod_workqueue
,
3419 .flags
= RPC_TASK_ASYNC
,
3423 dprintk("%s: begin!\n", __func__
);
3424 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
3425 fl
->fl_u
.nfs4_fl
.owner
);
3429 data
->arg
.block
= 1;
3431 data
->arg
.reclaim
= 1;
3432 msg
.rpc_argp
= &data
->arg
,
3433 msg
.rpc_resp
= &data
->res
,
3434 task_setup_data
.callback_data
= data
;
3435 task
= rpc_run_task(&task_setup_data
);
3437 return PTR_ERR(task
);
3438 ret
= nfs4_wait_for_completion_rpc_task(task
);
3440 ret
= data
->rpc_status
;
3441 if (ret
== -NFS4ERR_DENIED
)
3444 data
->cancelled
= 1;
3446 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
3450 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
3452 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3453 struct nfs4_exception exception
= { };
3457 /* Cache the lock if possible... */
3458 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
3460 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
3461 if (err
!= -NFS4ERR_DELAY
)
3463 nfs4_handle_exception(server
, err
, &exception
);
3464 } while (exception
.retry
);
3468 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
3470 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3471 struct nfs4_exception exception
= { };
3474 err
= nfs4_set_lock_state(state
, request
);
3478 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
3480 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
3481 if (err
!= -NFS4ERR_DELAY
)
3483 nfs4_handle_exception(server
, err
, &exception
);
3484 } while (exception
.retry
);
3488 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3490 struct nfs_client
*clp
= state
->owner
->so_client
;
3491 unsigned char fl_flags
= request
->fl_flags
;
3494 /* Is this a delegated open? */
3495 status
= nfs4_set_lock_state(state
, request
);
3498 request
->fl_flags
|= FL_ACCESS
;
3499 status
= do_vfs_lock(request
->fl_file
, request
);
3502 down_read(&clp
->cl_sem
);
3503 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
3504 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3505 /* Yes: cache locks! */
3506 down_read(&nfsi
->rwsem
);
3507 /* ...but avoid races with delegation recall... */
3508 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
3509 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
3510 status
= do_vfs_lock(request
->fl_file
, request
);
3511 up_read(&nfsi
->rwsem
);
3514 up_read(&nfsi
->rwsem
);
3516 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
3519 /* Note: we always want to sleep here! */
3520 request
->fl_flags
= fl_flags
| FL_SLEEP
;
3521 if (do_vfs_lock(request
->fl_file
, request
) < 0)
3522 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
3524 up_read(&clp
->cl_sem
);
3526 request
->fl_flags
= fl_flags
;
3530 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3532 struct nfs4_exception exception
= { };
3536 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3537 _nfs4_proc_setlk(state
, cmd
, request
),
3539 } while (exception
.retry
);
3544 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
3546 struct nfs_open_context
*ctx
;
3547 struct nfs4_state
*state
;
3548 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
3551 /* verify open state */
3552 ctx
= nfs_file_open_context(filp
);
3555 if (request
->fl_start
< 0 || request
->fl_end
< 0)
3558 if (IS_GETLK(cmd
)) {
3560 return nfs4_proc_getlk(state
, F_GETLK
, request
);
3564 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
3567 if (request
->fl_type
== F_UNLCK
) {
3569 return nfs4_proc_unlck(state
, cmd
, request
);
3576 status
= nfs4_proc_setlk(state
, cmd
, request
);
3577 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
3579 timeout
= nfs4_set_lock_task_retry(timeout
);
3580 status
= -ERESTARTSYS
;
3583 } while(status
< 0);
3587 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
3589 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3590 struct nfs4_exception exception
= { };
3593 err
= nfs4_set_lock_state(state
, fl
);
3597 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, 0);
3598 if (err
!= -NFS4ERR_DELAY
)
3600 err
= nfs4_handle_exception(server
, err
, &exception
);
3601 } while (exception
.retry
);
3606 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3608 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
3609 size_t buflen
, int flags
)
3611 struct inode
*inode
= dentry
->d_inode
;
3613 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3616 return nfs4_proc_set_acl(inode
, buf
, buflen
);
3619 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
3620 * and that's what we'll do for e.g. user attributes that haven't been set.
3621 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3622 * attributes in kernel-managed attribute namespaces. */
3623 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
3626 struct inode
*inode
= dentry
->d_inode
;
3628 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3631 return nfs4_proc_get_acl(inode
, buf
, buflen
);
3634 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
3636 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
3638 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
3640 if (buf
&& buflen
< len
)
3643 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
3647 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
3648 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
3650 struct nfs_server
*server
= NFS_SERVER(dir
);
3652 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
3653 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
3655 struct nfs4_fs_locations_arg args
= {
3656 .dir_fh
= NFS_FH(dir
),
3661 struct rpc_message msg
= {
3662 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
3664 .rpc_resp
= fs_locations
,
3668 dprintk("%s: start\n", __func__
);
3669 nfs_fattr_init(&fs_locations
->fattr
);
3670 fs_locations
->server
= server
;
3671 fs_locations
->nlocations
= 0;
3672 status
= rpc_call_sync(server
->client
, &msg
, 0);
3673 dprintk("%s: returned status = %d\n", __func__
, status
);
3677 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops
= {
3678 .recover_open
= nfs4_open_reclaim
,
3679 .recover_lock
= nfs4_lock_reclaim
,
3682 struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops
= {
3683 .recover_open
= nfs4_open_expired
,
3684 .recover_lock
= nfs4_lock_expired
,
3687 static const struct inode_operations nfs4_file_inode_operations
= {
3688 .permission
= nfs_permission
,
3689 .getattr
= nfs_getattr
,
3690 .setattr
= nfs_setattr
,
3691 .getxattr
= nfs4_getxattr
,
3692 .setxattr
= nfs4_setxattr
,
3693 .listxattr
= nfs4_listxattr
,
3696 const struct nfs_rpc_ops nfs_v4_clientops
= {
3697 .version
= 4, /* protocol version */
3698 .dentry_ops
= &nfs4_dentry_operations
,
3699 .dir_inode_ops
= &nfs4_dir_inode_operations
,
3700 .file_inode_ops
= &nfs4_file_inode_operations
,
3701 .getroot
= nfs4_proc_get_root
,
3702 .getattr
= nfs4_proc_getattr
,
3703 .setattr
= nfs4_proc_setattr
,
3704 .lookupfh
= nfs4_proc_lookupfh
,
3705 .lookup
= nfs4_proc_lookup
,
3706 .access
= nfs4_proc_access
,
3707 .readlink
= nfs4_proc_readlink
,
3708 .create
= nfs4_proc_create
,
3709 .remove
= nfs4_proc_remove
,
3710 .unlink_setup
= nfs4_proc_unlink_setup
,
3711 .unlink_done
= nfs4_proc_unlink_done
,
3712 .rename
= nfs4_proc_rename
,
3713 .link
= nfs4_proc_link
,
3714 .symlink
= nfs4_proc_symlink
,
3715 .mkdir
= nfs4_proc_mkdir
,
3716 .rmdir
= nfs4_proc_remove
,
3717 .readdir
= nfs4_proc_readdir
,
3718 .mknod
= nfs4_proc_mknod
,
3719 .statfs
= nfs4_proc_statfs
,
3720 .fsinfo
= nfs4_proc_fsinfo
,
3721 .pathconf
= nfs4_proc_pathconf
,
3722 .set_capabilities
= nfs4_server_capabilities
,
3723 .decode_dirent
= nfs4_decode_dirent
,
3724 .read_setup
= nfs4_proc_read_setup
,
3725 .read_done
= nfs4_read_done
,
3726 .write_setup
= nfs4_proc_write_setup
,
3727 .write_done
= nfs4_write_done
,
3728 .commit_setup
= nfs4_proc_commit_setup
,
3729 .commit_done
= nfs4_commit_done
,
3730 .lock
= nfs4_proc_lock
,
3731 .clear_acl_cache
= nfs4_zap_acl_attr
,