]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: define is_devname_ignore()
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Thu, 23 Mar 2023 16:50:16 +0000 (17:50 +0100)
committerJes Sorensen <jes@trained-monkey.org>
Mon, 8 May 2023 20:23:45 +0000 (16:23 -0400)
Use function instead of direct checks across code.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Incremental.c
Monitor.c
config.c
mdadm.c
mdadm.h

index 59b850f1a24e63e86f76911ecfe6502676664f03..f13ce027da037a572e0a44896906ccb701bc13c6 100644 (file)
@@ -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);
@@ -1567,8 +1566,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);
index 3273f2fb4cc41d919050130543ef4ea7caa585fa..66175968406cbd18775ef544f8da20c8b1402715 100644 (file)
--- 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;
index f44cc1d3c33bb857f13d0aa97802ccc3d6c475b0..e61c04963fb97933e677b6616f246c2b2853a537 100644 (file)
--- 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 2296911d5e168adb55116abcdcc092e91cf4f409..076b45e030b39c3eb5bf723329c30f043b469f35 100644 (file)
--- 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 f2e70baa6cf53b7c3d018ba30342dd71e04acdc7..0932c2d3bb16e341bf0edd69eb3a50acf6f001ef 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1650,6 +1650,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,