NFSv4: nfs_inode_find_state_and_recover() should check all stateids
authorTrond Myklebust <trond.myklebust@primarydata.com>
Thu, 22 Sep 2016 17:39:07 +0000 (13:39 -0400)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 27 Sep 2016 18:34:35 +0000 (14:34 -0400)
Modify the helper nfs_inode_find_state_and_recover() so that it
can check all open/lock/delegation state trackers on that inode for
whether or not they need are affected by a revoked stateid error.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Tested-by: Oleg Drokin <green@linuxhacker.ru>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/delegation.c
fs/nfs/delegation.h
fs/nfs/nfs4state.c

index 484f147001083364bacc8d5a751a44c8473ed618..5de4cfb2ab07b08aa1866e6fe2b88061bc0033c1 100644 (file)
@@ -1001,6 +1001,25 @@ restart:
        rcu_read_unlock();
 }
 
+void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
+               const nfs4_stateid *stateid)
+{
+       struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
+       struct nfs_delegation *delegation;
+       bool found = false;
+
+       rcu_read_lock();
+       delegation = rcu_dereference(NFS_I(inode)->delegation);
+       if (delegation &&
+           nfs4_stateid_match_other(&delegation->stateid, stateid)) {
+               nfs_mark_test_expired_delegation(NFS_SERVER(inode), delegation);
+               found = true;
+       }
+       rcu_read_unlock();
+       if (found)
+               nfs4_schedule_state_manager(clp);
+}
+
 /**
  * nfs_delegations_present - check for existence of delegations
  * @clp: client state handle
index 1442e3b1521d25932a3fe5fa5d29242d0eca7c69..e9d55579687393552b0d83c46dfcafc56dbace89 100644 (file)
@@ -66,6 +66,8 @@ void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
 int nfs4_have_delegation(struct inode *inode, fmode_t flags);
 int nfs4_check_delegation(struct inode *inode, fmode_t flags);
 bool nfs4_delegation_flush_on_close(const struct inode *inode);
+void nfs_inode_find_delegation_state_and_recover(struct inode *inode,
+               const nfs4_stateid *stateid);
 
 #endif
 
index 63da0411e2af060ca00fa277b6562d116e602d0a..4b538bb194f8896731cc8b13a335d5813bebc56a 100644 (file)
@@ -1337,6 +1337,35 @@ int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_
 }
 EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
 
+static struct nfs4_lock_state *
+nfs_state_find_lock_state_by_stateid(struct nfs4_state *state,
+               const nfs4_stateid *stateid)
+{
+       struct nfs4_lock_state *pos;
+
+       list_for_each_entry(pos, &state->lock_states, ls_locks) {
+               if (!test_bit(NFS_LOCK_INITIALIZED, &pos->ls_flags))
+                       continue;
+               if (nfs4_stateid_match_other(&pos->ls_stateid, stateid))
+                       return pos;
+       }
+       return NULL;
+}
+
+static bool nfs_state_lock_state_matches_stateid(struct nfs4_state *state,
+               const nfs4_stateid *stateid)
+{
+       bool found = false;
+
+       if (test_bit(LK_STATE_IN_USE, &state->flags)) {
+               spin_lock(&state->state_lock);
+               if (nfs_state_find_lock_state_by_stateid(state, stateid))
+                       found = true;
+               spin_unlock(&state->state_lock);
+       }
+       return found;
+}
+
 void nfs_inode_find_state_and_recover(struct inode *inode,
                const nfs4_stateid *stateid)
 {
@@ -1351,14 +1380,19 @@ void nfs_inode_find_state_and_recover(struct inode *inode,
                state = ctx->state;
                if (state == NULL)
                        continue;
-               if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
-                       continue;
-               if (!nfs4_stateid_match(&state->stateid, stateid))
+               if (nfs4_stateid_match_other(&state->stateid, stateid)) {
+                       nfs4_state_mark_reclaim_nograce(clp, state);
+                       found = true;
                        continue;
-               nfs4_state_mark_reclaim_nograce(clp, state);
-               found = true;
+               }
+               if (nfs_state_lock_state_matches_stateid(state, stateid)) {
+                       nfs4_state_mark_reclaim_nograce(clp, state);
+                       found = true;
+               }
        }
        spin_unlock(&inode->i_lock);
+
+       nfs_inode_find_delegation_state_and_recover(inode, stateid);
        if (found)
                nfs4_schedule_state_manager(clp);
 }