"Fossies" - the Fresh Open Source Software Archive

Member "btrfs-progs-v5.4.1/tests/misc-tests/038-backup-root-corruption/test.sh" (9 Jan 2020, 1516 Bytes) of package /linux/misc/btrfs-progs-v5.4.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test.sh": v5.4_vs_v5.4.1.

    1 #!/bin/bash
    2 # Test that a corrupted filesystem will correctly handle writing of backup root
    3 
    4 source "$TEST_TOP/common"
    5 
    6 check_prereq mkfs.btrfs
    7 check_prereq btrfs
    8 check_prereq btrfs-corrupt-block
    9 
   10 setup_root_helper
   11 prepare_test_dev
   12 
   13 # Create a file and unmount to commit some backup roots
   14 run_check_mkfs_test_dev
   15 run_check_mount_test_dev
   16 run_check $SUDO_HELPER touch "$TEST_MNT/file"
   17 run_check_umount_test_dev
   18 
   19 dump_super() {
   20     run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super -f "$TEST_DEV"
   21 }
   22 
   23 # Ensure currently active backup slot is the expected one (slot 3)
   24 backup2_root_ptr=$(dump_super | grep -A1 "backup 2" | grep backup_tree_root | awk '{print $2}')
   25 
   26 main_root_ptr=$(dump_super | awk '/^root\t/{print $2}')
   27 
   28 [ "$backup2_root_ptr" -eq "$main_root_ptr" ] || _fail "Backup slot 2 is not in use"
   29 
   30 run_check "$TOP/btrfs-corrupt-block" -m $main_root_ptr -f generation "$TEST_DEV"
   31 
   32 # Should fail because the root is corrupted
   33 run_mustfail "Unexpected successful mount" \
   34     $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT"
   35 
   36 # Cycle mount with the backup to force rewrite of slot 3
   37 run_check_mount_test_dev -o usebackuproot
   38 run_check_umount_test_dev
   39 
   40 # Since we've used backup 1 as the usable root, then backup 2 should have been
   41 # overwritten
   42 main_root_ptr=$(dump_super | grep root | head -n1 | awk '{print $2}')
   43 backup2_new_root_ptr=$(dump_super | grep -A1 "backup 2" | grep backup_tree_root | awk '{print $2}')
   44 
   45 [ "$backup2_root_ptr" -ne "$backup2_new_root_ptr" ] || _fail "Backup 2 not overwritten"