4 * Client-side XDR for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
9 * Kendrick Smith <kmsmith@umich.edu>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Implementation of the NFSv4 state model. For the time being,
37 * this is minimal, but will be made much more complex in a
41 #include <linux/kernel.h>
42 #include <linux/slab.h>
43 #include <linux/smp_lock.h>
44 #include <linux/nfs_fs.h>
45 #include <linux/nfs_idmap.h>
46 #include <linux/kthread.h>
47 #include <linux/module.h>
48 #include <linux/random.h>
49 #include <linux/workqueue.h>
50 #include <linux/bitops.h>
54 #include "delegation.h"
57 #define OPENOWNER_POOL_SIZE 8
59 const nfs4_stateid zero_stateid
;
61 static LIST_HEAD(nfs4_clientid_list
);
63 int nfs4_init_clientid(struct nfs_client
*clp
, struct rpc_cred
*cred
)
68 port
= nfs_callback_tcpport
;
69 if (clp
->cl_addr
.ss_family
== AF_INET6
)
70 port
= nfs_callback_tcpport6
;
72 status
= nfs4_proc_setclientid(clp
, NFS4_CALLBACK
, port
, cred
);
74 status
= nfs4_proc_setclientid_confirm(clp
, cred
);
76 nfs4_schedule_state_renewal(clp
);
80 struct rpc_cred
*nfs4_get_machine_cred_locked(struct nfs_client
*clp
)
82 struct rpc_cred
*cred
= NULL
;
84 if (clp
->cl_machine_cred
!= NULL
)
85 cred
= get_rpccred(clp
->cl_machine_cred
);
89 static void nfs4_clear_machine_cred(struct nfs_client
*clp
)
91 struct rpc_cred
*cred
;
93 spin_lock(&clp
->cl_lock
);
94 cred
= clp
->cl_machine_cred
;
95 clp
->cl_machine_cred
= NULL
;
96 spin_unlock(&clp
->cl_lock
);
101 struct rpc_cred
*nfs4_get_renew_cred_locked(struct nfs_client
*clp
)
103 struct nfs4_state_owner
*sp
;
105 struct rpc_cred
*cred
= NULL
;
107 for (pos
= rb_first(&clp
->cl_state_owners
); pos
!= NULL
; pos
= rb_next(pos
)) {
108 sp
= rb_entry(pos
, struct nfs4_state_owner
, so_client_node
);
109 if (list_empty(&sp
->so_states
))
111 cred
= get_rpccred(sp
->so_cred
);
117 #if defined(CONFIG_NFS_V4_1)
119 static int nfs41_setup_state_renewal(struct nfs_client
*clp
)
122 struct nfs_fsinfo fsinfo
;
124 status
= nfs4_proc_get_lease_time(clp
, &fsinfo
);
126 /* Update lease time and schedule renewal */
127 spin_lock(&clp
->cl_lock
);
128 clp
->cl_lease_time
= fsinfo
.lease_time
* HZ
;
129 clp
->cl_last_renewal
= jiffies
;
130 spin_unlock(&clp
->cl_lock
);
132 nfs4_schedule_state_renewal(clp
);
138 static void nfs4_end_drain_session(struct nfs_client
*clp
)
140 struct nfs4_session
*ses
= clp
->cl_session
;
143 if (test_and_clear_bit(NFS4CLNT_SESSION_DRAINING
, &clp
->cl_state
)) {
144 spin_lock(&ses
->fc_slot_table
.slot_tbl_lock
);
145 max_slots
= ses
->fc_slot_table
.max_slots
;
146 while (max_slots
--) {
147 struct rpc_task
*task
;
149 task
= rpc_wake_up_next(&ses
->fc_slot_table
.
153 rpc_task_set_priority(task
, RPC_PRIORITY_PRIVILEGED
);
155 spin_unlock(&ses
->fc_slot_table
.slot_tbl_lock
);
159 static int nfs4_begin_drain_session(struct nfs_client
*clp
)
161 struct nfs4_session
*ses
= clp
->cl_session
;
162 struct nfs4_slot_table
*tbl
= &ses
->fc_slot_table
;
164 spin_lock(&tbl
->slot_tbl_lock
);
165 set_bit(NFS4CLNT_SESSION_DRAINING
, &clp
->cl_state
);
166 if (tbl
->highest_used_slotid
!= -1) {
167 INIT_COMPLETION(ses
->complete
);
168 spin_unlock(&tbl
->slot_tbl_lock
);
169 return wait_for_completion_interruptible(&ses
->complete
);
171 spin_unlock(&tbl
->slot_tbl_lock
);
175 int nfs41_init_clientid(struct nfs_client
*clp
, struct rpc_cred
*cred
)
179 nfs4_begin_drain_session(clp
);
180 status
= nfs4_proc_exchange_id(clp
, cred
);
183 status
= nfs4_proc_create_session(clp
);
186 nfs41_setup_state_renewal(clp
);
187 nfs_mark_client_ready(clp
, NFS_CS_READY
);
192 struct rpc_cred
*nfs4_get_exchange_id_cred(struct nfs_client
*clp
)
194 struct rpc_cred
*cred
;
196 spin_lock(&clp
->cl_lock
);
197 cred
= nfs4_get_machine_cred_locked(clp
);
198 spin_unlock(&clp
->cl_lock
);
202 #endif /* CONFIG_NFS_V4_1 */
204 struct rpc_cred
*nfs4_get_setclientid_cred(struct nfs_client
*clp
)
206 struct nfs4_state_owner
*sp
;
208 struct rpc_cred
*cred
;
210 spin_lock(&clp
->cl_lock
);
211 cred
= nfs4_get_machine_cred_locked(clp
);
214 pos
= rb_first(&clp
->cl_state_owners
);
216 sp
= rb_entry(pos
, struct nfs4_state_owner
, so_client_node
);
217 cred
= get_rpccred(sp
->so_cred
);
220 spin_unlock(&clp
->cl_lock
);
224 static void nfs_alloc_unique_id(struct rb_root
*root
, struct nfs_unique_id
*new,
225 __u64 minval
, int maxbits
)
227 struct rb_node
**p
, *parent
;
228 struct nfs_unique_id
*pos
;
232 mask
= (1ULL << maxbits
) - 1ULL;
234 /* Ensure distribution is more or less flat */
235 get_random_bytes(&new->id
, sizeof(new->id
));
237 if (new->id
< minval
)
245 pos
= rb_entry(parent
, struct nfs_unique_id
, rb_node
);
247 if (new->id
< pos
->id
)
249 else if (new->id
> pos
->id
)
254 rb_link_node(&new->rb_node
, parent
, p
);
255 rb_insert_color(&new->rb_node
, root
);
260 if (new->id
< minval
|| (new->id
& mask
) != new->id
) {
264 parent
= rb_next(parent
);
267 pos
= rb_entry(parent
, struct nfs_unique_id
, rb_node
);
268 if (new->id
< pos
->id
)
274 static void nfs_free_unique_id(struct rb_root
*root
, struct nfs_unique_id
*id
)
276 rb_erase(&id
->rb_node
, root
);
279 static struct nfs4_state_owner
*
280 nfs4_find_state_owner(struct nfs_server
*server
, struct rpc_cred
*cred
)
282 struct nfs_client
*clp
= server
->nfs_client
;
283 struct rb_node
**p
= &clp
->cl_state_owners
.rb_node
,
285 struct nfs4_state_owner
*sp
, *res
= NULL
;
289 sp
= rb_entry(parent
, struct nfs4_state_owner
, so_client_node
);
291 if (server
< sp
->so_server
) {
292 p
= &parent
->rb_left
;
295 if (server
> sp
->so_server
) {
296 p
= &parent
->rb_right
;
299 if (cred
< sp
->so_cred
)
300 p
= &parent
->rb_left
;
301 else if (cred
> sp
->so_cred
)
302 p
= &parent
->rb_right
;
304 atomic_inc(&sp
->so_count
);
312 static struct nfs4_state_owner
*
313 nfs4_insert_state_owner(struct nfs_client
*clp
, struct nfs4_state_owner
*new)
315 struct rb_node
**p
= &clp
->cl_state_owners
.rb_node
,
317 struct nfs4_state_owner
*sp
;
321 sp
= rb_entry(parent
, struct nfs4_state_owner
, so_client_node
);
323 if (new->so_server
< sp
->so_server
) {
324 p
= &parent
->rb_left
;
327 if (new->so_server
> sp
->so_server
) {
328 p
= &parent
->rb_right
;
331 if (new->so_cred
< sp
->so_cred
)
332 p
= &parent
->rb_left
;
333 else if (new->so_cred
> sp
->so_cred
)
334 p
= &parent
->rb_right
;
336 atomic_inc(&sp
->so_count
);
340 nfs_alloc_unique_id(&clp
->cl_openowner_id
, &new->so_owner_id
, 1, 64);
341 rb_link_node(&new->so_client_node
, parent
, p
);
342 rb_insert_color(&new->so_client_node
, &clp
->cl_state_owners
);
347 nfs4_remove_state_owner(struct nfs_client
*clp
, struct nfs4_state_owner
*sp
)
349 if (!RB_EMPTY_NODE(&sp
->so_client_node
))
350 rb_erase(&sp
->so_client_node
, &clp
->cl_state_owners
);
351 nfs_free_unique_id(&clp
->cl_openowner_id
, &sp
->so_owner_id
);
355 * nfs4_alloc_state_owner(): this is called on the OPEN or CREATE path to
356 * create a new state_owner.
359 static struct nfs4_state_owner
*
360 nfs4_alloc_state_owner(void)
362 struct nfs4_state_owner
*sp
;
364 sp
= kzalloc(sizeof(*sp
),GFP_KERNEL
);
367 spin_lock_init(&sp
->so_lock
);
368 INIT_LIST_HEAD(&sp
->so_states
);
369 INIT_LIST_HEAD(&sp
->so_delegations
);
370 rpc_init_wait_queue(&sp
->so_sequence
.wait
, "Seqid_waitqueue");
371 sp
->so_seqid
.sequence
= &sp
->so_sequence
;
372 spin_lock_init(&sp
->so_sequence
.lock
);
373 INIT_LIST_HEAD(&sp
->so_sequence
.list
);
374 atomic_set(&sp
->so_count
, 1);
379 nfs4_drop_state_owner(struct nfs4_state_owner
*sp
)
381 if (!RB_EMPTY_NODE(&sp
->so_client_node
)) {
382 struct nfs_client
*clp
= sp
->so_client
;
384 spin_lock(&clp
->cl_lock
);
385 rb_erase(&sp
->so_client_node
, &clp
->cl_state_owners
);
386 RB_CLEAR_NODE(&sp
->so_client_node
);
387 spin_unlock(&clp
->cl_lock
);
391 struct nfs4_state_owner
*nfs4_get_state_owner(struct nfs_server
*server
, struct rpc_cred
*cred
)
393 struct nfs_client
*clp
= server
->nfs_client
;
394 struct nfs4_state_owner
*sp
, *new;
396 spin_lock(&clp
->cl_lock
);
397 sp
= nfs4_find_state_owner(server
, cred
);
398 spin_unlock(&clp
->cl_lock
);
401 new = nfs4_alloc_state_owner();
404 new->so_client
= clp
;
405 new->so_server
= server
;
407 spin_lock(&clp
->cl_lock
);
408 sp
= nfs4_insert_state_owner(clp
, new);
409 spin_unlock(&clp
->cl_lock
);
413 rpc_destroy_wait_queue(&new->so_sequence
.wait
);
419 void nfs4_put_state_owner(struct nfs4_state_owner
*sp
)
421 struct nfs_client
*clp
= sp
->so_client
;
422 struct rpc_cred
*cred
= sp
->so_cred
;
424 if (!atomic_dec_and_lock(&sp
->so_count
, &clp
->cl_lock
))
426 nfs4_remove_state_owner(clp
, sp
);
427 spin_unlock(&clp
->cl_lock
);
428 rpc_destroy_wait_queue(&sp
->so_sequence
.wait
);
433 static struct nfs4_state
*
434 nfs4_alloc_open_state(void)
436 struct nfs4_state
*state
;
438 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
441 atomic_set(&state
->count
, 1);
442 INIT_LIST_HEAD(&state
->lock_states
);
443 spin_lock_init(&state
->state_lock
);
444 seqlock_init(&state
->seqlock
);
449 nfs4_state_set_mode_locked(struct nfs4_state
*state
, fmode_t fmode
)
451 if (state
->state
== fmode
)
453 /* NB! List reordering - see the reclaim code for why. */
454 if ((fmode
& FMODE_WRITE
) != (state
->state
& FMODE_WRITE
)) {
455 if (fmode
& FMODE_WRITE
)
456 list_move(&state
->open_states
, &state
->owner
->so_states
);
458 list_move_tail(&state
->open_states
, &state
->owner
->so_states
);
460 state
->state
= fmode
;
463 static struct nfs4_state
*
464 __nfs4_find_state_byowner(struct inode
*inode
, struct nfs4_state_owner
*owner
)
466 struct nfs_inode
*nfsi
= NFS_I(inode
);
467 struct nfs4_state
*state
;
469 list_for_each_entry(state
, &nfsi
->open_states
, inode_states
) {
470 if (state
->owner
!= owner
)
472 if (atomic_inc_not_zero(&state
->count
))
479 nfs4_free_open_state(struct nfs4_state
*state
)
485 nfs4_get_open_state(struct inode
*inode
, struct nfs4_state_owner
*owner
)
487 struct nfs4_state
*state
, *new;
488 struct nfs_inode
*nfsi
= NFS_I(inode
);
490 spin_lock(&inode
->i_lock
);
491 state
= __nfs4_find_state_byowner(inode
, owner
);
492 spin_unlock(&inode
->i_lock
);
495 new = nfs4_alloc_open_state();
496 spin_lock(&owner
->so_lock
);
497 spin_lock(&inode
->i_lock
);
498 state
= __nfs4_find_state_byowner(inode
, owner
);
499 if (state
== NULL
&& new != NULL
) {
501 state
->owner
= owner
;
502 atomic_inc(&owner
->so_count
);
503 list_add(&state
->inode_states
, &nfsi
->open_states
);
504 state
->inode
= igrab(inode
);
505 spin_unlock(&inode
->i_lock
);
506 /* Note: The reclaim code dictates that we add stateless
507 * and read-only stateids to the end of the list */
508 list_add_tail(&state
->open_states
, &owner
->so_states
);
509 spin_unlock(&owner
->so_lock
);
511 spin_unlock(&inode
->i_lock
);
512 spin_unlock(&owner
->so_lock
);
514 nfs4_free_open_state(new);
520 void nfs4_put_open_state(struct nfs4_state
*state
)
522 struct inode
*inode
= state
->inode
;
523 struct nfs4_state_owner
*owner
= state
->owner
;
525 if (!atomic_dec_and_lock(&state
->count
, &owner
->so_lock
))
527 spin_lock(&inode
->i_lock
);
528 list_del(&state
->inode_states
);
529 list_del(&state
->open_states
);
530 spin_unlock(&inode
->i_lock
);
531 spin_unlock(&owner
->so_lock
);
533 nfs4_free_open_state(state
);
534 nfs4_put_state_owner(owner
);
538 * Close the current file.
540 static void __nfs4_close(struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
, int wait
)
542 struct nfs4_state_owner
*owner
= state
->owner
;
546 atomic_inc(&owner
->so_count
);
547 /* Protect against nfs4_find_state() */
548 spin_lock(&owner
->so_lock
);
549 switch (fmode
& (FMODE_READ
| FMODE_WRITE
)) {
556 case FMODE_READ
|FMODE_WRITE
:
559 newstate
= FMODE_READ
|FMODE_WRITE
;
560 if (state
->n_rdwr
== 0) {
561 if (state
->n_rdonly
== 0) {
562 newstate
&= ~FMODE_READ
;
563 call_close
|= test_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
564 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
566 if (state
->n_wronly
== 0) {
567 newstate
&= ~FMODE_WRITE
;
568 call_close
|= test_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
569 call_close
|= test_bit(NFS_O_RDWR_STATE
, &state
->flags
);
572 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
574 nfs4_state_set_mode_locked(state
, newstate
);
575 spin_unlock(&owner
->so_lock
);
578 nfs4_put_open_state(state
);
579 nfs4_put_state_owner(owner
);
581 nfs4_do_close(path
, state
, wait
);
584 void nfs4_close_state(struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
)
586 __nfs4_close(path
, state
, fmode
, 0);
589 void nfs4_close_sync(struct path
*path
, struct nfs4_state
*state
, fmode_t fmode
)
591 __nfs4_close(path
, state
, fmode
, 1);
595 * Search the state->lock_states for an existing lock_owner
596 * that is compatible with current->files
598 static struct nfs4_lock_state
*
599 __nfs4_find_lock_state(struct nfs4_state
*state
, fl_owner_t fl_owner
)
601 struct nfs4_lock_state
*pos
;
602 list_for_each_entry(pos
, &state
->lock_states
, ls_locks
) {
603 if (pos
->ls_owner
!= fl_owner
)
605 atomic_inc(&pos
->ls_count
);
612 * Return a compatible lock_state. If no initialized lock_state structure
613 * exists, return an uninitialized one.
616 static struct nfs4_lock_state
*nfs4_alloc_lock_state(struct nfs4_state
*state
, fl_owner_t fl_owner
)
618 struct nfs4_lock_state
*lsp
;
619 struct nfs_client
*clp
= state
->owner
->so_client
;
621 lsp
= kzalloc(sizeof(*lsp
), GFP_KERNEL
);
624 rpc_init_wait_queue(&lsp
->ls_sequence
.wait
, "lock_seqid_waitqueue");
625 spin_lock_init(&lsp
->ls_sequence
.lock
);
626 INIT_LIST_HEAD(&lsp
->ls_sequence
.list
);
627 lsp
->ls_seqid
.sequence
= &lsp
->ls_sequence
;
628 atomic_set(&lsp
->ls_count
, 1);
629 lsp
->ls_state
= state
;
630 lsp
->ls_owner
= fl_owner
;
631 spin_lock(&clp
->cl_lock
);
632 nfs_alloc_unique_id(&clp
->cl_lockowner_id
, &lsp
->ls_id
, 1, 64);
633 spin_unlock(&clp
->cl_lock
);
634 INIT_LIST_HEAD(&lsp
->ls_locks
);
638 static void nfs4_free_lock_state(struct nfs4_lock_state
*lsp
)
640 struct nfs_client
*clp
= lsp
->ls_state
->owner
->so_client
;
642 spin_lock(&clp
->cl_lock
);
643 nfs_free_unique_id(&clp
->cl_lockowner_id
, &lsp
->ls_id
);
644 spin_unlock(&clp
->cl_lock
);
645 rpc_destroy_wait_queue(&lsp
->ls_sequence
.wait
);
650 * Return a compatible lock_state. If no initialized lock_state structure
651 * exists, return an uninitialized one.
654 static struct nfs4_lock_state
*nfs4_get_lock_state(struct nfs4_state
*state
, fl_owner_t owner
)
656 struct nfs4_lock_state
*lsp
, *new = NULL
;
659 spin_lock(&state
->state_lock
);
660 lsp
= __nfs4_find_lock_state(state
, owner
);
664 list_add(&new->ls_locks
, &state
->lock_states
);
665 set_bit(LK_STATE_IN_USE
, &state
->flags
);
670 spin_unlock(&state
->state_lock
);
671 new = nfs4_alloc_lock_state(state
, owner
);
675 spin_unlock(&state
->state_lock
);
677 nfs4_free_lock_state(new);
682 * Release reference to lock_state, and free it if we see that
683 * it is no longer in use
685 void nfs4_put_lock_state(struct nfs4_lock_state
*lsp
)
687 struct nfs4_state
*state
;
691 state
= lsp
->ls_state
;
692 if (!atomic_dec_and_lock(&lsp
->ls_count
, &state
->state_lock
))
694 list_del(&lsp
->ls_locks
);
695 if (list_empty(&state
->lock_states
))
696 clear_bit(LK_STATE_IN_USE
, &state
->flags
);
697 spin_unlock(&state
->state_lock
);
698 nfs4_free_lock_state(lsp
);
701 static void nfs4_fl_copy_lock(struct file_lock
*dst
, struct file_lock
*src
)
703 struct nfs4_lock_state
*lsp
= src
->fl_u
.nfs4_fl
.owner
;
705 dst
->fl_u
.nfs4_fl
.owner
= lsp
;
706 atomic_inc(&lsp
->ls_count
);
709 static void nfs4_fl_release_lock(struct file_lock
*fl
)
711 nfs4_put_lock_state(fl
->fl_u
.nfs4_fl
.owner
);
714 static const struct file_lock_operations nfs4_fl_lock_ops
= {
715 .fl_copy_lock
= nfs4_fl_copy_lock
,
716 .fl_release_private
= nfs4_fl_release_lock
,
719 int nfs4_set_lock_state(struct nfs4_state
*state
, struct file_lock
*fl
)
721 struct nfs4_lock_state
*lsp
;
723 if (fl
->fl_ops
!= NULL
)
725 lsp
= nfs4_get_lock_state(state
, fl
->fl_owner
);
728 fl
->fl_u
.nfs4_fl
.owner
= lsp
;
729 fl
->fl_ops
= &nfs4_fl_lock_ops
;
734 * Byte-range lock aware utility to initialize the stateid of read/write
737 void nfs4_copy_stateid(nfs4_stateid
*dst
, struct nfs4_state
*state
, fl_owner_t fl_owner
)
739 struct nfs4_lock_state
*lsp
;
743 seq
= read_seqbegin(&state
->seqlock
);
744 memcpy(dst
, &state
->stateid
, sizeof(*dst
));
745 } while (read_seqretry(&state
->seqlock
, seq
));
746 if (test_bit(LK_STATE_IN_USE
, &state
->flags
) == 0)
749 spin_lock(&state
->state_lock
);
750 lsp
= __nfs4_find_lock_state(state
, fl_owner
);
751 if (lsp
!= NULL
&& (lsp
->ls_flags
& NFS_LOCK_INITIALIZED
) != 0)
752 memcpy(dst
, &lsp
->ls_stateid
, sizeof(*dst
));
753 spin_unlock(&state
->state_lock
);
754 nfs4_put_lock_state(lsp
);
757 struct nfs_seqid
*nfs_alloc_seqid(struct nfs_seqid_counter
*counter
)
759 struct nfs_seqid
*new;
761 new = kmalloc(sizeof(*new), GFP_KERNEL
);
763 new->sequence
= counter
;
764 INIT_LIST_HEAD(&new->list
);
769 void nfs_release_seqid(struct nfs_seqid
*seqid
)
771 if (!list_empty(&seqid
->list
)) {
772 struct rpc_sequence
*sequence
= seqid
->sequence
->sequence
;
774 spin_lock(&sequence
->lock
);
775 list_del_init(&seqid
->list
);
776 spin_unlock(&sequence
->lock
);
777 rpc_wake_up(&sequence
->wait
);
781 void nfs_free_seqid(struct nfs_seqid
*seqid
)
783 nfs_release_seqid(seqid
);
788 * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
789 * failed with a seqid incrementing error -
790 * see comments nfs_fs.h:seqid_mutating_error()
792 static void nfs_increment_seqid(int status
, struct nfs_seqid
*seqid
)
794 BUG_ON(list_first_entry(&seqid
->sequence
->sequence
->list
, struct nfs_seqid
, list
) != seqid
);
798 case -NFS4ERR_BAD_SEQID
:
799 if (seqid
->sequence
->flags
& NFS_SEQID_CONFIRMED
)
801 printk(KERN_WARNING
"NFS: v4 server returned a bad"
802 " sequence-id error on an"
803 " unconfirmed sequence %p!\n",
805 case -NFS4ERR_STALE_CLIENTID
:
806 case -NFS4ERR_STALE_STATEID
:
807 case -NFS4ERR_BAD_STATEID
:
808 case -NFS4ERR_BADXDR
:
809 case -NFS4ERR_RESOURCE
:
810 case -NFS4ERR_NOFILEHANDLE
:
811 /* Non-seqid mutating errors */
815 * Note: no locking needed as we are guaranteed to be first
816 * on the sequence list
818 seqid
->sequence
->counter
++;
821 void nfs_increment_open_seqid(int status
, struct nfs_seqid
*seqid
)
823 struct nfs4_state_owner
*sp
= container_of(seqid
->sequence
,
824 struct nfs4_state_owner
, so_seqid
);
825 struct nfs_server
*server
= sp
->so_server
;
827 if (status
== -NFS4ERR_BAD_SEQID
)
828 nfs4_drop_state_owner(sp
);
829 if (!nfs4_has_session(server
->nfs_client
))
830 nfs_increment_seqid(status
, seqid
);
834 * Increment the seqid if the LOCK/LOCKU succeeded, or
835 * failed with a seqid incrementing error -
836 * see comments nfs_fs.h:seqid_mutating_error()
838 void nfs_increment_lock_seqid(int status
, struct nfs_seqid
*seqid
)
840 nfs_increment_seqid(status
, seqid
);
843 int nfs_wait_on_sequence(struct nfs_seqid
*seqid
, struct rpc_task
*task
)
845 struct rpc_sequence
*sequence
= seqid
->sequence
->sequence
;
848 spin_lock(&sequence
->lock
);
849 if (list_empty(&seqid
->list
))
850 list_add_tail(&seqid
->list
, &sequence
->list
);
851 if (list_first_entry(&sequence
->list
, struct nfs_seqid
, list
) == seqid
)
853 rpc_sleep_on(&sequence
->wait
, task
, NULL
);
856 spin_unlock(&sequence
->lock
);
860 static int nfs4_run_state_manager(void *);
862 static void nfs4_clear_state_manager_bit(struct nfs_client
*clp
)
864 smp_mb__before_clear_bit();
865 clear_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
);
866 smp_mb__after_clear_bit();
867 wake_up_bit(&clp
->cl_state
, NFS4CLNT_MANAGER_RUNNING
);
868 rpc_wake_up(&clp
->cl_rpcwaitq
);
872 * Schedule the nfs_client asynchronous state management routine
874 void nfs4_schedule_state_manager(struct nfs_client
*clp
)
876 struct task_struct
*task
;
878 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) != 0)
880 __module_get(THIS_MODULE
);
881 atomic_inc(&clp
->cl_count
);
882 task
= kthread_run(nfs4_run_state_manager
, clp
, "%s-manager",
883 rpc_peeraddr2str(clp
->cl_rpcclient
,
887 nfs4_clear_state_manager_bit(clp
);
889 module_put(THIS_MODULE
);
893 * Schedule a state recovery attempt
895 void nfs4_schedule_state_recovery(struct nfs_client
*clp
)
899 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
900 set_bit(NFS4CLNT_CHECK_LEASE
, &clp
->cl_state
);
901 nfs4_schedule_state_manager(clp
);
904 int nfs4_state_mark_reclaim_reboot(struct nfs_client
*clp
, struct nfs4_state
*state
)
907 set_bit(NFS_STATE_RECLAIM_REBOOT
, &state
->flags
);
908 /* Don't recover state that expired before the reboot */
909 if (test_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
)) {
910 clear_bit(NFS_STATE_RECLAIM_REBOOT
, &state
->flags
);
913 set_bit(NFS_OWNER_RECLAIM_REBOOT
, &state
->owner
->so_flags
);
914 set_bit(NFS4CLNT_RECLAIM_REBOOT
, &clp
->cl_state
);
918 int nfs4_state_mark_reclaim_nograce(struct nfs_client
*clp
, struct nfs4_state
*state
)
920 set_bit(NFS_STATE_RECLAIM_NOGRACE
, &state
->flags
);
921 clear_bit(NFS_STATE_RECLAIM_REBOOT
, &state
->flags
);
922 set_bit(NFS_OWNER_RECLAIM_NOGRACE
, &state
->owner
->so_flags
);
923 set_bit(NFS4CLNT_RECLAIM_NOGRACE
, &clp
->cl_state
);
927 static int nfs4_reclaim_locks(struct nfs4_state
*state
, const struct nfs4_state_recovery_ops
*ops
)
929 struct inode
*inode
= state
->inode
;
930 struct nfs_inode
*nfsi
= NFS_I(inode
);
931 struct file_lock
*fl
;
934 if (inode
->i_flock
== NULL
)
937 /* Guard against delegation returns and new lock/unlock calls */
938 down_write(&nfsi
->rwsem
);
939 /* Protect inode->i_flock using the BKL */
941 for (fl
= inode
->i_flock
; fl
!= NULL
; fl
= fl
->fl_next
) {
942 if (!(fl
->fl_flags
& (FL_POSIX
|FL_FLOCK
)))
944 if (nfs_file_open_context(fl
->fl_file
)->state
!= state
)
947 status
= ops
->recover_lock(state
, fl
);
952 case -NFS4ERR_ADMIN_REVOKED
:
953 case -NFS4ERR_STALE_STATEID
:
954 case -NFS4ERR_BAD_STATEID
:
955 case -NFS4ERR_EXPIRED
:
956 case -NFS4ERR_NO_GRACE
:
957 case -NFS4ERR_STALE_CLIENTID
:
958 case -NFS4ERR_BADSESSION
:
959 case -NFS4ERR_BADSLOT
:
960 case -NFS4ERR_BAD_HIGH_SLOT
:
961 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
964 printk(KERN_ERR
"%s: unhandled error %d. Zeroing state\n",
967 case -NFS4ERR_DENIED
:
968 case -NFS4ERR_RECLAIM_BAD
:
969 case -NFS4ERR_RECLAIM_CONFLICT
:
970 /* kill_proc(fl->fl_pid, SIGLOST, 1); */
977 up_write(&nfsi
->rwsem
);
981 static int nfs4_reclaim_open_state(struct nfs4_state_owner
*sp
, const struct nfs4_state_recovery_ops
*ops
)
983 struct nfs4_state
*state
;
984 struct nfs4_lock_state
*lock
;
987 /* Note: we rely on the sp->so_states list being ordered
988 * so that we always reclaim open(O_RDWR) and/or open(O_WRITE)
990 * This is needed to ensure that the server won't give us any
991 * read delegations that we have to return if, say, we are
992 * recovering after a network partition or a reboot from a
993 * server that doesn't support a grace period.
996 spin_lock(&sp
->so_lock
);
997 list_for_each_entry(state
, &sp
->so_states
, open_states
) {
998 if (!test_and_clear_bit(ops
->state_flag_bit
, &state
->flags
))
1000 if (state
->state
== 0)
1002 atomic_inc(&state
->count
);
1003 spin_unlock(&sp
->so_lock
);
1004 status
= ops
->recover_open(sp
, state
);
1006 status
= nfs4_reclaim_locks(state
, ops
);
1008 list_for_each_entry(lock
, &state
->lock_states
, ls_locks
) {
1009 if (!(lock
->ls_flags
& NFS_LOCK_INITIALIZED
))
1010 printk("%s: Lock reclaim failed!\n",
1013 nfs4_put_open_state(state
);
1019 printk(KERN_ERR
"%s: unhandled error %d. Zeroing state\n",
1025 * Open state on this file cannot be recovered
1026 * All we can do is revert to using the zero stateid.
1028 memset(state
->stateid
.data
, 0,
1029 sizeof(state
->stateid
.data
));
1030 /* Mark the file as being 'closed' */
1033 case -NFS4ERR_ADMIN_REVOKED
:
1034 case -NFS4ERR_STALE_STATEID
:
1035 case -NFS4ERR_BAD_STATEID
:
1036 case -NFS4ERR_RECLAIM_BAD
:
1037 case -NFS4ERR_RECLAIM_CONFLICT
:
1038 nfs4_state_mark_reclaim_nograce(sp
->so_client
, state
);
1040 case -NFS4ERR_EXPIRED
:
1041 case -NFS4ERR_NO_GRACE
:
1042 nfs4_state_mark_reclaim_nograce(sp
->so_client
, state
);
1043 case -NFS4ERR_STALE_CLIENTID
:
1044 case -NFS4ERR_BADSESSION
:
1045 case -NFS4ERR_BADSLOT
:
1046 case -NFS4ERR_BAD_HIGH_SLOT
:
1047 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1050 nfs4_put_open_state(state
);
1053 spin_unlock(&sp
->so_lock
);
1056 nfs4_put_open_state(state
);
1060 static void nfs4_clear_open_state(struct nfs4_state
*state
)
1062 struct nfs4_lock_state
*lock
;
1064 clear_bit(NFS_DELEGATED_STATE
, &state
->flags
);
1065 clear_bit(NFS_O_RDONLY_STATE
, &state
->flags
);
1066 clear_bit(NFS_O_WRONLY_STATE
, &state
->flags
);
1067 clear_bit(NFS_O_RDWR_STATE
, &state
->flags
);
1068 list_for_each_entry(lock
, &state
->lock_states
, ls_locks
) {
1069 lock
->ls_seqid
.flags
= 0;
1070 lock
->ls_flags
&= ~NFS_LOCK_INITIALIZED
;
1074 static void nfs4_state_mark_reclaim_helper(struct nfs_client
*clp
, int (*mark_reclaim
)(struct nfs_client
*clp
, struct nfs4_state
*state
))
1076 struct nfs4_state_owner
*sp
;
1077 struct rb_node
*pos
;
1078 struct nfs4_state
*state
;
1080 /* Reset all sequence ids to zero */
1081 for (pos
= rb_first(&clp
->cl_state_owners
); pos
!= NULL
; pos
= rb_next(pos
)) {
1082 sp
= rb_entry(pos
, struct nfs4_state_owner
, so_client_node
);
1083 sp
->so_seqid
.flags
= 0;
1084 spin_lock(&sp
->so_lock
);
1085 list_for_each_entry(state
, &sp
->so_states
, open_states
) {
1086 if (mark_reclaim(clp
, state
))
1087 nfs4_clear_open_state(state
);
1089 spin_unlock(&sp
->so_lock
);
1093 static void nfs4_state_start_reclaim_reboot(struct nfs_client
*clp
)
1095 /* Mark all delegations for reclaim */
1096 nfs_delegation_mark_reclaim(clp
);
1097 nfs4_state_mark_reclaim_helper(clp
, nfs4_state_mark_reclaim_reboot
);
1100 static void nfs4_reclaim_complete(struct nfs_client
*clp
,
1101 const struct nfs4_state_recovery_ops
*ops
)
1103 /* Notify the server we're done reclaiming our state */
1104 if (ops
->reclaim_complete
)
1105 (void)ops
->reclaim_complete(clp
);
1108 static void nfs4_state_end_reclaim_reboot(struct nfs_client
*clp
)
1110 struct nfs4_state_owner
*sp
;
1111 struct rb_node
*pos
;
1112 struct nfs4_state
*state
;
1114 if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT
, &clp
->cl_state
))
1117 nfs4_reclaim_complete(clp
,
1118 nfs4_reboot_recovery_ops
[clp
->cl_minorversion
]);
1120 for (pos
= rb_first(&clp
->cl_state_owners
); pos
!= NULL
; pos
= rb_next(pos
)) {
1121 sp
= rb_entry(pos
, struct nfs4_state_owner
, so_client_node
);
1122 spin_lock(&sp
->so_lock
);
1123 list_for_each_entry(state
, &sp
->so_states
, open_states
) {
1124 if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT
, &state
->flags
))
1126 nfs4_state_mark_reclaim_nograce(clp
, state
);
1128 spin_unlock(&sp
->so_lock
);
1131 nfs_delegation_reap_unclaimed(clp
);
1134 static void nfs_delegation_clear_all(struct nfs_client
*clp
)
1136 nfs_delegation_mark_reclaim(clp
);
1137 nfs_delegation_reap_unclaimed(clp
);
1140 static void nfs4_state_start_reclaim_nograce(struct nfs_client
*clp
)
1142 nfs_delegation_clear_all(clp
);
1143 nfs4_state_mark_reclaim_helper(clp
, nfs4_state_mark_reclaim_nograce
);
1146 static int nfs4_recovery_handle_error(struct nfs_client
*clp
, int error
)
1149 case -NFS4ERR_CB_PATH_DOWN
:
1150 nfs_handle_cb_pathdown(clp
);
1152 case -NFS4ERR_NO_GRACE
:
1153 nfs4_state_end_reclaim_reboot(clp
);
1155 case -NFS4ERR_STALE_CLIENTID
:
1156 case -NFS4ERR_LEASE_MOVED
:
1157 set_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
1158 nfs4_state_end_reclaim_reboot(clp
);
1159 nfs4_state_start_reclaim_reboot(clp
);
1161 case -NFS4ERR_EXPIRED
:
1162 set_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
1163 nfs4_state_start_reclaim_nograce(clp
);
1165 case -NFS4ERR_BADSESSION
:
1166 case -NFS4ERR_BADSLOT
:
1167 case -NFS4ERR_BAD_HIGH_SLOT
:
1168 case -NFS4ERR_DEADSESSION
:
1169 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION
:
1170 case -NFS4ERR_SEQ_FALSE_RETRY
:
1171 case -NFS4ERR_SEQ_MISORDERED
:
1172 set_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
);
1173 /* Zero session reset errors */
1179 static int nfs4_do_reclaim(struct nfs_client
*clp
, const struct nfs4_state_recovery_ops
*ops
)
1181 struct rb_node
*pos
;
1185 spin_lock(&clp
->cl_lock
);
1186 for (pos
= rb_first(&clp
->cl_state_owners
); pos
!= NULL
; pos
= rb_next(pos
)) {
1187 struct nfs4_state_owner
*sp
= rb_entry(pos
, struct nfs4_state_owner
, so_client_node
);
1188 if (!test_and_clear_bit(ops
->owner_flag_bit
, &sp
->so_flags
))
1190 atomic_inc(&sp
->so_count
);
1191 spin_unlock(&clp
->cl_lock
);
1192 status
= nfs4_reclaim_open_state(sp
, ops
);
1194 set_bit(ops
->owner_flag_bit
, &sp
->so_flags
);
1195 nfs4_put_state_owner(sp
);
1196 return nfs4_recovery_handle_error(clp
, status
);
1198 nfs4_put_state_owner(sp
);
1201 spin_unlock(&clp
->cl_lock
);
1205 static int nfs4_check_lease(struct nfs_client
*clp
)
1207 struct rpc_cred
*cred
;
1208 struct nfs4_state_maintenance_ops
*ops
=
1209 nfs4_state_renewal_ops
[clp
->cl_minorversion
];
1210 int status
= -NFS4ERR_EXPIRED
;
1212 /* Is the client already known to have an expired lease? */
1213 if (test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
1215 spin_lock(&clp
->cl_lock
);
1216 cred
= ops
->get_state_renewal_cred_locked(clp
);
1217 spin_unlock(&clp
->cl_lock
);
1219 cred
= nfs4_get_setclientid_cred(clp
);
1223 status
= ops
->renew_lease(clp
, cred
);
1226 return nfs4_recovery_handle_error(clp
, status
);
1229 static int nfs4_reclaim_lease(struct nfs_client
*clp
)
1231 struct rpc_cred
*cred
;
1232 struct nfs4_state_recovery_ops
*ops
=
1233 nfs4_reboot_recovery_ops
[clp
->cl_minorversion
];
1234 int status
= -ENOENT
;
1236 cred
= ops
->get_clid_cred(clp
);
1238 status
= ops
->establish_clid(clp
, cred
);
1240 /* Handle case where the user hasn't set up machine creds */
1241 if (status
== -EACCES
&& cred
== clp
->cl_machine_cred
) {
1242 nfs4_clear_machine_cred(clp
);
1245 if (status
== -NFS4ERR_MINOR_VERS_MISMATCH
)
1246 status
= -EPROTONOSUPPORT
;
1251 #ifdef CONFIG_NFS_V4_1
1252 void nfs41_handle_recall_slot(struct nfs_client
*clp
)
1254 set_bit(NFS4CLNT_RECALL_SLOT
, &clp
->cl_state
);
1255 nfs4_schedule_state_recovery(clp
);
1258 void nfs41_handle_sequence_flag_errors(struct nfs_client
*clp
, u32 flags
)
1262 else if (flags
& SEQ4_STATUS_RESTART_RECLAIM_NEEDED
) {
1263 set_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
1264 nfs4_state_start_reclaim_reboot(clp
);
1265 nfs4_schedule_state_recovery(clp
);
1266 } else if (flags
& (SEQ4_STATUS_EXPIRED_ALL_STATE_REVOKED
|
1267 SEQ4_STATUS_EXPIRED_SOME_STATE_REVOKED
|
1268 SEQ4_STATUS_ADMIN_STATE_REVOKED
|
1269 SEQ4_STATUS_RECALLABLE_STATE_REVOKED
|
1270 SEQ4_STATUS_LEASE_MOVED
)) {
1271 set_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
1272 nfs4_state_start_reclaim_nograce(clp
);
1273 nfs4_schedule_state_recovery(clp
);
1274 } else if (flags
& (SEQ4_STATUS_CB_PATH_DOWN
|
1275 SEQ4_STATUS_BACKCHANNEL_FAULT
|
1276 SEQ4_STATUS_CB_PATH_DOWN_SESSION
))
1277 nfs_expire_all_delegations(clp
);
1280 static int nfs4_reset_session(struct nfs_client
*clp
)
1284 nfs4_begin_drain_session(clp
);
1285 status
= nfs4_proc_destroy_session(clp
->cl_session
);
1286 if (status
&& status
!= -NFS4ERR_BADSESSION
&&
1287 status
!= -NFS4ERR_DEADSESSION
) {
1288 status
= nfs4_recovery_handle_error(clp
, status
);
1292 memset(clp
->cl_session
->sess_id
.data
, 0, NFS4_MAX_SESSIONID_LEN
);
1293 status
= nfs4_proc_create_session(clp
);
1295 status
= nfs4_recovery_handle_error(clp
, status
);
1298 /* create_session negotiated new slot table */
1299 clear_bit(NFS4CLNT_RECALL_SLOT
, &clp
->cl_state
);
1301 /* Let the state manager reestablish state */
1302 if (!test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
1303 nfs41_setup_state_renewal(clp
);
1308 static int nfs4_recall_slot(struct nfs_client
*clp
)
1310 struct nfs4_slot_table
*fc_tbl
= &clp
->cl_session
->fc_slot_table
;
1311 struct nfs4_channel_attrs
*fc_attrs
= &clp
->cl_session
->fc_attrs
;
1312 struct nfs4_slot
*new, *old
;
1315 nfs4_begin_drain_session(clp
);
1316 new = kmalloc(fc_tbl
->target_max_slots
* sizeof(struct nfs4_slot
),
1321 spin_lock(&fc_tbl
->slot_tbl_lock
);
1322 for (i
= 0; i
< fc_tbl
->target_max_slots
; i
++)
1323 new[i
].seq_nr
= fc_tbl
->slots
[i
].seq_nr
;
1324 old
= fc_tbl
->slots
;
1325 fc_tbl
->slots
= new;
1326 fc_tbl
->max_slots
= fc_tbl
->target_max_slots
;
1327 fc_tbl
->target_max_slots
= 0;
1328 fc_attrs
->max_reqs
= fc_tbl
->max_slots
;
1329 spin_unlock(&fc_tbl
->slot_tbl_lock
);
1332 nfs4_end_drain_session(clp
);
1336 #else /* CONFIG_NFS_V4_1 */
1337 static int nfs4_reset_session(struct nfs_client
*clp
) { return 0; }
1338 static int nfs4_end_drain_session(struct nfs_client
*clp
) { return 0; }
1339 static int nfs4_recall_slot(struct nfs_client
*clp
) { return 0; }
1340 #endif /* CONFIG_NFS_V4_1 */
1342 /* Set NFS4CLNT_LEASE_EXPIRED for all v4.0 errors and for recoverable errors
1343 * on EXCHANGE_ID for v4.1
1345 static void nfs4_set_lease_expired(struct nfs_client
*clp
, int status
)
1347 if (nfs4_has_session(clp
)) {
1349 case -NFS4ERR_DELAY
:
1350 case -NFS4ERR_CLID_INUSE
:
1355 case -NFS4ERR_NOT_SAME
: /* FixMe: implement recovery
1356 * in nfs4_exchange_id */
1361 set_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
);
1364 static void nfs4_state_manager(struct nfs_client
*clp
)
1368 /* Ensure exclusive access to NFSv4 state */
1370 if (test_and_clear_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
)) {
1371 /* We're going to have to re-establish a clientid */
1372 status
= nfs4_reclaim_lease(clp
);
1374 nfs4_set_lease_expired(clp
, status
);
1375 if (test_bit(NFS4CLNT_LEASE_EXPIRED
,
1378 if (clp
->cl_cons_state
==
1379 NFS_CS_SESSION_INITING
)
1380 nfs_mark_client_ready(clp
, status
);
1383 clear_bit(NFS4CLNT_CHECK_LEASE
, &clp
->cl_state
);
1384 set_bit(NFS4CLNT_RECLAIM_REBOOT
, &clp
->cl_state
);
1387 if (test_and_clear_bit(NFS4CLNT_CHECK_LEASE
, &clp
->cl_state
)) {
1388 status
= nfs4_check_lease(clp
);
1389 if (test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
1391 if (status
< 0 && status
!= -NFS4ERR_CB_PATH_DOWN
)
1395 /* Initialize or reset the session */
1396 if (test_and_clear_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
)
1397 && nfs4_has_session(clp
)) {
1398 status
= nfs4_reset_session(clp
);
1399 if (test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
))
1405 /* First recover reboot state... */
1406 if (test_bit(NFS4CLNT_RECLAIM_REBOOT
, &clp
->cl_state
)) {
1407 status
= nfs4_do_reclaim(clp
,
1408 nfs4_reboot_recovery_ops
[clp
->cl_minorversion
]);
1409 if (test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) ||
1410 test_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
))
1412 nfs4_state_end_reclaim_reboot(clp
);
1413 if (test_bit(NFS4CLNT_RECLAIM_NOGRACE
, &clp
->cl_state
))
1419 /* Now recover expired state... */
1420 if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE
, &clp
->cl_state
)) {
1421 status
= nfs4_do_reclaim(clp
,
1422 nfs4_nograce_recovery_ops
[clp
->cl_minorversion
]);
1423 if (test_bit(NFS4CLNT_LEASE_EXPIRED
, &clp
->cl_state
) ||
1424 test_bit(NFS4CLNT_SESSION_RESET
, &clp
->cl_state
) ||
1425 test_bit(NFS4CLNT_RECLAIM_REBOOT
, &clp
->cl_state
))
1431 nfs4_end_drain_session(clp
);
1432 if (test_and_clear_bit(NFS4CLNT_DELEGRETURN
, &clp
->cl_state
)) {
1433 nfs_client_return_marked_delegations(clp
);
1436 /* Recall session slots */
1437 if (test_and_clear_bit(NFS4CLNT_RECALL_SLOT
, &clp
->cl_state
)
1438 && nfs4_has_session(clp
)) {
1439 status
= nfs4_recall_slot(clp
);
1446 nfs4_clear_state_manager_bit(clp
);
1447 /* Did we race with an attempt to give us more work? */
1448 if (clp
->cl_state
== 0)
1450 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING
, &clp
->cl_state
) != 0)
1455 printk(KERN_WARNING
"Error: state manager failed on NFSv4 server %s"
1456 " with error %d\n", clp
->cl_hostname
, -status
);
1457 nfs4_end_drain_session(clp
);
1458 nfs4_clear_state_manager_bit(clp
);
1461 static int nfs4_run_state_manager(void *ptr
)
1463 struct nfs_client
*clp
= ptr
;
1465 allow_signal(SIGKILL
);
1466 nfs4_state_manager(clp
);
1467 nfs_put_client(clp
);
1468 module_put_and_exit(0);