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

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



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@xxxxxx>
---
  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



[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux