Skip to content

Commit

Permalink
v2v: Keep more inspection data in the inspect struct.
Browse files Browse the repository at this point in the history
Just code motion, no functional change.
  • Loading branch information
rwmjones committed Aug 5, 2014
1 parent 34cb73f commit 9ae2600
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 47 deletions.
41 changes: 14 additions & 27 deletions v2v/convert_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ let string_of_kernel_info ki =

(* The conversion function. *)
let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
({ i_root = root; i_apps = apps; i_apps_map = apps_map }
as inspect) source =
inspect source =
(*----------------------------------------------------------------------*)
(* Inspect the guest first. We already did some basic inspection in
* the common v2v.ml code, but that has to deal with generic guests
Expand All @@ -71,27 +70,15 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
Lib_linux.augeas_init verbose g;

(* Basic inspection data available as local variables. *)
let typ = g#inspect_get_type root in
assert (typ = "linux");
assert (inspect.i_type = "linux");

let distro = g#inspect_get_distro root in
let family =
match distro with
match inspect.i_distro with
| "rhel" | "centos" | "scientificlinux" | "redhat-based" -> `RHEL_family
| "sles" | "suse-based" | "opensuse" -> `SUSE_family
| _ -> assert false in

(*
let arch = g#inspect_get_arch root in
*)
let major_version = g#inspect_get_major_version root
(*
and minor_version = g#inspect_get_minor_version root
*)
and package_format = g#inspect_get_package_format root
and package_management = g#inspect_get_package_management root in

assert (package_format = "rpm");
assert (inspect.i_package_format = "rpm");

(* What grub is installed? *)
let grub_config, grub =
Expand All @@ -112,7 +99,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
match grub with
| `Grub2 -> ""
| `Grub1 ->
let mounts = g#inspect_get_mountpoints root in
let mounts = g#inspect_get_mountpoints inspect.i_root in
try
List.find (
fun path -> List.mem_assoc path mounts
Expand Down Expand Up @@ -250,7 +237,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
)

| _ -> None
) apps in
) inspect.i_apps in

if verbose then (
printf "installed kernel packages in this guest:\n";
Expand Down Expand Up @@ -397,7 +384,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)

and clean_rpmdb () =
(* Clean RPM database. *)
assert (package_format = "rpm");
assert (inspect.i_package_format = "rpm");
let dbfiles = g#glob_expand "/var/lib/rpm/__db.00?" in
let dbfiles = Array.to_list dbfiles in
List.iter g#rm_f dbfiles
Expand All @@ -418,7 +405,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
Some name
else
None
) apps in
) inspect.i_apps in
Lib_linux.remove verbose g inspect xenmods;

(* Undo related nastiness if kmod-xenpv was installed. *)
Expand Down Expand Up @@ -490,7 +477,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
let has_guest_additions =
List.exists (
fun { G.app2_name = name } -> name = package_name
) apps in
) inspect.i_apps in
if has_guest_additions then
Lib_linux.remove verbose g inspect [package_name];

Expand Down Expand Up @@ -552,7 +539,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
libraries := name :: !libraries
else if string_prefix name "vmware-tools-" then
remove := name :: !remove
) apps;
) inspect.i_apps;
let libraries = !libraries in

