linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mateusz Kusiak <mateusz.kusiak@intel.com>
To: linux-raid@vger.kernel.org
Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com
Subject: [PATCH 2/8] monitor: refactor checkpoint update
Date: Tue, 16 Jan 2024 12:24:28 +0100	[thread overview]
Message-ID: <20240116112434.30705-3-mateusz.kusiak@intel.com> (raw)
In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com>

"if" statements of checkpoint updates have too many responsibilties.
This results in unclear code flow and duplicated code.

Refactor checkpoint update code and simplify "if" statements.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
---
 monitor.c | 51 +++++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/monitor.c b/monitor.c
index e0e65f3786d5..138664b2c6d4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -412,6 +412,7 @@ static int read_and_act(struct active_array *a, fd_set *fds)
 	int ret = 0;
 	int count = 0;
 	struct timeval tv;
+	bool write_checkpoint = false;
 
 	a->next_state = bad_word;
 	a->next_action = bad_action;
@@ -564,40 +565,38 @@ static int read_and_act(struct active_array *a, fd_set *fds)
 		}
 	}
 
-	/* Handle reshape checkpointing
-	 */
-	if ((a->curr_action == idle && a->prev_action == reshape) ||
-	    (a->curr_action == reshape && sync_completed > a->last_checkpoint)) {
-		/* Reshape has progressed or completed so we need to
-		 * update the array state - and possibly the array size
-		 */
+	/* Update reshape checkpoint, depending if it finished or progressed */
+	if (a->curr_action == idle && a->prev_action == reshape) {
+		char buf[40];
+
 		if (sync_completed != 0)
 			a->last_checkpoint = sync_completed;
-		/* We might need to update last_checkpoint depending on
-		 * the reason that reshape finished.
-		 * if array reshape is really finished:
-		 *        set check point to the end, this allows
-		 *        set_array_state() to finalize reshape in metadata
-		 * if reshape if broken: do not set checkpoint to the end
-		 *        this allows for reshape restart from checkpoint
+
+		/*
+		 * If reshape really finished, set checkpoint to the end to finalize it.
+		 * Do not set checkpoint if reshape is broken.
+		 * Reshape will restart from last checkpoint.
 		 */
-		if ((a->curr_action != reshape) &&
-		    (a->prev_action == reshape)) {
-			char buf[40];
-			if ((sysfs_get_str(&a->info, NULL,
-					  "reshape_position",
-					  buf,
-					  sizeof(buf)) >= 0) &&
-			     strncmp(buf, "none", 4) == 0)
+		if (sysfs_get_str(&a->info, NULL, "reshape_position", buf, sizeof(buf)) >= 0)
+			if (strncmp(buf, "none", 4) == 0)
 				a->last_checkpoint = a->info.component_size;
-		}
-		a->container->ss->set_array_state(a, a->curr_state <= clean);
-		a->last_checkpoint = sync_completed;
+
+		write_checkpoint = true;
 	}
 
-	if (sync_completed > a->last_checkpoint) {
+	if (a->curr_action >= reshape && sync_completed > a->last_checkpoint) {
+		/* Update checkpoint if neither reshape nor idle action */
 		a->last_checkpoint = sync_completed;
+
+		write_checkpoint = true;
+	}
+
+	/* Save checkpoint */
+	if (write_checkpoint) {
 		a->container->ss->set_array_state(a, a->curr_state <= clean);
+
+		if (a->curr_action <= reshape)
+			a->last_checkpoint = sync_completed;
 	}
 
 	if (sync_completed >= a->info.component_size)
-- 
2.35.3


  parent reply	other threads:[~2024-01-16 11:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 11:24 [PATCH 0/8] Fix checkpointing Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 1/8] Remove hardcoded checkpoint interval checking Mateusz Kusiak
2024-01-16 11:24 ` Mateusz Kusiak [this message]
2024-01-16 11:24 ` [PATCH 3/8] Super-intel: Fix first checkpoint restart Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 4/8] Define sysfs max buffer size Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 5/8] Replace "none" with macro Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 6/8] super-intel: Remove inaccessible code Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 7/8] Grow: Move update_tail assign to Grow_reshape() Mateusz Kusiak
2024-01-16 11:24 ` [PATCH 8/8] Add understanding output section in man Mateusz Kusiak
2024-01-17  8:02 ` [PATCH 0/8] Fix checkpointing Mariusz Tkaczyk

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=20240116112434.30705-3-mateusz.kusiak@intel.com \
    --to=mateusz.kusiak@intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mariusz.tkaczyk@linux.intel.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).