Blame SOURCES/0025-imsm-block-changing-slots-during-creation.patch

cd8c44
From 9a7df595bbe360132cb37c8b39aa1fd9ac24b43f Mon Sep 17 00:00:00 2001
cd8c44
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
cd8c44
Date: Tue, 21 Jun 2022 00:10:43 +0800
2b63fb
Subject: [PATCH 25/83] imsm: block changing slots during creation
cd8c44
cd8c44
If user specifies drives for array creation, then slot order across
cd8c44
volumes is not preserved.
cd8c44
Ideally, it should be checked in validate_geometry() but it is not
cd8c44
possible in current implementation (order is determined later).
cd8c44
Add verification in add_to_super_imsm_volume() and throw error if
cd8c44
mismatch is detected.
cd8c44
IMSM allows to use only same members within container.
cd8c44
This is not hardware dependency but metadata limitation.
cd8c44
Therefore, 09-imsm-overlap test is removed. Testing it is pointless.
cd8c44
After this patch, creation in this scenario is blocked. Offset
cd8c44
verification is covered in other tests.
cd8c44
cd8c44
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
cd8c44
Acked-by: Coly Li <colyli@suse.de>
cd8c44
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
cd8c44
---
cd8c44
 super-intel.c        | 33 ++++++++++++++++++++++-----------
cd8c44
 tests/09imsm-overlap | 28 ----------------------------
cd8c44
 2 files changed, 22 insertions(+), 39 deletions(-)
cd8c44
 delete mode 100644 tests/09imsm-overlap
cd8c44
cd8c44
diff --git a/super-intel.c b/super-intel.c
cd8c44
index deef7c87..8ffe485c 100644
cd8c44
--- a/super-intel.c
cd8c44
+++ b/super-intel.c
cd8c44
@@ -5789,6 +5789,10 @@ static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
cd8c44
 	struct imsm_map *map;
cd8c44
 	struct dl *dl, *df;
cd8c44
 	int slot;
cd8c44
+	int autolayout = 0;
cd8c44
+
cd8c44
+	if (!is_fd_valid(fd))
cd8c44
+		autolayout = 1;
cd8c44
 
cd8c44
 	dev = get_imsm_dev(super, super->current_vol);
cd8c44
 	map = get_imsm_map(dev, MAP_0);
cd8c44
@@ -5799,25 +5803,32 @@ static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk,
cd8c44
 		return 1;
cd8c44
 	}
cd8c44
 
cd8c44
-	if (!is_fd_valid(fd)) {
cd8c44
-		/* we're doing autolayout so grab the pre-marked (in
cd8c44
-		 * validate_geometry) raid_disk
cd8c44
-		 */
cd8c44
-		for (dl = super->disks; dl; dl = dl->next)
cd8c44
+	for (dl = super->disks; dl ; dl = dl->next) {
cd8c44
+		if (autolayout) {
cd8c44
 			if (dl->raiddisk == dk->raid_disk)
cd8c44
 				break;
cd8c44
-	} else {
cd8c44
-		for (dl = super->disks; dl ; dl = dl->next)
cd8c44
-			if (dl->major == dk->major &&
cd8c44
-			    dl->minor == dk->minor)
cd8c44
-				break;
cd8c44
+		} else if (dl->major == dk->major && dl->minor == dk->minor)
cd8c44
+			break;
cd8c44
 	}
cd8c44
 
cd8c44
 	if (!dl) {
cd8c44
-		pr_err("%s is not a member of the same container\n", devname);
cd8c44
+		if (!autolayout)
cd8c44
+			pr_err("%s is not a member of the same container.\n",
cd8c44
+			       devname);
cd8c44
 		return 1;
cd8c44
 	}
cd8c44
 
cd8c44
+	if (!autolayout && super->current_vol > 0) {
cd8c44
+		int _slot = get_disk_slot_in_dev(super, 0, dl->index);
cd8c44
+
cd8c44
+		if (_slot != dk->raid_disk) {
cd8c44
+			pr_err("Member %s is in %d slot for the first volume, but is in %d slot for a new volume.\n",
cd8c44
+			       dl->devname, _slot, dk->raid_disk);
cd8c44
+			pr_err("Raid members are in different order than for the first volume, aborting.\n");
cd8c44
+			return 1;
cd8c44
+		}
cd8c44
+	}
cd8c44
+
cd8c44
 	if (mpb->num_disks == 0)
cd8c44
 		if (!get_dev_sector_size(dl->fd, dl->devname,
cd8c44
 					 &super->sector_size))
cd8c44
diff --git a/tests/09imsm-overlap b/tests/09imsm-overlap
cd8c44
deleted file mode 100644
cd8c44
index ff5d2093..00000000
cd8c44
--- a/tests/09imsm-overlap
cd8c44
+++ /dev/null
cd8c44
@@ -1,28 +0,0 @@
cd8c44
-
cd8c44
-. tests/env-imsm-template
cd8c44
-
cd8c44
-# create raid arrays with varying degress of overlap
cd8c44
-mdadm -CR $container -e imsm -n 6 $dev0 $dev1 $dev2 $dev3 $dev4 $dev5
cd8c44
-imsm_check container 6
cd8c44
-
cd8c44
-size=1024
cd8c44
-level=1
cd8c44
-num_disks=2
cd8c44
-mdadm -CR $member0 $dev0 $dev1 -n $num_disks -l $level -z $size
cd8c44
-mdadm -CR $member1 $dev1 $dev2 -n $num_disks -l $level -z $size
cd8c44
-mdadm -CR $member2 $dev2 $dev3 -n $num_disks -l $level -z $size
cd8c44
-mdadm -CR $member3 $dev3 $dev4 -n $num_disks -l $level -z $size
cd8c44
-mdadm -CR $member4 $dev4 $dev5 -n $num_disks -l $level -z $size
cd8c44
-
cd8c44
-udevadm settle
cd8c44
-
cd8c44
-offset=0
cd8c44
-imsm_check member $member0 $num_disks $level $size 1024 $offset
cd8c44
-offset=$((offset+size+4096))
cd8c44
-imsm_check member $member1 $num_disks $level $size 1024 $offset
cd8c44
-offset=$((offset+size+4096))
cd8c44
-imsm_check member $member2 $num_disks $level $size 1024 $offset
cd8c44
-offset=$((offset+size+4096))
cd8c44
-imsm_check member $member3 $num_disks $level $size 1024 $offset
cd8c44
-offset=$((offset+size+4096))
cd8c44
-imsm_check member $member4 $num_disks $level $size 1024 $offset
cd8c44
-- 
2b63fb
2.38.1
cd8c44