(* VMware tools includes 'libraries' packages which provide custom
Expand All @@ -563,7 +550,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
*)
if libraries <> [] then (
(* We only support removal of libraries on systems which use yum. *)
if package_management = "yum" then (
if inspect.i_package_management = "yum" then (
List.iter (
fun library ->
let provides =
Expand Down Expand Up @@ -620,7 +607,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
let pkgs =
List.filter (
fun { G.app2_name = name } -> string_prefix name "xe-guest-utilities"
) apps in
) inspect.i_apps in
let pkgs = List.map (fun { G.app2_name = name } -> name) pkgs in

if pkgs <> [] then (
Expand Down Expand Up @@ -844,7 +831,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
* only to a particular version of mkinitrd.
*)
let env =
if family = `RHEL_family && major_version = 4 then
if family = `RHEL_family && inspect.i_major_version = 4 then
Some "root_lvm=1"
else
None in
Expand Down Expand Up @@ -1016,7 +1003,7 @@ let rec convert ?(keep_serial_console = true) verbose (g : G.guestfs)
* added to the target in the order they appear in the libvirt XML.
*)
let block_prefix =
match family, major_version with
match family, inspect.i_major_version with
| `RHEL_family, v when v < 5 ->
(* RHEL < 5 used old ide driver *) "hd"
| `RHEL_family, 5 ->
Expand Down
16 changes: 8 additions & 8 deletions v2v/convert_windows.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ let convert verbose (g : G.guestfs) inspect source =
rhev_apt_exe msg;
None in

let systemroot = g#inspect_get_windows_systemroot inspect.i_root
and major_version = g#inspect_get_major_version inspect.i_root
and minor_version = g#inspect_get_minor_version inspect.i_root
and arch = g#inspect_get_arch inspect.i_root in
let systemroot = g#inspect_get_windows_systemroot inspect.i_root in

(* This is a wrapper that handles opening and closing the hive
* properly around a function [f]. If [~write] is [true] then the
Expand Down Expand Up @@ -223,7 +220,7 @@ echo uninstalling Xen PV driver

(* See if the drivers for this guest are available in virtio_win_dir. *)
let path =
match major_version, minor_version, arch with
match inspect.i_major_version, inspect.i_minor_version, inspect.i_arch with
| 5, 1, "i386" ->
Some (virtio_win_dir // "drivers/i386/WinXP")
| 5, 2, "i386" ->
Expand Down Expand Up @@ -254,7 +251,8 @@ echo uninstalling Xen PV driver
match path with
| None ->
warning ~prog (f_"there are no virtio drivers available for this version of Windows (%d.%d %s). virt-v2v looks for drivers in %s\n\nThe guest will be configured to use slower emulated devices.")
major_version minor_version arch virtio_win_dir;
inspect.i_major_version inspect.i_minor_version
inspect.i_arch virtio_win_dir;
( "ide", "rtl8139" )

| Some path ->
Expand All @@ -263,7 +261,8 @@ echo uninstalling Xen PV driver
let block_path = path // "viostor.sys" in
if not (Sys.file_exists block_path) then (
warning ~prog (f_"there is no viostor (virtio block device) driver for this version of Windows (%d.%d %s). virt-v2v looks for this driver here: %s\n\nThe guest will be configured to use a slower emulated device.")
major_version minor_version arch block_path;
inspect.i_major_version inspect.i_minor_version
inspect.i_arch block_path;
"ide"
)
else (
Expand All @@ -279,7 +278,8 @@ echo uninstalling Xen PV driver
let net_path = path // "netkvm.inf" in
if not (Sys.file_exists net_path) then (
warning ~prog (f_"there is no virtio network driver for this version of Windows (%d.%d %s). virt-v2v looks for this driver here: %s\n\nThe guest will be configured to use a slower emulated device.")
major_version minor_version arch net_path;
inspect.i_major_version inspect.i_minor_version
inspect.i_arch net_path;
"rtl8139"
)
else
Expand Down
7 changes: 3 additions & 4 deletions v2v/lib_linux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ let install verbose g inspect packages =

let remove verbose g inspect packages =
if packages <> [] then (
let root = inspect.i_root in
let package_format = g#inspect_get_package_format root in
let package_format = inspect.i_package_format in
match package_format with
| "rpm" ->
let cmd = [ "rpm"; "-e" ] @ packages in
Expand All @@ -117,7 +116,7 @@ let remove verbose g inspect packages =
)

let file_list_of_package verbose (g : Guestfs.guestfs) inspect name =
let package_format = g#inspect_get_package_format inspect.i_root in
let package_format = inspect.i_package_format in

match package_format with
| "rpm" ->
Expand All @@ -131,7 +130,7 @@ let file_list_of_package verbose (g : Guestfs.guestfs) inspect name =
format

let rec file_owner verbose g inspect path =
let package_format = g#inspect_get_package_format inspect.i_root in
let package_format = inspect.i_package_format in
match package_format with
| "rpm" ->
(* Although it is possible in RPM for multiple packages to own
Expand Down
9 changes: 9 additions & 0 deletions v2v/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ ov_source_format = %s

type inspect = {
i_root : string;
i_type : string;
i_distro : string;
i_arch : string;
i_major_version : int;
i_minor_version : int;
i_package_format : string;
i_package_management : string;
i_product_name : string;
i_product_variant : string;
i_apps : Guestfs.application2 list;
i_apps_map : Guestfs.application2 list StringMap.t;
}
Expand Down
12 changes: 10 additions & 2 deletions v2v/types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ val string_of_overlay : overlay -> string

type inspect = {
i_root : string; (** Root device. *)
i_type : string; (** Usual inspection fields. *)
i_distro : string;
i_arch : string;
i_major_version : int;
i_minor_version : int;
i_package_format : string;
i_package_management : string;
i_product_name : string;
i_product_variant : string;
i_apps : Guestfs.application2 list; (** List of packages installed. *)
i_apps_map : Guestfs.application2 list StringMap.t;
(** This is a map from the app name to the application object.
Since RPM allows multiple packages with the same name to be
installed, the value is a list. *)
}
(** Inspection information. Only the applications list is stored here
as that is the only one which is slow/inconvenient to fetch. *)
(** Inspection information. *)

type guestcaps = {
gcaps_block_bus : string; (** "virtio", "ide", possibly others *)
Expand Down
21 changes: 15 additions & 6 deletions v2v/v2v.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,16 @@ let rec main () =

(* Conversion. *)
let guestcaps =
let root = inspect.i_root in

(match g#inspect_get_product_name root with
(match inspect.i_product_name with
| "unknown" ->
msg (f_"Converting the guest to run on KVM")
| prod ->
msg (f_"Converting %s to run on KVM") prod
);

match g#inspect_get_type root with
match inspect.i_type with
| "linux" ->
(match g#inspect_get_distro root with
(match inspect.i_distro with
| "fedora"
| "rhel" | "centos" | "scientificlinux" | "redhat-based"
| "sles" | "suse-based" | "opensuse" ->
Expand Down Expand Up @@ -338,7 +336,18 @@ and inspect_source g root_choice =
StringMap.add name (app :: vs) map
) StringMap.empty apps in

{ i_root = root; i_apps = apps; i_apps_map = apps_map; }
{ i_root = root;
i_type = g#inspect_get_type root;
i_distro = g#inspect_get_distro root;
i_arch = g#inspect_get_arch root;
i_major_version = g#inspect_get_major_version root;
i_minor_version = g#inspect_get_minor_version root;
i_package_format = g#inspect_get_package_format root;
i_package_management = g#inspect_get_package_management root;
i_product_name = g#inspect_get_product_name root;
i_product_variant = g#inspect_get_product_variant root;
i_apps = apps;
i_apps_map = apps_map; }

let () =
try main ()
Expand Down

0 comments on commit 9ae2600

Please sign in to comment.