btrfs: regression test for subvol deletion after rename
authorJosef Bacik <josef@toxicpanda.com>
Fri, 20 Dec 2019 14:40:24 +0000 (09:40 -0500)
committerEryu Guan <guaneryu@gmail.com>
Mon, 6 Jan 2020 09:59:27 +0000 (17:59 +0800)
Test removal of a subvolume via rmdir after it has been renamed into a
snapshot of the volume that originally contained the subvolume
reference.

This currently fails on btrfs but is fixed by the patch with the title

  "btrfs: fix invalid removal of root ref"

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/202 [new file with mode: 0755]
tests/btrfs/202.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/202 b/tests/btrfs/202
new file mode 100755 (executable)
index 0000000..5d56a2a
--- /dev/null
@@ -0,0 +1,57 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# FS QA Test 201
+#
+# Regression test for fix "btrfs: fix invalid removal of root ref"
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+}
+
+. ./common/rc
+. ./common/filter
+
+rm -f $seqres.full
+
+_supported_fs btrfs
+_supported_os Linux
+
+_scratch_mkfs >> $seqres.full 2>&1
+_scratch_mount
+
+# Create a subvol b under a and then snapshot a into c.  This create's a stub
+# entry in c for b because c doesn't have a reference for b.
+#
+# But when we rename b c/foo it creates a ref for b in c.  However if we go to
+# remove c/b btrfs used to depend on not finding the root ref to handle the
+# unlink properly, but we now have a ref for that root.  We also had a bug that
+# would allow us to remove mis-matched refs if the keys matched, so we'd end up
+# removing too many entries which would cause a transaction abort.
+
+$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a | _filter_scratch
+$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a/b | _filter_scratch
+$BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT/a $SCRATCH_MNT/c \
+       | _filter_scratch
+
+# Need the dummy entry created so that we get the invalid removal when we rmdir
+ls $SCRATCH_MNT/c/b
+
+mkdir $SCRATCH_MNT/c/foo
+mv $SCRATCH_MNT/a/b $SCRATCH_MNT/c/foo
+rm -rf $SCRATCH_MNT/*
+touch $SCRATCH_MNT/blah
+
+status=0
+exit
diff --git a/tests/btrfs/202.out b/tests/btrfs/202.out
new file mode 100644 (file)
index 0000000..938870c
--- /dev/null
@@ -0,0 +1,4 @@
+QA output created by 201
+Create subvolume 'SCRATCH_MNT/a'
+Create subvolume 'SCRATCH_MNT/a/b'
+Create a snapshot of 'SCRATCH_MNT/a' in 'SCRATCH_MNT/c'
index d7eeb45d3bc427beed0ec9396d7b9c3530932c58..697b6a38ea0019dcf9baf78518f9f7f266e228a2 100644 (file)
 199 auto quick trim
 200 auto quick send clone
 201 auto quick punch log
+202 auto quick subvol snapshot