From patchwork Tue Jan 26 10:38:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 8120041 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9B3B3BEEE5 for ; Tue, 26 Jan 2016 10:40:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7DBB2025B for ; Tue, 26 Jan 2016 10:40:50 +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 99D5020256 for ; Tue, 26 Jan 2016 10:40:49 +0000 (UTC) Received: from localhost ([::1]:42917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO13J-0007oH-03 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jan 2016 05:40:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO128-0005iW-KA for qemu-devel@nongnu.org; Tue, 26 Jan 2016 05:39:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aO127-0007Py-J0 for qemu-devel@nongnu.org; Tue, 26 Jan 2016 05:39:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aO122-0007PY-L4; Tue, 26 Jan 2016 05:39:30 -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 470A88F279; Tue, 26 Jan 2016 10:39:30 +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 u0QAcRTH016464; Tue, 26 Jan 2016 05:39:22 -0500 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 26 Jan 2016 18:38:15 +0800 Message-Id: <1453804705-7205-7-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 06/16] block: Introduce bdrv_dirty_bitmap_set_persistent 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 By implementing bdrv_dirty_bitmap_set_persistent, a driver can support the persistent dirty bitmap feature. Once a dirty bitmap is made persistent, the driver is responsible for saving the dirty bitmap when appropriate, for example before close; if a persistent bitmap is removed or made non-persistent, .bdrv_dirty_bitmap_set_persistent will be called, the driver should then remove the dirty bitmap from the disk. This operation is not recursed in block layer, a filter such as blkdebug needs to implement the callback and explicitly pass down to bs->file, etc. Signed-off-by: Fam Zheng --- block/dirty-bitmap.c | 38 ++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 8 ++++++++ include/block/dirty-bitmap.h | 4 ++++ 3 files changed, 50 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 1aa7f76..882a0db 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -43,6 +43,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; /* Whether this bitmap is persistent. */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; @@ -71,6 +72,37 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap) bitmap->name = NULL; } +int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + bool persistent, bool flag_only, + Error **errp) +{ + int ret = 0; + + if (!bitmap->name) { + error_setg(errp, "Cannot change the persistent status of an anonymous" + "bitmap"); + return -EINVAL; + } + + if (persistent == bitmap->persistent) { + return 0; + } + + if (!flag_only) { + if (!bs->drv || !bs->drv->bdrv_dirty_bitmap_set_persistent) { + error_setg(errp, "Not supported in this format."); + return -ENOTSUP; + } + ret = bs->drv->bdrv_dirty_bitmap_set_persistent(bs, bitmap, persistent, + errp); + } + if (!ret) { + bitmap->persistent = persistent; + } + return ret; +} + BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, const char *name, @@ -194,6 +226,12 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs, uint64_t granularity; BdrvDirtyBitmap *child; + if (bitmap->persistent) { + error_setg(errp, "Cannot create a successor for a bitmap that is " + "persistent"); + return -1; + } + if (bdrv_dirty_bitmap_frozen(bitmap)) { error_setg(errp, "Cannot create a successor for a bitmap that is " "currently frozen"); diff --git a/include/block/block_int.h b/include/block/block_int.h index 5fa58e8..fbc34af 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -305,6 +305,14 @@ struct BlockDriver { */ void (*bdrv_drain)(BlockDriverState *bs); + /** + * Make the dirty bitmap persistent if persistent=true or transient + * otherwise. + */ + int (*bdrv_dirty_bitmap_set_persistent)(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + bool persistent, Error **errp); + QLIST_ENTRY(BlockDriver) list; }; diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index d14d923..5885720 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -24,6 +24,10 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name); void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); +int bdrv_dirty_bitmap_set_persistent(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + bool persistent, bool flag_only, + Error **errp); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);