From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7VqM-0000nQ-7u for qemu-devel@nongnu.org; Tue, 23 Jun 2015 17:34:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7VqK-0006Il-81 for qemu-devel@nongnu.org; Tue, 23 Jun 2015 17:34:58 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:33819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7VqK-0006Ih-19 for qemu-devel@nongnu.org; Tue, 23 Jun 2015 17:34:56 -0400 Received: by wicnd19 with SMTP id nd19so117852686wic.1 for ; Tue, 23 Jun 2015 14:34:55 -0700 (PDT) From: =?UTF-8?q?Jind=C5=99ich=20Makovi=C4=8Dka?= Date: Tue, 23 Jun 2015 23:34:49 +0200 Message-Id: <1435095289-14342-2-git-send-email-makovick@gmail.com> In-Reply-To: <1435095289-14342-1-git-send-email-makovick@gmail.com> References: <1435095289-14342-1-git-send-email-makovick@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH] qcow2: Handle EAGAIN returned from update_refcount List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Jind=C5=99ich=20Makovi=C4=8Dka?= Fixes a crash during image compression Signed-off-by: Jindřich Makovička --- 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