Blame SOURCES/0014-o-kubevirt-Implement-oo-compressed-for-qcow2-files.patch

c659c5
From 64a86bb9ef0298496a992a3a76d190b3895ffeee Mon Sep 17 00:00:00 2001
c659c5
From: "Richard W.M. Jones" <rjones@redhat.com>
c659c5
Date: Fri, 20 Jan 2023 10:35:55 +0000
c659c5
Subject: [PATCH] -o kubevirt: Implement -oo compressed for qcow2 files
c659c5
c659c5
Reported-by: Xiaodai Wang
c659c5
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2162444
c659c5
Updates: commit 53690a0c602a4286fdb9408fdf6a01cc352697ec
c659c5
(cherry picked from commit ada18150543466955ff73a24a9b9a66ddfac270e)
c659c5
---
c659c5
 output/output_kubevirt.ml | 30 ++++++++++++++++++++++--------
c659c5
 1 file changed, 22 insertions(+), 8 deletions(-)
c659c5
c659c5
diff --git a/output/output_kubevirt.ml b/output/output_kubevirt.ml
c659c5
index d41b5d8e..ee89fdbf 100644
c659c5
--- a/output/output_kubevirt.ml
c659c5
+++ b/output/output_kubevirt.ml
c659c5
@@ -35,7 +35,7 @@ let rfc1123_re =
c659c5
     "[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*"
c659c5
 
c659c5
 module Kubevirt = struct
c659c5
-  type poptions = output_allocation * string * string * string
c659c5
+  type poptions = bool * output_allocation * string * string * string
c659c5
 
c659c5
   type t = unit
c659c5
 
c659c5
@@ -46,11 +46,22 @@ module Kubevirt = struct
c659c5
       | None -> ""
c659c5
 
c659c5
   let query_output_options () =
c659c5
-    printf (f_"No output options can be used in this mode.\n")
c659c5
+    printf (f_"Output options that can be used with -o kubevirt:
c659c5
+
c659c5
+  -oo compressed      Compress the output file (used only with -of qcow2)
c659c5
+")
c659c5
+
c659c5
 
c659c5
   let parse_options options source =
c659c5
-    if options.output_options <> [] then
c659c5
-      error (f_"no -oo (output options) are allowed here");
c659c5
+    let compressed = ref false in
c659c5
+    List.iter (
c659c5
+      function
c659c5
+      | "compressed", "" -> compressed := true
c659c5
+      | "compressed", v -> compressed := bool_of_string v
c659c5
+      | k, _ ->
c659c5
+         error (f_"-o kubevirt: unknown output option ā€˜-oo %sā€™") k
c659c5
+    ) options.output_options;
c659c5
+
c659c5
     if options.output_password <> None then
c659c5
       error_option_cannot_be_used_in_output_mode "kubevirt" "-op";
c659c5
 
c659c5
@@ -73,11 +84,13 @@ module Kubevirt = struct
c659c5
                 end with an alphanumeric character.  Rerun virt-v2v with \
c659c5
                 the '-on name' option to rename it.");
c659c5
 
c659c5
-    options.output_alloc, options.output_format, output_name, output_storage
c659c5
+    !compressed, options.output_alloc, options.output_format,
c659c5
+    output_name, output_storage
c659c5
 
c659c5
   let setup dir options source =
c659c5
     let disks = get_disks dir in
c659c5
-    let output_alloc, output_format, output_name, output_storage = options in
c659c5
+    let compressed, output_alloc, output_format, output_name, output_storage =
c659c5
+      options in
c659c5
 
c659c5
     List.iter (
c659c5
       fun (i, size) ->
c659c5
@@ -86,11 +99,12 @@ module Kubevirt = struct
c659c5
 
c659c5
         (* Create the actual output disk. *)
c659c5
         let outdisk = disk_path output_storage output_name i in
c659c5
-        output_to_local_file output_alloc output_format outdisk size socket
c659c5
+        output_to_local_file ~compressed output_alloc output_format
c659c5
+          outdisk size socket
c659c5
     ) disks
c659c5
 
c659c5
   let finalize dir options () source inspect target_meta =
c659c5
-    let output_alloc, output_format, output_name, output_storage = options in
c659c5
+    let _, output_alloc, output_format, output_name, output_storage = options in
c659c5
 
c659c5
     let doc = create_kubevirt_yaml source inspect target_meta
c659c5
                 (disk_path output_storage output_name)