Blame SOURCES/0024-imsm-use-same-slot-across-container.patch

c0f891
From 6d4d9ab295de165e57b5c30e044028dbffb8f297 Mon Sep 17 00:00:00 2001
c0f891
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
c0f891
Date: Tue, 21 Jun 2022 00:10:42 +0800
37f2b0
Subject: [PATCH 24/83] imsm: use same slot across container
c0f891
c0f891
Autolayout relies on drives order on super->disks list, but
c0f891
it is not quaranted by readdir() in sysfs_read(). As a result
c0f891
drive could be put in different slot in second volume.
c0f891
c0f891
Make it consistent by reffering to first volume, if exists.
c0f891
c0f891
Use enum imsm_status to unify error handling.
c0f891
c0f891
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
c0f891
Acked-by: Coly Li <colyli@suse.de>
c0f891
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
c0f891
---
c0f891
 super-intel.c | 169 ++++++++++++++++++++++++++++++++------------------
c0f891
 1 file changed, 108 insertions(+), 61 deletions(-)
c0f891
c0f891
diff --git a/super-intel.c b/super-intel.c
c0f891
index cd1f1e3d..deef7c87 100644
c0f891
--- a/super-intel.c
c0f891
+++ b/super-intel.c
c0f891
@@ -7522,11 +7522,27 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level,
c0f891
 	return 1;
c0f891
 }
c0f891
 
