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

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