btrfs/022: Add qgroup assign test
PATCH 1/1 btrfs/022: Add qgroup assign test
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tests/btrfs/022 +40 -0
@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test() +{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNT + + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync + + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a") + a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9') + + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match" +} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1
@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"
Signature · 1 line
2.25.1
Quoted 7 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
Signed-off-by Sidong Yang <[email protected]>
We usually don't add new test case to existing tests, as that may make a PASSed test starting to FAIL, which looks like a regression.
Quoted 9 lines
--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +0
-0
tests/btrfs/022 _limit_test_noexceed() · line 114
Quoted 5 lines
tests/btrfs/022 +2
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test()
Local function names don't need to be prefixed with "_".
tests/btrfs/022 _limit_test_noexceed() · line 117
Quoted 3 lines
tests/btrfs/022 +3
-0+{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
The helpers based on run_check are not recommended, please just open-coded btrfs subvolume command and filter the output when necessary. j
Quoted 5 lines
tests/btrfs/022 +5
-0+ _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT
tests/btrfs/022 _limit_test_noexceed() · line 132
Quoted 10 lines
tests/btrfs/022 +10
-0+ subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNT + + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync
Just fsync the individule files if possible.
tests/btrfs/022 _limit_test_noexceed() · line 135
Quoted 3 lines
tests/btrfs/022 +3
-0+ + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a") + a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9')
$AWK_PROG
tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 9 lines
tests/btrfs/022 +9
-0+ + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"
Print the actual number and expected number as well?
Thanks,
Eryu
Quoted 20 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"Signature · 1 line
2.25.1
Quoted 9 lines · Eryu Guan
Quoted 7 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
Signed-off-by Sidong Yang <[email protected]>
Hi Eryu.
Thanks for review!
Quoted 2 lines
We usually don't add new test case to existing tests, as that may make a PASSed test starting to FAIL, which looks like a regression.
Okay, If then, is it okay for writing a new script for this?
Quoted 13 lines
Quoted 13 lines
--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +0
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" }
Quoted 4 lines
tests/btrfs/022 _limit_test_noexceed() · line 114
Quoted 2 lines
tests/btrfs/022 +2
-0+#basic assign testing +_parent_assign_test()Local function names don't need to be prefixed with "_".
okay, thanks.
Quoted 17 lines
tests/btrfs/022 _limit_test_noexceed() · line 117
Quoted 4 lines
tests/btrfs/022 +3
-0+{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/aThe helpers based on
run_checkare not recommended, please just open-coded btrfs subvolume command and filter the output when necessary. jQuoted 9 lines
tests/btrfs/022 +9
-0+ _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT +
Quoted 8 lines
tests/btrfs/022 _limit_test_noexceed() · line 132
Quoted 6 lines
tests/btrfs/022 +6
-0+ _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNT + + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + syncJust fsync the individule files if possible.
Thanks. I'll fix it like this.
sync $SCRATCH_MNT/b/file
Quoted 7 lines
tests/btrfs/022 _limit_test_noexceed() · line 135
Quoted 5 lines
tests/btrfs/022 +3
-0+ + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a") + a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9')$AWK_PROG
Okay! awk -> $AWK_PROG
Quoted 12 lines
tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 10 lines
tests/btrfs/022 +9
-0+ + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"Print the actual number and expected number as well?
Yes, you mean writing like this?
echo "a_shared = $a_shared" >> $seqres.full echo "b_shared = $b_shared" >> $seqres.full echo "sum = $sum" >> $seqres.full echo "q_shared = $q_shared" >> $seqres.full
and I'm just curious that we don't need to cleanup qgroup environment after testing finished?
Thanks,
Sidong
Quoted 24 lines
Thanks,
EryuQuoted 20 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"Signature · 1 line
2.25.1
Quoted 5 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
A little surprised that I haven't submitted such test case, especially we had a fix in kernel.
cbab8ade585a ("btrfs: qgroup: mark qgroup inconsistent if we're inherting snapshot to a new qgroup")
Despite the comment from Eryu, some btrfs specific comment inlined below.
Quoted 20 lines
Signed-off-by Sidong Yang <[email protected]>--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +6
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test() +{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a + _run_btrfs_util_prog quota enable $SCRATCH_MNT
tests/btrfs/022 _limit_test_noexceed() · line 128
Quoted 10 lines
tests/btrfs/022 +10
-0+ subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNT
The coverage is not good enough.
Qgroup assign (or inherit) happens not only during "btrfs qgroup assign" but also "btrfs subvolume snapshot -i".
And we also need to consider cases like shared extents between two subvolumes (either caused by snapshot or reflink).
That means we have two factors, assign or snapshot -i, subvolumes with shared extents or not.
That means we need at least 3 combinations:
- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents
(snapshot -i, no shared extents is invalid, as snapshot will always cause shared extents)
Quoted 6 lines
tests/btrfs/022 +6
-0+ + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync + + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a")
tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 10 lines
tests/btrfs/022 +10
-0+ a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9') + + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"
Nope, we don't need to do such complex checking all by ourselves.
Just let "btrfs check" to handle it, as it will also check the qgroup numbers.
Thanks,
Qu
Quoted 19 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"
Quoted 8 lines · Qu Wenruo
Quoted 5 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
Hi Qu!
Thanks for review!
Quoted 6 lines
A little surprised that I haven't submitted such test case, especially we had a fix in kernel.
cbab8ade585a("btrfs: qgroup: mark qgroup inconsistent if we're inherting snapshot to a new qgroup")
Yeah, there was no test code for qgroup.
Quoted 46 lines
Despite the comment from Eryu, some btrfs specific comment inlined below.
Quoted 20 lines
Signed-off-by Sidong Yang <[email protected]>--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +6
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test() +{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a + _run_btrfs_util_prog quota enable $SCRATCH_MNTtests/btrfs/022 _limit_test_noexceed() · line 128
Quoted 10 lines
tests/btrfs/022 +10
-0+ subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNTThe coverage is not good enough.
Qgroup assign (or inherit) happens not only during "btrfs qgroup assign" but also "btrfs subvolume snapshot -i".
And we also need to consider cases like shared extents between two subvolumes (either caused by snapshot or reflink).
That means we have two factors, assign or snapshot -i, subvolumes with shared extents or not.
That means we need at least 3 combinations:
Quoted 6 lines
- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents(snapshot -i, no shared extents is invalid, as snapshot will always cause shared extents)
Thanks for good example!
but there is a question. How can I make shared extents in test code? It's okay that write some file and make a snapshot from it?
Quoted 20 lines
Quoted 7 lines
tests/btrfs/022 +6
-0+ + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync + + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a")tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 10 lines
tests/btrfs/022 +10
-0+ a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9') + + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"Nope, we don't need to do such complex checking all by ourselves.
Quoted 2 lines
Just let "btrfs check" to handle it, as it will also check the qgroup numbers.
It's very easy way to check! Thanks.
Taken together, I'll work for new test case that tests qgroup cases.
Sincerely,
Sidong
Quoted 24 lines
Thanks,
QuQuoted 19 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"
Quoted 72 lines · Sidong Yang
Quoted 8 lines · Qu Wenruo
Quoted 5 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
Hi Qu!
Thanks for review!Quoted 6 lines
A little surprised that I haven't submitted such test case, especially we had a fix in kernel.
cbab8ade585a("btrfs: qgroup: mark qgroup inconsistent if we're inherting snapshot to a new qgroup")Yeah, there was no test code for qgroup.
Quoted 50 lines
Despite the comment from Eryu, some btrfs specific comment inlined below.
Quoted 20 lines
Signed-off-by Sidong Yang <[email protected]>--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +6
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test() +{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a + _run_btrfs_util_prog quota enable $SCRATCH_MNTtests/btrfs/022 _limit_test_noexceed() · line 128
Quoted 10 lines
tests/btrfs/022 +10
-0+ subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNTThe coverage is not good enough.
Qgroup assign (or inherit) happens not only during "btrfs qgroup assign" but also "btrfs subvolume snapshot -i".
And we also need to consider cases like shared extents between two subvolumes (either caused by snapshot or reflink).
That means we have two factors, assign or snapshot -i, subvolumes with shared extents or not.
That means we need at least 3 combinations:- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents
Quoted 5 lines
Quoted 2 lines
(snapshot -i, no shared extents is invalid, as snapshot will always cause shared extents)
Thanks for good example!
but there is a question. How can I make shared extents in test code?
Reflink is the most simple solution.
Quoted 1 line
It's okay that write some file and make a snapshot from it?
If you only want some shared extents, reflink is easier than snapshot.
Thanks,
Qu
Quoted 55 lines
Quoted 21 lines
Quoted 8 lines
tests/btrfs/022 +6
-0+ + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync + + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a")tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 10 lines
tests/btrfs/022 +10
-0+ a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9') + + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"Nope, we don't need to do such complex checking all by ourselves.
Quoted 2 lines
Just let "btrfs check" to handle it, as it will also check the qgroup numbers.
It's very easy way to check! Thanks.
Taken together, I'll work for new test case that tests qgroup cases.
Sincerely,
SidongQuoted 24 lines
Thanks,
QuQuoted 19 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"
Quoted 78 lines · Qu Wenruo
Quoted 75 lines · Sidong Yang
Quoted 8 lines · Qu Wenruo
Quoted 5 lines · Sidong Yang
The btrfs/022 test is basic test about qgroup. but it doesn't have test with qgroup assign function. This patch adds parent assign test. parent assign test make two subvolumes and a qgroup for assign. Assign two subvolumes with a qgroup and check that quota of group has same value with sum of two subvolumes.
Hi Qu!
Thanks for review!Quoted 6 lines
A little surprised that I haven't submitted such test case, especially we had a fix in kernel.
cbab8ade585a("btrfs: qgroup: mark qgroup inconsistent if we're inherting snapshot to a new qgroup")Yeah, there was no test code for qgroup.
Quoted 52 lines
Despite the comment from Eryu, some btrfs specific comment inlined below.
Quoted 20 lines
Signed-off-by Sidong Yang <[email protected]>--- tests/btrfs/022 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tests/btrfs/022 +6
-0@@ -110,6 +110,40 @@ _limit_test_noexceed() [ $? -eq 0 ] || _fail "should have been allowed to write" } +#basic assign testing +_parent_assign_test() +{ + echo "=== parent assign test ===" >> $seqres.full + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/a + _run_btrfs_util_prog quota enable $SCRATCH_MNTtests/btrfs/022 _limit_test_noexceed() · line 128
Quoted 10 lines
tests/btrfs/022 +10
-0+ subvolid_a=$(_btrfs_get_subvolid $SCRATCH_MNT a) + + _run_btrfs_util_prog subvolume create $SCRATCH_MNT/b + _run_btrfs_util_prog quota enable $SCRATCH_MNT + subvolid_b=$(_btrfs_get_subvolid $SCRATCH_MNT b) + + _run_btrfs_util_prog qgroup create 1/100 $SCRATCH_MNT + + _run_btrfs_util_prog qgroup assign 0/$subvolid_a 1/100 $SCRATCH_MNT + _run_btrfs_util_prog qgroup assign 0/$subvolid_b 1/100 $SCRATCH_MNTThe coverage is not good enough.
Qgroup assign (or inherit) happens not only during "btrfs qgroup assign" but also "btrfs subvolume snapshot -i".
And we also need to consider cases like shared extents between two subvolumes (either caused by snapshot or reflink).
That means we have two factors, assign or snapshot -i, subvolumes with shared extents or not.
That means we need at least 3 combinations:- assign, no shared extents
- assign, shared extents
- snapshot -i, shared extents(snapshot -i, no shared extents is invalid, as snapshot will always cause shared extents)
Quoted 8 lines
Quoted 2 lines
Thanks for good example!
but there is a question. How can I make shared extents in test code?Reflink is the most simple solution.
Quoted 1 line
It's okay that write some file and make a snapshot from it?
If you only want some shared extents, reflink is easier than snapshot.
I've written a new patch v2 for this. Could you review it?
Thanks,
Sidong
Quoted 60 lines
Thanks,
QuQuoted 55 lines
Quoted 21 lines
Quoted 8 lines
tests/btrfs/022 +6
-0+ + _ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1 + _ddt of=$SCRATCH_MNT/b/file bs=4M count=1 >> $seqres.full 2>&1 + sync + + a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_a")tests/btrfs/022 _limit_test_noexceed() · line 144
Quoted 10 lines
tests/btrfs/022 +10
-0+ a_shared=$(echo $a_shared | awk '{ print $2 }' | tr -dc '0-9') + + b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid_b") + b_shared=$(echo $b_shared | awk '{ print $2 }' | tr -dc '0-9') + sum=$(expr $b_shared + $a_shared) + + q_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "1/100") + q_shared=$(echo $q_shared | awk '{ print $2 }' | tr -dc '0-9') + + [ $sum -eq $q_shared ] || _fail "shared values don't match"Nope, we don't need to do such complex checking all by ourselves.
Quoted 2 lines
Just let "btrfs check" to handle it, as it will also check the qgroup numbers.
It's very easy way to check! Thanks.
Taken together, I'll work for new test case that tests qgroup cases.
Sincerely,
SidongQuoted 24 lines
Thanks,
QuQuoted 19 lines
tests/btrfs/022 +8
-0+} + units=`_btrfs_qgroup_units` _scratch_mkfs > /dev/null 2>&1@@ -133,6 +167,12 @@ _check_scratch_fs _scratch_mkfs > /dev/null 2>&1 _scratch_mount _limit_test_noexceed +_scratch_unmount +_check_scratch_fs + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount +_parent_assign_test # success, all done echo "Silence is golden"