From patchwork Mon Sep 30 12:02:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 279137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4FDC72C0091 for ; Mon, 30 Sep 2013 22:05:15 +1000 (EST) Received: from localhost ([::1]:48461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQcDx-0003GT-Bk for incoming@patchwork.ozlabs.org; Mon, 30 Sep 2013 08:05:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQcC7-0000sy-T3 for qemu-devel@nongnu.org; Mon, 30 Sep 2013 08:03:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VQcBz-0005mv-JW for qemu-devel@nongnu.org; Mon, 30 Sep 2013 08:03:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40973) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQcBz-0005mp-Bl for qemu-devel@nongnu.org; Mon, 30 Sep 2013 08:03:11 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8UC3AUT012236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 30 Sep 2013 08:03:10 -0400 Received: from T430s.nay.redhat.com (vpn1-7-166.sin2.redhat.com [10.67.7.166]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8UC2xs2001174; Mon, 30 Sep 2013 08:03:07 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 30 Sep 2013 20:02:53 +0800 Message-Id: <1380542578-2387-3-git-send-email-famz@redhat.com> In-Reply-To: <1380542578-2387-1-git-send-email-famz@redhat.com> References: <1380542578-2387-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 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 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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