Pablo Greco e6a3ae
From 2f11a1952881d9e2dcc8acb3549441dbd9ade1e3 Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Kevin Wolf <kwolf@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 14 Aug 2019 08:42:26 +0100
Pablo Greco e6a3ae
Subject: [PATCH 03/10] virtio-blk: Increase in_flight for request restart BH
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Kevin Wolf <kwolf@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190814084229.6458-3-kwolf@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 89967
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 2/5] virtio-blk: Increase in_flight for request restart BH
Pablo Greco e6a3ae
Bugzilla: 1716349
Pablo Greco e6a3ae
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Max Reitz <mreitz@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
virtio_blk_dma_restart_bh() submits new requests, so in order to make
Pablo Greco e6a3ae
sure that these requests are not started inside a drained section of the
Pablo Greco e6a3ae
attached BlockBackend, we need to make sure that draining the
Pablo Greco e6a3ae
BlockBackend waits for the BH to be executed.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
This BH is still questionable because its scheduled in the main thread
Pablo Greco e6a3ae
instead of the configured iothread. Leave a FIXME comment for this.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
But with this fix, enabling the data plane at least waits for these
Pablo Greco e6a3ae
requests (in bdrv_set_aio_context()) instead of changing the AioContext
Pablo Greco e6a3ae
under their feet and making them run in the wrong thread, causing
Pablo Greco e6a3ae
crashes and failures (e.g. due to missing locking).
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Pablo Greco e6a3ae
(cherry picked from commit 680f200217748e0920b79ec1d524717c2f50935b)
Pablo Greco e6a3ae
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 hw/block/virtio-blk.c | 4 ++++
Pablo Greco e6a3ae
 1 file changed, 4 insertions(+)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
Pablo Greco e6a3ae
index b1532e4..691ade4 100644
Pablo Greco e6a3ae
--- a/hw/block/virtio-blk.c
Pablo Greco e6a3ae
+++ b/hw/block/virtio-blk.c
Pablo Greco e6a3ae
@@ -678,6 +678,7 @@ static void virtio_blk_dma_restart_bh(void *opaque)
Pablo Greco e6a3ae
     if (mrb.num_reqs) {
Pablo Greco e6a3ae
         virtio_blk_submit_multireq(s->blk, &mrb);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
+    blk_dec_in_flight(s->conf.conf.blk);
Pablo Greco e6a3ae
     aio_context_release(blk_get_aio_context(s->conf.conf.blk));
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
@@ -691,8 +692,11 @@ static void virtio_blk_dma_restart_cb(void *opaque, int running,
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     if (!s->bh) {
Pablo Greco e6a3ae
+        /* FIXME The data plane is not started yet, so these requests are
Pablo Greco e6a3ae
+         * processed in the main thread. */
Pablo Greco e6a3ae
         s->bh = aio_bh_new(blk_get_aio_context(s->conf.conf.blk),
Pablo Greco e6a3ae
                            virtio_blk_dma_restart_bh, s);
Pablo Greco e6a3ae
+        blk_inc_in_flight(s->conf.conf.blk);
Pablo Greco e6a3ae
         qemu_bh_schedule(s->bh);
Pablo Greco e6a3ae
     }
Pablo Greco e6a3ae
 }
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae