Since libvirt 2.0.0, these two new <listen/> types have been
supported: https://libvirt.org/formatdomain.html#elementsGraphics

This change just copies that configuration over from the source to the
destination if the destination is also libvirt.

Since we previously used 'LNone' to mean "no parseable <listen/>
element" I also had to change previous uses of 'LNone' to 'LNoListen',
so we can use 'LNone' to mean "<listen type='none'>".

Thanks: Ming Xie.
---
 v2v/input_disk.ml       |  2 +-
 v2v/input_libvirtxml.ml | 17 ++++++++++++-----
 v2v/output_libvirt.ml   |  9 ++++++++-
 v2v/types.ml            |  8 ++++++--
 v2v/types.mli           |  4 +++-
 5 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index e07222f..2852ce9 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -84,7 +84,7 @@ class input_disk input_format disk = object
       s_firmware = UnknownFirmware;       (* causes virt-v2v to autodetect *)
       s_display =
         Some { s_display_type = Window; s_keymap = None; s_password = None;
-               s_listen = LNone; s_port = None };
+               s_listen = LNoListen; s_port = None };
       s_video = None;
       s_sound = None;
       s_disks = [disk];
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index 33e878e..d94591f 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -96,24 +96,31 @@ let parse_libvirt_xml ?conn xml =
         let nr_nodes = Xml.xpathobj_nr_nodes obj in
         if nr_nodes < 1 then (
           match xpath_string "@listen" with
-          | None -> LNone | Some a -> LAddress a
+          | None -> LNoListen | Some a -> LAddress a
         ) else (
           (* Use only the first <listen> configuration. *)
           match xpath_string "listen[1]/@type" with
-          | None -> LNone
+          | None -> LNoListen
           | Some "address" ->
             (match xpath_string "listen[1]/@address" with
-            | None -> LNone
+            | None -> LNoListen
             | Some a -> LAddress a
             )
           | Some "network" ->
             (match xpath_string "listen[1]/@network" with
-            | None -> LNone
+            | None -> LNoListen
             | Some n -> LNetwork n
             )
+          | Some "socket" ->
+            (match xpath_string "listen[1]/@socket" with
+            | None -> LNoListen
+            | Some n -> LSocket n
+            )
+          | Some "none" ->
+            LNone
           | Some t ->
             warning (f_"<listen type='%s'> in the input libvirt XML was 
ignored") t;
-            LNone
+            LNoListen
         ) in
       let port =
         match xpath_string "@autoport" with
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index e934335..ac91922 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -281,13 +281,20 @@ let create_libvirt_xml ?pool source target_buses guestcaps
   (match source.s_display with
    | Some { s_listen = listen } ->
       (match listen with
+       | LNoListen -> ()
        | LAddress a ->
           let sub = e "listen" [ "type", "address"; "address", a ] [] in
           append_child sub graphics
        | LNetwork n ->
           let sub = e "listen" [ "type", "network"; "network", n ] [] in
           append_child sub graphics
-       | LNone -> ())
+       | LSocket s ->
+          let sub = e "listen" [ "type", "socket"; "socket", s ] [] in
+          append_child sub graphics
+       | LNone ->
+          let sub = e "listen" [ "type", "none" ] [] in
+          append_child sub graphics
+      )
    | None -> ());
   (match source.s_display with
    | Some { s_port = Some p } ->
diff --git a/v2v/types.ml b/v2v/types.ml
index c43db24..bf4365c 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -82,9 +82,11 @@ and source_display = {
 }
 and s_display_type = Window | VNC | Spice
 and s_display_listen =
-  | LNone
+  | LNoListen
   | LAddress of string
   | LNetwork of string
+  | LSocket of string
+  | LNone
 
 and source_video = Source_other_video of string |
                    Source_Cirrus | Source_QXL
@@ -227,9 +229,11 @@ and string_of_source_display { s_display_type = typ;
     (match keymap with None -> "" | Some km -> " " ^ km)
     (match password with None -> "" | Some _ -> " with password")
     (match listen with
-    | LNone -> ""
+    | LNoListen -> ""
     | LAddress a -> sprintf " listening on address %s" a
     | LNetwork n -> sprintf " listening on network %s" n
+    | LSocket s -> sprintf " listening on Unix domain socket %s" s
+    | LNone -> " listening on private fd"
     )
 
 and string_of_source_video = function
diff --git a/v2v/types.mli b/v2v/types.mli
index 2727383..514565c 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -139,9 +139,11 @@ and source_display = {
 }
 and s_display_type = Window | VNC | Spice
 and s_display_listen =
-  | LNone
+  | LNoListen                      (** No parseable <listen/> element. *)
   | LAddress of string             (** Listen address. *)
   | LNetwork of string             (** Listen network. *)
+  | LSocket of string              (** Listen Unix domain socket. *)
+  | LNone                          (** <listen type='none'> *)
 
 (** Video adapter model. *)
 and source_video = Source_other_video of string |
-- 
2.9.3

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to