[Libguestfs] [v2v PATCH 8/9] convert/libosinfo_utils: introduce "os_support_of_osinfo_device_list"

Laszlo Ersek lersek at redhat.com
Thu Jan 6 14:09:09 UTC 2022


Add a helper function for calculating q35 support and virtio-1.0 support
from the list of devices returned by the previously introduced
"osinfo_os#get_devices" method.

(Rather than folding the list into a record of bools, implement the
function explicitly, recursively. Folding wouldn't stop (without abusing
exceptions) once all fields in the record turned "true", but a recursive
function can just return the accumulator at that point.)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1942325
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 convert/libosinfo_utils.mli | 14 ++++++++++++++
 convert/libosinfo_utils.ml  | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/convert/libosinfo_utils.mli b/convert/libosinfo_utils.mli
index 5a703334d9f0..ab77ec97df30 100644
--- a/convert/libosinfo_utils.mli
+++ b/convert/libosinfo_utils.mli
@@ -30,3 +30,17 @@ val string_of_osinfo_device_driver : Libosinfo.osinfo_device_driver -> string
 
 val string_of_osinfo_device_list : Libosinfo.osinfo_device list -> string
 (** Convert an [osinfo_device] list to a printable string for debugging. *)
+
+type os_support = {
+  q35 : bool;
+  vio10 : bool;
+}
+(** Tell whether the operating system supports the Q35 board type and/or
+    non-transitional (virtio-1.0-only) virtio devices. (Internally, the
+    virtio-1.0-net device is used as a proxy for the general statement about
+    virtio-1.0.)
+ *)
+
+val os_support_of_osinfo_device_list : Libosinfo.osinfo_device list ->
+                                       os_support
+(** Get [os_support] from an [osinfo_device] list. *)
diff --git a/convert/libosinfo_utils.ml b/convert/libosinfo_utils.ml
index d5eb082b458c..b2ed31ab5c42 100644
--- a/convert/libosinfo_utils.ml
+++ b/convert/libosinfo_utils.ml
@@ -77,3 +77,22 @@ let string_of_osinfo_device_list dev_list =
    *)
   String.concat "\n"
     (List.map (fun dev -> columnate (listify dev) max_widths) dev_list)
+
+type os_support = {
+  q35 : bool;
+  vio10 : bool;
+}
+
+let os_support_of_osinfo_device_list =
+  let rec next accu left =
+    match accu, left with
+    | { q35 = true; vio10 = true }, _
+    | _ , [] ->
+      accu
+    | { q35; vio10 }, { Libosinfo.id } :: tail ->
+      let q35 = q35 || id = "http://qemu.org/chipset/x86/q35"
+      and vio10 = vio10 || id = "http://pcisig.com/pci/1af4/1041"
+      in
+      next { q35; vio10 } tail
+  in
+  next { q35 = false; vio10 = false }
-- 
2.19.1.3.g30247aa5d201




More information about the Libguestfs mailing list