NFSv4: Fail I/O if the state recovery fails irrevocably
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Thu, 14 Mar 2013 20:57:48 +0000 (16:57 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Mon, 25 Mar 2013 16:04:10 +0000 (12:04 -0400)
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: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/nfs4_fs.h
fs/nfs/nfs4filelayout.c
fs/nfs/nfs4proc.c
fs/nfs/nfs4state.c
fs/nfs/pnfs.c

index 944c9a5c10390cdca6112f3ecf27574ef0a89e81..9ce90135bf22d6abe0b364e13198e747534a7eb5 100644 (file)
@@ -149,6 +149,7 @@ enum {
        NFS_STATE_RECLAIM_REBOOT,       /* OPEN stateid server rebooted */
        NFS_STATE_RECLAIM_NOGRACE,      /* OPEN stateid needs to recover state */
        NFS_STATE_POSIX_LOCKS,          /* Posix locks are supported */
+       NFS_STATE_RECOVERY_FAILED,      /* OPEN stateid state recovery failed */
 };
 
 struct nfs4_state {
@@ -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 void nfs4_schedule_state_manager(struct nfs_client *);
 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_server_scope(struct nfs_client *,
                                      struct nfs41_server_scope **);
@@ -412,6 +413,11 @@ static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_statei
        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
 
 #define nfs4_close_state(a, b) do { } while (0)
index 4fb234d3aefb240f3d067523bda6df467336d2d0..1ee5737211d723e55fffb3fa6db68e1cd7ca5c50 100644 (file)
@@ -158,11 +158,14 @@ static int filelayout_async_handle_error(struct rpc_task *task,
        case -NFS4ERR_OPENMODE:
                if (state == NULL)
                        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;
        case -NFS4ERR_EXPIRED:
-               if (state != NULL)
-                       nfs4_schedule_stateid_recovery(mds_server, state);
+               if (state != NULL) {
+                       if (nfs4_schedule_stateid_recovery(mds_server, state) < 0)
+                               goto out_bad_stateid;
+               }
                nfs4_schedule_lease_recovery(mds_client);
                goto wait_on_recovery;
        /* DS session errors */
@@ -226,6 +229,9 @@ reset:
 out:
        task->tk_status = 0;
        return -EAGAIN;
+out_bad_stateid:
+       task->tk_status = -EIO;
+       return 0;
 wait_on_recovery:
        rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
        if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
index 26431cf62ddbc393fd5fe1e432742be37d06e12e..c3bbb6c53d6118bd0f15befe0efdea04a56377bb 100644 (file)
@@ -295,7 +295,9 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
                        }
                        if (state == NULL)
                                break;
-                       nfs4_schedule_stateid_recovery(server, state);
+                       ret = nfs4_schedule_stateid_recovery(server, state);
+                       if (ret < 0)
+                               break;
                        goto wait_on_recovery;
                case -NFS4ERR_DELEG_REVOKED:
                case -NFS4ERR_ADMIN_REVOKED:
@@ -303,11 +305,16 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
                        if (state == NULL)
                                break;
                        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;
                case -NFS4ERR_EXPIRED:
-                       if (state != NULL)
-                               nfs4_schedule_stateid_recovery(server, state);
+                       if (state != NULL) {
+                               ret = nfs4_schedule_stateid_recovery(server, state);
+                               if (ret < 0)
+                                       break;
+                       }
                case -NFS4ERR_STALE_STATEID:
                case -NFS4ERR_STALE_CLIENTID:
                        nfs4_schedule_lease_recovery(clp);
@@ -2053,7 +2060,7 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 
        nfs_fattr_init(fattr);
 
-       if (state != NULL) {
+       if (state != NULL && nfs4_valid_open_stateid(state)) {
                struct nfs_lockowner lockowner = {
                        .l_owner = current->files,
                        .l_pid = current->tgid,
@@ -2201,6 +2208,8 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
                        calldata->arg.fmode &= ~FMODE_WRITE;
                }
        }
+       if (!nfs4_valid_open_stateid(state))
+               call_close = 0;
        spin_unlock(&state->owner->so_lock);
 
        if (!call_close) {
@@ -3980,11 +3989,14 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
                case -NFS4ERR_OPENMODE:
                        if (state == NULL)
                                break;
-                       nfs4_schedule_stateid_recovery(server, state);
+                       if (nfs4_schedule_stateid_recovery(server, state) < 0)
+                               goto stateid_invalid;
                        goto wait_on_recovery;
                case -NFS4ERR_EXPIRED:
-                       if (state != NULL)
-                               nfs4_schedule_stateid_recovery(server, state);
+                       if (state != NULL) {
+                               if (nfs4_schedule_stateid_recovery(server, state) < 0)
+                                       goto stateid_invalid;
+                       }
                case -NFS4ERR_STALE_STATEID:
                case -NFS4ERR_STALE_CLIENTID:
                        nfs4_schedule_lease_recovery(clp);
@@ -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);
        return 0;
+stateid_invalid:
+       task->tk_status = -EIO;
+       return 0;
 wait_on_recovery:
        rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
        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)
                data->res.open_seqid = data->arg.open_seqid;
        } else
                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;
        if (nfs4_setup_sequence(data->server,
                                &data->arg.seq_args,
                                &data->res.seq_res,
                                task) == 0)
                return;
+out_release_open_seqid:
        nfs_release_seqid(data->arg.open_seqid);
 out_release_lock_seqid:
        nfs_release_seqid(data->arg.lock_seqid);
index 6ace365c6334db844af0c2c3f221cd871ef3658c..fec1c5bb486327bd39185dcad3df353a94b75419 100644 (file)
@@ -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) {
                if (state->owner != owner)
                        continue;
+               if (!nfs4_valid_open_stateid(state))
+                       continue;
                if (atomic_inc_not_zero(&state->count))
                        return state;
        }
