Richard W.M. Jones
2017-Dec-07 16:21 UTC
[Libguestfs] [PATCH] v2v: -o null: Use the qemu null device driver.
Instead of writing to a temporary file and deleting it, use the null
block driver in qemu to throw it away.
---
v2v/output_null.ml | 47 +++++++++++++++++++++++++++++++++--------------
v2v/virt-v2v.pod | 4 ----
2 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/v2v/output_null.ml b/v2v/output_null.ml
index d01f45654..4d06aa0de 100644
--- a/v2v/output_null.ml
+++ b/v2v/output_null.ml
@@ -26,16 +26,23 @@ open Common_gettext.Gettext
open Types
open Utils
+(* Notes:
+ *
+ * This only happens to work because we run qemu-img convert
+ * with the -n [no create output] option, since null-co doesn't
+ * support creation. If -n is removed in the main program then
+ * the tests will break very obviously.
+ *
+ * The null-co device is not zero-sized. It actually has a fixed
+ * size (defaults to 2^30 I believe).
+ *
+ * qemu-img convert checks the output size and will fail if it's
+ * too small, so we have to set the size. We could set it to
+ * match the input size but it's easier to set it to some huge
+ * size instead.
+ *)
+
class output_null - (* It would be nice to be able to write to /dev/null.
- * Unfortunately qemu-img convert cannot do that. Instead create a
- * temporary directory which is always deleted at exit.
- *)
- let tmpdir - let base_dir = (open_guestfs ())#get_cachedir () in
- let t = Mkdtemp.temp_dir ~base_dir "null." in
- rmdir_on_exit t;
- t in
object
inherit output
@@ -44,13 +51,25 @@ object
method supported_firmware = [ TargetBIOS; TargetUEFI ]
method prepare_targets source targets - List.map (
- fun t ->
- let target_file = tmpdir // t.target_overlay.ov_sd in
- { t with target_file = target_file }
- ) targets
+ let json_params = [
+ "file.driver", JSON.String "null-co";
+ "file.size", JSON.String "1E";
+ ] in
+ let target_file = "json:" ^ JSON.string_of_doc json_params in
+ (* XXX It's not really right to set target_format here, but
+ * it works.
+ *)
+ let target_format = "raw" in
+ List.map (fun t -> { t with target_file; target_format }) targets
method create_metadata _ _ _ _ _ _ = ()
+
+ (* Stops the main program from calling g#disk_create to try to create
+ * the null device.
+ *)
+ method disk_create ?backingfile ?backingformat ?preallocation ?compat
+ ?clustersize path format size + ()
end
let output_null () = new output_null
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index aad06ead0..4ac44988e 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -1901,10 +1901,6 @@ This temporarily places a full copy of the output disks
in C<$TMPDIR>.
You must ensure there is sufficient space in the output directory for
the converted guest.
-=item I<-o null>
-
-This temporarily places a full copy of the output disks in C<$TMPDIR>.
-
=back
See also L</Minimum free space check in the host> below.
--
2.13.2
Richard W.M. Jones
2017-Dec-07 16:52 UTC
Re: [Libguestfs] [PATCH] v2v: -o null: Use the qemu null device driver.
On Thu, Dec 07, 2017 at 04:21:14PM +0000, Richard W.M. Jones wrote:> Instead of writing to a temporary file and deleting it, use the null > block driver in qemu to throw it away.This commit isn't quite right (although working) because certain places in the code expect target_file to be a real file. eg We are calling 'du' on the target file resulting in this non-fatal message: du: cannot access 'json:{ "file.driver": "null-co", "file.size": "1E" }': No such file or directory Need to think about this a bit. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Possibly Parallel Threads
- [PATCH] v2v: -o null: support older qemu-img (RHBZ#1580309)
- [v2v PATCH 1/2] Add back guestcaps as parameter of output#prepare_targets
- [PATCH v2 0/2] v2v: -o null: Use the qemu null device driver.
- [PATCH] v2v: Allow output modes to rewrite disk copying
- [PATCH 3/4] ocaml tools: Use global variables to store trace (-x) and verbose (-v) flags.