Blame SOURCES/kvm-qcow2-Flush-pending-discards-before-allocating-clust.patch

9ae3a8
From 1ae5408c46e940c7a993ba59c7e31163d78dd81a Mon Sep 17 00:00:00 2001
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
Date: Sat, 13 Jun 2015 16:22:36 +0200
9ae3a8
Subject: [PATCH 42/42] qcow2: Flush pending discards before allocating cluster
9ae3a8
9ae3a8
Message-id: <1434212556-3927-43-git-send-email-mreitz@redhat.com>
9ae3a8
Patchwork-id: 66061
9ae3a8
O-Subject: [RHEL-7.2 qemu-kvm PATCH 42/42] qcow2: Flush pending discards before allocating cluster
9ae3a8
Bugzilla: 1129893
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
BZ: 1129893
9ae3a8
9ae3a8
Before a freed cluster can be reused, pending discards for this cluster
9ae3a8
must be processed.
9ae3a8
9ae3a8
The original assumption was that this was not a problem because discards
9ae3a8
are only cached during discard/write zeroes operations, which are
9ae3a8
synchronous so that no concurrent write requests can cause cluster
9ae3a8
allocations.
9ae3a8
9ae3a8
However, the discard/write zeroes operation itself can allocate a new L2
9ae3a8
table (and it has to in order to put zero flags there), so make sure we
9ae3a8
can cope with the situation.
9ae3a8
9ae3a8
This fixes https://bugs.launchpad.net/bugs/1349972.
9ae3a8
9ae3a8
Cc: qemu-stable@nongnu.org
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Reviewed-by: Max Reitz <mreitz@redhat.com>
9ae3a8
(cherry picked from commit ecbda7a22576591a84f44de1be0150faf6001f1c)
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/qcow2-refcount.c | 5 +++++
9ae3a8
 1 file changed, 5 insertions(+)
9ae3a8
9ae3a8
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
9ae3a8
index cee5b1f..848fd31 100644
9ae3a8
--- a/block/qcow2-refcount.c
9ae3a8
+++ b/block/qcow2-refcount.c
9ae3a8
@@ -663,6 +663,11 @@ static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size)
9ae3a8
     uint64_t i, nb_clusters;
9ae3a8
     int refcount;
9ae3a8
 
9ae3a8
+    /* We can't allocate clusters if they may still be queued for discard. */
9ae3a8
+    if (s->cache_discards) {
9ae3a8
+        qcow2_process_discards(bs, 0);
9ae3a8
+    }
9ae3a8
+
9ae3a8
     nb_clusters = size_to_clusters(s, size);
9ae3a8
 retry:
9ae3a8
     for(i = 0; i < nb_clusters; i++) {
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8