2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test correct operation of free objectid related functionality
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
28 # remove previous $seqres.full before test
31 # real QA test starts here
33 # Modify as appropriate.
36 _require_btrfs_command inspect-internal dump-tree
38 _scratch_mkfs > /dev/null
41 # create a new subvolume to validate its objectid is initialized accordingly,
42 # the expected value is 256 as this is the first free objectid in a new file
44 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/newvol >> $seqres.full 2>&1 \
45 || _fail "couldn't create subvol"
47 $BTRFS_UTIL_PROG inspect-internal dump-tree -t1 $SCRATCH_DEV \
48 | grep -q "256 ROOT_ITEM" || _fail "First subvol with id 256 doesn't exist"
50 # create new file in the new subvolume to validate its objectid is set as
52 touch $SCRATCH_MNT/newvol/file1 || _fail "Cannot create file in new subvol"
54 # ensure we have consistent view on-disk
57 # get output related to the new root's dir entry
58 output_file=$tmp.output
59 $BTRFS_UTIL_PROG inspect-internal dump-tree -t5 $SCRATCH_DEV | grep -A2 "256 DIR_ITEM 1903355334" > $output_file
61 # get the objectid of the new root
62 new_root_id=$($AWK_PROG '/location key/{printf $3}' $output_file | tr -d '(')
63 [ $new_root_id -eq 256 ] || _fail "New root id not equal to 256"
65 # the given root should always be item number 2, since it's the only item
66 item_seq=$($AWK_PROG '/item/ {printf $2}' $output_file)
67 [ $item_seq -eq 2 ] || _fail "New root not at item idx 2"
69 # now parse the structure of the new subvol's tree
70 $BTRFS_UTIL_PROG inspect-internal dump-tree -t256 $SCRATCH_DEV > $output_file
72 # this is the subvol's own ino
73 first_ino=$($AWK_PROG '/item 0/{printf $4}' $output_file | tr -d '(')
74 [ $first_ino -eq 256 ] || _fail "First ino objectid in subvol not 256"
76 # this is ino of first file in subvol
77 second_ino=$($AWK_PROG '/item 4/{printf $4}' $output_file | tr -d '(')
78 [ $second_ino -eq 257 ] || _fail "Second ino objectid in subvol not 257"
81 echo "Silence is golden"