[Libguestfs] [PATCH v2 2/4] v2v: introduce requested guestcaps type

Roman Kagan rkagan at virtuozzo.com
Sat Feb 20 08:26:08 UTC 2016


Introduce a type to contain the guestcaps that are to be put in effect
in the converted VM: options of the block type, net type, and video.

It'll be populated by the caller and passed into convert function to
affect its choice of devices and drivers.

Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 v2v/types.ml  | 47 +++++++++++++++++++++++++++++++++++++----------
 v2v/types.mli |  8 ++++++++
 2 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/v2v/types.ml b/v2v/types.ml
index a082c37..821b7ec 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -361,10 +361,29 @@ type guestcaps = {
   gcaps_arch : string;
   gcaps_acpi : bool;
 }
+and requested_guestcaps = {
+  rcaps_block_bus : guestcaps_block_type option;
+  rcaps_net_bus : guestcaps_net_type option;
+  rcaps_video : guestcaps_video_type option;
+}
 and guestcaps_block_type = Virtio_blk | IDE
 and guestcaps_net_type = Virtio_net | E1000 | RTL8139
 and guestcaps_video_type = QXL | Cirrus
 
+let string_of_block_type block_type =
+  (match block_type with
+   | Virtio_blk -> "virtio-blk"
+   | IDE -> "ide")
+let string_of_net_type net_type =
+  (match net_type with
+   | Virtio_net -> "virtio-net"
+   | E1000 -> "e1000"
+   | RTL8139 -> "rtl8139")
+let string_of_video video =
+  (match video with
+   | QXL -> "qxl"
+   | Cirrus -> "cirrus")
+
 let string_of_guestcaps gcaps =
   sprintf "\
 gcaps_block_bus = %s
@@ -372,19 +391,27 @@ gcaps_net_bus = %s
 gcaps_video = %s
 gcaps_arch = %s
 gcaps_acpi = %b
-" (match gcaps.gcaps_block_bus with
-   | Virtio_blk -> "virtio"
-   | IDE -> "ide")
-  (match gcaps.gcaps_net_bus with
-   | Virtio_net -> "virtio-net"
-   | E1000 -> "e1000"
-   | RTL8139 -> "rtl8139")
-  (match gcaps.gcaps_video with
-   | QXL -> "qxl"
-   | Cirrus -> "cirrus")
+" (string_of_block_type gcaps.gcaps_block_bus)
+  (string_of_net_type gcaps.gcaps_net_bus)
+  (string_of_video gcaps.gcaps_video)
   gcaps.gcaps_arch
   gcaps.gcaps_acpi
 
+let string_of_requested_guestcaps rcaps =
+  sprintf "\
+rcaps_block_bus = %s
+rcaps_net_bus = %s
+rcaps_video = %s
+" (match rcaps.rcaps_block_bus with
+   | None -> "unspecified"
+   | Some block_type -> (string_of_block_type block_type))
+  (match rcaps.rcaps_net_bus with
+   | None -> "unspecified"
+   | Some net_type -> (string_of_net_type net_type))
+  (match rcaps.rcaps_video with
+   | None -> "unspecified"
+   | Some video -> (string_of_video video))
+
 type target_buses = {
   target_virtio_blk_bus : target_bus_slot array;
   target_ide_bus : target_bus_slot array;
diff --git a/v2v/types.mli b/v2v/types.mli
index f58028f..0e40668 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -207,6 +207,13 @@ type guestcaps = {
   gcaps_arch : string;      (** Architecture that KVM must emulate. *)
   gcaps_acpi : bool;        (** True if guest supports acpi. *)
 }
+and requested_guestcaps = {
+  rcaps_block_bus : guestcaps_block_type option;
+  rcaps_net_bus : guestcaps_net_type option;
+  rcaps_video : guestcaps_video_type option;
+  (** Requested guest capabilities, to allow the caller to affect converter
+      choices *)
+}
 (** Guest capabilities after conversion.  eg. Was virtio found or installed? *)
 
 and guestcaps_block_type = Virtio_blk | IDE
@@ -214,6 +221,7 @@ and guestcaps_net_type = Virtio_net | E1000 | RTL8139
 and guestcaps_video_type = QXL | Cirrus
 
 val string_of_guestcaps : guestcaps -> string
+val string_of_requested_guestcaps : requested_guestcaps -> string
 
 type target_buses = {
   target_virtio_blk_bus : target_bus_slot array;
-- 
2.5.0




More information about the Libguestfs mailing list