btrfs-progs: fix read-write subvol and received_uuid flags check

There's a report that a read-only subvolume with a received_uuid set
emits the warning in command 'btrfs subvolume show', which is obviously
wrong.

The reason is that there are different types of root item flags,
depending on how we read them. The check in cmd_subvol_show uses the
ioctl GET_SUBVOL_INFO and the appropriate flag is raw
BTRFS_ROOT_SUBVOL_RDONLY (0x1), while there's another SUBVOL_GETFLAGS that
maps the flags and the raw value is different (BTRFS_SUBVOL_RDONLY, 0x2).

Due to this the warning was issued. Fix that by using the right flag
constant. The test has been extended to check for all combinations of
read-write and received_uuid.

Issue: #419
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2021-11-01 23:33:26 +01:00
parent 8f81113021
commit dca6b12f0a
2 changed files with 28 additions and 2 deletions

View File

@ -1369,7 +1369,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv)
/* Warn if it's a read-write subvolume with received_uuid */
if (!uuid_is_null(subvol.received_uuid) &&
!(subvol.flags & BTRFS_SUBVOL_RDONLY)) {
!(subvol.flags & BTRFS_ROOT_SUBVOL_RDONLY)) {
warning("the subvolume is read-write and has received_uuid set,\n"
"\t don't use it for incremental send. Please see section\n"
"\t 'SUBVOLUME FLAGS' in manual page btrfs-subvolume for\n"

View File

@ -7,6 +7,7 @@ source "$TEST_TOP/common"
setup_root_helper
prepare_test_dev
ORIG_TEST_DEV="$TEST_DEV"
TEST_DEV=$(extract_image "subvol-rw-recv.img")
run_check_mount_test_dev
if ! run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/subvol1" |
@ -18,5 +19,30 @@ if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/snap1" |
_fail "unexpected warning"
fi
run_check_umount_test_dev
rm -- "$TEST_DEV"
TEST_DEV="$ORIG_TEST_DEV"
run_check_mkfs_test_dev
run_check_mount_test_dev
run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT/subvol1"
if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/subvol1" |
grep -q "WARNING.*received_uuid"; then
_fail "unexpected warning"
fi
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "$TEST_MNT/subvol1" "$TEST_MNT/snap1"
if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/snap1" |
grep -q "WARNING.*received_uuid"; then
_fail "unexpected warning"
fi
run_check $SUDO_HELPER mkdir "$TEST_MNT/recv"
touch send.stream
chmod a+w send.stream
run_check $SUDO_HELPER "$TOP/btrfs" send -f send.stream "$TEST_MNT/snap1"
run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.stream -m "$TEST_MNT" "$TEST_MNT/recv"
if run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume show "$TEST_MNT/recv/snap1" |
grep -q "WARNING.*received_uuid"; then
_fail "unexpected warning"
fi
run_check_umount_test_dev
rm -- send.stream