Skip to contentSkip to conversation

btrfs: Add new test for qgroup assign functionality

PATCH Superseded Sidong Yang 2 participants 5 messages Sep 22, 2020 – Sep 24, 2020 Btrfs file system

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs: Add new test for qgroup assign functionality

This new test will test btrfs's qgroup assign functionality. The test has 3 cases.

- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents

Each cases create subvolumes and assign qgroup in their own way and check with the command "btrfs check".

Cc Qu Wenruo <[email protected]>
Cc Eryu Guan <[email protected]>

---
v2: create new test and use the cases

---
 tests/btrfs/221     | 121 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/221.out |   2 +
 tests/btrfs/group   |   1 +
 3 files changed, 124 insertions(+)
 create mode 100755 tests/btrfs/221
 create mode 100644 tests/btrfs/221.out
tests/btrfs/221 new file +121 -0
new file mode 100755
index 00000000..7fe5d78f
@@ -0,0 +1,121 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.
+#
+# FS QA Test 221
+#
+# Test the assign functionality of qgroups
+#
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+
+_require_test
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+	echo "=== qgroup assign shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+
+	_ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+	cp --reflink=always "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1 >> $seqres.full 2>&1
+
+	_scratch_unmount
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+	echo "=== qgroup assign no shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test snapshot with assigning qgroup for submodule
+snapshot_test()
+{
+	echo "=== qgroup snapshot test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+
+	_run_btrfs_util_prog subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_no_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
tests/btrfs/221.out new file +2 -0
new file mode 100644
index 00000000..aa4351cd
@@ -0,0 +1,2 @@
+QA output created by 221
+Silence is golden
tests/btrfs/group +1 -0
index 1b5fa695..cdda38f3 100644
@@ -222,3 +222,4 @@
 218 auto quick volume
 219 auto quick volume
 220 auto quick
+221 auto quick qgroup
Signature · 1 line
2.25.1
#1 lore raw
Quoted 30 lines · Sidong Yang

This new test will test btrfs's qgroup assign functionality. The test has 3 cases.

- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents

Each cases create subvolumes and assign qgroup in their own way and check with the command "btrfs check".

Cc Qu Wenruo <[email protected]>
Cc Eryu Guan <[email protected]>

---
v2: create new test and use the cases

---
 tests/btrfs/221     | 121 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/221.out |   2 +
 tests/btrfs/group   |   1 +
 3 files changed, 124 insertions(+)
 create mode 100755 tests/btrfs/221
 create mode 100644 tests/btrfs/221.out
tests/btrfs/221 new file +0 -0
new file mode 100755
index 00000000..7fe5d78f

tests/btrfs/221 line 3

Quoted 3 lines
tests/btrfs/221 new file +3 -0
@@ -0,0 +1,121 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.

So, "YOUR NAME HERE" is your name? :)

Quoted 22 lines
tests/btrfs/221 new file +22 -0
+#
+# FS QA Test 221
+#
+# Test the assign functionality of qgroups
+#
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc

tests/btrfs/221 line 35

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+. ./common/filter
+. ./common/reflink
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic

It's a btrfs specific test.

tests/btrfs/221 line 38

Quoted 3 lines
tests/btrfs/221 new file +3 -0
+_supported_os Linux
+
+_require_test

You don't need test_dev at all.

tests/btrfs/221 line 47

Quoted 9 lines
tests/btrfs/221 new file +9 -0
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+	echo "=== qgroup assign shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT

I'm not sure if _run_btrfs_util_prog is still recommended. IIRC nowadays we recommend to call $BTRFS_UTIL_PROG directly.

Test case btrfs/193 would be the example.

tests/btrfs/221 line 52

Quoted 5 lines
tests/btrfs/221 new file +5 -0
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

"btrfs qgroup assign" can take path directly. This would save your some lines. E.g:

  # btrfs qgroup create 1/100 /mnt/btrfs/
  # btrfs qgroup assign /mnt/btrfs/ 1/100 /mnt/btrfs/
  # btrfs qgroup  show -pc /mnt/btrfs/
  qgroupid         rfer         excl parent  child
  --------         ----         ---- ------  -----
  0/5          16.00KiB     16.00KiB 1/100   ---
  1/100        16.00KiB     16.00KiB ---     0/5

