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

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