4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/utsname.h>
40 #include <linux/delay.h>
41 #include <linux/errno.h>
42 #include <linux/string.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/nfs.h>
45 #include <linux/nfs4.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/nfs_page.h>
48 #include <linux/smp_lock.h>
49 #include <linux/namei.h>
50 #include <linux/mount.h>
53 #include "delegation.h"
55 #define NFSDBG_FACILITY NFSDBG_PROC
57 #define NFS4_POLL_RETRY_MIN (1*HZ)
58 #define NFS4_POLL_RETRY_MAX (15*HZ)
60 static int _nfs4_proc_open_confirm(struct rpc_clnt
*clnt
, const struct nfs_fh
*fh
, struct nfs4_state_owner
*sp
, nfs4_stateid
*stateid
, struct nfs_seqid
*seqid
);
61 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
62 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*);
63 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
);
64 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
);
65 extern u32
*nfs4_decode_dirent(u32
*p
, struct nfs_entry
*entry
, int plus
);
66 extern struct rpc_procinfo nfs4_procedures
[];
68 /* Prevent leaks of NFSv4 errors into userland */
69 int nfs4_map_errors(int err
)
72 dprintk("%s could not handle NFSv4 error %d\n",
80 * This is our standard bitmap for GETATTR requests.
82 const u32 nfs4_fattr_bitmap
[2] = {
87 | FATTR4_WORD0_FILEID
,
89 | FATTR4_WORD1_NUMLINKS
91 | FATTR4_WORD1_OWNER_GROUP
93 | FATTR4_WORD1_SPACE_USED
94 | FATTR4_WORD1_TIME_ACCESS
95 | FATTR4_WORD1_TIME_METADATA
96 | FATTR4_WORD1_TIME_MODIFY
99 const u32 nfs4_statfs_bitmap
[2] = {
100 FATTR4_WORD0_FILES_AVAIL
101 | FATTR4_WORD0_FILES_FREE
102 | FATTR4_WORD0_FILES_TOTAL
,
103 FATTR4_WORD1_SPACE_AVAIL
104 | FATTR4_WORD1_SPACE_FREE
105 | FATTR4_WORD1_SPACE_TOTAL
108 const u32 nfs4_pathconf_bitmap
[2] = {
110 | FATTR4_WORD0_MAXNAME
,
114 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
115 | FATTR4_WORD0_MAXREAD
116 | FATTR4_WORD0_MAXWRITE
117 | FATTR4_WORD0_LEASE_TIME
,
121 static void nfs4_setup_readdir(u64 cookie
, u32
*verifier
, struct dentry
*dentry
,
122 struct nfs4_readdir_arg
*readdir
)
126 BUG_ON(readdir
->count
< 80);
128 readdir
->cookie
= cookie
;
129 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
134 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
139 * NFSv4 servers do not return entries for '.' and '..'
140 * Therefore, we fake these entries here. We let '.'
141 * have cookie 0 and '..' have cookie 1. Note that
142 * when talking to the server, we always send cookie 0
145 start
= p
= (u32
*)kmap_atomic(*readdir
->pages
, KM_USER0
);
148 *p
++ = xdr_one
; /* next */
149 *p
++ = xdr_zero
; /* cookie, first word */
150 *p
++ = xdr_one
; /* cookie, second word */
151 *p
++ = xdr_one
; /* entry len */
152 memcpy(p
, ".\0\0\0", 4); /* entry */
154 *p
++ = xdr_one
; /* bitmap length */
155 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
156 *p
++ = htonl(8); /* attribute buffer length */
157 p
= xdr_encode_hyper(p
, dentry
->d_inode
->i_ino
);
160 *p
++ = xdr_one
; /* next */
161 *p
++ = xdr_zero
; /* cookie, first word */
162 *p
++ = xdr_two
; /* cookie, second word */
163 *p
++ = xdr_two
; /* entry len */
164 memcpy(p
, "..\0\0", 4); /* entry */
166 *p
++ = xdr_one
; /* bitmap length */
167 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
168 *p
++ = htonl(8); /* attribute buffer length */
169 p
= xdr_encode_hyper(p
, dentry
->d_parent
->d_inode
->i_ino
);
171 readdir
->pgbase
= (char *)p
- (char *)start
;
172 readdir
->count
-= readdir
->pgbase
;
173 kunmap_atomic(start
, KM_USER0
);
177 renew_lease(struct nfs_server
*server
, unsigned long timestamp
)
179 struct nfs4_client
*clp
= server
->nfs4_state
;
180 spin_lock(&clp
->cl_lock
);
181 if (time_before(clp
->cl_last_renewal
,timestamp
))
182 clp
->cl_last_renewal
= timestamp
;
183 spin_unlock(&clp
->cl_lock
);
186 static void update_changeattr(struct inode
*inode
, struct nfs4_change_info
*cinfo
)
188 struct nfs_inode
*nfsi
= NFS_I(inode
);
190 if (cinfo
->before
== nfsi
->change_attr
&& cinfo
->atomic
)
191 nfsi
->change_attr
= cinfo
->after
;
194 /* Helper for asynchronous RPC calls */
195 static int nfs4_call_async(struct rpc_clnt
*clnt
, rpc_action tk_begin
,
196 rpc_action tk_exit
, void *calldata
)
198 struct rpc_task
*task
;
200 if (!(task
= rpc_new_task(clnt
, tk_exit
, RPC_TASK_ASYNC
)))
203 task
->tk_calldata
= calldata
;
204 task
->tk_action
= tk_begin
;
209 static void update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, int open_flags
)
211 struct inode
*inode
= state
->inode
;
213 open_flags
&= (FMODE_READ
|FMODE_WRITE
);
214 /* Protect against nfs4_find_state() */
215 spin_lock(&inode
->i_lock
);
216 state
->state
|= open_flags
;
217 /* NB! List reordering - see the reclaim code for why. */
218 if ((open_flags
& FMODE_WRITE
) && 0 == state
->nwriters
++)
219 list_move(&state
->open_states
, &state
->owner
->so_states
);
220 if (open_flags
& FMODE_READ
)
222 memcpy(&state
->stateid
, stateid
, sizeof(state
->stateid
));
223 spin_unlock(&inode
->i_lock
);
228 * reclaim state on the server after a reboot.
230 static int _nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
232 struct inode
*inode
= state
->inode
;
233 struct nfs_server
*server
= NFS_SERVER(inode
);
234 struct nfs_delegation
*delegation
= NFS_I(inode
)->delegation
;
235 struct nfs_openargs o_arg
= {
238 .open_flags
= state
->state
,
239 .clientid
= server
->nfs4_state
->cl_clientid
,
240 .claim
= NFS4_OPEN_CLAIM_PREVIOUS
,
241 .bitmask
= server
->attr_bitmask
,
243 struct nfs_openres o_res
= {
244 .server
= server
, /* Grrr */
246 struct rpc_message msg
= {
247 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
],
250 .rpc_cred
= sp
->so_cred
,
254 if (delegation
!= NULL
) {
255 if (!(delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
)) {
256 memcpy(&state
->stateid
, &delegation
->stateid
,
257 sizeof(state
->stateid
));
258 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
261 o_arg
.u
.delegation_type
= delegation
->type
;
263 o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
264 if (o_arg
.seqid
== NULL
)
266 status
= rpc_call_sync(server
->client
, &msg
, RPC_TASK_NOINTR
);
267 /* Confirm the sequence as being established */
268 nfs_confirm_seqid(&sp
->so_seqid
, status
);
269 nfs_increment_open_seqid(status
, o_arg
.seqid
);
271 memcpy(&state
->stateid
, &o_res
.stateid
, sizeof(state
->stateid
));
272 if (o_res
.delegation_type
!= 0) {
273 nfs_inode_reclaim_delegation(inode
, sp
->so_cred
, &o_res
);
274 /* Did the server issue an immediate delegation recall? */
276 nfs_async_inode_return_delegation(inode
, &o_res
.stateid
);
279 nfs_free_seqid(o_arg
.seqid
);
280 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
281 /* Ensure we update the inode attributes */
286 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
288 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
289 struct nfs4_exception exception
= { };
292 err
= _nfs4_open_reclaim(sp
, state
);
293 if (err
!= -NFS4ERR_DELAY
)
295 nfs4_handle_exception(server
, err
, &exception
);
296 } while (exception
.retry
);
300 static int _nfs4_open_delegation_recall(struct dentry
*dentry
, struct nfs4_state
*state
)
302 struct nfs4_state_owner
*sp
= state
->owner
;
303 struct inode
*inode
= dentry
->d_inode
;
304 struct nfs_server
*server
= NFS_SERVER(inode
);
305 struct dentry
*parent
= dget_parent(dentry
);
306 struct nfs_openargs arg
= {
307 .fh
= NFS_FH(parent
->d_inode
),
308 .clientid
= server
->nfs4_state
->cl_clientid
,
309 .name
= &dentry
->d_name
,
312 .bitmask
= server
->attr_bitmask
,
313 .claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
,
315 struct nfs_openres res
= {
318 struct rpc_message msg
= {
319 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
],
322 .rpc_cred
= sp
->so_cred
,
326 if (!test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
328 if (state
->state
== 0)
330 arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
332 if (arg
.seqid
== NULL
)
334 arg
.open_flags
= state
->state
;
335 memcpy(arg
.u
.delegation
.data
, state
->stateid
.data
, sizeof(arg
.u
.delegation
.data
));
336 status
= rpc_call_sync(server
->client
, &msg
, RPC_TASK_NOINTR
);
337 nfs_increment_open_seqid(status
, arg
.seqid
);
340 if(res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
341 status
= _nfs4_proc_open_confirm(server
->client
, NFS_FH(inode
),
342 sp
, &res
.stateid
, arg
.seqid
);
346 nfs_confirm_seqid(&sp
->so_seqid
, 0);
348 memcpy(state
->stateid
.data
, res
.stateid
.data
,
349 sizeof(state
->stateid
.data
));
350 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
353 nfs_free_seqid(arg
.seqid
);
359 int nfs4_open_delegation_recall(struct dentry
*dentry
, struct nfs4_state
*state
)
361 struct nfs4_exception exception
= { };
362 struct nfs_server
*server
= NFS_SERVER(dentry
->d_inode
);
365 err
= _nfs4_open_delegation_recall(dentry
, state
);
369 case -NFS4ERR_STALE_CLIENTID
:
370 case -NFS4ERR_STALE_STATEID
:
371 case -NFS4ERR_EXPIRED
:
372 /* Don't recall a delegation if it was lost */
373 nfs4_schedule_state_recovery(server
->nfs4_state
);
376 err
= nfs4_handle_exception(server
, err
, &exception
);
377 } while (exception
.retry
);
381 static int _nfs4_proc_open_confirm(struct rpc_clnt
*clnt
, const struct nfs_fh
*fh
, struct nfs4_state_owner
*sp
, nfs4_stateid
*stateid
, struct nfs_seqid
*seqid
)
383 struct nfs_open_confirmargs arg
= {
388 struct nfs_open_confirmres res
;
389 struct rpc_message msg
= {
390 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
393 .rpc_cred
= sp
->so_cred
,
397 status
= rpc_call_sync(clnt
, &msg
, RPC_TASK_NOINTR
);
398 /* Confirm the sequence as being established */
399 nfs_confirm_seqid(&sp
->so_seqid
, status
);
400 nfs_increment_open_seqid(status
, seqid
);
402 memcpy(stateid
, &res
.stateid
, sizeof(*stateid
));
406 static int _nfs4_proc_open(struct inode
*dir
, struct nfs4_state_owner
*sp
, struct nfs_openargs
*o_arg
, struct nfs_openres
*o_res
)
408 struct nfs_server
*server
= NFS_SERVER(dir
);
409 struct rpc_message msg
= {
410 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
413 .rpc_cred
= sp
->so_cred
,
417 /* Update sequence id. The caller must serialize! */
418 o_arg
->id
= sp
->so_id
;
419 o_arg
->clientid
= sp
->so_client
->cl_clientid
;
421 status
= rpc_call_sync(server
->client
, &msg
, RPC_TASK_NOINTR
);
423 /* OPEN on anything except a regular file is disallowed in NFSv4 */
424 switch (o_res
->f_attr
->mode
& S_IFMT
) {
438 nfs_increment_open_seqid(status
, o_arg
->seqid
);
441 update_changeattr(dir
, &o_res
->cinfo
);
442 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
443 status
= _nfs4_proc_open_confirm(server
->client
, &o_res
->fh
,
444 sp
, &o_res
->stateid
, o_arg
->seqid
);
448 nfs_confirm_seqid(&sp
->so_seqid
, 0);
449 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
450 status
= server
->rpc_ops
->getattr(server
, &o_res
->fh
, o_res
->f_attr
);
455 static int _nfs4_do_access(struct inode
*inode
, struct rpc_cred
*cred
, int openflags
)
457 struct nfs_access_entry cache
;
461 if (openflags
& FMODE_READ
)
463 if (openflags
& FMODE_WRITE
)
465 status
= nfs_access_get_cached(inode
, cred
, &cache
);
469 /* Be clever: ask server to check for all possible rights */
470 cache
.mask
= MAY_EXEC
| MAY_WRITE
| MAY_READ
;
472 cache
.jiffies
= jiffies
;
473 status
= _nfs4_proc_access(inode
, &cache
);
476 nfs_access_add_cache(inode
, &cache
);
478 if ((cache
.mask
& mask
) == mask
)
485 * reclaim state on the server after a network partition.
486 * Assumes caller holds the appropriate lock
488 static int _nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
, struct dentry
*dentry
)
490 struct dentry
*parent
= dget_parent(dentry
);
491 struct inode
*dir
= parent
->d_inode
;
492 struct inode
*inode
= state
->inode
;
493 struct nfs_server
*server
= NFS_SERVER(dir
);
494 struct nfs_delegation
*delegation
= NFS_I(inode
)->delegation
;
495 struct nfs_fattr f_attr
= {
498 struct nfs_openargs o_arg
= {
500 .open_flags
= state
->state
,
501 .name
= &dentry
->d_name
,
502 .bitmask
= server
->attr_bitmask
,
503 .claim
= NFS4_OPEN_CLAIM_NULL
,
505 struct nfs_openres o_res
= {
511 if (delegation
!= NULL
&& !(delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
)) {
512 status
= _nfs4_do_access(inode
, sp
->so_cred
, state
->state
);
515 memcpy(&state
->stateid
, &delegation
->stateid
, sizeof(state
->stateid
));
516 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
519 o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
521 if (o_arg
.seqid
== NULL
)
523 status
= _nfs4_proc_open(dir
, sp
, &o_arg
, &o_res
);
526 /* Check if files differ */
527 if ((f_attr
.mode
& S_IFMT
) != (inode
->i_mode
& S_IFMT
))
529 /* Has the file handle changed? */
530 if (nfs_compare_fh(&o_res
.fh
, NFS_FH(inode
)) != 0) {
531 /* Verify if the change attributes are the same */
532 if (f_attr
.change_attr
!= NFS_I(inode
)->change_attr
)
534 if (nfs_size_to_loff_t(f_attr
.size
) != inode
->i_size
)
536 /* Lets just pretend that this is the same file */
537 nfs_copy_fh(NFS_FH(inode
), &o_res
.fh
);
538 NFS_I(inode
)->fileid
= f_attr
.fileid
;
540 memcpy(&state
->stateid
, &o_res
.stateid
, sizeof(state
->stateid
));
541 if (o_res
.delegation_type
!= 0) {
542 if (!(delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
))
543 nfs_inode_set_delegation(inode
, sp
->so_cred
, &o_res
);
545 nfs_inode_reclaim_delegation(inode
, sp
->so_cred
, &o_res
);
548 nfs_free_seqid(o_arg
.seqid
);
549 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
555 /* Invalidate the state owner so we don't ever use it again */
556 nfs4_drop_state_owner(sp
);
558 /* Should we be trying to close that stateid? */
562 static inline int nfs4_do_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
, struct dentry
*dentry
)
564 struct nfs_server
*server
= NFS_SERVER(dentry
->d_inode
);
565 struct nfs4_exception exception
= { };
569 err
= _nfs4_open_expired(sp
, state
, dentry
);
570 if (err
== -NFS4ERR_DELAY
)
571 nfs4_handle_exception(server
, err
, &exception
);
572 } while (exception
.retry
);
576 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
578 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
579 struct nfs_open_context
*ctx
;
582 spin_lock(&state
->inode
->i_lock
);
583 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
584 if (ctx
->state
!= state
)
586 get_nfs_open_context(ctx
);
587 spin_unlock(&state
->inode
->i_lock
);
588 status
= nfs4_do_open_expired(sp
, state
, ctx
->dentry
);
589 put_nfs_open_context(ctx
);
592 spin_unlock(&state
->inode
->i_lock
);
597 * Returns an nfs4_state + an extra reference to the inode
599 static int _nfs4_open_delegated(struct inode
*inode
, int flags
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
601 struct nfs_delegation
*delegation
;
602 struct nfs_server
*server
= NFS_SERVER(inode
);
603 struct nfs4_client
*clp
= server
->nfs4_state
;
604 struct nfs_inode
*nfsi
= NFS_I(inode
);
605 struct nfs4_state_owner
*sp
= NULL
;
606 struct nfs4_state
*state
= NULL
;
607 int open_flags
= flags
& (FMODE_READ
|FMODE_WRITE
);
610 /* Protect against reboot recovery - NOTE ORDER! */
611 down_read(&clp
->cl_sem
);
612 /* Protect against delegation recall */
613 down_read(&nfsi
->rwsem
);
614 delegation
= NFS_I(inode
)->delegation
;
616 if (delegation
== NULL
|| (delegation
->type
& open_flags
) != open_flags
)
619 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
620 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__
);
623 state
= nfs4_get_open_state(inode
, sp
);
628 if ((state
->state
& open_flags
) == open_flags
) {
629 spin_lock(&inode
->i_lock
);
630 if (open_flags
& FMODE_READ
)
632 if (open_flags
& FMODE_WRITE
)
634 spin_unlock(&inode
->i_lock
);
636 } else if (state
->state
!= 0)
640 err
= _nfs4_do_access(inode
, cred
, open_flags
);
644 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
645 update_open_stateid(state
, &delegation
->stateid
, open_flags
);
647 nfs4_put_state_owner(sp
);
648 up_read(&nfsi
->rwsem
);
649 up_read(&clp
->cl_sem
);
656 nfs4_put_open_state(state
);
657 nfs4_put_state_owner(sp
);
659 up_read(&nfsi
->rwsem
);
660 up_read(&clp
->cl_sem
);
664 static struct nfs4_state
*nfs4_open_delegated(struct inode
*inode
, int flags
, struct rpc_cred
*cred
)
666 struct nfs4_exception exception
= { };
667 struct nfs4_state
*res
;
671 err
= _nfs4_open_delegated(inode
, flags
, cred
, &res
);
674 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode
),
676 } while (exception
.retry
);
681 * Returns an nfs4_state + an referenced inode
683 static int _nfs4_do_open(struct inode
*dir
, struct dentry
*dentry
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
685 struct nfs4_state_owner
*sp
;
686 struct nfs4_state
*state
= NULL
;
687 struct nfs_server
*server
= NFS_SERVER(dir
);
688 struct nfs4_client
*clp
= server
->nfs4_state
;
689 struct inode
*inode
= NULL
;
691 struct nfs_fattr f_attr
= {
694 struct nfs_openargs o_arg
= {
697 .name
= &dentry
->d_name
,
699 .bitmask
= server
->attr_bitmask
,
700 .claim
= NFS4_OPEN_CLAIM_NULL
,
702 struct nfs_openres o_res
= {
707 /* Protect against reboot recovery conflicts */
708 down_read(&clp
->cl_sem
);
710 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
711 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
714 if (flags
& O_EXCL
) {
715 u32
*p
= (u32
*) o_arg
.u
.verifier
.data
;
719 o_arg
.u
.attrs
= sattr
;
720 /* Serialization for the sequence id */
722 o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
723 if (o_arg
.seqid
== NULL
)
725 status
= _nfs4_proc_open(dir
, sp
, &o_arg
, &o_res
);
730 inode
= nfs_fhget(dir
->i_sb
, &o_res
.fh
, &f_attr
);
733 state
= nfs4_get_open_state(inode
, sp
);
736 update_open_stateid(state
, &o_res
.stateid
, flags
);
737 if (o_res
.delegation_type
!= 0)
738 nfs_inode_set_delegation(inode
, cred
, &o_res
);
739 nfs_free_seqid(o_arg
.seqid
);
740 nfs4_put_state_owner(sp
);
741 up_read(&clp
->cl_sem
);
747 nfs4_put_open_state(state
);
748 nfs_free_seqid(o_arg
.seqid
);
749 nfs4_put_state_owner(sp
);
751 /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
752 up_read(&clp
->cl_sem
);
760 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct dentry
*dentry
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
762 struct nfs4_exception exception
= { };
763 struct nfs4_state
*res
;
767 status
= _nfs4_do_open(dir
, dentry
, flags
, sattr
, cred
, &res
);
770 /* NOTE: BAD_SEQID means the server and client disagree about the
771 * book-keeping w.r.t. state-changing operations
772 * (OPEN/CLOSE/LOCK/LOCKU...)
773 * It is actually a sign of a bug on the client or on the server.
775 * If we receive a BAD_SEQID error in the particular case of
776 * doing an OPEN, we assume that nfs_increment_open_seqid() will
777 * have unhashed the old state_owner for us, and that we can
778 * therefore safely retry using a new one. We should still warn
781 if (status
== -NFS4ERR_BAD_SEQID
) {
782 printk(KERN_WARNING
"NFS: v4 server returned a bad sequence-id error!\n");
786 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
787 status
, &exception
));
788 } while (exception
.retry
);
792 static int _nfs4_do_setattr(struct nfs_server
*server
, struct nfs_fattr
*fattr
,
793 struct nfs_fh
*fhandle
, struct iattr
*sattr
,
794 struct nfs4_state
*state
)
796 struct nfs_setattrargs arg
= {
800 .bitmask
= server
->attr_bitmask
,
802 struct nfs_setattrres res
= {
806 struct rpc_message msg
= {
807 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
816 msg
.rpc_cred
= state
->owner
->so_cred
;
817 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
819 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
821 status
= rpc_call_sync(server
->client
, &msg
, 0);
825 static int nfs4_do_setattr(struct nfs_server
*server
, struct nfs_fattr
*fattr
,
826 struct nfs_fh
*fhandle
, struct iattr
*sattr
,
827 struct nfs4_state
*state
)
829 struct nfs4_exception exception
= { };
832 err
= nfs4_handle_exception(server
,
833 _nfs4_do_setattr(server
, fattr
, fhandle
, sattr
,
836 } while (exception
.retry
);
840 struct nfs4_closedata
{
842 struct nfs4_state
*state
;
843 struct nfs_closeargs arg
;
844 struct nfs_closeres res
;
847 static void nfs4_free_closedata(struct nfs4_closedata
*calldata
)
849 struct nfs4_state
*state
= calldata
->state
;
850 struct nfs4_state_owner
*sp
= state
->owner
;
852 nfs4_put_open_state(calldata
->state
);
853 nfs_free_seqid(calldata
->arg
.seqid
);
854 nfs4_put_state_owner(sp
);
858 static void nfs4_close_done(struct rpc_task
*task
)
860 struct nfs4_closedata
*calldata
= (struct nfs4_closedata
*)task
->tk_calldata
;
861 struct nfs4_state
*state
= calldata
->state
;
862 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
864 /* hmm. we are done with the inode, and in the process of freeing
865 * the state_owner. we keep this around to process errors
867 nfs_increment_open_seqid(task
->tk_status
, calldata
->arg
.seqid
);
868 switch (task
->tk_status
) {
870 memcpy(&state
->stateid
, &calldata
->res
.stateid
,
871 sizeof(state
->stateid
));
873 case -NFS4ERR_STALE_STATEID
:
874 case -NFS4ERR_EXPIRED
:
875 state
->state
= calldata
->arg
.open_flags
;
876 nfs4_schedule_state_recovery(server
->nfs4_state
);
879 if (nfs4_async_handle_error(task
, server
) == -EAGAIN
) {
880 rpc_restart_call(task
);
884 state
->state
= calldata
->arg
.open_flags
;
885 nfs4_free_closedata(calldata
);
888 static void nfs4_close_begin(struct rpc_task
*task
)
890 struct nfs4_closedata
*calldata
= (struct nfs4_closedata
*)task
->tk_calldata
;
891 struct nfs4_state
*state
= calldata
->state
;
892 struct rpc_message msg
= {
893 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
894 .rpc_argp
= &calldata
->arg
,
895 .rpc_resp
= &calldata
->res
,
896 .rpc_cred
= state
->owner
->so_cred
,
901 status
= nfs_wait_on_sequence(calldata
->arg
.seqid
, task
);
904 /* Don't reorder reads */
906 /* Recalculate the new open mode in case someone reopened the file
907 * while we were waiting in line to be scheduled.
909 if (state
->nreaders
!= 0)
911 if (state
->nwriters
!= 0)
913 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
915 if (mode
== state
->state
) {
916 nfs4_free_closedata(calldata
);
917 task
->tk_exit
= NULL
;
922 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
923 calldata
->arg
.open_flags
= mode
;
924 rpc_call_setup(task
, &msg
, 0);
928 * It is possible for data to be read/written from a mem-mapped file
929 * after the sys_close call (which hits the vfs layer as a flush).
930 * This means that we can't safely call nfsv4 close on a file until
931 * the inode is cleared. This in turn means that we are not good
932 * NFSv4 citizens - we do not indicate to the server to update the file's
933 * share state even when we are done with one of the three share
934 * stateid's in the inode.
936 * NOTE: Caller must be holding the sp->so_owner semaphore!
938 int nfs4_do_close(struct inode
*inode
, struct nfs4_state
*state
, mode_t mode
)
940 struct nfs4_closedata
*calldata
;
941 int status
= -ENOMEM
;
943 calldata
= kmalloc(sizeof(*calldata
), GFP_KERNEL
);
944 if (calldata
== NULL
)
946 calldata
->inode
= inode
;
947 calldata
->state
= state
;
948 calldata
->arg
.fh
= NFS_FH(inode
);
949 calldata
->arg
.stateid
= &state
->stateid
;
950 /* Serialization for the sequence id */
951 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
952 if (calldata
->arg
.seqid
== NULL
)
953 goto out_free_calldata
;
955 status
= nfs4_call_async(NFS_SERVER(inode
)->client
, nfs4_close_begin
,
956 nfs4_close_done
, calldata
);
960 nfs_free_seqid(calldata
->arg
.seqid
);
967 static void nfs4_intent_set_file(struct nameidata
*nd
, struct dentry
*dentry
, struct nfs4_state
*state
)
971 filp
= lookup_instantiate_filp(nd
, dentry
, NULL
);
973 struct nfs_open_context
*ctx
;
974 ctx
= (struct nfs_open_context
*)filp
->private_data
;
977 nfs4_close_state(state
, nd
->intent
.open
.flags
);
981 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
984 struct rpc_cred
*cred
;
985 struct nfs4_state
*state
;
988 if (nd
->flags
& LOOKUP_CREATE
) {
989 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
990 attr
.ia_valid
= ATTR_MODE
;
991 if (!IS_POSIXACL(dir
))
992 attr
.ia_mode
&= ~current
->fs
->umask
;
995 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
998 cred
= rpcauth_lookupcred(NFS_SERVER(dir
)->client
->cl_auth
, 0);
1000 return (struct dentry
*)cred
;
1001 state
= nfs4_do_open(dir
, dentry
, nd
->intent
.open
.flags
, &attr
, cred
);
1003 if (IS_ERR(state
)) {
1004 if (PTR_ERR(state
) == -ENOENT
)
1005 d_add(dentry
, NULL
);
1006 return (struct dentry
*)state
;
1008 res
= d_add_unique(dentry
, state
->inode
);
1011 nfs4_intent_set_file(nd
, dentry
, state
);
1016 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1018 struct rpc_cred
*cred
;
1019 struct nfs4_state
*state
;
1020 struct inode
*inode
;
1022 cred
= rpcauth_lookupcred(NFS_SERVER(dir
)->client
->cl_auth
, 0);
1024 return PTR_ERR(cred
);
1025 state
= nfs4_open_delegated(dentry
->d_inode
, openflags
, cred
);
1027 state
= nfs4_do_open(dir
, dentry
, openflags
, NULL
, cred
);
1029 if (IS_ERR(state
)) {
1030 switch (PTR_ERR(state
)) {
1036 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1039 if (dentry
->d_inode
== NULL
)
1044 inode
= state
->inode
;
1046 if (inode
== dentry
->d_inode
) {
1047 nfs4_intent_set_file(nd
, dentry
, state
);
1050 nfs4_close_state(state
, openflags
);
1057 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1059 struct nfs4_server_caps_res res
= {};
1060 struct rpc_message msg
= {
1061 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
1062 .rpc_argp
= fhandle
,
1067 status
= rpc_call_sync(server
->client
, &msg
, 0);
1069 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
1070 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
1071 server
->caps
|= NFS_CAP_ACLS
;
1072 if (res
.has_links
!= 0)
1073 server
->caps
|= NFS_CAP_HARDLINKS
;
1074 if (res
.has_symlinks
!= 0)
1075 server
->caps
|= NFS_CAP_SYMLINKS
;
1076 server
->acl_bitmask
= res
.acl_bitmask
;
1081 static int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1083 struct nfs4_exception exception
= { };
1086 err
= nfs4_handle_exception(server
,
1087 _nfs4_server_capabilities(server
, fhandle
),
1089 } while (exception
.retry
);
1093 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1094 struct nfs_fsinfo
*info
)
1096 struct nfs_fattr
* fattr
= info
->fattr
;
1097 struct nfs4_lookup_root_arg args
= {
1098 .bitmask
= nfs4_fattr_bitmap
,
1100 struct nfs4_lookup_res res
= {
1105 struct rpc_message msg
= {
1106 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
1111 return rpc_call_sync(server
->client
, &msg
, 0);
1114 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1115 struct nfs_fsinfo
*info
)
1117 struct nfs4_exception exception
= { };
1120 err
= nfs4_handle_exception(server
,
1121 _nfs4_lookup_root(server
, fhandle
, info
),
1123 } while (exception
.retry
);
1127 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1128 struct nfs_fsinfo
*info
)
1130 struct nfs_fattr
* fattr
= info
->fattr
;
1133 struct nfs4_lookup_arg args
= {
1136 .bitmask
= nfs4_fattr_bitmap
,
1138 struct nfs4_lookup_res res
= {
1143 struct rpc_message msg
= {
1144 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
1151 * Now we do a separate LOOKUP for each component of the mount path.
1152 * The LOOKUPs are done separately so that we can conveniently
1153 * catch an ERR_WRONGSEC if it occurs along the way...
1155 status
= nfs4_lookup_root(server
, fhandle
, info
);
1159 p
= server
->mnt_path
;
1161 struct nfs4_exception exception
= { };
1168 while (*p
&& (*p
!= '/'))
1174 status
= nfs4_handle_exception(server
,
1175 rpc_call_sync(server
->client
, &msg
, 0),
1177 } while (exception
.retry
);
1180 if (status
== -ENOENT
) {
1181 printk(KERN_NOTICE
"NFS: mount path %s does not exist!\n", server
->mnt_path
);
1182 printk(KERN_NOTICE
"NFS: suggestion: try mounting '/' instead.\n");
1187 status
= nfs4_server_capabilities(server
, fhandle
);
1189 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
1194 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1196 struct nfs4_getattr_arg args
= {
1198 .bitmask
= server
->attr_bitmask
,
1200 struct nfs4_getattr_res res
= {
1204 struct rpc_message msg
= {
1205 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
1211 return rpc_call_sync(server
->client
, &msg
, 0);
1214 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1216 struct nfs4_exception exception
= { };
1219 err
= nfs4_handle_exception(server
,
1220 _nfs4_proc_getattr(server
, fhandle
, fattr
),
1222 } while (exception
.retry
);
1227 * The file is not closed if it is opened due to the a request to change
1228 * the size of the file. The open call will not be needed once the
1229 * VFS layer lookup-intents are implemented.
1231 * Close is called when the inode is destroyed.
1232 * If we haven't opened the file for O_WRONLY, we
1233 * need to in the size_change case to obtain a stateid.
1236 * Because OPEN is always done by name in nfsv4, it is
1237 * possible that we opened a different file by the same
1238 * name. We can recognize this race condition, but we
1239 * can't do anything about it besides returning an error.
1241 * This will be fixed with VFS changes (lookup-intent).
1244 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
1245 struct iattr
*sattr
)
1247 struct rpc_cred
*cred
;
1248 struct inode
*inode
= dentry
->d_inode
;
1249 struct nfs4_state
*state
;
1254 cred
= rpcauth_lookupcred(NFS_SERVER(inode
)->client
->cl_auth
, 0);
1256 return PTR_ERR(cred
);
1257 /* Search for an existing WRITE delegation first */
1258 state
= nfs4_open_delegated(inode
, FMODE_WRITE
, cred
);
1259 if (!IS_ERR(state
)) {
1260 /* NB: nfs4_open_delegated() bumps the inode->i_count */
1263 /* Search for an existing open(O_WRITE) stateid */
1264 state
= nfs4_find_state(inode
, cred
, FMODE_WRITE
);
1267 status
= nfs4_do_setattr(NFS_SERVER(inode
), fattr
,
1268 NFS_FH(inode
), sattr
, state
);
1270 nfs_setattr_update_inode(inode
, sattr
);
1272 nfs4_close_state(state
, FMODE_WRITE
);
1277 static int _nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
1278 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1281 struct nfs_server
*server
= NFS_SERVER(dir
);
1282 struct nfs4_lookup_arg args
= {
1283 .bitmask
= server
->attr_bitmask
,
1284 .dir_fh
= NFS_FH(dir
),
1287 struct nfs4_lookup_res res
= {
1292 struct rpc_message msg
= {
1293 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
1300 dprintk("NFS call lookup %s\n", name
->name
);
1301 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1302 dprintk("NFS reply lookup: %d\n", status
);
1306 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1308 struct nfs4_exception exception
= { };
1311 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1312 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
1314 } while (exception
.retry
);
1318 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1320 struct nfs4_accessargs args
= {
1321 .fh
= NFS_FH(inode
),
1323 struct nfs4_accessres res
= { 0 };
1324 struct rpc_message msg
= {
1325 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
1328 .rpc_cred
= entry
->cred
,
1330 int mode
= entry
->mask
;
1334 * Determine which access bits we want to ask for...
1336 if (mode
& MAY_READ
)
1337 args
.access
|= NFS4_ACCESS_READ
;
1338 if (S_ISDIR(inode
->i_mode
)) {
1339 if (mode
& MAY_WRITE
)
1340 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
1341 if (mode
& MAY_EXEC
)
1342 args
.access
|= NFS4_ACCESS_LOOKUP
;
1344 if (mode
& MAY_WRITE
)
1345 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
1346 if (mode
& MAY_EXEC
)
1347 args
.access
|= NFS4_ACCESS_EXECUTE
;
1349 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1352 if (res
.access
& NFS4_ACCESS_READ
)
1353 entry
->mask
|= MAY_READ
;
1354 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
1355 entry
->mask
|= MAY_WRITE
;
1356 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
1357 entry
->mask
|= MAY_EXEC
;
1362 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1364 struct nfs4_exception exception
= { };
1367 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1368 _nfs4_proc_access(inode
, entry
),
1370 } while (exception
.retry
);
1375 * TODO: For the time being, we don't try to get any attributes
1376 * along with any of the zero-copy operations READ, READDIR,
1379 * In the case of the first three, we want to put the GETATTR
1380 * after the read-type operation -- this is because it is hard
1381 * to predict the length of a GETATTR response in v4, and thus
1382 * align the READ data correctly. This means that the GETATTR
1383 * may end up partially falling into the page cache, and we should
1384 * shift it into the 'tail' of the xdr_buf before processing.
1385 * To do this efficiently, we need to know the total length
1386 * of data received, which doesn't seem to be available outside
1389 * In the case of WRITE, we also want to put the GETATTR after
1390 * the operation -- in this case because we want to make sure
1391 * we get the post-operation mtime and size. This means that
1392 * we can't use xdr_encode_pages() as written: we need a variant
1393 * of it which would leave room in the 'tail' iovec.
1395 * Both of these changes to the XDR layer would in fact be quite
1396 * minor, but I decided to leave them for a subsequent patch.
1398 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1399 unsigned int pgbase
, unsigned int pglen
)
1401 struct nfs4_readlink args
= {
1402 .fh
= NFS_FH(inode
),
1407 struct rpc_message msg
= {
1408 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
1413 return rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1416 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1417 unsigned int pgbase
, unsigned int pglen
)
1419 struct nfs4_exception exception
= { };
1422 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1423 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
1425 } while (exception
.retry
);
1429 static int _nfs4_proc_read(struct nfs_read_data
*rdata
)
1431 int flags
= rdata
->flags
;
1432 struct inode
*inode
= rdata
->inode
;
1433 struct nfs_fattr
*fattr
= rdata
->res
.fattr
;
1434 struct nfs_server
*server
= NFS_SERVER(inode
);
1435 struct rpc_message msg
= {
1436 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
],
1437 .rpc_argp
= &rdata
->args
,
1438 .rpc_resp
= &rdata
->res
,
1439 .rpc_cred
= rdata
->cred
,
1441 unsigned long timestamp
= jiffies
;
1444 dprintk("NFS call read %d @ %Ld\n", rdata
->args
.count
,
1445 (long long) rdata
->args
.offset
);
1448 status
= rpc_call_sync(server
->client
, &msg
, flags
);
1450 renew_lease(server
, timestamp
);
1451 dprintk("NFS reply read: %d\n", status
);
1455 static int nfs4_proc_read(struct nfs_read_data
*rdata
)
1457 struct nfs4_exception exception
= { };
1460 err
= nfs4_handle_exception(NFS_SERVER(rdata
->inode
),
1461 _nfs4_proc_read(rdata
),
1463 } while (exception
.retry
);
1467 static int _nfs4_proc_write(struct nfs_write_data
*wdata
)
1469 int rpcflags
= wdata
->flags
;
1470 struct inode
*inode
= wdata
->inode
;
1471 struct nfs_fattr
*fattr
= wdata
->res
.fattr
;
1472 struct nfs_server
*server
= NFS_SERVER(inode
);
1473 struct rpc_message msg
= {
1474 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
],
1475 .rpc_argp
= &wdata
->args
,
1476 .rpc_resp
= &wdata
->res
,
1477 .rpc_cred
= wdata
->cred
,
1481 dprintk("NFS call write %d @ %Ld\n", wdata
->args
.count
,
1482 (long long) wdata
->args
.offset
);
1485 status
= rpc_call_sync(server
->client
, &msg
, rpcflags
);
1486 dprintk("NFS reply write: %d\n", status
);
1490 static int nfs4_proc_write(struct nfs_write_data
*wdata
)
1492 struct nfs4_exception exception
= { };
1495 err
= nfs4_handle_exception(NFS_SERVER(wdata
->inode
),
1496 _nfs4_proc_write(wdata
),
1498 } while (exception
.retry
);
1502 static int _nfs4_proc_commit(struct nfs_write_data
*cdata
)
1504 struct inode
*inode
= cdata
->inode
;
1505 struct nfs_fattr
*fattr
= cdata
->res
.fattr
;
1506 struct nfs_server
*server
= NFS_SERVER(inode
);
1507 struct rpc_message msg
= {
1508 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
],
1509 .rpc_argp
= &cdata
->args
,
1510 .rpc_resp
= &cdata
->res
,
1511 .rpc_cred
= cdata
->cred
,
1515 dprintk("NFS call commit %d @ %Ld\n", cdata
->args
.count
,
1516 (long long) cdata
->args
.offset
);
1519 status
= rpc_call_sync(server
->client
, &msg
, 0);
1520 dprintk("NFS reply commit: %d\n", status
);
1524 static int nfs4_proc_commit(struct nfs_write_data
*cdata
)
1526 struct nfs4_exception exception
= { };
1529 err
= nfs4_handle_exception(NFS_SERVER(cdata
->inode
),
1530 _nfs4_proc_commit(cdata
),
1532 } while (exception
.retry
);
1538 * We will need to arrange for the VFS layer to provide an atomic open.
1539 * Until then, this create/open method is prone to inefficiency and race
1540 * conditions due to the lookup, create, and open VFS calls from sys_open()
1541 * placed on the wire.
1543 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1544 * The file will be opened again in the subsequent VFS open call
1545 * (nfs4_proc_file_open).
1547 * The open for read will just hang around to be used by any process that
1548 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1552 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
1553 int flags
, struct nameidata
*nd
)
1555 struct nfs4_state
*state
;
1556 struct rpc_cred
*cred
;
1559 cred
= rpcauth_lookupcred(NFS_SERVER(dir
)->client
->cl_auth
, 0);
1561 status
= PTR_ERR(cred
);
1564 state
= nfs4_do_open(dir
, dentry
, flags
, sattr
, cred
);
1566 if (IS_ERR(state
)) {
1567 status
= PTR_ERR(state
);
1570 d_instantiate(dentry
, state
->inode
);
1571 if (flags
& O_EXCL
) {
1572 struct nfs_fattr fattr
;
1573 status
= nfs4_do_setattr(NFS_SERVER(dir
), &fattr
,
1574 NFS_FH(state
->inode
), sattr
, state
);
1576 nfs_setattr_update_inode(state
->inode
, sattr
);
1578 if (status
== 0 && nd
!= NULL
&& (nd
->flags
& LOOKUP_OPEN
))
1579 nfs4_intent_set_file(nd
, dentry
, state
);
1581 nfs4_close_state(state
, flags
);
1586 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1588 struct nfs4_remove_arg args
= {
1592 struct nfs4_change_info res
;
1593 struct rpc_message msg
= {
1594 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
1600 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1602 update_changeattr(dir
, &res
);
1606 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1608 struct nfs4_exception exception
= { };
1611 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1612 _nfs4_proc_remove(dir
, name
),
1614 } while (exception
.retry
);
1618 struct unlink_desc
{
1619 struct nfs4_remove_arg args
;
1620 struct nfs4_change_info res
;
1623 static int nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct dentry
*dir
,
1626 struct unlink_desc
*up
;
1628 up
= (struct unlink_desc
*) kmalloc(sizeof(*up
), GFP_KERNEL
);
1632 up
->args
.fh
= NFS_FH(dir
->d_inode
);
1633 up
->args
.name
= name
;
1635 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
1636 msg
->rpc_argp
= &up
->args
;
1637 msg
->rpc_resp
= &up
->res
;
1641 static int nfs4_proc_unlink_done(struct dentry
*dir
, struct rpc_task
*task
)
1643 struct rpc_message
*msg
= &task
->tk_msg
;
1644 struct unlink_desc
*up
;
1646 if (msg
->rpc_resp
!= NULL
) {
1647 up
= container_of(msg
->rpc_resp
, struct unlink_desc
, res
);
1648 update_changeattr(dir
->d_inode
, &up
->res
);
1650 msg
->rpc_resp
= NULL
;
1651 msg
->rpc_argp
= NULL
;
1656 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
1657 struct inode
*new_dir
, struct qstr
*new_name
)
1659 struct nfs4_rename_arg arg
= {
1660 .old_dir
= NFS_FH(old_dir
),
1661 .new_dir
= NFS_FH(new_dir
),
1662 .old_name
= old_name
,
1663 .new_name
= new_name
,
1665 struct nfs4_rename_res res
= { };
1666 struct rpc_message msg
= {
1667 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
1673 status
= rpc_call_sync(NFS_CLIENT(old_dir
), &msg
, 0);
1676 update_changeattr(old_dir
, &res
.old_cinfo
);
1677 update_changeattr(new_dir
, &res
.new_cinfo
);
1682 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
1683 struct inode
*new_dir
, struct qstr
*new_name
)
1685 struct nfs4_exception exception
= { };
1688 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
1689 _nfs4_proc_rename(old_dir
, old_name
,
1692 } while (exception
.retry
);
1696 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
1698 struct nfs4_link_arg arg
= {
1699 .fh
= NFS_FH(inode
),
1700 .dir_fh
= NFS_FH(dir
),
1703 struct nfs4_change_info cinfo
= { };
1704 struct rpc_message msg
= {
1705 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
1711 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1713 update_changeattr(dir
, &cinfo
);
1718 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
1720 struct nfs4_exception exception
= { };
1723 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1724 _nfs4_proc_link(inode
, dir
, name
),
1726 } while (exception
.retry
);
1730 static int _nfs4_proc_symlink(struct inode
*dir
, struct qstr
*name
,
1731 struct qstr
*path
, struct iattr
*sattr
, struct nfs_fh
*fhandle
,
1732 struct nfs_fattr
*fattr
)
1734 struct nfs_server
*server
= NFS_SERVER(dir
);
1735 struct nfs4_create_arg arg
= {
1736 .dir_fh
= NFS_FH(dir
),
1741 .bitmask
= server
->attr_bitmask
,
1743 struct nfs4_create_res res
= {
1748 struct rpc_message msg
= {
1749 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
],
1755 if (path
->len
> NFS4_MAXPATHLEN
)
1756 return -ENAMETOOLONG
;
1757 arg
.u
.symlink
= path
;
1760 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1762 update_changeattr(dir
, &res
.dir_cinfo
);
1766 static int nfs4_proc_symlink(struct inode
*dir
, struct qstr
*name
,
1767 struct qstr
*path
, struct iattr
*sattr
, struct nfs_fh
*fhandle
,
1768 struct nfs_fattr
*fattr
)
1770 struct nfs4_exception exception
= { };
1773 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1774 _nfs4_proc_symlink(dir
, name
, path
, sattr
,
1777 } while (exception
.retry
);
1781 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
1782 struct iattr
*sattr
)
1784 struct nfs_server
*server
= NFS_SERVER(dir
);
1785 struct nfs_fh fhandle
;
1786 struct nfs_fattr fattr
;
1787 struct nfs4_create_arg arg
= {
1788 .dir_fh
= NFS_FH(dir
),
1790 .name
= &dentry
->d_name
,
1793 .bitmask
= server
->attr_bitmask
,
1795 struct nfs4_create_res res
= {
1800 struct rpc_message msg
= {
1801 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
],
1809 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1811 update_changeattr(dir
, &res
.dir_cinfo
);
1812 status
= nfs_instantiate(dentry
, &fhandle
, &fattr
);
1817 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
1818 struct iattr
*sattr
)
1820 struct nfs4_exception exception
= { };
1823 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1824 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
1826 } while (exception
.retry
);
1830 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
1831 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
1833 struct inode
*dir
= dentry
->d_inode
;
1834 struct nfs4_readdir_arg args
= {
1839 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
1841 struct nfs4_readdir_res res
;
1842 struct rpc_message msg
= {
1843 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
1850 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__
,
1851 dentry
->d_parent
->d_name
.name
,
1852 dentry
->d_name
.name
,
1853 (unsigned long long)cookie
);
1855 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
1856 res
.pgbase
= args
.pgbase
;
1857 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1859 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
1861 dprintk("%s: returns %d\n", __FUNCTION__
, status
);
1865 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
1866 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
1868 struct nfs4_exception exception
= { };
1871 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
1872 _nfs4_proc_readdir(dentry
, cred
, cookie
,
1875 } while (exception
.retry
);
1879 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
1880 struct iattr
*sattr
, dev_t rdev
)
1882 struct nfs_server
*server
= NFS_SERVER(dir
);
1884 struct nfs_fattr fattr
;
1885 struct nfs4_create_arg arg
= {
1886 .dir_fh
= NFS_FH(dir
),
1888 .name
= &dentry
->d_name
,
1890 .bitmask
= server
->attr_bitmask
,
1892 struct nfs4_create_res res
= {
1897 struct rpc_message msg
= {
1898 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
],
1903 int mode
= sattr
->ia_mode
;
1907 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
1908 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
1910 arg
.ftype
= NF4FIFO
;
1911 else if (S_ISBLK(mode
)) {
1913 arg
.u
.device
.specdata1
= MAJOR(rdev
);
1914 arg
.u
.device
.specdata2
= MINOR(rdev
);
1916 else if (S_ISCHR(mode
)) {
1918 arg
.u
.device
.specdata1
= MAJOR(rdev
);
1919 arg
.u
.device
.specdata2
= MINOR(rdev
);
1922 arg
.ftype
= NF4SOCK
;
1924 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
1926 update_changeattr(dir
, &res
.dir_cinfo
);
1927 status
= nfs_instantiate(dentry
, &fh
, &fattr
);
1932 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
1933 struct iattr
*sattr
, dev_t rdev
)
1935 struct nfs4_exception exception
= { };
1938 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1939 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
1941 } while (exception
.retry
);
1945 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1946 struct nfs_fsstat
*fsstat
)
1948 struct nfs4_statfs_arg args
= {
1950 .bitmask
= server
->attr_bitmask
,
1952 struct rpc_message msg
= {
1953 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
1958 fsstat
->fattr
->valid
= 0;
1959 return rpc_call_sync(server
->client
, &msg
, 0);
1962 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
1964 struct nfs4_exception exception
= { };
1967 err
= nfs4_handle_exception(server
,
1968 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
1970 } while (exception
.retry
);
1974 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1975 struct nfs_fsinfo
*fsinfo
)
1977 struct nfs4_fsinfo_arg args
= {
1979 .bitmask
= server
->attr_bitmask
,
1981 struct rpc_message msg
= {
1982 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
1987 return rpc_call_sync(server
->client
, &msg
, 0);
1990 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
1992 struct nfs4_exception exception
= { };
1996 err
= nfs4_handle_exception(server
,
1997 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
1999 } while (exception
.retry
);
2003 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2005 fsinfo
->fattr
->valid
= 0;
2006 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2009 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2010 struct nfs_pathconf
*pathconf
)
2012 struct nfs4_pathconf_arg args
= {
2014 .bitmask
= server
->attr_bitmask
,
2016 struct rpc_message msg
= {
2017 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2019 .rpc_resp
= pathconf
,
2022 /* None of the pathconf attributes are mandatory to implement */
2023 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2024 memset(pathconf
, 0, sizeof(*pathconf
));
2028 pathconf
->fattr
->valid
= 0;
2029 return rpc_call_sync(server
->client
, &msg
, 0);
2032 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2033 struct nfs_pathconf
*pathconf
)
2035 struct nfs4_exception exception
= { };
2039 err
= nfs4_handle_exception(server
,
2040 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2042 } while (exception
.retry
);
2047 nfs4_read_done(struct rpc_task
*task
)
2049 struct nfs_read_data
*data
= (struct nfs_read_data
*) task
->tk_calldata
;
2050 struct inode
*inode
= data
->inode
;
2052 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2053 rpc_restart_call(task
);
2056 if (task
->tk_status
> 0)
2057 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
2058 /* Call back common NFS readpage processing */
2059 nfs_readpage_result(task
);
2063 nfs4_proc_read_setup(struct nfs_read_data
*data
)
2065 struct rpc_task
*task
= &data
->task
;
2066 struct rpc_message msg
= {
2067 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
],
2068 .rpc_argp
= &data
->args
,
2069 .rpc_resp
= &data
->res
,
2070 .rpc_cred
= data
->cred
,
2072 struct inode
*inode
= data
->inode
;
2075 data
->timestamp
= jiffies
;
2077 /* N.B. Do we need to test? Never called for swapfile inode */
2078 flags
= RPC_TASK_ASYNC
| (IS_SWAPFILE(inode
)? NFS_RPC_SWAPFLAGS
: 0);
2080 /* Finalize the task. */
2081 rpc_init_task(task
, NFS_CLIENT(inode
), nfs4_read_done
, flags
);
2082 rpc_call_setup(task
, &msg
, 0);
2086 nfs4_write_done(struct rpc_task
*task
)
2088 struct nfs_write_data
*data
= (struct nfs_write_data
*) task
->tk_calldata
;
2089 struct inode
*inode
= data
->inode
;
2091 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2092 rpc_restart_call(task
);
2095 if (task
->tk_status
>= 0)
2096 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
2097 /* Call back common NFS writeback processing */
2098 nfs_writeback_done(task
);
2102 nfs4_proc_write_setup(struct nfs_write_data
*data
, int how
)
2104 struct rpc_task
*task
= &data
->task
;
2105 struct rpc_message msg
= {
2106 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
],
2107 .rpc_argp
= &data
->args
,
2108 .rpc_resp
= &data
->res
,
2109 .rpc_cred
= data
->cred
,
2111 struct inode
*inode
= data
->inode
;
2115 if (how
& FLUSH_STABLE
) {
2116 if (!NFS_I(inode
)->ncommit
)
2117 stable
= NFS_FILE_SYNC
;
2119 stable
= NFS_DATA_SYNC
;
2121 stable
= NFS_UNSTABLE
;
2122 data
->args
.stable
= stable
;
2124 data
->timestamp
= jiffies
;
2126 /* Set the initial flags for the task. */
2127 flags
= (how
& FLUSH_SYNC
) ? 0 : RPC_TASK_ASYNC
;
2129 /* Finalize the task. */
2130 rpc_init_task(task
, NFS_CLIENT(inode
), nfs4_write_done
, flags
);
2131 rpc_call_setup(task
, &msg
, 0);
2135 nfs4_commit_done(struct rpc_task
*task
)
2137 struct nfs_write_data
*data
= (struct nfs_write_data
*) task
->tk_calldata
;
2138 struct inode
*inode
= data
->inode
;
2140 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2141 rpc_restart_call(task
);
2144 /* Call back common NFS writeback processing */
2145 nfs_commit_done(task
);
2149 nfs4_proc_commit_setup(struct nfs_write_data
*data
, int how
)
2151 struct rpc_task
*task
= &data
->task
;
2152 struct rpc_message msg
= {
2153 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
],
2154 .rpc_argp
= &data
->args
,
2155 .rpc_resp
= &data
->res
,
2156 .rpc_cred
= data
->cred
,
2158 struct inode
*inode
= data
->inode
;
2161 /* Set the initial flags for the task. */
2162 flags
= (how
& FLUSH_SYNC
) ? 0 : RPC_TASK_ASYNC
;
2164 /* Finalize the task. */
2165 rpc_init_task(task
, NFS_CLIENT(inode
), nfs4_commit_done
, flags
);
2166 rpc_call_setup(task
, &msg
, 0);
2170 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2171 * standalone procedure for queueing an asynchronous RENEW.
2174 renew_done(struct rpc_task
*task
)
2176 struct nfs4_client
*clp
= (struct nfs4_client
*)task
->tk_msg
.rpc_argp
;
2177 unsigned long timestamp
= (unsigned long)task
->tk_calldata
;
2179 if (task
->tk_status
< 0) {
2180 switch (task
->tk_status
) {
2181 case -NFS4ERR_STALE_CLIENTID
:
2182 case -NFS4ERR_EXPIRED
:
2183 case -NFS4ERR_CB_PATH_DOWN
:
2184 nfs4_schedule_state_recovery(clp
);
2188 spin_lock(&clp
->cl_lock
);
2189 if (time_before(clp
->cl_last_renewal
,timestamp
))
2190 clp
->cl_last_renewal
= timestamp
;
2191 spin_unlock(&clp
->cl_lock
);
2195 nfs4_proc_async_renew(struct nfs4_client
*clp
)
2197 struct rpc_message msg
= {
2198 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2200 .rpc_cred
= clp
->cl_cred
,
2203 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
2204 renew_done
, (void *)jiffies
);
2208 nfs4_proc_renew(struct nfs4_client
*clp
)
2210 struct rpc_message msg
= {
2211 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2213 .rpc_cred
= clp
->cl_cred
,
2215 unsigned long now
= jiffies
;
2218 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2221 spin_lock(&clp
->cl_lock
);
2222 if (time_before(clp
->cl_last_renewal
,now
))
2223 clp
->cl_last_renewal
= now
;
2224 spin_unlock(&clp
->cl_lock
);
2228 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
2230 return (server
->caps
& NFS_CAP_ACLS
)
2231 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
2232 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
2235 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2236 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2239 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2241 static void buf_to_pages(const void *buf
, size_t buflen
,
2242 struct page
**pages
, unsigned int *pgbase
)
2244 const void *p
= buf
;
2246 *pgbase
= offset_in_page(buf
);
2248 while (p
< buf
+ buflen
) {
2249 *(pages
++) = virt_to_page(p
);
2250 p
+= PAGE_CACHE_SIZE
;
2254 struct nfs4_cached_acl
{
2260 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
2262 struct nfs_inode
*nfsi
= NFS_I(inode
);
2264 spin_lock(&inode
->i_lock
);
2265 kfree(nfsi
->nfs4_acl
);
2266 nfsi
->nfs4_acl
= acl
;
2267 spin_unlock(&inode
->i_lock
);
2270 static void nfs4_zap_acl_attr(struct inode
*inode
)
2272 nfs4_set_cached_acl(inode
, NULL
);
2275 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
2277 struct nfs_inode
*nfsi
= NFS_I(inode
);
2278 struct nfs4_cached_acl
*acl
;
2281 spin_lock(&inode
->i_lock
);
2282 acl
= nfsi
->nfs4_acl
;
2285 if (buf
== NULL
) /* user is just asking for length */
2287 if (acl
->cached
== 0)
2289 ret
= -ERANGE
; /* see getxattr(2) man page */
2290 if (acl
->len
> buflen
)
2292 memcpy(buf
, acl
->data
, acl
->len
);
2296 spin_unlock(&inode
->i_lock
);
2300 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
2302 struct nfs4_cached_acl
*acl
;
2304 if (buf
&& acl_len
<= PAGE_SIZE
) {
2305 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
2309 memcpy(acl
->data
, buf
, acl_len
);
2311 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
2318 nfs4_set_cached_acl(inode
, acl
);
2321 static inline ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
2323 struct page
*pages
[NFS4ACL_MAXPAGES
];
2324 struct nfs_getaclargs args
= {
2325 .fh
= NFS_FH(inode
),
2329 size_t resp_len
= buflen
;
2331 struct rpc_message msg
= {
2332 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
2334 .rpc_resp
= &resp_len
,
2336 struct page
*localpage
= NULL
;
2339 if (buflen
< PAGE_SIZE
) {
2340 /* As long as we're doing a round trip to the server anyway,
2341 * let's be prepared for a page of acl data. */
2342 localpage
= alloc_page(GFP_KERNEL
);
2343 resp_buf
= page_address(localpage
);
2344 if (localpage
== NULL
)
2346 args
.acl_pages
[0] = localpage
;
2347 args
.acl_pgbase
= 0;
2348 args
.acl_len
= PAGE_SIZE
;
2351 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
2353 ret
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2356 if (resp_len
> args
.acl_len
)
2357 nfs4_write_cached_acl(inode
, NULL
, resp_len
);
2359 nfs4_write_cached_acl(inode
, resp_buf
, resp_len
);
2362 if (resp_len
> buflen
)
2365 memcpy(buf
, resp_buf
, resp_len
);
2370 __free_page(localpage
);
2374 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
2376 struct nfs_server
*server
= NFS_SERVER(inode
);
2379 if (!nfs4_server_supports_acls(server
))
2381 ret
= nfs_revalidate_inode(server
, inode
);
2384 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
2387 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
2390 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
2392 struct nfs_server
*server
= NFS_SERVER(inode
);
2393 struct page
*pages
[NFS4ACL_MAXPAGES
];
2394 struct nfs_setaclargs arg
= {
2395 .fh
= NFS_FH(inode
),
2399 struct rpc_message msg
= {
2400 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
2406 if (!nfs4_server_supports_acls(server
))
2408 nfs_inode_return_delegation(inode
);
2409 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
2410 ret
= rpc_call_sync(NFS_SERVER(inode
)->client
, &msg
, 0);
2412 nfs4_write_cached_acl(inode
, buf
, buflen
);
2417 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
)
2419 struct nfs4_client
*clp
= server
->nfs4_state
;
2421 if (!clp
|| task
->tk_status
>= 0)
2423 switch(task
->tk_status
) {
2424 case -NFS4ERR_STALE_CLIENTID
:
2425 case -NFS4ERR_STALE_STATEID
:
2426 case -NFS4ERR_EXPIRED
:
2427 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
, NULL
);
2428 nfs4_schedule_state_recovery(clp
);
2429 if (test_bit(NFS4CLNT_OK
, &clp
->cl_state
))
2430 rpc_wake_up_task(task
);
2431 task
->tk_status
= 0;
2433 case -NFS4ERR_GRACE
:
2434 case -NFS4ERR_DELAY
:
2435 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
2436 task
->tk_status
= 0;
2438 case -NFS4ERR_OLD_STATEID
:
2439 task
->tk_status
= 0;
2442 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
2446 static int nfs4_wait_clnt_recover(struct rpc_clnt
*clnt
, struct nfs4_client
*clp
)
2450 int interruptible
, res
= 0;
2454 rpc_clnt_sigmask(clnt
, &oldset
);
2455 interruptible
= TASK_UNINTERRUPTIBLE
;
2457 interruptible
= TASK_INTERRUPTIBLE
;
2458 prepare_to_wait(&clp
->cl_waitq
, &wait
, interruptible
);
2459 nfs4_schedule_state_recovery(clp
);
2460 if (clnt
->cl_intr
&& signalled())
2462 else if (!test_bit(NFS4CLNT_OK
, &clp
->cl_state
))
2464 finish_wait(&clp
->cl_waitq
, &wait
);
2465 rpc_clnt_sigunmask(clnt
, &oldset
);
2469 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
2477 *timeout
= NFS4_POLL_RETRY_MIN
;
2478 if (*timeout
> NFS4_POLL_RETRY_MAX
)
2479 *timeout
= NFS4_POLL_RETRY_MAX
;
2480 rpc_clnt_sigmask(clnt
, &oldset
);
2481 if (clnt
->cl_intr
) {
2482 schedule_timeout_interruptible(*timeout
);
2486 schedule_timeout_uninterruptible(*timeout
);
2487 rpc_clnt_sigunmask(clnt
, &oldset
);
2492 /* This is the error handling routine for processes that are allowed
2495 int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
2497 struct nfs4_client
*clp
= server
->nfs4_state
;
2498 int ret
= errorcode
;
2500 exception
->retry
= 0;
2504 case -NFS4ERR_STALE_CLIENTID
:
2505 case -NFS4ERR_STALE_STATEID
:
2506 case -NFS4ERR_EXPIRED
:
2507 ret
= nfs4_wait_clnt_recover(server
->client
, clp
);
2509 exception
->retry
= 1;
2511 case -NFS4ERR_GRACE
:
2512 case -NFS4ERR_DELAY
:
2513 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
2515 exception
->retry
= 1;
2517 case -NFS4ERR_OLD_STATEID
:
2519 exception
->retry
= 1;
2521 /* We failed to handle the error */
2522 return nfs4_map_errors(ret
);
2525 int nfs4_proc_setclientid(struct nfs4_client
*clp
, u32 program
, unsigned short port
)
2527 nfs4_verifier sc_verifier
;
2528 struct nfs4_setclientid setclientid
= {
2529 .sc_verifier
= &sc_verifier
,
2532 struct rpc_message msg
= {
2533 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
2534 .rpc_argp
= &setclientid
,
2536 .rpc_cred
= clp
->cl_cred
,
2542 p
= (u32
*)sc_verifier
.data
;
2543 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
2544 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
2547 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
2548 sizeof(setclientid
.sc_name
), "%s/%u.%u.%u.%u %s %u",
2549 clp
->cl_ipaddr
, NIPQUAD(clp
->cl_addr
.s_addr
),
2550 clp
->cl_cred
->cr_ops
->cr_name
,
2551 clp
->cl_id_uniquifier
);
2552 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
2553 sizeof(setclientid
.sc_netid
), "tcp");
2554 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
2555 sizeof(setclientid
.sc_uaddr
), "%s.%d.%d",
2556 clp
->cl_ipaddr
, port
>> 8, port
& 255);
2558 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2559 if (status
!= -NFS4ERR_CLID_INUSE
)
2564 ssleep(clp
->cl_lease_time
+ 1);
2566 if (++clp
->cl_id_uniquifier
== 0)
2573 nfs4_proc_setclientid_confirm(struct nfs4_client
*clp
)
2575 struct nfs_fsinfo fsinfo
;
2576 struct rpc_message msg
= {
2577 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
2579 .rpc_resp
= &fsinfo
,
2580 .rpc_cred
= clp
->cl_cred
,
2586 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2588 spin_lock(&clp
->cl_lock
);
2589 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
2590 clp
->cl_last_renewal
= now
;
2591 spin_unlock(&clp
->cl_lock
);
2596 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
)
2598 struct nfs4_delegreturnargs args
= {
2599 .fhandle
= NFS_FH(inode
),
2602 struct rpc_message msg
= {
2603 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
2608 return rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2611 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
)
2613 struct nfs_server
*server
= NFS_SERVER(inode
);
2614 struct nfs4_exception exception
= { };
2617 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
);
2619 case -NFS4ERR_STALE_STATEID
:
2620 case -NFS4ERR_EXPIRED
:
2621 nfs4_schedule_state_recovery(server
->nfs4_state
);
2625 err
= nfs4_handle_exception(server
, err
, &exception
);
2626 } while (exception
.retry
);
2630 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2631 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
2634 * sleep, with exponential backoff, and retry the LOCK operation.
2636 static unsigned long
2637 nfs4_set_lock_task_retry(unsigned long timeout
)
2639 schedule_timeout_interruptible(timeout
);
2641 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
2642 return NFS4_LOCK_MAXTIMEOUT
;
2647 nfs4_lck_type(int cmd
, struct file_lock
*request
)
2650 switch (request
->fl_type
) {
2652 return IS_SETLKW(cmd
) ? NFS4_READW_LT
: NFS4_READ_LT
;
2654 return IS_SETLKW(cmd
) ? NFS4_WRITEW_LT
: NFS4_WRITE_LT
;
2656 return NFS4_WRITE_LT
;
2662 static inline uint64_t
2663 nfs4_lck_length(struct file_lock
*request
)
2665 if (request
->fl_end
== OFFSET_MAX
)
2666 return ~(uint64_t)0;
2667 return request
->fl_end
- request
->fl_start
+ 1;
2670 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
2672 struct inode
*inode
= state
->inode
;
2673 struct nfs_server
*server
= NFS_SERVER(inode
);
2674 struct nfs4_client
*clp
= server
->nfs4_state
;
2675 struct nfs_lockargs arg
= {
2676 .fh
= NFS_FH(inode
),
2677 .type
= nfs4_lck_type(cmd
, request
),
2678 .offset
= request
->fl_start
,
2679 .length
= nfs4_lck_length(request
),
2681 struct nfs_lockres res
= {
2684 struct rpc_message msg
= {
2685 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
2688 .rpc_cred
= state
->owner
->so_cred
,
2690 struct nfs_lowner nlo
;
2691 struct nfs4_lock_state
*lsp
;
2694 down_read(&clp
->cl_sem
);
2695 nlo
.clientid
= clp
->cl_clientid
;
2696 status
= nfs4_set_lock_state(state
, request
);
2699 lsp
= request
->fl_u
.nfs4_fl
.owner
;
2700 nlo
.id
= lsp
->ls_id
;
2702 status
= rpc_call_sync(server
->client
, &msg
, 0);
2704 request
->fl_type
= F_UNLCK
;
2705 } else if (status
== -NFS4ERR_DENIED
) {
2706 int64_t len
, start
, end
;
2707 start
= res
.u
.denied
.offset
;
2708 len
= res
.u
.denied
.length
;
2709 end
= start
+ len
- 1;
2710 if (end
< 0 || len
== 0)
2711 request
->fl_end
= OFFSET_MAX
;
2713 request
->fl_end
= (loff_t
)end
;
2714 request
->fl_start
= (loff_t
)start
;
2715 request
->fl_type
= F_WRLCK
;
2716 if (res
.u
.denied
.type
& 1)
2717 request
->fl_type
= F_RDLCK
;
2718 request
->fl_pid
= 0;
2722 up_read(&clp
->cl_sem
);
2726 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
2728 struct nfs4_exception exception
= { };
2732 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
2733 _nfs4_proc_getlk(state
, cmd
, request
),
2735 } while (exception
.retry
);
2739 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
2742 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
2744 res
= posix_lock_file_wait(file
, fl
);
2747 res
= flock_lock_file_wait(file
, fl
);
2753 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n",
2758 struct nfs4_unlockdata
{
2759 struct nfs_lockargs arg
;
2760 struct nfs_locku_opargs luargs
;
2761 struct nfs_lockres res
;
2762 struct nfs4_lock_state
*lsp
;
2763 struct nfs_open_context
*ctx
;
2765 struct completion completion
;
2768 static void nfs4_locku_release_calldata(struct nfs4_unlockdata
*calldata
)
2770 if (atomic_dec_and_test(&calldata
->refcount
)) {
2771 nfs_free_seqid(calldata
->luargs
.seqid
);
2772 nfs4_put_lock_state(calldata
->lsp
);
2773 put_nfs_open_context(calldata
->ctx
);
2778 static void nfs4_locku_complete(struct nfs4_unlockdata
*calldata
)
2780 complete(&calldata
->completion
);
2781 nfs4_locku_release_calldata(calldata
);
2784 static void nfs4_locku_done(struct rpc_task
*task
)
2786 struct nfs4_unlockdata
*calldata
= (struct nfs4_unlockdata
*)task
->tk_calldata
;
2788 nfs_increment_lock_seqid(task
->tk_status
, calldata
->luargs
.seqid
);
2789 switch (task
->tk_status
) {
2791 memcpy(calldata
->lsp
->ls_stateid
.data
,
2792 calldata
->res
.u
.stateid
.data
,
2793 sizeof(calldata
->lsp
->ls_stateid
.data
));
2795 case -NFS4ERR_STALE_STATEID
:
2796 case -NFS4ERR_EXPIRED
:
2797 nfs4_schedule_state_recovery(calldata
->res
.server
->nfs4_state
);
2800 if (nfs4_async_handle_error(task
, calldata
->res
.server
) == -EAGAIN
) {
2801 rpc_restart_call(task
);
2805 nfs4_locku_complete(calldata
);
2808 static void nfs4_locku_begin(struct rpc_task
*task
)
2810 struct nfs4_unlockdata
*calldata
= (struct nfs4_unlockdata
*)task
->tk_calldata
;
2811 struct rpc_message msg
= {
2812 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
2813 .rpc_argp
= &calldata
->arg
,
2814 .rpc_resp
= &calldata
->res
,
2815 .rpc_cred
= calldata
->lsp
->ls_state
->owner
->so_cred
,
2819 status
= nfs_wait_on_sequence(calldata
->luargs
.seqid
, task
);
2822 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
2823 nfs4_locku_complete(calldata
);
2824 task
->tk_exit
= NULL
;
2828 rpc_call_setup(task
, &msg
, 0);
2831 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
2833 struct nfs4_unlockdata
*calldata
;
2834 struct inode
*inode
= state
->inode
;
2835 struct nfs_server
*server
= NFS_SERVER(inode
);
2836 struct nfs4_lock_state
*lsp
;
2839 status
= nfs4_set_lock_state(state
, request
);
2842 lsp
= request
->fl_u
.nfs4_fl
.owner
;
2843 /* We might have lost the locks! */
2844 if ((lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0)
2846 calldata
= kmalloc(sizeof(*calldata
), GFP_KERNEL
);
2847 if (calldata
== NULL
)
2849 calldata
->luargs
.seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
2850 if (calldata
->luargs
.seqid
== NULL
) {
2854 calldata
->luargs
.stateid
= &lsp
->ls_stateid
;
2855 calldata
->arg
.fh
= NFS_FH(inode
);
2856 calldata
->arg
.type
= nfs4_lck_type(cmd
, request
);
2857 calldata
->arg
.offset
= request
->fl_start
;
2858 calldata
->arg
.length
= nfs4_lck_length(request
);
2859 calldata
->arg
.u
.locku
= &calldata
->luargs
;
2860 calldata
->res
.server
= server
;
2861 calldata
->lsp
= lsp
;
2862 atomic_inc(&lsp
->ls_count
);
2864 /* Ensure we don't close file until we're done freeing locks! */
2865 calldata
->ctx
= get_nfs_open_context((struct nfs_open_context
*)request
->fl_file
->private_data
);
2867 atomic_set(&calldata
->refcount
, 2);
2868 init_completion(&calldata
->completion
);
2870 status
= nfs4_call_async(NFS_SERVER(inode
)->client
, nfs4_locku_begin
,
2871 nfs4_locku_done
, calldata
);
2873 wait_for_completion_interruptible(&calldata
->completion
);
2874 do_vfs_lock(request
->fl_file
, request
);
2875 nfs4_locku_release_calldata(calldata
);
2879 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
, int reclaim
)
2881 struct inode
*inode
= state
->inode
;
2882 struct nfs_server
*server
= NFS_SERVER(inode
);
2883 struct nfs4_lock_state
*lsp
= request
->fl_u
.nfs4_fl
.owner
;
2884 struct nfs_lock_opargs largs
= {
2885 .lock_stateid
= &lsp
->ls_stateid
,
2886 .open_stateid
= &state
->stateid
,
2888 .clientid
= server
->nfs4_state
->cl_clientid
,
2893 struct nfs_lockargs arg
= {
2894 .fh
= NFS_FH(inode
),
2895 .type
= nfs4_lck_type(cmd
, request
),
2896 .offset
= request
->fl_start
,
2897 .length
= nfs4_lck_length(request
),
2902 struct nfs_lockres res
= {
2905 struct rpc_message msg
= {
2906 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
2909 .rpc_cred
= state
->owner
->so_cred
,
2911 int status
= -ENOMEM
;
2913 largs
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
2914 if (largs
.lock_seqid
== NULL
)
2916 if (!(lsp
->ls_seqid
.flags
& NFS_SEQID_CONFIRMED
)) {
2917 struct nfs4_state_owner
*owner
= state
->owner
;
2919 largs
.open_seqid
= nfs_alloc_seqid(&owner
->so_seqid
);
2920 if (largs
.open_seqid
== NULL
)
2922 largs
.new_lock_owner
= 1;
2923 status
= rpc_call_sync(server
->client
, &msg
, RPC_TASK_NOINTR
);
2924 /* increment open seqid on success, and seqid mutating errors */
2925 if (largs
.new_lock_owner
!= 0) {
2926 nfs_increment_open_seqid(status
, largs
.open_seqid
);
2928 nfs_confirm_seqid(&lsp
->ls_seqid
, 0);
2930 nfs_free_seqid(largs
.open_seqid
);
2932 status
= rpc_call_sync(server
->client
, &msg
, RPC_TASK_NOINTR
);
2933 /* increment lock seqid on success, and seqid mutating errors*/
2934 nfs_increment_lock_seqid(status
, largs
.lock_seqid
);
2935 /* save the returned stateid. */
2937 memcpy(lsp
->ls_stateid
.data
, res
.u
.stateid
.data
,
2938 sizeof(lsp
->ls_stateid
.data
));
2939 lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
2940 } else if (status
== -NFS4ERR_DENIED
)
2943 nfs_free_seqid(largs
.lock_seqid
);
2947 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
2949 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2950 struct nfs4_exception exception
= { };
2954 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
2955 if (err
!= -NFS4ERR_DELAY
)
2957 nfs4_handle_exception(server
, err
, &exception
);
2958 } while (exception
.retry
);
2962 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
2964 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2965 struct nfs4_exception exception
= { };
2969 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
2970 if (err
!= -NFS4ERR_DELAY
)
2972 nfs4_handle_exception(server
, err
, &exception
);
2973 } while (exception
.retry
);
2977 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
2979 struct nfs4_client
*clp
= state
->owner
->so_client
;
2982 down_read(&clp
->cl_sem
);
2983 status
= nfs4_set_lock_state(state
, request
);
2985 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
2987 /* Note: we always want to sleep here! */
2988 request
->fl_flags
|= FL_SLEEP
;
2989 if (do_vfs_lock(request
->fl_file
, request
) < 0)
2990 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __FUNCTION__
);
2992 up_read(&clp
->cl_sem
);
2996 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
2998 struct nfs4_exception exception
= { };
3002 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3003 _nfs4_proc_setlk(state
, cmd
, request
),
3005 } while (exception
.retry
);
3010 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
3012 struct nfs_open_context
*ctx
;
3013 struct nfs4_state
*state
;
3014 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
3017 /* verify open state */
3018 ctx
= (struct nfs_open_context
*)filp
->private_data
;
3021 if (request
->fl_start
< 0 || request
->fl_end
< 0)
3025 return nfs4_proc_getlk(state
, F_GETLK
, request
);
3027 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
3030 if (request
->fl_type
== F_UNLCK
)
3031 return nfs4_proc_unlck(state
, cmd
, request
);
3034 status
= nfs4_proc_setlk(state
, cmd
, request
);
3035 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
3037 timeout
= nfs4_set_lock_task_retry(timeout
);
3038 status
= -ERESTARTSYS
;
3041 } while(status
< 0);
3046 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3048 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
3049 size_t buflen
, int flags
)
3051 struct inode
*inode
= dentry
->d_inode
;
3053 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3056 if (!S_ISREG(inode
->i_mode
) &&
3057 (!S_ISDIR(inode
->i_mode
) || inode
->i_mode
& S_ISVTX
))
3060 return nfs4_proc_set_acl(inode
, buf
, buflen
);
3063 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
3064 * and that's what we'll do for e.g. user attributes that haven't been set.
3065 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3066 * attributes in kernel-managed attribute namespaces. */
3067 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
3070 struct inode
*inode
= dentry
->d_inode
;
3072 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3075 return nfs4_proc_get_acl(inode
, buf
, buflen
);
3078 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
3080 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
3082 if (buf
&& buflen
< len
)
3085 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
3089 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops
= {
3090 .recover_open
= nfs4_open_reclaim
,
3091 .recover_lock
= nfs4_lock_reclaim
,
3094 struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops
= {
3095 .recover_open
= nfs4_open_expired
,
3096 .recover_lock
= nfs4_lock_expired
,
3099 static struct inode_operations nfs4_file_inode_operations
= {
3100 .permission
= nfs_permission
,
3101 .getattr
= nfs_getattr
,
3102 .setattr
= nfs_setattr
,
3103 .getxattr
= nfs4_getxattr
,
3104 .setxattr
= nfs4_setxattr
,
3105 .listxattr
= nfs4_listxattr
,
3108 struct nfs_rpc_ops nfs_v4_clientops
= {
3109 .version
= 4, /* protocol version */
3110 .dentry_ops
= &nfs4_dentry_operations
,
3111 .dir_inode_ops
= &nfs4_dir_inode_operations
,
3112 .file_inode_ops
= &nfs4_file_inode_operations
,
3113 .getroot
= nfs4_proc_get_root
,
3114 .getattr
= nfs4_proc_getattr
,
3115 .setattr
= nfs4_proc_setattr
,
3116 .lookup
= nfs4_proc_lookup
,
3117 .access
= nfs4_proc_access
,
3118 .readlink
= nfs4_proc_readlink
,
3119 .read
= nfs4_proc_read
,
3120 .write
= nfs4_proc_write
,
3121 .commit
= nfs4_proc_commit
,
3122 .create
= nfs4_proc_create
,
3123 .remove
= nfs4_proc_remove
,
3124 .unlink_setup
= nfs4_proc_unlink_setup
,
3125 .unlink_done
= nfs4_proc_unlink_done
,
3126 .rename
= nfs4_proc_rename
,
3127 .link
= nfs4_proc_link
,
3128 .symlink
= nfs4_proc_symlink
,
3129 .mkdir
= nfs4_proc_mkdir
,
3130 .rmdir
= nfs4_proc_remove
,
3131 .readdir
= nfs4_proc_readdir
,
3132 .mknod
= nfs4_proc_mknod
,
3133 .statfs
= nfs4_proc_statfs
,
3134 .fsinfo
= nfs4_proc_fsinfo
,
3135 .pathconf
= nfs4_proc_pathconf
,
3136 .decode_dirent
= nfs4_decode_dirent
,
3137 .read_setup
= nfs4_proc_read_setup
,
3138 .write_setup
= nfs4_proc_write_setup
,
3139 .commit_setup
= nfs4_proc_commit_setup
,
3140 .file_open
= nfs_open
,
3141 .file_release
= nfs_release
,
3142 .lock
= nfs4_proc_lock
,
3143 .clear_acl_cache
= nfs4_zap_acl_attr
,