@@ -1286,14 +1288,17 @@ static int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_s
        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;
 
+       if (!nfs4_valid_open_stateid(state))
+               return -EBADF;
        nfs4_state_mark_reclaim_nograce(clp, state);
        dprintk("%s: scheduling stateid recovery for server %s\n", __func__,
                        clp->cl_hostname);
        nfs4_schedule_state_manager(clp);
+       return 0;
 }
 EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
 
@@ -1323,6 +1328,11 @@ void nfs_inode_find_state_and_recover(struct inode *inode,
                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)
 {
@@ -1398,6 +1408,8 @@ restart:
        list_for_each_entry(state, &sp->so_states, open_states) {
                if (!test_and_clear_bit(ops->state_flag_bit, &state->flags))
                        continue;
+               if (!nfs4_valid_open_stateid(state))
+                       continue;
                if (state->state == 0)
                        continue;
                atomic_inc(&state->count);
@@ -1430,10 +1442,7 @@ restart:
                                 * Open state on this file cannot be recovered
                                 * All we can do is revert to using the zero stateid.
                                 */
-                               memset(&state->stateid, 0,
-                                       sizeof(state->stateid));
-                               /* Mark the file as being 'closed' */
-                               state->state = 0;
+                               nfs4_state_mark_recovery_failed(state, status);
                                break;
                        case -NFS4ERR_ADMIN_REVOKED:
                        case -NFS4ERR_STALE_STATEID:
index 4bdffe0ba025228803b65d4fe54ab5cb0adda0ed..c5bd758e563768d76b2a43c830dcba8b53e175cf 100644 (file)
@@ -718,6 +718,8 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
        spin_lock(&lo->plh_inode->i_lock);
        if (pnfs_layoutgets_blocked(lo, 1)) {
                status = -EAGAIN;
+       } else if (!nfs4_valid_open_stateid(open_state)) {
+               status = -EBADF;
        } else if (list_empty(&lo->plh_segs)) {
                int seq;