From patchwork Wed Apr 27 16:04:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ren Kimura X-Patchwork-Id: 8959721 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 559B09F441 for ; Wed, 27 Apr 2016 16:05:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B05AA20219 for ; Wed, 27 Apr 2016 16:05:30 +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 16486200DC for ; Wed, 27 Apr 2016 16:05:30 +0000 (UTC) Received: from localhost ([::1]:44084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avRxx-0000Px-E5 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Apr 2016 12:05:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avRxp-0000MR-E7 for qemu-devel@nongnu.org; Wed, 27 Apr 2016 12:05:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avRxo-0002ew-J0 for qemu-devel@nongnu.org; Wed, 27 Apr 2016 12:05:21 -0400 Received: from mail-pa0-x241.google.com ([2607:f8b0:400e:c03::241]:33598) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avRxj-0002cr-CZ; Wed, 27 Apr 2016 12:05:15 -0400 Received: by mail-pa0-x241.google.com with SMTP id vv3so6204807pab.0; Wed, 27 Apr 2016 09:05:15 -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; bh=exNYFVpLuEAKPtRsDZoqiJ72XriE5a9AlV/KlbPscXA=; b=Yr7to68b5i4xLfHt8+7FdJwXirmQBTggYOCfr25dXqebLGyoMRZ7fn9ostXNYcQQc7 7yATySavLnmsBqSZhMz8gXo85L89441/xwBVuof1zoWZeuBQqG6gr2nM+Ketw6ZLGaK9 IToQvgnrQ3ziltOgtIV5XInOB7fqDzC9lV0X47F3fEro51UamTJ6ObylfUn/PNvgrz5h 6FWXQ1c6Be6AYZl8sciscpwsoG9hsK5a5w34Njj3sjyxotPWWuOMNj5PpaSE7f2+EyFh +fEUbW5r7aM5elunyUuO3QFHF2+Iwk3JMkjhYEy0C5Uv+8+8jZ10PEApz8mRjPWio/gR MS+w== 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; bh=exNYFVpLuEAKPtRsDZoqiJ72XriE5a9AlV/KlbPscXA=; b=M8Ch/ZOtFqxlI6b5kFMJP5i/sTkgbu/mf0RFspoLjFv8X5miMdBszL5rhxw2yRoQDH Y0/hTPprT1Jtb6XZaqYQMQA6KRo7SAn3TAkhPUdrHy5WEyNCJn37WmZIBqb1Oi9ASa10 9aYCl5xbB4Jyc1WLHUnJGuWZ76nNUlWtPfPLnnCUzl5ArFEiqLJ1lYGoUkSrdWKP3zvZ 5zYjNJjqJEXfPUBPaBoukzaVnzLCvQ+Tl3SBxh1NaYbC7wzPqIUcBrqHRK0k3bVHW/BC gi5PwBceKmM7gbjeoXtoWa581dKDIwsTi9rhPianiRkGIdvdLpQbqnsmTY73thrnITuN 22KQ== X-Gm-Message-State: AOPr4FUotHI0WsTopAj0BRC0Qmegi0i4mCplyliutM5ytVk1YnkawPHsl11fooA4hcKAkQ== X-Received: by 10.66.139.9 with SMTP id qu9mr13060957pab.101.1461773114671; Wed, 27 Apr 2016 09:05:14 -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 eh9sm7812033pad.47.2016.04.27.09.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Apr 2016 09:05:14 -0700 (PDT) From: Ren Kimura To: mreitz@redhat.com Date: Thu, 28 Apr 2016 01:04:58 +0900 Message-Id: <1461773098-20356-1-git-send-email-rkx1209dev@gmail.com> X-Mailer: git-send-email 2.5.0 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 v5] 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: kwolf@redhat.com, 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 When converting images, check the block status of its backing file chain to avoid needlessly reading zeros. Signed-off-by: Ren Kimura --- qemu-img.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1697762..cb72f14 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1478,10 +1478,21 @@ 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 = bdrv_get_block_status_above(blk_bs(s->src[s->src_cur]), NULL, + sector_num - s->src_cur_offset, + n, &n, &file); + if (ret < 0) { + return ret; + } + + if (ret & BDRV_BLOCK_ZERO) { + s->status = BLK_ZERO; + } else { + s->status = BLK_DATA; + } } else { s->status = BLK_BACKING_FILE; }