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

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