From patchwork Tue Jan 16 11:24:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520715 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EA8D1B7FD for ; Tue, 16 Jan 2024 11:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y7X1qw3R" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404323; x=1736940323; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=csuLvsnMRaK5rqT5TrLVKLW2Bi7D4Nq9Nw4I8bFmqV4=; b=Y7X1qw3RJJaPBrEePvbfogHzv9Au4hnpnypes13bEpjLsRV/CL7KvFM/ eiXJwRiQ2QCXs8//cUxNa1lnkD7EpnNrwBMY1q1X+t8eL/I3dSVjqDa0x P7TAQC89+fGUe3b0H9xC7wxlEpFDZi6eMdR8ouQiKHgqhRoc2cUETJXbt LYoQFPlVBXxHijZIj03wRRnbgRl89NW3u30XaWeLJowJKgWHF/eCF75kE Nn9+uq6R0VFtBuShl1vciSrOY6wC+1NVu9+j5DHFgh/40ksDmx/N8nGHd AWKEmPX9ctNCNYz66iYsgE5dVjmJsXDMPa+35FqobsxFz+OYwr1jO4R0e w==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307155" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307155" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:25:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111542" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:25:21 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 1/8] Remove hardcoded checkpoint interval checking Date: Tue, 16 Jan 2024 12:24:27 +0100 Message-Id: <20240116112434.30705-2-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mdmon assumes that kernel marks checkpoint every 1/16 of the volume size and that the checkpoints are equal in size. This is not true, kernel may mark checkpoints more frequently depending on several factors, including sync speed. This results in checkpoints reported by mdadm --examine falling behind the one reported by kernel. Remove hardcoded checkpoint interval checking. Signed-off-by: Mateusz Kusiak --- monitor.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/monitor.c b/monitor.c index 820a93d0ceaf..e0e65f3786d5 100644 --- a/monitor.c +++ b/monitor.c @@ -564,22 +564,10 @@ static int read_and_act(struct active_array *a, fd_set *fds) } } - /* Check for recovery checkpoint notifications. We need to be a - * minimum distance away from the last checkpoint to prevent - * over checkpointing. Note reshape checkpointing is handled - * in the second branch. + /* Handle reshape checkpointing */ - if (sync_completed > a->last_checkpoint && - sync_completed - a->last_checkpoint > a->info.component_size >> 4 && - a->curr_action > reshape) { - /* A (non-reshape) sync_action has reached a checkpoint. - * Record the updated position in the metadata - */ - a->last_checkpoint = sync_completed; - a->container->ss->set_array_state(a, a->curr_state <= clean); - } else if ((a->curr_action == idle && a->prev_action == reshape) || - (a->curr_action == reshape && - sync_completed > a->last_checkpoint)) { + 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 */ @@ -607,8 +595,10 @@ static int read_and_act(struct active_array *a, fd_set *fds) a->last_checkpoint = sync_completed; } - if (sync_completed > a->last_checkpoint) + if (sync_completed > a->last_checkpoint) { a->last_checkpoint = sync_completed; + a->container->ss->set_array_state(a, a->curr_state <= clean); + } if (sync_completed >= a->info.component_size) a->last_checkpoint = 0; From patchwork Tue Jan 16 11:24:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520716 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EE681B7FD for ; Tue, 16 Jan 2024 11:25:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Sl+veJpE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404336; x=1736940336; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y8VLNa1UAqY/X811BoBVzjvchHXimiTOi+XYqUAhffI=; b=Sl+veJpEH0BuD0uiAjAq21yjwLuyHdMhdsArVHcJgTjtiryxG+/aEiHn oHqwlOOZ5TFEOQS7LgmRNiUQrACPAguBuJq7tDNzuphDLLTevQGs/8Nm1 VXuABl0EkSYO15eLoKWY86SAJY2YiuiCi2xQiW8qQkpxYtozpFldtCs/C 6Y5T3LEs1lV6BfiQmBZp/ADGlW8E2aWA09BgXxzegdFxoTyYX+//aLIl3 I4Fc2TAcrBbE59I5+pMVAex1nULkxYjo4ARuHVCu6gzF5k3yNDqpnofB/ t2wyzmIbMrHJEAH5ZNRbW/D3t2zQHflz0AmOhIRALkvqL+7Yt6Kb2TIv3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307229" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307229" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:25:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111575" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:25:35 -0800 From: Mateusz Kusiak 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 Message-Id: <20240116112434.30705-3-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 "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 --- 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) From patchwork Tue Jan 16 11:24:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520717 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 077691B7F9 for ; Tue, 16 Jan 2024 11:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CtBIIPB2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404350; x=1736940350; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KH/lreDIYz1akb/UEE2T3wPH0f1vsrlZr2KB6DCu3Rw=; b=CtBIIPB2mj/D1AA334w5fylIpvPGKnsRZnFe4mV1G7m7iRj+hM7RN9y6 11nrfqBEoCKETQ6HA4G3ggkvkOQdfRV8DC20H5otXXxpmgbm7NQtqDA3Q A7/Oog/4OLkB3TsOe7in1G2lD/sQXUmeyNJm3b8vV4qwsX/9H0fRciB5P tLz/eHvgBFv6T14OgavDvmi9K+34vOoYkLRrLxZkU7foLRs7OjcIyit2G yUJjWey+yPLtp2ahDJB8sKvdsKHPiVflQwcMLkaqa5dC8+uC3Tt2fW7PN n31TapIlTtaIM/1adQvGXNwuuuRGVUl8NxVhLJ/mEoKNDu+l5ZqYd5Tf4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307264" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307264" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:25:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111622" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:25:48 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 3/8] Super-intel: Fix first checkpoint restart Date: Tue, 16 Jan 2024 12:24:29 +0100 Message-Id: <20240116112434.30705-4-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When imsm based array is stopped after reaching first checkpoint and then assembled, first checkpoint is reported as 0. This behaviour is valid only for initial checkpoint, if the array was stopped while performing some action. Last checkpoint value is not taken from metadata but always starts with 0 and it's incremented when sync_completed in sysfs changes. In simplification, read_and_act() is responsible for checkpoint updates and is executed each time sysfs checkpoint update happens. For first checkpoint it is executed twice and due to marking checkpoint before triggering any action on the array, it is impossible to read sync_completed from sysfs in just two iterations. The workaround to this is not marking any checkpoint for first sysfs checkpoint after RAID assembly, to preserve checkpoint value stored in metadata. Signed-off-by: Mateusz Kusiak --- super-intel.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/super-intel.c b/super-intel.c index 77b0066fc470..5e4c08fb7854 100644 --- a/super-intel.c +++ b/super-intel.c @@ -8818,6 +8818,9 @@ static int imsm_set_array_state(struct active_array *a, int consistent) super->updates_pending++; } + if (a->prev_action == idle) + goto skip_mark_checkpoint; + mark_checkpoint: /* skip checkpointing for general migration, * it is controlled in mdadm From patchwork Tue Jan 16 11:24:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520718 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54E381B7F9 for ; Tue, 16 Jan 2024 11:26:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="El/TXJwA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404364; x=1736940364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yxNILIY9y9fzyTXPa6qqqilPERAVbMNp0byPXhdGB30=; b=El/TXJwAAz2ftiEQ9nB4VADfnsw1DnxxwFzPSjRIU9kmvYDt3x4pjRVW JyB9Q5BzQoUN2ZZnagRatzd/hJiVKxEl1P1PRP35ZZDka76BCo55Fbkwm uBDR7M1QDToi59T5ZEcQO9qb5y1bDQU//cJgs4jyUF5tUakgtww3ntZx9 eR9CKSAM8Ual0Vcnsi+pG2FTyjQCuEJUqLNYKUJcV3zMnMgfNXyzSFA13 IK6JqGka4AuwPZ2hf8utsUzeiP9+ZQs/wgA1h4zXhOD5TE40SJn/joKPi j1IXsX3+H0Ikld+X3OJ8De52chpm7Enrk1aYSk3A0M+1ckgOTqjKw1SeY w==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307300" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307300" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:26:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111674" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:26:02 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 4/8] Define sysfs max buffer size Date: Tue, 16 Jan 2024 12:24:30 +0100 Message-Id: <20240116112434.30705-5-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 sysfs_get_str() usages have inconsistant buffer size. This results in wild buffer declarations and redundant memory usage. Define maximum buffer size for sysfs strings. Replace wild sysfs string buffer sizes for globaly defined value. Signed-off-by: Mateusz Kusiak --- Grow.c | 36 ++++++++++++++++++------------------ Incremental.c | 2 +- Manage.c | 8 ++++---- Monitor.c | 6 +++--- managemon.c | 6 +++--- mdadm.h | 2 ++ monitor.c | 20 ++++++++++---------- msg.c | 4 ++-- super-intel.c | 14 +++++++------- sysfs.c | 8 ++++---- 10 files changed, 54 insertions(+), 52 deletions(-) diff --git a/Grow.c b/Grow.c index 8fa978756a82..8ca8ee781d1b 100644 --- a/Grow.c +++ b/Grow.c @@ -545,7 +545,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha char *subarray = NULL; int ret = 0; char container_dev[PATH_MAX]; - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC && s->consistency_policy != CONSISTENCY_POLICY_PPL) { @@ -594,7 +594,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha } if (s->consistency_policy == CONSISTENCY_POLICY_PPL) { - if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) { + if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) { ret = 1; goto free_info; } else if (strcmp(buf, "reshape\n") == 0) { @@ -817,12 +817,12 @@ static int freeze(struct supertype *st) else { struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION); int err; - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; if (!sra) return -1; /* Need to clear any 'read-auto' status */ - if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 && + if (sysfs_get_str(sra, NULL, "array_state", buf, sizeof(buf)) > 0 && strncmp(buf, "read-auto", 9) == 0) sysfs_set_str(sra, NULL, "array_state", "clean"); @@ -838,10 +838,10 @@ static void unfreeze(struct supertype *st) return unfreeze_container(st); else { struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION); - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; if (sra && - sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 && + sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 && strcmp(buf, "frozen\n") == 0) sysfs_set_str(sra, NULL, "sync_action", "idle"); sysfs_free(sra); @@ -851,12 +851,12 @@ static void unfreeze(struct supertype *st) static void wait_reshape(struct mdinfo *sra) { int fd = sysfs_get_fd(sra, NULL, "sync_action"); - char action[20]; + char action[SYSFS_MAX_BUF_SIZE]; if (fd < 0) return; - while (sysfs_fd_get_str(fd, action, 20) > 0 && + while (sysfs_fd_get_str(fd, action, sizeof(action)) > 0 && strncmp(action, "reshape", 7) == 0) sysfs_wait(fd, NULL); close(fd); @@ -902,7 +902,7 @@ static int subarray_set_num(char *container, struct mdinfo *sra, char *name, int * to close a race with the array_state going clean before the * next write to raid_disks / stripe_cache_size */ - char safe[50]; + char safe[SYSFS_MAX_BUF_SIZE]; int rc; /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */ @@ -2396,11 +2396,11 @@ release: static int verify_reshape_position(struct mdinfo *info, int level) { int ret_val = 0; - char buf[40]; + char buf[SYSFS_MAX_BUF_SIZE]; int rv; /* read sync_max, failure can mean raid0 array */ - rv = sysfs_get_str(info, NULL, "sync_max", buf, 40); + rv = sysfs_get_str(info, NULL, "sync_max", buf, sizeof(buf)); if (rv > 0) { char *ep; @@ -3040,7 +3040,7 @@ static int reshape_array(char *container, int fd, char *devname, unsigned long long array_size; int done; struct mdinfo *sra = NULL; - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; /* when reshaping a RAID0, the component_size might be zero. * So try to fix that up. @@ -3916,7 +3916,7 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape, unsigned long long array_size = (info->component_size * reshape->before.data_disks); int fd; - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; /* First, we unsuspend any region that is now known to be safe. * If suspend_point is on the 'wrong' side of reshape_progress, then @@ -4094,8 +4094,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape, /* Check that sync_action is still 'reshape' to avoid * waiting forever on a dead array */ - char action[20]; - if (sysfs_get_str(info, NULL, "sync_action", action, 20) <= 0 || + char action[SYSFS_MAX_BUF_SIZE]; + if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) <= 0 || strncmp(action, "reshape", 7) != 0) break; /* Some kernels reset 'sync_completed' to zero @@ -4121,8 +4121,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape, */ if (completed == 0) { unsigned long long reshapep; - char action[20]; - if (sysfs_get_str(info, NULL, "sync_action", action, 20) > 0 && + char action[SYSFS_MAX_BUF_SIZE]; + if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) > 0 && strncmp(action, "idle", 4) == 0 && sysfs_get_ll(info, NULL, "reshape_position", &reshapep) == 0) @@ -4240,7 +4240,7 @@ static int grow_backup(struct mdinfo *sra, if (sd->disk.state & (1<disk.state & (1< lacks the possibility to re-add new device in this port\n"); diff --git a/Manage.c b/Manage.c index f997b1633e74..02ada689e02a 100644 --- a/Manage.c +++ b/Manage.c @@ -180,7 +180,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry) char container[32]; int err; int count; - char buf[32]; + char buf[SYSFS_MAX_BUF_SIZE]; unsigned long long rd1, rd2; if (will_retry && verbose == 0) @@ -311,7 +311,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry) if (mdi && is_level456(mdi->array.level) && sysfs_attribute_available(mdi, NULL, "sync_action") && sysfs_attribute_available(mdi, NULL, "reshape_direction") && - sysfs_get_str(mdi, NULL, "sync_action", buf, 20) > 0 && + sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0 && strcmp(buf, "reshape\n") == 0 && sysfs_get_two(mdi, NULL, "raid_disks", &rd1, &rd2) == 2) { unsigned long long position, curr; @@ -1510,8 +1510,8 @@ int Manage_subdevs(char *devname, int fd, sprintf(dname, "dev-%s", dv->devname); sysfd = sysfs_open(fd2devnm(fd), dname, "block/dev"); if (sysfd >= 0) { - char dn[20]; - if (sysfs_fd_get_str(sysfd, dn, 20) > 0 && + char dn[SYSFS_MAX_BUF_SIZE]; + if (sysfs_fd_get_str(sysfd, dn, sizeof(dn)) > 0 && sscanf(dn, "%d:%d", &mj,&mn) == 2) { rdev = makedev(mj,mn); found = 1; diff --git a/Monitor.c b/Monitor.c index e74a0558a057..7548adcf01f0 100644 --- a/Monitor.c +++ b/Monitor.c @@ -1346,12 +1346,12 @@ int Wait(char *dev) * sync_action does. */ struct mdinfo mdi; - char buf[21]; + char buf[SYSFS_MAX_BUF_SIZE]; if (sysfs_init(&mdi, -1, devnm)) return 2; if (sysfs_get_str(&mdi, NULL, "sync_action", - buf, 20) > 0 && + buf, sizeof(buf)) > 0 && strcmp(buf,"idle\n") != 0) { e->percent = RESYNC_UNKNOWN; if (strcmp(buf, "frozen\n") == 0) { @@ -1430,7 +1430,7 @@ int WaitClean(char *dev, int verbose) if (rv) { int state_fd = sysfs_open(fd2devnm(fd), NULL, "array_state"); - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; int delay = 5000; /* minimize the safe_mode_delay and prepare to wait up to 5s diff --git a/managemon.c b/managemon.c index a7bfa8f618a4..358459e79435 100644 --- a/managemon.c +++ b/managemon.c @@ -454,7 +454,7 @@ static void manage_member(struct mdstat_ent *mdstat, * trying to find and assign a spare. * We do that whenever the monitor tells us too. */ - char buf[64]; + char buf[SYSFS_MAX_BUF_SIZE]; int frozen; struct supertype *container = a->container; struct mdinfo *mdi; @@ -664,7 +664,7 @@ static void manage_new(struct mdstat_ent *mdstat, struct mdinfo *mdi = NULL, *di; int i, inst; int failed = 0; - char buf[40]; + char buf[SYSFS_MAX_BUF_SIZE]; /* check if array is ready to be monitored */ if (!mdstat->active || !mdstat->level) @@ -738,7 +738,7 @@ static void manage_new(struct mdstat_ent *mdstat, * read this information for new arrays only (empty victim) */ if ((victim == NULL) && - (sysfs_get_str(mdi, NULL, "sync_action", buf, 40) > 0) && + (sysfs_get_str(mdi, NULL, "sync_action", buf, sizeof(buf)) > 0) && (strncmp(buf, "reshape", 7) == 0)) { if (sysfs_get_ll(mdi, NULL, "reshape_position", &new->last_checkpoint) != 0) diff --git a/mdadm.h b/mdadm.h index f0ceeb78ca6c..d159b92a67ef 100644 --- a/mdadm.h +++ b/mdadm.h @@ -759,6 +759,8 @@ enum sysfs_read_flags { GET_DEVS_ALL = (1 << 27), }; +#define SYSFS_MAX_BUF_SIZE 64 + /* If fd >= 0, get the array it is open on, * else use devnm. */ diff --git a/monitor.c b/monitor.c index 138664b2c6d4..6b5b4501a0b9 100644 --- a/monitor.c +++ b/monitor.c @@ -81,10 +81,10 @@ static int read_attr(char *buf, int len, int fd) static void read_resync_start(int fd, unsigned long long *v) { - char buf[30]; + char buf[SYSFS_MAX_BUF_SIZE]; int n; - n = read_attr(buf, 30, fd); + n = read_attr(buf, sizeof(buf), fd); if (n <= 0) { dprintf("Failed to read resync_start (%d)\n", fd); return; @@ -98,11 +98,11 @@ static void read_resync_start(int fd, unsigned long long *v) static unsigned long long read_sync_completed(int fd) { unsigned long long val; - char buf[50]; + char buf[SYSFS_MAX_BUF_SIZE]; int n; char *ep; - n = read_attr(buf, 50, fd); + n = read_attr(buf, sizeof(buf), fd); if (n <= 0) return 0; @@ -115,8 +115,8 @@ static unsigned long long read_sync_completed(int fd) static enum array_state read_state(int fd) { - char buf[20]; - int n = read_attr(buf, 20, fd); + char buf[SYSFS_MAX_BUF_SIZE]; + int n = read_attr(buf, sizeof(buf), fd); if (n <= 0) return bad_word; @@ -125,8 +125,8 @@ static enum array_state read_state(int fd) static enum sync_action read_action( int fd) { - char buf[20]; - int n = read_attr(buf, 20, fd); + char buf[SYSFS_MAX_BUF_SIZE]; + int n = read_attr(buf, sizeof(buf), fd); if (n <= 0) return bad_action; @@ -135,7 +135,7 @@ static enum sync_action read_action( int fd) int read_dev_state(int fd) { - char buf[100]; + char buf[SYSFS_MAX_BUF_SIZE]; int n = read_attr(buf, sizeof(buf), fd); char *cp; int rv = 0; @@ -567,7 +567,7 @@ static int read_and_act(struct active_array *a, fd_set *fds) /* Update reshape checkpoint, depending if it finished or progressed */ if (a->curr_action == idle && a->prev_action == reshape) { - char buf[40]; + char buf[SYSFS_MAX_BUF_SIZE]; if (sync_completed != 0) a->last_checkpoint = sync_completed; diff --git a/msg.c b/msg.c index 45cd45040a61..ba0e25be906d 100644 --- a/msg.c +++ b/msg.c @@ -324,7 +324,7 @@ int block_monitor(char *container, const int freeze) { struct mdstat_ent *ent, *e, *e2; struct mdinfo *sra = NULL; - char buf[64]; + char buf[SYSFS_MAX_BUF_SIZE]; int rv = 0; if (check_mdmon_version(container)) @@ -366,7 +366,7 @@ int block_monitor(char *container, const int freeze) !sysfs_attribute_available(sra, NULL, "sync_action")) || (freeze && sysfs_attribute_available(sra, NULL, "sync_action") && - sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 && + sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 && strcmp(buf, "frozen\n") == 0)) /* pass */; else { diff --git a/super-intel.c b/super-intel.c index 5e4c08fb7854..e13e6bbc4ae9 100644 --- a/super-intel.c +++ b/super-intel.c @@ -11218,11 +11218,11 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info) unsigned int sector_size = super->sector_size; unsigned long long curr_migr_unit = current_migr_unit(migr_rec); unsigned long long num_migr_units = get_num_migr_units(migr_rec); - char buffer[20]; + char buffer[SYSFS_MAX_BUF_SIZE]; int skipped_disks = 0; struct dl *dl_disk; - err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, 20); + err = sysfs_get_str(info, NULL, "array_state", (char *)buffer, sizeof(buffer)); if (err < 1) return 1; @@ -12141,9 +12141,9 @@ exit_imsm_reshape_super: static int read_completed(int fd, unsigned long long *val) { int ret; - char buf[50]; + char buf[SYSFS_MAX_BUF_SIZE]; - ret = sysfs_fd_get_str(fd, buf, 50); + ret = sysfs_fd_get_str(fd, buf, sizeof(buf)); if (ret < 0) return ret; @@ -12216,12 +12216,12 @@ int wait_for_reshape_imsm(struct mdinfo *sra, int ndata) do { int rc; - char action[20]; + char action[SYSFS_MAX_BUF_SIZE]; int timeout = 3000; sysfs_wait(fd, &timeout); if (sysfs_get_str(sra, NULL, "sync_action", - action, 20) > 0 && + action, sizeof(action)) > 0 && strncmp(action, "reshape", 7) != 0) { if (strncmp(action, "idle", 4) == 0) break; @@ -12268,7 +12268,7 @@ int check_degradation_change(struct mdinfo *info, if (sd->disk.state & (1<disk.state & (1<disk.raid_disk; if (sysfs_get_str(info, diff --git a/sysfs.c b/sysfs.c index 94d02f53a768..5fad338f2bc9 100644 --- a/sysfs.c +++ b/sysfs.c @@ -664,7 +664,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) ver[0] = 0; if (info->array.major_version == -1 && info->array.minor_version == -2) { - char buf[1024]; + char buf[SYSFS_MAX_BUF_SIZE]; strcat(strcpy(ver, "external:"), info->text_version); @@ -675,7 +675,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) * version first, and preserve the flag */ if (sysfs_get_str(info, NULL, "metadata_version", - buf, 1024) > 0) + buf, sizeof(buf)) > 0) if (strlen(buf) >= 9 && buf[9] == '-') ver[9] = '-'; @@ -966,11 +966,11 @@ int sysfs_freeze_array(struct mdinfo *sra) * return 0 if this kernel doesn't support 'frozen' * return 1 if it worked. */ - char buf[20]; + char buf[SYSFS_MAX_BUF_SIZE]; if (!sysfs_attribute_available(sra, NULL, "sync_action")) return 1; /* no sync_action == frozen */ - if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) + if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) return 0; if (strcmp(buf, "frozen\n") == 0) /* Already frozen */ From patchwork Tue Jan 16 11:24:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520719 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2435D1B7F3 for ; Tue, 16 Jan 2024 11:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nBalCUyb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404378; x=1736940378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JIrIWKZIWuRUCjMZ2VeMsudDPCxTnJRc6O7Qvqzwgyo=; b=nBalCUybOd7zIDse32FqdjREcteWrLzfIcYhUN+62NpmGywIx5ZSVVO9 dUgnr/sqKAH2lHI0/HwHANJidqdAxagiGU/5spwcATnM1wuvYOmmiMRgY spgqdTR8m0YQvrYFVjeylnsTNOVFiLJ+ukvNqEyyOmcshvWry82ZdnDEx ww7JnNs+No05QJfWU/cgDWjVIzzKGKEGoyFltHHDFy2QGC1vA+Nf7BjCC SfoUYmsuSAeX3c9YfnhaGD3L6q2mlk3PACQyQec2kMeLAtX5BbLmgd0ca AM2/z5MILor5TW1XUfVvBBDwIl+L7hQlhhVl9ddSaT/6++I7Qncmfu/Yo A==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307332" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307332" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:26:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111767" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:26:16 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 5/8] Replace "none" with macro Date: Tue, 16 Jan 2024 12:24:31 +0100 Message-Id: <20240116112434.30705-6-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 String "none" is used many times throughout the code. Replace "none" strings with predefined macro. Add str_is_none() for comparing strings with "none". Replace str(n)cmp calls with function. Signed-off-by: Mateusz Kusiak --- Assemble.c | 3 +-- Build.c | 4 ++-- Create.c | 2 +- Grow.c | 15 +++++++-------- Incremental.c | 2 +- Manage.c | 2 +- config.c | 2 +- maps.c | 4 ++-- mdadm.c | 7 +++---- mdadm.h | 16 ++++++++++++++++ monitor.c | 4 ++-- super-intel.c | 4 ++-- sysfs.c | 4 ++-- util.c | 2 +- 14 files changed, 42 insertions(+), 29 deletions(-) diff --git a/Assemble.c b/Assemble.c index 61e8cd17e332..9951b268aa06 100644 --- a/Assemble.c +++ b/Assemble.c @@ -2025,8 +2025,7 @@ int assemble_container_content(struct supertype *st, int mdfd, if (dev) continue; /* Don't want this one any more */ - if (sysfs_set_str(sra, dev2, "slot", "none") < 0 && - errno == EBUSY) { + if (sysfs_set_str(sra, dev2, "slot", STR_COMMON_NONE) < 0 && errno == EBUSY) { pr_err("Cannot remove old device %s: not updating %s\n", dev2->sys_name, sra->sys_name); sysfs_free(sra); return 1; diff --git a/Build.c b/Build.c index 8d6f6f582104..2155e76ae3d4 100644 --- a/Build.c +++ b/Build.c @@ -83,7 +83,7 @@ int Build(char *mddev, struct mddev_dev *devlist, } mddev = chosen_name; - map_update(&map, fd2devnm(mdfd), "none", uuid, chosen_name); + map_update(&map, fd2devnm(mdfd), STR_COMMON_NONE, uuid, chosen_name); map_unlock(&map); array.level = s->level; @@ -113,7 +113,7 @@ int Build(char *mddev, struct mddev_dev *devlist, goto abort; } - if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0) + if (s->bitmap_file && str_is_none(s->bitmap_file) == true) s->bitmap_file = NULL; if (s->bitmap_file && s->level <= 0) { pr_err("bitmaps not meaningful with level %s\n", diff --git a/Create.c b/Create.c index ea6a4745f38a..99bf879af6f5 100644 --- a/Create.c +++ b/Create.c @@ -938,7 +938,7 @@ int Create(struct supertype *st, char *mddev, pr_err("automatically enabling write-intent bitmap on large array\n"); s->bitmap_file = "internal"; } - if (s->bitmap_file && strcmp(s->bitmap_file, "none") == 0) + if (s->bitmap_file && str_is_none(s->bitmap_file) == true) s->bitmap_file = NULL; if (s->consistency_policy == CONSISTENCY_POLICY_PPL && diff --git a/Grow.c b/Grow.c index 8ca8ee781d1b..f95dae82ef0d 100644 --- a/Grow.c +++ b/Grow.c @@ -309,7 +309,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) return 1; } if (bmf.pathname[0]) { - if (strcmp(s->bitmap_file,"none") == 0) { + if (str_is_none(s->bitmap_file) == true) { if (ioctl(fd, SET_BITMAP_FILE, -1) != 0) { pr_err("failed to remove bitmap %s\n", bmf.pathname); @@ -325,7 +325,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) return 1; } if (array.state & (1 << MD_SB_BITMAP_PRESENT)) { - if (strcmp(s->bitmap_file, "none")==0) { + if (str_is_none(s->bitmap_file) == true) { array.state &= ~(1 << MD_SB_BITMAP_PRESENT); if (md_set_array_info(fd, &array) != 0) { if (array.state & (1 << MD_SB_CLUSTERED)) @@ -340,7 +340,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s) return 1; } - if (strcmp(s->bitmap_file, "none") == 0) { + if (str_is_none(s->bitmap_file) == true) { pr_err("no bitmap found on %s\n", devname); return 1; } @@ -1067,7 +1067,7 @@ int remove_disks_for_takeover(struct supertype *st, remaining = sd->next; sysfs_set_str(sra, sd, "state", "faulty"); - sysfs_set_str(sra, sd, "slot", "none"); + sysfs_set_str(sra, sd, "slot", STR_COMMON_NONE); /* for external metadata disks should be removed in mdmon */ if (!st->ss->external) sysfs_set_str(sra, sd, "state", "remove"); @@ -2145,8 +2145,7 @@ size_change_error: * a backport has been arranged. */ if (sra == NULL || - sysfs_set_str(sra, NULL, "resync_start", - "none") < 0) + sysfs_set_str(sra, NULL, "resync_start", STR_COMMON_NONE) < 0) pr_err("--assume-clean not supported with --grow on this kernel\n"); } md_get_array_info(fd, &array); @@ -4159,8 +4158,8 @@ check_progress: * it was just a device failure that leaves us degraded but * functioning. */ - if (sysfs_get_str(info, NULL, "reshape_position", buf, - sizeof(buf)) < 0 || strncmp(buf, "none", 4) != 0) { + if (sysfs_get_str(info, NULL, "reshape_position", buf, sizeof(buf)) < 0 || + str_is_none(buf) == false) { /* The abort might only be temporary. Wait up to 10 * seconds for fd to contain a valid number again. */ diff --git a/Incremental.c b/Incremental.c index ca76a8a34727..2f5d8c729b12 100644 --- a/Incremental.c +++ b/Incremental.c @@ -670,7 +670,7 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra, continue; if (d->disk.raid_disk > -1) - sysfs_set_str(sra, d, "slot", "none"); + sysfs_set_str(sra, d, "slot", STR_COMMON_NONE); if (sysfs_set_str(sra, d, "state", "remove") == 0) if (verbose >= 0) pr_err("removing old device %s from %s\n", diff --git a/Manage.c b/Manage.c index 02ada689e02a..c89e7f545ce2 100644 --- a/Manage.c +++ b/Manage.c @@ -401,7 +401,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry) unsigned long long max_completed; sysfs_get_ll(mdi, NULL, "reshape_position", &curr); sysfs_fd_get_str(scfd, buf, sizeof(buf)); - if (strncmp(buf, "none", 4) == 0) { + if (str_is_none(buf) == true) { /* Either reshape has aborted, or hasn't * quite started yet. Wait a bit and * check 'sync_action' to see. diff --git a/config.c b/config.c index 450880e3c35a..888ecd38c374 100644 --- a/config.c +++ b/config.c @@ -878,7 +878,7 @@ void load_conffile(void) dl_add(list, dl_strdup("partitions")); devline(list); free_line(list); - } else if (strcmp(conffile, "none") != 0) { + } else if (str_is_none(conffile) == false) { f = fopen(conffile, "r"); /* Debian chose to relocate mdadm.conf into /etc/mdadm/. * To allow Debian users to compile from clean source and still diff --git a/maps.c b/maps.c index b586679acc74..17f8b54dc40f 100644 --- a/maps.c +++ b/maps.c @@ -137,14 +137,14 @@ mapping_t faultylayout[] = { { "clear", ClearErrors}, { "flush", ClearFaults}, - { "none", ClearErrors}, + { STR_COMMON_NONE, ClearErrors}, { "default", ClearErrors}, { NULL, UnSet } }; mapping_t consistency_policies[] = { { "unknown", CONSISTENCY_POLICY_UNKNOWN}, - { "none", CONSISTENCY_POLICY_NONE}, + { STR_COMMON_NONE, CONSISTENCY_POLICY_NONE}, { "resync", CONSISTENCY_POLICY_RESYNC}, { "bitmap", CONSISTENCY_POLICY_BITMAP}, { "journal", CONSISTENCY_POLICY_JOURNAL}, diff --git a/mdadm.c b/mdadm.c index 22d1c53bba06..fa5350061104 100644 --- a/mdadm.c +++ b/mdadm.c @@ -1105,7 +1105,7 @@ int main(int argc, char *argv[]) exit(2); } if (strcmp(optarg, "internal") == 0 || - strcmp(optarg, "none") == 0 || + str_is_none(optarg) == true || strchr(optarg, '/') != NULL) { s.bitmap_file = optarg; continue; @@ -1240,13 +1240,12 @@ int main(int argc, char *argv[]) pr_err("PPL consistency policy is only supported for RAID level 5.\n"); exit(2); } else if (s.consistency_policy == CONSISTENCY_POLICY_BITMAP && - (!s.bitmap_file || - strcmp(s.bitmap_file, "none") == 0)) { + (!s.bitmap_file || str_is_none(s.bitmap_file) == true)) { pr_err("--bitmap is required for consistency policy: %s\n", map_num_s(consistency_policies, s.consistency_policy)); exit(2); } else if (s.bitmap_file && - strcmp(s.bitmap_file, "none") != 0 && + str_is_none(s.bitmap_file) == false && s.consistency_policy != CONSISTENCY_POLICY_BITMAP && s.consistency_policy != CONSISTENCY_POLICY_JOURNAL) { pr_err("--bitmap is not compatible with consistency policy: %s\n", diff --git a/mdadm.h b/mdadm.h index d159b92a67ef..95d51e0579ce 100644 --- a/mdadm.h +++ b/mdadm.h @@ -2025,3 +2025,19 @@ static inline int is_container(const int level) return 1; return 0; } + +#define STR_COMMON_NONE "none" + +/** + * str_is_none() - check if @str starts with "none". + * @str: string + * + * return: + * true if string starts with "none", false otherwise. + */ +static inline bool str_is_none(char *str) +{ + if (strncmp(str, STR_COMMON_NONE, 4) == 0) + return true; + return false; +} diff --git a/monitor.c b/monitor.c index 6b5b4501a0b9..be0bec785080 100644 --- a/monitor.c +++ b/monitor.c @@ -89,7 +89,7 @@ static void read_resync_start(int fd, unsigned long long *v) dprintf("Failed to read resync_start (%d)\n", fd); return; } - if (strncmp(buf, "none", 4) == 0) + if (str_is_none(buf) == true) *v = MaxSector; else *v = strtoull(buf, NULL, 10); @@ -578,7 +578,7 @@ static int read_and_act(struct active_array *a, fd_set *fds) * Reshape will restart from last checkpoint. */ if (sysfs_get_str(&a->info, NULL, "reshape_position", buf, sizeof(buf)) >= 0) - if (strncmp(buf, "none", 4) == 0) + if (str_is_none(buf) == true) a->last_checkpoint = a->info.component_size; write_checkpoint = true; diff --git a/super-intel.c b/super-intel.c index e13e6bbc4ae9..b4cea60f060a 100644 --- a/super-intel.c +++ b/super-intel.c @@ -1825,7 +1825,7 @@ static void print_imsm_dev(struct intel_super *super, printf("\n"); printf(" Failed disk : "); if (map->failed_disk_num == 0xff) - printf("none"); + printf(STR_COMMON_NONE); else printf("%i", map->failed_disk_num); printf("\n"); @@ -12148,7 +12148,7 @@ static int read_completed(int fd, unsigned long long *val) return ret; ret = COMPLETED_OK; - if (strncmp(buf, "none", 4) == 0) { + if (str_is_none(buf) == true) { ret = COMPLETED_NONE; } else if (strncmp(buf, "delayed", 7) == 0) { ret = COMPLETED_DELAYED; diff --git a/sysfs.c b/sysfs.c index 5fad338f2bc9..e11b85556725 100644 --- a/sysfs.c +++ b/sysfs.c @@ -148,7 +148,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) strcpy(base, "metadata_version"); if (load_sys(fname, buf, sizeof(buf))) goto abort; - if (strncmp(buf, "none", 4) == 0) { + if (str_is_none(buf) == true) { sra->array.major_version = sra->array.minor_version = -1; strcpy(sra->text_version, ""); @@ -244,7 +244,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) goto abort; if (strncmp(buf, "file", 4) == 0) sra->bitmap_offset = 1; - else if (strncmp(buf, "none", 4) == 0) + else if (str_is_none(buf) == true) sra->bitmap_offset = 0; else if (buf[0] == '+') sra->bitmap_offset = strtol(buf+1, NULL, 10); diff --git a/util.c b/util.c index fa378ebac6ef..b145447370b3 100644 --- a/util.c +++ b/util.c @@ -1852,7 +1852,7 @@ int remove_disk(int mdfd, struct supertype *st, /* Remove the disk given by 'info' from the array */ if (st->ss->external) - rv = sysfs_set_str(sra, info, "slot", "none"); + rv = sysfs_set_str(sra, info, "slot", STR_COMMON_NONE); else rv = ioctl(mdfd, HOT_REMOVE_DISK, makedev(info->disk.major, info->disk.minor)); From patchwork Tue Jan 16 11:24:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520720 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DEC21B7F3 for ; Tue, 16 Jan 2024 11:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dRB4vGkg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404392; x=1736940392; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fCbKk0/5VH+9HxNyYjQyHY92hllY9OFiDQ9w8dW4n48=; b=dRB4vGkgwqnZUzz+mTZyrshCKCCCqKABtBWJKPWvaLlEqpuClFV5x/R8 OspJOMGGd6LWtEZSXitsW2IkvD7SWjarKZ933oRmUy1s1kI7KrBtwXLsO 3uQDUNRy3CHqpM8wLaFotVpSlmRxnIBGKeCAMMCtePDUsMjTcEKHaPn/v 0sLXnso2Kb6IY9bYNgrdFPIXHrPzdBSu8+EqMdDnXEfXJeqKxTJqJsyRx gsiNi4tecMfnHesOin/UkngISHSzInMEh8U90InKCo3zihx4p6ikzK8J+ rhmHR5thUaweEMmF6nU/eUWKyzc6K7+GSBmyMcWh4/cG7LjrlZTgxiIQo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307388" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307388" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:26:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111896" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:26:30 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 6/8] super-intel: Remove inaccessible code Date: Tue, 16 Jan 2024 12:24:32 +0100 Message-Id: <20240116112434.30705-7-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Remove inaccessible "if" statement from imsm_set_array_state(). Signed-off-by: Mateusz Kusiak --- super-intel.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/super-intel.c b/super-intel.c index b4cea60f060a..a3588f2ed4c1 100644 --- a/super-intel.c +++ b/super-intel.c @@ -8738,23 +8738,6 @@ static int imsm_set_array_state(struct active_array *a, int consistent) /* still reshaping, maybe update vol_curr_migr_unit */ goto mark_checkpoint; } else { - if (a->last_checkpoint == 0 && a->prev_action == reshape) { - /* for some reason we aborted the reshape. - * - * disable automatic metadata rollback - * user action is required to recover process - */ - if (0) { - struct imsm_map *map2 = - get_imsm_map(dev, MAP_1); - dev->vol.migr_state = 0; - set_migr_type(dev, 0); - set_vol_curr_migr_unit(dev, 0); - memcpy(map, map2, - sizeof_imsm_map(map2)); - super->updates_pending++; - } - } if (a->last_checkpoint >= a->info.component_size) { unsigned long long array_blocks; int used_disks; From patchwork Tue Jan 16 11:24:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520721 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A5D21B7F3 for ; Tue, 16 Jan 2024 11:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AXgccyfG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404406; x=1736940406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bPqdCBNCtFJ6rYiCOTKYqNDBlaXmmDRJ76b5eSdNank=; b=AXgccyfGco1Tdy8RUAwT3pBH9LkfRUGkSpQuXn+v1EQTnY9JYt7MreUR +LP3i+EmPJZXGH3UaBegTtSG0al4D3ZAAmpNP4RSRwsvswvE8Cg4NYbBo 0wP4SPtUkqM0mYajfjvlQ9Xw+HuMmt5GDK6DK8zkeVQXfl3Na3B+XzwYl fUDEicIjTRYOGGohTSIXfjXHhyyPAengxrgovGEJdwjmGQjWK079YCe6m s/IXbdJmZH7JssTDqN4DGS0FGTBZyhrrLuRmOzqbQ5WmOb2WoPZMzxR7B Ad8QxKhj0uq0ZI4Ho6mjQLbmIfGVpfz9LKOpRfi+4AWj9MCMQhk69kHfB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307406" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307406" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:26:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26111964" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:26:45 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 7/8] Grow: Move update_tail assign to Grow_reshape() Date: Tue, 16 Jan 2024 12:24:33 +0100 Message-Id: <20240116112434.30705-8-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Due to e919fb0af245 ("FIX: Enable metadata updates for raid0") code can't enter super-intel.c:3415, resulting in checkpoint not being saved to metadata for second volume in matrix raid array. This results in checkpoint being stuck at last value for the first volume. Move st->update_tail to Grow_reshape() so it is assigned for each volume. Signed-off-by: Mateusz Kusiak --- Grow.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Grow.c b/Grow.c index f95dae82ef0d..5498e54fec11 100644 --- a/Grow.c +++ b/Grow.c @@ -2085,9 +2085,10 @@ int Grow_reshape(char *devname, int fd, if (!mdmon_running(st->container_devnm)) start_mdmon(st->container_devnm); ping_monitor(container); - if (mdmon_running(st->container_devnm) && - st->update_tail == NULL) - st->update_tail = &st->updates; + if (mdmon_running(st->container_devnm) == false) { + pr_err("No mdmon found. Grow cannot continue.\n"); + goto release; + } } if (s->size == MAX_SIZE) @@ -3048,6 +3049,8 @@ static int reshape_array(char *container, int fd, char *devname, dprintf("Cannot get array information.\n"); goto release; } + if (st->update_tail == NULL) + st->update_tail = &st->updates; if (array.level == 0 && info->component_size == 0) { get_dev_size(fd, NULL, &array_size); info->component_size = array_size / array.raid_disks; @@ -5152,9 +5155,7 @@ int Grow_continue_command(char *devname, int fd, start_mdmon(container); ping_monitor(container); - if (mdmon_running(container)) - st->update_tail = &st->updates; - else { + if (mdmon_running(container) == false) { pr_err("No mdmon found. Grow cannot continue.\n"); ret_val = 1; goto Grow_continue_command_exit; From patchwork Tue Jan 16 11:24:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Kusiak X-Patchwork-Id: 13520722 X-Patchwork-Delegate: mariusz.tkaczyk@linux.intel.com Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE2D91B7F3 for ; Tue, 16 Jan 2024 11:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fkgfpF2U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705404425; x=1736940425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4YvIB23pE5Y+Im/dLTsi/yzbQXtu1VxBAtZNBJaSx3I=; b=fkgfpF2UN7jM7KUKmP7CsCKaqgDr0TitDEfZZe8QC5JCmOJ+viAaZKzB hBmT2h6jAYYD2yf5z4Oq7kroSOscRoogrdQsl03jhY741R7uiSgTTgOoq 5zTJHgxWYhZCPil07KyawyXTY4q0pwYzBhzmoSiiWfW5WBk8g4KDGEBZ3 lQ2bK6DUNIZlJk6UnCRoUqqj7ZbA+9TUuI3ZL3FZhAqlg37M9QMwr+wMl M0oYQjhkZnWIh0nHEB54jHigocf6A+G7xFWMU0tdtmlZMlmYQ8fey8WLQ gd6M/+wqWNzazFMRbtgdu0TTKUJkXmKF7n/FWPU275DKE1d6c6A8Jvjwp Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10954"; a="21307444" X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="21307444" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2024 03:27:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,199,1701158400"; d="scan'208";a="26112020" Received: from patodeveloperka.igk.intel.com ([10.102.109.29]) by fmviesa001.fm.intel.com with ESMTP; 16 Jan 2024 03:27:00 -0800 From: Mateusz Kusiak To: linux-raid@vger.kernel.org Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com Subject: [PATCH 8/8] Add understanding output section in man Date: Tue, 16 Jan 2024 12:24:34 +0100 Message-Id: <20240116112434.30705-9-mateusz.kusiak@intel.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240116112434.30705-1-mateusz.kusiak@intel.com> References: <20240116112434.30705-1-mateusz.kusiak@intel.com> Precedence: bulk X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add new section in man for explaining mdadm outputs. Describe checkpoint entry. Signed-off-by: Mateusz Kusiak --- mdadm.8.in | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mdadm.8.in b/mdadm.8.in index b7159509f74d..7c8959be8810 100644 --- a/mdadm.8.in +++ b/mdadm.8.in @@ -3197,7 +3197,7 @@ environment. This can be useful for testing or for disaster recovery. You should be aware that interoperability may be compromised by setting this value. -These change can also be suppressed by adding +These change can also be suppressed by adding .B mdadm.imsm.test=1 to the kernel command line. This makes it easy to test IMSM code in a virtual machine that doesn't have IMSM virtual hardware. @@ -3464,6 +3464,25 @@ is any string. These names are supported by since version 3.3 provided they are enabled in .IR mdadm.conf . +.SH UNDERSTANDING OUTPUT + +.TP +EXAMINE + +.TP +.B checkpoint +Checkpoint value is reported when array is performing some action including +resync, recovery or reshape. Checkpoints allow resuming action from certain +point if it was interrupted. + +Checkpoint is reported as combination of two values: current migration unit +and number of blocks per unit. By multiplying those values and dividing by +array size checkpoint progress percentage can be obtained in relation to +current progress reported in /proc/mdstat. Checkpoint is also related to (and +sometimes based on) sysfs entry sync_completed but depending on action units +may differ. Even if units are the same, it should not be expected that +checkpoint and sync_completed will be exact match nor updated simultaneously. + .SH NOTE .I mdadm was previously known as