2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
7 # Check that we can upgrade a filesystem to support inobtcount and that
8 # everything works properly after the upgrade.
11 _begin_fstest auto quick inobtcount
13 # Import common functions.
16 # real QA test starts here
18 _require_scratch_xfs_inobtcount
19 _require_command "$XFS_ADMIN_PROG" "xfs_admin"
20 _require_xfs_repair_upgrade inobtcount
22 # Make sure we can't format a filesystem with inobtcount and not finobt.
23 _scratch_mkfs -m crc=1,inobtcount=1,finobt=0 &> $seqres.full && \
24 echo "Should not be able to format with inobtcount but not finobt."
26 # Make sure we can't upgrade a V4 filesystem
27 _scratch_mkfs -m crc=0,inobtcount=0,finobt=0 >> $seqres.full
28 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
29 _check_scratch_xfs_features INOBTCNT
31 # Make sure we can't upgrade a filesystem to inobtcount without finobt.
32 _scratch_mkfs -m crc=1,inobtcount=0,finobt=0 >> $seqres.full
33 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
34 _check_scratch_xfs_features INOBTCNT
36 # Format V5 filesystem without inode btree counter support and populate it.
37 _scratch_mkfs -m crc=1,inobtcount=0 >> $seqres.full
40 mkdir $SCRATCH_MNT/stress
41 $FSSTRESS_PROG -d $SCRATCH_MNT/stress -n 1000 >> $seqres.full
42 echo moo > $SCRATCH_MNT/urk
46 # Upgrade filesystem to have the counters and inject failure into repair and
47 # make sure that the only path forward is to re-run repair on the filesystem.
48 echo "Fail partway through upgrading"
49 XFS_REPAIR_FAIL_AFTER_PHASE=2 _scratch_xfs_repair -c inobtcount=1 2>> $seqres.full
50 test $? -eq 137 || echo "repair should have been killed??"
51 _check_scratch_xfs_features NEEDSREPAIR INOBTCNT
52 _try_scratch_mount &> $tmp.mount
54 _filter_error_mount < $tmp.mount
55 if [ $res -eq 0 ]; then
56 echo "needsrepair should have prevented mount"
60 echo "Re-run repair to finish upgrade"
61 _scratch_xfs_repair 2>> $seqres.full
62 _check_scratch_xfs_features NEEDSREPAIR INOBTCNT
64 echo "Filesystem should be usable again"
66 $FSSTRESS_PROG -d $SCRATCH_MNT/stress -n 1000 >> $seqres.full
69 _check_scratch_xfs_features INOBTCNT
71 echo "Make sure we have nonzero counters"
72 _scratch_xfs_db -c 'agi 0' -c 'print ino_blocks fino_blocks' | \
73 sed -e 's/= 0$/= ZERO/g' -e 's/= [0-9]*/= NONZERO/g'
75 echo "Make sure we can't re-add inobtcount"
76 _scratch_xfs_admin -O inobtcount=1 2>> $seqres.full
78 echo "Mount again, look at our files"
79 _scratch_mount >> $seqres.full