From patchwork Mon Apr 19 08:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467834 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cp1yxftu; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP10062tlz9tlQ for ; Mon, 19 Apr 2021 18:56:48 +1000 (AEST) Received: from localhost ([::1]:57642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPi2-0000nh-Qk for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:56:46 -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 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= 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 X-MC-Unique: crUD8v1KPg2OvxqZ9KaQxQ-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 *bs) } } +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 = bdrv_write_threshold_get(bs); + + return treshold_overage(req, thres); } static int coroutine_fn before_write_notify(NotifierWithReturn *notifier, @@ -56,14 +60,14 @@ static int coroutine_fn before_write_notify(NotifierWithReturn *notifier, { BdrvTrackedRequest *req = opaque; BlockDriverState *bs = req->bs; - uint64_t amount = 0; + uint64_t thres = bdrv_write_threshold_get(bs); + uint64_t amount = treshold_overage(req, thres); - amount = bdrv_write_threshold_exceeded(bs, req); if (amount > 0) { qapi_event_send_block_write_threshold( bs->node_name, amount, - bs->write_threshold_offset); + thres); /* autodisable to avoid flooding the monitor */ write_threshold_disable(bs); From patchwork Mon Apr 19 08:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=i7fDYh0d; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP0zv6v0Qz9tlQ for ; Mon, 19 Apr 2021 18:56:43 +1000 (AEST) Received: from localhost ([::1]:57234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPhx-0000d3-VM for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:56:42 -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 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= 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 X-MC-Unique: cxtm6m-yN_uXk7RBST2ShA-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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_name, Error **errp) { BlockDriverState *bs; - AioContext *aio_context; bs = bdrv_find_node(node_name); if (!bs) { @@ -119,10 +118,8 @@ void qmp_block_set_write_threshold(const char *node_name, return; } - aio_context = 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); } From patchwork Mon Apr 19 08:55:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Zs1MADo7; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP1203LpFz9vFb for ; Mon, 19 Apr 2021 18:58:32 +1000 (AEST) Received: from localhost ([::1]:37216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPjg-0003yM-Uc for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:58:28 -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 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= 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 X-MC-Unique: 37hii6YUNGyykaSM_9xJtw-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 @@ #include "qemu/osdep.h" #include "qemu/notify.h" +#include "qemu/rcu_queue.h" void notifier_list_init(NotifierList *list) { @@ -23,19 +24,19 @@ void notifier_list_init(NotifierList *list) void notifier_list_add(NotifierList *list, Notifier *notifier) { - QLIST_INSERT_HEAD(&list->notifiers, notifier, node); + QLIST_INSERT_HEAD_RCU(&list->notifiers, notifier, node); } void notifier_remove(Notifier *notifier) { - QLIST_REMOVE(notifier, node); + QLIST_REMOVE_RCU(notifier, node); } void notifier_list_notify(NotifierList *list, void *data) { Notifier *notifier, *next; - 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(NotifierWithReturnList *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); } void notifier_with_return_remove(NotifierWithReturn *notifier) { - QLIST_REMOVE(notifier, node); + QLIST_REMOVE_RCU(notifier, node); } int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data) @@ -66,7 +67,7 @@ int notifier_with_return_list_notify(NotifierWithReturnList *list, void *data) NotifierWithReturn *notifier, *next; int ret = 0; - QLIST_FOREACH_SAFE(notifier, &list->notifiers, node, next) { + QLIST_FOREACH_SAFE_RCU(notifier, &list->notifiers, node, next) { ret = notifier->notify(notifier, data); if (ret != 0) { break; From patchwork Mon Apr 19 08:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eISZDC+X; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP15R6xj9z9vDw for ; Mon, 19 Apr 2021 19:01:31 +1000 (AEST) Received: from localhost ([::1]:45792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPmb-0007Ox-RC for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 05:01:29 -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 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= 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 X-MC-Unique: lSBt1HoWPyuJQ_FoIUIW5A-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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(BdrvAioNotifier *ban) g_free(ban); } -static void bdrv_detach_aio_context(BlockDriverState *bs) +void bdrv_detach_aio_context(BlockDriverState *bs) { BdrvAioNotifier *baf, *baf_tmp; @@ -6462,8 +6462,8 @@ static void bdrv_detach_aio_context(BlockDriverState *bs) bs->aio_context = NULL; } -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; 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, QEMUIOVector *qiov) return true; } +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); } 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_notifier); bs->write_threshold_offset = 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); /** * 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); +/** + * 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 processed 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 the + * 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: * From patchwork Mon Apr 19 08:55:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ic+YctlL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP10H3hZgz9tlQ for ; Mon, 19 Apr 2021 18:57:03 +1000 (AEST) Received: from localhost ([::1]:59292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPiH-0001VF-EN for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:57:01 -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 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= 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 X-MC-Unique: 4Ob2kNUZPwezetl79daUyA-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; - /* 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); From patchwork Mon Apr 19 08:55:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Yoh8MZH1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP12j5hn6z9tlQ for ; Mon, 19 Apr 2021 18:59:09 +1000 (AEST) Received: from localhost ([::1]:39572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPkJ-0004vS-Nj for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:59:07 -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 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= 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 X-MC-Unique: dv6RVMSUOg26xJi_rCY8HA-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 **errp) { - BlockDriverState *to_replace_bs = bdrv_find_node(node_name); - AioContext *aio_context; - - if (!to_replace_bs) { - error_setg(errp, "Failed to find node with node-name='%s'", node_name); - return NULL; - } - - aio_context = 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 = NULL; - goto out; + return NULL; } /* We don't want arbitrary node of the BDS chain to be replaced only the top @@ -6806,12 +6797,9 @@ BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, "because it cannot be guaranteed that doing so would not " "lead to an abrupt change of visible data", node_name, parent_bs->node_name); - to_replace_bs = NULL; - goto out; + return NULL; } -out: - aio_context_release(aio_context); return to_replace_bs; } 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; } - to_replace_bs = check_to_replace_node(bs, replaces, errp); + to_replace_bs = bdrv_find_node(replaces); if (!to_replace_bs) { + error_setg(errp, "Failed to find node with node-name='%s'", + replaces); return; } replace_aio_context = 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 = bdrv_getlength(to_replace_bs); aio_context_release(replace_aio_context); 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, QemuOpts *opts, /* 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 **errp); /* async block I/O */ From patchwork Mon Apr 19 08:55:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467838 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TZ1cEzS0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP12l5Dctz9tlQ for ; Mon, 19 Apr 2021 18:59:11 +1000 (AEST) Received: from localhost ([::1]:39724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPkL-0004z8-MR for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:59:09 -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 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= 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 X-MC-Unique: hH51lMPaOV-yvXD3Jv87eQ-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; @@ -210,7 +212,7 @@ static int replication_return_value(BDRVReplicationState *s, int ret) } if (ret < 0) { - s->error = ret; + qatomic_set(&s->error, ret); ret = 0; } @@ -307,6 +309,7 @@ out: return ret; } +/* Called with no I/O pending. */ static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { Error *local_err = NULL; @@ -420,7 +423,7 @@ static void backup_job_completed(void *opaque, int ret) if (s->stage != BLOCK_REPLICATION_FAILOVER) { /* The backup job is cancelled unexpectedly */ - s->error = -EIO; + qatomic_set(&s->error, -EIO); } backup_job_cleanup(bs); @@ -445,6 +448,7 @@ static bool check_top_bs(BlockDriverState *top_bs, BlockDriverState *bs) return false; } +/* 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, ReplicationMode mode, BDRVReplicationState *s; BlockDriverState *top_bs; int64_t active_length, hidden_length, disk_length; - AioContext *aio_context; Error *local_err = NULL; BackupPerf perf = { .use_copy_range = true, .max_workers = 1 }; - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s = bs->opaque; if (s->stage == BLOCK_REPLICATION_DONE || @@ -467,20 +468,17 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, * Ignore the request because the secondary side of replication * doesn't have to do anything anymore. */ - aio_context_release(aio_context); return; } if (s->stage != BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); - aio_context_release(aio_context); return; } if (s->mode != 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; } @@ -492,21 +490,18 @@ static void replication_start(ReplicationState *rs, ReplicationMode 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; } s->hidden_disk = 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; } s->secondary_disk = 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 backend"); - aio_context_release(aio_context); return; } @@ -518,7 +513,6 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, active_length != hidden_length || hidden_length != disk_length) { error_setg(errp, "Active disk, hidden disk, secondary disk's length" " are not the same"); - aio_context_release(aio_context); return; } @@ -529,7 +523,6 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, !s->hidden_disk->bs->drv->bdrv_make_empty) { error_setg(errp, "Active disk or hidden disk doesn't support make_empty"); - aio_context_release(aio_context); return; } @@ -537,7 +530,6 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, reopen_backing_file(bs, true, &local_err); if (local_err) { error_propagate(errp, local_err); - aio_context_release(aio_context); return; } @@ -550,7 +542,6 @@ static void replication_start(ReplicationState *rs, ReplicationMode 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, ReplicationMode 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(); } @@ -582,18 +571,15 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, secondary_do_checkpoint(s, errp); } - s->error = 0; - aio_context_release(aio_context); + qatomic_set(&s->error, 0); } +/* Called with no I/O pending. */ static void replication_do_checkpoint(ReplicationState *rs, Error **errp) { BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s = bs->opaque; if (s->stage == BLOCK_REPLICATION_DONE || @@ -603,38 +589,30 @@ static void replication_do_checkpoint(ReplicationState *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; } if (s->mode == REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); } - aio_context_release(aio_context); } static void replication_get_error(ReplicationState *rs, Error **errp) { BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s = bs->opaque; if (s->stage == BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } - 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); } static void replication_done(void *opaque, int ret) @@ -648,10 +626,10 @@ static void replication_done(void *opaque, int ret) s->active_disk = NULL; s->secondary_disk = NULL; s->hidden_disk = NULL; - s->error = 0; + qatomic_set(&s->error, 0); } else { s->stage = BLOCK_REPLICATION_FAILOVER_FAILED; - s->error = -EIO; + qatomic_set(&s->error, -EIO); } } @@ -659,10 +637,7 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) { BlockDriverState *bs = rs->opaque; BDRVReplicationState *s; - AioContext *aio_context; - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); s = bs->opaque; if (s->stage == BLOCK_REPLICATION_DONE || @@ -672,20 +647,18 @@ static void replication_stop(ReplicationState *rs, bool 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; } if (s->stage != BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); - aio_context_release(aio_context); return; } switch (s->mode) { case REPLICATION_MODE_PRIMARY: s->stage = BLOCK_REPLICATION_DONE; - s->error = 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 = BLOCK_REPLICATION_DONE; - aio_context_release(aio_context); return; } @@ -711,10 +683,8 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) NULL, replication_done, bs, true, errp); break; default: - aio_context_release(aio_context); abort(); } - aio_context_release(aio_context); } static const char *const replication_strong_runtime_opts[] = { From patchwork Mon Apr 19 08:55:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1467839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=IkeE3Oj3; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FP1331snhz9vFb for ; Mon, 19 Apr 2021 18:59:27 +1000 (AEST) Received: from localhost ([::1]:41418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYPkb-0005eb-7o for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2021 04:59:25 -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 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= 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 X-MC-Unique: Ex5CCSPwP-OmoojNzOR5kQ-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = NULL; while ((blk = blk_all_next(blk)) != NULL) { - AioContext *aio_context = blk_get_aio_context(blk); BlockDriverState *unfiltered_bs = bdrv_skip_filters(blk_bs(blk)); - aio_context_acquire(aio_context); if (blk_is_inserted(blk) && bdrv_cow_child(unfiltered_bs)) { int ret; ret = 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 = container_of(job, MirrorBlockJob, common.job); BlockJob *bjob = &s->common; MirrorBDSOpaque *bs_opaque; - AioContext *replace_aio_context = NULL; BlockDriverState *src; BlockDriverState *target_bs; BlockDriverState *mirror_top_bs; @@ -699,11 +698,6 @@ static int mirror_exit_common(Job *job) } } - if (s->to_replace) { - replace_aio_context = bdrv_get_aio_context(s->to_replace); - aio_context_acquire(replace_aio_context); - } - if (s->should_complete && !abort) { BlockDriverState *to_replace = s->to_replace ?: src; bool ro = 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); 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 = NULL; - AioContext *aio_context; BlockDriverState *image_bs = NULL; Error *local_err = NULL; bool ro; @@ -3480,37 +3479,34 @@ void qmp_change_backing_file(const char *device, return; } - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - image_bs = bdrv_lookup_bs(NULL, image_node_name, &local_err); if (local_err) { error_propagate(errp, local_err); - goto out; + return; } if (!image_bs) { error_setg(errp, "image file not found"); - goto out; + return; } if (bdrv_find_base(image_bs) == image_bs) { error_setg(errp, "not allowing backing file change on an image " "without a backing file"); - goto out; + return; } /* 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; } /* 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; } /* if not r/w, reopen to make r/w */ @@ -3518,7 +3514,7 @@ void qmp_change_backing_file(const char *device, if (ro) { if (bdrv_reopen_set_read_only(image_bs, false, errp) != 0) { - goto out; + return; } } @@ -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); } void qmp_blockdev_add(BlockdevOptions *options, Error **errp)