tests/btrfs/221 line 56

Quoted 4 lines
tests/btrfs/221 new file +4 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

Shouldn't this assign happens when we have shared extents between the two subvolumes?

Now you're just testing the basic qgroup functionality of accounting, not assign.

For real assign tests, what we want is either:
- After assign, qgroup accounting is still correct We don't need even to rescan.
And "btrfs check" will verify the numbers are correct.

- After assign, qgroup accounting is inconsistent
At least we should either have qgroup inconsistent bit set, or qgroup rescan kicked in automatically.
And "btrfs check" will skip the qgroup numbers.

But in your case, we're assigning two empty subovlumes into the same qgroup, then do some operations.
This only covers the "assign, no shared extents" case.

tests/btrfs/221 line 62

Quoted 6 lines
tests/btrfs/221 new file +6 -0
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+
+	_ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+	cp --reflink=always "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1 >> $seqres.full 2>&1
+
+	_scratch_unmount

Since you're unmounting here, why not keep the _scratch_mkfs and _scratch_unmount pair in the same function?

Quoted 9 lines
tests/btrfs/221 new file +9 -0
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+	echo "=== qgroup assign no shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT

tests/btrfs/221 line 81

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT

No, we don't want rescan.

And the timing is still wrong.

Quoted 6 lines
tests/btrfs/221 new file +6 -0
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test snapshot with assigning qgroup for submodule

tests/btrfs/221 line 97

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+snapshot_test()
+{
+	echo "=== qgroup snapshot test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+
+	_run_btrfs_util_prog subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)

Even we're snapshotting on the source subvolume, since it's empty, we will only copy the root item, resulting two empty subvolumes without sharing anything.

You need to at least fill the source subvolumes with some data. It's better to bump the tree level with some inline extents.

Thanks,
Qu

Quoted 42 lines
tests/btrfs/221 new file +24 -0
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_no_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
tests/btrfs/221.out new file +2 -0
new file mode 100644
index 00000000..aa4351cd
@@ -0,0 +1,2 @@
+QA output created by 221
+Silence is golden
tests/btrfs/group +1 -0
index 1b5fa695..cdda38f3 100644
@@ -222,3 +222,4 @@
 218 auto quick volume
 219 auto quick volume
 220 auto quick
+221 auto quick qgroup
#2 lore raw
Quoted 27 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang

This new test will test btrfs's qgroup assign functionality. The test has 3 cases.

- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents

Each cases create subvolumes and assign qgroup in their own way and check with the command "btrfs check".

Cc Qu Wenruo <[email protected]>
Cc Eryu Guan <[email protected]>

---
v2: create new test and use the cases

---
 tests/btrfs/221     | 121 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/221.out |   2 +
 tests/btrfs/group   |   1 +
 3 files changed, 124 insertions(+)
 create mode 100755 tests/btrfs/221
 create mode 100644 tests/btrfs/221.out
Quoted 11 lines

tests/btrfs/221 line 3

Quoted 9 lines
tests/btrfs/221 new file +3 -0
new file mode 100755
index 00000000..7fe5d78f
@@ -0,0 +1,121 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.

So, "YOUR NAME HERE" is your name? :)

Oops! I missed it.

Quoted 27 lines
Quoted 27 lines
tests/btrfs/221 new file +26 -0
+#
+# FS QA Test 221
+#
+# Test the assign functionality of qgroups
+#
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# remove previous $seqres.full before test
Quoted 8 lines

tests/btrfs/221 line 35

Quoted 6 lines
tests/btrfs/221 new file +6 -0
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic

It's a btrfs specific test.

Thanks!

Quoted 6 lines

tests/btrfs/221 line 38

Quoted 4 lines
tests/btrfs/221 new file +3 -0
+_supported_os Linux
+
+_require_test

You don't need test_dev at all.

