From patchwork Sun Apr 23 14:33:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: 858585 jemmy X-Patchwork-Id: 9694855 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 A2772601E9 for ; Sun, 23 Apr 2017 14:34:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E96D26490 for ; Sun, 23 Apr 2017 14:34:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F517269A3; Sun, 23 Apr 2017 14:34:24 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 E8C0D26490 for ; Sun, 23 Apr 2017 14:34:22 +0000 (UTC) Received: from localhost ([::1]:39433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2Iaj-0007K6-RH for patchwork-qemu-devel@patchwork.kernel.org; Sun, 23 Apr 2017 10:34:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2IZt-0007Jy-1w for qemu-devel@nongnu.org; Sun, 23 Apr 2017 10:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2IZp-0003Ir-UO for qemu-devel@nongnu.org; Sun, 23 Apr 2017 10:33:29 -0400 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:36815) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d2IZp-0003Ii-Oa; Sun, 23 Apr 2017 10:33:25 -0400 Received: by mail-it0-x242.google.com with SMTP id x188so9229301itb.3; Sun, 23 Apr 2017 07:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=brGP4ChN/aluwuaz5264RruQUmz4oQirvjRw2cm2vQQ=; b=mBnmhtf9heqb3R8UP1iwNrShRAFKC3KligBrillozQYGfIyufBgU2GlrHb9dBwEGUA grCseOQhGPZY1EEkIxobmxV331bd1lF2+NFaXl+T2mWD/iNdutezPDm8HxP/EQBFJ8u5 i06+ipb1ISPp+rro2EIzq1VfxgTSAB7dh83zkqN5b44l04moapHq+ZDsxKiF8gyej26O gC8KRKLoPiDAoKgOwUuP7TL35fn8Zrh4MLe4tngwRKoP9rYsG6efAP8PlYC6b255l2Yn B1y/0M77E3WswFUU714tzJ36qyaQ070+jF3DALLNhEbjjfh0rIn0vTijMPooU8uVYXCw eT9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=brGP4ChN/aluwuaz5264RruQUmz4oQirvjRw2cm2vQQ=; b=Tcvx1InRtEg7QIrmeIcC3oqak0k4MZcLJX+iBGK26jpFWQ2TsOXZ08EMo21tIf+kuo 0T8DQtRl1xZuWrCfmWCDCVF8dAc/QwwQj/Upj/qT5H8sD46mbUM2ICnZssT8IjRjIkvm aK3tkEkbamqrYIfdKFF7T/iQ8GZ7T/rcDkLPxigGYCUaRKy+QVMQACyIijcPc1aQywoB 60Ehbtylg7wcEruC5DAsc4NbrDuv3Yc5piCu3POSKNqSd/iudx4Owzjf5fHdl5/rpz5C EBLXULlkzY3YUtjc3c2hJBEqFN/UyJwj8yn2E3c5gt1dEf4czkQHa5lUeNjQu8K29MVs IBAQ== X-Gm-Message-State: AN3rC/5qmoRYLSBG969l4k76b8CdNfogZ2axC9T4XOJXjiNSTsfq0vYt RT8UFy8l+ynFsQ== X-Received: by 10.84.135.34 with SMTP id 31mr26457275pli.99.1492958004987; Sun, 23 Apr 2017 07:33:24 -0700 (PDT) Received: from localhost.localdomain ([119.28.70.25]) by smtp.gmail.com with ESMTPSA id f62sm25861106pfb.84.2017.04.23.07.33.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Apr 2017 07:33:24 -0700 (PDT) From: jemmy858585@gmail.com X-Google-Original-From: lidongchen@tencent.com To: qemu-devel@nongnu.org Date: Sun, 23 Apr 2017 22:33:16 +0800 Message-Id: <1492957997-28587-1-git-send-email-lidongchen@tencent.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::242 Subject: [Qemu-devel] [PATCH 1/2] qemu-img: make sure contain the consecutive number of zero bytes 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, Lidong Chen , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Lidong Chen is_allocated_sectors_min don't guarantee to contain the consecutive number of zero bytes. this patch fixes this bug. Signed-off-by: Lidong Chen --- qemu-img.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b220cf7..df6d165 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1060,9 +1060,9 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum) } /* - * Like is_allocated_sectors, but if the buffer starts with a used sector, - * up to 'min' consecutive sectors containing zeros are ignored. This avoids - * breaking up write requests for only small sparse areas. + * Like is_allocated_sectors, but up to 'min' consecutive sectors + * containing zeros are ignored. This avoids breaking up write requests + * for only small sparse areas. */ static int is_allocated_sectors_min(const uint8_t *buf, int n, int *pnum, int min) @@ -1071,11 +1071,12 @@ static int is_allocated_sectors_min(const uint8_t *buf, int n, int *pnum, int num_checked, num_used; if (n < min) { - min = n; + *pnum = n; + return 1; } ret = is_allocated_sectors(buf, n, pnum); - if (!ret) { + if (!ret && *pnum >= min) { return ret; }