Skip to contentSkip to conversation

btrfs: regression test for subvol deletion after rename

PATCH Superseded Josef Bacik 2 participants 4 messages Dec 19, 2019 – Dec 20, 2019 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: regression test for subvol deletion after rename

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"

---
 tests/btrfs/202     | 54 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/202.out |  4 ++++
 tests/btrfs/group   |  1 +
 3 files changed, 59 insertions(+)
 create mode 100755 tests/btrfs/202
 create mode 100644 tests/btrfs/202.out
tests/btrfs/202 new file +54 -0
new file mode 100755
index 00000000..b02ee446
@@ -0,0 +1,54 @@
+#! /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
+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
tests/btrfs/202.out new file +4 -0
new file mode 100644
index 00000000..938870cf
@@ -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'
tests/btrfs/group +1 -0
index d7eeb45d..7abc5f07 100644
@@ -204,3 +204,4 @@
 199 auto quick trim
 200 auto quick send clone
 201 auto quick punch log
+202 auto quick volume
Signature · 1 line
2.23.0
#1 lore raw
Quoted 60 lines · Josef Bacik

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"

---
 tests/btrfs/202     | 54 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/202.out |  4 ++++
 tests/btrfs/group   |  1 +
 3 files changed, 59 insertions(+)
 create mode 100755 tests/btrfs/202
 create mode 100644 tests/btrfs/202.out
tests/btrfs/202 new file +37 -0
new file mode 100755
index 00000000..b02ee446
@@ -0,0 +1,54 @@
+#! /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

tests/btrfs/202 line 47

Quoted 10 lines
tests/btrfs/202 new file +10 -0
+# 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
+ls $SCRATCH_MNT/c/b

Isn't this ls redundant?

Quoted 27 lines
tests/btrfs/202 new file +7 -0
+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
tests/btrfs/202.out new file +4 -0
new file mode 100644
index 00000000..938870cf
@@ -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'
tests/btrfs/group +1 -0
index d7eeb45d..7abc5f07 100644
@@ -204,3 +204,4 @@
 199 auto quick trim
 200 auto quick send clone
 201 auto quick punch log
+202 auto quick volume
#2 lore raw
Quoted 67 lines · Nikolay Borisov
Quoted 64 lines · Josef Bacik

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"

---
  tests/btrfs/202     | 54 +++++++++++++++++++++++++++++++++++++++++++++
  tests/btrfs/202.out |  4 ++++
  tests/btrfs/group   |  1 +
  3 files changed, 59 insertions(+)

create mode 100755 tests/btrfs/202
create mode 100644 tests/btrfs/202.out

tests/btrfs/202 new file +41 -0
new file mode 100755
index 00000000..b02ee446
@@ -0,0 +1,54 @@
+#! /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.
Quoted 9 lines

tests/btrfs/202 line 47

Quoted 6 lines
tests/btrfs/202 new file +6 -0
+
+$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
+ls $SCRATCH_MNT/c/b

Isn't this ls redundant?

No we need the dummy entry in cache before we add the root ref during the rename. Thanks,

Josef

#3 lore raw
Quoted 83 lines · Josef Bacik
Quoted 72 lines · Nikolay Borisov
Quoted 69 lines · Josef Bacik

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"

---
  tests/btrfs/202     | 54 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/202.out |  4 ++++
  tests/btrfs/group   |  1 +

  3 files changed, 59 insertions(+)

  create mode 100755 tests/btrfs/202
  create mode 100644 tests/btrfs/202.out

tests/btrfs/202 new file +34 -0
new file mode 100755
index 00000000..b02ee446
@@ -0,0 +1,54 @@
+#! /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

tests/btrfs/202 new file +3 -0
+# 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.

Quoted 9 lines

tests/btrfs/202 line 47

Quoted 6 lines
tests/btrfs/202 new file +6 -0
+
+$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
+ls $SCRATCH_MNT/c/b

Isn't this ls redundant?

Quoted 1 line

No we need the dummy entry in cache before we add the root ref during the rename.  Thanks,

A comment stating this would be good.

Quoted 2 lines

Josef