btrfs: Add new test for setting the stripe size.
PATCH v2 1/1 btrfs: Add new test for setting the stripe size.
Summary:
Add new testcase for testing the new btrfs sysfs knob to change the stripe size. The new knob uses /sys/fs/btrfs/<UUID>/allocation/<block type>/stripe_size.
The test case implements three different cases:
- Test allocation with the default stripe size
- Test allocation after increasing the stripe size
- Test allocation when the free space is smaller than the stripe size.
Note: this test needs to force the allocation of space. It uses the /sys/fs/btrfs/<UUID>/allocation/<block type>/force_chunk_alloc knob.
Testing:
The test has been run with volumes of different sizes.
---
V2: - added new functions to common/btrfs and use them in the new test
- _require_btrfs_sysfs_attr - Make sure btrfs supports a sysfs setting
- _get_btrfs_sysfs_attr - Read sysfs value
- _set_btrfs_sysfs_attr - Write sysfs value
- create file system of required size with _scratch_mkfs_sized
- use shortened error message
- Remove last logging message
--- common/btrfs | 69 ++++++++++ tests/btrfs/248 | 302 ++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/248.out | 10 ++ 3 files changed, 381 insertions(+) create mode 100755 tests/btrfs/248 create mode 100644 tests/btrfs/248.out
common/btrfs +69 -0
@@ -445,3 +445,72 @@ _scratch_btrfs_is_zoned() [ `_zone_type ${SCRATCH_DEV}` != "none" ] && return 0 return 1 } + +# Print the content of /sys/fs/btrfs/$UUID/$ATTR +# +# All arguments are necessary, and in this order: +# - mnt: mount point name, e.g. $SCRATCH_MNT +# - attr: path name under /sys/fs/btrfs/$uuid/$attr +# +# Usage example: +# _get_btrfs_sysfs_attr /mnt/scratch allocation/data/stripe_size +_get_btrfs_sysfs_attr() +{ + local mnt=$1 + local attr=$2 + + if [ ! -e "$mnt" -o -z "$attr" ];then + _fail "Usage: _get_btrfs_sysfs_attr <mounted_directory> <attr>" + fi + + local uuid=$(findmnt -n -o UUID ${mnt}) + cat /sys/fs/btrfs/${uuid}/${attr} +} + +# Write "content" into /sys/fs/btrfs/$UUID/$ATTR +# +# All arguments are necessary, and in this order: +# - mnt: mount point name, e.g. $SCRATCH_MNT +# - attr: path name under /sys/fs/btrfs/$uuid/$attr +# - content: the content of $attr +# +# Usage example: +# _set_btrfs_sysfs_attr /mnt/scratch allocation/data/stripe_size +_set_btrfs_sysfs_attr() +{ + local mnt=$1 + shift + local attr=$1 + shift + local content="$*" + + if [ ! -e "$mnt" -o -z "$attr" -o -z "$content" ];then + _fail "Usage: _set_btrfs_sysfs_attr <mounted_directory> <attr> <content>" + fi + + local uuid=$(findmnt -n -o UUID ${mnt}) + echo "$content" > /sys/fs/btrfs/${uuid}/${attr} +} + +# Verify if the sysfs entry in /sys/fs/btrfs/$UUID/$ATTR exists +# +# All arguments are necessary, and in this order: +# - mnt: mount point name, e.g. $SCRATCH_MNT +# - attr: path name under /sys/fs/btrfs/$uuid/$attr +# +# Usage example: +# _require_btrfs_sysfs_attr /mnt/scratch allocation/data/stripe_size +_require_btrfs_sysfs_attr() +{ + local mnt=$1 + local attr=$2 + + if [ ! -e "$mnt" -o -z "$attr" ];then + _fail "Usage: _get_btrfs_sysfs_attr <mounted_directory> <attr>" + fi + + local uuid=$(findmnt -n -o UUID ${mnt}) + if [[ ! -e /sys/fs/btrfs/${uuid}/${attr} ]]; then + _notrun "Btrfs does not support sysfs $attr" + fi +}
tests/btrfs/248 new file +302 -0
302 lines not on this page · raw message
tests/btrfs/248.out new file +10 -0
@@ -0,0 +1,10 @@ +QA output created by 248 +Capture default stripe sizes. +Check free space. +First allocation. +Second allocation. +Calculate request size so last memory allocation cannot be completely fullfilled. +Third allocation. +Verify first allocation. +Verify second allocation. +Verify third allocation.
Signature · 1 line
2.30.2