diff mbox series

syscalls/statx04: use stx_attributes_mask before test

Message ID 1571975625-6322-1-git-send-email-xuyang2018.jy@cn.fujitsu.com
State Rejected
Headers show
Series syscalls/statx04: use stx_attributes_mask before test | expand

Commit Message

Yang Xu Oct. 25, 2019, 3:53 a.m. UTC
stx_attributes_mask shows what's supported in stx_attributes.
Set supp_{append,compr,immutable,nodump} attributes only on filesystems
which actually support it.

Also merge duplicate code.

---------------
v2->v3:
1.add kernel version check for stx_attributes_mask
2. use test_flag(int) instead of test_flagged and test_unflagged
---------------

Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/kernel/syscalls/statx/statx04.c | 158 +++++++++++++---------
 1 file changed, 93 insertions(+), 65 deletions(-)

Comments

Yang Xu Oct. 31, 2019, 10:03 a.m. UTC | #1
Hi All

Ping.

> stx_attributes_mask shows what's supported in stx_attributes.
> Set supp_{append,compr,immutable,nodump} attributes only on filesystems
> which actually support it.
>
> Also merge duplicate code.
>
> ---------------
> v2->v3:
> 1.add kernel version check for stx_attributes_mask
> 2. use test_flag(int) instead of test_flagged and test_unflagged
> ---------------
>
> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> ---
>   testcases/kernel/syscalls/statx/statx04.c | 158 +++++++++++++---------
>   1 file changed, 93 insertions(+), 65 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/statx/statx04.c b/testcases/kernel/syscalls/statx/statx04.c
> index 71de734f5..c0fa06d46 100644
> --- a/testcases/kernel/syscalls/statx/statx04.c
> +++ b/testcases/kernel/syscalls/statx/statx04.c
> @@ -34,85 +34,70 @@
>   #define TESTDIR_UNFLAGGED MOUNT_POINT"/test_dir2"
>   
>   static int fd, clear_flags;
> +static int supp_compr;
> +static int supp_append;
> +static int supp_immutable;
> +static int supp_nodump;
>   
> -static void test_flagged(void)
> +static void test_flag(int flag)
>   {
>   	struct statx buf;
>   
> -	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
> -	if (TST_RET == 0)
> -		tst_res(TPASS,
> -			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
> -	else
> -		tst_brk(TFAIL | TTERRNO,
> -			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
> -
> -	if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
> -		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is not set");
> -
> -	if (buf.stx_attributes & STATX_ATTR_APPEND)
> -		tst_res(TPASS, "STATX_ATTR_APPEND flag is set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_APPEND flag is not set");
> -
> -	if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
> -		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is not set");
> -
> -	if (buf.stx_attributes & STATX_ATTR_NODUMP)
> -		tst_res(TPASS, "STATX_ATTR_NODUMP flag is set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is not set");
> -}
> -
> -static void test_unflagged(void)
> -{
> -	struct statx buf;
> -
> -	TEST(statx(AT_FDCWD, TESTDIR_UNFLAGGED, 0, 0, &buf));
> +	TEST(statx(AT_FDCWD, flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED, 0, 0, &buf));
>   	if (TST_RET == 0)
>   		tst_res(TPASS,
>   			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
> -			TESTDIR_UNFLAGGED);
> +			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
>   	else
>   		tst_brk(TFAIL | TTERRNO,
>   			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
> -			TESTDIR_UNFLAGGED);
> -
> -	if ((buf.stx_attributes & STATX_ATTR_COMPRESSED) == 0)
> -		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is not set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is set");
> -
> -	if ((buf.stx_attributes & STATX_ATTR_APPEND) == 0)
> -		tst_res(TPASS, "STATX_ATTR_APPEND flag is not set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_APPEND flag is set");
> -
> -	if ((buf.stx_attributes & STATX_ATTR_IMMUTABLE) == 0)
> -		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is not set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is set");
> -
> -	if ((buf.stx_attributes & STATX_ATTR_NODUMP) == 0)
> -		tst_res(TPASS, "STATX_ATTR_NODUMP flag is not set");
> -	else
> -		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is set");
> +			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
> +
> +	if (supp_compr) {
> +		if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
> +			tst_res(flag ? TPASS : TFAIL,
> +				"STATX_ATTR_COMPRESSED flag is set");
> +		else
> +			tst_res(flag ? TFAIL : TPASS,
> +				"STATX_ATTR_COMPRESSED flag is not set");
> +	}
> +	if (supp_append) {
> +		if (buf.stx_attributes & STATX_ATTR_APPEND)
> +			tst_res(flag ? TPASS : TFAIL,
> +				"STATX_ATTR_APPEND flag is set");
> +		else
> +			tst_res(flag ? TFAIL : TPASS,
> +				"STATX_ATTR_APPEND flag is not set");
> +	}
> +	if (supp_immutable) {
> +		if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
> +			tst_res(flag ? TPASS : TFAIL,
> +				"STATX_ATTR_IMMUTABLE flag is set");
> +		else
> +			tst_res(flag ? TFAIL : TPASS,
> +				"STATX_ATTR_IMMUTABLE flag is not set");
> +	}
> +	if (supp_nodump) {
> +		if (buf.stx_attributes & STATX_ATTR_NODUMP)
> +			tst_res(flag ? TPASS : TFAIL,
> +				"STATX_ATTR_NODUMP flag is set");
> +		else
> +			tst_res(flag ? TFAIL : TPASS,
> +				"STATX_ATTR_NODUMP flag is not set");
> +	}
>   }
>   
>   struct test_cases {
> -	void (*tfunc)(void);
> +	void (*tfunc)(int);
> +	int set_flag;
>   } tcases[] = {
> -	{&test_flagged},
> -	{&test_unflagged},
> +	{&test_flag, 1},
> +	{&test_flag, 0},
>   };
>   
>   static void run(unsigned int i)
>   {
> -	tcases[i].tfunc();
> +	tcases[i].tfunc(tcases[i].set_flag);
>   }
>   
>   static void caid_flags_setup(void)
> @@ -135,12 +120,17 @@ static void caid_flags_setup(void)
>   		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
>   	}
>   
> -	attr |= FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL;
> +	if (supp_compr)
> +		attr |= FS_COMPR_FL;
> +	if (supp_append)
> +		attr |= FS_APPEND_FL;
> +	if (supp_immutable)
> +		attr |= FS_IMMUTABLE_FL;
> +	if (supp_nodump)
> +		attr |= FS_NODUMP_FL;
>   
>   	ret = ioctl(fd, FS_IOC_SETFLAGS, &attr);
>   	if (ret < 0) {
> -		if (errno == EOPNOTSUPP)
> -			tst_brk(TCONF, "Flags not supported");
>   		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_SETFLAGS, %i)", fd, attr);
>   	}
>   
> @@ -149,11 +139,49 @@ static void caid_flags_setup(void)
>   
>   static void setup(void)
>   {
> +	struct statx buf;
> +
> +	supp_compr = 1;
> +	supp_append = 1;
> +	supp_immutable = 1;
> +	supp_nodump = 1;
>   	SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
>   	SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
>   
> +	// don't check ext4 because ext4 supports statx since 4.11.
>   	if (!strcmp(tst_device->fs_type, "btrfs") && tst_kvercmp(4, 13, 0) < 0)
> -		tst_brk(TCONF, "Btrfs statx() supported since 4.13");
> +		tst_brk(TCONF, "Btrfs statx() stx_attributes_mask supported since 4.13");
> +
> +	if (!strcmp(tst_device->fs_type, "xfs") && tst_kvercmp(5, 1, 0) < 0)
> +		tst_brk(TCONF, "xfs statx() stx_attributes_mask supported since 5.1");
> +
> +	if (!strcmp(tst_device->fs_type, "ext2") && tst_kvercmp(5, 1, 0) < 0)
> +		tst_brk(TCONF, "ext2 statx() stx_attributes_mask supported since 5.1");
> +
> +	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
> +	if (TST_RET == -1)
> +		tst_brk(TFAIL | TTERRNO,
> +			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
> +
> +	if ((buf.stx_attributes_mask & FS_COMPR_FL) == 0) {
> +		supp_compr = 0;
> +		tst_res(TCONF, "filesystem doesn't support FS_COMPR_FL");
> +	}
> +	if ((buf.stx_attributes_mask & FS_APPEND_FL) == 0) {
> +		supp_append = 0;
> +		tst_res(TCONF, "filesystem doesn't support FS_APPEND_FL");
> +	}
> +	if ((buf.stx_attributes_mask & FS_IMMUTABLE_FL) == 0) {
> +		supp_immutable = 0;
> +		tst_res(TCONF, "filesystem doesn't support FS_IMMUTABLE_FL");
> +	}
> +	if ((buf.stx_attributes_mask & FS_NODUMP_FL) == 0) {
> +		supp_nodump = 0;
> +		tst_res(TCONF, "filesystem doesn't support FS_NODUMP_FL");
> +	}
> +	if (!(supp_compr || supp_append || supp_immutable || supp_nodump))
> +		tst_brk(TCONF,
> +			"filesystem doesn't support the above any attr, skip it");
>   
>   	caid_flags_setup();
>   }
Li Wang May 25, 2021, 1:18 p.m. UTC | #2
Hi all,

Yang Xu <xuyang2018.jy@cn.fujitsu.com> wrote:

>
> stx_attributes_mask shows what's supported in stx_attributes.
> Set supp_{append,compr,immutable,nodump} attributes only on filesystems
> which actually support it.
>
> Also merge duplicate code.
>
> ---------------
> v2->v3:
> 1.add kernel version check for stx_attributes_mask
> 2. use test_flag(int) instead of test_flagged and test_unflagged
> ---------------
>
> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Reviewed-by: Li Wang <liwang@redhat.com>

This patch makes sense to me, I'm not sure if any blocker issue for
holding the apply process. If _no_ I would help to merge it:).
Cyril Hrubis May 25, 2021, 2:16 p.m. UTC | #3
Hi!
> > stx_attributes_mask shows what's supported in stx_attributes.
> > Set supp_{append,compr,immutable,nodump} attributes only on filesystems
> > which actually support it.
> >
> > Also merge duplicate code.
> >
> > ---------------
> > v2->v3:
> > 1.add kernel version check for stx_attributes_mask
> > 2. use test_flag(int) instead of test_flagged and test_unflagged
> > ---------------
> >
> > Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> > Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> Reviewed-by: Li Wang <liwang@redhat.com>
> 
> This patch makes sense to me, I'm not sure if any blocker issue for
> holding the apply process. If _no_ I would help to merge it:).

