From fbb0daf1ee29cda6d9117be2430c7d5d66463eca Mon Sep 17 00:00:00 2001
From: Pino Toscano <ptoscano@redhat.com>
Date: Mon, 16 Sep 2019 14:01:14 +0200
Subject: [PATCH] v2v: add output#disk_copied hook
Add a simple method in the Output class to do work right after a disk
was successfully copied.
(cherry picked from commit 74ee936505acf56d01f9b819588e7902a9401e81)
---
v2v/types.ml | 1 +
v2v/types.mli | 8 ++++++++
v2v/v2v.ml | 9 ++++++++-
3 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/v2v/types.ml b/v2v/types.ml
index 77f879200..714b30014 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -521,6 +521,7 @@ 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_copied (_ : target) (_ : int) (_ : int) = ()
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 be9406100..f595ab0ef 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -441,6 +441,10 @@ end
│ by running ‘qemu-img convert’.
│
▼
+ output#disk_copied The output mode is notified about the
+ │ successful copy of each disk.
+ │
+ ▼
output#create_metadata VM should be created from the metadata
supplied. Also any finalization can
be done here.
@@ -485,6 +489,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_copied : target -> int -> int -> unit
+ (** Called after a disk was successfully copied on the target.
+ The second parameter is the index of the copied disk (starting
+ from 0), and the third is the number of disks in total. *)
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 277d8f2c7..63e809030 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -798,7 +798,14 @@ and copy_targets cmdline targets input output =
pc;
if pc < 0. then eprintf " ! ESTIMATE TOO LOW !";
eprintf "\n%!";
- )
+ );
+
+ (* Let the output mode know that the disk was copied successfully,
+ * so it can perform any operations without waiting for all the
+ * other disks to be copied (i.e. before the metadata is actually
+ * created).
+ *)
+ output#disk_copied t i nr_disks
) targets
(* Update the target_actual_size field in the target structure. *)
--
2.18.4