yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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