Yeah, I just realized that I used only scratch dev noy test dev. Thanks!

Quoted 14 lines

tests/btrfs/221 line 47

Quoted 10 lines
tests/btrfs/221 new file +9 -0
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+	echo "=== qgroup assign shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT

I'm not sure if _run_btrfs_util_prog is still recommended. IIRC nowadays we recommend to call $BTRFS_UTIL_PROG directly.

Quoted 1 line

Test case btrfs/193 would be the example.

It's good to replace it! Thanks.

Quoted 10 lines

tests/btrfs/221 line 52

Quoted 6 lines
tests/btrfs/221 new file +5 -0
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

"btrfs qgroup assign" can take path directly. This would save your some lines. E.g:

Quoted 7 lines
  # btrfs qgroup create 1/100 /mnt/btrfs/
  # btrfs qgroup assign /mnt/btrfs/ 1/100 /mnt/btrfs/
  # btrfs qgroup  show -pc /mnt/btrfs/
  qgroupid         rfer         excl parent  child
  --------         ----         ---- ------  -----
  0/5          16.00KiB     16.00KiB 1/100   ---
  1/100        16.00KiB     16.00KiB ---     0/5

Thanks for good tip!

Quoted 17 lines

tests/btrfs/221 line 56

Quoted 5 lines
tests/btrfs/221 new file +4 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

Shouldn't this assign happens when we have shared extents between the two subvolumes?

Now you're just testing the basic qgroup functionality of accounting, not assign.

For real assign tests, what we want is either:
- After assign, qgroup accounting is still correct We don't need even to rescan.
And "btrfs check" will verify the numbers are correct.

Quoted 8 lines

- After assign, qgroup accounting is inconsistent
At least we should either have qgroup inconsistent bit set, or qgroup rescan kicked in automatically.
And "btrfs check" will skip the qgroup numbers.

But in your case, we're assigning two empty subovlumes into the same qgroup, then do some operations.
This only covers the "assign, no shared extents" case.

You mean that there should be some data with reflink before assigning? If so, the code below should be executed before assigning qgroups. Should test process be like this?
make submodules -> make data -> copy with reflink -> assign qgroup

Quoted 33 lines

tests/btrfs/221 line 62

Quoted 7 lines
tests/btrfs/221 new file +6 -0
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+
+	_ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+	cp --reflink=always "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1 >> $seqres.full 2>&1
+
+	_scratch_unmount

Since you're unmounting here, why not keep the _scratch_mkfs and _scratch_unmount pair in the same function?

Quoted 9 lines
tests/btrfs/221 new file +9 -0
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+	echo "=== qgroup assign no shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT

tests/btrfs/221 line 81

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT

No, we don't want rescan.

Quoted 1 line

And the timing is still wrong.

Yeah, I'll delete it.

Quoted 22 lines
Quoted 7 lines
tests/btrfs/221 new file +6 -0
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test snapshot with assigning qgroup for submodule

tests/btrfs/221 line 97

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+snapshot_test()
+{
+	echo "=== qgroup snapshot test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+
+	_run_btrfs_util_prog subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)

Even we're snapshotting on the source subvolume, since it's empty, we will only copy the root item, resulting two empty subvolumes without sharing anything.

Quoted 2 lines

You need to at least fill the source subvolumes with some data. It's better to bump the tree level with some inline extents.

I should write some data before snapshot. is it right? Thanks for all your comments.

Thanks,
Sidong

Quoted 47 lines

Thanks,
Qu

Quoted 42 lines
tests/btrfs/221 new file +24 -0
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_no_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
tests/btrfs/221.out new file +2 -0
new file mode 100644
index 00000000..aa4351cd
@@ -0,0 +1,2 @@
+QA output created by 221
+Silence is golden
tests/btrfs/group +1 -0
index 1b5fa695..cdda38f3 100644
@@ -222,3 +222,4 @@
 218 auto quick volume
 219 auto quick volume
 220 auto quick
+221 auto quick qgroup
#3 lore raw
Quoted 143 lines · Sidong Yang
Quoted 27 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang

This new test will test btrfs's qgroup assign functionality. The test has 3 cases.

- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents

Each cases create subvolumes and assign qgroup in their own way and check with the command "btrfs check".

Cc Qu Wenruo <[email protected]>
Cc Eryu Guan <[email protected]>

---
v2: create new test and use the cases

---
 tests/btrfs/221     | 121 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/221.out |   2 +
 tests/btrfs/group   |   1 +
 3 files changed, 124 insertions(+)
 create mode 100755 tests/btrfs/221
 create mode 100644 tests/btrfs/221.out
Quoted 11 lines

tests/btrfs/221 line 3

Quoted 9 lines
tests/btrfs/221 new file +3 -0
new file mode 100755
index 00000000..7fe5d78f
@@ -0,0 +1,121 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.

So, "YOUR NAME HERE" is your name? :)

Oops! I missed it.

Quoted 27 lines
Quoted 27 lines
tests/btrfs/221 new file +26 -0
+#
+# FS QA Test 221
+#
+# Test the assign functionality of qgroups
+#
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# remove previous $seqres.full before test
Quoted 8 lines

tests/btrfs/221 line 35

Quoted 6 lines
tests/btrfs/221 new file +6 -0
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic

It's a btrfs specific test.

Thanks!

Quoted 6 lines

tests/btrfs/221 line 38

Quoted 4 lines
tests/btrfs/221 new file +3 -0
+_supported_os Linux
+
+_require_test

You don't need test_dev at all.

Yeah, I just realized that I used only scratch dev noy test dev. Thanks!

Quoted 14 lines

tests/btrfs/221 line 47

Quoted 10 lines
tests/btrfs/221 new file +9 -0
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+	echo "=== qgroup assign shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT

I'm not sure if _run_btrfs_util_prog is still recommended. IIRC nowadays we recommend to call $BTRFS_UTIL_PROG directly.

Quoted 1 line

Test case btrfs/193 would be the example.

It's good to replace it! Thanks.

Quoted 10 lines

tests/btrfs/221 line 52

Quoted 6 lines
tests/btrfs/221 new file +5 -0
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

"btrfs qgroup assign" can take path directly. This would save your some lines. E.g:

Quoted 7 lines
  # btrfs qgroup create 1/100 /mnt/btrfs/
  # btrfs qgroup assign /mnt/btrfs/ 1/100 /mnt/btrfs/
  # btrfs qgroup  show -pc /mnt/btrfs/
  qgroupid         rfer         excl parent  child
  --------         ----         ---- ------  -----
  0/5          16.00KiB     16.00KiB 1/100   ---
  1/100        16.00KiB     16.00KiB ---     0/5

Thanks for good tip!

Quoted 22 lines

tests/btrfs/221 line 56

Quoted 5 lines
tests/btrfs/221 new file +4 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

Shouldn't this assign happens when we have shared extents between the two subvolumes?

Now you're just testing the basic qgroup functionality of accounting, not assign.

For real assign tests, what we want is either:
- After assign, qgroup accounting is still correct We don't need even to rescan.
And "btrfs check" will verify the numbers are correct.

- After assign, qgroup accounting is inconsistent
At least we should either have qgroup inconsistent bit set, or qgroup rescan kicked in automatically.
And "btrfs check" will skip the qgroup numbers.

Quoted 8 lines
Quoted 3 lines

But in your case, we're assigning two empty subovlumes into the same qgroup, then do some operations.
This only covers the "assign, no shared extents" case.

You mean that there should be some data with reflink before assigning? If so, the code below should be executed before assigning qgroups. Should test process be like this?
make submodules -> make data -> copy with reflink -> assign qgroup

Yep.

Furthermore, we should have qgroup enabled/rescanned before make subvolumes.

Quoted 58 lines
Quoted 34 lines

tests/btrfs/221 line 62

Quoted 8 lines
tests/btrfs/221 new file +6 -0
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+
+	_ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+	cp --reflink=always "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1 >> $seqres.full 2>&1
+
+	_scratch_unmount

