changes in v5:
- simplified expression in copy_drivers
- new commit fixing path constructions
- indentation fixes
changes in v4:
- fix call to install_local
changes in v2:
- moved copy_drivers above copy_files
- renamed copy_files to copy_from_virtio_win
- renamed install to install_local
- use rpm instead of yum
This installs packages with QEMU Guest Agent when converting Linux machine. The
packages should be available on guest tools ISO. The patches work "as-is" but
probably deserve some more attention:
- it is "abusing" Winows_virtio code but renaming/refactoring everything to
remove "windows" from the name and use "guest tools" seems like a
lot of
unnecesary work
- support for Debian is missing
I don't know how to install the package only when all it's dependencies are
already installed. dpkg cannot be used to check that (simulate the install).
And attempting to install the package will leave it half-installed (dpkg
cannot roll-back).
Tomáš Golembiovský (3):
v2v: refactor copy_drivers() in Windows_virtio
v2v: fix path construction in Windows_virtio.copy_files()
v2v: linux: install QEMU-GA (RHBZ#1619665)
v2v/convert_linux.ml | 2 ++
v2v/windows_virtio.ml | 78 +++++++++++++++++++++++++++++++++---------
v2v/windows_virtio.mli | 4 +++
3 files changed, 67 insertions(+), 17 deletions(-)
--
2.19.1
Show replies by date
Changed the function to be more generic and renamed.
The only change in behavior is in produced debug messages.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/windows_virtio.ml | 46 +++++++++++++++++++++++++++----------------
1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
index 9b45c76f5..eeee0096e 100644
--- a/v2v/windows_virtio.ml
+++ b/v2v/windows_virtio.ml
@@ -254,28 +254,39 @@ and ddb_regedits inspect drv_name drv_pciid =
* been copied.
*)
and copy_drivers g inspect driverdir =
- let ret = ref false in
+ [] <> copy_from_virtio_win g inspect "/" driverdir
virtio_iso_path_matches_guest_os
+
+(* Copy all files from virtio_win directory/ISO located in [srcdir]
+ * subdirectory and all its subdirectories to the [destdir]. The directory
+ * hierarchy is not preserved, meaning all files will be directly in [destdir].
+ * The file list is filtered based on [filter] function.
+ *
+ * Returns list of copied files.
+ *)
+and copy_from_virtio_win g inspect srcdir destdir filter =
+ let ret = ref [] in
if is_directory virtio_win then (
- debug "windows: copy_drivers: source directory virtio_win %s" virtio_win;
+ let dir = virtio_win // srcdir in
+ debug "windows: copy_from_virtio_win: guest tools source directory %s"
dir;
- let cmd = sprintf "cd %s && find -L -type f" (quote virtio_win) in
+ let cmd = sprintf "cd %s && find -L -type f" (quote dir) in
let paths = external_command cmd in
List.iter (
fun path ->
- if virtio_iso_path_matches_guest_os path inspect then (
- let source = virtio_win // path in
- let target = driverdir //
- String.lowercase_ascii (Filename.basename path) in
- debug "copying virtio driver bits: 'host:%s' ->
'%s'"
+ if filter path inspect then (
+ let source = dir // path in
+ let target_name = String.lowercase_ascii (Filename.basename path) in
+ let target = destdir // target_name in
+ debug "windows: copying guest tools bits: 'host:%s' ->
'%s'"
source target;
g#write target (read_whole_file source);
- ret := true
+ List.push_front target_name ret
)
) paths
)
else if is_regular_file virtio_win then (
- debug "windows: copy_drivers: source ISO virtio_win %s" virtio_win;
+ debug "windows: copy_from_virtio_win: guest tools source ISO %s"
virtio_win;
try
let g2 = open_guestfs ~identifier:"virtio_win" () in
@@ -283,19 +294,20 @@ and copy_drivers g inspect driverdir =
g2#launch ();
let vio_root = "/" in
g2#mount_ro "/dev/sda" vio_root;
- let paths = g2#find vio_root in
+ let srcdir = vio_root // srcdir in
+ let paths = g2#find srcdir in
Array.iter (
fun path ->
- let source = vio_root // path in
+ let source = srcdir // path in
if g2#is_file source ~followsymlinks:false &&
- virtio_iso_path_matches_guest_os path inspect then (
- let target = driverdir //
- String.lowercase_ascii (Filename.basename path) in
- debug "copying virtio driver bits: '%s:%s' ->
'%s'"
+ filter path inspect then (
+ let target_name = String.lowercase_ascii (Filename.basename path) in
+ let target = destdir // target_name in
+ debug "windows: copying guest tools bits: '%s:%s' ->
'%s'"
virtio_win path target;
g#write target (g2#read_file source);
- ret := true
+ List.push_front target_name ret
)
) paths;
g2#close()
--
2.19.1
Some paths in the function are evaluated in libguestfs environment.
Previous commit copied the invalid construction. This is now fixed.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/windows_virtio.ml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
index eeee0096e..5d3dbde4d 100644
--- a/v2v/windows_virtio.ml
+++ b/v2v/windows_virtio.ml
@@ -294,15 +294,15 @@ and copy_from_virtio_win g inspect srcdir destdir filter =
g2#launch ();
let vio_root = "/" in
g2#mount_ro "/dev/sda" vio_root;
- let srcdir = vio_root // srcdir in
+ let srcdir = vio_root ^ "/" ^ srcdir in
let paths = g2#find srcdir in
Array.iter (
fun path ->
- let source = srcdir // path in
+ let source = srcdir ^ "/" ^ path in
if g2#is_file source ~followsymlinks:false &&
filter path inspect then (
let target_name = String.lowercase_ascii (Filename.basename path) in
- let target = destdir // target_name in
+ let target = destdir ^ "/" ^ target_name in
debug "windows: copying guest tools bits: '%s:%s' ->
'%s'"
virtio_win path target;
--
2.19.1
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/convert_linux.ml | 2 ++
v2v/windows_virtio.ml | 32 ++++++++++++++++++++++++++++++++
v2v/windows_virtio.mli | 4 ++++
3 files changed, 38 insertions(+)
diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index e8c64ac1b..a1bafe91a 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -81,6 +81,8 @@ let convert (g : G.guestfs) inspect source output rcaps =
let rec do_convert () =
augeas_grub_configuration ();
+ Windows_virtio.install_linux_tools g inspect;
+
unconfigure_xen ();
unconfigure_vbox ();
unconfigure_vmware ();
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
index 5d3dbde4d..0b9bdfff3 100644
--- a/v2v/windows_virtio.ml
+++ b/v2v/windows_virtio.ml
@@ -27,6 +27,8 @@ open Regedit
open Types
open Utils
+module G = Guestfs
+
let virtio_win =
try Sys.getenv "VIRTIO_WIN"
with Not_found ->
@@ -181,6 +183,36 @@ let rec install_drivers ((g, _) as reg) inspect rcaps =
virtio_rng_supported, virtio_ballon_supported, isa_pvpanic_supported)
)
+and install_linux_tools g inspect =
+ let os =
+ match inspect.i_distro with
+ | "fedora" -> Some "fc28"
+ | "rhel" | "centos" | "scientificlinux" |
"redhat-based"
+ | "oraclelinux" ->
+ (match inspect.i_major_version with
+ | 6 -> Some "el6"
+ | 7 -> Some "el7"
+ | _ -> None)
+ | "sles" | "suse-based" | "opensuse" -> Some
"lp151"
+ | _ -> None in
+
+ match os with
+ | None ->
+ warning (f_"don't know how to install guest tools on %s-%d")
+ inspect.i_distro inspect.i_major_version
+ | Some os ->
+ let src_path = "linux" // os in
+ let dst_path = "/var/tmp" in
+ debug "locating packages in %s" src_path;
+ let packages = copy_from_virtio_win g inspect src_path dst_path
+ (fun _ _ -> true) in
+ debug "done copying %d files" (List.length packages);
+ let packages = List.map ((//) dst_path) packages in
+ try
+ Linux.install_local g inspect packages;
+ with G.Error msg ->
+ warning (f_"failed to install QEMU Guest Agent: %s") msg
+
and add_guestor_to_registry ((g, root) as reg) inspect drv_name drv_pciid =
let ddb_node = g#hivex_node_get_child root "DriverDatabase" in
diff --git a/v2v/windows_virtio.mli b/v2v/windows_virtio.mli
index 91b3ced45..fa9997829 100644
--- a/v2v/windows_virtio.mli
+++ b/v2v/windows_virtio.mli
@@ -40,6 +40,10 @@ val install_drivers
virtio devices if we managed to install those, or legacy devices
if we didn't. *)
+val install_linux_tools : Guestfs.guestfs -> Types.inspect -> unit
+(** installs QEMU Guest Agent on Linux guest OS from the driver directory or
+ driver ISO. It is not fatal if we fail to install the agent. *)
+
(**/**)
(* The following function is only exported for unit tests. *)
--
2.19.1