From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822659; cv=none; d=zohomail.com; s=zohoarc; b=SsY+IrTozSxqTPlq2rDMpWeG742KZLhFyuChNG36vsnL3mFSxxFp9Ojc1viqK1xuAlsM2hk6/OdMY1KDH6UWRbslDMQEvHSddMv78mfsojxg3cfFcW2WYJkRWq7mwAhy4lJM3GN8ENWInuGLuKZ01145D4IgwHLoX01+OtIpmaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822659; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DkWiMkt5sIbge2AcrwiT02/uD6ZmQ+1LR8tOvXPaAks=; b=I6fPvTNYCIbzLqt0SIXWnXm5zJ9ReRkKpF1/M1pr457ZHGqgb79sQRFtSxwXuO5rM9AIi1aRfNPT68/Q2LB5ru+Uh6/F34/OzGm3vefvwJwiu9MmhCQAjbBVrqFBfpObEiD4q+oKROGg9qgVTOwL9TddtgCXS1tu2k78KNIrnDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822659464136.60853049777324; Mon, 19 Apr 2021 01:57:39 -0700 (PDT) Received: from localhost ([::1]:33548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPis-0002VT-CE for importer@patchew.org; Mon, 19 Apr 2021 04:57:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhI-0000XQ-2k for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24382) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhF-0000tm-PF for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:55:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-crUD8v1KPg2OvxqZ9KaQxQ-1; Mon, 19 Apr 2021 04:55:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 234F883DD2B; Mon, 19 Apr 2021 08:55:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 987EB5D742; Mon, 19 Apr 2021 08:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DkWiMkt5sIbge2AcrwiT02/uD6ZmQ+1LR8tOvXPaAks=; b=cp1yxftu5XUKEy0YqLU8cISbOBLPGE7eLDSeJbG2r1x0cuHmRGCj8LNYKO8XZHr2gEY/CA mnV2/2JqfeVz3yKEBQlJi7Odxrl8RRGu+oQ7o5Yao4uFBgmEXQRD4OxnFC+aFg3Q/EeTuR puJ9lAicGkcYjyug5zE/OYpmrgxv0J0= X-MC-Unique: crUD8v1KPg2OvxqZ9KaQxQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 1/8] block: prepare write threshold code for thread safety Date: Mon, 19 Apr 2021 10:55:34 +0200 Message-Id: <20210419085541.22310-2-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: Stefan Hajnoczi Co-developed-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- 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 85b78dc2a9..63040fa4f2 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 treshold_overage(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 treshold_overage(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 treshold_overage(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); =20 /* autodisable to avoid flooding the monitor */ write_threshold_disable(bs); --=20 2.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822651; cv=none; d=zohomail.com; s=zohoarc; b=kGSa/P5+FZr1BK9orUBcybH4FKIWN9IicuW0CjhEhq6yZaHR8ssVXbwmcqkeY2SjHo833oiI3L8nACKZxCaha+GMqhWp59WlSD748R/C2c9lLm6wNqk+tVY/27tHAt9+kQ5Wrag3z0ouOcUR02+bYHNJN62X7BwQqT1EJZeYkno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822651; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F7NwFsCFY1ZCxrd9bRPmNUOXiKGCgh0XcDto2jSEUCQ=; b=lLS0cCV9DQRWFLYVpe5rTNvsNLKTTiEO+eaLk5BiYNwQ5DM2RbupbBza780nfqAwlfpdJRNl+JpLDdPoGVHTC5egepJkTnDsWc2a+zO1+E2zsvg3SLt7cRQ2NG4kVvmBRspdKcynamLwSVOsv1ylT6TlY8X8/2iUu92Qub8b6mc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822651402363.64738544226077; Mon, 19 Apr 2021 01:57:31 -0700 (PDT) Received: from localhost ([::1]:33074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPij-0002K2-33 for importer@patchew.org; Mon, 19 Apr 2021 04:57:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhK-0000Zt-5Q for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31059) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhI-0000vw-K5 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-cxtm6m-yN_uXk7RBST2ShA-1; Mon, 19 Apr 2021 04:55:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F579107ACF6; Mon, 19 Apr 2021 08:55:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93B5C5D742; Mon, 19 Apr 2021 08:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F7NwFsCFY1ZCxrd9bRPmNUOXiKGCgh0XcDto2jSEUCQ=; b=i7fDYh0d95vWOWQfukIOZNs7wAqgRWFDVBMLe8WVhq3gRlGRcpk7k9K17VmDELrcK1xm/7 oQPqErrlQlvwmkd9malBUk3huj7h4ZlMQAtXXHq9l61+3brl1W9RpXkUja308yzh8G72yd 4f7Y/LSC38fB5YTl/jHBWrpuo7E999I= X-MC-Unique: cxtm6m-yN_uXk7RBST2ShA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 2/8] block: protect write threshold QMP commands from concurrent requests Date: Mon, 19 Apr 2021 10:55:35 +0200 Message-Id: <20210419085541.22310-3-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Stefan Hajnoczi Co-developed-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- 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 63040fa4f2..77c74bdaa7 100644 --- a/block/write-threshold.c +++ b/block/write-threshold.c @@ -111,7 +111,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) { @@ -119,10 +118,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.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822759; cv=none; d=zohomail.com; s=zohoarc; b=ZDx5M/dU3i2vHYKRAOXUdhUIS8uPeA3K6ye9BHGxPc8nWiP75yxp4N+bl+Emm/h1qQJbLrqLa65En0KahpSy5zHBdKPqigFolqTCpO4+1e4Nm0BAZzGGqgKqXdrca1bRhC5+UMVPn2cWdbX0plOrcwcIkpItIZDRklf/Ne0ML1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822759; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Q7e3ACKik/9Tt3fAfsgsQlAWRQdjxhC03g6iQjWjbOg=; b=TjFu+NRi2hNR4wB0eOlZMsHCRTcqNYb/vS5xJJqR9GcZocSDPn58cFpnRi7vNzPnz1q7DqDRsO2su5jkVMqUI9HT4XRRBorS6Ltv4vOOE22bGyO0f+l5E04SO6+a4ie2NwC4p2VDUNc4QfVL72ysyQy2yIC6yLM1g8waN8Ng62E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822759598375.52776391831935; Mon, 19 Apr 2021 01:59:19 -0700 (PDT) Received: from localhost ([::1]:41286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPkU-0005bX-H0 for importer@patchew.org; Mon, 19 Apr 2021 04:59:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhP-0000ny-L4 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhN-0000yl-Uf for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-37hii6YUNGyykaSM_9xJtw-1; Mon, 19 Apr 2021 04:56:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E36387A82A; Mon, 19 Apr 2021 08:56:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF93C5D742; Mon, 19 Apr 2021 08:55:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q7e3ACKik/9Tt3fAfsgsQlAWRQdjxhC03g6iQjWjbOg=; b=Zs1MADo7T9lfMfLbZAxiNlTswSWSFsmmRJfzdIXGxDHWKl18epEAafr/XGcBEPTJJu3yEA 3VJyYUh/ddhXSnwCAqdHj7LS7ne2kPLRNJk2zu9WWkG9FMQ3OV8A3f6jhiqPtYUJSiu/HJ dH8zTj3L+IpmciHPQ2beWZJJoz8c3Fg= X-MC-Unique: 37hii6YUNGyykaSM_9xJtw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 3/8] util: use RCU accessors for notifiers Date: Mon, 19 Apr 2021 10:55:36 +0200 Message-Id: <20210419085541.22310-4-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Note that calling rcu_read_lock() is left to the caller. In fact, if the notifier is really only used within the BQL, it's unnecessary. Even outside the BQL, RCU accessors can also be used with any API that has the same contract as synchronize_rcu, i.e. it stops until all concurrent readers complete, no matter how "readers" are defined. In the next patch, for example, synchronize_rcu's role is taken by bdrv_drain (which is a superset of synchronize_rcu, since it also blocks new incoming readers). Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- util/notify.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/util/notify.c b/util/notify.c index 76bab212ae..529f1d121e 100644 --- a/util/notify.c +++ b/util/notify.c @@ -15,6 +15,7 @@ =20 #include "qemu/osdep.h" #include "qemu/notify.h" +#include "qemu/rcu_queue.h" =20 void notifier_list_init(NotifierList *list) { @@ -23,19 +24,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); } } @@ -53,12 +54,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) @@ -66,7 +67,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.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822941; cv=none; d=zohomail.com; s=zohoarc; b=c0AnqQ62JXc8msIYei22zR68LUb9EHiSRtevJV3rkO0vnyMqJiPRhoMeP72b3yw3hhxRoeChyWznkaddUH0G+2SW2zf6tY4xwT3E17Wx21grxSA8+tZKmyTowoWHLX4dDUEzc6Mx9omEUc22bEUubBPwG8JjFBvFQ4UqSt6TdD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822941; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aj+m7bFeSvHh3CRGJg61cTK6r5lIG3JM1YBLFdhutP8=; b=XQUyRIG+bxw9wYrHG81wSUzonYbQ0gIx+jf2zl8A7np23bHn3SH8ug+/1LXbS4soOTBKZu4rbteJjG0h92N/niu4FlAbZ7KzdUJFIEnY6geH6Yq0fT8nw11WeWbvV22X6zZXnqOOud0OwYmA4w/OaWwiG4Nd7wjgJD0zPpheORc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822941577608.8898140030486; Mon, 19 Apr 2021 02:02:21 -0700 (PDT) Received: from localhost ([::1]:49514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPnQ-0000ag-5M for importer@patchew.org; Mon, 19 Apr 2021 05:02:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhR-0000sr-Lt for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhO-0000zT-Ly for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-lSBt1HoWPyuJQ_FoIUIW5A-1; Mon, 19 Apr 2021 04:56:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70DEB184B7E4; Mon, 19 Apr 2021 08:56:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE4A05D742; Mon, 19 Apr 2021 08:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aj+m7bFeSvHh3CRGJg61cTK6r5lIG3JM1YBLFdhutP8=; b=eISZDC+X2XLEk0xOAPkIp4Do10r6Bbhm1loLSxAZddw/wZkGyf0jcXABFWnnKEYb3h2zLA NmD8W3gQ3MhM4J0v/+KpenD77midl6m1qS8KG68APooIjHRrfLb5gY9Uk8Kofh4cBolzgM jfsCkaxlorlHiGct+4F9zxkrVl+JX1M= X-MC-Unique: lSBt1HoWPyuJQ_FoIUIW5A-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 4/8] block: make before-write notifiers thread-safe Date: Mon, 19 Apr 2021 10:55:37 +0200 Message-Id: <20210419085541.22310-5-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 6 +++--- block/io.c | 12 ++++++++++++ block/write-threshold.c | 2 +- include/block/block_int.h | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index c5b887cec1..f40fb63c75 100644 --- a/block.c +++ b/block.c @@ -6434,7 +6434,7 @@ static void bdrv_do_remove_aio_context_notifier(BdrvA= ioNotifier *ban) g_free(ban); } =20 -static void bdrv_detach_aio_context(BlockDriverState *bs) +void bdrv_detach_aio_context(BlockDriverState *bs) { BdrvAioNotifier *baf, *baf_tmp; =20 @@ -6462,8 +6462,8 @@ static void bdrv_detach_aio_context(BlockDriverState = *bs) bs->aio_context =3D NULL; } =20 -static void bdrv_attach_aio_context(BlockDriverState *bs, - AioContext *new_context) +void bdrv_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) { BdrvAioNotifier *ban, *ban_tmp; =20 diff --git a/block/io.c b/block/io.c index ca2dca3007..8f6af6077b 100644 --- a/block/io.c +++ b/block/io.c @@ -3137,10 +3137,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 77c74bdaa7..b87b749b02 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 88e4111939..a1aad5ad2d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1089,6 +1089,8 @@ bool bdrv_backing_overridden(BlockDriverState *bs); =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. @@ -1096,6 +1098,41 @@ bool bdrv_backing_overridden(BlockDriverState *bs); 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 + * current #AioContext. This is only needed by block drivers that manage = their + * own children. Both ->file and ->backing are automatically handled and + * block drivers should not call this function on them explicitly. + */ +void bdrv_detach_aio_context(BlockDriverState *bs); + +/** + * bdrv_attach_aio_context: + * + * May be called from .bdrv_attach_aio_context() to attach children to the= new + * #AioContext. This is only needed by block drivers that manage their own + * children. Both ->file and ->backing are automatically handled and block + * drivers should not call this function on them explicitly. + */ +void bdrv_attach_aio_context(BlockDriverState *bs, + AioContext *new_context); + /** * bdrv_add_aio_context_notifier: * --=20 2.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822673; cv=none; d=zohomail.com; s=zohoarc; b=YgJaQdih4W8fgsgstP2cMZYrHAvQtHzbt5t+Ftiu2RBBjdUc5JY+Tf3NWkP0lwOIxquH6aIdDcP39i/c/EcbVTPY2bxSzG6teOCkTUOTYrA2olWr4DdAdTF6d2OTxLsTtUv1VCskTgOWysCK73U/O9ndXZ5uk3Gs4C9GnloSxns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822673; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lXizbPfIrIGc6IgigvTm3SgSyrjrrLEJTlKfj6LSoF4=; b=JvS2GsDL5hMiXco28NZTMySJVGUCZcgLeopcMMZqN5i8tEpRv4G/+9Sr2XeqWYkMzwuzSh14jAJANJ17jmP/dYCDm4V/0Qko7DrJT3n+JoIqIzJyIPAEQ+ZhVOqy/AHuy0r4j43gnvIVwzStFqjjQQJ1JGPwPv1tOcYGgYbgXME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161882267314678.44934316796014; Mon, 19 Apr 2021 01:57:53 -0700 (PDT) Received: from localhost ([::1]:35056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPj6-000383-3P for importer@patchew.org; Mon, 19 Apr 2021 04:57:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhV-00014y-Tw for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30312) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhS-000129-Qu for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-212-4Ob2kNUZPwezetl79daUyA-1; Mon, 19 Apr 2021 04:56:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9810183DD36; Mon, 19 Apr 2021 08:56:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5A865D741; Mon, 19 Apr 2021 08:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lXizbPfIrIGc6IgigvTm3SgSyrjrrLEJTlKfj6LSoF4=; b=Ic+YctlLBBOqQLPgMiQSbEYpHP1+vNma0JkZCTOl+nuKrGBxIwMpHd3rCXK9x309jJ9eVd 2ewTYSUdSRIZpmvYgAJBO8UlEEJZjUVs51pGKzXNs7DVpnOe7jyns/84jaMKQR7Y9J0M8C qRlRGgioYqyd1Y9WgTykCXUfLSZavVQ= X-MC-Unique: 4Ob2kNUZPwezetl79daUyA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 5/8] block: add a few more notes on locking Date: Mon, 19 Apr 2021 10:55:38 +0200 Message-Id: <20210419085541.22310-6-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- include/block/block_int.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index a1aad5ad2d..67a0777e12 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -154,7 +154,9 @@ struct BlockDriver { */ 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); @@ -168,6 +170,7 @@ struct BlockDriver { /* Protocol drivers should implement this instead of bdrv_open */ int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, Error **errp); + /* Called from main thread. */ void (*bdrv_close)(BlockDriverState *bs); =20 =20 --=20 2.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822801; cv=none; d=zohomail.com; s=zohoarc; b=joe2baZpGDYAqn7tIvmc5UPIMdvxdK7mttZoqudyNL9CTkfB5UFDMbSb7f6lA2/L0iBBoawWaLvwIO5HjM018jPCxYraLW3pANmdKdCgRsmIv+nPhN5ck5aFa4S6ojcnUZ0p2ZXw38JOXbvQiIOH8OF0CtLPvtPpN5vBtR+Vorg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822801; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UYLRRbpbjp9mKUuAMkZXKJr//pFxyKHZyB+Y7882t5M=; b=oLpxzYJGERxbv2UM//+mc9zZjRI29Joxq4pUvSv36SYyX1W61BdnNpFUIykxH/G9IfeDnuujWxtHPyDR1hI7ISFJN/wPqVIbq+ODgF9rrJ/PFnaeW4NnrIUZLhEOYZm+Mxzss65uALGT+nNXCPPozldooF3XjExXpQMqBpUZAFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161882280127137.852457622301245; Mon, 19 Apr 2021 02:00:01 -0700 (PDT) Received: from localhost ([::1]:43602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPlA-0006Wi-5M for importer@patchew.org; Mon, 19 Apr 2021 05:00:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhe-0001OK-1G for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhb-0001BU-67 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-dv6RVMSUOg26xJi_rCY8HA-1; Mon, 19 Apr 2021 04:56:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B04A1020C21; Mon, 19 Apr 2021 08:56:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id F055D5D741; Mon, 19 Apr 2021 08:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UYLRRbpbjp9mKUuAMkZXKJr//pFxyKHZyB+Y7882t5M=; b=Yoh8MZH1Gp0Y+2W6SRfo1KuRcoDY/PygpxFpJUs3pBRI9sqKpFeZ09ss49yqTqZdppZSLZ o1u+8vckGXYvl+d37W1N9dH2ZN8IL/z5uhRP4ldVIcN0hshh1KuXVKInFVjZ7WXtWyAhC/ AoLk3iUWj/nHSDa0RupkPsVIltFs1MA= X-MC-Unique: dv6RVMSUOg26xJi_rCY8HA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 6/8] block: do not acquire AioContext in check_to_replace_node Date: Mon, 19 Apr 2021 10:55:39 +0200 Message-Id: <20210419085541.22310-7-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make the (only) caller do it. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 22 +++++----------------- blockdev.c | 7 ++++++- include/block/block.h | 1 + 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/block.c b/block.c index f40fb63c75..fd12f88062 100644 --- a/block.c +++ b/block.c @@ -6776,24 +6776,15 @@ bool bdrv_recurse_can_replace(BlockDriverState *bs, * * The result (whether the node can be replaced or not) is only valid * for as long as no graph or permission changes occur. + * + * Called with AioContext lock held. */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *to_replace_bs, const char *node_name, Error **err= p) { - BlockDriverState *to_replace_bs =3D bdrv_find_node(node_name); - AioContext *aio_context; - - if (!to_replace_bs) { - error_setg(errp, "Failed to find node with node-name=3D'%s'", node= _name); - return NULL; - } - - 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 @@ -6806,12 +6797,9 @@ BlockDriverState *check_to_replace_node(BlockDriverS= tate *parent_bs, "because it cannot be guaranteed that doing so would no= t " "lead to an abrupt change of visible data", node_name, parent_bs->node_name); - to_replace_bs =3D NULL; - goto out; + return NULL; } =20 -out: - aio_context_release(aio_context); return to_replace_bs; } =20 diff --git a/blockdev.c b/blockdev.c index a57590aae4..e901107344 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3056,13 +3056,18 @@ static void blockdev_mirror_common(const char *job_= id, BlockDriverState *bs, return; } =20 - to_replace_bs =3D check_to_replace_node(bs, replaces, errp); + to_replace_bs =3D bdrv_find_node(replaces); if (!to_replace_bs) { + error_setg(errp, "Failed to find node with node-name=3D'%s'", + replaces); return; } =20 replace_aio_context =3D bdrv_get_aio_context(to_replace_bs); aio_context_acquire(replace_aio_context); + if (!check_to_replace_node(bs, to_replace_bs, replaces, errp)) { + return; + } replace_size =3D bdrv_getlength(to_replace_bs); aio_context_release(replace_aio_context); =20 diff --git a/include/block/block.h b/include/block/block.h index b3f6e509d4..f57c34a19a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -474,6 +474,7 @@ int bdrv_amend_options(BlockDriverState *bs_new, QemuOp= ts *opts, =20 /* check if a named node can be replaced when doing drive-mirror */ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, + BlockDriverState *to_replace_bs, const char *node_name, Error **err= p); =20 /* async block I/O */ --=20 2.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822804; cv=none; d=zohomail.com; s=zohoarc; b=UoHmiq0uHS54bmtfOyWEKIWqNRmIXrqdqgWWvRlnbEv+N++AthoBVYceQvdLJTh3gLKIVY0UgX67nZcFlq7mtCBcBhgh8TEcZSqhywn4zxUuvm1JiTBteii04pCSMdnkizRnB+GA4vlllx4KnVkozbDvtatbUqrtrPXx4HbDvqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822804; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mHxLtTUKf/xVLg6DTW6BHHXfxci386yjrRvLXJnhv9s=; b=gPdFVEb0edXEH/V2M0pgUgbI6ylRjgGqpejIDIUq/8yNIwz8mnjCCmEA+PfrQSI6IP2CLx+A0KvCDvAHWoBqzdpu9Ao0weOsAzIWdrhta+7sbL588mlIxNwrqhy5QoL694AzuUkR5lSNDBB1iVRGGtod5XfCrfT5e/jMrwEBF0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822804604485.78691879804785; Mon, 19 Apr 2021 02:00:04 -0700 (PDT) Received: from localhost ([::1]:43794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPlD-0006bb-7D for importer@patchew.org; Mon, 19 Apr 2021 05:00:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhh-0001Qp-O3 for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24127) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhf-0001H5-IA for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-hH51lMPaOV-yvXD3Jv87eQ-1; Mon, 19 Apr 2021 04:56:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEFF16D24A; Mon, 19 Apr 2021 08:56:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB9475D741; Mon, 19 Apr 2021 08:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mHxLtTUKf/xVLg6DTW6BHHXfxci386yjrRvLXJnhv9s=; b=TZ1cEzS0Bzd/Xanfzkl0EVRSmHBx68DQp3o+18l7/yb9Vx2ixcD+c2g1gZaOAFaqDR9m9e FA3ivIewA0QkvxUrZSqFH/fUGXOJ0x4sFbU2FO/bq/J6Nms/MHpAPPrIxFStqXfewImhq3 KfTRuSbR16cipp6ONDi7YXT1HF2s/xA= X-MC-Unique: hH51lMPaOV-yvXD3Jv87eQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 7/8] block/replication: do not acquire AioContext Date: Mon, 19 Apr 2021 10:55:40 +0200 Message-Id: <20210419085541.22310-8-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Signed-off-by: Emanuele Giuseppe Esposito --- block/replication.c | 54 ++++++++++----------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/block/replication.c b/block/replication.c index 97be7ef4de..25ee37b21b 100644 --- a/block/replication.c +++ b/block/replication.c @@ -45,6 +45,8 @@ typedef struct BDRVReplicationState { Error *blocker; bool orig_hidden_read_only; bool orig_secondary_read_only; + + /* This field is accessed asynchronously. */ int error; } BDRVReplicationState; =20 @@ -210,7 +212,7 @@ static int replication_return_value(BDRVReplicationStat= e *s, int ret) } =20 if (ret < 0) { - s->error =3D ret; + qatomic_set(&s->error, ret); ret =3D 0; } =20 @@ -307,6 +309,7 @@ out: return ret; } =20 +/* Called with no I/O pending. */ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { Error *local_err =3D NULL; @@ -420,7 +423,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; + qatomic_set(&s->error, -EIO); } =20 backup_job_cleanup(bs); @@ -445,6 +448,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) { @@ -452,12 +456,9 @@ static void replication_start(ReplicationState *rs, Re= plicationMode mode, BDRVReplicationState *s; BlockDriverState *top_bs; int64_t active_length, hidden_length, disk_length; - AioContext *aio_context; Error *local_err =3D NULL; BackupPerf perf =3D { .use_copy_range =3D true, .max_workers =3D 1 }; =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s =3D bs->opaque; =20 if (s->stage =3D=3D BLOCK_REPLICATION_DONE || @@ -467,20 +468,17 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, * Ignore the request because the secondary side of replication * doesn't have to do anything anymore. */ - aio_context_release(aio_context); return; } =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 @@ -492,21 +490,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 @@ -518,7 +513,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 @@ -529,7 +523,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 @@ -537,7 +530,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 @@ -550,7 +542,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); @@ -566,13 +557,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; } job_start(&s->backup_job->job); break; default: - aio_context_release(aio_context); abort(); } =20 @@ -582,18 +571,15 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, secondary_do_checkpoint(s, errp); } =20 - s->error =3D 0; - aio_context_release(aio_context); + qatomic_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->stage =3D=3D BLOCK_REPLICATION_DONE || @@ -603,38 +589,30 @@ static void replication_do_checkpoint(ReplicationStat= e *rs, Error **errp) * Ignore the request because the secondary side of replication * doesn't have to do anything anymore. */ - aio_context_release(aio_context); return; } =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=3D BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } =20 - if (s->error) { + if (qatomic_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) @@ -648,10 +626,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; + qatomic_set(&s->error, 0); } else { s->stage =3D BLOCK_REPLICATION_FAILOVER_FAILED; - s->error =3D -EIO; + qatomic_set(&s->error, -EIO); } } =20 @@ -659,10 +637,7 @@ static void replication_stop(ReplicationState *rs, boo= l 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=3D BLOCK_REPLICATION_DONE || @@ -672,20 +647,18 @@ static void replication_stop(ReplicationState *rs, bo= ol failover, Error **errp) * Ignore the request because the secondary side of replication * doesn't have to do anything anymore. */ - aio_context_release(aio_context); return; } =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; + qatomic_set(&s->error, 0); break; case REPLICATION_MODE_SECONDARY: /* @@ -700,7 +673,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 @@ -711,10 +683,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 static const char *const replication_strong_runtime_opts[] =3D { --=20 2.30.2 From nobody Sun Feb 8 00:11:49 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618822834; cv=none; d=zohomail.com; s=zohoarc; b=LLXK0udqXVKh/viLLVZ5cKevAIHDDNBGbVU2dMq/JxeMyjb5IfFgYXf+DAoNwk4ysIAOpaof8le4PFsCMeFYAzTXRCgGPfjmzyrVNMt41Vtu6BuMJIxpHEvqjx/prdM14pryPevbvicDQBYFDXK4qPvAlP5bE1GKd9Vd9qbJQqo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618822834; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZA0KhXzvaBqWyhzILLmVRLdX/8xBMJXcXdvw+3nKvwQ=; b=UH1fS4AxtLu8mRy203lV6/aY4cpuJonWS49hKE4BKCwt39laq9e4G/VOFyG1EbBsKCQK1PsZClIaK3FYtvac0UThILrLu3YcW4G341jXmPyTcXHEpBNJ94ILl/YUIjzVnPXv8sD4CgaoTpDRclREwvI+6QxZmSDOENIWbioseoc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618822834130829.0484445644668; Mon, 19 Apr 2021 02:00:34 -0700 (PDT) Received: from localhost ([::1]:45418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPlc-0007Fr-G6 for importer@patchew.org; Mon, 19 Apr 2021 05:00:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhk-0001Sq-LE for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYPhh-0001Hj-7x for qemu-devel@nongnu.org; Mon, 19 Apr 2021 04:56:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-Ex5CCSPwP-OmoojNzOR5kQ-1; Mon, 19 Apr 2021 04:56:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0B8E83DD25; Mon, 19 Apr 2021 08:56:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-114-195.ams2.redhat.com [10.36.114.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36CFB5D71D; Mon, 19 Apr 2021 08:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618822583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZA0KhXzvaBqWyhzILLmVRLdX/8xBMJXcXdvw+3nKvwQ=; b=IkeE3Oj3/bm6WbxqIAphnKEeSIyEhycIDhOGnp1Gr1DhZ/E73EJwNsmOdjAXlyP0mh4YZ0 E4io+DHGoO5YaCBk67RdpwIGJZzmMKqrjyiWIvdy52xWTNKONGomNTPSTV2ObcAIp0RrX7 quDF1aaYjCGVrBuZR9mY3fmz1xBcbDA= X-MC-Unique: Ex5CCSPwP-OmoojNzOR5kQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 8/8] block: do not take AioContext around reopen Date: Mon, 19 Apr 2021 10:55:41 +0200 Message-Id: <20210419085541.22310-9-eesposit@redhat.com> In-Reply-To: <20210419085541.22310-1-eesposit@redhat.com> References: <20210419085541.22310-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito , Markus Armbruster , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 4 ---- block/mirror.c | 9 --------- blockdev.c | 19 ++++++------------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 413af51f3b..6fdc698e9e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2291,20 +2291,16 @@ 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); BlockDriverState *unfiltered_bs =3D bdrv_skip_filters(blk_bs(blk)); =20 - aio_context_acquire(aio_context); if (blk_is_inserted(blk) && bdrv_cow_child(unfiltered_bs)) { int ret; =20 ret =3D bdrv_commit(unfiltered_bs); if (ret < 0) { - aio_context_release(aio_context); return ret; } } - aio_context_release(aio_context); } return 0; } diff --git a/block/mirror.c b/block/mirror.c index 5a71bd8bbc..43174bbc6b 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -631,7 +631,6 @@ static int mirror_exit_common(Job *job) MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockJob *bjob =3D &s->common; MirrorBDSOpaque *bs_opaque; - AioContext *replace_aio_context =3D NULL; BlockDriverState *src; BlockDriverState *target_bs; BlockDriverState *mirror_top_bs; @@ -699,11 +698,6 @@ static int mirror_exit_common(Job *job) } } =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 && !abort) { BlockDriverState *to_replace =3D s->to_replace ?: src; bool ro =3D bdrv_is_read_only(to_replace); @@ -740,9 +734,6 @@ static int mirror_exit_common(Job *job) 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/blockdev.c b/blockdev.c index e901107344..1672ef756e 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3469,7 +3469,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; @@ -3480,37 +3479,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 */ @@ -3518,7 +3514,7 @@ void qmp_change_backing_file(const char *device, =20 if (ro) { if (bdrv_reopen_set_read_only(image_bs, false, errp) !=3D 0) { - goto out; + return; } } =20 @@ -3536,9 +3532,6 @@ void qmp_change_backing_file(const char *device, if (ro) { bdrv_reopen_set_read_only(image_bs, true, errp); } - -out: - aio_context_release(aio_context); } =20 void qmp_blockdev_add(BlockdevOptions *options, Error **errp) --=20 2.30.2