Blame SOURCES/0060-mdadm-replace-container-level-checking-with-inline.patch

c3a0e9
From 6f2af6a48c541f207cb727a31fb86de2cd04fc21 Mon Sep 17 00:00:00 2001
c3a0e9
From: Kinga Tanska <kinga.tanska@intel.com>
c3a0e9
Date: Fri, 2 Sep 2022 08:49:23 +0200
c3a0e9
Subject: [PATCH 60/63] mdadm: replace container level checking with inline
c3a0e9
c3a0e9
To unify all containers checks in code, is_container() function is
c3a0e9
added and propagated.
c3a0e9
c3a0e9
Signed-off-by: Kinga Tanska <kinga.tanska@intel.com>
c3a0e9
Acked-by: Coly Li <colyli@suse.de>
c3a0e9
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
c3a0e9
---
c3a0e9
 Assemble.c    |  7 +++----
c3a0e9
 Create.c      |  6 +++---
c3a0e9
 Grow.c        |  6 +++---
c3a0e9
 Incremental.c |  4 ++--
c3a0e9
 mdadm.h       | 14 ++++++++++++++
c3a0e9
 super-ddf.c   |  6 +++---
c3a0e9
 super-intel.c |  4 ++--
c3a0e9
 super0.c      |  2 +-
c3a0e9
 super1.c      |  2 +-
c3a0e9
 sysfs.c       |  2 +-
c3a0e9
 10 files changed, 33 insertions(+), 20 deletions(-)
c3a0e9
c3a0e9
diff --git a/Assemble.c b/Assemble.c
c3a0e9
index 1dd82a8c..8b0af0c9 100644
c3a0e9
--- a/Assemble.c
c3a0e9
+++ b/Assemble.c
c3a0e9
@@ -1120,7 +1120,7 @@ static int start_array(int mdfd,
c3a0e9
 			       i/2, mddev);
c3a0e9
 	}
c3a0e9
 
