linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] NFS: Split out the body of nfs4_reclaim_open_state()
@ 2018-09-11 20:23 schumaker.anna
  2018-09-11 20:23 ` [PATCH 2/3] NFS: Reduce indentation of the switch statement in nfs4_reclaim_open_state() schumaker.anna
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: schumaker.anna @ 2018-09-11 20:23 UTC (permalink / raw)
  To: Trond.Myklebust, linux-nfs

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

Moving all of this into a new function removes the need for cramped
indentation, making the code overall easier to look at.   I also take
this chance to switch copy recovery over to using
nfs4_stateid_match_other()

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 fs/nfs/nfs4state.c | 83 ++++++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 36 deletions(-)

diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 3df0eb52da1c..aa46a3216d60 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1547,10 +1547,51 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
 	return status;
 }
 
+static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
+				     const struct nfs4_state_recovery_ops *ops)
+{
+	struct nfs4_lock_state *lock;
+	int status;
+
+	status = ops->recover_open(sp, state);
+	if (status < 0)
+		return status;
+
+	status = nfs4_reclaim_locks(state, ops);
+	if (status < 0)
+		return status;
+
+	if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
+		spin_lock(&state->state_lock);
+		list_for_each_entry(lock, &state->lock_states, ls_locks) {
+			if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
+				pr_warn_ratelimited("NFS: %s: Lock reclaim failed!\n", __func__);
+		}
+		spin_unlock(&state->state_lock);
+	}
+
+#ifdef CONFIG_NFS_V4_2
+	if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
+		struct nfs4_copy_state *copy;
+		spin_lock(&sp->so_server->nfs_client->cl_lock);
+		list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
+			if (nfs4_stateid_match_other(&state->stateid, &copy->parent_state->stateid))
+				continue;
+			copy->flags = 1;
+			complete(&copy->completion);
+			break;
+		}
+		spin_unlock(&sp->so_server->nfs_client->cl_lock);
+	}
+#endif /* CONFIG_NFS_V4_2 */
+
+	clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
+	return status;
+}
+
 static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
 {
 	struct nfs4_state *state;
-	struct nfs4_lock_state *lock;
 	int status = 0;
 
 	/* Note: we rely on the sp->so_states list being ordered 
@@ -1573,43 +1614,13 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
 			continue;
 		atomic_inc(&state->count);
 		spin_unlock(&sp->so_lock);
-		status = ops->recover_open(sp, state);
+		status = __nfs4_reclaim_open_state(sp, state, ops);
 		if (status >= 0) {
-			status = nfs4_reclaim_locks(state, ops);
-			if (status >= 0) {
-				if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
-					spin_lock(&state->state_lock);
-					list_for_each_entry(lock, &state->lock_states, ls_locks) {
-						if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
-							pr_warn_ratelimited("NFS: "
-									    "%s: Lock reclaim "
-									    "failed!\n", __func__);
-					}
-					spin_unlock(&state->state_lock);
-				}
-				clear_bit(NFS_STATE_RECLAIM_NOGRACE,
-					&state->flags);
-#ifdef CONFIG_NFS_V4_2
-				if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
-					struct nfs4_copy_state *copy;
-
-					spin_lock(&sp->so_server->nfs_client->cl_lock);
-					list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
-						if (memcmp(&state->stateid.other, &copy->parent_state->stateid.other, NFS4_STATEID_SIZE))
-							continue;
-						copy->flags = 1;
-						complete(&copy->completion);
-						printk("AGLO: server rebooted waking up the copy\n");
-						break;
-					}
-					spin_unlock(&sp->so_server->nfs_client->cl_lock);
-				}
-#endif /* CONFIG_NFS_V4_2 */
-				nfs4_put_open_state(state);
-				spin_lock(&sp->so_lock);
-				goto restart;
-			}
+			nfs4_put_open_state(state);
+			spin_lock(&sp->so_lock);
+			goto restart;
 		}
+
 		switch (status) {
 			default:
 				printk(KERN_ERR "NFS: %s: unhandled error %d\n",
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-09-19  1:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-11 20:23 [PATCH 1/3] NFS: Split out the body of nfs4_reclaim_open_state() schumaker.anna
2018-09-11 20:23 ` [PATCH 2/3] NFS: Reduce indentation of the switch statement in nfs4_reclaim_open_state() schumaker.anna
2018-09-11 20:23 ` [PATCH 3/3] NFS: Reduce indentation of nfs4_recovery_handle_error() schumaker.anna
2018-09-18 20:19 ` [PATCH 1/3] NFS: Split out the body of nfs4_reclaim_open_state() Trond Myklebust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).