* [LTP] [PATCH v5 2/3] syscalls/statx04: remove btrfs kernel version and add linux tags
2021-11-16 7:55 [LTP] [PATCH v5 1/3] syscalls/statx04: Skip STATX_ATTR_COMPRESSED flag when tesing xfs Yang Xu
@ 2021-11-16 7:55 ` Yang Xu
2021-11-16 8:05 ` xuyang2018.jy
2021-11-16 9:49 ` Richard Palethorpe
2021-11-16 7:55 ` [LTP] [PATCH v5 3/3] syscalls/statx08: Add new test Yang Xu
2021-11-16 9:47 ` [LTP] [PATCH v5 1/3] syscalls/statx04: Skip STATX_ATTR_COMPRESSED flag when tesing xfs Richard Palethorpe
2 siblings, 2 replies; 9+ messages in thread
From: Yang Xu @ 2021-11-16 7:55 UTC (permalink / raw)
To: ltp
Also add docparse formatting.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/statx/statx04.c | 54 +++++++++++++++++------
1 file changed, 41 insertions(+), 13 deletions(-)
diff --git a/testcases/kernel/syscalls/statx/statx04.c b/testcases/kernel/syscalls/statx/statx04.c
index 6881ce261..a51891311 100644
--- a/testcases/kernel/syscalls/statx/statx04.c
+++ b/testcases/kernel/syscalls/statx/statx04.c
@@ -4,25 +4,50 @@
* Email: code@zilogic.com
*/
-/*
- * Test statx
+/*\
+ * [Description]
*
* This code tests if the attributes field of statx received expected value.
* File set with following flags by using SAFE_IOCTL:
- * 1) STATX_ATTR_COMPRESSED - The file is compressed by the filesystem.
- * 2) STATX_ATTR_IMMUTABLE - The file cannot be modified.
- * 3) STATX_ATTR_APPEND - The file can only be opened in append mode for
- * writing.
- * 4) STATX_ATTR_NODUMP - File is not a candidate for backup when a backup
+ *
+ * - STATX_ATTR_COMPRESSED: The file is compressed by the filesystem.
+ * - STATX_ATTR_IMMUTABLE: The file cannot be modified.
+ * - STATX_ATTR_APPEND: The file can only be opened in append mode for writing.
+ * - STATX_ATTR_NODUMP: File is not a candidate for backup when a backup
* program such as dump(8) is run.
*
* Two directories are tested.
- * First directory has all flags set.
- * Second directory has no flags set.
+ * First directory has all flags set. Second directory has no flags set.
*
- * xfs filesystem doesn't support STATX_ATTR_COMPRESSED flags, so we only test
+ * xfs filesystem doesn't support STATX_ATTR_COMPRESSED flag, so we only test
* three other flags.
*
+ * ext2, ext4, btrfs and xfs support statx syscall since the following commit
+ *
+ * commit 93bc420ed41df63a18ae794101f7cbf45226a6ef
+ * Author: yangerkun <yangerkun@huawei.com>
+ * Date: Mon Feb 18 09:07:02 2019 +0800
+ *
+ * ext2: support statx syscall
+ *
+ * commit 99652ea56a4186bc5bf8a3721c5353f41b35ebcb
+ * Author: David Howells <dhowells@redhat.com>
+ * Date: Fri Mar 31 18:31:56 2017 +0100
+ *
+ * ext4: Add statx support
+ *
+ * commit 04a87e3472828f769a93655d7c64a27573bdbc2c
+ * Author: Yonghong Song <yhs@fb.com>
+ * Date: Fri May 12 15:07:43 2017 -0700
+ *
+ * Btrfs: add statx support
+ *
+ * commit 5f955f26f3d42d04aba65590a32eb70eedb7f37d
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ * Date: Fri Mar 31 18:32:03 2017 +0100
+ *
+ * xfs: report crtime and attribute flags to statx
+ *
* Minimum kernel version required is 4.11.
*/
@@ -160,9 +185,6 @@ static void setup(void)
SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
- if (!strcmp(tst_device->fs_type, "btrfs") && tst_kvercmp(4, 13, 0) < 0)
- tst_brk(TCONF, "Btrfs statx() supported since 4.13");
-
caid_flags_setup();
}
@@ -190,4 +212,10 @@ static struct tst_test test = {
.mount_device = 1,
.mntpoint = MOUNT_POINT,
.min_kver = "4.11",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "93bc420ed41d"},
+ {"linux-git", "99652ea56a41"},
+ {"linux-git", "04a87e347282"},
+ {"linux-git", "5f955f26f3d4"},
+ },
};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [LTP] [PATCH v5 3/3] syscalls/statx08: Add new test
2021-11-16 7:55 [LTP] [PATCH v5 1/3] syscalls/statx04: Skip STATX_ATTR_COMPRESSED flag when tesing xfs Yang Xu
2021-11-16 7:55 ` [LTP] [PATCH v5 2/3] syscalls/statx04: remove btrfs kernel version and add linux tags Yang Xu
@ 2021-11-16 7:55 ` Yang Xu
2021-11-16 9:53 ` Richard Palethorpe
2021-11-17 9:48 ` Richard Palethorpe
2021-11-16 9:47 ` [LTP] [PATCH v5 1/3] syscalls/statx04: Skip STATX_ATTR_COMPRESSED flag when tesing xfs Richard Palethorpe
2 siblings, 2 replies; 9+ messages in thread
From: Yang Xu @ 2021-11-16 7:55 UTC (permalink / raw)
To: ltp
Like statx04.c, but use stx_attributes_mask before test so we only test
flag which has been implemented by the underlying filesystem.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/statx/.gitignore | 1 +
testcases/kernel/syscalls/statx/statx08.c | 196 +++++++++++++++++++++
3 files changed, 198 insertions(+)
create mode 100644 testcases/kernel/syscalls/statx/statx08.c
diff --git a/runtest/syscalls b/runtest/syscalls
index d57c73e39..bcd6ac1ab 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1741,6 +1741,7 @@ statx04 statx04
statx05 statx05
statx06 statx06
statx07 statx07
+statx08 statx08
membarrier01 membarrier01
diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore
index 2f5457e48..4db060dbb 100644
--- a/testcases/kernel/syscalls/statx/.gitignore
+++ b/testcases/kernel/syscalls/statx/.gitignore
@@ -5,3 +5,4 @@
/statx05
/statx06
/statx07
+/statx08
diff --git a/testcases/kernel/syscalls/statx/statx08.c b/testcases/kernel/syscalls/statx/statx08.c
new file mode 100644
index 000000000..dc869d6b6
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx08.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This case tests whether the attributes field of statx received expected value
+ * by using flags in the stx_attributes_mask field of statx.
+ * File set with following flags by using SAFE_IOCTL:
+ *
+ * - STATX_ATTR_COMPRESSED: The file is compressed by the filesystem.
+ * - STATX_ATTR_IMMUTABLE: The file cannot be modified.
+ * - STATX_ATTR_APPEND: The file can only be opened in append mode for writing.
+ * - STATX_ATTR_NODUMP: File is not a candidate for backup when a backup
+ * program such as dump(8) is run.
+ *
+ * Two directories are tested.
+ * First directory has all flags set. Second directory has no flags set.
+ *
+ * Minimum kernel version required is 4.11.
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/fs.h"
+#include <stdlib.h>
+#include "lapi/stat.h"
+
+#define MOUNT_POINT "mntpoint"
+#define TESTDIR_FLAGGED MOUNT_POINT"/test_dir1"
+#define TESTDIR_UNFLAGGED MOUNT_POINT"/test_dir2"
+
+static int fd, clear_flags;
+static int supp_compr = 1, supp_append = 1, supp_immutable = 1, supp_nodump = 1;
+
+static void test_flag(int flag)
+{
+ struct statx 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)",
+ flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
+ else
+ tst_brk(TFAIL | TTERRNO,
+ "sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
+ 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)(int);
+ int set_flag;
+} tcases[] = {
+ {&test_flag, 1},
+ {&test_flag, 0},
+};
+
+static void run(unsigned int i)
+{
+ tcases[i].tfunc(tcases[i].set_flag);
+}
+
+static void caid_flags_setup(void)
+{
+ int attr, ret;
+
+ fd = SAFE_OPEN(TESTDIR_FLAGGED, O_RDONLY | O_DIRECTORY);
+
+ ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
+ if (ret < 0) {
+ if (errno == ENOTTY)
+ tst_brk(TCONF | TERRNO, "FS_IOC_GETFLAGS not supported");
+
+ /* ntfs3g fuse fs returns wrong errno for unimplemented ioctls */
+ if (!strcmp(tst_device->fs_type, "ntfs")) {
+ tst_brk(TCONF | TERRNO,
+ "ntfs3g does not support FS_IOC_GETFLAGS");
+ }
+
+ tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
+ }
+
+ 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) {
+ tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_SETFLAGS, %i)", fd, attr);
+ }
+
+ clear_flags = 1;
+}
+
+static void setup(void)
+{
+ struct statx buf;
+
+ SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
+ SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
+
+ 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();
+}
+
+static void cleanup(void)
+{
+ int attr;
+
+ if (clear_flags) {
+ SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attr);
+ attr &= ~(FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL);
+ SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attr);
+ }
+
+ if (fd > 0)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test = run,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .all_filesystems = 1,
+ .mount_device = 1,
+ .mntpoint = MOUNT_POINT,
+ .min_kver = "4.11",
+};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 9+ messages in thread