qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Jindřich Makovička" <makovick@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Jindřich Makovička" <makovick@gmail.com>
Subject: [Qemu-devel] [PATCH] qcow2: Handle EAGAIN returned from update_refcount
Date: Tue, 23 Jun 2015 23:34:49 +0200	[thread overview]
Message-ID: <1435095289-14342-2-git-send-email-makovick@gmail.com> (raw)
In-Reply-To: <1435095289-14342-1-git-send-email-makovick@gmail.com>

Fixes a crash during image compression

Signed-off-by: Jindřich Makovička <makovick@gmail.com>
---
 block/qcow2-refcount.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 0632fc3..f8d18e7 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -940,19 +940,22 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
     }
 
     free_in_cluster = s->cluster_size - offset_into_cluster(s, offset);
-    if (!offset || free_in_cluster < size) {
-        int64_t new_cluster = alloc_clusters_noref(bs, s->cluster_size);
-        if (new_cluster < 0) {
-            return new_cluster;
-        }
+    do {
+        if (!offset || free_in_cluster < size) {
+            int64_t new_cluster = alloc_clusters_noref(bs, s->cluster_size);
+            if (new_cluster < 0) {
+                fprintf(stderr, "error getting new cluster\n");
+                return new_cluster;
+            }
 
-        if (!offset || ROUND_UP(offset, s->cluster_size) != new_cluster) {
-            offset = new_cluster;
+            if (!offset || ROUND_UP(offset, s->cluster_size) != new_cluster) {
+                offset = new_cluster;
+            }
         }
-    }
 
-    assert(offset);
-    ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+        assert(offset);
+        ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
+    } while (ret == -EAGAIN);
     if (ret < 0) {
         return ret;
     }
-- 
2.1.4

  reply	other threads:[~2015-06-23 21:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-23 21:34 [Qemu-devel] [PATCH] Fix occassional crashes during qcow2 recompression Jindřich Makovička
2015-06-23 21:34 ` Jindřich Makovička [this message]
2015-06-24  5:05   ` [Qemu-devel] [PATCH] qcow2: Handle EAGAIN returned from update_refcount Jindřich Makovička
2015-06-24 14:15     ` Cole Robinson
2015-06-24 14:22       ` Richard W.M. Jones
2015-06-24 15:26     ` Max Reitz
2015-06-25 14:52 ` [Qemu-devel] [PATCH] Fix occassional crashes during qcow2 recompression Stefan Hajnoczi

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=1435095289-14342-2-git-send-email-makovick@gmail.com \
    --to=makovick@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).