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

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