[Libguestfs] [PATCH 07/11] v2v: add support for SUSE VMDP drivers

Cédric Bosdonnat cbosdonnat at suse.com
Thu May 12 13:29:15 UTC 2016


To add this support, two things are needed:
 * make the existing code searches for either the viostor
   or the SUSE VMDP (Virtual Machine Driver Pack) files.

 * add a firstboot script setting up VMDP.

Note that 2 firstboot scripts are intentionally added for the VMDP
setup. This is due to windows potentially rebooting after loading the
virtio block driver. It may happen that this reboot interrupts the VMDP
setup in the firstboot script, we thus make sure the setup is run a
second time in case it needs to finish the previous run.
---
 v2v/convert_windows.ml | 73 +++++++++++++++++++++++++++++++++++++++++---------
 v2v/windows_virtio.ml  | 25 ++++++++++++-----
 2 files changed, 78 insertions(+), 20 deletions(-)

diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index 5daae6c..ab28636 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -43,18 +43,25 @@ let convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
     try Sys.getenv "VIRT_TOOLS_DATA_DIR"
     with Not_found -> Guestfs_config.datadir // "virt-tools" in
 
-  (* Check if RHEV-APT exists.  This is optional. *)
-  let rhev_apt_exe = virt_tools_data_dir // "rhev-apt.exe" in
-  let rhev_apt_exe =
+  (* Check if either RHEV-APT or VMDP exists.  This is optional. *)
+  let tools = ["rhev-apt.exe"; "vmdp.exe"] in
+  let installer =
     try
