From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKm8E-00076v-02 for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZKm8A-0002y1-1J for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:13 -0400 Received: from e19.ny.us.ibm.com ([129.33.205.209]:54941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZKm89-0002xs-TK for qemu-devel@nongnu.org; Thu, 30 Jul 2015 07:36:09 -0400 Received: from /spool/local by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Jul 2015 07:36:09 -0400 From: Michael Roth Date: Thu, 30 Jul 2015 06:32:22 -0500 Message-Id: <1438255988-10418-8-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1438255988-10418-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1438255988-10418-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 07/53] qcow2: Flush pending discards before allocating cluster List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-stable@nongnu.org From: Kevin Wolf Before a freed cluster can be reused, pending discards for this cluster must be processed. The original assumption was that this was not a problem because discards are only cached during discard/write zeroes operations, which are synchronous so that no concurrent write requests can cause cluster allocations. However, the discard/write zeroes operation itself can allocate a new L2 table (and it has to in order to put zero flags there), so make sure we can cope with the situation. This fixes https://bugs.launchpad.net/bugs/1349972. Cc: qemu-stable@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz (cherry picked from commit ecbda7a22576591a84f44de1be0150faf6001f1c) Signed-off-by: Michael Roth --- block/qcow2-refcount.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 6cbae1d..63c0085 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -833,6 +833,11 @@ static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size) uint64_t i, nb_clusters, refcount; int ret; + /* We can't allocate clusters if they may still be queued for discard. */ + if (s->cache_discards) { + qcow2_process_discards(bs, 0); + } + nb_clusters = size_to_clusters(s, size); retry: for(i = 0; i < nb_clusters; i++) { -- 1.9.1