Blame SOURCES/0009-lib-Autodetect-backing-format-for-qemu-img-create-b.patch

aba816
From 791a16b049ea1ce2c450acd367fce774d9aab5b1 Mon Sep 17 00:00:00 2001
aba816
From: "Richard W.M. Jones" <rjones@redhat.com>
aba816
Date: Tue, 31 Aug 2021 08:27:15 +0100
aba816
Subject: [PATCH] lib: Autodetect backing format for qemu-img create -b
aba816
aba816
qemu 6.1 has decided to change qemu-img create so that a backing
aba816
format (-F) is required if a backing file (-b) is specified.  Since we
aba816
don't want to change the libguestfs API to force callers to specify
aba816
this because that would be an API break, autodetect it.
aba816
aba816
This is similar to commit c8c181e8d9 ("launch: libvirt: Autodetect
aba816
backing format for readonly drive overlays").
aba816
aba816
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1998820
aba816
(cherry picked from commit 45de287447bb18d59749fbfc1ec5072413090109)
aba816
---
aba816
 lib/create.c | 9 +++++++++
aba816
 1 file changed, 9 insertions(+)
aba816
aba816
diff --git a/lib/create.c b/lib/create.c
aba816
index 44a7df25f..75a4d3a28 100644
aba816
--- a/lib/create.c
aba816
+++ b/lib/create.c
aba816
@@ -255,6 +255,7 @@ disk_create_qcow2 (guestfs_h *g, const char *filename, int64_t size,
aba816
                    const struct guestfs_disk_create_argv *optargs)
aba816
 {
aba816
   const char *backingformat = NULL;
aba816
+  CLEANUP_FREE char *backingformat_free = NULL;
aba816
   const char *preallocation = NULL;
aba816
   const char *compat = NULL;
aba816
   int clustersize = -1;
aba816
@@ -270,6 +271,14 @@ disk_create_qcow2 (guestfs_h *g, const char *filename, int64_t size,
aba816
       return -1;
aba816
     }
aba816
   }
aba816
+  else if (backingfile) {
aba816
+    /* Since qemu 6.1, qemu-img create has requires a backing format (-F)
aba816
+     * parameter if backing file (-b) is used (RHBZ#1998820).
aba816
+     */
aba816
+    backingformat = backingformat_free = guestfs_disk_format (g, backingfile);
aba816
+    if (!backingformat)
aba816
+      return -1;
aba816
+  }
aba816
   if (optargs->bitmask & GUESTFS_DISK_CREATE_PREALLOCATION_BITMASK) {
aba816
     if (STREQ (optargs->preallocation, "off") ||
aba816
         STREQ (optargs->preallocation, "sparse"))
aba816
-- 
aba816
2.31.1
aba816