[Pkg-libvirt-commits] [libguestfs] 86/266: v2v: Add --no-copy option.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:41:45 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 cec3b42ad6f72195f4ffae80757b34e046bbc2f6
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Tue Aug 12 21:53:57 2014 +0100
v2v: Add --no-copy option.
This option allows callers to generate the metadata without copying
the disks.
---
v2v/cmdline.ml | 9 +++++-
v2v/target_RHEV.ml | 27 +++++++++++++-----
v2v/v2v.ml | 82 ++++++++++++++++++++++++++++--------------------------
v2v/virt-v2v.pod | 12 ++++++++
4 files changed, 83 insertions(+), 47 deletions(-)
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index bcc9740..c76b5bd 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -33,6 +33,7 @@ let parse_cmdline () =
in
let debug_gc = ref false in
+ let do_copy = ref true in
let input_conn = ref "" in
let output_conn = ref "" in
let output_format = ref "" in
@@ -91,6 +92,7 @@ let parse_cmdline () =
"-ic", Arg.Set_string input_conn, "uri " ^ s_"Libvirt URI";
"--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
"--machine-readable", Arg.Set machine_readable, " " ^ s_"Make output machine readable";
+ "--no-copy", Arg.Clear do_copy, " " ^ s_"Just write the metadata";
"-o", Arg.String set_output_mode, "libvirt|local|rhev " ^ 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";
@@ -139,6 +141,7 @@ read the man page virt-v2v(1).
(* Dereference the arguments. *)
let args = List.rev !args in
let debug_gc = !debug_gc in
+ let do_copy = !do_copy in
let input_conn = match !input_conn with "" -> None | s -> Some s in
let input_mode = !input_mode in
let machine_readable = !machine_readable in
@@ -202,7 +205,10 @@ read the man page virt-v2v(1).
error (f_"-o libvirt: do not use the -os option");
if vmtype <> None then
error (f_"--vmtype option can only be used with '-o rhev'");
+ if not do_copy then
+ error (f_"--no-copy and '-o libvirt' cannot be used at the same time");
OutputLibvirt output_conn
+
| `Local ->
if output_storage = "" then
error (f_"-o local: output directory was not specified, use '-os /dir'");
@@ -212,6 +218,7 @@ read the man page virt-v2v(1).
if vmtype <> None then
error (f_"--vmtype option can only be used with '-o rhev'");
OutputLocal output_storage
+
| `RHEV ->
if output_storage = "" then
error (f_"-o rhev: output storage was not specified, use '-os'");
@@ -224,5 +231,5 @@ read the man page virt-v2v(1).
OutputRHEV (output_storage, rhev_params) in
input, output,
- debug_gc, output_alloc, output_format, output_name,
+ debug_gc, do_copy, output_alloc, output_format, output_name,
quiet, root_choice, trace, verbose
diff --git a/v2v/target_RHEV.ml b/v2v/target_RHEV.ml
index 77d0bf8..c0d0b2e 100644
--- a/v2v/target_RHEV.ml
+++ b/v2v/target_RHEV.ml
@@ -516,8 +516,7 @@ and add_disks output_alloc overlays guestcaps ovf =
fun i ov ->
let is_boot_drive = i == 0 in
- let target_file = ov.ov_target_file
- and vol_uuid = ov.ov_vol_uuid in
+ let vol_uuid = ov.ov_vol_uuid in
assert (vol_uuid <> "");
let fileref = !image_uuid // vol_uuid in
@@ -525,8 +524,17 @@ and add_disks output_alloc overlays guestcaps ovf =
let size_gb =
Int64.to_float ov.ov_virtual_size /. 1024. /. 1024. /. 1024. in
let usage_gb =
- let usage_mb = du_m target_file in
- Int64.to_float usage_mb /. 1024. in
+ (* In the --no-copy case it can happen that the target file
+ * does not exist. In that case we simply omit the
+ * ovf:actual_size attribute.
+ *)
+ if Sys.file_exists ov.ov_target_file then (
+ let usage_mb = du_m ov.ov_target_file in
+ if usage_mb > 0L then (
+ let usage_mb = Int64.to_float usage_mb /. 1024. in
+ Some usage_mb
+ ) else None
+ ) else None in
let format_for_rhev =
match ov.ov_target_format with
@@ -552,10 +560,9 @@ and add_disks output_alloc overlays guestcaps ovf =
(* Add disk to DiskSection. *)
let disk =
- e "Disk" [
+ let attrs = [
"ovf:diskId", vol_uuid;
"ovf:size", sprintf "%.1f" size_gb;
- "ovf:actual_size", sprintf "%.1f" usage_gb;
"ovf:fileRef", fileref;
"ovf:parentRef", "";
"ovf:vm_snapshot_id", uuidgen ~prog ();
@@ -566,7 +573,13 @@ and add_disks output_alloc overlays guestcaps ovf =
if guestcaps.gcaps_block_bus = "virtio" then "VirtIO" else "IDE";
"ovf:disk-type", "System"; (* RHBZ#744538 *)
"ovf:boot", if is_boot_drive then "True" else "False";
- ] [] in
+ ] in
+ let attrs =
+ match usage_gb with
+ | None -> attrs
+ | Some usage_gb ->
+ ("ovf:actual_size", sprintf "%.1f" usage_gb) :: attrs in
+ e "Disk" attrs [] in
append_child disk disk_section;
(* Add disk to VirtualHardware. *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 652d514..2a9d944 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -32,7 +32,7 @@ let () = Random.self_init ()
let rec main () =
(* Handle the command line. *)
let input, output,
- debug_gc, output_alloc, output_format, output_name,
+ debug_gc, do_copy, output_alloc, output_format, output_name,
quiet, root_choice, trace, verbose =
Cmdline.parse_cmdline () in
@@ -134,56 +134,60 @@ let rec main () =
| typ ->
error (f_"virt-v2v is unable to convert this guest type (type=%s)") typ in
- (* Trim the filesystems to reduce transfer size. *)
- msg (f_"Trimming filesystems to reduce amount of data to copy");
- let () =
+ if do_copy then (
+ (* Trim the filesystems to reduce transfer size. *)
+ msg (f_"Trimming filesystems to reduce amount of data to copy");
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
- ) mps in
+ ) mps
+ );
msg (f_"Closing the overlay");
g#umount_all ();
g#shutdown ();
g#close ();
- (* Copy the source to the output. *)
let delete_target_on_exit = ref true in
- at_exit (fun () ->
- if !delete_target_on_exit then (
- List.iter (
- fun ov -> try Unix.unlink ov.ov_target_file with _ -> ()
- ) overlays
- )
- );
- let nr_overlays = List.length overlays in
- iteri (
- fun i ov ->
- msg (f_"Copying disk %d/%d to %s (%s)")
- (i+1) nr_overlays ov.ov_target_file ov.ov_target_format;
- if verbose then printf "%s%!" (string_of_overlay ov);
-
- (* It turns out that libguestfs's disk creation code is
- * considerably more flexible and easier to use than qemu-img, so
- * create the disk explicitly using libguestfs then pass the
- * 'qemu-img convert -n' option so qemu reuses the disk.
- *)
- let preallocation = ov.ov_preallocation in
- let compat =
- match ov.ov_target_format with "qcow2" -> Some "1.1" | _ -> None in
- (new G.guestfs ())#disk_create ov.ov_target_file
- ov.ov_target_format ov.ov_virtual_size ?preallocation ?compat;
-
- let cmd =
- sprintf "qemu-img convert -n -f qcow2 -O %s %s %s"
- (quote ov.ov_target_format) (quote ov.ov_overlay)
- (quote ov.ov_target_file) in
- if verbose then printf "%s\n%!" cmd;
- if Sys.command cmd <> 0 then
- error (f_"qemu-img command failed, see earlier errors");
- ) overlays;
+
+ if do_copy then (
+ (* Copy the source to the output. *)
+ at_exit (fun () ->
+ if !delete_target_on_exit then (
+ List.iter (
+ fun ov -> try Unix.unlink ov.ov_target_file with _ -> ()
+ ) overlays
+ )
+ );
+ let nr_overlays = List.length overlays in
+ iteri (
+ fun i ov ->
+ msg (f_"Copying disk %d/%d to %s (%s)")
+ (i+1) nr_overlays ov.ov_target_file ov.ov_target_format;
+ if verbose then printf "%s%!" (string_of_overlay ov);
+
+ (* It turns out that libguestfs's disk creation code is
+ * considerably more flexible and easier to use than qemu-img, so
+ * create the disk explicitly using libguestfs then pass the
+ * 'qemu-img convert -n' option so qemu reuses the disk.
+ *)
+ let preallocation = ov.ov_preallocation in
+ let compat =
+ match ov.ov_target_format with "qcow2" -> Some "1.1" | _ -> None in
+ (new G.guestfs ())#disk_create ov.ov_target_file
+ ov.ov_target_format ov.ov_virtual_size ?preallocation ?compat;
+
+ let cmd =
+ sprintf "qemu-img convert -n -f qcow2 -O %s %s %s"
+ (quote ov.ov_target_format) (quote ov.ov_overlay)
+ (quote ov.ov_target_file) in
+ if verbose then printf "%s\n%!" cmd;
+ if Sys.command cmd <> 0 then
+ error (f_"qemu-img command failed, see earlier errors");
+ ) overlays
+ ) (* do_copy *);
(* Create output metadata. *)
msg (f_"Creating output metadata");
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 505894d..606831e 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -68,6 +68,18 @@ This option is used to make the output more machine friendly
when being parsed by other programs. See
L</MACHINE READABLE OUTPUT> below.
+=item B<--no-copy>
+
+Don't copy the disks. Instead, conversion is performed (and thrown
+away), and metadata is written, but no disks are created.
+
+This is useful in two cases: Either you want to test if conversion is
+likely to succeed, without the long copying process. Or you are only
+interested in looking at the metadata.
+
+This option is not compatible with I<-o libvirt> since it would create
+a faulty guest (one with no disks).
+
=item B<-o libvirt>
Set the output method to I<libvirt>. This is the default.
--
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