On Tue, Oct 15, 2019 at 06:42:49PM +0300, Nikolay Borisov wrote:
> This tests ensures that the kernel correctly persists backup roots in
> case the filesystem has been mounted from a backup root.
>
> Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx>
> ---
> .../misc-tests/038-backup-root-corruption/test.sh | 50 ++++++++++++++++++++++
> 1 file changed, 50 insertions(+)
> create mode 100755 tests/misc-tests/038-backup-root-corruption/test.sh
>
> diff --git a/tests/misc-tests/038-backup-root-corruption/test.sh b/tests/misc-tests/038-backup-root-corruption/test.sh
> new file mode 100755
> index 000000000000..2fb117b3a928
> --- /dev/null
> +++ b/tests/misc-tests/038-backup-root-corruption/test.sh
> @@ -0,0 +1,50 @@
> +#!/bin/bash
> +# Test that a corrupted filesystem will correctly handle writing of
> +# backup root
> +
> +source "$TEST_TOP/common"
> +
> +check_prereq mkfs.btrfs
> +check_prereq btrfs
> +check_prereq btrfs-corrupt-block
> +
> +setup_loopdevs 1
> +prepare_loopdevs
> +dev=${loopdevs[1]}
And the loop devices are not necessary at all
prepare_device
and be done.
> +
> +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$dev"
> +
> +# Create a file and unmount to commit some backup roots
> +run_check $SUDO_HELPER mount "$dev" "$TEST_MNT"
> +run_check touch "$TEST_MNT/file" && sync
sync is not necessary when it's followed by umount, besides that it
syncs all fileystems so it's an unnecessary slowdown
> +run_check $SUDO_HELPER umount "$TEST_MNT"
> +
> +# Ensure currently active backup slot is the expected one (slot 3)
> +backup2_root_ptr=$($SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super -f "$dev" \
this should use run_check_stdout so we have the full output logged, as
the inspect-part is called several times I added a helper for that.
> + | grep -A1 "backup 2" | grep backup_tree_root | awk '{print $2}')
> +
> +main_root_ptr=$($SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super -f "$dev" \
> + | grep root | head -n1 | awk '{print $2}')
> +
> +[[ "$backup2_root_ptr" -eq "$main_root_ptr" ]] || _fail "Backup slot 2 is not in use"
[[ ]] is not necessary when it's a simple check that [ ] can do
All fixed and pushed.