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

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