Tomáš Golembiovský
2018-Nov-13 12:41 UTC
[Libguestfs] [PATCH v4 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
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: 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.1
Tomáš Golembiovský
2018-Nov-13 12:41 UTC
[Libguestfs] [PATCH v4 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.1
Tomáš Golembiovský
2018-Nov-13 12:41 UTC
[Libguestfs] [PATCH v4 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.1
Tomáš Golembiovský
2018-Nov-13 12:41 UTC
[Libguestfs] [PATCH v4 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..73717ead7 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_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
Tomáš Golembiovský
2018-Nov-13 14:01 UTC
Re: [Libguestfs] [PATCH v4 0/3] Install QEMU-GA from oVirt guest tools ISO on Linux
On Tue, 13 Nov 2018 13:41:39 +0100 Tomáš Golembiovský <tgolembi@redhat.com> wrote:> changes in v4: > - fix call to install_localv3 was same as v2 because I forgot to commit the changes. The difference between v2 and v4 is just one line in the Linux.install_local call. Tomas> > 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.1 >-- Tomáš Golembiovský <tgolembi@redhat.com>
Richard W.M. Jones
2018-Nov-13 17:34 UTC
Re: [Libguestfs] [PATCH v4 1/3] v2v: refactor copy_drivers() in Windows_virtio
On Tue, Nov 13, 2018 at 01:41:40PM +0100, Tomáš Golembiovský wrote:> + List.length ( > + copy_from_virtio_win g inspect "/" driverdir virtio_iso_path_matches_guest_os > + ) > 0Any reason not to change this to copy_from_virtio_win ... <> [] as described in the previous comment on this patch? More comments here: https://www.redhat.com/archives/libguestfs/2018-November/msg00081.html Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2018-Nov-13 17:36 UTC
Re: [Libguestfs] [PATCH v4 2/3] v2v: linux: install packages
On Tue, Nov 13, 2018 at 01:41:41PM +0100, Tomáš Golembiovský wrote:> Install packages from local files without touching network. > > Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>I pushed this one, thanks. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Richard W.M. Jones
2018-Nov-13 17:42 UTC
Re: [Libguestfs] [PATCH v4 3/3] v2v: linux: install QEMU-GA (RHBZ#1619665)
On Tue, Nov 13, 2018 at 01:41:42PM +0100, Tomáš Golembiovský wrote:> +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 inMy preferred indentation for this would be: 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 as I think it's a little bit clearer. The patch however is fine apart from this whitespace. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Richard W.M. Jones
2018-Nov-30 11:05 UTC
[Libguestfs] Test failure (was: Re: [PATCH v4 1/3] v2v: refactor copy_drivers() in Windows_virtio)
This commit (I think) causes a strange bug in the tests: FAIL: test-v2v-conversion-of-centos-6.sh ======================================= test-v2v-conversion-of.sh: info: you can skip this test by setting SKIP_TEST_V2V_CONVERSION_OF_CENTOS_6_SH=1 ... virt-v2v: error: /usr/share/virtio-win/virtio-win.iso: cannot open virtio-win ISO file: find0: //linux/el6: No such file or directory (see full logs attached) Could you see if there's a problem with this patch? This prevents me from releasing libguestfs 1.40 so it is quite important. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW