From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149935937996122.124269766097655; Thu, 6 Jul 2017 09:42:59 -0700 (PDT) Received: from localhost ([::1]:52400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9rl-0008Nh-Qi for importer@patchew.org; Thu, 06 Jul 2017 12:42:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nf-0004ne-8O for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9ne-000612-Es for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38430) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nZ-0005xG-EO; Thu, 06 Jul 2017 12:38:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D88FC04B31E; Thu, 6 Jul 2017 16:38:36 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BE4753CD1; Thu, 6 Jul 2017 16:38:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5D88FC04B31E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5D88FC04B31E From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:18 +0200 Message-Id: <20170706163828.24082-2-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 06 Jul 2017 16:38:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/11] block: prepare write threshold code for thread safety X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Code refactoring only. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/write-threshold.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/block/write-threshold.c b/block/write-threshold.c index 0bd1a01c86..c8ebc32b4d 100644 --- a/block/write-threshold.c +++ b/block/write-threshold.c @@ -37,18 +37,22 @@ static void write_threshold_disable(BlockDriverState *b= s) } } =20 +static uint64_t exceeded_amount(const BdrvTrackedRequest *req, + uint64_t thres) +{ + if (thres > 0 && req->offset + req->bytes > thres) { + return req->offset + req->bytes - thres; + } else { + return 0; + } +} + uint64_t bdrv_write_threshold_exceeded(const BlockDriverState *bs, const BdrvTrackedRequest *req) { - if (bdrv_write_threshold_is_set(bs)) { - if (req->offset > bs->write_threshold_offset) { - return (req->offset - bs->write_threshold_offset) + req->bytes; - } - if ((req->offset + req->bytes) > bs->write_threshold_offset) { - return (req->offset + req->bytes) - bs->write_threshold_offset; - } - } - return 0; + uint64_t thres =3D bdrv_write_threshold_get(bs); + + return exceeded_amount(req, thres); } =20 static int coroutine_fn before_write_notify(NotifierWithReturn *notifier, @@ -56,14 +60,14 @@ static int coroutine_fn before_write_notify(NotifierWit= hReturn *notifier, { BdrvTrackedRequest *req =3D opaque; BlockDriverState *bs =3D req->bs; - uint64_t amount =3D 0; + uint64_t thres =3D bdrv_write_threshold_get(bs); + uint64_t amount =3D exceeded_amount(req, thres); =20 - amount =3D bdrv_write_threshold_exceeded(bs, req); if (amount > 0) { qapi_event_send_block_write_threshold( bs->node_name, amount, - bs->write_threshold_offset, + thres, &error_abort); =20 /* autodisable to avoid flooding the monitor */ --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359252100785.129168495958; Thu, 6 Jul 2017 09:40:52 -0700 (PDT) Received: from localhost ([::1]:52390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9pg-0006Kk-NQ for importer@patchew.org; Thu, 06 Jul 2017 12:40:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nf-0004nc-7B for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9ne-00060w-D3 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28447) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9na-0005y2-Qa; Thu, 06 Jul 2017 12:38:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C107A85547; Thu, 6 Jul 2017 16:38:37 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EF9053CD1; Thu, 6 Jul 2017 16:38:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C107A85547 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C107A85547 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:19 +0200 Message-Id: <20170706163828.24082-3-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 06 Jul 2017 16:38:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/11] block: make write-threshold thread-safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For simplicity, use bdrv_drained_begin/end to avoid concurrent writes to the write threshold, or reading it while it is being set. qmp_block_set_write_threshold is protected by the BQL. Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/write-threshold.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/block/write-threshold.c b/block/write-threshold.c index c8ebc32b4d..64ddd3d653 100644 --- a/block/write-threshold.c +++ b/block/write-threshold.c @@ -112,7 +112,6 @@ void qmp_block_set_write_threshold(const char *node_nam= e, Error **errp) { BlockDriverState *bs; - AioContext *aio_context; =20 bs =3D bdrv_find_node(node_name); if (!bs) { @@ -120,10 +119,8 @@ void qmp_block_set_write_threshold(const char *node_na= me, return; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - + /* Avoid a concurrent write_threshold_disable. */ + bdrv_drained_begin(bs); bdrv_write_threshold_set(bs, threshold_bytes); - - aio_context_release(aio_context); + bdrv_drained_end(bs); } --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359243812690.0982623053801; Thu, 6 Jul 2017 09:40:43 -0700 (PDT) Received: from localhost ([::1]:52389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9pZ-0006DK-DH for importer@patchew.org; Thu, 06 Jul 2017 12:40:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nf-0004nr-I1 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9ne-00061Q-Mh for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60444) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nc-0005z3-HZ; Thu, 06 Jul 2017 12:38:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6940B83F3E; Thu, 6 Jul 2017 16:38:39 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CDB853CD1; Thu, 6 Jul 2017 16:38:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6940B83F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6940B83F3E From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:20 +0200 Message-Id: <20170706163828.24082-4-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 06 Jul 2017 16:38:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/11] util: use RCU accessors for notifiers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This provides more flexibility for its users. Signed-off-by: Paolo Bonzini --- util/notify.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/util/notify.c b/util/notify.c index 06de63a839..16fff8d07d 100644 --- a/util/notify.c +++ b/util/notify.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/notify.h" +#include "qemu/rcu_queue.h" =20 void notifier_list_init(NotifierList *list) { @@ -24,19 +25,19 @@ void notifier_list_init(NotifierList *list) =20 void notifier_list_add(NotifierList *list, Notifier *notifier) { - QLIST_INSERT_HEAD(&list->notifiers, notifier, node); + QLIST_INSERT_HEAD_RCU(&list->notifiers, notifier, node); } =20 void notifier_remove(Notifier *notifier) { - QLIST_REMOVE(notifier, node); + QLIST_REMOVE_RCU(notifier, node); } =20 void notifier_list_notify(NotifierList *list, void *data) { Notifier *notifier, *next; =20 - QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { + QLIST_FOREACH_SAFE_RCU(notifier, &list->notifiers, node, next) { notifier->notify(notifier, data); } } @@ -49,12 +50,12 @@ void notifier_with_return_list_init(NotifierWithReturnL= ist *list) void notifier_with_return_list_add(NotifierWithReturnList *list, NotifierWithReturn *notifier) { - QLIST_INSERT_HEAD(&list->notifiers, notifier, node); + QLIST_INSERT_HEAD_RCU(&list->notifiers, notifier, node); } =20 void notifier_with_return_remove(NotifierWithReturn *notifier) { - QLIST_REMOVE(notifier, node); + QLIST_REMOVE_RCU(notifier, node); } =20 int notifier_with_return_list_notify(NotifierWithReturnList *list, void *d= ata) @@ -62,7 +63,7 @@ int notifier_with_return_list_notify(NotifierWithReturnLi= st *list, void *data) NotifierWithReturn *notifier, *next; int ret =3D 0; =20 - QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { + QLIST_FOREACH_SAFE_RCU(notifier, &list->notifiers, node, next) { ret =3D notifier->notify(notifier, data); if (ret !=3D 0) { break; --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359379064879.2955207546722; Thu, 6 Jul 2017 09:42:59 -0700 (PDT) Received: from localhost ([::1]:52399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9rk-0008MD-PR for importer@patchew.org; Thu, 06 Jul 2017 12:42:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nh-0004qP-OT for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9ng-00062i-Jf for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nd-0005zn-Sb; Thu, 06 Jul 2017 12:38:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D87364DD49; Thu, 6 Jul 2017 16:38:40 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8FAC60A9D; Thu, 6 Jul 2017 16:38:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D87364DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D87364DD49 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:21 +0200 Message-Id: <20170706163828.24082-5-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 06 Jul 2017 16:38:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/11] block: make before-write notifiers thread-safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reads access the list in RCU style, so be careful to avoid use-after-free scenarios in the backup block job. Apart from this, all that's needed is protecting updates with a mutex. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 17 +++++++++++++---- block/io.c | 12 ++++++++++++ block/write-threshold.c | 2 +- include/block/block_int.h | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/block/backup.c b/block/backup.c index 5387fbd84e..9214ffcc58 100644 --- a/block/backup.c +++ b/block/backup.c @@ -246,6 +246,13 @@ static void backup_abort(BlockJob *job) static void backup_clean(BlockJob *job) { BackupBlockJob *s =3D container_of(job, BackupBlockJob, common); + + /* Ensure that no I/O is using the notifier anymore before freeing + * the bitmap and the job. + */ + blk_drain(job->blk); + g_free(s->done_bitmap); + assert(s->target); blk_unref(s->target); s->target =3D NULL; @@ -526,12 +533,14 @@ static void coroutine_fn backup_run(void *opaque) } } =20 - notifier_with_return_remove(&job->before_write); - - /* wait until pending backup_do_cow() calls have completed */ + /* At this point, all future invocations of the write notifier will + * find a 1 in the done_bitmap, but we still have to wait for pending + * backup_do_cow() calls to complete. + */ qemu_co_rwlock_wrlock(&job->flush_rwlock); qemu_co_rwlock_unlock(&job->flush_rwlock); - g_free(job->done_bitmap); + + bdrv_remove_before_write_notifier(bs, &job->before_write); =20 data =3D g_malloc(sizeof(*data)); data->ret =3D ret; diff --git a/block/io.c b/block/io.c index 68f19bbe69..089866bb5e 100644 --- a/block/io.c +++ b/block/io.c @@ -2499,10 +2499,22 @@ bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEM= UIOVector *qiov) return true; } =20 +static QemuSpin notifiers_spin_lock; + void bdrv_add_before_write_notifier(BlockDriverState *bs, NotifierWithReturn *notifier) { + qemu_spin_lock(¬ifiers_spin_lock); notifier_with_return_list_add(&bs->before_write_notifiers, notifier); + qemu_spin_unlock(¬ifiers_spin_lock); +} + +void bdrv_remove_before_write_notifier(BlockDriverState *bs, + NotifierWithReturn *notifier) +{ + qemu_spin_lock(¬ifiers_spin_lock); + notifier_with_return_remove(notifier); + qemu_spin_unlock(¬ifiers_spin_lock); } =20 void bdrv_io_plug(BlockDriverState *bs) diff --git a/block/write-threshold.c b/block/write-threshold.c index 64ddd3d653..53c8caeda7 100644 --- a/block/write-threshold.c +++ b/block/write-threshold.c @@ -32,7 +32,7 @@ bool bdrv_write_threshold_is_set(const BlockDriverState *= bs) static void write_threshold_disable(BlockDriverState *bs) { if (bdrv_write_threshold_is_set(bs)) { - notifier_with_return_remove(&bs->write_threshold_notifier); + bdrv_remove_before_write_notifier(bs, &bs->write_threshold_notifie= r); bs->write_threshold_offset =3D 0; } } diff --git a/include/block/block_int.h b/include/block/block_int.h index 6d3fbbfc1e..173d9dcaf9 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -707,6 +707,8 @@ void bdrv_parse_filename_strip_prefix(const char *filen= ame, const char *prefix, =20 /** * bdrv_add_before_write_notifier: + * @bs: The #BlockDriverState for which to register the notifier + * @notifier: The notifier to add * * Register a callback that is invoked before write requests are processed= but * after any throttling or waiting for overlapping requests. @@ -715,6 +717,20 @@ void bdrv_add_before_write_notifier(BlockDriverState *= bs, NotifierWithReturn *notifier); =20 /** + * bdrv_remove_before_write_notifier: + * @bs: The #BlockDriverState for which to register the notifier + * @notifier: The notifier to add + * + * Unregister a callback that is invoked before write requests are process= ed but + * after any throttling or waiting for overlapping requests. + * + * Note that more I/O could be pending on @bs. You need to wait for + * it to finish, for example with bdrv_drain(), before freeing @notifier. + */ +void bdrv_remove_before_write_notifier(BlockDriverState *bs, + NotifierWithReturn *notifier); + +/** * bdrv_detach_aio_context: * * May be called from .bdrv_detach_aio_context() to detach children from t= he --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359494983143.69459819430142; Thu, 6 Jul 2017 09:44:54 -0700 (PDT) Received: from localhost ([::1]:52409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9td-0001pH-QD for importer@patchew.org; Thu, 06 Jul 2017 12:44:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nj-0004s9-1n for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9nh-00063i-Tr for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nf-00061V-DD; Thu, 06 Jul 2017 12:38:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5593D7D0C2; Thu, 6 Jul 2017 16:38:42 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34B2B53CD1; Thu, 6 Jul 2017 16:38:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5593D7D0C2 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5593D7D0C2 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:22 +0200 Message-Id: <20170706163828.24082-6-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 06 Jul 2017 16:38:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/11] block-backup: add reqs_lock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Protect the list of inflight reqs and the CoQueues for dependent requests. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block/backup.c | 20 +++++++++++++++----- block/replication.c | 2 +- include/block/block_backup.h | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/block/backup.c b/block/backup.c index 9214ffcc58..0ed7726fe6 100644 --- a/block/backup.c +++ b/block/backup.c @@ -45,6 +45,7 @@ typedef struct BackupBlockJob { bool compress; NotifierWithReturn before_write; QLIST_HEAD(, CowRequest) inflight_reqs; + CoMutex reqs_lock; } BackupBlockJob; =20 /* Size of a cluster in sectors, instead of bytes. */ @@ -61,16 +62,18 @@ static void coroutine_fn wait_for_overlapping_requests(= BackupBlockJob *job, CowRequest *req; bool retry; =20 + qemu_co_mutex_lock(&job->reqs_lock); do { retry =3D false; QLIST_FOREACH(req, &job->inflight_reqs, list) { if (end > req->start && start < req->end) { - qemu_co_queue_wait(&req->wait_queue, NULL); + qemu_co_queue_wait(&req->wait_queue, &job->reqs_lock); retry =3D true; break; } } } while (retry); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 /* Keep track of an in-flight request */ @@ -80,14 +83,18 @@ static void cow_request_begin(CowRequest *req, BackupBl= ockJob *job, req->start =3D start; req->end =3D end; qemu_co_queue_init(&req->wait_queue); + qemu_co_mutex_lock(&job->reqs_lock); QLIST_INSERT_HEAD(&job->inflight_reqs, req, list); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 /* Forget about a completed request */ -static void cow_request_end(CowRequest *req) +static void cow_request_end(CowRequest *req, BackupBlockJob *job) { + qemu_co_mutex_lock(&job->reqs_lock); QLIST_REMOVE(req, list); qemu_co_queue_restart_all(&req->wait_queue); + qemu_co_mutex_unlock(&job->reqs_lock); } =20 static int coroutine_fn backup_do_cow(BackupBlockJob *job, @@ -175,7 +182,7 @@ out: qemu_vfree(bounce_buffer); } =20 - cow_request_end(&cow_request); + cow_request_end(&cow_request, job); =20 trace_backup_do_cow_return(job, sector_num, nb_sectors, ret); =20 @@ -311,9 +318,11 @@ void backup_cow_request_begin(CowRequest *req, BlockJo= b *job, cow_request_begin(req, backup_job, start, end); } =20 -void backup_cow_request_end(CowRequest *req) +void backup_cow_request_end(CowRequest *req, BlockJob *job) { - cow_request_end(req); + BackupBlockJob *backup_job =3D container_of(job, BackupBlockJob, commo= n); + + cow_request_end(req, backup_job); } =20 static void backup_drain(BlockJob *job) @@ -653,6 +662,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, goto error; } =20 + qemu_co_mutex_init(&job->reqs_lock); job->on_source_error =3D on_source_error; job->on_target_error =3D on_target_error; job->sync_mode =3D sync_mode; diff --git a/block/replication.c b/block/replication.c index 3885f04c31..5d6e2ec916 100644 --- a/block/replication.c +++ b/block/replication.c @@ -240,7 +240,7 @@ static coroutine_fn int replication_co_readv(BlockDrive= rState *bs, remaining_sectors); ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov); - backup_cow_request_end(&req); + backup_cow_request_end(&req, child->bs->job); goto out; } =20 diff --git a/include/block/block_backup.h b/include/block/block_backup.h index 8a759477a3..2fe0cdd808 100644 --- a/include/block/block_backup.h +++ b/include/block/block_backup.h @@ -32,7 +32,7 @@ void backup_wait_for_overlapping_requests(BlockJob *job, = int64_t sector_num, void backup_cow_request_begin(CowRequest *req, BlockJob *job, int64_t sector_num, int nb_sectors); -void backup_cow_request_end(CowRequest *req); +void backup_cow_request_end(CowRequest *req, BlockJob *job); =20 void backup_do_checkpoint(BlockJob *job, Error **errp); =20 --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359511057830.1923550884641; Thu, 6 Jul 2017 09:45:11 -0700 (PDT) Received: from localhost ([::1]:52410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9tt-000229-Qp for importer@patchew.org; Thu, 06 Jul 2017 12:45:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nj-0004sX-Dt for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9ni-00064L-MZ for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9ng-00062W-SR; Thu, 06 Jul 2017 12:38:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C60C07F3E3; Thu, 6 Jul 2017 16:38:43 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A519060A9D; Thu, 6 Jul 2017 16:38:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C60C07F3E3 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C60C07F3E3 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:23 +0200 Message-Id: <20170706163828.24082-7-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Jul 2017 16:38:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/11] block: add a few more notes on locking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 173d9dcaf9..43c9f4fcae 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -114,7 +114,9 @@ struct BlockDriver { /* Set if a driver can support backing files */ bool supports_backing; =20 - /* For handling image reopen for split or non-split files */ + /* For handling image reopen for split or non-split files. Called + * with no I/O pending. + */ int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state); @@ -125,11 +127,13 @@ struct BlockDriver { Error **errp); int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, Error **errp); - void (*bdrv_close)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QemuOpts *opts, Error **errp); - int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); =20 + /* Called from main thread. */ + void (*bdrv_close)(BlockDriverState *bs); + int (*bdrv_set_key)(BlockDriverState *bs, const char *key); + void (*bdrv_refresh_filename)(BlockDriverState *bs, QDict *options); =20 /* aio */ --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359397440230.77541648089846; Thu, 6 Jul 2017 09:43:17 -0700 (PDT) Received: from localhost ([::1]:52401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9s1-00008O-7y for importer@patchew.org; Thu, 06 Jul 2017 12:43:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9np-0004yD-C4 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9no-00067C-Cu for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39828) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9ni-00063T-Cc; Thu, 06 Jul 2017 12:38:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40D295F7B6; Thu, 6 Jul 2017 16:38:45 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2036A60A9D; Thu, 6 Jul 2017 16:38:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 40D295F7B6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 40D295F7B6 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:24 +0200 Message-Id: <20170706163828.24082-8-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 06 Jul 2017 16:38:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/11] block: do not acquire AioContext in check_to_replace_node X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The only caller does it already. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- block.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index 694396281b..af0a9a1c22 100644 --- a/block.c +++ b/block.c @@ -4701,23 +4701,19 @@ bool bdrv_is_first_non_filter(BlockDriverState *can= didate) return false; } =20 +/* Called with AioContext lock held. */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **err= p) { BlockDriverState *to_replace_bs =3D bdrv_find_node(node_name); - AioContext *aio_context; =20 if (!to_replace_bs) { error_setg(errp, "Node name '%s' not found", node_name); return NULL; } =20 - aio_context =3D bdrv_get_aio_context(to_replace_bs); - aio_context_acquire(aio_context); - if (bdrv_op_is_blocked(to_replace_bs, BLOCK_OP_TYPE_REPLACE, errp)) { - to_replace_bs =3D NULL; - goto out; + return NULL; } =20 /* We don't want arbitrary node of the BDS chain to be replaced only t= he top @@ -4727,12 +4723,9 @@ BlockDriverState *check_to_replace_node(BlockDriverS= tate *parent_bs, */ if (!bdrv_recurse_is_first_non_filter(parent_bs, to_replace_bs)) { error_setg(errp, "Only top most non filter can be replaced"); - to_replace_bs =3D NULL; - goto out; + return NULL; } =20 -out: - aio_context_release(aio_context); return to_replace_bs; } =20 --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359514603582.497976924945; Thu, 6 Jul 2017 09:45:14 -0700 (PDT) Received: from localhost ([::1]:52411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9tu-00022Y-IT for importer@patchew.org; Thu, 06 Jul 2017 12:45:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33245) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nq-0004z9-2N for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9np-00067U-Ap for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nj-00064c-QZ; Thu, 06 Jul 2017 12:38:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B787C5F7B6; Thu, 6 Jul 2017 16:38:46 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 907F160A9D; Thu, 6 Jul 2017 16:38:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B787C5F7B6 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B787C5F7B6 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:25 +0200 Message-Id: <20170706163828.24082-9-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 06 Jul 2017 16:38:46 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/11] block: drain I/O around key management X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The resulting drained section is a replacement for the AioContext. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- blockdev.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/blockdev.c b/blockdev.c index f92dcf24bf..b2c305402d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2253,7 +2253,6 @@ void qmp_block_passwd(bool has_device, const char *de= vice, { Error *local_err =3D NULL; BlockDriverState *bs; - AioContext *aio_context; =20 bs =3D bdrv_lookup_bs(has_device ? device : NULL, has_node_name ? node_name : NULL, @@ -2263,12 +2262,9 @@ void qmp_block_passwd(bool has_device, const char *d= evice, return; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - + bdrv_drained_begin(bs); bdrv_add_key(bs, password, errp); - - aio_context_release(aio_context); + bdrv_drained_end(bs); } =20 /* --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359615724697.1888112118387; Thu, 6 Jul 2017 09:46:55 -0700 (PDT) Received: from localhost ([::1]:52420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9vZ-0003K3-6E for importer@patchew.org; Thu, 06 Jul 2017 12:46:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33260) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nr-00050f-DO for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9np-00067y-W4 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:38:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nl-00065j-Fd; Thu, 06 Jul 2017 12:38:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 666F94DD49; Thu, 6 Jul 2017 16:38:48 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F21660A9D; Thu, 6 Jul 2017 16:38:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 666F94DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 666F94DD49 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:26 +0200 Message-Id: <20170706163828.24082-10-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 06 Jul 2017 16:38:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/11] block/replication: do not acquire AioContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Replication functions are mostly called when the BDS is quiescent and does not have any pending I/O. They do not need to synchronize on anything since BDS and BB are now thread-safe. Signed-off-by: Paolo Bonzini --- block/replication.c | 51 ++++++++++++-------------------------------------= -- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/block/replication.c b/block/replication.c index 5d6e2ec916..7a3b94b90f 100644 --- a/block/replication.c +++ b/block/replication.c @@ -41,6 +41,8 @@ typedef struct BDRVReplicationState { Error *blocker; int orig_hidden_flags; int orig_secondary_flags; + + /* This field is accessed asynchronously. */ int error; } BDRVReplicationState; =20 @@ -201,7 +203,7 @@ static int replication_return_value(BDRVReplicationStat= e *s, int ret) } =20 if (ret < 0) { - s->error =3D ret; + atomic_set(&s->error, ret); ret =3D 0; } =20 @@ -311,6 +313,7 @@ static bool replication_recurse_is_first_non_filter(Blo= ckDriverState *bs, return bdrv_recurse_is_first_non_filter(bs->file->bs, candidate); } =20 +/* Called with no I/O pending. */ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { Error *local_err =3D NULL; @@ -405,7 +408,7 @@ static void backup_job_completed(void *opaque, int ret) =20 if (s->stage !=3D BLOCK_REPLICATION_FAILOVER) { /* The backup job is cancelled unexpectedly */ - s->error =3D -EIO; + atomic_set(&s->error, -EIO); } =20 backup_job_cleanup(bs); @@ -430,6 +433,7 @@ static bool check_top_bs(BlockDriverState *top_bs, Bloc= kDriverState *bs) return false; } =20 +/* Called with no I/O pending. */ static void replication_start(ReplicationState *rs, ReplicationMode mode, Error **errp) { @@ -437,24 +441,19 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, BDRVReplicationState *s; BlockDriverState *top_bs; int64_t active_length, hidden_length, disk_length; - AioContext *aio_context; Error *local_err =3D NULL; BlockJob *job; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); - aio_context_release(aio_context); return; } =20 if (s->mode !=3D mode) { error_setg(errp, "The parameter mode's value is invalid, needs %d," " but got %d", s->mode, mode); - aio_context_release(aio_context); return; } =20 @@ -466,21 +465,18 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, if (!s->active_disk || !s->active_disk->bs || !s->active_disk->bs->backing) { error_setg(errp, "Active disk doesn't have backing file"); - aio_context_release(aio_context); return; } =20 s->hidden_disk =3D s->active_disk->bs->backing; if (!s->hidden_disk->bs || !s->hidden_disk->bs->backing) { error_setg(errp, "Hidden disk doesn't have backing file"); - aio_context_release(aio_context); return; } =20 s->secondary_disk =3D s->hidden_disk->bs->backing; if (!s->secondary_disk->bs || !bdrv_has_blk(s->secondary_disk->bs)= ) { error_setg(errp, "The secondary disk doesn't have block backen= d"); - aio_context_release(aio_context); return; } =20 @@ -492,7 +488,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, active_length !=3D hidden_length || hidden_length !=3D disk_le= ngth) { error_setg(errp, "Active disk, hidden disk, secondary disk's l= ength" " are not the same"); - aio_context_release(aio_context); return; } =20 @@ -500,7 +495,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, !s->hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_em= pty"); - aio_context_release(aio_context); return; } =20 @@ -508,7 +502,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, reopen_backing_file(bs, true, &local_err); if (local_err) { error_propagate(errp, local_err); - aio_context_release(aio_context); return; } =20 @@ -521,7 +514,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, !check_top_bs(top_bs, bs)) { error_setg(errp, "No top_bs or it is invalid"); reopen_backing_file(bs, false, NULL); - aio_context_release(aio_context); return; } bdrv_op_block_all(top_bs, s->blocker); @@ -535,13 +527,11 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, if (local_err) { error_propagate(errp, local_err); backup_job_cleanup(bs); - aio_context_release(aio_context); return; } block_job_start(job); break; default: - aio_context_release(aio_context); abort(); } =20 @@ -551,48 +541,38 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, secondary_do_checkpoint(s, errp); } =20 - s->error =3D 0; - aio_context_release(aio_context); + atomic_set(&s->error, 0); } =20 +/* Called with no I/O pending. */ static void replication_do_checkpoint(ReplicationState *rs, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->mode =3D=3D REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); } - aio_context_release(aio_context); } =20 static void replication_get_error(ReplicationState *rs, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } =20 - if (s->error) { + if (atomic_read(&s->error)) { error_setg(errp, "I/O error occurred"); - aio_context_release(aio_context); return; } - aio_context_release(aio_context); } =20 static void replication_done(void *opaque, int ret) @@ -608,10 +588,10 @@ static void replication_done(void *opaque, int ret) s->active_disk =3D NULL; s->secondary_disk =3D NULL; s->hidden_disk =3D NULL; - s->error =3D 0; + atomic_set(&s->error, 0); } else { s->stage =3D BLOCK_REPLICATION_FAILOVER_FAILED; - s->error =3D -EIO; + atomic_set(&s->error, -EIO); } } =20 @@ -619,22 +599,18 @@ static void replication_stop(ReplicationState *rs, bo= ol failover, Error **errp) { BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage !=3D BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } =20 switch (s->mode) { case REPLICATION_MODE_PRIMARY: s->stage =3D BLOCK_REPLICATION_DONE; - s->error =3D 0; + atomic_set(&s->error, 0); break; case REPLICATION_MODE_SECONDARY: /* @@ -649,7 +625,6 @@ static void replication_stop(ReplicationState *rs, bool= failover, Error **errp) if (!failover) { secondary_do_checkpoint(s, errp); s->stage =3D BLOCK_REPLICATION_DONE; - aio_context_release(aio_context); return; } =20 @@ -659,10 +634,8 @@ static void replication_stop(ReplicationState *rs, boo= l failover, Error **errp) NULL, replication_done, bs, true, errp); break; default: - aio_context_release(aio_context); abort(); } - aio_context_release(aio_context); } =20 BlockDriver bdrv_replication =3D { --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359264526184.46211808361045; Thu, 6 Jul 2017 09:41:04 -0700 (PDT) Received: from localhost ([::1]:52391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9pr-0006TW-29 for importer@patchew.org; Thu, 06 Jul 2017 12:40:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9nz-00058U-H0 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:39:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9nu-0006At-Im for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:39:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38756) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nr-00068F-63; Thu, 06 Jul 2017 12:38:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 207BB90907; Thu, 6 Jul 2017 16:38:54 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84A7353CD1; Thu, 6 Jul 2017 16:38:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 207BB90907 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 207BB90907 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:27 +0200 Message-Id: <20170706163828.24082-11-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 06 Jul 2017 16:38:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/11] block: do not take AioContext around reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reopen needs to handle AioContext carefully due to calling bdrv_drain_all_begin/end. By not taking AioContext around calls to bdrv_reopen_multiple, we can drop the function's release/acquire pair and the AioContext argument too. Signed-off-by: Paolo Bonzini --- block.c | 6 ++---- block/block-backend.c | 5 ----- block/commit.c | 2 +- block/mirror.c | 9 --------- block/replication.c | 3 +-- blockdev.c | 19 ++++++------------- include/block/block.h | 2 +- qemu-io-cmds.c | 2 +- 8 files changed, 12 insertions(+), 36 deletions(-) diff --git a/block.c b/block.c index af0a9a1c22..4bf6ab11f7 100644 --- a/block.c +++ b/block.c @@ -2793,7 +2793,7 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue = *bs_queue, * to all devices. * */ -int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp) +int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) { int ret =3D -1; BlockReopenQueueEntry *bs_entry, *next; @@ -2801,9 +2801,7 @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReopen= Queue *bs_queue, Error **er =20 assert(bs_queue !=3D NULL); =20 - aio_context_release(ctx); bdrv_drain_all_begin(); - aio_context_acquire(ctx); =20 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, &local_err)) { @@ -2847,7 +2845,7 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags,= Error **errp) Error *local_err =3D NULL; BlockReopenQueue *queue =3D bdrv_reopen_queue(NULL, bs, NULL, bdrv_fla= gs); =20 - ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_e= rr); + ret =3D bdrv_reopen_multiple(queue, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); } diff --git a/block/block-backend.c b/block/block-backend.c index 0df3457a09..0ce1fb1c26 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1888,17 +1888,12 @@ int blk_commit_all(void) BlockBackend *blk =3D NULL; =20 while ((blk =3D blk_all_next(blk)) !=3D NULL) { - AioContext *aio_context =3D blk_get_aio_context(blk); - - aio_context_acquire(aio_context); if (blk_is_inserted(blk) && blk->root->bs->backing) { int ret =3D bdrv_commit(blk->root->bs); if (ret < 0) { - aio_context_release(aio_context); return ret; } } - aio_context_release(aio_context); } return 0; } diff --git a/block/commit.c b/block/commit.c index 8c09c3dbcd..1fe67fa8db 100644 --- a/block/commit.c +++ b/block/commit.c @@ -335,7 +335,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, orig_overlay_flags | BDRV_O_RDWR); } if (reopen_queue) { - bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &loca= l_err); + bdrv_reopen_multiple(reopen_queue, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); goto fail; diff --git a/block/mirror.c b/block/mirror.c index 68744a17e8..804edbad21 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -505,7 +505,6 @@ static void mirror_exit(BlockJob *job, void *opaque) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common); MirrorExitData *data =3D opaque; - AioContext *replace_aio_context =3D NULL; BlockDriverState *src =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); BlockDriverState *mirror_top_bs =3D s->mirror_top_bs; @@ -545,11 +544,6 @@ static void mirror_exit(BlockJob *job, void *opaque) } } =20 - if (s->to_replace) { - replace_aio_context =3D bdrv_get_aio_context(s->to_replace); - aio_context_acquire(replace_aio_context); - } - if (s->should_complete && data->ret =3D=3D 0) { BlockDriverState *to_replace =3D src; if (s->to_replace) { @@ -575,9 +569,6 @@ static void mirror_exit(BlockJob *job, void *opaque) error_free(s->replace_blocker); bdrv_unref(s->to_replace); } - if (replace_aio_context) { - aio_context_release(replace_aio_context); - } g_free(s->replaces); bdrv_unref(target_bs); =20 diff --git a/block/replication.c b/block/replication.c index 7a3b94b90f..9350ef100b 100644 --- a/block/replication.c +++ b/block/replication.c @@ -381,8 +381,7 @@ static void reopen_backing_file(BlockDriverState *bs, b= ool writable, } =20 if (reopen_queue) { - bdrv_reopen_multiple(bdrv_get_aio_context(bs), - reopen_queue, &local_err); + bdrv_reopen_multiple(reopen_queue, &local_err); error_propagate(errp, local_err); } } diff --git a/blockdev.c b/blockdev.c index b2c305402d..88ab606949 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3710,7 +3710,6 @@ void qmp_change_backing_file(const char *device, Error **errp) { BlockDriverState *bs =3D NULL; - AioContext *aio_context; BlockDriverState *image_bs =3D NULL; Error *local_err =3D NULL; bool ro; @@ -3722,37 +3721,34 @@ void qmp_change_backing_file(const char *device, return; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - image_bs =3D bdrv_lookup_bs(NULL, image_node_name, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; + return; } =20 if (!image_bs) { error_setg(errp, "image file not found"); - goto out; + return; } =20 if (bdrv_find_base(image_bs) =3D=3D image_bs) { error_setg(errp, "not allowing backing file change on an image " "without a backing file"); - goto out; + return; } =20 /* even though we are not necessarily operating on bs, we need it to * determine if block ops are currently prohibited on the chain */ if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_CHANGE, errp)) { - goto out; + return; } =20 /* final sanity check */ if (!bdrv_chain_contains(bs, image_bs)) { error_setg(errp, "'%s' and image file are not in the same chain", device); - goto out; + return; } =20 /* if not r/w, reopen to make r/w */ @@ -3763,7 +3759,7 @@ void qmp_change_backing_file(const char *device, bdrv_reopen(image_bs, open_flags | BDRV_O_RDWR, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; + return; } } =20 @@ -3781,9 +3777,6 @@ void qmp_change_backing_file(const char *device, bdrv_reopen(image_bs, open_flags, &local_err); error_propagate(errp, local_err); } - -out: - aio_context_release(aio_context); } =20 void hmp_drive_add_node(Monitor *mon, const char *optstr) diff --git a/include/block/block.h b/include/block/block.h index 85e4be7462..f533f80f1f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -265,7 +265,7 @@ BlockDriverState *bdrv_new_open_driver(BlockDriver *drv= , const char *node_name, BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, QDict *options, int flags); -int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp); +int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp); int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp); int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index b0ea327024..19d3114542 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2006,7 +2006,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) qemu_opts_reset(&reopen_opts); =20 brq =3D bdrv_reopen_queue(NULL, bs, opts, flags); - bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); + bdrv_reopen_multiple(brq, &local_err); if (local_err) { error_report_err(local_err); } else { --=20 2.13.0 From nobody Wed Nov 5 07:34:32 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499359626471307.82726553442865; Thu, 6 Jul 2017 09:47:06 -0700 (PDT) Received: from localhost ([::1]:52421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9vj-0003Of-Rs for importer@patchew.org; Thu, 06 Jul 2017 12:47:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dT9o1-0005AP-Ig for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:39:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dT9nz-0006E6-N7 for qemu-devel@nongnu.org; Thu, 06 Jul 2017 12:39:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46910) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dT9nt-00069P-3G; Thu, 06 Jul 2017 12:38:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CC4C4DD49; Thu, 6 Jul 2017 16:38:56 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-229.ams2.redhat.com [10.36.117.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7075C60A9D; Thu, 6 Jul 2017 16:38:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0CC4C4DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=pbonzini@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0CC4C4DD49 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 6 Jul 2017 18:38:28 +0200 Message-Id: <20170706163828.24082-12-pbonzini@redhat.com> In-Reply-To: <20170706163828.24082-1-pbonzini@redhat.com> References: <20170706163828.24082-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 06 Jul 2017 16:38:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/11] block/snapshot: do not take AioContext lock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Snapshots are only created/destroyed/loaded under the BQL, while no other I/O is happening. Snapshot information could be accessed while other I/O is happening, but also under the BQL so they cannot be modified concurrently. The AioContext lock is overkill. If needed, in the future the BQL could be split to a separate lock covering all snapshot operations, and the create/destroy/goto callbacks changed to run in a coroutine (so the driver can do mutual exclusion as usual). Signed-off-by: Paolo Bonzini --- block/snapshot.c | 28 +--------------------------- blockdev.c | 43 ++++++++++++------------------------------- hmp.c | 7 ------- include/block/block_int.h | 5 +++++ include/block/snapshot.h | 4 +--- migration/savevm.c | 22 ---------------------- monitor.c | 10 ++-------- 7 files changed, 21 insertions(+), 98 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index a46564e7b7..08c59d6166 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -384,9 +384,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverSta= te *bs, } =20 =20 -/* Group operations. All block drivers are involved. - * These functions will properly handle dataplane (take aio_context_acquire - * when appropriate for appropriate block drivers) */ +/* Group operations. All block drivers are involved. */ =20 bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs) { @@ -395,13 +393,9 @@ bool bdrv_all_can_snapshot(BlockDriverState **first_ba= d_bs) BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); if (bdrv_is_inserted(bs) && !bdrv_is_read_only(bs)) { ok =3D bdrv_can_snapshot(bs); } - aio_context_release(ctx); if (!ok) { goto fail; } @@ -421,14 +415,10 @@ int bdrv_all_delete_snapshot(const char *name, BlockD= riverState **first_bad_bs, QEMUSnapshotInfo sn1, *snapshot =3D &sn1; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); if (bdrv_can_snapshot(bs) && bdrv_snapshot_find(bs, snapshot, name) >=3D 0) { ret =3D bdrv_snapshot_delete_by_id_or_name(bs, name, err); } - aio_context_release(ctx); if (ret < 0) { goto fail; } @@ -447,13 +437,9 @@ int bdrv_all_goto_snapshot(const char *name, BlockDriv= erState **first_bad_bs) BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); if (bdrv_can_snapshot(bs)) { err =3D bdrv_snapshot_goto(bs, name); } - aio_context_release(ctx); if (err < 0) { goto fail; } @@ -472,13 +458,9 @@ int bdrv_all_find_snapshot(const char *name, BlockDriv= erState **first_bad_bs) BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); if (bdrv_can_snapshot(bs)) { err =3D bdrv_snapshot_find(bs, &sn, name); } - aio_context_release(ctx); if (err < 0) { goto fail; } @@ -499,9 +481,6 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); if (bs =3D=3D vm_state_bs) { sn->vm_state_size =3D vm_state_size; err =3D bdrv_snapshot_create(bs, sn); @@ -509,7 +488,6 @@ int bdrv_all_create_snapshot(QEMUSnapshotInfo *sn, sn->vm_state_size =3D 0; err =3D bdrv_snapshot_create(bs, sn); } - aio_context_release(ctx); if (err < 0) { goto fail; } @@ -526,13 +504,9 @@ BlockDriverState *bdrv_all_find_vmstate_bs(void) BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - AioContext *ctx =3D bdrv_get_aio_context(bs); bool found; =20 - aio_context_acquire(ctx); found =3D bdrv_can_snapshot(bs); - aio_context_release(ctx); - if (found) { break; } diff --git a/blockdev.c b/blockdev.c index 88ab606949..56ef9c41a3 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1280,7 +1280,6 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_s= ync(const char *device, Error **errp) { BlockDriverState *bs; - AioContext *aio_context; QEMUSnapshotInfo sn; Error *local_err =3D NULL; SnapshotInfo *info =3D NULL; @@ -1290,8 +1289,6 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_s= ync(const char *device, if (!bs) { return NULL; } - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); =20 if (!has_id) { id =3D NULL; @@ -1303,34 +1300,32 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal= _sync(const char *device, =20 if (!id && !name) { error_setg(errp, "Name or id must be provided"); - goto out_aio_context; + return NULL; } =20 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE, err= p)) { - goto out_aio_context; + return NULL; } =20 ret =3D bdrv_snapshot_find_by_id_and_name(bs, id, name, &sn, &local_er= r); if (local_err) { error_propagate(errp, local_err); - goto out_aio_context; + return NULL; } if (!ret) { error_setg(errp, "Snapshot with id '%s' and name '%s' does not exist on " "device '%s'", STR_OR_NULL(id), STR_OR_NULL(name), device); - goto out_aio_context; + return NULL; } =20 bdrv_snapshot_delete(bs, id, name, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out_aio_context; + return NULL; } =20 - aio_context_release(aio_context); - info =3D g_new0(SnapshotInfo, 1); info->id =3D g_strdup(sn.id_str); info->name =3D g_strdup(sn.name); @@ -1341,10 +1336,6 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_= sync(const char *device, info->vm_clock_sec =3D sn.vm_clock_nsec / 1000000000; =20 return info; - -out_aio_context: - aio_context_release(aio_context); - return NULL; } =20 /** @@ -1446,7 +1437,6 @@ struct BlkActionState { typedef struct InternalSnapshotState { BlkActionState common; BlockDriverState *bs; - AioContext *aio_context; QEMUSnapshotInfo sn; bool created; } InternalSnapshotState; @@ -1498,10 +1488,6 @@ static void internal_snapshot_prepare(BlkActionState= *common, return; } =20 - /* AioContext is released in .clean() */ - state->aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(state->aio_context); - state->bs =3D bs; bdrv_drained_begin(bs); =20 @@ -1585,11 +1571,8 @@ static void internal_snapshot_clean(BlkActionState *= common) InternalSnapshotState *state =3D DO_UPCAST(InternalSnapshotState, common, common); =20 - if (state->aio_context) { - if (state->bs) { - bdrv_drained_end(state->bs); - } - aio_context_release(state->aio_context); + if (state->bs) { + bdrv_drained_end(state->bs); } } =20 @@ -1598,7 +1581,6 @@ typedef struct ExternalSnapshotState { BlkActionState common; BlockDriverState *old_bs; BlockDriverState *new_bs; - AioContext *aio_context; bool overlay_appended; } ExternalSnapshotState; =20 @@ -1654,9 +1636,7 @@ static void external_snapshot_prepare(BlkActionState = *common, return; } =20 - /* Acquire AioContext now so any threads operating on old_bs stop */ - state->aio_context =3D bdrv_get_aio_context(state->old_bs); - aio_context_acquire(state->aio_context); + /* Make any threads operating on old_bs stop */ bdrv_drained_begin(state->old_bs); =20 if (!bdrv_is_inserted(state->old_bs)) { @@ -1756,7 +1736,7 @@ static void external_snapshot_prepare(BlkActionState = *common, return; } =20 - bdrv_set_aio_context(state->new_bs, state->aio_context); + bdrv_set_aio_context(state->new_bs, bdrv_get_aio_context(state->old_bs= )); =20 /* This removes our old bs and adds the new bs. This is an operation t= hat * can fail, so we need to do it in .prepare; undoing it for abort is @@ -1775,6 +1755,8 @@ static void external_snapshot_commit(BlkActionState *= common) ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); =20 + bdrv_set_aio_context(state->new_bs, bdrv_get_aio_context(state->old_bs= )); + /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ @@ -1803,9 +1785,8 @@ static void external_snapshot_clean(BlkActionState *c= ommon) { ExternalSnapshotState *state =3D DO_UPCAST(ExternalSnapshotState, common, comm= on); - if (state->aio_context) { + if (state->old_bs) { bdrv_drained_end(state->old_bs); - aio_context_release(state->aio_context); bdrv_unref(state->new_bs); } } diff --git a/hmp.c b/hmp.c index 8c72c58b20..3c63ea7a72 100644 --- a/hmp.c +++ b/hmp.c @@ -1321,7 +1321,6 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qd= ict) int nb_sns, i; int total; int *global_snapshots; - AioContext *aio_context; =20 typedef struct SnapshotEntry { QEMUSnapshotInfo sn; @@ -1345,11 +1344,8 @@ void hmp_info_snapshots(Monitor *mon, const QDict *q= dict) monitor_printf(mon, "No available block device supports snapshots\= n"); return; } - aio_context =3D bdrv_get_aio_context(bs); =20 - aio_context_acquire(aio_context); nb_sns =3D bdrv_snapshot_list(bs, &sn_tab); - aio_context_release(aio_context); =20 if (nb_sns < 0) { monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); @@ -1360,9 +1356,7 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qd= ict) int bs1_nb_sns =3D 0; ImageEntry *ie; SnapshotEntry *se; - AioContext *ctx =3D bdrv_get_aio_context(bs1); =20 - aio_context_acquire(ctx); if (bdrv_can_snapshot(bs1)) { sn =3D NULL; bs1_nb_sns =3D bdrv_snapshot_list(bs1, &sn); @@ -1380,7 +1374,6 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qd= ict) } g_free(sn); } - aio_context_release(ctx); } =20 if (no_snapshot) { diff --git a/include/block/block_int.h b/include/block/block_int.h index 43c9f4fcae..38d1067fa8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -217,6 +217,11 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov); =20 + /* + * Snapshots are only created/destroyed/loaded under the BQL, while no + * other I/O is happening. snapshots/nb_snapshots is read while other + * I/O is happening, but also under the BQL. + */ int (*bdrv_snapshot_create)(BlockDriverState *bs, QEMUSnapshotInfo *sn_info); int (*bdrv_snapshot_goto)(BlockDriverState *bs, diff --git a/include/block/snapshot.h b/include/block/snapshot.h index e5c0553115..735d0f694c 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -76,9 +76,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState= *bs, Error **errp); =20 =20 -/* Group operations. All block drivers are involved. - * These functions will properly handle dataplane (take aio_context_acquire - * when appropriate for appropriate block drivers */ +/* Group operations. All block drivers are involved. */ =20 bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs); int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bs= d_bs, diff --git a/migration/savevm.c b/migration/savevm.c index c7a49c93c5..1b168c3ba8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2073,7 +2073,6 @@ int save_snapshot(const char *name, Error **errp) uint64_t vm_state_size; qemu_timeval tv; struct tm tm; - AioContext *aio_context; =20 if (!bdrv_all_can_snapshot(&bs)) { error_setg(errp, "Device '%s' is writable but does not support " @@ -2096,7 +2095,6 @@ int save_snapshot(const char *name, Error **errp) error_setg(errp, "No block device can accept snapshots"); return ret; } - aio_context =3D bdrv_get_aio_context(bs); =20 saved_vm_running =3D runstate_is_running(); =20 @@ -2109,8 +2107,6 @@ int save_snapshot(const char *name, Error **errp) =20 bdrv_drain_all_begin(); =20 - aio_context_acquire(aio_context); - memset(sn, 0, sizeof(*sn)); =20 /* fill auxiliary fields */ @@ -2146,14 +2142,6 @@ int save_snapshot(const char *name, Error **errp) goto the_end; } =20 - /* The bdrv_all_create_snapshot() call that follows acquires the AioCo= ntext - * for itself. BDRV_POLL_WHILE() does not support nested locking beca= use - * it only releases the lock once. Therefore synchronous I/O will dea= dlock - * unless we release the AioContext before bdrv_all_create_snapshot(). - */ - aio_context_release(aio_context); - aio_context =3D NULL; - ret =3D bdrv_all_create_snapshot(sn, bs, vm_state_size, &bs); if (ret < 0) { error_setg(errp, "Error while creating snapshot on '%s'", @@ -2164,10 +2152,6 @@ int save_snapshot(const char *name, Error **errp) ret =3D 0; =20 the_end: - if (aio_context) { - aio_context_release(aio_context); - } - bdrv_drain_all_end(); =20 if (saved_vm_running) { @@ -2241,7 +2225,6 @@ int load_snapshot(const char *name, Error **errp) QEMUSnapshotInfo sn; QEMUFile *f; int ret; - AioContext *aio_context; MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 if (!bdrv_all_can_snapshot(&bs)) { @@ -2263,12 +2246,9 @@ int load_snapshot(const char *name, Error **errp) error_setg(errp, "No block device supports snapshots"); return -ENOTSUP; } - aio_context =3D bdrv_get_aio_context(bs_vm_state); =20 /* Don't even try to load empty VM states */ - aio_context_acquire(aio_context); ret =3D bdrv_snapshot_find(bs_vm_state, &sn, name); - aio_context_release(aio_context); if (ret < 0) { return ret; } else if (sn.vm_state_size =3D=3D 0) { @@ -2298,10 +2278,8 @@ int load_snapshot(const char *name, Error **errp) qemu_system_reset(SHUTDOWN_CAUSE_NONE); mis->from_src_file =3D f; =20 - aio_context_acquire(aio_context); ret =3D qemu_loadvm_state(f); migration_incoming_state_destroy(); - aio_context_release(aio_context); =20 bdrv_drain_all_end(); =20 diff --git a/monitor.c b/monitor.c index 3c369f4dd5..48687aa94d 100644 --- a/monitor.c +++ b/monitor.c @@ -3639,15 +3639,9 @@ static void vm_completion(ReadLineState *rs, const c= har *str) =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { SnapshotInfoList *snapshots, *snapshot; - AioContext *ctx =3D bdrv_get_aio_context(bs); - bool ok =3D false; =20 - aio_context_acquire(ctx); - if (bdrv_can_snapshot(bs)) { - ok =3D bdrv_query_snapshot_info_list(bs, &snapshots, NULL) =3D= =3D 0; - } - aio_context_release(ctx); - if (!ok) { + if (!bdrv_can_snapshot(bs) || + bdrv_query_snapshot_info_list(bs, &snapshots, NULL) !=3D 0) { continue; } =20 --=20 2.13.0