4 * Client-side procedure declarations for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <linux/delay.h>
40 #include <linux/errno.h>
41 #include <linux/string.h>
42 #include <linux/slab.h>
43 #include <linux/sunrpc/clnt.h>
44 #include <linux/sunrpc/gss_api.h>
45 #include <linux/nfs.h>
46 #include <linux/nfs4.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/nfs_page.h>
49 #include <linux/namei.h>
50 #include <linux/mount.h>
51 #include <linux/module.h>
52 #include <linux/sunrpc/bc_xprt.h>
53 #include <linux/xattr.h>
54 #include <linux/utsname.h>
57 #include "delegation.h"
63 #define NFSDBG_FACILITY NFSDBG_PROC
65 #define NFS4_POLL_RETRY_MIN (HZ/10)
66 #define NFS4_POLL_RETRY_MAX (15*HZ)
68 #define NFS4_MAX_LOOP_ON_RECOVER (10)
71 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
72 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
);
73 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
74 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
75 static int _nfs4_proc_lookup(struct rpc_clnt
*client
, struct inode
*dir
,
76 const struct qstr
*name
, struct nfs_fh
*fhandle
,
77 struct nfs_fattr
*fattr
);
78 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
79 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
80 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
81 struct nfs4_state
*state
);
83 /* Prevent leaks of NFSv4 errors into userland */
84 static int nfs4_map_errors(int err
)
89 case -NFS4ERR_RESOURCE
:
91 case -NFS4ERR_WRONGSEC
:
93 case -NFS4ERR_BADOWNER
:
94 case -NFS4ERR_BADNAME
:
97 dprintk("%s could not handle NFSv4 error %d\n",
105 * This is our standard bitmap for GETATTR requests.
107 const u32 nfs4_fattr_bitmap
[2] = {
109 | FATTR4_WORD0_CHANGE
112 | FATTR4_WORD0_FILEID
,
114 | FATTR4_WORD1_NUMLINKS
116 | FATTR4_WORD1_OWNER_GROUP
117 | FATTR4_WORD1_RAWDEV
118 | FATTR4_WORD1_SPACE_USED
119 | FATTR4_WORD1_TIME_ACCESS
120 | FATTR4_WORD1_TIME_METADATA
121 | FATTR4_WORD1_TIME_MODIFY
124 const u32 nfs4_statfs_bitmap
[2] = {
125 FATTR4_WORD0_FILES_AVAIL
126 | FATTR4_WORD0_FILES_FREE
127 | FATTR4_WORD0_FILES_TOTAL
,
128 FATTR4_WORD1_SPACE_AVAIL
129 | FATTR4_WORD1_SPACE_FREE
130 | FATTR4_WORD1_SPACE_TOTAL
133 const u32 nfs4_pathconf_bitmap
[2] = {
135 | FATTR4_WORD0_MAXNAME
,
139 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
140 | FATTR4_WORD0_MAXREAD
141 | FATTR4_WORD0_MAXWRITE
142 | FATTR4_WORD0_LEASE_TIME
,
143 FATTR4_WORD1_TIME_DELTA
144 | FATTR4_WORD1_FS_LAYOUT_TYPES
147 const u32 nfs4_fs_locations_bitmap
[2] = {
149 | FATTR4_WORD0_CHANGE
152 | FATTR4_WORD0_FILEID
153 | FATTR4_WORD0_FS_LOCATIONS
,
155 | FATTR4_WORD1_NUMLINKS
157 | FATTR4_WORD1_OWNER_GROUP
158 | FATTR4_WORD1_RAWDEV
159 | FATTR4_WORD1_SPACE_USED
160 | FATTR4_WORD1_TIME_ACCESS
161 | FATTR4_WORD1_TIME_METADATA
162 | FATTR4_WORD1_TIME_MODIFY
163 | FATTR4_WORD1_MOUNTED_ON_FILEID
166 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
167 struct nfs4_readdir_arg
*readdir
)
171 BUG_ON(readdir
->count
< 80);
173 readdir
->cookie
= cookie
;
174 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
179 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
184 * NFSv4 servers do not return entries for '.' and '..'
185 * Therefore, we fake these entries here. We let '.'
186 * have cookie 0 and '..' have cookie 1. Note that
187 * when talking to the server, we always send cookie 0
190 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
193 *p
++ = xdr_one
; /* next */
194 *p
++ = xdr_zero
; /* cookie, first word */
195 *p
++ = xdr_one
; /* cookie, second word */
196 *p
++ = xdr_one
; /* entry len */
197 memcpy(p
, ".\0\0\0", 4); /* entry */
199 *p
++ = xdr_one
; /* bitmap length */
200 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
201 *p
++ = htonl(8); /* attribute buffer length */
202 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
205 *p
++ = xdr_one
; /* next */
206 *p
++ = xdr_zero
; /* cookie, first word */
207 *p
++ = xdr_two
; /* cookie, second word */
208 *p
++ = xdr_two
; /* entry len */
209 memcpy(p
, "..\0\0", 4); /* entry */
211 *p
++ = xdr_one
; /* bitmap length */
212 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
213 *p
++ = htonl(8); /* attribute buffer length */
214 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
216 readdir
->pgbase
= (char *)p
- (char *)start
;
217 readdir
->count
-= readdir
->pgbase
;
218 kunmap_atomic(start
, KM_USER0
);
221 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
227 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
228 nfs_wait_bit_killable
, TASK_KILLABLE
);
232 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
239 *timeout
= NFS4_POLL_RETRY_MIN
;
240 if (*timeout
> NFS4_POLL_RETRY_MAX
)
241 *timeout
= NFS4_POLL_RETRY_MAX
;
242 schedule_timeout_killable(*timeout
);
243 if (fatal_signal_pending(current
))
249 /* This is the error handling routine for processes that are allowed
252 static int nfs4_handle_exception(struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
254 struct nfs_client
*clp
= server
->nfs_client
;
255 struct nfs4_state
*state
= exception
->state
;
258 exception
->retry
= 0;
262 case -NFS4ERR_ADMIN_REVOKED
:
263 case -NFS4ERR_BAD_STATEID
:
264 case -NFS4ERR_OPENMODE
:
267 nfs4_schedule_stateid_recovery(server
, state
);
268 goto wait_on_recovery
;
269 case -NFS4ERR_STALE_STATEID
:
270 case -NFS4ERR_STALE_CLIENTID
:
271 case -NFS4ERR_EXPIRED
:
272 nfs4_schedule_lease_recovery(clp
);
273 goto wait_on_recovery
;
274 #if defined(CONFIG_NFS_V4_1)
275 case -NFS4ERR_BADSESSION
:
276 case -NFS4ERR_BADSLOT
:
277 case -NFS4ERR_BAD_HIGH_SLOT
:
278 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
279 case -NFS4ERR_DEADSESSION
:
280 case -NFS4ERR_SEQ_FALSE_RETRY
:
281 case -NFS4ERR_SEQ_MISORDERED
:
282 dprintk("%s ERROR: %d Reset session\n", __func__
,
284 nfs4_schedule_session_recovery(clp
->cl_session
);
285 exception
->retry
= 1;
287 #endif /* defined(CONFIG_NFS_V4_1) */
288 case -NFS4ERR_FILE_OPEN
:
289 if (exception
->timeout
> HZ
) {
290 /* We have retried a decent amount, time to
299 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
302 case -NFS4ERR_OLD_STATEID
:
303 exception
->retry
= 1;
305 case -NFS4ERR_BADOWNER
:
306 /* The following works around a Linux server bug! */
307 case -NFS4ERR_BADNAME
:
308 if (server
->caps
& NFS_CAP_UIDGID_NOMAP
) {
309 server
->caps
&= ~NFS_CAP_UIDGID_NOMAP
;
310 exception
->retry
= 1;
311 printk(KERN_WARNING
"NFS: v4 server %s "
312 "does not accept raw "
314 "Reenabling the idmapper.\n",
315 server
->nfs_client
->cl_hostname
);
318 /* We failed to handle the error */
319 return nfs4_map_errors(ret
);
321 ret
= nfs4_wait_clnt_recover(clp
);
323 exception
->retry
= 1;
328 static void do_renew_lease(struct nfs_client
*clp
, unsigned long timestamp
)
330 spin_lock(&clp
->cl_lock
);
331 if (time_before(clp
->cl_last_renewal
,timestamp
))
332 clp
->cl_last_renewal
= timestamp
;
333 spin_unlock(&clp
->cl_lock
);
336 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
338 do_renew_lease(server
->nfs_client
, timestamp
);
341 #if defined(CONFIG_NFS_V4_1)
344 * nfs4_free_slot - free a slot and efficiently update slot table.
346 * freeing a slot is trivially done by clearing its respective bit
348 * If the freed slotid equals highest_used_slotid we want to update it
349 * so that the server would be able to size down the slot table if needed,
350 * otherwise we know that the highest_used_slotid is still in use.
351 * When updating highest_used_slotid there may be "holes" in the bitmap
352 * so we need to scan down from highest_used_slotid to 0 looking for the now
353 * highest slotid in use.
354 * If none found, highest_used_slotid is set to -1.
356 * Must be called while holding tbl->slot_tbl_lock
359 nfs4_free_slot(struct nfs4_slot_table
*tbl
, struct nfs4_slot
*free_slot
)
361 int free_slotid
= free_slot
- tbl
->slots
;
362 int slotid
= free_slotid
;
364 BUG_ON(slotid
< 0 || slotid
>= NFS4_MAX_SLOT_TABLE
);
365 /* clear used bit in bitmap */
366 __clear_bit(slotid
, tbl
->used_slots
);
368 /* update highest_used_slotid when it is freed */
369 if (slotid
== tbl
->highest_used_slotid
) {
370 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
371 if (slotid
< tbl
->max_slots
)
372 tbl
->highest_used_slotid
= slotid
;
374 tbl
->highest_used_slotid
= -1;
376 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
377 free_slotid
, tbl
->highest_used_slotid
);
381 * Signal state manager thread if session fore channel is drained
383 static void nfs4_check_drain_fc_complete(struct nfs4_session
*ses
)
385 struct rpc_task
*task
;
387 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
)) {
388 task
= rpc_wake_up_next(&ses
->fc_slot_table
.slot_tbl_waitq
);
390 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
394 if (ses
->fc_slot_table
.highest_used_slotid
!= -1)
397 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__
);
398 complete(&ses
->fc_slot_table
.complete
);
402 * Signal state manager thread if session back channel is drained
404 void nfs4_check_drain_bc_complete(struct nfs4_session
*ses
)
406 if (!test_bit(NFS4_SESSION_DRAINING
, &ses
->session_state
) ||
407 ses
->bc_slot_table
.highest_used_slotid
!= -1)
409 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__
);
410 complete(&ses
->bc_slot_table
.complete
);
413 static void nfs41_sequence_free_slot(struct nfs4_sequence_res
*res
)
415 struct nfs4_slot_table
*tbl
;
417 tbl
= &res
->sr_session
->fc_slot_table
;
419 /* just wake up the next guy waiting since
420 * we may have not consumed a slot after all */
421 dprintk("%s: No slot\n", __func__
);
425 spin_lock(&tbl
->slot_tbl_lock
);
426 nfs4_free_slot(tbl
, res
->sr_slot
);
427 nfs4_check_drain_fc_complete(res
->sr_session
);
428 spin_unlock(&tbl
->slot_tbl_lock
);
432 static int nfs41_sequence_done(struct rpc_task
*task
, struct nfs4_sequence_res
*res
)
434 unsigned long timestamp
;
435 struct nfs_client
*clp
;
438 * sr_status remains 1 if an RPC level error occurred. The server
439 * may or may not have processed the sequence operation..
440 * Proceed as if the server received and processed the sequence
443 if (res
->sr_status
== 1)
444 res
->sr_status
= NFS_OK
;
446 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
450 /* Check the SEQUENCE operation status */
451 switch (res
->sr_status
) {
453 /* Update the slot's sequence and clientid lease timer */
454 ++res
->sr_slot
->seq_nr
;
455 timestamp
= res
->sr_renewal_time
;
456 clp
= res
->sr_session
->clp
;
457 do_renew_lease(clp
, timestamp
);
458 /* Check sequence flags */
459 if (res
->sr_status_flags
!= 0)
460 nfs4_schedule_lease_recovery(clp
);
463 /* The server detected a resend of the RPC call and
464 * returned NFS4ERR_DELAY as per Section 2.10.6.2
467 dprintk("%s: slot=%td seq=%d: Operation in progress\n",
469 res
->sr_slot
- res
->sr_session
->fc_slot_table
.slots
,
470 res
->sr_slot
->seq_nr
);
473 /* Just update the slot sequence no. */
474 ++res
->sr_slot
->seq_nr
;
477 /* The session may be reset by one of the error handlers. */
478 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
479 nfs41_sequence_free_slot(res
);
482 if (!rpc_restart_call(task
))
484 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
488 static int nfs4_sequence_done(struct rpc_task
*task
,
489 struct nfs4_sequence_res
*res
)
491 if (res
->sr_session
== NULL
)
493 return nfs41_sequence_done(task
, res
);
497 * nfs4_find_slot - efficiently look for a free slot
499 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
500 * If found, we mark the slot as used, update the highest_used_slotid,
501 * and respectively set up the sequence operation args.
502 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
504 * Note: must be called with under the slot_tbl_lock.
507 nfs4_find_slot(struct nfs4_slot_table
*tbl
)
510 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
511 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
513 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
514 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
516 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
517 if (slotid
>= tbl
->max_slots
)
519 __set_bit(slotid
, tbl
->used_slots
);
520 if (slotid
> tbl
->highest_used_slotid
)
521 tbl
->highest_used_slotid
= slotid
;
524 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
525 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
529 int nfs41_setup_sequence(struct nfs4_session
*session
,
530 struct nfs4_sequence_args
*args
,
531 struct nfs4_sequence_res
*res
,
533 struct rpc_task
*task
)
535 struct nfs4_slot
*slot
;
536 struct nfs4_slot_table
*tbl
;
539 dprintk("--> %s\n", __func__
);
540 /* slot already allocated? */
541 if (res
->sr_slot
!= NULL
)
544 tbl
= &session
->fc_slot_table
;
546 spin_lock(&tbl
->slot_tbl_lock
);
547 if (test_bit(NFS4_SESSION_DRAINING
, &session
->session_state
) &&
548 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
550 * The state manager will wait until the slot table is empty.
551 * Schedule the reset thread
553 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
554 spin_unlock(&tbl
->slot_tbl_lock
);
555 dprintk("%s Schedule Session Reset\n", __func__
);
559 if (!rpc_queue_empty(&tbl
->slot_tbl_waitq
) &&
560 !rpc_task_has_priority(task
, RPC_PRIORITY_PRIVILEGED
)) {
561 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
562 spin_unlock(&tbl
->slot_tbl_lock
);
563 dprintk("%s enforce FIFO order\n", __func__
);
567 slotid
= nfs4_find_slot(tbl
);
568 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
569 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
570 spin_unlock(&tbl
->slot_tbl_lock
);
571 dprintk("<-- %s: no free slots\n", __func__
);
574 spin_unlock(&tbl
->slot_tbl_lock
);
576 rpc_task_set_priority(task
, RPC_PRIORITY_NORMAL
);
577 slot
= tbl
->slots
+ slotid
;
578 args
->sa_session
= session
;
579 args
->sa_slotid
= slotid
;
580 args
->sa_cache_this
= cache_reply
;
582 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
584 res
->sr_session
= session
;
586 res
->sr_renewal_time
= jiffies
;
587 res
->sr_status_flags
= 0;
589 * sr_status is only set in decode_sequence, and so will remain
590 * set to 1 if an rpc level failure occurs.
595 EXPORT_SYMBOL_GPL(nfs41_setup_sequence
);
597 int nfs4_setup_sequence(const struct nfs_server
*server
,
598 struct nfs4_sequence_args
*args
,
599 struct nfs4_sequence_res
*res
,
601 struct rpc_task
*task
)
603 struct nfs4_session
*session
= nfs4_get_session(server
);
606 if (session
== NULL
) {
607 args
->sa_session
= NULL
;
608 res
->sr_session
= NULL
;
612 dprintk("--> %s clp %p session %p sr_slot %td\n",
613 __func__
, session
->clp
, session
, res
->sr_slot
?
614 res
->sr_slot
- session
->fc_slot_table
.slots
: -1);
616 ret
= nfs41_setup_sequence(session
, args
, res
, cache_reply
,
619 dprintk("<-- %s status=%d\n", __func__
, ret
);
623 struct nfs41_call_sync_data
{
624 const struct nfs_server
*seq_server
;
625 struct nfs4_sequence_args
*seq_args
;
626 struct nfs4_sequence_res
*seq_res
;
630 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
632 struct nfs41_call_sync_data
*data
= calldata
;
634 dprintk("--> %s data->seq_server %p\n", __func__
, data
->seq_server
);
636 if (nfs4_setup_sequence(data
->seq_server
, data
->seq_args
,
637 data
->seq_res
, data
->cache_reply
, task
))
639 rpc_call_start(task
);
642 static void nfs41_call_priv_sync_prepare(struct rpc_task
*task
, void *calldata
)
644 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
645 nfs41_call_sync_prepare(task
, calldata
);
648 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
650 struct nfs41_call_sync_data
*data
= calldata
;
652 nfs41_sequence_done(task
, data
->seq_res
);
655 struct rpc_call_ops nfs41_call_sync_ops
= {
656 .rpc_call_prepare
= nfs41_call_sync_prepare
,
657 .rpc_call_done
= nfs41_call_sync_done
,
660 struct rpc_call_ops nfs41_call_priv_sync_ops
= {
661 .rpc_call_prepare
= nfs41_call_priv_sync_prepare
,
662 .rpc_call_done
= nfs41_call_sync_done
,
665 static int nfs4_call_sync_sequence(struct rpc_clnt
*clnt
,
666 struct nfs_server
*server
,
667 struct rpc_message
*msg
,
668 struct nfs4_sequence_args
*args
,
669 struct nfs4_sequence_res
*res
,
674 struct rpc_task
*task
;
675 struct nfs41_call_sync_data data
= {
676 .seq_server
= server
,
679 .cache_reply
= cache_reply
,
681 struct rpc_task_setup task_setup
= {
684 .callback_ops
= &nfs41_call_sync_ops
,
685 .callback_data
= &data
690 task_setup
.callback_ops
= &nfs41_call_priv_sync_ops
;
691 task
= rpc_run_task(&task_setup
);
695 ret
= task
->tk_status
;
701 int _nfs4_call_sync_session(struct rpc_clnt
*clnt
,
702 struct nfs_server
*server
,
703 struct rpc_message
*msg
,
704 struct nfs4_sequence_args
*args
,
705 struct nfs4_sequence_res
*res
,
708 return nfs4_call_sync_sequence(clnt
, server
, msg
, args
, res
, cache_reply
, 0);
712 static int nfs4_sequence_done(struct rpc_task
*task
,
713 struct nfs4_sequence_res
*res
)
717 #endif /* CONFIG_NFS_V4_1 */
719 int _nfs4_call_sync(struct rpc_clnt
*clnt
,
720 struct nfs_server
*server
,
721 struct rpc_message
*msg
,
722 struct nfs4_sequence_args
*args
,
723 struct nfs4_sequence_res
*res
,
726 args
->sa_session
= res
->sr_session
= NULL
;
727 return rpc_call_sync(clnt
, msg
, 0);
731 int nfs4_call_sync(struct rpc_clnt
*clnt
,
732 struct nfs_server
*server
,
733 struct rpc_message
*msg
,
734 struct nfs4_sequence_args
*args
,
735 struct nfs4_sequence_res
*res
,
738 return server
->nfs_client
->cl_mvops
->call_sync(clnt
, server
, msg
,
739 args
, res
, cache_reply
);
742 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
744 struct nfs_inode
*nfsi
= NFS_I(dir
);
746 spin_lock(&dir
->i_lock
);
747 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
748 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
749 nfs_force_lookup_revalidate(dir
);
750 nfsi
->change_attr
= cinfo
->after
;
751 spin_unlock(&dir
->i_lock
);
754 struct nfs4_opendata
{
756 struct nfs_openargs o_arg
;
757 struct nfs_openres o_res
;
758 struct nfs_open_confirmargs c_arg
;
759 struct nfs_open_confirmres c_res
;
760 struct nfs_fattr f_attr
;
761 struct nfs_fattr dir_attr
;
764 struct nfs4_state_owner
*owner
;
765 struct nfs4_state
*state
;
767 unsigned long timestamp
;
768 unsigned int rpc_done
: 1;
774 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
776 p
->o_res
.f_attr
= &p
->f_attr
;
777 p
->o_res
.dir_attr
= &p
->dir_attr
;
778 p
->o_res
.seqid
= p
->o_arg
.seqid
;
779 p
->c_res
.seqid
= p
->c_arg
.seqid
;
780 p
->o_res
.server
= p
->o_arg
.server
;
781 nfs_fattr_init(&p
->f_attr
);
782 nfs_fattr_init(&p
->dir_attr
);
785 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
786 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
787 const struct iattr
*attrs
,
790 struct dentry
*parent
= dget_parent(path
->dentry
);
791 struct inode
*dir
= parent
->d_inode
;
792 struct nfs_server
*server
= NFS_SERVER(dir
);
793 struct nfs4_opendata
*p
;
795 p
= kzalloc(sizeof(*p
), gfp_mask
);
798 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
, gfp_mask
);
799 if (p
->o_arg
.seqid
== NULL
)
805 atomic_inc(&sp
->so_count
);
806 p
->o_arg
.fh
= NFS_FH(dir
);
807 p
->o_arg
.open_flags
= flags
;
808 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
809 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
810 p
->o_arg
.id
= sp
->so_owner_id
.id
;
811 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
812 p
->o_arg
.server
= server
;
813 p
->o_arg
.bitmask
= server
->attr_bitmask
;
814 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
815 if (flags
& O_CREAT
) {
818 p
->o_arg
.u
.attrs
= &p
->attrs
;
819 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
820 s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
824 p
->c_arg
.fh
= &p
->o_res
.fh
;
825 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
826 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
827 nfs4_init_opendata_res(p
);
837 static void nfs4_opendata_free(struct kref
*kref
)
839 struct nfs4_opendata
*p
= container_of(kref
,
840 struct nfs4_opendata
, kref
);
842 nfs_free_seqid(p
->o_arg
.seqid
);
843 if (p
->state
!= NULL
)
844 nfs4_put_open_state(p
->state
);
845 nfs4_put_state_owner(p
->owner
);
851 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
854 kref_put(&p
->kref
, nfs4_opendata_free
);
857 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
861 ret
= rpc_wait_for_completion_task(task
);
865 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
869 if (open_mode
& O_EXCL
)
871 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
873 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0
874 && state
->n_rdonly
!= 0;
877 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0
878 && state
->n_wronly
!= 0;
880 case FMODE_READ
|FMODE_WRITE
:
881 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0
882 && state
->n_rdwr
!= 0;
888 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
890 if ((delegation
->type
& fmode
) != fmode
)
892 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
894 nfs_mark_delegation_referenced(delegation
);
898 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
907 case FMODE_READ
|FMODE_WRITE
:
910 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
913 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
915 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
916 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
917 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
920 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
923 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
925 case FMODE_READ
|FMODE_WRITE
:
926 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
930 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
932 write_seqlock(&state
->seqlock
);
933 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
934 write_sequnlock(&state
->seqlock
);
937 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
940 * Protect the call to nfs4_state_set_mode_locked and
941 * serialise the stateid update
943 write_seqlock(&state
->seqlock
);
944 if (deleg_stateid
!= NULL
) {
945 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
946 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
948 if (open_stateid
!= NULL
)
949 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
950 write_sequnlock(&state
->seqlock
);
951 spin_lock(&state
->owner
->so_lock
);
952 update_open_stateflags(state
, fmode
);
953 spin_unlock(&state
->owner
->so_lock
);
956 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
958 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
959 struct nfs_delegation
*deleg_cur
;
962 fmode
&= (FMODE_READ
|FMODE_WRITE
);
965 deleg_cur
= rcu_dereference(nfsi
->delegation
);
966 if (deleg_cur
== NULL
)
969 spin_lock(&deleg_cur
->lock
);
970 if (nfsi
->delegation
!= deleg_cur
||
971 (deleg_cur
->type
& fmode
) != fmode
)
972 goto no_delegation_unlock
;
974 if (delegation
== NULL
)
975 delegation
= &deleg_cur
->stateid
;
976 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
977 goto no_delegation_unlock
;
979 nfs_mark_delegation_referenced(deleg_cur
);
980 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
982 no_delegation_unlock
:
983 spin_unlock(&deleg_cur
->lock
);
987 if (!ret
&& open_stateid
!= NULL
) {
988 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
996 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
998 struct nfs_delegation
*delegation
;
1001 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1002 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
1007 nfs_inode_return_delegation(inode
);
1010 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
1012 struct nfs4_state
*state
= opendata
->state
;
1013 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1014 struct nfs_delegation
*delegation
;
1015 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
1016 fmode_t fmode
= opendata
->o_arg
.fmode
;
1017 nfs4_stateid stateid
;
1021 if (can_open_cached(state
, fmode
, open_mode
)) {
1022 spin_lock(&state
->owner
->so_lock
);
1023 if (can_open_cached(state
, fmode
, open_mode
)) {
1024 update_open_stateflags(state
, fmode
);
1025 spin_unlock(&state
->owner
->so_lock
);
1026 goto out_return_state
;
1028 spin_unlock(&state
->owner
->so_lock
);
1031 delegation
= rcu_dereference(nfsi
->delegation
);
1032 if (delegation
== NULL
||
1033 !can_open_delegated(delegation
, fmode
)) {
1037 /* Save the delegation */
1038 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
1040 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
1045 /* Try to update the stateid using the delegation */
1046 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
1047 goto out_return_state
;
1050 return ERR_PTR(ret
);
1052 atomic_inc(&state
->count
);
1056 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
1058 struct inode
*inode
;
1059 struct nfs4_state
*state
= NULL
;
1060 struct nfs_delegation
*delegation
;
1063 if (!data
->rpc_done
) {
1064 state
= nfs4_try_open_cached(data
);
1069 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
1071 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
1072 ret
= PTR_ERR(inode
);
1076 state
= nfs4_get_open_state(inode
, data
->owner
);
1079 if (data
->o_res
.delegation_type
!= 0) {
1080 int delegation_flags
= 0;
1083 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
1085 delegation_flags
= delegation
->flags
;
1087 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
1088 nfs_inode_set_delegation(state
->inode
,
1089 data
->owner
->so_cred
,
1092 nfs_inode_reclaim_delegation(state
->inode
,
1093 data
->owner
->so_cred
,
1097 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1105 return ERR_PTR(ret
);
1108 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1110 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1111 struct nfs_open_context
*ctx
;
1113 spin_lock(&state
->inode
->i_lock
);
1114 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1115 if (ctx
->state
!= state
)
1117 get_nfs_open_context(ctx
);
1118 spin_unlock(&state
->inode
->i_lock
);
1121 spin_unlock(&state
->inode
->i_lock
);
1122 return ERR_PTR(-ENOENT
);
1125 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1127 struct nfs4_opendata
*opendata
;
1129 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
, GFP_NOFS
);
1130 if (opendata
== NULL
)
1131 return ERR_PTR(-ENOMEM
);
1132 opendata
->state
= state
;
1133 atomic_inc(&state
->count
);
1137 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1139 struct nfs4_state
*newstate
;
1142 opendata
->o_arg
.open_flags
= 0;
1143 opendata
->o_arg
.fmode
= fmode
;
1144 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1145 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1146 nfs4_init_opendata_res(opendata
);
1147 ret
= _nfs4_recover_proc_open(opendata
);
1150 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1151 if (IS_ERR(newstate
))
1152 return PTR_ERR(newstate
);
1153 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1158 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1160 struct nfs4_state
*newstate
;
1163 /* memory barrier prior to reading state->n_* */
1164 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1166 if (state
->n_rdwr
!= 0) {
1167 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1168 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1171 if (newstate
!= state
)
1174 if (state
->n_wronly
!= 0) {
1175 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1176 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1179 if (newstate
!= state
)
1182 if (state
->n_rdonly
!= 0) {
1183 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1184 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1187 if (newstate
!= state
)
1191 * We may have performed cached opens for all three recoveries.
1192 * Check if we need to update the current stateid.
1194 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1195 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1196 write_seqlock(&state
->seqlock
);
1197 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1198 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1199 write_sequnlock(&state
->seqlock
);
1206 * reclaim state on the server after a reboot.
1208 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1210 struct nfs_delegation
*delegation
;
1211 struct nfs4_opendata
*opendata
;
1212 fmode_t delegation_type
= 0;
1215 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1216 if (IS_ERR(opendata
))
1217 return PTR_ERR(opendata
);
1218 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1219 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1221 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1222 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1223 delegation_type
= delegation
->type
;
1225 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1226 status
= nfs4_open_recover(opendata
, state
);
1227 nfs4_opendata_put(opendata
);
1231 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1233 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1234 struct nfs4_exception exception
= { };
1237 err
= _nfs4_do_open_reclaim(ctx
, state
);
1238 if (err
!= -NFS4ERR_DELAY
)
1240 nfs4_handle_exception(server
, err
, &exception
);
1241 } while (exception
.retry
);
1245 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1247 struct nfs_open_context
*ctx
;
1250 ctx
= nfs4_state_find_open_context(state
);
1252 return PTR_ERR(ctx
);
1253 ret
= nfs4_do_open_reclaim(ctx
, state
);
1254 put_nfs_open_context(ctx
);
1258 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1260 struct nfs4_opendata
*opendata
;
1263 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1264 if (IS_ERR(opendata
))
1265 return PTR_ERR(opendata
);
1266 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1267 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1268 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1269 ret
= nfs4_open_recover(opendata
, state
);
1270 nfs4_opendata_put(opendata
);
1274 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1276 struct nfs4_exception exception
= { };
1277 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1280 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1286 case -NFS4ERR_BADSESSION
:
1287 case -NFS4ERR_BADSLOT
:
1288 case -NFS4ERR_BAD_HIGH_SLOT
:
1289 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1290 case -NFS4ERR_DEADSESSION
:
1291 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
1293 case -NFS4ERR_STALE_CLIENTID
:
1294 case -NFS4ERR_STALE_STATEID
:
1295 case -NFS4ERR_EXPIRED
:
1296 /* Don't recall a delegation if it was lost */
1297 nfs4_schedule_lease_recovery(server
->nfs_client
);
1301 * The show must go on: exit, but mark the
1302 * stateid as needing recovery.
1304 case -NFS4ERR_ADMIN_REVOKED
:
1305 case -NFS4ERR_BAD_STATEID
:
1306 nfs4_schedule_stateid_recovery(server
, state
);
1309 * User RPCSEC_GSS context has expired.
1310 * We cannot recover this stateid now, so
1311 * skip it and allow recovery thread to
1318 err
= nfs4_handle_exception(server
, err
, &exception
);
1319 } while (exception
.retry
);
1324 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1326 struct nfs4_opendata
*data
= calldata
;
1328 data
->rpc_status
= task
->tk_status
;
1329 if (data
->rpc_status
== 0) {
1330 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1331 sizeof(data
->o_res
.stateid
.data
));
1332 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1333 renew_lease(data
->o_res
.server
, data
->timestamp
);
1338 static void nfs4_open_confirm_release(void *calldata
)
1340 struct nfs4_opendata
*data
= calldata
;
1341 struct nfs4_state
*state
= NULL
;
1343 /* If this request hasn't been cancelled, do nothing */
1344 if (data
->cancelled
== 0)
1346 /* In case of error, no cleanup! */
1347 if (!data
->rpc_done
)
1349 state
= nfs4_opendata_to_nfs4_state(data
);
1351 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1353 nfs4_opendata_put(data
);
1356 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1357 .rpc_call_done
= nfs4_open_confirm_done
,
1358 .rpc_release
= nfs4_open_confirm_release
,
1362 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1364 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1366 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1367 struct rpc_task
*task
;
1368 struct rpc_message msg
= {
1369 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1370 .rpc_argp
= &data
->c_arg
,
1371 .rpc_resp
= &data
->c_res
,
1372 .rpc_cred
= data
->owner
->so_cred
,
1374 struct rpc_task_setup task_setup_data
= {
1375 .rpc_client
= server
->client
,
1376 .rpc_message
= &msg
,
1377 .callback_ops
= &nfs4_open_confirm_ops
,
1378 .callback_data
= data
,
1379 .workqueue
= nfsiod_workqueue
,
1380 .flags
= RPC_TASK_ASYNC
,
1384 kref_get(&data
->kref
);
1386 data
->rpc_status
= 0;
1387 data
->timestamp
= jiffies
;
1388 task
= rpc_run_task(&task_setup_data
);
1390 return PTR_ERR(task
);
1391 status
= nfs4_wait_for_completion_rpc_task(task
);
1393 data
->cancelled
= 1;
1396 status
= data
->rpc_status
;
1401 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1403 struct nfs4_opendata
*data
= calldata
;
1404 struct nfs4_state_owner
*sp
= data
->owner
;
1406 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1409 * Check if we still need to send an OPEN call, or if we can use
1410 * a delegation instead.
1412 if (data
->state
!= NULL
) {
1413 struct nfs_delegation
*delegation
;
1415 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1418 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1419 if (delegation
!= NULL
&&
1420 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1426 /* Update sequence id. */
1427 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1428 data
->o_arg
.clientid
= sp
->so_server
->nfs_client
->cl_clientid
;
1429 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1430 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1431 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1433 data
->timestamp
= jiffies
;
1434 if (nfs4_setup_sequence(data
->o_arg
.server
,
1435 &data
->o_arg
.seq_args
,
1436 &data
->o_res
.seq_res
, 1, task
))
1438 rpc_call_start(task
);
1441 task
->tk_action
= NULL
;
1445 static void nfs4_recover_open_prepare(struct rpc_task
*task
, void *calldata
)
1447 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
1448 nfs4_open_prepare(task
, calldata
);
1451 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1453 struct nfs4_opendata
*data
= calldata
;
1455 data
->rpc_status
= task
->tk_status
;
1457 if (!nfs4_sequence_done(task
, &data
->o_res
.seq_res
))
1460 if (task
->tk_status
== 0) {
1461 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1465 data
->rpc_status
= -ELOOP
;
1468 data
->rpc_status
= -EISDIR
;
1471 data
->rpc_status
= -ENOTDIR
;
1473 renew_lease(data
->o_res
.server
, data
->timestamp
);
1474 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1475 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1480 static void nfs4_open_release(void *calldata
)
1482 struct nfs4_opendata
*data
= calldata
;
1483 struct nfs4_state
*state
= NULL
;
1485 /* If this request hasn't been cancelled, do nothing */
1486 if (data
->cancelled
== 0)
1488 /* In case of error, no cleanup! */
1489 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1491 /* In case we need an open_confirm, no cleanup! */
1492 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1494 state
= nfs4_opendata_to_nfs4_state(data
);
1496 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1498 nfs4_opendata_put(data
);
1501 static const struct rpc_call_ops nfs4_open_ops
= {
1502 .rpc_call_prepare
= nfs4_open_prepare
,
1503 .rpc_call_done
= nfs4_open_done
,
1504 .rpc_release
= nfs4_open_release
,
1507 static const struct rpc_call_ops nfs4_recover_open_ops
= {
1508 .rpc_call_prepare
= nfs4_recover_open_prepare
,
1509 .rpc_call_done
= nfs4_open_done
,
1510 .rpc_release
= nfs4_open_release
,
1513 static int nfs4_run_open_task(struct nfs4_opendata
*data
, int isrecover
)
1515 struct inode
*dir
= data
->dir
->d_inode
;
1516 struct nfs_server
*server
= NFS_SERVER(dir
);
1517 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1518 struct nfs_openres
*o_res
= &data
->o_res
;
1519 struct rpc_task
*task
;
1520 struct rpc_message msg
= {
1521 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1524 .rpc_cred
= data
->owner
->so_cred
,
1526 struct rpc_task_setup task_setup_data
= {
1527 .rpc_client
= server
->client
,
1528 .rpc_message
= &msg
,
1529 .callback_ops
= &nfs4_open_ops
,
1530 .callback_data
= data
,
1531 .workqueue
= nfsiod_workqueue
,
1532 .flags
= RPC_TASK_ASYNC
,
1536 kref_get(&data
->kref
);
1538 data
->rpc_status
= 0;
1539 data
->cancelled
= 0;
1541 task_setup_data
.callback_ops
= &nfs4_recover_open_ops
;
1542 task
= rpc_run_task(&task_setup_data
);
1544 return PTR_ERR(task
);
1545 status
= nfs4_wait_for_completion_rpc_task(task
);
1547 data
->cancelled
= 1;
1550 status
= data
->rpc_status
;
1556 static int _nfs4_recover_proc_open(struct nfs4_opendata
*data
)
1558 struct inode
*dir
= data
->dir
->d_inode
;
1559 struct nfs_openres
*o_res
= &data
->o_res
;
1562 status
= nfs4_run_open_task(data
, 1);
1563 if (status
!= 0 || !data
->rpc_done
)
1566 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1568 if (o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1569 status
= _nfs4_proc_open_confirm(data
);
1578 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1580 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1582 struct inode
*dir
= data
->dir
->d_inode
;
1583 struct nfs_server
*server
= NFS_SERVER(dir
);
1584 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1585 struct nfs_openres
*o_res
= &data
->o_res
;
1588 status
= nfs4_run_open_task(data
, 0);
1589 if (status
!= 0 || !data
->rpc_done
)
1592 if (o_arg
->open_flags
& O_CREAT
) {
1593 update_changeattr(dir
, &o_res
->cinfo
);
1594 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1596 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1597 if ((o_res
->rflags
& NFS4_OPEN_RESULT_LOCKTYPE_POSIX
) == 0)
1598 server
->caps
&= ~NFS_CAP_POSIX_LOCK
;
1599 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1600 status
= _nfs4_proc_open_confirm(data
);
1604 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1605 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1609 static int nfs4_client_recover_expired_lease(struct nfs_client
*clp
)
1614 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1615 ret
= nfs4_wait_clnt_recover(clp
);
1618 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1619 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1621 nfs4_schedule_state_manager(clp
);
1627 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1629 return nfs4_client_recover_expired_lease(server
->nfs_client
);
1634 * reclaim state on the server after a network partition.
1635 * Assumes caller holds the appropriate lock
1637 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1639 struct nfs4_opendata
*opendata
;
1642 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1643 if (IS_ERR(opendata
))
1644 return PTR_ERR(opendata
);
1645 ret
= nfs4_open_recover(opendata
, state
);
1647 d_drop(ctx
->path
.dentry
);
1648 nfs4_opendata_put(opendata
);
1652 static int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1654 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1655 struct nfs4_exception exception
= { };
1659 err
= _nfs4_open_expired(ctx
, state
);
1663 case -NFS4ERR_GRACE
:
1664 case -NFS4ERR_DELAY
:
1665 nfs4_handle_exception(server
, err
, &exception
);
1668 } while (exception
.retry
);
1673 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1675 struct nfs_open_context
*ctx
;
1678 ctx
= nfs4_state_find_open_context(state
);
1680 return PTR_ERR(ctx
);
1681 ret
= nfs4_do_open_expired(ctx
, state
);
1682 put_nfs_open_context(ctx
);
1687 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1688 * fields corresponding to attributes that were used to store the verifier.
1689 * Make sure we clobber those fields in the later setattr call
1691 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1693 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1694 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1695 sattr
->ia_valid
|= ATTR_ATIME
;
1697 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1698 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1699 sattr
->ia_valid
|= ATTR_MTIME
;
1703 * Returns a referenced nfs4_state
1705 static int _nfs4_do_open(struct inode
*dir
, struct path
*path
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
, struct nfs4_state
**res
)
1707 struct nfs4_state_owner
*sp
;
1708 struct nfs4_state
*state
= NULL
;
1709 struct nfs_server
*server
= NFS_SERVER(dir
);
1710 struct nfs4_opendata
*opendata
;
1713 /* Protect against reboot recovery conflicts */
1715 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1716 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1719 status
= nfs4_recover_expired_lease(server
);
1721 goto err_put_state_owner
;
1722 if (path
->dentry
->d_inode
!= NULL
)
1723 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1725 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
, GFP_KERNEL
);
1726 if (opendata
== NULL
)
1727 goto err_put_state_owner
;
1729 if (path
->dentry
->d_inode
!= NULL
)
1730 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1732 status
= _nfs4_proc_open(opendata
);
1734 goto err_opendata_put
;
1736 state
= nfs4_opendata_to_nfs4_state(opendata
);
1737 status
= PTR_ERR(state
);
1739 goto err_opendata_put
;
1740 if (server
->caps
& NFS_CAP_POSIX_LOCK
)
1741 set_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
);
1743 if (opendata
->o_arg
.open_flags
& O_EXCL
) {
1744 nfs4_exclusive_attrset(opendata
, sattr
);
1746 nfs_fattr_init(opendata
->o_res
.f_attr
);
1747 status
= nfs4_do_setattr(state
->inode
, cred
,
1748 opendata
->o_res
.f_attr
, sattr
,
1751 nfs_setattr_update_inode(state
->inode
, sattr
);
1752 nfs_post_op_update_inode(state
->inode
, opendata
->o_res
.f_attr
);
1754 nfs4_opendata_put(opendata
);
1755 nfs4_put_state_owner(sp
);
1759 nfs4_opendata_put(opendata
);
1760 err_put_state_owner
:
1761 nfs4_put_state_owner(sp
);
1768 static struct nfs4_state
*nfs4_do_open(struct inode
*dir
, struct path
*path
, fmode_t fmode
, int flags
, struct iattr
*sattr
, struct rpc_cred
*cred
)
1770 struct nfs4_exception exception
= { };
1771 struct nfs4_state
*res
;
1775 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1778 /* NOTE: BAD_SEQID means the server and client disagree about the
1779 * book-keeping w.r.t. state-changing operations
1780 * (OPEN/CLOSE/LOCK/LOCKU...)
1781 * It is actually a sign of a bug on the client or on the server.
1783 * If we receive a BAD_SEQID error in the particular case of
1784 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1785 * have unhashed the old state_owner for us, and that we can
1786 * therefore safely retry using a new one. We should still warn
1787 * the user though...
1789 if (status
== -NFS4ERR_BAD_SEQID
) {
1790 printk(KERN_WARNING
"NFS: v4 server %s "
1791 " returned a bad sequence-id error!\n",
1792 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1793 exception
.retry
= 1;
1797 * BAD_STATEID on OPEN means that the server cancelled our
1798 * state before it received the OPEN_CONFIRM.
1799 * Recover by retrying the request as per the discussion
1800 * on Page 181 of RFC3530.
1802 if (status
== -NFS4ERR_BAD_STATEID
) {
1803 exception
.retry
= 1;
1806 if (status
== -EAGAIN
) {
1807 /* We must have found a delegation */
1808 exception
.retry
= 1;
1811 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1812 status
, &exception
));
1813 } while (exception
.retry
);
1817 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1818 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1819 struct nfs4_state
*state
)
1821 struct nfs_server
*server
= NFS_SERVER(inode
);
1822 struct nfs_setattrargs arg
= {
1823 .fh
= NFS_FH(inode
),
1826 .bitmask
= server
->attr_bitmask
,
1828 struct nfs_setattrres res
= {
1832 struct rpc_message msg
= {
1833 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1838 unsigned long timestamp
= jiffies
;
1841 nfs_fattr_init(fattr
);
1843 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1844 /* Use that stateid */
1845 } else if (state
!= NULL
) {
1846 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
, current
->tgid
);
1848 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1850 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
1851 if (status
== 0 && state
!= NULL
)
1852 renew_lease(server
, timestamp
);
1856 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1857 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1858 struct nfs4_state
*state
)
1860 struct nfs_server
*server
= NFS_SERVER(inode
);
1861 struct nfs4_exception exception
= { };
1864 err
= nfs4_handle_exception(server
,
1865 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1867 } while (exception
.retry
);
1871 struct nfs4_closedata
{
1873 struct inode
*inode
;
1874 struct nfs4_state
*state
;
1875 struct nfs_closeargs arg
;
1876 struct nfs_closeres res
;
1877 struct nfs_fattr fattr
;
1878 unsigned long timestamp
;
1883 static void nfs4_free_closedata(void *data
)
1885 struct nfs4_closedata
*calldata
= data
;
1886 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1889 pnfs_roc_release(calldata
->state
->inode
);
1890 nfs4_put_open_state(calldata
->state
);
1891 nfs_free_seqid(calldata
->arg
.seqid
);
1892 nfs4_put_state_owner(sp
);
1893 path_put(&calldata
->path
);
1897 static void nfs4_close_clear_stateid_flags(struct nfs4_state
*state
,
1900 spin_lock(&state
->owner
->so_lock
);
1901 if (!(fmode
& FMODE_READ
))
1902 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1903 if (!(fmode
& FMODE_WRITE
))
1904 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1905 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1906 spin_unlock(&state
->owner
->so_lock
);
1909 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1911 struct nfs4_closedata
*calldata
= data
;
1912 struct nfs4_state
*state
= calldata
->state
;
1913 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1915 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
1917 /* hmm. we are done with the inode, and in the process of freeing
1918 * the state_owner. we keep this around to process errors
1920 switch (task
->tk_status
) {
1923 pnfs_roc_set_barrier(state
->inode
,
1924 calldata
->roc_barrier
);
1925 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1926 renew_lease(server
, calldata
->timestamp
);
1927 nfs4_close_clear_stateid_flags(state
,
1928 calldata
->arg
.fmode
);
1930 case -NFS4ERR_STALE_STATEID
:
1931 case -NFS4ERR_OLD_STATEID
:
1932 case -NFS4ERR_BAD_STATEID
:
1933 case -NFS4ERR_EXPIRED
:
1934 if (calldata
->arg
.fmode
== 0)
1937 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
)
1938 rpc_restart_call_prepare(task
);
1940 nfs_release_seqid(calldata
->arg
.seqid
);
1941 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1944 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1946 struct nfs4_closedata
*calldata
= data
;
1947 struct nfs4_state
*state
= calldata
->state
;
1950 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1953 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1954 calldata
->arg
.fmode
= FMODE_READ
|FMODE_WRITE
;
1955 spin_lock(&state
->owner
->so_lock
);
1956 /* Calculate the change in open mode */
1957 if (state
->n_rdwr
== 0) {
1958 if (state
->n_rdonly
== 0) {
1959 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1960 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1961 calldata
->arg
.fmode
&= ~FMODE_READ
;
1963 if (state
->n_wronly
== 0) {
1964 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1965 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1966 calldata
->arg
.fmode
&= ~FMODE_WRITE
;
1969 spin_unlock(&state
->owner
->so_lock
);
1972 /* Note: exit _without_ calling nfs4_close_done */
1973 task
->tk_action
= NULL
;
1977 if (calldata
->arg
.fmode
== 0) {
1978 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
];
1979 if (calldata
->roc
&&
1980 pnfs_roc_drain(calldata
->inode
, &calldata
->roc_barrier
)) {
1981 rpc_sleep_on(&NFS_SERVER(calldata
->inode
)->roc_rpcwaitq
,
1987 nfs_fattr_init(calldata
->res
.fattr
);
1988 calldata
->timestamp
= jiffies
;
1989 if (nfs4_setup_sequence(NFS_SERVER(calldata
->inode
),
1990 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1993 rpc_call_start(task
);
1996 static const struct rpc_call_ops nfs4_close_ops
= {
1997 .rpc_call_prepare
= nfs4_close_prepare
,
1998 .rpc_call_done
= nfs4_close_done
,
1999 .rpc_release
= nfs4_free_closedata
,
2003 * It is possible for data to be read/written from a mem-mapped file
2004 * after the sys_close call (which hits the vfs layer as a flush).
2005 * This means that we can't safely call nfsv4 close on a file until
2006 * the inode is cleared. This in turn means that we are not good
2007 * NFSv4 citizens - we do not indicate to the server to update the file's
2008 * share state even when we are done with one of the three share
2009 * stateid's in the inode.
2011 * NOTE: Caller must be holding the sp->so_owner semaphore!
2013 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, gfp_t gfp_mask
, int wait
, bool roc
)
2015 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
2016 struct nfs4_closedata
*calldata
;
2017 struct nfs4_state_owner
*sp
= state
->owner
;
2018 struct rpc_task
*task
;
2019 struct rpc_message msg
= {
2020 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
2021 .rpc_cred
= state
->owner
->so_cred
,
2023 struct rpc_task_setup task_setup_data
= {
2024 .rpc_client
= server
->client
,
2025 .rpc_message
= &msg
,
2026 .callback_ops
= &nfs4_close_ops
,
2027 .workqueue
= nfsiod_workqueue
,
2028 .flags
= RPC_TASK_ASYNC
,
2030 int status
= -ENOMEM
;
2032 calldata
= kzalloc(sizeof(*calldata
), gfp_mask
);
2033 if (calldata
== NULL
)
2035 calldata
->inode
= state
->inode
;
2036 calldata
->state
= state
;
2037 calldata
->arg
.fh
= NFS_FH(state
->inode
);
2038 calldata
->arg
.stateid
= &state
->open_stateid
;
2039 /* Serialization for the sequence id */
2040 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
, gfp_mask
);
2041 if (calldata
->arg
.seqid
== NULL
)
2042 goto out_free_calldata
;
2043 calldata
->arg
.fmode
= 0;
2044 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
2045 calldata
->res
.fattr
= &calldata
->fattr
;
2046 calldata
->res
.seqid
= calldata
->arg
.seqid
;
2047 calldata
->res
.server
= server
;
2048 calldata
->roc
= roc
;
2050 calldata
->path
= *path
;
2052 msg
.rpc_argp
= &calldata
->arg
;
2053 msg
.rpc_resp
= &calldata
->res
;
2054 task_setup_data
.callback_data
= calldata
;
2055 task
= rpc_run_task(&task_setup_data
);
2057 return PTR_ERR(task
);
2060 status
= rpc_wait_for_completion_task(task
);
2067 pnfs_roc_release(state
->inode
);
2068 nfs4_put_open_state(state
);
2069 nfs4_put_state_owner(sp
);
2073 static struct inode
*
2074 nfs4_atomic_open(struct inode
*dir
, struct nfs_open_context
*ctx
, int open_flags
, struct iattr
*attr
)
2076 struct nfs4_state
*state
;
2078 /* Protect against concurrent sillydeletes */
2079 state
= nfs4_do_open(dir
, &ctx
->path
, ctx
->mode
, open_flags
, attr
, ctx
->cred
);
2081 return ERR_CAST(state
);
2083 return igrab(state
->inode
);
2086 static void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
2088 if (ctx
->state
== NULL
)
2091 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
2093 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
2096 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2098 struct nfs4_server_caps_arg args
= {
2101 struct nfs4_server_caps_res res
= {};
2102 struct rpc_message msg
= {
2103 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2109 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2111 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2112 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2113 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2114 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2115 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2116 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2117 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2118 server
->caps
|= NFS_CAP_ACLS
;
2119 if (res
.has_links
!= 0)
2120 server
->caps
|= NFS_CAP_HARDLINKS
;
2121 if (res
.has_symlinks
!= 0)
2122 server
->caps
|= NFS_CAP_SYMLINKS
;
2123 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2124 server
->caps
|= NFS_CAP_FILEID
;
2125 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2126 server
->caps
|= NFS_CAP_MODE
;
2127 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2128 server
->caps
|= NFS_CAP_NLINK
;
2129 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2130 server
->caps
|= NFS_CAP_OWNER
;
2131 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2132 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2133 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2134 server
->caps
|= NFS_CAP_ATIME
;
2135 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2136 server
->caps
|= NFS_CAP_CTIME
;
2137 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2138 server
->caps
|= NFS_CAP_MTIME
;
2140 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2141 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2142 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2143 server
->acl_bitmask
= res
.acl_bitmask
;
2149 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2151 struct nfs4_exception exception
= { };
2154 err
= nfs4_handle_exception(server
,
2155 _nfs4_server_capabilities(server
, fhandle
),
2157 } while (exception
.retry
);
2161 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2162 struct nfs_fsinfo
*info
)
2164 struct nfs4_lookup_root_arg args
= {
2165 .bitmask
= nfs4_fattr_bitmap
,
2167 struct nfs4_lookup_res res
= {
2169 .fattr
= info
->fattr
,
2172 struct rpc_message msg
= {
2173 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2178 nfs_fattr_init(info
->fattr
);
2179 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2182 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2183 struct nfs_fsinfo
*info
)
2185 struct nfs4_exception exception
= { };
2188 err
= nfs4_handle_exception(server
,
2189 _nfs4_lookup_root(server
, fhandle
, info
),
2191 } while (exception
.retry
);
2195 static int nfs4_lookup_root_sec(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2196 struct nfs_fsinfo
*info
, rpc_authflavor_t flavor
)
2198 struct rpc_auth
*auth
;
2201 auth
= rpcauth_create(flavor
, server
->client
);
2206 ret
= nfs4_lookup_root(server
, fhandle
, info
);
2214 * get the file handle for the "/" directory on the server
2216 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2217 struct nfs_fsinfo
*info
)
2219 int i
, len
, status
= 0;
2220 rpc_authflavor_t flav_array
[NFS_MAX_SECFLAVORS
+ 2];
2222 flav_array
[0] = RPC_AUTH_UNIX
;
2223 len
= gss_mech_list_pseudoflavors(&flav_array
[1]);
2224 flav_array
[1+len
] = RPC_AUTH_NULL
;
2227 for (i
= 0; i
< len
; i
++) {
2228 status
= nfs4_lookup_root_sec(server
, fhandle
, info
, flav_array
[i
]);
2233 status
= nfs4_server_capabilities(server
, fhandle
);
2235 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2236 return nfs4_map_errors(status
);
2240 * Get locations and (maybe) other attributes of a referral.
2241 * Note that we'll actually follow the referral later when
2242 * we detect fsid mismatch in inode revalidation
2244 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2246 int status
= -ENOMEM
;
2247 struct page
*page
= NULL
;
2248 struct nfs4_fs_locations
*locations
= NULL
;
2250 page
= alloc_page(GFP_KERNEL
);
2253 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2254 if (locations
== NULL
)
2257 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2260 /* Make sure server returned a different fsid for the referral */
2261 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2262 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2267 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2268 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2270 fattr
->mode
= S_IFDIR
;
2271 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2279 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2281 struct nfs4_getattr_arg args
= {
2283 .bitmask
= server
->attr_bitmask
,
2285 struct nfs4_getattr_res res
= {
2289 struct rpc_message msg
= {
2290 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2295 nfs_fattr_init(fattr
);
2296 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2299 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2301 struct nfs4_exception exception
= { };
2304 err
= nfs4_handle_exception(server
,
2305 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2307 } while (exception
.retry
);
2312 * The file is not closed if it is opened due to the a request to change
2313 * the size of the file. The open call will not be needed once the
2314 * VFS layer lookup-intents are implemented.
2316 * Close is called when the inode is destroyed.
2317 * If we haven't opened the file for O_WRONLY, we
2318 * need to in the size_change case to obtain a stateid.
2321 * Because OPEN is always done by name in nfsv4, it is
2322 * possible that we opened a different file by the same
2323 * name. We can recognize this race condition, but we
2324 * can't do anything about it besides returning an error.
2326 * This will be fixed with VFS changes (lookup-intent).
2329 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2330 struct iattr
*sattr
)
2332 struct inode
*inode
= dentry
->d_inode
;
2333 struct rpc_cred
*cred
= NULL
;
2334 struct nfs4_state
*state
= NULL
;
2337 nfs_fattr_init(fattr
);
2339 /* Search for an existing open(O_WRITE) file */
2340 if (sattr
->ia_valid
& ATTR_FILE
) {
2341 struct nfs_open_context
*ctx
;
2343 ctx
= nfs_file_open_context(sattr
->ia_file
);
2350 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2352 nfs_setattr_update_inode(inode
, sattr
);
2356 static int _nfs4_proc_lookupfh(struct rpc_clnt
*clnt
, struct nfs_server
*server
,
2357 const struct nfs_fh
*dirfh
, const struct qstr
*name
,
2358 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2361 struct nfs4_lookup_arg args
= {
2362 .bitmask
= server
->attr_bitmask
,
2366 struct nfs4_lookup_res res
= {
2371 struct rpc_message msg
= {
2372 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2377 nfs_fattr_init(fattr
);
2379 dprintk("NFS call lookupfh %s\n", name
->name
);
2380 status
= nfs4_call_sync(clnt
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2381 dprintk("NFS reply lookupfh: %d\n", status
);
2385 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2386 struct qstr
*name
, struct nfs_fh
*fhandle
,
2387 struct nfs_fattr
*fattr
)
2389 struct nfs4_exception exception
= { };
2392 err
= _nfs4_proc_lookupfh(server
->client
, server
, dirfh
, name
, fhandle
, fattr
);
2394 if (err
== -NFS4ERR_MOVED
) {
2398 err
= nfs4_handle_exception(server
, err
, &exception
);
2399 } while (exception
.retry
);
2403 static int _nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
,
2404 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2405 struct nfs_fattr
*fattr
)
2409 dprintk("NFS call lookup %s\n", name
->name
);
2410 status
= _nfs4_proc_lookupfh(clnt
, NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2411 if (status
== -NFS4ERR_MOVED
)
2412 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2413 dprintk("NFS reply lookup: %d\n", status
);
2417 void nfs_fixup_secinfo_attributes(struct nfs_fattr
*fattr
, struct nfs_fh
*fh
)
2419 memset(fh
, 0, sizeof(struct nfs_fh
));
2420 fattr
->fsid
.major
= 1;
2421 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
2422 NFS_ATTR_FATTR_NLINK
| NFS_ATTR_FATTR_FSID
| NFS_ATTR_FATTR_MOUNTPOINT
;
2423 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
2427 static int nfs4_proc_lookup(struct rpc_clnt
*clnt
, struct inode
*dir
, struct qstr
*name
,
2428 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2430 struct nfs4_exception exception
= { };
2433 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2434 _nfs4_proc_lookup(clnt
, dir
, name
, fhandle
, fattr
),
2437 nfs_fixup_secinfo_attributes(fattr
, fhandle
);
2438 } while (exception
.retry
);
2442 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2444 struct nfs_server
*server
= NFS_SERVER(inode
);
2445 struct nfs4_accessargs args
= {
2446 .fh
= NFS_FH(inode
),
2447 .bitmask
= server
->attr_bitmask
,
2449 struct nfs4_accessres res
= {
2452 struct rpc_message msg
= {
2453 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2456 .rpc_cred
= entry
->cred
,
2458 int mode
= entry
->mask
;
2462 * Determine which access bits we want to ask for...
2464 if (mode
& MAY_READ
)
2465 args
.access
|= NFS4_ACCESS_READ
;
2466 if (S_ISDIR(inode
->i_mode
)) {
2467 if (mode
& MAY_WRITE
)
2468 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2469 if (mode
& MAY_EXEC
)
2470 args
.access
|= NFS4_ACCESS_LOOKUP
;
2472 if (mode
& MAY_WRITE
)
2473 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2474 if (mode
& MAY_EXEC
)
2475 args
.access
|= NFS4_ACCESS_EXECUTE
;
2478 res
.fattr
= nfs_alloc_fattr();
2479 if (res
.fattr
== NULL
)
2482 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2485 if (res
.access
& NFS4_ACCESS_READ
)
2486 entry
->mask
|= MAY_READ
;
2487 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2488 entry
->mask
|= MAY_WRITE
;
2489 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2490 entry
->mask
|= MAY_EXEC
;
2491 nfs_refresh_inode(inode
, res
.fattr
);
2493 nfs_free_fattr(res
.fattr
);
2497 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2499 struct nfs4_exception exception
= { };
2502 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2503 _nfs4_proc_access(inode
, entry
),
2505 } while (exception
.retry
);
2510 * TODO: For the time being, we don't try to get any attributes
2511 * along with any of the zero-copy operations READ, READDIR,
2514 * In the case of the first three, we want to put the GETATTR
2515 * after the read-type operation -- this is because it is hard
2516 * to predict the length of a GETATTR response in v4, and thus
2517 * align the READ data correctly. This means that the GETATTR
2518 * may end up partially falling into the page cache, and we should
2519 * shift it into the 'tail' of the xdr_buf before processing.
2520 * To do this efficiently, we need to know the total length
2521 * of data received, which doesn't seem to be available outside
2524 * In the case of WRITE, we also want to put the GETATTR after
2525 * the operation -- in this case because we want to make sure
2526 * we get the post-operation mtime and size. This means that
2527 * we can't use xdr_encode_pages() as written: we need a variant
2528 * of it which would leave room in the 'tail' iovec.
2530 * Both of these changes to the XDR layer would in fact be quite
2531 * minor, but I decided to leave them for a subsequent patch.
2533 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2534 unsigned int pgbase
, unsigned int pglen
)
2536 struct nfs4_readlink args
= {
2537 .fh
= NFS_FH(inode
),
2542 struct nfs4_readlink_res res
;
2543 struct rpc_message msg
= {
2544 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2549 return nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2552 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2553 unsigned int pgbase
, unsigned int pglen
)
2555 struct nfs4_exception exception
= { };
2558 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2559 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2561 } while (exception
.retry
);
2567 * We will need to arrange for the VFS layer to provide an atomic open.
2568 * Until then, this create/open method is prone to inefficiency and race
2569 * conditions due to the lookup, create, and open VFS calls from sys_open()
2570 * placed on the wire.
2572 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2573 * The file will be opened again in the subsequent VFS open call
2574 * (nfs4_proc_file_open).
2576 * The open for read will just hang around to be used by any process that
2577 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2581 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2582 int flags
, struct nfs_open_context
*ctx
)
2584 struct path my_path
= {
2587 struct path
*path
= &my_path
;
2588 struct nfs4_state
*state
;
2589 struct rpc_cred
*cred
= NULL
;
2598 sattr
->ia_mode
&= ~current_umask();
2599 state
= nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
);
2601 if (IS_ERR(state
)) {
2602 status
= PTR_ERR(state
);
2605 d_add(dentry
, igrab(state
->inode
));
2606 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2610 nfs4_close_sync(path
, state
, fmode
);
2615 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2617 struct nfs_server
*server
= NFS_SERVER(dir
);
2618 struct nfs_removeargs args
= {
2620 .name
.len
= name
->len
,
2621 .name
.name
= name
->name
,
2622 .bitmask
= server
->attr_bitmask
,
2624 struct nfs_removeres res
= {
2627 struct rpc_message msg
= {
2628 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2632 int status
= -ENOMEM
;
2634 res
.dir_attr
= nfs_alloc_fattr();
2635 if (res
.dir_attr
== NULL
)
2638 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 1);
2640 update_changeattr(dir
, &res
.cinfo
);
2641 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2643 nfs_free_fattr(res
.dir_attr
);
2648 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2650 struct nfs4_exception exception
= { };
2653 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2654 _nfs4_proc_remove(dir
, name
),
2656 } while (exception
.retry
);
2660 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2662 struct nfs_server
*server
= NFS_SERVER(dir
);
2663 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2664 struct nfs_removeres
*res
= msg
->rpc_resp
;
2666 args
->bitmask
= server
->cache_consistency_bitmask
;
2667 res
->server
= server
;
2668 res
->seq_res
.sr_slot
= NULL
;
2669 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2672 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2674 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2676 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2678 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2680 update_changeattr(dir
, &res
->cinfo
);
2681 nfs_post_op_update_inode(dir
, res
->dir_attr
);
2685 static void nfs4_proc_rename_setup(struct rpc_message
*msg
, struct inode
*dir
)
2687 struct nfs_server
*server
= NFS_SERVER(dir
);
2688 struct nfs_renameargs
*arg
= msg
->rpc_argp
;
2689 struct nfs_renameres
*res
= msg
->rpc_resp
;
2691 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
];
2692 arg
->bitmask
= server
->attr_bitmask
;
2693 res
->server
= server
;
2696 static int nfs4_proc_rename_done(struct rpc_task
*task
, struct inode
*old_dir
,
2697 struct inode
*new_dir
)
2699 struct nfs_renameres
*res
= task
->tk_msg
.rpc_resp
;
2701 if (!nfs4_sequence_done(task
, &res
->seq_res
))
2703 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2706 update_changeattr(old_dir
, &res
->old_cinfo
);
2707 nfs_post_op_update_inode(old_dir
, res
->old_fattr
);
2708 update_changeattr(new_dir
, &res
->new_cinfo
);
2709 nfs_post_op_update_inode(new_dir
, res
->new_fattr
);
2713 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2714 struct inode
*new_dir
, struct qstr
*new_name
)
2716 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2717 struct nfs_renameargs arg
= {
2718 .old_dir
= NFS_FH(old_dir
),
2719 .new_dir
= NFS_FH(new_dir
),
2720 .old_name
= old_name
,
2721 .new_name
= new_name
,
2722 .bitmask
= server
->attr_bitmask
,
2724 struct nfs_renameres res
= {
2727 struct rpc_message msg
= {
2728 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2732 int status
= -ENOMEM
;
2734 res
.old_fattr
= nfs_alloc_fattr();
2735 res
.new_fattr
= nfs_alloc_fattr();
2736 if (res
.old_fattr
== NULL
|| res
.new_fattr
== NULL
)
2739 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2741 update_changeattr(old_dir
, &res
.old_cinfo
);
2742 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2743 update_changeattr(new_dir
, &res
.new_cinfo
);
2744 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2747 nfs_free_fattr(res
.new_fattr
);
2748 nfs_free_fattr(res
.old_fattr
);
2752 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2753 struct inode
*new_dir
, struct qstr
*new_name
)
2755 struct nfs4_exception exception
= { };
2758 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2759 _nfs4_proc_rename(old_dir
, old_name
,
2762 } while (exception
.retry
);
2766 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2768 struct nfs_server
*server
= NFS_SERVER(inode
);
2769 struct nfs4_link_arg arg
= {
2770 .fh
= NFS_FH(inode
),
2771 .dir_fh
= NFS_FH(dir
),
2773 .bitmask
= server
->attr_bitmask
,
2775 struct nfs4_link_res res
= {
2778 struct rpc_message msg
= {
2779 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2783 int status
= -ENOMEM
;
2785 res
.fattr
= nfs_alloc_fattr();
2786 res
.dir_attr
= nfs_alloc_fattr();
2787 if (res
.fattr
== NULL
|| res
.dir_attr
== NULL
)
2790 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
2792 update_changeattr(dir
, &res
.cinfo
);
2793 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2794 nfs_post_op_update_inode(inode
, res
.fattr
);
2797 nfs_free_fattr(res
.dir_attr
);
2798 nfs_free_fattr(res
.fattr
);
2802 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2804 struct nfs4_exception exception
= { };
2807 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2808 _nfs4_proc_link(inode
, dir
, name
),
2810 } while (exception
.retry
);
2814 struct nfs4_createdata
{
2815 struct rpc_message msg
;
2816 struct nfs4_create_arg arg
;
2817 struct nfs4_create_res res
;
2819 struct nfs_fattr fattr
;
2820 struct nfs_fattr dir_fattr
;
2823 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2824 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2826 struct nfs4_createdata
*data
;
2828 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2830 struct nfs_server
*server
= NFS_SERVER(dir
);
2832 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2833 data
->msg
.rpc_argp
= &data
->arg
;
2834 data
->msg
.rpc_resp
= &data
->res
;
2835 data
->arg
.dir_fh
= NFS_FH(dir
);
2836 data
->arg
.server
= server
;
2837 data
->arg
.name
= name
;
2838 data
->arg
.attrs
= sattr
;
2839 data
->arg
.ftype
= ftype
;
2840 data
->arg
.bitmask
= server
->attr_bitmask
;
2841 data
->res
.server
= server
;
2842 data
->res
.fh
= &data
->fh
;
2843 data
->res
.fattr
= &data
->fattr
;
2844 data
->res
.dir_fattr
= &data
->dir_fattr
;
2845 nfs_fattr_init(data
->res
.fattr
);
2846 nfs_fattr_init(data
->res
.dir_fattr
);
2851 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2853 int status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &data
->msg
,
2854 &data
->arg
.seq_args
, &data
->res
.seq_res
, 1);
2856 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2857 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2858 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2863 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2868 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2869 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2871 struct nfs4_createdata
*data
;
2872 int status
= -ENAMETOOLONG
;
2874 if (len
> NFS4_MAXPATHLEN
)
2878 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2882 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2883 data
->arg
.u
.symlink
.pages
= &page
;
2884 data
->arg
.u
.symlink
.len
= len
;
2886 status
= nfs4_do_create(dir
, dentry
, data
);
2888 nfs4_free_createdata(data
);
2893 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2894 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2896 struct nfs4_exception exception
= { };
2899 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2900 _nfs4_proc_symlink(dir
, dentry
, page
,
2903 } while (exception
.retry
);
2907 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2908 struct iattr
*sattr
)
2910 struct nfs4_createdata
*data
;
2911 int status
= -ENOMEM
;
2913 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2917 status
= nfs4_do_create(dir
, dentry
, data
);
2919 nfs4_free_createdata(data
);
2924 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2925 struct iattr
*sattr
)
2927 struct nfs4_exception exception
= { };
2930 sattr
->ia_mode
&= ~current_umask();
2932 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2933 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2935 } while (exception
.retry
);
2939 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2940 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2942 struct inode
*dir
= dentry
->d_inode
;
2943 struct nfs4_readdir_arg args
= {
2948 .bitmask
= NFS_SERVER(dentry
->d_inode
)->attr_bitmask
,
2951 struct nfs4_readdir_res res
;
2952 struct rpc_message msg
= {
2953 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2960 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2961 dentry
->d_parent
->d_name
.name
,
2962 dentry
->d_name
.name
,
2963 (unsigned long long)cookie
);
2964 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2965 res
.pgbase
= args
.pgbase
;
2966 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
2968 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2969 status
+= args
.pgbase
;
2972 nfs_invalidate_atime(dir
);
2974 dprintk("%s: returns %d\n", __func__
, status
);
2978 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2979 u64 cookie
, struct page
**pages
, unsigned int count
, int plus
)
2981 struct nfs4_exception exception
= { };
2984 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2985 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2986 pages
, count
, plus
),
2988 } while (exception
.retry
);
2992 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2993 struct iattr
*sattr
, dev_t rdev
)
2995 struct nfs4_createdata
*data
;
2996 int mode
= sattr
->ia_mode
;
2997 int status
= -ENOMEM
;
2999 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
3000 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
3002 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
3007 data
->arg
.ftype
= NF4FIFO
;
3008 else if (S_ISBLK(mode
)) {
3009 data
->arg
.ftype
= NF4BLK
;
3010 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3011 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3013 else if (S_ISCHR(mode
)) {
3014 data
->arg
.ftype
= NF4CHR
;
3015 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
3016 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
3019 status
= nfs4_do_create(dir
, dentry
, data
);
3021 nfs4_free_createdata(data
);
3026 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
3027 struct iattr
*sattr
, dev_t rdev
)
3029 struct nfs4_exception exception
= { };
3032 sattr
->ia_mode
&= ~current_umask();
3034 err
= nfs4_handle_exception(NFS_SERVER(dir
),
3035 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
3037 } while (exception
.retry
);
3041 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3042 struct nfs_fsstat
*fsstat
)
3044 struct nfs4_statfs_arg args
= {
3046 .bitmask
= server
->attr_bitmask
,
3048 struct nfs4_statfs_res res
= {
3051 struct rpc_message msg
= {
3052 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
3057 nfs_fattr_init(fsstat
->fattr
);
3058 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3061 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
3063 struct nfs4_exception exception
= { };
3066 err
= nfs4_handle_exception(server
,
3067 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
3069 } while (exception
.retry
);
3073 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3074 struct nfs_fsinfo
*fsinfo
)
3076 struct nfs4_fsinfo_arg args
= {
3078 .bitmask
= server
->attr_bitmask
,
3080 struct nfs4_fsinfo_res res
= {
3083 struct rpc_message msg
= {
3084 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
3089 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3092 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3094 struct nfs4_exception exception
= { };
3098 err
= nfs4_handle_exception(server
,
3099 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
3101 } while (exception
.retry
);
3105 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
3107 nfs_fattr_init(fsinfo
->fattr
);
3108 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
3111 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3112 struct nfs_pathconf
*pathconf
)
3114 struct nfs4_pathconf_arg args
= {
3116 .bitmask
= server
->attr_bitmask
,
3118 struct nfs4_pathconf_res res
= {
3119 .pathconf
= pathconf
,
3121 struct rpc_message msg
= {
3122 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
3127 /* None of the pathconf attributes are mandatory to implement */
3128 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
3129 memset(pathconf
, 0, sizeof(*pathconf
));
3133 nfs_fattr_init(pathconf
->fattr
);
3134 return nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3137 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
3138 struct nfs_pathconf
*pathconf
)
3140 struct nfs4_exception exception
= { };
3144 err
= nfs4_handle_exception(server
,
3145 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
3147 } while (exception
.retry
);
3151 static int nfs4_read_done_cb(struct rpc_task
*task
, struct nfs_read_data
*data
)
3153 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3155 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
3156 nfs_restart_rpc(task
, server
->nfs_client
);
3160 nfs_invalidate_atime(data
->inode
);
3161 if (task
->tk_status
> 0)
3162 renew_lease(server
, data
->timestamp
);
3166 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
3169 dprintk("--> %s\n", __func__
);
3171 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3174 return data
->read_done_cb(task
, data
);
3177 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
3179 data
->timestamp
= jiffies
;
3180 data
->read_done_cb
= nfs4_read_done_cb
;
3181 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
3184 /* Reset the the nfs_read_data to send the read to the MDS. */
3185 void nfs4_reset_read(struct rpc_task
*task
, struct nfs_read_data
*data
)
3187 dprintk("%s Reset task for i/o through\n", __func__
);
3188 put_lseg(data
->lseg
);
3190 /* offsets will differ in the dense stripe case */
3191 data
->args
.offset
= data
->mds_offset
;
3192 data
->ds_clp
= NULL
;
3193 data
->args
.fh
= NFS_FH(data
->inode
);
3194 data
->read_done_cb
= nfs4_read_done_cb
;
3195 task
->tk_ops
= data
->mds_ops
;
3196 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3198 EXPORT_SYMBOL_GPL(nfs4_reset_read
);
3200 static int nfs4_write_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3202 struct inode
*inode
= data
->inode
;
3204 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
3205 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3208 if (task
->tk_status
>= 0) {
3209 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3210 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3215 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3217 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3219 return data
->write_done_cb(task
, data
);
3222 /* Reset the the nfs_write_data to send the write to the MDS. */
3223 void nfs4_reset_write(struct rpc_task
*task
, struct nfs_write_data
*data
)
3225 dprintk("%s Reset task for i/o through\n", __func__
);
3226 put_lseg(data
->lseg
);
3228 data
->ds_clp
= NULL
;
3229 data
->write_done_cb
= nfs4_write_done_cb
;
3230 data
->args
.fh
= NFS_FH(data
->inode
);
3231 data
->args
.bitmask
= data
->res
.server
->cache_consistency_bitmask
;
3232 data
->args
.offset
= data
->mds_offset
;
3233 data
->res
.fattr
= &data
->fattr
;
3234 task
->tk_ops
= data
->mds_ops
;
3235 rpc_task_reset_client(task
, NFS_CLIENT(data
->inode
));
3237 EXPORT_SYMBOL_GPL(nfs4_reset_write
);
3239 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3241 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3244 data
->args
.bitmask
= NULL
;
3245 data
->res
.fattr
= NULL
;
3247 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3248 if (!data
->write_done_cb
)
3249 data
->write_done_cb
= nfs4_write_done_cb
;
3250 data
->res
.server
= server
;
3251 data
->timestamp
= jiffies
;
3253 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3256 static int nfs4_commit_done_cb(struct rpc_task
*task
, struct nfs_write_data
*data
)
3258 struct inode
*inode
= data
->inode
;
3260 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3261 nfs_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3264 nfs_refresh_inode(inode
, data
->res
.fattr
);
3268 static int nfs4_commit_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(task
, data
);
3275 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3277 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3280 data
->args
.bitmask
= NULL
;
3281 data
->res
.fattr
= NULL
;
3283 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3284 if (!data
->write_done_cb
)
3285 data
->write_done_cb
= nfs4_commit_done_cb
;
3286 data
->res
.server
= server
;
3287 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3290 struct nfs4_renewdata
{
3291 struct nfs_client
*client
;
3292 unsigned long timestamp
;
3296 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3297 * standalone procedure for queueing an asynchronous RENEW.
3299 static void nfs4_renew_release(void *calldata
)
3301 struct nfs4_renewdata
*data
= calldata
;
3302 struct nfs_client
*clp
= data
->client
;
3304 if (atomic_read(&clp
->cl_count
) > 1)
3305 nfs4_schedule_state_renewal(clp
);
3306 nfs_put_client(clp
);
3310 static void nfs4_renew_done(struct rpc_task
*task
, void *calldata
)
3312 struct nfs4_renewdata
*data
= calldata
;
3313 struct nfs_client
*clp
= data
->client
;
3314 unsigned long timestamp
= data
->timestamp
;
3316 if (task
->tk_status
< 0) {
3317 /* Unless we're shutting down, schedule state recovery! */
3318 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3319 nfs4_schedule_lease_recovery(clp
);
3322 do_renew_lease(clp
, timestamp
);
3325 static const struct rpc_call_ops nfs4_renew_ops
= {
3326 .rpc_call_done
= nfs4_renew_done
,
3327 .rpc_release
= nfs4_renew_release
,
3330 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3332 struct rpc_message msg
= {
3333 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3337 struct nfs4_renewdata
*data
;
3339 if (!atomic_inc_not_zero(&clp
->cl_count
))
3341 data
= kmalloc(sizeof(*data
), GFP_KERNEL
);
3345 data
->timestamp
= jiffies
;
3346 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3347 &nfs4_renew_ops
, data
);
3350 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3352 struct rpc_message msg
= {
3353 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3357 unsigned long now
= jiffies
;
3360 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3363 do_renew_lease(clp
, now
);
3367 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3369 return (server
->caps
& NFS_CAP_ACLS
)
3370 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3371 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3374 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3375 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3378 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3380 static void buf_to_pages(const void *buf
, size_t buflen
,
3381 struct page
**pages
, unsigned int *pgbase
)
3383 const void *p
= buf
;
3385 *pgbase
= offset_in_page(buf
);
3387 while (p
< buf
+ buflen
) {
3388 *(pages
++) = virt_to_page(p
);
3389 p
+= PAGE_CACHE_SIZE
;
3393 static int buf_to_pages_noslab(const void *buf
, size_t buflen
,
3394 struct page
**pages
, unsigned int *pgbase
)
3396 struct page
*newpage
, **spages
;
3402 len
= min_t(size_t, PAGE_CACHE_SIZE
, buflen
);
3403 newpage
= alloc_page(GFP_KERNEL
);
3405 if (newpage
== NULL
)
3407 memcpy(page_address(newpage
), buf
, len
);
3412 } while (buflen
!= 0);
3418 __free_page(spages
[rc
-1]);
3422 struct nfs4_cached_acl
{
3428 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3430 struct nfs_inode
*nfsi
= NFS_I(inode
);
3432 spin_lock(&inode
->i_lock
);
3433 kfree(nfsi
->nfs4_acl
);
3434 nfsi
->nfs4_acl
= acl
;
3435 spin_unlock(&inode
->i_lock
);
3438 static void nfs4_zap_acl_attr(struct inode
*inode
)
3440 nfs4_set_cached_acl(inode
, NULL
);
3443 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3445 struct nfs_inode
*nfsi
= NFS_I(inode
);
3446 struct nfs4_cached_acl
*acl
;
3449 spin_lock(&inode
->i_lock
);
3450 acl
= nfsi
->nfs4_acl
;
3453 if (buf
== NULL
) /* user is just asking for length */
3455 if (acl
->cached
== 0)
3457 ret
= -ERANGE
; /* see getxattr(2) man page */
3458 if (acl
->len
> buflen
)
3460 memcpy(buf
, acl
->data
, acl
->len
);
3464 spin_unlock(&inode
->i_lock
);
3468 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3470 struct nfs4_cached_acl
*acl
;
3472 if (buf
&& acl_len
<= PAGE_SIZE
) {
3473 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3477 memcpy(acl
->data
, buf
, acl_len
);
3479 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3486 nfs4_set_cached_acl(inode
, acl
);
3489 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3491 struct page
*pages
[NFS4ACL_MAXPAGES
];
3492 struct nfs_getaclargs args
= {
3493 .fh
= NFS_FH(inode
),
3497 struct nfs_getaclres res
= {
3501 struct rpc_message msg
= {
3502 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3506 struct page
*localpage
= NULL
;
3509 if (buflen
< PAGE_SIZE
) {
3510 /* As long as we're doing a round trip to the server anyway,
3511 * let's be prepared for a page of acl data. */
3512 localpage
= alloc_page(GFP_KERNEL
);
3513 resp_buf
= page_address(localpage
);
3514 if (localpage
== NULL
)
3516 args
.acl_pages
[0] = localpage
;
3517 args
.acl_pgbase
= 0;
3518 args
.acl_len
= PAGE_SIZE
;
3521 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3523 ret
= nfs4_call_sync(NFS_SERVER(inode
)->client
, NFS_SERVER(inode
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
3526 if (res
.acl_len
> args
.acl_len
)
3527 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3529 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3532 if (res
.acl_len
> buflen
)
3535 memcpy(buf
, resp_buf
, res
.acl_len
);
3540 __free_page(localpage
);
3544 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3546 struct nfs4_exception exception
= { };
3549 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3552 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3553 } while (exception
.retry
);
3557 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3559 struct nfs_server
*server
= NFS_SERVER(inode
);
3562 if (!nfs4_server_supports_acls(server
))
3564 ret
= nfs_revalidate_inode(server
, inode
);
3567 if (NFS_I(inode
)->cache_validity
& NFS_INO_INVALID_ACL
)
3568 nfs_zap_acl_cache(inode
);
3569 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3572 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3575 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3577 struct nfs_server
*server
= NFS_SERVER(inode
);
3578 struct page
*pages
[NFS4ACL_MAXPAGES
];
3579 struct nfs_setaclargs arg
= {
3580 .fh
= NFS_FH(inode
),
3584 struct nfs_setaclres res
;
3585 struct rpc_message msg
= {
3586 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3592 if (!nfs4_server_supports_acls(server
))
3594 i
= buf_to_pages_noslab(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3597 nfs_inode_return_delegation(inode
);
3598 ret
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3601 * Free each page after tx, so the only ref left is
3602 * held by the network stack
3605 put_page(pages
[i
-1]);
3608 * Acl update can result in inode attribute update.
3609 * so mark the attribute cache invalid.
3611 spin_lock(&inode
->i_lock
);
3612 NFS_I(inode
)->cache_validity
|= NFS_INO_INVALID_ATTR
;
3613 spin_unlock(&inode
->i_lock
);
3614 nfs_access_zap_cache(inode
);
3615 nfs_zap_acl_cache(inode
);
3619 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3621 struct nfs4_exception exception
= { };
3624 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3625 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3627 } while (exception
.retry
);
3632 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3634 struct nfs_client
*clp
= server
->nfs_client
;
3636 if (task
->tk_status
>= 0)
3638 switch(task
->tk_status
) {
3639 case -NFS4ERR_ADMIN_REVOKED
:
3640 case -NFS4ERR_BAD_STATEID
:
3641 case -NFS4ERR_OPENMODE
:
3644 nfs4_schedule_stateid_recovery(server
, state
);
3645 goto wait_on_recovery
;
3646 case -NFS4ERR_STALE_STATEID
:
3647 case -NFS4ERR_STALE_CLIENTID
:
3648 case -NFS4ERR_EXPIRED
:
3649 nfs4_schedule_lease_recovery(clp
);
3650 goto wait_on_recovery
;
3651 #if defined(CONFIG_NFS_V4_1)
3652 case -NFS4ERR_BADSESSION
:
3653 case -NFS4ERR_BADSLOT
:
3654 case -NFS4ERR_BAD_HIGH_SLOT
:
3655 case -NFS4ERR_DEADSESSION
:
3656 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3657 case -NFS4ERR_SEQ_FALSE_RETRY
:
3658 case -NFS4ERR_SEQ_MISORDERED
:
3659 dprintk("%s ERROR %d, Reset session\n", __func__
,
3661 nfs4_schedule_session_recovery(clp
->cl_session
);
3662 task
->tk_status
= 0;
3664 #endif /* CONFIG_NFS_V4_1 */
3665 case -NFS4ERR_DELAY
:
3666 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3667 case -NFS4ERR_GRACE
:
3669 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3670 task
->tk_status
= 0;
3672 case -NFS4ERR_OLD_STATEID
:
3673 task
->tk_status
= 0;
3676 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3679 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3680 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3681 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3682 task
->tk_status
= 0;
3686 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
,
3687 unsigned short port
, struct rpc_cred
*cred
,
3688 struct nfs4_setclientid_res
*res
)
3690 nfs4_verifier sc_verifier
;
3691 struct nfs4_setclientid setclientid
= {
3692 .sc_verifier
= &sc_verifier
,
3694 .sc_cb_ident
= clp
->cl_cb_ident
,
3696 struct rpc_message msg
= {
3697 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3698 .rpc_argp
= &setclientid
,
3706 p
= (__be32
*)sc_verifier
.data
;
3707 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3708 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3711 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3712 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3714 rpc_peeraddr2str(clp
->cl_rpcclient
,
3716 rpc_peeraddr2str(clp
->cl_rpcclient
,
3718 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3719 clp
->cl_id_uniquifier
);
3720 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3721 sizeof(setclientid
.sc_netid
),
3722 rpc_peeraddr2str(clp
->cl_rpcclient
,
3723 RPC_DISPLAY_NETID
));
3724 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3725 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3726 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3728 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3729 if (status
!= -NFS4ERR_CLID_INUSE
)
3734 ssleep(clp
->cl_lease_time
/ HZ
+ 1);
3736 if (++clp
->cl_id_uniquifier
== 0)
3742 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3743 struct nfs4_setclientid_res
*arg
,
3744 struct rpc_cred
*cred
)
3746 struct nfs_fsinfo fsinfo
;
3747 struct rpc_message msg
= {
3748 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3750 .rpc_resp
= &fsinfo
,
3757 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3759 spin_lock(&clp
->cl_lock
);
3760 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3761 clp
->cl_last_renewal
= now
;
3762 spin_unlock(&clp
->cl_lock
);
3767 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
,
3768 struct nfs4_setclientid_res
*arg
,
3769 struct rpc_cred
*cred
)
3774 err
= _nfs4_proc_setclientid_confirm(clp
, arg
, cred
);
3778 case -NFS4ERR_RESOURCE
:
3779 /* The IBM lawyers misread another document! */
3780 case -NFS4ERR_DELAY
:
3781 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3787 struct nfs4_delegreturndata
{
3788 struct nfs4_delegreturnargs args
;
3789 struct nfs4_delegreturnres res
;
3791 nfs4_stateid stateid
;
3792 unsigned long timestamp
;
3793 struct nfs_fattr fattr
;
3797 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3799 struct nfs4_delegreturndata
*data
= calldata
;
3801 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
3804 switch (task
->tk_status
) {
3805 case -NFS4ERR_STALE_STATEID
:
3806 case -NFS4ERR_EXPIRED
:
3808 renew_lease(data
->res
.server
, data
->timestamp
);
3811 if (nfs4_async_handle_error(task
, data
->res
.server
, NULL
) ==
3813 nfs_restart_rpc(task
, data
->res
.server
->nfs_client
);
3817 data
->rpc_status
= task
->tk_status
;
3820 static void nfs4_delegreturn_release(void *calldata
)
3825 #if defined(CONFIG_NFS_V4_1)
3826 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3828 struct nfs4_delegreturndata
*d_data
;
3830 d_data
= (struct nfs4_delegreturndata
*)data
;
3832 if (nfs4_setup_sequence(d_data
->res
.server
,
3833 &d_data
->args
.seq_args
,
3834 &d_data
->res
.seq_res
, 1, task
))
3836 rpc_call_start(task
);
3838 #endif /* CONFIG_NFS_V4_1 */
3840 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3841 #if defined(CONFIG_NFS_V4_1)
3842 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3843 #endif /* CONFIG_NFS_V4_1 */
3844 .rpc_call_done
= nfs4_delegreturn_done
,
3845 .rpc_release
= nfs4_delegreturn_release
,
3848 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3850 struct nfs4_delegreturndata
*data
;
3851 struct nfs_server
*server
= NFS_SERVER(inode
);
3852 struct rpc_task
*task
;
3853 struct rpc_message msg
= {
3854 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3857 struct rpc_task_setup task_setup_data
= {
3858 .rpc_client
= server
->client
,
3859 .rpc_message
= &msg
,
3860 .callback_ops
= &nfs4_delegreturn_ops
,
3861 .flags
= RPC_TASK_ASYNC
,
3865 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
3868 data
->args
.fhandle
= &data
->fh
;
3869 data
->args
.stateid
= &data
->stateid
;
3870 data
->args
.bitmask
= server
->attr_bitmask
;
3871 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3872 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3873 data
->res
.fattr
= &data
->fattr
;
3874 data
->res
.server
= server
;
3875 nfs_fattr_init(data
->res
.fattr
);
3876 data
->timestamp
= jiffies
;
3877 data
->rpc_status
= 0;
3879 task_setup_data
.callback_data
= data
;
3880 msg
.rpc_argp
= &data
->args
;
3881 msg
.rpc_resp
= &data
->res
;
3882 task
= rpc_run_task(&task_setup_data
);
3884 return PTR_ERR(task
);
3887 status
= nfs4_wait_for_completion_rpc_task(task
);
3890 status
= data
->rpc_status
;
3893 nfs_refresh_inode(inode
, &data
->fattr
);
3899 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3901 struct nfs_server
*server
= NFS_SERVER(inode
);
3902 struct nfs4_exception exception
= { };
3905 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3907 case -NFS4ERR_STALE_STATEID
:
3908 case -NFS4ERR_EXPIRED
:
3912 err
= nfs4_handle_exception(server
, err
, &exception
);
3913 } while (exception
.retry
);
3917 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3918 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3921 * sleep, with exponential backoff, and retry the LOCK operation.
3923 static unsigned long
3924 nfs4_set_lock_task_retry(unsigned long timeout
)
3926 schedule_timeout_killable(timeout
);
3928 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3929 return NFS4_LOCK_MAXTIMEOUT
;
3933 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3935 struct inode
*inode
= state
->inode
;
3936 struct nfs_server
*server
= NFS_SERVER(inode
);
3937 struct nfs_client
*clp
= server
->nfs_client
;
3938 struct nfs_lockt_args arg
= {
3939 .fh
= NFS_FH(inode
),
3942 struct nfs_lockt_res res
= {
3945 struct rpc_message msg
= {
3946 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3949 .rpc_cred
= state
->owner
->so_cred
,
3951 struct nfs4_lock_state
*lsp
;
3954 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3955 status
= nfs4_set_lock_state(state
, request
);
3958 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3959 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3960 arg
.lock_owner
.s_dev
= server
->s_dev
;
3961 status
= nfs4_call_sync(server
->client
, server
, &msg
, &arg
.seq_args
, &res
.seq_res
, 1);
3964 request
->fl_type
= F_UNLCK
;
3966 case -NFS4ERR_DENIED
:
3969 request
->fl_ops
->fl_release_private(request
);
3974 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3976 struct nfs4_exception exception
= { };
3980 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3981 _nfs4_proc_getlk(state
, cmd
, request
),
3983 } while (exception
.retry
);
3987 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3990 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3992 res
= posix_lock_file_wait(file
, fl
);
3995 res
= flock_lock_file_wait(file
, fl
);
4003 struct nfs4_unlockdata
{
4004 struct nfs_locku_args arg
;
4005 struct nfs_locku_res res
;
4006 struct nfs4_lock_state
*lsp
;
4007 struct nfs_open_context
*ctx
;
4008 struct file_lock fl
;
4009 const struct nfs_server
*server
;
4010 unsigned long timestamp
;
4013 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
4014 struct nfs_open_context
*ctx
,
4015 struct nfs4_lock_state
*lsp
,
4016 struct nfs_seqid
*seqid
)
4018 struct nfs4_unlockdata
*p
;
4019 struct inode
*inode
= lsp
->ls_state
->inode
;
4021 p
= kzalloc(sizeof(*p
), GFP_NOFS
);
4024 p
->arg
.fh
= NFS_FH(inode
);
4026 p
->arg
.seqid
= seqid
;
4027 p
->res
.seqid
= seqid
;
4028 p
->arg
.stateid
= &lsp
->ls_stateid
;
4030 atomic_inc(&lsp
->ls_count
);
4031 /* Ensure we don't close file until we're done freeing locks! */
4032 p
->ctx
= get_nfs_open_context(ctx
);
4033 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4034 p
->server
= NFS_SERVER(inode
);
4038 static void nfs4_locku_release_calldata(void *data
)
4040 struct nfs4_unlockdata
*calldata
= data
;
4041 nfs_free_seqid(calldata
->arg
.seqid
);
4042 nfs4_put_lock_state(calldata
->lsp
);
4043 put_nfs_open_context(calldata
->ctx
);
4047 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
4049 struct nfs4_unlockdata
*calldata
= data
;
4051 if (!nfs4_sequence_done(task
, &calldata
->res
.seq_res
))
4053 switch (task
->tk_status
) {
4055 memcpy(calldata
->lsp
->ls_stateid
.data
,
4056 calldata
->res
.stateid
.data
,
4057 sizeof(calldata
->lsp
->ls_stateid
.data
));
4058 renew_lease(calldata
->server
, calldata
->timestamp
);
4060 case -NFS4ERR_BAD_STATEID
:
4061 case -NFS4ERR_OLD_STATEID
:
4062 case -NFS4ERR_STALE_STATEID
:
4063 case -NFS4ERR_EXPIRED
:
4066 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
4067 nfs_restart_rpc(task
,
4068 calldata
->server
->nfs_client
);
4072 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
4074 struct nfs4_unlockdata
*calldata
= data
;
4076 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
4078 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
4079 /* Note: exit _without_ running nfs4_locku_done */
4080 task
->tk_action
= NULL
;
4083 calldata
->timestamp
= jiffies
;
4084 if (nfs4_setup_sequence(calldata
->server
,
4085 &calldata
->arg
.seq_args
,
4086 &calldata
->res
.seq_res
, 1, task
))
4088 rpc_call_start(task
);
4091 static const struct rpc_call_ops nfs4_locku_ops
= {
4092 .rpc_call_prepare
= nfs4_locku_prepare
,
4093 .rpc_call_done
= nfs4_locku_done
,
4094 .rpc_release
= nfs4_locku_release_calldata
,
4097 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
4098 struct nfs_open_context
*ctx
,
4099 struct nfs4_lock_state
*lsp
,
4100 struct nfs_seqid
*seqid
)
4102 struct nfs4_unlockdata
*data
;
4103 struct rpc_message msg
= {
4104 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
4105 .rpc_cred
= ctx
->cred
,
4107 struct rpc_task_setup task_setup_data
= {
4108 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
4109 .rpc_message
= &msg
,
4110 .callback_ops
= &nfs4_locku_ops
,
4111 .workqueue
= nfsiod_workqueue
,
4112 .flags
= RPC_TASK_ASYNC
,
4115 /* Ensure this is an unlock - when canceling a lock, the
4116 * canceled lock is passed in, and it won't be an unlock.
4118 fl
->fl_type
= F_UNLCK
;
4120 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
4122 nfs_free_seqid(seqid
);
4123 return ERR_PTR(-ENOMEM
);
4126 msg
.rpc_argp
= &data
->arg
;
4127 msg
.rpc_resp
= &data
->res
;
4128 task_setup_data
.callback_data
= data
;
4129 return rpc_run_task(&task_setup_data
);
4132 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4134 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4135 struct nfs_seqid
*seqid
;
4136 struct nfs4_lock_state
*lsp
;
4137 struct rpc_task
*task
;
4139 unsigned char fl_flags
= request
->fl_flags
;
4141 status
= nfs4_set_lock_state(state
, request
);
4142 /* Unlock _before_ we do the RPC call */
4143 request
->fl_flags
|= FL_EXISTS
;
4144 down_read(&nfsi
->rwsem
);
4145 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
4146 up_read(&nfsi
->rwsem
);
4149 up_read(&nfsi
->rwsem
);
4152 /* Is this a delegated lock? */
4153 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
4155 lsp
= request
->fl_u
.nfs4_fl
.owner
;
4156 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, GFP_KERNEL
);
4160 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
4161 status
= PTR_ERR(task
);
4164 status
= nfs4_wait_for_completion_rpc_task(task
);
4167 request
->fl_flags
= fl_flags
;
4171 struct nfs4_lockdata
{
4172 struct nfs_lock_args arg
;
4173 struct nfs_lock_res res
;
4174 struct nfs4_lock_state
*lsp
;
4175 struct nfs_open_context
*ctx
;
4176 struct file_lock fl
;
4177 unsigned long timestamp
;
4180 struct nfs_server
*server
;
4183 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
4184 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
,
4187 struct nfs4_lockdata
*p
;
4188 struct inode
*inode
= lsp
->ls_state
->inode
;
4189 struct nfs_server
*server
= NFS_SERVER(inode
);
4191 p
= kzalloc(sizeof(*p
), gfp_mask
);
4195 p
->arg
.fh
= NFS_FH(inode
);
4197 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
, gfp_mask
);
4198 if (p
->arg
.open_seqid
== NULL
)
4200 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
, gfp_mask
);
4201 if (p
->arg
.lock_seqid
== NULL
)
4202 goto out_free_seqid
;
4203 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
4204 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4205 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
4206 p
->arg
.lock_owner
.s_dev
= server
->s_dev
;
4207 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
4210 atomic_inc(&lsp
->ls_count
);
4211 p
->ctx
= get_nfs_open_context(ctx
);
4212 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
4215 nfs_free_seqid(p
->arg
.open_seqid
);
4221 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
4223 struct nfs4_lockdata
*data
= calldata
;
4224 struct nfs4_state
*state
= data
->lsp
->ls_state
;
4226 dprintk("%s: begin!\n", __func__
);
4227 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
4229 /* Do we need to do an open_to_lock_owner? */
4230 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
4231 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
4233 data
->arg
.open_stateid
= &state
->stateid
;
4234 data
->arg
.new_lock_owner
= 1;
4235 data
->res
.open_seqid
= data
->arg
.open_seqid
;
4237 data
->arg
.new_lock_owner
= 0;
4238 data
->timestamp
= jiffies
;
4239 if (nfs4_setup_sequence(data
->server
,
4240 &data
->arg
.seq_args
,
4241 &data
->res
.seq_res
, 1, task
))
4243 rpc_call_start(task
);
4244 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
4247 static void nfs4_recover_lock_prepare(struct rpc_task
*task
, void *calldata
)
4249 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4250 nfs4_lock_prepare(task
, calldata
);
4253 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
4255 struct nfs4_lockdata
*data
= calldata
;
4257 dprintk("%s: begin!\n", __func__
);
4259 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
4262 data
->rpc_status
= task
->tk_status
;
4263 if (data
->arg
.new_lock_owner
!= 0) {
4264 if (data
->rpc_status
== 0)
4265 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
4269 if (data
->rpc_status
== 0) {
4270 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
4271 sizeof(data
->lsp
->ls_stateid
.data
));
4272 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
4273 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
4276 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
4279 static void nfs4_lock_release(void *calldata
)
4281 struct nfs4_lockdata
*data
= calldata
;
4283 dprintk("%s: begin!\n", __func__
);
4284 nfs_free_seqid(data
->arg
.open_seqid
);
4285 if (data
->cancelled
!= 0) {
4286 struct rpc_task
*task
;
4287 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
4288 data
->arg
.lock_seqid
);
4290 rpc_put_task_async(task
);
4291 dprintk("%s: cancelling lock!\n", __func__
);
4293 nfs_free_seqid(data
->arg
.lock_seqid
);
4294 nfs4_put_lock_state(data
->lsp
);
4295 put_nfs_open_context(data
->ctx
);
4297 dprintk("%s: done!\n", __func__
);
4300 static const struct rpc_call_ops nfs4_lock_ops
= {
4301 .rpc_call_prepare
= nfs4_lock_prepare
,
4302 .rpc_call_done
= nfs4_lock_done
,
4303 .rpc_release
= nfs4_lock_release
,
4306 static const struct rpc_call_ops nfs4_recover_lock_ops
= {
4307 .rpc_call_prepare
= nfs4_recover_lock_prepare
,
4308 .rpc_call_done
= nfs4_lock_done
,
4309 .rpc_release
= nfs4_lock_release
,
4312 static void nfs4_handle_setlk_error(struct nfs_server
*server
, struct nfs4_lock_state
*lsp
, int new_lock_owner
, int error
)
4315 case -NFS4ERR_ADMIN_REVOKED
:
4316 case -NFS4ERR_BAD_STATEID
:
4317 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4318 if (new_lock_owner
!= 0 ||
4319 (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
4320 nfs4_schedule_stateid_recovery(server
, lsp
->ls_state
);
4322 case -NFS4ERR_STALE_STATEID
:
4323 lsp
->ls_seqid
.flags
&= ~NFS_SEQID_CONFIRMED
;
4324 case -NFS4ERR_EXPIRED
:
4325 nfs4_schedule_lease_recovery(server
->nfs_client
);
4329 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int recovery_type
)
4331 struct nfs4_lockdata
*data
;
4332 struct rpc_task
*task
;
4333 struct rpc_message msg
= {
4334 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
4335 .rpc_cred
= state
->owner
->so_cred
,
4337 struct rpc_task_setup task_setup_data
= {
4338 .rpc_client
= NFS_CLIENT(state
->inode
),
4339 .rpc_message
= &msg
,
4340 .callback_ops
= &nfs4_lock_ops
,
4341 .workqueue
= nfsiod_workqueue
,
4342 .flags
= RPC_TASK_ASYNC
,
4346 dprintk("%s: begin!\n", __func__
);
4347 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
4348 fl
->fl_u
.nfs4_fl
.owner
,
4349 recovery_type
== NFS_LOCK_NEW
? GFP_KERNEL
: GFP_NOFS
);
4353 data
->arg
.block
= 1;
4354 if (recovery_type
> NFS_LOCK_NEW
) {
4355 if (recovery_type
== NFS_LOCK_RECLAIM
)
4356 data
->arg
.reclaim
= NFS_LOCK_RECLAIM
;
4357 task_setup_data
.callback_ops
= &nfs4_recover_lock_ops
;
4359 msg
.rpc_argp
= &data
->arg
;
4360 msg
.rpc_resp
= &data
->res
;
4361 task_setup_data
.callback_data
= data
;
4362 task
= rpc_run_task(&task_setup_data
);
4364 return PTR_ERR(task
);
4365 ret
= nfs4_wait_for_completion_rpc_task(task
);
4367 ret
= data
->rpc_status
;
4369 nfs4_handle_setlk_error(data
->server
, data
->lsp
,
4370 data
->arg
.new_lock_owner
, ret
);
4372 data
->cancelled
= 1;
4374 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4378 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4380 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4381 struct nfs4_exception exception
= { };
4385 /* Cache the lock if possible... */
4386 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4388 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_RECLAIM
);
4389 if (err
!= -NFS4ERR_DELAY
)
4391 nfs4_handle_exception(server
, err
, &exception
);
4392 } while (exception
.retry
);
4396 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4398 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4399 struct nfs4_exception exception
= { };
4402 err
= nfs4_set_lock_state(state
, request
);
4406 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4408 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, NFS_LOCK_EXPIRED
);
4412 case -NFS4ERR_GRACE
:
4413 case -NFS4ERR_DELAY
:
4414 nfs4_handle_exception(server
, err
, &exception
);
4417 } while (exception
.retry
);
4422 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4424 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4425 unsigned char fl_flags
= request
->fl_flags
;
4426 int status
= -ENOLCK
;
4428 if ((fl_flags
& FL_POSIX
) &&
4429 !test_bit(NFS_STATE_POSIX_LOCKS
, &state
->flags
))
4431 /* Is this a delegated open? */
4432 status
= nfs4_set_lock_state(state
, request
);
4435 request
->fl_flags
|= FL_ACCESS
;
4436 status
= do_vfs_lock(request
->fl_file
, request
);
4439 down_read(&nfsi
->rwsem
);
4440 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4441 /* Yes: cache locks! */
4442 /* ...but avoid races with delegation recall... */
4443 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4444 status
= do_vfs_lock(request
->fl_file
, request
);
4447 status
= _nfs4_do_setlk(state
, cmd
, request
, NFS_LOCK_NEW
);
4450 /* Note: we always want to sleep here! */
4451 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4452 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4453 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4455 up_read(&nfsi
->rwsem
);
4457 request
->fl_flags
= fl_flags
;
4461 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4463 struct nfs4_exception exception
= { };
4467 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4468 if (err
== -NFS4ERR_DENIED
)
4470 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4472 } while (exception
.retry
);
4477 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4479 struct nfs_open_context
*ctx
;
4480 struct nfs4_state
*state
;
4481 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4484 /* verify open state */
4485 ctx
= nfs_file_open_context(filp
);
4488 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4491 if (IS_GETLK(cmd
)) {
4493 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4497 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4500 if (request
->fl_type
== F_UNLCK
) {
4502 return nfs4_proc_unlck(state
, cmd
, request
);
4509 status
= nfs4_proc_setlk(state
, cmd
, request
);
4510 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4512 timeout
= nfs4_set_lock_task_retry(timeout
);
4513 status
= -ERESTARTSYS
;
4516 } while(status
< 0);
4520 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4522 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4523 struct nfs4_exception exception
= { };
4526 err
= nfs4_set_lock_state(state
, fl
);
4530 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, NFS_LOCK_NEW
);
4533 printk(KERN_ERR
"%s: unhandled error %d.\n",
4538 case -NFS4ERR_EXPIRED
:
4539 case -NFS4ERR_STALE_CLIENTID
:
4540 case -NFS4ERR_STALE_STATEID
:
4541 nfs4_schedule_lease_recovery(server
->nfs_client
);
4543 case -NFS4ERR_BADSESSION
:
4544 case -NFS4ERR_BADSLOT
:
4545 case -NFS4ERR_BAD_HIGH_SLOT
:
4546 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
4547 case -NFS4ERR_DEADSESSION
:
4548 nfs4_schedule_session_recovery(server
->nfs_client
->cl_session
);
4552 * The show must go on: exit, but mark the
4553 * stateid as needing recovery.
4555 case -NFS4ERR_ADMIN_REVOKED
:
4556 case -NFS4ERR_BAD_STATEID
:
4557 case -NFS4ERR_OPENMODE
:
4558 nfs4_schedule_stateid_recovery(server
, state
);
4563 * User RPCSEC_GSS context has expired.
4564 * We cannot recover this stateid now, so
4565 * skip it and allow recovery thread to
4571 case -NFS4ERR_DENIED
:
4572 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4575 case -NFS4ERR_DELAY
:
4578 err
= nfs4_handle_exception(server
, err
, &exception
);
4579 } while (exception
.retry
);
4584 static void nfs4_release_lockowner_release(void *calldata
)
4589 const struct rpc_call_ops nfs4_release_lockowner_ops
= {
4590 .rpc_release
= nfs4_release_lockowner_release
,
4593 void nfs4_release_lockowner(const struct nfs4_lock_state
*lsp
)
4595 struct nfs_server
*server
= lsp
->ls_state
->owner
->so_server
;
4596 struct nfs_release_lockowner_args
*args
;
4597 struct rpc_message msg
= {
4598 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RELEASE_LOCKOWNER
],
4601 if (server
->nfs_client
->cl_mvops
->minor_version
!= 0)
4603 args
= kmalloc(sizeof(*args
), GFP_NOFS
);
4606 args
->lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
4607 args
->lock_owner
.id
= lsp
->ls_id
.id
;
4608 args
->lock_owner
.s_dev
= server
->s_dev
;
4609 msg
.rpc_argp
= args
;
4610 rpc_call_async(server
->client
, &msg
, 0, &nfs4_release_lockowner_ops
, args
);
4613 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4615 static int nfs4_xattr_set_nfs4_acl(struct dentry
*dentry
, const char *key
,
4616 const void *buf
, size_t buflen
,
4617 int flags
, int type
)
4619 if (strcmp(key
, "") != 0)
4622 return nfs4_proc_set_acl(dentry
->d_inode
, buf
, buflen
);
4625 static int nfs4_xattr_get_nfs4_acl(struct dentry
*dentry
, const char *key
,
4626 void *buf
, size_t buflen
, int type
)
4628 if (strcmp(key
, "") != 0)
4631 return nfs4_proc_get_acl(dentry
->d_inode
, buf
, buflen
);
4634 static size_t nfs4_xattr_list_nfs4_acl(struct dentry
*dentry
, char *list
,
4635 size_t list_len
, const char *name
,
4636 size_t name_len
, int type
)
4638 size_t len
= sizeof(XATTR_NAME_NFSV4_ACL
);
4640 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4643 if (list
&& len
<= list_len
)
4644 memcpy(list
, XATTR_NAME_NFSV4_ACL
, len
);
4648 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4650 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4651 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4652 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4655 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4656 NFS_ATTR_FATTR_NLINK
;
4657 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4661 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4662 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4664 struct nfs_server
*server
= NFS_SERVER(dir
);
4666 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4667 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4669 struct nfs4_fs_locations_arg args
= {
4670 .dir_fh
= NFS_FH(dir
),
4675 struct nfs4_fs_locations_res res
= {
4676 .fs_locations
= fs_locations
,
4678 struct rpc_message msg
= {
4679 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4685 dprintk("%s: start\n", __func__
);
4686 nfs_fattr_init(&fs_locations
->fattr
);
4687 fs_locations
->server
= server
;
4688 fs_locations
->nlocations
= 0;
4689 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4690 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4691 dprintk("%s: returned status = %d\n", __func__
, status
);
4695 static int _nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4698 struct nfs4_secinfo_arg args
= {
4699 .dir_fh
= NFS_FH(dir
),
4702 struct nfs4_secinfo_res res
= {
4705 struct rpc_message msg
= {
4706 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SECINFO
],
4711 dprintk("NFS call secinfo %s\n", name
->name
);
4712 status
= nfs4_call_sync(NFS_SERVER(dir
)->client
, NFS_SERVER(dir
), &msg
, &args
.seq_args
, &res
.seq_res
, 0);
4713 dprintk("NFS reply secinfo: %d\n", status
);
4717 int nfs4_proc_secinfo(struct inode
*dir
, const struct qstr
*name
, struct nfs4_secinfo_flavors
*flavors
)
4719 struct nfs4_exception exception
= { };
4722 err
= nfs4_handle_exception(NFS_SERVER(dir
),
4723 _nfs4_proc_secinfo(dir
, name
, flavors
),
4725 } while (exception
.retry
);
4729 #ifdef CONFIG_NFS_V4_1
4731 * Check the exchange flags returned by the server for invalid flags, having
4732 * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or
4735 static int nfs4_check_cl_exchange_flags(u32 flags
)
4737 if (flags
& ~EXCHGID4_FLAG_MASK_R
)
4739 if ((flags
& EXCHGID4_FLAG_USE_PNFS_MDS
) &&
4740 (flags
& EXCHGID4_FLAG_USE_NON_PNFS
))
4742 if (!(flags
& (EXCHGID4_FLAG_MASK_PNFS
)))
4746 return -NFS4ERR_INVAL
;
4750 * nfs4_proc_exchange_id()
4752 * Since the clientid has expired, all compounds using sessions
4753 * associated with the stale clientid will be returning
4754 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4755 * be in some phase of session reset.
4757 int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4759 nfs4_verifier verifier
;
4760 struct nfs41_exchange_id_args args
= {
4762 .flags
= EXCHGID4_FLAG_SUPP_MOVED_REFER
,
4764 struct nfs41_exchange_id_res res
= {
4768 struct rpc_message msg
= {
4769 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4776 dprintk("--> %s\n", __func__
);
4777 BUG_ON(clp
== NULL
);
4779 p
= (u32
*)verifier
.data
;
4780 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4781 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4782 args
.verifier
= &verifier
;
4784 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4787 init_utsname()->nodename
,
4788 init_utsname()->domainname
,
4789 clp
->cl_rpcclient
->cl_auth
->au_flavor
);
4791 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4793 status
= nfs4_check_cl_exchange_flags(clp
->cl_exchange_flags
);
4794 dprintk("<-- %s status= %d\n", __func__
, status
);
4798 struct nfs4_get_lease_time_data
{
4799 struct nfs4_get_lease_time_args
*args
;
4800 struct nfs4_get_lease_time_res
*res
;
4801 struct nfs_client
*clp
;
4804 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4808 struct nfs4_get_lease_time_data
*data
=
4809 (struct nfs4_get_lease_time_data
*)calldata
;
4811 dprintk("--> %s\n", __func__
);
4812 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
4813 /* just setup sequence, do not trigger session recovery
4814 since we're invoked within one */
4815 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4816 &data
->args
->la_seq_args
,
4817 &data
->res
->lr_seq_res
, 0, task
);
4819 BUG_ON(ret
== -EAGAIN
);
4820 rpc_call_start(task
);
4821 dprintk("<-- %s\n", __func__
);
4825 * Called from nfs4_state_manager thread for session setup, so don't recover
4826 * from sequence operation or clientid errors.
4828 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4830 struct nfs4_get_lease_time_data
*data
=
4831 (struct nfs4_get_lease_time_data
*)calldata
;
4833 dprintk("--> %s\n", __func__
);
4834 if (!nfs41_sequence_done(task
, &data
->res
->lr_seq_res
))
4836 switch (task
->tk_status
) {
4837 case -NFS4ERR_DELAY
:
4838 case -NFS4ERR_GRACE
:
4839 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4840 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4841 task
->tk_status
= 0;
4842 nfs_restart_rpc(task
, data
->clp
);
4845 dprintk("<-- %s\n", __func__
);
4848 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4849 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4850 .rpc_call_done
= nfs4_get_lease_time_done
,
4853 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4855 struct rpc_task
*task
;
4856 struct nfs4_get_lease_time_args args
;
4857 struct nfs4_get_lease_time_res res
= {
4858 .lr_fsinfo
= fsinfo
,
4860 struct nfs4_get_lease_time_data data
= {
4865 struct rpc_message msg
= {
4866 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4870 struct rpc_task_setup task_setup
= {
4871 .rpc_client
= clp
->cl_rpcclient
,
4872 .rpc_message
= &msg
,
4873 .callback_ops
= &nfs4_get_lease_time_ops
,
4874 .callback_data
= &data
4878 dprintk("--> %s\n", __func__
);
4879 task
= rpc_run_task(&task_setup
);
4882 status
= PTR_ERR(task
);
4884 status
= task
->tk_status
;
4887 dprintk("<-- %s return %d\n", __func__
, status
);
4893 * Reset a slot table
4895 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, u32 max_reqs
,
4898 struct nfs4_slot
*new = NULL
;
4902 dprintk("--> %s: max_reqs=%u, tbl->max_slots %d\n", __func__
,
4903 max_reqs
, tbl
->max_slots
);
4905 /* Does the newly negotiated max_reqs match the existing slot table? */
4906 if (max_reqs
!= tbl
->max_slots
) {
4908 new = kmalloc(max_reqs
* sizeof(struct nfs4_slot
),
4915 spin_lock(&tbl
->slot_tbl_lock
);
4918 tbl
->max_slots
= max_reqs
;
4920 for (i
= 0; i
< tbl
->max_slots
; ++i
)
4921 tbl
->slots
[i
].seq_nr
= ivalue
;
4922 spin_unlock(&tbl
->slot_tbl_lock
);
4923 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4924 tbl
, tbl
->slots
, tbl
->max_slots
);
4926 dprintk("<-- %s: return %d\n", __func__
, ret
);
4931 * Reset the forechannel and backchannel slot tables
4933 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4937 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4938 session
->fc_attrs
.max_reqs
, 1);
4942 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4943 session
->bc_attrs
.max_reqs
, 0);
4947 /* Destroy the slot table */
4948 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4950 if (session
->fc_slot_table
.slots
!= NULL
) {
4951 kfree(session
->fc_slot_table
.slots
);
4952 session
->fc_slot_table
.slots
= NULL
;
4954 if (session
->bc_slot_table
.slots
!= NULL
) {
4955 kfree(session
->bc_slot_table
.slots
);
4956 session
->bc_slot_table
.slots
= NULL
;
4962 * Initialize slot table
4964 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4965 int max_slots
, int ivalue
)
4967 struct nfs4_slot
*slot
;
4970 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4972 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4974 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_NOFS
);
4979 spin_lock(&tbl
->slot_tbl_lock
);
4980 tbl
->max_slots
= max_slots
;
4982 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4983 spin_unlock(&tbl
->slot_tbl_lock
);
4984 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4985 tbl
, tbl
->slots
, tbl
->max_slots
);
4987 dprintk("<-- %s: return %d\n", __func__
, ret
);
4992 * Initialize the forechannel and backchannel tables
4994 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4996 struct nfs4_slot_table
*tbl
;
4999 tbl
= &session
->fc_slot_table
;
5000 if (tbl
->slots
== NULL
) {
5001 status
= nfs4_init_slot_table(tbl
,
5002 session
->fc_attrs
.max_reqs
, 1);
5007 tbl
= &session
->bc_slot_table
;
5008 if (tbl
->slots
== NULL
) {
5009 status
= nfs4_init_slot_table(tbl
,
5010 session
->bc_attrs
.max_reqs
, 0);
5012 nfs4_destroy_slot_tables(session
);
5018 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
5020 struct nfs4_session
*session
;
5021 struct nfs4_slot_table
*tbl
;
5023 session
= kzalloc(sizeof(struct nfs4_session
), GFP_NOFS
);
5027 tbl
= &session
->fc_slot_table
;
5028 tbl
->highest_used_slotid
= -1;
5029 spin_lock_init(&tbl
->slot_tbl_lock
);
5030 rpc_init_priority_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
5031 init_completion(&tbl
->complete
);
5033 tbl
= &session
->bc_slot_table
;
5034 tbl
->highest_used_slotid
= -1;
5035 spin_lock_init(&tbl
->slot_tbl_lock
);
5036 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
5037 init_completion(&tbl
->complete
);
5039 session
->session_state
= 1<<NFS4_SESSION_INITING
;
5045 void nfs4_destroy_session(struct nfs4_session
*session
)
5047 nfs4_proc_destroy_session(session
);
5048 dprintk("%s Destroy backchannel for xprt %p\n",
5049 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
5050 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
5051 NFS41_BC_MIN_CALLBACKS
);
5052 nfs4_destroy_slot_tables(session
);
5057 * Initialize the values to be used by the client in CREATE_SESSION
5058 * If nfs4_init_session set the fore channel request and response sizes,
5061 * Set the back channel max_resp_sz_cached to zero to force the client to
5062 * always set csa_cachethis to FALSE because the current implementation
5063 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
5065 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
5067 struct nfs4_session
*session
= args
->client
->cl_session
;
5068 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
5069 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
5072 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
5074 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
5075 /* Fore channel attributes */
5076 args
->fc_attrs
.headerpadsz
= 0;
5077 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
5078 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
5079 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
5080 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
5082 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5083 "max_ops=%u max_reqs=%u\n",
5085 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
5086 args
->fc_attrs
.max_ops
, args
->fc_attrs
.max_reqs
);
5088 /* Back channel attributes */
5089 args
->bc_attrs
.headerpadsz
= 0;
5090 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
5091 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
5092 args
->bc_attrs
.max_resp_sz_cached
= 0;
5093 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
5094 args
->bc_attrs
.max_reqs
= 1;
5096 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
5097 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
5099 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
5100 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
5101 args
->bc_attrs
.max_reqs
);
5104 static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5106 struct nfs4_channel_attrs
*sent
= &args
->fc_attrs
;
5107 struct nfs4_channel_attrs
*rcvd
= &session
->fc_attrs
;
5109 if (rcvd
->headerpadsz
> sent
->headerpadsz
)
5111 if (rcvd
->max_resp_sz
> sent
->max_resp_sz
)
5114 * Our requested max_ops is the minimum we need; we're not
5115 * prepared to break up compounds into smaller pieces than that.
5116 * So, no point even trying to continue if the server won't
5119 if (rcvd
->max_ops
< sent
->max_ops
)
5121 if (rcvd
->max_reqs
== 0)
5126 static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args
*args
, struct nfs4_session
*session
)
5128 struct nfs4_channel_attrs
*sent
= &args
->bc_attrs
;
5129 struct nfs4_channel_attrs
*rcvd
= &session
->bc_attrs
;
5131 if (rcvd
->max_rqst_sz
> sent
->max_rqst_sz
)
5133 if (rcvd
->max_resp_sz
< sent
->max_resp_sz
)
5135 if (rcvd
->max_resp_sz_cached
> sent
->max_resp_sz_cached
)
5137 /* These would render the backchannel useless: */
5138 if (rcvd
->max_ops
== 0)
5140 if (rcvd
->max_reqs
== 0)
5145 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
5146 struct nfs4_session
*session
)
5150 ret
= nfs4_verify_fore_channel_attrs(args
, session
);
5153 return nfs4_verify_back_channel_attrs(args
, session
);
5156 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
5158 struct nfs4_session
*session
= clp
->cl_session
;
5159 struct nfs41_create_session_args args
= {
5161 .cb_program
= NFS4_CALLBACK
,
5163 struct nfs41_create_session_res res
= {
5166 struct rpc_message msg
= {
5167 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
5173 nfs4_init_channel_attrs(&args
);
5174 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
5176 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5179 /* Verify the session's negotiated channel_attrs values */
5180 status
= nfs4_verify_channel_attrs(&args
, session
);
5182 /* Increment the clientid slot sequence id */
5190 * Issues a CREATE_SESSION operation to the server.
5191 * It is the responsibility of the caller to verify the session is
5192 * expired before calling this routine.
5194 int nfs4_proc_create_session(struct nfs_client
*clp
)
5198 struct nfs4_session
*session
= clp
->cl_session
;
5202 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
5205 status
= _nfs4_proc_create_session(clp
);
5206 if (status
== -NFS4ERR_DELAY
) {
5207 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
5211 } while (status
== -NFS4ERR_DELAY
);
5216 /* Init and reset the fore channel */
5217 status
= nfs4_init_slot_tables(session
);
5218 dprintk("slot table initialization returned %d\n", status
);
5221 status
= nfs4_reset_slot_tables(session
);
5222 dprintk("slot table reset returned %d\n", status
);
5226 ptr
= (unsigned *)&session
->sess_id
.data
[0];
5227 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
5228 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
5230 dprintk("<-- %s\n", __func__
);
5235 * Issue the over-the-wire RPC DESTROY_SESSION.
5236 * The caller must serialize access to this routine.
5238 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
5241 struct rpc_message msg
;
5243 dprintk("--> nfs4_proc_destroy_session\n");
5245 /* session is still being setup */
5246 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
5249 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
5250 msg
.rpc_argp
= session
;
5251 msg
.rpc_resp
= NULL
;
5252 msg
.rpc_cred
= NULL
;
5253 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
5257 "Got error %d from the server on DESTROY_SESSION. "
5258 "Session has been destroyed regardless...\n", status
);
5260 dprintk("<-- nfs4_proc_destroy_session\n");
5264 int nfs4_init_session(struct nfs_server
*server
)
5266 struct nfs_client
*clp
= server
->nfs_client
;
5267 struct nfs4_session
*session
;
5268 unsigned int rsize
, wsize
;
5271 if (!nfs4_has_session(clp
))
5274 session
= clp
->cl_session
;
5275 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5278 rsize
= server
->rsize
;
5280 rsize
= NFS_MAX_FILE_IO_SIZE
;
5281 wsize
= server
->wsize
;
5283 wsize
= NFS_MAX_FILE_IO_SIZE
;
5285 session
->fc_attrs
.max_rqst_sz
= wsize
+ nfs41_maxwrite_overhead
;
5286 session
->fc_attrs
.max_resp_sz
= rsize
+ nfs41_maxread_overhead
;
5288 ret
= nfs4_recover_expired_lease(server
);
5290 ret
= nfs4_check_client_ready(clp
);
5294 int nfs4_init_ds_session(struct nfs_client
*clp
)
5296 struct nfs4_session
*session
= clp
->cl_session
;
5299 if (!test_and_clear_bit(NFS4_SESSION_INITING
, &session
->session_state
))
5302 ret
= nfs4_client_recover_expired_lease(clp
);
5304 /* Test for the DS role */
5305 if (!is_ds_client(clp
))
5308 ret
= nfs4_check_client_ready(clp
);
5312 EXPORT_SYMBOL_GPL(nfs4_init_ds_session
);
5316 * Renew the cl_session lease.
5318 struct nfs4_sequence_data
{
5319 struct nfs_client
*clp
;
5320 struct nfs4_sequence_args args
;
5321 struct nfs4_sequence_res res
;
5324 static void nfs41_sequence_release(void *data
)
5326 struct nfs4_sequence_data
*calldata
= data
;
5327 struct nfs_client
*clp
= calldata
->clp
;
5329 if (atomic_read(&clp
->cl_count
) > 1)
5330 nfs4_schedule_state_renewal(clp
);
5331 nfs_put_client(clp
);
5335 static int nfs41_sequence_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5337 switch(task
->tk_status
) {
5338 case -NFS4ERR_DELAY
:
5339 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5342 nfs4_schedule_lease_recovery(clp
);
5347 static void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
5349 struct nfs4_sequence_data
*calldata
= data
;
5350 struct nfs_client
*clp
= calldata
->clp
;
5352 if (!nfs41_sequence_done(task
, task
->tk_msg
.rpc_resp
))
5355 if (task
->tk_status
< 0) {
5356 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
5357 if (atomic_read(&clp
->cl_count
) == 1)
5360 if (nfs41_sequence_handle_errors(task
, clp
) == -EAGAIN
) {
5361 rpc_restart_call_prepare(task
);
5365 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
5367 dprintk("<-- %s\n", __func__
);
5370 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
5372 struct nfs4_sequence_data
*calldata
= data
;
5373 struct nfs_client
*clp
= calldata
->clp
;
5374 struct nfs4_sequence_args
*args
;
5375 struct nfs4_sequence_res
*res
;
5377 args
= task
->tk_msg
.rpc_argp
;
5378 res
= task
->tk_msg
.rpc_resp
;
5380 if (nfs41_setup_sequence(clp
->cl_session
, args
, res
, 0, task
))
5382 rpc_call_start(task
);
5385 static const struct rpc_call_ops nfs41_sequence_ops
= {
5386 .rpc_call_done
= nfs41_sequence_call_done
,
5387 .rpc_call_prepare
= nfs41_sequence_prepare
,
5388 .rpc_release
= nfs41_sequence_release
,
5391 static struct rpc_task
*_nfs41_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5393 struct nfs4_sequence_data
*calldata
;
5394 struct rpc_message msg
= {
5395 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
5398 struct rpc_task_setup task_setup_data
= {
5399 .rpc_client
= clp
->cl_rpcclient
,
5400 .rpc_message
= &msg
,
5401 .callback_ops
= &nfs41_sequence_ops
,
5402 .flags
= RPC_TASK_ASYNC
| RPC_TASK_SOFT
,
5405 if (!atomic_inc_not_zero(&clp
->cl_count
))
5406 return ERR_PTR(-EIO
);
5407 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5408 if (calldata
== NULL
) {
5409 nfs_put_client(clp
);
5410 return ERR_PTR(-ENOMEM
);
5412 msg
.rpc_argp
= &calldata
->args
;
5413 msg
.rpc_resp
= &calldata
->res
;
5414 calldata
->clp
= clp
;
5415 task_setup_data
.callback_data
= calldata
;
5417 return rpc_run_task(&task_setup_data
);
5420 static int nfs41_proc_async_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5422 struct rpc_task
*task
;
5425 task
= _nfs41_proc_sequence(clp
, cred
);
5427 ret
= PTR_ERR(task
);
5429 rpc_put_task_async(task
);
5430 dprintk("<-- %s status=%d\n", __func__
, ret
);
5434 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
5436 struct rpc_task
*task
;
5439 task
= _nfs41_proc_sequence(clp
, cred
);
5441 ret
= PTR_ERR(task
);
5444 ret
= rpc_wait_for_completion_task(task
);
5446 struct nfs4_sequence_res
*res
= task
->tk_msg
.rpc_resp
;
5448 if (task
->tk_status
== 0)
5449 nfs41_handle_sequence_flag_errors(clp
, res
->sr_status_flags
);
5450 ret
= task
->tk_status
;
5454 dprintk("<-- %s status=%d\n", __func__
, ret
);
5458 struct nfs4_reclaim_complete_data
{
5459 struct nfs_client
*clp
;
5460 struct nfs41_reclaim_complete_args arg
;
5461 struct nfs41_reclaim_complete_res res
;
5464 static void nfs4_reclaim_complete_prepare(struct rpc_task
*task
, void *data
)
5466 struct nfs4_reclaim_complete_data
*calldata
= data
;
5468 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
5469 if (nfs41_setup_sequence(calldata
->clp
->cl_session
,
5470 &calldata
->arg
.seq_args
,
5471 &calldata
->res
.seq_res
, 0, task
))
5474 rpc_call_start(task
);
5477 static int nfs41_reclaim_complete_handle_errors(struct rpc_task
*task
, struct nfs_client
*clp
)
5479 switch(task
->tk_status
) {
5481 case -NFS4ERR_COMPLETE_ALREADY
:
5482 case -NFS4ERR_WRONG_CRED
: /* What to do here? */
5484 case -NFS4ERR_DELAY
:
5485 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
5488 nfs4_schedule_lease_recovery(clp
);
5493 static void nfs4_reclaim_complete_done(struct rpc_task
*task
, void *data
)
5495 struct nfs4_reclaim_complete_data
*calldata
= data
;
5496 struct nfs_client
*clp
= calldata
->clp
;
5497 struct nfs4_sequence_res
*res
= &calldata
->res
.seq_res
;
5499 dprintk("--> %s\n", __func__
);
5500 if (!nfs41_sequence_done(task
, res
))
5503 if (nfs41_reclaim_complete_handle_errors(task
, clp
) == -EAGAIN
) {
5504 rpc_restart_call_prepare(task
);
5507 dprintk("<-- %s\n", __func__
);
5510 static void nfs4_free_reclaim_complete_data(void *data
)
5512 struct nfs4_reclaim_complete_data
*calldata
= data
;
5517 static const struct rpc_call_ops nfs4_reclaim_complete_call_ops
= {
5518 .rpc_call_prepare
= nfs4_reclaim_complete_prepare
,
5519 .rpc_call_done
= nfs4_reclaim_complete_done
,
5520 .rpc_release
= nfs4_free_reclaim_complete_data
,
5524 * Issue a global reclaim complete.
5526 static int nfs41_proc_reclaim_complete(struct nfs_client
*clp
)
5528 struct nfs4_reclaim_complete_data
*calldata
;
5529 struct rpc_task
*task
;
5530 struct rpc_message msg
= {
5531 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RECLAIM_COMPLETE
],
5533 struct rpc_task_setup task_setup_data
= {
5534 .rpc_client
= clp
->cl_rpcclient
,
5535 .rpc_message
= &msg
,
5536 .callback_ops
= &nfs4_reclaim_complete_call_ops
,
5537 .flags
= RPC_TASK_ASYNC
,
5539 int status
= -ENOMEM
;
5541 dprintk("--> %s\n", __func__
);
5542 calldata
= kzalloc(sizeof(*calldata
), GFP_NOFS
);
5543 if (calldata
== NULL
)
5545 calldata
->clp
= clp
;
5546 calldata
->arg
.one_fs
= 0;
5548 msg
.rpc_argp
= &calldata
->arg
;
5549 msg
.rpc_resp
= &calldata
->res
;
5550 task_setup_data
.callback_data
= calldata
;
5551 task
= rpc_run_task(&task_setup_data
);
5553 status
= PTR_ERR(task
);
5556 status
= nfs4_wait_for_completion_rpc_task(task
);
5558 status
= task
->tk_status
;
5562 dprintk("<-- %s status=%d\n", __func__
, status
);
5567 nfs4_layoutget_prepare(struct rpc_task
*task
, void *calldata
)
5569 struct nfs4_layoutget
*lgp
= calldata
;
5570 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5572 dprintk("--> %s\n", __func__
);
5573 /* Note the is a race here, where a CB_LAYOUTRECALL can come in
5574 * right now covering the LAYOUTGET we are about to send.
5575 * However, that is not so catastrophic, and there seems
5576 * to be no way to prevent it completely.
5578 if (nfs4_setup_sequence(server
, &lgp
->args
.seq_args
,
5579 &lgp
->res
.seq_res
, 0, task
))
5581 if (pnfs_choose_layoutget_stateid(&lgp
->args
.stateid
,
5582 NFS_I(lgp
->args
.inode
)->layout
,
5583 lgp
->args
.ctx
->state
)) {
5584 rpc_exit(task
, NFS4_OK
);
5587 rpc_call_start(task
);
5590 static void nfs4_layoutget_done(struct rpc_task
*task
, void *calldata
)
5592 struct nfs4_layoutget
*lgp
= calldata
;
5593 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5595 dprintk("--> %s\n", __func__
);
5597 if (!nfs4_sequence_done(task
, &lgp
->res
.seq_res
))
5600 switch (task
->tk_status
) {
5603 case -NFS4ERR_LAYOUTTRYLATER
:
5604 case -NFS4ERR_RECALLCONFLICT
:
5605 task
->tk_status
= -NFS4ERR_DELAY
;
5608 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5609 rpc_restart_call_prepare(task
);
5613 dprintk("<-- %s\n", __func__
);
5616 static void nfs4_layoutget_release(void *calldata
)
5618 struct nfs4_layoutget
*lgp
= calldata
;
5620 dprintk("--> %s\n", __func__
);
5621 put_nfs_open_context(lgp
->args
.ctx
);
5623 dprintk("<-- %s\n", __func__
);
5626 static const struct rpc_call_ops nfs4_layoutget_call_ops
= {
5627 .rpc_call_prepare
= nfs4_layoutget_prepare
,
5628 .rpc_call_done
= nfs4_layoutget_done
,
5629 .rpc_release
= nfs4_layoutget_release
,
5632 int nfs4_proc_layoutget(struct nfs4_layoutget
*lgp
)
5634 struct nfs_server
*server
= NFS_SERVER(lgp
->args
.inode
);
5635 struct rpc_task
*task
;
5636 struct rpc_message msg
= {
5637 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTGET
],
5638 .rpc_argp
= &lgp
->args
,
5639 .rpc_resp
= &lgp
->res
,
5641 struct rpc_task_setup task_setup_data
= {
5642 .rpc_client
= server
->client
,
5643 .rpc_message
= &msg
,
5644 .callback_ops
= &nfs4_layoutget_call_ops
,
5645 .callback_data
= lgp
,
5646 .flags
= RPC_TASK_ASYNC
,
5650 dprintk("--> %s\n", __func__
);
5652 lgp
->res
.layoutp
= &lgp
->args
.layout
;
5653 lgp
->res
.seq_res
.sr_slot
= NULL
;
5654 task
= rpc_run_task(&task_setup_data
);
5656 return PTR_ERR(task
);
5657 status
= nfs4_wait_for_completion_rpc_task(task
);
5659 status
= task
->tk_status
;
5661 status
= pnfs_layout_process(lgp
);
5663 dprintk("<-- %s status=%d\n", __func__
, status
);
5668 _nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5670 struct nfs4_getdeviceinfo_args args
= {
5673 struct nfs4_getdeviceinfo_res res
= {
5676 struct rpc_message msg
= {
5677 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETDEVICEINFO
],
5683 dprintk("--> %s\n", __func__
);
5684 status
= nfs4_call_sync(server
->client
, server
, &msg
, &args
.seq_args
, &res
.seq_res
, 0);
5685 dprintk("<-- %s status=%d\n", __func__
, status
);
5690 int nfs4_proc_getdeviceinfo(struct nfs_server
*server
, struct pnfs_device
*pdev
)
5692 struct nfs4_exception exception
= { };
5696 err
= nfs4_handle_exception(server
,
5697 _nfs4_proc_getdeviceinfo(server
, pdev
),
5699 } while (exception
.retry
);
5702 EXPORT_SYMBOL_GPL(nfs4_proc_getdeviceinfo
);
5704 static void nfs4_layoutcommit_prepare(struct rpc_task
*task
, void *calldata
)
5706 struct nfs4_layoutcommit_data
*data
= calldata
;
5707 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5709 if (nfs4_setup_sequence(server
, &data
->args
.seq_args
,
5710 &data
->res
.seq_res
, 1, task
))
5712 rpc_call_start(task
);
5716 nfs4_layoutcommit_done(struct rpc_task
*task
, void *calldata
)
5718 struct nfs4_layoutcommit_data
*data
= calldata
;
5719 struct nfs_server
*server
= NFS_SERVER(data
->args
.inode
);
5721 if (!nfs4_sequence_done(task
, &data
->res
.seq_res
))
5724 switch (task
->tk_status
) { /* Just ignore these failures */
5725 case NFS4ERR_DELEG_REVOKED
: /* layout was recalled */
5726 case NFS4ERR_BADIOMODE
: /* no IOMODE_RW layout for range */
5727 case NFS4ERR_BADLAYOUT
: /* no layout */
5728 case NFS4ERR_GRACE
: /* loca_recalim always false */
5729 task
->tk_status
= 0;
5732 if (nfs4_async_handle_error(task
, server
, NULL
) == -EAGAIN
) {
5733 nfs_restart_rpc(task
, server
->nfs_client
);
5737 if (task
->tk_status
== 0)
5738 nfs_post_op_update_inode_force_wcc(data
->args
.inode
,
5742 static void nfs4_layoutcommit_release(void *calldata
)
5744 struct nfs4_layoutcommit_data
*data
= calldata
;
5746 /* Matched by references in pnfs_set_layoutcommit */
5747 put_lseg(data
->lseg
);
5748 put_rpccred(data
->cred
);
5752 static const struct rpc_call_ops nfs4_layoutcommit_ops
= {
5753 .rpc_call_prepare
= nfs4_layoutcommit_prepare
,
5754 .rpc_call_done
= nfs4_layoutcommit_done
,
5755 .rpc_release
= nfs4_layoutcommit_release
,
5759 nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data
*data
, bool sync
)
5761 struct rpc_message msg
= {
5762 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LAYOUTCOMMIT
],
5763 .rpc_argp
= &data
->args
,
5764 .rpc_resp
= &data
->res
,
5765 .rpc_cred
= data
->cred
,
5767 struct rpc_task_setup task_setup_data
= {
5768 .task
= &data
->task
,
5769 .rpc_client
= NFS_CLIENT(data
->args
.inode
),
5770 .rpc_message
= &msg
,
5771 .callback_ops
= &nfs4_layoutcommit_ops
,
5772 .callback_data
= data
,
5773 .flags
= RPC_TASK_ASYNC
,
5775 struct rpc_task
*task
;
5778 dprintk("NFS: %4d initiating layoutcommit call. sync %d "
5779 "lbw: %llu inode %lu\n",
5780 data
->task
.tk_pid
, sync
,
5781 data
->args
.lastbytewritten
,
5782 data
->args
.inode
->i_ino
);
5784 task
= rpc_run_task(&task_setup_data
);
5786 return PTR_ERR(task
);
5789 status
= nfs4_wait_for_completion_rpc_task(task
);
5792 status
= task
->tk_status
;
5794 dprintk("%s: status %d\n", __func__
, status
);
5798 #endif /* CONFIG_NFS_V4_1 */
5800 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
5801 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5802 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5803 .recover_open
= nfs4_open_reclaim
,
5804 .recover_lock
= nfs4_lock_reclaim
,
5805 .establish_clid
= nfs4_init_clientid
,
5806 .get_clid_cred
= nfs4_get_setclientid_cred
,
5809 #if defined(CONFIG_NFS_V4_1)
5810 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
5811 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
5812 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
5813 .recover_open
= nfs4_open_reclaim
,
5814 .recover_lock
= nfs4_lock_reclaim
,
5815 .establish_clid
= nfs41_init_clientid
,
5816 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5817 .reclaim_complete
= nfs41_proc_reclaim_complete
,
5819 #endif /* CONFIG_NFS_V4_1 */
5821 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
5822 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5823 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5824 .recover_open
= nfs4_open_expired
,
5825 .recover_lock
= nfs4_lock_expired
,
5826 .establish_clid
= nfs4_init_clientid
,
5827 .get_clid_cred
= nfs4_get_setclientid_cred
,
5830 #if defined(CONFIG_NFS_V4_1)
5831 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
5832 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
5833 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
5834 .recover_open
= nfs4_open_expired
,
5835 .recover_lock
= nfs4_lock_expired
,
5836 .establish_clid
= nfs41_init_clientid
,
5837 .get_clid_cred
= nfs4_get_exchange_id_cred
,
5839 #endif /* CONFIG_NFS_V4_1 */
5841 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
5842 .sched_state_renewal
= nfs4_proc_async_renew
,
5843 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
5844 .renew_lease
= nfs4_proc_renew
,
5847 #if defined(CONFIG_NFS_V4_1)
5848 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
5849 .sched_state_renewal
= nfs41_proc_async_sequence
,
5850 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
5851 .renew_lease
= nfs4_proc_sequence
,
5855 static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops
= {
5857 .call_sync
= _nfs4_call_sync
,
5858 .validate_stateid
= nfs4_validate_delegation_stateid
,
5859 .reboot_recovery_ops
= &nfs40_reboot_recovery_ops
,
5860 .nograce_recovery_ops
= &nfs40_nograce_recovery_ops
,
5861 .state_renewal_ops
= &nfs40_state_renewal_ops
,
5864 #if defined(CONFIG_NFS_V4_1)
5865 static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops
= {
5867 .call_sync
= _nfs4_call_sync_session
,
5868 .validate_stateid
= nfs41_validate_delegation_stateid
,
5869 .reboot_recovery_ops
= &nfs41_reboot_recovery_ops
,
5870 .nograce_recovery_ops
= &nfs41_nograce_recovery_ops
,
5871 .state_renewal_ops
= &nfs41_state_renewal_ops
,
5875 const struct nfs4_minor_version_ops
*nfs_v4_minor_ops
[] = {
5876 [0] = &nfs_v4_0_minor_ops
,
5877 #if defined(CONFIG_NFS_V4_1)
5878 [1] = &nfs_v4_1_minor_ops
,
5882 static const struct inode_operations nfs4_file_inode_operations
= {
5883 .permission
= nfs_permission
,
5884 .getattr
= nfs_getattr
,
5885 .setattr
= nfs_setattr
,
5886 .getxattr
= generic_getxattr
,
5887 .setxattr
= generic_setxattr
,
5888 .listxattr
= generic_listxattr
,
5889 .removexattr
= generic_removexattr
,
5892 const struct nfs_rpc_ops nfs_v4_clientops
= {
5893 .version
= 4, /* protocol version */
5894 .dentry_ops
= &nfs4_dentry_operations
,
5895 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5896 .file_inode_ops
= &nfs4_file_inode_operations
,
5897 .getroot
= nfs4_proc_get_root
,
5898 .getattr
= nfs4_proc_getattr
,
5899 .setattr
= nfs4_proc_setattr
,
5900 .lookupfh
= nfs4_proc_lookupfh
,
5901 .lookup
= nfs4_proc_lookup
,
5902 .access
= nfs4_proc_access
,
5903 .readlink
= nfs4_proc_readlink
,
5904 .create
= nfs4_proc_create
,
5905 .remove
= nfs4_proc_remove
,
5906 .unlink_setup
= nfs4_proc_unlink_setup
,
5907 .unlink_done
= nfs4_proc_unlink_done
,
5908 .rename
= nfs4_proc_rename
,
5909 .rename_setup
= nfs4_proc_rename_setup
,
5910 .rename_done
= nfs4_proc_rename_done
,
5911 .link
= nfs4_proc_link
,
5912 .symlink
= nfs4_proc_symlink
,
5913 .mkdir
= nfs4_proc_mkdir
,
5914 .rmdir
= nfs4_proc_remove
,
5915 .readdir
= nfs4_proc_readdir
,
5916 .mknod
= nfs4_proc_mknod
,
5917 .statfs
= nfs4_proc_statfs
,
5918 .fsinfo
= nfs4_proc_fsinfo
,
5919 .pathconf
= nfs4_proc_pathconf
,
5920 .set_capabilities
= nfs4_server_capabilities
,
5921 .decode_dirent
= nfs4_decode_dirent
,
5922 .read_setup
= nfs4_proc_read_setup
,
5923 .read_done
= nfs4_read_done
,
5924 .write_setup
= nfs4_proc_write_setup
,
5925 .write_done
= nfs4_write_done
,
5926 .commit_setup
= nfs4_proc_commit_setup
,
5927 .commit_done
= nfs4_commit_done
,
5928 .lock
= nfs4_proc_lock
,
5929 .clear_acl_cache
= nfs4_zap_acl_attr
,
5930 .close_context
= nfs4_close_context
,
5931 .open_context
= nfs4_atomic_open
,
5932 .init_client
= nfs4_init_client
,
5933 .secinfo
= nfs4_proc_secinfo
,
5936 static const struct xattr_handler nfs4_xattr_nfs4_acl_handler
= {
5937 .prefix
= XATTR_NAME_NFSV4_ACL
,
5938 .list
= nfs4_xattr_list_nfs4_acl
,
5939 .get
= nfs4_xattr_get_nfs4_acl
,
5940 .set
= nfs4_xattr_set_nfs4_acl
,
5943 const struct xattr_handler
*nfs4_xattr_handlers
[] = {
5944 &nfs4_xattr_nfs4_acl_handler
,