block: acquire AioContext in qmp_block_resize()

Make block_resize safe for dataplane where another thread may be running
the BlockDriverState's AioContext.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Stefan Hajnoczi 2014-08-18 14:52:28 +01:00 committed by Kevin Wolf
parent 6ffb4cb6fd
commit 927e0e769f
1 changed files with 10 additions and 3 deletions

View File

@ -1799,6 +1799,7 @@ void qmp_block_resize(bool has_device, const char *device,
{ {
Error *local_err = NULL; Error *local_err = NULL;
BlockDriverState *bs; BlockDriverState *bs;
AioContext *aio_context;
int ret; int ret;
bs = bdrv_lookup_bs(has_device ? device : NULL, bs = bdrv_lookup_bs(has_device ? device : NULL,
@ -1809,19 +1810,22 @@ void qmp_block_resize(bool has_device, const char *device,
return; return;
} }
aio_context = bdrv_get_aio_context(bs);
aio_context_acquire(aio_context);
if (!bdrv_is_first_non_filter(bs)) { if (!bdrv_is_first_non_filter(bs)) {
error_set(errp, QERR_FEATURE_DISABLED, "resize"); error_set(errp, QERR_FEATURE_DISABLED, "resize");
return; goto out;
} }
if (size < 0) { if (size < 0) {
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size"); error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
return; goto out;
} }
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) { if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_RESIZE, NULL)) {
error_set(errp, QERR_DEVICE_IN_USE, device); error_set(errp, QERR_DEVICE_IN_USE, device);
return; goto out;
} }
/* complete all in-flight operations before resizing the device */ /* complete all in-flight operations before resizing the device */
@ -1847,6 +1851,9 @@ void qmp_block_resize(bool has_device, const char *device,
error_setg_errno(errp, -ret, "Could not resize"); error_setg_errno(errp, -ret, "Could not resize");
break; break;
} }
out:
aio_context_release(aio_context);
} }
static void block_job_cb(void *opaque, int ret) static void block_job_cb(void *opaque, int ret)