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

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