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 From: Wen Congyang Date: Wed, 25 Mar 2015 17:36:11 +0800 Message-ID: <1427276174-9130-11-git-send-email-wency@cn.fujitsu.com> 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 Content-Type: text/plain Subject: [Qemu-devel] [RFC PATCH COLO v2 10/13] Backup: clear all bitmap when doing block checkpoint List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Fam Zheng , Max Reitz , Paolo Bonzini Cc: Kevin Wolf , qemu block , Lai Jiangshan , Jeff Cody , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Stefan Hajnoczi , Yang Hongyang , zhanghailiang 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. */ -- 2.1.0