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"
56 #define NFSDBG_FACILITY NFSDBG_PROC
58 #define NFS4_POLL_RETRY_MIN (HZ/10)
59 #define NFS4_POLL_RETRY_MAX (15*HZ)
62 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
63 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
64 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*);
65 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
);
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
);
69 /* Prevent leaks of NFSv4 errors into userland */
70 int nfs4_map_errors(int err
)
73 dprintk("%s could not handle NFSv4 error %d\n",
81 * This is our standard bitmap for GETATTR requests.
83 const u32 nfs4_fattr_bitmap
[2] = {
88 | FATTR4_WORD0_FILEID
,
90 | FATTR4_WORD1_NUMLINKS
92 | FATTR4_WORD1_OWNER_GROUP
94 | FATTR4_WORD1_SPACE_USED
95 | FATTR4_WORD1_TIME_ACCESS
96 | FATTR4_WORD1_TIME_METADATA
97 | FATTR4_WORD1_TIME_MODIFY
100 const u32 nfs4_statfs_bitmap
[2] = {
101 FATTR4_WORD0_FILES_AVAIL
102 | FATTR4_WORD0_FILES_FREE
103 | FATTR4_WORD0_FILES_TOTAL
,
104 FATTR4_WORD1_SPACE_AVAIL
105 | FATTR4_WORD1_SPACE_FREE
106 | FATTR4_WORD1_SPACE_TOTAL
109 const u32 nfs4_pathconf_bitmap
[2] = {
111 | FATTR4_WORD0_MAXNAME
,
115 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
116 | FATTR4_WORD0_MAXREAD
117 | FATTR4_WORD0_MAXWRITE
118 | FATTR4_WORD0_LEASE_TIME
,
122 const u32 nfs4_fs_locations_bitmap
[2] = {
124 | FATTR4_WORD0_CHANGE
127 | FATTR4_WORD0_FILEID
128 | FATTR4_WORD0_FS_LOCATIONS
,
130 | FATTR4_WORD1_NUMLINKS
132 | FATTR4_WORD1_OWNER_GROUP
133 | FATTR4_WORD1_RAWDEV
134 | FATTR4_WORD1_SPACE_USED
135 | FATTR4_WORD1_TIME_ACCESS
136 | FATTR4_WORD1_TIME_METADATA
137 | FATTR4_WORD1_TIME_MODIFY
138 | FATTR4_WORD1_MOUNTED_ON_FILEID
141 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
142 struct nfs4_readdir_arg
*readdir
)
146 BUG_ON(readdir
->count
< 80);
148 readdir
->cookie
= cookie
;
149 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
154 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
159 * NFSv4 servers do not return entries for '.' and '..'
160 * Therefore, we fake these entries here. We let '.'
161 * have cookie 0 and '..' have cookie 1. Note that
162 * when talking to the server, we always send cookie 0
165 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
168 *p
++ = xdr_one
; /* next */
169 *p
++ = xdr_zero
; /* cookie, first word */
170 *p
++ = xdr_one
; /* cookie, second word */
171 *p
++ = xdr_one
; /* entry len */
172 memcpy(p
, ".\0\0\0", 4); /* entry */
174 *p
++ = xdr_one
; /* bitmap length */
175 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
176 *p
++ = htonl(8); /* attribute buffer length */
177 p
= xdr_encode_hyper(p
, dentry
->d_inode
->i_ino
);
180 *p
++ = xdr_one
; /* next */
181 *p
++ = xdr_zero
; /* cookie, first word */
182 *p
++ = xdr_two
; /* cookie, second word */
183 *p
++ = xdr_two
; /* entry len */
184 memcpy(p
, "..\0\0", 4); /* entry */
186 *p
++ = xdr_one
; /* bitmap length */
187 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
188 *p
++ = htonl(8); /* attribute buffer length */
189 p
= xdr_encode_hyper(p
, dentry
->d_parent
->d_inode
->i_ino
);
191 readdir
->pgbase
= (char *)p
- (char *)start
;
192 readdir
->count
-= readdir
->pgbase
;
193 kunmap_atomic(start
, KM_USER0
);
196 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
198 struct nfs_client
*clp
= server
->nfs_client
;
199 spin_lock(&clp
->cl_lock
);
200 if (time_before(clp
->cl_last_renewal
,timestamp
))
201 clp
->cl_last_renewal
= timestamp
;
202 spin_unlock(&clp
->cl_lock
);
205 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
207 struct nfs_inode
*nfsi
= NFS_I(dir
);
209 spin_lock(&dir
->i_lock
);
210 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
211 if (cinfo
->before
== nfsi
->change_attr
&& cinfo
->atomic
)
212 nfsi
->change_attr
= cinfo
->after
;
213 spin_unlock(&dir
->i_lock
);
216 struct nfs4_opendata
{
218 struct nfs_openargs o_arg
;
219 struct nfs_openres o_res
;
220 struct nfs_open_confirmargs c_arg
;
221 struct nfs_open_confirmres c_res
;
222 struct nfs_fattr f_attr
;
223 struct nfs_fattr dir_attr
;
226 struct nfs4_state_owner
*owner
;
228 unsigned long timestamp
;
234 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
236 p
->o_res
.f_attr
= &p
->f_attr
;
237 p
->o_res
.dir_attr
= &p
->dir_attr
;
238 p
->o_res
.server
= p
->o_arg
.server
;
239 nfs_fattr_init(&p
->f_attr
);
240 nfs_fattr_init(&p
->dir_attr
);
243 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
244 struct nfs4_state_owner
*sp
, int flags
,
245 const struct iattr
*attrs
)
247 struct dentry
*parent
= dget_parent(path
->dentry
);
248 struct inode
*dir
= parent
->d_inode
;
249 struct nfs_server
*server
= NFS_SERVER(dir
);
250 struct nfs4_opendata
*p
;
252 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
255 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
256 if (p
->o_arg
.seqid
== NULL
)
258 p
->path
.mnt
= mntget(path
->mnt
);
259 p
->path
.dentry
= dget(path
->dentry
);
262 atomic_inc(&sp
->so_count
);
263 p
->o_arg
.fh
= NFS_FH(dir
);
264 p
->o_arg
.open_flags
= flags
,
265 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
266 p
->o_arg
.id
= sp
->so_owner_id
.id
;
267 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
268 p
->o_arg
.server
= server
;
269 p
->o_arg
.bitmask
= server
->attr_bitmask
;
270 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
271 if (flags
& O_EXCL
) {
272 u32
*s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
275 } else if (flags
& O_CREAT
) {
276 p
->o_arg
.u
.attrs
= &p
->attrs
;
277 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
279 p
->c_arg
.fh
= &p
->o_res
.fh
;
280 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
281 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
282 nfs4_init_opendata_res(p
);
292 static void nfs4_opendata_free(struct kref
*kref
)
294 struct nfs4_opendata
*p
= container_of(kref
,
295 struct nfs4_opendata
, kref
);
297 nfs_free_seqid(p
->o_arg
.seqid
);
298 nfs4_put_state_owner(p
->owner
);
300 dput(p
->path
.dentry
);
305 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
308 kref_put(&p
->kref
, nfs4_opendata_free
);
311 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
316 rpc_clnt_sigmask(task
->tk_client
, &oldset
);
317 ret
= rpc_wait_for_completion_task(task
);
318 rpc_clnt_sigunmask(task
->tk_client
, &oldset
);
322 static inline void update_open_stateflags(struct nfs4_state
*state
, mode_t open_flags
)
324 switch (open_flags
) {
331 case FMODE_READ
|FMODE_WRITE
:
336 static void update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, int open_flags
)
338 struct inode
*inode
= state
->inode
;
340 open_flags
&= (FMODE_READ
|FMODE_WRITE
);
341 /* Protect against nfs4_find_state_byowner() */
342 spin_lock(&state
->owner
->so_lock
);
343 spin_lock(&inode
->i_lock
);
344 memcpy(&state
->stateid
, stateid
, sizeof(state
->stateid
));
345 update_open_stateflags(state
, open_flags
);
346 nfs4_state_set_mode_locked(state
, state
->state
| open_flags
);
347 spin_unlock(&inode
->i_lock
);
348 spin_unlock(&state
->owner
->so_lock
);
351 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
354 struct nfs4_state
*state
= NULL
;
356 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
358 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
361 state
= nfs4_get_open_state(inode
, data
->owner
);
364 update_open_stateid(state
, &data
->o_res
.stateid
, data
->o_arg
.open_flags
);
365 if (data
->o_res
.delegation_type
!= 0) {
366 struct nfs_inode
*nfsi
= NFS_I(inode
);
367 int delegation_flags
= 0;
369 if (nfsi
->delegation
)
370 delegation_flags
= nfsi
->delegation
->flags
;
371 if (!(delegation_flags
& NFS_DELEGATION_NEED_RECLAIM
))
372 nfs_inode_set_delegation(state
->inode
,
373 data
->owner
->so_cred
,
376 nfs_inode_reclaim_delegation(state
->inode
,
377 data
->owner
->so_cred
,
386 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
388 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
389 struct nfs_open_context
*ctx
;
391 spin_lock(&state
->inode
->i_lock
);
392 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
393 if (ctx
->state
!= state
)
395 get_nfs_open_context(ctx
);
396 spin_unlock(&state
->inode
->i_lock
);
399 spin_unlock(&state
->inode
->i_lock
);
400 return ERR_PTR(-ENOENT
);
403 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, mode_t openflags
, struct nfs4_state
**res
)
405 struct nfs4_state
*newstate
;
408 opendata
->o_arg
.open_flags
= openflags
;
409 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
410 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
411 nfs4_init_opendata_res(opendata
);
412 ret
= _nfs4_proc_open(opendata
);
415 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
416 if (newstate
!= NULL
)
417 nfs4_close_state(&opendata
->path
, newstate
, openflags
);
422 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
424 struct nfs4_state
*newstate
;
427 /* memory barrier prior to reading state->n_* */
428 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
430 if (state
->n_rdwr
!= 0) {
431 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
434 if (newstate
!= state
)
437 if (state
->n_wronly
!= 0) {
438 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
441 if (newstate
!= state
)
444 if (state
->n_rdonly
!= 0) {
445 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
448 if (newstate
!= state
)
456 * reclaim state on the server after a reboot.
458 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
460 struct nfs_delegation
*delegation
= NFS_I(state
->inode
)->delegation
;
461 struct nfs4_opendata
*opendata
;
462 int delegation_type
= 0;
465 if (delegation
!= NULL
) {
466 if (!(delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
)) {
467 memcpy(&state
->stateid
, &delegation
->stateid
,
468 sizeof(state
->stateid
));
469 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
472 delegation_type
= delegation
->type
;
474 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, NULL
);
475 if (opendata
== NULL
)
477 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
478 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
479 nfs_copy_fh(&opendata
->o_res
.fh
, opendata
->o_arg
.fh
);
480 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
481 status
= nfs4_open_recover(opendata
, state
);
482 nfs4_opendata_put(opendata
);
486 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
488 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
489 struct nfs4_exception exception
= { };
492 err
= _nfs4_do_open_reclaim(ctx
, state
);
493 if (err
!= -NFS4ERR_DELAY
)
495 nfs4_handle_exception(server
, err
, &exception
);
496 } while (exception
.retry
);
500 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
502 struct nfs_open_context
*ctx
;
505 ctx
= nfs4_state_find_open_context(state
);
508 ret
= nfs4_do_open_reclaim(ctx
, state
);
509 put_nfs_open_context(ctx
);
513 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
515 struct nfs4_state_owner
*sp
= state
->owner
;
516 struct nfs4_opendata
*opendata
;
519 opendata
= nfs4_opendata_alloc(&ctx
->path
, sp
, 0, NULL
);
520 if (opendata
== NULL
)
522 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
523 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
524 sizeof(opendata
->o_arg
.u
.delegation
.data
));
525 ret
= nfs4_open_recover(opendata
, state
);
526 nfs4_opendata_put(opendata
);
530 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
532 struct nfs4_exception exception
= { };
533 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
536 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
540 case -NFS4ERR_STALE_CLIENTID
:
541 case -NFS4ERR_STALE_STATEID
:
542 case -NFS4ERR_EXPIRED
:
543 /* Don't recall a delegation if it was lost */
544 nfs4_schedule_state_recovery(server
->nfs_client
);
547 err
= nfs4_handle_exception(server
, err
, &exception
);
548 } while (exception
.retry
);
552 static void nfs4_open_confirm_prepare(struct rpc_task
*task
, void *calldata
)
554 struct nfs4_opendata
*data
= calldata
;
555 struct rpc_message msg
= {
556 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
557 .rpc_argp
= &data
->c_arg
,
558 .rpc_resp
= &data
->c_res
,
559 .rpc_cred
= data
->owner
->so_cred
,
561 data
->timestamp
= jiffies
;
562 rpc_call_setup(task
, &msg
, 0);
565 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
567 struct nfs4_opendata
*data
= calldata
;
569 data
->rpc_status
= task
->tk_status
;
570 if (RPC_ASSASSINATED(task
))
572 if (data
->rpc_status
== 0) {
573 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
574 sizeof(data
->o_res
.stateid
.data
));
575 renew_lease(data
->o_res
.server
, data
->timestamp
);
577 nfs_confirm_seqid(&data
->owner
->so_seqid
, data
->rpc_status
);
578 nfs_increment_open_seqid(data
->rpc_status
, data
->c_arg
.seqid
);
581 static void nfs4_open_confirm_release(void *calldata
)
583 struct nfs4_opendata
*data
= calldata
;
584 struct nfs4_state
*state
= NULL
;
586 /* If this request hasn't been cancelled, do nothing */
587 if (data
->cancelled
== 0)
589 /* In case of error, no cleanup! */
590 if (data
->rpc_status
!= 0)
592 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
593 state
= nfs4_opendata_to_nfs4_state(data
);
595 nfs4_close_state(&data
->path
, state
, data
->o_arg
.open_flags
);
597 nfs4_opendata_put(data
);
600 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
601 .rpc_call_prepare
= nfs4_open_confirm_prepare
,
602 .rpc_call_done
= nfs4_open_confirm_done
,
603 .rpc_release
= nfs4_open_confirm_release
,
607 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
609 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
611 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
612 struct rpc_task
*task
;
615 kref_get(&data
->kref
);
617 * If rpc_run_task() ends up calling ->rpc_release(), we
618 * want to ensure that it takes the 'error' code path.
620 data
->rpc_status
= -ENOMEM
;
621 task
= rpc_run_task(server
->client
, RPC_TASK_ASYNC
, &nfs4_open_confirm_ops
, data
);
623 return PTR_ERR(task
);
624 status
= nfs4_wait_for_completion_rpc_task(task
);
629 status
= data
->rpc_status
;
634 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
636 struct nfs4_opendata
*data
= calldata
;
637 struct nfs4_state_owner
*sp
= data
->owner
;
638 struct rpc_message msg
= {
639 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
640 .rpc_argp
= &data
->o_arg
,
641 .rpc_resp
= &data
->o_res
,
642 .rpc_cred
= sp
->so_cred
,
645 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
647 /* Update sequence id. */
648 data
->o_arg
.id
= sp
->so_owner_id
.id
;
649 data
->o_arg
.clientid
= sp
->so_client
->cl_clientid
;
650 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
)
651 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
652 data
->timestamp
= jiffies
;
653 rpc_call_setup(task
, &msg
, 0);
656 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
658 struct nfs4_opendata
*data
= calldata
;
660 data
->rpc_status
= task
->tk_status
;
661 if (RPC_ASSASSINATED(task
))
663 if (task
->tk_status
== 0) {
664 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
668 data
->rpc_status
= -ELOOP
;
671 data
->rpc_status
= -EISDIR
;
674 data
->rpc_status
= -ENOTDIR
;
676 renew_lease(data
->o_res
.server
, data
->timestamp
);
677 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
678 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
680 nfs_increment_open_seqid(data
->rpc_status
, data
->o_arg
.seqid
);
683 static void nfs4_open_release(void *calldata
)
685 struct nfs4_opendata
*data
= calldata
;
686 struct nfs4_state
*state
= NULL
;
688 /* If this request hasn't been cancelled, do nothing */
689 if (data
->cancelled
== 0)
691 /* In case of error, no cleanup! */
692 if (data
->rpc_status
!= 0)
694 /* In case we need an open_confirm, no cleanup! */
695 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
697 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
698 state
= nfs4_opendata_to_nfs4_state(data
);
700 nfs4_close_state(&data
->path
, state
, data
->o_arg
.open_flags
);
702 nfs4_opendata_put(data
);
705 static const struct rpc_call_ops nfs4_open_ops
= {
706 .rpc_call_prepare
= nfs4_open_prepare
,
707 .rpc_call_done
= nfs4_open_done
,
708 .rpc_release
= nfs4_open_release
,
712 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
714 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
716 struct inode
*dir
= data
->dir
->d_inode
;
717 struct nfs_server
*server
= NFS_SERVER(dir
);
718 struct nfs_openargs
*o_arg
= &data
->o_arg
;
719 struct nfs_openres
*o_res
= &data
->o_res
;
720 struct rpc_task
*task
;
723 kref_get(&data
->kref
);
725 * If rpc_run_task() ends up calling ->rpc_release(), we
726 * want to ensure that it takes the 'error' code path.
728 data
->rpc_status
= -ENOMEM
;
730 task
= rpc_run_task(server
->client
, RPC_TASK_ASYNC
, &nfs4_open_ops
, data
);
732 return PTR_ERR(task
);
733 status
= nfs4_wait_for_completion_rpc_task(task
);
738 status
= data
->rpc_status
;
743 if (o_arg
->open_flags
& O_CREAT
) {
744 update_changeattr(dir
, &o_res
->cinfo
);
745 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
747 nfs_refresh_inode(dir
, o_res
->dir_attr
);
748 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
749 status
= _nfs4_proc_open_confirm(data
);
753 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
754 return server
->nfs_client
->rpc_ops
->getattr(server
, &o_res
->fh
, o_res
->f_attr
);
758 static int _nfs4_do_access(struct inode
*inode
, struct rpc_cred
*cred
, int openflags
)
760 struct nfs_access_entry cache
;
764 if (openflags
& FMODE_READ
)
766 if (openflags
& FMODE_WRITE
)
768 if (openflags
& FMODE_EXEC
)
770 status
= nfs_access_get_cached(inode
, cred
, &cache
);
774 /* Be clever: ask server to check for all possible rights */
775 cache
.mask
= MAY_EXEC
| MAY_WRITE
| MAY_READ
;
777 cache
.jiffies
= jiffies
;
778 status
= _nfs4_proc_access(inode
, &cache
);
781 nfs_access_add_cache(inode
, &cache
);
783 if ((cache
.mask
& mask
) == mask
)
788 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
790 struct nfs_client
*clp
= server
->nfs_client
;
794 ret
= nfs4_wait_clnt_recover(server
->client
, clp
);
797 if (!test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
799 nfs4_schedule_state_recovery(clp
);
806 * reclaim state on the server after a network partition.
807 * Assumes caller holds the appropriate lock
809 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
811 struct inode
*inode
= state
->inode
;
812 struct nfs_delegation
*delegation
= NFS_I(inode
)->delegation
;
813 struct nfs4_opendata
*opendata
;
814 int openflags
= state
->state
& (FMODE_READ
|FMODE_WRITE
);
817 if (delegation
!= NULL
&& !(delegation
->flags
& NFS_DELEGATION_NEED_RECLAIM
)) {
818 ret
= _nfs4_do_access(inode
, ctx
->cred
, openflags
);
821 memcpy(&state
->stateid
, &delegation
->stateid
, sizeof(state
->stateid
));
822 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
825 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, openflags
, NULL
);
826 if (opendata
== NULL
)
828 ret
= nfs4_open_recover(opendata
, state
);
829 if (ret
== -ESTALE
) {
830 /* Invalidate the state owner so we don't ever use it again */
831 nfs4_drop_state_owner(state
->owner
);
832 d_drop(ctx
->path
.dentry
);
834 nfs4_opendata_put(opendata
);
838 static inline int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
840 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
841 struct nfs4_exception exception
= { };
845 err
= _nfs4_open_expired(ctx
, state
);
846 if (err
== -NFS4ERR_DELAY
)
847 nfs4_handle_exception(server
, err
, &exception
);
848 } while (exception
.retry
);
852 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
854 struct nfs_open_context
*ctx
;
857 ctx
= nfs4_state_find_open_context(state
);
860 ret
= nfs4_do_open_expired(ctx
, state
);
861 put_nfs_open_context(ctx
);
866 * Returns a referenced nfs4_state if there is an open delegation on the file
868 static int _nfs4_open_delegated(struct inode
*inode
, int flags
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
870 struct nfs_delegation
*delegation
;
871 struct nfs_server
*server
= NFS_SERVER(inode
);
872 struct nfs_client
*clp
= server
->nfs_client
;
873 struct nfs_inode
*nfsi
= NFS_I(inode
);
874 struct nfs4_state_owner
*sp
= NULL
;
875 struct nfs4_state
*state
= NULL
;
876 int open_flags
= flags
& (FMODE_READ
|FMODE_WRITE
);
880 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
881 dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__
);
884 err
= nfs4_recover_expired_lease(server
);
886 goto out_put_state_owner
;
887 /* Protect against reboot recovery - NOTE ORDER! */
888 down_read(&clp
->cl_sem
);
889 /* Protect against delegation recall */
890 down_read(&nfsi
->rwsem
);
891 delegation
= NFS_I(inode
)->delegation
;
893 if (delegation
== NULL
|| (delegation
->type
& open_flags
) != open_flags
)
896 state
= nfs4_get_open_state(inode
, sp
);
901 if ((state
->state
& open_flags
) == open_flags
) {
902 spin_lock(&inode
->i_lock
);
903 update_open_stateflags(state
, open_flags
);
904 spin_unlock(&inode
->i_lock
);
906 } else if (state
->state
!= 0)
907 goto out_put_open_state
;
910 err
= _nfs4_do_access(inode
, cred
, open_flags
);
913 goto out_put_open_state
;
914 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
915 update_open_stateid(state
, &delegation
->stateid
, open_flags
);
917 nfs4_put_state_owner(sp
);
918 up_read(&nfsi
->rwsem
);
919 up_read(&clp
->cl_sem
);
923 nfs4_put_open_state(state
);
925 up_read(&nfsi
->rwsem
);
926 up_read(&clp
->cl_sem
);
928 nfs_inode_return_delegation(inode
);
930 nfs4_put_state_owner(sp
);
934 static struct nfs4_state
*nfs4_open_delegated(struct inode
*inode
, int flags
, struct rpc_cred
*cred
)
936 struct nfs4_exception exception
= { };
937 struct nfs4_state
*res
= ERR_PTR(-EIO
);
941 err
= _nfs4_open_delegated(inode
, flags
, cred
, &res
);
944 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(inode
),
946 } while (exception
.retry
);
951 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
952 * fields corresponding to attributes that were used to store the verifier.
953 * Make sure we clobber those fields in the later setattr call
955 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
957 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
958 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
959 sattr
->ia_valid
|= ATTR_ATIME
;
961 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
962 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
963 sattr
->ia_valid
|= ATTR_MTIME
;
967 * Returns a referenced nfs4_state
969 static int _nfs4_do_open(struct inode
*dir
, struct path
*path
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
971 struct nfs4_state_owner
*sp
;
972 struct nfs4_state
*state
= NULL
;
973 struct nfs_server
*server
= NFS_SERVER(dir
);
974 struct nfs_client
*clp
= server
->nfs_client
;
975 struct nfs4_opendata
*opendata
;
978 /* Protect against reboot recovery conflicts */
980 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
981 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
984 status
= nfs4_recover_expired_lease(server
);
986 goto err_put_state_owner
;
987 down_read(&clp
->cl_sem
);
989 opendata
= nfs4_opendata_alloc(path
, sp
, flags
, sattr
);
990 if (opendata
== NULL
)
991 goto err_release_rwsem
;
993 status
= _nfs4_proc_open(opendata
);
995 goto err_opendata_put
;
997 if (opendata
->o_arg
.open_flags
& O_EXCL
)
998 nfs4_exclusive_attrset(opendata
, sattr
);
1001 state
= nfs4_opendata_to_nfs4_state(opendata
);
1003 goto err_opendata_put
;
1004 nfs4_opendata_put(opendata
);
1005 nfs4_put_state_owner(sp
);
1006 up_read(&clp
->cl_sem
);
1010 nfs4_opendata_put(opendata
);
1012 up_read(&clp
->cl_sem
);
1013 err_put_state_owner
:
1014 nfs4_put_state_owner(sp
);
1021 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct path
*path
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
1023 struct nfs4_exception exception
= { };
1024 struct nfs4_state
*res
;
1028 status
= _nfs4_do_open(dir
, path
, flags
, sattr
, cred
, &res
);
1031 /* NOTE: BAD_SEQID means the server and client disagree about the
1032 * book-keeping w.r.t. state-changing operations
1033 * (OPEN/CLOSE/LOCK/LOCKU...)
1034 * It is actually a sign of a bug on the client or on the server.
1036 * If we receive a BAD_SEQID error in the particular case of
1037 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1038 * have unhashed the old state_owner for us, and that we can
1039 * therefore safely retry using a new one. We should still warn
1040 * the user though...
1042 if (status
== -NFS4ERR_BAD_SEQID
) {
1043 printk(KERN_WARNING
"NFS: v4 server returned a bad sequence-id error!\n");
1044 exception
.retry
= 1;
1048 * BAD_STATEID on OPEN means that the server cancelled our
1049 * state before it received the OPEN_CONFIRM.
1050 * Recover by retrying the request as per the discussion
1051 * on Page 181 of RFC3530.
1053 if (status
== -NFS4ERR_BAD_STATEID
) {
1054 exception
.retry
= 1;
1057 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1058 status
, &exception
));
1059 } while (exception
.retry
);
1063 static int _nfs4_do_setattr(struct inode
*inode
, struct nfs_fattr
*fattr
,
1064 struct iattr
*sattr
, struct nfs4_state
*state
)
1066 struct nfs_server
*server
= NFS_SERVER(inode
);
1067 struct nfs_setattrargs arg
= {
1068 .fh
= NFS_FH(inode
),
1071 .bitmask
= server
->attr_bitmask
,
1073 struct nfs_setattrres res
= {
1077 struct rpc_message msg
= {
1078 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1082 unsigned long timestamp
= jiffies
;
1085 nfs_fattr_init(fattr
);
1087 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1088 /* Use that stateid */
1089 } else if (state
!= NULL
) {
1090 msg
.rpc_cred
= state
->owner
->so_cred
;
1091 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
1093 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1095 status
= rpc_call_sync(server
->client
, &msg
, 0);
1096 if (status
== 0 && state
!= NULL
)
1097 renew_lease(server
, timestamp
);
1101 static int nfs4_do_setattr(struct inode
*inode
, struct nfs_fattr
*fattr
,
1102 struct iattr
*sattr
, struct nfs4_state
*state
)
1104 struct nfs_server
*server
= NFS_SERVER(inode
);
1105 struct nfs4_exception exception
= { };
1108 err
= nfs4_handle_exception(server
,
1109 _nfs4_do_setattr(inode
, fattr
, sattr
, state
),
1111 } while (exception
.retry
);
1115 struct nfs4_closedata
{
1117 struct inode
*inode
;
1118 struct nfs4_state
*state
;
1119 struct nfs_closeargs arg
;
1120 struct nfs_closeres res
;
1121 struct nfs_fattr fattr
;
1122 unsigned long timestamp
;
1125 static void nfs4_free_closedata(void *data
)
1127 struct nfs4_closedata
*calldata
= data
;
1128 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1130 nfs4_put_open_state(calldata
->state
);
1131 nfs_free_seqid(calldata
->arg
.seqid
);
1132 nfs4_put_state_owner(sp
);
1133 dput(calldata
->path
.dentry
);
1134 mntput(calldata
->path
.mnt
);
1138 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1140 struct nfs4_closedata
*calldata
= data
;
1141 struct nfs4_state
*state
= calldata
->state
;
1142 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1144 if (RPC_ASSASSINATED(task
))
1146 /* hmm. we are done with the inode, and in the process of freeing
1147 * the state_owner. we keep this around to process errors
1149 nfs_increment_open_seqid(task
->tk_status
, calldata
->arg
.seqid
);
1150 switch (task
->tk_status
) {
1152 memcpy(&state
->stateid
, &calldata
->res
.stateid
,
1153 sizeof(state
->stateid
));
1154 renew_lease(server
, calldata
->timestamp
);
1156 case -NFS4ERR_STALE_STATEID
:
1157 case -NFS4ERR_EXPIRED
:
1160 if (nfs4_async_handle_error(task
, server
) == -EAGAIN
) {
1161 rpc_restart_call(task
);
1165 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1168 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1170 struct nfs4_closedata
*calldata
= data
;
1171 struct nfs4_state
*state
= calldata
->state
;
1172 struct rpc_message msg
= {
1173 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1174 .rpc_argp
= &calldata
->arg
,
1175 .rpc_resp
= &calldata
->res
,
1176 .rpc_cred
= state
->owner
->so_cred
,
1178 int mode
= 0, old_mode
;
1180 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1182 /* Recalculate the new open mode in case someone reopened the file
1183 * while we were waiting in line to be scheduled.
1185 spin_lock(&state
->owner
->so_lock
);
1186 spin_lock(&calldata
->inode
->i_lock
);
1187 mode
= old_mode
= state
->state
;
1188 if (state
->n_rdwr
== 0) {
1189 if (state
->n_rdonly
== 0)
1190 mode
&= ~FMODE_READ
;
1191 if (state
->n_wronly
== 0)
1192 mode
&= ~FMODE_WRITE
;
1194 nfs4_state_set_mode_locked(state
, mode
);
1195 spin_unlock(&calldata
->inode
->i_lock
);
1196 spin_unlock(&state
->owner
->so_lock
);
1197 if (mode
== old_mode
|| test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
1198 /* Note: exit _without_ calling nfs4_close_done */
1199 task
->tk_action
= NULL
;
1202 nfs_fattr_init(calldata
->res
.fattr
);
1204 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1205 calldata
->arg
.open_flags
= mode
;
1206 calldata
->timestamp
= jiffies
;
1207 rpc_call_setup(task
, &msg
, 0);
1210 static const struct rpc_call_ops nfs4_close_ops
= {
1211 .rpc_call_prepare
= nfs4_close_prepare
,
1212 .rpc_call_done
= nfs4_close_done
,
1213 .rpc_release
= nfs4_free_closedata
,
1217 * It is possible for data to be read/written from a mem-mapped file
1218 * after the sys_close call (which hits the vfs layer as a flush).
1219 * This means that we can't safely call nfsv4 close on a file until
1220 * the inode is cleared. This in turn means that we are not good
1221 * NFSv4 citizens - we do not indicate to the server to update the file's
1222 * share state even when we are done with one of the three share
1223 * stateid's in the inode.
1225 * NOTE: Caller must be holding the sp->so_owner semaphore!
1227 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
)
1229 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1230 struct nfs4_closedata
*calldata
;
1231 struct nfs4_state_owner
*sp
= state
->owner
;
1232 struct rpc_task
*task
;
1233 int status
= -ENOMEM
;
1235 calldata
= kmalloc(sizeof(*calldata
), GFP_KERNEL
);
1236 if (calldata
== NULL
)
1238 calldata
->inode
= state
->inode
;
1239 calldata
->state
= state
;
1240 calldata
->arg
.fh
= NFS_FH(state
->inode
);
1241 calldata
->arg
.stateid
= &state
->stateid
;
1242 /* Serialization for the sequence id */
1243 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
1244 if (calldata
->arg
.seqid
== NULL
)
1245 goto out_free_calldata
;
1246 calldata
->arg
.bitmask
= server
->attr_bitmask
;
1247 calldata
->res
.fattr
= &calldata
->fattr
;
1248 calldata
->res
.server
= server
;
1249 calldata
->path
.mnt
= mntget(path
->mnt
);
1250 calldata
->path
.dentry
= dget(path
->dentry
);
1252 task
= rpc_run_task(server
->client
, RPC_TASK_ASYNC
, &nfs4_close_ops
, calldata
);
1254 return PTR_ERR(task
);
1260 nfs4_put_open_state(state
);
1261 nfs4_put_state_owner(sp
);
1265 static int nfs4_intent_set_file(struct nameidata
*nd
, struct path
*path
, struct nfs4_state
*state
)
1270 /* If the open_intent is for execute, we have an extra check to make */
1271 if (nd
->intent
.open
.flags
& FMODE_EXEC
) {
1272 ret
= _nfs4_do_access(state
->inode
,
1273 state
->owner
->so_cred
,
1274 nd
->intent
.open
.flags
);
1278 filp
= lookup_instantiate_filp(nd
, path
->dentry
, NULL
);
1279 if (!IS_ERR(filp
)) {
1280 struct nfs_open_context
*ctx
;
1281 ctx
= (struct nfs_open_context
*)filp
->private_data
;
1285 ret
= PTR_ERR(filp
);
1287 nfs4_close_state(path
, state
, nd
->intent
.open
.flags
);
1292 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
1294 struct path path
= {
1299 struct rpc_cred
*cred
;
1300 struct nfs4_state
*state
;
1303 if (nd
->flags
& LOOKUP_CREATE
) {
1304 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
1305 attr
.ia_valid
= ATTR_MODE
;
1306 if (!IS_POSIXACL(dir
))
1307 attr
.ia_mode
&= ~current
->fs
->umask
;
1310 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
1313 cred
= rpcauth_lookupcred(NFS_CLIENT(dir
)->cl_auth
, 0);
1315 return (struct dentry
*)cred
;
1316 state
= nfs4_do_open(dir
, &path
, nd
->intent
.open
.flags
, &attr
, cred
);
1318 if (IS_ERR(state
)) {
1319 if (PTR_ERR(state
) == -ENOENT
)
1320 d_add(dentry
, NULL
);
1321 return (struct dentry
*)state
;
1323 res
= d_add_unique(dentry
, igrab(state
->inode
));
1326 nfs4_intent_set_file(nd
, &path
, state
);
1331 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1333 struct path path
= {
1337 struct rpc_cred
*cred
;
1338 struct nfs4_state
*state
;
1340 cred
= rpcauth_lookupcred(NFS_CLIENT(dir
)->cl_auth
, 0);
1342 return PTR_ERR(cred
);
1343 state
= nfs4_open_delegated(dentry
->d_inode
, openflags
, cred
);
1345 state
= nfs4_do_open(dir
, &path
, openflags
, NULL
, cred
);
1347 if (IS_ERR(state
)) {
1348 switch (PTR_ERR(state
)) {
1354 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1360 if (state
->inode
== dentry
->d_inode
) {
1361 nfs4_intent_set_file(nd
, &path
, state
);
1364 nfs4_close_state(&path
, state
, openflags
);
1371 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1373 struct nfs4_server_caps_res res
= {};
1374 struct rpc_message msg
= {
1375 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
1376 .rpc_argp
= fhandle
,
1381 status
= rpc_call_sync(server
->client
, &msg
, 0);
1383 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
1384 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
1385 server
->caps
|= NFS_CAP_ACLS
;
1386 if (res
.has_links
!= 0)
1387 server
->caps
|= NFS_CAP_HARDLINKS
;
1388 if (res
.has_symlinks
!= 0)
1389 server
->caps
|= NFS_CAP_SYMLINKS
;
1390 server
->acl_bitmask
= res
.acl_bitmask
;
1395 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1397 struct nfs4_exception exception
= { };
1400 err
= nfs4_handle_exception(server
,
1401 _nfs4_server_capabilities(server
, fhandle
),
1403 } while (exception
.retry
);
1407 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1408 struct nfs_fsinfo
*info
)
1410 struct nfs4_lookup_root_arg args
= {
1411 .bitmask
= nfs4_fattr_bitmap
,
1413 struct nfs4_lookup_res res
= {
1415 .fattr
= info
->fattr
,
1418 struct rpc_message msg
= {
1419 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
1423 nfs_fattr_init(info
->fattr
);
1424 return rpc_call_sync(server
->client
, &msg
, 0);
1427 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1428 struct nfs_fsinfo
*info
)
1430 struct nfs4_exception exception
= { };
1433 err
= nfs4_handle_exception(server
,
1434 _nfs4_lookup_root(server
, fhandle
, info
),
1436 } while (exception
.retry
);
1441 * get the file handle for the "/" directory on the server
1443 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
1444 struct nfs_fsinfo
*info
)
1448 status
= nfs4_lookup_root(server
, fhandle
, info
);
1450 status
= nfs4_server_capabilities(server
, fhandle
);
1452 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
1453 return nfs4_map_errors(status
);
1457 * Get locations and (maybe) other attributes of a referral.
1458 * Note that we'll actually follow the referral later when
1459 * we detect fsid mismatch in inode revalidation
1461 static int nfs4_get_referral(struct inode
*dir
, struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
1463 int status
= -ENOMEM
;
1464 struct page
*page
= NULL
;
1465 struct nfs4_fs_locations
*locations
= NULL
;
1467 page
= alloc_page(GFP_KERNEL
);
1470 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
1471 if (locations
== NULL
)
1474 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
1477 /* Make sure server returned a different fsid for the referral */
1478 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
1479 dprintk("%s: server did not return a different fsid for a referral at %s\n", __FUNCTION__
, name
->name
);
1484 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
1485 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
1487 fattr
->mode
= S_IFDIR
;
1488 memset(fhandle
, 0, sizeof(struct nfs_fh
));
1497 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1499 struct nfs4_getattr_arg args
= {
1501 .bitmask
= server
->attr_bitmask
,
1503 struct nfs4_getattr_res res
= {
1507 struct rpc_message msg
= {
1508 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
1513 nfs_fattr_init(fattr
);
1514 return rpc_call_sync(server
->client
, &msg
, 0);
1517 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1519 struct nfs4_exception exception
= { };
1522 err
= nfs4_handle_exception(server
,
1523 _nfs4_proc_getattr(server
, fhandle
, fattr
),
1525 } while (exception
.retry
);
1530 * The file is not closed if it is opened due to the a request to change
1531 * the size of the file. The open call will not be needed once the
1532 * VFS layer lookup-intents are implemented.
1534 * Close is called when the inode is destroyed.
1535 * If we haven't opened the file for O_WRONLY, we
1536 * need to in the size_change case to obtain a stateid.
1539 * Because OPEN is always done by name in nfsv4, it is
1540 * possible that we opened a different file by the same
1541 * name. We can recognize this race condition, but we
1542 * can't do anything about it besides returning an error.
1544 * This will be fixed with VFS changes (lookup-intent).
1547 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
1548 struct iattr
*sattr
)
1550 struct rpc_cred
*cred
;
1551 struct inode
*inode
= dentry
->d_inode
;
1552 struct nfs_open_context
*ctx
;
1553 struct nfs4_state
*state
= NULL
;
1556 nfs_fattr_init(fattr
);
1558 cred
= rpcauth_lookupcred(NFS_CLIENT(inode
)->cl_auth
, 0);
1560 return PTR_ERR(cred
);
1562 /* Search for an existing open(O_WRITE) file */
1563 ctx
= nfs_find_open_context(inode
, cred
, FMODE_WRITE
);
1567 status
= nfs4_do_setattr(inode
, fattr
, sattr
, state
);
1569 nfs_setattr_update_inode(inode
, sattr
);
1571 put_nfs_open_context(ctx
);
1576 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
1577 struct qstr
*name
, struct nfs_fh
*fhandle
,
1578 struct nfs_fattr
*fattr
)
1581 struct nfs4_lookup_arg args
= {
1582 .bitmask
= server
->attr_bitmask
,
1586 struct nfs4_lookup_res res
= {
1591 struct rpc_message msg
= {
1592 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
1597 nfs_fattr_init(fattr
);
1599 dprintk("NFS call lookupfh %s\n", name
->name
);
1600 status
= rpc_call_sync(server
->client
, &msg
, 0);
1601 dprintk("NFS reply lookupfh: %d\n", status
);
1605 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
1606 struct qstr
*name
, struct nfs_fh
*fhandle
,
1607 struct nfs_fattr
*fattr
)
1609 struct nfs4_exception exception
= { };
1612 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
1614 if (err
== -NFS4ERR_MOVED
) {
1618 err
= nfs4_handle_exception(server
, err
, &exception
);
1619 } while (exception
.retry
);
1623 static int _nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
,
1624 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1628 dprintk("NFS call lookup %s\n", name
->name
);
1629 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
1630 if (status
== -NFS4ERR_MOVED
)
1631 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
1632 dprintk("NFS reply lookup: %d\n", status
);
1636 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
1638 struct nfs4_exception exception
= { };
1641 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1642 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
1644 } while (exception
.retry
);
1648 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1650 struct nfs4_accessargs args
= {
1651 .fh
= NFS_FH(inode
),
1653 struct nfs4_accessres res
= { 0 };
1654 struct rpc_message msg
= {
1655 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
1658 .rpc_cred
= entry
->cred
,
1660 int mode
= entry
->mask
;
1664 * Determine which access bits we want to ask for...
1666 if (mode
& MAY_READ
)
1667 args
.access
|= NFS4_ACCESS_READ
;
1668 if (S_ISDIR(inode
->i_mode
)) {
1669 if (mode
& MAY_WRITE
)
1670 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
1671 if (mode
& MAY_EXEC
)
1672 args
.access
|= NFS4_ACCESS_LOOKUP
;
1674 if (mode
& MAY_WRITE
)
1675 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
1676 if (mode
& MAY_EXEC
)
1677 args
.access
|= NFS4_ACCESS_EXECUTE
;
1679 status
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1682 if (res
.access
& NFS4_ACCESS_READ
)
1683 entry
->mask
|= MAY_READ
;
1684 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
1685 entry
->mask
|= MAY_WRITE
;
1686 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
1687 entry
->mask
|= MAY_EXEC
;
1692 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
1694 struct nfs4_exception exception
= { };
1697 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1698 _nfs4_proc_access(inode
, entry
),
1700 } while (exception
.retry
);
1705 * TODO: For the time being, we don't try to get any attributes
1706 * along with any of the zero-copy operations READ, READDIR,
1709 * In the case of the first three, we want to put the GETATTR
1710 * after the read-type operation -- this is because it is hard
1711 * to predict the length of a GETATTR response in v4, and thus
1712 * align the READ data correctly. This means that the GETATTR
1713 * may end up partially falling into the page cache, and we should
1714 * shift it into the 'tail' of the xdr_buf before processing.
1715 * To do this efficiently, we need to know the total length
1716 * of data received, which doesn't seem to be available outside
1719 * In the case of WRITE, we also want to put the GETATTR after
1720 * the operation -- in this case because we want to make sure
1721 * we get the post-operation mtime and size. This means that
1722 * we can't use xdr_encode_pages() as written: we need a variant
1723 * of it which would leave room in the 'tail' iovec.
1725 * Both of these changes to the XDR layer would in fact be quite
1726 * minor, but I decided to leave them for a subsequent patch.
1728 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1729 unsigned int pgbase
, unsigned int pglen
)
1731 struct nfs4_readlink args
= {
1732 .fh
= NFS_FH(inode
),
1737 struct rpc_message msg
= {
1738 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
1743 return rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
1746 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
1747 unsigned int pgbase
, unsigned int pglen
)
1749 struct nfs4_exception exception
= { };
1752 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1753 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
1755 } while (exception
.retry
);
1761 * We will need to arrange for the VFS layer to provide an atomic open.
1762 * Until then, this create/open method is prone to inefficiency and race
1763 * conditions due to the lookup, create, and open VFS calls from sys_open()
1764 * placed on the wire.
1766 * Given the above sorry state of affairs, I'm simply sending an OPEN.
1767 * The file will be opened again in the subsequent VFS open call
1768 * (nfs4_proc_file_open).
1770 * The open for read will just hang around to be used by any process that
1771 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
1775 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
1776 int flags
, struct nameidata
*nd
)
1778 struct path path
= {
1782 struct nfs4_state
*state
;
1783 struct rpc_cred
*cred
;
1786 cred
= rpcauth_lookupcred(NFS_CLIENT(dir
)->cl_auth
, 0);
1788 status
= PTR_ERR(cred
);
1791 state
= nfs4_do_open(dir
, &path
, flags
, sattr
, cred
);
1793 if (IS_ERR(state
)) {
1794 status
= PTR_ERR(state
);
1797 d_instantiate(dentry
, igrab(state
->inode
));
1798 if (flags
& O_EXCL
) {
1799 struct nfs_fattr fattr
;
1800 status
= nfs4_do_setattr(state
->inode
, &fattr
, sattr
, state
);
1802 nfs_setattr_update_inode(state
->inode
, sattr
);
1803 nfs_post_op_update_inode(state
->inode
, &fattr
);
1805 if (status
== 0 && (nd
->flags
& LOOKUP_OPEN
) != 0)
1806 status
= nfs4_intent_set_file(nd
, &path
, state
);
1808 nfs4_close_state(&path
, state
, flags
);
1813 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1815 struct nfs_server
*server
= NFS_SERVER(dir
);
1816 struct nfs4_remove_arg args
= {
1819 .bitmask
= server
->attr_bitmask
,
1821 struct nfs_fattr dir_attr
;
1822 struct nfs4_remove_res res
= {
1824 .dir_attr
= &dir_attr
,
1826 struct rpc_message msg
= {
1827 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
1833 nfs_fattr_init(res
.dir_attr
);
1834 status
= rpc_call_sync(server
->client
, &msg
, 0);
1836 update_changeattr(dir
, &res
.cinfo
);
1837 nfs_post_op_update_inode(dir
, res
.dir_attr
);
1842 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
1844 struct nfs4_exception exception
= { };
1847 err
= nfs4_handle_exception(NFS_SERVER(dir
),
1848 _nfs4_proc_remove(dir
, name
),
1850 } while (exception
.retry
);
1854 struct unlink_desc
{
1855 struct nfs4_remove_arg args
;
1856 struct nfs4_remove_res res
;
1857 struct nfs_fattr dir_attr
;
1860 static int nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct dentry
*dir
,
1863 struct nfs_server
*server
= NFS_SERVER(dir
->d_inode
);
1864 struct unlink_desc
*up
;
1866 up
= kmalloc(sizeof(*up
), GFP_KERNEL
);
1870 up
->args
.fh
= NFS_FH(dir
->d_inode
);
1871 up
->args
.name
= name
;
1872 up
->args
.bitmask
= server
->attr_bitmask
;
1873 up
->res
.server
= server
;
1874 up
->res
.dir_attr
= &up
->dir_attr
;
1876 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
1877 msg
->rpc_argp
= &up
->args
;
1878 msg
->rpc_resp
= &up
->res
;
1882 static int nfs4_proc_unlink_done(struct dentry
*dir
, struct rpc_task
*task
)
1884 struct rpc_message
*msg
= &task
->tk_msg
;
1885 struct unlink_desc
*up
;
1887 if (msg
->rpc_resp
!= NULL
) {
1888 up
= container_of(msg
->rpc_resp
, struct unlink_desc
, res
);
1889 update_changeattr(dir
->d_inode
, &up
->res
.cinfo
);
1890 nfs_post_op_update_inode(dir
->d_inode
, up
->res
.dir_attr
);
1892 msg
->rpc_resp
= NULL
;
1893 msg
->rpc_argp
= NULL
;
1898 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
1899 struct inode
*new_dir
, struct qstr
*new_name
)
1901 struct nfs_server
*server
= NFS_SERVER(old_dir
);
1902 struct nfs4_rename_arg arg
= {
1903 .old_dir
= NFS_FH(old_dir
),
1904 .new_dir
= NFS_FH(new_dir
),
1905 .old_name
= old_name
,
1906 .new_name
= new_name
,
1907 .bitmask
= server
->attr_bitmask
,
1909 struct nfs_fattr old_fattr
, new_fattr
;
1910 struct nfs4_rename_res res
= {
1912 .old_fattr
= &old_fattr
,
1913 .new_fattr
= &new_fattr
,
1915 struct rpc_message msg
= {
1916 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
1922 nfs_fattr_init(res
.old_fattr
);
1923 nfs_fattr_init(res
.new_fattr
);
1924 status
= rpc_call_sync(server
->client
, &msg
, 0);
1927 update_changeattr(old_dir
, &res
.old_cinfo
);
1928 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
1929 update_changeattr(new_dir
, &res
.new_cinfo
);
1930 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
1935 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
1936 struct inode
*new_dir
, struct qstr
*new_name
)
1938 struct nfs4_exception exception
= { };
1941 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
1942 _nfs4_proc_rename(old_dir
, old_name
,
1945 } while (exception
.retry
);
1949 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
1951 struct nfs_server
*server
= NFS_SERVER(inode
);
1952 struct nfs4_link_arg arg
= {
1953 .fh
= NFS_FH(inode
),
1954 .dir_fh
= NFS_FH(dir
),
1956 .bitmask
= server
->attr_bitmask
,
1958 struct nfs_fattr fattr
, dir_attr
;
1959 struct nfs4_link_res res
= {
1962 .dir_attr
= &dir_attr
,
1964 struct rpc_message msg
= {
1965 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
1971 nfs_fattr_init(res
.fattr
);
1972 nfs_fattr_init(res
.dir_attr
);
1973 status
= rpc_call_sync(server
->client
, &msg
, 0);
1975 update_changeattr(dir
, &res
.cinfo
);
1976 nfs_post_op_update_inode(dir
, res
.dir_attr
);
1977 nfs_post_op_update_inode(inode
, res
.fattr
);
1983 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
1985 struct nfs4_exception exception
= { };
1988 err
= nfs4_handle_exception(NFS_SERVER(inode
),
1989 _nfs4_proc_link(inode
, dir
, name
),
1991 } while (exception
.retry
);
1995 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
1996 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
1998 struct nfs_server
*server
= NFS_SERVER(dir
);
1999 struct nfs_fh fhandle
;
2000 struct nfs_fattr fattr
, dir_fattr
;
2001 struct nfs4_create_arg arg
= {
2002 .dir_fh
= NFS_FH(dir
),
2004 .name
= &dentry
->d_name
,
2007 .bitmask
= server
->attr_bitmask
,
2009 struct nfs4_create_res res
= {
2013 .dir_fattr
= &dir_fattr
,
2015 struct rpc_message msg
= {
2016 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
],
2022 if (len
> NFS4_MAXPATHLEN
)
2023 return -ENAMETOOLONG
;
2025 arg
.u
.symlink
.pages
= &page
;
2026 arg
.u
.symlink
.len
= len
;
2027 nfs_fattr_init(&fattr
);
2028 nfs_fattr_init(&dir_fattr
);
2030 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
2032 update_changeattr(dir
, &res
.dir_cinfo
);
2033 nfs_post_op_update_inode(dir
, res
.dir_fattr
);
2034 status
= nfs_instantiate(dentry
, &fhandle
, &fattr
);
2039 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2040 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2042 struct nfs4_exception exception
= { };
2045 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2046 _nfs4_proc_symlink(dir
, dentry
, page
,
2049 } while (exception
.retry
);
2053 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2054 struct iattr
*sattr
)
2056 struct nfs_server
*server
= NFS_SERVER(dir
);
2057 struct nfs_fh fhandle
;
2058 struct nfs_fattr fattr
, dir_fattr
;
2059 struct nfs4_create_arg arg
= {
2060 .dir_fh
= NFS_FH(dir
),
2062 .name
= &dentry
->d_name
,
2065 .bitmask
= server
->attr_bitmask
,
2067 struct nfs4_create_res res
= {
2071 .dir_fattr
= &dir_fattr
,
2073 struct rpc_message msg
= {
2074 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
],
2080 nfs_fattr_init(&fattr
);
2081 nfs_fattr_init(&dir_fattr
);
2083 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
2085 update_changeattr(dir
, &res
.dir_cinfo
);
2086 nfs_post_op_update_inode(dir
, res
.dir_fattr
);
2087 status
= nfs_instantiate(dentry
, &fhandle
, &fattr
);
2092 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2093 struct iattr
*sattr
)
2095 struct nfs4_exception exception
= { };
2098 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2099 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2101 } while (exception
.retry
);
2105 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2106 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2108 struct inode
*dir
= dentry
->d_inode
;
2109 struct nfs4_readdir_arg args
= {
2114 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2116 struct nfs4_readdir_res res
;
2117 struct rpc_message msg
= {
2118 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2125 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __FUNCTION__
,
2126 dentry
->d_parent
->d_name
.name
,
2127 dentry
->d_name
.name
,
2128 (unsigned long long)cookie
);
2129 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2130 res
.pgbase
= args
.pgbase
;
2131 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
2133 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2134 dprintk("%s: returns %d\n", __FUNCTION__
, status
);
2138 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2139 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2141 struct nfs4_exception exception
= { };
2144 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2145 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2148 } while (exception
.retry
);
2152 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2153 struct iattr
*sattr
, dev_t rdev
)
2155 struct nfs_server
*server
= NFS_SERVER(dir
);
2157 struct nfs_fattr fattr
, dir_fattr
;
2158 struct nfs4_create_arg arg
= {
2159 .dir_fh
= NFS_FH(dir
),
2161 .name
= &dentry
->d_name
,
2163 .bitmask
= server
->attr_bitmask
,
2165 struct nfs4_create_res res
= {
2169 .dir_fattr
= &dir_fattr
,
2171 struct rpc_message msg
= {
2172 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
],
2177 int mode
= sattr
->ia_mode
;
2179 nfs_fattr_init(&fattr
);
2180 nfs_fattr_init(&dir_fattr
);
2182 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2183 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2185 arg
.ftype
= NF4FIFO
;
2186 else if (S_ISBLK(mode
)) {
2188 arg
.u
.device
.specdata1
= MAJOR(rdev
);
2189 arg
.u
.device
.specdata2
= MINOR(rdev
);
2191 else if (S_ISCHR(mode
)) {
2193 arg
.u
.device
.specdata1
= MAJOR(rdev
);
2194 arg
.u
.device
.specdata2
= MINOR(rdev
);
2197 arg
.ftype
= NF4SOCK
;
2199 status
= rpc_call_sync(NFS_CLIENT(dir
), &msg
, 0);
2201 update_changeattr(dir
, &res
.dir_cinfo
);
2202 nfs_post_op_update_inode(dir
, res
.dir_fattr
);
2203 status
= nfs_instantiate(dentry
, &fh
, &fattr
);
2208 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2209 struct iattr
*sattr
, dev_t rdev
)
2211 struct nfs4_exception exception
= { };
2214 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2215 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2217 } while (exception
.retry
);
2221 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2222 struct nfs_fsstat
*fsstat
)
2224 struct nfs4_statfs_arg args
= {
2226 .bitmask
= server
->attr_bitmask
,
2228 struct rpc_message msg
= {
2229 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2234 nfs_fattr_init(fsstat
->fattr
);
2235 return rpc_call_sync(server
->client
, &msg
, 0);
2238 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2240 struct nfs4_exception exception
= { };
2243 err
= nfs4_handle_exception(server
,
2244 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2246 } while (exception
.retry
);
2250 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2251 struct nfs_fsinfo
*fsinfo
)
2253 struct nfs4_fsinfo_arg args
= {
2255 .bitmask
= server
->attr_bitmask
,
2257 struct rpc_message msg
= {
2258 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
2263 return rpc_call_sync(server
->client
, &msg
, 0);
2266 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2268 struct nfs4_exception exception
= { };
2272 err
= nfs4_handle_exception(server
,
2273 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
2275 } while (exception
.retry
);
2279 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2281 nfs_fattr_init(fsinfo
->fattr
);
2282 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2285 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2286 struct nfs_pathconf
*pathconf
)
2288 struct nfs4_pathconf_arg args
= {
2290 .bitmask
= server
->attr_bitmask
,
2292 struct rpc_message msg
= {
2293 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2295 .rpc_resp
= pathconf
,
2298 /* None of the pathconf attributes are mandatory to implement */
2299 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2300 memset(pathconf
, 0, sizeof(*pathconf
));
2304 nfs_fattr_init(pathconf
->fattr
);
2305 return rpc_call_sync(server
->client
, &msg
, 0);
2308 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2309 struct nfs_pathconf
*pathconf
)
2311 struct nfs4_exception exception
= { };
2315 err
= nfs4_handle_exception(server
,
2316 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2318 } while (exception
.retry
);
2322 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
2324 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2326 if (nfs4_async_handle_error(task
, server
) == -EAGAIN
) {
2327 rpc_restart_call(task
);
2330 if (task
->tk_status
> 0)
2331 renew_lease(server
, data
->timestamp
);
2335 static void nfs4_proc_read_setup(struct nfs_read_data
*data
)
2337 struct rpc_message msg
= {
2338 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
],
2339 .rpc_argp
= &data
->args
,
2340 .rpc_resp
= &data
->res
,
2341 .rpc_cred
= data
->cred
,
2344 data
->timestamp
= jiffies
;
2346 rpc_call_setup(&data
->task
, &msg
, 0);
2349 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
2351 struct inode
*inode
= data
->inode
;
2353 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2354 rpc_restart_call(task
);
2357 if (task
->tk_status
>= 0) {
2358 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
2359 nfs_post_op_update_inode(inode
, data
->res
.fattr
);
2364 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, int how
)
2366 struct rpc_message msg
= {
2367 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
],
2368 .rpc_argp
= &data
->args
,
2369 .rpc_resp
= &data
->res
,
2370 .rpc_cred
= data
->cred
,
2372 struct inode
*inode
= data
->inode
;
2373 struct nfs_server
*server
= NFS_SERVER(inode
);
2376 if (how
& FLUSH_STABLE
) {
2377 if (!NFS_I(inode
)->ncommit
)
2378 stable
= NFS_FILE_SYNC
;
2380 stable
= NFS_DATA_SYNC
;
2382 stable
= NFS_UNSTABLE
;
2383 data
->args
.stable
= stable
;
2384 data
->args
.bitmask
= server
->attr_bitmask
;
2385 data
->res
.server
= server
;
2387 data
->timestamp
= jiffies
;
2389 /* Finalize the task. */
2390 rpc_call_setup(&data
->task
, &msg
, 0);
2393 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
2395 struct inode
*inode
= data
->inode
;
2397 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
)) == -EAGAIN
) {
2398 rpc_restart_call(task
);
2401 if (task
->tk_status
>= 0)
2402 nfs_post_op_update_inode(inode
, data
->res
.fattr
);
2406 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, int how
)
2408 struct rpc_message msg
= {
2409 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
],
2410 .rpc_argp
= &data
->args
,
2411 .rpc_resp
= &data
->res
,
2412 .rpc_cred
= data
->cred
,
2414 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2416 data
->args
.bitmask
= server
->attr_bitmask
;
2417 data
->res
.server
= server
;
2419 rpc_call_setup(&data
->task
, &msg
, 0);
2423 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
2424 * standalone procedure for queueing an asynchronous RENEW.
2426 static void nfs4_renew_done(struct rpc_task
*task
, void *data
)
2428 struct nfs_client
*clp
= (struct nfs_client
*)task
->tk_msg
.rpc_argp
;
2429 unsigned long timestamp
= (unsigned long)data
;
2431 if (task
->tk_status
< 0) {
2432 switch (task
->tk_status
) {
2433 case -NFS4ERR_STALE_CLIENTID
:
2434 case -NFS4ERR_EXPIRED
:
2435 case -NFS4ERR_CB_PATH_DOWN
:
2436 nfs4_schedule_state_recovery(clp
);
2440 spin_lock(&clp
->cl_lock
);
2441 if (time_before(clp
->cl_last_renewal
,timestamp
))
2442 clp
->cl_last_renewal
= timestamp
;
2443 spin_unlock(&clp
->cl_lock
);
2446 static const struct rpc_call_ops nfs4_renew_ops
= {
2447 .rpc_call_done
= nfs4_renew_done
,
2450 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2452 struct rpc_message msg
= {
2453 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2458 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
2459 &nfs4_renew_ops
, (void *)jiffies
);
2462 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2464 struct rpc_message msg
= {
2465 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
2469 unsigned long now
= jiffies
;
2472 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2475 spin_lock(&clp
->cl_lock
);
2476 if (time_before(clp
->cl_last_renewal
,now
))
2477 clp
->cl_last_renewal
= now
;
2478 spin_unlock(&clp
->cl_lock
);
2482 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
2484 return (server
->caps
& NFS_CAP_ACLS
)
2485 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
2486 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
2489 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
2490 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
2493 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
2495 static void buf_to_pages(const void *buf
, size_t buflen
,
2496 struct page
**pages
, unsigned int *pgbase
)
2498 const void *p
= buf
;
2500 *pgbase
= offset_in_page(buf
);
2502 while (p
< buf
+ buflen
) {
2503 *(pages
++) = virt_to_page(p
);
2504 p
+= PAGE_CACHE_SIZE
;
2508 struct nfs4_cached_acl
{
2514 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
2516 struct nfs_inode
*nfsi
= NFS_I(inode
);
2518 spin_lock(&inode
->i_lock
);
2519 kfree(nfsi
->nfs4_acl
);
2520 nfsi
->nfs4_acl
= acl
;
2521 spin_unlock(&inode
->i_lock
);
2524 static void nfs4_zap_acl_attr(struct inode
*inode
)
2526 nfs4_set_cached_acl(inode
, NULL
);
2529 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
2531 struct nfs_inode
*nfsi
= NFS_I(inode
);
2532 struct nfs4_cached_acl
*acl
;
2535 spin_lock(&inode
->i_lock
);
2536 acl
= nfsi
->nfs4_acl
;
2539 if (buf
== NULL
) /* user is just asking for length */
2541 if (acl
->cached
== 0)
2543 ret
= -ERANGE
; /* see getxattr(2) man page */
2544 if (acl
->len
> buflen
)
2546 memcpy(buf
, acl
->data
, acl
->len
);
2550 spin_unlock(&inode
->i_lock
);
2554 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
2556 struct nfs4_cached_acl
*acl
;
2558 if (buf
&& acl_len
<= PAGE_SIZE
) {
2559 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
2563 memcpy(acl
->data
, buf
, acl_len
);
2565 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
2572 nfs4_set_cached_acl(inode
, acl
);
2575 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
2577 struct page
*pages
[NFS4ACL_MAXPAGES
];
2578 struct nfs_getaclargs args
= {
2579 .fh
= NFS_FH(inode
),
2583 size_t resp_len
= buflen
;
2585 struct rpc_message msg
= {
2586 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
2588 .rpc_resp
= &resp_len
,
2590 struct page
*localpage
= NULL
;
2593 if (buflen
< PAGE_SIZE
) {
2594 /* As long as we're doing a round trip to the server anyway,
2595 * let's be prepared for a page of acl data. */
2596 localpage
= alloc_page(GFP_KERNEL
);
2597 resp_buf
= page_address(localpage
);
2598 if (localpage
== NULL
)
2600 args
.acl_pages
[0] = localpage
;
2601 args
.acl_pgbase
= 0;
2602 resp_len
= args
.acl_len
= PAGE_SIZE
;
2605 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
2607 ret
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2610 if (resp_len
> args
.acl_len
)
2611 nfs4_write_cached_acl(inode
, NULL
, resp_len
);
2613 nfs4_write_cached_acl(inode
, resp_buf
, resp_len
);
2616 if (resp_len
> buflen
)
2619 memcpy(buf
, resp_buf
, resp_len
);
2624 __free_page(localpage
);
2628 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
2630 struct nfs4_exception exception
= { };
2633 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
2636 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
2637 } while (exception
.retry
);
2641 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
2643 struct nfs_server
*server
= NFS_SERVER(inode
);
2646 if (!nfs4_server_supports_acls(server
))
2648 ret
= nfs_revalidate_inode(server
, inode
);
2651 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
2654 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
2657 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
2659 struct nfs_server
*server
= NFS_SERVER(inode
);
2660 struct page
*pages
[NFS4ACL_MAXPAGES
];
2661 struct nfs_setaclargs arg
= {
2662 .fh
= NFS_FH(inode
),
2666 struct rpc_message msg
= {
2667 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
2673 if (!nfs4_server_supports_acls(server
))
2675 nfs_inode_return_delegation(inode
);
2676 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
2677 ret
= rpc_call_sync(NFS_CLIENT(inode
), &msg
, 0);
2678 nfs_zap_caches(inode
);
2682 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
2684 struct nfs4_exception exception
= { };
2687 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2688 __nfs4_proc_set_acl(inode
, buf
, buflen
),
2690 } while (exception
.retry
);
2695 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
)
2697 struct nfs_client
*clp
= server
->nfs_client
;
2699 if (!clp
|| task
->tk_status
>= 0)
2701 switch(task
->tk_status
) {
2702 case -NFS4ERR_STALE_CLIENTID
:
2703 case -NFS4ERR_STALE_STATEID
:
2704 case -NFS4ERR_EXPIRED
:
2705 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
, NULL
);
2706 nfs4_schedule_state_recovery(clp
);
2707 if (test_bit(NFS4CLNT_STATE_RECOVER
, &clp
->cl_state
) == 0)
2708 rpc_wake_up_task(task
);
2709 task
->tk_status
= 0;
2711 case -NFS4ERR_DELAY
:
2712 nfs_inc_server_stats((struct nfs_server
*) server
,
2714 case -NFS4ERR_GRACE
:
2715 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
2716 task
->tk_status
= 0;
2718 case -NFS4ERR_OLD_STATEID
:
2719 task
->tk_status
= 0;
2722 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
2726 static int nfs4_wait_bit_interruptible(void *word
)
2728 if (signal_pending(current
))
2729 return -ERESTARTSYS
;
2734 static int nfs4_wait_clnt_recover(struct rpc_clnt
*clnt
, struct nfs_client
*clp
)
2741 rwsem_acquire(&clp
->cl_sem
.dep_map
, 0, 0, _RET_IP_
);
2743 rpc_clnt_sigmask(clnt
, &oldset
);
2744 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_STATE_RECOVER
,
2745 nfs4_wait_bit_interruptible
,
2746 TASK_INTERRUPTIBLE
);
2747 rpc_clnt_sigunmask(clnt
, &oldset
);
2749 rwsem_release(&clp
->cl_sem
.dep_map
, 1, _RET_IP_
);
2753 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
2761 *timeout
= NFS4_POLL_RETRY_MIN
;
2762 if (*timeout
> NFS4_POLL_RETRY_MAX
)
2763 *timeout
= NFS4_POLL_RETRY_MAX
;
2764 rpc_clnt_sigmask(clnt
, &oldset
);
2765 if (clnt
->cl_intr
) {
2766 schedule_timeout_interruptible(*timeout
);
2770 schedule_timeout_uninterruptible(*timeout
);
2771 rpc_clnt_sigunmask(clnt
, &oldset
);
2776 /* This is the error handling routine for processes that are allowed
2779 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
2781 struct nfs_client
*clp
= server
->nfs_client
;
2782 int ret
= errorcode
;
2784 exception
->retry
= 0;
2788 case -NFS4ERR_STALE_CLIENTID
:
2789 case -NFS4ERR_STALE_STATEID
:
2790 case -NFS4ERR_EXPIRED
:
2791 nfs4_schedule_state_recovery(clp
);
2792 ret
= nfs4_wait_clnt_recover(server
->client
, clp
);
2794 exception
->retry
= 1;
2796 case -NFS4ERR_FILE_OPEN
:
2797 case -NFS4ERR_GRACE
:
2798 case -NFS4ERR_DELAY
:
2799 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
2802 case -NFS4ERR_OLD_STATEID
:
2803 exception
->retry
= 1;
2805 /* We failed to handle the error */
2806 return nfs4_map_errors(ret
);
2809 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
, unsigned short port
, struct rpc_cred
*cred
)
2811 nfs4_verifier sc_verifier
;
2812 struct nfs4_setclientid setclientid
= {
2813 .sc_verifier
= &sc_verifier
,
2816 struct rpc_message msg
= {
2817 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
2818 .rpc_argp
= &setclientid
,
2826 p
= (__be32
*)sc_verifier
.data
;
2827 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
2828 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
2831 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
2832 sizeof(setclientid
.sc_name
), "%s/%u.%u.%u.%u %s %u",
2833 clp
->cl_ipaddr
, NIPQUAD(clp
->cl_addr
.sin_addr
),
2834 cred
->cr_ops
->cr_name
,
2835 clp
->cl_id_uniquifier
);
2836 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
2837 sizeof(setclientid
.sc_netid
), "tcp");
2838 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
2839 sizeof(setclientid
.sc_uaddr
), "%s.%d.%d",
2840 clp
->cl_ipaddr
, port
>> 8, port
& 255);
2842 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2843 if (status
!= -NFS4ERR_CLID_INUSE
)
2848 ssleep(clp
->cl_lease_time
+ 1);
2850 if (++clp
->cl_id_uniquifier
== 0)
2856 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2858 struct nfs_fsinfo fsinfo
;
2859 struct rpc_message msg
= {
2860 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
2862 .rpc_resp
= &fsinfo
,
2869 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
2871 spin_lock(&clp
->cl_lock
);
2872 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
2873 clp
->cl_last_renewal
= now
;
2874 clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
2875 spin_unlock(&clp
->cl_lock
);
2880 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
2885 err
= _nfs4_proc_setclientid_confirm(clp
, cred
);
2889 case -NFS4ERR_RESOURCE
:
2890 /* The IBM lawyers misread another document! */
2891 case -NFS4ERR_DELAY
:
2892 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
2898 struct nfs4_delegreturndata
{
2899 struct nfs4_delegreturnargs args
;
2900 struct nfs4_delegreturnres res
;
2902 nfs4_stateid stateid
;
2903 struct rpc_cred
*cred
;
2904 unsigned long timestamp
;
2905 struct nfs_fattr fattr
;
2909 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *calldata
)
2911 struct nfs4_delegreturndata
*data
= calldata
;
2912 struct rpc_message msg
= {
2913 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
2914 .rpc_argp
= &data
->args
,
2915 .rpc_resp
= &data
->res
,
2916 .rpc_cred
= data
->cred
,
2918 nfs_fattr_init(data
->res
.fattr
);
2919 rpc_call_setup(task
, &msg
, 0);
2922 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
2924 struct nfs4_delegreturndata
*data
= calldata
;
2925 data
->rpc_status
= task
->tk_status
;
2926 if (data
->rpc_status
== 0)
2927 renew_lease(data
->res
.server
, data
->timestamp
);
2930 static void nfs4_delegreturn_release(void *calldata
)
2932 struct nfs4_delegreturndata
*data
= calldata
;
2934 put_rpccred(data
->cred
);
2938 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
2939 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
2940 .rpc_call_done
= nfs4_delegreturn_done
,
2941 .rpc_release
= nfs4_delegreturn_release
,
2944 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
)
2946 struct nfs4_delegreturndata
*data
;
2947 struct nfs_server
*server
= NFS_SERVER(inode
);
2948 struct rpc_task
*task
;
2951 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
2954 data
->args
.fhandle
= &data
->fh
;
2955 data
->args
.stateid
= &data
->stateid
;
2956 data
->args
.bitmask
= server
->attr_bitmask
;
2957 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
2958 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
2959 data
->res
.fattr
= &data
->fattr
;
2960 data
->res
.server
= server
;
2961 data
->cred
= get_rpccred(cred
);
2962 data
->timestamp
= jiffies
;
2963 data
->rpc_status
= 0;
2965 task
= rpc_run_task(NFS_CLIENT(inode
), RPC_TASK_ASYNC
, &nfs4_delegreturn_ops
, data
);
2967 return PTR_ERR(task
);
2968 status
= nfs4_wait_for_completion_rpc_task(task
);
2970 status
= data
->rpc_status
;
2972 nfs_post_op_update_inode(inode
, &data
->fattr
);
2978 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
)
2980 struct nfs_server
*server
= NFS_SERVER(inode
);
2981 struct nfs4_exception exception
= { };
2984 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
);
2986 case -NFS4ERR_STALE_STATEID
:
2987 case -NFS4ERR_EXPIRED
:
2991 err
= nfs4_handle_exception(server
, err
, &exception
);
2992 } while (exception
.retry
);
2996 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
2997 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3000 * sleep, with exponential backoff, and retry the LOCK operation.
3002 static unsigned long
3003 nfs4_set_lock_task_retry(unsigned long timeout
)
3005 schedule_timeout_interruptible(timeout
);
3007 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3008 return NFS4_LOCK_MAXTIMEOUT
;
3012 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3014 struct inode
*inode
= state
->inode
;
3015 struct nfs_server
*server
= NFS_SERVER(inode
);
3016 struct nfs_client
*clp
= server
->nfs_client
;
3017 struct nfs_lockt_args arg
= {
3018 .fh
= NFS_FH(inode
),
3021 struct nfs_lockt_res res
= {
3024 struct rpc_message msg
= {
3025 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3028 .rpc_cred
= state
->owner
->so_cred
,
3030 struct nfs4_lock_state
*lsp
;
3033 down_read(&clp
->cl_sem
);
3034 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3035 status
= nfs4_set_lock_state(state
, request
);
3038 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3039 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3040 status
= rpc_call_sync(server
->client
, &msg
, 0);
3043 request
->fl_type
= F_UNLCK
;
3045 case -NFS4ERR_DENIED
:
3048 request
->fl_ops
->fl_release_private(request
);
3050 up_read(&clp
->cl_sem
);
3054 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3056 struct nfs4_exception exception
= { };
3060 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3061 _nfs4_proc_getlk(state
, cmd
, request
),
3063 } while (exception
.retry
);
3067 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3070 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3072 res
= posix_lock_file_wait(file
, fl
);
3075 res
= flock_lock_file_wait(file
, fl
);
3083 struct nfs4_unlockdata
{
3084 struct nfs_locku_args arg
;
3085 struct nfs_locku_res res
;
3086 struct nfs4_lock_state
*lsp
;
3087 struct nfs_open_context
*ctx
;
3088 struct file_lock fl
;
3089 const struct nfs_server
*server
;
3090 unsigned long timestamp
;
3093 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3094 struct nfs_open_context
*ctx
,
3095 struct nfs4_lock_state
*lsp
,
3096 struct nfs_seqid
*seqid
)
3098 struct nfs4_unlockdata
*p
;
3099 struct inode
*inode
= lsp
->ls_state
->inode
;
3101 p
= kmalloc(sizeof(*p
), GFP_KERNEL
);
3104 p
->arg
.fh
= NFS_FH(inode
);
3106 p
->arg
.seqid
= seqid
;
3107 p
->arg
.stateid
= &lsp
->ls_stateid
;
3109 atomic_inc(&lsp
->ls_count
);
3110 /* Ensure we don't close file until we're done freeing locks! */
3111 p
->ctx
= get_nfs_open_context(ctx
);
3112 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3113 p
->server
= NFS_SERVER(inode
);
3117 static void nfs4_locku_release_calldata(void *data
)
3119 struct nfs4_unlockdata
*calldata
= data
;
3120 nfs_free_seqid(calldata
->arg
.seqid
);
3121 nfs4_put_lock_state(calldata
->lsp
);
3122 put_nfs_open_context(calldata
->ctx
);
3126 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3128 struct nfs4_unlockdata
*calldata
= data
;
3130 if (RPC_ASSASSINATED(task
))
3132 nfs_increment_lock_seqid(task
->tk_status
, calldata
->arg
.seqid
);
3133 switch (task
->tk_status
) {
3135 memcpy(calldata
->lsp
->ls_stateid
.data
,
3136 calldata
->res
.stateid
.data
,
3137 sizeof(calldata
->lsp
->ls_stateid
.data
));
3138 renew_lease(calldata
->server
, calldata
->timestamp
);
3140 case -NFS4ERR_STALE_STATEID
:
3141 case -NFS4ERR_EXPIRED
:
3144 if (nfs4_async_handle_error(task
, calldata
->server
) == -EAGAIN
)
3145 rpc_restart_call(task
);
3149 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3151 struct nfs4_unlockdata
*calldata
= data
;
3152 struct rpc_message msg
= {
3153 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3154 .rpc_argp
= &calldata
->arg
,
3155 .rpc_resp
= &calldata
->res
,
3156 .rpc_cred
= calldata
->lsp
->ls_state
->owner
->so_cred
,
3159 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3161 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3162 /* Note: exit _without_ running nfs4_locku_done */
3163 task
->tk_action
= NULL
;
3166 calldata
->timestamp
= jiffies
;
3167 rpc_call_setup(task
, &msg
, 0);
3170 static const struct rpc_call_ops nfs4_locku_ops
= {
3171 .rpc_call_prepare
= nfs4_locku_prepare
,
3172 .rpc_call_done
= nfs4_locku_done
,
3173 .rpc_release
= nfs4_locku_release_calldata
,
3176 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3177 struct nfs_open_context
*ctx
,
3178 struct nfs4_lock_state
*lsp
,
3179 struct nfs_seqid
*seqid
)
3181 struct nfs4_unlockdata
*data
;
3183 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3185 nfs_free_seqid(seqid
);
3186 return ERR_PTR(-ENOMEM
);
3189 return rpc_run_task(NFS_CLIENT(lsp
->ls_state
->inode
), RPC_TASK_ASYNC
, &nfs4_locku_ops
, data
);
3192 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3194 struct nfs_seqid
*seqid
;
3195 struct nfs4_lock_state
*lsp
;
3196 struct rpc_task
*task
;
3199 status
= nfs4_set_lock_state(state
, request
);
3200 /* Unlock _before_ we do the RPC call */
3201 request
->fl_flags
|= FL_EXISTS
;
3202 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
)
3206 /* Is this a delegated lock? */
3207 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
3209 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3210 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3214 task
= nfs4_do_unlck(request
, request
->fl_file
->private_data
, lsp
, seqid
);
3215 status
= PTR_ERR(task
);
3218 status
= nfs4_wait_for_completion_rpc_task(task
);
3224 struct nfs4_lockdata
{
3225 struct nfs_lock_args arg
;
3226 struct nfs_lock_res res
;
3227 struct nfs4_lock_state
*lsp
;
3228 struct nfs_open_context
*ctx
;
3229 struct file_lock fl
;
3230 unsigned long timestamp
;
3235 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
3236 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
)
3238 struct nfs4_lockdata
*p
;
3239 struct inode
*inode
= lsp
->ls_state
->inode
;
3240 struct nfs_server
*server
= NFS_SERVER(inode
);
3242 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3246 p
->arg
.fh
= NFS_FH(inode
);
3248 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3249 if (p
->arg
.lock_seqid
== NULL
)
3251 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
3252 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
3253 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3255 atomic_inc(&lsp
->ls_count
);
3256 p
->ctx
= get_nfs_open_context(ctx
);
3257 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3264 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
3266 struct nfs4_lockdata
*data
= calldata
;
3267 struct nfs4_state
*state
= data
->lsp
->ls_state
;
3268 struct nfs4_state_owner
*sp
= state
->owner
;
3269 struct rpc_message msg
= {
3270 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
3271 .rpc_argp
= &data
->arg
,
3272 .rpc_resp
= &data
->res
,
3273 .rpc_cred
= sp
->so_cred
,
3276 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
3278 dprintk("%s: begin!\n", __FUNCTION__
);
3279 /* Do we need to do an open_to_lock_owner? */
3280 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
3281 data
->arg
.open_seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
3282 if (data
->arg
.open_seqid
== NULL
) {
3283 data
->rpc_status
= -ENOMEM
;
3284 task
->tk_action
= NULL
;
3287 data
->arg
.open_stateid
= &state
->stateid
;
3288 data
->arg
.new_lock_owner
= 1;
3290 data
->timestamp
= jiffies
;
3291 rpc_call_setup(task
, &msg
, 0);
3293 dprintk("%s: done!, ret = %d\n", __FUNCTION__
, data
->rpc_status
);
3296 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
3298 struct nfs4_lockdata
*data
= calldata
;
3300 dprintk("%s: begin!\n", __FUNCTION__
);
3302 data
->rpc_status
= task
->tk_status
;
3303 if (RPC_ASSASSINATED(task
))
3305 if (data
->arg
.new_lock_owner
!= 0) {
3306 nfs_increment_open_seqid(data
->rpc_status
, data
->arg
.open_seqid
);
3307 if (data
->rpc_status
== 0)
3308 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
3312 if (data
->rpc_status
== 0) {
3313 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
3314 sizeof(data
->lsp
->ls_stateid
.data
));
3315 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
3316 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
3318 nfs_increment_lock_seqid(data
->rpc_status
, data
->arg
.lock_seqid
);
3320 dprintk("%s: done, ret = %d!\n", __FUNCTION__
, data
->rpc_status
);
3323 static void nfs4_lock_release(void *calldata
)
3325 struct nfs4_lockdata
*data
= calldata
;
3327 dprintk("%s: begin!\n", __FUNCTION__
);
3328 if (data
->arg
.open_seqid
!= NULL
)
3329 nfs_free_seqid(data
->arg
.open_seqid
);
3330 if (data
->cancelled
!= 0) {
3331 struct rpc_task
*task
;
3332 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
3333 data
->arg
.lock_seqid
);
3336 dprintk("%s: cancelling lock!\n", __FUNCTION__
);
3338 nfs_free_seqid(data
->arg
.lock_seqid
);
3339 nfs4_put_lock_state(data
->lsp
);
3340 put_nfs_open_context(data
->ctx
);
3342 dprintk("%s: done!\n", __FUNCTION__
);
3345 static const struct rpc_call_ops nfs4_lock_ops
= {
3346 .rpc_call_prepare
= nfs4_lock_prepare
,
3347 .rpc_call_done
= nfs4_lock_done
,
3348 .rpc_release
= nfs4_lock_release
,
3351 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int reclaim
)
3353 struct nfs4_lockdata
*data
;
3354 struct rpc_task
*task
;
3357 dprintk("%s: begin!\n", __FUNCTION__
);
3358 data
= nfs4_alloc_lockdata(fl
, fl
->fl_file
->private_data
,
3359 fl
->fl_u
.nfs4_fl
.owner
);
3363 data
->arg
.block
= 1;
3365 data
->arg
.reclaim
= 1;
3366 task
= rpc_run_task(NFS_CLIENT(state
->inode
), RPC_TASK_ASYNC
,
3367 &nfs4_lock_ops
, data
);
3369 return PTR_ERR(task
);
3370 ret
= nfs4_wait_for_completion_rpc_task(task
);
3372 ret
= data
->rpc_status
;
3373 if (ret
== -NFS4ERR_DENIED
)
3376 data
->cancelled
= 1;
3378 dprintk("%s: done, ret = %d!\n", __FUNCTION__
, ret
);
3382 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
3384 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3385 struct nfs4_exception exception
= { };
3389 /* Cache the lock if possible... */
3390 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
3392 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
3393 if (err
!= -NFS4ERR_DELAY
)
3395 nfs4_handle_exception(server
, err
, &exception
);
3396 } while (exception
.retry
);
3400 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
3402 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3403 struct nfs4_exception exception
= { };
3406 err
= nfs4_set_lock_state(state
, request
);
3410 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
3412 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
3413 if (err
!= -NFS4ERR_DELAY
)
3415 nfs4_handle_exception(server
, err
, &exception
);
3416 } while (exception
.retry
);
3420 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3422 struct nfs_client
*clp
= state
->owner
->so_client
;
3423 unsigned char fl_flags
= request
->fl_flags
;
3426 /* Is this a delegated open? */
3427 status
= nfs4_set_lock_state(state
, request
);
3430 request
->fl_flags
|= FL_ACCESS
;
3431 status
= do_vfs_lock(request
->fl_file
, request
);
3434 down_read(&clp
->cl_sem
);
3435 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
3436 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3437 /* Yes: cache locks! */
3438 down_read(&nfsi
->rwsem
);
3439 /* ...but avoid races with delegation recall... */
3440 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
3441 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
3442 status
= do_vfs_lock(request
->fl_file
, request
);
3443 up_read(&nfsi
->rwsem
);
3446 up_read(&nfsi
->rwsem
);
3448 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
3451 /* Note: we always want to sleep here! */
3452 request
->fl_flags
= fl_flags
| FL_SLEEP
;
3453 if (do_vfs_lock(request
->fl_file
, request
) < 0)
3454 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __FUNCTION__
);
3456 up_read(&clp
->cl_sem
);
3458 request
->fl_flags
= fl_flags
;
3462 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3464 struct nfs4_exception exception
= { };
3468 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3469 _nfs4_proc_setlk(state
, cmd
, request
),
3471 } while (exception
.retry
);
3476 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
3478 struct nfs_open_context
*ctx
;
3479 struct nfs4_state
*state
;
3480 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
3483 /* verify open state */
3484 ctx
= (struct nfs_open_context
*)filp
->private_data
;
3487 if (request
->fl_start
< 0 || request
->fl_end
< 0)
3491 return nfs4_proc_getlk(state
, F_GETLK
, request
);
3493 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
3496 if (request
->fl_type
== F_UNLCK
)
3497 return nfs4_proc_unlck(state
, cmd
, request
);
3500 status
= nfs4_proc_setlk(state
, cmd
, request
);
3501 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
3503 timeout
= nfs4_set_lock_task_retry(timeout
);
3504 status
= -ERESTARTSYS
;
3507 } while(status
< 0);
3511 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
3513 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
3514 struct nfs4_exception exception
= { };
3517 err
= nfs4_set_lock_state(state
, fl
);
3521 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, 0);
3522 if (err
!= -NFS4ERR_DELAY
)
3524 err
= nfs4_handle_exception(server
, err
, &exception
);
3525 } while (exception
.retry
);
3530 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
3532 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
3533 size_t buflen
, int flags
)
3535 struct inode
*inode
= dentry
->d_inode
;
3537 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3540 if (!S_ISREG(inode
->i_mode
) &&
3541 (!S_ISDIR(inode
->i_mode
) || inode
->i_mode
& S_ISVTX
))
3544 return nfs4_proc_set_acl(inode
, buf
, buflen
);
3547 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
3548 * and that's what we'll do for e.g. user attributes that haven't been set.
3549 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
3550 * attributes in kernel-managed attribute namespaces. */
3551 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
3554 struct inode
*inode
= dentry
->d_inode
;
3556 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
3559 return nfs4_proc_get_acl(inode
, buf
, buflen
);
3562 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
3564 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
3566 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
3568 if (buf
&& buflen
< len
)
3571 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
3575 int nfs4_proc_fs_locations(struct inode
*dir
, struct qstr
*name
,
3576 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
3578 struct nfs_server
*server
= NFS_SERVER(dir
);
3580 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
3581 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
3583 struct nfs4_fs_locations_arg args
= {
3584 .dir_fh
= NFS_FH(dir
),
3589 struct rpc_message msg
= {
3590 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
3592 .rpc_resp
= fs_locations
,
3596 dprintk("%s: start\n", __FUNCTION__
);
3597 nfs_fattr_init(&fs_locations
->fattr
);
3598 fs_locations
->server
= server
;
3599 fs_locations
->nlocations
= 0;
3600 status
= rpc_call_sync(server
->client
, &msg
, 0);
3601 dprintk("%s: returned status = %d\n", __FUNCTION__
, status
);
3605 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops
= {
3606 .recover_open
= nfs4_open_reclaim
,
3607 .recover_lock
= nfs4_lock_reclaim
,
3610 struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops
= {
3611 .recover_open
= nfs4_open_expired
,
3612 .recover_lock
= nfs4_lock_expired
,
3615 static const struct inode_operations nfs4_file_inode_operations
= {
3616 .permission
= nfs_permission
,
3617 .getattr
= nfs_getattr
,
3618 .setattr
= nfs_setattr
,
3619 .getxattr
= nfs4_getxattr
,
3620 .setxattr
= nfs4_setxattr
,
3621 .listxattr
= nfs4_listxattr
,
3624 const struct nfs_rpc_ops nfs_v4_clientops
= {
3625 .version
= 4, /* protocol version */
3626 .dentry_ops
= &nfs4_dentry_operations
,
3627 .dir_inode_ops
= &nfs4_dir_inode_operations
,
3628 .file_inode_ops
= &nfs4_file_inode_operations
,
3629 .getroot
= nfs4_proc_get_root
,
3630 .getattr
= nfs4_proc_getattr
,
3631 .setattr
= nfs4_proc_setattr
,
3632 .lookupfh
= nfs4_proc_lookupfh
,
3633 .lookup
= nfs4_proc_lookup
,
3634 .access
= nfs4_proc_access
,
3635 .readlink
= nfs4_proc_readlink
,
3636 .create
= nfs4_proc_create
,
3637 .remove
= nfs4_proc_remove
,
3638 .unlink_setup
= nfs4_proc_unlink_setup
,
3639 .unlink_done
= nfs4_proc_unlink_done
,
3640 .rename
= nfs4_proc_rename
,
3641 .link
= nfs4_proc_link
,
3642 .symlink
= nfs4_proc_symlink
,
3643 .mkdir
= nfs4_proc_mkdir
,
3644 .rmdir
= nfs4_proc_remove
,
3645 .readdir
= nfs4_proc_readdir
,
3646 .mknod
= nfs4_proc_mknod
,
3647 .statfs
= nfs4_proc_statfs
,
3648 .fsinfo
= nfs4_proc_fsinfo
,
3649 .pathconf
= nfs4_proc_pathconf
,
3650 .set_capabilities
= nfs4_server_capabilities
,
3651 .decode_dirent
= nfs4_decode_dirent
,
3652 .read_setup
= nfs4_proc_read_setup
,
3653 .read_done
= nfs4_read_done
,
3654 .write_setup
= nfs4_proc_write_setup
,
3655 .write_done
= nfs4_write_done
,
3656 .commit_setup
= nfs4_proc_commit_setup
,
3657 .commit_done
= nfs4_commit_done
,
3658 .file_open
= nfs_open
,
3659 .file_release
= nfs_release
,
3660 .lock
= nfs4_proc_lock
,
3661 .clear_acl_cache
= nfs4_zap_acl_attr
,