See:

https://github.com/linux-test-project/ltp/issues/557

Basically this change hides a kernel bug. I've proposed to create a
separate test for kernel that makes sure that all flags that are
supposed to be enabled are enabled for new enough kernels, then we can
apply this patch.
Yang Xu \(Fujitsu\) May 26, 2021, 4 a.m. UTC | #4
Hi Cyril
> Hi!
>>> stx_attributes_mask shows what's supported in stx_attributes.
>>> Set supp_{append,compr,immutable,nodump} attributes only on filesystems
>>> which actually support it.
>>>
>>> Also merge duplicate code.
>>>
>>> ---------------
>>> v2->v3:
>>> 1.add kernel version check for stx_attributes_mask
>>> 2. use test_flag(int) instead of test_flagged and test_unflagged
>>> ---------------
>>>
>>> Signed-off-by: Yang Xu<xuyang2018.jy@cn.fujitsu.com>
>>> Reviewed-by: Petr Vorel<pvorel@suse.cz>
>>
>> Reviewed-by: Li Wang<liwang@redhat.com>
>>
>> This patch makes sense to me, I'm not sure if any blocker issue for
>> holding the apply process. If _no_ I would help to merge it:).
>
> See:
>
> https://github.com/linux-test-project/ltp/issues/557
>
> Basically this change hides a kernel bug.
I don't think it is a kernel bug and it is only an non-supported feature 
before linux 5.1 when not using ext4 driver for ext2.

