Blame SOURCES/0096-Super1-allow-RAID0-layout-setting-to-be-removed.patch

3c4af5
From 97b51a2c2d00b79a59f2a8e37134031b0c9e0223 Mon Sep 17 00:00:00 2001
3c4af5
From: NeilBrown <neilb@suse.de>
3c4af5
Date: Wed, 14 Oct 2020 13:12:48 +1100
3c4af5
Subject: [PATCH 096/108] Super1: allow RAID0 layout setting to be removed.
3c4af5
3c4af5
Once the RAID0 layout has been set, the RAID0 array cannot be assembled
3c4af5
on an older kernel which doesn't understand layouts.
3c4af5
This is an intentional safety feature, but sometimes people need the
3c4af5
ability to roll-back to a previously working configuration.
3c4af5
3c4af5
So add "--update=layout-unspecified" to remove RAID0 layout information
3c4af5
from the superblock.
3c4af5
Running "--assemble --update=layout-unspecified" will cause the assembly
3c4af5
the fail when run on a newer kernel, but will allow it to work on
3c4af5
an older kernel.
3c4af5
3c4af5
Signed-off-by: NeilBrown <neilb@suse.de>
3c4af5
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
3c4af5
---
3c4af5
 md.4       | 13 +++++++++++++
3c4af5
 mdadm.8.in | 15 +++++++++++++--
3c4af5
 mdadm.c    |  5 +++--
3c4af5
 super1.c   |  6 +++++-
3c4af5
 4 files changed, 34 insertions(+), 5 deletions(-)
3c4af5
3c4af5
diff --git a/md.4 b/md.4
3c4af5
index aecff38..60fdd27 100644
3c4af5
--- a/md.4
3c4af5
+++ b/md.4
3c4af5
@@ -215,6 +215,19 @@ option or the
3c4af5
 .B "--update=layout-alternate"
3c4af5
 option.
3c4af5
 
3c4af5
+Once you have updated the layout you will not be able to mount the array
3c4af5
+on an older kernel.  If you need to revert to an older kernel, the
3c4af5
+layout information can be erased with the
3c4af5
+.B "--update=layout-unspecificed"
3c4af5
+option.  If you use this option to 
3c4af5
+.B --assemble
3c4af5
+while running a newer kernel, the array will NOT assemble, but the
3c4af5
+metadata will be update so that it can be assembled on an older kernel.
3c4af5
+
3c4af5
+No that setting the layout to "unspecified" removes protections against
3c4af5
+this bug, and you must be sure that the kernel you use matches the
3c4af5
+layout of the array.
3c4af5
+
3c4af5
 .SS RAID1
3c4af5
 
