diff mbox series

[3/6,v3] common/btrfs: add helper _has_btrfs_sysfs_feature_attr

Message ID 077b252e8affc50ad3d7826d57ba42a2a8746d13.1698674332.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series btrfs/219 cloned-device mount capability update | expand

Commit Message

Anand Jain Oct. 30, 2023, 2:15 p.m. UTC
With this helper, btrfs test cases can now check if a particular feature
is implemented in the kernel.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 common/btrfs | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Filipe Manana Oct. 30, 2023, 4:23 p.m. UTC | #1
On Mon, Oct 30, 2023 at 2:15 PM Anand Jain <anand.jain@oracle.com> wrote:
>
> With this helper, btrfs test cases can now check if a particular feature
> is implemented in the kernel.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>  common/btrfs | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/common/btrfs b/common/btrfs
> index c3bffd2ae3f7..fbc26181f7bc 100644
> --- a/common/btrfs
> +++ b/common/btrfs
> @@ -753,3 +753,15 @@ _require_scratch_enable_simple_quota()
>                                         _notrun "simple quotas not available"
>         _scratch_unmount
>  }
> +
> +_has_btrfs_sysfs_feature_attr()
> +{
> +       local feature_attr=$1
> +
> +       [ -z $feature_attr ] && \
> +               _fail "Missing feature name argument for _has_btrfs_sysfs_attr"
> +
> +       modprobe btrfs &> /dev/null
> +
> +       test -e /sys/fs/btrfs/features/$feature_attr
> +}

We already have _require_btrfs_fs_feature() to do exactly this.
Tried it in patch 5/6 and it works perfectly...

Thanks.

> --
> 2.39.3
>
Anand Jain Oct. 30, 2023, 11:29 p.m. UTC | #2
>> +_has_btrfs_sysfs_feature_attr()
>> +{
>> +       local feature_attr=$1
>> +
>> +       [ -z $feature_attr ] && \
>> +               _fail "Missing feature name argument for _has_btrfs_sysfs_attr"
>> +
>> +       modprobe btrfs &> /dev/null
>> +
>> +       test -e /sys/fs/btrfs/features/$feature_attr
>> +}
> 
> We already have _require_btrfs_fs_feature() to do exactly this.
> Tried it in patch 5/6 and it works perfectly...

I noticed that. But, _require_btrfs_fs_feature() triggers _notrun()
when the feature is absent in the kernel. Given our need to run the
testcase with and without temp-fsid, it is not suitable.

Thanks, Anand
Filipe Manana Oct. 31, 2023, 11:34 a.m. UTC | #3
On Mon, Oct 30, 2023 at 11:30 PM Anand Jain <anand.jain@oracle.com> wrote:
>
>
> >> +_has_btrfs_sysfs_feature_attr()
> >> +{
> >> +       local feature_attr=$1
> >> +
> >> +       [ -z $feature_attr ] && \
> >> +               _fail "Missing feature name argument for _has_btrfs_sysfs_attr"
> >> +
> >> +       modprobe btrfs &> /dev/null
> >> +
> >> +       test -e /sys/fs/btrfs/features/$feature_attr
> >> +}
> >
> > We already have _require_btrfs_fs_feature() to do exactly this.
> > Tried it in patch 5/6 and it works perfectly...
>
> I noticed that. But, _require_btrfs_fs_feature() triggers _notrun()
> when the feature is absent in the kernel. Given our need to run the
> testcase with and without temp-fsid, it is not suitable.

Yes, nevermind. It's fine then.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

>
> Thanks, Anand
>
diff mbox series

Patch

diff --git a/common/btrfs b/common/btrfs
index c3bffd2ae3f7..fbc26181f7bc 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -753,3 +753,15 @@  _require_scratch_enable_simple_quota()
 					_notrun "simple quotas not available"
 	_scratch_unmount
 }
+
+_has_btrfs_sysfs_feature_attr()
+{
+	local feature_attr=$1
+
+	[ -z $feature_attr ] && \
+		_fail "Missing feature name argument for _has_btrfs_sysfs_attr"
+
+	modprobe btrfs &> /dev/null
+
+	test -e /sys/fs/btrfs/features/$feature_attr
+}