diff options
Diffstat (limited to 'testcases/kernel/syscalls/statx')
-rw-r--r-- | testcases/kernel/syscalls/statx/.gitignore | 3 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx01.c | 1 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx02.c | 1 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx03.c | 1 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx04.c | 3 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx05.c | 1 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx06.c | 4 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx07.c | 14 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx08.c | 1 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx09.c | 15 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx10.c | 93 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx11.c | 89 | ||||
-rw-r--r-- | testcases/kernel/syscalls/statx/statx12.c | 95 |
13 files changed, 306 insertions, 15 deletions
diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore index 1cea43c0d..f6a423eed 100644 --- a/testcases/kernel/syscalls/statx/.gitignore +++ b/testcases/kernel/syscalls/statx/.gitignore @@ -7,3 +7,6 @@ /statx07 /statx08 /statx09 +/statx10 +/statx11 +/statx12 diff --git a/testcases/kernel/syscalls/statx/statx01.c b/testcases/kernel/syscalls/statx/statx01.c index 68f56549f..f9c2748d2 100644 --- a/testcases/kernel/syscalls/statx/statx01.c +++ b/testcases/kernel/syscalls/statx/statx01.c @@ -33,6 +33,7 @@ #include "tst_test.h" #include "tst_safe_macros.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #include "tst_safe_stdio.h" #include <string.h> #include <inttypes.h> diff --git a/testcases/kernel/syscalls/statx/statx02.c b/testcases/kernel/syscalls/statx/statx02.c index a8e868d7a..5ed80894d 100644 --- a/testcases/kernel/syscalls/statx/statx02.c +++ b/testcases/kernel/syscalls/statx/statx02.c @@ -28,6 +28,7 @@ #include "tst_test.h" #include "tst_safe_macros.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #define TESTFILE "test_temp" #define LINK_FILE "test_temp_ln" diff --git a/testcases/kernel/syscalls/statx/statx03.c b/testcases/kernel/syscalls/statx/statx03.c index b88809063..2465d8773 100644 --- a/testcases/kernel/syscalls/statx/statx03.c +++ b/testcases/kernel/syscalls/statx/statx03.c @@ -24,6 +24,7 @@ #include "tst_safe_macros.h" #include "tst_get_bad_addr.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #define TESTFILE "test_file" #define MODE 0644 diff --git a/testcases/kernel/syscalls/statx/statx04.c b/testcases/kernel/syscalls/statx/statx04.c index 3923b7f8e..58296bd24 100644 --- a/testcases/kernel/syscalls/statx/statx04.c +++ b/testcases/kernel/syscalls/statx/statx04.c @@ -52,10 +52,11 @@ */ #define _GNU_SOURCE +#include <stdlib.h> #include "tst_test.h" #include "lapi/fs.h" -#include <stdlib.h> #include "lapi/stat.h" +#include "lapi/fcntl.h" #define MOUNT_POINT "mntpoint" #define TESTDIR MOUNT_POINT "/testdir" diff --git a/testcases/kernel/syscalls/statx/statx05.c b/testcases/kernel/syscalls/statx/statx05.c index f62dadd5c..9781b3e70 100644 --- a/testcases/kernel/syscalls/statx/statx05.c +++ b/testcases/kernel/syscalls/statx/statx05.c @@ -27,6 +27,7 @@ #include "tst_test.h" #include "lapi/fs.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #define MNTPOINT "mnt_point" #define TESTDIR_FLAGGED MNTPOINT"/test_dir1" diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c index fa75982b0..1771dff49 100644 --- a/testcases/kernel/syscalls/statx/statx06.c +++ b/testcases/kernel/syscalls/statx/statx06.c @@ -111,10 +111,10 @@ static void test_statx(unsigned int test_nr) clock_wait_tick(); SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &after_time); - TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_ALL, &buff)); + TEST(statx(AT_FDCWD, TEST_FILE, 0, STATX_BASIC_STATS | STATX_BTIME, &buff)); if (TST_RET != 0) { tst_brk(TFAIL | TTERRNO, - "statx(AT_FDCWD, %s, 0, STATX_ALL, &buff)", + "statx(AT_FDCWD, %s, 0, STATX_BASIC_STATS | STATX_BTIME, &buff)", TEST_FILE); } diff --git a/testcases/kernel/syscalls/statx/statx07.c b/testcases/kernel/syscalls/statx/statx07.c index 8cb3e9b6d..4dbf83e18 100644 --- a/testcases/kernel/syscalls/statx/statx07.c +++ b/testcases/kernel/syscalls/statx/statx07.c @@ -27,12 +27,7 @@ * but mode has been chaged in server file. * * The support for SYNC flags was implemented in NFS in: - * - * commit 9ccee940bd5b766b6dab6c1a80908b9490a4850d - * Author: Trond Myklebust <trond.myklebust@primarydata.com> - * Date: Thu Jan 4 17:46:09 2018 -0500 - * - * Support statx() mask and query flags parameters + * 9ccee940bd5b ("Support statx() mask and query flags parameters") */ #define _GNU_SOURCE @@ -44,6 +39,7 @@ #include <sys/mount.h> #include "tst_test.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #define MODE(X) (X & (~S_IFMT)) #define FLAG_NAME(x) .flag = x, .flag_name = #x @@ -67,15 +63,15 @@ static int get_mode(char *file_name, int flag_type, char *flag_name) { struct statx buf; - TEST(statx(AT_FDCWD, file_name, flag_type, STATX_ALL, &buf)); + TEST(statx(AT_FDCWD, file_name, flag_type, STATX_BASIC_STATS, &buf)); if (TST_RET == -1) { tst_brk(TFAIL | TST_ERR, - "statx(AT_FDCWD, %s, %s, STATX_ALL, &buf)", + "statx(AT_FDCWD, %s, %s, STATX_BASIC_STATS, &buf)", file_name, flag_name); } - tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_ALL, &buf) = %o", + tst_res(TINFO, "statx(AT_FDCWD, %s, %s, STATX_BASIC_STATS, &buf) = %o", file_name, flag_name, buf.stx_mode); return buf.stx_mode; diff --git a/testcases/kernel/syscalls/statx/statx08.c b/testcases/kernel/syscalls/statx/statx08.c index 10b1ca460..64b36986d 100644 --- a/testcases/kernel/syscalls/statx/statx08.c +++ b/testcases/kernel/syscalls/statx/statx08.c @@ -26,6 +26,7 @@ #include "lapi/fs.h" #include <stdlib.h> #include "lapi/stat.h" +#include "lapi/fcntl.h" #define MOUNT_POINT "mntpoint" #define TESTDIR_FLAGGED MOUNT_POINT"/test_dir1" diff --git a/testcases/kernel/syscalls/statx/statx09.c b/testcases/kernel/syscalls/statx/statx09.c index aea329e08..6e75ff3ec 100644 --- a/testcases/kernel/syscalls/statx/statx09.c +++ b/testcases/kernel/syscalls/statx/statx09.c @@ -20,10 +20,12 @@ #define _GNU_SOURCE #include <sys/mount.h> #include <stdlib.h> +#include <stdio.h> #include "tst_test.h" #include "lapi/fs.h" #include "lapi/fsverity.h" #include "lapi/stat.h" +#include "lapi/fcntl.h" #include <inttypes.h> #define MNTPOINT "mnt_point" @@ -79,8 +81,10 @@ static void flag_setup(void) { int fd, attr, ret; struct fsverity_enable_arg enable; + struct stat statbuf; fd = SAFE_OPEN(TESTFILE_FLAGGED, O_RDONLY, 0664); + SAFE_FSTAT(fd, &statbuf); ret = ioctl(fd, FS_IOC_GETFLAGS, &attr); if (ret < 0) { @@ -93,7 +97,7 @@ static void flag_setup(void) memset(&enable, 0, sizeof(enable)); enable.version = 1; enable.hash_algorithm = hash_algorithms[0]; - enable.block_size = 4096; + enable.block_size = statbuf.st_blksize; enable.salt_size = 0; enable.salt_ptr = (intptr_t)NULL; enable.sig_size = 0; @@ -117,6 +121,12 @@ static void flag_setup(void) static void setup(void) { + char opt_bsize[32]; + const char *const fs_opts[] = {"-O verity", opt_bsize, NULL}; + + snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", getpagesize()); + SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL); + TEST(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL)); if (TST_RET) { if (TST_ERR == EINVAL) @@ -144,10 +154,9 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_root = 1, + .needs_device = 1, .mntpoint = MNTPOINT, - .format_device = 1, .dev_fs_type = "ext4", - .dev_fs_opts = (const char *const []){"-O verity", NULL}, .needs_kconfigs = (const char *[]) { "CONFIG_FS_VERITY", NULL diff --git a/testcases/kernel/syscalls/statx/statx10.c b/testcases/kernel/syscalls/statx/statx10.c new file mode 100644 index 000000000..42106285e --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx10.c @@ -0,0 +1,93 @@ +// 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 + * + * Check these two values are nonzero under dio situation when STATX_DIOALIGN + * in the request mask. + * + * On ext4, files that use certain filesystem features (data journaling, + * 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. + * + * Minimum Linux version required is v6.1. + */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdbool.h> +#include "tst_test.h" +#include "lapi/stat.h" +#include "lapi/fcntl.h" + +#define MNTPOINT "mnt_point" +#define TESTFILE MNTPOINT"/testfile" + +static void verify_statx(void) +{ + struct statx buf; + + TST_EXP_PASS_SILENT(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, "Filesystem does not support STATX_DIOALIGN"); + return; + } + +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN + if (buf.stx_dio_mem_align != 0) + tst_res(TPASS, "stx_dio_mem_align:%u", buf.stx_dio_mem_align); + else + tst_res(TFAIL, "stx_dio_mem_align was 0, but DIO should be supported"); + + if (buf.stx_dio_offset_align != 0) + tst_res(TPASS, "stx_dio_offset_align:%u", buf.stx_dio_offset_align); + else + tst_res(TFAIL, "stx_dio_offset_align was 0, but DIO should be supported"); +#else + tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field"); +#endif +} + +static void setup(void) +{ + int fd = -1; + + 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) { + if (errno == EINVAL) + tst_brk(TCONF, + "The regular file is not on a filesystem that support DIO"); + else + tst_brk(TBROK | TERRNO, + "The regular file is open with O_RDWR | O_DIRECT failed"); + } + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .test_all = verify_statx, + .setup = setup, + .needs_root = 1, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, +}; diff --git a/testcases/kernel/syscalls/statx/statx11.c b/testcases/kernel/syscalls/statx/statx11.c new file mode 100644 index 000000000..653050855 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx11.c @@ -0,0 +1,89 @@ +// 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 block device. + * + * - STATX_DIOALIGN Want stx_dio_mem_align and stx_dio_offset_align value + * + * These two values are tightly coupled to the kernel's current DIO + * restrictions on block devices. + * + * Minimum Linux version required is v6.1. + */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <sys/mount.h> +#include <unistd.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdio.h> +#include "tst_test.h" +#include "lapi/stat.h" + +static char sys_bdev_dma_path[1024], sys_bdev_logical_path[1024]; + +static void verify_statx(void) +{ + struct statx buf; + + TST_EXP_PASS_SILENT(statx(AT_FDCWD, tst_device->dev, 0, STATX_DIOALIGN, &buf), + "statx(AT_FDCWD, %s, 0, STATX_DIOALIGN, &buf)", tst_device->dev); + + if (!(buf.stx_mask & STATX_DIOALIGN)) { + tst_res(TCONF, "Filesystem does not support STATX_DIOALIGN"); + return; + } + +#ifdef HAVE_STRUCT_STATX_STX_DIO_MEM_ALIGN + /* + * This test is tightly coupled to the kernel's current DIO restrictions + * on block devices. The general rule of DIO needing to be aligned to the + * block device's logical block size was relaxed to allow user buffers + * (but not file offsets) aligned to the DMA alignment instead. See v6.0 + * commit bf8d08532bc1 ("iomap: add support for dma aligned direct-io") and + * they are subject to further change in the future. + * Also can see commit 2d985f8c6b9 ("vfs: support STATX_DIOALIGN on block devices). + */ + TST_ASSERT_ULONG(sys_bdev_dma_path, buf.stx_dio_mem_align - 1); + TST_ASSERT_ULONG(sys_bdev_logical_path, buf.stx_dio_offset_align); +#else + tst_res(TCONF, "glibc statx struct miss stx_dio_mem_align field"); +#endif +} + +static void setup(void) +{ + char full_name[256]; + char *dev_name; + + strcpy(full_name, tst_device->dev); + dev_name = SAFE_BASENAME(full_name); + sprintf(sys_bdev_logical_path, "/sys/block/%s/queue/logical_block_size", dev_name); + + /* + * Since /sys/block/%s/queue doesn't exist for partition, we need to + * use a while to search block device instead of partition. + */ + while (access(sys_bdev_logical_path, F_OK) != 0) { + dev_name[strlen(dev_name)-1] = '\0'; + sprintf(sys_bdev_logical_path, "/sys/block/%s/queue/logical_block_size", dev_name); + } + + sprintf(sys_bdev_dma_path, "/sys/block/%s/queue/dma_alignment", dev_name); + if (access(sys_bdev_dma_path, F_OK) != 0) + tst_brk(TCONF, "dma_alignment sysfs file doesn't exist"); +} + +static struct tst_test test = { + .test_all = verify_statx, + .setup = setup, + .needs_device = 1, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/statx/statx12.c b/testcases/kernel/syscalls/statx/statx12.c new file mode 100644 index 000000000..432f1cb77 --- /dev/null +++ b/testcases/kernel/syscalls/statx/statx12.c @@ -0,0 +1,95 @@ +// 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_ATTR_MOUNT_ROOT flag. + * + * This flag indicates whether the path or fd refers to the root of a mount + * or not. + * + * Minimum Linux version required is v5.8. + */ + +#define _GNU_SOURCE +#include <unistd.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdio.h> +#include "tst_test.h" +#include "lapi/stat.h" + +#define MNTPOINT "mntpoint" +#define TESTFILE MNTPOINT"/testfile" + +static int dir_fd = -1, file_fd = -1; + +static struct tcase { + const char *path; + bool mnt_root; + int *fd; +} tcases[] = { + {MNTPOINT, 1, &dir_fd}, + {TESTFILE, 0, &file_fd} +}; + +static void verify_statx(unsigned int n) +{ + struct tcase *tc = &tcases[n/2]; + struct statx buf; + bool flag = n % 2; + + if (flag) { + tst_res(TINFO, "Testing %s with STATX_ATTR_MOUNT_ROOT by fd", + tc->path); + TST_EXP_PASS_SILENT(statx(*tc->fd, "", AT_EMPTY_PATH, 0, &buf)); + } else { + tst_res(TINFO, "Testing %s with STATX_ATTR_MOUNT_ROOT by path", + tc->path); + TST_EXP_PASS_SILENT(statx(AT_FDCWD, tc->path, 0, 0, &buf)); + } + + if (!(buf.stx_attributes_mask & STATX_ATTR_MOUNT_ROOT)) { + tst_res(TCONF, "Filesystem does not support STATX_ATTR_MOUNT_ROOT"); + return; + } + + if (buf.stx_attributes & STATX_ATTR_MOUNT_ROOT) { + tst_res(tc->mnt_root ? TPASS : TFAIL, + "STATX_ATTR_MOUNT_ROOT flag is set"); + } else { + tst_res(tc->mnt_root ? TFAIL : TPASS, + "STATX_ATTR_MOUNT_ROOT flag is not set"); + } +} + +static void setup(void) +{ + SAFE_CREAT(TESTFILE, 0755); + dir_fd = SAFE_OPEN(MNTPOINT, O_DIRECTORY); + file_fd = SAFE_OPEN(TESTFILE, O_RDWR); +} + +static void cleanup(void) +{ + if (dir_fd > -1) + SAFE_CLOSE(dir_fd); + + if (file_fd > -1) + SAFE_CLOSE(file_fd); +} + +static struct tst_test test = { + .test = verify_statx, + .setup = setup, + .cleanup = cleanup, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_root = 1, + .tcnt = 2 * ARRAY_SIZE(tcases) +}; |