c3a0e9
-	if (content->array.level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(content->array.level)) {
c3a0e9
 		sysfs_rules_apply(mddev, content);
c3a0e9
 		if (c->verbose >= 0) {
c3a0e9
 			pr_err("Container %s has been assembled with %d drive%s",
c3a0e9
@@ -1549,8 +1549,7 @@ try_again:
c3a0e9
 			 */
c3a0e9
 			trustworthy = LOCAL;
c3a0e9
 
c3a0e9
-		if (name[0] == 0 &&
c3a0e9
-		    content->array.level == LEVEL_CONTAINER) {
c3a0e9
+		if (!name[0] && is_container(content->array.level)) {
c3a0e9
 			name = content->text_version;
c3a0e9
 			trustworthy = METADATA;
c3a0e9
 		}
c3a0e9
@@ -1809,7 +1808,7 @@ try_again:
c3a0e9
 		}
c3a0e9
 #endif
c3a0e9
 	}
c3a0e9
-	if (c->force && !clean && content->array.level != LEVEL_CONTAINER &&
c3a0e9
+	if (c->force && !clean && !is_container(content->array.level) &&
c3a0e9
 	    !enough(content->array.level, content->array.raid_disks,
c3a0e9
 		    content->array.layout, clean, avail)) {
c3a0e9
 		change += st->ss->update_super(st, content, "force-array",
c3a0e9
diff --git a/Create.c b/Create.c
c3a0e9
index e06ec2ae..953e7372 100644
c3a0e9
--- a/Create.c
c3a0e9
+++ b/Create.c
c3a0e9
@@ -487,7 +487,7 @@ int Create(struct supertype *st, char *mddev,
c3a0e9
 			    st->minor_version >= 1)
c3a0e9
 				/* metadata at front */
c3a0e9
 				warn |= check_partitions(fd, dname, 0, 0);
c3a0e9
-			else if (s->level == 1 || s->level == LEVEL_CONTAINER ||
c3a0e9
+			else if (s->level == 1 || is_container(s->level) ||
c3a0e9
 				 (s->level == 0 && s->raiddisks == 1))
c3a0e9
 				/* partitions could be meaningful */
c3a0e9
 				warn |= check_partitions(fd, dname, freesize*2, s->size*2);
c3a0e9
@@ -997,7 +997,7 @@ int Create(struct supertype *st, char *mddev,
c3a0e9
 			 * again returns container info.
c3a0e9
 			 */
c3a0e9
 			st->ss->getinfo_super(st, &info_new, NULL);
c3a0e9
-			if (st->ss->external && s->level != LEVEL_CONTAINER &&
c3a0e9
+			if (st->ss->external && !is_container(s->level) &&
c3a0e9
 			    !same_uuid(info_new.uuid, info.uuid, 0)) {
c3a0e9
 				map_update(&map, fd2devnm(mdfd),
c3a0e9
 					   info_new.text_version,
c3a0e9
@@ -1040,7 +1040,7 @@ int Create(struct supertype *st, char *mddev,
c3a0e9
 	map_unlock(&map);
c3a0e9
 	free(infos);
c3a0e9
 
c3a0e9
-	if (s->level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(s->level)) {
c3a0e9
 		/* No need to start.  But we should signal udev to
c3a0e9
 		 * create links */
c3a0e9
 		sysfs_uevent(&info, "change");
c3a0e9
diff --git a/Grow.c b/Grow.c
c3a0e9
index 0f07a894..e362403a 100644
c3a0e9
--- a/Grow.c
c3a0e9
+++ b/Grow.c
c3a0e9
@@ -2175,7 +2175,7 @@ size_change_error:
c3a0e9
 					devname, s->size);
c3a0e9
 		}
c3a0e9
 		changed = 1;
c3a0e9
-	} else if (array.level != LEVEL_CONTAINER) {
c3a0e9
+	} else if (!is_container(array.level)) {
c3a0e9
 		s->size = get_component_size(fd)/2;
c3a0e9
 		if (s->size == 0)
c3a0e9
 			s->size = array.size;
c3a0e9
@@ -2231,7 +2231,7 @@ size_change_error:
c3a0e9
 	info.component_size = s->size*2;
c3a0e9
 	info.new_level = s->level;
c3a0e9
 	info.new_chunk = s->chunk * 1024;
c3a0e9
-	if (info.array.level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(info.array.level)) {
c3a0e9
 		info.delta_disks = UnSet;
c3a0e9
 		info.array.raid_disks = s->raiddisks;
c3a0e9
 	} else if (s->raiddisks)
c3a0e9
@@ -2344,7 +2344,7 @@ size_change_error:
c3a0e9
 				printf("layout for %s set to %d\n",
c3a0e9
 				       devname, array.layout);
c3a0e9
 		}
c3a0e9
-	} else if (array.level == LEVEL_CONTAINER) {
c3a0e9
+	} else if (is_container(array.level)) {
c3a0e9
 		/* This change is to be applied to every array in the
c3a0e9
 		 * container.  This is only needed when the metadata imposes
c3a0e9
 		 * restraints of the various arrays in the container.
c3a0e9
diff --git a/Incremental.c b/Incremental.c
c3a0e9
index 4d0cd9d6..5a5f4c4c 100644
c3a0e9
--- a/Incremental.c
c3a0e9
+++ b/Incremental.c
c3a0e9
@@ -244,7 +244,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
c3a0e9
 		c->autof = ci->autof;
c3a0e9
 
c3a0e9
 	name_to_use = info.name;
c3a0e9
-	if (name_to_use[0] == 0 && info.array.level == LEVEL_CONTAINER) {
c3a0e9
+	if (name_to_use[0] == 0 && is_container(info.array.level)) {
c3a0e9
 		name_to_use = info.text_version;
c3a0e9
 		trustworthy = METADATA;
c3a0e9
 	}
c3a0e9
@@ -472,7 +472,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
c3a0e9
 
c3a0e9
 	/* 7/ Is there enough devices to possibly start the array? */
c3a0e9
 	/* 7a/ if not, finish with success. */
c3a0e9
-	if (info.array.level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(info.array.level)) {
c3a0e9
 		char devnm[32];
c3a0e9
 		/* Try to assemble within the container */
c3a0e9
 		sysfs_uevent(sra, "change");
c3a0e9
diff --git a/mdadm.h b/mdadm.h
c3a0e9
index 941a5f38..3673494e 100644
c3a0e9
--- a/mdadm.h
c3a0e9
+++ b/mdadm.h
c3a0e9
@@ -1924,3 +1924,17 @@ enum r0layout {
c3a0e9
  * This is true for native and DDF, IMSM allows 16.
c3a0e9
  */
c3a0e9
 #define MD_NAME_MAX 32
c3a0e9
+
c3a0e9
+/**
c3a0e9
+ * is_container() - check if @level is &LEVEL_CONTAINER
c3a0e9
+ * @level: level value
c3a0e9
+ *
c3a0e9
+ * return:
c3a0e9
+ * 1 if level is equal to &LEVEL_CONTAINER, 0 otherwise.
c3a0e9
+ */
c3a0e9
+static inline int is_container(const int level)
c3a0e9
+{
c3a0e9
+	if (level == LEVEL_CONTAINER)
c3a0e9
+		return 1;
c3a0e9
+	return 0;
c3a0e9
+}
c3a0e9
diff --git a/super-ddf.c b/super-ddf.c
c3a0e9
index 949e7d15..9d1e3b94 100644
c3a0e9
--- a/super-ddf.c
c3a0e9
+++ b/super-ddf.c
c3a0e9
@@ -3325,7 +3325,7 @@ validate_geometry_ddf_container(struct supertype *st,
c3a0e9
 	int fd;
c3a0e9
 	unsigned long long ldsize;
c3a0e9
 
c3a0e9
-	if (level != LEVEL_CONTAINER)
c3a0e9
+	if (!is_container(level))
c3a0e9
 		return 0;
c3a0e9
 	if (!dev)
c3a0e9
 		return 1;
c3a0e9
@@ -3371,7 +3371,7 @@ static int validate_geometry_ddf(struct supertype *st,
c3a0e9
 
c3a0e9
 	if (level == LEVEL_NONE)
c3a0e9
 		level = LEVEL_CONTAINER;
c3a0e9
-	if (level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(level)) {
c3a0e9
 		/* Must be a fresh device to add to a container */
c3a0e9
 		return validate_geometry_ddf_container(st, level, raiddisks,
c3a0e9
 						       data_offset, dev,
c3a0e9
@@ -3488,7 +3488,7 @@ static int validate_geometry_ddf_bvd(struct supertype *st,
c3a0e9
 	struct dl *dl;
c3a0e9
 	unsigned long long maxsize;
c3a0e9
 	/* ddf/bvd supports lots of things, but not containers */
c3a0e9
-	if (level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(level)) {
c3a0e9
 		if (verbose)
c3a0e9
 			pr_err("DDF cannot create a container within an container\n");
c3a0e9
 		return 0;
c3a0e9
diff --git a/super-intel.c b/super-intel.c
c3a0e9
index 4d82af3d..b0565610 100644
c3a0e9
--- a/super-intel.c
c3a0e9
+++ b/super-intel.c
c3a0e9
@@ -6727,7 +6727,7 @@ static int validate_geometry_imsm_container(struct supertype *st, int level,
c3a0e9
 	struct intel_super *super = NULL;
c3a0e9
 	int rv = 0;
c3a0e9
 
c3a0e9
-	if (level != LEVEL_CONTAINER)
c3a0e9
+	if (!is_container(level))
c3a0e9
 		return 0;
c3a0e9
 	if (!dev)
c3a0e9
 		return 1;
c3a0e9
@@ -7692,7 +7692,7 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
c3a0e9
 	 * if given unused devices create a container
c3a0e9
 	 * if given given devices in a container create a member volume
c3a0e9
 	 */
c3a0e9
-	if (level == LEVEL_CONTAINER)
c3a0e9
+	if (is_container(level))
c3a0e9
 		/* Must be a fresh device to add to a container */
c3a0e9
 		return validate_geometry_imsm_container(st, level, raiddisks,
c3a0e9
 							data_offset, dev,
c3a0e9
diff --git a/super0.c b/super0.c
c3a0e9
index 37f595ed..93876e2e 100644
c3a0e9
--- a/super0.c
c3a0e9
+++ b/super0.c
c3a0e9
@@ -1273,7 +1273,7 @@ static int validate_geometry0(struct supertype *st, int level,
c3a0e9
 	if (get_linux_version() < 3001000)
c3a0e9
 		tbmax = 2;
c3a0e9
 
c3a0e9
-	if (level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(level)) {
c3a0e9
 		if (verbose)
c3a0e9
 			pr_err("0.90 metadata does not support containers\n");
c3a0e9
 		return 0;
c3a0e9
diff --git a/super1.c b/super1.c
c3a0e9
index 58345e68..0b505a7e 100644
c3a0e9
--- a/super1.c
c3a0e9
+++ b/super1.c
c3a0e9
@@ -2830,7 +2830,7 @@ static int validate_geometry1(struct supertype *st, int level,
c3a0e9
 	unsigned long long overhead;
c3a0e9
 	int fd;
c3a0e9
 
c3a0e9
-	if (level == LEVEL_CONTAINER) {
c3a0e9
+	if (is_container(level)) {
c3a0e9
 		if (verbose)
c3a0e9
 			pr_err("1.x metadata does not support containers\n");
c3a0e9
 		return 0;
c3a0e9
diff --git a/sysfs.c b/sysfs.c
c3a0e9
index 0d98a65f..ca1d888f 100644
c3a0e9
--- a/sysfs.c
c3a0e9
+++ b/sysfs.c
c3a0e9
@@ -763,7 +763,7 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume)
c3a0e9
 
c3a0e9
 	rv = sysfs_set_num(sra, sd, "offset", sd->data_offset);
c3a0e9
 	rv |= sysfs_set_num(sra, sd, "size", (sd->component_size+1) / 2);
c3a0e9
-	if (sra->array.level != LEVEL_CONTAINER) {
c3a0e9
+	if (!is_container(sra->array.level)) {
c3a0e9
 		if (sra->consistency_policy == CONSISTENCY_POLICY_PPL) {
c3a0e9
 			rv |= sysfs_set_num(sra, sd, "ppl_sector", sd->ppl_sector);
c3a0e9
 			rv |= sysfs_set_num(sra, sd, "ppl_size", sd->ppl_size);
c3a0e9
-- 
c3a0e9
2.38.1
c3a0e9