From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJNMe-0007Mv-BN for qemu-devel@nongnu.org; Mon, 18 Aug 2014 09:52:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJNMY-0002PG-7j for qemu-devel@nongnu.org; Mon, 18 Aug 2014 09:52:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJNMX-0002Of-TW for qemu-devel@nongnu.org; Mon, 18 Aug 2014 09:52:42 -0400 From: Stefan Hajnoczi Date: Mon, 18 Aug 2014 14:52:28 +0100 Message-Id: <1408369949-3128-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1408369949-3128-1-git-send-email-stefanha@redhat.com> References: <1408369949-3128-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] block: acquire AioContext in qmp_block_resize() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Andrey Korolyov , Stefan Hajnoczi , Max Reitz Make block_resize safe for dataplane where another thread may be running the BlockDriverState's AioContext. Signed-off-by: Stefan Hajnoczi --- blockdev.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 48bd9a3..197b799 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1799,6 +1799,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, @@ -1809,19 +1810,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 */ @@ -1847,6 +1851,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); } static void block_job_cb(void *opaque, int ret) -- 1.9.3