Blame SOURCES/kvm-block-trickle-down-the-fallback-image-creation-funct.patch

902636
From a1f7b929ae1fe6fa424c520c3a5eb497333b0fd9 Mon Sep 17 00:00:00 2001
902636
From: Maxim Levitsky <mlevitsk@redhat.com>
902636
Date: Thu, 26 Mar 2020 20:23:07 +0000
902636
Subject: [PATCH 2/4] block: trickle down the fallback image creation function
902636
 use to the block drivers
902636
902636
RH-Author: Maxim Levitsky <mlevitsk@redhat.com>
902636
Message-id: <20200326202307.9264-3-mlevitsk@redhat.com>
902636
Patchwork-id: 94446
902636
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 2/2] block: trickle down the fallback image creation function use to the block drivers
902636
Bugzilla: 1816007
902636
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
902636
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
902636
Instead of checking the .bdrv_co_create_opts to see if we need the
902636
fallback, just implement the .bdrv_co_create_opts in the drivers that
902636
need it.
902636
902636
This way we don't break various places that need to know if the
902636
underlying protocol/format really supports image creation, and this way
902636
we still allow some drivers to not support image creation.
902636
902636
Fixes: fd17146cd93d1704cd96d7c2757b325fc7aac6fd
902636
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1816007
902636
902636
Note that technically this driver reverts the image creation fallback
902636
for the vxhs driver since I don't have a means to test it, and IMHO it
902636
is better to leave it not supported as it was prior to generic image
902636
creation patches.
902636
902636
Also drop iscsi_create_opts which was left accidentally.
902636
902636
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
902636
Message-Id: <20200326011218.29230-3-mlevitsk@redhat.com>
902636
Reviewed-by: Denis V. Lunev <den@openvz.org>
902636
[mreitz: Fixed alignment, and moved bdrv_co_create_opts_simple() and
902636
         bdrv_create_opts_simple from block.h into block_int.h]
902636
Signed-off-by: Max Reitz <mreitz@redhat.com>
902636
(cherry picked from commit 5a5e7f8cd86b7ced0732b1b6e28c82baa65b09c9)
902636
902636
Contextual conflicts in block.c and include/block/block_int.h
902636
902636
(conflict in block.c by default shows as functional but
902636
with --diff-algorithm=patience it becomes a contextual conflict)
902636
902636
...
902636
001/2:[----] [--] 'block: pass BlockDriver reference to the .bdrv_co_create'
902636
002/2:[0014] [FC] 'block: trickle down the fallback image creation function use to the block drivers'
902636
...
902636
002/2: 'meld <(git show 5a5e7f8^\!) <(git show 6d3bca5^\!)'
902636
902636
So now running:
902636
meld <(git show 5a5e7f8^\!  --diff-algorithm=patience) <(git show 6d3bca5^\! --diff-algorithm=patience)
902636
902636
shows no contextual conflicts
902636
It is mostly due to missing commit f6dc1c31d3801dcbdf0c56574f9ff4f05180810c
902636
Thanks to Max Reitz for helping me with this.
902636
902636
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 block.c                   | 35 ++++++++++++++++++++---------------
902636
 block/file-posix.c        |  7 ++++++-
902636
 block/iscsi.c             | 16 ++++------------
902636
 block/nbd.c               |  6 ++++++
902636
 block/nvme.c              |  3 +++
902636
 include/block/block.h     |  1 +
902636
 include/block/block_int.h | 11 +++++++++++
902636
 7 files changed, 51 insertions(+), 28 deletions(-)
902636
902636
diff --git a/block.c b/block.c
902636
index f9a1c5b..ba3b40d7 100644
902636
--- a/block.c
902636
+++ b/block.c
902636
@@ -597,8 +597,15 @@ static int create_file_fallback_zero_first_sector(BlockBackend *blk,
902636
     return 0;
902636
 }
902636
 
902636
-static int bdrv_create_file_fallback(const char *filename, BlockDriver *drv,
902636
-                                     QemuOpts *opts, Error **errp)
902636
+/**
902636
+ * Simple implementation of bdrv_co_create_opts for protocol drivers
902636
+ * which only support creation via opening a file
902636
+ * (usually existing raw storage device)
902636
+ */
902636
+int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
902636
+                                            const char *filename,
902636
+                                            QemuOpts *opts,
902636
+                                            Error **errp)
902636
 {
902636
     BlockBackend *blk;
902636
     QDict *options;
902636
@@ -662,11 +669,7 @@ int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp)
902636
         return -ENOENT;
902636
     }
902636
 
902636
-    if (drv->bdrv_co_create_opts) {
902636
-        return bdrv_create(drv, filename, opts, errp);
902636
-    } else {
902636
-        return bdrv_create_file_fallback(filename, drv, opts, errp);
902636
-    }
902636
+    return bdrv_create(drv, filename, opts, errp);
902636
 }
902636
 
902636
 /**
902636
@@ -1543,9 +1546,9 @@ QemuOptsList bdrv_runtime_opts = {
902636
     },
902636
 };
902636
 
902636
-static QemuOptsList fallback_create_opts = {
902636
-    .name = "fallback-create-opts",
902636
-    .head = QTAILQ_HEAD_INITIALIZER(fallback_create_opts.head),
902636
+QemuOptsList bdrv_create_opts_simple = {
902636
+    .name = "simple-create-opts",
902636
+    .head = QTAILQ_HEAD_INITIALIZER(bdrv_create_opts_simple.head),
902636
     .desc = {
902636
         {
902636
             .name = BLOCK_OPT_SIZE,
902636
@@ -5910,13 +5913,15 @@ void bdrv_img_create(const char *filename, const char *fmt,
902636
         return;
902636
     }
902636
 
902636
-    create_opts = qemu_opts_append(create_opts, drv->create_opts);
902636
-    if (proto_drv->create_opts) {
902636
-        create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
902636
-    } else {
902636
-        create_opts = qemu_opts_append(create_opts, &fallback_create_opts);
902636
+    if (!proto_drv->create_opts) {
902636
+        error_setg(errp, "Protocol driver '%s' does not support image creation",
902636
+                   proto_drv->format_name);
902636
+        return;
902636
     }
902636
 
902636
+    create_opts = qemu_opts_append(create_opts, drv->create_opts);
902636
+    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
902636
+
902636
     /* Create parameter list with default values */
902636
     opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
902636
     qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort);
