4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/sunrpc/clnt.h>
43 #include <linux/nfs.h>
44 #include <linux/nfs4.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/nfs_page.h>
47 #include <linux/namei.h>
48 #include <linux/mount.h>
49 #include <linux/module.h>
50 #include <linux/sunrpc/bc_xprt.h>
53 #include "delegation.h"
58 #define NFSDBG_FACILITY NFSDBG_PROC
60 #define NFS4_POLL_RETRY_MIN (HZ/10)
61 #define NFS4_POLL_RETRY_MAX (15*HZ)
63 #define NFS4_MAX_LOOP_ON_RECOVER (10)
66 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
67 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
68 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
69 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
70 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
72 /* Prevent leaks of NFSv4 errors into userland */
73 static int nfs4_map_errors(int err
)
78 case -NFS4ERR_RESOURCE
:
81 dprintk("%s could not handle NFSv4 error %d\n",
89 * This is our standard bitmap for GETATTR requests.
91 const u32 nfs4_fattr_bitmap
[2] = {
96 | FATTR4_WORD0_FILEID
,
98 | FATTR4_WORD1_NUMLINKS
100 | FATTR4_WORD1_OWNER_GROUP
101 | FATTR4_WORD1_RAWDEV
102 | FATTR4_WORD1_SPACE_USED
103 | FATTR4_WORD1_TIME_ACCESS
104 | FATTR4_WORD1_TIME_METADATA
105 | FATTR4_WORD1_TIME_MODIFY
108 const u32 nfs4_statfs_bitmap
[2] = {
109 FATTR4_WORD0_FILES_AVAIL
110 | FATTR4_WORD0_FILES_FREE
111 | FATTR4_WORD0_FILES_TOTAL
,
112 FATTR4_WORD1_SPACE_AVAIL
113 | FATTR4_WORD1_SPACE_FREE
114 | FATTR4_WORD1_SPACE_TOTAL
117 const u32 nfs4_pathconf_bitmap
[2] = {
119 | FATTR4_WORD0_MAXNAME
,
123 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
124 | FATTR4_WORD0_MAXREAD
125 | FATTR4_WORD0_MAXWRITE
126 | FATTR4_WORD0_LEASE_TIME
,
130 const u32 nfs4_fs_locations_bitmap
[2] = {
132 | FATTR4_WORD0_CHANGE
135 | FATTR4_WORD0_FILEID
136 | FATTR4_WORD0_FS_LOCATIONS
,
138 | FATTR4_WORD1_NUMLINKS
140 | FATTR4_WORD1_OWNER_GROUP
141 | FATTR4_WORD1_RAWDEV
142 | FATTR4_WORD1_SPACE_USED
143 | FATTR4_WORD1_TIME_ACCESS
144 | FATTR4_WORD1_TIME_METADATA
145 | FATTR4_WORD1_TIME_MODIFY
146 | FATTR4_WORD1_MOUNTED_ON_FILEID
149 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
150 struct nfs4_readdir_arg
*readdir
)
154 BUG_ON(readdir
->count
< 80);
156 readdir
->cookie
= cookie
;
157 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
162 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
167 * NFSv4 servers do not return entries for '.' and '..'
168 * Therefore, we fake these entries here. We let '.'
169 * have cookie 0 and '..' have cookie 1. Note that
170 * when talking to the server, we always send cookie 0
173 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
176 *p
++ = xdr_one
; /* next */
177 *p
++ = xdr_zero
; /* cookie, first word */
178 *p
++ = xdr_one
; /* cookie, second word */
179 *p
++ = xdr_one
; /* entry len */
180 memcpy(p
, ".\0\0\0", 4); /* entry */
182 *p
++ = xdr_one
; /* bitmap length */
183 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
184 *p
++ = htonl(8); /* attribute buffer length */
185 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
188 *p
++ = xdr_one
; /* next */
189 *p
++ = xdr_zero
; /* cookie, first word */
190 *p
++ = xdr_two
; /* cookie, second word */
191 *p
++ = xdr_two
; /* entry len */
192 memcpy(p
, "..\0\0", 4); /* entry */
194 *p
++ = xdr_one
; /* bitmap length */
195 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
196 *p
++ = htonl(8); /* attribute buffer length */
197 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
199 readdir
->pgbase
= (char *)p
- (char *)start
;
200 readdir
->count
-= readdir
->pgbase
;
201 kunmap_atomic(start
, KM_USER0
);
204 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
210 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
211 nfs_wait_bit_killable
, TASK_KILLABLE
);
215 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
222 *timeout
= NFS4_POLL_RETRY_MIN
;
223 if (*timeout
> NFS4_POLL_RETRY_MAX
)
224 *timeout
= NFS4_POLL_RETRY_MAX
;
225 schedule_timeout_killable(*timeout
);
226 if (fatal_signal_pending(current
))
232 /* This is the error handling routine for processes that are allowed
235 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
237 struct nfs_client
*clp
= server
->nfs_client
;
238 struct nfs4_state
*state
= exception
->state
;
241 exception
->retry
= 0;
245 case -NFS4ERR_ADMIN_REVOKED
:
246 case -NFS4ERR_BAD_STATEID
:
247 case -NFS4ERR_OPENMODE
:
250 nfs4_state_mark_reclaim_nograce(clp
, state
);
251 case -NFS4ERR_STALE_CLIENTID
:
252 case -NFS4ERR_STALE_STATEID
:
253 case -NFS4ERR_EXPIRED
:
254 nfs4_schedule_state_recovery(clp
);
255 ret
= nfs4_wait_clnt_recover(clp
);
257 exception
->retry
= 1;
258 #if !defined(CONFIG_NFS_V4_1)
260 #else /* !defined(CONFIG_NFS_V4_1) */
261 if (!nfs4_has_session(server
->nfs_client
))
264 case -NFS4ERR_BADSESSION
:
265 case -NFS4ERR_BADSLOT
:
266 case -NFS4ERR_BAD_HIGH_SLOT
:
267 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
268 case -NFS4ERR_DEADSESSION
:
269 case -NFS4ERR_SEQ_FALSE_RETRY
:
270 case -NFS4ERR_SEQ_MISORDERED
:
271 dprintk("%s ERROR: %d Reset session\n", __func__
,
273 nfs4_schedule_state_recovery(clp
);
274 exception
->retry
= 1;
276 #endif /* !defined(CONFIG_NFS_V4_1) */
277 case -NFS4ERR_FILE_OPEN
:
278 if (exception
->timeout
> HZ
) {
279 /* We have retried a decent amount, time to
287 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
290 case -NFS4ERR_OLD_STATEID
:
291 exception
->retry
= 1;
293 /* We failed to handle the error */
294 return nfs4_map_errors(ret
);
298 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
300 struct nfs_client
*clp
= server
->nfs_client
;
301 spin_lock(&clp
->cl_lock
);
302 if (time_before(clp
->cl_last_renewal
,timestamp
))
303 clp
->cl_last_renewal
= timestamp
;
304 spin_unlock(&clp
->cl_lock
);
307 #if defined(CONFIG_NFS_V4_1)
310 * nfs4_free_slot - free a slot and efficiently update slot table.
312 * freeing a slot is trivially done by clearing its respective bit
314 * If the freed slotid equals highest_used_slotid we want to update it
315 * so that the server would be able to size down the slot table if needed,
316 * otherwise we know that the highest_used_slotid is still in use.
317 * When updating highest_used_slotid there may be "holes" in the bitmap
318 * so we need to scan down from highest_used_slotid to 0 looking for the now
319 * highest slotid in use.
320 * If none found, highest_used_slotid is set to -1.
322 * Must be called while holding tbl->slot_tbl_lock
325 nfs4_free_slot(struct nfs4_slot_table
*tbl
, u8 free_slotid
)
327 int slotid
= free_slotid
;
329 /* clear used bit in bitmap */
330 __clear_bit(slotid
, tbl
->used_slots
);
332 /* update highest_used_slotid when it is freed */
333 if (slotid
== tbl
->highest_used_slotid
) {
334 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
335 if (slotid
< tbl
->max_slots
)
336 tbl
->highest_used_slotid
= slotid
;
338 tbl
->highest_used_slotid
= -1;
340 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
341 free_slotid
, tbl
->highest_used_slotid
);
345 * Signal state manager thread if session is drained
347 static void nfs41_check_drain_session_complete(struct nfs4_session
*ses
)
349 if (!test_bit(NFS4CLNT_SESSION_DRAINING
, &ses
->clp
->cl_state
)) {
350 rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
354 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
357 dprintk("%s COMPLETE: Session Drained\n", __func__
);
358 complete(&ses
->complete
);
361 static void nfs41_sequence_free_slot(const struct nfs_client
*clp
,
362 struct nfs4_sequence_res
*res
)
364 struct nfs4_slot_table
*tbl
;
366 tbl
= &clp
->cl_session
->fc_slot_table
;
367 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
) {
368 /* just wake up the next guy waiting since
369 * we may have not consumed a slot after all */
370 dprintk("%s: No slot\n", __func__
);
374 spin_lock(&tbl
->slot_tbl_lock
);
375 nfs4_free_slot(tbl
, res
->sr_slotid
);
376 nfs41_check_drain_session_complete(clp
->cl_session
);
377 spin_unlock(&tbl
->slot_tbl_lock
);
378 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
381 static void nfs41_sequence_done(struct nfs_client
*clp
,
382 struct nfs4_sequence_res
*res
,
385 unsigned long timestamp
;
386 struct nfs4_slot_table
*tbl
;
387 struct nfs4_slot
*slot
;
390 * sr_status remains 1 if an RPC level error occurred. The server
391 * may or may not have processed the sequence operation..
392 * Proceed as if the server received and processed the sequence
395 if (res
->sr_status
== 1)
396 res
->sr_status
= NFS_OK
;
398 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
399 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
)
402 /* Check the SEQUENCE operation status */
403 if (res
->sr_status
== 0) {
404 tbl
= &clp
->cl_session
->fc_slot_table
;
405 slot
= tbl
->slots
+ res
->sr_slotid
;
406 /* Update the slot's sequence and clientid lease timer */
408 timestamp
= res
->sr_renewal_time
;
409 spin_lock(&clp
->cl_lock
);
410 if (time_before(clp
->cl_last_renewal
, timestamp
))
411 clp
->cl_last_renewal
= timestamp
;
412 spin_unlock(&clp
->cl_lock
);
413 /* Check sequence flags */
414 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
417 /* The session may be reset by one of the error handlers. */
418 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
419 nfs41_sequence_free_slot(clp
, res
);
423 * nfs4_find_slot - efficiently look for a free slot
425 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
426 * If found, we mark the slot as used, update the highest_used_slotid,
427 * and respectively set up the sequence operation args.
428 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
430 * Note: must be called with under the slot_tbl_lock.
433 nfs4_find_slot(struct nfs4_slot_table
*tbl
, struct rpc_task
*task
)
436 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
437 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
439 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
440 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
442 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
443 if (slotid
>= tbl
->max_slots
)
445 __set_bit(slotid
, tbl
->used_slots
);
446 if (slotid
> tbl
->highest_used_slotid
)
447 tbl
->highest_used_slotid
= slotid
;
450 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
451 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
455 static int nfs41_setup_sequence(struct nfs4_session
*session
,
456 struct nfs4_sequence_args
*args
,
457 struct nfs4_sequence_res
*res
,
459 struct rpc_task
*task
)
461 struct nfs4_slot
*slot
;
462 struct nfs4_slot_table
*tbl
;
465 dprintk("--> %s\n", __func__
);
466 /* slot already allocated? */
467 if (res
->sr_slotid
!= NFS4_MAX_SLOT_TABLE
)
470 memset(res
, 0, sizeof(*res
));
471 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
472 tbl
= &session
->fc_slot_table
;
474 spin_lock(&tbl
->slot_tbl_lock
);
475 if (test_bit(NFS4CLNT_SESSION_DRAINING
, &session
->clp
->cl_state
)) {
477 * The state manager will wait until the slot table is empty.
478 * Schedule the reset thread
480 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
481 spin_unlock(&tbl
->slot_tbl_lock
);
482 dprintk("%s Schedule Session Reset\n", __func__
);
486 slotid
= nfs4_find_slot(tbl
, task
);
487 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
488 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
489 spin_unlock(&tbl
->slot_tbl_lock
);
490 dprintk("<-- %s: no free slots\n", __func__
);
493 spin_unlock(&tbl
->slot_tbl_lock
);
495 slot
= tbl
->slots
+ slotid
;
496 args
->sa_session
= session
;
497 args
->sa_slotid
= slotid
;
498 args
->sa_cache_this
= cache_reply
;
500 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
502 res
->sr_session
= session
;
503 res
->sr_slotid
= slotid
;
504 res
->sr_renewal_time
= jiffies
;
506 * sr_status is only set in decode_sequence, and so will remain
507 * set to 1 if an rpc level failure occurs.
513 int nfs4_setup_sequence(struct nfs_client
*clp
,
514 struct nfs4_sequence_args
*args
,
515 struct nfs4_sequence_res
*res
,
517 struct rpc_task
*task
)
521 dprintk("--> %s clp %p session %p sr_slotid %d\n",
522 __func__
, clp
, clp
->cl_session
, res
->sr_slotid
);
524 if (!nfs4_has_session(clp
))
526 ret
= nfs41_setup_sequence(clp
->cl_session
, args
, res
, cache_reply
,
528 if (ret
&& ret
!= -EAGAIN
) {
529 /* terminate rpc task */
530 task
->tk_status
= ret
;
531 task
->tk_action
= NULL
;
534 dprintk("<-- %s status=%d\n", __func__
, ret
);
538 struct nfs41_call_sync_data
{
539 struct nfs_client
*clp
;
540 struct nfs4_sequence_args
*seq_args
;
541 struct nfs4_sequence_res
*seq_res
;
545 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
547 struct nfs41_call_sync_data
*data
= calldata
;
549 dprintk("--> %s data->clp->cl_session %p\n", __func__
,
550 data
->clp
->cl_session
);
551 if (nfs4_setup_sequence(data
->clp
, data
->seq_args
,
552 data
->seq_res
, data
->cache_reply
, task
))
554 rpc_call_start(task
);
557 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
559 struct nfs41_call_sync_data
*data
= calldata
;
561 nfs41_sequence_done(data
->clp
, data
->seq_res
, task
->tk_status
);
564 struct rpc_call_ops nfs41_call_sync_ops
= {
565 .rpc_call_prepare
= nfs41_call_sync_prepare
,
566 .rpc_call_done
= nfs41_call_sync_done
,
569 static int nfs4_call_sync_sequence(struct nfs_client
*clp
,
570 struct rpc_clnt
*clnt
,
571 struct rpc_message
*msg
,
572 struct nfs4_sequence_args
*args
,
573 struct nfs4_sequence_res
*res
,
577 struct rpc_task
*task
;
578 struct nfs41_call_sync_data data
= {
582 .cache_reply
= cache_reply
,
584 struct rpc_task_setup task_setup
= {
587 .callback_ops
= &nfs41_call_sync_ops
,
588 .callback_data
= &data
591 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
592 task
= rpc_run_task(&task_setup
);
596 ret
= task
->tk_status
;
602 int _nfs4_call_sync_session(struct nfs_server
*server
,
603 struct rpc_message
*msg
,
604 struct nfs4_sequence_args
*args
,
605 struct nfs4_sequence_res
*res
,
608 return nfs4_call_sync_sequence(server
->nfs_client
, server
->client
,
609 msg
, args
, res
, cache_reply
);
612 #endif /* CONFIG_NFS_V4_1 */
614 int _nfs4_call_sync(struct nfs_server
*server
,
615 struct rpc_message
*msg
,
616 struct nfs4_sequence_args
*args
,
617 struct nfs4_sequence_res
*res
,
620 args
->sa_session
= res
->sr_session
= NULL
;
621 return rpc_call_sync(server
->client
, msg
, 0);
624 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
625 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
626 &(res)->seq_res, (cache_reply))
628 static void nfs4_sequence_done(const struct nfs_server
*server
,
629 struct nfs4_sequence_res
*res
, int rpc_status
)
631 #ifdef CONFIG_NFS_V4_1
632 if (nfs4_has_session(server
->nfs_client
))
633 nfs41_sequence_done(server
->nfs_client
, res
, rpc_status
);
634 #endif /* CONFIG_NFS_V4_1 */
637 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
639 struct nfs_inode
*nfsi
= NFS_I(dir
);
641 spin_lock(&dir
->i_lock
);
642 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
643 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
644 nfs_force_lookup_revalidate(dir
);
645 nfsi
->change_attr
= cinfo
->after
;
646 spin_unlock(&dir
->i_lock
);
649 struct nfs4_opendata
{
651 struct nfs_openargs o_arg
;
652 struct nfs_openres o_res
;
653 struct nfs_open_confirmargs c_arg
;
654 struct nfs_open_confirmres c_res
;
655 struct nfs_fattr f_attr
;
656 struct nfs_fattr dir_attr
;
659 struct nfs4_state_owner
*owner
;
660 struct nfs4_state
*state
;
662 unsigned long timestamp
;
663 unsigned int rpc_done
: 1;
669 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
671 p
->o_res
.f_attr
= &p
->f_attr
;
672 p
->o_res
.dir_attr
= &p
->dir_attr
;
673 p
->o_res
.seqid
= p
->o_arg
.seqid
;
674 p
->c_res
.seqid
= p
->c_arg
.seqid
;
675 p
->o_res
.server
= p
->o_arg
.server
;
676 nfs_fattr_init(&p
->f_attr
);
677 nfs_fattr_init(&p
->dir_attr
);
678 p
->o_res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
681 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
682 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
683 const struct iattr
*attrs
)
685 struct dentry
*parent
= dget_parent(path
->dentry
);
686 struct inode
*dir
= parent
->d_inode
;
687 struct nfs_server
*server
= NFS_SERVER(dir
);
688 struct nfs4_opendata
*p
;
690 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
693 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
694 if (p
->o_arg
.seqid
== NULL
)
696 p
->path
.mnt
= mntget(path
->mnt
);
697 p
->path
.dentry
= dget(path
->dentry
);
700 atomic_inc(&sp
->so_count
);
701 p
->o_arg
.fh
= NFS_FH(dir
);
702 p
->o_arg
.open_flags
= flags
;
703 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
704 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
705 p
->o_arg
.id
= sp
->so_owner_id
.id
;
706 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
707 p
->o_arg
.server
= server
;
708 p
->o_arg
.bitmask
= server
->attr_bitmask
;
709 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
710 if (flags
& O_EXCL
) {
711 if (nfs4_has_persistent_session(server
->nfs_client
)) {
713 p
->o_arg
.u
.attrs
= &p
->attrs
;
714 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
715 } else { /* EXCLUSIVE4_1 */
716 u32
*s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
720 } else if (flags
& O_CREAT
) {
721 p
->o_arg
.u
.attrs
= &p
->attrs
;
722 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
724 p
->c_arg
.fh
= &p
->o_res
.fh
;
725 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
726 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
727 nfs4_init_opendata_res(p
);
737 static void nfs4_opendata_free(struct kref
*kref
)
739 struct nfs4_opendata
*p
= container_of(kref
,
740 struct nfs4_opendata
, kref
);
742 nfs_free_seqid(p
->o_arg
.seqid
);
743 if (p
->state
!= NULL
)
744 nfs4_put_open_state(p
->state
);
745 nfs4_put_state_owner(p
->owner
);
751 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
754 kref_put(&p
->kref
, nfs4_opendata_free
);
757 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
761 ret
= rpc_wait_for_completion_task(task
);
765 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
769 if (open_mode
& O_EXCL
)
771 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
773 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
774 && state
->n_rdonly
!= 0;
777 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
778 && state
->n_wronly
!= 0;
780 case FMODE_READ
|FMODE_WRITE
:
781 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
782 && state
->n_rdwr
!= 0;
788 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
790 if ((delegation
->type
& fmode
) != fmode
)
792 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
794 nfs_mark_delegation_referenced(delegation
);
798 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
807 case FMODE_READ
|FMODE_WRITE
:
810 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
813 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
815 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
816 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
817 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
820 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
823 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
825 case FMODE_READ
|FMODE_WRITE
:
826 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
830 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
832 write_seqlock(&state
->seqlock
);
833 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
834 write_sequnlock(&state
->seqlock
);
837 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
840 * Protect the call to nfs4_state_set_mode_locked and
841 * serialise the stateid update
843 write_seqlock(&state
->seqlock
);
844 if (deleg_stateid
!= NULL
) {
845 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
846 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
848 if (open_stateid
!= NULL
)
849 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
850 write_sequnlock(&state
->seqlock
);
851 spin_lock(&state
->owner
->so_lock
);
852 update_open_stateflags(state
, fmode
);
853 spin_unlock(&state
->owner
->so_lock
);
856 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
858 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
859 struct nfs_delegation
*deleg_cur
;
862 fmode
&= (FMODE_READ
|FMODE_WRITE
);
865 deleg_cur
= rcu_dereference(nfsi
->delegation
);
866 if (deleg_cur
== NULL
)
869 spin_lock(&deleg_cur
->lock
);
870 if (nfsi
->delegation
!= deleg_cur
||
871 (deleg_cur
->type
& fmode
) != fmode
)
872 goto no_delegation_unlock
;
874 if (delegation
== NULL
)
875 delegation
= &deleg_cur
->stateid
;
876 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
877 goto no_delegation_unlock
;
879 nfs_mark_delegation_referenced(deleg_cur
);
880 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
882 no_delegation_unlock
:
883 spin_unlock(&deleg_cur
->lock
);
887 if (!ret
&& open_stateid
!= NULL
) {
888 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
896 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
898 struct nfs_delegation
*delegation
;
901 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
902 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
907 nfs_inode_return_delegation(inode
);
910 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
912 struct nfs4_state
*state
= opendata
->state
;
913 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
914 struct nfs_delegation
*delegation
;
915 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
916 fmode_t fmode
= opendata
->o_arg
.fmode
;
917 nfs4_stateid stateid
;
921 if (can_open_cached(state
, fmode
, open_mode
)) {
922 spin_lock(&state
->owner
->so_lock
);
923 if (can_open_cached(state
, fmode
, open_mode
)) {
924 update_open_stateflags(state
, fmode
);
925 spin_unlock(&state
->owner
->so_lock
);
926 goto out_return_state
;
928 spin_unlock(&state
->owner
->so_lock
);
931 delegation
= rcu_dereference(nfsi
->delegation
);
932 if (delegation
== NULL
||
933 !can_open_delegated(delegation
, fmode
)) {
937 /* Save the delegation */
938 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
940 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
945 /* Try to update the stateid using the delegation */
946 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
947 goto out_return_state
;
952 atomic_inc(&state
->count
);
956 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
959 struct nfs4_state
*state
= NULL
;
960 struct nfs_delegation
*delegation
;
963 if (!data
->rpc_done
) {
964 state
= nfs4_try_open_cached(data
);
969 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
971 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
972 ret
= PTR_ERR(inode
);
976 state
= nfs4_get_open_state(inode
, data
->owner
);
979 if (data
->o_res
.delegation_type
!= 0) {
980 int delegation_flags
= 0;
983 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
985 delegation_flags
= delegation
->flags
;
987 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
988 nfs_inode_set_delegation(state
->inode
,
989 data
->owner
->so_cred
,
992 nfs_inode_reclaim_delegation(state
->inode
,
993 data
->owner
->so_cred
,
997 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1005 return ERR_PTR(ret
);
1008 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1010 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1011 struct nfs_open_context
*ctx
;
1013 spin_lock(&state
->inode
->i_lock
);
1014 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1015 if (ctx
->state
!= state
)
1017 get_nfs_open_context(ctx
);
1018 spin_unlock(&state
->inode
->i_lock
);
1021 spin_unlock(&state
->inode
->i_lock
);
1022 return ERR_PTR(-ENOENT
);
1025 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1027 struct nfs4_opendata
*opendata
;
1029 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
);
1030 if (opendata
== NULL
)
1031 return ERR_PTR(-ENOMEM
);
1032 opendata
->state
= state
;
1033 atomic_inc(&state
->count
);
1037 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1039 struct nfs4_state
*newstate
;
1042 opendata
->o_arg
.open_flags
= 0;
1043 opendata
->o_arg
.fmode
= fmode
;
1044 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1045 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1046 nfs4_init_opendata_res(opendata
);
1047 ret
= _nfs4_proc_open(opendata
);
1050 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1051 if (IS_ERR(newstate
))
1052 return PTR_ERR(newstate
);
1053 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1058 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1060 struct nfs4_state
*newstate
;
1063 /* memory barrier prior to reading state->n_* */
1064 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1066 if (state
->n_rdwr
!= 0) {
1067 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1070 if (newstate
!= state
)
1073 if (state
->n_wronly
!= 0) {
1074 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1077 if (newstate
!= state
)
1080 if (state
->n_rdonly
!= 0) {
1081 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1084 if (newstate
!= state
)
1088 * We may have performed cached opens for all three recoveries.
1089 * Check if we need to update the current stateid.
1091 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1092 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1093 write_seqlock(&state
->seqlock
);
1094 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1095 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1096 write_sequnlock(&state
->seqlock
);
1103 * reclaim state on the server after a reboot.
1105 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1107 struct nfs_delegation
*delegation
;
1108 struct nfs4_opendata
*opendata
;
1109 fmode_t delegation_type
= 0;
1112 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1113 if (IS_ERR(opendata
))
1114 return PTR_ERR(opendata
);
1115 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1116 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1118 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1119 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1120 delegation_type
= delegation
->type
;
1122 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1123 status
= nfs4_open_recover(opendata
, state
);
1124 nfs4_opendata_put(opendata
);
1128 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1130 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1131 struct nfs4_exception exception
= { };
1134 err
= _nfs4_do_open_reclaim(ctx
, state
);
1135 if (err
!= -NFS4ERR_DELAY
)
1137 nfs4_handle_exception(server
, err
, &exception
);
1138 } while (exception
.retry
);
1142 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1144 struct nfs_open_context
*ctx
;
1147 ctx
= nfs4_state_find_open_context(state
);
1149 return PTR_ERR(ctx
);
1150 ret
= nfs4_do_open_reclaim(ctx
, state
);
1151 put_nfs_open_context(ctx
);
1155 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1157 struct nfs4_opendata
*opendata
;
1160 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1161 if (IS_ERR(opendata
))
1162 return PTR_ERR(opendata
);
1163 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1164 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1165 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1166 ret
= nfs4_open_recover(opendata
, state
);
1167 nfs4_opendata_put(opendata
);
1171 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1173 struct nfs4_exception exception
= { };
1174 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1177 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1183 case -NFS4ERR_BADSESSION
:
1184 case -NFS4ERR_BADSLOT
:
1185 case -NFS4ERR_BAD_HIGH_SLOT
:
1186 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1187 case -NFS4ERR_DEADSESSION
:
1188 nfs4_schedule_state_recovery(
1189 server
->nfs_client
);
1191 case -NFS4ERR_STALE_CLIENTID
:
1192 case -NFS4ERR_STALE_STATEID
:
1193 case -NFS4ERR_EXPIRED
:
1194 /* Don't recall a delegation if it was lost */
1195 nfs4_schedule_state_recovery(server
->nfs_client
);
1199 * The show must go on: exit, but mark the
1200 * stateid as needing recovery.
1202 case -NFS4ERR_ADMIN_REVOKED
:
1203 case -NFS4ERR_BAD_STATEID
:
1204 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
1209 err
= nfs4_handle_exception(server
, err
, &exception
);
1210 } while (exception
.retry
);
1215 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1217 struct nfs4_opendata
*data
= calldata
;
1219 data
->rpc_status
= task
->tk_status
;
1220 if (RPC_ASSASSINATED(task
))
1222 if (data
->rpc_status
== 0) {
1223 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1224 sizeof(data
->o_res
.stateid
.data
));
1225 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1226 renew_lease(data
->o_res
.server
, data
->timestamp
);
1231 static void nfs4_open_confirm_release(void *calldata
)
1233 struct nfs4_opendata
*data
= calldata
;
1234 struct nfs4_state
*state
= NULL
;
1236 /* If this request hasn't been cancelled, do nothing */
1237 if (data
->cancelled
== 0)
1239 /* In case of error, no cleanup! */
1240 if (!data
->rpc_done
)
1242 state
= nfs4_opendata_to_nfs4_state(data
);
1244 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1246 nfs4_opendata_put(data
);
1249 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1250 .rpc_call_done
= nfs4_open_confirm_done
,
1251 .rpc_release
= nfs4_open_confirm_release
,
1255 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1257 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1259 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1260 struct rpc_task
*task
;
1261 struct rpc_message msg
= {
1262 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1263 .rpc_argp
= &data
->c_arg
,
1264 .rpc_resp
= &data
->c_res
,
1265 .rpc_cred
= data
->owner
->so_cred
,
1267 struct rpc_task_setup task_setup_data
= {
1268 .rpc_client
= server
->client
,
1269 .rpc_message
= &msg
,
1270 .callback_ops
= &nfs4_open_confirm_ops
,
1271 .callback_data
= data
,
1272 .workqueue
= nfsiod_workqueue
,
1273 .flags
= RPC_TASK_ASYNC
,
1277 kref_get(&data
->kref
);
1279 data
->rpc_status
= 0;
1280 data
->timestamp
= jiffies
;
1281 task
= rpc_run_task(&task_setup_data
);
1283 return PTR_ERR(task
);
1284 status
= nfs4_wait_for_completion_rpc_task(task
);
1286 data
->cancelled
= 1;
1289 status
= data
->rpc_status
;
1294 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1296 struct nfs4_opendata
*data
= calldata
;
1297 struct nfs4_state_owner
*sp
= data
->owner
;
1299 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1302 * Check if we still need to send an OPEN call, or if we can use
1303 * a delegation instead.
1305 if (data
->state
!= NULL
) {
1306 struct nfs_delegation
*delegation
;
1308 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1311 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1312 if (delegation
!= NULL
&&
1313 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1319 /* Update sequence id. */
1320 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1321 data
->o_arg
.clientid
= sp
->so_client
->cl_clientid
;
1322 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1323 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1324 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1326 data
->timestamp
= jiffies
;
1327 if (nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
1328 &data
->o_arg
.seq_args
,
1329 &data
->o_res
.seq_res
, 1, task
))
1331 rpc_call_start(task
);
1334 task
->tk_action
= NULL
;
1338 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1340 struct nfs4_opendata
*data
= calldata
;
1342 data
->rpc_status
= task
->tk_status
;
1344 nfs4_sequence_done(data
->o_arg
.server
, &data
->o_res
.seq_res
,
1347 if (RPC_ASSASSINATED(task
))
1349 if (task
->tk_status
== 0) {
1350 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1354 data
->rpc_status
= -ELOOP
;
1357 data
->rpc_status
= -EISDIR
;
1360 data
->rpc_status
= -ENOTDIR
;
1362 renew_lease(data
->o_res
.server
, data
->timestamp
);
1363 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1364 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1369 static void nfs4_open_release(void *calldata
)
1371 struct nfs4_opendata
*data
= calldata
;
1372 struct nfs4_state
*state
= NULL
;
1374 /* If this request hasn't been cancelled, do nothing */
1375 if (data
->cancelled
== 0)
1377 /* In case of error, no cleanup! */
1378 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1380 /* In case we need an open_confirm, no cleanup! */
1381 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1383 state
= nfs4_opendata_to_nfs4_state(data
);
1385 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1387 nfs4_opendata_put(data
);
1390 static const struct rpc_call_ops nfs4_open_ops
= {
1391 .rpc_call_prepare
= nfs4_open_prepare
,
1392 .rpc_call_done
= nfs4_open_done
,
1393 .rpc_release
= nfs4_open_release
,
1397 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1399 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1401 struct inode
*dir
= data
->dir
->d_inode
;
1402 struct nfs_server
*server
= NFS_SERVER(dir
);
1403 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1404 struct nfs_openres
*o_res
= &data
->o_res
;
1405 struct rpc_task
*task
;
1406 struct rpc_message msg
= {
1407 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1410 .rpc_cred
= data
->owner
->so_cred
,
1412 struct rpc_task_setup task_setup_data
= {
1413 .rpc_client
= server
->client
,
1414 .rpc_message
= &msg
,
1415 .callback_ops
= &nfs4_open_ops
,
1416 .callback_data
= data
,
1417 .workqueue
= nfsiod_workqueue
,
1418 .flags
= RPC_TASK_ASYNC
,
1422 kref_get(&data
->kref
);
1424 data
->rpc_status
= 0;
1425 data
->cancelled
= 0;
1426 task
= rpc_run_task(&task_setup_data
);
1428 return PTR_ERR(task
);
1429 status
= nfs4_wait_for_completion_rpc_task(task
);
1431 data
->cancelled
= 1;
1434 status
= data
->rpc_status
;
1436 if (status
!= 0 || !data
->rpc_done
)
1439 if (o_arg
->open_flags
& O_CREAT
) {
1440 update_changeattr(dir
, &o_res
->cinfo
);
1441 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1443 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1444 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1445 status
= _nfs4_proc_open_confirm(data
);
1449 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1450 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1454 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1456 struct nfs_client
*clp
= server
->nfs_client
;
1460 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1461 ret
= nfs4_wait_clnt_recover(clp
);
1464 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1465 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1467 nfs4_schedule_state_recovery(clp
);
1475 * reclaim state on the server after a network partition.
1476 * Assumes caller holds the appropriate lock
1478 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1480 struct nfs4_opendata
*opendata
;
1483 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1484 if (IS_ERR(opendata
))
1485 return PTR_ERR(opendata
);
1486 ret
= nfs4_open_recover(opendata
, state
);
1488 d_drop(ctx
->path
.dentry
);
1489 nfs4_opendata_put(opendata
);
1493 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1495 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1496 struct nfs4_exception exception
= { };
1500 err
= _nfs4_open_expired(ctx
, state
);
1504 case -NFS4ERR_GRACE
:
1505 case -NFS4ERR_DELAY
:
1506 nfs4_handle_exception(server
, err
, &exception
);
1509 } while (exception
.retry
);
1514 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1516 struct nfs_open_context
*ctx
;
1519 ctx
= nfs4_state_find_open_context(state
);
1521 return PTR_ERR(ctx
);
1522 ret
= nfs4_do_open_expired(ctx
, state
);
1523 put_nfs_open_context(ctx
);
1528 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1529 * fields corresponding to attributes that were used to store the verifier.
1530 * Make sure we clobber those fields in the later setattr call
1532 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1534 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1535 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1536 sattr
->ia_valid
|= ATTR_ATIME
;
1538 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1539 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1540 sattr
->ia_valid
|= ATTR_MTIME
;
1544 * Returns a referenced nfs4_state
1546 static int _nfs4_do_open(struct inode
*dir
, struct path
*path
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
1548 struct nfs4_state_owner
*sp
;
1549 struct nfs4_state
*state
= NULL
;
1550 struct nfs_server
*server
= NFS_SERVER(dir
);
1551 struct nfs4_opendata
*opendata
;
1554 /* Protect against reboot recovery conflicts */
1556 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1557 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1560 status
= nfs4_recover_expired_lease(server
);
1562 goto err_put_state_owner
;
1563 if (path
->dentry
->d_inode
!= NULL
)
1564 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1566 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
);
1567 if (opendata
== NULL
)
1568 goto err_put_state_owner
;
1570 if (path
->dentry
->d_inode
!= NULL
)
1571 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1573 status
= _nfs4_proc_open(opendata
);
1575 goto err_opendata_put
;
1577 if (opendata
->o_arg
.open_flags
& O_EXCL
)
1578 nfs4_exclusive_attrset(opendata
, sattr
);
1580 state
= nfs4_opendata_to_nfs4_state(opendata
);
1581 status
= PTR_ERR(state
);
1583 goto err_opendata_put
;
1584 nfs4_opendata_put(opendata
);
1585 nfs4_put_state_owner(sp
);
1589 nfs4_opendata_put(opendata
);
1590 err_put_state_owner
:
1591 nfs4_put_state_owner(sp
);
1598 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct path
*path
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
1600 struct nfs4_exception exception
= { };
1601 struct nfs4_state
*res
;
1605 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1608 /* NOTE: BAD_SEQID means the server and client disagree about the
1609 * book-keeping w.r.t. state-changing operations
1610 * (OPEN/CLOSE/LOCK/LOCKU...)
1611 * It is actually a sign of a bug on the client or on the server.
1613 * If we receive a BAD_SEQID error in the particular case of
1614 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1615 * have unhashed the old state_owner for us, and that we can
1616 * therefore safely retry using a new one. We should still warn
1617 * the user though...
1619 if (status
== -NFS4ERR_BAD_SEQID
) {
1620 printk(KERN_WARNING
"NFS: v4 server %s "
1621 " returned a bad sequence-id error!\n",
1622 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1623 exception
.retry
= 1;
1627 * BAD_STATEID on OPEN means that the server cancelled our
1628 * state before it received the OPEN_CONFIRM.
1629 * Recover by retrying the request as per the discussion
1630 * on Page 181 of RFC3530.
1632 if (status
== -NFS4ERR_BAD_STATEID
) {
1633 exception
.retry
= 1;
1636 if (status
== -EAGAIN
) {
1637 /* We must have found a delegation */
1638 exception
.retry
= 1;
1641 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1642 status
, &exception
));
1643 } while (exception
.retry
);
1647 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1648 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1649 struct nfs4_state
*state
)
1651 struct nfs_server
*server
= NFS_SERVER(inode
);
1652 struct nfs_setattrargs arg
= {
1653 .fh
= NFS_FH(inode
),
1656 .bitmask
= server
->attr_bitmask
,
1658 struct nfs_setattrres res
= {
1662 struct rpc_message msg
= {
1663 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1668 unsigned long timestamp
= jiffies
;
1671 nfs_fattr_init(fattr
);
1673 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1674 /* Use that stateid */
1675 } else if (state
!= NULL
) {
1676 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
1678 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1680 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
1681 if (status
== 0 && state
!= NULL
)
1682 renew_lease(server
, timestamp
);
1686 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1687 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1688 struct nfs4_state
*state
)
1690 struct nfs_server
*server
= NFS_SERVER(inode
);
1691 struct nfs4_exception exception
= { };
1694 err
= nfs4_handle_exception(server
,
1695 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1697 } while (exception
.retry
);
1701 struct nfs4_closedata
{
1703 struct inode
*inode
;
1704 struct nfs4_state
*state
;
1705 struct nfs_closeargs arg
;
1706 struct nfs_closeres res
;
1707 struct nfs_fattr fattr
;
1708 unsigned long timestamp
;
1711 static void nfs4_free_closedata(void *data
)
1713 struct nfs4_closedata
*calldata
= data
;
1714 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1716 nfs4_put_open_state(calldata
->state
);
1717 nfs_free_seqid(calldata
->arg
.seqid
);
1718 nfs4_put_state_owner(sp
);
1719 path_put(&calldata
->path
);
1723 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1726 spin_lock(&state
->owner
->so_lock
);
1727 if (!(fmode
& FMODE_READ
))
1728 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1729 if (!(fmode
& FMODE_WRITE
))
1730 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1731 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1732 spin_unlock(&state
->owner
->so_lock
);
1735 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1737 struct nfs4_closedata
*calldata
= data
;
1738 struct nfs4_state
*state
= calldata
->state
;
1739 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1741 nfs4_sequence_done(server
, &calldata
->res
.seq_res
, task
->tk_status
);
1742 if (RPC_ASSASSINATED(task
))
1744 /* hmm. we are done with the inode, and in the process of freeing
1745 * the state_owner. we keep this around to process errors
1747 switch (task
->tk_status
) {
1749 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1750 renew_lease(server
, calldata
->timestamp
);
1751 nfs4_close_clear_stateid_flags(state
,
1752 calldata
->arg
.fmode
);
1754 case -NFS4ERR_STALE_STATEID
:
1755 case -NFS4ERR_OLD_STATEID
:
1756 case -NFS4ERR_BAD_STATEID
:
1757 case -NFS4ERR_EXPIRED
:
1758 if (calldata
->arg
.fmode
== 0)
1761 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
) {
1762 nfs_restart_rpc(task
, server
->nfs_client
);
1766 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1769 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1771 struct nfs4_closedata
*calldata
= data
;
1772 struct nfs4_state
*state
= calldata
->state
;
1775 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1778 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1779 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1780 spin_lock(&state
->owner
->so_lock
);
1781 /* Calculate the change in open mode */
1782 if (state
->n_rdwr
== 0) {
1783 if (state
->n_rdonly
== 0) {
1784 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1785 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1786 calldata
->arg
.fmode
&= ~FMODE_READ
;
1788 if (state
->n_wronly
== 0) {
1789 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1790 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1791 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1794 spin_unlock(&state
->owner
->so_lock
);
1797 /* Note: exit _without_ calling nfs4_close_done */
1798 task
->tk_action
= NULL
;
1802 if (calldata
->arg
.fmode
== 0)
1803 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
1805 nfs_fattr_init(calldata
->res
.fattr
);
1806 calldata
->timestamp
= jiffies
;
1807 if (nfs4_setup_sequence((NFS_SERVER(calldata
->inode
))->nfs_client
,
1808 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1811 rpc_call_start(task
);
1814 static const struct rpc_call_ops nfs4_close_ops
= {
1815 .rpc_call_prepare
= nfs4_close_prepare
,
1816 .rpc_call_done
= nfs4_close_done
,
1817 .rpc_release
= nfs4_free_closedata
,
1821 * It is possible for data to be read/written from a mem-mapped file
1822 * after the sys_close call (which hits the vfs layer as a flush).
1823 * This means that we can't safely call nfsv4 close on a file until
1824 * the inode is cleared. This in turn means that we are not good
1825 * NFSv4 citizens - we do not indicate to the server to update the file's
1826 * share state even when we are done with one of the three share
1827 * stateid's in the inode.
1829 * NOTE: Caller must be holding the sp->so_owner semaphore!
1831 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, int wait
)
1833 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1834 struct nfs4_closedata
*calldata
;
1835 struct nfs4_state_owner
*sp
= state
->owner
;
1836 struct rpc_task
*task
;
1837 struct rpc_message msg
= {
1838 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1839 .rpc_cred
= state
->owner
->so_cred
,
1841 struct rpc_task_setup task_setup_data
= {
1842 .rpc_client
= server
->client
,
1843 .rpc_message
= &msg
,
1844 .callback_ops
= &nfs4_close_ops
,
1845 .workqueue
= nfsiod_workqueue
,
1846 .flags
= RPC_TASK_ASYNC
,
1848 int status
= -ENOMEM
;
1850 calldata
= kzalloc(sizeof(*calldata
), GFP_KERNEL
);
1851 if (calldata
== NULL
)
1853 calldata
->inode
= state
->inode
;
1854 calldata
->state
= state
;
1855 calldata
->arg
.fh
= NFS_FH(state
->inode
);
1856 calldata
->arg
.stateid
= &state
->open_stateid
;
1857 if (nfs4_has_session(server
->nfs_client
))
1858 memset(calldata
->arg
.stateid
->data
, 0, 4); /* clear seqid */
1859 /* Serialization for the sequence id */
1860 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
1861 if (calldata
->arg
.seqid
== NULL
)
1862 goto out_free_calldata
;
1863 calldata
->arg
.fmode
= 0;
1864 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
1865 calldata
->res
.fattr
= &calldata
->fattr
;
1866 calldata
->res
.seqid
= calldata
->arg
.seqid
;
1867 calldata
->res
.server
= server
;
1868 calldata
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
1869 calldata
->path
.mnt
= mntget(path
->mnt
);
1870 calldata
->path
.dentry
= dget(path
->dentry
);
1872 msg
.rpc_argp
= &calldata
->arg
,
1873 msg
.rpc_resp
= &calldata
->res
,
1874 task_setup_data
.callback_data
= calldata
;
1875 task
= rpc_run_task(&task_setup_data
);
1877 return PTR_ERR(task
);
1880 status
= rpc_wait_for_completion_task(task
);
1886 nfs4_put_open_state(state
);
1887 nfs4_put_state_owner(sp
);
1891 static int nfs4_intent_set_file(struct nameidata
*nd
, struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
)
1896 /* If the open_intent is for execute, we have an extra check to make */
1897 if (fmode
& FMODE_EXEC
) {
1898 ret
= nfs_may_open(state
->inode
,
1899 state
->owner
->so_cred
,
1900 nd
->intent
.open
.flags
);
1904 filp
= lookup_instantiate_filp(nd
, path
->dentry
, NULL
);
1905 if (!IS_ERR(filp
)) {
1906 struct nfs_open_context
*ctx
;
1907 ctx
= nfs_file_open_context(filp
);
1911 ret
= PTR_ERR(filp
);
1913 nfs4_close_sync(path
, state
, fmode
& (FMODE_READ
|FMODE_WRITE
));
1918 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
1920 struct path path
= {
1921 .mnt
= nd
->path
.mnt
,
1924 struct dentry
*parent
;
1926 struct rpc_cred
*cred
;
1927 struct nfs4_state
*state
;
1929 fmode_t fmode
= nd
->intent
.open
.flags
& (FMODE_READ
| FMODE_WRITE
| FMODE_EXEC
);
1931 if (nd
->flags
& LOOKUP_CREATE
) {
1932 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
1933 attr
.ia_valid
= ATTR_MODE
;
1934 if (!IS_POSIXACL(dir
))
1935 attr
.ia_mode
&= ~current_umask();
1938 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
1941 cred
= rpc_lookup_cred();
1943 return (struct dentry
*)cred
;
1944 parent
= dentry
->d_parent
;
1945 /* Protect against concurrent sillydeletes */
1946 nfs_block_sillyrename(parent
);
1947 state
= nfs4_do_open(dir
, &path
, fmode
, nd
->intent
.open
.flags
, &attr
, cred
);
1949 if (IS_ERR(state
)) {
1950 if (PTR_ERR(state
) == -ENOENT
) {
1951 d_add(dentry
, NULL
);
1952 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1954 nfs_unblock_sillyrename(parent
);
1955 return (struct dentry
*)state
;
1957 res
= d_add_unique(dentry
, igrab(state
->inode
));
1960 nfs_set_verifier(path
.dentry
, nfs_save_change_attribute(dir
));
1961 nfs_unblock_sillyrename(parent
);
1962 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
1967 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1969 struct path path
= {
1970 .mnt
= nd
->path
.mnt
,
1973 struct rpc_cred
*cred
;
1974 struct nfs4_state
*state
;
1975 fmode_t fmode
= openflags
& (FMODE_READ
| FMODE_WRITE
);
1977 cred
= rpc_lookup_cred();
1979 return PTR_ERR(cred
);
1980 state
= nfs4_do_open(dir
, &path
, fmode
, openflags
, NULL
, cred
);
1982 if (IS_ERR(state
)) {
1983 switch (PTR_ERR(state
)) {
1989 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1995 if (state
->inode
== dentry
->d_inode
) {
1996 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1997 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
2000 nfs4_close_sync(&path
, state
, fmode
);
2006 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2008 if (ctx
->state
== NULL
)
2011 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
2013 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
2016 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2018 struct nfs4_server_caps_arg args
= {
2021 struct nfs4_server_caps_res res
= {};
2022 struct rpc_message msg
= {
2023 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2029 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2031 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2032 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2033 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2034 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2035 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2036 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2037 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2038 server
->caps
|= NFS_CAP_ACLS
;
2039 if (res
.has_links
!= 0)
2040 server
->caps
|= NFS_CAP_HARDLINKS
;
2041 if (res
.has_symlinks
!= 0)
2042 server
->caps
|= NFS_CAP_SYMLINKS
;
2043 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2044 server
->caps
|= NFS_CAP_FILEID
;
2045 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2046 server
->caps
|= NFS_CAP_MODE
;
2047 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2048 server
->caps
|= NFS_CAP_NLINK
;
2049 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2050 server
->caps
|= NFS_CAP_OWNER
;
2051 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2052 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2053 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2054 server
->caps
|= NFS_CAP_ATIME
;
2055 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2056 server
->caps
|= NFS_CAP_CTIME
;
2057 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2058 server
->caps
|= NFS_CAP_MTIME
;
2060 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2061 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2062 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2063 server
->acl_bitmask
= res
.acl_bitmask
;
2069 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2071 struct nfs4_exception exception
= { };
2074 err
= nfs4_handle_exception(server
,
2075 _nfs4_server_capabilities(server
, fhandle
),
2077 } while (exception
.retry
);
2081 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2082 struct nfs_fsinfo
*info
)
2084 struct nfs4_lookup_root_arg args
= {
2085 .bitmask
= nfs4_fattr_bitmap
,
2087 struct nfs4_lookup_res res
= {
2089 .fattr
= info
->fattr
,
2092 struct rpc_message msg
= {
2093 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2098 nfs_fattr_init(info
->fattr
);
2099 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2102 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2103 struct nfs_fsinfo
*info
)
2105 struct nfs4_exception exception
= { };
2108 err
= nfs4_handle_exception(server
,
2109 _nfs4_lookup_root(server
, fhandle
, info
),
2111 } while (exception
.retry
);
2116 * get the file handle for the "/" directory on the server
2118 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2119 struct nfs_fsinfo
*info
)
2123 status
= nfs4_lookup_root(server
, fhandle
, info
);
2125 status
= nfs4_server_capabilities(server
, fhandle
);
2127 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2128 return nfs4_map_errors(status
);
2132 * Get locations and (maybe) other attributes of a referral.
2133 * Note that we'll actually follow the referral later when
2134 * we detect fsid mismatch in inode revalidation
2136 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2138 int status
= -ENOMEM
;
2139 struct page
*page
= NULL
;
2140 struct nfs4_fs_locations
*locations
= NULL
;
2142 page
= alloc_page(GFP_KERNEL
);
2145 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2146 if (locations
== NULL
)
2149 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2152 /* Make sure server returned a different fsid for the referral */
2153 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2154 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2159 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2160 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2162 fattr
->mode
= S_IFDIR
;
2163 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2172 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2174 struct nfs4_getattr_arg args
= {
2176 .bitmask
= server
->attr_bitmask
,
2178 struct nfs4_getattr_res res
= {
2182 struct rpc_message msg
= {
2183 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2188 nfs_fattr_init(fattr
);
2189 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2192 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2194 struct nfs4_exception exception
= { };
2197 err
= nfs4_handle_exception(server
,
2198 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2200 } while (exception
.retry
);
2205 * The file is not closed if it is opened due to the a request to change
2206 * the size of the file. The open call will not be needed once the
2207 * VFS layer lookup-intents are implemented.
2209 * Close is called when the inode is destroyed.
2210 * If we haven't opened the file for O_WRONLY, we
2211 * need to in the size_change case to obtain a stateid.
2214 * Because OPEN is always done by name in nfsv4, it is
2215 * possible that we opened a different file by the same
2216 * name. We can recognize this race condition, but we
2217 * can't do anything about it besides returning an error.
2219 * This will be fixed with VFS changes (lookup-intent).
2222 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2223 struct iattr
*sattr
)
2225 struct inode
*inode
= dentry
->d_inode
;
2226 struct rpc_cred
*cred
= NULL
;
2227 struct nfs4_state
*state
= NULL
;
2230 nfs_fattr_init(fattr
);
2232 /* Search for an existing open(O_WRITE) file */
2233 if (sattr
->ia_valid
& ATTR_FILE
) {
2234 struct nfs_open_context
*ctx
;
2236 ctx
= nfs_file_open_context(sattr
->ia_file
);
2243 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2245 nfs_setattr_update_inode(inode
, sattr
);
2249 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
2250 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2251 struct nfs_fattr
*fattr
)
2254 struct nfs4_lookup_arg args
= {
2255 .bitmask
= server
->attr_bitmask
,
2259 struct nfs4_lookup_res res
= {
2264 struct rpc_message msg
= {
2265 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2270 nfs_fattr_init(fattr
);
2272 dprintk("NFS call lookupfh %s\n", name
->name
);
2273 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2274 dprintk("NFS reply lookupfh: %d\n", status
);
2278 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2279 struct qstr
*name
, struct nfs_fh
*fhandle
,
2280 struct nfs_fattr
*fattr
)
2282 struct nfs4_exception exception
= { };
2285 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
2287 if (err
== -NFS4ERR_MOVED
) {
2291 err
= nfs4_handle_exception(server
, err
, &exception
);
2292 } while (exception
.retry
);
2296 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
2297 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2301 dprintk("NFS call lookup %s\n", name
->name
);
2302 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2303 if (status
== -NFS4ERR_MOVED
)
2304 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2305 dprintk("NFS reply lookup: %d\n", status
);
2309 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2311 struct nfs4_exception exception
= { };
2314 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2315 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
2317 } while (exception
.retry
);
2321 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2323 struct nfs_server
*server
= NFS_SERVER(inode
);
2324 struct nfs_fattr fattr
;
2325 struct nfs4_accessargs args
= {
2326 .fh
= NFS_FH(inode
),
2327 .bitmask
= server
->attr_bitmask
,
2329 struct nfs4_accessres res
= {
2333 struct rpc_message msg
= {
2334 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2337 .rpc_cred
= entry
->cred
,
2339 int mode
= entry
->mask
;
2343 * Determine which access bits we want to ask for...
2345 if (mode
& MAY_READ
)
2346 args
.access
|= NFS4_ACCESS_READ
;
2347 if (S_ISDIR(inode
->i_mode
)) {
2348 if (mode
& MAY_WRITE
)
2349 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2350 if (mode
& MAY_EXEC
)
2351 args
.access
|= NFS4_ACCESS_LOOKUP
;
2353 if (mode
& MAY_WRITE
)
2354 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2355 if (mode
& MAY_EXEC
)
2356 args
.access
|= NFS4_ACCESS_EXECUTE
;
2358 nfs_fattr_init(&fattr
);
2359 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2362 if (res
.access
& NFS4_ACCESS_READ
)
2363 entry
->mask
|= MAY_READ
;
2364 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2365 entry
->mask
|= MAY_WRITE
;
2366 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2367 entry
->mask
|= MAY_EXEC
;
2368 nfs_refresh_inode(inode
, &fattr
);
2373 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2375 struct nfs4_exception exception
= { };
2378 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2379 _nfs4_proc_access(inode
, entry
),
2381 } while (exception
.retry
);
2386 * TODO: For the time being, we don't try to get any attributes
2387 * along with any of the zero-copy operations READ, READDIR,
2390 * In the case of the first three, we want to put the GETATTR
2391 * after the read-type operation -- this is because it is hard
2392 * to predict the length of a GETATTR response in v4, and thus
2393 * align the READ data correctly. This means that the GETATTR
2394 * may end up partially falling into the page cache, and we should
2395 * shift it into the 'tail' of the xdr_buf before processing.
2396 * To do this efficiently, we need to know the total length
2397 * of data received, which doesn't seem to be available outside
2400 * In the case of WRITE, we also want to put the GETATTR after
2401 * the operation -- in this case because we want to make sure
2402 * we get the post-operation mtime and size. This means that
2403 * we can't use xdr_encode_pages() as written: we need a variant
2404 * of it which would leave room in the 'tail' iovec.
2406 * Both of these changes to the XDR layer would in fact be quite
2407 * minor, but I decided to leave them for a subsequent patch.
2409 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2410 unsigned int pgbase
, unsigned int pglen
)
2412 struct nfs4_readlink args
= {
2413 .fh
= NFS_FH(inode
),
2418 struct nfs4_readlink_res res
;
2419 struct rpc_message msg
= {
2420 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2425 return nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
2428 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2429 unsigned int pgbase
, unsigned int pglen
)
2431 struct nfs4_exception exception
= { };
2434 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2435 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2437 } while (exception
.retry
);
2443 * We will need to arrange for the VFS layer to provide an atomic open.
2444 * Until then, this create/open method is prone to inefficiency and race
2445 * conditions due to the lookup, create, and open VFS calls from sys_open()
2446 * placed on the wire.
2448 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2449 * The file will be opened again in the subsequent VFS open call
2450 * (nfs4_proc_file_open).
2452 * The open for read will just hang around to be used by any process that
2453 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2457 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2458 int flags
, struct nameidata
*nd
)
2460 struct path path
= {
2461 .mnt
= nd
->path
.mnt
,
2464 struct nfs4_state
*state
;
2465 struct rpc_cred
*cred
;
2466 fmode_t fmode
= flags
& (FMODE_READ
| FMODE_WRITE
);
2469 cred
= rpc_lookup_cred();
2471 status
= PTR_ERR(cred
);
2474 state
= nfs4_do_open(dir
, &path
, fmode
, flags
, sattr
, cred
);
2476 if (IS_ERR(state
)) {
2477 status
= PTR_ERR(state
);
2480 d_add(dentry
, igrab(state
->inode
));
2481 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2482 if (flags
& O_EXCL
) {
2483 struct nfs_fattr fattr
;
2484 status
= nfs4_do_setattr(state
->inode
, cred
, &fattr
, sattr
, state
);
2486 nfs_setattr_update_inode(state
->inode
, sattr
);
2487 nfs_post_op_update_inode(state
->inode
, &fattr
);
2489 if (status
== 0 && (nd
->flags
& LOOKUP_OPEN
) != 0)
2490 status
= nfs4_intent_set_file(nd
, &path
, state
, fmode
);
2492 nfs4_close_sync(&path
, state
, fmode
);
2499 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2501 struct nfs_server
*server
= NFS_SERVER(dir
);
2502 struct nfs_removeargs args
= {
2504 .name
.len
= name
->len
,
2505 .name
.name
= name
->name
,
2506 .bitmask
= server
->attr_bitmask
,
2508 struct nfs_removeres res
= {
2511 struct rpc_message msg
= {
2512 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2518 nfs_fattr_init(&res
.dir_attr
);
2519 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 1);
2521 update_changeattr(dir
, &res
.cinfo
);
2522 nfs_post_op_update_inode(dir
, &res
.dir_attr
);
2527 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2529 struct nfs4_exception exception
= { };
2532 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2533 _nfs4_proc_remove(dir
, name
),
2535 } while (exception
.retry
);
2539 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2541 struct nfs_server
*server
= NFS_SERVER(dir
);
2542 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2543 struct nfs_removeres
*res
= msg
->rpc_resp
;
2545 args
->bitmask
= server
->cache_consistency_bitmask
;
2546 res
->server
= server
;
2547 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2550 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2552 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2554 nfs4_sequence_done(res
->server
, &res
->seq_res
, task
->tk_status
);
2555 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2557 update_changeattr(dir
, &res
->cinfo
);
2558 nfs_post_op_update_inode(dir
, &res
->dir_attr
);
2562 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2563 struct inode
*new_dir
, struct qstr
*new_name
)
2565 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2566 struct nfs4_rename_arg arg
= {
2567 .old_dir
= NFS_FH(old_dir
),
2568 .new_dir
= NFS_FH(new_dir
),
2569 .old_name
= old_name
,
2570 .new_name
= new_name
,
2571 .bitmask
= server
->attr_bitmask
,
2573 struct nfs_fattr old_fattr
, new_fattr
;
2574 struct nfs4_rename_res res
= {
2576 .old_fattr
= &old_fattr
,
2577 .new_fattr
= &new_fattr
,
2579 struct rpc_message msg
= {
2580 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2586 nfs_fattr_init(res
.old_fattr
);
2587 nfs_fattr_init(res
.new_fattr
);
2588 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2591 update_changeattr(old_dir
, &res
.old_cinfo
);
2592 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2593 update_changeattr(new_dir
, &res
.new_cinfo
);
2594 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2599 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2600 struct inode
*new_dir
, struct qstr
*new_name
)
2602 struct nfs4_exception exception
= { };
2605 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2606 _nfs4_proc_rename(old_dir
, old_name
,
2609 } while (exception
.retry
);
2613 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2615 struct nfs_server
*server
= NFS_SERVER(inode
);
2616 struct nfs4_link_arg arg
= {
2617 .fh
= NFS_FH(inode
),
2618 .dir_fh
= NFS_FH(dir
),
2620 .bitmask
= server
->attr_bitmask
,
2622 struct nfs_fattr fattr
, dir_attr
;
2623 struct nfs4_link_res res
= {
2626 .dir_attr
= &dir_attr
,
2628 struct rpc_message msg
= {
2629 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2635 nfs_fattr_init(res
.fattr
);
2636 nfs_fattr_init(res
.dir_attr
);
2637 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2639 update_changeattr(dir
, &res
.cinfo
);
2640 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2641 nfs_post_op_update_inode(inode
, res
.fattr
);
2647 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2649 struct nfs4_exception exception
= { };
2652 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2653 _nfs4_proc_link(inode
, dir
, name
),
2655 } while (exception
.retry
);
2659 struct nfs4_createdata
{
2660 struct rpc_message msg
;
2661 struct nfs4_create_arg arg
;
2662 struct nfs4_create_res res
;
2664 struct nfs_fattr fattr
;
2665 struct nfs_fattr dir_fattr
;
2668 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2669 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2671 struct nfs4_createdata
*data
;
2673 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2675 struct nfs_server
*server
= NFS_SERVER(dir
);
2677 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2678 data
->msg
.rpc_argp
= &data
->arg
;
2679 data
->msg
.rpc_resp
= &data
->res
;
2680 data
->arg
.dir_fh
= NFS_FH(dir
);
2681 data
->arg
.server
= server
;
2682 data
->arg
.name
= name
;
2683 data
->arg
.attrs
= sattr
;
2684 data
->arg
.ftype
= ftype
;
2685 data
->arg
.bitmask
= server
->attr_bitmask
;
2686 data
->res
.server
= server
;
2687 data
->res
.fh
= &data
->fh
;
2688 data
->res
.fattr
= &data
->fattr
;
2689 data
->res
.dir_fattr
= &data
->dir_fattr
;
2690 nfs_fattr_init(data
->res
.fattr
);
2691 nfs_fattr_init(data
->res
.dir_fattr
);
2696 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2698 int status
= nfs4_call_sync(NFS_SERVER(dir
), &data
->msg
,
2699 &data
->arg
, &data
->res
, 1);
2701 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2702 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2703 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2708 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2713 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2714 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2716 struct nfs4_createdata
*data
;
2717 int status
= -ENAMETOOLONG
;
2719 if (len
> NFS4_MAXPATHLEN
)
2723 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2727 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2728 data
->arg
.u
.symlink
.pages
= &page
;
2729 data
->arg
.u
.symlink
.len
= len
;
2731 status
= nfs4_do_create(dir
, dentry
, data
);
2733 nfs4_free_createdata(data
);
2738 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2739 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2741 struct nfs4_exception exception
= { };
2744 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2745 _nfs4_proc_symlink(dir
, dentry
, page
,
2748 } while (exception
.retry
);
2752 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2753 struct iattr
*sattr
)
2755 struct nfs4_createdata
*data
;
2756 int status
= -ENOMEM
;
2758 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2762 status
= nfs4_do_create(dir
, dentry
, data
);
2764 nfs4_free_createdata(data
);
2769 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2770 struct iattr
*sattr
)
2772 struct nfs4_exception exception
= { };
2775 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2776 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2778 } while (exception
.retry
);
2782 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2783 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2785 struct inode
*dir
= dentry
->d_inode
;
2786 struct nfs4_readdir_arg args
= {
2791 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2793 struct nfs4_readdir_res res
;
2794 struct rpc_message msg
= {
2795 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2802 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2803 dentry
->d_parent
->d_name
.name
,
2804 dentry
->d_name
.name
,
2805 (unsigned long long)cookie
);
2806 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2807 res
.pgbase
= args
.pgbase
;
2808 status
= nfs4_call_sync(NFS_SERVER(dir
), &msg
, &args
, &res
, 0);
2810 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2812 nfs_invalidate_atime(dir
);
2814 dprintk("%s: returns %d\n", __func__
, status
);
2818 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2819 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2821 struct nfs4_exception exception
= { };
2824 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2825 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2828 } while (exception
.retry
);
2832 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2833 struct iattr
*sattr
, dev_t rdev
)
2835 struct nfs4_createdata
*data
;
2836 int mode
= sattr
->ia_mode
;
2837 int status
= -ENOMEM
;
2839 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2840 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2842 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2847 data
->arg
.ftype
= NF4FIFO
;
2848 else if (S_ISBLK(mode
)) {
2849 data
->arg
.ftype
= NF4BLK
;
2850 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2851 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2853 else if (S_ISCHR(mode
)) {
2854 data
->arg
.ftype
= NF4CHR
;
2855 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2856 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2859 status
= nfs4_do_create(dir
, dentry
, data
);
2861 nfs4_free_createdata(data
);
2866 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2867 struct iattr
*sattr
, dev_t rdev
)
2869 struct nfs4_exception exception
= { };
2872 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2873 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2875 } while (exception
.retry
);
2879 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2880 struct nfs_fsstat
*fsstat
)
2882 struct nfs4_statfs_arg args
= {
2884 .bitmask
= server
->attr_bitmask
,
2886 struct nfs4_statfs_res res
= {
2889 struct rpc_message msg
= {
2890 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2895 nfs_fattr_init(fsstat
->fattr
);
2896 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2899 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2901 struct nfs4_exception exception
= { };
2904 err
= nfs4_handle_exception(server
,
2905 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2907 } while (exception
.retry
);
2911 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2912 struct nfs_fsinfo
*fsinfo
)
2914 struct nfs4_fsinfo_arg args
= {
2916 .bitmask
= server
->attr_bitmask
,
2918 struct nfs4_fsinfo_res res
= {
2921 struct rpc_message msg
= {
2922 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
2927 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2930 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2932 struct nfs4_exception exception
= { };
2936 err
= nfs4_handle_exception(server
,
2937 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
2939 } while (exception
.retry
);
2943 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2945 nfs_fattr_init(fsinfo
->fattr
);
2946 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2949 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2950 struct nfs_pathconf
*pathconf
)
2952 struct nfs4_pathconf_arg args
= {
2954 .bitmask
= server
->attr_bitmask
,
2956 struct nfs4_pathconf_res res
= {
2957 .pathconf
= pathconf
,
2959 struct rpc_message msg
= {
2960 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2965 /* None of the pathconf attributes are mandatory to implement */
2966 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2967 memset(pathconf
, 0, sizeof(*pathconf
));
2971 nfs_fattr_init(pathconf
->fattr
);
2972 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2975 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2976 struct nfs_pathconf
*pathconf
)
2978 struct nfs4_exception exception
= { };
2982 err
= nfs4_handle_exception(server
,
2983 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2985 } while (exception
.retry
);
2989 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
2991 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2993 dprintk("--> %s\n", __func__
);
2995 nfs4_sequence_done(server
, &data
->res
.seq_res
, task
->tk_status
);
2997 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
2998 nfs_restart_rpc(task
, server
->nfs_client
);
3002 nfs_invalidate_atime(data
->inode
);
3003 if (task
->tk_status
> 0)
3004 renew_lease(server
, data
->timestamp
);
3008 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3010 data
->timestamp
= jiffies
;
3011 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3014 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3016 struct inode
*inode
= data
->inode
;
3018 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
3021 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3022 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3025 if (task
->tk_status
>= 0) {
3026 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3027 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3032 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3034 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3036 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3037 data
->res
.server
= server
;
3038 data
->timestamp
= jiffies
;
3040 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3043 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3045 struct inode
*inode
= data
->inode
;
3047 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
3049 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3050 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3053 nfs_refresh_inode(inode
, data
->res
.fattr
);
3057 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3059 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3061 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3062 data
->res
.server
= server
;
3063 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3067 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3068 * standalone procedure for queueing an asynchronous RENEW.
3070 static void nfs4_renew_done(struct rpc_task
*task
, void *data
)
3072 struct nfs_client
*clp
= (struct nfs_client
*)task
->tk_msg
.rpc_argp
;
3073 unsigned long timestamp
= (unsigned long)data
;
3075 if (task
->tk_status
< 0) {
3076 /* Unless we're shutting down, schedule state recovery! */
3077 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3078 nfs4_schedule_state_recovery(clp
);
3081 spin_lock(&clp
->cl_lock
);
3082 if (time_before(clp
->cl_last_renewal
,timestamp
))
3083 clp
->cl_last_renewal
= timestamp
;
3084 spin_unlock(&clp
->cl_lock
);
3087 static const struct rpc_call_ops nfs4_renew_ops
= {
3088 .rpc_call_done
= nfs4_renew_done
,
3091 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3093 struct rpc_message msg
= {
3094 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3099 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3100 &nfs4_renew_ops
, (void *)jiffies
);
3103 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3105 struct rpc_message msg
= {
3106 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3110 unsigned long now
= jiffies
;
3113 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3116 spin_lock(&clp
->cl_lock
);
3117 if (time_before(clp
->cl_last_renewal
,now
))
3118 clp
->cl_last_renewal
= now
;
3119 spin_unlock(&clp
->cl_lock
);
3123 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3125 return (server
->caps
& NFS_CAP_ACLS
)
3126 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3127 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3130 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3131 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3134 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3136 static void buf_to_pages(const void *buf
, size_t buflen
,
3137 struct page
**pages
, unsigned int *pgbase
)
3139 const void *p
= buf
;
3141 *pgbase
= offset_in_page(buf
);
3143 while (p
< buf
+ buflen
) {
3144 *(pages
++) = virt_to_page(p
);
3145 p
+= PAGE_CACHE_SIZE
;
3149 struct nfs4_cached_acl
{
3155 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3157 struct nfs_inode
*nfsi
= NFS_I(inode
);
3159 spin_lock(&inode
->i_lock
);
3160 kfree(nfsi
->nfs4_acl
);
3161 nfsi
->nfs4_acl
= acl
;
3162 spin_unlock(&inode
->i_lock
);
3165 static void nfs4_zap_acl_attr(struct inode
*inode
)
3167 nfs4_set_cached_acl(inode
, NULL
);
3170 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3172 struct nfs_inode
*nfsi
= NFS_I(inode
);
3173 struct nfs4_cached_acl
*acl
;
3176 spin_lock(&inode
->i_lock
);
3177 acl
= nfsi
->nfs4_acl
;
3180 if (buf
== NULL
) /* user is just asking for length */
3182 if (acl
->cached
== 0)
3184 ret
= -ERANGE
; /* see getxattr(2) man page */
3185 if (acl
->len
> buflen
)
3187 memcpy(buf
, acl
->data
, acl
->len
);
3191 spin_unlock(&inode
->i_lock
);
3195 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3197 struct nfs4_cached_acl
*acl
;
3199 if (buf
&& acl_len
<= PAGE_SIZE
) {
3200 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3204 memcpy(acl
->data
, buf
, acl_len
);
3206 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3213 nfs4_set_cached_acl(inode
, acl
);
3216 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3218 struct page
*pages
[NFS4ACL_MAXPAGES
];
3219 struct nfs_getaclargs args
= {
3220 .fh
= NFS_FH(inode
),
3224 struct nfs_getaclres res
= {
3228 struct rpc_message msg
= {
3229 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3233 struct page
*localpage
= NULL
;
3236 if (buflen
< PAGE_SIZE
) {
3237 /* As long as we're doing a round trip to the server anyway,
3238 * let's be prepared for a page of acl data. */
3239 localpage
= alloc_page(GFP_KERNEL
);
3240 resp_buf
= page_address(localpage
);
3241 if (localpage
== NULL
)
3243 args
.acl_pages
[0] = localpage
;
3244 args
.acl_pgbase
= 0;
3245 args
.acl_len
= PAGE_SIZE
;
3248 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3250 ret
= nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
3253 if (res
.acl_len
> args
.acl_len
)
3254 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3256 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3259 if (res
.acl_len
> buflen
)
3262 memcpy(buf
, resp_buf
, res
.acl_len
);
3267 __free_page(localpage
);
3271 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3273 struct nfs4_exception exception
= { };
3276 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3279 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3280 } while (exception
.retry
);
3284 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3286 struct nfs_server
*server
= NFS_SERVER(inode
);
3289 if (!nfs4_server_supports_acls(server
))
3291 ret
= nfs_revalidate_inode(server
, inode
);
3294 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3297 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3300 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3302 struct nfs_server
*server
= NFS_SERVER(inode
);
3303 struct page
*pages
[NFS4ACL_MAXPAGES
];
3304 struct nfs_setaclargs arg
= {
3305 .fh
= NFS_FH(inode
),
3309 struct nfs_setaclres res
;
3310 struct rpc_message msg
= {
3311 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3317 if (!nfs4_server_supports_acls(server
))
3319 nfs_inode_return_delegation(inode
);
3320 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3321 ret
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3322 nfs_access_zap_cache(inode
);
3323 nfs_zap_acl_cache(inode
);
3327 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3329 struct nfs4_exception exception
= { };
3332 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3333 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3335 } while (exception
.retry
);
3340 _nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs_client
*clp
, struct nfs4_state
*state
)
3342 if (!clp
|| task
->tk_status
>= 0)
3344 switch(task
->tk_status
) {
3345 case -NFS4ERR_ADMIN_REVOKED
:
3346 case -NFS4ERR_BAD_STATEID
:
3347 case -NFS4ERR_OPENMODE
:
3350 nfs4_state_mark_reclaim_nograce(clp
, state
);
3351 case -NFS4ERR_STALE_CLIENTID
:
3352 case -NFS4ERR_STALE_STATEID
:
3353 case -NFS4ERR_EXPIRED
:
3354 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3355 nfs4_schedule_state_recovery(clp
);
3356 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3357 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3358 task
->tk_status
= 0;
3360 #if defined(CONFIG_NFS_V4_1)
3361 case -NFS4ERR_BADSESSION
:
3362 case -NFS4ERR_BADSLOT
:
3363 case -NFS4ERR_BAD_HIGH_SLOT
:
3364 case -NFS4ERR_DEADSESSION
:
3365 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3366 case -NFS4ERR_SEQ_FALSE_RETRY
:
3367 case -NFS4ERR_SEQ_MISORDERED
:
3368 dprintk("%s ERROR %d, Reset session\n", __func__
,
3370 nfs4_schedule_state_recovery(clp
);
3371 task
->tk_status
= 0;
3373 #endif /* CONFIG_NFS_V4_1 */
3374 case -NFS4ERR_DELAY
:
3376 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3377 case -NFS4ERR_GRACE
:
3378 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3379 task
->tk_status
= 0;
3381 case -NFS4ERR_OLD_STATEID
:
3382 task
->tk_status
= 0;
3385 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3390 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3392 return _nfs4_async_handle_error(task
, server
, server
->nfs_client
, state
);
3395 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
, unsigned short port
, struct rpc_cred
*cred
)
3397 nfs4_verifier sc_verifier
;
3398 struct nfs4_setclientid setclientid
= {
3399 .sc_verifier
= &sc_verifier
,
3402 struct rpc_message msg
= {
3403 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3404 .rpc_argp
= &setclientid
,
3412 p
= (__be32
*)sc_verifier
.data
;
3413 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3414 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3417 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3418 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3420 rpc_peeraddr2str(clp
->cl_rpcclient
,
3422 rpc_peeraddr2str(clp
->cl_rpcclient
,
3424 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3425 clp
->cl_id_uniquifier
);
3426 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3427 sizeof(setclientid
.sc_netid
),
3428 rpc_peeraddr2str(clp
->cl_rpcclient
,
3429 RPC_DISPLAY_NETID
));
3430 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3431 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3432 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3434 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3435 if (status
!= -NFS4ERR_CLID_INUSE
)
3440 ssleep(clp
->cl_lease_time
+ 1);
3442 if (++clp
->cl_id_uniquifier
== 0)
3448 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3450 struct nfs_fsinfo fsinfo
;
3451 struct rpc_message msg
= {
3452 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3454 .rpc_resp
= &fsinfo
,
3461 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3463 spin_lock(&clp
->cl_lock
);
3464 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3465 clp
->cl_last_renewal
= now
;
3466 spin_unlock(&clp
->cl_lock
);
3471 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3476 err
= _nfs4_proc_setclientid_confirm(clp
, cred
);
3480 case -NFS4ERR_RESOURCE
:
3481 /* The IBM lawyers misread another document! */
3482 case -NFS4ERR_DELAY
:
3483 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3489 struct nfs4_delegreturndata
{
3490 struct nfs4_delegreturnargs args
;
3491 struct nfs4_delegreturnres res
;
3493 nfs4_stateid stateid
;
3494 unsigned long timestamp
;
3495 struct nfs_fattr fattr
;
3499 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3501 struct nfs4_delegreturndata
*data
= calldata
;
3503 nfs4_sequence_done(data
->res
.server
, &data
->res
.seq_res
,
3506 switch (task
->tk_status
) {
3507 case -NFS4ERR_STALE_STATEID
:
3508 case -NFS4ERR_EXPIRED
:
3510 renew_lease(data
->res
.server
, data
->timestamp
);
3513 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3515 nfs_restart_rpc(task
, data
->res
.server
->nfs_client
);
3519 data
->rpc_status
= task
->tk_status
;
3522 static void nfs4_delegreturn_release(void *calldata
)
3527 #if defined(CONFIG_NFS_V4_1)
3528 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3530 struct nfs4_delegreturndata
*d_data
;
3532 d_data
= (struct nfs4_delegreturndata
*)data
;
3534 if (nfs4_setup_sequence(d_data
->res
.server
->nfs_client
,
3535 &d_data
->args
.seq_args
,
3536 &d_data
->res
.seq_res
, 1, task
))
3538 rpc_call_start(task
);
3540 #endif /* CONFIG_NFS_V4_1 */
3542 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3543 #if defined(CONFIG_NFS_V4_1)
3544 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3545 #endif /* CONFIG_NFS_V4_1 */
3546 .rpc_call_done
= nfs4_delegreturn_done
,
3547 .rpc_release
= nfs4_delegreturn_release
,
3550 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3552 struct nfs4_delegreturndata
*data
;
3553 struct nfs_server
*server
= NFS_SERVER(inode
);
3554 struct rpc_task
*task
;
3555 struct rpc_message msg
= {
3556 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3559 struct rpc_task_setup task_setup_data
= {
3560 .rpc_client
= server
->client
,
3561 .rpc_message
= &msg
,
3562 .callback_ops
= &nfs4_delegreturn_ops
,
3563 .flags
= RPC_TASK_ASYNC
,
3567 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3570 data
->args
.fhandle
= &data
->fh
;
3571 data
->args
.stateid
= &data
->stateid
;
3572 data
->args
.bitmask
= server
->attr_bitmask
;
3573 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3574 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3575 data
->res
.fattr
= &data
->fattr
;
3576 data
->res
.server
= server
;
3577 data
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3578 nfs_fattr_init(data
->res
.fattr
);
3579 data
->timestamp
= jiffies
;
3580 data
->rpc_status
= 0;
3582 task_setup_data
.callback_data
= data
;
3583 msg
.rpc_argp
= &data
->args
,
3584 msg
.rpc_resp
= &data
->res
,
3585 task
= rpc_run_task(&task_setup_data
);
3587 return PTR_ERR(task
);
3590 status
= nfs4_wait_for_completion_rpc_task(task
);
3593 status
= data
->rpc_status
;
3596 nfs_refresh_inode(inode
, &data
->fattr
);
3602 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3604 struct nfs_server
*server
= NFS_SERVER(inode
);
3605 struct nfs4_exception exception
= { };
3608 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3610 case -NFS4ERR_STALE_STATEID
:
3611 case -NFS4ERR_EXPIRED
:
3615 err
= nfs4_handle_exception(server
, err
, &exception
);
3616 } while (exception
.retry
);
3620 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3621 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3624 * sleep, with exponential backoff, and retry the LOCK operation.
3626 static unsigned long
3627 nfs4_set_lock_task_retry(unsigned long timeout
)
3629 schedule_timeout_killable(timeout
);
3631 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3632 return NFS4_LOCK_MAXTIMEOUT
;
3636 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3638 struct inode
*inode
= state
->inode
;
3639 struct nfs_server
*server
= NFS_SERVER(inode
);
3640 struct nfs_client
*clp
= server
->nfs_client
;
3641 struct nfs_lockt_args arg
= {
3642 .fh
= NFS_FH(inode
),
3645 struct nfs_lockt_res res
= {
3648 struct rpc_message msg
= {
3649 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3652 .rpc_cred
= state
->owner
->so_cred
,
3654 struct nfs4_lock_state
*lsp
;
3657 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3658 status
= nfs4_set_lock_state(state
, request
);
3661 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3662 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3663 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3666 request
->fl_type
= F_UNLCK
;
3668 case -NFS4ERR_DENIED
:
3671 request
->fl_ops
->fl_release_private(request
);
3676 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3678 struct nfs4_exception exception
= { };
3682 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3683 _nfs4_proc_getlk(state
, cmd
, request
),
3685 } while (exception
.retry
);
3689 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3692 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3694 res
= posix_lock_file_wait(file
, fl
);
3697 res
= flock_lock_file_wait(file
, fl
);
3705 struct nfs4_unlockdata
{
3706 struct nfs_locku_args arg
;
3707 struct nfs_locku_res res
;
3708 struct nfs4_lock_state
*lsp
;
3709 struct nfs_open_context
*ctx
;
3710 struct file_lock fl
;
3711 const struct nfs_server
*server
;
3712 unsigned long timestamp
;
3715 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3716 struct nfs_open_context
*ctx
,
3717 struct nfs4_lock_state
*lsp
,
3718 struct nfs_seqid
*seqid
)
3720 struct nfs4_unlockdata
*p
;
3721 struct inode
*inode
= lsp
->ls_state
->inode
;
3723 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3726 p
->arg
.fh
= NFS_FH(inode
);
3728 p
->arg
.seqid
= seqid
;
3729 p
->res
.seqid
= seqid
;
3730 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3731 p
->arg
.stateid
= &lsp
->ls_stateid
;
3733 atomic_inc(&lsp
->ls_count
);
3734 /* Ensure we don't close file until we're done freeing locks! */
3735 p
->ctx
= get_nfs_open_context(ctx
);
3736 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3737 p
->server
= NFS_SERVER(inode
);
3741 static void nfs4_locku_release_calldata(void *data
)
3743 struct nfs4_unlockdata
*calldata
= data
;
3744 nfs_free_seqid(calldata
->arg
.seqid
);
3745 nfs4_put_lock_state(calldata
->lsp
);
3746 put_nfs_open_context(calldata
->ctx
);
3750 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3752 struct nfs4_unlockdata
*calldata
= data
;
3754 nfs4_sequence_done(calldata
->server
, &calldata
->res
.seq_res
,
3756 if (RPC_ASSASSINATED(task
))
3758 switch (task
->tk_status
) {
3760 memcpy(calldata
->lsp
->ls_stateid
.data
,
3761 calldata
->res
.stateid
.data
,
3762 sizeof(calldata
->lsp
->ls_stateid
.data
));
3763 renew_lease(calldata
->server
, calldata
->timestamp
);
3765 case -NFS4ERR_BAD_STATEID
:
3766 case -NFS4ERR_OLD_STATEID
:
3767 case -NFS4ERR_STALE_STATEID
:
3768 case -NFS4ERR_EXPIRED
:
3771 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
3772 nfs_restart_rpc(task
,
3773 calldata
->server
->nfs_client
);
3777 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3779 struct nfs4_unlockdata
*calldata
= data
;
3781 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3783 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3784 /* Note: exit _without_ running nfs4_locku_done */
3785 task
->tk_action
= NULL
;
3788 calldata
->timestamp
= jiffies
;
3789 if (nfs4_setup_sequence(calldata
->server
->nfs_client
,
3790 &calldata
->arg
.seq_args
,
3791 &calldata
->res
.seq_res
, 1, task
))
3793 rpc_call_start(task
);
3796 static const struct rpc_call_ops nfs4_locku_ops
= {
3797 .rpc_call_prepare
= nfs4_locku_prepare
,
3798 .rpc_call_done
= nfs4_locku_done
,
3799 .rpc_release
= nfs4_locku_release_calldata
,
3802 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3803 struct nfs_open_context
*ctx
,
3804 struct nfs4_lock_state
*lsp
,
3805 struct nfs_seqid
*seqid
)
3807 struct nfs4_unlockdata
*data
;
3808 struct rpc_message msg
= {
3809 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3810 .rpc_cred
= ctx
->cred
,
3812 struct rpc_task_setup task_setup_data
= {
3813 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
3814 .rpc_message
= &msg
,
3815 .callback_ops
= &nfs4_locku_ops
,
3816 .workqueue
= nfsiod_workqueue
,
3817 .flags
= RPC_TASK_ASYNC
,
3820 /* Ensure this is an unlock - when canceling a lock, the
3821 * canceled lock is passed in, and it won't be an unlock.
3823 fl
->fl_type
= F_UNLCK
;
3825 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3827 nfs_free_seqid(seqid
);
3828 return ERR_PTR(-ENOMEM
);
3831 msg
.rpc_argp
= &data
->arg
,
3832 msg
.rpc_resp
= &data
->res
,
3833 task_setup_data
.callback_data
= data
;
3834 return rpc_run_task(&task_setup_data
);
3837 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3839 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3840 struct nfs_seqid
*seqid
;
3841 struct nfs4_lock_state
*lsp
;
3842 struct rpc_task
*task
;
3844 unsigned char fl_flags
= request
->fl_flags
;
3846 status
= nfs4_set_lock_state(state
, request
);
3847 /* Unlock _before_ we do the RPC call */
3848 request
->fl_flags
|= FL_EXISTS
;
3849 down_read(&nfsi
->rwsem
);
3850 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
3851 up_read(&nfsi
->rwsem
);
3854 up_read(&nfsi
->rwsem
);
3857 /* Is this a delegated lock? */
3858 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
3860 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3861 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3865 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
3866 status
= PTR_ERR(task
);
3869 status
= nfs4_wait_for_completion_rpc_task(task
);
3872 request
->fl_flags
= fl_flags
;
3876 struct nfs4_lockdata
{
3877 struct nfs_lock_args arg
;
3878 struct nfs_lock_res res
;
3879 struct nfs4_lock_state
*lsp
;
3880 struct nfs_open_context
*ctx
;
3881 struct file_lock fl
;
3882 unsigned long timestamp
;
3885 struct nfs_server
*server
;
3888 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
3889 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
)
3891 struct nfs4_lockdata
*p
;
3892 struct inode
*inode
= lsp
->ls_state
->inode
;
3893 struct nfs_server
*server
= NFS_SERVER(inode
);
3895 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3899 p
->arg
.fh
= NFS_FH(inode
);
3901 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
);
3902 if (p
->arg
.open_seqid
== NULL
)
3904 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3905 if (p
->arg
.lock_seqid
== NULL
)
3906 goto out_free_seqid
;
3907 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
3908 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
3909 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3910 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
3911 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3914 atomic_inc(&lsp
->ls_count
);
3915 p
->ctx
= get_nfs_open_context(ctx
);
3916 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3919 nfs_free_seqid(p
->arg
.open_seqid
);
3925 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
3927 struct nfs4_lockdata
*data
= calldata
;
3928 struct nfs4_state
*state
= data
->lsp
->ls_state
;
3930 dprintk("%s: begin!\n", __func__
);
3931 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
3933 /* Do we need to do an open_to_lock_owner? */
3934 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
3935 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
3937 data
->arg
.open_stateid
= &state
->stateid
;
3938 data
->arg
.new_lock_owner
= 1;
3939 data
->res
.open_seqid
= data
->arg
.open_seqid
;
3941 data
->arg
.new_lock_owner
= 0;
3942 data
->timestamp
= jiffies
;
3943 if (nfs4_setup_sequence(data
->server
->nfs_client
, &data
->arg
.seq_args
,
3944 &data
->res
.seq_res
, 1, task
))
3946 rpc_call_start(task
);
3947 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
3950 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
3952 struct nfs4_lockdata
*data
= calldata
;
3954 dprintk("%s: begin!\n", __func__
);
3956 nfs4_sequence_done(data
->server
, &data
->res
.seq_res
,
3959 data
->rpc_status
= task
->tk_status
;
3960 if (RPC_ASSASSINATED(task
))
3962 if (data
->arg
.new_lock_owner
!= 0) {
3963 if (data
->rpc_status
== 0)
3964 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
3968 if (data
->rpc_status
== 0) {
3969 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
3970 sizeof(data
->lsp
->ls_stateid
.data
));
3971 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
3972 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
3975 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
3978 static void nfs4_lock_release(void *calldata
)
3980 struct nfs4_lockdata
*data
= calldata
;
3982 dprintk("%s: begin!\n", __func__
);
3983 nfs_free_seqid(data
->arg
.open_seqid
);
3984 if (data
->cancelled
!= 0) {
3985 struct rpc_task
*task
;
3986 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
3987 data
->arg
.lock_seqid
);
3990 dprintk("%s: cancelling lock!\n", __func__
);
3992 nfs_free_seqid(data
->arg
.lock_seqid
);
3993 nfs4_put_lock_state(data
->lsp
);
3994 put_nfs_open_context(data
->ctx
);
3996 dprintk("%s: done!\n", __func__
);
3999 static const struct rpc_call_ops nfs4_lock_ops
= {
4000 .rpc_call_prepare
= nfs4_lock_prepare
,
4001 .rpc_call_done
= nfs4_lock_done
,
4002 .rpc_release
= nfs4_lock_release
,
4005 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int reclaim
)
4007 struct nfs4_lockdata
*data
;
4008 struct rpc_task
*task
;
4009 struct rpc_message msg
= {
4010 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4011 .rpc_cred
= state
->owner
->so_cred
,
4013 struct rpc_task_setup task_setup_data
= {
4014 .rpc_client
= NFS_CLIENT(state
->inode
),
4015 .rpc_message
= &msg
,
4016 .callback_ops
= &nfs4_lock_ops
,
4017 .workqueue
= nfsiod_workqueue
,
4018 .flags
= RPC_TASK_ASYNC
,
4022 dprintk("%s: begin!\n", __func__
);
4023 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4024 fl
->fl_u
.nfs4_fl
.owner
);
4028 data
->arg
.block
= 1;
4030 data
->arg
.reclaim
= 1;
4031 msg
.rpc_argp
= &data
->arg
,
4032 msg
.rpc_resp
= &data
->res
,
4033 task_setup_data
.callback_data
= data
;
4034 task
= rpc_run_task(&task_setup_data
);
4036 return PTR_ERR(task
);
4037 ret
= nfs4_wait_for_completion_rpc_task(task
);
4039 ret
= data
->rpc_status
;
4041 data
->cancelled
= 1;
4043 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4047 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4049 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4050 struct nfs4_exception exception
= { };
4054 /* Cache the lock if possible... */
4055 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4057 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
4058 if (err
!= -NFS4ERR_DELAY
)
4060 nfs4_handle_exception(server
, err
, &exception
);
4061 } while (exception
.retry
);
4065 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4067 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4068 struct nfs4_exception exception
= { };
4071 err
= nfs4_set_lock_state(state
, request
);
4075 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4077 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
4081 case -NFS4ERR_GRACE
:
4082 case -NFS4ERR_DELAY
:
4083 nfs4_handle_exception(server
, err
, &exception
);
4086 } while (exception
.retry
);
4091 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4093 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4094 unsigned char fl_flags
= request
->fl_flags
;
4097 /* Is this a delegated open? */
4098 status
= nfs4_set_lock_state(state
, request
);
4101 request
->fl_flags
|= FL_ACCESS
;
4102 status
= do_vfs_lock(request
->fl_file
, request
);
4105 down_read(&nfsi
->rwsem
);
4106 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4107 /* Yes: cache locks! */
4108 /* ...but avoid races with delegation recall... */
4109 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4110 status
= do_vfs_lock(request
->fl_file
, request
);
4113 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
4116 /* Note: we always want to sleep here! */
4117 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4118 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4119 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4121 up_read(&nfsi
->rwsem
);
4123 request
->fl_flags
= fl_flags
;
4127 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4129 struct nfs4_exception exception
= { };
4133 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4134 if (err
== -NFS4ERR_DENIED
)
4136 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4138 } while (exception
.retry
);
4143 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4145 struct nfs_open_context
*ctx
;
4146 struct nfs4_state
*state
;
4147 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4150 /* verify open state */
4151 ctx
= nfs_file_open_context(filp
);
4154 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4157 if (IS_GETLK(cmd
)) {
4159 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4163 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4166 if (request
->fl_type
== F_UNLCK
) {
4168 return nfs4_proc_unlck(state
, cmd
, request
);
4175 status
= nfs4_proc_setlk(state
, cmd
, request
);
4176 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4178 timeout
= nfs4_set_lock_task_retry(timeout
);
4179 status
= -ERESTARTSYS
;
4182 } while(status
< 0);
4186 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4188 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4189 struct nfs4_exception exception
= { };
4192 err
= nfs4_set_lock_state(state
, fl
);
4196 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, 0);
4199 printk(KERN_ERR
"%s: unhandled error %d.\n",
4204 case -NFS4ERR_EXPIRED
:
4205 case -NFS4ERR_STALE_CLIENTID
:
4206 case -NFS4ERR_STALE_STATEID
:
4207 case -NFS4ERR_BADSESSION
:
4208 case -NFS4ERR_BADSLOT
:
4209 case -NFS4ERR_BAD_HIGH_SLOT
:
4210 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4211 case -NFS4ERR_DEADSESSION
:
4212 nfs4_schedule_state_recovery(server
->nfs_client
);
4216 * The show must go on: exit, but mark the
4217 * stateid as needing recovery.
4219 case -NFS4ERR_ADMIN_REVOKED
:
4220 case -NFS4ERR_BAD_STATEID
:
4221 case -NFS4ERR_OPENMODE
:
4222 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
4226 case -NFS4ERR_DENIED
:
4227 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4230 case -NFS4ERR_DELAY
:
4233 err
= nfs4_handle_exception(server
, err
, &exception
);
4234 } while (exception
.retry
);
4239 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4241 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
4242 size_t buflen
, int flags
)
4244 struct inode
*inode
= dentry
->d_inode
;
4246 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4249 return nfs4_proc_set_acl(inode
, buf
, buflen
);
4252 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4253 * and that's what we'll do for e.g. user attributes that haven't been set.
4254 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4255 * attributes in kernel-managed attribute namespaces. */
4256 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
4259 struct inode
*inode
= dentry
->d_inode
;
4261 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4264 return nfs4_proc_get_acl(inode
, buf
, buflen
);
4267 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
4269 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
4271 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4273 if (buf
&& buflen
< len
)
4276 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
4280 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4282 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4283 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4284 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4287 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4288 NFS_ATTR_FATTR_NLINK
;
4289 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4293 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4294 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4296 struct nfs_server
*server
= NFS_SERVER(dir
);
4298 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4299 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4301 struct nfs4_fs_locations_arg args
= {
4302 .dir_fh
= NFS_FH(dir
),
4307 struct nfs4_fs_locations_res res
= {
4308 .fs_locations
= fs_locations
,
4310 struct rpc_message msg
= {
4311 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4317 dprintk("%s: start\n", __func__
);
4318 nfs_fattr_init(&fs_locations
->fattr
);
4319 fs_locations
->server
= server
;
4320 fs_locations
->nlocations
= 0;
4321 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
4322 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4323 dprintk("%s: returned status = %d\n", __func__
, status
);
4327 #ifdef CONFIG_NFS_V4_1
4329 * nfs4_proc_exchange_id()
4331 * Since the clientid has expired, all compounds using sessions
4332 * associated with the stale clientid will be returning
4333 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4334 * be in some phase of session reset.
4336 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4338 nfs4_verifier verifier
;
4339 struct nfs41_exchange_id_args args
= {
4341 .flags
= clp
->cl_exchange_flags
,
4343 struct nfs41_exchange_id_res res
= {
4347 struct rpc_message msg
= {
4348 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4355 dprintk("--> %s\n", __func__
);
4356 BUG_ON(clp
== NULL
);
4358 /* Remove server-only flags */
4359 args
.flags
&= ~EXCHGID4_FLAG_CONFIRMED_R
;
4361 p
= (u32
*)verifier
.data
;
4362 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4363 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4364 args
.verifier
= &verifier
;
4367 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4370 rpc_peeraddr2str(clp
->cl_rpcclient
,
4372 clp
->cl_id_uniquifier
);
4374 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4376 if (status
!= NFS4ERR_CLID_INUSE
)
4382 if (++clp
->cl_id_uniquifier
== 0)
4386 dprintk("<-- %s status= %d\n", __func__
, status
);
4390 struct nfs4_get_lease_time_data
{
4391 struct nfs4_get_lease_time_args
*args
;
4392 struct nfs4_get_lease_time_res
*res
;
4393 struct nfs_client
*clp
;
4396 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4400 struct nfs4_get_lease_time_data
*data
=
4401 (struct nfs4_get_lease_time_data
*)calldata
;
4403 dprintk("--> %s\n", __func__
);
4404 /* just setup sequence, do not trigger session recovery
4405 since we're invoked within one */
4406 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4407 &data
->args
->la_seq_args
,
4408 &data
->res
->lr_seq_res
, 0, task
);
4410 BUG_ON(ret
== -EAGAIN
);
4411 rpc_call_start(task
);
4412 dprintk("<-- %s\n", __func__
);
4416 * Called from nfs4_state_manager thread for session setup, so don't recover
4417 * from sequence operation or clientid errors.
4419 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4421 struct nfs4_get_lease_time_data
*data
=
4422 (struct nfs4_get_lease_time_data
*)calldata
;
4424 dprintk("--> %s\n", __func__
);
4425 nfs41_sequence_done(data
->clp
, &data
->res
->lr_seq_res
, task
->tk_status
);
4426 switch (task
->tk_status
) {
4427 case -NFS4ERR_DELAY
:
4428 case -NFS4ERR_GRACE
:
4429 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4430 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4431 task
->tk_status
= 0;
4432 nfs_restart_rpc(task
, data
->clp
);
4435 dprintk("<-- %s\n", __func__
);
4438 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4439 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4440 .rpc_call_done
= nfs4_get_lease_time_done
,
4443 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4445 struct rpc_task
*task
;
4446 struct nfs4_get_lease_time_args args
;
4447 struct nfs4_get_lease_time_res res
= {
4448 .lr_fsinfo
= fsinfo
,
4450 struct nfs4_get_lease_time_data data
= {
4455 struct rpc_message msg
= {
4456 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4460 struct rpc_task_setup task_setup
= {
4461 .rpc_client
= clp
->cl_rpcclient
,
4462 .rpc_message
= &msg
,
4463 .callback_ops
= &nfs4_get_lease_time_ops
,
4464 .callback_data
= &data
4468 res
.lr_seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
4469 dprintk("--> %s\n", __func__
);
4470 task
= rpc_run_task(&task_setup
);
4473 status
= PTR_ERR(task
);
4475 status
= task
->tk_status
;
4478 dprintk("<-- %s return %d\n", __func__
, status
);
4484 * Reset a slot table
4486 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, int max_slots
,
4487 int old_max_slots
, int ivalue
)
4492 dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__
, max_slots
, tbl
);
4495 * Until we have dynamic slot table adjustment, insist
4496 * upon the same slot table size
4498 if (max_slots
!= old_max_slots
) {
4499 dprintk("%s reset slot table does't match old\n",
4501 ret
= -EINVAL
; /*XXX NFS4ERR_REQ_TOO_BIG ? */
4504 spin_lock(&tbl
->slot_tbl_lock
);
4505 for (i
= 0; i
< max_slots
; ++i
)
4506 tbl
->slots
[i
].seq_nr
= ivalue
;
4507 spin_unlock(&tbl
->slot_tbl_lock
);
4508 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4509 tbl
, tbl
->slots
, tbl
->max_slots
);
4511 dprintk("<-- %s: return %d\n", __func__
, ret
);
4516 * Reset the forechannel and backchannel slot tables
4518 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4522 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4523 session
->fc_attrs
.max_reqs
,
4524 session
->fc_slot_table
.max_slots
,
4529 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4530 session
->bc_attrs
.max_reqs
,
4531 session
->bc_slot_table
.max_slots
,
4536 /* Destroy the slot table */
4537 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4539 if (session
->fc_slot_table
.slots
!= NULL
) {
4540 kfree(session
->fc_slot_table
.slots
);
4541 session
->fc_slot_table
.slots
= NULL
;
4543 if (session
->bc_slot_table
.slots
!= NULL
) {
4544 kfree(session
->bc_slot_table
.slots
);
4545 session
->bc_slot_table
.slots
= NULL
;
4551 * Initialize slot table
4553 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4554 int max_slots
, int ivalue
)
4556 struct nfs4_slot
*slot
;
4559 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4561 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4563 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_KERNEL
);
4568 spin_lock(&tbl
->slot_tbl_lock
);
4569 tbl
->max_slots
= max_slots
;
4571 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4572 spin_unlock(&tbl
->slot_tbl_lock
);
4573 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4574 tbl
, tbl
->slots
, tbl
->max_slots
);
4576 dprintk("<-- %s: return %d\n", __func__
, ret
);
4581 * Initialize the forechannel and backchannel tables
4583 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4585 struct nfs4_slot_table
*tbl
;
4588 tbl
= &session
->fc_slot_table
;
4589 if (tbl
->slots
== NULL
) {
4590 status
= nfs4_init_slot_table(tbl
,
4591 session
->fc_attrs
.max_reqs
, 1);
4596 tbl
= &session
->bc_slot_table
;
4597 if (tbl
->slots
== NULL
) {
4598 status
= nfs4_init_slot_table(tbl
,
4599 session
->bc_attrs
.max_reqs
, 0);
4601 nfs4_destroy_slot_tables(session
);
4607 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
4609 struct nfs4_session
*session
;
4610 struct nfs4_slot_table
*tbl
;
4612 session
= kzalloc(sizeof(struct nfs4_session
), GFP_KERNEL
);
4617 * The create session reply races with the server back
4618 * channel probe. Mark the client NFS_CS_SESSION_INITING
4619 * so that the client back channel can find the
4622 clp
->cl_cons_state
= NFS_CS_SESSION_INITING
;
4623 init_completion(&session
->complete
);
4625 tbl
= &session
->fc_slot_table
;
4626 tbl
->highest_used_slotid
= -1;
4627 spin_lock_init(&tbl
->slot_tbl_lock
);
4628 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
4630 tbl
= &session
->bc_slot_table
;
4631 tbl
->highest_used_slotid
= -1;
4632 spin_lock_init(&tbl
->slot_tbl_lock
);
4633 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
4639 void nfs4_destroy_session(struct nfs4_session
*session
)
4641 nfs4_proc_destroy_session(session
);
4642 dprintk("%s Destroy backchannel for xprt %p\n",
4643 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
4644 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
4645 NFS41_BC_MIN_CALLBACKS
);
4646 nfs4_destroy_slot_tables(session
);
4651 * Initialize the values to be used by the client in CREATE_SESSION
4652 * If nfs4_init_session set the fore channel request and response sizes,
4655 * Set the back channel max_resp_sz_cached to zero to force the client to
4656 * always set csa_cachethis to FALSE because the current implementation
4657 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4659 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
4661 struct nfs4_session
*session
= args
->client
->cl_session
;
4662 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
4663 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
4666 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
4668 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
4669 /* Fore channel attributes */
4670 args
->fc_attrs
.headerpadsz
= 0;
4671 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
4672 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
4673 args
->fc_attrs
.max_resp_sz_cached
= mxresp_sz
;
4674 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
4675 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
4677 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4678 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4680 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
4681 args
->fc_attrs
.max_resp_sz_cached
, args
->fc_attrs
.max_ops
,
4682 args
->fc_attrs
.max_reqs
);
4684 /* Back channel attributes */
4685 args
->bc_attrs
.headerpadsz
= 0;
4686 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
4687 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
4688 args
->bc_attrs
.max_resp_sz_cached
= 0;
4689 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
4690 args
->bc_attrs
.max_reqs
= 1;
4692 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4693 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4695 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
4696 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
4697 args
->bc_attrs
.max_reqs
);
4700 static int _verify_channel_attr(char *chan
, char *attr_name
, u32 sent
, u32 rcvd
)
4704 printk(KERN_WARNING
"%s: Session INVALID: %s channel %s increased. "
4705 "sent=%u rcvd=%u\n", __func__
, chan
, attr_name
, sent
, rcvd
);
4709 #define _verify_fore_channel_attr(_name_) \
4710 _verify_channel_attr("fore", #_name_, \
4711 args->fc_attrs._name_, \
4712 session->fc_attrs._name_)
4714 #define _verify_back_channel_attr(_name_) \
4715 _verify_channel_attr("back", #_name_, \
4716 args->bc_attrs._name_, \
4717 session->bc_attrs._name_)
4720 * The server is not allowed to increase the fore channel header pad size,
4721 * maximum response size, or maximum number of operations.
4723 * The back channel attributes are only negotiatied down: We send what the
4724 * (back channel) server insists upon.
4726 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
4727 struct nfs4_session
*session
)
4731 ret
|= _verify_fore_channel_attr(headerpadsz
);
4732 ret
|= _verify_fore_channel_attr(max_resp_sz
);
4733 ret
|= _verify_fore_channel_attr(max_ops
);
4735 ret
|= _verify_back_channel_attr(headerpadsz
);
4736 ret
|= _verify_back_channel_attr(max_rqst_sz
);
4737 ret
|= _verify_back_channel_attr(max_resp_sz
);
4738 ret
|= _verify_back_channel_attr(max_resp_sz_cached
);
4739 ret
|= _verify_back_channel_attr(max_ops
);
4740 ret
|= _verify_back_channel_attr(max_reqs
);
4745 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
4747 struct nfs4_session
*session
= clp
->cl_session
;
4748 struct nfs41_create_session_args args
= {
4750 .cb_program
= NFS4_CALLBACK
,
4752 struct nfs41_create_session_res res
= {
4755 struct rpc_message msg
= {
4756 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
4762 nfs4_init_channel_attrs(&args
);
4763 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
4765 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4768 /* Verify the session's negotiated channel_attrs values */
4769 status
= nfs4_verify_channel_attrs(&args
, session
);
4771 /* Increment the clientid slot sequence id */
4779 * Issues a CREATE_SESSION operation to the server.
4780 * It is the responsibility of the caller to verify the session is
4781 * expired before calling this routine.
4783 int nfs4_proc_create_session(struct nfs_client
*clp
)
4787 struct nfs4_session
*session
= clp
->cl_session
;
4789 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
4791 status
= _nfs4_proc_create_session(clp
);
4795 /* Init and reset the fore channel */
4796 status
= nfs4_init_slot_tables(session
);
4797 dprintk("slot table initialization returned %d\n", status
);
4800 status
= nfs4_reset_slot_tables(session
);
4801 dprintk("slot table reset returned %d\n", status
);
4805 ptr
= (unsigned *)&session
->sess_id
.data
[0];
4806 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
4807 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
4809 dprintk("<-- %s\n", __func__
);
4814 * Issue the over-the-wire RPC DESTROY_SESSION.
4815 * The caller must serialize access to this routine.
4817 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
4820 struct rpc_message msg
;
4822 dprintk("--> nfs4_proc_destroy_session\n");
4824 /* session is still being setup */
4825 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
4828 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
4829 msg
.rpc_argp
= session
;
4830 msg
.rpc_resp
= NULL
;
4831 msg
.rpc_cred
= NULL
;
4832 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4836 "Got error %d from the server on DESTROY_SESSION. "
4837 "Session has been destroyed regardless...\n", status
);
4839 dprintk("<-- nfs4_proc_destroy_session\n");
4843 int nfs4_init_session(struct nfs_server
*server
)
4845 struct nfs_client
*clp
= server
->nfs_client
;
4846 struct nfs4_session
*session
;
4849 if (!nfs4_has_session(clp
))
4852 session
= clp
->cl_session
;
4853 session
->fc_attrs
.max_rqst_sz
= server
->wsize
+ nfs41_maxwrite_overhead
;
4854 session
->fc_attrs
.max_resp_sz
= server
->rsize
+ nfs41_maxread_overhead
;
4856 ret
= nfs4_recover_expired_lease(server
);
4858 ret
= nfs4_check_client_ready(clp
);
4863 * Renew the cl_session lease.
4865 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4867 struct nfs4_sequence_args args
;
4868 struct nfs4_sequence_res res
;
4870 struct rpc_message msg
= {
4871 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
4877 args
.sa_cache_this
= 0;
4879 return nfs4_call_sync_sequence(clp
, clp
->cl_rpcclient
, &msg
, &args
,
4883 void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
4885 struct nfs_client
*clp
= (struct nfs_client
*)data
;
4887 nfs41_sequence_done(clp
, task
->tk_msg
.rpc_resp
, task
->tk_status
);
4889 if (task
->tk_status
< 0) {
4890 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
4892 if (_nfs4_async_handle_error(task
, NULL
, clp
, NULL
)
4894 nfs_restart_rpc(task
, clp
);
4898 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
4900 kfree(task
->tk_msg
.rpc_argp
);
4901 kfree(task
->tk_msg
.rpc_resp
);
4903 dprintk("<-- %s\n", __func__
);
4906 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
4908 struct nfs_client
*clp
;
4909 struct nfs4_sequence_args
*args
;
4910 struct nfs4_sequence_res
*res
;
4912 clp
= (struct nfs_client
*)data
;
4913 args
= task
->tk_msg
.rpc_argp
;
4914 res
= task
->tk_msg
.rpc_resp
;
4916 if (nfs4_setup_sequence(clp
, args
, res
, 0, task
))
4918 rpc_call_start(task
);
4921 static const struct rpc_call_ops nfs41_sequence_ops
= {
4922 .rpc_call_done
= nfs41_sequence_call_done
,
4923 .rpc_call_prepare
= nfs41_sequence_prepare
,
4926 static int nfs41_proc_async_sequence(struct nfs_client
*clp
,
4927 struct rpc_cred
*cred
)
4929 struct nfs4_sequence_args
*args
;
4930 struct nfs4_sequence_res
*res
;
4931 struct rpc_message msg
= {
4932 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
4936 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
4939 res
= kzalloc(sizeof(*res
), GFP_KERNEL
);
4944 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
4945 msg
.rpc_argp
= args
;
4948 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
4949 &nfs41_sequence_ops
, (void *)clp
);
4952 struct nfs4_reclaim_complete_data
{
4953 struct nfs_client
*clp
;
4954 struct nfs41_reclaim_complete_args arg
;
4955 struct nfs41_reclaim_complete_res res
;
4958 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
4960 struct nfs4_reclaim_complete_data
*calldata
= data
;
4962 if (nfs4_setup_sequence(calldata
->clp
, &calldata
->arg
.seq_args
,
4963 &calldata
->res
.seq_res
, 0, task
))
4966 rpc_call_start(task
);
4969 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
4971 struct nfs4_reclaim_complete_data
*calldata
= data
;
4972 struct nfs_client
*clp
= calldata
->clp
;
4973 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
4975 dprintk("--> %s\n", __func__
);
4976 nfs41_sequence_done(clp
, res
, task
->tk_status
);
4977 switch (task
->tk_status
) {
4979 case -NFS4ERR_COMPLETE_ALREADY
:
4981 case -NFS4ERR_BADSESSION
:
4982 case -NFS4ERR_DEADSESSION
:
4984 * Handle the session error, but do not retry the operation, as
4985 * we have no way of telling whether the clientid had to be
4986 * reset before we got our reply. If reset, a new wave of
4987 * reclaim operations will follow, containing their own reclaim
4988 * complete. We don't want our retry to get on the way of
4989 * recovery by incorrectly indicating to the server that we're
4990 * done reclaiming state since the process had to be restarted.
4992 _nfs4_async_handle_error(task
, NULL
, clp
, NULL
);
4995 if (_nfs4_async_handle_error(
4996 task
, NULL
, clp
, NULL
) == -EAGAIN
) {
4997 rpc_restart_call_prepare(task
);
5002 dprintk("<-- %s\n", __func__
);
5005 static void nfs4_free_reclaim_complete_data(void *data
)
5007 struct nfs4_reclaim_complete_data
*calldata
= data
;
5012 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5013 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5014 .rpc_call_done
= nfs4_reclaim_complete_done
,
5015 .rpc_release
= nfs4_free_reclaim_complete_data
,
5019 * Issue a global reclaim complete.
5021 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5023 struct nfs4_reclaim_complete_data
*calldata
;
5024 struct rpc_task
*task
;
5025 struct rpc_message msg
= {
5026 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5028 struct rpc_task_setup task_setup_data
= {
5029 .rpc_client
= clp
->cl_rpcclient
,
5030 .rpc_message
= &msg
,
5031 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5032 .flags
= RPC_TASK_ASYNC
,
5034 int status
= -ENOMEM
;
5036 dprintk("--> %s\n", __func__
);
5037 calldata
= kzalloc(sizeof(*calldata
), GFP_KERNEL
);
5038 if (calldata
== NULL
)
5040 calldata
->clp
= clp
;
5041 calldata
->arg
.one_fs
= 0;
5042 calldata
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
5044 msg
.rpc_argp
= &calldata
->arg
;
5045 msg
.rpc_resp
= &calldata
->res
;
5046 task_setup_data
.callback_data
= calldata
;
5047 task
= rpc_run_task(&task_setup_data
);
5049 status
= PTR_ERR(task
);
5052 dprintk("<-- %s status=%d\n", __func__
, status
);
5055 #endif /* CONFIG_NFS_V4_1 */
5057 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
5058 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5059 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5060 .recover_open
= nfs4_open_reclaim
,
5061 .recover_lock
= nfs4_lock_reclaim
,
5062 .establish_clid
= nfs4_init_clientid
,
5063 .get_clid_cred
= nfs4_get_setclientid_cred
,
5066 #if defined(CONFIG_NFS_V4_1)
5067 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
5068 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5069 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5070 .recover_open
= nfs4_open_reclaim
,
5071 .recover_lock
= nfs4_lock_reclaim
,
5072 .establish_clid
= nfs41_init_clientid
,
5073 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5074 .reclaim_complete
= nfs41_proc_reclaim_complete
,
5076 #endif /* CONFIG_NFS_V4_1 */
5078 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
5079 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5080 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5081 .recover_open
= nfs4_open_expired
,
5082 .recover_lock
= nfs4_lock_expired
,
5083 .establish_clid
= nfs4_init_clientid
,
5084 .get_clid_cred
= nfs4_get_setclientid_cred
,
5087 #if defined(CONFIG_NFS_V4_1)
5088 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
5089 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5090 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5091 .recover_open
= nfs4_open_expired
,
5092 .recover_lock
= nfs4_lock_expired
,
5093 .establish_clid
= nfs41_init_clientid
,
5094 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5096 #endif /* CONFIG_NFS_V4_1 */
5098 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
5099 .sched_state_renewal
= nfs4_proc_async_renew
,
5100 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
5101 .renew_lease
= nfs4_proc_renew
,
5104 #if defined(CONFIG_NFS_V4_1)
5105 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
5106 .sched_state_renewal
= nfs41_proc_async_sequence
,
5107 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
5108 .renew_lease
= nfs4_proc_sequence
,
5113 * Per minor version reboot and network partition recovery ops
5116 struct nfs4_state_recovery_ops
*nfs4_reboot_recovery_ops
[] = {
5117 &nfs40_reboot_recovery_ops
,
5118 #if defined(CONFIG_NFS_V4_1)
5119 &nfs41_reboot_recovery_ops
,
5123 struct nfs4_state_recovery_ops
*nfs4_nograce_recovery_ops
[] = {
5124 &nfs40_nograce_recovery_ops
,
5125 #if defined(CONFIG_NFS_V4_1)
5126 &nfs41_nograce_recovery_ops
,
5130 struct nfs4_state_maintenance_ops
*nfs4_state_renewal_ops
[] = {
5131 &nfs40_state_renewal_ops
,
5132 #if defined(CONFIG_NFS_V4_1)
5133 &nfs41_state_renewal_ops
,
5137 static const struct inode_operations nfs4_file_inode_operations
= {
5138 .permission
= nfs_permission
,
5139 .getattr
= nfs_getattr
,
5140 .setattr
= nfs_setattr
,
5141 .getxattr
= nfs4_getxattr
,
5142 .setxattr
= nfs4_setxattr
,
5143 .listxattr
= nfs4_listxattr
,
5146 const struct nfs_rpc_ops nfs_v4_clientops
= {
5147 .version
= 4, /* protocol version */
5148 .dentry_ops
= &nfs4_dentry_operations
,
5149 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5150 .file_inode_ops
= &nfs4_file_inode_operations
,
5151 .getroot
= nfs4_proc_get_root
,
5152 .getattr
= nfs4_proc_getattr
,
5153 .setattr
= nfs4_proc_setattr
,
5154 .lookupfh
= nfs4_proc_lookupfh
,
5155 .lookup
= nfs4_proc_lookup
,
5156 .access
= nfs4_proc_access
,
5157 .readlink
= nfs4_proc_readlink
,
5158 .create
= nfs4_proc_create
,
5159 .remove
= nfs4_proc_remove
,
5160 .unlink_setup
= nfs4_proc_unlink_setup
,
5161 .unlink_done
= nfs4_proc_unlink_done
,
5162 .rename
= nfs4_proc_rename
,
5163 .link
= nfs4_proc_link
,
5164 .symlink
= nfs4_proc_symlink
,
5165 .mkdir
= nfs4_proc_mkdir
,
5166 .rmdir
= nfs4_proc_remove
,
5167 .readdir
= nfs4_proc_readdir
,
5168 .mknod
= nfs4_proc_mknod
,
5169 .statfs
= nfs4_proc_statfs
,
5170 .fsinfo
= nfs4_proc_fsinfo
,
5171 .pathconf
= nfs4_proc_pathconf
,
5172 .set_capabilities
= nfs4_server_capabilities
,
5173 .decode_dirent
= nfs4_decode_dirent
,
5174 .read_setup
= nfs4_proc_read_setup
,
5175 .read_done
= nfs4_read_done
,
5176 .write_setup
= nfs4_proc_write_setup
,
5177 .write_done
= nfs4_write_done
,
5178 .commit_setup
= nfs4_proc_commit_setup
,
5179 .commit_done
= nfs4_commit_done
,
5180 .lock
= nfs4_proc_lock
,
5181 .clear_acl_cache
= nfs4_zap_acl_attr
,
5182 .close_context
= nfs4_close_context
,