btrfs-progs: tests: in misc/038 test cases

The test case always fails in my VM, with the following error:

  $ sudo TEST=038\* make test-misc
     [TEST]   misc-tests.sh
     [TEST/misc]   038-backup-root-corruption
  Backup 2 not overwritten
  test failed for case 038-backup-root-corruption

After more debugging, it turns out that there is nothing wrong except
the final check:

  [ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten"

The _fail() is only triggered if the previous check returns false, which
is completely the opposite.

Furthermore on the github CI, the kernel commits 2 instead of 1
transaction, resulting the next slot never to match the current
generation/tree root.

The two bugs combined, github CI always passses the test case, while
for my VM which does the expected one transaction, it would always fail.

Fix it by:

- Use a proper "if [] then; fi" block to check the tree root bytenr
- Use the generation diff to calculate the expected backup root slot
- Log the full super block dump for debug usage

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2024-06-04 15:01:25 +09:30 committed by David Sterba
parent 0eeb12aef5
commit ff1ff014f0
1 changed files with 12 additions and 4 deletions

View File

@ -41,6 +41,9 @@ slot_num=$(echo $found | cut -f1 -d:)
# To follow the dump-super output, where backup slot starts at 0. # To follow the dump-super output, where backup slot starts at 0.
slot_num=$(($slot_num - 1)) slot_num=$(($slot_num - 1))
_log "Original superblock:"
_log "$(dump_super)"
# Save the backup slot info into the log # Save the backup slot info into the log
_log "Backup slot $slot_num will be utilized" _log "Backup slot $slot_num will be utilized"
dump_super | run_check grep -A9 "backup $slot_num:" dump_super | run_check grep -A9 "backup $slot_num:"
@ -56,9 +59,14 @@ run_check_mount_test_dev -o usebackuproot
run_check_umount_test_dev run_check_umount_test_dev
main_root_ptr=$(dump_super | awk '/^root\t/{print $2}') main_root_ptr=$(dump_super | awk '/^root\t/{print $2}')
cur_gen=$(dump_super | grep ^generation | awk '{print $2}')
# The next slot should be overwritten # The slot to be used is based on how many transaction are committed.
slot_num=$(( ($slot_num + 1) % 4 )) slot_num=$(( ($slot_num + $cur_gen - $backup_gen) % 4 ))
backup_new_root_ptr=$(dump_super | grep -A1 "backup $slot_num" | grep backup_tree_root | awk '{print $2}') backup_new_root_ptr=$(dump_super | grep -A1 "backup $slot_num" | grep backup_tree_root | awk '{print $2}')
[ "$main_root_ptr" -ne "$backup_new_root_ptr" ] || _fail "Backup 2 not overwritten" _log "After the backup usage:"
_log "$(dump_super)"
if [ "$main_root_ptr" -ne "$backup_new_root_ptr" ]; then
_fail "Backup ${slot_num} not overwritten"
fi