yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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