Blame SOURCES/0022-mdadm-super1-restore-commit-45a87c2f31335-to-fix-clu.patch

cd8c44
From 63902857b98c37c8ac4b837bb01d006b327a4532 Mon Sep 17 00:00:00 2001
cd8c44
From: Heming Zhao <heming.zhao@suse.com>
cd8c44
Date: Tue, 21 Jun 2022 00:10:40 +0800
2b63fb
Subject: [PATCH 22/83] mdadm/super1: restore commit 45a87c2f31335 to fix
cd8c44
 clustered slot issue
cd8c44
cd8c44
Commit 9d67f6496c71 ("mdadm:check the nodes when operate clustered
cd8c44
array") modified assignment logic for st->nodes in write_bitmap1(),
cd8c44
which introduced bitmap slot issue:
cd8c44
cd8c44
load_super1 didn't set up supertype.nodes, which made spare disk only
cd8c44
have one slot info. Then it triggered kernel md_bitmap_load_sb to get
cd8c44
wrong bitmap slot data.
cd8c44
cd8c44
For fixing this issue, there are two methods:
cd8c44
cd8c44
1> revert the related code of commit 9d67f6496c71. and restore the code
cd8c44
   from former commit 45a87c2f31335 ("super1: add more checks for
cd8c44
   NodeNumUpdate option").
cd8c44
   st->nodes value would be 0 & 1 under current code logic. i.e.
cd8c44
   When adding a spare disk, there is no place to init st->nodes, and
cd8c44
   the value is ZERO.
cd8c44
cd8c44
2> keep 9d67f6496c71, add additional ->nodes handling in load_super1(),
cd8c44
   let load_super1 to set st->nodes when bitmap is BITMAP_MAJOR_CLUSTERED.
cd8c44
   Under current mdadm code logic, load_super1 will be called many
cd8c44
   times, any new code in load_super1 will cost mdadm running more time.
cd8c44
   And more reason is I prefer as much as possible to limit clustered
cd8c44
   code spreading in every corner.
cd8c44
cd8c44
So I used method <1> to fix this issue.
cd8c44
cd8c44
How to trigger:
cd8c44
cd8c44
dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sda
cd8c44
dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sdb
cd8c44
dd if=/dev/zero bs=1M count=1 oflag=direct of=/dev/sdc
cd8c44
mdadm -C /dev/md0 -b clustered -e 1.2 -n 2 -l mirror /dev/sda /dev/sdb
cd8c44
mdadm -a /dev/md0 /dev/sdc
cd8c44
mdadm /dev/md0 --fail /dev/sda
cd8c44
mdadm /dev/md0 --remove /dev/sda
cd8c44
mdadm -Ss
cd8c44
mdadm -A /dev/md0 /dev/sdb /dev/sdc
cd8c44
cd8c44
the output of current "mdadm -X /dev/sdc":
cd8c44
(there should be (by default) 4 slot info for correct output)
cd8c44
```
cd8c44
        Filename : /dev/sdc
cd8c44
           Magic : 6d746962
cd8c44
         Version : 5
cd8c44
            UUID : a74642f8:a6b1fba8:58e1f8db:cfe7b082
cd8c44
          Events : 29
cd8c44
  Events Cleared : 0
cd8c44
           State : OK
cd8c44
       Chunksize : 64 MB
cd8c44
          Daemon : 5s flush period
cd8c44
      Write Mode : Normal
cd8c44
       Sync Size : 306176 (299.00 MiB 313.52 MB)
cd8c44
          Bitmap : 5 bits (chunks), 5 dirty (100.0%)
cd8c44
```
cd8c44
cd8c44
And mdadm later operations will trigger kernel output error message:
cd8c44
(triggered by "mdadm -A /dev/md0 /dev/sdb /dev/sdc")
cd8c44
```
cd8c44
kernel: md0: invalid bitmap file superblock: bad magic
cd8c44
kernel: md_bitmap_copy_from_slot can't get bitmap from slot 1
cd8c44
kernel: md-cluster: Could not gather bitmaps from slot 1
cd8c44
kernel: md0: invalid bitmap file superblock: bad magic
cd8c44
kernel: md_bitmap_copy_from_slot can't get bitmap from slot 2
cd8c44
kernel: md-cluster: Could not gather bitmaps from slot 2
cd8c44
kernel: md0: invalid bitmap file superblock: bad magic
cd8c44
kernel: md_bitmap_copy_from_slot can't get bitmap from slot 3
cd8c44
kernel: md-cluster: Could not gather bitmaps from slot 3
cd8c44
kernel: md-cluster: failed to gather all resyn infos
cd8c44
kernel: md0: detected capacity change from 0 to 612352
cd8c44
```
cd8c44
cd8c44
Acked-by: Coly Li <colyli@suse.de>
cd8c44
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
cd8c44
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
cd8c44
---
cd8c44
 super1.c | 12 +++++++++++-
cd8c44
 1 file changed, 11 insertions(+), 1 deletion(-)
cd8c44
cd8c44
diff --git a/super1.c b/super1.c
cd8c44
index e3e2f954..3a0c69fd 100644
cd8c44
--- a/super1.c
cd8c44
+++ b/super1.c
cd8c44
@@ -2674,7 +2674,17 @@ static int write_bitmap1(struct supertype *st, int fd, enum bitmap_update update
cd8c44
 		}
cd8c44
 
cd8c44
 		if (bms->version == BITMAP_MAJOR_CLUSTERED) {
cd8c44
-			if (__cpu_to_le32(st->nodes) < bms->nodes) {
cd8c44
+			if (st->nodes == 1) {
cd8c44
+				/* the parameter for nodes is not valid */
cd8c44
+				pr_err("Warning: cluster-md at least needs two nodes\n");
cd8c44
+				return -EINVAL;
cd8c44
+			} else if (st->nodes == 0) {
cd8c44
+				/*
cd8c44
+				 * parameter "--nodes" is not specified, (eg, add a disk to
cd8c44
+				 * clustered raid)
cd8c44
+				 */
cd8c44
+				break;
cd8c44
+			} else if (__cpu_to_le32(st->nodes) < bms->nodes) {
cd8c44
 				/*
cd8c44
 				 * Since the nodes num is not increased, no
cd8c44
 				 * need to check the space enough or not,
cd8c44
-- 
2b63fb
2.38.1
cd8c44