All of lore.kernel.org
 help / color / mirror / Atom feed
From: jemmy858585@gmail.com
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org,
	Lidong Chen <lidongchen@tencent.com>
Subject: [Qemu-devel] [PATCH 1/2] qemu-img: make sure contain the consecutive number of zero bytes
Date: Sun, 23 Apr 2017 22:33:16 +0800	[thread overview]
Message-ID: <1492957997-28587-1-git-send-email-lidongchen@tencent.com> (raw)

From: Lidong Chen <lidongchen@tencent.com>

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 <lidongchen@tencent.com>
---
 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;
     }
 
-- 
1.8.3.1

             reply	other threads:[~2017-04-23 14:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-23 14:33 jemmy858585 [this message]
2017-04-23 14:33 ` [Qemu-devel] [PATCH 2/2] qemu-img: fix some spelling errors jemmy858585
2017-04-24 14:40   ` Eric Blake
2017-04-24 15:37     ` Philippe Mathieu-Daudé
2017-04-24 15:47       ` Eric Blake
2017-04-24 15:53         ` Eric Blake
2017-04-25  2:10           ` 858585 jemmy
2017-04-25 19:11           ` Max Reitz
2017-04-26  8:05             ` 858585 jemmy
2017-04-24 14:43 ` [Qemu-devel] [PATCH 1/2] qemu-img: make sure contain the consecutive number of zero bytes Eric Blake
2017-04-25  1:50   ` 858585 jemmy
2017-04-25 19:20     ` Eric Blake
2017-04-25 20:01     ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1492957997-28587-1-git-send-email-lidongchen@tencent.com \
    --to=jemmy858585@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=lidongchen@tencent.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.