lib/sysfs: add VFS parameter to sysfs_devno_is_dm_*()

Add const struct ul_vfs_ops *vfs parameter to sysfs_devno_is_dm_hidden()
and sysfs_devno_is_dm_private() so the internal sysfs reads go through
VFS dispatch.

Wire pr->vfs in libblkid probe.c and topology/sysfs.c callers.
Non-library callers pass NULL.

Addresses: https://github.com/util-linux/util-linux/issues/4308
Signed-off-by: Karel Zak <kzak@redhat.com>
diff --git a/disk-utils/fdisk-list.c b/disk-utils/fdisk-list.c
index 76c1ac6..e92eba8 100644
--- a/disk-utils/fdisk-list.c
+++ b/disk-utils/fdisk-list.c
@@ -416,7 +416,7 @@
 		if (devno <= 0)
 			continue;
 
-		if (sysfs_devno_is_dm_private(devno, NULL) ||
+		if (sysfs_devno_is_dm_private(devno, NULL, NULL) ||
 		    sysfs_devno_is_wholedisk(devno) <= 0)
 			continue;
 
diff --git a/include/sysfs.h b/include/sysfs.h
index 37f3b71..0cf8339 100644
--- a/include/sysfs.h
+++ b/include/sysfs.h
@@ -93,10 +93,14 @@
                                 size_t len,
                                 dev_t *diskdevno);
 
+struct ul_vfs_ops;
+
 int sysfs_devno_to_wholedisk(dev_t dev, char *diskname,
                              size_t len, dev_t *diskdevno);
-int sysfs_devno_is_dm_hidden(dev_t devno, char **uuid);
-int sysfs_devno_is_dm_private(dev_t devno, char **uuid);
+int sysfs_devno_is_dm_hidden(dev_t devno, char **uuid,
+                             const struct ul_vfs_ops *vfs);
+int sysfs_devno_is_dm_private(dev_t devno, char **uuid,
+                              const struct ul_vfs_ops *vfs);
 int sysfs_devno_is_wholedisk(dev_t devno);
 
 dev_t sysfs_devname_to_devno(const char *name);
diff --git a/lib/sysfs.c b/lib/sysfs.c
index ad8a88e..99c486d 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -664,7 +664,8 @@
  *
  * The @uuid (if not NULL) returns DM device UUID, use free() to deallocate.
  */
-int sysfs_devno_is_dm_hidden(dev_t devno, char **uuid)
+int sysfs_devno_is_dm_hidden(dev_t devno, char **uuid,
+			     const struct ul_vfs_ops *vfs)
 {
 	struct path_cxt *pc = NULL;
 	char *id = NULL;
@@ -673,6 +674,7 @@
 	pc = ul_new_sysfs_path(devno, NULL, NULL);
 	if (!pc)
 		goto done;
+	ul_path_refer_vfs(pc, vfs);
 	if (ul_path_read_string(pc, &id, "dm/uuid") <= 0 || !id)
 		goto done;
 
@@ -698,7 +700,8 @@
  * Returns 1 if the device is private device mapper device. The @uuid
  * (if not NULL) returns DM device UUID, use free() to deallocate.
  */
-int sysfs_devno_is_dm_private(dev_t devno, char **uuid)
+int sysfs_devno_is_dm_private(dev_t devno, char **uuid,
+			      const struct ul_vfs_ops *vfs)
 {
 	struct path_cxt *pc = NULL;
 	char *id = NULL;
@@ -707,6 +710,7 @@
 	pc = ul_new_sysfs_path(devno, NULL, NULL);
 	if (!pc)
 		goto done;
+	ul_path_refer_vfs(pc, vfs);
 	if (ul_path_read_string(pc, &id, "dm/uuid") <= 0 || !id)
 		goto done;
 
diff --git a/libblkid/src/blkid.h.in b/libblkid/src/blkid.h.in
index 1f39eef..c1bf350 100644
--- a/libblkid/src/blkid.h.in
+++ b/libblkid/src/blkid.h.in
@@ -22,6 +22,7 @@
 #ifndef _BLKID_BLKID_H
 #define _BLKID_BLKID_H
 
+#include <stdio.h>
 #include <stdint.h>
 #include <sys/types.h>
 
diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
index 7f4c279..36d70eb 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -232,7 +232,7 @@
 	struct stat sb;
 
 	if (stat(filename, &sb) == 0 && S_ISBLK(sb.st_mode) &&
-	    sysfs_devno_is_dm_hidden(sb.st_rdev, NULL)) {
+	    sysfs_devno_is_dm_hidden(sb.st_rdev, NULL, pr->vfs)) {
 		DBG(LOWPROBE, ul_debug("ignore hidden device mapper device"));
 		errno = EINVAL;
 		return -EINVAL;
@@ -1213,7 +1213,7 @@
 #endif
 	if (S_ISBLK(sb.st_mode) &&
 	    !is_floppy &&
-	    sysfs_devno_is_dm_private(sb.st_rdev, &dm_uuid)) {
+	    sysfs_devno_is_dm_private(sb.st_rdev, &dm_uuid, pr->vfs)) {
 		DBG(LOWPROBE, ul_debug("ignore private device mapper device"));
 		pr->flags |= BLKID_FL_NOSCAN_DEV;
 	}
diff --git a/libblkid/src/topology/sysfs.c b/libblkid/src/topology/sysfs.c
index d216cfc..c968945 100644
--- a/libblkid/src/topology/sysfs.c
+++ b/libblkid/src/topology/sysfs.c
@@ -56,6 +56,7 @@
 	pc = ul_new_sysfs_path(dev, NULL, NULL);
 	if (!pc)
 		return 1;
+	ul_path_refer_vfs(pc, pr->vfs);
 
 	rc = 1;		/* nothing (default) */
 
diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c
index 7ca267d..b59af77 100644
--- a/libblkid/src/verify.c
+++ b/libblkid/src/verify.c
@@ -105,7 +105,7 @@
 		   (long long)diff));
 #endif
 
-	if (sysfs_devno_is_dm_private(st.st_rdev, NULL))
+	if (sysfs_devno_is_dm_private(st.st_rdev, NULL, NULL))
 		goto dev_free;
 	if (!cache->probe) {
 		cache->probe = blkid_new_probe();