3c4af5
 A RAID1 array is also known as a mirrored set (though mirrors tend to
3c4af5
diff --git a/mdadm.8.in b/mdadm.8.in
3c4af5
index ab832e8..34a93a8 100644
3c4af5
--- a/mdadm.8.in
3c4af5
+++ b/mdadm.8.in
3c4af5
@@ -1213,6 +1213,7 @@ argument given to this flag can be one of
3c4af5
 .BR no\-ppl ,
3c4af5
 .BR layout\-original ,
3c4af5
 .BR layout\-alternate ,
3c4af5
+.BR layout\-unspecified ,
3c4af5
 .BR metadata ,
3c4af5
 or
3c4af5
 .BR super\-minor .
3c4af5
@@ -1368,8 +1369,9 @@ The
3c4af5
 .B layout\-original
3c4af5
 and
3c4af5
 .B layout\-alternate
3c4af5
-options are for RAID0 arrays in use before Linux 5.4.  If the array was being
3c4af5
-used with Linux 3.13 or earlier, then to assemble the array on a new kernel,
3c4af5
+options are for RAID0 arrays with non-uniform devices size that were in
3c4af5
+use before Linux 5.4.  If the array was being used with Linux 3.13 or
3c4af5
+earlier, then to assemble the array on a new kernel, 
3c4af5
 .B \-\-update=layout\-original
3c4af5
 must be given.  If the array was created and used with a kernel from Linux 3.14 to
3c4af5
 Linux 5.3, then
3c4af5
@@ -1379,6 +1381,15 @@ will happen normally.
3c4af5
 For more information, see
3c4af5
 .IR md (4).
3c4af5
 
3c4af5
+The
3c4af5
+.B layout\-unspecified
3c4af5
+option reverts the effect of
3c4af5
+.B layout\-orignal
3c4af5
+or
3c4af5
+.B layout\-alternate
3c4af5
+and allows the array to be again used on a kernel prior to Linux 5.3.
3c4af5
+This option should be used with great caution.
3c4af5
+
3c4af5
 .TP
3c4af5
 .BR \-\-freeze\-reshape
3c4af5
 Option is intended to be used in start-up scripts during initrd boot phase.
3c4af5
diff --git a/mdadm.c b/mdadm.c
3c4af5
index 1b3467f..493d70e 100644
3c4af5
--- a/mdadm.c
3c4af5
+++ b/mdadm.c
3c4af5
@@ -796,7 +796,8 @@ int main(int argc, char *argv[])
3c4af5
 			if (strcmp(c.update, "revert-reshape") == 0)
3c4af5
 				continue;
3c4af5
 			if (strcmp(c.update, "layout-original") == 0 ||
3c4af5
-			    strcmp(c.update, "layout-alternate") == 0)
3c4af5
+			    strcmp(c.update, "layout-alternate") == 0 ||
3c4af5
+			    strcmp(c.update, "layout-unspecified") == 0)
3c4af5
 				continue;
3c4af5
 			if (strcmp(c.update, "byteorder") == 0) {
3c4af5
 				if (ss) {
3c4af5
@@ -828,7 +829,7 @@ int main(int argc, char *argv[])
3c4af5
 		"     'summaries', 'homehost', 'home-cluster', 'byteorder', 'devicesize',\n"
3c4af5
 		"     'no-bitmap', 'metadata', 'revert-reshape'\n"
3c4af5
 		"     'bbl', 'no-bbl', 'force-no-bbl', 'ppl', 'no-ppl'\n"
3c4af5
-		"     'layout-original', 'layout-alternate'\n"
3c4af5
+		"     'layout-original', 'layout-alternate', 'layout-unspecified'\n"
3c4af5
 				);
3c4af5
 			exit(outf == stdout ? 0 : 2);
3c4af5
 
3c4af5
diff --git a/super1.c b/super1.c
3c4af5
index 7664883..8b0d6ff 100644
3c4af5
--- a/super1.c
3c4af5
+++ b/super1.c
3c4af5
@@ -1551,11 +1551,15 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
3c4af5
 	else if (strcmp(update, "nofailfast") == 0)
3c4af5
 		sb->devflags &= ~FailFast1;
3c4af5
 	else if (strcmp(update, "layout-original") == 0 ||
3c4af5
-		 strcmp(update, "layout-alternate") == 0) {
3c4af5
+		 strcmp(update, "layout-alternate") == 0 ||
3c4af5
+		 strcmp(update, "layout-unspecified") == 0) {
3c4af5
 		if (__le32_to_cpu(sb->level) != 0) {
3c4af5
 			pr_err("%s: %s only supported for RAID0\n",
3c4af5
 			       devname?:"", update);
3c4af5
 			rv = -1;
3c4af5
+		} else if (strcmp(update, "layout-unspecified") == 0) {
3c4af5
+			sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_RAID0_LAYOUT);
3c4af5
+			sb->layout = 0;
3c4af5
 		} else {
3c4af5
 			sb->feature_map |= __cpu_to_le32(MD_FEATURE_RAID0_LAYOUT);
3c4af5
 			sb->layout = __cpu_to_le32(update[7] == 'o' ? 1 : 2);
3c4af5
-- 
3c4af5
2.7.5
3c4af5