From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0bX6-0005dv-C4 for qemu-devel@nongnu.org; Fri, 27 Jun 2014 15:10:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0bX0-00071g-7G for qemu-devel@nongnu.org; Fri, 27 Jun 2014 15:10:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3618) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0bWz-00071Q-Vx for qemu-devel@nongnu.org; Fri, 27 Jun 2014 15:09:54 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5RJ9qbw032767 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 27 Jun 2014 15:09:53 -0400 From: Kevin Wolf Date: Fri, 27 Jun 2014 21:08:50 +0200 Message-Id: <1403896146-3063-32-git-send-email-kwolf@redhat.com> In-Reply-To: <1403896146-3063-1-git-send-email-kwolf@redhat.com> References: <1403896146-3063-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 31/47] 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: kwolf@redhat.com 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 Tested-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- 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.8.3.1