> I've proposed to create a
> separate test for kernel that makes sure that all flags that are
> supposed to be enabled are enabled for new enough kernels, then we can
> apply this patch.
But not all fs support all flags, like xfs it doesn't support 
STATX_ATTR_COMPRESSED flag even now.

[1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/xfs/xfs_iops.c#n611
>
Li Wang May 26, 2021, 8:31 a.m. UTC | #5
Hi all,

> >> This patch makes sense to me, I'm not sure if any blocker issue for
> >> holding the apply process. If _no_ I would help to merge it:).
> >
> > See:
> >
> > https://github.com/linux-test-project/ltp/issues/557
> >
> > Basically this change hides a kernel bug.
> I don't think it is a kernel bug and it is only an non-supported feature
> before linux 5.1 when not using ext4 driver for ext2.

Cyril hopes to have a reproducer to cover the bug [1] (though
you think it a non-support problem), but that is responsible
advice for FileSystem:).
Actually, the worth to say, there already a separate test
(xfstest/generic/424) for reproducing this problem[2].
See: https://github.com/kdave/xfstests/blob/master/tests/generic/424
I believe FS QE/Dev will run it for all filesystems regularly.

So maybe we can safely apply this patch in LTP without
adding a duplicated test?

[1] https://bugs.linaro.org/show_bug.cgi?id=4012
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=93bc420ed41df63
Yang Xu \(Fujitsu\) May 26, 2021, 10:02 a.m. UTC | #6
Hi Li
> Hi all,
>
>  > >> This patch makes sense to me, I'm not sure if any blocker issue for
>  > >> holding the apply process. If _no_ I would help to merge it:).
>  > >
>  > > See:
>  > >
>  > > https://github.com/linux-test-project/ltp/issues/557
>  > >
>  > > Basically this change hides a kernel bug.
>  > I don't think it is a kernel bug and it is only an non-supported feature
>  > before linux 5.1 when not using ext4 driver for ext2.
>
> Cyril hopes to have a reproducer to cover the bug [1](though
> you think it a non-support problem), but that is responsible
> advicefor FileSystem:).
Yes, xfstest is more situable to do this.
> Actually, the worth to say, there already a separate test
> (xfstest/generic/424) for reproducing this problem[2].
Yes, this fix is found by xfstest/generic/424.
> See: https://github.com/kdave/xfstests/blob/master/tests/generic/424
Usually I see xfstests case on offical repo repository
https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git
> I believe FS QE/Dev will run it for all filesystems regularly.
I think Theodore Ts'o may do it on xfstests-bld[1] and other 
project(like lkp) may also do it by using really ext2 driver. So having 
generic/424 is enough to find this kernel bug.

