Message ID | 1680518676-2863-2-git-send-email-xuyang2018.jy@fujitsu.com |
---|---|
State | Superseded |
Headers | show |
Series | [v2,1/4] lapi/stat.h: Add STATX_DIOALIGN related definition | expand |
On Mon, Apr 03, 2023 at 06:44:34PM +0800, Yang Xu wrote: > +static void verify_statx(void) > +{ > + struct statx buf; > + > + memset(&buf, 0, sizeof(buf)); > + TST_EXP_PASS(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf), > + "statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE); > + > + if (!(buf.stx_mask & STATX_DIOALIGN)) { > + tst_res(TCONF, "STATX_DIOALIGN is not supported until linux 6.1"); > + return; > + } > + > + if (buf.stx_dio_mem_align != 0) > + tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align); > + else > + tst_res(TFAIL, "don't get stx_dio_mem_align on supported dio fs"); > + > + if (buf.stx_dio_offset_align != 0) > + tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align); > + else > + tst_res(TFAIL, "don't get stx_dio_offset_align on supported dio fs"); > +} > + > +static void setup(void) > +{ > + if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4")) > + tst_brk(TCONF, "This test only supports ext4 and xfs"); > + > + SAFE_FILE_PRINTF(TESTFILE, "AAAA"); > + fd = open(TESTFILE, O_RDWR | O_DIRECT); > + if (fd == -1 && errno == EINVAL) > + tst_brk(TCONF, "The regular file is not on a filesystem that support DIO"); > +} On ext4, files that use certain filesystem features (data journalling, encryption, and verity) fall back to buffered I/O. This test will fail when passed such a file, as it assumes that DIO doesn't fall back to buffered I/O. How is it guaranteed that such a file is not passed to this test? - Eric
on 2023/04/04 1:01, Eric Biggers wrote: > On Mon, Apr 03, 2023 at 06:44:34PM +0800, Yang Xu wrote: >> +static void verify_statx(void) >> +{ >> + struct statx buf; >> + >> + memset(&buf, 0, sizeof(buf)); >> + TST_EXP_PASS(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf), >> + "statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE); >> + >> + if (!(buf.stx_mask & STATX_DIOALIGN)) { >> + tst_res(TCONF, "STATX_DIOALIGN is not supported until linux 6.1"); >> + return; >> + } >> + >> + if (buf.stx_dio_mem_align != 0) >> + tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align); >> + else >> + tst_res(TFAIL, "don't get stx_dio_mem_align on supported dio fs"); >> + >> + if (buf.stx_dio_offset_align != 0) >> + tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align); >> + else >> + tst_res(TFAIL, "don't get stx_dio_offset_align on supported dio fs"); >> +} >> + >> +static void setup(void) >> +{ >> + if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4")) >> + tst_brk(TCONF, "This test only supports ext4 and xfs"); >> + >> + SAFE_FILE_PRINTF(TESTFILE, "AAAA"); >> + fd = open(TESTFILE, O_RDWR | O_DIRECT); >> + if (fd == -1 && errno == EINVAL) >> + tst_brk(TCONF, "The regular file is not on a filesystem that support DIO"); >> +} > > On ext4, files that use certain filesystem features (data journalling, > encryption, and verity) fall back to buffered I/O. This test will fail when > passed such a file, as it assumes that DIO doesn't fall back to buffered I/O. Yes, I also reproduce it when I mount a partion with data=journal on /tmp directory. mount -o data=journal /dev/vdb /tmp [root@localhost statx]# ./statx10 ...... tst_test.c:1634: TINFO: === Testing on ext2 === tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext2 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:59: TCONF: This test only supports ext4 and xfs tst_test.c:1634: TINFO: === Testing on ext3 === tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext3 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:59: TCONF: This test only supports ext4 and xfs tst_test.c:1634: TINFO: === Testing on ext4 === tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) passed statx10.c:48: TFAIL: don't get stx_dio_mem_align on supported dio fs statx10.c:53: TFAIL: don't get stx_dio_offset_align on supported dio fs tst_test.c:1634: TINFO: === Testing on xfs === tst_test.c:1093: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts='' statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) passed statx10.c:48: TFAIL: don't get stx_dio_mem_align on supported dio fs statx10.c:53: TFAIL: don't get stx_dio_offset_align on supported dio fs tst_test.c:1634: TINFO: === Testing on tmpfs === tst_test.c:1093: TINFO: Skipping mkfs for TMPFS filesystem tst_test.c:1074: TINFO: Limiting tmpfs size to 32MB statx10.c:59: TCONF: This test only supports ext4 and xfs IMO, If we use a actual block device to test instead of use a loop device on /tmp directory, it should be ok. export LTP_DEV=/dev/vdb tst_test.c:1634: TINFO: === Testing on ext2 === tst_test.c:1093: TINFO: Formatting /dev/vdb with ext2 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:59: TCONF: This test only supports ext4 and xfs tst_test.c:1634: TINFO: === Testing on ext3 === tst_test.c:1093: TINFO: Formatting /dev/vdb with ext3 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:59: TCONF: This test only supports ext4 and xfs tst_test.c:1634: TINFO: === Testing on ext4 === tst_test.c:1093: TINFO: Formatting /dev/vdb with ext4 opts='' extra opts='' mke2fs 1.46.5 (30-Dec-2021) statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) passed statx10.c:46: TPASS: stx_dio_mem_align:512 statx10.c:51: TPASS: stx_dio_offset_align:512 tst_test.c:1634: TINFO: === Testing on xfs === tst_test.c:1093: TINFO: Formatting /dev/vdb with xfs opts='' extra opts='' statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) passed statx10.c:46: TPASS: stx_dio_mem_align:512 statx10.c:51: TPASS: stx_dio_offset_align:512 tst_test.c:1634: TINFO: === Testing on tmpfs === tst_test.c:1093: TINFO: Skipping mkfs for TMPFS filesystem tst_test.c:1074: TINFO: Limiting tmpfs size to 32MB statx10.c:59: TCONF: This test only supports ext4 and xfs > > How is it guaranteed that such a file is not passed to this test? Since /etc/mk2fs.conf doesn't enable data=journal, encrypt, verity feature by default and ltp use default mkfs configure , mount option. I think we can detect dio io support before mount. Best Regards Yang Xu > > - Eric
on 2023/04/04 11:10, xuyang2018.jy@fujitsu.com wrote: > > on 2023/04/04 1:01, Eric Biggers wrote: >> On Mon, Apr 03, 2023 at 06:44:34PM +0800, Yang Xu wrote: >>> +static void verify_statx(void) >>> +{ >>> + struct statx buf; >>> + >>> + memset(&buf, 0, sizeof(buf)); >>> + TST_EXP_PASS(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf), >>> + "statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE); >>> + >>> + if (!(buf.stx_mask & STATX_DIOALIGN)) { >>> + tst_res(TCONF, "STATX_DIOALIGN is not supported until linux 6.1"); >>> + return; >>> + } >>> + >>> + if (buf.stx_dio_mem_align != 0) >>> + tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align); >>> + else >>> + tst_res(TFAIL, "don't get stx_dio_mem_align on supported dio fs"); >>> + >>> + if (buf.stx_dio_offset_align != 0) >>> + tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align); >>> + else >>> + tst_res(TFAIL, "don't get stx_dio_offset_align on supported dio fs"); >>> +} >>> + >>> +static void setup(void) >>> +{ >>> + if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4")) >>> + tst_brk(TCONF, "This test only supports ext4 and xfs"); >>> + >>> + SAFE_FILE_PRINTF(TESTFILE, "AAAA"); >>> + fd = open(TESTFILE, O_RDWR | O_DIRECT); >>> + if (fd == -1 && errno == EINVAL) >>> + tst_brk(TCONF, "The regular file is not on a filesystem that support DIO"); >>> +} >> >> On ext4, files that use certain filesystem features (data journalling, >> encryption, and verity) fall back to buffered I/O. This test will fail when >> passed such a file, as it assumes that DIO doesn't fall back to buffered I/O. > > Yes, I also reproduce it when I mount a partion with data=journal on > /tmp directory. > > mount -o data=journal /dev/vdb /tmp > [root@localhost statx]# ./statx10 > ...... > tst_test.c:1634: TINFO: === Testing on ext2 === > tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext2 opts='' extra > opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:59: TCONF: This test only supports ext4 and xfs > tst_test.c:1634: TINFO: === Testing on ext3 === > tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext3 opts='' extra > opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:59: TCONF: This test only supports ext4 and xfs > tst_test.c:1634: TINFO: === Testing on ext4 === > tst_test.c:1093: TINFO: Formatting /dev/loop0 with ext4 opts='' extra > opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) > passed Sorry, I did a mistake, I just test regular file on /tmp instead of on real ext4 or xfs filesystem because testfile does't under mntpoint. -#define TESTFILE "testfile" +#define TESTFILE MNTPOINT"/testfile" Best Regards Yang Xu > statx10.c:48: TFAIL: don't get stx_dio_mem_align on supported dio fs > statx10.c:53: TFAIL: don't get stx_dio_offset_align on supported dio fs > tst_test.c:1634: TINFO: === Testing on xfs === > tst_test.c:1093: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts='' > statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) > passed > statx10.c:48: TFAIL: don't get stx_dio_mem_align on supported dio fs > statx10.c:53: TFAIL: don't get stx_dio_offset_align on supported dio fs > tst_test.c:1634: TINFO: === Testing on tmpfs === > tst_test.c:1093: TINFO: Skipping mkfs for TMPFS filesystem > tst_test.c:1074: TINFO: Limiting tmpfs size to 32MB > statx10.c:59: TCONF: This test only supports ext4 and xfs > > IMO, If we use a actual block device to test instead of use a loop > device on /tmp directory, it should be ok. > > export LTP_DEV=/dev/vdb > tst_test.c:1634: TINFO: === Testing on ext2 === > tst_test.c:1093: TINFO: Formatting /dev/vdb with ext2 opts='' extra opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:59: TCONF: This test only supports ext4 and xfs > tst_test.c:1634: TINFO: === Testing on ext3 === > tst_test.c:1093: TINFO: Formatting /dev/vdb with ext3 opts='' extra opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:59: TCONF: This test only supports ext4 and xfs > tst_test.c:1634: TINFO: === Testing on ext4 === > tst_test.c:1093: TINFO: Formatting /dev/vdb with ext4 opts='' extra opts='' > mke2fs 1.46.5 (30-Dec-2021) > statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) > passed > statx10.c:46: TPASS: stx_dio_mem_align:512 > statx10.c:51: TPASS: stx_dio_offset_align:512 > tst_test.c:1634: TINFO: === Testing on xfs === > tst_test.c:1093: TINFO: Formatting /dev/vdb with xfs opts='' extra opts='' > statx10.c:37: TPASS: statx(AT_FDCWD, testfile, 0, STATX_DIOALIGN, &buf) > passed > statx10.c:46: TPASS: stx_dio_mem_align:512 > statx10.c:51: TPASS: stx_dio_offset_align:512 > tst_test.c:1634: TINFO: === Testing on tmpfs === > tst_test.c:1093: TINFO: Skipping mkfs for TMPFS filesystem > tst_test.c:1074: TINFO: Limiting tmpfs size to 32MB > statx10.c:59: TCONF: This test only supports ext4 and xfs > >> >> How is it guaranteed that such a file is not passed to this test? > > Since /etc/mk2fs.conf doesn't enable data=journal, encrypt, verity > feature by default and ltp use default mkfs configure , mount option. > > I think we can detect dio io support before mount. > > > Best Regards > Yang Xu > > > >> >> - Eric >
diff --git a/configure.ac b/configure.ac index 4c8763376..548288310 100644 --- a/configure.ac +++ b/configure.ac @@ -158,7 +158,7 @@ AC_CHECK_FUNCS(mkdtemp,[],AC_MSG_ERROR(mkdtemp() not found!)) 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],,,[ +AC_CHECK_MEMBERS([struct statx.stx_mnt_id, struct statx.stx_dio_mem_align],,,[ #define _GNU_SOURCE #include <sys/stat.h> ]) diff --git a/runtest/syscalls b/runtest/syscalls index 8b002e989..92123772c 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1769,6 +1769,7 @@ statx06 statx06 statx07 statx07 statx08 statx08 statx09 statx09 +statx10 statx10 membarrier01 membarrier01 diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 1cea43c0d..67341ff2d 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -7,3 +7,4 @@ /statx07 /statx08 /statx09 +/statx10 diff --git a/testcases/kernel/syscalls/statx/statx10.c b/testcases/kernel/syscalls/statx/statx10.c new file mode 100644 index 000000000..4307ada16 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx10.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@fujitsu.com> + */ + +/*\ + * [Description] + * + * It is a basic test for STATX_DIOALIGN mask on ext4 and xfs filesystem. + * + * - STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align value + * + * Minimum Linux version required is v6.1. + */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdlib.h> +#include <stdbool.h> +#include "tst_test.h" +#include "lapi/stat.h" + +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN +#define MNTPOINT "mnt_point" +#define TESTFILE "testfile" + +static int fd = -1; + +static void verify_statx(void) +{ + struct statx buf; + + memset(&buf, 0, sizeof(buf)); + TST_EXP_PASS(statx(AT_FDCWD, TESTFILE, 0, STATX_DIOALIGN, &buf), + "statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", TESTFILE); + + if (!(buf.stx_mask & STATX_DIOALIGN)) { + tst_res(TCONF, "STATX_DIOALIGN is not supported until linux 6.1"); + return; + } + + if (buf.stx_dio_mem_align != 0) + tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align); + else + tst_res(TFAIL, "don't get stx_dio_mem_align on supported dio fs"); + + if (buf.stx_dio_offset_align != 0) + tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align); + else + tst_res(TFAIL, "don't get stx_dio_offset_align on supported dio fs"); +} + +static void setup(void) +{ + if (strcmp(tst_device->fs_type, "xfs") && strcmp(tst_device->fs_type, "ext4")) + tst_brk(TCONF, "This test only supports ext4 and xfs"); + + SAFE_FILE_PRINTF(TESTFILE, "AAAA"); + fd = open(TESTFILE, O_RDWR | O_DIRECT); + if (fd == -1 && errno == EINVAL) + tst_brk(TCONF, "The regular file is not on a filesystem that support DIO"); +} + +static void cleanup(void) +{ + if (fd > -1) + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .test_all = verify_statx, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, +}; +#else +TST_TEST_TCONF("test requires struct statx to have the stx_dio_mem_align fields"); +#endif
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. For struct statx member check, we only check stx_dio_mem_align because these two member is introduced toger in separate commit in kernel, so it is safe. Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com> --- configure.ac | 2 +- runtest/syscalls | 1 + testcases/kernel/syscalls/statx/.gitignore | 1 + testcases/kernel/syscalls/statx/statx10.c | 84 ++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/statx/statx10.c