902636
diff --git a/block/file-posix.c b/block/file-posix.c
902636
index a2e0a74..dd18d40 100644
902636
--- a/block/file-posix.c
902636
+++ b/block/file-posix.c
902636
@@ -3432,6 +3432,8 @@ static BlockDriver bdrv_host_device = {
902636
     .bdrv_reopen_prepare = raw_reopen_prepare,
902636
     .bdrv_reopen_commit  = raw_reopen_commit,
902636
     .bdrv_reopen_abort   = raw_reopen_abort,
902636
+    .bdrv_co_create_opts = bdrv_co_create_opts_simple,
902636
+    .create_opts         = &bdrv_create_opts_simple,
902636
     .mutable_opts        = mutable_opts,
902636
     .bdrv_co_invalidate_cache = raw_co_invalidate_cache,
902636
     .bdrv_co_pwrite_zeroes = hdev_co_pwrite_zeroes,
902636
@@ -3558,10 +3560,11 @@ static BlockDriver bdrv_host_cdrom = {
902636
     .bdrv_reopen_prepare = raw_reopen_prepare,
902636
     .bdrv_reopen_commit  = raw_reopen_commit,
902636
     .bdrv_reopen_abort   = raw_reopen_abort,
902636
+    .bdrv_co_create_opts = bdrv_co_create_opts_simple,
902636
+    .create_opts         = &bdrv_create_opts_simple,
902636
     .mutable_opts        = mutable_opts,
902636
     .bdrv_co_invalidate_cache = raw_co_invalidate_cache,
902636
 
902636
-
902636
     .bdrv_co_preadv         = raw_co_preadv,
902636
     .bdrv_co_pwritev        = raw_co_pwritev,
902636
     .bdrv_co_flush_to_disk  = raw_co_flush_to_disk,
902636
@@ -3690,6 +3693,8 @@ static BlockDriver bdrv_host_cdrom = {
902636
     .bdrv_reopen_prepare = raw_reopen_prepare,
902636
     .bdrv_reopen_commit  = raw_reopen_commit,
902636
     .bdrv_reopen_abort   = raw_reopen_abort,
902636
+    .bdrv_co_create_opts = bdrv_co_create_opts_simple,
902636
+    .create_opts         = &bdrv_create_opts_simple,
902636
     .mutable_opts       = mutable_opts,
902636
 
902636
     .bdrv_co_preadv         = raw_co_preadv,
902636
diff --git a/block/iscsi.c b/block/iscsi.c
902636
index b45da65..16b0716 100644
902636
--- a/block/iscsi.c
902636
+++ b/block/iscsi.c
902636
@@ -2399,18 +2399,6 @@ out_unlock:
902636
     return r;
902636
 }
902636
 
902636
-static QemuOptsList iscsi_create_opts = {
902636
-    .name = "iscsi-create-opts",
902636
-    .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head),
902636
-    .desc = {
902636
-        {
902636
-            .name = BLOCK_OPT_SIZE,
902636
-            .type = QEMU_OPT_SIZE,
902636
-            .help = "Virtual disk size"
902636
-        },
902636
-        { /* end of list */ }
902636
-    }
902636
-};
902636
 
902636
 static const char *const iscsi_strong_runtime_opts[] = {
902636
     "transport",
902636
@@ -2434,6 +2422,8 @@ static BlockDriver bdrv_iscsi = {
902636
     .bdrv_parse_filename    = iscsi_parse_filename,
902636
     .bdrv_file_open         = iscsi_open,
902636
     .bdrv_close             = iscsi_close,
902636
+    .bdrv_co_create_opts    = bdrv_co_create_opts_simple,
902636
+    .create_opts            = &bdrv_create_opts_simple,
902636
     .bdrv_reopen_prepare    = iscsi_reopen_prepare,
902636
     .bdrv_reopen_commit     = iscsi_reopen_commit,
902636
     .bdrv_co_invalidate_cache = iscsi_co_invalidate_cache,
902636
@@ -2471,6 +2461,8 @@ static BlockDriver bdrv_iser = {
902636
     .bdrv_parse_filename    = iscsi_parse_filename,
902636
     .bdrv_file_open         = iscsi_open,
902636
     .bdrv_close             = iscsi_close,
902636
+    .bdrv_co_create_opts    = bdrv_co_create_opts_simple,
902636
+    .create_opts            = &bdrv_create_opts_simple,
902636
     .bdrv_reopen_prepare    = iscsi_reopen_prepare,
902636
     .bdrv_reopen_commit     = iscsi_reopen_commit,
902636
     .bdrv_co_invalidate_cache  = iscsi_co_invalidate_cache,
902636
diff --git a/block/nbd.c b/block/nbd.c
902636
index a73f0d9..927915d 100644
902636
--- a/block/nbd.c
902636
+++ b/block/nbd.c
902636
@@ -2030,6 +2030,8 @@ static BlockDriver bdrv_nbd = {
902636
     .protocol_name              = "nbd",
902636
     .instance_size              = sizeof(BDRVNBDState),
902636
     .bdrv_parse_filename        = nbd_parse_filename,
902636
+    .bdrv_co_create_opts        = bdrv_co_create_opts_simple,
902636
+    .create_opts                = &bdrv_create_opts_simple,
902636
     .bdrv_file_open             = nbd_open,
902636
     .bdrv_reopen_prepare        = nbd_client_reopen_prepare,
902636
     .bdrv_co_preadv             = nbd_client_co_preadv,
902636
@@ -2055,6 +2057,8 @@ static BlockDriver bdrv_nbd_tcp = {
902636
     .protocol_name              = "nbd+tcp",
902636
     .instance_size              = sizeof(BDRVNBDState),
902636
     .bdrv_parse_filename        = nbd_parse_filename,
902636
+    .bdrv_co_create_opts        = bdrv_co_create_opts_simple,
902636
+    .create_opts                = &bdrv_create_opts_simple,
902636
     .bdrv_file_open             = nbd_open,
902636
     .bdrv_reopen_prepare        = nbd_client_reopen_prepare,
902636
     .bdrv_co_preadv             = nbd_client_co_preadv,
902636
@@ -2080,6 +2084,8 @@ static BlockDriver bdrv_nbd_unix = {
902636
     .protocol_name              = "nbd+unix",
902636
     .instance_size              = sizeof(BDRVNBDState),
902636
     .bdrv_parse_filename        = nbd_parse_filename,
902636
+    .bdrv_co_create_opts        = bdrv_co_create_opts_simple,
902636
+    .create_opts                = &bdrv_create_opts_simple,
902636
     .bdrv_file_open             = nbd_open,
902636
     .bdrv_reopen_prepare        = nbd_client_reopen_prepare,
902636
     .bdrv_co_preadv             = nbd_client_co_preadv,
902636
diff --git a/block/nvme.c b/block/nvme.c
902636
index d41c4bd..7b7c0cc 100644
902636
--- a/block/nvme.c
902636
+++ b/block/nvme.c
902636
@@ -1333,6 +1333,9 @@ static BlockDriver bdrv_nvme = {
902636
     .protocol_name            = "nvme",
902636
     .instance_size            = sizeof(BDRVNVMeState),
902636
 
902636
+    .bdrv_co_create_opts      = bdrv_co_create_opts_simple,
902636
+    .create_opts              = &bdrv_create_opts_simple,
902636
+
902636
     .bdrv_parse_filename      = nvme_parse_filename,
902636
     .bdrv_file_open           = nvme_file_open,
902636
     .bdrv_close               = nvme_close,
902636
diff --git a/include/block/block.h b/include/block/block.h
902636
index 1df9848..92685d2 100644
902636
--- a/include/block/block.h
902636
+++ b/include/block/block.h
902636
@@ -293,6 +293,7 @@ BlockDriver *bdrv_find_format(const char *format_name);
902636
 int bdrv_create(BlockDriver *drv, const char* filename,
902636
                 QemuOpts *opts, Error **errp);
902636
 int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
902636
+
902636
 BlockDriverState *bdrv_new(void);
902636
 void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
902636
                  Error **errp);
902636
diff --git a/include/block/block_int.h b/include/block/block_int.h
902636
index 7ff81be..529f153 100644
902636
--- a/include/block/block_int.h
902636
+++ b/include/block/block_int.h
902636
@@ -1325,4 +1325,15 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset,
902636
 
902636
 int refresh_total_sectors(BlockDriverState *bs, int64_t hint);
902636
 
902636
+/**
902636
+ * Simple implementation of bdrv_co_create_opts for protocol drivers
902636
+ * which only support creation via opening a file
902636
+ * (usually existing raw storage device)
902636
+ */
902636
+int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
902636
+                                            const char *filename,
902636
+                                            QemuOpts *opts,
902636
+                                            Error **errp);
902636
+extern QemuOptsList bdrv_create_opts_simple;
902636
+
902636
 #endif /* BLOCK_INT_H */
902636
-- 
902636
1.8.3.1
902636