From patchwork Wed Mar 25 09:36:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 454333 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3E9CA140077 for ; Wed, 25 Mar 2015 20:38:43 +1100 (AEDT) Received: from localhost ([::1]:37103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yahlp-0006ib-F3 for incoming@patchwork.ozlabs.org; Wed, 25 Mar 2015 05:38:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yahgx-0006Ll-RR for qemu-devel@nongnu.org; Wed, 25 Mar 2015 05:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yahgw-0007x5-PF for qemu-devel@nongnu.org; Wed, 25 Mar 2015 05:33:39 -0400 Received: from [59.151.112.132] (port=19442 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yahgw-0007w9-5T; Wed, 25 Mar 2015 05:33:38 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="89293806" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Mar 2015 17:29:52 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t2P9WYIq015831; Wed, 25 Mar 2015 17:32:34 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 25 Mar 2015 17:33:40 +0800 From: Wen Congyang To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini Date: Wed, 25 Mar 2015 17:36:11 +0800 Message-ID: <1427276174-9130-11-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427276174-9130-1-git-send-email-wency@cn.fujitsu.com> References: <1427276174-9130-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Kevin Wolf , qemu block , Lai Jiangshan , Jeff Cody , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Stefan Hajnoczi , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [RFC PATCH COLO v2 10/13] Backup: clear all bitmap when doing block checkpoint 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 Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei Cc: Jeff Cody --- block/backup.c | 12 ++++++++++++ include/block/block_int.h | 1 + include/qemu/hbitmap.h | 8 ++++++++ util/hbitmap.c | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/block/backup.c b/block/backup.c index 1c535b1..4e9d535 100644 --- a/block/backup.c +++ b/block/backup.c @@ -435,3 +435,15 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, job->common.co = qemu_coroutine_create(backup_run); qemu_coroutine_enter(job->common.co, job); } + +void backup_do_checkpoint(BlockJob *job, Error **errp) +{ + BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common); + + if (job->driver != &backup_job_driver) { + error_setg(errp, "It is not backup job"); + return; + } + + hbitmap_reset_all(backup_job->bitmap); +} diff --git a/include/block/block_int.h b/include/block/block_int.h index 624945d..45d547b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -628,6 +628,7 @@ void backup_start(BlockDriverState *bs, BlockDriverState *target, BlockdevOnError on_target_error, BlockCompletionFunc *cb, void *opaque, Error **errp); +void backup_do_checkpoint(BlockJob *job, Error **errp); void blk_dev_change_media_cb(BlockBackend *blk, bool load); bool blk_dev_has_removable_media(BlockBackend *blk); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 550d7ce..95a55e4 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -109,6 +109,14 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count); void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count); /** + * hbitmap_reset_all: + * @hb: HBitmap to operate on. + * + * Reset all bits in an HBitmap. + */ +void hbitmap_reset_all(HBitmap *hb); + +/** * hbitmap_get: * @hb: HBitmap to operate on. * @item: Bit to query (0-based). diff --git a/util/hbitmap.c b/util/hbitmap.c index ab13971..4111ca5 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -353,6 +353,25 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count) hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last); } +void hbitmap_reset_all(HBitmap *hb) +{ +#if 0 + hbitmap_reset(hb, 0, hb->size << hb->granularity); +#else + uint64_t size = hb->size; + unsigned int i; + + /* Same as hbitmap_alloc() except memset() */ + for (i = HBITMAP_LEVELS; i-- > 0; ) { + size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1); + memset(hb->levels[i], 0, size * sizeof(unsigned long)); + } + + assert(size == 1); + hb->levels[0][0] |= 1UL << (BITS_PER_LONG - 1); +#endif +} + bool hbitmap_get(const HBitmap *hb, uint64_t item) { /* Compute position and bit in the last layer. */