Since you're unmounting here, why not keep the _scratch_mkfs and _scratch_unmount pair in the same function?

Quoted 9 lines
tests/btrfs/221 new file +9 -0
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+	echo "=== qgroup assign no shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT

tests/btrfs/221 line 81

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT

No, we don't want rescan.

Quoted 1 line

And the timing is still wrong.

Yeah, I'll delete it.

Quoted 22 lines
Quoted 7 lines
tests/btrfs/221 new file +6 -0
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test snapshot with assigning qgroup for submodule

tests/btrfs/221 line 97

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+snapshot_test()
+{
+	echo "=== qgroup snapshot test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+
+	_run_btrfs_util_prog subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)

Even we're snapshotting on the source subvolume, since it's empty, we will only copy the root item, resulting two empty subvolumes without sharing anything.

Quoted 4 lines
Quoted 2 lines

You need to at least fill the source subvolumes with some data. It's better to bump the tree level with some inline extents.

I should write some data before snapshot. is it right?

Right. That's the bare minimal.

Thanks,
qu

Quoted 55 lines

Thanks for all your comments.

Thanks,
Sidong

Quoted 47 lines

Thanks,
Qu

Quoted 42 lines
tests/btrfs/221 new file +24 -0
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_no_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
tests/btrfs/221.out new file +2 -0
new file mode 100644
index 00000000..aa4351cd
@@ -0,0 +1,2 @@
+QA output created by 221
+Silence is golden
tests/btrfs/group +1 -0
index 1b5fa695..cdda38f3 100644
@@ -222,3 +222,4 @@
 218 auto quick volume
 219 auto quick volume
 220 auto quick
+221 auto quick qgroup
#4 lore raw
Quoted 219 lines · Qu Wenruo
Quoted 143 lines · Sidong Yang
Quoted 27 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang

This new test will test btrfs's qgroup assign functionality. The test has 3 cases.

- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents

Each cases create subvolumes and assign qgroup in their own way and check with the command "btrfs check".

Cc Qu Wenruo <[email protected]>
Cc Eryu Guan <[email protected]>

---
v2: create new test and use the cases

---
 tests/btrfs/221     | 121 ++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/221.out |   2 +
 tests/btrfs/group   |   1 +
 3 files changed, 124 insertions(+)
 create mode 100755 tests/btrfs/221
 create mode 100644 tests/btrfs/221.out
Quoted 11 lines

tests/btrfs/221 line 3

Quoted 9 lines
tests/btrfs/221 new file +3 -0
new file mode 100755
index 00000000..7fe5d78f
@@ -0,0 +1,121 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.

So, "YOUR NAME HERE" is your name? :)

Oops! I missed it.

Quoted 27 lines
Quoted 27 lines
tests/btrfs/221 new file +26 -0
+#
+# FS QA Test 221
+#
+# Test the assign functionality of qgroups
+#
+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.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/reflink
+
+# remove previous $seqres.full before test
Quoted 8 lines

tests/btrfs/221 line 35

Quoted 6 lines
tests/btrfs/221 new file +6 -0
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic

It's a btrfs specific test.

Thanks!

Quoted 6 lines

tests/btrfs/221 line 38

Quoted 4 lines
tests/btrfs/221 new file +3 -0
+_supported_os Linux
+
+_require_test

You don't need test_dev at all.

Yeah, I just realized that I used only scratch dev noy test dev. Thanks!

Quoted 14 lines

tests/btrfs/221 line 47

Quoted 10 lines
tests/btrfs/221 new file +9 -0
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+	echo "=== qgroup assign shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT

I'm not sure if _run_btrfs_util_prog is still recommended. IIRC nowadays we recommend to call $BTRFS_UTIL_PROG directly.

Quoted 1 line

Test case btrfs/193 would be the example.

It's good to replace it! Thanks.

Quoted 10 lines

tests/btrfs/221 line 52

Quoted 6 lines
tests/btrfs/221 new file +5 -0
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

"btrfs qgroup assign" can take path directly. This would save your some lines. E.g:

