btrfs: Add new test for qgroup assign functionality
authorSidong Yang <realwakka@gmail.com>
Sun, 11 Oct 2020 06:20:19 +0000 (06:20 +0000)
committerEryu Guan <guaneryu@gmail.com>
Sun, 18 Oct 2020 11:10:48 +0000 (19:10 +0800)
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 <wqu@suse.com>
Cc: Eryu Guan <guan@eryu.me>
Signed-off-by: Sidong Yang <realwakka@gmail.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/224 [new file with mode: 0755]
tests/btrfs/224.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/224 b/tests/btrfs/224
new file mode 100755 (executable)
index 0000000..ecf6a46
--- /dev/null
@@ -0,0 +1,115 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Sidong Yang.  All Rights Reserved.
+#
+# FS QA Test 224
+#
+# 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 btrfs
+
+_require_scratch
+_require_btrfs_qgroup_report
+_require_cp_reflink
+
+# Test assign qgroup for submodule with shared extents by reflink
+assign_shared_test()
+{
+       _scratch_mkfs > /dev/null 2>&1
+       _scratch_mount
+
+       echo "=== qgroup assign shared test ===" >> $seqres.full
+       $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
+       $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
+
+       $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a >> $seqres.full
+       $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/b >> $seqres.full
+
+       _ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+       _cp_reflink "$SCRATCH_MNT"/a/file1 "$SCRATCH_MNT"/b/file1
+
+       $BTRFS_UTIL_PROG qgroup create 1/100 $SCRATCH_MNT
+       $BTRFS_UTIL_PROG qgroup assign $SCRATCH_MNT/a 1/100 $SCRATCH_MNT
+       $BTRFS_UTIL_PROG qgroup assign $SCRATCH_MNT/b 1/100 $SCRATCH_MNT
+
+       _scratch_unmount
+       _check_scratch_fs
+}
+
+# Test assign qgroup for submodule without shared extents
+assign_no_shared_test()
+{
+       _scratch_mkfs > /dev/null 2>&1
+       _scratch_mount
+
+       echo "=== qgroup assign no shared test ===" >> $seqres.full
+       $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
+       $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
+
+       $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a >> $seqres.full
+       $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/b >> $seqres.full
+
+       $BTRFS_UTIL_PROG qgroup create 1/100 $SCRATCH_MNT
+       $BTRFS_UTIL_PROG qgroup assign $SCRATCH_MNT/a 1/100 $SCRATCH_MNT
+       $BTRFS_UTIL_PROG qgroup assign $SCRATCH_MNT/b 1/100 $SCRATCH_MNT
+
+       _scratch_unmount
+       _check_scratch_fs
+}
+
+# Test snapshot with assigning qgroup for submodule
+snapshot_test()
+{
+       _scratch_mkfs > /dev/null 2>&1
+       _scratch_mount
+
+       echo "=== qgroup snapshot test ===" >> $seqres.full
+       $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
+       $BTRFS_UTIL_PROG quota rescan -w $SCRATCH_MNT >> $seqres.full
+
+       $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/a >> $seqres.full
+       _ddt of="$SCRATCH_MNT"/a/file1 bs=1M count=1 >> $seqres.full 2>&1
+       subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
+       $BTRFS_UTIL_PROG subvolume snapshot -i 0/$subvolid $SCRATCH_MNT/a $SCRATCH_MNT/b >> $seqres.full
+
+       _scratch_unmount
+       _check_scratch_fs
+}
+
+
+assign_no_shared_test
+
+assign_shared_test
+
+snapshot_test
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/btrfs/224.out b/tests/btrfs/224.out
new file mode 100644 (file)
index 0000000..806f433
--- /dev/null
@@ -0,0 +1,2 @@
+QA output created by 224
+Silence is golden
index 96e101a..9ad33ba 100644 (file)
 221 auto quick send
 222 auto quick send
 223 auto quick replace trim
+224 auto quick qgroup