Skip to contentSkip to conversation

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

PATCH In review Gaurav Pathak 4 participants 18 messages Sep 17 – Oct 14

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Fixes #1224
---
 configure.ac                               |   2 +-
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 130 +++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +1 -1
index 18bfdb88c..72f423c56 100644
@@ -181,7 +181,7 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +130 -0

130 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Fixes #1224
---
 configure.ac                               |   2 +-
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 130 +++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +1 -1
index 18bfdb88c..72f423c56 100644
@@ -181,7 +181,7 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +130 -0

130 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Gaurav,

Quoted 3 lines · Gaurav Pathak

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

Fixes #1224

Fixes tags must reference a valid commit SHA in git history. Use
Closes: #1224 or a Link tag to reference an issue.

configure.ac AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>]) · line 187

Quoted 5 lines
configure.ac +1 -1
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])

Do not use configure.ac checks to conditionally compile test logic. Instead, add fallback definitions for STATX_WRITE_ATOMIC, STATX_ATTR_WRITE_ATOMIC, and stx_atomic_write_* members in include/lapi/stat.h so the test builds unconditionally.

Quoted 7 lines

/*\
* This test validates the STATX_WRITE_ATOMIC feature (introduced in Linux 6.13).
* It ensures that supported filesystems (xfs as of now) correctly report their
* atomic write limits to user space when queried via statx().
*
* The test performs the following validations:
* - Creates a test file using O_DIRECT (a prerequisite for atomic writes).

Add a blank line before the bulleted list to comply with reST syntax.

Quoted 3 lines

#define _GNU_SOURCE
#include <sys/param.h>
#include "tst_test.h"

Include "lapi/stat.h" so statx() and atomic write definitions are available on older C libraries. <sys/param.h> is unused and should be removed.

Quoted 4 lines
	TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buff),
			"statx(AT_FDCWD, %s, 0, STATX_WRITE_ATOMIC, &buf)", TESTFILE);

	if (!(buff.stx_attributes & STATX_ATTR_WRITE_ATOMIC)) {

TST_EXP_PASS_SILENT() does not abort on error. If statx() fails, execution proceeds to read uninitialized memory from buff. Add "if (!TST_PASS) return;" after the call. Also drop the redundant, mismatched format string.

Quoted 7 lines
	if (buff.stx_atomic_write_unit_max > 0 &&
			__builtin_popcount(buff.stx_atomic_write_unit_max) == 1)
		tst_res(TPASS, "stx_atomic_write_unit_max(%u) is power of 2",
				buff.stx_atomic_write_unit_max);
	else
		tst_res(TFAIL, "stx_atomic_write_unit_max(%u) is not a power of 2",
				buff.stx_atomic_write_unit_max);

Assert that buff.stx_atomic_write_unit_min <= buff.stx_atomic_write_unit_max. The ordering between min and max is never checked when stx_atomic_write_unit_max_opt is 0.

Quoted 25 lines
#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
	if (buff.stx_atomic_write_unit_max_opt == 0) {
		tst_res(TINFO, "stx_atomic_write_unit_max_opt is 0 (no optimized max reported)");
	} else {
		if (buff.stx_atomic_write_unit_max_opt > buff.stx_atomic_write_unit_max)
			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max (%u)",
					buff.stx_atomic_write_unit_max_opt,
					buff.stx_atomic_write_unit_max);

		else if (buff.stx_atomic_write_unit_max_opt < buff.stx_atomic_write_unit_min)
			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is less than min (%u)",
					buff.stx_atomic_write_unit_max_opt,
					buff.stx_atomic_write_unit_min);
		else
			tst_res(TPASS, "stx_atomic_write_unit_max_opt (%u) is within valid range [%u, %u]",
					buff.stx_atomic_write_unit_max_opt,
					buff.stx_atomic_write_unit_min,
					buff.stx_atomic_write_unit_max);

		if (__builtin_popcount(buff.stx_atomic_write_unit_max_opt) != 1)
			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is not a power of 2",
					buff.stx_atomic_write_unit_max_opt);
	}
#else
	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in struct statx");
Quoted 1 line

#endif

Do not bury #ifdef feature checks inside test functions. Defining the members in include/lapi/stat.h removes the need for this guard and TCONF branch.

Quoted 13 lines

static void setup(void)

{
	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);

	if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
		tst_brk(TCONF, "This test only supports ext4 and xfs");

	umask(0);
	memset(data_buff, '@', WRITE_SIZE);

	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);
}

data_buff is allocated with SAFE_MEMALIGN() but never freed. Free data_buff after SAFE_WRITE(), and move the allocation after the filesystem check so it is not leaked on tst_brk(). Also remove the extra space after the '=' assignment.

Quoted 5 lines

static void cleanup(void)

{
	if (file_fd > -1)
		SAFE_CLOSE(file_fd);
}

Use if (file_fd != -1) per LTP conventions.

Also, add an entry for statx13 to runtest/syscalls.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Gaurav Pathak

Hi Gaurav,

nit: this is a second version of the patch, it'd help to distinguish them if you generate it with git format-patch -v2. It's also mentioned (as "-v 2") in our tutorial:

https://linux-test-project.readthedocs.io/en/latest/developers/test_case_tutorial.html

(Tutorial is slightly outdated both code and instructions but still more or less valid. It should be structured and improved but I still recommend you to read it to get various ideas not covered elsewhere).

Also this second patch failed to build in CI. Could you please enable CI in your LTP fork and push the branch before sending? You 1) get results quicker 2) saves our time to look on something which is broken.

Quoted 11 lines

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Quoted 8 lines
Fixes #1224
---
 configure.ac                               |   2 +-
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 130 +++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)

Please go over agent reports (it asked for runtest/syscalls already in the first patch).
...

testcases/kernel/syscalls/statx/statx13.c line 8

Quoted 12 lines

index 000000000..ea42a102c

testcases/kernel/syscalls/statx/statx13.c new file +8 -0
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 SUSE LLC <[email protected]>
+ */
+
+/*\
+ * This test validates the STATX_WRITE_ATOMIC feature (introduced in Linux 6.13).
+ * It ensures that supported filesystems (xfs as of now) correctly report their

git grep generic_atomic_write_valid (functions mentioned at [1] which was mentioned in the "block atomic writes" feature [2]) mentions also ext4. And you also test both xfs and ext4, you should either update filesystem list in docs or not mention filesystems at all.

[1] https://lore.kernel.org/linux-xfs/[email protected]/T/#t
[2] https://lore.kernel.org/lkml/[email protected]/

testcases/kernel/syscalls/statx/statx13.c line 11

Quoted 3 lines
testcases/kernel/syscalls/statx/statx13.c new file +3 -0
+ * atomic write limits to user space when queried via statx().
+ *
+ * The test performs the following validations:

nit: there needs to be a blank line otherwise list will not be formatted

=> we should teach agent to recognise it

testcases/kernel/syscalls/statx/statx13.c line 15

Quoted 4 lines
testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+ * - Creates a test file using O_DIRECT (a prerequisite for atomic writes).
+ * - Calls statx() with the STATX_WRITE_ATOMIC mask to retrieve the limits.
+ * - Verifies that stx_atomic_write_unit_min, stx_atomic_write_unit_max, and
+ *    stx_atomic_write_unit_max_opt are logically consistent (e.g., max_opt is

And this extra space before stx_atomic_write_unit_max_opt make is formatted as bold (see later doc build)

testcases/kernel/syscalls/statx/statx13.c line 25

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+ *    within the min and max bounds).
+ * - Ensures all reported atomic write unit sizes are valid powers of two.
+ */
+
+#define _GNU_SOURCE
+#include <sys/param.h>
+#include "tst_test.h"
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE MNTPOINT"/testfile"

