diff mbox series

[v3,2/6] btrfs: quota mode helpers

Message ID 3c6f4cd053ccd2deb8ee459f5b0e5eb6fd877487.1695856385.git.boris@bur.io (mailing list archive)
State New, archived
Headers show
Series btrfs: simple quotas fstests | expand

Commit Message

Boris Burkov Sept. 27, 2023, 11:14 p.m. UTC
To facilitate skipping tests depending on the qgroup mode after mkfs,
add support for figuring out the mode. This cannot just rely on the new
sysfs file, since it might not be present on older kernels.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 common/btrfs | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Anand Jain Sept. 28, 2023, 1:07 p.m. UTC | #1
On 28/09/2023 07:14, Boris Burkov wrote:
> To facilitate skipping tests depending on the qgroup mode after mkfs,
> add support for figuring out the mode. This cannot just rely on the new
> sysfs file, since it might not be present on older kernels.
> 
> Signed-off-by: Boris Burkov <boris@bur.io>
> ---
>   common/btrfs | 38 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 38 insertions(+)
> 
> diff --git a/common/btrfs b/common/btrfs
> index c9903a413..37796cc6e 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -689,3 +689,41 @@ _require_btrfs_scratch_logical_resolve_v2()
>   	fi
>   	_scratch_unmount
>   }
> +
> +_qgroup_mode()
> +{
> +	local dev=$1
> +
> +	if [ ! -b "$dev" ]; then
> +		_fail "Usage: _qgroup_mode <mounted_device>"
> +	fi
> +
> +	if _has_fs_sysfs_attr $dev /qgroups/mode; then
> +		_get_fs_sysfs_attr $dev qgroups/mode
> +	else
> +		echo "disabled"
> +	fi
> +}
> +
> +_check_regular_qgroup()
> +{
> +	_qgroup_mode "$@" | grep -q 'qgroup'
> +}
> +
> +_require_scratch_qgroup()
> +{
> +	_scratch_mkfs >>$seqres.full 2>&1
> +	_scratch_mount
> +	_run_btrfs_util_prog quota enable $SCRATCH_MNT
> +	_check_regular_qgroup $SCRATCH_DEV || _notrun "not running normal qgroups"
> +	_scratch_unmount
> +}
> +


> +_require_scratch_enable_simple_quota()
> +{
> +    _scratch_mkfs >>$seqres.full 2>&1
> +    _scratch_mount
> +	_qgroup_mode $SCRATCH_DEV | grep 'squota' && _notrun "cannot enable simple quota; on by default"
> +    $BTRFS_UTIL_PROG quota enable --simple $SCRATCH_MNT || _notrun "simple quotas not available"
> +	_scratch_unmount
> +}

The rest of the patches look good so far. However, the indentation is 
mixed above; lines have a combination of spaces and tabs. Please help 
fix it if you are resending the whole series, or else I will fix it 
while merging.

Thanks, Anand
diff mbox series

Patch

diff --git a/common/btrfs b/common/btrfs
index c9903a413..37796cc6e 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -689,3 +689,41 @@  _require_btrfs_scratch_logical_resolve_v2()
 	fi
 	_scratch_unmount
 }
+
+_qgroup_mode()
+{
+	local dev=$1
+
+	if [ ! -b "$dev" ]; then
+		_fail "Usage: _qgroup_mode <mounted_device>"
+	fi
+
+	if _has_fs_sysfs_attr $dev /qgroups/mode; then
+		_get_fs_sysfs_attr $dev qgroups/mode
+	else
+		echo "disabled"
+	fi
+}
+
+_check_regular_qgroup()
+{
+	_qgroup_mode "$@" | grep -q 'qgroup'
+}
+
+_require_scratch_qgroup()
+{
+	_scratch_mkfs >>$seqres.full 2>&1
+	_scratch_mount
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_check_regular_qgroup $SCRATCH_DEV || _notrun "not running normal qgroups"
+	_scratch_unmount
+}
+
+_require_scratch_enable_simple_quota()
+{
+    _scratch_mkfs >>$seqres.full 2>&1
+    _scratch_mount
+	_qgroup_mode $SCRATCH_DEV | grep 'squota' && _notrun "cannot enable simple quota; on by default"
+    $BTRFS_UTIL_PROG quota enable --simple $SCRATCH_MNT || _notrun "simple quotas not available"
+	_scratch_unmount
+}