<div dir="auto"><div>Hello,</div><div dir="auto"><br></div><div dir="auto">Thank you this new version of the patch.</div><div dir="auto">in this moment doc/c-test-api.txt is out of sync with the code, I can handle its fix.</div><div dir="auto"><br></div><div dir="auto">Regards</div><div dir="auto">Alessandro<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Tue, Oct 25, 2022, 16:59 Richard Palethorpe <<a href="mailto:rpalethorpe@suse.com">rpalethorpe@suse.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mountinfo doesn't always contain the correct device name. For example<br>
/dev/root may be displayed, but not exist in devtmpfs[1].<br>
<br>
The unevent file in sysfs is another way of finding the device name<br>
from the major and minor numbers. Possibly it always displays the<br>
proper device name.<br>
<br>
One caveat is the sysfs can be disabled, so this commit does not<br>
remove the mountinfo method altogether, but leaves it as a fallback.<br>
<br>
Alessandro Carminati originally sent two patches[1] which added the<br>
uevent file method as a fallback. However it seems like the better<br>
method.<br>
<br>
[1]: <a href="https://lore.kernel.org/ltp/Y0023HcAOlhfAcJw@lab.hqhome163.com/" rel="noreferrer noreferrer" target="_blank">https://lore.kernel.org/ltp/Y0023HcAOlhfAcJw@lab.hqhome163.com/</a><br>
<br>
Signed-off-by: Richard Palethorpe <<a href="mailto:rpalethorpe@suse.com" target="_blank" rel="noreferrer">rpalethorpe@suse.com</a>><br>
Suggested-by: Alessandro Carminati <<a href="mailto:alessandro.carminati@gmail.com" target="_blank" rel="noreferrer">alessandro.carminati@gmail.com</a>><br>
Reported-by: Alessandro Carminati <<a href="mailto:alessandro.carminati@gmail.com" target="_blank" rel="noreferrer">alessandro.carminati@gmail.com</a>><br>
---<br>
<br>
Alessandro, it seems you tried to edit the last patch by hand? In any<br>
case it did not apply and I ended up making some other changes. So I<br>
took the liberty of submitting a new patch.<br>
<br>
Thanks,<br>
Richard.<br>
<br>
 lib/tst_device.c | 20 ++++++++++++++++++--<br>
 1 file changed, 18 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/lib/tst_device.c b/lib/tst_device.c<br>
index 8419b80c3..676903fff 100644<br>
--- a/lib/tst_device.c<br>
+++ b/lib/tst_device.c<br>
@@ -526,14 +526,30 @@ void tst_find_backing_dev(const char *path, char *dev)<br>
        unsigned int dev_major, dev_minor, line_mjr, line_mnr;<br>
        unsigned int len, best_match_len = 1;<br>
        char mnt_point[PATH_MAX];<br>
+       char uevent_path[PATH_MAX];<br>
+       char dev_name[NAME_MAX];<br>
<br>
        if (stat(path, &buf) < 0)<br>
                tst_brkm(TWARN | TERRNO, NULL, "stat() failed");<br>
<br>
+       *dev = '\0';<br>
        dev_major = major(buf.st_dev);<br>
        dev_minor = minor(buf.st_dev);<br>
+<br>
+       sprintf(uevent_path,<br>
+               "/sys/dev/block/%d:%d/uevent", dev_major, dev_minor);<br>
+<br>
+       if (!access(uevent_path, R_OK)) {<br>
+               FILE_LINES_SCANF(NULL, uevent_path, "DEVNAME=%s", dev_name);<br>
+<br>
+               if (dev_name[0])<br>
+                       sprintf(dev, "/dev/%s", dev_name);<br>
+       }<br>
+<br>
+       if (!stat(dev, &buf))<br>
+               goto out;<br>
+<br>
        file = SAFE_FOPEN(NULL, "/proc/self/mountinfo", "r");<br>
-       *dev = '\0';<br>
<br>
        while (fgets(line, sizeof(line), file)) {<br>
                if (sscanf(line, "%*d %*d %d:%d %*s %s",<br>
@@ -564,7 +580,7 @@ void tst_find_backing_dev(const char *path, char *dev)<br>
<br>
        if (stat(dev, &buf) < 0)<br>
                tst_brkm(TWARN | TERRNO, NULL, "stat(%s) failed", dev);<br>
-<br>
+out:<br>
        if (S_ISBLK(buf.st_mode) != 1)<br>
                tst_brkm(TCONF, NULL, "dev(%s) isn't a block dev", dev);<br>
 }<br>
-- <br>
2.36.1<br>
<br>
</blockquote></div></div></div>