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

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