Blame SOURCES/0016-v2v-vCenter-Adjust-readahead-parameter-between-conve.patch

0d20ef
From d783c57507d76ba18d61c3bfb7c867cf3d69d612 Mon Sep 17 00:00:00 2001
0d20ef
From: "Richard W.M. Jones" <rjones@redhat.com>
0d20ef
Date: Mon, 20 Oct 2014 18:34:48 +0100
0d20ef
Subject: [PATCH] v2v: vCenter: Adjust readahead parameter between conversion
0d20ef
 and copying phases (RHBZ#1151033) (RHBZ#1153589).
0d20ef
0d20ef
Previously we fixed RHBZ#1151033 by increasing the cURL readahead
0d20ef
parameter to a large value.  Unfortunately this is too large -- and
0d20ef
hence slow -- for the conversion phase, which broke on slow vCenter
0d20ef
servers (RHBZ#1153589).
0d20ef
0d20ef
What we do now is to perform the conversion phase with the default
0d20ef
readahead (2MB) to ensure stability, since performance of the
0d20ef
conversion phase is not critical.  Then before copying we change the
0d20ef
readahead to the larger value (64MB) to ensure efficient copying.
0d20ef
0d20ef
(cherry picked from commit 9281dc7d44b7b02c6470a61425aa177e6525ee88)
0d20ef
---
0d20ef
 v2v/input_libvirt.ml | 29 ++++++++++++++++++++++++++++-
0d20ef
 v2v/vCenter.ml       | 10 +++++++---
0d20ef
 v2v/vCenter.mli      |  2 +-
0d20ef
 3 files changed, 36 insertions(+), 5 deletions(-)
0d20ef
0d20ef
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
0d20ef
index 9d2869f..93d96b7 100644
0d20ef
--- a/v2v/input_libvirt.ml
0d20ef
+++ b/v2v/input_libvirt.ml
0d20ef
@@ -79,6 +79,9 @@ class input_libvirt_vcenter_https
0d20ef
 object
0d20ef
   inherit input_libvirt verbose libvirt_uri guest
0d20ef
 
0d20ef
+  val mutable mapf = fun ?readahead uri format -> uri, format
0d20ef
+  val saved_uri = Hashtbl.create 13
0d20ef
+
0d20ef
   method source () =
0d20ef
     if verbose then printf "input_libvirt_vcenter_https: source()\n%!";
0d20ef
 
0d20ef
@@ -91,7 +94,15 @@ object
0d20ef
     let { s_disks = disks } as source =
0d20ef
       Input_libvirtxml.parse_libvirt_xml ~verbose xml in
0d20ef
 
0d20ef
-    let mapf = VCenter.map_path_to_uri verbose parsed_uri scheme server in
0d20ef
+    (* Save the mapf function and the original s_qemu_uri fields, so
0d20ef
+     * we can get them in the adjust_overlay_parameters method below.
0d20ef
+     *)
0d20ef
+    mapf <- VCenter.map_path_to_uri verbose parsed_uri scheme server;
0d20ef
+    List.iter (
0d20ef
+      fun disk ->
0d20ef
+        Hashtbl.add saved_uri disk.s_disk_id (disk.s_qemu_uri, disk.s_format)
0d20ef
+    ) disks;
0d20ef
+
0d20ef
     let disks = List.map (
0d20ef
       fun ({ s_qemu_uri = uri; s_format = format } as disk) ->
0d20ef
         let uri, format = mapf uri format in
0d20ef
@@ -99,6 +110,22 @@ object
0d20ef
     ) disks in
0d20ef
 
0d20ef
     { source with s_disks = disks }
0d20ef
+
0d20ef
+  (* See RHBZ#1151033 and RHBZ#1153589 for why this is necessary. *)
0d20ef
+  method adjust_overlay_parameters overlay =
0d20ef
+    let orig_uri, orig_format =
0d20ef
+      try Hashtbl.find saved_uri overlay.ov_source.s_disk_id
0d20ef
+      with Not_found -> failwith "internal error in adjust_overlay_parameters" in
0d20ef
+    let backing_file, _ =
0d20ef
+      mapf ~readahead:(64 * 1024 * 1024) orig_uri orig_format in
0d20ef
+
0d20ef
+    (* Rebase the qcow2 overlay to adjust the readahead parameter. *)
0d20ef
+    let cmd =
0d20ef
+      sprintf "qemu-img rebase -u -b %s %s"
0d20ef
+        (quote backing_file) (quote overlay.ov_overlay_file) in
0d20ef
+    if verbose then printf "%s\n%!" cmd;
0d20ef
+    if Sys.command cmd <> 0 then
0d20ef
+      warning ~prog (f_"qemu-img rebase failed, see earlier errors")
0d20ef
 end
0d20ef
 
0d20ef
 (* Subclass specialized for handling Xen over SSH. *)
0d20ef
diff --git a/v2v/vCenter.ml b/v2v/vCenter.ml
0d20ef
index c04247e..dc29863 100644
0d20ef
--- a/v2v/vCenter.ml
0d20ef
+++ b/v2v/vCenter.ml
0d20ef
@@ -44,7 +44,7 @@ let session_cookie = ref ""
0d20ef
  * XXX Need to handle templates.  The file is called "-delta.vmdk" in
0d20ef
  * place of "-flat.vmdk".
0d20ef
  *)
0d20ef
-let rec map_path_to_uri verbose uri scheme server path format =
0d20ef
+let rec map_path_to_uri verbose uri scheme server ?readahead path format =
0d20ef
   if not (Str.string_match esx_re path 0) then
0d20ef
     path, format
0d20ef
   else (
0d20ef
@@ -84,11 +84,15 @@ let rec map_path_to_uri verbose uri scheme server path format =
0d20ef
       "file.driver", JSON.String "https";
0d20ef
       "file.url", JSON.String url;
0d20ef
       "file.timeout", JSON.Int 600;
0d20ef
-      (* Choose a large readahead.  See: RHBZ#1151033 *)
0d20ef
-      "file.readahead", JSON.Int (64 * 1024 * 1024);
0d20ef
     ] in
0d20ef
 
0d20ef
     let json_params =
0d20ef
+      match readahead with
0d20ef
+      | None -> json_params
0d20ef
+      | Some readahead ->
0d20ef
+        ("file.readahead", JSON.Int readahead) :: json_params in
0d20ef
+
0d20ef
+    let json_params =
0d20ef
       if sslverify then json_params
0d20ef
       else ("file.sslverify", JSON.String "off") :: json_params in
0d20ef
 
0d20ef
diff --git a/v2v/vCenter.mli b/v2v/vCenter.mli
0d20ef
index e504098..06ba452 100644
0d20ef
--- a/v2v/vCenter.mli
0d20ef
+++ b/v2v/vCenter.mli
0d20ef
@@ -18,6 +18,6 @@
0d20ef
 
0d20ef
 (** Functions for dealing with ESX. *)
0d20ef
 
0d20ef
-val map_path_to_uri : bool -> Xml.uri -> string -> string -> string -> string option -> string * string option
0d20ef
+val map_path_to_uri : bool -> Xml.uri -> string -> string -> ?readahead:int -> string -> string option -> string * string option
0d20ef
 (** Map a VMware path like "[datastore1] guest/guest.vmdk" to the
0d20ef
     URL where we can fetch the data. *)
0d20ef
-- 
0d20ef
1.8.3.1
0d20ef