From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgXEj-0000vG-Tz for qemu-devel@nongnu.org; Tue, 21 Oct 2014 07:04:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgXEd-0002Rn-Py for qemu-devel@nongnu.org; Tue, 21 Oct 2014 07:04:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgXEd-0002Ri-JH for qemu-devel@nongnu.org; Tue, 21 Oct 2014 07:04:15 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9LB4EFr011662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 21 Oct 2014 07:04:14 -0400 From: Stefan Hajnoczi Date: Tue, 21 Oct 2014 12:03:52 +0100 Message-Id: <1413889440-32577-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1413889440-32577-1-git-send-email-stefanha@redhat.com> References: <1413889440-32577-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH v2 03/11] 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: Kevin Wolf , Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , Max Reitz 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 --- blockdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockdev.c b/blockdev.c index fd55904..c46876c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -113,14 +113,21 @@ void override_max_devs(BlockInterfaceType type, int max_devs) void blockdev_mark_auto_del(BlockDriverState *bs) { DriveInfo *dinfo = drive_get_by_blockdev(bs); + AioContext *aio_context; if (dinfo && !dinfo->enable_auto_del) { 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); + if (dinfo) { dinfo->auto_del = 1; } -- 1.9.3