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/sunrpc/gss_api.h>
45 #include <linux/nfs.h>
46 #include <linux/nfs4.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/nfs_page.h>
49 #include <linux/nfs_mount.h>
50 #include <linux/namei.h>
51 #include <linux/mount.h>
52 #include <linux/module.h>
53 #include <linux/sunrpc/bc_xprt.h>
54 #include <linux/xattr.h>
55 #include <linux/utsname.h>
58 #include "delegation.h"
64 #define NFSDBG_FACILITY NFSDBG_PROC
66 #define NFS4_POLL_RETRY_MIN (HZ/10)
67 #define NFS4_POLL_RETRY_MAX (15*HZ)
69 #define NFS4_MAX_LOOP_ON_RECOVER (10)
72 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
73 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
74 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
75 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
76 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
77 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
78 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
79 struct nfs4_state
*state
);
80 #ifdef CONFIG_NFS_V4_1
81 static int nfs41_test_stateid(struct nfs_server
*, struct nfs4_state
*);
82 static int nfs41_free_stateid(struct nfs_server
*, struct nfs4_state
*);
84 /* Prevent leaks of NFSv4 errors into userland */
85 static int nfs4_map_errors(int err
)
90 case -NFS4ERR_RESOURCE
:
92 case -NFS4ERR_WRONGSEC
:
94 case -NFS4ERR_BADOWNER
:
95 case -NFS4ERR_BADNAME
:
98 dprintk("%s could not handle NFSv4 error %d\n",
106 * This is our standard bitmap for GETATTR requests.
108 const u32 nfs4_fattr_bitmap
[2] = {
110 | FATTR4_WORD0_CHANGE
113 | FATTR4_WORD0_FILEID
,
115 | FATTR4_WORD1_NUMLINKS
117 | FATTR4_WORD1_OWNER_GROUP
118 | FATTR4_WORD1_RAWDEV
119 | FATTR4_WORD1_SPACE_USED
120 | FATTR4_WORD1_TIME_ACCESS
121 | FATTR4_WORD1_TIME_METADATA
122 | FATTR4_WORD1_TIME_MODIFY
125 const u32 nfs4_statfs_bitmap
[2] = {
126 FATTR4_WORD0_FILES_AVAIL
127 | FATTR4_WORD0_FILES_FREE
128 | FATTR4_WORD0_FILES_TOTAL
,
129 FATTR4_WORD1_SPACE_AVAIL
130 | FATTR4_WORD1_SPACE_FREE
131 | FATTR4_WORD1_SPACE_TOTAL
134 const u32 nfs4_pathconf_bitmap
[2] = {
136 | FATTR4_WORD0_MAXNAME
,
140 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
141 | FATTR4_WORD0_MAXREAD
142 | FATTR4_WORD0_MAXWRITE
143 | FATTR4_WORD0_LEASE_TIME
,
144 FATTR4_WORD1_TIME_DELTA
145 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
146 FATTR4_WORD2_LAYOUT_BLKSIZE
149 const u32 nfs4_fs_locations_bitmap
[2] = {
151 | FATTR4_WORD0_CHANGE
154 | FATTR4_WORD0_FILEID
155 | FATTR4_WORD0_FS_LOCATIONS
,
157 | FATTR4_WORD1_NUMLINKS
159 | FATTR4_WORD1_OWNER_GROUP
160 | FATTR4_WORD1_RAWDEV
161 | FATTR4_WORD1_SPACE_USED
162 | FATTR4_WORD1_TIME_ACCESS
163 | FATTR4_WORD1_TIME_METADATA
164 | FATTR4_WORD1_TIME_MODIFY
165 | FATTR4_WORD1_MOUNTED_ON_FILEID
168 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
169 struct nfs4_readdir_arg
*readdir
)
173 BUG_ON(readdir
->count
< 80);
175 readdir
->cookie
= cookie
;
176 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
181 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
186 * NFSv4 servers do not return entries for '.' and '..'
187 * Therefore, we fake these entries here. We let '.'
188 * have cookie 0 and '..' have cookie 1. Note that
189 * when talking to the server, we always send cookie 0
192 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
195 *p
++ = xdr_one
; /* next */
196 *p
++ = xdr_zero
; /* cookie, first word */
197 *p
++ = xdr_one
; /* cookie, second word */
198 *p
++ = xdr_one
; /* entry len */
199 memcpy(p
, ".\0\0\0", 4); /* entry */
201 *p
++ = xdr_one
; /* bitmap length */
202 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
203 *p
++ = htonl(8); /* attribute buffer length */
204 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
207 *p
++ = xdr_one
; /* next */
208 *p
++ = xdr_zero
; /* cookie, first word */
209 *p
++ = xdr_two
; /* cookie, second word */
210 *p
++ = xdr_two
; /* entry len */
211 memcpy(p
, "..\0\0", 4); /* entry */
213 *p
++ = xdr_one
; /* bitmap length */
214 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
215 *p
++ = htonl(8); /* attribute buffer length */
216 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
218 readdir
->pgbase
= (char *)p
- (char *)start
;
219 readdir
->count
-= readdir
->pgbase
;
220 kunmap_atomic(start
, KM_USER0
);
223 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
229 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
230 nfs_wait_bit_killable
, TASK_KILLABLE
);
234 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
241 *timeout
= NFS4_POLL_RETRY_MIN
;
242 if (*timeout
> NFS4_POLL_RETRY_MAX
)
243 *timeout
= NFS4_POLL_RETRY_MAX
;
244 schedule_timeout_killable(*timeout
);
245 if (fatal_signal_pending(current
))
251 /* This is the error handling routine for processes that are allowed
254 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
256 struct nfs_client
*clp
= server
->nfs_client
;
257 struct nfs4_state
*state
= exception
->state
;
260 exception
->retry
= 0;
264 case -NFS4ERR_ADMIN_REVOKED
:
265 case -NFS4ERR_BAD_STATEID
:
266 case -NFS4ERR_OPENMODE
:
269 nfs4_schedule_stateid_recovery(server
, state
);
270 goto wait_on_recovery
;
271 case -NFS4ERR_EXPIRED
:
273 nfs4_schedule_stateid_recovery(server
, state
);
274 case -NFS4ERR_STALE_STATEID
:
275 case -NFS4ERR_STALE_CLIENTID
:
276 nfs4_schedule_lease_recovery(clp
);
277 goto wait_on_recovery
;
278 #if defined(CONFIG_NFS_V4_1)
279 case -NFS4ERR_BADSESSION
:
280 case -NFS4ERR_BADSLOT
:
281 case -NFS4ERR_BAD_HIGH_SLOT
:
282 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
283 case -NFS4ERR_DEADSESSION
:
284 case -NFS4ERR_SEQ_FALSE_RETRY
:
285 case -NFS4ERR_SEQ_MISORDERED
:
286 dprintk("%s ERROR: %d Reset session\n", __func__
,
288 nfs4_schedule_session_recovery(clp
->cl_session
);
289 exception
->retry
= 1;
291 #endif /* defined(CONFIG_NFS_V4_1) */
292 case -NFS4ERR_FILE_OPEN
:
293 if (exception
->timeout
> HZ
) {
294 /* We have retried a decent amount, time to
303 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
306 case -NFS4ERR_RETRY_UNCACHED_REP
:
307 case -NFS4ERR_OLD_STATEID
:
308 exception
->retry
= 1;
310 case -NFS4ERR_BADOWNER
:
311 /* The following works around a Linux server bug! */
312 case -NFS4ERR_BADNAME
:
313 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
314 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
315 exception
->retry
= 1;
316 printk(KERN_WARNING
"NFS: v4 server %s "
317 "does not accept raw "
319 "Reenabling the idmapper.\n",
320 server
->nfs_client
->cl_hostname
);
323 /* We failed to handle the error */
324 return nfs4_map_errors(ret
);
326 ret
= nfs4_wait_clnt_recover(clp
);
328 exception
->retry
= 1;
333 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
335 spin_lock(&clp
->cl_lock
);
336 if (time_before(clp
->cl_last_renewal
,timestamp
))
337 clp
->cl_last_renewal
= timestamp
;
338 spin_unlock(&clp
->cl_lock
);
341 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
343 do_renew_lease(server
->nfs_client
, timestamp
);
346 #if defined(CONFIG_NFS_V4_1)
349 * nfs4_free_slot - free a slot and efficiently update slot table.
351 * freeing a slot is trivially done by clearing its respective bit
353 * If the freed slotid equals highest_used_slotid we want to update it
354 * so that the server would be able to size down the slot table if needed,
355 * otherwise we know that the highest_used_slotid is still in use.
356 * When updating highest_used_slotid there may be "holes" in the bitmap
357 * so we need to scan down from highest_used_slotid to 0 looking for the now
358 * highest slotid in use.
359 * If none found, highest_used_slotid is set to -1.
361 * Must be called while holding tbl->slot_tbl_lock
364 nfs4_free_slot(struct nfs4_slot_table
*tbl
, struct nfs4_slot
*free_slot
)
366 int free_slotid
= free_slot
- tbl
->slots
;
367 int slotid
= free_slotid
;
369 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
370 /* clear used bit in bitmap */
371 __clear_bit(slotid
, tbl
->used_slots
);
373 /* update highest_used_slotid when it is freed */
374 if (slotid
== tbl
->highest_used_slotid
) {
375 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
376 if (slotid
< tbl
->max_slots
)
377 tbl
->highest_used_slotid
= slotid
;
379 tbl
->highest_used_slotid
= -1;
381 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
382 free_slotid
, tbl
->highest_used_slotid
);
386 * Signal state manager thread if session fore channel is drained
388 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
390 struct rpc_task
*task
;
392 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
393 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
395 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
399 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
402 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
403 complete(&ses
->fc_slot_table
.complete
);
407 * Signal state manager thread if session back channel is drained
409 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
411 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
412 ses
->bc_slot_table
.highest_used_slotid
!= -1)
414 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
415 complete(&ses
->bc_slot_table
.complete
);
418 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
420 struct nfs4_slot_table
*tbl
;
422 tbl
= &res
->sr_session
->fc_slot_table
;
424 /* just wake up the next guy waiting since
425 * we may have not consumed a slot after all */
426 dprintk("%s: No slot\n", __func__
);
430 spin_lock(&tbl
->slot_tbl_lock
);
431 nfs4_free_slot(tbl
, res
->sr_slot
);
432 nfs4_check_drain_fc_complete(res
->sr_session
);
433 spin_unlock(&tbl
->slot_tbl_lock
);
437 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
439 unsigned long timestamp
;
440 struct nfs_client
*clp
;
443 * sr_status remains 1 if an RPC level error occurred. The server
444 * may or may not have processed the sequence operation..
445 * Proceed as if the server received and processed the sequence
448 if (res
->sr_status
== 1)
449 res
->sr_status
= NFS_OK
;
451 /* don't increment the sequence number if the task wasn't sent */
452 if (!RPC_WAS_SENT(task
))
455 /* Check the SEQUENCE operation status */
456 switch (res
->sr_status
) {
458 /* Update the slot's sequence and clientid lease timer */
459 ++res
->sr_slot
->seq_nr
;
460 timestamp
= res
->sr_renewal_time
;
461 clp
= res
->sr_session
->clp
;
462 do_renew_lease(clp
, timestamp
);
463 /* Check sequence flags */
464 if (res
->sr_status_flags
!= 0)
465 nfs4_schedule_lease_recovery(clp
);
468 /* The server detected a resend of the RPC call and
469 * returned NFS4ERR_DELAY as per Section 2.10.6.2
472 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
474 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
475 res
->sr_slot
->seq_nr
);
478 /* Just update the slot sequence no. */
479 ++res
->sr_slot
->seq_nr
;
482 /* The session may be reset by one of the error handlers. */
483 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
484 nfs41_sequence_free_slot(res
);
487 if (!rpc_restart_call(task
))
489 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
493 static int nfs4_sequence_done(struct rpc_task
*task
,
494 struct nfs4_sequence_res
*res
)
496 if (res
->sr_session
== NULL
)
498 return nfs41_sequence_done(task
, res
);
502 * nfs4_find_slot - efficiently look for a free slot
504 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
505 * If found, we mark the slot as used, update the highest_used_slotid,
506 * and respectively set up the sequence operation args.
507 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
509 * Note: must be called with under the slot_tbl_lock.
512 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
515 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
516 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
518 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
519 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
521 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
522 if (slotid
>= tbl
->max_slots
)
524 __set_bit(slotid
, tbl
->used_slots
);
525 if (slotid
> tbl
->highest_used_slotid
)
526 tbl
->highest_used_slotid
= slotid
;
529 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
530 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
534 int nfs41_setup_sequence(struct nfs4_session
*session
,
535 struct nfs4_sequence_args
*args
,
536 struct nfs4_sequence_res
*res
,
538 struct rpc_task
*task
)
540 struct nfs4_slot
*slot
;
541 struct nfs4_slot_table
*tbl
;
544 dprintk("--> %s\n", __func__
);
545 /* slot already allocated? */
546 if (res
->sr_slot
!= NULL
)
549 tbl
= &session
->fc_slot_table
;
551 spin_lock(&tbl
->slot_tbl_lock
);
552 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
553 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
555 * The state manager will wait until the slot table is empty.
556 * Schedule the reset thread
558 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
559 spin_unlock(&tbl
->slot_tbl_lock
);
560 dprintk("%s Schedule Session Reset\n", __func__
);
564 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
565 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
566 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
567 spin_unlock(&tbl
->slot_tbl_lock
);
568 dprintk("%s enforce FIFO order\n", __func__
);
572 slotid
= nfs4_find_slot(tbl
);
573 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
574 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
575 spin_unlock(&tbl
->slot_tbl_lock
);
576 dprintk("<-- %s: no free slots\n", __func__
);
579 spin_unlock(&tbl
->slot_tbl_lock
);
581 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
582 slot
= tbl
->slots
+ slotid
;
583 args
->sa_session
= session
;
584 args
->sa_slotid
= slotid
;
585 args
->sa_cache_this
= cache_reply
;
587 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
589 res
->sr_session
= session
;
591 res
->sr_renewal_time
= jiffies
;
592 res
->sr_status_flags
= 0;
594 * sr_status is only set in decode_sequence, and so will remain
595 * set to 1 if an rpc level failure occurs.
600 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
602 int nfs4_setup_sequence(const struct nfs_server
*server
,
603 struct nfs4_sequence_args
*args
,
604 struct nfs4_sequence_res
*res
,
606 struct rpc_task
*task
)
608 struct nfs4_session
*session
= nfs4_get_session(server
);
611 if (session
== NULL
) {
612 args
->sa_session
= NULL
;
613 res
->sr_session
= NULL
;
617 dprintk("--> %s clp %p session %p sr_slot %td\n",
618 __func__
, session
->clp
, session
, res
->sr_slot
?
619 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
621 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
624 dprintk("<-- %s status=%d\n", __func__
, ret
);
628 struct nfs41_call_sync_data
{
629 const struct nfs_server
*seq_server
;
630 struct nfs4_sequence_args
*seq_args
;
631 struct nfs4_sequence_res
*seq_res
;
635 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
637 struct nfs41_call_sync_data
*data
= calldata
;
639 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
641 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
642 data
->seq_res
, data
->cache_reply
, task
))
644 rpc_call_start(task
);
647 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
649 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
650 nfs41_call_sync_prepare(task
, calldata
);
653 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
655 struct nfs41_call_sync_data
*data
= calldata
;
657 nfs41_sequence_done(task
, data
->seq_res
);
660 struct rpc_call_ops nfs41_call_sync_ops
= {
661 .rpc_call_prepare
= nfs41_call_sync_prepare
,
662 .rpc_call_done
= nfs41_call_sync_done
,
665 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
666 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
667 .rpc_call_done
= nfs41_call_sync_done
,
670 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
671 struct nfs_server
*server
,
672 struct rpc_message
*msg
,
673 struct nfs4_sequence_args
*args
,
674 struct nfs4_sequence_res
*res
,
679 struct rpc_task
*task
;
680 struct nfs41_call_sync_data data
= {
681 .seq_server
= server
,
684 .cache_reply
= cache_reply
,
686 struct rpc_task_setup task_setup
= {
689 .callback_ops
= &nfs41_call_sync_ops
,
690 .callback_data
= &data
695 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
696 task
= rpc_run_task(&task_setup
);
700 ret
= task
->tk_status
;
706 int _nfs4_call_sync_session(struct rpc_clnt
*clnt
,
707 struct nfs_server
*server
,
708 struct rpc_message
*msg
,
709 struct nfs4_sequence_args
*args
,
710 struct nfs4_sequence_res
*res
,
713 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
, cache_reply
, 0);
717 static int nfs4_sequence_done(struct rpc_task
*task
,
718 struct nfs4_sequence_res
*res
)
722 #endif /* CONFIG_NFS_V4_1 */
724 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
725 struct nfs_server
*server
,
726 struct rpc_message
*msg
,
727 struct nfs4_sequence_args
*args
,
728 struct nfs4_sequence_res
*res
,
731 args
->sa_session
= res
->sr_session
= NULL
;
732 return rpc_call_sync(clnt
, msg
, 0);
736 int nfs4_call_sync(struct rpc_clnt
*clnt
,
737 struct nfs_server
*server
,
738 struct rpc_message
*msg
,
739 struct nfs4_sequence_args
*args
,
740 struct nfs4_sequence_res
*res
,
743 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
744 args
, res
, cache_reply
);
747 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
749 struct nfs_inode
*nfsi
= NFS_I(dir
);
751 spin_lock(&dir
->i_lock
);
752 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
753 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
754 nfs_force_lookup_revalidate(dir
);
755 dir
->i_version
= cinfo
->after
;
756 spin_unlock(&dir
->i_lock
);
759 struct nfs4_opendata
{
761 struct nfs_openargs o_arg
;
762 struct nfs_openres o_res
;
763 struct nfs_open_confirmargs c_arg
;
764 struct nfs_open_confirmres c_res
;
765 struct nfs_fattr f_attr
;
766 struct nfs_fattr dir_attr
;
768 struct dentry
*dentry
;
769 struct nfs4_state_owner
*owner
;
770 struct nfs4_state
*state
;
772 unsigned long timestamp
;
773 unsigned int rpc_done
: 1;
779 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
781 p
->o_res
.f_attr
= &p
->f_attr
;
782 p
->o_res
.dir_attr
= &p
->dir_attr
;
783 p
->o_res
.seqid
= p
->o_arg
.seqid
;
784 p
->c_res
.seqid
= p
->c_arg
.seqid
;
785 p
->o_res
.server
= p
->o_arg
.server
;
786 nfs_fattr_init(&p
->f_attr
);
787 nfs_fattr_init(&p
->dir_attr
);
790 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
791 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
792 const struct iattr
*attrs
,
795 struct dentry
*parent
= dget_parent(dentry
);
796 struct inode
*dir
= parent
->d_inode
;
797 struct nfs_server
*server
= NFS_SERVER(dir
);
798 struct nfs4_opendata
*p
;
800 p
= kzalloc(sizeof(*p
), gfp_mask
);
803 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
804 if (p
->o_arg
.seqid
== NULL
)
806 nfs_sb_active(dentry
->d_sb
);
807 p
->dentry
= dget(dentry
);
810 atomic_inc(&sp
->so_count
);
811 p
->o_arg
.fh
= NFS_FH(dir
);
812 p
->o_arg
.open_flags
= flags
;
813 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
814 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
815 p
->o_arg
.id
= sp
->so_owner_id
.id
;
816 p
->o_arg
.name
= &dentry
->d_name
;
817 p
->o_arg
.server
= server
;
818 p
->o_arg
.bitmask
= server
->attr_bitmask
;
819 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
820 if (flags
& O_CREAT
) {
823 p
->o_arg
.u
.attrs
= &p
->attrs
;
824 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
825 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
829 p
->c_arg
.fh
= &p
->o_res
.fh
;
830 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
831 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
832 nfs4_init_opendata_res(p
);
842 static void nfs4_opendata_free(struct kref
*kref
)
844 struct nfs4_opendata
*p
= container_of(kref
,
845 struct nfs4_opendata
, kref
);
846 struct super_block
*sb
= p
->dentry
->d_sb
;
848 nfs_free_seqid(p
->o_arg
.seqid
);
849 if (p
->state
!= NULL
)
850 nfs4_put_open_state(p
->state
);
851 nfs4_put_state_owner(p
->owner
);
858 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
861 kref_put(&p
->kref
, nfs4_opendata_free
);
864 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
868 ret
= rpc_wait_for_completion_task(task
);
872 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
876 if (open_mode
& O_EXCL
)
878 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
880 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
881 && state
->n_rdonly
!= 0;
884 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
885 && state
->n_wronly
!= 0;
887 case FMODE_READ
|FMODE_WRITE
:
888 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
889 && state
->n_rdwr
!= 0;
895 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
897 if ((delegation
->type
& fmode
) != fmode
)
899 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
901 nfs_mark_delegation_referenced(delegation
);
905 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
914 case FMODE_READ
|FMODE_WRITE
:
917 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
920 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
922 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
923 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
924 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
927 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
930 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
932 case FMODE_READ
|FMODE_WRITE
:
933 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
937 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
939 write_seqlock(&state
->seqlock
);
940 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
941 write_sequnlock(&state
->seqlock
);
944 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
947 * Protect the call to nfs4_state_set_mode_locked and
948 * serialise the stateid update
950 write_seqlock(&state
->seqlock
);
951 if (deleg_stateid
!= NULL
) {
952 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
953 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
955 if (open_stateid
!= NULL
)
956 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
957 write_sequnlock(&state
->seqlock
);
958 spin_lock(&state
->owner
->so_lock
);
959 update_open_stateflags(state
, fmode
);
960 spin_unlock(&state
->owner
->so_lock
);
963 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
965 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
966 struct nfs_delegation
*deleg_cur
;
969 fmode
&= (FMODE_READ
|FMODE_WRITE
);
972 deleg_cur
= rcu_dereference(nfsi
->delegation
);
973 if (deleg_cur
== NULL
)
976 spin_lock(&deleg_cur
->lock
);
977 if (nfsi
->delegation
!= deleg_cur
||
978 (deleg_cur
->type
& fmode
) != fmode
)
979 goto no_delegation_unlock
;
981 if (delegation
== NULL
)
982 delegation
= &deleg_cur
->stateid
;
983 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
984 goto no_delegation_unlock
;
986 nfs_mark_delegation_referenced(deleg_cur
);
987 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
989 no_delegation_unlock
:
990 spin_unlock(&deleg_cur
->lock
);
994 if (!ret
&& open_stateid
!= NULL
) {
995 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1003 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1005 struct nfs_delegation
*delegation
;
1008 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1009 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1014 nfs_inode_return_delegation(inode
);
1017 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1019 struct nfs4_state
*state
= opendata
->state
;
1020 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1021 struct nfs_delegation
*delegation
;
1022 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
1023 fmode_t fmode
= opendata
->o_arg
.fmode
;
1024 nfs4_stateid stateid
;
1028 if (can_open_cached(state
, fmode
, open_mode
)) {
1029 spin_lock(&state
->owner
->so_lock
);
1030 if (can_open_cached(state
, fmode
, open_mode
)) {
1031 update_open_stateflags(state
, fmode
);
1032 spin_unlock(&state
->owner
->so_lock
);
1033 goto out_return_state
;
1035 spin_unlock(&state
->owner
->so_lock
);
1038 delegation
= rcu_dereference(nfsi
->delegation
);
1039 if (delegation
== NULL
||
1040 !can_open_delegated(delegation
, fmode
)) {
1044 /* Save the delegation */
1045 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1047 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1052 /* Try to update the stateid using the delegation */
1053 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1054 goto out_return_state
;
1057 return ERR_PTR(ret
);
1059 atomic_inc(&state
->count
);
1063 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1065 struct inode
*inode
;
1066 struct nfs4_state
*state
= NULL
;
1067 struct nfs_delegation
*delegation
;
1070 if (!data
->rpc_done
) {
1071 state
= nfs4_try_open_cached(data
);
1076 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1078 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1079 ret
= PTR_ERR(inode
);
1083 state
= nfs4_get_open_state(inode
, data
->owner
);
1086 if (data
->o_res
.delegation_type
!= 0) {
1087 int delegation_flags
= 0;
1090 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1092 delegation_flags
= delegation
->flags
;
1094 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1095 nfs_inode_set_delegation(state
->inode
,
1096 data
->owner
->so_cred
,
1099 nfs_inode_reclaim_delegation(state
->inode
,
1100 data
->owner
->so_cred
,
1104 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1112 return ERR_PTR(ret
);
1115 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1117 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1118 struct nfs_open_context
*ctx
;
1120 spin_lock(&state
->inode
->i_lock
);
1121 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1122 if (ctx
->state
!= state
)
1124 get_nfs_open_context(ctx
);
1125 spin_unlock(&state
->inode
->i_lock
);
1128 spin_unlock(&state
->inode
->i_lock
);
1129 return ERR_PTR(-ENOENT
);
1132 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1134 struct nfs4_opendata
*opendata
;
1136 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1137 if (opendata
== NULL
)
1138 return ERR_PTR(-ENOMEM
);
1139 opendata
->state
= state
;
1140 atomic_inc(&state
->count
);
1144 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1146 struct nfs4_state
*newstate
;
1149 opendata
->o_arg
.open_flags
= 0;
1150 opendata
->o_arg
.fmode
= fmode
;
1151 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1152 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1153 nfs4_init_opendata_res(opendata
);
1154 ret
= _nfs4_recover_proc_open(opendata
);
1157 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1158 if (IS_ERR(newstate
))
1159 return PTR_ERR(newstate
);
1160 nfs4_close_state(newstate
, fmode
);
1165 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1167 struct nfs4_state
*newstate
;
1170 /* memory barrier prior to reading state->n_* */
1171 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1173 if (state
->n_rdwr
!= 0) {
1174 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1175 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1178 if (newstate
!= state
)
1181 if (state
->n_wronly
!= 0) {
1182 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1183 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1186 if (newstate
!= state
)
1189 if (state
->n_rdonly
!= 0) {
1190 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1191 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1194 if (newstate
!= state
)
1198 * We may have performed cached opens for all three recoveries.
1199 * Check if we need to update the current stateid.
1201 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1202 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1203 write_seqlock(&state
->seqlock
);
1204 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1205 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1206 write_sequnlock(&state
->seqlock
);
1213 * reclaim state on the server after a reboot.
1215 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1217 struct nfs_delegation
*delegation
;
1218 struct nfs4_opendata
*opendata
;
1219 fmode_t delegation_type
= 0;
1222 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1223 if (IS_ERR(opendata
))
1224 return PTR_ERR(opendata
);
1225 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1226 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1228 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1229 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1230 delegation_type
= delegation
->type
;
1232 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1233 status
= nfs4_open_recover(opendata
, state
);
1234 nfs4_opendata_put(opendata
);
1238 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1240 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1241 struct nfs4_exception exception
= { };
1244 err
= _nfs4_do_open_reclaim(ctx
, state
);
1245 if (err
!= -NFS4ERR_DELAY
)
1247 nfs4_handle_exception(server
, err
, &exception
);
1248 } while (exception
.retry
);
1252 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1254 struct nfs_open_context
*ctx
;
1257 ctx
= nfs4_state_find_open_context(state
);
1259 return PTR_ERR(ctx
);
1260 ret
= nfs4_do_open_reclaim(ctx
, state
);
1261 put_nfs_open_context(ctx
);
1265 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1267 struct nfs4_opendata
*opendata
;
1270 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1271 if (IS_ERR(opendata
))
1272 return PTR_ERR(opendata
);
1273 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1274 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1275 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1276 ret
= nfs4_open_recover(opendata
, state
);
1277 nfs4_opendata_put(opendata
);
1281 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1283 struct nfs4_exception exception
= { };
1284 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1287 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1293 case -NFS4ERR_BADSESSION
:
1294 case -NFS4ERR_BADSLOT
:
1295 case -NFS4ERR_BAD_HIGH_SLOT
:
1296 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1297 case -NFS4ERR_DEADSESSION
:
1298 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1300 case -NFS4ERR_STALE_CLIENTID
:
1301 case -NFS4ERR_STALE_STATEID
:
1302 case -NFS4ERR_EXPIRED
:
1303 /* Don't recall a delegation if it was lost */
1304 nfs4_schedule_lease_recovery(server
->nfs_client
);
1308 * The show must go on: exit, but mark the
1309 * stateid as needing recovery.
1311 case -NFS4ERR_ADMIN_REVOKED
:
1312 case -NFS4ERR_BAD_STATEID
:
1313 nfs4_schedule_stateid_recovery(server
, state
);
1316 * User RPCSEC_GSS context has expired.
1317 * We cannot recover this stateid now, so
1318 * skip it and allow recovery thread to
1325 err
= nfs4_handle_exception(server
, err
, &exception
);
1326 } while (exception
.retry
);
1331 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1333 struct nfs4_opendata
*data
= calldata
;
1335 data
->rpc_status
= task
->tk_status
;
1336 if (data
->rpc_status
== 0) {
1337 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1338 sizeof(data
->o_res
.stateid
.data
));
1339 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1340 renew_lease(data
->o_res
.server
, data
->timestamp
);
1345 static void nfs4_open_confirm_release(void *calldata
)
1347 struct nfs4_opendata
*data
= calldata
;
1348 struct nfs4_state
*state
= NULL
;
1350 /* If this request hasn't been cancelled, do nothing */
1351 if (data
->cancelled
== 0)
1353 /* In case of error, no cleanup! */
1354 if (!data
->rpc_done
)
1356 state
= nfs4_opendata_to_nfs4_state(data
);
1358 nfs4_close_state(state
, data
->o_arg
.fmode
);
1360 nfs4_opendata_put(data
);
1363 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1364 .rpc_call_done
= nfs4_open_confirm_done
,
1365 .rpc_release
= nfs4_open_confirm_release
,
1369 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1371 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1373 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1374 struct rpc_task
*task
;
1375 struct rpc_message msg
= {
1376 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1377 .rpc_argp
= &data
->c_arg
,
1378 .rpc_resp
= &data
->c_res
,
1379 .rpc_cred
= data
->owner
->so_cred
,
1381 struct rpc_task_setup task_setup_data
= {
1382 .rpc_client
= server
->client
,
1383 .rpc_message
= &msg
,
1384 .callback_ops
= &nfs4_open_confirm_ops
,
1385 .callback_data
= data
,
1386 .workqueue
= nfsiod_workqueue
,
1387 .flags
= RPC_TASK_ASYNC
,
1391 kref_get(&data
->kref
);
1393 data
->rpc_status
= 0;
1394 data
->timestamp
= jiffies
;
1395 task
= rpc_run_task(&task_setup_data
);
1397 return PTR_ERR(task
);
1398 status
= nfs4_wait_for_completion_rpc_task(task
);
1400 data
->cancelled
= 1;
1403 status
= data
->rpc_status
;
1408 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1410 struct nfs4_opendata
*data
= calldata
;
1411 struct nfs4_state_owner
*sp
= data
->owner
;
1413 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1416 * Check if we still need to send an OPEN call, or if we can use
1417 * a delegation instead.
1419 if (data
->state
!= NULL
) {
1420 struct nfs_delegation
*delegation
;
1422 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1425 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1426 if (delegation
!= NULL
&&
1427 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1433 /* Update sequence id. */
1434 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1435 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1436 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1437 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1438 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1440 data
->timestamp
= jiffies
;
1441 if (nfs4_setup_sequence(data
->o_arg
.server
,
1442 &data
->o_arg
.seq_args
,
1443 &data
->o_res
.seq_res
, 1, task
))
1445 rpc_call_start(task
);
1448 task
->tk_action
= NULL
;
1452 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1454 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1455 nfs4_open_prepare(task
, calldata
);
1458 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1460 struct nfs4_opendata
*data
= calldata
;
1462 data
->rpc_status
= task
->tk_status
;
1464 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1467 if (task
->tk_status
== 0) {
1468 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1472 data
->rpc_status
= -ELOOP
;
1475 data
->rpc_status
= -EISDIR
;
1478 data
->rpc_status
= -ENOTDIR
;
1480 renew_lease(data
->o_res
.server
, data
->timestamp
);
1481 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1482 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1487 static void nfs4_open_release(void *calldata
)
1489 struct nfs4_opendata
*data
= calldata
;
1490 struct nfs4_state
*state
= NULL
;
1492 /* If this request hasn't been cancelled, do nothing */
1493 if (data
->cancelled
== 0)
1495 /* In case of error, no cleanup! */
1496 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1498 /* In case we need an open_confirm, no cleanup! */
1499 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1501 state
= nfs4_opendata_to_nfs4_state(data
);
1503 nfs4_close_state(state
, data
->o_arg
.fmode
);
1505 nfs4_opendata_put(data
);
1508 static const struct rpc_call_ops nfs4_open_ops
= {
1509 .rpc_call_prepare
= nfs4_open_prepare
,
1510 .rpc_call_done
= nfs4_open_done
,
1511 .rpc_release
= nfs4_open_release
,
1514 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1515 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1516 .rpc_call_done
= nfs4_open_done
,
1517 .rpc_release
= nfs4_open_release
,
1520 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1522 struct inode
*dir
= data
->dir
->d_inode
;
1523 struct nfs_server
*server
= NFS_SERVER(dir
);
1524 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1525 struct nfs_openres
*o_res
= &data
->o_res
;
1526 struct rpc_task
*task
;
1527 struct rpc_message msg
= {
1528 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1531 .rpc_cred
= data
->owner
->so_cred
,
1533 struct rpc_task_setup task_setup_data
= {
1534 .rpc_client
= server
->client
,
1535 .rpc_message
= &msg
,
1536 .callback_ops
= &nfs4_open_ops
,
1537 .callback_data
= data
,
1538 .workqueue
= nfsiod_workqueue
,
1539 .flags
= RPC_TASK_ASYNC
,
1543 kref_get(&data
->kref
);
1545 data
->rpc_status
= 0;
1546 data
->cancelled
= 0;
1548 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1549 task
= rpc_run_task(&task_setup_data
);
1551 return PTR_ERR(task
);
1552 status
= nfs4_wait_for_completion_rpc_task(task
);
1554 data
->cancelled
= 1;
1557 status
= data
->rpc_status
;
1563 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1565 struct inode
*dir
= data
->dir
->d_inode
;
1566 struct nfs_openres
*o_res
= &data
->o_res
;
1569 status
= nfs4_run_open_task(data
, 1);
1570 if (status
!= 0 || !data
->rpc_done
)
1573 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1575 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1576 status
= _nfs4_proc_open_confirm(data
);
1585 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1587 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1589 struct inode
*dir
= data
->dir
->d_inode
;
1590 struct nfs_server
*server
= NFS_SERVER(dir
);
1591 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1592 struct nfs_openres
*o_res
= &data
->o_res
;
1595 status
= nfs4_run_open_task(data
, 0);
1596 if (!data
->rpc_done
)
1599 if (status
== -NFS4ERR_BADNAME
&&
1600 !(o_arg
->open_flags
& O_CREAT
))
1605 if (o_arg
->open_flags
& O_CREAT
) {
1606 update_changeattr(dir
, &o_res
->cinfo
);
1607 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1609 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1610 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1611 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1612 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1613 status
= _nfs4_proc_open_confirm(data
);
1617 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1618 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1622 static int nfs4_client_recover_expired_lease(struct nfs_client
*clp
)
1627 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1628 ret
= nfs4_wait_clnt_recover(clp
);
1631 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1632 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1634 nfs4_schedule_state_manager(clp
);
1640 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1642 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1647 * reclaim state on the server after a network partition.
1648 * Assumes caller holds the appropriate lock
1650 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1652 struct nfs4_opendata
*opendata
;
1655 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1656 if (IS_ERR(opendata
))
1657 return PTR_ERR(opendata
);
1658 ret
= nfs4_open_recover(opendata
, state
);
1660 d_drop(ctx
->dentry
);
1661 nfs4_opendata_put(opendata
);
1665 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1667 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1668 struct nfs4_exception exception
= { };
1672 err
= _nfs4_open_expired(ctx
, state
);
1676 case -NFS4ERR_GRACE
:
1677 case -NFS4ERR_DELAY
:
1678 nfs4_handle_exception(server
, err
, &exception
);
1681 } while (exception
.retry
);
1686 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1688 struct nfs_open_context
*ctx
;
1691 ctx
= nfs4_state_find_open_context(state
);
1693 return PTR_ERR(ctx
);
1694 ret
= nfs4_do_open_expired(ctx
, state
);
1695 put_nfs_open_context(ctx
);
1699 #if defined(CONFIG_NFS_V4_1)
1700 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1703 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1705 status
= nfs41_test_stateid(server
, state
);
1706 if (status
== NFS_OK
)
1708 nfs41_free_stateid(server
, state
);
1709 return nfs4_open_expired(sp
, state
);
1714 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1715 * fields corresponding to attributes that were used to store the verifier.
1716 * Make sure we clobber those fields in the later setattr call
1718 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1720 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1721 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1722 sattr
->ia_valid
|= ATTR_ATIME
;
1724 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1725 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1726 sattr
->ia_valid
|= ATTR_MTIME
;
1730 * Returns a referenced nfs4_state
1732 static int _nfs4_do_open(struct inode
*dir
, struct dentry
*dentry
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
1734 struct nfs4_state_owner
*sp
;
1735 struct nfs4_state
*state
= NULL
;
1736 struct nfs_server
*server
= NFS_SERVER(dir
);
1737 struct nfs4_opendata
*opendata
;
1740 /* Protect against reboot recovery conflicts */
1742 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1743 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1746 status
= nfs4_recover_expired_lease(server
);
1748 goto err_put_state_owner
;
1749 if (dentry
->d_inode
!= NULL
)
1750 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
1752 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1753 if (opendata
== NULL
)
1754 goto err_put_state_owner
;
1756 if (dentry
->d_inode
!= NULL
)
1757 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
1759 status
= _nfs4_proc_open(opendata
);
1761 goto err_opendata_put
;
1763 state
= nfs4_opendata_to_nfs4_state(opendata
);
1764 status
= PTR_ERR(state
);
1766 goto err_opendata_put
;
1767 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1768 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1770 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1771 nfs4_exclusive_attrset(opendata
, sattr
);
1773 nfs_fattr_init(opendata
->o_res
.f_attr
);
1774 status
= nfs4_do_setattr(state
->inode
, cred
,
1775 opendata
->o_res
.f_attr
, sattr
,
1778 nfs_setattr_update_inode(state
->inode
, sattr
);
1779 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1781 nfs4_opendata_put(opendata
);
1782 nfs4_put_state_owner(sp
);
1786 nfs4_opendata_put(opendata
);
1787 err_put_state_owner
:
1788 nfs4_put_state_owner(sp
);
1795 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct dentry
*dentry
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
1797 struct nfs4_exception exception
= { };
1798 struct nfs4_state
*res
;
1802 status
= _nfs4_do_open(dir
, dentry
, fmode
, flags
, sattr
, cred
, &res
);
1805 /* NOTE: BAD_SEQID means the server and client disagree about the
1806 * book-keeping w.r.t. state-changing operations
1807 * (OPEN/CLOSE/LOCK/LOCKU...)
1808 * It is actually a sign of a bug on the client or on the server.
1810 * If we receive a BAD_SEQID error in the particular case of
1811 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1812 * have unhashed the old state_owner for us, and that we can
1813 * therefore safely retry using a new one. We should still warn
1814 * the user though...
1816 if (status
== -NFS4ERR_BAD_SEQID
) {
1817 printk(KERN_WARNING
"NFS: v4 server %s "
1818 " returned a bad sequence-id error!\n",
1819 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1820 exception
.retry
= 1;
1824 * BAD_STATEID on OPEN means that the server cancelled our
1825 * state before it received the OPEN_CONFIRM.
1826 * Recover by retrying the request as per the discussion
1827 * on Page 181 of RFC3530.
1829 if (status
== -NFS4ERR_BAD_STATEID
) {
1830 exception
.retry
= 1;
1833 if (status
== -EAGAIN
) {
1834 /* We must have found a delegation */
1835 exception
.retry
= 1;
1838 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1839 status
, &exception
));
1840 } while (exception
.retry
);
1844 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1845 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1846 struct nfs4_state
*state
)
1848 struct nfs_server
*server
= NFS_SERVER(inode
);
1849 struct nfs_setattrargs arg
= {
1850 .fh
= NFS_FH(inode
),
1853 .bitmask
= server
->attr_bitmask
,
1855 struct nfs_setattrres res
= {
1859 struct rpc_message msg
= {
1860 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1865 unsigned long timestamp
= jiffies
;
1868 nfs_fattr_init(fattr
);
1870 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1871 /* Use that stateid */
1872 } else if (state
!= NULL
) {
1873 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1875 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1877 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
1878 if (status
== 0 && state
!= NULL
)
1879 renew_lease(server
, timestamp
);
1883 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1884 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1885 struct nfs4_state
*state
)
1887 struct nfs_server
*server
= NFS_SERVER(inode
);
1888 struct nfs4_exception exception
= { };
1891 err
= nfs4_handle_exception(server
,
1892 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1894 } while (exception
.retry
);
1898 struct nfs4_closedata
{
1899 struct inode
*inode
;
1900 struct nfs4_state
*state
;
1901 struct nfs_closeargs arg
;
1902 struct nfs_closeres res
;
1903 struct nfs_fattr fattr
;
1904 unsigned long timestamp
;
1909 static void nfs4_free_closedata(void *data
)
1911 struct nfs4_closedata
*calldata
= data
;
1912 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1913 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
1916 pnfs_roc_release(calldata
->state
->inode
);
1917 nfs4_put_open_state(calldata
->state
);
1918 nfs_free_seqid(calldata
->arg
.seqid
);
1919 nfs4_put_state_owner(sp
);
1920 nfs_sb_deactive(sb
);
1924 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1927 spin_lock(&state
->owner
->so_lock
);
1928 if (!(fmode
& FMODE_READ
))
1929 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1930 if (!(fmode
& FMODE_WRITE
))
1931 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1932 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1933 spin_unlock(&state
->owner
->so_lock
);
1936 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1938 struct nfs4_closedata
*calldata
= data
;
1939 struct nfs4_state
*state
= calldata
->state
;
1940 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1942 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1944 /* hmm. we are done with the inode, and in the process of freeing
1945 * the state_owner. we keep this around to process errors
1947 switch (task
->tk_status
) {
1950 pnfs_roc_set_barrier(state
->inode
,
1951 calldata
->roc_barrier
);
1952 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1953 renew_lease(server
, calldata
->timestamp
);
1954 nfs4_close_clear_stateid_flags(state
,
1955 calldata
->arg
.fmode
);
1957 case -NFS4ERR_STALE_STATEID
:
1958 case -NFS4ERR_OLD_STATEID
:
1959 case -NFS4ERR_BAD_STATEID
:
1960 case -NFS4ERR_EXPIRED
:
1961 if (calldata
->arg
.fmode
== 0)
1964 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1965 rpc_restart_call_prepare(task
);
1967 nfs_release_seqid(calldata
->arg
.seqid
);
1968 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1971 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1973 struct nfs4_closedata
*calldata
= data
;
1974 struct nfs4_state
*state
= calldata
->state
;
1977 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1980 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1981 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1982 spin_lock(&state
->owner
->so_lock
);
1983 /* Calculate the change in open mode */
1984 if (state
->n_rdwr
== 0) {
1985 if (state
->n_rdonly
== 0) {
1986 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1987 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1988 calldata
->arg
.fmode
&= ~FMODE_READ
;
1990 if (state
->n_wronly
== 0) {
1991 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1992 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1993 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1996 spin_unlock(&state
->owner
->so_lock
);
1999 /* Note: exit _without_ calling nfs4_close_done */
2000 task
->tk_action
= NULL
;
2004 if (calldata
->arg
.fmode
== 0) {
2005 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2006 if (calldata
->roc
&&
2007 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
2008 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
2014 nfs_fattr_init(calldata
->res
.fattr
);
2015 calldata
->timestamp
= jiffies
;
2016 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
2017 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
2020 rpc_call_start(task
);
2023 static const struct rpc_call_ops nfs4_close_ops
= {
2024 .rpc_call_prepare
= nfs4_close_prepare
,
2025 .rpc_call_done
= nfs4_close_done
,
2026 .rpc_release
= nfs4_free_closedata
,
2030 * It is possible for data to be read/written from a mem-mapped file
2031 * after the sys_close call (which hits the vfs layer as a flush).
2032 * This means that we can't safely call nfsv4 close on a file until
2033 * the inode is cleared. This in turn means that we are not good
2034 * NFSv4 citizens - we do not indicate to the server to update the file's
2035 * share state even when we are done with one of the three share
2036 * stateid's in the inode.
2038 * NOTE: Caller must be holding the sp->so_owner semaphore!
2040 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
2042 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2043 struct nfs4_closedata
*calldata
;
2044 struct nfs4_state_owner
*sp
= state
->owner
;
2045 struct rpc_task
*task
;
2046 struct rpc_message msg
= {
2047 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2048 .rpc_cred
= state
->owner
->so_cred
,
2050 struct rpc_task_setup task_setup_data
= {
2051 .rpc_client
= server
->client
,
2052 .rpc_message
= &msg
,
2053 .callback_ops
= &nfs4_close_ops
,
2054 .workqueue
= nfsiod_workqueue
,
2055 .flags
= RPC_TASK_ASYNC
,
2057 int status
= -ENOMEM
;
2059 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2060 if (calldata
== NULL
)
2062 calldata
->inode
= state
->inode
;
2063 calldata
->state
= state
;
2064 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2065 calldata
->arg
.stateid
= &state
->open_stateid
;
2066 /* Serialization for the sequence id */
2067 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2068 if (calldata
->arg
.seqid
== NULL
)
2069 goto out_free_calldata
;
2070 calldata
->arg
.fmode
= 0;
2071 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2072 calldata
->res
.fattr
= &calldata
->fattr
;
2073 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2074 calldata
->res
.server
= server
;
2075 calldata
->roc
= roc
;
2076 nfs_sb_active(calldata
->inode
->i_sb
);
2078 msg
.rpc_argp
= &calldata
->arg
;
2079 msg
.rpc_resp
= &calldata
->res
;
2080 task_setup_data
.callback_data
= calldata
;
2081 task
= rpc_run_task(&task_setup_data
);
2083 return PTR_ERR(task
);
2086 status
= rpc_wait_for_completion_task(task
);
2093 pnfs_roc_release(state
->inode
);
2094 nfs4_put_open_state(state
);
2095 nfs4_put_state_owner(sp
);
2099 static struct inode
*
2100 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2102 struct nfs4_state
*state
;
2104 /* Protect against concurrent sillydeletes */
2105 state
= nfs4_do_open(dir
, ctx
->dentry
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2107 return ERR_CAST(state
);
2109 return igrab(state
->inode
);
2112 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2114 if (ctx
->state
== NULL
)
2117 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2119 nfs4_close_state(ctx
->state
, ctx
->mode
);
2122 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2124 struct nfs4_server_caps_arg args
= {
2127 struct nfs4_server_caps_res res
= {};
2128 struct rpc_message msg
= {
2129 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2135 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2137 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2138 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2139 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2140 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2141 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2142 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2143 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2144 server
->caps
|= NFS_CAP_ACLS
;
2145 if (res
.has_links
!= 0)
2146 server
->caps
|= NFS_CAP_HARDLINKS
;
2147 if (res
.has_symlinks
!= 0)
2148 server
->caps
|= NFS_CAP_SYMLINKS
;
2149 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2150 server
->caps
|= NFS_CAP_FILEID
;
2151 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2152 server
->caps
|= NFS_CAP_MODE
;
2153 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2154 server
->caps
|= NFS_CAP_NLINK
;
2155 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2156 server
->caps
|= NFS_CAP_OWNER
;
2157 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2158 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2159 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2160 server
->caps
|= NFS_CAP_ATIME
;
2161 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2162 server
->caps
|= NFS_CAP_CTIME
;
2163 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2164 server
->caps
|= NFS_CAP_MTIME
;
2166 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2167 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2168 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2169 server
->acl_bitmask
= res
.acl_bitmask
;
2175 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2177 struct nfs4_exception exception
= { };
2180 err
= nfs4_handle_exception(server
,
2181 _nfs4_server_capabilities(server
, fhandle
),
2183 } while (exception
.retry
);
2187 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2188 struct nfs_fsinfo
*info
)
2190 struct nfs4_lookup_root_arg args
= {
2191 .bitmask
= nfs4_fattr_bitmap
,
2193 struct nfs4_lookup_res res
= {
2195 .fattr
= info
->fattr
,
2198 struct rpc_message msg
= {
2199 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2204 nfs_fattr_init(info
->fattr
);
2205 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2208 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2209 struct nfs_fsinfo
*info
)
2211 struct nfs4_exception exception
= { };
2214 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2217 case -NFS4ERR_WRONGSEC
:
2220 err
= nfs4_handle_exception(server
, err
, &exception
);
2222 } while (exception
.retry
);
2226 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2227 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2229 struct rpc_auth
*auth
;
2232 auth
= rpcauth_create(flavor
, server
->client
);
2237 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2242 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2243 struct nfs_fsinfo
*info
)
2245 int i
, len
, status
= 0;
2246 rpc_authflavor_t flav_array
[NFS_MAX_SECFLAVORS
];
2248 len
= gss_mech_list_pseudoflavors(&flav_array
[0]);
2249 flav_array
[len
] = RPC_AUTH_NULL
;
2252 for (i
= 0; i
< len
; i
++) {
2253 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2254 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2259 * -EACCESS could mean that the user doesn't have correct permissions
2260 * to access the mount. It could also mean that we tried to mount
2261 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2262 * existing mount programs don't handle -EACCES very well so it should
2263 * be mapped to -EPERM instead.
2265 if (status
== -EACCES
)
2271 * get the file handle for the "/" directory on the server
2273 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2274 struct nfs_fsinfo
*info
)
2276 int minor_version
= server
->nfs_client
->cl_minorversion
;
2277 int status
= nfs4_lookup_root(server
, fhandle
, info
);
2278 if ((status
== -NFS4ERR_WRONGSEC
) && !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2280 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2281 * by nfs4_map_errors() as this function exits.
2283 status
= nfs_v4_minor_ops
[minor_version
]->find_root_sec(server
, fhandle
, info
);
2285 status
= nfs4_server_capabilities(server
, fhandle
);
2287 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2288 return nfs4_map_errors(status
);
2291 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
2293 * Get locations and (maybe) other attributes of a referral.
2294 * Note that we'll actually follow the referral later when
2295 * we detect fsid mismatch in inode revalidation
2297 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
,
2298 struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2300 int status
= -ENOMEM
;
2301 struct page
*page
= NULL
;
2302 struct nfs4_fs_locations
*locations
= NULL
;
2304 page
= alloc_page(GFP_KERNEL
);
2307 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2308 if (locations
== NULL
)
2311 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2314 /* Make sure server returned a different fsid for the referral */
2315 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2316 dprintk("%s: server did not return a different fsid for"
2317 " a referral at %s\n", __func__
, name
->name
);
2321 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2322 nfs_fixup_referral_attributes(&locations
->fattr
);
2324 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2325 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2326 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2334 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2336 struct nfs4_getattr_arg args
= {
2338 .bitmask
= server
->attr_bitmask
,
2340 struct nfs4_getattr_res res
= {
2344 struct rpc_message msg
= {
2345 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2350 nfs_fattr_init(fattr
);
2351 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2354 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2356 struct nfs4_exception exception
= { };
2359 err
= nfs4_handle_exception(server
,
2360 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2362 } while (exception
.retry
);
2367 * The file is not closed if it is opened due to the a request to change
2368 * the size of the file. The open call will not be needed once the
2369 * VFS layer lookup-intents are implemented.
2371 * Close is called when the inode is destroyed.
2372 * If we haven't opened the file for O_WRONLY, we
2373 * need to in the size_change case to obtain a stateid.
2376 * Because OPEN is always done by name in nfsv4, it is
2377 * possible that we opened a different file by the same
2378 * name. We can recognize this race condition, but we
2379 * can't do anything about it besides returning an error.
2381 * This will be fixed with VFS changes (lookup-intent).
2384 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2385 struct iattr
*sattr
)
2387 struct inode
*inode
= dentry
->d_inode
;
2388 struct rpc_cred
*cred
= NULL
;
2389 struct nfs4_state
*state
= NULL
;
2392 if (pnfs_ld_layoutret_on_setattr(inode
))
2393 pnfs_return_layout(inode
);
2395 nfs_fattr_init(fattr
);
2397 /* Search for an existing open(O_WRITE) file */
2398 if (sattr
->ia_valid
& ATTR_FILE
) {
2399 struct nfs_open_context
*ctx
;
2401 ctx
= nfs_file_open_context(sattr
->ia_file
);
2408 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2410 nfs_setattr_update_inode(inode
, sattr
);
2414 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
2415 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2416 struct nfs_fattr
*fattr
)
2418 struct nfs_server
*server
= NFS_SERVER(dir
);
2420 struct nfs4_lookup_arg args
= {
2421 .bitmask
= server
->attr_bitmask
,
2422 .dir_fh
= NFS_FH(dir
),
2425 struct nfs4_lookup_res res
= {
2430 struct rpc_message msg
= {
2431 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2436 nfs_fattr_init(fattr
);
2438 dprintk("NFS call lookup %s\n", name
->name
);
2439 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2440 dprintk("NFS reply lookup: %d\n", status
);
2444 void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
, struct nfs_fh
*fh
)
2446 memset(fh
, 0, sizeof(struct nfs_fh
));
2447 fattr
->fsid
.major
= 1;
2448 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
2449 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_FSID
| NFS_ATTR_FATTR_MOUNTPOINT
;
2450 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
2454 static int nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
, struct qstr
*name
,
2455 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2457 struct nfs4_exception exception
= { };
2462 status
= _nfs4_proc_lookup(clnt
, dir
, name
, fhandle
, fattr
);
2464 case -NFS4ERR_BADNAME
:
2466 case -NFS4ERR_MOVED
:
2467 err
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2469 case -NFS4ERR_WRONGSEC
:
2470 nfs_fixup_secinfo_attributes(fattr
, fhandle
);
2472 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2473 status
, &exception
);
2474 } while (exception
.retry
);
2478 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2480 struct nfs_server
*server
= NFS_SERVER(inode
);
2481 struct nfs4_accessargs args
= {
2482 .fh
= NFS_FH(inode
),
2483 .bitmask
= server
->attr_bitmask
,
2485 struct nfs4_accessres res
= {
2488 struct rpc_message msg
= {
2489 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2492 .rpc_cred
= entry
->cred
,
2494 int mode
= entry
->mask
;
2498 * Determine which access bits we want to ask for...
2500 if (mode
& MAY_READ
)
2501 args
.access
|= NFS4_ACCESS_READ
;
2502 if (S_ISDIR(inode
->i_mode
)) {
2503 if (mode
& MAY_WRITE
)
2504 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2505 if (mode
& MAY_EXEC
)
2506 args
.access
|= NFS4_ACCESS_LOOKUP
;
2508 if (mode
& MAY_WRITE
)
2509 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2510 if (mode
& MAY_EXEC
)
2511 args
.access
|= NFS4_ACCESS_EXECUTE
;
2514 res
.fattr
= nfs_alloc_fattr();
2515 if (res
.fattr
== NULL
)
2518 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2521 if (res
.access
& NFS4_ACCESS_READ
)
2522 entry
->mask
|= MAY_READ
;
2523 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2524 entry
->mask
|= MAY_WRITE
;
2525 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2526 entry
->mask
|= MAY_EXEC
;
2527 nfs_refresh_inode(inode
, res
.fattr
);
2529 nfs_free_fattr(res
.fattr
);
2533 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2535 struct nfs4_exception exception
= { };
2538 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2539 _nfs4_proc_access(inode
, entry
),
2541 } while (exception
.retry
);
2546 * TODO: For the time being, we don't try to get any attributes
2547 * along with any of the zero-copy operations READ, READDIR,
2550 * In the case of the first three, we want to put the GETATTR
2551 * after the read-type operation -- this is because it is hard
2552 * to predict the length of a GETATTR response in v4, and thus
2553 * align the READ data correctly. This means that the GETATTR
2554 * may end up partially falling into the page cache, and we should
2555 * shift it into the 'tail' of the xdr_buf before processing.
2556 * To do this efficiently, we need to know the total length
2557 * of data received, which doesn't seem to be available outside
2560 * In the case of WRITE, we also want to put the GETATTR after
2561 * the operation -- in this case because we want to make sure
2562 * we get the post-operation mtime and size. This means that
2563 * we can't use xdr_encode_pages() as written: we need a variant
2564 * of it which would leave room in the 'tail' iovec.
2566 * Both of these changes to the XDR layer would in fact be quite
2567 * minor, but I decided to leave them for a subsequent patch.
2569 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2570 unsigned int pgbase
, unsigned int pglen
)
2572 struct nfs4_readlink args
= {
2573 .fh
= NFS_FH(inode
),
2578 struct nfs4_readlink_res res
;
2579 struct rpc_message msg
= {
2580 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2585 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2588 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2589 unsigned int pgbase
, unsigned int pglen
)
2591 struct nfs4_exception exception
= { };
2594 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2595 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2597 } while (exception
.retry
);
2603 * We will need to arrange for the VFS layer to provide an atomic open.
2604 * Until then, this create/open method is prone to inefficiency and race
2605 * conditions due to the lookup, create, and open VFS calls from sys_open()
2606 * placed on the wire.
2608 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2609 * The file will be opened again in the subsequent VFS open call
2610 * (nfs4_proc_file_open).
2612 * The open for read will just hang around to be used by any process that
2613 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2617 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2618 int flags
, struct nfs_open_context
*ctx
)
2620 struct dentry
*de
= dentry
;
2621 struct nfs4_state
*state
;
2622 struct rpc_cred
*cred
= NULL
;
2631 sattr
->ia_mode
&= ~current_umask();
2632 state
= nfs4_do_open(dir
, de
, fmode
, flags
, sattr
, cred
);
2634 if (IS_ERR(state
)) {
2635 status
= PTR_ERR(state
);
2638 d_add(dentry
, igrab(state
->inode
));
2639 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2643 nfs4_close_sync(state
, fmode
);
2648 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2650 struct nfs_server
*server
= NFS_SERVER(dir
);
2651 struct nfs_removeargs args
= {
2653 .name
.len
= name
->len
,
2654 .name
.name
= name
->name
,
2655 .bitmask
= server
->attr_bitmask
,
2657 struct nfs_removeres res
= {
2660 struct rpc_message msg
= {
2661 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2665 int status
= -ENOMEM
;
2667 res
.dir_attr
= nfs_alloc_fattr();
2668 if (res
.dir_attr
== NULL
)
2671 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
2673 update_changeattr(dir
, &res
.cinfo
);
2674 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2676 nfs_free_fattr(res
.dir_attr
);
2681 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2683 struct nfs4_exception exception
= { };
2686 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2687 _nfs4_proc_remove(dir
, name
),
2689 } while (exception
.retry
);
2693 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2695 struct nfs_server
*server
= NFS_SERVER(dir
);
2696 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2697 struct nfs_removeres
*res
= msg
->rpc_resp
;
2699 args
->bitmask
= server
->cache_consistency_bitmask
;
2700 res
->server
= server
;
2701 res
->seq_res
.sr_slot
= NULL
;
2702 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2705 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2707 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2709 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2711 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2713 update_changeattr(dir
, &res
->cinfo
);
2714 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2718 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2720 struct nfs_server
*server
= NFS_SERVER(dir
);
2721 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2722 struct nfs_renameres
*res
= msg
->rpc_resp
;
2724 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2725 arg
->bitmask
= server
->attr_bitmask
;
2726 res
->server
= server
;
2729 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2730 struct inode
*new_dir
)
2732 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2734 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2736 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2739 update_changeattr(old_dir
, &res
->old_cinfo
);
2740 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2741 update_changeattr(new_dir
, &res
->new_cinfo
);
2742 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2746 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2747 struct inode
*new_dir
, struct qstr
*new_name
)
2749 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2750 struct nfs_renameargs arg
= {
2751 .old_dir
= NFS_FH(old_dir
),
2752 .new_dir
= NFS_FH(new_dir
),
2753 .old_name
= old_name
,
2754 .new_name
= new_name
,
2755 .bitmask
= server
->attr_bitmask
,
2757 struct nfs_renameres res
= {
2760 struct rpc_message msg
= {
2761 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2765 int status
= -ENOMEM
;
2767 res
.old_fattr
= nfs_alloc_fattr();
2768 res
.new_fattr
= nfs_alloc_fattr();
2769 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2772 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2774 update_changeattr(old_dir
, &res
.old_cinfo
);
2775 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2776 update_changeattr(new_dir
, &res
.new_cinfo
);
2777 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2780 nfs_free_fattr(res
.new_fattr
);
2781 nfs_free_fattr(res
.old_fattr
);
2785 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2786 struct inode
*new_dir
, struct qstr
*new_name
)
2788 struct nfs4_exception exception
= { };
2791 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2792 _nfs4_proc_rename(old_dir
, old_name
,
2795 } while (exception
.retry
);
2799 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2801 struct nfs_server
*server
= NFS_SERVER(inode
);
2802 struct nfs4_link_arg arg
= {
2803 .fh
= NFS_FH(inode
),
2804 .dir_fh
= NFS_FH(dir
),
2806 .bitmask
= server
->attr_bitmask
,
2808 struct nfs4_link_res res
= {
2811 struct rpc_message msg
= {
2812 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2816 int status
= -ENOMEM
;
2818 res
.fattr
= nfs_alloc_fattr();
2819 res
.dir_attr
= nfs_alloc_fattr();
2820 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2823 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2825 update_changeattr(dir
, &res
.cinfo
);
2826 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2827 nfs_post_op_update_inode(inode
, res
.fattr
);
2830 nfs_free_fattr(res
.dir_attr
);
2831 nfs_free_fattr(res
.fattr
);
2835 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2837 struct nfs4_exception exception
= { };
2840 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2841 _nfs4_proc_link(inode
, dir
, name
),
2843 } while (exception
.retry
);
2847 struct nfs4_createdata
{
2848 struct rpc_message msg
;
2849 struct nfs4_create_arg arg
;
2850 struct nfs4_create_res res
;
2852 struct nfs_fattr fattr
;
2853 struct nfs_fattr dir_fattr
;
2856 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2857 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2859 struct nfs4_createdata
*data
;
2861 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2863 struct nfs_server
*server
= NFS_SERVER(dir
);
2865 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2866 data
->msg
.rpc_argp
= &data
->arg
;
2867 data
->msg
.rpc_resp
= &data
->res
;
2868 data
->arg
.dir_fh
= NFS_FH(dir
);
2869 data
->arg
.server
= server
;
2870 data
->arg
.name
= name
;
2871 data
->arg
.attrs
= sattr
;
2872 data
->arg
.ftype
= ftype
;
2873 data
->arg
.bitmask
= server
->attr_bitmask
;
2874 data
->res
.server
= server
;
2875 data
->res
.fh
= &data
->fh
;
2876 data
->res
.fattr
= &data
->fattr
;
2877 data
->res
.dir_fattr
= &data
->dir_fattr
;
2878 nfs_fattr_init(data
->res
.fattr
);
2879 nfs_fattr_init(data
->res
.dir_fattr
);
2884 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2886 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
2887 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
2889 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2890 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2891 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2896 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2901 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2902 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2904 struct nfs4_createdata
*data
;
2905 int status
= -ENAMETOOLONG
;
2907 if (len
> NFS4_MAXPATHLEN
)
2911 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2915 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2916 data
->arg
.u
.symlink
.pages
= &page
;
2917 data
->arg
.u
.symlink
.len
= len
;
2919 status
= nfs4_do_create(dir
, dentry
, data
);
2921 nfs4_free_createdata(data
);
2926 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2927 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2929 struct nfs4_exception exception
= { };
2932 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2933 _nfs4_proc_symlink(dir
, dentry
, page
,
2936 } while (exception
.retry
);
2940 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2941 struct iattr
*sattr
)
2943 struct nfs4_createdata
*data
;
2944 int status
= -ENOMEM
;
2946 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2950 status
= nfs4_do_create(dir
, dentry
, data
);
2952 nfs4_free_createdata(data
);
2957 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2958 struct iattr
*sattr
)
2960 struct nfs4_exception exception
= { };
2963 sattr
->ia_mode
&= ~current_umask();
2965 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2966 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2968 } while (exception
.retry
);
2972 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2973 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2975 struct inode
*dir
= dentry
->d_inode
;
2976 struct nfs4_readdir_arg args
= {
2981 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2984 struct nfs4_readdir_res res
;
2985 struct rpc_message msg
= {
2986 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2993 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2994 dentry
->d_parent
->d_name
.name
,
2995 dentry
->d_name
.name
,
2996 (unsigned long long)cookie
);
2997 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2998 res
.pgbase
= args
.pgbase
;
2999 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3001 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3002 status
+= args
.pgbase
;
3005 nfs_invalidate_atime(dir
);
3007 dprintk("%s: returns %d\n", __func__
, status
);
3011 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3012 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3014 struct nfs4_exception exception
= { };
3017 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
3018 _nfs4_proc_readdir(dentry
, cred
, cookie
,
3019 pages
, count
, plus
),
3021 } while (exception
.retry
);
3025 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3026 struct iattr
*sattr
, dev_t rdev
)
3028 struct nfs4_createdata
*data
;
3029 int mode
= sattr
->ia_mode
;
3030 int status
= -ENOMEM
;
3032 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
3033 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
3035 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3040 data
->arg
.ftype
= NF4FIFO
;
3041 else if (S_ISBLK(mode
)) {
3042 data
->arg
.ftype
= NF4BLK
;
3043 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3044 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3046 else if (S_ISCHR(mode
)) {
3047 data
->arg
.ftype
= NF4CHR
;
3048 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3049 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3052 status
= nfs4_do_create(dir
, dentry
, data
);
3054 nfs4_free_createdata(data
);
3059 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3060 struct iattr
*sattr
, dev_t rdev
)
3062 struct nfs4_exception exception
= { };
3065 sattr
->ia_mode
&= ~current_umask();
3067 err
= nfs4_handle_exception(NFS_SERVER(dir
),
3068 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
3070 } while (exception
.retry
);
3074 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3075 struct nfs_fsstat
*fsstat
)
3077 struct nfs4_statfs_arg args
= {
3079 .bitmask
= server
->attr_bitmask
,
3081 struct nfs4_statfs_res res
= {
3084 struct rpc_message msg
= {
3085 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3090 nfs_fattr_init(fsstat
->fattr
);
3091 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3094 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3096 struct nfs4_exception exception
= { };
3099 err
= nfs4_handle_exception(server
,
3100 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3102 } while (exception
.retry
);
3106 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3107 struct nfs_fsinfo
*fsinfo
)
3109 struct nfs4_fsinfo_arg args
= {
3111 .bitmask
= server
->attr_bitmask
,
3113 struct nfs4_fsinfo_res res
= {
3116 struct rpc_message msg
= {
3117 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3122 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3125 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3127 struct nfs4_exception exception
= { };
3131 err
= nfs4_handle_exception(server
,
3132 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3134 } while (exception
.retry
);
3138 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3140 nfs_fattr_init(fsinfo
->fattr
);
3141 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3144 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3145 struct nfs_pathconf
*pathconf
)
3147 struct nfs4_pathconf_arg args
= {
3149 .bitmask
= server
->attr_bitmask
,
3151 struct nfs4_pathconf_res res
= {
3152 .pathconf
= pathconf
,
3154 struct rpc_message msg
= {
3155 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3160 /* None of the pathconf attributes are mandatory to implement */
3161 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3162 memset(pathconf
, 0, sizeof(*pathconf
));
3166 nfs_fattr_init(pathconf
->fattr
);
3167 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3170 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3171 struct nfs_pathconf
*pathconf
)
3173 struct nfs4_exception exception
= { };
3177 err
= nfs4_handle_exception(server
,
3178 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3180 } while (exception
.retry
);
3184 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3186 nfs_invalidate_atime(data
->inode
);
3189 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3191 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3193 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3194 rpc_restart_call_prepare(task
);
3198 __nfs4_read_done_cb(data
);
3199 if (task
->tk_status
> 0)
3200 renew_lease(server
, data
->timestamp
);
3204 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3207 dprintk("--> %s\n", __func__
);
3209 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3212 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3213 nfs4_read_done_cb(task
, data
);
3216 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3218 data
->timestamp
= jiffies
;
3219 data
->read_done_cb
= nfs4_read_done_cb
;
3220 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3223 /* Reset the the nfs_read_data to send the read to the MDS. */
3224 void nfs4_reset_read(struct rpc_task
*task
, struct nfs_read_data
*data
)
3226 dprintk("%s Reset task for i/o through\n", __func__
);
3227 put_lseg(data
->lseg
);
3229 /* offsets will differ in the dense stripe case */
3230 data
->args
.offset
= data
->mds_offset
;
3231 data
->ds_clp
= NULL
;
3232 data
->args
.fh
= NFS_FH(data
->inode
);
3233 data
->read_done_cb
= nfs4_read_done_cb
;
3234 task
->tk_ops
= data
->mds_ops
;
3235 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3237 EXPORT_SYMBOL_GPL(nfs4_reset_read
);
3239 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3241 struct inode
*inode
= data
->inode
;
3243 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3244 rpc_restart_call_prepare(task
);
3247 if (task
->tk_status
>= 0) {
3248 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3249 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3254 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3256 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3258 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
3259 nfs4_write_done_cb(task
, data
);
3262 /* Reset the the nfs_write_data to send the write to the MDS. */
3263 void nfs4_reset_write(struct rpc_task
*task
, struct nfs_write_data
*data
)
3265 dprintk("%s Reset task for i/o through\n", __func__
);
3266 put_lseg(data
->lseg
);
3268 data
->ds_clp
= NULL
;
3269 data
->write_done_cb
= nfs4_write_done_cb
;
3270 data
->args
.fh
= NFS_FH(data
->inode
);
3271 data
->args
.bitmask
= data
->res
.server
->cache_consistency_bitmask
;
3272 data
->args
.offset
= data
->mds_offset
;
3273 data
->res
.fattr
= &data
->fattr
;
3274 task
->tk_ops
= data
->mds_ops
;
3275 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3277 EXPORT_SYMBOL_GPL(nfs4_reset_write
);
3279 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3281 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3284 data
->args
.bitmask
= NULL
;
3285 data
->res
.fattr
= NULL
;
3287 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3288 if (!data
->write_done_cb
)
3289 data
->write_done_cb
= nfs4_write_done_cb
;
3290 data
->res
.server
= server
;
3291 data
->timestamp
= jiffies
;
3293 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3296 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3298 struct inode
*inode
= data
->inode
;
3300 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3301 rpc_restart_call_prepare(task
);
3304 nfs_refresh_inode(inode
, data
->res
.fattr
);
3308 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3310 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3312 return data
->write_done_cb(task
, data
);
3315 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3317 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3320 data
->args
.bitmask
= NULL
;
3321 data
->res
.fattr
= NULL
;
3323 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3324 if (!data
->write_done_cb
)
3325 data
->write_done_cb
= nfs4_commit_done_cb
;
3326 data
->res
.server
= server
;
3327 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3330 struct nfs4_renewdata
{
3331 struct nfs_client
*client
;
3332 unsigned long timestamp
;
3336 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3337 * standalone procedure for queueing an asynchronous RENEW.
3339 static void nfs4_renew_release(void *calldata
)
3341 struct nfs4_renewdata
*data
= calldata
;
3342 struct nfs_client
*clp
= data
->client
;
3344 if (atomic_read(&clp
->cl_count
) > 1)
3345 nfs4_schedule_state_renewal(clp
);
3346 nfs_put_client(clp
);
3350 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3352 struct nfs4_renewdata
*data
= calldata
;
3353 struct nfs_client
*clp
= data
->client
;
3354 unsigned long timestamp
= data
->timestamp
;
3356 if (task
->tk_status
< 0) {
3357 /* Unless we're shutting down, schedule state recovery! */
3358 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
3360 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
3361 nfs4_schedule_lease_recovery(clp
);
3364 nfs4_schedule_path_down_recovery(clp
);
3366 do_renew_lease(clp
, timestamp
);
3369 static const struct rpc_call_ops nfs4_renew_ops
= {
3370 .rpc_call_done
= nfs4_renew_done
,
3371 .rpc_release
= nfs4_renew_release
,
3374 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
3376 struct rpc_message msg
= {
3377 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3381 struct nfs4_renewdata
*data
;
3383 if (renew_flags
== 0)
3385 if (!atomic_inc_not_zero(&clp
->cl_count
))
3387 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
3391 data
->timestamp
= jiffies
;
3392 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3393 &nfs4_renew_ops
, data
);
3396 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3398 struct rpc_message msg
= {
3399 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3403 unsigned long now
= jiffies
;
3406 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3409 do_renew_lease(clp
, now
);
3413 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3415 return (server
->caps
& NFS_CAP_ACLS
)
3416 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3417 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3420 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3421 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3424 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3426 static void buf_to_pages(const void *buf
, size_t buflen
,
3427 struct page
**pages
, unsigned int *pgbase
)
3429 const void *p
= buf
;
3431 *pgbase
= offset_in_page(buf
);
3433 while (p
< buf
+ buflen
) {
3434 *(pages
++) = virt_to_page(p
);
3435 p
+= PAGE_CACHE_SIZE
;
3439 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3440 struct page
**pages
, unsigned int *pgbase
)
3442 struct page
*newpage
, **spages
;
3448 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3449 newpage
= alloc_page(GFP_KERNEL
);
3451 if (newpage
== NULL
)
3453 memcpy(page_address(newpage
), buf
, len
);
3458 } while (buflen
!= 0);
3464 __free_page(spages
[rc
-1]);
3468 struct nfs4_cached_acl
{
3474 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3476 struct nfs_inode
*nfsi
= NFS_I(inode
);
3478 spin_lock(&inode
->i_lock
);
3479 kfree(nfsi
->nfs4_acl
);
3480 nfsi
->nfs4_acl
= acl
;
3481 spin_unlock(&inode
->i_lock
);
3484 static void nfs4_zap_acl_attr(struct inode
*inode
)
3486 nfs4_set_cached_acl(inode
, NULL
);
3489 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3491 struct nfs_inode
*nfsi
= NFS_I(inode
);
3492 struct nfs4_cached_acl
*acl
;
3495 spin_lock(&inode
->i_lock
);
3496 acl
= nfsi
->nfs4_acl
;
3499 if (buf
== NULL
) /* user is just asking for length */
3501 if (acl
->cached
== 0)
3503 ret
= -ERANGE
; /* see getxattr(2) man page */
3504 if (acl
->len
> buflen
)
3506 memcpy(buf
, acl
->data
, acl
->len
);
3510 spin_unlock(&inode
->i_lock
);
3514 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3516 struct nfs4_cached_acl
*acl
;
3518 if (buf
&& acl_len
<= PAGE_SIZE
) {
3519 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3523 memcpy(acl
->data
, buf
, acl_len
);
3525 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3532 nfs4_set_cached_acl(inode
, acl
);
3535 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3537 struct page
*pages
[NFS4ACL_MAXPAGES
];
3538 struct nfs_getaclargs args
= {
3539 .fh
= NFS_FH(inode
),
3543 struct nfs_getaclres res
= {
3547 struct rpc_message msg
= {
3548 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3552 struct page
*localpage
= NULL
;
3555 if (buflen
< PAGE_SIZE
) {
3556 /* As long as we're doing a round trip to the server anyway,
3557 * let's be prepared for a page of acl data. */
3558 localpage
= alloc_page(GFP_KERNEL
);
3559 resp_buf
= page_address(localpage
);
3560 if (localpage
== NULL
)
3562 args
.acl_pages
[0] = localpage
;
3563 args
.acl_pgbase
= 0;
3564 args
.acl_len
= PAGE_SIZE
;
3567 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3569 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3572 if (res
.acl_len
> args
.acl_len
)
3573 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3575 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3578 if (res
.acl_len
> buflen
)
3581 memcpy(buf
, resp_buf
, res
.acl_len
);
3586 __free_page(localpage
);
3590 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3592 struct nfs4_exception exception
= { };
3595 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3598 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3599 } while (exception
.retry
);
3603 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3605 struct nfs_server
*server
= NFS_SERVER(inode
);
3608 if (!nfs4_server_supports_acls(server
))
3610 ret
= nfs_revalidate_inode(server
, inode
);
3613 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3614 nfs_zap_acl_cache(inode
);
3615 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3618 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3621 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3623 struct nfs_server
*server
= NFS_SERVER(inode
);
3624 struct page
*pages
[NFS4ACL_MAXPAGES
];
3625 struct nfs_setaclargs arg
= {
3626 .fh
= NFS_FH(inode
),
3630 struct nfs_setaclres res
;
3631 struct rpc_message msg
= {
3632 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3638 if (!nfs4_server_supports_acls(server
))
3640 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3643 nfs_inode_return_delegation(inode
);
3644 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3647 * Free each page after tx, so the only ref left is
3648 * held by the network stack
3651 put_page(pages
[i
-1]);
3654 * Acl update can result in inode attribute update.
3655 * so mark the attribute cache invalid.
3657 spin_lock(&inode
->i_lock
);
3658 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3659 spin_unlock(&inode
->i_lock
);
3660 nfs_access_zap_cache(inode
);
3661 nfs_zap_acl_cache(inode
);
3665 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3667 struct nfs4_exception exception
= { };
3670 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3671 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3673 } while (exception
.retry
);
3678 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3680 struct nfs_client
*clp
= server
->nfs_client
;
3682 if (task
->tk_status
>= 0)
3684 switch(task
->tk_status
) {
3685 case -NFS4ERR_ADMIN_REVOKED
:
3686 case -NFS4ERR_BAD_STATEID
:
3687 case -NFS4ERR_OPENMODE
:
3690 nfs4_schedule_stateid_recovery(server
, state
);
3691 goto wait_on_recovery
;
3692 case -NFS4ERR_EXPIRED
:
3694 nfs4_schedule_stateid_recovery(server
, state
);
3695 case -NFS4ERR_STALE_STATEID
:
3696 case -NFS4ERR_STALE_CLIENTID
:
3697 nfs4_schedule_lease_recovery(clp
);
3698 goto wait_on_recovery
;
3699 #if defined(CONFIG_NFS_V4_1)
3700 case -NFS4ERR_BADSESSION
:
3701 case -NFS4ERR_BADSLOT
:
3702 case -NFS4ERR_BAD_HIGH_SLOT
:
3703 case -NFS4ERR_DEADSESSION
:
3704 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3705 case -NFS4ERR_SEQ_FALSE_RETRY
:
3706 case -NFS4ERR_SEQ_MISORDERED
:
3707 dprintk("%s ERROR %d, Reset session\n", __func__
,
3709 nfs4_schedule_session_recovery(clp
->cl_session
);
3710 task
->tk_status
= 0;
3712 #endif /* CONFIG_NFS_V4_1 */
3713 case -NFS4ERR_DELAY
:
3714 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3715 case -NFS4ERR_GRACE
:
3717 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3718 task
->tk_status
= 0;
3720 case -NFS4ERR_RETRY_UNCACHED_REP
:
3721 case -NFS4ERR_OLD_STATEID
:
3722 task
->tk_status
= 0;
3725 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3728 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3729 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3730 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3731 task
->tk_status
= 0;
3735 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3736 unsigned short port
, struct rpc_cred
*cred
,
3737 struct nfs4_setclientid_res
*res
)
3739 nfs4_verifier sc_verifier
;
3740 struct nfs4_setclientid setclientid
= {
3741 .sc_verifier
= &sc_verifier
,
3743 .sc_cb_ident
= clp
->cl_cb_ident
,
3745 struct rpc_message msg
= {
3746 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3747 .rpc_argp
= &setclientid
,
3755 p
= (__be32
*)sc_verifier
.data
;
3756 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3757 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3760 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3761 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3763 rpc_peeraddr2str(clp
->cl_rpcclient
,
3765 rpc_peeraddr2str(clp
->cl_rpcclient
,
3767 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3768 clp
->cl_id_uniquifier
);
3769 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3770 sizeof(setclientid
.sc_netid
),
3771 rpc_peeraddr2str(clp
->cl_rpcclient
,
3772 RPC_DISPLAY_NETID
));
3773 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3774 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3775 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3777 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3778 if (status
!= -NFS4ERR_CLID_INUSE
)
3781 ++clp
->cl_id_uniquifier
;
3785 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3790 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3791 struct nfs4_setclientid_res
*arg
,
3792 struct rpc_cred
*cred
)
3794 struct nfs_fsinfo fsinfo
;
3795 struct rpc_message msg
= {
3796 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3798 .rpc_resp
= &fsinfo
,
3805 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3807 spin_lock(&clp
->cl_lock
);
3808 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3809 clp
->cl_last_renewal
= now
;
3810 spin_unlock(&clp
->cl_lock
);
3815 struct nfs4_delegreturndata
{
3816 struct nfs4_delegreturnargs args
;
3817 struct nfs4_delegreturnres res
;
3819 nfs4_stateid stateid
;
3820 unsigned long timestamp
;
3821 struct nfs_fattr fattr
;
3825 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3827 struct nfs4_delegreturndata
*data
= calldata
;
3829 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3832 switch (task
->tk_status
) {
3833 case -NFS4ERR_STALE_STATEID
:
3834 case -NFS4ERR_EXPIRED
:
3836 renew_lease(data
->res
.server
, data
->timestamp
);
3839 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3841 rpc_restart_call_prepare(task
);
3845 data
->rpc_status
= task
->tk_status
;
3848 static void nfs4_delegreturn_release(void *calldata
)
3853 #if defined(CONFIG_NFS_V4_1)
3854 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3856 struct nfs4_delegreturndata
*d_data
;
3858 d_data
= (struct nfs4_delegreturndata
*)data
;
3860 if (nfs4_setup_sequence(d_data
->res
.server
,
3861 &d_data
->args
.seq_args
,
3862 &d_data
->res
.seq_res
, 1, task
))
3864 rpc_call_start(task
);
3866 #endif /* CONFIG_NFS_V4_1 */
3868 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3869 #if defined(CONFIG_NFS_V4_1)
3870 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3871 #endif /* CONFIG_NFS_V4_1 */
3872 .rpc_call_done
= nfs4_delegreturn_done
,
3873 .rpc_release
= nfs4_delegreturn_release
,
3876 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3878 struct nfs4_delegreturndata
*data
;
3879 struct nfs_server
*server
= NFS_SERVER(inode
);
3880 struct rpc_task
*task
;
3881 struct rpc_message msg
= {
3882 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3885 struct rpc_task_setup task_setup_data
= {
3886 .rpc_client
= server
->client
,
3887 .rpc_message
= &msg
,
3888 .callback_ops
= &nfs4_delegreturn_ops
,
3889 .flags
= RPC_TASK_ASYNC
,
3893 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3896 data
->args
.fhandle
= &data
->fh
;
3897 data
->args
.stateid
= &data
->stateid
;
3898 data
->args
.bitmask
= server
->attr_bitmask
;
3899 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3900 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3901 data
->res
.fattr
= &data
->fattr
;
3902 data
->res
.server
= server
;
3903 nfs_fattr_init(data
->res
.fattr
);
3904 data
->timestamp
= jiffies
;
3905 data
->rpc_status
= 0;
3907 task_setup_data
.callback_data
= data
;
3908 msg
.rpc_argp
= &data
->args
;
3909 msg
.rpc_resp
= &data
->res
;
3910 task
= rpc_run_task(&task_setup_data
);
3912 return PTR_ERR(task
);
3915 status
= nfs4_wait_for_completion_rpc_task(task
);
3918 status
= data
->rpc_status
;
3921 nfs_refresh_inode(inode
, &data
->fattr
);
3927 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3929 struct nfs_server
*server
= NFS_SERVER(inode
);
3930 struct nfs4_exception exception
= { };
3933 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3935 case -NFS4ERR_STALE_STATEID
:
3936 case -NFS4ERR_EXPIRED
:
3940 err
= nfs4_handle_exception(server
, err
, &exception
);
3941 } while (exception
.retry
);
3945 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3946 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3949 * sleep, with exponential backoff, and retry the LOCK operation.
3951 static unsigned long
3952 nfs4_set_lock_task_retry(unsigned long timeout
)
3954 schedule_timeout_killable(timeout
);
3956 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3957 return NFS4_LOCK_MAXTIMEOUT
;
3961 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3963 struct inode
*inode
= state
->inode
;
3964 struct nfs_server
*server
= NFS_SERVER(inode
);
3965 struct nfs_client
*clp
= server
->nfs_client
;
3966 struct nfs_lockt_args arg
= {
3967 .fh
= NFS_FH(inode
),
3970 struct nfs_lockt_res res
= {
3973 struct rpc_message msg
= {
3974 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3977 .rpc_cred
= state
->owner
->so_cred
,
3979 struct nfs4_lock_state
*lsp
;
3982 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3983 status
= nfs4_set_lock_state(state
, request
);
3986 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3987 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3988 arg
.lock_owner
.s_dev
= server
->s_dev
;
3989 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3992 request
->fl_type
= F_UNLCK
;
3994 case -NFS4ERR_DENIED
:
3997 request
->fl_ops
->fl_release_private(request
);
4002 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4004 struct nfs4_exception exception
= { };
4008 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4009 _nfs4_proc_getlk(state
, cmd
, request
),
4011 } while (exception
.retry
);
4015 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
4018 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
4020 res
= posix_lock_file_wait(file
, fl
);
4023 res
= flock_lock_file_wait(file
, fl
);
4031 struct nfs4_unlockdata
{
4032 struct nfs_locku_args arg
;
4033 struct nfs_locku_res res
;
4034 struct nfs4_lock_state
*lsp
;
4035 struct nfs_open_context
*ctx
;
4036 struct file_lock fl
;
4037 const struct nfs_server
*server
;
4038 unsigned long timestamp
;
4041 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
4042 struct nfs_open_context
*ctx
,
4043 struct nfs4_lock_state
*lsp
,
4044 struct nfs_seqid
*seqid
)
4046 struct nfs4_unlockdata
*p
;
4047 struct inode
*inode
= lsp
->ls_state
->inode
;
4049 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
4052 p
->arg
.fh
= NFS_FH(inode
);
4054 p
->arg
.seqid
= seqid
;
4055 p
->res
.seqid
= seqid
;
4056 p
->arg
.stateid
= &lsp
->ls_stateid
;
4058 atomic_inc(&lsp
->ls_count
);
4059 /* Ensure we don't close file until we're done freeing locks! */
4060 p
->ctx
= get_nfs_open_context(ctx
);
4061 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4062 p
->server
= NFS_SERVER(inode
);
4066 static void nfs4_locku_release_calldata(void *data
)
4068 struct nfs4_unlockdata
*calldata
= data
;
4069 nfs_free_seqid(calldata
->arg
.seqid
);
4070 nfs4_put_lock_state(calldata
->lsp
);
4071 put_nfs_open_context(calldata
->ctx
);
4075 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
4077 struct nfs4_unlockdata
*calldata
= data
;
4079 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
4081 switch (task
->tk_status
) {
4083 memcpy(calldata
->lsp
->ls_stateid
.data
,
4084 calldata
->res
.stateid
.data
,
4085 sizeof(calldata
->lsp
->ls_stateid
.data
));
4086 renew_lease(calldata
->server
, calldata
->timestamp
);
4088 case -NFS4ERR_BAD_STATEID
:
4089 case -NFS4ERR_OLD_STATEID
:
4090 case -NFS4ERR_STALE_STATEID
:
4091 case -NFS4ERR_EXPIRED
:
4094 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
4095 rpc_restart_call_prepare(task
);
4099 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
4101 struct nfs4_unlockdata
*calldata
= data
;
4103 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
4105 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
4106 /* Note: exit _without_ running nfs4_locku_done */
4107 task
->tk_action
= NULL
;
4110 calldata
->timestamp
= jiffies
;
4111 if (nfs4_setup_sequence(calldata
->server
,
4112 &calldata
->arg
.seq_args
,
4113 &calldata
->res
.seq_res
, 1, task
))
4115 rpc_call_start(task
);
4118 static const struct rpc_call_ops nfs4_locku_ops
= {
4119 .rpc_call_prepare
= nfs4_locku_prepare
,
4120 .rpc_call_done
= nfs4_locku_done
,
4121 .rpc_release
= nfs4_locku_release_calldata
,
4124 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
4125 struct nfs_open_context
*ctx
,
4126 struct nfs4_lock_state
*lsp
,
4127 struct nfs_seqid
*seqid
)
4129 struct nfs4_unlockdata
*data
;
4130 struct rpc_message msg
= {
4131 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
4132 .rpc_cred
= ctx
->cred
,
4134 struct rpc_task_setup task_setup_data
= {
4135 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
4136 .rpc_message
= &msg
,
4137 .callback_ops
= &nfs4_locku_ops
,
4138 .workqueue
= nfsiod_workqueue
,
4139 .flags
= RPC_TASK_ASYNC
,
4142 /* Ensure this is an unlock - when canceling a lock, the
4143 * canceled lock is passed in, and it won't be an unlock.
4145 fl
->fl_type
= F_UNLCK
;
4147 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
4149 nfs_free_seqid(seqid
);
4150 return ERR_PTR(-ENOMEM
);
4153 msg
.rpc_argp
= &data
->arg
;
4154 msg
.rpc_resp
= &data
->res
;
4155 task_setup_data
.callback_data
= data
;
4156 return rpc_run_task(&task_setup_data
);
4159 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4161 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4162 struct nfs_seqid
*seqid
;
4163 struct nfs4_lock_state
*lsp
;
4164 struct rpc_task
*task
;
4166 unsigned char fl_flags
= request
->fl_flags
;
4168 status
= nfs4_set_lock_state(state
, request
);
4169 /* Unlock _before_ we do the RPC call */
4170 request
->fl_flags
|= FL_EXISTS
;
4171 down_read(&nfsi
->rwsem
);
4172 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4173 up_read(&nfsi
->rwsem
);
4176 up_read(&nfsi
->rwsem
);
4179 /* Is this a delegated lock? */
4180 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4182 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4183 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4187 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4188 status
= PTR_ERR(task
);
4191 status
= nfs4_wait_for_completion_rpc_task(task
);
4194 request
->fl_flags
= fl_flags
;
4198 struct nfs4_lockdata
{
4199 struct nfs_lock_args arg
;
4200 struct nfs_lock_res res
;
4201 struct nfs4_lock_state
*lsp
;
4202 struct nfs_open_context
*ctx
;
4203 struct file_lock fl
;
4204 unsigned long timestamp
;
4207 struct nfs_server
*server
;
4210 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4211 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4214 struct nfs4_lockdata
*p
;
4215 struct inode
*inode
= lsp
->ls_state
->inode
;
4216 struct nfs_server
*server
= NFS_SERVER(inode
);
4218 p
= kzalloc(sizeof(*p
), gfp_mask
);
4222 p
->arg
.fh
= NFS_FH(inode
);
4224 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4225 if (p
->arg
.open_seqid
== NULL
)
4227 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4228 if (p
->arg
.lock_seqid
== NULL
)
4229 goto out_free_seqid
;
4230 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4231 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4232 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4233 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4234 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4237 atomic_inc(&lsp
->ls_count
);
4238 p
->ctx
= get_nfs_open_context(ctx
);
4239 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4242 nfs_free_seqid(p
->arg
.open_seqid
);
4248 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4250 struct nfs4_lockdata
*data
= calldata
;
4251 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4253 dprintk("%s: begin!\n", __func__
);
4254 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4256 /* Do we need to do an open_to_lock_owner? */
4257 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4258 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4260 data
->arg
.open_stateid
= &state
->stateid
;
4261 data
->arg
.new_lock_owner
= 1;
4262 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4264 data
->arg
.new_lock_owner
= 0;
4265 data
->timestamp
= jiffies
;
4266 if (nfs4_setup_sequence(data
->server
,
4267 &data
->arg
.seq_args
,
4268 &data
->res
.seq_res
, 1, task
))
4270 rpc_call_start(task
);
4271 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4274 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4276 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4277 nfs4_lock_prepare(task
, calldata
);
4280 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4282 struct nfs4_lockdata
*data
= calldata
;
4284 dprintk("%s: begin!\n", __func__
);
4286 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4289 data
->rpc_status
= task
->tk_status
;
4290 if (data
->arg
.new_lock_owner
!= 0) {
4291 if (data
->rpc_status
== 0)
4292 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4296 if (data
->rpc_status
== 0) {
4297 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4298 sizeof(data
->lsp
->ls_stateid
.data
));
4299 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4300 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
4303 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4306 static void nfs4_lock_release(void *calldata
)
4308 struct nfs4_lockdata
*data
= calldata
;
4310 dprintk("%s: begin!\n", __func__
);
4311 nfs_free_seqid(data
->arg
.open_seqid
);
4312 if (data
->cancelled
!= 0) {
4313 struct rpc_task
*task
;
4314 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4315 data
->arg
.lock_seqid
);
4317 rpc_put_task_async(task
);
4318 dprintk("%s: cancelling lock!\n", __func__
);
4320 nfs_free_seqid(data
->arg
.lock_seqid
);
4321 nfs4_put_lock_state(data
->lsp
);
4322 put_nfs_open_context(data
->ctx
);
4324 dprintk("%s: done!\n", __func__
);
4327 static const struct rpc_call_ops nfs4_lock_ops
= {
4328 .rpc_call_prepare
= nfs4_lock_prepare
,
4329 .rpc_call_done
= nfs4_lock_done
,
4330 .rpc_release
= nfs4_lock_release
,
4333 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4334 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4335 .rpc_call_done
= nfs4_lock_done
,
4336 .rpc_release
= nfs4_lock_release
,
4339 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4342 case -NFS4ERR_ADMIN_REVOKED
:
4343 case -NFS4ERR_BAD_STATEID
:
4344 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4345 if (new_lock_owner
!= 0 ||
4346 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4347 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
4349 case -NFS4ERR_STALE_STATEID
:
4350 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4351 case -NFS4ERR_EXPIRED
:
4352 nfs4_schedule_lease_recovery(server
->nfs_client
);
4356 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4358 struct nfs4_lockdata
*data
;
4359 struct rpc_task
*task
;
4360 struct rpc_message msg
= {
4361 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4362 .rpc_cred
= state
->owner
->so_cred
,
4364 struct rpc_task_setup task_setup_data
= {
4365 .rpc_client
= NFS_CLIENT(state
->inode
),
4366 .rpc_message
= &msg
,
4367 .callback_ops
= &nfs4_lock_ops
,
4368 .workqueue
= nfsiod_workqueue
,
4369 .flags
= RPC_TASK_ASYNC
,
4373 dprintk("%s: begin!\n", __func__
);
4374 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4375 fl
->fl_u
.nfs4_fl
.owner
,
4376 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4380 data
->arg
.block
= 1;
4381 if (recovery_type
> NFS_LOCK_NEW
) {
4382 if (recovery_type
== NFS_LOCK_RECLAIM
)
4383 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4384 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4386 msg
.rpc_argp
= &data
->arg
;
4387 msg
.rpc_resp
= &data
->res
;
4388 task_setup_data
.callback_data
= data
;
4389 task
= rpc_run_task(&task_setup_data
);
4391 return PTR_ERR(task
);
4392 ret
= nfs4_wait_for_completion_rpc_task(task
);
4394 ret
= data
->rpc_status
;
4396 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4397 data
->arg
.new_lock_owner
, ret
);
4399 data
->cancelled
= 1;
4401 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4405 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4407 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4408 struct nfs4_exception exception
= { };
4412 /* Cache the lock if possible... */
4413 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4415 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4416 if (err
!= -NFS4ERR_DELAY
)
4418 nfs4_handle_exception(server
, err
, &exception
);
4419 } while (exception
.retry
);
4423 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4425 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4426 struct nfs4_exception exception
= { };
4429 err
= nfs4_set_lock_state(state
, request
);
4433 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4435 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4439 case -NFS4ERR_GRACE
:
4440 case -NFS4ERR_DELAY
:
4441 nfs4_handle_exception(server
, err
, &exception
);
4444 } while (exception
.retry
);
4449 #if defined(CONFIG_NFS_V4_1)
4450 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4453 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4455 status
= nfs41_test_stateid(server
, state
);
4456 if (status
== NFS_OK
)
4458 nfs41_free_stateid(server
, state
);
4459 return nfs4_lock_expired(state
, request
);
4463 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4465 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4466 unsigned char fl_flags
= request
->fl_flags
;
4467 int status
= -ENOLCK
;
4469 if ((fl_flags
& FL_POSIX
) &&
4470 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4472 /* Is this a delegated open? */
4473 status
= nfs4_set_lock_state(state
, request
);
4476 request
->fl_flags
|= FL_ACCESS
;
4477 status
= do_vfs_lock(request
->fl_file
, request
);
4480 down_read(&nfsi
->rwsem
);
4481 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4482 /* Yes: cache locks! */
4483 /* ...but avoid races with delegation recall... */
4484 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4485 status
= do_vfs_lock(request
->fl_file
, request
);
4488 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4491 /* Note: we always want to sleep here! */
4492 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4493 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4494 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4496 up_read(&nfsi
->rwsem
);
4498 request
->fl_flags
= fl_flags
;
4502 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4504 struct nfs4_exception exception
= { };
4508 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4509 if (err
== -NFS4ERR_DENIED
)
4511 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4513 } while (exception
.retry
);
4518 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4520 struct nfs_open_context
*ctx
;
4521 struct nfs4_state
*state
;
4522 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4525 /* verify open state */
4526 ctx
= nfs_file_open_context(filp
);
4529 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4532 if (IS_GETLK(cmd
)) {
4534 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4538 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4541 if (request
->fl_type
== F_UNLCK
) {
4543 return nfs4_proc_unlck(state
, cmd
, request
);
4550 status
= nfs4_proc_setlk(state
, cmd
, request
);
4551 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4553 timeout
= nfs4_set_lock_task_retry(timeout
);
4554 status
= -ERESTARTSYS
;
4557 } while(status
< 0);
4561 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4563 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4564 struct nfs4_exception exception
= { };
4567 err
= nfs4_set_lock_state(state
, fl
);
4571 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4574 printk(KERN_ERR
"%s: unhandled error %d.\n",
4579 case -NFS4ERR_EXPIRED
:
4580 nfs4_schedule_stateid_recovery(server
, state
);
4581 case -NFS4ERR_STALE_CLIENTID
:
4582 case -NFS4ERR_STALE_STATEID
:
4583 nfs4_schedule_lease_recovery(server
->nfs_client
);
4585 case -NFS4ERR_BADSESSION
:
4586 case -NFS4ERR_BADSLOT
:
4587 case -NFS4ERR_BAD_HIGH_SLOT
:
4588 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4589 case -NFS4ERR_DEADSESSION
:
4590 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4594 * The show must go on: exit, but mark the
4595 * stateid as needing recovery.
4597 case -NFS4ERR_ADMIN_REVOKED
:
4598 case -NFS4ERR_BAD_STATEID
:
4599 case -NFS4ERR_OPENMODE
:
4600 nfs4_schedule_stateid_recovery(server
, state
);
4605 * User RPCSEC_GSS context has expired.
4606 * We cannot recover this stateid now, so
4607 * skip it and allow recovery thread to
4613 case -NFS4ERR_DENIED
:
4614 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4617 case -NFS4ERR_DELAY
:
4620 err
= nfs4_handle_exception(server
, err
, &exception
);
4621 } while (exception
.retry
);
4626 static void nfs4_release_lockowner_release(void *calldata
)
4631 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4632 .rpc_release
= nfs4_release_lockowner_release
,
4635 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4637 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4638 struct nfs_release_lockowner_args
*args
;
4639 struct rpc_message msg
= {
4640 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4643 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4645 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4648 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4649 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4650 args
->lock_owner
.s_dev
= server
->s_dev
;
4651 msg
.rpc_argp
= args
;
4652 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4655 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4657 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4658 const void *buf
, size_t buflen
,
4659 int flags
, int type
)
4661 if (strcmp(key
, "") != 0)
4664 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4667 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4668 void *buf
, size_t buflen
, int type
)
4670 if (strcmp(key
, "") != 0)
4673 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4676 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4677 size_t list_len
, const char *name
,
4678 size_t name_len
, int type
)
4680 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4682 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4685 if (list
&& len
<= list_len
)
4686 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4691 * nfs_fhget will use either the mounted_on_fileid or the fileid
4693 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4695 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
4696 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
4697 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4698 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4701 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4702 NFS_ATTR_FATTR_NLINK
;
4703 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4707 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4708 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4710 struct nfs_server
*server
= NFS_SERVER(dir
);
4712 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4714 struct nfs4_fs_locations_arg args
= {
4715 .dir_fh
= NFS_FH(dir
),
4720 struct nfs4_fs_locations_res res
= {
4721 .fs_locations
= fs_locations
,
4723 struct rpc_message msg
= {
4724 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4730 dprintk("%s: start\n", __func__
);
4732 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
4733 * is not supported */
4734 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
4735 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
4737 bitmask
[0] |= FATTR4_WORD0_FILEID
;
4739 nfs_fattr_init(&fs_locations
->fattr
);
4740 fs_locations
->server
= server
;
4741 fs_locations
->nlocations
= 0;
4742 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4743 dprintk("%s: returned status = %d\n", __func__
, status
);
4747 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4750 struct nfs4_secinfo_arg args
= {
4751 .dir_fh
= NFS_FH(dir
),
4754 struct nfs4_secinfo_res res
= {
4757 struct rpc_message msg
= {
4758 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
4763 dprintk("NFS call secinfo %s\n", name
->name
);
4764 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4765 dprintk("NFS reply secinfo: %d\n", status
);
4769 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4771 struct nfs4_exception exception
= { };
4774 err
= nfs4_handle_exception(NFS_SERVER(dir
),
4775 _nfs4_proc_secinfo(dir
, name
, flavors
),
4777 } while (exception
.retry
);
4781 #ifdef CONFIG_NFS_V4_1
4783 * Check the exchange flags returned by the server for invalid flags, having
4784 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4787 static int nfs4_check_cl_exchange_flags(u32 flags
)
4789 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4791 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4792 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4794 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4798 return -NFS4ERR_INVAL
;
4802 nfs41_same_server_scope(struct server_scope
*a
, struct server_scope
*b
)
4804 if (a
->server_scope_sz
== b
->server_scope_sz
&&
4805 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
4812 * nfs4_proc_exchange_id()
4814 * Since the clientid has expired, all compounds using sessions
4815 * associated with the stale clientid will be returning
4816 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4817 * be in some phase of session reset.
4819 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4821 nfs4_verifier verifier
;
4822 struct nfs41_exchange_id_args args
= {
4824 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4826 struct nfs41_exchange_id_res res
= {
4830 struct rpc_message msg
= {
4831 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4838 dprintk("--> %s\n", __func__
);
4839 BUG_ON(clp
== NULL
);
4841 p
= (u32
*)verifier
.data
;
4842 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4843 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4844 args
.verifier
= &verifier
;
4846 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4849 init_utsname()->nodename
,
4850 init_utsname()->domainname
,
4851 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4853 res
.server_scope
= kzalloc(sizeof(struct server_scope
), GFP_KERNEL
);
4854 if (unlikely(!res
.server_scope
))
4857 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4859 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4862 if (clp
->server_scope
&&
4863 !nfs41_same_server_scope(clp
->server_scope
,
4864 res
.server_scope
)) {
4865 dprintk("%s: server_scope mismatch detected\n",
4867 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
4868 kfree(clp
->server_scope
);
4869 clp
->server_scope
= NULL
;
4872 if (!clp
->server_scope
)
4873 clp
->server_scope
= res
.server_scope
;
4875 kfree(res
.server_scope
);
4878 dprintk("<-- %s status= %d\n", __func__
, status
);
4882 struct nfs4_get_lease_time_data
{
4883 struct nfs4_get_lease_time_args
*args
;
4884 struct nfs4_get_lease_time_res
*res
;
4885 struct nfs_client
*clp
;
4888 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4892 struct nfs4_get_lease_time_data
*data
=
4893 (struct nfs4_get_lease_time_data
*)calldata
;
4895 dprintk("--> %s\n", __func__
);
4896 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4897 /* just setup sequence, do not trigger session recovery
4898 since we're invoked within one */
4899 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4900 &data
->args
->la_seq_args
,
4901 &data
->res
->lr_seq_res
, 0, task
);
4903 BUG_ON(ret
== -EAGAIN
);
4904 rpc_call_start(task
);
4905 dprintk("<-- %s\n", __func__
);
4909 * Called from nfs4_state_manager thread for session setup, so don't recover
4910 * from sequence operation or clientid errors.
4912 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4914 struct nfs4_get_lease_time_data
*data
=
4915 (struct nfs4_get_lease_time_data
*)calldata
;
4917 dprintk("--> %s\n", __func__
);
4918 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4920 switch (task
->tk_status
) {
4921 case -NFS4ERR_DELAY
:
4922 case -NFS4ERR_GRACE
:
4923 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4924 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4925 task
->tk_status
= 0;
4927 case -NFS4ERR_RETRY_UNCACHED_REP
:
4928 rpc_restart_call_prepare(task
);
4931 dprintk("<-- %s\n", __func__
);
4934 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4935 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4936 .rpc_call_done
= nfs4_get_lease_time_done
,
4939 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4941 struct rpc_task
*task
;
4942 struct nfs4_get_lease_time_args args
;
4943 struct nfs4_get_lease_time_res res
= {
4944 .lr_fsinfo
= fsinfo
,
4946 struct nfs4_get_lease_time_data data
= {
4951 struct rpc_message msg
= {
4952 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4956 struct rpc_task_setup task_setup
= {
4957 .rpc_client
= clp
->cl_rpcclient
,
4958 .rpc_message
= &msg
,
4959 .callback_ops
= &nfs4_get_lease_time_ops
,
4960 .callback_data
= &data
,
4961 .flags
= RPC_TASK_TIMEOUT
,
4965 dprintk("--> %s\n", __func__
);
4966 task
= rpc_run_task(&task_setup
);
4969 status
= PTR_ERR(task
);
4971 status
= task
->tk_status
;
4974 dprintk("<-- %s return %d\n", __func__
, status
);
4980 * Reset a slot table
4982 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
4985 struct nfs4_slot
*new = NULL
;
4989 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
4990 max_reqs
, tbl
->max_slots
);
4992 /* Does the newly negotiated max_reqs match the existing slot table? */
4993 if (max_reqs
!= tbl
->max_slots
) {
4995 new = kmalloc(max_reqs
* sizeof(struct nfs4_slot
),
5002 spin_lock(&tbl
->slot_tbl_lock
);
5005 tbl
->max_slots
= max_reqs
;
5007 for (i
= 0; i
< tbl
->max_slots
; ++i
)
5008 tbl
->slots
[i
].seq_nr
= ivalue
;
5009 spin_unlock(&tbl
->slot_tbl_lock
);
5010 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
5011 tbl
, tbl
->slots
, tbl
->max_slots
);
5013 dprintk("<-- %s: return %d\n", __func__
, ret
);
5018 * Reset the forechannel and backchannel slot tables
5020 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
5024 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
5025 session
->fc_attrs
.max_reqs
, 1);
5029 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
5030 session
->bc_attrs
.max_reqs
, 0);
5034 /* Destroy the slot table */
5035 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
5037 if (session
->fc_slot_table
.slots
!= NULL
) {
5038 kfree(session
->fc_slot_table
.slots
);
5039 session
->fc_slot_table
.slots
= NULL
;
5041 if (session
->bc_slot_table
.slots
!= NULL
) {
5042 kfree(session
->bc_slot_table
.slots
);
5043 session
->bc_slot_table
.slots
= NULL
;
5049 * Initialize slot table
5051 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
5052 int max_slots
, int ivalue
)
5054 struct nfs4_slot
*slot
;
5057 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
5059 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
5061 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_NOFS
);
5066 spin_lock(&tbl
->slot_tbl_lock
);
5067 tbl
->max_slots
= max_slots
;
5069 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
5070 spin_unlock(&tbl
->slot_tbl_lock
);
5071 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
5072 tbl
, tbl
->slots
, tbl
->max_slots
);
5074 dprintk("<-- %s: return %d\n", __func__
, ret
);
5079 * Initialize the forechannel and backchannel tables
5081 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
5083 struct nfs4_slot_table
*tbl
;
5086 tbl
= &session
->fc_slot_table
;
5087 if (tbl
->slots
== NULL
) {
5088 status
= nfs4_init_slot_table(tbl
,
5089 session
->fc_attrs
.max_reqs
, 1);
5094 tbl
= &session
->bc_slot_table
;
5095 if (tbl
->slots
== NULL
) {
5096 status
= nfs4_init_slot_table(tbl
,
5097 session
->bc_attrs
.max_reqs
, 0);
5099 nfs4_destroy_slot_tables(session
);
5105 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
5107 struct nfs4_session
*session
;
5108 struct nfs4_slot_table
*tbl
;
5110 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5114 tbl
= &session
->fc_slot_table
;
5115 tbl
->highest_used_slotid
= -1;
5116 spin_lock_init(&tbl
->slot_tbl_lock
);
5117 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
5118 init_completion(&tbl
->complete
);
5120 tbl
= &session
->bc_slot_table
;
5121 tbl
->highest_used_slotid
= -1;
5122 spin_lock_init(&tbl
->slot_tbl_lock
);
5123 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
5124 init_completion(&tbl
->complete
);
5126 session
->session_state
= 1<<NFS4_SESSION_INITING
;
5132 void nfs4_destroy_session(struct nfs4_session
*session
)
5134 nfs4_proc_destroy_session(session
);
5135 dprintk("%s Destroy backchannel for xprt %p\n",
5136 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
5137 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
5138 NFS41_BC_MIN_CALLBACKS
);
5139 nfs4_destroy_slot_tables(session
);
5144 * Initialize the values to be used by the client in CREATE_SESSION
5145 * If nfs4_init_session set the fore channel request and response sizes,
5148 * Set the back channel max_resp_sz_cached to zero to force the client to
5149 * always set csa_cachethis to FALSE because the current implementation
5150 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5152 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
5154 struct nfs4_session
*session
= args
->client
->cl_session
;
5155 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
5156 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
5159 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
5161 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
5162 /* Fore channel attributes */
5163 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
5164 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
5165 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
5166 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
5168 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5169 "max_ops=%u max_reqs=%u\n",
5171 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
5172 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
5174 /* Back channel attributes */
5175 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
5176 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
5177 args
->bc_attrs
.max_resp_sz_cached
= 0;
5178 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
5179 args
->bc_attrs
.max_reqs
= 1;
5181 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5182 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5184 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
5185 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
5186 args
->bc_attrs
.max_reqs
);
5189 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5191 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
5192 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
5194 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
5197 * Our requested max_ops is the minimum we need; we're not
5198 * prepared to break up compounds into smaller pieces than that.
5199 * So, no point even trying to continue if the server won't
5202 if (rcvd
->max_ops
< sent
->max_ops
)
5204 if (rcvd
->max_reqs
== 0)
5209 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5211 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
5212 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
5214 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
5216 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
5218 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
5220 /* These would render the backchannel useless: */
5221 if (rcvd
->max_ops
== 0)
5223 if (rcvd
->max_reqs
== 0)
5228 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
5229 struct nfs4_session
*session
)
5233 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
5236 return nfs4_verify_back_channel_attrs(args
, session
);
5239 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
5241 struct nfs4_session
*session
= clp
->cl_session
;
5242 struct nfs41_create_session_args args
= {
5244 .cb_program
= NFS4_CALLBACK
,
5246 struct nfs41_create_session_res res
= {
5249 struct rpc_message msg
= {
5250 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5256 nfs4_init_channel_attrs(&args
);
5257 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5259 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5262 /* Verify the session's negotiated channel_attrs values */
5263 status
= nfs4_verify_channel_attrs(&args
, session
);
5265 /* Increment the clientid slot sequence id */
5273 * Issues a CREATE_SESSION operation to the server.
5274 * It is the responsibility of the caller to verify the session is
5275 * expired before calling this routine.
5277 int nfs4_proc_create_session(struct nfs_client
*clp
)
5281 struct nfs4_session
*session
= clp
->cl_session
;
5283 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5285 status
= _nfs4_proc_create_session(clp
);
5289 /* Init and reset the fore channel */
5290 status
= nfs4_init_slot_tables(session
);
5291 dprintk("slot table initialization returned %d\n", status
);
5294 status
= nfs4_reset_slot_tables(session
);
5295 dprintk("slot table reset returned %d\n", status
);
5299 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5300 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5301 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5303 dprintk("<-- %s\n", __func__
);
5308 * Issue the over-the-wire RPC DESTROY_SESSION.
5309 * The caller must serialize access to this routine.
5311 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5314 struct rpc_message msg
;
5316 dprintk("--> nfs4_proc_destroy_session\n");
5318 /* session is still being setup */
5319 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5322 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5323 msg
.rpc_argp
= session
;
5324 msg
.rpc_resp
= NULL
;
5325 msg
.rpc_cred
= NULL
;
5326 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5330 "Got error %d from the server on DESTROY_SESSION. "
5331 "Session has been destroyed regardless...\n", status
);
5333 dprintk("<-- nfs4_proc_destroy_session\n");
5337 int nfs4_init_session(struct nfs_server
*server
)
5339 struct nfs_client
*clp
= server
->nfs_client
;
5340 struct nfs4_session
*session
;
5341 unsigned int rsize
, wsize
;
5344 if (!nfs4_has_session(clp
))
5347 session
= clp
->cl_session
;
5348 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5351 rsize
= server
->rsize
;
5353 rsize
= NFS_MAX_FILE_IO_SIZE
;
5354 wsize
= server
->wsize
;
5356 wsize
= NFS_MAX_FILE_IO_SIZE
;
5358 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5359 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5361 ret
= nfs4_recover_expired_lease(server
);
5363 ret
= nfs4_check_client_ready(clp
);
5367 int nfs4_init_ds_session(struct nfs_client
*clp
)
5369 struct nfs4_session
*session
= clp
->cl_session
;
5372 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5375 ret
= nfs4_client_recover_expired_lease(clp
);
5377 /* Test for the DS role */
5378 if (!is_ds_client(clp
))
5381 ret
= nfs4_check_client_ready(clp
);
5385 EXPORT_SYMBOL_GPL(nfs4_init_ds_session
);
5389 * Renew the cl_session lease.
5391 struct nfs4_sequence_data
{
5392 struct nfs_client
*clp
;
5393 struct nfs4_sequence_args args
;
5394 struct nfs4_sequence_res res
;
5397 static void nfs41_sequence_release(void *data
)
5399 struct nfs4_sequence_data
*calldata
= data
;
5400 struct nfs_client
*clp
= calldata
->clp
;
5402 if (atomic_read(&clp
->cl_count
) > 1)
5403 nfs4_schedule_state_renewal(clp
);
5404 nfs_put_client(clp
);
5408 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5410 switch(task
->tk_status
) {
5411 case -NFS4ERR_DELAY
:
5412 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5415 nfs4_schedule_lease_recovery(clp
);
5420 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5422 struct nfs4_sequence_data
*calldata
= data
;
5423 struct nfs_client
*clp
= calldata
->clp
;
5425 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5428 if (task
->tk_status
< 0) {
5429 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5430 if (atomic_read(&clp
->cl_count
) == 1)
5433 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5434 rpc_restart_call_prepare(task
);
5438 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5440 dprintk("<-- %s\n", __func__
);
5443 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5445 struct nfs4_sequence_data
*calldata
= data
;
5446 struct nfs_client
*clp
= calldata
->clp
;
5447 struct nfs4_sequence_args
*args
;
5448 struct nfs4_sequence_res
*res
;
5450 args
= task
->tk_msg
.rpc_argp
;
5451 res
= task
->tk_msg
.rpc_resp
;
5453 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5455 rpc_call_start(task
);
5458 static const struct rpc_call_ops nfs41_sequence_ops
= {
5459 .rpc_call_done
= nfs41_sequence_call_done
,
5460 .rpc_call_prepare
= nfs41_sequence_prepare
,
5461 .rpc_release
= nfs41_sequence_release
,
5464 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5466 struct nfs4_sequence_data
*calldata
;
5467 struct rpc_message msg
= {
5468 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5471 struct rpc_task_setup task_setup_data
= {
5472 .rpc_client
= clp
->cl_rpcclient
,
5473 .rpc_message
= &msg
,
5474 .callback_ops
= &nfs41_sequence_ops
,
5475 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5478 if (!atomic_inc_not_zero(&clp
->cl_count
))
5479 return ERR_PTR(-EIO
);
5480 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5481 if (calldata
== NULL
) {
5482 nfs_put_client(clp
);
5483 return ERR_PTR(-ENOMEM
);
5485 msg
.rpc_argp
= &calldata
->args
;
5486 msg
.rpc_resp
= &calldata
->res
;
5487 calldata
->clp
= clp
;
5488 task_setup_data
.callback_data
= calldata
;
5490 return rpc_run_task(&task_setup_data
);
5493 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
5495 struct rpc_task
*task
;
5498 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
5500 task
= _nfs41_proc_sequence(clp
, cred
);
5502 ret
= PTR_ERR(task
);
5504 rpc_put_task_async(task
);
5505 dprintk("<-- %s status=%d\n", __func__
, ret
);
5509 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5511 struct rpc_task
*task
;
5514 task
= _nfs41_proc_sequence(clp
, cred
);
5516 ret
= PTR_ERR(task
);
5519 ret
= rpc_wait_for_completion_task(task
);
5521 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
5523 if (task
->tk_status
== 0)
5524 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
5525 ret
= task
->tk_status
;
5529 dprintk("<-- %s status=%d\n", __func__
, ret
);
5533 struct nfs4_reclaim_complete_data
{
5534 struct nfs_client
*clp
;
5535 struct nfs41_reclaim_complete_args arg
;
5536 struct nfs41_reclaim_complete_res res
;
5539 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5541 struct nfs4_reclaim_complete_data
*calldata
= data
;
5543 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5544 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5545 &calldata
->arg
.seq_args
,
5546 &calldata
->res
.seq_res
, 0, task
))
5549 rpc_call_start(task
);
5552 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5554 switch(task
->tk_status
) {
5556 case -NFS4ERR_COMPLETE_ALREADY
:
5557 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5559 case -NFS4ERR_DELAY
:
5560 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5562 case -NFS4ERR_RETRY_UNCACHED_REP
:
5565 nfs4_schedule_lease_recovery(clp
);
5570 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5572 struct nfs4_reclaim_complete_data
*calldata
= data
;
5573 struct nfs_client
*clp
= calldata
->clp
;
5574 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5576 dprintk("--> %s\n", __func__
);
5577 if (!nfs41_sequence_done(task
, res
))
5580 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5581 rpc_restart_call_prepare(task
);
5584 dprintk("<-- %s\n", __func__
);
5587 static void nfs4_free_reclaim_complete_data(void *data
)
5589 struct nfs4_reclaim_complete_data
*calldata
= data
;
5594 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5595 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5596 .rpc_call_done
= nfs4_reclaim_complete_done
,
5597 .rpc_release
= nfs4_free_reclaim_complete_data
,
5601 * Issue a global reclaim complete.
5603 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5605 struct nfs4_reclaim_complete_data
*calldata
;
5606 struct rpc_task
*task
;
5607 struct rpc_message msg
= {
5608 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5610 struct rpc_task_setup task_setup_data
= {
5611 .rpc_client
= clp
->cl_rpcclient
,
5612 .rpc_message
= &msg
,
5613 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5614 .flags
= RPC_TASK_ASYNC
,
5616 int status
= -ENOMEM
;
5618 dprintk("--> %s\n", __func__
);
5619 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5620 if (calldata
== NULL
)
5622 calldata
->clp
= clp
;
5623 calldata
->arg
.one_fs
= 0;
5625 msg
.rpc_argp
= &calldata
->arg
;
5626 msg
.rpc_resp
= &calldata
->res
;
5627 task_setup_data
.callback_data
= calldata
;
5628 task
= rpc_run_task(&task_setup_data
);
5630 status
= PTR_ERR(task
);
5633 status
= nfs4_wait_for_completion_rpc_task(task
);
5635 status
= task
->tk_status
;
5639 dprintk("<-- %s status=%d\n", __func__
, status
);
5644 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5646 struct nfs4_layoutget
*lgp
= calldata
;
5647 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5649 dprintk("--> %s\n", __func__
);
5650 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5651 * right now covering the LAYOUTGET we are about to send.
5652 * However, that is not so catastrophic, and there seems
5653 * to be no way to prevent it completely.
5655 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5656 &lgp
->res
.seq_res
, 0, task
))
5658 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5659 NFS_I(lgp
->args
.inode
)->layout
,
5660 lgp
->args
.ctx
->state
)) {
5661 rpc_exit(task
, NFS4_OK
);
5664 rpc_call_start(task
);
5667 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5669 struct nfs4_layoutget
*lgp
= calldata
;
5670 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5672 dprintk("--> %s\n", __func__
);
5674 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5677 switch (task
->tk_status
) {
5680 case -NFS4ERR_LAYOUTTRYLATER
:
5681 case -NFS4ERR_RECALLCONFLICT
:
5682 task
->tk_status
= -NFS4ERR_DELAY
;
5685 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5686 rpc_restart_call_prepare(task
);
5690 dprintk("<-- %s\n", __func__
);
5693 static void nfs4_layoutget_release(void *calldata
)
5695 struct nfs4_layoutget
*lgp
= calldata
;
5697 dprintk("--> %s\n", __func__
);
5698 put_nfs_open_context(lgp
->args
.ctx
);
5700 dprintk("<-- %s\n", __func__
);
5703 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5704 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5705 .rpc_call_done
= nfs4_layoutget_done
,
5706 .rpc_release
= nfs4_layoutget_release
,
5709 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5711 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5712 struct rpc_task
*task
;
5713 struct rpc_message msg
= {
5714 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5715 .rpc_argp
= &lgp
->args
,
5716 .rpc_resp
= &lgp
->res
,
5718 struct rpc_task_setup task_setup_data
= {
5719 .rpc_client
= server
->client
,
5720 .rpc_message
= &msg
,
5721 .callback_ops
= &nfs4_layoutget_call_ops
,
5722 .callback_data
= lgp
,
5723 .flags
= RPC_TASK_ASYNC
,
5727 dprintk("--> %s\n", __func__
);
5729 lgp
->res
.layoutp
= &lgp
->args
.layout
;
5730 lgp
->res
.seq_res
.sr_slot
= NULL
;
5731 task
= rpc_run_task(&task_setup_data
);
5733 return PTR_ERR(task
);
5734 status
= nfs4_wait_for_completion_rpc_task(task
);
5736 status
= task
->tk_status
;
5738 status
= pnfs_layout_process(lgp
);
5740 dprintk("<-- %s status=%d\n", __func__
, status
);
5745 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
5747 struct nfs4_layoutreturn
*lrp
= calldata
;
5749 dprintk("--> %s\n", __func__
);
5750 if (nfs41_setup_sequence(lrp
->clp
->cl_session
, &lrp
->args
.seq_args
,
5751 &lrp
->res
.seq_res
, 0, task
))
5753 rpc_call_start(task
);
5756 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
5758 struct nfs4_layoutreturn
*lrp
= calldata
;
5759 struct nfs_server
*server
;
5760 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
5762 dprintk("--> %s\n", __func__
);
5764 if (!nfs4_sequence_done(task
, &lrp
->res
.seq_res
))
5767 server
= NFS_SERVER(lrp
->args
.inode
);
5768 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5769 rpc_restart_call_prepare(task
);
5772 spin_lock(&lo
->plh_inode
->i_lock
);
5773 if (task
->tk_status
== 0) {
5774 if (lrp
->res
.lrs_present
) {
5775 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
5777 BUG_ON(!list_empty(&lo
->plh_segs
));
5779 lo
->plh_block_lgets
--;
5780 spin_unlock(&lo
->plh_inode
->i_lock
);
5781 dprintk("<-- %s\n", __func__
);
5784 static void nfs4_layoutreturn_release(void *calldata
)
5786 struct nfs4_layoutreturn
*lrp
= calldata
;
5788 dprintk("--> %s\n", __func__
);
5789 put_layout_hdr(lrp
->args
.layout
);
5791 dprintk("<-- %s\n", __func__
);
5794 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
5795 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
5796 .rpc_call_done
= nfs4_layoutreturn_done
,
5797 .rpc_release
= nfs4_layoutreturn_release
,
5800 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
5802 struct rpc_task
*task
;
5803 struct rpc_message msg
= {
5804 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
5805 .rpc_argp
= &lrp
->args
,
5806 .rpc_resp
= &lrp
->res
,
5808 struct rpc_task_setup task_setup_data
= {
5809 .rpc_client
= lrp
->clp
->cl_rpcclient
,
5810 .rpc_message
= &msg
,
5811 .callback_ops
= &nfs4_layoutreturn_call_ops
,
5812 .callback_data
= lrp
,
5816 dprintk("--> %s\n", __func__
);
5817 task
= rpc_run_task(&task_setup_data
);
5819 return PTR_ERR(task
);
5820 status
= task
->tk_status
;
5821 dprintk("<-- %s status=%d\n", __func__
, status
);
5827 * Retrieve the list of Data Server devices from the MDS.
5829 static int _nfs4_getdevicelist(struct nfs_server
*server
,
5830 const struct nfs_fh
*fh
,
5831 struct pnfs_devicelist
*devlist
)
5833 struct nfs4_getdevicelist_args args
= {
5835 .layoutclass
= server
->pnfs_curr_ld
->id
,
5837 struct nfs4_getdevicelist_res res
= {
5840 struct rpc_message msg
= {
5841 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
5847 dprintk("--> %s\n", __func__
);
5848 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
5850 dprintk("<-- %s status=%d\n", __func__
, status
);
5854 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
5855 const struct nfs_fh
*fh
,
5856 struct pnfs_devicelist
*devlist
)
5858 struct nfs4_exception exception
= { };
5862 err
= nfs4_handle_exception(server
,
5863 _nfs4_getdevicelist(server
, fh
, devlist
),
5865 } while (exception
.retry
);
5867 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
5868 err
, devlist
->num_devs
);
5872 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
5875 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5877 struct nfs4_getdeviceinfo_args args
= {
5880 struct nfs4_getdeviceinfo_res res
= {
5883 struct rpc_message msg
= {
5884 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5890 dprintk("--> %s\n", __func__
);
5891 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5892 dprintk("<-- %s status=%d\n", __func__
, status
);
5897 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5899 struct nfs4_exception exception
= { };
5903 err
= nfs4_handle_exception(server
,
5904 _nfs4_proc_getdeviceinfo(server
, pdev
),
5906 } while (exception
.retry
);
5909 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5911 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
5913 struct nfs4_layoutcommit_data
*data
= calldata
;
5914 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5916 if (nfs4_setup_sequence(server
, &data
->args
.seq_args
,
5917 &data
->res
.seq_res
, 1, task
))
5919 rpc_call_start(task
);
5923 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
5925 struct nfs4_layoutcommit_data
*data
= calldata
;
5926 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5928 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5931 switch (task
->tk_status
) { /* Just ignore these failures */
5932 case NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
5933 case NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
5934 case NFS4ERR_BADLAYOUT
: /* no layout */
5935 case NFS4ERR_GRACE
: /* loca_recalim always false */
5936 task
->tk_status
= 0;
5939 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5940 rpc_restart_call_prepare(task
);
5944 if (task
->tk_status
== 0)
5945 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
5949 static void nfs4_layoutcommit_release(void *calldata
)
5951 struct nfs4_layoutcommit_data
*data
= calldata
;
5952 struct pnfs_layout_segment
*lseg
, *tmp
;
5954 pnfs_cleanup_layoutcommit(data
);
5955 /* Matched by references in pnfs_set_layoutcommit */
5956 list_for_each_entry_safe(lseg
, tmp
, &data
->lseg_list
, pls_lc_list
) {
5957 list_del_init(&lseg
->pls_lc_list
);
5958 if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT
,
5962 put_rpccred(data
->cred
);
5966 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
5967 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
5968 .rpc_call_done
= nfs4_layoutcommit_done
,
5969 .rpc_release
= nfs4_layoutcommit_release
,
5973 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
5975 struct rpc_message msg
= {
5976 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
5977 .rpc_argp
= &data
->args
,
5978 .rpc_resp
= &data
->res
,
5979 .rpc_cred
= data
->cred
,
5981 struct rpc_task_setup task_setup_data
= {
5982 .task
= &data
->task
,
5983 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
5984 .rpc_message
= &msg
,
5985 .callback_ops
= &nfs4_layoutcommit_ops
,
5986 .callback_data
= data
,
5987 .flags
= RPC_TASK_ASYNC
,
5989 struct rpc_task
*task
;
5992 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
5993 "lbw: %llu inode %lu\n",
5994 data
->task
.tk_pid
, sync
,
5995 data
->args
.lastbytewritten
,
5996 data
->args
.inode
->i_ino
);
5998 task
= rpc_run_task(&task_setup_data
);
6000 return PTR_ERR(task
);
6003 status
= nfs4_wait_for_completion_rpc_task(task
);
6006 status
= task
->tk_status
;
6008 dprintk("%s: status %d\n", __func__
, status
);
6014 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6015 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
6017 struct nfs41_secinfo_no_name_args args
= {
6018 .style
= SECINFO_STYLE_CURRENT_FH
,
6020 struct nfs4_secinfo_res res
= {
6023 struct rpc_message msg
= {
6024 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
6028 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
6032 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6033 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
6035 struct nfs4_exception exception
= { };
6038 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
6041 case -NFS4ERR_WRONGSEC
:
6042 case -NFS4ERR_NOTSUPP
:
6045 err
= nfs4_handle_exception(server
, err
, &exception
);
6047 } while (exception
.retry
);
6052 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6053 struct nfs_fsinfo
*info
)
6057 rpc_authflavor_t flavor
;
6058 struct nfs4_secinfo_flavors
*flavors
;
6060 page
= alloc_page(GFP_KERNEL
);
6066 flavors
= page_address(page
);
6067 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
6070 * Fall back on "guess and check" method if
6071 * the server doesn't support SECINFO_NO_NAME
6073 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
6074 err
= nfs4_find_root_sec(server
, fhandle
, info
);
6080 flavor
= nfs_find_best_sec(flavors
);
6082 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
6091 static int _nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6094 struct nfs41_test_stateid_args args
= {
6095 .stateid
= &state
->stateid
,
6097 struct nfs41_test_stateid_res res
;
6098 struct rpc_message msg
= {
6099 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
6103 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6104 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6108 static int nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6110 struct nfs4_exception exception
= { };
6113 err
= nfs4_handle_exception(server
,
6114 _nfs41_test_stateid(server
, state
),
6116 } while (exception
.retry
);
6120 static int _nfs4_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6123 struct nfs41_free_stateid_args args
= {
6124 .stateid
= &state
->stateid
,
6126 struct nfs41_free_stateid_res res
;
6127 struct rpc_message msg
= {
6128 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
6133 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6134 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6138 static int nfs41_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6140 struct nfs4_exception exception
= { };
6143 err
= nfs4_handle_exception(server
,
6144 _nfs4_free_stateid(server
, state
),
6146 } while (exception
.retry
);
6149 #endif /* CONFIG_NFS_V4_1 */
6151 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
6152 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6153 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6154 .recover_open
= nfs4_open_reclaim
,
6155 .recover_lock
= nfs4_lock_reclaim
,
6156 .establish_clid
= nfs4_init_clientid
,
6157 .get_clid_cred
= nfs4_get_setclientid_cred
,
6160 #if defined(CONFIG_NFS_V4_1)
6161 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
6162 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6163 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6164 .recover_open
= nfs4_open_reclaim
,
6165 .recover_lock
= nfs4_lock_reclaim
,
6166 .establish_clid
= nfs41_init_clientid
,
6167 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6168 .reclaim_complete
= nfs41_proc_reclaim_complete
,
6170 #endif /* CONFIG_NFS_V4_1 */
6172 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
6173 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6174 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6175 .recover_open
= nfs4_open_expired
,
6176 .recover_lock
= nfs4_lock_expired
,
6177 .establish_clid
= nfs4_init_clientid
,
6178 .get_clid_cred
= nfs4_get_setclientid_cred
,
6181 #if defined(CONFIG_NFS_V4_1)
6182 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
6183 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6184 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6185 .recover_open
= nfs41_open_expired
,
6186 .recover_lock
= nfs41_lock_expired
,
6187 .establish_clid
= nfs41_init_clientid
,
6188 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6190 #endif /* CONFIG_NFS_V4_1 */
6192 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
6193 .sched_state_renewal
= nfs4_proc_async_renew
,
6194 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
6195 .renew_lease
= nfs4_proc_renew
,
6198 #if defined(CONFIG_NFS_V4_1)
6199 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
6200 .sched_state_renewal
= nfs41_proc_async_sequence
,
6201 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
6202 .renew_lease
= nfs4_proc_sequence
,
6206 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
6208 .call_sync
= _nfs4_call_sync
,
6209 .validate_stateid
= nfs4_validate_delegation_stateid
,
6210 .find_root_sec
= nfs4_find_root_sec
,
6211 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
6212 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
6213 .state_renewal_ops
= &nfs40_state_renewal_ops
,
6216 #if defined(CONFIG_NFS_V4_1)
6217 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
6219 .call_sync
= _nfs4_call_sync_session
,
6220 .validate_stateid
= nfs41_validate_delegation_stateid
,
6221 .find_root_sec
= nfs41_find_root_sec
,
6222 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
6223 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
6224 .state_renewal_ops
= &nfs41_state_renewal_ops
,
6228 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
6229 [0] = &nfs_v4_0_minor_ops
,
6230 #if defined(CONFIG_NFS_V4_1)
6231 [1] = &nfs_v4_1_minor_ops
,
6235 static const struct inode_operations nfs4_file_inode_operations
= {
6236 .permission
= nfs_permission
,
6237 .getattr
= nfs_getattr
,
6238 .setattr
= nfs_setattr
,
6239 .getxattr
= generic_getxattr
,
6240 .setxattr
= generic_setxattr
,
6241 .listxattr
= generic_listxattr
,
6242 .removexattr
= generic_removexattr
,
6245 const struct nfs_rpc_ops nfs_v4_clientops
= {
6246 .version
= 4, /* protocol version */
6247 .dentry_ops
= &nfs4_dentry_operations
,
6248 .dir_inode_ops
= &nfs4_dir_inode_operations
,
6249 .file_inode_ops
= &nfs4_file_inode_operations
,
6250 .getroot
= nfs4_proc_get_root
,
6251 .getattr
= nfs4_proc_getattr
,
6252 .setattr
= nfs4_proc_setattr
,
6253 .lookup
= nfs4_proc_lookup
,
6254 .access
= nfs4_proc_access
,
6255 .readlink
= nfs4_proc_readlink
,
6256 .create
= nfs4_proc_create
,
6257 .remove
= nfs4_proc_remove
,
6258 .unlink_setup
= nfs4_proc_unlink_setup
,
6259 .unlink_done
= nfs4_proc_unlink_done
,
6260 .rename
= nfs4_proc_rename
,
6261 .rename_setup
= nfs4_proc_rename_setup
,
6262 .rename_done
= nfs4_proc_rename_done
,
6263 .link
= nfs4_proc_link
,
6264 .symlink
= nfs4_proc_symlink
,
6265 .mkdir
= nfs4_proc_mkdir
,
6266 .rmdir
= nfs4_proc_remove
,
6267 .readdir
= nfs4_proc_readdir
,
6268 .mknod
= nfs4_proc_mknod
,
6269 .statfs
= nfs4_proc_statfs
,
6270 .fsinfo
= nfs4_proc_fsinfo
,
6271 .pathconf
= nfs4_proc_pathconf
,
6272 .set_capabilities
= nfs4_server_capabilities
,
6273 .decode_dirent
= nfs4_decode_dirent
,
6274 .read_setup
= nfs4_proc_read_setup
,
6275 .read_done
= nfs4_read_done
,
6276 .write_setup
= nfs4_proc_write_setup
,
6277 .write_done
= nfs4_write_done
,
6278 .commit_setup
= nfs4_proc_commit_setup
,
6279 .commit_done
= nfs4_commit_done
,
6280 .lock
= nfs4_proc_lock
,
6281 .clear_acl_cache
= nfs4_zap_acl_attr
,
6282 .close_context
= nfs4_close_context
,
6283 .open_context
= nfs4_atomic_open
,
6284 .init_client
= nfs4_init_client
,
6285 .secinfo
= nfs4_proc_secinfo
,
6288 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
6289 .prefix
= XATTR_NAME_NFSV4_ACL
,
6290 .list
= nfs4_xattr_list_nfs4_acl
,
6291 .get
= nfs4_xattr_get_nfs4_acl
,
6292 .set
= nfs4_xattr_set_nfs4_acl
,
6295 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
6296 &nfs4_xattr_nfs4_acl_handler
,