-      let chan = open_in rhev_apt_exe in
-      close_in chan;
-      Some rhev_apt_exe
-    with
-      Sys_error msg ->
-        warning (f_"'%s' is missing.  Unable to install RHEV-APT (RHEV guest agent).  Original error: %s")
-          rhev_apt_exe msg;
-        None in
+      let tool = List.find (
+        fun item ->
+          try (
+            let exe_path = virt_tools_data_dir // item in
+            let chan = open_in exe_path in
+            close_in chan;
+            true
+          ) with _ ->
+            false
+      ) tools in
+      Some (virt_tools_data_dir // tool)
+    with Not_found -> (
+      warning (f_"Neither rhev-apt.exe nor vmdp.exe can be found.  Unable to install one of them.");
+      None
+    ) in
 
   (* Get the Windows %systemroot%. *)
   let systemroot = g#inspect_get_windows_systemroot inspect.i_root in
@@ -211,7 +218,14 @@ let convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
   (* Perform the conversion of the Windows guest. *)
 
   let rec configure_firstboot () =
-    configure_rhev_apt ();
+    match installer with
+    | None -> info (f_"No firstboot installer to configure")
+    | Some installer_path ->
+       let installer_name = Filename.basename installer_path in
+       match installer_name with
+        | "rhev-apt.exe" -> configure_rhev_apt ()
+        | "vmdp.exe" -> configure_vmdp ()
+        | _ -> info (f_"No setup function for installer '%s'") installer_path;
     unconfigure_xenpv ();
     unconfigure_prltools ()
 
@@ -219,7 +233,7 @@ let convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
     (* Configure RHEV-APT (the RHEV guest agent).  However if it doesn't
      * exist just warn about it and continue.
      *)
-    match rhev_apt_exe with
+    match installer with
     | None -> ()
     | Some rhev_apt_exe ->
       g#upload rhev_apt_exe "/rhev-apt.exe"; (* XXX *)
@@ -236,6 +250,39 @@ net start rhev-apt
       Firstboot.add_firstboot_script g inspect.i_root
         "configure rhev-apt" fb_script
 
+  and configure_vmdp () =
+    (* Configure VMDP if possible *)
+    match installer with
+    | None -> ()
+    | Some vmdp_exe ->
+      g#upload vmdp_exe "/vmdp.exe";
+
+      let fb_script = "\
+echo V2V first boot script started
+echo Decompressing VMDP installer
+\"\\vmdp.exe\"
+pushd \"VMDP-*\"
+echo Installing VMDP
+setup.exe /eula_accepted /no_reboot
+popd
+" in
+
+      let fb_recover_script = "\
+echo Finishing VMDP installation
+if not exist VMDP-* (
+  \"\\vmdp.exe\"
+)
+pushd \"VMDP-*\"
+setup.exe /eula_accepted /no_reboot
+popd
+" in
+
+      Firstboot.add_firstboot_script g inspect.i_root
+        "configure vmdp" fb_script;
+
+      Firstboot.add_firstboot_script g inspect.i_root
+        "finish vmdp setup" fb_recover_script
+
   and unconfigure_xenpv () =
     match xenpv_uninst with
     | None -> () (* nothing to be uninstalled *)
diff --git a/v2v/windows_virtio.ml b/v2v/windows_virtio.ml
index 7e9f735..a878a3e 100644
--- a/v2v/windows_virtio.ml
+++ b/v2v/windows_virtio.ml
@@ -66,11 +66,19 @@ let rec install_drivers g inspect systemroot root current_cs rcaps =
   else (
     (* Can we install the block driver? *)
     let block : guestcaps_block_type =
-      let has_viostor = g#exists (driverdir // "viostor.inf") in
+      let filenames = ["virtio_blk"; "vrtioblk"; "viostor"] in
+      let driver_name = try (
+        List.find (
+          fun driver_file ->
+            let source = driverdir // (driver_file ^ ".sys") in
+            g#exists source
+        ) filenames
+      ) with Not_found -> "" in
+      let has_viostor = not (driver_name = "") in
       let has_vioscsi = g#exists (driverdir // "vioscsi.inf") in
       match rcaps.rcaps_block_bus, has_viostor, has_vioscsi with
       | Some Virtio_blk, false, _ ->
-        error (f_"there is no viostor (virtio block device) driver for this version of Windows (%d.%d %s).  virt-v2v looks for this driver in %s\n\nThe guest will be configured to use a slower emulated device.")
+        error (f_"there is no virtio block device driver for this version of Windows (%d.%d %s).  virt-v2v looks for this driver in %s\n\nThe guest will be configured to use a slower emulated device.")
               inspect.i_major_version inspect.i_minor_version
               inspect.i_arch virtio_win
 
@@ -79,8 +87,9 @@ let rec install_drivers g inspect systemroot root current_cs rcaps =
               inspect.i_major_version inspect.i_minor_version
               inspect.i_arch virtio_win
 
+
       | None, false, _ ->
-        warning (f_"there is no viostor (virtio block device) driver for this version of Windows (%d.%d %s).  virt-v2v looks for this driver in %s\n\nThe guest will be configured to use a slower emulated device.")
+        warning (f_"there is no virtio block device driver for this version of Windows (%d.%d %s).  virt-v2v looks for this driver in %s\n\nThe guest will be configured to use a slower emulated device.")
                 inspect.i_major_version inspect.i_minor_version
                 inspect.i_arch virtio_win;
         IDE
@@ -88,11 +97,12 @@ let rec install_drivers g inspect systemroot root current_cs rcaps =
       | (Some Virtio_blk | None), true, _ ->
         (* Block driver needs tweaks to allow booting; the rest is set up by PnP
          * manager *)
-        let source = driverdir // "viostor.sys" in
-        let target = sprintf "%s/system32/drivers/viostor.sys" systemroot in
+        let source = driverdir // (driver_name ^ ".sys") in
+        let targetdir = systemroot ^ "/system32/drivers/" in
+        let target = targetdir // (driver_name ^ ".sys") in
         let target = g#case_sensitive_path target in
         g#cp source target;
-        add_guestor_to_registry g root current_cs "viostor"
+        add_guestor_to_registry g root current_cs driver_name
                                 viostor_pciid;
         Virtio_blk
 
@@ -112,7 +122,8 @@ let rec install_drivers g inspect systemroot root current_cs rcaps =
 
     (* Can we install the virtio-net driver? *)
     let net : guestcaps_net_type =
-      let has_netkvm = g#exists (driverdir // "netkvm.inf") in
+      let filenames = ["virtio_net.inf"; "netkvm.inf"] in
+      let has_netkvm = List.exists (fun driver_file -> g#exists (driverdir // driver_file)) filenames in
       match rcaps.rcaps_net_bus, has_netkvm with
       | Some Virtio_net, false ->
         error (f_"there is no virtio network driver for this version of Windows (%d.%d %s).  virt-v2v looks for this driver in %s")
-- 
2.6.6




More information about the Libguestfs mailing list