From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJOWy-0003uZ-8B for qemu-devel@nongnu.org; Mon, 18 Aug 2014 11:07:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJOWs-0001Tw-3b for qemu-devel@nongnu.org; Mon, 18 Aug 2014 11:07:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJOWr-0001SO-Pv for qemu-devel@nongnu.org; Mon, 18 Aug 2014 11:07:26 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7IF7N65029292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 18 Aug 2014 11:07:24 -0400 From: Stefan Hajnoczi Date: Mon, 18 Aug 2014 16:07:12 +0100 Message-Id: <1408374433-5360-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1408374433-5360-1-git-send-email-stefanha@redhat.com> References: <1408374433-5360-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] block: acquire AioContext in do_drive_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 Make drive_del safe for dataplane where another thread may be running the BlockDriverState's AioContext. Note the assumption that AioContext's lifetime exceeds DriveInfo and BlockDriverState. We release AioContext after DriveInfo and BlockDriverState are potentially freed. This is clearly safe with the global AioContext but also with -object iothread and implicit iothreads created by -device virtio-blk-pci,x-data-plane=on (their lifetime is tied to DeviceState, not BlockDriverState). Signed-off-by: Stefan Hajnoczi --- blockdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/blockdev.c b/blockdev.c index 48bd9a3..5cabb99 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1757,6 +1757,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *id = qdict_get_str(qdict, "id"); BlockDriverState *bs; + AioContext *aio_context; Error *local_err = NULL; bs = bdrv_find(id); @@ -1764,9 +1765,14 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) error_report("Device '%s' not found", id); return -1; } + + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { error_report("%s", error_get_pretty(local_err)); error_free(local_err); + aio_context_release(aio_context); return -1; } @@ -1790,6 +1796,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data) drive_del(drive_get_by_blockdev(bs)); } + aio_context_release(aio_context); return 0; } -- 1.9.3