From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size
Date: Wed, 24 Jun 2020 13:32:17 +0200 [thread overview]
Message-ID: <20200624113217.GC30917@yuki.lan> (raw)
In-Reply-To: <1591853524-17011-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>
Hi!
> +static void find_backing_bdpath(char *buf)
> +{
> + const char *const df_cmd[] = {"df", "-T", ".", NULL};
> + char line[PATH_MAX];
> + FILE *file;
> +
> + SAFE_CMD(df_cmd, "1.txt", NULL);
> + file = SAFE_FOPEN("1.txt", "r");
> +
> + while (fgets(line, sizeof(line), file) != NULL) {
> + sscanf(line, "%s", buf);
> + if (strstr(buf, "/dev/") != NULL)
> + break;
> + }
> + SAFE_FCLOSE(file);
> +}
I do not like that we are calling df for something like this.
Looking at what that command does it's not that complex. It does
statfs() to get minor and major number, then scans /proc/self/mountinfo
for these, since these are on third column and then just prints whatever
it's in the 10th column. This isn't more complex that what we have here
and avoids needs to execute binaries and parse the output.
Also this function could be in a test library probably in tst_device.h.
> static void setup(void)
> {
> - int fd;
> - struct stat buf;
> + char buf[100];
>
> if (tst_fs_type(".") == TST_TMPFS_MAGIC)
> tst_brk(TCONF, "tmpfd doesn't support O_DIRECT flag");
> @@ -109,13 +126,6 @@ static void setup(void)
> sprintf(sys_loop_diopath, "/sys/block/loop%d/loop/dio", dev_num);
> tst_fill_file("test.img", 0, 1024, 1024);
>
> - fd = SAFE_OPEN("test.img", O_RDONLY);
> - SAFE_FSTAT(fd, &buf);
> - SAFE_CLOSE(fd);
> -
> - logical_block_size = buf.st_blksize;
> - tst_res(TINFO, "backing dev logical_block_size is %d", logical_block_size);
> -
> tst_attach_device(dev_path, "test.img");
> attach_flag = 1;
> dev_fd = SAFE_OPEN(dev_path, O_RDWR);
> @@ -130,13 +140,23 @@ static void setup(void)
> * size of loop is bigger than the backing device's and the loop
> * needn't transform transfer.
> */
> - TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
> + find_backing_bdpath(buf);
> + block_devfd = SAFE_OPEN(buf, O_RDWR);
> +
> + SAFE_IOCTL(block_devfd, BLKSSZGET, &logical_block_size);
> + tst_res(TINFO, "backing dev logical_block_size is %d", logical_block_size);
> + SAFE_CLOSE(block_devfd);
> +
> + if (logical_block_size > 512)
> + TST_RETRY_FUNC(ioctl(dev_fd, LOOP_SET_BLOCK_SIZE, logical_block_size), TST_RETVAL_EQ0);
> }
>
> static void cleanup(void)
> {
> if (dev_fd > 0)
> SAFE_CLOSE(dev_fd);
> + if (block_devfd > 0)
> + SAFE_CLOSE(block_devfd);
> if (attach_flag)
> tst_detach_device(dev_path);
> }
> @@ -150,5 +170,9 @@ static struct tst_test test = {
> .needs_drivers = (const char *const []) {
> "loop",
> NULL
> + },
> + .needs_cmds = (const char *const []) {
> + "df",
> + NULL
> }
> };
> --
> 2.23.0
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-06-24 11:32 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-09 8:33 [LTP] [PATCH] syscalls/ioctl_loop05: Get the logic_block_size dynamically Yang Xu
2020-06-09 9:24 ` Jan Stancek
2020-06-09 9:48 ` Yang Xu
2020-06-09 10:16 ` Jan Stancek
2020-06-09 10:46 ` Yang Xu
2020-06-09 11:01 ` Jan Stancek
2020-06-10 1:19 ` Yang Xu
2020-06-10 5:37 ` [LTP] [PATCH v2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-06-10 10:13 ` Jan Stancek
2020-06-10 10:42 ` Yang Xu
2020-06-10 12:19 ` Yang Xu
2020-06-10 13:04 ` Jan Stancek
2020-06-11 4:56 ` Yang Xu
2020-06-11 5:32 ` [LTP] [PATCH v3] " Yang Xu
2020-06-11 11:09 ` Jan Stancek
2020-06-12 2:57 ` Yang Xu
2020-06-24 5:07 ` Yang Xu
2020-06-24 11:32 ` Cyril Hrubis [this message]
2020-06-24 13:06 ` Jan Stancek
2020-06-25 17:10 ` Yang Xu
2020-06-28 7:42 ` [LTP] [PATCH v4 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Yang Xu
2020-06-28 7:42 ` [LTP] [PATCH v4 2/2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-06-29 7:56 ` [LTP] [PATCH v4 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Jan Stancek
2020-06-29 10:37 ` Yang Xu
2020-06-29 11:08 ` Jan Stancek
2020-06-29 11:41 ` [LTP] [PATCH v5 " Yang Xu
2020-06-29 11:41 ` [LTP] [PATCH v5 2/2] syscalls/ioctl_loop05: Use correct blockdev to get logical_block_size Yang Xu
2020-07-02 9:18 ` [LTP] [PATCH v5 1/2] tst_device: Add new api tst_find_backing_dev(path, dev) Jan Stancek
2020-07-02 12:27 ` Cyril Hrubis
2020-07-02 13:17 ` Jan Stancek
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=20200624113217.GC30917@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