Skip to content

Commit 7a62292

Browse files
committed
syscalls/statx10: Add basic test for STATX_DIOALIGN on regular file
STATX_DIOALIGN is used to get stx_dio_mem_align and stx_dio_offset_align for files on fs that support direct io. We just check whether these value are nonzero on ext4 and xfs. On ext4, files that use certain filesystem features (data journalling, encryption, and verity) fall back to buffered I/O. But ltp creates own filesystem by enabling mount_device in tst_test struct. If we set block device to LTP_DEV environment, we use this block device to mount by using default mount option. Otherwise, use loop device to simuate it. So it can avoid these above situations and don't fall back to buffered I/O. For struct statx member check, we only check stx_dio_mem_align because these two member is introduced together in separate commit in kernel, so it is safe. Reviewed-by: Xiao Yang <[email protected]> Signed-off-by: Yang Xu <[email protected]>
1 parent 517c7b5 commit 7a62292

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!))
158158
AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
159159
AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
160160
AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
161-
AC_CHECK_MEMBERS([struct statx.stx_mnt_id],,,[
161+
AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[
162162
#define _GNU_SOURCE
163163
#include <sys/stat.h>
164164
])

runtest/syscalls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,7 @@ statx06 statx06
17651765
statx07 statx07
17661766
statx08 statx08
17671767
statx09 statx09
1768+
statx10 statx10
17681769

17691770
membarrier01 membarrier01
17701771

testcases/kernel/syscalls/statx/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/statx07
88
/statx08
99
/statx09
10+
/statx10
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
4+
* Author: Yang Xu <[email protected]>
5+
*/
6+
7+
/*\
8+
* [Description]
9+
*
10+
* It is a basic test for STATX_DIOALIGN mask on ext4 and xfs filesystem.
11+
*
12+
* - STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align value
13+
*
14+
* Check these two values are nonzero under dio situation when STATX_DIOALIGN
15+
* in the request mask.
16+
*
17+
* On ext4, files that use certain filesystem features (data journaling,
18+
* encryption, and verity) fall back to buffered I/O. But ltp creates own
19+
* filesystem by enabling mount_device in tst_test struct. If we set block
20+
* device to LTP_DEV environment, we use this block device to mount by using
21+
* default mount option. Otherwise, use loop device to simuate it. So it can
22+
* avoid these above situations and don't fall back to buffered I/O.
23+
*
24+
* Minimum Linux version required is v6.1.
25+
*/
26+
27+
#define _GNU_SOURCE
28+
#include <sys/types.h>
29+
#include <unistd.h>
30+
#include <stdlib.h>
31+
#include <stdbool.h>
32+
#include "tst_test.h"
33+
#include "lapi/stat.h"
34+
#include "lapi/fcntl.h"
35+
36+
#define MNTPOINT "mnt_point"
37+
#define TESTFILE MNTPOINT"/testfile"
38+
39+
static void verify_statx(void)
40+
{
41+
struct statx buf;
42+
43+
TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf),
44+
"statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE);
45+
46+
if (!(buf.stx_mask & STATX_DIOALIGN)) {
47+
tst_res(TCONF, "Filesystem does not support STATX_DIOALIGN");
48+
return;
49+
}
50+
51+
#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN
52+
if (buf.stx_dio_mem_align != 0)
53+
tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align);
54+
else
55+
tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported");
56+
57+
if (buf.stx_dio_offset_align != 0)
58+
tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align);
59+
else
60+
tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported");
61+
#else
62+
tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field");
63+
#endif
64+
}
65+
66+
static void setup(void)
67+
{
68+
int fd = -1;
69+
70+
if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4"))
71+
tst_brk(TCONF, "This test only supports ext4 and xfs");
72+
73+
SAFE_FILE_PRINTF(TESTFILE, "AAAA");
74+
fd = open(TESTFILE, O_RDWR | O_DIRECT);
75+
if (fd == -1) {
76+
if (errno == EINVAL)
77+
tst_brk(TCONF,
78+
"The regular file is not on a filesystem that support DIO");
79+
else
80+
tst_brk(TBROK | TERRNO,
81+
"The regular file is open with O_RDWR | O_DIRECT failed");
82+
}
83+
SAFE_CLOSE(fd);
84+
}
85+
86+
static struct tst_test test = {
87+
.test_all = verify_statx,
88+
.setup = setup,
89+
.needs_root = 1,
90+
.mntpoint = MNTPOINT,
91+
.mount_device = 1,
92+
.all_filesystems = 1,
93+
};

0 commit comments

Comments
 (0)