From patchwork Mon Aug 8 15:05:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 9268549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9CF1F60754 for ; Mon, 8 Aug 2016 15:14:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F2DC26D17 for ; Mon, 8 Aug 2016 15:14:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82A9B283F8; Mon, 8 Aug 2016 15:14:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 1E1B326D17 for ; Mon, 8 Aug 2016 15:14:53 +0000 (UTC) Received: from localhost ([::1]:58025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWmGS-0007Io-5q for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Aug 2016 11:14:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWm7T-00070R-Vt for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWm7Q-0004Sh-5V for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:35 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:35681 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWm7P-0004PZ-LG for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:31 -0400 Received: from kvm.qa.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u77NfZcR001857; Mon, 8 Aug 2016 02:41:38 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 8 Aug 2016 18:05:06 +0300 Message-Id: <1470668720-211300-16-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1470668720-211300-1-git-send-email-vsementsov@virtuozzo.com> References: <1470668720-211300-1-git-send-email-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 15/29] block/dirty-bitmap: introduce persistent bitmaps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add field 'persistent' to BdrvDirtyBitmap. Store all persistent bitmaps of the BDS in bdrv_close(). Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 2 ++ block/dirty-bitmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/block/dirty-bitmap.h | 5 +++++ 3 files changed, 49 insertions(+) diff --git a/block.c b/block.c index 30d64e6..fdef1b2 100644 --- a/block.c +++ b/block.c @@ -2155,6 +2155,8 @@ static void bdrv_close(BlockDriverState *bs) bdrv_flush(bs); bdrv_drain(bs); /* in case flush left pending I/O */ + /* save and release persistent dirty bitmaps */ + bdrv_finalize_persistent_dirty_bitmaps(bs); bdrv_release_named_dirty_bitmaps(bs); assert(QLIST_EMPTY(&bs->dirty_bitmaps)); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 83415e1..6df7fe1 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -44,6 +44,7 @@ struct BdrvDirtyBitmap { int64_t size; /* Size of the bitmap (Number of sectors) */ bool disabled; /* Bitmap is read-only */ int active_iterators; /* How many iterators are active */ + bool persistent; /* bitmap must be saved to owner disk image */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; @@ -70,6 +71,8 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap) assert(!bdrv_dirty_bitmap_frozen(bitmap)); g_free(bitmap->name); bitmap->name = NULL; + + bitmap->persistent = false; } BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, @@ -238,6 +241,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs, bitmap->name = NULL; successor->name = name; bitmap->successor = NULL; + successor->persistent = bitmap->persistent; + bitmap->persistent = false; bdrv_release_dirty_bitmap(bs, bitmap); return successor; @@ -555,3 +560,40 @@ bool bdrv_load_check_dirty_bitmap(BlockDriverState *file, const char *name) } return false; } + +void bdrv_store_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + Error **errp) +{ + if (bs == NULL || bs->drv == NULL || + bs->drv->bdrv_dirty_bitmap_store == NULL) { + error_setg(errp, "Storing bitmap is unsupported for the format."); + return; + } + + bs->drv->bdrv_dirty_bitmap_store(bs, bitmap, errp); +} + +void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, + bool persistent) +{ + bitmap->persistent = persistent; +} + +void bdrv_finalize_persistent_dirty_bitmaps(BlockDriverState *bs) +{ + BdrvDirtyBitmap *bm, *bm_next; + + QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, bm_next) { + if (bm->persistent) { + if (!bdrv_is_read_only(bs) && + !(bdrv_get_flags(bs) & BDRV_O_INACTIVE)) { + Error *local_err = NULL; + bdrv_store_dirty_bitmap(bs, bm, &local_err); + if (local_err) { + error_report_err(local_err); + } + } + bdrv_release_dirty_bitmap(bs, bm); + } + } +} diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 6007c64..05aa7f9 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -76,5 +76,10 @@ void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); bool bdrv_load_check_dirty_bitmap(BlockDriverState *file, const char *name); +void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, + bool persistent); +void bdrv_store_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + Error **errp); +void bdrv_finalize_persistent_dirty_bitmaps(BlockDriverState *bs); #endif