From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437963; cv=none; d=zohomail.com; s=zohoarc; b=mRk9siFz2+u7DQp7HTK/2Bb9nRNqgzAShJTdhizDCwndSIVBQFS2Cb5inu7z/e/45LXLw3F7D6anTE0VoHXa5j4VO2SDokkiv60qwyYgMW9jh25loBaV28bDDU3QUvx1GpVwbm9Jgyc8iAwCqjCznJcVpy8rrqxNe7xx+6vI4Wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437963; 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=IkNqxcXoiEcIqI+TOUi8PzluuUNcjPnMLAZj0J2HVdo=; b=kvrTQNtjJZYgpDp7hwYJK+HGUKLQZ4jeEwIR5OE7FBnHKY1phoAXdfIoLhN4gR5Hko7qOwoYqg2Sz1odEt3VGrUBDOd/R0erEISjhjgiHg5u4Y6wWCGZUDDxI0kNL7+gFg1uzmeeYG69XQl8WXDD1LpWKEdA+9hTz5L2XgvIZFk= 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+importer2=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 1675437963718854.5737948294268; Fri, 3 Feb 2023 07:26:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtg-0007GL-Ci; Fri, 03 Feb 2023 10:22:40 -0500 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 1pNxte-0007F6-VO for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:38 -0500 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 1pNxtc-00054L-Tz for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:38 -0500 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-471-uofXDCzvMc-ingQJCZl9fg-1; Fri, 03 Feb 2023 10:22:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 92B338030D0; Fri, 3 Feb 2023 15:22:34 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09F42408573E; Fri, 3 Feb 2023 15:22:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437756; 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=IkNqxcXoiEcIqI+TOUi8PzluuUNcjPnMLAZj0J2HVdo=; b=WS+Uu+Bm0ykRgiRWokfLUN1ICt1qRm9dTQ1qhrFBRiPRpkm5EP9hWJHZxVmI4A9zw1xyCV ZXUsGUfMIs4e6T0svRE6EVsfKiI4zUaQpg8q+SoL0II61x/RSho1As/UV0+s4DKRG1yFh8 IHZN8qhOfxITYf8N3MWlO3+BtzyvtyU= X-MC-Unique: uofXDCzvMc-ingQJCZl9fg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 01/23] block: Make bdrv_can_set_read_only() static Date: Fri, 3 Feb 2023 16:21:40 +0100 Message-Id: <20230203152202.49054-2-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437965500100001 Content-Type: text/plain; charset="utf-8" It is never called outside of block.c. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block-io.h | 2 -- block.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 614cbd7eda..f9fa88204d 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -134,8 +134,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, - bool ignore_allow_rdw, Error **errp); int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, Error **errp); bool bdrv_is_read_only(BlockDriverState *bs); diff --git a/block.c b/block.c index 122aa9a9ac..c2a8d66f75 100644 --- a/block.c +++ b/block.c @@ -277,8 +277,8 @@ bool bdrv_is_read_only(BlockDriverState *bs) return !(bs->open_flags & BDRV_O_RDWR); } =20 -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, - bool ignore_allow_rdw, Error **errp) +static int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, + bool ignore_allow_rdw, Error **errp) { IO_CODE(); =20 --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437938; cv=none; d=zohomail.com; s=zohoarc; b=DJjgrNM0Tk0KsIYRlBtYmQPUOVfqgf+Qhvl/7aPOd6lkFriXLVfQPrbeQqeE/MFVBoxwoq66f7hhzJP/+TFNAJXKA34/gN5037M8c3YMFYvCdHB0AAvV8k3fldokK2LgUXvu039mKIrPqY1ArCy3pnb2mXNme6RSMCoqKYTpeD0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437938; 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=9FWIxIX0VhSeabhTBkO39/gJmbAWNLg0jACV2soe1Yg=; b=nU3HSdyjYtWarbGLic/C5KfLyTubpSvRm6ALjelQ9NTwOjFr/GfSaTk++Yqr3TgAyT/Q7D4drFJ3w6BbHR3yfaZvGBn61F9NgHb/O1AAExWjL3+sGyObavd3aLCxkgTRJ5LWLMYA1gEhnoukebNOdWx1rgPYM9ROKoy1niZeS+c= 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+importer2=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 1675437938128822.7042624137824; Fri, 3 Feb 2023 07:25:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtl-0007KC-VE; Fri, 03 Feb 2023 10:22:45 -0500 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 1pNxtk-0007JJ-IF for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:44 -0500 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 1pNxtj-0005HD-40 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:44 -0500 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-345-Ccw1MxUBM62M79Ix9Ve1EA-1; Fri, 03 Feb 2023 10:22:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C6083101B429; Fri, 3 Feb 2023 15:22:35 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC230410B1AD; Fri, 3 Feb 2023 15:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437762; 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=9FWIxIX0VhSeabhTBkO39/gJmbAWNLg0jACV2soe1Yg=; b=WDTY9NjKbx4TuS5vf7BAKPiuYa9Gubwbv5eo4P0ZDFPYsSS6IBe+6tQsHKm4APGpgfFTTm k+yReASMDELAfcRaf8AEGzMeFNohZ0SRHJ7jCSWYOgBGbStB8Ho8/Abkid6qitJnMoF12n THkYL8AdxGoA92UQmAU83iZbOUu+Q8A= X-MC-Unique: Ccw1MxUBM62M79Ix9Ve1EA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 02/23] mirror: Fix access of uninitialised fields during start Date: Fri, 3 Feb 2023 16:21:41 +0100 Message-Id: <20230203152202.49054-3-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437939305100001 Content-Type: text/plain; charset="utf-8" bdrv_mirror_top_pwritev() accesses the job object when active mirroring is enabled. It disables this code during early initialisation while s->job isn't set yet. However, s->job is still set way too early when the job object isn't fully initialised. For example, &s->ops_in_flight isn't initialised yet and the in_flight bitmap doesn't exist yet. This causes crashes when a write request comes in too early. Move the assignment of s->job to when the mirror job is actually fully initialised to make sure that the mirror_top driver doesn't access it too early. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/mirror.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index ab326b67c9..fbbb4f619e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -896,6 +896,7 @@ static int coroutine_fn mirror_run(Job *job, Error **er= rp) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; + MirrorBDSOpaque *mirror_top_opaque =3D s->mirror_top_bs->opaque; BlockDriverState *target_bs =3D blk_bs(s->target); bool need_drain =3D true; BlockDeviceIoStatus iostatus; @@ -985,6 +986,12 @@ static int coroutine_fn mirror_run(Job *job, Error **e= rrp) } } =20 + /* + * Only now the job is fully initialised and mirror_top_bs should start + * accessing it. + */ + mirror_top_opaque->job =3D s; + assert(!s->dbi); s->dbi =3D bdrv_dirty_iter_new(s->dirty_bitmap); for (;;) { @@ -1704,7 +1711,6 @@ static BlockJob *mirror_start_job( if (!s) { goto fail; } - bs_opaque->job =3D s; =20 /* The block job now has a reference to this node */ bdrv_unref(mirror_top_bs); --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437801; cv=none; d=zohomail.com; s=zohoarc; b=f5Yg4c1Bab4JTdLfyDC19v0aDX3eWlyvTye5IrjXSZCNU6uGZ3aJ3Gm46WWHhaHB7LfqQ3ft97xiCqQO/pfUeV5b4TdSF3vACZOS+TrIktTPceYI+2hW29zD6SRfaSl0kWXN0U2J/Yf9IWkz1oKyf+CcqCz6aYTXbzf2Yc+jaAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437801; 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=yFVAsROfmCE5NJOxdUrmfKkNG/j1E040c2my0mBQjio=; b=kpyRwGackTZxRoQXdmwyk/VmyodotdzYj3IGq2hzsVND6ufDVegeDpi4corsQSYHwb8+ViJ4uvv3FI9nOSfeRySQi0pqhwSD1LIvnhIau/AagoT/d/hPICb74I47li6MyE0mkGFPUZLhWYaw8rEZA4y4vH9pjYpa8Wdv7J0DUYY= 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+importer2=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 1675437801870879.1836696224268; Fri, 3 Feb 2023 07:23:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtj-0007Ix-K6; Fri, 03 Feb 2023 10:22:43 -0500 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 1pNxth-0007Hp-GM for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:41 -0500 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 1pNxtf-00059y-7b for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:41 -0500 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-81-2QKrUIaoPMmqxi8jviExtQ-1; Fri, 03 Feb 2023 10:22:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 044A3811E6E; Fri, 3 Feb 2023 15:22:37 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A423404CD80; Fri, 3 Feb 2023 15:22:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437758; 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=yFVAsROfmCE5NJOxdUrmfKkNG/j1E040c2my0mBQjio=; b=bk9mBNI/q6SeTYxS6yC8fryAxkQlntdzuR+uSh/Kfz1Whtd4XK13ZOjYuKmqpG3/biu+H9 WdLeWZEaGHqVNpqJBOKIqu0X4lHvzKADKHg+ckvy/Yl/SsOSdSbwl8f6gGl2xK5UtLkVzo GZ2tXpzrm0yu6xNjyJr5aXv6xjQsjDU= X-MC-Unique: 2QKrUIaoPMmqxi8jviExtQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 03/23] block: Mark bdrv_co_truncate() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:42 +0100 Message-Id: <20230203152202.49054-4-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437802406100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_truncate() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 6 +++--- include/block/block_int-common.h | 7 ++++--- block/block-backend.c | 1 + block/crypto.c | 2 +- block/io.c | 1 + block/parallels.c | 14 ++++++++------ block/preallocate.c | 2 +- block/qcow.c | 17 ++++++++++++----- block/qcow2.c | 14 ++++++++------ block/raw-format.c | 6 +++--- block/vmdk.c | 2 ++ 11 files changed, 44 insertions(+), 28 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index f9fa88204d..9a09ec2bdd 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -72,9 +72,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, in= t64_t offset, int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, BdrvRequestFlags fla= gs); =20 -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, - PreallocMode prealloc, BdrvRequestFlags = flags, - Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **er= rp); =20 int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index ba2e0fce25..eaf62beaff 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -677,9 +677,10 @@ struct BlockDriver { * If @exact is true and this function fails but would succeed * with @exact =3D false, it should return -ENOTSUP. */ - int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t off= set, - bool exact, PreallocMode prealloc, - BdrvRequestFlags flags, Error **e= rrp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_truncate)( + BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); + int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( BlockDriverState *bs); diff --git a/block/block-backend.c b/block/block-backend.c index ef512f7c48..f25f3ba5e7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2372,6 +2372,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, i= nt64_t offset, bool exact, Error **errp) { IO_OR_GS_CODE(); + GRAPH_RDLOCK_GUARD(); if (!blk_is_available(blk)) { error_setg(errp, "No medium inserted"); return -ENOMEDIUM; diff --git a/block/crypto.c b/block/crypto.c index 9c477397c7..8c0c245d11 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -360,7 +360,7 @@ static int block_crypto_co_create_generic(BlockDriverSt= ate *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) diff --git a/block/io.c b/block/io.c index 2dc0c13e41..84ec46546f 100644 --- a/block/io.c +++ b/block/io.c @@ -3377,6 +3377,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, int64_t old_size, new_bytes; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { diff --git a/block/parallels.c b/block/parallels.c index d4378e09de..36c9de8a8a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -165,9 +165,9 @@ static int64_t block_status(BDRVParallelsState *s, int6= 4_t sector_num, return start_off; } =20 -static coroutine_fn int64_t allocate_clusters(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum) +static int64_t coroutine_fn GRAPH_RDLOCK +allocate_clusters(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum) { int ret =3D 0; BDRVParallelsState *s =3D bs->opaque; @@ -329,6 +329,8 @@ static coroutine_fn int parallels_co_writev(BlockDriver= State *bs, QEMUIOVector hd_qiov; int ret =3D 0; =20 + assume_graph_lock(); /* FIXME */ + qemu_iovec_init(&hd_qiov, qiov->niov); =20 while (nb_sectors > 0) { @@ -414,9 +416,9 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, } =20 =20 -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s =3D bs->opaque; int64_t size, prev_off, high_off; diff --git a/block/preallocate.c b/block/preallocate.c index c0dcf8c346..42da9cb9f1 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -370,7 +370,7 @@ static coroutine_fn int preallocate_co_pwritev_part(Blo= ckDriverState *bs, flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK preallocate_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) diff --git a/block/qcow.c b/block/qcow.c index 20c53b447b..5eb1ab5e59 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -350,11 +350,10 @@ static int qcow_reopen_prepare(BDRVReopenState *state, * return 0 if not allocated, 1 if *result is assigned, and negative * errno on failure. */ -static int coroutine_fn get_cluster_offset(BlockDriverState *bs, - uint64_t offset, int allocate, - int compressed_size, - int n_start, int n_end, - uint64_t *result) +static int coroutine_fn GRAPH_RDLOCK +get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate, + int compressed_size, int n_start, int n_end, + uint64_t *result) { BDRVQcowState *s =3D bs->opaque; int min_index, i, j, l1_index, l2_index, ret; @@ -536,6 +535,8 @@ static int coroutine_fn qcow_co_block_status(BlockDrive= rState *bs, int64_t n; uint64_t cluster_offset; =20 + assume_graph_lock(); /* FIXME */ + qemu_co_mutex_lock(&s->lock); ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); qemu_co_mutex_unlock(&s->lock); @@ -630,6 +631,8 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 + assume_graph_lock(); /* FIXME */ + if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -726,6 +729,8 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverStat= e *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 + assume_graph_lock(); /* FIXME */ + s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 /* We must always copy the iov when encrypting, so we @@ -1056,6 +1061,8 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int6= 4_t offset, int64_t bytes, uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 + assume_graph_lock(); /* FIXME */ + buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes !=3D s->cluster_size) { if (bytes > s->cluster_size || diff --git a/block/qcow2.c b/block/qcow2.c index ee0e5b45cc..e06ea7b5ff 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3183,9 +3183,9 @@ static int qcow2_set_up_encryption(BlockDriverState *= bs, * * Returns: 0 on success, -errno on failure. */ -static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offs= et, - uint64_t new_length, PreallocMode m= ode, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co(BlockDriverState *bs, uint64_t offset, uint64_t new_length, + PreallocMode mode, Error **errp) { BDRVQcow2State *s =3D bs->opaque; uint64_t bytes; @@ -4209,9 +4209,9 @@ fail: return ret; } =20 -static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t of= fset, - bool exact, PreallocMode preallo= c, - BdrvRequestFlags flags, Error **= errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp) { BDRVQcow2State *s =3D bs->opaque; uint64_t old_length; @@ -4672,6 +4672,8 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, AioTaskPool *aio =3D NULL; int ret =3D 0; =20 + assume_graph_lock(); /* FIXME */ + if (has_data_file(bs)) { return -ENOTSUP; } diff --git a/block/raw-format.c b/block/raw-format.c index 0dc469b629..f39e1f502b 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -384,9 +384,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Er= ror **errp) } } =20 -static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, - bool exact, PreallocMode prealloc, - BdrvRequestFlags flags, Error **er= rp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **err= p) { BDRVRawState *s =3D bs->opaque; =20 diff --git a/block/vmdk.c b/block/vmdk.c index 171c9272ca..3fcb75319f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2130,6 +2130,8 @@ static int coroutine_fn vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { + assume_graph_lock(); /* FIXME */ + if (bytes =3D=3D 0) { /* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */ --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437909; cv=none; d=zohomail.com; s=zohoarc; b=jsC/HAKdF0KLydNp7okI31icTCpkwdEIAILRE5bEciAnlQG5xPUOikZhqgGB+BdV6GF4ZpWNpEwuq9TCHFh9LMTTEpUBnlgOSVWIRVCrEF/jGd42ncW4HuMWrjr+wr9JIYn9QFhIwg1YtkkV+qXvP9YVjY0uBADgn31lHBfNB5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437909; 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=5dstL4bJtHekAZMU1rni1Wp918hdSBzq1us1VEn7k2g=; b=fQMEqFZqLiI8FBXY8mNnpgYYtXFkpDwKseFEZs9ekH996paZxYNCXrZfESsyOa4CG4VBADbqbkruAxKBTr9xMdLP4TfMmwfN1/13pe9iYz37amZUonkfVTHwRcReQdHYPWar+3SNf3NdvyOHVW6bOs1S/90+rhuaOn3OUkRVKvo= 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+importer2=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 1675437909651916.6674595398503; Fri, 3 Feb 2023 07:25:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtl-0007K0-4O; Fri, 03 Feb 2023 10:22:45 -0500 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 1pNxtj-0007Ib-19 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:43 -0500 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 1pNxtg-0005EX-OI for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:42 -0500 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-515-M8jldBywMUK4zUghd-4jig-1; Fri, 03 Feb 2023 10:22:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59A9485D062; Fri, 3 Feb 2023 15:22:38 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EACF40C1073; Fri, 3 Feb 2023 15:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437760; 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=5dstL4bJtHekAZMU1rni1Wp918hdSBzq1us1VEn7k2g=; b=Cyh+CwbX10Yd14QYgpi2ZmDYaqI9rlqINf6E0WfJT4RXDv78SnzRZamqUO3T3VTAHOcGzK UH0ZKhB7RdwoyUXHqGD1G9hvrc9fzYzCH+XQJxhDOFVBqzbEkQwxYi7htaXce2kYW8zit9 H+B2Q39jXkkjKXfQT2nGeWxa/Rl29I4= X-MC-Unique: M8jldBywMUK4zUghd-4jig-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 04/23] block: Mark bdrv_co_block_status() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:43 +0100 Message-Id: <20230203152202.49054-5-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437911159100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_block_status() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/coroutines.h | 2 +- include/block/block-copy.h | 6 +++--- include/block/block-io.h | 22 +++++++++++----------- include/block/block_int-common.h | 3 ++- block/backup.c | 3 +++ block/block-backend.c | 2 ++ block/block-copy.c | 19 +++++++++++-------- block/io.c | 13 ++++++++----- block/mirror.c | 14 +++++++++----- block/qcow.c | 11 ++++------- block/quorum.c | 9 ++++----- block/stream.c | 32 ++++++++++++++++++-------------- qemu-img.c | 4 +++- tests/unit/test-block-iothread.c | 3 ++- 14 files changed, 81 insertions(+), 62 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 2a1e0b3c9d..dd9f3d449b 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -43,7 +43,7 @@ bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res,= BdrvCheckMode fix); int coroutine_fn GRAPH_RDLOCK bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); =20 -int coroutine_fn +int coroutine_fn GRAPH_RDLOCK bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool include_base, diff --git a/include/block/block-copy.h b/include/block/block-copy.h index d0f8386554..0700953ab8 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -36,9 +36,9 @@ void block_copy_set_progress_meter(BlockCopyState *s, Pro= gressMeter *pm); void block_copy_state_free(BlockCopyState *s); =20 void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); -int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, - int64_t offset, - int64_t *count); + +int64_t coroutine_fn GRAPH_RDLOCK +block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *c= ount); =20 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, diff --git a/include/block/block-io.h b/include/block/block-io.h index 9a09ec2bdd..6303501b0f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -109,24 +109,24 @@ int bdrv_block_status(BlockDriverState *bs, int64_t o= ffset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status_above(BlockDriverState *bs, BlockDriverState *base, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file); int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, - int64_t bytes, int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, + int64_t *pnum); int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); =20 -int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, - BlockDriverState *base, - bool include_base, int64_t off= set, - int64_t bytes, int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + bool include_base, int64_t offset, int64_t byte= s, + int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t byt= es, int64_t *pnum); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index eaf62beaff..5f0104a1af 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -606,7 +606,8 @@ struct BlockDriver { * *pnum value for the block-status cache on protocol nodes, prior * to clamping *pnum for return to its caller. */ - int coroutine_fn (*bdrv_co_block_status)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_block_status)( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 diff --git a/block/backup.c b/block/backup.c index 824d39acaa..46fca2459d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -270,7 +270,10 @@ static int coroutine_fn backup_run(Job *job, Error **e= rrp) return -ECANCELED; } =20 + /* rdlock protects the subsequent call to bdrv_is_allocated() = */ + bdrv_graph_co_rdlock(); ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); + bdrv_graph_co_rdunlock(); if (ret < 0) { return ret; } diff --git a/block/block-backend.c b/block/block-backend.c index f25f3ba5e7..f5d9e3e269 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1431,6 +1431,7 @@ int coroutine_fn blk_co_block_status_above(BlockBacke= nd *blk, BlockDriverState **file) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); return bdrv_co_block_status_above(blk_bs(blk), base, offset, bytes, pn= um, map, file); } @@ -1441,6 +1442,7 @@ int coroutine_fn blk_co_is_allocated_above(BlockBacke= nd *blk, int64_t bytes, int64_t *pnum) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); return bdrv_co_is_allocated_above(blk_bs(blk), base, include_base, off= set, bytes, pnum); } diff --git a/block/block-copy.c b/block/block-copy.c index 30a4da0f2e..d299fac7cc 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -581,9 +581,9 @@ static coroutine_fn int block_copy_task_entry(AioTask *= task) return ret; } =20 -static coroutine_fn int block_copy_block_status(BlockCopyState *s, - int64_t offset, - int64_t bytes, int64_t *pn= um) +static coroutine_fn GRAPH_RDLOCK +int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t byt= es, + int64_t *pnum) { int64_t num; BlockDriverState *base; @@ -618,9 +618,9 @@ static coroutine_fn int block_copy_block_status(BlockCo= pyState *s, * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. */ -static int coroutine_fn block_copy_is_cluster_allocated(BlockCopyState *s, - int64_t offset, - int64_t *pnum) +static int coroutine_fn GRAPH_RDLOCK +block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, + int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; int64_t count, total_count =3D 0; @@ -630,6 +630,7 @@ static int coroutine_fn block_copy_is_cluster_allocated= (BlockCopyState *s, assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); =20 while (true) { + /* protected in backup_run() */ ret =3D bdrv_co_is_allocated(bs, offset, bytes, &count); if (ret < 0) { return ret; @@ -704,7 +705,7 @@ int64_t coroutine_fn block_copy_reset_unallocated(Block= CopyState *s, * Returns 1 if dirty clusters found and successfully copied, 0 if no dirty * clusters found and -errno on failure. */ -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK block_copy_dirty_clusters(BlockCopyCallState *call_state) { BlockCopyState *s =3D call_state->s; @@ -827,7 +828,8 @@ void block_copy_kick(BlockCopyCallState *call_state) * it means that some I/O operation failed in context of _this_ block_copy= call, * not some parallel operation. */ -static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) +static int coroutine_fn GRAPH_RDLOCK +block_copy_common(BlockCopyCallState *call_state) { int ret; BlockCopyState *s =3D call_state->s; @@ -892,6 +894,7 @@ static int coroutine_fn block_copy_common(BlockCopyCall= State *call_state) =20 static void coroutine_fn block_copy_async_co_entry(void *opaque) { + GRAPH_RDLOCK_GUARD(); block_copy_common(opaque); } =20 diff --git a/block/io.c b/block/io.c index 84ec46546f..68eaa985f5 100644 --- a/block/io.c +++ b/block/io.c @@ -2221,11 +2221,10 @@ int bdrv_flush_all(void) * BDRV_BLOCK_OFFSET_VALID bit is set, 'map' and 'file' (if non-NULL) are * set to the host mapping and BDS corresponding to the guest offset. */ -static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, BlockDriverState **file) { int64_t total_size; int64_t n; /* bytes */ @@ -2237,6 +2236,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, bool has_filtered_child; =20 assert(pnum); + assert_bdrv_graph_readable(); *pnum =3D 0; total_size =3D bdrv_getlength(bs); if (total_size < 0) { @@ -2467,6 +2467,7 @@ bdrv_co_common_block_status_above(BlockDriverState *b= s, IO_CODE(); =20 assert(!include_base || base); /* Can't include NULL base */ + assert_bdrv_graph_readable(); =20 if (!depth) { depth =3D &dummy; @@ -2592,6 +2593,8 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverStat= e *bs, int64_t offset, int64_t pnum =3D bytes; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + if (!bytes) { return 1; } diff --git a/block/mirror.c b/block/mirror.c index fbbb4f619e..94c523af28 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -558,9 +558,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) MirrorMethod mirror_method =3D MIRROR_METHOD_COPY; =20 assert(!(offset % s->granularity)); - ret =3D bdrv_block_status_above(source, NULL, offset, - nb_chunks * s->granularity, - &io_bytes, NULL, NULL); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_block_status_above(source, NULL, offset, + nb_chunks * s->granularity, + &io_bytes, NULL, NULL); + } if (ret < 0) { io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { @@ -863,8 +865,10 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJ= ob *s) return 0; } =20 - ret =3D bdrv_is_allocated_above(bs, s->base_overlay, true, offset,= bytes, - &count); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_is_allocated_above(bs, s->base_overlay, true, off= set, + bytes, &count); + } if (ret < 0) { return ret; } diff --git a/block/qcow.c b/block/qcow.c index 5eb1ab5e59..2d19a78818 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -524,19 +524,16 @@ get_cluster_offset(BlockDriverState *bs, uint64_t off= set, int allocate, return 1; } =20 -static int coroutine_fn qcow_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { BDRVQcowState *s =3D bs->opaque; int index_in_cluster, ret; int64_t n; uint64_t cluster_offset; =20 - assume_graph_lock(); /* FIXME */ - qemu_co_mutex_lock(&s->lock); ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); qemu_co_mutex_unlock(&s->lock); diff --git a/block/quorum.c b/block/quorum.c index d1dcf2eaba..f3fe067541 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1217,11 +1217,10 @@ static void quorum_child_perm(BlockDriverState *bs,= BdrvChild *c, * return BDRV_BLOCK_ZERO if *all* children agree that a certain * region contains zeroes, and BDRV_BLOCK_DATA otherwise. */ -static int coroutine_fn quorum_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t cou= nt, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t count, + int64_t *pnum, int64_t *map, BlockDriverState **fil= e) { BDRVQuorumState *s =3D bs->opaque; int i, ret; diff --git a/block/stream.c b/block/stream.c index 8744ad103f..22368ce186 100644 --- a/block/stream.c +++ b/block/stream.c @@ -161,21 +161,25 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_CHUNK, &n); - if (ret =3D=3D 1) { - /* Allocated in the top, no need to copy. */ - } else if (ret >=3D 0) { - /* Copy if allocated in the intermediate images. Limit to the - * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ - ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), - s->base_overlay, true, - offset, n, &n); - /* Finish early if end of backing file has been reached */ - if (ret =3D=3D 0 && n =3D=3D 0) { - n =3D len - offset; + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_CHUNK,= &n); + if (ret =3D=3D 1) { + /* Allocated in the top, no need to copy. */ + } else if (ret >=3D 0) { + /* + * Copy if allocated in the intermediate images. Limit to= the + * known-unallocated area [offset, offset+n*BDRV_SECTOR_SI= ZE). + */ + ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), + s->base_overlay, true, + offset, n, &n); + /* Finish early if end of backing file has been reached */ + if (ret =3D=3D 0 && n =3D=3D 0) { + n =3D len - offset; + } + + copy =3D (ret > 0); } - - copy =3D (ret > 0); } trace_stream_one_iteration(s, offset, n, ret); if (copy) { diff --git a/qemu-img.c b/qemu-img.c index 7c05931866..cd0178b51b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1991,7 +1991,9 @@ static void coroutine_fn convert_co_do_copy(void *opa= que) qemu_co_mutex_unlock(&s->lock); break; } - n =3D convert_iteration_sectors(s, s->sector_num); + WITH_GRAPH_RDLOCK_GUARD() { + n =3D convert_iteration_sectors(s, s->sector_num); + } if (n < 0) { qemu_co_mutex_unlock(&s->lock); s->ret =3D n; diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 6dfac6468a..3a5e1eb2c4 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -312,7 +312,8 @@ static void test_sync_op_blk_truncate(BlockBackend *blk) g_assert_cmpint(ret, =3D=3D, -EINVAL); } =20 -static void test_sync_op_block_status(BdrvChild *c) +/* Disable TSA to make bdrv_test.bdrv_co_block_status writable */ +static void TSA_NO_TSA test_sync_op_block_status(BdrvChild *c) { int ret; int64_t n; --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438060; cv=none; d=zohomail.com; s=zohoarc; b=camBuVxmOeeuNDFf611MXLE20Kf6kw629Vj0+54aAWJnmfw+WCLZR4c2wXgNiGCOy4qeGovzsYrP4OnaEgI54ov97oYiORNkOm131l2X3uny93bCn2OYxNTLsz/zTwMoTem+suVkHv95/OacgKsEm67kEpOvQsnUsE4o7+n63zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438060; 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=6AGJvzJuHKjnpX3gwR+d/ibfUFVOLm8YnZQqQotE9mk=; b=B9CI2rXcjcaztIXZLn3hcmAGbRCDuUmKymLZklxKtVGVUetz3G1AMRQIyn93AKUHhKv4xAhe8LeUUpw1NLG24psWRyScpf29RHZe511/CWfi10hbrZn7cqAhX/RHeZy0yQMU3RC1PBXRsgt1Sfg1j8UUWbm8NuDcBh2Z9Nx9AnM= 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+importer2=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 1675438060152817.0653527692871; Fri, 3 Feb 2023 07:27:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtn-0007LM-Sm; Fri, 03 Feb 2023 10:22:47 -0500 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 1pNxtl-0007K7-Oq for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:45 -0500 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 1pNxtk-0005HV-5P for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:45 -0500 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-500-7qaoG_ZRNembhY-R-EhmUA-1; Fri, 03 Feb 2023 10:22:39 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C26985A5B1; Fri, 3 Feb 2023 15:22:39 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 924E9410B1AD; Fri, 3 Feb 2023 15:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437763; 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=6AGJvzJuHKjnpX3gwR+d/ibfUFVOLm8YnZQqQotE9mk=; b=JYpeNIzkWKcBox+vHTOCpN7o1y95esqCBb4eLLTiTdvHwIAkGKo0PDuCqywcH3SlfIIZRI SCO8+QDjwDilFyx0HwACP0pyMwMkeN5oefH9RFwhzBl1/JAjaYA3TVBrtSTYf4Ba8P+viB Edb/e16Spz98JCZg/xr1CMT4O8RZjF4= X-MC-Unique: 7qaoG_ZRNembhY-R-EhmUA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 05/23] block: Mark bdrv_co_ioctl() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:44 +0100 Message-Id: <20230203152202.49054-6-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438060555100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_ioctl() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 3 ++- include/block/block_int-common.h | 9 +++++---- block/block-backend.c | 1 + block/io.c | 1 + block/raw-format.c | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 6303501b0f..3f42c76f23 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -97,7 +97,8 @@ void bdrv_aio_cancel(BlockAIOCB *acb); void bdrv_aio_cancel_async(BlockAIOCB *acb); =20 /* sg packet commands */ -int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 5f0104a1af..64700daf38 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -714,11 +714,12 @@ struct BlockDriver { void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); =20 /* to control generic scsi devices */ - BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, - unsigned long int req, void *buf, + BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)( + BlockDriverState *bs, unsigned long int req, void *buf, BlockCompletionFunc *cb, void *opaque); - int coroutine_fn (*bdrv_co_ioctl)(BlockDriverState *bs, - unsigned long int req, void *buf); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_ioctl)( + BlockDriverState *bs, unsigned long int req, void *buf); =20 /* * Returns 0 for completed check, -errno for internal errors. diff --git a/block/block-backend.c b/block/block-backend.c index f5d9e3e269..5c731a1c6c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1672,6 +1672,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int = req, void *buf) IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 if (!blk_is_available(blk)) { return -ENOMEDIUM; diff --git a/block/io.c b/block/io.c index 68eaa985f5..27a2824c87 100644 --- a/block/io.c +++ b/block/io.c @@ -3080,6 +3080,7 @@ int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, = int req, void *buf) }; BlockAIOCB *acb; IO_CODE(); + assert_bdrv_graph_readable(); =20 bdrv_inc_in_flight(bs); if (!drv || (!drv->bdrv_aio_ioctl && !drv->bdrv_co_ioctl)) { diff --git a/block/raw-format.c b/block/raw-format.c index f39e1f502b..202acb1232 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -415,8 +415,8 @@ static void coroutine_fn raw_co_lock_medium(BlockDriver= State *bs, bool locked) bdrv_co_lock_medium(bs->file->bs, locked); } =20 -static int coroutine_fn raw_co_ioctl(BlockDriverState *bs, - unsigned long int req, void *buf) +static int coroutine_fn GRAPH_RDLOCK +raw_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s =3D bs->opaque; if (s->offset || s->has_size) { --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437868; cv=none; d=zohomail.com; s=zohoarc; b=IFyltZr57EjZKho6KpLNiayI8qoJSs/3L8RUg7rzFgtE9B6U/ZhadWWfcO0sdD3aUQOBIgPS6VYM0kGzqg1v4yGNywczIImDy7Z6ookL3eAOm4RiZb9jF7RMB3lgypUxhiC749u/AJPr1J6PdEboDTJbxFrJNE+iYpiKVq7GBa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437868; 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=NdB4e7zSJFK3b1OkS0rb2GIdRY93MnrNo12MWToZGOQ=; b=m0KQj+t9yRvaBoZZmxdqGHZTpDKDrnoOifA9R3ZGV1wtOUTdgbTyOtIhO23cdn0AZTRvbWwDvC37wPykNtdjNzUgE4UxgPewoF70RcwG597Bf08BXodeoVKW8KDWRcIpyNDkdur2nW3nifUA6/V+ST00dcKQKc20LZwmrSQ6CQY= 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+importer2=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 1675437868469811.3444061843903; Fri, 3 Feb 2023 07:24:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtm-0007Kx-Nq; Fri, 03 Feb 2023 10:22:46 -0500 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 1pNxtk-0007J9-BT for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:44 -0500 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 1pNxti-0005H9-Pq for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:44 -0500 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-472-fr9TUFIjPuygJnCUOk1qDw-1; Fri, 03 Feb 2023 10:22:41 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD1D11C051AC; Fri, 3 Feb 2023 15:22:40 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id C437940168B7; Fri, 3 Feb 2023 15:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437762; 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=NdB4e7zSJFK3b1OkS0rb2GIdRY93MnrNo12MWToZGOQ=; b=TRKOJpzGrMnpYeshUeF04UW+eVLNZbb6YYWUQqWYistxnHisulOIGTOtDSBRIaaFXYOgY9 KFlaH4so+ImQTYlCHYL4a5aCNtasQu40nVvalf/i2CAUXJKZQY76935fVHrGO5z/dYlqqY d75dFMEJ00X2F7NR7fjK6AqCowcHP9o= X-MC-Unique: fr9TUFIjPuygJnCUOk1qDw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 06/23] block/qed: add missing graph rdlock in qed_need_check_timer_entry Date: Fri, 3 Feb 2023 16:21:45 +0100 Message-Id: <20230203152202.49054-7-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437868917100005 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This function is called in two different places: - timer callback, which does not take the graph rdlock. - bdrv_qed_drain_begin(), which is .bdrv_drain_begin() callback documented as function that does not take the lock. Since it calls recursive functions that traverse the graph, we need to protect them with the graph rdlock. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qed.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/qed.c b/block/qed.c index 175a46c67b..7690d0215d 100644 --- a/block/qed.c +++ b/block/qed.c @@ -282,11 +282,12 @@ static void coroutine_fn qed_unplug_allocating_write_= reqs(BDRVQEDState *s) qemu_co_mutex_unlock(&s->table_lock); } =20 -static void coroutine_fn qed_need_check_timer(BDRVQEDState *s) +static void coroutine_fn GRAPH_RDLOCK qed_need_check_timer(BDRVQEDState *s) { int ret; =20 trace_qed_need_check_timer_cb(s); + assert_bdrv_graph_readable(); =20 if (!qed_plug_allocating_write_reqs(s)) { return; @@ -312,6 +313,7 @@ static void coroutine_fn qed_need_check_timer(BDRVQEDSt= ate *s) static void coroutine_fn qed_need_check_timer_entry(void *opaque) { BDRVQEDState *s =3D opaque; + GRAPH_RDLOCK_GUARD(); =20 qed_need_check_timer(opaque); bdrv_dec_in_flight(s->bs); --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438032; cv=none; d=zohomail.com; s=zohoarc; b=PvOrGS4C98lVTlgh63pbza4mx2VKVPLhaO+zm7/A4bN9zVoSeoti6LspRc3T58tJHp2v5Ts2mTyx1nQbTOv+RCowou4PxPoTPv66qPn3VZnvvIbDU5OyEywzO/GS2FGNwmYmQuvuc96sEwydoazuCU73NyidXVqGn3m7f1lbvC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438032; 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=5cLT8ImVdYdGwljLjTFm3mFG30vnJU6QS1/c6zNU0Is=; b=VXcCLciNclPJ/+xa2Sg+0w2mZ5hGZHiHIc4uzZBTS7+Be3JT37Gg1vtYPOQedoLFlU5iI5aerUPw+AqUhEakgWwCsDR5L3sOu/UPF4xLbgQQYdFSAru20SAglOzWfSFHXDfRO6ywByp2r5C80SnpSt+ob7KmHOO1ztaiIlEcuUo= 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+importer2=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 1675438032165728.6322806901969; Fri, 3 Feb 2023 07:27:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtx-0007Qk-1Q; Fri, 03 Feb 2023 10:22:57 -0500 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 1pNxtu-0007Ov-Oi for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:54 -0500 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 1pNxtr-0005Je-N1 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:54 -0500 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-643-UZhXHf1dMs-zxx_OgbGBfg-1; Fri, 03 Feb 2023 10:22:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED64B800B24; Fri, 3 Feb 2023 15:22:41 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000E9404CD81; Fri, 3 Feb 2023 15:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437771; 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=5cLT8ImVdYdGwljLjTFm3mFG30vnJU6QS1/c6zNU0Is=; b=LfprYJtT6H5apD/n/mfP/Ag3f8X8XT1Zt0b/goR0rmIpWsMIndzIW+Kz7vMn2NDoqMktnl HsMCB4vBSQenBbatQni+apuuZCkmOS3qqjm/Tc6eJq0AHlzFoLguvRGDtfpBchse3txKB3 7VA9K9IPkh8lIThbFbzJbBpnDbmpfJA= X-MC-Unique: UZhXHf1dMs-zxx_OgbGBfg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 07/23] block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:46 +0100 Message-Id: <20230203152202.49054-8-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438034450100005 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_flush() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qcow2.h | 5 +++- block/qed.h | 29 +++++++++++++-------- include/block/block-io.h | 2 +- include/block/block_int-common.h | 12 +++++---- block/blkdebug.c | 2 +- block/blklogwrites.c | 21 ++++++++++----- block/blkreplay.c | 2 +- block/blkverify.c | 2 +- block/block-backend.c | 3 ++- block/copy-before-write.c | 2 +- block/file-posix.c | 4 +-- block/io.c | 7 +++++ block/mirror.c | 2 +- block/preallocate.c | 2 +- block/qed-check.c | 3 ++- block/qed-table.c | 6 ++--- block/qed.c | 44 +++++++++++++++++++------------- block/quorum.c | 2 +- block/throttle.c | 2 +- block/vmdk.c | 6 +++-- 20 files changed, 98 insertions(+), 60 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 2285f18a73..7a02699bfa 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -900,7 +900,10 @@ int coroutine_fn qcow2_detect_metadata_preallocation(B= lockDriverState *bs); /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); -int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_= size); + +int coroutine_fn GRAPH_RDLOCK +qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); + int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); diff --git a/block/qed.h b/block/qed.h index 3d12bf78d4..e48f7c2480 100644 --- a/block/qed.h +++ b/block/qed.h @@ -201,20 +201,25 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache= , CachedL2Table *l2_table); * Table I/O functions */ int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); -int coroutine_fn qed_write_l1_table(BDRVQEDState *s, unsigned int index, - unsigned int n); -int coroutine_fn qed_write_l1_table_sync(BDRVQEDState *s, unsigned int ind= ex, - unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int = n); + int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *reque= st, uint64_t offset); int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); -int coroutine_fn qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, - unsigned int index, unsigned int n, - bool flush); -int coroutine_fn qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *requ= est, - unsigned int index, unsigned int = n, - bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int inde= x, + unsigned int n, bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, + unsigned int index, unsigned int n, bool flush); =20 /** * Cluster functions @@ -226,7 +231,9 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, /** * Consistency check */ -int coroutine_fn qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool = fix); +int coroutine_fn GRAPH_RDLOCK +qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); + =20 QEDTable *qed_alloc_table(BDRVQEDState *s); =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index 3f42c76f23..7e96506138 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -101,7 +101,7 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Ensure contents are flushed to disk. */ -int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); =20 int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 64700daf38..51eaabd9d1 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -477,8 +477,8 @@ struct BlockDriver { BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque); + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( + BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); @@ -646,7 +646,7 @@ struct BlockDriver { * layers, if needed. This function is needed for deterministic * synchronization of the flush finishing callback. */ - int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *b= s); =20 /* Delete a created file. */ int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, @@ -656,14 +656,16 @@ struct BlockDriver { * Flushes all data that was already written to the OS all the way dow= n to * the disk (for example file-posix.c calls fsync()). */ - int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_disk)( + BlockDriverState *bs); =20 /* * Flushes all internal caches to the OS. The data may still sit in a * writeback cache of the host OS, but it will survive a crash of the = qemu * process. */ - int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_os)( + BlockDriverState *bs); =20 /* * Truncate @bs to @offset bytes using the given @prealloc mode diff --git a/block/blkdebug.c b/block/blkdebug.c index 28772be73f..5ba3766a2c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -668,7 +668,7 @@ blkdebug_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn blkdebug_co_flush(BlockDriverState *bs) +static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(BlockDriverState *b= s) { int err =3D rule_check(bs, 0, 0, BLKDEBUG_IO_TYPE_FLUSH); =20 diff --git a/block/blklogwrites.c b/block/blklogwrites.c index b00b8a6dd0..5ec1d23f29 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -307,7 +307,7 @@ typedef struct BlkLogWritesFileReq { uint64_t bytes; int file_flags; QEMUIOVector *qiov; - int (*func)(struct BlkLogWritesFileReq *r); + int GRAPH_RDLOCK_PTR (*func)(struct BlkLogWritesFileReq *r); int file_ret; } BlkLogWritesFileReq; =20 @@ -319,7 +319,8 @@ typedef struct { int log_ret; } BlkLogWritesLogReq; =20 -static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) { BDRVBlkLogWritesState *s =3D lr->bs->opaque; uint64_t cur_log_offset =3D s->cur_log_sector << s->sectorbits; @@ -368,15 +369,16 @@ static void coroutine_fn blk_log_writes_co_do_log(Blk= LogWritesLogReq *lr) } } =20 -static void coroutine_fn blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) { fr->file_ret =3D fr->func(fr); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t byte= s, QEMUIOVector *qiov, int flags, - int (*file_func)(BlkLogWritesFileReq *r), + int /*GRAPH_RDLOCK*/ (*file_func)(BlkLogWritesFileRe= q *r), uint64_t entry_flags, bool is_zero_write) { QEMUIOVector log_qiov; @@ -442,7 +444,8 @@ blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFil= eReq *fr) fr->file_flags); } =20 -static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileRe= q *fr) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr) { return bdrv_co_flush(fr->bs->file->bs); } @@ -457,6 +460,7 @@ static int coroutine_fn blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t by= tes, QEMUIOVector *qiov, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev, 0, fal= se); } @@ -465,12 +469,14 @@ static int coroutine_fn blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, flags, blk_log_writes_co_do_file_pwrite_zeroes, = 0, true); } =20 -static int coroutine_fn blk_log_writes_co_flush_to_disk(BlockDriverState *= bs) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_flush_to_disk(BlockDriverState *bs) { return blk_log_writes_co_log(bs, 0, 0, NULL, 0, blk_log_writes_co_do_file_flush, @@ -480,6 +486,7 @@ static int coroutine_fn blk_log_writes_co_flush_to_disk= (BlockDriverState *bs) static int coroutine_fn blk_log_writes_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t b= ytes) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, 0, blk_log_writes_co_do_file_pdiscard, LOG_DISCARD_FLAG, false); diff --git a/block/blkreplay.c b/block/blkreplay.c index 16543f585a..ce13fa5ba5 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriv= erState *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkreplay_co_flush(BlockDriverState *= bs) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_flush(bs->file->bs); diff --git a/block/blkverify.c b/block/blkverify.c index edf1a550f2..8c11c2eae4 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -256,7 +256,7 @@ blkverify_co_pwritev(BlockDriverState *bs, int64_t offs= et, int64_t bytes, return blkverify_co_prwv(bs, &r, offset, bytes, qiov, qiov, flags, tru= e); } =20 -static int coroutine_fn blkverify_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkverify_co_flush(BlockDriverState *= bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 diff --git a/block/block-backend.c b/block/block-backend.c index 5c731a1c6c..3e58b95b8a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1762,8 +1762,9 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, i= nt64_t offset, /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_flush(BlockBackend *blk) { - blk_wait_while_drained(blk); IO_CODE(); + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 if (!blk_is_available(blk)) { return -ENOMEDIUM; diff --git a/block/copy-before-write.c b/block/copy-before-write.c index c9fb809ba0..4ba72c6309 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -185,7 +185,7 @@ static coroutine_fn int cbw_co_pwritev(BlockDriverState= *bs, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn cbw_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK cbw_co_flush(BlockDriverState *bs) { if (!bs->file) { return 0; diff --git a/block/file-posix.c b/block/file-posix.c index d3073a7caa..7481ccddb6 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2920,8 +2920,8 @@ static void coroutine_fn check_cache_dropped(BlockDri= verState *bs, Error **errp) } #endif /* __linux__ */ =20 -static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +raw_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; int ret; diff --git a/block/io.c b/block/io.c index 27a2824c87..e6b4713117 100644 --- a/block/io.c +++ b/block/io.c @@ -933,6 +933,8 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, = int64_t offset, int ret; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + ret =3D bdrv_co_pwrite(child, offset, bytes, buf, flags); if (ret < 0) { return ret; @@ -1041,6 +1043,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriv= erState *bs, QEMUIOVector local_qiov; int ret; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1680,6 +1684,8 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, int head =3D 0; int tail =3D 0; =20 + assume_graph_lock(); /* FIXME */ + int64_t max_write_zeroes =3D MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT64_MAX); int alignment =3D MAX(bs->bl.pwrite_zeroes_alignment, @@ -2836,6 +2842,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) int ret =3D 0; IO_CODE(); =20 + assert_bdrv_graph_readable(); bdrv_inc_in_flight(bs); =20 if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs) || diff --git a/block/mirror.c b/block/mirror.c index 94c523af28..d1d79f2319 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1535,7 +1535,7 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, return ret; } =20 -static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverStat= e *bs) { if (bs->backing =3D=3D NULL) { /* we can be here after failed bdrv_append in mirror_start_job */ diff --git a/block/preallocate.c b/block/preallocate.c index 42da9cb9f1..483b596280 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -437,7 +437,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t o= ffset, return 0; } =20 -static int coroutine_fn preallocate_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState= *bs) { return bdrv_co_flush(bs->file->bs); } diff --git a/block/qed-check.c b/block/qed-check.c index a6612be00f..8fd94f405e 100644 --- a/block/qed-check.c +++ b/block/qed-check.c @@ -107,7 +107,8 @@ static unsigned int qed_check_l2_table(QEDCheck *check,= QEDTable *table) /** * Descend tables and check each cluster is referenced once only */ -static int coroutine_fn qed_check_l1_table(QEDCheck *check, QEDTable *tabl= e) +static int coroutine_fn GRAPH_RDLOCK +qed_check_l1_table(QEDCheck *check, QEDTable *table) { BDRVQEDState *s =3D check->s; unsigned int i, num_invalid_l1 =3D 0; diff --git a/block/qed-table.c b/block/qed-table.c index e41c87a157..e9c72814c8 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -63,9 +63,9 @@ out: * * Called with table_lock held. */ -static int coroutine_fn qed_write_table(BDRVQEDState *s, uint64_t offset, - QEDTable *table, unsigned int inde= x, - unsigned int n, bool flush) +static int coroutine_fn GRAPH_RDLOCK +qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, + unsigned int index, unsigned int n, bool flush) { unsigned int sector_mask =3D BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; diff --git a/block/qed.c b/block/qed.c index 7690d0215d..cf794a1add 100644 --- a/block/qed.c +++ b/block/qed.c @@ -395,8 +395,8 @@ static void bdrv_qed_init_state(BlockDriverState *bs) } =20 /* Called with table_lock held. */ -static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *opti= ons, - int flags, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags, Error **= errp) { BDRVQEDState *s =3D bs->opaque; QEDHeader le_header; @@ -557,7 +557,7 @@ typedef struct QEDOpenCo { int ret; } QEDOpenCo; =20 -static void coroutine_fn bdrv_qed_open_entry(void *opaque) +static void coroutine_fn GRAPH_RDLOCK bdrv_qed_open_entry(void *opaque) { QEDOpenCo *qoc =3D opaque; BDRVQEDState *s =3D qoc->bs->opaque; @@ -579,6 +579,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *o= ptions, 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; @@ -995,7 +997,7 @@ static void coroutine_fn qed_aio_complete(QEDAIOCB *acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_l1_update(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_l1_update(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); CachedL2Table *l2_table =3D acb->request.l2_table; @@ -1025,7 +1027,8 @@ static int coroutine_fn qed_aio_write_l1_update(QEDAI= OCB *acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t of= fset) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset) { BDRVQEDState *s =3D acb_to_s(acb); bool need_alloc =3D acb->find_cluster_ret =3D=3D QED_CLUSTER_L1; @@ -1081,7 +1084,7 @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *= acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_cow(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_cow(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t start, len, offset; @@ -1159,7 +1162,8 @@ static bool qed_should_set_need_check(BDRVQEDState *s) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); int ret; @@ -1265,8 +1269,8 @@ out: * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_data(void *opaque, int ret, - uint64_t offset, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; =20 @@ -1336,7 +1340,7 @@ static int coroutine_fn qed_aio_read_data(void *opaqu= e, int ret, /** * Begin next I/O or complete the request */ -static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_next_io(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset; @@ -1381,9 +1385,9 @@ static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb) return ret; } =20 -static int coroutine_fn qed_co_request(BlockDriverState *bs, int64_t secto= r_num, - QEMUIOVector *qiov, int nb_sectors, - int flags) +static int coroutine_fn GRAPH_RDLOCK +qed_co_request(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qio= v, + int nb_sectors, int flags) { QEDAIOCB acb =3D { .bs =3D bs, @@ -1404,6 +1408,7 @@ static int coroutine_fn bdrv_qed_co_readv(BlockDriver= State *bs, int64_t sector_num, int nb_secto= rs, QEMUIOVector *qiov) { + assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, 0); } =20 @@ -1411,6 +1416,7 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDrive= rState *bs, int64_t sector_num, int nb_sect= ors, QEMUIOVector *qiov, int flags) { + assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 @@ -1421,6 +1427,8 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Blo= ckDriverState *bs, { BDRVQEDState *s =3D bs->opaque; =20 + assume_graph_lock(); /* FIXME */ + /* * Zero writes start without an I/O buffer. If a buffer becomes neces= sary * then it will be allocated during request processing. @@ -1571,8 +1579,8 @@ static int bdrv_qed_change_backing_file(BlockDriverSt= ate *bs, return ret; } =20 -static void coroutine_fn bdrv_qed_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVQEDState *s =3D bs->opaque; int ret; @@ -1588,9 +1596,9 @@ static void coroutine_fn bdrv_qed_co_invalidate_cache= (BlockDriverState *bs, } } =20 -static int coroutine_fn bdrv_qed_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_check(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BDRVQEDState *s =3D bs->opaque; int ret; diff --git a/block/quorum.c b/block/quorum.c index f3fe067541..3fe3791ab2 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -778,7 +778,7 @@ static int64_t coroutine_fn quorum_co_getlength(BlockDr= iverState *bs) return result; } =20 -static coroutine_fn int quorum_co_flush(BlockDriverState *bs) +static coroutine_fn GRAPH_RDLOCK int quorum_co_flush(BlockDriverState *bs) { BDRVQuorumState *s =3D bs->opaque; QuorumVoteVersion *winner =3D NULL; diff --git a/block/throttle.c b/block/throttle.c index 64fa0f5acc..a0db840927 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -162,7 +162,7 @@ static int coroutine_fn throttle_co_pwritev_compressed(= BlockDriverState *bs, BDRV_REQ_WRITE_COMPRESSED); } =20 -static int coroutine_fn throttle_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK throttle_co_flush(BlockDriverState *b= s) { return bdrv_co_flush(bs->file->bs); } diff --git a/block/vmdk.c b/block/vmdk.c index 3fcb75319f..d074f696aa 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1484,8 +1484,8 @@ exit: return ret; } =20 -static int coroutine_fn vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_= data, - uint32_t offset) +static int coroutine_fn GRAPH_RDLOCK +vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, uint32_t offset) { offset =3D cpu_to_le32(offset); /* update L2 table */ @@ -2028,6 +2028,8 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, uint64_t bytes_done =3D 0; VmdkMetaData m_data; =20 + assume_graph_lock(); /* FIXME */ + if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 " total_sectors=3D0x%" PRIx64, --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437970; cv=none; d=zohomail.com; s=zohoarc; b=iX4QYc8PAq6LOEyBRRZe8mHCa0BAKjFr54mb3b+J+7lbSojcInQlPztBKIHM3rNIH//malopyDDsADJuNgmkhGYd+QTNf4nEK4RZX4zh7Y+549h2iqjfT83Sq9QUtSOknEZkVscW5Yd2fY8DIjH5lRFnFfiyd5YFi+Jzab37G1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437970; 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=d2gDPz9I+4OFrmUH7anE1UB6ntai/JakfAsryJ5ctZQ=; b=JWcZAVQ/hGh+ruFp2H0pqvDwdQC4xcONbDemsisNC/sJcNXEmjDg2ymQ/jGEjb70gBl7ue2HLR+joHGkeemEvGS9/HmLvH5GcB8XJdUbxpYwsG9dbmlNJ4JMaOa8GYAKe9sFqvvomAMQJOQRoxFOCkAbybPAeuCWSdHjOg0eLEg= 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+importer2=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 167543797023260.95238976823737; Fri, 3 Feb 2023 07:26:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtr-0007NH-Ej; Fri, 03 Feb 2023 10:22:51 -0500 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 1pNxtp-0007MN-Ni for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:49 -0500 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 1pNxtn-0005IJ-M3 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:49 -0500 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-86-t0guZuwwOESpaNZkvaaSTw-1; Fri, 03 Feb 2023 10:22:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2C00F800B24; Fri, 3 Feb 2023 15:22:43 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31994404CD80; Fri, 3 Feb 2023 15:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437767; 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=d2gDPz9I+4OFrmUH7anE1UB6ntai/JakfAsryJ5ctZQ=; b=Q+u5Z3O7NfHdiJhyySSBLm6qTM5OBCYve6I6OylVHYHOZs+ugoEZ7nAyFTkJN2Vrm2PzXD Jzx+c0ACL+DDvc+BhHz++eklP85wwOqcfy75r+on7APh0zRFUiub/gzmLqnlpYt8pRULAT 9D3brln9bBLmeRXobw7JayFqplG6hi0= X-MC-Unique: t0guZuwwOESpaNZkvaaSTw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 08/23] block: Mark bdrv_co_pdiscard() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:47 +0100 Message-Id: <20230203152202.49054-9-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437971541100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pdiscard() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 5 +++-- include/block/block_int-common.h | 15 +++++++++------ include/block/block_int-io.h | 2 +- block/blkdebug.c | 4 ++-- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 4 ++-- block/block-backend.c | 1 + block/copy-before-write.c | 8 ++++---- block/copy-on-read.c | 4 ++-- block/filter-compress.c | 4 ++-- block/io.c | 2 ++ block/mirror.c | 14 +++++++++----- block/preallocate.c | 4 ++-- block/raw-format.c | 4 ++-- block/snapshot-access.c | 4 ++-- block/throttle.c | 4 ++-- 16 files changed, 47 insertions(+), 37 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 7e96506138..627061fd5f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -103,8 +103,9 @@ bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); /* Ensure contents are flushed to disk. */ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, - int64_t bytes); +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, + int64_t bytes); + bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 51eaabd9d1..c52190abdb 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -479,8 +479,9 @@ struct BlockDriver { BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, - int64_t offset, int bytes, + + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_pdiscard)( + BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); =20 int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, @@ -543,8 +544,9 @@ struct BlockDriver { */ int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, - int64_t offset, int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( + BlockDriverState *bs, int64_t offset, int64_t bytes); =20 /* * Map [offset, offset + nbytes) range onto a child of @bs to copy fro= m, @@ -632,8 +634,9 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); - int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs, - int64_t offset, int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)( + BlockDriverState *bs, int64_t offset, int64_t bytes); =20 /* * Invalidate any cached meta-data. diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 4430bf4c4a..4bb6ccaa34 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -40,7 +40,7 @@ int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); -int coroutine_fn bdrv_co_pdiscard_snapshot(BlockDriverState *bs, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *= bs, int64_t offset, int64_t bytes); =20 =20 diff --git a/block/blkdebug.c b/block/blkdebug.c index 5ba3766a2c..8506004707 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -712,8 +712,8 @@ static int coroutine_fn blkdebug_co_pwrite_zeroes(Block= DriverState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { uint32_t align =3D bs->bl.pdiscard_alignment; int err; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 5ec1d23f29..3033f5035b 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -450,7 +450,7 @@ blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr) return bdrv_co_flush(fr->bs->file->bs); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr) { return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes); @@ -483,10 +483,9 @@ blk_log_writes_co_flush_to_disk(BlockDriverState *bs) LOG_FLUSH_FLAG, false); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t b= ytes) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, 0, blk_log_writes_co_do_file_pdiscard, LOG_DISCARD_FLAG, false); diff --git a/block/blkreplay.c b/block/blkreplay.c index ce13fa5ba5..c18d3a755d 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -102,8 +102,8 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(Bloc= kDriverState *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t byte= s) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pdiscard(bs->file, offset, bytes); diff --git a/block/block-backend.c b/block/block-backend.c index 3e58b95b8a..b4d2387947 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1719,6 +1719,7 @@ blk_co_do_pdiscard(BlockBackend *blk, int64_t offset,= int64_t bytes) IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 ret =3D blk_check_byte_request(blk, offset, bytes); if (ret < 0) { diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 4ba72c6309..42b46e746a 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -149,8 +149,8 @@ static coroutine_fn int cbw_do_copy_before_write(BlockD= riverState *bs, return 0; } =20 -static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, 0); if (ret < 0) { @@ -322,8 +322,8 @@ cbw_co_snapshot_block_status(BlockDriverState *bs, return ret; } =20 -static int coroutine_fn cbw_co_pdiscard_snapshot(BlockDriverState *bs, - int64_t offset, int64_t b= ytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t byt= es) { BDRVCopyBeforeWriteState *s =3D bs->opaque; =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 3280eb2feb..b564f1ca3f 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -200,8 +200,8 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDrive= rState *bs, } =20 =20 -static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 2e2a65966c..083aaef53c 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -92,8 +92,8 @@ static int coroutine_fn compress_co_pwrite_zeroes(BlockDr= iverState *bs, } =20 =20 -static int coroutine_fn compress_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/io.c b/block/io.c index e6b4713117..f15b910549 100644 --- a/block/io.c +++ b/block/io.c @@ -2968,6 +2968,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int head, tail, align; BlockDriverState *bs =3D child->bs; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!bs || !bs->drv || !bdrv_co_is_inserted(bs)) { return -ENOMEDIUM; @@ -3574,6 +3575,7 @@ bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64= _t offset, int64_t bytes) BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; diff --git a/block/mirror.c b/block/mirror.c index d1d79f2319..b67e8b14f8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1443,9 +1443,10 @@ static int coroutine_fn bdrv_mirror_top_preadv(Block= DriverState *bs, return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } =20 -static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs, - MirrorMethod method, uint64_t offset, uint64_t bytes, QEMUIOVector *qi= ov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_do_write(BlockDriverState *bs, MirrorMethod method, + uint64_t offset, uint64_t bytes, QEMUIOVector *qi= ov, + int flags) { MirrorOp *op =3D NULL; MirrorBDSOpaque *s =3D bs->opaque; @@ -1503,6 +1504,8 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, int ret =3D 0; bool copy_to_target =3D false; =20 + assume_graph_lock(); /* FIXME */ + if (s->job) { copy_to_target =3D s->job->ret >=3D 0 && !job_is_cancelled(&s->job->common.job) && @@ -1547,12 +1550,13 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_to= p_flush(BlockDriverState *bs) static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, offset, bytes,= NULL, flags); } =20 -static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t byt= es) { return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, offset, byt= es, NULL, 0); diff --git a/block/preallocate.c b/block/preallocate.c index 483b596280..c2c2dc8a8c 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -234,8 +234,8 @@ static coroutine_fn int preallocate_co_preadv_part( flags); } =20 -static int coroutine_fn preallocate_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t byt= es) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t byte= s) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/raw-format.c b/block/raw-format.c index 202acb1232..7f1036ebed 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -305,8 +305,8 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDrive= rState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { int ret; =20 diff --git a/block/snapshot-access.c b/block/snapshot-access.c index 0a30ec6cd9..009cc4aea0 100644 --- a/block/snapshot-access.c +++ b/block/snapshot-access.c @@ -49,8 +49,8 @@ snapshot_access_co_block_status(BlockDriverState *bs, bytes, pnum, map, file); } =20 -static int coroutine_fn snapshot_access_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +snapshot_access_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t = bytes) { return bdrv_co_pdiscard_snapshot(bs->file->bs, offset, bytes); } diff --git a/block/throttle.c b/block/throttle.c index a0db840927..b07d853c0a 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -144,8 +144,8 @@ static int coroutine_fn throttle_co_pwrite_zeroes(Block= DriverState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); --=20 2.38.1 From nobody Thu Mar 28 11:49:23 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438054; cv=none; d=zohomail.com; s=zohoarc; b=Sz670QJly1r+OYbTWDZdB9Y+mjDsAr+XjoaRJ7mbI63XlIyqWqaZoa54t9fYJyOjbVb03C7cR1RlyFeMXhf22vYgjHCxdOzjwrhluaVyP7GlTUEdpu7P54DAY5tozwq4YFlQZFfdJ40oUoCD5SdLn7PUZz2OGzq3k8OI1ITjLKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438054; 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=Nx5wCTKth5pDTOab2FUS28ZmJOulQw87Ee60VcM0Vc4=; b=FVb2+AmaGFLc696LwZC1gJpIkvFHMBDTG6nbHOvQhfMbpjEucid4drDl9/V5XG1BAR2Z0FnRyZQx1dS8Su4MDn1nAEROnXtSZeA4Dfk8XxRJL8NfHH+D5CgpZxJQgtLtIkg2Y1CI0zyepI+/VeRnNQA3j590jy7/ZWRYHXX5ENY= 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+importer2=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 1675438054566537.0911001811189; Fri, 3 Feb 2023 07:27:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtt-0007OT-4B; Fri, 03 Feb 2023 10:22:53 -0500 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 1pNxtr-0007NI-Bv for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:51 -0500 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 1pNxto-0005Id-Gr for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:51 -0500 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-182-Zwt0HTeDPH6ZhTHwrAZUzQ-1; Fri, 03 Feb 2023 10:22:44 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 62C6785D061; Fri, 3 Feb 2023 15:22:44 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 665EE404CD80; Fri, 3 Feb 2023 15:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437768; 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=Nx5wCTKth5pDTOab2FUS28ZmJOulQw87Ee60VcM0Vc4=; b=OFUL1VsrKuvTACyApskiEMZr6POuxlv9Au/RjDlSFOsYkabkqZ389/1GUaPU0uV/WG7eGW oPVIzttwkuFPalLEJZ19qkp8M+DBpdSusagkzTirc4p2Wgkof4aa3Lskt3/RMpD5CIglW7 kgFfgP/cJTft4aw9vDDa3hOEPPYQ0RE= X-MC-Unique: Zwt0HTeDPH6ZhTHwrAZUzQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 09/23] block: Mark bdrv_co_pwrite_zeroes() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:48 +0100 Message-Id: <20230203152202.49054-10-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438056579100002 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_zeroes() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qcow2.h | 6 ++++-- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 5 +++-- block/blkdebug.c | 6 +++--- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 5 +++-- block/block-copy.c | 13 +++++++------ block/copy-before-write.c | 5 +++-- block/copy-on-read.c | 6 +++--- block/filter-compress.c | 6 +++--- block/io.c | 12 +++++++++--- block/mirror.c | 6 +++--- block/preallocate.c | 11 +++++++---- block/qcow2.c | 30 ++++++++++++++++++------------ block/qed.c | 9 +++------ block/quorum.c | 15 ++++++++++----- block/raw-format.c | 6 +++--- block/throttle.c | 6 +++--- 18 files changed, 92 insertions(+), 69 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 7a02699bfa..82cd1664cf 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -927,8 +927,10 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, Q= CowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, bool full_discard); -int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t o= ffset, - uint64_t bytes, int flags); + +int coroutine_fn GRAPH_RDLOCK +qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, uint64_t b= ytes, + int flags); =20 int qcow2_expand_zero_clusters(BlockDriverState *bs, BlockDriverAmendStatusCB *status_cb, diff --git a/include/block/block-io.h b/include/block/block-io.h index 627061fd5f..ec26f07d60 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -69,8 +69,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, in= t64_t offset, * function is not suitable for zeroing the entire image in a single reque= st * because it may allocate memory for the entire region. */ -int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, - int64_t bytes, BdrvRequestFlags fla= gs); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, + BdrvRequestFlags flags); =20 int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, @@ -133,8 +134,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, bool include_base, int64_t offset, int64_t byt= es, int64_t *pnum); =20 -int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, - int64_t bytes); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index c52190abdb..21b4cb1101 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -542,8 +542,9 @@ struct BlockDriver { * function pointer may be NULL or return -ENOSUP and .bdrv_co_writev() * will be called instead. */ - int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwrite_zeroes)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags); =20 int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( BlockDriverState *bs, int64_t offset, int64_t bytes); diff --git a/block/blkdebug.c b/block/blkdebug.c index 8506004707..eed03bfe7e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -679,9 +679,9 @@ static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(= BlockDriverState *bs) return bdrv_co_flush(bs->file->bs); } =20 -static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { uint32_t align =3D MAX(bs->bl.request_alignment, bs->bl.pwrite_zeroes_alignment); diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 3033f5035b..bdaa2a57a2 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -437,7 +437,7 @@ blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *= fr) fr->qiov, fr->file_flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFileReq *fr) { return bdrv_co_pwrite_zeroes(fr->bs->file, fr->offset, fr->bytes, @@ -465,11 +465,10 @@ blk_log_writes_co_pwritev(BlockDriverState *bs, int64= _t offset, int64_t bytes, blk_log_writes_co_do_file_pwritev, 0, fal= se); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, flags, blk_log_writes_co_do_file_pwrite_zeroes, = 0, true); diff --git a/block/blkreplay.c b/block/blkreplay.c index c18d3a755d..2703a0c8c6 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -91,8 +91,9 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverS= tate *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t b= ytes, + BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); diff --git a/block/block-copy.c b/block/block-copy.c index d299fac7cc..e13d7bc6b6 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -469,10 +469,9 @@ static coroutine_fn int block_copy_task_run(AioTaskPoo= l *pool, * value of @method should be used for subsequent tasks. * Returns 0 on success. */ -static int coroutine_fn block_copy_do_copy(BlockCopyState *s, - int64_t offset, int64_t bytes, - BlockCopyMethod *method, - bool *error_is_read) +static int coroutine_fn GRAPH_RDLOCK +block_copy_do_copy(BlockCopyState *s, int64_t offset, int64_t bytes, + BlockCopyMethod *method, bool *error_is_read) { int ret; int64_t nbytes =3D MIN(offset + bytes, s->len) - offset; @@ -558,8 +557,10 @@ static coroutine_fn int block_copy_task_entry(AioTask = *task) BlockCopyMethod method =3D t->method; int ret; =20 - ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, - &error_is_read); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, + &error_is_read); + } =20 WITH_QEMU_LOCK_GUARD(&s->lock) { if (s->method =3D=3D t->method) { diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 42b46e746a..61854beae2 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -160,8 +160,9 @@ cbw_co_pdiscard(BlockDriverState *bs, int64_t offset, i= nt64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int coroutine_fn cbw_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, flags); if (ret < 0) { diff --git a/block/copy-on-read.c b/block/copy-on-read.c index b564f1ca3f..ebf6864dd3 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -192,9 +192,9 @@ static int coroutine_fn cor_co_pwritev_part(BlockDriver= State *bs, } =20 =20 -static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 083aaef53c..7a632f47fe 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -84,9 +84,9 @@ static int coroutine_fn compress_co_pwritev_part(BlockDri= verState *bs, } =20 =20 -static int coroutine_fn compress_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } diff --git a/block/io.c b/block/io.c index f15b910549..ce4dc10bc0 100644 --- a/block/io.c +++ b/block/io.c @@ -1172,6 +1172,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, int64_t progress =3D 0; bool skip_write; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1692,6 +1694,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, bs->bl.request_alignment); int max_transfer =3D MIN_NON_ZERO(bs->bl.max_transfer, MAX_BOUNCE_BUFF= ER); =20 + assert_bdrv_graph_readable(); bdrv_check_request(offset, bytes, &error_abort); =20 if (!drv) { @@ -1907,6 +1910,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, int64_t bytes_remaining =3D bytes; int max_transfer; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -2156,6 +2161,7 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *chi= ld, int64_t offset, { IO_CODE(); trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); + assert_bdrv_graph_readable(); =20 if (!(child->bs->open_flags & BDRV_O_UNMAP)) { flags &=3D ~BDRV_REQ_MAY_UNMAP; @@ -2599,8 +2605,6 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverStat= e *bs, int64_t offset, int64_t pnum =3D bytes; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - if (!bytes) { return 1; } @@ -3238,7 +3242,7 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *= host, size_t size) } } =20 -static int coroutine_fn bdrv_co_copy_range_internal( +static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_range_internal( BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags, @@ -3327,6 +3331,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assume_graph_lock(); /* FIXME */ trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3344,6 +3349,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assume_graph_lock(); /* FIXME */ trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, diff --git a/block/mirror.c b/block/mirror.c index b67e8b14f8..a6f4ec6282 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1547,10 +1547,10 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_to= p_flush(BlockDriverState *bs) return bdrv_co_flush(bs->backing->bs); } =20 -static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset, + int64_t bytes, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, offset, bytes,= NULL, flags); } diff --git a/block/preallocate.c b/block/preallocate.c index c2c2dc8a8c..91d73c81c6 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -269,8 +269,9 @@ static bool has_prealloc_perms(BlockDriverState *bs) * want_merge_zero is used to merge write-zero request with preallocation = in * one bdrv_co_pwrite_zeroes() call. */ -static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset, - int64_t bytes, bool want_merge_zero) +static bool coroutine_fn GRAPH_RDLOCK +handle_write(BlockDriverState *bs, int64_t offset, int64_t bytes, + bool want_merge_zero) { BDRVPreallocateState *s =3D bs->opaque; int64_t end =3D offset + bytes; @@ -345,8 +346,9 @@ static bool coroutine_fn handle_write(BlockDriverState = *bs, int64_t offset, return want_merge_zero; } =20 -static int coroutine_fn preallocate_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, + int64_t bytes, BdrvRequestFlags flags) { bool want_merge_zero =3D !(flags & ~(BDRV_REQ_ZERO_WRITE | BDRV_REQ_NO_FALLBACK)); @@ -364,6 +366,7 @@ static coroutine_fn int preallocate_co_pwritev_part(Blo= ckDriverState *bs, size_t qiov_offset, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ handle_write(bs, offset, bytes, false); =20 return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, diff --git a/block/qcow2.c b/block/qcow2.c index e06ea7b5ff..89c3edbd61 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2450,7 +2450,8 @@ static bool merge_cow(uint64_t offset, unsigned bytes, * Return 1 if the COW regions read as zeroes, 0 if not, < 0 on error. * Note that returning 0 does not guarantee non-zero data. */ -static int coroutine_fn is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) { /* * This check is designed for optimization shortcut so it must be @@ -2468,8 +2469,8 @@ static int coroutine_fn is_zero_cow(BlockDriverState = *bs, QCowL2Meta *m) m->cow_end.nb_bytes); } =20 -static int coroutine_fn handle_alloc_space(BlockDriverState *bs, - QCowL2Meta *l2meta) +static int coroutine_fn GRAPH_RDLOCK +handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) { BDRVQcow2State *s =3D bs->opaque; QCowL2Meta *m; @@ -2532,12 +2533,10 @@ static int coroutine_fn handle_alloc_space(BlockDri= verState *bs, * l2meta - if not NULL, qcow2_co_pwritev_task() will consume it. Caller = must * not use it somehow after qcow2_co_pwritev_task() call */ -static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, - uint64_t host_offset, - uint64_t offset, uint64_t by= tes, - QEMUIOVector *qiov, - uint64_t qiov_offset, - QCowL2Meta *l2meta) +static coroutine_fn GRAPH_RDLOCK +int qcow2_co_pwritev_task(BlockDriverState *bs, uint64_t host_offset, + uint64_t offset, uint64_t bytes, QEMUIOVector *q= iov, + uint64_t qiov_offset, QCowL2Meta *l2meta) { int ret; BDRVQcow2State *s =3D bs->opaque; @@ -2603,7 +2602,11 @@ out_locked: return ret; } =20 -static coroutine_fn int qcow2_co_pwritev_task_entry(AioTask *task) +/* + * This function can count as GRAPH_RDLOCK because qcow2_co_pwritev_part()= holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwritev_task_entry(AioTask *= task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -2626,6 +2629,8 @@ static coroutine_fn int qcow2_co_pwritev_part( QCowL2Meta *l2meta =3D NULL; AioTaskPool *aio =3D NULL; =20 + assume_graph_lock(); /* FIXME */ + trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -3974,8 +3979,9 @@ static bool is_zero(BlockDriverState *bs, int64_t off= set, int64_t bytes) return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && bytes =3D=3D 0; } =20 -static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; BDRVQcow2State *s =3D bs->opaque; diff --git a/block/qed.c b/block/qed.c index cf794a1add..bdcb6de6df 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1420,15 +1420,12 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDri= verState *bs, return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 -static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { BDRVQEDState *s =3D bs->opaque; =20 - assume_graph_lock(); /* FIXME */ - /* * Zero writes start without an I/O buffer. If a buffer becomes neces= sary * then it will be allocated during request processing. diff --git a/block/quorum.c b/block/quorum.c index 3fe3791ab2..02ae0d8343 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -683,7 +683,11 @@ static int coroutine_fn quorum_co_preadv(BlockDriverSt= ate *bs, return ret; } =20 -static void coroutine_fn write_quorum_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because quorum_co_pwritev() hol= ds the + * graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK write_quorum_entry(void *opaque) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -722,6 +726,8 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverSt= ate *bs, int64_t offset, QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); int i, ret; =20 + assume_graph_lock(); /* FIXME */ + for (i =3D 0; i < s->num_children; i++) { Coroutine *co; QuorumCo data =3D { @@ -745,10 +751,9 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverS= tate *bs, int64_t offset, return ret; } =20 -static int coroutine_fn quorum_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - BdrvRequestFlags flags) - +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t byte= s, + BdrvRequestFlags flags) { return quorum_co_pwritev(bs, offset, bytes, NULL, flags | BDRV_REQ_ZERO_WRITE); diff --git a/block/raw-format.c b/block/raw-format.c index 7f1036ebed..007d7f6e42 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -292,9 +292,9 @@ static int coroutine_fn raw_co_block_status(BlockDriver= State *bs, return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 -static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; =20 diff --git a/block/throttle.c b/block/throttle.c index b07d853c0a..3db4fa3c40 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -134,9 +134,9 @@ static int coroutine_fn throttle_co_pwritev(BlockDriver= State *bs, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438067; cv=none; d=zohomail.com; s=zohoarc; b=RdqfEVxo0c7BFy1H3u1f9S2eRoGeV1jPFRNSnToDrfAhYIncgUSUbXPGMcHOMWoh4qiemGR42LcNeheYHvisXNvUYthjgbPl5d7Gp6WpSO+ZMrxvs5mOwUuHWMrgOvWcsnYv3/XCS1GlxdyUk5gU6AvV0so81bN2kALdfoVA+ZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438067; 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=g2GUK/uGzv0f/Rq3GF43MAUipHXc/xVMjYJ1eXQfGbM=; b=BBHwAfjF0DsZ21TdEz/6m31Mc8R3WYfxCjhlhXhDDitXzLWXgJjK3fogeTgt/WvArGkiQGL5Is6pzoIJoy+GD/zCpGs4c1DLges6F/4sssR1xm5pP9OURIW3yuBGrE7bets0GYfTJTOGXMZpoW9hqvbZZc4aqhKFfGNwJG08aAI= 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+importer2=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 167543806744444.45619967477262; Fri, 3 Feb 2023 07:27:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtt-0007OY-Hn; Fri, 03 Feb 2023 10:22:53 -0500 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 1pNxts-0007O1-BZ for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:52 -0500 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 1pNxtp-0005Ip-Sp for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:52 -0500 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-371-t4C71H2WOeKBi14x6i0x4g-1; Fri, 03 Feb 2023 10:22:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 96B6C85D061; Fri, 3 Feb 2023 15:22:45 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D2D0404CD80; Fri, 3 Feb 2023 15:22:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437769; 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=g2GUK/uGzv0f/Rq3GF43MAUipHXc/xVMjYJ1eXQfGbM=; b=BfsbgRw2sMpQdzcj1KnFQeqG8vh8zI7LuAAW1sac5CfTB2dcSa3UZ3RHhPA4DVvlfXV4s4 7pnvy1uJlL1ib/TKvARO+Z1yR0OLoZ8h0nxO1C7bq3b6nr/Ql6hzLrg1kpEteRNHW5akqi fkCVz64QehjISq+BYgUGmLw8WIMR+6g= X-MC-Unique: t4C71H2WOeKBi14x6i0x4g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 10/23] block: Mark read/write in block/io.c GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:49 +0100 Message-Id: <20230203152202.49054-11-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438068673100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_driver_*() need to hold a reader lock for the graph. It doesn't add the annotation to public functions yet. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qcow2.h | 5 ++- include/block/block_int-common.h | 40 ++++++++++--------- block/io.c | 66 +++++++++++++++----------------- block/parallels.c | 8 ++-- block/qcow.c | 20 ++++------ block/qcow2-cluster.c | 10 ++--- block/qcow2.c | 37 ++++++++++-------- block/qed.c | 14 +++---- block/quorum.c | 8 ++-- block/vmdk.c | 4 +- 10 files changed, 101 insertions(+), 111 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 82cd1664cf..46dca53e45 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -921,8 +921,9 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(= BlockDriverState *bs, void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_ent= ry, uint64_t *coffset, int *csize); =20 -int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs, - QCowL2Meta *m); +int coroutine_fn GRAPH_RDLOCK +qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); + void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 21b4cb1101..192841f040 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -471,12 +471,14 @@ struct BlockDriver { Error **errp); =20 /* aio */ - BlockAIOCB *(*bdrv_aio_preadv)(BlockDriverState *bs, + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_preadv)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs, + + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_pwritev)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); =20 @@ -484,7 +486,7 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); =20 - int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_readv)(BlockDriverState *b= s, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); =20 /** @@ -502,16 +504,16 @@ struct BlockDriver { * * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_preadv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv)(BlockDriverState *= bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); =20 - int coroutine_fn (*bdrv_co_preadv_part)(BlockDriverState *bs, - int64_t offset, int64_t bytes, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_part)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); =20 - int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_writev)(BlockDriverState *= bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int flags); /** @@ -529,12 +531,12 @@ struct BlockDriver { * * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_pwritev)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pwritev_part)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_off= set, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector = *qiov, BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_part)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector = *qiov, + size_t qiov_offset, BdrvRequestFlags flags); =20 /* * Efficiently zero a region of the disk image. Typically an image fo= rmat @@ -695,11 +697,13 @@ struct BlockDriver { BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, Error **errp); =20 - int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov); - int coroutine_fn (*bdrv_co_pwritev_compressed_part)(BlockDriverState *= bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - size_t qiov_offset); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed_part)( + 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); @@ -764,7 +768,7 @@ struct BlockDriver { BlockDriverState *bs, const char *name, Error **errp); }; =20 -static inline bool block_driver_can_compress(BlockDriver *drv) +static inline bool TSA_NO_TSA block_driver_can_compress(BlockDriver *drv) { return drv->bdrv_co_pwritev_compressed || drv->bdrv_co_pwritev_compressed_part; diff --git a/block/io.c b/block/io.c index ce4dc10bc0..484e068724 100644 --- a/block/io.c +++ b/block/io.c @@ -160,6 +160,7 @@ 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); @@ -961,10 +962,9 @@ static void bdrv_co_io_em_complete(void *opaque, int r= et) aio_co_wake(co->coroutine); } =20 -static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_driver_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriver *drv =3D bs->drv; int64_t sector_num; @@ -1030,11 +1030,10 @@ out: return ret; } =20 -static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_driver_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BlockDriver *drv =3D bs->drv; bool emulate_fua =3D false; @@ -1043,8 +1042,6 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriv= erState *bs, QEMUIOVector local_qiov; int ret; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1114,7 +1111,7 @@ emulate_flags: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK bdrv_driver_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -1149,9 +1146,9 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = int64_t offset, return ret; } =20 -static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_copy_on_readv(BdrvChild *child, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriverState *bs =3D child->bs; =20 @@ -1172,8 +1169,6 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, int64_t progress =3D 0; bool skip_write; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1315,9 +1310,10 @@ err: * handles copy on read, zeroing after EOF, and fragmentation of large * reads; any other features must be implemented by the caller. */ -static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, - BdrvTrackedRequest *req, int64_t offset, int64_t bytes, - int64_t align, QEMUIOVector *qiov, size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_aligned_preadv(BdrvChild *child, BdrvTrackedRequest *req, + int64_t offset, int64_t bytes, int64_t align, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriverState *bs =3D child->bs; int64_t total_bytes, max_bytes; @@ -1484,10 +1480,9 @@ static bool bdrv_init_padding(BlockDriverState *bs, return true; } =20 -static coroutine_fn int bdrv_padding_rmw_read(BdrvChild *child, - BdrvTrackedRequest *req, - BdrvRequestPadding *pad, - bool zero_middle) +static int coroutine_fn GRAPH_RDLOCK +bdrv_padding_rmw_read(BdrvChild *child, BdrvTrackedRequest *req, + BdrvRequestPadding *pad, bool zero_middle) { QEMUIOVector local_qiov; BlockDriverState *bs =3D child->bs; @@ -1626,6 +1621,8 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, int ret; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + trace_bdrv_co_preadv_part(bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { @@ -1898,10 +1895,11 @@ bdrv_co_write_req_finish(BdrvChild *child, int64_t = offset, int64_t bytes, * Forwards an already correctly aligned write request to the BlockDriver, * after possibly fragmenting it. */ -static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, - BdrvTrackedRequest *req, int64_t offset, int64_t bytes, - int64_t align, QEMUIOVector *qiov, size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_aligned_pwritev(BdrvChild *child, BdrvTrackedRequest *req, + int64_t offset, int64_t bytes, int64_t align, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; @@ -1910,8 +1908,6 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, int64_t bytes_remaining =3D bytes; int max_transfer; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1984,11 +1980,9 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, return ret; } =20 -static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags, - BdrvTrackedRequest *req) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, + BdrvRequestFlags flags, BdrvTrackedRequest *req) { BlockDriverState *bs =3D child->bs; QEMUIOVector local_qiov; @@ -2076,6 +2070,8 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, bool padded =3D false; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { diff --git a/block/parallels.c b/block/parallels.c index 36c9de8a8a..2cf5061524 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -320,17 +320,15 @@ static int coroutine_fn parallels_co_block_status(Blo= ckDriverState *bs, return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 -static coroutine_fn int parallels_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sec= tors, - QEMUIOVector *qiov, int flags) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_secto= rs, + QEMUIOVector *qiov, int flags) { BDRVParallelsState *s =3D bs->opaque; uint64_t bytes_done =3D 0; QEMUIOVector hd_qiov; int ret =3D 0; =20 - assume_graph_lock(); /* FIXME */ - qemu_iovec_init(&hd_qiov, qiov->niov); =20 while (nb_sectors > 0) { diff --git a/block/qcow.c b/block/qcow.c index 2d19a78818..1e1d1792d0 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -617,9 +617,9 @@ static void qcow_refresh_limits(BlockDriverState *bs, E= rror **errp) bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; } =20 -static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offse= t, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -628,8 +628,6 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 - assume_graph_lock(); /* FIXME */ - if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -715,9 +713,9 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, return ret; } =20 -static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offs= et, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -726,8 +724,6 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverStat= e *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 - assume_graph_lock(); /* FIXME */ - s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 /* We must always copy the iov when encrypting, so we @@ -1048,7 +1044,7 @@ static int qcow_make_empty(BlockDriverState *bs) =20 /* XXX: put compressed sectors first, then all the cluster aligned tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { @@ -1058,8 +1054,6 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int6= 4_t offset, int64_t bytes, uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 - assume_graph_lock(); /* FIXME */ - buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes !=3D s->cluster_size) { if (bytes > s->cluster_size || diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 870be106b6..a22607d90d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -491,10 +491,9 @@ static int count_contiguous_subclusters(BlockDriverSta= te *bs, int nb_clusters, return count; } =20 -static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, - uint64_t src_cluster_offset, - unsigned offset_in_cluster, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset, + unsigned offset_in_cluster, QEMUIOVector *qiov) { int ret; =20 @@ -886,7 +885,8 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(= BlockDriverState *bs, return 0; } =20 -static int coroutine_fn perform_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +perform_cow(BlockDriverState *bs, QCowL2Meta *m) { BDRVQcow2State *s =3D bs->opaque; Qcow2COWRegion *start =3D &m->cow_start; diff --git a/block/qcow2.c b/block/qcow2.c index 89c3edbd61..8f5ad75984 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2137,9 +2137,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, return status; } =20 -static coroutine_fn int qcow2_handle_l2meta(BlockDriverState *bs, - QCowL2Meta **pl2meta, - bool link_l2) +static int coroutine_fn GRAPH_RDLOCK +qcow2_handle_l2meta(BlockDriverState *bs, QCowL2Meta **pl2meta, bool link_= l2) { int ret =3D 0; QCowL2Meta *l2meta =3D *pl2meta; @@ -2617,9 +2616,10 @@ static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwrite= v_task_entry(AioTask *task) t->l2meta); } =20 -static coroutine_fn int qcow2_co_pwritev_part( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BDRVQcow2State *s =3D bs->opaque; int offset_in_cluster; @@ -2629,8 +2629,6 @@ static coroutine_fn int qcow2_co_pwritev_part( QCowL2Meta *l2meta =3D NULL; AioTaskPool *aio =3D NULL; =20 - assume_graph_lock(); /* FIXME */ - trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -4160,6 +4158,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, uint64_t host_offset; QCowL2Meta *l2meta =3D NULL; =20 + assume_graph_lock(); /* FIXME */ assert(!bs->encrypted); =20 qemu_co_mutex_lock(&s->lock); @@ -4591,7 +4590,7 @@ fail: return ret; } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_pwritev_compressed_task(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -4655,7 +4654,13 @@ fail: return ret; } =20 -static coroutine_fn int qcow2_co_pwritev_compressed_task_entry(AioTask *ta= sk) +/* + * This function can count as GRAPH_RDLOCK because + * qcow2_co_pwritev_compressed_part() holds the graph lock and keeps it un= til + * this coroutine has terminated. + */ +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_compressed_task_entry(AioTask *task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -4669,7 +4674,7 @@ static coroutine_fn int qcow2_co_pwritev_compressed_t= ask_entry(AioTask *task) * XXX: put compressed sectors first, then all the cluster aligned * tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_pwritev_compressed_part(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -4678,8 +4683,6 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, AioTaskPool *aio =3D NULL; int ret =3D 0; =20 - assume_graph_lock(); /* FIXME */ - if (has_data_file(bs)) { return -ENOTSUP; } @@ -5296,8 +5299,8 @@ static int64_t qcow2_check_vmstate_request(BlockDrive= rState *bs, return pos; } =20 -static coroutine_fn int qcow2_co_save_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t = pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { @@ -5308,8 +5311,8 @@ static coroutine_fn int qcow2_co_save_vmstate(BlockDr= iverState *bs, return bs->drv->bdrv_co_pwritev_part(bs, offset, qiov->size, qiov, 0, = 0); } =20 -static coroutine_fn int qcow2_co_load_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t = pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { diff --git a/block/qed.c b/block/qed.c index bdcb6de6df..a4a74e59ef 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1404,19 +1404,17 @@ qed_co_request(BlockDriverState *bs, int64_t sector= _num, QEMUIOVector *qiov, return qed_aio_next_io(&acb); } =20 -static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_secto= rs, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov) { - assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, 0); } =20 -static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sect= ors, - QEMUIOVector *qiov, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sector= s, + QEMUIOVector *qiov, int flags) { - assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 diff --git a/block/quorum.c b/block/quorum.c index 02ae0d8343..ef6cda2868 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -718,16 +718,14 @@ static void coroutine_fn GRAPH_RDLOCK write_quorum_en= try(void *opaque) } } =20 -static int coroutine_fn quorum_co_pwritev(BlockDriverState *bs, int64_t of= fset, - int64_t bytes, QEMUIOVector *qio= v, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQuorumState *s =3D bs->opaque; QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); int i, ret; =20 - assume_graph_lock(); /* FIXME */ - for (i =3D 0; i < s->num_children; i++) { Coroutine *co; QuorumCo data =3D { diff --git a/block/vmdk.c b/block/vmdk.c index d074f696aa..8b844300f4 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2128,12 +2128,10 @@ vmdk_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { - assume_graph_lock(); /* FIXME */ - if (bytes =3D=3D 0) { /* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */ --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438082; cv=none; d=zohomail.com; s=zohoarc; b=HHiqMelHjqREOpdjuhV4k3pTAr7aXi0nDm+MqwZEBr0h7Bh39p2KQ9D1K/XD4FXFZ2eSwCgaRO4UpEYoN2wJThoEaRjLYnWJZiqOkoOO3EzLMYy19vnPOS3PP/ggPpqaayJZgfyqcTedP5cFJHoueMwi357HvRCv5s5YBDN/Imw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438082; 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=ye1OBWPf3c5ntovp3axdPbV9hjKTaM2Esx8acTaBJig=; b=d8OPAVz6csejLvDGfgCSvV0XLLfpfHab6GBB2GUBVqeLk+0c+IkKEpSA05hadsBXx+m3XhO83rmT74VytDrOqarDP4yr8iUw8noRoHcrsXBv5di+9MZ3DA5BAVb/9BjJ4z0MgzcIacJ+lfDaieQIeO8856vM8U/TpoWmZUFgnrY= 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+importer2=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 1675438082524733.7311091784871; Fri, 3 Feb 2023 07:28:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxty-0007RB-Cx; Fri, 03 Feb 2023 10:22:58 -0500 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 1pNxtu-0007Os-LN for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:54 -0500 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 1pNxtq-0005JI-Vh for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:54 -0500 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-556-YxrxnjqhOCGWKck6v4BAXw-1; Fri, 03 Feb 2023 10:22:47 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB4CD85D06A; Fri, 3 Feb 2023 15:22:46 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id D42DC404CD80; Fri, 3 Feb 2023 15:22:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437770; 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=ye1OBWPf3c5ntovp3axdPbV9hjKTaM2Esx8acTaBJig=; b=fE1vFy5qEMxd73duBReoldXTNdZng5P75YTrNGF2Elv9nBxNAJPZJwvvXF1KbzM8ojp78n 4nMU+DbEg93QGswrRB/+wA8XH+vvLu6gJoEMKtrdtRl/NPEQEfi8Oe1w5Td9pNSOIk562Q BLxgOpGjLw5Eq/XK4V+qp3d9lThpEPU= X-MC-Unique: YxrxnjqhOCGWKck6v4BAXw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 11/23] block: Mark public read/write functions GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:50 +0100 Message-Id: <20230203152202.49054-12-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438084746100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pread*/pwrite*() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qcow2.h | 9 ++--- block/qed.h | 18 +++++----- include/block/block_int-io.h | 14 ++++---- block/blkdebug.c | 4 +-- block/blklogwrites.c | 7 ++-- block/blkreplay.c | 10 +++--- block/block-backend.c | 2 ++ block/bochs.c | 2 +- block/commit.c | 5 +-- block/copy-before-write.c | 16 ++++----- block/copy-on-read.c | 26 ++++++--------- block/crypto.c | 4 +-- block/filter-compress.c | 19 +++++------ block/io.c | 7 ++-- block/mirror.c | 18 +++++----- block/parallels.c | 8 +++-- block/preallocate.c | 18 +++++----- block/qcow.c | 8 ++--- block/qcow2-cluster.c | 7 ++-- block/qcow2.c | 53 +++++++++++++++-------------- block/qed-table.c | 4 +-- block/qed.c | 31 +++++++++-------- block/quorum.c | 29 ++++++++++------ block/raw-format.c | 12 +++---- block/replication.c | 15 ++++----- block/throttle.c | 21 +++++------- block/vdi.c | 4 +-- block/vhdx.c | 11 +++--- block/vmdk.c | 65 +++++++++++++++--------------------- block/vpc.c | 4 +-- tests/unit/test-bdrv-drain.c | 20 ++++++----- 31 files changed, 233 insertions(+), 238 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 46dca53e45..7487bcfcf9 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -846,7 +846,7 @@ int qcow2_validate_table(BlockDriverState *bs, uint64_t= offset, Error **errp); =20 /* qcow2-refcount.c functions */ -int coroutine_fn qcow2_refcount_init(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_refcount_init(BlockDriverState *bs); void qcow2_refcount_close(BlockDriverState *bs); =20 int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index, @@ -954,9 +954,10 @@ void qcow2_free_snapshots(BlockDriverState *bs); int qcow2_read_snapshots(BlockDriverState *bs, Error **errp); int qcow2_write_snapshots(BlockDriverState *bs); =20 -int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix); +int coroutine_fn GRAPH_RDLOCK +qcow2_check_read_snapshot_table(BlockDriverState *bs, BdrvCheckResult *res= ult, + BdrvCheckMode fix); + int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix); diff --git a/block/qed.h b/block/qed.h index e48f7c2480..988654cb86 100644 --- a/block/qed.h +++ b/block/qed.h @@ -200,7 +200,7 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, = CachedL2Table *l2_table); /** * Table I/O functions */ -int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); +int coroutine_fn GRAPH_RDLOCK qed_read_l1_table_sync(BDRVQEDState *s); =20 int coroutine_fn GRAPH_RDLOCK qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n); @@ -208,10 +208,11 @@ qed_write_l1_table(BDRVQEDState *s, unsigned int inde= x, unsigned int n); int coroutine_fn GRAPH_RDLOCK qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int = n); =20 -int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *reque= st, - uint64_t offset); -int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, - uint64_t offset); +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offs= et); + +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); =20 int coroutine_fn GRAPH_RDLOCK qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int inde= x, @@ -224,9 +225,9 @@ qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *re= quest, /** * Cluster functions */ -int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request, - uint64_t pos, size_t *len, - uint64_t *img_offset); +int coroutine_fn GRAPH_RDLOCK +qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, + size_t *len, uint64_t *img_offset); =20 /** * Consistency check @@ -234,7 +235,6 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, int coroutine_fn GRAPH_RDLOCK qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); =20 - QEDTable *qed_alloc_table(BDRVQEDState *s); =20 /** diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 4bb6ccaa34..34d4b0fb8e 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -44,33 +44,35 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot= (BlockDriverState *bs, int64_t offset, int64_t bytes); =20 =20 -int coroutine_fn bdrv_co_preadv(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_part(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev_part(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); =20 -static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bdrv_co_preadv(child, offset, bytes, &qiov, flags); } =20 -static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pwrite(BdrvChild *chil= d, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bdrv_co_pwritev(child, offset, bytes, &qiov, flags); } diff --git a/block/blkdebug.c b/block/blkdebug.c index eed03bfe7e..f418a90873 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -626,7 +626,7 @@ static int rule_check(BlockDriverState *bs, uint64_t of= fset, uint64_t bytes, return -error; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blkdebug_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -647,7 +647,7 @@ blkdebug_co_preadv(BlockDriverState *bs, int64_t offset= , int64_t bytes, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blkdebug_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/blklogwrites.c b/block/blklogwrites.c index bdaa2a57a2..93086c31e1 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -294,7 +294,7 @@ static void blk_log_writes_refresh_limits(BlockDriverSt= ate *bs, Error **errp) bs->bl.request_alignment =3D s->sectorsize; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_preadv(BlockDriverState *bs, int64_t offset, int64_t byt= es, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -430,7 +430,7 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t of= fset, uint64_t bytes, return fr.file_ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *fr) { return bdrv_co_pwritev(fr->bs->file, fr->offset, fr->bytes, @@ -456,11 +456,10 @@ blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileRe= q *fr) return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t by= tes, QEMUIOVector *qiov, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev, 0, fal= se); } diff --git a/block/blkreplay.c b/block/blkreplay.c index 2703a0c8c6..bc96bbd41e 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -69,8 +69,9 @@ static void block_request_create(uint64_t reqid, BlockDri= verState *bs, replay_block_event(req->bh, reqid); } =20 -static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); @@ -80,8 +81,9 @@ static int coroutine_fn blkreplay_co_preadv(BlockDriverSt= ate *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); diff --git a/block/block-backend.c b/block/block-backend.c index b4d2387947..146ef91547 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1289,6 +1289,7 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offs= et, int64_t bytes, IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); @@ -1363,6 +1364,7 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t off= set, int64_t bytes, IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); diff --git a/block/bochs.c b/block/bochs.c index 46e7958316..2f5ae52c90 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -237,7 +237,7 @@ static int64_t seek_to_sector(BlockDriverState *bs, int= 64_t sector_num) return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset)); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK bochs_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/commit.c b/block/commit.c index 41e3599281..10f6512e07 100644 --- a/block/commit.c +++ b/block/commit.c @@ -207,8 +207,9 @@ static const BlockJobDriver commit_job_driver =3D { }, }; =20 -static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_commit_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 61854beae2..e223e37300 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -78,9 +78,9 @@ typedef struct BDRVCopyBeforeWriteState { int snapshot_error; } BDRVCopyBeforeWriteState; =20 -static coroutine_fn int cbw_co_preadv( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } @@ -172,11 +172,9 @@ cbw_co_pwrite_zeroes(BlockDriverState *bs, int64_t off= set, int64_t bytes, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static coroutine_fn int cbw_co_pwritev(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static coroutine_fn GRAPH_RDLOCK +int cbw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, flags); if (ret < 0) { @@ -266,6 +264,8 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, BdrvChild *file; int ret; =20 + assume_graph_lock(); /* FIXME */ + /* TODO: upgrade to async loop using AioTask */ while (bytes) { int64_t cur_bytes; diff --git a/block/copy-on-read.c b/block/copy-on-read.c index ebf6864dd3..78da353f88 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -127,11 +127,10 @@ static int64_t coroutine_fn cor_co_getlength(BlockDri= verState *bs) } =20 =20 -static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { int64_t n; int local_flags; @@ -180,12 +179,10 @@ static int coroutine_fn cor_co_preadv_part(BlockDrive= rState *bs, } =20 =20 -static int coroutine_fn cor_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, flags); @@ -207,10 +204,9 @@ cor_co_pdiscard(BlockDriverState *bs, int64_t offset, = int64_t bytes) } =20 =20 -static int coroutine_fn cor_co_pwritev_compressed(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t by= tes, + QEMUIOVector *qiov) { return bdrv_co_pwritev(bs->file, offset, bytes, qiov, BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/crypto.c b/block/crypto.c index 8c0c245d11..2d24f336c2 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -398,7 +398,7 @@ static int block_crypto_reopen_prepare(BDRVReopenState = *state, */ #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -460,7 +460,7 @@ block_crypto_co_preadv(BlockDriverState *bs, int64_t of= fset, int64_t bytes, } =20 =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/filter-compress.c b/block/filter-compress.c index 7a632f47fe..0dd5606410 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -61,23 +61,20 @@ static int64_t coroutine_fn compress_co_getlength(Block= DriverState *bs) } =20 =20 -static int coroutine_fn compress_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset, flags); } =20 =20 -static int coroutine_fn compress_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t byt= es, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, flags | BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/io.c b/block/io.c index 484e068724..6f168a9a40 100644 --- a/block/io.c +++ b/block/io.c @@ -971,6 +971,7 @@ bdrv_driver_preadv(BlockDriverState *bs, int64_t offset= , int64_t bytes, unsigned int nb_sectors; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); assert(!(flags & ~bs->supported_read_flags)); @@ -1041,6 +1042,7 @@ bdrv_driver_pwritev(BlockDriverState *bs, int64_t off= set, int64_t bytes, unsigned int nb_sectors; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 @@ -1119,6 +1121,7 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = int64_t offset, BlockDriver *drv =3D bs->drv; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 @@ -1621,8 +1624,6 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, int ret; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - trace_bdrv_co_preadv_part(bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { @@ -2070,8 +2071,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, bool padded =3D false; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { diff --git a/block/mirror.c b/block/mirror.c index a6f4ec6282..ec5cd22a7c 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -390,8 +390,10 @@ static void coroutine_fn mirror_co_read(void *opaque) op->is_in_flight =3D true; trace_mirror_one_iteration(s, op->offset, op->bytes); =20 - ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->byte= s, - &op->qiov, 0); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->= bytes, + &op->qiov, 0); + } mirror_read_complete(op, ret); } =20 @@ -1437,8 +1439,9 @@ static void coroutine_fn active_write_settle(MirrorOp= *op) g_free(op); } =20 -static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } @@ -1495,8 +1498,9 @@ out: return ret; } =20 -static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, BdrvRequestFlags flags) { MirrorBDSOpaque *s =3D bs->opaque; QEMUIOVector bounce_qiov; @@ -1504,8 +1508,6 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, int ret =3D 0; bool copy_to_target =3D false; =20 - assume_graph_lock(); /* FIXME */ - if (s->job) { copy_to_target =3D s->job->ret >=3D 0 && !job_is_cancelled(&s->job->common.job) && diff --git a/block/parallels.c b/block/parallels.c index 2cf5061524..a7e9cad146 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -261,7 +261,8 @@ allocate_clusters(BlockDriverState *bs, int64_t sector_= num, } =20 =20 -static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_flush_to_os(BlockDriverState *bs) { BDRVParallelsState *s =3D bs->opaque; unsigned long size =3D DIV_ROUND_UP(s->header_size, s->bat_dirty_block= ); @@ -363,8 +364,9 @@ parallels_co_writev(BlockDriverState *bs, int64_t secto= r_num, int nb_sectors, return ret; } =20 -static coroutine_fn int parallels_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sector= s, + QEMUIOVector *qiov) { BDRVParallelsState *s =3D bs->opaque; uint64_t bytes_done =3D 0; diff --git a/block/preallocate.c b/block/preallocate.c index 91d73c81c6..63a296882d 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -226,9 +226,10 @@ static void preallocate_reopen_abort(BDRVReopenState *= state) state->opaque =3D NULL; } =20 -static coroutine_fn int preallocate_co_preadv_part( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t b= ytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset, flags); @@ -359,14 +360,11 @@ preallocate_co_pwrite_zeroes(BlockDriverState *bs, in= t64_t offset, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t = bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ handle_write(bs, offset, bytes, false); =20 return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, diff --git a/block/qcow.c b/block/qcow.c index 1e1d1792d0..58a0b4e2f0 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -92,8 +92,8 @@ typedef struct BDRVQcowState { =20 static QemuOptsList qcow_create_opts; =20 -static int coroutine_fn decompress_cluster(BlockDriverState *bs, - uint64_t cluster_offset); +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); =20 static int qcow_probe(const uint8_t *buf, int buf_size, const char *filena= me) { @@ -584,8 +584,8 @@ static int decompress_buffer(uint8_t *out_buf, int out_= buf_size, return 0; } =20 -static int coroutine_fn decompress_cluster(BlockDriverState *bs, - uint64_t cluster_offset) +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) { BDRVQcowState *s =3D bs->opaque; int ret, csize; diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a22607d90d..a9e6622fe3 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -534,10 +534,9 @@ do_perform_cow_read(BlockDriverState *bs, uint64_t src= _cluster_offset, return 0; } =20 -static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, - uint64_t cluster_offset, - unsigned offset_in_cluster, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_write(BlockDriverState *bs, uint64_t cluster_offset, + unsigned offset_in_cluster, QEMUIOVector *qiov) { BDRVQcow2State *s =3D bs->opaque; int ret; diff --git a/block/qcow2.c b/block/qcow2.c index 8f5ad75984..ddf9394bf0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -601,9 +601,9 @@ static void qcow2_add_check_result(BdrvCheckResult *out, } } =20 -static int coroutine_fn qcow2_co_check_locked(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_check_locked(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BdrvCheckResult snapshot_res =3D {}; BdrvCheckResult refcount_res =3D {}; @@ -640,9 +640,9 @@ static int coroutine_fn qcow2_co_check_locked(BlockDriv= erState *bs, return ret; } =20 -static int coroutine_fn qcow2_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_check(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BDRVQcow2State *s =3D bs->opaque; int ret; @@ -1294,9 +1294,9 @@ static int validate_compression_type(BDRVQcow2State *= s, Error **errp) } =20 /* Called with s->lock held. */ -static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, - int flags, bool open_data_file, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, + bool open_data_file, Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; @@ -1890,6 +1890,8 @@ 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 */ + qemu_co_mutex_lock(&s->lock); qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, qoc->errp); @@ -2169,7 +2171,7 @@ out: return ret; } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_encrypted(BlockDriverState *bs, uint64_t host_offset, uint64_t offset, @@ -2270,12 +2272,10 @@ static coroutine_fn int qcow2_add_task(BlockDriverS= tate *bs, return 0; } =20 -static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, - QCow2SubclusterType subc_type, - uint64_t host_offset, - uint64_t offset, uint64_t byt= es, - QEMUIOVector *qiov, - size_t qiov_offset) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type, + uint64_t host_offset, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset) { BDRVQcow2State *s =3D bs->opaque; =20 @@ -2314,7 +2314,11 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDr= iverState *bs, g_assert_not_reached(); } =20 -static coroutine_fn int qcow2_co_preadv_task_entry(AioTask *task) +/* + * This function can count as GRAPH_RDLOCK because qcow2_co_preadv_part() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_task_entry(AioTask *t= ask) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -2325,11 +2329,10 @@ static coroutine_fn int qcow2_co_preadv_task_entry(= AioTask *task) t->qiov, t->qiov_offset); } =20 -static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BDRVQcow2State *s =3D bs->opaque; int ret =3D 0; @@ -2774,8 +2777,8 @@ static void qcow2_close(BlockDriverState *bs) qcow2_do_close(bs, true); } =20 -static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; @@ -4737,7 +4740,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t l2_entry, uint64_t offset, diff --git a/block/qed-table.c b/block/qed-table.c index e9c72814c8..3b331ce709 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -21,8 +21,8 @@ #include "qemu/memalign.h" =20 /* Called with table_lock held. */ -static int coroutine_fn qed_read_table(BDRVQEDState *s, uint64_t offset, - QEDTable *table) +static int coroutine_fn GRAPH_RDLOCK +qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table) { unsigned int bytes =3D s->header.cluster_size * s->header.table_size; =20 diff --git a/block/qed.c b/block/qed.c index a4a74e59ef..c969b31e2c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -100,7 +100,7 @@ int qed_write_header_sync(BDRVQEDState *s) * * No new allocating reqs can start while this function runs. */ -static int coroutine_fn qed_write_header(BDRVQEDState *s) +static int coroutine_fn GRAPH_RDLOCK qed_write_header(BDRVQEDState *s) { /* We must write full sectors for O_DIRECT but cannot necessarily gene= rate * the data following the header if an unrecognized compat feature is @@ -826,11 +826,10 @@ fail: return ret; } =20 -static int coroutine_fn bdrv_qed_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t pos, int64_t byte= s, - int64_t *pnum, int64_t *m= ap, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_block_status(BlockDriverState *bs, bool want_zero, int64_t pos, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVQEDState *s =3D bs->opaque; size_t len =3D MIN(bytes, SIZE_MAX); @@ -883,8 +882,8 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb) * This function reads qiov->size bytes starting at pos from the backing f= ile. * If there is no backing file then zeroes are read. */ -static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t po= s, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +qed_read_backing_file(BDRVQEDState *s, uint64_t pos, QEMUIOVector *qiov) { if (s->bs->backing) { BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); @@ -902,9 +901,9 @@ static int coroutine_fn qed_read_backing_file(BDRVQEDSt= ate *s, uint64_t pos, * @len: Number of bytes * @offset: Byte offset in image file */ -static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s, - uint64_t pos, uint64_t = len, - uint64_t offset) +static int coroutine_fn GRAPH_RDLOCK +qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, uint64_t len, + uint64_t offset) { QEMUIOVector qiov; int ret; @@ -1066,7 +1065,7 @@ qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offse= t) * * Called with table_lock *not* held. */ -static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_main(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + @@ -1226,8 +1225,8 @@ qed_aio_write_alloc(QEDAIOCB *acb, size_t len) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offs= et, - size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); int r; @@ -1302,8 +1301,8 @@ qed_aio_write_data(void *opaque, int ret, uint64_t of= fset, size_t len) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_read_data(void *opaque, int ret, - uint64_t offset, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); diff --git a/block/quorum.c b/block/quorum.c index ef6cda2868..d58f86d3a5 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -270,7 +270,11 @@ static void quorum_report_bad_versions(BDRVQuorumState= *s, } } =20 -static void coroutine_fn quorum_rewrite_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because read_quorum_children() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK quorum_rewrite_entry(void *opaque) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -290,8 +294,8 @@ static void coroutine_fn quorum_rewrite_entry(void *opa= que) } } =20 -static bool quorum_rewrite_bad_versions(QuorumAIOCB *acb, - QuorumVoteValue *value) +static bool coroutine_fn GRAPH_RDLOCK +quorum_rewrite_bad_versions(QuorumAIOCB *acb, QuorumVoteValue *value) { QuorumVoteVersion *version; QuorumVoteItem *item; @@ -491,7 +495,7 @@ static int quorum_vote_error(QuorumAIOCB *acb) return ret; } =20 -static void quorum_vote(QuorumAIOCB *acb) +static void coroutine_fn GRAPH_RDLOCK quorum_vote(QuorumAIOCB *acb) { bool quorum =3D true; int i, j, ret; @@ -571,7 +575,11 @@ free_exit: quorum_free_vote_list(&acb->votes); } =20 -static void coroutine_fn read_quorum_children_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because read_quorum_children() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK read_quorum_children_entry(void *opa= que) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -599,7 +607,7 @@ static void coroutine_fn read_quorum_children_entry(voi= d *opaque) } } =20 -static int coroutine_fn read_quorum_children(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_quorum_children(QuorumAIOCB *acb) { BDRVQuorumState *s =3D acb->bs->opaque; int i; @@ -640,7 +648,7 @@ static int coroutine_fn read_quorum_children(QuorumAIOC= B *acb) return acb->vote_ret; } =20 -static int coroutine_fn read_fifo_child(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_fifo_child(QuorumAIOCB *acb) { BDRVQuorumState *s =3D acb->bs->opaque; int n, ret; @@ -661,10 +669,9 @@ static int coroutine_fn read_fifo_child(QuorumAIOCB *a= cb) return ret; } =20 -static int coroutine_fn quorum_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQuorumState *s =3D bs->opaque; QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); diff --git a/block/raw-format.c b/block/raw-format.c index 007d7f6e42..92adf97ab0 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -203,9 +203,9 @@ static inline int raw_adjust_offset(BlockDriverState *b= s, int64_t *offset, return 0; } =20 -static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret; =20 @@ -218,9 +218,9 @@ static int coroutine_fn raw_co_preadv(BlockDriverState = *bs, int64_t offset, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offse= t, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { void *buf =3D NULL; BlockDriver *drv; diff --git a/block/replication.c b/block/replication.c index a27417d310..f9f899bfc8 100644 --- a/block/replication.c +++ b/block/replication.c @@ -220,10 +220,9 @@ static int replication_return_value(BDRVReplicationSta= te *s, int ret) return ret; } =20 -static coroutine_fn int replication_co_readv(BlockDriverState *bs, - int64_t sector_num, - int remaining_sectors, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +replication_co_readv(BlockDriverState *bs, int64_t sector_num, + int remaining_sectors, QEMUIOVector *qiov) { BDRVReplicationState *s =3D bs->opaque; int ret; @@ -244,11 +243,9 @@ static coroutine_fn int replication_co_readv(BlockDriv= erState *bs, return replication_return_value(s, ret); } =20 -static coroutine_fn int replication_co_writev(BlockDriverState *bs, - int64_t sector_num, - int remaining_sectors, - QEMUIOVector *qiov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +replication_co_writev(BlockDriverState *bs, int64_t sector_num, + int remaining_sectors, QEMUIOVector *qiov, int flags) { BDRVReplicationState *s =3D bs->opaque; QEMUIOVector hd_qiov; diff --git a/block/throttle.c b/block/throttle.c index 3db4fa3c40..5cfea3d5f8 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -111,10 +111,9 @@ static int64_t coroutine_fn throttle_co_getlength(Bloc= kDriverState *bs) return bdrv_co_getlength(bs->file->bs); } =20 -static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { =20 ThrottleGroupMember *tgm =3D bs->opaque; @@ -123,10 +122,9 @@ static int coroutine_fn throttle_co_preadv(BlockDriver= State *bs, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); @@ -153,10 +151,9 @@ throttle_co_pdiscard(BlockDriverState *bs, int64_t off= set, int64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int coroutine_fn throttle_co_pwritev_compressed(BlockDriverState *b= s, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, + int64_t bytes, QEMUIOVector *qiov) { return throttle_co_pwritev(bs, offset, bytes, qiov, BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/vdi.c b/block/vdi.c index 27db67d493..b50c0b7277 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -544,7 +544,7 @@ static int coroutine_fn vdi_co_block_status(BlockDriver= State *bs, (s->header.image_type =3D=3D VDI_TYPE_STATIC ? BDRV_BLOCK_RECURSE = : 0); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vdi_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -600,7 +600,7 @@ vdi_co_preadv(BlockDriverState *bs, int64_t offset, int= 64_t bytes, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/vhdx.c b/block/vhdx.c index 59fbdb413b..ffa4455e82 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1172,8 +1172,9 @@ vhdx_co_get_info(BlockDriverState *bs, BlockDriverInf= o *bdi) } =20 =20 -static coroutine_fn int vhdx_co_readv(BlockDriverState *bs, int64_t sector= _num, - int nb_sectors, QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov) { BDRVVHDXState *s =3D bs->opaque; int ret =3D 0; @@ -1324,9 +1325,9 @@ int vhdx_user_visible_write(BlockDriverState *bs, BDR= VVHDXState *s) return ret; } =20 -static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t secto= r_num, - int nb_sectors, QEMUIOVector *qiov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov, int flags) { int ret =3D -ENOTSUP; BDRVVHDXState *s =3D bs->opaque; diff --git a/block/vmdk.c b/block/vmdk.c index 8b844300f4..c601ca85f4 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1403,13 +1403,11 @@ static void vmdk_refresh_limits(BlockDriverState *b= s, Error **errp) * [@skip_start_sector, @skip_end_sector) is not copied or written, and le= ave * it for call to write user data in the request. */ -static int coroutine_fn get_whole_cluster(BlockDriverState *bs, - VmdkExtent *extent, - uint64_t cluster_offset, - uint64_t offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes, - bool zeroed) +static int coroutine_fn GRAPH_RDLOCK +get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent, + uint64_t cluster_offset, uint64_t offset, + uint64_t skip_start_bytes, uint64_t skip_end_bytes, + bool zeroed) { int ret =3D VMDK_OK; int64_t cluster_bytes; @@ -1536,14 +1534,11 @@ vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_d= ata, uint32_t offset) * VMDK_UNALLOC if cluster is not mapped and @allocate is false. * VMDK_ERROR if failed. */ -static int coroutine_fn get_cluster_offset(BlockDriverState *bs, - VmdkExtent *extent, - VmdkMetaData *m_data, - uint64_t offset, - bool allocate, - uint64_t *cluster_offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) +static int coroutine_fn GRAPH_RDLOCK +get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, + VmdkMetaData *m_data, uint64_t offset, bool allocate, + uint64_t *cluster_offset, uint64_t skip_start_bytes, + uint64_t skip_end_bytes) { unsigned int l1_index, l2_offset, l2_index; int min_index, i, j; @@ -1736,11 +1731,10 @@ static inline uint64_t vmdk_find_offset_in_cluster(= VmdkExtent *extent, return extent_relative_offset % cluster_size; } =20 -static int coroutine_fn vmdk_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { BDRVVmdkState *s =3D bs->opaque; int64_t index_in_cluster, n, ret; @@ -1785,7 +1779,7 @@ static int coroutine_fn vmdk_co_block_status(BlockDri= verState *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, uint64_t qiov_offset, uint64_t n_bytes, @@ -1867,10 +1861,9 @@ vmdk_write_extent(VmdkExtent *extent, int64_t cluste= r_offset, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, - int64_t offset_in_cluster, QEMUIOVector *qiov, - int bytes) + int64_t offset_in_cluster, QEMUIOVector *qiov, int bytes) { int ret; int cluster_bytes, buf_bytes; @@ -1934,7 +1927,7 @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_= offset, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -2016,9 +2009,9 @@ fail: * * Returns: error code with 0 for success. */ -static int coroutine_fn vmdk_pwritev(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, QEMUIOVector *qiov, - bool zeroed, bool zero_dry_run) +static int coroutine_fn GRAPH_RDLOCK +vmdk_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, bool zeroed, bool zero_dry_run) { BDRVVmdkState *s =3D bs->opaque; VmdkExtent *extent =3D NULL; @@ -2028,8 +2021,6 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, uint64_t bytes_done =3D 0; VmdkMetaData m_data; =20 - assume_graph_lock(); /* FIXME */ - if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 " total_sectors=3D0x%" PRIx64, @@ -2116,7 +2107,7 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -2156,10 +2147,9 @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int= 64_t offset, int64_t bytes, return vmdk_co_pwritev(bs, offset, bytes, qiov, 0); } =20 -static int coroutine_fn vmdk_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; BDRVVmdkState *s =3D bs->opaque; @@ -2920,9 +2910,8 @@ static VmdkExtentInfo *vmdk_get_extent_info(VmdkExten= t *extent) return info; } =20 -static int coroutine_fn vmdk_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_check(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode= fix) { BDRVVmdkState *s =3D bs->opaque; VmdkExtent *extent =3D NULL; diff --git a/block/vpc.c b/block/vpc.c index 3c256fc5a4..1f0f26c0c4 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -610,7 +610,7 @@ vpc_co_get_info(BlockDriverState *bs, BlockDriverInfo *= bdi) return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vpc_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -660,7 +660,7 @@ fail: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vpc_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 4fed8b751f..d9d3807062 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -933,10 +933,9 @@ static void bdrv_test_top_close(BlockDriverState *bs) } } =20 -static int coroutine_fn bdrv_test_top_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_test_top_co_preadv(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVTestTopState *tts =3D bs->opaque; return bdrv_co_preadv(tts->wait_child, offset, bytes, qiov, flags); @@ -967,6 +966,8 @@ static void coroutine_fn test_co_delete_by_drain(void *= opaque) void *buffer =3D g_malloc(65536); QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buffer, 65536); =20 + GRAPH_RDLOCK_GUARD(); + /* Pretend some internal write operation from parent to child. * Important: We have to read from the child, not from the parent! * Draining works by first propagating it all up the tree to the @@ -1698,11 +1699,9 @@ static void bdrv_replace_test_close(BlockDriverState= *bs) * Otherwise: * Set .has_read to true and return success. */ -static int coroutine_fn bdrv_replace_test_co_preadv(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_replace_test_co_preadv(BlockDriverState *bs, int64_t offset, int64_t = bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVReplaceTestState *s =3D bs->opaque; =20 @@ -1778,7 +1777,10 @@ static void coroutine_fn bdrv_replace_test_read_entr= y(void *opaque) int ret; =20 /* Queue a read request post-drain */ + bdrv_graph_co_rdlock(); ret =3D bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0); + bdrv_graph_co_rdunlock(); + g_assert(ret >=3D 0); bdrv_dec_in_flight(bs); } --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437871; cv=none; d=zohomail.com; s=zohoarc; b=JaUDIoQj/nGw9PdhHev96EGjxwHR0ycT3pnAg5CJ6s01EHbwGy1Nlc5fZB+2W/ChOPaLR67BFwiS0+FPH89AkNLIQ/mhV2MaLBpsF8skjCIC2KmQ71phTp2GqHbVVmcjpvKE4b9pGGmPsdv6J4maM5j/79LnNEXGQajEPPb1pd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437871; 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=L7ZI2aujUC4UCT+sBJYSVYKATE/NFLvwnUKjUfTMmVc=; b=FY4OqpTR60SpEfvceuJohtNSVACIb6Xxdroi7qDHVEg2cJw5UBTjmt8y5262D12ter7bgJGtcWf2/MffPdwU5RDrSYYboB+JtFolZhFP5jpFCr0aDN7fGh8xXfyhfy3vfqlbrt4m4QysJxknqWDN/KdY9Al+8yOfkQ+1stxQS4A= 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+importer2=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 1675437871727706.8019214171037; Fri, 3 Feb 2023 07:24:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtu-0007Oq-Ld; Fri, 03 Feb 2023 10:22:54 -0500 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 1pNxts-0007OM-P4 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:52 -0500 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 1pNxtr-0005JT-6u for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:52 -0500 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-564-RmRmW9kKOgyG78KDOBnlGw-1; Fri, 03 Feb 2023 10:22:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B94C811E9C; Fri, 3 Feb 2023 15:22:48 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 301E6404CD80; Fri, 3 Feb 2023 15:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437770; 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=L7ZI2aujUC4UCT+sBJYSVYKATE/NFLvwnUKjUfTMmVc=; b=Zhi/ne22NXpXA3z1NPLbNRN9XUF2H+jXdoy/nTV+2Jt5llarBV68lE+0CRAHU8bf+AoHiA 7ip4DrW6yTsJVDLkpkcOIV3oidP002oa+yY/2bvI4BsNJDJ7GF6rRw48se8G34Bt520X2N O0uvAx8KcePClReZxW99o8yjSC9XjA8= X-MC-Unique: RmRmW9kKOgyG78KDOBnlGw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 12/23] block: Mark bdrv_co_pwrite_sync() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:51 +0100 Message-Id: <20230203152202.49054-13-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437873292100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_sync() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/qcow2.h | 2 +- include/block/block-io.h | 7 ++++--- block/io.c | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 7487bcfcf9..c59e33c01c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -893,7 +893,7 @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, Bdrv= CheckResult *res, int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, BlockDriverAmendStatusCB *status_cb, void *cb_opaque, Error **errp); -int coroutine_fn qcow2_shrink_reftable(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs); int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs); =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index ec26f07d60..bbe8a5659a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -60,9 +60,10 @@ int co_wrapper_mixed_bdrv_rdlock bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); =20 -int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); + /* * Efficiently zero a region of the disk image. Note that this is a regul= ar * I/O request like read or write and should have a reasonable size. This diff --git a/block/io.c b/block/io.c index 6f168a9a40..4ea19a37e6 100644 --- a/block/io.c +++ b/block/io.c @@ -933,8 +933,7 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, = int64_t offset, { int ret; IO_CODE(); - - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); =20 ret =3D bdrv_co_pwrite(child, offset, bytes, buf, flags); if (ret < 0) { --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437802; cv=none; d=zohomail.com; s=zohoarc; b=RtZCAXdMJU11zGxGynzSi22lg1EoiwG+FUasEy6srDh/sOz5VoyUxzcu//TJKlTgZmqu6SK0Bb491WdK12Rr/8Htqoy0FKfCyscLFD8DX8b2h5fXiRW3L4oMNoKsTWiyH/PwQxZ3q5ONHpTl7lsnV0NlpFD5j1YtzY2lCg+xeqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437802; 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=kzJ8rIuji1hnzfubuOBI027OVgOScYqVBiGjwb67HZ0=; b=EozOhT0WfJAFA1+fueIbuUGk+AgIq64GI1M9SvUh4YpSRQdqO379zqTTdOPHNCYzBRfER75r96cKjI/zLrAl042fmZauiuYFHD5kngW1flm1CvfLYb+5lZgacrXN2Oqozpa6r/1Gc/9fechs3kJE5b685lL5VZGfnfmNanOyD6Q= 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+importer2=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 1675437802261931.4990097389837; Fri, 3 Feb 2023 07:23:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxtz-0007Ru-NP; Fri, 03 Feb 2023 10:22:59 -0500 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 1pNxty-0007RL-EP for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:58 -0500 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 1pNxtw-0005LK-O5 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:22:57 -0500 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-166-FhkYfJqvPMeSUsQi8bRfew-1; Fri, 03 Feb 2023 10:22:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3809318E0AC4; Fri, 3 Feb 2023 15:22:54 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63C32404CD80; Fri, 3 Feb 2023 15:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437776; 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=kzJ8rIuji1hnzfubuOBI027OVgOScYqVBiGjwb67HZ0=; b=WfL/TrKWWVCS7zKZ9LVfuHkpAYgp1TflvehK38DLBBU7znrEto1j5O8dDrW9i7YHBT2Xf1 D/6C4PH6Uu+MNW2M2vwREEs0hdzHvgAAbHTLuS4+/ZLXumyEXHMvcEDj65CoMehpqGUK0q /HkLFU3YllOhUcJ2xwMx6CLcpUop55A= X-MC-Unique: FhkYfJqvPMeSUsQi8bRfew-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 13/23] block: Mark bdrv_co_do_pwrite_zeroes() GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:52 +0100 Message-Id: <20230203152202.49054-14-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437804296100011 Content-Type: text/plain; charset="utf-8" All callers are already GRAPH_RDLOCK, so just add the annotation and remove assume_graph_lock(). Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- block/io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/io.c b/block/io.c index 4ea19a37e6..a56e565b12 100644 --- a/block/io.c +++ b/block/io.c @@ -1672,8 +1672,9 @@ fail: return ret; } =20 -static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t byt= es, + BdrvRequestFlags flags) { BlockDriver *drv =3D bs->drv; QEMUIOVector qiov; @@ -1683,8 +1684,6 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, int head =3D 0; int tail =3D 0; =20 - assume_graph_lock(); /* FIXME */ - int64_t max_write_zeroes =3D MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT64_MAX); int alignment =3D MAX(bs->bl.pwrite_zeroes_alignment, --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438008; cv=none; d=zohomail.com; s=zohoarc; b=MkxzSvV3wUwsugzIjjz5BXauz1LvKhK5iqU6ps8TGbeGW/x0vNxcgDMG5gEgKx9foAS9o7xCBTCx+7rJM66na4nchDqa/zskpPHYogAT7J/HnNKr5kQqjjJIYJw8dMpCE83XJntE7CzUA/x6dKE4JAiz27/0rctEPCawwBXWPms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438008; 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=EH+7Hq7DlBviiyJzr3E1dGvYTqlIAtdXFSDO3noMALQ=; b=O6X9SKQN7/SyxuDFqGnTqNvXweObcDmZlb/0yu3cIlG/b3hphHmtsIORJTgUhcECWvsfqg4CDVFkT1T7qljj0Ym3ghD+dW2rwzh3RLRAJLFBrTNjqvk9wdzXGrsIVawJC5sILmNfaeOyjX2pWqoJ6Tu5cPiwCM5ouRwj65+GkRA= 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+importer2=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 1675438008583185.28601436559995; Fri, 3 Feb 2023 07:26:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu4-0007XG-E4; Fri, 03 Feb 2023 10:23:04 -0500 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 1pNxu1-0007T6-N8 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:01 -0500 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 1pNxtz-0005ML-Mu for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:01 -0500 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-346-NZ-jM4-LNE-1IExE-RqNhA-1; Fri, 03 Feb 2023 10:22:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DA3985D062; Fri, 3 Feb 2023 15:22:55 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71090410B1AD; Fri, 3 Feb 2023 15:22:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437779; 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=EH+7Hq7DlBviiyJzr3E1dGvYTqlIAtdXFSDO3noMALQ=; b=fi/4f3aheUudZdfcxoYgUk3wvCOCq8mzUaounvV4WoVZMEwc0yUscK7u/q7gJ8Huz0R8R1 KApPb4CYCmO7OL0k0128NCxIOh0VyuyOtilQ7iBe6nKqwpZWyXhzAD5Hbmc9ZEKM9Wa9Vp iqPxP46XH7XKWhXtoRATUgYkdSFibxc= X-MC-Unique: NZ-jM4-LNE-1IExE-RqNhA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 14/23] block: Mark bdrv_co_copy_range() GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:53 +0100 Message-Id: <20230203152202.49054-15-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438010122100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_copy_range() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 24 ++++++++---------------- include/block/block_int-io.h | 20 ++++++++++---------- block/block-backend.c | 2 ++ block/file-posix.c | 16 +++++++--------- block/io.c | 7 +++++-- block/iscsi.c | 28 ++++++++++++---------------- block/qcow2.c | 5 ++--- block/raw-format.c | 28 ++++++++++++---------------- qemu-img.c | 4 +++- 10 files changed, 66 insertions(+), 77 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index bbe8a5659a..c551742a86 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -274,10 +274,11 @@ bool co_wrapper bdrv_can_store_new_dirty_bitmap(Block= DriverState *bs, * * Returns: 0 if succeeded; negative error code if failed. **/ -int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, - BdrvChild *dst, int64_t dst_offset, - int64_t bytes, BdrvRequestFlags read_f= lags, - BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 /* * "I/O or GS" API functions. These functions can run without diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 192841f040..29b230cc0b 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -559,14 +559,10 @@ struct BlockDriver { * See the comment of bdrv_co_copy_range for the parameter and return = value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_from)(BlockDriverState *bs, - BdrvChild *src, - int64_t offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flag= s, - BdrvRequestFlags write_fla= gs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_from)( + BlockDriverState *bs, BdrvChild *src, int64_t offset, + BdrvChild *dst, int64_t dst_offset, int64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 /* * Map [offset, offset + nbytes) range onto a child of bs to copy data= to, @@ -577,14 +573,10 @@ struct BlockDriver { * See the comment of bdrv_co_copy_range for the parameter and return = value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_to)(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags= ); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_to)( + BlockDriverState *bs, BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, int64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 /* * Building block for bdrv_block_status[_above] and diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 34d4b0fb8e..5788bd66ba 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -113,16 +113,16 @@ void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap= *dest, void bdrv_inc_in_flight(BlockDriverState *bs); void bdrv_dec_in_flight(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offse= t, - BdrvChild *dst, int64_t dst_offse= t, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags); -int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, - BdrvChild *dst, int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint); diff --git a/block/block-backend.c b/block/block-backend.c index 146ef91547..fdb1e1d5f7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2644,6 +2644,8 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, if (r) { return r; } + + GRAPH_RDLOCK_GUARD(); return bdrv_co_copy_range(blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags); diff --git a/block/file-posix.c b/block/file-posix.c index 7481ccddb6..bdb8a56c9e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3272,7 +3272,7 @@ static void raw_abort_perm_update(BlockDriverState *b= s) raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL); } =20 -static int coroutine_fn raw_co_copy_range_from( +static int coroutine_fn GRAPH_RDLOCK raw_co_copy_range_from( BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) @@ -3281,14 +3281,12 @@ static int coroutine_fn raw_co_copy_range_from( read_flags, write_flags); } =20 -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { RawPosixAIOData acb; BDRVRawState *s =3D bs->opaque; diff --git a/block/io.c b/block/io.c index a56e565b12..b060561929 100644 --- a/block/io.c +++ b/block/io.c @@ -3243,6 +3243,7 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_ran= ge_internal( { BdrvTrackedRequest req; int ret; + assert_bdrv_graph_readable(); =20 /* TODO We can support BDRV_REQ_NO_FALLBACK here */ assert(!(read_flags & BDRV_REQ_NO_FALLBACK)); @@ -3324,7 +3325,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3342,7 +3343,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3355,6 +3356,8 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, i= nt64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assert_bdrv_graph_readable(); + return bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); diff --git a/block/iscsi.c b/block/iscsi.c index b3e10f40b6..2aa5975543 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2186,14 +2186,12 @@ static void coroutine_fn iscsi_co_invalidate_cache(= BlockDriverState *bs, iscsi_allocmap_invalidate(iscsilun); } =20 -static int coroutine_fn iscsi_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_fla= gs, - BdrvRequestFlags write_fl= ags) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_from(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); @@ -2327,14 +2325,12 @@ static void iscsi_xcopy_data(struct iscsi_data *dat= a, src_lba, dst_lba); } =20 -static int coroutine_fn iscsi_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flag= s) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { IscsiLun *dst_lun =3D dst->bs->opaque; IscsiLun *src_lun; diff --git a/block/qcow2.c b/block/qcow2.c index ddf9394bf0..c318f41f38 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4065,7 +4065,7 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriver= State *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_from(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, @@ -4148,7 +4148,7 @@ out: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_to(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, @@ -4161,7 +4161,6 @@ qcow2_co_copy_range_to(BlockDriverState *bs, uint64_t host_offset; QCowL2Meta *l2meta =3D NULL; =20 - assume_graph_lock(); /* FIXME */ assert(!bs->encrypted); =20 qemu_co_mutex_lock(&s->lock); diff --git a/block/raw-format.c b/block/raw-format.c index 92adf97ab0..9913cb8174 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -536,14 +536,12 @@ static int raw_probe_geometry(BlockDriverState *bs, H= DGeometry *geo) return bdrv_probe_geometry(bs->file->bs, geo); } =20 -static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flag= s) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_from(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int ret; =20 @@ -555,14 +553,12 @@ static int coroutine_fn raw_co_copy_range_from(BlockD= riverState *bs, bytes, read_flags, write_flags); } =20 -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int ret; =20 diff --git a/qemu-img.c b/qemu-img.c index cd0178b51b..9aeac69fa6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2041,7 +2041,9 @@ retry: =20 if (s->ret =3D=3D -EINPROGRESS) { if (copy_range) { - ret =3D convert_co_copy_range(s, sector_num, n); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D convert_co_copy_range(s, sector_num, n); + } if (ret) { s->copy_range =3D false; goto retry; --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437866; cv=none; d=zohomail.com; s=zohoarc; b=R6+gKniNZsGFnoGXulrJU2nwxIGg+RKUcUKOixxc4YcsDdvjnCKg3ovvb5PbQdS3Ctl2qmKm3nVSorH09KViYqox2ROxLnuNDN+GVmGh3TUOZakqK80mup6Q/i4LqlyBK7uxFimo43NZ9UTq/kiFTO4mQuKao74ZtFA844QXBM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437866; 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=zPk/4BOJ/3Wh4Y9blY42T76M/VfDyqYsvQ0LzP9DTNU=; b=NaGGnPjenwm53O7dzNSibPhCWQ3inpJYmFiSCxRQ91xHHTfSG2A+fMQwcSqnnr0jAAqEqwkoLiesyw8Nj+YsXmZmHAsTcIfWV4ICWMdMOPNRmawTbzzn+UDBmREitn0jjl4OVd3APTvdv6/xbM6UfUEBue7ms9pz9wjRw2lSUXw= 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+importer2=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 1675437866300281.37763041030246; Fri, 3 Feb 2023 07:24:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu2-0007U7-VQ; Fri, 03 Feb 2023 10:23:03 -0500 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 1pNxu1-0007SW-4q for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:01 -0500 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 1pNxty-0005MA-SS for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:00 -0500 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-194-g4yUAcN8NzmFQz3wjYIGEg-1; Fri, 03 Feb 2023 10:22:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DF06101A52E; Fri, 3 Feb 2023 15:22:56 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4F9740168BB; Fri, 3 Feb 2023 15:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437778; 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=zPk/4BOJ/3Wh4Y9blY42T76M/VfDyqYsvQ0LzP9DTNU=; b=iV2v2C+QrBNR6OOjuOMhsGFIRDn2EbJSmZLz4f1djZy4VrpsEhGB62XTOKTE3C3qtQcJc9 r1jY3Vh/nwnrxcIgOR6JWEloxPXHE2RESgTBtad8kU9zJHfodQ2Hj91UG+2iMT8tKF8gg8 v680UQgqV4jJpc1YIFiboBw9zHjIQ3U= X-MC-Unique: g4yUAcN8NzmFQz3wjYIGEg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 15/23] block: Mark preadv_snapshot/snapshot_block_status GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:54 +0100 Message-Id: <20230203152202.49054-16-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437867026100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block_int-common.h | 12 +++++++----- include/block/block_int-io.h | 8 ++++---- block/copy-before-write.c | 6 ++---- block/io.c | 2 ++ block/snapshot-access.c | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 29b230cc0b..7d8309ba5a 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -624,11 +624,13 @@ struct BlockDriver { * - receive the snapshot's actual length (which may differ from bs's * length) */ - int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_off= set); - int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, - bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, - int64_t *map, BlockDriverState **file); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_snapshot)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_snapshot_block_status)( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t byte= s, + int64_t *pnum, int64_t *map, BlockDriverState **file); =20 int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)( BlockDriverState *bs, int64_t offset, int64_t bytes); diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 5788bd66ba..612e5ddf99 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -35,11 +35,11 @@ * the I/O API. */ =20 -int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_snapshot(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); -int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, - bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, - int64_t *map, BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK bdrv_co_snapshot_block_status( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, BlockDriverState **file); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *= bs, int64_t offset, int64_t bytes); =20 diff --git a/block/copy-before-write.c b/block/copy-before-write.c index e223e37300..646d8227a4 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -256,7 +256,7 @@ cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq= *req) g_free(req); } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) { @@ -264,8 +264,6 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, BdrvChild *file; int ret; =20 - assume_graph_lock(); /* FIXME */ - /* TODO: upgrade to async loop using AioTask */ while (bytes) { int64_t cur_bytes; @@ -290,7 +288,7 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK cbw_co_snapshot_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/block/io.c b/block/io.c index b060561929..af9a0cc964 100644 --- a/block/io.c +++ b/block/io.c @@ -3529,6 +3529,7 @@ bdrv_co_preadv_snapshot(BdrvChild *child, int64_t off= set, int64_t bytes, BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; @@ -3554,6 +3555,7 @@ bdrv_co_snapshot_block_status(BlockDriverState *bs, BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; diff --git a/block/snapshot-access.c b/block/snapshot-access.c index 009cc4aea0..67ea339da9 100644 --- a/block/snapshot-access.c +++ b/block/snapshot-access.c @@ -26,7 +26,7 @@ #include "qemu/cutils.h" #include "block/block_int.h" =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, @@ -39,7 +39,7 @@ snapshot_access_co_preadv_part(BlockDriverState *bs, return bdrv_co_preadv_snapshot(bs->file, offset, bytes, qiov, qiov_off= set); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437991; cv=none; d=zohomail.com; s=zohoarc; b=PmKIX0gVSRq6vWotJX7Sx/2Y5a6y1b9tysPUMbf8DhjRwjYQEyD3mF80WOe3o1xY84kArQVMvX22ykUIMuuoS0avmTVekLIps/EpEGA6btc7vbMB1f0XyPA4uzJGagA6QPMJD9EIGIJm8HvWRP6MGly3R2A0Z9/dskj88qQCf74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437991; 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=/P7s5W59wEXVHr10reqP7AT+xBROjlfR67ZOWlKx3hc=; b=d9zrK1lN2QBJoNmHMAHd/ZetVQd21/bOCbLnCeGbWCi/EFAiWXRxHgGjFA6Ni57i/Y4eWxQGoczcc0Kit6nAo2E1oMJIweoa+rXx1Oy6ZEhlO/DY3KTjpUgg7aP9pkclZ79AnUuyG5oKCfAmLM6Pk6euxAFU0I2hzcumju7ahW8= 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+importer2=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 1675437991714184.98373653248404; Fri, 3 Feb 2023 07:26:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu7-0007bS-6X; Fri, 03 Feb 2023 10:23:07 -0500 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 1pNxu2-0007Tw-Ll for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:02 -0500 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 1pNxu0-0005MR-6N for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:02 -0500 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-533-ruP3GlaCNSyDzU9byVbThg-1; Fri, 03 Feb 2023 10:22:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1054101A52E; Fri, 3 Feb 2023 15:22:57 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7964404CD80; Fri, 3 Feb 2023 15:22:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437779; 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=/P7s5W59wEXVHr10reqP7AT+xBROjlfR67ZOWlKx3hc=; b=S/BE6vCR83DeWVykkxEIKuHSE1QM9JdcQDOl5igZE0TnodFPQpFuqq4klFbMKEN29NrwAW IX7bkCDDbexVe/q45N0pqMCmMoyurnfnAnhVbnjSdqrBY4njwO2vH8eldH98fXfD5cog20 3p1cZYVSXuppaZAzAPkH7smLVzrYrUo= X-MC-Unique: ruP3GlaCNSyDzU9byVbThg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 16/23] block: Mark bdrv_co_create() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:55 +0100 Message-Id: <20230203152202.49054-17-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437993989100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_create() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-global-state.h | 14 ++++--- include/block/block_int-common.h | 11 +++--- block.c | 1 + block/create.c | 9 ++++- block/crypto.c | 7 ++-- block/file-posix.c | 7 ++-- block/file-win32.c | 7 ++-- block/parallels.c | 7 ++-- block/qcow.c | 6 +-- block/qcow2.c | 7 ++-- block/qed.c | 7 ++-- block/raw-format.c | 7 ++-- block/vdi.c | 7 ++-- block/vhdx.c | 7 ++-- block/vmdk.c | 63 ++++++++++++++---------------- block/vpc.c | 7 ++-- 16 files changed, 84 insertions(+), 90 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 447176414e..399200a9a3 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -58,13 +58,15 @@ BlockDriver *bdrv_find_protocol(const char *filename, Error **errp); BlockDriver *bdrv_find_format(const char *format_name); =20 -int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, - QemuOpts *opts, Error **errp); -int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, - QemuOpts *opts, Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts, + Error **errp); =20 -int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, - Error **errp); +int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filen= ame, + QemuOpts *opts, Error **errp); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp); =20 BlockDriverState *bdrv_new(void); int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 7d8309ba5a..6b8fd22c71 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -246,12 +246,11 @@ struct BlockDriver { Error **errp); void (*bdrv_close)(BlockDriverState *bs); =20 - int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, - Error **errp); - int coroutine_fn (*bdrv_co_create_opts)(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( + BlockdevCreateOptions *opts, Error **errp); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)( + BlockDriver *drv, const char *filename, QemuOpts *opts, Error **er= rp); =20 int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts, diff --git a/block.c b/block.c index c2a8d66f75..b91f7658af 100644 --- a/block.c +++ b/block.c @@ -533,6 +533,7 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const= char *filename, int ret; GLOBAL_STATE_CODE(); ERRP_GUARD(); + assert_bdrv_graph_readable(); =20 if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", diff --git a/block/create.c b/block/create.c index 4df43f11f4..bf67b9947c 100644 --- a/block/create.c +++ b/block/create.c @@ -43,6 +43,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Err= or **errp) int ret; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD(); =20 job_progress_set_remaining(&s->common, 1); ret =3D s->drv->bdrv_co_create(s->opts, errp); @@ -59,6 +60,12 @@ static const JobDriver blockdev_create_job_driver =3D { .run =3D blockdev_create_run, }; =20 +/* Checking whether the function is present doesn't require the graph lock= */ +static inline bool TSA_NO_TSA has_bdrv_co_create(BlockDriver *drv) +{ + return drv->bdrv_co_create; +} + void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *option= s, Error **errp) { @@ -79,7 +86,7 @@ void qmp_blockdev_create(const char *job_id, BlockdevCrea= teOptions *options, } =20 /* Error out if the driver doesn't support .bdrv_co_create */ - if (!drv->bdrv_co_create) { + if (!has_bdrv_co_create(drv)) { error_setg(errp, "Driver does not support blockdev-create"); return; } diff --git a/block/crypto.c b/block/crypto.c index 2d24f336c2..28f870f33c 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -665,10 +665,9 @@ fail: return ret; } =20 -static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv, - const char *filen= ame, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { QCryptoBlockCreateOptions *create_opts =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/file-posix.c b/block/file-posix.c index bdb8a56c9e..6c6451c79f 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2607,10 +2607,9 @@ out: return result; } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions options; int64_t total_size =3D 0; diff --git a/block/file-win32.c b/block/file-win32.c index 200d244116..c7d0b85306 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -613,10 +613,9 @@ static int raw_co_create(BlockdevCreateOptions *option= s, Error **errp) return 0; } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions options; int64_t total_size =3D 0; diff --git a/block/parallels.c b/block/parallels.c index a7e9cad146..013684801a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -622,10 +622,9 @@ exit: goto out; } =20 -static int coroutine_fn parallels_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/qcow.c b/block/qcow.c index 58a0b4e2f0..490e4f819e 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -921,9 +921,9 @@ exit: return ret; } =20 -static int coroutine_fn qcow_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/qcow2.c b/block/qcow2.c index c318f41f38..30fd53fa64 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3816,10 +3816,9 @@ out: return ret; } =20 -static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opt= s, + Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/qed.c b/block/qed.c index c969b31e2c..ed94bb61ca 100644 --- a/block/qed.c +++ b/block/qed.c @@ -754,10 +754,9 @@ out: return ret; } =20 -static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/raw-format.c b/block/raw-format.c index 9913cb8174..646606e223 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -430,10 +430,9 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { return bdrv_co_create_file(filename, opts, errp); } diff --git a/block/vdi.c b/block/vdi.c index b50c0b7277..f2434d6153 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -898,10 +898,9 @@ static int coroutine_fn vdi_co_create(BlockdevCreateOp= tions *create_options, return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp); } =20 -static int coroutine_fn vdi_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vdi_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { QDict *qdict =3D NULL; BlockdevCreateOptions *create_options =3D NULL; diff --git a/block/vhdx.c b/block/vhdx.c index ffa4455e82..81420722a1 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2059,10 +2059,9 @@ delete_and_exit: return ret; } =20 -static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/vmdk.c b/block/vmdk.c index c601ca85f4..f5f49018fe 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2277,11 +2277,10 @@ exit: return ret; } =20 -static int coroutine_fn vmdk_create_extent(const char *filename, - int64_t filesize, bool flat, - bool compress, bool zeroed_grai= n, - BlockBackend **pbb, - QemuOpts *opts, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_create_extent(const char *filename, int64_t filesize, bool flat, + bool compress, bool zeroed_grain, BlockBackend **pbb, + QemuOpts *opts, Error **errp) { int ret; BlockBackend *blk =3D NULL; @@ -2359,14 +2358,10 @@ static int filename_decompose(const char *filename,= char *path, char *prefix, * non-split format. * idx >=3D 1: get the n-th extent if in a split subformat */ -typedef BlockBackend * coroutine_fn (*vmdk_create_extent_fn)(int64_t size, - int idx, - bool flat, - bool split, - bool compress, - bool zeroed_g= rain, - void *opaque, - Error **errp); +typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */ + (*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split, + bool compress, bool zeroed_grain, void *opaqu= e, + Error **errp); =20 static void vmdk_desc_add_extent(GString *desc, const char *extent_line_fmt, @@ -2379,17 +2374,18 @@ static void vmdk_desc_add_extent(GString *desc, g_free(basename); } =20 -static int coroutine_fn vmdk_co_do_create(int64_t size, - BlockdevVmdkSubformat subformat, - BlockdevVmdkAdapterType adapter_= type, - const char *backing_file, - const char *hw_version, - const char *toolsversion, - bool compat6, - bool zeroed_grain, - vmdk_create_extent_fn extent_fn, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_do_create(int64_t size, + BlockdevVmdkSubformat subformat, + BlockdevVmdkAdapterType adapter_type, + const char *backing_file, + const char *hw_version, + const char *toolsversion, + bool compat6, + bool zeroed_grain, + vmdk_create_extent_fn extent_fn, + void *opaque, + Error **errp) { int extent_idx; BlockBackend *blk =3D NULL; @@ -2609,10 +2605,10 @@ typedef struct { QemuOpts *opts; } VMDKCreateOptsData; =20 -static BlockBackend * coroutine_fn vmdk_co_create_opts_cb(int64_t size, in= t idx, - bool flat, bool split, bool co= mpress, - bool zeroed_grain, void *opaqu= e, - Error **errp) +static BlockBackend * coroutine_fn GRAPH_RDLOCK +vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split, + bool compress, bool zeroed_grain, void *opaque, + Error **errp) { BlockBackend *blk =3D NULL; BlockDriverState *bs =3D NULL; @@ -2651,10 +2647,9 @@ exit: return blk; } =20 -static int coroutine_fn vmdk_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { Error *local_err =3D NULL; char *desc =3D NULL; @@ -2814,8 +2809,8 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(= int64_t size, int idx, return blk; } =20 -static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_optio= ns, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsVmdk *opts; =20 diff --git a/block/vpc.c b/block/vpc.c index 1f0f26c0c4..b89b0ff8e2 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1087,10 +1087,9 @@ out: return ret; } =20 -static int coroutine_fn vpc_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vpc_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437824; cv=none; d=zohomail.com; s=zohoarc; b=b0o2JoynbPtJmSw+GLqojQc/kyie/mhvWeVzfgGSgJH4NNqTjU5hMMUmmyHiWYAOSQwcTgagT3YBIaDvZkSZtC7p+MGMaocEy2jdt3YRkeQlbYAAW41RXpXvn6oSTvMySr8pUVi1jTaPuIpY7MAwaFH96T8dZSivshqS/TwD7Yw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437824; 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=hsMoKc1kfwQocMh0gbn0IS4q5JFYNQlfuNfS04Ywu/Q=; b=FTwWXjo0MtjW3rclWLqHoqD2qGS46L0PbxQJMg8vo7m83mJ6DDvJq/LXwj9KLYXqtIeCEnAdFgUmgu5tWgQx3BDUAMz74XmP5BAz3H7MeQr8LuhHl/ZTEQGNlRjyDwHOpcaL31voqmdadgd7qHOiKwOTZZj4/yTqW0tK+Bkv9FM= 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+importer2=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 1675437824617153.00857468161269; Fri, 3 Feb 2023 07:23:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu6-0007b9-Fg; Fri, 03 Feb 2023 10:23:06 -0500 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 1pNxu3-0007VS-4V for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:03 -0500 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 1pNxu1-0005Mk-Ir for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:02 -0500 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-586-Gszzo2DhOJSP18aSplFf0w-1; Fri, 03 Feb 2023 10:22:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 10960101A52E; Fri, 3 Feb 2023 15:22:59 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15C9040C1073; Fri, 3 Feb 2023 15:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437780; 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=hsMoKc1kfwQocMh0gbn0IS4q5JFYNQlfuNfS04Ywu/Q=; b=FF9m7rsjX+KcpsfzG1CPWihsnwOHkJR/lbwwFEQ+hH4nsF3O3biShVhTbO73DyLAeXB8Ic SlFRUqWNNGpgyU0teCPECXcTbJ4etxTh9BJICXF6sXEKvxuPO0Fz27fPLHRWNN543SxTYk tgqhuE1y7kyStX46TYnZ1Wr3z1VcsxA= X-MC-Unique: Gszzo2DhOJSP18aSplFf0w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 17/23] block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:56 +0100 Message-Id: <20230203152202.49054-18-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437826399100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_io_plug() and bdrv_co_io_unplug() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 5 +++-- block/block-backend.c | 2 ++ block/io.c | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index c551742a86..b8f99741a3 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -233,8 +233,8 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, A= ioContext *old_ctx); =20 AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c); =20 -void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs); -void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); =20 bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6b8fd22c71..61f894bcf6 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -735,8 +735,9 @@ struct BlockDriver { BlkdebugEvent event); =20 /* io queue for linux-aio */ - void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); - void coroutine_fn (*bdrv_co_io_unplug)(BlockDriverState *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_plug)(BlockDriverState= *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_unplug)( + BlockDriverState *bs); =20 /** * bdrv_drain_begin is called if implemented in the beginning of a diff --git a/block/block-backend.c b/block/block-backend.c index fdb1e1d5f7..3661a066b3 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2328,6 +2328,7 @@ void coroutine_fn blk_co_io_plug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_io_plug(bs); @@ -2338,6 +2339,7 @@ void coroutine_fn blk_co_io_unplug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_io_unplug(bs); diff --git a/block/io.c b/block/io.c index af9a0cc964..be350aba98 100644 --- a/block/io.c +++ b/block/io.c @@ -3150,6 +3150,7 @@ void coroutine_fn bdrv_co_io_plug(BlockDriverState *b= s) { BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 QLIST_FOREACH(child, &bs->children, next) { bdrv_co_io_plug(child->bs); @@ -3167,6 +3168,7 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverState = *bs) { BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 assert(bs->io_plugged); if (qatomic_fetch_dec(&bs->io_plugged) =3D=3D 1) { --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438033; cv=none; d=zohomail.com; s=zohoarc; b=cvB/6D9QlL+dAHRZ1fOV9MKi5f+MFeE3iaHOrLDn43ksw7lp0UcmYGNphsPsf34Xeb8UFqeGFkEvA4wpOrZw2PuC5zbT85HzG3KL4vF4Z8SoR+RqIIz14isFkS5Hc9CqpVIzjhBk33lPAVncNrGgosHsgBRU1nYKo7WVP7uXtJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438033; 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=ay6AlvhlYXQzTZqnIJii1z7Wwzb8APYKuAXK3Nxv3RI=; b=nA4pRh9XCANk0Hym5mKRpNKuQF5az8oNq46TsQoHTvFPbIVrqbCP7brK31D1REXmxrrJk5Cz15nhLbJN7bS0xPSwYng5ORs7ourzxVZDZYlKI4posiXiO04617gk6OLchxTu8ZfSKDvjTdoN8zr+9S3edEDTfZR13yvIj0IW+BI= 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+importer2=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 1675438033414159.20442303023992; Fri, 3 Feb 2023 07:27:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu7-0007ci-T0; Fri, 03 Feb 2023 10:23:07 -0500 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 1pNxu4-0007Wy-AQ for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:04 -0500 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 1pNxu2-0005NC-E0 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:04 -0500 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-624-8VVaUU63P9O_VuFe9rlNxw-1; Fri, 03 Feb 2023 10:23:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 421BD185A7A4; Fri, 3 Feb 2023 15:23:00 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 485FD410B1AD; Fri, 3 Feb 2023 15:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437781; 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=ay6AlvhlYXQzTZqnIJii1z7Wwzb8APYKuAXK3Nxv3RI=; b=c9teZGnafUpc0Y1wGMlEOAKMRLkkLnIU7WzVRfcHRm7Avh33q9r433o1IXZzR6OEtpufsM 08vBwvCGLaEV3PJn14ZYZE/APVm613mUQ6SgQ9yaCRj7a9o69qSbJJn4tesK7goii4hnVI 85P1WJGzlJbo2Fe5NpNVi/QouIz+lAU= X-MC-Unique: 8VVaUU63P9O_VuFe9rlNxw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 18/23] block: Mark bdrv_co_is_inserted() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:57 +0100 Message-Id: <20230203152202.49054-19-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438034428100003 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_is_inserted() need to hold a reader lock for the graph. blk_is_inserted() is done as a co_wrapper_mixed_bdrv_rdlock (unlike most other blk_* functions) because it is called a lot from other blk_co_*() functions that already hold the lock. These calls go through blk_is_available(), which becomes a co_wrapper_mixed_bdrv_rdlock, too, for the same reason. Functions that run in a coroutine and can call bdrv_co_is_available() directly are changed to do so, which results in better TSA coverage. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 3 ++- include/sysemu/block-backend-io.h | 7 ++++--- block.c | 1 + block/block-backend.c | 25 ++++++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index b8f99741a3..88db63492a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -145,8 +145,8 @@ bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); int bdrv_get_flags(BlockDriverState *bs); =20 -bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs); -bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); +bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); +bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); =20 void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 61f894bcf6..b4a82269e5 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -712,7 +712,8 @@ struct BlockDriver { BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 /* removable device specific */ - bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( + BlockDriverState *bs); void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); =20 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index b1196ab93c..40ab178719 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -55,10 +55,11 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned l= ong int req, void *buf, void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); =20 -bool coroutine_fn blk_co_is_inserted(BlockBackend *blk); -bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk); =20 -bool blk_is_available(BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk); =20 void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked); void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked); diff --git a/block.c b/block.c index b91f7658af..0b66995a4b 100644 --- a/block.c +++ b/block.c @@ -6803,6 +6803,7 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverStat= e *bs) BlockDriver *drv =3D bs->drv; BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return false; diff --git a/block/block-backend.c b/block/block-backend.c index 3661a066b3..20af699f00 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1235,8 +1235,8 @@ void blk_set_disable_request_queuing(BlockBackend *bl= k, bool disable) blk->disable_request_queuing =3D disable; } =20 -static coroutine_fn int blk_check_byte_request(BlockBackend *blk, - int64_t offset, int64_t byt= es) +static int coroutine_fn GRAPH_RDLOCK +blk_check_byte_request(BlockBackend *blk, int64_t offset, int64_t bytes) { int64_t len; =20 @@ -1244,7 +1244,7 @@ static coroutine_fn int blk_check_byte_request(BlockB= ackend *blk, return -EIO; } =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1606,8 +1606,9 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, = int64_t offset, int64_t coroutine_fn blk_co_getlength(BlockBackend *blk) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1627,8 +1628,9 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb= _sectors_ptr) int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1676,7 +1678,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int = req, void *buf) blk_wait_while_drained(blk); GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1769,7 +1771,7 @@ static int coroutine_fn blk_co_do_flush(BlockBackend = *blk) blk_wait_while_drained(blk); GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1996,14 +1998,15 @@ bool coroutine_fn blk_co_is_inserted(BlockBackend *= blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bs && bdrv_co_is_inserted(bs); } =20 -bool blk_is_available(BlockBackend *blk) +bool coroutine_fn blk_co_is_available(BlockBackend *blk) { IO_CODE(); - return blk_is_inserted(blk) && !blk_dev_is_tray_open(blk); + return blk_co_is_inserted(blk) && !blk_dev_is_tray_open(blk); } =20 void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked) @@ -2382,7 +2385,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, i= nt64_t offset, bool exact, { IO_OR_GS_CODE(); GRAPH_RDLOCK_GUARD(); - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { error_setg(errp, "No medium inserted"); return -ENOMEDIUM; } @@ -2637,6 +2640,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, { int r; IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 r =3D blk_check_byte_request(blk_in, off_in, bytes); if (r) { @@ -2647,7 +2651,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, return r; } =20 - GRAPH_RDLOCK_GUARD(); return bdrv_co_copy_range(blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags); --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437802; cv=none; d=zohomail.com; s=zohoarc; b=kME7hQl2A9XMTxNf8Mu8mSzZiVwX8KxmCBn5Avd1s5QZmWVsVehgWWfOE9SNLFA4gS7LqrmycIziBQ8uyjwxQ9XDxr32+fHwynvSEAGBRWMNZ4tPV52xi4glXcdGDJUAYitMckmKw/0L4Awoo9Bb9I+Dlz3R7NO87y2jsT26pnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437802; 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=mwRom/j1B2ATDG3WfYUc62doVKvycJJoRZlrKvtxGWY=; b=h2SFI6r/c0ffkTMxnlrcT1iXv0tzgfx3eO1cLEmw5z9RbTW8yHg6LJIhq7ar9Vq5/QI7lI7azyEAanTlIloTecICs/bzO9wa9/KuSbqdjpsNnbQ02aa1t35fOUBYTTVF/0p1YyCcVwD++gpvD49YhuFO5vcPLrjHZQGhK3hBu7Q= 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+importer2=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 1675437802021396.84590423284135; Fri, 3 Feb 2023 07:23:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxu9-0007eB-7k; Fri, 03 Feb 2023 10:23:09 -0500 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 1pNxu7-0007bY-55 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:07 -0500 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 1pNxu5-0005OP-Bp for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:06 -0500 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-288-HRM2mcI-OGCioYdMFezLXA-1; Fri, 03 Feb 2023 10:23:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 750AB8030D0; Fri, 3 Feb 2023 15:23:01 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AE7040168B7; Fri, 3 Feb 2023 15:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437784; 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=mwRom/j1B2ATDG3WfYUc62doVKvycJJoRZlrKvtxGWY=; b=bGgcIzeoS4jICNOZjYXHouIbdtApKyBxax3OOp2tQsKHoJk39/38s52kUKoLcuJZX5wwid 0rDKsMcS410WOZBrUG2kOEaVgj/HNLhStnGyzFUctwPFadJY3bJpofDj6s10yfATMpveyX W2bgwtGIBT2InDxU71mywgatQRQhlVk= X-MC-Unique: HRM2mcI-OGCioYdMFezLXA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 19/23] block: Mark bdrv_co_eject/lock_medium() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:58 +0100 Message-Id: <20230203152202.49054-20-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437802473100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_eject() and bdrv_co_lock_medium() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 7 +++++-- include/block/block_int-common.h | 6 ++++-- block.c | 2 ++ block/block-backend.c | 2 ++ block/copy-on-read.c | 6 ++++-- block/filter-compress.c | 4 ++-- block/raw-format.c | 6 ++++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 88db63492a..bf2748011e 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -148,8 +148,11 @@ int bdrv_get_flags(BlockDriverState *bs); bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); =20 -void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); -void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); +void coroutine_fn GRAPH_RDLOCK +bdrv_co_lock_medium(BlockDriverState *bs, bool locked); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_eject(BlockDriverState *bs, bool eject_flag); =20 const char *bdrv_get_format_name(BlockDriverState *bs); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index b4a82269e5..30e6bd4909 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -714,8 +714,10 @@ struct BlockDriver { /* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); - void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); - void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_eject)( + BlockDriverState *bs, bool eject_flag); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_lock_medium)( + BlockDriverState *bs, bool locked); =20 /* to control generic scsi devices */ BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)( diff --git a/block.c b/block.c index 0b66995a4b..e2da543f3a 100644 --- a/block.c +++ b/block.c @@ -6826,6 +6826,7 @@ void coroutine_fn bdrv_co_eject(BlockDriverState *bs,= bool eject_flag) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (drv && drv->bdrv_co_eject) { drv->bdrv_co_eject(bs, eject_flag); @@ -6840,6 +6841,7 @@ void coroutine_fn bdrv_co_lock_medium(BlockDriverStat= e *bs, bool locked) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); trace_bdrv_lock_medium(bs, locked); =20 if (drv && drv->bdrv_co_lock_medium) { diff --git a/block/block-backend.c b/block/block-backend.c index 20af699f00..278b04ce69 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2013,6 +2013,7 @@ void coroutine_fn blk_co_lock_medium(BlockBackend *bl= k, bool locked) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_lock_medium(bs, locked); @@ -2024,6 +2025,7 @@ void coroutine_fn blk_co_eject(BlockBackend *blk, boo= l eject_flag) BlockDriverState *bs =3D blk_bs(blk); char *id; IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_eject(bs, eject_flag); diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 78da353f88..20215cff93 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -213,13 +213,15 @@ cor_co_pwritev_compressed(BlockDriverState *bs, int64= _t offset, int64_t bytes, } =20 =20 -static void coroutine_fn cor_co_eject(BlockDriverState *bs, bool eject_fla= g) +static void coroutine_fn GRAPH_RDLOCK +cor_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 -static void coroutine_fn cor_co_lock_medium(BlockDriverState *bs, bool loc= ked) +static void coroutine_fn GRAPH_RDLOCK +cor_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 0dd5606410..c7d50a67a7 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -114,14 +114,14 @@ static void compress_refresh_limits(BlockDriverState = *bs, Error **errp) } =20 =20 -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCK compress_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCK compress_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); diff --git a/block/raw-format.c b/block/raw-format.c index 646606e223..f4203d4806 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -405,12 +405,14 @@ raw_co_truncate(BlockDriverState *bs, int64_t offset,= bool exact, return bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp= ); } =20 -static void coroutine_fn raw_co_eject(BlockDriverState *bs, bool eject_fla= g) +static void coroutine_fn GRAPH_RDLOCK +raw_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 -static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool loc= ked) +static void coroutine_fn GRAPH_RDLOCK +raw_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); } --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675438008; cv=none; d=zohomail.com; s=zohoarc; b=VUA+Ra/p3rI08xPiewF6kuut3B/LM5J1acaN8Fn907bDLLWE0Eg3vpiYN0jHAioaHxEsyG4Ulv+iArm/VEOyYc2DT3/u+vrFVKKeiEDd86e4zVUOGlKfAbGbFkf54nAOzU3jw4cB1cYIcpP0BMO4hkjc02cZHDLyw4aDvrGx8E4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675438008; 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=uaCl/tzum7v2jDGIcPwdXbJ03M5KUBTnLe5jdw5kVQA=; b=N0fmCmptnUmYdhD/WRp/nGGooeOdpl5D76dDnxCxQjyPwXtwFZk9IcMw36ukbVTi19uf+FuBwmcSRNfDL65J0XruaJooshWDcxHkwXhkY1jpnwB6gsYmJYExPFsRxKf4CxVtQLdJUwrBcCD9KkJHanr8Xj6YfaQeJn0P3U1uNt0= 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+importer2=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 1675438008465587.392294358338; Fri, 3 Feb 2023 07:26:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxuA-0007fv-Mh; Fri, 03 Feb 2023 10:23:10 -0500 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 1pNxu9-0007e4-0J for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:09 -0500 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 1pNxu7-0005PA-Iu for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:08 -0500 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-630-ZNfiBuGyM1SdTUvRKFq_lw-1; Fri, 03 Feb 2023 10:23:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A72AD280604E; Fri, 3 Feb 2023 15:23:02 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD453404CD80; Fri, 3 Feb 2023 15:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437787; 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=uaCl/tzum7v2jDGIcPwdXbJ03M5KUBTnLe5jdw5kVQA=; b=VkBBsPrSGGaADUoKp/Ec3R8DJDOJTapufwKOMuhx2ZeHq1FFko6160LAnFzdfNrgpNPimS xR5DtDXxZ0mM4ohTKwVI8tdzSpZsbeJ6zE+8lhmjc3/rVUtnYR8G+4Ursxt3uO9m1IhDXs DXCRT9l3LJWHerhaD/C2NnIPRsq96IA= X-MC-Unique: ZNfiBuGyM1SdTUvRKFq_lw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 20/23] block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:21:59 +0100 Message-Id: <20230203152202.49054-21-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675438010073100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_register_buf() and bdrv_unregister_buf() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block_int-common.h | 7 ++++--- block/io.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 30e6bd4909..88d9897c97 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -445,9 +445,10 @@ struct BlockDriver { * * Returns: true on success, false on failure */ - bool (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t siz= e, - Error **errp); - void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host, size_t s= ize); + bool GRAPH_RDLOCK_PTR (*bdrv_register_buf)( + BlockDriverState *bs, void *host, size_t size, Error **errp); + void GRAPH_RDLOCK_PTR (*bdrv_unregister_buf)( + BlockDriverState *bs, void *host, size_t size); =20 /* * This field is modified only under the BQL, and is part of diff --git a/block/io.c b/block/io.c index be350aba98..9d3db1753d 100644 --- a/block/io.c +++ b/block/io.c @@ -3184,13 +3184,15 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverStat= e *bs) } =20 /* Helper that undoes bdrv_register_buf() when it fails partway through */ -static void bdrv_register_buf_rollback(BlockDriverState *bs, - void *host, - size_t size, - BdrvChild *final_child) +static void GRAPH_RDLOCK +bdrv_register_buf_rollback(BlockDriverState *bs, void *host, size_t size, + BdrvChild *final_child) { BdrvChild *child; =20 + GLOBAL_STATE_CODE(); + assert_bdrv_graph_readable(); + QLIST_FOREACH(child, &bs->children, next) { if (child =3D=3D final_child) { break; @@ -3210,6 +3212,8 @@ bool bdrv_register_buf(BlockDriverState *bs, void *ho= st, size_t size, BdrvChild *child; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + if (bs->drv && bs->drv->bdrv_register_buf) { if (!bs->drv->bdrv_register_buf(bs, host, size, errp)) { return false; @@ -3229,6 +3233,8 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *= host, size_t size) BdrvChild *child; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + if (bs->drv && bs->drv->bdrv_unregister_buf) { bs->drv->bdrv_unregister_buf(bs, host, size); } --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437877; cv=none; d=zohomail.com; s=zohoarc; b=h5Q01QIDcDHiRtWEGgQFdSUlrwHvu+v5K+KK61ea2ue1j+e9IrITrChuj8yG4srCkIr5WOjvsnYg3H5Y51ygP+0eZ9hyh3AMp8/6MVaqwxBd8oJcWPiq2EPIPeGST7R7JDyp9jxBbAOARZLAMnfNrUP1ScRn53wPPZoEaNg4I9Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437877; 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=PbZs8InVURnoMKD74IuoMRwN06NholNMEjHQObAQmSU=; b=R/0lGXmZxq6QEom+k3GIeMO6Do4UIvv0b44coCLJRo1h5I3Ux9/Do19d+MOb0STeO7djq3gtqViN29wKXoEtigQhbnk70WeTV1+Ju8VZJog/uvH7Q4Bvs9QVtWRt+X3BePX0Xq4srSgn8Riwx4wcxfrTsZ+avHLoy7mRrykCaLU= 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+importer2=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 1675437877357301.2789542664177; Fri, 3 Feb 2023 07:24:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxuB-0007gS-A1; Fri, 03 Feb 2023 10:23:11 -0500 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 1pNxu9-0007eb-IS for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:09 -0500 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 1pNxu8-0005PQ-5b for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:09 -0500 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-118-KHXVru0HNvKLhn8mnvR0rA-1; Fri, 03 Feb 2023 10:23:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D80E887A9E7; Fri, 3 Feb 2023 15:23:03 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF06040168BD; Fri, 3 Feb 2023 15:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437787; 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=PbZs8InVURnoMKD74IuoMRwN06NholNMEjHQObAQmSU=; b=VCnL0AJvGxtTC7V1AvZZ3D5B3BPwCdooqUVD5LhA3hg6l6RS5aMgvexr7Hn+gSCW0cphe5 95l5FBb1Z3uQExuOo5dIqqTcjlOcrOvQ6/WyA3EZpYind1iPBBX2Qj8XbyVsuhcJO9cg8V BR/pBVEIzLGBfTd850NlP8TMQ6t31pw= X-MC-Unique: KHXVru0HNvKLhn8mnvR0rA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 21/23] block: Mark bdrv_co_delete_file() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:22:00 +0100 Message-Id: <20230203152202.49054-22-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437878967100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_delete_file() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 8 ++++++-- include/block/block_int-common.h | 4 ++-- block.c | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index bf2748011e..a195a9fb11 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -90,8 +90,12 @@ int64_t co_wrapper bdrv_get_allocated_file_size(BlockDri= verState *bs); BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); -int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp); -void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file(BlockDriverState *bs, Error **errp); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file_noerr(BlockDriverState *bs); =20 =20 /* async block I/O */ diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 88d9897c97..257a9d18c6 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -649,8 +649,8 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *b= s); =20 /* Delete a created file. */ - int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, - Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_delete_file)( + BlockDriverState *bs, Error **errp); =20 /* * Flushes all data that was already written to the OS all the way dow= n to diff --git a/block.c b/block.c index e2da543f3a..1e378e881d 100644 --- a/block.c +++ b/block.c @@ -740,6 +740,7 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *= bs, Error **errp) =20 IO_CODE(); assert(bs !=3D NULL); + assert_bdrv_graph_readable(); =20 if (!bs->drv) { error_setg(errp, "Block node '%s' is not opened", bs->filename); --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437888; cv=none; d=zohomail.com; s=zohoarc; b=L78PncEF98w6Gd2QKeAEzncYPlwfE1xOXy2uRaMU/VhXVd5EN2+/8sQzjQ5CH2BGqPivoinbpypFnh6ZCg44fgeeI8NuustEOtt5NOXm4pBXZlEFFCDaJPJ7VRz9G1wFuhJanpvjEe6CT+6OsB5QJ04IXmeJNb33SjYEo1EHVps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437888; 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=9rFzXCef8TjyMlU//s5g+XWqWiEKh3IWbXr/+etAJwU=; b=BVjk50fbAwQPcyis8FI57sAnMT2I/oHVqqZIz3Ld+M/LhRfQ3qXq/GCxZdiELwLRziRSYbkR08gO1tgnmo/dFsOJ2gytoFpIqrhjFJqaIvBxzFwI9CsGldZOwt7jnGRtmapAHyxhHjddzPUEwrArIhv2FVJyInCURIK9lCwET3I= 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+importer2=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 1675437888509505.51278541576664; Fri, 3 Feb 2023 07:24:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxuC-0007gr-Ew; Fri, 03 Feb 2023 10:23:12 -0500 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 1pNxu9-0007f9-R3 for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:10 -0500 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 1pNxu8-0005PS-8V for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:09 -0500 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-389-ps0CHXKYMQ6RJQii5EfnGg-1; Fri, 03 Feb 2023 10:23:05 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 166442A5956F; Fri, 3 Feb 2023 15:23:05 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CA51408573E; Fri, 3 Feb 2023 15:23:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437787; 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=9rFzXCef8TjyMlU//s5g+XWqWiEKh3IWbXr/+etAJwU=; b=LnnAL383+qPp4JJYEUHAX9V5Ge3ZJBsL4kH0BOR0pxqRd9TLfwqkXt5wRCwBxWFZV+a711 laDNfASmeS3U90MTE2DT1wgOkGjhC8TRvv3i+CREZbaduSauh1Sg4kMujXtn0m/JSBIBj6 lPFL6tfptb3Z1EWTffvHBk6glxe1OkY= X-MC-Unique: ps0CHXKYMQ6RJQii5EfnGg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 22/23] block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:22:01 +0100 Message-Id: <20230203152202.49054-23-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437889048100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_*_dirty_bitmap() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 14 ++++++-------- include/block/block_int-common.h | 6 ++++-- include/block/dirty-bitmap.h | 12 ++++++------ block/dirty-bitmap.c | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index a195a9fb11..95bcc79b75 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -243,14 +243,12 @@ AioContext *child_of_bds_get_parent_aio_context(BdrvC= hild *c); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); =20 -bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, - Error **errp); -bool co_wrapper bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, - Error **errp); +bool coroutine_fn GRAPH_RDLOCK +bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, + uint32_t granularity, Error **errp); +bool co_wrapper_bdrv_rdlock +bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, + uint32_t granularity, Error **errp); =20 /** * diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 257a9d18c6..d72e31aba3 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -759,10 +759,12 @@ struct BlockDriver { void (*bdrv_drain_end)(BlockDriverState *bs); =20 bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs); - bool coroutine_fn (*bdrv_co_can_store_new_dirty_bitmap)( + + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_can_store_new_dirty_bitma= p)( BlockDriverState *bs, const char *name, uint32_t granularity, Error **errp); - int coroutine_fn (*bdrv_co_remove_persistent_dirty_bitmap)( + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_remove_persistent_dirty_bi= tmap)( BlockDriverState *bs, const char *name, Error **errp); }; =20 diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 233535ef2d..fa956debfb 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -36,12 +36,12 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitm= ap, uint32_t flags, void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *= bs, - const char *name, - Error **errp); -int co_wrapper bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *n= ame, + Error **errp); +int co_wrapper_bdrv_rdlock +bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, + Error **errp); =20 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 1e7aee4010..13a1979755 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -394,6 +394,7 @@ int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *n= ame, Error **errp) { + assert_bdrv_graph_readable(); if (bs->drv && bs->drv->bdrv_co_remove_persistent_dirty_bitmap) { return bs->drv->bdrv_co_remove_persistent_dirty_bitmap(bs, name, e= rrp); } @@ -415,6 +416,7 @@ bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs= , const char *name, uint32_t granularity, Error **errp) { BlockDriver *drv =3D bs->drv; + assert_bdrv_graph_readable(); =20 if (!drv) { error_setg_errno(errp, ENOMEDIUM, --=20 2.38.1 From nobody Thu Mar 28 11:49:24 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437901; cv=none; d=zohomail.com; s=zohoarc; b=A9hERpYikHYf/gxSfZvqGFPtmUOLhAf4patG8Vr0Z1FGxkrznzF2BR9WkI3uk2N0Iq+Flx0eJok2/+HFOHk/g7ZRE4TO4BHjpASI2goKac3WtgcV0W610D3Vc0Qf2Dg1MZWESrwhhM6sQlznBgmvUwXAo3mGSM6FOr0Z/dndKuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437901; 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=loal9xD94xXkwbGWgi/vz2iclG599UJkU2NqA3mfoww=; b=eevbRaWE1RRquaohD7aPwlmRylxXiJ9j+kcdHt2GCsDJsDd0poNKEPFsgqX6SalgNYoqVnJfTw1qVA8k9ImP+hNhekEVlyonkgfL0fmUnwHBFNkHeWKFJbUlLTEw3CebB8MDdiwEqy9uI4P0kObgphuDZyZTHXsUB/6LTkgqKM4= 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+importer2=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 1675437901048592.1112244836739; Fri, 3 Feb 2023 07:25:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxuF-0007lB-PC; Fri, 03 Feb 2023 10:23:15 -0500 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 1pNxuC-0007hE-JT for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:12 -0500 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 1pNxuA-0005QI-KR for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:12 -0500 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-640-RdHuAAO8MV6Ake_H5SiwIQ-1; Fri, 03 Feb 2023 10:23:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46413800B24; Fri, 3 Feb 2023 15:23:06 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CDC840168B7; Fri, 3 Feb 2023 15:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437790; 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=loal9xD94xXkwbGWgi/vz2iclG599UJkU2NqA3mfoww=; b=dypCl26nb9NdPPKWAC93eneBKXKIBd3zvdlPKQcdR44P5MDxsJ0Cr1JzOxetmTrzwu65uD dhIff4beBUckQe70brf9LkoRDHiXqa/u6ciRGz9J0exrH8NkyxuxMbbusnyQJVGd0EqQYh jXGsu9JPEv+d8QYVFGz5aBFgAwVEsjs= X-MC-Unique: RdHuAAO8MV6Ake_H5SiwIQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 23/23] block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:22:02 +0100 Message-Id: <20230203152202.49054-24-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437903110100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_refresh_total_sectors() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 8 ++++---- include/block/block_int-common.h | 4 +++- include/block/block_int-io.h | 7 ++++--- block.c | 3 +++ block/blkdebug.c | 3 ++- block/blklogwrites.c | 3 ++- block/blkreplay.c | 3 ++- block/blkverify.c | 3 ++- block/copy-on-read.c | 2 +- block/crypto.c | 3 ++- block/filter-compress.c | 3 ++- block/mirror.c | 3 +++ block/preallocate.c | 3 ++- block/quorum.c | 3 ++- block/raw-format.c | 3 ++- block/replication.c | 3 ++- block/stream.c | 8 +++++--- block/throttle.c | 3 ++- 18 files changed, 45 insertions(+), 23 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 95bcc79b75..5da99d4d60 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -78,11 +78,11 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **er= rp); =20 -int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_nb_sectors(BlockDriverState *bs); +int64_t co_wrapper_mixed_bdrv_rdlock bdrv_nb_sectors(BlockDriverState *bs); =20 -int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *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); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index d72e31aba3..d419017328 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -684,7 +684,9 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 - int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); + int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_getlength)( + BlockDriverState *bs); + int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( BlockDriverState *bs); =20 diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 612e5ddf99..eb0da7232e 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -124,9 +124,10 @@ bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offs= et, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 -int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, - int64_t hint); -int co_wrapper_mixed +int coroutine_fn GRAPH_RDLOCK +bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint); + +int co_wrapper_mixed_bdrv_rdlock bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 BdrvChild *bdrv_cow_child(BlockDriverState *bs); diff --git a/block.c b/block.c index 1e378e881d..1f1e63c468 100644 --- a/block.c +++ b/block.c @@ -1042,6 +1042,7 @@ int coroutine_fn bdrv_co_refresh_total_sectors(BlockD= riverState *bs, { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; @@ -5820,6 +5821,7 @@ int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverSt= ate *bs) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) return -ENOMEDIUM; @@ -5841,6 +5843,7 @@ int64_t coroutine_fn bdrv_co_getlength(BlockDriverSta= te *bs) { int64_t ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 ret =3D bdrv_co_nb_sectors(bs); if (ret < 0) { diff --git a/block/blkdebug.c b/block/blkdebug.c index f418a90873..978c8cff9e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -967,7 +967,8 @@ static bool blkdebug_debug_is_suspended(BlockDriverStat= e *bs, const char *tag) return false; } =20 -static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkdebug_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 93086c31e1..3ea7141cb5 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -267,7 +267,8 @@ static void blk_log_writes_close(BlockDriverState *bs) s->log_file =3D NULL; } =20 -static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *= bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blkreplay.c b/block/blkreplay.c index bc96bbd41e..04f53eea41 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -40,7 +40,8 @@ fail: return ret; } =20 -static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkreplay_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blkverify.c b/block/blkverify.c index 8c11c2eae4..1c16f86b2e 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -155,7 +155,8 @@ static void blkverify_close(BlockDriverState *bs) s->test_file =3D NULL; } =20 -static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkverify_co_getlength(BlockDriverState *bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 20215cff93..cc0f848b0f 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -121,7 +121,7 @@ static void cor_child_perm(BlockDriverState *bs, BdrvCh= ild *c, } =20 =20 -static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK cor_co_getlength(BlockDriverState= *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/crypto.c b/block/crypto.c index 28f870f33c..88b092e1a4 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -531,7 +531,8 @@ static void block_crypto_refresh_limits(BlockDriverStat= e *bs, Error **errp) } =20 =20 -static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +block_crypto_co_getlength(BlockDriverState *bs) { BlockCrypto *crypto =3D bs->opaque; int64_t len =3D bdrv_co_getlength(bs->file->bs); diff --git a/block/filter-compress.c b/block/filter-compress.c index c7d50a67a7..ac285f4b66 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -55,7 +55,8 @@ static int compress_open(BlockDriverState *bs, QDict *opt= ions, int flags, } =20 =20 -static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +compress_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/mirror.c b/block/mirror.c index ec5cd22a7c..97c6a5777d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -917,7 +917,10 @@ static int coroutine_fn mirror_run(Job *job, Error **e= rrp) goto immediate_exit; } =20 + bdrv_graph_co_rdlock(); s->bdev_length =3D bdrv_co_getlength(bs); + bdrv_graph_co_rdunlock(); + if (s->bdev_length < 0) { ret =3D s->bdev_length; goto immediate_exit; diff --git a/block/preallocate.c b/block/preallocate.c index 63a296882d..71c3601809 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -443,7 +443,8 @@ static int coroutine_fn GRAPH_RDLOCK preallocate_co_flu= sh(BlockDriverState *bs) return bdrv_co_flush(bs->file->bs); } =20 -static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +preallocate_co_getlength(BlockDriverState *bs) { int64_t ret; BDRVPreallocateState *s =3D bs->opaque; diff --git a/block/quorum.c b/block/quorum.c index d58f86d3a5..ff5a0a2da3 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -764,7 +764,8 @@ quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t o= ffset, int64_t bytes, flags | BDRV_REQ_ZERO_WRITE); } =20 -static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +quorum_co_getlength(BlockDriverState *bs) { BDRVQuorumState *s =3D bs->opaque; int64_t result; diff --git a/block/raw-format.c b/block/raw-format.c index f4203d4806..66783ed8e7 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -317,7 +317,8 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, i= nt64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +raw_co_getlength(BlockDriverState *bs) { int64_t len; BDRVRawState *s =3D bs->opaque; diff --git a/block/replication.c b/block/replication.c index f9f899bfc8..de01f96184 100644 --- a/block/replication.c +++ b/block/replication.c @@ -179,7 +179,8 @@ static void replication_child_perm(BlockDriverState *bs= , BdrvChild *c, return; } =20 -static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +replication_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/stream.c b/block/stream.c index 22368ce186..68018699de 100644 --- a/block/stream.c +++ b/block/stream.c @@ -141,9 +141,11 @@ static int coroutine_fn stream_run(Job *job, Error **e= rrp) return 0; } =20 - len =3D bdrv_getlength(s->target_bs); - if (len < 0) { - return len; + WITH_GRAPH_RDLOCK_GUARD() { + len =3D bdrv_co_getlength(s->target_bs); + if (len < 0) { + return len; + } } job_progress_set_remaining(&s->common.job, len); =20 diff --git a/block/throttle.c b/block/throttle.c index 5cfea3d5f8..3aaef18d4e 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -106,7 +106,8 @@ static void throttle_close(BlockDriverState *bs) } =20 =20 -static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +throttle_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } --=20 2.38.1