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

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