[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/73] blockdev: acquire AioContext in change-backing
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 12/73] blockdev: acquire AioContext in change-backing-file |
Date: |
Wed, 10 Dec 2014 11:33:38 +0100 |
From: Stefan Hajnoczi <address@hidden>
Add dataplane support to the change-backing-file QMP commands. By
acquiring the AioContext we avoid race conditions with the dataplane
thread which may also be accessing the BlockDriverState.
Note that this command operates on both bs and a node in its chain
(image_bs). The bdrv_chain_contains(bs, image_bs) check guarantees that
bs and image_bs are in the same AioContext.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
blockdev.c | 19 +++++++++++++------
hw/block/dataplane/virtio-blk.c | 1 +
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 7bf88d4..a52f205 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2584,6 +2584,7 @@ void qmp_change_backing_file(const char *device,
Error **errp)
{
BlockDriverState *bs = NULL;
+ AioContext *aio_context;
BlockDriverState *image_bs = NULL;
Error *local_err = NULL;
bool ro;
@@ -2597,34 +2598,37 @@ void qmp_change_backing_file(const char *device,
return;
}
+ aio_context = bdrv_get_aio_context(bs);
+ aio_context_acquire(aio_context);
+
image_bs = bdrv_lookup_bs(NULL, image_node_name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
- return;
+ goto out;
}
if (!image_bs) {
error_setg(errp, "image file not found");
- return;
+ goto out;
}
if (bdrv_find_base(image_bs) == image_bs) {
error_setg(errp, "not allowing backing file change on an image "
"without a backing file");
- return;
+ goto out;
}
/* even though we are not necessarily operating on bs, we need it to
* determine if block ops are currently prohibited on the chain */
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_CHANGE, errp)) {
- return;
+ goto out;
}
/* final sanity check */
if (!bdrv_chain_contains(bs, image_bs)) {
error_setg(errp, "'%s' and image file are not in the same chain",
device);
- return;
+ goto out;
}
/* if not r/w, reopen to make r/w */
@@ -2635,7 +2639,7 @@ void qmp_change_backing_file(const char *device,
bdrv_reopen(image_bs, open_flags | BDRV_O_RDWR, &local_err);
if (local_err) {
error_propagate(errp, local_err);
- return;
+ goto out;
}
}
@@ -2655,6 +2659,9 @@ void qmp_change_backing_file(const char *device,
error_propagate(errp, local_err); /* will preserve prior errp */
}
}
+
+out:
+ aio_context_release(aio_context);
}
void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 2548113..90ab27e 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -197,6 +197,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev,
VirtIOBlkConf *conf,
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_RESIZE, s->blocker);
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_BACKUP_SOURCE, s->blocker);
+ blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_CHANGE, s->blocker);
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_COMMIT, s->blocker);
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_EJECT, s->blocker);
blk_op_unblock(conf->conf.blk, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
--
1.8.3.1
- [Qemu-devel] [PULL 69/73] vmdk: Fix comment to match code of extent lines, (continued)
- [Qemu-devel] [PULL 69/73] vmdk: Fix comment to match code of extent lines, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when reading it, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 70/73] vmdk: Clean up descriptor file reading, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 67/73] block: Use g_new0() for a bit of extra type checking, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 73/73] vmdk: Set errp on failures in vmdk_open_vmdk4, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 72/73] vmdk: Remove unnecessary initialization, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 64/73] qemu-iotests: Skip 099 for VMDK subformats with desc file, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 43/73] qcow2.py: Add required padding for header extensions, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 05/73] qjson: Drop trailing space for pretty formatting, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 59/73] iotests: Add test for unsupported image creation, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 12/73] blockdev: acquire AioContext in change-backing-file,
Kevin Wolf <=
- [Qemu-devel] [PULL 04/73] qmp: Add optional switch "query-nodes" in query-blockstats, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 18/73] blkdebug: Simplify and improve filename generation, Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 33/73] block: Factor bdrv_probe_all() out of find_image_format(), Kevin Wolf, 2014/12/10
- [Qemu-devel] [PULL 08/73] iotests: Use -qmp-pretty in 067, Kevin Wolf, 2014/12/10
- Re: [Qemu-devel] [PULL 00/73] Merging block-next for 2.3, Peter Maydell, 2014/12/11