cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2 PATCH 04/12] GFS2: Add do_xmote states to state machine
Date: Mon,  9 Jul 2018 12:50:20 -0500	[thread overview]
Message-ID: <20180709175028.17090-5-rpeterso@redhat.com> (raw)
In-Reply-To: <20180709175028.17090-1-rpeterso@redhat.com>

This patch adds two new states to the glock state machine. The
first is a normal call for gl_target. The second is an abnormal
call for cases in which dlm was unable to grant our request.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
---
 fs/gfs2/glock.c | 37 ++++++++++++++++++++++++++++---------
 fs/gfs2/glock.h |  3 +++
 2 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index b5ba0abca51f..b87c51479a8a 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -60,7 +60,7 @@ struct gfs2_glock_iter {
 
 typedef void (*glock_examiner) (struct gfs2_glock * gl);
 
-static void do_xmote(struct gfs2_glock *gl, unsigned int target);
+static void __state_machine(struct gfs2_glock *gl, int new_state);
 static void state_machine(struct gfs2_glock *gl, int new_state);
 
 static struct dentry *gfs2_root;
@@ -444,9 +444,12 @@ static void gfs2_demote_wake(struct gfs2_glock *gl)
  * finish_xmote - The DLM has replied to one of our lock requests
  * @gl: The glock
  *
+ * Returns: -EAGAIN if do_xmote should be called next
+ *          -EBUSY if dlm could not satisfy the request
+ *          else 0
  */
 
-static void finish_xmote(struct gfs2_glock *gl)
+static int finish_xmote(struct gfs2_glock *gl)
 {
 	const struct gfs2_glock_operations *glops = gl->gl_ops;
 	struct gfs2_holder *gh;
@@ -484,18 +487,16 @@ static void finish_xmote(struct gfs2_glock *gl)
 		switch(state) {
 		/* Unlocked due to conversion deadlock, try again */
 		case LM_ST_UNLOCKED:
-			do_xmote(gl, gl->gl_target);
-			break;
+			return -EAGAIN;
 		/* Conversion fails, unlock and try again */
 		case LM_ST_SHARED:
 		case LM_ST_DEFERRED:
-			do_xmote(gl, LM_ST_UNLOCKED);
-			break;
+			return -EBUSY;
 		default: /* Everything else */
 			pr_err("wanted %u got %u\n", gl->gl_target, state);
 			GLOCK_BUG_ON(gl, 1);
 		}
-		return;
+		return 0;
 	}
 
 	/* Fast path - we got what we asked for */
@@ -513,10 +514,11 @@ static void finish_xmote(struct gfs2_glock *gl)
 		}
 		rv = do_promote(gl);
 		if (rv == 2)
-			return;
+			return 0;
 	}
 out:
 	clear_bit(GLF_LOCK, &gl->gl_flags);
+	return 0;
 }
 
 /**
@@ -655,7 +657,7 @@ __acquires(&gl->gl_lockref.lock)
 		if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
 			do_error(gl, 0); /* Fail queued try locks */
 	}
-	do_xmote(gl, gl->gl_target);
+	__state_machine(gl, GL_ST_DO_XMOTE);
 	return;
 }
 
@@ -673,6 +675,8 @@ __acquires(&gl->gl_lockref.lock)
  */
 static void __state_machine(struct gfs2_glock *gl, int new_state)
 {
+	int ret;
+
 	BUG_ON(!spin_is_locked(&gl->gl_lockref.lock));
 
 	do {
@@ -684,6 +688,21 @@ static void __state_machine(struct gfs2_glock *gl, int new_state)
 
 		case GL_ST_FINISH_XMOTE:
 			gl->gl_mch = GL_ST_IDLE;
+			ret = finish_xmote(gl);
+			if (ret == -EBUSY)
+				gl->gl_mch = GL_ST_DO_XMOTE_UNLOCK;
+			else if (ret == -EAGAIN)
+				gl->gl_mch = GL_ST_DO_XMOTE;
+			break;
+
+		case GL_ST_DO_XMOTE:
+			gl->gl_mch = GL_ST_IDLE;
+			do_xmote(gl, gl->gl_target);
+			break;
+
+		case GL_ST_DO_XMOTE_UNLOCK:
+			gl->gl_mch = GL_ST_IDLE;
+			do_xmote(gl, LM_ST_UNLOCKED);
 			finish_xmote(gl);
 			break;
 		}
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 88043d610d64..8333bbc5a197 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -123,6 +123,9 @@ enum {
 enum gl_machine_states {
 	GL_ST_IDLE = 0,		/* State machine idle; no transition needed */
 	GL_ST_FINISH_XMOTE = 1,	/* Promotion/demotion complete */
+	GL_ST_DO_XMOTE = 2,	/* Promote or demote a waiter */
+	GL_ST_DO_XMOTE_UNLOCK = 3, /* Promote or demote a waiter after a failed
+				      state change attempt from dlm. */
 };
 
 struct lm_lockops {
-- 
2.17.1



  parent reply	other threads:[~2018-07-09 17:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-09 17:50 [Cluster-devel] [GFS2 PATCH 00/12] Radical Reform of glock state machine Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 01/12] GFS2: Make do_xmote determine its own gh parameter Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 02/12] GFS2: Eliminate a goto in finish_xmote Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 03/12] GFS2: Baby step toward a real state machine: finish_xmote Bob Peterson
2018-07-09 17:50 ` Bob Peterson [this message]
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 05/12] GFS2: Make do_xmote not call the state machine again Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 06/12] GFS2: Add blocking and non-blocking demote to state machine Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 07/12] GFS2: Add a new GL_ST_PROMOTE state to glock " Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 08/12] GFS2: Replace run_queue with new GL_ST_RUN state in " Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 09/12] GFS2: Reduce redundancy in GL_ST_DEMOTE_NONBLOCK state Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 10/12] GFS2: Reduce glock_work_func to a single call to state_machine Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 11/12] GFS2: Add new GL_ST_UNLOCK state to reduce calls to the __ version Bob Peterson
2018-07-09 17:50 ` [Cluster-devel] [GFS2 PATCH 12/12] GFS2: Optimization of GL_ST_UNLOCK state Bob Peterson
2018-07-10  8:27 ` [Cluster-devel] [GFS2 PATCH 00/12] Radical Reform of glock state machine Steven Whitehouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180709175028.17090-5-rpeterso@redhat.com \
    --to=rpeterso@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).