Tomáš Golembiovský
2018-Nov-07 11:40 UTC
[Libguestfs] [PATCH v2 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
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: linux: install packages v2v: linux: install QEMU-GA (RHBZ#1619665) v2v/convert_linux.ml | 2 ++ v2v/linux.ml | 14 ++++++++ v2v/linux.mli | 3 ++ v2v/windows_virtio.ml | 78 +++++++++++++++++++++++++++++++++--------- v2v/windows_virtio.mli | 4 +++ 5 files changed, 84 insertions(+), 17 deletions(-) -- 2.19.0
Tomáš Golembiovský
2018-Nov-07 11:40 UTC
[Libguestfs] [PATCH v2 1/3] v2v: refactor copy_drivers() in Windows_virtio
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@redhat.com> --- v2v/windows_virtio.ml | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml index 9b45c76f5..da02b6c4e 100644 --- a/v2v/windows_virtio.ml +++ b/v2v/windows_virtio.ml @@ -254,28 +254,41 @@ and ddb_regedits inspect drv_name drv_pciid * been copied. *) and copy_drivers g inspect driverdir - let ret = ref false in + List.length ( + copy_from_virtio_win g inspect "/" driverdir virtio_iso_path_matches_guest_os + ) > 0 + +(* 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 +296,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.0
Tomáš Golembiovský
2018-Nov-07 11:40 UTC
[Libguestfs] [PATCH v2 2/3] v2v: linux: install packages
Install packages from local files without touching network. Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- v2v/linux.ml | 14 ++++++++++++++ v2v/linux.mli | 3 +++ 2 files changed, 17 insertions(+) diff --git a/v2v/linux.ml b/v2v/linux.ml index 177724e39..966170cdd 100644 --- a/v2v/linux.ml +++ b/v2v/linux.ml @@ -31,6 +31,20 @@ let augeas_reload g g#aug_load (); debug_augeas_errors g +let rec install_local g { i_package_format = package_format } packages + if packages <> [] then ( + match package_format with + | "rpm" -> + let cmd = [ "rpm"; "--upgrade"; "-v" ] @ packages in + let cmd = Array.of_list cmd in + ignore (g#command cmd) + | format -> + error (f_"don’t know how to install packages using %s: packages: %s") + format (String.concat " " packages) + (* Reload Augeas in case anything changed. *) + augeas_reload g + ) + let rec remove g inspect packages if packages <> [] then ( do_remove g inspect packages; diff --git a/v2v/linux.mli b/v2v/linux.mli index 1c604665e..80593cebc 100644 --- a/v2v/linux.mli +++ b/v2v/linux.mli @@ -23,6 +23,9 @@ val augeas_reload : Guestfs.guestfs -> unit additional debugging information about parsing problems that augeas found. *) +val install_local: Guestfs.guestfs -> Types.inspect -> string list -> unit +(** Install pacakge(s). *) + val remove : Guestfs.guestfs -> Types.inspect -> string list -> unit (** Uninstall package(s). *) -- 2.19.0
Tomáš Golembiovský
2018-Nov-07 11:40 UTC
[Libguestfs] [PATCH v2 3/3] v2v: linux: install QEMU-GA (RHBZ#1619665)
Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> --- v2v/convert_linux.ml | 2 ++ v2v/windows_virtio.ml | 30 ++++++++++++++++++++++++++++++ v2v/windows_virtio.mli | 4 ++++ 3 files changed, 36 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 da02b6c4e..223e7661b 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,34 @@ 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 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.0
Maybe Matching Threads
- [PATCH v3 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
- [PATCH v4 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
- [PATCH v5 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
- [PATCH 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
- [PATCH v3] v2v: don't fail when virtio-win does not have qemu-ga