cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
432cb7
From c7f63e7bbc5119d92775e20d1ebbf8280c78b732 Mon Sep 17 00:00:00 2001
432cb7
From: Hanna Reitz <hreitz@redhat.com>
432cb7
Date: Fri, 4 Feb 2022 12:10:11 +0100
432cb7
Subject: [PATCH 5/6] block/nbd: Move s->ioc on AioContext change
432cb7
432cb7
RH-Author: Hanna Reitz <hreitz@redhat.com>
432cb7
RH-MergeRequest: 117: block/nbd: Handle AioContext changes
432cb7
RH-Commit: [5/6] 107757b9fbadfb832c75521317108525daa4174e
432cb7
RH-Bugzilla: 2035185
432cb7
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
432cb7
RH-Acked-by: Eric Blake <eblake@redhat.com>
432cb7
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
432cb7
432cb7
s->ioc must always be attached to the NBD node's AioContext.  If that
432cb7
context changes, s->ioc must be attached to the new context.
432cb7
432cb7
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2033626
432cb7
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
432cb7
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
432cb7
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
432cb7
(cherry picked from commit e15f3a66c830e3fce99c9d56c493c2f7078a1225)
432cb7
432cb7
Conflict:
432cb7
- block/nbd.c: open_timer was added after the 6.2 release, so we need
432cb7
  not (and cannot) assert it is NULL here.
432cb7
432cb7
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
432cb7
---
432cb7
 block/nbd.c | 41 +++++++++++++++++++++++++++++++++++++++++
432cb7
 1 file changed, 41 insertions(+)
432cb7
432cb7
diff --git a/block/nbd.c b/block/nbd.c
432cb7
index aab20125d8..a3896c7f5f 100644
432cb7
--- a/block/nbd.c
432cb7
+++ b/block/nbd.c
432cb7
@@ -2003,6 +2003,38 @@ static void nbd_cancel_in_flight(BlockDriverState *bs)
432cb7
     nbd_co_establish_connection_cancel(s->conn);
432cb7
 }
432cb7
 
432cb7
+static void nbd_attach_aio_context(BlockDriverState *bs,
432cb7
+                                   AioContext *new_context)
432cb7
+{
432cb7
+    BDRVNBDState *s = bs->opaque;
432cb7
+
432cb7
+    /*
432cb7
+     * The reconnect_delay_timer is scheduled in I/O paths when the
432cb7
+     * connection is lost, to cancel the reconnection attempt after a
432cb7
+     * given time.  Once this attempt is done (successfully or not),
432cb7
+     * nbd_reconnect_attempt() ensures the timer is deleted before the
432cb7
+     * respective I/O request is resumed.
432cb7
+     * Since the AioContext can only be changed when a node is drained,
432cb7
+     * the reconnect_delay_timer cannot be active here.
432cb7
+     */
432cb7
+    assert(!s->reconnect_delay_timer);
432cb7
+
432cb7
+    if (s->ioc) {
432cb7
+        qio_channel_attach_aio_context(s->ioc, new_context);
432cb7
+    }
432cb7
+}
432cb7
+
432cb7
+static void nbd_detach_aio_context(BlockDriverState *bs)
432cb7
+{
432cb7
+    BDRVNBDState *s = bs->opaque;
432cb7
+
432cb7
+    assert(!s->reconnect_delay_timer);
432cb7
+
432cb7
+    if (s->ioc) {
432cb7
+        qio_channel_detach_aio_context(s->ioc);
432cb7
+    }
432cb7
+}
432cb7
+
432cb7
 static BlockDriver bdrv_nbd = {
432cb7
     .format_name                = "nbd",
432cb7
     .protocol_name              = "nbd",
432cb7
@@ -2026,6 +2058,9 @@ static BlockDriver bdrv_nbd = {
432cb7
     .bdrv_dirname               = nbd_dirname,
432cb7
     .strong_runtime_opts        = nbd_strong_runtime_opts,
432cb7
     .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
432cb7
+
432cb7
+    .bdrv_attach_aio_context    = nbd_attach_aio_context,
432cb7
+    .bdrv_detach_aio_context    = nbd_detach_aio_context,
432cb7
 };
432cb7
 
432cb7
 static BlockDriver bdrv_nbd_tcp = {
432cb7
@@ -2051,6 +2086,9 @@ static BlockDriver bdrv_nbd_tcp = {
432cb7
     .bdrv_dirname               = nbd_dirname,
432cb7
     .strong_runtime_opts        = nbd_strong_runtime_opts,
432cb7
     .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
432cb7
+
432cb7
+    .bdrv_attach_aio_context    = nbd_attach_aio_context,
432cb7
+    .bdrv_detach_aio_context    = nbd_detach_aio_context,
432cb7
 };
432cb7
 
432cb7
 static BlockDriver bdrv_nbd_unix = {
432cb7
@@ -2076,6 +2114,9 @@ static BlockDriver bdrv_nbd_unix = {
432cb7
     .bdrv_dirname               = nbd_dirname,
432cb7
     .strong_runtime_opts        = nbd_strong_runtime_opts,
432cb7
     .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
432cb7
+
432cb7
+    .bdrv_attach_aio_context    = nbd_attach_aio_context,
432cb7
+    .bdrv_detach_aio_context    = nbd_detach_aio_context,
432cb7
 };
432cb7
 
432cb7
 static void bdrv_nbd_init(void)
432cb7
-- 
432cb7
2.27.0
432cb7