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/ratelimit.h>
43 #include <linux/printk.h>
44 #include <linux/slab.h>
45 #include <linux/sunrpc/clnt.h>
46 #include <linux/sunrpc/gss_api.h>
47 #include <linux/nfs.h>
48 #include <linux/nfs4.h>
49 #include <linux/nfs_fs.h>
50 #include <linux/nfs_page.h>
51 #include <linux/nfs_mount.h>
52 #include <linux/namei.h>
53 #include <linux/mount.h>
54 #include <linux/module.h>
55 #include <linux/nfs_idmap.h>
56 #include <linux/sunrpc/bc_xprt.h>
57 #include <linux/xattr.h>
58 #include <linux/utsname.h>
59 #include <linux/freezer.h>
62 #include "delegation.h"
68 #define NFSDBG_FACILITY NFSDBG_PROC
70 #define NFS4_POLL_RETRY_MIN (HZ/10)
71 #define NFS4_POLL_RETRY_MAX (15*HZ)
73 #define NFS4_MAX_LOOP_ON_RECOVER (10)
76 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
77 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
78 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
79 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
80 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
81 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
82 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
83 struct nfs4_state
*state
);
84 #ifdef CONFIG_NFS_V4_1
85 static int nfs41_test_stateid(struct nfs_server
*, struct nfs4_state
*);
86 static int nfs41_free_stateid(struct nfs_server
*, struct nfs4_state
*);
88 /* Prevent leaks of NFSv4 errors into userland */
89 static int nfs4_map_errors(int err
)
94 case -NFS4ERR_RESOURCE
:
96 case -NFS4ERR_WRONGSEC
:
98 case -NFS4ERR_BADOWNER
:
99 case -NFS4ERR_BADNAME
:
102 dprintk("%s could not handle NFSv4 error %d\n",
110 * This is our standard bitmap for GETATTR requests.
112 const u32 nfs4_fattr_bitmap
[2] = {
114 | FATTR4_WORD0_CHANGE
117 | FATTR4_WORD0_FILEID
,
119 | FATTR4_WORD1_NUMLINKS
121 | FATTR4_WORD1_OWNER_GROUP
122 | FATTR4_WORD1_RAWDEV
123 | FATTR4_WORD1_SPACE_USED
124 | FATTR4_WORD1_TIME_ACCESS
125 | FATTR4_WORD1_TIME_METADATA
126 | FATTR4_WORD1_TIME_MODIFY
129 const u32 nfs4_statfs_bitmap
[2] = {
130 FATTR4_WORD0_FILES_AVAIL
131 | FATTR4_WORD0_FILES_FREE
132 | FATTR4_WORD0_FILES_TOTAL
,
133 FATTR4_WORD1_SPACE_AVAIL
134 | FATTR4_WORD1_SPACE_FREE
135 | FATTR4_WORD1_SPACE_TOTAL
138 const u32 nfs4_pathconf_bitmap
[2] = {
140 | FATTR4_WORD0_MAXNAME
,
144 const u32 nfs4_fsinfo_bitmap
[3] = { FATTR4_WORD0_MAXFILESIZE
145 | FATTR4_WORD0_MAXREAD
146 | FATTR4_WORD0_MAXWRITE
147 | FATTR4_WORD0_LEASE_TIME
,
148 FATTR4_WORD1_TIME_DELTA
149 | FATTR4_WORD1_FS_LAYOUT_TYPES
,
150 FATTR4_WORD2_LAYOUT_BLKSIZE
153 const u32 nfs4_fs_locations_bitmap
[2] = {
155 | FATTR4_WORD0_CHANGE
158 | FATTR4_WORD0_FILEID
159 | FATTR4_WORD0_FS_LOCATIONS
,
161 | FATTR4_WORD1_NUMLINKS
163 | FATTR4_WORD1_OWNER_GROUP
164 | FATTR4_WORD1_RAWDEV
165 | FATTR4_WORD1_SPACE_USED
166 | FATTR4_WORD1_TIME_ACCESS
167 | FATTR4_WORD1_TIME_METADATA
168 | FATTR4_WORD1_TIME_MODIFY
169 | FATTR4_WORD1_MOUNTED_ON_FILEID
172 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
173 struct nfs4_readdir_arg
*readdir
)
177 BUG_ON(readdir
->count
< 80);
179 readdir
->cookie
= cookie
;
180 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
185 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
190 * NFSv4 servers do not return entries for '.' and '..'
191 * Therefore, we fake these entries here. We let '.'
192 * have cookie 0 and '..' have cookie 1. Note that
193 * when talking to the server, we always send cookie 0
196 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
199 *p
++ = xdr_one
; /* next */
200 *p
++ = xdr_zero
; /* cookie, first word */
201 *p
++ = xdr_one
; /* cookie, second word */
202 *p
++ = xdr_one
; /* entry len */
203 memcpy(p
, ".\0\0\0", 4); /* entry */
205 *p
++ = xdr_one
; /* bitmap length */
206 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
207 *p
++ = htonl(8); /* attribute buffer length */
208 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
211 *p
++ = xdr_one
; /* next */
212 *p
++ = xdr_zero
; /* cookie, first word */
213 *p
++ = xdr_two
; /* cookie, second word */
214 *p
++ = xdr_two
; /* entry len */
215 memcpy(p
, "..\0\0", 4); /* entry */
217 *p
++ = xdr_one
; /* bitmap length */
218 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
219 *p
++ = htonl(8); /* attribute buffer length */
220 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
222 readdir
->pgbase
= (char *)p
- (char *)start
;
223 readdir
->count
-= readdir
->pgbase
;
224 kunmap_atomic(start
, KM_USER0
);
227 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
233 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
234 nfs_wait_bit_killable
, TASK_KILLABLE
);
238 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
245 *timeout
= NFS4_POLL_RETRY_MIN
;
246 if (*timeout
> NFS4_POLL_RETRY_MAX
)
247 *timeout
= NFS4_POLL_RETRY_MAX
;
248 freezable_schedule_timeout_killable(*timeout
);
249 if (fatal_signal_pending(current
))
255 /* This is the error handling routine for processes that are allowed
258 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
260 struct nfs_client
*clp
= server
->nfs_client
;
261 struct nfs4_state
*state
= exception
->state
;
264 exception
->retry
= 0;
268 case -NFS4ERR_ADMIN_REVOKED
:
269 case -NFS4ERR_BAD_STATEID
:
270 case -NFS4ERR_OPENMODE
:
273 nfs4_schedule_stateid_recovery(server
, state
);
274 goto wait_on_recovery
;
275 case -NFS4ERR_EXPIRED
:
277 nfs4_schedule_stateid_recovery(server
, state
);
278 case -NFS4ERR_STALE_STATEID
:
279 case -NFS4ERR_STALE_CLIENTID
:
280 nfs4_schedule_lease_recovery(clp
);
281 goto wait_on_recovery
;
282 #if defined(CONFIG_NFS_V4_1)
283 case -NFS4ERR_BADSESSION
:
284 case -NFS4ERR_BADSLOT
:
285 case -NFS4ERR_BAD_HIGH_SLOT
:
286 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
287 case -NFS4ERR_DEADSESSION
:
288 case -NFS4ERR_SEQ_FALSE_RETRY
:
289 case -NFS4ERR_SEQ_MISORDERED
:
290 dprintk("%s ERROR: %d Reset session\n", __func__
,
292 nfs4_schedule_session_recovery(clp
->cl_session
);
293 exception
->retry
= 1;
295 #endif /* defined(CONFIG_NFS_V4_1) */
296 case -NFS4ERR_FILE_OPEN
:
297 if (exception
->timeout
> HZ
) {
298 /* We have retried a decent amount, time to
307 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
310 case -NFS4ERR_RETRY_UNCACHED_REP
:
311 case -NFS4ERR_OLD_STATEID
:
312 exception
->retry
= 1;
314 case -NFS4ERR_BADOWNER
:
315 /* The following works around a Linux server bug! */
316 case -NFS4ERR_BADNAME
:
317 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
318 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
319 exception
->retry
= 1;
320 printk(KERN_WARNING
"NFS: v4 server %s "
321 "does not accept raw "
323 "Reenabling the idmapper.\n",
324 server
->nfs_client
->cl_hostname
);
327 /* We failed to handle the error */
328 return nfs4_map_errors(ret
);
330 ret
= nfs4_wait_clnt_recover(clp
);
332 exception
->retry
= 1;
337 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
339 spin_lock(&clp
->cl_lock
);
340 if (time_before(clp
->cl_last_renewal
,timestamp
))
341 clp
->cl_last_renewal
= timestamp
;
342 spin_unlock(&clp
->cl_lock
);
345 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
347 do_renew_lease(server
->nfs_client
, timestamp
);
350 #if defined(CONFIG_NFS_V4_1)
353 * nfs4_free_slot - free a slot and efficiently update slot table.
355 * freeing a slot is trivially done by clearing its respective bit
357 * If the freed slotid equals highest_used_slotid we want to update it
358 * so that the server would be able to size down the slot table if needed,
359 * otherwise we know that the highest_used_slotid is still in use.
360 * When updating highest_used_slotid there may be "holes" in the bitmap
361 * so we need to scan down from highest_used_slotid to 0 looking for the now
362 * highest slotid in use.
363 * If none found, highest_used_slotid is set to -1.
365 * Must be called while holding tbl->slot_tbl_lock
368 nfs4_free_slot(struct nfs4_slot_table
*tbl
, u8 free_slotid
)
370 int slotid
= free_slotid
;
372 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
373 /* clear used bit in bitmap */
374 __clear_bit(slotid
, tbl
->used_slots
);
376 /* update highest_used_slotid when it is freed */
377 if (slotid
== tbl
->highest_used_slotid
) {
378 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
379 if (slotid
< tbl
->max_slots
)
380 tbl
->highest_used_slotid
= slotid
;
382 tbl
->highest_used_slotid
= -1;
384 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
385 free_slotid
, tbl
->highest_used_slotid
);
389 * Signal state manager thread if session fore channel is drained
391 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
393 struct rpc_task
*task
;
395 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
396 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
398 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
402 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
405 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
406 complete(&ses
->fc_slot_table
.complete
);
410 * Signal state manager thread if session back channel is drained
412 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
414 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
415 ses
->bc_slot_table
.highest_used_slotid
!= -1)
417 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
418 complete(&ses
->bc_slot_table
.complete
);
421 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
423 struct nfs4_slot_table
*tbl
;
425 tbl
= &res
->sr_session
->fc_slot_table
;
427 /* just wake up the next guy waiting since
428 * we may have not consumed a slot after all */
429 dprintk("%s: No slot\n", __func__
);
433 spin_lock(&tbl
->slot_tbl_lock
);
434 nfs4_free_slot(tbl
, res
->sr_slot
- tbl
->slots
);
435 nfs4_check_drain_fc_complete(res
->sr_session
);
436 spin_unlock(&tbl
->slot_tbl_lock
);
440 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
442 unsigned long timestamp
;
443 struct nfs_client
*clp
;
446 * sr_status remains 1 if an RPC level error occurred. The server
447 * may or may not have processed the sequence operation..
448 * Proceed as if the server received and processed the sequence
451 if (res
->sr_status
== 1)
452 res
->sr_status
= NFS_OK
;
454 /* don't increment the sequence number if the task wasn't sent */
455 if (!RPC_WAS_SENT(task
))
458 /* Check the SEQUENCE operation status */
459 switch (res
->sr_status
) {
461 /* Update the slot's sequence and clientid lease timer */
462 ++res
->sr_slot
->seq_nr
;
463 timestamp
= res
->sr_renewal_time
;
464 clp
= res
->sr_session
->clp
;
465 do_renew_lease(clp
, timestamp
);
466 /* Check sequence flags */
467 if (res
->sr_status_flags
!= 0)
468 nfs4_schedule_lease_recovery(clp
);
471 /* The server detected a resend of the RPC call and
472 * returned NFS4ERR_DELAY as per Section 2.10.6.2
475 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
477 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
478 res
->sr_slot
->seq_nr
);
481 /* Just update the slot sequence no. */
482 ++res
->sr_slot
->seq_nr
;
485 /* The session may be reset by one of the error handlers. */
486 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
487 nfs41_sequence_free_slot(res
);
490 if (!rpc_restart_call(task
))
492 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
496 static int nfs4_sequence_done(struct rpc_task
*task
,
497 struct nfs4_sequence_res
*res
)
499 if (res
->sr_session
== NULL
)
501 return nfs41_sequence_done(task
, res
);
505 * nfs4_find_slot - efficiently look for a free slot
507 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
508 * If found, we mark the slot as used, update the highest_used_slotid,
509 * and respectively set up the sequence operation args.
510 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
512 * Note: must be called with under the slot_tbl_lock.
515 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
518 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
519 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
521 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
522 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
524 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
525 if (slotid
>= tbl
->max_slots
)
527 __set_bit(slotid
, tbl
->used_slots
);
528 if (slotid
> tbl
->highest_used_slotid
)
529 tbl
->highest_used_slotid
= slotid
;
532 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
533 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
537 int nfs41_setup_sequence(struct nfs4_session
*session
,
538 struct nfs4_sequence_args
*args
,
539 struct nfs4_sequence_res
*res
,
541 struct rpc_task
*task
)
543 struct nfs4_slot
*slot
;
544 struct nfs4_slot_table
*tbl
;
547 dprintk("--> %s\n", __func__
);
548 /* slot already allocated? */
549 if (res
->sr_slot
!= NULL
)
552 tbl
= &session
->fc_slot_table
;
554 spin_lock(&tbl
->slot_tbl_lock
);
555 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
556 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
557 /* The state manager will wait until the slot table is empty */
558 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
559 spin_unlock(&tbl
->slot_tbl_lock
);
560 dprintk("%s session is draining\n", __func__
);
564 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
565 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
566 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
567 spin_unlock(&tbl
->slot_tbl_lock
);
568 dprintk("%s enforce FIFO order\n", __func__
);
572 slotid
= nfs4_find_slot(tbl
);
573 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
574 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
575 spin_unlock(&tbl
->slot_tbl_lock
);
576 dprintk("<-- %s: no free slots\n", __func__
);
579 spin_unlock(&tbl
->slot_tbl_lock
);
581 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
582 slot
= tbl
->slots
+ slotid
;
583 args
->sa_session
= session
;
584 args
->sa_slotid
= slotid
;
585 args
->sa_cache_this
= cache_reply
;
587 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
589 res
->sr_session
= session
;
591 res
->sr_renewal_time
= jiffies
;
592 res
->sr_status_flags
= 0;
594 * sr_status is only set in decode_sequence, and so will remain
595 * set to 1 if an rpc level failure occurs.
600 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
602 int nfs4_setup_sequence(const struct nfs_server
*server
,
603 struct nfs4_sequence_args
*args
,
604 struct nfs4_sequence_res
*res
,
606 struct rpc_task
*task
)
608 struct nfs4_session
*session
= nfs4_get_session(server
);
611 if (session
== NULL
) {
612 args
->sa_session
= NULL
;
613 res
->sr_session
= NULL
;
617 dprintk("--> %s clp %p session %p sr_slot %td\n",
618 __func__
, session
->clp
, session
, res
->sr_slot
?
619 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
621 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
624 dprintk("<-- %s status=%d\n", __func__
, ret
);
628 struct nfs41_call_sync_data
{
629 const struct nfs_server
*seq_server
;
630 struct nfs4_sequence_args
*seq_args
;
631 struct nfs4_sequence_res
*seq_res
;
635 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
637 struct nfs41_call_sync_data
*data
= calldata
;
639 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
641 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
642 data
->seq_res
, data
->cache_reply
, task
))
644 rpc_call_start(task
);
647 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
649 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
650 nfs41_call_sync_prepare(task
, calldata
);
653 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
655 struct nfs41_call_sync_data
*data
= calldata
;
657 nfs41_sequence_done(task
, data
->seq_res
);
660 struct rpc_call_ops nfs41_call_sync_ops
= {
661 .rpc_call_prepare
= nfs41_call_sync_prepare
,
662 .rpc_call_done
= nfs41_call_sync_done
,
665 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
666 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
667 .rpc_call_done
= nfs41_call_sync_done
,
670 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
671 struct nfs_server
*server
,
672 struct rpc_message
*msg
,
673 struct nfs4_sequence_args
*args
,
674 struct nfs4_sequence_res
*res
,
679 struct rpc_task
*task
;
680 struct nfs41_call_sync_data data
= {
681 .seq_server
= server
,
684 .cache_reply
= cache_reply
,
686 struct rpc_task_setup task_setup
= {
689 .callback_ops
= &nfs41_call_sync_ops
,
690 .callback_data
= &data
695 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
696 task
= rpc_run_task(&task_setup
);
700 ret
= task
->tk_status
;
706 int _nfs4_call_sync_session(struct rpc_clnt
*clnt
,
707 struct nfs_server
*server
,
708 struct rpc_message
*msg
,
709 struct nfs4_sequence_args
*args
,
710 struct nfs4_sequence_res
*res
,
713 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
, cache_reply
, 0);
717 static int nfs4_sequence_done(struct rpc_task
*task
,
718 struct nfs4_sequence_res
*res
)
722 #endif /* CONFIG_NFS_V4_1 */
724 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
725 struct nfs_server
*server
,
726 struct rpc_message
*msg
,
727 struct nfs4_sequence_args
*args
,
728 struct nfs4_sequence_res
*res
,
731 args
->sa_session
= res
->sr_session
= NULL
;
732 return rpc_call_sync(clnt
, msg
, 0);
736 int nfs4_call_sync(struct rpc_clnt
*clnt
,
737 struct nfs_server
*server
,
738 struct rpc_message
*msg
,
739 struct nfs4_sequence_args
*args
,
740 struct nfs4_sequence_res
*res
,
743 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
744 args
, res
, cache_reply
);
747 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
749 struct nfs_inode
*nfsi
= NFS_I(dir
);
751 spin_lock(&dir
->i_lock
);
752 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
753 if (!cinfo
->atomic
|| cinfo
->before
!= dir
->i_version
)
754 nfs_force_lookup_revalidate(dir
);
755 dir
->i_version
= cinfo
->after
;
756 spin_unlock(&dir
->i_lock
);
759 struct nfs4_opendata
{
761 struct nfs_openargs o_arg
;
762 struct nfs_openres o_res
;
763 struct nfs_open_confirmargs c_arg
;
764 struct nfs_open_confirmres c_res
;
765 struct nfs4_string owner_name
;
766 struct nfs4_string group_name
;
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
);
790 nfs_fattr_init_names(&p
->f_attr
, &p
->owner_name
, &p
->group_name
);
793 static struct nfs4_opendata
*nfs4_opendata_alloc(struct dentry
*dentry
,
794 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
795 const struct iattr
*attrs
,
798 struct dentry
*parent
= dget_parent(dentry
);
799 struct inode
*dir
= parent
->d_inode
;
800 struct nfs_server
*server
= NFS_SERVER(dir
);
801 struct nfs4_opendata
*p
;
803 p
= kzalloc(sizeof(*p
), gfp_mask
);
806 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
807 if (p
->o_arg
.seqid
== NULL
)
809 nfs_sb_active(dentry
->d_sb
);
810 p
->dentry
= dget(dentry
);
813 atomic_inc(&sp
->so_count
);
814 p
->o_arg
.fh
= NFS_FH(dir
);
815 p
->o_arg
.open_flags
= flags
;
816 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
817 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
818 p
->o_arg
.id
= sp
->so_owner_id
.id
;
819 p
->o_arg
.name
= &dentry
->d_name
;
820 p
->o_arg
.server
= server
;
821 p
->o_arg
.bitmask
= server
->attr_bitmask
;
822 p
->o_arg
.dir_bitmask
= server
->cache_consistency_bitmask
;
823 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
824 if (flags
& O_CREAT
) {
827 p
->o_arg
.u
.attrs
= &p
->attrs
;
828 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
829 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
833 p
->c_arg
.fh
= &p
->o_res
.fh
;
834 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
835 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
836 nfs4_init_opendata_res(p
);
846 static void nfs4_opendata_free(struct kref
*kref
)
848 struct nfs4_opendata
*p
= container_of(kref
,
849 struct nfs4_opendata
, kref
);
850 struct super_block
*sb
= p
->dentry
->d_sb
;
852 nfs_free_seqid(p
->o_arg
.seqid
);
853 if (p
->state
!= NULL
)
854 nfs4_put_open_state(p
->state
);
855 nfs4_put_state_owner(p
->owner
);
859 nfs_fattr_free_names(&p
->f_attr
);
863 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
866 kref_put(&p
->kref
, nfs4_opendata_free
);
869 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
873 ret
= rpc_wait_for_completion_task(task
);
877 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
881 if (open_mode
& O_EXCL
)
883 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
885 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
886 && state
->n_rdonly
!= 0;
889 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
890 && state
->n_wronly
!= 0;
892 case FMODE_READ
|FMODE_WRITE
:
893 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
894 && state
->n_rdwr
!= 0;
900 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
902 if (delegation
== NULL
)
904 if ((delegation
->type
& fmode
) != fmode
)
906 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
908 nfs_mark_delegation_referenced(delegation
);
912 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
921 case FMODE_READ
|FMODE_WRITE
:
924 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
927 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
929 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
930 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
931 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
934 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
937 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
939 case FMODE_READ
|FMODE_WRITE
:
940 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
944 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
946 write_seqlock(&state
->seqlock
);
947 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
948 write_sequnlock(&state
->seqlock
);
951 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
954 * Protect the call to nfs4_state_set_mode_locked and
955 * serialise the stateid update
957 write_seqlock(&state
->seqlock
);
958 if (deleg_stateid
!= NULL
) {
959 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
960 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
962 if (open_stateid
!= NULL
)
963 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
964 write_sequnlock(&state
->seqlock
);
965 spin_lock(&state
->owner
->so_lock
);
966 update_open_stateflags(state
, fmode
);
967 spin_unlock(&state
->owner
->so_lock
);
970 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
972 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
973 struct nfs_delegation
*deleg_cur
;
976 fmode
&= (FMODE_READ
|FMODE_WRITE
);
979 deleg_cur
= rcu_dereference(nfsi
->delegation
);
980 if (deleg_cur
== NULL
)
983 spin_lock(&deleg_cur
->lock
);
984 if (nfsi
->delegation
!= deleg_cur
||
985 (deleg_cur
->type
& fmode
) != fmode
)
986 goto no_delegation_unlock
;
988 if (delegation
== NULL
)
989 delegation
= &deleg_cur
->stateid
;
990 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
991 goto no_delegation_unlock
;
993 nfs_mark_delegation_referenced(deleg_cur
);
994 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
996 no_delegation_unlock
:
997 spin_unlock(&deleg_cur
->lock
);
1001 if (!ret
&& open_stateid
!= NULL
) {
1002 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
1010 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
1012 struct nfs_delegation
*delegation
;
1015 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1016 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1021 nfs_inode_return_delegation(inode
);
1024 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1026 struct nfs4_state
*state
= opendata
->state
;
1027 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1028 struct nfs_delegation
*delegation
;
1029 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
1030 fmode_t fmode
= opendata
->o_arg
.fmode
;
1031 nfs4_stateid stateid
;
1035 if (can_open_cached(state
, fmode
, open_mode
)) {
1036 spin_lock(&state
->owner
->so_lock
);
1037 if (can_open_cached(state
, fmode
, open_mode
)) {
1038 update_open_stateflags(state
, fmode
);
1039 spin_unlock(&state
->owner
->so_lock
);
1040 goto out_return_state
;
1042 spin_unlock(&state
->owner
->so_lock
);
1045 delegation
= rcu_dereference(nfsi
->delegation
);
1046 if (!can_open_delegated(delegation
, fmode
)) {
1050 /* Save the delegation */
1051 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1053 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1058 /* Try to update the stateid using the delegation */
1059 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1060 goto out_return_state
;
1063 return ERR_PTR(ret
);
1065 atomic_inc(&state
->count
);
1069 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1071 struct inode
*inode
;
1072 struct nfs4_state
*state
= NULL
;
1073 struct nfs_delegation
*delegation
;
1076 if (!data
->rpc_done
) {
1077 state
= nfs4_try_open_cached(data
);
1082 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1084 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1085 ret
= PTR_ERR(inode
);
1089 state
= nfs4_get_open_state(inode
, data
->owner
);
1092 if (data
->o_res
.delegation_type
!= 0) {
1093 int delegation_flags
= 0;
1096 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1098 delegation_flags
= delegation
->flags
;
1100 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_DELEGATE_CUR
) {
1101 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1102 "returning a delegation for "
1103 "OPEN(CLAIM_DELEGATE_CUR)\n",
1104 NFS_CLIENT(inode
)->cl_server
);
1105 } else if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1106 nfs_inode_set_delegation(state
->inode
,
1107 data
->owner
->so_cred
,
1110 nfs_inode_reclaim_delegation(state
->inode
,
1111 data
->owner
->so_cred
,
1115 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1123 return ERR_PTR(ret
);
1126 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1128 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1129 struct nfs_open_context
*ctx
;
1131 spin_lock(&state
->inode
->i_lock
);
1132 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1133 if (ctx
->state
!= state
)
1135 get_nfs_open_context(ctx
);
1136 spin_unlock(&state
->inode
->i_lock
);
1139 spin_unlock(&state
->inode
->i_lock
);
1140 return ERR_PTR(-ENOENT
);
1143 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1145 struct nfs4_opendata
*opendata
;
1147 opendata
= nfs4_opendata_alloc(ctx
->dentry
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1148 if (opendata
== NULL
)
1149 return ERR_PTR(-ENOMEM
);
1150 opendata
->state
= state
;
1151 atomic_inc(&state
->count
);
1155 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1157 struct nfs4_state
*newstate
;
1160 opendata
->o_arg
.open_flags
= 0;
1161 opendata
->o_arg
.fmode
= fmode
;
1162 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1163 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1164 nfs4_init_opendata_res(opendata
);
1165 ret
= _nfs4_recover_proc_open(opendata
);
1168 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1169 if (IS_ERR(newstate
))
1170 return PTR_ERR(newstate
);
1171 nfs4_close_state(newstate
, fmode
);
1176 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1178 struct nfs4_state
*newstate
;
1181 /* memory barrier prior to reading state->n_* */
1182 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1184 if (state
->n_rdwr
!= 0) {
1185 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1186 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1189 if (newstate
!= state
)
1192 if (state
->n_wronly
!= 0) {
1193 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1194 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1197 if (newstate
!= state
)
1200 if (state
->n_rdonly
!= 0) {
1201 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1202 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1205 if (newstate
!= state
)
1209 * We may have performed cached opens for all three recoveries.
1210 * Check if we need to update the current stateid.
1212 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1213 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1214 write_seqlock(&state
->seqlock
);
1215 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1216 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1217 write_sequnlock(&state
->seqlock
);
1224 * reclaim state on the server after a reboot.
1226 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1228 struct nfs_delegation
*delegation
;
1229 struct nfs4_opendata
*opendata
;
1230 fmode_t delegation_type
= 0;
1233 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1234 if (IS_ERR(opendata
))
1235 return PTR_ERR(opendata
);
1236 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1237 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1239 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1240 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1241 delegation_type
= delegation
->type
;
1243 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1244 status
= nfs4_open_recover(opendata
, state
);
1245 nfs4_opendata_put(opendata
);
1249 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1251 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1252 struct nfs4_exception exception
= { };
1255 err
= _nfs4_do_open_reclaim(ctx
, state
);
1256 if (err
!= -NFS4ERR_DELAY
)
1258 nfs4_handle_exception(server
, err
, &exception
);
1259 } while (exception
.retry
);
1263 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1265 struct nfs_open_context
*ctx
;
1268 ctx
= nfs4_state_find_open_context(state
);
1270 return PTR_ERR(ctx
);
1271 ret
= nfs4_do_open_reclaim(ctx
, state
);
1272 put_nfs_open_context(ctx
);
1276 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1278 struct nfs4_opendata
*opendata
;
1281 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1282 if (IS_ERR(opendata
))
1283 return PTR_ERR(opendata
);
1284 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1285 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1286 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1287 ret
= nfs4_open_recover(opendata
, state
);
1288 nfs4_opendata_put(opendata
);
1292 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1294 struct nfs4_exception exception
= { };
1295 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1298 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1304 case -NFS4ERR_BADSESSION
:
1305 case -NFS4ERR_BADSLOT
:
1306 case -NFS4ERR_BAD_HIGH_SLOT
:
1307 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1308 case -NFS4ERR_DEADSESSION
:
1309 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1311 case -NFS4ERR_STALE_CLIENTID
:
1312 case -NFS4ERR_STALE_STATEID
:
1313 case -NFS4ERR_EXPIRED
:
1314 /* Don't recall a delegation if it was lost */
1315 nfs4_schedule_lease_recovery(server
->nfs_client
);
1319 * The show must go on: exit, but mark the
1320 * stateid as needing recovery.
1322 case -NFS4ERR_ADMIN_REVOKED
:
1323 case -NFS4ERR_BAD_STATEID
:
1324 nfs4_schedule_stateid_recovery(server
, state
);
1327 * User RPCSEC_GSS context has expired.
1328 * We cannot recover this stateid now, so
1329 * skip it and allow recovery thread to
1336 err
= nfs4_handle_exception(server
, err
, &exception
);
1337 } while (exception
.retry
);
1342 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1344 struct nfs4_opendata
*data
= calldata
;
1346 data
->rpc_status
= task
->tk_status
;
1347 if (data
->rpc_status
== 0) {
1348 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1349 sizeof(data
->o_res
.stateid
.data
));
1350 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1351 renew_lease(data
->o_res
.server
, data
->timestamp
);
1356 static void nfs4_open_confirm_release(void *calldata
)
1358 struct nfs4_opendata
*data
= calldata
;
1359 struct nfs4_state
*state
= NULL
;
1361 /* If this request hasn't been cancelled, do nothing */
1362 if (data
->cancelled
== 0)
1364 /* In case of error, no cleanup! */
1365 if (!data
->rpc_done
)
1367 state
= nfs4_opendata_to_nfs4_state(data
);
1369 nfs4_close_state(state
, data
->o_arg
.fmode
);
1371 nfs4_opendata_put(data
);
1374 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1375 .rpc_call_done
= nfs4_open_confirm_done
,
1376 .rpc_release
= nfs4_open_confirm_release
,
1380 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1382 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1384 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1385 struct rpc_task
*task
;
1386 struct rpc_message msg
= {
1387 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1388 .rpc_argp
= &data
->c_arg
,
1389 .rpc_resp
= &data
->c_res
,
1390 .rpc_cred
= data
->owner
->so_cred
,
1392 struct rpc_task_setup task_setup_data
= {
1393 .rpc_client
= server
->client
,
1394 .rpc_message
= &msg
,
1395 .callback_ops
= &nfs4_open_confirm_ops
,
1396 .callback_data
= data
,
1397 .workqueue
= nfsiod_workqueue
,
1398 .flags
= RPC_TASK_ASYNC
,
1402 kref_get(&data
->kref
);
1404 data
->rpc_status
= 0;
1405 data
->timestamp
= jiffies
;
1406 task
= rpc_run_task(&task_setup_data
);
1408 return PTR_ERR(task
);
1409 status
= nfs4_wait_for_completion_rpc_task(task
);
1411 data
->cancelled
= 1;
1414 status
= data
->rpc_status
;
1419 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1421 struct nfs4_opendata
*data
= calldata
;
1422 struct nfs4_state_owner
*sp
= data
->owner
;
1424 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1427 * Check if we still need to send an OPEN call, or if we can use
1428 * a delegation instead.
1430 if (data
->state
!= NULL
) {
1431 struct nfs_delegation
*delegation
;
1433 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1436 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1437 if (data
->o_arg
.claim
!= NFS4_OPEN_CLAIM_DELEGATE_CUR
&&
1438 can_open_delegated(delegation
, data
->o_arg
.fmode
))
1439 goto unlock_no_action
;
1442 /* Update sequence id. */
1443 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1444 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1445 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1446 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1447 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1449 data
->timestamp
= jiffies
;
1450 if (nfs4_setup_sequence(data
->o_arg
.server
,
1451 &data
->o_arg
.seq_args
,
1452 &data
->o_res
.seq_res
, 1, task
))
1454 rpc_call_start(task
);
1459 task
->tk_action
= NULL
;
1463 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1465 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1466 nfs4_open_prepare(task
, calldata
);
1469 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1471 struct nfs4_opendata
*data
= calldata
;
1473 data
->rpc_status
= task
->tk_status
;
1475 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1478 if (task
->tk_status
== 0) {
1479 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1483 data
->rpc_status
= -ELOOP
;
1486 data
->rpc_status
= -EISDIR
;
1489 data
->rpc_status
= -ENOTDIR
;
1491 renew_lease(data
->o_res
.server
, data
->timestamp
);
1492 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1493 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1498 static void nfs4_open_release(void *calldata
)
1500 struct nfs4_opendata
*data
= calldata
;
1501 struct nfs4_state
*state
= NULL
;
1503 /* If this request hasn't been cancelled, do nothing */
1504 if (data
->cancelled
== 0)
1506 /* In case of error, no cleanup! */
1507 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1509 /* In case we need an open_confirm, no cleanup! */
1510 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1512 state
= nfs4_opendata_to_nfs4_state(data
);
1514 nfs4_close_state(state
, data
->o_arg
.fmode
);
1516 nfs4_opendata_put(data
);
1519 static const struct rpc_call_ops nfs4_open_ops
= {
1520 .rpc_call_prepare
= nfs4_open_prepare
,
1521 .rpc_call_done
= nfs4_open_done
,
1522 .rpc_release
= nfs4_open_release
,
1525 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1526 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1527 .rpc_call_done
= nfs4_open_done
,
1528 .rpc_release
= nfs4_open_release
,
1531 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1533 struct inode
*dir
= data
->dir
->d_inode
;
1534 struct nfs_server
*server
= NFS_SERVER(dir
);
1535 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1536 struct nfs_openres
*o_res
= &data
->o_res
;
1537 struct rpc_task
*task
;
1538 struct rpc_message msg
= {
1539 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1542 .rpc_cred
= data
->owner
->so_cred
,
1544 struct rpc_task_setup task_setup_data
= {
1545 .rpc_client
= server
->client
,
1546 .rpc_message
= &msg
,
1547 .callback_ops
= &nfs4_open_ops
,
1548 .callback_data
= data
,
1549 .workqueue
= nfsiod_workqueue
,
1550 .flags
= RPC_TASK_ASYNC
,
1554 kref_get(&data
->kref
);
1556 data
->rpc_status
= 0;
1557 data
->cancelled
= 0;
1559 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1560 task
= rpc_run_task(&task_setup_data
);
1562 return PTR_ERR(task
);
1563 status
= nfs4_wait_for_completion_rpc_task(task
);
1565 data
->cancelled
= 1;
1568 status
= data
->rpc_status
;
1574 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1576 struct inode
*dir
= data
->dir
->d_inode
;
1577 struct nfs_openres
*o_res
= &data
->o_res
;
1580 status
= nfs4_run_open_task(data
, 1);
1581 if (status
!= 0 || !data
->rpc_done
)
1584 nfs_fattr_map_and_free_names(NFS_SERVER(dir
), &data
->f_attr
);
1586 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1588 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1589 status
= _nfs4_proc_open_confirm(data
);
1598 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1600 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1602 struct inode
*dir
= data
->dir
->d_inode
;
1603 struct nfs_server
*server
= NFS_SERVER(dir
);
1604 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1605 struct nfs_openres
*o_res
= &data
->o_res
;
1608 status
= nfs4_run_open_task(data
, 0);
1609 if (!data
->rpc_done
)
1612 if (status
== -NFS4ERR_BADNAME
&&
1613 !(o_arg
->open_flags
& O_CREAT
))
1618 nfs_fattr_map_and_free_names(server
, &data
->f_attr
);
1620 if (o_arg
->open_flags
& O_CREAT
) {
1621 update_changeattr(dir
, &o_res
->cinfo
);
1622 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1624 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1625 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1626 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1627 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1628 status
= _nfs4_proc_open_confirm(data
);
1632 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1633 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1637 static int nfs4_client_recover_expired_lease(struct nfs_client
*clp
)
1642 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1643 ret
= nfs4_wait_clnt_recover(clp
);
1646 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1647 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1649 nfs4_schedule_state_manager(clp
);
1655 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1657 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1662 * reclaim state on the server after a network partition.
1663 * Assumes caller holds the appropriate lock
1665 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1667 struct nfs4_opendata
*opendata
;
1670 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1671 if (IS_ERR(opendata
))
1672 return PTR_ERR(opendata
);
1673 ret
= nfs4_open_recover(opendata
, state
);
1675 d_drop(ctx
->dentry
);
1676 nfs4_opendata_put(opendata
);
1680 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1682 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1683 struct nfs4_exception exception
= { };
1687 err
= _nfs4_open_expired(ctx
, state
);
1691 case -NFS4ERR_GRACE
:
1692 case -NFS4ERR_DELAY
:
1693 nfs4_handle_exception(server
, err
, &exception
);
1696 } while (exception
.retry
);
1701 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1703 struct nfs_open_context
*ctx
;
1706 ctx
= nfs4_state_find_open_context(state
);
1708 return PTR_ERR(ctx
);
1709 ret
= nfs4_do_open_expired(ctx
, state
);
1710 put_nfs_open_context(ctx
);
1714 #if defined(CONFIG_NFS_V4_1)
1715 static int nfs41_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1718 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1720 status
= nfs41_test_stateid(server
, state
);
1721 if (status
== NFS_OK
)
1723 nfs41_free_stateid(server
, state
);
1724 return nfs4_open_expired(sp
, state
);
1729 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1730 * fields corresponding to attributes that were used to store the verifier.
1731 * Make sure we clobber those fields in the later setattr call
1733 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1735 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1736 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1737 sattr
->ia_valid
|= ATTR_ATIME
;
1739 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1740 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1741 sattr
->ia_valid
|= ATTR_MTIME
;
1745 * Returns a referenced nfs4_state
1747 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
)
1749 struct nfs4_state_owner
*sp
;
1750 struct nfs4_state
*state
= NULL
;
1751 struct nfs_server
*server
= NFS_SERVER(dir
);
1752 struct nfs4_opendata
*opendata
;
1755 /* Protect against reboot recovery conflicts */
1757 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1758 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1761 status
= nfs4_recover_expired_lease(server
);
1763 goto err_put_state_owner
;
1764 if (dentry
->d_inode
!= NULL
)
1765 nfs4_return_incompatible_delegation(dentry
->d_inode
, fmode
);
1767 opendata
= nfs4_opendata_alloc(dentry
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1768 if (opendata
== NULL
)
1769 goto err_put_state_owner
;
1771 if (dentry
->d_inode
!= NULL
)
1772 opendata
->state
= nfs4_get_open_state(dentry
->d_inode
, sp
);
1774 status
= _nfs4_proc_open(opendata
);
1776 goto err_opendata_put
;
1778 state
= nfs4_opendata_to_nfs4_state(opendata
);
1779 status
= PTR_ERR(state
);
1781 goto err_opendata_put
;
1782 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1783 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1785 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1786 nfs4_exclusive_attrset(opendata
, sattr
);
1788 nfs_fattr_init(opendata
->o_res
.f_attr
);
1789 status
= nfs4_do_setattr(state
->inode
, cred
,
1790 opendata
->o_res
.f_attr
, sattr
,
1793 nfs_setattr_update_inode(state
->inode
, sattr
);
1794 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1796 nfs4_opendata_put(opendata
);
1797 nfs4_put_state_owner(sp
);
1801 nfs4_opendata_put(opendata
);
1802 err_put_state_owner
:
1803 nfs4_put_state_owner(sp
);
1810 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
)
1812 struct nfs4_exception exception
= { };
1813 struct nfs4_state
*res
;
1817 status
= _nfs4_do_open(dir
, dentry
, fmode
, flags
, sattr
, cred
, &res
);
1820 /* NOTE: BAD_SEQID means the server and client disagree about the
1821 * book-keeping w.r.t. state-changing operations
1822 * (OPEN/CLOSE/LOCK/LOCKU...)
1823 * It is actually a sign of a bug on the client or on the server.
1825 * If we receive a BAD_SEQID error in the particular case of
1826 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1827 * have unhashed the old state_owner for us, and that we can
1828 * therefore safely retry using a new one. We should still warn
1829 * the user though...
1831 if (status
== -NFS4ERR_BAD_SEQID
) {
1832 printk(KERN_WARNING
"NFS: v4 server %s "
1833 " returned a bad sequence-id error!\n",
1834 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1835 exception
.retry
= 1;
1839 * BAD_STATEID on OPEN means that the server cancelled our
1840 * state before it received the OPEN_CONFIRM.
1841 * Recover by retrying the request as per the discussion
1842 * on Page 181 of RFC3530.
1844 if (status
== -NFS4ERR_BAD_STATEID
) {
1845 exception
.retry
= 1;
1848 if (status
== -EAGAIN
) {
1849 /* We must have found a delegation */
1850 exception
.retry
= 1;
1853 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1854 status
, &exception
));
1855 } while (exception
.retry
);
1859 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1860 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1861 struct nfs4_state
*state
)
1863 struct nfs_server
*server
= NFS_SERVER(inode
);
1864 struct nfs_setattrargs arg
= {
1865 .fh
= NFS_FH(inode
),
1868 .bitmask
= server
->attr_bitmask
,
1870 struct nfs_setattrres res
= {
1874 struct rpc_message msg
= {
1875 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1880 unsigned long timestamp
= jiffies
;
1883 nfs_fattr_init(fattr
);
1885 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1886 /* Use that stateid */
1887 } else if (state
!= NULL
) {
1888 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1890 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1892 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
1893 if (status
== 0 && state
!= NULL
)
1894 renew_lease(server
, timestamp
);
1898 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1899 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1900 struct nfs4_state
*state
)
1902 struct nfs_server
*server
= NFS_SERVER(inode
);
1903 struct nfs4_exception exception
= { };
1906 err
= nfs4_handle_exception(server
,
1907 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1909 } while (exception
.retry
);
1913 struct nfs4_closedata
{
1914 struct inode
*inode
;
1915 struct nfs4_state
*state
;
1916 struct nfs_closeargs arg
;
1917 struct nfs_closeres res
;
1918 struct nfs_fattr fattr
;
1919 unsigned long timestamp
;
1924 static void nfs4_free_closedata(void *data
)
1926 struct nfs4_closedata
*calldata
= data
;
1927 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1928 struct super_block
*sb
= calldata
->state
->inode
->i_sb
;
1931 pnfs_roc_release(calldata
->state
->inode
);
1932 nfs4_put_open_state(calldata
->state
);
1933 nfs_free_seqid(calldata
->arg
.seqid
);
1934 nfs4_put_state_owner(sp
);
1935 nfs_sb_deactive(sb
);
1939 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1942 spin_lock(&state
->owner
->so_lock
);
1943 if (!(fmode
& FMODE_READ
))
1944 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1945 if (!(fmode
& FMODE_WRITE
))
1946 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1947 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1948 spin_unlock(&state
->owner
->so_lock
);
1951 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1953 struct nfs4_closedata
*calldata
= data
;
1954 struct nfs4_state
*state
= calldata
->state
;
1955 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1957 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1959 /* hmm. we are done with the inode, and in the process of freeing
1960 * the state_owner. we keep this around to process errors
1962 switch (task
->tk_status
) {
1965 pnfs_roc_set_barrier(state
->inode
,
1966 calldata
->roc_barrier
);
1967 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1968 renew_lease(server
, calldata
->timestamp
);
1969 nfs4_close_clear_stateid_flags(state
,
1970 calldata
->arg
.fmode
);
1972 case -NFS4ERR_STALE_STATEID
:
1973 case -NFS4ERR_OLD_STATEID
:
1974 case -NFS4ERR_BAD_STATEID
:
1975 case -NFS4ERR_EXPIRED
:
1976 if (calldata
->arg
.fmode
== 0)
1979 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1980 rpc_restart_call_prepare(task
);
1982 nfs_release_seqid(calldata
->arg
.seqid
);
1983 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1986 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1988 struct nfs4_closedata
*calldata
= data
;
1989 struct nfs4_state
*state
= calldata
->state
;
1992 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1995 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1996 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1997 spin_lock(&state
->owner
->so_lock
);
1998 /* Calculate the change in open mode */
1999 if (state
->n_rdwr
== 0) {
2000 if (state
->n_rdonly
== 0) {
2001 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
2002 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2003 calldata
->arg
.fmode
&= ~FMODE_READ
;
2005 if (state
->n_wronly
== 0) {
2006 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
2007 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
2008 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
2011 spin_unlock(&state
->owner
->so_lock
);
2014 /* Note: exit _without_ calling nfs4_close_done */
2015 task
->tk_action
= NULL
;
2019 if (calldata
->arg
.fmode
== 0) {
2020 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
2021 if (calldata
->roc
&&
2022 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
2023 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
2029 nfs_fattr_init(calldata
->res
.fattr
);
2030 calldata
->timestamp
= jiffies
;
2031 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
2032 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
2035 rpc_call_start(task
);
2038 static const struct rpc_call_ops nfs4_close_ops
= {
2039 .rpc_call_prepare
= nfs4_close_prepare
,
2040 .rpc_call_done
= nfs4_close_done
,
2041 .rpc_release
= nfs4_free_closedata
,
2045 * It is possible for data to be read/written from a mem-mapped file
2046 * after the sys_close call (which hits the vfs layer as a flush).
2047 * This means that we can't safely call nfsv4 close on a file until
2048 * the inode is cleared. This in turn means that we are not good
2049 * NFSv4 citizens - we do not indicate to the server to update the file's
2050 * share state even when we are done with one of the three share
2051 * stateid's in the inode.
2053 * NOTE: Caller must be holding the sp->so_owner semaphore!
2055 int nfs4_do_close(struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
2057 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2058 struct nfs4_closedata
*calldata
;
2059 struct nfs4_state_owner
*sp
= state
->owner
;
2060 struct rpc_task
*task
;
2061 struct rpc_message msg
= {
2062 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2063 .rpc_cred
= state
->owner
->so_cred
,
2065 struct rpc_task_setup task_setup_data
= {
2066 .rpc_client
= server
->client
,
2067 .rpc_message
= &msg
,
2068 .callback_ops
= &nfs4_close_ops
,
2069 .workqueue
= nfsiod_workqueue
,
2070 .flags
= RPC_TASK_ASYNC
,
2072 int status
= -ENOMEM
;
2074 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2075 if (calldata
== NULL
)
2077 calldata
->inode
= state
->inode
;
2078 calldata
->state
= state
;
2079 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2080 calldata
->arg
.stateid
= &state
->open_stateid
;
2081 /* Serialization for the sequence id */
2082 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2083 if (calldata
->arg
.seqid
== NULL
)
2084 goto out_free_calldata
;
2085 calldata
->arg
.fmode
= 0;
2086 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2087 calldata
->res
.fattr
= &calldata
->fattr
;
2088 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2089 calldata
->res
.server
= server
;
2090 calldata
->roc
= roc
;
2091 nfs_sb_active(calldata
->inode
->i_sb
);
2093 msg
.rpc_argp
= &calldata
->arg
;
2094 msg
.rpc_resp
= &calldata
->res
;
2095 task_setup_data
.callback_data
= calldata
;
2096 task
= rpc_run_task(&task_setup_data
);
2098 return PTR_ERR(task
);
2101 status
= rpc_wait_for_completion_task(task
);
2108 pnfs_roc_release(state
->inode
);
2109 nfs4_put_open_state(state
);
2110 nfs4_put_state_owner(sp
);
2114 static struct inode
*
2115 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2117 struct nfs4_state
*state
;
2119 /* Protect against concurrent sillydeletes */
2120 state
= nfs4_do_open(dir
, ctx
->dentry
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2122 return ERR_CAST(state
);
2124 return igrab(state
->inode
);
2127 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2129 if (ctx
->state
== NULL
)
2132 nfs4_close_sync(ctx
->state
, ctx
->mode
);
2134 nfs4_close_state(ctx
->state
, ctx
->mode
);
2137 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2139 struct nfs4_server_caps_arg args
= {
2142 struct nfs4_server_caps_res res
= {};
2143 struct rpc_message msg
= {
2144 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2150 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2152 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2153 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2154 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2155 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2156 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2157 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2158 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2159 server
->caps
|= NFS_CAP_ACLS
;
2160 if (res
.has_links
!= 0)
2161 server
->caps
|= NFS_CAP_HARDLINKS
;
2162 if (res
.has_symlinks
!= 0)
2163 server
->caps
|= NFS_CAP_SYMLINKS
;
2164 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2165 server
->caps
|= NFS_CAP_FILEID
;
2166 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2167 server
->caps
|= NFS_CAP_MODE
;
2168 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2169 server
->caps
|= NFS_CAP_NLINK
;
2170 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2171 server
->caps
|= NFS_CAP_OWNER
;
2172 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2173 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2174 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2175 server
->caps
|= NFS_CAP_ATIME
;
2176 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2177 server
->caps
|= NFS_CAP_CTIME
;
2178 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2179 server
->caps
|= NFS_CAP_MTIME
;
2181 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2182 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2183 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2184 server
->acl_bitmask
= res
.acl_bitmask
;
2190 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2192 struct nfs4_exception exception
= { };
2195 err
= nfs4_handle_exception(server
,
2196 _nfs4_server_capabilities(server
, fhandle
),
2198 } while (exception
.retry
);
2202 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2203 struct nfs_fsinfo
*info
)
2205 struct nfs4_lookup_root_arg args
= {
2206 .bitmask
= nfs4_fattr_bitmap
,
2208 struct nfs4_lookup_res res
= {
2210 .fattr
= info
->fattr
,
2213 struct rpc_message msg
= {
2214 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2219 nfs_fattr_init(info
->fattr
);
2220 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2223 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2224 struct nfs_fsinfo
*info
)
2226 struct nfs4_exception exception
= { };
2229 err
= _nfs4_lookup_root(server
, fhandle
, info
);
2232 case -NFS4ERR_WRONGSEC
:
2235 err
= nfs4_handle_exception(server
, err
, &exception
);
2237 } while (exception
.retry
);
2241 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2242 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2244 struct rpc_auth
*auth
;
2247 auth
= rpcauth_create(flavor
, server
->client
);
2252 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2257 static int nfs4_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2258 struct nfs_fsinfo
*info
)
2260 int i
, len
, status
= 0;
2261 rpc_authflavor_t flav_array
[NFS_MAX_SECFLAVORS
];
2263 len
= gss_mech_list_pseudoflavors(&flav_array
[0]);
2264 flav_array
[len
] = RPC_AUTH_NULL
;
2267 for (i
= 0; i
< len
; i
++) {
2268 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2269 if (status
== -NFS4ERR_WRONGSEC
|| status
== -EACCES
)
2274 * -EACCESS could mean that the user doesn't have correct permissions
2275 * to access the mount. It could also mean that we tried to mount
2276 * with a gss auth flavor, but rpc.gssd isn't running. Either way,
2277 * existing mount programs don't handle -EACCES very well so it should
2278 * be mapped to -EPERM instead.
2280 if (status
== -EACCES
)
2286 * get the file handle for the "/" directory on the server
2288 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2289 struct nfs_fsinfo
*info
)
2291 int minor_version
= server
->nfs_client
->cl_minorversion
;
2292 int status
= nfs4_lookup_root(server
, fhandle
, info
);
2293 if ((status
== -NFS4ERR_WRONGSEC
) && !(server
->flags
& NFS_MOUNT_SECFLAVOUR
))
2295 * A status of -NFS4ERR_WRONGSEC will be mapped to -EPERM
2296 * by nfs4_map_errors() as this function exits.
2298 status
= nfs_v4_minor_ops
[minor_version
]->find_root_sec(server
, fhandle
, info
);
2300 status
= nfs4_server_capabilities(server
, fhandle
);
2302 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2303 return nfs4_map_errors(status
);
2306 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
);
2308 * Get locations and (maybe) other attributes of a referral.
2309 * Note that we'll actually follow the referral later when
2310 * we detect fsid mismatch in inode revalidation
2312 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
,
2313 struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2315 int status
= -ENOMEM
;
2316 struct page
*page
= NULL
;
2317 struct nfs4_fs_locations
*locations
= NULL
;
2319 page
= alloc_page(GFP_KERNEL
);
2322 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2323 if (locations
== NULL
)
2326 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2329 /* Make sure server returned a different fsid for the referral */
2330 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2331 dprintk("%s: server did not return a different fsid for"
2332 " a referral at %s\n", __func__
, name
->name
);
2336 /* Fixup attributes for the nfs_lookup() call to nfs_fhget() */
2337 nfs_fixup_referral_attributes(&locations
->fattr
);
2339 /* replace the lookup nfs_fattr with the locations nfs_fattr */
2340 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2341 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2349 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2351 struct nfs4_getattr_arg args
= {
2353 .bitmask
= server
->attr_bitmask
,
2355 struct nfs4_getattr_res res
= {
2359 struct rpc_message msg
= {
2360 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2365 nfs_fattr_init(fattr
);
2366 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2369 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2371 struct nfs4_exception exception
= { };
2374 err
= nfs4_handle_exception(server
,
2375 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2377 } while (exception
.retry
);
2382 * The file is not closed if it is opened due to the a request to change
2383 * the size of the file. The open call will not be needed once the
2384 * VFS layer lookup-intents are implemented.
2386 * Close is called when the inode is destroyed.
2387 * If we haven't opened the file for O_WRONLY, we
2388 * need to in the size_change case to obtain a stateid.
2391 * Because OPEN is always done by name in nfsv4, it is
2392 * possible that we opened a different file by the same
2393 * name. We can recognize this race condition, but we
2394 * can't do anything about it besides returning an error.
2396 * This will be fixed with VFS changes (lookup-intent).
2399 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2400 struct iattr
*sattr
)
2402 struct inode
*inode
= dentry
->d_inode
;
2403 struct rpc_cred
*cred
= NULL
;
2404 struct nfs4_state
*state
= NULL
;
2407 if (pnfs_ld_layoutret_on_setattr(inode
))
2408 pnfs_return_layout(inode
);
2410 nfs_fattr_init(fattr
);
2412 /* Search for an existing open(O_WRITE) file */
2413 if (sattr
->ia_valid
& ATTR_FILE
) {
2414 struct nfs_open_context
*ctx
;
2416 ctx
= nfs_file_open_context(sattr
->ia_file
);
2423 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2425 nfs_setattr_update_inode(inode
, sattr
);
2429 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
2430 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2431 struct nfs_fattr
*fattr
)
2433 struct nfs_server
*server
= NFS_SERVER(dir
);
2435 struct nfs4_lookup_arg args
= {
2436 .bitmask
= server
->attr_bitmask
,
2437 .dir_fh
= NFS_FH(dir
),
2440 struct nfs4_lookup_res res
= {
2445 struct rpc_message msg
= {
2446 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2451 nfs_fattr_init(fattr
);
2453 dprintk("NFS call lookup %s\n", name
->name
);
2454 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2455 dprintk("NFS reply lookup: %d\n", status
);
2459 void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
, struct nfs_fh
*fh
)
2461 memset(fh
, 0, sizeof(struct nfs_fh
));
2462 fattr
->fsid
.major
= 1;
2463 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
2464 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_FSID
| NFS_ATTR_FATTR_MOUNTPOINT
;
2465 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
2469 static int nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
, struct qstr
*name
,
2470 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2472 struct nfs4_exception exception
= { };
2477 status
= _nfs4_proc_lookup(clnt
, dir
, name
, fhandle
, fattr
);
2479 case -NFS4ERR_BADNAME
:
2481 case -NFS4ERR_MOVED
:
2482 return nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2483 case -NFS4ERR_WRONGSEC
:
2484 nfs_fixup_secinfo_attributes(fattr
, fhandle
);
2486 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2487 status
, &exception
);
2488 } while (exception
.retry
);
2492 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2494 struct nfs_server
*server
= NFS_SERVER(inode
);
2495 struct nfs4_accessargs args
= {
2496 .fh
= NFS_FH(inode
),
2497 .bitmask
= server
->attr_bitmask
,
2499 struct nfs4_accessres res
= {
2502 struct rpc_message msg
= {
2503 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2506 .rpc_cred
= entry
->cred
,
2508 int mode
= entry
->mask
;
2512 * Determine which access bits we want to ask for...
2514 if (mode
& MAY_READ
)
2515 args
.access
|= NFS4_ACCESS_READ
;
2516 if (S_ISDIR(inode
->i_mode
)) {
2517 if (mode
& MAY_WRITE
)
2518 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2519 if (mode
& MAY_EXEC
)
2520 args
.access
|= NFS4_ACCESS_LOOKUP
;
2522 if (mode
& MAY_WRITE
)
2523 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2524 if (mode
& MAY_EXEC
)
2525 args
.access
|= NFS4_ACCESS_EXECUTE
;
2528 res
.fattr
= nfs_alloc_fattr();
2529 if (res
.fattr
== NULL
)
2532 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2535 if (res
.access
& NFS4_ACCESS_READ
)
2536 entry
->mask
|= MAY_READ
;
2537 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2538 entry
->mask
|= MAY_WRITE
;
2539 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2540 entry
->mask
|= MAY_EXEC
;
2541 nfs_refresh_inode(inode
, res
.fattr
);
2543 nfs_free_fattr(res
.fattr
);
2547 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2549 struct nfs4_exception exception
= { };
2552 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2553 _nfs4_proc_access(inode
, entry
),
2555 } while (exception
.retry
);
2560 * TODO: For the time being, we don't try to get any attributes
2561 * along with any of the zero-copy operations READ, READDIR,
2564 * In the case of the first three, we want to put the GETATTR
2565 * after the read-type operation -- this is because it is hard
2566 * to predict the length of a GETATTR response in v4, and thus
2567 * align the READ data correctly. This means that the GETATTR
2568 * may end up partially falling into the page cache, and we should
2569 * shift it into the 'tail' of the xdr_buf before processing.
2570 * To do this efficiently, we need to know the total length
2571 * of data received, which doesn't seem to be available outside
2574 * In the case of WRITE, we also want to put the GETATTR after
2575 * the operation -- in this case because we want to make sure
2576 * we get the post-operation mtime and size. This means that
2577 * we can't use xdr_encode_pages() as written: we need a variant
2578 * of it which would leave room in the 'tail' iovec.
2580 * Both of these changes to the XDR layer would in fact be quite
2581 * minor, but I decided to leave them for a subsequent patch.
2583 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2584 unsigned int pgbase
, unsigned int pglen
)
2586 struct nfs4_readlink args
= {
2587 .fh
= NFS_FH(inode
),
2592 struct nfs4_readlink_res res
;
2593 struct rpc_message msg
= {
2594 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2599 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2602 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2603 unsigned int pgbase
, unsigned int pglen
)
2605 struct nfs4_exception exception
= { };
2608 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2609 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2611 } while (exception
.retry
);
2617 * We will need to arrange for the VFS layer to provide an atomic open.
2618 * Until then, this create/open method is prone to inefficiency and race
2619 * conditions due to the lookup, create, and open VFS calls from sys_open()
2620 * placed on the wire.
2622 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2623 * The file will be opened again in the subsequent VFS open call
2624 * (nfs4_proc_file_open).
2626 * The open for read will just hang around to be used by any process that
2627 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2631 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2632 int flags
, struct nfs_open_context
*ctx
)
2634 struct dentry
*de
= dentry
;
2635 struct nfs4_state
*state
;
2636 struct rpc_cred
*cred
= NULL
;
2645 sattr
->ia_mode
&= ~current_umask();
2646 state
= nfs4_do_open(dir
, de
, fmode
, flags
, sattr
, cred
);
2648 if (IS_ERR(state
)) {
2649 status
= PTR_ERR(state
);
2652 d_add(dentry
, igrab(state
->inode
));
2653 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2657 nfs4_close_sync(state
, fmode
);
2662 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2664 struct nfs_server
*server
= NFS_SERVER(dir
);
2665 struct nfs_removeargs args
= {
2667 .name
.len
= name
->len
,
2668 .name
.name
= name
->name
,
2669 .bitmask
= server
->attr_bitmask
,
2671 struct nfs_removeres res
= {
2674 struct rpc_message msg
= {
2675 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2679 int status
= -ENOMEM
;
2681 res
.dir_attr
= nfs_alloc_fattr();
2682 if (res
.dir_attr
== NULL
)
2685 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
2687 update_changeattr(dir
, &res
.cinfo
);
2688 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2690 nfs_free_fattr(res
.dir_attr
);
2695 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2697 struct nfs4_exception exception
= { };
2700 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2701 _nfs4_proc_remove(dir
, name
),
2703 } while (exception
.retry
);
2707 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2709 struct nfs_server
*server
= NFS_SERVER(dir
);
2710 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2711 struct nfs_removeres
*res
= msg
->rpc_resp
;
2713 args
->bitmask
= server
->cache_consistency_bitmask
;
2714 res
->server
= server
;
2715 res
->seq_res
.sr_slot
= NULL
;
2716 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2719 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2721 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2723 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2725 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2727 update_changeattr(dir
, &res
->cinfo
);
2728 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2732 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2734 struct nfs_server
*server
= NFS_SERVER(dir
);
2735 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2736 struct nfs_renameres
*res
= msg
->rpc_resp
;
2738 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2739 arg
->bitmask
= server
->attr_bitmask
;
2740 res
->server
= server
;
2743 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2744 struct inode
*new_dir
)
2746 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2748 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2750 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2753 update_changeattr(old_dir
, &res
->old_cinfo
);
2754 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2755 update_changeattr(new_dir
, &res
->new_cinfo
);
2756 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2760 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2761 struct inode
*new_dir
, struct qstr
*new_name
)
2763 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2764 struct nfs_renameargs arg
= {
2765 .old_dir
= NFS_FH(old_dir
),
2766 .new_dir
= NFS_FH(new_dir
),
2767 .old_name
= old_name
,
2768 .new_name
= new_name
,
2769 .bitmask
= server
->attr_bitmask
,
2771 struct nfs_renameres res
= {
2774 struct rpc_message msg
= {
2775 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2779 int status
= -ENOMEM
;
2781 res
.old_fattr
= nfs_alloc_fattr();
2782 res
.new_fattr
= nfs_alloc_fattr();
2783 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2786 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2788 update_changeattr(old_dir
, &res
.old_cinfo
);
2789 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2790 update_changeattr(new_dir
, &res
.new_cinfo
);
2791 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2794 nfs_free_fattr(res
.new_fattr
);
2795 nfs_free_fattr(res
.old_fattr
);
2799 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2800 struct inode
*new_dir
, struct qstr
*new_name
)
2802 struct nfs4_exception exception
= { };
2805 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2806 _nfs4_proc_rename(old_dir
, old_name
,
2809 } while (exception
.retry
);
2813 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2815 struct nfs_server
*server
= NFS_SERVER(inode
);
2816 struct nfs4_link_arg arg
= {
2817 .fh
= NFS_FH(inode
),
2818 .dir_fh
= NFS_FH(dir
),
2820 .bitmask
= server
->attr_bitmask
,
2822 struct nfs4_link_res res
= {
2825 struct rpc_message msg
= {
2826 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2830 int status
= -ENOMEM
;
2832 res
.fattr
= nfs_alloc_fattr();
2833 res
.dir_attr
= nfs_alloc_fattr();
2834 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2837 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2839 update_changeattr(dir
, &res
.cinfo
);
2840 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2841 nfs_post_op_update_inode(inode
, res
.fattr
);
2844 nfs_free_fattr(res
.dir_attr
);
2845 nfs_free_fattr(res
.fattr
);
2849 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2851 struct nfs4_exception exception
= { };
2854 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2855 _nfs4_proc_link(inode
, dir
, name
),
2857 } while (exception
.retry
);
2861 struct nfs4_createdata
{
2862 struct rpc_message msg
;
2863 struct nfs4_create_arg arg
;
2864 struct nfs4_create_res res
;
2866 struct nfs_fattr fattr
;
2867 struct nfs_fattr dir_fattr
;
2870 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2871 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2873 struct nfs4_createdata
*data
;
2875 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2877 struct nfs_server
*server
= NFS_SERVER(dir
);
2879 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2880 data
->msg
.rpc_argp
= &data
->arg
;
2881 data
->msg
.rpc_resp
= &data
->res
;
2882 data
->arg
.dir_fh
= NFS_FH(dir
);
2883 data
->arg
.server
= server
;
2884 data
->arg
.name
= name
;
2885 data
->arg
.attrs
= sattr
;
2886 data
->arg
.ftype
= ftype
;
2887 data
->arg
.bitmask
= server
->attr_bitmask
;
2888 data
->res
.server
= server
;
2889 data
->res
.fh
= &data
->fh
;
2890 data
->res
.fattr
= &data
->fattr
;
2891 data
->res
.dir_fattr
= &data
->dir_fattr
;
2892 nfs_fattr_init(data
->res
.fattr
);
2893 nfs_fattr_init(data
->res
.dir_fattr
);
2898 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2900 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
2901 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
2903 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2904 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2905 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2910 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2915 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2916 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2918 struct nfs4_createdata
*data
;
2919 int status
= -ENAMETOOLONG
;
2921 if (len
> NFS4_MAXPATHLEN
)
2925 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2929 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2930 data
->arg
.u
.symlink
.pages
= &page
;
2931 data
->arg
.u
.symlink
.len
= len
;
2933 status
= nfs4_do_create(dir
, dentry
, data
);
2935 nfs4_free_createdata(data
);
2940 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2941 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2943 struct nfs4_exception exception
= { };
2946 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2947 _nfs4_proc_symlink(dir
, dentry
, page
,
2950 } while (exception
.retry
);
2954 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2955 struct iattr
*sattr
)
2957 struct nfs4_createdata
*data
;
2958 int status
= -ENOMEM
;
2960 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2964 status
= nfs4_do_create(dir
, dentry
, data
);
2966 nfs4_free_createdata(data
);
2971 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2972 struct iattr
*sattr
)
2974 struct nfs4_exception exception
= { };
2977 sattr
->ia_mode
&= ~current_umask();
2979 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2980 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2982 } while (exception
.retry
);
2986 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2987 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2989 struct inode
*dir
= dentry
->d_inode
;
2990 struct nfs4_readdir_arg args
= {
2995 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2998 struct nfs4_readdir_res res
;
2999 struct rpc_message msg
= {
3000 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
3007 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
3008 dentry
->d_parent
->d_name
.name
,
3009 dentry
->d_name
.name
,
3010 (unsigned long long)cookie
);
3011 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
3012 res
.pgbase
= args
.pgbase
;
3013 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3015 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
3016 status
+= args
.pgbase
;
3019 nfs_invalidate_atime(dir
);
3021 dprintk("%s: returns %d\n", __func__
, status
);
3025 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
3026 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
3028 struct nfs4_exception exception
= { };
3031 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
3032 _nfs4_proc_readdir(dentry
, cred
, cookie
,
3033 pages
, count
, plus
),
3035 } while (exception
.retry
);
3039 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3040 struct iattr
*sattr
, dev_t rdev
)
3042 struct nfs4_createdata
*data
;
3043 int mode
= sattr
->ia_mode
;
3044 int status
= -ENOMEM
;
3046 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
3047 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
3049 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3054 data
->arg
.ftype
= NF4FIFO
;
3055 else if (S_ISBLK(mode
)) {
3056 data
->arg
.ftype
= NF4BLK
;
3057 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3058 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3060 else if (S_ISCHR(mode
)) {
3061 data
->arg
.ftype
= NF4CHR
;
3062 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3063 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3066 status
= nfs4_do_create(dir
, dentry
, data
);
3068 nfs4_free_createdata(data
);
3073 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3074 struct iattr
*sattr
, dev_t rdev
)
3076 struct nfs4_exception exception
= { };
3079 sattr
->ia_mode
&= ~current_umask();
3081 err
= nfs4_handle_exception(NFS_SERVER(dir
),
3082 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
3084 } while (exception
.retry
);
3088 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3089 struct nfs_fsstat
*fsstat
)
3091 struct nfs4_statfs_arg args
= {
3093 .bitmask
= server
->attr_bitmask
,
3095 struct nfs4_statfs_res res
= {
3098 struct rpc_message msg
= {
3099 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3104 nfs_fattr_init(fsstat
->fattr
);
3105 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3108 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3110 struct nfs4_exception exception
= { };
3113 err
= nfs4_handle_exception(server
,
3114 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3116 } while (exception
.retry
);
3120 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3121 struct nfs_fsinfo
*fsinfo
)
3123 struct nfs4_fsinfo_arg args
= {
3125 .bitmask
= server
->attr_bitmask
,
3127 struct nfs4_fsinfo_res res
= {
3130 struct rpc_message msg
= {
3131 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3136 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3139 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3141 struct nfs4_exception exception
= { };
3145 err
= nfs4_handle_exception(server
,
3146 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3148 } while (exception
.retry
);
3152 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3154 nfs_fattr_init(fsinfo
->fattr
);
3155 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3158 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3159 struct nfs_pathconf
*pathconf
)
3161 struct nfs4_pathconf_arg args
= {
3163 .bitmask
= server
->attr_bitmask
,
3165 struct nfs4_pathconf_res res
= {
3166 .pathconf
= pathconf
,
3168 struct rpc_message msg
= {
3169 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3174 /* None of the pathconf attributes are mandatory to implement */
3175 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3176 memset(pathconf
, 0, sizeof(*pathconf
));
3180 nfs_fattr_init(pathconf
->fattr
);
3181 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3184 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3185 struct nfs_pathconf
*pathconf
)
3187 struct nfs4_exception exception
= { };
3191 err
= nfs4_handle_exception(server
,
3192 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3194 } while (exception
.retry
);
3198 void __nfs4_read_done_cb(struct nfs_read_data
*data
)
3200 nfs_invalidate_atime(data
->inode
);
3203 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3205 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3207 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3208 rpc_restart_call_prepare(task
);
3212 __nfs4_read_done_cb(data
);
3213 if (task
->tk_status
> 0)
3214 renew_lease(server
, data
->timestamp
);
3218 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3221 dprintk("--> %s\n", __func__
);
3223 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3226 return data
->read_done_cb
? data
->read_done_cb(task
, data
) :
3227 nfs4_read_done_cb(task
, data
);
3230 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3232 data
->timestamp
= jiffies
;
3233 data
->read_done_cb
= nfs4_read_done_cb
;
3234 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3237 /* Reset the the nfs_read_data to send the read to the MDS. */
3238 void nfs4_reset_read(struct rpc_task
*task
, struct nfs_read_data
*data
)
3240 dprintk("%s Reset task for i/o through\n", __func__
);
3241 put_lseg(data
->lseg
);
3243 /* offsets will differ in the dense stripe case */
3244 data
->args
.offset
= data
->mds_offset
;
3245 data
->ds_clp
= NULL
;
3246 data
->args
.fh
= NFS_FH(data
->inode
);
3247 data
->read_done_cb
= nfs4_read_done_cb
;
3248 task
->tk_ops
= data
->mds_ops
;
3249 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3251 EXPORT_SYMBOL_GPL(nfs4_reset_read
);
3253 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3255 struct inode
*inode
= data
->inode
;
3257 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3258 rpc_restart_call_prepare(task
);
3261 if (task
->tk_status
>= 0) {
3262 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3263 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3268 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3270 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3272 return data
->write_done_cb
? data
->write_done_cb(task
, data
) :
3273 nfs4_write_done_cb(task
, data
);
3276 /* Reset the the nfs_write_data to send the write to the MDS. */
3277 void nfs4_reset_write(struct rpc_task
*task
, struct nfs_write_data
*data
)
3279 dprintk("%s Reset task for i/o through\n", __func__
);
3280 put_lseg(data
->lseg
);
3282 data
->ds_clp
= NULL
;
3283 data
->write_done_cb
= nfs4_write_done_cb
;
3284 data
->args
.fh
= NFS_FH(data
->inode
);
3285 data
->args
.bitmask
= data
->res
.server
->cache_consistency_bitmask
;
3286 data
->args
.offset
= data
->mds_offset
;
3287 data
->res
.fattr
= &data
->fattr
;
3288 task
->tk_ops
= data
->mds_ops
;
3289 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3291 EXPORT_SYMBOL_GPL(nfs4_reset_write
);
3293 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3295 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3298 data
->args
.bitmask
= NULL
;
3299 data
->res
.fattr
= NULL
;
3301 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3302 if (!data
->write_done_cb
)
3303 data
->write_done_cb
= nfs4_write_done_cb
;
3304 data
->res
.server
= server
;
3305 data
->timestamp
= jiffies
;
3307 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3310 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3312 struct inode
*inode
= data
->inode
;
3314 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3315 rpc_restart_call_prepare(task
);
3318 nfs_refresh_inode(inode
, data
->res
.fattr
);
3322 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3324 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3326 return data
->write_done_cb(task
, data
);
3329 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3331 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3334 data
->args
.bitmask
= NULL
;
3335 data
->res
.fattr
= NULL
;
3337 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3338 if (!data
->write_done_cb
)
3339 data
->write_done_cb
= nfs4_commit_done_cb
;
3340 data
->res
.server
= server
;
3341 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3344 struct nfs4_renewdata
{
3345 struct nfs_client
*client
;
3346 unsigned long timestamp
;
3350 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3351 * standalone procedure for queueing an asynchronous RENEW.
3353 static void nfs4_renew_release(void *calldata
)
3355 struct nfs4_renewdata
*data
= calldata
;
3356 struct nfs_client
*clp
= data
->client
;
3358 if (atomic_read(&clp
->cl_count
) > 1)
3359 nfs4_schedule_state_renewal(clp
);
3360 nfs_put_client(clp
);
3364 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3366 struct nfs4_renewdata
*data
= calldata
;
3367 struct nfs_client
*clp
= data
->client
;
3368 unsigned long timestamp
= data
->timestamp
;
3370 if (task
->tk_status
< 0) {
3371 /* Unless we're shutting down, schedule state recovery! */
3372 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) == 0)
3374 if (task
->tk_status
!= NFS4ERR_CB_PATH_DOWN
) {
3375 nfs4_schedule_lease_recovery(clp
);
3378 nfs4_schedule_path_down_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 static int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
3390 struct rpc_message msg
= {
3391 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3395 struct nfs4_renewdata
*data
;
3397 if (renew_flags
== 0)
3399 if (!atomic_inc_not_zero(&clp
->cl_count
))
3401 data
= kmalloc(sizeof(*data
), GFP_NOFS
);
3405 data
->timestamp
= jiffies
;
3406 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3407 &nfs4_renew_ops
, data
);
3410 static int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3412 struct rpc_message msg
= {
3413 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3417 unsigned long now
= jiffies
;
3420 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3423 do_renew_lease(clp
, now
);
3427 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3429 return (server
->caps
& NFS_CAP_ACLS
)
3430 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3431 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3434 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3435 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3438 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3440 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3441 struct page
**pages
, unsigned int *pgbase
)
3443 struct page
*newpage
, **spages
;
3449 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3450 newpage
= alloc_page(GFP_KERNEL
);
3452 if (newpage
== NULL
)
3454 memcpy(page_address(newpage
), buf
, len
);
3459 } while (buflen
!= 0);
3465 __free_page(spages
[rc
-1]);
3469 struct nfs4_cached_acl
{
3475 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3477 struct nfs_inode
*nfsi
= NFS_I(inode
);
3479 spin_lock(&inode
->i_lock
);
3480 kfree(nfsi
->nfs4_acl
);
3481 nfsi
->nfs4_acl
= acl
;
3482 spin_unlock(&inode
->i_lock
);
3485 static void nfs4_zap_acl_attr(struct inode
*inode
)
3487 nfs4_set_cached_acl(inode
, NULL
);
3490 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3492 struct nfs_inode
*nfsi
= NFS_I(inode
);
3493 struct nfs4_cached_acl
*acl
;
3496 spin_lock(&inode
->i_lock
);
3497 acl
= nfsi
->nfs4_acl
;
3500 if (buf
== NULL
) /* user is just asking for length */
3502 if (acl
->cached
== 0)
3504 ret
= -ERANGE
; /* see getxattr(2) man page */
3505 if (acl
->len
> buflen
)
3507 memcpy(buf
, acl
->data
, acl
->len
);
3511 spin_unlock(&inode
->i_lock
);
3515 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3517 struct nfs4_cached_acl
*acl
;
3519 if (buf
&& acl_len
<= PAGE_SIZE
) {
3520 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3524 memcpy(acl
->data
, buf
, acl_len
);
3526 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3533 nfs4_set_cached_acl(inode
, acl
);
3537 * The getxattr API returns the required buffer length when called with a
3538 * NULL buf. The NFSv4 acl tool then calls getxattr again after allocating
3539 * the required buf. On a NULL buf, we send a page of data to the server
3540 * guessing that the ACL request can be serviced by a page. If so, we cache
3541 * up to the page of ACL data, and the 2nd call to getxattr is serviced by
3542 * the cache. If not so, we throw away the page, and cache the required
3543 * length. The next getxattr call will then produce another round trip to
3544 * the server, this time with the input buf of the required size.
3546 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3548 struct page
*pages
[NFS4ACL_MAXPAGES
] = {NULL
, };
3549 struct nfs_getaclargs args
= {
3550 .fh
= NFS_FH(inode
),
3554 struct nfs_getaclres res
= {
3558 struct rpc_message msg
= {
3559 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3563 int ret
= -ENOMEM
, npages
, i
, acl_len
= 0;
3565 npages
= (buflen
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
3566 /* As long as we're doing a round trip to the server anyway,
3567 * let's be prepared for a page of acl data. */
3571 for (i
= 0; i
< npages
; i
++) {
3572 pages
[i
] = alloc_page(GFP_KERNEL
);
3577 /* for decoding across pages */
3578 res
.acl_scratch
= alloc_page(GFP_KERNEL
);
3579 if (!res
.acl_scratch
)
3582 args
.acl_len
= npages
* PAGE_SIZE
;
3583 args
.acl_pgbase
= 0;
3584 /* Let decode_getfacl know not to fail if the ACL data is larger than
3585 * the page we send as a guess */
3587 res
.acl_flags
|= NFS4_ACL_LEN_REQUEST
;
3588 resp_buf
= page_address(pages
[0]);
3590 dprintk("%s buf %p buflen %zu npages %d args.acl_len %zu\n",
3591 __func__
, buf
, buflen
, npages
, args
.acl_len
);
3592 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
),
3593 &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3597 acl_len
= res
.acl_len
- res
.acl_data_offset
;
3598 if (acl_len
> args
.acl_len
)
3599 nfs4_write_cached_acl(inode
, NULL
, acl_len
);
3601 nfs4_write_cached_acl(inode
, resp_buf
+ res
.acl_data_offset
,
3605 if (acl_len
> buflen
)
3607 _copy_from_pages(buf
, pages
, res
.acl_data_offset
,
3612 for (i
= 0; i
< npages
; i
++)
3614 __free_page(pages
[i
]);
3615 if (res
.acl_scratch
)
3616 __free_page(res
.acl_scratch
);
3620 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3622 struct nfs4_exception exception
= { };
3625 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3628 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3629 } while (exception
.retry
);
3633 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3635 struct nfs_server
*server
= NFS_SERVER(inode
);
3638 if (!nfs4_server_supports_acls(server
))
3640 ret
= nfs_revalidate_inode(server
, inode
);
3643 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3644 nfs_zap_acl_cache(inode
);
3645 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3647 /* -ENOENT is returned if there is no ACL or if there is an ACL
3648 * but no cached acl data, just the acl length */
3650 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3653 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3655 struct nfs_server
*server
= NFS_SERVER(inode
);
3656 struct page
*pages
[NFS4ACL_MAXPAGES
];
3657 struct nfs_setaclargs arg
= {
3658 .fh
= NFS_FH(inode
),
3662 struct nfs_setaclres res
;
3663 struct rpc_message msg
= {
3664 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3670 if (!nfs4_server_supports_acls(server
))
3672 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3675 nfs_inode_return_delegation(inode
);
3676 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3679 * Free each page after tx, so the only ref left is
3680 * held by the network stack
3683 put_page(pages
[i
-1]);
3686 * Acl update can result in inode attribute update.
3687 * so mark the attribute cache invalid.
3689 spin_lock(&inode
->i_lock
);
3690 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3691 spin_unlock(&inode
->i_lock
);
3692 nfs_access_zap_cache(inode
);
3693 nfs_zap_acl_cache(inode
);
3697 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3699 struct nfs4_exception exception
= { };
3702 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3703 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3705 } while (exception
.retry
);
3710 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3712 struct nfs_client
*clp
= server
->nfs_client
;
3714 if (task
->tk_status
>= 0)
3716 switch(task
->tk_status
) {
3717 case -NFS4ERR_ADMIN_REVOKED
:
3718 case -NFS4ERR_BAD_STATEID
:
3719 case -NFS4ERR_OPENMODE
:
3722 nfs4_schedule_stateid_recovery(server
, state
);
3723 goto wait_on_recovery
;
3724 case -NFS4ERR_EXPIRED
:
3726 nfs4_schedule_stateid_recovery(server
, state
);
3727 case -NFS4ERR_STALE_STATEID
:
3728 case -NFS4ERR_STALE_CLIENTID
:
3729 nfs4_schedule_lease_recovery(clp
);
3730 goto wait_on_recovery
;
3731 #if defined(CONFIG_NFS_V4_1)
3732 case -NFS4ERR_BADSESSION
:
3733 case -NFS4ERR_BADSLOT
:
3734 case -NFS4ERR_BAD_HIGH_SLOT
:
3735 case -NFS4ERR_DEADSESSION
:
3736 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3737 case -NFS4ERR_SEQ_FALSE_RETRY
:
3738 case -NFS4ERR_SEQ_MISORDERED
:
3739 dprintk("%s ERROR %d, Reset session\n", __func__
,
3741 nfs4_schedule_session_recovery(clp
->cl_session
);
3742 task
->tk_status
= 0;
3744 #endif /* CONFIG_NFS_V4_1 */
3745 case -NFS4ERR_DELAY
:
3746 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3747 case -NFS4ERR_GRACE
:
3749 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3750 task
->tk_status
= 0;
3752 case -NFS4ERR_RETRY_UNCACHED_REP
:
3753 case -NFS4ERR_OLD_STATEID
:
3754 task
->tk_status
= 0;
3757 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3760 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3761 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3762 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3763 task
->tk_status
= 0;
3767 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3768 unsigned short port
, struct rpc_cred
*cred
,
3769 struct nfs4_setclientid_res
*res
)
3771 nfs4_verifier sc_verifier
;
3772 struct nfs4_setclientid setclientid
= {
3773 .sc_verifier
= &sc_verifier
,
3775 .sc_cb_ident
= clp
->cl_cb_ident
,
3777 struct rpc_message msg
= {
3778 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3779 .rpc_argp
= &setclientid
,
3787 p
= (__be32
*)sc_verifier
.data
;
3788 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3789 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3792 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3793 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3795 rpc_peeraddr2str(clp
->cl_rpcclient
,
3797 rpc_peeraddr2str(clp
->cl_rpcclient
,
3799 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3800 clp
->cl_id_uniquifier
);
3801 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3802 sizeof(setclientid
.sc_netid
),
3803 rpc_peeraddr2str(clp
->cl_rpcclient
,
3804 RPC_DISPLAY_NETID
));
3805 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3806 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3807 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3809 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3810 if (status
!= -NFS4ERR_CLID_INUSE
)
3813 ++clp
->cl_id_uniquifier
;
3817 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3822 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3823 struct nfs4_setclientid_res
*arg
,
3824 struct rpc_cred
*cred
)
3826 struct nfs_fsinfo fsinfo
;
3827 struct rpc_message msg
= {
3828 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3830 .rpc_resp
= &fsinfo
,
3837 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
3839 spin_lock(&clp
->cl_lock
);
3840 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3841 clp
->cl_last_renewal
= now
;
3842 spin_unlock(&clp
->cl_lock
);
3847 struct nfs4_delegreturndata
{
3848 struct nfs4_delegreturnargs args
;
3849 struct nfs4_delegreturnres res
;
3851 nfs4_stateid stateid
;
3852 unsigned long timestamp
;
3853 struct nfs_fattr fattr
;
3857 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3859 struct nfs4_delegreturndata
*data
= calldata
;
3861 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3864 switch (task
->tk_status
) {
3865 case -NFS4ERR_STALE_STATEID
:
3866 case -NFS4ERR_EXPIRED
:
3868 renew_lease(data
->res
.server
, data
->timestamp
);
3871 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3873 rpc_restart_call_prepare(task
);
3877 data
->rpc_status
= task
->tk_status
;
3880 static void nfs4_delegreturn_release(void *calldata
)
3885 #if defined(CONFIG_NFS_V4_1)
3886 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3888 struct nfs4_delegreturndata
*d_data
;
3890 d_data
= (struct nfs4_delegreturndata
*)data
;
3892 if (nfs4_setup_sequence(d_data
->res
.server
,
3893 &d_data
->args
.seq_args
,
3894 &d_data
->res
.seq_res
, 1, task
))
3896 rpc_call_start(task
);
3898 #endif /* CONFIG_NFS_V4_1 */
3900 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3901 #if defined(CONFIG_NFS_V4_1)
3902 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3903 #endif /* CONFIG_NFS_V4_1 */
3904 .rpc_call_done
= nfs4_delegreturn_done
,
3905 .rpc_release
= nfs4_delegreturn_release
,
3908 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3910 struct nfs4_delegreturndata
*data
;
3911 struct nfs_server
*server
= NFS_SERVER(inode
);
3912 struct rpc_task
*task
;
3913 struct rpc_message msg
= {
3914 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3917 struct rpc_task_setup task_setup_data
= {
3918 .rpc_client
= server
->client
,
3919 .rpc_message
= &msg
,
3920 .callback_ops
= &nfs4_delegreturn_ops
,
3921 .flags
= RPC_TASK_ASYNC
,
3925 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3928 data
->args
.fhandle
= &data
->fh
;
3929 data
->args
.stateid
= &data
->stateid
;
3930 data
->args
.bitmask
= server
->attr_bitmask
;
3931 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3932 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3933 data
->res
.fattr
= &data
->fattr
;
3934 data
->res
.server
= server
;
3935 nfs_fattr_init(data
->res
.fattr
);
3936 data
->timestamp
= jiffies
;
3937 data
->rpc_status
= 0;
3939 task_setup_data
.callback_data
= data
;
3940 msg
.rpc_argp
= &data
->args
;
3941 msg
.rpc_resp
= &data
->res
;
3942 task
= rpc_run_task(&task_setup_data
);
3944 return PTR_ERR(task
);
3947 status
= nfs4_wait_for_completion_rpc_task(task
);
3950 status
= data
->rpc_status
;
3953 nfs_refresh_inode(inode
, &data
->fattr
);
3959 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3961 struct nfs_server
*server
= NFS_SERVER(inode
);
3962 struct nfs4_exception exception
= { };
3965 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3967 case -NFS4ERR_STALE_STATEID
:
3968 case -NFS4ERR_EXPIRED
:
3972 err
= nfs4_handle_exception(server
, err
, &exception
);
3973 } while (exception
.retry
);
3977 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3978 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3981 * sleep, with exponential backoff, and retry the LOCK operation.
3983 static unsigned long
3984 nfs4_set_lock_task_retry(unsigned long timeout
)
3986 freezable_schedule_timeout_killable(timeout
);
3988 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3989 return NFS4_LOCK_MAXTIMEOUT
;
3993 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3995 struct inode
*inode
= state
->inode
;
3996 struct nfs_server
*server
= NFS_SERVER(inode
);
3997 struct nfs_client
*clp
= server
->nfs_client
;
3998 struct nfs_lockt_args arg
= {
3999 .fh
= NFS_FH(inode
),
4002 struct nfs_lockt_res res
= {
4005 struct rpc_message msg
= {
4006 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
4009 .rpc_cred
= state
->owner
->so_cred
,
4011 struct nfs4_lock_state
*lsp
;
4014 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
4015 status
= nfs4_set_lock_state(state
, request
);
4018 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4019 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4020 arg
.lock_owner
.s_dev
= server
->s_dev
;
4021 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
4024 request
->fl_type
= F_UNLCK
;
4026 case -NFS4ERR_DENIED
:
4029 request
->fl_ops
->fl_release_private(request
);
4034 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4036 struct nfs4_exception exception
= { };
4040 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4041 _nfs4_proc_getlk(state
, cmd
, request
),
4043 } while (exception
.retry
);
4047 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
4050 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
4052 res
= posix_lock_file_wait(file
, fl
);
4055 res
= flock_lock_file_wait(file
, fl
);
4063 struct nfs4_unlockdata
{
4064 struct nfs_locku_args arg
;
4065 struct nfs_locku_res res
;
4066 struct nfs4_lock_state
*lsp
;
4067 struct nfs_open_context
*ctx
;
4068 struct file_lock fl
;
4069 const struct nfs_server
*server
;
4070 unsigned long timestamp
;
4073 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
4074 struct nfs_open_context
*ctx
,
4075 struct nfs4_lock_state
*lsp
,
4076 struct nfs_seqid
*seqid
)
4078 struct nfs4_unlockdata
*p
;
4079 struct inode
*inode
= lsp
->ls_state
->inode
;
4081 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
4084 p
->arg
.fh
= NFS_FH(inode
);
4086 p
->arg
.seqid
= seqid
;
4087 p
->res
.seqid
= seqid
;
4088 p
->arg
.stateid
= &lsp
->ls_stateid
;
4090 atomic_inc(&lsp
->ls_count
);
4091 /* Ensure we don't close file until we're done freeing locks! */
4092 p
->ctx
= get_nfs_open_context(ctx
);
4093 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4094 p
->server
= NFS_SERVER(inode
);
4098 static void nfs4_locku_release_calldata(void *data
)
4100 struct nfs4_unlockdata
*calldata
= data
;
4101 nfs_free_seqid(calldata
->arg
.seqid
);
4102 nfs4_put_lock_state(calldata
->lsp
);
4103 put_nfs_open_context(calldata
->ctx
);
4107 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
4109 struct nfs4_unlockdata
*calldata
= data
;
4111 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
4113 switch (task
->tk_status
) {
4115 memcpy(calldata
->lsp
->ls_stateid
.data
,
4116 calldata
->res
.stateid
.data
,
4117 sizeof(calldata
->lsp
->ls_stateid
.data
));
4118 renew_lease(calldata
->server
, calldata
->timestamp
);
4120 case -NFS4ERR_BAD_STATEID
:
4121 case -NFS4ERR_OLD_STATEID
:
4122 case -NFS4ERR_STALE_STATEID
:
4123 case -NFS4ERR_EXPIRED
:
4126 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
4127 rpc_restart_call_prepare(task
);
4131 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
4133 struct nfs4_unlockdata
*calldata
= data
;
4135 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
4137 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
4138 /* Note: exit _without_ running nfs4_locku_done */
4139 task
->tk_action
= NULL
;
4142 calldata
->timestamp
= jiffies
;
4143 if (nfs4_setup_sequence(calldata
->server
,
4144 &calldata
->arg
.seq_args
,
4145 &calldata
->res
.seq_res
, 1, task
))
4147 rpc_call_start(task
);
4150 static const struct rpc_call_ops nfs4_locku_ops
= {
4151 .rpc_call_prepare
= nfs4_locku_prepare
,
4152 .rpc_call_done
= nfs4_locku_done
,
4153 .rpc_release
= nfs4_locku_release_calldata
,
4156 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
4157 struct nfs_open_context
*ctx
,
4158 struct nfs4_lock_state
*lsp
,
4159 struct nfs_seqid
*seqid
)
4161 struct nfs4_unlockdata
*data
;
4162 struct rpc_message msg
= {
4163 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
4164 .rpc_cred
= ctx
->cred
,
4166 struct rpc_task_setup task_setup_data
= {
4167 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
4168 .rpc_message
= &msg
,
4169 .callback_ops
= &nfs4_locku_ops
,
4170 .workqueue
= nfsiod_workqueue
,
4171 .flags
= RPC_TASK_ASYNC
,
4174 /* Ensure this is an unlock - when canceling a lock, the
4175 * canceled lock is passed in, and it won't be an unlock.
4177 fl
->fl_type
= F_UNLCK
;
4179 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
4181 nfs_free_seqid(seqid
);
4182 return ERR_PTR(-ENOMEM
);
4185 msg
.rpc_argp
= &data
->arg
;
4186 msg
.rpc_resp
= &data
->res
;
4187 task_setup_data
.callback_data
= data
;
4188 return rpc_run_task(&task_setup_data
);
4191 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4193 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4194 struct nfs_seqid
*seqid
;
4195 struct nfs4_lock_state
*lsp
;
4196 struct rpc_task
*task
;
4198 unsigned char fl_flags
= request
->fl_flags
;
4200 status
= nfs4_set_lock_state(state
, request
);
4201 /* Unlock _before_ we do the RPC call */
4202 request
->fl_flags
|= FL_EXISTS
;
4203 down_read(&nfsi
->rwsem
);
4204 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4205 up_read(&nfsi
->rwsem
);
4208 up_read(&nfsi
->rwsem
);
4211 /* Is this a delegated lock? */
4212 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4214 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4215 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4219 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4220 status
= PTR_ERR(task
);
4223 status
= nfs4_wait_for_completion_rpc_task(task
);
4226 request
->fl_flags
= fl_flags
;
4230 struct nfs4_lockdata
{
4231 struct nfs_lock_args arg
;
4232 struct nfs_lock_res res
;
4233 struct nfs4_lock_state
*lsp
;
4234 struct nfs_open_context
*ctx
;
4235 struct file_lock fl
;
4236 unsigned long timestamp
;
4239 struct nfs_server
*server
;
4242 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4243 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4246 struct nfs4_lockdata
*p
;
4247 struct inode
*inode
= lsp
->ls_state
->inode
;
4248 struct nfs_server
*server
= NFS_SERVER(inode
);
4250 p
= kzalloc(sizeof(*p
), gfp_mask
);
4254 p
->arg
.fh
= NFS_FH(inode
);
4256 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4257 if (p
->arg
.open_seqid
== NULL
)
4259 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4260 if (p
->arg
.lock_seqid
== NULL
)
4261 goto out_free_seqid
;
4262 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4263 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4264 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4265 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4266 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4269 atomic_inc(&lsp
->ls_count
);
4270 p
->ctx
= get_nfs_open_context(ctx
);
4271 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4274 nfs_free_seqid(p
->arg
.open_seqid
);
4280 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4282 struct nfs4_lockdata
*data
= calldata
;
4283 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4285 dprintk("%s: begin!\n", __func__
);
4286 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4288 /* Do we need to do an open_to_lock_owner? */
4289 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4290 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4292 data
->arg
.open_stateid
= &state
->stateid
;
4293 data
->arg
.new_lock_owner
= 1;
4294 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4296 data
->arg
.new_lock_owner
= 0;
4297 data
->timestamp
= jiffies
;
4298 if (nfs4_setup_sequence(data
->server
,
4299 &data
->arg
.seq_args
,
4300 &data
->res
.seq_res
, 1, task
))
4302 rpc_call_start(task
);
4303 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4306 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4308 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4309 nfs4_lock_prepare(task
, calldata
);
4312 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4314 struct nfs4_lockdata
*data
= calldata
;
4316 dprintk("%s: begin!\n", __func__
);
4318 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4321 data
->rpc_status
= task
->tk_status
;
4322 if (data
->arg
.new_lock_owner
!= 0) {
4323 if (data
->rpc_status
== 0)
4324 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4328 if (data
->rpc_status
== 0) {
4329 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4330 sizeof(data
->lsp
->ls_stateid
.data
));
4331 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4332 renew_lease(NFS_SERVER(data
->ctx
->dentry
->d_inode
), data
->timestamp
);
4335 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4338 static void nfs4_lock_release(void *calldata
)
4340 struct nfs4_lockdata
*data
= calldata
;
4342 dprintk("%s: begin!\n", __func__
);
4343 nfs_free_seqid(data
->arg
.open_seqid
);
4344 if (data
->cancelled
!= 0) {
4345 struct rpc_task
*task
;
4346 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4347 data
->arg
.lock_seqid
);
4349 rpc_put_task_async(task
);
4350 dprintk("%s: cancelling lock!\n", __func__
);
4352 nfs_free_seqid(data
->arg
.lock_seqid
);
4353 nfs4_put_lock_state(data
->lsp
);
4354 put_nfs_open_context(data
->ctx
);
4356 dprintk("%s: done!\n", __func__
);
4359 static const struct rpc_call_ops nfs4_lock_ops
= {
4360 .rpc_call_prepare
= nfs4_lock_prepare
,
4361 .rpc_call_done
= nfs4_lock_done
,
4362 .rpc_release
= nfs4_lock_release
,
4365 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4366 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4367 .rpc_call_done
= nfs4_lock_done
,
4368 .rpc_release
= nfs4_lock_release
,
4371 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4374 case -NFS4ERR_ADMIN_REVOKED
:
4375 case -NFS4ERR_BAD_STATEID
:
4376 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4377 if (new_lock_owner
!= 0 ||
4378 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4379 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
4381 case -NFS4ERR_STALE_STATEID
:
4382 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4383 case -NFS4ERR_EXPIRED
:
4384 nfs4_schedule_lease_recovery(server
->nfs_client
);
4388 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4390 struct nfs4_lockdata
*data
;
4391 struct rpc_task
*task
;
4392 struct rpc_message msg
= {
4393 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4394 .rpc_cred
= state
->owner
->so_cred
,
4396 struct rpc_task_setup task_setup_data
= {
4397 .rpc_client
= NFS_CLIENT(state
->inode
),
4398 .rpc_message
= &msg
,
4399 .callback_ops
= &nfs4_lock_ops
,
4400 .workqueue
= nfsiod_workqueue
,
4401 .flags
= RPC_TASK_ASYNC
,
4405 dprintk("%s: begin!\n", __func__
);
4406 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4407 fl
->fl_u
.nfs4_fl
.owner
,
4408 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4412 data
->arg
.block
= 1;
4413 if (recovery_type
> NFS_LOCK_NEW
) {
4414 if (recovery_type
== NFS_LOCK_RECLAIM
)
4415 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4416 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4418 msg
.rpc_argp
= &data
->arg
;
4419 msg
.rpc_resp
= &data
->res
;
4420 task_setup_data
.callback_data
= data
;
4421 task
= rpc_run_task(&task_setup_data
);
4423 return PTR_ERR(task
);
4424 ret
= nfs4_wait_for_completion_rpc_task(task
);
4426 ret
= data
->rpc_status
;
4428 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4429 data
->arg
.new_lock_owner
, ret
);
4431 data
->cancelled
= 1;
4433 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4437 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4439 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4440 struct nfs4_exception exception
= { };
4444 /* Cache the lock if possible... */
4445 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4447 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4448 if (err
!= -NFS4ERR_DELAY
)
4450 nfs4_handle_exception(server
, err
, &exception
);
4451 } while (exception
.retry
);
4455 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4457 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4458 struct nfs4_exception exception
= { };
4461 err
= nfs4_set_lock_state(state
, request
);
4465 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4467 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4471 case -NFS4ERR_GRACE
:
4472 case -NFS4ERR_DELAY
:
4473 nfs4_handle_exception(server
, err
, &exception
);
4476 } while (exception
.retry
);
4481 #if defined(CONFIG_NFS_V4_1)
4482 static int nfs41_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4485 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4487 status
= nfs41_test_stateid(server
, state
);
4488 if (status
== NFS_OK
)
4490 nfs41_free_stateid(server
, state
);
4491 return nfs4_lock_expired(state
, request
);
4495 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4497 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4498 unsigned char fl_flags
= request
->fl_flags
;
4499 int status
= -ENOLCK
;
4501 if ((fl_flags
& FL_POSIX
) &&
4502 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4504 /* Is this a delegated open? */
4505 status
= nfs4_set_lock_state(state
, request
);
4508 request
->fl_flags
|= FL_ACCESS
;
4509 status
= do_vfs_lock(request
->fl_file
, request
);
4512 down_read(&nfsi
->rwsem
);
4513 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4514 /* Yes: cache locks! */
4515 /* ...but avoid races with delegation recall... */
4516 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4517 status
= do_vfs_lock(request
->fl_file
, request
);
4520 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4523 /* Note: we always want to sleep here! */
4524 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4525 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4526 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4528 up_read(&nfsi
->rwsem
);
4530 request
->fl_flags
= fl_flags
;
4534 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4536 struct nfs4_exception exception
= { };
4540 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4541 if (err
== -NFS4ERR_DENIED
)
4543 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4545 } while (exception
.retry
);
4550 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4552 struct nfs_open_context
*ctx
;
4553 struct nfs4_state
*state
;
4554 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4557 /* verify open state */
4558 ctx
= nfs_file_open_context(filp
);
4561 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4564 if (IS_GETLK(cmd
)) {
4566 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4570 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4573 if (request
->fl_type
== F_UNLCK
) {
4575 return nfs4_proc_unlck(state
, cmd
, request
);
4582 status
= nfs4_proc_setlk(state
, cmd
, request
);
4583 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4585 timeout
= nfs4_set_lock_task_retry(timeout
);
4586 status
= -ERESTARTSYS
;
4589 } while(status
< 0);
4593 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4595 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4596 struct nfs4_exception exception
= { };
4599 err
= nfs4_set_lock_state(state
, fl
);
4603 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4606 printk(KERN_ERR
"%s: unhandled error %d.\n",
4611 case -NFS4ERR_EXPIRED
:
4612 nfs4_schedule_stateid_recovery(server
, state
);
4613 case -NFS4ERR_STALE_CLIENTID
:
4614 case -NFS4ERR_STALE_STATEID
:
4615 nfs4_schedule_lease_recovery(server
->nfs_client
);
4617 case -NFS4ERR_BADSESSION
:
4618 case -NFS4ERR_BADSLOT
:
4619 case -NFS4ERR_BAD_HIGH_SLOT
:
4620 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4621 case -NFS4ERR_DEADSESSION
:
4622 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4626 * The show must go on: exit, but mark the
4627 * stateid as needing recovery.
4629 case -NFS4ERR_ADMIN_REVOKED
:
4630 case -NFS4ERR_BAD_STATEID
:
4631 case -NFS4ERR_OPENMODE
:
4632 nfs4_schedule_stateid_recovery(server
, state
);
4637 * User RPCSEC_GSS context has expired.
4638 * We cannot recover this stateid now, so
4639 * skip it and allow recovery thread to
4645 case -NFS4ERR_DENIED
:
4646 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4649 case -NFS4ERR_DELAY
:
4652 err
= nfs4_handle_exception(server
, err
, &exception
);
4653 } while (exception
.retry
);
4658 static void nfs4_release_lockowner_release(void *calldata
)
4663 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4664 .rpc_release
= nfs4_release_lockowner_release
,
4667 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4669 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4670 struct nfs_release_lockowner_args
*args
;
4671 struct rpc_message msg
= {
4672 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4675 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4677 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4680 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4681 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4682 args
->lock_owner
.s_dev
= server
->s_dev
;
4683 msg
.rpc_argp
= args
;
4684 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4687 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4689 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4690 const void *buf
, size_t buflen
,
4691 int flags
, int type
)
4693 if (strcmp(key
, "") != 0)
4696 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4699 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4700 void *buf
, size_t buflen
, int type
)
4702 if (strcmp(key
, "") != 0)
4705 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4708 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4709 size_t list_len
, const char *name
,
4710 size_t name_len
, int type
)
4712 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4714 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4717 if (list
&& len
<= list_len
)
4718 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4723 * nfs_fhget will use either the mounted_on_fileid or the fileid
4725 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4727 if (!(((fattr
->valid
& NFS_ATTR_FATTR_MOUNTED_ON_FILEID
) ||
4728 (fattr
->valid
& NFS_ATTR_FATTR_FILEID
)) &&
4729 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4730 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4733 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4734 NFS_ATTR_FATTR_NLINK
;
4735 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4739 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4740 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4742 struct nfs_server
*server
= NFS_SERVER(dir
);
4744 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4746 struct nfs4_fs_locations_arg args
= {
4747 .dir_fh
= NFS_FH(dir
),
4752 struct nfs4_fs_locations_res res
= {
4753 .fs_locations
= fs_locations
,
4755 struct rpc_message msg
= {
4756 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4762 dprintk("%s: start\n", __func__
);
4764 /* Ask for the fileid of the absent filesystem if mounted_on_fileid
4765 * is not supported */
4766 if (NFS_SERVER(dir
)->attr_bitmask
[1] & FATTR4_WORD1_MOUNTED_ON_FILEID
)
4767 bitmask
[1] |= FATTR4_WORD1_MOUNTED_ON_FILEID
;
4769 bitmask
[0] |= FATTR4_WORD0_FILEID
;
4771 nfs_fattr_init(&fs_locations
->fattr
);
4772 fs_locations
->server
= server
;
4773 fs_locations
->nlocations
= 0;
4774 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4775 dprintk("%s: returned status = %d\n", __func__
, status
);
4779 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4782 struct nfs4_secinfo_arg args
= {
4783 .dir_fh
= NFS_FH(dir
),
4786 struct nfs4_secinfo_res res
= {
4789 struct rpc_message msg
= {
4790 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
4795 dprintk("NFS call secinfo %s\n", name
->name
);
4796 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4797 dprintk("NFS reply secinfo: %d\n", status
);
4801 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4803 struct nfs4_exception exception
= { };
4806 err
= nfs4_handle_exception(NFS_SERVER(dir
),
4807 _nfs4_proc_secinfo(dir
, name
, flavors
),
4809 } while (exception
.retry
);
4813 #ifdef CONFIG_NFS_V4_1
4815 * Check the exchange flags returned by the server for invalid flags, having
4816 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4819 static int nfs4_check_cl_exchange_flags(u32 flags
)
4821 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4823 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4824 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4826 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4830 return -NFS4ERR_INVAL
;
4834 nfs41_same_server_scope(struct server_scope
*a
, struct server_scope
*b
)
4836 if (a
->server_scope_sz
== b
->server_scope_sz
&&
4837 memcmp(a
->server_scope
, b
->server_scope
, a
->server_scope_sz
) == 0)
4844 * nfs4_proc_exchange_id()
4846 * Since the clientid has expired, all compounds using sessions
4847 * associated with the stale clientid will be returning
4848 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4849 * be in some phase of session reset.
4851 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4853 nfs4_verifier verifier
;
4854 struct nfs41_exchange_id_args args
= {
4856 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4858 struct nfs41_exchange_id_res res
= {
4862 struct rpc_message msg
= {
4863 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4870 dprintk("--> %s\n", __func__
);
4871 BUG_ON(clp
== NULL
);
4873 p
= (u32
*)verifier
.data
;
4874 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4875 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4876 args
.verifier
= &verifier
;
4878 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4881 init_utsname()->nodename
,
4882 init_utsname()->domainname
,
4883 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4885 res
.server_scope
= kzalloc(sizeof(struct server_scope
), GFP_KERNEL
);
4886 if (unlikely(!res
.server_scope
)) {
4891 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
4893 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4896 if (clp
->server_scope
&&
4897 !nfs41_same_server_scope(clp
->server_scope
,
4898 res
.server_scope
)) {
4899 dprintk("%s: server_scope mismatch detected\n",
4901 set_bit(NFS4CLNT_SERVER_SCOPE_MISMATCH
, &clp
->cl_state
);
4902 kfree(clp
->server_scope
);
4903 clp
->server_scope
= NULL
;
4906 if (!clp
->server_scope
) {
4907 clp
->server_scope
= res
.server_scope
;
4911 kfree(res
.server_scope
);
4913 dprintk("<-- %s status= %d\n", __func__
, status
);
4917 struct nfs4_get_lease_time_data
{
4918 struct nfs4_get_lease_time_args
*args
;
4919 struct nfs4_get_lease_time_res
*res
;
4920 struct nfs_client
*clp
;
4923 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4927 struct nfs4_get_lease_time_data
*data
=
4928 (struct nfs4_get_lease_time_data
*)calldata
;
4930 dprintk("--> %s\n", __func__
);
4931 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4932 /* just setup sequence, do not trigger session recovery
4933 since we're invoked within one */
4934 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4935 &data
->args
->la_seq_args
,
4936 &data
->res
->lr_seq_res
, 0, task
);
4938 BUG_ON(ret
== -EAGAIN
);
4939 rpc_call_start(task
);
4940 dprintk("<-- %s\n", __func__
);
4944 * Called from nfs4_state_manager thread for session setup, so don't recover
4945 * from sequence operation or clientid errors.
4947 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4949 struct nfs4_get_lease_time_data
*data
=
4950 (struct nfs4_get_lease_time_data
*)calldata
;
4952 dprintk("--> %s\n", __func__
);
4953 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4955 switch (task
->tk_status
) {
4956 case -NFS4ERR_DELAY
:
4957 case -NFS4ERR_GRACE
:
4958 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4959 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4960 task
->tk_status
= 0;
4962 case -NFS4ERR_RETRY_UNCACHED_REP
:
4963 rpc_restart_call_prepare(task
);
4966 dprintk("<-- %s\n", __func__
);
4969 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4970 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4971 .rpc_call_done
= nfs4_get_lease_time_done
,
4974 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4976 struct rpc_task
*task
;
4977 struct nfs4_get_lease_time_args args
;
4978 struct nfs4_get_lease_time_res res
= {
4979 .lr_fsinfo
= fsinfo
,
4981 struct nfs4_get_lease_time_data data
= {
4986 struct rpc_message msg
= {
4987 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4991 struct rpc_task_setup task_setup
= {
4992 .rpc_client
= clp
->cl_rpcclient
,
4993 .rpc_message
= &msg
,
4994 .callback_ops
= &nfs4_get_lease_time_ops
,
4995 .callback_data
= &data
,
4996 .flags
= RPC_TASK_TIMEOUT
,
5000 dprintk("--> %s\n", __func__
);
5001 task
= rpc_run_task(&task_setup
);
5004 status
= PTR_ERR(task
);
5006 status
= task
->tk_status
;
5009 dprintk("<-- %s return %d\n", __func__
, status
);
5014 static struct nfs4_slot
*nfs4_alloc_slots(u32 max_slots
, gfp_t gfp_flags
)
5016 return kcalloc(max_slots
, sizeof(struct nfs4_slot
), gfp_flags
);
5019 static void nfs4_add_and_init_slots(struct nfs4_slot_table
*tbl
,
5020 struct nfs4_slot
*new,
5024 struct nfs4_slot
*old
= NULL
;
5027 spin_lock(&tbl
->slot_tbl_lock
);
5031 tbl
->max_slots
= max_slots
;
5033 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
5034 for (i
= 0; i
< tbl
->max_slots
; i
++)
5035 tbl
->slots
[i
].seq_nr
= ivalue
;
5036 spin_unlock(&tbl
->slot_tbl_lock
);
5041 * (re)Initialise a slot table
5043 static int nfs4_realloc_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
5046 struct nfs4_slot
*new = NULL
;
5049 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
5050 max_reqs
, tbl
->max_slots
);
5052 /* Does the newly negotiated max_reqs match the existing slot table? */
5053 if (max_reqs
!= tbl
->max_slots
) {
5054 new = nfs4_alloc_slots(max_reqs
, GFP_NOFS
);
5060 nfs4_add_and_init_slots(tbl
, new, max_reqs
, ivalue
);
5061 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
5062 tbl
, tbl
->slots
, tbl
->max_slots
);
5064 dprintk("<-- %s: return %d\n", __func__
, ret
);
5068 /* Destroy the slot table */
5069 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
5071 if (session
->fc_slot_table
.slots
!= NULL
) {
5072 kfree(session
->fc_slot_table
.slots
);
5073 session
->fc_slot_table
.slots
= NULL
;
5075 if (session
->bc_slot_table
.slots
!= NULL
) {
5076 kfree(session
->bc_slot_table
.slots
);
5077 session
->bc_slot_table
.slots
= NULL
;
5083 * Initialize or reset the forechannel and backchannel tables
5085 static int nfs4_setup_session_slot_tables(struct nfs4_session
*ses
)
5087 struct nfs4_slot_table
*tbl
;
5090 dprintk("--> %s\n", __func__
);
5092 tbl
= &ses
->fc_slot_table
;
5093 status
= nfs4_realloc_slot_table(tbl
, ses
->fc_attrs
.max_reqs
, 1);
5094 if (status
) /* -ENOMEM */
5097 tbl
= &ses
->bc_slot_table
;
5098 status
= nfs4_realloc_slot_table(tbl
, ses
->bc_attrs
.max_reqs
, 0);
5099 if (status
&& tbl
->slots
== NULL
)
5100 /* Fore and back channel share a connection so get
5101 * both slot tables or neither */
5102 nfs4_destroy_slot_tables(ses
);
5106 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
5108 struct nfs4_session
*session
;
5109 struct nfs4_slot_table
*tbl
;
5111 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5115 tbl
= &session
->fc_slot_table
;
5116 tbl
->highest_used_slotid
= -1;
5117 spin_lock_init(&tbl
->slot_tbl_lock
);
5118 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
5119 init_completion(&tbl
->complete
);
5121 tbl
= &session
->bc_slot_table
;
5122 tbl
->highest_used_slotid
= -1;
5123 spin_lock_init(&tbl
->slot_tbl_lock
);
5124 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
5125 init_completion(&tbl
->complete
);
5127 session
->session_state
= 1<<NFS4_SESSION_INITING
;
5133 void nfs4_destroy_session(struct nfs4_session
*session
)
5135 nfs4_proc_destroy_session(session
);
5136 dprintk("%s Destroy backchannel for xprt %p\n",
5137 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
5138 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
5139 NFS41_BC_MIN_CALLBACKS
);
5140 nfs4_destroy_slot_tables(session
);
5145 * Initialize the values to be used by the client in CREATE_SESSION
5146 * If nfs4_init_session set the fore channel request and response sizes,
5149 * Set the back channel max_resp_sz_cached to zero to force the client to
5150 * always set csa_cachethis to FALSE because the current implementation
5151 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5153 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
5155 struct nfs4_session
*session
= args
->client
->cl_session
;
5156 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
5157 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
5160 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
5162 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
5163 /* Fore channel attributes */
5164 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
5165 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
5166 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
5167 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
5169 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5170 "max_ops=%u max_reqs=%u\n",
5172 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
5173 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
5175 /* Back channel attributes */
5176 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
5177 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
5178 args
->bc_attrs
.max_resp_sz_cached
= 0;
5179 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
5180 args
->bc_attrs
.max_reqs
= 1;
5182 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5183 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5185 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
5186 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
5187 args
->bc_attrs
.max_reqs
);
5190 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5192 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
5193 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
5195 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
5198 * Our requested max_ops is the minimum we need; we're not
5199 * prepared to break up compounds into smaller pieces than that.
5200 * So, no point even trying to continue if the server won't
5203 if (rcvd
->max_ops
< sent
->max_ops
)
5205 if (rcvd
->max_reqs
== 0)
5210 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5212 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
5213 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
5215 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
5217 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
5219 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
5221 /* These would render the backchannel useless: */
5222 if (rcvd
->max_ops
== 0)
5224 if (rcvd
->max_reqs
== 0)
5229 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
5230 struct nfs4_session
*session
)
5234 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
5237 return nfs4_verify_back_channel_attrs(args
, session
);
5240 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
5242 struct nfs4_session
*session
= clp
->cl_session
;
5243 struct nfs41_create_session_args args
= {
5245 .cb_program
= NFS4_CALLBACK
,
5247 struct nfs41_create_session_res res
= {
5250 struct rpc_message msg
= {
5251 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5257 nfs4_init_channel_attrs(&args
);
5258 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5260 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5263 /* Verify the session's negotiated channel_attrs values */
5264 status
= nfs4_verify_channel_attrs(&args
, session
);
5266 /* Increment the clientid slot sequence id */
5274 * Issues a CREATE_SESSION operation to the server.
5275 * It is the responsibility of the caller to verify the session is
5276 * expired before calling this routine.
5278 int nfs4_proc_create_session(struct nfs_client
*clp
)
5282 struct nfs4_session
*session
= clp
->cl_session
;
5284 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5286 status
= _nfs4_proc_create_session(clp
);
5290 /* Init or reset the session slot tables */
5291 status
= nfs4_setup_session_slot_tables(session
);
5292 dprintk("slot table setup returned %d\n", status
);
5296 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5297 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5298 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5300 dprintk("<-- %s\n", __func__
);
5305 * Issue the over-the-wire RPC DESTROY_SESSION.
5306 * The caller must serialize access to this routine.
5308 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5311 struct rpc_message msg
;
5313 dprintk("--> nfs4_proc_destroy_session\n");
5315 /* session is still being setup */
5316 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5319 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5320 msg
.rpc_argp
= session
;
5321 msg
.rpc_resp
= NULL
;
5322 msg
.rpc_cred
= NULL
;
5323 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, RPC_TASK_TIMEOUT
);
5327 "Got error %d from the server on DESTROY_SESSION. "
5328 "Session has been destroyed regardless...\n", status
);
5330 dprintk("<-- nfs4_proc_destroy_session\n");
5334 int nfs4_init_session(struct nfs_server
*server
)
5336 struct nfs_client
*clp
= server
->nfs_client
;
5337 struct nfs4_session
*session
;
5338 unsigned int rsize
, wsize
;
5341 if (!nfs4_has_session(clp
))
5344 session
= clp
->cl_session
;
5345 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5348 rsize
= server
->rsize
;
5350 rsize
= NFS_MAX_FILE_IO_SIZE
;
5351 wsize
= server
->wsize
;
5353 wsize
= NFS_MAX_FILE_IO_SIZE
;
5355 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5356 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5358 ret
= nfs4_recover_expired_lease(server
);
5360 ret
= nfs4_check_client_ready(clp
);
5364 int nfs4_init_ds_session(struct nfs_client
*clp
)
5366 struct nfs4_session
*session
= clp
->cl_session
;
5369 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5372 ret
= nfs4_client_recover_expired_lease(clp
);
5374 /* Test for the DS role */
5375 if (!is_ds_client(clp
))
5378 ret
= nfs4_check_client_ready(clp
);
5382 EXPORT_SYMBOL_GPL(nfs4_init_ds_session
);
5386 * Renew the cl_session lease.
5388 struct nfs4_sequence_data
{
5389 struct nfs_client
*clp
;
5390 struct nfs4_sequence_args args
;
5391 struct nfs4_sequence_res res
;
5394 static void nfs41_sequence_release(void *data
)
5396 struct nfs4_sequence_data
*calldata
= data
;
5397 struct nfs_client
*clp
= calldata
->clp
;
5399 if (atomic_read(&clp
->cl_count
) > 1)
5400 nfs4_schedule_state_renewal(clp
);
5401 nfs_put_client(clp
);
5405 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5407 switch(task
->tk_status
) {
5408 case -NFS4ERR_DELAY
:
5409 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5412 nfs4_schedule_lease_recovery(clp
);
5417 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5419 struct nfs4_sequence_data
*calldata
= data
;
5420 struct nfs_client
*clp
= calldata
->clp
;
5422 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5425 if (task
->tk_status
< 0) {
5426 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5427 if (atomic_read(&clp
->cl_count
) == 1)
5430 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5431 rpc_restart_call_prepare(task
);
5435 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5437 dprintk("<-- %s\n", __func__
);
5440 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5442 struct nfs4_sequence_data
*calldata
= data
;
5443 struct nfs_client
*clp
= calldata
->clp
;
5444 struct nfs4_sequence_args
*args
;
5445 struct nfs4_sequence_res
*res
;
5447 args
= task
->tk_msg
.rpc_argp
;
5448 res
= task
->tk_msg
.rpc_resp
;
5450 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5452 rpc_call_start(task
);
5455 static const struct rpc_call_ops nfs41_sequence_ops
= {
5456 .rpc_call_done
= nfs41_sequence_call_done
,
5457 .rpc_call_prepare
= nfs41_sequence_prepare
,
5458 .rpc_release
= nfs41_sequence_release
,
5461 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5463 struct nfs4_sequence_data
*calldata
;
5464 struct rpc_message msg
= {
5465 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5468 struct rpc_task_setup task_setup_data
= {
5469 .rpc_client
= clp
->cl_rpcclient
,
5470 .rpc_message
= &msg
,
5471 .callback_ops
= &nfs41_sequence_ops
,
5472 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5475 if (!atomic_inc_not_zero(&clp
->cl_count
))
5476 return ERR_PTR(-EIO
);
5477 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5478 if (calldata
== NULL
) {
5479 nfs_put_client(clp
);
5480 return ERR_PTR(-ENOMEM
);
5482 msg
.rpc_argp
= &calldata
->args
;
5483 msg
.rpc_resp
= &calldata
->res
;
5484 calldata
->clp
= clp
;
5485 task_setup_data
.callback_data
= calldata
;
5487 return rpc_run_task(&task_setup_data
);
5490 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
, unsigned renew_flags
)
5492 struct rpc_task
*task
;
5495 if ((renew_flags
& NFS4_RENEW_TIMEOUT
) == 0)
5497 task
= _nfs41_proc_sequence(clp
, cred
);
5499 ret
= PTR_ERR(task
);
5501 rpc_put_task_async(task
);
5502 dprintk("<-- %s status=%d\n", __func__
, ret
);
5506 static int nfs4_proc_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
);
5516 ret
= rpc_wait_for_completion_task(task
);
5518 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
5520 if (task
->tk_status
== 0)
5521 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
5522 ret
= task
->tk_status
;
5526 dprintk("<-- %s status=%d\n", __func__
, ret
);
5530 struct nfs4_reclaim_complete_data
{
5531 struct nfs_client
*clp
;
5532 struct nfs41_reclaim_complete_args arg
;
5533 struct nfs41_reclaim_complete_res res
;
5536 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5538 struct nfs4_reclaim_complete_data
*calldata
= data
;
5540 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5541 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5542 &calldata
->arg
.seq_args
,
5543 &calldata
->res
.seq_res
, 0, task
))
5546 rpc_call_start(task
);
5549 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5551 switch(task
->tk_status
) {
5553 case -NFS4ERR_COMPLETE_ALREADY
:
5554 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5556 case -NFS4ERR_DELAY
:
5557 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5559 case -NFS4ERR_RETRY_UNCACHED_REP
:
5562 nfs4_schedule_lease_recovery(clp
);
5567 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5569 struct nfs4_reclaim_complete_data
*calldata
= data
;
5570 struct nfs_client
*clp
= calldata
->clp
;
5571 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5573 dprintk("--> %s\n", __func__
);
5574 if (!nfs41_sequence_done(task
, res
))
5577 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5578 rpc_restart_call_prepare(task
);
5581 dprintk("<-- %s\n", __func__
);
5584 static void nfs4_free_reclaim_complete_data(void *data
)
5586 struct nfs4_reclaim_complete_data
*calldata
= data
;
5591 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5592 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5593 .rpc_call_done
= nfs4_reclaim_complete_done
,
5594 .rpc_release
= nfs4_free_reclaim_complete_data
,
5598 * Issue a global reclaim complete.
5600 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5602 struct nfs4_reclaim_complete_data
*calldata
;
5603 struct rpc_task
*task
;
5604 struct rpc_message msg
= {
5605 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5607 struct rpc_task_setup task_setup_data
= {
5608 .rpc_client
= clp
->cl_rpcclient
,
5609 .rpc_message
= &msg
,
5610 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5611 .flags
= RPC_TASK_ASYNC
,
5613 int status
= -ENOMEM
;
5615 dprintk("--> %s\n", __func__
);
5616 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5617 if (calldata
== NULL
)
5619 calldata
->clp
= clp
;
5620 calldata
->arg
.one_fs
= 0;
5622 msg
.rpc_argp
= &calldata
->arg
;
5623 msg
.rpc_resp
= &calldata
->res
;
5624 task_setup_data
.callback_data
= calldata
;
5625 task
= rpc_run_task(&task_setup_data
);
5627 status
= PTR_ERR(task
);
5630 status
= nfs4_wait_for_completion_rpc_task(task
);
5632 status
= task
->tk_status
;
5636 dprintk("<-- %s status=%d\n", __func__
, status
);
5641 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5643 struct nfs4_layoutget
*lgp
= calldata
;
5644 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5646 dprintk("--> %s\n", __func__
);
5647 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5648 * right now covering the LAYOUTGET we are about to send.
5649 * However, that is not so catastrophic, and there seems
5650 * to be no way to prevent it completely.
5652 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5653 &lgp
->res
.seq_res
, 0, task
))
5655 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5656 NFS_I(lgp
->args
.inode
)->layout
,
5657 lgp
->args
.ctx
->state
)) {
5658 rpc_exit(task
, NFS4_OK
);
5661 rpc_call_start(task
);
5664 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5666 struct nfs4_layoutget
*lgp
= calldata
;
5667 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5669 dprintk("--> %s\n", __func__
);
5671 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5674 switch (task
->tk_status
) {
5677 case -NFS4ERR_LAYOUTTRYLATER
:
5678 case -NFS4ERR_RECALLCONFLICT
:
5679 task
->tk_status
= -NFS4ERR_DELAY
;
5682 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5683 rpc_restart_call_prepare(task
);
5687 dprintk("<-- %s\n", __func__
);
5690 static void nfs4_layoutget_release(void *calldata
)
5692 struct nfs4_layoutget
*lgp
= calldata
;
5694 dprintk("--> %s\n", __func__
);
5695 put_nfs_open_context(lgp
->args
.ctx
);
5697 dprintk("<-- %s\n", __func__
);
5700 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5701 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5702 .rpc_call_done
= nfs4_layoutget_done
,
5703 .rpc_release
= nfs4_layoutget_release
,
5706 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5708 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5709 struct rpc_task
*task
;
5710 struct rpc_message msg
= {
5711 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5712 .rpc_argp
= &lgp
->args
,
5713 .rpc_resp
= &lgp
->res
,
5715 struct rpc_task_setup task_setup_data
= {
5716 .rpc_client
= server
->client
,
5717 .rpc_message
= &msg
,
5718 .callback_ops
= &nfs4_layoutget_call_ops
,
5719 .callback_data
= lgp
,
5720 .flags
= RPC_TASK_ASYNC
,
5724 dprintk("--> %s\n", __func__
);
5726 lgp
->res
.layoutp
= &lgp
->args
.layout
;
5727 lgp
->res
.seq_res
.sr_slot
= NULL
;
5728 task
= rpc_run_task(&task_setup_data
);
5730 return PTR_ERR(task
);
5731 status
= nfs4_wait_for_completion_rpc_task(task
);
5733 status
= task
->tk_status
;
5735 status
= pnfs_layout_process(lgp
);
5737 dprintk("<-- %s status=%d\n", __func__
, status
);
5742 nfs4_layoutreturn_prepare(struct rpc_task
*task
, void *calldata
)
5744 struct nfs4_layoutreturn
*lrp
= calldata
;
5746 dprintk("--> %s\n", __func__
);
5747 if (nfs41_setup_sequence(lrp
->clp
->cl_session
, &lrp
->args
.seq_args
,
5748 &lrp
->res
.seq_res
, 0, task
))
5750 rpc_call_start(task
);
5753 static void nfs4_layoutreturn_done(struct rpc_task
*task
, void *calldata
)
5755 struct nfs4_layoutreturn
*lrp
= calldata
;
5756 struct nfs_server
*server
;
5757 struct pnfs_layout_hdr
*lo
= lrp
->args
.layout
;
5759 dprintk("--> %s\n", __func__
);
5761 if (!nfs4_sequence_done(task
, &lrp
->res
.seq_res
))
5764 server
= NFS_SERVER(lrp
->args
.inode
);
5765 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5766 rpc_restart_call_prepare(task
);
5769 spin_lock(&lo
->plh_inode
->i_lock
);
5770 if (task
->tk_status
== 0) {
5771 if (lrp
->res
.lrs_present
) {
5772 pnfs_set_layout_stateid(lo
, &lrp
->res
.stateid
, true);
5774 BUG_ON(!list_empty(&lo
->plh_segs
));
5776 lo
->plh_block_lgets
--;
5777 spin_unlock(&lo
->plh_inode
->i_lock
);
5778 dprintk("<-- %s\n", __func__
);
5781 static void nfs4_layoutreturn_release(void *calldata
)
5783 struct nfs4_layoutreturn
*lrp
= calldata
;
5785 dprintk("--> %s\n", __func__
);
5786 put_layout_hdr(lrp
->args
.layout
);
5788 dprintk("<-- %s\n", __func__
);
5791 static const struct rpc_call_ops nfs4_layoutreturn_call_ops
= {
5792 .rpc_call_prepare
= nfs4_layoutreturn_prepare
,
5793 .rpc_call_done
= nfs4_layoutreturn_done
,
5794 .rpc_release
= nfs4_layoutreturn_release
,
5797 int nfs4_proc_layoutreturn(struct nfs4_layoutreturn
*lrp
)
5799 struct rpc_task
*task
;
5800 struct rpc_message msg
= {
5801 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTRETURN
],
5802 .rpc_argp
= &lrp
->args
,
5803 .rpc_resp
= &lrp
->res
,
5805 struct rpc_task_setup task_setup_data
= {
5806 .rpc_client
= lrp
->clp
->cl_rpcclient
,
5807 .rpc_message
= &msg
,
5808 .callback_ops
= &nfs4_layoutreturn_call_ops
,
5809 .callback_data
= lrp
,
5813 dprintk("--> %s\n", __func__
);
5814 task
= rpc_run_task(&task_setup_data
);
5816 return PTR_ERR(task
);
5817 status
= task
->tk_status
;
5818 dprintk("<-- %s status=%d\n", __func__
, status
);
5824 * Retrieve the list of Data Server devices from the MDS.
5826 static int _nfs4_getdevicelist(struct nfs_server
*server
,
5827 const struct nfs_fh
*fh
,
5828 struct pnfs_devicelist
*devlist
)
5830 struct nfs4_getdevicelist_args args
= {
5832 .layoutclass
= server
->pnfs_curr_ld
->id
,
5834 struct nfs4_getdevicelist_res res
= {
5837 struct rpc_message msg
= {
5838 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICELIST
],
5844 dprintk("--> %s\n", __func__
);
5845 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
,
5847 dprintk("<-- %s status=%d\n", __func__
, status
);
5851 int nfs4_proc_getdevicelist(struct nfs_server
*server
,
5852 const struct nfs_fh
*fh
,
5853 struct pnfs_devicelist
*devlist
)
5855 struct nfs4_exception exception
= { };
5859 err
= nfs4_handle_exception(server
,
5860 _nfs4_getdevicelist(server
, fh
, devlist
),
5862 } while (exception
.retry
);
5864 dprintk("%s: err=%d, num_devs=%u\n", __func__
,
5865 err
, devlist
->num_devs
);
5869 EXPORT_SYMBOL_GPL(nfs4_proc_getdevicelist
);
5872 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5874 struct nfs4_getdeviceinfo_args args
= {
5877 struct nfs4_getdeviceinfo_res res
= {
5880 struct rpc_message msg
= {
5881 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5887 dprintk("--> %s\n", __func__
);
5888 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5889 dprintk("<-- %s status=%d\n", __func__
, status
);
5894 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5896 struct nfs4_exception exception
= { };
5900 err
= nfs4_handle_exception(server
,
5901 _nfs4_proc_getdeviceinfo(server
, pdev
),
5903 } while (exception
.retry
);
5906 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5908 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
5910 struct nfs4_layoutcommit_data
*data
= calldata
;
5911 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5913 if (nfs4_setup_sequence(server
, &data
->args
.seq_args
,
5914 &data
->res
.seq_res
, 1, task
))
5916 rpc_call_start(task
);
5920 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
5922 struct nfs4_layoutcommit_data
*data
= calldata
;
5923 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5925 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5928 switch (task
->tk_status
) { /* Just ignore these failures */
5929 case NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
5930 case NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
5931 case NFS4ERR_BADLAYOUT
: /* no layout */
5932 case NFS4ERR_GRACE
: /* loca_recalim always false */
5933 task
->tk_status
= 0;
5936 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5937 rpc_restart_call_prepare(task
);
5941 if (task
->tk_status
== 0)
5942 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
5946 static void nfs4_layoutcommit_release(void *calldata
)
5948 struct nfs4_layoutcommit_data
*data
= calldata
;
5949 struct pnfs_layout_segment
*lseg
, *tmp
;
5950 unsigned long *bitlock
= &NFS_I(data
->args
.inode
)->flags
;
5952 pnfs_cleanup_layoutcommit(data
);
5953 /* Matched by references in pnfs_set_layoutcommit */
5954 list_for_each_entry_safe(lseg
, tmp
, &data
->lseg_list
, pls_lc_list
) {
5955 list_del_init(&lseg
->pls_lc_list
);
5956 if (test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT
,
5961 clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING
, bitlock
);
5962 smp_mb__after_clear_bit();
5963 wake_up_bit(bitlock
, NFS_INO_LAYOUTCOMMITTING
);
5965 put_rpccred(data
->cred
);
5969 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
5970 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
5971 .rpc_call_done
= nfs4_layoutcommit_done
,
5972 .rpc_release
= nfs4_layoutcommit_release
,
5976 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
5978 struct rpc_message msg
= {
5979 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
5980 .rpc_argp
= &data
->args
,
5981 .rpc_resp
= &data
->res
,
5982 .rpc_cred
= data
->cred
,
5984 struct rpc_task_setup task_setup_data
= {
5985 .task
= &data
->task
,
5986 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
5987 .rpc_message
= &msg
,
5988 .callback_ops
= &nfs4_layoutcommit_ops
,
5989 .callback_data
= data
,
5990 .flags
= RPC_TASK_ASYNC
,
5992 struct rpc_task
*task
;
5995 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
5996 "lbw: %llu inode %lu\n",
5997 data
->task
.tk_pid
, sync
,
5998 data
->args
.lastbytewritten
,
5999 data
->args
.inode
->i_ino
);
6001 task
= rpc_run_task(&task_setup_data
);
6003 return PTR_ERR(task
);
6006 status
= nfs4_wait_for_completion_rpc_task(task
);
6009 status
= task
->tk_status
;
6011 dprintk("%s: status %d\n", __func__
, status
);
6017 _nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6018 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
6020 struct nfs41_secinfo_no_name_args args
= {
6021 .style
= SECINFO_STYLE_CURRENT_FH
,
6023 struct nfs4_secinfo_res res
= {
6026 struct rpc_message msg
= {
6027 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO_NO_NAME
],
6031 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
6035 nfs41_proc_secinfo_no_name(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6036 struct nfs_fsinfo
*info
, struct nfs4_secinfo_flavors
*flavors
)
6038 struct nfs4_exception exception
= { };
6041 err
= _nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
6044 case -NFS4ERR_WRONGSEC
:
6045 case -NFS4ERR_NOTSUPP
:
6048 err
= nfs4_handle_exception(server
, err
, &exception
);
6050 } while (exception
.retry
);
6055 nfs41_find_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
6056 struct nfs_fsinfo
*info
)
6060 rpc_authflavor_t flavor
;
6061 struct nfs4_secinfo_flavors
*flavors
;
6063 page
= alloc_page(GFP_KERNEL
);
6069 flavors
= page_address(page
);
6070 err
= nfs41_proc_secinfo_no_name(server
, fhandle
, info
, flavors
);
6073 * Fall back on "guess and check" method if
6074 * the server doesn't support SECINFO_NO_NAME
6076 if (err
== -NFS4ERR_WRONGSEC
|| err
== -NFS4ERR_NOTSUPP
) {
6077 err
= nfs4_find_root_sec(server
, fhandle
, info
);
6083 flavor
= nfs_find_best_sec(flavors
);
6085 err
= nfs4_lookup_root_sec(server
, fhandle
, info
, flavor
);
6094 static int _nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6097 struct nfs41_test_stateid_args args
= {
6098 .stateid
= &state
->stateid
,
6100 struct nfs41_test_stateid_res res
;
6101 struct rpc_message msg
= {
6102 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_TEST_STATEID
],
6106 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6107 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6111 static int nfs41_test_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6113 struct nfs4_exception exception
= { };
6116 err
= nfs4_handle_exception(server
,
6117 _nfs41_test_stateid(server
, state
),
6119 } while (exception
.retry
);
6123 static int _nfs4_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6126 struct nfs41_free_stateid_args args
= {
6127 .stateid
= &state
->stateid
,
6129 struct nfs41_free_stateid_res res
;
6130 struct rpc_message msg
= {
6131 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FREE_STATEID
],
6136 args
.seq_args
.sa_session
= res
.seq_res
.sr_session
= NULL
;
6137 status
= nfs4_call_sync_sequence(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0, 1);
6141 static int nfs41_free_stateid(struct nfs_server
*server
, struct nfs4_state
*state
)
6143 struct nfs4_exception exception
= { };
6146 err
= nfs4_handle_exception(server
,
6147 _nfs4_free_stateid(server
, state
),
6149 } while (exception
.retry
);
6152 #endif /* CONFIG_NFS_V4_1 */
6154 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
6155 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6156 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6157 .recover_open
= nfs4_open_reclaim
,
6158 .recover_lock
= nfs4_lock_reclaim
,
6159 .establish_clid
= nfs4_init_clientid
,
6160 .get_clid_cred
= nfs4_get_setclientid_cred
,
6163 #if defined(CONFIG_NFS_V4_1)
6164 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
6165 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
6166 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
6167 .recover_open
= nfs4_open_reclaim
,
6168 .recover_lock
= nfs4_lock_reclaim
,
6169 .establish_clid
= nfs41_init_clientid
,
6170 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6171 .reclaim_complete
= nfs41_proc_reclaim_complete
,
6173 #endif /* CONFIG_NFS_V4_1 */
6175 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
6176 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6177 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6178 .recover_open
= nfs4_open_expired
,
6179 .recover_lock
= nfs4_lock_expired
,
6180 .establish_clid
= nfs4_init_clientid
,
6181 .get_clid_cred
= nfs4_get_setclientid_cred
,
6184 #if defined(CONFIG_NFS_V4_1)
6185 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
6186 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
6187 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
6188 .recover_open
= nfs41_open_expired
,
6189 .recover_lock
= nfs41_lock_expired
,
6190 .establish_clid
= nfs41_init_clientid
,
6191 .get_clid_cred
= nfs4_get_exchange_id_cred
,
6193 #endif /* CONFIG_NFS_V4_1 */
6195 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
6196 .sched_state_renewal
= nfs4_proc_async_renew
,
6197 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
6198 .renew_lease
= nfs4_proc_renew
,
6201 #if defined(CONFIG_NFS_V4_1)
6202 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
6203 .sched_state_renewal
= nfs41_proc_async_sequence
,
6204 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
6205 .renew_lease
= nfs4_proc_sequence
,
6209 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
6211 .call_sync
= _nfs4_call_sync
,
6212 .validate_stateid
= nfs4_validate_delegation_stateid
,
6213 .find_root_sec
= nfs4_find_root_sec
,
6214 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
6215 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
6216 .state_renewal_ops
= &nfs40_state_renewal_ops
,
6219 #if defined(CONFIG_NFS_V4_1)
6220 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
6222 .call_sync
= _nfs4_call_sync_session
,
6223 .validate_stateid
= nfs41_validate_delegation_stateid
,
6224 .find_root_sec
= nfs41_find_root_sec
,
6225 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
6226 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
6227 .state_renewal_ops
= &nfs41_state_renewal_ops
,
6231 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
6232 [0] = &nfs_v4_0_minor_ops
,
6233 #if defined(CONFIG_NFS_V4_1)
6234 [1] = &nfs_v4_1_minor_ops
,
6238 static const struct inode_operations nfs4_file_inode_operations
= {
6239 .permission
= nfs_permission
,
6240 .getattr
= nfs_getattr
,
6241 .setattr
= nfs_setattr
,
6242 .getxattr
= generic_getxattr
,
6243 .setxattr
= generic_setxattr
,
6244 .listxattr
= generic_listxattr
,
6245 .removexattr
= generic_removexattr
,
6248 const struct nfs_rpc_ops nfs_v4_clientops
= {
6249 .version
= 4, /* protocol version */
6250 .dentry_ops
= &nfs4_dentry_operations
,
6251 .dir_inode_ops
= &nfs4_dir_inode_operations
,
6252 .file_inode_ops
= &nfs4_file_inode_operations
,
6253 .file_ops
= &nfs4_file_operations
,
6254 .getroot
= nfs4_proc_get_root
,
6255 .getattr
= nfs4_proc_getattr
,
6256 .setattr
= nfs4_proc_setattr
,
6257 .lookup
= nfs4_proc_lookup
,
6258 .access
= nfs4_proc_access
,
6259 .readlink
= nfs4_proc_readlink
,
6260 .create
= nfs4_proc_create
,
6261 .remove
= nfs4_proc_remove
,
6262 .unlink_setup
= nfs4_proc_unlink_setup
,
6263 .unlink_done
= nfs4_proc_unlink_done
,
6264 .rename
= nfs4_proc_rename
,
6265 .rename_setup
= nfs4_proc_rename_setup
,
6266 .rename_done
= nfs4_proc_rename_done
,
6267 .link
= nfs4_proc_link
,
6268 .symlink
= nfs4_proc_symlink
,
6269 .mkdir
= nfs4_proc_mkdir
,
6270 .rmdir
= nfs4_proc_remove
,
6271 .readdir
= nfs4_proc_readdir
,
6272 .mknod
= nfs4_proc_mknod
,
6273 .statfs
= nfs4_proc_statfs
,
6274 .fsinfo
= nfs4_proc_fsinfo
,
6275 .pathconf
= nfs4_proc_pathconf
,
6276 .set_capabilities
= nfs4_server_capabilities
,
6277 .decode_dirent
= nfs4_decode_dirent
,
6278 .read_setup
= nfs4_proc_read_setup
,
6279 .read_done
= nfs4_read_done
,
6280 .write_setup
= nfs4_proc_write_setup
,
6281 .write_done
= nfs4_write_done
,
6282 .commit_setup
= nfs4_proc_commit_setup
,
6283 .commit_done
= nfs4_commit_done
,
6284 .lock
= nfs4_proc_lock
,
6285 .clear_acl_cache
= nfs4_zap_acl_attr
,
6286 .close_context
= nfs4_close_context
,
6287 .open_context
= nfs4_atomic_open
,
6288 .init_client
= nfs4_init_client
,
6289 .secinfo
= nfs4_proc_secinfo
,
6292 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
6293 .prefix
= XATTR_NAME_NFSV4_ACL
,
6294 .list
= nfs4_xattr_list_nfs4_acl
,
6295 .get
= nfs4_xattr_get_nfs4_acl
,
6296 .set
= nfs4_xattr_set_nfs4_acl
,
6299 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
6300 &nfs4_xattr_nfs4_acl_handler
,