From b0ac37f6c9f6ab8da44e631e9cb6af5649548634 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 8 Jul 2025 11:15:56 +0100 Subject: [PATCH] -o kubevirt: Add -oo create=false to avoid disk creation Indicate that an external process will create the disks, so normal creation of disks by virt-v2v should be skipped. Testing ------- I couldn't think of a way to add a test this since g#disk_create (implemented in libguestfs.git:lib/create.c) will open(O_TRUNC) + truncate(2) the existing disk, so the inode will remain the same. Instead I tested it by hand by not creating the disk and observing the error from nbdkit: nbdkit: error: realpath: /var/tmp/disk.img: No such file or directory virt-v2v: error: nbdkit did not start up. There may be errors printed by nbdkit above. Fixes: https://issues.redhat.com/browse/RHEL-101599 --- docs/virt-v2v.pod | 5 +++++ output/output_kubevirt.ml | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/virt-v2v.pod b/docs/virt-v2v.pod index 5020d179..e228fb33 100644 --- a/docs/virt-v2v.pod +++ b/docs/virt-v2v.pod @@ -603,6 +603,11 @@ For outputs which support qcow2 format (I<-of qcow2>), this writes a compressed qcow2 file. It is the equivalent to the I<-c> option of L. +=item B<-oo create=false> + +For I<-o kubevirt>, indicate that another management process will +create the output disks, so do not (re-)create them in virt-v2v. + =item B<-oo disk=>DISK For I<-o kubevirt> this overrides the path to each output disk, diff --git a/output/output_kubevirt.ml b/output/output_kubevirt.ml index eae9c049..8a5ab56d 100644 --- a/output/output_kubevirt.ml +++ b/output/output_kubevirt.ml @@ -36,7 +36,8 @@ let rfc1123_re = module Kubevirt = struct type poptions = - bool * string list option * output_allocation * string * string * string + bool * bool * string list option * + output_allocation * string * string * string type t = unit @@ -50,17 +51,21 @@ module Kubevirt = struct printf (f_"Output options that can be used with -o kubevirt: -oo compressed Compress the output file (used only with -of qcow2) + -oo create=false Do not create the output disks -oo disk=disk1 Specify filename of output disk (if used, must be given once for each disk, else -os path is used) ") let parse_options options source = let compressed = ref false in + let create = ref true in let disks = ref [] in List.iter ( function | "compressed", "" -> compressed := true | "compressed", v -> compressed := bool_of_string v + | "create", "" -> create := true + | "create", v -> create := bool_of_string v | "disk", v -> List.push_back disks v | k, _ -> error (f_"-o kubevirt: unknown output option ā€˜-oo %s’") k @@ -90,18 +95,18 @@ module Kubevirt = struct let disks = match !disks with [] -> None | disks -> Some disks in - !compressed, disks, + !compressed, !create, disks, options.output_alloc, options.output_format, output_name, output_storage let setup dir options source input_disks = - let compressed, disks, + let compressed, create, disks, output_alloc, output_format, output_name, output_storage = options in let uris = match disks with | None -> - create_local_output_disks dir ~compressed + create_local_output_disks dir ~compressed ~create output_alloc output_format output_name output_storage input_disks | Some disks -> (* -oo disk specified, so create the disks by hand. *) @@ -118,7 +123,7 @@ module Kubevirt = struct let socket = sprintf "%s/out%d" dir i in On_exit.unlink socket; - output_to_local_file ~compressed + output_to_local_file ~compressed ~create output_alloc output_format disk size socket; NBD_URI.Unix (socket, None) @@ -128,7 +133,7 @@ module Kubevirt = struct (), uris let finalize dir options () output_disks source inspect target_meta = - let _, disks, + let _, _, disks, output_alloc, output_format, output_name, output_storage = options in (* This function will return the disk path for the i'th disk. *)