summaryrefslogtreecommitdiffstats
path: root/block/block-backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/block-backend.c')
-rw-r--r--block/block-backend.c76
1 files changed, 49 insertions, 27 deletions
diff --git a/block/block-backend.c b/block/block-backend.c
index 4f59664397..c0c7d56c8d 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -134,10 +134,9 @@ static void blk_root_drained_end(BdrvChild *child, int *drained_end_counter);
static void blk_root_change_media(BdrvChild *child, bool load);
static void blk_root_resize(BdrvChild *child);
-static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
- GSList **ignore, Error **errp);
-static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx,
- GSList **ignore);
+static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GHashTable *visited, Transaction *tran,
+ Error **errp);
static char *blk_root_get_parent_desc(BdrvChild *child)
{
@@ -334,8 +333,7 @@ static const BdrvChildClass child_root = {
.attach = blk_root_attach,
.detach = blk_root_detach,
- .can_set_aio_ctx = blk_root_can_set_aio_ctx,
- .set_aio_ctx = blk_root_set_aio_ctx,
+ .change_aio_ctx = blk_root_change_aio_ctx,
.get_parent_aio_context = blk_root_get_parent_aio_context,
};
@@ -1946,7 +1944,7 @@ bool blk_enable_write_cache(BlockBackend *blk)
void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
{
- GLOBAL_STATE_CODE();
+ IO_CODE();
blk->enable_write_cache = wce;
}
@@ -2149,8 +2147,11 @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context,
bdrv_ref(bs);
if (update_root_node) {
- ret = bdrv_child_try_set_aio_context(bs, new_context, blk->root,
- errp);
+ /*
+ * update_root_node MUST be false for blk_root_set_aio_ctx_commit(),
+ * as we are already in the commit function of a transaction.
+ */
+ ret = bdrv_try_change_aio_context(bs, new_context, blk->root, errp);
if (ret < 0) {
bdrv_unref(bs);
return ret;
@@ -2177,33 +2178,54 @@ int blk_set_aio_context(BlockBackend *blk, AioContext *new_context,
return blk_do_set_aio_context(blk, new_context, true, errp);
}
-static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
- GSList **ignore, Error **errp)
+typedef struct BdrvStateBlkRootContext {
+ AioContext *new_ctx;
+ BlockBackend *blk;
+} BdrvStateBlkRootContext;
+
+static void blk_root_set_aio_ctx_commit(void *opaque)
+{
+ BdrvStateBlkRootContext *s = opaque;
+ BlockBackend *blk = s->blk;
+
+ blk_do_set_aio_context(blk, s->new_ctx, false, &error_abort);
+}
+
+static TransactionActionDrv set_blk_root_context = {
+ .commit = blk_root_set_aio_ctx_commit,
+ .clean = g_free,
+};
+
+static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx,
+ GHashTable *visited, Transaction *tran,
+ Error **errp)
{
BlockBackend *blk = child->opaque;
+ BdrvStateBlkRootContext *s;
- if (blk->allow_aio_context_change) {
- return true;
+ if (!blk->allow_aio_context_change) {
+ /*
+ * Manually created BlockBackends (those with a name) that are not
+ * attached to anything can change their AioContext without updating
+ * their user; return an error for others.
+ */
+ if (!blk->name || blk->dev) {
+ /* TODO Add BB name/QOM path */
+ error_setg(errp, "Cannot change iothread of active block backend");
+ return false;
+ }
}
- /* Only manually created BlockBackends that are not attached to anything
- * can change their AioContext without updating their user. */
- if (!blk->name || blk->dev) {
- /* TODO Add BB name/QOM path */
- error_setg(errp, "Cannot change iothread of active block backend");
- return false;
- }
+ s = g_new(BdrvStateBlkRootContext, 1);
+ *s = (BdrvStateBlkRootContext) {
+ .new_ctx = ctx,
+ .blk = blk,
+ };
+ tran_add(tran, &set_blk_root_context, s);
return true;
}
-static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx,
- GSList **ignore)
-{
- BlockBackend *blk = child->opaque;
- blk_do_set_aio_context(blk, ctx, false, &error_abort);
-}
-
void blk_add_aio_context_notifier(BlockBackend *blk,
void (*attached_aio_context)(AioContext *new_context, void *opaque),
void (*detach_aio_context)(void *opaque), void *opaque)