Commit 5d422301 authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Fail I/O if the state recovery fails irrevocably

If state recovery fails with an ESTALE or a ENOENT, then we shouldn't
keep retrying. Instead, mark the stateid as being invalid and
fail the I/O with an EIO error.
For other operations such as POSIX and BSD file locking, truncate
etc, fail with an EBADF to indicate that this file descriptor is no
longer valid.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 3ed5e2a2
...@@ -149,6 +149,7 @@ enum { ...@@ -149,6 +149,7 @@ enum {
NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */ NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */
NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */ NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */
NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */ NFS_STATE_POSIX_LOCKS, /* Posix locks are supported */
NFS_STATE_RECOVERY_FAILED, /* OPEN stateid state recovery failed */
}; };
struct nfs4_state { struct nfs4_state {
...@@ -347,7 +348,7 @@ extern int nfs4_wait_clnt_recover(struct nfs_client *clp); ...@@ -347,7 +348,7 @@ extern int nfs4_wait_clnt_recover(struct nfs_client *clp);
extern int nfs4_client_recover_expired_lease(struct nfs_client *clp); extern int nfs4_client_recover_expired_lease(struct nfs_client *clp);
extern void nfs4_schedule_state_manager(struct nfs_client *); extern void nfs4_schedule_state_manager(struct nfs_client *);
extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
extern void nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *); extern int nfs4_schedule_stateid_recovery(const struct nfs_server *, struct nfs4_state *);
extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags); extern void nfs41_handle_sequence_flag_errors(struct nfs_client *clp, u32 flags);
extern void nfs41_handle_server_scope(struct nfs_client *, extern void nfs41_handle_server_scope(struct nfs_client *,
struct nfs41_server_scope **); struct nfs41_server_scope **);
...@@ -412,6 +413,11 @@ static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_statei ...@@ -412,6 +413,11 @@ static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_statei
return memcmp(dst, src, sizeof(*dst)) == 0; return memcmp(dst, src, sizeof(*dst)) == 0;
} }
static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
{
return test_bit(NFS_STATE_RECOVERY_FAILED, &state->flags) == 0;
}
#else #else
#define nfs4_close_state(a, b) do { } while (0) #define nfs4_close_state(a, b) do { } while (0)
......
...@@ -158,11 +158,14 @@ static int filelayout_async_handle_error(struct rpc_task *task, ...@@ -158,11 +158,14 @@ static int filelayout_async_handle_error(struct rpc_task *task,
case -NFS4ERR_OPENMODE: case -NFS4ERR_OPENMODE:
if (state == NULL) if (state == NULL)
break; break;
nfs4_schedule_stateid_recovery(mds_server, state); if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
goto out_bad_stateid;
goto wait_on_recovery; goto wait_on_recovery;
case -NFS4ERR_EXPIRED: case -NFS4ERR_EXPIRED:
if (state != NULL) if (state != NULL) {
nfs4_schedule_stateid_recovery(mds_server, state); if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
goto out_bad_stateid;
}
nfs4_schedule_lease_recovery(mds_client); nfs4_schedule_lease_recovery(mds_client);
goto wait_on_recovery; goto wait_on_recovery;
/* DS session errors */ /* DS session errors */
...@@ -226,6 +229,9 @@ static int filelayout_async_handle_error(struct rpc_task *task, ...@@ -226,6 +229,9 @@ static int filelayout_async_handle_error(struct rpc_task *task,
out: out:
task->tk_status = 0; task->tk_status = 0;
return -EAGAIN; return -EAGAIN;
out_bad_stateid:
task->tk_status = -EIO;
return 0;
wait_on_recovery: wait_on_recovery:
rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL); rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0) if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
......
...@@ -295,7 +295,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc ...@@ -295,7 +295,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
} }
if (state == NULL) if (state == NULL)
break; break;
nfs4_schedule_stateid_recovery(server, state); ret = nfs4_schedule_stateid_recovery(server, state);
if (ret < 0)
break;
goto wait_on_recovery; goto wait_on_recovery;
case -NFS4ERR_DELEG_REVOKED: case -NFS4ERR_DELEG_REVOKED:
case -NFS4ERR_ADMIN_REVOKED: case -NFS4ERR_ADMIN_REVOKED:
...@@ -303,11 +305,16 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc ...@@ -303,11 +305,16 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
if (state == NULL) if (state == NULL)
break; break;
nfs_remove_bad_delegation(state->inode); nfs_remove_bad_delegation(state->inode);
nfs4_schedule_stateid_recovery(server, state); ret = nfs4_schedule_stateid_recovery(server, state);
if (ret < 0)
break;
goto wait_on_recovery; goto wait_on_recovery;
case -NFS4ERR_EXPIRED: case -NFS4ERR_EXPIRED:
if (state != NULL) if (state != NULL) {
nfs4_schedule_stateid_recovery(server, state); ret = nfs4_schedule_stateid_recovery(server, state);
if (ret < 0)
break;
}
case -NFS4ERR_STALE_STATEID: case -NFS4ERR_STALE_STATEID:
case -NFS4ERR_STALE_CLIENTID: case -NFS4ERR_STALE_CLIENTID:
nfs4_schedule_lease_recovery(clp); nfs4_schedule_lease_recovery(clp);
...@@ -2053,7 +2060,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, ...@@ -2053,7 +2060,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
nfs_fattr_init(fattr); nfs_fattr_init(fattr);
if (state != NULL) { if (state != NULL && nfs4_valid_open_stateid(state)) {
struct nfs_lockowner lockowner = { struct nfs_lockowner lockowner = {
.l_owner = current->files, .l_owner = current->files,
.l_pid = current->tgid, .l_pid = current->tgid,
...@@ -2201,6 +2208,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) ...@@ -2201,6 +2208,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
calldata->arg.fmode &= ~FMODE_WRITE; calldata->arg.fmode &= ~FMODE_WRITE;
} }
} }
if (!nfs4_valid_open_stateid(state))
call_close = 0;
spin_unlock(&state->owner->so_lock); spin_unlock(&state->owner->so_lock);
if (!call_close) { if (!call_close) {
...@@ -3980,11 +3989,14 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, ...@@ -3980,11 +3989,14 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
case -NFS4ERR_OPENMODE: case -NFS4ERR_OPENMODE:
if (state == NULL) if (state == NULL)
break; break;
nfs4_schedule_stateid_recovery(server, state); if (nfs4_schedule_stateid_recovery(server, state) < 0)
goto stateid_invalid;
goto wait_on_recovery; goto wait_on_recovery;
case -NFS4ERR_EXPIRED: case -NFS4ERR_EXPIRED:
if (state != NULL) if (state != NULL) {
nfs4_schedule_stateid_recovery(server, state); if (nfs4_schedule_stateid_recovery(server, state) < 0)
goto stateid_invalid;
}
case -NFS4ERR_STALE_STATEID: case -NFS4ERR_STALE_STATEID:
case -NFS4ERR_STALE_CLIENTID: case -NFS4ERR_STALE_CLIENTID:
nfs4_schedule_lease_recovery(clp); nfs4_schedule_lease_recovery(clp);
...@@ -4016,6 +4028,9 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server, ...@@ -4016,6 +4028,9 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
} }
task->tk_status = nfs4_map_errors(task->tk_status); task->tk_status = nfs4_map_errors(task->tk_status);
return 0; return 0;
stateid_invalid:
task->tk_status = -EIO;
return 0;
wait_on_recovery: wait_on_recovery:
rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL); rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0) if (test_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) == 0)
...@@ -4632,12 +4647,18 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata) ...@@ -4632,12 +4647,18 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
data->res.open_seqid = data->arg.open_seqid; data->res.open_seqid = data->arg.open_seqid;
} else } else
data->arg.new_lock_owner = 0; data->arg.new_lock_owner = 0;
if (!nfs4_valid_open_stateid(state)) {
data->rpc_status = -EBADF;
task->tk_action = NULL;
goto out_release_open_seqid;
}
data->timestamp = jiffies; data->timestamp = jiffies;
if (nfs4_setup_sequence(data->server, if (nfs4_setup_sequence(data->server,
&data->arg.seq_args, &data->arg.seq_args,
&data->res.seq_res, &data->res.seq_res,
task) == 0) task) == 0)
return; return;
out_release_open_seqid:
nfs_release_seqid(data->arg.open_seqid); nfs_release_seqid(data->arg.open_seqid);
out_release_lock_seqid: out_release_lock_seqid:
nfs_release_seqid(data->arg.lock_seqid); nfs_release_seqid(data->arg.lock_seqid);
......
...@@ -699,6 +699,8 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner) ...@@ -699,6 +699,8 @@ __nfs4_find_state_byowner(struct inode *inode, struct nfs4_state_owner *owner)
list_for_each_entry(state, &nfsi->open_states, inode_states) { list_for_each_entry(state, &nfsi->open_states, inode_states) {
if (state->owner != owner) if (state->owner != owner)
continue; continue;
if (!nfs4_valid_open_stateid(state))
continue;
if (atomic_inc_not_zero(&state->count)) if (atomic_inc_not_zero(&state->count))
return state; return state;
} }
...@@ -1286,14 +1288,17 @@ static int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_s ...@@ -1286,14 +1288,17 @@ static int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_s
return 1; return 1;
} }
void nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state) int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_state *state)
{ {
struct nfs_client *clp = server->nfs_client; struct nfs_client *clp = server->nfs_client;
if (!nfs4_valid_open_stateid(state))
return -EBADF;
nfs4_state_mark_reclaim_nograce(clp, state); nfs4_state_mark_reclaim_nograce(clp, state);
dprintk("%s: scheduling stateid recovery for server %s\n", __func__, dprintk("%s: scheduling stateid recovery for server %s\n", __func__,
clp->cl_hostname); clp->cl_hostname);
nfs4_schedule_state_manager(clp); nfs4_schedule_state_manager(clp);
return 0;
} }
EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery); EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
...@@ -1323,6 +1328,11 @@ void nfs_inode_find_state_and_recover(struct inode *inode, ...@@ -1323,6 +1328,11 @@ void nfs_inode_find_state_and_recover(struct inode *inode,
nfs4_schedule_state_manager(clp); nfs4_schedule_state_manager(clp);
} }
static void nfs4_state_mark_recovery_failed(struct nfs4_state *state, int error)
{
set_bit(NFS_STATE_RECOVERY_FAILED, &state->flags);
}
static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
{ {
...@@ -1398,6 +1408,8 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs ...@@ -1398,6 +1408,8 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
list_for_each_entry(state, &sp->so_states, open_states) { list_for_each_entry(state, &sp->so_states, open_states) {
if (!test_and_clear_bit(ops->state_flag_bit, &state->flags)) if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
continue; continue;
if (!nfs4_valid_open_stateid(state))
continue;
if (state->state == 0) if (state->state == 0)
continue; continue;
atomic_inc(&state->count); atomic_inc(&state->count);
...@@ -1430,10 +1442,7 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs ...@@ -1430,10 +1442,7 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
* Open state on this file cannot be recovered * Open state on this file cannot be recovered
* All we can do is revert to using the zero stateid. * All we can do is revert to using the zero stateid.
*/ */
memset(&state->stateid, 0, nfs4_state_mark_recovery_failed(state, status);
sizeof(state->stateid));
/* Mark the file as being 'closed' */
state->state = 0;
break; break;
case -NFS4ERR_ADMIN_REVOKED: case -NFS4ERR_ADMIN_REVOKED:
case -NFS4ERR_STALE_STATEID: case -NFS4ERR_STALE_STATEID:
......
...@@ -718,6 +718,8 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, ...@@ -718,6 +718,8 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
spin_lock(&lo->plh_inode->i_lock); spin_lock(&lo->plh_inode->i_lock);
if (pnfs_layoutgets_blocked(lo, 1)) { if (pnfs_layoutgets_blocked(lo, 1)) {
status = -EAGAIN; status = -EAGAIN;
} else if (!nfs4_valid_open_stateid(open_state)) {
status = -EBADF;
} else if (list_empty(&lo->plh_segs)) { } else if (list_empty(&lo->plh_segs)) {
int seq; int seq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment