From eec7eb2eaf2ee51075347cbc9439f210cedc54b6 Mon Sep 17 00:00:00 2001 From: zhangjian Date: Mon, 17 Mar 2025 02:13:48 +0000 Subject: [PATCH] super1 clear extra flags when initializing metadata --- ...tra-flags-when-initializing-metadata.patch | 72 +++++++++++++++++++ mdadm.spec | 6 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 0037-super1-Clear-extra-flags-when-initializing-metadata.patch diff --git a/0037-super1-Clear-extra-flags-when-initializing-metadata.patch b/0037-super1-Clear-extra-flags-when-initializing-metadata.patch new file mode 100644 index 0000000..7036427 --- /dev/null +++ b/0037-super1-Clear-extra-flags-when-initializing-metadata.patch @@ -0,0 +1,72 @@ +From cd095a93a350ca71ff54ec217c3d936a9c2c6a84 Mon Sep 17 00:00:00 2001 +From: Wu Guanghao +Date: Tue, 11 Mar 2025 03:11:55 +0000 +Subject: [PATCH] super1: Clear extra flags when initializing metadata + +When adding a disk to a RAID1 array, the metadata is read from the +existing member disks for sync. However, only the bad_blocks flag are +copied, the bad_blocks records are not copied, so the bad_blocks +records are all zeros. The kernel function super_1_load() detects +bad_blocks flag and reads the bad_blocks record, then sets the bad +block using badblocks_set(). + +After the kernel commit 1726c7746783 (badblocks: improve badblocks_set() +for multiple ranges handling) if the length of a bad_blocks record is 0, +it will return a failure. Therefore the device addition will fail. + +So when adding a new disk, some flags cannot be sync and need to be clead. + +Signed-off-by: Wu Guanghao +--- + super1.c | 3 +++ + tests/05r1-add-badblocks | 24 ++++++++++++++++++++++++ + 2 files changed, 27 insertions(+) + create mode 100644 tests/05r1-add-badblocks + +diff --git a/super1.c b/super1.c +index 06bc145..f5ad4fe 100644 +--- a/super1.c ++++ b/super1.c +@@ -1889,6 +1889,9 @@ static int write_init_super1(struct supertype *st) + unsigned long long data_offset; + long bm_offset; + ++ /* Clear extra flags */ ++ sb->feature_map &= ~__cpu_to_le32(MD_FEATURE_BAD_BLOCKS | MD_FEATURE_REPLACEMENT); ++ + for (di = st->info; di; di = di->next) { + if (di->disk.state & (1 << MD_DISK_JOURNAL)) + sb->feature_map |= __cpu_to_le32(MD_FEATURE_JOURNAL); +diff --git a/tests/05r1-add-badblocks b/tests/05r1-add-badblocks +new file mode 100644 +index 0000000..6192327 +--- /dev/null ++++ b/tests/05r1-add-badblocks +@@ -0,0 +1,24 @@ ++# ++# create a raid1 with a drive and set badblocks for the drive. ++# add a new drive does not cause an error. ++# ++ ++# create raid1 ++mdadm -CR $md0 -l1 -n2 -e1.0 $dev1 missing ++testdev $md0 1 $mdsize1a 64 ++sleep 3 ++ ++# set badblocks for the drive ++dev1_name=$(basename $dev1) ++echo "100 100" > /sys/block/md0/md/dev-$dev1_name/bad_blocks ++echo "write_error" > /sys/block/md0/md/dev-$dev1_name/state ++ ++# write badblocks to metadata ++dd if=/dev/zero of=$md0 bs=512 count=200 oflag=direct ++ ++# re-add and recovery ++mdadm $md0 -a $dev2 ++check recovery ++ ++mdadm -S $md0 ++ +-- +2.33.0 + diff --git a/mdadm.spec b/mdadm.spec index bcbf245..01ff29c 100644 --- a/mdadm.spec +++ b/mdadm.spec @@ -1,6 +1,6 @@ Name: mdadm Version: 4.1 -Release: 13 +Release: 14 Summary: The software RAID arrays user manage tools License: GPLv2+ URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/ @@ -46,6 +46,7 @@ Patch33: 0033-mdadm-block-creation-with-long-names.patch Patch34: 0034-Fix-null-pointer-for-incremental-in-mdadm.patch Patch35: 0035-Fix-race-of-mdadm-add-and-mdadm-incremental.patch Patch36: 0036-fix-memory-leak-in-file-mdadm.patch +Patch37: 0037-super1-Clear-extra-flags-when-initializing-metadata.patch BuildRequires: systemd gcc binutils Requires(post): systemd coreutils @@ -111,6 +112,9 @@ install -d -m 710 %{buildroot}/var/run/mdadm/ %{_mandir}/man*/* %changelog +* Mon Mar 17 2025 wuguanghao - 4.1-14 +- super1 clear extra flags when initializing metadata + * Mon Jun 24 2024 zhangyaqi - 4.1-13 - fix memory leak in file mdadm -- Gitee