|
@@ -4124,19 +4124,26 @@ void bdrv_reopen_queue_free(BlockReopenQueue *bs_queue)
|
|
*
|
|
*
|
|
* All affected nodes must be drained between bdrv_reopen_queue() and
|
|
* All affected nodes must be drained between bdrv_reopen_queue() and
|
|
* bdrv_reopen_multiple().
|
|
* bdrv_reopen_multiple().
|
|
|
|
+ *
|
|
|
|
+ * To be called from the main thread, with all other AioContexts unlocked.
|
|
*/
|
|
*/
|
|
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
|
|
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
|
|
{
|
|
{
|
|
int ret = -1;
|
|
int ret = -1;
|
|
BlockReopenQueueEntry *bs_entry, *next;
|
|
BlockReopenQueueEntry *bs_entry, *next;
|
|
|
|
+ AioContext *ctx;
|
|
Transaction *tran = tran_new();
|
|
Transaction *tran = tran_new();
|
|
g_autoptr(GHashTable) found = NULL;
|
|
g_autoptr(GHashTable) found = NULL;
|
|
g_autoptr(GSList) refresh_list = NULL;
|
|
g_autoptr(GSList) refresh_list = NULL;
|
|
|
|
|
|
|
|
+ assert(qemu_get_current_aio_context() == qemu_get_aio_context());
|
|
assert(bs_queue != NULL);
|
|
assert(bs_queue != NULL);
|
|
|
|
|
|
QTAILQ_FOREACH(bs_entry, bs_queue, entry) {
|
|
QTAILQ_FOREACH(bs_entry, bs_queue, entry) {
|
|
|
|
+ ctx = bdrv_get_aio_context(bs_entry->state.bs);
|
|
|
|
+ aio_context_acquire(ctx);
|
|
ret = bdrv_flush(bs_entry->state.bs);
|
|
ret = bdrv_flush(bs_entry->state.bs);
|
|
|
|
+ aio_context_release(ctx);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
error_setg_errno(errp, -ret, "Error flushing drive");
|
|
error_setg_errno(errp, -ret, "Error flushing drive");
|
|
goto abort;
|
|
goto abort;
|
|
@@ -4145,7 +4152,10 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
|
|
|
|
|
|
QTAILQ_FOREACH(bs_entry, bs_queue, entry) {
|
|
QTAILQ_FOREACH(bs_entry, bs_queue, entry) {
|
|
assert(bs_entry->state.bs->quiesce_counter > 0);
|
|
assert(bs_entry->state.bs->quiesce_counter > 0);
|
|
|
|
+ ctx = bdrv_get_aio_context(bs_entry->state.bs);
|
|
|
|
+ aio_context_acquire(ctx);
|
|
ret = bdrv_reopen_prepare(&bs_entry->state, bs_queue, tran, errp);
|
|
ret = bdrv_reopen_prepare(&bs_entry->state, bs_queue, tran, errp);
|
|
|
|
+ aio_context_release(ctx);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
goto abort;
|
|
goto abort;
|
|
}
|
|
}
|
|
@@ -4188,7 +4198,10 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
|
|
* to first element.
|
|
* to first element.
|
|
*/
|
|
*/
|
|
QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) {
|
|
QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) {
|
|
|
|
+ ctx = bdrv_get_aio_context(bs_entry->state.bs);
|
|
|
|
+ aio_context_acquire(ctx);
|
|
bdrv_reopen_commit(&bs_entry->state);
|
|
bdrv_reopen_commit(&bs_entry->state);
|
|
|
|
+ aio_context_release(ctx);
|
|
}
|
|
}
|
|
|
|
|
|
tran_commit(tran);
|
|
tran_commit(tran);
|
|
@@ -4197,7 +4210,10 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
|
|
BlockDriverState *bs = bs_entry->state.bs;
|
|
BlockDriverState *bs = bs_entry->state.bs;
|
|
|
|
|
|
if (bs->drv->bdrv_reopen_commit_post) {
|
|
if (bs->drv->bdrv_reopen_commit_post) {
|
|
|
|
+ ctx = bdrv_get_aio_context(bs);
|
|
|
|
+ aio_context_acquire(ctx);
|
|
bs->drv->bdrv_reopen_commit_post(&bs_entry->state);
|
|
bs->drv->bdrv_reopen_commit_post(&bs_entry->state);
|
|
|
|
+ aio_context_release(ctx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4208,7 +4224,10 @@ abort:
|
|
tran_abort(tran);
|
|
tran_abort(tran);
|
|
QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
|
|
QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
|
|
if (bs_entry->prepared) {
|
|
if (bs_entry->prepared) {
|
|
|
|
+ ctx = bdrv_get_aio_context(bs_entry->state.bs);
|
|
|
|
+ aio_context_acquire(ctx);
|
|
bdrv_reopen_abort(&bs_entry->state);
|
|
bdrv_reopen_abort(&bs_entry->state);
|
|
|
|
+ aio_context_release(ctx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4218,23 +4237,39 @@ cleanup:
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
|
|
|
|
- Error **errp)
|
|
|
|
|
|
+int bdrv_reopen(BlockDriverState *bs, QDict *opts, bool keep_old_opts,
|
|
|
|
+ Error **errp)
|
|
{
|
|
{
|
|
- int ret;
|
|
|
|
|
|
+ AioContext *ctx = bdrv_get_aio_context(bs);
|
|
BlockReopenQueue *queue;
|
|
BlockReopenQueue *queue;
|
|
- QDict *opts = qdict_new();
|
|
|
|
-
|
|
|
|
- qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only);
|
|
|
|
|
|
+ int ret;
|
|
|
|
|
|
bdrv_subtree_drained_begin(bs);
|
|
bdrv_subtree_drained_begin(bs);
|
|
- queue = bdrv_reopen_queue(NULL, bs, opts, true);
|
|
|
|
|
|
+ if (ctx != qemu_get_aio_context()) {
|
|
|
|
+ aio_context_release(ctx);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ queue = bdrv_reopen_queue(NULL, bs, opts, keep_old_opts);
|
|
ret = bdrv_reopen_multiple(queue, errp);
|
|
ret = bdrv_reopen_multiple(queue, errp);
|
|
|
|
+
|
|
|
|
+ if (ctx != qemu_get_aio_context()) {
|
|
|
|
+ aio_context_acquire(ctx);
|
|
|
|
+ }
|
|
bdrv_subtree_drained_end(bs);
|
|
bdrv_subtree_drained_end(bs);
|
|
|
|
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
|
|
|
|
+ Error **errp)
|
|
|
|
+{
|
|
|
|
+ QDict *opts = qdict_new();
|
|
|
|
+
|
|
|
|
+ qdict_put_bool(opts, BDRV_OPT_READ_ONLY, read_only);
|
|
|
|
+
|
|
|
|
+ return bdrv_reopen(bs, opts, true, errp);
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Take a BDRVReopenState and check if the value of 'backing' in the
|
|
* Take a BDRVReopenState and check if the value of 'backing' in the
|
|
* reopen_state->options QDict is valid or not.
|
|
* reopen_state->options QDict is valid or not.
|