From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwkKQ-0006YX-17 for qemu-devel@nongnu.org; Mon, 16 Jun 2014 23:45:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwkKJ-0007fJ-OE for qemu-devel@nongnu.org; Mon, 16 Jun 2014 23:44:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53705) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwkKJ-0007fC-Fc for qemu-devel@nongnu.org; Mon, 16 Jun 2014 23:44:51 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5H3ioOW003618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 16 Jun 2014 23:44:50 -0400 From: Fam Zheng Date: Tue, 17 Jun 2014 11:44:57 +0800 Message-Id: <1402976701-10271-3-git-send-email-famz@redhat.com> In-Reply-To: <1402976701-10271-1-git-send-email-famz@redhat.com> References: <1402976701-10271-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 2/6] block: acquire AioContext in qmp_query_blockstats() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Stefan Hajnoczi From: Stefan Hajnoczi Make query-blockstats safe for dataplane by acquiring the BlockDriverState's AioContext. This ensures that the dataplane IOThread and the main loop's monitor code do not race. Note the assumption that acquiring the drive's BDS AioContext also protects ->file and ->backing_hd. This assumption is made by other aio_context_acquire() callers too. Signed-off-by: Stefan Hajnoczi Signed-off-by: Fam Zheng --- block/qapi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/qapi.c b/block/qapi.c index aeabaaf..f44f6b4 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -360,7 +360,11 @@ BlockStatsList *qmp_query_blockstats(Error **errp) while ((bs = bdrv_next(bs))) { BlockStatsList *info = g_malloc0(sizeof(*info)); + AioContext *ctx = bdrv_get_aio_context(bs); + + aio_context_acquire(ctx); info->value = bdrv_query_stats(bs); + aio_context_release(ctx); *p_next = info; p_next = &info->next; -- 2.0.0