[LTP] [PATCH] tst_find_backing_dev: match mount point if major/minor can't be found
Cyril Hrubis
chrubis@suse.cz
Fri May 13 17:07:11 CEST 2022
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
More information about the ltp
mailing list