From patchwork Tue Jun 10 07:29:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 357789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E8A0D140077 for ; Tue, 10 Jun 2014 18:50:38 +1000 (EST) Received: from localhost ([::1]:37630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuHlM-0000gA-SX for incoming@patchwork.ozlabs.org; Tue, 10 Jun 2014 04:50:36 -0400 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 Received: from localhost (reserved-198-188.str.redhat.com [10.33.198.188]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5A8m8np002797; Tue, 10 Jun 2014 04:48:10 -0400 From: Stefan Hajnoczi To: 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 3/3] block: acquire AioContext is qmp_query_blockstats() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;