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

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