NFSv4: Clean up for the state loss reclaimer
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
@@ -811,7 +811,7 @@ void nfs4_schedule_state_recovery(struct nfs_client *clp)
|
|||||||
nfs4_recover_state(clp);
|
nfs4_recover_state(clp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nfs4_reclaim_locks(struct nfs4_state_recovery_ops *ops, struct nfs4_state *state)
|
static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
|
||||||
{
|
{
|
||||||
struct inode *inode = state->inode;
|
struct inode *inode = state->inode;
|
||||||
struct file_lock *fl;
|
struct file_lock *fl;
|
||||||
@@ -844,7 +844,7 @@ out_err:
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct nfs4_state_owner *sp)
|
static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
|
||||||
{
|
{
|
||||||
struct nfs4_state *state;
|
struct nfs4_state *state;
|
||||||
struct nfs4_lock_state *lock;
|
struct nfs4_lock_state *lock;
|
||||||
@@ -863,15 +863,15 @@ static int nfs4_reclaim_open_state(struct nfs4_state_recovery_ops *ops, struct n
|
|||||||
continue;
|
continue;
|
||||||
status = ops->recover_open(sp, state);
|
status = ops->recover_open(sp, state);
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
status = nfs4_reclaim_locks(ops, state);
|
status = nfs4_reclaim_locks(state, ops);
|
||||||
if (status < 0)
|
if (status >= 0) {
|
||||||
goto out_err;
|
list_for_each_entry(lock, &state->lock_states, ls_locks) {
|
||||||
list_for_each_entry(lock, &state->lock_states, ls_locks) {
|
if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
|
||||||
if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
|
printk("%s: Lock reclaim failed!\n",
|
||||||
printk("%s: Lock reclaim failed!\n",
|
|
||||||
__func__);
|
__func__);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
switch (status) {
|
switch (status) {
|
||||||
default:
|
default:
|
||||||
@@ -928,30 +928,71 @@ static void nfs4_state_mark_reclaim(struct nfs_client *clp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int reclaimer(void *ptr)
|
static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops)
|
||||||
{
|
{
|
||||||
struct nfs_client *clp = ptr;
|
|
||||||
struct nfs4_state_owner *sp;
|
|
||||||
struct rb_node *pos;
|
struct rb_node *pos;
|
||||||
struct nfs4_state_recovery_ops *ops;
|
|
||||||
struct rpc_cred *cred;
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
allow_signal(SIGKILL);
|
/* Note: list is protected by exclusive lock on cl->cl_sem */
|
||||||
|
for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
|
||||||
|
struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
|
||||||
|
status = nfs4_reclaim_open_state(sp, ops);
|
||||||
|
if (status < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nfs4_check_lease(struct nfs_client *clp)
|
||||||
|
{
|
||||||
|
struct rpc_cred *cred;
|
||||||
|
int status = -NFS4ERR_EXPIRED;
|
||||||
|
|
||||||
/* Ensure exclusive access to NFSv4 state */
|
|
||||||
down_write(&clp->cl_sem);
|
|
||||||
/* Are there any NFS mounts out there? */
|
|
||||||
if (list_empty(&clp->cl_superblocks))
|
|
||||||
goto out;
|
|
||||||
restart_loop:
|
|
||||||
ops = &nfs4_network_partition_recovery_ops;
|
|
||||||
/* Are there any open files on this volume? */
|
/* Are there any open files on this volume? */
|
||||||
cred = nfs4_get_renew_cred(clp);
|
cred = nfs4_get_renew_cred(clp);
|
||||||
if (cred != NULL) {
|
if (cred != NULL) {
|
||||||
/* Yes there are: try to renew the old lease */
|
/* Yes there are: try to renew the old lease */
|
||||||
status = nfs4_proc_renew(clp, cred);
|
status = nfs4_proc_renew(clp, cred);
|
||||||
put_rpccred(cred);
|
put_rpccred(cred);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "reboot" to ensure we clear all state on the server */
|
||||||
|
clp->cl_boot_time = CURRENT_TIME;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int nfs4_reclaim_lease(struct nfs_client *clp)
|
||||||
|
{
|
||||||
|
struct rpc_cred *cred;
|
||||||
|
int status = -ENOENT;
|
||||||
|
|
||||||
|
cred = nfs4_get_setclientid_cred(clp);
|
||||||
|
if (cred != NULL) {
|
||||||
|
status = nfs4_init_client(clp, cred);
|
||||||
|
put_rpccred(cred);
|
||||||
|
/* Handle case where the user hasn't set up machine creds */
|
||||||
|
if (status == -EACCES && cred == clp->cl_machine_cred) {
|
||||||
|
nfs4_clear_machine_cred(clp);
|
||||||
|
status = -EAGAIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int reclaimer(void *ptr)
|
||||||
|
{
|
||||||
|
struct nfs_client *clp = ptr;
|
||||||
|
const struct nfs4_state_recovery_ops *ops;
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
allow_signal(SIGKILL);
|
||||||
|
|
||||||
|
/* Ensure exclusive access to NFSv4 state */
|
||||||
|
down_write(&clp->cl_sem);
|
||||||
|
while (!list_empty(&clp->cl_superblocks)) {
|
||||||
|
ops = &nfs4_network_partition_recovery_ops;
|
||||||
|
status = nfs4_check_lease(clp);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 0:
|
case 0:
|
||||||
case -NFS4ERR_CB_PATH_DOWN:
|
case -NFS4ERR_CB_PATH_DOWN:
|
||||||
@@ -960,43 +1001,34 @@ restart_loop:
|
|||||||
case -NFS4ERR_LEASE_MOVED:
|
case -NFS4ERR_LEASE_MOVED:
|
||||||
ops = &nfs4_reboot_recovery_ops;
|
ops = &nfs4_reboot_recovery_ops;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* "reboot" to ensure we clear all state on the server */
|
/* We're going to have to re-establish a clientid */
|
||||||
clp->cl_boot_time = CURRENT_TIME;
|
nfs4_state_mark_reclaim(clp);
|
||||||
}
|
|
||||||
/* We're going to have to re-establish a clientid */
|
status = nfs4_reclaim_lease(clp);
|
||||||
nfs4_state_mark_reclaim(clp);
|
if (status) {
|
||||||
status = -ENOENT;
|
if (status == -EAGAIN)
|
||||||
cred = nfs4_get_setclientid_cred(clp);
|
continue;
|
||||||
if (cred != NULL) {
|
goto out_error;
|
||||||
status = nfs4_init_client(clp, cred);
|
|
||||||
put_rpccred(cred);
|
|
||||||
/* Handle case where the user hasn't set up machine creds */
|
|
||||||
if (status == -EACCES && cred == clp->cl_machine_cred) {
|
|
||||||
nfs4_clear_machine_cred(clp);
|
|
||||||
goto restart_loop;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (status)
|
/* Mark all delegations for reclaim */
|
||||||
goto out_error;
|
nfs_delegation_mark_reclaim(clp);
|
||||||
/* Mark all delegations for reclaim */
|
/* Note: list is protected by exclusive lock on cl->cl_sem */
|
||||||
nfs_delegation_mark_reclaim(clp);
|
status = nfs4_do_reclaim(clp, ops);
|
||||||
/* Note: list is protected by exclusive lock on cl->cl_sem */
|
|
||||||
for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
|
|
||||||
sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
|
|
||||||
status = nfs4_reclaim_open_state(ops, sp);
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
if (status == -NFS4ERR_NO_GRACE) {
|
if (status == -NFS4ERR_NO_GRACE) {
|
||||||
ops = &nfs4_network_partition_recovery_ops;
|
ops = &nfs4_network_partition_recovery_ops;
|
||||||
status = nfs4_reclaim_open_state(ops, sp);
|
status = nfs4_do_reclaim(clp, ops);
|
||||||
}
|
}
|
||||||
if (status == -NFS4ERR_STALE_CLIENTID)
|
if (status == -NFS4ERR_STALE_CLIENTID)
|
||||||
goto restart_loop;
|
continue;
|
||||||
if (status == -NFS4ERR_EXPIRED)
|
if (status == -NFS4ERR_EXPIRED)
|
||||||
goto restart_loop;
|
continue;
|
||||||
}
|
}
|
||||||
|
nfs_delegation_reap_unclaimed(clp);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
nfs_delegation_reap_unclaimed(clp);
|
|
||||||
out:
|
out:
|
||||||
up_write(&clp->cl_sem);
|
up_write(&clp->cl_sem);
|
||||||
if (status == -NFS4ERR_CB_PATH_DOWN)
|
if (status == -NFS4ERR_CB_PATH_DOWN)
|
||||||
|
Reference in New Issue
Block a user