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/slab.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/nfs.h>
45 #include <linux/nfs4.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/nfs_page.h>
48 #include <linux/namei.h>
49 #include <linux/mount.h>
50 #include <linux/module.h>
51 #include <linux/sunrpc/bc_xprt.h>
52 #include <linux/xattr.h>
53 #include <linux/utsname.h>
57 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_PROC
65 #define NFS4_POLL_RETRY_MIN (HZ/10)
66 #define NFS4_POLL_RETRY_MAX (15*HZ)
68 #define NFS4_MAX_LOOP_ON_RECOVER (10)
71 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
72 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
73 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
74 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
75 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
76 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
77 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
78 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
79 struct nfs4_state
*state
);
81 /* Prevent leaks of NFSv4 errors into userland */
82 static int nfs4_map_errors(int err
)
87 case -NFS4ERR_RESOURCE
:
90 dprintk("%s could not handle NFSv4 error %d\n",
98 * This is our standard bitmap for GETATTR requests.
100 const u32 nfs4_fattr_bitmap
[2] = {
102 | FATTR4_WORD0_CHANGE
105 | FATTR4_WORD0_FILEID
,
107 | FATTR4_WORD1_NUMLINKS
109 | FATTR4_WORD1_OWNER_GROUP
110 | FATTR4_WORD1_RAWDEV
111 | FATTR4_WORD1_SPACE_USED
112 | FATTR4_WORD1_TIME_ACCESS
113 | FATTR4_WORD1_TIME_METADATA
114 | FATTR4_WORD1_TIME_MODIFY
117 const u32 nfs4_statfs_bitmap
[2] = {
118 FATTR4_WORD0_FILES_AVAIL
119 | FATTR4_WORD0_FILES_FREE
120 | FATTR4_WORD0_FILES_TOTAL
,
121 FATTR4_WORD1_SPACE_AVAIL
122 | FATTR4_WORD1_SPACE_FREE
123 | FATTR4_WORD1_SPACE_TOTAL
126 const u32 nfs4_pathconf_bitmap
[2] = {
128 | FATTR4_WORD0_MAXNAME
,
132 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
133 | FATTR4_WORD0_MAXREAD
134 | FATTR4_WORD0_MAXWRITE
135 | FATTR4_WORD0_LEASE_TIME
,
136 FATTR4_WORD1_TIME_DELTA
137 | FATTR4_WORD1_FS_LAYOUT_TYPES
140 const u32 nfs4_fs_locations_bitmap
[2] = {
142 | FATTR4_WORD0_CHANGE
145 | FATTR4_WORD0_FILEID
146 | FATTR4_WORD0_FS_LOCATIONS
,
148 | FATTR4_WORD1_NUMLINKS
150 | FATTR4_WORD1_OWNER_GROUP
151 | FATTR4_WORD1_RAWDEV
152 | FATTR4_WORD1_SPACE_USED
153 | FATTR4_WORD1_TIME_ACCESS
154 | FATTR4_WORD1_TIME_METADATA
155 | FATTR4_WORD1_TIME_MODIFY
156 | FATTR4_WORD1_MOUNTED_ON_FILEID
159 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
160 struct nfs4_readdir_arg
*readdir
)
164 BUG_ON(readdir
->count
< 80);
166 readdir
->cookie
= cookie
;
167 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
172 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
177 * NFSv4 servers do not return entries for '.' and '..'
178 * Therefore, we fake these entries here. We let '.'
179 * have cookie 0 and '..' have cookie 1. Note that
180 * when talking to the server, we always send cookie 0
183 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
186 *p
++ = xdr_one
; /* next */
187 *p
++ = xdr_zero
; /* cookie, first word */
188 *p
++ = xdr_one
; /* cookie, second word */
189 *p
++ = xdr_one
; /* entry len */
190 memcpy(p
, ".\0\0\0", 4); /* entry */
192 *p
++ = xdr_one
; /* bitmap length */
193 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
194 *p
++ = htonl(8); /* attribute buffer length */
195 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
198 *p
++ = xdr_one
; /* next */
199 *p
++ = xdr_zero
; /* cookie, first word */
200 *p
++ = xdr_two
; /* cookie, second word */
201 *p
++ = xdr_two
; /* entry len */
202 memcpy(p
, "..\0\0", 4); /* entry */
204 *p
++ = xdr_one
; /* bitmap length */
205 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
206 *p
++ = htonl(8); /* attribute buffer length */
207 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
209 readdir
->pgbase
= (char *)p
- (char *)start
;
210 readdir
->count
-= readdir
->pgbase
;
211 kunmap_atomic(start
, KM_USER0
);
214 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
220 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
221 nfs_wait_bit_killable
, TASK_KILLABLE
);
225 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
232 *timeout
= NFS4_POLL_RETRY_MIN
;
233 if (*timeout
> NFS4_POLL_RETRY_MAX
)
234 *timeout
= NFS4_POLL_RETRY_MAX
;
235 schedule_timeout_killable(*timeout
);
236 if (fatal_signal_pending(current
))
242 /* This is the error handling routine for processes that are allowed
245 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
247 struct nfs_client
*clp
= server
->nfs_client
;
248 struct nfs4_state
*state
= exception
->state
;
251 exception
->retry
= 0;
255 case -NFS4ERR_ADMIN_REVOKED
:
256 case -NFS4ERR_BAD_STATEID
:
257 case -NFS4ERR_OPENMODE
:
260 nfs4_schedule_stateid_recovery(server
, state
);
261 goto wait_on_recovery
;
262 case -NFS4ERR_STALE_STATEID
:
263 case -NFS4ERR_STALE_CLIENTID
:
264 case -NFS4ERR_EXPIRED
:
265 nfs4_schedule_lease_recovery(clp
);
266 goto wait_on_recovery
;
267 #if defined(CONFIG_NFS_V4_1)
268 case -NFS4ERR_BADSESSION
:
269 case -NFS4ERR_BADSLOT
:
270 case -NFS4ERR_BAD_HIGH_SLOT
:
271 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
272 case -NFS4ERR_DEADSESSION
:
273 case -NFS4ERR_SEQ_FALSE_RETRY
:
274 case -NFS4ERR_SEQ_MISORDERED
:
275 dprintk("%s ERROR: %d Reset session\n", __func__
,
277 nfs4_schedule_session_recovery(clp
->cl_session
);
278 exception
->retry
= 1;
280 #endif /* defined(CONFIG_NFS_V4_1) */
281 case -NFS4ERR_FILE_OPEN
:
282 if (exception
->timeout
> HZ
) {
283 /* We have retried a decent amount, time to
292 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
295 case -NFS4ERR_OLD_STATEID
:
296 exception
->retry
= 1;
298 /* We failed to handle the error */
299 return nfs4_map_errors(ret
);
301 ret
= nfs4_wait_clnt_recover(clp
);
303 exception
->retry
= 1;
308 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
310 spin_lock(&clp
->cl_lock
);
311 if (time_before(clp
->cl_last_renewal
,timestamp
))
312 clp
->cl_last_renewal
= timestamp
;
313 spin_unlock(&clp
->cl_lock
);
316 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
318 do_renew_lease(server
->nfs_client
, timestamp
);
321 #if defined(CONFIG_NFS_V4_1)
324 * nfs4_free_slot - free a slot and efficiently update slot table.
326 * freeing a slot is trivially done by clearing its respective bit
328 * If the freed slotid equals highest_used_slotid we want to update it
329 * so that the server would be able to size down the slot table if needed,
330 * otherwise we know that the highest_used_slotid is still in use.
331 * When updating highest_used_slotid there may be "holes" in the bitmap
332 * so we need to scan down from highest_used_slotid to 0 looking for the now
333 * highest slotid in use.
334 * If none found, highest_used_slotid is set to -1.
336 * Must be called while holding tbl->slot_tbl_lock
339 nfs4_free_slot(struct nfs4_slot_table
*tbl
, struct nfs4_slot
*free_slot
)
341 int free_slotid
= free_slot
- tbl
->slots
;
342 int slotid
= free_slotid
;
344 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
345 /* clear used bit in bitmap */
346 __clear_bit(slotid
, tbl
->used_slots
);
348 /* update highest_used_slotid when it is freed */
349 if (slotid
== tbl
->highest_used_slotid
) {
350 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
351 if (slotid
< tbl
->max_slots
)
352 tbl
->highest_used_slotid
= slotid
;
354 tbl
->highest_used_slotid
= -1;
356 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
357 free_slotid
, tbl
->highest_used_slotid
);
361 * Signal state manager thread if session fore channel is drained
363 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
365 struct rpc_task
*task
;
367 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
368 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
370 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
374 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
377 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
378 complete(&ses
->fc_slot_table
.complete
);
382 * Signal state manager thread if session back channel is drained
384 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
386 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
387 ses
->bc_slot_table
.highest_used_slotid
!= -1)
389 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
390 complete(&ses
->bc_slot_table
.complete
);
393 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
395 struct nfs4_slot_table
*tbl
;
397 tbl
= &res
->sr_session
->fc_slot_table
;
399 /* just wake up the next guy waiting since
400 * we may have not consumed a slot after all */
401 dprintk("%s: No slot\n", __func__
);
405 spin_lock(&tbl
->slot_tbl_lock
);
406 nfs4_free_slot(tbl
, res
->sr_slot
);
407 nfs4_check_drain_fc_complete(res
->sr_session
);
408 spin_unlock(&tbl
->slot_tbl_lock
);
412 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
414 unsigned long timestamp
;
415 struct nfs_client
*clp
;
418 * sr_status remains 1 if an RPC level error occurred. The server
419 * may or may not have processed the sequence operation..
420 * Proceed as if the server received and processed the sequence
423 if (res
->sr_status
== 1)
424 res
->sr_status
= NFS_OK
;
426 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
430 /* Check the SEQUENCE operation status */
431 switch (res
->sr_status
) {
433 /* Update the slot's sequence and clientid lease timer */
434 ++res
->sr_slot
->seq_nr
;
435 timestamp
= res
->sr_renewal_time
;
436 clp
= res
->sr_session
->clp
;
437 do_renew_lease(clp
, timestamp
);
438 /* Check sequence flags */
439 if (atomic_read(&clp
->cl_count
) > 1)
440 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
443 /* The server detected a resend of the RPC call and
444 * returned NFS4ERR_DELAY as per Section 2.10.6.2
447 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
449 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
450 res
->sr_slot
->seq_nr
);
453 /* Just update the slot sequence no. */
454 ++res
->sr_slot
->seq_nr
;
457 /* The session may be reset by one of the error handlers. */
458 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
459 nfs41_sequence_free_slot(res
);
462 if (!rpc_restart_call(task
))
464 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
468 static int nfs4_sequence_done(struct rpc_task
*task
,
469 struct nfs4_sequence_res
*res
)
471 if (res
->sr_session
== NULL
)
473 return nfs41_sequence_done(task
, res
);
477 * nfs4_find_slot - efficiently look for a free slot
479 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
480 * If found, we mark the slot as used, update the highest_used_slotid,
481 * and respectively set up the sequence operation args.
482 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
484 * Note: must be called with under the slot_tbl_lock.
487 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
490 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
491 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
493 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
494 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
496 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
497 if (slotid
>= tbl
->max_slots
)
499 __set_bit(slotid
, tbl
->used_slots
);
500 if (slotid
> tbl
->highest_used_slotid
)
501 tbl
->highest_used_slotid
= slotid
;
504 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
505 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
509 static int nfs41_setup_sequence(struct nfs4_session
*session
,
510 struct nfs4_sequence_args
*args
,
511 struct nfs4_sequence_res
*res
,
513 struct rpc_task
*task
)
515 struct nfs4_slot
*slot
;
516 struct nfs4_slot_table
*tbl
;
519 dprintk("--> %s\n", __func__
);
520 /* slot already allocated? */
521 if (res
->sr_slot
!= NULL
)
524 tbl
= &session
->fc_slot_table
;
526 spin_lock(&tbl
->slot_tbl_lock
);
527 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
528 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
530 * The state manager will wait until the slot table is empty.
531 * Schedule the reset thread
533 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
534 spin_unlock(&tbl
->slot_tbl_lock
);
535 dprintk("%s Schedule Session Reset\n", __func__
);
539 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
540 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
541 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
542 spin_unlock(&tbl
->slot_tbl_lock
);
543 dprintk("%s enforce FIFO order\n", __func__
);
547 slotid
= nfs4_find_slot(tbl
);
548 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
549 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
550 spin_unlock(&tbl
->slot_tbl_lock
);
551 dprintk("<-- %s: no free slots\n", __func__
);
554 spin_unlock(&tbl
->slot_tbl_lock
);
556 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
557 slot
= tbl
->slots
+ slotid
;
558 args
->sa_session
= session
;
559 args
->sa_slotid
= slotid
;
560 args
->sa_cache_this
= cache_reply
;
562 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
564 res
->sr_session
= session
;
566 res
->sr_renewal_time
= jiffies
;
567 res
->sr_status_flags
= 0;
569 * sr_status is only set in decode_sequence, and so will remain
570 * set to 1 if an rpc level failure occurs.
576 int nfs4_setup_sequence(const struct nfs_server
*server
,
577 struct nfs4_sequence_args
*args
,
578 struct nfs4_sequence_res
*res
,
580 struct rpc_task
*task
)
582 struct nfs4_session
*session
= nfs4_get_session(server
);
585 if (session
== NULL
) {
586 args
->sa_session
= NULL
;
587 res
->sr_session
= NULL
;
591 dprintk("--> %s clp %p session %p sr_slot %td\n",
592 __func__
, session
->clp
, session
, res
->sr_slot
?
593 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
595 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
598 dprintk("<-- %s status=%d\n", __func__
, ret
);
602 struct nfs41_call_sync_data
{
603 const struct nfs_server
*seq_server
;
604 struct nfs4_sequence_args
*seq_args
;
605 struct nfs4_sequence_res
*seq_res
;
609 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
611 struct nfs41_call_sync_data
*data
= calldata
;
613 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
615 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
616 data
->seq_res
, data
->cache_reply
, task
))
618 rpc_call_start(task
);
621 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
623 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
624 nfs41_call_sync_prepare(task
, calldata
);
627 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
629 struct nfs41_call_sync_data
*data
= calldata
;
631 nfs41_sequence_done(task
, data
->seq_res
);
634 struct rpc_call_ops nfs41_call_sync_ops
= {
635 .rpc_call_prepare
= nfs41_call_sync_prepare
,
636 .rpc_call_done
= nfs41_call_sync_done
,
639 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
640 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
641 .rpc_call_done
= nfs41_call_sync_done
,
644 static int nfs4_call_sync_sequence(struct nfs_server
*server
,
645 struct rpc_message
*msg
,
646 struct nfs4_sequence_args
*args
,
647 struct nfs4_sequence_res
*res
,
652 struct rpc_task
*task
;
653 struct nfs41_call_sync_data data
= {
654 .seq_server
= server
,
657 .cache_reply
= cache_reply
,
659 struct rpc_task_setup task_setup
= {
660 .rpc_client
= server
->client
,
662 .callback_ops
= &nfs41_call_sync_ops
,
663 .callback_data
= &data
668 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
669 task
= rpc_run_task(&task_setup
);
673 ret
= task
->tk_status
;
679 int _nfs4_call_sync_session(struct nfs_server
*server
,
680 struct rpc_message
*msg
,
681 struct nfs4_sequence_args
*args
,
682 struct nfs4_sequence_res
*res
,
685 return nfs4_call_sync_sequence(server
, msg
, args
, res
, cache_reply
, 0);
689 static int nfs4_sequence_done(struct rpc_task
*task
,
690 struct nfs4_sequence_res
*res
)
694 #endif /* CONFIG_NFS_V4_1 */
696 int _nfs4_call_sync(struct nfs_server
*server
,
697 struct rpc_message
*msg
,
698 struct nfs4_sequence_args
*args
,
699 struct nfs4_sequence_res
*res
,
702 args
->sa_session
= res
->sr_session
= NULL
;
703 return rpc_call_sync(server
->client
, msg
, 0);
706 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
707 (server)->nfs_client->cl_mvops->call_sync((server), (msg), &(args)->seq_args, \
708 &(res)->seq_res, (cache_reply))
710 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
712 struct nfs_inode
*nfsi
= NFS_I(dir
);
714 spin_lock(&dir
->i_lock
);
715 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
716 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
717 nfs_force_lookup_revalidate(dir
);
718 nfsi
->change_attr
= cinfo
->after
;
719 spin_unlock(&dir
->i_lock
);
722 struct nfs4_opendata
{
724 struct nfs_openargs o_arg
;
725 struct nfs_openres o_res
;
726 struct nfs_open_confirmargs c_arg
;
727 struct nfs_open_confirmres c_res
;
728 struct nfs_fattr f_attr
;
729 struct nfs_fattr dir_attr
;
732 struct nfs4_state_owner
*owner
;
733 struct nfs4_state
*state
;
735 unsigned long timestamp
;
736 unsigned int rpc_done
: 1;
742 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
744 p
->o_res
.f_attr
= &p
->f_attr
;
745 p
->o_res
.dir_attr
= &p
->dir_attr
;
746 p
->o_res
.seqid
= p
->o_arg
.seqid
;
747 p
->c_res
.seqid
= p
->c_arg
.seqid
;
748 p
->o_res
.server
= p
->o_arg
.server
;
749 nfs_fattr_init(&p
->f_attr
);
750 nfs_fattr_init(&p
->dir_attr
);
753 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
754 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
755 const struct iattr
*attrs
,
758 struct dentry
*parent
= dget_parent(path
->dentry
);
759 struct inode
*dir
= parent
->d_inode
;
760 struct nfs_server
*server
= NFS_SERVER(dir
);
761 struct nfs4_opendata
*p
;
763 p
= kzalloc(sizeof(*p
), gfp_mask
);
766 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
767 if (p
->o_arg
.seqid
== NULL
)
773 atomic_inc(&sp
->so_count
);
774 p
->o_arg
.fh
= NFS_FH(dir
);
775 p
->o_arg
.open_flags
= flags
;
776 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
777 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
778 p
->o_arg
.id
= sp
->so_owner_id
.id
;
779 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
780 p
->o_arg
.server
= server
;
781 p
->o_arg
.bitmask
= server
->attr_bitmask
;
782 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
783 if (flags
& O_CREAT
) {
786 p
->o_arg
.u
.attrs
= &p
->attrs
;
787 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
788 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
792 p
->c_arg
.fh
= &p
->o_res
.fh
;
793 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
794 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
795 nfs4_init_opendata_res(p
);
805 static void nfs4_opendata_free(struct kref
*kref
)
807 struct nfs4_opendata
*p
= container_of(kref
,
808 struct nfs4_opendata
, kref
);
810 nfs_free_seqid(p
->o_arg
.seqid
);
811 if (p
->state
!= NULL
)
812 nfs4_put_open_state(p
->state
);
813 nfs4_put_state_owner(p
->owner
);
819 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
822 kref_put(&p
->kref
, nfs4_opendata_free
);
825 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
829 ret
= rpc_wait_for_completion_task(task
);
833 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
837 if (open_mode
& O_EXCL
)
839 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
841 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
842 && state
->n_rdonly
!= 0;
845 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
846 && state
->n_wronly
!= 0;
848 case FMODE_READ
|FMODE_WRITE
:
849 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
850 && state
->n_rdwr
!= 0;
856 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
858 if ((delegation
->type
& fmode
) != fmode
)
860 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
862 nfs_mark_delegation_referenced(delegation
);
866 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
875 case FMODE_READ
|FMODE_WRITE
:
878 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
881 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
883 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
884 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
885 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
888 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
891 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
893 case FMODE_READ
|FMODE_WRITE
:
894 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
898 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
900 write_seqlock(&state
->seqlock
);
901 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
902 write_sequnlock(&state
->seqlock
);
905 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
908 * Protect the call to nfs4_state_set_mode_locked and
909 * serialise the stateid update
911 write_seqlock(&state
->seqlock
);
912 if (deleg_stateid
!= NULL
) {
913 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
914 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
916 if (open_stateid
!= NULL
)
917 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
918 write_sequnlock(&state
->seqlock
);
919 spin_lock(&state
->owner
->so_lock
);
920 update_open_stateflags(state
, fmode
);
921 spin_unlock(&state
->owner
->so_lock
);
924 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
926 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
927 struct nfs_delegation
*deleg_cur
;
930 fmode
&= (FMODE_READ
|FMODE_WRITE
);
933 deleg_cur
= rcu_dereference(nfsi
->delegation
);
934 if (deleg_cur
== NULL
)
937 spin_lock(&deleg_cur
->lock
);
938 if (nfsi
->delegation
!= deleg_cur
||
939 (deleg_cur
->type
& fmode
) != fmode
)
940 goto no_delegation_unlock
;
942 if (delegation
== NULL
)
943 delegation
= &deleg_cur
->stateid
;
944 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
945 goto no_delegation_unlock
;
947 nfs_mark_delegation_referenced(deleg_cur
);
948 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
950 no_delegation_unlock
:
951 spin_unlock(&deleg_cur
->lock
);
955 if (!ret
&& open_stateid
!= NULL
) {
956 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
964 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
966 struct nfs_delegation
*delegation
;
969 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
970 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
975 nfs_inode_return_delegation(inode
);
978 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
980 struct nfs4_state
*state
= opendata
->state
;
981 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
982 struct nfs_delegation
*delegation
;
983 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
984 fmode_t fmode
= opendata
->o_arg
.fmode
;
985 nfs4_stateid stateid
;
989 if (can_open_cached(state
, fmode
, open_mode
)) {
990 spin_lock(&state
->owner
->so_lock
);
991 if (can_open_cached(state
, fmode
, open_mode
)) {
992 update_open_stateflags(state
, fmode
);
993 spin_unlock(&state
->owner
->so_lock
);
994 goto out_return_state
;
996 spin_unlock(&state
->owner
->so_lock
);
999 delegation
= rcu_dereference(nfsi
->delegation
);
1000 if (delegation
== NULL
||
1001 !can_open_delegated(delegation
, fmode
)) {
1005 /* Save the delegation */
1006 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1008 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1013 /* Try to update the stateid using the delegation */
1014 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1015 goto out_return_state
;
1018 return ERR_PTR(ret
);
1020 atomic_inc(&state
->count
);
1024 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1026 struct inode
*inode
;
1027 struct nfs4_state
*state
= NULL
;
1028 struct nfs_delegation
*delegation
;
1031 if (!data
->rpc_done
) {
1032 state
= nfs4_try_open_cached(data
);
1037 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1039 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1040 ret
= PTR_ERR(inode
);
1044 state
= nfs4_get_open_state(inode
, data
->owner
);
1047 if (data
->o_res
.delegation_type
!= 0) {
1048 int delegation_flags
= 0;
1051 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1053 delegation_flags
= delegation
->flags
;
1055 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1056 nfs_inode_set_delegation(state
->inode
,
1057 data
->owner
->so_cred
,
1060 nfs_inode_reclaim_delegation(state
->inode
,
1061 data
->owner
->so_cred
,
1065 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1073 return ERR_PTR(ret
);
1076 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1078 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1079 struct nfs_open_context
*ctx
;
1081 spin_lock(&state
->inode
->i_lock
);
1082 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1083 if (ctx
->state
!= state
)
1085 get_nfs_open_context(ctx
);
1086 spin_unlock(&state
->inode
->i_lock
);
1089 spin_unlock(&state
->inode
->i_lock
);
1090 return ERR_PTR(-ENOENT
);
1093 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1095 struct nfs4_opendata
*opendata
;
1097 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1098 if (opendata
== NULL
)
1099 return ERR_PTR(-ENOMEM
);
1100 opendata
->state
= state
;
1101 atomic_inc(&state
->count
);
1105 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1107 struct nfs4_state
*newstate
;
1110 opendata
->o_arg
.open_flags
= 0;
1111 opendata
->o_arg
.fmode
= fmode
;
1112 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1113 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1114 nfs4_init_opendata_res(opendata
);
1115 ret
= _nfs4_recover_proc_open(opendata
);
1118 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1119 if (IS_ERR(newstate
))
1120 return PTR_ERR(newstate
);
1121 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1126 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1128 struct nfs4_state
*newstate
;
1131 /* memory barrier prior to reading state->n_* */
1132 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1134 if (state
->n_rdwr
!= 0) {
1135 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1136 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1139 if (newstate
!= state
)
1142 if (state
->n_wronly
!= 0) {
1143 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1144 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1147 if (newstate
!= state
)
1150 if (state
->n_rdonly
!= 0) {
1151 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1152 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1155 if (newstate
!= state
)
1159 * We may have performed cached opens for all three recoveries.
1160 * Check if we need to update the current stateid.
1162 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1163 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1164 write_seqlock(&state
->seqlock
);
1165 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1166 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1167 write_sequnlock(&state
->seqlock
);
1174 * reclaim state on the server after a reboot.
1176 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1178 struct nfs_delegation
*delegation
;
1179 struct nfs4_opendata
*opendata
;
1180 fmode_t delegation_type
= 0;
1183 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1184 if (IS_ERR(opendata
))
1185 return PTR_ERR(opendata
);
1186 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1187 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1189 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1190 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1191 delegation_type
= delegation
->type
;
1193 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1194 status
= nfs4_open_recover(opendata
, state
);
1195 nfs4_opendata_put(opendata
);
1199 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1201 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1202 struct nfs4_exception exception
= { };
1205 err
= _nfs4_do_open_reclaim(ctx
, state
);
1206 if (err
!= -NFS4ERR_DELAY
)
1208 nfs4_handle_exception(server
, err
, &exception
);
1209 } while (exception
.retry
);
1213 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1215 struct nfs_open_context
*ctx
;
1218 ctx
= nfs4_state_find_open_context(state
);
1220 return PTR_ERR(ctx
);
1221 ret
= nfs4_do_open_reclaim(ctx
, state
);
1222 put_nfs_open_context(ctx
);
1226 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1228 struct nfs4_opendata
*opendata
;
1231 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1232 if (IS_ERR(opendata
))
1233 return PTR_ERR(opendata
);
1234 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1235 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1236 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1237 ret
= nfs4_open_recover(opendata
, state
);
1238 nfs4_opendata_put(opendata
);
1242 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1244 struct nfs4_exception exception
= { };
1245 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1248 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1254 case -NFS4ERR_BADSESSION
:
1255 case -NFS4ERR_BADSLOT
:
1256 case -NFS4ERR_BAD_HIGH_SLOT
:
1257 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1258 case -NFS4ERR_DEADSESSION
:
1259 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1261 case -NFS4ERR_STALE_CLIENTID
:
1262 case -NFS4ERR_STALE_STATEID
:
1263 case -NFS4ERR_EXPIRED
:
1264 /* Don't recall a delegation if it was lost */
1265 nfs4_schedule_lease_recovery(server
->nfs_client
);
1269 * The show must go on: exit, but mark the
1270 * stateid as needing recovery.
1272 case -NFS4ERR_ADMIN_REVOKED
:
1273 case -NFS4ERR_BAD_STATEID
:
1274 nfs4_schedule_stateid_recovery(server
, state
);
1277 * User RPCSEC_GSS context has expired.
1278 * We cannot recover this stateid now, so
1279 * skip it and allow recovery thread to
1286 err
= nfs4_handle_exception(server
, err
, &exception
);
1287 } while (exception
.retry
);
1292 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1294 struct nfs4_opendata
*data
= calldata
;
1296 data
->rpc_status
= task
->tk_status
;
1297 if (data
->rpc_status
== 0) {
1298 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1299 sizeof(data
->o_res
.stateid
.data
));
1300 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1301 renew_lease(data
->o_res
.server
, data
->timestamp
);
1306 static void nfs4_open_confirm_release(void *calldata
)
1308 struct nfs4_opendata
*data
= calldata
;
1309 struct nfs4_state
*state
= NULL
;
1311 /* If this request hasn't been cancelled, do nothing */
1312 if (data
->cancelled
== 0)
1314 /* In case of error, no cleanup! */
1315 if (!data
->rpc_done
)
1317 state
= nfs4_opendata_to_nfs4_state(data
);
1319 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1321 nfs4_opendata_put(data
);
1324 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1325 .rpc_call_done
= nfs4_open_confirm_done
,
1326 .rpc_release
= nfs4_open_confirm_release
,
1330 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1332 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1334 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1335 struct rpc_task
*task
;
1336 struct rpc_message msg
= {
1337 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1338 .rpc_argp
= &data
->c_arg
,
1339 .rpc_resp
= &data
->c_res
,
1340 .rpc_cred
= data
->owner
->so_cred
,
1342 struct rpc_task_setup task_setup_data
= {
1343 .rpc_client
= server
->client
,
1344 .rpc_message
= &msg
,
1345 .callback_ops
= &nfs4_open_confirm_ops
,
1346 .callback_data
= data
,
1347 .workqueue
= nfsiod_workqueue
,
1348 .flags
= RPC_TASK_ASYNC
,
1352 kref_get(&data
->kref
);
1354 data
->rpc_status
= 0;
1355 data
->timestamp
= jiffies
;
1356 task
= rpc_run_task(&task_setup_data
);
1358 return PTR_ERR(task
);
1359 status
= nfs4_wait_for_completion_rpc_task(task
);
1361 data
->cancelled
= 1;
1364 status
= data
->rpc_status
;
1369 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1371 struct nfs4_opendata
*data
= calldata
;
1372 struct nfs4_state_owner
*sp
= data
->owner
;
1374 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1377 * Check if we still need to send an OPEN call, or if we can use
1378 * a delegation instead.
1380 if (data
->state
!= NULL
) {
1381 struct nfs_delegation
*delegation
;
1383 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1386 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1387 if (delegation
!= NULL
&&
1388 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1394 /* Update sequence id. */
1395 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1396 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1397 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1398 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1399 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1401 data
->timestamp
= jiffies
;
1402 if (nfs4_setup_sequence(data
->o_arg
.server
,
1403 &data
->o_arg
.seq_args
,
1404 &data
->o_res
.seq_res
, 1, task
))
1406 rpc_call_start(task
);
1409 task
->tk_action
= NULL
;
1413 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1415 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1416 nfs4_open_prepare(task
, calldata
);
1419 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1421 struct nfs4_opendata
*data
= calldata
;
1423 data
->rpc_status
= task
->tk_status
;
1425 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1428 if (task
->tk_status
== 0) {
1429 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1433 data
->rpc_status
= -ELOOP
;
1436 data
->rpc_status
= -EISDIR
;
1439 data
->rpc_status
= -ENOTDIR
;
1441 renew_lease(data
->o_res
.server
, data
->timestamp
);
1442 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1443 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1448 static void nfs4_open_release(void *calldata
)
1450 struct nfs4_opendata
*data
= calldata
;
1451 struct nfs4_state
*state
= NULL
;
1453 /* If this request hasn't been cancelled, do nothing */
1454 if (data
->cancelled
== 0)
1456 /* In case of error, no cleanup! */
1457 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1459 /* In case we need an open_confirm, no cleanup! */
1460 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1462 state
= nfs4_opendata_to_nfs4_state(data
);
1464 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1466 nfs4_opendata_put(data
);
1469 static const struct rpc_call_ops nfs4_open_ops
= {
1470 .rpc_call_prepare
= nfs4_open_prepare
,
1471 .rpc_call_done
= nfs4_open_done
,
1472 .rpc_release
= nfs4_open_release
,
1475 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1476 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1477 .rpc_call_done
= nfs4_open_done
,
1478 .rpc_release
= nfs4_open_release
,
1481 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1483 struct inode
*dir
= data
->dir
->d_inode
;
1484 struct nfs_server
*server
= NFS_SERVER(dir
);
1485 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1486 struct nfs_openres
*o_res
= &data
->o_res
;
1487 struct rpc_task
*task
;
1488 struct rpc_message msg
= {
1489 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1492 .rpc_cred
= data
->owner
->so_cred
,
1494 struct rpc_task_setup task_setup_data
= {
1495 .rpc_client
= server
->client
,
1496 .rpc_message
= &msg
,
1497 .callback_ops
= &nfs4_open_ops
,
1498 .callback_data
= data
,
1499 .workqueue
= nfsiod_workqueue
,
1500 .flags
= RPC_TASK_ASYNC
,
1504 kref_get(&data
->kref
);
1506 data
->rpc_status
= 0;
1507 data
->cancelled
= 0;
1509 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1510 task
= rpc_run_task(&task_setup_data
);
1512 return PTR_ERR(task
);
1513 status
= nfs4_wait_for_completion_rpc_task(task
);
1515 data
->cancelled
= 1;
1518 status
= data
->rpc_status
;
1524 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1526 struct inode
*dir
= data
->dir
->d_inode
;
1527 struct nfs_openres
*o_res
= &data
->o_res
;
1530 status
= nfs4_run_open_task(data
, 1);
1531 if (status
!= 0 || !data
->rpc_done
)
1534 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1536 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1537 status
= _nfs4_proc_open_confirm(data
);
1546 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1548 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1550 struct inode
*dir
= data
->dir
->d_inode
;
1551 struct nfs_server
*server
= NFS_SERVER(dir
);
1552 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1553 struct nfs_openres
*o_res
= &data
->o_res
;
1556 status
= nfs4_run_open_task(data
, 0);
1557 if (status
!= 0 || !data
->rpc_done
)
1560 if (o_arg
->open_flags
& O_CREAT
) {
1561 update_changeattr(dir
, &o_res
->cinfo
);
1562 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1564 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1565 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1566 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1567 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1568 status
= _nfs4_proc_open_confirm(data
);
1572 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1573 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1577 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1579 struct nfs_client
*clp
= server
->nfs_client
;
1583 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1584 ret
= nfs4_wait_clnt_recover(clp
);
1587 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1588 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1590 nfs4_schedule_state_manager(clp
);
1598 * reclaim state on the server after a network partition.
1599 * Assumes caller holds the appropriate lock
1601 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1603 struct nfs4_opendata
*opendata
;
1606 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1607 if (IS_ERR(opendata
))
1608 return PTR_ERR(opendata
);
1609 ret
= nfs4_open_recover(opendata
, state
);
1611 d_drop(ctx
->path
.dentry
);
1612 nfs4_opendata_put(opendata
);
1616 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1618 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1619 struct nfs4_exception exception
= { };
1623 err
= _nfs4_open_expired(ctx
, state
);
1627 case -NFS4ERR_GRACE
:
1628 case -NFS4ERR_DELAY
:
1629 nfs4_handle_exception(server
, err
, &exception
);
1632 } while (exception
.retry
);
1637 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1639 struct nfs_open_context
*ctx
;
1642 ctx
= nfs4_state_find_open_context(state
);
1644 return PTR_ERR(ctx
);
1645 ret
= nfs4_do_open_expired(ctx
, state
);
1646 put_nfs_open_context(ctx
);
1651 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1652 * fields corresponding to attributes that were used to store the verifier.
1653 * Make sure we clobber those fields in the later setattr call
1655 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1657 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1658 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1659 sattr
->ia_valid
|= ATTR_ATIME
;
1661 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1662 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1663 sattr
->ia_valid
|= ATTR_MTIME
;
1667 * Returns a referenced nfs4_state
1669 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
)
1671 struct nfs4_state_owner
*sp
;
1672 struct nfs4_state
*state
= NULL
;
1673 struct nfs_server
*server
= NFS_SERVER(dir
);
1674 struct nfs4_opendata
*opendata
;
1677 /* Protect against reboot recovery conflicts */
1679 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1680 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1683 status
= nfs4_recover_expired_lease(server
);
1685 goto err_put_state_owner
;
1686 if (path
->dentry
->d_inode
!= NULL
)
1687 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1689 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1690 if (opendata
== NULL
)
1691 goto err_put_state_owner
;
1693 if (path
->dentry
->d_inode
!= NULL
)
1694 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1696 status
= _nfs4_proc_open(opendata
);
1698 goto err_opendata_put
;
1700 state
= nfs4_opendata_to_nfs4_state(opendata
);
1701 status
= PTR_ERR(state
);
1703 goto err_opendata_put
;
1704 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1705 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1707 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1708 nfs4_exclusive_attrset(opendata
, sattr
);
1710 nfs_fattr_init(opendata
->o_res
.f_attr
);
1711 status
= nfs4_do_setattr(state
->inode
, cred
,
1712 opendata
->o_res
.f_attr
, sattr
,
1715 nfs_setattr_update_inode(state
->inode
, sattr
);
1716 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1718 nfs4_opendata_put(opendata
);
1719 nfs4_put_state_owner(sp
);
1723 nfs4_opendata_put(opendata
);
1724 err_put_state_owner
:
1725 nfs4_put_state_owner(sp
);
1732 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
)
1734 struct nfs4_exception exception
= { };
1735 struct nfs4_state
*res
;
1739 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1742 /* NOTE: BAD_SEQID means the server and client disagree about the
1743 * book-keeping w.r.t. state-changing operations
1744 * (OPEN/CLOSE/LOCK/LOCKU...)
1745 * It is actually a sign of a bug on the client or on the server.
1747 * If we receive a BAD_SEQID error in the particular case of
1748 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1749 * have unhashed the old state_owner for us, and that we can
1750 * therefore safely retry using a new one. We should still warn
1751 * the user though...
1753 if (status
== -NFS4ERR_BAD_SEQID
) {
1754 printk(KERN_WARNING
"NFS: v4 server %s "
1755 " returned a bad sequence-id error!\n",
1756 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1757 exception
.retry
= 1;
1761 * BAD_STATEID on OPEN means that the server cancelled our
1762 * state before it received the OPEN_CONFIRM.
1763 * Recover by retrying the request as per the discussion
1764 * on Page 181 of RFC3530.
1766 if (status
== -NFS4ERR_BAD_STATEID
) {
1767 exception
.retry
= 1;
1770 if (status
== -EAGAIN
) {
1771 /* We must have found a delegation */
1772 exception
.retry
= 1;
1775 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1776 status
, &exception
));
1777 } while (exception
.retry
);
1781 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1782 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1783 struct nfs4_state
*state
)
1785 struct nfs_server
*server
= NFS_SERVER(inode
);
1786 struct nfs_setattrargs arg
= {
1787 .fh
= NFS_FH(inode
),
1790 .bitmask
= server
->attr_bitmask
,
1792 struct nfs_setattrres res
= {
1796 struct rpc_message msg
= {
1797 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1802 unsigned long timestamp
= jiffies
;
1805 nfs_fattr_init(fattr
);
1807 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1808 /* Use that stateid */
1809 } else if (state
!= NULL
) {
1810 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1812 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1814 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
1815 if (status
== 0 && state
!= NULL
)
1816 renew_lease(server
, timestamp
);
1820 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1821 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1822 struct nfs4_state
*state
)
1824 struct nfs_server
*server
= NFS_SERVER(inode
);
1825 struct nfs4_exception exception
= { };
1828 err
= nfs4_handle_exception(server
,
1829 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1831 } while (exception
.retry
);
1835 struct nfs4_closedata
{
1837 struct inode
*inode
;
1838 struct nfs4_state
*state
;
1839 struct nfs_closeargs arg
;
1840 struct nfs_closeres res
;
1841 struct nfs_fattr fattr
;
1842 unsigned long timestamp
;
1847 static void nfs4_free_closedata(void *data
)
1849 struct nfs4_closedata
*calldata
= data
;
1850 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1853 pnfs_roc_release(calldata
->state
->inode
);
1854 nfs4_put_open_state(calldata
->state
);
1855 nfs_free_seqid(calldata
->arg
.seqid
);
1856 nfs4_put_state_owner(sp
);
1857 path_put(&calldata
->path
);
1861 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1864 spin_lock(&state
->owner
->so_lock
);
1865 if (!(fmode
& FMODE_READ
))
1866 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1867 if (!(fmode
& FMODE_WRITE
))
1868 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1869 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1870 spin_unlock(&state
->owner
->so_lock
);
1873 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1875 struct nfs4_closedata
*calldata
= data
;
1876 struct nfs4_state
*state
= calldata
->state
;
1877 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1879 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1881 /* hmm. we are done with the inode, and in the process of freeing
1882 * the state_owner. we keep this around to process errors
1884 switch (task
->tk_status
) {
1887 pnfs_roc_set_barrier(state
->inode
,
1888 calldata
->roc_barrier
);
1889 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1890 renew_lease(server
, calldata
->timestamp
);
1891 nfs4_close_clear_stateid_flags(state
,
1892 calldata
->arg
.fmode
);
1894 case -NFS4ERR_STALE_STATEID
:
1895 case -NFS4ERR_OLD_STATEID
:
1896 case -NFS4ERR_BAD_STATEID
:
1897 case -NFS4ERR_EXPIRED
:
1898 if (calldata
->arg
.fmode
== 0)
1901 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1902 rpc_restart_call_prepare(task
);
1904 nfs_release_seqid(calldata
->arg
.seqid
);
1905 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1908 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1910 struct nfs4_closedata
*calldata
= data
;
1911 struct nfs4_state
*state
= calldata
->state
;
1914 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1917 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1918 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1919 spin_lock(&state
->owner
->so_lock
);
1920 /* Calculate the change in open mode */
1921 if (state
->n_rdwr
== 0) {
1922 if (state
->n_rdonly
== 0) {
1923 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1924 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1925 calldata
->arg
.fmode
&= ~FMODE_READ
;
1927 if (state
->n_wronly
== 0) {
1928 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1929 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1930 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1933 spin_unlock(&state
->owner
->so_lock
);
1936 /* Note: exit _without_ calling nfs4_close_done */
1937 task
->tk_action
= NULL
;
1941 if (calldata
->arg
.fmode
== 0) {
1942 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
1943 if (calldata
->roc
&&
1944 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
1945 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
1951 nfs_fattr_init(calldata
->res
.fattr
);
1952 calldata
->timestamp
= jiffies
;
1953 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
1954 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1957 rpc_call_start(task
);
1960 static const struct rpc_call_ops nfs4_close_ops
= {
1961 .rpc_call_prepare
= nfs4_close_prepare
,
1962 .rpc_call_done
= nfs4_close_done
,
1963 .rpc_release
= nfs4_free_closedata
,
1967 * It is possible for data to be read/written from a mem-mapped file
1968 * after the sys_close call (which hits the vfs layer as a flush).
1969 * This means that we can't safely call nfsv4 close on a file until
1970 * the inode is cleared. This in turn means that we are not good
1971 * NFSv4 citizens - we do not indicate to the server to update the file's
1972 * share state even when we are done with one of the three share
1973 * stateid's in the inode.
1975 * NOTE: Caller must be holding the sp->so_owner semaphore!
1977 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
1979 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1980 struct nfs4_closedata
*calldata
;
1981 struct nfs4_state_owner
*sp
= state
->owner
;
1982 struct rpc_task
*task
;
1983 struct rpc_message msg
= {
1984 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1985 .rpc_cred
= state
->owner
->so_cred
,
1987 struct rpc_task_setup task_setup_data
= {
1988 .rpc_client
= server
->client
,
1989 .rpc_message
= &msg
,
1990 .callback_ops
= &nfs4_close_ops
,
1991 .workqueue
= nfsiod_workqueue
,
1992 .flags
= RPC_TASK_ASYNC
,
1994 int status
= -ENOMEM
;
1996 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
1997 if (calldata
== NULL
)
1999 calldata
->inode
= state
->inode
;
2000 calldata
->state
= state
;
2001 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2002 calldata
->arg
.stateid
= &state
->open_stateid
;
2003 /* Serialization for the sequence id */
2004 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2005 if (calldata
->arg
.seqid
== NULL
)
2006 goto out_free_calldata
;
2007 calldata
->arg
.fmode
= 0;
2008 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2009 calldata
->res
.fattr
= &calldata
->fattr
;
2010 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2011 calldata
->res
.server
= server
;
2012 calldata
->roc
= roc
;
2014 calldata
->path
= *path
;
2016 msg
.rpc_argp
= &calldata
->arg
;
2017 msg
.rpc_resp
= &calldata
->res
;
2018 task_setup_data
.callback_data
= calldata
;
2019 task
= rpc_run_task(&task_setup_data
);
2021 return PTR_ERR(task
);
2024 status
= rpc_wait_for_completion_task(task
);
2031 pnfs_roc_release(state
->inode
);
2032 nfs4_put_open_state(state
);
2033 nfs4_put_state_owner(sp
);
2037 static struct inode
*
2038 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2040 struct nfs4_state
*state
;
2042 /* Protect against concurrent sillydeletes */
2043 state
= nfs4_do_open(dir
, &ctx
->path
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2045 return ERR_CAST(state
);
2047 return igrab(state
->inode
);
2050 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2052 if (ctx
->state
== NULL
)
2055 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
2057 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
2060 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2062 struct nfs4_server_caps_arg args
= {
2065 struct nfs4_server_caps_res res
= {};
2066 struct rpc_message msg
= {
2067 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2073 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2075 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2076 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2077 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2078 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2079 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2080 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2081 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2082 server
->caps
|= NFS_CAP_ACLS
;
2083 if (res
.has_links
!= 0)
2084 server
->caps
|= NFS_CAP_HARDLINKS
;
2085 if (res
.has_symlinks
!= 0)
2086 server
->caps
|= NFS_CAP_SYMLINKS
;
2087 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2088 server
->caps
|= NFS_CAP_FILEID
;
2089 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2090 server
->caps
|= NFS_CAP_MODE
;
2091 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2092 server
->caps
|= NFS_CAP_NLINK
;
2093 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2094 server
->caps
|= NFS_CAP_OWNER
;
2095 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2096 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2097 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2098 server
->caps
|= NFS_CAP_ATIME
;
2099 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2100 server
->caps
|= NFS_CAP_CTIME
;
2101 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2102 server
->caps
|= NFS_CAP_MTIME
;
2104 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2105 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2106 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2107 server
->acl_bitmask
= res
.acl_bitmask
;
2113 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2115 struct nfs4_exception exception
= { };
2118 err
= nfs4_handle_exception(server
,
2119 _nfs4_server_capabilities(server
, fhandle
),
2121 } while (exception
.retry
);
2125 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2126 struct nfs_fsinfo
*info
)
2128 struct nfs4_lookup_root_arg args
= {
2129 .bitmask
= nfs4_fattr_bitmap
,
2131 struct nfs4_lookup_res res
= {
2133 .fattr
= info
->fattr
,
2136 struct rpc_message msg
= {
2137 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2142 nfs_fattr_init(info
->fattr
);
2143 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2146 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2147 struct nfs_fsinfo
*info
)
2149 struct nfs4_exception exception
= { };
2152 err
= nfs4_handle_exception(server
,
2153 _nfs4_lookup_root(server
, fhandle
, info
),
2155 } while (exception
.retry
);
2160 * get the file handle for the "/" directory on the server
2162 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2163 struct nfs_fsinfo
*info
)
2167 status
= nfs4_lookup_root(server
, fhandle
, info
);
2169 status
= nfs4_server_capabilities(server
, fhandle
);
2171 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2172 return nfs4_map_errors(status
);
2176 * Get locations and (maybe) other attributes of a referral.
2177 * Note that we'll actually follow the referral later when
2178 * we detect fsid mismatch in inode revalidation
2180 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2182 int status
= -ENOMEM
;
2183 struct page
*page
= NULL
;
2184 struct nfs4_fs_locations
*locations
= NULL
;
2186 page
= alloc_page(GFP_KERNEL
);
2189 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2190 if (locations
== NULL
)
2193 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2196 /* Make sure server returned a different fsid for the referral */
2197 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2198 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2203 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2204 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2206 fattr
->mode
= S_IFDIR
;
2207 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2215 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2217 struct nfs4_getattr_arg args
= {
2219 .bitmask
= server
->attr_bitmask
,
2221 struct nfs4_getattr_res res
= {
2225 struct rpc_message msg
= {
2226 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2231 nfs_fattr_init(fattr
);
2232 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2235 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2237 struct nfs4_exception exception
= { };
2240 err
= nfs4_handle_exception(server
,
2241 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2243 } while (exception
.retry
);
2248 * The file is not closed if it is opened due to the a request to change
2249 * the size of the file. The open call will not be needed once the
2250 * VFS layer lookup-intents are implemented.
2252 * Close is called when the inode is destroyed.
2253 * If we haven't opened the file for O_WRONLY, we
2254 * need to in the size_change case to obtain a stateid.
2257 * Because OPEN is always done by name in nfsv4, it is
2258 * possible that we opened a different file by the same
2259 * name. We can recognize this race condition, but we
2260 * can't do anything about it besides returning an error.
2262 * This will be fixed with VFS changes (lookup-intent).
2265 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2266 struct iattr
*sattr
)
2268 struct inode
*inode
= dentry
->d_inode
;
2269 struct rpc_cred
*cred
= NULL
;
2270 struct nfs4_state
*state
= NULL
;
2273 nfs_fattr_init(fattr
);
2275 /* Search for an existing open(O_WRITE) file */
2276 if (sattr
->ia_valid
& ATTR_FILE
) {
2277 struct nfs_open_context
*ctx
;
2279 ctx
= nfs_file_open_context(sattr
->ia_file
);
2286 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2288 nfs_setattr_update_inode(inode
, sattr
);
2292 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
2293 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2294 struct nfs_fattr
*fattr
)
2297 struct nfs4_lookup_arg args
= {
2298 .bitmask
= server
->attr_bitmask
,
2302 struct nfs4_lookup_res res
= {
2307 struct rpc_message msg
= {
2308 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2313 nfs_fattr_init(fattr
);
2315 dprintk("NFS call lookupfh %s\n", name
->name
);
2316 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2317 dprintk("NFS reply lookupfh: %d\n", status
);
2321 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2322 struct qstr
*name
, struct nfs_fh
*fhandle
,
2323 struct nfs_fattr
*fattr
)
2325 struct nfs4_exception exception
= { };
2328 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
2330 if (err
== -NFS4ERR_MOVED
) {
2334 err
= nfs4_handle_exception(server
, err
, &exception
);
2335 } while (exception
.retry
);
2339 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
2340 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2344 dprintk("NFS call lookup %s\n", name
->name
);
2345 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2346 if (status
== -NFS4ERR_MOVED
)
2347 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2348 dprintk("NFS reply lookup: %d\n", status
);
2352 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2354 struct nfs4_exception exception
= { };
2357 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2358 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
2360 } while (exception
.retry
);
2364 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2366 struct nfs_server
*server
= NFS_SERVER(inode
);
2367 struct nfs4_accessargs args
= {
2368 .fh
= NFS_FH(inode
),
2369 .bitmask
= server
->attr_bitmask
,
2371 struct nfs4_accessres res
= {
2374 struct rpc_message msg
= {
2375 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2378 .rpc_cred
= entry
->cred
,
2380 int mode
= entry
->mask
;
2384 * Determine which access bits we want to ask for...
2386 if (mode
& MAY_READ
)
2387 args
.access
|= NFS4_ACCESS_READ
;
2388 if (S_ISDIR(inode
->i_mode
)) {
2389 if (mode
& MAY_WRITE
)
2390 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2391 if (mode
& MAY_EXEC
)
2392 args
.access
|= NFS4_ACCESS_LOOKUP
;
2394 if (mode
& MAY_WRITE
)
2395 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2396 if (mode
& MAY_EXEC
)
2397 args
.access
|= NFS4_ACCESS_EXECUTE
;
2400 res
.fattr
= nfs_alloc_fattr();
2401 if (res
.fattr
== NULL
)
2404 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2407 if (res
.access
& NFS4_ACCESS_READ
)
2408 entry
->mask
|= MAY_READ
;
2409 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2410 entry
->mask
|= MAY_WRITE
;
2411 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2412 entry
->mask
|= MAY_EXEC
;
2413 nfs_refresh_inode(inode
, res
.fattr
);
2415 nfs_free_fattr(res
.fattr
);
2419 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2421 struct nfs4_exception exception
= { };
2424 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2425 _nfs4_proc_access(inode
, entry
),
2427 } while (exception
.retry
);
2432 * TODO: For the time being, we don't try to get any attributes
2433 * along with any of the zero-copy operations READ, READDIR,
2436 * In the case of the first three, we want to put the GETATTR
2437 * after the read-type operation -- this is because it is hard
2438 * to predict the length of a GETATTR response in v4, and thus
2439 * align the READ data correctly. This means that the GETATTR
2440 * may end up partially falling into the page cache, and we should
2441 * shift it into the 'tail' of the xdr_buf before processing.
2442 * To do this efficiently, we need to know the total length
2443 * of data received, which doesn't seem to be available outside
2446 * In the case of WRITE, we also want to put the GETATTR after
2447 * the operation -- in this case because we want to make sure
2448 * we get the post-operation mtime and size. This means that
2449 * we can't use xdr_encode_pages() as written: we need a variant
2450 * of it which would leave room in the 'tail' iovec.
2452 * Both of these changes to the XDR layer would in fact be quite
2453 * minor, but I decided to leave them for a subsequent patch.
2455 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2456 unsigned int pgbase
, unsigned int pglen
)
2458 struct nfs4_readlink args
= {
2459 .fh
= NFS_FH(inode
),
2464 struct nfs4_readlink_res res
;
2465 struct rpc_message msg
= {
2466 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2471 return nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
2474 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2475 unsigned int pgbase
, unsigned int pglen
)
2477 struct nfs4_exception exception
= { };
2480 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2481 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2483 } while (exception
.retry
);
2489 * We will need to arrange for the VFS layer to provide an atomic open.
2490 * Until then, this create/open method is prone to inefficiency and race
2491 * conditions due to the lookup, create, and open VFS calls from sys_open()
2492 * placed on the wire.
2494 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2495 * The file will be opened again in the subsequent VFS open call
2496 * (nfs4_proc_file_open).
2498 * The open for read will just hang around to be used by any process that
2499 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2503 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2504 int flags
, struct nfs_open_context
*ctx
)
2506 struct path my_path
= {
2509 struct path
*path
= &my_path
;
2510 struct nfs4_state
*state
;
2511 struct rpc_cred
*cred
= NULL
;
2520 sattr
->ia_mode
&= ~current_umask();
2521 state
= nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
);
2523 if (IS_ERR(state
)) {
2524 status
= PTR_ERR(state
);
2527 d_add(dentry
, igrab(state
->inode
));
2528 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2532 nfs4_close_sync(path
, state
, fmode
);
2537 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2539 struct nfs_server
*server
= NFS_SERVER(dir
);
2540 struct nfs_removeargs args
= {
2542 .name
.len
= name
->len
,
2543 .name
.name
= name
->name
,
2544 .bitmask
= server
->attr_bitmask
,
2546 struct nfs_removeres res
= {
2549 struct rpc_message msg
= {
2550 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2554 int status
= -ENOMEM
;
2556 res
.dir_attr
= nfs_alloc_fattr();
2557 if (res
.dir_attr
== NULL
)
2560 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 1);
2562 update_changeattr(dir
, &res
.cinfo
);
2563 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2565 nfs_free_fattr(res
.dir_attr
);
2570 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2572 struct nfs4_exception exception
= { };
2575 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2576 _nfs4_proc_remove(dir
, name
),
2578 } while (exception
.retry
);
2582 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2584 struct nfs_server
*server
= NFS_SERVER(dir
);
2585 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2586 struct nfs_removeres
*res
= msg
->rpc_resp
;
2588 args
->bitmask
= server
->cache_consistency_bitmask
;
2589 res
->server
= server
;
2590 res
->seq_res
.sr_slot
= NULL
;
2591 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2594 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2596 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2598 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2600 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2602 update_changeattr(dir
, &res
->cinfo
);
2603 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2607 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2609 struct nfs_server
*server
= NFS_SERVER(dir
);
2610 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2611 struct nfs_renameres
*res
= msg
->rpc_resp
;
2613 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2614 arg
->bitmask
= server
->attr_bitmask
;
2615 res
->server
= server
;
2618 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2619 struct inode
*new_dir
)
2621 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2623 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2625 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2628 update_changeattr(old_dir
, &res
->old_cinfo
);
2629 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2630 update_changeattr(new_dir
, &res
->new_cinfo
);
2631 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2635 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2636 struct inode
*new_dir
, struct qstr
*new_name
)
2638 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2639 struct nfs_renameargs arg
= {
2640 .old_dir
= NFS_FH(old_dir
),
2641 .new_dir
= NFS_FH(new_dir
),
2642 .old_name
= old_name
,
2643 .new_name
= new_name
,
2644 .bitmask
= server
->attr_bitmask
,
2646 struct nfs_renameres res
= {
2649 struct rpc_message msg
= {
2650 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2654 int status
= -ENOMEM
;
2656 res
.old_fattr
= nfs_alloc_fattr();
2657 res
.new_fattr
= nfs_alloc_fattr();
2658 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2661 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2663 update_changeattr(old_dir
, &res
.old_cinfo
);
2664 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2665 update_changeattr(new_dir
, &res
.new_cinfo
);
2666 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2669 nfs_free_fattr(res
.new_fattr
);
2670 nfs_free_fattr(res
.old_fattr
);
2674 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2675 struct inode
*new_dir
, struct qstr
*new_name
)
2677 struct nfs4_exception exception
= { };
2680 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2681 _nfs4_proc_rename(old_dir
, old_name
,
2684 } while (exception
.retry
);
2688 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2690 struct nfs_server
*server
= NFS_SERVER(inode
);
2691 struct nfs4_link_arg arg
= {
2692 .fh
= NFS_FH(inode
),
2693 .dir_fh
= NFS_FH(dir
),
2695 .bitmask
= server
->attr_bitmask
,
2697 struct nfs4_link_res res
= {
2700 struct rpc_message msg
= {
2701 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2705 int status
= -ENOMEM
;
2707 res
.fattr
= nfs_alloc_fattr();
2708 res
.dir_attr
= nfs_alloc_fattr();
2709 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2712 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2714 update_changeattr(dir
, &res
.cinfo
);
2715 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2716 nfs_post_op_update_inode(inode
, res
.fattr
);
2719 nfs_free_fattr(res
.dir_attr
);
2720 nfs_free_fattr(res
.fattr
);
2724 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2726 struct nfs4_exception exception
= { };
2729 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2730 _nfs4_proc_link(inode
, dir
, name
),
2732 } while (exception
.retry
);
2736 struct nfs4_createdata
{
2737 struct rpc_message msg
;
2738 struct nfs4_create_arg arg
;
2739 struct nfs4_create_res res
;
2741 struct nfs_fattr fattr
;
2742 struct nfs_fattr dir_fattr
;
2745 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2746 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2748 struct nfs4_createdata
*data
;
2750 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2752 struct nfs_server
*server
= NFS_SERVER(dir
);
2754 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2755 data
->msg
.rpc_argp
= &data
->arg
;
2756 data
->msg
.rpc_resp
= &data
->res
;
2757 data
->arg
.dir_fh
= NFS_FH(dir
);
2758 data
->arg
.server
= server
;
2759 data
->arg
.name
= name
;
2760 data
->arg
.attrs
= sattr
;
2761 data
->arg
.ftype
= ftype
;
2762 data
->arg
.bitmask
= server
->attr_bitmask
;
2763 data
->res
.server
= server
;
2764 data
->res
.fh
= &data
->fh
;
2765 data
->res
.fattr
= &data
->fattr
;
2766 data
->res
.dir_fattr
= &data
->dir_fattr
;
2767 nfs_fattr_init(data
->res
.fattr
);
2768 nfs_fattr_init(data
->res
.dir_fattr
);
2773 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2775 int status
= nfs4_call_sync(NFS_SERVER(dir
), &data
->msg
,
2776 &data
->arg
, &data
->res
, 1);
2778 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2779 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2780 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2785 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2790 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2791 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2793 struct nfs4_createdata
*data
;
2794 int status
= -ENAMETOOLONG
;
2796 if (len
> NFS4_MAXPATHLEN
)
2800 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2804 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2805 data
->arg
.u
.symlink
.pages
= &page
;
2806 data
->arg
.u
.symlink
.len
= len
;
2808 status
= nfs4_do_create(dir
, dentry
, data
);
2810 nfs4_free_createdata(data
);
2815 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2816 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2818 struct nfs4_exception exception
= { };
2821 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2822 _nfs4_proc_symlink(dir
, dentry
, page
,
2825 } while (exception
.retry
);
2829 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2830 struct iattr
*sattr
)
2832 struct nfs4_createdata
*data
;
2833 int status
= -ENOMEM
;
2835 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2839 status
= nfs4_do_create(dir
, dentry
, data
);
2841 nfs4_free_createdata(data
);
2846 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2847 struct iattr
*sattr
)
2849 struct nfs4_exception exception
= { };
2852 sattr
->ia_mode
&= ~current_umask();
2854 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2855 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2857 } while (exception
.retry
);
2861 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2862 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2864 struct inode
*dir
= dentry
->d_inode
;
2865 struct nfs4_readdir_arg args
= {
2870 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2873 struct nfs4_readdir_res res
;
2874 struct rpc_message msg
= {
2875 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2882 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2883 dentry
->d_parent
->d_name
.name
,
2884 dentry
->d_name
.name
,
2885 (unsigned long long)cookie
);
2886 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2887 res
.pgbase
= args
.pgbase
;
2888 status
= nfs4_call_sync(NFS_SERVER(dir
), &msg
, &args
, &res
, 0);
2890 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2891 status
+= args
.pgbase
;
2894 nfs_invalidate_atime(dir
);
2896 dprintk("%s: returns %d\n", __func__
, status
);
2900 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2901 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2903 struct nfs4_exception exception
= { };
2906 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2907 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2908 pages
, count
, plus
),
2910 } while (exception
.retry
);
2914 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2915 struct iattr
*sattr
, dev_t rdev
)
2917 struct nfs4_createdata
*data
;
2918 int mode
= sattr
->ia_mode
;
2919 int status
= -ENOMEM
;
2921 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2922 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2924 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2929 data
->arg
.ftype
= NF4FIFO
;
2930 else if (S_ISBLK(mode
)) {
2931 data
->arg
.ftype
= NF4BLK
;
2932 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2933 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2935 else if (S_ISCHR(mode
)) {
2936 data
->arg
.ftype
= NF4CHR
;
2937 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2938 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2941 status
= nfs4_do_create(dir
, dentry
, data
);
2943 nfs4_free_createdata(data
);
2948 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2949 struct iattr
*sattr
, dev_t rdev
)
2951 struct nfs4_exception exception
= { };
2954 sattr
->ia_mode
&= ~current_umask();
2956 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2957 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2959 } while (exception
.retry
);
2963 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2964 struct nfs_fsstat
*fsstat
)
2966 struct nfs4_statfs_arg args
= {
2968 .bitmask
= server
->attr_bitmask
,
2970 struct nfs4_statfs_res res
= {
2973 struct rpc_message msg
= {
2974 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2979 nfs_fattr_init(fsstat
->fattr
);
2980 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2983 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2985 struct nfs4_exception exception
= { };
2988 err
= nfs4_handle_exception(server
,
2989 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2991 } while (exception
.retry
);
2995 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2996 struct nfs_fsinfo
*fsinfo
)
2998 struct nfs4_fsinfo_arg args
= {
3000 .bitmask
= server
->attr_bitmask
,
3002 struct nfs4_fsinfo_res res
= {
3005 struct rpc_message msg
= {
3006 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3011 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
3014 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3016 struct nfs4_exception exception
= { };
3020 err
= nfs4_handle_exception(server
,
3021 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3023 } while (exception
.retry
);
3027 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3029 nfs_fattr_init(fsinfo
->fattr
);
3030 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3033 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3034 struct nfs_pathconf
*pathconf
)
3036 struct nfs4_pathconf_arg args
= {
3038 .bitmask
= server
->attr_bitmask
,
3040 struct nfs4_pathconf_res res
= {
3041 .pathconf
= pathconf
,
3043 struct rpc_message msg
= {
3044 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3049 /* None of the pathconf attributes are mandatory to implement */
3050 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3051 memset(pathconf
, 0, sizeof(*pathconf
));
3055 nfs_fattr_init(pathconf
->fattr
);
3056 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
3059 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3060 struct nfs_pathconf
*pathconf
)
3062 struct nfs4_exception exception
= { };
3066 err
= nfs4_handle_exception(server
,
3067 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3069 } while (exception
.retry
);
3073 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3075 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3077 dprintk("--> %s\n", __func__
);
3079 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3082 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3083 nfs_restart_rpc(task
, server
->nfs_client
);
3087 nfs_invalidate_atime(data
->inode
);
3088 if (task
->tk_status
> 0)
3089 renew_lease(server
, data
->timestamp
);
3093 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3095 data
->timestamp
= jiffies
;
3096 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3099 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3101 struct inode
*inode
= data
->inode
;
3103 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3106 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3107 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3110 if (task
->tk_status
>= 0) {
3111 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3112 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3117 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3119 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3121 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3122 data
->res
.server
= server
;
3123 data
->timestamp
= jiffies
;
3125 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3128 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3130 struct inode
*inode
= data
->inode
;
3132 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3135 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3136 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3139 nfs_refresh_inode(inode
, data
->res
.fattr
);
3143 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3145 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3147 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3148 data
->res
.server
= server
;
3149 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3152 struct nfs4_renewdata
{
3153 struct nfs_client
*client
;
3154 unsigned long timestamp
;
3158 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3159 * standalone procedure for queueing an asynchronous RENEW.
3161 static void nfs4_renew_release(void *calldata
)
3163 struct nfs4_renewdata
*data
= calldata
;
3164 struct nfs_client
*clp
= data
->client
;
3166 if (atomic_read(&clp
->cl_count
) > 1)
3167 nfs4_schedule_state_renewal(clp
);
3168 nfs_put_client(clp
);
3172 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3174 struct nfs4_renewdata
*data
= calldata
;
3175 struct nfs_client
*clp
= data
->client
;
3176 unsigned long timestamp
= data
->timestamp
;
3178 if (task
->tk_status
< 0) {
3179 /* Unless we're shutting down, schedule state recovery! */
3180 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3181 nfs4_schedule_lease_recovery(clp
);
3184 do_renew_lease(clp
, timestamp
);
3187 static const struct rpc_call_ops nfs4_renew_ops
= {
3188 .rpc_call_done
= nfs4_renew_done
,
3189 .rpc_release
= nfs4_renew_release
,
3192 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3194 struct rpc_message msg
= {
3195 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3199 struct nfs4_renewdata
*data
;
3201 if (!atomic_inc_not_zero(&clp
->cl_count
))
3203 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
3207 data
->timestamp
= jiffies
;
3208 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3209 &nfs4_renew_ops
, data
);
3212 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3214 struct rpc_message msg
= {
3215 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3219 unsigned long now
= jiffies
;
3222 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3225 do_renew_lease(clp
, now
);
3229 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3231 return (server
->caps
& NFS_CAP_ACLS
)
3232 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3233 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3236 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3237 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3240 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3242 static void buf_to_pages(const void *buf
, size_t buflen
,
3243 struct page
**pages
, unsigned int *pgbase
)
3245 const void *p
= buf
;
3247 *pgbase
= offset_in_page(buf
);
3249 while (p
< buf
+ buflen
) {
3250 *(pages
++) = virt_to_page(p
);
3251 p
+= PAGE_CACHE_SIZE
;
3255 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3256 struct page
**pages
, unsigned int *pgbase
)
3258 struct page
*newpage
, **spages
;
3264 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3265 newpage
= alloc_page(GFP_KERNEL
);
3267 if (newpage
== NULL
)
3269 memcpy(page_address(newpage
), buf
, len
);
3274 } while (buflen
!= 0);
3280 __free_page(spages
[rc
-1]);
3284 struct nfs4_cached_acl
{
3290 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3292 struct nfs_inode
*nfsi
= NFS_I(inode
);
3294 spin_lock(&inode
->i_lock
);
3295 kfree(nfsi
->nfs4_acl
);
3296 nfsi
->nfs4_acl
= acl
;
3297 spin_unlock(&inode
->i_lock
);
3300 static void nfs4_zap_acl_attr(struct inode
*inode
)
3302 nfs4_set_cached_acl(inode
, NULL
);
3305 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3307 struct nfs_inode
*nfsi
= NFS_I(inode
);
3308 struct nfs4_cached_acl
*acl
;
3311 spin_lock(&inode
->i_lock
);
3312 acl
= nfsi
->nfs4_acl
;
3315 if (buf
== NULL
) /* user is just asking for length */
3317 if (acl
->cached
== 0)
3319 ret
= -ERANGE
; /* see getxattr(2) man page */
3320 if (acl
->len
> buflen
)
3322 memcpy(buf
, acl
->data
, acl
->len
);
3326 spin_unlock(&inode
->i_lock
);
3330 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3332 struct nfs4_cached_acl
*acl
;
3334 if (buf
&& acl_len
<= PAGE_SIZE
) {
3335 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3339 memcpy(acl
->data
, buf
, acl_len
);
3341 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3348 nfs4_set_cached_acl(inode
, acl
);
3351 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3353 struct page
*pages
[NFS4ACL_MAXPAGES
];
3354 struct nfs_getaclargs args
= {
3355 .fh
= NFS_FH(inode
),
3359 struct nfs_getaclres res
= {
3363 struct rpc_message msg
= {
3364 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3368 struct page
*localpage
= NULL
;
3371 if (buflen
< PAGE_SIZE
) {
3372 /* As long as we're doing a round trip to the server anyway,
3373 * let's be prepared for a page of acl data. */
3374 localpage
= alloc_page(GFP_KERNEL
);
3375 resp_buf
= page_address(localpage
);
3376 if (localpage
== NULL
)
3378 args
.acl_pages
[0] = localpage
;
3379 args
.acl_pgbase
= 0;
3380 args
.acl_len
= PAGE_SIZE
;
3383 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3385 ret
= nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
3388 if (res
.acl_len
> args
.acl_len
)
3389 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3391 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3394 if (res
.acl_len
> buflen
)
3397 memcpy(buf
, resp_buf
, res
.acl_len
);
3402 __free_page(localpage
);
3406 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3408 struct nfs4_exception exception
= { };
3411 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3414 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3415 } while (exception
.retry
);
3419 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3421 struct nfs_server
*server
= NFS_SERVER(inode
);
3424 if (!nfs4_server_supports_acls(server
))
3426 ret
= nfs_revalidate_inode(server
, inode
);
3429 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3430 nfs_zap_acl_cache(inode
);
3431 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3434 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3437 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3439 struct nfs_server
*server
= NFS_SERVER(inode
);
3440 struct page
*pages
[NFS4ACL_MAXPAGES
];
3441 struct nfs_setaclargs arg
= {
3442 .fh
= NFS_FH(inode
),
3446 struct nfs_setaclres res
;
3447 struct rpc_message msg
= {
3448 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3454 if (!nfs4_server_supports_acls(server
))
3456 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3459 nfs_inode_return_delegation(inode
);
3460 ret
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3463 * Free each page after tx, so the only ref left is
3464 * held by the network stack
3467 put_page(pages
[i
-1]);
3470 * Acl update can result in inode attribute update.
3471 * so mark the attribute cache invalid.
3473 spin_lock(&inode
->i_lock
);
3474 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3475 spin_unlock(&inode
->i_lock
);
3476 nfs_access_zap_cache(inode
);
3477 nfs_zap_acl_cache(inode
);
3481 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3483 struct nfs4_exception exception
= { };
3486 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3487 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3489 } while (exception
.retry
);
3494 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3496 struct nfs_client
*clp
= server
->nfs_client
;
3498 if (task
->tk_status
>= 0)
3500 switch(task
->tk_status
) {
3501 case -NFS4ERR_ADMIN_REVOKED
:
3502 case -NFS4ERR_BAD_STATEID
:
3503 case -NFS4ERR_OPENMODE
:
3506 nfs4_schedule_stateid_recovery(server
, state
);
3507 goto wait_on_recovery
;
3508 case -NFS4ERR_STALE_STATEID
:
3509 case -NFS4ERR_STALE_CLIENTID
:
3510 case -NFS4ERR_EXPIRED
:
3511 nfs4_schedule_lease_recovery(clp
);
3512 goto wait_on_recovery
;
3513 #if defined(CONFIG_NFS_V4_1)
3514 case -NFS4ERR_BADSESSION
:
3515 case -NFS4ERR_BADSLOT
:
3516 case -NFS4ERR_BAD_HIGH_SLOT
:
3517 case -NFS4ERR_DEADSESSION
:
3518 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3519 case -NFS4ERR_SEQ_FALSE_RETRY
:
3520 case -NFS4ERR_SEQ_MISORDERED
:
3521 dprintk("%s ERROR %d, Reset session\n", __func__
,
3523 nfs4_schedule_session_recovery(clp
->cl_session
);
3524 task
->tk_status
= 0;
3526 #endif /* CONFIG_NFS_V4_1 */
3527 case -NFS4ERR_DELAY
:
3528 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3529 case -NFS4ERR_GRACE
:
3531 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3532 task
->tk_status
= 0;
3534 case -NFS4ERR_OLD_STATEID
:
3535 task
->tk_status
= 0;
3538 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3541 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3542 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3543 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3544 task
->tk_status
= 0;
3548 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3549 unsigned short port
, struct rpc_cred
*cred
,
3550 struct nfs4_setclientid_res
*res
)
3552 nfs4_verifier sc_verifier
;
3553 struct nfs4_setclientid setclientid
= {
3554 .sc_verifier
= &sc_verifier
,
3556 .sc_cb_ident
= clp
->cl_cb_ident
,
3558 struct rpc_message msg
= {
3559 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3560 .rpc_argp
= &setclientid
,
3568 p
= (__be32
*)sc_verifier
.data
;
3569 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3570 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3573 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3574 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3576 rpc_peeraddr2str(clp
->cl_rpcclient
,
3578 rpc_peeraddr2str(clp
->cl_rpcclient
,
3580 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3581 clp
->cl_id_uniquifier
);
3582 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3583 sizeof(setclientid
.sc_netid
),
3584 rpc_peeraddr2str(clp
->cl_rpcclient
,
3585 RPC_DISPLAY_NETID
));
3586 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3587 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3588 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3590 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3591 if (status
!= -NFS4ERR_CLID_INUSE
)
3596 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3598 if (++clp
->cl_id_uniquifier
== 0)
3604 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3605 struct nfs4_setclientid_res
*arg
,
3606 struct rpc_cred
*cred
)
3608 struct nfs_fsinfo fsinfo
;
3609 struct rpc_message msg
= {
3610 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3612 .rpc_resp
= &fsinfo
,
3619 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3621 spin_lock(&clp
->cl_lock
);
3622 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3623 clp
->cl_last_renewal
= now
;
3624 spin_unlock(&clp
->cl_lock
);
3629 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3630 struct nfs4_setclientid_res
*arg
,
3631 struct rpc_cred
*cred
)
3636 err
= _nfs4_proc_setclientid_confirm(clp
, arg
, cred
);
3640 case -NFS4ERR_RESOURCE
:
3641 /* The IBM lawyers misread another document! */
3642 case -NFS4ERR_DELAY
:
3643 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3649 struct nfs4_delegreturndata
{
3650 struct nfs4_delegreturnargs args
;
3651 struct nfs4_delegreturnres res
;
3653 nfs4_stateid stateid
;
3654 unsigned long timestamp
;
3655 struct nfs_fattr fattr
;
3659 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3661 struct nfs4_delegreturndata
*data
= calldata
;
3663 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3666 switch (task
->tk_status
) {
3667 case -NFS4ERR_STALE_STATEID
:
3668 case -NFS4ERR_EXPIRED
:
3670 renew_lease(data
->res
.server
, data
->timestamp
);
3673 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3675 nfs_restart_rpc(task
, data
->res
.server
->nfs_client
);
3679 data
->rpc_status
= task
->tk_status
;
3682 static void nfs4_delegreturn_release(void *calldata
)
3687 #if defined(CONFIG_NFS_V4_1)
3688 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3690 struct nfs4_delegreturndata
*d_data
;
3692 d_data
= (struct nfs4_delegreturndata
*)data
;
3694 if (nfs4_setup_sequence(d_data
->res
.server
,
3695 &d_data
->args
.seq_args
,
3696 &d_data
->res
.seq_res
, 1, task
))
3698 rpc_call_start(task
);
3700 #endif /* CONFIG_NFS_V4_1 */
3702 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3703 #if defined(CONFIG_NFS_V4_1)
3704 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3705 #endif /* CONFIG_NFS_V4_1 */
3706 .rpc_call_done
= nfs4_delegreturn_done
,
3707 .rpc_release
= nfs4_delegreturn_release
,
3710 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3712 struct nfs4_delegreturndata
*data
;
3713 struct nfs_server
*server
= NFS_SERVER(inode
);
3714 struct rpc_task
*task
;
3715 struct rpc_message msg
= {
3716 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3719 struct rpc_task_setup task_setup_data
= {
3720 .rpc_client
= server
->client
,
3721 .rpc_message
= &msg
,
3722 .callback_ops
= &nfs4_delegreturn_ops
,
3723 .flags
= RPC_TASK_ASYNC
,
3727 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3730 data
->args
.fhandle
= &data
->fh
;
3731 data
->args
.stateid
= &data
->stateid
;
3732 data
->args
.bitmask
= server
->attr_bitmask
;
3733 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3734 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3735 data
->res
.fattr
= &data
->fattr
;
3736 data
->res
.server
= server
;
3737 nfs_fattr_init(data
->res
.fattr
);
3738 data
->timestamp
= jiffies
;
3739 data
->rpc_status
= 0;
3741 task_setup_data
.callback_data
= data
;
3742 msg
.rpc_argp
= &data
->args
;
3743 msg
.rpc_resp
= &data
->res
;
3744 task
= rpc_run_task(&task_setup_data
);
3746 return PTR_ERR(task
);
3749 status
= nfs4_wait_for_completion_rpc_task(task
);
3752 status
= data
->rpc_status
;
3755 nfs_refresh_inode(inode
, &data
->fattr
);
3761 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3763 struct nfs_server
*server
= NFS_SERVER(inode
);
3764 struct nfs4_exception exception
= { };
3767 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3769 case -NFS4ERR_STALE_STATEID
:
3770 case -NFS4ERR_EXPIRED
:
3774 err
= nfs4_handle_exception(server
, err
, &exception
);
3775 } while (exception
.retry
);
3779 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3780 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3783 * sleep, with exponential backoff, and retry the LOCK operation.
3785 static unsigned long
3786 nfs4_set_lock_task_retry(unsigned long timeout
)
3788 schedule_timeout_killable(timeout
);
3790 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3791 return NFS4_LOCK_MAXTIMEOUT
;
3795 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3797 struct inode
*inode
= state
->inode
;
3798 struct nfs_server
*server
= NFS_SERVER(inode
);
3799 struct nfs_client
*clp
= server
->nfs_client
;
3800 struct nfs_lockt_args arg
= {
3801 .fh
= NFS_FH(inode
),
3804 struct nfs_lockt_res res
= {
3807 struct rpc_message msg
= {
3808 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3811 .rpc_cred
= state
->owner
->so_cred
,
3813 struct nfs4_lock_state
*lsp
;
3816 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3817 status
= nfs4_set_lock_state(state
, request
);
3820 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3821 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3822 arg
.lock_owner
.s_dev
= server
->s_dev
;
3823 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3826 request
->fl_type
= F_UNLCK
;
3828 case -NFS4ERR_DENIED
:
3831 request
->fl_ops
->fl_release_private(request
);
3836 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3838 struct nfs4_exception exception
= { };
3842 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3843 _nfs4_proc_getlk(state
, cmd
, request
),
3845 } while (exception
.retry
);
3849 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3852 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3854 res
= posix_lock_file_wait(file
, fl
);
3857 res
= flock_lock_file_wait(file
, fl
);
3865 struct nfs4_unlockdata
{
3866 struct nfs_locku_args arg
;
3867 struct nfs_locku_res res
;
3868 struct nfs4_lock_state
*lsp
;
3869 struct nfs_open_context
*ctx
;
3870 struct file_lock fl
;
3871 const struct nfs_server
*server
;
3872 unsigned long timestamp
;
3875 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3876 struct nfs_open_context
*ctx
,
3877 struct nfs4_lock_state
*lsp
,
3878 struct nfs_seqid
*seqid
)
3880 struct nfs4_unlockdata
*p
;
3881 struct inode
*inode
= lsp
->ls_state
->inode
;
3883 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
3886 p
->arg
.fh
= NFS_FH(inode
);
3888 p
->arg
.seqid
= seqid
;
3889 p
->res
.seqid
= seqid
;
3890 p
->arg
.stateid
= &lsp
->ls_stateid
;
3892 atomic_inc(&lsp
->ls_count
);
3893 /* Ensure we don't close file until we're done freeing locks! */
3894 p
->ctx
= get_nfs_open_context(ctx
);
3895 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3896 p
->server
= NFS_SERVER(inode
);
3900 static void nfs4_locku_release_calldata(void *data
)
3902 struct nfs4_unlockdata
*calldata
= data
;
3903 nfs_free_seqid(calldata
->arg
.seqid
);
3904 nfs4_put_lock_state(calldata
->lsp
);
3905 put_nfs_open_context(calldata
->ctx
);
3909 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3911 struct nfs4_unlockdata
*calldata
= data
;
3913 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
3915 switch (task
->tk_status
) {
3917 memcpy(calldata
->lsp
->ls_stateid
.data
,
3918 calldata
->res
.stateid
.data
,
3919 sizeof(calldata
->lsp
->ls_stateid
.data
));
3920 renew_lease(calldata
->server
, calldata
->timestamp
);
3922 case -NFS4ERR_BAD_STATEID
:
3923 case -NFS4ERR_OLD_STATEID
:
3924 case -NFS4ERR_STALE_STATEID
:
3925 case -NFS4ERR_EXPIRED
:
3928 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
3929 nfs_restart_rpc(task
,
3930 calldata
->server
->nfs_client
);
3934 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3936 struct nfs4_unlockdata
*calldata
= data
;
3938 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3940 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3941 /* Note: exit _without_ running nfs4_locku_done */
3942 task
->tk_action
= NULL
;
3945 calldata
->timestamp
= jiffies
;
3946 if (nfs4_setup_sequence(calldata
->server
,
3947 &calldata
->arg
.seq_args
,
3948 &calldata
->res
.seq_res
, 1, task
))
3950 rpc_call_start(task
);
3953 static const struct rpc_call_ops nfs4_locku_ops
= {
3954 .rpc_call_prepare
= nfs4_locku_prepare
,
3955 .rpc_call_done
= nfs4_locku_done
,
3956 .rpc_release
= nfs4_locku_release_calldata
,
3959 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3960 struct nfs_open_context
*ctx
,
3961 struct nfs4_lock_state
*lsp
,
3962 struct nfs_seqid
*seqid
)
3964 struct nfs4_unlockdata
*data
;
3965 struct rpc_message msg
= {
3966 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3967 .rpc_cred
= ctx
->cred
,
3969 struct rpc_task_setup task_setup_data
= {
3970 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
3971 .rpc_message
= &msg
,
3972 .callback_ops
= &nfs4_locku_ops
,
3973 .workqueue
= nfsiod_workqueue
,
3974 .flags
= RPC_TASK_ASYNC
,
3977 /* Ensure this is an unlock - when canceling a lock, the
3978 * canceled lock is passed in, and it won't be an unlock.
3980 fl
->fl_type
= F_UNLCK
;
3982 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3984 nfs_free_seqid(seqid
);
3985 return ERR_PTR(-ENOMEM
);
3988 msg
.rpc_argp
= &data
->arg
;
3989 msg
.rpc_resp
= &data
->res
;
3990 task_setup_data
.callback_data
= data
;
3991 return rpc_run_task(&task_setup_data
);
3994 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3996 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3997 struct nfs_seqid
*seqid
;
3998 struct nfs4_lock_state
*lsp
;
3999 struct rpc_task
*task
;
4001 unsigned char fl_flags
= request
->fl_flags
;
4003 status
= nfs4_set_lock_state(state
, request
);
4004 /* Unlock _before_ we do the RPC call */
4005 request
->fl_flags
|= FL_EXISTS
;
4006 down_read(&nfsi
->rwsem
);
4007 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4008 up_read(&nfsi
->rwsem
);
4011 up_read(&nfsi
->rwsem
);
4014 /* Is this a delegated lock? */
4015 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4017 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4018 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4022 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4023 status
= PTR_ERR(task
);
4026 status
= nfs4_wait_for_completion_rpc_task(task
);
4029 request
->fl_flags
= fl_flags
;
4033 struct nfs4_lockdata
{
4034 struct nfs_lock_args arg
;
4035 struct nfs_lock_res res
;
4036 struct nfs4_lock_state
*lsp
;
4037 struct nfs_open_context
*ctx
;
4038 struct file_lock fl
;
4039 unsigned long timestamp
;
4042 struct nfs_server
*server
;
4045 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4046 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4049 struct nfs4_lockdata
*p
;
4050 struct inode
*inode
= lsp
->ls_state
->inode
;
4051 struct nfs_server
*server
= NFS_SERVER(inode
);
4053 p
= kzalloc(sizeof(*p
), gfp_mask
);
4057 p
->arg
.fh
= NFS_FH(inode
);
4059 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4060 if (p
->arg
.open_seqid
== NULL
)
4062 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4063 if (p
->arg
.lock_seqid
== NULL
)
4064 goto out_free_seqid
;
4065 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4066 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4067 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4068 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4069 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4072 atomic_inc(&lsp
->ls_count
);
4073 p
->ctx
= get_nfs_open_context(ctx
);
4074 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4077 nfs_free_seqid(p
->arg
.open_seqid
);
4083 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4085 struct nfs4_lockdata
*data
= calldata
;
4086 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4088 dprintk("%s: begin!\n", __func__
);
4089 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4091 /* Do we need to do an open_to_lock_owner? */
4092 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4093 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4095 data
->arg
.open_stateid
= &state
->stateid
;
4096 data
->arg
.new_lock_owner
= 1;
4097 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4099 data
->arg
.new_lock_owner
= 0;
4100 data
->timestamp
= jiffies
;
4101 if (nfs4_setup_sequence(data
->server
,
4102 &data
->arg
.seq_args
,
4103 &data
->res
.seq_res
, 1, task
))
4105 rpc_call_start(task
);
4106 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4109 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4111 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4112 nfs4_lock_prepare(task
, calldata
);
4115 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4117 struct nfs4_lockdata
*data
= calldata
;
4119 dprintk("%s: begin!\n", __func__
);
4121 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4124 data
->rpc_status
= task
->tk_status
;
4125 if (data
->arg
.new_lock_owner
!= 0) {
4126 if (data
->rpc_status
== 0)
4127 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4131 if (data
->rpc_status
== 0) {
4132 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4133 sizeof(data
->lsp
->ls_stateid
.data
));
4134 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4135 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
4138 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4141 static void nfs4_lock_release(void *calldata
)
4143 struct nfs4_lockdata
*data
= calldata
;
4145 dprintk("%s: begin!\n", __func__
);
4146 nfs_free_seqid(data
->arg
.open_seqid
);
4147 if (data
->cancelled
!= 0) {
4148 struct rpc_task
*task
;
4149 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4150 data
->arg
.lock_seqid
);
4152 rpc_put_task_async(task
);
4153 dprintk("%s: cancelling lock!\n", __func__
);
4155 nfs_free_seqid(data
->arg
.lock_seqid
);
4156 nfs4_put_lock_state(data
->lsp
);
4157 put_nfs_open_context(data
->ctx
);
4159 dprintk("%s: done!\n", __func__
);
4162 static const struct rpc_call_ops nfs4_lock_ops
= {
4163 .rpc_call_prepare
= nfs4_lock_prepare
,
4164 .rpc_call_done
= nfs4_lock_done
,
4165 .rpc_release
= nfs4_lock_release
,
4168 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4169 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4170 .rpc_call_done
= nfs4_lock_done
,
4171 .rpc_release
= nfs4_lock_release
,
4174 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4176 struct nfs_client
*clp
= server
->nfs_client
;
4177 struct nfs4_state
*state
= lsp
->ls_state
;
4180 case -NFS4ERR_ADMIN_REVOKED
:
4181 case -NFS4ERR_BAD_STATEID
:
4182 case -NFS4ERR_EXPIRED
:
4183 if (new_lock_owner
!= 0 ||
4184 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4185 nfs4_state_mark_reclaim_nograce(clp
, state
);
4186 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4188 case -NFS4ERR_STALE_STATEID
:
4189 if (new_lock_owner
!= 0 ||
4190 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4191 nfs4_state_mark_reclaim_reboot(clp
, state
);
4192 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4196 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4198 struct nfs4_lockdata
*data
;
4199 struct rpc_task
*task
;
4200 struct rpc_message msg
= {
4201 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4202 .rpc_cred
= state
->owner
->so_cred
,
4204 struct rpc_task_setup task_setup_data
= {
4205 .rpc_client
= NFS_CLIENT(state
->inode
),
4206 .rpc_message
= &msg
,
4207 .callback_ops
= &nfs4_lock_ops
,
4208 .workqueue
= nfsiod_workqueue
,
4209 .flags
= RPC_TASK_ASYNC
,
4213 dprintk("%s: begin!\n", __func__
);
4214 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4215 fl
->fl_u
.nfs4_fl
.owner
,
4216 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4220 data
->arg
.block
= 1;
4221 if (recovery_type
> NFS_LOCK_NEW
) {
4222 if (recovery_type
== NFS_LOCK_RECLAIM
)
4223 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4224 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4226 msg
.rpc_argp
= &data
->arg
;
4227 msg
.rpc_resp
= &data
->res
;
4228 task_setup_data
.callback_data
= data
;
4229 task
= rpc_run_task(&task_setup_data
);
4231 return PTR_ERR(task
);
4232 ret
= nfs4_wait_for_completion_rpc_task(task
);
4234 ret
= data
->rpc_status
;
4236 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4237 data
->arg
.new_lock_owner
, ret
);
4239 data
->cancelled
= 1;
4241 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4245 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4247 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4248 struct nfs4_exception exception
= { };
4252 /* Cache the lock if possible... */
4253 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4255 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4256 if (err
!= -NFS4ERR_DELAY
)
4258 nfs4_handle_exception(server
, err
, &exception
);
4259 } while (exception
.retry
);
4263 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4265 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4266 struct nfs4_exception exception
= { };
4269 err
= nfs4_set_lock_state(state
, request
);
4273 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4275 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4279 case -NFS4ERR_GRACE
:
4280 case -NFS4ERR_DELAY
:
4281 nfs4_handle_exception(server
, err
, &exception
);
4284 } while (exception
.retry
);
4289 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4291 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4292 unsigned char fl_flags
= request
->fl_flags
;
4293 int status
= -ENOLCK
;
4295 if ((fl_flags
& FL_POSIX
) &&
4296 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4298 /* Is this a delegated open? */
4299 status
= nfs4_set_lock_state(state
, request
);
4302 request
->fl_flags
|= FL_ACCESS
;
4303 status
= do_vfs_lock(request
->fl_file
, request
);
4306 down_read(&nfsi
->rwsem
);
4307 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4308 /* Yes: cache locks! */
4309 /* ...but avoid races with delegation recall... */
4310 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4311 status
= do_vfs_lock(request
->fl_file
, request
);
4314 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4317 /* Note: we always want to sleep here! */
4318 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4319 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4320 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4322 up_read(&nfsi
->rwsem
);
4324 request
->fl_flags
= fl_flags
;
4328 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4330 struct nfs4_exception exception
= { };
4334 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4335 if (err
== -NFS4ERR_DENIED
)
4337 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4339 } while (exception
.retry
);
4344 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4346 struct nfs_open_context
*ctx
;
4347 struct nfs4_state
*state
;
4348 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4351 /* verify open state */
4352 ctx
= nfs_file_open_context(filp
);
4355 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4358 if (IS_GETLK(cmd
)) {
4360 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4364 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4367 if (request
->fl_type
== F_UNLCK
) {
4369 return nfs4_proc_unlck(state
, cmd
, request
);
4376 status
= nfs4_proc_setlk(state
, cmd
, request
);
4377 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4379 timeout
= nfs4_set_lock_task_retry(timeout
);
4380 status
= -ERESTARTSYS
;
4383 } while(status
< 0);
4387 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4389 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4390 struct nfs4_exception exception
= { };
4393 err
= nfs4_set_lock_state(state
, fl
);
4397 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4400 printk(KERN_ERR
"%s: unhandled error %d.\n",
4405 case -NFS4ERR_EXPIRED
:
4406 case -NFS4ERR_STALE_CLIENTID
:
4407 case -NFS4ERR_STALE_STATEID
:
4408 nfs4_schedule_lease_recovery(server
->nfs_client
);
4410 case -NFS4ERR_BADSESSION
:
4411 case -NFS4ERR_BADSLOT
:
4412 case -NFS4ERR_BAD_HIGH_SLOT
:
4413 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4414 case -NFS4ERR_DEADSESSION
:
4415 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4419 * The show must go on: exit, but mark the
4420 * stateid as needing recovery.
4422 case -NFS4ERR_ADMIN_REVOKED
:
4423 case -NFS4ERR_BAD_STATEID
:
4424 case -NFS4ERR_OPENMODE
:
4425 nfs4_schedule_stateid_recovery(server
, state
);
4430 * User RPCSEC_GSS context has expired.
4431 * We cannot recover this stateid now, so
4432 * skip it and allow recovery thread to
4438 case -NFS4ERR_DENIED
:
4439 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4442 case -NFS4ERR_DELAY
:
4445 err
= nfs4_handle_exception(server
, err
, &exception
);
4446 } while (exception
.retry
);
4451 static void nfs4_release_lockowner_release(void *calldata
)
4456 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4457 .rpc_release
= nfs4_release_lockowner_release
,
4460 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4462 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4463 struct nfs_release_lockowner_args
*args
;
4464 struct rpc_message msg
= {
4465 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4468 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4470 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4473 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4474 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4475 args
->lock_owner
.s_dev
= server
->s_dev
;
4476 msg
.rpc_argp
= args
;
4477 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4480 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4482 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4483 const void *buf
, size_t buflen
,
4484 int flags
, int type
)
4486 if (strcmp(key
, "") != 0)
4489 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4492 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4493 void *buf
, size_t buflen
, int type
)
4495 if (strcmp(key
, "") != 0)
4498 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4501 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4502 size_t list_len
, const char *name
,
4503 size_t name_len
, int type
)
4505 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4507 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4510 if (list
&& len
<= list_len
)
4511 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4515 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4517 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4518 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4519 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4522 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4523 NFS_ATTR_FATTR_NLINK
;
4524 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4528 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4529 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4531 struct nfs_server
*server
= NFS_SERVER(dir
);
4533 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4534 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4536 struct nfs4_fs_locations_arg args
= {
4537 .dir_fh
= NFS_FH(dir
),
4542 struct nfs4_fs_locations_res res
= {
4543 .fs_locations
= fs_locations
,
4545 struct rpc_message msg
= {
4546 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4552 dprintk("%s: start\n", __func__
);
4553 nfs_fattr_init(&fs_locations
->fattr
);
4554 fs_locations
->server
= server
;
4555 fs_locations
->nlocations
= 0;
4556 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
4557 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4558 dprintk("%s: returned status = %d\n", __func__
, status
);
4562 #ifdef CONFIG_NFS_V4_1
4564 * Check the exchange flags returned by the server for invalid flags, having
4565 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4568 static int nfs4_check_cl_exchange_flags(u32 flags
)
4570 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4572 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4573 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4575 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4579 return -NFS4ERR_INVAL
;
4583 * nfs4_proc_exchange_id()
4585 * Since the clientid has expired, all compounds using sessions
4586 * associated with the stale clientid will be returning
4587 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4588 * be in some phase of session reset.
4590 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4592 nfs4_verifier verifier
;
4593 struct nfs41_exchange_id_args args
= {
4595 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4597 struct nfs41_exchange_id_res res
= {
4601 struct rpc_message msg
= {
4602 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4609 dprintk("--> %s\n", __func__
);
4610 BUG_ON(clp
== NULL
);
4612 p
= (u32
*)verifier
.data
;
4613 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4614 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4615 args
.verifier
= &verifier
;
4617 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4620 init_utsname()->nodename
,
4621 init_utsname()->domainname
,
4622 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4624 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4626 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4627 dprintk("<-- %s status= %d\n", __func__
, status
);
4631 struct nfs4_get_lease_time_data
{
4632 struct nfs4_get_lease_time_args
*args
;
4633 struct nfs4_get_lease_time_res
*res
;
4634 struct nfs_client
*clp
;
4637 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4641 struct nfs4_get_lease_time_data
*data
=
4642 (struct nfs4_get_lease_time_data
*)calldata
;
4644 dprintk("--> %s\n", __func__
);
4645 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4646 /* just setup sequence, do not trigger session recovery
4647 since we're invoked within one */
4648 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4649 &data
->args
->la_seq_args
,
4650 &data
->res
->lr_seq_res
, 0, task
);
4652 BUG_ON(ret
== -EAGAIN
);
4653 rpc_call_start(task
);
4654 dprintk("<-- %s\n", __func__
);
4658 * Called from nfs4_state_manager thread for session setup, so don't recover
4659 * from sequence operation or clientid errors.
4661 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4663 struct nfs4_get_lease_time_data
*data
=
4664 (struct nfs4_get_lease_time_data
*)calldata
;
4666 dprintk("--> %s\n", __func__
);
4667 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4669 switch (task
->tk_status
) {
4670 case -NFS4ERR_DELAY
:
4671 case -NFS4ERR_GRACE
:
4672 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4673 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4674 task
->tk_status
= 0;
4675 nfs_restart_rpc(task
, data
->clp
);
4678 dprintk("<-- %s\n", __func__
);
4681 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4682 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4683 .rpc_call_done
= nfs4_get_lease_time_done
,
4686 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4688 struct rpc_task
*task
;
4689 struct nfs4_get_lease_time_args args
;
4690 struct nfs4_get_lease_time_res res
= {
4691 .lr_fsinfo
= fsinfo
,
4693 struct nfs4_get_lease_time_data data
= {
4698 struct rpc_message msg
= {
4699 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4703 struct rpc_task_setup task_setup
= {
4704 .rpc_client
= clp
->cl_rpcclient
,
4705 .rpc_message
= &msg
,
4706 .callback_ops
= &nfs4_get_lease_time_ops
,
4707 .callback_data
= &data
4711 dprintk("--> %s\n", __func__
);
4712 task
= rpc_run_task(&task_setup
);
4715 status
= PTR_ERR(task
);
4717 status
= task
->tk_status
;
4720 dprintk("<-- %s return %d\n", __func__
, status
);
4726 * Reset a slot table
4728 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
4731 struct nfs4_slot
*new = NULL
;
4735 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
4736 max_reqs
, tbl
->max_slots
);
4738 /* Does the newly negotiated max_reqs match the existing slot table? */
4739 if (max_reqs
!= tbl
->max_slots
) {
4741 new = kmalloc(max_reqs
* sizeof(struct nfs4_slot
),
4748 spin_lock(&tbl
->slot_tbl_lock
);
4751 tbl
->max_slots
= max_reqs
;
4753 for (i
= 0; i
< tbl
->max_slots
; ++i
)
4754 tbl
->slots
[i
].seq_nr
= ivalue
;
4755 spin_unlock(&tbl
->slot_tbl_lock
);
4756 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4757 tbl
, tbl
->slots
, tbl
->max_slots
);
4759 dprintk("<-- %s: return %d\n", __func__
, ret
);
4764 * Reset the forechannel and backchannel slot tables
4766 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4770 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4771 session
->fc_attrs
.max_reqs
, 1);
4775 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4776 session
->bc_attrs
.max_reqs
, 0);
4780 /* Destroy the slot table */
4781 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4783 if (session
->fc_slot_table
.slots
!= NULL
) {
4784 kfree(session
->fc_slot_table
.slots
);
4785 session
->fc_slot_table
.slots
= NULL
;
4787 if (session
->bc_slot_table
.slots
!= NULL
) {
4788 kfree(session
->bc_slot_table
.slots
);
4789 session
->bc_slot_table
.slots
= NULL
;
4795 * Initialize slot table
4797 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4798 int max_slots
, int ivalue
)
4800 struct nfs4_slot
*slot
;
4803 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4805 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4807 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_NOFS
);
4812 spin_lock(&tbl
->slot_tbl_lock
);
4813 tbl
->max_slots
= max_slots
;
4815 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4816 spin_unlock(&tbl
->slot_tbl_lock
);
4817 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4818 tbl
, tbl
->slots
, tbl
->max_slots
);
4820 dprintk("<-- %s: return %d\n", __func__
, ret
);
4825 * Initialize the forechannel and backchannel tables
4827 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4829 struct nfs4_slot_table
*tbl
;
4832 tbl
= &session
->fc_slot_table
;
4833 if (tbl
->slots
== NULL
) {
4834 status
= nfs4_init_slot_table(tbl
,
4835 session
->fc_attrs
.max_reqs
, 1);
4840 tbl
= &session
->bc_slot_table
;
4841 if (tbl
->slots
== NULL
) {
4842 status
= nfs4_init_slot_table(tbl
,
4843 session
->bc_attrs
.max_reqs
, 0);
4845 nfs4_destroy_slot_tables(session
);
4851 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
4853 struct nfs4_session
*session
;
4854 struct nfs4_slot_table
*tbl
;
4856 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
4860 tbl
= &session
->fc_slot_table
;
4861 tbl
->highest_used_slotid
= -1;
4862 spin_lock_init(&tbl
->slot_tbl_lock
);
4863 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
4864 init_completion(&tbl
->complete
);
4866 tbl
= &session
->bc_slot_table
;
4867 tbl
->highest_used_slotid
= -1;
4868 spin_lock_init(&tbl
->slot_tbl_lock
);
4869 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
4870 init_completion(&tbl
->complete
);
4872 session
->session_state
= 1<<NFS4_SESSION_INITING
;
4878 void nfs4_destroy_session(struct nfs4_session
*session
)
4880 nfs4_proc_destroy_session(session
);
4881 dprintk("%s Destroy backchannel for xprt %p\n",
4882 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
4883 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
4884 NFS41_BC_MIN_CALLBACKS
);
4885 nfs4_destroy_slot_tables(session
);
4890 * Initialize the values to be used by the client in CREATE_SESSION
4891 * If nfs4_init_session set the fore channel request and response sizes,
4894 * Set the back channel max_resp_sz_cached to zero to force the client to
4895 * always set csa_cachethis to FALSE because the current implementation
4896 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4898 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
4900 struct nfs4_session
*session
= args
->client
->cl_session
;
4901 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
4902 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
4905 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
4907 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
4908 /* Fore channel attributes */
4909 args
->fc_attrs
.headerpadsz
= 0;
4910 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
4911 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
4912 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
4913 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
4915 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4916 "max_ops=%u max_reqs=%u\n",
4918 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
4919 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
4921 /* Back channel attributes */
4922 args
->bc_attrs
.headerpadsz
= 0;
4923 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
4924 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
4925 args
->bc_attrs
.max_resp_sz_cached
= 0;
4926 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
4927 args
->bc_attrs
.max_reqs
= 1;
4929 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4930 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4932 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
4933 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
4934 args
->bc_attrs
.max_reqs
);
4937 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
4939 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
4940 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
4942 if (rcvd
->headerpadsz
> sent
->headerpadsz
)
4944 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
4947 * Our requested max_ops is the minimum we need; we're not
4948 * prepared to break up compounds into smaller pieces than that.
4949 * So, no point even trying to continue if the server won't
4952 if (rcvd
->max_ops
< sent
->max_ops
)
4954 if (rcvd
->max_reqs
== 0)
4959 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
4961 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
4962 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
4964 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
4966 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
4968 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
4970 /* These would render the backchannel useless: */
4971 if (rcvd
->max_ops
== 0)
4973 if (rcvd
->max_reqs
== 0)
4978 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
4979 struct nfs4_session
*session
)
4983 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
4986 return nfs4_verify_back_channel_attrs(args
, session
);
4989 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
4991 struct nfs4_session
*session
= clp
->cl_session
;
4992 struct nfs41_create_session_args args
= {
4994 .cb_program
= NFS4_CALLBACK
,
4996 struct nfs41_create_session_res res
= {
4999 struct rpc_message msg
= {
5000 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5006 nfs4_init_channel_attrs(&args
);
5007 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5009 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5012 /* Verify the session's negotiated channel_attrs values */
5013 status
= nfs4_verify_channel_attrs(&args
, session
);
5015 /* Increment the clientid slot sequence id */
5023 * Issues a CREATE_SESSION operation to the server.
5024 * It is the responsibility of the caller to verify the session is
5025 * expired before calling this routine.
5027 int nfs4_proc_create_session(struct nfs_client
*clp
)
5031 struct nfs4_session
*session
= clp
->cl_session
;
5035 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5038 status
= _nfs4_proc_create_session(clp
);
5039 if (status
== -NFS4ERR_DELAY
) {
5040 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
5044 } while (status
== -NFS4ERR_DELAY
);
5049 /* Init and reset the fore channel */
5050 status
= nfs4_init_slot_tables(session
);
5051 dprintk("slot table initialization returned %d\n", status
);
5054 status
= nfs4_reset_slot_tables(session
);
5055 dprintk("slot table reset returned %d\n", status
);
5059 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5060 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5061 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5063 dprintk("<-- %s\n", __func__
);
5068 * Issue the over-the-wire RPC DESTROY_SESSION.
5069 * The caller must serialize access to this routine.
5071 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5074 struct rpc_message msg
;
5076 dprintk("--> nfs4_proc_destroy_session\n");
5078 /* session is still being setup */
5079 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5082 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5083 msg
.rpc_argp
= session
;
5084 msg
.rpc_resp
= NULL
;
5085 msg
.rpc_cred
= NULL
;
5086 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5090 "Got error %d from the server on DESTROY_SESSION. "
5091 "Session has been destroyed regardless...\n", status
);
5093 dprintk("<-- nfs4_proc_destroy_session\n");
5097 int nfs4_init_session(struct nfs_server
*server
)
5099 struct nfs_client
*clp
= server
->nfs_client
;
5100 struct nfs4_session
*session
;
5101 unsigned int rsize
, wsize
;
5104 if (!nfs4_has_session(clp
))
5107 session
= clp
->cl_session
;
5108 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5111 rsize
= server
->rsize
;
5113 rsize
= NFS_MAX_FILE_IO_SIZE
;
5114 wsize
= server
->wsize
;
5116 wsize
= NFS_MAX_FILE_IO_SIZE
;
5118 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5119 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5121 ret
= nfs4_recover_expired_lease(server
);
5123 ret
= nfs4_check_client_ready(clp
);
5128 * Renew the cl_session lease.
5130 struct nfs4_sequence_data
{
5131 struct nfs_client
*clp
;
5132 struct nfs4_sequence_args args
;
5133 struct nfs4_sequence_res res
;
5136 static void nfs41_sequence_release(void *data
)
5138 struct nfs4_sequence_data
*calldata
= data
;
5139 struct nfs_client
*clp
= calldata
->clp
;
5141 if (atomic_read(&clp
->cl_count
) > 1)
5142 nfs4_schedule_state_renewal(clp
);
5143 nfs_put_client(clp
);
5147 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5149 switch(task
->tk_status
) {
5150 case -NFS4ERR_DELAY
:
5151 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5154 nfs4_schedule_lease_recovery(clp
);
5159 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5161 struct nfs4_sequence_data
*calldata
= data
;
5162 struct nfs_client
*clp
= calldata
->clp
;
5164 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5167 if (task
->tk_status
< 0) {
5168 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5169 if (atomic_read(&clp
->cl_count
) == 1)
5172 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5173 rpc_restart_call_prepare(task
);
5177 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5179 dprintk("<-- %s\n", __func__
);
5182 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5184 struct nfs4_sequence_data
*calldata
= data
;
5185 struct nfs_client
*clp
= calldata
->clp
;
5186 struct nfs4_sequence_args
*args
;
5187 struct nfs4_sequence_res
*res
;
5189 args
= task
->tk_msg
.rpc_argp
;
5190 res
= task
->tk_msg
.rpc_resp
;
5192 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5194 rpc_call_start(task
);
5197 static const struct rpc_call_ops nfs41_sequence_ops
= {
5198 .rpc_call_done
= nfs41_sequence_call_done
,
5199 .rpc_call_prepare
= nfs41_sequence_prepare
,
5200 .rpc_release
= nfs41_sequence_release
,
5203 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5205 struct nfs4_sequence_data
*calldata
;
5206 struct rpc_message msg
= {
5207 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5210 struct rpc_task_setup task_setup_data
= {
5211 .rpc_client
= clp
->cl_rpcclient
,
5212 .rpc_message
= &msg
,
5213 .callback_ops
= &nfs41_sequence_ops
,
5214 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5217 if (!atomic_inc_not_zero(&clp
->cl_count
))
5218 return ERR_PTR(-EIO
);
5219 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5220 if (calldata
== NULL
) {
5221 nfs_put_client(clp
);
5222 return ERR_PTR(-ENOMEM
);
5224 msg
.rpc_argp
= &calldata
->args
;
5225 msg
.rpc_resp
= &calldata
->res
;
5226 calldata
->clp
= clp
;
5227 task_setup_data
.callback_data
= calldata
;
5229 return rpc_run_task(&task_setup_data
);
5232 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5234 struct rpc_task
*task
;
5237 task
= _nfs41_proc_sequence(clp
, cred
);
5239 ret
= PTR_ERR(task
);
5241 rpc_put_task_async(task
);
5242 dprintk("<-- %s status=%d\n", __func__
, ret
);
5246 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5248 struct rpc_task
*task
;
5251 task
= _nfs41_proc_sequence(clp
, cred
);
5253 ret
= PTR_ERR(task
);
5256 ret
= rpc_wait_for_completion_task(task
);
5258 ret
= task
->tk_status
;
5261 dprintk("<-- %s status=%d\n", __func__
, ret
);
5265 struct nfs4_reclaim_complete_data
{
5266 struct nfs_client
*clp
;
5267 struct nfs41_reclaim_complete_args arg
;
5268 struct nfs41_reclaim_complete_res res
;
5271 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5273 struct nfs4_reclaim_complete_data
*calldata
= data
;
5275 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5276 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5277 &calldata
->arg
.seq_args
,
5278 &calldata
->res
.seq_res
, 0, task
))
5281 rpc_call_start(task
);
5284 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5286 switch(task
->tk_status
) {
5288 case -NFS4ERR_COMPLETE_ALREADY
:
5289 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5291 case -NFS4ERR_DELAY
:
5292 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5295 nfs4_schedule_lease_recovery(clp
);
5300 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5302 struct nfs4_reclaim_complete_data
*calldata
= data
;
5303 struct nfs_client
*clp
= calldata
->clp
;
5304 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5306 dprintk("--> %s\n", __func__
);
5307 if (!nfs41_sequence_done(task
, res
))
5310 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5311 rpc_restart_call_prepare(task
);
5314 dprintk("<-- %s\n", __func__
);
5317 static void nfs4_free_reclaim_complete_data(void *data
)
5319 struct nfs4_reclaim_complete_data
*calldata
= data
;
5324 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5325 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5326 .rpc_call_done
= nfs4_reclaim_complete_done
,
5327 .rpc_release
= nfs4_free_reclaim_complete_data
,
5331 * Issue a global reclaim complete.
5333 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5335 struct nfs4_reclaim_complete_data
*calldata
;
5336 struct rpc_task
*task
;
5337 struct rpc_message msg
= {
5338 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5340 struct rpc_task_setup task_setup_data
= {
5341 .rpc_client
= clp
->cl_rpcclient
,
5342 .rpc_message
= &msg
,
5343 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5344 .flags
= RPC_TASK_ASYNC
,
5346 int status
= -ENOMEM
;
5348 dprintk("--> %s\n", __func__
);
5349 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5350 if (calldata
== NULL
)
5352 calldata
->clp
= clp
;
5353 calldata
->arg
.one_fs
= 0;
5355 msg
.rpc_argp
= &calldata
->arg
;
5356 msg
.rpc_resp
= &calldata
->res
;
5357 task_setup_data
.callback_data
= calldata
;
5358 task
= rpc_run_task(&task_setup_data
);
5360 status
= PTR_ERR(task
);
5363 status
= nfs4_wait_for_completion_rpc_task(task
);
5365 status
= task
->tk_status
;
5369 dprintk("<-- %s status=%d\n", __func__
, status
);
5374 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5376 struct nfs4_layoutget
*lgp
= calldata
;
5377 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5379 dprintk("--> %s\n", __func__
);
5380 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5381 * right now covering the LAYOUTGET we are about to send.
5382 * However, that is not so catastrophic, and there seems
5383 * to be no way to prevent it completely.
5385 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5386 &lgp
->res
.seq_res
, 0, task
))
5388 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5389 NFS_I(lgp
->args
.inode
)->layout
,
5390 lgp
->args
.ctx
->state
)) {
5391 rpc_exit(task
, NFS4_OK
);
5394 rpc_call_start(task
);
5397 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5399 struct nfs4_layoutget
*lgp
= calldata
;
5400 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5402 dprintk("--> %s\n", __func__
);
5404 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5407 switch (task
->tk_status
) {
5410 case -NFS4ERR_LAYOUTTRYLATER
:
5411 case -NFS4ERR_RECALLCONFLICT
:
5412 task
->tk_status
= -NFS4ERR_DELAY
;
5415 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5416 rpc_restart_call_prepare(task
);
5420 dprintk("<-- %s\n", __func__
);
5423 static void nfs4_layoutget_release(void *calldata
)
5425 struct nfs4_layoutget
*lgp
= calldata
;
5427 dprintk("--> %s\n", __func__
);
5428 if (lgp
->res
.layout
.buf
!= NULL
)
5429 free_page((unsigned long) lgp
->res
.layout
.buf
);
5430 put_nfs_open_context(lgp
->args
.ctx
);
5432 dprintk("<-- %s\n", __func__
);
5435 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5436 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5437 .rpc_call_done
= nfs4_layoutget_done
,
5438 .rpc_release
= nfs4_layoutget_release
,
5441 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5443 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5444 struct rpc_task
*task
;
5445 struct rpc_message msg
= {
5446 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5447 .rpc_argp
= &lgp
->args
,
5448 .rpc_resp
= &lgp
->res
,
5450 struct rpc_task_setup task_setup_data
= {
5451 .rpc_client
= server
->client
,
5452 .rpc_message
= &msg
,
5453 .callback_ops
= &nfs4_layoutget_call_ops
,
5454 .callback_data
= lgp
,
5455 .flags
= RPC_TASK_ASYNC
,
5459 dprintk("--> %s\n", __func__
);
5461 lgp
->res
.layout
.buf
= (void *)__get_free_page(GFP_NOFS
);
5462 if (lgp
->res
.layout
.buf
== NULL
) {
5463 nfs4_layoutget_release(lgp
);
5467 lgp
->res
.seq_res
.sr_slot
= NULL
;
5468 task
= rpc_run_task(&task_setup_data
);
5470 return PTR_ERR(task
);
5471 status
= nfs4_wait_for_completion_rpc_task(task
);
5473 status
= task
->tk_status
;
5475 status
= pnfs_layout_process(lgp
);
5477 dprintk("<-- %s status=%d\n", __func__
, status
);
5482 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5484 struct nfs4_getdeviceinfo_args args
= {
5487 struct nfs4_getdeviceinfo_res res
= {
5490 struct rpc_message msg
= {
5491 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5497 dprintk("--> %s\n", __func__
);
5498 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
5499 dprintk("<-- %s status=%d\n", __func__
, status
);
5504 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5506 struct nfs4_exception exception
= { };
5510 err
= nfs4_handle_exception(server
,
5511 _nfs4_proc_getdeviceinfo(server
, pdev
),
5513 } while (exception
.retry
);
5516 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5518 #endif /* CONFIG_NFS_V4_1 */
5520 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
5521 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5522 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5523 .recover_open
= nfs4_open_reclaim
,
5524 .recover_lock
= nfs4_lock_reclaim
,
5525 .establish_clid
= nfs4_init_clientid
,
5526 .get_clid_cred
= nfs4_get_setclientid_cred
,
5529 #if defined(CONFIG_NFS_V4_1)
5530 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
5531 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5532 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5533 .recover_open
= nfs4_open_reclaim
,
5534 .recover_lock
= nfs4_lock_reclaim
,
5535 .establish_clid
= nfs41_init_clientid
,
5536 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5537 .reclaim_complete
= nfs41_proc_reclaim_complete
,
5539 #endif /* CONFIG_NFS_V4_1 */
5541 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
5542 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5543 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5544 .recover_open
= nfs4_open_expired
,
5545 .recover_lock
= nfs4_lock_expired
,
5546 .establish_clid
= nfs4_init_clientid
,
5547 .get_clid_cred
= nfs4_get_setclientid_cred
,
5550 #if defined(CONFIG_NFS_V4_1)
5551 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
5552 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5553 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5554 .recover_open
= nfs4_open_expired
,
5555 .recover_lock
= nfs4_lock_expired
,
5556 .establish_clid
= nfs41_init_clientid
,
5557 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5559 #endif /* CONFIG_NFS_V4_1 */
5561 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
5562 .sched_state_renewal
= nfs4_proc_async_renew
,
5563 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
5564 .renew_lease
= nfs4_proc_renew
,
5567 #if defined(CONFIG_NFS_V4_1)
5568 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
5569 .sched_state_renewal
= nfs41_proc_async_sequence
,
5570 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
5571 .renew_lease
= nfs4_proc_sequence
,
5575 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
5577 .call_sync
= _nfs4_call_sync
,
5578 .validate_stateid
= nfs4_validate_delegation_stateid
,
5579 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
5580 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
5581 .state_renewal_ops
= &nfs40_state_renewal_ops
,
5584 #if defined(CONFIG_NFS_V4_1)
5585 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
5587 .call_sync
= _nfs4_call_sync_session
,
5588 .validate_stateid
= nfs41_validate_delegation_stateid
,
5589 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
5590 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
5591 .state_renewal_ops
= &nfs41_state_renewal_ops
,
5595 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
5596 [0] = &nfs_v4_0_minor_ops
,
5597 #if defined(CONFIG_NFS_V4_1)
5598 [1] = &nfs_v4_1_minor_ops
,
5602 static const struct inode_operations nfs4_file_inode_operations
= {
5603 .permission
= nfs_permission
,
5604 .getattr
= nfs_getattr
,
5605 .setattr
= nfs_setattr
,
5606 .getxattr
= generic_getxattr
,
5607 .setxattr
= generic_setxattr
,
5608 .listxattr
= generic_listxattr
,
5609 .removexattr
= generic_removexattr
,
5612 const struct nfs_rpc_ops nfs_v4_clientops
= {
5613 .version
= 4, /* protocol version */
5614 .dentry_ops
= &nfs4_dentry_operations
,
5615 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5616 .file_inode_ops
= &nfs4_file_inode_operations
,
5617 .getroot
= nfs4_proc_get_root
,
5618 .getattr
= nfs4_proc_getattr
,
5619 .setattr
= nfs4_proc_setattr
,
5620 .lookupfh
= nfs4_proc_lookupfh
,
5621 .lookup
= nfs4_proc_lookup
,
5622 .access
= nfs4_proc_access
,
5623 .readlink
= nfs4_proc_readlink
,
5624 .create
= nfs4_proc_create
,
5625 .remove
= nfs4_proc_remove
,
5626 .unlink_setup
= nfs4_proc_unlink_setup
,
5627 .unlink_done
= nfs4_proc_unlink_done
,
5628 .rename
= nfs4_proc_rename
,
5629 .rename_setup
= nfs4_proc_rename_setup
,
5630 .rename_done
= nfs4_proc_rename_done
,
5631 .link
= nfs4_proc_link
,
5632 .symlink
= nfs4_proc_symlink
,
5633 .mkdir
= nfs4_proc_mkdir
,
5634 .rmdir
= nfs4_proc_remove
,
5635 .readdir
= nfs4_proc_readdir
,
5636 .mknod
= nfs4_proc_mknod
,
5637 .statfs
= nfs4_proc_statfs
,
5638 .fsinfo
= nfs4_proc_fsinfo
,
5639 .pathconf
= nfs4_proc_pathconf
,
5640 .set_capabilities
= nfs4_server_capabilities
,
5641 .decode_dirent
= nfs4_decode_dirent
,
5642 .read_setup
= nfs4_proc_read_setup
,
5643 .read_done
= nfs4_read_done
,
5644 .write_setup
= nfs4_proc_write_setup
,
5645 .write_done
= nfs4_write_done
,
5646 .commit_setup
= nfs4_proc_commit_setup
,
5647 .commit_done
= nfs4_commit_done
,
5648 .lock
= nfs4_proc_lock
,
5649 .clear_acl_cache
= nfs4_zap_acl_attr
,
5650 .close_context
= nfs4_close_context
,
5651 .open_context
= nfs4_atomic_open
,
5654 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
5655 .prefix
= XATTR_NAME_NFSV4_ACL
,
5656 .list
= nfs4_xattr_list_nfs4_acl
,
5657 .get
= nfs4_xattr_get_nfs4_acl
,
5658 .set
= nfs4_xattr_set_nfs4_acl
,
5661 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
5662 &nfs4_xattr_nfs4_acl_handler
,