|
|
357786 |
From 15606cc179623a45cc36fd3a769897678083e804 Mon Sep 17 00:00:00 2001
|
|
|
357786 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Date: Tue, 26 Jun 2018 09:48:40 +0200
|
|
|
357786 |
Subject: [PATCH 71/89] block/create: Make x-blockdev-create a job
|
|
|
357786 |
|
|
|
357786 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Message-id: <20180626094856.6924-58-kwolf@redhat.com>
|
|
|
357786 |
Patchwork-id: 81066
|
|
|
357786 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 57/73] block/create: Make x-blockdev-create a job
|
|
|
357786 |
Bugzilla: 1513543
|
|
|
357786 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
357786 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
357786 |
|
|
|
357786 |
This changes the x-blockdev-create QMP command so that it doesn't block
|
|
|
357786 |
the monitor and the main loop any more, but starts a background job that
|
|
|
357786 |
performs the image creation.
|
|
|
357786 |
|
|
|
357786 |
The basic job as implemented here is all that is necessary to make image
|
|
|
357786 |
creation asynchronous and to provide a QMP interface that can be marked
|
|
|
357786 |
stable, but it still lacks a few features that jobs usually provide: The
|
|
|
357786 |
job will ignore pause commands and it doesn't publish more than very
|
|
|
357786 |
basic progress yet (total-progress is 1 and current-progress advances
|
|
|
357786 |
from 0 to 1 when the driver callbacks returns). These features can be
|
|
|
357786 |
added later without breaking compatibility.
|
|
|
357786 |
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Reviewed-by: Max Reitz <mreitz@redhat.com>
|
|
|
357786 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
357786 |
(cherry picked from commit e5ab4347f9f53495e31fcef5e232c7c6be4a0567)
|
|
|
357786 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
357786 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
357786 |
---
|
|
|
357786 |
block/create.c | 67 +++++++++++++++++++++++++++++++++---------------
|
|
|
357786 |
qapi/block-core.json | 14 ++++++----
|
|
|
357786 |
qapi/job.json | 4 ++-
|
|
|
357786 |
tests/qemu-iotests/group | 14 +++++-----
|
|
|
357786 |
4 files changed, 66 insertions(+), 33 deletions(-)
|
|
|
357786 |
|
|
|
357786 |
diff --git a/block/create.c b/block/create.c
|
|
|
357786 |
index 8bd8a03..1a263e4 100644
|
|
|
357786 |
--- a/block/create.c
|
|
|
357786 |
+++ b/block/create.c
|
|
|
357786 |
@@ -24,28 +24,51 @@
|
|
|
357786 |
|
|
|
357786 |
#include "qemu/osdep.h"
|
|
|
357786 |
#include "block/block_int.h"
|
|
|
357786 |
+#include "qemu/job.h"
|
|
|
357786 |
#include "qapi/qapi-commands-block-core.h"
|
|
|
357786 |
+#include "qapi/qapi-visit-block-core.h"
|
|
|
357786 |
+#include "qapi/clone-visitor.h"
|
|
|
357786 |
#include "qapi/error.h"
|
|
|
357786 |
|
|
|
357786 |
-typedef struct BlockdevCreateCo {
|
|
|
357786 |
+typedef struct BlockdevCreateJob {
|
|
|
357786 |
+ Job common;
|
|
|
357786 |
BlockDriver *drv;
|
|
|
357786 |
BlockdevCreateOptions *opts;
|
|
|
357786 |
int ret;
|
|
|
357786 |
- Error **errp;
|
|
|
357786 |
-} BlockdevCreateCo;
|
|
|
357786 |
+ Error *err;
|
|
|
357786 |
+} BlockdevCreateJob;
|
|
|
357786 |
|
|
|
357786 |
-static void coroutine_fn bdrv_co_create_co_entry(void *opaque)
|
|
|
357786 |
+static void blockdev_create_complete(Job *job, void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
- BlockdevCreateCo *cco = opaque;
|
|
|
357786 |
- cco->ret = cco->drv->bdrv_co_create(cco->opts, cco->errp);
|
|
|
357786 |
+ BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
|
|
|
357786 |
+
|
|
|
357786 |
+ job_completed(job, s->ret, s->err);
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
-void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
|
|
|
357786 |
+static void coroutine_fn blockdev_create_run(void *opaque)
|
|
|
357786 |
{
|
|
|
357786 |
+ BlockdevCreateJob *s = opaque;
|
|
|
357786 |
+
|
|
|
357786 |
+ job_progress_set_remaining(&s->common, 1);
|
|
|
357786 |
+ s->ret = s->drv->bdrv_co_create(s->opts, &s->err);
|
|
|
357786 |
+ job_progress_update(&s->common, 1);
|
|
|
357786 |
+
|
|
|
357786 |
+ qapi_free_BlockdevCreateOptions(s->opts);
|
|
|
357786 |
+ job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL);
|
|
|
357786 |
+}
|
|
|
357786 |
+
|
|
|
357786 |
+static const JobDriver blockdev_create_job_driver = {
|
|
|
357786 |
+ .instance_size = sizeof(BlockdevCreateJob),
|
|
|
357786 |
+ .job_type = JOB_TYPE_CREATE,
|
|
|
357786 |
+ .start = blockdev_create_run,
|
|
|
357786 |
+};
|
|
|
357786 |
+
|
|
|
357786 |
+void qmp_x_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
|
|
|
357786 |
+ Error **errp)
|
|
|
357786 |
+{
|
|
|
357786 |
+ BlockdevCreateJob *s;
|
|
|
357786 |
const char *fmt = BlockdevDriver_str(options->driver);
|
|
|
357786 |
BlockDriver *drv = bdrv_find_format(fmt);
|
|
|
357786 |
- Coroutine *co;
|
|
|
357786 |
- BlockdevCreateCo cco;
|
|
|
357786 |
|
|
|
357786 |
/* If the driver is in the schema, we know that it exists. But it may not
|
|
|
357786 |
* be whitelisted. */
|
|
|
357786 |
@@ -55,22 +78,24 @@ void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- /* Call callback if it exists */
|
|
|
357786 |
+ /* Error out if the driver doesn't support .bdrv_co_create */
|
|
|
357786 |
if (!drv->bdrv_co_create) {
|
|
|
357786 |
error_setg(errp, "Driver does not support blockdev-create");
|
|
|
357786 |
return;
|
|
|
357786 |
}
|
|
|
357786 |
|
|
|
357786 |
- cco = (BlockdevCreateCo) {
|
|
|
357786 |
- .drv = drv,
|
|
|
357786 |
- .opts = options,
|
|
|
357786 |
- .ret = -EINPROGRESS,
|
|
|
357786 |
- .errp = errp,
|
|
|
357786 |
- };
|
|
|
357786 |
-
|
|
|
357786 |
- co = qemu_coroutine_create(bdrv_co_create_co_entry, &cco;;
|
|
|
357786 |
- qemu_coroutine_enter(co);
|
|
|
357786 |
- while (cco.ret == -EINPROGRESS) {
|
|
|
357786 |
- aio_poll(qemu_get_aio_context(), true);
|
|
|
357786 |
+ /* Create the block job */
|
|
|
357786 |
+ /* TODO Running in the main context. Block drivers need to error out or add
|
|
|
357786 |
+ * locking when they use a BDS in a different AioContext. */
|
|
|
357786 |
+ s = job_create(job_id, &blockdev_create_job_driver, NULL,
|
|
|
357786 |
+ qemu_get_aio_context(), JOB_DEFAULT | JOB_MANUAL_DISMISS,
|
|
|
357786 |
+ NULL, NULL, errp);
|
|
|
357786 |
+ if (!s) {
|
|
|
357786 |
+ return;
|
|
|
357786 |
}
|
|
|
357786 |
+
|
|
|
357786 |
+ s->drv = drv,
|
|
|
357786 |
+ s->opts = QAPI_CLONE(BlockdevCreateOptions, options),
|
|
|
357786 |
+
|
|
|
357786 |
+ job_start(&s->common);
|
|
|
357786 |
}
|
|
|
357786 |
diff --git a/qapi/block-core.json b/qapi/block-core.json
|
|
|
357786 |
index 67e613a..d22d1db 100644
|
|
|
357786 |
--- a/qapi/block-core.json
|
|
|
357786 |
+++ b/qapi/block-core.json
|
|
|
357786 |
@@ -4027,14 +4027,18 @@
|
|
|
357786 |
##
|
|
|
357786 |
# @x-blockdev-create:
|
|
|
357786 |
#
|
|
|
357786 |
-# Create an image format on a given node.
|
|
|
357786 |
-# TODO Replace with something asynchronous (block job?)
|
|
|
357786 |
+# Starts a job to create an image format on a given node. The job is
|
|
|
357786 |
+# automatically finalized, but a manual job-dismiss is required.
|
|
|
357786 |
#
|
|
|
357786 |
-# Since: 2.12
|
|
|
357786 |
+# @job-id: Identifier for the newly created job.
|
|
|
357786 |
+#
|
|
|
357786 |
+# @options: Options for the image creation.
|
|
|
357786 |
+#
|
|
|
357786 |
+# Since: 3.0
|
|
|
357786 |
##
|
|
|
357786 |
{ 'command': 'x-blockdev-create',
|
|
|
357786 |
- 'data': 'BlockdevCreateOptions',
|
|
|
357786 |
- 'boxed': true }
|
|
|
357786 |
+ 'data': { 'job-id': 'str',
|
|
|
357786 |
+ 'options': 'BlockdevCreateOptions' } }
|
|
|
357786 |
|
|
|
357786 |
##
|
|
|
357786 |
# @blockdev-open-tray:
|
|
|
357786 |
diff --git a/qapi/job.json b/qapi/job.json
|
|
|
357786 |
index 970124d..69c1970 100644
|
|
|
357786 |
--- a/qapi/job.json
|
|
|
357786 |
+++ b/qapi/job.json
|
|
|
357786 |
@@ -17,10 +17,12 @@
|
|
|
357786 |
#
|
|
|
357786 |
# @backup: drive backup job type, see "drive-backup"
|
|
|
357786 |
#
|
|
|
357786 |
+# @create: image creation job type, see "x-blockdev-create" (since 3.0)
|
|
|
357786 |
+#
|
|
|
357786 |
# Since: 1.7
|
|
|
357786 |
##
|
|
|
357786 |
{ 'enum': 'JobType',
|
|
|
357786 |
- 'data': ['commit', 'stream', 'mirror', 'backup'] }
|
|
|
357786 |
+ 'data': ['commit', 'stream', 'mirror', 'backup', 'create'] }
|
|
|
357786 |
|
|
|
357786 |
##
|
|
|
357786 |
# @JobStatus:
|
|
|
357786 |
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
|
|
|
357786 |
index 5c55adc..37ec5f1 100644
|
|
|
357786 |
--- a/tests/qemu-iotests/group
|
|
|
357786 |
+++ b/tests/qemu-iotests/group
|
|
|
357786 |
@@ -204,14 +204,16 @@
|
|
|
357786 |
203 rw auto
|
|
|
357786 |
204 rw auto quick
|
|
|
357786 |
205 rw auto quick
|
|
|
357786 |
-206 rw auto
|
|
|
357786 |
-207 rw auto
|
|
|
357786 |
+# TODO The following commented out tests need to be reworked to work
|
|
|
357786 |
+# with the x-blockdev-create job
|
|
|
357786 |
+#206 rw auto
|
|
|
357786 |
+#207 rw auto
|
|
|
357786 |
208 rw auto quick
|
|
|
357786 |
209 rw auto quick
|
|
|
357786 |
-210 rw auto
|
|
|
357786 |
-211 rw auto quick
|
|
|
357786 |
-212 rw auto quick
|
|
|
357786 |
-213 rw auto quick
|
|
|
357786 |
+#210 rw auto
|
|
|
357786 |
+#211 rw auto quick
|
|
|
357786 |
+#212 rw auto quick
|
|
|
357786 |
+#213 rw auto quick
|
|
|
357786 |
214 rw auto
|
|
|
357786 |
215 rw auto quick
|
|
|
357786 |
216 rw auto quick
|
|
|
357786 |
--
|
|
|
357786 |
1.8.3.1
|
|
|
357786 |
|