[Libguestfs] [PATCH 19/27] daemon: Reimplement ‘list_filesystems’ API in the daemon, in OCaml.

Pino Toscano ptoscano at redhat.com
Thu Jul 20 15:13:34 UTC 2017


On Friday, 14 July 2017 15:39:27 CEST Richard W.M. Jones wrote:
> +let rec list_filesystems () =
> +  let has_lvm2 = Lvm.available () in
> +  let has_ldm = Ldm.available () in
> +
> +  let devices = Devsparts.list_devices () in
> +  let partitions = Devsparts.list_partitions () in
> +  let mds = Md.list_md_devices () in
> +
> +  (* Look to see if any devices directly contain filesystems
> +   * (RHBZ#590167).  However vfs-type will fail to tell us anything
> +   * useful about devices which just contain partitions, so we also
> +   * get the list of partitions and exclude the corresponding devices
> +   * by using part-to-dev.
> +   *)
> +  let devices = List.fold_left (
> +    fun devices part ->
> +      let d = Devsparts.part_to_dev part in
> +      List.filter ((<>) d) devices
> +  ) devices partitions in

Hm it took me a couple of reading to get it -- what would you think
about the following (untested):

  module StringSet = Set.Make (String)
  ...
  let devices_of_partitions = List.fold_left (
    fun set part ->
      StringSet.add part set
  ) partitions StringSet.empty in
  (* Remove  *)
  let devices = List.filter (
    fun dev ->
      not (StringSet.mem dev devices_of_partitions)
  ) devices in
  let devices = devices @ partitions in

> +  (* Use vfs-type to check for filesystems on devices. *)
> +  let ret = filter_map check_with_vfs_type devices in
> +
> +  (* Use vfs-type to check for filesystems on partitions, but
> +   * ignore MBR partition type 42 used by LDM.
> +   *)
> +  let ret =
> +    ret @
> +      filter_map (
> +        fun part ->
> +          if not has_ldm || not (is_mbr_partition_type_42 part) then
> +            check_with_vfs_type part
> +          else
> +            None                (* ignore type 42 *)
> +      ) partitions in

Now this will run is_mbr_partition_type_42 on devices as well, in case
ldm is available -- I guess it should not be an issue?

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170720/8c1d3134/attachment.sig>


More information about the Libguestfs mailing list