From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, jcody@redhat.com,
famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH v4 2/7] qmp: add internal sync mode "common" to mirror_start
Date: Mon, 30 Sep 2013 20:02:53 +0800 [thread overview]
Message-ID: <1380542578-2387-3-git-send-email-famz@redhat.com> (raw)
In-Reply-To: <1380542578-2387-1-git-send-email-famz@redhat.com>
This adds a new sync mode "common" which only copies data that is above
the common ancestor of source and target. In general, this could be useful
in cases like:
base_bs ---> common_ancestor ---> foo ---> bar --->source
\
\---> target
Where data in foo, bar and source will be copied to target, once such
common backing_hd sharing is introduced. For now, we could use a special
case: If target is the ancestor of source, like,
base_bs ---> target ---> foo ---> bar --->source
The data in foo, bar and source will be copied to target, like
drive-commit, and when they are synced, the source bs replaces target
bs. This is specifically useful for block commit of active layer.
This mode is not available (-ENOTSUP) from QMP interface, it is only
used internally by block commit code.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/mirror.c | 16 ++++++++++++++--
blockdev.c | 5 +++++
qapi-schema.json | 2 +-
tests/qemu-iotests/041 | 5 +++++
tests/qemu-iotests/041.out | 4 ++--
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index 6e7a274..fdc7fa8 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -31,6 +31,7 @@ typedef struct MirrorBlockJob {
BlockJob common;
RateLimit limit;
BlockDriverState *target;
+ BlockDriverState *base;
MirrorSyncMode mode;
BlockdevOnError on_source_error, on_target_error;
bool synced;
@@ -334,8 +335,7 @@ static void coroutine_fn mirror_run(void *opaque)
if (s->mode != MIRROR_SYNC_MODE_NONE) {
/* First part, loop on the sectors and initialize the dirty bitmap. */
- BlockDriverState *base;
- base = s->mode == MIRROR_SYNC_MODE_FULL ? NULL : bs->backing_hd;
+ BlockDriverState *base = s->base;
for (sector_num = 0; sector_num < end; ) {
int64_t next = (sector_num | (sectors_per_chunk - 1)) + 1;
ret = bdrv_is_allocated_above(bs, base,
@@ -541,6 +541,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
void *opaque, Error **errp)
{
MirrorBlockJob *s;
+ BlockDriverState *base = NULL;
if (granularity == 0) {
/* Choose the default granularity based on the target file's cluster
@@ -563,6 +564,16 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
return;
}
+ if (mode == MIRROR_SYNC_MODE_COMMON) {
+ base = bdrv_common_ancestor(bs, target);
+ if (!base) {
+ error_setg(errp, "source and target has no common ancestor");
+ return;
+ }
+ } else if (mode == MIRROR_SYNC_MODE_TOP) {
+ base = bs->backing_hd;
+ }
+
s = block_job_create(&mirror_job_type, bs, speed, cb, opaque, errp);
if (!s) {
return;
@@ -572,6 +583,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
s->on_target_error = on_target_error;
s->target = target;
s->mode = mode;
+ s->base = base;
s->granularity = granularity;
s->buf_size = MAX(buf_size, granularity);
diff --git a/blockdev.c b/blockdev.c
index 8aa66a9..3acd330 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1906,6 +1906,11 @@ void qmp_drive_mirror(const char *device, const char *target,
return;
}
+ if (sync == MIRROR_SYNC_MODE_COMMON) {
+ error_set(errp, QERR_UNSUPPORTED);
+ return;
+ }
+
flags = bs->open_flags | BDRV_O_RDWR;
source = bs->backing_hd;
if (!source && sync == MIRROR_SYNC_MODE_TOP) {
diff --git a/qapi-schema.json b/qapi-schema.json
index 145eca8..6addf49 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1363,7 +1363,7 @@
# Since: 1.3
##
{ 'enum': 'MirrorSyncMode',
- 'data': ['top', 'full', 'none'] }
+ 'data': ['top', 'full', 'none', 'common'] }
##
# @BlockJobInfo:
diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index 6661c03..86b3251 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -206,6 +206,11 @@ class TestSingleDrive(ImageMirroringTestCase):
target=target_img)
self.assert_qmp(result, 'error/class', 'DeviceNotFound')
+ def test_common(self):
+ result = self.vm.qmp('drive-mirror', device='drive0', sync='common',
+ target=target_img)
+ self.assert_qmp(result, 'error/class', 'GenericError')
+
class TestMirrorNoBacking(ImageMirroringTestCase):
image_len = 2 * 1024 * 1024 # MB
diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out
index 42314e9..4fd1c2d 100644
--- a/tests/qemu-iotests/041.out
+++ b/tests/qemu-iotests/041.out
@@ -1,5 +1,5 @@
-........................
+.........................
----------------------------------------------------------------------
-Ran 24 tests
+Ran 25 tests
OK
--
1.8.3.1
next prev parent reply other threads:[~2013-09-30 12:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-30 12:02 [Qemu-devel] [PATCH v4 0/7] block: allow commit active as top Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 1/7] block: add bdrv_common_ancestor() Fam Zheng
2013-09-30 21:40 ` Eric Blake
2013-09-30 12:02 ` Fam Zheng [this message]
2013-09-30 14:49 ` [Qemu-devel] [PATCH v4 2/7] qmp: add internal sync mode "common" to mirror_start Eric Blake
2013-10-08 8:08 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 3/7] mirror: don't close target Fam Zheng
2013-10-01 17:11 ` Eric Blake
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 4/7] mirror: Add commit_job_type to perform commit with mirror code Fam Zheng
2013-10-01 17:13 ` Eric Blake
2013-10-08 8:37 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 5/7] commit: support commit active layer Fam Zheng
2013-09-30 12:16 ` Paolo Bonzini
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 6/7] commit: remove unused check Fam Zheng
2013-09-30 12:17 ` Paolo Bonzini
2013-10-08 9:32 ` Fam Zheng
2013-09-30 12:02 ` [Qemu-devel] [PATCH v4 7/7] qemu-iotests: update test cases for commit active 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=1380542578-2387-3-git-send-email-famz@redhat.com \
--to=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--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).