Files
apfstests/tests/btrfs/022
T

141 lines
4.1 KiB
Bash
Raw Normal View History

2013-12-03 10:29:29 +11:00
#! /bin/bash
2018-06-09 11:35:50 +10:00
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2013 Fusion IO. All Rights Reserved.
#
2013-12-03 10:29:29 +11:00
# FS QA Test No. 022
#
# Test the basic 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
_supported_fs btrfs
_supported_os Linux
_require_scratch
_require_btrfs_qgroup_report
2013-12-03 10:29:29 +11:00
rm -f $seqres.full
# Test to make sure we can actually turn it on and it makes sense
_basic_test()
{
2020-02-07 09:59:42 +08:00
echo "=== basic test ===" >> $seqres.full
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
_run_btrfs_util_prog quota enable $SCRATCH_MNT/a
_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
2013-12-03 10:29:29 +11:00
subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep $subvolid >> \
2013-12-03 10:29:29 +11:00
$seqres.full 2>&1
[ $? -eq 0 ] || _fail "couldn't find our subvols quota group"
run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
$FSSTRESS_AVOID
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT/a \
2013-12-03 10:29:29 +11:00
$SCRATCH_MNT/b
# the shared values of both the original subvol and snapshot should
# match
2020-02-07 09:59:41 +08:00
a_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
2013-12-03 10:29:29 +11:00
a_shared=$(echo $a_shared | awk '{ print $2 }')
2020-02-07 09:59:42 +08:00
echo "subvol a id=$subvolid" >> $seqres.full
2013-12-03 10:29:29 +11:00
subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT b)
2020-02-07 09:59:42 +08:00
echo "subvol b id=$subvolid" >> $seqres.full
2020-02-07 09:59:41 +08:00
b_shared=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
2013-12-03 10:29:29 +11:00
b_shared=$(echo $b_shared | awk '{ print $2 }')
2020-02-07 09:59:42 +08:00
$BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT >> $seqres.full
2013-12-03 10:29:29 +11:00
[ $b_shared -eq $a_shared ] || _fail "shared values don't match"
}
#enable quotas, do some work, check our values and then rescan and make sure we
#come up with the same answer
_rescan_test()
{
2020-02-07 09:59:42 +08:00
echo "=== rescan test ===" >> $seqres.full
2013-12-03 10:29:29 +11:00
# first with a blank subvol
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
_run_btrfs_util_prog quota enable $SCRATCH_MNT/a
2013-12-03 10:29:29 +11:00
subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
run_check $FSSTRESS_PROG -d $SCRATCH_MNT/a -w -p 1 -n 2000 \
$FSSTRESS_AVOID
sync
2020-02-07 09:59:41 +08:00
output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
2020-02-07 09:59:42 +08:00
echo "qgroup values before rescan: $output" >> $seqres.full
2013-12-03 10:29:29 +11:00
refer=$(echo $output | awk '{ print $2 }')
excl=$(echo $output | awk '{ print $3 }')
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
2020-02-07 09:59:41 +08:00
output=$($BTRFS_UTIL_PROG qgroup show $units $SCRATCH_MNT | grep "0/$subvolid")
2020-02-07 09:59:42 +08:00
echo "qgroup values after rescan: $output" >> $seqres.full
2013-12-03 10:29:29 +11:00
[ $refer -eq $(echo $output | awk '{ print $2 }') ] || \
_fail "reference values don't match after rescan"
[ $excl -eq $(echo $output | awk '{ print $3 }') ] || \
_fail "exclusive values don't match after rescan"
}
#basic exceed limit testing
_limit_test_exceed()
2013-12-03 10:29:29 +11:00
{
2020-02-07 09:59:42 +08:00
echo "=== limit exceed test ===" >> $seqres.full
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
_run_btrfs_util_prog quota enable $SCRATCH_MNT
2013-12-03 10:29:29 +11:00
subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
2017-02-06 15:55:39 +08:00
_ddt of=$SCRATCH_MNT/a/file bs=10M count=1 >> $seqres.full 2>&1
2013-12-03 10:29:29 +11:00
[ $? -ne 0 ] || _fail "quota should have limited us"
}
#basic noexceed limit testing
_limit_test_noexceed()
{
2020-02-07 09:59:42 +08:00
echo "=== limit not exceed test ===" >> $seqres.full
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog subvolume create $SCRATCH_MNT/a
_run_btrfs_util_prog quota enable $SCRATCH_MNT
subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT a)
2014-03-13 15:17:44 +11:00
_run_btrfs_util_prog qgroup limit 5M 0/$subvolid $SCRATCH_MNT
2017-02-06 15:55:39 +08:00
_ddt of=$SCRATCH_MNT/a/file bs=4M count=1 >> $seqres.full 2>&1
2013-12-03 10:29:29 +11:00
[ $? -eq 0 ] || _fail "should have been allowed to write"
}
units=`_btrfs_qgroup_units`
2013-12-03 10:29:29 +11:00
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
_basic_test
_scratch_unmount
_check_scratch_fs
2013-12-03 10:29:29 +11:00
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
_rescan_test
_scratch_unmount
_check_scratch_fs
2013-12-03 10:29:29 +11:00
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
_limit_test_exceed
_scratch_unmount
_check_scratch_fs
_scratch_mkfs > /dev/null 2>&1
_scratch_mount
_limit_test_noexceed
2013-12-03 10:29:29 +11:00
# success, all done
echo "Silence is golden"
status=0
exit