nit style check complains, you'll find it with:

$ make check-statx13
...
CHECK testcases/kernel/syscalls/statx/statx13.c
statx13.c:25: CHECK: Concatenated strings should use spaces between elements
Quoted 7 lines
testcases/kernel/syscalls/statx/statx13.c new file +7 -0
+#define MODE 0644
+
+#define WRITE_SIZE 4096
+#define ALIGNMENT  4096
+
+static int file_fd = -1;
+

testcases/kernel/syscalls/statx/statx13.c line 42

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+static void verify_statx(void)
+{
+	struct statx buff;
+
+	TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buff),
+			"statx(AT_FDCWD, %s, 0, STATX_WRITE_ATOMIC, &buf)", TESTFILE);
+
+	if (!(buff.stx_attributes & STATX_ATTR_WRITE_ATOMIC)) {
+		tst_res(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");
+		return;

This is enough (without following return).

		tst_brk(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");
Quoted 11 lines
testcases/kernel/syscalls/statx/statx13.c new file +11 -0
+	}
+
+	if (buff.stx_atomic_write_unit_min > 0 &&
+			__builtin_popcount(buff.stx_atomic_write_unit_min) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_min(%u) is power of 2",
+				buff.stx_atomic_write_unit_min);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_min(%u) is not a power of 2",
+				buff.stx_atomic_write_unit_min);
+
+	if (buff.stx_atomic_write_unit_max > 0 &&

testcases/kernel/syscalls/statx/statx13.c line 63

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+			__builtin_popcount(buff.stx_atomic_write_unit_max) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_max(%u) is power of 2",
+				buff.stx_atomic_write_unit_max);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_max(%u) is not a power of 2",
+				buff.stx_atomic_write_unit_max);
+
+#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
+	if (buff.stx_atomic_write_unit_max_opt == 0) {
+		tst_res(TINFO, "stx_atomic_write_unit_max_opt is 0 (no optimized max reported)");

Shouldn't this be TPASS?

Quoted 21 lines
testcases/kernel/syscalls/statx/statx13.c new file +21 -0
+	} else {
+		if (buff.stx_atomic_write_unit_max_opt > buff.stx_atomic_write_unit_max)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max (%u)",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_max);
+
+		else if (buff.stx_atomic_write_unit_max_opt < buff.stx_atomic_write_unit_min)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is less than min (%u)",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min);
+		else
+			tst_res(TPASS, "stx_atomic_write_unit_max_opt (%u) is within valid range [%u, %u]",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min,
+					buff.stx_atomic_write_unit_max);
+
+		if (__builtin_popcount(buff.stx_atomic_write_unit_max_opt) != 1)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is not a power of 2",
+					buff.stx_atomic_write_unit_max_opt);
+	}
+#else

testcases/kernel/syscalls/statx/statx13.c line 94

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in struct statx");
+#endif
+}
+
+static void setup(void)
+{
+	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);
+
+	if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
+		tst_brk(TCONF, "This test only supports ext4 and xfs");

FYI .filesystems member in struct tst_test test select filesystems, you don't need to check here. Please remove it.

=> we should teach agent to detect this.

Quoted 12 lines
testcases/kernel/syscalls/statx/statx13.c new file +12 -0
+
+	umask(0);
+	memset(data_buff, '@', WRITE_SIZE);
+
+	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
+	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);
+}
+
+static void cleanup(void)
+{
+	if (file_fd > -1)
+		SAFE_CLOSE(file_fd);

testcases/kernel/syscalls/statx/statx13.c line 116

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+}
+
+static struct tst_test test = {
+	.test_all = verify_statx,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.13",
+	.needs_root = 1,
+	.needs_device = 1,
+	.needs_tmpdir = 1,

nit: Some tags aren't needed and will be later deleted. You can see it:

$ cd metadata/; make
/home/pvorel/install/src/ltp.git/metadata/parse.sh > ltp.json
testcases/kernel/syscalls/statx/statx13.c: useless tag: needs_device
testcases/kernel/syscalls/statx/statx13.c: useless tag: needs_tmpdir

Or you could see it at doc build (but that usually requires python virtualenv and it's slower, OTOH you can check how the doc will look like)

$ cd doc; make setup && make
=> see the docs in thml file:
doc/html/users/test_catalog.html#statx13

testcases/kernel/syscalls/statx/statx13.c line 126

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.filesystems = (struct tst_fs[]) {
+		{
+			.type = "xfs",
+			.mkfs_opts = (const char *const []){"-f", "-bsize=16K", NULL},
+		},
+		{
+			.type = "ext4",
+			.mkfs_opts = (const char *const []){"-O", "bigalloc", "-b", "4096", "-C", "65536", NULL},

BTW my 7.2.0-4.g080d79d-default still TCONF on ext4. Maybe wrong params?

Quoted 4 lines
testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+		},
+		{}
+	},
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#4 lore raw
Quoted 235 lines · Petr Vorel

Hi Gaurav,

nit: this is a second version of the patch, it'd help to distinguish them if you generate it with git format-patch -v2. It's also mentioned (as "-v 2") in our tutorial:

https://linux-test-project.readthedocs.io/en/latest/developers/test_case_tutorial.html

(Tutorial is slightly outdated both code and instructions but still more or less valid. It should be structured and improved but I still recommend you to read it to get various ideas not covered elsewhere).

Also this second patch failed to build in CI. Could you please enable CI in your LTP fork and push the branch before sending? You 1) get results quicker 2) saves our time to look on something which is broken.

Quoted 13 lines

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Fixes #1224
Quoted 7 lines
---
 configure.ac                               |   2 +-
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 130 
+++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletion(-)

Please go over agent reports (it asked for runtest/syscalls already in the first patch).
...

Quoted 11 lines

index 000000000..ea42a102c

