diff mbox series

[2/5] common/btrfs: quota mode helpers

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

Commit Message

Boris Burkov July 5, 2023, 11:42 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 | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Anand Jain Sept. 22, 2023, 4:34 p.m. UTC | #1
On 06/07/2023 07:42, 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 | 43 +++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 43 insertions(+)
> 
> diff --git a/common/btrfs b/common/btrfs
> index 175b33aee..66c065a10 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -680,3 +680,46 @@ _require_btrfs_scratch_logical_resolve_v2()
>   	fi
>   	_scratch_unmount
>   }
> +
> +_qgroup_mode_file()
> +{
> +	local mnt=$1
> +
> +	uuid=$(findmnt -n -o UUID $mnt)
> +	echo /sys/fs/btrfs/${uuid}/qgroups/mode
> +}


> +
> +_qgroup_enabled_file()
> +{
> +	local mnt=$1
> +
> +	uuid=$(findmnt -n -o UUID $mnt)


> +	echo /sys/fs/btrfs/${uuid}/qgroups/enabled
> +}
> +


> +_qgroup_mode()
> +{
> +	local mnt=$1
> +
> +	if [ ! -f "$(_qgroup_enabled_file $mnt)" ]; then
> +		echo "disabled"
> +		return
> +	fi
> +
> +	if [ -f "$(_qgroup_mode_file $mnt)" ]; then
> +		cat $(_qgroup_mode_file $mnt)
> +	elif [ $(cat $(_qgroup_enabled_file $mnt)) -eq "1" ]; then
/> +		echo "qgroup"
> +	else
> +		echo "disabled" # should not be reachable, the enabled file won't exist.
> +	fi
> +}
> +
> +_require_scratch_qgroup()
> +{
> +	_scratch_mkfs >>$seqres.full 2>&1
> +	_scratch_mount
> +	_run_btrfs_util_prog quota enable $SCRATCH_MNT
> +	_check_regular_qgroup $SCRATCH_MNT || _notrun "not running normal qgroups"
> +	_scratch_unmount
> +}


Can you add _has_scratch_fs_sysfs() helper for scratch?  See for example 
_has_fs_sysfs().

So that you can do something like..

if [ _has_scratch_fs_sysfs qgroups/mode ]; then
	if [ $(_get_fs_sysfs_attr $mnt qgroups/mode) == 1 ]; then
		echo qgroup
	else
		echo something
else
	_notrun "qgroup unsupported"
fi


Thanks, Anand
diff mbox series

Patch

diff --git a/common/btrfs b/common/btrfs
index 175b33aee..66c065a10 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -680,3 +680,46 @@  _require_btrfs_scratch_logical_resolve_v2()
 	fi
 	_scratch_unmount
 }
+
+_qgroup_mode_file()
+{
+	local mnt=$1
+
+	uuid=$(findmnt -n -o UUID $mnt)
+	echo /sys/fs/btrfs/${uuid}/qgroups/mode
+}
+
+_qgroup_enabled_file()
+{
+	local mnt=$1
+
+	uuid=$(findmnt -n -o UUID $mnt)
+	echo /sys/fs/btrfs/${uuid}/qgroups/enabled
+}
+
+_qgroup_mode()
+{
+	local mnt=$1
+
+	if [ ! -f "$(_qgroup_enabled_file $mnt)" ]; then
+		echo "disabled"
+		return
+	fi
+
+	if [ -f "$(_qgroup_mode_file $mnt)" ]; then
+		cat $(_qgroup_mode_file $mnt)
+	elif [ $(cat $(_qgroup_enabled_file $mnt)) -eq "1" ]; then
+		echo "qgroup"
+	else
+		echo "disabled" # should not be reachable, the enabled file won't exist.
+	fi
+}
+
+_require_scratch_qgroup()
+{
+	_scratch_mkfs >>$seqres.full 2>&1
+	_scratch_mount
+	_run_btrfs_util_prog quota enable $SCRATCH_MNT
+	_check_regular_qgroup $SCRATCH_MNT || _notrun "not running normal qgroups"
+	_scratch_unmount
+}