Blame SOURCES/0090-Detail-show-correct-raid-level-when-the-array-is-ina.patch

790dca
From 64bf4dff34301a4b44883a8bc03f7835faef121e Mon Sep 17 00:00:00 2001
790dca
From: Lidong Zhong <lidong.zhong@suse.com>
790dca
Date: Mon, 14 Sep 2020 10:52:18 +0800
790dca
Subject: [PATCH 090/108] Detail: show correct raid level when the array is
790dca
 inactive
790dca
790dca
Sometimes the raid level in the output of `mdadm -D /dev/mdX` is
790dca
misleading when the array is in inactive state. Here is a testcase for
790dca
introduction.
790dca
1\ creating a raid1 device with two disks. Specify a different hostname
790dca
rather than the real one for later verfication.
790dca
790dca
node1:~ # mdadm --create /dev/md0 --homehost TESTARRAY -o -l 1 -n 2 /dev/sdb
790dca
/dev/sdc
790dca
2\ remove one of the devices and reboot
790dca
3\ show the detail of raid1 device
790dca
790dca
node1:~ # mdadm -D /dev/md127
790dca
/dev/md127:
790dca
        Version : 1.2
790dca
     Raid Level : raid0
790dca
  Total Devices : 1
790dca
    Persistence : Superblock is persistent
790dca
          State : inactive
790dca
Working Devices : 1
790dca
790dca
You can see that the "Raid Level" in /dev/md127 is raid0 now.
790dca
After step 2\ is done, the degraded raid1 device is recognized
790dca
as a "foreign" array in 64-md-raid-assembly.rules. And thus the
790dca
timer to activate the raid1 device is not triggered. The array
790dca
level returned from GET_ARRAY_INFO ioctl is 0. And the string
790dca
shown for "Raid Level" is
790dca
str = map_num(pers, array.level);
790dca
And the definition of pers is
790dca
mapping_t pers[] = {
790dca
{ "linear", LEVEL_LINEAR},
790dca
{ "raid0", 0},
790dca
{ "0", 0}
790dca
...
790dca
So the misleading "raid0" is shown in this testcase.
790dca
790dca
Changelog:
790dca
v1: don't show "Raid Level" when array is inactive
790dca
Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
790dca
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
790dca
---
790dca
 Detail.c | 5 ++++-
790dca
 1 file changed, 4 insertions(+), 1 deletion(-)
790dca
790dca
diff --git a/Detail.c b/Detail.c
790dca
index 24eeba0..b6587c8 100644
790dca
--- a/Detail.c
790dca
+++ b/Detail.c
790dca
@@ -224,7 +224,10 @@ int Detail(char *dev, struct context *c)
790dca
 	}
790dca
 
790dca
 	/* Ok, we have some info to print... */
790dca
-	str = map_num(pers, array.level);
790dca
+	if (inactive)
790dca
+		str = map_num(pers, info->array.level);
790dca
+	else
790dca
+		str = map_num(pers, array.level);
790dca
 
790dca
 	if (c->export) {
790dca
 		if (array.raid_disks) {
790dca
-- 
790dca
2.7.5
790dca