Blame SOURCES/0074-Change-update-to-enum-in-update_super-and-update_sub.patch

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