dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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