Blame SOURCES/0134-v2v-convert-libvirt-display-port-configuration.patch

ffd6ed
From bbafb02ae131fbe920886e7685ccd2b156af87e9 Mon Sep 17 00:00:00 2001
ffd6ed
From: Pino Toscano <ptoscano@redhat.com>
ffd6ed
Date: Tue, 14 Apr 2015 13:22:10 +0200
ffd6ed
Subject: [PATCH] v2v: convert libvirt display port configuration
ffd6ed
ffd6ed
Read the port configuration from the XML of libvirt domains, restoring
ffd6ed
it when writing new libvirt XMLs instead of always setting the
ffd6ed
"autoport" option.
ffd6ed
ffd6ed
(cherry picked from commit 1db249a0cc21c65e0d3192567b6016745cea7e58)
ffd6ed
---
ffd6ed
 v2v/input_disk.ml       |  2 +-
ffd6ed
 v2v/input_libvirtxml.ml | 13 +++++++++++--
ffd6ed
 v2v/output_libvirt.ml   |  8 +++++++-
ffd6ed
 v2v/output_qemu.ml      |  3 ++-
ffd6ed
 v2v/types.ml            |  1 +
ffd6ed
 v2v/types.mli           |  1 +
ffd6ed
 6 files changed, 23 insertions(+), 5 deletions(-)
ffd6ed
ffd6ed
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
ffd6ed
index e5a07b4..54e0bbe 100644
ffd6ed
--- a/v2v/input_disk.ml
ffd6ed
+++ b/v2v/input_disk.ml
ffd6ed
@@ -87,7 +87,7 @@ class input_disk verbose input_format disk = object
ffd6ed
       s_features = [ "acpi"; "apic"; "pae" ];
ffd6ed
       s_display =
ffd6ed
         Some { s_display_type = Window; s_keymap = None; s_password = None;
ffd6ed
-               s_listen = LNone };
ffd6ed
+               s_listen = LNone; s_port = None };
ffd6ed
       s_disks = [disk];
ffd6ed
       s_removables = [];
ffd6ed
       s_nics = [network];
ffd6ed
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
ffd6ed
index 037405c..34f1bd1 100644
ffd6ed
--- a/v2v/input_libvirtxml.ml
ffd6ed
+++ b/v2v/input_libvirtxml.ml
ffd6ed
@@ -115,14 +115,23 @@ let parse_libvirt_xml ~verbose xml =
ffd6ed
             warning ~prog (f_"<listen type='%s'> in the input libvirt XML was ignored") t;
ffd6ed
             LNone
ffd6ed
         ) in
ffd6ed
+      let port =
ffd6ed
+        match xpath_to_string "@autoport" "yes" with
ffd6ed
+        | "no" ->
ffd6ed
+          let port = xpath_to_int "@port" (-1) in
ffd6ed
+          if port >= 0 then Some port
ffd6ed
+          else None
ffd6ed
+        | _ -> None in
ffd6ed
       match xpath_to_string "@type" "" with
ffd6ed
       | "" -> None
ffd6ed
       | "vnc" ->
ffd6ed
         Some { s_display_type = VNC;
ffd6ed
-               s_keymap = keymap; s_password = password; s_listen = listen }
ffd6ed
+               s_keymap = keymap; s_password = password; s_listen = listen;
ffd6ed
+               s_port = port }
ffd6ed
       | "spice" ->
ffd6ed
         Some { s_display_type = Spice;
ffd6ed
-               s_keymap = keymap; s_password = password; s_listen = listen }
ffd6ed
+               s_keymap = keymap; s_password = password; s_listen = listen;
ffd6ed
+               s_port = port }
ffd6ed
       | "sdl"|"desktop" as t ->
ffd6ed
         warning ~prog (f_"virt-v2v does not support local displays, so <graphics type='%s'> in the input libvirt XML was ignored") t;
ffd6ed
         None
ffd6ed
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
ffd6ed
index 118d4a4..dee432d 100644
ffd6ed
--- a/v2v/output_libvirt.ml
ffd6ed
+++ b/v2v/output_libvirt.ml
ffd6ed
@@ -230,7 +230,6 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
ffd6ed
 
ffd6ed
     append_attr ("heads", "1") video;
ffd6ed
 
ffd6ed
-    append_attr ("autoport", "yes") graphics;
ffd6ed
     (match source.s_display with
ffd6ed
     | Some { s_keymap = Some km } -> append_attr ("keymap", km) graphics
ffd6ed
     | _ -> ());
ffd6ed
@@ -248,6 +247,13 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
ffd6ed
         append_child sub graphics
ffd6ed
       | LNone -> ())
ffd6ed
     | _ -> ());
ffd6ed
+    (match source.s_display with
ffd6ed
+    | Some { s_port = Some p } ->
ffd6ed
+      append_attr ("autoport", "no") graphics;
ffd6ed
+      append_attr ("port", string_of_int p) graphics
ffd6ed
+    | _ ->
ffd6ed
+      append_attr ("autoport", "yes") graphics;
ffd6ed
+      append_attr ("port", "-1") graphics);
ffd6ed
 
ffd6ed
     video, graphics in
ffd6ed
 
ffd6ed
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
ffd6ed
index 4b1d69a..860e1bf 100644
ffd6ed
--- a/v2v/output_qemu.ml
ffd6ed
+++ b/v2v/output_qemu.ml
ffd6ed
@@ -95,7 +95,8 @@ object
ffd6ed
       | VNC ->
ffd6ed
         fpf "%s-display vnc=:0" nl
ffd6ed
       | Spice ->
ffd6ed
-        fpf "%s-spice port=5900,addr=127.0.0.1" nl
ffd6ed
+        fpf "%s-spice port=%d,addr=127.0.0.1" nl
ffd6ed
+        (match display.s_port with None -> 5900 | Some p -> p)
ffd6ed
       );
ffd6ed
       fpf "%s-vga %s" nl
ffd6ed
         (match guestcaps.gcaps_video with Cirrus -> "cirrus" | QXL -> "qxl")
ffd6ed
diff --git a/v2v/types.ml b/v2v/types.ml
ffd6ed
index e8ee288..bbe679a 100644
ffd6ed
--- a/v2v/types.ml
ffd6ed
+++ b/v2v/types.ml
ffd6ed
@@ -56,6 +56,7 @@ and source_display = {
ffd6ed
   s_keymap : string option;
ffd6ed
   s_password : string option;
ffd6ed
   s_listen : s_display_listen;
ffd6ed
+  s_port : int option;
ffd6ed
 }
ffd6ed
 and s_display_type = Window | VNC | Spice
ffd6ed
 and s_display_listen =
ffd6ed
diff --git a/v2v/types.mli b/v2v/types.mli
ffd6ed
index e1aa6f9..5925c97 100644
ffd6ed
--- a/v2v/types.mli
ffd6ed
+++ b/v2v/types.mli
ffd6ed
@@ -72,6 +72,7 @@ and source_display = {
ffd6ed
   s_password : string option;      (** If required, password to access
ffd6ed
                                        the display. *)
ffd6ed
   s_listen : s_display_listen;     (** Listen address. *)
ffd6ed
+  s_port : int option;             (** Display port. *)
ffd6ed
 }
ffd6ed
 and s_display_type = Window | VNC | Spice
ffd6ed
 and s_display_listen =
ffd6ed
-- 
ffd6ed
1.8.3.1
ffd6ed