From patchwork Thu Sep 15 16:34:49 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: 9334249 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 71946601C2 for ; Thu, 15 Sep 2016 16:39:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66F0429A73 for ; Thu, 15 Sep 2016 16:39:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BB9229A78; Thu, 15 Sep 2016 16:39:19 +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 AF48529A73 for ; Thu, 15 Sep 2016 16:39:18 +0000 (UTC) Received: from localhost ([::1]:36244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkZgz-000620-Pk for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Sep 2016 12:39:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkZcu-0002qG-Nn for qemu-devel@nongnu.org; Thu, 15 Sep 2016 12:35:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkZcq-0004Le-2P for qemu-devel@nongnu.org; Thu, 15 Sep 2016 12:35:04 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:3786 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkZcp-0004Kv-Ku for qemu-devel@nongnu.org; Thu, 15 Sep 2016 12:34:59 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u8DK5gh1001084; Tue, 13 Sep 2016 23:05:43 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 15 Sep 2016 19:34:49 +0300 Message-Id: <1473957290-13382-2-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1473957290-13382-1-git-send-email-den@openvz.org> References: <1473957290-13382-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v3 1/2] block: sync bdrv_co_get_block_status_above() with bdrv_is_allocated_above() 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 , Fam Zheng , Jeff Cody , Max Reitz , Stefan Hajnoczi , den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP They should work very similar, covering same areas if backing store is shorter than the image. This change is necessary for the followup patch switching to bdrv_get_block_status_above() in mirror to avoid assert in check_block. This change should be made very carefully. Let us assume that we have top image and 2 backing stores L0->L1->L2. L0: -------------- L1: ------- L2: -------======= The data marked as '=' in L2 should not appear as BDRV_BLOCK_ALLOCATED and we should return it as filled in L0 image with properly calculated *pnum value. Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi CC: Fam Zheng CC: Kevin Wolf CC: Max Reitz CC: Jeff Cody --- block/io.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 420944d..067d465 100644 --- a/block/io.c +++ b/block/io.c @@ -1741,18 +1741,33 @@ static int64_t coroutine_fn bdrv_co_get_block_status_above(BlockDriverState *bs, BlockDriverState **file) { BlockDriverState *p; - int64_t ret = 0; + int64_t ret = 0, res = nb_sectors; assert(bs != base); for (p = bs; p != base; p = backing_bs(p)) { - ret = bdrv_co_get_block_status(p, sector_num, nb_sectors, pnum, file); - if (ret < 0 || ret & BDRV_BLOCK_ALLOCATED) { - break; + int sc; + ret = bdrv_co_get_block_status(p, sector_num, nb_sectors, &sc, file); + if (ret < 0) { + return ret; + } else if (ret & BDRV_BLOCK_ALLOCATED) { + *pnum = sc; + return ret; + } + + if (res > sc && (p == bs || sector_num + sc < p->total_sectors)) { + res = sc; } + /* [sector_num, pnum] unallocated on this layer, which could be only * the first part of [sector_num, nb_sectors]. */ - nb_sectors = MIN(nb_sectors, *pnum); + nb_sectors = MIN(nb_sectors, sc); + + if (nb_sectors == 0) { + break; + } } + + *pnum = res; return ret; }