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

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