generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / btrfs / 202
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # FS QA Test 201
5 #
6 # Regression test for fix "btrfs: fix invalid removal of root ref"
7 #
8 seq=`basename $0`
9 seqres=$RESULT_DIR/$seq
10 echo "QA output created by $seq"
11
12 here=`pwd`
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -f $tmp.*
21 }
22
23 . ./common/rc
24 . ./common/filter
25
26 rm -f $seqres.full
27
28 _supported_fs btrfs
29
30 _scratch_mkfs >> $seqres.full 2>&1
31 _scratch_mount
32
33 # Create a subvol b under a and then snapshot a into c.  This create's a stub
34 # entry in c for b because c doesn't have a reference for b.
35 #
36 # But when we rename b c/foo it creates a ref for b in c.  However if we go to
37 # remove c/b btrfs used to depend on not finding the root ref to handle the
38 # unlink properly, but we now have a ref for that root.  We also had a bug that
39 # would allow us to remove mis-matched refs if the keys matched, so we'd end up
40 # removing too many entries which would cause a transaction abort.
41
42 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a | _filter_scratch
43 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a/b | _filter_scratch
44 $BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT/a $SCRATCH_MNT/c \
45         | _filter_scratch
46
47 # Need the dummy entry created so that we get the invalid removal when we rmdir
48 ls $SCRATCH_MNT/c/b
49
50 mkdir $SCRATCH_MNT/c/foo
51 mv $SCRATCH_MNT/a/b $SCRATCH_MNT/c/foo
52 rm -rf $SCRATCH_MNT/*
53 touch $SCRATCH_MNT/blah
54
55 status=0
56 exit