Blame SOURCES/kvm-block-Fix-blk-in_flight-during-blk_wait_while_draine.patch

22c213
From f17b37b58a57d849d2ff5fa04f149d9415803a39 Mon Sep 17 00:00:00 2001
22c213
From: Kevin Wolf <kwolf@redhat.com>
22c213
Date: Wed, 8 Apr 2020 17:29:17 +0100
22c213
Subject: [PATCH 6/6] block: Fix blk->in_flight during blk_wait_while_drained()
22c213
22c213
RH-Author: Kevin Wolf <kwolf@redhat.com>
22c213
Message-id: <20200408172917.18712-7-kwolf@redhat.com>
22c213
Patchwork-id: 94599
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH 6/6] block: Fix blk->in_flight during blk_wait_while_drained()
22c213
Bugzilla: 1817621
22c213
RH-Acked-by: Eric Blake <eblake@redhat.com>
22c213
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
22c213
Waiting in blk_wait_while_drained() while blk->in_flight is increased
22c213
for the current request is wrong because it will cause the drain
22c213
operation to deadlock.
22c213
22c213
This patch makes sure that blk_wait_while_drained() is called with
22c213
blk->in_flight increased exactly once for the current request, and that
22c213
it temporarily decreases the counter while it waits.
22c213
22c213
Fixes: cf3129323f900ef5ddbccbe86e4fa801e88c566e
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
22c213
Reviewed-by: Max Reitz <mreitz@redhat.com>
22c213
Message-Id: <20200407121259.21350-4-kwolf@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit 7f16476fab14fc32388e0ebae793f64673848efa)
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 block/block-backend.c | 17 +++++------------
22c213
 1 file changed, 5 insertions(+), 12 deletions(-)
22c213
22c213
diff --git a/block/block-backend.c b/block/block-backend.c
22c213
index 610dbfa..38ae413 100644
22c213
--- a/block/block-backend.c
22c213
+++ b/block/block-backend.c
22c213
@@ -1140,10 +1140,15 @@ static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
22c213
     return 0;
22c213
 }
22c213
 
22c213
+/* To be called between exactly one pair of blk_inc/dec_in_flight() */
22c213
 static void coroutine_fn blk_wait_while_drained(BlockBackend *blk)
22c213
 {
22c213
+    assert(blk->in_flight > 0);
22c213
+
22c213
     if (blk->quiesce_counter && !blk->disable_request_queuing) {
22c213
+        blk_dec_in_flight(blk);
22c213
         qemu_co_queue_wait(&blk->queued_requests, NULL);
22c213
+        blk_inc_in_flight(blk);
22c213
     }
22c213
 }
22c213
 
22c213
@@ -1418,12 +1423,6 @@ static void blk_aio_read_entry(void *opaque)
22c213
     BlkRwCo *rwco = &acb->rwco;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    if (rwco->blk->quiesce_counter) {
22c213
-        blk_dec_in_flight(rwco->blk);
22c213
-        blk_wait_while_drained(rwco->blk);
22c213
-        blk_inc_in_flight(rwco->blk);
22c213
-    }
22c213
-
22c213
     assert(qiov->size == acb->bytes);
22c213
     rwco->ret = blk_do_preadv(rwco->blk, rwco->offset, acb->bytes,
22c213
                               qiov, rwco->flags);
22c213
@@ -1436,12 +1435,6 @@ static void blk_aio_write_entry(void *opaque)
22c213
     BlkRwCo *rwco = &acb->rwco;
22c213
     QEMUIOVector *qiov = rwco->iobuf;
22c213
 
22c213
-    if (rwco->blk->quiesce_counter) {
22c213
-        blk_dec_in_flight(rwco->blk);
22c213
-        blk_wait_while_drained(rwco->blk);
22c213
-        blk_inc_in_flight(rwco->blk);
22c213
-    }
22c213
-
22c213
     assert(!qiov || qiov->size == acb->bytes);
22c213
     rwco->ret = blk_do_pwritev_part(rwco->blk, rwco->offset, acb->bytes,
22c213
                                     qiov, 0, rwco->flags);
22c213
-- 
22c213
1.8.3.1
22c213