[Libguestfs] [PATCH v2 6/7] daemon: Search device-mapper devices for list-filesystems API.

Richard W.M. Jones rjones at redhat.com
Mon Sep 7 09:43:59 UTC 2020


In case any bare filesystems were decrypted using cryptsetup-open,
they would appear as /dev/mapper/name devices.  Since list-filesystems
did not consider those when searching for filesystems, the unencrypted
filesystems would not be returned.

Note that previously this worked for LUKS because the common case
(eg. for Fedora) was that whole devices were encrypted and thoes
devices contained LVs, so luks-open + vgactivate would activate the
LVs which would then be found by list-filesystems.  For Windows
BitLocker, the common case seems to be that each separate NTFS
filesystem is contained in a separate BitLocker wrapper.
---
 daemon/listfs.ml | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/daemon/listfs.ml b/daemon/listfs.ml
index a4c917d12..d8add5005 100644
--- a/daemon/listfs.ml
+++ b/daemon/listfs.ml
@@ -35,6 +35,14 @@ let rec list_filesystems () =
   let devices = List.filter is_not_partitioned_device devices in
   List.iter (check_with_vfs_type ret) devices;
 
+  (* Device-mapper devices.
+   * We include these in case any encrypted devices contain
+   * direct filesystems.
+   *)
+  let devices = Lvm_dm.list_dm_devices () in
+  let devices = List.filter is_not_partitioned_device devices in
+  List.iter (check_with_vfs_type ret) devices;
+
   (* Partitions. *)
   let partitions = Devsparts.list_partitions () in
   let partitions = List.filter is_partition_can_hold_filesystem partitions in
@@ -64,6 +72,11 @@ let rec list_filesystems () =
  * such devices.
  *)
 and is_not_partitioned_device device =
+  let device =
+    if String.is_prefix device "/dev/mapper/" then
+      Unix_utils.Realpath.realpath device
+    else
+      device in
   assert (String.is_prefix device "/dev/");
   let dev_name = String.sub device 5 (String.length device - 5) in
   let dev_dir = "/sys/block/" ^ dev_name in
-- 
2.27.0




More information about the Libguestfs mailing list