From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Jeff Cody <jcody@redhat.com>, Kevin Wolf <kwolf@redhat.com>,
Max Reitz <mreitz@redhat.com>,
qemu-block@nongnu.org, pbonzini@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH for-2.6 1/3] mirror: Extract mirror_replace
Date: Fri, 22 Apr 2016 14:35:05 +0800 [thread overview]
Message-ID: <1461306907-2837-2-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1461306907-2837-1-git-send-email-famz@redhat.com>
Move the BDS replacing code to a separate function so that it can be
used in the next patch. A new field "should_replace" is added and set to
true so the function is always called for now.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/mirror.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index d56e30e..6c3fe43 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -441,26 +441,20 @@ static void mirror_drain(MirrorBlockJob *s)
}
typedef struct {
+ bool should_replace;
int ret;
} MirrorExitData;
-static void mirror_exit(BlockJob *job, void *opaque)
+static void mirror_replace(MirrorBlockJob *s, int *ret)
{
- MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
- MirrorExitData *data = opaque;
AioContext *replace_aio_context = NULL;
- BlockDriverState *src = s->common.bs;
-
- /* Make sure that the source BDS doesn't go away before we called
- * block_job_completed(). */
- bdrv_ref(src);
if (s->to_replace) {
replace_aio_context = bdrv_get_aio_context(s->to_replace);
aio_context_acquire(replace_aio_context);
}
- if (s->should_complete && data->ret == 0) {
+ if (s->should_complete && *ret == 0) {
BlockDriverState *to_replace = s->common.bs;
if (s->to_replace) {
to_replace = s->to_replace;
@@ -470,7 +464,7 @@ static void mirror_exit(BlockJob *job, void *opaque)
* nodes could have been newly attached to a BlockBackend. */
if (to_replace->blk && s->target->blk) {
error_report("block job: Can't create node with two BlockBackends");
- data->ret = -EINVAL;
+ *ret = -EINVAL;
goto out;
}
@@ -481,14 +475,29 @@ static void mirror_exit(BlockJob *job, void *opaque)
}
out:
+ if (replace_aio_context) {
+ aio_context_release(replace_aio_context);
+ }
+}
+
+static void mirror_exit(BlockJob *job, void *opaque)
+{
+ MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
+ MirrorExitData *data = opaque;
+ BlockDriverState *src = s->common.bs;
+
+ /* Make sure that the source BDS doesn't go away before we called
+ * block_job_completed(). */
+ bdrv_ref(src);
+
+ if (data->should_replace) {
+ mirror_replace(s, &data->ret);
+ }
if (s->to_replace) {
bdrv_op_unblock_all(s->to_replace, s->replace_blocker);
error_free(s->replace_blocker);
bdrv_unref(s->to_replace);
}
- if (replace_aio_context) {
- aio_context_release(replace_aio_context);
- }
g_free(s->replaces);
bdrv_op_unblock_all(s->target, s->common.blocker);
bdrv_unref(s->target);
@@ -713,6 +722,7 @@ immediate_exit:
data = g_malloc(sizeof(*data));
data->ret = ret;
+ data->should_replace = true;
/* Before we switch to target in mirror_exit, make sure data doesn't
* change. */
bdrv_drained_begin(s->common.bs);
--
2.8.0
next prev parent reply other threads:[~2016-04-22 6:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-22 6:35 [Qemu-devel] [PATCH for-2.6 0/3] block: Fix assertion failure at mirror exit Fam Zheng
2016-04-22 6:35 ` Fam Zheng [this message]
2016-04-22 6:35 ` [Qemu-devel] [PATCH for-2.6 2/3] mirror: Skip BH for mirror_exit if in main loop Fam Zheng
2016-04-22 9:37 ` Fam Zheng
2016-04-22 6:35 ` [Qemu-devel] [PATCH for-2.6 3/3] block: Update comment of bdrv_drained_begin Fam Zheng
2016-04-22 6:46 ` [Qemu-devel] [PATCH for-2.6 0/3] block: Fix assertion failure at mirror exit Fam Zheng
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=1461306907-2837-2-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).