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

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