[LTP] [PATCH v6 6/7] Add file_attr03 test
Andrea Cervesato
andrea.cervesato@suse.de
Thu Aug 7 09:01:44 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that `file_setattr` is correctly setting filesystems additional
attributes. We are running test on XFS only, since it's the only filesystem
currently implementing the features we need.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/file_attr/.gitignore | 1 +
testcases/kernel/syscalls/file_attr/file_attr03.c | 76 +++++++++++++++++++++++
3 files changed, 78 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index b69e474a6a596359bb1ace30312b55d6bf2b65cc..c33987328d3d6ec96660260aaee4f9ca8c4f0aee 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -248,6 +248,7 @@ fsetxattr02 fsetxattr02
file_attr01 file_attr01
file_attr02 file_attr02
+file_attr03 file_attr03
#posix_fadvise test cases
posix_fadvise01 posix_fadvise01
diff --git a/testcases/kernel/syscalls/file_attr/.gitignore b/testcases/kernel/syscalls/file_attr/.gitignore
index afe9c2fc9a4218dc032f044c1d317355a784a525..b79a340b733f7407dc135c5c3b0a9cd0e003e6c9 100644
--- a/testcases/kernel/syscalls/file_attr/.gitignore
+++ b/testcases/kernel/syscalls/file_attr/.gitignore
@@ -1,2 +1,3 @@
file_attr01
file_attr02
+file_attr03
diff --git a/testcases/kernel/syscalls/file_attr/file_attr03.c b/testcases/kernel/syscalls/file_attr/file_attr03.c
new file mode 100644
index 0000000000000000000000000000000000000000..9ad7790411a87f72bb0bd41a01063c3a0eccff2f
--- /dev/null
+++ b/testcases/kernel/syscalls/file_attr/file_attr03.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that `file_setattr` is correctly setting filesystems additional
+ * attributes. We are running test on XFS only, since it's the only filesystem
+ * currently implementing the features we need.
+ */
+
+#include "tst_test.h"
+#include "lapi/fs.h"
+
+#define MNTPOINT "mntpoint"
+#define FILEPATH (MNTPOINT "/ltp_file")
+#define BLOCKS 1024
+#define PROJID 16
+
+static int fd = -1;
+static int block_size;
+static struct fsxattr xattr;
+static struct file_attr *attr;
+
+static void run(void)
+{
+ fd = SAFE_CREAT(FILEPATH, 0777);
+
+ TST_EXP_PASS(file_setattr(AT_FDCWD, FILEPATH,
+ attr, FILE_ATTR_SIZE_LATEST, 0));
+
+ SAFE_IOCTL(fd, FS_IOC_FSGETXATTR, &xattr);
+ SAFE_CLOSE(fd);
+
+ TST_EXP_EQ_LI(xattr.fsx_xflags & FS_XFLAG_EXTSIZE, FS_XFLAG_EXTSIZE);
+ TST_EXP_EQ_LI(xattr.fsx_xflags & FS_XFLAG_COWEXTSIZE, FS_XFLAG_COWEXTSIZE);
+ TST_EXP_EQ_LI(xattr.fsx_extsize, BLOCKS * block_size);
+ TST_EXP_EQ_LI(xattr.fsx_cowextsize, BLOCKS * block_size);
+ TST_EXP_EQ_LI(xattr.fsx_projid, PROJID);
+
+ SAFE_UNLINK(FILEPATH);
+}
+
+static void setup(void)
+{
+ block_size = tst_dev_block_size(MNTPOINT);
+
+ attr->fa_xflags |= FS_XFLAG_EXTSIZE;
+ attr->fa_xflags |= FS_XFLAG_COWEXTSIZE;
+ attr->fa_extsize = BLOCKS * block_size;
+ attr->fa_cowextsize = BLOCKS * block_size;
+ attr->fa_projid = PROJID;
+}
+
+static void cleanup(void)
+{
+ if (fd != -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .mntpoint = MNTPOINT,
+ .needs_root = 1,
+ .mount_device = 1,
+ .filesystems = (struct tst_fs []) {
+ {.type = "xfs"},
+ {}
+ },
+ .bufs = (struct tst_buffers []) {
+ {&attr, .size = sizeof(struct file_attr)},
+ {}
+ }
+};
--
2.50.1
More information about the ltp
mailing list