pNFS: Fix LAYOUTGET handling of NFS4ERR_BAD_STATEID and NFS4ERR_EXPIRED
authorTrond Myklebust <trond.myklebust@primarydata.com>
Thu, 14 Jul 2016 19:14:02 +0000 (15:14 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Tue, 19 Jul 2016 20:23:23 +0000 (16:23 -0400)
We want to recover the open stateid if there is no layout stateid
and/or the stateid argument matches an open stateid.
Otherwise throw out the existing layout and recover from scratch, as
the layout stateid is bad.

Fixes: 183d9e7b112aa ("pnfs: rework LAYOUTGET retry handling")
Cc: stable@vger.kernel.org # 4.7
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
fs/nfs/nfs4proc.c

index ee8efe0a52029ec5f0d9cbc46cc6d895191b6a6a..a1a3b4c9a563b71f47198dcc0b319dde8b3eb82b 100644 (file)
@@ -7886,6 +7886,7 @@ nfs4_layoutget_handle_exception(struct rpc_task *task,
        struct pnfs_layout_hdr *lo;
        int nfs4err = task->tk_status;
        int err, status = 0;
+       LIST_HEAD(head);
 
        dprintk("--> %s tk_status => %d\n", __func__, -task->tk_status);
 
@@ -7930,30 +7931,25 @@ nfs4_layoutget_handle_exception(struct rpc_task *task,
        case -NFS4ERR_BAD_STATEID:
                exception->timeout = 0;
                spin_lock(&inode->i_lock);
-               if (nfs4_stateid_match(&lgp->args.stateid,
+               lo = NFS_I(inode)->layout;
+               /* If the open stateid was bad, then recover it. */
+               if (!lo || test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) ||
+                   nfs4_stateid_match_other(&lgp->args.stateid,
                                        &lgp->args.ctx->state->stateid)) {
                        spin_unlock(&inode->i_lock);
-                       /* If the open stateid was bad, then recover it. */
                        exception->state = lgp->args.ctx->state;
                        break;
                }
-               lo = NFS_I(inode)->layout;
-               if (lo && !test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) &&
-                   nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) {
-                       LIST_HEAD(head);
-
-                       /*
-                        * Mark the bad layout state as invalid, then retry
-                        * with the current stateid.
-                        */
-                       set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags);
-                       pnfs_mark_matching_lsegs_invalid(lo, &head, NULL, 0);
-                       spin_unlock(&inode->i_lock);
-                       pnfs_free_lseg_list(&head);
-                       status = -EAGAIN;
-                       goto out;
-               } else
-                       spin_unlock(&inode->i_lock);
+
+               /*
+                * Mark the bad layout state as invalid, then retry
+                */
+               set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags);
+               pnfs_mark_matching_lsegs_invalid(lo, &head, NULL, 0);
+               spin_unlock(&inode->i_lock);
+               pnfs_free_lseg_list(&head);
+               status = -EAGAIN;
+               goto out;
        }
 
        err = nfs4_handle_exception(server, nfs4err, exception);