]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Replace "none" with macro
authorMateusz Kusiak <mateusz.kusiak@intel.com>
Thu, 18 Jan 2024 10:28:41 +0000 (11:28 +0100)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Wed, 24 Jan 2024 15:15:04 +0000 (16:15 +0100)
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 <mateusz.kusiak@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
14 files changed:
Assemble.c
Build.c
Create.c
Grow.c
Incremental.c
Manage.c
config.c
maps.c
mdadm.c
mdadm.h
monitor.c
super-intel.c
sysfs.c
util.c

index 0879c2ed547308ff745cf01004c9b5e32a31d676..9d042055ad4eca47bcf90a784350a56349090ab6 100644 (file)
@@ -2015,8 +2015,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 657ab315de62607ac92993053661ee1df132a2c1..1fbf8596a9dd3d8786e411bfe4f1ce99cc83c62a 100644 (file)
--- a/Build.c
+++ b/Build.c
@@ -82,7 +82,7 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
                return 1;
        }
 
-       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;
@@ -111,7 +111,7 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
                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",
index ddd1a79bf3934c37703419367fabc93389c61788..8082f54a8fdcbe5ec94109ffdac5588240ef180f 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -938,7 +938,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
                        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 8ca8ee781d1b4dd5f24c0ae717b7da64e5b519db..f95dae82ef0da85ea125147ce7bd747bea31c253 100644 (file)
--- 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.
                 */
index 52e396237e64f54ef331e806bc9e845b849f7e59..6cbc164a27b93bc3ad48bcd23626713489a513b9 100644 (file)
@@ -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",
index d66dc7b8af91b7869baab96382e06f307a468dd8..30302ac833f2f872144bb2497016e0c929c34e7a 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -402,7 +402,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.
index 5f12a1f8641c340f49764566cae9f4a8f072d408..9a04cae85f52740b380d3fa89892ee29f364afe8 100644 (file)
--- a/config.c
+++ b/config.c
@@ -998,7 +998,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 b586679acc74dd9428eac44ad62cb69a003a1ad4..17f8b54dc40ffd3c657c41472c516c6a405840e1 100644 (file)
--- 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 62f981dfbd15f0efea2a065552c983c007f2205c..3f1912884d49cf64cf1ae41ac0a5b29532314589 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1099,7 +1099,7 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                        if (strcmp(optarg, "internal") == 0 ||
-                           strcmp(optarg, "none") == 0 ||
+                           strcmp(optarg, STR_COMMON_NONE) == 0 ||
                            strchr(optarg, '/') != NULL) {
                                s.bitmap_file = optarg;
                                continue;
@@ -1234,13 +1234,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 46692730801e58ef7a6ce7c23b9c0f8ca7307b67..709b6104c4014146abc8301f2e31110758885db9 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -2027,3 +2027,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, sizeof(STR_COMMON_NONE) - 1) == 0)
+               return true;
+       return false;
+}
index f54d07b24f591822df81135f731b1368d0c2350a..4acec6783e6e27f2f25599856a3724e9945bc942 100644 (file)
--- 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);
@@ -600,7 +600,7 @@ static int read_and_act(struct active_array *a, fd_set *fds)
                                          "reshape_position",
                                          buf,
                                          sizeof(buf)) >= 0) &&
-                            strncmp(buf, "none", 4) == 0)
+                            str_is_none(buf) == true)
                                a->last_checkpoint = a->info.component_size;
                }
                a->container->ss->set_array_state(a, a->curr_state <= clean);
index c3e832686578a03d2f20a1aed09019a39946d9a5..01fcc6b3bfb6ee02eab5d53b6004d063578a430a 100644 (file)
@@ -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");
@@ -12086,7 +12086,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 0dc7badfc4b721ccebae1e7db688dca753141401..f95ef7013e845b62791f499acd08d5f0abe315fd 100644 (file)
--- 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 fa378ebac6ef3b7e8b15cbc2509105e26b4c1bd0..b145447370b364d66c10f65c94282008e0a2aab7 100644 (file)
--- 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));