From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBv-0006ar-Qf for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:53:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlGBp-0000sw-Li for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34073) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlGBp-0000sl-FK for qemu-devel@nongnu.org; Mon, 03 Nov 2014 06:52:53 -0500 From: Stefan Hajnoczi Date: Mon, 3 Nov 2014 11:50:48 +0000 Message-Id: <1415015456-25086-46-git-send-email-stefanha@redhat.com> In-Reply-To: <1415015456-25086-1-git-send-email-stefanha@redhat.com> References: <1415015456-25086-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 45/53] blockdev: acquire AioContext in blockdev_mark_auto_del() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi When an emulated storage controller is unrealized it will call blockdev_mark_auto_del(). This will cancel any running block job (and that eventually releases its reference to the BDS so it can be freed). Since the block job may be executing in another AioContext we must acquire/release to ensure thread safety. Signed-off-by: Stefan Hajnoczi Reviewed-by: Max Reitz Message-id: 1413889440-32577-4-git-send-email-stefanha@redhat.com --- blockdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockdev.c b/blockdev.c index 40fc5d6..741df98 100644 --- a/blockdev.c +++ b/blockdev.c @@ -115,14 +115,21 @@ void blockdev_mark_auto_del(BlockBackend *blk) { DriveInfo *dinfo = blk_legacy_dinfo(blk); BlockDriverState *bs = blk_bs(blk); + AioContext *aio_context; if (!dinfo) { return; } + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (bs->job) { block_job_cancel(bs->job); } + + aio_context_release(aio_context); + dinfo->auto_del = 1; } -- 1.9.3