From: Fam Zheng <famz@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 04/11] block: Support streaming to an intermediate layer
Date: Fri, 15 May 2015 10:33:19 +0800 [thread overview]
Message-ID: <20150515023319.GF28144@ad.nay.redhat.com> (raw)
In-Reply-To: <6957969aef43d7f379807c7646c7aeae3ce1d208.1431523498.git.berto@igalia.com>
On Wed, 05/13 16:27, Alberto Garcia wrote:
> This makes sure that the image we are steaming into is open in
> read-write mode during the operation.
>
> Operation blockers are also set in all intermediate nodes, since they
> will be removed from the chain afterwards.
>
> Finally, this also unblocks the stream operation in backing files.
>
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
> block.c | 4 +++-
> block/stream.c | 33 +++++++++++++++++++++++++++++++++
> 2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 7904098..8fab7e4 100644
> --- a/block.c
> +++ b/block.c
> @@ -1044,9 +1044,11 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
> backing_hd->drv ? backing_hd->drv->format_name : "");
>
> bdrv_op_block_all(bs->backing_hd, bs->backing_blocker);
> - /* Otherwise we won't be able to commit due to check in bdrv_commit */
> + /* Otherwise we won't be able to commit or stream */
> bdrv_op_unblock(bs->backing_hd, BLOCK_OP_TYPE_COMMIT_TARGET,
> bs->backing_blocker);
> + bdrv_op_unblock(bs->backing_hd, BLOCK_OP_TYPE_STREAM,
> + bs->backing_blocker);
> out:
> bdrv_refresh_limits(bs, NULL);
> }
> diff --git a/block/stream.c b/block/stream.c
> index 37bfd8b..8ba5a24 100644
> --- a/block/stream.c
> +++ b/block/stream.c
> @@ -33,6 +33,8 @@ typedef struct StreamBlockJob {
> BlockDriverState *base;
> BlockdevOnError on_error;
> char *backing_file_str;
> + int bs_flags;
> + Error *blocker;
> } StreamBlockJob;
>
> static int coroutine_fn stream_populate(BlockDriverState *bs,
> @@ -89,6 +91,13 @@ static void stream_complete(BlockJob *job, void *opaque)
> StreamBlockJob *s = container_of(job, StreamBlockJob, common);
> StreamCompleteData *data = opaque;
> BlockDriverState *base = s->base;
> + BlockDriverState *bs;
> +
> + /* Remove all blockers set in stream_start() */
> + for (bs = job->bs->backing_hd; bs && bs != s->base; bs = bs->backing_hd) {
> + bdrv_op_unblock_all(bs, s->blocker);
> + }
> + error_free(s->blocker);
>
> if (!block_job_is_cancelled(&s->common) && data->reached_end &&
> data->ret == 0) {
> @@ -103,6 +112,11 @@ static void stream_complete(BlockJob *job, void *opaque)
> close_unused_images(job->bs, base, base_id);
> }
>
> + /* Reopen the image back in read-only mode if necessary */
> + if (s->bs_flags != bdrv_get_flags(job->bs)) {
> + bdrv_reopen(job->bs, s->bs_flags, NULL);
> + }
> +
> g_free(s->backing_file_str);
> block_job_completed(&s->common, data->ret);
> g_free(data);
> @@ -246,7 +260,9 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
> BlockCompletionFunc *cb,
> void *opaque, Error **errp)
> {
> + BlockDriverState *iter;
> StreamBlockJob *s;
> + int orig_bs_flags;
>
> if ((on_error == BLOCKDEV_ON_ERROR_STOP ||
> on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
> @@ -255,13 +271,30 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
> return;
> }
>
> + /* Make sure that the image is opened in read-write mode */
> + orig_bs_flags = bdrv_get_flags(bs);
> + if (!(orig_bs_flags & BDRV_O_RDWR)) {
> + if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) {
I don't think all bdrv_reopen implementation will guarantee to set errp
on error :(. For example:
static int qcow2_reopen_prepare(BDRVReopenState *state,
BlockReopenQueue *queue, Error **errp)
{
int ret;
if ((state->flags & BDRV_O_RDWR) == 0) {
ret = bdrv_flush(state->bs);
if (ret < 0) {
return ret;
}
ret = qcow2_mark_clean(state->bs);
if (ret < 0) {
return ret;
}
}
return 0;
}
Maybe we should set one here so the user sees the failure?
Fam
> + return;
> + }
> + }
> +
> s = block_job_create(&stream_job_driver, bs, speed, cb, opaque, errp);
> if (!s) {
> return;
> }
>
> + /* Block all intermediate nodes between bs and base, because they
> + * will disappear from the chain after this operation */
> + error_setg(&s->blocker, "blocked by the block-stream operation in '%s'",
> + bdrv_get_device_or_node_name(bs));
> + for (iter = bs->backing_hd; iter && iter != base; iter = iter->backing_hd) {
> + bdrv_op_block_all(iter, s->blocker);
> + }
> +
> s->base = base;
> s->backing_file_str = g_strdup(backing_file_str);
> + s->bs_flags = orig_bs_flags;
>
> s->on_error = on_error;
> s->common.co = qemu_coroutine_create(stream_run);
> --
> 2.1.4
>
>
next prev parent reply other threads:[~2015-05-15 2:34 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 13:27 [Qemu-devel] [PATCH v7 00/11] Support streaming to an intermediate layer Alberto Garcia
2015-05-13 13:27 ` [Qemu-devel] [PATCH 01/11] block: keep a list of block jobs Alberto Garcia
2015-05-15 2:11 ` Fam Zheng
2015-05-18 16:39 ` Max Reitz
2015-05-13 13:27 ` [Qemu-devel] [PATCH 02/11] block: allow block jobs in any arbitrary node Alberto Garcia
2015-05-15 2:19 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 03/11] block: never cancel a streaming job without running stream_complete() Alberto Garcia
2015-05-15 2:23 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 04/11] block: Support streaming to an intermediate layer Alberto Garcia
2015-05-15 2:33 ` Fam Zheng [this message]
2015-05-15 9:04 ` Alberto Garcia
2015-05-15 9:14 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 05/11] block: Add QMP support for " Alberto Garcia
2015-05-15 2:38 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 06/11] docs: Document how to stream " Alberto Garcia
2015-05-15 2:42 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 07/11] qemu-iotests: fix test_stream_partial() Alberto Garcia
2015-05-15 2:43 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 08/11] qemu-iotests: add no-op streaming test Alberto Garcia
2015-05-15 2:44 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 09/11] qemu-iotests: test streaming to an intermediate layer Alberto Garcia
2015-05-15 2:45 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 10/11] qemu-iotests: test block-stream operations in parallel Alberto Garcia
2015-05-15 2:53 ` Fam Zheng
2015-05-13 13:27 ` [Qemu-devel] [PATCH 11/11] qemu-iotests: test overlapping block-stream operations Alberto Garcia
2015-05-15 2:56 ` Fam Zheng
2015-05-15 8:58 ` Alberto Garcia
2015-05-15 9:18 ` Fam Zheng
2015-06-16 8:51 ` [Qemu-devel] [PATCH v7 00/11] Support streaming to an intermediate layer Alberto Garcia
2015-06-18 10:45 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2015-06-18 11:41 ` Alberto Garcia
2015-06-18 11:47 ` Kevin Wolf
2015-06-18 12:07 ` Alberto Garcia
2015-06-18 12:36 ` Eric Blake
2015-06-18 12:55 ` Eric Blake
2015-06-19 10:09 ` Alberto Garcia
2015-06-22 16:17 ` [Qemu-devel] " Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2015-04-24 15:01 [Qemu-devel] [PATCH v6 " Alberto Garcia
2015-04-24 15:01 ` [Qemu-devel] [PATCH 04/11] block: " Alberto Garcia
2015-04-24 11:40 [Qemu-devel] [PATCH v5 00/11] " Alberto Garcia
2015-04-24 11:40 ` [Qemu-devel] [PATCH 04/11] block: " Alberto Garcia
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=20150515023319.GF28144@ad.nay.redhat.com \
--to=famz@redhat.com \
--cc=berto@igalia.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).