From patchwork Thu Jul 2 09:19:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 490528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DB2F71402B8 for ; Thu, 2 Jul 2015 19:22:22 +1000 (AEST) Received: from localhost ([::1]:35450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAahJ-0005EN-0R for incoming@patchwork.ozlabs.org; Thu, 02 Jul 2015 05:22:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAafE-0001Q7-2S for qemu-devel@nongnu.org; Thu, 02 Jul 2015 05:20:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAaf9-0000Cl-UU for qemu-devel@nongnu.org; Thu, 02 Jul 2015 05:20:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAaf9-0000CI-QA for qemu-devel@nongnu.org; Thu, 02 Jul 2015 05:20:07 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id AB2882D44FF; Thu, 2 Jul 2015 09:20:03 +0000 (UTC) Received: from localhost (ovpn-112-49.ams2.redhat.com [10.36.112.49]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t629K1XQ026887; Thu, 2 Jul 2015 05:20:02 -0400 From: Stefan Hajnoczi To: Date: Thu, 2 Jul 2015 10:19:34 +0100 Message-Id: <1435828789-9647-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1435828789-9647-1-git-send-email-stefanha@redhat.com> References: <1435828789-9647-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Peter Maydell , Stefan Hajnoczi , =?UTF-8?q?Jind=C5=99ich=20Makovi=C4=8Dka?= Subject: [Qemu-devel] [PULL 02/17] qcow2: Handle EAGAIN returned from update_refcount X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jindřich Makovička Fixes a crash during image compression Signed-off-by: Jindřich Makovička Tested-by: Richard W.M. Jones Reviewed-by: Max Reitz Signed-off-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 0632fc3..b0ee42d 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -940,19 +940,21 @@ 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) { + 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; }