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/sunrpc/clnt.h>
43 #include <linux/nfs.h>
44 #include <linux/nfs4.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/nfs_page.h>
47 #include <linux/namei.h>
48 #include <linux/mount.h>
49 #include <linux/module.h>
50 #include <linux/sunrpc/bc_xprt.h>
53 #include "delegation.h"
58 #define NFSDBG_FACILITY NFSDBG_PROC
60 #define NFS4_POLL_RETRY_MIN (HZ/10)
61 #define NFS4_POLL_RETRY_MAX (15*HZ)
63 #define NFS4_MAX_LOOP_ON_RECOVER (10)
66 static int _nfs4_proc_open(struct nfs4_opendata
*data
);
67 static int nfs4_do_fsinfo(struct nfs_server
*, struct nfs_fh
*, struct nfs_fsinfo
*);
68 static int nfs4_async_handle_error(struct rpc_task
*, const struct nfs_server
*, struct nfs4_state
*);
69 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
70 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
);
72 /* Prevent leaks of NFSv4 errors into userland */
73 static int nfs4_map_errors(int err
)
76 dprintk("%s could not handle NFSv4 error %d\n",
84 * This is our standard bitmap for GETATTR requests.
86 const u32 nfs4_fattr_bitmap
[2] = {
91 | FATTR4_WORD0_FILEID
,
93 | FATTR4_WORD1_NUMLINKS
95 | FATTR4_WORD1_OWNER_GROUP
97 | FATTR4_WORD1_SPACE_USED
98 | FATTR4_WORD1_TIME_ACCESS
99 | FATTR4_WORD1_TIME_METADATA
100 | FATTR4_WORD1_TIME_MODIFY
103 const u32 nfs4_statfs_bitmap
[2] = {
104 FATTR4_WORD0_FILES_AVAIL
105 | FATTR4_WORD0_FILES_FREE
106 | FATTR4_WORD0_FILES_TOTAL
,
107 FATTR4_WORD1_SPACE_AVAIL
108 | FATTR4_WORD1_SPACE_FREE
109 | FATTR4_WORD1_SPACE_TOTAL
112 const u32 nfs4_pathconf_bitmap
[2] = {
114 | FATTR4_WORD0_MAXNAME
,
118 const u32 nfs4_fsinfo_bitmap
[2] = { FATTR4_WORD0_MAXFILESIZE
119 | FATTR4_WORD0_MAXREAD
120 | FATTR4_WORD0_MAXWRITE
121 | FATTR4_WORD0_LEASE_TIME
,
125 const u32 nfs4_fs_locations_bitmap
[2] = {
127 | FATTR4_WORD0_CHANGE
130 | FATTR4_WORD0_FILEID
131 | FATTR4_WORD0_FS_LOCATIONS
,
133 | FATTR4_WORD1_NUMLINKS
135 | FATTR4_WORD1_OWNER_GROUP
136 | FATTR4_WORD1_RAWDEV
137 | FATTR4_WORD1_SPACE_USED
138 | FATTR4_WORD1_TIME_ACCESS
139 | FATTR4_WORD1_TIME_METADATA
140 | FATTR4_WORD1_TIME_MODIFY
141 | FATTR4_WORD1_MOUNTED_ON_FILEID
144 static void nfs4_setup_readdir(u64 cookie
, __be32
*verifier
, struct dentry
*dentry
,
145 struct nfs4_readdir_arg
*readdir
)
149 BUG_ON(readdir
->count
< 80);
151 readdir
->cookie
= cookie
;
152 memcpy(&readdir
->verifier
, verifier
, sizeof(readdir
->verifier
));
157 memset(&readdir
->verifier
, 0, sizeof(readdir
->verifier
));
162 * NFSv4 servers do not return entries for '.' and '..'
163 * Therefore, we fake these entries here. We let '.'
164 * have cookie 0 and '..' have cookie 1. Note that
165 * when talking to the server, we always send cookie 0
168 start
= p
= kmap_atomic(*readdir
->pages
, KM_USER0
);
171 *p
++ = xdr_one
; /* next */
172 *p
++ = xdr_zero
; /* cookie, first word */
173 *p
++ = xdr_one
; /* cookie, second word */
174 *p
++ = xdr_one
; /* entry len */
175 memcpy(p
, ".\0\0\0", 4); /* entry */
177 *p
++ = xdr_one
; /* bitmap length */
178 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
179 *p
++ = htonl(8); /* attribute buffer length */
180 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_inode
));
183 *p
++ = xdr_one
; /* next */
184 *p
++ = xdr_zero
; /* cookie, first word */
185 *p
++ = xdr_two
; /* cookie, second word */
186 *p
++ = xdr_two
; /* entry len */
187 memcpy(p
, "..\0\0", 4); /* entry */
189 *p
++ = xdr_one
; /* bitmap length */
190 *p
++ = htonl(FATTR4_WORD0_FILEID
); /* bitmap */
191 *p
++ = htonl(8); /* attribute buffer length */
192 p
= xdr_encode_hyper(p
, NFS_FILEID(dentry
->d_parent
->d_inode
));
194 readdir
->pgbase
= (char *)p
- (char *)start
;
195 readdir
->count
-= readdir
->pgbase
;
196 kunmap_atomic(start
, KM_USER0
);
199 static int nfs4_wait_clnt_recover(struct nfs_client
*clp
)
205 res
= wait_on_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
,
206 nfs_wait_bit_killable
, TASK_KILLABLE
);
210 static int nfs4_delay(struct rpc_clnt
*clnt
, long *timeout
)
217 *timeout
= NFS4_POLL_RETRY_MIN
;
218 if (*timeout
> NFS4_POLL_RETRY_MAX
)
219 *timeout
= NFS4_POLL_RETRY_MAX
;
220 schedule_timeout_killable(*timeout
);
221 if (fatal_signal_pending(current
))
227 /* This is the error handling routine for processes that are allowed
230 static int nfs4_handle_exception(const struct nfs_server
*server
, int errorcode
, struct nfs4_exception
*exception
)
232 struct nfs_client
*clp
= server
->nfs_client
;
233 struct nfs4_state
*state
= exception
->state
;
236 exception
->retry
= 0;
240 case -NFS4ERR_ADMIN_REVOKED
:
241 case -NFS4ERR_BAD_STATEID
:
242 case -NFS4ERR_OPENMODE
:
245 nfs4_state_mark_reclaim_nograce(clp
, state
);
246 case -NFS4ERR_STALE_CLIENTID
:
247 case -NFS4ERR_STALE_STATEID
:
248 case -NFS4ERR_EXPIRED
:
249 nfs4_schedule_state_recovery(clp
);
250 ret
= nfs4_wait_clnt_recover(clp
);
252 exception
->retry
= 1;
253 #if !defined(CONFIG_NFS_V4_1)
255 #else /* !defined(CONFIG_NFS_V4_1) */
256 if (!nfs4_has_session(server
->nfs_client
))
259 case -NFS4ERR_BADSESSION
:
260 case -NFS4ERR_BADSLOT
:
261 case -NFS4ERR_BAD_HIGH_SLOT
:
262 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
263 case -NFS4ERR_DEADSESSION
:
264 case -NFS4ERR_SEQ_FALSE_RETRY
:
265 case -NFS4ERR_SEQ_MISORDERED
:
266 dprintk("%s ERROR: %d Reset session\n", __func__
,
268 set_bit(NFS4CLNT_SESSION_SETUP
, &clp
->cl_state
);
269 exception
->retry
= 1;
271 #endif /* !defined(CONFIG_NFS_V4_1) */
272 case -NFS4ERR_FILE_OPEN
:
275 ret
= nfs4_delay(server
->client
, &exception
->timeout
);
278 case -NFS4ERR_OLD_STATEID
:
279 exception
->retry
= 1;
281 /* We failed to handle the error */
282 return nfs4_map_errors(ret
);
286 static void renew_lease(const struct nfs_server
*server
, unsigned long timestamp
)
288 struct nfs_client
*clp
= server
->nfs_client
;
289 spin_lock(&clp
->cl_lock
);
290 if (time_before(clp
->cl_last_renewal
,timestamp
))
291 clp
->cl_last_renewal
= timestamp
;
292 spin_unlock(&clp
->cl_lock
);
295 #if defined(CONFIG_NFS_V4_1)
298 * nfs4_free_slot - free a slot and efficiently update slot table.
300 * freeing a slot is trivially done by clearing its respective bit
302 * If the freed slotid equals highest_used_slotid we want to update it
303 * so that the server would be able to size down the slot table if needed,
304 * otherwise we know that the highest_used_slotid is still in use.
305 * When updating highest_used_slotid there may be "holes" in the bitmap
306 * so we need to scan down from highest_used_slotid to 0 looking for the now
307 * highest slotid in use.
308 * If none found, highest_used_slotid is set to -1.
311 nfs4_free_slot(struct nfs4_slot_table
*tbl
, u8 free_slotid
)
313 int slotid
= free_slotid
;
315 spin_lock(&tbl
->slot_tbl_lock
);
316 /* clear used bit in bitmap */
317 __clear_bit(slotid
, tbl
->used_slots
);
319 /* update highest_used_slotid when it is freed */
320 if (slotid
== tbl
->highest_used_slotid
) {
321 slotid
= find_last_bit(tbl
->used_slots
, tbl
->max_slots
);
322 if (slotid
>= 0 && slotid
< tbl
->max_slots
)
323 tbl
->highest_used_slotid
= slotid
;
325 tbl
->highest_used_slotid
= -1;
327 rpc_wake_up_next(&tbl
->slot_tbl_waitq
);
328 spin_unlock(&tbl
->slot_tbl_lock
);
329 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__
,
330 free_slotid
, tbl
->highest_used_slotid
);
333 void nfs41_sequence_free_slot(const struct nfs_client
*clp
,
334 struct nfs4_sequence_res
*res
)
336 struct nfs4_slot_table
*tbl
;
338 if (!nfs4_has_session(clp
)) {
339 dprintk("%s: No session\n", __func__
);
342 tbl
= &clp
->cl_session
->fc_slot_table
;
343 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
) {
344 dprintk("%s: No slot\n", __func__
);
345 /* just wake up the next guy waiting since
346 * we may have not consumed a slot after all */
347 rpc_wake_up_next(&tbl
->slot_tbl_waitq
);
350 nfs4_free_slot(tbl
, res
->sr_slotid
);
351 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
354 static void nfs41_sequence_done(struct nfs_client
*clp
,
355 struct nfs4_sequence_res
*res
,
358 unsigned long timestamp
;
359 struct nfs4_slot_table
*tbl
;
360 struct nfs4_slot
*slot
;
363 * sr_status remains 1 if an RPC level error occurred. The server
364 * may or may not have processed the sequence operation..
365 * Proceed as if the server received and processed the sequence
368 if (res
->sr_status
== 1)
369 res
->sr_status
= NFS_OK
;
371 /* -ERESTARTSYS can result in skipping nfs41_sequence_setup */
372 if (res
->sr_slotid
== NFS4_MAX_SLOT_TABLE
)
375 tbl
= &clp
->cl_session
->fc_slot_table
;
376 slot
= tbl
->slots
+ res
->sr_slotid
;
378 if (res
->sr_status
== 0) {
379 /* Update the slot's sequence and clientid lease timer */
381 timestamp
= res
->sr_renewal_time
;
382 spin_lock(&clp
->cl_lock
);
383 if (time_before(clp
->cl_last_renewal
, timestamp
))
384 clp
->cl_last_renewal
= timestamp
;
385 spin_unlock(&clp
->cl_lock
);
389 /* The session may be reset by one of the error handlers. */
390 dprintk("%s: Error %d free the slot \n", __func__
, res
->sr_status
);
391 nfs41_sequence_free_slot(clp
, res
);
395 * nfs4_find_slot - efficiently look for a free slot
397 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
398 * If found, we mark the slot as used, update the highest_used_slotid,
399 * and respectively set up the sequence operation args.
400 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise.
402 * Note: must be called with under the slot_tbl_lock.
405 nfs4_find_slot(struct nfs4_slot_table
*tbl
, struct rpc_task
*task
)
408 u8 ret_id
= NFS4_MAX_SLOT_TABLE
;
409 BUILD_BUG_ON((u8
)NFS4_MAX_SLOT_TABLE
!= (int)NFS4_MAX_SLOT_TABLE
);
411 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n",
412 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
,
414 slotid
= find_first_zero_bit(tbl
->used_slots
, tbl
->max_slots
);
415 if (slotid
>= tbl
->max_slots
)
417 __set_bit(slotid
, tbl
->used_slots
);
418 if (slotid
> tbl
->highest_used_slotid
)
419 tbl
->highest_used_slotid
= slotid
;
422 dprintk("<-- %s used_slots=%04lx highest_used=%d slotid=%d \n",
423 __func__
, tbl
->used_slots
[0], tbl
->highest_used_slotid
, ret_id
);
427 static int nfs4_recover_session(struct nfs4_session
*session
)
429 struct nfs_client
*clp
= session
->clp
;
433 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
434 ret
= nfs4_wait_clnt_recover(clp
);
437 if (!test_bit(NFS4CLNT_SESSION_SETUP
, &clp
->cl_state
))
439 nfs4_schedule_state_manager(clp
);
445 static int nfs41_setup_sequence(struct nfs4_session
*session
,
446 struct nfs4_sequence_args
*args
,
447 struct nfs4_sequence_res
*res
,
449 struct rpc_task
*task
)
451 struct nfs4_slot
*slot
;
452 struct nfs4_slot_table
*tbl
;
456 dprintk("--> %s\n", __func__
);
457 /* slot already allocated? */
458 if (res
->sr_slotid
!= NFS4_MAX_SLOT_TABLE
)
461 memset(res
, 0, sizeof(*res
));
462 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
463 tbl
= &session
->fc_slot_table
;
465 spin_lock(&tbl
->slot_tbl_lock
);
466 if (test_bit(NFS4CLNT_SESSION_SETUP
, &session
->clp
->cl_state
)) {
467 if (tbl
->highest_used_slotid
!= -1) {
468 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
469 spin_unlock(&tbl
->slot_tbl_lock
);
470 dprintk("<-- %s: Session reset: draining\n", __func__
);
474 /* The slot table is empty; start the reset thread */
475 dprintk("%s Session Reset\n", __func__
);
476 spin_unlock(&tbl
->slot_tbl_lock
);
477 status
= nfs4_recover_session(session
);
480 spin_lock(&tbl
->slot_tbl_lock
);
483 slotid
= nfs4_find_slot(tbl
, task
);
484 if (slotid
== NFS4_MAX_SLOT_TABLE
) {
485 rpc_sleep_on(&tbl
->slot_tbl_waitq
, task
, NULL
);
486 spin_unlock(&tbl
->slot_tbl_lock
);
487 dprintk("<-- %s: no free slots\n", __func__
);
490 spin_unlock(&tbl
->slot_tbl_lock
);
492 slot
= tbl
->slots
+ slotid
;
493 args
->sa_session
= session
;
494 args
->sa_slotid
= slotid
;
495 args
->sa_cache_this
= cache_reply
;
497 dprintk("<-- %s slotid=%d seqid=%d\n", __func__
, slotid
, slot
->seq_nr
);
499 res
->sr_session
= session
;
500 res
->sr_slotid
= slotid
;
501 res
->sr_renewal_time
= jiffies
;
503 * sr_status is only set in decode_sequence, and so will remain
504 * set to 1 if an rpc level failure occurs.
510 int nfs4_setup_sequence(struct nfs_client
*clp
,
511 struct nfs4_sequence_args
*args
,
512 struct nfs4_sequence_res
*res
,
514 struct rpc_task
*task
)
518 dprintk("--> %s clp %p session %p sr_slotid %d\n",
519 __func__
, clp
, clp
->cl_session
, res
->sr_slotid
);
521 if (!nfs4_has_session(clp
))
523 ret
= nfs41_setup_sequence(clp
->cl_session
, args
, res
, cache_reply
,
525 if (ret
!= -EAGAIN
) {
526 /* terminate rpc task */
527 task
->tk_status
= ret
;
528 task
->tk_action
= NULL
;
531 dprintk("<-- %s status=%d\n", __func__
, ret
);
535 struct nfs41_call_sync_data
{
536 struct nfs_client
*clp
;
537 struct nfs4_sequence_args
*seq_args
;
538 struct nfs4_sequence_res
*seq_res
;
542 static void nfs41_call_sync_prepare(struct rpc_task
*task
, void *calldata
)
544 struct nfs41_call_sync_data
*data
= calldata
;
546 dprintk("--> %s data->clp->cl_session %p\n", __func__
,
547 data
->clp
->cl_session
);
548 if (nfs4_setup_sequence(data
->clp
, data
->seq_args
,
549 data
->seq_res
, data
->cache_reply
, task
))
551 rpc_call_start(task
);
554 static void nfs41_call_sync_done(struct rpc_task
*task
, void *calldata
)
556 struct nfs41_call_sync_data
*data
= calldata
;
558 nfs41_sequence_done(data
->clp
, data
->seq_res
, task
->tk_status
);
559 nfs41_sequence_free_slot(data
->clp
, data
->seq_res
);
562 struct rpc_call_ops nfs41_call_sync_ops
= {
563 .rpc_call_prepare
= nfs41_call_sync_prepare
,
564 .rpc_call_done
= nfs41_call_sync_done
,
567 static int nfs4_call_sync_sequence(struct nfs_client
*clp
,
568 struct rpc_clnt
*clnt
,
569 struct rpc_message
*msg
,
570 struct nfs4_sequence_args
*args
,
571 struct nfs4_sequence_res
*res
,
575 struct rpc_task
*task
;
576 struct nfs41_call_sync_data data
= {
580 .cache_reply
= cache_reply
,
582 struct rpc_task_setup task_setup
= {
585 .callback_ops
= &nfs41_call_sync_ops
,
586 .callback_data
= &data
589 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
590 task
= rpc_run_task(&task_setup
);
594 ret
= task
->tk_status
;
600 int _nfs4_call_sync_session(struct nfs_server
*server
,
601 struct rpc_message
*msg
,
602 struct nfs4_sequence_args
*args
,
603 struct nfs4_sequence_res
*res
,
606 return nfs4_call_sync_sequence(server
->nfs_client
, server
->client
,
607 msg
, args
, res
, cache_reply
);
610 #endif /* CONFIG_NFS_V4_1 */
612 int _nfs4_call_sync(struct nfs_server
*server
,
613 struct rpc_message
*msg
,
614 struct nfs4_sequence_args
*args
,
615 struct nfs4_sequence_res
*res
,
618 args
->sa_session
= res
->sr_session
= NULL
;
619 return rpc_call_sync(server
->client
, msg
, 0);
622 #define nfs4_call_sync(server, msg, args, res, cache_reply) \
623 (server)->nfs_client->cl_call_sync((server), (msg), &(args)->seq_args, \
624 &(res)->seq_res, (cache_reply))
626 static void nfs4_sequence_done(const struct nfs_server
*server
,
627 struct nfs4_sequence_res
*res
, int rpc_status
)
629 #ifdef CONFIG_NFS_V4_1
630 if (nfs4_has_session(server
->nfs_client
))
631 nfs41_sequence_done(server
->nfs_client
, res
, rpc_status
);
632 #endif /* CONFIG_NFS_V4_1 */
635 /* no restart, therefore free slot here */
636 static void nfs4_sequence_done_free_slot(const struct nfs_server
*server
,
637 struct nfs4_sequence_res
*res
,
640 nfs4_sequence_done(server
, res
, rpc_status
);
641 nfs4_sequence_free_slot(server
->nfs_client
, res
);
644 static void update_changeattr(struct inode
*dir
, struct nfs4_change_info
*cinfo
)
646 struct nfs_inode
*nfsi
= NFS_I(dir
);
648 spin_lock(&dir
->i_lock
);
649 nfsi
->cache_validity
|= NFS_INO_INVALID_ATTR
|NFS_INO_REVAL_PAGECACHE
|NFS_INO_INVALID_DATA
;
650 if (!cinfo
->atomic
|| cinfo
->before
!= nfsi
->change_attr
)
651 nfs_force_lookup_revalidate(dir
);
652 nfsi
->change_attr
= cinfo
->after
;
653 spin_unlock(&dir
->i_lock
);
656 struct nfs4_opendata
{
658 struct nfs_openargs o_arg
;
659 struct nfs_openres o_res
;
660 struct nfs_open_confirmargs c_arg
;
661 struct nfs_open_confirmres c_res
;
662 struct nfs_fattr f_attr
;
663 struct nfs_fattr dir_attr
;
666 struct nfs4_state_owner
*owner
;
667 struct nfs4_state
*state
;
669 unsigned long timestamp
;
670 unsigned int rpc_done
: 1;
676 static void nfs4_init_opendata_res(struct nfs4_opendata
*p
)
678 p
->o_res
.f_attr
= &p
->f_attr
;
679 p
->o_res
.dir_attr
= &p
->dir_attr
;
680 p
->o_res
.seqid
= p
->o_arg
.seqid
;
681 p
->c_res
.seqid
= p
->c_arg
.seqid
;
682 p
->o_res
.server
= p
->o_arg
.server
;
683 nfs_fattr_init(&p
->f_attr
);
684 nfs_fattr_init(&p
->dir_attr
);
685 p
->o_res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
688 static struct nfs4_opendata
*nfs4_opendata_alloc(struct path
*path
,
689 struct nfs4_state_owner
*sp
, fmode_t fmode
, int flags
,
690 const struct iattr
*attrs
)
692 struct dentry
*parent
= dget_parent(path
->dentry
);
693 struct inode
*dir
= parent
->d_inode
;
694 struct nfs_server
*server
= NFS_SERVER(dir
);
695 struct nfs4_opendata
*p
;
697 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
700 p
->o_arg
.seqid
= nfs_alloc_seqid(&sp
->so_seqid
);
701 if (p
->o_arg
.seqid
== NULL
)
703 p
->path
.mnt
= mntget(path
->mnt
);
704 p
->path
.dentry
= dget(path
->dentry
);
707 atomic_inc(&sp
->so_count
);
708 p
->o_arg
.fh
= NFS_FH(dir
);
709 p
->o_arg
.open_flags
= flags
;
710 p
->o_arg
.fmode
= fmode
& (FMODE_READ
|FMODE_WRITE
);
711 p
->o_arg
.clientid
= server
->nfs_client
->cl_clientid
;
712 p
->o_arg
.id
= sp
->so_owner_id
.id
;
713 p
->o_arg
.name
= &p
->path
.dentry
->d_name
;
714 p
->o_arg
.server
= server
;
715 p
->o_arg
.bitmask
= server
->attr_bitmask
;
716 p
->o_arg
.claim
= NFS4_OPEN_CLAIM_NULL
;
717 if (flags
& O_EXCL
) {
718 u32
*s
= (u32
*) p
->o_arg
.u
.verifier
.data
;
721 } else if (flags
& O_CREAT
) {
722 p
->o_arg
.u
.attrs
= &p
->attrs
;
723 memcpy(&p
->attrs
, attrs
, sizeof(p
->attrs
));
725 p
->c_arg
.fh
= &p
->o_res
.fh
;
726 p
->c_arg
.stateid
= &p
->o_res
.stateid
;
727 p
->c_arg
.seqid
= p
->o_arg
.seqid
;
728 nfs4_init_opendata_res(p
);
738 static void nfs4_opendata_free(struct kref
*kref
)
740 struct nfs4_opendata
*p
= container_of(kref
,
741 struct nfs4_opendata
, kref
);
743 nfs_free_seqid(p
->o_arg
.seqid
);
744 if (p
->state
!= NULL
)
745 nfs4_put_open_state(p
->state
);
746 nfs4_put_state_owner(p
->owner
);
752 static void nfs4_opendata_put(struct nfs4_opendata
*p
)
755 kref_put(&p
->kref
, nfs4_opendata_free
);
758 static int nfs4_wait_for_completion_rpc_task(struct rpc_task
*task
)
762 ret
= rpc_wait_for_completion_task(task
);
766 static int can_open_cached(struct nfs4_state
*state
, fmode_t mode
, int open_mode
)
770 if (open_mode
& O_EXCL
)
772 switch (mode
& (FMODE_READ
|FMODE_WRITE
)) {
774 ret
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0;
777 ret
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0;
779 case FMODE_READ
|FMODE_WRITE
:
780 ret
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
) != 0;
786 static int can_open_delegated(struct nfs_delegation
*delegation
, fmode_t fmode
)
788 if ((delegation
->type
& fmode
) != fmode
)
790 if (test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
))
792 nfs_mark_delegation_referenced(delegation
);
796 static void update_open_stateflags(struct nfs4_state
*state
, fmode_t fmode
)
805 case FMODE_READ
|FMODE_WRITE
:
808 nfs4_state_set_mode_locked(state
, state
->state
| fmode
);
811 static void nfs_set_open_stateid_locked(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
813 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
814 memcpy(state
->stateid
.data
, stateid
->data
, sizeof(state
->stateid
.data
));
815 memcpy(state
->open_stateid
.data
, stateid
->data
, sizeof(state
->open_stateid
.data
));
818 set_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
821 set_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
823 case FMODE_READ
|FMODE_WRITE
:
824 set_bit(NFS_O_RDWR_STATE
, &state
->flags
);
828 static void nfs_set_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*stateid
, fmode_t fmode
)
830 write_seqlock(&state
->seqlock
);
831 nfs_set_open_stateid_locked(state
, stateid
, fmode
);
832 write_sequnlock(&state
->seqlock
);
835 static void __update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, const nfs4_stateid
*deleg_stateid
, fmode_t fmode
)
838 * Protect the call to nfs4_state_set_mode_locked and
839 * serialise the stateid update
841 write_seqlock(&state
->seqlock
);
842 if (deleg_stateid
!= NULL
) {
843 memcpy(state
->stateid
.data
, deleg_stateid
->data
, sizeof(state
->stateid
.data
));
844 set_bit(NFS_DELEGATED_STATE
, &state
->flags
);
846 if (open_stateid
!= NULL
)
847 nfs_set_open_stateid_locked(state
, open_stateid
, fmode
);
848 write_sequnlock(&state
->seqlock
);
849 spin_lock(&state
->owner
->so_lock
);
850 update_open_stateflags(state
, fmode
);
851 spin_unlock(&state
->owner
->so_lock
);
854 static int update_open_stateid(struct nfs4_state
*state
, nfs4_stateid
*open_stateid
, nfs4_stateid
*delegation
, fmode_t fmode
)
856 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
857 struct nfs_delegation
*deleg_cur
;
860 fmode
&= (FMODE_READ
|FMODE_WRITE
);
863 deleg_cur
= rcu_dereference(nfsi
->delegation
);
864 if (deleg_cur
== NULL
)
867 spin_lock(&deleg_cur
->lock
);
868 if (nfsi
->delegation
!= deleg_cur
||
869 (deleg_cur
->type
& fmode
) != fmode
)
870 goto no_delegation_unlock
;
872 if (delegation
== NULL
)
873 delegation
= &deleg_cur
->stateid
;
874 else if (memcmp(deleg_cur
->stateid
.data
, delegation
->data
, NFS4_STATEID_SIZE
) != 0)
875 goto no_delegation_unlock
;
877 nfs_mark_delegation_referenced(deleg_cur
);
878 __update_open_stateid(state
, open_stateid
, &deleg_cur
->stateid
, fmode
);
880 no_delegation_unlock
:
881 spin_unlock(&deleg_cur
->lock
);
885 if (!ret
&& open_stateid
!= NULL
) {
886 __update_open_stateid(state
, open_stateid
, NULL
, fmode
);
894 static void nfs4_return_incompatible_delegation(struct inode
*inode
, fmode_t fmode
)
896 struct nfs_delegation
*delegation
;
899 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
900 if (delegation
== NULL
|| (delegation
->type
& fmode
) == fmode
) {
905 nfs_inode_return_delegation(inode
);
908 static struct nfs4_state
*nfs4_try_open_cached(struct nfs4_opendata
*opendata
)
910 struct nfs4_state
*state
= opendata
->state
;
911 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
912 struct nfs_delegation
*delegation
;
913 int open_mode
= opendata
->o_arg
.open_flags
& O_EXCL
;
914 fmode_t fmode
= opendata
->o_arg
.fmode
;
915 nfs4_stateid stateid
;
919 if (can_open_cached(state
, fmode
, open_mode
)) {
920 spin_lock(&state
->owner
->so_lock
);
921 if (can_open_cached(state
, fmode
, open_mode
)) {
922 update_open_stateflags(state
, fmode
);
923 spin_unlock(&state
->owner
->so_lock
);
924 goto out_return_state
;
926 spin_unlock(&state
->owner
->so_lock
);
929 delegation
= rcu_dereference(nfsi
->delegation
);
930 if (delegation
== NULL
||
931 !can_open_delegated(delegation
, fmode
)) {
935 /* Save the delegation */
936 memcpy(stateid
.data
, delegation
->stateid
.data
, sizeof(stateid
.data
));
938 ret
= nfs_may_open(state
->inode
, state
->owner
->so_cred
, open_mode
);
943 /* Try to update the stateid using the delegation */
944 if (update_open_stateid(state
, NULL
, &stateid
, fmode
))
945 goto out_return_state
;
950 atomic_inc(&state
->count
);
954 static struct nfs4_state
*nfs4_opendata_to_nfs4_state(struct nfs4_opendata
*data
)
957 struct nfs4_state
*state
= NULL
;
958 struct nfs_delegation
*delegation
;
961 if (!data
->rpc_done
) {
962 state
= nfs4_try_open_cached(data
);
967 if (!(data
->f_attr
.valid
& NFS_ATTR_FATTR
))
969 inode
= nfs_fhget(data
->dir
->d_sb
, &data
->o_res
.fh
, &data
->f_attr
);
970 ret
= PTR_ERR(inode
);
974 state
= nfs4_get_open_state(inode
, data
->owner
);
977 if (data
->o_res
.delegation_type
!= 0) {
978 int delegation_flags
= 0;
981 delegation
= rcu_dereference(NFS_I(inode
)->delegation
);
983 delegation_flags
= delegation
->flags
;
985 if ((delegation_flags
& 1UL<<NFS_DELEGATION_NEED_RECLAIM
) == 0)
986 nfs_inode_set_delegation(state
->inode
,
987 data
->owner
->so_cred
,
990 nfs_inode_reclaim_delegation(state
->inode
,
991 data
->owner
->so_cred
,
995 update_open_stateid(state
, &data
->o_res
.stateid
, NULL
,
1003 return ERR_PTR(ret
);
1006 static struct nfs_open_context
*nfs4_state_find_open_context(struct nfs4_state
*state
)
1008 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
1009 struct nfs_open_context
*ctx
;
1011 spin_lock(&state
->inode
->i_lock
);
1012 list_for_each_entry(ctx
, &nfsi
->open_files
, list
) {
1013 if (ctx
->state
!= state
)
1015 get_nfs_open_context(ctx
);
1016 spin_unlock(&state
->inode
->i_lock
);
1019 spin_unlock(&state
->inode
->i_lock
);
1020 return ERR_PTR(-ENOENT
);
1023 static struct nfs4_opendata
*nfs4_open_recoverdata_alloc(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1025 struct nfs4_opendata
*opendata
;
1027 opendata
= nfs4_opendata_alloc(&ctx
->path
, state
->owner
, 0, 0, NULL
);
1028 if (opendata
== NULL
)
1029 return ERR_PTR(-ENOMEM
);
1030 opendata
->state
= state
;
1031 atomic_inc(&state
->count
);
1035 static int nfs4_open_recover_helper(struct nfs4_opendata
*opendata
, fmode_t fmode
, struct nfs4_state
**res
)
1037 struct nfs4_state
*newstate
;
1040 opendata
->o_arg
.open_flags
= 0;
1041 opendata
->o_arg
.fmode
= fmode
;
1042 memset(&opendata
->o_res
, 0, sizeof(opendata
->o_res
));
1043 memset(&opendata
->c_res
, 0, sizeof(opendata
->c_res
));
1044 nfs4_init_opendata_res(opendata
);
1045 ret
= _nfs4_proc_open(opendata
);
1048 newstate
= nfs4_opendata_to_nfs4_state(opendata
);
1049 if (IS_ERR(newstate
))
1050 return PTR_ERR(newstate
);
1051 nfs4_close_state(&opendata
->path
, newstate
, fmode
);
1056 static int nfs4_open_recover(struct nfs4_opendata
*opendata
, struct nfs4_state
*state
)
1058 struct nfs4_state
*newstate
;
1061 /* memory barrier prior to reading state->n_* */
1062 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1064 if (state
->n_rdwr
!= 0) {
1065 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
|FMODE_WRITE
, &newstate
);
1068 if (newstate
!= state
)
1071 if (state
->n_wronly
!= 0) {
1072 ret
= nfs4_open_recover_helper(opendata
, FMODE_WRITE
, &newstate
);
1075 if (newstate
!= state
)
1078 if (state
->n_rdonly
!= 0) {
1079 ret
= nfs4_open_recover_helper(opendata
, FMODE_READ
, &newstate
);
1082 if (newstate
!= state
)
1086 * We may have performed cached opens for all three recoveries.
1087 * Check if we need to update the current stateid.
1089 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0 &&
1090 memcmp(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
)) != 0) {
1091 write_seqlock(&state
->seqlock
);
1092 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) == 0)
1093 memcpy(state
->stateid
.data
, state
->open_stateid
.data
, sizeof(state
->stateid
.data
));
1094 write_sequnlock(&state
->seqlock
);
1101 * reclaim state on the server after a reboot.
1103 static int _nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1105 struct nfs_delegation
*delegation
;
1106 struct nfs4_opendata
*opendata
;
1107 fmode_t delegation_type
= 0;
1110 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1111 if (IS_ERR(opendata
))
1112 return PTR_ERR(opendata
);
1113 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_PREVIOUS
;
1114 opendata
->o_arg
.fh
= NFS_FH(state
->inode
);
1116 delegation
= rcu_dereference(NFS_I(state
->inode
)->delegation
);
1117 if (delegation
!= NULL
&& test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) != 0)
1118 delegation_type
= delegation
->type
;
1120 opendata
->o_arg
.u
.delegation_type
= delegation_type
;
1121 status
= nfs4_open_recover(opendata
, state
);
1122 nfs4_opendata_put(opendata
);
1126 static int nfs4_do_open_reclaim(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1128 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1129 struct nfs4_exception exception
= { };
1132 err
= _nfs4_do_open_reclaim(ctx
, state
);
1133 if (err
!= -NFS4ERR_DELAY
)
1135 nfs4_handle_exception(server
, err
, &exception
);
1136 } while (exception
.retry
);
1140 static int nfs4_open_reclaim(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1142 struct nfs_open_context
*ctx
;
1145 ctx
= nfs4_state_find_open_context(state
);
1147 return PTR_ERR(ctx
);
1148 ret
= nfs4_do_open_reclaim(ctx
, state
);
1149 put_nfs_open_context(ctx
);
1153 static int _nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1155 struct nfs4_opendata
*opendata
;
1158 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1159 if (IS_ERR(opendata
))
1160 return PTR_ERR(opendata
);
1161 opendata
->o_arg
.claim
= NFS4_OPEN_CLAIM_DELEGATE_CUR
;
1162 memcpy(opendata
->o_arg
.u
.delegation
.data
, stateid
->data
,
1163 sizeof(opendata
->o_arg
.u
.delegation
.data
));
1164 ret
= nfs4_open_recover(opendata
, state
);
1165 nfs4_opendata_put(opendata
);
1169 int nfs4_open_delegation_recall(struct nfs_open_context
*ctx
, struct nfs4_state
*state
, const nfs4_stateid
*stateid
)
1171 struct nfs4_exception exception
= { };
1172 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1175 err
= _nfs4_open_delegation_recall(ctx
, state
, stateid
);
1181 case -NFS4ERR_STALE_CLIENTID
:
1182 case -NFS4ERR_STALE_STATEID
:
1183 case -NFS4ERR_EXPIRED
:
1184 /* Don't recall a delegation if it was lost */
1185 nfs4_schedule_state_recovery(server
->nfs_client
);
1189 * The show must go on: exit, but mark the
1190 * stateid as needing recovery.
1192 case -NFS4ERR_ADMIN_REVOKED
:
1193 case -NFS4ERR_BAD_STATEID
:
1194 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
1199 err
= nfs4_handle_exception(server
, err
, &exception
);
1200 } while (exception
.retry
);
1205 static void nfs4_open_confirm_done(struct rpc_task
*task
, void *calldata
)
1207 struct nfs4_opendata
*data
= calldata
;
1209 data
->rpc_status
= task
->tk_status
;
1210 if (RPC_ASSASSINATED(task
))
1212 if (data
->rpc_status
== 0) {
1213 memcpy(data
->o_res
.stateid
.data
, data
->c_res
.stateid
.data
,
1214 sizeof(data
->o_res
.stateid
.data
));
1215 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1216 renew_lease(data
->o_res
.server
, data
->timestamp
);
1221 static void nfs4_open_confirm_release(void *calldata
)
1223 struct nfs4_opendata
*data
= calldata
;
1224 struct nfs4_state
*state
= NULL
;
1226 /* If this request hasn't been cancelled, do nothing */
1227 if (data
->cancelled
== 0)
1229 /* In case of error, no cleanup! */
1230 if (!data
->rpc_done
)
1232 state
= nfs4_opendata_to_nfs4_state(data
);
1234 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1236 nfs4_opendata_put(data
);
1239 static const struct rpc_call_ops nfs4_open_confirm_ops
= {
1240 .rpc_call_done
= nfs4_open_confirm_done
,
1241 .rpc_release
= nfs4_open_confirm_release
,
1245 * Note: On error, nfs4_proc_open_confirm will free the struct nfs4_opendata
1247 static int _nfs4_proc_open_confirm(struct nfs4_opendata
*data
)
1249 struct nfs_server
*server
= NFS_SERVER(data
->dir
->d_inode
);
1250 struct rpc_task
*task
;
1251 struct rpc_message msg
= {
1252 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_CONFIRM
],
1253 .rpc_argp
= &data
->c_arg
,
1254 .rpc_resp
= &data
->c_res
,
1255 .rpc_cred
= data
->owner
->so_cred
,
1257 struct rpc_task_setup task_setup_data
= {
1258 .rpc_client
= server
->client
,
1259 .rpc_message
= &msg
,
1260 .callback_ops
= &nfs4_open_confirm_ops
,
1261 .callback_data
= data
,
1262 .workqueue
= nfsiod_workqueue
,
1263 .flags
= RPC_TASK_ASYNC
,
1267 kref_get(&data
->kref
);
1269 data
->rpc_status
= 0;
1270 data
->timestamp
= jiffies
;
1271 task
= rpc_run_task(&task_setup_data
);
1273 return PTR_ERR(task
);
1274 status
= nfs4_wait_for_completion_rpc_task(task
);
1276 data
->cancelled
= 1;
1279 status
= data
->rpc_status
;
1284 static void nfs4_open_prepare(struct rpc_task
*task
, void *calldata
)
1286 struct nfs4_opendata
*data
= calldata
;
1287 struct nfs4_state_owner
*sp
= data
->owner
;
1289 if (nfs_wait_on_sequence(data
->o_arg
.seqid
, task
) != 0)
1292 * Check if we still need to send an OPEN call, or if we can use
1293 * a delegation instead.
1295 if (data
->state
!= NULL
) {
1296 struct nfs_delegation
*delegation
;
1298 if (can_open_cached(data
->state
, data
->o_arg
.fmode
, data
->o_arg
.open_flags
))
1301 delegation
= rcu_dereference(NFS_I(data
->state
->inode
)->delegation
);
1302 if (delegation
!= NULL
&&
1303 test_bit(NFS_DELEGATION_NEED_RECLAIM
, &delegation
->flags
) == 0) {
1309 /* Update sequence id. */
1310 data
->o_arg
.id
= sp
->so_owner_id
.id
;
1311 data
->o_arg
.clientid
= sp
->so_client
->cl_clientid
;
1312 if (data
->o_arg
.claim
== NFS4_OPEN_CLAIM_PREVIOUS
) {
1313 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_NOATTR
];
1314 nfs_copy_fh(&data
->o_res
.fh
, data
->o_arg
.fh
);
1316 data
->timestamp
= jiffies
;
1317 if (nfs4_setup_sequence(data
->o_arg
.server
->nfs_client
,
1318 &data
->o_arg
.seq_args
,
1319 &data
->o_res
.seq_res
, 1, task
))
1321 rpc_call_start(task
);
1324 task
->tk_action
= NULL
;
1328 static void nfs4_open_done(struct rpc_task
*task
, void *calldata
)
1330 struct nfs4_opendata
*data
= calldata
;
1332 data
->rpc_status
= task
->tk_status
;
1334 nfs4_sequence_done_free_slot(data
->o_arg
.server
, &data
->o_res
.seq_res
,
1337 if (RPC_ASSASSINATED(task
))
1339 if (task
->tk_status
== 0) {
1340 switch (data
->o_res
.f_attr
->mode
& S_IFMT
) {
1344 data
->rpc_status
= -ELOOP
;
1347 data
->rpc_status
= -EISDIR
;
1350 data
->rpc_status
= -ENOTDIR
;
1352 renew_lease(data
->o_res
.server
, data
->timestamp
);
1353 if (!(data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
))
1354 nfs_confirm_seqid(&data
->owner
->so_seqid
, 0);
1359 static void nfs4_open_release(void *calldata
)
1361 struct nfs4_opendata
*data
= calldata
;
1362 struct nfs4_state
*state
= NULL
;
1364 /* If this request hasn't been cancelled, do nothing */
1365 if (data
->cancelled
== 0)
1367 /* In case of error, no cleanup! */
1368 if (data
->rpc_status
!= 0 || !data
->rpc_done
)
1370 /* In case we need an open_confirm, no cleanup! */
1371 if (data
->o_res
.rflags
& NFS4_OPEN_RESULT_CONFIRM
)
1373 state
= nfs4_opendata_to_nfs4_state(data
);
1375 nfs4_close_state(&data
->path
, state
, data
->o_arg
.fmode
);
1377 nfs4_opendata_put(data
);
1380 static const struct rpc_call_ops nfs4_open_ops
= {
1381 .rpc_call_prepare
= nfs4_open_prepare
,
1382 .rpc_call_done
= nfs4_open_done
,
1383 .rpc_release
= nfs4_open_release
,
1387 * Note: On error, nfs4_proc_open will free the struct nfs4_opendata
1389 static int _nfs4_proc_open(struct nfs4_opendata
*data
)
1391 struct inode
*dir
= data
->dir
->d_inode
;
1392 struct nfs_server
*server
= NFS_SERVER(dir
);
1393 struct nfs_openargs
*o_arg
= &data
->o_arg
;
1394 struct nfs_openres
*o_res
= &data
->o_res
;
1395 struct rpc_task
*task
;
1396 struct rpc_message msg
= {
1397 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN
],
1400 .rpc_cred
= data
->owner
->so_cred
,
1402 struct rpc_task_setup task_setup_data
= {
1403 .rpc_client
= server
->client
,
1404 .rpc_message
= &msg
,
1405 .callback_ops
= &nfs4_open_ops
,
1406 .callback_data
= data
,
1407 .workqueue
= nfsiod_workqueue
,
1408 .flags
= RPC_TASK_ASYNC
,
1412 kref_get(&data
->kref
);
1414 data
->rpc_status
= 0;
1415 data
->cancelled
= 0;
1416 task
= rpc_run_task(&task_setup_data
);
1418 return PTR_ERR(task
);
1419 status
= nfs4_wait_for_completion_rpc_task(task
);
1421 data
->cancelled
= 1;
1424 status
= data
->rpc_status
;
1426 if (status
!= 0 || !data
->rpc_done
)
1429 if (o_res
->fh
.size
== 0)
1430 _nfs4_proc_lookup(dir
, o_arg
->name
, &o_res
->fh
, o_res
->f_attr
);
1432 if (o_arg
->open_flags
& O_CREAT
) {
1433 update_changeattr(dir
, &o_res
->cinfo
);
1434 nfs_post_op_update_inode(dir
, o_res
->dir_attr
);
1436 nfs_refresh_inode(dir
, o_res
->dir_attr
);
1437 if(o_res
->rflags
& NFS4_OPEN_RESULT_CONFIRM
) {
1438 status
= _nfs4_proc_open_confirm(data
);
1442 if (!(o_res
->f_attr
->valid
& NFS_ATTR_FATTR
))
1443 _nfs4_proc_getattr(server
, &o_res
->fh
, o_res
->f_attr
);
1447 static int nfs4_recover_expired_lease(struct nfs_server
*server
)
1449 struct nfs_client
*clp
= server
->nfs_client
;
1453 for (loop
= NFS4_MAX_LOOP_ON_RECOVER
; loop
!= 0; loop
--) {
1454 ret
= nfs4_wait_clnt_recover(clp
);
1457 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) &&
1458 !test_bit(NFS4CLNT_CHECK_LEASE
,&clp
->cl_state
))
1460 nfs4_schedule_state_recovery(clp
);
1468 * reclaim state on the server after a network partition.
1469 * Assumes caller holds the appropriate lock
1471 static int _nfs4_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1473 struct nfs4_opendata
*opendata
;
1476 opendata
= nfs4_open_recoverdata_alloc(ctx
, state
);
1477 if (IS_ERR(opendata
))
1478 return PTR_ERR(opendata
);
1479 ret
= nfs4_open_recover(opendata
, state
);
1481 d_drop(ctx
->path
.dentry
);
1482 nfs4_opendata_put(opendata
);
1486 static inline int nfs4_do_open_expired(struct nfs_open_context
*ctx
, struct nfs4_state
*state
)
1488 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1489 struct nfs4_exception exception
= { };
1493 err
= _nfs4_open_expired(ctx
, state
);
1494 if (err
!= -NFS4ERR_DELAY
)
1496 nfs4_handle_exception(server
, err
, &exception
);
1497 } while (exception
.retry
);
1501 static int nfs4_open_expired(struct nfs4_state_owner
*sp
, struct nfs4_state
*state
)
1503 struct nfs_open_context
*ctx
;
1506 ctx
= nfs4_state_find_open_context(state
);
1508 return PTR_ERR(ctx
);
1509 ret
= nfs4_do_open_expired(ctx
, state
);
1510 put_nfs_open_context(ctx
);
1515 * on an EXCLUSIVE create, the server should send back a bitmask with FATTR4-*
1516 * fields corresponding to attributes that were used to store the verifier.
1517 * Make sure we clobber those fields in the later setattr call
1519 static inline void nfs4_exclusive_attrset(struct nfs4_opendata
*opendata
, struct iattr
*sattr
)
1521 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_ACCESS
) &&
1522 !(sattr
->ia_valid
& ATTR_ATIME_SET
))
1523 sattr
->ia_valid
|= ATTR_ATIME
;
1525 if ((opendata
->o_res
.attrset
[1] & FATTR4_WORD1_TIME_MODIFY
) &&
1526 !(sattr
->ia_valid
& ATTR_MTIME_SET
))
1527 sattr
->ia_valid
|= ATTR_MTIME
;
1531 * Returns a referenced nfs4_state
1533 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
)
1535 struct nfs4_state_owner
*sp
;
1536 struct nfs4_state
*state
= NULL
;
1537 struct nfs_server
*server
= NFS_SERVER(dir
);
1538 struct nfs4_opendata
*opendata
;
1541 /* Protect against reboot recovery conflicts */
1543 if (!(sp
= nfs4_get_state_owner(server
, cred
))) {
1544 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1547 status
= nfs4_recover_expired_lease(server
);
1549 goto err_put_state_owner
;
1550 if (path
->dentry
->d_inode
!= NULL
)
1551 nfs4_return_incompatible_delegation(path
->dentry
->d_inode
, fmode
);
1553 opendata
= nfs4_opendata_alloc(path
, sp
, fmode
, flags
, sattr
);
1554 if (opendata
== NULL
)
1555 goto err_put_state_owner
;
1557 if (path
->dentry
->d_inode
!= NULL
)
1558 opendata
->state
= nfs4_get_open_state(path
->dentry
->d_inode
, sp
);
1560 status
= _nfs4_proc_open(opendata
);
1562 goto err_opendata_put
;
1564 if (opendata
->o_arg
.open_flags
& O_EXCL
)
1565 nfs4_exclusive_attrset(opendata
, sattr
);
1567 state
= nfs4_opendata_to_nfs4_state(opendata
);
1568 status
= PTR_ERR(state
);
1570 goto err_opendata_put
;
1571 nfs4_opendata_put(opendata
);
1572 nfs4_put_state_owner(sp
);
1576 nfs4_opendata_put(opendata
);
1577 err_put_state_owner
:
1578 nfs4_put_state_owner(sp
);
1585 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
)
1587 struct nfs4_exception exception
= { };
1588 struct nfs4_state
*res
;
1592 status
= _nfs4_do_open(dir
, path
, fmode
, flags
, sattr
, cred
, &res
);
1595 /* NOTE: BAD_SEQID means the server and client disagree about the
1596 * book-keeping w.r.t. state-changing operations
1597 * (OPEN/CLOSE/LOCK/LOCKU...)
1598 * It is actually a sign of a bug on the client or on the server.
1600 * If we receive a BAD_SEQID error in the particular case of
1601 * doing an OPEN, we assume that nfs_increment_open_seqid() will
1602 * have unhashed the old state_owner for us, and that we can
1603 * therefore safely retry using a new one. We should still warn
1604 * the user though...
1606 if (status
== -NFS4ERR_BAD_SEQID
) {
1607 printk(KERN_WARNING
"NFS: v4 server %s "
1608 " returned a bad sequence-id error!\n",
1609 NFS_SERVER(dir
)->nfs_client
->cl_hostname
);
1610 exception
.retry
= 1;
1614 * BAD_STATEID on OPEN means that the server cancelled our
1615 * state before it received the OPEN_CONFIRM.
1616 * Recover by retrying the request as per the discussion
1617 * on Page 181 of RFC3530.
1619 if (status
== -NFS4ERR_BAD_STATEID
) {
1620 exception
.retry
= 1;
1623 if (status
== -EAGAIN
) {
1624 /* We must have found a delegation */
1625 exception
.retry
= 1;
1628 res
= ERR_PTR(nfs4_handle_exception(NFS_SERVER(dir
),
1629 status
, &exception
));
1630 } while (exception
.retry
);
1634 static int _nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1635 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1636 struct nfs4_state
*state
)
1638 struct nfs_server
*server
= NFS_SERVER(inode
);
1639 struct nfs_setattrargs arg
= {
1640 .fh
= NFS_FH(inode
),
1643 .bitmask
= server
->attr_bitmask
,
1645 struct nfs_setattrres res
= {
1649 struct rpc_message msg
= {
1650 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETATTR
],
1655 unsigned long timestamp
= jiffies
;
1658 nfs_fattr_init(fattr
);
1660 if (nfs4_copy_delegation_stateid(&arg
.stateid
, inode
)) {
1661 /* Use that stateid */
1662 } else if (state
!= NULL
) {
1663 nfs4_copy_stateid(&arg
.stateid
, state
, current
->files
);
1665 memcpy(&arg
.stateid
, &zero_stateid
, sizeof(arg
.stateid
));
1667 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
1668 if (status
== 0 && state
!= NULL
)
1669 renew_lease(server
, timestamp
);
1673 static int nfs4_do_setattr(struct inode
*inode
, struct rpc_cred
*cred
,
1674 struct nfs_fattr
*fattr
, struct iattr
*sattr
,
1675 struct nfs4_state
*state
)
1677 struct nfs_server
*server
= NFS_SERVER(inode
);
1678 struct nfs4_exception exception
= { };
1681 err
= nfs4_handle_exception(server
,
1682 _nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
),
1684 } while (exception
.retry
);
1688 struct nfs4_closedata
{
1690 struct inode
*inode
;
1691 struct nfs4_state
*state
;
1692 struct nfs_closeargs arg
;
1693 struct nfs_closeres res
;
1694 struct nfs_fattr fattr
;
1695 unsigned long timestamp
;
1698 static void nfs4_free_closedata(void *data
)
1700 struct nfs4_closedata
*calldata
= data
;
1701 struct nfs4_state_owner
*sp
= calldata
->state
->owner
;
1703 nfs4_put_open_state(calldata
->state
);
1704 nfs_free_seqid(calldata
->arg
.seqid
);
1705 nfs4_put_state_owner(sp
);
1706 path_put(&calldata
->path
);
1710 static void nfs4_close_done(struct rpc_task
*task
, void *data
)
1712 struct nfs4_closedata
*calldata
= data
;
1713 struct nfs4_state
*state
= calldata
->state
;
1714 struct nfs_server
*server
= NFS_SERVER(calldata
->inode
);
1716 nfs4_sequence_done(server
, &calldata
->res
.seq_res
, task
->tk_status
);
1717 if (RPC_ASSASSINATED(task
))
1719 /* hmm. we are done with the inode, and in the process of freeing
1720 * the state_owner. we keep this around to process errors
1722 switch (task
->tk_status
) {
1724 nfs_set_open_stateid(state
, &calldata
->res
.stateid
, 0);
1725 renew_lease(server
, calldata
->timestamp
);
1727 case -NFS4ERR_STALE_STATEID
:
1728 case -NFS4ERR_OLD_STATEID
:
1729 case -NFS4ERR_BAD_STATEID
:
1730 case -NFS4ERR_EXPIRED
:
1731 if (calldata
->arg
.fmode
== 0)
1734 if (nfs4_async_handle_error(task
, server
, state
) == -EAGAIN
) {
1735 nfs4_restart_rpc(task
, server
->nfs_client
);
1739 nfs4_sequence_free_slot(server
->nfs_client
, &calldata
->res
.seq_res
);
1740 nfs_refresh_inode(calldata
->inode
, calldata
->res
.fattr
);
1743 static void nfs4_close_prepare(struct rpc_task
*task
, void *data
)
1745 struct nfs4_closedata
*calldata
= data
;
1746 struct nfs4_state
*state
= calldata
->state
;
1747 int clear_rd
, clear_wr
, clear_rdwr
;
1749 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
1752 clear_rd
= clear_wr
= clear_rdwr
= 0;
1753 spin_lock(&state
->owner
->so_lock
);
1754 /* Calculate the change in open mode */
1755 if (state
->n_rdwr
== 0) {
1756 if (state
->n_rdonly
== 0) {
1757 clear_rd
|= test_and_clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1758 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1760 if (state
->n_wronly
== 0) {
1761 clear_wr
|= test_and_clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1762 clear_rdwr
|= test_and_clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1765 spin_unlock(&state
->owner
->so_lock
);
1766 if (!clear_rd
&& !clear_wr
&& !clear_rdwr
) {
1767 /* Note: exit _without_ calling nfs4_close_done */
1768 task
->tk_action
= NULL
;
1771 nfs_fattr_init(calldata
->res
.fattr
);
1772 if (test_bit(NFS_O_RDONLY_STATE
, &state
->flags
) != 0) {
1773 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1774 calldata
->arg
.fmode
= FMODE_READ
;
1775 } else if (test_bit(NFS_O_WRONLY_STATE
, &state
->flags
) != 0) {
1776 task
->tk_msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_OPEN_DOWNGRADE
];
1777 calldata
->arg
.fmode
= FMODE_WRITE
;
1779 calldata
->timestamp
= jiffies
;
1780 if (nfs4_setup_sequence((NFS_SERVER(calldata
->inode
))->nfs_client
,
1781 &calldata
->arg
.seq_args
, &calldata
->res
.seq_res
,
1784 rpc_call_start(task
);
1787 static const struct rpc_call_ops nfs4_close_ops
= {
1788 .rpc_call_prepare
= nfs4_close_prepare
,
1789 .rpc_call_done
= nfs4_close_done
,
1790 .rpc_release
= nfs4_free_closedata
,
1794 * It is possible for data to be read/written from a mem-mapped file
1795 * after the sys_close call (which hits the vfs layer as a flush).
1796 * This means that we can't safely call nfsv4 close on a file until
1797 * the inode is cleared. This in turn means that we are not good
1798 * NFSv4 citizens - we do not indicate to the server to update the file's
1799 * share state even when we are done with one of the three share
1800 * stateid's in the inode.
1802 * NOTE: Caller must be holding the sp->so_owner semaphore!
1804 int nfs4_do_close(struct path
*path
, struct nfs4_state
*state
, int wait
)
1806 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
1807 struct nfs4_closedata
*calldata
;
1808 struct nfs4_state_owner
*sp
= state
->owner
;
1809 struct rpc_task
*task
;
1810 struct rpc_message msg
= {
1811 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CLOSE
],
1812 .rpc_cred
= state
->owner
->so_cred
,
1814 struct rpc_task_setup task_setup_data
= {
1815 .rpc_client
= server
->client
,
1816 .rpc_message
= &msg
,
1817 .callback_ops
= &nfs4_close_ops
,
1818 .workqueue
= nfsiod_workqueue
,
1819 .flags
= RPC_TASK_ASYNC
,
1821 int status
= -ENOMEM
;
1823 calldata
= kzalloc(sizeof(*calldata
), GFP_KERNEL
);
1824 if (calldata
== NULL
)
1826 calldata
->inode
= state
->inode
;
1827 calldata
->state
= state
;
1828 calldata
->arg
.fh
= NFS_FH(state
->inode
);
1829 calldata
->arg
.stateid
= &state
->open_stateid
;
1830 if (nfs4_has_session(server
->nfs_client
))
1831 memset(calldata
->arg
.stateid
->data
, 0, 4); /* clear seqid */
1832 /* Serialization for the sequence id */
1833 calldata
->arg
.seqid
= nfs_alloc_seqid(&state
->owner
->so_seqid
);
1834 if (calldata
->arg
.seqid
== NULL
)
1835 goto out_free_calldata
;
1836 calldata
->arg
.fmode
= 0;
1837 calldata
->arg
.bitmask
= server
->cache_consistency_bitmask
;
1838 calldata
->res
.fattr
= &calldata
->fattr
;
1839 calldata
->res
.seqid
= calldata
->arg
.seqid
;
1840 calldata
->res
.server
= server
;
1841 calldata
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
1842 calldata
->path
.mnt
= mntget(path
->mnt
);
1843 calldata
->path
.dentry
= dget(path
->dentry
);
1845 msg
.rpc_argp
= &calldata
->arg
,
1846 msg
.rpc_resp
= &calldata
->res
,
1847 task_setup_data
.callback_data
= calldata
;
1848 task
= rpc_run_task(&task_setup_data
);
1850 return PTR_ERR(task
);
1853 status
= rpc_wait_for_completion_task(task
);
1859 nfs4_put_open_state(state
);
1860 nfs4_put_state_owner(sp
);
1864 static int nfs4_intent_set_file(struct nameidata
*nd
, struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
)
1869 /* If the open_intent is for execute, we have an extra check to make */
1870 if (fmode
& FMODE_EXEC
) {
1871 ret
= nfs_may_open(state
->inode
,
1872 state
->owner
->so_cred
,
1873 nd
->intent
.open
.flags
);
1877 filp
= lookup_instantiate_filp(nd
, path
->dentry
, NULL
);
1878 if (!IS_ERR(filp
)) {
1879 struct nfs_open_context
*ctx
;
1880 ctx
= nfs_file_open_context(filp
);
1884 ret
= PTR_ERR(filp
);
1886 nfs4_close_sync(path
, state
, fmode
& (FMODE_READ
|FMODE_WRITE
));
1891 nfs4_atomic_open(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
1893 struct path path
= {
1894 .mnt
= nd
->path
.mnt
,
1897 struct dentry
*parent
;
1899 struct rpc_cred
*cred
;
1900 struct nfs4_state
*state
;
1902 fmode_t fmode
= nd
->intent
.open
.flags
& (FMODE_READ
| FMODE_WRITE
| FMODE_EXEC
);
1904 if (nd
->flags
& LOOKUP_CREATE
) {
1905 attr
.ia_mode
= nd
->intent
.open
.create_mode
;
1906 attr
.ia_valid
= ATTR_MODE
;
1907 if (!IS_POSIXACL(dir
))
1908 attr
.ia_mode
&= ~current_umask();
1911 BUG_ON(nd
->intent
.open
.flags
& O_CREAT
);
1914 cred
= rpc_lookup_cred();
1916 return (struct dentry
*)cred
;
1917 parent
= dentry
->d_parent
;
1918 /* Protect against concurrent sillydeletes */
1919 nfs_block_sillyrename(parent
);
1920 state
= nfs4_do_open(dir
, &path
, fmode
, nd
->intent
.open
.flags
, &attr
, cred
);
1922 if (IS_ERR(state
)) {
1923 if (PTR_ERR(state
) == -ENOENT
) {
1924 d_add(dentry
, NULL
);
1925 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1927 nfs_unblock_sillyrename(parent
);
1928 return (struct dentry
*)state
;
1930 res
= d_add_unique(dentry
, igrab(state
->inode
));
1933 nfs_set_verifier(path
.dentry
, nfs_save_change_attribute(dir
));
1934 nfs_unblock_sillyrename(parent
);
1935 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
1940 nfs4_open_revalidate(struct inode
*dir
, struct dentry
*dentry
, int openflags
, struct nameidata
*nd
)
1942 struct path path
= {
1943 .mnt
= nd
->path
.mnt
,
1946 struct rpc_cred
*cred
;
1947 struct nfs4_state
*state
;
1948 fmode_t fmode
= openflags
& (FMODE_READ
| FMODE_WRITE
);
1950 cred
= rpc_lookup_cred();
1952 return PTR_ERR(cred
);
1953 state
= nfs4_do_open(dir
, &path
, fmode
, openflags
, NULL
, cred
);
1955 if (IS_ERR(state
)) {
1956 switch (PTR_ERR(state
)) {
1962 lookup_instantiate_filp(nd
, (struct dentry
*)state
, NULL
);
1968 if (state
->inode
== dentry
->d_inode
) {
1969 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
1970 nfs4_intent_set_file(nd
, &path
, state
, fmode
);
1973 nfs4_close_sync(&path
, state
, fmode
);
1979 void nfs4_close_context(struct nfs_open_context
*ctx
, int is_sync
)
1981 if (ctx
->state
== NULL
)
1984 nfs4_close_sync(&ctx
->path
, ctx
->state
, ctx
->mode
);
1986 nfs4_close_state(&ctx
->path
, ctx
->state
, ctx
->mode
);
1989 static int _nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
1991 struct nfs4_server_caps_arg args
= {
1994 struct nfs4_server_caps_res res
= {};
1995 struct rpc_message msg
= {
1996 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SERVER_CAPS
],
2002 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2004 memcpy(server
->attr_bitmask
, res
.attr_bitmask
, sizeof(server
->attr_bitmask
));
2005 server
->caps
&= ~(NFS_CAP_ACLS
|NFS_CAP_HARDLINKS
|
2006 NFS_CAP_SYMLINKS
|NFS_CAP_FILEID
|
2007 NFS_CAP_MODE
|NFS_CAP_NLINK
|NFS_CAP_OWNER
|
2008 NFS_CAP_OWNER_GROUP
|NFS_CAP_ATIME
|
2009 NFS_CAP_CTIME
|NFS_CAP_MTIME
);
2010 if (res
.attr_bitmask
[0] & FATTR4_WORD0_ACL
)
2011 server
->caps
|= NFS_CAP_ACLS
;
2012 if (res
.has_links
!= 0)
2013 server
->caps
|= NFS_CAP_HARDLINKS
;
2014 if (res
.has_symlinks
!= 0)
2015 server
->caps
|= NFS_CAP_SYMLINKS
;
2016 if (res
.attr_bitmask
[0] & FATTR4_WORD0_FILEID
)
2017 server
->caps
|= NFS_CAP_FILEID
;
2018 if (res
.attr_bitmask
[1] & FATTR4_WORD1_MODE
)
2019 server
->caps
|= NFS_CAP_MODE
;
2020 if (res
.attr_bitmask
[1] & FATTR4_WORD1_NUMLINKS
)
2021 server
->caps
|= NFS_CAP_NLINK
;
2022 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER
)
2023 server
->caps
|= NFS_CAP_OWNER
;
2024 if (res
.attr_bitmask
[1] & FATTR4_WORD1_OWNER_GROUP
)
2025 server
->caps
|= NFS_CAP_OWNER_GROUP
;
2026 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_ACCESS
)
2027 server
->caps
|= NFS_CAP_ATIME
;
2028 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_METADATA
)
2029 server
->caps
|= NFS_CAP_CTIME
;
2030 if (res
.attr_bitmask
[1] & FATTR4_WORD1_TIME_MODIFY
)
2031 server
->caps
|= NFS_CAP_MTIME
;
2033 memcpy(server
->cache_consistency_bitmask
, res
.attr_bitmask
, sizeof(server
->cache_consistency_bitmask
));
2034 server
->cache_consistency_bitmask
[0] &= FATTR4_WORD0_CHANGE
|FATTR4_WORD0_SIZE
;
2035 server
->cache_consistency_bitmask
[1] &= FATTR4_WORD1_TIME_METADATA
|FATTR4_WORD1_TIME_MODIFY
;
2036 server
->acl_bitmask
= res
.acl_bitmask
;
2042 int nfs4_server_capabilities(struct nfs_server
*server
, struct nfs_fh
*fhandle
)
2044 struct nfs4_exception exception
= { };
2047 err
= nfs4_handle_exception(server
,
2048 _nfs4_server_capabilities(server
, fhandle
),
2050 } while (exception
.retry
);
2054 static int _nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2055 struct nfs_fsinfo
*info
)
2057 struct nfs4_lookup_root_arg args
= {
2058 .bitmask
= nfs4_fattr_bitmap
,
2060 struct nfs4_lookup_res res
= {
2062 .fattr
= info
->fattr
,
2065 struct rpc_message msg
= {
2066 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP_ROOT
],
2071 nfs_fattr_init(info
->fattr
);
2072 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2075 static int nfs4_lookup_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2076 struct nfs_fsinfo
*info
)
2078 struct nfs4_exception exception
= { };
2081 err
= nfs4_handle_exception(server
,
2082 _nfs4_lookup_root(server
, fhandle
, info
),
2084 } while (exception
.retry
);
2089 * get the file handle for the "/" directory on the server
2091 static int nfs4_proc_get_root(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2092 struct nfs_fsinfo
*info
)
2096 status
= nfs4_lookup_root(server
, fhandle
, info
);
2098 status
= nfs4_server_capabilities(server
, fhandle
);
2100 status
= nfs4_do_fsinfo(server
, fhandle
, info
);
2101 return nfs4_map_errors(status
);
2105 * Get locations and (maybe) other attributes of a referral.
2106 * Note that we'll actually follow the referral later when
2107 * we detect fsid mismatch in inode revalidation
2109 static int nfs4_get_referral(struct inode
*dir
, const struct qstr
*name
, struct nfs_fattr
*fattr
, struct nfs_fh
*fhandle
)
2111 int status
= -ENOMEM
;
2112 struct page
*page
= NULL
;
2113 struct nfs4_fs_locations
*locations
= NULL
;
2115 page
= alloc_page(GFP_KERNEL
);
2118 locations
= kmalloc(sizeof(struct nfs4_fs_locations
), GFP_KERNEL
);
2119 if (locations
== NULL
)
2122 status
= nfs4_proc_fs_locations(dir
, name
, locations
, page
);
2125 /* Make sure server returned a different fsid for the referral */
2126 if (nfs_fsid_equal(&NFS_SERVER(dir
)->fsid
, &locations
->fattr
.fsid
)) {
2127 dprintk("%s: server did not return a different fsid for a referral at %s\n", __func__
, name
->name
);
2132 memcpy(fattr
, &locations
->fattr
, sizeof(struct nfs_fattr
));
2133 fattr
->valid
|= NFS_ATTR_FATTR_V4_REFERRAL
;
2135 fattr
->mode
= S_IFDIR
;
2136 memset(fhandle
, 0, sizeof(struct nfs_fh
));
2145 static int _nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2147 struct nfs4_getattr_arg args
= {
2149 .bitmask
= server
->attr_bitmask
,
2151 struct nfs4_getattr_res res
= {
2155 struct rpc_message msg
= {
2156 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETATTR
],
2161 nfs_fattr_init(fattr
);
2162 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2165 static int nfs4_proc_getattr(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2167 struct nfs4_exception exception
= { };
2170 err
= nfs4_handle_exception(server
,
2171 _nfs4_proc_getattr(server
, fhandle
, fattr
),
2173 } while (exception
.retry
);
2178 * The file is not closed if it is opened due to the a request to change
2179 * the size of the file. The open call will not be needed once the
2180 * VFS layer lookup-intents are implemented.
2182 * Close is called when the inode is destroyed.
2183 * If we haven't opened the file for O_WRONLY, we
2184 * need to in the size_change case to obtain a stateid.
2187 * Because OPEN is always done by name in nfsv4, it is
2188 * possible that we opened a different file by the same
2189 * name. We can recognize this race condition, but we
2190 * can't do anything about it besides returning an error.
2192 * This will be fixed with VFS changes (lookup-intent).
2195 nfs4_proc_setattr(struct dentry
*dentry
, struct nfs_fattr
*fattr
,
2196 struct iattr
*sattr
)
2198 struct inode
*inode
= dentry
->d_inode
;
2199 struct rpc_cred
*cred
= NULL
;
2200 struct nfs4_state
*state
= NULL
;
2203 nfs_fattr_init(fattr
);
2205 /* Search for an existing open(O_WRITE) file */
2206 if (sattr
->ia_valid
& ATTR_FILE
) {
2207 struct nfs_open_context
*ctx
;
2209 ctx
= nfs_file_open_context(sattr
->ia_file
);
2216 status
= nfs4_do_setattr(inode
, cred
, fattr
, sattr
, state
);
2218 nfs_setattr_update_inode(inode
, sattr
);
2222 static int _nfs4_proc_lookupfh(struct nfs_server
*server
, const struct nfs_fh
*dirfh
,
2223 const struct qstr
*name
, struct nfs_fh
*fhandle
,
2224 struct nfs_fattr
*fattr
)
2227 struct nfs4_lookup_arg args
= {
2228 .bitmask
= server
->attr_bitmask
,
2232 struct nfs4_lookup_res res
= {
2237 struct rpc_message msg
= {
2238 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOOKUP
],
2243 nfs_fattr_init(fattr
);
2245 dprintk("NFS call lookupfh %s\n", name
->name
);
2246 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2247 dprintk("NFS reply lookupfh: %d\n", status
);
2251 static int nfs4_proc_lookupfh(struct nfs_server
*server
, struct nfs_fh
*dirfh
,
2252 struct qstr
*name
, struct nfs_fh
*fhandle
,
2253 struct nfs_fattr
*fattr
)
2255 struct nfs4_exception exception
= { };
2258 err
= _nfs4_proc_lookupfh(server
, dirfh
, name
, fhandle
, fattr
);
2260 if (err
== -NFS4ERR_MOVED
) {
2264 err
= nfs4_handle_exception(server
, err
, &exception
);
2265 } while (exception
.retry
);
2269 static int _nfs4_proc_lookup(struct inode
*dir
, const struct qstr
*name
,
2270 struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2274 dprintk("NFS call lookup %s\n", name
->name
);
2275 status
= _nfs4_proc_lookupfh(NFS_SERVER(dir
), NFS_FH(dir
), name
, fhandle
, fattr
);
2276 if (status
== -NFS4ERR_MOVED
)
2277 status
= nfs4_get_referral(dir
, name
, fattr
, fhandle
);
2278 dprintk("NFS reply lookup: %d\n", status
);
2282 static int nfs4_proc_lookup(struct inode
*dir
, struct qstr
*name
, struct nfs_fh
*fhandle
, struct nfs_fattr
*fattr
)
2284 struct nfs4_exception exception
= { };
2287 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2288 _nfs4_proc_lookup(dir
, name
, fhandle
, fattr
),
2290 } while (exception
.retry
);
2294 static int _nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2296 struct nfs_server
*server
= NFS_SERVER(inode
);
2297 struct nfs_fattr fattr
;
2298 struct nfs4_accessargs args
= {
2299 .fh
= NFS_FH(inode
),
2300 .bitmask
= server
->attr_bitmask
,
2302 struct nfs4_accessres res
= {
2306 struct rpc_message msg
= {
2307 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_ACCESS
],
2310 .rpc_cred
= entry
->cred
,
2312 int mode
= entry
->mask
;
2316 * Determine which access bits we want to ask for...
2318 if (mode
& MAY_READ
)
2319 args
.access
|= NFS4_ACCESS_READ
;
2320 if (S_ISDIR(inode
->i_mode
)) {
2321 if (mode
& MAY_WRITE
)
2322 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
;
2323 if (mode
& MAY_EXEC
)
2324 args
.access
|= NFS4_ACCESS_LOOKUP
;
2326 if (mode
& MAY_WRITE
)
2327 args
.access
|= NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
;
2328 if (mode
& MAY_EXEC
)
2329 args
.access
|= NFS4_ACCESS_EXECUTE
;
2331 nfs_fattr_init(&fattr
);
2332 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2335 if (res
.access
& NFS4_ACCESS_READ
)
2336 entry
->mask
|= MAY_READ
;
2337 if (res
.access
& (NFS4_ACCESS_MODIFY
| NFS4_ACCESS_EXTEND
| NFS4_ACCESS_DELETE
))
2338 entry
->mask
|= MAY_WRITE
;
2339 if (res
.access
& (NFS4_ACCESS_LOOKUP
|NFS4_ACCESS_EXECUTE
))
2340 entry
->mask
|= MAY_EXEC
;
2341 nfs_refresh_inode(inode
, &fattr
);
2346 static int nfs4_proc_access(struct inode
*inode
, struct nfs_access_entry
*entry
)
2348 struct nfs4_exception exception
= { };
2351 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2352 _nfs4_proc_access(inode
, entry
),
2354 } while (exception
.retry
);
2359 * TODO: For the time being, we don't try to get any attributes
2360 * along with any of the zero-copy operations READ, READDIR,
2363 * In the case of the first three, we want to put the GETATTR
2364 * after the read-type operation -- this is because it is hard
2365 * to predict the length of a GETATTR response in v4, and thus
2366 * align the READ data correctly. This means that the GETATTR
2367 * may end up partially falling into the page cache, and we should
2368 * shift it into the 'tail' of the xdr_buf before processing.
2369 * To do this efficiently, we need to know the total length
2370 * of data received, which doesn't seem to be available outside
2373 * In the case of WRITE, we also want to put the GETATTR after
2374 * the operation -- in this case because we want to make sure
2375 * we get the post-operation mtime and size. This means that
2376 * we can't use xdr_encode_pages() as written: we need a variant
2377 * of it which would leave room in the 'tail' iovec.
2379 * Both of these changes to the XDR layer would in fact be quite
2380 * minor, but I decided to leave them for a subsequent patch.
2382 static int _nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2383 unsigned int pgbase
, unsigned int pglen
)
2385 struct nfs4_readlink args
= {
2386 .fh
= NFS_FH(inode
),
2391 struct nfs4_readlink_res res
;
2392 struct rpc_message msg
= {
2393 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READLINK
],
2398 return nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
2401 static int nfs4_proc_readlink(struct inode
*inode
, struct page
*page
,
2402 unsigned int pgbase
, unsigned int pglen
)
2404 struct nfs4_exception exception
= { };
2407 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2408 _nfs4_proc_readlink(inode
, page
, pgbase
, pglen
),
2410 } while (exception
.retry
);
2416 * We will need to arrange for the VFS layer to provide an atomic open.
2417 * Until then, this create/open method is prone to inefficiency and race
2418 * conditions due to the lookup, create, and open VFS calls from sys_open()
2419 * placed on the wire.
2421 * Given the above sorry state of affairs, I'm simply sending an OPEN.
2422 * The file will be opened again in the subsequent VFS open call
2423 * (nfs4_proc_file_open).
2425 * The open for read will just hang around to be used by any process that
2426 * opens the file O_RDONLY. This will all be resolved with the VFS changes.
2430 nfs4_proc_create(struct inode
*dir
, struct dentry
*dentry
, struct iattr
*sattr
,
2431 int flags
, struct nameidata
*nd
)
2433 struct path path
= {
2434 .mnt
= nd
->path
.mnt
,
2437 struct nfs4_state
*state
;
2438 struct rpc_cred
*cred
;
2439 fmode_t fmode
= flags
& (FMODE_READ
| FMODE_WRITE
);
2442 cred
= rpc_lookup_cred();
2444 status
= PTR_ERR(cred
);
2447 state
= nfs4_do_open(dir
, &path
, fmode
, flags
, sattr
, cred
);
2449 if (IS_ERR(state
)) {
2450 status
= PTR_ERR(state
);
2453 d_add(dentry
, igrab(state
->inode
));
2454 nfs_set_verifier(dentry
, nfs_save_change_attribute(dir
));
2455 if (flags
& O_EXCL
) {
2456 struct nfs_fattr fattr
;
2457 status
= nfs4_do_setattr(state
->inode
, cred
, &fattr
, sattr
, state
);
2459 nfs_setattr_update_inode(state
->inode
, sattr
);
2460 nfs_post_op_update_inode(state
->inode
, &fattr
);
2462 if (status
== 0 && (nd
->flags
& LOOKUP_OPEN
) != 0)
2463 status
= nfs4_intent_set_file(nd
, &path
, state
, fmode
);
2465 nfs4_close_sync(&path
, state
, fmode
);
2472 static int _nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2474 struct nfs_server
*server
= NFS_SERVER(dir
);
2475 struct nfs_removeargs args
= {
2477 .name
.len
= name
->len
,
2478 .name
.name
= name
->name
,
2479 .bitmask
= server
->attr_bitmask
,
2481 struct nfs_removeres res
= {
2484 struct rpc_message msg
= {
2485 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
],
2491 nfs_fattr_init(&res
.dir_attr
);
2492 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 1);
2494 update_changeattr(dir
, &res
.cinfo
);
2495 nfs_post_op_update_inode(dir
, &res
.dir_attr
);
2500 static int nfs4_proc_remove(struct inode
*dir
, struct qstr
*name
)
2502 struct nfs4_exception exception
= { };
2505 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2506 _nfs4_proc_remove(dir
, name
),
2508 } while (exception
.retry
);
2512 static void nfs4_proc_unlink_setup(struct rpc_message
*msg
, struct inode
*dir
)
2514 struct nfs_server
*server
= NFS_SERVER(dir
);
2515 struct nfs_removeargs
*args
= msg
->rpc_argp
;
2516 struct nfs_removeres
*res
= msg
->rpc_resp
;
2518 args
->bitmask
= server
->cache_consistency_bitmask
;
2519 res
->server
= server
;
2520 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_REMOVE
];
2523 static int nfs4_proc_unlink_done(struct rpc_task
*task
, struct inode
*dir
)
2525 struct nfs_removeres
*res
= task
->tk_msg
.rpc_resp
;
2527 nfs4_sequence_done(res
->server
, &res
->seq_res
, task
->tk_status
);
2528 if (nfs4_async_handle_error(task
, res
->server
, NULL
) == -EAGAIN
)
2530 nfs4_sequence_free_slot(res
->server
->nfs_client
, &res
->seq_res
);
2531 update_changeattr(dir
, &res
->cinfo
);
2532 nfs_post_op_update_inode(dir
, &res
->dir_attr
);
2536 static int _nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2537 struct inode
*new_dir
, struct qstr
*new_name
)
2539 struct nfs_server
*server
= NFS_SERVER(old_dir
);
2540 struct nfs4_rename_arg arg
= {
2541 .old_dir
= NFS_FH(old_dir
),
2542 .new_dir
= NFS_FH(new_dir
),
2543 .old_name
= old_name
,
2544 .new_name
= new_name
,
2545 .bitmask
= server
->attr_bitmask
,
2547 struct nfs_fattr old_fattr
, new_fattr
;
2548 struct nfs4_rename_res res
= {
2550 .old_fattr
= &old_fattr
,
2551 .new_fattr
= &new_fattr
,
2553 struct rpc_message msg
= {
2554 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENAME
],
2560 nfs_fattr_init(res
.old_fattr
);
2561 nfs_fattr_init(res
.new_fattr
);
2562 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2565 update_changeattr(old_dir
, &res
.old_cinfo
);
2566 nfs_post_op_update_inode(old_dir
, res
.old_fattr
);
2567 update_changeattr(new_dir
, &res
.new_cinfo
);
2568 nfs_post_op_update_inode(new_dir
, res
.new_fattr
);
2573 static int nfs4_proc_rename(struct inode
*old_dir
, struct qstr
*old_name
,
2574 struct inode
*new_dir
, struct qstr
*new_name
)
2576 struct nfs4_exception exception
= { };
2579 err
= nfs4_handle_exception(NFS_SERVER(old_dir
),
2580 _nfs4_proc_rename(old_dir
, old_name
,
2583 } while (exception
.retry
);
2587 static int _nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2589 struct nfs_server
*server
= NFS_SERVER(inode
);
2590 struct nfs4_link_arg arg
= {
2591 .fh
= NFS_FH(inode
),
2592 .dir_fh
= NFS_FH(dir
),
2594 .bitmask
= server
->attr_bitmask
,
2596 struct nfs_fattr fattr
, dir_attr
;
2597 struct nfs4_link_res res
= {
2600 .dir_attr
= &dir_attr
,
2602 struct rpc_message msg
= {
2603 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LINK
],
2609 nfs_fattr_init(res
.fattr
);
2610 nfs_fattr_init(res
.dir_attr
);
2611 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
2613 update_changeattr(dir
, &res
.cinfo
);
2614 nfs_post_op_update_inode(dir
, res
.dir_attr
);
2615 nfs_post_op_update_inode(inode
, res
.fattr
);
2621 static int nfs4_proc_link(struct inode
*inode
, struct inode
*dir
, struct qstr
*name
)
2623 struct nfs4_exception exception
= { };
2626 err
= nfs4_handle_exception(NFS_SERVER(inode
),
2627 _nfs4_proc_link(inode
, dir
, name
),
2629 } while (exception
.retry
);
2633 struct nfs4_createdata
{
2634 struct rpc_message msg
;
2635 struct nfs4_create_arg arg
;
2636 struct nfs4_create_res res
;
2638 struct nfs_fattr fattr
;
2639 struct nfs_fattr dir_fattr
;
2642 static struct nfs4_createdata
*nfs4_alloc_createdata(struct inode
*dir
,
2643 struct qstr
*name
, struct iattr
*sattr
, u32 ftype
)
2645 struct nfs4_createdata
*data
;
2647 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
2649 struct nfs_server
*server
= NFS_SERVER(dir
);
2651 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE
];
2652 data
->msg
.rpc_argp
= &data
->arg
;
2653 data
->msg
.rpc_resp
= &data
->res
;
2654 data
->arg
.dir_fh
= NFS_FH(dir
);
2655 data
->arg
.server
= server
;
2656 data
->arg
.name
= name
;
2657 data
->arg
.attrs
= sattr
;
2658 data
->arg
.ftype
= ftype
;
2659 data
->arg
.bitmask
= server
->attr_bitmask
;
2660 data
->res
.server
= server
;
2661 data
->res
.fh
= &data
->fh
;
2662 data
->res
.fattr
= &data
->fattr
;
2663 data
->res
.dir_fattr
= &data
->dir_fattr
;
2664 nfs_fattr_init(data
->res
.fattr
);
2665 nfs_fattr_init(data
->res
.dir_fattr
);
2670 static int nfs4_do_create(struct inode
*dir
, struct dentry
*dentry
, struct nfs4_createdata
*data
)
2672 int status
= nfs4_call_sync(NFS_SERVER(dir
), &data
->msg
,
2673 &data
->arg
, &data
->res
, 1);
2675 update_changeattr(dir
, &data
->res
.dir_cinfo
);
2676 nfs_post_op_update_inode(dir
, data
->res
.dir_fattr
);
2677 status
= nfs_instantiate(dentry
, data
->res
.fh
, data
->res
.fattr
);
2682 static void nfs4_free_createdata(struct nfs4_createdata
*data
)
2687 static int _nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2688 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2690 struct nfs4_createdata
*data
;
2691 int status
= -ENAMETOOLONG
;
2693 if (len
> NFS4_MAXPATHLEN
)
2697 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4LNK
);
2701 data
->msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SYMLINK
];
2702 data
->arg
.u
.symlink
.pages
= &page
;
2703 data
->arg
.u
.symlink
.len
= len
;
2705 status
= nfs4_do_create(dir
, dentry
, data
);
2707 nfs4_free_createdata(data
);
2712 static int nfs4_proc_symlink(struct inode
*dir
, struct dentry
*dentry
,
2713 struct page
*page
, unsigned int len
, struct iattr
*sattr
)
2715 struct nfs4_exception exception
= { };
2718 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2719 _nfs4_proc_symlink(dir
, dentry
, page
,
2722 } while (exception
.retry
);
2726 static int _nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2727 struct iattr
*sattr
)
2729 struct nfs4_createdata
*data
;
2730 int status
= -ENOMEM
;
2732 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4DIR
);
2736 status
= nfs4_do_create(dir
, dentry
, data
);
2738 nfs4_free_createdata(data
);
2743 static int nfs4_proc_mkdir(struct inode
*dir
, struct dentry
*dentry
,
2744 struct iattr
*sattr
)
2746 struct nfs4_exception exception
= { };
2749 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2750 _nfs4_proc_mkdir(dir
, dentry
, sattr
),
2752 } while (exception
.retry
);
2756 static int _nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2757 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2759 struct inode
*dir
= dentry
->d_inode
;
2760 struct nfs4_readdir_arg args
= {
2765 .bitmask
= NFS_SERVER(dentry
->d_inode
)->cache_consistency_bitmask
,
2767 struct nfs4_readdir_res res
;
2768 struct rpc_message msg
= {
2769 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READDIR
],
2776 dprintk("%s: dentry = %s/%s, cookie = %Lu\n", __func__
,
2777 dentry
->d_parent
->d_name
.name
,
2778 dentry
->d_name
.name
,
2779 (unsigned long long)cookie
);
2780 nfs4_setup_readdir(cookie
, NFS_COOKIEVERF(dir
), dentry
, &args
);
2781 res
.pgbase
= args
.pgbase
;
2782 status
= nfs4_call_sync(NFS_SERVER(dir
), &msg
, &args
, &res
, 0);
2784 memcpy(NFS_COOKIEVERF(dir
), res
.verifier
.data
, NFS4_VERIFIER_SIZE
);
2786 nfs_invalidate_atime(dir
);
2788 dprintk("%s: returns %d\n", __func__
, status
);
2792 static int nfs4_proc_readdir(struct dentry
*dentry
, struct rpc_cred
*cred
,
2793 u64 cookie
, struct page
*page
, unsigned int count
, int plus
)
2795 struct nfs4_exception exception
= { };
2798 err
= nfs4_handle_exception(NFS_SERVER(dentry
->d_inode
),
2799 _nfs4_proc_readdir(dentry
, cred
, cookie
,
2802 } while (exception
.retry
);
2806 static int _nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2807 struct iattr
*sattr
, dev_t rdev
)
2809 struct nfs4_createdata
*data
;
2810 int mode
= sattr
->ia_mode
;
2811 int status
= -ENOMEM
;
2813 BUG_ON(!(sattr
->ia_valid
& ATTR_MODE
));
2814 BUG_ON(!S_ISFIFO(mode
) && !S_ISBLK(mode
) && !S_ISCHR(mode
) && !S_ISSOCK(mode
));
2816 data
= nfs4_alloc_createdata(dir
, &dentry
->d_name
, sattr
, NF4SOCK
);
2821 data
->arg
.ftype
= NF4FIFO
;
2822 else if (S_ISBLK(mode
)) {
2823 data
->arg
.ftype
= NF4BLK
;
2824 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2825 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2827 else if (S_ISCHR(mode
)) {
2828 data
->arg
.ftype
= NF4CHR
;
2829 data
->arg
.u
.device
.specdata1
= MAJOR(rdev
);
2830 data
->arg
.u
.device
.specdata2
= MINOR(rdev
);
2833 status
= nfs4_do_create(dir
, dentry
, data
);
2835 nfs4_free_createdata(data
);
2840 static int nfs4_proc_mknod(struct inode
*dir
, struct dentry
*dentry
,
2841 struct iattr
*sattr
, dev_t rdev
)
2843 struct nfs4_exception exception
= { };
2846 err
= nfs4_handle_exception(NFS_SERVER(dir
),
2847 _nfs4_proc_mknod(dir
, dentry
, sattr
, rdev
),
2849 } while (exception
.retry
);
2853 static int _nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2854 struct nfs_fsstat
*fsstat
)
2856 struct nfs4_statfs_arg args
= {
2858 .bitmask
= server
->attr_bitmask
,
2860 struct nfs4_statfs_res res
= {
2863 struct rpc_message msg
= {
2864 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_STATFS
],
2869 nfs_fattr_init(fsstat
->fattr
);
2870 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2873 static int nfs4_proc_statfs(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsstat
*fsstat
)
2875 struct nfs4_exception exception
= { };
2878 err
= nfs4_handle_exception(server
,
2879 _nfs4_proc_statfs(server
, fhandle
, fsstat
),
2881 } while (exception
.retry
);
2885 static int _nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2886 struct nfs_fsinfo
*fsinfo
)
2888 struct nfs4_fsinfo_arg args
= {
2890 .bitmask
= server
->attr_bitmask
,
2892 struct nfs4_fsinfo_res res
= {
2895 struct rpc_message msg
= {
2896 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FSINFO
],
2901 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2904 static int nfs4_do_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2906 struct nfs4_exception exception
= { };
2910 err
= nfs4_handle_exception(server
,
2911 _nfs4_do_fsinfo(server
, fhandle
, fsinfo
),
2913 } while (exception
.retry
);
2917 static int nfs4_proc_fsinfo(struct nfs_server
*server
, struct nfs_fh
*fhandle
, struct nfs_fsinfo
*fsinfo
)
2919 nfs_fattr_init(fsinfo
->fattr
);
2920 return nfs4_do_fsinfo(server
, fhandle
, fsinfo
);
2923 static int _nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2924 struct nfs_pathconf
*pathconf
)
2926 struct nfs4_pathconf_arg args
= {
2928 .bitmask
= server
->attr_bitmask
,
2930 struct nfs4_pathconf_res res
= {
2931 .pathconf
= pathconf
,
2933 struct rpc_message msg
= {
2934 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_PATHCONF
],
2939 /* None of the pathconf attributes are mandatory to implement */
2940 if ((args
.bitmask
[0] & nfs4_pathconf_bitmap
[0]) == 0) {
2941 memset(pathconf
, 0, sizeof(*pathconf
));
2945 nfs_fattr_init(pathconf
->fattr
);
2946 return nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
2949 static int nfs4_proc_pathconf(struct nfs_server
*server
, struct nfs_fh
*fhandle
,
2950 struct nfs_pathconf
*pathconf
)
2952 struct nfs4_exception exception
= { };
2956 err
= nfs4_handle_exception(server
,
2957 _nfs4_proc_pathconf(server
, fhandle
, pathconf
),
2959 } while (exception
.retry
);
2963 static int nfs4_read_done(struct rpc_task
*task
, struct nfs_read_data
*data
)
2965 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
2967 dprintk("--> %s\n", __func__
);
2969 /* nfs4_sequence_free_slot called in the read rpc_call_done */
2970 nfs4_sequence_done(server
, &data
->res
.seq_res
, task
->tk_status
);
2972 if (nfs4_async_handle_error(task
, server
, data
->args
.context
->state
) == -EAGAIN
) {
2973 nfs4_restart_rpc(task
, server
->nfs_client
);
2977 nfs_invalidate_atime(data
->inode
);
2978 if (task
->tk_status
> 0)
2979 renew_lease(server
, data
->timestamp
);
2983 static void nfs4_proc_read_setup(struct nfs_read_data
*data
, struct rpc_message
*msg
)
2985 data
->timestamp
= jiffies
;
2986 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_READ
];
2989 static int nfs4_write_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
2991 struct inode
*inode
= data
->inode
;
2993 /* slot is freed in nfs_writeback_done */
2994 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
2997 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), data
->args
.context
->state
) == -EAGAIN
) {
2998 nfs4_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3001 if (task
->tk_status
>= 0) {
3002 renew_lease(NFS_SERVER(inode
), data
->timestamp
);
3003 nfs_post_op_update_inode_force_wcc(inode
, data
->res
.fattr
);
3008 static void nfs4_proc_write_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3010 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3012 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3013 data
->res
.server
= server
;
3014 data
->timestamp
= jiffies
;
3016 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_WRITE
];
3019 static int nfs4_commit_done(struct rpc_task
*task
, struct nfs_write_data
*data
)
3021 struct inode
*inode
= data
->inode
;
3023 nfs4_sequence_done(NFS_SERVER(inode
), &data
->res
.seq_res
,
3025 if (nfs4_async_handle_error(task
, NFS_SERVER(inode
), NULL
) == -EAGAIN
) {
3026 nfs4_restart_rpc(task
, NFS_SERVER(inode
)->nfs_client
);
3029 nfs4_sequence_free_slot(NFS_SERVER(inode
)->nfs_client
,
3030 &data
->res
.seq_res
);
3031 nfs_refresh_inode(inode
, data
->res
.fattr
);
3035 static void nfs4_proc_commit_setup(struct nfs_write_data
*data
, struct rpc_message
*msg
)
3037 struct nfs_server
*server
= NFS_SERVER(data
->inode
);
3039 data
->args
.bitmask
= server
->cache_consistency_bitmask
;
3040 data
->res
.server
= server
;
3041 msg
->rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_COMMIT
];
3045 * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
3046 * standalone procedure for queueing an asynchronous RENEW.
3048 static void nfs4_renew_done(struct rpc_task
*task
, void *data
)
3050 struct nfs_client
*clp
= (struct nfs_client
*)task
->tk_msg
.rpc_argp
;
3051 unsigned long timestamp
= (unsigned long)data
;
3053 if (task
->tk_status
< 0) {
3054 /* Unless we're shutting down, schedule state recovery! */
3055 if (test_bit(NFS_CS_RENEWD
, &clp
->cl_res_state
) != 0)
3056 nfs4_schedule_state_recovery(clp
);
3059 spin_lock(&clp
->cl_lock
);
3060 if (time_before(clp
->cl_last_renewal
,timestamp
))
3061 clp
->cl_last_renewal
= timestamp
;
3062 spin_unlock(&clp
->cl_lock
);
3063 dprintk("%s calling put_rpccred on rpc_cred %p\n", __func__
,
3064 task
->tk_msg
.rpc_cred
);
3065 put_rpccred(task
->tk_msg
.rpc_cred
);
3068 static const struct rpc_call_ops nfs4_renew_ops
= {
3069 .rpc_call_done
= nfs4_renew_done
,
3072 int nfs4_proc_async_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3074 struct rpc_message msg
= {
3075 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3080 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
3081 &nfs4_renew_ops
, (void *)jiffies
);
3084 int nfs4_proc_renew(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3086 struct rpc_message msg
= {
3087 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_RENEW
],
3091 unsigned long now
= jiffies
;
3094 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3097 spin_lock(&clp
->cl_lock
);
3098 if (time_before(clp
->cl_last_renewal
,now
))
3099 clp
->cl_last_renewal
= now
;
3100 spin_unlock(&clp
->cl_lock
);
3104 static inline int nfs4_server_supports_acls(struct nfs_server
*server
)
3106 return (server
->caps
& NFS_CAP_ACLS
)
3107 && (server
->acl_bitmask
& ACL4_SUPPORT_ALLOW_ACL
)
3108 && (server
->acl_bitmask
& ACL4_SUPPORT_DENY_ACL
);
3111 /* Assuming that XATTR_SIZE_MAX is a multiple of PAGE_CACHE_SIZE, and that
3112 * it's OK to put sizeof(void) * (XATTR_SIZE_MAX/PAGE_CACHE_SIZE) bytes on
3115 #define NFS4ACL_MAXPAGES (XATTR_SIZE_MAX >> PAGE_CACHE_SHIFT)
3117 static void buf_to_pages(const void *buf
, size_t buflen
,
3118 struct page
**pages
, unsigned int *pgbase
)
3120 const void *p
= buf
;
3122 *pgbase
= offset_in_page(buf
);
3124 while (p
< buf
+ buflen
) {
3125 *(pages
++) = virt_to_page(p
);
3126 p
+= PAGE_CACHE_SIZE
;
3130 struct nfs4_cached_acl
{
3136 static void nfs4_set_cached_acl(struct inode
*inode
, struct nfs4_cached_acl
*acl
)
3138 struct nfs_inode
*nfsi
= NFS_I(inode
);
3140 spin_lock(&inode
->i_lock
);
3141 kfree(nfsi
->nfs4_acl
);
3142 nfsi
->nfs4_acl
= acl
;
3143 spin_unlock(&inode
->i_lock
);
3146 static void nfs4_zap_acl_attr(struct inode
*inode
)
3148 nfs4_set_cached_acl(inode
, NULL
);
3151 static inline ssize_t
nfs4_read_cached_acl(struct inode
*inode
, char *buf
, size_t buflen
)
3153 struct nfs_inode
*nfsi
= NFS_I(inode
);
3154 struct nfs4_cached_acl
*acl
;
3157 spin_lock(&inode
->i_lock
);
3158 acl
= nfsi
->nfs4_acl
;
3161 if (buf
== NULL
) /* user is just asking for length */
3163 if (acl
->cached
== 0)
3165 ret
= -ERANGE
; /* see getxattr(2) man page */
3166 if (acl
->len
> buflen
)
3168 memcpy(buf
, acl
->data
, acl
->len
);
3172 spin_unlock(&inode
->i_lock
);
3176 static void nfs4_write_cached_acl(struct inode
*inode
, const char *buf
, size_t acl_len
)
3178 struct nfs4_cached_acl
*acl
;
3180 if (buf
&& acl_len
<= PAGE_SIZE
) {
3181 acl
= kmalloc(sizeof(*acl
) + acl_len
, GFP_KERNEL
);
3185 memcpy(acl
->data
, buf
, acl_len
);
3187 acl
= kmalloc(sizeof(*acl
), GFP_KERNEL
);
3194 nfs4_set_cached_acl(inode
, acl
);
3197 static ssize_t
__nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3199 struct page
*pages
[NFS4ACL_MAXPAGES
];
3200 struct nfs_getaclargs args
= {
3201 .fh
= NFS_FH(inode
),
3205 struct nfs_getaclres res
= {
3209 struct rpc_message msg
= {
3210 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GETACL
],
3214 struct page
*localpage
= NULL
;
3217 if (buflen
< PAGE_SIZE
) {
3218 /* As long as we're doing a round trip to the server anyway,
3219 * let's be prepared for a page of acl data. */
3220 localpage
= alloc_page(GFP_KERNEL
);
3221 resp_buf
= page_address(localpage
);
3222 if (localpage
== NULL
)
3224 args
.acl_pages
[0] = localpage
;
3225 args
.acl_pgbase
= 0;
3226 args
.acl_len
= PAGE_SIZE
;
3229 buf_to_pages(buf
, buflen
, args
.acl_pages
, &args
.acl_pgbase
);
3231 ret
= nfs4_call_sync(NFS_SERVER(inode
), &msg
, &args
, &res
, 0);
3234 if (res
.acl_len
> args
.acl_len
)
3235 nfs4_write_cached_acl(inode
, NULL
, res
.acl_len
);
3237 nfs4_write_cached_acl(inode
, resp_buf
, res
.acl_len
);
3240 if (res
.acl_len
> buflen
)
3243 memcpy(buf
, resp_buf
, res
.acl_len
);
3248 __free_page(localpage
);
3252 static ssize_t
nfs4_get_acl_uncached(struct inode
*inode
, void *buf
, size_t buflen
)
3254 struct nfs4_exception exception
= { };
3257 ret
= __nfs4_get_acl_uncached(inode
, buf
, buflen
);
3260 ret
= nfs4_handle_exception(NFS_SERVER(inode
), ret
, &exception
);
3261 } while (exception
.retry
);
3265 static ssize_t
nfs4_proc_get_acl(struct inode
*inode
, void *buf
, size_t buflen
)
3267 struct nfs_server
*server
= NFS_SERVER(inode
);
3270 if (!nfs4_server_supports_acls(server
))
3272 ret
= nfs_revalidate_inode(server
, inode
);
3275 ret
= nfs4_read_cached_acl(inode
, buf
, buflen
);
3278 return nfs4_get_acl_uncached(inode
, buf
, buflen
);
3281 static int __nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3283 struct nfs_server
*server
= NFS_SERVER(inode
);
3284 struct page
*pages
[NFS4ACL_MAXPAGES
];
3285 struct nfs_setaclargs arg
= {
3286 .fh
= NFS_FH(inode
),
3290 struct nfs_setaclres res
;
3291 struct rpc_message msg
= {
3292 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETACL
],
3298 if (!nfs4_server_supports_acls(server
))
3300 nfs_inode_return_delegation(inode
);
3301 buf_to_pages(buf
, buflen
, arg
.acl_pages
, &arg
.acl_pgbase
);
3302 ret
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3303 nfs_access_zap_cache(inode
);
3304 nfs_zap_acl_cache(inode
);
3308 static int nfs4_proc_set_acl(struct inode
*inode
, const void *buf
, size_t buflen
)
3310 struct nfs4_exception exception
= { };
3313 err
= nfs4_handle_exception(NFS_SERVER(inode
),
3314 __nfs4_proc_set_acl(inode
, buf
, buflen
),
3316 } while (exception
.retry
);
3321 _nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs_client
*clp
, struct nfs4_state
*state
)
3323 if (!clp
|| task
->tk_status
>= 0)
3325 switch(task
->tk_status
) {
3326 case -NFS4ERR_ADMIN_REVOKED
:
3327 case -NFS4ERR_BAD_STATEID
:
3328 case -NFS4ERR_OPENMODE
:
3331 nfs4_state_mark_reclaim_nograce(clp
, state
);
3332 case -NFS4ERR_STALE_CLIENTID
:
3333 case -NFS4ERR_STALE_STATEID
:
3334 case -NFS4ERR_EXPIRED
:
3335 rpc_sleep_on(&clp
->cl_rpcwaitq
, task
, NULL
);
3336 nfs4_schedule_state_recovery(clp
);
3337 if (test_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) == 0)
3338 rpc_wake_up_queued_task(&clp
->cl_rpcwaitq
, task
);
3339 task
->tk_status
= 0;
3341 #if defined(CONFIG_NFS_V4_1)
3342 case -NFS4ERR_BADSESSION
:
3343 case -NFS4ERR_BADSLOT
:
3344 case -NFS4ERR_BAD_HIGH_SLOT
:
3345 case -NFS4ERR_DEADSESSION
:
3346 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
3347 case -NFS4ERR_SEQ_FALSE_RETRY
:
3348 case -NFS4ERR_SEQ_MISORDERED
:
3349 dprintk("%s ERROR %d, Reset session\n", __func__
,
3351 set_bit(NFS4CLNT_SESSION_SETUP
, &clp
->cl_state
);
3352 task
->tk_status
= 0;
3354 #endif /* CONFIG_NFS_V4_1 */
3355 case -NFS4ERR_DELAY
:
3357 nfs_inc_server_stats(server
, NFSIOS_DELAY
);
3358 case -NFS4ERR_GRACE
:
3359 rpc_delay(task
, NFS4_POLL_RETRY_MAX
);
3360 task
->tk_status
= 0;
3362 case -NFS4ERR_OLD_STATEID
:
3363 task
->tk_status
= 0;
3366 task
->tk_status
= nfs4_map_errors(task
->tk_status
);
3371 nfs4_async_handle_error(struct rpc_task
*task
, const struct nfs_server
*server
, struct nfs4_state
*state
)
3373 return _nfs4_async_handle_error(task
, server
, server
->nfs_client
, state
);
3376 int nfs4_proc_setclientid(struct nfs_client
*clp
, u32 program
, unsigned short port
, struct rpc_cred
*cred
)
3378 nfs4_verifier sc_verifier
;
3379 struct nfs4_setclientid setclientid
= {
3380 .sc_verifier
= &sc_verifier
,
3383 struct rpc_message msg
= {
3384 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID
],
3385 .rpc_argp
= &setclientid
,
3393 p
= (__be32
*)sc_verifier
.data
;
3394 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
3395 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
3398 setclientid
.sc_name_len
= scnprintf(setclientid
.sc_name
,
3399 sizeof(setclientid
.sc_name
), "%s/%s %s %s %u",
3401 rpc_peeraddr2str(clp
->cl_rpcclient
,
3403 rpc_peeraddr2str(clp
->cl_rpcclient
,
3405 clp
->cl_rpcclient
->cl_auth
->au_ops
->au_name
,
3406 clp
->cl_id_uniquifier
);
3407 setclientid
.sc_netid_len
= scnprintf(setclientid
.sc_netid
,
3408 sizeof(setclientid
.sc_netid
),
3409 rpc_peeraddr2str(clp
->cl_rpcclient
,
3410 RPC_DISPLAY_NETID
));
3411 setclientid
.sc_uaddr_len
= scnprintf(setclientid
.sc_uaddr
,
3412 sizeof(setclientid
.sc_uaddr
), "%s.%u.%u",
3413 clp
->cl_ipaddr
, port
>> 8, port
& 255);
3415 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3416 if (status
!= -NFS4ERR_CLID_INUSE
)
3421 ssleep(clp
->cl_lease_time
+ 1);
3423 if (++clp
->cl_id_uniquifier
== 0)
3429 static int _nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3431 struct nfs_fsinfo fsinfo
;
3432 struct rpc_message msg
= {
3433 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SETCLIENTID_CONFIRM
],
3435 .rpc_resp
= &fsinfo
,
3442 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
3444 spin_lock(&clp
->cl_lock
);
3445 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
3446 clp
->cl_last_renewal
= now
;
3447 spin_unlock(&clp
->cl_lock
);
3452 int nfs4_proc_setclientid_confirm(struct nfs_client
*clp
, struct rpc_cred
*cred
)
3457 err
= _nfs4_proc_setclientid_confirm(clp
, cred
);
3461 case -NFS4ERR_RESOURCE
:
3462 /* The IBM lawyers misread another document! */
3463 case -NFS4ERR_DELAY
:
3464 err
= nfs4_delay(clp
->cl_rpcclient
, &timeout
);
3470 struct nfs4_delegreturndata
{
3471 struct nfs4_delegreturnargs args
;
3472 struct nfs4_delegreturnres res
;
3474 nfs4_stateid stateid
;
3475 unsigned long timestamp
;
3476 struct nfs_fattr fattr
;
3480 static void nfs4_delegreturn_done(struct rpc_task
*task
, void *calldata
)
3482 struct nfs4_delegreturndata
*data
= calldata
;
3484 nfs4_sequence_done_free_slot(data
->res
.server
, &data
->res
.seq_res
,
3487 data
->rpc_status
= task
->tk_status
;
3488 if (data
->rpc_status
== 0)
3489 renew_lease(data
->res
.server
, data
->timestamp
);
3492 static void nfs4_delegreturn_release(void *calldata
)
3497 #if defined(CONFIG_NFS_V4_1)
3498 static void nfs4_delegreturn_prepare(struct rpc_task
*task
, void *data
)
3500 struct nfs4_delegreturndata
*d_data
;
3502 d_data
= (struct nfs4_delegreturndata
*)data
;
3504 if (nfs4_setup_sequence(d_data
->res
.server
->nfs_client
,
3505 &d_data
->args
.seq_args
,
3506 &d_data
->res
.seq_res
, 1, task
))
3508 rpc_call_start(task
);
3510 #endif /* CONFIG_NFS_V4_1 */
3512 static const struct rpc_call_ops nfs4_delegreturn_ops
= {
3513 #if defined(CONFIG_NFS_V4_1)
3514 .rpc_call_prepare
= nfs4_delegreturn_prepare
,
3515 #endif /* CONFIG_NFS_V4_1 */
3516 .rpc_call_done
= nfs4_delegreturn_done
,
3517 .rpc_release
= nfs4_delegreturn_release
,
3520 static int _nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3522 struct nfs4_delegreturndata
*data
;
3523 struct nfs_server
*server
= NFS_SERVER(inode
);
3524 struct rpc_task
*task
;
3525 struct rpc_message msg
= {
3526 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DELEGRETURN
],
3529 struct rpc_task_setup task_setup_data
= {
3530 .rpc_client
= server
->client
,
3531 .rpc_message
= &msg
,
3532 .callback_ops
= &nfs4_delegreturn_ops
,
3533 .flags
= RPC_TASK_ASYNC
,
3537 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
3540 data
->args
.fhandle
= &data
->fh
;
3541 data
->args
.stateid
= &data
->stateid
;
3542 data
->args
.bitmask
= server
->attr_bitmask
;
3543 nfs_copy_fh(&data
->fh
, NFS_FH(inode
));
3544 memcpy(&data
->stateid
, stateid
, sizeof(data
->stateid
));
3545 data
->res
.fattr
= &data
->fattr
;
3546 data
->res
.server
= server
;
3547 data
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3548 nfs_fattr_init(data
->res
.fattr
);
3549 data
->timestamp
= jiffies
;
3550 data
->rpc_status
= 0;
3552 task_setup_data
.callback_data
= data
;
3553 msg
.rpc_argp
= &data
->args
,
3554 msg
.rpc_resp
= &data
->res
,
3555 task
= rpc_run_task(&task_setup_data
);
3557 return PTR_ERR(task
);
3560 status
= nfs4_wait_for_completion_rpc_task(task
);
3563 status
= data
->rpc_status
;
3566 nfs_refresh_inode(inode
, &data
->fattr
);
3572 int nfs4_proc_delegreturn(struct inode
*inode
, struct rpc_cred
*cred
, const nfs4_stateid
*stateid
, int issync
)
3574 struct nfs_server
*server
= NFS_SERVER(inode
);
3575 struct nfs4_exception exception
= { };
3578 err
= _nfs4_proc_delegreturn(inode
, cred
, stateid
, issync
);
3580 case -NFS4ERR_STALE_STATEID
:
3581 case -NFS4ERR_EXPIRED
:
3585 err
= nfs4_handle_exception(server
, err
, &exception
);
3586 } while (exception
.retry
);
3590 #define NFS4_LOCK_MINTIMEOUT (1 * HZ)
3591 #define NFS4_LOCK_MAXTIMEOUT (30 * HZ)
3594 * sleep, with exponential backoff, and retry the LOCK operation.
3596 static unsigned long
3597 nfs4_set_lock_task_retry(unsigned long timeout
)
3599 schedule_timeout_killable(timeout
);
3601 if (timeout
> NFS4_LOCK_MAXTIMEOUT
)
3602 return NFS4_LOCK_MAXTIMEOUT
;
3606 static int _nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3608 struct inode
*inode
= state
->inode
;
3609 struct nfs_server
*server
= NFS_SERVER(inode
);
3610 struct nfs_client
*clp
= server
->nfs_client
;
3611 struct nfs_lockt_args arg
= {
3612 .fh
= NFS_FH(inode
),
3615 struct nfs_lockt_res res
= {
3618 struct rpc_message msg
= {
3619 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKT
],
3622 .rpc_cred
= state
->owner
->so_cred
,
3624 struct nfs4_lock_state
*lsp
;
3627 arg
.lock_owner
.clientid
= clp
->cl_clientid
;
3628 status
= nfs4_set_lock_state(state
, request
);
3631 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3632 arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3633 status
= nfs4_call_sync(server
, &msg
, &arg
, &res
, 1);
3636 request
->fl_type
= F_UNLCK
;
3638 case -NFS4ERR_DENIED
:
3641 request
->fl_ops
->fl_release_private(request
);
3646 static int nfs4_proc_getlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3648 struct nfs4_exception exception
= { };
3652 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
3653 _nfs4_proc_getlk(state
, cmd
, request
),
3655 } while (exception
.retry
);
3659 static int do_vfs_lock(struct file
*file
, struct file_lock
*fl
)
3662 switch (fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)) {
3664 res
= posix_lock_file_wait(file
, fl
);
3667 res
= flock_lock_file_wait(file
, fl
);
3675 struct nfs4_unlockdata
{
3676 struct nfs_locku_args arg
;
3677 struct nfs_locku_res res
;
3678 struct nfs4_lock_state
*lsp
;
3679 struct nfs_open_context
*ctx
;
3680 struct file_lock fl
;
3681 const struct nfs_server
*server
;
3682 unsigned long timestamp
;
3685 static struct nfs4_unlockdata
*nfs4_alloc_unlockdata(struct file_lock
*fl
,
3686 struct nfs_open_context
*ctx
,
3687 struct nfs4_lock_state
*lsp
,
3688 struct nfs_seqid
*seqid
)
3690 struct nfs4_unlockdata
*p
;
3691 struct inode
*inode
= lsp
->ls_state
->inode
;
3693 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3696 p
->arg
.fh
= NFS_FH(inode
);
3698 p
->arg
.seqid
= seqid
;
3699 p
->res
.seqid
= seqid
;
3700 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3701 p
->arg
.stateid
= &lsp
->ls_stateid
;
3703 atomic_inc(&lsp
->ls_count
);
3704 /* Ensure we don't close file until we're done freeing locks! */
3705 p
->ctx
= get_nfs_open_context(ctx
);
3706 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3707 p
->server
= NFS_SERVER(inode
);
3711 static void nfs4_locku_release_calldata(void *data
)
3713 struct nfs4_unlockdata
*calldata
= data
;
3714 nfs_free_seqid(calldata
->arg
.seqid
);
3715 nfs4_put_lock_state(calldata
->lsp
);
3716 put_nfs_open_context(calldata
->ctx
);
3720 static void nfs4_locku_done(struct rpc_task
*task
, void *data
)
3722 struct nfs4_unlockdata
*calldata
= data
;
3724 nfs4_sequence_done(calldata
->server
, &calldata
->res
.seq_res
,
3726 if (RPC_ASSASSINATED(task
))
3728 switch (task
->tk_status
) {
3730 memcpy(calldata
->lsp
->ls_stateid
.data
,
3731 calldata
->res
.stateid
.data
,
3732 sizeof(calldata
->lsp
->ls_stateid
.data
));
3733 renew_lease(calldata
->server
, calldata
->timestamp
);
3735 case -NFS4ERR_BAD_STATEID
:
3736 case -NFS4ERR_OLD_STATEID
:
3737 case -NFS4ERR_STALE_STATEID
:
3738 case -NFS4ERR_EXPIRED
:
3741 if (nfs4_async_handle_error(task
, calldata
->server
, NULL
) == -EAGAIN
)
3742 nfs4_restart_rpc(task
,
3743 calldata
->server
->nfs_client
);
3745 nfs4_sequence_free_slot(calldata
->server
->nfs_client
,
3746 &calldata
->res
.seq_res
);
3749 static void nfs4_locku_prepare(struct rpc_task
*task
, void *data
)
3751 struct nfs4_unlockdata
*calldata
= data
;
3753 if (nfs_wait_on_sequence(calldata
->arg
.seqid
, task
) != 0)
3755 if ((calldata
->lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) == 0) {
3756 /* Note: exit _without_ running nfs4_locku_done */
3757 task
->tk_action
= NULL
;
3760 calldata
->timestamp
= jiffies
;
3761 if (nfs4_setup_sequence(calldata
->server
->nfs_client
,
3762 &calldata
->arg
.seq_args
,
3763 &calldata
->res
.seq_res
, 1, task
))
3765 rpc_call_start(task
);
3768 static const struct rpc_call_ops nfs4_locku_ops
= {
3769 .rpc_call_prepare
= nfs4_locku_prepare
,
3770 .rpc_call_done
= nfs4_locku_done
,
3771 .rpc_release
= nfs4_locku_release_calldata
,
3774 static struct rpc_task
*nfs4_do_unlck(struct file_lock
*fl
,
3775 struct nfs_open_context
*ctx
,
3776 struct nfs4_lock_state
*lsp
,
3777 struct nfs_seqid
*seqid
)
3779 struct nfs4_unlockdata
*data
;
3780 struct rpc_message msg
= {
3781 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCKU
],
3782 .rpc_cred
= ctx
->cred
,
3784 struct rpc_task_setup task_setup_data
= {
3785 .rpc_client
= NFS_CLIENT(lsp
->ls_state
->inode
),
3786 .rpc_message
= &msg
,
3787 .callback_ops
= &nfs4_locku_ops
,
3788 .workqueue
= nfsiod_workqueue
,
3789 .flags
= RPC_TASK_ASYNC
,
3792 /* Ensure this is an unlock - when canceling a lock, the
3793 * canceled lock is passed in, and it won't be an unlock.
3795 fl
->fl_type
= F_UNLCK
;
3797 data
= nfs4_alloc_unlockdata(fl
, ctx
, lsp
, seqid
);
3799 nfs_free_seqid(seqid
);
3800 return ERR_PTR(-ENOMEM
);
3803 msg
.rpc_argp
= &data
->arg
,
3804 msg
.rpc_resp
= &data
->res
,
3805 task_setup_data
.callback_data
= data
;
3806 return rpc_run_task(&task_setup_data
);
3809 static int nfs4_proc_unlck(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
3811 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
3812 struct nfs_seqid
*seqid
;
3813 struct nfs4_lock_state
*lsp
;
3814 struct rpc_task
*task
;
3816 unsigned char fl_flags
= request
->fl_flags
;
3818 status
= nfs4_set_lock_state(state
, request
);
3819 /* Unlock _before_ we do the RPC call */
3820 request
->fl_flags
|= FL_EXISTS
;
3821 down_read(&nfsi
->rwsem
);
3822 if (do_vfs_lock(request
->fl_file
, request
) == -ENOENT
) {
3823 up_read(&nfsi
->rwsem
);
3826 up_read(&nfsi
->rwsem
);
3829 /* Is this a delegated lock? */
3830 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
))
3832 lsp
= request
->fl_u
.nfs4_fl
.owner
;
3833 seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3837 task
= nfs4_do_unlck(request
, nfs_file_open_context(request
->fl_file
), lsp
, seqid
);
3838 status
= PTR_ERR(task
);
3841 status
= nfs4_wait_for_completion_rpc_task(task
);
3844 request
->fl_flags
= fl_flags
;
3848 struct nfs4_lockdata
{
3849 struct nfs_lock_args arg
;
3850 struct nfs_lock_res res
;
3851 struct nfs4_lock_state
*lsp
;
3852 struct nfs_open_context
*ctx
;
3853 struct file_lock fl
;
3854 unsigned long timestamp
;
3857 struct nfs_server
*server
;
3860 static struct nfs4_lockdata
*nfs4_alloc_lockdata(struct file_lock
*fl
,
3861 struct nfs_open_context
*ctx
, struct nfs4_lock_state
*lsp
)
3863 struct nfs4_lockdata
*p
;
3864 struct inode
*inode
= lsp
->ls_state
->inode
;
3865 struct nfs_server
*server
= NFS_SERVER(inode
);
3867 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
3871 p
->arg
.fh
= NFS_FH(inode
);
3873 p
->arg
.open_seqid
= nfs_alloc_seqid(&lsp
->ls_state
->owner
->so_seqid
);
3874 if (p
->arg
.open_seqid
== NULL
)
3876 p
->arg
.lock_seqid
= nfs_alloc_seqid(&lsp
->ls_seqid
);
3877 if (p
->arg
.lock_seqid
== NULL
)
3878 goto out_free_seqid
;
3879 p
->arg
.lock_stateid
= &lsp
->ls_stateid
;
3880 p
->arg
.lock_owner
.clientid
= server
->nfs_client
->cl_clientid
;
3881 p
->arg
.lock_owner
.id
= lsp
->ls_id
.id
;
3882 p
->res
.lock_seqid
= p
->arg
.lock_seqid
;
3883 p
->res
.seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
3886 atomic_inc(&lsp
->ls_count
);
3887 p
->ctx
= get_nfs_open_context(ctx
);
3888 memcpy(&p
->fl
, fl
, sizeof(p
->fl
));
3891 nfs_free_seqid(p
->arg
.open_seqid
);
3897 static void nfs4_lock_prepare(struct rpc_task
*task
, void *calldata
)
3899 struct nfs4_lockdata
*data
= calldata
;
3900 struct nfs4_state
*state
= data
->lsp
->ls_state
;
3902 dprintk("%s: begin!\n", __func__
);
3903 if (nfs_wait_on_sequence(data
->arg
.lock_seqid
, task
) != 0)
3905 /* Do we need to do an open_to_lock_owner? */
3906 if (!(data
->arg
.lock_seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)) {
3907 if (nfs_wait_on_sequence(data
->arg
.open_seqid
, task
) != 0)
3909 data
->arg
.open_stateid
= &state
->stateid
;
3910 data
->arg
.new_lock_owner
= 1;
3911 data
->res
.open_seqid
= data
->arg
.open_seqid
;
3913 data
->arg
.new_lock_owner
= 0;
3914 data
->timestamp
= jiffies
;
3915 if (nfs4_setup_sequence(data
->server
->nfs_client
, &data
->arg
.seq_args
,
3916 &data
->res
.seq_res
, 1, task
))
3918 rpc_call_start(task
);
3919 dprintk("%s: done!, ret = %d\n", __func__
, data
->rpc_status
);
3922 static void nfs4_lock_done(struct rpc_task
*task
, void *calldata
)
3924 struct nfs4_lockdata
*data
= calldata
;
3926 dprintk("%s: begin!\n", __func__
);
3928 nfs4_sequence_done_free_slot(data
->server
, &data
->res
.seq_res
,
3931 data
->rpc_status
= task
->tk_status
;
3932 if (RPC_ASSASSINATED(task
))
3934 if (data
->arg
.new_lock_owner
!= 0) {
3935 if (data
->rpc_status
== 0)
3936 nfs_confirm_seqid(&data
->lsp
->ls_seqid
, 0);
3940 if (data
->rpc_status
== 0) {
3941 memcpy(data
->lsp
->ls_stateid
.data
, data
->res
.stateid
.data
,
3942 sizeof(data
->lsp
->ls_stateid
.data
));
3943 data
->lsp
->ls_flags
|= NFS_LOCK_INITIALIZED
;
3944 renew_lease(NFS_SERVER(data
->ctx
->path
.dentry
->d_inode
), data
->timestamp
);
3947 dprintk("%s: done, ret = %d!\n", __func__
, data
->rpc_status
);
3950 static void nfs4_lock_release(void *calldata
)
3952 struct nfs4_lockdata
*data
= calldata
;
3954 dprintk("%s: begin!\n", __func__
);
3955 nfs_free_seqid(data
->arg
.open_seqid
);
3956 if (data
->cancelled
!= 0) {
3957 struct rpc_task
*task
;
3958 task
= nfs4_do_unlck(&data
->fl
, data
->ctx
, data
->lsp
,
3959 data
->arg
.lock_seqid
);
3962 dprintk("%s: cancelling lock!\n", __func__
);
3964 nfs_free_seqid(data
->arg
.lock_seqid
);
3965 nfs4_put_lock_state(data
->lsp
);
3966 put_nfs_open_context(data
->ctx
);
3968 dprintk("%s: done!\n", __func__
);
3971 static const struct rpc_call_ops nfs4_lock_ops
= {
3972 .rpc_call_prepare
= nfs4_lock_prepare
,
3973 .rpc_call_done
= nfs4_lock_done
,
3974 .rpc_release
= nfs4_lock_release
,
3977 static int _nfs4_do_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*fl
, int reclaim
)
3979 struct nfs4_lockdata
*data
;
3980 struct rpc_task
*task
;
3981 struct rpc_message msg
= {
3982 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_LOCK
],
3983 .rpc_cred
= state
->owner
->so_cred
,
3985 struct rpc_task_setup task_setup_data
= {
3986 .rpc_client
= NFS_CLIENT(state
->inode
),
3987 .rpc_message
= &msg
,
3988 .callback_ops
= &nfs4_lock_ops
,
3989 .workqueue
= nfsiod_workqueue
,
3990 .flags
= RPC_TASK_ASYNC
,
3994 dprintk("%s: begin!\n", __func__
);
3995 data
= nfs4_alloc_lockdata(fl
, nfs_file_open_context(fl
->fl_file
),
3996 fl
->fl_u
.nfs4_fl
.owner
);
4000 data
->arg
.block
= 1;
4002 data
->arg
.reclaim
= 1;
4003 msg
.rpc_argp
= &data
->arg
,
4004 msg
.rpc_resp
= &data
->res
,
4005 task_setup_data
.callback_data
= data
;
4006 task
= rpc_run_task(&task_setup_data
);
4008 return PTR_ERR(task
);
4009 ret
= nfs4_wait_for_completion_rpc_task(task
);
4011 ret
= data
->rpc_status
;
4013 data
->cancelled
= 1;
4015 dprintk("%s: done, ret = %d!\n", __func__
, ret
);
4019 static int nfs4_lock_reclaim(struct nfs4_state
*state
, struct file_lock
*request
)
4021 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4022 struct nfs4_exception exception
= { };
4026 /* Cache the lock if possible... */
4027 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4029 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 1);
4030 if (err
!= -NFS4ERR_DELAY
)
4032 nfs4_handle_exception(server
, err
, &exception
);
4033 } while (exception
.retry
);
4037 static int nfs4_lock_expired(struct nfs4_state
*state
, struct file_lock
*request
)
4039 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4040 struct nfs4_exception exception
= { };
4043 err
= nfs4_set_lock_state(state
, request
);
4047 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
) != 0)
4049 err
= _nfs4_do_setlk(state
, F_SETLK
, request
, 0);
4050 if (err
!= -NFS4ERR_DELAY
)
4052 nfs4_handle_exception(server
, err
, &exception
);
4053 } while (exception
.retry
);
4057 static int _nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4059 struct nfs_inode
*nfsi
= NFS_I(state
->inode
);
4060 unsigned char fl_flags
= request
->fl_flags
;
4063 /* Is this a delegated open? */
4064 status
= nfs4_set_lock_state(state
, request
);
4067 request
->fl_flags
|= FL_ACCESS
;
4068 status
= do_vfs_lock(request
->fl_file
, request
);
4071 down_read(&nfsi
->rwsem
);
4072 if (test_bit(NFS_DELEGATED_STATE
, &state
->flags
)) {
4073 /* Yes: cache locks! */
4074 /* ...but avoid races with delegation recall... */
4075 request
->fl_flags
= fl_flags
& ~FL_SLEEP
;
4076 status
= do_vfs_lock(request
->fl_file
, request
);
4079 status
= _nfs4_do_setlk(state
, cmd
, request
, 0);
4082 /* Note: we always want to sleep here! */
4083 request
->fl_flags
= fl_flags
| FL_SLEEP
;
4084 if (do_vfs_lock(request
->fl_file
, request
) < 0)
4085 printk(KERN_WARNING
"%s: VFS is out of sync with lock manager!\n", __func__
);
4087 up_read(&nfsi
->rwsem
);
4089 request
->fl_flags
= fl_flags
;
4093 static int nfs4_proc_setlk(struct nfs4_state
*state
, int cmd
, struct file_lock
*request
)
4095 struct nfs4_exception exception
= { };
4099 err
= _nfs4_proc_setlk(state
, cmd
, request
);
4100 if (err
== -NFS4ERR_DENIED
)
4102 err
= nfs4_handle_exception(NFS_SERVER(state
->inode
),
4104 } while (exception
.retry
);
4109 nfs4_proc_lock(struct file
*filp
, int cmd
, struct file_lock
*request
)
4111 struct nfs_open_context
*ctx
;
4112 struct nfs4_state
*state
;
4113 unsigned long timeout
= NFS4_LOCK_MINTIMEOUT
;
4116 /* verify open state */
4117 ctx
= nfs_file_open_context(filp
);
4120 if (request
->fl_start
< 0 || request
->fl_end
< 0)
4123 if (IS_GETLK(cmd
)) {
4125 return nfs4_proc_getlk(state
, F_GETLK
, request
);
4129 if (!(IS_SETLK(cmd
) || IS_SETLKW(cmd
)))
4132 if (request
->fl_type
== F_UNLCK
) {
4134 return nfs4_proc_unlck(state
, cmd
, request
);
4141 status
= nfs4_proc_setlk(state
, cmd
, request
);
4142 if ((status
!= -EAGAIN
) || IS_SETLK(cmd
))
4144 timeout
= nfs4_set_lock_task_retry(timeout
);
4145 status
= -ERESTARTSYS
;
4148 } while(status
< 0);
4152 int nfs4_lock_delegation_recall(struct nfs4_state
*state
, struct file_lock
*fl
)
4154 struct nfs_server
*server
= NFS_SERVER(state
->inode
);
4155 struct nfs4_exception exception
= { };
4158 err
= nfs4_set_lock_state(state
, fl
);
4162 err
= _nfs4_do_setlk(state
, F_SETLK
, fl
, 0);
4165 printk(KERN_ERR
"%s: unhandled error %d.\n",
4170 case -NFS4ERR_EXPIRED
:
4171 case -NFS4ERR_STALE_CLIENTID
:
4172 case -NFS4ERR_STALE_STATEID
:
4173 nfs4_schedule_state_recovery(server
->nfs_client
);
4177 * The show must go on: exit, but mark the
4178 * stateid as needing recovery.
4180 case -NFS4ERR_ADMIN_REVOKED
:
4181 case -NFS4ERR_BAD_STATEID
:
4182 case -NFS4ERR_OPENMODE
:
4183 nfs4_state_mark_reclaim_nograce(server
->nfs_client
, state
);
4187 case -NFS4ERR_DENIED
:
4188 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
4191 case -NFS4ERR_DELAY
:
4194 err
= nfs4_handle_exception(server
, err
, &exception
);
4195 } while (exception
.retry
);
4200 #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
4202 int nfs4_setxattr(struct dentry
*dentry
, const char *key
, const void *buf
,
4203 size_t buflen
, int flags
)
4205 struct inode
*inode
= dentry
->d_inode
;
4207 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4210 return nfs4_proc_set_acl(inode
, buf
, buflen
);
4213 /* The getxattr man page suggests returning -ENODATA for unknown attributes,
4214 * and that's what we'll do for e.g. user attributes that haven't been set.
4215 * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported
4216 * attributes in kernel-managed attribute namespaces. */
4217 ssize_t
nfs4_getxattr(struct dentry
*dentry
, const char *key
, void *buf
,
4220 struct inode
*inode
= dentry
->d_inode
;
4222 if (strcmp(key
, XATTR_NAME_NFSV4_ACL
) != 0)
4225 return nfs4_proc_get_acl(inode
, buf
, buflen
);
4228 ssize_t
nfs4_listxattr(struct dentry
*dentry
, char *buf
, size_t buflen
)
4230 size_t len
= strlen(XATTR_NAME_NFSV4_ACL
) + 1;
4232 if (!nfs4_server_supports_acls(NFS_SERVER(dentry
->d_inode
)))
4234 if (buf
&& buflen
< len
)
4237 memcpy(buf
, XATTR_NAME_NFSV4_ACL
, len
);
4241 static void nfs_fixup_referral_attributes(struct nfs_fattr
*fattr
)
4243 if (!((fattr
->valid
& NFS_ATTR_FATTR_FILEID
) &&
4244 (fattr
->valid
& NFS_ATTR_FATTR_FSID
) &&
4245 (fattr
->valid
& NFS_ATTR_FATTR_V4_REFERRAL
)))
4248 fattr
->valid
|= NFS_ATTR_FATTR_TYPE
| NFS_ATTR_FATTR_MODE
|
4249 NFS_ATTR_FATTR_NLINK
;
4250 fattr
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
4254 int nfs4_proc_fs_locations(struct inode
*dir
, const struct qstr
*name
,
4255 struct nfs4_fs_locations
*fs_locations
, struct page
*page
)
4257 struct nfs_server
*server
= NFS_SERVER(dir
);
4259 [0] = FATTR4_WORD0_FSID
| FATTR4_WORD0_FS_LOCATIONS
,
4260 [1] = FATTR4_WORD1_MOUNTED_ON_FILEID
,
4262 struct nfs4_fs_locations_arg args
= {
4263 .dir_fh
= NFS_FH(dir
),
4268 struct nfs4_fs_locations_res res
= {
4269 .fs_locations
= fs_locations
,
4271 struct rpc_message msg
= {
4272 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_FS_LOCATIONS
],
4278 dprintk("%s: start\n", __func__
);
4279 nfs_fattr_init(&fs_locations
->fattr
);
4280 fs_locations
->server
= server
;
4281 fs_locations
->nlocations
= 0;
4282 status
= nfs4_call_sync(server
, &msg
, &args
, &res
, 0);
4283 nfs_fixup_referral_attributes(&fs_locations
->fattr
);
4284 dprintk("%s: returned status = %d\n", __func__
, status
);
4288 #ifdef CONFIG_NFS_V4_1
4290 * nfs4_proc_exchange_id()
4292 * Since the clientid has expired, all compounds using sessions
4293 * associated with the stale clientid will be returning
4294 * NFS4ERR_BADSESSION in the sequence operation, and will therefore
4295 * be in some phase of session reset.
4297 static int nfs4_proc_exchange_id(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4299 nfs4_verifier verifier
;
4300 struct nfs41_exchange_id_args args
= {
4302 .flags
= clp
->cl_exchange_flags
,
4304 struct nfs41_exchange_id_res res
= {
4308 struct rpc_message msg
= {
4309 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_EXCHANGE_ID
],
4316 dprintk("--> %s\n", __func__
);
4317 BUG_ON(clp
== NULL
);
4319 p
= (u32
*)verifier
.data
;
4320 *p
++ = htonl((u32
)clp
->cl_boot_time
.tv_sec
);
4321 *p
= htonl((u32
)clp
->cl_boot_time
.tv_nsec
);
4322 args
.verifier
= &verifier
;
4325 args
.id_len
= scnprintf(args
.id
, sizeof(args
.id
),
4328 rpc_peeraddr2str(clp
->cl_rpcclient
,
4330 clp
->cl_id_uniquifier
);
4332 status
= rpc_call_sync(clp
->cl_rpcclient
, &msg
, 0);
4334 if (status
!= NFS4ERR_CLID_INUSE
)
4340 if (++clp
->cl_id_uniquifier
== 0)
4344 dprintk("<-- %s status= %d\n", __func__
, status
);
4348 struct nfs4_get_lease_time_data
{
4349 struct nfs4_get_lease_time_args
*args
;
4350 struct nfs4_get_lease_time_res
*res
;
4351 struct nfs_client
*clp
;
4354 static void nfs4_get_lease_time_prepare(struct rpc_task
*task
,
4358 struct nfs4_get_lease_time_data
*data
=
4359 (struct nfs4_get_lease_time_data
*)calldata
;
4361 dprintk("--> %s\n", __func__
);
4362 /* just setup sequence, do not trigger session recovery
4363 since we're invoked within one */
4364 ret
= nfs41_setup_sequence(data
->clp
->cl_session
,
4365 &data
->args
->la_seq_args
,
4366 &data
->res
->lr_seq_res
, 0, task
);
4368 BUG_ON(ret
== -EAGAIN
);
4369 rpc_call_start(task
);
4370 dprintk("<-- %s\n", __func__
);
4374 * Called from nfs4_state_manager thread for session setup, so don't recover
4375 * from sequence operation or clientid errors.
4377 static void nfs4_get_lease_time_done(struct rpc_task
*task
, void *calldata
)
4379 struct nfs4_get_lease_time_data
*data
=
4380 (struct nfs4_get_lease_time_data
*)calldata
;
4382 dprintk("--> %s\n", __func__
);
4383 nfs41_sequence_done(data
->clp
, &data
->res
->lr_seq_res
, task
->tk_status
);
4384 switch (task
->tk_status
) {
4385 case -NFS4ERR_DELAY
:
4386 case -NFS4ERR_GRACE
:
4387 dprintk("%s Retry: tk_status %d\n", __func__
, task
->tk_status
);
4388 rpc_delay(task
, NFS4_POLL_RETRY_MIN
);
4389 task
->tk_status
= 0;
4390 nfs4_restart_rpc(task
, data
->clp
);
4393 nfs41_sequence_free_slot(data
->clp
, &data
->res
->lr_seq_res
);
4394 dprintk("<-- %s\n", __func__
);
4397 struct rpc_call_ops nfs4_get_lease_time_ops
= {
4398 .rpc_call_prepare
= nfs4_get_lease_time_prepare
,
4399 .rpc_call_done
= nfs4_get_lease_time_done
,
4402 int nfs4_proc_get_lease_time(struct nfs_client
*clp
, struct nfs_fsinfo
*fsinfo
)
4404 struct rpc_task
*task
;
4405 struct nfs4_get_lease_time_args args
;
4406 struct nfs4_get_lease_time_res res
= {
4407 .lr_fsinfo
= fsinfo
,
4409 struct nfs4_get_lease_time_data data
= {
4414 struct rpc_message msg
= {
4415 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_GET_LEASE_TIME
],
4419 struct rpc_task_setup task_setup
= {
4420 .rpc_client
= clp
->cl_rpcclient
,
4421 .rpc_message
= &msg
,
4422 .callback_ops
= &nfs4_get_lease_time_ops
,
4423 .callback_data
= &data
4427 res
.lr_seq_res
.sr_slotid
= NFS4_MAX_SLOT_TABLE
;
4428 dprintk("--> %s\n", __func__
);
4429 task
= rpc_run_task(&task_setup
);
4432 status
= PTR_ERR(task
);
4434 status
= task
->tk_status
;
4437 dprintk("<-- %s return %d\n", __func__
, status
);
4443 * Reset a slot table
4445 static int nfs4_reset_slot_table(struct nfs4_slot_table
*tbl
, int max_slots
,
4446 int old_max_slots
, int ivalue
)
4451 dprintk("--> %s: max_reqs=%u, tbl %p\n", __func__
, max_slots
, tbl
);
4454 * Until we have dynamic slot table adjustment, insist
4455 * upon the same slot table size
4457 if (max_slots
!= old_max_slots
) {
4458 dprintk("%s reset slot table does't match old\n",
4460 ret
= -EINVAL
; /*XXX NFS4ERR_REQ_TOO_BIG ? */
4463 spin_lock(&tbl
->slot_tbl_lock
);
4464 for (i
= 0; i
< max_slots
; ++i
)
4465 tbl
->slots
[i
].seq_nr
= ivalue
;
4466 tbl
->highest_used_slotid
= -1;
4467 spin_unlock(&tbl
->slot_tbl_lock
);
4468 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4469 tbl
, tbl
->slots
, tbl
->max_slots
);
4471 dprintk("<-- %s: return %d\n", __func__
, ret
);
4476 * Reset the forechannel and backchannel slot tables
4478 static int nfs4_reset_slot_tables(struct nfs4_session
*session
)
4482 status
= nfs4_reset_slot_table(&session
->fc_slot_table
,
4483 session
->fc_attrs
.max_reqs
,
4484 session
->fc_slot_table
.max_slots
,
4489 status
= nfs4_reset_slot_table(&session
->bc_slot_table
,
4490 session
->bc_attrs
.max_reqs
,
4491 session
->bc_slot_table
.max_slots
,
4496 /* Destroy the slot table */
4497 static void nfs4_destroy_slot_tables(struct nfs4_session
*session
)
4499 if (session
->fc_slot_table
.slots
!= NULL
) {
4500 kfree(session
->fc_slot_table
.slots
);
4501 session
->fc_slot_table
.slots
= NULL
;
4503 if (session
->bc_slot_table
.slots
!= NULL
) {
4504 kfree(session
->bc_slot_table
.slots
);
4505 session
->bc_slot_table
.slots
= NULL
;
4511 * Initialize slot table
4513 static int nfs4_init_slot_table(struct nfs4_slot_table
*tbl
,
4514 int max_slots
, int ivalue
)
4517 struct nfs4_slot
*slot
;
4520 BUG_ON(max_slots
> NFS4_MAX_SLOT_TABLE
);
4522 dprintk("--> %s: max_reqs=%u\n", __func__
, max_slots
);
4524 slot
= kcalloc(max_slots
, sizeof(struct nfs4_slot
), GFP_KERNEL
);
4527 for (i
= 0; i
< max_slots
; ++i
)
4528 slot
[i
].seq_nr
= ivalue
;
4531 spin_lock(&tbl
->slot_tbl_lock
);
4532 if (tbl
->slots
!= NULL
) {
4533 spin_unlock(&tbl
->slot_tbl_lock
);
4534 dprintk("%s: slot table already initialized. tbl=%p slots=%p\n",
4535 __func__
, tbl
, tbl
->slots
);
4539 tbl
->max_slots
= max_slots
;
4541 tbl
->highest_used_slotid
= -1; /* no slot is currently used */
4542 spin_unlock(&tbl
->slot_tbl_lock
);
4543 dprintk("%s: tbl=%p slots=%p max_slots=%d\n", __func__
,
4544 tbl
, tbl
->slots
, tbl
->max_slots
);
4546 dprintk("<-- %s: return %d\n", __func__
, ret
);
4555 * Initialize the forechannel and backchannel tables
4557 static int nfs4_init_slot_tables(struct nfs4_session
*session
)
4561 status
= nfs4_init_slot_table(&session
->fc_slot_table
,
4562 session
->fc_attrs
.max_reqs
, 1);
4566 status
= nfs4_init_slot_table(&session
->bc_slot_table
,
4567 session
->bc_attrs
.max_reqs
, 0);
4569 nfs4_destroy_slot_tables(session
);
4574 struct nfs4_session
*nfs4_alloc_session(struct nfs_client
*clp
)
4576 struct nfs4_session
*session
;
4577 struct nfs4_slot_table
*tbl
;
4579 session
= kzalloc(sizeof(struct nfs4_session
), GFP_KERNEL
);
4583 set_bit(NFS4CLNT_SESSION_SETUP
, &clp
->cl_state
);
4585 * The create session reply races with the server back
4586 * channel probe. Mark the client NFS_CS_SESSION_INITING
4587 * so that the client back channel can find the
4590 clp
->cl_cons_state
= NFS_CS_SESSION_INITING
;
4592 tbl
= &session
->fc_slot_table
;
4593 spin_lock_init(&tbl
->slot_tbl_lock
);
4594 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "ForeChannel Slot table");
4596 tbl
= &session
->bc_slot_table
;
4597 spin_lock_init(&tbl
->slot_tbl_lock
);
4598 rpc_init_wait_queue(&tbl
->slot_tbl_waitq
, "BackChannel Slot table");
4604 void nfs4_destroy_session(struct nfs4_session
*session
)
4606 nfs4_proc_destroy_session(session
);
4607 dprintk("%s Destroy backchannel for xprt %p\n",
4608 __func__
, session
->clp
->cl_rpcclient
->cl_xprt
);
4609 xprt_destroy_backchannel(session
->clp
->cl_rpcclient
->cl_xprt
,
4610 NFS41_BC_MIN_CALLBACKS
);
4611 nfs4_destroy_slot_tables(session
);
4616 * Initialize the values to be used by the client in CREATE_SESSION
4617 * If nfs4_init_session set the fore channel request and response sizes,
4620 * Set the back channel max_resp_sz_cached to zero to force the client to
4621 * always set csa_cachethis to FALSE because the current implementation
4622 * of the back channel DRC only supports caching the CB_SEQUENCE operation.
4624 static void nfs4_init_channel_attrs(struct nfs41_create_session_args
*args
)
4626 struct nfs4_session
*session
= args
->client
->cl_session
;
4627 unsigned int mxrqst_sz
= session
->fc_attrs
.max_rqst_sz
,
4628 mxresp_sz
= session
->fc_attrs
.max_resp_sz
;
4631 mxrqst_sz
= NFS_MAX_FILE_IO_SIZE
;
4633 mxresp_sz
= NFS_MAX_FILE_IO_SIZE
;
4634 /* Fore channel attributes */
4635 args
->fc_attrs
.headerpadsz
= 0;
4636 args
->fc_attrs
.max_rqst_sz
= mxrqst_sz
;
4637 args
->fc_attrs
.max_resp_sz
= mxresp_sz
;
4638 args
->fc_attrs
.max_resp_sz_cached
= mxresp_sz
;
4639 args
->fc_attrs
.max_ops
= NFS4_MAX_OPS
;
4640 args
->fc_attrs
.max_reqs
= session
->clp
->cl_rpcclient
->cl_xprt
->max_reqs
;
4642 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
4643 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4645 args
->fc_attrs
.max_rqst_sz
, args
->fc_attrs
.max_resp_sz
,
4646 args
->fc_attrs
.max_resp_sz_cached
, args
->fc_attrs
.max_ops
,
4647 args
->fc_attrs
.max_reqs
);
4649 /* Back channel attributes */
4650 args
->bc_attrs
.headerpadsz
= 0;
4651 args
->bc_attrs
.max_rqst_sz
= PAGE_SIZE
;
4652 args
->bc_attrs
.max_resp_sz
= PAGE_SIZE
;
4653 args
->bc_attrs
.max_resp_sz_cached
= 0;
4654 args
->bc_attrs
.max_ops
= NFS4_MAX_BACK_CHANNEL_OPS
;
4655 args
->bc_attrs
.max_reqs
= 1;
4657 dprintk("%s: Back Channel : max_rqst_sz=%u max_resp_sz=%u "
4658 "max_resp_sz_cached=%u max_ops=%u max_reqs=%u\n",
4660 args
->bc_attrs
.max_rqst_sz
, args
->bc_attrs
.max_resp_sz
,
4661 args
->bc_attrs
.max_resp_sz_cached
, args
->bc_attrs
.max_ops
,
4662 args
->bc_attrs
.max_reqs
);
4665 static int _verify_channel_attr(char *chan
, char *attr_name
, u32 sent
, u32 rcvd
)
4669 printk(KERN_WARNING
"%s: Session INVALID: %s channel %s increased. "
4670 "sent=%u rcvd=%u\n", __func__
, chan
, attr_name
, sent
, rcvd
);
4674 #define _verify_fore_channel_attr(_name_) \
4675 _verify_channel_attr("fore", #_name_, \
4676 args->fc_attrs._name_, \
4677 session->fc_attrs._name_)
4679 #define _verify_back_channel_attr(_name_) \
4680 _verify_channel_attr("back", #_name_, \
4681 args->bc_attrs._name_, \
4682 session->bc_attrs._name_)
4685 * The server is not allowed to increase the fore channel header pad size,
4686 * maximum response size, or maximum number of operations.
4688 * The back channel attributes are only negotiatied down: We send what the
4689 * (back channel) server insists upon.
4691 static int nfs4_verify_channel_attrs(struct nfs41_create_session_args
*args
,
4692 struct nfs4_session
*session
)
4696 ret
|= _verify_fore_channel_attr(headerpadsz
);
4697 ret
|= _verify_fore_channel_attr(max_resp_sz
);
4698 ret
|= _verify_fore_channel_attr(max_ops
);
4700 ret
|= _verify_back_channel_attr(headerpadsz
);
4701 ret
|= _verify_back_channel_attr(max_rqst_sz
);
4702 ret
|= _verify_back_channel_attr(max_resp_sz
);
4703 ret
|= _verify_back_channel_attr(max_resp_sz_cached
);
4704 ret
|= _verify_back_channel_attr(max_ops
);
4705 ret
|= _verify_back_channel_attr(max_reqs
);
4710 static int _nfs4_proc_create_session(struct nfs_client
*clp
)
4712 struct nfs4_session
*session
= clp
->cl_session
;
4713 struct nfs41_create_session_args args
= {
4715 .cb_program
= NFS4_CALLBACK
,
4717 struct nfs41_create_session_res res
= {
4720 struct rpc_message msg
= {
4721 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_CREATE_SESSION
],
4727 nfs4_init_channel_attrs(&args
);
4728 args
.flags
= (SESSION4_PERSIST
| SESSION4_BACK_CHAN
);
4730 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4733 /* Verify the session's negotiated channel_attrs values */
4734 status
= nfs4_verify_channel_attrs(&args
, session
);
4736 /* Increment the clientid slot sequence id */
4744 * Issues a CREATE_SESSION operation to the server.
4745 * It is the responsibility of the caller to verify the session is
4746 * expired before calling this routine.
4748 int nfs4_proc_create_session(struct nfs_client
*clp
, int reset
)
4752 struct nfs_fsinfo fsinfo
;
4753 struct nfs4_session
*session
= clp
->cl_session
;
4755 dprintk("--> %s clp=%p session=%p\n", __func__
, clp
, session
);
4757 status
= _nfs4_proc_create_session(clp
);
4761 /* Init or reset the fore channel */
4763 status
= nfs4_reset_slot_tables(session
);
4765 status
= nfs4_init_slot_tables(session
);
4766 dprintk("fore channel slot table initialization returned %d\n", status
);
4770 ptr
= (unsigned *)&session
->sess_id
.data
[0];
4771 dprintk("%s client>seqid %d sessionid %u:%u:%u:%u\n", __func__
,
4772 clp
->cl_seqid
, ptr
[0], ptr
[1], ptr
[2], ptr
[3]);
4775 /* Lease time is aleady set */
4778 /* Get the lease time */
4779 status
= nfs4_proc_get_lease_time(clp
, &fsinfo
);
4781 /* Update lease time and schedule renewal */
4782 spin_lock(&clp
->cl_lock
);
4783 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
4784 clp
->cl_last_renewal
= jiffies
;
4785 clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
4786 spin_unlock(&clp
->cl_lock
);
4788 nfs4_schedule_state_renewal(clp
);
4791 dprintk("<-- %s\n", __func__
);
4796 * Issue the over-the-wire RPC DESTROY_SESSION.
4797 * The caller must serialize access to this routine.
4799 int nfs4_proc_destroy_session(struct nfs4_session
*session
)
4802 struct rpc_message msg
;
4804 dprintk("--> nfs4_proc_destroy_session\n");
4806 /* session is still being setup */
4807 if (session
->clp
->cl_cons_state
!= NFS_CS_READY
)
4810 msg
.rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_DESTROY_SESSION
];
4811 msg
.rpc_argp
= session
;
4812 msg
.rpc_resp
= NULL
;
4813 msg
.rpc_cred
= NULL
;
4814 status
= rpc_call_sync(session
->clp
->cl_rpcclient
, &msg
, 0);
4818 "Got error %d from the server on DESTROY_SESSION. "
4819 "Session has been destroyed regardless...\n", status
);
4821 dprintk("<-- nfs4_proc_destroy_session\n");
4825 int nfs4_init_session(struct nfs_server
*server
)
4827 struct nfs_client
*clp
= server
->nfs_client
;
4830 if (!nfs4_has_session(clp
))
4833 clp
->cl_session
->fc_attrs
.max_rqst_sz
= server
->wsize
;
4834 clp
->cl_session
->fc_attrs
.max_resp_sz
= server
->rsize
;
4835 ret
= nfs4_recover_expired_lease(server
);
4837 ret
= nfs4_check_client_ready(clp
);
4842 * Renew the cl_session lease.
4844 static int nfs4_proc_sequence(struct nfs_client
*clp
, struct rpc_cred
*cred
)
4846 struct nfs4_sequence_args args
;
4847 struct nfs4_sequence_res res
;
4849 struct rpc_message msg
= {
4850 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
4856 args
.sa_cache_this
= 0;
4858 return nfs4_call_sync_sequence(clp
, clp
->cl_rpcclient
, &msg
, &args
,
4862 void nfs41_sequence_call_done(struct rpc_task
*task
, void *data
)
4864 struct nfs_client
*clp
= (struct nfs_client
*)data
;
4866 nfs41_sequence_done(clp
, task
->tk_msg
.rpc_resp
, task
->tk_status
);
4868 if (task
->tk_status
< 0) {
4869 dprintk("%s ERROR %d\n", __func__
, task
->tk_status
);
4871 if (_nfs4_async_handle_error(task
, NULL
, clp
, NULL
)
4873 nfs4_restart_rpc(task
, clp
);
4877 nfs41_sequence_free_slot(clp
, task
->tk_msg
.rpc_resp
);
4878 dprintk("%s rpc_cred %p\n", __func__
, task
->tk_msg
.rpc_cred
);
4880 put_rpccred(task
->tk_msg
.rpc_cred
);
4881 kfree(task
->tk_msg
.rpc_argp
);
4882 kfree(task
->tk_msg
.rpc_resp
);
4884 dprintk("<-- %s\n", __func__
);
4887 static void nfs41_sequence_prepare(struct rpc_task
*task
, void *data
)
4889 struct nfs_client
*clp
;
4890 struct nfs4_sequence_args
*args
;
4891 struct nfs4_sequence_res
*res
;
4893 clp
= (struct nfs_client
*)data
;
4894 args
= task
->tk_msg
.rpc_argp
;
4895 res
= task
->tk_msg
.rpc_resp
;
4897 if (nfs4_setup_sequence(clp
, args
, res
, 0, task
))
4899 rpc_call_start(task
);
4902 static const struct rpc_call_ops nfs41_sequence_ops
= {
4903 .rpc_call_done
= nfs41_sequence_call_done
,
4904 .rpc_call_prepare
= nfs41_sequence_prepare
,
4907 static int nfs41_proc_async_sequence(struct nfs_client
*clp
,
4908 struct rpc_cred
*cred
)
4910 struct nfs4_sequence_args
*args
;
4911 struct nfs4_sequence_res
*res
;
4912 struct rpc_message msg
= {
4913 .rpc_proc
= &nfs4_procedures
[NFSPROC4_CLNT_SEQUENCE
],
4917 args
= kzalloc(sizeof(*args
), GFP_KERNEL
);
4920 res
= kzalloc(sizeof(*res
), GFP_KERNEL
);
4925 res
->sr_slotid
= NFS4_MAX_SLOT_TABLE
;
4926 msg
.rpc_argp
= args
;
4929 return rpc_call_async(clp
->cl_rpcclient
, &msg
, RPC_TASK_SOFT
,
4930 &nfs41_sequence_ops
, (void *)clp
);
4933 #endif /* CONFIG_NFS_V4_1 */
4935 struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops
= {
4936 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
4937 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
4938 .recover_open
= nfs4_open_reclaim
,
4939 .recover_lock
= nfs4_lock_reclaim
,
4940 .establish_clid
= nfs4_init_clientid
,
4941 .get_clid_cred
= nfs4_get_setclientid_cred
,
4944 #if defined(CONFIG_NFS_V4_1)
4945 struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops
= {
4946 .owner_flag_bit
= NFS_OWNER_RECLAIM_REBOOT
,
4947 .state_flag_bit
= NFS_STATE_RECLAIM_REBOOT
,
4948 .recover_open
= nfs4_open_reclaim
,
4949 .recover_lock
= nfs4_lock_reclaim
,
4950 .establish_clid
= nfs4_proc_exchange_id
,
4951 .get_clid_cred
= nfs4_get_exchange_id_cred
,
4953 #endif /* CONFIG_NFS_V4_1 */
4955 struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops
= {
4956 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
4957 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
4958 .recover_open
= nfs4_open_expired
,
4959 .recover_lock
= nfs4_lock_expired
,
4960 .establish_clid
= nfs4_init_clientid
,
4961 .get_clid_cred
= nfs4_get_setclientid_cred
,
4964 #if defined(CONFIG_NFS_V4_1)
4965 struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops
= {
4966 .owner_flag_bit
= NFS_OWNER_RECLAIM_NOGRACE
,
4967 .state_flag_bit
= NFS_STATE_RECLAIM_NOGRACE
,
4968 .recover_open
= nfs4_open_expired
,
4969 .recover_lock
= nfs4_lock_expired
,
4970 .establish_clid
= nfs4_proc_exchange_id
,
4971 .get_clid_cred
= nfs4_get_exchange_id_cred
,
4973 #endif /* CONFIG_NFS_V4_1 */
4975 struct nfs4_state_maintenance_ops nfs40_state_renewal_ops
= {
4976 .sched_state_renewal
= nfs4_proc_async_renew
,
4977 .get_state_renewal_cred_locked
= nfs4_get_renew_cred_locked
,
4978 .renew_lease
= nfs4_proc_renew
,
4981 #if defined(CONFIG_NFS_V4_1)
4982 struct nfs4_state_maintenance_ops nfs41_state_renewal_ops
= {
4983 .sched_state_renewal
= nfs41_proc_async_sequence
,
4984 .get_state_renewal_cred_locked
= nfs4_get_machine_cred_locked
,
4985 .renew_lease
= nfs4_proc_sequence
,
4990 * Per minor version reboot and network partition recovery ops
4993 struct nfs4_state_recovery_ops
*nfs4_reboot_recovery_ops
[] = {
4994 &nfs40_reboot_recovery_ops
,
4995 #if defined(CONFIG_NFS_V4_1)
4996 &nfs41_reboot_recovery_ops
,
5000 struct nfs4_state_recovery_ops
*nfs4_nograce_recovery_ops
[] = {
5001 &nfs40_nograce_recovery_ops
,
5002 #if defined(CONFIG_NFS_V4_1)
5003 &nfs41_nograce_recovery_ops
,
5007 struct nfs4_state_maintenance_ops
*nfs4_state_renewal_ops
[] = {
5008 &nfs40_state_renewal_ops
,
5009 #if defined(CONFIG_NFS_V4_1)
5010 &nfs41_state_renewal_ops
,
5014 static const struct inode_operations nfs4_file_inode_operations
= {
5015 .permission
= nfs_permission
,
5016 .getattr
= nfs_getattr
,
5017 .setattr
= nfs_setattr
,
5018 .getxattr
= nfs4_getxattr
,
5019 .setxattr
= nfs4_setxattr
,
5020 .listxattr
= nfs4_listxattr
,
5023 const struct nfs_rpc_ops nfs_v4_clientops
= {
5024 .version
= 4, /* protocol version */
5025 .dentry_ops
= &nfs4_dentry_operations
,
5026 .dir_inode_ops
= &nfs4_dir_inode_operations
,
5027 .file_inode_ops
= &nfs4_file_inode_operations
,
5028 .getroot
= nfs4_proc_get_root
,
5029 .getattr
= nfs4_proc_getattr
,
5030 .setattr
= nfs4_proc_setattr
,
5031 .lookupfh
= nfs4_proc_lookupfh
,
5032 .lookup
= nfs4_proc_lookup
,
5033 .access
= nfs4_proc_access
,
5034 .readlink
= nfs4_proc_readlink
,
5035 .create
= nfs4_proc_create
,
5036 .remove
= nfs4_proc_remove
,
5037 .unlink_setup
= nfs4_proc_unlink_setup
,
5038 .unlink_done
= nfs4_proc_unlink_done
,
5039 .rename
= nfs4_proc_rename
,
5040 .link
= nfs4_proc_link
,
5041 .symlink
= nfs4_proc_symlink
,
5042 .mkdir
= nfs4_proc_mkdir
,
5043 .rmdir
= nfs4_proc_remove
,
5044 .readdir
= nfs4_proc_readdir
,
5045 .mknod
= nfs4_proc_mknod
,
5046 .statfs
= nfs4_proc_statfs
,
5047 .fsinfo
= nfs4_proc_fsinfo
,
5048 .pathconf
= nfs4_proc_pathconf
,
5049 .set_capabilities
= nfs4_server_capabilities
,
5050 .decode_dirent
= nfs4_decode_dirent
,
5051 .read_setup
= nfs4_proc_read_setup
,
5052 .read_done
= nfs4_read_done
,
5053 .write_setup
= nfs4_proc_write_setup
,
5054 .write_done
= nfs4_write_done
,
5055 .commit_setup
= nfs4_proc_commit_setup
,
5056 .commit_done
= nfs4_commit_done
,
5057 .lock
= nfs4_proc_lock
,
5058 .clear_acl_cache
= nfs4_zap_acl_attr
,
5059 .close_context
= nfs4_close_context
,