Blame SOURCES/0055-Assemble-add-support-for-RAID0-layouts.patch

5d5466
From 027c099fd1a31fb3815e592de75d0791a22353b4 Mon Sep 17 00:00:00 2001
5d5466
From: NeilBrown <neilb@suse.de>
5d5466
Date: Mon, 4 Nov 2019 14:27:49 +1100
5d5466
Subject: [RHEL8.2 PATCH 55/61] Assemble: add support for RAID0 layouts.
5d5466
5d5466
If you have a RAID0 array with varying sized devices
5d5466
on a kernel before 5.4, you cannot assembling it on
5d5466
5.4 or later without explicitly setting the layout.
5d5466
This is now possible with
5d5466
  --update=layout-original (For 3.13 and earlier kernels)
5d5466
or
5d5466
  --update=layout-alternate (for 3.14 and later kernels)
5d5466
5d5466
Signed-off-by: NeilBrown <neilb@suse.de>
5d5466
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
5d5466
---
5d5466
 Assemble.c |  8 ++++++++
5d5466
 md.4       |  7 +++++++
5d5466
 mdadm.8.in | 17 +++++++++++++++++
5d5466
 mdadm.c    |  4 ++++
5d5466
 super1.c   | 12 +++++++++++-
5d5466
 5 files changed, 47 insertions(+), 1 deletion(-)
