From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: jsnow@redhat.com, eblake@redhat.com, pkrempa@redhat.com,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 04/14] block/create: Make x-blockdev-create a job
Date: Tue, 29 May 2018 13:38:37 +0200 [thread overview]
Message-ID: <a8246b04-65e2-9169-69b5-fd57edcf1089@redhat.com> (raw)
In-Reply-To: <20180525163327.23097-5-kwolf@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 5007 bytes --]
On 2018-05-25 18:33, Kevin Wolf wrote:
> This changes the x-blockdev-create QMP command so that it doesn't block
> the monitor and the main loop any more, but starts a background job that
> performs the image creation.
>
> The basic job as implemented here is all that is necessary to make image
> creation asynchronous and to provide a QMP interface that can be marked
> stable, but it still lacks a few features that jobs usually provide: The
> job will ignore pause commands and it doesn't publish progress yet (so
> both current-progress and total-progress stay at 0). These features can
> be added later without breaking compatibility.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> qapi/block-core.json | 14 +++++++----
> qapi/job.json | 4 +++-
> block/create.c | 61 ++++++++++++++++++++++++++++++++----------------
> tests/qemu-iotests/group | 14 ++++++-----
> 4 files changed, 61 insertions(+), 32 deletions(-)
[...]
> diff --git a/block/create.c b/block/create.c
> index 8bd8a03719..87fdab3b72 100644
> --- a/block/create.c
> +++ b/block/create.c
> @@ -24,28 +24,49 @@
>
> #include "qemu/osdep.h"
> #include "block/block_int.h"
> +#include "qemu/job.h"
> #include "qapi/qapi-commands-block-core.h"
> +#include "qapi/qapi-visit-block-core.h"
> +#include "qapi/clone-visitor.h"
> #include "qapi/error.h"
>
> -typedef struct BlockdevCreateCo {
> +typedef struct BlockdevCreateJob {
> + Job common;
> BlockDriver *drv;
> BlockdevCreateOptions *opts;
> int ret;
> - Error **errp;
> -} BlockdevCreateCo;
> + Error *err;
> +} BlockdevCreateJob;
>
> -static void coroutine_fn bdrv_co_create_co_entry(void *opaque)
> +static void blockdev_create_complete(Job *job, void *opaque)
> {
> - BlockdevCreateCo *cco = opaque;
> - cco->ret = cco->drv->bdrv_co_create(cco->opts, cco->errp);
> + BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
> +
> + job_completed(job, s->ret, s->err);
> }
>
> -void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
> +static void coroutine_fn blockdev_create_run(void *opaque)
> {
> + BlockdevCreateJob *s = opaque;
> +
> + s->ret = s->drv->bdrv_co_create(s->opts, &s->err);
> +
> + qapi_free_BlockdevCreateOptions(s->opts);
> + job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL);
Better be safe than sorry, but probably not strictly necessary
considering the job is always run in the main loop anyway (more on that
below, though).
> +}
> +
> +static const JobDriver blockdev_create_job_driver = {
> + .instance_size = sizeof(BlockdevCreateJob),
> + .job_type = JOB_TYPE_CREATE,
> + .start = blockdev_create_run,
> +};
> +
> +void qmp_x_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
> + Error **errp)
> +{
> + BlockdevCreateJob *s;
> const char *fmt = BlockdevDriver_str(options->driver);
> BlockDriver *drv = bdrv_find_format(fmt);
> - Coroutine *co;
> - BlockdevCreateCo cco;
>
> /* If the driver is in the schema, we know that it exists. But it may not
> * be whitelisted. */
> @@ -61,16 +82,16 @@ void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
Minor note: The comment above this if () block reads:
/* Call callback if it exists */
Which is now no longer really what is happening. It just checks whether
the block driver supports blockdev-create.
> return;
> }
>
> - cco = (BlockdevCreateCo) {
> - .drv = drv,
> - .opts = options,
> - .ret = -EINPROGRESS,
> - .errp = errp,
> - };
> -
> - co = qemu_coroutine_create(bdrv_co_create_co_entry, &cco);
> - qemu_coroutine_enter(co);
> - while (cco.ret == -EINPROGRESS) {
> - aio_poll(qemu_get_aio_context(), true);
> + /* Create the block job */
> + s = job_create(job_id, &blockdev_create_job_driver, NULL,
> + qemu_get_aio_context(), JOB_DEFAULT | JOB_MANUAL_DISMISS,
Hmmm... The old code already used the main AIO context, but is that
correct? When you create a qcow2 node on top of a file node, shouldn't
you use the AIO context of the file node?
I see that figuring out the correct context generically may be difficult
to impossible, so OK, maybe we should just run image creation in the
main context for now. But then, qcow2 (and other formats) should at
least take a lock on their file's context, which they don't seem to do.
So I suppose I can give a
Reviewed-by: Max Reitz <mreitz@redhat.com>
for this patch, but I think some block drivers need some locking.
Max
> + NULL, NULL, errp);
> + if (!s) {
> + return;
> }
> +
> + s->drv = drv,
> + s->opts = QAPI_CLONE(BlockdevCreateOptions, options),
> +
> + job_start(&s->common);
> }
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2018-05-29 11:38 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-25 16:33 [Qemu-devel] [PATCH 00/14] block: Make blockdev-create a job and stable API Kevin Wolf
2018-05-25 16:33 ` [Qemu-devel] [PATCH 01/14] vdi: Fix vdi_co_do_create() return value Kevin Wolf
2018-05-29 10:38 ` Max Reitz
2018-05-29 14:45 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:33 ` [Qemu-devel] [PATCH 02/14] vhdx: Fix vhdx_co_create() " Kevin Wolf
2018-05-29 10:40 ` Max Reitz
2018-05-29 14:44 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:33 ` [Qemu-devel] [PATCH 03/14] job: Add error message for failing jobs Kevin Wolf
2018-05-29 11:01 ` Max Reitz
2018-05-29 14:43 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-29 19:54 ` Kevin Wolf
2018-05-25 16:33 ` [Qemu-devel] [PATCH 04/14] block/create: Make x-blockdev-create a job Kevin Wolf
2018-05-29 11:38 ` Max Reitz [this message]
2018-05-29 15:27 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-29 15:40 ` Kevin Wolf
2018-05-25 16:33 ` [Qemu-devel] [PATCH 05/14] qemu-iotests: Add VM.get_qmp_events_filtered() Kevin Wolf
2018-05-29 11:41 ` Max Reitz
2018-05-25 16:33 ` [Qemu-devel] [PATCH 06/14] qemu-iotests: Add VM.qmp_log() Kevin Wolf
2018-05-29 11:48 ` Max Reitz
2018-05-29 12:12 ` Kevin Wolf
2018-05-29 12:15 ` Max Reitz
2018-05-29 12:39 ` Kevin Wolf
2018-05-29 12:41 ` Max Reitz
2018-05-29 18:31 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:33 ` [Qemu-devel] [PATCH 07/14] qemu-iotests: Add iotests.img_info_log() Kevin Wolf
2018-05-29 11:56 ` Max Reitz
2018-05-25 16:33 ` [Qemu-devel] [PATCH 08/14] qemu-iotests: Rewrite 206 for blockdev-create job Kevin Wolf
2018-05-29 12:27 ` Max Reitz
2018-05-29 18:49 ` Kevin Wolf
2018-05-25 16:33 ` [Qemu-devel] [PATCH 09/14] qemu-iotests: Rewrite 207 " Kevin Wolf
2018-05-29 12:44 ` Max Reitz
2018-05-29 12:47 ` Max Reitz
2018-05-29 17:52 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:33 ` [Qemu-devel] [PATCH 10/14] qemu-iotests: Rewrite 210 " Kevin Wolf
2018-05-29 13:02 ` Max Reitz
2018-05-29 18:23 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:33 ` [Qemu-devel] [PATCH 11/14] qemu-iotests: Rewrite 211 " Kevin Wolf
2018-05-29 13:12 ` Max Reitz
2018-05-25 16:33 ` [Qemu-devel] [PATCH 12/14] qemu-iotests: Rewrite 212 " Kevin Wolf
2018-05-29 13:21 ` Max Reitz
2018-05-25 16:33 ` [Qemu-devel] [PATCH 13/14] qemu-iotests: Rewrite 213 " Kevin Wolf
2018-05-29 13:27 ` Max Reitz
2018-05-25 16:33 ` [Qemu-devel] [PATCH 14/14] block/create: Mark blockdev-create stable Kevin Wolf
2018-05-29 13:30 ` Max Reitz
2018-05-29 18:25 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2018-05-25 16:52 ` [Qemu-devel] [PATCH 00/14] block: Make blockdev-create a job and stable API no-reply
2018-05-25 18:13 ` Eric Blake
2018-05-28 8:42 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a8246b04-65e2-9169-69b5-fd57edcf1089@redhat.com \
--to=mreitz@redhat.com \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pkrempa@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).