testcases/kernel/syscalls/statx/statx13.c new file +7 -0
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 SUSE LLC <[email protected]>
+ */
+
+/*\
+ * This test validates the STATX_WRITE_ATOMIC feature (introduced in 
Quoted 3 lines

Linux 6.13).
+ * It ensures that supported filesystems (xfs as of now) correctly report their

git grep generic_atomic_write_valid (functions mentioned at [1] which was mentioned in the "block atomic writes" feature [2]) mentions also ext4. And you also test both xfs and ext4, you should either update filesystem list in docs or not mention filesystems at all.

[1] https://lore.kernel.org/linux-xfs/[email protected]/T/#t
[2] https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines

+ * atomic write limits to user space when queried via statx().
+ *
+ * The test performs the following validations:

nit: there needs to be a blank line otherwise list will not be formatted

=> we should teach agent to recognise it

Quoted 8 lines

+ * - Creates a test file using O_DIRECT (a prerequisite for atomic writes).
+ * - Calls statx() with the STATX_WRITE_ATOMIC mask to retrieve the limits.
+ * - Verifies that stx_atomic_write_unit_min, stx_atomic_write_unit_max, and
+ * stx_atomic_write_unit_max_opt are logically consistent (e.g.,
max_opt is

And this extra space before stx_atomic_write_unit_max_opt make is formatted as bold (see later doc build)

testcases/kernel/syscalls/statx/statx13.c line 25

Quoted 11 lines

+ * within the min and max bounds).
+ * - Ensures all reported atomic write unit sizes are valid powers of two.
+ */

testcases/kernel/syscalls/statx/statx13.c new file +7 -0
+
+#define _GNU_SOURCE
+#include <sys/param.h>
+#include "tst_test.h"
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE MNTPOINT"/testfile"

nit style check complains, you'll find it with:

$ make check-statx13
...
CHECK testcases/kernel/syscalls/statx/statx13.c
statx13.c:25: CHECK: Concatenated strings should use spaces between elements
Quoted 13 lines
testcases/kernel/syscalls/statx/statx13.c new file +12 -0
+#define MODE 0644
+
+#define WRITE_SIZE 4096
+#define ALIGNMENT  4096
+
+static int file_fd = -1;
+
+static void verify_statx(void)
+{
+	struct statx buff;
+
+	TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | 

STATX_WRITE_ATOMIC, &buff),

testcases/kernel/syscalls/statx/statx13.c line 42

Quoted 5 lines
testcases/kernel/syscalls/statx/statx13.c new file +5 -0
+			"statx(AT_FDCWD, %s, 0, STATX_WRITE_ATOMIC, &buf)", TESTFILE);
+
+	if (!(buff.stx_attributes & STATX_ATTR_WRITE_ATOMIC)) {
+		tst_res(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");
+		return;

This is enough (without following return).

		tst_brk(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");
Quoted 21 lines
testcases/kernel/syscalls/statx/statx13.c new file +21 -0
+	}
+
+	if (buff.stx_atomic_write_unit_min > 0 &&
+			__builtin_popcount(buff.stx_atomic_write_unit_min) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_min(%u) is power of 2",
+				buff.stx_atomic_write_unit_min);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_min(%u) is not a power of 2",
+				buff.stx_atomic_write_unit_min);
+
+	if (buff.stx_atomic_write_unit_max > 0 &&
+			__builtin_popcount(buff.stx_atomic_write_unit_max) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_max(%u) is power of 2",
+				buff.stx_atomic_write_unit_max);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_max(%u) is not a power of 2",
+				buff.stx_atomic_write_unit_max);
+
+#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
+	if (buff.stx_atomic_write_unit_max_opt == 0) {
+		tst_res(TINFO, "stx_atomic_write_unit_max_opt is 0 (no optimized 
Quoted 1 line

max reported)");

Shouldn't this be TPASS?

Quoted 38 lines
testcases/kernel/syscalls/statx/statx13.c new file +2 -0
+	} else {
+		if (buff.stx_atomic_write_unit_max_opt > 

buff.stx_atomic_write_unit_max)

testcases/kernel/syscalls/statx/statx13.c new file +1 -0
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max 

(%u)",

testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_max);
+
+		else if (buff.stx_atomic_write_unit_max_opt < 

buff.stx_atomic_write_unit_min)

testcases/kernel/syscalls/statx/statx13.c new file +1 -0
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is less than 

min (%u)",

testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min);
+		else
+			tst_res(TPASS, "stx_atomic_write_unit_max_opt (%u) is within valid 

range [%u, %u]",

testcases/kernel/syscalls/statx/statx13.c new file +6 -0
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min,
+					buff.stx_atomic_write_unit_max);
+
+		if (__builtin_popcount(buff.stx_atomic_write_unit_max_opt) != 1)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is not a power 

of 2",

testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+					buff.stx_atomic_write_unit_max_opt);
+	}
+#else
+	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in 

struct statx");

testcases/kernel/syscalls/statx/statx13.c new file +8 -0
+#endif
+}
+
+static void setup(void)
+{
+	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);
+
+	if (strcmp(tst_device->fs_type, "xfs") && 

strcmp(tst_device->fs_type, "ext4"))

testcases/kernel/syscalls/statx/statx13.c line 94

Quoted 1 line
testcases/kernel/syscalls/statx/statx13.c new file +1 -0
+		tst_brk(TCONF, "This test only supports ext4 and xfs");

FYI .filesystems member in struct tst_test test select filesystems, you don't need to check here. Please remove it.

=> we should teach agent to detect this.