5d5466
5d5466
diff --git a/Assemble.c b/Assemble.c
5d5466
index b2e6914..6b5a7c8 100644
5d5466
--- a/Assemble.c
5d5466
+++ b/Assemble.c
5d5466
@@ -1031,6 +1031,11 @@ static int start_array(int mdfd,
5d5466
 				pr_err("failed to add %s to %s: %s\n",
5d5466
 				       devices[j].devname, mddev,
5d5466
 				       strerror(errno));
5d5466
+				if (errno == EINVAL && content->array.level == 0 &&
5d5466
+				    content->array.layout != 0) {
5d5466
+					cont_err("Possibly your kernel doesn't support RAID0 layouts.\n");
5d5466
+					cont_err("Please upgrade.\n");
5d5466
+				}
5d5466
 				if (i < content->array.raid_disks * 2 ||
5d5466
 				    i == bestcnt)
5d5466
 					okcnt--;
5d5466
@@ -1220,6 +1225,9 @@ static int start_array(int mdfd,
5d5466
 			return 0;
5d5466
 		}
5d5466
 		pr_err("failed to RUN_ARRAY %s: %s\n", mddev, strerror(errno));
5d5466
+		if (errno == 524 /* ENOTSUP */ &&
5d5466
+		    content->array.level == 0 && content->array.layout == 0)
5d5466
+			cont_err("Please use --update=layout-original or --update=layout-alternate\n");
5d5466
 
5d5466
 		if (!enough(content->array.level, content->array.raid_disks,
5d5466
 			    content->array.layout, 1, avail))
5d5466
diff --git a/md.4 b/md.4
5d5466
index 6fe2755..0712af2 100644
5d5466
--- a/md.4
5d5466
+++ b/md.4
5d5466
@@ -208,6 +208,13 @@ array,
5d5466
 will record the chosen layout in the metadata in a way that allows newer
5d5466
 kernels to assemble the array without needing a module parameter.
5d5466
 
5d5466
+To assemble an old array on a new kernel without using the module parameter,
5d5466
+use either the
5d5466
+.B "--update=layout-original"
5d5466
+option or the
5d5466
+.B "--update=layout-alternate"
5d5466
+option.
5d5466
+
5d5466
 .SS RAID1
5d5466
 
5d5466
 A RAID1 array is also known as a mirrored set (though mirrors tend to
5d5466
diff --git a/mdadm.8.in b/mdadm.8.in
5d5466
index fc9b6a6..6b63bb4 100644
5d5466
--- a/mdadm.8.in
5d5466
+++ b/mdadm.8.in
5d5466
@@ -1213,6 +1213,8 @@ argument given to this flag can be one of
5d5466
 .BR no\-bbl ,
5d5466
 .BR ppl ,
5d5466
 .BR no\-ppl ,
5d5466
+.BR layout\-original ,
5d5466
+.BR layout\-alternate ,
5d5466
 .BR metadata ,
5d5466
 or
5d5466
 .BR super\-minor .
5d5466
@@ -1364,6 +1366,21 @@ The
5d5466
 .B no\-ppl
5d5466
 option will disable PPL in the superblock.
5d5466
 
5d5466
+The
5d5466
+.B layout\-original
5d5466
+and
5d5466
+.B layout\-alternate
5d5466
+options are for RAID0 arrays in use before Linux 5.4.  If the array was being
5d5466
+used with Linux 3.13 or earlier, then to assemble the array on a new kernel,
5d5466
+.B \-\-update=layout\-original
5d5466
+must be given.  If the array was created and used with a kernel from Linux 3.14 to
5d5466
+Linux 5.3, then
5d5466
+.B \-\-update=layout\-alternate
5d5466
+must be given.  This only needs to be given once.  Subsequent assembly of the array
5d5466
+will happen normally.
5d5466
+For more information, see
5d5466
+.IR md (4).
5d5466
+
5d5466
 .TP
5d5466
 .BR \-\-freeze\-reshape
5d5466
 Option is intended to be used in start-up scripts during initrd boot phase.
5d5466
diff --git a/mdadm.c b/mdadm.c
5d5466
index e438f9c..256a97e 100644
5d5466
--- a/mdadm.c
5d5466
+++ b/mdadm.c
5d5466
@@ -795,6 +795,9 @@ int main(int argc, char *argv[])
5d5466
 				continue;
5d5466
 			if (strcmp(c.update, "revert-reshape") == 0)
5d5466
 				continue;
5d5466
+			if (strcmp(c.update, "layout-original") == 0 ||
5d5466
+			    strcmp(c.update, "layout-alternate") == 0)
5d5466
+				continue;
5d5466
 			if (strcmp(c.update, "byteorder") == 0) {
5d5466
 				if (ss) {
5d5466
 					pr_err("must not set metadata type with --update=byteorder.\n");
5d5466
@@ -825,6 +828,7 @@ int main(int argc, char *argv[])
5d5466
 		"     'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
5d5466
 		"     'no-bitmap', 'metadata', 'revert-reshape'\n"
5d5466
 		"     'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
5d5466
+		"     'layout-original', 'layout-alternate'\n"
5d5466
 				);
5d5466
 			exit(outf == stdout ? 0 : 2);
5d5466
 
5d5466
diff --git a/super1.c b/super1.c
5d5466
index cedbb53..e0d80be 100644
5d5466
--- a/super1.c
5d5466
+++ b/super1.c
5d5466
@@ -1550,7 +1550,17 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
5d5466
 		sb->devflags |= FailFast1;
5d5466
 	else if (strcmp(update, "nofailfast") == 0)
5d5466
 		sb->devflags &= ~FailFast1;
5d5466
-	else
5d5466
+	else if (strcmp(update, "layout-original") == 0 ||
5d5466
+		 strcmp(update, "layout-alternate") == 0) {
5d5466
+		if (__le32_to_cpu(sb->level) != 0) {
5d5466
+			pr_err("%s: %s only supported for RAID0\n",
5d5466
+			       devname?:"", update);
5d5466
+			rv = -1;
5d5466
+		} else {
5d5466
+			sb->feature_map |= __cpu_to_le32(MD_FEATURE_RAID0_LAYOUT);
5d5466
+			sb->layout = __cpu_to_le32(update[7] == 'o' ? 1 : 2);
5d5466
+		}
5d5466
+	} else
5d5466
 		rv = -1;
5d5466
 
5d5466
 	sb->sb_csum = calc_sb_1_csum(sb);
5d5466
-- 
5d5466
2.7.5
5d5466