From a30f77fe6e83e6dd51c67ebdbe30cf8f89db3e50 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 3 Sep 2014 09:17:58 +0200 Subject: [PATCH 05/15] block: acquire AioContext in qmp_block_resize() Message-id: <1409735881-28863-2-git-send-email-stefanha@redhat.com> Patchwork-id: 60822 O-Subject: [RHEL7.1 qemu-kvm-rhev PATCH 1/4] block: acquire AioContext in qmp_block_resize() Bugzilla: 1136752 RH-Acked-by: Paolo Bonzini RH-Acked-by: Laszlo Ersek RH-Acked-by: Fam Zheng Make block_resize safe for dataplane where another thread may be running the BlockDriverState's AioContext. Signed-off-by: Stefan Hajnoczi Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf (cherry picked from commit 927e0e769f4008f458de8a94a809e85c1fd016eb) Signed-off-by: Stefan Hajnoczi --- blockdev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) Signed-off-by: Miroslav Rezanina --- blockdev.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index f9db328..caa073d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1804,6 +1804,7 @@ void qmp_block_resize(bool has_device, const char *device, { Error *local_err = NULL; BlockDriverState *bs; + AioContext *aio_context; int ret; bs = bdrv_lookup_bs(has_device ? device : NULL, @@ -1814,19 +1815,22 @@ void qmp_block_resize(bool has_device, const char *device, return; } + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (!bdrv_is_first_non_filter(bs)) { error_set(errp, QERR_FEATURE_DISABLED, "resize"); - return; + goto out; } if (size < 0) { 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)) { error_set(errp, QERR_DEVICE_IN_USE, device); - return; + goto out; } /* complete all in-flight operations before resizing the device */ @@ -1852,6 +1856,9 @@ void qmp_block_resize(bool has_device, const char *device, error_setg_errno(errp, -ret, "Could not resize"); break; } + +out: + aio_context_release(aio_context); } #ifdef CONFIG_LIVE_BLOCK_OPS -- 1.7.1