Quoted 12 lines
testcases/kernel/syscalls/statx/statx13.c new file +12 -0
+
+	umask(0);
+	memset(data_buff, '@', WRITE_SIZE);
+
+	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
+	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);
+}
+
+static void cleanup(void)
+{
+	if (file_fd > -1)
+		SAFE_CLOSE(file_fd);

testcases/kernel/syscalls/statx/statx13.c line 116

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+}
+
+static struct tst_test test = {
+	.test_all = verify_statx,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.13",
+	.needs_root = 1,
+	.needs_device = 1,
+	.needs_tmpdir = 1,

nit: Some tags aren't needed and will be later deleted. You can see it:

$ cd metadata/; make
/home/pvorel/install/src/ltp.git/metadata/parse.sh > ltp.json
testcases/kernel/syscalls/statx/statx13.c: useless tag: needs_device
testcases/kernel/syscalls/statx/statx13.c: useless tag: needs_tmpdir

Or you could see it at doc build (but that usually requires python virtualenv and it's slower, OTOH you can check how the doc will look like)

$ cd doc; make setup && make
=> see the docs in thml file:
doc/html/users/test_catalog.html#statx13
Quoted 11 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.filesystems = (struct tst_fs[]) {
+		{
+			.type = "xfs",
+			.mkfs_opts = (const char *const []){"-f", "-bsize=16K", NULL},
+		},
+		{
+			.type = "ext4",
+			.mkfs_opts = (const char *const []){"-O", "bigalloc", "-b", 

"4096", "-C", "65536", NULL},

BTW my 7.2.0-4.g080d79d-default still TCONF on ext4. Maybe wrong params?

Quoted 4 lines

testcases/kernel/syscalls/statx/statx13.c line 130

Quoted 4 lines
testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+		},
+		{}
+	},
+};

Hello Petr,
Thanks a lot for reviewing the patch and providing useful pointers.
I am able to fix almost all of the issues reviewed by you and reported by automation agent.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
(quoted diff) +2 -0
+			.type = "ext4",
+			.mkfs_opts = (const char *const []){"-O", "bigalloc", "-b", 

"4096", "-C", "65536", NULL},

BTW my 7.2.0-4.g080d79d-default still TCONF on ext4. Maybe wrong params?

However, for ext4 filesystem case, I used scsi_debug kernel module to emulate the behavior of allowing 16K write operation using O_DIRECT flag which is bigger than the PAGESIZE of 4096. On my system and some other machines on which I ran this test, ext4 is not allowing me to cross PAGESIZE boundary, maybe because the kernel running on those machines is compiled with 4K PAGESIZE. I believe this is also the same in your case. Maybe we need to test this on a kernel having PAGESIZE greater than 4096.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Gaurav Pathak

Hi all,

Quoted 12 lines

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Fixes #1224

...

Quoted 5 lines
testcases/kernel/syscalls/statx/statx13.c new file +0 -0
new file mode 100644
index 000000000..ea42a102c

...

Quoted 1 line

+#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT

Looking at this, I wonder why this and also older statx10.c, statx11.c does not use ltp_statx added by Andrea in d89a232a7b ("Add SAFE_STATX macro")

Kind regards,
Petr

Quoted 26 lines
testcases/kernel/syscalls/statx/statx13.c new file +26 -0
+	if (buff.stx_atomic_write_unit_max_opt == 0) {
+		tst_res(TINFO, "stx_atomic_write_unit_max_opt is 0 (no optimized max reported)");
+	} else {
+		if (buff.stx_atomic_write_unit_max_opt > buff.stx_atomic_write_unit_max)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max (%u)",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_max);
+
+		else if (buff.stx_atomic_write_unit_max_opt < buff.stx_atomic_write_unit_min)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is less than min (%u)",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min);
+		else
+			tst_res(TPASS, "stx_atomic_write_unit_max_opt (%u) is within valid range [%u, %u]",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_min,
+					buff.stx_atomic_write_unit_max);
+
+		if (__builtin_popcount(buff.stx_atomic_write_unit_max_opt) != 1)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is not a power of 2",
+					buff.stx_atomic_write_unit_max_opt);
+	}
+#else
+	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in struct statx");
+#endif
+}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

PATCH v3 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Closes #1224
---
 configure.ac                               |   4 +-
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 139 +++++++++++++++++++++
 5 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +3 -1
index 18bfdb88c..d5a609fa7 100644
@@ -181,7 +181,9 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt,
+				  struct statx.stx_atomic_write_unit_min, struct statx.stx_atomic_write_unit_max,
+				  struct statx.stx_atomic_write_segments_max],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
include/lapi/stat.h +16 -1
index 17b62ea98..859e410ab 100644
@@ -93,7 +93,14 @@ struct statx_timestamp {
 	uint64_t	stx_mnt_id; \
 	uint32_t	stx_dio_mem_align; \
 	uint32_t	stx_dio_offset_align; \
-	uint64_t	__spare3[12]; \
+	uint64_t	stx_subvol; \
+	uint32_t	stx_atomic_write_unit_min; \
+	uint32_t	stx_atomic_write_unit_max; \
+	uint32_t	stx_atomic_write_segments_max; \
+	uint32_t	stx_dio_read_offset_align; \
+	uint32_t	stx_atomic_write_unit_max_opt; \
+	uint32_t	__spare2[1]; \
+	uint64_t	__spare3[8]; \
 };
 
 LTP_DEFINE_STATX_STRUCT(statx_fallback);
@@ -197,6 +204,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
+#ifndef STATX_WRITE_ATOMIC
+#define STATX_WRITE_ATOMIC  0x00010000U
+#endif
+
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
@@ -248,6 +259,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID_UNIQUE  0x00004000U
 #endif
 
+#ifndef STATX_ATTR_WRITE_ATOMIC
+#define STATX_ATTR_WRITE_ATOMIC	0x00400000
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
runtest/syscalls +1 -0
index d953f0558..b8c7fbb0f 100644
@@ -1926,6 +1926,7 @@ statx09 statx09
 statx10 statx10
 statx11 statx11
 statx12 statx12
+statx13 statx13
 
 membarrier01 membarrier01
 
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +139 -0

139 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi Gaurav,

Quoted 6 lines · Gaurav Pathak

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

Fixes #1224
Closes #1224 or a Link tag to reference an issue.

Fixes: tags must reference a commit SHA present in git history, not an issue. Use Closes: #1224 to reference the issue. Also remove the unedited template instruction "or a Link tag to reference an issue." from the Closes tag.

configure.ac AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>]) · line 187

Quoted 13 lines
configure.ac +1 -1
index 18bfdb88c..72f423c56 100644
@@ -181,7 +181,7 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])

configure.ac checks may only enable fallback API definitions in include/lapi/. Fallback definitions for struct statx extensions and atomic write flags should be added to include/lapi/stat.h instead.

testcases/kernel/syscalls/statx/statx13.c

Quoted 5 lines
testcases/kernel/syscalls/statx/statx13.c new file +0 -0
new file mode 100644
index 000000000..ea42a102c

Add an entry for statx13 to runtest/syscalls.

Quoted 7 lines

