From patchwork Tue Sep 6 15:11:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9317233 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 019E7607D3 for ; Tue, 6 Sep 2016 15:15:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F8811FFAD for ; Tue, 6 Sep 2016 15:15:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13D12277D9; Tue, 6 Sep 2016 15:15:22 +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 5BC2B1FFAD for ; Tue, 6 Sep 2016 15:15:21 +0000 (UTC) Received: from localhost ([::1]:34273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhI5m-0005Yo-25 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Sep 2016 11:15:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhI2j-0002fy-Da for qemu-devel@nongnu.org; Tue, 06 Sep 2016 11:12:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhI2d-0008Aq-QV for qemu-devel@nongnu.org; Tue, 06 Sep 2016 11:12:09 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:46471 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhI2d-00085t-DY; Tue, 06 Sep 2016 11:12:03 -0400 Received: from iris.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u86FBJZC032574; Tue, 6 Sep 2016 18:11:20 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 6 Sep 2016 18:11:19 +0300 Message-Id: <1473174679-18413-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/1] mirror: fix improperly filled copy_bitmap for mirror block job 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: Kevin Wolf , den@openvz.org, Jeff Cody , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP bdrv_is_allocated_above() returns true in the case if qcow2 even for completely zeroed areas as BDRV_BLOCK_ALLOCATED flag is set in both cases. Though we have completely zeroed out the image just above or it was already zeroed. The patch stops using bdrv_is_allocated_above() wrapper and switches to bdrv_get_block_status_above() to distinguish zeroed areas and areas with data to avoid extra IO operations, which could be VERY slow. Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Kevin Wolf CC: Max Reitz --- block/mirror.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index e0b3f41..87edbd8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -552,7 +552,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) BlockDriverState *base = s->base; BlockDriverState *bs = blk_bs(s->common.blk); BlockDriverState *target_bs = blk_bs(s->target); - int ret, n; + int n; end = s->bdev_length / BDRV_SECTOR_SIZE; @@ -590,6 +590,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) /* Just to make sure we are not exceeding int limit. */ int nb_sectors = MIN(INT_MAX >> BDRV_SECTOR_BITS, end - sector_num); + int64_t status; + BlockDriverState *file; mirror_throttle(s); @@ -597,13 +599,14 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJob *s) return 0; } - ret = bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, &n); - if (ret < 0) { - return ret; + status = bdrv_get_block_status_above(bs, base, sector_num, + nb_sectors, &n, &file); + if (status < 0) { + return status; } assert(n > 0); - if (ret == 1) { + if (status & BDRV_BLOCK_DATA) { bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n); } sector_num += n;