[Libguestfs] [PATCH] v2v: Allow output modes to rewrite disk copying
Richard W.M. Jones
rjones at redhat.com
Tue Apr 30 07:27:36 UTC 2019
On Tue, Apr 30, 2019 at 08:48:30AM +0200, Martin Kletzander wrote:
> All the current output modes use the default, It's just that I have a patch that
> uses this, so there might be someone in the future who wants to use this and if
> not, then at least you can tell me if this is wrong or not.
It's a straightforward enough refactoring. I see no problem with the
patch as it stands, but I'd want to see the dependent patches before
we push the whole lot as a series.
Rich.
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
> v2v/types.ml | 15 +++++++++++++++
> v2v/types.mli | 8 +++++++-
> v2v/v2v.ml | 17 +++--------------
> 3 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/v2v/types.ml b/v2v/types.ml
> index 77f879200a26..2780f05fdfbf 100644
> --- a/v2v/types.ml
> +++ b/v2v/types.ml
> @@ -521,6 +521,21 @@ class virtual output = object
> method override_output_format (_ : overlay) = (None : string option)
> method virtual prepare_targets : source -> (string * overlay) list -> target_buses -> guestcaps -> inspect -> target_firmware -> target_file list
> method disk_create = (open_guestfs ())#disk_create
> + method disk_copy target compressed =
> + let filename =
> + match target.target_file with
> + | TargetFile filename -> qemu_input_filename filename
> + | TargetURI uri -> uri in
> + let cmd =
> + [ "qemu-img"; "convert" ] @
> + (if not (quiet ()) then [ "-p" ] else []) @
> + [ "-n"; "-f"; "qcow2"; "-O"; target.target_format ] @
> + (if compressed then [ "-c" ] else []) @
> + [ target.target_overlay.ov_overlay_file; filename ] in
> + message (f_"Copying disk to %s (%s)") filename target.target_format;
> + if run_command cmd <> 0 then
> + error (f_"qemu-img command failed, see earlier errors");
> +
> method virtual create_metadata : source -> target list -> target_buses -> guestcaps -> inspect -> target_firmware -> unit
> method keep_serial_console = true
> method install_rhev_apt = false
> diff --git a/v2v/types.mli b/v2v/types.mli
> index be9406100785..a3b89bbcc9b3 100644
> --- a/v2v/types.mli
> +++ b/v2v/types.mli
> @@ -438,7 +438,9 @@ end
> │ this by defining output#disk_create.
> ▼
> copying Guest data is copied to the target disks
> - │ by running ‘qemu-img convert’.
> + (output#disk_copy) by running ‘qemu-img convert’. In rare
> + │ case output modules can affect the
> + │ behaviour of this in output#disk_copy
> │
> ▼
> output#create_metadata VM should be created from the metadata
> @@ -485,6 +487,10 @@ class virtual output : object
> (** Called in order to create disks on the target. The method has the
> same signature as Guestfs#disk_create. Normally you should {b not}
> define this since the default method calls Guestfs#disk_create. *)
> + method disk_copy : target -> bool -> unit
> + (** Called in order to copy disks on the target. Normally you should
> + {b not} define this unless you handle the copy yourself in a very
> + special way. *)
> method virtual create_metadata : source -> target list -> target_buses -> guestcaps -> inspect -> target_firmware -> unit
> (** Called after conversion and copying to create metadata and
> do any finalization. *)
> diff --git a/v2v/v2v.ml b/v2v/v2v.ml
> index 277d8f2c7a3e..1bd2225f7334 100644
> --- a/v2v/v2v.ml
> +++ b/v2v/v2v.ml
> @@ -687,10 +687,10 @@ and copy_targets cmdline targets input output =
> fun i t ->
> (match t.target_file with
> | TargetFile s ->
> - message (f_"Copying disk %d/%d to %s (%s)")
> + message (f_"Preparing disk %d/%d in %s (%s)")
> (i+1) nr_disks s t.target_format;
> | TargetURI s ->
> - message (f_"Copying disk %d/%d to qemu URI %s (%s)")
> + message (f_"Preparing disk %d/%d on qemu URI %s (%s)")
> (i+1) nr_disks s t.target_format
> );
> debug "%s" (string_of_overlay t.target_overlay);
> @@ -744,19 +744,8 @@ and copy_targets cmdline targets input output =
> ()
> );
>
> - let cmd =
> - let filename =
> - match t.target_file with
> - | TargetFile filename -> qemu_input_filename filename
> - | TargetURI uri -> uri in
> - [ "qemu-img"; "convert" ] @
> - (if not (quiet ()) then [ "-p" ] else []) @
> - [ "-n"; "-f"; "qcow2"; "-O"; t.target_format ] @
> - (if cmdline.compressed then [ "-c" ] else []) @
> - [ overlay_file; filename ] in
> let start_time = gettimeofday () in
> - if run_command cmd <> 0 then
> - error (f_"qemu-img command failed, see earlier errors");
> + output#disk_copy t cmdline.compressed;
> let end_time = gettimeofday () in
>
> (* Calculate the actual size on the target. *)
> --
> 2.21.0
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
More information about the Libguestfs
mailing list