1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Hanna Reitz <hreitz@redhat.com>
3 Date: Wed, 9 Feb 2022 15:02:57 +0100
4 Subject: [PATCH] block/nbd: Move s->ioc on AioContext change
6 s->ioc must always be attached to the NBD node's AioContext. If that
7 context changes, s->ioc must be attached to the new context.
9 Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2033626
10 Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
11 Signed-off-by: Hanna Reitz <hreitz@redhat.com>
12 [FE: backport (open_timer doesn't exist yet in 6.2.0)]
13 Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
15 block/nbd.c | 41 +++++++++++++++++++++++++++++++++++++++++
16 1 file changed, 41 insertions(+)
18 diff --git a/block/nbd.c b/block/nbd.c
19 index aab20125d8..a3896c7f5f 100644
22 @@ -2003,6 +2003,38 @@ static void nbd_cancel_in_flight(BlockDriverState *bs)
23 nbd_co_establish_connection_cancel(s->conn);
26 +static void nbd_attach_aio_context(BlockDriverState *bs,
27 + AioContext *new_context)
29 + BDRVNBDState *s = bs->opaque;
32 + * The reconnect_delay_timer is scheduled in I/O paths when the
33 + * connection is lost, to cancel the reconnection attempt after a
34 + * given time. Once this attempt is done (successfully or not),
35 + * nbd_reconnect_attempt() ensures the timer is deleted before the
36 + * respective I/O request is resumed.
37 + * Since the AioContext can only be changed when a node is drained,
38 + * the reconnect_delay_timer cannot be active here.
40 + assert(!s->reconnect_delay_timer);
43 + qio_channel_attach_aio_context(s->ioc, new_context);
47 +static void nbd_detach_aio_context(BlockDriverState *bs)
49 + BDRVNBDState *s = bs->opaque;
51 + assert(!s->reconnect_delay_timer);
54 + qio_channel_detach_aio_context(s->ioc);
58 static BlockDriver bdrv_nbd = {
60 .protocol_name = "nbd",
61 @@ -2026,6 +2058,9 @@ static BlockDriver bdrv_nbd = {
62 .bdrv_dirname = nbd_dirname,
63 .strong_runtime_opts = nbd_strong_runtime_opts,
64 .bdrv_cancel_in_flight = nbd_cancel_in_flight,
66 + .bdrv_attach_aio_context = nbd_attach_aio_context,
67 + .bdrv_detach_aio_context = nbd_detach_aio_context,
70 static BlockDriver bdrv_nbd_tcp = {
71 @@ -2051,6 +2086,9 @@ static BlockDriver bdrv_nbd_tcp = {
72 .bdrv_dirname = nbd_dirname,
73 .strong_runtime_opts = nbd_strong_runtime_opts,
74 .bdrv_cancel_in_flight = nbd_cancel_in_flight,
76 + .bdrv_attach_aio_context = nbd_attach_aio_context,
77 + .bdrv_detach_aio_context = nbd_detach_aio_context,
80 static BlockDriver bdrv_nbd_unix = {
81 @@ -2076,6 +2114,9 @@ static BlockDriver bdrv_nbd_unix = {
82 .bdrv_dirname = nbd_dirname,
83 .strong_runtime_opts = nbd_strong_runtime_opts,
84 .bdrv_cancel_in_flight = nbd_cancel_in_flight,
86 + .bdrv_attach_aio_context = nbd_attach_aio_context,
87 + .bdrv_detach_aio_context = nbd_detach_aio_context,
90 static void bdrv_nbd_init(void)