[1]https://git.kernel.org/pub/scm/fs/ext2/xfstests-bld.git/tree/kernel-configs/x86_64-config-5.10#n114
>
> So maybe we can safely apply this patch in LTP without
> adding a duplicated test?
+1. With this patch, we can also run this case on xfs filesystem.
>
> [1] https://bugs.linaro.org/show_bug.cgi?id=4012
> [2]
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=93bc420ed41df63
>
> --
> Regards,
> Li Wang
Richard Palethorpe Nov. 10, 2021, 1:28 p.m. UTC | #7
Hello Yang,

The fix/feature appears easy to backport, so I would suggest just adding the git
commit tags to the test. If the feature is required then people can
backport the patches, otherwise they can filter out the test.
Yang Xu \(Fujitsu\) Nov. 11, 2021, 3:25 a.m. UTC | #8
Hi Richard
> Hello Yang,
> 
> The fix/feature appears easy to backport, so I would suggest just adding the git
> commit tags to the test. If the feature is required then people can
> backport the patches, otherwise they can filter out the test.
> 

I will add these linux tags into description and send a v4.

Best Regards
Yang Xu
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/statx/statx04.c b/testcases/kernel/syscalls/statx/statx04.c
index 71de734f5..c0fa06d46 100644
--- a/testcases/kernel/syscalls/statx/statx04.c
+++ b/testcases/kernel/syscalls/statx/statx04.c
@@ -34,85 +34,70 @@ 
 #define TESTDIR_UNFLAGGED MOUNT_POINT"/test_dir2"
 
 static int fd, clear_flags;
+static int supp_compr;
+static int supp_append;
+static int supp_immutable;
+static int supp_nodump;
 