Quoted 7 lines
  # btrfs qgroup create 1/100 /mnt/btrfs/
  # btrfs qgroup assign /mnt/btrfs/ 1/100 /mnt/btrfs/
  # btrfs qgroup  show -pc /mnt/btrfs/
  qgroupid         rfer         excl parent  child
  --------         ----         ---- ------  -----
  0/5          16.00KiB     16.00KiB 1/100   ---
  1/100        16.00KiB     16.00KiB ---     0/5

Thanks for good tip!

Quoted 22 lines

tests/btrfs/221 line 56

Quoted 5 lines
tests/btrfs/221 new file +4 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT

Shouldn't this assign happens when we have shared extents between the two subvolumes?

Now you're just testing the basic qgroup functionality of accounting, not assign.

For real assign tests, what we want is either:
- After assign, qgroup accounting is still correct We don't need even to rescan.
And "btrfs check" will verify the numbers are correct.

- After assign, qgroup accounting is inconsistent
At least we should either have qgroup inconsistent bit set, or qgroup rescan kicked in automatically.
And "btrfs check" will skip the qgroup numbers.

Quoted 8 lines
Quoted 3 lines

But in your case, we're assigning two empty subovlumes into the same qgroup, then do some operations.
This only covers the "assign, no shared extents" case.

You mean that there should be some data with reflink before assigning? If so, the code below should be executed before assigning qgroups. Should test process be like this?
make submodules -> make data -> copy with reflink -> assign qgroup

Yep.

Furthermore, we should have qgroup enabled/rescanned before make subvolumes.

Quoted 61 lines
Quoted 34 lines

tests/btrfs/221 line 62

Quoted 8 lines
tests/btrfs/221 new file +6 -0
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+
+	_ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+	cp --reflink=always "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1 >> $seqres.full 2>&1
+
+	_scratch_unmount

Since you're unmounting here, why not keep the _scratch_mkfs and _scratch_unmount pair in the same function?

Quoted 9 lines
tests/btrfs/221 new file +9 -0
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+	echo "=== qgroup assign no shared test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT

tests/btrfs/221 line 81

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
+	_run_btrfs_util_prog qgroup assign 0/$subvolid 1/100 $SCRATCH_MNT
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT

No, we don't want rescan.

Quoted 1 line

And the timing is still wrong.

Yeah, I'll delete it.

Quoted 24 lines
Quoted 7 lines
tests/btrfs/221 new file +6 -0
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+# Test snapshot with assigning qgroup for submodule

tests/btrfs/221 line 97

Quoted 10 lines
tests/btrfs/221 new file +10 -0
+snapshot_test()
+{
+	echo "=== qgroup snapshot test ===" >> $seqres.full
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+
+	_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+
+	_run_btrfs_util_prog subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b
+	subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)

Even we're snapshotting on the source subvolume, since it's empty, we will only copy the root item, resulting two empty subvolumes without sharing anything.

You need to at least fill the source subvolumes with some data. It's better to bump the tree level with some inline extents.

Quoted 6 lines
Quoted 1 line

I should write some data before snapshot. is it right?

Right. That's the bare minimal.

Thanks,
qu

Thanks so much! I've written a new patch just before. Could you review it please?

Thanks,
Sidong

Quoted 57 lines
Quoted 56 lines

Thanks for all your comments.

Thanks,
Sidong

Quoted 47 lines

Thanks,
Qu

Quoted 42 lines
tests/btrfs/221 new file +24 -0
+
+	_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
+	_scratch_unmount
+
+	_run_btrfs_util_prog check $SCRATCH_DEV
+}
+
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_no_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+assign_shared_test
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
tests/btrfs/221.out new file +2 -0
new file mode 100644
index 00000000..aa4351cd
@@ -0,0 +1,2 @@
+QA output created by 221
+Silence is golden
tests/btrfs/group +1 -0
index 1b5fa695..cdda38f3 100644
@@ -222,3 +222,4 @@
 218 auto quick volume
 219 auto quick volume
 220 auto quick
+221 auto quick qgroup