[LTP] [PATCH v6 6/6] syscalls/statx11: Add basic test for STATX_DIOALIGN on block device

Xiao Yang (Fujitsu) yangx.jy@fujitsu.com
Fri May 19 08:24:51 CEST 2023


Hi Xu

LGTM.
Reviewed-by: Xiao Yang <yangx.jy@fujitsu.com>

Best Regards,
Xiao Yang

On 2023/5/15 15:11, Yang Xu wrote:
> Since STATX_DIOLAIGN is only supported on regular file and block device,
> so this case is used to test the latter.
> 
> This test is tightly coupled to the kernel's current DIO restrictions on block
> devices.  These changed in v6.0, and they are subject to further change in the
> future.
> 
> It is fine for now because STATX_DIOALIGN is only in v6.1 and later
> anyway.
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>   runtest/syscalls                           |  1 +
>   testcases/kernel/syscalls/statx/.gitignore |  1 +
>   testcases/kernel/syscalls/statx/statx11.c  | 89 ++++++++++++++++++++++
>   3 files changed, 91 insertions(+)
>   create mode 100644 testcases/kernel/syscalls/statx/statx11.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index e2548dae5..e5ad2c2f9 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1766,6 +1766,7 @@ statx07 statx07
>   statx08 statx08
>   statx09 statx09
>   statx10 statx10
> +statx11 statx11
>   
>   membarrier01 membarrier01
>   
> diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore
> index 67341ff2d..48ac4078b 100644
> --- a/testcases/kernel/syscalls/statx/.gitignore
> +++ b/testcases/kernel/syscalls/statx/.gitignore
> @@ -8,3 +8,4 @@
>   /statx08
>   /statx09
>   /statx10
> +/statx11
> 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,
> +};


More information about the ltp mailing list