c0f891
-static int imsm_get_free_size(struct supertype *st, int raiddisks,
c0f891
-			 unsigned long long size, int chunk,
c0f891
-			 unsigned long long *freesize)
c0f891
+/**
c0f891
+ * imsm_get_free_size() - get the biggest, common free space from members.
c0f891
+ * @super: &intel_super pointer, not NULL.
c0f891
+ * @raiddisks: number of raid disks.
c0f891
+ * @size: requested size, could be 0 (means max size).
c0f891
+ * @chunk: requested chunk.
c0f891
+ * @freesize: pointer for returned size value.
c0f891
+ *
c0f891
+ * Return: &IMSM_STATUS_OK or &IMSM_STATUS_ERROR.
c0f891
+ *
c0f891
+ * @freesize is set to meaningful value, this can be @size, or calculated
c0f891
+ * max free size.
c0f891
+ * super->create_offset value is modified and set appropriately in
c0f891
+ * merge_extends() for further creation.
c0f891
+ */
c0f891
+static imsm_status_t imsm_get_free_size(struct intel_super *super,
c0f891
+					const int raiddisks,
c0f891
+					unsigned long long size,
c0f891
+					const int chunk,
c0f891
+					unsigned long long *freesize)
c0f891
 {
c0f891
-	struct intel_super *super = st->sb;
c0f891
 	struct imsm_super *mpb = super->anchor;
c0f891
 	struct dl *dl;
c0f891
 	int i;
c0f891
@@ -7570,12 +7586,10 @@ static int imsm_get_free_size(struct supertype *st, int raiddisks,
c0f891
 		/* chunk is in K */
c0f891
 		minsize = chunk * 2;
c0f891
 
c0f891
-	if (cnt < raiddisks ||
c0f891
-	    (super->orom && used && used != raiddisks) ||
c0f891
-	    maxsize < minsize ||
c0f891
-	    maxsize == 0) {
c0f891
+	if (cnt < raiddisks || (super->orom && used && used != raiddisks) ||
c0f891
+	    maxsize < minsize || maxsize == 0) {
c0f891
 		pr_err("not enough devices with space to create array.\n");
c0f891
-		return 0; /* No enough free spaces large enough */
c0f891
+		return IMSM_STATUS_ERROR;
c0f891
 	}
c0f891
 
c0f891
 	if (size == 0) {
c0f891
@@ -7588,37 +7602,69 @@ static int imsm_get_free_size(struct supertype *st, int raiddisks,
c0f891
 	}
c0f891
 	if (mpb->num_raid_devs > 0 && size && size != maxsize)
c0f891
 		pr_err("attempting to create a second volume with size less then remaining space.\n");
c0f891
-	cnt = 0;
c0f891
-	for (dl = super->disks; dl; dl = dl->next)
c0f891
-		if (dl->e)
c0f891
-			dl->raiddisk = cnt++;
c0f891
-
c0f891
 	*freesize = size;
c0f891
 
c0f891
 	dprintf("imsm: imsm_get_free_size() returns : %llu\n", size);
c0f891
 
c0f891
-	return 1;
c0f891
+	return IMSM_STATUS_OK;
c0f891
 }
c0f891
 
c0f891
-static int reserve_space(struct supertype *st, int raiddisks,
c0f891
-			 unsigned long long size, int chunk,
c0f891
-			 unsigned long long *freesize)
c0f891
+/**
c0f891
+ * autolayout_imsm() - automatically layout a new volume.
c0f891
+ * @super: &intel_super pointer, not NULL.
c0f891
+ * @raiddisks: number of raid disks.
c0f891
+ * @size: requested size, could be 0 (means max size).
c0f891
+ * @chunk: requested chunk.
c0f891
+ * @freesize: pointer for returned size value.
c0f891
+ *
c0f891
+ * We are being asked to automatically layout a new volume based on the current
c0f891
+ * contents of the container. If the parameters can be satisfied autolayout_imsm
c0f891
+ * will record the disks, start offset, and will return size of the volume to
c0f891
+ * be created. See imsm_get_free_size() for details.
c0f891
+ * add_to_super() and getinfo_super() detect when autolayout is in progress.
c0f891
+ * If first volume exists, slots are set consistently to it.
c0f891
+ *
c0f891
+ * Return: &IMSM_STATUS_OK on success, &IMSM_STATUS_ERROR otherwise.
c0f891
+ *
c0f891
+ * Disks are marked for creation via dl->raiddisk.
c0f891
+ */
c0f891
+static imsm_status_t autolayout_imsm(struct intel_super *super,
c0f891
+				     const int raiddisks,
c0f891
+				     unsigned long long size, const int chunk,
c0f891
+				     unsigned long long *freesize)
c0f891
 {
c0f891
-	struct intel_super *super = st->sb;
c0f891
-	struct dl *dl;
c0f891
-	int cnt;
c0f891
-	int rv = 0;
c0f891
+	int curr_slot = 0;
c0f891
+	struct dl *disk;
c0f891
+	int vol_cnt = super->anchor->num_raid_devs;
c0f891
+	imsm_status_t rv;
c0f891
 
c0f891
-	rv = imsm_get_free_size(st, raiddisks, size, chunk, freesize);
c0f891
-	if (rv) {
c0f891
-		cnt = 0;
c0f891
-		for (dl = super->disks; dl; dl = dl->next)
c0f891
-			if (dl->e)
c0f891
-				dl->raiddisk = cnt++;
c0f891
-		rv = 1;
c0f891
+	rv = imsm_get_free_size(super, raiddisks, size, chunk, freesize);
c0f891
+	if (rv != IMSM_STATUS_OK)
c0f891
+		return IMSM_STATUS_ERROR;
c0f891
+
c0f891
+	for (disk = super->disks; disk; disk = disk->next) {
c0f891
+		if (!disk->e)
c0f891
+			continue;
c0f891
+
c0f891
+		if (curr_slot == raiddisks)
c0f891
+			break;
c0f891
+
c0f891
+		if (vol_cnt == 0) {
c0f891
+			disk->raiddisk = curr_slot;
c0f891
+		} else {
c0f891
+			int _slot = get_disk_slot_in_dev(super, 0, disk->index);
c0f891
+
c0f891
+			if (_slot == -1) {
c0f891
+				pr_err("Disk %s is not used in first volume, aborting\n",
c0f891
+				       disk->devname);
c0f891
+				return IMSM_STATUS_ERROR;
c0f891
+			}
c0f891
+			disk->raiddisk = _slot;
c0f891
+		}
c0f891
+		curr_slot++;
c0f891
 	}
c0f891
 
c0f891
-	return rv;
c0f891
+	return IMSM_STATUS_OK;
c0f891
 }
c0f891
 
c0f891
 static int validate_geometry_imsm(struct supertype *st, int level, int layout,
c0f891
@@ -7654,35 +7700,35 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout,
c0f891
 	}
c0f891
 
c0f891
 	if (!dev) {
c0f891
-		if (st->sb) {
c0f891
-			struct intel_super *super = st->sb;
c0f891
-			if (!validate_geometry_imsm_orom(st->sb, level, layout,
c0f891
-							 raiddisks, chunk, size,
c0f891
-							 verbose))
c0f891
+		struct intel_super *super = st->sb;
c0f891
+
c0f891
+		/*
c0f891
+		 * Autolayout mode, st->sb and freesize must be set.
c0f891
+		 */
c0f891
+		if (!super || !freesize) {
c0f891
+			pr_vrb("freesize and superblock must be set for autolayout, aborting\n");
c0f891
+			return 1;
c0f891
+		}
c0f891
+
c0f891
+		if (!validate_geometry_imsm_orom(st->sb, level, layout,
c0f891
+						 raiddisks, chunk, size,
c0f891
+						 verbose))
c0f891
+			return 0;
c0f891
+
c0f891
+		if (super->orom) {
c0f891
+			imsm_status_t rv;
c0f891
+			int count = count_volumes(super->hba, super->orom->dpa,
c0f891
+					      verbose);
c0f891
+			if (super->orom->vphba <= count) {
c0f891
+				pr_vrb("platform does not support more than %d raid volumes.\n",
c0f891
+				       super->orom->vphba);
c0f891
 				return 0;
c0f891
-			/* we are being asked to automatically layout a
c0f891
-			 * new volume based on the current contents of
c0f891
-			 * the container.  If the the parameters can be
c0f891
-			 * satisfied reserve_space will record the disks,
c0f891
-			 * start offset, and size of the volume to be
c0f891
-			 * created.  add_to_super and getinfo_super
c0f891
-			 * detect when autolayout is in progress.
c0f891
-			 */
c0f891
-			/* assuming that freesize is always given when array is
c0f891
-			   created */
c0f891
-			if (super->orom && freesize) {
c0f891
-				int count;
c0f891
-				count = count_volumes(super->hba,
c0f891
-						      super->orom->dpa, verbose);
c0f891
-				if (super->orom->vphba <= count) {
c0f891
-					pr_vrb("platform does not support more than %d raid volumes.\n",
c0f891
-					       super->orom->vphba);
c0f891
-					return 0;
c0f891
-				}
c0f891
 			}
c0f891
-			if (freesize)
c0f891
-				return reserve_space(st, raiddisks, size,
c0f891
-						     *chunk, freesize);
c0f891
+
c0f891
+			rv = autolayout_imsm(super, raiddisks, size, *chunk,
c0f891
+					     freesize);
c0f891
+			if (rv != IMSM_STATUS_OK)
c0f891
+				return 0;
c0f891
 		}
c0f891
 		return 1;
c0f891
 	}
c0f891
@@ -11538,7 +11584,7 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st,
c0f891
 	unsigned long long current_size;
c0f891
 	unsigned long long free_size;
c0f891
 	unsigned long long max_size;
c0f891
-	int rv;
c0f891
+	imsm_status_t rv;
c0f891
 
c0f891
 	getinfo_super_imsm_volume(st, &info, NULL);
c0f891
 	if (geo->level != info.array.level && geo->level >= 0 &&
c0f891
@@ -11657,9 +11703,10 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st,
c0f891
 		}
c0f891
 		/* check the maximum available size
c0f891
 		 */
c0f891
-		rv =  imsm_get_free_size(st, dev->vol.map->num_members,
c0f891
-					 0, chunk, &free_size);
c0f891
-		if (rv == 0)
c0f891
+		rv = imsm_get_free_size(super, dev->vol.map->num_members,
c0f891
+					0, chunk, &free_size);
c0f891
+
c0f891
+		if (rv != IMSM_STATUS_OK)
c0f891
 			/* Cannot find maximum available space
c0f891
 			 */
c0f891
 			max_size = 0;
c0f891
-- 
37f2b0
2.38.1
c0f891