From patchwork Wed Apr 13 13:24:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ren Kimura X-Patchwork-Id: 8822431 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9FF2F9F39A for ; Wed, 13 Apr 2016 13:25:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 037E4202A1 for ; Wed, 13 Apr 2016 13:25:22 +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 5481F2014A for ; Wed, 13 Apr 2016 13:25:20 +0000 (UTC) Received: from localhost ([::1]:43780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqKnH-0004b7-No for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Apr 2016 09:25:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqKmz-0004Cg-QU for qemu-devel@nongnu.org; Wed, 13 Apr 2016 09:25:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqKmy-0002NH-TR for qemu-devel@nongnu.org; Wed, 13 Apr 2016 09:25:01 -0400 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:36197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqKmp-0002IF-IB; Wed, 13 Apr 2016 09:24:51 -0400 Received: by mail-pa0-x241.google.com with SMTP id k3so3930533pav.3; Wed, 13 Apr 2016 06:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rc4BXo/vKhMr7uqbSmg40ABOeptf60PmXIlNTQFuIMQ=; b=TReuidwY3y1RqDPggDJSSTPQDHUwUnenuXTHZ0zycmma122foaxBZ0TPqD8HorcLM2 SkAVyDg61b4SvnJeLj8NKQQ/XP5FleolMsIJcUD902rX2lL7nEbbSX8RzEi6GapUFjnR FjUW4wHRTapXUFX6kt7G9OcdJ2UiKnc+r1YcxutnLIiIDDOoIz/nAmjI+mckdrXUuCM5 45cMZOlgerR7K2SAqabxtPDT6RsSvNTCWCEE6AlF21JEs+Hah0xX8D216jY+5njouMkQ PMxYbggEmI7ktkTnLaAHcuqUW+Oywbxvj8kinaw9HVRiRy2uD0J+Rz/3sbEHqe9Yox6g R5sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rc4BXo/vKhMr7uqbSmg40ABOeptf60PmXIlNTQFuIMQ=; b=Pt7WcuKu75/ZfDv053cw7rvlDCTQCJCJHePKFoLzAZTMQvGfWT4dipnbsAPYHW3tAs Hw6CZq4UA0jIjKT/+u8nQipq26fZOlITE5SXGddK0T+2MZ7GxLVWUKdY25uwmkoytCx6 g+DJE2zgScK8cBviFRffzh2q5iL36lHkWessCEfpD2HHIyJnbV+oR8nU73cEcnEp75Ud mxeJ/U8JwyAs28NWboftvdpePHqZV18nx9/9vGqgKbkLYGFJHBWnzcs+AT1KY+DdTlX5 V+kJ5z/ESCL0o/zGan0qQ7ywkky7fPFhaA9iFmd/JT5ugi7CIwEh1kpZU5L6xxDgRQXY 2djg== X-Gm-Message-State: AOPr4FVfY1VVjL9YZ4Ruag8d0GnjEZTMsx0By6v9NnraMmtzYrKTWLHlwoRpBAW14Mc9OQ== X-Received: by 10.66.229.1 with SMTP id sm1mr10685126pac.26.1460553890938; Wed, 13 Apr 2016 06:24:50 -0700 (PDT) Received: from localhost.localdomain (112-70-24-137f1.hyg1.eonet.ne.jp. [112.70.24.137]) by smtp.googlemail.com with ESMTPSA id a11sm51340780pat.6.2016.04.13.06.24.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 13 Apr 2016 06:24:50 -0700 (PDT) From: Ren Kimura To: kwolf@redhat.com Date: Wed, 13 Apr 2016 22:24:07 +0900 Message-Id: <1460553847-29886-2-git-send-email-rkx1209dev@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1460553847-29886-1-git-send-email-rkx1209dev@gmail.com> References: <1460553847-29886-1-git-send-email-rkx1209dev@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c03::241 Subject: [Qemu-devel] [PATCH 1/1] qemu-img: check block status of backing file when converting. 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: qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Ren Kimura --- qemu-img.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 06264d9..53471a1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1451,6 +1451,21 @@ static void convert_select_part(ImgConvertState *s, int64_t sector_num) } } +static int64_t get_backing_status(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, int *pnum, + BlockDriverState **file) +{ + int64_t ret; + if (bs->backing) { + ret = get_backing_status(bs->backing->bs, sector_num, + nb_sectors, pnum, file); + } else { + ret = bdrv_get_block_status(bs, sector_num, nb_sectors, pnum, file); + } + return ret; +} + static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) { int64_t ret; @@ -1469,7 +1484,6 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) if (ret < 0) { return ret; } - if (ret & BDRV_BLOCK_ZERO) { s->status = BLK_ZERO; } else if (ret & BDRV_BLOCK_DATA) { @@ -1477,10 +1491,17 @@ static int convert_iteration_sectors(ImgConvertState *s, int64_t sector_num) } else if (!s->target_has_backing) { /* Without a target backing file we must copy over the contents of * the backing file as well. */ - /* TODO Check block status of the backing file chain to avoid + /* Check block status of the backing file chain to avoid * needlessly reading zeroes and limiting the iteration to the * buffer size */ - s->status = BLK_DATA; + ret = get_backing_status(blk_bs(s->src[s->src_cur]), + sector_num - s->src_cur_offset, + n, &n, &file); + if (ret & BDRV_BLOCK_ZERO) { + s->status = BLK_ZERO; + } else { + s->status = BLK_DATA; + } } else { s->status = BLK_BACKING_FILE; }