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

linuxtestproject.agent@gmail.com linuxtestproject.agent@gmail.com
Fri Sep 18 14:51:56 CEST 2026


Hi Gaurav,

On Thu Sep 17 16:23:04 2026 +0530, Gaurav Pathak wrote:
> syscalls/statx13: Add basic test for STATX_WRITE_ATOMIC on regular file

> Fixes: #1224
> 
> Signed-off-by: Gaurav Pathak <gaurav.pathak@suse.com>
> 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.

> diff --git a/configure.ac b/configure.ac
> index 18bfdb88c..72f423c56 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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.

> diff --git a/testcases/kernel/syscalls/statx/statx13.c b/testcases/kernel/syscalls/statx/statx13.c
> new file mode 100644
> index 000000000..ea42a102c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/statx/statx13.c

Add an entry for statx13 to runtest/syscalls.

> +/*\
> + * 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)`.

> +#define TESTFILE MNTPOINT"/testfile"

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

> +#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.

> +#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.

> +		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.

> +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.

> +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


More information about the ltp mailing list