[Pkg-libvirt-commits] [libguestfs] 57/266: v2v: Keep more inspection data in the inspect struct.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:41:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit 95c3b78f081c2d861fb1517ccfd6b5eb1e1be224
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Aug 4 22:20:56 2014 +0100

    v2v: Keep more inspection data in the inspect struct.
    
    Just code motion, no functional change.
---
 v2v/convert_linux.ml   | 41 ++++++++++++++---------------------------
 v2v/convert_windows.ml | 16 ++++++++--------
 v2v/lib_linux.ml       |  7 +++----
 v2v/types.ml           |  9 +++++++++
 v2v/types.mli          | 12 ++++++++++--
 v2v/v2v.ml             | 21 +++++++++++++++------
 6 files changed, 59 insertions(+), 47 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index aba8d2c..3489c6b 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -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
@@ -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 =
@@ -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
@@ -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";
@@ -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
@@ -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. *)
@@ -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];
 
@@ -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
@@ -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 =
@@ -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 (
@@ -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
@@ -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 ->
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 3b0f673..626a427 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -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
@@ -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" ->
@@ -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 ->
@@ -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 (
@@ -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
diff --git a/v2v/lib_linux.ml b/v2v/lib_linux.ml
index 8362d2a..2c743e3 100644
--- a/v2v/lib_linux.ml
+++ b/v2v/lib_linux.ml
@@ -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
@@ -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" ->
@@ -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
diff --git a/v2v/types.ml b/v2v/types.ml
index 3d50bf3..849ad0f 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -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;
 }
diff --git a/v2v/types.mli b/v2v/types.mli
index 42f3dbe..c8ef5c3 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -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 *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 417b692..4dca2fe 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -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" ->
@@ -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 ()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list