-static void test_flagged(void)
+static void test_flag(int flag)
 {
 	struct statx buf;
 
-	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
-	if (TST_RET == 0)
-		tst_res(TPASS,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
-	else
-		tst_brk(TFAIL | TTERRNO,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
-
-	if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
-		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_APPEND)
-		tst_res(TPASS, "STATX_ATTR_APPEND flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_APPEND flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
-		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_NODUMP)
-		tst_res(TPASS, "STATX_ATTR_NODUMP flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is not set");
-}
-
-static void test_unflagged(void)
-{
-	struct statx buf;
-
-	TEST(statx(AT_FDCWD, TESTDIR_UNFLAGGED, 0, 0, &buf));
+	TEST(statx(AT_FDCWD, flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED, 0, 0, &buf));
 	if (TST_RET == 0)
 		tst_res(TPASS,
 			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
-			TESTDIR_UNFLAGGED);
+			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
 	else
 		tst_brk(TFAIL | TTERRNO,
 			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
-			TESTDIR_UNFLAGGED);
-
-	if ((buf.stx_attributes & STATX_ATTR_COMPRESSED) == 0)
-		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_APPEND) == 0)
-		tst_res(TPASS, "STATX_ATTR_APPEND flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_APPEND flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_IMMUTABLE) == 0)
-		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_NODUMP) == 0)
-		tst_res(TPASS, "STATX_ATTR_NODUMP flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is set");
+			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
+
+	if (supp_compr) {
+		if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_COMPRESSED flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_COMPRESSED flag is not set");
+	}
+	if (supp_append) {
+		if (buf.stx_attributes & STATX_ATTR_APPEND)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_APPEND flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_APPEND flag is not set");
+	}
+	if (supp_immutable) {
+		if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_IMMUTABLE flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_IMMUTABLE flag is not set");
+	}
+	if (supp_nodump) {
+		if (buf.stx_attributes & STATX_ATTR_NODUMP)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_NODUMP flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_NODUMP flag is not set");
+	}
 }
 
 struct test_cases {
-	void (*tfunc)(void);
+	void (*tfunc)(int);
+	int set_flag;
 } tcases[] = {
-	{&test_flagged},
-	{&test_unflagged},
+	{&test_flag, 1},
+	{&test_flag, 0},
 };
 
 static void run(unsigned int i)
 {
-	tcases[i].tfunc();
+	tcases[i].tfunc(tcases[i].set_flag);
 }
 
 static void caid_flags_setup(void)
@@ -135,12 +120,17 @@  static void caid_flags_setup(void)
 		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
 	}
 
-	attr |= FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL;
+	if (supp_compr)
+		attr |= FS_COMPR_FL;
+	if (supp_append)
+		attr |= FS_APPEND_FL;
+	if (supp_immutable)
+		attr |= FS_IMMUTABLE_FL;
+	if (supp_nodump)
+		attr |= FS_NODUMP_FL;
 
 	ret = ioctl(fd, FS_IOC_SETFLAGS, &attr);
 	if (ret < 0) {
-		if (errno == EOPNOTSUPP)
-			tst_brk(TCONF, "Flags not supported");
 		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_SETFLAGS, %i)", fd, attr);
 	}
 
@@ -149,11 +139,49 @@  static void caid_flags_setup(void)
 
 static void setup(void)
 {
+	struct statx buf;
+
+	supp_compr = 1;
+	supp_append = 1;
+	supp_immutable = 1;
+	supp_nodump = 1;
 	SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
 	SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
 
+	// don't check ext4 because ext4 supports statx since 4.11.
 	if (!strcmp(tst_device->fs_type, "btrfs") && tst_kvercmp(4, 13, 0) < 0)
-		tst_brk(TCONF, "Btrfs statx() supported since 4.13");
+		tst_brk(TCONF, "Btrfs statx() stx_attributes_mask supported since 4.13");
+
+	if (!strcmp(tst_device->fs_type, "xfs") && tst_kvercmp(5, 1, 0) < 0)
+		tst_brk(TCONF, "xfs statx() stx_attributes_mask supported since 5.1");
+
+	if (!strcmp(tst_device->fs_type, "ext2") && tst_kvercmp(5, 1, 0) < 0)
+		tst_brk(TCONF, "ext2 statx() stx_attributes_mask supported since 5.1");
+
+	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TTERRNO,
+			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
+
+	if ((buf.stx_attributes_mask & FS_COMPR_FL) == 0) {
+		supp_compr = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_COMPR_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_APPEND_FL) == 0) {
+		supp_append = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_APPEND_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_IMMUTABLE_FL) == 0) {
+		supp_immutable = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_IMMUTABLE_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_NODUMP_FL) == 0) {
+		supp_nodump = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_NODUMP_FL");
+	}
+	if (!(supp_compr || supp_append || supp_immutable || supp_nodump))
+		tst_brk(TCONF,
+			"filesystem doesn't support the above any attr, skip it");
 
 	caid_flags_setup();
 }