[LTP] [PATCH v2] tst_find_backing_dev: match mount point if major/minor can't be found
Jan Stancek
jstancek@redhat.com
Tue May 17 14:19:44 CEST 2022
ioctl_loop05 fails on btrfs, because tst_find_backing_dev doesn't find
major/minor returned by stat()
Per https://lwn.net/Articles/866582
"btrfs allocates a separate device number (the usual major/minor pair)
for each subvolume ... and call to on a file within a subvolume will
return a device number that does not exist in files like mountinfo."
As fallback, if there's no major/minor match, use best match of mount path.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
lib/tst_device.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/lib/tst_device.c b/lib/tst_device.c
index d296f9118cde..b1af0f0146d4 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -506,6 +506,16 @@ 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;
@@ -514,6 +524,8 @@ void tst_find_backing_dev(const char *path, char *dev)
char *pre = NULL;
char *next = NULL;
unsigned int dev_major, dev_minor, line_mjr, line_mnr;
+ unsigned int len, best_match_len = 0;
+ char mnt_point[PATH_MAX];
if (stat(path, &buf) < 0)
tst_brkm(TWARN | TERRNO, NULL, "stat() failed");
@@ -524,17 +536,25 @@ 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",
+ &line_mjr, &line_mnr, mnt_point) != 3)
continue;
+ pre = strstr(line, " - ");
+ pre = strtok_r(pre, " ", &next);
+ pre = strtok_r(NULL, " ", &next);
+ pre = strtok_r(NULL, " ", &next);
+
if (line_mjr == dev_major && line_mnr == dev_minor) {
- pre = strstr(line, " - ");
- pre = strtok_r(pre, " ", &next);
- pre = strtok_r(NULL, " ", &next);
- pre = strtok_r(NULL, " ", &next);
strcpy(dev, pre);
break;
}
+
+ len = count_match_len(path, mnt_point);
+ if (len > best_match_len) {
+ strcpy(dev, pre);
+ best_match_len = len;
+ }
}
SAFE_FCLOSE(NULL, file);
--
2.27.0
More information about the ltp
mailing list