linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: jes@trained-monkey.org
Cc: linux-raid@vger.kernel.org, colyli@suse.de, xni@redhat.com
Subject: [PATCH 3/4] mdadm: define is_devname_ignore()
Date: Thu, 23 Mar 2023 17:50:16 +0100	[thread overview]
Message-ID: <20230323165017.27121-4-mariusz.tkaczyk@linux.intel.com> (raw)
In-Reply-To: <20230323165017.27121-1-mariusz.tkaczyk@linux.intel.com>

Use function instead of direct checks across code.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 Incremental.c |  6 ++----
 Monitor.c     |  2 +-
 config.c      | 16 ++++++++++++++--
 mdadm.c       |  5 ++---
 mdadm.h       |  1 +
 5 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index b3dc499a..ebbbd4db 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -202,8 +202,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
 	if (!match && rv == 2)
 		goto out;
 
-	if (match && match->devname &&
-	    strcasecmp(match->devname, "<ignore>") == 0) {
+	if (match && match->devname && is_devname_ignore(match->devname) == true) {
 		if (c->verbose >= 0)
 			pr_err("array containing %s is explicitly ignored by mdadm.conf\n",
 				devname);
@@ -1564,8 +1563,7 @@ static int Incremental_container(struct supertype *st, char *devname,
 				break;
 			}
 
-			if (match && match->devname &&
-			    strcasecmp(match->devname, "<ignore>") == 0) {
+			if (match && match->devname && is_devname_ignore(match->devname) == true) {
 				if (c->verbose > 0)
 					pr_err("array %s/%s is explicitly ignored by mdadm.conf\n",
 					       match->container, match->member);
diff --git a/Monitor.c b/Monitor.c
index 3273f2fb..ce8d5802 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -250,7 +250,7 @@ int Monitor(struct mddev_dev *devlist,
 
 			if (mdlist->devname == NULL)
 				continue;
-			if (strcasecmp(mdlist->devname, "<ignore>") == 0)
+			if (is_devname_ignore(mdlist->devname) == true)
 				continue;
 			if (!is_mddev(mdlist->devname))
 				continue;
diff --git a/config.c b/config.c
index f44cc1d3..e61c0496 100644
--- a/config.c
+++ b/config.c
@@ -119,6 +119,18 @@ int match_keyword(char *word)
 	return -1;
 }
 
+/**
+ * is_devname_ignore() - check if &devname is a special "<ignore>" keyword.
+ */
+bool is_devname_ignore(char *devname)
+{
+	static const char keyword[] = "<ignore>";
+
+	if (strcasecmp(devname, keyword) == 0)
+		return true;
+	return false;
+}
+
 /**
  * ident_init() - Set defaults.
  * @ident: ident pointer, not NULL.
@@ -404,7 +416,7 @@ void arrayline(char *line)
 			 *  <ignore>
 			 *  or anything that doesn't start '/' or '<'
 			 */
-			if (strcasecmp(w, "<ignore>") == 0 ||
+			if (is_devname_ignore(w) == true ||
 			    strncmp(w, DEV_MD_DIR, DEV_MD_DIR_LEN) == 0 ||
 			    (w[0] != '/' && w[0] != '<') ||
 			    (strncmp(w, DEV_NUM_PREF, DEV_NUM_PREF_LEN) == 0 &&
@@ -571,7 +583,7 @@ void homehostline(char *line)
 	char *w;
 
 	for (w = dl_next(line); w != line; w = dl_next(w)) {
-		if (strcasecmp(w, "<ignore>") == 0)
+		if (is_devname_ignore(w) == true)
 			require_homehost = 0;
 		else if (home_host == NULL) {
 			if (strcasecmp(w, "<none>") == 0)
diff --git a/mdadm.c b/mdadm.c
index 4685ad6b..cae37177 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -154,7 +154,7 @@ int main(int argc, char *argv[])
 			continue;
 
 		case HomeHost:
-			if (strcasecmp(optarg, "<ignore>") == 0)
+			if (is_devname_ignore(optarg) == true)
 				c.require_homehost = 0;
 			else
 				c.homehost = optarg;
@@ -1749,8 +1749,7 @@ static int scan_assemble(struct supertype *ss,
 			int r;
 			if (a->assembled)
 				continue;
-			if (a->devname &&
-			    strcasecmp(a->devname, "<ignore>") == 0)
+			if (a->devname && is_devname_ignore(a->devname) == true)
 				continue;
 
 			r = Assemble(ss, a->devname,
diff --git a/mdadm.h b/mdadm.h
index 63ec88a0..87fd4a57 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -1648,6 +1648,7 @@ extern void print_escape(char *str);
 extern int use_udev(void);
 extern unsigned long GCD(unsigned long a, unsigned long b);
 extern int conf_name_is_free(char *name);
+extern bool is_devname_ignore(char *devname);
 extern int conf_verify_devnames(struct mddev_ident *array_list);
 extern int devname_matches(char *name, char *match);
 extern struct mddev_ident *conf_match(struct supertype *st,
-- 
2.26.2


  parent reply	other threads:[~2023-03-23 16:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 16:50 [PATCH 0/4] Few config related refactors Mariusz Tkaczyk
2023-03-23 16:50 ` [PATCH 1/4] mdadm: define DEV_MD_DIR Mariusz Tkaczyk
2023-03-23 16:50 ` [PATCH 2/4] mdadm: define DEV_NUM_PREF Mariusz Tkaczyk
2023-03-23 16:50 ` Mariusz Tkaczyk [this message]
2023-03-23 16:50 ` [PATCH 4/4] mdadm: numbered names verification Mariusz Tkaczyk
2023-03-24  2:13 ` [PATCH 0/4] Few config related refactors Xiao Ni
2023-04-20 10:46   ` Mariusz Tkaczyk
2023-05-08 20:26 ` Jes Sorensen

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=20230323165017.27121-4-mariusz.tkaczyk@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=colyli@suse.de \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=xni@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).