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>
56 #include "delegation.h"
62 #define NFSDBG_FACILITY NFSDBG_PROC
64 #define NFS4_POLL_RETRY_MIN (HZ/10)
65 #define NFS4_POLL_RETRY_MAX (15*HZ)
67 #define NFS4_MAX_LOOP_ON_RECOVER (10)
70 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
71 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
72 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
73 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
74 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
75 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
76 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
77 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
78 struct nfs4_state
*state
);
80 /* Prevent leaks of NFSv4 errors into userland */
81 static int nfs4_map_errors(int err
)
86 case -NFS4ERR_RESOURCE
:
88 case -NFS4ERR_BADOWNER
:
89 case -NFS4ERR_BADNAME
:
92 dprintk("%s could not handle NFSv4 error %d\n",
100 * This is our standard bitmap for GETATTR requests.
102 const u32 nfs4_fattr_bitmap
[2] = {
104 | FATTR4_WORD0_CHANGE
107 | FATTR4_WORD0_FILEID
,
109 | FATTR4_WORD1_NUMLINKS
111 | FATTR4_WORD1_OWNER_GROUP
112 | FATTR4_WORD1_RAWDEV
113 | FATTR4_WORD1_SPACE_USED
114 | FATTR4_WORD1_TIME_ACCESS
115 | FATTR4_WORD1_TIME_METADATA
116 | FATTR4_WORD1_TIME_MODIFY
119 const u32 nfs4_statfs_bitmap
[2] = {
120 FATTR4_WORD0_FILES_AVAIL
121 | FATTR4_WORD0_FILES_FREE
122 | FATTR4_WORD0_FILES_TOTAL
,
123 FATTR4_WORD1_SPACE_AVAIL
124 | FATTR4_WORD1_SPACE_FREE
125 | FATTR4_WORD1_SPACE_TOTAL
128 const u32 nfs4_pathconf_bitmap
[2] = {
130 | FATTR4_WORD0_MAXNAME
,
134 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
135 | FATTR4_WORD0_MAXREAD
136 | FATTR4_WORD0_MAXWRITE
137 | FATTR4_WORD0_LEASE_TIME
,
138 FATTR4_WORD1_TIME_DELTA
139 | FATTR4_WORD1_FS_LAYOUT_TYPES
142 const u32 nfs4_fs_locations_bitmap
[2] = {
144 | FATTR4_WORD0_CHANGE
147 | FATTR4_WORD0_FILEID
148 | FATTR4_WORD0_FS_LOCATIONS
,
150 | FATTR4_WORD1_NUMLINKS
152 | FATTR4_WORD1_OWNER_GROUP
153 | FATTR4_WORD1_RAWDEV
154 | FATTR4_WORD1_SPACE_USED
155 | FATTR4_WORD1_TIME_ACCESS
156 | FATTR4_WORD1_TIME_METADATA
157 | FATTR4_WORD1_TIME_MODIFY
158 | FATTR4_WORD1_MOUNTED_ON_FILEID
161 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
162 struct nfs4_readdir_arg
*readdir
)
166 BUG_ON(readdir
->count
< 80);
168 readdir
->cookie
= cookie
;
169 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
174 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
179 * NFSv4 servers do not return entries for '.' and '..'
180 * Therefore, we fake these entries here. We let '.'
181 * have cookie 0 and '..' have cookie 1. Note that
182 * when talking to the server, we always send cookie 0
185 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
188 *p
++ = xdr_one
; /* next */
189 *p
++ = xdr_zero
; /* cookie, first word */
190 *p
++ = xdr_one
; /* cookie, second word */
191 *p
++ = xdr_one
; /* entry len */
192 memcpy(p
, ".\0\0\0", 4); /* entry */
194 *p
++ = xdr_one
; /* bitmap length */
195 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
196 *p
++ = htonl(8); /* attribute buffer length */
197 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
200 *p
++ = xdr_one
; /* next */
201 *p
++ = xdr_zero
; /* cookie, first word */
202 *p
++ = xdr_two
; /* cookie, second word */
203 *p
++ = xdr_two
; /* entry len */
204 memcpy(p
, "..\0\0", 4); /* entry */
206 *p
++ = xdr_one
; /* bitmap length */
207 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
208 *p
++ = htonl(8); /* attribute buffer length */
209 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
211 readdir
->pgbase
= (char *)p
- (char *)start
;
212 readdir
->count
-= readdir
->pgbase
;
213 kunmap_atomic(start
, KM_USER0
);
216 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
222 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
223 nfs_wait_bit_killable
, TASK_KILLABLE
);
227 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
234 *timeout
= NFS4_POLL_RETRY_MIN
;
235 if (*timeout
> NFS4_POLL_RETRY_MAX
)
236 *timeout
= NFS4_POLL_RETRY_MAX
;
237 schedule_timeout_killable(*timeout
);
238 if (fatal_signal_pending(current
))
244 /* This is the error handling routine for processes that are allowed
247 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
249 struct nfs_client
*clp
= server
->nfs_client
;
250 struct nfs4_state
*state
= exception
->state
;
253 exception
->retry
= 0;
257 case -NFS4ERR_ADMIN_REVOKED
:
258 case -NFS4ERR_BAD_STATEID
:
259 case -NFS4ERR_OPENMODE
:
262 nfs4_schedule_stateid_recovery(server
, state
);
263 goto wait_on_recovery
;
264 case -NFS4ERR_STALE_STATEID
:
265 case -NFS4ERR_STALE_CLIENTID
:
266 case -NFS4ERR_EXPIRED
:
267 nfs4_schedule_lease_recovery(clp
);
268 goto wait_on_recovery
;
269 #if defined(CONFIG_NFS_V4_1)
270 case -NFS4ERR_BADSESSION
:
271 case -NFS4ERR_BADSLOT
:
272 case -NFS4ERR_BAD_HIGH_SLOT
:
273 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
274 case -NFS4ERR_DEADSESSION
:
275 case -NFS4ERR_SEQ_FALSE_RETRY
:
276 case -NFS4ERR_SEQ_MISORDERED
:
277 dprintk("%s ERROR: %d Reset session\n", __func__
,
279 nfs4_schedule_session_recovery(clp
->cl_session
);
280 exception
->retry
= 1;
282 #endif /* defined(CONFIG_NFS_V4_1) */
283 case -NFS4ERR_FILE_OPEN
:
284 if (exception
->timeout
> HZ
) {
285 /* We have retried a decent amount, time to
294 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
297 case -NFS4ERR_OLD_STATEID
:
298 exception
->retry
= 1;
300 case -NFS4ERR_BADOWNER
:
301 /* The following works around a Linux server bug! */
302 case -NFS4ERR_BADNAME
:
303 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
304 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
305 exception
->retry
= 1;
306 printk(KERN_WARNING
"NFS: v4 server %s "
307 "does not accept raw "
309 "Reenabling the idmapper.\n",
310 server
->nfs_client
->cl_hostname
);
313 /* We failed to handle the error */
314 return nfs4_map_errors(ret
);
316 ret
= nfs4_wait_clnt_recover(clp
);
318 exception
->retry
= 1;
323 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
325 spin_lock(&clp
->cl_lock
);
326 if (time_before(clp
->cl_last_renewal
,timestamp
))
327 clp
->cl_last_renewal
= timestamp
;
328 spin_unlock(&clp
->cl_lock
);
331 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
333 do_renew_lease(server
->nfs_client
, timestamp
);
336 #if defined(CONFIG_NFS_V4_1)
339 * nfs4_free_slot - free a slot and efficiently update slot table.
341 * freeing a slot is trivially done by clearing its respective bit
343 * If the freed slotid equals highest_used_slotid we want to update it
344 * so that the server would be able to size down the slot table if needed,
345 * otherwise we know that the highest_used_slotid is still in use.
346 * When updating highest_used_slotid there may be "holes" in the bitmap
347 * so we need to scan down from highest_used_slotid to 0 looking for the now
348 * highest slotid in use.
349 * If none found, highest_used_slotid is set to -1.
351 * Must be called while holding tbl->slot_tbl_lock
354 nfs4_free_slot(struct nfs4_slot_table
*tbl
, struct nfs4_slot
*free_slot
)
356 int free_slotid
= free_slot
- tbl
->slots
;
357 int slotid
= free_slotid
;
359 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
360 /* clear used bit in bitmap */
361 __clear_bit(slotid
, tbl
->used_slots
);
363 /* update highest_used_slotid when it is freed */
364 if (slotid
== tbl
->highest_used_slotid
) {
365 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
366 if (slotid
< tbl
->max_slots
)
367 tbl
->highest_used_slotid
= slotid
;
369 tbl
->highest_used_slotid
= -1;
371 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
372 free_slotid
, tbl
->highest_used_slotid
);
376 * Signal state manager thread if session fore channel is drained
378 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
380 struct rpc_task
*task
;
382 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
383 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
385 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
389 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
392 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
393 complete(&ses
->fc_slot_table
.complete
);
397 * Signal state manager thread if session back channel is drained
399 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
401 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
402 ses
->bc_slot_table
.highest_used_slotid
!= -1)
404 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
405 complete(&ses
->bc_slot_table
.complete
);
408 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
410 struct nfs4_slot_table
*tbl
;
412 tbl
= &res
->sr_session
->fc_slot_table
;
414 /* just wake up the next guy waiting since
415 * we may have not consumed a slot after all */
416 dprintk("%s: No slot\n", __func__
);
420 spin_lock(&tbl
->slot_tbl_lock
);
421 nfs4_free_slot(tbl
, res
->sr_slot
);
422 nfs4_check_drain_fc_complete(res
->sr_session
);
423 spin_unlock(&tbl
->slot_tbl_lock
);
427 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
429 unsigned long timestamp
;
430 struct nfs_client
*clp
;
433 * sr_status remains 1 if an RPC level error occurred. The server
434 * may or may not have processed the sequence operation..
435 * Proceed as if the server received and processed the sequence
438 if (res
->sr_status
== 1)
439 res
->sr_status
= NFS_OK
;
441 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
445 /* Check the SEQUENCE operation status */
446 switch (res
->sr_status
) {
448 /* Update the slot's sequence and clientid lease timer */
449 ++res
->sr_slot
->seq_nr
;
450 timestamp
= res
->sr_renewal_time
;
451 clp
= res
->sr_session
->clp
;
452 do_renew_lease(clp
, timestamp
);
453 /* Check sequence flags */
454 if (res
->sr_status_flags
!= 0)
455 nfs4_schedule_lease_recovery(clp
);
458 /* The server detected a resend of the RPC call and
459 * returned NFS4ERR_DELAY as per Section 2.10.6.2
462 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
464 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
465 res
->sr_slot
->seq_nr
);
468 /* Just update the slot sequence no. */
469 ++res
->sr_slot
->seq_nr
;
472 /* The session may be reset by one of the error handlers. */
473 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
474 nfs41_sequence_free_slot(res
);
477 if (!rpc_restart_call(task
))
479 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
483 static int nfs4_sequence_done(struct rpc_task
*task
,
484 struct nfs4_sequence_res
*res
)
486 if (res
->sr_session
== NULL
)
488 return nfs41_sequence_done(task
, res
);
492 * nfs4_find_slot - efficiently look for a free slot
494 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
495 * If found, we mark the slot as used, update the highest_used_slotid,
496 * and respectively set up the sequence operation args.
497 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
499 * Note: must be called with under the slot_tbl_lock.
502 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
505 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
506 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
508 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
509 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
511 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
512 if (slotid
>= tbl
->max_slots
)
514 __set_bit(slotid
, tbl
->used_slots
);
515 if (slotid
> tbl
->highest_used_slotid
)
516 tbl
->highest_used_slotid
= slotid
;
519 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
520 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
524 int nfs41_setup_sequence(struct nfs4_session
*session
,
525 struct nfs4_sequence_args
*args
,
526 struct nfs4_sequence_res
*res
,
528 struct rpc_task
*task
)
530 struct nfs4_slot
*slot
;
531 struct nfs4_slot_table
*tbl
;
534 dprintk("--> %s\n", __func__
);
535 /* slot already allocated? */
536 if (res
->sr_slot
!= NULL
)
539 tbl
= &session
->fc_slot_table
;
541 spin_lock(&tbl
->slot_tbl_lock
);
542 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
543 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
545 * The state manager will wait until the slot table is empty.
546 * Schedule the reset thread
548 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
549 spin_unlock(&tbl
->slot_tbl_lock
);
550 dprintk("%s Schedule Session Reset\n", __func__
);
554 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
555 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
556 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
557 spin_unlock(&tbl
->slot_tbl_lock
);
558 dprintk("%s enforce FIFO order\n", __func__
);
562 slotid
= nfs4_find_slot(tbl
);
563 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
564 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
565 spin_unlock(&tbl
->slot_tbl_lock
);
566 dprintk("<-- %s: no free slots\n", __func__
);
569 spin_unlock(&tbl
->slot_tbl_lock
);
571 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
572 slot
= tbl
->slots
+ slotid
;
573 args
->sa_session
= session
;
574 args
->sa_slotid
= slotid
;
575 args
->sa_cache_this
= cache_reply
;
577 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
579 res
->sr_session
= session
;
581 res
->sr_renewal_time
= jiffies
;
582 res
->sr_status_flags
= 0;
584 * sr_status is only set in decode_sequence, and so will remain
585 * set to 1 if an rpc level failure occurs.
590 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
592 int nfs4_setup_sequence(const struct nfs_server
*server
,
593 struct nfs4_sequence_args
*args
,
594 struct nfs4_sequence_res
*res
,
596 struct rpc_task
*task
)
598 struct nfs4_session
*session
= nfs4_get_session(server
);
601 if (session
== NULL
) {
602 args
->sa_session
= NULL
;
603 res
->sr_session
= NULL
;
607 dprintk("--> %s clp %p session %p sr_slot %td\n",
608 __func__
, session
->clp
, session
, res
->sr_slot
?
609 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
611 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
614 dprintk("<-- %s status=%d\n", __func__
, ret
);
618 struct nfs41_call_sync_data
{
619 const struct nfs_server
*seq_server
;
620 struct nfs4_sequence_args
*seq_args
;
621 struct nfs4_sequence_res
*seq_res
;
625 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
627 struct nfs41_call_sync_data
*data
= calldata
;
629 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
631 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
632 data
->seq_res
, data
->cache_reply
, task
))
634 rpc_call_start(task
);
637 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
639 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
640 nfs41_call_sync_prepare(task
, calldata
);
643 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
645 struct nfs41_call_sync_data
*data
= calldata
;
647 nfs41_sequence_done(task
, data
->seq_res
);
650 struct rpc_call_ops nfs41_call_sync_ops
= {
651 .rpc_call_prepare
= nfs41_call_sync_prepare
,
652 .rpc_call_done
= nfs41_call_sync_done
,
655 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
656 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
657 .rpc_call_done
= nfs41_call_sync_done
,
660 static int nfs4_call_sync_sequence(struct nfs_server
*server
,
661 struct rpc_message
*msg
,
662 struct nfs4_sequence_args
*args
,
663 struct nfs4_sequence_res
*res
,
668 struct rpc_task
*task
;
669 struct nfs41_call_sync_data data
= {
670 .seq_server
= server
,
673 .cache_reply
= cache_reply
,
675 struct rpc_task_setup task_setup
= {
676 .rpc_client
= server
->client
,
678 .callback_ops
= &nfs41_call_sync_ops
,
679 .callback_data
= &data
684 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
685 task
= rpc_run_task(&task_setup
);
689 ret
= task
->tk_status
;
695 int _nfs4_call_sync_session(struct nfs_server
*server
,
696 struct rpc_message
*msg
,
697 struct nfs4_sequence_args
*args
,
698 struct nfs4_sequence_res
*res
,
701 return nfs4_call_sync_sequence(server
, msg
, args
, res
, cache_reply
, 0);
705 static int nfs4_sequence_done(struct rpc_task
*task
,
706 struct nfs4_sequence_res
*res
)
710 #endif /* CONFIG_NFS_V4_1 */
712 int _nfs4_call_sync(struct nfs_server
*server
,
713 struct rpc_message
*msg
,
714 struct nfs4_sequence_args
*args
,
715 struct nfs4_sequence_res
*res
,
718 args
->sa_session
= res
->sr_session
= NULL
;
719 return rpc_call_sync(server
->client
, msg
, 0);
723 int nfs4_call_sync(struct nfs_server
*server
,
724 struct rpc_message
*msg
,
725 struct nfs4_sequence_args
*args
,
726 struct nfs4_sequence_res
*res
,
729 return server
->nfs_client
->cl_mvops
->call_sync(server
, msg
, args
,
733 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
735 struct nfs_inode
*nfsi
= NFS_I(dir
);
737 spin_lock(&dir
->i_lock
);
738 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
739 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
740 nfs_force_lookup_revalidate(dir
);
741 nfsi
->change_attr
= cinfo
->after
;
742 spin_unlock(&dir
->i_lock
);
745 struct nfs4_opendata
{
747 struct nfs_openargs o_arg
;
748 struct nfs_openres o_res
;
749 struct nfs_open_confirmargs c_arg
;
750 struct nfs_open_confirmres c_res
;
751 struct nfs_fattr f_attr
;
752 struct nfs_fattr dir_attr
;
755 struct nfs4_state_owner
*owner
;
756 struct nfs4_state
*state
;
758 unsigned long timestamp
;
759 unsigned int rpc_done
: 1;
765 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
767 p
->o_res
.f_attr
= &p
->f_attr
;
768 p
->o_res
.dir_attr
= &p
->dir_attr
;
769 p
->o_res
.seqid
= p
->o_arg
.seqid
;
770 p
->c_res
.seqid
= p
->c_arg
.seqid
;
771 p
->o_res
.server
= p
->o_arg
.server
;
772 nfs_fattr_init(&p
->f_attr
);
773 nfs_fattr_init(&p
->dir_attr
);
776 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
777 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
778 const struct iattr
*attrs
,
781 struct dentry
*parent
= dget_parent(path
->dentry
);
782 struct inode
*dir
= parent
->d_inode
;
783 struct nfs_server
*server
= NFS_SERVER(dir
);
784 struct nfs4_opendata
*p
;
786 p
= kzalloc(sizeof(*p
), gfp_mask
);
789 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
790 if (p
->o_arg
.seqid
== NULL
)
796 atomic_inc(&sp
->so_count
);
797 p
->o_arg
.fh
= NFS_FH(dir
);
798 p
->o_arg
.open_flags
= flags
;
799 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
800 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
801 p
->o_arg
.id
= sp
->so_owner_id
.id
;
802 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
803 p
->o_arg
.server
= server
;
804 p
->o_arg
.bitmask
= server
->attr_bitmask
;
805 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
806 if (flags
& O_CREAT
) {
809 p
->o_arg
.u
.attrs
= &p
->attrs
;
810 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
811 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
815 p
->c_arg
.fh
= &p
->o_res
.fh
;
816 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
817 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
818 nfs4_init_opendata_res(p
);
828 static void nfs4_opendata_free(struct kref
*kref
)
830 struct nfs4_opendata
*p
= container_of(kref
,
831 struct nfs4_opendata
, kref
);
833 nfs_free_seqid(p
->o_arg
.seqid
);
834 if (p
->state
!= NULL
)
835 nfs4_put_open_state(p
->state
);
836 nfs4_put_state_owner(p
->owner
);
842 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
845 kref_put(&p
->kref
, nfs4_opendata_free
);
848 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
852 ret
= rpc_wait_for_completion_task(task
);
856 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
860 if (open_mode
& O_EXCL
)
862 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
864 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
865 && state
->n_rdonly
!= 0;
868 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
869 && state
->n_wronly
!= 0;
871 case FMODE_READ
|FMODE_WRITE
:
872 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
873 && state
->n_rdwr
!= 0;
879 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
881 if ((delegation
->type
& fmode
) != fmode
)
883 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
885 nfs_mark_delegation_referenced(delegation
);
889 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
898 case FMODE_READ
|FMODE_WRITE
:
901 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
904 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
906 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
907 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
908 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
911 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
914 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
916 case FMODE_READ
|FMODE_WRITE
:
917 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
921 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
923 write_seqlock(&state
->seqlock
);
924 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
925 write_sequnlock(&state
->seqlock
);
928 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
931 * Protect the call to nfs4_state_set_mode_locked and
932 * serialise the stateid update
934 write_seqlock(&state
->seqlock
);
935 if (deleg_stateid
!= NULL
) {
936 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
937 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
939 if (open_stateid
!= NULL
)
940 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
941 write_sequnlock(&state
->seqlock
);
942 spin_lock(&state
->owner
->so_lock
);
943 update_open_stateflags(state
, fmode
);
944 spin_unlock(&state
->owner
->so_lock
);
947 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
949 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
950 struct nfs_delegation
*deleg_cur
;
953 fmode
&= (FMODE_READ
|FMODE_WRITE
);
956 deleg_cur
= rcu_dereference(nfsi
->delegation
);
957 if (deleg_cur
== NULL
)
960 spin_lock(&deleg_cur
->lock
);
961 if (nfsi
->delegation
!= deleg_cur
||
962 (deleg_cur
->type
& fmode
) != fmode
)
963 goto no_delegation_unlock
;
965 if (delegation
== NULL
)
966 delegation
= &deleg_cur
->stateid
;
967 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
968 goto no_delegation_unlock
;
970 nfs_mark_delegation_referenced(deleg_cur
);
971 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
973 no_delegation_unlock
:
974 spin_unlock(&deleg_cur
->lock
);
978 if (!ret
&& open_stateid
!= NULL
) {
979 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
987 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
989 struct nfs_delegation
*delegation
;
992 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
993 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
998 nfs_inode_return_delegation(inode
);
1001 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1003 struct nfs4_state
*state
= opendata
->state
;
1004 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1005 struct nfs_delegation
*delegation
;
1006 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
1007 fmode_t fmode
= opendata
->o_arg
.fmode
;
1008 nfs4_stateid stateid
;
1012 if (can_open_cached(state
, fmode
, open_mode
)) {
1013 spin_lock(&state
->owner
->so_lock
);
1014 if (can_open_cached(state
, fmode
, open_mode
)) {
1015 update_open_stateflags(state
, fmode
);
1016 spin_unlock(&state
->owner
->so_lock
);
1017 goto out_return_state
;
1019 spin_unlock(&state
->owner
->so_lock
);
1022 delegation
= rcu_dereference(nfsi
->delegation
);
1023 if (delegation
== NULL
||
1024 !can_open_delegated(delegation
, fmode
)) {
1028 /* Save the delegation */
1029 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1031 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1036 /* Try to update the stateid using the delegation */
1037 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1038 goto out_return_state
;
1041 return ERR_PTR(ret
);
1043 atomic_inc(&state
->count
);
1047 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1049 struct inode
*inode
;
1050 struct nfs4_state
*state
= NULL
;
1051 struct nfs_delegation
*delegation
;
1054 if (!data
->rpc_done
) {
1055 state
= nfs4_try_open_cached(data
);
1060 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1062 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1063 ret
= PTR_ERR(inode
);
1067 state
= nfs4_get_open_state(inode
, data
->owner
);
1070 if (data
->o_res
.delegation_type
!= 0) {
1071 int delegation_flags
= 0;
1074 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1076 delegation_flags
= delegation
->flags
;
1078 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1079 nfs_inode_set_delegation(state
->inode
,
1080 data
->owner
->so_cred
,
1083 nfs_inode_reclaim_delegation(state
->inode
,
1084 data
->owner
->so_cred
,
1088 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1096 return ERR_PTR(ret
);
1099 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1101 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1102 struct nfs_open_context
*ctx
;
1104 spin_lock(&state
->inode
->i_lock
);
1105 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1106 if (ctx
->state
!= state
)
1108 get_nfs_open_context(ctx
);
1109 spin_unlock(&state
->inode
->i_lock
);
1112 spin_unlock(&state
->inode
->i_lock
);
1113 return ERR_PTR(-ENOENT
);
1116 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1118 struct nfs4_opendata
*opendata
;
1120 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1121 if (opendata
== NULL
)
1122 return ERR_PTR(-ENOMEM
);
1123 opendata
->state
= state
;
1124 atomic_inc(&state
->count
);
1128 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1130 struct nfs4_state
*newstate
;
1133 opendata
->o_arg
.open_flags
= 0;
1134 opendata
->o_arg
.fmode
= fmode
;
1135 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1136 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1137 nfs4_init_opendata_res(opendata
);
1138 ret
= _nfs4_recover_proc_open(opendata
);
1141 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1142 if (IS_ERR(newstate
))
1143 return PTR_ERR(newstate
);
1144 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1149 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1151 struct nfs4_state
*newstate
;
1154 /* memory barrier prior to reading state->n_* */
1155 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1157 if (state
->n_rdwr
!= 0) {
1158 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1159 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1162 if (newstate
!= state
)
1165 if (state
->n_wronly
!= 0) {
1166 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1167 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1170 if (newstate
!= state
)
1173 if (state
->n_rdonly
!= 0) {
1174 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1175 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1178 if (newstate
!= state
)
1182 * We may have performed cached opens for all three recoveries.
1183 * Check if we need to update the current stateid.
1185 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1186 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1187 write_seqlock(&state
->seqlock
);
1188 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1189 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1190 write_sequnlock(&state
->seqlock
);
1197 * reclaim state on the server after a reboot.
1199 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1201 struct nfs_delegation
*delegation
;
1202 struct nfs4_opendata
*opendata
;
1203 fmode_t delegation_type
= 0;
1206 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1207 if (IS_ERR(opendata
))
1208 return PTR_ERR(opendata
);
1209 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1210 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1212 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1213 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1214 delegation_type
= delegation
->type
;
1216 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1217 status
= nfs4_open_recover(opendata
, state
);
1218 nfs4_opendata_put(opendata
);
1222 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1224 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1225 struct nfs4_exception exception
= { };
1228 err
= _nfs4_do_open_reclaim(ctx
, state
);
1229 if (err
!= -NFS4ERR_DELAY
)
1231 nfs4_handle_exception(server
, err
, &exception
);
1232 } while (exception
.retry
);
1236 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1238 struct nfs_open_context
*ctx
;
1241 ctx
= nfs4_state_find_open_context(state
);
1243 return PTR_ERR(ctx
);
1244 ret
= nfs4_do_open_reclaim(ctx
, state
);
1245 put_nfs_open_context(ctx
);
1249 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1251 struct nfs4_opendata
*opendata
;
1254 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1255 if (IS_ERR(opendata
))
1256 return PTR_ERR(opendata
);
1257 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1258 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1259 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1260 ret
= nfs4_open_recover(opendata
, state
);
1261 nfs4_opendata_put(opendata
);
1265 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1267 struct nfs4_exception exception
= { };
1268 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1271 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1277 case -NFS4ERR_BADSESSION
:
1278 case -NFS4ERR_BADSLOT
:
1279 case -NFS4ERR_BAD_HIGH_SLOT
:
1280 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1281 case -NFS4ERR_DEADSESSION
:
1282 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1284 case -NFS4ERR_STALE_CLIENTID
:
1285 case -NFS4ERR_STALE_STATEID
:
1286 case -NFS4ERR_EXPIRED
:
1287 /* Don't recall a delegation if it was lost */
1288 nfs4_schedule_lease_recovery(server
->nfs_client
);
1292 * The show must go on: exit, but mark the
1293 * stateid as needing recovery.
1295 case -NFS4ERR_ADMIN_REVOKED
:
1296 case -NFS4ERR_BAD_STATEID
:
1297 nfs4_schedule_stateid_recovery(server
, state
);
1300 * User RPCSEC_GSS context has expired.
1301 * We cannot recover this stateid now, so
1302 * skip it and allow recovery thread to
1309 err
= nfs4_handle_exception(server
, err
, &exception
);
1310 } while (exception
.retry
);
1315 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1317 struct nfs4_opendata
*data
= calldata
;
1319 data
->rpc_status
= task
->tk_status
;
1320 if (data
->rpc_status
== 0) {
1321 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1322 sizeof(data
->o_res
.stateid
.data
));
1323 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1324 renew_lease(data
->o_res
.server
, data
->timestamp
);
1329 static void nfs4_open_confirm_release(void *calldata
)
1331 struct nfs4_opendata
*data
= calldata
;
1332 struct nfs4_state
*state
= NULL
;
1334 /* If this request hasn't been cancelled, do nothing */
1335 if (data
->cancelled
== 0)
1337 /* In case of error, no cleanup! */
1338 if (!data
->rpc_done
)
1340 state
= nfs4_opendata_to_nfs4_state(data
);
1342 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1344 nfs4_opendata_put(data
);
1347 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1348 .rpc_call_done
= nfs4_open_confirm_done
,
1349 .rpc_release
= nfs4_open_confirm_release
,
1353 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1355 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1357 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1358 struct rpc_task
*task
;
1359 struct rpc_message msg
= {
1360 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1361 .rpc_argp
= &data
->c_arg
,
1362 .rpc_resp
= &data
->c_res
,
1363 .rpc_cred
= data
->owner
->so_cred
,
1365 struct rpc_task_setup task_setup_data
= {
1366 .rpc_client
= server
->client
,
1367 .rpc_message
= &msg
,
1368 .callback_ops
= &nfs4_open_confirm_ops
,
1369 .callback_data
= data
,
1370 .workqueue
= nfsiod_workqueue
,
1371 .flags
= RPC_TASK_ASYNC
,
1375 kref_get(&data
->kref
);
1377 data
->rpc_status
= 0;
1378 data
->timestamp
= jiffies
;
1379 task
= rpc_run_task(&task_setup_data
);
1381 return PTR_ERR(task
);
1382 status
= nfs4_wait_for_completion_rpc_task(task
);
1384 data
->cancelled
= 1;
1387 status
= data
->rpc_status
;
1392 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1394 struct nfs4_opendata
*data
= calldata
;
1395 struct nfs4_state_owner
*sp
= data
->owner
;
1397 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1400 * Check if we still need to send an OPEN call, or if we can use
1401 * a delegation instead.
1403 if (data
->state
!= NULL
) {
1404 struct nfs_delegation
*delegation
;
1406 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1409 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1410 if (delegation
!= NULL
&&
1411 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1417 /* Update sequence id. */
1418 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1419 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1420 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1421 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1422 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1424 data
->timestamp
= jiffies
;
1425 if (nfs4_setup_sequence(data
->o_arg
.server
,
1426 &data
->o_arg
.seq_args
,
1427 &data
->o_res
.seq_res
, 1, task
))
1429 rpc_call_start(task
);
1432 task
->tk_action
= NULL
;
1436 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1438 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1439 nfs4_open_prepare(task
, calldata
);
1442 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1444 struct nfs4_opendata
*data
= calldata
;
1446 data
->rpc_status
= task
->tk_status
;
1448 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1451 if (task
->tk_status
== 0) {
1452 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1456 data
->rpc_status
= -ELOOP
;
1459 data
->rpc_status
= -EISDIR
;
1462 data
->rpc_status
= -ENOTDIR
;
1464 renew_lease(data
->o_res
.server
, data
->timestamp
);
1465 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1466 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1471 static void nfs4_open_release(void *calldata
)
1473 struct nfs4_opendata
*data
= calldata
;
1474 struct nfs4_state
*state
= NULL
;
1476 /* If this request hasn't been cancelled, do nothing */
1477 if (data
->cancelled
== 0)
1479 /* In case of error, no cleanup! */
1480 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1482 /* In case we need an open_confirm, no cleanup! */
1483 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1485 state
= nfs4_opendata_to_nfs4_state(data
);
1487 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1489 nfs4_opendata_put(data
);
1492 static const struct rpc_call_ops nfs4_open_ops
= {
1493 .rpc_call_prepare
= nfs4_open_prepare
,
1494 .rpc_call_done
= nfs4_open_done
,
1495 .rpc_release
= nfs4_open_release
,
1498 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1499 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1500 .rpc_call_done
= nfs4_open_done
,
1501 .rpc_release
= nfs4_open_release
,
1504 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1506 struct inode
*dir
= data
->dir
->d_inode
;
1507 struct nfs_server
*server
= NFS_SERVER(dir
);
1508 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1509 struct nfs_openres
*o_res
= &data
->o_res
;
1510 struct rpc_task
*task
;
1511 struct rpc_message msg
= {
1512 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1515 .rpc_cred
= data
->owner
->so_cred
,
1517 struct rpc_task_setup task_setup_data
= {
1518 .rpc_client
= server
->client
,
1519 .rpc_message
= &msg
,
1520 .callback_ops
= &nfs4_open_ops
,
1521 .callback_data
= data
,
1522 .workqueue
= nfsiod_workqueue
,
1523 .flags
= RPC_TASK_ASYNC
,
1527 kref_get(&data
->kref
);
1529 data
->rpc_status
= 0;
1530 data
->cancelled
= 0;
1532 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1533 task
= rpc_run_task(&task_setup_data
);
1535 return PTR_ERR(task
);
1536 status
= nfs4_wait_for_completion_rpc_task(task
);
1538 data
->cancelled
= 1;
1541 status
= data
->rpc_status
;
1547 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1549 struct inode
*dir
= data
->dir
->d_inode
;
1550 struct nfs_openres
*o_res
= &data
->o_res
;
1553 status
= nfs4_run_open_task(data
, 1);
1554 if (status
!= 0 || !data
->rpc_done
)
1557 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1559 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1560 status
= _nfs4_proc_open_confirm(data
);
1569 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1571 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1573 struct inode
*dir
= data
->dir
->d_inode
;
1574 struct nfs_server
*server
= NFS_SERVER(dir
);
1575 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1576 struct nfs_openres
*o_res
= &data
->o_res
;
1579 status
= nfs4_run_open_task(data
, 0);
1580 if (status
!= 0 || !data
->rpc_done
)
1583 if (o_arg
->open_flags
& O_CREAT
) {
1584 update_changeattr(dir
, &o_res
->cinfo
);
1585 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1587 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1588 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1589 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1590 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1591 status
= _nfs4_proc_open_confirm(data
);
1595 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1596 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1600 static int nfs4_client_recover_expired_lease(struct nfs_client
*clp
)
1605 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1606 ret
= nfs4_wait_clnt_recover(clp
);
1609 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1610 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1612 nfs4_schedule_state_manager(clp
);
1618 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1620 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1625 * reclaim state on the server after a network partition.
1626 * Assumes caller holds the appropriate lock
1628 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1630 struct nfs4_opendata
*opendata
;
1633 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1634 if (IS_ERR(opendata
))
1635 return PTR_ERR(opendata
);
1636 ret
= nfs4_open_recover(opendata
, state
);
1638 d_drop(ctx
->path
.dentry
);
1639 nfs4_opendata_put(opendata
);
1643 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1645 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1646 struct nfs4_exception exception
= { };
1650 err
= _nfs4_open_expired(ctx
, state
);
1654 case -NFS4ERR_GRACE
:
1655 case -NFS4ERR_DELAY
:
1656 nfs4_handle_exception(server
, err
, &exception
);
1659 } while (exception
.retry
);
1664 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1666 struct nfs_open_context
*ctx
;
1669 ctx
= nfs4_state_find_open_context(state
);
1671 return PTR_ERR(ctx
);
1672 ret
= nfs4_do_open_expired(ctx
, state
);
1673 put_nfs_open_context(ctx
);
1678 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1679 * fields corresponding to attributes that were used to store the verifier.
1680 * Make sure we clobber those fields in the later setattr call
1682 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1684 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1685 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1686 sattr
->ia_valid
|= ATTR_ATIME
;
1688 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1689 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1690 sattr
->ia_valid
|= ATTR_MTIME
;
1694 * Returns a referenced nfs4_state
1696 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
)
1698 struct nfs4_state_owner
*sp
;
1699 struct nfs4_state
*state
= NULL
;
1700 struct nfs_server
*server
= NFS_SERVER(dir
);
1701 struct nfs4_opendata
*opendata
;
1704 /* Protect against reboot recovery conflicts */
1706 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1707 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1710 status
= nfs4_recover_expired_lease(server
);
1712 goto err_put_state_owner
;
1713 if (path
->dentry
->d_inode
!= NULL
)
1714 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1716 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1717 if (opendata
== NULL
)
1718 goto err_put_state_owner
;
1720 if (path
->dentry
->d_inode
!= NULL
)
1721 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1723 status
= _nfs4_proc_open(opendata
);
1725 goto err_opendata_put
;
1727 state
= nfs4_opendata_to_nfs4_state(opendata
);
1728 status
= PTR_ERR(state
);
1730 goto err_opendata_put
;
1731 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1732 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1734 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1735 nfs4_exclusive_attrset(opendata
, sattr
);
1737 nfs_fattr_init(opendata
->o_res
.f_attr
);
1738 status
= nfs4_do_setattr(state
->inode
, cred
,
1739 opendata
->o_res
.f_attr
, sattr
,
1742 nfs_setattr_update_inode(state
->inode
, sattr
);
1743 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1745 nfs4_opendata_put(opendata
);
1746 nfs4_put_state_owner(sp
);
1750 nfs4_opendata_put(opendata
);
1751 err_put_state_owner
:
1752 nfs4_put_state_owner(sp
);
1759 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
)
1761 struct nfs4_exception exception
= { };
1762 struct nfs4_state
*res
;
1766 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1769 /* NOTE: BAD_SEQID means the server and client disagree about the
1770 * book-keeping w.r.t. state-changing operations
1771 * (OPEN/CLOSE/LOCK/LOCKU...)
1772 * It is actually a sign of a bug on the client or on the server.
1774 * If we receive a BAD_SEQID error in the particular case of
1775 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1776 * have unhashed the old state_owner for us, and that we can
1777 * therefore safely retry using a new one. We should still warn
1778 * the user though...
1780 if (status
== -NFS4ERR_BAD_SEQID
) {
1781 printk(KERN_WARNING
"NFS: v4 server %s "
1782 " returned a bad sequence-id error!\n",
1783 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1784 exception
.retry
= 1;
1788 * BAD_STATEID on OPEN means that the server cancelled our
1789 * state before it received the OPEN_CONFIRM.
1790 * Recover by retrying the request as per the discussion
1791 * on Page 181 of RFC3530.
1793 if (status
== -NFS4ERR_BAD_STATEID
) {
1794 exception
.retry
= 1;
1797 if (status
== -EAGAIN
) {
1798 /* We must have found a delegation */
1799 exception
.retry
= 1;
1802 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1803 status
, &exception
));
1804 } while (exception
.retry
);
1808 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1809 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1810 struct nfs4_state
*state
)
1812 struct nfs_server
*server
= NFS_SERVER(inode
);
1813 struct nfs_setattrargs arg
= {
1814 .fh
= NFS_FH(inode
),
1817 .bitmask
= server
->attr_bitmask
,
1819 struct nfs_setattrres res
= {
1823 struct rpc_message msg
= {
1824 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1829 unsigned long timestamp
= jiffies
;
1832 nfs_fattr_init(fattr
);
1834 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1835 /* Use that stateid */
1836 } else if (state
!= NULL
) {
1837 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1839 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1841 status
= nfs4_call_sync(server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
1842 if (status
== 0 && state
!= NULL
)
1843 renew_lease(server
, timestamp
);
1847 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1848 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1849 struct nfs4_state
*state
)
1851 struct nfs_server
*server
= NFS_SERVER(inode
);
1852 struct nfs4_exception exception
= { };
1855 err
= nfs4_handle_exception(server
,
1856 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1858 } while (exception
.retry
);
1862 struct nfs4_closedata
{
1864 struct inode
*inode
;
1865 struct nfs4_state
*state
;
1866 struct nfs_closeargs arg
;
1867 struct nfs_closeres res
;
1868 struct nfs_fattr fattr
;
1869 unsigned long timestamp
;
1874 static void nfs4_free_closedata(void *data
)
1876 struct nfs4_closedata
*calldata
= data
;
1877 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1880 pnfs_roc_release(calldata
->state
->inode
);
1881 nfs4_put_open_state(calldata
->state
);
1882 nfs_free_seqid(calldata
->arg
.seqid
);
1883 nfs4_put_state_owner(sp
);
1884 path_put(&calldata
->path
);
1888 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1891 spin_lock(&state
->owner
->so_lock
);
1892 if (!(fmode
& FMODE_READ
))
1893 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1894 if (!(fmode
& FMODE_WRITE
))
1895 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1896 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1897 spin_unlock(&state
->owner
->so_lock
);
1900 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1902 struct nfs4_closedata
*calldata
= data
;
1903 struct nfs4_state
*state
= calldata
->state
;
1904 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1906 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1908 /* hmm. we are done with the inode, and in the process of freeing
1909 * the state_owner. we keep this around to process errors
1911 switch (task
->tk_status
) {
1914 pnfs_roc_set_barrier(state
->inode
,
1915 calldata
->roc_barrier
);
1916 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1917 renew_lease(server
, calldata
->timestamp
);
1918 nfs4_close_clear_stateid_flags(state
,
1919 calldata
->arg
.fmode
);
1921 case -NFS4ERR_STALE_STATEID
:
1922 case -NFS4ERR_OLD_STATEID
:
1923 case -NFS4ERR_BAD_STATEID
:
1924 case -NFS4ERR_EXPIRED
:
1925 if (calldata
->arg
.fmode
== 0)
1928 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1929 rpc_restart_call_prepare(task
);
1931 nfs_release_seqid(calldata
->arg
.seqid
);
1932 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1935 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1937 struct nfs4_closedata
*calldata
= data
;
1938 struct nfs4_state
*state
= calldata
->state
;
1941 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1944 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1945 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1946 spin_lock(&state
->owner
->so_lock
);
1947 /* Calculate the change in open mode */
1948 if (state
->n_rdwr
== 0) {
1949 if (state
->n_rdonly
== 0) {
1950 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1951 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1952 calldata
->arg
.fmode
&= ~FMODE_READ
;
1954 if (state
->n_wronly
== 0) {
1955 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1956 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1957 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1960 spin_unlock(&state
->owner
->so_lock
);
1963 /* Note: exit _without_ calling nfs4_close_done */
1964 task
->tk_action
= NULL
;
1968 if (calldata
->arg
.fmode
== 0) {
1969 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
1970 if (calldata
->roc
&&
1971 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
1972 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
1978 nfs_fattr_init(calldata
->res
.fattr
);
1979 calldata
->timestamp
= jiffies
;
1980 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
1981 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1984 rpc_call_start(task
);
1987 static const struct rpc_call_ops nfs4_close_ops
= {
1988 .rpc_call_prepare
= nfs4_close_prepare
,
1989 .rpc_call_done
= nfs4_close_done
,
1990 .rpc_release
= nfs4_free_closedata
,
1994 * It is possible for data to be read/written from a mem-mapped file
1995 * after the sys_close call (which hits the vfs layer as a flush).
1996 * This means that we can't safely call nfsv4 close on a file until
1997 * the inode is cleared. This in turn means that we are not good
1998 * NFSv4 citizens - we do not indicate to the server to update the file's
1999 * share state even when we are done with one of the three share
2000 * stateid's in the inode.
2002 * NOTE: Caller must be holding the sp->so_owner semaphore!
2004 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
2006 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2007 struct nfs4_closedata
*calldata
;
2008 struct nfs4_state_owner
*sp
= state
->owner
;
2009 struct rpc_task
*task
;
2010 struct rpc_message msg
= {
2011 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2012 .rpc_cred
= state
->owner
->so_cred
,
2014 struct rpc_task_setup task_setup_data
= {
2015 .rpc_client
= server
->client
,
2016 .rpc_message
= &msg
,
2017 .callback_ops
= &nfs4_close_ops
,
2018 .workqueue
= nfsiod_workqueue
,
2019 .flags
= RPC_TASK_ASYNC
,
2021 int status
= -ENOMEM
;
2023 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2024 if (calldata
== NULL
)
2026 calldata
->inode
= state
->inode
;
2027 calldata
->state
= state
;
2028 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2029 calldata
->arg
.stateid
= &state
->open_stateid
;
2030 /* Serialization for the sequence id */
2031 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2032 if (calldata
->arg
.seqid
== NULL
)
2033 goto out_free_calldata
;
2034 calldata
->arg
.fmode
= 0;
2035 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2036 calldata
->res
.fattr
= &calldata
->fattr
;
2037 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2038 calldata
->res
.server
= server
;
2039 calldata
->roc
= roc
;
2041 calldata
->path
= *path
;
2043 msg
.rpc_argp
= &calldata
->arg
;
2044 msg
.rpc_resp
= &calldata
->res
;
2045 task_setup_data
.callback_data
= calldata
;
2046 task
= rpc_run_task(&task_setup_data
);
2048 return PTR_ERR(task
);
2051 status
= rpc_wait_for_completion_task(task
);
2058 pnfs_roc_release(state
->inode
);
2059 nfs4_put_open_state(state
);
2060 nfs4_put_state_owner(sp
);
2064 static struct inode
*
2065 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2067 struct nfs4_state
*state
;
2069 /* Protect against concurrent sillydeletes */
2070 state
= nfs4_do_open(dir
, &ctx
->path
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2072 return ERR_CAST(state
);
2074 return igrab(state
->inode
);
2077 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2079 if (ctx
->state
== NULL
)
2082 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
2084 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
2087 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2089 struct nfs4_server_caps_arg args
= {
2092 struct nfs4_server_caps_res res
= {};
2093 struct rpc_message msg
= {
2094 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2100 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2102 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2103 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2104 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2105 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2106 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2107 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2108 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2109 server
->caps
|= NFS_CAP_ACLS
;
2110 if (res
.has_links
!= 0)
2111 server
->caps
|= NFS_CAP_HARDLINKS
;
2112 if (res
.has_symlinks
!= 0)
2113 server
->caps
|= NFS_CAP_SYMLINKS
;
2114 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2115 server
->caps
|= NFS_CAP_FILEID
;
2116 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2117 server
->caps
|= NFS_CAP_MODE
;
2118 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2119 server
->caps
|= NFS_CAP_NLINK
;
2120 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2121 server
->caps
|= NFS_CAP_OWNER
;
2122 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2123 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2124 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2125 server
->caps
|= NFS_CAP_ATIME
;
2126 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2127 server
->caps
|= NFS_CAP_CTIME
;
2128 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2129 server
->caps
|= NFS_CAP_MTIME
;
2131 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2132 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2133 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2134 server
->acl_bitmask
= res
.acl_bitmask
;
2140 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2142 struct nfs4_exception exception
= { };
2145 err
= nfs4_handle_exception(server
,
2146 _nfs4_server_capabilities(server
, fhandle
),
2148 } while (exception
.retry
);
2152 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2153 struct nfs_fsinfo
*info
)
2155 struct nfs4_lookup_root_arg args
= {
2156 .bitmask
= nfs4_fattr_bitmap
,
2158 struct nfs4_lookup_res res
= {
2160 .fattr
= info
->fattr
,
2163 struct rpc_message msg
= {
2164 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2169 nfs_fattr_init(info
->fattr
);
2170 return nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2173 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2174 struct nfs_fsinfo
*info
)
2176 struct nfs4_exception exception
= { };
2179 err
= nfs4_handle_exception(server
,
2180 _nfs4_lookup_root(server
, fhandle
, info
),
2182 } while (exception
.retry
);
2187 * get the file handle for the "/" directory on the server
2189 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2190 struct nfs_fsinfo
*info
)
2194 status
= nfs4_lookup_root(server
, fhandle
, info
);
2196 status
= nfs4_server_capabilities(server
, fhandle
);
2198 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2199 return nfs4_map_errors(status
);
2203 * Get locations and (maybe) other attributes of a referral.
2204 * Note that we'll actually follow the referral later when
2205 * we detect fsid mismatch in inode revalidation
2207 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2209 int status
= -ENOMEM
;
2210 struct page
*page
= NULL
;
2211 struct nfs4_fs_locations
*locations
= NULL
;
2213 page
= alloc_page(GFP_KERNEL
);
2216 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2217 if (locations
== NULL
)
2220 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2223 /* Make sure server returned a different fsid for the referral */
2224 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2225 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2230 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2231 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2233 fattr
->mode
= S_IFDIR
;
2234 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2242 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2244 struct nfs4_getattr_arg args
= {
2246 .bitmask
= server
->attr_bitmask
,
2248 struct nfs4_getattr_res res
= {
2252 struct rpc_message msg
= {
2253 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2258 nfs_fattr_init(fattr
);
2259 return nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2262 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2264 struct nfs4_exception exception
= { };
2267 err
= nfs4_handle_exception(server
,
2268 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2270 } while (exception
.retry
);
2275 * The file is not closed if it is opened due to the a request to change
2276 * the size of the file. The open call will not be needed once the
2277 * VFS layer lookup-intents are implemented.
2279 * Close is called when the inode is destroyed.
2280 * If we haven't opened the file for O_WRONLY, we
2281 * need to in the size_change case to obtain a stateid.
2284 * Because OPEN is always done by name in nfsv4, it is
2285 * possible that we opened a different file by the same
2286 * name. We can recognize this race condition, but we
2287 * can't do anything about it besides returning an error.
2289 * This will be fixed with VFS changes (lookup-intent).
2292 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2293 struct iattr
*sattr
)
2295 struct inode
*inode
= dentry
->d_inode
;
2296 struct rpc_cred
*cred
= NULL
;
2297 struct nfs4_state
*state
= NULL
;
2300 nfs_fattr_init(fattr
);
2302 /* Search for an existing open(O_WRITE) file */
2303 if (sattr
->ia_valid
& ATTR_FILE
) {
2304 struct nfs_open_context
*ctx
;
2306 ctx
= nfs_file_open_context(sattr
->ia_file
);
2313 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2315 nfs_setattr_update_inode(inode
, sattr
);
2319 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
2320 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2321 struct nfs_fattr
*fattr
)
2324 struct nfs4_lookup_arg args
= {
2325 .bitmask
= server
->attr_bitmask
,
2329 struct nfs4_lookup_res res
= {
2334 struct rpc_message msg
= {
2335 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2340 nfs_fattr_init(fattr
);
2342 dprintk("NFS call lookupfh %s\n", name
->name
);
2343 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2344 dprintk("NFS reply lookupfh: %d\n", status
);
2348 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2349 struct qstr
*name
, struct nfs_fh
*fhandle
,
2350 struct nfs_fattr
*fattr
)
2352 struct nfs4_exception exception
= { };
2355 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
2357 if (err
== -NFS4ERR_MOVED
) {
2361 err
= nfs4_handle_exception(server
, err
, &exception
);
2362 } while (exception
.retry
);
2366 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
2367 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2371 dprintk("NFS call lookup %s\n", name
->name
);
2372 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2373 if (status
== -NFS4ERR_MOVED
)
2374 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2375 dprintk("NFS reply lookup: %d\n", status
);
2379 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2381 struct nfs4_exception exception
= { };
2384 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2385 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
2387 } while (exception
.retry
);
2391 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2393 struct nfs_server
*server
= NFS_SERVER(inode
);
2394 struct nfs4_accessargs args
= {
2395 .fh
= NFS_FH(inode
),
2396 .bitmask
= server
->attr_bitmask
,
2398 struct nfs4_accessres res
= {
2401 struct rpc_message msg
= {
2402 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2405 .rpc_cred
= entry
->cred
,
2407 int mode
= entry
->mask
;
2411 * Determine which access bits we want to ask for...
2413 if (mode
& MAY_READ
)
2414 args
.access
|= NFS4_ACCESS_READ
;
2415 if (S_ISDIR(inode
->i_mode
)) {
2416 if (mode
& MAY_WRITE
)
2417 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2418 if (mode
& MAY_EXEC
)
2419 args
.access
|= NFS4_ACCESS_LOOKUP
;
2421 if (mode
& MAY_WRITE
)
2422 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2423 if (mode
& MAY_EXEC
)
2424 args
.access
|= NFS4_ACCESS_EXECUTE
;
2427 res
.fattr
= nfs_alloc_fattr();
2428 if (res
.fattr
== NULL
)
2431 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2434 if (res
.access
& NFS4_ACCESS_READ
)
2435 entry
->mask
|= MAY_READ
;
2436 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2437 entry
->mask
|= MAY_WRITE
;
2438 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2439 entry
->mask
|= MAY_EXEC
;
2440 nfs_refresh_inode(inode
, res
.fattr
);
2442 nfs_free_fattr(res
.fattr
);
2446 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2448 struct nfs4_exception exception
= { };
2451 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2452 _nfs4_proc_access(inode
, entry
),
2454 } while (exception
.retry
);
2459 * TODO: For the time being, we don't try to get any attributes
2460 * along with any of the zero-copy operations READ, READDIR,
2463 * In the case of the first three, we want to put the GETATTR
2464 * after the read-type operation -- this is because it is hard
2465 * to predict the length of a GETATTR response in v4, and thus
2466 * align the READ data correctly. This means that the GETATTR
2467 * may end up partially falling into the page cache, and we should
2468 * shift it into the 'tail' of the xdr_buf before processing.
2469 * To do this efficiently, we need to know the total length
2470 * of data received, which doesn't seem to be available outside
2473 * In the case of WRITE, we also want to put the GETATTR after
2474 * the operation -- in this case because we want to make sure
2475 * we get the post-operation mtime and size. This means that
2476 * we can't use xdr_encode_pages() as written: we need a variant
2477 * of it which would leave room in the 'tail' iovec.
2479 * Both of these changes to the XDR layer would in fact be quite
2480 * minor, but I decided to leave them for a subsequent patch.
2482 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2483 unsigned int pgbase
, unsigned int pglen
)
2485 struct nfs4_readlink args
= {
2486 .fh
= NFS_FH(inode
),
2491 struct nfs4_readlink_res res
;
2492 struct rpc_message msg
= {
2493 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2498 return nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2501 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2502 unsigned int pgbase
, unsigned int pglen
)
2504 struct nfs4_exception exception
= { };
2507 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2508 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2510 } while (exception
.retry
);
2516 * We will need to arrange for the VFS layer to provide an atomic open.
2517 * Until then, this create/open method is prone to inefficiency and race
2518 * conditions due to the lookup, create, and open VFS calls from sys_open()
2519 * placed on the wire.
2521 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2522 * The file will be opened again in the subsequent VFS open call
2523 * (nfs4_proc_file_open).
2525 * The open for read will just hang around to be used by any process that
2526 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2530 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2531 int flags
, struct nfs_open_context
*ctx
)
2533 struct path my_path
= {
2536 struct path
*path
= &my_path
;
2537 struct nfs4_state
*state
;
2538 struct rpc_cred
*cred
= NULL
;
2547 sattr
->ia_mode
&= ~current_umask();
2548 state
= nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
);
2550 if (IS_ERR(state
)) {
2551 status
= PTR_ERR(state
);
2554 d_add(dentry
, igrab(state
->inode
));
2555 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2559 nfs4_close_sync(path
, state
, fmode
);
2564 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2566 struct nfs_server
*server
= NFS_SERVER(dir
);
2567 struct nfs_removeargs args
= {
2569 .name
.len
= name
->len
,
2570 .name
.name
= name
->name
,
2571 .bitmask
= server
->attr_bitmask
,
2573 struct nfs_removeres res
= {
2576 struct rpc_message msg
= {
2577 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2581 int status
= -ENOMEM
;
2583 res
.dir_attr
= nfs_alloc_fattr();
2584 if (res
.dir_attr
== NULL
)
2587 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
2589 update_changeattr(dir
, &res
.cinfo
);
2590 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2592 nfs_free_fattr(res
.dir_attr
);
2597 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2599 struct nfs4_exception exception
= { };
2602 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2603 _nfs4_proc_remove(dir
, name
),
2605 } while (exception
.retry
);
2609 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2611 struct nfs_server
*server
= NFS_SERVER(dir
);
2612 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2613 struct nfs_removeres
*res
= msg
->rpc_resp
;
2615 args
->bitmask
= server
->cache_consistency_bitmask
;
2616 res
->server
= server
;
2617 res
->seq_res
.sr_slot
= NULL
;
2618 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2621 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2623 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2625 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2627 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2629 update_changeattr(dir
, &res
->cinfo
);
2630 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2634 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2636 struct nfs_server
*server
= NFS_SERVER(dir
);
2637 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2638 struct nfs_renameres
*res
= msg
->rpc_resp
;
2640 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2641 arg
->bitmask
= server
->attr_bitmask
;
2642 res
->server
= server
;
2645 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2646 struct inode
*new_dir
)
2648 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2650 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2652 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2655 update_changeattr(old_dir
, &res
->old_cinfo
);
2656 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2657 update_changeattr(new_dir
, &res
->new_cinfo
);
2658 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2662 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2663 struct inode
*new_dir
, struct qstr
*new_name
)
2665 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2666 struct nfs_renameargs arg
= {
2667 .old_dir
= NFS_FH(old_dir
),
2668 .new_dir
= NFS_FH(new_dir
),
2669 .old_name
= old_name
,
2670 .new_name
= new_name
,
2671 .bitmask
= server
->attr_bitmask
,
2673 struct nfs_renameres res
= {
2676 struct rpc_message msg
= {
2677 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2681 int status
= -ENOMEM
;
2683 res
.old_fattr
= nfs_alloc_fattr();
2684 res
.new_fattr
= nfs_alloc_fattr();
2685 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2688 status
= nfs4_call_sync(server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2690 update_changeattr(old_dir
, &res
.old_cinfo
);
2691 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2692 update_changeattr(new_dir
, &res
.new_cinfo
);
2693 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2696 nfs_free_fattr(res
.new_fattr
);
2697 nfs_free_fattr(res
.old_fattr
);
2701 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2702 struct inode
*new_dir
, struct qstr
*new_name
)
2704 struct nfs4_exception exception
= { };
2707 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2708 _nfs4_proc_rename(old_dir
, old_name
,
2711 } while (exception
.retry
);
2715 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2717 struct nfs_server
*server
= NFS_SERVER(inode
);
2718 struct nfs4_link_arg arg
= {
2719 .fh
= NFS_FH(inode
),
2720 .dir_fh
= NFS_FH(dir
),
2722 .bitmask
= server
->attr_bitmask
,
2724 struct nfs4_link_res res
= {
2727 struct rpc_message msg
= {
2728 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2732 int status
= -ENOMEM
;
2734 res
.fattr
= nfs_alloc_fattr();
2735 res
.dir_attr
= nfs_alloc_fattr();
2736 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2739 status
= nfs4_call_sync(server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2741 update_changeattr(dir
, &res
.cinfo
);
2742 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2743 nfs_post_op_update_inode(inode
, res
.fattr
);
2746 nfs_free_fattr(res
.dir_attr
);
2747 nfs_free_fattr(res
.fattr
);
2751 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2753 struct nfs4_exception exception
= { };
2756 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2757 _nfs4_proc_link(inode
, dir
, name
),
2759 } while (exception
.retry
);
2763 struct nfs4_createdata
{
2764 struct rpc_message msg
;
2765 struct nfs4_create_arg arg
;
2766 struct nfs4_create_res res
;
2768 struct nfs_fattr fattr
;
2769 struct nfs_fattr dir_fattr
;
2772 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2773 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2775 struct nfs4_createdata
*data
;
2777 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2779 struct nfs_server
*server
= NFS_SERVER(dir
);
2781 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2782 data
->msg
.rpc_argp
= &data
->arg
;
2783 data
->msg
.rpc_resp
= &data
->res
;
2784 data
->arg
.dir_fh
= NFS_FH(dir
);
2785 data
->arg
.server
= server
;
2786 data
->arg
.name
= name
;
2787 data
->arg
.attrs
= sattr
;
2788 data
->arg
.ftype
= ftype
;
2789 data
->arg
.bitmask
= server
->attr_bitmask
;
2790 data
->res
.server
= server
;
2791 data
->res
.fh
= &data
->fh
;
2792 data
->res
.fattr
= &data
->fattr
;
2793 data
->res
.dir_fattr
= &data
->dir_fattr
;
2794 nfs_fattr_init(data
->res
.fattr
);
2795 nfs_fattr_init(data
->res
.dir_fattr
);
2800 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2802 int status
= nfs4_call_sync(NFS_SERVER(dir
), &data
->msg
,
2803 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
2805 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2806 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2807 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2812 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2817 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2818 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2820 struct nfs4_createdata
*data
;
2821 int status
= -ENAMETOOLONG
;
2823 if (len
> NFS4_MAXPATHLEN
)
2827 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2831 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2832 data
->arg
.u
.symlink
.pages
= &page
;
2833 data
->arg
.u
.symlink
.len
= len
;
2835 status
= nfs4_do_create(dir
, dentry
, data
);
2837 nfs4_free_createdata(data
);
2842 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2843 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2845 struct nfs4_exception exception
= { };
2848 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2849 _nfs4_proc_symlink(dir
, dentry
, page
,
2852 } while (exception
.retry
);
2856 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2857 struct iattr
*sattr
)
2859 struct nfs4_createdata
*data
;
2860 int status
= -ENOMEM
;
2862 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2866 status
= nfs4_do_create(dir
, dentry
, data
);
2868 nfs4_free_createdata(data
);
2873 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2874 struct iattr
*sattr
)
2876 struct nfs4_exception exception
= { };
2879 sattr
->ia_mode
&= ~current_umask();
2881 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2882 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2884 } while (exception
.retry
);
2888 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2889 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2891 struct inode
*dir
= dentry
->d_inode
;
2892 struct nfs4_readdir_arg args
= {
2897 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2900 struct nfs4_readdir_res res
;
2901 struct rpc_message msg
= {
2902 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2909 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2910 dentry
->d_parent
->d_name
.name
,
2911 dentry
->d_name
.name
,
2912 (unsigned long long)cookie
);
2913 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2914 res
.pgbase
= args
.pgbase
;
2915 status
= nfs4_call_sync(NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2917 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2918 status
+= args
.pgbase
;
2921 nfs_invalidate_atime(dir
);
2923 dprintk("%s: returns %d\n", __func__
, status
);
2927 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2928 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2930 struct nfs4_exception exception
= { };
2933 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2934 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2935 pages
, count
, plus
),
2937 } while (exception
.retry
);
2941 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2942 struct iattr
*sattr
, dev_t rdev
)
2944 struct nfs4_createdata
*data
;
2945 int mode
= sattr
->ia_mode
;
2946 int status
= -ENOMEM
;
2948 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2949 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2951 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2956 data
->arg
.ftype
= NF4FIFO
;
2957 else if (S_ISBLK(mode
)) {
2958 data
->arg
.ftype
= NF4BLK
;
2959 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2960 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2962 else if (S_ISCHR(mode
)) {
2963 data
->arg
.ftype
= NF4CHR
;
2964 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2965 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2968 status
= nfs4_do_create(dir
, dentry
, data
);
2970 nfs4_free_createdata(data
);
2975 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2976 struct iattr
*sattr
, dev_t rdev
)
2978 struct nfs4_exception exception
= { };
2981 sattr
->ia_mode
&= ~current_umask();
2983 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2984 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2986 } while (exception
.retry
);
2990 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2991 struct nfs_fsstat
*fsstat
)
2993 struct nfs4_statfs_arg args
= {
2995 .bitmask
= server
->attr_bitmask
,
2997 struct nfs4_statfs_res res
= {
3000 struct rpc_message msg
= {
3001 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3006 nfs_fattr_init(fsstat
->fattr
);
3007 return nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3010 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3012 struct nfs4_exception exception
= { };
3015 err
= nfs4_handle_exception(server
,
3016 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3018 } while (exception
.retry
);
3022 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3023 struct nfs_fsinfo
*fsinfo
)
3025 struct nfs4_fsinfo_arg args
= {
3027 .bitmask
= server
->attr_bitmask
,
3029 struct nfs4_fsinfo_res res
= {
3032 struct rpc_message msg
= {
3033 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3038 return nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3041 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3043 struct nfs4_exception exception
= { };
3047 err
= nfs4_handle_exception(server
,
3048 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3050 } while (exception
.retry
);
3054 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3056 nfs_fattr_init(fsinfo
->fattr
);
3057 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3060 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3061 struct nfs_pathconf
*pathconf
)
3063 struct nfs4_pathconf_arg args
= {
3065 .bitmask
= server
->attr_bitmask
,
3067 struct nfs4_pathconf_res res
= {
3068 .pathconf
= pathconf
,
3070 struct rpc_message msg
= {
3071 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3076 /* None of the pathconf attributes are mandatory to implement */
3077 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3078 memset(pathconf
, 0, sizeof(*pathconf
));
3082 nfs_fattr_init(pathconf
->fattr
);
3083 return nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3086 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3087 struct nfs_pathconf
*pathconf
)
3089 struct nfs4_exception exception
= { };
3093 err
= nfs4_handle_exception(server
,
3094 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3096 } while (exception
.retry
);
3100 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3102 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3104 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3105 nfs_restart_rpc(task
, server
->nfs_client
);
3109 nfs_invalidate_atime(data
->inode
);
3110 if (task
->tk_status
> 0)
3111 renew_lease(server
, data
->timestamp
);
3115 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3118 dprintk("--> %s\n", __func__
);
3120 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3123 return data
->read_done_cb(task
, data
);
3126 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3128 data
->timestamp
= jiffies
;
3129 data
->read_done_cb
= nfs4_read_done_cb
;
3130 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3133 /* Reset the the nfs_read_data to send the read to the MDS. */
3134 void nfs4_reset_read(struct rpc_task
*task
, struct nfs_read_data
*data
)
3136 dprintk("%s Reset task for i/o through\n", __func__
);
3137 put_lseg(data
->lseg
);
3139 /* offsets will differ in the dense stripe case */
3140 data
->args
.offset
= data
->mds_offset
;
3141 data
->ds_clp
= NULL
;
3142 data
->args
.fh
= NFS_FH(data
->inode
);
3143 data
->read_done_cb
= nfs4_read_done_cb
;
3144 task
->tk_ops
= data
->mds_ops
;
3145 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3147 EXPORT_SYMBOL_GPL(nfs4_reset_read
);
3149 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3151 struct inode
*inode
= data
->inode
;
3153 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3154 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3157 if (task
->tk_status
>= 0) {
3158 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3159 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3164 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3166 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3168 return data
->write_done_cb(task
, data
);
3171 /* Reset the the nfs_write_data to send the write to the MDS. */
3172 void nfs4_reset_write(struct rpc_task
*task
, struct nfs_write_data
*data
)
3174 dprintk("%s Reset task for i/o through\n", __func__
);
3175 put_lseg(data
->lseg
);
3177 data
->ds_clp
= NULL
;
3178 data
->write_done_cb
= nfs4_write_done_cb
;
3179 data
->args
.fh
= NFS_FH(data
->inode
);
3180 data
->args
.bitmask
= data
->res
.server
->cache_consistency_bitmask
;
3181 data
->args
.offset
= data
->mds_offset
;
3182 data
->res
.fattr
= &data
->fattr
;
3183 task
->tk_ops
= data
->mds_ops
;
3184 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3186 EXPORT_SYMBOL_GPL(nfs4_reset_write
);
3188 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3190 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3193 data
->args
.bitmask
= NULL
;
3194 data
->res
.fattr
= NULL
;
3196 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3197 if (!data
->write_done_cb
)
3198 data
->write_done_cb
= nfs4_write_done_cb
;
3199 data
->res
.server
= server
;
3200 data
->timestamp
= jiffies
;
3202 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3205 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3207 struct inode
*inode
= data
->inode
;
3209 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3212 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3213 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3216 nfs_refresh_inode(inode
, data
->res
.fattr
);
3220 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3222 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3224 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3225 data
->res
.server
= server
;
3226 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3229 struct nfs4_renewdata
{
3230 struct nfs_client
*client
;
3231 unsigned long timestamp
;
3235 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3236 * standalone procedure for queueing an asynchronous RENEW.
3238 static void nfs4_renew_release(void *calldata
)
3240 struct nfs4_renewdata
*data
= calldata
;
3241 struct nfs_client
*clp
= data
->client
;
3243 if (atomic_read(&clp
->cl_count
) > 1)
3244 nfs4_schedule_state_renewal(clp
);
3245 nfs_put_client(clp
);
3249 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3251 struct nfs4_renewdata
*data
= calldata
;
3252 struct nfs_client
*clp
= data
->client
;
3253 unsigned long timestamp
= data
->timestamp
;
3255 if (task
->tk_status
< 0) {
3256 /* Unless we're shutting down, schedule state recovery! */
3257 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3258 nfs4_schedule_lease_recovery(clp
);
3261 do_renew_lease(clp
, timestamp
);
3264 static const struct rpc_call_ops nfs4_renew_ops
= {
3265 .rpc_call_done
= nfs4_renew_done
,
3266 .rpc_release
= nfs4_renew_release
,
3269 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3271 struct rpc_message msg
= {
3272 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3276 struct nfs4_renewdata
*data
;
3278 if (!atomic_inc_not_zero(&clp
->cl_count
))
3280 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
3284 data
->timestamp
= jiffies
;
3285 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3286 &nfs4_renew_ops
, data
);
3289 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3291 struct rpc_message msg
= {
3292 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3296 unsigned long now
= jiffies
;
3299 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3302 do_renew_lease(clp
, now
);
3306 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3308 return (server
->caps
& NFS_CAP_ACLS
)
3309 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3310 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3313 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3314 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3317 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3319 static void buf_to_pages(const void *buf
, size_t buflen
,
3320 struct page
**pages
, unsigned int *pgbase
)
3322 const void *p
= buf
;
3324 *pgbase
= offset_in_page(buf
);
3326 while (p
< buf
+ buflen
) {
3327 *(pages
++) = virt_to_page(p
);
3328 p
+= PAGE_CACHE_SIZE
;
3332 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3333 struct page
**pages
, unsigned int *pgbase
)
3335 struct page
*newpage
, **spages
;
3341 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3342 newpage
= alloc_page(GFP_KERNEL
);
3344 if (newpage
== NULL
)
3346 memcpy(page_address(newpage
), buf
, len
);
3351 } while (buflen
!= 0);
3357 __free_page(spages
[rc
-1]);
3361 struct nfs4_cached_acl
{
3367 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3369 struct nfs_inode
*nfsi
= NFS_I(inode
);
3371 spin_lock(&inode
->i_lock
);
3372 kfree(nfsi
->nfs4_acl
);
3373 nfsi
->nfs4_acl
= acl
;
3374 spin_unlock(&inode
->i_lock
);
3377 static void nfs4_zap_acl_attr(struct inode
*inode
)
3379 nfs4_set_cached_acl(inode
, NULL
);
3382 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3384 struct nfs_inode
*nfsi
= NFS_I(inode
);
3385 struct nfs4_cached_acl
*acl
;
3388 spin_lock(&inode
->i_lock
);
3389 acl
= nfsi
->nfs4_acl
;
3392 if (buf
== NULL
) /* user is just asking for length */
3394 if (acl
->cached
== 0)
3396 ret
= -ERANGE
; /* see getxattr(2) man page */
3397 if (acl
->len
> buflen
)
3399 memcpy(buf
, acl
->data
, acl
->len
);
3403 spin_unlock(&inode
->i_lock
);
3407 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3409 struct nfs4_cached_acl
*acl
;
3411 if (buf
&& acl_len
<= PAGE_SIZE
) {
3412 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3416 memcpy(acl
->data
, buf
, acl_len
);
3418 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3425 nfs4_set_cached_acl(inode
, acl
);
3428 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3430 struct page
*pages
[NFS4ACL_MAXPAGES
];
3431 struct nfs_getaclargs args
= {
3432 .fh
= NFS_FH(inode
),
3436 struct nfs_getaclres res
= {
3440 struct rpc_message msg
= {
3441 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3445 struct page
*localpage
= NULL
;
3448 if (buflen
< PAGE_SIZE
) {
3449 /* As long as we're doing a round trip to the server anyway,
3450 * let's be prepared for a page of acl data. */
3451 localpage
= alloc_page(GFP_KERNEL
);
3452 resp_buf
= page_address(localpage
);
3453 if (localpage
== NULL
)
3455 args
.acl_pages
[0] = localpage
;
3456 args
.acl_pgbase
= 0;
3457 args
.acl_len
= PAGE_SIZE
;
3460 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3462 ret
= nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3465 if (res
.acl_len
> args
.acl_len
)
3466 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3468 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3471 if (res
.acl_len
> buflen
)
3474 memcpy(buf
, resp_buf
, res
.acl_len
);
3479 __free_page(localpage
);
3483 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3485 struct nfs4_exception exception
= { };
3488 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3491 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3492 } while (exception
.retry
);
3496 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3498 struct nfs_server
*server
= NFS_SERVER(inode
);
3501 if (!nfs4_server_supports_acls(server
))
3503 ret
= nfs_revalidate_inode(server
, inode
);
3506 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3507 nfs_zap_acl_cache(inode
);
3508 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3511 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3514 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3516 struct nfs_server
*server
= NFS_SERVER(inode
);
3517 struct page
*pages
[NFS4ACL_MAXPAGES
];
3518 struct nfs_setaclargs arg
= {
3519 .fh
= NFS_FH(inode
),
3523 struct nfs_setaclres res
;
3524 struct rpc_message msg
= {
3525 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3531 if (!nfs4_server_supports_acls(server
))
3533 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3536 nfs_inode_return_delegation(inode
);
3537 ret
= nfs4_call_sync(server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3540 * Free each page after tx, so the only ref left is
3541 * held by the network stack
3544 put_page(pages
[i
-1]);
3547 * Acl update can result in inode attribute update.
3548 * so mark the attribute cache invalid.
3550 spin_lock(&inode
->i_lock
);
3551 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3552 spin_unlock(&inode
->i_lock
);
3553 nfs_access_zap_cache(inode
);
3554 nfs_zap_acl_cache(inode
);
3558 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3560 struct nfs4_exception exception
= { };
3563 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3564 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3566 } while (exception
.retry
);
3571 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3573 struct nfs_client
*clp
= server
->nfs_client
;
3575 if (task
->tk_status
>= 0)
3577 switch(task
->tk_status
) {
3578 case -NFS4ERR_ADMIN_REVOKED
:
3579 case -NFS4ERR_BAD_STATEID
:
3580 case -NFS4ERR_OPENMODE
:
3583 nfs4_schedule_stateid_recovery(server
, state
);
3584 goto wait_on_recovery
;
3585 case -NFS4ERR_STALE_STATEID
:
3586 case -NFS4ERR_STALE_CLIENTID
:
3587 case -NFS4ERR_EXPIRED
:
3588 nfs4_schedule_lease_recovery(clp
);
3589 goto wait_on_recovery
;
3590 #if defined(CONFIG_NFS_V4_1)
3591 case -NFS4ERR_BADSESSION
:
3592 case -NFS4ERR_BADSLOT
:
3593 case -NFS4ERR_BAD_HIGH_SLOT
:
3594 case -NFS4ERR_DEADSESSION
:
3595 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3596 case -NFS4ERR_SEQ_FALSE_RETRY
:
3597 case -NFS4ERR_SEQ_MISORDERED
:
3598 dprintk("%s ERROR %d, Reset session\n", __func__
,
3600 nfs4_schedule_session_recovery(clp
->cl_session
);
3601 task
->tk_status
= 0;
3603 #endif /* CONFIG_NFS_V4_1 */
3604 case -NFS4ERR_DELAY
:
3605 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3606 case -NFS4ERR_GRACE
:
3608 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3609 task
->tk_status
= 0;
3611 case -NFS4ERR_OLD_STATEID
:
3612 task
->tk_status
= 0;
3615 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3618 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3619 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3620 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3621 task
->tk_status
= 0;
3625 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3626 unsigned short port
, struct rpc_cred
*cred
,
3627 struct nfs4_setclientid_res
*res
)
3629 nfs4_verifier sc_verifier
;
3630 struct nfs4_setclientid setclientid
= {
3631 .sc_verifier
= &sc_verifier
,
3633 .sc_cb_ident
= clp
->cl_cb_ident
,
3635 struct rpc_message msg
= {
3636 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3637 .rpc_argp
= &setclientid
,
3645 p
= (__be32
*)sc_verifier
.data
;
3646 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3647 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3650 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3651 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3653 rpc_peeraddr2str(clp
->cl_rpcclient
,
3655 rpc_peeraddr2str(clp
->cl_rpcclient
,
3657 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3658 clp
->cl_id_uniquifier
);
3659 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3660 sizeof(setclientid
.sc_netid
),
3661 rpc_peeraddr2str(clp
->cl_rpcclient
,
3662 RPC_DISPLAY_NETID
));
3663 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3664 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3665 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3667 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3668 if (status
!= -NFS4ERR_CLID_INUSE
)
3673 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3675 if (++clp
->cl_id_uniquifier
== 0)
3681 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3682 struct nfs4_setclientid_res
*arg
,
3683 struct rpc_cred
*cred
)
3685 struct nfs_fsinfo fsinfo
;
3686 struct rpc_message msg
= {
3687 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3689 .rpc_resp
= &fsinfo
,
3696 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3698 spin_lock(&clp
->cl_lock
);
3699 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3700 clp
->cl_last_renewal
= now
;
3701 spin_unlock(&clp
->cl_lock
);
3706 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3707 struct nfs4_setclientid_res
*arg
,
3708 struct rpc_cred
*cred
)
3713 err
= _nfs4_proc_setclientid_confirm(clp
, arg
, cred
);
3717 case -NFS4ERR_RESOURCE
:
3718 /* The IBM lawyers misread another document! */
3719 case -NFS4ERR_DELAY
:
3720 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3726 struct nfs4_delegreturndata
{
3727 struct nfs4_delegreturnargs args
;
3728 struct nfs4_delegreturnres res
;
3730 nfs4_stateid stateid
;
3731 unsigned long timestamp
;
3732 struct nfs_fattr fattr
;
3736 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3738 struct nfs4_delegreturndata
*data
= calldata
;
3740 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3743 switch (task
->tk_status
) {
3744 case -NFS4ERR_STALE_STATEID
:
3745 case -NFS4ERR_EXPIRED
:
3747 renew_lease(data
->res
.server
, data
->timestamp
);
3750 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3752 nfs_restart_rpc(task
, data
->res
.server
->nfs_client
);
3756 data
->rpc_status
= task
->tk_status
;
3759 static void nfs4_delegreturn_release(void *calldata
)
3764 #if defined(CONFIG_NFS_V4_1)
3765 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3767 struct nfs4_delegreturndata
*d_data
;
3769 d_data
= (struct nfs4_delegreturndata
*)data
;
3771 if (nfs4_setup_sequence(d_data
->res
.server
,
3772 &d_data
->args
.seq_args
,
3773 &d_data
->res
.seq_res
, 1, task
))
3775 rpc_call_start(task
);
3777 #endif /* CONFIG_NFS_V4_1 */
3779 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3780 #if defined(CONFIG_NFS_V4_1)
3781 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3782 #endif /* CONFIG_NFS_V4_1 */
3783 .rpc_call_done
= nfs4_delegreturn_done
,
3784 .rpc_release
= nfs4_delegreturn_release
,
3787 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3789 struct nfs4_delegreturndata
*data
;
3790 struct nfs_server
*server
= NFS_SERVER(inode
);
3791 struct rpc_task
*task
;
3792 struct rpc_message msg
= {
3793 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3796 struct rpc_task_setup task_setup_data
= {
3797 .rpc_client
= server
->client
,
3798 .rpc_message
= &msg
,
3799 .callback_ops
= &nfs4_delegreturn_ops
,
3800 .flags
= RPC_TASK_ASYNC
,
3804 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3807 data
->args
.fhandle
= &data
->fh
;
3808 data
->args
.stateid
= &data
->stateid
;
3809 data
->args
.bitmask
= server
->attr_bitmask
;
3810 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3811 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3812 data
->res
.fattr
= &data
->fattr
;
3813 data
->res
.server
= server
;
3814 nfs_fattr_init(data
->res
.fattr
);
3815 data
->timestamp
= jiffies
;
3816 data
->rpc_status
= 0;
3818 task_setup_data
.callback_data
= data
;
3819 msg
.rpc_argp
= &data
->args
;
3820 msg
.rpc_resp
= &data
->res
;
3821 task
= rpc_run_task(&task_setup_data
);
3823 return PTR_ERR(task
);
3826 status
= nfs4_wait_for_completion_rpc_task(task
);
3829 status
= data
->rpc_status
;
3832 nfs_refresh_inode(inode
, &data
->fattr
);
3838 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3840 struct nfs_server
*server
= NFS_SERVER(inode
);
3841 struct nfs4_exception exception
= { };
3844 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3846 case -NFS4ERR_STALE_STATEID
:
3847 case -NFS4ERR_EXPIRED
:
3851 err
= nfs4_handle_exception(server
, err
, &exception
);
3852 } while (exception
.retry
);
3856 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3857 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3860 * sleep, with exponential backoff, and retry the LOCK operation.
3862 static unsigned long
3863 nfs4_set_lock_task_retry(unsigned long timeout
)
3865 schedule_timeout_killable(timeout
);
3867 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3868 return NFS4_LOCK_MAXTIMEOUT
;
3872 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3874 struct inode
*inode
= state
->inode
;
3875 struct nfs_server
*server
= NFS_SERVER(inode
);
3876 struct nfs_client
*clp
= server
->nfs_client
;
3877 struct nfs_lockt_args arg
= {
3878 .fh
= NFS_FH(inode
),
3881 struct nfs_lockt_res res
= {
3884 struct rpc_message msg
= {
3885 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3888 .rpc_cred
= state
->owner
->so_cred
,
3890 struct nfs4_lock_state
*lsp
;
3893 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3894 status
= nfs4_set_lock_state(state
, request
);
3897 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3898 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3899 arg
.lock_owner
.s_dev
= server
->s_dev
;
3900 status
= nfs4_call_sync(server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3903 request
->fl_type
= F_UNLCK
;
3905 case -NFS4ERR_DENIED
:
3908 request
->fl_ops
->fl_release_private(request
);
3913 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3915 struct nfs4_exception exception
= { };
3919 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3920 _nfs4_proc_getlk(state
, cmd
, request
),
3922 } while (exception
.retry
);
3926 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3929 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3931 res
= posix_lock_file_wait(file
, fl
);
3934 res
= flock_lock_file_wait(file
, fl
);
3942 struct nfs4_unlockdata
{
3943 struct nfs_locku_args arg
;
3944 struct nfs_locku_res res
;
3945 struct nfs4_lock_state
*lsp
;
3946 struct nfs_open_context
*ctx
;
3947 struct file_lock fl
;
3948 const struct nfs_server
*server
;
3949 unsigned long timestamp
;
3952 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3953 struct nfs_open_context
*ctx
,
3954 struct nfs4_lock_state
*lsp
,
3955 struct nfs_seqid
*seqid
)
3957 struct nfs4_unlockdata
*p
;
3958 struct inode
*inode
= lsp
->ls_state
->inode
;
3960 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
3963 p
->arg
.fh
= NFS_FH(inode
);
3965 p
->arg
.seqid
= seqid
;
3966 p
->res
.seqid
= seqid
;
3967 p
->arg
.stateid
= &lsp
->ls_stateid
;
3969 atomic_inc(&lsp
->ls_count
);
3970 /* Ensure we don't close file until we're done freeing locks! */
3971 p
->ctx
= get_nfs_open_context(ctx
);
3972 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3973 p
->server
= NFS_SERVER(inode
);
3977 static void nfs4_locku_release_calldata(void *data
)
3979 struct nfs4_unlockdata
*calldata
= data
;
3980 nfs_free_seqid(calldata
->arg
.seqid
);
3981 nfs4_put_lock_state(calldata
->lsp
);
3982 put_nfs_open_context(calldata
->ctx
);
3986 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3988 struct nfs4_unlockdata
*calldata
= data
;
3990 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
3992 switch (task
->tk_status
) {
3994 memcpy(calldata
->lsp
->ls_stateid
.data
,
3995 calldata
->res
.stateid
.data
,
3996 sizeof(calldata
->lsp
->ls_stateid
.data
));
3997 renew_lease(calldata
->server
, calldata
->timestamp
);
3999 case -NFS4ERR_BAD_STATEID
:
4000 case -NFS4ERR_OLD_STATEID
:
4001 case -NFS4ERR_STALE_STATEID
:
4002 case -NFS4ERR_EXPIRED
:
4005 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
4006 nfs_restart_rpc(task
,
4007 calldata
->server
->nfs_client
);
4011 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
4013 struct nfs4_unlockdata
*calldata
= data
;
4015 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
4017 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
4018 /* Note: exit _without_ running nfs4_locku_done */
4019 task
->tk_action
= NULL
;
4022 calldata
->timestamp
= jiffies
;
4023 if (nfs4_setup_sequence(calldata
->server
,
4024 &calldata
->arg
.seq_args
,
4025 &calldata
->res
.seq_res
, 1, task
))
4027 rpc_call_start(task
);
4030 static const struct rpc_call_ops nfs4_locku_ops
= {
4031 .rpc_call_prepare
= nfs4_locku_prepare
,
4032 .rpc_call_done
= nfs4_locku_done
,
4033 .rpc_release
= nfs4_locku_release_calldata
,
4036 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
4037 struct nfs_open_context
*ctx
,
4038 struct nfs4_lock_state
*lsp
,
4039 struct nfs_seqid
*seqid
)
4041 struct nfs4_unlockdata
*data
;
4042 struct rpc_message msg
= {
4043 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
4044 .rpc_cred
= ctx
->cred
,
4046 struct rpc_task_setup task_setup_data
= {
4047 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
4048 .rpc_message
= &msg
,
4049 .callback_ops
= &nfs4_locku_ops
,
4050 .workqueue
= nfsiod_workqueue
,
4051 .flags
= RPC_TASK_ASYNC
,
4054 /* Ensure this is an unlock - when canceling a lock, the
4055 * canceled lock is passed in, and it won't be an unlock.
4057 fl
->fl_type
= F_UNLCK
;
4059 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
4061 nfs_free_seqid(seqid
);
4062 return ERR_PTR(-ENOMEM
);
4065 msg
.rpc_argp
= &data
->arg
;
4066 msg
.rpc_resp
= &data
->res
;
4067 task_setup_data
.callback_data
= data
;
4068 return rpc_run_task(&task_setup_data
);
4071 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4073 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4074 struct nfs_seqid
*seqid
;
4075 struct nfs4_lock_state
*lsp
;
4076 struct rpc_task
*task
;
4078 unsigned char fl_flags
= request
->fl_flags
;
4080 status
= nfs4_set_lock_state(state
, request
);
4081 /* Unlock _before_ we do the RPC call */
4082 request
->fl_flags
|= FL_EXISTS
;
4083 down_read(&nfsi
->rwsem
);
4084 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4085 up_read(&nfsi
->rwsem
);
4088 up_read(&nfsi
->rwsem
);
4091 /* Is this a delegated lock? */
4092 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4094 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4095 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4099 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4100 status
= PTR_ERR(task
);
4103 status
= nfs4_wait_for_completion_rpc_task(task
);
4106 request
->fl_flags
= fl_flags
;
4110 struct nfs4_lockdata
{
4111 struct nfs_lock_args arg
;
4112 struct nfs_lock_res res
;
4113 struct nfs4_lock_state
*lsp
;
4114 struct nfs_open_context
*ctx
;
4115 struct file_lock fl
;
4116 unsigned long timestamp
;
4119 struct nfs_server
*server
;
4122 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4123 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4126 struct nfs4_lockdata
*p
;
4127 struct inode
*inode
= lsp
->ls_state
->inode
;
4128 struct nfs_server
*server
= NFS_SERVER(inode
);
4130 p
= kzalloc(sizeof(*p
), gfp_mask
);
4134 p
->arg
.fh
= NFS_FH(inode
);
4136 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4137 if (p
->arg
.open_seqid
== NULL
)
4139 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4140 if (p
->arg
.lock_seqid
== NULL
)
4141 goto out_free_seqid
;
4142 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4143 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4144 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4145 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4146 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4149 atomic_inc(&lsp
->ls_count
);
4150 p
->ctx
= get_nfs_open_context(ctx
);
4151 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4154 nfs_free_seqid(p
->arg
.open_seqid
);
4160 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4162 struct nfs4_lockdata
*data
= calldata
;
4163 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4165 dprintk("%s: begin!\n", __func__
);
4166 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4168 /* Do we need to do an open_to_lock_owner? */
4169 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4170 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4172 data
->arg
.open_stateid
= &state
->stateid
;
4173 data
->arg
.new_lock_owner
= 1;
4174 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4176 data
->arg
.new_lock_owner
= 0;
4177 data
->timestamp
= jiffies
;
4178 if (nfs4_setup_sequence(data
->server
,
4179 &data
->arg
.seq_args
,
4180 &data
->res
.seq_res
, 1, task
))
4182 rpc_call_start(task
);
4183 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4186 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4188 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4189 nfs4_lock_prepare(task
, calldata
);
4192 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4194 struct nfs4_lockdata
*data
= calldata
;
4196 dprintk("%s: begin!\n", __func__
);
4198 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4201 data
->rpc_status
= task
->tk_status
;
4202 if (data
->arg
.new_lock_owner
!= 0) {
4203 if (data
->rpc_status
== 0)
4204 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4208 if (data
->rpc_status
== 0) {
4209 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4210 sizeof(data
->lsp
->ls_stateid
.data
));
4211 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4212 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
4215 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4218 static void nfs4_lock_release(void *calldata
)
4220 struct nfs4_lockdata
*data
= calldata
;
4222 dprintk("%s: begin!\n", __func__
);
4223 nfs_free_seqid(data
->arg
.open_seqid
);
4224 if (data
->cancelled
!= 0) {
4225 struct rpc_task
*task
;
4226 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4227 data
->arg
.lock_seqid
);
4229 rpc_put_task_async(task
);
4230 dprintk("%s: cancelling lock!\n", __func__
);
4232 nfs_free_seqid(data
->arg
.lock_seqid
);
4233 nfs4_put_lock_state(data
->lsp
);
4234 put_nfs_open_context(data
->ctx
);
4236 dprintk("%s: done!\n", __func__
);
4239 static const struct rpc_call_ops nfs4_lock_ops
= {
4240 .rpc_call_prepare
= nfs4_lock_prepare
,
4241 .rpc_call_done
= nfs4_lock_done
,
4242 .rpc_release
= nfs4_lock_release
,
4245 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4246 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4247 .rpc_call_done
= nfs4_lock_done
,
4248 .rpc_release
= nfs4_lock_release
,
4251 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4254 case -NFS4ERR_ADMIN_REVOKED
:
4255 case -NFS4ERR_BAD_STATEID
:
4256 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4257 if (new_lock_owner
!= 0 ||
4258 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4259 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
4261 case -NFS4ERR_STALE_STATEID
:
4262 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4263 case -NFS4ERR_EXPIRED
:
4264 nfs4_schedule_lease_recovery(server
->nfs_client
);
4268 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4270 struct nfs4_lockdata
*data
;
4271 struct rpc_task
*task
;
4272 struct rpc_message msg
= {
4273 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4274 .rpc_cred
= state
->owner
->so_cred
,
4276 struct rpc_task_setup task_setup_data
= {
4277 .rpc_client
= NFS_CLIENT(state
->inode
),
4278 .rpc_message
= &msg
,
4279 .callback_ops
= &nfs4_lock_ops
,
4280 .workqueue
= nfsiod_workqueue
,
4281 .flags
= RPC_TASK_ASYNC
,
4285 dprintk("%s: begin!\n", __func__
);
4286 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4287 fl
->fl_u
.nfs4_fl
.owner
,
4288 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4292 data
->arg
.block
= 1;
4293 if (recovery_type
> NFS_LOCK_NEW
) {
4294 if (recovery_type
== NFS_LOCK_RECLAIM
)
4295 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4296 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4298 msg
.rpc_argp
= &data
->arg
;
4299 msg
.rpc_resp
= &data
->res
;
4300 task_setup_data
.callback_data
= data
;
4301 task
= rpc_run_task(&task_setup_data
);
4303 return PTR_ERR(task
);
4304 ret
= nfs4_wait_for_completion_rpc_task(task
);
4306 ret
= data
->rpc_status
;
4308 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4309 data
->arg
.new_lock_owner
, ret
);
4311 data
->cancelled
= 1;
4313 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4317 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4319 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4320 struct nfs4_exception exception
= { };
4324 /* Cache the lock if possible... */
4325 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4327 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4328 if (err
!= -NFS4ERR_DELAY
)
4330 nfs4_handle_exception(server
, err
, &exception
);
4331 } while (exception
.retry
);
4335 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4337 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4338 struct nfs4_exception exception
= { };
4341 err
= nfs4_set_lock_state(state
, request
);
4345 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4347 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4351 case -NFS4ERR_GRACE
:
4352 case -NFS4ERR_DELAY
:
4353 nfs4_handle_exception(server
, err
, &exception
);
4356 } while (exception
.retry
);
4361 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4363 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4364 unsigned char fl_flags
= request
->fl_flags
;
4365 int status
= -ENOLCK
;
4367 if ((fl_flags
& FL_POSIX
) &&
4368 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4370 /* Is this a delegated open? */
4371 status
= nfs4_set_lock_state(state
, request
);
4374 request
->fl_flags
|= FL_ACCESS
;
4375 status
= do_vfs_lock(request
->fl_file
, request
);
4378 down_read(&nfsi
->rwsem
);
4379 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4380 /* Yes: cache locks! */
4381 /* ...but avoid races with delegation recall... */
4382 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4383 status
= do_vfs_lock(request
->fl_file
, request
);
4386 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4389 /* Note: we always want to sleep here! */
4390 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4391 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4392 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4394 up_read(&nfsi
->rwsem
);
4396 request
->fl_flags
= fl_flags
;
4400 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4402 struct nfs4_exception exception
= { };
4406 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4407 if (err
== -NFS4ERR_DENIED
)
4409 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4411 } while (exception
.retry
);
4416 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4418 struct nfs_open_context
*ctx
;
4419 struct nfs4_state
*state
;
4420 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4423 /* verify open state */
4424 ctx
= nfs_file_open_context(filp
);
4427 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4430 if (IS_GETLK(cmd
)) {
4432 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4436 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4439 if (request
->fl_type
== F_UNLCK
) {
4441 return nfs4_proc_unlck(state
, cmd
, request
);
4448 status
= nfs4_proc_setlk(state
, cmd
, request
);
4449 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4451 timeout
= nfs4_set_lock_task_retry(timeout
);
4452 status
= -ERESTARTSYS
;
4455 } while(status
< 0);
4459 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4461 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4462 struct nfs4_exception exception
= { };
4465 err
= nfs4_set_lock_state(state
, fl
);
4469 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4472 printk(KERN_ERR
"%s: unhandled error %d.\n",
4477 case -NFS4ERR_EXPIRED
:
4478 case -NFS4ERR_STALE_CLIENTID
:
4479 case -NFS4ERR_STALE_STATEID
:
4480 nfs4_schedule_lease_recovery(server
->nfs_client
);
4482 case -NFS4ERR_BADSESSION
:
4483 case -NFS4ERR_BADSLOT
:
4484 case -NFS4ERR_BAD_HIGH_SLOT
:
4485 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4486 case -NFS4ERR_DEADSESSION
:
4487 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4491 * The show must go on: exit, but mark the
4492 * stateid as needing recovery.
4494 case -NFS4ERR_ADMIN_REVOKED
:
4495 case -NFS4ERR_BAD_STATEID
:
4496 case -NFS4ERR_OPENMODE
:
4497 nfs4_schedule_stateid_recovery(server
, state
);
4502 * User RPCSEC_GSS context has expired.
4503 * We cannot recover this stateid now, so
4504 * skip it and allow recovery thread to
4510 case -NFS4ERR_DENIED
:
4511 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4514 case -NFS4ERR_DELAY
:
4517 err
= nfs4_handle_exception(server
, err
, &exception
);
4518 } while (exception
.retry
);
4523 static void nfs4_release_lockowner_release(void *calldata
)
4528 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4529 .rpc_release
= nfs4_release_lockowner_release
,
4532 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4534 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4535 struct nfs_release_lockowner_args
*args
;
4536 struct rpc_message msg
= {
4537 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4540 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4542 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4545 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4546 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4547 args
->lock_owner
.s_dev
= server
->s_dev
;
4548 msg
.rpc_argp
= args
;
4549 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4552 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4554 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4555 const void *buf
, size_t buflen
,
4556 int flags
, int type
)
4558 if (strcmp(key
, "") != 0)
4561 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4564 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4565 void *buf
, size_t buflen
, int type
)
4567 if (strcmp(key
, "") != 0)
4570 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4573 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4574 size_t list_len
, const char *name
,
4575 size_t name_len
, int type
)
4577 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4579 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4582 if (list
&& len
<= list_len
)
4583 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4587 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4589 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4590 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4591 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4594 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4595 NFS_ATTR_FATTR_NLINK
;
4596 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4600 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4601 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4603 struct nfs_server
*server
= NFS_SERVER(dir
);
4605 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4606 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4608 struct nfs4_fs_locations_arg args
= {
4609 .dir_fh
= NFS_FH(dir
),
4614 struct nfs4_fs_locations_res res
= {
4615 .fs_locations
= fs_locations
,
4617 struct rpc_message msg
= {
4618 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4624 dprintk("%s: start\n", __func__
);
4625 nfs_fattr_init(&fs_locations
->fattr
);
4626 fs_locations
->server
= server
;
4627 fs_locations
->nlocations
= 0;
4628 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4629 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4630 dprintk("%s: returned status = %d\n", __func__
, status
);
4634 #ifdef CONFIG_NFS_V4_1
4636 * Check the exchange flags returned by the server for invalid flags, having
4637 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4640 static int nfs4_check_cl_exchange_flags(u32 flags
)
4642 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4644 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4645 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4647 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4651 return -NFS4ERR_INVAL
;
4655 * nfs4_proc_exchange_id()
4657 * Since the clientid has expired, all compounds using sessions
4658 * associated with the stale clientid will be returning
4659 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4660 * be in some phase of session reset.
4662 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4664 nfs4_verifier verifier
;
4665 struct nfs41_exchange_id_args args
= {
4667 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4669 struct nfs41_exchange_id_res res
= {
4673 struct rpc_message msg
= {
4674 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4681 dprintk("--> %s\n", __func__
);
4682 BUG_ON(clp
== NULL
);
4684 p
= (u32
*)verifier
.data
;
4685 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4686 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4687 args
.verifier
= &verifier
;
4689 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4692 init_utsname()->nodename
,
4693 init_utsname()->domainname
,
4694 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4696 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4698 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4699 dprintk("<-- %s status= %d\n", __func__
, status
);
4703 struct nfs4_get_lease_time_data
{
4704 struct nfs4_get_lease_time_args
*args
;
4705 struct nfs4_get_lease_time_res
*res
;
4706 struct nfs_client
*clp
;
4709 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4713 struct nfs4_get_lease_time_data
*data
=
4714 (struct nfs4_get_lease_time_data
*)calldata
;
4716 dprintk("--> %s\n", __func__
);
4717 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4718 /* just setup sequence, do not trigger session recovery
4719 since we're invoked within one */
4720 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4721 &data
->args
->la_seq_args
,
4722 &data
->res
->lr_seq_res
, 0, task
);
4724 BUG_ON(ret
== -EAGAIN
);
4725 rpc_call_start(task
);
4726 dprintk("<-- %s\n", __func__
);
4730 * Called from nfs4_state_manager thread for session setup, so don't recover
4731 * from sequence operation or clientid errors.
4733 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4735 struct nfs4_get_lease_time_data
*data
=
4736 (struct nfs4_get_lease_time_data
*)calldata
;
4738 dprintk("--> %s\n", __func__
);
4739 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4741 switch (task
->tk_status
) {
4742 case -NFS4ERR_DELAY
:
4743 case -NFS4ERR_GRACE
:
4744 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4745 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4746 task
->tk_status
= 0;
4747 nfs_restart_rpc(task
, data
->clp
);
4750 dprintk("<-- %s\n", __func__
);
4753 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4754 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4755 .rpc_call_done
= nfs4_get_lease_time_done
,
4758 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4760 struct rpc_task
*task
;
4761 struct nfs4_get_lease_time_args args
;
4762 struct nfs4_get_lease_time_res res
= {
4763 .lr_fsinfo
= fsinfo
,
4765 struct nfs4_get_lease_time_data data
= {
4770 struct rpc_message msg
= {
4771 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4775 struct rpc_task_setup task_setup
= {
4776 .rpc_client
= clp
->cl_rpcclient
,
4777 .rpc_message
= &msg
,
4778 .callback_ops
= &nfs4_get_lease_time_ops
,
4779 .callback_data
= &data
4783 dprintk("--> %s\n", __func__
);
4784 task
= rpc_run_task(&task_setup
);
4787 status
= PTR_ERR(task
);
4789 status
= task
->tk_status
;
4792 dprintk("<-- %s return %d\n", __func__
, status
);
4798 * Reset a slot table
4800 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
4803 struct nfs4_slot
*new = NULL
;
4807 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
4808 max_reqs
, tbl
->max_slots
);
4810 /* Does the newly negotiated max_reqs match the existing slot table? */
4811 if (max_reqs
!= tbl
->max_slots
) {
4813 new = kmalloc(max_reqs
* sizeof(struct nfs4_slot
),
4820 spin_lock(&tbl
->slot_tbl_lock
);
4823 tbl
->max_slots
= max_reqs
;
4825 for (i
= 0; i
< tbl
->max_slots
; ++i
)
4826 tbl
->slots
[i
].seq_nr
= ivalue
;
4827 spin_unlock(&tbl
->slot_tbl_lock
);
4828 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4829 tbl
, tbl
->slots
, tbl
->max_slots
);
4831 dprintk("<-- %s: return %d\n", __func__
, ret
);
4836 * Reset the forechannel and backchannel slot tables
4838 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4842 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4843 session
->fc_attrs
.max_reqs
, 1);
4847 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4848 session
->bc_attrs
.max_reqs
, 0);
4852 /* Destroy the slot table */
4853 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4855 if (session
->fc_slot_table
.slots
!= NULL
) {
4856 kfree(session
->fc_slot_table
.slots
);
4857 session
->fc_slot_table
.slots
= NULL
;
4859 if (session
->bc_slot_table
.slots
!= NULL
) {
4860 kfree(session
->bc_slot_table
.slots
);
4861 session
->bc_slot_table
.slots
= NULL
;
4867 * Initialize slot table
4869 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4870 int max_slots
, int ivalue
)
4872 struct nfs4_slot
*slot
;
4875 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4877 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4879 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_NOFS
);
4884 spin_lock(&tbl
->slot_tbl_lock
);
4885 tbl
->max_slots
= max_slots
;
4887 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4888 spin_unlock(&tbl
->slot_tbl_lock
);
4889 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4890 tbl
, tbl
->slots
, tbl
->max_slots
);
4892 dprintk("<-- %s: return %d\n", __func__
, ret
);
4897 * Initialize the forechannel and backchannel tables
4899 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4901 struct nfs4_slot_table
*tbl
;
4904 tbl
= &session
->fc_slot_table
;
4905 if (tbl
->slots
== NULL
) {
4906 status
= nfs4_init_slot_table(tbl
,
4907 session
->fc_attrs
.max_reqs
, 1);
4912 tbl
= &session
->bc_slot_table
;
4913 if (tbl
->slots
== NULL
) {
4914 status
= nfs4_init_slot_table(tbl
,
4915 session
->bc_attrs
.max_reqs
, 0);
4917 nfs4_destroy_slot_tables(session
);
4923 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
4925 struct nfs4_session
*session
;
4926 struct nfs4_slot_table
*tbl
;
4928 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
4932 tbl
= &session
->fc_slot_table
;
4933 tbl
->highest_used_slotid
= -1;
4934 spin_lock_init(&tbl
->slot_tbl_lock
);
4935 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
4936 init_completion(&tbl
->complete
);
4938 tbl
= &session
->bc_slot_table
;
4939 tbl
->highest_used_slotid
= -1;
4940 spin_lock_init(&tbl
->slot_tbl_lock
);
4941 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
4942 init_completion(&tbl
->complete
);
4944 session
->session_state
= 1<<NFS4_SESSION_INITING
;
4950 void nfs4_destroy_session(struct nfs4_session
*session
)
4952 nfs4_proc_destroy_session(session
);
4953 dprintk("%s Destroy backchannel for xprt %p\n",
4954 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
4955 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
4956 NFS41_BC_MIN_CALLBACKS
);
4957 nfs4_destroy_slot_tables(session
);
4962 * Initialize the values to be used by the client in CREATE_SESSION
4963 * If nfs4_init_session set the fore channel request and response sizes,
4966 * Set the back channel max_resp_sz_cached to zero to force the client to
4967 * always set csa_cachethis to FALSE because the current implementation
4968 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4970 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
4972 struct nfs4_session
*session
= args
->client
->cl_session
;
4973 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
4974 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
4977 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
4979 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
4980 /* Fore channel attributes */
4981 args
->fc_attrs
.headerpadsz
= 0;
4982 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
4983 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
4984 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
4985 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
4987 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4988 "max_ops=%u max_reqs=%u\n",
4990 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
4991 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
4993 /* Back channel attributes */
4994 args
->bc_attrs
.headerpadsz
= 0;
4995 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
4996 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
4997 args
->bc_attrs
.max_resp_sz_cached
= 0;
4998 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
4999 args
->bc_attrs
.max_reqs
= 1;
5001 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5002 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5004 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
5005 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
5006 args
->bc_attrs
.max_reqs
);
5009 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5011 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
5012 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
5014 if (rcvd
->headerpadsz
> sent
->headerpadsz
)
5016 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
5019 * Our requested max_ops is the minimum we need; we're not
5020 * prepared to break up compounds into smaller pieces than that.
5021 * So, no point even trying to continue if the server won't
5024 if (rcvd
->max_ops
< sent
->max_ops
)
5026 if (rcvd
->max_reqs
== 0)
5031 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5033 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
5034 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
5036 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
5038 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
5040 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
5042 /* These would render the backchannel useless: */
5043 if (rcvd
->max_ops
== 0)
5045 if (rcvd
->max_reqs
== 0)
5050 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
5051 struct nfs4_session
*session
)
5055 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
5058 return nfs4_verify_back_channel_attrs(args
, session
);
5061 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
5063 struct nfs4_session
*session
= clp
->cl_session
;
5064 struct nfs41_create_session_args args
= {
5066 .cb_program
= NFS4_CALLBACK
,
5068 struct nfs41_create_session_res res
= {
5071 struct rpc_message msg
= {
5072 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5078 nfs4_init_channel_attrs(&args
);
5079 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5081 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5084 /* Verify the session's negotiated channel_attrs values */
5085 status
= nfs4_verify_channel_attrs(&args
, session
);
5087 /* Increment the clientid slot sequence id */
5095 * Issues a CREATE_SESSION operation to the server.
5096 * It is the responsibility of the caller to verify the session is
5097 * expired before calling this routine.
5099 int nfs4_proc_create_session(struct nfs_client
*clp
)
5103 struct nfs4_session
*session
= clp
->cl_session
;
5107 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5110 status
= _nfs4_proc_create_session(clp
);
5111 if (status
== -NFS4ERR_DELAY
) {
5112 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
5116 } while (status
== -NFS4ERR_DELAY
);
5121 /* Init and reset the fore channel */
5122 status
= nfs4_init_slot_tables(session
);
5123 dprintk("slot table initialization returned %d\n", status
);
5126 status
= nfs4_reset_slot_tables(session
);
5127 dprintk("slot table reset returned %d\n", status
);
5131 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5132 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5133 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5135 dprintk("<-- %s\n", __func__
);
5140 * Issue the over-the-wire RPC DESTROY_SESSION.
5141 * The caller must serialize access to this routine.
5143 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5146 struct rpc_message msg
;
5148 dprintk("--> nfs4_proc_destroy_session\n");
5150 /* session is still being setup */
5151 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5154 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5155 msg
.rpc_argp
= session
;
5156 msg
.rpc_resp
= NULL
;
5157 msg
.rpc_cred
= NULL
;
5158 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5162 "Got error %d from the server on DESTROY_SESSION. "
5163 "Session has been destroyed regardless...\n", status
);
5165 dprintk("<-- nfs4_proc_destroy_session\n");
5169 int nfs4_init_session(struct nfs_server
*server
)
5171 struct nfs_client
*clp
= server
->nfs_client
;
5172 struct nfs4_session
*session
;
5173 unsigned int rsize
, wsize
;
5176 if (!nfs4_has_session(clp
))
5179 session
= clp
->cl_session
;
5180 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5183 rsize
= server
->rsize
;
5185 rsize
= NFS_MAX_FILE_IO_SIZE
;
5186 wsize
= server
->wsize
;
5188 wsize
= NFS_MAX_FILE_IO_SIZE
;
5190 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5191 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5193 ret
= nfs4_recover_expired_lease(server
);
5195 ret
= nfs4_check_client_ready(clp
);
5199 int nfs4_init_ds_session(struct nfs_client
*clp
)
5201 struct nfs4_session
*session
= clp
->cl_session
;
5204 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5207 ret
= nfs4_client_recover_expired_lease(clp
);
5209 /* Test for the DS role */
5210 if (!is_ds_client(clp
))
5213 ret
= nfs4_check_client_ready(clp
);
5217 EXPORT_SYMBOL_GPL(nfs4_init_ds_session
);
5221 * Renew the cl_session lease.
5223 struct nfs4_sequence_data
{
5224 struct nfs_client
*clp
;
5225 struct nfs4_sequence_args args
;
5226 struct nfs4_sequence_res res
;
5229 static void nfs41_sequence_release(void *data
)
5231 struct nfs4_sequence_data
*calldata
= data
;
5232 struct nfs_client
*clp
= calldata
->clp
;
5234 if (atomic_read(&clp
->cl_count
) > 1)
5235 nfs4_schedule_state_renewal(clp
);
5236 nfs_put_client(clp
);
5240 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5242 switch(task
->tk_status
) {
5243 case -NFS4ERR_DELAY
:
5244 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5247 nfs4_schedule_lease_recovery(clp
);
5252 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5254 struct nfs4_sequence_data
*calldata
= data
;
5255 struct nfs_client
*clp
= calldata
->clp
;
5257 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5260 if (task
->tk_status
< 0) {
5261 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5262 if (atomic_read(&clp
->cl_count
) == 1)
5265 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5266 rpc_restart_call_prepare(task
);
5270 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5272 dprintk("<-- %s\n", __func__
);
5275 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5277 struct nfs4_sequence_data
*calldata
= data
;
5278 struct nfs_client
*clp
= calldata
->clp
;
5279 struct nfs4_sequence_args
*args
;
5280 struct nfs4_sequence_res
*res
;
5282 args
= task
->tk_msg
.rpc_argp
;
5283 res
= task
->tk_msg
.rpc_resp
;
5285 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5287 rpc_call_start(task
);
5290 static const struct rpc_call_ops nfs41_sequence_ops
= {
5291 .rpc_call_done
= nfs41_sequence_call_done
,
5292 .rpc_call_prepare
= nfs41_sequence_prepare
,
5293 .rpc_release
= nfs41_sequence_release
,
5296 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5298 struct nfs4_sequence_data
*calldata
;
5299 struct rpc_message msg
= {
5300 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5303 struct rpc_task_setup task_setup_data
= {
5304 .rpc_client
= clp
->cl_rpcclient
,
5305 .rpc_message
= &msg
,
5306 .callback_ops
= &nfs41_sequence_ops
,
5307 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5310 if (!atomic_inc_not_zero(&clp
->cl_count
))
5311 return ERR_PTR(-EIO
);
5312 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5313 if (calldata
== NULL
) {
5314 nfs_put_client(clp
);
5315 return ERR_PTR(-ENOMEM
);
5317 msg
.rpc_argp
= &calldata
->args
;
5318 msg
.rpc_resp
= &calldata
->res
;
5319 calldata
->clp
= clp
;
5320 task_setup_data
.callback_data
= calldata
;
5322 return rpc_run_task(&task_setup_data
);
5325 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5327 struct rpc_task
*task
;
5330 task
= _nfs41_proc_sequence(clp
, cred
);
5332 ret
= PTR_ERR(task
);
5334 rpc_put_task_async(task
);
5335 dprintk("<-- %s status=%d\n", __func__
, ret
);
5339 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5341 struct rpc_task
*task
;
5344 task
= _nfs41_proc_sequence(clp
, cred
);
5346 ret
= PTR_ERR(task
);
5349 ret
= rpc_wait_for_completion_task(task
);
5351 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
5353 if (task
->tk_status
== 0)
5354 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
5355 ret
= task
->tk_status
;
5359 dprintk("<-- %s status=%d\n", __func__
, ret
);
5363 struct nfs4_reclaim_complete_data
{
5364 struct nfs_client
*clp
;
5365 struct nfs41_reclaim_complete_args arg
;
5366 struct nfs41_reclaim_complete_res res
;
5369 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5371 struct nfs4_reclaim_complete_data
*calldata
= data
;
5373 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5374 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5375 &calldata
->arg
.seq_args
,
5376 &calldata
->res
.seq_res
, 0, task
))
5379 rpc_call_start(task
);
5382 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5384 switch(task
->tk_status
) {
5386 case -NFS4ERR_COMPLETE_ALREADY
:
5387 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5389 case -NFS4ERR_DELAY
:
5390 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5393 nfs4_schedule_lease_recovery(clp
);
5398 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5400 struct nfs4_reclaim_complete_data
*calldata
= data
;
5401 struct nfs_client
*clp
= calldata
->clp
;
5402 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5404 dprintk("--> %s\n", __func__
);
5405 if (!nfs41_sequence_done(task
, res
))
5408 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5409 rpc_restart_call_prepare(task
);
5412 dprintk("<-- %s\n", __func__
);
5415 static void nfs4_free_reclaim_complete_data(void *data
)
5417 struct nfs4_reclaim_complete_data
*calldata
= data
;
5422 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5423 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5424 .rpc_call_done
= nfs4_reclaim_complete_done
,
5425 .rpc_release
= nfs4_free_reclaim_complete_data
,
5429 * Issue a global reclaim complete.
5431 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5433 struct nfs4_reclaim_complete_data
*calldata
;
5434 struct rpc_task
*task
;
5435 struct rpc_message msg
= {
5436 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5438 struct rpc_task_setup task_setup_data
= {
5439 .rpc_client
= clp
->cl_rpcclient
,
5440 .rpc_message
= &msg
,
5441 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5442 .flags
= RPC_TASK_ASYNC
,
5444 int status
= -ENOMEM
;
5446 dprintk("--> %s\n", __func__
);
5447 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5448 if (calldata
== NULL
)
5450 calldata
->clp
= clp
;
5451 calldata
->arg
.one_fs
= 0;
5453 msg
.rpc_argp
= &calldata
->arg
;
5454 msg
.rpc_resp
= &calldata
->res
;
5455 task_setup_data
.callback_data
= calldata
;
5456 task
= rpc_run_task(&task_setup_data
);
5458 status
= PTR_ERR(task
);
5461 status
= nfs4_wait_for_completion_rpc_task(task
);
5463 status
= task
->tk_status
;
5467 dprintk("<-- %s status=%d\n", __func__
, status
);
5472 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5474 struct nfs4_layoutget
*lgp
= calldata
;
5475 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5477 dprintk("--> %s\n", __func__
);
5478 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5479 * right now covering the LAYOUTGET we are about to send.
5480 * However, that is not so catastrophic, and there seems
5481 * to be no way to prevent it completely.
5483 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5484 &lgp
->res
.seq_res
, 0, task
))
5486 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5487 NFS_I(lgp
->args
.inode
)->layout
,
5488 lgp
->args
.ctx
->state
)) {
5489 rpc_exit(task
, NFS4_OK
);
5492 rpc_call_start(task
);
5495 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5497 struct nfs4_layoutget
*lgp
= calldata
;
5498 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5500 dprintk("--> %s\n", __func__
);
5502 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5505 switch (task
->tk_status
) {
5508 case -NFS4ERR_LAYOUTTRYLATER
:
5509 case -NFS4ERR_RECALLCONFLICT
:
5510 task
->tk_status
= -NFS4ERR_DELAY
;
5513 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5514 rpc_restart_call_prepare(task
);
5518 dprintk("<-- %s\n", __func__
);
5521 static void nfs4_layoutget_release(void *calldata
)
5523 struct nfs4_layoutget
*lgp
= calldata
;
5525 dprintk("--> %s\n", __func__
);
5526 if (lgp
->res
.layout
.buf
!= NULL
)
5527 free_page((unsigned long) lgp
->res
.layout
.buf
);
5528 put_nfs_open_context(lgp
->args
.ctx
);
5530 dprintk("<-- %s\n", __func__
);
5533 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5534 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5535 .rpc_call_done
= nfs4_layoutget_done
,
5536 .rpc_release
= nfs4_layoutget_release
,
5539 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5541 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5542 struct rpc_task
*task
;
5543 struct rpc_message msg
= {
5544 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5545 .rpc_argp
= &lgp
->args
,
5546 .rpc_resp
= &lgp
->res
,
5548 struct rpc_task_setup task_setup_data
= {
5549 .rpc_client
= server
->client
,
5550 .rpc_message
= &msg
,
5551 .callback_ops
= &nfs4_layoutget_call_ops
,
5552 .callback_data
= lgp
,
5553 .flags
= RPC_TASK_ASYNC
,
5557 dprintk("--> %s\n", __func__
);
5559 lgp
->res
.layout
.buf
= (void *)__get_free_page(GFP_NOFS
);
5560 if (lgp
->res
.layout
.buf
== NULL
) {
5561 nfs4_layoutget_release(lgp
);
5565 lgp
->res
.seq_res
.sr_slot
= NULL
;
5566 task
= rpc_run_task(&task_setup_data
);
5568 return PTR_ERR(task
);
5569 status
= nfs4_wait_for_completion_rpc_task(task
);
5571 status
= task
->tk_status
;
5573 status
= pnfs_layout_process(lgp
);
5575 dprintk("<-- %s status=%d\n", __func__
, status
);
5580 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5582 struct nfs4_getdeviceinfo_args args
= {
5585 struct nfs4_getdeviceinfo_res res
= {
5588 struct rpc_message msg
= {
5589 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5595 dprintk("--> %s\n", __func__
);
5596 status
= nfs4_call_sync(server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5597 dprintk("<-- %s status=%d\n", __func__
, status
);
5602 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5604 struct nfs4_exception exception
= { };
5608 err
= nfs4_handle_exception(server
,
5609 _nfs4_proc_getdeviceinfo(server
, pdev
),
5611 } while (exception
.retry
);
5614 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5616 #endif /* CONFIG_NFS_V4_1 */
5618 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
5619 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5620 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5621 .recover_open
= nfs4_open_reclaim
,
5622 .recover_lock
= nfs4_lock_reclaim
,
5623 .establish_clid
= nfs4_init_clientid
,
5624 .get_clid_cred
= nfs4_get_setclientid_cred
,
5627 #if defined(CONFIG_NFS_V4_1)
5628 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
5629 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5630 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5631 .recover_open
= nfs4_open_reclaim
,
5632 .recover_lock
= nfs4_lock_reclaim
,
5633 .establish_clid
= nfs41_init_clientid
,
5634 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5635 .reclaim_complete
= nfs41_proc_reclaim_complete
,
5637 #endif /* CONFIG_NFS_V4_1 */
5639 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
5640 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5641 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5642 .recover_open
= nfs4_open_expired
,
5643 .recover_lock
= nfs4_lock_expired
,
5644 .establish_clid
= nfs4_init_clientid
,
5645 .get_clid_cred
= nfs4_get_setclientid_cred
,
5648 #if defined(CONFIG_NFS_V4_1)
5649 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
5650 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5651 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5652 .recover_open
= nfs4_open_expired
,
5653 .recover_lock
= nfs4_lock_expired
,
5654 .establish_clid
= nfs41_init_clientid
,
5655 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5657 #endif /* CONFIG_NFS_V4_1 */
5659 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
5660 .sched_state_renewal
= nfs4_proc_async_renew
,
5661 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
5662 .renew_lease
= nfs4_proc_renew
,
5665 #if defined(CONFIG_NFS_V4_1)
5666 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
5667 .sched_state_renewal
= nfs41_proc_async_sequence
,
5668 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
5669 .renew_lease
= nfs4_proc_sequence
,
5673 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
5675 .call_sync
= _nfs4_call_sync
,
5676 .validate_stateid
= nfs4_validate_delegation_stateid
,
5677 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
5678 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
5679 .state_renewal_ops
= &nfs40_state_renewal_ops
,
5682 #if defined(CONFIG_NFS_V4_1)
5683 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
5685 .call_sync
= _nfs4_call_sync_session
,
5686 .validate_stateid
= nfs41_validate_delegation_stateid
,
5687 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
5688 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
5689 .state_renewal_ops
= &nfs41_state_renewal_ops
,
5693 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
5694 [0] = &nfs_v4_0_minor_ops
,
5695 #if defined(CONFIG_NFS_V4_1)
5696 [1] = &nfs_v4_1_minor_ops
,
5700 static const struct inode_operations nfs4_file_inode_operations
= {
5701 .permission
= nfs_permission
,
5702 .getattr
= nfs_getattr
,
5703 .setattr
= nfs_setattr
,
5704 .getxattr
= generic_getxattr
,
5705 .setxattr
= generic_setxattr
,
5706 .listxattr
= generic_listxattr
,
5707 .removexattr
= generic_removexattr
,
5710 const struct nfs_rpc_ops nfs_v4_clientops
= {
5711 .version
= 4, /* protocol version */
5712 .dentry_ops
= &nfs4_dentry_operations
,
5713 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5714 .file_inode_ops
= &nfs4_file_inode_operations
,
5715 .getroot
= nfs4_proc_get_root
,
5716 .getattr
= nfs4_proc_getattr
,
5717 .setattr
= nfs4_proc_setattr
,
5718 .lookupfh
= nfs4_proc_lookupfh
,
5719 .lookup
= nfs4_proc_lookup
,
5720 .access
= nfs4_proc_access
,
5721 .readlink
= nfs4_proc_readlink
,
5722 .create
= nfs4_proc_create
,
5723 .remove
= nfs4_proc_remove
,
5724 .unlink_setup
= nfs4_proc_unlink_setup
,
5725 .unlink_done
= nfs4_proc_unlink_done
,
5726 .rename
= nfs4_proc_rename
,
5727 .rename_setup
= nfs4_proc_rename_setup
,
5728 .rename_done
= nfs4_proc_rename_done
,
5729 .link
= nfs4_proc_link
,
5730 .symlink
= nfs4_proc_symlink
,
5731 .mkdir
= nfs4_proc_mkdir
,
5732 .rmdir
= nfs4_proc_remove
,
5733 .readdir
= nfs4_proc_readdir
,
5734 .mknod
= nfs4_proc_mknod
,
5735 .statfs
= nfs4_proc_statfs
,
5736 .fsinfo
= nfs4_proc_fsinfo
,
5737 .pathconf
= nfs4_proc_pathconf
,
5738 .set_capabilities
= nfs4_server_capabilities
,
5739 .decode_dirent
= nfs4_decode_dirent
,
5740 .read_setup
= nfs4_proc_read_setup
,
5741 .read_done
= nfs4_read_done
,
5742 .write_setup
= nfs4_proc_write_setup
,
5743 .write_done
= nfs4_write_done
,
5744 .commit_setup
= nfs4_proc_commit_setup
,
5745 .commit_done
= nfs4_commit_done
,
5746 .lock
= nfs4_proc_lock
,
5747 .clear_acl_cache
= nfs4_zap_acl_attr
,
5748 .close_context
= nfs4_close_context
,
5749 .open_context
= nfs4_atomic_open
,
5750 .init_client
= nfs4_init_client
,
5753 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
5754 .prefix
= XATTR_NAME_NFSV4_ACL
,
5755 .list
= nfs4_xattr_list_nfs4_acl
,
5756 .get
= nfs4_xattr_get_nfs4_acl
,
5757 .set
= nfs4_xattr_set_nfs4_acl
,
5760 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
5761 &nfs4_xattr_nfs4_acl_handler
,