]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Change update to enum in update_super and update_subarray
authorMateusz Kusiak <mateusz.kusiak@intel.com>
Mon, 2 Jan 2023 08:35:22 +0000 (09:35 +0100)
committerJes Sorensen <jes@trained-monkey.org>
Wed, 4 Jan 2023 15:20:58 +0000 (10:20 -0500)
Use already existing enum, change update_super and update_subarray
update to enum globally.
Refactor function references also.
Remove code specific options from update_options.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Assemble.c
Examine.c
Grow.c
Manage.c
maps.c
mdadm.h
super-intel.c
super0.c
super1.c

index 8b0af0c907cf624a426722d05a9fde5964ec6b7e..dba910cd387434cdcb21b08e4e67e6cbbd06da6b 100644 (file)
@@ -695,12 +695,16 @@ static int load_devices(struct devs *devices, char *devmap,
                        } else if (strcmp(c->update, "revert-reshape") == 0 &&
                                   c->invalid_backup)
                                err = tst->ss->update_super(tst, content,
-                                                           "revert-reshape-nobackup",
+                                                           UOPT_SPEC_REVERT_RESHAPE_NOBACKUP,
                                                            devname, c->verbose,
                                                            ident->uuid_set,
                                                            c->homehost);
                        else
-                               err = tst->ss->update_super(tst, content, c->update,
+                               /*
+                                * Mapping is temporary, will be removed in this patchset
+                                */
+                               err = tst->ss->update_super(tst, content,
+                                                           map_name(update_options, c->update),
                                                            devname, c->verbose,
                                                            ident->uuid_set,
                                                            c->homehost);
@@ -960,7 +964,7 @@ static int force_array(struct mdinfo *content,
                        continue;
                }
                content->events = devices[most_recent].i.events;
-               tst->ss->update_super(tst, content, "force-one",
+               tst->ss->update_super(tst, content, UOPT_SPEC_FORCE_ONE,
                                      devices[chosen_drive].devname, c->verbose,
                                      0, NULL);
 
@@ -1788,7 +1792,7 @@ try_again:
                if (!(devices[j].i.array.state & 1))
                        clean = 0;
 
-               if (st->ss->update_super(st, &devices[j].i, "assemble", NULL,
+               if (st->ss->update_super(st, &devices[j].i, UOPT_SPEC_ASSEMBLE, NULL,
                                         c->verbose, 0, NULL)) {
                        if (c->force) {
                                if (c->verbose >= 0)
@@ -1811,7 +1815,7 @@ try_again:
        if (c->force && !clean && !is_container(content->array.level) &&
            !enough(content->array.level, content->array.raid_disks,
                    content->array.layout, clean, avail)) {
-               change += st->ss->update_super(st, content, "force-array",
+               change += st->ss->update_super(st, content, UOPT_SPEC_FORCE_ARRAY,
                                               devices[chosen_drive].devname, c->verbose,
                                               0, NULL);
                was_forced = 1;
index 9574a3ccafecaaa648e0de25d70432f25deb0f10..c9605a60dfe476927d3a4dac1ca2912f04c3fa22 100644 (file)
--- a/Examine.c
+++ b/Examine.c
@@ -117,7 +117,7 @@ int Examine(struct mddev_dev *devlist,
                }
 
                if (c->SparcAdjust)
-                       st->ss->update_super(st, NULL, "sparc2.2",
+                       st->ss->update_super(st, NULL, UOPT_SPARC22,
                                             devlist->devname, 0, 0, NULL);
                /* Ok, its good enough to try, though the checksum could be wrong */
 
diff --git a/Grow.c b/Grow.c
index b73ec2aebb9f257548b3ebe2aacb5d3d3e080351..82d5d2ea6426615ee1642a8122566bd0ab6cccc5 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -196,7 +196,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        info.disk.minor = minor(rdev);
        info.disk.raid_disk = d;
        info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
-       if (st->ss->update_super(st, &info, "linear-grow-new", newdev,
+       if (st->ss->update_super(st, &info, UOPT_SPEC_LINEAR_GROW_NEW, newdev,
                                 0, 0, NULL) != 0) {
                pr_err("Preparing new metadata failed on %s\n", newdev);
                close(nfd);
@@ -254,7 +254,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                info.array.active_disks = nd+1;
                info.array.working_disks = nd+1;
 
-               if (st->ss->update_super(st, &info, "linear-grow-update", dv,
+               if (st->ss->update_super(st, &info, UOPT_SPEC_LINEAR_GROW_UPDATE, dv,
                                     0, 0, NULL) != 0) {
                        pr_err("Updating metadata failed on %s\n", dv);
                        close(fd2);
@@ -668,7 +668,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
                                        goto free_info;
                                }
 
-                               ret = st->ss->update_super(st, sra, "ppl",
+                               ret = st->ss->update_super(st, sra, UOPT_PPL,
                                                           devname,
                                                           c->verbose, 0, NULL);
                                if (ret) {
@@ -4950,7 +4950,8 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist,
                                continue;
                        st->ss->getinfo_super(st, &dinfo, NULL);
                        dinfo.reshape_progress = info->reshape_progress;
-                       st->ss->update_super(st, &dinfo, "_reshape_progress",
+                       st->ss->update_super(st, &dinfo,
+                                            UOPT_SPEC__RESHAPE_PROGRESS,
                                             NULL,0, 0, NULL);
                        st->ss->store_super(st, fdlist[j]);
                        st->ss->free_super(st);
index 5a9ea3165ee3a51cf8afb9cbd48a9d8c78c7e032..87b8aa0c47ae7880c813e96fdc65b905a8362a03 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -605,6 +605,7 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
        struct mdinfo mdi;
        int duuid[4];
        int ouuid[4];
+       enum update_opt update_enum = map_name(update_options, update);
 
        dev_st->ss->getinfo_super(dev_st, &mdi, NULL);
        dev_st->ss->uuid_from_super(dev_st, ouuid);
@@ -666,23 +667,23 @@ int attempt_re_add(int fd, int tfd, struct mddev_dev *dv,
 
                        if (dv->writemostly == FlagSet)
                                rv = dev_st->ss->update_super(
-                                       dev_st, NULL, "writemostly",
+                                       dev_st, NULL, UOPT_SPEC_WRITEMOSTLY,
                                        devname, verbose, 0, NULL);
                        if (dv->writemostly == FlagClear)
                                rv = dev_st->ss->update_super(
-                                       dev_st, NULL, "readwrite",
+                                       dev_st, NULL, UOPT_SPEC_READWRITE,
                                        devname, verbose, 0, NULL);
                        if (dv->failfast == FlagSet)
                                rv = dev_st->ss->update_super(
-                                       dev_st, NULL, "failfast",
+                                       dev_st, NULL, UOPT_SPEC_FAILFAST,
                                        devname, verbose, 0, NULL);
                        if (dv->failfast == FlagClear)
                                rv = dev_st->ss->update_super(
-                                       dev_st, NULL, "nofailfast",
+                                       dev_st, NULL, UOPT_SPEC_NOFAILFAST,
                                        devname, verbose, 0, NULL);
                        if (update)
                                rv = dev_st->ss->update_super(
-                                       dev_st, NULL, update,
+                                       dev_st, NULL, update_enum,
                                        devname, verbose, 0, NULL);
                        if (rv == 0)
                                rv = dev_st->ss->store_super(dev_st, tfd);
@@ -1731,6 +1732,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
        struct supertype supertype, *st = &supertype;
        int fd, rv = 2;
        struct mdinfo *info = NULL;
+       enum update_opt update_enum = map_name(update_options, update);
 
        memset(st, 0, sizeof(*st));
 
@@ -1762,7 +1764,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident
                goto free_super;
        }
 
-       rv = st->ss->update_subarray(st, subarray, update, ident);
+       rv = st->ss->update_subarray(st, subarray, update_enum, ident);
 
        if (rv) {
                if (verbose >= 0)
diff --git a/maps.c b/maps.c
index c59036f18d37910b2c8d921e3e26addcf5046a80..b586679acc74dd9428eac44ad62cb69a003a1ad4 100644 (file)
--- a/maps.c
+++ b/maps.c
@@ -194,27 +194,6 @@ mapping_t update_options[] = {
        { "byteorder", UOPT_BYTEORDER },
        { "help", UOPT_HELP },
        { "?", UOPT_HELP },
-       /*
-        * Those enries are temporary and will be removed in this patchset.
-        *
-        * Before update_super:update can be changed to enum,
-        * all update_super sub-functions must be adapted first.
-        * Update options will be passed as string (as it is for now),
-        * and then mapped, so all options must be handled temporarily.
-        *
-        * Those options code specific and should not be accessible for user.
-        */
-       { "force-one", UOPT_SPEC_FORCE_ONE },
-       { "force-array", UOPT_SPEC_FORCE_ARRAY },
-       { "assemble", UOPT_SPEC_ASSEMBLE },
-       { "linear-grow-new", UOPT_SPEC_LINEAR_GROW_NEW },
-       { "linear-grow-update", UOPT_SPEC_LINEAR_GROW_UPDATE },
-       { "_reshape_progress", UOPT_SPEC__RESHAPE_PROGRESS },
-       { "writemostly", UOPT_SPEC_WRITEMOSTLY },
-       { "readwrite", UOPT_SPEC_READWRITE },
-       { "failfast", UOPT_SPEC_FAILFAST },
-       { "nofailfast", UOPT_SPEC_NOFAILFAST },
-       { "revert-reshape-nobackup", UOPT_SPEC_REVERT_RESHAPE_NOBACKUP },
        { NULL, UOPT_UNDEFINED}
 };
 
diff --git a/mdadm.h b/mdadm.h
index 31db25f561317c1f3f15f9936fad042f115a2129..5dc9439054f700852218a76212cc3c210f044442 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1011,7 +1011,7 @@ extern struct superswitch {
         *                    it will resume going in the opposite direction.
         */
        int (*update_super)(struct supertype *st, struct mdinfo *info,
-                           char *update,
+                           enum update_opt update,
                            char *devname, int verbose,
                            int uuid_set, char *homehost);
 
@@ -1137,9 +1137,15 @@ extern struct superswitch {
        /* Permit subarray's to be deleted from inactive containers */
        int (*kill_subarray)(struct supertype *st,
                             char *subarray_id); /* optional */
-       /* Permit subarray's to be modified */
+       /**
+        * update_subarray() - Permit subarray to be modified.
+        * @st: Supertype.
+        * @subarray: Subarray name.
+        * @update: Update option.
+        * @ident: Optional identifiers.
+        */
        int (*update_subarray)(struct supertype *st, char *subarray,
-                              char *update, struct mddev_ident *ident); /* optional */
+                              enum update_opt update, struct mddev_ident *ident);
        /* Check if reshape is supported for this external format.
         * st is obtained from super_by_fd() where st->subarray[0] is
         * initialized to indicate if reshape is being performed at the
index 85fb7f177602f97cd80232b06ad5bb6bdb5b4151..1f5f6eda6d22d22503214ce118e33ed0035d13e8 100644 (file)
@@ -3893,8 +3893,8 @@ struct mdinfo *getinfo_super_disks_imsm(struct supertype *st)
 }
 
 static int update_super_imsm(struct supertype *st, struct mdinfo *info,
-                            char *update, char *devname, int verbose,
-                            int uuid_set, char *homehost)
+                            enum update_opt update, char *devname,
+                            int verbose, int uuid_set, char *homehost)
 {
        /* For 'assemble' and 'force' we need to return non-zero if any
         * change was made.  For others, the return value is ignored.
@@ -3930,7 +3930,7 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info,
 
        mpb = super->anchor;
 
-       switch (map_name(update_options, update)) {
+       switch (update) {
        case UOPT_UUID:
                /* We take this to mean that the family_num should be updated.
                 * However that is much smaller than the uuid so we cannot really
@@ -6538,7 +6538,7 @@ static int validate_ppl_imsm(struct supertype *st, struct mdinfo *info,
                if (mdmon_running(st->container_devnm))
                        st->update_tail = &st->updates;
 
-               if (st->ss->update_subarray(st, subarray, "ppl", NULL)) {
+               if (st->ss->update_subarray(st, subarray, UOPT_PPL, NULL)) {
                        pr_err("Failed to update subarray %s\n",
                              subarray);
                } else {
@@ -7916,13 +7916,13 @@ static int get_rwh_policy_from_update(enum update_opt update)
 }
 
 static int update_subarray_imsm(struct supertype *st, char *subarray,
-                               char *update, struct mddev_ident *ident)
+                               enum update_opt update, struct mddev_ident *ident)
 {
        /* update the subarray currently referenced by ->current_vol */
        struct intel_super *super = st->sb;
        struct imsm_super *mpb = super->anchor;
 
-       if (map_name(update_options, update) == UOPT_NAME) {
+       if (update == UOPT_NAME) {
                char *name = ident->name;
                char *ep;
                int vol;
@@ -7956,7 +7956,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
                        }
                        super->updates_pending++;
                }
-       } else if (get_rwh_policy_from_update(map_name(update_options, update)) != UOPT_UNDEFINED) {
+       } else if (get_rwh_policy_from_update(update) != UOPT_UNDEFINED) {
                int new_policy;
                char *ep;
                int vol = strtoul(subarray, &ep, 10);
@@ -7964,7 +7964,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
                if (*ep != '\0' || vol >= super->anchor->num_raid_devs)
                        return 2;
 
-               new_policy = get_rwh_policy_from_update(map_name(update_options, update));
+               new_policy = get_rwh_policy_from_update(update);
 
                if (st->update_tail) {
                        struct imsm_update_rwh_policy *u = xmalloc(sizeof(*u));
index d9f5bff49e0a596c149c3f6ffb564d37ed8c534c..a7c5f813d926fd13f99cebb2304acb8ba83f7ea0 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -491,7 +491,7 @@ static struct mdinfo *container_content0(struct supertype *st, char *subarray)
 }
 
 static int update_super0(struct supertype *st, struct mdinfo *info,
-                        char *update,
+                        enum update_opt update,
                         char *devname, int verbose,
                         int uuid_set, char *homehost)
 {
@@ -502,20 +502,19 @@ static int update_super0(struct supertype *st, struct mdinfo *info,
        int rv = 0;
        int uuid[4];
        mdp_super_t *sb = st->sb;
-       enum update_opt update_enum = map_name(update_options, update);
 
-       if (update_enum == UOPT_HOMEHOST && homehost) {
+       if (update == UOPT_HOMEHOST && homehost) {
                /*
                 * note that 'homehost' is special as it is really
                 * a "uuid" update.
                 */
                uuid_set = 0;
-               update_enum = UOPT_UUID;
+               update = UOPT_UUID;
                info->uuid[0] = sb->set_uuid0;
                info->uuid[1] = sb->set_uuid1;
        }
 
-       switch (update_enum) {
+       switch (update) {
        case UOPT_UUID:
                if (!uuid_set && homehost) {
                        char buf[20];
index b0a97016c3f9a1c5ff8681d55f402f5d514d0bcd..f7020320eaf223307da0c95cce76593e92a781c6 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -1208,7 +1208,7 @@ static struct mdinfo *container_content1(struct supertype *st, char *subarray)
 }
 
 static int update_super1(struct supertype *st, struct mdinfo *info,
-                        char *update, char *devname, int verbose,
+                        enum update_opt update, char *devname, int verbose,
                         int uuid_set, char *homehost)
 {
        /* NOTE: for 'assemble' and 'force' we need to return non-zero
@@ -1218,15 +1218,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
        int rv = 0;
        struct mdp_superblock_1 *sb = st->sb;
        bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
-       enum update_opt update_enum = map_name(update_options, update);
 
-       if (update_enum == UOPT_HOMEHOST && homehost) {
+       if (update == UOPT_HOMEHOST && homehost) {
                /*
                 * Note that 'homehost' is special as it is really
                 * a "name" update.
                 */
                char *c;
-               update_enum = UOPT_NAME;
+               update = UOPT_NAME;
                c = strchr(sb->set_name, ':');
                if (c)
                        snprintf(info->name, sizeof(info->name), "%s", c+1);
@@ -1234,7 +1233,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                        snprintf(info->name, sizeof(info->name), "%s", sb->set_name);
        }
 
-       switch (update_enum) {
+       switch (update) {
        case UOPT_NAME: {
                int namelen;
 
@@ -1534,7 +1533,7 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
                         * If that couldn't happen, the "-nobackup" version
                         * will be used.
                         */
-                       if (update_enum == UOPT_SPEC_REVERT_RESHAPE_NOBACKUP &&
+                       if (update == UOPT_SPEC_REVERT_RESHAPE_NOBACKUP &&
                            sb->reshape_position == 0 &&
                            (__le32_to_cpu(sb->delta_disks) > 0 ||
                             (__le32_to_cpu(sb->delta_disks) == 0 &&
@@ -1618,14 +1617,14 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
        case UOPT_LAYOUT_UNSPECIFIED:
                if (__le32_to_cpu(sb->level) != 0) {
                        pr_err("%s: %s only supported for RAID0\n",
-                              devname ?: "", map_num(update_options, update_enum));
+                              devname ?: "", map_num(update_options, update));
                        rv = -1;
-               } else if (update_enum == UOPT_LAYOUT_UNSPECIFIED) {
+               } else if (update == UOPT_LAYOUT_UNSPECIFIED) {
                        sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_RAID0_LAYOUT);
                        sb->layout = 0;
                } else {
                        sb->feature_map |= __cpu_to_le32(MD_FEATURE_RAID0_LAYOUT);
-                       sb->layout = __cpu_to_le32(update_enum == UOPT_LAYOUT_ORIGINAL ? 1 : 2);
+                       sb->layout = __cpu_to_le32(update == UOPT_LAYOUT_ORIGINAL ? 1 : 2);
                }
                break;
        default: