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 set_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
);
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.
323 nfs4_free_slot(struct nfs4_slot_table
*tbl
, u8 free_slotid
)
325 int slotid
= free_slotid
;
327 spin_lock(&tbl
->slot_tbl_lock
);
328 /* clear used bit in bitmap */
329 __clear_bit(slotid
, tbl
->used_slots
);
331 /* update highest_used_slotid when it is freed */
332 if (slotid
== tbl
->highest_used_slotid
) {
333 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
334 if (slotid
>= 0 && slotid
< tbl
->max_slots
)
335 tbl
->highest_used_slotid
= slotid
;
337 tbl
->highest_used_slotid
= -1;
339 rpc_wake_up_next(&tbl
->slot_tbl_waitq
);
340 spin_unlock(&tbl
->slot_tbl_lock
);
341 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
342 free_slotid
, tbl
->highest_used_slotid
);
345 void nfs41_sequence_free_slot(const struct nfs_client
*clp
,
346 struct nfs4_sequence_res
*res
)
348 struct nfs4_slot_table
*tbl
;
350 if (!nfs4_has_session(clp
)) {
351 dprintk("%s: No session\n", __func__
);
354 tbl
= &clp
->cl_session
->fc_slot_table
;
355 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
) {
356 dprintk("%s: No slot\n", __func__
);
357 /* just wake up the next guy waiting since
358 * we may have not consumed a slot after all */
359 rpc_wake_up_next(&tbl
->slot_tbl_waitq
);
362 nfs4_free_slot(tbl
, res
->sr_slotid
);
363 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
366 static void nfs41_sequence_done(struct nfs_client
*clp
,
367 struct nfs4_sequence_res
*res
,
370 unsigned long timestamp
;
371 struct nfs4_slot_table
*tbl
;
372 struct nfs4_slot
*slot
;
375 * sr_status remains 1 if an RPC level error occurred. The server
376 * may or may not have processed the sequence operation..
377 * Proceed as if the server received and processed the sequence
380 if (res
->sr_status
== 1)
381 res
->sr_status
= NFS_OK
;
383 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
384 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
)
387 tbl
= &clp
->cl_session
->fc_slot_table
;
388 slot
= tbl
->slots
+ res
->sr_slotid
;
390 if (res
->sr_status
== 0) {
391 /* Update the slot's sequence and clientid lease timer */
393 timestamp
= res
->sr_renewal_time
;
394 spin_lock(&clp
->cl_lock
);
395 if (time_before(clp
->cl_last_renewal
, timestamp
))
396 clp
->cl_last_renewal
= timestamp
;
397 spin_unlock(&clp
->cl_lock
);
401 /* The session may be reset by one of the error handlers. */
402 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
403 nfs41_sequence_free_slot(clp
, res
);
407 * nfs4_find_slot - efficiently look for a free slot
409 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
410 * If found, we mark the slot as used, update the highest_used_slotid,
411 * and respectively set up the sequence operation args.
412 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
414 * Note: must be called with under the slot_tbl_lock.
417 nfs4_find_slot(struct nfs4_slot_table
*tbl
, struct rpc_task
*task
)
420 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
421 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
423 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
424 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
426 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
427 if (slotid
>= tbl
->max_slots
)
429 __set_bit(slotid
, tbl
->used_slots
);
430 if (slotid
> tbl
->highest_used_slotid
)
431 tbl
->highest_used_slotid
= slotid
;
434 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
435 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
439 static int nfs41_setup_sequence(struct nfs4_session
*session
,
440 struct nfs4_sequence_args
*args
,
441 struct nfs4_sequence_res
*res
,
443 struct rpc_task
*task
)
445 struct nfs4_slot
*slot
;
446 struct nfs4_slot_table
*tbl
;
449 dprintk("--> %s\n", __func__
);
450 /* slot already allocated? */
451 if (res
->sr_slotid
!= NFS4_MAX_SLOT_TABLE
)
454 memset(res
, 0, sizeof(*res
));
455 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
456 tbl
= &session
->fc_slot_table
;
458 spin_lock(&tbl
->slot_tbl_lock
);
459 if (test_bit(NFS4CLNT_SESSION_RESET
, &session
->clp
->cl_state
)) {
460 if (tbl
->highest_used_slotid
!= -1) {
461 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
462 spin_unlock(&tbl
->slot_tbl_lock
);
463 dprintk("<-- %s: Session reset: draining\n", __func__
);
467 /* The slot table is empty; start the reset thread */
468 dprintk("%s Session Reset\n", __func__
);
469 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
470 nfs4_schedule_state_manager(session
->clp
);
471 spin_unlock(&tbl
->slot_tbl_lock
);
475 slotid
= nfs4_find_slot(tbl
, task
);
476 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
477 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
478 spin_unlock(&tbl
->slot_tbl_lock
);
479 dprintk("<-- %s: no free slots\n", __func__
);
482 spin_unlock(&tbl
->slot_tbl_lock
);
484 slot
= tbl
->slots
+ slotid
;
485 args
->sa_session
= session
;
486 args
->sa_slotid
= slotid
;
487 args
->sa_cache_this
= cache_reply
;
489 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
491 res
->sr_session
= session
;
492 res
->sr_slotid
= slotid
;
493 res
->sr_renewal_time
= jiffies
;
495 * sr_status is only set in decode_sequence, and so will remain
496 * set to 1 if an rpc level failure occurs.
502 int nfs4_setup_sequence(struct nfs_client
*clp
,
503 struct nfs4_sequence_args
*args
,
504 struct nfs4_sequence_res
*res
,
506 struct rpc_task
*task
)
510 dprintk("--> %s clp %p session %p sr_slotid %d\n",
511 __func__
, clp
, clp
->cl_session
, res
->sr_slotid
);
513 if (!nfs4_has_session(clp
))
515 ret
= nfs41_setup_sequence(clp
->cl_session
, args
, res
, cache_reply
,
517 if (ret
&& ret
!= -EAGAIN
) {
518 /* terminate rpc task */
519 task
->tk_status
= ret
;
520 task
->tk_action
= NULL
;
523 dprintk("<-- %s status=%d\n", __func__
, ret
);
527 struct nfs41_call_sync_data
{
528 struct nfs_client
*clp
;
529 struct nfs4_sequence_args
*seq_args
;
530 struct nfs4_sequence_res
*seq_res
;
534 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
536 struct nfs41_call_sync_data
*data
= calldata
;
538 dprintk("--> %s data->clp->cl_session %p\n", __func__
,
539 data
->clp
->cl_session
);
540 if (nfs4_setup_sequence(data
->clp
, data
->seq_args
,
541 data
->seq_res
, data
->cache_reply
, task
))
543 rpc_call_start(task
);
546 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
548 struct nfs41_call_sync_data
*data
= calldata
;
550 nfs41_sequence_done(data
->clp
, data
->seq_res
, task
->tk_status
);
551 nfs41_sequence_free_slot(data
->clp
, data
->seq_res
);
554 struct rpc_call_ops nfs41_call_sync_ops
= {
555 .rpc_call_prepare
= nfs41_call_sync_prepare
,
556 .rpc_call_done
= nfs41_call_sync_done
,
559 static int nfs4_call_sync_sequence(struct nfs_client
*clp
,
560 struct rpc_clnt
*clnt
,
561 struct rpc_message
*msg
,
562 struct nfs4_sequence_args
*args
,
563 struct nfs4_sequence_res
*res
,
567 struct rpc_task
*task
;
568 struct nfs41_call_sync_data data
= {
572 .cache_reply
= cache_reply
,
574 struct rpc_task_setup task_setup
= {
577 .callback_ops
= &nfs41_call_sync_ops
,
578 .callback_data
= &data
581 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
582 task
= rpc_run_task(&task_setup
);
586 ret
= task
->tk_status
;
592 int _nfs4_call_sync_session(struct nfs_server
*server
,
593 struct rpc_message
*msg
,
594 struct nfs4_sequence_args
*args
,
595 struct nfs4_sequence_res
*res
,
598 return nfs4_call_sync_sequence(server
->nfs_client
, server
->client
,
599 msg
, args
, res
, cache_reply
);
602 #endif /* CONFIG_NFS_V4_1 */
604 int _nfs4_call_sync(struct nfs_server
*server
,
605 struct rpc_message
*msg
,
606 struct nfs4_sequence_args
*args
,
607 struct nfs4_sequence_res
*res
,
610 args
->sa_session
= res
->sr_session
= NULL
;
611 return rpc_call_sync(server
->client
, msg
, 0);
614 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
615 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
616 &(res)->seq_res, (cache_reply))
618 static void nfs4_sequence_done(const struct nfs_server
*server
,
619 struct nfs4_sequence_res
*res
, int rpc_status
)
621 #ifdef CONFIG_NFS_V4_1
622 if (nfs4_has_session(server
->nfs_client
))
623 nfs41_sequence_done(server
->nfs_client
, res
, rpc_status
);
624 #endif /* CONFIG_NFS_V4_1 */
627 void nfs4_restart_rpc(struct rpc_task
*task
, const struct nfs_client
*clp
,
628 struct nfs4_sequence_res
*res
)
630 #ifdef CONFIG_NFS_V4_1
631 if (nfs4_has_session(clp
)) {
632 nfs41_sequence_free_slot(clp
, res
);
633 rpc_restart_call_prepare(task
);
636 #endif /* CONFIG_NFS_V4_1 */
637 rpc_restart_call(task
);
640 /* no restart, therefore free slot here */
641 static void nfs4_sequence_done_free_slot(const struct nfs_server
*server
,
642 struct nfs4_sequence_res
*res
,
645 nfs4_sequence_done(server
, res
, rpc_status
);
646 nfs4_sequence_free_slot(server
->nfs_client
, res
);
649 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
651 struct nfs_inode
*nfsi
= NFS_I(dir
);
653 spin_lock(&dir
->i_lock
);
654 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
655 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
656 nfs_force_lookup_revalidate(dir
);
657 nfsi
->change_attr
= cinfo
->after
;
658 spin_unlock(&dir
->i_lock
);
661 struct nfs4_opendata
{
663 struct nfs_openargs o_arg
;
664 struct nfs_openres o_res
;
665 struct nfs_open_confirmargs c_arg
;
666 struct nfs_open_confirmres c_res
;
667 struct nfs_fattr f_attr
;
668 struct nfs_fattr dir_attr
;
671 struct nfs4_state_owner
*owner
;
672 struct nfs4_state
*state
;
674 unsigned long timestamp
;
675 unsigned int rpc_done
: 1;
681 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
683 p
->o_res
.f_attr
= &p
->f_attr
;
684 p
->o_res
.dir_attr
= &p
->dir_attr
;
685 p
->o_res
.seqid
= p
->o_arg
.seqid
;
686 p
->c_res
.seqid
= p
->c_arg
.seqid
;
687 p
->o_res
.server
= p
->o_arg
.server
;
688 nfs_fattr_init(&p
->f_attr
);
689 nfs_fattr_init(&p
->dir_attr
);
690 p
->o_res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
693 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
694 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
695 const struct iattr
*attrs
)
697 struct dentry
*parent
= dget_parent(path
->dentry
);
698 struct inode
*dir
= parent
->d_inode
;
699 struct nfs_server
*server
= NFS_SERVER(dir
);
700 struct nfs4_opendata
*p
;
702 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
705 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
706 if (p
->o_arg
.seqid
== NULL
)
708 p
->path
.mnt
= mntget(path
->mnt
);
709 p
->path
.dentry
= dget(path
->dentry
);
712 atomic_inc(&sp
->so_count
);
713 p
->o_arg
.fh
= NFS_FH(dir
);
714 p
->o_arg
.open_flags
= flags
;
715 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
716 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
717 p
->o_arg
.id
= sp
->so_owner_id
.id
;
718 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
719 p
->o_arg
.server
= server
;
720 p
->o_arg
.bitmask
= server
->attr_bitmask
;
721 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
722 if (flags
& O_EXCL
) {
723 u32
*s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
726 } else if (flags
& O_CREAT
) {
727 p
->o_arg
.u
.attrs
= &p
->attrs
;
728 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
730 p
->c_arg
.fh
= &p
->o_res
.fh
;
731 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
732 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
733 nfs4_init_opendata_res(p
);
743 static void nfs4_opendata_free(struct kref
*kref
)
745 struct nfs4_opendata
*p
= container_of(kref
,
746 struct nfs4_opendata
, kref
);
748 nfs_free_seqid(p
->o_arg
.seqid
);
749 if (p
->state
!= NULL
)
750 nfs4_put_open_state(p
->state
);
751 nfs4_put_state_owner(p
->owner
);
757 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
760 kref_put(&p
->kref
, nfs4_opendata_free
);
763 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
767 ret
= rpc_wait_for_completion_task(task
);
771 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
775 if (open_mode
& O_EXCL
)
777 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
779 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0;
782 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0;
784 case FMODE_READ
|FMODE_WRITE
:
785 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0;
791 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
793 if ((delegation
->type
& fmode
) != fmode
)
795 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
797 nfs_mark_delegation_referenced(delegation
);
801 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
810 case FMODE_READ
|FMODE_WRITE
:
813 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
816 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
818 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
819 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
820 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
823 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
826 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
828 case FMODE_READ
|FMODE_WRITE
:
829 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
833 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
835 write_seqlock(&state
->seqlock
);
836 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
837 write_sequnlock(&state
->seqlock
);
840 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
843 * Protect the call to nfs4_state_set_mode_locked and
844 * serialise the stateid update
846 write_seqlock(&state
->seqlock
);
847 if (deleg_stateid
!= NULL
) {
848 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
849 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
851 if (open_stateid
!= NULL
)
852 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
853 write_sequnlock(&state
->seqlock
);
854 spin_lock(&state
->owner
->so_lock
);
855 update_open_stateflags(state
, fmode
);
856 spin_unlock(&state
->owner
->so_lock
);
859 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
861 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
862 struct nfs_delegation
*deleg_cur
;
865 fmode
&= (FMODE_READ
|FMODE_WRITE
);
868 deleg_cur
= rcu_dereference(nfsi
->delegation
);
869 if (deleg_cur
== NULL
)
872 spin_lock(&deleg_cur
->lock
);
873 if (nfsi
->delegation
!= deleg_cur
||
874 (deleg_cur
->type
& fmode
) != fmode
)
875 goto no_delegation_unlock
;
877 if (delegation
== NULL
)
878 delegation
= &deleg_cur
->stateid
;
879 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
880 goto no_delegation_unlock
;
882 nfs_mark_delegation_referenced(deleg_cur
);
883 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
885 no_delegation_unlock
:
886 spin_unlock(&deleg_cur
->lock
);
890 if (!ret
&& open_stateid
!= NULL
) {
891 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
899 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
901 struct nfs_delegation
*delegation
;
904 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
905 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
910 nfs_inode_return_delegation(inode
);
913 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
915 struct nfs4_state
*state
= opendata
->state
;
916 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
917 struct nfs_delegation
*delegation
;
918 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
919 fmode_t fmode
= opendata
->o_arg
.fmode
;
920 nfs4_stateid stateid
;
924 if (can_open_cached(state
, fmode
, open_mode
)) {
925 spin_lock(&state
->owner
->so_lock
);
926 if (can_open_cached(state
, fmode
, open_mode
)) {
927 update_open_stateflags(state
, fmode
);
928 spin_unlock(&state
->owner
->so_lock
);
929 goto out_return_state
;
931 spin_unlock(&state
->owner
->so_lock
);
934 delegation
= rcu_dereference(nfsi
->delegation
);
935 if (delegation
== NULL
||
936 !can_open_delegated(delegation
, fmode
)) {
940 /* Save the delegation */
941 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
943 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
948 /* Try to update the stateid using the delegation */
949 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
950 goto out_return_state
;
955 atomic_inc(&state
->count
);
959 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
962 struct nfs4_state
*state
= NULL
;
963 struct nfs_delegation
*delegation
;
966 if (!data
->rpc_done
) {
967 state
= nfs4_try_open_cached(data
);
972 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
974 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
975 ret
= PTR_ERR(inode
);
979 state
= nfs4_get_open_state(inode
, data
->owner
);
982 if (data
->o_res
.delegation_type
!= 0) {
983 int delegation_flags
= 0;
986 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
988 delegation_flags
= delegation
->flags
;
990 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
991 nfs_inode_set_delegation(state
->inode
,
992 data
->owner
->so_cred
,
995 nfs_inode_reclaim_delegation(state
->inode
,
996 data
->owner
->so_cred
,
1000 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1008 return ERR_PTR(ret
);
1011 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1013 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1014 struct nfs_open_context
*ctx
;
1016 spin_lock(&state
->inode
->i_lock
);
1017 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1018 if (ctx
->state
!= state
)
1020 get_nfs_open_context(ctx
);
1021 spin_unlock(&state
->inode
->i_lock
);
1024 spin_unlock(&state
->inode
->i_lock
);
1025 return ERR_PTR(-ENOENT
);
1028 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1030 struct nfs4_opendata
*opendata
;
1032 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
);
1033 if (opendata
== NULL
)
1034 return ERR_PTR(-ENOMEM
);
1035 opendata
->state
= state
;
1036 atomic_inc(&state
->count
);
1040 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1042 struct nfs4_state
*newstate
;
1045 opendata
->o_arg
.open_flags
= 0;
1046 opendata
->o_arg
.fmode
= fmode
;
1047 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1048 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1049 nfs4_init_opendata_res(opendata
);
1050 ret
= _nfs4_proc_open(opendata
);
1053 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1054 if (IS_ERR(newstate
))
1055 return PTR_ERR(newstate
);
1056 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1061 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1063 struct nfs4_state
*newstate
;
1066 /* memory barrier prior to reading state->n_* */
1067 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1069 if (state
->n_rdwr
!= 0) {
1070 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1073 if (newstate
!= state
)
1076 if (state
->n_wronly
!= 0) {
1077 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1080 if (newstate
!= state
)
1083 if (state
->n_rdonly
!= 0) {
1084 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1087 if (newstate
!= state
)
1091 * We may have performed cached opens for all three recoveries.
1092 * Check if we need to update the current stateid.
1094 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1095 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1096 write_seqlock(&state
->seqlock
);
1097 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1098 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1099 write_sequnlock(&state
->seqlock
);
1106 * reclaim state on the server after a reboot.
1108 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1110 struct nfs_delegation
*delegation
;
1111 struct nfs4_opendata
*opendata
;
1112 fmode_t delegation_type
= 0;
1115 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1116 if (IS_ERR(opendata
))
1117 return PTR_ERR(opendata
);
1118 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1119 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1121 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1122 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1123 delegation_type
= delegation
->type
;
1125 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1126 status
= nfs4_open_recover(opendata
, state
);
1127 nfs4_opendata_put(opendata
);
1131 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1133 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1134 struct nfs4_exception exception
= { };
1137 err
= _nfs4_do_open_reclaim(ctx
, state
);
1138 if (err
!= -NFS4ERR_DELAY
)
1140 nfs4_handle_exception(server
, err
, &exception
);
1141 } while (exception
.retry
);
1145 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1147 struct nfs_open_context
*ctx
;
1150 ctx
= nfs4_state_find_open_context(state
);
1152 return PTR_ERR(ctx
);
1153 ret
= nfs4_do_open_reclaim(ctx
, state
);
1154 put_nfs_open_context(ctx
);
1158 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1160 struct nfs4_opendata
*opendata
;
1163 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1164 if (IS_ERR(opendata
))
1165 return PTR_ERR(opendata
);
1166 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1167 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1168 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1169 ret
= nfs4_open_recover(opendata
, state
);
1170 nfs4_opendata_put(opendata
);
1174 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1176 struct nfs4_exception exception
= { };
1177 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1180 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1186 case -NFS4ERR_STALE_CLIENTID
:
1187 case -NFS4ERR_STALE_STATEID
:
1188 case -NFS4ERR_EXPIRED
:
1189 /* Don't recall a delegation if it was lost */
1190 nfs4_schedule_state_recovery(server
->nfs_client
);
1194 * The show must go on: exit, but mark the
1195 * stateid as needing recovery.
1197 case -NFS4ERR_ADMIN_REVOKED
:
1198 case -NFS4ERR_BAD_STATEID
:
1199 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
1204 err
= nfs4_handle_exception(server
, err
, &exception
);
1205 } while (exception
.retry
);
1210 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1212 struct nfs4_opendata
*data
= calldata
;
1214 data
->rpc_status
= task
->tk_status
;
1215 if (RPC_ASSASSINATED(task
))
1217 if (data
->rpc_status
== 0) {
1218 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1219 sizeof(data
->o_res
.stateid
.data
));
1220 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1221 renew_lease(data
->o_res
.server
, data
->timestamp
);
1226 static void nfs4_open_confirm_release(void *calldata
)
1228 struct nfs4_opendata
*data
= calldata
;
1229 struct nfs4_state
*state
= NULL
;
1231 /* If this request hasn't been cancelled, do nothing */
1232 if (data
->cancelled
== 0)
1234 /* In case of error, no cleanup! */
1235 if (!data
->rpc_done
)
1237 state
= nfs4_opendata_to_nfs4_state(data
);
1239 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1241 nfs4_opendata_put(data
);
1244 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1245 .rpc_call_done
= nfs4_open_confirm_done
,
1246 .rpc_release
= nfs4_open_confirm_release
,
1250 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1252 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1254 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1255 struct rpc_task
*task
;
1256 struct rpc_message msg
= {
1257 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1258 .rpc_argp
= &data
->c_arg
,
1259 .rpc_resp
= &data
->c_res
,
1260 .rpc_cred
= data
->owner
->so_cred
,
1262 struct rpc_task_setup task_setup_data
= {
1263 .rpc_client
= server
->client
,
1264 .rpc_message
= &msg
,
1265 .callback_ops
= &nfs4_open_confirm_ops
,
1266 .callback_data
= data
,
1267 .workqueue
= nfsiod_workqueue
,
1268 .flags
= RPC_TASK_ASYNC
,
1272 kref_get(&data
->kref
);
1274 data
->rpc_status
= 0;
1275 data
->timestamp
= jiffies
;
1276 task
= rpc_run_task(&task_setup_data
);
1278 return PTR_ERR(task
);
1279 status
= nfs4_wait_for_completion_rpc_task(task
);
1281 data
->cancelled
= 1;
1284 status
= data
->rpc_status
;
1289 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1291 struct nfs4_opendata
*data
= calldata
;
1292 struct nfs4_state_owner
*sp
= data
->owner
;
1294 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1297 * Check if we still need to send an OPEN call, or if we can use
1298 * a delegation instead.
1300 if (data
->state
!= NULL
) {
1301 struct nfs_delegation
*delegation
;
1303 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1306 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1307 if (delegation
!= NULL
&&
1308 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1314 /* Update sequence id. */
1315 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1316 data
->o_arg
.clientid
= sp
->so_client
->cl_clientid
;
1317 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1318 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1319 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1321 data
->timestamp
= jiffies
;
1322 if (nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
1323 &data
->o_arg
.seq_args
,
1324 &data
->o_res
.seq_res
, 1, task
))
1326 rpc_call_start(task
);
1329 task
->tk_action
= NULL
;
1333 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1335 struct nfs4_opendata
*data
= calldata
;
1337 data
->rpc_status
= task
->tk_status
;
1339 nfs4_sequence_done_free_slot(data
->o_arg
.server
, &data
->o_res
.seq_res
,
1342 if (RPC_ASSASSINATED(task
))
1344 if (task
->tk_status
== 0) {
1345 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1349 data
->rpc_status
= -ELOOP
;
1352 data
->rpc_status
= -EISDIR
;
1355 data
->rpc_status
= -ENOTDIR
;
1357 renew_lease(data
->o_res
.server
, data
->timestamp
);
1358 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1359 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1364 static void nfs4_open_release(void *calldata
)
1366 struct nfs4_opendata
*data
= calldata
;
1367 struct nfs4_state
*state
= NULL
;
1369 /* If this request hasn't been cancelled, do nothing */
1370 if (data
->cancelled
== 0)
1372 /* In case of error, no cleanup! */
1373 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1375 /* In case we need an open_confirm, no cleanup! */
1376 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1378 state
= nfs4_opendata_to_nfs4_state(data
);
1380 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1382 nfs4_opendata_put(data
);
1385 static const struct rpc_call_ops nfs4_open_ops
= {
1386 .rpc_call_prepare
= nfs4_open_prepare
,
1387 .rpc_call_done
= nfs4_open_done
,
1388 .rpc_release
= nfs4_open_release
,
1392 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1394 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1396 struct inode
*dir
= data
->dir
->d_inode
;
1397 struct nfs_server
*server
= NFS_SERVER(dir
);
1398 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1399 struct nfs_openres
*o_res
= &data
->o_res
;
1400 struct rpc_task
*task
;
1401 struct rpc_message msg
= {
1402 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1405 .rpc_cred
= data
->owner
->so_cred
,
1407 struct rpc_task_setup task_setup_data
= {
1408 .rpc_client
= server
->client
,
1409 .rpc_message
= &msg
,
1410 .callback_ops
= &nfs4_open_ops
,
1411 .callback_data
= data
,
1412 .workqueue
= nfsiod_workqueue
,
1413 .flags
= RPC_TASK_ASYNC
,
1417 kref_get(&data
->kref
);
1419 data
->rpc_status
= 0;
1420 data
->cancelled
= 0;
1421 task
= rpc_run_task(&task_setup_data
);
1423 return PTR_ERR(task
);
1424 status
= nfs4_wait_for_completion_rpc_task(task
);
1426 data
->cancelled
= 1;
1429 status
= data
->rpc_status
;
1431 if (status
!= 0 || !data
->rpc_done
)
1434 if (o_res
->fh
.size
== 0)
1435 _nfs4_proc_lookup(dir
, o_arg
->name
, &o_res
->fh
, o_res
->f_attr
);
1437 if (o_arg
->open_flags
& O_CREAT
) {
1438 update_changeattr(dir
, &o_res
->cinfo
);
1439 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1441 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1442 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1443 status
= _nfs4_proc_open_confirm(data
);
1447 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1448 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1452 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1454 struct nfs_client
*clp
= server
->nfs_client
;
1458 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1459 ret
= nfs4_wait_clnt_recover(clp
);
1462 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1463 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1465 nfs4_schedule_state_recovery(clp
);
1473 * reclaim state on the server after a network partition.
1474 * Assumes caller holds the appropriate lock
1476 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1478 struct nfs4_opendata
*opendata
;
1481 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1482 if (IS_ERR(opendata
))
1483 return PTR_ERR(opendata
);
1484 ret
= nfs4_open_recover(opendata
, state
);
1486 d_drop(ctx
->path
.dentry
);
1487 nfs4_opendata_put(opendata
);
1491 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1493 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1494 struct nfs4_exception exception
= { };
1498 err
= _nfs4_open_expired(ctx
, state
);
1502 case -NFS4ERR_GRACE
:
1503 case -NFS4ERR_DELAY
:
1504 nfs4_handle_exception(server
, err
, &exception
);
1507 } while (exception
.retry
);
1512 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1514 struct nfs_open_context
*ctx
;
1517 ctx
= nfs4_state_find_open_context(state
);
1519 return PTR_ERR(ctx
);
1520 ret
= nfs4_do_open_expired(ctx
, state
);
1521 put_nfs_open_context(ctx
);
1526 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1527 * fields corresponding to attributes that were used to store the verifier.
1528 * Make sure we clobber those fields in the later setattr call
1530 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1532 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1533 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1534 sattr
->ia_valid
|= ATTR_ATIME
;
1536 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1537 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1538 sattr
->ia_valid
|= ATTR_MTIME
;
1542 * Returns a referenced nfs4_state
1544 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
)
1546 struct nfs4_state_owner
*sp
;
1547 struct nfs4_state
*state
= NULL
;
1548 struct nfs_server
*server
= NFS_SERVER(dir
);
1549 struct nfs4_opendata
*opendata
;
1552 /* Protect against reboot recovery conflicts */
1554 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1555 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1558 status
= nfs4_recover_expired_lease(server
);
1560 goto err_put_state_owner
;
1561 if (path
->dentry
->d_inode
!= NULL
)
1562 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1564 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
);
1565 if (opendata
== NULL
)
1566 goto err_put_state_owner
;
1568 if (path
->dentry
->d_inode
!= NULL
)
1569 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1571 status
= _nfs4_proc_open(opendata
);
1573 goto err_opendata_put
;
1575 if (opendata
->o_arg
.open_flags
& O_EXCL
)
1576 nfs4_exclusive_attrset(opendata
, sattr
);
1578 state
= nfs4_opendata_to_nfs4_state(opendata
);
1579 status
= PTR_ERR(state
);
1581 goto err_opendata_put
;
1582 nfs4_opendata_put(opendata
);
1583 nfs4_put_state_owner(sp
);
1587 nfs4_opendata_put(opendata
);
1588 err_put_state_owner
:
1589 nfs4_put_state_owner(sp
);
1596 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
)
1598 struct nfs4_exception exception
= { };
1599 struct nfs4_state
*res
;
1603 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1606 /* NOTE: BAD_SEQID means the server and client disagree about the
1607 * book-keeping w.r.t. state-changing operations
1608 * (OPEN/CLOSE/LOCK/LOCKU...)
1609 * It is actually a sign of a bug on the client or on the server.
1611 * If we receive a BAD_SEQID error in the particular case of
1612 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1613 * have unhashed the old state_owner for us, and that we can
1614 * therefore safely retry using a new one. We should still warn
1615 * the user though...
1617 if (status
== -NFS4ERR_BAD_SEQID
) {
1618 printk(KERN_WARNING
"NFS: v4 server %s "
1619 " returned a bad sequence-id error!\n",
1620 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1621 exception
.retry
= 1;
1625 * BAD_STATEID on OPEN means that the server cancelled our
1626 * state before it received the OPEN_CONFIRM.
1627 * Recover by retrying the request as per the discussion
1628 * on Page 181 of RFC3530.
1630 if (status
== -NFS4ERR_BAD_STATEID
) {
1631 exception
.retry
= 1;
1634 if (status
== -EAGAIN
) {
1635 /* We must have found a delegation */
1636 exception
.retry
= 1;
1639 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1640 status
, &exception
));
1641 } while (exception
.retry
);
1645 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1646 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1647 struct nfs4_state
*state
)
1649 struct nfs_server
*server
= NFS_SERVER(inode
);
1650 struct nfs_setattrargs arg
= {
1651 .fh
= NFS_FH(inode
),
1654 .bitmask
= server
->attr_bitmask
,
1656 struct nfs_setattrres res
= {
1660 struct rpc_message msg
= {
1661 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1666 unsigned long timestamp
= jiffies
;
1669 nfs_fattr_init(fattr
);
1671 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1672 /* Use that stateid */
1673 } else if (state
!= NULL
) {
1674 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
1676 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1678 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
1679 if (status
== 0 && state
!= NULL
)
1680 renew_lease(server
, timestamp
);
1684 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1685 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1686 struct nfs4_state
*state
)
1688 struct nfs_server
*server
= NFS_SERVER(inode
);
1689 struct nfs4_exception exception
= { };
1692 err
= nfs4_handle_exception(server
,
1693 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1695 } while (exception
.retry
);
1699 struct nfs4_closedata
{
1701 struct inode
*inode
;
1702 struct nfs4_state
*state
;
1703 struct nfs_closeargs arg
;
1704 struct nfs_closeres res
;
1705 struct nfs_fattr fattr
;
1706 unsigned long timestamp
;
1709 static void nfs4_free_closedata(void *data
)
1711 struct nfs4_closedata
*calldata
= data
;
1712 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1714 nfs4_put_open_state(calldata
->state
);
1715 nfs_free_seqid(calldata
->arg
.seqid
);
1716 nfs4_put_state_owner(sp
);
1717 path_put(&calldata
->path
);
1721 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1723 struct nfs4_closedata
*calldata
= data
;
1724 struct nfs4_state
*state
= calldata
->state
;
1725 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1727 nfs4_sequence_done(server
, &calldata
->res
.seq_res
, task
->tk_status
);
1728 if (RPC_ASSASSINATED(task
))
1730 /* hmm. we are done with the inode, and in the process of freeing
1731 * the state_owner. we keep this around to process errors
1733 switch (task
->tk_status
) {
1735 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1736 renew_lease(server
, calldata
->timestamp
);
1738 case -NFS4ERR_STALE_STATEID
:
1739 case -NFS4ERR_OLD_STATEID
:
1740 case -NFS4ERR_BAD_STATEID
:
1741 case -NFS4ERR_EXPIRED
:
1742 if (calldata
->arg
.fmode
== 0)
1745 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
) {
1746 nfs4_restart_rpc(task
, server
->nfs_client
,
1747 &calldata
->res
.seq_res
);
1751 nfs4_sequence_free_slot(server
->nfs_client
, &calldata
->res
.seq_res
);
1752 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1755 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1757 struct nfs4_closedata
*calldata
= data
;
1758 struct nfs4_state
*state
= calldata
->state
;
1759 int clear_rd
, clear_wr
, clear_rdwr
;
1761 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1764 clear_rd
= clear_wr
= clear_rdwr
= 0;
1765 spin_lock(&state
->owner
->so_lock
);
1766 /* Calculate the change in open mode */
1767 if (state
->n_rdwr
== 0) {
1768 if (state
->n_rdonly
== 0) {
1769 clear_rd
|= test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1770 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1772 if (state
->n_wronly
== 0) {
1773 clear_wr
|= test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1774 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1777 spin_unlock(&state
->owner
->so_lock
);
1778 if (!clear_rd
&& !clear_wr
&& !clear_rdwr
) {
1779 /* Note: exit _without_ calling nfs4_close_done */
1780 task
->tk_action
= NULL
;
1783 nfs_fattr_init(calldata
->res
.fattr
);
1784 if (test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0) {
1785 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1786 calldata
->arg
.fmode
= FMODE_READ
;
1787 } else if (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0) {
1788 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1789 calldata
->arg
.fmode
= FMODE_WRITE
;
1791 calldata
->timestamp
= jiffies
;
1792 if (nfs4_setup_sequence((NFS_SERVER(calldata
->inode
))->nfs_client
,
1793 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1796 rpc_call_start(task
);
1799 static const struct rpc_call_ops nfs4_close_ops
= {
1800 .rpc_call_prepare
= nfs4_close_prepare
,
1801 .rpc_call_done
= nfs4_close_done
,
1802 .rpc_release
= nfs4_free_closedata
,
1806 * It is possible for data to be read/written from a mem-mapped file
1807 * after the sys_close call (which hits the vfs layer as a flush).
1808 * This means that we can't safely call nfsv4 close on a file until
1809 * the inode is cleared. This in turn means that we are not good
1810 * NFSv4 citizens - we do not indicate to the server to update the file's
1811 * share state even when we are done with one of the three share
1812 * stateid's in the inode.
1814 * NOTE: Caller must be holding the sp->so_owner semaphore!
1816 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, int wait
)
1818 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1819 struct nfs4_closedata
*calldata
;
1820 struct nfs4_state_owner
*sp
= state
->owner
;
1821 struct rpc_task
*task
;
1822 struct rpc_message msg
= {
1823 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1824 .rpc_cred
= state
->owner
->so_cred
,
1826 struct rpc_task_setup task_setup_data
= {
1827 .rpc_client
= server
->client
,
1828 .rpc_message
= &msg
,
1829 .callback_ops
= &nfs4_close_ops
,
1830 .workqueue
= nfsiod_workqueue
,
1831 .flags
= RPC_TASK_ASYNC
,
1833 int status
= -ENOMEM
;
1835 calldata
= kzalloc(sizeof(*calldata
), GFP_KERNEL
);
1836 if (calldata
== NULL
)
1838 calldata
->inode
= state
->inode
;
1839 calldata
->state
= state
;
1840 calldata
->arg
.fh
= NFS_FH(state
->inode
);
1841 calldata
->arg
.stateid
= &state
->open_stateid
;
1842 if (nfs4_has_session(server
->nfs_client
))
1843 memset(calldata
->arg
.stateid
->data
, 0, 4); /* clear seqid */
1844 /* Serialization for the sequence id */
1845 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
1846 if (calldata
->arg
.seqid
== NULL
)
1847 goto out_free_calldata
;
1848 calldata
->arg
.fmode
= 0;
1849 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
1850 calldata
->res
.fattr
= &calldata
->fattr
;
1851 calldata
->res
.seqid
= calldata
->arg
.seqid
;
1852 calldata
->res
.server
= server
;
1853 calldata
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
1854 calldata
->path
.mnt
= mntget(path
->mnt
);
1855 calldata
->path
.dentry
= dget(path
->dentry
);
1857 msg
.rpc_argp
= &calldata
->arg
,
1858 msg
.rpc_resp
= &calldata
->res
,
1859 task_setup_data
.callback_data
= calldata
;
1860 task
= rpc_run_task(&task_setup_data
);
1862 return PTR_ERR(task
);
1865 status
= rpc_wait_for_completion_task(task
);
1871 nfs4_put_open_state(state
);
1872 nfs4_put_state_owner(sp
);
1876 static int nfs4_intent_set_file(struct nameidata
*nd
, struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
)
1881 /* If the open_intent is for execute, we have an extra check to make */
1882 if (fmode
& FMODE_EXEC
) {
1883 ret
= nfs_may_open(state
->inode
,
1884 state
->owner
->so_cred
,
1885 nd
->intent
.open
.flags
);
1889 filp
= lookup_instantiate_filp(nd
, path
->dentry
, NULL
);
1890 if (!IS_ERR(filp
)) {
1891 struct nfs_open_context
*ctx
;
1892 ctx
= nfs_file_open_context(filp
);
1896 ret
= PTR_ERR(filp
);
1898 nfs4_close_sync(path
, state
, fmode
& (FMODE_READ
|FMODE_WRITE
));
1903 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
1905 struct path path
= {
1906 .mnt
= nd
->path
.mnt
,
1909 struct dentry
*parent
;
1911 struct rpc_cred
*cred
;
1912 struct nfs4_state
*state
;
1914 fmode_t fmode
= nd
->intent
.open
.flags
& (FMODE_READ
| FMODE_WRITE
| FMODE_EXEC
);
1916 if (nd
->flags
& LOOKUP_CREATE
) {
1917 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
1918 attr
.ia_valid
= ATTR_MODE
;
1919 if (!IS_POSIXACL(dir
))
1920 attr
.ia_mode
&= ~current_umask();
1923 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
1926 cred
= rpc_lookup_cred();
1928 return (struct dentry
*)cred
;
1929 parent
= dentry
->d_parent
;
1930 /* Protect against concurrent sillydeletes */
1931 nfs_block_sillyrename(parent
);
1932 state
= nfs4_do_open(dir
, &path
, fmode
, nd
->intent
.open
.flags
, &attr
, cred
);
1934 if (IS_ERR(state
)) {
1935 if (PTR_ERR(state
) == -ENOENT
) {
1936 d_add(dentry
, NULL
);
1937 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1939 nfs_unblock_sillyrename(parent
);
1940 return (struct dentry
*)state
;
1942 res
= d_add_unique(dentry
, igrab(state
->inode
));
1945 nfs_set_verifier(path
.dentry
, nfs_save_change_attribute(dir
));
1946 nfs_unblock_sillyrename(parent
);
1947 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
1952 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1954 struct path path
= {
1955 .mnt
= nd
->path
.mnt
,
1958 struct rpc_cred
*cred
;
1959 struct nfs4_state
*state
;
1960 fmode_t fmode
= openflags
& (FMODE_READ
| FMODE_WRITE
);
1962 cred
= rpc_lookup_cred();
1964 return PTR_ERR(cred
);
1965 state
= nfs4_do_open(dir
, &path
, fmode
, openflags
, NULL
, cred
);
1967 if (IS_ERR(state
)) {
1968 switch (PTR_ERR(state
)) {
1974 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1980 if (state
->inode
== dentry
->d_inode
) {
1981 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1982 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
1985 nfs4_close_sync(&path
, state
, fmode
);
1991 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
1993 if (ctx
->state
== NULL
)
1996 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
1998 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
2001 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2003 struct nfs4_server_caps_arg args
= {
2006 struct nfs4_server_caps_res res
= {};
2007 struct rpc_message msg
= {
2008 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2014 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2016 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2017 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2018 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2019 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2020 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2021 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2022 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2023 server
->caps
|= NFS_CAP_ACLS
;
2024 if (res
.has_links
!= 0)
2025 server
->caps
|= NFS_CAP_HARDLINKS
;
2026 if (res
.has_symlinks
!= 0)
2027 server
->caps
|= NFS_CAP_SYMLINKS
;
2028 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2029 server
->caps
|= NFS_CAP_FILEID
;
2030 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2031 server
->caps
|= NFS_CAP_MODE
;
2032 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2033 server
->caps
|= NFS_CAP_NLINK
;
2034 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2035 server
->caps
|= NFS_CAP_OWNER
;
2036 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2037 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2038 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2039 server
->caps
|= NFS_CAP_ATIME
;
2040 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2041 server
->caps
|= NFS_CAP_CTIME
;
2042 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2043 server
->caps
|= NFS_CAP_MTIME
;
2045 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2046 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2047 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2048 server
->acl_bitmask
= res
.acl_bitmask
;
2054 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2056 struct nfs4_exception exception
= { };
2059 err
= nfs4_handle_exception(server
,
2060 _nfs4_server_capabilities(server
, fhandle
),
2062 } while (exception
.retry
);
2066 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2067 struct nfs_fsinfo
*info
)
2069 struct nfs4_lookup_root_arg args
= {
2070 .bitmask
= nfs4_fattr_bitmap
,
2072 struct nfs4_lookup_res res
= {
2074 .fattr
= info
->fattr
,
2077 struct rpc_message msg
= {
2078 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2083 nfs_fattr_init(info
->fattr
);
2084 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2087 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2088 struct nfs_fsinfo
*info
)
2090 struct nfs4_exception exception
= { };
2093 err
= nfs4_handle_exception(server
,
2094 _nfs4_lookup_root(server
, fhandle
, info
),
2096 } while (exception
.retry
);
2101 * get the file handle for the "/" directory on the server
2103 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2104 struct nfs_fsinfo
*info
)
2108 status
= nfs4_lookup_root(server
, fhandle
, info
);
2110 status
= nfs4_server_capabilities(server
, fhandle
);
2112 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2113 return nfs4_map_errors(status
);
2117 * Get locations and (maybe) other attributes of a referral.
2118 * Note that we'll actually follow the referral later when
2119 * we detect fsid mismatch in inode revalidation
2121 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2123 int status
= -ENOMEM
;
2124 struct page
*page
= NULL
;
2125 struct nfs4_fs_locations
*locations
= NULL
;
2127 page
= alloc_page(GFP_KERNEL
);
2130 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2131 if (locations
== NULL
)
2134 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2137 /* Make sure server returned a different fsid for the referral */
2138 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2139 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2144 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2145 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2147 fattr
->mode
= S_IFDIR
;
2148 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2157 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2159 struct nfs4_getattr_arg args
= {
2161 .bitmask
= server
->attr_bitmask
,
2163 struct nfs4_getattr_res res
= {
2167 struct rpc_message msg
= {
2168 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2173 nfs_fattr_init(fattr
);
2174 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2177 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2179 struct nfs4_exception exception
= { };
2182 err
= nfs4_handle_exception(server
,
2183 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2185 } while (exception
.retry
);
2190 * The file is not closed if it is opened due to the a request to change
2191 * the size of the file. The open call will not be needed once the
2192 * VFS layer lookup-intents are implemented.
2194 * Close is called when the inode is destroyed.
2195 * If we haven't opened the file for O_WRONLY, we
2196 * need to in the size_change case to obtain a stateid.
2199 * Because OPEN is always done by name in nfsv4, it is
2200 * possible that we opened a different file by the same
2201 * name. We can recognize this race condition, but we
2202 * can't do anything about it besides returning an error.
2204 * This will be fixed with VFS changes (lookup-intent).
2207 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2208 struct iattr
*sattr
)
2210 struct inode
*inode
= dentry
->d_inode
;
2211 struct rpc_cred
*cred
= NULL
;
2212 struct nfs4_state
*state
= NULL
;
2215 nfs_fattr_init(fattr
);
2217 /* Search for an existing open(O_WRITE) file */
2218 if (sattr
->ia_valid
& ATTR_FILE
) {
2219 struct nfs_open_context
*ctx
;
2221 ctx
= nfs_file_open_context(sattr
->ia_file
);
2228 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2230 nfs_setattr_update_inode(inode
, sattr
);
2234 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
2235 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2236 struct nfs_fattr
*fattr
)
2239 struct nfs4_lookup_arg args
= {
2240 .bitmask
= server
->attr_bitmask
,
2244 struct nfs4_lookup_res res
= {
2249 struct rpc_message msg
= {
2250 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2255 nfs_fattr_init(fattr
);
2257 dprintk("NFS call lookupfh %s\n", name
->name
);
2258 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2259 dprintk("NFS reply lookupfh: %d\n", status
);
2263 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2264 struct qstr
*name
, struct nfs_fh
*fhandle
,
2265 struct nfs_fattr
*fattr
)
2267 struct nfs4_exception exception
= { };
2270 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
2272 if (err
== -NFS4ERR_MOVED
) {
2276 err
= nfs4_handle_exception(server
, err
, &exception
);
2277 } while (exception
.retry
);
2281 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
2282 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2286 dprintk("NFS call lookup %s\n", name
->name
);
2287 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2288 if (status
== -NFS4ERR_MOVED
)
2289 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2290 dprintk("NFS reply lookup: %d\n", status
);
2294 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2296 struct nfs4_exception exception
= { };
2299 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2300 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
2302 } while (exception
.retry
);
2306 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2308 struct nfs_server
*server
= NFS_SERVER(inode
);
2309 struct nfs_fattr fattr
;
2310 struct nfs4_accessargs args
= {
2311 .fh
= NFS_FH(inode
),
2312 .bitmask
= server
->attr_bitmask
,
2314 struct nfs4_accessres res
= {
2318 struct rpc_message msg
= {
2319 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2322 .rpc_cred
= entry
->cred
,
2324 int mode
= entry
->mask
;
2328 * Determine which access bits we want to ask for...
2330 if (mode
& MAY_READ
)
2331 args
.access
|= NFS4_ACCESS_READ
;
2332 if (S_ISDIR(inode
->i_mode
)) {
2333 if (mode
& MAY_WRITE
)
2334 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2335 if (mode
& MAY_EXEC
)
2336 args
.access
|= NFS4_ACCESS_LOOKUP
;
2338 if (mode
& MAY_WRITE
)
2339 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2340 if (mode
& MAY_EXEC
)
2341 args
.access
|= NFS4_ACCESS_EXECUTE
;
2343 nfs_fattr_init(&fattr
);
2344 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2347 if (res
.access
& NFS4_ACCESS_READ
)
2348 entry
->mask
|= MAY_READ
;
2349 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2350 entry
->mask
|= MAY_WRITE
;
2351 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2352 entry
->mask
|= MAY_EXEC
;
2353 nfs_refresh_inode(inode
, &fattr
);
2358 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2360 struct nfs4_exception exception
= { };
2363 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2364 _nfs4_proc_access(inode
, entry
),
2366 } while (exception
.retry
);
2371 * TODO: For the time being, we don't try to get any attributes
2372 * along with any of the zero-copy operations READ, READDIR,
2375 * In the case of the first three, we want to put the GETATTR
2376 * after the read-type operation -- this is because it is hard
2377 * to predict the length of a GETATTR response in v4, and thus
2378 * align the READ data correctly. This means that the GETATTR
2379 * may end up partially falling into the page cache, and we should
2380 * shift it into the 'tail' of the xdr_buf before processing.
2381 * To do this efficiently, we need to know the total length
2382 * of data received, which doesn't seem to be available outside
2385 * In the case of WRITE, we also want to put the GETATTR after
2386 * the operation -- in this case because we want to make sure
2387 * we get the post-operation mtime and size. This means that
2388 * we can't use xdr_encode_pages() as written: we need a variant
2389 * of it which would leave room in the 'tail' iovec.
2391 * Both of these changes to the XDR layer would in fact be quite
2392 * minor, but I decided to leave them for a subsequent patch.
2394 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2395 unsigned int pgbase
, unsigned int pglen
)
2397 struct nfs4_readlink args
= {
2398 .fh
= NFS_FH(inode
),
2403 struct nfs4_readlink_res res
;
2404 struct rpc_message msg
= {
2405 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2410 return nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
2413 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2414 unsigned int pgbase
, unsigned int pglen
)
2416 struct nfs4_exception exception
= { };
2419 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2420 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2422 } while (exception
.retry
);
2428 * We will need to arrange for the VFS layer to provide an atomic open.
2429 * Until then, this create/open method is prone to inefficiency and race
2430 * conditions due to the lookup, create, and open VFS calls from sys_open()
2431 * placed on the wire.
2433 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2434 * The file will be opened again in the subsequent VFS open call
2435 * (nfs4_proc_file_open).
2437 * The open for read will just hang around to be used by any process that
2438 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2442 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2443 int flags
, struct nameidata
*nd
)
2445 struct path path
= {
2446 .mnt
= nd
->path
.mnt
,
2449 struct nfs4_state
*state
;
2450 struct rpc_cred
*cred
;
2451 fmode_t fmode
= flags
& (FMODE_READ
| FMODE_WRITE
);
2454 cred
= rpc_lookup_cred();
2456 status
= PTR_ERR(cred
);
2459 state
= nfs4_do_open(dir
, &path
, fmode
, flags
, sattr
, cred
);
2461 if (IS_ERR(state
)) {
2462 status
= PTR_ERR(state
);
2465 d_add(dentry
, igrab(state
->inode
));
2466 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2467 if (flags
& O_EXCL
) {
2468 struct nfs_fattr fattr
;
2469 status
= nfs4_do_setattr(state
->inode
, cred
, &fattr
, sattr
, state
);
2471 nfs_setattr_update_inode(state
->inode
, sattr
);
2472 nfs_post_op_update_inode(state
->inode
, &fattr
);
2474 if (status
== 0 && (nd
->flags
& LOOKUP_OPEN
) != 0)
2475 status
= nfs4_intent_set_file(nd
, &path
, state
, fmode
);
2477 nfs4_close_sync(&path
, state
, fmode
);
2484 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2486 struct nfs_server
*server
= NFS_SERVER(dir
);
2487 struct nfs_removeargs args
= {
2489 .name
.len
= name
->len
,
2490 .name
.name
= name
->name
,
2491 .bitmask
= server
->attr_bitmask
,
2493 struct nfs_removeres res
= {
2496 struct rpc_message msg
= {
2497 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2503 nfs_fattr_init(&res
.dir_attr
);
2504 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 1);
2506 update_changeattr(dir
, &res
.cinfo
);
2507 nfs_post_op_update_inode(dir
, &res
.dir_attr
);
2512 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2514 struct nfs4_exception exception
= { };
2517 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2518 _nfs4_proc_remove(dir
, name
),
2520 } while (exception
.retry
);
2524 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2526 struct nfs_server
*server
= NFS_SERVER(dir
);
2527 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2528 struct nfs_removeres
*res
= msg
->rpc_resp
;
2530 args
->bitmask
= server
->cache_consistency_bitmask
;
2531 res
->server
= server
;
2532 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2535 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2537 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2539 nfs4_sequence_done(res
->server
, &res
->seq_res
, task
->tk_status
);
2540 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2542 nfs4_sequence_free_slot(res
->server
->nfs_client
, &res
->seq_res
);
2543 update_changeattr(dir
, &res
->cinfo
);
2544 nfs_post_op_update_inode(dir
, &res
->dir_attr
);
2548 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2549 struct inode
*new_dir
, struct qstr
*new_name
)
2551 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2552 struct nfs4_rename_arg arg
= {
2553 .old_dir
= NFS_FH(old_dir
),
2554 .new_dir
= NFS_FH(new_dir
),
2555 .old_name
= old_name
,
2556 .new_name
= new_name
,
2557 .bitmask
= server
->attr_bitmask
,
2559 struct nfs_fattr old_fattr
, new_fattr
;
2560 struct nfs4_rename_res res
= {
2562 .old_fattr
= &old_fattr
,
2563 .new_fattr
= &new_fattr
,
2565 struct rpc_message msg
= {
2566 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2572 nfs_fattr_init(res
.old_fattr
);
2573 nfs_fattr_init(res
.new_fattr
);
2574 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2577 update_changeattr(old_dir
, &res
.old_cinfo
);
2578 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2579 update_changeattr(new_dir
, &res
.new_cinfo
);
2580 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2585 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2586 struct inode
*new_dir
, struct qstr
*new_name
)
2588 struct nfs4_exception exception
= { };
2591 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2592 _nfs4_proc_rename(old_dir
, old_name
,
2595 } while (exception
.retry
);
2599 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2601 struct nfs_server
*server
= NFS_SERVER(inode
);
2602 struct nfs4_link_arg arg
= {
2603 .fh
= NFS_FH(inode
),
2604 .dir_fh
= NFS_FH(dir
),
2606 .bitmask
= server
->attr_bitmask
,
2608 struct nfs_fattr fattr
, dir_attr
;
2609 struct nfs4_link_res res
= {
2612 .dir_attr
= &dir_attr
,
2614 struct rpc_message msg
= {
2615 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2621 nfs_fattr_init(res
.fattr
);
2622 nfs_fattr_init(res
.dir_attr
);
2623 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2625 update_changeattr(dir
, &res
.cinfo
);
2626 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2627 nfs_post_op_update_inode(inode
, res
.fattr
);
2633 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2635 struct nfs4_exception exception
= { };
2638 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2639 _nfs4_proc_link(inode
, dir
, name
),
2641 } while (exception
.retry
);
2645 struct nfs4_createdata
{
2646 struct rpc_message msg
;
2647 struct nfs4_create_arg arg
;
2648 struct nfs4_create_res res
;
2650 struct nfs_fattr fattr
;
2651 struct nfs_fattr dir_fattr
;
2654 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2655 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2657 struct nfs4_createdata
*data
;
2659 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2661 struct nfs_server
*server
= NFS_SERVER(dir
);
2663 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2664 data
->msg
.rpc_argp
= &data
->arg
;
2665 data
->msg
.rpc_resp
= &data
->res
;
2666 data
->arg
.dir_fh
= NFS_FH(dir
);
2667 data
->arg
.server
= server
;
2668 data
->arg
.name
= name
;
2669 data
->arg
.attrs
= sattr
;
2670 data
->arg
.ftype
= ftype
;
2671 data
->arg
.bitmask
= server
->attr_bitmask
;
2672 data
->res
.server
= server
;
2673 data
->res
.fh
= &data
->fh
;
2674 data
->res
.fattr
= &data
->fattr
;
2675 data
->res
.dir_fattr
= &data
->dir_fattr
;
2676 nfs_fattr_init(data
->res
.fattr
);
2677 nfs_fattr_init(data
->res
.dir_fattr
);
2682 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2684 int status
= nfs4_call_sync(NFS_SERVER(dir
), &data
->msg
,
2685 &data
->arg
, &data
->res
, 1);
2687 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2688 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2689 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2694 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2699 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2700 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2702 struct nfs4_createdata
*data
;
2703 int status
= -ENAMETOOLONG
;
2705 if (len
> NFS4_MAXPATHLEN
)
2709 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2713 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2714 data
->arg
.u
.symlink
.pages
= &page
;
2715 data
->arg
.u
.symlink
.len
= len
;
2717 status
= nfs4_do_create(dir
, dentry
, data
);
2719 nfs4_free_createdata(data
);
2724 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2725 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2727 struct nfs4_exception exception
= { };
2730 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2731 _nfs4_proc_symlink(dir
, dentry
, page
,
2734 } while (exception
.retry
);
2738 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2739 struct iattr
*sattr
)
2741 struct nfs4_createdata
*data
;
2742 int status
= -ENOMEM
;
2744 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2748 status
= nfs4_do_create(dir
, dentry
, data
);
2750 nfs4_free_createdata(data
);
2755 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2756 struct iattr
*sattr
)
2758 struct nfs4_exception exception
= { };
2761 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2762 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2764 } while (exception
.retry
);
2768 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2769 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2771 struct inode
*dir
= dentry
->d_inode
;
2772 struct nfs4_readdir_arg args
= {
2777 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2779 struct nfs4_readdir_res res
;
2780 struct rpc_message msg
= {
2781 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2788 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2789 dentry
->d_parent
->d_name
.name
,
2790 dentry
->d_name
.name
,
2791 (unsigned long long)cookie
);
2792 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2793 res
.pgbase
= args
.pgbase
;
2794 status
= nfs4_call_sync(NFS_SERVER(dir
), &msg
, &args
, &res
, 0);
2796 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2798 nfs_invalidate_atime(dir
);
2800 dprintk("%s: returns %d\n", __func__
, status
);
2804 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2805 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2807 struct nfs4_exception exception
= { };
2810 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2811 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2814 } while (exception
.retry
);
2818 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2819 struct iattr
*sattr
, dev_t rdev
)
2821 struct nfs4_createdata
*data
;
2822 int mode
= sattr
->ia_mode
;
2823 int status
= -ENOMEM
;
2825 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2826 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2828 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2833 data
->arg
.ftype
= NF4FIFO
;
2834 else if (S_ISBLK(mode
)) {
2835 data
->arg
.ftype
= NF4BLK
;
2836 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2837 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2839 else if (S_ISCHR(mode
)) {
2840 data
->arg
.ftype
= NF4CHR
;
2841 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2842 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2845 status
= nfs4_do_create(dir
, dentry
, data
);
2847 nfs4_free_createdata(data
);
2852 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2853 struct iattr
*sattr
, dev_t rdev
)
2855 struct nfs4_exception exception
= { };
2858 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2859 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2861 } while (exception
.retry
);
2865 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2866 struct nfs_fsstat
*fsstat
)
2868 struct nfs4_statfs_arg args
= {
2870 .bitmask
= server
->attr_bitmask
,
2872 struct nfs4_statfs_res res
= {
2875 struct rpc_message msg
= {
2876 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2881 nfs_fattr_init(fsstat
->fattr
);
2882 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2885 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2887 struct nfs4_exception exception
= { };
2890 err
= nfs4_handle_exception(server
,
2891 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2893 } while (exception
.retry
);
2897 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2898 struct nfs_fsinfo
*fsinfo
)
2900 struct nfs4_fsinfo_arg args
= {
2902 .bitmask
= server
->attr_bitmask
,
2904 struct nfs4_fsinfo_res res
= {
2907 struct rpc_message msg
= {
2908 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
2913 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2916 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2918 struct nfs4_exception exception
= { };
2922 err
= nfs4_handle_exception(server
,
2923 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
2925 } while (exception
.retry
);
2929 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2931 nfs_fattr_init(fsinfo
->fattr
);
2932 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2935 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2936 struct nfs_pathconf
*pathconf
)
2938 struct nfs4_pathconf_arg args
= {
2940 .bitmask
= server
->attr_bitmask
,
2942 struct nfs4_pathconf_res res
= {
2943 .pathconf
= pathconf
,
2945 struct rpc_message msg
= {
2946 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2951 /* None of the pathconf attributes are mandatory to implement */
2952 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2953 memset(pathconf
, 0, sizeof(*pathconf
));
2957 nfs_fattr_init(pathconf
->fattr
);
2958 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2961 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2962 struct nfs_pathconf
*pathconf
)
2964 struct nfs4_exception exception
= { };
2968 err
= nfs4_handle_exception(server
,
2969 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2971 } while (exception
.retry
);
2975 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
2977 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2979 dprintk("--> %s\n", __func__
);
2981 /* nfs4_sequence_free_slot called in the read rpc_call_done */
2982 nfs4_sequence_done(server
, &data
->res
.seq_res
, task
->tk_status
);
2984 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
2985 nfs4_restart_rpc(task
, server
->nfs_client
, &data
->res
.seq_res
);
2989 nfs_invalidate_atime(data
->inode
);
2990 if (task
->tk_status
> 0)
2991 renew_lease(server
, data
->timestamp
);
2992 else if (task
->tk_status
< 0)
2993 nfs4_sequence_free_slot(server
->nfs_client
, &data
->res
.seq_res
);
2998 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3000 data
->timestamp
= jiffies
;
3001 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3004 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3006 struct inode
*inode
= data
->inode
;
3008 /* slot is freed in nfs_writeback_done */
3009 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
3012 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3013 nfs4_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
,
3014 &data
->res
.seq_res
);
3017 if (task
->tk_status
>= 0) {
3018 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3019 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3024 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3026 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3028 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3029 data
->res
.server
= server
;
3030 data
->timestamp
= jiffies
;
3032 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3035 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3037 struct inode
*inode
= data
->inode
;
3039 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
3041 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3042 nfs4_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
,
3043 &data
->res
.seq_res
);
3046 nfs4_sequence_free_slot(NFS_SERVER(inode
)->nfs_client
,
3047 &data
->res
.seq_res
);
3048 nfs_refresh_inode(inode
, data
->res
.fattr
);
3052 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3054 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3056 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3057 data
->res
.server
= server
;
3058 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3062 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3063 * standalone procedure for queueing an asynchronous RENEW.
3065 static void nfs4_renew_done(struct rpc_task
*task
, void *data
)
3067 struct nfs_client
*clp
= (struct nfs_client
*)task
->tk_msg
.rpc_argp
;
3068 unsigned long timestamp
= (unsigned long)data
;
3070 if (task
->tk_status
< 0) {
3071 /* Unless we're shutting down, schedule state recovery! */
3072 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3073 nfs4_schedule_state_recovery(clp
);
3076 spin_lock(&clp
->cl_lock
);
3077 if (time_before(clp
->cl_last_renewal
,timestamp
))
3078 clp
->cl_last_renewal
= timestamp
;
3079 spin_unlock(&clp
->cl_lock
);
3082 static const struct rpc_call_ops nfs4_renew_ops
= {
3083 .rpc_call_done
= nfs4_renew_done
,
3086 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3088 struct rpc_message msg
= {
3089 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3094 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3095 &nfs4_renew_ops
, (void *)jiffies
);
3098 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3100 struct rpc_message msg
= {
3101 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3105 unsigned long now
= jiffies
;
3108 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3111 spin_lock(&clp
->cl_lock
);
3112 if (time_before(clp
->cl_last_renewal
,now
))
3113 clp
->cl_last_renewal
= now
;
3114 spin_unlock(&clp
->cl_lock
);
3118 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3120 return (server
->caps
& NFS_CAP_ACLS
)
3121 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3122 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3125 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3126 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3129 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3131 static void buf_to_pages(const void *buf
, size_t buflen
,
3132 struct page
**pages
, unsigned int *pgbase
)
3134 const void *p
= buf
;
3136 *pgbase
= offset_in_page(buf
);
3138 while (p
< buf
+ buflen
) {
3139 *(pages
++) = virt_to_page(p
);
3140 p
+= PAGE_CACHE_SIZE
;
3144 struct nfs4_cached_acl
{
3150 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3152 struct nfs_inode
*nfsi
= NFS_I(inode
);
3154 spin_lock(&inode
->i_lock
);
3155 kfree(nfsi
->nfs4_acl
);
3156 nfsi
->nfs4_acl
= acl
;
3157 spin_unlock(&inode
->i_lock
);
3160 static void nfs4_zap_acl_attr(struct inode
*inode
)
3162 nfs4_set_cached_acl(inode
, NULL
);
3165 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3167 struct nfs_inode
*nfsi
= NFS_I(inode
);
3168 struct nfs4_cached_acl
*acl
;
3171 spin_lock(&inode
->i_lock
);
3172 acl
= nfsi
->nfs4_acl
;
3175 if (buf
== NULL
) /* user is just asking for length */
3177 if (acl
->cached
== 0)
3179 ret
= -ERANGE
; /* see getxattr(2) man page */
3180 if (acl
->len
> buflen
)
3182 memcpy(buf
, acl
->data
, acl
->len
);
3186 spin_unlock(&inode
->i_lock
);
3190 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3192 struct nfs4_cached_acl
*acl
;
3194 if (buf
&& acl_len
<= PAGE_SIZE
) {
3195 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3199 memcpy(acl
->data
, buf
, acl_len
);
3201 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3208 nfs4_set_cached_acl(inode
, acl
);
3211 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3213 struct page
*pages
[NFS4ACL_MAXPAGES
];
3214 struct nfs_getaclargs args
= {
3215 .fh
= NFS_FH(inode
),
3219 struct nfs_getaclres res
= {
3223 struct rpc_message msg
= {
3224 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3228 struct page
*localpage
= NULL
;
3231 if (buflen
< PAGE_SIZE
) {
3232 /* As long as we're doing a round trip to the server anyway,
3233 * let's be prepared for a page of acl data. */
3234 localpage
= alloc_page(GFP_KERNEL
);
3235 resp_buf
= page_address(localpage
);
3236 if (localpage
== NULL
)
3238 args
.acl_pages
[0] = localpage
;
3239 args
.acl_pgbase
= 0;
3240 args
.acl_len
= PAGE_SIZE
;
3243 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3245 ret
= nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
3248 if (res
.acl_len
> args
.acl_len
)
3249 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3251 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3254 if (res
.acl_len
> buflen
)
3257 memcpy(buf
, resp_buf
, res
.acl_len
);
3262 __free_page(localpage
);
3266 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3268 struct nfs4_exception exception
= { };
3271 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3274 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3275 } while (exception
.retry
);
3279 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3281 struct nfs_server
*server
= NFS_SERVER(inode
);
3284 if (!nfs4_server_supports_acls(server
))
3286 ret
= nfs_revalidate_inode(server
, inode
);
3289 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3292 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3295 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3297 struct nfs_server
*server
= NFS_SERVER(inode
);
3298 struct page
*pages
[NFS4ACL_MAXPAGES
];
3299 struct nfs_setaclargs arg
= {
3300 .fh
= NFS_FH(inode
),
3304 struct nfs_setaclres res
;
3305 struct rpc_message msg
= {
3306 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3312 if (!nfs4_server_supports_acls(server
))
3314 nfs_inode_return_delegation(inode
);
3315 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3316 ret
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3317 nfs_access_zap_cache(inode
);
3318 nfs_zap_acl_cache(inode
);
3322 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3324 struct nfs4_exception exception
= { };
3327 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3328 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3330 } while (exception
.retry
);
3335 _nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs_client
*clp
, struct nfs4_state
*state
)
3337 if (!clp
|| task
->tk_status
>= 0)
3339 switch(task
->tk_status
) {
3340 case -NFS4ERR_ADMIN_REVOKED
:
3341 case -NFS4ERR_BAD_STATEID
:
3342 case -NFS4ERR_OPENMODE
:
3345 nfs4_state_mark_reclaim_nograce(clp
, state
);
3346 case -NFS4ERR_STALE_CLIENTID
:
3347 case -NFS4ERR_STALE_STATEID
:
3348 case -NFS4ERR_EXPIRED
:
3349 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3350 nfs4_schedule_state_recovery(clp
);
3351 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3352 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3353 task
->tk_status
= 0;
3355 #if defined(CONFIG_NFS_V4_1)
3356 case -NFS4ERR_BADSESSION
:
3357 case -NFS4ERR_BADSLOT
:
3358 case -NFS4ERR_BAD_HIGH_SLOT
:
3359 case -NFS4ERR_DEADSESSION
:
3360 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3361 case -NFS4ERR_SEQ_FALSE_RETRY
:
3362 case -NFS4ERR_SEQ_MISORDERED
:
3363 dprintk("%s ERROR %d, Reset session\n", __func__
,
3365 set_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
);
3366 task
->tk_status
= 0;
3368 #endif /* CONFIG_NFS_V4_1 */
3369 case -NFS4ERR_DELAY
:
3371 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3372 case -NFS4ERR_GRACE
:
3373 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3374 task
->tk_status
= 0;
3376 case -NFS4ERR_OLD_STATEID
:
3377 task
->tk_status
= 0;
3380 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3385 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3387 return _nfs4_async_handle_error(task
, server
, server
->nfs_client
, state
);
3390 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
, unsigned short port
, struct rpc_cred
*cred
)
3392 nfs4_verifier sc_verifier
;
3393 struct nfs4_setclientid setclientid
= {
3394 .sc_verifier
= &sc_verifier
,
3397 struct rpc_message msg
= {
3398 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3399 .rpc_argp
= &setclientid
,
3407 p
= (__be32
*)sc_verifier
.data
;
3408 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3409 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3412 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3413 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3415 rpc_peeraddr2str(clp
->cl_rpcclient
,
3417 rpc_peeraddr2str(clp
->cl_rpcclient
,
3419 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3420 clp
->cl_id_uniquifier
);
3421 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3422 sizeof(setclientid
.sc_netid
),
3423 rpc_peeraddr2str(clp
->cl_rpcclient
,
3424 RPC_DISPLAY_NETID
));
3425 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3426 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3427 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3429 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3430 if (status
!= -NFS4ERR_CLID_INUSE
)
3435 ssleep(clp
->cl_lease_time
+ 1);
3437 if (++clp
->cl_id_uniquifier
== 0)
3443 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3445 struct nfs_fsinfo fsinfo
;
3446 struct rpc_message msg
= {
3447 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3449 .rpc_resp
= &fsinfo
,
3456 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3458 spin_lock(&clp
->cl_lock
);
3459 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3460 clp
->cl_last_renewal
= now
;
3461 spin_unlock(&clp
->cl_lock
);
3466 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3471 err
= _nfs4_proc_setclientid_confirm(clp
, cred
);
3475 case -NFS4ERR_RESOURCE
:
3476 /* The IBM lawyers misread another document! */
3477 case -NFS4ERR_DELAY
:
3478 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3484 struct nfs4_delegreturndata
{
3485 struct nfs4_delegreturnargs args
;
3486 struct nfs4_delegreturnres res
;
3488 nfs4_stateid stateid
;
3489 unsigned long timestamp
;
3490 struct nfs_fattr fattr
;
3494 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3496 struct nfs4_delegreturndata
*data
= calldata
;
3498 nfs4_sequence_done_free_slot(data
->res
.server
, &data
->res
.seq_res
,
3501 data
->rpc_status
= task
->tk_status
;
3502 if (data
->rpc_status
== 0)
3503 renew_lease(data
->res
.server
, data
->timestamp
);
3506 static void nfs4_delegreturn_release(void *calldata
)
3511 #if defined(CONFIG_NFS_V4_1)
3512 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3514 struct nfs4_delegreturndata
*d_data
;
3516 d_data
= (struct nfs4_delegreturndata
*)data
;
3518 if (nfs4_setup_sequence(d_data
->res
.server
->nfs_client
,
3519 &d_data
->args
.seq_args
,
3520 &d_data
->res
.seq_res
, 1, task
))
3522 rpc_call_start(task
);
3524 #endif /* CONFIG_NFS_V4_1 */
3526 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3527 #if defined(CONFIG_NFS_V4_1)
3528 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3529 #endif /* CONFIG_NFS_V4_1 */
3530 .rpc_call_done
= nfs4_delegreturn_done
,
3531 .rpc_release
= nfs4_delegreturn_release
,
3534 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3536 struct nfs4_delegreturndata
*data
;
3537 struct nfs_server
*server
= NFS_SERVER(inode
);
3538 struct rpc_task
*task
;
3539 struct rpc_message msg
= {
3540 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3543 struct rpc_task_setup task_setup_data
= {
3544 .rpc_client
= server
->client
,
3545 .rpc_message
= &msg
,
3546 .callback_ops
= &nfs4_delegreturn_ops
,
3547 .flags
= RPC_TASK_ASYNC
,
3551 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3554 data
->args
.fhandle
= &data
->fh
;
3555 data
->args
.stateid
= &data
->stateid
;
3556 data
->args
.bitmask
= server
->attr_bitmask
;
3557 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3558 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3559 data
->res
.fattr
= &data
->fattr
;
3560 data
->res
.server
= server
;
3561 data
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3562 nfs_fattr_init(data
->res
.fattr
);
3563 data
->timestamp
= jiffies
;
3564 data
->rpc_status
= 0;
3566 task_setup_data
.callback_data
= data
;
3567 msg
.rpc_argp
= &data
->args
,
3568 msg
.rpc_resp
= &data
->res
,
3569 task
= rpc_run_task(&task_setup_data
);
3571 return PTR_ERR(task
);
3574 status
= nfs4_wait_for_completion_rpc_task(task
);
3577 status
= data
->rpc_status
;
3580 nfs_refresh_inode(inode
, &data
->fattr
);
3586 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3588 struct nfs_server
*server
= NFS_SERVER(inode
);
3589 struct nfs4_exception exception
= { };
3592 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3594 case -NFS4ERR_STALE_STATEID
:
3595 case -NFS4ERR_EXPIRED
:
3599 err
= nfs4_handle_exception(server
, err
, &exception
);
3600 } while (exception
.retry
);
3604 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3605 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3608 * sleep, with exponential backoff, and retry the LOCK operation.
3610 static unsigned long
3611 nfs4_set_lock_task_retry(unsigned long timeout
)
3613 schedule_timeout_killable(timeout
);
3615 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3616 return NFS4_LOCK_MAXTIMEOUT
;
3620 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3622 struct inode
*inode
= state
->inode
;
3623 struct nfs_server
*server
= NFS_SERVER(inode
);
3624 struct nfs_client
*clp
= server
->nfs_client
;
3625 struct nfs_lockt_args arg
= {
3626 .fh
= NFS_FH(inode
),
3629 struct nfs_lockt_res res
= {
3632 struct rpc_message msg
= {
3633 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3636 .rpc_cred
= state
->owner
->so_cred
,
3638 struct nfs4_lock_state
*lsp
;
3641 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3642 status
= nfs4_set_lock_state(state
, request
);
3645 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3646 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3647 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3650 request
->fl_type
= F_UNLCK
;
3652 case -NFS4ERR_DENIED
:
3655 request
->fl_ops
->fl_release_private(request
);
3660 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3662 struct nfs4_exception exception
= { };
3666 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3667 _nfs4_proc_getlk(state
, cmd
, request
),
3669 } while (exception
.retry
);
3673 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3676 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3678 res
= posix_lock_file_wait(file
, fl
);
3681 res
= flock_lock_file_wait(file
, fl
);
3689 struct nfs4_unlockdata
{
3690 struct nfs_locku_args arg
;
3691 struct nfs_locku_res res
;
3692 struct nfs4_lock_state
*lsp
;
3693 struct nfs_open_context
*ctx
;
3694 struct file_lock fl
;
3695 const struct nfs_server
*server
;
3696 unsigned long timestamp
;
3699 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3700 struct nfs_open_context
*ctx
,
3701 struct nfs4_lock_state
*lsp
,
3702 struct nfs_seqid
*seqid
)
3704 struct nfs4_unlockdata
*p
;
3705 struct inode
*inode
= lsp
->ls_state
->inode
;
3707 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3710 p
->arg
.fh
= NFS_FH(inode
);
3712 p
->arg
.seqid
= seqid
;
3713 p
->res
.seqid
= seqid
;
3714 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3715 p
->arg
.stateid
= &lsp
->ls_stateid
;
3717 atomic_inc(&lsp
->ls_count
);
3718 /* Ensure we don't close file until we're done freeing locks! */
3719 p
->ctx
= get_nfs_open_context(ctx
);
3720 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3721 p
->server
= NFS_SERVER(inode
);
3725 static void nfs4_locku_release_calldata(void *data
)
3727 struct nfs4_unlockdata
*calldata
= data
;
3728 nfs_free_seqid(calldata
->arg
.seqid
);
3729 nfs4_put_lock_state(calldata
->lsp
);
3730 put_nfs_open_context(calldata
->ctx
);
3734 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3736 struct nfs4_unlockdata
*calldata
= data
;
3738 nfs4_sequence_done(calldata
->server
, &calldata
->res
.seq_res
,
3740 if (RPC_ASSASSINATED(task
))
3742 switch (task
->tk_status
) {
3744 memcpy(calldata
->lsp
->ls_stateid
.data
,
3745 calldata
->res
.stateid
.data
,
3746 sizeof(calldata
->lsp
->ls_stateid
.data
));
3747 renew_lease(calldata
->server
, calldata
->timestamp
);
3749 case -NFS4ERR_BAD_STATEID
:
3750 case -NFS4ERR_OLD_STATEID
:
3751 case -NFS4ERR_STALE_STATEID
:
3752 case -NFS4ERR_EXPIRED
:
3755 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
3756 nfs4_restart_rpc(task
,
3757 calldata
->server
->nfs_client
,
3758 &calldata
->res
.seq_res
);
3760 nfs4_sequence_free_slot(calldata
->server
->nfs_client
,
3761 &calldata
->res
.seq_res
);
3764 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3766 struct nfs4_unlockdata
*calldata
= data
;
3768 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3770 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3771 /* Note: exit _without_ running nfs4_locku_done */
3772 task
->tk_action
= NULL
;
3775 calldata
->timestamp
= jiffies
;
3776 if (nfs4_setup_sequence(calldata
->server
->nfs_client
,
3777 &calldata
->arg
.seq_args
,
3778 &calldata
->res
.seq_res
, 1, task
))
3780 rpc_call_start(task
);
3783 static const struct rpc_call_ops nfs4_locku_ops
= {
3784 .rpc_call_prepare
= nfs4_locku_prepare
,
3785 .rpc_call_done
= nfs4_locku_done
,
3786 .rpc_release
= nfs4_locku_release_calldata
,
3789 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3790 struct nfs_open_context
*ctx
,
3791 struct nfs4_lock_state
*lsp
,
3792 struct nfs_seqid
*seqid
)
3794 struct nfs4_unlockdata
*data
;
3795 struct rpc_message msg
= {
3796 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3797 .rpc_cred
= ctx
->cred
,
3799 struct rpc_task_setup task_setup_data
= {
3800 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
3801 .rpc_message
= &msg
,
3802 .callback_ops
= &nfs4_locku_ops
,
3803 .workqueue
= nfsiod_workqueue
,
3804 .flags
= RPC_TASK_ASYNC
,
3807 /* Ensure this is an unlock - when canceling a lock, the
3808 * canceled lock is passed in, and it won't be an unlock.
3810 fl
->fl_type
= F_UNLCK
;
3812 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3814 nfs_free_seqid(seqid
);
3815 return ERR_PTR(-ENOMEM
);
3818 msg
.rpc_argp
= &data
->arg
,
3819 msg
.rpc_resp
= &data
->res
,
3820 task_setup_data
.callback_data
= data
;
3821 return rpc_run_task(&task_setup_data
);
3824 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3826 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3827 struct nfs_seqid
*seqid
;
3828 struct nfs4_lock_state
*lsp
;
3829 struct rpc_task
*task
;
3831 unsigned char fl_flags
= request
->fl_flags
;
3833 status
= nfs4_set_lock_state(state
, request
);
3834 /* Unlock _before_ we do the RPC call */
3835 request
->fl_flags
|= FL_EXISTS
;
3836 down_read(&nfsi
->rwsem
);
3837 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
3838 up_read(&nfsi
->rwsem
);
3841 up_read(&nfsi
->rwsem
);
3844 /* Is this a delegated lock? */
3845 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
3847 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3848 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3852 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
3853 status
= PTR_ERR(task
);
3856 status
= nfs4_wait_for_completion_rpc_task(task
);
3859 request
->fl_flags
= fl_flags
;
3863 struct nfs4_lockdata
{
3864 struct nfs_lock_args arg
;
3865 struct nfs_lock_res res
;
3866 struct nfs4_lock_state
*lsp
;
3867 struct nfs_open_context
*ctx
;
3868 struct file_lock fl
;
3869 unsigned long timestamp
;
3872 struct nfs_server
*server
;
3875 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
3876 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
)
3878 struct nfs4_lockdata
*p
;
3879 struct inode
*inode
= lsp
->ls_state
->inode
;
3880 struct nfs_server
*server
= NFS_SERVER(inode
);
3882 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3886 p
->arg
.fh
= NFS_FH(inode
);
3888 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
);
3889 if (p
->arg
.open_seqid
== NULL
)
3891 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3892 if (p
->arg
.lock_seqid
== NULL
)
3893 goto out_free_seqid
;
3894 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
3895 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
3896 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3897 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
3898 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3901 atomic_inc(&lsp
->ls_count
);
3902 p
->ctx
= get_nfs_open_context(ctx
);
3903 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3906 nfs_free_seqid(p
->arg
.open_seqid
);
3912 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
3914 struct nfs4_lockdata
*data
= calldata
;
3915 struct nfs4_state
*state
= data
->lsp
->ls_state
;
3917 dprintk("%s: begin!\n", __func__
);
3918 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
3920 /* Do we need to do an open_to_lock_owner? */
3921 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
3922 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
3924 data
->arg
.open_stateid
= &state
->stateid
;
3925 data
->arg
.new_lock_owner
= 1;
3926 data
->res
.open_seqid
= data
->arg
.open_seqid
;
3928 data
->arg
.new_lock_owner
= 0;
3929 data
->timestamp
= jiffies
;
3930 if (nfs4_setup_sequence(data
->server
->nfs_client
, &data
->arg
.seq_args
,
3931 &data
->res
.seq_res
, 1, task
))
3933 rpc_call_start(task
);
3934 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
3937 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
3939 struct nfs4_lockdata
*data
= calldata
;
3941 dprintk("%s: begin!\n", __func__
);
3943 nfs4_sequence_done_free_slot(data
->server
, &data
->res
.seq_res
,
3946 data
->rpc_status
= task
->tk_status
;
3947 if (RPC_ASSASSINATED(task
))
3949 if (data
->arg
.new_lock_owner
!= 0) {
3950 if (data
->rpc_status
== 0)
3951 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
3955 if (data
->rpc_status
== 0) {
3956 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
3957 sizeof(data
->lsp
->ls_stateid
.data
));
3958 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
3959 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
3962 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
3965 static void nfs4_lock_release(void *calldata
)
3967 struct nfs4_lockdata
*data
= calldata
;
3969 dprintk("%s: begin!\n", __func__
);
3970 nfs_free_seqid(data
->arg
.open_seqid
);
3971 if (data
->cancelled
!= 0) {
3972 struct rpc_task
*task
;
3973 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
3974 data
->arg
.lock_seqid
);
3977 dprintk("%s: cancelling lock!\n", __func__
);
3979 nfs_free_seqid(data
->arg
.lock_seqid
);
3980 nfs4_put_lock_state(data
->lsp
);
3981 put_nfs_open_context(data
->ctx
);
3983 dprintk("%s: done!\n", __func__
);
3986 static const struct rpc_call_ops nfs4_lock_ops
= {
3987 .rpc_call_prepare
= nfs4_lock_prepare
,
3988 .rpc_call_done
= nfs4_lock_done
,
3989 .rpc_release
= nfs4_lock_release
,
3992 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int reclaim
)
3994 struct nfs4_lockdata
*data
;
3995 struct rpc_task
*task
;
3996 struct rpc_message msg
= {
3997 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
3998 .rpc_cred
= state
->owner
->so_cred
,
4000 struct rpc_task_setup task_setup_data
= {
4001 .rpc_client
= NFS_CLIENT(state
->inode
),
4002 .rpc_message
= &msg
,
4003 .callback_ops
= &nfs4_lock_ops
,
4004 .workqueue
= nfsiod_workqueue
,
4005 .flags
= RPC_TASK_ASYNC
,
4009 dprintk("%s: begin!\n", __func__
);
4010 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4011 fl
->fl_u
.nfs4_fl
.owner
);
4015 data
->arg
.block
= 1;
4017 data
->arg
.reclaim
= 1;
4018 msg
.rpc_argp
= &data
->arg
,
4019 msg
.rpc_resp
= &data
->res
,
4020 task_setup_data
.callback_data
= data
;
4021 task
= rpc_run_task(&task_setup_data
);
4023 return PTR_ERR(task
);
4024 ret
= nfs4_wait_for_completion_rpc_task(task
);
4026 ret
= data
->rpc_status
;
4028 data
->cancelled
= 1;
4030 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4034 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4036 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4037 struct nfs4_exception exception
= { };
4041 /* Cache the lock if possible... */
4042 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4044 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
4045 if (err
!= -NFS4ERR_DELAY
)
4047 nfs4_handle_exception(server
, err
, &exception
);
4048 } while (exception
.retry
);
4052 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4054 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4055 struct nfs4_exception exception
= { };
4058 err
= nfs4_set_lock_state(state
, request
);
4062 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4064 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
4068 case -NFS4ERR_GRACE
:
4069 case -NFS4ERR_DELAY
:
4070 nfs4_handle_exception(server
, err
, &exception
);
4073 } while (exception
.retry
);
4078 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4080 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4081 unsigned char fl_flags
= request
->fl_flags
;
4084 /* Is this a delegated open? */
4085 status
= nfs4_set_lock_state(state
, request
);
4088 request
->fl_flags
|= FL_ACCESS
;
4089 status
= do_vfs_lock(request
->fl_file
, request
);
4092 down_read(&nfsi
->rwsem
);
4093 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4094 /* Yes: cache locks! */
4095 /* ...but avoid races with delegation recall... */
4096 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4097 status
= do_vfs_lock(request
->fl_file
, request
);
4100 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
4103 /* Note: we always want to sleep here! */
4104 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4105 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4106 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4108 up_read(&nfsi
->rwsem
);
4110 request
->fl_flags
= fl_flags
;
4114 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4116 struct nfs4_exception exception
= { };
4120 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4121 if (err
== -NFS4ERR_DENIED
)
4123 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4125 } while (exception
.retry
);
4130 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4132 struct nfs_open_context
*ctx
;
4133 struct nfs4_state
*state
;
4134 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4137 /* verify open state */
4138 ctx
= nfs_file_open_context(filp
);
4141 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4144 if (IS_GETLK(cmd
)) {
4146 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4150 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4153 if (request
->fl_type
== F_UNLCK
) {
4155 return nfs4_proc_unlck(state
, cmd
, request
);
4162 status
= nfs4_proc_setlk(state
, cmd
, request
);
4163 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4165 timeout
= nfs4_set_lock_task_retry(timeout
);
4166 status
= -ERESTARTSYS
;
4169 } while(status
< 0);
4173 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4175 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4176 struct nfs4_exception exception
= { };
4179 err
= nfs4_set_lock_state(state
, fl
);
4183 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, 0);
4186 printk(KERN_ERR
"%s: unhandled error %d.\n",
4191 case -NFS4ERR_EXPIRED
:
4192 case -NFS4ERR_STALE_CLIENTID
:
4193 case -NFS4ERR_STALE_STATEID
:
4194 nfs4_schedule_state_recovery(server
->nfs_client
);
4198 * The show must go on: exit, but mark the
4199 * stateid as needing recovery.
4201 case -NFS4ERR_ADMIN_REVOKED
:
4202 case -NFS4ERR_BAD_STATEID
:
4203 case -NFS4ERR_OPENMODE
:
4204 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
4208 case -NFS4ERR_DENIED
:
4209 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4212 case -NFS4ERR_DELAY
:
4215 err
= nfs4_handle_exception(server
, err
, &exception
);
4216 } while (exception
.retry
);
4221 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4223 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
4224 size_t buflen
, int flags
)
4226 struct inode
*inode
= dentry
->d_inode
;
4228 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4231 return nfs4_proc_set_acl(inode
, buf
, buflen
);
4234 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4235 * and that's what we'll do for e.g. user attributes that haven't been set.
4236 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4237 * attributes in kernel-managed attribute namespaces. */
4238 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
4241 struct inode
*inode
= dentry
->d_inode
;
4243 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4246 return nfs4_proc_get_acl(inode
, buf
, buflen
);
4249 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
4251 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
4253 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4255 if (buf
&& buflen
< len
)
4258 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
4262 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4264 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4265 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4266 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4269 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4270 NFS_ATTR_FATTR_NLINK
;
4271 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4275 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4276 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4278 struct nfs_server
*server
= NFS_SERVER(dir
);
4280 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4281 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4283 struct nfs4_fs_locations_arg args
= {
4284 .dir_fh
= NFS_FH(dir
),
4289 struct nfs4_fs_locations_res res
= {
4290 .fs_locations
= fs_locations
,
4292 struct rpc_message msg
= {
4293 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4299 dprintk("%s: start\n", __func__
);
4300 nfs_fattr_init(&fs_locations
->fattr
);
4301 fs_locations
->server
= server
;
4302 fs_locations
->nlocations
= 0;
4303 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
4304 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4305 dprintk("%s: returned status = %d\n", __func__
, status
);
4309 #ifdef CONFIG_NFS_V4_1
4311 * nfs4_proc_exchange_id()
4313 * Since the clientid has expired, all compounds using sessions
4314 * associated with the stale clientid will be returning
4315 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4316 * be in some phase of session reset.
4318 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4320 nfs4_verifier verifier
;
4321 struct nfs41_exchange_id_args args
= {
4323 .flags
= clp
->cl_exchange_flags
,
4325 struct nfs41_exchange_id_res res
= {
4329 struct rpc_message msg
= {
4330 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4337 dprintk("--> %s\n", __func__
);
4338 BUG_ON(clp
== NULL
);
4340 p
= (u32
*)verifier
.data
;
4341 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4342 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4343 args
.verifier
= &verifier
;
4346 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4349 rpc_peeraddr2str(clp
->cl_rpcclient
,
4351 clp
->cl_id_uniquifier
);
4353 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4355 if (status
!= NFS4ERR_CLID_INUSE
)
4361 if (++clp
->cl_id_uniquifier
== 0)
4365 dprintk("<-- %s status= %d\n", __func__
, status
);
4369 struct nfs4_get_lease_time_data
{
4370 struct nfs4_get_lease_time_args
*args
;
4371 struct nfs4_get_lease_time_res
*res
;
4372 struct nfs_client
*clp
;
4375 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4379 struct nfs4_get_lease_time_data
*data
=
4380 (struct nfs4_get_lease_time_data
*)calldata
;
4382 dprintk("--> %s\n", __func__
);
4383 /* just setup sequence, do not trigger session recovery
4384 since we're invoked within one */
4385 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4386 &data
->args
->la_seq_args
,
4387 &data
->res
->lr_seq_res
, 0, task
);
4389 BUG_ON(ret
== -EAGAIN
);
4390 rpc_call_start(task
);
4391 dprintk("<-- %s\n", __func__
);
4395 * Called from nfs4_state_manager thread for session setup, so don't recover
4396 * from sequence operation or clientid errors.
4398 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4400 struct nfs4_get_lease_time_data
*data
=
4401 (struct nfs4_get_lease_time_data
*)calldata
;
4403 dprintk("--> %s\n", __func__
);
4404 nfs41_sequence_done(data
->clp
, &data
->res
->lr_seq_res
, task
->tk_status
);
4405 switch (task
->tk_status
) {
4406 case -NFS4ERR_DELAY
:
4407 case -NFS4ERR_GRACE
:
4408 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4409 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4410 task
->tk_status
= 0;
4411 rpc_restart_call(task
);
4414 nfs41_sequence_free_slot(data
->clp
, &data
->res
->lr_seq_res
);
4415 dprintk("<-- %s\n", __func__
);
4418 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4419 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4420 .rpc_call_done
= nfs4_get_lease_time_done
,
4423 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4425 struct rpc_task
*task
;
4426 struct nfs4_get_lease_time_args args
;
4427 struct nfs4_get_lease_time_res res
= {
4428 .lr_fsinfo
= fsinfo
,
4430 struct nfs4_get_lease_time_data data
= {
4435 struct rpc_message msg
= {
4436 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4440 struct rpc_task_setup task_setup
= {
4441 .rpc_client
= clp
->cl_rpcclient
,
4442 .rpc_message
= &msg
,
4443 .callback_ops
= &nfs4_get_lease_time_ops
,
4444 .callback_data
= &data
4448 res
.lr_seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
4449 dprintk("--> %s\n", __func__
);
4450 task
= rpc_run_task(&task_setup
);
4453 status
= PTR_ERR(task
);
4455 status
= task
->tk_status
;
4458 dprintk("<-- %s return %d\n", __func__
, status
);
4464 * Reset a slot table
4466 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, int max_slots
,
4467 int old_max_slots
, int ivalue
)
4472 dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__
, max_slots
, tbl
);
4475 * Until we have dynamic slot table adjustment, insist
4476 * upon the same slot table size
4478 if (max_slots
!= old_max_slots
) {
4479 dprintk("%s reset slot table does't match old\n",
4481 ret
= -EINVAL
; /*XXX NFS4ERR_REQ_TOO_BIG ? */
4484 spin_lock(&tbl
->slot_tbl_lock
);
4485 for (i
= 0; i
< max_slots
; ++i
)
4486 tbl
->slots
[i
].seq_nr
= ivalue
;
4487 tbl
->highest_used_slotid
= -1;
4488 spin_unlock(&tbl
->slot_tbl_lock
);
4489 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4490 tbl
, tbl
->slots
, tbl
->max_slots
);
4492 dprintk("<-- %s: return %d\n", __func__
, ret
);
4497 * Reset the forechannel and backchannel slot tables
4499 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4503 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4504 session
->fc_attrs
.max_reqs
,
4505 session
->fc_slot_table
.max_slots
,
4510 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4511 session
->bc_attrs
.max_reqs
,
4512 session
->bc_slot_table
.max_slots
,
4517 /* Destroy the slot table */
4518 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4520 if (session
->fc_slot_table
.slots
!= NULL
) {
4521 kfree(session
->fc_slot_table
.slots
);
4522 session
->fc_slot_table
.slots
= NULL
;
4524 if (session
->bc_slot_table
.slots
!= NULL
) {
4525 kfree(session
->bc_slot_table
.slots
);
4526 session
->bc_slot_table
.slots
= NULL
;
4532 * Initialize slot table
4534 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4535 int max_slots
, int ivalue
)
4538 struct nfs4_slot
*slot
;
4541 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4543 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4545 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_KERNEL
);
4548 for (i
= 0; i
< max_slots
; ++i
)
4549 slot
[i
].seq_nr
= ivalue
;
4552 spin_lock(&tbl
->slot_tbl_lock
);
4553 if (tbl
->slots
!= NULL
) {
4554 spin_unlock(&tbl
->slot_tbl_lock
);
4555 dprintk("%s: slot table already initialized. tbl=%p slots=%p\n",
4556 __func__
, tbl
, tbl
->slots
);
4560 tbl
->max_slots
= max_slots
;
4562 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4563 spin_unlock(&tbl
->slot_tbl_lock
);
4564 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4565 tbl
, tbl
->slots
, tbl
->max_slots
);
4567 dprintk("<-- %s: return %d\n", __func__
, ret
);
4576 * Initialize the forechannel and backchannel tables
4578 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4582 status
= nfs4_init_slot_table(&session
->fc_slot_table
,
4583 session
->fc_attrs
.max_reqs
, 1);
4587 status
= nfs4_init_slot_table(&session
->bc_slot_table
,
4588 session
->bc_attrs
.max_reqs
, 0);
4590 nfs4_destroy_slot_tables(session
);
4595 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
4597 struct nfs4_session
*session
;
4598 struct nfs4_slot_table
*tbl
;
4600 session
= kzalloc(sizeof(struct nfs4_session
), GFP_KERNEL
);
4605 * The create session reply races with the server back
4606 * channel probe. Mark the client NFS_CS_SESSION_INITING
4607 * so that the client back channel can find the
4610 clp
->cl_cons_state
= NFS_CS_SESSION_INITING
;
4612 tbl
= &session
->fc_slot_table
;
4613 spin_lock_init(&tbl
->slot_tbl_lock
);
4614 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
4616 tbl
= &session
->bc_slot_table
;
4617 spin_lock_init(&tbl
->slot_tbl_lock
);
4618 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
4624 void nfs4_destroy_session(struct nfs4_session
*session
)
4626 nfs4_proc_destroy_session(session
);
4627 dprintk("%s Destroy backchannel for xprt %p\n",
4628 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
4629 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
4630 NFS41_BC_MIN_CALLBACKS
);
4631 nfs4_destroy_slot_tables(session
);
4636 * Initialize the values to be used by the client in CREATE_SESSION
4637 * If nfs4_init_session set the fore channel request and response sizes,
4640 * Set the back channel max_resp_sz_cached to zero to force the client to
4641 * always set csa_cachethis to FALSE because the current implementation
4642 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4644 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
4646 struct nfs4_session
*session
= args
->client
->cl_session
;
4647 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
4648 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
4651 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
4653 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
4654 /* Fore channel attributes */
4655 args
->fc_attrs
.headerpadsz
= 0;
4656 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
4657 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
4658 args
->fc_attrs
.max_resp_sz_cached
= mxresp_sz
;
4659 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
4660 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
4662 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4663 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4665 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
4666 args
->fc_attrs
.max_resp_sz_cached
, args
->fc_attrs
.max_ops
,
4667 args
->fc_attrs
.max_reqs
);
4669 /* Back channel attributes */
4670 args
->bc_attrs
.headerpadsz
= 0;
4671 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
4672 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
4673 args
->bc_attrs
.max_resp_sz_cached
= 0;
4674 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
4675 args
->bc_attrs
.max_reqs
= 1;
4677 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4678 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4680 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
4681 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
4682 args
->bc_attrs
.max_reqs
);
4685 static int _verify_channel_attr(char *chan
, char *attr_name
, u32 sent
, u32 rcvd
)
4689 printk(KERN_WARNING
"%s: Session INVALID: %s channel %s increased. "
4690 "sent=%u rcvd=%u\n", __func__
, chan
, attr_name
, sent
, rcvd
);
4694 #define _verify_fore_channel_attr(_name_) \
4695 _verify_channel_attr("fore", #_name_, \
4696 args->fc_attrs._name_, \
4697 session->fc_attrs._name_)
4699 #define _verify_back_channel_attr(_name_) \
4700 _verify_channel_attr("back", #_name_, \
4701 args->bc_attrs._name_, \
4702 session->bc_attrs._name_)
4705 * The server is not allowed to increase the fore channel header pad size,
4706 * maximum response size, or maximum number of operations.
4708 * The back channel attributes are only negotiatied down: We send what the
4709 * (back channel) server insists upon.
4711 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
4712 struct nfs4_session
*session
)
4716 ret
|= _verify_fore_channel_attr(headerpadsz
);
4717 ret
|= _verify_fore_channel_attr(max_resp_sz
);
4718 ret
|= _verify_fore_channel_attr(max_ops
);
4720 ret
|= _verify_back_channel_attr(headerpadsz
);
4721 ret
|= _verify_back_channel_attr(max_rqst_sz
);
4722 ret
|= _verify_back_channel_attr(max_resp_sz
);
4723 ret
|= _verify_back_channel_attr(max_resp_sz_cached
);
4724 ret
|= _verify_back_channel_attr(max_ops
);
4725 ret
|= _verify_back_channel_attr(max_reqs
);
4730 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
4732 struct nfs4_session
*session
= clp
->cl_session
;
4733 struct nfs41_create_session_args args
= {
4735 .cb_program
= NFS4_CALLBACK
,
4737 struct nfs41_create_session_res res
= {
4740 struct rpc_message msg
= {
4741 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
4747 nfs4_init_channel_attrs(&args
);
4748 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
4750 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4753 /* Verify the session's negotiated channel_attrs values */
4754 status
= nfs4_verify_channel_attrs(&args
, session
);
4756 /* Increment the clientid slot sequence id */
4764 * Issues a CREATE_SESSION operation to the server.
4765 * It is the responsibility of the caller to verify the session is
4766 * expired before calling this routine.
4768 int nfs4_proc_create_session(struct nfs_client
*clp
, int reset
)
4772 struct nfs_fsinfo fsinfo
;
4773 struct nfs4_session
*session
= clp
->cl_session
;
4775 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
4777 status
= _nfs4_proc_create_session(clp
);
4781 /* Init or reset the fore channel */
4783 status
= nfs4_reset_slot_tables(session
);
4785 status
= nfs4_init_slot_tables(session
);
4786 dprintk("fore channel slot table initialization returned %d\n", status
);
4790 ptr
= (unsigned *)&session
->sess_id
.data
[0];
4791 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
4792 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
4795 /* Lease time is aleady set */
4798 /* Get the lease time */
4799 status
= nfs4_proc_get_lease_time(clp
, &fsinfo
);
4801 /* Update lease time and schedule renewal */
4802 spin_lock(&clp
->cl_lock
);
4803 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
4804 clp
->cl_last_renewal
= jiffies
;
4805 clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
4806 spin_unlock(&clp
->cl_lock
);
4808 nfs4_schedule_state_renewal(clp
);
4811 dprintk("<-- %s\n", __func__
);
4816 * Issue the over-the-wire RPC DESTROY_SESSION.
4817 * The caller must serialize access to this routine.
4819 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
4822 struct rpc_message msg
;
4824 dprintk("--> nfs4_proc_destroy_session\n");
4826 /* session is still being setup */
4827 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
4830 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
4831 msg
.rpc_argp
= session
;
4832 msg
.rpc_resp
= NULL
;
4833 msg
.rpc_cred
= NULL
;
4834 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4838 "Got error %d from the server on DESTROY_SESSION. "
4839 "Session has been destroyed regardless...\n", status
);
4841 dprintk("<-- nfs4_proc_destroy_session\n");
4845 int nfs4_init_session(struct nfs_server
*server
)
4847 struct nfs_client
*clp
= server
->nfs_client
;
4850 if (!nfs4_has_session(clp
))
4853 clp
->cl_session
->fc_attrs
.max_rqst_sz
= server
->wsize
;
4854 clp
->cl_session
->fc_attrs
.max_resp_sz
= server
->rsize
;
4855 ret
= nfs4_recover_expired_lease(server
);
4857 ret
= nfs4_check_client_ready(clp
);
4862 * Renew the cl_session lease.
4864 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4866 struct nfs4_sequence_args args
;
4867 struct nfs4_sequence_res res
;
4869 struct rpc_message msg
= {
4870 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
4876 args
.sa_cache_this
= 0;
4878 return nfs4_call_sync_sequence(clp
, clp
->cl_rpcclient
, &msg
, &args
,
4882 void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
4884 struct nfs_client
*clp
= (struct nfs_client
*)data
;
4886 nfs41_sequence_done(clp
, task
->tk_msg
.rpc_resp
, task
->tk_status
);
4888 if (task
->tk_status
< 0) {
4889 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
4891 if (_nfs4_async_handle_error(task
, NULL
, clp
, NULL
)
4893 nfs4_restart_rpc(task
, clp
, task
->tk_msg
.rpc_resp
);
4897 nfs41_sequence_free_slot(clp
, task
->tk_msg
.rpc_resp
);
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 #endif /* CONFIG_NFS_V4_1 */
4954 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
4955 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
4956 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
4957 .recover_open
= nfs4_open_reclaim
,
4958 .recover_lock
= nfs4_lock_reclaim
,
4959 .establish_clid
= nfs4_init_clientid
,
4960 .get_clid_cred
= nfs4_get_setclientid_cred
,
4963 #if defined(CONFIG_NFS_V4_1)
4964 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
4965 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
4966 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
4967 .recover_open
= nfs4_open_reclaim
,
4968 .recover_lock
= nfs4_lock_reclaim
,
4969 .establish_clid
= nfs41_init_clientid
,
4970 .get_clid_cred
= nfs4_get_exchange_id_cred
,
4972 #endif /* CONFIG_NFS_V4_1 */
4974 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
4975 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
4976 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
4977 .recover_open
= nfs4_open_expired
,
4978 .recover_lock
= nfs4_lock_expired
,
4979 .establish_clid
= nfs4_init_clientid
,
4980 .get_clid_cred
= nfs4_get_setclientid_cred
,
4983 #if defined(CONFIG_NFS_V4_1)
4984 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
4985 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
4986 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
4987 .recover_open
= nfs4_open_expired
,
4988 .recover_lock
= nfs4_lock_expired
,
4989 .establish_clid
= nfs41_init_clientid
,
4990 .get_clid_cred
= nfs4_get_exchange_id_cred
,
4992 #endif /* CONFIG_NFS_V4_1 */
4994 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
4995 .sched_state_renewal
= nfs4_proc_async_renew
,
4996 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
4997 .renew_lease
= nfs4_proc_renew
,
5000 #if defined(CONFIG_NFS_V4_1)
5001 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
5002 .sched_state_renewal
= nfs41_proc_async_sequence
,
5003 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
5004 .renew_lease
= nfs4_proc_sequence
,
5009 * Per minor version reboot and network partition recovery ops
5012 struct nfs4_state_recovery_ops
*nfs4_reboot_recovery_ops
[] = {
5013 &nfs40_reboot_recovery_ops
,
5014 #if defined(CONFIG_NFS_V4_1)
5015 &nfs41_reboot_recovery_ops
,
5019 struct nfs4_state_recovery_ops
*nfs4_nograce_recovery_ops
[] = {
5020 &nfs40_nograce_recovery_ops
,
5021 #if defined(CONFIG_NFS_V4_1)
5022 &nfs41_nograce_recovery_ops
,
5026 struct nfs4_state_maintenance_ops
*nfs4_state_renewal_ops
[] = {
5027 &nfs40_state_renewal_ops
,
5028 #if defined(CONFIG_NFS_V4_1)
5029 &nfs41_state_renewal_ops
,
5033 static const struct inode_operations nfs4_file_inode_operations
= {
5034 .permission
= nfs_permission
,
5035 .getattr
= nfs_getattr
,
5036 .setattr
= nfs_setattr
,
5037 .getxattr
= nfs4_getxattr
,
5038 .setxattr
= nfs4_setxattr
,
5039 .listxattr
= nfs4_listxattr
,
5042 const struct nfs_rpc_ops nfs_v4_clientops
= {
5043 .version
= 4, /* protocol version */
5044 .dentry_ops
= &nfs4_dentry_operations
,
5045 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5046 .file_inode_ops
= &nfs4_file_inode_operations
,
5047 .getroot
= nfs4_proc_get_root
,
5048 .getattr
= nfs4_proc_getattr
,
5049 .setattr
= nfs4_proc_setattr
,
5050 .lookupfh
= nfs4_proc_lookupfh
,
5051 .lookup
= nfs4_proc_lookup
,
5052 .access
= nfs4_proc_access
,
5053 .readlink
= nfs4_proc_readlink
,
5054 .create
= nfs4_proc_create
,
5055 .remove
= nfs4_proc_remove
,
5056 .unlink_setup
= nfs4_proc_unlink_setup
,
5057 .unlink_done
= nfs4_proc_unlink_done
,
5058 .rename
= nfs4_proc_rename
,
5059 .link
= nfs4_proc_link
,
5060 .symlink
= nfs4_proc_symlink
,
5061 .mkdir
= nfs4_proc_mkdir
,
5062 .rmdir
= nfs4_proc_remove
,
5063 .readdir
= nfs4_proc_readdir
,
5064 .mknod
= nfs4_proc_mknod
,
5065 .statfs
= nfs4_proc_statfs
,
5066 .fsinfo
= nfs4_proc_fsinfo
,
5067 .pathconf
= nfs4_proc_pathconf
,
5068 .set_capabilities
= nfs4_server_capabilities
,
5069 .decode_dirent
= nfs4_decode_dirent
,
5070 .read_setup
= nfs4_proc_read_setup
,
5071 .read_done
= nfs4_read_done
,
5072 .write_setup
= nfs4_proc_write_setup
,
5073 .write_done
= nfs4_write_done
,
5074 .commit_setup
= nfs4_proc_commit_setup
,
5075 .commit_done
= nfs4_commit_done
,
5076 .lock
= nfs4_proc_lock
,
5077 .clear_acl_cache
= nfs4_zap_acl_attr
,
5078 .close_context
= nfs4_close_context
,