From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH v3 11/16] mirror: implement completion
Date: Thu, 18 Oct 2012 16:49:25 +0200 [thread overview]
Message-ID: <1350571770-9836-12-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1350571770-9836-1-git-send-email-pbonzini@redhat.com>
Switching to the target of the migration is done mostly asynchronously,
and reported to management via the BLOCK_JOB_COMPLETED event; the only
synchronous phase is opening the backing files. bdrv_open_backing_file
can always be done, even for migration of the full image (aka sync:
'full'). In this case, qmp_drive_mirror will create the target disk
with no backing file at all, and bdrv_open_backing_file will be a no-op.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
v2->v3: complete member renamed to should_complete,
added bdrv_reopen
block/mirror.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
1 file modificato, 40 inserzioni(+), 5 rimozioni(-)
diff --git a/block/mirror.c b/block/mirror.c
index b353798..6320f6a 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -32,6 +32,8 @@ typedef struct MirrorBlockJob {
RateLimit limit;
BlockDriverState *target;
MirrorSyncMode mode;
+ bool synced;
+ bool should_complete;
int64_t sector_num;
uint8_t *buf;
} MirrorBlockJob;
@@ -70,7 +72,6 @@ static void coroutine_fn mirror_run(void *opaque)
int64_t sector_num, end;
int ret = 0;
int n;
- bool synced = false;
if (block_job_is_cancelled(&s->common)) {
goto immediate_exit;
@@ -136,9 +137,14 @@ static void coroutine_fn mirror_run(void *opaque)
* report completion. This way, block-job-cancel will leave
* the target in a consistent state.
*/
- synced = true;
s->common.offset = end * BDRV_SECTOR_SIZE;
- should_complete = block_job_is_cancelled(&s->common);
+ if (!s->synced) {
+ block_job_ready(&s->common);
+ s->synced = true;
+ }
+
+ should_complete = s->should_complete ||
+ block_job_is_cancelled(&s->common);
cnt = bdrv_get_dirty_count(bs);
}
@@ -157,8 +163,8 @@ static void coroutine_fn mirror_run(void *opaque)
}
ret = 0;
- trace_mirror_before_sleep(s, cnt, synced);
- if (!synced) {
+ trace_mirror_before_sleep(s, cnt, s->synced);
+ if (!s->synced) {
/* Publish progress */
s->common.offset = end * BDRV_SECTOR_SIZE - cnt * BLOCK_SIZE;
@@ -191,6 +197,12 @@ static void coroutine_fn mirror_run(void *opaque)
immediate_exit:
g_free(s->buf);
bdrv_set_dirty_tracking(bs, false);
+ if (s->should_complete && ret == 0) {
+ if (bdrv_get_flags(s->target) != bdrv_get_flags(s->common.bs)) {
+ bdrv_reopen(s->target, bdrv_get_flags(s->common.bs), NULL);
+ }
+ bdrv_swap(s->target, s->common.bs);
+ }
bdrv_close(s->target);
bdrv_delete(s->target);
block_job_completed(&s->common, ret);
@@ -207,10 +219,33 @@ static void mirror_set_speed(BlockJob *job, int64_t speed, Error **errp)
ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME);
}
+static void mirror_complete(BlockJob *job, Error **errp)
+{
+ MirrorBlockJob *s = container_of(job, MirrorBlockJob, common);
+ int ret;
+
+ ret = bdrv_open_backing_file(s->target);
+ if (ret < 0) {
+ char backing_filename[PATH_MAX];
+ bdrv_get_full_backing_filename(s->target, backing_filename,
+ sizeof(backing_filename));
+ error_set(errp, QERR_OPEN_FILE_FAILED, backing_filename);
+ return;
+ }
+ if (!s->synced) {
+ error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name);
+ return;
+ }
+
+ s->should_complete = true;
+ block_job_resume(job);
+}
+
static BlockJobType mirror_job_type = {
.instance_size = sizeof(MirrorBlockJob),
.job_type = "mirror",
.set_speed = mirror_set_speed,
+ .complete = mirror_complete,
};
void mirror_start(BlockDriverState *bs, BlockDriverState *target,
--
1.7.12.1
next prev parent reply other threads:[~2012-10-18 14:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-18 14:49 [Qemu-devel] [PULL for Kevin 00/16] Block job improvements part 2 Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 01/16] block: add bdrv_query_info Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 02/16] block: add bdrv_query_stats Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 03/16] block: add bdrv_open_backing_file Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 04/16] block: introduce new dirty bitmap functionality Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 05/16] block: export dirty bitmap information in query-block Paolo Bonzini
2012-10-18 16:51 ` Eric Blake
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 06/16] block: rename block_job_complete to block_job_completed Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 07/16] block: add block-job-complete Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 08/16] block: introduce BLOCK_JOB_READY event Paolo Bonzini
2012-10-18 16:58 ` Eric Blake
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 09/16] mirror: introduce mirror job Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 10/16] qmp: add drive-mirror command Paolo Bonzini
2012-10-18 17:34 ` Eric Blake
2012-10-19 12:54 ` Kevin Wolf
2012-10-19 13:13 ` Paolo Bonzini
2012-10-18 14:49 ` Paolo Bonzini [this message]
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 12/16] qemu-iotests: add mirroring test case Paolo Bonzini
2012-10-19 16:19 ` Kevin Wolf
2012-10-20 13:47 ` Paolo Bonzini
2012-10-22 8:44 ` Kevin Wolf
2012-10-22 15:38 ` Paolo Bonzini
2012-10-23 14:39 ` [Qemu-devel] [PATCH v4 " Paolo Bonzini
2012-10-23 14:39 ` [Qemu-devel] [PATCH v4 16/16] qemu-iotests: add testcases for mirroring on-source-error/on-target-error Paolo Bonzini
2012-10-19 17:24 ` [Qemu-devel] [PATCH v3 12/16] qemu-iotests: add mirroring test case Kevin Wolf
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 13/16] iostatus: forward block_job_iostatus_reset to block job Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 14/16] mirror: add support for on-source-error/on-target-error Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 15/16] qmp: add pull_event function Paolo Bonzini
2012-10-18 14:49 ` [Qemu-devel] [PATCH v3 16/16] qemu-iotests: add testcases for mirroring on-source-error/on-target-error Paolo Bonzini
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=1350571770-9836-12-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.com \
--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).