diff mbox series

[v7,11/11] qcow2: use reqlist_mark_req_invalid()

Message ID 20210904162428.222008-12-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qcow2: fix parallel rewrite and discard (reqlist) | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 4, 2021, 4:24 p.m. UTC
Instead of small critical sections which wants only to remove a
request from the list let's use new atomic interface. And don't forget
to call reqlist_free_invalid_reqs() when we are in a critical section
anyway, to not overflow the RAM with invalid requests.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/qcow2.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index aefe6558b6..f2094c1ecc 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2306,9 +2306,7 @@  static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs,
     }
 
     if (req) {
-        WITH_QEMU_LOCK_GUARD(&s->lock) {
-            reqlist_free_req(req);
-        }
+        reqlist_mark_req_invalid(req);
     }
 
     return ret;
@@ -2348,6 +2346,7 @@  static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs,
         }
 
         qemu_co_mutex_lock(&s->lock);
+        reqlist_free_invalid_reqs(&s->guest_reqs);
         ret = qcow2_get_host_offset(bs, offset, &cur_bytes,
                                     &host_offset, &type, &req);
         qemu_co_mutex_unlock(&s->lock);
@@ -2769,6 +2768,8 @@  static void qcow2_close(BlockDriverState *bs)
 
     qcow2_refcount_close(bs);
     qcow2_free_snapshots(bs);
+
+    reqlist_free_invalid_reqs(&s->guest_reqs);
 }
 
 static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs,
@@ -4619,6 +4620,7 @@  qcow2_co_pwritev_compressed_task(BlockDriverState *bs,
     }
 
     qemu_co_mutex_lock(&s->lock);
+    reqlist_free_invalid_reqs(&s->guest_reqs);
     ret = qcow2_alloc_compressed_cluster_offset(bs, offset, out_len,
                                                 &cluster_offset, &req);
     if (ret < 0) {
@@ -4641,9 +4643,7 @@  success:
     ret = 0;
 fail:
     if (req) {
-        WITH_QEMU_LOCK_GUARD(&s->lock) {
-            reqlist_free_req(req);
-        }
+        reqlist_mark_req_invalid(req);
     }
     qemu_vfree(buf);
     g_free(out_buf);