public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1 03/10] syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test
Date: Fri, 3 Apr 2020 13:55:02 +0200	[thread overview]
Message-ID: <20200403115502.GC26355@yuki.lan> (raw)
In-Reply-To: <1585839990-19923-4-git-send-email-xuyang2018.jy@cn.fujitsu.com>

Hi!
> For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
> directory and also get lo_flags by using LOOP_GET_STATUS.
> 
> For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
> But we also check whether we can scan partition table correctly ie check
> whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
> 
> Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> ---
>  runtest/syscalls                              |   3 +-
>  testcases/kernel/syscalls/ioctl/.gitignore    |   1 +
>  .../kernel/syscalls/ioctl/ioctl_loop01.c      | 127 ++++++++++++++++++
>  3 files changed, 130 insertions(+), 1 deletion(-)
>  create mode 100644 testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 777f0ac6a..7fd67450e 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -524,10 +524,11 @@ ioctl03      ioctl03
>  ioctl04      ioctl04
>  ioctl05      ioctl05
>  ioctl06      ioctl06
> -
>  ioctl07      ioctl07
>  ioctl08      ioctl08
>  
> +ioctl_loop01 ioctl_loop01
> +
>  ioctl_ns01 ioctl_ns01
>  ioctl_ns02 ioctl_ns02
>  ioctl_ns03 ioctl_ns03
> diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
> index 97fbb9681..4cfef2839 100644
> --- a/testcases/kernel/syscalls/ioctl/.gitignore
> +++ b/testcases/kernel/syscalls/ioctl/.gitignore
> @@ -6,6 +6,7 @@
>  /ioctl06
>  /ioctl07
>  /ioctl08
> +/ioctl_loop01
>  /ioctl_ns01
>  /ioctl_ns02
>  /ioctl_ns03
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> new file mode 100644
> index 000000000..e806e0443
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
> @@ -0,0 +1,127 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
> + *
> + * This is a basic ioctl test about loopdevice.
> + * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
> + *
> + * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear fieldvalue in sys
> + * directory and also get lo_flags by using LOOP_GET_STATUS.
> + *
> + * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
> + * But we also check whether we can scan partition table correctly ie check
> + * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
> + */
> +
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include "ioctl_loop_support.h"
> +#include "lapi/loop.h"
> +#include "tst_test.h"
> +
> +static char dev_path[1024], backing_path[1024], backing_file_path[1024];
> +static int dev_num, attach_flag, dev_fd;
> +/*
> + *In drivers/block/loop.c code, set status function doesn't handle
> + *LO_FLAGS_READ_ONLY flag and ingore it. Only loop_set_fd with rondonly
> + *mode file_fd, lo_flags will include LO_FLAGS_READ_ONLY.
> + */
> +#define set_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN | LO_FLAGS_READ_ONLY | LO_FLAGS_DIRECT_IO)
> +#define get_flags (LO_FLAGS_AUTOCLEAR | LO_FLAGS_PARTSCAN)
> +
> +static char partscan_path[1024], autoclear_path[1024];
> +static char loop_partpath[1026], sys_loop_partpath[1026];
> +
> +static void verify_ioctl_loop(void)
> +{
> +	int ret;
> +	struct loop_info loopinfo, loopinfoget;
> +
> +	tst_attach_device(dev_path, "test.img");
> +	attach_flag = 1;
> +
> +	check_sys_value(partscan_path, 0);
> +	check_sys_value(autoclear_path, 0);
> +	check_sys_string(backing_path, backing_file_path);
> +
> +	dev_fd = SAFE_OPEN(dev_path, O_RDWR);
> +	memset(&loopinfo, 0, sizeof(loopinfo));
> +	memset(&loopinfo, 0, sizeof(loopinfoget));
> +
> +	loopinfo.lo_flags = set_flags;
> +	SAFE_IOCTL(dev_fd, LOOP_SET_STATUS, &loopinfo);

I guess that it would be safer to memset() the loopinfo_get here, also
if we zero the structure we may as well reuse the loopinfo here as well.

> +	SAFE_IOCTL(dev_fd, LOOP_GET_STATUS, &loopinfoget);
> +
> +	if (loopinfoget.lo_flags & ~get_flags)
> +		tst_res(TFAIL, "expect %d but got %d", get_flags, loopinfoget.lo_flags);
> +	else
> +		tst_res(TPASS, "get expected lo_flag %d", loopinfoget.lo_flags);
> +
> +	ret = access(loop_partpath, F_OK);
> +	if (ret == 0)
> +		tst_res(TPASS, "access %s succeeds", loop_partpath);
> +	else
> +		tst_res(TFAIL, "access %s fails", loop_partpath);
> +
> +	ret = access(sys_loop_partpath, F_OK);
> +	if (ret == 0)
> +		tst_res(TPASS, "access %s succeeds", sys_loop_partpath);
> +	else
> +		tst_res(TFAIL, "access %s fails", sys_loop_partpath);
> +
> +	check_sys_value(partscan_path, 1);
> +	check_sys_value(autoclear_path, 1);
> +
> +	SAFE_CLOSE(dev_fd);
> +	tst_detach_device(dev_path);
> +	attach_flag = 0;
> +}
> +
> +static void setup(void)
> +{
> +	const char *const cmd_dd[] = {"dd", "if=/dev/zero", "of=test.img", "bs=1M", "count=10", NULL};
> +	const char *const cmd_parted[] = {"parted", "-s", "test.img", "mklabel", "msdos", "mkpart",
> +						"primary", "ext4", "1M", "10M", NULL};
> +
> +	dev_num = tst_find_free_loopdev(dev_path, sizeof(dev_path));
> +	if (dev_num < 0)
> +		tst_brk(TBROK, "Failed to find free loop device");
> +
> +	SAFE_CMD(cmd_dd, NULL, NULL);

Why not tst_fill_file("test.img", 0, 1024 * 1024, 10); ?

> +	SAFE_CMD(cmd_parted, NULL, NULL);

I wonder if we can avoid dependency on parted by having a look at the
changes in the image after the call to parted and writing a few bytes
ourselves instead.

> +	sprintf(partscan_path, "/sys/block/loop%d/loop/partscan", dev_num);
> +	sprintf(autoclear_path, "/sys/block/loop%d/loop/autoclear", dev_num);
> +	sprintf(backing_path, "/sys/block/loop%d/loop/backing_file", dev_num);
> +	sprintf(sys_loop_partpath, "/sys/block/loop%d/loop%dp1", dev_num, dev_num);
> +	sprintf(backing_file_path, "%s/test.img", tst_get_tmpdir());
> +	sprintf(loop_partpath, "%sp1", dev_path);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (dev_fd > 0)
> +		SAFE_CLOSE(dev_fd);
> +	if (attach_flag)
> +		tst_detach_device(dev_path);
> +}
> +
> +static struct tst_test test = {
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.test_all = verify_ioctl_loop,
> +	.needs_root = 1,
> +	.needs_cmds = (const char *const []) {
> +		"dd",
> +		"parted",
> +		NULL
> +	},
> +	.needs_drivers = (const char *const []) {
> +		"loop",
> +		NULL
> +	},
> +	.needs_tmpdir = 1,
> +};
> -- 
> 2.23.0
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2020-04-03 11:55 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-02 15:06 [LTP] [PATCH v1 00/10] add loop ioctl test Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 01/10] lapi: Add a configure check and fallback for loop ioctl and flag Yang Xu
2020-04-03 11:44   ` Cyril Hrubis
2020-04-06  6:01     ` Yang Xu
2020-04-09  8:47   ` Martin Doucha
2020-04-09 10:09     ` Cyril Hrubis
2020-04-09 10:14     ` Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 02/10] syscalls/ioctl:add common c file for loop ioctl Yang Xu
2020-04-03 12:16   ` Cyril Hrubis
2020-04-09  2:42     ` Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 03/10] syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test Yang Xu
2020-04-03 11:55   ` Cyril Hrubis [this message]
2020-04-06  6:27     ` Yang Xu
2020-04-09  6:10       ` Yang Xu
2020-04-09  7:55         ` Cyril Hrubis
2020-04-09 10:44           ` [LTP] [PATCH v2 01/10] lapi/loop.h: Add fallback for loop ioctl and flag Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 02/10] syscalls/ioctl:add common c file for loop ioctl Yang Xu
2020-04-17 15:10               ` Cyril Hrubis
2020-04-20  2:23                 ` Yang Xu
2020-04-20  6:08                   ` Yang Xu
2020-04-20 13:01                     ` Cyril Hrubis
2020-04-21  6:19                       ` Yang Xu
2020-04-21  8:55                         ` Cyril Hrubis
2020-04-21 10:35                           ` Yang Xu
2020-04-21 12:12                             ` Cyril Hrubis
2020-04-22  3:12                               ` Yang Xu
2020-04-20 12:55                   ` Cyril Hrubis
2020-04-09 10:44             ` [LTP] [PATCH v2 03/10] syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 04/10] syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 05/10] syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode Yang Xu
2020-04-17 15:12               ` Cyril Hrubis
2020-04-09 10:44             ` [LTP] [PATCH v2 06/10] syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 07/10] syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO " Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 08/10] syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test Yang Xu
2020-04-22 13:57               ` Cyril Hrubis
2020-04-09 10:44             ` [LTP] [PATCH v2 09/10] syscalls/ioctl_loop07: Add dio with logic block size " Yang Xu
2020-04-22 13:58               ` Cyril Hrubis
2020-04-23  6:06                 ` Yang Xu
2020-04-23 10:12                   ` Yang Xu
2020-04-24  4:43                     ` Yang Xu
2020-04-09 10:44             ` [LTP] [PATCH v2 10/10] syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test Yang Xu
2020-04-28 15:44               ` Cyril Hrubis
2020-04-09 10:44             ` [LTP] [PATCH v2 00/10] add loop ioctl test Yang Xu
2020-04-09 10:50             ` [LTP] [PATCH v2 01/10] lapi/loop.h: Add fallback for loop ioctl and flag Yang Xu
2020-04-17 15:11             ` Cyril Hrubis
2020-04-27  1:24   ` [LTP] [PATCH v1 03/10] syscalls/ioctl_loop01: Add LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN test Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 04/10] syscalls/ioctl_loop02: Add LO_FLAGS_READ_ONLY and LOOP_CHANGE_FD test Yang Xu
2020-04-03 13:34   ` Cyril Hrubis
2020-04-06  7:24     ` Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 05/10] syscalls/ioctl_loop03: Add LOOP_CHANGE_FD test with WR mode Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 06/10] syscalls/ioctl_loop04: Add LOOP_SET_CAPACITY ioctl test Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 07/10] syscalls/ioctl_loop05: Add LOOP_SET_DIRECT_IO " Yang Xu
2020-04-03 16:44   ` Cyril Hrubis
2020-04-06  7:53     ` Yang Xu
2020-04-06  8:30       ` Cyril Hrubis
2020-04-02 15:06 ` [LTP] [PATCH v1 08/10] syscalls/ioctl_loop06: Add LOOP_SET_BLOCK_SIZE error test Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 09/10] syscalls/ioctl_loop07: Add dio with logic block size " Yang Xu
2020-04-02 15:06 ` [LTP] [PATCH v1 10/10] syscalls/ioctl_loop08: Add LOOP_SET/GET_STATUS64 sizelimit field test Yang Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200403115502.GC26355@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox