[Pkg-libvirt-commits] [libguestfs] 09/17: v2v: Add --no-trim option, allowing fstrim to be suppressed.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:48:30 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.55-1
in repository libguestfs.

commit ea015319b06acb76a5bd89961b16c2bc82aff74e
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Sep 26 12:42:08 2014 +0100

    v2v: Add --no-trim option, allowing fstrim to be suppressed.
    
    Mainly useful for testing whether fstrim is responsible for various
    unexplained boot failures.  We can also suggest it in the field.
---
 v2v/cmdline.ml   | 34 +++++++++++++++++++++++++++-------
 v2v/v2v.ml       | 10 ++++++----
 v2v/virt-v2v.pod | 19 +++++++++++++++++++
 3 files changed, 52 insertions(+), 11 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 26409d2..6b25a02 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -77,6 +77,24 @@ let parse_cmdline () =
     add_network, add_bridge
   in
 
+  let no_trim = ref [] in
+  let set_no_trim = function
+    | "all" | "ALL" | "*" ->
+      (* Note: this is a magic value tested in the main code.  The
+       * no_trim list does NOT support wildcards.
+       *)
+      no_trim := ["*"]
+    | mps ->
+      let mps = string_nsplit "," mps in
+      List.iter (
+        fun mp ->
+          if String.length mp = 0 then
+            error (f_"--no-trim: empty mountpoint");
+          if mp.[0] <> '/' then
+            error (f_"--no-trim: %s: mountpoint does not begin with '/'") mp;
+      ) mps
+  in
+
   let output_mode = ref `Not_set in
   let set_output_mode mode =
     if !output_mode <> `Not_set then
@@ -124,17 +142,18 @@ let parse_cmdline () =
     "--bridge",  Arg.String add_bridge,     "in:out " ^ s_"Map bridge 'in' to 'out'";
     "--debug-gc",Arg.Set debug_gc,          " " ^ s_"Debug GC and memory allocations";
     "--debug-overlay",Arg.Set debug_overlays,
-                                            " " ^ s_"Save overlay files";
+    " " ^ s_"Save overlay files";
     "--debug-overlays",Arg.Set debug_overlays,
-                                            ditto;
+    ditto;
     "-i",        Arg.String set_input_mode, i_options ^ " " ^ s_"Set input mode (default: libvirt)";
     "-ic",       Arg.Set_string input_conn, "uri " ^ s_"Libvirt URI";
     "-if",       Arg.Set_string input_format,
-                                            "format " ^ s_"Input format (for -i disk)";
+    "format " ^ s_"Input format (for -i disk)";
     "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
     "--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
     "--network", Arg.String add_network,    "in:out " ^ s_"Map network 'in' to 'out'";
     "--no-copy", Arg.Clear do_copy,         " " ^ s_"Just write the metadata";
+    "--no-trim", Arg.String set_no_trim,    "all|mp,mp,.." ^ s_"Don't trim selected mounts";
     "-o",        Arg.String set_output_mode, o_options ^ " " ^ s_"Set output mode (default: libvirt)";
     "-oa",       Arg.String set_output_alloc, "sparse|preallocated " ^ s_"Set output allocation mode";
     "-oc",       Arg.Set_string output_conn, "uri " ^ s_"Libvirt URI";
@@ -147,11 +166,11 @@ let parse_cmdline () =
     "--quiet",   Arg.Set quiet,             ditto;
     "--root",    Arg.String set_root_choice,"ask|... " ^ s_"How to choose root filesystem";
     "--vdsm-image-uuid",
-                 Arg.Set_string vdsm_image_uuid, "uuid " ^ s_"Output image UUID";
+    Arg.Set_string vdsm_image_uuid, "uuid " ^ s_"Output image UUID";
     "--vdsm-vol-uuid",
-                 Arg.String add_vdsm_vol_uuid, "uuid " ^ s_"Output vol UUID(s)";
+    Arg.String add_vdsm_vol_uuid, "uuid " ^ s_"Output vol UUID(s)";
     "--vdsm-vm-uuid",
-                 Arg.Set_string vdsm_vm_uuid, "uuid " ^ s_"Output VM UUID";
+    Arg.Set_string vdsm_vm_uuid, "uuid " ^ s_"Output VM UUID";
     "-v",        Arg.Set verbose,           " " ^ s_"Enable debugging messages";
     "--verbose", Arg.Set verbose,           ditto;
     "-V",        Arg.Unit display_version,  " " ^ s_"Display version and exit";
@@ -196,6 +215,7 @@ read the man page virt-v2v(1).
   let input_mode = !input_mode in
   let machine_readable = !machine_readable in
   let network_map = !network_map in
+  let no_trim = !no_trim in
   let output_alloc = !output_alloc in
   let output_conn = match !output_conn with "" -> None | s -> Some s in
   let output_format = match !output_format with "" -> None | s -> Some s in
@@ -353,6 +373,6 @@ read the man page virt-v2v(1).
         vmtype output_alloc in
 
   input, output,
-  debug_gc, debug_overlays, do_copy, network_map,
+  debug_gc, debug_overlays, do_copy, network_map, no_trim,
   output_alloc, output_format, output_name,
   print_source, quiet, root_choice, trace, verbose
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 7227960..970dfb2 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -40,7 +40,7 @@ let () = Random.self_init ()
 let rec main () =
   (* Handle the command line. *)
   let input, output,
-    debug_gc, debug_overlays, do_copy, network_map,
+    debug_gc, debug_overlays, do_copy, network_map, no_trim,
     output_alloc, output_format, output_name,
     print_source, quiet, root_choice, trace, verbose =
     Cmdline.parse_cmdline () in
@@ -244,7 +244,7 @@ let rec main () =
       printf (f_"This guest does not have virtio drivers installed.\n%!");
   );
 
-  if do_copy || debug_overlays then (
+  if no_trim <> ["*"] && (do_copy || debug_overlays) then (
     (* Doing fstrim on all the filesystems reduces the transfer size
      * because unused blocks are marked in the overlay and thus do
      * not have to be copied.
@@ -253,8 +253,10 @@ let rec main () =
     let mps = g#mountpoints () in
     List.iter (
       fun (_, mp) ->
-        try g#fstrim mp
-        with G.Error msg -> warning ~prog (f_"%s: %s (ignored)") mp msg
+        if not (List.mem mp no_trim) then (
+          try g#fstrim mp
+          with G.Error msg -> warning ~prog (f_"%s: %s (ignored)") mp msg
+        )
     ) mps
   );
 
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 8e45d77..646b3bd 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -259,6 +259,24 @@ a faulty guest (one with no disks).
 
 This option is not compatible with I<-o glance> for technical reasons.
 
+=item B<--no-trim all>
+
+=item B<--no-trim> mp[,mp...]
+
+By default virt-v2v runs L<fstrim(8)> to reduce the amount of data
+that needs to be copied.  This is known to break some buggy
+bootloaders causing boot failures after conversion (see for example
+L<https://bugzilla.redhat.com/show_bug.cgi?id=1141145#c27>).
+
+You can use I<--no-trim all> to disable all trimming.  Note this will
+greatly increase the amount of data that has to be copied and can make
+virt-v2v run much more slowly.
+
+You can also disable trimming on selected filesystems only (specified
+by a comma-separated list of their mount point(s) in the guest).
+Typically you would use I<--no-trim /boot> to work around the grub bug
+mentioned above.
+
 =item B<-o disk>
 
 This is the same as I<-o local>.
@@ -1023,6 +1041,7 @@ L<virt-sysprep(1)>,
 L<guestfs(3)>,
 L<guestfish(1)>,
 L<qemu-img(1)>,
+L<fstrim(8)>,
 L<http://libguestfs.org/>.
 
 =head1 AUTHORS

-- 
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