btrfs-progs: balance: fix raid56 warning for other profiles

The warning is printed for profiles where it's not intended (like raid0
or raid1c4). Check the correct variable for the target profiles.

Issue: #355
Fixes: 1ed5db8db4 ("btrfs-progs: balance convert: add a warning and countdown for RAID56 conversion")
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-03-15 14:37:37 +01:00
parent cbadf0f1ae
commit 3a22f0b25b
2 changed files with 37 additions and 2 deletions

View File

@ -645,8 +645,8 @@ static int cmd_balance_start(const struct cmd_struct *cmd,
if (!(ptrs[i]->flags & BTRFS_BALANCE_ARGS_CONVERT))
continue;
if (!(ptrs[i]->flags & (BTRFS_BLOCK_GROUP_RAID6 |
BTRFS_BLOCK_GROUP_RAID5)))
if (!(ptrs[i]->target & (BTRFS_BLOCK_GROUP_RAID6 |
BTRFS_BLOCK_GROUP_RAID5)))
continue;
if (raid56_warned)

View File

@ -0,0 +1,35 @@
#!/bin/bash
# Verify that raid56 warning is printed before balance conversion when the
# target profile is raid5 or raid6, but not other profiles
source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
setup_root_helper
setup_loopdevs 6
prepare_loopdevs
TEST_DEV=${loopdevs[1]}
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d single -m single "${loopdevs[@]}"
run_check_mount_test_dev
stdout=$(run_check_stdout $SUDO_HELPER "$TOP/btrfs" balance start -mconvert=raid5 "$TEST_MNT")
if ! echo "$stdout" | grep -q WARNING; then
_fail "no warning for balance conversion"
fi
run_check $SUDO_HELPER "$TOP/btrfs" balance start -f -mconvert=raid6 "$TEST_MNT"
run_mayfail $SUDO_HELPER "$TOP/btrfs" balance start -mconvert=raid0 "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" balance start -f -mconvert=raid0 "$TEST_MNT"
if run_check_stdout $SUDO_HELPER "$TOP/btrfs" balance start -mconvert=raid1c3 "$TEST_MNT" |
grep -q WARNING; then
_fail "warning found for balance conversion"
fi
if run_check_stdout $SUDO_HELPER "$TOP/btrfs" balance start -mconvert=raid1c4 "$TEST_MNT" |
grep -q WARNING; then
_fail "warning found for balance conversion"
fi
run_check_umount_test_dev
cleanup_loopdevs