41 #include <linux/kernel.h>
42 #include <linux/slab.h>
44 #include <linux/nfs_fs.h>
45 #include <linux/nfs_idmap.h>
47 #include <linux/module.h>
48 #include <linux/random.h>
51 #include <linux/bitops.h>
63 #define NFSDBG_FACILITY NFSDBG_STATE
65 #define OPENOWNER_POOL_SIZE 8
73 struct nfs4_setclientid_res clid = {
74 .clientid = clp->cl_clientid,
75 .confirm = clp->cl_confirm,
81 if (
test_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state))
83 port = nn->nfs_callback_tcpport;
85 port = nn->nfs_callback_tcpport6;
90 clp->cl_clientid = clid.clientid;
91 clp->cl_confirm = clid.confirm;
92 set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
97 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
118 struct rpc_cred *
cred)
120 struct nfs4_setclientid_res clid = {
121 .clientid = clp->cl_clientid,
122 .confirm = clp->cl_confirm,
128 port = nn->nfs_callback_tcpport;
130 port = nn->nfs_callback_tcpport6;
135 clp->cl_clientid = clid.clientid;
136 clp->cl_confirm = clid.confirm;
141 set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
162 static void nfs4_clear_machine_cred(
struct nfs_client *clp)
164 struct rpc_cred *
cred;
166 spin_lock(&clp->cl_lock);
169 spin_unlock(&clp->cl_lock);
174 static struct rpc_cred *
175 nfs4_get_renew_cred_server_locked(
struct nfs_server *server)
177 struct rpc_cred *cred =
NULL;
178 struct nfs4_state_owner *
sp;
181 for (pos =
rb_first(&server->state_owners);
184 sp =
rb_entry(pos,
struct nfs4_state_owner, so_server_node);
185 if (list_empty(&sp->so_states))
187 cred = get_rpccred(sp->so_cred);
202 struct rpc_cred *cred =
NULL;
212 cred = nfs4_get_renew_cred_server_locked(server);
222 #if defined(CONFIG_NFS_V4_1)
224 static int nfs41_setup_state_renewal(
struct nfs_client *clp)
234 status = nfs4_proc_get_lease_time(clp, &fsinfo);
237 spin_lock(&clp->cl_lock);
238 clp->cl_lease_time = fsinfo.lease_time *
HZ;
239 clp->cl_last_renewal =
jiffies;
240 spin_unlock(&clp->cl_lock);
253 static void nfs4_end_drain_session(
struct nfs_client *clp)
255 struct nfs4_session *ses = clp->cl_session;
256 struct nfs4_slot_table *tbl;
261 tbl = &ses->fc_slot_table;
263 spin_lock(&tbl->slot_tbl_lock);
264 max_slots = tbl->max_slots;
265 while (max_slots--) {
267 nfs4_set_task_privileged,
271 spin_unlock(&tbl->slot_tbl_lock);
275 static int nfs4_wait_on_slot_tbl(
struct nfs4_slot_table *tbl)
277 spin_lock(&tbl->slot_tbl_lock);
280 spin_unlock(&tbl->slot_tbl_lock);
283 spin_unlock(&tbl->slot_tbl_lock);
287 static int nfs4_begin_drain_session(
struct nfs_client *clp)
289 struct nfs4_session *ses = clp->cl_session;
292 set_bit(NFS4_SESSION_DRAINING, &ses->session_state);
294 ret = nfs4_wait_on_slot_tbl(&ses->bc_slot_table);
298 return nfs4_wait_on_slot_tbl(&ses->fc_slot_table);
301 static void nfs41_finish_session_reset(
struct nfs_client *clp)
303 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
304 clear_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
306 clear_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
307 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
308 nfs41_setup_state_renewal(clp);
311 int nfs41_init_clientid(
struct nfs_client *clp,
struct rpc_cred *cred)
315 if (
test_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state))
317 nfs4_begin_drain_session(clp);
318 status = nfs4_proc_exchange_id(clp, cred);
321 set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
323 status = nfs4_proc_create_session(clp, cred);
326 nfs41_finish_session_reset(clp);
345 int nfs41_discover_server_trunking(
struct nfs_client *clp,
347 struct rpc_cred *cred)
351 status = nfs4_proc_exchange_id(clp, cred);
354 set_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
359 struct rpc_cred *nfs4_get_exchange_id_cred(
struct nfs_client *clp)
361 struct rpc_cred *cred;
363 spin_lock(&clp->cl_lock);
365 spin_unlock(&clp->cl_lock);
371 static struct rpc_cred *
372 nfs4_get_setclientid_cred_server(
struct nfs_server *server)
375 struct rpc_cred *cred =
NULL;
376 struct nfs4_state_owner *
sp;
379 spin_lock(&clp->cl_lock);
380 pos =
rb_first(&server->state_owners);
382 sp =
rb_entry(pos,
struct nfs4_state_owner, so_server_node);
383 cred = get_rpccred(sp->so_cred);
385 spin_unlock(&clp->cl_lock);
398 struct rpc_cred *cred;
400 spin_lock(&clp->cl_lock);
402 spin_unlock(&clp->cl_lock);
407 list_for_each_entry_rcu(server, &clp->
cl_superblocks, client_link) {
408 cred = nfs4_get_setclientid_cred_server(server);
418 static struct nfs4_state_owner *
419 nfs4_find_state_owner_locked(
struct nfs_server *server,
struct rpc_cred *cred)
421 struct rb_node **
p = &server->state_owners.rb_node,
423 struct nfs4_state_owner *
sp;
427 sp =
rb_entry(parent,
struct nfs4_state_owner, so_server_node);
431 else if (cred > sp->so_cred)
434 if (!list_empty(&sp->so_lru))
435 list_del_init(&sp->so_lru);
443 static struct nfs4_state_owner *
444 nfs4_insert_state_owner_locked(
struct nfs4_state_owner *
new)
447 struct rb_node **p = &server->state_owners.rb_node,
449 struct nfs4_state_owner *
sp;
454 sp =
rb_entry(parent,
struct nfs4_state_owner, so_server_node);
456 if (new->so_cred < sp->so_cred)
458 else if (new->so_cred > sp->so_cred)
461 if (!list_empty(&sp->so_lru))
462 list_del_init(&sp->so_lru);
470 rb_link_node(&new->so_server_node, parent, p);
476 nfs4_remove_state_owner_locked(
struct nfs4_state_owner *sp)
481 rb_erase(&sp->so_server_node, &server->state_owners);
486 nfs4_init_seqid_counter(
struct nfs_seqid_counter *
sc)
492 INIT_LIST_HEAD(&sc->list);
497 nfs4_destroy_seqid_counter(
struct nfs_seqid_counter *
sc)
507 static struct nfs4_state_owner *
508 nfs4_alloc_state_owner(
struct nfs_server *server,
509 struct rpc_cred *cred,
512 struct nfs4_state_owner *
sp;
514 sp = kzalloc(
sizeof(*sp), gfp_flags);
517 sp->so_server = server;
518 sp->so_cred = get_rpccred(cred);
520 INIT_LIST_HEAD(&sp->so_states);
521 nfs4_init_seqid_counter(&sp->so_seqid);
523 INIT_LIST_HEAD(&sp->so_lru);
528 nfs4_drop_state_owner(
struct nfs4_state_owner *sp)
536 spin_lock(&clp->cl_lock);
538 rb_erase(rb_node, &server->state_owners);
541 spin_unlock(&clp->cl_lock);
545 static void nfs4_free_state_owner(
struct nfs4_state_owner *sp)
547 nfs4_destroy_seqid_counter(&sp->so_seqid);
552 static void nfs4_gc_state_owners(
struct nfs_server *server)
555 struct nfs4_state_owner *
sp, *
tmp;
556 unsigned long time_min, time_max;
559 spin_lock(&clp->cl_lock);
561 time_min = (
long)time_max - (
long)clp->cl_lease_time;
566 list_move(&sp->so_lru, &doomed);
567 nfs4_remove_state_owner_locked(sp);
569 spin_unlock(&clp->cl_lock);
573 nfs4_free_state_owner(sp);
585 struct rpc_cred *cred,
589 struct nfs4_state_owner *
sp, *
new;
591 spin_lock(&clp->cl_lock);
592 sp = nfs4_find_state_owner_locked(server, cred);
593 spin_unlock(&clp->cl_lock);
596 new = nfs4_alloc_state_owner(server, cred, gfp_flags);
602 spin_lock(&clp->cl_lock);
603 sp = nfs4_insert_state_owner_locked(
new);
604 spin_unlock(&clp->cl_lock);
605 }
while (sp == ERR_PTR(-
EAGAIN));
607 nfs4_free_state_owner(
new);
609 nfs4_gc_state_owners(server);
635 spin_unlock(&clp->cl_lock);
648 struct nfs4_state_owner *
sp, *
tmp;
651 spin_lock(&clp->cl_lock);
653 list_move(&sp->so_lru, &doomed);
654 nfs4_remove_state_owner_locked(sp);
656 spin_unlock(&clp->cl_lock);
660 nfs4_free_state_owner(sp);
664 static struct nfs4_state *
665 nfs4_alloc_open_state(
void)
667 struct nfs4_state *
state;
669 state = kzalloc(
sizeof(*state),
GFP_NOFS);
673 INIT_LIST_HEAD(&state->lock_states);
682 if (state->state == fmode)
685 if ((fmode &
FMODE_WRITE) != (state->state & FMODE_WRITE)) {
686 if (fmode & FMODE_WRITE)
687 list_move(&state->open_states, &state->owner->so_states);
689 list_move_tail(&state->open_states, &state->owner->so_states);
691 state->state = fmode;
694 static struct nfs4_state *
695 __nfs4_find_state_byowner(
struct inode *
inode,
struct nfs4_state_owner *
owner)
698 struct nfs4_state *
state;
701 if (state->owner != owner)
710 nfs4_free_open_state(
struct nfs4_state *state)
718 struct nfs4_state *
state, *
new;
721 spin_lock(&inode->
i_lock);
722 state = __nfs4_find_state_byowner(inode, owner);
723 spin_unlock(&inode->
i_lock);
726 new = nfs4_alloc_open_state();
727 spin_lock(&owner->so_lock);
728 spin_lock(&inode->
i_lock);
729 state = __nfs4_find_state_byowner(inode, owner);
732 state->owner =
owner;
734 list_add(&state->inode_states, &nfsi->open_states);
736 state->inode =
inode;
737 spin_unlock(&inode->
i_lock);
741 spin_unlock(&owner->so_lock);
743 spin_unlock(&inode->
i_lock);
744 spin_unlock(&owner->so_lock);
746 nfs4_free_open_state(
new);
754 struct inode *inode = state->inode;
755 struct nfs4_state_owner *owner = state->owner;
759 spin_lock(&inode->
i_lock);
762 spin_unlock(&inode->
i_lock);
763 spin_unlock(&owner->so_lock);
765 nfs4_free_open_state(state);
772 static void __nfs4_close(
struct nfs4_state *state,
775 struct nfs4_state_owner *owner = state->owner;
781 spin_lock(&owner->so_lock);
793 if (state->n_rdwr == 0) {
794 if (state->n_rdonly == 0) {
796 call_close |=
test_bit(NFS_O_RDONLY_STATE, &state->flags);
797 call_close |=
test_bit(NFS_O_RDWR_STATE, &state->flags);
799 if (state->n_wronly == 0) {
801 call_close |=
test_bit(NFS_O_WRONLY_STATE, &state->flags);
802 call_close |=
test_bit(NFS_O_RDWR_STATE, &state->flags);
805 clear_bit(NFS_DELEGATED_STATE, &state->flags);
808 spin_unlock(&owner->so_lock);
819 __nfs4_close(state, fmode,
GFP_NOFS, 0);
832 __nfs4_find_lock_state(
struct nfs4_state *state,
fl_owner_t fl_owner,
pid_t fl_pid,
unsigned int type)
836 if (type != NFS4_ANY_LOCK_TYPE && pos->ls_owner.lo_type != type)
838 switch (pos->ls_owner.lo_type) {
839 case NFS4_POSIX_LOCK_TYPE:
840 if (pos->ls_owner.lo_u.posix_owner != fl_owner)
843 case NFS4_FLOCK_LOCK_TYPE:
844 if (pos->ls_owner.lo_u.flock_owner != fl_pid)
861 struct nfs_server *server = state->owner->so_server;
863 lsp = kzalloc(
sizeof(*lsp),
GFP_NOFS);
866 nfs4_init_seqid_counter(&lsp->ls_seqid);
868 lsp->ls_state =
state;
869 lsp->ls_owner.lo_type =
type;
870 switch (lsp->ls_owner.lo_type) {
871 case NFS4_FLOCK_LOCK_TYPE:
872 lsp->ls_owner.lo_u.flock_owner = fl_pid;
874 case NFS4_POSIX_LOCK_TYPE:
875 lsp->ls_owner.lo_u.posix_owner = fl_owner;
881 if (lsp->ls_seqid.owner_id < 0)
883 INIT_LIST_HEAD(&lsp->ls_locks);
893 nfs4_destroy_seqid_counter(&lsp->ls_seqid);
907 spin_lock(&state->state_lock);
908 lsp = __nfs4_find_lock_state(state, owner, pid, type);
912 list_add(&new->ls_locks, &state->lock_states);
913 set_bit(LK_STATE_IN_USE, &state->flags);
918 spin_unlock(&state->state_lock);
919 new = nfs4_alloc_lock_state(state, owner, pid, type);
923 spin_unlock(&state->state_lock);
935 struct nfs4_state *
state;
939 state = lsp->ls_state;
943 if (list_empty(&state->lock_states))
944 clear_bit(LK_STATE_IN_USE, &state->flags);
945 spin_unlock(&state->state_lock);
946 if (
test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) {
961 static void nfs4_fl_release_lock(
struct file_lock *
fl)
967 .fl_copy_lock = nfs4_fl_copy_lock,
968 .fl_release_private = nfs4_fl_release_lock,
978 lsp = nfs4_get_lock_state(state, fl->
fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
980 lsp = nfs4_get_lock_state(state,
NULL, fl->
fl_pid,
981 NFS4_FLOCK_LOCK_TYPE);
987 fl->
fl_ops = &nfs4_fl_lock_ops;
991 static bool nfs4_copy_lock_stateid(
nfs4_stateid *
dst,
struct nfs4_state *state,
1000 if (lockowner ==
NULL)
1003 if (
test_bit(LK_STATE_IN_USE, &state->flags) == 0)
1006 fl_owner = lockowner->
l_owner;
1007 fl_pid = lockowner->
l_pid;
1008 spin_lock(&state->state_lock);
1009 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
1010 if (lsp !=
NULL &&
test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags) != 0) {
1011 nfs4_stateid_copy(dst, &lsp->ls_stateid);
1014 spin_unlock(&state->state_lock);
1020 static void nfs4_copy_open_stateid(
nfs4_stateid *dst,
struct nfs4_state *state)
1025 seq = read_seqbegin(&state->seqlock);
1026 nfs4_stateid_copy(dst, &state->stateid);
1027 }
while (read_seqretry(&state->seqlock, seq));
1039 if (nfs4_copy_lock_stateid(dst, state, lockowner))
1041 nfs4_copy_open_stateid(dst, state);
1046 struct nfs_seqid *
new;
1048 new =
kmalloc(
sizeof(*
new), gfp_mask);
1051 INIT_LIST_HEAD(&new->list);
1059 struct nfs_seqid_counter *
sequence;
1061 if (list_empty(&seqid->list))
1063 sequence = seqid->sequence;
1064 spin_lock(&sequence->lock);
1065 list_del_init(&seqid->list);
1066 if (!list_empty(&sequence->list)) {
1067 struct nfs_seqid *
next;
1070 struct nfs_seqid,
list);
1073 spin_unlock(&sequence->lock);
1087 static void nfs_increment_seqid(
int status,
struct nfs_seqid *
seqid)
1094 if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
1097 " sequence-id error on an"
1098 " unconfirmed sequence %p!\n",
1113 seqid->sequence->counter++;
1118 struct nfs4_state_owner *sp =
container_of(seqid->sequence,
1119 struct nfs4_state_owner, so_seqid);
1123 nfs4_drop_state_owner(sp);
1125 nfs_increment_seqid(status, seqid);
1135 nfs_increment_seqid(status, seqid);
1140 struct nfs_seqid_counter *
sequence = seqid->sequence;
1143 spin_lock(&sequence->lock);
1145 if (list_empty(&seqid->list))
1152 spin_unlock(&sequence->lock);
1156 static int nfs4_run_state_manager(
void *);
1158 static void nfs4_clear_state_manager_bit(
struct nfs_client *clp)
1161 clear_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state);
1163 wake_up_bit(&clp->cl_state, NFS4CLNT_MANAGER_RUNNING);
1190 __func__, PTR_ERR(task));
1191 nfs4_clear_state_manager_bit(clp);
1204 if (!
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1205 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1206 dprintk(
"%s: scheduling lease recovery for server %s\n", __func__,
1220 static void nfs40_handle_cb_pathdown(
struct nfs_client *clp)
1222 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1224 dprintk(
"%s: handling CB_PATHDOWN recovery for server %s\n", __func__,
1230 nfs40_handle_cb_pathdown(clp);
1234 static int nfs4_state_mark_reclaim_reboot(
struct nfs_client *clp,
struct nfs4_state *state)
1237 set_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1239 if (
test_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags)) {
1240 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1243 set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
1244 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
1248 static int nfs4_state_mark_reclaim_nograce(
struct nfs_client *clp,
struct nfs4_state *state)
1250 set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1251 clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
1252 set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
1253 set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
1261 nfs4_state_mark_reclaim_nograce(clp, state);
1262 dprintk(
"%s: scheduling stateid recovery for server %s\n", __func__,
1271 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1274 struct nfs4_state *
state;
1277 spin_lock(&inode->
i_lock);
1282 if (!
test_bit(NFS_DELEGATED_STATE, &state->flags))
1284 if (!nfs4_stateid_match(&state->stateid, stateid))
1286 nfs4_state_mark_reclaim_nograce(clp, state);
1289 spin_unlock(&inode->
i_lock);
1295 static int nfs4_reclaim_locks(
struct nfs4_state *state,
const struct nfs4_state_recovery_ops *ops)
1297 struct inode *inode = state->inode;
1312 if (nfs_file_open_context(fl->
fl_file)->state != state)
1315 status = ops->recover_lock(state, fl);
1333 "Zeroing state\n", __func__, status);
1349 static int nfs4_reclaim_open_state(
struct nfs4_state_owner *sp,
const struct nfs4_state_recovery_ops *ops)
1351 struct nfs4_state *
state;
1364 spin_lock(&sp->so_lock);
1368 if (state->state == 0)
1371 spin_unlock(&sp->so_lock);
1372 status = ops->recover_open(sp, state);
1374 status = nfs4_reclaim_locks(state, ops);
1376 spin_lock(&state->state_lock);
1378 if (!
test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1381 "failed!\n", __func__);
1383 spin_unlock(&state->state_lock);
1391 "Zeroing state\n", __func__, status);
1399 memset(&state->stateid, 0,
1400 sizeof(state->stateid));
1417 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1421 nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
1432 spin_unlock(&sp->so_lock);
1439 static void nfs4_clear_open_state(
struct nfs4_state *state)
1443 clear_bit(NFS_DELEGATED_STATE, &state->flags);
1444 clear_bit(NFS_O_RDONLY_STATE, &state->flags);
1445 clear_bit(NFS_O_WRONLY_STATE, &state->flags);
1446 clear_bit(NFS_O_RDWR_STATE, &state->flags);
1447 spin_lock(&state->state_lock);
1449 lock->ls_seqid.flags = 0;
1450 clear_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags);
1452 spin_unlock(&state->state_lock);
1455 static void nfs4_reset_seqids(
struct nfs_server *server,
1456 int (*mark_reclaim)(
struct nfs_client *clp,
struct nfs4_state *state))
1459 struct nfs4_state_owner *
sp;
1460 struct rb_node *
pos;
1461 struct nfs4_state *
state;
1463 spin_lock(&clp->cl_lock);
1464 for (pos =
rb_first(&server->state_owners);
1467 sp =
rb_entry(pos,
struct nfs4_state_owner, so_server_node);
1468 sp->so_seqid.flags = 0;
1469 spin_lock(&sp->so_lock);
1471 if (mark_reclaim(clp, state))
1472 nfs4_clear_open_state(state);
1474 spin_unlock(&sp->so_lock);
1476 spin_unlock(&clp->cl_lock);
1479 static void nfs4_state_mark_reclaim_helper(
struct nfs_client *clp,
1480 int (*mark_reclaim)(
struct nfs_client *clp,
struct nfs4_state *state))
1486 nfs4_reset_seqids(server, mark_reclaim);
1494 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_reboot);
1497 static void nfs4_reclaim_complete(
struct nfs_client *clp,
1498 const struct nfs4_state_recovery_ops *ops)
1501 if (ops->reclaim_complete)
1502 (
void)ops->reclaim_complete(clp);
1505 static void nfs4_clear_reclaim_server(
struct nfs_server *server)
1508 struct nfs4_state_owner *
sp;
1509 struct rb_node *
pos;
1510 struct nfs4_state *
state;
1512 spin_lock(&clp->cl_lock);
1513 for (pos =
rb_first(&server->state_owners);
1516 sp =
rb_entry(pos,
struct nfs4_state_owner, so_server_node);
1517 spin_lock(&sp->so_lock);
1522 nfs4_state_mark_reclaim_nograce(clp, state);
1524 spin_unlock(&sp->so_lock);
1526 spin_unlock(&clp->cl_lock);
1529 static int nfs4_state_clear_reclaim_reboot(
struct nfs_client *clp)
1538 nfs4_clear_reclaim_server(server);
1547 if (!nfs4_state_clear_reclaim_reboot(clp))
1549 nfs4_reclaim_complete(clp, clp->cl_mvops->reboot_recovery_ops);
1552 static void nfs_delegation_clear_all(
struct nfs_client *clp)
1558 static void nfs4_state_start_reclaim_nograce(
struct nfs_client *clp)
1560 nfs_delegation_clear_all(clp);
1561 nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
1564 static void nfs4_warn_keyexpired(
const char *
s)
1567 " encountered RPCSEC_GSS session"
1568 " expired against NFSv4 server %s.\n",
1572 static int nfs4_recovery_handle_error(
struct nfs_client *clp,
int error)
1578 nfs40_handle_cb_pathdown(clp);
1581 nfs4_state_end_reclaim_reboot(clp);
1585 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1586 nfs4_state_clear_reclaim_reboot(clp);
1587 nfs4_state_start_reclaim_reboot(clp);
1590 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1591 nfs4_state_start_reclaim_nograce(clp);
1599 set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1603 set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
1610 dprintk(
"%s: failed to handle error %d for server %s\n",
1614 dprintk(
"%s: handled error %d for server %s\n", __func__, error,
1619 static int nfs4_do_reclaim(
struct nfs_client *clp,
const struct nfs4_state_recovery_ops *ops)
1621 struct nfs4_state_owner *
sp;
1623 struct rb_node *
pos;
1628 list_for_each_entry_rcu(server, &clp->
cl_superblocks, client_link) {
1630 spin_lock(&clp->cl_lock);
1631 for (pos =
rb_first(&server->state_owners);
1635 struct nfs4_state_owner, so_server_node);
1640 spin_unlock(&clp->cl_lock);
1643 status = nfs4_reclaim_open_state(sp, ops);
1645 set_bit(ops->owner_flag_bit, &sp->so_flags);
1647 return nfs4_recovery_handle_error(clp, status);
1653 spin_unlock(&clp->cl_lock);
1659 static int nfs4_check_lease(
struct nfs_client *clp)
1661 struct rpc_cred *cred;
1662 const struct nfs4_state_maintenance_ops *ops =
1663 clp->cl_mvops->state_renewal_ops;
1667 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
1669 spin_lock(&clp->cl_lock);
1670 cred = ops->get_state_renewal_cred_locked(clp);
1671 spin_unlock(&clp->cl_lock);
1678 status = ops->renew_lease(clp, cred);
1681 return nfs4_recovery_handle_error(clp, status);
1687 static int nfs4_handle_reclaim_lease_error(
struct nfs_client *clp,
int status)
1695 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
1698 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
1699 nfs4_state_clear_reclaim_reboot(clp);
1700 nfs4_state_start_reclaim_reboot(clp);
1703 pr_err(
"NFS: Server %s reports our clientid is in use\n",
1706 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
1712 nfs4_clear_machine_cred(clp);
1722 dprintk(
"%s: exit with error %d for server %s\n",
1730 dprintk(
"%s: exit with error %d for server %s\n", __func__,
1734 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1735 dprintk(
"%s: handled error %d for server %s\n", __func__, status,
1740 static int nfs4_establish_lease(
struct nfs_client *clp)
1742 struct rpc_cred *cred;
1743 const struct nfs4_state_recovery_ops *ops =
1744 clp->cl_mvops->reboot_recovery_ops;
1747 cred = ops->get_clid_cred(clp);
1750 status = ops->establish_clid(clp, cred);
1762 static int nfs4_reclaim_lease(
struct nfs_client *clp)
1766 status = nfs4_establish_lease(clp);
1768 return nfs4_handle_reclaim_lease_error(clp, status);
1770 nfs4_state_start_reclaim_nograce(clp);
1771 if (!
test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
1772 set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
1773 clear_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1774 clear_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1778 static int nfs4_purge_lease(
struct nfs_client *clp)
1782 status = nfs4_establish_lease(clp);
1784 return nfs4_handle_reclaim_lease_error(clp, status);
1785 clear_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state);
1786 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1787 nfs4_state_start_reclaim_nograce(clp);
1807 const struct nfs4_state_recovery_ops *ops =
1808 clp->cl_mvops->reboot_recovery_ops;
1809 rpc_authflavor_t *flavors, flav, save;
1811 struct rpc_cred *cred;
1817 flavors = kcalloc(len,
sizeof(*flavors),
GFP_KERNEL);
1818 if (flavors ==
NULL) {
1828 save = clnt->
cl_auth->au_flavor;
1834 cred = ops->get_clid_cred(clp);
1838 status = ops->detect_trunking(clp, result, cred);
1848 nfs4_clear_machine_cred(clp);
1853 dprintk(
"NFS: %s after status %d, retrying\n",
1863 flav = flavors[i++];
1865 flav = flavors[i++];
1868 status = PTR_ERR(clnt);
1890 dprintk(
"NFS: %s: status = %d\n", __func__, status);
1894 #ifdef CONFIG_NFS_V4_1
1895 void nfs4_schedule_session_recovery(
struct nfs4_session *session,
int err)
1901 set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
1904 set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
1910 void nfs41_handle_recall_slot(
struct nfs_client *clp)
1912 set_bit(NFS4CLNT_RECALL_SLOT, &clp->cl_state);
1913 dprintk(
"%s: scheduling slot recall for server %s\n", __func__,
1918 static void nfs4_reset_all_state(
struct nfs_client *clp)
1921 set_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state);
1922 clear_bit(NFS4CLNT_LEASE_CONFIRM, &clp->cl_state);
1923 nfs4_state_start_reclaim_nograce(clp);
1924 dprintk(
"%s: scheduling reset of all state for server %s!\n",
1930 static void nfs41_handle_server_reboot(
struct nfs_client *clp)
1933 nfs4_state_start_reclaim_reboot(clp);
1934 dprintk(
"%s: server %s rebooted!\n", __func__,
1940 static void nfs41_handle_state_revoked(
struct nfs_client *clp)
1942 nfs4_reset_all_state(clp);
1946 static void nfs41_handle_recallable_state_revoked(
struct nfs_client *clp)
1950 dprintk(
"%s: Recallable state revoked on server %s!\n", __func__,
1954 static void nfs41_handle_backchannel_fault(
struct nfs_client *clp)
1959 dprintk(
"%s: server %s declared a backchannel fault\n", __func__,
1963 static void nfs41_handle_cb_path_down(
struct nfs_client *clp)
1966 &clp->cl_state) == 0)
1975 dprintk(
"%s: \"%s\" (client ID %llx) flags=0x%08x\n",
1976 __func__, clp->
cl_hostname, clp->cl_clientid, flags);
1979 nfs41_handle_server_reboot(clp);
1984 nfs41_handle_state_revoked(clp);
1986 nfs41_handle_recallable_state_revoked(clp);
1988 nfs41_handle_backchannel_fault(clp);
1991 nfs41_handle_cb_path_down(clp);
1994 static int nfs4_reset_session(
struct nfs_client *clp)
1996 struct rpc_cred *cred;
1999 if (!nfs4_has_session(clp))
2001 nfs4_begin_drain_session(clp);
2002 cred = nfs4_get_exchange_id_cred(clp);
2003 status = nfs4_proc_destroy_session(clp->cl_session, cred);
2006 status = nfs4_recovery_handle_error(clp, status);
2011 status = nfs4_proc_create_session(clp, cred);
2013 dprintk(
"%s: session reset failed with status %d for server %s!\n",
2015 status = nfs4_handle_reclaim_lease_error(clp, status);
2018 nfs41_finish_session_reset(clp);
2019 dprintk(
"%s: session reset was successful for server %s!\n",
2027 static int nfs4_recall_slot(
struct nfs_client *clp)
2029 struct nfs4_slot_table *fc_tbl;
2033 if (!nfs4_has_session(clp))
2035 nfs4_begin_drain_session(clp);
2036 fc_tbl = &clp->cl_session->fc_slot_table;
2042 spin_lock(&fc_tbl->slot_tbl_lock);
2043 for (i = 0; i < fc_tbl->target_max_slots; i++)
2044 new[i].
seq_nr = fc_tbl->slots[i].seq_nr;
2045 old = fc_tbl->slots;
2046 fc_tbl->slots =
new;
2047 fc_tbl->max_slots = fc_tbl->target_max_slots;
2048 fc_tbl->target_max_slots = 0;
2049 clp->cl_session->fc_attrs.max_reqs = fc_tbl->max_slots;
2050 spin_unlock(&fc_tbl->slot_tbl_lock);
2056 static int nfs4_bind_conn_to_session(
struct nfs_client *clp)
2058 struct rpc_cred *cred;
2061 if (!nfs4_has_session(clp))
2063 nfs4_begin_drain_session(clp);
2064 cred = nfs4_get_exchange_id_cred(clp);
2065 ret = nfs4_proc_bind_conn_to_session(clp, cred);
2068 clear_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
2071 dprintk(
"%s: bind_conn_to_session was successful for server %s!\n",
2076 set_bit(NFS4CLNT_BIND_CONN_TO_SESSION, &clp->cl_state);
2079 return nfs4_recovery_handle_error(clp, ret);
2084 static int nfs4_reset_session(
struct nfs_client *clp) {
return 0; }
2085 static int nfs4_end_drain_session(
struct nfs_client *clp) {
return 0; }
2086 static int nfs4_recall_slot(
struct nfs_client *clp) {
return 0; }
2088 static int nfs4_bind_conn_to_session(
struct nfs_client *clp)
2094 static void nfs4_state_manager(
struct nfs_client *clp)
2097 const char *
section =
"", *section_sep =
"";
2101 if (
test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
2102 section =
"purge state";
2103 status = nfs4_purge_lease(clp);
2109 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state)) {
2110 section =
"lease expired";
2112 status = nfs4_reclaim_lease(clp);
2119 section =
"check lease";
2120 status = nfs4_check_lease(clp);
2123 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
2129 section =
"reset session";
2130 status = nfs4_reset_session(clp);
2131 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state))
2140 section =
"bind conn to session";
2141 status = nfs4_bind_conn_to_session(clp);
2149 section =
"recall slot";
2150 status = nfs4_recall_slot(clp);
2157 if (
test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
2158 section =
"reclaim reboot";
2159 status = nfs4_do_reclaim(clp,
2160 clp->cl_mvops->reboot_recovery_ops);
2161 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
2162 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
2164 nfs4_state_end_reclaim_reboot(clp);
2165 if (
test_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state))
2173 section =
"reclaim nograce";
2174 status = nfs4_do_reclaim(clp,
2175 clp->cl_mvops->nograce_recovery_ops);
2176 if (
test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
2177 test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
2178 test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
2184 nfs4_end_drain_session(clp);
2190 nfs4_clear_state_manager_bit(clp);
2192 if (clp->cl_state == 0)
2202 " with error %d\n", section_sep, section,
2205 nfs4_end_drain_session(clp);
2206 nfs4_clear_state_manager_bit(clp);
2209 static int nfs4_run_state_manager(
void *
ptr)
2214 nfs4_state_manager(clp);