From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUBz9-0004c7-46 for qemu-devel@nongnu.org; Thu, 10 Oct 2013 04:52:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUBz0-0006sw-Rl for qemu-devel@nongnu.org; Thu, 10 Oct 2013 04:52:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUBz0-0006sf-Jm for qemu-devel@nongnu.org; Thu, 10 Oct 2013 04:52:34 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9A8qXej000820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 10 Oct 2013 04:52:33 -0400 From: Max Reitz Date: Thu, 10 Oct 2013 10:52:23 +0200 Message-Id: <1381395144-4449-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1381395144-4449-1-git-send-email-mreitz@redhat.com> References: <1381395144-4449-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] qcow2: Undo leaked allocations in co_writev List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz If the write request spans more than one L2 table, qcow2_alloc_cluster_offset cannot handle the required allocations atomically. This results in leaks if it allocated new clusters in any but the last L2 table touched and an error occurs in qcow2_co_writev before having established the L2 link. These non-atomic allocations were, however, indeed successful and are therefore given to the caller in the L2Meta list. If an error occurs in qcow2_co_writev and the L2Meta list is unwound, all its remaining entries are clusters whose L2 links were not yet established. Thus, all allocations in that list should be undone. Signed-off-by: Max Reitz --- block/qcow2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index b2489fb..6bedd5d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1017,6 +1017,13 @@ fail: while (l2meta != NULL) { QCowL2Meta *next; + /* Undo all leaked allocations */ + if (l2meta->nb_clusters != 0) { + qcow2_free_clusters(bs, l2meta->alloc_offset, + l2meta->nb_clusters << s->cluster_bits, + QCOW2_DISCARD_ALWAYS); + } + if (l2meta->nb_clusters != 0) { QLIST_REMOVE(l2meta, next_in_flight); } -- 1.8.3.1