From patchwork Tue Jan 26 10:38:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8120011 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C516F9F818 for ; Tue, 26 Jan 2016 10:40:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1DF7120166 for ; Tue, 26 Jan 2016 10:40:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 54DFB20145 for ; Tue, 26 Jan 2016 10:40:01 +0000 (UTC) Received: from localhost ([::1]:42904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO12W-00068w-M6 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jan 2016 05:40:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO12I-00063d-EH for qemu-devel@nongnu.org; Tue, 26 Jan 2016 05:39:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aO12H-0007Rw-CI for qemu-devel@nongnu.org; Tue, 26 Jan 2016 05:39:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60473) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO12C-0007Qz-Ru; Tue, 26 Jan 2016 05:39:41 -0500 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 (Postfix) with ESMTPS id 743208F2F2; Tue, 26 Jan 2016 10:39:40 +0000 (UTC) Received: from fam-t430.redhat.com (vpn1-5-65.pek2.redhat.com [10.72.5.65]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0QAcRTI016464; Tue, 26 Jan 2016 05:39:31 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 26 Jan 2016 18:38:16 +0800 Message-Id: <1453804705-7205-8-git-send-email-famz@redhat.com> In-Reply-To: <1453804705-7205-1-git-send-email-famz@redhat.com> References: <1453804705-7205-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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, jsnow@redhat.com, Markus Armbruster , mreitz@redhat.com, vsementsov@parallels.com, Stefan Hajnoczi Subject: [Qemu-devel] [RFC PATCH 07/16] block: Only swap non-persistent dirty bitmaps 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Persistent dirty bitmaps are special because they're tightly associated with, or even belonging to the driver, swapping them doesn't make much sense. Because this has nothing to do with backward compatibility, it's okay to just let them stay with the old BDS. Signed-off-by: Fam Zheng --- block.c | 11 +++++------ block/dirty-bitmap.c | 25 +++++++++++++++++++++++++ include/block/dirty-bitmap.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 78db342..3a29de2 100644 --- a/block.c +++ b/block.c @@ -2274,9 +2274,6 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest, bs_dest->copy_on_read = bs_src->copy_on_read; bs_dest->enable_write_cache = bs_src->enable_write_cache; - - /* dirty bitmap */ - bs_dest->dirty_bitmaps = bs_src->dirty_bitmaps; } static void change_parent_backing_link(BlockDriverState *from, @@ -2302,10 +2299,12 @@ static void change_parent_backing_link(BlockDriverState *from, } static void swap_feature_fields(BlockDriverState *bs_top, - BlockDriverState *bs_new) + BlockDriverState *bs_new, + Error **errp) { BlockDriverState tmp; + bdrv_dirty_bitmap_swap(bs_top, bs_new); bdrv_move_feature_fields(&tmp, bs_top); bdrv_move_feature_fields(bs_top, bs_new); bdrv_move_feature_fields(bs_new, &tmp); @@ -2343,7 +2342,7 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) change_parent_backing_link(bs_top, bs_new); /* Some fields always stay on top of the backing file chain */ - swap_feature_fields(bs_top, bs_new); + swap_feature_fields(bs_top, bs_new, NULL); bdrv_set_backing_hd(bs_new, bs_top); bdrv_unref(bs_top); @@ -2368,7 +2367,7 @@ void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new) * swap instead so that pointers aren't duplicated and cause trouble. * (Also, bdrv_swap() used to do the same.) */ assert(!new->blk); - swap_feature_fields(old, new); + swap_feature_fields(old, new, NULL); } change_parent_backing_link(old, new); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 882a0db..a3a401f 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -65,6 +65,31 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name) return NULL; } +/* Swap non-persistent dirty bitmaps. */ +void bdrv_dirty_bitmap_swap(BlockDriverState *bs1, BlockDriverState *bs2) +{ + BdrvDirtyBitmap *bm, *next; + QLIST_HEAD(, BdrvDirtyBitmap) tmp = QLIST_HEAD_INITIALIZER(&tmp); + + QLIST_FOREACH_SAFE(bm, &bs1->dirty_bitmaps, list, next) { + if (bm->persistent) { + continue; + } + QLIST_REMOVE(bm, list); + QLIST_INSERT_HEAD(&tmp, bm, list); + } + QLIST_FOREACH_SAFE(bm, &bs2->dirty_bitmaps, list, next) { + if (bm->persistent) { + continue; + } + QLIST_REMOVE(bm, list); + QLIST_INSERT_HEAD(&bs1->dirty_bitmaps, bm, list); + } + QLIST_FOREACH_SAFE(bm, &tmp, list, next) { + QLIST_INSERT_HEAD(&bs2->dirty_bitmaps, bm, list); + } +} + void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 5885720..a4de9c7 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -23,6 +23,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, Error **errp); BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name); +void bdrv_dirty_bitmap_swap(BlockDriverState *bs1, BlockDriverState *bs2); void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs, BdrvDirtyBitmap *bitmap,