+/*\
+ * This test validates the STATX_WRITE_ATOMIC feature (introduced in Linux 6.13).
+ * It ensures that supported filesystems (xfs as of now) correctly report their
+ * atomic write limits to user space when queried via statx().
+ *
+ * The test performs the following validations:
+ * - Creates a test file using O_DIRECT (a prerequisite for atomic writes).

Insert a blank line before the bulleted list so Sphinx can parse the reST block correctly. Also, reference the syscall as :manpage:statx(2).

Quoted 1 line

+#define TESTFILE MNTPOINT"/testfile"

Add a space between concatenated string literals: MNTPOINT "/testfile".

testcases/kernel/syscalls/statx/statx13.c line 22

Quoted 3 lines
testcases/kernel/syscalls/statx/statx13.c new file +3 -0
+#define _GNU_SOURCE
+#include <sys/param.h>
+#include "tst_test.h"

Include "lapi/stat.h". Fallback definitions for STATX_WRITE_ATOMIC, STATX_ATTR_WRITE_ATOMIC, and atomic write fields in struct statx must be provided in include/lapi/stat.h so the test compiles on older C libraries.

testcases/kernel/syscalls/statx/statx13.c

Quoted 2 lines
testcases/kernel/syscalls/statx/statx13.c new file +2 -0
+#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
+	if (buff.stx_atomic_write_unit_max_opt == 0) {

Do not place #ifdef guards inside function bodies. Define the fallback struct in include/lapi/stat.h so the test code compiles unconditionally.

testcases/kernel/syscalls/statx/statx13.c

Quoted 6 lines
testcases/kernel/syscalls/statx/statx13.c new file +6 -0
+		if (buff.stx_atomic_write_unit_max_opt > buff.stx_atomic_write_unit_max)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max (%u)",
+					buff.stx_atomic_write_unit_max_opt,
+					buff.stx_atomic_write_unit_max);
+
+		else if (buff.stx_atomic_write_unit_max_opt < buff.stx_atomic_write_unit_min)

Remove the blank line between if and else if to follow kernel coding style.

testcases/kernel/syscalls/statx/statx13.c line 112

Quoted 13 lines
testcases/kernel/syscalls/statx/statx13.c new file +13 -0
+static void setup(void)
+{
+	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);
+
+	if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
+		tst_brk(TCONF, "This test only supports ext4 and xfs");
+
+	umask(0);
+	memset(data_buff, '@', WRITE_SIZE);
+
+	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
+	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);
+}

data_buff is never freed, leaking memory. Move the allocation after the filesystem check and call free(data_buff) after SAFE_WRITE(). Also remove the double space after '=' in file_fd assignment.

testcases/kernel/syscalls/statx/statx13.c line 118

Quoted 5 lines
testcases/kernel/syscalls/statx/statx13.c new file +5 -0
+static void cleanup(void)
+{
+	if (file_fd > -1)
+		SAFE_CLOSE(file_fd);
+}

Use if (file_fd != -1) instead of file_fd > -1 to match the LTP convention.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

All AI spotted errors are correct. Please update the patch.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
In reply to Gaurav Pathak

Hi Gaurav,

please make sure you are using the versioning tag. Probably to start using b4 is the right approach: I use it for more than a year now and it's easier to track versions in that way.

Without using a proper tag, both patchwork and ltp-agent are tracking patches in the wrong way, causing (like in this case) a wrong review from the agent.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
In reply to Gaurav Pathak

Hi Gaurav,

Quoted 3 lines · Gaurav Pathak

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

Fixes #1224

Fixes: must reference a valid commit SHA in local git history. If referencing a GitHub issue, use Closes: #1224 instead.

testcases/kernel/syscalls/statx/.gitignore line 13

Quoted 9 lines
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13

The new test must also be added to runtest/syscalls.

testcases/kernel/syscalls/statx/.gitignore

Quoted 5 lines
testcases/kernel/syscalls/statx/.gitignore +1 -1
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])

Compile-time checks in configure.ac may only enable fallback API definitions in include/lapi/. Fallback definitions for STATX_WRITE_ATOMIC, STATX_ATTR_WRITE_ATOMIC, and the atomic write struct statx fields belong in include/lapi/stat.h so the test builds on distributions with older libc headers.

Quoted 7 lines

+ * The test performs the following validations:
+ * - Creates a test file using O_DIRECT (a prerequisite for atomic writes).
+ * - Calls statx() with the STATX_WRITE_ATOMIC mask to retrieve the limits.
+ * - Verifies that stx_atomic_write_unit_min, stx_atomic_write_unit_max, and
+ * stx_atomic_write_unit_max_opt are logically consistent (e.g., max_opt is
+ * within the min and max bounds).
+ * - Ensures all reported atomic write unit sizes are valid powers of two.

Add a blank line before the bulleted list. Reference the syscall as :manpage:statx(2) and align the continuation indentation on line 15. Also update the doc comment regarding supported filesystems since ext4 is tested as well.

testcases/kernel/syscalls/statx/.gitignore

Quoted 6 lines
testcases/kernel/syscalls/statx/.gitignore +6 -0
+#define _GNU_SOURCE
+#include <sys/param.h>
+#include "tst_test.h"
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE MNTPOINT"/testfile"

Drop unused <sys/param.h> and include "lapi/stat.h". Add a space between concatenated string literals: MNTPOINT "/testfile".

testcases/kernel/syscalls/statx/.gitignore

Quoted 3 lines
testcases/kernel/syscalls/statx/.gitignore +3 -0
+static void verify_statx(void)
+{
+	struct statx buff;

Tested syscall struct arguments must not be allocated on the stack. Declare a static pointer and allocate it via .bufs in struct tst_test.

Quoted 4 lines
testcases/kernel/syscalls/statx/.gitignore +4 -0
+#ifdef HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
+	if (buff.stx_atomic_write_unit_max_opt == 0) {
+		tst_res(TINFO, "stx_atomic_write_unit_max_opt is 0 (no optimized max reported)");
+	} else {

[...]

testcases/kernel/syscalls/statx/.gitignore

Quoted 3 lines
testcases/kernel/syscalls/statx/.gitignore +3 -0
+#else
+	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in struct statx");
+#endif

Compile-time feature guards must not be placed inside function bodies. Provide fallback definitions in include/lapi/stat.h instead.

testcases/kernel/syscalls/statx/.gitignore

Quoted 13 lines
testcases/kernel/syscalls/statx/.gitignore +13 -0
+static void setup(void)
+{
+	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);
+
+	if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
+		tst_brk(TCONF, "This test only supports ext4 and xfs");
+
+	umask(0);
+	memset(data_buff, '@', WRITE_SIZE);
+
+	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
+	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);
+}

data_buff is never freed, leaking memory. Free it after SAFE_WRITE(), and perform the allocation after the filesystem check to avoid leaking on tst_brk().

testcases/kernel/syscalls/statx/.gitignore

Quoted 5 lines
testcases/kernel/syscalls/statx/.gitignore +5 -0
+static void cleanup(void)
+{
+	if (file_fd > -1)
+		SAFE_CLOSE(file_fd);
+}

Use if (file_fd != -1) to check file descriptor validity. Also, file_fd is kept open across test iterations but verify_statx() only accesses TESTFILE by path; close file_fd in setup() after writing if fd-based statx is not tested.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

v4 cover syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

Hi,

Thank you for the detailed feedback. I have addressed all the issues pointed out by the LTP AI Reviewer—including fixing the memory leak, correcting the statx struct allocation, moving the feature guards to lapi/stat.h, and fixing the commit reference format.

Please find the revised v4 patch.

Gaurav Pathak (1):
syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular
file

 configure.ac                               |   4 +-
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 139 +++++++++++++++++++++
 5 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v4 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Closes #1224
---
 configure.ac                               |   4 +-
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 139 +++++++++++++++++++++
 5 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +3 -1
index 18bfdb88c..d5a609fa7 100644
@@ -181,7 +181,9 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt,
+				  struct statx.stx_atomic_write_unit_min, struct statx.stx_atomic_write_unit_max,
+				  struct statx.stx_atomic_write_segments_max],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
include/lapi/stat.h +16 -1
index 17b62ea98..859e410ab 100644
@@ -93,7 +93,14 @@ struct statx_timestamp {
 	uint64_t	stx_mnt_id; \
 	uint32_t	stx_dio_mem_align; \
 	uint32_t	stx_dio_offset_align; \
-	uint64_t	__spare3[12]; \
+	uint64_t	stx_subvol; \
+	uint32_t	stx_atomic_write_unit_min; \
+	uint32_t	stx_atomic_write_unit_max; \
+	uint32_t	stx_atomic_write_segments_max; \
+	uint32_t	stx_dio_read_offset_align; \
+	uint32_t	stx_atomic_write_unit_max_opt; \
+	uint32_t	__spare2[1]; \
+	uint64_t	__spare3[8]; \
 };
 
 LTP_DEFINE_STATX_STRUCT(statx_fallback);
@@ -197,6 +204,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
+#ifndef STATX_WRITE_ATOMIC
+#define STATX_WRITE_ATOMIC  0x00010000U
+#endif
+
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
@@ -248,6 +259,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID_UNIQUE  0x00004000U
 #endif
 
+#ifndef STATX_ATTR_WRITE_ATOMIC
+#define STATX_ATTR_WRITE_ATOMIC	0x00400000
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
runtest/syscalls +1 -0
index d953f0558..b8c7fbb0f 100644
@@ -1926,6 +1926,7 @@ statx09 statx09
 statx10 statx10
 statx11 statx11
 statx12 statx12
+statx13 statx13
 
 membarrier01 membarrier01
 
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +139 -0

139 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

Hi Gaurav,

Quoted 10 lines

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate these atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

Quoted 4 lines

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

Closes #1224

we don't add Github tags in the git history, please remove it.

Quoted 103 lines
---
 configure.ac                               |   4 +-
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 139 +++++++++++++++++++++
 5 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +3 -1
index 18bfdb88c..d5a609fa7 100644
@@ -181,7 +181,9 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt,
+				  struct statx.stx_atomic_write_unit_min, struct statx.stx_atomic_write_unit_max,
+				  struct statx.stx_atomic_write_segments_max],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
include/lapi/stat.h +16 -1
index 17b62ea98..859e410ab 100644
@@ -93,7 +93,14 @@ struct statx_timestamp {
 	uint64_t	stx_mnt_id; \
 	uint32_t	stx_dio_mem_align; \
 	uint32_t	stx_dio_offset_align; \
-	uint64_t	__spare3[12]; \
+	uint64_t	stx_subvol; \
+	uint32_t	stx_atomic_write_unit_min; \
+	uint32_t	stx_atomic_write_unit_max; \
+	uint32_t	stx_atomic_write_segments_max; \
+	uint32_t	stx_dio_read_offset_align; \
+	uint32_t	stx_atomic_write_unit_max_opt; \
+	uint32_t	__spare2[1]; \
+	uint64_t	__spare3[8]; \
 };
 
 LTP_DEFINE_STATX_STRUCT(statx_fallback);
@@ -197,6 +204,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
+#ifndef STATX_WRITE_ATOMIC
+#define STATX_WRITE_ATOMIC  0x00010000U
+#endif
+
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
@@ -248,6 +259,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID_UNIQUE  0x00004000U
 #endif
 
+#ifndef STATX_ATTR_WRITE_ATOMIC
+#define STATX_ATTR_WRITE_ATOMIC	0x00400000
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
runtest/syscalls +1 -0
index d953f0558..b8c7fbb0f 100644
@@ -1926,6 +1926,7 @@ statx09 statx09
 statx10 statx10
 statx11 statx11
 statx12 statx12
+statx13 statx13
 
 membarrier01 membarrier01
 
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +8 -0
new file mode 100644
index 000000000..cc445fa57
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 SUSE LLC <[email protected]>
+ */
+
+/*\
+ * This test validates the STATX_WRITE_ATOMIC feature (introduced in Linux 6.13).
+ * It ensures that supported filesystems (xfs and nfs) correctly report their

testcases/kernel/syscalls/statx/statx13.c line 18

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+ * atomic write limits to user space when queried via statx().
+ *
+ * The test performs the following validations:
+ *
+ * - Creates a test file using O_DIRECT (a prerequisite for atomic writes).
+ * - Calls statx() with the STATX_WRITE_ATOMIC mask to retrieve the limits.
+ * - Verifies that stx_atomic_write_unit_min, stx_atomic_write_unit_max, and
+ *   stx_atomic_write_unit_max_opt are logically consistent (e.g., max_opt is
+ *   within the min and max bounds).
+ * - Ensures all reported atomic write unit sizes are valid powers of two.

This looks more like [Algorithm] section.

testcases/kernel/syscalls/statx/statx13.c line 30

Quoted 12 lines
testcases/kernel/syscalls/statx/statx13.c new file +12 -0
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/stat.h"
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE MNTPOINT "/testfile"
+#define MODE 0644
+
+#define WRITE_SIZE 4096
+#define ALIGNMENT  4096

We need to use the right page size when we use O_DIRECT. Please take a look at the other tests using O_DIRECT, so we avoid defining a default value for it.

testcases/kernel/syscalls/statx/statx13.c line 38

Quoted 8 lines
testcases/kernel/syscalls/statx/statx13.c new file +8 -0
+
+static int file_fd = -1;
+
+static void verify_statx(void)
+{
+	struct ltp_statx buff;
+
+	TST_EXP_PASS_SILENT(SAFE_STATX(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buff));

SAFE_STATX() will fail the syscall, so it shadows TST_EXP_PASS_SILENT(). We need to use raw statx() in these cases, because it's our subject of test, performing a TST_EXP_PASS() check on it.

We really want to know if statx() fails when STATX_WRITE_ATOMIC is passed.

Quoted 23 lines
testcases/kernel/syscalls/statx/statx13.c new file +23 -0
+
+	if (!TST_PASS)
+		return;
+
+	if (!(buff.data.stx_attributes & STATX_ATTR_WRITE_ATOMIC))
+		tst_brk(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");
+
+#if HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MIN
+	if (buff.data.stx_atomic_write_unit_min <= buff.data.stx_atomic_write_unit_max)
+		tst_res(TPASS, "stx_atomic_write_unit_min(%u) <= stx_atomic_write_unit_max(%u)",
+				buff.data.stx_atomic_write_unit_min, buff.data.stx_atomic_write_unit_max);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_min(%u) > stx_atomic_write_unit_max(%u)",
+				buff.data.stx_atomic_write_unit_min, buff.data.stx_atomic_write_unit_max);
+
+	if (buff.data.stx_atomic_write_unit_min > 0 &&
+			__builtin_popcount(buff.data.stx_atomic_write_unit_min) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_min(%u) is power of 2",
+				buff.data.stx_atomic_write_unit_min);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_min(%u) is not a power of 2",
+				buff.data.stx_atomic_write_unit_min);
+

testcases/kernel/syscalls/statx/statx13.c line 71

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+	if (buff.data.stx_atomic_write_unit_max > 0 &&
+			__builtin_popcount(buff.data.stx_atomic_write_unit_max) == 1)
+		tst_res(TPASS, "stx_atomic_write_unit_max(%u) is power of 2",
+				buff.data.stx_atomic_write_unit_max);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_max(%u) is not a power of 2",
+				buff.data.stx_atomic_write_unit_max);
+#else
+	tst_res(TCONF, "stx_atomic_write_unit_max or stx_atomic_write_unit_min is not defined in struct statx");
+#endif

This is not correct. If stx_atomic_write_unit_max is not defined, we should fallback that into the LTP fallback headers and _before_ even starting the test, check if statx() supports it. If it doesn't then we can TCONF.

Quoted 17 lines
testcases/kernel/syscalls/statx/statx13.c new file +17 -0
+
+#if HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT
+	if (buff.data.stx_atomic_write_unit_max_opt == 0) {
+		tst_res(TPASS, "stx_atomic_write_unit_max_opt is 0 (no optimized max reported)");
+	} else {
+		if (buff.data.stx_atomic_write_unit_max_opt > buff.data.stx_atomic_write_unit_max)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) exceeds max (%u)",
+					buff.data.stx_atomic_write_unit_max_opt,
+					buff.data.stx_atomic_write_unit_max);
+
+		else if (buff.data.stx_atomic_write_unit_max_opt < buff.data.stx_atomic_write_unit_min)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is less than min (%u)",
+					buff.data.stx_atomic_write_unit_max_opt,
+					buff.data.stx_atomic_write_unit_min);
+		else
+			tst_res(TPASS, "stx_atomic_write_unit_max_opt (%u) is within valid range [%u, %u]",
+					buff.data.stx_atomic_write_unit_max_opt,

testcases/kernel/syscalls/statx/statx13.c line 98

Quoted 10 lines
testcases/kernel/syscalls/statx/statx13.c new file +10 -0
+					buff.data.stx_atomic_write_unit_min,
+					buff.data.stx_atomic_write_unit_max);
+
+		if (__builtin_popcount(buff.data.stx_atomic_write_unit_max_opt) != 1)
+			tst_res(TFAIL, "stx_atomic_write_unit_max_opt (%u) is not a power of 2",
+					buff.data.stx_atomic_write_unit_max_opt);
+	}
+#else
+	tst_res(TCONF, "stx_atomic_write_unit_max_opt is not defined in struct statx");
+#endif

Same mistake here.

testcases/kernel/syscalls/statx/statx13.c line 105

Quoted 7 lines
testcases/kernel/syscalls/statx/statx13.c new file +7 -0
+}
+
+static void setup(void)
+{
+	char *data_buff = SAFE_MEMALIGN(ALIGNMENT, WRITE_SIZE);
+
+	umask(0);

This is not needed.

testcases/kernel/syscalls/statx/statx13.c line 109

Quoted 4 lines
testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+	memset(data_buff, '@', WRITE_SIZE);
+
+	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT | O_DIRECT, MODE);
+	SAFE_WRITE(SAFE_WRITE_ALL, file_fd, data_buff, WRITE_SIZE);

SAFE_CLOSE() goes here.

testcases/kernel/syscalls/statx/statx13.c line 117

Quoted 8 lines
testcases/kernel/syscalls/statx/statx13.c new file +8 -0
+
+	free(data_buff);
+}
+
+static void cleanup(void)
+{
+	if (file_fd != -1)
+		SAFE_CLOSE(file_fd);

We can close it right after SAFE_WRITE() because file descriptior is never in use during the test.

Quoted 28 lines
testcases/kernel/syscalls/statx/statx13.c new file +22 -0
+}
+
+static struct tst_test test = {
+	.test_all = verify_statx,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "6.11",
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.filesystems = (struct tst_fs[]) {
+		{
+			.type = "xfs",
+			.mkfs_opts = (const char *const []){"-f", "-bsize=16K", NULL},
+		},
+		{
+			.type = "ext4",
+			.mkfs_opts = (const char *const []){"-O", "bigalloc", "-b", "4096", "-C", "65536", NULL},
+		},
+		{}
+	},
+};
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v5 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate the atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

---
 configure.ac                               |   4 +-
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 125 +++++++++++++++++++++
 5 files changed, 146 insertions(+), 2 deletions(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
configure.ac +3 -1
index 370c2e74f..8ec6720dd 100644
@@ -180,7 +180,9 @@ AC_CHECK_MEMBERS([struct iocb.aio_rw_flags],,,[#include <linux/aio_abi.h>])
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
-AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align, struct statx.stx_atomic_write_unit_max_opt,
+				  struct statx.stx_atomic_write_unit_min, struct statx.stx_atomic_write_unit_max,
+				  struct statx.stx_atomic_write_segments_max],,,[
 #define _GNU_SOURCE
 #include <sys/stat.h>
 ])
include/lapi/stat.h +16 -1
index 17b62ea98..859e410ab 100644
@@ -93,7 +93,14 @@ struct statx_timestamp {
 	uint64_t	stx_mnt_id; \
 	uint32_t	stx_dio_mem_align; \
 	uint32_t	stx_dio_offset_align; \
-	uint64_t	__spare3[12]; \
+	uint64_t	stx_subvol; \
+	uint32_t	stx_atomic_write_unit_min; \
+	uint32_t	stx_atomic_write_unit_max; \
+	uint32_t	stx_atomic_write_segments_max; \
+	uint32_t	stx_dio_read_offset_align; \
+	uint32_t	stx_atomic_write_unit_max_opt; \
+	uint32_t	__spare2[1]; \
+	uint64_t	__spare3[8]; \
 };
 
 LTP_DEFINE_STATX_STRUCT(statx_fallback);
@@ -197,6 +204,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
+#ifndef STATX_WRITE_ATOMIC
+#define STATX_WRITE_ATOMIC  0x00010000U
+#endif
+
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
@@ -248,6 +259,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID_UNIQUE  0x00004000U
 #endif
 
+#ifndef STATX_ATTR_WRITE_ATOMIC
+#define STATX_ATTR_WRITE_ATOMIC	0x00400000
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
runtest/syscalls +1 -0
index accdf2df9..c0d8eb31e 100644
@@ -1947,6 +1947,7 @@ statx09 statx09
 statx10 statx10
 statx11 statx11
 statx12 statx12
+statx13 statx13
 
 membarrier01 membarrier01
 
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +125 -0

125 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

Hi Gaurav,

Quoted 5 lines · Gaurav Pathak

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

#if HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MIN

#if HAVE_STRUCT_STATX_STX_ATOMIC_WRITE_UNIT_MAX_OPT

High: These probes inspect libc's struct statx, but buff.data is the unconditionally extended statx_fallback. With glibc 2.39, a valid atomic write response yields two TCONF results and no limit checks. Remove both HAVE_* guards and the new, unnecessary configure probes; detect support at runtime.

Quoted 2 lines
	if (!(buff.data.stx_attributes & STATX_ATTR_WRITE_ATOMIC))
		tst_brk(TCONF, "Filesystem does not support STATX_WRITE_ATOMIC");

Medium: Valid-looking limits pass even with stx_mask and stx_attributes_mask both zero, while nonzero advertised limits with a missing active attribute produce only TCONF. Validate both masks before interpreting the fields, and report inconsistent advertised support as TFAIL rather than skipping it.

Quoted 1 line
	TST_EXP_PASS_SILENT(SAFE_STATX(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buff));

Medium: SAFE_STATX aborts with TBROK before the expectation can classify a syscall failure; returning -1/EIO reproduces this. Since statx is the syscall under test, call statx(..., &buff.buff) directly inside TST_EXP_PASS_SILENT.

Quoted 1 line
	struct ltp_statx buff;

Low: Allocate the tested syscall output through .bufs using a static struct ltp_statx pointer and .size = sizeof(*buff), rather than a stack struct, as required for new LTP tests.

Quoted 2 lines

* It ensures that supported filesystems (xfs and nfs) correctly report their
* atomic write limits to user space when queried via statx().

Low: The filesystem array tests xfs and ext4, not nfs. Describe the actual coverage using :manpage:statx(2), and document that root is required to format and mount the test device.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#16 lore raw

PATCH v6 1/1 syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

From: Gaurav Pathak <[email protected]>

This patch adds a new test to validate the atomic write limit fields. The test ensures the filesystem correctly advertises the STATX_ATTR_WRITE_ATOMIC attribute when queried on a file opened with O_DIRECT. It also verifies that the reported optimized maximum is logically consistent by falling within the absolute minimum and maximum boundaries. Furthermore, it checks that all reported atomic write unit sizes are valid powers of two, adhering to the strict requirements of the kernel block layer.

If the underlying storage hardware or filesystem lacks atomic write support, the test gracefully skips with TCONF.

---
 include/lapi/stat.h                        |  17 ++-
 runtest/syscalls                           |   1 +
 testcases/kernel/syscalls/statx/.gitignore |   1 +
 testcases/kernel/syscalls/statx/statx13.c  | 130 +++++++++++++++++++++
 4 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 testcases/kernel/syscalls/statx/statx13.c
include/lapi/stat.h +16 -1
index 17b62ea98..859e410ab 100644
@@ -93,7 +93,14 @@ struct statx_timestamp {
 	uint64_t	stx_mnt_id; \
 	uint32_t	stx_dio_mem_align; \
 	uint32_t	stx_dio_offset_align; \
-	uint64_t	__spare3[12]; \
+	uint64_t	stx_subvol; \
+	uint32_t	stx_atomic_write_unit_min; \
+	uint32_t	stx_atomic_write_unit_max; \
+	uint32_t	stx_atomic_write_segments_max; \
+	uint32_t	stx_dio_read_offset_align; \
+	uint32_t	stx_atomic_write_unit_max_opt; \
+	uint32_t	__spare2[1]; \
+	uint64_t	__spare3[8]; \
 };
 
 LTP_DEFINE_STATX_STRUCT(statx_fallback);
@@ -197,6 +204,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_DIOALIGN		0x00002000U
 #endif
 
+#ifndef STATX_WRITE_ATOMIC
+#define STATX_WRITE_ATOMIC  0x00010000U
+#endif
+
 #ifndef STATX__RESERVED
 # define STATX__RESERVED	0x80000000U
 #endif
@@ -248,6 +259,10 @@ static inline int statx(int dirfd, const char *pathname, unsigned int flags,
 # define STATX_MNT_ID_UNIQUE  0x00004000U
 #endif
 
+#ifndef STATX_ATTR_WRITE_ATOMIC
+#define STATX_ATTR_WRITE_ATOMIC	0x00400000
+#endif
+
 #define SAFE_FCHMODAT2(dfd, filename, mode, flags) \
 	safe_fchmodat2(__FILE__, __LINE__, (dfd), (filename), (mode), (flags))
 
runtest/syscalls +1 -0
index accdf2df9..c0d8eb31e 100644
@@ -1947,6 +1947,7 @@ statx09 statx09
 statx10 statx10
 statx11 statx11
 statx12 statx12
+statx13 statx13
 
 membarrier01 membarrier01
 
testcases/kernel/syscalls/statx/.gitignore +1 -0
index f6a423eed..e601a46a3 100644
@@ -10,3 +10,4 @@
 /statx10
 /statx11
 /statx12
+/statx13
testcases/kernel/syscalls/statx/statx13.c new file +130 -0

130 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

Hi Gaurav,

testcases/kernel/syscalls/statx/statx13.c line 28

Quoted 6 lines · Gaurav Pathak

syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

testcases/kernel/syscalls/statx/statx13.c new file +4 -0
+	struct ltp_statx buff;
+
+	TST_EXP_PASS(statx(AT_FDCWD, TESTFILE, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buff.buff),
+			"statx(AT_FDCWD, %s, 0, STATX_BASIC_STATS | STATX_WRITE_ATOMIC, &buf)", TESTFILE);

TST_EXP_PASS reports failure but does not return, so a statx() error leaves the following checks reading uninitialized output. Return immediately when !TST_PASS before accessing buff. Allocate this syscall buffer through .bufs rather than on the stack.

testcases/kernel/syscalls/statx/statx13.c line 122

Quoted 4 lines
testcases/kernel/syscalls/statx/statx13.c new file +3 -0
+	.min_kver = "6.11",
...
+			.type = "xfs",
+			.mkfs_opts = (const char *const []){"-f", "-bsize=16K", NULL},

Linux 6.11 rejects XFS blocks larger than PAGE_SIZE, so this configuration fails to mount on a 4 KiB-page system admitted by min_kver. The framework reports TBROK before setup or feature detection, also preventing the ext4 case from running. Use a portable block size or separately gate this large-block configuration.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!(buff.data.stx_attributes & STATX_ATTR_WRITE_ATOMIC))
+		tst_brk(TCONF, "STATX_WRITE_ATOMIC unsupported by block dev or filesystem: STATX_ATTR_WRITE_ATOMIC missing from stx_attributes");

A response with nonzero atomic limits but a missing support attribute is inconsistent, not simply unsupported. This branch hides that regression as TCONF despite the stated goal of validating the attribute. Check attribute/limit consistency first and reserve TCONF for unsupported results with zero limits.

include/lapi/stat.h struct statx_timestamp { · line 99

Quoted 1 line
include/lapi/stat.h +1 -0
+	uint32_t	stx_atomic_write_segments_max; \

verify_statx() never checks this returned limit. A response advertising atomic writes with segments_max = 0 passes every assertion, although it cannot describe a nonempty atomic write. Require stx_atomic_write_segments_max > 0 when support is advertised.

testcases/kernel/syscalls/statx/statx13.c

Quoted 6 lines
testcases/kernel/syscalls/statx/statx13.c new file +6 -0
+	if (buff.data.stx_atomic_write_unit_min <= buff.data.stx_atomic_write_unit_max)
+		tst_res(TPASS, "stx_atomic_write_unit_min(%u) <= stx_atomic_write_unit_max(%u)",
+				buff.data.stx_atomic_write_unit_min, buff.data.stx_atomic_write_unit_max);
+	else
+		tst_res(TFAIL, "stx_atomic_write_unit_min(%u) > stx_atomic_write_unit_max(%u)",
+				buff.data.stx_atomic_write_unit_min, buff.data.stx_atomic_write_unit_max);

Use TST_EXP_EXPR for this comparison and the repeated power-of-two assertions instead of manual TPASS/TFAIL branches.

Quoted 2 lines

+ * It ensures that supported filesystems (xfs and nfs) correctly report their
+ * atomic write limits to user space when queried via statx().

The filesystem list tests XFS and ext4, not NFS. Describe the actual regular-file checks using :manpage:statx(2) and document that root is required to format and mount the test filesystems.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp