diff options
author | Kevin Wolf <kwolf@redhat.com> | 2020-03-06 15:14:13 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2020-03-06 17:34:09 +0100 |
commit | 1de6b45fb5c1489b450df7d1a4c692bba9678ce6 (patch) | |
tree | 383726d81225ad23498c9ebd6f149773fae344ba /block.c | |
parent | 97518e11c3d902a32386d33797044f6b79bccc6f (diff) |
block: bdrv_reopen() with backing file in different AioContext
This patch allows bdrv_reopen() (and therefore the x-blockdev-reopen QMP
command) to attach a node as the new backing file even if the node is in
a different AioContext than the parent if one of both nodes can be moved
to the AioContext of the other node.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Message-Id: <20200306141413.30705-3-kwolf@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -3787,6 +3787,29 @@ static void bdrv_reopen_perm(BlockReopenQueue *q, BlockDriverState *bs, *shared = cumulative_shared_perms; } +static bool bdrv_reopen_can_attach(BlockDriverState *parent, + BdrvChild *child, + BlockDriverState *new_child, + Error **errp) +{ + AioContext *parent_ctx = bdrv_get_aio_context(parent); + AioContext *child_ctx = bdrv_get_aio_context(new_child); + GSList *ignore; + bool ret; + + ignore = g_slist_prepend(NULL, child); + ret = bdrv_can_set_aio_context(new_child, parent_ctx, &ignore, NULL); + g_slist_free(ignore); + if (ret) { + return ret; + } + + ignore = g_slist_prepend(NULL, child); + ret = bdrv_can_set_aio_context(parent, child_ctx, &ignore, errp); + g_slist_free(ignore); + return ret; +} + /* * Take a BDRVReopenState and check if the value of 'backing' in the * reopen_state->options QDict is valid or not. @@ -3838,14 +3861,11 @@ static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state, } /* - * TODO: before removing the x- prefix from x-blockdev-reopen we - * should move the new backing file into the right AioContext - * instead of returning an error. + * Check AioContext compatibility so that the bdrv_set_backing_hd() call in + * bdrv_reopen_commit() won't fail. */ if (new_backing_bs) { - if (bdrv_get_aio_context(new_backing_bs) != bdrv_get_aio_context(bs)) { - error_setg(errp, "Cannot use a new backing file " - "with a different AioContext"); + if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)) { return -EINVAL; } } |