From: Cyril Hrubis <chrubis@suse.cz>
To: Jan Stancek <jstancek@redhat.com>
Cc: liwan@redhat.com, xuyang2018.jy@cn.fujitsu.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] tst_find_backing_dev: match mount point if major/minor can't be found
Date: Fri, 13 May 2022 17:07:11 +0200 [thread overview]
Message-ID: <Yn50Hx2IqdXU1nzC@yuki> (raw)
In-Reply-To: <f38ee2905aa8b765c243896fa326b5507919a446.1651061197.git.jstancek@redhat.com>
Hi!
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
> lib/tst_device.c | 31 +++++++++++++++++++++----------
> 1 file changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index d296f9118cde..e560ec97460b 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -506,14 +506,22 @@ unsigned long tst_dev_bytes_written(const char *dev)
> return dev_bytes_written;
> }
>
> +static int count_match_len(const char *first, const char *second)
> +{
> + int len = 0;
> +
> + while (*first && *first++ == *second++)
> + len++;
> +
> + return len;
> +}
> +
> void tst_find_backing_dev(const char *path, char *dev)
> {
> struct stat buf;
> FILE *file;
> - char line[PATH_MAX];
> - char *pre = NULL;
> - char *next = NULL;
> - unsigned int dev_major, dev_minor, line_mjr, line_mnr;
> + char line[PATH_MAX], mnt_point[PATH_MAX], mnt_source[PATH_MAX];
> + unsigned int dev_major, dev_minor, line_mjr, line_mnr, best_match_len = 0;
>
> if (stat(path, &buf) < 0)
> tst_brkm(TWARN | TERRNO, NULL, "stat() failed");
> @@ -524,17 +532,20 @@ void tst_find_backing_dev(const char *path, char *dev)
> *dev = '\0';
>
> while (fgets(line, sizeof(line), file)) {
> - if (sscanf(line, "%*d %*d %d:%d", &line_mjr, &line_mnr) != 2)
> + if (sscanf(line, "%*d %*d %d:%d %*s %s %*s %*s %*s %*s %s",
> + &line_mjr, &line_mnr, mnt_point, mnt_source) != 4)
> continue;
We did this before and it didn't work see: 5dfd9c29f094e3024ceab760715456436188ecab
We really have to parse the string based on the dash (" - ") to make it
work reliably.
Other than that the rest of the patch looks reasonable.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2022-05-13 15:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 12:08 [LTP] [PATCH] tst_find_backing_dev: match mount point if major/minor can't be found Jan Stancek
2022-05-13 15:07 ` Cyril Hrubis [this message]
2022-05-17 12:19 ` [LTP] [PATCH v2] " Jan Stancek
2022-05-17 15:33 ` Cyril Hrubis
2022-05-19 9:56 ` Jan Stancek
2022-05-19 10:01 ` Cyril Hrubis
2022-05-19 10:13 ` 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=Yn50Hx2IqdXU1nzC@yuki \
--to=chrubis@suse.cz \
--cc=jstancek@redhat.com \
--cc=liwan@redhat.com \
--cc=ltp@lists.linux.it \
--cc=xuyang2018.jy@cn.fujitsu.com \
/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