From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201552; cv=none; d=zohomail.com; s=zohoarc; b=AAJDlHF116nYduWK1VNmOCfonAbrikXKT93/4j1eY7vxV1i8IIxKZ2FipEPNrW2S49632V/0GeS3aAmwKZ8CAS1LK33yovod3rXSgtm/ni2d0FrgtqLbRGCTh2/dUPonNDiuAl9GX1BP3zNZ/uw6HYmabmd4e5vNg8MVZ4LNMdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201552; h=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=s3Zbn8tJ/b081MbWgYZPkFNrkxwQdGfuG401p2h3/Ps=; b=d1B2r60C9FrGECeN5TZnZ47XEfQ7wnmJeN4+XTtQVpVJmXMhaFgY33t6M6EpZ8mXY4wu6IoQpUNbSBHyqg50/LohM9d1bS7KiKQppoHB5wvio0axN4tI5tNDmYB2IPT4rzhxwPknO7AzdPMrQFojO6GPuS1RqnRZ9fMXTpb0QEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201552367320.01269469746353; Thu, 4 May 2023 04:59:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXb3-00034s-DU; Thu, 04 May 2023 07:58:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb2-00034k-BG for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb0-0004AH-PJ for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:04 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-493-Hadxg4-FOsm-QTcyMSWZCA-1; Thu, 04 May 2023 07:58:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 117FC1C0758D; Thu, 4 May 2023 11:58:00 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id F182AC15BAD; Thu, 4 May 2023 11:57:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s3Zbn8tJ/b081MbWgYZPkFNrkxwQdGfuG401p2h3/Ps=; b=TFBYkiIv9IxZRxTIn2xM+bs3RexJjiis1GqUEPWWCimmPjjm1ZiYwKZQ6fkF/vRBwqM9b7 yARWcuS/xYH+KuZEXM/X0BxfpoLUaYA0LxiOmxe9vITtbpxzqwhuRIfevS6CfVnMqSWihG +CGuuBDE0QFssSOYU/YtbNPht+klyg4= X-MC-Unique: Hadxg4-FOsm-QTcyMSWZCA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 01/20] qcow2: Don't call bdrv_getlength() in coroutine_fns Date: Thu, 4 May 2023 13:57:31 +0200 Message-Id: <20230504115750.54437-2-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201554033100003 Content-Type: text/plain; charset="utf-8" There is a bdrv_co_getlength() now, which should be used in coroutine context. This requires adding GRAPH_RDLOCK to some functions so that this still compiles with TSA because bdrv_co_getlength() is GRAPH_RDLOCK. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qcow2.h | 4 +++- block/qcow2-refcount.c | 2 +- block/qcow2.c | 19 +++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index c75decc38a..4f67eb912a 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -895,7 +895,9 @@ int qcow2_change_refcount_order(BlockDriverState *bs, i= nt refcount_order, void *cb_opaque, Error **errp); int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs); int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t = size); -int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs); + +int coroutine_fn GRAPH_RDLOCK +qcow2_detect_metadata_preallocation(BlockDriverState *bs); =20 /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index b2a81ff707..4cf91bd955 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -3715,7 +3715,7 @@ int coroutine_fn qcow2_detect_metadata_preallocation(= BlockDriverState *bs) =20 qemu_co_mutex_assert_locked(&s->lock); =20 - file_length =3D bdrv_getlength(bs->file->bs); + file_length =3D bdrv_co_getlength(bs->file->bs); if (file_length < 0) { return file_length; } diff --git a/block/qcow2.c b/block/qcow2.c index fe5def438e..94cf59af8b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2089,11 +2089,10 @@ static void qcow2_join_options(QDict *options, QDic= t *old_options) } } =20 -static int coroutine_fn qcow2_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t coun= t, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, + int64_t count, int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVQcow2State *s =3D bs->opaque; uint64_t host_offset; @@ -3235,7 +3234,7 @@ preallocate_co(BlockDriverState *bs, uint64_t offset,= uint64_t new_length, * all of the allocated clusters (otherwise we get failing reads after * EOF). Extend the image to the last allocated sector. */ - file_length =3D bdrv_getlength(s->data_file->bs); + file_length =3D bdrv_co_getlength(s->data_file->bs); if (file_length < 0) { error_setg_errno(errp, -file_length, "Could not get file size"); ret =3D file_length; @@ -4098,7 +4097,7 @@ qcow2_co_copy_range_from(BlockDriverState *bs, case QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN: case QCOW2_SUBCLUSTER_UNALLOCATED_ALLOC: if (bs->backing && bs->backing->bs) { - int64_t backing_length =3D bdrv_getlength(bs->backing->bs); + int64_t backing_length =3D bdrv_co_getlength(bs->backing->= bs); if (src_offset >=3D backing_length) { cur_write_flags |=3D BDRV_REQ_ZERO_WRITE; } else { @@ -4293,7 +4292,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offse= t, bool exact, goto fail; } =20 - old_file_size =3D bdrv_getlength(bs->file->bs); + old_file_size =3D bdrv_co_getlength(bs->file->bs); if (old_file_size < 0) { error_setg_errno(errp, -old_file_size, "Failed to inquire current file length"); @@ -4386,7 +4385,7 @@ qcow2_co_truncate(BlockDriverState *bs, int64_t offse= t, bool exact, break; } =20 - old_file_size =3D bdrv_getlength(bs->file->bs); + old_file_size =3D bdrv_co_getlength(bs->file->bs); if (old_file_size < 0) { error_setg_errno(errp, -old_file_size, "Failed to inquire current file length"); @@ -4694,7 +4693,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, * align end of file to a sector boundary to ease reading with * sector based I/Os */ - int64_t len =3D bdrv_getlength(bs->file->bs); + int64_t len =3D bdrv_co_getlength(bs->file->bs); if (len < 0) { return len; } --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201517; cv=none; d=zohomail.com; s=zohoarc; b=QxtF/DN0oNwPbsV5KjwqgCcNQXiVDBkezMChqpXrMS60dXMDVbY1QHdQjxXFkx0P1IB2djQMzNDSkH2jUATEbYKgQDmgt2FUcpJcXmu+WeRaps3qf+pwOr4OtAVIcLkEwTk/QHB0oZEZCk/oMuH8dLiuYi/y/snp89fO2hkM6jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201517; h=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=DZ40R9KYF+tmfGUBQSPEbZGpA9hUo09OFYdPhnW4g0g=; b=f7ax2RVIw0qhmqtfm+IBgucN1B/fBWp/YHDv6jyy5kP69GwTtAK5cFgXzLhNi0zidHvk/Q9lbnULJhxqxvO2ELjiGURaPo3SNGMboypC/DeODuKY/2O5ISWaO+j+LSos7OiDn6ekdihBGf+EOEYHggGYdpCXjPe+f0IEIDnOuG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201517733867.0355194492288; Thu, 4 May 2023 04:58:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXb6-00035d-Go; Thu, 04 May 2023 07:58:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb3-000350-Py for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb1-0004AQ-L5 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:05 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-578-ACuR8iYTOsOqlCxEOOHdjw-1; Thu, 04 May 2023 07:58:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C5F1109DCEC; Thu, 4 May 2023 11:58:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 495F4C15BAD; Thu, 4 May 2023 11:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZ40R9KYF+tmfGUBQSPEbZGpA9hUo09OFYdPhnW4g0g=; b=W839XwxZT2aa9WEbJcQyWHD7mwK3hOpXGnsQQvQ+MOh9q8OtdQVk4mjhTbdgrgYY/zB4MP roBhKVqoAPJXYxsHLim8O/m4rTF8Yi0/nk+OF2+yOYhcDfBYnwceQ1+AavXkzRu9np4GSP VLthmR15/p9WtGHMy71+vw52Kk/Mcns= X-MC-Unique: ACuR8iYTOsOqlCxEOOHdjw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 02/20] block: Consistently call bdrv_activate() outside coroutine Date: Thu, 4 May 2023 13:57:32 +0200 Message-Id: <20230504115750.54437-3-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201518948100003 Content-Type: text/plain; charset="utf-8" Migration code can call bdrv_activate() in coroutine context, whereas other callers call it outside of coroutines. As it calls other code that is not supposed to run in coroutines, standardise on running outside of coroutines. This adds a no_co_wrapper to switch to the main loop before calling bdrv_activate(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-global-state.h | 6 +++++- block/block-backend.c | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 399200a9a3..2c312cc774 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -166,7 +166,11 @@ int bdrv_amend_options(BlockDriverState *bs_new, QemuO= pts *opts, BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, Error **err= p); =20 -int bdrv_activate(BlockDriverState *bs, Error **errp); +int no_coroutine_fn bdrv_activate(BlockDriverState *bs, Error **errp); + +int coroutine_fn no_co_wrapper +bdrv_co_activate(BlockDriverState *bs, Error **errp); + void bdrv_activate_all(Error **errp); int bdrv_inactivate_all(void); =20 diff --git a/block/block-backend.c b/block/block-backend.c index fc530ded6a..e37d55d3e9 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2024,7 +2024,15 @@ void blk_activate(BlockBackend *blk, Error **errp) return; } =20 - bdrv_activate(bs, errp); + /* + * Migration code can call this function in coroutine context, so leave + * coroutine context if necessary. + */ + if (qemu_in_coroutine()) { + bdrv_co_activate(bs, errp); + } else { + bdrv_activate(bs, errp); + } } =20 bool coroutine_fn blk_co_is_inserted(BlockBackend *blk) --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201573; cv=none; d=zohomail.com; s=zohoarc; b=fmHz+V7uQf8kSBKg9b7jcCSiMYkelByhr6CZHZjmCFEUmUO2VAWRiCm/g3CTy9ACDS05kdtcjjXpNkXjcp8pI+7K4D1v9JI6GXqZrAvrHy3vTjaAQoHHeVFs/Qs0wmQyMtSkISjORNy6r6QDYj71nhZIPSEbtEY+OkrYW4I4Xss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201573; h=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=vI+bWUMcRVfjSYLIXOk22bokeJ0/9kNbNIAmPkPe/m4=; b=avTobSEBukgyFhzdmkYtzBCZOa+uiRwQwnXnXJOmCE1U35UgKfRM/97w3BjT0mwFNClRdAccN8asznkypJfkG+/8dY7vo/fUAcdGJSUADP1bI86/4BMfbb+zP5igExfeYuEbwXTxmZb6/dHbNvoBVHi2a5znsOPhKMHeZXiLO8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201573838904.4862677090658; Thu, 4 May 2023 04:59:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbA-00036q-4c; Thu, 04 May 2023 07:58:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb5-00035Y-CE for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb2-0004Ap-SV for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:07 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-nwXgBHt8OcyUFJBChtrlBg-1; Thu, 04 May 2023 07:58:03 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A853D280BC47; Thu, 4 May 2023 11:58:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94423C15BAD; Thu, 4 May 2023 11:58:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201484; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vI+bWUMcRVfjSYLIXOk22bokeJ0/9kNbNIAmPkPe/m4=; b=hvt44GgUDE6nK9A7oJ0/zdTT8wsTN0oz8EO8PyCG51IOg43eKABxt9Q5HcRnru56AFdfTM W4qJkt2PhkFrkA6MCRRmfvfenX34iWQM5BI5sH7UzL7HFvp9OETWmoIu8XFkFhZiXjnOwS tzlnZfXllVNf1KUT7WoLmSDlZtt/5e8= X-MC-Unique: nwXgBHt8OcyUFJBChtrlBg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 03/20] block: bdrv/blk_co_unref() for calls in coroutine context Date: Thu, 4 May 2023 13:57:33 +0200 Message-Id: <20230504115750.54437-4-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201575226100001 Content-Type: text/plain; charset="utf-8" These functions must not be called in coroutine context, because they need write access to the graph. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-global-state.h | 3 ++- include/sysemu/block-backend-global-state.h | 5 ++++- block.c | 2 +- block/crypto.c | 6 +++--- block/parallels.c | 6 +++--- block/qcow.c | 6 +++--- block/qcow2.c | 14 +++++++------- block/qed.c | 6 +++--- block/vdi.c | 6 +++--- block/vhdx.c | 6 +++--- block/vmdk.c | 18 +++++++++--------- block/vpc.c | 6 +++--- 12 files changed, 44 insertions(+), 40 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 2c312cc774..ec3ddb17a8 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -218,7 +218,8 @@ void bdrv_img_create(const char *filename, const char *= fmt, bool quiet, Error **errp); =20 void bdrv_ref(BlockDriverState *bs); -void bdrv_unref(BlockDriverState *bs); +void no_coroutine_fn bdrv_unref(BlockDriverState *bs); +void coroutine_fn no_co_wrapper bdrv_co_unref(BlockDriverState *bs); void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child); BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, BlockDriverState *child_bs, diff --git a/include/sysemu/block-backend-global-state.h b/include/sysemu/b= lock-backend-global-state.h index 2b6d27db7c..fa83f9389c 100644 --- a/include/sysemu/block-backend-global-state.h +++ b/include/sysemu/block-backend-global-state.h @@ -42,7 +42,10 @@ blk_co_new_open(const char *filename, const char *refere= nce, QDict *options, =20 int blk_get_refcnt(BlockBackend *blk); void blk_ref(BlockBackend *blk); -void blk_unref(BlockBackend *blk); + +void no_coroutine_fn blk_unref(BlockBackend *blk); +void coroutine_fn no_co_wrapper blk_co_unref(BlockBackend *blk); + void blk_remove_all_bs(void); BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); diff --git a/block.c b/block.c index 5ec1a3897e..20d5ee0959 100644 --- a/block.c +++ b/block.c @@ -680,7 +680,7 @@ int coroutine_fn bdrv_co_create_opts_simple(BlockDriver= *drv, =20 ret =3D 0; out: - blk_unref(blk); + blk_co_unref(blk); return ret; } =20 diff --git a/block/crypto.c b/block/crypto.c index ca67289187..8fd3ad0054 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -355,7 +355,7 @@ block_crypto_co_create_generic(BlockDriverState *bs, in= t64_t size, ret =3D 0; cleanup: qcrypto_block_free(crypto); - blk_unref(blk); + blk_co_unref(blk); return ret; } =20 @@ -661,7 +661,7 @@ block_crypto_co_create_luks(BlockdevCreateOptions *crea= te_options, Error **errp) =20 ret =3D 0; fail: - bdrv_unref(bs); + bdrv_co_unref(bs); return ret; } =20 @@ -730,7 +730,7 @@ fail: bdrv_co_delete_file_noerr(bs); } =20 - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_QCryptoBlockCreateOptions(create_opts); qobject_unref(cryptoopts); return ret; diff --git a/block/parallels.c b/block/parallels.c index 013684801a..b49c35929e 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -613,8 +613,8 @@ static int coroutine_fn parallels_co_create(BlockdevCre= ateOptions* opts, =20 ret =3D 0; out: - blk_unref(blk); - bdrv_unref(bs); + blk_co_unref(blk); + bdrv_co_unref(bs); return ret; =20 exit: @@ -691,7 +691,7 @@ parallels_co_create_opts(BlockDriver *drv, const char *= filename, =20 done: qobject_unref(qdict); - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } diff --git a/block/qcow.c b/block/qcow.c index 490e4f819e..a0c701f578 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -915,8 +915,8 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOp= tions *opts, g_free(tmp); ret =3D 0; exit: - blk_unref(qcow_blk); - bdrv_unref(bs); + blk_co_unref(qcow_blk); + bdrv_co_unref(bs); qcrypto_block_free(crypto); return ret; } @@ -1015,7 +1015,7 @@ qcow_co_create_opts(BlockDriver *drv, const char *fil= ename, fail: g_free(backing_fmt); qobject_unref(qdict); - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index 94cf59af8b..01742b3ebe 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3705,7 +3705,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) goto out; } =20 - blk_unref(blk); + blk_co_unref(blk); blk =3D NULL; =20 /* @@ -3785,7 +3785,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) } } =20 - blk_unref(blk); + blk_co_unref(blk); blk =3D NULL; =20 /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returni= ng. @@ -3810,9 +3810,9 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) =20 ret =3D 0; out: - blk_unref(blk); - bdrv_unref(bs); - bdrv_unref(data_bs); + blk_co_unref(blk); + bdrv_co_unref(bs); + bdrv_co_unref(data_bs); return ret; } =20 @@ -3943,8 +3943,8 @@ finish: } =20 qobject_unref(qdict); - bdrv_unref(bs); - bdrv_unref(data_bs); + bdrv_co_unref(bs); + bdrv_co_unref(data_bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } diff --git a/block/qed.c b/block/qed.c index 0705a7b4e2..aff2a2076e 100644 --- a/block/qed.c +++ b/block/qed.c @@ -748,8 +748,8 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCrea= teOptions *opts, ret =3D 0; /* success */ out: g_free(l1_table); - blk_unref(blk); - bdrv_unref(bs); + blk_co_unref(blk); + bdrv_co_unref(bs); return ret; } =20 @@ -819,7 +819,7 @@ bdrv_qed_co_create_opts(BlockDriver *drv, const char *f= ilename, =20 fail: qobject_unref(qdict); - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } diff --git a/block/vdi.c b/block/vdi.c index f2434d6153..08331d2dd7 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -886,8 +886,8 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreate= Options *create_options, =20 ret =3D 0; exit: - blk_unref(blk); - bdrv_unref(bs_file); + blk_co_unref(blk); + bdrv_co_unref(bs_file); g_free(bmap); return ret; } @@ -975,7 +975,7 @@ vdi_co_create_opts(BlockDriver *drv, const char *filena= me, done: qobject_unref(qdict); qapi_free_BlockdevCreateOptions(create_options); - bdrv_unref(bs_file); + bdrv_co_unref(bs_file); return ret; } =20 diff --git a/block/vhdx.c b/block/vhdx.c index 81420722a1..00777da91a 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2053,8 +2053,8 @@ static int coroutine_fn vhdx_co_create(BlockdevCreate= Options *opts, =20 ret =3D 0; delete_and_exit: - blk_unref(blk); - bdrv_unref(bs); + blk_co_unref(blk); + bdrv_co_unref(bs); g_free(creator); return ret; } @@ -2144,7 +2144,7 @@ vhdx_co_create_opts(BlockDriver *drv, const char *fil= ename, =20 fail: qobject_unref(qdict); - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } diff --git a/block/vmdk.c b/block/vmdk.c index 3f8c731e32..11b553ef25 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2306,7 +2306,7 @@ exit: if (pbb) { *pbb =3D blk; } else { - blk_unref(blk); + blk_co_unref(blk); blk =3D NULL; } } @@ -2516,12 +2516,12 @@ vmdk_co_do_create(int64_t size, if (strcmp(blk_bs(backing)->drv->format_name, "vmdk")) { error_setg(errp, "Invalid backing file format: %s. Must be vmd= k", blk_bs(backing)->drv->format_name); - blk_unref(backing); + blk_co_unref(backing); ret =3D -EINVAL; goto exit; } ret =3D vmdk_read_cid(blk_bs(backing), 0, &parent_cid); - blk_unref(backing); + blk_co_unref(backing); if (ret) { error_setg(errp, "Failed to read parent CID"); goto exit; @@ -2542,14 +2542,14 @@ vmdk_co_do_create(int64_t size, blk_bs(extent_blk)->filename); created_size +=3D cur_size; extent_idx++; - blk_unref(extent_blk); + blk_co_unref(extent_blk); } =20 /* Check whether we got excess extents */ extent_blk =3D extent_fn(-1, extent_idx, flat, split, compress, zeroed= _grain, opaque, NULL); if (extent_blk) { - blk_unref(extent_blk); + blk_co_unref(extent_blk); error_setg(errp, "List of extents contains unused extents"); ret =3D -EINVAL; goto exit; @@ -2590,7 +2590,7 @@ vmdk_co_do_create(int64_t size, ret =3D 0; exit: if (blk) { - blk_unref(blk); + blk_co_unref(blk); } g_free(desc); g_free(parent_desc_line); @@ -2641,7 +2641,7 @@ vmdk_co_create_opts_cb(int64_t size, int idx, bool fl= at, bool split, errp)) { goto exit; } - bdrv_unref(bs); + bdrv_co_unref(bs); exit: g_free(ext_filename); return blk; @@ -2797,12 +2797,12 @@ static BlockBackend * coroutine_fn vmdk_co_create_c= b(int64_t size, int idx, return NULL; } blk_set_allow_write_beyond_eof(blk, true); - bdrv_unref(bs); + bdrv_co_unref(bs); =20 if (size !=3D -1) { ret =3D vmdk_init_extent(blk, size, flat, compress, zeroed_grain, = errp); if (ret) { - blk_unref(blk); + blk_co_unref(blk); blk =3D NULL; } } diff --git a/block/vpc.c b/block/vpc.c index b89b0ff8e2..07ddda5b99 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1082,8 +1082,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, } =20 out: - blk_unref(blk); - bdrv_unref(bs); + blk_co_unref(blk); + bdrv_co_unref(bs); return ret; } =20 @@ -1162,7 +1162,7 @@ vpc_co_create_opts(BlockDriver *drv, const char *file= name, =20 fail: qobject_unref(qdict); - bdrv_unref(bs); + bdrv_co_unref(bs); qapi_free_BlockdevCreateOptions(create_options); return ret; } --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201889; cv=none; d=zohomail.com; s=zohoarc; b=hBmVq+hSTcvAsjp3nm69GPJNzSJdbEyaESvrAaOUgAcWuVIKhUyWj1VThZsxWuzOYYMTTtnBr+cFnVV9n6Ywb27wQmmondwAeXXdtIFbtFYR4f54DStCmXnEVTnGX+YJyaWRUV8uouT2WAwpUj0V7itpWwEFItMT+uZISqElM2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201889; h=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=dZ+h7ase581NGdpvJuAaYn+E0GOZEbMPKQhKKqG4uQ0=; b=g3+EQf9XrzaE0/A06Omuvw3uQRt+VsmF8NQKjTLJx4aSp/ByBIw4iZHwsFjr2OAoEshzyJYMW4i5yOkiAfxgttWnO0kWq5IBZaJ4JCjBWXOCBOparSH3tjWs8PJAp0z/bLjwhcWdUH5XrYR8+SlMgpppCCiRiJcbL1cFL/lQtJU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201889501407.31578395669385; Thu, 4 May 2023 05:04:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbN-0003EE-8G; Thu, 04 May 2023 07:58:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb5-00035b-TP for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb4-0004BC-Cs for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:07 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-AATEeXqcOT20ST50ZR0vOw-1; Thu, 04 May 2023 07:58:04 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F2C311C07594; Thu, 4 May 2023 11:58:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0999C15BAD; Thu, 4 May 2023 11:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201485; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dZ+h7ase581NGdpvJuAaYn+E0GOZEbMPKQhKKqG4uQ0=; b=KL0zGv3WrXpgDabU9FdTu5dvsesrhjtCDIstljVBWub4VDAxyoTYkcTZp9STsLOrKW8rCo Z17MnxjrxowJNW3AeYB4hATdkYRezPI392K9cfs3BCda+JylGB7bwJ8eUfFJyk+bXNHNmh 8Sc4cPCGr11TdDX1+4zbfbXI0ELsShE= X-MC-Unique: AATEeXqcOT20ST50ZR0vOw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 04/20] block: Don't call no_coroutine_fns in qmp_block_resize() Date: Thu, 4 May 2023 13:57:34 +0200 Message-Id: <20230504115750.54437-5-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201890695100001 Content-Type: text/plain; charset="utf-8" This QMP handler runs in a coroutine, so it must use the corresponding no_co_wrappers instead. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- blockdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index 2c1752a403..e464daea58 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2440,7 +2440,7 @@ void coroutine_fn qmp_block_resize(const char *device= , const char *node_name, return; } =20 - blk =3D blk_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, errp); + blk =3D blk_co_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, errp); if (!blk) { return; } @@ -2455,7 +2455,7 @@ void coroutine_fn qmp_block_resize(const char *device= , const char *node_name, =20 bdrv_co_lock(bs); bdrv_drained_end(bs); - blk_unref(blk); + blk_co_unref(blk); bdrv_co_unlock(bs); } =20 --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201708; cv=none; d=zohomail.com; s=zohoarc; b=A05YLEjhMfoIwqXgo7lCNjoXVxtuf+NC8FRL9tlOsD+c9c1CegAIHjQBdyHMfu6c/w69/ToLuP1RKfDr3aPi+5K0QfwG6C0AUKgAqlg99mXJzPNYbVn2EyclUVW0d3SRkOhIaRuki/bnT3BXf8RRgI1wQZ80VZIwHGvJliXsnCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201708; h=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=b5jLUirhNoYzN1twE71CbT//aP1PZdge+4Tqoso7lE8=; b=h5DbzDQBen/9uH+dZQ3r/GQ5iUdjCLcBpAEFiwCfdPi/m33b4fec4SHJiqU0LyBlDrySTmTIozyNY//z1jywCok2Ez8qZXUVRJPlYXaVV1L9HgageExsB4EixcPFqsh7qWHtvUTHFmVKjXCiiVup+O/8nE04q9bw1yW+3fBFPBo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201708765311.93656681099185; Thu, 4 May 2023 05:01:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbY-0003VI-Az; Thu, 04 May 2023 07:58:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbK-0003Eg-Jo for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXb7-0004C8-LC for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:22 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-127-kLKPG78UMm-uY-rIsN5Hhg-1; Thu, 04 May 2023 07:58:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49A2B38221C7; Thu, 4 May 2023 11:58:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 370F8C15BAD; Thu, 4 May 2023 11:58:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b5jLUirhNoYzN1twE71CbT//aP1PZdge+4Tqoso7lE8=; b=L6Y0qJ81auUtbWQwyAjDqBZ/lqeRu0nLC5uF1ui3AidJBjY6JPgnTIZ1wB9kkhRd3EXuey +Wpj9O6cXv4RlcSojjwK9nV1afEZgg4YmKTGD//owObwqpgNeDBhv8EY07CHqvcySRzp0m RBnIUIC6sapcJR8TcKlgswpqFPcTiyk= X-MC-Unique: kLKPG78UMm-uY-rIsN5Hhg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 05/20] test-bdrv-drain: Don't modify the graph in coroutines Date: Thu, 4 May 2023 13:57:35 +0200 Message-Id: <20230504115750.54437-6-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201719865100001 Content-Type: text/plain; charset="utf-8" test-bdrv-drain contains a few test cases that are run both in coroutine and non-coroutine context. Running the entire code including the setup and shutdown in coroutines is incorrect because graph modifications can generally not happen in coroutines. Change the test so that creating and destroying the test nodes and BlockBackends always happens outside of coroutine context. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- tests/unit/test-bdrv-drain.c | 112 +++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 37 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index d9d3807062..9a4c5e59d6 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -188,6 +188,25 @@ static void do_drain_begin_unlocked(enum drain_type dr= ain_type, BlockDriverState } } =20 +static BlockBackend * no_coroutine_fn test_setup(void) +{ + BlockBackend *blk; + BlockDriverState *bs, *backing; + + blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); + bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, + &error_abort); + blk_insert_bs(blk, bs, &error_abort); + + backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); + bdrv_set_backing_hd(bs, backing, &error_abort); + + bdrv_unref(backing); + bdrv_unref(bs); + + return blk; +} + static void do_drain_end_unlocked(enum drain_type drain_type, BlockDriverS= tate *bs) { if (drain_type !=3D BDRV_DRAIN_ALL) { @@ -199,25 +218,19 @@ static void do_drain_end_unlocked(enum drain_type dra= in_type, BlockDriverState * } } =20 -static void test_drv_cb_common(enum drain_type drain_type, bool recursive) +static void test_drv_cb_common(BlockBackend *blk, enum drain_type drain_ty= pe, + bool recursive) { - BlockBackend *blk; - BlockDriverState *bs, *backing; + BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *backing =3D bs->backing->bs; BDRVTestState *s, *backing_s; BlockAIOCB *acb; int aio_ret; =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); s =3D bs->opaque; - blk_insert_bs(blk, bs, &error_abort); - - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); backing_s =3D backing->opaque; - bdrv_set_backing_hd(bs, backing, &error_abort); =20 /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */ g_assert_cmpint(s->drain_count, =3D=3D, 0); @@ -252,44 +265,53 @@ static void test_drv_cb_common(enum drain_type drain_= type, bool recursive) =20 g_assert_cmpint(s->drain_count, =3D=3D, 0); g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); - - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); } =20 static void test_drv_cb_drain_all(void) { - test_drv_cb_common(BDRV_DRAIN_ALL, true); + BlockBackend *blk =3D test_setup(); + test_drv_cb_common(blk, BDRV_DRAIN_ALL, true); + blk_unref(blk); } =20 static void test_drv_cb_drain(void) { - test_drv_cb_common(BDRV_DRAIN, false); + BlockBackend *blk =3D test_setup(); + test_drv_cb_common(blk, BDRV_DRAIN, false); + blk_unref(blk); +} + +static void coroutine_fn test_drv_cb_co_drain_all_entry(void) +{ + BlockBackend *blk =3D blk_all_next(NULL); + test_drv_cb_common(blk, BDRV_DRAIN_ALL, true); } =20 static void test_drv_cb_co_drain_all(void) { - call_in_coroutine(test_drv_cb_drain_all); + BlockBackend *blk =3D test_setup(); + call_in_coroutine(test_drv_cb_co_drain_all_entry); + blk_unref(blk); } =20 -static void test_drv_cb_co_drain(void) +static void coroutine_fn test_drv_cb_co_drain_entry(void) { - call_in_coroutine(test_drv_cb_drain); + BlockBackend *blk =3D blk_all_next(NULL); + test_drv_cb_common(blk, BDRV_DRAIN, false); } =20 -static void test_quiesce_common(enum drain_type drain_type, bool recursive) +static void test_drv_cb_co_drain(void) { - BlockBackend *blk; - BlockDriverState *bs, *backing; - - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); - blk_insert_bs(blk, bs, &error_abort); + BlockBackend *blk =3D test_setup(); + call_in_coroutine(test_drv_cb_co_drain_entry); + blk_unref(blk); +} =20 - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); - bdrv_set_backing_hd(bs, backing, &error_abort); +static void test_quiesce_common(BlockBackend *blk, enum drain_type drain_t= ype, + bool recursive) +{ + BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *backing =3D bs->backing->bs; =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); @@ -307,30 +329,46 @@ static void test_quiesce_common(enum drain_type drain= _type, bool recursive) =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); - - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); } =20 static void test_quiesce_drain_all(void) { - test_quiesce_common(BDRV_DRAIN_ALL, true); + BlockBackend *blk =3D test_setup(); + test_quiesce_common(blk, BDRV_DRAIN_ALL, true); + blk_unref(blk); } =20 static void test_quiesce_drain(void) { - test_quiesce_common(BDRV_DRAIN, false); + BlockBackend *blk =3D test_setup(); + test_quiesce_common(blk, BDRV_DRAIN, false); + blk_unref(blk); +} + +static void coroutine_fn test_quiesce_co_drain_all_entry(void) +{ + BlockBackend *blk =3D blk_all_next(NULL); + test_quiesce_common(blk, BDRV_DRAIN_ALL, true); } =20 static void test_quiesce_co_drain_all(void) { - call_in_coroutine(test_quiesce_drain_all); + BlockBackend *blk =3D test_setup(); + call_in_coroutine(test_quiesce_co_drain_all_entry); + blk_unref(blk); +} + +static void coroutine_fn test_quiesce_co_drain_entry(void) +{ + BlockBackend *blk =3D blk_all_next(NULL); + test_quiesce_common(blk, BDRV_DRAIN, false); } =20 static void test_quiesce_co_drain(void) { - call_in_coroutine(test_quiesce_drain); + BlockBackend *blk =3D test_setup(); + call_in_coroutine(test_quiesce_co_drain_entry); + blk_unref(blk); } =20 static void test_nested(void) --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201554; cv=none; d=zohomail.com; s=zohoarc; b=UKRHV5koH3Zsk26R+Nf8wHqzpcmCFQ1oy3ZL6TLWmB4I8iN4e7aVySgrJYlE+V0yR67zDlGnXhWM9+BLatC6JcAtOqea8o3xJ/ohUhQ6rT3xfS794yCUtLj8BglhQi5JhaG+Gfe7DeGeZLztKOAYfn1KLsNBHTQdho+gTgHf3uY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201554; h=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=1tJPsUDy0/a5aRDPOU/Kfiz+JnZ5QWXleCNGkgAkRew=; b=AauySkWL4AFL4OPYDV5rsf/ITl5VUdG85IQfHAbzrEyf0H3gryodkCBx5k3dj6B8DI/w5TJ97w80W7B9EBq2/iFjHYMOQqHnOOMoMAqa4Soepv7AGqleoDDZY+TsJKWRF3R6xKsgisKH+ojni4a75ZJkFPGaYGBWoiowyJSYO5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201554114695.5203243355984; Thu, 4 May 2023 04:59:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbS-0003Ko-I2; Thu, 04 May 2023 07:58:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbD-00039Q-V1 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbA-0004Cp-P0 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:15 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-Ppi5M15YM3GzW9VBzC-3vQ-1; Thu, 04 May 2023 07:58:06 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 950FD884341; Thu, 4 May 2023 11:58:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81429C15BAD; Thu, 4 May 2023 11:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201491; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1tJPsUDy0/a5aRDPOU/Kfiz+JnZ5QWXleCNGkgAkRew=; b=jNnHlvg0StxvrE8AwW2qBDVrbbW1EC03UqwqIXWnSG1iF/VBd1CZDTZCTW7OEaiyr987tt Vj5MQpoG5SKYyXx/6FdMEOWzlmB5YaIoD6E+BYKvKXPjdCsta45lUCRpVwyviVxdKfAi2v k4tiJke3Hv3KvhmMlwL629B4Ztbk3Ns= X-MC-Unique: Ppi5M15YM3GzW9VBzC-3vQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 06/20] graph-lock: Add GRAPH_UNLOCKED(_PTR) Date: Thu, 4 May 2023 13:57:36 +0200 Message-Id: <20230504115750.54437-7-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201556020100007 Content-Type: text/plain; charset="utf-8" For some functions, it is part of their interface to be called without holding the graph lock. Add a new macro to document this. The macro expands to TSA_EXCLUDES(), which is a relatively weak check because it passes in cases where the compiler just doesn't know if the lock is held. Function pointers can't be checked at all. Therefore, its primary purpose is documentation. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/graph-lock.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h index ac0fef8605..f17d1588e7 100644 --- a/include/block/graph-lock.h +++ b/include/block/graph-lock.h @@ -73,6 +73,7 @@ extern BdrvGraphLock graph_lock; */ #define GRAPH_WRLOCK TSA_REQUIRES(graph_lock) #define GRAPH_RDLOCK TSA_REQUIRES_SHARED(graph_lock) +#define GRAPH_UNLOCKED TSA_EXCLUDES(graph_lock) =20 /* * TSA annotations are not part of function types, so checks are defeated = when @@ -83,6 +84,7 @@ extern BdrvGraphLock graph_lock; */ #define GRAPH_RDLOCK_PTR TSA_GUARDED_BY(graph_lock) #define GRAPH_WRLOCK_PTR TSA_GUARDED_BY(graph_lock) +#define GRAPH_UNLOCKED_PTR =20 /* * register_aiocontext: --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201646; cv=none; d=zohomail.com; s=zohoarc; b=diJtUmBUNjXgJJjvV/4kU4PScUPL/pejmXGI95xou3EbMZRQNq9XSBnDMgdK+LkIYKo3ZPvFnoeYuDQaW88OS4pKqMdEBujRKtquNmWx97Weloq+X2ZYjFwkvEpMZShPf4P4VqiFKI61i36WNKUstHZuf+pBd07KbyHwUrQK8tI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201646; h=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=tOHQtQr3/59fDREj7disi55ITHVjHcEhzH/D1IWPZUU=; b=n+mSYpsDr+X167/i20DWUhhhu7uoJbB2/CBM1CnzdR32jJ8SV4h5HJu3qf061axksueM6qRi+Ya8fcLHH86SL2Xj4IIjcBvwEjalhA5wngtoKLcyWTyiS3/9fFYJH+VbFSV7p4fQVzovx1d1X52kMBTECC/QiLjzZVYGR2LYvnA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201646090616.7170565373542; Thu, 4 May 2023 05:00:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbW-0003Q9-Oh; Thu, 04 May 2023 07:58:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbD-00039R-VZ for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbC-0004D9-0V for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:15 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-534-0R--2_3XNkO3QkxV8Av7Fw-1; Thu, 04 May 2023 07:58:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5712811E7B; Thu, 4 May 2023 11:58:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD36EC15BAD; Thu, 4 May 2023 11:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tOHQtQr3/59fDREj7disi55ITHVjHcEhzH/D1IWPZUU=; b=c9HPUFwxkpnv5oLcGMtGnnkdAdXKO8Yr2uSe+AQwkP9uBkxVGSOuFTOlqsMpndw2jKZt5M C4oJk6re395G4/gS0Z7KggfmKE7H8ebmuvrDX1mPXP/UoEpEPMEU90SYK09JAYUVKP9x2V tTkuAxXao1YUxYFZKKSND/eKI/BJ2do= X-MC-Unique: 0R--2_3XNkO3QkxV8Av7Fw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 07/20] graph-lock: Fix GRAPH_RDLOCK_GUARD*() to be reader lock Date: Thu, 4 May 2023 13:57:37 +0200 Message-Id: <20230504115750.54437-8-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201647070100001 Content-Type: text/plain; charset="utf-8" GRAPH_RDLOCK_GUARD() and GRAPH_RDLOCK_GUARD_MAINLOOP() only take a reader lock for the graph, so the correct annotation for them to use is TSA_ASSERT_SHARED rather than TSA_ASSERT. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/graph-lock.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h index f17d1588e7..7574a2de5b 100644 --- a/include/block/graph-lock.h +++ b/include/block/graph-lock.h @@ -205,12 +205,12 @@ typedef struct GraphLockable { } GraphLockable; #define GML_OBJ_() (&(GraphLockable) { }) =20 /* - * This is not marked as TSA_ACQUIRE() because TSA doesn't understand the + * This is not marked as TSA_ACQUIRE_SHARED() because TSA doesn't understa= nd the * cleanup attribute and would therefore complain that the graph is never - * unlocked. TSA_ASSERT() makes sure that the following calls know that we - * hold the lock while unlocking is left unchecked. + * unlocked. TSA_ASSERT_SHARED() makes sure that the following calls know = that + * we hold the lock while unlocking is left unchecked. */ -static inline GraphLockable * TSA_ASSERT(graph_lock) TSA_NO_TSA coroutine_= fn +static inline GraphLockable * TSA_ASSERT_SHARED(graph_lock) TSA_NO_TSA cor= outine_fn graph_lockable_auto_lock(GraphLockable *x) { bdrv_graph_co_rdlock(); @@ -249,12 +249,12 @@ typedef struct GraphLockableMainloop { } GraphLockabl= eMainloop; #define GMLML_OBJ_() (&(GraphLockableMainloop) { }) =20 /* - * This is not marked as TSA_ACQUIRE() because TSA doesn't understand the + * This is not marked as TSA_ACQUIRE_SHARED() because TSA doesn't understa= nd the * cleanup attribute and would therefore complain that the graph is never - * unlocked. TSA_ASSERT() makes sure that the following calls know that we - * hold the lock while unlocking is left unchecked. + * unlocked. TSA_ASSERT_SHARED() makes sure that the following calls know = that + * we hold the lock while unlocking is left unchecked. */ -static inline GraphLockableMainloop * TSA_ASSERT(graph_lock) TSA_NO_TSA +static inline GraphLockableMainloop * TSA_ASSERT_SHARED(graph_lock) TSA_NO= _TSA graph_lockable_auto_lock_mainloop(GraphLockableMainloop *x) { bdrv_graph_rdlock_main_loop(); --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201581; cv=none; d=zohomail.com; s=zohoarc; b=LUF3JH/pUvLe8zbEg/Zebt4wLN6nHORczw6sZwU2LCdziQiZuCiwtNJ7/0PbwJDge/p0m9/gZwJzF67ucZBRgzk770A4fdKjaYjPGH5J1fk7oo/86H6HImEBlNQVTkwZxkJ9FTeHNzjMWW9GylUiG3pvoRPlU8xosyS/C9TVSH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201581; h=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=tU7ahHCz+W2gnqL9QeXCpZJM9olRFNuNP87npfPIqOg=; b=AmhPYC9S4t937udyB5a42nN6J25DXvv36MU9etkY4Eem9qXWOdlX+uMhiHzxRSl4jP98hnXUPgItZUbsRK3BrYe/l9kipiNc+iN35QvtrnYfDkErwgWxGF4PHMr1TV/Q+pbHzVc4JhX5cP6O6uxAmfZjmeFwlCzHpnNRNbISBQw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201581081868.0972410626327; Thu, 4 May 2023 04:59:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbU-0003Mg-34; Thu, 04 May 2023 07:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbG-0003Ag-4W for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbD-0004DZ-NK for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:17 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-ScPiV8MeNUSf3a6EK2HnKg-1; Thu, 04 May 2023 07:58:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59889101A531; Thu, 4 May 2023 11:58:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 298BBC15BAD; Thu, 4 May 2023 11:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tU7ahHCz+W2gnqL9QeXCpZJM9olRFNuNP87npfPIqOg=; b=IfQluCE790rOSRC8uUpMzSSJdPF9bAWxvyxo0FsUV5gCyQ3O+x8gVTEO69kNVtUVq6Pm4M BU6FvmkUO2k+VC+mYgriZo5gyMVCc4upD54OvRnaCZSmvN9aa8vpPkbzTuw2qEPcvB+lCc gyHINAQObWu0D5kTAddJ9iDvJkOTbUY= X-MC-Unique: ScPiV8MeNUSf3a6EK2HnKg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 08/20] block: .bdrv_open is non-coroutine and unlocked Date: Thu, 4 May 2023 13:57:38 +0200 Message-Id: <20230504115750.54437-9-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201583164100001 Content-Type: text/plain; charset="utf-8" Drivers were a bit confused about whether .bdrv_open can run in a coroutine and whether or not it holds a graph lock. It cannot keep a graph lock from the caller across the whole function because it both changes the graph (requires a writer lock) and does I/O (requires a reader lock). Therefore, it should take these locks internally as needed. The functions used to be called in coroutine context during image creation. This was buggy for other reasons, and as of commit 32192301, all block drivers go through no_co_wrappers. So it is not called in coroutine context any more. Fix qcow2 and qed to work with the correct assumptions: The graph lock needs to be taken internally instead of just assuming it's already there, and the coroutine path is dead code that can be removed. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block_int-common.h | 8 ++++---- block.c | 6 +++--- block/qcow2.c | 15 ++++++--------- block/qed.c | 18 ++++++++---------- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 013d419444..6fb28cd8fa 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -236,12 +236,12 @@ struct BlockDriver { void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state); void (*bdrv_join_options)(QDict *options, QDict *old_options); =20 - int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags, - Error **errp); + int GRAPH_UNLOCKED_PTR (*bdrv_open)( + BlockDriverState *bs, QDict *options, int flags, Error **errp); =20 /* Protocol drivers should implement this instead of bdrv_open */ - int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, - Error **errp); + int GRAPH_UNLOCKED_PTR (*bdrv_file_open)( + BlockDriverState *bs, QDict *options, int flags, Error **errp); void (*bdrv_close)(BlockDriverState *bs); =20 int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( diff --git a/block.c b/block.c index 20d5ee0959..abec940867 100644 --- a/block.c +++ b/block.c @@ -1610,9 +1610,9 @@ out: * bdrv_refresh_total_sectors() which polls when called from non-coroutine * context. */ -static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, - const char *node_name, QDict *options, - int open_flags, Error **errp) +static int no_coroutine_fn GRAPH_UNLOCKED +bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, const char *node_= name, + QDict *options, int open_flags, Error **errp) { Error *local_err =3D NULL; int i, ret; diff --git a/block/qcow2.c b/block/qcow2.c index 01742b3ebe..5bde3b8401 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1891,7 +1891,7 @@ static void coroutine_fn qcow2_open_entry(void *opaqu= e) QCow2OpenCo *qoc =3D opaque; BDRVQcow2State *s =3D qoc->bs->opaque; =20 - assume_graph_lock(); /* FIXME */ + GRAPH_RDLOCK_GUARD(); =20 qemu_co_mutex_lock(&s->lock); qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, @@ -1920,14 +1920,11 @@ static int qcow2_open(BlockDriverState *bs, QDict *= options, int flags, /* Initialise locks */ qemu_co_mutex_init(&s->lock); =20 - if (qemu_in_coroutine()) { - /* From bdrv_co_create. */ - qcow2_open_entry(&qoc); - } else { - assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context(= )); - qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc)= ); - BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); - } + assert(!qemu_in_coroutine()); + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + qemu_coroutine_enter(qemu_coroutine_create(qcow2_open_entry, &qoc)); + BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); + return qoc.ret; } =20 diff --git a/block/qed.c b/block/qed.c index aff2a2076e..be9ff0fb34 100644 --- a/block/qed.c +++ b/block/qed.c @@ -557,11 +557,13 @@ typedef struct QEDOpenCo { int ret; } QEDOpenCo; =20 -static void coroutine_fn GRAPH_RDLOCK bdrv_qed_open_entry(void *opaque) +static void coroutine_fn bdrv_qed_open_entry(void *opaque) { QEDOpenCo *qoc =3D opaque; BDRVQEDState *s =3D qoc->bs->opaque; =20 + GRAPH_RDLOCK_GUARD(); + qemu_co_mutex_lock(&s->table_lock); qoc->ret =3D bdrv_qed_do_open(qoc->bs, qoc->options, qoc->flags, qoc->= errp); qemu_co_mutex_unlock(&s->table_lock); @@ -579,21 +581,17 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict = *options, int flags, }; int ret; =20 - assume_graph_lock(); /* FIXME */ - ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); if (ret < 0) { return ret; } =20 bdrv_qed_init_state(bs); - if (qemu_in_coroutine()) { - bdrv_qed_open_entry(&qoc); - } else { - assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context(= )); - qemu_coroutine_enter(qemu_coroutine_create(bdrv_qed_open_entry, &q= oc)); - BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); - } + assert(!qemu_in_coroutine()); + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + qemu_coroutine_enter(qemu_coroutine_create(bdrv_qed_open_entry, &qoc)); + BDRV_POLL_WHILE(bs, qoc.ret =3D=3D -EINPROGRESS); + return qoc.ret; } =20 --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201704; cv=none; d=zohomail.com; s=zohoarc; b=ALIzTt42XN7v1ydpRMPiIvyjZYFVjSPCYqAQToSzN1EZ9rdE30MR4eWbDhOp6MA4/hSW2046wmKbomw+Dlaeqqb/RNAS+mHDdbsOajaED8l4hLvpRIjyn9F/o4Ux0uUqC66X4EJINn3bNle4pYz0OFXMoXWB6FjZKSkRSlpRQOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201704; h=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=GxkK5CZ4aQrNPUciTwgsAV6ozk6+OUv0xyYpufbraCg=; b=LAoCpt7JkUqKQdP/5eY4/3YcR2O+tqEjpFe4SGPsVEdptFy11YwCVE8d52kMqs8gtbgAwuODqePLo0FlYO+0uuD1yrs8DdpuanB80b6BgzJD8BjlmXtmH4jrGNNHPEm3hwc2TR8Z1JOVUdWrP9QFoTqW1p/ish2AbFYEaoGOzJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168320170481296.72702350318389; Thu, 4 May 2023 05:01:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbc-0003rn-IA; Thu, 04 May 2023 07:58:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbS-0003Kq-Ed for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbC-0004DM-Ry for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-505-OwAkV7baMVGSELoYANUwOw-1; Thu, 04 May 2023 07:58:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE2A1800B35; Thu, 4 May 2023 11:58:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90F6DC15BAD; Thu, 4 May 2023 11:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GxkK5CZ4aQrNPUciTwgsAV6ozk6+OUv0xyYpufbraCg=; b=ArzGbhqhlS7K7NOa6bOi+T0LKzFwCx/aCFdgNTOrHo7Jo6tbtV3MBw3+Ir56VYeQm/rvbt kPfxXZOdwL2qWLFOMI2w89mG+wN0cSYn56kXQ/ROaOwNuLhxw6wnchh3Wampndo0aLH9eN tkNFXBPbUvL3GO4K9VnBXg6HgHPXDPM= X-MC-Unique: OwAkV7baMVGSELoYANUwOw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 09/20] nbd: Remove nbd_co_flush() wrapper function Date: Thu, 4 May 2023 13:57:39 +0200 Message-Id: <20230504115750.54437-10-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201715596100003 Content-Type: text/plain; charset="utf-8" The only thing nbd_co_flush() does is call nbd_client_co_flush(). Just use that function directly in the BlockDriver definitions and remove the wrapper. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/nbd.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index bf2894ad5c..d3ee256844 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1920,11 +1920,6 @@ fail: return ret; } =20 -static int coroutine_fn nbd_co_flush(BlockDriverState *bs) -{ - return nbd_client_co_flush(bs); -} - static void nbd_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; @@ -2120,7 +2115,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_co_pwritev =3D nbd_client_co_pwritev, .bdrv_co_pwrite_zeroes =3D nbd_client_co_pwrite_zeroes, .bdrv_close =3D nbd_close, - .bdrv_co_flush_to_os =3D nbd_co_flush, + .bdrv_co_flush_to_os =3D nbd_client_co_flush, .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, @@ -2148,7 +2143,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_co_pwritev =3D nbd_client_co_pwritev, .bdrv_co_pwrite_zeroes =3D nbd_client_co_pwrite_zeroes, .bdrv_close =3D nbd_close, - .bdrv_co_flush_to_os =3D nbd_co_flush, + .bdrv_co_flush_to_os =3D nbd_client_co_flush, .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, @@ -2176,7 +2171,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_co_pwritev =3D nbd_client_co_pwritev, .bdrv_co_pwrite_zeroes =3D nbd_client_co_pwrite_zeroes, .bdrv_close =3D nbd_close, - .bdrv_co_flush_to_os =3D nbd_co_flush, + .bdrv_co_flush_to_os =3D nbd_client_co_flush, .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201554; cv=none; d=zohomail.com; s=zohoarc; b=gRklB9d1njYwbjqtVe2CBGEp6VWWbI8JmriWHe7aMfm3EuS50z6K1tZgJdzagiqq4+D1vIL/Disr6w/FVLTiIwpiD4tSeloLN3okbvxOAQpMauv6vk4SVzoTaiXAzCFldyUBn3H7DOK7c/2gmSAC6t+9TvsWmo5FKecU9ziPZbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201554; h=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=NhJZo29oQVPz0Wd5Il6SwrHFblLFckXczaunQDpp8Zs=; b=gudWL1vh0CwIjYqAcS2P5GlxMy77OxdkBcNkI31Xz32ZrqMhkhBhFCuwg9snXSc8jLC5D6aE+MEf8/jp96jA0sRy2t3pmndwI5A5xEWqQHZGsTk4ebgrZTZ3Rce4ShW7s+a5p9h5gpKgXwTaBD8RNf3qCSLSPEOq/m0R5uTYuoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201554878103.97410210389512; Thu, 4 May 2023 04:59:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbb-0003lJ-Eq; Thu, 04 May 2023 07:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbS-0003LD-HN for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbP-0004Fn-9Z for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:30 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-fOwFevG4OYKrdErnTGqTUA-1; Thu, 04 May 2023 07:58:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0900338221C7; Thu, 4 May 2023 11:58:14 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id E66CAC15BAD; Thu, 4 May 2023 11:58:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NhJZo29oQVPz0Wd5Il6SwrHFblLFckXczaunQDpp8Zs=; b=QKd6zS+61gS/8sfRP4iSgoTaProyfwZKwmEyQvraGTIH4KhMpGkDMUwq2QfiaA86L6E3/w qc2loaITrzK3KV2C76V/LYJZoDk21Rd2kzBEr1j49QSx1isoH+/BUW+l3Pm8gJvYFAo8Jg NievlwUHGwl/yodlu3bXfpWXucsdyo4= X-MC-Unique: fOwFevG4OYKrdErnTGqTUA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 10/20] nbd: Mark nbd_co_do_establish_connection() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:40 +0200 Message-Id: <20230504115750.54437-11-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201557116100011 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of nbd_co_do_establish_connection() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/coroutines.h | 5 +++-- block/nbd.c | 39 +++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index dd9f3d449b..f3226682d6 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -61,7 +61,7 @@ bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector = *qiov, int64_t pos); int coroutine_fn GRAPH_RDLOCK bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); =20 -int coroutine_fn +int coroutine_fn GRAPH_RDLOCK nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp); =20 @@ -85,7 +85,8 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file, int *depth); -int co_wrapper_mixed + +int co_wrapper_mixed_bdrv_rdlock nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **e= rrp); =20 #endif /* BLOCK_COROUTINES_H */ diff --git a/block/nbd.c b/block/nbd.c index d3ee256844..a3f8f8a9d5 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -322,6 +322,7 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, int ret; IO_CODE(); =20 + assert_bdrv_graph_readable(); assert(!s->ioc); =20 s->ioc =3D nbd_co_establish_connection(s->conn, &s->info, blocking, er= rp); @@ -369,7 +370,7 @@ static bool nbd_client_connecting(BDRVNBDState *s) } =20 /* Called with s->requests_lock taken. */ -static coroutine_fn void nbd_reconnect_attempt(BDRVNBDState *s) +static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_attempt(BDRVNBDState *= s) { int ret; bool blocking =3D s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT; @@ -480,9 +481,9 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDStat= e *s, uint64_t handle) } } =20 -static int coroutine_fn nbd_co_send_request(BlockDriverState *bs, - NBDRequest *request, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +nbd_co_send_request(BlockDriverState *bs, NBDRequest *request, + QEMUIOVector *qiov) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; int rc, i =3D -1; @@ -1171,8 +1172,9 @@ static int coroutine_fn nbd_co_receive_blockstatus_re= ply(BDRVNBDState *s, return iter.ret; } =20 -static int coroutine_fn nbd_co_request(BlockDriverState *bs, NBDRequest *r= equest, - QEMUIOVector *write_qiov) +static int coroutine_fn GRAPH_RDLOCK +nbd_co_request(BlockDriverState *bs, NBDRequest *request, + QEMUIOVector *write_qiov) { int ret, request_ret; Error *local_err =3D NULL; @@ -1208,9 +1210,9 @@ static int coroutine_fn nbd_co_request(BlockDriverSta= te *bs, NBDRequest *request return ret ? ret : request_ret; } =20 -static int coroutine_fn nbd_client_co_preadv(BlockDriverState *bs, int64_t= offset, - int64_t bytes, QEMUIOVector *= qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +nbd_client_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret, request_ret; Error *local_err =3D NULL; @@ -1266,9 +1268,9 @@ static int coroutine_fn nbd_client_co_preadv(BlockDri= verState *bs, int64_t offse return ret ? ret : request_ret; } =20 -static int coroutine_fn nbd_client_co_pwritev(BlockDriverState *bs, int64_= t offset, - int64_t bytes, QEMUIOVector = *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +nbd_client_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; NBDRequest request =3D { @@ -1291,8 +1293,9 @@ static int coroutine_fn nbd_client_co_pwritev(BlockDr= iverState *bs, int64_t offs return nbd_co_request(bs, &request, qiov); } =20 -static int coroutine_fn nbd_client_co_pwrite_zeroes(BlockDriverState *bs, = int64_t offset, - int64_t bytes, BdrvReq= uestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t = bytes, + BdrvRequestFlags flags) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; NBDRequest request =3D { @@ -1326,7 +1329,7 @@ static int coroutine_fn nbd_client_co_pwrite_zeroes(B= lockDriverState *bs, int64_ return nbd_co_request(bs, &request, NULL); } =20 -static int coroutine_fn nbd_client_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK nbd_client_co_flush(BlockDriverState = *bs) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; NBDRequest request =3D { .type =3D NBD_CMD_FLUSH }; @@ -1341,8 +1344,8 @@ static int coroutine_fn nbd_client_co_flush(BlockDriv= erState *bs) return nbd_co_request(bs, &request, NULL); } =20 -static int coroutine_fn nbd_client_co_pdiscard(BlockDriverState *bs, int64= _t offset, - int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; NBDRequest request =3D { @@ -1361,7 +1364,7 @@ static int coroutine_fn nbd_client_co_pdiscard(BlockD= riverState *bs, int64_t off return nbd_co_request(bs, &request, NULL); } =20 -static int coroutine_fn nbd_client_co_block_status( +static int coroutine_fn GRAPH_RDLOCK nbd_client_co_block_status( BlockDriverState *bs, bool want_zero, int64_t offset, int64_t byte= s, int64_t *pnum, int64_t *map, BlockDriverState **file) { --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201801; cv=none; d=zohomail.com; s=zohoarc; b=cYgrzt+CsMpS81SavOdKIlm2nIlC9OmnFVPTAMFxE2fCMOqJPiMOJ/trqQF04flErTOmKdNUpWeYcyMUcbuqOPD4xiA0Jajq01MNpNR85abY7zVO9sscfq/bwfTAZdYRit43947A9AhpOfH7HmgQ5Yq9iZ6046f3ICvbJsbDeUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201801; h=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=i81jJMpIATmtlfBmGOPfMo/WO9M89YDrGbDRXnlDZfs=; b=bpQEQgntWtd5QcWJfuVd97WhGenJj/P1GZibsx9hyTSk8wqpkvtAvqQCGipYeyZsgJBYCbVJYBoVnC/psbCm3h/GgA6n7oXAOn2u1OOZ59Gb0kuA+HbI+UK065CitU8RnPFbGyxzVuEsleJd4bMaROoYCqllxgwu9vpePr8l/W0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201801001858.6928646047929; Thu, 4 May 2023 05:03:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbZ-0003d6-PG; Thu, 04 May 2023 07:58:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbK-0003Ea-FB for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbH-0004E9-Bj for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-458-U03l7DrIMMSQDySAA5fIzA-1; Thu, 04 May 2023 07:58:15 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 610B5811E7C; Thu, 4 May 2023 11:58:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40A6FC15BAD; Thu, 4 May 2023 11:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201498; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i81jJMpIATmtlfBmGOPfMo/WO9M89YDrGbDRXnlDZfs=; b=YM48aHtXR+xwQia2OY+9stAiKLPRNyFquBFi0mhLfNUrXpYLo8Fi4pqGrxdhn13Dd5RX4T 7571snO+VFzTk1M/sAhA11h4wq3fV4agap/u4kG9/Ty2lya/2CWLTevX51BMu+lB4aLbmF d/WTrLpkoxMiEFeVZ5R5fRftLWcQO3Q= X-MC-Unique: U03l7DrIMMSQDySAA5fIzA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 11/20] vhdx: Require GRAPH_RDLOCK for accessing a node's parent list Date: Thu, 4 May 2023 13:57:41 +0200 Message-Id: <20230504115750.54437-12-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201802271100002 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that functions accessing the parent list of a node need to hold a reader lock for the graph. As it happens, they already do. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/vhdx.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 00777da91a..b20b1edf11 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1506,8 +1506,9 @@ exit: * There are 2 headers, and the highest sequence number will represent * the active header */ -static int vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size, - uint32_t log_size) +static int coroutine_fn GRAPH_RDLOCK +vhdx_create_new_headers(BlockBackend *blk, uint64_t image_size, + uint32_t log_size) { BlockDriverState *bs =3D blk_bs(blk); BdrvChild *child; @@ -1897,8 +1898,8 @@ exit: * .---- ~ ----------- ~ ------------ ~ ---------------- ~ -----------. * 1MB */ -static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_create(BlockdevCreateOptions *opts, Error **errp) { BlockdevCreateOptionsVhdx *vhdx_opts; BlockBackend *blk =3D NULL; --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201663; cv=none; d=zohomail.com; s=zohoarc; b=QLsflm5gxwT3AffutfBxGfEzp+CQ5Wtb1K89c9+zFgv1G90dl2n81gTz0EEm7dSxKm46PgFnrl0D6vrWXO4+GQiC2fvPIwTTXrTGUYmwTp3l8urIOtCAqzhN6HFhMX5uVyPgQ/qb5DsbRVnKBE7V2ob1OqxXlSPE9n+1gwE47bA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201663; h=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=K/sdHy6Fk6pNRu5YspXW3VX0IYXNu43UTK5jXiiG9iI=; b=liRy4+d9BdD7aAtgxdOz9w1+y8LDNfhuEdulRmnW2l7mCLaI8wkVJj7krlW0WJcawRcJufu/Aj0j6y/QmL9m+/PIcrkSBoSUO8S/xwLzfb/36tgAVI4sDLmh3UXu68I9t8fKYTqeV1NWB2A3FzSnOAjo6KE0stu5wZkJwqBI8aY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168320166323748.83216355430477; Thu, 4 May 2023 05:01:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbY-0003Vw-HP; Thu, 04 May 2023 07:58:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbL-0003Fq-WD for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbI-0004EP-Pf for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:23 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-335GQX_mNiKGsv2RaZnTzw-1; Thu, 04 May 2023 07:58:17 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD73EA0F388; Thu, 4 May 2023 11:58:16 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98C3AC15BAD; Thu, 4 May 2023 11:58:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K/sdHy6Fk6pNRu5YspXW3VX0IYXNu43UTK5jXiiG9iI=; b=dH9arHHJCkZAvRJyxPGaAir94cp20GMktGL09HjNrmDpTnNIInZWOCPRksq3lpfhYEfuzv VBCsN5jvGiJVMkGaYbr6wcVUCclDmB4yTPb3uZsLkewXiudLZA29EAGjY1DpwpETm8q/QX Su1yCpdOwOoKfFjZ06YvQ9nocc3GdTg= X-MC-Unique: 335GQX_mNiKGsv2RaZnTzw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 12/20] mirror: Require GRAPH_RDLOCK for accessing a node's parent list Date: Thu, 4 May 2023 13:57:42 +0200 Message-Id: <20230504115750.54437-13-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201665883100009 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that functions accessing the parent list of a node need to hold a reader lock for the graph. As it happens, they already do. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/mirror.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 80fa345071..b5c4ae31f3 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1416,7 +1416,7 @@ static MirrorOp *coroutine_fn active_write_prepare(Mi= rrorBlockJob *s, return op; } =20 -static void coroutine_fn active_write_settle(MirrorOp *op) +static void coroutine_fn GRAPH_RDLOCK active_write_settle(MirrorOp *op) { uint64_t start_chunk =3D op->offset / op->s->granularity; uint64_t end_chunk =3D DIV_ROUND_UP(op->offset + op->bytes, --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201633; cv=none; d=zohomail.com; s=zohoarc; b=NpZUn9oxaI36KF421JppEz5TBhlQ4p38VTV5vvEQ7Fn/zUnnCiiiPquQ2W1v36EFToylhAzx1yaTOVTkt/KDPOQCZthE+PrySNXqJg3m0/iw2ldDEZc738WqgdqpwhOS94v2nQqBOgvJZ8QF2dsoIlmhlH0RSmLcfpTLbtO8d7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201633; h=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=+eO7Ise7Lvc5QyPq6wHNHS6S7KxgQRw9eJppNosft58=; b=NIKFK1Xe4vo65byu4P+9nkXHMfKW/BPT/O3K2VR8TrT4eZcYIKUY7i8jVspEkuZFTWZbnn3azyQ0LK8XbqPWnXvTBXrBuwTfqXbPPCknVE6OT18TgCUXpqF5Qb3K57UT1Rc6MDbU6L6491tf1NeJV9CAlk9GNNyDBhmCgCzh44s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201633729341.43255012933196; Thu, 4 May 2023 05:00:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbb-0003mW-PL; Thu, 04 May 2023 07:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbL-0003Fl-V2 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbI-0004EJ-4E for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:23 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-321-ZR50s-kiOGyD55VZHgXJMQ-1; Thu, 04 May 2023 07:58:18 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 077413C1068B; Thu, 4 May 2023 11:58:18 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id E613EC15BAD; Thu, 4 May 2023 11:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+eO7Ise7Lvc5QyPq6wHNHS6S7KxgQRw9eJppNosft58=; b=ieJjlCt/sLyAwTE8oW/5BCFd9meEY69ovRinUVgvJ4KJ9oPe2loR5mHBTccuXkOc78Coeq D2bGav5DRhkMpymTIU2b4VY07GhpQNNGFeCZrxl+NkXwto4oCBzu0g0dXcEMn9T0lzfJQO iJjp3afOkQRfoeqsZe+LtxacHv0Nqkc= X-MC-Unique: ZR50s-kiOGyD55VZHgXJMQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 13/20] block: Mark bdrv_co_get_allocated_file_size() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:43 +0200 Message-Id: <20230504115750.54437-14-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201634811100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_get_allocated_file_size() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-io.h | 7 +++++-- include/block/block_int-common.h | 2 +- block.c | 4 +++- block/vmdk.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 5dab88521d..fb2adb31c7 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -84,8 +84,11 @@ int64_t coroutine_mixed_fn bdrv_nb_sectors(BlockDriverSt= ate *bs); int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_getlength(BlockDriverState *bs); int64_t co_wrapper_mixed_bdrv_rdlock bdrv_getlength(BlockDriverState *bs); =20 -int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs); -int64_t co_wrapper bdrv_get_allocated_file_size(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK +bdrv_co_get_allocated_file_size(BlockDriverState *bs); + +int64_t co_wrapper_bdrv_rdlock +bdrv_get_allocated_file_size(BlockDriverState *bs); =20 BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6fb28cd8fa..6e0365d8f2 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -685,7 +685,7 @@ struct BlockDriver { int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_getlength)( BlockDriverState *bs); =20 - int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( + int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_get_allocated_file_siz= e)( BlockDriverState *bs); =20 BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, diff --git a/block.c b/block.c index abec940867..3ccb935950 100644 --- a/block.c +++ b/block.c @@ -5750,7 +5750,8 @@ exit: * sums the size of all data-bearing children. (This excludes backing * children.) */ -static int64_t coroutine_fn bdrv_sum_allocated_file_size(BlockDriverState = *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +bdrv_sum_allocated_file_size(BlockDriverState *bs) { BdrvChild *child; int64_t child_size, sum =3D 0; @@ -5778,6 +5779,7 @@ int64_t coroutine_fn bdrv_co_get_allocated_file_size(= BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; diff --git a/block/vmdk.c b/block/vmdk.c index 11b553ef25..fddbd1c86c 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2845,7 +2845,7 @@ static void vmdk_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static int64_t coroutine_fn +static int64_t coroutine_fn GRAPH_RDLOCK vmdk_co_get_allocated_file_size(BlockDriverState *bs) { int i; --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201557; cv=none; d=zohomail.com; s=zohoarc; b=BBGlkwHyNYjIxLrWrzOcie1EsqRlc2j7NVJRdq/Tq2SwsAPOTMHL+iOe9sTEnKX6MJRyOIhWxlOHyBeom6yZj/a2NWOUaSb3/l9aQltSlJTJ6vPMZBmirsFsGdi//Am9c7o8atUoJ0B6d9SwJrXzUx0ecIttXqI7i5DvmIgjQQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201557; h=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=DF4i67+jE0B+7rPzv4KwH9kOencdv/UJ1i01ycr3cgs=; b=Do4gJ+xIdlO0yh3aQPKC/8Dux0AtPBtzm4y5qFt7evKT4MMnUujrSKDOxz0t4N3pAp9+FP+KbgEgW3zDDjyxFniJPMj8u3RrRjBxbIX5+4Qbcv3//yRqMDx1vErGABfme9F1eNDYENMSZf7B6dNkr64sBlBgibYxNdBoUvvq81E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201557072725.2901848380442; Thu, 4 May 2023 04:59:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbU-0003MX-1S; Thu, 04 May 2023 07:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbO-0003Hz-Q3 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbL-0004Ez-9Z for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:26 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-tl2pPeWcOXq_rjRkiFdTYA-1; Thu, 04 May 2023 07:58:19 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59A5C109DCE7; Thu, 4 May 2023 11:58:19 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F7A2C15BAD; Thu, 4 May 2023 11:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DF4i67+jE0B+7rPzv4KwH9kOencdv/UJ1i01ycr3cgs=; b=JaBt7ZK6uHAcbZrETO6/CRtFzJTOPG8/SDgjWCwsIcbE+DxqCG/T7n43XaBP0OktSi8BMP DaeBiywIiYIiWcbppqlmW69akpyYElpPW818u9nfDktY1RhrQmryWm/jPVH6RZFn8jK+Ly sOD8vJ/SjIL1v9+Ws093ocoY27glmtI= X-MC-Unique: tl2pPeWcOXq_rjRkiFdTYA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 14/20] block: Mark bdrv_co_get_info() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:44 +0200 Message-Id: <20230504115750.54437-15-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201559099100015 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_get_info() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-io.h | 7 +++++-- include/block/block_int-common.h | 4 ++-- block.c | 2 ++ block/crypto.c | 2 +- block/io.c | 11 +++++------ block/mirror.c | 8 ++++++-- block/raw-format.c | 2 +- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index fb2adb31c7..bba7f957e1 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -167,8 +167,11 @@ const char *bdrv_get_node_name(const BlockDriverState = *bs); const char *bdrv_get_device_name(const BlockDriverState *bs); const char *bdrv_get_device_or_node_name(const BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_get_info(BlockDriverState *bs, BlockDriverInfo *b= di); -int co_wrapper_mixed bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *= bdi); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); + +int co_wrapper_mixed_bdrv_rdlock +bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); =20 ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6e0365d8f2..ee77903f72 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -699,8 +699,8 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); =20 - int coroutine_fn (*bdrv_co_get_info)(BlockDriverState *bs, - BlockDriverInfo *bdi); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_get_info)( + BlockDriverState *bs, BlockDriverInfo *bdi); =20 ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs, Error **errp); diff --git a/block.c b/block.c index 3ccb935950..a6deaf8ad1 100644 --- a/block.c +++ b/block.c @@ -6349,6 +6349,8 @@ int coroutine_fn bdrv_co_get_info(BlockDriverState *b= s, BlockDriverInfo *bdi) int ret; BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); + /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { return -ENOMEDIUM; diff --git a/block/crypto.c b/block/crypto.c index 8fd3ad0054..30093cff9b 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -736,7 +736,7 @@ fail: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_get_info_luks(BlockDriverState *bs, BlockDriverInfo *bdi) { BlockDriverInfo subbdi; diff --git a/block/io.c b/block/io.c index 6fa1993374..3bf9ef9d87 100644 --- a/block/io.c +++ b/block/io.c @@ -727,10 +727,9 @@ BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_requ= est(BlockDriverState *bs) /** * Round a region to cluster boundaries */ -void coroutine_fn bdrv_round_to_clusters(BlockDriverState *bs, - int64_t offset, int64_t bytes, - int64_t *cluster_offset, - int64_t *cluster_bytes) +void coroutine_fn GRAPH_RDLOCK +bdrv_round_to_clusters(BlockDriverState *bs, int64_t offset, int64_t bytes, + int64_t *cluster_offset, int64_t *cluster_bytes) { BlockDriverInfo bdi; IO_CODE(); @@ -744,7 +743,7 @@ void coroutine_fn bdrv_round_to_clusters(BlockDriverSta= te *bs, } } =20 -static coroutine_fn int bdrv_get_cluster_size(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK bdrv_get_cluster_size(BlockDriverStat= e *bs) { BlockDriverInfo bdi; int ret; @@ -1800,7 +1799,7 @@ fail: return ret; } =20 -static inline int coroutine_fn +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_write_req_prepare(BdrvChild *child, int64_t offset, int64_t bytes, BdrvTrackedRequest *req, int flags) { diff --git a/block/mirror.c b/block/mirror.c index b5c4ae31f3..e48ed0af31 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -576,8 +576,10 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) } else if (ret >=3D 0 && !(ret & BDRV_BLOCK_DATA)) { int64_t target_offset; int64_t target_bytes; - bdrv_round_to_clusters(blk_bs(s->target), offset, io_bytes, - &target_offset, &target_bytes); + WITH_GRAPH_RDLOCK_GUARD() { + bdrv_round_to_clusters(blk_bs(s->target), offset, io_bytes, + &target_offset, &target_bytes); + } if (target_offset =3D=3D offset && target_bytes =3D=3D io_bytes) { mirror_method =3D ret & BDRV_BLOCK_ZERO ? @@ -966,11 +968,13 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) */ bdrv_get_backing_filename(target_bs, backing_filename, sizeof(backing_filename)); + bdrv_graph_co_rdlock(); if (!bdrv_co_get_info(target_bs, &bdi) && bdi.cluster_size) { s->target_cluster_size =3D bdi.cluster_size; } else { s->target_cluster_size =3D BDRV_SECTOR_SIZE; } + bdrv_graph_co_rdunlock(); if (backing_filename[0] && !bdrv_backing_chain_next(target_bs) && s->granularity < s->target_cluster_size) { s->buf_size =3D MAX(s->buf_size, s->target_cluster_size); diff --git a/block/raw-format.c b/block/raw-format.c index 06b8030d9d..fd9e61f58e 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -369,7 +369,7 @@ static BlockMeasureInfo *raw_measure(QemuOpts *opts, Bl= ockDriverState *in_bs, return info; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK raw_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return bdrv_co_get_info(bs->file->bs, bdi); --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201661; cv=none; d=zohomail.com; s=zohoarc; b=Y04Vdi1KO/ucqyee1oRNk5hFR7sxdux/d0APTzioKPqN9qz0H6QVv5KUs22dX16UkHMLWsyOUk4ypHK85A1MSulLVdkPW5Qvmq5C8NxkB+I6T5+ZcQGr9eFAE1W7CwTQGRacdlt/H6iYPat098ZckaIpCzu4aBD7KsNarhiOqSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201661; h=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=j7vwLRs9MG3iGbGuG/PDFuAio0GCNFXcM+j5WqYFfQQ=; b=KOAD+d6JjRGp6OohEGHq26ycez95GxJeqol6oh9hSQPgQ7nL4D7drQutTLseuQnZYgCTrYwD7bQuHCOKNC0Sm+ntoiDYblDDvetjTJDLBq5z0TB12uEm57+3V4WIlzxlnCnOWHP1QmuQMqyQDMmR+d67KZDqRgmfF4G0V/HuZ3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201661109311.9321903785259; Thu, 4 May 2023 05:01:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbW-0003Q8-Ps; Thu, 04 May 2023 07:58:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbQ-0003IV-4m for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbM-0004Fa-Nl for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-0_3Xv0-jMAKm3HOfKQ42DQ-1; Thu, 04 May 2023 07:58:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A76A4185A790; Thu, 4 May 2023 11:58:20 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91234C15BAD; Thu, 4 May 2023 11:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j7vwLRs9MG3iGbGuG/PDFuAio0GCNFXcM+j5WqYFfQQ=; b=FgNjyaaWDaElxb8cjduBciVa/CAXLJUXS2DuRv0YTUbsbHl70469Mp75Zq3PuFeCLCTqh9 e3kNBbJNtQpqjL2QxUd/HNG1rC4cT8LEtg6UI7lFUYPNfwd7jfdmqx9FZB/6qdHlZkRap2 hw8fFtWXuCZeSzRNjrpmOogBhkUHhTw= X-MC-Unique: 0_3Xv0-jMAKm3HOfKQ42DQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 15/20] block: Mark bdrv_co_debug_event() GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:45 +0200 Message-Id: <20230504115750.54437-16-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201663171100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_debug_event() need to hold a reader lock for the graph. Unfortunately we cannot use a co_wrapper_bdrv_rdlock (i.e. make the coroutine wrapper a no_coroutine_fn), because the function is called (using the BLKDBG_EVENT macro) by mixed functions that run both in coroutine and non-coroutine context (for example many of the functions in qcow2-cluster.c and qcow2-refcount.c). Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 4 ++-- block.c | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index bba7f957e1..1f612ec5bd 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -205,10 +205,11 @@ void *qemu_try_blockalign0(BlockDriverState *bs, size= _t size); void bdrv_enable_copy_on_read(BlockDriverState *bs); void bdrv_disable_copy_on_read(BlockDriverState *bs); =20 -void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, - BlkdebugEvent event); -void co_wrapper_mixed bdrv_debug_event(BlockDriverState *bs, - BlkdebugEvent event); +void coroutine_fn GRAPH_RDLOCK +bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent event); + +void co_wrapper_mixed_bdrv_rdlock +bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event); =20 #define BLKDBG_EVENT(child, evt) \ do { \ diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index ee77903f72..88ce7f9d9e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -735,8 +735,8 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_check)( BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix); =20 - void coroutine_fn (*bdrv_co_debug_event)(BlockDriverState *bs, - BlkdebugEvent event); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_debug_event)( + BlockDriverState *bs, BlkdebugEvent event); =20 /* io queue for linux-aio */ void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_plug)(BlockDriverState= *bs); diff --git a/block.c b/block.c index a6deaf8ad1..1bc766c778 100644 --- a/block.c +++ b/block.c @@ -6399,6 +6399,8 @@ BlockStatsSpecific *bdrv_get_specific_stats(BlockDriv= erState *bs) void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent = event) { IO_CODE(); + assert_bdrv_graph_readable(); + if (!bs || !bs->drv || !bs->drv->bdrv_co_debug_event) { return; } --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201765; cv=none; d=zohomail.com; s=zohoarc; b=TWpS+YWi2OlSyE36Y4tIX1sXxiA8vD052ZtDOUOVnqu1ipKU75gC1hzCctbHcgFIR4CBVYJijpUsVVGEAz2spXgkcB8Ko36a8PkvwlyIGAXbmbQ57Gqyz2GklSJaDimOTqD1/KUf0305Oh/E5pidEQHOZUWTIEqe7cMSlPnUCPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201765; h=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=sTUZWoOMsg2zP1xva543L+izUXQjBjaFhLACyrGXlHI=; b=MBNeR7DU/GQqeZKJ0odzc0532uACZxCizu/T8jnnmLLkxVISKc50EqvNFrYaGvjyTuBkBN61GZuK1VAwIPbxXH8KToT3aynFYrkI/EOaUw2PKYA74Pbpq/gdUViKzlMRgzj774p+urw6FOkLdbBvsF5GBCEdp0DJAfL6VZj4drE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201765439199.20816846063076; Thu, 4 May 2023 05:02:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXba-0003fQ-7G; Thu, 04 May 2023 07:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbQ-0003IU-3C for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbO-0004Fy-6O for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-197-KytW5uFJMHqjOzwp40g-jg-1; Thu, 04 May 2023 07:58:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3CCD811E7C; Thu, 4 May 2023 11:58:21 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id DECEFC15BAD; Thu, 4 May 2023 11:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sTUZWoOMsg2zP1xva543L+izUXQjBjaFhLACyrGXlHI=; b=gHxSqlUP4NY31t2CaX0g+j5wyqrNC238R6IjGvXHboBz0SyYeVEFgmjnTtJS4IGdB7rCSR AV3HmW4EDmSZE4shgrL4KxIr8kMmk9m+J805SpnWbChMsfH9bkiMzGc9ZLrNLffELT8vgo 1sgYVuUyXgnMv0K3j3DgxyYc6AbBL1c= X-MC-Unique: KytW5uFJMHqjOzwp40g-jg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 16/20] block: Mark BlockDriver callbacks for amend job GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:46 +0200 Message-Id: <20230504115750.54437-17-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201765992100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of amend callbacks in BlockDriver need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block_int-common.h | 12 ++++++------ block/amend.c | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 88ce7f9d9e..37d094796e 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -204,12 +204,13 @@ struct BlockDriver { * to allow driver-specific initialization code that requires * the BQL, like setting up specific permission flags. */ - int (*bdrv_amend_pre_run)(BlockDriverState *bs, Error **errp); + int GRAPH_RDLOCK_PTR (*bdrv_amend_pre_run)( + BlockDriverState *bs, Error **errp); /* * This function is invoked under BQL after .bdrv_co_amend() * to allow cleaning up what was done in .bdrv_amend_pre_run(). */ - void (*bdrv_amend_clean)(BlockDriverState *bs); + void GRAPH_RDLOCK_PTR (*bdrv_amend_clean)(BlockDriverState *bs); =20 /* * Return true if @to_replace can be replaced by a BDS with the @@ -463,10 +464,9 @@ struct BlockDriver { =20 int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filena= me); =20 - int coroutine_fn (*bdrv_co_amend)(BlockDriverState *bs, - BlockdevAmendOptions *opts, - bool force, - Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_amend)( + BlockDriverState *bs, BlockdevAmendOptions *opts, bool force, + Error **errp); =20 /* aio */ BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_preadv)(BlockDriverState *bs, diff --git a/block/amend.c b/block/amend.c index bc4bb7b416..53a410247c 100644 --- a/block/amend.c +++ b/block/amend.c @@ -46,6 +46,7 @@ static int coroutine_fn blockdev_amend_run(Job *job, Erro= r **errp) { BlockdevAmendJob *s =3D container_of(job, BlockdevAmendJob, common); int ret; + GRAPH_RDLOCK_GUARD(); =20 job_progress_set_remaining(&s->common, 1); ret =3D s->bs->drv->bdrv_co_amend(s->bs, s->opts, s->force, errp); @@ -54,7 +55,8 @@ static int coroutine_fn blockdev_amend_run(Job *job, Erro= r **errp) return ret; } =20 -static int blockdev_amend_pre_run(BlockdevAmendJob *s, Error **errp) +static int GRAPH_RDLOCK +blockdev_amend_pre_run(BlockdevAmendJob *s, Error **errp) { if (s->bs->drv->bdrv_amend_pre_run) { return s->bs->drv->bdrv_amend_pre_run(s->bs, errp); @@ -67,9 +69,11 @@ static void blockdev_amend_free(Job *job) { BlockdevAmendJob *s =3D container_of(job, BlockdevAmendJob, common); =20 + bdrv_graph_rdlock_main_loop(); if (s->bs->drv->bdrv_amend_clean) { s->bs->drv->bdrv_amend_clean(s->bs); } + bdrv_graph_rdunlock_main_loop(); =20 bdrv_unref(s->bs); } @@ -93,6 +97,8 @@ void qmp_x_blockdev_amend(const char *job_id, BlockDriver *drv =3D bdrv_find_format(fmt); BlockDriverState *bs; =20 + GRAPH_RDLOCK_GUARD_MAINLOOP(); + bs =3D bdrv_lookup_bs(NULL, node_name, errp); if (!bs) { return; --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201705; cv=none; d=zohomail.com; s=zohoarc; b=ZrA2P5jklmnoth3Fo0ZgTuwoW0E9d879f1fIFHPUas6UzECVDJpQTKUf+0eH3AioP8QH2U2xpNT986HgTi9xl7YcYWdPniiKh138HJzGV8Tnhcg9EKjE2M4FY/pc8uTiDbW9mrvaKXsegYRwoRH7aX7fZvCI4DruJy1JzICzQb8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201705; h=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=XZKCrqmNhgsnPTeK1gszRIdl4QSE8RZXAWYHCpXnO8E=; b=EQHy5KXKJ/O6erjpn81AK/53vYfHuWXUiRqAntHfzKkwMPPkprfcm0F0T+Uw1BNIUBjj34SPHAL9MFqu+PrUgMLgg/BV5CXMdPHOgVTyQ5Uwo224KlNW+8avx+yVB02C4YCOzrAAEFwZs2+7k+GiiTi+9U0wmipYw/DldFBJf/w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201705143154.13723376488235; Thu, 4 May 2023 05:01:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbb-0003in-QK; Thu, 04 May 2023 07:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbR-0003K4-7G for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbP-0004Fw-9b for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:28 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-66-AaLk_xOVMfSrE8ecPWbKyw-1; Thu, 04 May 2023 07:58:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EDF6C280BC47; Thu, 4 May 2023 11:58:23 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37981C15BAD; Thu, 4 May 2023 11:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XZKCrqmNhgsnPTeK1gszRIdl4QSE8RZXAWYHCpXnO8E=; b=g7auOgBYJTLLM6Iu71sy9EOh/cBXeTWjZca4pvQtThq6ui6wcqZiLJ38k9/w9vEROeGJVJ NyCqPcA+uQ2isG3IhUNoeYCjp5GMXXbpHqxjXrzjdMB3J6VJQDGkjj9xC1ssb+JO4QNKAg xysphDR/lJV0acll1let2YQBs0nnzpY= X-MC-Unique: AaLk_xOVMfSrE8ecPWbKyw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 17/20] block: Mark bdrv_query_bds_stats() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:47 +0200 Message-Id: <20230504115750.54437-18-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201716602100005 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_query_bds_stats() need to hold a reader lock for the graph because it accesses the children list of a node. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qapi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index c84147849d..71f2751257 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -604,8 +604,8 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, = BlockBackend *blk) =3D bdrv_latency_histogram_stats(&hgram[BLOCK_ACCT_FLUSH]); } =20 -static BlockStats *bdrv_query_bds_stats(BlockDriverState *bs, - bool blk_level) +static BlockStats * GRAPH_RDLOCK +bdrv_query_bds_stats(BlockDriverState *bs, bool blk_level) { BdrvChild *parent_child; BlockDriverState *filter_or_cow_bs; @@ -713,6 +713,8 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nod= es, BlockBackend *blk; BlockDriverState *bs; =20 + GRAPH_RDLOCK_GUARD_MAINLOOP(); + /* Just to be safe if query_nodes is not always initialized */ if (has_query_nodes && query_nodes) { for (bs =3D bdrv_next_node(NULL); bs; bs =3D bdrv_next_node(bs)) { --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201712; cv=none; d=zohomail.com; s=zohoarc; b=BQkBoASkFY/WwMhNbXwOEigu/jLl1rjUqOlQJqoJj44vhCNf7wGXV8vZcx8FdncaYVVPnpJaGyPV1LJ1VhW86lLCX9JxfBxBMXB3CZiMnv48aAThRD8iUCyf/ccKkJxX2LBAfKhzkZT2ZBdkChd9zqYvXfAno2GwPzMxOhAQKdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201712; h=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=KF//YYEKa89C7Kwr3ZcRWCvVN4G+Poi0Ti/7lAlEpj4=; b=CsWcasu6I3Je8Pkv6/9Cp6t6E0A26ccRzRM9rp0/0jSzhQwcgYeHKJTF6QKkmugwsX6ctiNJmF9tlmdcMh6mnBGWo8EOZKzGIJDoFXTlmzVbqJ/+I0ZvJAKzYWDP5wHOWBKO6zHFJgP2wBnlLNTySEou2zNs56q8tbUtEpTKguM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201712602593.7681918433797; Thu, 4 May 2023 05:01:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbe-0003wD-0c; Thu, 04 May 2023 07:58:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbU-0003Ng-4U for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbS-0004Hb-LG for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:31 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-wLB-oZxBMaOo0Ixbfep1xw-1; Thu, 04 May 2023 07:58:26 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E8CE185A78B; Thu, 4 May 2023 11:58:26 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35833C15BB8; Thu, 4 May 2023 11:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KF//YYEKa89C7Kwr3ZcRWCvVN4G+Poi0Ti/7lAlEpj4=; b=E29XUQGAoe/5DKBzS5FBf+ql7ZXT8zPlwzyQnElc4uiYpZuD7cGEw2zSvZ9D3vEQ5RSqen 0lDAzfIFGuf5O9qQTbr9FQhdYlEvOw1/vkQ9/9JMK2gQutNCSf9d0NU292ETRiGQuImvZl tF5CTkp/1IIO6q00oicayRbWgovUHHQ= X-MC-Unique: wLB-oZxBMaOo0Ixbfep1xw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 18/20] block: Mark bdrv_query_block_graph_info() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:48 +0200 Message-Id: <20230504115750.54437-19-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201726435100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_query_block_graph_info() need to hold a reader lock for the graph because it accesses the children list of a node. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/qapi.h | 7 ++++--- qemu-img.c | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/block/qapi.h b/include/block/qapi.h index 8773b9b191..18d48ddb70 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -25,6 +25,7 @@ #ifndef BLOCK_QAPI_H #define BLOCK_QAPI_H =20 +#include "block/graph-lock.h" #include "block/snapshot.h" #include "qapi/qapi-types-block-core.h" =20 @@ -43,9 +44,9 @@ void bdrv_query_image_info(BlockDriverState *bs, bool flat, bool skip_implicit_filters, Error **errp); -void bdrv_query_block_graph_info(BlockDriverState *bs, - BlockGraphInfo **p_info, - Error **errp); +void GRAPH_RDLOCK +bdrv_query_block_graph_info(BlockDriverState *bs, BlockGraphInfo **p_info, + Error **errp); =20 void bdrv_snapshot_dump(QEMUSnapshotInfo *sn); void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec, diff --git a/qemu-img.c b/qemu-img.c index 9aeac69fa6..9f9f0a7629 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2938,6 +2938,8 @@ static BlockGraphInfoList *collect_image_info_list(bo= ol image_opts, } bs =3D blk_bs(blk); =20 + GRAPH_RDLOCK_GUARD_MAINLOOP(); + /* * Note that the returned BlockGraphInfo object will not have * information about this image's backing node, because we have op= ened --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201669; cv=none; d=zohomail.com; s=zohoarc; b=mxy6ETmxo3+E0dAaZgfQ0BbdRitETIYkdhShl/ZREaqPPoMFSpAjG5lRgE0NYNwXe8VDd8KZVTzF2qXhH0uzDVAEbBkO6RUdQ9g6i3SOqAoCPzMQVTgmPjAb5VQq7dUy+LAcMoQP/eqQi/wISnVJWtM9wdFOsOaxc67Tpcoo418= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201669; h=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=oOq86BnFWA8YT2awmVhAjiZ3L0SCkkqkxa8RtHcPc+0=; b=YedL2NZJtIMztstEvtedCHXODXlahyqDPaTaVmMZyYfEdfNEfVp3RAL7LbCr63JgiEdDQ37ClKJcc36ypo3wQYUSJwj/XF5D8kemQ04NzXWXEZCgLUqCxkBjR97IiCFMfjCIYCEnvvochhtgkiH1d9S7uqTyWvPW08wuXJV1fXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201669910279.2558614742228; Thu, 4 May 2023 05:01:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbd-0003vH-G3; Thu, 04 May 2023 07:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbW-0003PH-9l for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbT-0004I9-Ni for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:33 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-213--j_7UTAlMXyrVSKZxt2pag-1; Thu, 04 May 2023 07:58:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA2B01C0758D; Thu, 4 May 2023 11:58:27 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 967F2C15BAD; Thu, 4 May 2023 11:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oOq86BnFWA8YT2awmVhAjiZ3L0SCkkqkxa8RtHcPc+0=; b=JBvk9jexOIrcdpeOFfMieX0heT9TgEHUg+NObPHBmL97a+ERmRn/h/6RKrIQ2XCARS7cjj ifhNJXnLCn01woVl5rotkRvL6JgfZ8r6AbciEpD8Fy2ithRukIn1XvLYuvAWMg6BEolGyi zPVkfdBru9mh4hP/DZHcnE3hQbGoAqU= X-MC-Unique: -j_7UTAlMXyrVSKZxt2pag-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 19/20] block: Mark bdrv_recurse_can_replace() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:49 +0200 Message-Id: <20230504115750.54437-20-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201674391100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_recurse_can_replace() need to hold a reader lock for the graph because it accesses the children list of a node. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-global-state.h | 5 +++-- include/block/block_int-common.h | 4 ++-- include/block/block_int-global-state.h | 4 ++-- block/blkverify.c | 5 +++-- block/mirror.c | 4 ++++ block/quorum.c | 4 ++-- blockdev.c | 3 +++ 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index ec3ddb17a8..f234bca0b6 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -163,8 +163,9 @@ int bdrv_amend_options(BlockDriverState *bs_new, QemuOp= ts *opts, Error **errp); =20 /* check if a named node can be replaced when doing drive-mirror */ -BlockDriverState *check_to_replace_node(BlockDriverState *parent_bs, - const char *node_name, Error **err= p); +BlockDriverState * GRAPH_RDLOCK +check_to_replace_node(BlockDriverState *parent_bs, const char *node_name, + Error **errp); =20 int no_coroutine_fn bdrv_activate(BlockDriverState *bs, Error **errp); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 37d094796e..024ded4fc2 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -217,8 +217,8 @@ struct BlockDriver { * same data as @bs without it affecting @bs's behavior (that is, * without it being visible to @bs's parents). */ - bool (*bdrv_recurse_can_replace)(BlockDriverState *bs, - BlockDriverState *to_replace); + bool GRAPH_RDLOCK_PTR (*bdrv_recurse_can_replace)( + BlockDriverState *bs, BlockDriverState *to_replace); =20 int (*bdrv_probe_device)(const char *filename); =20 diff --git a/include/block/block_int-global-state.h b/include/block/block_i= nt-global-state.h index 902406eb99..da5fb31089 100644 --- a/include/block/block_int-global-state.h +++ b/include/block/block_int-global-state.h @@ -225,8 +225,8 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm= , uint64_t shared, */ int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **e= rrp); =20 -bool bdrv_recurse_can_replace(BlockDriverState *bs, - BlockDriverState *to_replace); +bool GRAPH_RDLOCK bdrv_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace); =20 /* * Default implementation for BlockDriver.bdrv_child_perm() that can diff --git a/block/blkverify.c b/block/blkverify.c index 1c16f86b2e..7326461f30 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -265,8 +265,9 @@ static int coroutine_fn GRAPH_RDLOCK blkverify_co_flush= (BlockDriverState *bs) return bdrv_co_flush(s->test_file->bs); } =20 -static bool blkverify_recurse_can_replace(BlockDriverState *bs, - BlockDriverState *to_replace) +static bool GRAPH_RDLOCK +blkverify_recurse_can_replace(BlockDriverState *bs, + BlockDriverState *to_replace) { BDRVBlkverifyState *s =3D bs->opaque; =20 diff --git a/block/mirror.c b/block/mirror.c index e48ed0af31..717442ca4d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -747,7 +747,10 @@ static int mirror_exit_common(Job *job) * Cannot use check_to_replace_node() here, because that would * check for an op blocker on @to_replace, and we have our own * there. + * + * TODO Pull out the writer lock from bdrv_replace_node() to here */ + bdrv_graph_rdlock_main_loop(); if (bdrv_recurse_can_replace(src, to_replace)) { bdrv_replace_node(to_replace, target_bs, &local_err); } else { @@ -756,6 +759,7 @@ static int mirror_exit_common(Job *job) "would not lead to an abrupt change of visible data= ", to_replace->node_name, target_bs->node_name); } + bdrv_graph_rdunlock_main_loop(); bdrv_drained_end(target_bs); if (local_err) { error_report_err(local_err); diff --git a/block/quorum.c b/block/quorum.c index ff5a0a2da3..f28758cf2b 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -825,8 +825,8 @@ static coroutine_fn GRAPH_RDLOCK int quorum_co_flush(Bl= ockDriverState *bs) return result; } =20 -static bool quorum_recurse_can_replace(BlockDriverState *bs, - BlockDriverState *to_replace) +static bool GRAPH_RDLOCK +quorum_recurse_can_replace(BlockDriverState *bs, BlockDriverState *to_repl= ace) { BDRVQuorumState *s =3D bs->opaque; int i; diff --git a/blockdev.c b/blockdev.c index e464daea58..d141ca7a2d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2961,6 +2961,9 @@ static void blockdev_mirror_common(const char *job_id= , BlockDriverState *bs, BlockDriverState *unfiltered_bs; int job_flags =3D JOB_DEFAULT; =20 + GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + if (!has_speed) { speed =3D 0; } --=20 2.40.1 From nobody Tue May 14 07:05:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683201663; cv=none; d=zohomail.com; s=zohoarc; b=PRrQRM7DdYNHep/t8amMNURxwBA0zpO7x6LassritjGFvFb1qxyA0kU/vvRlkYsowO1c+DPMGODvmSyTtT5K116/ruc7osvOApcAl5dNYtHd9jeagDouEX6k6CwdcHkd8qgVWtIBXV9hBWmJYpZusPOnZBnQAFANsp+/K+cxKuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683201663; h=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=GyC4UfHad+kz1MVbuLV290vv8pN3kMDozePOi0V/IbY=; b=nabAy1TeWoT5uGO3vmEhxfudrGBYYaXOPFXZI3+mjQi6LMTwjc9/yTSo/e88BUO933Kd3uP9aIqFgV9KCa14TY3FyHCdcK1Kn5iJZqXOUIpCYKR2UVZH7kDYyBxOnCBNotG2BnPyQaHxqjpx3JwMXcEsIo5+saE6NlYnK6cfPE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683201663237584.077590369721; Thu, 4 May 2023 05:01:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puXbc-0003sZ-Q9; Thu, 04 May 2023 07:58:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbU-0003Nr-Lv for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1puXbT-0004I1-47 for qemu-devel@nongnu.org; Thu, 04 May 2023 07:58:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-403-7vKJ2IbhMROxdiFaL7R6iQ-1; Thu, 04 May 2023 07:58:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19B80A0F387; Thu, 4 May 2023 11:58:29 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id F11C6C15BAD; Thu, 4 May 2023 11:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683201510; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GyC4UfHad+kz1MVbuLV290vv8pN3kMDozePOi0V/IbY=; b=FR2/oc5ukDWvx6SaELseUlZ4D7sBLMM3oWIy7vv23XD8kHHziFhbyDwstcgeoefJlhtiWi zy8vORzlkCF1TXxMZeAVr+zVXy9LIPFRA+z3wi1kb/aNEIB0enNhTVaOmOFU/oM4VNSAwy 5ck7e+7UE9KP80uWxQ7NP0OHhKjRfVs= X-MC-Unique: 7vKJ2IbhMROxdiFaL7R6iQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 20/20] block: Mark bdrv_refresh_limits() and callers GRAPH_RDLOCK Date: Thu, 4 May 2023 13:57:50 +0200 Message-Id: <20230504115750.54437-21-kwolf@redhat.com> In-Reply-To: <20230504115750.54437-1-kwolf@redhat.com> References: <20230504115750.54437-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.161, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1683201665366100005 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_refresh_limits() need to hold a reader lock for the graph because it accesses the children list of a node. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- include/block/block-global-state.h | 5 ++++- include/block/block_int-common.h | 3 ++- block.c | 9 +++++++++ block/io.c | 1 - 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index f234bca0b6..2d93423d35 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -133,7 +133,10 @@ int bdrv_reopen_set_read_only(BlockDriverState *bs, bo= ol read_only, BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, const char *backing_file); void bdrv_refresh_filename(BlockDriverState *bs); -void bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error **= errp); + +void GRAPH_RDLOCK +bdrv_refresh_limits(BlockDriverState *bs, Transaction *tran, Error **errp); + int bdrv_commit(BlockDriverState *bs); int bdrv_make_empty(BdrvChild *c, Error **errp); int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_fil= e, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 024ded4fc2..4909876756 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -334,7 +334,8 @@ struct BlockDriver { int (*bdrv_debug_resume)(BlockDriverState *bs, const char *tag); bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag); =20 - void (*bdrv_refresh_limits)(BlockDriverState *bs, Error **errp); + void GRAPH_RDLOCK_PTR (*bdrv_refresh_limits)( + BlockDriverState *bs, Error **errp); =20 /* * Returns 1 if newly created images are guaranteed to contain only diff --git a/block.c b/block.c index 1bc766c778..dad9a4fa43 100644 --- a/block.c +++ b/block.c @@ -1667,7 +1667,10 @@ bdrv_open_driver(BlockDriverState *bs, BlockDriver *= drv, const char *node_name, return ret; } =20 + bdrv_graph_rdlock_main_loop(); bdrv_refresh_limits(bs, NULL, &local_err); + bdrv_graph_rdunlock_main_loop(); + if (local_err) { error_propagate(errp, local_err); return -EINVAL; @@ -3419,7 +3422,9 @@ static int bdrv_set_file_or_backing_noperm(BlockDrive= rState *parent_bs, } =20 out: + bdrv_graph_rdlock_main_loop(); bdrv_refresh_limits(parent_bs, tran, NULL); + bdrv_graph_rdunlock_main_loop(); =20 return 0; } @@ -4917,7 +4922,9 @@ static void bdrv_reopen_commit(BDRVReopenState *reope= n_state) qdict_del(bs->explicit_options, "backing"); qdict_del(bs->options, "backing"); =20 + bdrv_graph_rdlock_main_loop(); bdrv_refresh_limits(bs, NULL, NULL); + bdrv_graph_rdunlock_main_loop(); bdrv_refresh_total_sectors(bs, bs->total_sectors); } =20 @@ -5316,7 +5323,9 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriver= State *bs_top, out: tran_finalize(tran, ret); =20 + bdrv_graph_rdlock_main_loop(); bdrv_refresh_limits(bs_top, NULL, NULL); + bdrv_graph_rdunlock_main_loop(); =20 if (new_context && old_context !=3D new_context) { aio_context_release(new_context); diff --git a/block/io.c b/block/io.c index 3bf9ef9d87..58557f2f96 100644 --- a/block/io.c +++ b/block/io.c @@ -160,7 +160,6 @@ void bdrv_refresh_limits(BlockDriverState *bs, Transact= ion *tran, Error **errp) bool have_limits; =20 GLOBAL_STATE_CODE(); - assume_graph_lock(); /* FIXME */ =20 if (tran) { BdrvRefreshLimitsState *s =3D g_new(BdrvRefreshLimitsState, 1); --=20 2.40.1