From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuHj8-0004rj-Mg for qemu-devel@nongnu.org; Tue, 10 Jun 2014 04:48:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WuHj2-0006e2-CZ for qemu-devel@nongnu.org; Tue, 10 Jun 2014 04:48:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuHj1-0006dn-Tt for qemu-devel@nongnu.org; Tue, 10 Jun 2014 04:48:12 -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 s5A8mBw8010695 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 10 Jun 2014 04:48:11 -0400 From: Stefan Hajnoczi Date: Tue, 10 Jun 2014 09:29:52 +0200 Message-Id: <1402385392-15035-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1402385392-15035-1-git-send-email-stefanha@redhat.com> References: <1402385392-15035-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] block: acquire AioContext is 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 , Fam Zheng , Stefan Hajnoczi , Max Reitz 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 --- 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; -- 1.9.3