Skip to content

Commit

Permalink
block/nbd: Move s->ioc on AioContext change
Browse files Browse the repository at this point in the history
s->ioc must always be attached to the NBD node's AioContext.  If that
context changes, s->ioc must be attached to the new context.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2033626
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
  • Loading branch information
XanClic authored and Vladimir Sementsov-Ogievskiy committed Feb 9, 2022
1 parent 99fcaa1 commit bb19eba
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions block/nbd.c
Expand Up @@ -2055,6 +2055,42 @@ static void nbd_cancel_in_flight(BlockDriverState *bs)
nbd_co_establish_connection_cancel(s->conn);
}

static void nbd_attach_aio_context(BlockDriverState *bs,
AioContext *new_context)
{
BDRVNBDState *s = bs->opaque;

/* The open_timer is used only during nbd_open() */
assert(!s->open_timer);

/*
* The reconnect_delay_timer is scheduled in I/O paths when the
* connection is lost, to cancel the reconnection attempt after a
* given time. Once this attempt is done (successfully or not),
* nbd_reconnect_attempt() ensures the timer is deleted before the
* respective I/O request is resumed.
* Since the AioContext can only be changed when a node is drained,
* the reconnect_delay_timer cannot be active here.
*/
assert(!s->reconnect_delay_timer);

if (s->ioc) {
qio_channel_attach_aio_context(s->ioc, new_context);
}
}

static void nbd_detach_aio_context(BlockDriverState *bs)
{
BDRVNBDState *s = bs->opaque;

assert(!s->open_timer);
assert(!s->reconnect_delay_timer);

if (s->ioc) {
qio_channel_detach_aio_context(s->ioc);
}
}

static BlockDriver bdrv_nbd = {
.format_name = "nbd",
.protocol_name = "nbd",
Expand All @@ -2078,6 +2114,9 @@ static BlockDriver bdrv_nbd = {
.bdrv_dirname = nbd_dirname,
.strong_runtime_opts = nbd_strong_runtime_opts,
.bdrv_cancel_in_flight = nbd_cancel_in_flight,

.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_detach_aio_context = nbd_detach_aio_context,
};

static BlockDriver bdrv_nbd_tcp = {
Expand All @@ -2103,6 +2142,9 @@ static BlockDriver bdrv_nbd_tcp = {
.bdrv_dirname = nbd_dirname,
.strong_runtime_opts = nbd_strong_runtime_opts,
.bdrv_cancel_in_flight = nbd_cancel_in_flight,

.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_detach_aio_context = nbd_detach_aio_context,
};

static BlockDriver bdrv_nbd_unix = {
Expand All @@ -2128,6 +2170,9 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_dirname = nbd_dirname,
.strong_runtime_opts = nbd_strong_runtime_opts,
.bdrv_cancel_in_flight = nbd_cancel_in_flight,

.bdrv_attach_aio_context = nbd_attach_aio_context,
.bdrv_detach_aio_context = nbd_detach_aio_context,
};

static void bdrv_nbd_init(void)
Expand Down

0 comments on commit bb19eba

Please sign in to comment.