Blame SOURCES/0061-v2v-windows-install-QEMU-Guest-Agent-MSI.patch

da373f
From cf06f1d264a8832aa31265da5b2a28547b0faf49 Mon Sep 17 00:00:00 2001
3efd08
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= <tgolembi@redhat.com>
3efd08
Date: Tue, 8 Oct 2019 13:16:38 +0200
3efd08
Subject: [PATCH] v2v: windows: install QEMU Guest Agent MSI
3efd08
MIME-Version: 1.0
3efd08
Content-Type: text/plain; charset=UTF-8
3efd08
Content-Transfer-Encoding: 8bit
3efd08
3efd08
Use firstboot script to install MSI with QEMU-GA from virtio-win ISO or
3efd08
oVirt/RHV guest tools ISO.
3efd08
3efd08
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
3efd08
(cherry picked from commit 00b4ed312b0ba179e9901b73c099724c3f6606b4)
3efd08
---
3efd08
 v2v/convert_windows.ml | 19 +++++++++++++++++++
3efd08
 v2v/windows_virtio.ml  | 27 +++++++++++++++++++++++++++
3efd08
 v2v/windows_virtio.mli |  4 ++++
3efd08
 3 files changed, 50 insertions(+)
3efd08
3efd08
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
3efd08
index 75e609d61..bdb0092c3 100644
3efd08
--- a/v2v/convert_windows.ml
3efd08
+++ b/v2v/convert_windows.ml
3efd08
@@ -293,6 +293,13 @@ let convert (g : G.guestfs) inspect source output rcaps static_ips =
3efd08
     if Sys.file_exists tool_path then
3efd08
       configure_vmdp tool_path;
3efd08
 
3efd08
+    (* Install QEMU Guest Agent unconditionally and warn if missing *)
3efd08
+    let qemu_ga_files = Windows_virtio.copy_qemu_ga g inspect in
3efd08
+    if qemu_ga_files <> [] then
3efd08
+      configure_qemu_ga qemu_ga_files
3efd08
+    else
3efd08
+      warning (f_"QEMU Guest Agent MSI not found on tools ISO/directory. You may want to install the guest agent manually after conversion.");
3efd08
+
3efd08
     unconfigure_xenpv ();
3efd08
     unconfigure_prltools ();
3efd08
     unconfigure_vmwaretools ()
3efd08
@@ -418,6 +425,18 @@ popd
3efd08
     Firstboot.add_firstboot_script g inspect.i_root
3efd08
       "finish vmdp setup" fb_recover_script
3efd08
 
3efd08
+ and configure_qemu_ga files =
3efd08
+   List.iter (
3efd08
+     fun msi_path ->
3efd08
+       let fb_script = "\
3efd08
+echo Installing qemu-ga from " ^ msi_path ^ "
3efd08
+\"\\" ^ msi_path ^ "\" /qn /forcerestart /l+*vx \"%cd%\\qemu-ga.log\"
3efd08
+" in
3efd08
+      Firstboot.add_firstboot_script g inspect.i_root
3efd08
+        ("install " ^ msi_path) fb_script;
3efd08
+    ) files
3efd08
+
3efd08
+
3efd08
   and unconfigure_xenpv () =
3efd08
     match xenpv_uninst with
3efd08
     | None -> () (* nothing to be uninstalled *)
3efd08
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
3efd08
index 70f0bf09d..ea7e5c02d 100644
3efd08
--- a/v2v/windows_virtio.ml
3efd08
+++ b/v2v/windows_virtio.ml
3efd08
@@ -296,6 +296,13 @@ and copy_drivers g inspect driverdir =
3efd08
     (fun () ->
3efd08
       error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way.  Please report this as a bug with a full debug log."))
3efd08
 
3efd08
+and copy_qemu_ga g inspect =
3efd08
+  copy_from_virtio_win g inspect "/" "/"
3efd08
+    virtio_iso_path_matches_qemu_ga
3efd08
+    (fun () ->
3efd08
+      error (f_"root directory ‘/’ is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way.  Please report this as a bug with a full debug log."))
3efd08
+
3efd08
+
3efd08
 (* Copy all files from virtio_win directory/ISO located in [srcdir]
3efd08
  * subdirectory and all its subdirectories to the [destdir]. The directory
3efd08
  * hierarchy is not preserved, meaning all files will be directly in [destdir].
3efd08
@@ -427,6 +434,26 @@ and virtio_iso_path_matches_guest_os path inspect =
3efd08
 
3efd08
   with Not_found -> false
3efd08
 
3efd08
+(* Given a path of a file relative to the root of the directory tree
3efd08
+ * with virtio-win drivers, figure out if it's suitable for the
3efd08
+ * specific Windows flavor of the current guest.
3efd08
+ *)
3efd08
+and virtio_iso_path_matches_qemu_ga path inspect =
3efd08
+  let { i_arch = arch } = inspect in
3efd08
+  (* Lowercased path, since the ISO may contain upper or lowercase path
3efd08
+   * elements.
3efd08
+   *)
3efd08
+  let lc_name = String.lowercase_ascii (Filename.basename path) in
3efd08
+  lc_name = "rhev-qga.msi" ||
3efd08
+  match arch, lc_name with
3efd08
+  | ("i386", "qemu-ga-x86.msi")
3efd08
+  | ("i386", "qemu-ga-i386.msi")
3efd08
+  | ("i386", "RHEV-QGA.msi")
3efd08
+  | ("x86_64", "qemu-ga-x64.msi")
3efd08
+  | ("x86_64", "qemu-ga-x86_64.msi")
3efd08
+  | ("x86_64", "RHEV-QGA64.msi") -> true
3efd08
+  | _ -> false
3efd08
+
3efd08
 (* The following function is only exported for unit tests. *)
3efd08
 module UNIT_TESTS = struct
3efd08
   let virtio_iso_path_matches_guest_os = virtio_iso_path_matches_guest_os
3efd08
diff --git a/v2v/windows_virtio.mli b/v2v/windows_virtio.mli
3efd08
index ae3b7e865..731dbd6f0 100644
3efd08
--- a/v2v/windows_virtio.mli
3efd08
+++ b/v2v/windows_virtio.mli
3efd08
@@ -44,6 +44,10 @@ val install_linux_tools : Guestfs.guestfs -> Types.inspect -> unit
3efd08
 (** installs QEMU Guest Agent on Linux guest OS from the driver directory or
3efd08
     driver ISO. It is not fatal if we fail to install the agent. *)
3efd08
 
3efd08
+val copy_qemu_ga : Guestfs.guestfs -> Types.inspect -> string list
3efd08
+(** copy MSIs (idealy just one) with QEMU Guest Agent to Windows guest. The
3efd08
+    MSIs are not installed by this function. *)
3efd08
+
3efd08
 (**/**)
3efd08
 
3efd08
 (* The following function is only exported for unit tests. *)
3efd08
-- 
da373f
2.18.4
3efd08