diff options
author | Kevin Wolf <kwolf@redhat.com> | 2015-05-06 13:21:51 +0200 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2015-07-28 18:19:33 -0500 |
commit | ad9c167fd21b488c1c8cfda77e8542a97aefc14f (patch) | |
tree | 61fe4f36965f6cc51ac7ceb5d656141f15e106db | |
parent | d8e231fce23d49e2f15f2d098463ec110c6eaa56 (diff) | |
download | qemu-ad9c167fd21b488c1c8cfda77e8542a97aefc14f.zip qemu-ad9c167fd21b488c1c8cfda77e8542a97aefc14f.tar.gz qemu-ad9c167fd21b488c1c8cfda77e8542a97aefc14f.tar.bz2 |
qcow2: Flush pending discards before allocating cluster
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 <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
(cherry picked from commit ecbda7a22576591a84f44de1be0150faf6001f1c)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r-- | block/qcow2-refcount.c | 5 |
1 files changed, 5 insertions, 0 deletions
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++) { |