mdadm tests fix
cover mdadm tests fix
This is the fourth patch set which enhance/fix mdadm regression tests.
v2: fix problems for the first patches
Xiao Ni (10):
mdadm/Grow: Update new level when starting reshape mdadm/Grow: Update reshape_progress to need_back after reshape
finishes
mdadm/Grow: Can't open raid when running --grow --continue mdadm/Grow: sleep a while after removing disk in impose_level mdadm/tests: wait until level changes
mdadm/tests: 07changelevels fix
mdadm/tests: Remove 07reshape5intr.broken mdadm/tests: 07testreshape5 fix
mdadm/tests: remove 09imsm-assemble.broken mdadm/Manage: record errno
Grow.c | 39 +++++++++++++++++++++++++------ Manage.c | 8 ++++--- dev/null | 0 tests/05r6tor0 | 4 ++++ tests/07changelevels | 27 ++++++++++------------ tests/07changelevels.broken | 9 -------- tests/07reshape5intr.broken | 45 ------------------------------------ tests/07testreshape5 | 1 + tests/07testreshape5.broken | 12 ---------- tests/09imsm-assemble.broken | 6 ----- tests/func.sh | 4 ++++ 11 files changed, 58 insertions(+), 97 deletions(-) create mode 100644 dev/null delete mode 100644 tests/07changelevels.broken delete mode 100644 tests/07reshape5intr.broken delete mode 100644 tests/07testreshape5.broken delete mode 100644 tests/09imsm-assemble.broken
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v2 1/1 mdadm/Grow: Update new level when starting reshape
Reshape needs to specify a backup file when it can't update data offset of member disks. For this situation, first, it starts reshape and then it kicks off mdadm-grow-continue service which does backup job and monitors the reshape process. The service is a new process, so it needs to read superblock from member disks to get information.
But in the first step, it doesn't update new level in superblock. So it can't change level after reshape finishes, because the new level is not right. So records the new level in the first step.
---
v2: format change, add get_linux_version
Grow.c | 9 +++++++++ 1 file changed, 9 insertions(+)
Grow.c +9 -0
@@ -2941,15 +2941,24 @@ static int impose_reshape(struct mdinfo *sra,* persists from some earlier problem. */ int err =0 ; +if (sysfs_set_num (sra,NULL ,"chunk_size" , info->new_chunk) <0 ) err = errno; +if (!err &&sysfs_set_num (sra,NULL ,"layout" , reshape->after.layout) <0 ) err = errno; + +/* new_level is introduced in kernel 6.12 */ +if (!err &&get_linux_version () >=6012000 && +sysfs_set_num (sra,NULL ,"new_level" , info->new_level) <0 ) + err = errno; +if (!err &&subarray_set_num (container, sra,"raid_disks" , reshape->after.data_disks + reshape->parity) <0 ) err = errno; +if (err) {pr_err ("Cannot set device shape for %s\n" , devname);
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [PATCH V2 1/1] mdadm/Grow: Update new level when starting reshape
Grow.c static int impose_reshape(struct mdinfo *sra, · line 2955
Quoted 6 lines · On Wed, 11 Sep 2024 16:54:23 +0800 Xiao Ni <[email protected]> wrote:
Grow.c +4
-0+ +/* new_level is introduced in kernel 6.12 */ +if (!err &&get_linux_version () >=6012000 && + sysfs_set_num(sra, NULL, "new_level",
info->new_level) < 0)Grow.c +1
-0+ err = errno;
Hi Xiao,
I realized that we would do this better by checking existence of new_level sysfs file. This way, our solution is limited to kernel > 6.12 so, for example redhat 9 with kernel 5.14 will never pass the condition. I know that you fixed test issue but someone still may find this in real life.
I'm not going to rework it myself, I'm fine with current approach until someone will report issue about that for older kernel.
If you are going to rework this, please left a comment about kernel version that it was added, to let future maintainers know when the additional verification can be removed.
Thanks,
Mariusz
Re: [PATCH V2 1/1] mdadm/Grow: Update new level when starting reshape
Quoted 17 lines · Mariusz Tkaczyk
Quoted 6 lines · On Wed, 11 Sep 2024 16:54:23 +0800 Xiao Ni <[email protected]> wrote:
Grow.c +4
-0+ +/* new_level is introduced in kernel 6.12 */ +if (!err &&get_linux_version () >=6012000 && + sysfs_set_num(sra, NULL, "new_level",
info->new_level) < 0)
+ err = errno;Hi Xiao,
I realized that we would do this better by checking existence ofnew_levelsysfs file. This way, our solution is limited to kernel > 6.12 so, for example redhat 9 with kernel 5.14 will never pass the condition. I know that you fixed test issue but someone still may find this in real life.
Quoted 6 lines
I'm not going to rework it myself, I'm fine with current approach until someone will report issue about that for older kernel.
If you are going to rework this, please left a comment about kernel version that it was added, to let future maintainers know when the additional verification can be removed.
Hi Mariusz
Thanks for pointing this out. You're right. I'll fix it.
Regards
Xiao
Quoted 4 lines
Thanks,
Mariusz
PATCH v2 2/2 mdadm/Grow: Update reshape_progress to need_back after reshape finishes
In reply to Xiao NiIt tries to update data offset when kicking off reshape. If it can't change data offset, it needs to use child_monitor to monitor reshape progress and do back up job. And it needs to update reshape_progress to need_back when reshape finishes. If not, it will be in a infinite loop.
---
v2: add empty line after declaration
Grow.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Grow.c +10 -4
@@ -4148,8 +4148,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,* waiting forever on a dead array */ char action[SYSFS_MAX_BUF_SIZE ]; -if (sysfs_get_str (info,NULL ,"sync_action" , action,sizeof (action)) <=0 || -strncmp (action,"reshape" ,7 ) !=0 ) + +if (sysfs_get_str (info,NULL ,"sync_action" , action,sizeof (action)) <=0 )break ;/* Some kernels reset 'sync_completed' to zero * before setting 'sync_action' to 'idle'.
@@ -4157,12 +4157,18 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,*/ if (completed ==0 && advancing &&strncmp (action,"idle" ,4 ) ==0 && - info->reshape_progress >0 ) + info->reshape_progress >0 ) { + info->reshape_progress = need_backup;break ; + }if (completed ==0 && !advancing &&strncmp (action,"idle" ,4 ) ==0 && info->reshape_progress < - (info->component_size * reshape->after.data_disks)) + (info->component_size * reshape->after.data_disks)) { + info->reshape_progress = need_backup; +break ; + } +if (strncmp (action,"reshape" ,7 ) !=0 )break ;sysfs_wait (fd,NULL );if (sysfs_fd_get_ll (fd, &completed) <0 )
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 3/10 mdadm/Grow: Can't open raid when running --grow --continue
In reply to Xiao NiIt passes 'array' as devname in Grow_continue. So it fails to open raid device. Use mdinfo to open raid device.
--- Grow.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Grow.c +6 -3
@@ -3688,9 +3688,12 @@ started:set_array_size (st, info, info->text_version);if (info->new_level != reshape.level) { -if (fd <0 ) - fd =open (devname,O_RDONLY ); -impose_level (fd, info->new_level, devname, verbose); + fd =open_dev (sra->sys_name); +if (fd <0 ) { +pr_err ("Can't open %s\n" , sra->sys_name); + goto out; + } +impose_level (fd, info->new_level, sra->sys_name, verbose);close (fd);if (info->new_level ==0 ) st->update_tail =NULL ;
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH v2 4/4 mdadm/Grow: sleep a while after removing disk in impose_level
In reply to Xiao NiIt needs to remove disks when reshaping from raid456 to raid0. In kernel space it sets MD_RECOVERY_RUNNING. And it will fail to change level. So wait sometime to let md thread to clear this flag.
This is found by test case 05r6tor0.
---
v2: add log to give friendly message
Grow.c | 7 +++++++ 1 file changed, 7 insertions(+)
Grow.c +7 -0
@@ -3034,6 +3034,13 @@ static int impose_level(int fd, int level, char *devname, int verbose) makedev(disk.major, disk.minor));hot_remove_disk (fd,makedev (disk.major, disk.minor),1 ); } +/* +* hot_remove_disk lets kernel set MD_RECOVERY_RUNNING +* and it can't set level. It needs to wait sometime +* to let md thread to clear the flag. +*/ +pr_info ("wait 5 seconds to give kernel space to finish job\n" ); +sleep_for (5 ,0 , true); } c =map_num (pers, level);if (c) {
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 5/10 mdadm/tests: wait until level changes
In reply to Xiao Nicheck wait waits reshape finishes, but it doesn't wait level changes. The level change happens in a forked child progress. So we need to search the child progress and monitor it.
--- tests/05r6tor0 | 4 ++++ 1 file changed, 4 insertions(+)
tests/05r6tor0 +4 -0
@@ -13,6 +13,10 @@ check raid5 testdev $md0 3 19456 512 mdadm -G $md0 -l0 check wait; sleep 1 +while ps auxf | grep "mdadm -G" | grep -v grep +do + sleep 1 +done check raid0 testdev $md0 3 19456 512 mdadm -G $md0 -l5 --add $dev3 $dev4
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 6/10 mdadm/tests: 07changelevels fix
In reply to Xiao NiThere are five changes to this case.
1. remove testdev check. It can't work anymore and check if it's a block device directly.
2. It can't change level and chunk size at the same time
3. Sleep more than 10s before check wait.
The test devices are small. Sometimes it can finish so quickly once the reshape just starts. mdadm will be stuck before it waits reshape to start. So the sync speed is limited. And it restores the sync speed when it waits reshape to finish. It's good for case without backup file.
It uses systemd service mdadm-grow-continue to monitor reshape progress when specifying backup file. If reshape finishes so quickly before it starts monitoring reshape progress, the daemon will be stuck too. Because reshape_progress is 0 which means the reshape hasn't been started. So give more time to let service can get right information from kernel space.
But before getting these information. It needs to suspend array. At the same time the reshape is running. The kernel reshape daemon will update metadata 10s. So it needs to limit the sync speed more than 10s before restoring sync speed. Then systemd service can suspend array and start monitoring reshape progress.
4. Wait until mdadm-grow-continue service exits
mdadm --wait doesn't wait systemd service. For the case that needs backup file, systemd service deletes the backup file after reshape finishes. In this test case, it runs next case when reshape finishes. And it fails because it can't create backup file because the backup file exits.
5. Don't reshape from raid5 to raid1. It can't work now.
--- tests/07changelevels | 27 ++++++++++++--------------- tests/07changelevels.broken | 9 --------- tests/func.sh | 4 ++++ 3 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 tests/07changelevels.broken
tests/07changelevels +12 -15
@@ -10,7 +10,6 @@ export MDADM_GROW_VERIFY=1 dotest() { sleep 2 check wait - testdev $md0 $1 19968 64 nd blockdev --flushbufs $md0 cmp -s -n $[textK*1024] $md0 /tmp/RandFile || { echo cmp failed; exit 2; } # write something new - shift chars 4 space
@@ -24,7 +23,7 @@ checkgeo() { # level raid_disks chunk_size layout dev=$1 shift - sleep 0.5 + sleep 15 check wait sleep 1 for attr in level raid_disks chunk_size layout
@@ -43,22 +42,25 @@ checkgeo() { bu=/tmp/md-test-backup rm -f $bu -mdadm -CR $md0 -l1 -n2 -x1 $dev0 $dev1 $dev2 -z 19968 -testdev $md0 1 $mdsize1a 64 +mdadm -CR $md0 -l1 -n2 -x1 $dev0 $dev1 $dev2 +[ -b $md0 ] || die "$1 isn't a block device." dd if=/tmp/RandFile of=$md0 dotest 1 -mdadm --grow $md0 -l5 -n3 --chunk 64 +mdadm --grow $md0 -l5 -n3 +checkgeo md0 raid5 3 dotest 2 mdadm $md0 --add $dev3 $dev4 mdadm --grow $md0 -n4 --chunk 32 +checkgeo md0 raid5 4 $[32*1024] dotest 3 mdadm -G $md0 -l6 --backup-file $bu +checkgeo md0 raid6 5 $[32*1024] dotest 3 -mdadm -G /dev/md0 --array-size 39936 +mdadm -G /dev/md0 --array-size 37888 mdadm -G $md0 -n4 --backup-file $bu checkgeo md0 raid6 4 $[32*1024] dotest 2
@@ -67,14 +69,11 @@ mdadm -G $md0 -l5 --backup-file $bu checkgeo md0 raid5 3 $[32*1024] dotest 2 -mdadm -G /dev/md0 --array-size 19968 +mdadm -G /dev/md0 --array-size 18944 mdadm -G $md0 -n2 --backup-file $bu checkgeo md0 raid5 2 $[32*1024] dotest 1 -mdadm -G --level=1 $md0 -dotest 1 - # now repeat that last few steps only with a degraded array. mdadm -S $md0 mdadm -CR $md0 -l6 -n5 $dev0 $dev1 $dev2 $dev3 $dev4
@@ -83,7 +82,7 @@ dotest 3 mdadm $md0 --fail $dev0 -mdadm -G /dev/md0 --array-size 37888 +mdadm -G /dev/md0 --array-size 35840 mdadm -G $md0 -n4 --backup-file $bu dotest 2 checkgeo md0 raid6 4 $[512*1024]
@@ -103,12 +102,10 @@ dotest 2 mdadm -G $md0 -l5 --backup-file $bu dotest 2 -mdadm -G /dev/md0 --array-size 18944 +mdadm -G /dev/md0 --array-size 17920 mdadm -G $md0 -n2 --backup-file $bu dotest 1 checkgeo md0 raid5 2 $[512*1024] mdadm $md0 --fail $dev2 -mdadm -G --level=1 $md0 -dotest 1 -checkgeo md0 raid1 2 +mdadm -S $md0
tests/07changelevels.broken deleted +0 -9
@@ -1,9 +0,0 @@ -always fails - -Fails with errors: - - mdadm: /dev/loop0 is smaller than given size. 18976K < 19968K + metadata - mdadm: /dev/loop1 is smaller than given size. 18976K < 19968K + metadata - mdadm: /dev/loop2 is smaller than given size. 18976K < 19968K + metadata - - ERROR: /dev/md0 isn't a block device.
tests/func.sh +4 -0
@@ -362,6 +362,10 @@ check() { do sleep 0.5 done + while ps auxf | grep "mdadm --grow --continue" | grep -v grep + do + sleep 1 + done echo $min > /proc/sys/dev/raid/speed_limit_min echo $max > /proc/sys/dev/raid/speed_limit_max ;;
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 7/10 mdadm/tests: Remove 07reshape5intr.broken
In reply to Xiao Ni07reshape5intr can run successfully now.
--- tests/07reshape5intr.broken | 45 ------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 tests/07reshape5intr.broken
tests/07reshape5intr.broken deleted +0 -45
@@ -1,45 +0,0 @@ -always fails - -This patch, recently added to md-next causes the test to always fail: - -7e6ba434cc60 ("md: don't unregister sync_thread with reconfig_mutex -held") - -The new error is simply: - - ERROR: no reshape happening - -Before the patch, the error seen is below. - --- - -fails infrequently - -Fails roughly 1 in 4 runs with errors: - - mdadm: Merging with already-assembled /dev/md/0 - mdadm: cannot re-read metadata from /dev/loop6 - aborting - - ERROR: no reshape happening - -Also have seen a random deadlock: - - INFO: task mdadm:109702 blocked for more than 30 seconds. - Not tainted 5.18.0-rc3-eid-vmlocalyes-dbg-00095-g3c2b5427979d #2040 - "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. - task:mdadm state:D stack: 0 pid:109702 ppid: 1 flags:0x00004000 - Call Trace: - <TASK> - __schedule+0x67e/0x13b0 - schedule+0x82/0x110 - mddev_suspend+0x2e1/0x330 - suspend_lo_store+0xbd/0x140 - md_attr_store+0xcb/0x130 - sysfs_kf_write+0x89/0xb0 - kernfs_fop_write_iter+0x202/0x2c0 - new_sync_write+0x222/0x330 - vfs_write+0x3bc/0x4d0 - ksys_write+0xd9/0x180 - __x64_sys_write+0x43/0x50 - do_syscall_64+0x3b/0x90 - entry_SYSCALL_64_after_hwframe+0x44/0xae
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 8/10 mdadm/tests: 07testreshape5 fix
In reply to Xiao NiInit dir to avoid test failure.
--- tests/07testreshape5 | 1 + tests/07testreshape5.broken | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 tests/07testreshape5.broken
tests/07testreshape5 +1 -0
@@ -4,6 +4,7 @@ # kernel md code to move data into and out of variously # shaped md arrays. set -x +dir="." layouts=(la ra ls rs) for level in 5 6 do
tests/07testreshape5.broken deleted +0 -12
@@ -1,12 +0,0 @@ -always fails - -Test seems to run 'test_stripe' at $dir directory, but $dir is never -set. If $dir is adjusted to $PWD, the test still fails with: - - mdadm: /dev/loop2 is not suitable for this array. - mdadm: create aborted - ++ return 1 - ++ cmp -s -n 8192 /dev/md0 /tmp/RandFile - ++ echo cmp failed - cmp failed - ++ exit 2
Signature · 1 line
2.32.0 (Apple Git-132)
PATCH 9/10 mdadm/tests: remove 09imsm-assemble.broken
In reply to Xiao Ni09imsm-assemble can run successfully.
--- tests/09imsm-assemble.broken | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tests/09imsm-assemble.broken
tests/09imsm-assemble.broken deleted +0 -6
@@ -1,6 +0,0 @@ -fails infrequently - -Fails roughly 1 in 10 runs with errors: - - mdadm: /dev/loop2 is still in use, cannot remove. - /dev/loop2 removal from /dev/md/container should have succeeded
Signature · 1 line
2.32.0 (Apple Git-132)
Re: [PATCH 09/10] mdadm/tests: remove 09imsm-assemble.broken
Quoted 13 lines · On Wed, 11 Sep 2024 16:54:31 +0800 Xiao Ni <[email protected]> wrote:
09imsm-assemble can run successfully.
Signed-off-by Xiao Ni <[email protected]>--- tests/09imsm-assemble.broken | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tests/09imsm-assemble.brokentests/09imsm-assemble.broken deleted +0
-0
tests/09imsm-assemble.broken line 6
Quoted 6 lines
tests/09imsm-assemble.broken deleted +0
-6@@ -1,6 +0,0 @@ -fails infrequently - -Fails roughly 1 in 10 runs with errors: - - mdadm: /dev/loop2 is still in use, cannot remove. - /dev/loop2 removal from /dev/md/container should have succeeded
you created dev/null (probably accidentally). I will remove it in new commit because I already merged it.
Thanks,
Mariusz
PATCH 10/10 mdadm/Manage: record errno
In reply to Xiao NiSometimes it reports:
mdadm: failed to stop array /dev/md0: Success
It's the reason the errno is reset. So record errno during the loop.
--- Manage.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Manage.c +5 -3
@@ -238,13 +238,14 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry) "array_state", "inactive")) < 0 && errno == EBUSY) { + err = errno;sleep_for (0 ,MSEC_TO_NSEC (200 ), true); count--; }if (err) {if (verbose >=0 )pr_err ("failed to stop array %s: %s\n" , - devname,strerror (errno)); + devname,strerror (err)); rv =1 ; goto out; }
@@ -438,14 +439,15 @@ done: count =25 ; err =0 ;while (count && fd >=0 && (err =ioctl (fd,STOP_ARRAY ,NULL )) <0 && errno ==EBUSY ) { + err = errno;sleep_for (0 ,MSEC_TO_NSEC (200 ), true); count --; }if (fd >=0 && err) {if (verbose >=0 ) {pr_err ("failed to stop array %s: %s\n" , - devname,strerror (errno)); -if (errno ==EBUSY ) + devname,strerror (err)); +if (err ==EBUSY )cont_err ("Perhaps a running process, mounted filesystem or active volume group?\n" ); } rv =1 ;
Signature · 1 line
2.32.0 (Apple Git-132)
Quoted 26 lines · On Wed, 11 Sep 2024 16:54:22 +0800 Xiao Ni <[email protected]> wrote:
This is the fourth patch set which enhance/fix mdadm regression tests.
v2: fix problems for the first patches
Xiao Ni (10):
mdadm/Grow: Update new level when starting reshape mdadm/Grow: Updatereshape_progresstoneed_backafter reshape
finishes
mdadm/Grow: Can't open raid when running --grow --continue mdadm/Grow: sleep a while after removing disk inimpose_levelmdadm/tests: wait until level changes
mdadm/tests: 07changelevels fix
mdadm/tests: Remove 07reshape5intr.broken mdadm/tests: 07testreshape5 fix
mdadm/tests: remove 09imsm-assemble.broken mdadm/Manage: record errnoGrow.c | 39 +++++++++++++++++++++++++------ Manage.c | 8 ++++--- dev/null | 0 tests/05r6tor0 | 4 ++++ tests/07changelevels | 27 ++++++++++------------ tests/07changelevels.broken | 9 -------- tests/07reshape5intr.broken | 45 ------------------------------------ tests/07testreshape5 | 1 + tests/07testreshape5.broken | 12 ----------
Quoted 9 lines
tests/09imsm-assemble.broken | 6 ----- tests/func.sh | 4 ++++ 11 files changed, 58 insertions(+), 97 deletions(-) create mode 100644 dev/null delete mode 100644 tests/07changelevels.broken delete mode 100644 tests/07reshape5intr.broken delete mode 100644 tests/07testreshape5.broken delete mode 100644 tests/09imsm-assemble.broken
Applied all! We are working on enabling mdadm tests on Github so we will see if it helps. I'm also aware of dependency to new prop md/new_level.
Sorry for the delay, I had holidays.
Thanks,
Mariusz