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_lookup(struct rpc_clnt
*client
, struct inode
*dir
,
77 const struct qstr
*name
, struct nfs_fh
*fhandle
,
78 struct nfs_fattr
*fattr
);
79 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
80 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
81 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
82 struct nfs4_state
*state
);
83 #ifdef CONFIG_NFS_V4_1
84 static int nfs41_test_stateid(struct nfs_server
*, struct nfs4_state
*);
85 static int nfs41_free_stateid(struct nfs_server
*, struct nfs4_state
*);
87 /* Prevent leaks of NFSv4 errors into userland */
88 static int nfs4_map_errors(int err
)
93 case -NFS4ERR_RESOURCE
:
95 case -NFS4ERR_WRONGSEC
:
97 case -NFS4ERR_BADOWNER
:
98 case -NFS4ERR_BADNAME
:
101 dprintk("%s could not handle NFSv4 error %d\n",
109 * This is our standard bitmap for GETATTR requests.
111 const u32 nfs4_fattr_bitmap
[2] = {
113 | FATTR4_WORD0_CHANGE
116 | FATTR4_WORD0_FILEID
,
118 | FATTR4_WORD1_NUMLINKS
120 | FATTR4_WORD1_OWNER_GROUP
121 | FATTR4_WORD1_RAWDEV
122 | FATTR4_WORD1_SPACE_USED
123 | FATTR4_WORD1_TIME_ACCESS
124 | FATTR4_WORD1_TIME_METADATA
125 | FATTR4_WORD1_TIME_MODIFY
128 const u32 nfs4_statfs_bitmap
[2] = {
129 FATTR4_WORD0_FILES_AVAIL
130 | FATTR4_WORD0_FILES_FREE
131 | FATTR4_WORD0_FILES_TOTAL
,
132 FATTR4_WORD1_SPACE_AVAIL
133 | FATTR4_WORD1_SPACE_FREE
134 | FATTR4_WORD1_SPACE_TOTAL
137 const u32 nfs4_pathconf_bitmap
[2] = {
139 | FATTR4_WORD0_MAXNAME
,
143 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
144 | FATTR4_WORD0_MAXREAD
145 | FATTR4_WORD0_MAXWRITE
146 | FATTR4_WORD0_LEASE_TIME
,
147 FATTR4_WORD1_TIME_DELTA
148 | FATTR4_WORD1_FS_LAYOUT_TYPES
151 const u32 nfs4_fs_locations_bitmap
[2] = {
153 | FATTR4_WORD0_CHANGE
156 | FATTR4_WORD0_FILEID
157 | FATTR4_WORD0_FS_LOCATIONS
,
159 | FATTR4_WORD1_NUMLINKS
161 | FATTR4_WORD1_OWNER_GROUP
162 | FATTR4_WORD1_RAWDEV
163 | FATTR4_WORD1_SPACE_USED
164 | FATTR4_WORD1_TIME_ACCESS
165 | FATTR4_WORD1_TIME_METADATA
166 | FATTR4_WORD1_TIME_MODIFY
167 | FATTR4_WORD1_MOUNTED_ON_FILEID
170 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
171 struct nfs4_readdir_arg
*readdir
)
175 BUG_ON(readdir
->count
< 80);
177 readdir
->cookie
= cookie
;
178 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
183 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
188 * NFSv4 servers do not return entries for '.' and '..'
189 * Therefore, we fake these entries here. We let '.'
190 * have cookie 0 and '..' have cookie 1. Note that
191 * when talking to the server, we always send cookie 0
194 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
197 *p
++ = xdr_one
; /* next */
198 *p
++ = xdr_zero
; /* cookie, first word */
199 *p
++ = xdr_one
; /* cookie, second word */
200 *p
++ = xdr_one
; /* entry len */
201 memcpy(p
, ".\0\0\0", 4); /* entry */
203 *p
++ = xdr_one
; /* bitmap length */
204 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
205 *p
++ = htonl(8); /* attribute buffer length */
206 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
209 *p
++ = xdr_one
; /* next */
210 *p
++ = xdr_zero
; /* cookie, first word */
211 *p
++ = xdr_two
; /* cookie, second word */
212 *p
++ = xdr_two
; /* entry len */
213 memcpy(p
, "..\0\0", 4); /* entry */
215 *p
++ = xdr_one
; /* bitmap length */
216 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
217 *p
++ = htonl(8); /* attribute buffer length */
218 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
220 readdir
->pgbase
= (char *)p
- (char *)start
;
221 readdir
->count
-= readdir
->pgbase
;
222 kunmap_atomic(start
, KM_USER0
);
225 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
231 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
232 nfs_wait_bit_killable
, TASK_KILLABLE
);
236 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
243 *timeout
= NFS4_POLL_RETRY_MIN
;
244 if (*timeout
> NFS4_POLL_RETRY_MAX
)
245 *timeout
= NFS4_POLL_RETRY_MAX
;
246 schedule_timeout_killable(*timeout
);
247 if (fatal_signal_pending(current
))
253 /* This is the error handling routine for processes that are allowed
256 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
258 struct nfs_client
*clp
= server
->nfs_client
;
259 struct nfs4_state
*state
= exception
->state
;
262 exception
->retry
= 0;
266 case -NFS4ERR_ADMIN_REVOKED
:
267 case -NFS4ERR_BAD_STATEID
:
268 case -NFS4ERR_OPENMODE
:
271 nfs4_schedule_stateid_recovery(server
, state
);
272 goto wait_on_recovery
;
273 case -NFS4ERR_EXPIRED
:
275 nfs4_schedule_stateid_recovery(server
, state
);
276 case -NFS4ERR_STALE_STATEID
:
277 case -NFS4ERR_STALE_CLIENTID
:
278 nfs4_schedule_lease_recovery(clp
);
279 goto wait_on_recovery
;
280 #if defined(CONFIG_NFS_V4_1)
281 case -NFS4ERR_BADSESSION
:
282 case -NFS4ERR_BADSLOT
:
283 case -NFS4ERR_BAD_HIGH_SLOT
:
284 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
285 case -NFS4ERR_DEADSESSION
:
286 case -NFS4ERR_SEQ_FALSE_RETRY
:
287 case -NFS4ERR_SEQ_MISORDERED
:
288 dprintk("%s ERROR: %d Reset session\n", __func__
,
290 nfs4_schedule_session_recovery(clp
->cl_session
);
291 exception
->retry
= 1;
293 #endif /* defined(CONFIG_NFS_V4_1) */
294 case -NFS4ERR_FILE_OPEN
:
295 if (exception
->timeout
> HZ
) {
296 /* We have retried a decent amount, time to
305 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
308 case -NFS4ERR_RETRY_UNCACHED_REP
:
309 case -NFS4ERR_OLD_STATEID
:
310 exception
->retry
= 1;
312 case -NFS4ERR_BADOWNER
:
313 /* The following works around a Linux server bug! */
314 case -NFS4ERR_BADNAME
:
315 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
316 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
317 exception
->retry
= 1;
318 printk(KERN_WARNING
"NFS: v4 server %s "
319 "does not accept raw "
321 "Reenabling the idmapper.\n",
322 server
->nfs_client
->cl_hostname
);
325 /* We failed to handle the error */
326 return nfs4_map_errors(ret
);
328 ret
= nfs4_wait_clnt_recover(clp
);
330 exception
->retry
= 1;
335 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
337 spin_lock(&clp
->cl_lock
);
338 if (time_before(clp
->cl_last_renewal
,timestamp
))
339 clp
->cl_last_renewal
= timestamp
;
340 spin_unlock(&clp
->cl_lock
);
343 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
345 do_renew_lease(server
->nfs_client
, timestamp
);
348 #if defined(CONFIG_NFS_V4_1)
351 * nfs4_free_slot - free a slot and efficiently update slot table.
353 * freeing a slot is trivially done by clearing its respective bit
355 * If the freed slotid equals highest_used_slotid we want to update it
356 * so that the server would be able to size down the slot table if needed,
357 * otherwise we know that the highest_used_slotid is still in use.
358 * When updating highest_used_slotid there may be "holes" in the bitmap
359 * so we need to scan down from highest_used_slotid to 0 looking for the now
360 * highest slotid in use.
361 * If none found, highest_used_slotid is set to -1.
363 * Must be called while holding tbl->slot_tbl_lock
366 nfs4_free_slot(struct nfs4_slot_table
*tbl
, struct nfs4_slot
*free_slot
)
368 int free_slotid
= free_slot
- tbl
->slots
;
369 int slotid
= free_slotid
;
371 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
372 /* clear used bit in bitmap */
373 __clear_bit(slotid
, tbl
->used_slots
);
375 /* update highest_used_slotid when it is freed */
376 if (slotid
== tbl
->highest_used_slotid
) {
377 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
378 if (slotid
< tbl
->max_slots
)
379 tbl
->highest_used_slotid
= slotid
;
381 tbl
->highest_used_slotid
= -1;
383 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
384 free_slotid
, tbl
->highest_used_slotid
);
388 * Signal state manager thread if session fore channel is drained
390 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
392 struct rpc_task
*task
;
394 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
395 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
397 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
401 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
404 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
405 complete(&ses
->fc_slot_table
.complete
);
409 * Signal state manager thread if session back channel is drained
411 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
413 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
414 ses
->bc_slot_table
.highest_used_slotid
!= -1)
416 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
417 complete(&ses
->bc_slot_table
.complete
);
420 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
422 struct nfs4_slot_table
*tbl
;
424 tbl
= &res
->sr_session
->fc_slot_table
;
426 /* just wake up the next guy waiting since
427 * we may have not consumed a slot after all */
428 dprintk("%s: No slot\n", __func__
);
432 spin_lock(&tbl
->slot_tbl_lock
);
433 nfs4_free_slot(tbl
, res
->sr_slot
);
434 nfs4_check_drain_fc_complete(res
->sr_session
);
435 spin_unlock(&tbl
->slot_tbl_lock
);
439 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
441 unsigned long timestamp
;
442 struct nfs_client
*clp
;
445 * sr_status remains 1 if an RPC level error occurred. The server
446 * may or may not have processed the sequence operation..
447 * Proceed as if the server received and processed the sequence
450 if (res
->sr_status
== 1)
451 res
->sr_status
= NFS_OK
;
453 /* don't increment the sequence number if the task wasn't sent */
454 if (!RPC_WAS_SENT(task
))
457 /* Check the SEQUENCE operation status */
458 switch (res
->sr_status
) {
460 /* Update the slot's sequence and clientid lease timer */
461 ++res
->sr_slot
->seq_nr
;
462 timestamp
= res
->sr_renewal_time
;
463 clp
= res
->sr_session
->clp
;
464 do_renew_lease(clp
, timestamp
);
465 /* Check sequence flags */
466 if (res
->sr_status_flags
!= 0)
467 nfs4_schedule_lease_recovery(clp
);
470 /* The server detected a resend of the RPC call and
471 * returned NFS4ERR_DELAY as per Section 2.10.6.2
474 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
476 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
477 res
->sr_slot
->seq_nr
);
480 /* Just update the slot sequence no. */
481 ++res
->sr_slot
->seq_nr
;
484 /* The session may be reset by one of the error handlers. */
485 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
486 nfs41_sequence_free_slot(res
);
489 if (!rpc_restart_call(task
))
491 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
495 static int nfs4_sequence_done(struct rpc_task
*task
,
496 struct nfs4_sequence_res
*res
)
498 if (res
->sr_session
== NULL
)
500 return nfs41_sequence_done(task
, res
);
504 * nfs4_find_slot - efficiently look for a free slot
506 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
507 * If found, we mark the slot as used, update the highest_used_slotid,
508 * and respectively set up the sequence operation args.
509 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
511 * Note: must be called with under the slot_tbl_lock.
514 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
517 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
518 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
520 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
521 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
523 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
524 if (slotid
>= tbl
->max_slots
)
526 __set_bit(slotid
, tbl
->used_slots
);
527 if (slotid
> tbl
->highest_used_slotid
)
528 tbl
->highest_used_slotid
= slotid
;
531 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
532 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
536 int nfs41_setup_sequence(struct nfs4_session
*session
,
537 struct nfs4_sequence_args
*args
,
538 struct nfs4_sequence_res
*res
,
540 struct rpc_task
*task
)
542 struct nfs4_slot
*slot
;
543 struct nfs4_slot_table
*tbl
;
546 dprintk("--> %s\n", __func__
);
547 /* slot already allocated? */
548 if (res
->sr_slot
!= NULL
)
551 tbl
= &session
->fc_slot_table
;
553 spin_lock(&tbl
->slot_tbl_lock
);
554 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
555 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
557 * The state manager will wait until the slot table is empty.
558 * Schedule the reset thread
560 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
561 spin_unlock(&tbl
->slot_tbl_lock
);
562 dprintk("%s Schedule Session Reset\n", __func__
);
566 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
567 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
568 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
569 spin_unlock(&tbl
->slot_tbl_lock
);
570 dprintk("%s enforce FIFO order\n", __func__
);
574 slotid
= nfs4_find_slot(tbl
);
575 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
576 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
577 spin_unlock(&tbl
->slot_tbl_lock
);
578 dprintk("<-- %s: no free slots\n", __func__
);
581 spin_unlock(&tbl
->slot_tbl_lock
);
583 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
584 slot
= tbl
->slots
+ slotid
;
585 args
->sa_session
= session
;
586 args
->sa_slotid
= slotid
;
587 args
->sa_cache_this
= cache_reply
;
589 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
591 res
->sr_session
= session
;
593 res
->sr_renewal_time
= jiffies
;
594 res
->sr_status_flags
= 0;
596 * sr_status is only set in decode_sequence, and so will remain
597 * set to 1 if an rpc level failure occurs.
602 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
604 int nfs4_setup_sequence(const struct nfs_server
*server
,
605 struct nfs4_sequence_args
*args
,
606 struct nfs4_sequence_res
*res
,
608 struct rpc_task
*task
)
610 struct nfs4_session
*session
= nfs4_get_session(server
);
613 if (session
== NULL
) {
614 args
->sa_session
= NULL
;
615 res
->sr_session
= NULL
;
619 dprintk("--> %s clp %p session %p sr_slot %td\n",
620 __func__
, session
->clp
, session
, res
->sr_slot
?
621 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
623 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
626 dprintk("<-- %s status=%d\n", __func__
, ret
);
630 struct nfs41_call_sync_data
{
631 const struct nfs_server
*seq_server
;
632 struct nfs4_sequence_args
*seq_args
;
633 struct nfs4_sequence_res
*seq_res
;
637 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
639 struct nfs41_call_sync_data
*data
= calldata
;
641 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
643 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
644 data
->seq_res
, data
->cache_reply
, task
))
646 rpc_call_start(task
);
649 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
651 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
652 nfs41_call_sync_prepare(task
, calldata
);
655 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
657 struct nfs41_call_sync_data
*data
= calldata
;
659 nfs41_sequence_done(task
, data
->seq_res
);
662 struct rpc_call_ops nfs41_call_sync_ops
= {
663 .rpc_call_prepare
= nfs41_call_sync_prepare
,
664 .rpc_call_done
= nfs41_call_sync_done
,
667 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
668 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
669 .rpc_call_done
= nfs41_call_sync_done
,
672 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
673 struct nfs_server
*server
,
674 struct rpc_message
*msg
,
675 struct nfs4_sequence_args
*args
,
676 struct nfs4_sequence_res
*res
,
681 struct rpc_task
*task
;
682 struct nfs41_call_sync_data data
= {
683 .seq_server
= server
,
686 .cache_reply
= cache_reply
,
688 struct rpc_task_setup task_setup
= {
691 .callback_ops
= &nfs41_call_sync_ops
,
692 .callback_data
= &data
697 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
698 task
= rpc_run_task(&task_setup
);
702 ret
= task
->tk_status
;
708 int _nfs4_call_sync_session(struct rpc_clnt
*clnt
,
709 struct nfs_server
*server
,
710 struct rpc_message
*msg
,
711 struct nfs4_sequence_args
*args
,
712 struct nfs4_sequence_res
*res
,
715 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
, cache_reply
, 0);
719 static int nfs4_sequence_done(struct rpc_task
*task
,
720 struct nfs4_sequence_res
*res
)
724 #endif /* CONFIG_NFS_V4_1 */
726 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
727 struct nfs_server
*server
,
728 struct rpc_message
*msg
,
729 struct nfs4_sequence_args
*args
,
730 struct nfs4_sequence_res
*res
,
733 args
->sa_session
= res
->sr_session
= NULL
;
734 return rpc_call_sync(clnt
, msg
, 0);
738 int nfs4_call_sync(struct rpc_clnt
*clnt
,
739 struct nfs_server
*server
,
740 struct rpc_message
*msg
,
741 struct nfs4_sequence_args
*args
,
742 struct nfs4_sequence_res
*res
,
745 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
746 args
, res
, cache_reply
);
749 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
751 struct nfs_inode
*nfsi
= NFS_I(dir
);
753 spin_lock(&dir
->i_lock
);
754 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
755 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
756 nfs_force_lookup_revalidate(dir
);
757 nfsi
->change_attr
= cinfo
->after
;
758 spin_unlock(&dir
->i_lock
);
761 struct nfs4_opendata
{
763 struct nfs_openargs o_arg
;
764 struct nfs_openres o_res
;
765 struct nfs_open_confirmargs c_arg
;
766 struct nfs_open_confirmres c_res
;
767 struct nfs_fattr f_attr
;
768 struct nfs_fattr dir_attr
;
770 struct dentry
*dentry
;
771 struct nfs4_state_owner
*owner
;
772 struct nfs4_state
*state
;
774 unsigned long timestamp
;
775 unsigned int rpc_done
: 1;
781 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
783 p
->o_res
.f_attr
= &p
->f_attr
;
784 p
->o_res
.dir_attr
= &p
->dir_attr
;
785 p
->o_res
.seqid
= p
->o_arg
.seqid
;
786 p
->c_res
.seqid
= p
->c_arg
.seqid
;
787 p
->o_res
.server
= p
->o_arg
.server
;
788 nfs_fattr_init(&p
->f_attr
);
789 nfs_fattr_init(&p
->dir_attr
);
792 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
793 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
794 const struct iattr
*attrs
,
797 struct dentry
*parent
= dget_parent(dentry
);
798 struct inode
*dir
= parent
->d_inode
;
799 struct nfs_server
*server
= NFS_SERVER(dir
);
800 struct nfs4_opendata
*p
;
802 p
= kzalloc(sizeof(*p
), gfp_mask
);
805 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
806 if (p
->o_arg
.seqid
== NULL
)
808 nfs_sb_active(dentry
->d_sb
);
809 p
->dentry
= dget(dentry
);
812 atomic_inc(&sp
->so_count
);
813 p
->o_arg
.fh
= NFS_FH(dir
);
814 p
->o_arg
.open_flags
= flags
;
815 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
816 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
817 p
->o_arg
.id
= sp
->so_owner_id
.id
;
818 p
->o_arg
.name
= &dentry
->d_name
;
819 p
->o_arg
.server
= server
;
820 p
->o_arg
.bitmask
= server
->attr_bitmask
;
821 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
822 if (flags
& O_CREAT
) {
825 p
->o_arg
.u
.attrs
= &p
->attrs
;
826 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
827 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
831 p
->c_arg
.fh
= &p
->o_res
.fh
;
832 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
833 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
834 nfs4_init_opendata_res(p
);
844 static void nfs4_opendata_free(struct kref
*kref
)
846 struct nfs4_opendata
*p
= container_of(kref
,
847 struct nfs4_opendata
, kref
);
848 struct super_block
*sb
= p
->dentry
->d_sb
;
850 nfs_free_seqid(p
->o_arg
.seqid
);
851 if (p
->state
!= NULL
)
852 nfs4_put_open_state(p
->state
);
853 nfs4_put_state_owner(p
->owner
);
860 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
863 kref_put(&p
->kref
, nfs4_opendata_free
);
866 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
870 ret
= rpc_wait_for_completion_task(task
);
874 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
878 if (open_mode
& O_EXCL
)
880 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
882 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
883 && state
->n_rdonly
!= 0;
886 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
887 && state
->n_wronly
!= 0;
889 case FMODE_READ
|FMODE_WRITE
:
890 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
891 && state
->n_rdwr
!= 0;
897 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
899 if ((delegation
->type
& fmode
) != fmode
)
901 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
903 nfs_mark_delegation_referenced(delegation
);
907 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
916 case FMODE_READ
|FMODE_WRITE
:
919 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
922 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
924 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
925 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
926 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
929 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
932 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
934 case FMODE_READ
|FMODE_WRITE
:
935 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
939 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
941 write_seqlock(&state
->seqlock
);
942 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
943 write_sequnlock(&state
->seqlock
);
946 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
949 * Protect the call to nfs4_state_set_mode_locked and
950 * serialise the stateid update
952 write_seqlock(&state
->seqlock
);
953 if (deleg_stateid
!= NULL
) {
954 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
955 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
957 if (open_stateid
!= NULL
)
958 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
959 write_sequnlock(&state
->seqlock
);
960 spin_lock(&state
->owner
->so_lock
);
961 update_open_stateflags(state
, fmode
);
962 spin_unlock(&state
->owner
->so_lock
);
965 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
967 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
968 struct nfs_delegation
*deleg_cur
;
971 fmode
&= (FMODE_READ
|FMODE_WRITE
);
974 deleg_cur
= rcu_dereference(nfsi
->delegation
);
975 if (deleg_cur
== NULL
)
978 spin_lock(&deleg_cur
->lock
);
979 if (nfsi
->delegation
!= deleg_cur
||
980 (deleg_cur
->type
& fmode
) != fmode
)
981 goto no_delegation_unlock
;
983 if (delegation
== NULL
)
984 delegation
= &deleg_cur
->stateid
;
985 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
986 goto no_delegation_unlock
;
988 nfs_mark_delegation_referenced(deleg_cur
);
989 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
991 no_delegation_unlock
:
992 spin_unlock(&deleg_cur
->lock
);
996 if (!ret
&& open_stateid
!= NULL
) {
997 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1005 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1007 struct nfs_delegation
*delegation
;
1010 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1011 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1016 nfs_inode_return_delegation(inode
);
1019 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1021 struct nfs4_state
*state
= opendata
->state
;
1022 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1023 struct nfs_delegation
*delegation
;
1024 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
1025 fmode_t fmode
= opendata
->o_arg
.fmode
;
1026 nfs4_stateid stateid
;
1030 if (can_open_cached(state
, fmode
, open_mode
)) {
1031 spin_lock(&state
->owner
->so_lock
);
1032 if (can_open_cached(state
, fmode
, open_mode
)) {
1033 update_open_stateflags(state
, fmode
);
1034 spin_unlock(&state
->owner
->so_lock
);
1035 goto out_return_state
;
1037 spin_unlock(&state
->owner
->so_lock
);
1040 delegation
= rcu_dereference(nfsi
->delegation
);
1041 if (delegation
== NULL
||
1042 !can_open_delegated(delegation
, fmode
)) {
1046 /* Save the delegation */
1047 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1049 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1054 /* Try to update the stateid using the delegation */
1055 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1056 goto out_return_state
;
1059 return ERR_PTR(ret
);
1061 atomic_inc(&state
->count
);
1065 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1067 struct inode
*inode
;
1068 struct nfs4_state
*state
= NULL
;
1069 struct nfs_delegation
*delegation
;
1072 if (!data
->rpc_done
) {
1073 state
= nfs4_try_open_cached(data
);
1078 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1080 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1081 ret
= PTR_ERR(inode
);
1085 state
= nfs4_get_open_state(inode
, data
->owner
);
1088 if (data
->o_res
.delegation_type
!= 0) {
1089 int delegation_flags
= 0;
1092 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1094 delegation_flags
= delegation
->flags
;
1096 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1097 nfs_inode_set_delegation(state
->inode
,
1098 data
->owner
->so_cred
,
1101 nfs_inode_reclaim_delegation(state
->inode
,
1102 data
->owner
->so_cred
,
1106 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1114 return ERR_PTR(ret
);
1117 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1119 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1120 struct nfs_open_context
*ctx
;
1122 spin_lock(&state
->inode
->i_lock
);
1123 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1124 if (ctx
->state
!= state
)
1126 get_nfs_open_context(ctx
);
1127 spin_unlock(&state
->inode
->i_lock
);
1130 spin_unlock(&state
->inode
->i_lock
);
1131 return ERR_PTR(-ENOENT
);
1134 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1136 struct nfs4_opendata
*opendata
;
1138 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1139 if (opendata
== NULL
)
1140 return ERR_PTR(-ENOMEM
);
1141 opendata
->state
= state
;
1142 atomic_inc(&state
->count
);
1146 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1148 struct nfs4_state
*newstate
;
1151 opendata
->o_arg
.open_flags
= 0;
1152 opendata
->o_arg
.fmode
= fmode
;
1153 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1154 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1155 nfs4_init_opendata_res(opendata
);
1156 ret
= _nfs4_recover_proc_open(opendata
);
1159 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1160 if (IS_ERR(newstate
))
1161 return PTR_ERR(newstate
);
1162 nfs4_close_state(newstate
, fmode
);
1167 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1169 struct nfs4_state
*newstate
;
1172 /* memory barrier prior to reading state->n_* */
1173 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1175 if (state
->n_rdwr
!= 0) {
1176 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1177 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1180 if (newstate
!= state
)
1183 if (state
->n_wronly
!= 0) {
1184 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1185 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1188 if (newstate
!= state
)
1191 if (state
->n_rdonly
!= 0) {
1192 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1193 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1196 if (newstate
!= state
)
1200 * We may have performed cached opens for all three recoveries.
1201 * Check if we need to update the current stateid.
1203 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1204 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1205 write_seqlock(&state
->seqlock
);
1206 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1207 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1208 write_sequnlock(&state
->seqlock
);
1215 * reclaim state on the server after a reboot.
1217 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1219 struct nfs_delegation
*delegation
;
1220 struct nfs4_opendata
*opendata
;
1221 fmode_t delegation_type
= 0;
1224 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1225 if (IS_ERR(opendata
))
1226 return PTR_ERR(opendata
);
1227 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1228 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1230 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1231 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1232 delegation_type
= delegation
->type
;
1234 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1235 status
= nfs4_open_recover(opendata
, state
);
1236 nfs4_opendata_put(opendata
);
1240 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1242 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1243 struct nfs4_exception exception
= { };
1246 err
= _nfs4_do_open_reclaim(ctx
, state
);
1247 if (err
!= -NFS4ERR_DELAY
)
1249 nfs4_handle_exception(server
, err
, &exception
);
1250 } while (exception
.retry
);
1254 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1256 struct nfs_open_context
*ctx
;
1259 ctx
= nfs4_state_find_open_context(state
);
1261 return PTR_ERR(ctx
);
1262 ret
= nfs4_do_open_reclaim(ctx
, state
);
1263 put_nfs_open_context(ctx
);
1267 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1269 struct nfs4_opendata
*opendata
;
1272 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1273 if (IS_ERR(opendata
))
1274 return PTR_ERR(opendata
);
1275 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1276 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1277 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1278 ret
= nfs4_open_recover(opendata
, state
);
1279 nfs4_opendata_put(opendata
);
1283 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1285 struct nfs4_exception exception
= { };
1286 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1289 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1295 case -NFS4ERR_BADSESSION
:
1296 case -NFS4ERR_BADSLOT
:
1297 case -NFS4ERR_BAD_HIGH_SLOT
:
1298 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1299 case -NFS4ERR_DEADSESSION
:
1300 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1302 case -NFS4ERR_STALE_CLIENTID
:
1303 case -NFS4ERR_STALE_STATEID
:
1304 case -NFS4ERR_EXPIRED
:
1305 /* Don't recall a delegation if it was lost */
1306 nfs4_schedule_lease_recovery(server
->nfs_client
);
1310 * The show must go on: exit, but mark the
1311 * stateid as needing recovery.
1313 case -NFS4ERR_ADMIN_REVOKED
:
1314 case -NFS4ERR_BAD_STATEID
:
1315 nfs4_schedule_stateid_recovery(server
, state
);
1318 * User RPCSEC_GSS context has expired.
1319 * We cannot recover this stateid now, so
1320 * skip it and allow recovery thread to
1327 err
= nfs4_handle_exception(server
, err
, &exception
);
1328 } while (exception
.retry
);
1333 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1335 struct nfs4_opendata
*data
= calldata
;
1337 data
->rpc_status
= task
->tk_status
;
1338 if (data
->rpc_status
== 0) {
1339 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1340 sizeof(data
->o_res
.stateid
.data
));
1341 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1342 renew_lease(data
->o_res
.server
, data
->timestamp
);
1347 static void nfs4_open_confirm_release(void *calldata
)
1349 struct nfs4_opendata
*data
= calldata
;
1350 struct nfs4_state
*state
= NULL
;
1352 /* If this request hasn't been cancelled, do nothing */
1353 if (data
->cancelled
== 0)
1355 /* In case of error, no cleanup! */
1356 if (!data
->rpc_done
)
1358 state
= nfs4_opendata_to_nfs4_state(data
);
1360 nfs4_close_state(state
, data
->o_arg
.fmode
);
1362 nfs4_opendata_put(data
);
1365 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1366 .rpc_call_done
= nfs4_open_confirm_done
,
1367 .rpc_release
= nfs4_open_confirm_release
,
1371 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1373 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1375 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1376 struct rpc_task
*task
;
1377 struct rpc_message msg
= {
1378 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1379 .rpc_argp
= &data
->c_arg
,
1380 .rpc_resp
= &data
->c_res
,
1381 .rpc_cred
= data
->owner
->so_cred
,
1383 struct rpc_task_setup task_setup_data
= {
1384 .rpc_client
= server
->client
,
1385 .rpc_message
= &msg
,
1386 .callback_ops
= &nfs4_open_confirm_ops
,
1387 .callback_data
= data
,
1388 .workqueue
= nfsiod_workqueue
,
1389 .flags
= RPC_TASK_ASYNC
,
1393 kref_get(&data
->kref
);
1395 data
->rpc_status
= 0;
1396 data
->timestamp
= jiffies
;
1397 task
= rpc_run_task(&task_setup_data
);
1399 return PTR_ERR(task
);
1400 status
= nfs4_wait_for_completion_rpc_task(task
);
1402 data
->cancelled
= 1;
1405 status
= data
->rpc_status
;
1410 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1412 struct nfs4_opendata
*data
= calldata
;
1413 struct nfs4_state_owner
*sp
= data
->owner
;
1415 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1418 * Check if we still need to send an OPEN call, or if we can use
1419 * a delegation instead.
1421 if (data
->state
!= NULL
) {
1422 struct nfs_delegation
*delegation
;
1424 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1427 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1428 if (delegation
!= NULL
&&
1429 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1435 /* Update sequence id. */
1436 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1437 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1438 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1439 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1440 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1442 data
->timestamp
= jiffies
;
1443 if (nfs4_setup_sequence(data
->o_arg
.server
,
1444 &data
->o_arg
.seq_args
,
1445 &data
->o_res
.seq_res
, 1, task
))
1447 rpc_call_start(task
);
1450 task
->tk_action
= NULL
;
1454 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1456 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1457 nfs4_open_prepare(task
, calldata
);
1460 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1462 struct nfs4_opendata
*data
= calldata
;
1464 data
->rpc_status
= task
->tk_status
;
1466 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1469 if (task
->tk_status
== 0) {
1470 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1474 data
->rpc_status
= -ELOOP
;
1477 data
->rpc_status
= -EISDIR
;
1480 data
->rpc_status
= -ENOTDIR
;
1482 renew_lease(data
->o_res
.server
, data
->timestamp
);
1483 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1484 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1489 static void nfs4_open_release(void *calldata
)
1491 struct nfs4_opendata
*data
= calldata
;
1492 struct nfs4_state
*state
= NULL
;
1494 /* If this request hasn't been cancelled, do nothing */
1495 if (data
->cancelled
== 0)
1497 /* In case of error, no cleanup! */
1498 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1500 /* In case we need an open_confirm, no cleanup! */
1501 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1503 state
= nfs4_opendata_to_nfs4_state(data
);
1505 nfs4_close_state(state
, data
->o_arg
.fmode
);
1507 nfs4_opendata_put(data
);
1510 static const struct rpc_call_ops nfs4_open_ops
= {
1511 .rpc_call_prepare
= nfs4_open_prepare
,
1512 .rpc_call_done
= nfs4_open_done
,
1513 .rpc_release
= nfs4_open_release
,
1516 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1517 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1518 .rpc_call_done
= nfs4_open_done
,
1519 .rpc_release
= nfs4_open_release
,
1522 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1524 struct inode
*dir
= data
->dir
->d_inode
;
1525 struct nfs_server
*server
= NFS_SERVER(dir
);
1526 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1527 struct nfs_openres
*o_res
= &data
->o_res
;
1528 struct rpc_task
*task
;
1529 struct rpc_message msg
= {
1530 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1533 .rpc_cred
= data
->owner
->so_cred
,
1535 struct rpc_task_setup task_setup_data
= {
1536 .rpc_client
= server
->client
,
1537 .rpc_message
= &msg
,
1538 .callback_ops
= &nfs4_open_ops
,
1539 .callback_data
= data
,
1540 .workqueue
= nfsiod_workqueue
,
1541 .flags
= RPC_TASK_ASYNC
,
1545 kref_get(&data
->kref
);
1547 data
->rpc_status
= 0;
1548 data
->cancelled
= 0;
1550 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1551 task
= rpc_run_task(&task_setup_data
);
1553 return PTR_ERR(task
);
1554 status
= nfs4_wait_for_completion_rpc_task(task
);
1556 data
->cancelled
= 1;
1559 status
= data
->rpc_status
;
1565 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1567 struct inode
*dir
= data
->dir
->d_inode
;
1568 struct nfs_openres
*o_res
= &data
->o_res
;
1571 status
= nfs4_run_open_task(data
, 1);
1572 if (status
!= 0 || !data
->rpc_done
)
1575 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1577 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1578 status
= _nfs4_proc_open_confirm(data
);
1587 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1589 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1591 struct inode
*dir
= data
->dir
->d_inode
;
1592 struct nfs_server
*server
= NFS_SERVER(dir
);
1593 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1594 struct nfs_openres
*o_res
= &data
->o_res
;
1597 status
= nfs4_run_open_task(data
, 0);
1598 if (status
!= 0 || !data
->rpc_done
)
1601 if (o_arg
->open_flags
& O_CREAT
) {
1602 update_changeattr(dir
, &o_res
->cinfo
);
1603 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1605 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1606 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1607 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1608 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1609 status
= _nfs4_proc_open_confirm(data
);
1613 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1614 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1618 static int nfs4_client_recover_expired_lease(struct nfs_client
*clp
)
1623 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1624 ret
= nfs4_wait_clnt_recover(clp
);
1627 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1628 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1630 nfs4_schedule_state_manager(clp
);
1636 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1638 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1643 * reclaim state on the server after a network partition.
1644 * Assumes caller holds the appropriate lock
1646 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1648 struct nfs4_opendata
*opendata
;
1651 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1652 if (IS_ERR(opendata
))
1653 return PTR_ERR(opendata
);
1654 ret
= nfs4_open_recover(opendata
, state
);
1656 d_drop(ctx
->dentry
);
1657 nfs4_opendata_put(opendata
);
1661 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1663 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1664 struct nfs4_exception exception
= { };
1668 err
= _nfs4_open_expired(ctx
, state
);
1672 case -NFS4ERR_GRACE
:
1673 case -NFS4ERR_DELAY
:
1674 nfs4_handle_exception(server
, err
, &exception
);
1677 } while (exception
.retry
);
1682 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1684 struct nfs_open_context
*ctx
;
1687 ctx
= nfs4_state_find_open_context(state
);
1689 return PTR_ERR(ctx
);
1690 ret
= nfs4_do_open_expired(ctx
, state
);
1691 put_nfs_open_context(ctx
);
1695 #if defined(CONFIG_NFS_V4_1)
1696 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1699 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1701 status
= nfs41_test_stateid(server
, state
);
1702 if (status
== NFS_OK
)
1704 nfs41_free_stateid(server
, state
);
1705 return nfs4_open_expired(sp
, state
);
1710 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1711 * fields corresponding to attributes that were used to store the verifier.
1712 * Make sure we clobber those fields in the later setattr call
1714 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1716 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1717 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1718 sattr
->ia_valid
|= ATTR_ATIME
;
1720 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1721 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1722 sattr
->ia_valid
|= ATTR_MTIME
;
1726 * Returns a referenced nfs4_state
1728 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
)
1730 struct nfs4_state_owner
*sp
;
1731 struct nfs4_state
*state
= NULL
;
1732 struct nfs_server
*server
= NFS_SERVER(dir
);
1733 struct nfs4_opendata
*opendata
;
1736 /* Protect against reboot recovery conflicts */
1738 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1739 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1742 status
= nfs4_recover_expired_lease(server
);
1744 goto err_put_state_owner
;
1745 if (dentry
->d_inode
!= NULL
)
1746 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
1748 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1749 if (opendata
== NULL
)
1750 goto err_put_state_owner
;
1752 if (dentry
->d_inode
!= NULL
)
1753 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
1755 status
= _nfs4_proc_open(opendata
);
1757 goto err_opendata_put
;
1759 state
= nfs4_opendata_to_nfs4_state(opendata
);
1760 status
= PTR_ERR(state
);
1762 goto err_opendata_put
;
1763 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1764 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1766 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1767 nfs4_exclusive_attrset(opendata
, sattr
);
1769 nfs_fattr_init(opendata
->o_res
.f_attr
);
1770 status
= nfs4_do_setattr(state
->inode
, cred
,
1771 opendata
->o_res
.f_attr
, sattr
,
1774 nfs_setattr_update_inode(state
->inode
, sattr
);
1775 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1777 nfs4_opendata_put(opendata
);
1778 nfs4_put_state_owner(sp
);
1782 nfs4_opendata_put(opendata
);
1783 err_put_state_owner
:
1784 nfs4_put_state_owner(sp
);
1791 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
)
1793 struct nfs4_exception exception
= { };
1794 struct nfs4_state
*res
;
1798 status
= _nfs4_do_open(dir
, dentry
, fmode
, flags
, sattr
, cred
, &res
);
1801 /* NOTE: BAD_SEQID means the server and client disagree about the
1802 * book-keeping w.r.t. state-changing operations
1803 * (OPEN/CLOSE/LOCK/LOCKU...)
1804 * It is actually a sign of a bug on the client or on the server.
1806 * If we receive a BAD_SEQID error in the particular case of
1807 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1808 * have unhashed the old state_owner for us, and that we can
1809 * therefore safely retry using a new one. We should still warn
1810 * the user though...
1812 if (status
== -NFS4ERR_BAD_SEQID
) {
1813 printk(KERN_WARNING
"NFS: v4 server %s "
1814 " returned a bad sequence-id error!\n",
1815 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1816 exception
.retry
= 1;
1820 * BAD_STATEID on OPEN means that the server cancelled our
1821 * state before it received the OPEN_CONFIRM.
1822 * Recover by retrying the request as per the discussion
1823 * on Page 181 of RFC3530.
1825 if (status
== -NFS4ERR_BAD_STATEID
) {
1826 exception
.retry
= 1;
1829 if (status
== -EAGAIN
) {
1830 /* We must have found a delegation */
1831 exception
.retry
= 1;
1834 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1835 status
, &exception
));
1836 } while (exception
.retry
);
1840 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1841 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1842 struct nfs4_state
*state
)
1844 struct nfs_server
*server
= NFS_SERVER(inode
);
1845 struct nfs_setattrargs arg
= {
1846 .fh
= NFS_FH(inode
),
1849 .bitmask
= server
->attr_bitmask
,
1851 struct nfs_setattrres res
= {
1855 struct rpc_message msg
= {
1856 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1861 unsigned long timestamp
= jiffies
;
1864 nfs_fattr_init(fattr
);
1866 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1867 /* Use that stateid */
1868 } else if (state
!= NULL
) {
1869 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1871 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1873 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
1874 if (status
== 0 && state
!= NULL
)
1875 renew_lease(server
, timestamp
);
1879 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1880 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1881 struct nfs4_state
*state
)
1883 struct nfs_server
*server
= NFS_SERVER(inode
);
1884 struct nfs4_exception exception
= { };
1887 err
= nfs4_handle_exception(server
,
1888 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1890 } while (exception
.retry
);
1894 struct nfs4_closedata
{
1895 struct inode
*inode
;
1896 struct nfs4_state
*state
;
1897 struct nfs_closeargs arg
;
1898 struct nfs_closeres res
;
1899 struct nfs_fattr fattr
;
1900 unsigned long timestamp
;
1905 static void nfs4_free_closedata(void *data
)
1907 struct nfs4_closedata
*calldata
= data
;
1908 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1909 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
1912 pnfs_roc_release(calldata
->state
->inode
);
1913 nfs4_put_open_state(calldata
->state
);
1914 nfs_free_seqid(calldata
->arg
.seqid
);
1915 nfs4_put_state_owner(sp
);
1916 nfs_sb_deactive(sb
);
1920 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1923 spin_lock(&state
->owner
->so_lock
);
1924 if (!(fmode
& FMODE_READ
))
1925 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1926 if (!(fmode
& FMODE_WRITE
))
1927 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1928 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1929 spin_unlock(&state
->owner
->so_lock
);
1932 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1934 struct nfs4_closedata
*calldata
= data
;
1935 struct nfs4_state
*state
= calldata
->state
;
1936 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1938 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1940 /* hmm. we are done with the inode, and in the process of freeing
1941 * the state_owner. we keep this around to process errors
1943 switch (task
->tk_status
) {
1946 pnfs_roc_set_barrier(state
->inode
,
1947 calldata
->roc_barrier
);
1948 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1949 renew_lease(server
, calldata
->timestamp
);
1950 nfs4_close_clear_stateid_flags(state
,
1951 calldata
->arg
.fmode
);
1953 case -NFS4ERR_STALE_STATEID
:
1954 case -NFS4ERR_OLD_STATEID
:
1955 case -NFS4ERR_BAD_STATEID
:
1956 case -NFS4ERR_EXPIRED
:
1957 if (calldata
->arg
.fmode
== 0)
1960 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1961 rpc_restart_call_prepare(task
);
1963 nfs_release_seqid(calldata
->arg
.seqid
);
1964 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1967 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1969 struct nfs4_closedata
*calldata
= data
;
1970 struct nfs4_state
*state
= calldata
->state
;
1973 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1976 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1977 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1978 spin_lock(&state
->owner
->so_lock
);
1979 /* Calculate the change in open mode */
1980 if (state
->n_rdwr
== 0) {
1981 if (state
->n_rdonly
== 0) {
1982 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1983 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1984 calldata
->arg
.fmode
&= ~FMODE_READ
;
1986 if (state
->n_wronly
== 0) {
1987 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1988 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1989 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1992 spin_unlock(&state
->owner
->so_lock
);
1995 /* Note: exit _without_ calling nfs4_close_done */
1996 task
->tk_action
= NULL
;
2000 if (calldata
->arg
.fmode
== 0) {
2001 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2002 if (calldata
->roc
&&
2003 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
2004 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
2010 nfs_fattr_init(calldata
->res
.fattr
);
2011 calldata
->timestamp
= jiffies
;
2012 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
2013 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
2016 rpc_call_start(task
);
2019 static const struct rpc_call_ops nfs4_close_ops
= {
2020 .rpc_call_prepare
= nfs4_close_prepare
,
2021 .rpc_call_done
= nfs4_close_done
,
2022 .rpc_release
= nfs4_free_closedata
,
2026 * It is possible for data to be read/written from a mem-mapped file
2027 * after the sys_close call (which hits the vfs layer as a flush).
2028 * This means that we can't safely call nfsv4 close on a file until
2029 * the inode is cleared. This in turn means that we are not good
2030 * NFSv4 citizens - we do not indicate to the server to update the file's
2031 * share state even when we are done with one of the three share
2032 * stateid's in the inode.
2034 * NOTE: Caller must be holding the sp->so_owner semaphore!
2036 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
2038 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2039 struct nfs4_closedata
*calldata
;
2040 struct nfs4_state_owner
*sp
= state
->owner
;
2041 struct rpc_task
*task
;
2042 struct rpc_message msg
= {
2043 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2044 .rpc_cred
= state
->owner
->so_cred
,
2046 struct rpc_task_setup task_setup_data
= {
2047 .rpc_client
= server
->client
,
2048 .rpc_message
= &msg
,
2049 .callback_ops
= &nfs4_close_ops
,
2050 .workqueue
= nfsiod_workqueue
,
2051 .flags
= RPC_TASK_ASYNC
,
2053 int status
= -ENOMEM
;
2055 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2056 if (calldata
== NULL
)
2058 calldata
->inode
= state
->inode
;
2059 calldata
->state
= state
;
2060 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2061 calldata
->arg
.stateid
= &state
->open_stateid
;
2062 /* Serialization for the sequence id */
2063 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2064 if (calldata
->arg
.seqid
== NULL
)
2065 goto out_free_calldata
;
2066 calldata
->arg
.fmode
= 0;
2067 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2068 calldata
->res
.fattr
= &calldata
->fattr
;
2069 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2070 calldata
->res
.server
= server
;
2071 calldata
->roc
= roc
;
2072 nfs_sb_active(calldata
->inode
->i_sb
);
2074 msg
.rpc_argp
= &calldata
->arg
;
2075 msg
.rpc_resp
= &calldata
->res
;
2076 task_setup_data
.callback_data
= calldata
;
2077 task
= rpc_run_task(&task_setup_data
);
2079 return PTR_ERR(task
);
2082 status
= rpc_wait_for_completion_task(task
);
2089 pnfs_roc_release(state
->inode
);
2090 nfs4_put_open_state(state
);
2091 nfs4_put_state_owner(sp
);
2095 static struct inode
*
2096 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2098 struct nfs4_state
*state
;
2100 /* Protect against concurrent sillydeletes */
2101 state
= nfs4_do_open(dir
, ctx
->dentry
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2103 return ERR_CAST(state
);
2105 return igrab(state
->inode
);
2108 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2110 if (ctx
->state
== NULL
)
2113 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2115 nfs4_close_state(ctx
->state
, ctx
->mode
);
2118 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2120 struct nfs4_server_caps_arg args
= {
2123 struct nfs4_server_caps_res res
= {};
2124 struct rpc_message msg
= {
2125 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2131 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2133 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2134 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2135 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2136 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2137 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2138 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2139 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2140 server
->caps
|= NFS_CAP_ACLS
;
2141 if (res
.has_links
!= 0)
2142 server
->caps
|= NFS_CAP_HARDLINKS
;
2143 if (res
.has_symlinks
!= 0)
2144 server
->caps
|= NFS_CAP_SYMLINKS
;
2145 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2146 server
->caps
|= NFS_CAP_FILEID
;
2147 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2148 server
->caps
|= NFS_CAP_MODE
;
2149 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2150 server
->caps
|= NFS_CAP_NLINK
;
2151 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2152 server
->caps
|= NFS_CAP_OWNER
;
2153 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2154 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2155 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2156 server
->caps
|= NFS_CAP_ATIME
;
2157 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2158 server
->caps
|= NFS_CAP_CTIME
;
2159 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2160 server
->caps
|= NFS_CAP_MTIME
;
2162 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2163 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2164 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2165 server
->acl_bitmask
= res
.acl_bitmask
;
2171 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2173 struct nfs4_exception exception
= { };
2176 err
= nfs4_handle_exception(server
,
2177 _nfs4_server_capabilities(server
, fhandle
),
2179 } while (exception
.retry
);
2183 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2184 struct nfs_fsinfo
*info
)
2186 struct nfs4_lookup_root_arg args
= {
2187 .bitmask
= nfs4_fattr_bitmap
,
2189 struct nfs4_lookup_res res
= {
2191 .fattr
= info
->fattr
,
2194 struct rpc_message msg
= {
2195 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2200 nfs_fattr_init(info
->fattr
);
2201 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2204 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2205 struct nfs_fsinfo
*info
)
2207 struct nfs4_exception exception
= { };
2210 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2213 case -NFS4ERR_WRONGSEC
:
2216 err
= nfs4_handle_exception(server
, err
, &exception
);
2218 } while (exception
.retry
);
2222 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2223 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2225 struct rpc_auth
*auth
;
2228 auth
= rpcauth_create(flavor
, server
->client
);
2233 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2238 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2239 struct nfs_fsinfo
*info
)
2241 int i
, len
, status
= 0;
2242 rpc_authflavor_t flav_array
[NFS_MAX_SECFLAVORS
];
2244 len
= gss_mech_list_pseudoflavors(&flav_array
[0]);
2245 flav_array
[len
] = RPC_AUTH_NULL
;
2248 for (i
= 0; i
< len
; i
++) {
2249 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2250 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2255 * -EACCESS could mean that the user doesn't have correct permissions
2256 * to access the mount. It could also mean that we tried to mount
2257 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2258 * existing mount programs don't handle -EACCES very well so it should
2259 * be mapped to -EPERM instead.
2261 if (status
== -EACCES
)
2267 * get the file handle for the "/" directory on the server
2269 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2270 struct nfs_fsinfo
*info
)
2272 int minor_version
= server
->nfs_client
->cl_minorversion
;
2273 int status
= nfs4_lookup_root(server
, fhandle
, info
);
2274 if ((status
== -NFS4ERR_WRONGSEC
) && !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2276 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2277 * by nfs4_map_errors() as this function exits.
2279 status
= nfs_v4_minor_ops
[minor_version
]->find_root_sec(server
, fhandle
, info
);
2281 status
= nfs4_server_capabilities(server
, fhandle
);
2283 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2284 return nfs4_map_errors(status
);
2287 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
2289 * Get locations and (maybe) other attributes of a referral.
2290 * Note that we'll actually follow the referral later when
2291 * we detect fsid mismatch in inode revalidation
2293 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
,
2294 struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2296 int status
= -ENOMEM
;
2297 struct page
*page
= NULL
;
2298 struct nfs4_fs_locations
*locations
= NULL
;
2300 page
= alloc_page(GFP_KERNEL
);
2303 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2304 if (locations
== NULL
)
2307 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2310 /* Make sure server returned a different fsid for the referral */
2311 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2312 dprintk("%s: server did not return a different fsid for"
2313 " a referral at %s\n", __func__
, name
->name
);
2317 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2318 nfs_fixup_referral_attributes(&locations
->fattr
);
2320 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2321 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2322 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2330 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2332 struct nfs4_getattr_arg args
= {
2334 .bitmask
= server
->attr_bitmask
,
2336 struct nfs4_getattr_res res
= {
2340 struct rpc_message msg
= {
2341 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2346 nfs_fattr_init(fattr
);
2347 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2350 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2352 struct nfs4_exception exception
= { };
2355 err
= nfs4_handle_exception(server
,
2356 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2358 } while (exception
.retry
);
2363 * The file is not closed if it is opened due to the a request to change
2364 * the size of the file. The open call will not be needed once the
2365 * VFS layer lookup-intents are implemented.
2367 * Close is called when the inode is destroyed.
2368 * If we haven't opened the file for O_WRONLY, we
2369 * need to in the size_change case to obtain a stateid.
2372 * Because OPEN is always done by name in nfsv4, it is
2373 * possible that we opened a different file by the same
2374 * name. We can recognize this race condition, but we
2375 * can't do anything about it besides returning an error.
2377 * This will be fixed with VFS changes (lookup-intent).
2380 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2381 struct iattr
*sattr
)
2383 struct inode
*inode
= dentry
->d_inode
;
2384 struct rpc_cred
*cred
= NULL
;
2385 struct nfs4_state
*state
= NULL
;
2388 if (pnfs_ld_layoutret_on_setattr(inode
))
2389 pnfs_return_layout(inode
);
2391 nfs_fattr_init(fattr
);
2393 /* Search for an existing open(O_WRITE) file */
2394 if (sattr
->ia_valid
& ATTR_FILE
) {
2395 struct nfs_open_context
*ctx
;
2397 ctx
= nfs_file_open_context(sattr
->ia_file
);
2404 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2406 nfs_setattr_update_inode(inode
, sattr
);
2410 static int _nfs4_proc_lookupfh(struct rpc_clnt
*clnt
, struct nfs_server
*server
,
2411 const struct nfs_fh
*dirfh
, const struct qstr
*name
,
2412 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2415 struct nfs4_lookup_arg args
= {
2416 .bitmask
= server
->attr_bitmask
,
2420 struct nfs4_lookup_res res
= {
2425 struct rpc_message msg
= {
2426 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2431 nfs_fattr_init(fattr
);
2433 dprintk("NFS call lookupfh %s\n", name
->name
);
2434 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2435 dprintk("NFS reply lookupfh: %d\n", status
);
2439 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2440 struct qstr
*name
, struct nfs_fh
*fhandle
,
2441 struct nfs_fattr
*fattr
)
2443 struct nfs4_exception exception
= { };
2446 err
= _nfs4_proc_lookupfh(server
->client
, server
, dirfh
, name
, fhandle
, fattr
);
2448 if (err
== -NFS4ERR_MOVED
) {
2452 err
= nfs4_handle_exception(server
, err
, &exception
);
2453 } while (exception
.retry
);
2457 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
2458 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2459 struct nfs_fattr
*fattr
)
2463 dprintk("NFS call lookup %s\n", name
->name
);
2464 status
= _nfs4_proc_lookupfh(clnt
, NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2465 if (status
== -NFS4ERR_MOVED
)
2466 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2467 dprintk("NFS reply lookup: %d\n", status
);
2471 void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
, struct nfs_fh
*fh
)
2473 memset(fh
, 0, sizeof(struct nfs_fh
));
2474 fattr
->fsid
.major
= 1;
2475 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
2476 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_FSID
| NFS_ATTR_FATTR_MOUNTPOINT
;
2477 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
2481 static int nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
, struct qstr
*name
,
2482 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2484 struct nfs4_exception exception
= { };
2487 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2488 _nfs4_proc_lookup(clnt
, dir
, name
, fhandle
, fattr
),
2491 nfs_fixup_secinfo_attributes(fattr
, fhandle
);
2492 } while (exception
.retry
);
2496 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2498 struct nfs_server
*server
= NFS_SERVER(inode
);
2499 struct nfs4_accessargs args
= {
2500 .fh
= NFS_FH(inode
),
2501 .bitmask
= server
->attr_bitmask
,
2503 struct nfs4_accessres res
= {
2506 struct rpc_message msg
= {
2507 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2510 .rpc_cred
= entry
->cred
,
2512 int mode
= entry
->mask
;
2516 * Determine which access bits we want to ask for...
2518 if (mode
& MAY_READ
)
2519 args
.access
|= NFS4_ACCESS_READ
;
2520 if (S_ISDIR(inode
->i_mode
)) {
2521 if (mode
& MAY_WRITE
)
2522 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2523 if (mode
& MAY_EXEC
)
2524 args
.access
|= NFS4_ACCESS_LOOKUP
;
2526 if (mode
& MAY_WRITE
)
2527 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2528 if (mode
& MAY_EXEC
)
2529 args
.access
|= NFS4_ACCESS_EXECUTE
;
2532 res
.fattr
= nfs_alloc_fattr();
2533 if (res
.fattr
== NULL
)
2536 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2539 if (res
.access
& NFS4_ACCESS_READ
)
2540 entry
->mask
|= MAY_READ
;
2541 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2542 entry
->mask
|= MAY_WRITE
;
2543 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2544 entry
->mask
|= MAY_EXEC
;
2545 nfs_refresh_inode(inode
, res
.fattr
);
2547 nfs_free_fattr(res
.fattr
);
2551 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2553 struct nfs4_exception exception
= { };
2556 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2557 _nfs4_proc_access(inode
, entry
),
2559 } while (exception
.retry
);
2564 * TODO: For the time being, we don't try to get any attributes
2565 * along with any of the zero-copy operations READ, READDIR,
2568 * In the case of the first three, we want to put the GETATTR
2569 * after the read-type operation -- this is because it is hard
2570 * to predict the length of a GETATTR response in v4, and thus
2571 * align the READ data correctly. This means that the GETATTR
2572 * may end up partially falling into the page cache, and we should
2573 * shift it into the 'tail' of the xdr_buf before processing.
2574 * To do this efficiently, we need to know the total length
2575 * of data received, which doesn't seem to be available outside
2578 * In the case of WRITE, we also want to put the GETATTR after
2579 * the operation -- in this case because we want to make sure
2580 * we get the post-operation mtime and size. This means that
2581 * we can't use xdr_encode_pages() as written: we need a variant
2582 * of it which would leave room in the 'tail' iovec.
2584 * Both of these changes to the XDR layer would in fact be quite
2585 * minor, but I decided to leave them for a subsequent patch.
2587 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2588 unsigned int pgbase
, unsigned int pglen
)
2590 struct nfs4_readlink args
= {
2591 .fh
= NFS_FH(inode
),
2596 struct nfs4_readlink_res res
;
2597 struct rpc_message msg
= {
2598 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2603 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2606 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2607 unsigned int pgbase
, unsigned int pglen
)
2609 struct nfs4_exception exception
= { };
2612 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2613 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2615 } while (exception
.retry
);
2621 * We will need to arrange for the VFS layer to provide an atomic open.
2622 * Until then, this create/open method is prone to inefficiency and race
2623 * conditions due to the lookup, create, and open VFS calls from sys_open()
2624 * placed on the wire.
2626 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2627 * The file will be opened again in the subsequent VFS open call
2628 * (nfs4_proc_file_open).
2630 * The open for read will just hang around to be used by any process that
2631 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2635 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2636 int flags
, struct nfs_open_context
*ctx
)
2638 struct dentry
*de
= dentry
;
2639 struct nfs4_state
*state
;
2640 struct rpc_cred
*cred
= NULL
;
2649 sattr
->ia_mode
&= ~current_umask();
2650 state
= nfs4_do_open(dir
, de
, fmode
, flags
, sattr
, cred
);
2652 if (IS_ERR(state
)) {
2653 status
= PTR_ERR(state
);
2656 d_add(dentry
, igrab(state
->inode
));
2657 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2661 nfs4_close_sync(state
, fmode
);
2666 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2668 struct nfs_server
*server
= NFS_SERVER(dir
);
2669 struct nfs_removeargs args
= {
2671 .name
.len
= name
->len
,
2672 .name
.name
= name
->name
,
2673 .bitmask
= server
->attr_bitmask
,
2675 struct nfs_removeres res
= {
2678 struct rpc_message msg
= {
2679 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2683 int status
= -ENOMEM
;
2685 res
.dir_attr
= nfs_alloc_fattr();
2686 if (res
.dir_attr
== NULL
)
2689 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
2691 update_changeattr(dir
, &res
.cinfo
);
2692 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2694 nfs_free_fattr(res
.dir_attr
);
2699 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2701 struct nfs4_exception exception
= { };
2704 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2705 _nfs4_proc_remove(dir
, name
),
2707 } while (exception
.retry
);
2711 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2713 struct nfs_server
*server
= NFS_SERVER(dir
);
2714 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2715 struct nfs_removeres
*res
= msg
->rpc_resp
;
2717 args
->bitmask
= server
->cache_consistency_bitmask
;
2718 res
->server
= server
;
2719 res
->seq_res
.sr_slot
= NULL
;
2720 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2723 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2725 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2727 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2729 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2731 update_changeattr(dir
, &res
->cinfo
);
2732 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2736 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2738 struct nfs_server
*server
= NFS_SERVER(dir
);
2739 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2740 struct nfs_renameres
*res
= msg
->rpc_resp
;
2742 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2743 arg
->bitmask
= server
->attr_bitmask
;
2744 res
->server
= server
;
2747 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2748 struct inode
*new_dir
)
2750 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2752 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2754 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2757 update_changeattr(old_dir
, &res
->old_cinfo
);
2758 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2759 update_changeattr(new_dir
, &res
->new_cinfo
);
2760 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2764 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2765 struct inode
*new_dir
, struct qstr
*new_name
)
2767 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2768 struct nfs_renameargs arg
= {
2769 .old_dir
= NFS_FH(old_dir
),
2770 .new_dir
= NFS_FH(new_dir
),
2771 .old_name
= old_name
,
2772 .new_name
= new_name
,
2773 .bitmask
= server
->attr_bitmask
,
2775 struct nfs_renameres res
= {
2778 struct rpc_message msg
= {
2779 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2783 int status
= -ENOMEM
;
2785 res
.old_fattr
= nfs_alloc_fattr();
2786 res
.new_fattr
= nfs_alloc_fattr();
2787 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2790 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2792 update_changeattr(old_dir
, &res
.old_cinfo
);
2793 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2794 update_changeattr(new_dir
, &res
.new_cinfo
);
2795 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2798 nfs_free_fattr(res
.new_fattr
);
2799 nfs_free_fattr(res
.old_fattr
);
2803 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2804 struct inode
*new_dir
, struct qstr
*new_name
)
2806 struct nfs4_exception exception
= { };
2809 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2810 _nfs4_proc_rename(old_dir
, old_name
,
2813 } while (exception
.retry
);
2817 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2819 struct nfs_server
*server
= NFS_SERVER(inode
);
2820 struct nfs4_link_arg arg
= {
2821 .fh
= NFS_FH(inode
),
2822 .dir_fh
= NFS_FH(dir
),
2824 .bitmask
= server
->attr_bitmask
,
2826 struct nfs4_link_res res
= {
2829 struct rpc_message msg
= {
2830 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2834 int status
= -ENOMEM
;
2836 res
.fattr
= nfs_alloc_fattr();
2837 res
.dir_attr
= nfs_alloc_fattr();
2838 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2841 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2843 update_changeattr(dir
, &res
.cinfo
);
2844 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2845 nfs_post_op_update_inode(inode
, res
.fattr
);
2848 nfs_free_fattr(res
.dir_attr
);
2849 nfs_free_fattr(res
.fattr
);
2853 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2855 struct nfs4_exception exception
= { };
2858 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2859 _nfs4_proc_link(inode
, dir
, name
),
2861 } while (exception
.retry
);
2865 struct nfs4_createdata
{
2866 struct rpc_message msg
;
2867 struct nfs4_create_arg arg
;
2868 struct nfs4_create_res res
;
2870 struct nfs_fattr fattr
;
2871 struct nfs_fattr dir_fattr
;
2874 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2875 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2877 struct nfs4_createdata
*data
;
2879 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2881 struct nfs_server
*server
= NFS_SERVER(dir
);
2883 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2884 data
->msg
.rpc_argp
= &data
->arg
;
2885 data
->msg
.rpc_resp
= &data
->res
;
2886 data
->arg
.dir_fh
= NFS_FH(dir
);
2887 data
->arg
.server
= server
;
2888 data
->arg
.name
= name
;
2889 data
->arg
.attrs
= sattr
;
2890 data
->arg
.ftype
= ftype
;
2891 data
->arg
.bitmask
= server
->attr_bitmask
;
2892 data
->res
.server
= server
;
2893 data
->res
.fh
= &data
->fh
;
2894 data
->res
.fattr
= &data
->fattr
;
2895 data
->res
.dir_fattr
= &data
->dir_fattr
;
2896 nfs_fattr_init(data
->res
.fattr
);
2897 nfs_fattr_init(data
->res
.dir_fattr
);
2902 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2904 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
2905 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
2907 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2908 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2909 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2914 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2919 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2920 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2922 struct nfs4_createdata
*data
;
2923 int status
= -ENAMETOOLONG
;
2925 if (len
> NFS4_MAXPATHLEN
)
2929 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2933 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2934 data
->arg
.u
.symlink
.pages
= &page
;
2935 data
->arg
.u
.symlink
.len
= len
;
2937 status
= nfs4_do_create(dir
, dentry
, data
);
2939 nfs4_free_createdata(data
);
2944 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2945 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2947 struct nfs4_exception exception
= { };
2950 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2951 _nfs4_proc_symlink(dir
, dentry
, page
,
2954 } while (exception
.retry
);
2958 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2959 struct iattr
*sattr
)
2961 struct nfs4_createdata
*data
;
2962 int status
= -ENOMEM
;
2964 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2968 status
= nfs4_do_create(dir
, dentry
, data
);
2970 nfs4_free_createdata(data
);
2975 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2976 struct iattr
*sattr
)
2978 struct nfs4_exception exception
= { };
2981 sattr
->ia_mode
&= ~current_umask();
2983 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2984 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2986 } while (exception
.retry
);
2990 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2991 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2993 struct inode
*dir
= dentry
->d_inode
;
2994 struct nfs4_readdir_arg args
= {
2999 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
3002 struct nfs4_readdir_res res
;
3003 struct rpc_message msg
= {
3004 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3011 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
3012 dentry
->d_parent
->d_name
.name
,
3013 dentry
->d_name
.name
,
3014 (unsigned long long)cookie
);
3015 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
3016 res
.pgbase
= args
.pgbase
;
3017 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3019 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3020 status
+= args
.pgbase
;
3023 nfs_invalidate_atime(dir
);
3025 dprintk("%s: returns %d\n", __func__
, status
);
3029 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3030 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3032 struct nfs4_exception exception
= { };
3035 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
3036 _nfs4_proc_readdir(dentry
, cred
, cookie
,
3037 pages
, count
, plus
),
3039 } while (exception
.retry
);
3043 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3044 struct iattr
*sattr
, dev_t rdev
)
3046 struct nfs4_createdata
*data
;
3047 int mode
= sattr
->ia_mode
;
3048 int status
= -ENOMEM
;
3050 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
3051 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
3053 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3058 data
->arg
.ftype
= NF4FIFO
;
3059 else if (S_ISBLK(mode
)) {
3060 data
->arg
.ftype
= NF4BLK
;
3061 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3062 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3064 else if (S_ISCHR(mode
)) {
3065 data
->arg
.ftype
= NF4CHR
;
3066 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3067 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3070 status
= nfs4_do_create(dir
, dentry
, data
);
3072 nfs4_free_createdata(data
);
3077 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3078 struct iattr
*sattr
, dev_t rdev
)
3080 struct nfs4_exception exception
= { };
3083 sattr
->ia_mode
&= ~current_umask();
3085 err
= nfs4_handle_exception(NFS_SERVER(dir
),
3086 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
3088 } while (exception
.retry
);
3092 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3093 struct nfs_fsstat
*fsstat
)
3095 struct nfs4_statfs_arg args
= {
3097 .bitmask
= server
->attr_bitmask
,
3099 struct nfs4_statfs_res res
= {
3102 struct rpc_message msg
= {
3103 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3108 nfs_fattr_init(fsstat
->fattr
);
3109 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3112 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3114 struct nfs4_exception exception
= { };
3117 err
= nfs4_handle_exception(server
,
3118 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3120 } while (exception
.retry
);
3124 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3125 struct nfs_fsinfo
*fsinfo
)
3127 struct nfs4_fsinfo_arg args
= {
3129 .bitmask
= server
->attr_bitmask
,
3131 struct nfs4_fsinfo_res res
= {
3134 struct rpc_message msg
= {
3135 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3140 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3143 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3145 struct nfs4_exception exception
= { };
3149 err
= nfs4_handle_exception(server
,
3150 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3152 } while (exception
.retry
);
3156 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3158 nfs_fattr_init(fsinfo
->fattr
);
3159 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3162 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3163 struct nfs_pathconf
*pathconf
)
3165 struct nfs4_pathconf_arg args
= {
3167 .bitmask
= server
->attr_bitmask
,
3169 struct nfs4_pathconf_res res
= {
3170 .pathconf
= pathconf
,
3172 struct rpc_message msg
= {
3173 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3178 /* None of the pathconf attributes are mandatory to implement */
3179 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3180 memset(pathconf
, 0, sizeof(*pathconf
));
3184 nfs_fattr_init(pathconf
->fattr
);
3185 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3188 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3189 struct nfs_pathconf
*pathconf
)
3191 struct nfs4_exception exception
= { };
3195 err
= nfs4_handle_exception(server
,
3196 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3198 } while (exception
.retry
);
3202 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3204 nfs_invalidate_atime(data
->inode
);
3207 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3209 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3211 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3212 nfs_restart_rpc(task
, server
->nfs_client
);
3216 __nfs4_read_done_cb(data
);
3217 if (task
->tk_status
> 0)
3218 renew_lease(server
, data
->timestamp
);
3222 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3225 dprintk("--> %s\n", __func__
);
3227 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3230 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3231 nfs4_read_done_cb(task
, data
);
3234 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3236 data
->timestamp
= jiffies
;
3237 data
->read_done_cb
= nfs4_read_done_cb
;
3238 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3241 /* Reset the the nfs_read_data to send the read to the MDS. */
3242 void nfs4_reset_read(struct rpc_task
*task
, struct nfs_read_data
*data
)
3244 dprintk("%s Reset task for i/o through\n", __func__
);
3245 put_lseg(data
->lseg
);
3247 /* offsets will differ in the dense stripe case */
3248 data
->args
.offset
= data
->mds_offset
;
3249 data
->ds_clp
= NULL
;
3250 data
->args
.fh
= NFS_FH(data
->inode
);
3251 data
->read_done_cb
= nfs4_read_done_cb
;
3252 task
->tk_ops
= data
->mds_ops
;
3253 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3255 EXPORT_SYMBOL_GPL(nfs4_reset_read
);
3257 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3259 struct inode
*inode
= data
->inode
;
3261 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3262 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3265 if (task
->tk_status
>= 0) {
3266 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3267 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3272 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3274 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3276 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
3277 nfs4_write_done_cb(task
, data
);
3280 /* Reset the the nfs_write_data to send the write to the MDS. */
3281 void nfs4_reset_write(struct rpc_task
*task
, struct nfs_write_data
*data
)
3283 dprintk("%s Reset task for i/o through\n", __func__
);
3284 put_lseg(data
->lseg
);
3286 data
->ds_clp
= NULL
;
3287 data
->write_done_cb
= nfs4_write_done_cb
;
3288 data
->args
.fh
= NFS_FH(data
->inode
);
3289 data
->args
.bitmask
= data
->res
.server
->cache_consistency_bitmask
;
3290 data
->args
.offset
= data
->mds_offset
;
3291 data
->res
.fattr
= &data
->fattr
;
3292 task
->tk_ops
= data
->mds_ops
;
3293 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3295 EXPORT_SYMBOL_GPL(nfs4_reset_write
);
3297 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3299 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3302 data
->args
.bitmask
= NULL
;
3303 data
->res
.fattr
= NULL
;
3305 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3306 if (!data
->write_done_cb
)
3307 data
->write_done_cb
= nfs4_write_done_cb
;
3308 data
->res
.server
= server
;
3309 data
->timestamp
= jiffies
;
3311 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3314 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3316 struct inode
*inode
= data
->inode
;
3318 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3319 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3322 nfs_refresh_inode(inode
, data
->res
.fattr
);
3326 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3328 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3330 return data
->write_done_cb(task
, data
);
3333 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3335 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3338 data
->args
.bitmask
= NULL
;
3339 data
->res
.fattr
= NULL
;
3341 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3342 if (!data
->write_done_cb
)
3343 data
->write_done_cb
= nfs4_commit_done_cb
;
3344 data
->res
.server
= server
;
3345 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3348 struct nfs4_renewdata
{
3349 struct nfs_client
*client
;
3350 unsigned long timestamp
;
3354 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3355 * standalone procedure for queueing an asynchronous RENEW.
3357 static void nfs4_renew_release(void *calldata
)
3359 struct nfs4_renewdata
*data
= calldata
;
3360 struct nfs_client
*clp
= data
->client
;
3362 if (atomic_read(&clp
->cl_count
) > 1)
3363 nfs4_schedule_state_renewal(clp
);
3364 nfs_put_client(clp
);
3368 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3370 struct nfs4_renewdata
*data
= calldata
;
3371 struct nfs_client
*clp
= data
->client
;
3372 unsigned long timestamp
= data
->timestamp
;
3374 if (task
->tk_status
< 0) {
3375 /* Unless we're shutting down, schedule state recovery! */
3376 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3377 nfs4_schedule_lease_recovery(clp
);
3380 do_renew_lease(clp
, timestamp
);
3383 static const struct rpc_call_ops nfs4_renew_ops
= {
3384 .rpc_call_done
= nfs4_renew_done
,
3385 .rpc_release
= nfs4_renew_release
,
3388 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3390 struct rpc_message msg
= {
3391 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3395 struct nfs4_renewdata
*data
;
3397 if (!atomic_inc_not_zero(&clp
->cl_count
))
3399 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
3403 data
->timestamp
= jiffies
;
3404 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3405 &nfs4_renew_ops
, data
);
3408 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3410 struct rpc_message msg
= {
3411 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3415 unsigned long now
= jiffies
;
3418 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3421 do_renew_lease(clp
, now
);
3425 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3427 return (server
->caps
& NFS_CAP_ACLS
)
3428 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3429 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3432 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3433 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3436 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3438 static void buf_to_pages(const void *buf
, size_t buflen
,
3439 struct page
**pages
, unsigned int *pgbase
)
3441 const void *p
= buf
;
3443 *pgbase
= offset_in_page(buf
);
3445 while (p
< buf
+ buflen
) {
3446 *(pages
++) = virt_to_page(p
);
3447 p
+= PAGE_CACHE_SIZE
;
3451 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3452 struct page
**pages
, unsigned int *pgbase
)
3454 struct page
*newpage
, **spages
;
3460 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3461 newpage
= alloc_page(GFP_KERNEL
);
3463 if (newpage
== NULL
)
3465 memcpy(page_address(newpage
), buf
, len
);
3470 } while (buflen
!= 0);
3476 __free_page(spages
[rc
-1]);
3480 struct nfs4_cached_acl
{
3486 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3488 struct nfs_inode
*nfsi
= NFS_I(inode
);
3490 spin_lock(&inode
->i_lock
);
3491 kfree(nfsi
->nfs4_acl
);
3492 nfsi
->nfs4_acl
= acl
;
3493 spin_unlock(&inode
->i_lock
);
3496 static void nfs4_zap_acl_attr(struct inode
*inode
)
3498 nfs4_set_cached_acl(inode
, NULL
);
3501 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3503 struct nfs_inode
*nfsi
= NFS_I(inode
);
3504 struct nfs4_cached_acl
*acl
;
3507 spin_lock(&inode
->i_lock
);
3508 acl
= nfsi
->nfs4_acl
;
3511 if (buf
== NULL
) /* user is just asking for length */
3513 if (acl
->cached
== 0)
3515 ret
= -ERANGE
; /* see getxattr(2) man page */
3516 if (acl
->len
> buflen
)
3518 memcpy(buf
, acl
->data
, acl
->len
);
3522 spin_unlock(&inode
->i_lock
);
3526 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3528 struct nfs4_cached_acl
*acl
;
3530 if (buf
&& acl_len
<= PAGE_SIZE
) {
3531 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3535 memcpy(acl
->data
, buf
, acl_len
);
3537 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3544 nfs4_set_cached_acl(inode
, acl
);
3547 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3549 struct page
*pages
[NFS4ACL_MAXPAGES
];
3550 struct nfs_getaclargs args
= {
3551 .fh
= NFS_FH(inode
),
3555 struct nfs_getaclres res
= {
3559 struct rpc_message msg
= {
3560 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3564 struct page
*localpage
= NULL
;
3567 if (buflen
< PAGE_SIZE
) {
3568 /* As long as we're doing a round trip to the server anyway,
3569 * let's be prepared for a page of acl data. */
3570 localpage
= alloc_page(GFP_KERNEL
);
3571 resp_buf
= page_address(localpage
);
3572 if (localpage
== NULL
)
3574 args
.acl_pages
[0] = localpage
;
3575 args
.acl_pgbase
= 0;
3576 args
.acl_len
= PAGE_SIZE
;
3579 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3581 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3584 if (res
.acl_len
> args
.acl_len
)
3585 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3587 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3590 if (res
.acl_len
> buflen
)
3593 memcpy(buf
, resp_buf
, res
.acl_len
);
3598 __free_page(localpage
);
3602 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3604 struct nfs4_exception exception
= { };
3607 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3610 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3611 } while (exception
.retry
);
3615 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3617 struct nfs_server
*server
= NFS_SERVER(inode
);
3620 if (!nfs4_server_supports_acls(server
))
3622 ret
= nfs_revalidate_inode(server
, inode
);
3625 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3626 nfs_zap_acl_cache(inode
);
3627 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3630 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3633 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3635 struct nfs_server
*server
= NFS_SERVER(inode
);
3636 struct page
*pages
[NFS4ACL_MAXPAGES
];
3637 struct nfs_setaclargs arg
= {
3638 .fh
= NFS_FH(inode
),
3642 struct nfs_setaclres res
;
3643 struct rpc_message msg
= {
3644 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3650 if (!nfs4_server_supports_acls(server
))
3652 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3655 nfs_inode_return_delegation(inode
);
3656 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3659 * Free each page after tx, so the only ref left is
3660 * held by the network stack
3663 put_page(pages
[i
-1]);
3666 * Acl update can result in inode attribute update.
3667 * so mark the attribute cache invalid.
3669 spin_lock(&inode
->i_lock
);
3670 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3671 spin_unlock(&inode
->i_lock
);
3672 nfs_access_zap_cache(inode
);
3673 nfs_zap_acl_cache(inode
);
3677 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3679 struct nfs4_exception exception
= { };
3682 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3683 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3685 } while (exception
.retry
);
3690 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3692 struct nfs_client
*clp
= server
->nfs_client
;
3694 if (task
->tk_status
>= 0)
3696 switch(task
->tk_status
) {
3697 case -NFS4ERR_ADMIN_REVOKED
:
3698 case -NFS4ERR_BAD_STATEID
:
3699 case -NFS4ERR_OPENMODE
:
3702 nfs4_schedule_stateid_recovery(server
, state
);
3703 goto wait_on_recovery
;
3704 case -NFS4ERR_EXPIRED
:
3706 nfs4_schedule_stateid_recovery(server
, state
);
3707 case -NFS4ERR_STALE_STATEID
:
3708 case -NFS4ERR_STALE_CLIENTID
:
3709 nfs4_schedule_lease_recovery(clp
);
3710 goto wait_on_recovery
;
3711 #if defined(CONFIG_NFS_V4_1)
3712 case -NFS4ERR_BADSESSION
:
3713 case -NFS4ERR_BADSLOT
:
3714 case -NFS4ERR_BAD_HIGH_SLOT
:
3715 case -NFS4ERR_DEADSESSION
:
3716 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3717 case -NFS4ERR_SEQ_FALSE_RETRY
:
3718 case -NFS4ERR_SEQ_MISORDERED
:
3719 dprintk("%s ERROR %d, Reset session\n", __func__
,
3721 nfs4_schedule_session_recovery(clp
->cl_session
);
3722 task
->tk_status
= 0;
3724 #endif /* CONFIG_NFS_V4_1 */
3725 case -NFS4ERR_DELAY
:
3726 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3727 case -NFS4ERR_GRACE
:
3729 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3730 task
->tk_status
= 0;
3732 case -NFS4ERR_RETRY_UNCACHED_REP
:
3733 case -NFS4ERR_OLD_STATEID
:
3734 task
->tk_status
= 0;
3737 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3740 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3741 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3742 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3743 task
->tk_status
= 0;
3747 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3748 unsigned short port
, struct rpc_cred
*cred
,
3749 struct nfs4_setclientid_res
*res
)
3751 nfs4_verifier sc_verifier
;
3752 struct nfs4_setclientid setclientid
= {
3753 .sc_verifier
= &sc_verifier
,
3755 .sc_cb_ident
= clp
->cl_cb_ident
,
3757 struct rpc_message msg
= {
3758 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3759 .rpc_argp
= &setclientid
,
3767 p
= (__be32
*)sc_verifier
.data
;
3768 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3769 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3772 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3773 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3775 rpc_peeraddr2str(clp
->cl_rpcclient
,
3777 rpc_peeraddr2str(clp
->cl_rpcclient
,
3779 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3780 clp
->cl_id_uniquifier
);
3781 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3782 sizeof(setclientid
.sc_netid
),
3783 rpc_peeraddr2str(clp
->cl_rpcclient
,
3784 RPC_DISPLAY_NETID
));
3785 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3786 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3787 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3789 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3790 if (status
!= -NFS4ERR_CLID_INUSE
)
3793 ++clp
->cl_id_uniquifier
;
3797 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3802 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3803 struct nfs4_setclientid_res
*arg
,
3804 struct rpc_cred
*cred
)
3806 struct nfs_fsinfo fsinfo
;
3807 struct rpc_message msg
= {
3808 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3810 .rpc_resp
= &fsinfo
,
3817 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3819 spin_lock(&clp
->cl_lock
);
3820 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3821 clp
->cl_last_renewal
= now
;
3822 spin_unlock(&clp
->cl_lock
);
3827 struct nfs4_delegreturndata
{
3828 struct nfs4_delegreturnargs args
;
3829 struct nfs4_delegreturnres res
;
3831 nfs4_stateid stateid
;
3832 unsigned long timestamp
;
3833 struct nfs_fattr fattr
;
3837 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3839 struct nfs4_delegreturndata
*data
= calldata
;
3841 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3844 switch (task
->tk_status
) {
3845 case -NFS4ERR_STALE_STATEID
:
3846 case -NFS4ERR_EXPIRED
:
3848 renew_lease(data
->res
.server
, data
->timestamp
);
3851 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3853 nfs_restart_rpc(task
, data
->res
.server
->nfs_client
);
3857 data
->rpc_status
= task
->tk_status
;
3860 static void nfs4_delegreturn_release(void *calldata
)
3865 #if defined(CONFIG_NFS_V4_1)
3866 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3868 struct nfs4_delegreturndata
*d_data
;
3870 d_data
= (struct nfs4_delegreturndata
*)data
;
3872 if (nfs4_setup_sequence(d_data
->res
.server
,
3873 &d_data
->args
.seq_args
,
3874 &d_data
->res
.seq_res
, 1, task
))
3876 rpc_call_start(task
);
3878 #endif /* CONFIG_NFS_V4_1 */
3880 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3881 #if defined(CONFIG_NFS_V4_1)
3882 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3883 #endif /* CONFIG_NFS_V4_1 */
3884 .rpc_call_done
= nfs4_delegreturn_done
,
3885 .rpc_release
= nfs4_delegreturn_release
,
3888 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3890 struct nfs4_delegreturndata
*data
;
3891 struct nfs_server
*server
= NFS_SERVER(inode
);
3892 struct rpc_task
*task
;
3893 struct rpc_message msg
= {
3894 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3897 struct rpc_task_setup task_setup_data
= {
3898 .rpc_client
= server
->client
,
3899 .rpc_message
= &msg
,
3900 .callback_ops
= &nfs4_delegreturn_ops
,
3901 .flags
= RPC_TASK_ASYNC
,
3905 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3908 data
->args
.fhandle
= &data
->fh
;
3909 data
->args
.stateid
= &data
->stateid
;
3910 data
->args
.bitmask
= server
->attr_bitmask
;
3911 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3912 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3913 data
->res
.fattr
= &data
->fattr
;
3914 data
->res
.server
= server
;
3915 nfs_fattr_init(data
->res
.fattr
);
3916 data
->timestamp
= jiffies
;
3917 data
->rpc_status
= 0;
3919 task_setup_data
.callback_data
= data
;
3920 msg
.rpc_argp
= &data
->args
;
3921 msg
.rpc_resp
= &data
->res
;
3922 task
= rpc_run_task(&task_setup_data
);
3924 return PTR_ERR(task
);
3927 status
= nfs4_wait_for_completion_rpc_task(task
);
3930 status
= data
->rpc_status
;
3933 nfs_refresh_inode(inode
, &data
->fattr
);
3939 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3941 struct nfs_server
*server
= NFS_SERVER(inode
);
3942 struct nfs4_exception exception
= { };
3945 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3947 case -NFS4ERR_STALE_STATEID
:
3948 case -NFS4ERR_EXPIRED
:
3952 err
= nfs4_handle_exception(server
, err
, &exception
);
3953 } while (exception
.retry
);
3957 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3958 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3961 * sleep, with exponential backoff, and retry the LOCK operation.
3963 static unsigned long
3964 nfs4_set_lock_task_retry(unsigned long timeout
)
3966 schedule_timeout_killable(timeout
);
3968 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3969 return NFS4_LOCK_MAXTIMEOUT
;
3973 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3975 struct inode
*inode
= state
->inode
;
3976 struct nfs_server
*server
= NFS_SERVER(inode
);
3977 struct nfs_client
*clp
= server
->nfs_client
;
3978 struct nfs_lockt_args arg
= {
3979 .fh
= NFS_FH(inode
),
3982 struct nfs_lockt_res res
= {
3985 struct rpc_message msg
= {
3986 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3989 .rpc_cred
= state
->owner
->so_cred
,
3991 struct nfs4_lock_state
*lsp
;
3994 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3995 status
= nfs4_set_lock_state(state
, request
);
3998 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3999 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4000 arg
.lock_owner
.s_dev
= server
->s_dev
;
4001 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4004 request
->fl_type
= F_UNLCK
;
4006 case -NFS4ERR_DENIED
:
4009 request
->fl_ops
->fl_release_private(request
);
4014 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4016 struct nfs4_exception exception
= { };
4020 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4021 _nfs4_proc_getlk(state
, cmd
, request
),
4023 } while (exception
.retry
);
4027 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
4030 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
4032 res
= posix_lock_file_wait(file
, fl
);
4035 res
= flock_lock_file_wait(file
, fl
);
4043 struct nfs4_unlockdata
{
4044 struct nfs_locku_args arg
;
4045 struct nfs_locku_res res
;
4046 struct nfs4_lock_state
*lsp
;
4047 struct nfs_open_context
*ctx
;
4048 struct file_lock fl
;
4049 const struct nfs_server
*server
;
4050 unsigned long timestamp
;
4053 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
4054 struct nfs_open_context
*ctx
,
4055 struct nfs4_lock_state
*lsp
,
4056 struct nfs_seqid
*seqid
)
4058 struct nfs4_unlockdata
*p
;
4059 struct inode
*inode
= lsp
->ls_state
->inode
;
4061 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
4064 p
->arg
.fh
= NFS_FH(inode
);
4066 p
->arg
.seqid
= seqid
;
4067 p
->res
.seqid
= seqid
;
4068 p
->arg
.stateid
= &lsp
->ls_stateid
;
4070 atomic_inc(&lsp
->ls_count
);
4071 /* Ensure we don't close file until we're done freeing locks! */
4072 p
->ctx
= get_nfs_open_context(ctx
);
4073 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4074 p
->server
= NFS_SERVER(inode
);
4078 static void nfs4_locku_release_calldata(void *data
)
4080 struct nfs4_unlockdata
*calldata
= data
;
4081 nfs_free_seqid(calldata
->arg
.seqid
);
4082 nfs4_put_lock_state(calldata
->lsp
);
4083 put_nfs_open_context(calldata
->ctx
);
4087 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
4089 struct nfs4_unlockdata
*calldata
= data
;
4091 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
4093 switch (task
->tk_status
) {
4095 memcpy(calldata
->lsp
->ls_stateid
.data
,
4096 calldata
->res
.stateid
.data
,
4097 sizeof(calldata
->lsp
->ls_stateid
.data
));
4098 renew_lease(calldata
->server
, calldata
->timestamp
);
4100 case -NFS4ERR_BAD_STATEID
:
4101 case -NFS4ERR_OLD_STATEID
:
4102 case -NFS4ERR_STALE_STATEID
:
4103 case -NFS4ERR_EXPIRED
:
4106 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
4107 nfs_restart_rpc(task
,
4108 calldata
->server
->nfs_client
);
4112 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
4114 struct nfs4_unlockdata
*calldata
= data
;
4116 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
4118 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
4119 /* Note: exit _without_ running nfs4_locku_done */
4120 task
->tk_action
= NULL
;
4123 calldata
->timestamp
= jiffies
;
4124 if (nfs4_setup_sequence(calldata
->server
,
4125 &calldata
->arg
.seq_args
,
4126 &calldata
->res
.seq_res
, 1, task
))
4128 rpc_call_start(task
);
4131 static const struct rpc_call_ops nfs4_locku_ops
= {
4132 .rpc_call_prepare
= nfs4_locku_prepare
,
4133 .rpc_call_done
= nfs4_locku_done
,
4134 .rpc_release
= nfs4_locku_release_calldata
,
4137 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
4138 struct nfs_open_context
*ctx
,
4139 struct nfs4_lock_state
*lsp
,
4140 struct nfs_seqid
*seqid
)
4142 struct nfs4_unlockdata
*data
;
4143 struct rpc_message msg
= {
4144 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
4145 .rpc_cred
= ctx
->cred
,
4147 struct rpc_task_setup task_setup_data
= {
4148 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
4149 .rpc_message
= &msg
,
4150 .callback_ops
= &nfs4_locku_ops
,
4151 .workqueue
= nfsiod_workqueue
,
4152 .flags
= RPC_TASK_ASYNC
,
4155 /* Ensure this is an unlock - when canceling a lock, the
4156 * canceled lock is passed in, and it won't be an unlock.
4158 fl
->fl_type
= F_UNLCK
;
4160 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
4162 nfs_free_seqid(seqid
);
4163 return ERR_PTR(-ENOMEM
);
4166 msg
.rpc_argp
= &data
->arg
;
4167 msg
.rpc_resp
= &data
->res
;
4168 task_setup_data
.callback_data
= data
;
4169 return rpc_run_task(&task_setup_data
);
4172 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4174 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4175 struct nfs_seqid
*seqid
;
4176 struct nfs4_lock_state
*lsp
;
4177 struct rpc_task
*task
;
4179 unsigned char fl_flags
= request
->fl_flags
;
4181 status
= nfs4_set_lock_state(state
, request
);
4182 /* Unlock _before_ we do the RPC call */
4183 request
->fl_flags
|= FL_EXISTS
;
4184 down_read(&nfsi
->rwsem
);
4185 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4186 up_read(&nfsi
->rwsem
);
4189 up_read(&nfsi
->rwsem
);
4192 /* Is this a delegated lock? */
4193 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4195 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4196 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4200 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4201 status
= PTR_ERR(task
);
4204 status
= nfs4_wait_for_completion_rpc_task(task
);
4207 request
->fl_flags
= fl_flags
;
4211 struct nfs4_lockdata
{
4212 struct nfs_lock_args arg
;
4213 struct nfs_lock_res res
;
4214 struct nfs4_lock_state
*lsp
;
4215 struct nfs_open_context
*ctx
;
4216 struct file_lock fl
;
4217 unsigned long timestamp
;
4220 struct nfs_server
*server
;
4223 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4224 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4227 struct nfs4_lockdata
*p
;
4228 struct inode
*inode
= lsp
->ls_state
->inode
;
4229 struct nfs_server
*server
= NFS_SERVER(inode
);
4231 p
= kzalloc(sizeof(*p
), gfp_mask
);
4235 p
->arg
.fh
= NFS_FH(inode
);
4237 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4238 if (p
->arg
.open_seqid
== NULL
)
4240 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4241 if (p
->arg
.lock_seqid
== NULL
)
4242 goto out_free_seqid
;
4243 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4244 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4245 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4246 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4247 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4250 atomic_inc(&lsp
->ls_count
);
4251 p
->ctx
= get_nfs_open_context(ctx
);
4252 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4255 nfs_free_seqid(p
->arg
.open_seqid
);
4261 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4263 struct nfs4_lockdata
*data
= calldata
;
4264 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4266 dprintk("%s: begin!\n", __func__
);
4267 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4269 /* Do we need to do an open_to_lock_owner? */
4270 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4271 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4273 data
->arg
.open_stateid
= &state
->stateid
;
4274 data
->arg
.new_lock_owner
= 1;
4275 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4277 data
->arg
.new_lock_owner
= 0;
4278 data
->timestamp
= jiffies
;
4279 if (nfs4_setup_sequence(data
->server
,
4280 &data
->arg
.seq_args
,
4281 &data
->res
.seq_res
, 1, task
))
4283 rpc_call_start(task
);
4284 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4287 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4289 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4290 nfs4_lock_prepare(task
, calldata
);
4293 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4295 struct nfs4_lockdata
*data
= calldata
;
4297 dprintk("%s: begin!\n", __func__
);
4299 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4302 data
->rpc_status
= task
->tk_status
;
4303 if (data
->arg
.new_lock_owner
!= 0) {
4304 if (data
->rpc_status
== 0)
4305 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4309 if (data
->rpc_status
== 0) {
4310 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4311 sizeof(data
->lsp
->ls_stateid
.data
));
4312 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4313 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
4316 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4319 static void nfs4_lock_release(void *calldata
)
4321 struct nfs4_lockdata
*data
= calldata
;
4323 dprintk("%s: begin!\n", __func__
);
4324 nfs_free_seqid(data
->arg
.open_seqid
);
4325 if (data
->cancelled
!= 0) {
4326 struct rpc_task
*task
;
4327 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4328 data
->arg
.lock_seqid
);
4330 rpc_put_task_async(task
);
4331 dprintk("%s: cancelling lock!\n", __func__
);
4333 nfs_free_seqid(data
->arg
.lock_seqid
);
4334 nfs4_put_lock_state(data
->lsp
);
4335 put_nfs_open_context(data
->ctx
);
4337 dprintk("%s: done!\n", __func__
);
4340 static const struct rpc_call_ops nfs4_lock_ops
= {
4341 .rpc_call_prepare
= nfs4_lock_prepare
,
4342 .rpc_call_done
= nfs4_lock_done
,
4343 .rpc_release
= nfs4_lock_release
,
4346 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4347 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4348 .rpc_call_done
= nfs4_lock_done
,
4349 .rpc_release
= nfs4_lock_release
,
4352 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4355 case -NFS4ERR_ADMIN_REVOKED
:
4356 case -NFS4ERR_BAD_STATEID
:
4357 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4358 if (new_lock_owner
!= 0 ||
4359 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4360 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
4362 case -NFS4ERR_STALE_STATEID
:
4363 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4364 case -NFS4ERR_EXPIRED
:
4365 nfs4_schedule_lease_recovery(server
->nfs_client
);
4369 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4371 struct nfs4_lockdata
*data
;
4372 struct rpc_task
*task
;
4373 struct rpc_message msg
= {
4374 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4375 .rpc_cred
= state
->owner
->so_cred
,
4377 struct rpc_task_setup task_setup_data
= {
4378 .rpc_client
= NFS_CLIENT(state
->inode
),
4379 .rpc_message
= &msg
,
4380 .callback_ops
= &nfs4_lock_ops
,
4381 .workqueue
= nfsiod_workqueue
,
4382 .flags
= RPC_TASK_ASYNC
,
4386 dprintk("%s: begin!\n", __func__
);
4387 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4388 fl
->fl_u
.nfs4_fl
.owner
,
4389 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4393 data
->arg
.block
= 1;
4394 if (recovery_type
> NFS_LOCK_NEW
) {
4395 if (recovery_type
== NFS_LOCK_RECLAIM
)
4396 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4397 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4399 msg
.rpc_argp
= &data
->arg
;
4400 msg
.rpc_resp
= &data
->res
;
4401 task_setup_data
.callback_data
= data
;
4402 task
= rpc_run_task(&task_setup_data
);
4404 return PTR_ERR(task
);
4405 ret
= nfs4_wait_for_completion_rpc_task(task
);
4407 ret
= data
->rpc_status
;
4409 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4410 data
->arg
.new_lock_owner
, ret
);
4412 data
->cancelled
= 1;
4414 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4418 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4420 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4421 struct nfs4_exception exception
= { };
4425 /* Cache the lock if possible... */
4426 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4428 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4429 if (err
!= -NFS4ERR_DELAY
)
4431 nfs4_handle_exception(server
, err
, &exception
);
4432 } while (exception
.retry
);
4436 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4438 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4439 struct nfs4_exception exception
= { };
4442 err
= nfs4_set_lock_state(state
, request
);
4446 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4448 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4452 case -NFS4ERR_GRACE
:
4453 case -NFS4ERR_DELAY
:
4454 nfs4_handle_exception(server
, err
, &exception
);
4457 } while (exception
.retry
);
4462 #if defined(CONFIG_NFS_V4_1)
4463 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4466 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4468 status
= nfs41_test_stateid(server
, state
);
4469 if (status
== NFS_OK
)
4471 nfs41_free_stateid(server
, state
);
4472 return nfs4_lock_expired(state
, request
);
4476 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4478 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4479 unsigned char fl_flags
= request
->fl_flags
;
4480 int status
= -ENOLCK
;
4482 if ((fl_flags
& FL_POSIX
) &&
4483 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4485 /* Is this a delegated open? */
4486 status
= nfs4_set_lock_state(state
, request
);
4489 request
->fl_flags
|= FL_ACCESS
;
4490 status
= do_vfs_lock(request
->fl_file
, request
);
4493 down_read(&nfsi
->rwsem
);
4494 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4495 /* Yes: cache locks! */
4496 /* ...but avoid races with delegation recall... */
4497 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4498 status
= do_vfs_lock(request
->fl_file
, request
);
4501 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4504 /* Note: we always want to sleep here! */
4505 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4506 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4507 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4509 up_read(&nfsi
->rwsem
);
4511 request
->fl_flags
= fl_flags
;
4515 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4517 struct nfs4_exception exception
= { };
4521 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4522 if (err
== -NFS4ERR_DENIED
)
4524 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4526 } while (exception
.retry
);
4531 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4533 struct nfs_open_context
*ctx
;
4534 struct nfs4_state
*state
;
4535 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4538 /* verify open state */
4539 ctx
= nfs_file_open_context(filp
);
4542 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4545 if (IS_GETLK(cmd
)) {
4547 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4551 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4554 if (request
->fl_type
== F_UNLCK
) {
4556 return nfs4_proc_unlck(state
, cmd
, request
);
4563 status
= nfs4_proc_setlk(state
, cmd
, request
);
4564 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4566 timeout
= nfs4_set_lock_task_retry(timeout
);
4567 status
= -ERESTARTSYS
;
4570 } while(status
< 0);
4574 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4576 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4577 struct nfs4_exception exception
= { };
4580 err
= nfs4_set_lock_state(state
, fl
);
4584 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4587 printk(KERN_ERR
"%s: unhandled error %d.\n",
4592 case -NFS4ERR_EXPIRED
:
4593 nfs4_schedule_stateid_recovery(server
, state
);
4594 case -NFS4ERR_STALE_CLIENTID
:
4595 case -NFS4ERR_STALE_STATEID
:
4596 nfs4_schedule_lease_recovery(server
->nfs_client
);
4598 case -NFS4ERR_BADSESSION
:
4599 case -NFS4ERR_BADSLOT
:
4600 case -NFS4ERR_BAD_HIGH_SLOT
:
4601 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4602 case -NFS4ERR_DEADSESSION
:
4603 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4607 * The show must go on: exit, but mark the
4608 * stateid as needing recovery.
4610 case -NFS4ERR_ADMIN_REVOKED
:
4611 case -NFS4ERR_BAD_STATEID
:
4612 case -NFS4ERR_OPENMODE
:
4613 nfs4_schedule_stateid_recovery(server
, state
);
4618 * User RPCSEC_GSS context has expired.
4619 * We cannot recover this stateid now, so
4620 * skip it and allow recovery thread to
4626 case -NFS4ERR_DENIED
:
4627 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4630 case -NFS4ERR_DELAY
:
4633 err
= nfs4_handle_exception(server
, err
, &exception
);
4634 } while (exception
.retry
);
4639 static void nfs4_release_lockowner_release(void *calldata
)
4644 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4645 .rpc_release
= nfs4_release_lockowner_release
,
4648 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4650 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4651 struct nfs_release_lockowner_args
*args
;
4652 struct rpc_message msg
= {
4653 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4656 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4658 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4661 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4662 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4663 args
->lock_owner
.s_dev
= server
->s_dev
;
4664 msg
.rpc_argp
= args
;
4665 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4668 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4670 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4671 const void *buf
, size_t buflen
,
4672 int flags
, int type
)
4674 if (strcmp(key
, "") != 0)
4677 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4680 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4681 void *buf
, size_t buflen
, int type
)
4683 if (strcmp(key
, "") != 0)
4686 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4689 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4690 size_t list_len
, const char *name
,
4691 size_t name_len
, int type
)
4693 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4695 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4698 if (list
&& len
<= list_len
)
4699 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4704 * nfs_fhget will use either the mounted_on_fileid or the fileid
4706 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4708 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
4709 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
4710 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4711 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4714 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4715 NFS_ATTR_FATTR_NLINK
;
4716 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4720 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4721 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4723 struct nfs_server
*server
= NFS_SERVER(dir
);
4725 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4727 struct nfs4_fs_locations_arg args
= {
4728 .dir_fh
= NFS_FH(dir
),
4733 struct nfs4_fs_locations_res res
= {
4734 .fs_locations
= fs_locations
,
4736 struct rpc_message msg
= {
4737 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4743 dprintk("%s: start\n", __func__
);
4745 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
4746 * is not supported */
4747 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
4748 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
4750 bitmask
[0] |= FATTR4_WORD0_FILEID
;
4752 nfs_fattr_init(&fs_locations
->fattr
);
4753 fs_locations
->server
= server
;
4754 fs_locations
->nlocations
= 0;
4755 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4756 dprintk("%s: returned status = %d\n", __func__
, status
);
4760 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4763 struct nfs4_secinfo_arg args
= {
4764 .dir_fh
= NFS_FH(dir
),
4767 struct nfs4_secinfo_res res
= {
4770 struct rpc_message msg
= {
4771 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
4776 dprintk("NFS call secinfo %s\n", name
->name
);
4777 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4778 dprintk("NFS reply secinfo: %d\n", status
);
4782 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4784 struct nfs4_exception exception
= { };
4787 err
= nfs4_handle_exception(NFS_SERVER(dir
),
4788 _nfs4_proc_secinfo(dir
, name
, flavors
),
4790 } while (exception
.retry
);
4794 #ifdef CONFIG_NFS_V4_1
4796 * Check the exchange flags returned by the server for invalid flags, having
4797 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4800 static int nfs4_check_cl_exchange_flags(u32 flags
)
4802 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4804 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4805 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4807 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4811 return -NFS4ERR_INVAL
;
4815 nfs41_same_server_scope(struct server_scope
*a
, struct server_scope
*b
)
4817 if (a
->server_scope_sz
== b
->server_scope_sz
&&
4818 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
4825 * nfs4_proc_exchange_id()
4827 * Since the clientid has expired, all compounds using sessions
4828 * associated with the stale clientid will be returning
4829 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4830 * be in some phase of session reset.
4832 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4834 nfs4_verifier verifier
;
4835 struct nfs41_exchange_id_args args
= {
4837 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4839 struct nfs41_exchange_id_res res
= {
4843 struct rpc_message msg
= {
4844 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4851 dprintk("--> %s\n", __func__
);
4852 BUG_ON(clp
== NULL
);
4854 p
= (u32
*)verifier
.data
;
4855 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4856 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4857 args
.verifier
= &verifier
;
4859 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4862 init_utsname()->nodename
,
4863 init_utsname()->domainname
,
4864 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4866 res
.server_scope
= kzalloc(sizeof(struct server_scope
), GFP_KERNEL
);
4867 if (unlikely(!res
.server_scope
))
4870 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4872 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4875 if (clp
->server_scope
&&
4876 !nfs41_same_server_scope(clp
->server_scope
,
4877 res
.server_scope
)) {
4878 dprintk("%s: server_scope mismatch detected\n",
4880 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
4881 kfree(clp
->server_scope
);
4882 clp
->server_scope
= NULL
;
4885 if (!clp
->server_scope
)
4886 clp
->server_scope
= res
.server_scope
;
4888 kfree(res
.server_scope
);
4891 dprintk("<-- %s status= %d\n", __func__
, status
);
4895 struct nfs4_get_lease_time_data
{
4896 struct nfs4_get_lease_time_args
*args
;
4897 struct nfs4_get_lease_time_res
*res
;
4898 struct nfs_client
*clp
;
4901 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4905 struct nfs4_get_lease_time_data
*data
=
4906 (struct nfs4_get_lease_time_data
*)calldata
;
4908 dprintk("--> %s\n", __func__
);
4909 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4910 /* just setup sequence, do not trigger session recovery
4911 since we're invoked within one */
4912 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4913 &data
->args
->la_seq_args
,
4914 &data
->res
->lr_seq_res
, 0, task
);
4916 BUG_ON(ret
== -EAGAIN
);
4917 rpc_call_start(task
);
4918 dprintk("<-- %s\n", __func__
);
4922 * Called from nfs4_state_manager thread for session setup, so don't recover
4923 * from sequence operation or clientid errors.
4925 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4927 struct nfs4_get_lease_time_data
*data
=
4928 (struct nfs4_get_lease_time_data
*)calldata
;
4930 dprintk("--> %s\n", __func__
);
4931 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4933 switch (task
->tk_status
) {
4934 case -NFS4ERR_DELAY
:
4935 case -NFS4ERR_GRACE
:
4936 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4937 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4938 task
->tk_status
= 0;
4940 case -NFS4ERR_RETRY_UNCACHED_REP
:
4941 nfs_restart_rpc(task
, data
->clp
);
4944 dprintk("<-- %s\n", __func__
);
4947 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4948 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4949 .rpc_call_done
= nfs4_get_lease_time_done
,
4952 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4954 struct rpc_task
*task
;
4955 struct nfs4_get_lease_time_args args
;
4956 struct nfs4_get_lease_time_res res
= {
4957 .lr_fsinfo
= fsinfo
,
4959 struct nfs4_get_lease_time_data data
= {
4964 struct rpc_message msg
= {
4965 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4969 struct rpc_task_setup task_setup
= {
4970 .rpc_client
= clp
->cl_rpcclient
,
4971 .rpc_message
= &msg
,
4972 .callback_ops
= &nfs4_get_lease_time_ops
,
4973 .callback_data
= &data
,
4974 .flags
= RPC_TASK_TIMEOUT
,
4978 dprintk("--> %s\n", __func__
);
4979 task
= rpc_run_task(&task_setup
);
4982 status
= PTR_ERR(task
);
4984 status
= task
->tk_status
;
4987 dprintk("<-- %s return %d\n", __func__
, status
);
4993 * Reset a slot table
4995 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
4998 struct nfs4_slot
*new = NULL
;
5002 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
5003 max_reqs
, tbl
->max_slots
);
5005 /* Does the newly negotiated max_reqs match the existing slot table? */
5006 if (max_reqs
!= tbl
->max_slots
) {
5008 new = kmalloc(max_reqs
* sizeof(struct nfs4_slot
),
5015 spin_lock(&tbl
->slot_tbl_lock
);
5018 tbl
->max_slots
= max_reqs
;
5020 for (i
= 0; i
< tbl
->max_slots
; ++i
)
5021 tbl
->slots
[i
].seq_nr
= ivalue
;
5022 spin_unlock(&tbl
->slot_tbl_lock
);
5023 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
5024 tbl
, tbl
->slots
, tbl
->max_slots
);
5026 dprintk("<-- %s: return %d\n", __func__
, ret
);
5031 * Reset the forechannel and backchannel slot tables
5033 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
5037 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
5038 session
->fc_attrs
.max_reqs
, 1);
5042 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
5043 session
->bc_attrs
.max_reqs
, 0);
5047 /* Destroy the slot table */
5048 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
5050 if (session
->fc_slot_table
.slots
!= NULL
) {
5051 kfree(session
->fc_slot_table
.slots
);
5052 session
->fc_slot_table
.slots
= NULL
;
5054 if (session
->bc_slot_table
.slots
!= NULL
) {
5055 kfree(session
->bc_slot_table
.slots
);
5056 session
->bc_slot_table
.slots
= NULL
;
5062 * Initialize slot table
5064 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
5065 int max_slots
, int ivalue
)
5067 struct nfs4_slot
*slot
;
5070 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
5072 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
5074 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_NOFS
);
5079 spin_lock(&tbl
->slot_tbl_lock
);
5080 tbl
->max_slots
= max_slots
;
5082 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
5083 spin_unlock(&tbl
->slot_tbl_lock
);
5084 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
5085 tbl
, tbl
->slots
, tbl
->max_slots
);
5087 dprintk("<-- %s: return %d\n", __func__
, ret
);
5092 * Initialize the forechannel and backchannel tables
5094 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
5096 struct nfs4_slot_table
*tbl
;
5099 tbl
= &session
->fc_slot_table
;
5100 if (tbl
->slots
== NULL
) {
5101 status
= nfs4_init_slot_table(tbl
,
5102 session
->fc_attrs
.max_reqs
, 1);
5107 tbl
= &session
->bc_slot_table
;
5108 if (tbl
->slots
== NULL
) {
5109 status
= nfs4_init_slot_table(tbl
,
5110 session
->bc_attrs
.max_reqs
, 0);
5112 nfs4_destroy_slot_tables(session
);
5118 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
5120 struct nfs4_session
*session
;
5121 struct nfs4_slot_table
*tbl
;
5123 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5127 tbl
= &session
->fc_slot_table
;
5128 tbl
->highest_used_slotid
= -1;
5129 spin_lock_init(&tbl
->slot_tbl_lock
);
5130 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
5131 init_completion(&tbl
->complete
);
5133 tbl
= &session
->bc_slot_table
;
5134 tbl
->highest_used_slotid
= -1;
5135 spin_lock_init(&tbl
->slot_tbl_lock
);
5136 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
5137 init_completion(&tbl
->complete
);
5139 session
->session_state
= 1<<NFS4_SESSION_INITING
;
5145 void nfs4_destroy_session(struct nfs4_session
*session
)
5147 nfs4_proc_destroy_session(session
);
5148 dprintk("%s Destroy backchannel for xprt %p\n",
5149 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
5150 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
5151 NFS41_BC_MIN_CALLBACKS
);
5152 nfs4_destroy_slot_tables(session
);
5157 * Initialize the values to be used by the client in CREATE_SESSION
5158 * If nfs4_init_session set the fore channel request and response sizes,
5161 * Set the back channel max_resp_sz_cached to zero to force the client to
5162 * always set csa_cachethis to FALSE because the current implementation
5163 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5165 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
5167 struct nfs4_session
*session
= args
->client
->cl_session
;
5168 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
5169 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
5172 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
5174 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
5175 /* Fore channel attributes */
5176 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
5177 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
5178 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
5179 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
5181 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5182 "max_ops=%u max_reqs=%u\n",
5184 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
5185 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
5187 /* Back channel attributes */
5188 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
5189 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
5190 args
->bc_attrs
.max_resp_sz_cached
= 0;
5191 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
5192 args
->bc_attrs
.max_reqs
= 1;
5194 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5195 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5197 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
5198 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
5199 args
->bc_attrs
.max_reqs
);
5202 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5204 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
5205 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
5207 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
5210 * Our requested max_ops is the minimum we need; we're not
5211 * prepared to break up compounds into smaller pieces than that.
5212 * So, no point even trying to continue if the server won't
5215 if (rcvd
->max_ops
< sent
->max_ops
)
5217 if (rcvd
->max_reqs
== 0)
5222 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5224 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
5225 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
5227 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
5229 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
5231 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
5233 /* These would render the backchannel useless: */
5234 if (rcvd
->max_ops
== 0)
5236 if (rcvd
->max_reqs
== 0)
5241 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
5242 struct nfs4_session
*session
)
5246 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
5249 return nfs4_verify_back_channel_attrs(args
, session
);
5252 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
5254 struct nfs4_session
*session
= clp
->cl_session
;
5255 struct nfs41_create_session_args args
= {
5257 .cb_program
= NFS4_CALLBACK
,
5259 struct nfs41_create_session_res res
= {
5262 struct rpc_message msg
= {
5263 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5269 nfs4_init_channel_attrs(&args
);
5270 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5272 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5275 /* Verify the session's negotiated channel_attrs values */
5276 status
= nfs4_verify_channel_attrs(&args
, session
);
5278 /* Increment the clientid slot sequence id */
5286 * Issues a CREATE_SESSION operation to the server.
5287 * It is the responsibility of the caller to verify the session is
5288 * expired before calling this routine.
5290 int nfs4_proc_create_session(struct nfs_client
*clp
)
5294 struct nfs4_session
*session
= clp
->cl_session
;
5296 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5298 status
= _nfs4_proc_create_session(clp
);
5302 /* Init and reset the fore channel */
5303 status
= nfs4_init_slot_tables(session
);
5304 dprintk("slot table initialization returned %d\n", status
);
5307 status
= nfs4_reset_slot_tables(session
);
5308 dprintk("slot table reset returned %d\n", status
);
5312 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5313 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5314 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5316 dprintk("<-- %s\n", __func__
);
5321 * Issue the over-the-wire RPC DESTROY_SESSION.
5322 * The caller must serialize access to this routine.
5324 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5327 struct rpc_message msg
;
5329 dprintk("--> nfs4_proc_destroy_session\n");
5331 /* session is still being setup */
5332 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5335 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5336 msg
.rpc_argp
= session
;
5337 msg
.rpc_resp
= NULL
;
5338 msg
.rpc_cred
= NULL
;
5339 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5343 "Got error %d from the server on DESTROY_SESSION. "
5344 "Session has been destroyed regardless...\n", status
);
5346 dprintk("<-- nfs4_proc_destroy_session\n");
5350 int nfs4_init_session(struct nfs_server
*server
)
5352 struct nfs_client
*clp
= server
->nfs_client
;
5353 struct nfs4_session
*session
;
5354 unsigned int rsize
, wsize
;
5357 if (!nfs4_has_session(clp
))
5360 session
= clp
->cl_session
;
5361 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5364 rsize
= server
->rsize
;
5366 rsize
= NFS_MAX_FILE_IO_SIZE
;
5367 wsize
= server
->wsize
;
5369 wsize
= NFS_MAX_FILE_IO_SIZE
;
5371 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5372 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5374 ret
= nfs4_recover_expired_lease(server
);
5376 ret
= nfs4_check_client_ready(clp
);
5380 int nfs4_init_ds_session(struct nfs_client
*clp
)
5382 struct nfs4_session
*session
= clp
->cl_session
;
5385 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5388 ret
= nfs4_client_recover_expired_lease(clp
);
5390 /* Test for the DS role */
5391 if (!is_ds_client(clp
))
5394 ret
= nfs4_check_client_ready(clp
);
5398 EXPORT_SYMBOL_GPL(nfs4_init_ds_session
);
5402 * Renew the cl_session lease.
5404 struct nfs4_sequence_data
{
5405 struct nfs_client
*clp
;
5406 struct nfs4_sequence_args args
;
5407 struct nfs4_sequence_res res
;
5410 static void nfs41_sequence_release(void *data
)
5412 struct nfs4_sequence_data
*calldata
= data
;
5413 struct nfs_client
*clp
= calldata
->clp
;
5415 if (atomic_read(&clp
->cl_count
) > 1)
5416 nfs4_schedule_state_renewal(clp
);
5417 nfs_put_client(clp
);
5421 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5423 switch(task
->tk_status
) {
5424 case -NFS4ERR_DELAY
:
5425 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5428 nfs4_schedule_lease_recovery(clp
);
5433 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5435 struct nfs4_sequence_data
*calldata
= data
;
5436 struct nfs_client
*clp
= calldata
->clp
;
5438 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5441 if (task
->tk_status
< 0) {
5442 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5443 if (atomic_read(&clp
->cl_count
) == 1)
5446 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5447 rpc_restart_call_prepare(task
);
5451 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5453 dprintk("<-- %s\n", __func__
);
5456 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5458 struct nfs4_sequence_data
*calldata
= data
;
5459 struct nfs_client
*clp
= calldata
->clp
;
5460 struct nfs4_sequence_args
*args
;
5461 struct nfs4_sequence_res
*res
;
5463 args
= task
->tk_msg
.rpc_argp
;
5464 res
= task
->tk_msg
.rpc_resp
;
5466 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5468 rpc_call_start(task
);
5471 static const struct rpc_call_ops nfs41_sequence_ops
= {
5472 .rpc_call_done
= nfs41_sequence_call_done
,
5473 .rpc_call_prepare
= nfs41_sequence_prepare
,
5474 .rpc_release
= nfs41_sequence_release
,
5477 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5479 struct nfs4_sequence_data
*calldata
;
5480 struct rpc_message msg
= {
5481 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5484 struct rpc_task_setup task_setup_data
= {
5485 .rpc_client
= clp
->cl_rpcclient
,
5486 .rpc_message
= &msg
,
5487 .callback_ops
= &nfs41_sequence_ops
,
5488 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5491 if (!atomic_inc_not_zero(&clp
->cl_count
))
5492 return ERR_PTR(-EIO
);
5493 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5494 if (calldata
== NULL
) {
5495 nfs_put_client(clp
);
5496 return ERR_PTR(-ENOMEM
);
5498 msg
.rpc_argp
= &calldata
->args
;
5499 msg
.rpc_resp
= &calldata
->res
;
5500 calldata
->clp
= clp
;
5501 task_setup_data
.callback_data
= calldata
;
5503 return rpc_run_task(&task_setup_data
);
5506 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5508 struct rpc_task
*task
;
5511 task
= _nfs41_proc_sequence(clp
, cred
);
5513 ret
= PTR_ERR(task
);
5515 rpc_put_task_async(task
);
5516 dprintk("<-- %s status=%d\n", __func__
, ret
);
5520 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5522 struct rpc_task
*task
;
5525 task
= _nfs41_proc_sequence(clp
, cred
);
5527 ret
= PTR_ERR(task
);
5530 ret
= rpc_wait_for_completion_task(task
);
5532 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
5534 if (task
->tk_status
== 0)
5535 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
5536 ret
= task
->tk_status
;
5540 dprintk("<-- %s status=%d\n", __func__
, ret
);
5544 struct nfs4_reclaim_complete_data
{
5545 struct nfs_client
*clp
;
5546 struct nfs41_reclaim_complete_args arg
;
5547 struct nfs41_reclaim_complete_res res
;
5550 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5552 struct nfs4_reclaim_complete_data
*calldata
= data
;
5554 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5555 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5556 &calldata
->arg
.seq_args
,
5557 &calldata
->res
.seq_res
, 0, task
))
5560 rpc_call_start(task
);
5563 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5565 switch(task
->tk_status
) {
5567 case -NFS4ERR_COMPLETE_ALREADY
:
5568 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5570 case -NFS4ERR_DELAY
:
5571 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5573 case -NFS4ERR_RETRY_UNCACHED_REP
:
5576 nfs4_schedule_lease_recovery(clp
);
5581 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5583 struct nfs4_reclaim_complete_data
*calldata
= data
;
5584 struct nfs_client
*clp
= calldata
->clp
;
5585 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5587 dprintk("--> %s\n", __func__
);
5588 if (!nfs41_sequence_done(task
, res
))
5591 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5592 rpc_restart_call_prepare(task
);
5595 dprintk("<-- %s\n", __func__
);
5598 static void nfs4_free_reclaim_complete_data(void *data
)
5600 struct nfs4_reclaim_complete_data
*calldata
= data
;
5605 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5606 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5607 .rpc_call_done
= nfs4_reclaim_complete_done
,
5608 .rpc_release
= nfs4_free_reclaim_complete_data
,
5612 * Issue a global reclaim complete.
5614 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5616 struct nfs4_reclaim_complete_data
*calldata
;
5617 struct rpc_task
*task
;
5618 struct rpc_message msg
= {
5619 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5621 struct rpc_task_setup task_setup_data
= {
5622 .rpc_client
= clp
->cl_rpcclient
,
5623 .rpc_message
= &msg
,
5624 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5625 .flags
= RPC_TASK_ASYNC
,
5627 int status
= -ENOMEM
;
5629 dprintk("--> %s\n", __func__
);
5630 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5631 if (calldata
== NULL
)
5633 calldata
->clp
= clp
;
5634 calldata
->arg
.one_fs
= 0;
5636 msg
.rpc_argp
= &calldata
->arg
;
5637 msg
.rpc_resp
= &calldata
->res
;
5638 task_setup_data
.callback_data
= calldata
;
5639 task
= rpc_run_task(&task_setup_data
);
5641 status
= PTR_ERR(task
);
5644 status
= nfs4_wait_for_completion_rpc_task(task
);
5646 status
= task
->tk_status
;
5650 dprintk("<-- %s status=%d\n", __func__
, status
);
5655 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5657 struct nfs4_layoutget
*lgp
= calldata
;
5658 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5660 dprintk("--> %s\n", __func__
);
5661 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5662 * right now covering the LAYOUTGET we are about to send.
5663 * However, that is not so catastrophic, and there seems
5664 * to be no way to prevent it completely.
5666 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5667 &lgp
->res
.seq_res
, 0, task
))
5669 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5670 NFS_I(lgp
->args
.inode
)->layout
,
5671 lgp
->args
.ctx
->state
)) {
5672 rpc_exit(task
, NFS4_OK
);
5675 rpc_call_start(task
);
5678 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5680 struct nfs4_layoutget
*lgp
= calldata
;
5681 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5683 dprintk("--> %s\n", __func__
);
5685 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5688 switch (task
->tk_status
) {
5691 case -NFS4ERR_LAYOUTTRYLATER
:
5692 case -NFS4ERR_RECALLCONFLICT
:
5693 task
->tk_status
= -NFS4ERR_DELAY
;
5696 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5697 rpc_restart_call_prepare(task
);
5701 dprintk("<-- %s\n", __func__
);
5704 static void nfs4_layoutget_release(void *calldata
)
5706 struct nfs4_layoutget
*lgp
= calldata
;
5708 dprintk("--> %s\n", __func__
);
5709 put_nfs_open_context(lgp
->args
.ctx
);
5711 dprintk("<-- %s\n", __func__
);
5714 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5715 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5716 .rpc_call_done
= nfs4_layoutget_done
,
5717 .rpc_release
= nfs4_layoutget_release
,
5720 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5722 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5723 struct rpc_task
*task
;
5724 struct rpc_message msg
= {
5725 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5726 .rpc_argp
= &lgp
->args
,
5727 .rpc_resp
= &lgp
->res
,
5729 struct rpc_task_setup task_setup_data
= {
5730 .rpc_client
= server
->client
,
5731 .rpc_message
= &msg
,
5732 .callback_ops
= &nfs4_layoutget_call_ops
,
5733 .callback_data
= lgp
,
5734 .flags
= RPC_TASK_ASYNC
,
5738 dprintk("--> %s\n", __func__
);
5740 lgp
->res
.layoutp
= &lgp
->args
.layout
;
5741 lgp
->res
.seq_res
.sr_slot
= NULL
;
5742 task
= rpc_run_task(&task_setup_data
);
5744 return PTR_ERR(task
);
5745 status
= nfs4_wait_for_completion_rpc_task(task
);
5747 status
= task
->tk_status
;
5749 status
= pnfs_layout_process(lgp
);
5751 dprintk("<-- %s status=%d\n", __func__
, status
);
5756 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
5758 struct nfs4_layoutreturn
*lrp
= calldata
;
5760 dprintk("--> %s\n", __func__
);
5761 if (nfs41_setup_sequence(lrp
->clp
->cl_session
, &lrp
->args
.seq_args
,
5762 &lrp
->res
.seq_res
, 0, task
))
5764 rpc_call_start(task
);
5767 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
5769 struct nfs4_layoutreturn
*lrp
= calldata
;
5770 struct nfs_server
*server
;
5771 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
5773 dprintk("--> %s\n", __func__
);
5775 if (!nfs4_sequence_done(task
, &lrp
->res
.seq_res
))
5778 server
= NFS_SERVER(lrp
->args
.inode
);
5779 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5780 nfs_restart_rpc(task
, lrp
->clp
);
5783 spin_lock(&lo
->plh_inode
->i_lock
);
5784 if (task
->tk_status
== 0) {
5785 if (lrp
->res
.lrs_present
) {
5786 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
5788 BUG_ON(!list_empty(&lo
->plh_segs
));
5790 lo
->plh_block_lgets
--;
5791 spin_unlock(&lo
->plh_inode
->i_lock
);
5792 dprintk("<-- %s\n", __func__
);
5795 static void nfs4_layoutreturn_release(void *calldata
)
5797 struct nfs4_layoutreturn
*lrp
= calldata
;
5799 dprintk("--> %s\n", __func__
);
5800 put_layout_hdr(lrp
->args
.layout
);
5802 dprintk("<-- %s\n", __func__
);
5805 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
5806 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
5807 .rpc_call_done
= nfs4_layoutreturn_done
,
5808 .rpc_release
= nfs4_layoutreturn_release
,
5811 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
5813 struct rpc_task
*task
;
5814 struct rpc_message msg
= {
5815 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
5816 .rpc_argp
= &lrp
->args
,
5817 .rpc_resp
= &lrp
->res
,
5819 struct rpc_task_setup task_setup_data
= {
5820 .rpc_client
= lrp
->clp
->cl_rpcclient
,
5821 .rpc_message
= &msg
,
5822 .callback_ops
= &nfs4_layoutreturn_call_ops
,
5823 .callback_data
= lrp
,
5827 dprintk("--> %s\n", __func__
);
5828 task
= rpc_run_task(&task_setup_data
);
5830 return PTR_ERR(task
);
5831 status
= task
->tk_status
;
5832 dprintk("<-- %s status=%d\n", __func__
, status
);
5838 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5840 struct nfs4_getdeviceinfo_args args
= {
5843 struct nfs4_getdeviceinfo_res res
= {
5846 struct rpc_message msg
= {
5847 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5853 dprintk("--> %s\n", __func__
);
5854 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5855 dprintk("<-- %s status=%d\n", __func__
, status
);
5860 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5862 struct nfs4_exception exception
= { };
5866 err
= nfs4_handle_exception(server
,
5867 _nfs4_proc_getdeviceinfo(server
, pdev
),
5869 } while (exception
.retry
);
5872 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5874 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
5876 struct nfs4_layoutcommit_data
*data
= calldata
;
5877 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5879 if (nfs4_setup_sequence(server
, &data
->args
.seq_args
,
5880 &data
->res
.seq_res
, 1, task
))
5882 rpc_call_start(task
);
5886 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
5888 struct nfs4_layoutcommit_data
*data
= calldata
;
5889 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5891 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5894 switch (task
->tk_status
) { /* Just ignore these failures */
5895 case NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
5896 case NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
5897 case NFS4ERR_BADLAYOUT
: /* no layout */
5898 case NFS4ERR_GRACE
: /* loca_recalim always false */
5899 task
->tk_status
= 0;
5902 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5903 nfs_restart_rpc(task
, server
->nfs_client
);
5907 if (task
->tk_status
== 0)
5908 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
5912 static void nfs4_layoutcommit_release(void *calldata
)
5914 struct nfs4_layoutcommit_data
*data
= calldata
;
5916 /* Matched by references in pnfs_set_layoutcommit */
5917 put_lseg(data
->lseg
);
5918 put_rpccred(data
->cred
);
5922 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
5923 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
5924 .rpc_call_done
= nfs4_layoutcommit_done
,
5925 .rpc_release
= nfs4_layoutcommit_release
,
5929 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
5931 struct rpc_message msg
= {
5932 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
5933 .rpc_argp
= &data
->args
,
5934 .rpc_resp
= &data
->res
,
5935 .rpc_cred
= data
->cred
,
5937 struct rpc_task_setup task_setup_data
= {
5938 .task
= &data
->task
,
5939 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
5940 .rpc_message
= &msg
,
5941 .callback_ops
= &nfs4_layoutcommit_ops
,
5942 .callback_data
= data
,
5943 .flags
= RPC_TASK_ASYNC
,
5945 struct rpc_task
*task
;
5948 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
5949 "lbw: %llu inode %lu\n",
5950 data
->task
.tk_pid
, sync
,
5951 data
->args
.lastbytewritten
,
5952 data
->args
.inode
->i_ino
);
5954 task
= rpc_run_task(&task_setup_data
);
5956 return PTR_ERR(task
);
5959 status
= nfs4_wait_for_completion_rpc_task(task
);
5962 status
= task
->tk_status
;
5964 dprintk("%s: status %d\n", __func__
, status
);
5970 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
5971 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
5973 struct nfs41_secinfo_no_name_args args
= {
5974 .style
= SECINFO_STYLE_CURRENT_FH
,
5976 struct nfs4_secinfo_res res
= {
5979 struct rpc_message msg
= {
5980 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
5984 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5988 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
5989 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
5991 struct nfs4_exception exception
= { };
5994 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
5997 case -NFS4ERR_WRONGSEC
:
5998 case -NFS4ERR_NOTSUPP
:
6001 err
= nfs4_handle_exception(server
, err
, &exception
);
6003 } while (exception
.retry
);
6008 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6009 struct nfs_fsinfo
*info
)
6013 rpc_authflavor_t flavor
;
6014 struct nfs4_secinfo_flavors
*flavors
;
6016 page
= alloc_page(GFP_KERNEL
);
6022 flavors
= page_address(page
);
6023 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
6026 * Fall back on "guess and check" method if
6027 * the server doesn't support SECINFO_NO_NAME
6029 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
6030 err
= nfs4_find_root_sec(server
, fhandle
, info
);
6036 flavor
= nfs_find_best_sec(flavors
);
6038 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
6047 static int _nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6050 struct nfs41_test_stateid_args args
= {
6051 .stateid
= &state
->stateid
,
6053 struct nfs41_test_stateid_res res
;
6054 struct rpc_message msg
= {
6055 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
6059 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6060 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6064 static int nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6066 struct nfs4_exception exception
= { };
6069 err
= nfs4_handle_exception(server
,
6070 _nfs41_test_stateid(server
, state
),
6072 } while (exception
.retry
);
6076 static int _nfs4_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6079 struct nfs41_free_stateid_args args
= {
6080 .stateid
= &state
->stateid
,
6082 struct nfs41_free_stateid_res res
;
6083 struct rpc_message msg
= {
6084 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
6089 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6090 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6094 static int nfs41_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6096 struct nfs4_exception exception
= { };
6099 err
= nfs4_handle_exception(server
,
6100 _nfs4_free_stateid(server
, state
),
6102 } while (exception
.retry
);
6105 #endif /* CONFIG_NFS_V4_1 */
6107 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
6108 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6109 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6110 .recover_open
= nfs4_open_reclaim
,
6111 .recover_lock
= nfs4_lock_reclaim
,
6112 .establish_clid
= nfs4_init_clientid
,
6113 .get_clid_cred
= nfs4_get_setclientid_cred
,
6116 #if defined(CONFIG_NFS_V4_1)
6117 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
6118 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6119 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6120 .recover_open
= nfs4_open_reclaim
,
6121 .recover_lock
= nfs4_lock_reclaim
,
6122 .establish_clid
= nfs41_init_clientid
,
6123 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6124 .reclaim_complete
= nfs41_proc_reclaim_complete
,
6126 #endif /* CONFIG_NFS_V4_1 */
6128 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
6129 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6130 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6131 .recover_open
= nfs4_open_expired
,
6132 .recover_lock
= nfs4_lock_expired
,
6133 .establish_clid
= nfs4_init_clientid
,
6134 .get_clid_cred
= nfs4_get_setclientid_cred
,
6137 #if defined(CONFIG_NFS_V4_1)
6138 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
6139 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6140 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6141 .recover_open
= nfs41_open_expired
,
6142 .recover_lock
= nfs41_lock_expired
,
6143 .establish_clid
= nfs41_init_clientid
,
6144 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6146 #endif /* CONFIG_NFS_V4_1 */
6148 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
6149 .sched_state_renewal
= nfs4_proc_async_renew
,
6150 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
6151 .renew_lease
= nfs4_proc_renew
,
6154 #if defined(CONFIG_NFS_V4_1)
6155 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
6156 .sched_state_renewal
= nfs41_proc_async_sequence
,
6157 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
6158 .renew_lease
= nfs4_proc_sequence
,
6162 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
6164 .call_sync
= _nfs4_call_sync
,
6165 .validate_stateid
= nfs4_validate_delegation_stateid
,
6166 .find_root_sec
= nfs4_find_root_sec
,
6167 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
6168 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
6169 .state_renewal_ops
= &nfs40_state_renewal_ops
,
6172 #if defined(CONFIG_NFS_V4_1)
6173 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
6175 .call_sync
= _nfs4_call_sync_session
,
6176 .validate_stateid
= nfs41_validate_delegation_stateid
,
6177 .find_root_sec
= nfs41_find_root_sec
,
6178 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
6179 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
6180 .state_renewal_ops
= &nfs41_state_renewal_ops
,
6184 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
6185 [0] = &nfs_v4_0_minor_ops
,
6186 #if defined(CONFIG_NFS_V4_1)
6187 [1] = &nfs_v4_1_minor_ops
,
6191 static const struct inode_operations nfs4_file_inode_operations
= {
6192 .permission
= nfs_permission
,
6193 .getattr
= nfs_getattr
,
6194 .setattr
= nfs_setattr
,
6195 .getxattr
= generic_getxattr
,
6196 .setxattr
= generic_setxattr
,
6197 .listxattr
= generic_listxattr
,
6198 .removexattr
= generic_removexattr
,
6201 const struct nfs_rpc_ops nfs_v4_clientops
= {
6202 .version
= 4, /* protocol version */
6203 .dentry_ops
= &nfs4_dentry_operations
,
6204 .dir_inode_ops
= &nfs4_dir_inode_operations
,
6205 .file_inode_ops
= &nfs4_file_inode_operations
,
6206 .getroot
= nfs4_proc_get_root
,
6207 .getattr
= nfs4_proc_getattr
,
6208 .setattr
= nfs4_proc_setattr
,
6209 .lookupfh
= nfs4_proc_lookupfh
,
6210 .lookup
= nfs4_proc_lookup
,
6211 .access
= nfs4_proc_access
,
6212 .readlink
= nfs4_proc_readlink
,
6213 .create
= nfs4_proc_create
,
6214 .remove
= nfs4_proc_remove
,
6215 .unlink_setup
= nfs4_proc_unlink_setup
,
6216 .unlink_done
= nfs4_proc_unlink_done
,
6217 .rename
= nfs4_proc_rename
,
6218 .rename_setup
= nfs4_proc_rename_setup
,
6219 .rename_done
= nfs4_proc_rename_done
,
6220 .link
= nfs4_proc_link
,
6221 .symlink
= nfs4_proc_symlink
,
6222 .mkdir
= nfs4_proc_mkdir
,
6223 .rmdir
= nfs4_proc_remove
,
6224 .readdir
= nfs4_proc_readdir
,
6225 .mknod
= nfs4_proc_mknod
,
6226 .statfs
= nfs4_proc_statfs
,
6227 .fsinfo
= nfs4_proc_fsinfo
,
6228 .pathconf
= nfs4_proc_pathconf
,
6229 .set_capabilities
= nfs4_server_capabilities
,
6230 .decode_dirent
= nfs4_decode_dirent
,
6231 .read_setup
= nfs4_proc_read_setup
,
6232 .read_done
= nfs4_read_done
,
6233 .write_setup
= nfs4_proc_write_setup
,
6234 .write_done
= nfs4_write_done
,
6235 .commit_setup
= nfs4_proc_commit_setup
,
6236 .commit_done
= nfs4_commit_done
,
6237 .lock
= nfs4_proc_lock
,
6238 .clear_acl_cache
= nfs4_zap_acl_attr
,
6239 .close_context
= nfs4_close_context
,
6240 .open_context
= nfs4_atomic_open
,
6241 .init_client
= nfs4_init_client
,
6242 .secinfo
= nfs4_proc_secinfo
,
6245 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
6246 .prefix
= XATTR_NAME_NFSV4_ACL
,
6247 .list
= nfs4_xattr_list_nfs4_acl
,
6248 .get
= nfs4_xattr_get_nfs4_acl
,
6249 .set
= nfs4_xattr_set_nfs4_acl
,
6252 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
6253 &nfs4_xattr_nfs4_acl_handler
,