Blame SOURCES/0073-super-intel-refactor-the-code-for-enum.patch

91179e
From 4345e135c4c7dd04bb15bad140dfc4747f677738 Mon Sep 17 00:00:00 2001
91179e
From: Mateusz Kusiak <mateusz.kusiak@intel.com>
91179e
Date: Mon, 2 Jan 2023 09:35:21 +0100
91179e
Subject: [PATCH 73/83] super-intel: refactor the code for enum
91179e
91179e
It prepares super-intel for change context->update to enum.
91179e
91179e
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
91179e
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
91179e
---
91179e
 super-intel.c | 37 +++++++++++++++++++++++++------------
91179e
 1 file changed, 25 insertions(+), 12 deletions(-)
91179e
91179e
diff --git a/super-intel.c b/super-intel.c
91179e
index 5f93f3d3..85fb7f17 100644
91179e
--- a/super-intel.c
91179e
+++ b/super-intel.c
91179e
@@ -3930,7 +3930,8 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info,
91179e
 
91179e
 	mpb = super->anchor;
91179e
 
91179e
-	if (strcmp(update, "uuid") == 0) {
91179e
+	switch (map_name(update_options, 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
 		 * allow an explicit uuid to be given.  And it is hard to reliably
91179e
@@ -3954,10 +3955,14 @@ static int update_super_imsm(struct supertype *st, struct mdinfo *info,
91179e
 		}
91179e
 		if (rv == 0)
91179e
 			mpb->orig_family_num = info->uuid[0];
91179e
-	} else if (strcmp(update, "assemble") == 0)
91179e
+		break;
91179e
+	case UOPT_SPEC_ASSEMBLE:
91179e
 		rv = 0;
91179e
-	else
91179e
+		break;
91179e
+	default:
91179e
 		rv = -1;
91179e
+		break;
91179e
+	}
91179e
 
91179e
 	/* successful update? recompute checksum */
91179e
 	if (rv == 0)
91179e
@@ -7889,17 +7894,25 @@ static int kill_subarray_imsm(struct supertype *st, char *subarray_id)
91179e
 	return 0;
91179e
 }
91179e
 
91179e
-static int get_rwh_policy_from_update(char *update)
91179e
+/**
91179e
+ * get_rwh_policy_from_update() - Get the rwh policy for update option.
91179e
+ * @update: Update option.
91179e
+ */
91179e
+static int get_rwh_policy_from_update(enum update_opt update)
91179e
 {
91179e
-	if (strcmp(update, "ppl") == 0)
91179e
+	switch (update) {
91179e
+	case UOPT_PPL:
91179e
 		return RWH_MULTIPLE_DISTRIBUTED;
91179e
-	else if (strcmp(update, "no-ppl") == 0)
91179e
+	case UOPT_NO_PPL:
91179e
 		return RWH_MULTIPLE_OFF;
91179e
-	else if (strcmp(update, "bitmap") == 0)
91179e
+	case UOPT_BITMAP:
91179e
 		return RWH_BITMAP;
91179e
-	else if (strcmp(update, "no-bitmap") == 0)
91179e
+	case UOPT_NO_BITMAP:
91179e
 		return RWH_OFF;
91179e
-	return -1;
91179e
+	default:
91179e
+		break;
91179e
+	}
91179e
+	return UOPT_UNDEFINED;
91179e
 }
91179e
 
91179e
 static int update_subarray_imsm(struct supertype *st, char *subarray,
91179e
@@ -7909,7 +7922,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray,
91179e
 	struct intel_super *super = st->sb;
91179e
 	struct imsm_super *mpb = super->anchor;
91179e
 
91179e
-	if (strcmp(update, "name") == 0) {
91179e
+	if (map_name(update_options, update) == UOPT_NAME) {
91179e
 		char *name = ident->name;
91179e
 		char *ep;
91179e
 		int vol;
91179e
@@ -7943,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(update) != -1) {
91179e
+	} else if (get_rwh_policy_from_update(map_name(update_options, update)) != UOPT_UNDEFINED) {
91179e
 		int new_policy;
91179e
 		char *ep;
91179e
 		int vol = strtoul(subarray, &ep, 10);
91179e
@@ -7951,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(update);
91179e
+		new_policy = get_rwh_policy_from_update(map_name(update_options, update));
91179e
 
91179e
 		if (st->update_tail) {
91179e
 			struct imsm_update_rwh_policy *u = xmalloc(sizeof(*u));
91179e
-- 
91179e
2.38.1
91179e