Skip to contentSkip to conversation

qcow2: Flush pending discards before allocating cluster

PATCH Applied Kevin Wolf 2 participants 3 messages May 6, 2015 – May 8, 2015 Block layer

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 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.

---
 block/qcow2-refcount.c | 5 +++++
 1 file changed, 5 insertions(+)
block/qcow2-refcount.c +5 -0
index f47260b..83467c3 100644
@@ -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++) {
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · 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.

Quoted 6 lines

This fixes https://bugs.launchpad.net/bugs/1349972.

---
  block/qcow2-refcount.c | 5 +++++
  1 file changed, 5 insertions(+)
author Applied
#2 lore raw
In reply to Kevin Wolf

Am 06.05.2015 um 13:29 hat Kevin Wolf geschrieben:

Quoted 8 lines

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.

Quoted 7 lines

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.

Applied to my block branch.

Kevin