From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608573; cv=none; d=zohomail.com; s=zohoarc; b=LvsLYAnrWXxJfqHS5Wc9Yh0g1vbVEXW5bsrqHJVameopfIpismOEwBzTXc1HzE+80gh/UqMSEXsfCk2jU1XvwnAZzA03Bq1TxBAQyaCjqe/GxtBUxbOM8ySIJbSLVfEvoHonAURjNQkgvriAybIYfUFqA/0LdBwgk1hwr1gPGns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608573; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7eL5QOt6pRzng8VnrLmY7zeMAa5ne7tpOIThr8pO/xg=; b=OAJRkD6YO3rCd4R7gKJpTaw/7XLA7ANkIqyweMhpdyFidhDDSO5hYqHjb3UXM5MIhtOW1QCeLKXBdJvzkwzdxk8Eu67Z6hmSy+oPhz4+ufAJQGyFmIAWJEKeblHbI26aNqTWBwxoUQF4EvaNZF+fbRF7vBYDhbau0PW04HfMWiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608573941441.4078007210602; Tue, 15 Jul 2025 12:42:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublVD-0005Gb-Ly; Tue, 15 Jul 2025 15:39:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwM-0003Y9-Jq for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwI-0001Dv-Jw for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:45 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640--KzGxwDLP62kRAJdLePHxA-1; Tue, 15 Jul 2025 15:03:39 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04C42180024A; Tue, 15 Jul 2025 19:03:39 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 44BF3197702B; Tue, 15 Jul 2025 19:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606221; 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=7eL5QOt6pRzng8VnrLmY7zeMAa5ne7tpOIThr8pO/xg=; b=KUJYYcEzPumOJ8Cbln7USrdxt/xrq9lVSX39GPqqgADVYgiMehgnfAiJI4h3U5JHbo1Em3 /lzLFJksbxkQ6yQqK3tUVSodGU8M0KY8zYkUQbBfZlxZHQ3Lw/9/MVXm7MQE9375elkRE8 3SxXgm3wsLneIrxV8w6xH5T/6jMntaQ= X-MC-Unique: -KzGxwDLP62kRAJdLePHxA-1 X-Mimecast-MFC-AGG-ID: -KzGxwDLP62kRAJdLePHxA_1752606219 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 01/57] block: never use atomics to access bs->quiesce_counter Date: Tue, 15 Jul 2025 21:02:34 +0200 Message-ID: <20250715190330.378764-2-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608574671116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner All accesses of bs->quiesce_counter are in the main thread, either after a GLOBAL_STATE_CODE() macro or in a function with GRAPH_WRLOCK annotation. This is essentially a revert of 414c2ec358 ("block: access quiesce_counter with atomic ops"). At that time, neither the GLOBAL_STATE_CODE() macro nor the GRAPH_WRLOCK annotation existed. Even if the field was only accessed in the main thread back then (did not check if that is actually the case), it wouldn't have been easy to verify. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-24-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block_int-common.h | 2 +- block/io.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 925a3e7353..e96c6a6a03 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1253,7 +1253,7 @@ struct BlockDriverState { /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 - /* Accessed with atomic ops. */ + /* Accessed only in the main thread. */ int quiesce_counter; =20 unsigned int write_gen; /* Current data generation */ diff --git a/block/io.c b/block/io.c index ac5c7174f6..9bd8ba8431 100644 --- a/block/io.c +++ b/block/io.c @@ -361,7 +361,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= BdrvChild *parent, GLOBAL_STATE_CODE(); =20 /* Stop things in parent-to-child order */ - if (qatomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { + if (bs->quiesce_counter++ =3D=3D 0) { GRAPH_RDLOCK_GUARD_MAINLOOP(); bdrv_parent_drained_begin(bs, parent); if (bs->drv && bs->drv->bdrv_drain_begin) { @@ -401,8 +401,6 @@ bdrv_drained_begin(BlockDriverState *bs) */ static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) { - int old_quiesce_counter; - IO_OR_GS_CODE(); =20 if (qemu_in_coroutine()) { @@ -415,8 +413,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, B= drvChild *parent) assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ - old_quiesce_counter =3D qatomic_fetch_dec(&bs->quiesce_counter); - if (old_quiesce_counter =3D=3D 1) { + if (--bs->quiesce_counter =3D=3D 0) { GRAPH_RDLOCK_GUARD_MAINLOOP(); if (bs->drv && bs->drv->bdrv_drain_end) { bs->drv->bdrv_drain_end(bs); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608858; cv=none; d=zohomail.com; s=zohoarc; b=Fg3WG90KAUvJSPhti3RHuK0kw+d9274ge7yL+s53JqEh7Ka7K6ba2Kj/KERnFzi1GVe4CR/j/frtewBqrCs4m4Rxd5wDOHARmUwKPJk7bkC3pDhjQwdm/+cg7N2IMXgyKgzIf59KeMv1XorINWsKIdw8Xz0LJK20GH/dQ1f3dLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608858; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XZEA98qaKK1Z9qLWytMg+L44kgoZeZirr8NtetnhP08=; b=TRupI/krkjO2rpGXUdxJOnyX56F1tZ/sU9SDSEwR07rkZAkbepvevWod0CHVJvKPtONWhYTUbLXcy1dzJEh28miwndTT9Iib7KMSZiuU188ySHjBJqQYyc8YbZ81RfuS2mVyM88/RpKjrZN10r8XBO65LxM0/9CKnG7g/WZ6BAM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175260885827582.02269030133823; Tue, 15 Jul 2025 12:47:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublV5-0004eu-OS; Tue, 15 Jul 2025 15:39:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwO-0003YE-6q for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwK-0001EP-Vp for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:47 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-652-Kw-leed5PY6An8Bzk_dRnw-1; Tue, 15 Jul 2025 15:03:42 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6BF4E195609E; Tue, 15 Jul 2025 19:03:41 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7BBC4197702B; Tue, 15 Jul 2025 19:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606224; 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=XZEA98qaKK1Z9qLWytMg+L44kgoZeZirr8NtetnhP08=; b=ND8/bL5Zjv2nDqdYGVzzkwS2Xk4Xrhvrkn29VXXoI+1DGLlkZExF7nRsF8qU3+dCl4whSW pFgbybkb2JC7Pi28tBrjX5i1o98Zx8azO6WZslNr1SXMGMMDObj5k+3Z70Eq3t0usqiBnC mq5MudlYN7yhXfTZf+epzjXa2qf1bnk= X-MC-Unique: Kw-leed5PY6An8Bzk_dRnw-1 X-Mimecast-MFC-AGG-ID: Kw-leed5PY6An8Bzk_dRnw_1752606221 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 02/57] block: add bdrv_graph_wrlock_drained() convenience wrapper Date: Tue, 15 Jul 2025 21:02:35 +0200 Message-ID: <20250715190330.378764-3-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608860595116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner Many write-locked sections are also drained sections. A new bdrv_graph_wrunlock_drained() wrapper around bdrv_graph_wrunlock() is introduced, which will begin a drained section first. A global variable is used so bdrv_graph_wrunlock() knows if it also needs to end such a drained section. Both the aio_poll call in bdrv_graph_wrlock() and the aio_bh_poll() in bdrv_graph_wrunlock() can re-enter a write-locked section. While for the latter, ending the drain could be moved to before the call, the former requires that the variable is a counter and not just a boolean. Since the wrapper calls bdrv_drain_all_begin(), which must be called with the graph unlocked, mark the wrapper as GRAPH_UNLOCKED too. The switch to the new helpers was generated with the following commands and then manually checked: find . -name '*.c' -exec sed -i -z 's/bdrv_drain_all_begin();\n\s*bdrv_grap= h_wrlock();/bdrv_graph_wrlock_drained();/g' {} ';' find . -name '*.c' -exec sed -i -z 's/bdrv_graph_wrunlock();\n\s*bdrv_drain= _all_end();/bdrv_graph_wrunlock();/g' {} ';' Suggested-by: Kevin Wolf Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-25-f.ebner@proxmox.com> [kwolf: Removed redundant GRAPH_UNLOCKED] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/graph-lock.h | 11 +++++++++ block.c | 20 ++++------------ block/backup.c | 4 +--- block/blklogwrites.c | 8 ++----- block/blkverify.c | 4 +--- block/block-backend.c | 8 ++----- block/commit.c | 6 +---- block/graph-lock.c | 40 +++++++++++++++++++++++++++++--- block/mirror.c | 7 +----- block/qcow2.c | 4 +--- block/quorum.c | 8 ++----- block/replication.c | 11 ++------- block/snapshot.c | 4 +--- block/stream.c | 6 +---- block/vmdk.c | 20 ++++------------ blockdev.c | 4 +--- blockjob.c | 10 ++------ tests/unit/test-bdrv-drain.c | 36 +++++++--------------------- tests/unit/test-bdrv-graph-mod.c | 20 ++++------------ 19 files changed, 90 insertions(+), 141 deletions(-) diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h index 2c26c72108..95bf5ede40 100644 --- a/include/block/graph-lock.h +++ b/include/block/graph-lock.h @@ -112,10 +112,21 @@ void unregister_aiocontext(AioContext *ctx); void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA bdrv_graph_wrlock(void); =20 +/* + * bdrv_graph_wrlock_drained: + * Similar to bdrv_graph_wrlock, but will begin a drained section before + * locking. + */ +void no_coroutine_fn TSA_ACQUIRE(graph_lock) TSA_NO_TSA +bdrv_graph_wrlock_drained(void); + /* * bdrv_graph_wrunlock: * Write finished, reset global has_writer to 0 and restart * all readers that are waiting. + * + * Also ends the drained section if bdrv_graph_wrlock_drained() was used t= o lock + * the graph. */ void no_coroutine_fn TSA_RELEASE(graph_lock) TSA_NO_TSA bdrv_graph_wrunlock(void); diff --git a/block.c b/block.c index bfd4340b24..1da10d55f0 100644 --- a/block.c +++ b/block.c @@ -1721,14 +1721,12 @@ bdrv_open_driver(BlockDriverState *bs, BlockDriver = *drv, const char *node_name, open_failed: bs->drv =3D NULL; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); if (bs->file !=3D NULL) { bdrv_unref_child(bs, bs->file); assert(!bs->file); } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 g_free(bs->opaque); bs->opaque =3D NULL; @@ -3602,11 +3600,9 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd, int ret; GLOBAL_STATE_CODE(); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); ret =3D bdrv_set_backing_hd_drained(bs, backing_hd, errp); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 return ret; } @@ -3797,12 +3793,10 @@ static BdrvChild *bdrv_open_child_common(const char= *filename, return NULL; } =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); child =3D bdrv_attach_child(parent, bs, bdref_key, child_class, child_= role, errp); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 return child; } @@ -5180,8 +5174,7 @@ static void bdrv_close(BlockDriverState *bs) bs->drv =3D NULL; } =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); QLIST_FOREACH_SAFE(child, &bs->children, next, next) { bdrv_unref_child(bs, child); } @@ -5189,7 +5182,6 @@ static void bdrv_close(BlockDriverState *bs) assert(!bs->backing); assert(!bs->file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 g_free(bs->opaque); bs->opaque =3D NULL; @@ -5515,8 +5507,7 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriver= State *bs_top, assert(!bs_new->backing); bdrv_graph_rdunlock_main_loop(); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); =20 child =3D bdrv_attach_child_noperm(bs_new, bs_top, "backing", &child_of_bds, bdrv_backing_role(bs_n= ew), @@ -5537,7 +5528,6 @@ out: =20 bdrv_refresh_limits(bs_top, NULL, NULL); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 return ret; } diff --git a/block/backup.c b/block/backup.c index 909027c17a..d4713fa1cd 100644 --- a/block/backup.c +++ b/block/backup.c @@ -498,12 +498,10 @@ BlockJob *backup_job_create(const char *job_id, Block= DriverState *bs, block_copy_set_speed(bcs, speed); =20 /* Required permissions are taken by copy-before-write filter target */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); block_job_add_bdrv(&job->common, "target", target, 0, BLK_PERM_ALL, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 return &job->common; =20 diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 70ac76f401..aa1f888869 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -281,11 +281,9 @@ static int blk_log_writes_open(BlockDriverState *bs, Q= Dict *options, int flags, ret =3D 0; fail_log: if (ret < 0) { - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, s->log_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); s->log_file =3D NULL; qemu_mutex_destroy(&s->mutex); } @@ -298,12 +296,10 @@ static void blk_log_writes_close(BlockDriverState *bs) { BDRVBlkLogWritesState *s =3D bs->opaque; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, s->log_file); s->log_file =3D NULL; bdrv_graph_wrunlock(); - bdrv_drain_all_end(); qemu_mutex_destroy(&s->mutex); } =20 diff --git a/block/blkverify.c b/block/blkverify.c index 3a71f7498c..72efcbe7ef 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -151,12 +151,10 @@ static void blkverify_close(BlockDriverState *bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, s->test_file); s->test_file =3D NULL; bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 static int64_t coroutine_fn GRAPH_RDLOCK diff --git a/block/block-backend.c b/block/block-backend.c index 68209bb2f7..f8d6ba65c1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -889,11 +889,9 @@ void blk_remove_bs(BlockBackend *blk) root =3D blk->root; blk->root =3D NULL; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_root_unref_child(root); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 /* @@ -906,8 +904,7 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *= bs, Error **errp) =20 GLOBAL_STATE_CODE(); bdrv_ref(bs); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); =20 if ((bs->open_flags & BDRV_O_INACTIVE) && blk_can_inactivate(blk)) { blk->disable_perm =3D true; @@ -922,7 +919,6 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState *= bs, Error **errp) BDRV_CHILD_FILTERED | BDRV_CHILD_PR= IMARY, perm, shared_perm, blk, errp); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); if (blk->root =3D=3D NULL) { return -EPERM; } diff --git a/block/commit.c b/block/commit.c index 6c4b736ff8..dc1942483b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -392,8 +392,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, * this is the responsibility of the interface (i.e. whoever calls * commit_start()). */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); s->base_overlay =3D bdrv_find_overlay(top, base); assert(s->base_overlay); =20 @@ -425,21 +424,18 @@ void commit_start(const char *job_id, BlockDriverStat= e *bs, iter_shared_perms, errp); if (ret < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } } =20 if (bdrv_freeze_backing_chain(commit_top_bs, base, errp) < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } s->chain_frozen =3D true; =20 ret =3D block_job_add_bdrv(&s->common, "base", base, 0, BLK_PERM_ALL, = errp); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 if (ret < 0) { goto fail; diff --git a/block/graph-lock.c b/block/graph-lock.c index c81162b147..b7319473a1 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -33,6 +33,17 @@ static QemuMutex aio_context_list_lock; /* Written and read with atomic operations. */ static int has_writer; =20 +/* + * Many write-locked sections are also drained sections. There is a conven= ience + * wrapper bdrv_graph_wrlock_drained() which begins a drained section befo= re + * acquiring the lock. This variable here is used so bdrv_graph_wrunlock()= knows + * if it also needs to end such a drained section. It needs to be a counte= r, + * because the aio_poll() call in bdrv_graph_wrlock() might re-enter + * bdrv_graph_wrlock_drained(). And note that aio_bh_poll() in + * bdrv_graph_wrunlock() might also re-enter a write-locked section. + */ +static int wrlock_quiesced_counter; + /* * A reader coroutine could move from an AioContext to another. * If this happens, there is no problem from the point of view of @@ -112,8 +123,14 @@ void no_coroutine_fn bdrv_graph_wrlock(void) assert(!qatomic_read(&has_writer)); assert(!qemu_in_coroutine()); =20 - /* Make sure that constantly arriving new I/O doesn't cause starvation= */ - bdrv_drain_all_begin_nopoll(); + bool need_drain =3D wrlock_quiesced_counter =3D=3D 0; + + if (need_drain) { + /* + * Make sure that constantly arriving new I/O doesn't cause starva= tion + */ + bdrv_drain_all_begin_nopoll(); + } =20 /* * reader_count =3D=3D 0: this means writer will read has_reader as 1 @@ -139,7 +156,18 @@ void no_coroutine_fn bdrv_graph_wrlock(void) smp_mb(); } while (reader_count() >=3D 1); =20 - bdrv_drain_all_end(); + if (need_drain) { + bdrv_drain_all_end(); + } +} + +void no_coroutine_fn bdrv_graph_wrlock_drained(void) +{ + GLOBAL_STATE_CODE(); + + bdrv_drain_all_begin(); + wrlock_quiesced_counter++; + bdrv_graph_wrlock(); } =20 void no_coroutine_fn bdrv_graph_wrunlock(void) @@ -168,6 +196,12 @@ void no_coroutine_fn bdrv_graph_wrunlock(void) * progress. */ aio_bh_poll(qemu_get_aio_context()); + + if (wrlock_quiesced_counter > 0) { + bdrv_drain_all_end(); + wrlock_quiesced_counter--; + } + } =20 void coroutine_fn bdrv_graph_co_rdlock(void) diff --git a/block/mirror.c b/block/mirror.c index 6e8caf4b49..82a6e50cf8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -2014,15 +2014,13 @@ static BlockJob *mirror_start_job( */ bdrv_disable_dirty_bitmap(s->dirty_bitmap); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); ret =3D block_job_add_bdrv(&s->common, "source", bs, 0, BLK_PERM_WRITE_UNCHANGED | BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ, errp); if (ret < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } =20 @@ -2068,19 +2066,16 @@ static BlockJob *mirror_start_job( iter_shared_perms, errp); if (ret < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } } =20 if (bdrv_freeze_backing_chain(mirror_top_bs, target, errp) < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 QTAILQ_INIT(&s->ops_in_flight); =20 diff --git a/block/qcow2.c b/block/qcow2.c index 45451a7ee8..4aa9f9e068 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2823,11 +2823,9 @@ qcow2_do_close(BlockDriverState *bs, bool close_data= _file) if (close_data_file && has_data_file(bs)) { GLOBAL_STATE_CODE(); bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, s->data_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); s->data_file =3D NULL; bdrv_graph_rdlock_main_loop(); } diff --git a/block/quorum.c b/block/quorum.c index cc3bc5f4e7..76a4feb2d9 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1037,8 +1037,7 @@ static int quorum_open(BlockDriverState *bs, QDict *o= ptions, int flags, =20 close_exit: /* cleanup on error */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); for (i =3D 0; i < s->num_children; i++) { if (!opened[i]) { continue; @@ -1046,7 +1045,6 @@ close_exit: bdrv_unref_child(bs, s->children[i]); } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); g_free(s->children); g_free(opened); exit: @@ -1059,13 +1057,11 @@ static void quorum_close(BlockDriverState *bs) BDRVQuorumState *s =3D bs->opaque; int i; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); for (i =3D 0; i < s->num_children; i++) { bdrv_unref_child(bs, s->children[i]); } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 g_free(s->children); } diff --git a/block/replication.c b/block/replication.c index 0879718854..83978b61f5 100644 --- a/block/replication.c +++ b/block/replication.c @@ -540,8 +540,7 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, return; } =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); =20 bdrv_ref(hidden_disk->bs); s->hidden_disk =3D bdrv_attach_child(bs, hidden_disk->bs, "hidden = disk", @@ -550,7 +549,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, if (local_err) { error_propagate(errp, local_err); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); return; } =20 @@ -561,7 +559,6 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, if (local_err) { error_propagate(errp, local_err); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); return; } =20 @@ -574,14 +571,12 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, !check_top_bs(top_bs, bs)) { error_setg(errp, "No top_bs or it is invalid"); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); reopen_backing_file(bs, false, NULL); return; } bdrv_op_block_all(top_bs, s->blocker); =20 bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 s->backup_job =3D backup_job_create( NULL, s->secondary_disk->bs, s->hidden_dis= k->bs, @@ -656,14 +651,12 @@ static void replication_done(void *opaque, int ret) if (ret =3D=3D 0) { s->stage =3D BLOCK_REPLICATION_DONE; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, s->secondary_disk); s->secondary_disk =3D NULL; bdrv_unref_child(bs, s->hidden_disk); s->hidden_disk =3D NULL; bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 s->error =3D 0; } else { diff --git a/block/snapshot.c b/block/snapshot.c index 28c9c43621..bd9d759b32 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -291,11 +291,9 @@ int bdrv_snapshot_goto(BlockDriverState *bs, } =20 /* .bdrv_open() will re-attach it */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, fallback); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 ret =3D bdrv_snapshot_goto(fallback_bs, snapshot_id, errp); memset(bs->opaque, 0, drv->instance_size); diff --git a/block/stream.c b/block/stream.c index f5441f27f4..a6ef840e29 100644 --- a/block/stream.c +++ b/block/stream.c @@ -371,12 +371,10 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, * already have our own plans. Also don't allow resize as the image si= ze is * queried only at the job start and then cached. */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); if (block_job_add_bdrv(&s->common, "active node", bs, 0, basic_flags | BLK_PERM_WRITE, errp)) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } =20 @@ -397,12 +395,10 @@ void stream_start(const char *job_id, BlockDriverStat= e *bs, basic_flags, errp); if (ret < 0) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); goto fail; } } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 s->base_overlay =3D base_overlay; s->above_base =3D above_base; diff --git a/block/vmdk.c b/block/vmdk.c index 89a7250120..04986c8d55 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -271,8 +271,7 @@ static void vmdk_free_extents(BlockDriverState *bs) BDRVVmdkState *s =3D bs->opaque; VmdkExtent *e; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); for (i =3D 0; i < s->num_extents; i++) { e =3D &s->extents[i]; g_free(e->l1_table); @@ -284,7 +283,6 @@ static void vmdk_free_extents(BlockDriverState *bs) } } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 g_free(s->extents); } @@ -1249,11 +1247,9 @@ vmdk_parse_extents(const char *desc, BlockDriverStat= e *bs, QDict *options, 0, 0, 0, 0, 0, &extent, errp); if (ret < 0) { bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, extent_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); bdrv_graph_rdlock_main_loop(); goto out; } @@ -1270,11 +1266,9 @@ vmdk_parse_extents(const char *desc, BlockDriverStat= e *bs, QDict *options, g_free(buf); if (ret) { bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, extent_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); bdrv_graph_rdlock_main_loop(); goto out; } @@ -1283,11 +1277,9 @@ vmdk_parse_extents(const char *desc, BlockDriverStat= e *bs, QDict *options, ret =3D vmdk_open_se_sparse(bs, extent_file, bs->open_flags, e= rrp); if (ret) { bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, extent_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); bdrv_graph_rdlock_main_loop(); goto out; } @@ -1295,11 +1287,9 @@ vmdk_parse_extents(const char *desc, BlockDriverStat= e *bs, QDict *options, } else { error_setg(errp, "Unsupported extent type '%s'", type); bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(bs, extent_file); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); bdrv_graph_rdlock_main_loop(); ret =3D -ENOTSUP; goto out; diff --git a/blockdev.c b/blockdev.c index 2e7fda6780..e625534925 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3561,8 +3561,7 @@ void qmp_x_blockdev_change(const char *parent, const = char *child, BlockDriverState *parent_bs, *new_bs =3D NULL; BdrvChild *p_child; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); =20 parent_bs =3D bdrv_lookup_bs(parent, parent, errp); if (!parent_bs) { @@ -3599,7 +3598,6 @@ void qmp_x_blockdev_change(const char *parent, const = char *child, =20 out: bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 BlockJobInfoList *qmp_query_block_jobs(Error **errp) diff --git a/blockjob.c b/blockjob.c index e68181a35b..db7c3a69a0 100644 --- a/blockjob.c +++ b/blockjob.c @@ -198,8 +198,7 @@ void block_job_remove_all_bdrv(BlockJob *job) * one to make sure that such a concurrent access does not attempt * to process an already freed BdrvChild. */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); while (job->nodes) { GSList *l =3D job->nodes; BdrvChild *c =3D l->data; @@ -212,7 +211,6 @@ void block_job_remove_all_bdrv(BlockJob *job) g_slist_free_1(l); } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs) @@ -498,8 +496,7 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, int ret; GLOBAL_STATE_CODE(); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); =20 if (job_id =3D=3D NULL && !(flags & JOB_INTERNAL)) { job_id =3D bdrv_get_device_name(bs); @@ -509,7 +506,6 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, flags, cb, opaque, errp); if (job =3D=3D NULL) { bdrv_graph_wrunlock(); - bdrv_drain_all_end(); return NULL; } =20 @@ -548,12 +544,10 @@ void *block_job_create(const char *job_id, const Bloc= kJobDriver *driver, } =20 bdrv_graph_wrunlock(); - bdrv_drain_all_end(); return job; =20 fail: bdrv_graph_wrunlock(); - bdrv_drain_all_end(); job_early_fail(&job->job); return NULL; } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 59c2793725..3369c2c2aa 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -772,11 +772,9 @@ static void test_blockjob_common_drain_node(enum drain= _type drain_type, tjob->bs =3D src; job =3D &tjob->common; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abor= t); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 switch (result) { case TEST_JOB_SUCCESS: @@ -955,13 +953,11 @@ static void bdrv_test_top_close(BlockDriverState *bs) { BdrvChild *c, *next_c; =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); QLIST_FOREACH_SAFE(c, &bs->children, next, next_c) { bdrv_unref_child(bs, c); } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 static int coroutine_fn GRAPH_RDLOCK @@ -1053,12 +1049,10 @@ static void do_test_delete_by_drain(bool detach_ins= tead_of_delete, =20 null_bs =3D bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_P= ROTOCOL, &error_abort); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, BDRV_CHILD_DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 /* This child will be the one to pass to requests through to, and * it will stall until a drain occurs */ @@ -1066,25 +1060,21 @@ static void do_test_delete_by_drain(bool detach_ins= tead_of_delete, &error_abort); child_bs->total_sectors =3D 65536 >> BDRV_SECTOR_BITS; /* Takes our reference to child_bs */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); tts->wait_child =3D bdrv_attach_child(bs, child_bs, "wait-child", &child_of_bds, BDRV_CHILD_DATA | BDRV_CHILD_PRIMA= RY, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 /* This child is just there to be deleted * (for detach_instead_of_delete =3D=3D true) */ null_bs =3D bdrv_open("null-co://", NULL, NULL, BDRV_O_RDWR | BDRV_O_P= ROTOCOL, &error_abort); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(bs, null_bs, "null-child", &child_of_bds, BDRV_CHILD= _DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); blk_insert_bs(blk, bs, &error_abort); @@ -1167,8 +1157,7 @@ static void no_coroutine_fn detach_indirect_bh(void *= opaque) =20 bdrv_dec_in_flight(data->child_b->bs); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_unref_child(data->parent_b, data->child_b); =20 bdrv_ref(data->c); @@ -1176,7 +1165,6 @@ static void no_coroutine_fn detach_indirect_bh(void *= opaque) &child_of_bds, BDRV_CHILD_DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); } =20 static void coroutine_mixed_fn detach_by_parent_aio_cb(void *opaque, int r= et) @@ -1274,8 +1262,7 @@ static void TSA_NO_TSA test_detach_indirect(bool by_p= arent_cb) /* Set child relationships */ bdrv_ref(b); bdrv_ref(a); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); child_b =3D bdrv_attach_child(parent_b, b, "PB-B", &child_of_bds, BDRV_CHILD_DATA, &error_abort); child_a =3D bdrv_attach_child(parent_b, a, "PB-A", &child_of_bds, @@ -1286,7 +1273,6 @@ static void TSA_NO_TSA test_detach_indirect(bool by_p= arent_cb) by_parent_cb ? &child_of_bds : &detach_by_driver_cb_= class, BDRV_CHILD_DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 g_assert_cmpint(parent_a->refcnt, =3D=3D, 1); g_assert_cmpint(parent_b->refcnt, =3D=3D, 1); @@ -1699,8 +1685,7 @@ static void test_drop_intermediate_poll(void) * Establish the chain last, so the chain links are the first * elements in the BDS.parents lists */ - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); for (i =3D 0; i < 3; i++) { if (i) { /* Takes the reference to chain[i - 1] */ @@ -1709,7 +1694,6 @@ static void test_drop_intermediate_poll(void) } } bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 job =3D block_job_create("job", &test_simple_job_driver, NULL, job_nod= e, 0, BLK_PERM_ALL, 0, 0, NULL, NULL, &error_abort= ); @@ -1956,12 +1940,10 @@ static void do_test_replace_child_mid_drain(int old= _drain_count, new_child_bs->total_sectors =3D 1; =20 bdrv_ref(old_child_bs); - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(parent_bs, old_child_bs, "child", &child_of_bds, BDRV_CHILD_COW, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); parent_s->setup_completed =3D true; =20 for (i =3D 0; i < old_drain_count; i++) { diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index 7b03ebe4b0..b077f0e3e3 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -137,12 +137,10 @@ static void test_update_perm_tree(void) =20 blk_insert_bs(root, bs, &error_abort); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(filter, bs, "child", &child_of_bds, BDRV_CHILD_DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 ret =3D bdrv_append(filter, bs, NULL); g_assert_cmpint(ret, <, 0); @@ -206,13 +204,11 @@ static void test_should_update_child(void) =20 bdrv_set_backing_hd(target, bs, &error_abort); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); g_assert(target->backing->bs =3D=3D bs); bdrv_attach_child(filter, target, "target", &child_of_bds, BDRV_CHILD_DATA, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); bdrv_append(filter, bs, &error_abort); =20 bdrv_graph_rdlock_main_loop(); @@ -248,8 +244,7 @@ static void test_parallel_exclusive_write(void) bdrv_ref(base); bdrv_ref(fl1); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(top, fl1, "backing", &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); @@ -262,7 +257,6 @@ static void test_parallel_exclusive_write(void) =20 bdrv_replace_node(fl1, fl2, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 bdrv_drained_end(fl2); bdrv_drained_end(fl1); @@ -369,8 +363,7 @@ static void test_parallel_perm_update(void) */ bdrv_ref(base); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(top, ws, "file", &child_of_bds, BDRV_CHILD_DATA, &error_abort); c_fl1 =3D bdrv_attach_child(ws, fl1, "first", &child_of_bds, @@ -384,7 +377,6 @@ static void test_parallel_perm_update(void) BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 /* Select fl1 as first child to be active */ s->selected =3D c_fl1; @@ -438,13 +430,11 @@ static void test_append_greedy_filter(void) BlockDriverState *base =3D no_perm_node("base"); BlockDriverState *fl =3D exclusive_writer_node("fl1"); =20 - bdrv_drain_all_begin(); - bdrv_graph_wrlock(); + bdrv_graph_wrlock_drained(); bdrv_attach_child(top, base, "backing", &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, &error_abort); bdrv_graph_wrunlock(); - bdrv_drain_all_end(); =20 bdrv_append(fl, base, &error_abort); bdrv_unref(fl); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608400; cv=none; d=zohomail.com; s=zohoarc; b=CZBeev3VE884tndRm62A8nBe6yYdba1cwAcXXCfztHDqz9cR89h5lYfVbxkag98Go4cQPFD0lpLF16yaUPcQnaprrK8rGThOrY9U2lYNGPfhbPifqCnh04iZJxPShjO+Q454Qak0gNaM9NnE712oNtC1Ln1LgQ/DCTVwAJmFs/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608400; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0B/2XG8+KxS7pnHCp482EzG0hIY2ZE/7Mi1aO29pZNE=; b=N+wqp7Q3JxFjmd3e3RRdt5A2QVHaC4wRKN+xIELalDJ20AdZwV6g5S3ghqnEX3uaImpjG8zYPkxKSKCBDR4QUuaKYTFfmjxHcPq4TZu3ulzrq8HZUOY7K6reQhVQrrppWSwY3itPDELe6gXRZ8vN0VcwQBVxeeFIX5EAoHz9fwo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608400921644.6817174268309; Tue, 15 Jul 2025 12:40:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublV1-0004IT-E8; Tue, 15 Jul 2025 15:39:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwQ-0003YU-7O for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwO-0001F9-OU for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:49 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-Uhj__JRZOQq6leaM9e97Vg-1; Tue, 15 Jul 2025 15:03:44 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 70D971956089; Tue, 15 Jul 2025 19:03:43 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E45D9197702C; Tue, 15 Jul 2025 19:03:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606227; 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=0B/2XG8+KxS7pnHCp482EzG0hIY2ZE/7Mi1aO29pZNE=; b=S6KU93VvHGIM0vFEzazhFD4kOrgbvlsPXAi8qh0s9gtJyYbO3PLgCXcHbQrGKwWFy2aNFj HGm00GYjocTwVGWF1n2vmjVaU+ibqKJroPiYc74STVjI8BBq1OrM4NLnsVBuEMRaI8Q9OW r7qrO2OQBlfAItvvML23HlI3PKWZkQo= X-MC-Unique: Uhj__JRZOQq6leaM9e97Vg-1 X-Mimecast-MFC-AGG-ID: Uhj__JRZOQq6leaM9e97Vg_1752606223 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 03/57] block/mirror: switch to bdrv_set_backing_hd_drained() variant Date: Tue, 15 Jul 2025 21:02:36 +0200 Message-ID: <20250715190330.378764-4-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608402973116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner This is in preparation to mark bdrv_set_backing_hd() as GRAPH_UNLOCKED. Switch to using the bdrv_set_backing_hd_drained() variant, so that the drained and locked section can also cover the calls to bdrv_skip_filters() and bdrv_cow_bs(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-26-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 82a6e50cf8..873e95d029 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -761,30 +761,36 @@ static int mirror_exit_common(Job *job) bdrv_graph_rdlock_main_loop(); bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing, &error_abort); + bdrv_graph_rdunlock_main_loop(); =20 if (!abort && s->backing_mode =3D=3D MIRROR_SOURCE_BACKING_CHAIN) { BlockDriverState *backing; - BlockDriverState *unfiltered_target =3D bdrv_skip_filters(target_b= s); + BlockDriverState *unfiltered_target; + + bdrv_graph_wrlock_drained(); + unfiltered_target =3D bdrv_skip_filters(target_bs); =20 backing =3D s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE ? src : s->b= ase; if (bdrv_cow_bs(unfiltered_target) !=3D backing) { - bdrv_set_backing_hd(unfiltered_target, backing, &local_err); + bdrv_set_backing_hd_drained(unfiltered_target, backing, &local= _err); if (local_err) { error_report_err(local_err); local_err =3D NULL; ret =3D -EPERM; } } + bdrv_graph_wrunlock(); } else if (!abort && s->backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN)= { + bdrv_graph_rdlock_main_loop(); assert(!bdrv_backing_chain_next(target_bs)); ret =3D bdrv_open_backing_file(bdrv_skip_filters(target_bs), NULL, "backing", &local_err); + bdrv_graph_rdunlock_main_loop(); if (ret < 0) { error_report_err(local_err); local_err =3D NULL; } } - bdrv_graph_rdunlock_main_loop(); =20 if (s->should_complete && !abort) { BlockDriverState *to_replace =3D s->to_replace ?: src; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607860; cv=none; d=zohomail.com; s=zohoarc; b=kXj7eX5j+JRXdO1mNDIUwuCNMswMZjsHQqwLlxf723bXqgus+33HLsMwRSBYJyQqR/wtidbaj3n1Mjz6sbAoGsSJMytEbQ5W4/Q5hwQnmD2Ha0DV+izRxpuFLjYfoCydvu7oQOlKUxHeWz9nIpvJYPDn41q67OSgS/WKFCZKP9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607860; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VozVVm7+4vUKUcxr3dAo1lApjn1lz5m0QkTvFup66SM=; b=F9PhqO23YQ45JnmZLz58jz1oRHawcgGyt/NOymEhcZAKyeSKKnsbJCG2vEyc1lqiBa5B1UPsZnh6tvPmw8TZuuFv7mS2nvhmSwLD1iiQjDFzh40ykELASnFyfWVU0QVCd9RuhWQGYON2OGnpgEAUI2BM6PwlaWVEBON3A/OPUpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752607860932669.4696885788329; Tue, 15 Jul 2025 12:31:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublMS-0001of-L3; Tue, 15 Jul 2025 15:30:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwR-0003Yr-Ou for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwP-0001FN-S8 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:51 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-IYg0NmTrMCy18Kgdf7BWpg-1; Tue, 15 Jul 2025 15:03:46 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9C70D1800368; Tue, 15 Jul 2025 19:03:45 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5B09197702B; Tue, 15 Jul 2025 19:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606229; 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=VozVVm7+4vUKUcxr3dAo1lApjn1lz5m0QkTvFup66SM=; b=eBFtaJ9FANQl133d6BZ3Uwn6wz0wC4v66UT/Mb5JyfUAcpNKw1qRzLqMGGaqM/V5B790BO UMbEtfeQfqIXwa3Lw4UrGRnEiSOqRcxvLoFbss8PMtR+jU0cY4b6/RzHWljCGM6vrA4Iwv VVNP0Ucsvt0LEStHnZMmDSiiBhhSVjo= X-MC-Unique: IYg0NmTrMCy18Kgdf7BWpg-1 X-Mimecast-MFC-AGG-ID: IYg0NmTrMCy18Kgdf7BWpg_1752606225 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 04/57] block/commit: switch to bdrv_set_backing_hd_drained() variant Date: Tue, 15 Jul 2025 21:02:37 +0200 Message-ID: <20250715190330.378764-5-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607861772116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner This is in preparation to mark bdrv_set_backing_hd() as GRAPH_UNLOCKED. Switch to using the bdrv_set_backing_hd_drained() variant. For the first pair of calls to avoid draining and locking twice in a row within the individual calls. For the third call, so that the drained and locked section can also cover bdrv_cow_bs(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-27-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/commit.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/block/commit.c b/block/commit.c index dc1942483b..c9690a5da0 100644 --- a/block/commit.c +++ b/block/commit.c @@ -514,28 +514,32 @@ int bdrv_commit(BlockDriverState *bs) Error *local_err =3D NULL; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 if (!drv) return -ENOMEDIUM; =20 + bdrv_graph_rdlock_main_loop(); + backing_file_bs =3D bdrv_cow_bs(bs); =20 if (!backing_file_bs) { - return -ENOTSUP; + ret =3D -ENOTSUP; + goto out; } =20 if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_COMMIT_SOURCE, NULL) || bdrv_op_is_blocked(backing_file_bs, BLOCK_OP_TYPE_COMMIT_TARGET, N= ULL)) { - return -EBUSY; + ret =3D -EBUSY; + goto out; } =20 ro =3D bdrv_is_read_only(backing_file_bs); =20 if (ro) { if (bdrv_reopen_set_read_only(backing_file_bs, false, NULL)) { - return -EACCES; + ret =3D -EACCES; + goto out; } } =20 @@ -559,8 +563,14 @@ int bdrv_commit(BlockDriverState *bs) goto ro_cleanup; } =20 - bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); - bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); + bdrv_graph_rdunlock_main_loop(); + + bdrv_graph_wrlock_drained(); + bdrv_set_backing_hd_drained(commit_top_bs, backing_file_bs, &error_abo= rt); + bdrv_set_backing_hd_drained(bs, commit_top_bs, &error_abort); + bdrv_graph_wrunlock(); + + bdrv_graph_rdlock_main_loop(); =20 ret =3D blk_insert_bs(backing, backing_file_bs, &local_err); if (ret < 0) { @@ -635,9 +645,14 @@ int bdrv_commit(BlockDriverState *bs) ret =3D 0; ro_cleanup: blk_unref(backing); + + bdrv_graph_rdunlock_main_loop(); + bdrv_graph_wrlock_drained(); if (bdrv_cow_bs(bs) !=3D backing_file_bs) { - bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd_drained(bs, backing_file_bs, &error_abort); } + bdrv_graph_wrunlock(); + bdrv_graph_rdlock_main_loop(); bdrv_unref(commit_top_bs); blk_unref(src); =20 @@ -646,5 +661,8 @@ ro_cleanup: bdrv_reopen_set_read_only(backing_file_bs, true, NULL); } =20 +out: + bdrv_graph_rdunlock_main_loop(); + return ret; } --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608555; cv=none; d=zohomail.com; s=zohoarc; b=ZklFEka9LTFXtXIODS8RuH4A12IvH9KrMAQiRSvyRhgYKi5+P4gwhS9HISVo0wER9jHR8NtUqqbDdr3OxSQWiDQWIrrFq/hrQ+f952N83f4Df7ZW5lPN1jigKxyxsxs7egueiZlXliBTDAcZ3aH/CZJg+uV4l6WsgN3fl22M4Hg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608555; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6trNushndsv+D2tzWKPPnv40MMao6ZPGsi50y3Zk2k4=; b=BCURdwmtFcqCO8Cojt8vHr0fFN/gH4QgdFdIVZ4sVzpIXNmBaMIMzXlikV9payB2IdJJ7LiNS5cujTBB/+koHPs1Ji7Cd2f1g9J3grtae5881ho4q21qZqoW6c8d2PbUq6wKIv5GwuhmpKhGP1m9HOHRZdA96FgQcebpW+zocR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608555736805.636669094329; Tue, 15 Jul 2025 12:42:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublVL-0006Ec-EY; Tue, 15 Jul 2025 15:39:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwY-0003fL-DB for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwW-0001Gd-68 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:57 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-156-C4PmwvTaOYO_cL0G6c1GSg-1; Tue, 15 Jul 2025 15:03:48 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9F248195608C; Tue, 15 Jul 2025 19:03:47 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1EA65197702B; Tue, 15 Jul 2025 19:03:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606235; 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=6trNushndsv+D2tzWKPPnv40MMao6ZPGsi50y3Zk2k4=; b=DCrFfVxQ2V/G5LEWzxJ1QTX1WjslvycqrTx9Ne+yZSE0Tu+Ooo1r7tnf6OueXHhj5BuJdT BZudigOfDmSLkFqnsyBSBzlGvGuHcRaVxgF67eOyEzL6kZS+EFYaV3IGxTFPe1YfURrJrp IauQUaKV0vyhn5v1w5h0rjeXpQ94Klo= X-MC-Unique: C4PmwvTaOYO_cL0G6c1GSg-1 X-Mimecast-MFC-AGG-ID: C4PmwvTaOYO_cL0G6c1GSg_1752606227 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 05/57] block: call bdrv_set_backing_hd() while unlocked in bdrv_open_backing_file() Date: Tue, 15 Jul 2025 21:02:38 +0200 Message-ID: <20250715190330.378764-6-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608556332116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner This is in preparation to mark bdrv_set_backing_hd() as GRAPH_UNLOCKED. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-28-f.ebner@proxmox.com> [kwolf: Removed an extra blank line] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 1da10d55f0..9ef3b0262c 100644 --- a/block.c +++ b/block.c @@ -3632,7 +3632,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, Error *local_err =3D NULL; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); + + bdrv_graph_rdlock_main_loop(); =20 if (bs->backing !=3D NULL) { goto free_exit; @@ -3713,7 +3714,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, =20 /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ + bdrv_graph_rdunlock_main_loop(); ret =3D bdrv_set_backing_hd(bs, backing_hd, errp); + bdrv_graph_rdlock_main_loop(); bdrv_unref(backing_hd); =20 if (ret < 0) { @@ -3725,6 +3728,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, free_exit: g_free(backing_filename); qobject_unref(tmp_parent_options); + bdrv_graph_rdunlock_main_loop(); return ret; } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608835; cv=none; d=zohomail.com; s=zohoarc; b=QrjjzIRxGUV7UH1QhATgPixe9g5W61yGmCkKl5tcccSnlyzrXlH7IlTmMOgceBT6/5cAaVGG2wnWf82Pojqe+rLKuoQMEEyTA2WaRx6hG4gUjQom8QbClNzBikBGYGQNNMLW6ZSXmIhmcL01kQzh0i5a7URzRPvAo/pZSlqimBw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608835; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rd2bW5Ju0kM9EaHmRUryA+cUxt9TVzFmzt/26FPFvq8=; b=XEv8ze9t8sH5LKxR7HoM8OeS8eX9J8WfebEJBgbB8zf0tdvuGfvuXv8KcVdLTzOTQs2rTjawx3Zn6hrVSqEDzxmYSghF9lHeVO0OQPCbtoHXyXUWbKKKytULL/jdv9bXhsCjzrhu3W27LW7f4QcHgtQajrZLNjQwDx2cFBqhU1Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608835669785.6127563771171; Tue, 15 Jul 2025 12:47:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublVH-0005gz-4P; Tue, 15 Jul 2025 15:39:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwV-0003cN-PI for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwU-0001G6-5I for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:55 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-idQTrPGsM62xR43SuZ-YaQ-1; Tue, 15 Jul 2025 15:03:50 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C49E418001F9; Tue, 15 Jul 2025 19:03:49 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 209A9197702B; Tue, 15 Jul 2025 19:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606233; 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=rd2bW5Ju0kM9EaHmRUryA+cUxt9TVzFmzt/26FPFvq8=; b=Swf/1c13g4HaXX2xe+k9kofCzacqI0RgX5HVtZBoQHrGJsw8OATi40trsWn/G4FuJ4r13U D3i9gr+GdB9eIdp3k0MKi6MjmAL0o41Pi1XgFBg+rRyTVcwLxudUwkVd38M7I5vMvqi4GQ SdA9h7QgiGWCfO9idOwI/Uor0FrnbWI= X-MC-Unique: idQTrPGsM62xR43SuZ-YaQ-1 X-Mimecast-MFC-AGG-ID: idQTrPGsM62xR43SuZ-YaQ_1752606229 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 06/57] block: mark bdrv_set_backing_hd() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:39 +0200 Message-ID: <20250715190330.378764-7-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608837850116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_set_backing_hd() calls bdrv_drain_all_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-29-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 84a2a4ecd5..009b9ac946 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -100,8 +100,9 @@ bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); BlockDriverState * coroutine_fn no_co_wrapper bdrv_co_open_blockdev_ref(BlockdevRef *ref, Error **errp); =20 -int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, - Error **errp); +int GRAPH_UNLOCKED +bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, + Error **errp); int GRAPH_WRLOCK bdrv_set_backing_hd_drained(BlockDriverState *bs, BlockDriverState *backin= g_hd, Error **errp); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607905; cv=none; d=zohomail.com; s=zohoarc; b=mrrgfrF/DKqV+o+sLUEj9LMTFA0RLqTR771XAmc1WXnV97+03657V5rBk4iiYVPFAKuQEVCK8fHjPV8j87hHTg7r8HAGCOdq4o0NbgVs6fCtXfe2XSLWLBs1FnCtUR7dXRrZBHVE/UPBULwtIfS9Ctgjp73M8CjZdBhQSoqw3zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607905; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wig8VCwbp0AmNDJnIb/oPWtjxxq10qBR4IkeFYlDmpA=; b=gxygwfQ9tbgDuvwflv8Ubl827GISl5qReFfRGcGdDNUVhKuUkZSNk8l2rrgZunpYpyC7J3XYAo0lTX+JkGpQ5VYU93MnGZ5aUWSaWG4XnFAGOs5nDTI7b7QPS0MGq5XA/WIXIKN8hocVDbCcMnKRYjLR7pRR4Bn4jNW3CLcWr1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17526079050751011.7067272857664; Tue, 15 Jul 2025 12:31:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublMf-0001uB-QC; Tue, 15 Jul 2025 15:30:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwX-0003dm-0B for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwV-0001GH-32 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:56 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-456-FvH5FVZLN66gRNTP3YOR3Q-1; Tue, 15 Jul 2025 15:03:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 01385195608F; Tue, 15 Jul 2025 19:03:52 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 452E1197702B; Tue, 15 Jul 2025 19:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606234; 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=wig8VCwbp0AmNDJnIb/oPWtjxxq10qBR4IkeFYlDmpA=; b=aeppKzMAnaITlnMi6ml/lDLqzswL5FaHW1751H/5crKm79SGl70Lg4YUt5fnhZ06KKHhB6 mxjQMYj8OFwy/aNDjLBoIIqXZdsXNgS2CP3HCpReFQ0SoSH5zaViLsLmOmMG60OSvRzEMY UA1JVsfrxCIyumZ6i6lQmAs9Y3UD9NM= X-MC-Unique: FvH5FVZLN66gRNTP3YOR3Q-1 X-Mimecast-MFC-AGG-ID: FvH5FVZLN66gRNTP3YOR3Q_1752606232 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 07/57] blockdev: avoid locking and draining multiple times in external_snapshot_abort() Date: Tue, 15 Jul 2025 21:02:40 +0200 Message-ID: <20250715190330.378764-8-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607906250116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner By using the appropriate variants bdrv_set_backing_hd_drained() and bdrv_try_change_aio_context_locked(), there only needs to be a single drained and write-locked section in external_snapshot_abort(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-30-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- blockdev.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index e625534925..3c53472a23 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1580,11 +1580,19 @@ static void external_snapshot_abort(void *opaque) AioContext *tmp_context; int ret; =20 + bdrv_graph_wrlock_drained(); + aio_context =3D bdrv_get_aio_context(state->old_bs); =20 - bdrv_ref(state->old_bs); /* we can't let bdrv_set_backind_hd= () - close state->old_bs; we need it = */ - bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); + /* + * Note that state->old_bs would not disappear during the + * write-locked section, because the unref from + * bdrv_set_backing_hd_drained() only happens at the end of the + * write-locked section. However, just be explicit about keepi= ng a + * reference and don't rely on that implicit detail. + */ + bdrv_ref(state->old_bs); + bdrv_set_backing_hd_drained(state->new_bs, NULL, &error_abort); =20 /* * The call to bdrv_set_backing_hd() above returns state->old_= bs to @@ -1593,16 +1601,14 @@ static void external_snapshot_abort(void *opaque) */ tmp_context =3D bdrv_get_aio_context(state->old_bs); if (aio_context !=3D tmp_context) { - ret =3D bdrv_try_change_aio_context(state->old_bs, - aio_context, NULL, NULL); + ret =3D bdrv_try_change_aio_context_locked(state->old_bs, + aio_context, NULL, + NULL); assert(ret =3D=3D 0); } =20 - bdrv_drained_begin(state->new_bs); - bdrv_graph_wrlock(); bdrv_replace_node(state->new_bs, state->old_bs, &error_abort); bdrv_graph_wrunlock(); - bdrv_drained_end(state->new_bs); =20 bdrv_unref(state->old_bs); /* bdrv_replace_node() ref'ed old_b= s */ } --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607918; cv=none; d=zohomail.com; s=zohoarc; b=H1FP6HoMeQL690hKveuN0KqHzXQoI55RV0kGo0nx5PeSaJ9jXJsBdFmVtLBFmD2+H04vEklBZhw812iyYu8+UC6uQdUUiVGHHIrni8giAhiW1KtnnN5GjFjMSqZlDxA/EsNTRG0pWEOMVU38pXPmZ2UfQn4yU357GIWA3XvpsvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607918; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=68D7OkwdVd3bP6nYCJxOTZBsJbFiTqIIgPgBUBDKP90=; b=nc6fVr+ZiNCMXGzZijYeho/U3yIQ2jaKZM0r4Rz9ky9Pjfd+aHiUR+OxF0e91uGJV3buaYSNzs076l8Xcn3bhYR3Lj/n/5MbEUYuHL4MrGDQXCENJvCkWvRQr2/kyadZpPdjUeT1kM46+c9K0aXYmE9SXxR2OVZJRm8yp6nvdzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752607918242338.1403300840425; Tue, 15 Jul 2025 12:31:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublN3-0002LO-K2; Tue, 15 Jul 2025 15:31:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwZ-0003hb-Vl for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwX-0001Gt-Jy for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:03:59 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-UXn3L_r7NVutY6x1PkifPQ-1; Tue, 15 Jul 2025 15:03:55 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3DB55195608F; Tue, 15 Jul 2025 19:03:54 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76D80197702B; Tue, 15 Jul 2025 19:03:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606236; 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=68D7OkwdVd3bP6nYCJxOTZBsJbFiTqIIgPgBUBDKP90=; b=aZtobncsaRFzfYe0iT2HmWkdUQiP6enboaOrDcRxgFPIAWq9ZvyRmx7SFDI7vPPMFASmfu K74WMJ+ptbQ0tweKLiYAt4xR6v76zgVvLlh5g3AA4RBQQgIzWHbFQ/n/4exyOyZYb/eLp9 fr//RdrntA90r5Em6xye9bxl1GNZNs4= X-MC-Unique: UXn3L_r7NVutY6x1PkifPQ-1 X-Mimecast-MFC-AGG-ID: UXn3L_r7NVutY6x1PkifPQ_1752606234 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 08/57] block: drop wrapper for bdrv_set_backing_hd_drained() Date: Tue, 15 Jul 2025 21:02:41 +0200 Message-ID: <20250715190330.378764-9-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607920348116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner Nearly all callers (outside of the tests) are already using the _drained() variant of the function. It doesn't seem worth keeping. Simply adapt the remaining callers of bdrv_set_backing_hd() and rename bdrv_set_backing_hd_drained() to bdrv_set_backing_hd(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-31-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 5 +---- block.c | 20 ++++---------------- block/commit.c | 6 +++--- block/mirror.c | 2 +- block/stream.c | 13 ++++++------- blockdev.c | 13 ++++++++----- tests/unit/test-bdrv-drain.c | 12 +++++++++++- tests/unit/test-bdrv-graph-mod.c | 2 +- 8 files changed, 35 insertions(+), 38 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 009b9ac946..bcbb624a7b 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -100,12 +100,9 @@ bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); BlockDriverState * coroutine_fn no_co_wrapper bdrv_co_open_blockdev_ref(BlockdevRef *ref, Error **errp); =20 -int GRAPH_UNLOCKED +int GRAPH_WRLOCK bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, Error **errp); -int GRAPH_WRLOCK -bdrv_set_backing_hd_drained(BlockDriverState *bs, BlockDriverState *backin= g_hd, - Error **errp); =20 int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp); diff --git a/block.c b/block.c index 9ef3b0262c..4754705bfd 100644 --- a/block.c +++ b/block.c @@ -3570,9 +3570,8 @@ out: * * All block nodes must be drained. */ -int bdrv_set_backing_hd_drained(BlockDriverState *bs, - BlockDriverState *backing_hd, - Error **errp) +int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, + Error **errp) { int ret; Transaction *tran =3D tran_new(); @@ -3594,19 +3593,6 @@ out: return ret; } =20 -int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, - Error **errp) -{ - int ret; - GLOBAL_STATE_CODE(); - - bdrv_graph_wrlock_drained(); - ret =3D bdrv_set_backing_hd_drained(bs, backing_hd, errp); - bdrv_graph_wrunlock(); - - return ret; -} - /* * Opens the backing file for a BlockDriverState if not yet open * @@ -3715,7 +3701,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ bdrv_graph_rdunlock_main_loop(); + bdrv_graph_wrlock_drained(); ret =3D bdrv_set_backing_hd(bs, backing_hd, errp); + bdrv_graph_wrunlock(); bdrv_graph_rdlock_main_loop(); bdrv_unref(backing_hd); =20 diff --git a/block/commit.c b/block/commit.c index c9690a5da0..7496cf732e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -566,8 +566,8 @@ int bdrv_commit(BlockDriverState *bs) bdrv_graph_rdunlock_main_loop(); =20 bdrv_graph_wrlock_drained(); - bdrv_set_backing_hd_drained(commit_top_bs, backing_file_bs, &error_abo= rt); - bdrv_set_backing_hd_drained(bs, commit_top_bs, &error_abort); + bdrv_set_backing_hd(commit_top_bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd(bs, commit_top_bs, &error_abort); bdrv_graph_wrunlock(); =20 bdrv_graph_rdlock_main_loop(); @@ -649,7 +649,7 @@ ro_cleanup: bdrv_graph_rdunlock_main_loop(); bdrv_graph_wrlock_drained(); if (bdrv_cow_bs(bs) !=3D backing_file_bs) { - bdrv_set_backing_hd_drained(bs, backing_file_bs, &error_abort); + bdrv_set_backing_hd(bs, backing_file_bs, &error_abort); } bdrv_graph_wrunlock(); bdrv_graph_rdlock_main_loop(); diff --git a/block/mirror.c b/block/mirror.c index 873e95d029..b344182c74 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -772,7 +772,7 @@ static int mirror_exit_common(Job *job) =20 backing =3D s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE ? src : s->b= ase; if (bdrv_cow_bs(unfiltered_target) !=3D backing) { - bdrv_set_backing_hd_drained(unfiltered_target, backing, &local= _err); + bdrv_set_backing_hd(unfiltered_target, backing, &local_err); if (local_err) { error_report_err(local_err); local_err =3D NULL; diff --git a/block/stream.c b/block/stream.c index a6ef840e29..17e240460c 100644 --- a/block/stream.c +++ b/block/stream.c @@ -73,12 +73,11 @@ static int stream_prepare(Job *job) s->cor_filter_bs =3D NULL; =20 /* - * bdrv_set_backing_hd() requires that the unfiltered_bs and the COW c= hild - * of unfiltered_bs is drained. Drain already here and use - * bdrv_set_backing_hd_drained() instead because the polling during - * drained_begin() might change the graph, and if we do this only late= r, we - * may end up working with the wrong base node (or it might even have = gone - * away by the time we want to use it). + * bdrv_set_backing_hd() requires that all block nodes are drained. Dr= ain + * already here, because the polling during drained_begin() might chan= ge the + * graph, and if we do this only later, we may end up working with the= wrong + * base node (or it might even have gone away by the time we want to u= se + * it). */ if (unfiltered_bs_cow) { bdrv_ref(unfiltered_bs_cow); @@ -105,7 +104,7 @@ static int stream_prepare(Job *job) } =20 bdrv_graph_wrlock(); - bdrv_set_backing_hd_drained(unfiltered_bs, base, &local_err); + bdrv_set_backing_hd(unfiltered_bs, base, &local_err); bdrv_graph_wrunlock(); =20 /* diff --git a/blockdev.c b/blockdev.c index 3c53472a23..9f3f42d896 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1587,12 +1587,12 @@ static void external_snapshot_abort(void *opaque) /* * Note that state->old_bs would not disappear during the * write-locked section, because the unref from - * bdrv_set_backing_hd_drained() only happens at the end of the - * write-locked section. However, just be explicit about keepi= ng a - * reference and don't rely on that implicit detail. + * bdrv_set_backing_hd() only happens at the end of the write-= locked + * section. However, just be explicit about keeping a referenc= e and + * don't rely on that implicit detail. */ bdrv_ref(state->old_bs); - bdrv_set_backing_hd_drained(state->new_bs, NULL, &error_abort); + bdrv_set_backing_hd(state->new_bs, NULL, &error_abort); =20 /* * The call to bdrv_set_backing_hd() above returns state->old_= bs to @@ -1776,7 +1776,10 @@ static void drive_backup_action(DriveBackup *backup, } =20 if (set_backing_hd) { - if (bdrv_set_backing_hd(target_bs, source, errp) < 0) { + bdrv_graph_wrlock_drained(); + ret =3D bdrv_set_backing_hd(target_bs, source, errp); + bdrv_graph_wrunlock(); + if (ret < 0) { goto unref; } } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 3369c2c2aa..43b0ba8648 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -193,7 +193,9 @@ static BlockBackend * no_coroutine_fn test_setup(void) blk_insert_bs(blk, bs, &error_abort); =20 backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(bs, backing, &error_abort); + bdrv_graph_wrunlock(); =20 bdrv_unref(backing); bdrv_unref(bs); @@ -386,7 +388,9 @@ static void test_nested(void) =20 backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); backing_s =3D backing->opaque; + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(bs, backing, &error_abort); + bdrv_graph_wrunlock(); =20 for (outer =3D 0; outer < DRAIN_TYPE_MAX; outer++) { for (inner =3D 0; inner < DRAIN_TYPE_MAX; inner++) { @@ -733,10 +737,12 @@ static void test_blockjob_common_drain_node(enum drai= n_type drain_type, src_overlay =3D bdrv_new_open_driver(&bdrv_test, "source-overlay", BDRV_O_RDWR, &error_abort); =20 + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(src_overlay, src, &error_abort); bdrv_unref(src); bdrv_set_backing_hd(src, src_backing, &error_abort); bdrv_unref(src_backing); + bdrv_graph_wrunlock(); =20 blk_src =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL= ); blk_insert_bs(blk_src, src_overlay, &error_abort); @@ -1436,8 +1442,10 @@ static void test_drop_backing_job_commit(Job *job) TestDropBackingBlockJob *s =3D container_of(job, TestDropBackingBlockJob, common.job); =20 + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(s->bs, NULL, &error_abort); bdrv_set_backing_hd(s->detach_also, NULL, &error_abort); + bdrv_graph_wrunlock(); =20 *s->did_complete =3D true; } @@ -1530,7 +1538,9 @@ static void test_blockjob_commit_by_drained_end(void) snprintf(name, sizeof(name), "parent-node-%i", i); bs_parents[i] =3D bdrv_new_open_driver(&bdrv_test, name, BDRV_O_RD= WR, &error_abort); + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(bs_parents[i], bs_child, &error_abort); + bdrv_graph_wrunlock(); } =20 job =3D block_job_create("job", &test_drop_backing_job_driver, NULL, @@ -1679,13 +1689,13 @@ static void test_drop_intermediate_poll(void) =20 job_node =3D bdrv_new_open_driver(&bdrv_test, "job-node", BDRV_O_RDWR, &error_abort); + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(job_node, chain[1], &error_abort); =20 /* * Establish the chain last, so the chain links are the first * elements in the BDS.parents lists */ - bdrv_graph_wrlock_drained(); for (i =3D 0; i < 3; i++) { if (i) { /* Takes the reference to chain[i - 1] */ diff --git a/tests/unit/test-bdrv-graph-mod.c b/tests/unit/test-bdrv-graph-= mod.c index b077f0e3e3..567db99e4f 100644 --- a/tests/unit/test-bdrv-graph-mod.c +++ b/tests/unit/test-bdrv-graph-mod.c @@ -202,9 +202,9 @@ static void test_should_update_child(void) =20 blk_insert_bs(root, bs, &error_abort); =20 + bdrv_graph_wrlock_drained(); bdrv_set_backing_hd(target, bs, &error_abort); =20 - bdrv_graph_wrlock_drained(); g_assert(target->backing->bs =3D=3D bs); bdrv_attach_child(filter, target, "target", &child_of_bds, BDRV_CHILD_DATA, &error_abort); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608118; cv=none; d=zohomail.com; s=zohoarc; b=f46dCv0r0yprpykdbjt1m6t+vrHglI14Bbica1c1AqB/SAeFhszB67N/zbKZKSknPSPJq1qV/Pqjpa9Jdn549l1wpAe4f7tqNQI53L5+E1D3aY3iwVNFpWm7XVvRMW8VvAeWJMjKmqPIvBYZ3NEVlt6gTeJlgfisZSSQjgxWIpk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608118; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=I4rpNJx9xt2aKcvtEArA5OSXE4bNZXvUquKQfRJEfXg=; b=n5WtJOLQ7ym2lWyo5wVt40Re9qkcW3aQmwrLJIN0Ya7LIsRwEVcF+7wVuc9mnQATrBlXi8BwZmfrNkWh+m5bjjpuJTjsA412nT17FimFYCYaaB49kBIgEujprppQFISIOGtDSdxzCR1Qa9UBLuHkK7NWOJjWy2hq+pdJV8rTimg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608118509977.0402846073156; Tue, 15 Jul 2025 12:35:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQa-0003u6-6f; Tue, 15 Jul 2025 15:35:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwb-0003kQ-Ks for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwZ-0001HT-QB for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:01 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-QuDNlUV-MxedkRvVnxtVBw-1; Tue, 15 Jul 2025 15:03:57 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4881218001DD; Tue, 15 Jul 2025 19:03:56 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B255D197702B; Tue, 15 Jul 2025 19:03:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606239; 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=I4rpNJx9xt2aKcvtEArA5OSXE4bNZXvUquKQfRJEfXg=; b=cJkf2O4ekuwqw1HpNwDigaCP6Iy8pQiZxfwmzuRafLi9Cn4RKtI5l3N20Ct/Uy5fFaDu2c ocxOF4OKNYXFd6LuFJCIIgz3t6Uv1aXwM9AEeqSvCE2isW/HKc8cf18PSCzMqT0ohbFaS/ DPqvFogyPJXbOqsGIDOEMUpTH1/0JuI= X-MC-Unique: QuDNlUV-MxedkRvVnxtVBw-1 X-Mimecast-MFC-AGG-ID: QuDNlUV-MxedkRvVnxtVBw_1752606236 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 09/57] block-backend: mark blk_drain_all() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:42 +0200 Message-ID: <20250715190330.378764-10-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608120347116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function blk_drain_all() calls bdrv_drain_all_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-32-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/system/block-backend-global-state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/system/block-backend-global-state.h b/include/system/b= lock-backend-global-state.h index 35b5e8380b..a62dbdf0dc 100644 --- a/include/system/block-backend-global-state.h +++ b/include/system/block-backend-global-state.h @@ -79,7 +79,7 @@ void blk_aio_cancel(BlockAIOCB *acb); int blk_commit_all(void); bool blk_in_drain(BlockBackend *blk); void blk_drain(BlockBackend *blk); -void blk_drain_all(void); +void GRAPH_UNLOCKED blk_drain_all(void); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, BlockdevOnError on_write_error); bool blk_supports_write_perm(BlockBackend *blk); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608488; cv=none; d=zohomail.com; s=zohoarc; b=LZq3xOTmG5u5BGE/RreNarvUPZ7W0PcGUCWPjx6G70zWD+jFuFUo2r5KI1MMIGozaMYCF315OI55AK7s4y5Sv9+v+v38BjqOWCusZCppTOm/uGIcaumSCGiyDCoCpXBKjgXz4ow9GDodjWlqt9fYwxZEIYm99YJrRp562HBjw54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608488; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g6wbfJ8bu+RE8DlR1CZafLa6EWF9NJdAu+OwbSDIBAw=; b=ZYGfqlpQYlPl3J9vK/PTLgAsE20+HWwxK7q4fdAmO9u3klI2MhWiAcDQ4FLQTb8jth4JW3fl4AQTBNTmS0Uw46AaVfdIZVRhdPURFvvTrRA26vbvcFhFWOHXZQulGCqQDw3nJqsN3vrX2T4La17Y+Q4RD4a1Wnw72wJA4KayWU0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608488535889.7650251276442; Tue, 15 Jul 2025 12:41:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQo-0004wb-K1; Tue, 15 Jul 2025 15:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwk-0003vA-WA for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwj-0001JN-5s for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:10 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-557-IwaFEtVWPeGzYrCUONepWA-1; Tue, 15 Jul 2025 15:03:59 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5FF8918001D6; Tue, 15 Jul 2025 19:03:58 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BE441197702B; Tue, 15 Jul 2025 19:03:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606248; 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=g6wbfJ8bu+RE8DlR1CZafLa6EWF9NJdAu+OwbSDIBAw=; b=ejq6+wLiGzErmup7WRX+D3qtc1WS5F6Ed7neZ42xjuvBjH+WcEFyS+8RE++lK73ZHwawLW 8It9ZfBXpqkxK6Lzj5gtex0tpM4ZToHMa4r7CcoogCY+L6nON11OpZ21FsdIWh7xBTANm6 gscDC61oWmW1iSpYuACZo1FT0qrN690= X-MC-Unique: IwaFEtVWPeGzYrCUONepWA-1 X-Mimecast-MFC-AGG-ID: IwaFEtVWPeGzYrCUONepWA_1752606238 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 10/57] block/snapshot: mark bdrv_all_delete_snapshot() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:43 +0200 Message-ID: <20250715190330.378764-11-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608489740116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_all_delete_snapshot() calls bdrv_drain_all_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-33-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/snapshot.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/block/snapshot.h b/include/block/snapshot.h index 304cc6ea61..2316a43e26 100644 --- a/include/block/snapshot.h +++ b/include/block/snapshot.h @@ -90,9 +90,9 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState= *bs, =20 bool bdrv_all_can_snapshot(bool has_devices, strList *devices, Error **errp); -int bdrv_all_delete_snapshot(const char *name, - bool has_devices, strList *devices, - Error **errp); +int GRAPH_UNLOCKED +bdrv_all_delete_snapshot(const char *name, bool has_devices, strList *devi= ces, + Error **errp); int bdrv_all_goto_snapshot(const char *name, bool has_devices, strList *devices, Error **errp); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608701; cv=none; d=zohomail.com; s=zohoarc; b=QHQDpSt7Z9fdNCNoK/NjMfKhOgQWMQDfJz66wvNx7pgDkSu90VVDYxUmspfqwbits1/UBBhRLfzAc9jY/vZkOyT0ADGLPewY5D/u6WMqXgJCbpVw6cZ5+J1sVjYNaEpivikJeBb32l1Jrm7KO4z9TkhKIOVjm+FNR2NW0jAlqzw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608701; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=o1hSbirm0FeR7HEVUY1DNIhxsSnwTVjUfV1F5k4OPBg=; b=NE+0Gph/28LhkWh6mocb9tegtJ7BW+Ujvxg0KEahhObxXrmJjgo89TjTQh5jUCjz28O+03do2Vy0/OhYJBMFdxgohiumwuB5l0KFNjjmAZnnDlpWN7emrRJ0FnBFD00DpErF/3aUT3M04oY7n5vytYLENo8P1wisNvreoUBbso8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608701319213.37361191974514; Tue, 15 Jul 2025 12:45:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublW7-0006lm-VG; Tue, 15 Jul 2025 15:40:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwg-0003pe-F4 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwe-0001IX-QC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:06 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-RH-eXnsPPsONcMRZ0BKgzw-1; Tue, 15 Jul 2025 15:04:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6253618001F9; Tue, 15 Jul 2025 19:04:00 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D4C09197702B; Tue, 15 Jul 2025 19:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606243; 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=o1hSbirm0FeR7HEVUY1DNIhxsSnwTVjUfV1F5k4OPBg=; b=CorILoU5kCmjusFkAWxRHrACJd+f7JUkvArNVqayRDNIb0/XS+8UPliCJ12vyXIgPWo2II SyJdd9eA/NQ42Wk601pP7NvmpL2SXcVnvJcJufmHJb8FwRnBsz61dyLx3bHzBaSk81AGJN 0b7bUiKGv8+RdFOteAPcfpI6L8ceUzg= X-MC-Unique: RH-eXnsPPsONcMRZ0BKgzw-1 X-Mimecast-MFC-AGG-ID: RH-eXnsPPsONcMRZ0BKgzw_1752606240 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 11/57] block/stream: mark stream_prepare() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:44 +0200 Message-ID: <20250715190330.378764-12-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608701899116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function stream_prepare() calls bdrv_drain_all_begin(), which must be called with the graph unlocked. Also mark the JobDriver's prepare() callback as GRAPH_UNLOCKED_PTR, because that is the callback via which stream_prepare() is reached. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-34-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/qemu/job.h | 2 +- block/stream.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/job.h b/include/qemu/job.h index a5a04155ea..bb8ee766ef 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -263,7 +263,7 @@ struct JobDriver { * This callback will not be invoked if the job has already failed. * If it fails, abort and then clean will be called. */ - int (*prepare)(Job *job); + int GRAPH_UNLOCKED_PTR (*prepare)(Job *job); =20 /** * If the callback is not NULL, it will be invoked when all the jobs diff --git a/block/stream.c b/block/stream.c index 17e240460c..c0616b69e2 100644 --- a/block/stream.c +++ b/block/stream.c @@ -51,7 +51,7 @@ static int coroutine_fn stream_populate(BlockBackend *blk, return blk_co_preadv(blk, offset, bytes, NULL, BDRV_REQ_PREFETCH); } =20 -static int stream_prepare(Job *job) +static int GRAPH_UNLOCKED stream_prepare(Job *job) { StreamBlockJob *s =3D container_of(job, StreamBlockJob, common.job); BlockDriverState *unfiltered_bs; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608359; cv=none; d=zohomail.com; s=zohoarc; b=BFQdfeDRfRTHZoR1+yYVAvv19RhmnIGP/R+ifrXNihNr7d25sTrvdVj9qAKQQbHSlKDLMe6DGxIHGTFOz0rTn0GSK+ANpngKCSYiXGzp2HjGBCY1YjY0G+O3X3GrcJtpXcbRnWBzLw5vMC9byv2BAaEcOHWdpda0HXmo3QKmO94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608359; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dsMwsThFLoJaZZKZ4zj+/Nv7SnOyR7h5y7MYGS1V5ug=; b=ROm7UWc43Q9lswXrXSMckkcjr9wArWwLGrGtzTEHJAwBLZe6ZUdn/qsN3f+yZmm0rL18SrQWOnp+k0fnfYUEofpAiFcd2Mae++Z5sEXapD+pyAw2dM6KCoBMMkgTdYmAhUJEWqMqqy6ZqI7SePF1NDhGF96u4t35A1pno6AWnJE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608359430841.2688985128383; Tue, 15 Jul 2025 12:39:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQk-0004dX-Aw; Tue, 15 Jul 2025 15:35:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwj-0003t5-0y for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwh-0001J8-Be for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:08 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-494-vELb6pa-PLWpepkxvfZwvA-1; Tue, 15 Jul 2025 15:04:03 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 62FF61956087; Tue, 15 Jul 2025 19:04:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D6DCB197702C; Tue, 15 Jul 2025 19:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606246; 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=dsMwsThFLoJaZZKZ4zj+/Nv7SnOyR7h5y7MYGS1V5ug=; b=fQkwW3DjlOEgkNq31CcaIXSMqizT1e24IyKOPF4kuH2iF//havEyhaJNMchw6os9KsIIY5 dtKakqlancbPv3xbnbddS7g/c9QMFpmCo6LAVLy/redEkfDhG2HBSHx0scGpjNyr1dlqn+ 0TeGRtCx7XyV1c93ZtND9Msf7NMeGL4= X-MC-Unique: vELb6pa-PLWpepkxvfZwvA-1 X-Mimecast-MFC-AGG-ID: vELb6pa-PLWpepkxvfZwvA_1752606242 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 12/57] block: mark bdrv_reopen_queue() and bdrv_reopen_multiple() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:45 +0200 Message-ID: <20250715190330.378764-13-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608360528116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_reopen_queue() can call bdrv_drain_all_begin(), which must be called with the graph unlocked. The function bdrv_reopen_multiple() calls bdrv_reopen_prepare() which must be called with the graph unlocked. To mark bdrv_reopen_queue() as GRAPH_UNLOCKED, it is necessary to make the locked section in reopen_backing_file() shorter. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-35-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 9 +++++---- block/replication.c | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index bcbb624a7b..f25c65c1b4 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -121,11 +121,12 @@ BlockDriverState *bdrv_new_open_driver_opts(BlockDriv= er *drv, Error **errp); BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_= name, int flags, Error **errp); -BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue, - BlockDriverState *bs, QDict *options, - bool keep_old_opts); +BlockReopenQueue * GRAPH_UNLOCKED +bdrv_reopen_queue(BlockReopenQueue *bs_queue, BlockDriverState *bs, + QDict *options, bool keep_old_opts); void bdrv_reopen_queue_free(BlockReopenQueue *bs_queue); -int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp); +int GRAPH_UNLOCKED +bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp); int bdrv_reopen(BlockDriverState *bs, QDict *opts, bool keep_old_opts, Error **errp); int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only, diff --git a/block/replication.c b/block/replication.c index 83978b61f5..3a431e908c 100644 --- a/block/replication.c +++ b/block/replication.c @@ -364,14 +364,15 @@ static void reopen_backing_file(BlockDriverState *bs,= bool writable, BlockReopenQueue *reopen_queue =3D NULL; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 + bdrv_graph_rdlock_main_loop(); /* * s->hidden_disk and s->secondary_disk may not be set yet, as they wi= ll * only be set after the children are writable. */ hidden_disk =3D bs->file->bs->backing; secondary_disk =3D hidden_disk->bs->backing; + bdrv_graph_rdunlock_main_loop(); =20 if (writable) { s->orig_hidden_read_only =3D bdrv_is_read_only(hidden_disk->bs); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608496; cv=none; d=zohomail.com; s=zohoarc; b=R7Mhcuaig4RnPjVxiyyRvSHhA6z6xLI4Sn3rm/5k7PzWaTaI3mIyZnig1Dus+9Ux2BNVtVeoUzO8UbOBPlnZ3Ut9YvEej+SfVF7E5GLC6FY0jsIYE0rpTu2fqdKhSZ45jFStxbN2QsoDEg9JIn+edmD/x7Dcqq8h2QNDTc3AdW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608496; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5SzqBoKbn6ZBWj7S0TT0Fnn+fztMNR9VR1UPKe8EtBA=; b=bfRCk6UoKYTyOvBMmEBBliPRZLa7eQ5Mq01Bsla5vavb4FCfgp5MZPdn5QOdLr78jOGbr9K64X4npFcF+FF6WAa2LEpPB0/RTF8irwRWQUWYUCBz9M2AJlqLnZOPxGxR99PcOuUgirwE5M/Cmi+1+BnGbo6/JFb+mPFF44hJjoo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608496148824.0721813644703; Tue, 15 Jul 2025 12:41:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublWm-0007cR-MK; Tue, 15 Jul 2025 15:41:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwk-0003uA-B9 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwi-0001JG-8f for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:10 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-cE1AuyjvNxuBsUfCl3WI9w-1; Tue, 15 Jul 2025 15:04:05 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 762DF180029E; Tue, 15 Jul 2025 19:04:04 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D7489197702C; Tue, 15 Jul 2025 19:04:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606247; 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=5SzqBoKbn6ZBWj7S0TT0Fnn+fztMNR9VR1UPKe8EtBA=; b=OEfQrPR7wmE9qE0J1PPu3w50zxrmG4L1gFdGFEVHPB8j9fP7kEI0i7cEET+nTpYyb+Ayo+ GGKA3LLnvCv2nu18sRl6ebJJL4l0RloyeVB0z5zia1yxgrvEPFEx7n2dpOtgoTPRMD5992 DK7023n9ObgiEIXNhIk6a2RKyWnticc= X-MC-Unique: cE1AuyjvNxuBsUfCl3WI9w-1 X-Mimecast-MFC-AGG-ID: cE1AuyjvNxuBsUfCl3WI9w_1752606244 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 13/57] block: mark bdrv_inactivate() as GRAPH_RDLOCK and move drain to callers Date: Tue, 15 Jul 2025 21:02:46 +0200 Message-ID: <20250715190330.378764-14-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608498209116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_inactivate() calls bdrv_drain_all_begin(), which needs to be called with the graph unlocked, so either bdrv_inactivate() should be marked as GRAPH_UNLOCKED or the drain needs to be moved to the callers. The caller in qmp_blockdev_set_active() requires that the locked section covers bdrv_find_node() too, so the latter alternative is chosen. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-36-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 2 +- block.c | 14 ++---- blockdev.c | 73 ++++++++++++++++++------------ 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index f25c65c1b4..a641beb270 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -183,7 +183,7 @@ bdrv_activate(BlockDriverState *bs, Error **errp); int coroutine_fn no_co_wrapper_bdrv_rdlock bdrv_co_activate(BlockDriverState *bs, Error **errp); =20 -int no_coroutine_fn +int no_coroutine_fn GRAPH_RDLOCK bdrv_inactivate(BlockDriverState *bs, Error **errp); =20 void bdrv_activate_all(Error **errp); diff --git a/block.c b/block.c index 4754705bfd..932e599f45 100644 --- a/block.c +++ b/block.c @@ -7058,31 +7058,25 @@ bdrv_inactivate_recurse(BlockDriverState *bs, bool = top_level) return 0; } =20 +/* All block nodes must be drained. */ int bdrv_inactivate(BlockDriverState *bs, Error **errp) { int ret; =20 GLOBAL_STATE_CODE(); =20 - bdrv_drain_all_begin(); - bdrv_graph_rdlock_main_loop(); - if (bdrv_has_bds_parent(bs, true)) { error_setg(errp, "Node has active parent node"); - ret =3D -EPERM; - goto out; + return -EPERM; } =20 ret =3D bdrv_inactivate_recurse(bs, true); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to inactivate node"); - goto out; + return ret; } =20 -out: - bdrv_graph_rdunlock_main_loop(); - bdrv_drain_all_end(); - return ret; + return 0; } =20 int bdrv_inactivate_all(void) diff --git a/blockdev.c b/blockdev.c index 9f3f42d896..b451fee6e1 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1421,7 +1421,7 @@ static void external_snapshot_action(TransactionActio= n *action, bdrv_graph_rdunlock_main_loop(); /* Paired with .clean() */ bdrv_drained_begin(state->old_bs); - GRAPH_RDLOCK_GUARD_MAINLOOP(); + bdrv_graph_rdlock_main_loop(); =20 /* Make sure the associated bs did not change with the drain. */ check_bs =3D bdrv_lookup_bs(device, node_name, errp); @@ -1430,18 +1430,18 @@ static void external_snapshot_action(TransactionAct= ion *action, error_setg(errp, "Block node of device '%s' unexpectedly chang= ed", device); } /* else errp is already set */ - return; + goto unlock; } =20 if (!bdrv_is_inserted(state->old_bs)) { error_setg(errp, "Device '%s' has no medium", bdrv_get_device_or_node_name(state->old_bs)); - return; + goto unlock; } =20 if (bdrv_op_is_blocked(state->old_bs, BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT, errp)) { - return; + goto unlock; } =20 if (!bdrv_is_read_only(state->old_bs)) { @@ -1449,7 +1449,7 @@ static void external_snapshot_action(TransactionActio= n *action, if (ret < 0) { error_setg_errno(errp, -ret, "Write to node '%s' failed", bdrv_get_device_or_node_name(state->old_bs)); - return; + goto unlock; } } =20 @@ -1461,13 +1461,13 @@ static void external_snapshot_action(TransactionAct= ion *action, =20 if (node_name && !snapshot_node_name) { error_setg(errp, "New overlay node-name missing"); - return; + goto unlock; } =20 if (snapshot_node_name && bdrv_lookup_bs(snapshot_node_name, snapshot_node_name, NULL)) { error_setg(errp, "New overlay node-name already in use"); - return; + goto unlock; } =20 flags =3D state->old_bs->open_flags; @@ -1480,7 +1480,7 @@ static void external_snapshot_action(TransactionActio= n *action, int64_t size =3D bdrv_getlength(state->old_bs); if (size < 0) { error_setg_errno(errp, -size, "bdrv_getlength failed"); - return; + goto unlock; } bdrv_refresh_filename(state->old_bs); =20 @@ -1491,7 +1491,7 @@ static void external_snapshot_action(TransactionActio= n *action, =20 if (local_err) { error_propagate(errp, local_err); - return; + goto unlock; } } =20 @@ -1507,7 +1507,7 @@ static void external_snapshot_action(TransactionActio= n *action, =20 /* We will manually add the backing_hd field to the bs later */ if (!state->new_bs) { - return; + goto unlock; } =20 /* @@ -1518,22 +1518,22 @@ static void external_snapshot_action(TransactionAct= ion *action, bdrv_get_cumulative_perm(state->new_bs, &perm, &shared); if (perm & BLK_PERM_CONSISTENT_READ) { error_setg(errp, "The overlay is already in use"); - return; + goto unlock; } =20 if (state->new_bs->drv->is_filter) { error_setg(errp, "Filters cannot be used as overlays"); - return; + goto unlock; } =20 if (bdrv_cow_child(state->new_bs)) { error_setg(errp, "The overlay already has a backing image"); - return; + goto unlock; } =20 if (!state->new_bs->drv->supports_backing) { error_setg(errp, "The overlay does not support backing images"); - return; + goto unlock; } =20 /* @@ -1546,17 +1546,23 @@ static void external_snapshot_action(TransactionAct= ion *action, * to keep this working. */ if (bdrv_is_inactive(state->old_bs) && !bdrv_is_inactive(state->new_bs= )) { + bdrv_graph_rdunlock_main_loop(); + bdrv_drain_all_begin(); + bdrv_graph_rdlock_main_loop(); ret =3D bdrv_inactivate(state->new_bs, errp); + bdrv_drain_all_end(); if (ret < 0) { - return; + goto unlock; } } =20 ret =3D bdrv_append(state->new_bs, state->old_bs, errp); if (ret < 0) { - return; + goto unlock; } state->overlay_appended =3D true; +unlock: + bdrv_graph_rdunlock_main_loop(); } =20 static void external_snapshot_commit(void *opaque) @@ -3520,10 +3526,10 @@ void qmp_blockdev_del(const char *node_name, Error = **errp) =20 void qmp_blockdev_set_active(const char *node_name, bool active, Error **e= rrp) { + BlockDriverState *bs; int ret; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 if (!node_name) { if (active) { @@ -3534,19 +3540,30 @@ void qmp_blockdev_set_active(const char *node_name,= bool active, Error **errp) error_setg_errno(errp, -ret, "Failed to inactivate all nod= es"); } } + return; + } + + if (!active) { + bdrv_drain_all_begin(); + } + bdrv_graph_rdlock_main_loop(); + + bs =3D bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Failed to find node with node-name=3D'%s'", + node_name); + goto unlock; + } + if (active) { + bdrv_activate(bs, errp); } else { - BlockDriverState *bs =3D bdrv_find_node(node_name); - if (!bs) { - error_setg(errp, "Failed to find node with node-name=3D'%s'", - node_name); - return; - } + bdrv_inactivate(bs, errp); + } =20 - if (active) { - bdrv_activate(bs, errp); - } else { - bdrv_inactivate(bs, errp); - } +unlock: + bdrv_graph_rdunlock_main_loop(); + if (!active) { + bdrv_drain_all_end(); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607960; cv=none; d=zohomail.com; s=zohoarc; b=lgMeTi459/yUuVkPDopfzV19qLylxpzezO2p/FRhBLnmAkaE8kyPVs1C0NUHkJTFAK6Uc2Lb+R4DtIgIWKsZTGCKAMnAQWclV1XHR6ZgeK8pk2kIycssSiS5VF/arbSn5mi/grySnLb4koDO76M1ox2vJJ0+gYhvlsMUcPBn7mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607960; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=wdX9/ob2up+SGwd6KFjGchxjspQJLVewUW54m9JacRw=; b=izCR0WK5PnqsKEeoxR6MbTY5cFPs98knqsWhu0ARPyDj0J/sm06K493PDD7e/v+cujTSgA5ZwK4gBs3C+qfjHed8zJiPJowtiOjrzfuaZWh1JNjV6VQ41ZBy7Jlwp0XP9oUB4BloLoyGmIljzS3iahJlcS4wFNnosNRnMGsARIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752607960410677.2041836080107; Tue, 15 Jul 2025 12:32:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublNE-0002qp-Qg; Tue, 15 Jul 2025 15:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwl-0003vd-TA for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwj-0001JY-Ve for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:11 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-IaCNgBdrP864zMty65ZQEw-1; Tue, 15 Jul 2025 15:04:07 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8291B195609E; Tue, 15 Jul 2025 19:04:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC121197702B; Tue, 15 Jul 2025 19:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606249; 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=wdX9/ob2up+SGwd6KFjGchxjspQJLVewUW54m9JacRw=; b=EVc188caMrZDtwgi0YJWE3PygCwHP7r/h27dl8YOdbIZ0dQSkFVSTn4IJwaqC+SnV9rIEH K/ySiF3Hc8u6OrcHRk9BTkCq9P6Mq22Ctb4jmi+bOuvCggUOB3Rw+ZFg9k+Pc+lddD+eoz LvPnwgkooR6VlDAVpHOl4xX/X47+D+k= X-MC-Unique: IaCNgBdrP864zMty65ZQEw-1 X-Mimecast-MFC-AGG-ID: IaCNgBdrP864zMty65ZQEw_1752606246 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 14/57] block: mark bdrv_inactivate_all() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:47 +0200 Message-ID: <20250715190330.378764-15-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607962547116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_inactivate_all() calls bdrv_drain_all_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-37-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index a641beb270..eec92a98da 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -187,7 +187,7 @@ int no_coroutine_fn GRAPH_RDLOCK bdrv_inactivate(BlockDriverState *bs, Error **errp); =20 void bdrv_activate_all(Error **errp); -int bdrv_inactivate_all(void); +int GRAPH_UNLOCKED bdrv_inactivate_all(void); =20 int bdrv_flush_all(void); void bdrv_close_all(void); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608859; cv=none; d=zohomail.com; s=zohoarc; b=RdJpt3gvI95oSIypB6IicmQ7SyMj4k+I+COMLQaerXHtHgGYV+6weTUhK4T2rEeLZp/BhFLBACHCXKMqCZF2Ex49LCv9UtFOXuFFTsGhI6ob+5GXnFCkxx7RXVeztqK5VyapeZd6RMUGjjXRtqyn2yD6CyzrhVENp/o949OZzts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608859; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9TEp5F51Wr4fzDNqxQrYHyGc/wDiNmCHrnHqf+CaHzk=; b=O/WpufK/qC5osshKzZEmgn8+z/a4HIEOCUjxBaTDOhtloNyzGBlFmgnw0aTYfb5SNTdrKuaZk+gsNrHMgVg7fxJpuI33mxz0epY61TUkcs/Oywk2pdocEXjgpwTZESyM41AVnWDhbE9WEIRyQqznjnKOsvnrqWzvTl+70a7oeHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608859577967.2157908219863; Tue, 15 Jul 2025 12:47:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublX5-0008QY-Jv; Tue, 15 Jul 2025 15:41:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwo-0003xc-EX for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwm-0001KN-If for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:14 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-616-uIkVnprzMLWczPbjCP7yDA-1; Tue, 15 Jul 2025 15:04:10 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A0CE1956086; Tue, 15 Jul 2025 19:04:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 01EB1197702B; Tue, 15 Jul 2025 19:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606251; 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=9TEp5F51Wr4fzDNqxQrYHyGc/wDiNmCHrnHqf+CaHzk=; b=Yt+iSr2M5w4k+liqqiiaNSpCcxAaEyBr6WLd8VPy9OrIa5IhgpbNoTqM344QloKZxRqeRe ycgD+RG0HbYKLMBwu9IKrdQe2zyqwKBlxk965wIJuWLsXAO7IlaPIHHSeMbe2ghyDyTS73 ZtT2Ja/0KoGTFFB7inaeq6Hsu/QczcE= X-MC-Unique: uIkVnprzMLWczPbjCP7yDA-1 X-Mimecast-MFC-AGG-ID: uIkVnprzMLWczPbjCP7yDA_1752606249 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 15/57] block: mark blk_remove_bs() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:48 +0200 Message-ID: <20250715190330.378764-16-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608862204116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function blk_remove_bs() calls bdrv_graph_wrlock_drained() and can also call bdrv_drained_begin(), both of which which must be called with the graph unlocked. Marking blk_remove_bs() as GRAPH_UNLOCKED requires temporarily unlocking in hmp_drive_del(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-38-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/system/block-backend-global-state.h | 2 +- block/monitor/block-hmp-cmds.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/system/block-backend-global-state.h b/include/system/b= lock-backend-global-state.h index a62dbdf0dc..1a134083b7 100644 --- a/include/system/block-backend-global-state.h +++ b/include/system/block-backend-global-state.h @@ -55,7 +55,7 @@ void monitor_remove_blk(BlockBackend *blk); =20 BlockBackendPublic *blk_get_public(BlockBackend *blk); =20 -void blk_remove_bs(BlockBackend *blk); +void GRAPH_UNLOCKED blk_remove_bs(BlockBackend *blk); int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp); int blk_replace_bs(BlockBackend *blk, BlockDriverState *new_bs, Error **er= rp); bool GRAPH_RDLOCK bdrv_has_blk(BlockDriverState *bs); diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 6919a49bf5..282d1c386e 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -144,7 +144,7 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) Error *local_err =3D NULL; =20 GLOBAL_STATE_CODE(); - GRAPH_RDLOCK_GUARD_MAINLOOP(); + bdrv_graph_rdlock_main_loop(); =20 bs =3D bdrv_find_node(id); if (bs) { @@ -152,29 +152,31 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) if (local_err) { error_report_err(local_err); } - return; + goto unlock; } =20 blk =3D blk_by_name(id); if (!blk) { error_report("Device '%s' not found", id); - return; + goto unlock; } =20 if (!blk_legacy_dinfo(blk)) { error_report("Deleting device added with blockdev-add" " is not supported"); - return; + goto unlock; } =20 bs =3D blk_bs(blk); if (bs) { if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) { error_report_err(local_err); - return; + goto unlock; } =20 + bdrv_graph_rdunlock_main_loop(); blk_remove_bs(blk); + bdrv_graph_rdlock_main_loop(); } =20 /* Make the BlockBackend and the attached BlockDriverState anonymous */ @@ -191,6 +193,9 @@ void hmp_drive_del(Monitor *mon, const QDict *qdict) } else { blk_unref(blk); } + +unlock: + bdrv_graph_rdunlock_main_loop(); } =20 void hmp_commit(Monitor *mon, const QDict *qdict) --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608012; cv=none; d=zohomail.com; s=zohoarc; b=BbSXsYBGjILwpptAgTHsSfUk2rPA5VgscP+IJjLD93zZADiKN5GY9oVsE2jsOp12fqK40NuZLpT9i8Yw3meELQ040TPxrjGDr6iDGQWqF66yn/IOwxacELWisRWsLIX8M5a5OYJSK24S4Cdffnvt8dftl3jGRZ7eyMqvO0b+jrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608012; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=e4eR9iFA8/DFM+XIWQzDsp67WfYTuUdYYg3aIWy47ew=; b=fikEd9a0xlOvCaq62P7RSOnKPJi+ZE/d/4w00moLjlVz42JkJeZNaCMAtBf6gZKn90iQn4lkdoDxzKWco1qV2O8SjlfMbyxnJVPMFJ38kPyAEvdb6UbNweKcvqlF/+YU37GrFjiwmhIE8VOuK5LayznZYhiPsEdeDDXM6+xo2Lg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608012310509.9722570226106; Tue, 15 Jul 2025 12:33:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublNT-0003c6-Iz; Tue, 15 Jul 2025 15:31:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwt-000427-QT for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwr-0001LN-Ho for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:19 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-R-YAtYR_M9GiXIaWZKudZA-1; Tue, 15 Jul 2025 15:04:12 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AE3E918002AC; Tue, 15 Jul 2025 19:04:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF003197702C; Tue, 15 Jul 2025 19:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606256; 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=e4eR9iFA8/DFM+XIWQzDsp67WfYTuUdYYg3aIWy47ew=; b=JxW4Xe2ciiRGZ2C5YZ6jWeE+NpAlRzazkw5OmGaRoMq+oX9StELx2PMZv9dijKHFC0bkOt xcuQSDBYFdwK8nkoj1/2nZO6n45rPMqWJLUV11jnnWYqTbqNOLJhoArGvBF5buCsOYkuj9 lNYtMmYN507cOmCZJZhv4+LoKxgoKa8= X-MC-Unique: R-YAtYR_M9GiXIaWZKudZA-1 X-Mimecast-MFC-AGG-ID: R-YAtYR_M9GiXIaWZKudZA_1752606251 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 16/57] block: mark blk_drain() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:49 +0200 Message-ID: <20250715190330.378764-17-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608013102116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function blk_drain() calls bdrv_drained_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-39-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/system/block-backend-global-state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/system/block-backend-global-state.h b/include/system/b= lock-backend-global-state.h index 1a134083b7..f6ec1174e6 100644 --- a/include/system/block-backend-global-state.h +++ b/include/system/block-backend-global-state.h @@ -78,7 +78,7 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFlags fla= gs); void blk_aio_cancel(BlockAIOCB *acb); int blk_commit_all(void); bool blk_in_drain(BlockBackend *blk); -void blk_drain(BlockBackend *blk); +void GRAPH_UNLOCKED blk_drain(BlockBackend *blk); void GRAPH_UNLOCKED blk_drain_all(void); void blk_set_on_error(BlockBackend *blk, BlockdevOnError on_read_error, BlockdevOnError on_write_error); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608601; cv=none; d=zohomail.com; s=zohoarc; b=CQbvKkvEiAUuCwxYsVAI9KSWv6tiryAbHJqRpvv9fQWMXRxcmoe9Jl+ncGJ+MRi5PQCyowrv6WnMWKhU9aHmdrzFBwvfZAG2m9mcIVLEzOUmpmMbQ0GRZwqHggcoHiWVQqw9+zP9njwO8RjLogwPc1FH8Vahg1bqWCCRLsHtVhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608601; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pxPwS5k1fgHunb7JjvPEMs/scwHUrbhiJcxBC3V/Kcw=; b=IQUzauedqfl5zqtWPGWsT+DXir1sMUimAIBF5VlwMRmBRu+rpjBKh0IxDpn2AHK/l10hoKL5OVsUVMaJFE0ewxPLiaoF26MOj5rYQgSqpr7ZUhn2Fz6/Ms46PtUBZjQdlvXuQlvfIT/zyD264iSSlKxxvowrFunKke52caMffEY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608601720319.8747876034578; Tue, 15 Jul 2025 12:43:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublY0-00016l-JF; Tue, 15 Jul 2025 15:42:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwu-00043Y-VZ for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkws-0001La-VD for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:20 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-bCGQO3ogOEK2kg7QdbKvzw-1; Tue, 15 Jul 2025 15:04:14 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B8BCF18002A9; Tue, 15 Jul 2025 19:04:13 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2FDE4197702C; Tue, 15 Jul 2025 19:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606258; 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=pxPwS5k1fgHunb7JjvPEMs/scwHUrbhiJcxBC3V/Kcw=; b=dw3dCIkzUz+K0l/SyvsLY8iDEjRwTPZm/UBKaXeUxNdWA0hN3x3eZnVsgBPu+rT22toQ9L nz82EwDIguI2nBoOu/ghVniO2V5rIE3uG5oGFgL4MX4xoReBsEXiyo3w7aD7UEnR2w2IIn aoTP1E6AR7EON5q77zQ63TbfZ5r1fzg= X-MC-Unique: bCGQO3ogOEK2kg7QdbKvzw-1 X-Mimecast-MFC-AGG-ID: bCGQO3ogOEK2kg7QdbKvzw_1752606253 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 17/57] block-backend: mark blk_io_limits_disable() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:50 +0200 Message-ID: <20250715190330.378764-18-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608604887116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function blk_io_limits_disable() calls bdrv_drained_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-40-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/system/block-backend-global-state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/system/block-backend-global-state.h b/include/system/b= lock-backend-global-state.h index f6ec1174e6..c3849640df 100644 --- a/include/system/block-backend-global-state.h +++ b/include/system/block-backend-global-state.h @@ -109,7 +109,7 @@ int blk_probe_blocksizes(BlockBackend *blk, BlockSizes = *bsz); int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo); =20 void blk_set_io_limits(BlockBackend *blk, ThrottleConfig *cfg); -void blk_io_limits_disable(BlockBackend *blk); +void GRAPH_UNLOCKED blk_io_limits_disable(BlockBackend *blk); void blk_io_limits_enable(BlockBackend *blk, const char *group); void blk_io_limits_update_group(BlockBackend *blk, const char *group); void blk_set_force_allow_inactivate(BlockBackend *blk); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607923; cv=none; d=zohomail.com; s=zohoarc; b=PqiLUz+fGlvahIq/g9hyK+a6EpmiV2jXix+Hu+C9nH0HgFDXQ+z5v5noFyqgevs2o1mu56nUNkBHSOpbmvjUtkLRIlLtAhIBQ7T41o5Ik/m/CkYTMVMlKu03JlTdTXjkDjV5BL6bFjuA1FSVFKNtoCpb5IJMqU88zg8cnaB2OuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607923; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6bG2LiKW4UY4F0ikb9ynKo/iZ38MY+OeFpp3X1qbbw8=; b=YENdGwxdO6sWKJ+TYDPx6jUAuGyNMLfUp7OIwZjXxZN2Pchlcscwn8n0QYQjyLC85qRq3bfAPR/gJyawMESjsFbtWEWvES2fT1Xsj1shfORCYTqG5+tdIvjpOzhQchY61kcRUOUPqkhTB9GP8Zycuo+kKUOZ8Sxnp/5dBPrd6+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752607923841946.3154298169469; Tue, 15 Jul 2025 12:32:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublNa-0003vv-HH; Tue, 15 Jul 2025 15:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwv-00043Z-2s for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwt-0001Ld-Bx for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:20 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-481-wAFutUMYMuWbQj8ZZyGjWg-1; Tue, 15 Jul 2025 15:04:16 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B9165180028F; Tue, 15 Jul 2025 19:04:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 39665197702B; Tue, 15 Jul 2025 19:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606258; 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=6bG2LiKW4UY4F0ikb9ynKo/iZ38MY+OeFpp3X1qbbw8=; b=b/Mpf8lNsl4RXFyHZtJSLtQsL6kHVQ3CsTP1qdK3C86G9Fsj8rgoo9hiW3sozg3eucdfYV KlOv8rNCrc92M/M0oriUqtQ+YtxzcSDea8SIEO4Rzu7+ircRx9AuzXDjFbJOIlKP7beQ7Z trqegB4p2vrNSZGw2IGic7ZMLr2pK90= X-MC-Unique: wAFutUMYMuWbQj8ZZyGjWg-1 X-Mimecast-MFC-AGG-ID: wAFutUMYMuWbQj8ZZyGjWg_1752606255 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 18/57] block/commit: mark commit_abort() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:51 +0200 Message-ID: <20250715190330.378764-19-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607930301116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function commit_abort() calls bdrv_drained_begin(), which must be called with the graph unlocked. Also mark the JobDriver's abort() callback as GRAPH_UNLOCKED_PTR, because that is the callback via which commit_abort() is reached. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-41-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/qemu/job.h | 2 +- block/commit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/job.h b/include/qemu/job.h index bb8ee766ef..ead31578d3 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -283,7 +283,7 @@ struct JobDriver { * All jobs will complete with a call to either .commit() or .abort() = but * never both. */ - void (*abort)(Job *job); + void GRAPH_UNLOCKED_PTR (*abort)(Job *job); =20 /** * If the callback is not NULL, it will be invoked after a call to eit= her diff --git a/block/commit.c b/block/commit.c index 7496cf732e..0d9e1a16d7 100644 --- a/block/commit.c +++ b/block/commit.c @@ -68,7 +68,7 @@ static int commit_prepare(Job *job) s->backing_mask_protocol); } =20 -static void commit_abort(Job *job) +static void GRAPH_UNLOCKED commit_abort(Job *job) { CommitBlockJob *s =3D container_of(job, CommitBlockJob, common.job); BlockDriverState *top_bs =3D blk_bs(s->top); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752607989; cv=none; d=zohomail.com; s=zohoarc; b=XYdesdfkxA+7FbiUNO+xkX2Bf3vN8ciQHIsM94MiQDy25IFNSBdVbGnouF+qa+WCFZGcHY92H582d8YX/gnQKId/WJshTahLJQrcn4VnjO6IMjS62x6T1ZnJnrwHtOilz43++XV1krThqEA4GmwsRmdaYQgNv3Oo1FMtd2O0O/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752607989; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8W8fQy5JCYizGetg+mDWw1LL18wUNUGbfORKfvklxKo=; b=lTHV6+MvP9AEqI6U8p91Ub0GPke1s73HmtXYPcshc3yJlOYM/uWCWoXVRSQu7EaQXdWzybc/9ibMYro6/cGV+/sRgq/UC7kjjegqJmf8wCG1BhXbJ2qA1Hq1wbkfaG6T1LkpD895S94AYTcd/771NWAfoahKrf7n1TW3hFt7JtE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752607988943599.5195916482046; Tue, 15 Jul 2025 12:33:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublNr-0004dx-VE; Tue, 15 Jul 2025 15:32:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwz-00046p-JC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkww-0001MF-3Q for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:24 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-9-WJwmQLNkKz1TAbOgkjAQ-1; Tue, 15 Jul 2025 15:04:18 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C3D76195608E; Tue, 15 Jul 2025 19:04:17 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3A667197702B; Tue, 15 Jul 2025 19:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606261; 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=8W8fQy5JCYizGetg+mDWw1LL18wUNUGbfORKfvklxKo=; b=F7qqcCuY39s+YBFjfDPLhSwt31VNfkoI2ktm7XB6IKaoF06+Xw45cgS4whV8+V16tvOxxB f6xr5rxLHE3j+3PGZg/QzIvl2nIyZMslf2xUesvdzO4ooAPCqc5TwERB4dtjwRN+kuruqR QkESwXt4gD+M0CpUdHrsqkSv1tIFYuY= X-MC-Unique: 9-WJwmQLNkKz1TAbOgkjAQ-1 X-Mimecast-MFC-AGG-ID: 9-WJwmQLNkKz1TAbOgkjAQ_1752606257 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 19/57] block: Allow bdrv_new() with and without graph lock Date: Tue, 15 Jul 2025 21:02:52 +0200 Message-ID: <20250715190330.378764-20-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752607997034116600 Content-Type: text/plain; charset="utf-8" bdrv_new() calls bdrv_drained_begin(), which can poll and therefore can't be called while holding the graph lock. One option to make sure that this call is allowed would be marking bdrv_new() GRAPH_UNLOCKED. However, this is actually an unnecessary restriction because we know that we only just created the BlockDriverState and it isn't even part of the graph yet. We can use bdrv_do_drained_begin_quiesce() instead to avoid the polling, which means that bdrv_new() can now safely be called from callers that hold the graph lock as well as from callers that don't. Signed-off-by: Kevin Wolf --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index 932e599f45..fe5aa2e767 100644 --- a/block.c +++ b/block.c @@ -431,7 +431,7 @@ BlockDriverState *bdrv_new(void) bs->block_status_cache =3D g_new0(BdrvBlockStatusCache, 1); =20 for (i =3D 0; i < bdrv_drain_all_count; i++) { - bdrv_drained_begin(bs); + bdrv_do_drained_begin_quiesce(bs, NULL); } =20 QTAILQ_INSERT_TAIL(&all_bdrv_states, bs, bs_list); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608161; cv=none; d=zohomail.com; s=zohoarc; b=O7nFYNGdgHdZgxebR88UZ0WbyOQM20pffrFuxQUPCoQ0QX15Mq3veQ8MdE4lkZfTAq3UhKF5CPPlMNJ60vzSLq5O35J9G8LGjHPHWzZos+NBKkLzWBAKLXm2iz1cf4bzA/rTmL1dEdpUbdxf60afCMYqIf1wxMmTMl1O4nnhfbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608161; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vLNpHxU1zt9qnIq8PoBzTouwSE4SUYUIo9nnck6qlZM=; b=eo2JFUWz/XZzfQF0ScbO5EBd3sDATQ17ELEFPQk0XSd0VyE6JMncBshDTmL4nor8o54qtq0ydi51Ah9D7/dH+OPWZVjfA/TFUFiHljnOB81p26V2zN6398JFQ8RjgSlS46evrpEJXhohb6YL7j9K+KtmJTWcT0rJkaTzo8ZYg6Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608161827116.61188403482367; Tue, 15 Jul 2025 12:36:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublRJ-0006Kb-VN; Tue, 15 Jul 2025 15:35:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx1-000478-TK for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkwz-0001Mj-CY for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:27 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-kN30f_dsP6a-XGgm7jn87w-1; Tue, 15 Jul 2025 15:04:20 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0C1BB19560A3; Tue, 15 Jul 2025 19:04:20 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 47B55197702B; Tue, 15 Jul 2025 19:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606263; 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=vLNpHxU1zt9qnIq8PoBzTouwSE4SUYUIo9nnck6qlZM=; b=eEDCKdLZoPjfGg7bzCJLMPgye6pKlIAVtdd+20At4mIoDwuHTaE0wRHB/5PpfiDVVkiu6A v6snxO1C03in4GnsWqtOsiNyDGCjlWj/L2keiES22nMFbCqjxDt9vtgElHxpSC4SDE457c wo31JWz+nkUWkJu4/l9+wJu/n5LYF1k= X-MC-Unique: kN30f_dsP6a-XGgm7jn87w-1 X-Mimecast-MFC-AGG-ID: kN30f_dsP6a-XGgm7jn87w_1752606260 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 20/57] block: mark bdrv_replace_child_bs() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:53 +0200 Message-ID: <20250715190330.378764-21-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608162588116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_replace_child_bs() calls bdrv_drained_begin() which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-43-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index eec92a98da..706a2cde36 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -74,8 +74,8 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverStat= e *bs_top, int GRAPH_WRLOCK bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, Error **er= rp); =20 -int bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, - Error **errp); +int GRAPH_UNLOCKED +bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, Error **= errp); BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_optio= ns, int flags, Error **errp); int bdrv_drop_filter(BlockDriverState *bs, Error **errp); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608511; cv=none; d=zohomail.com; s=zohoarc; b=GdAgqQuLTxFLvWkbfzfSbRi1If120VhMv4yMWmB8HT4uCQ9S/huN8XSRLAZpQlmhJVqYTYzxDA+zztgC4qYgjZxlsLCCpCegApVIV40eJjnUgSynRFJlwmslCgs//+ijTvSF6EQiZF0cJAVwRhnHNvqK55YcQgBh6f0hNNKELwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608511; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1nb79uyak6u3+GWQ5IsuWkbzxb9UrXWeLaJnLPpJGP8=; b=RU0xW59o9RLs3qTT/2IVtBqvJxTUgJogcN7keuzOpMQPcRV4b0oKPQRli1EIg3UmVgnQ1Rh1PmOkfMiwuTPV48I0NJdcO9NasUwwIgEb8FVgeYOuKa5Z/OIR+rDSaoEzLqNMOcB4MHIV8zxQUe+BbY3T07UpfhjaKtBP115gcdM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608511024594.696880430447; Tue, 15 Jul 2025 12:41:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublRO-0006fj-Uy; Tue, 15 Jul 2025 15:35:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx2-00047P-MV for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx1-0001NR-2z for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:28 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-FRtUwrNwNO6YXQTNpKKLIQ-1; Tue, 15 Jul 2025 15:04:23 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 26A35195608E; Tue, 15 Jul 2025 19:04:22 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 81AD9197702B; Tue, 15 Jul 2025 19:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606266; 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=1nb79uyak6u3+GWQ5IsuWkbzxb9UrXWeLaJnLPpJGP8=; b=F+cBVl26fKDs+4AsSi7quy4umjmBAMt2r4n7spo72ReTpWuzszkfURMA6bUe9wJ7zLPXvJ K2YKchhUdfTdR7oDmG+Q878+23AxyZ8WgT6tEnH1FYfJcLSCgtei6K2B6upRBmvjsUZQZg 3xqD3oubnZjDL7SMNwYnKgEhlyCucnY= X-MC-Unique: FRtUwrNwNO6YXQTNpKKLIQ-1 X-Mimecast-MFC-AGG-ID: FRtUwrNwNO6YXQTNpKKLIQ_1752606262 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 21/57] block: mark bdrv_insert_node() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:54 +0200 Message-ID: <20250715190330.378764-22-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608512013116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_insert_node() calls bdrv_drained_begin() which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-44-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 706a2cde36..cb4d8bca22 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -76,8 +76,9 @@ bdrv_replace_node(BlockDriverState *from, BlockDriverStat= e *to, Error **errp); =20 int GRAPH_UNLOCKED bdrv_replace_child_bs(BdrvChild *child, BlockDriverState *new_bs, Error **= errp); -BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *node_optio= ns, - int flags, Error **errp); +BlockDriverState * GRAPH_UNLOCKED +bdrv_insert_node(BlockDriverState *bs, QDict *node_options, int flags, + Error **errp); int bdrv_drop_filter(BlockDriverState *bs, Error **errp); =20 BdrvChild * no_coroutine_fn --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608629; cv=none; d=zohomail.com; s=zohoarc; b=OWbh+/lOymqK/0k/fZjkHg8SgLmdOOT4PTYIvZwhrS2I3GcMr2XEpPjEagPeyhZBPbCiB1//psJs2OXQ7OHlesTpE2nfrbPSFxCgvepgQB9HHdnGh2qaYrHoXigoX1Zune6OeIp/qx8CIs1Ja82Al7+gFRvrzEqfshmO0Vks0nE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uWpHW+dJTRgs/UsKDiUZcZceRbFsPgysLM4ftLaD1lI=; b=JV3RuXi1fcII1qOmVYpbdRhFYT3L5u54oiFGfEVSx4n4cstiwZzc+OMct6Q8SHcvOziJsJNrCfZ4bvvr4b7RmYcAJRq/tdzLTDV9UVsrJSnez56UZ5EtjgzmqnfeZ59c1C0Gu6VdFuUxcDFN+G0U2k9JUKcWuRKW7QoPJGD5d+U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608629376364.95527853125066; Tue, 15 Jul 2025 12:43:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublYf-0002S8-1C; Tue, 15 Jul 2025 15:43:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx3-00047T-2z for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx1-0001NW-Ea for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:28 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-355-ka8JMxlzOnybmOQgaJNhXg-1; Tue, 15 Jul 2025 15:04:25 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 275B5195608B; Tue, 15 Jul 2025 19:04:24 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C1DF197702B; Tue, 15 Jul 2025 19:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606266; 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=uWpHW+dJTRgs/UsKDiUZcZceRbFsPgysLM4ftLaD1lI=; b=AtYYrRPB4IUlC7SG8s9hwyJMNZJhcQTgVwERxzLPzv+koCWwdv/Soy41LvxQRQ8kFg6d70 Gley0q4kw/Yp1zl2A3f2uh7pz9fxbzDCTRxuaYMqBJejv4Xh8m2HK/twihdHfFPnlt5/NO uW6boI6siJ+lmC+EbQnjcCx0ts3Cx/k= X-MC-Unique: ka8JMxlzOnybmOQgaJNhXg-1 X-Mimecast-MFC-AGG-ID: ka8JMxlzOnybmOQgaJNhXg_1752606264 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 22/57] block: mark bdrv_drop_intermediate() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:55 +0200 Message-ID: <20250715190330.378764-23-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608630927116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_drop_intermediate() calls bdrv_drained_begin(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-45-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index cb4d8bca22..d3dd951013 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -143,9 +143,10 @@ int bdrv_commit(BlockDriverState *bs); int GRAPH_RDLOCK bdrv_make_empty(BdrvChild *c, Error **errp); =20 void bdrv_register(BlockDriver *bdrv); -int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, - const char *backing_file_str, - bool backing_mask_protocol); +int GRAPH_UNLOCKED +bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, + const char *backing_file_str, + bool backing_mask_protocol); =20 BlockDriverState * GRAPH_RDLOCK bdrv_find_overlay(BlockDriverState *active, BlockDriverState *bs); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608635; cv=none; d=zohomail.com; s=zohoarc; b=PjByoAoLO8hl9/h5Ek1WXygOGXnFzVsYuzGbqHSrEDEDbKNjDx1XEzXBZzGxhCOeDc8Xd8xF4FEebw8Amw+/FUvArV/Itu2jAn9w65++FdQkRmHFjz3JrQrcQEMPD3P1SXAyj7BFYHY0IoG24tBwym/gl3PNEPc4tK/tkmz6XdE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608635; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=co16lsTRhl96cJfZ2vlYr+ol1iUZRlfrosgVkThrvCw=; b=DWoZkLdpdCLl4rgz8lp5CaKLp+Xg3zZkrPtcrc79md8ICBvHciDqEIMbACrXpYWS2ODPn1ktJHgG2GDCy6gT32b4X4kM8NhVI5zLhUfVJvuyCcNF/pAkd0qzUxier2j+u2v0OwW0RvswtH7Jpb2SJiAujLhTgZfuXLXTBF4C6Xg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608635790606.521696203295; Tue, 15 Jul 2025 12:43:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublYa-00026k-9g; Tue, 15 Jul 2025 15:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx8-00047p-7t for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx3-0001O0-Dc for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:33 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-LAJNEvtDNYGFb1N-U2D7Ag-1; Tue, 15 Jul 2025 15:04:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 32583180028D; Tue, 15 Jul 2025 19:04:26 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9D899197702B; Tue, 15 Jul 2025 19:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606268; 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=co16lsTRhl96cJfZ2vlYr+ol1iUZRlfrosgVkThrvCw=; b=PB3akvt6vpxgJpdGN9btfyz/dPNko+Eiucdd9zXP85huXeH+0eCZ2LrplgynigbGzQYlcy Q4KFPFHTT8/D06UPAOVbqcl2A8hM8Bslm92iFcCcnk9pOQFtKnwJBU5wJ+gcFnLiVdSBXY s+Prs53gjOU2Vm9/5bndlpgZJQ2OaWI= X-MC-Unique: LAJNEvtDNYGFb1N-U2D7Ag-1 X-Mimecast-MFC-AGG-ID: LAJNEvtDNYGFb1N-U2D7Ag_1752606266 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 23/57] block: mark bdrv_close_all() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:56 +0200 Message-ID: <20250715190330.378764-24-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608637159116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_close_all() calls bdrv_drain_all(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-46-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index d3dd951013..e7c9acd2ba 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -192,7 +192,7 @@ void bdrv_activate_all(Error **errp); int GRAPH_UNLOCKED bdrv_inactivate_all(void); =20 int bdrv_flush_all(void); -void bdrv_close_all(void); +void GRAPH_UNLOCKED bdrv_close_all(void); void GRAPH_UNLOCKED bdrv_drain_all_begin(void); void bdrv_drain_all_begin_nopoll(void); void bdrv_drain_all_end(void); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608662; cv=none; d=zohomail.com; s=zohoarc; b=GU7TyYK00OHyjgvjBbdGkDzdul74C4JCJ47DLGmfbAG87JEaDuDdkhQZ6ChpwXqpsNkqfxc09VXIaAZeixn4G1OkR3rMq62H7dcnmjYB+h53hD8Ro4Vg+YnqBE+o81odw12upoF21WXhElvsTmTrPhfb7gqbyDRXFUECA0dDbfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608662; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=85C+bmwGQpnY3yJXrQ56iww5z/nGCdAErB540jMO+p8=; b=RGAXh55hydNoPrf/C0WNe2QkzzMykj7mVUDkd0sPZ1dfLERp5Dvr44OtfSV+TUomNrSRduTpGC9Z7VQKZ77LUuZSXlsRm5Is/YLB+7RhtzqM0AOL0CGH2TNqj3YbZsXOqCcszMjz6kaw3vGViUIYKqdS9BeJKNmZVScD/dkhxXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608662576372.3112300665697; Tue, 15 Jul 2025 12:44:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublYx-0003uY-MB; Tue, 15 Jul 2025 15:43:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx9-00047v-Hj for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx8-0001Oa-1F for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:35 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-GbJ6YLJFM9qn9b9yZnePfA-1; Tue, 15 Jul 2025 15:04:29 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A40AD19560B2; Tue, 15 Jul 2025 19:04:28 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A872E197702B; Tue, 15 Jul 2025 19:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606273; 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=85C+bmwGQpnY3yJXrQ56iww5z/nGCdAErB540jMO+p8=; b=Sfo8hC+4zWVVBO8Oc1b+eZ36T3UAoOkMcMO5uzo0efUIt0Ew7r6SVsLktwQH34mLw6EBqA r+omE2CcJvO25+G4AHGsBK2J3JOYkwXjCj3miN/bbTeCTX/tgfpP6R/8b/F00SLldRGYO4 Qof78CYuMt/oFf1wqoaxr+oPIzS2RK4= X-MC-Unique: GbJ6YLJFM9qn9b9yZnePfA-1 X-Mimecast-MFC-AGG-ID: GbJ6YLJFM9qn9b9yZnePfA_1752606268 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 24/57] block: mark bdrv_close() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:57 +0200 Message-ID: <20250715190330.378764-25-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608663545116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The functions blk_log_writes_close(), blkverify_close(), quorum_close(), vmdk_close() via vmdk_free_extents(), and other bdrv_close() implementations call bdrv_graph_wrlock_drained(), which must be called with the graph unlocked. They are reached via the BlockDriver's bdrv_close() callback and the bdrv_close() wrapper, which are also marked as GRAPH_UNLOCKED_PTR and GRAPH_UNLOCKED. Furthermore, the function bdrv_close() also calls bdrv_drained_begin() and bdrv_graph_wrlock_drained(), so there are additional reasons for marking it GRAPH_UNLOCKED. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-47-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block_int-common.h | 2 +- block.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index e96c6a6a03..034c0634c8 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -248,7 +248,7 @@ struct BlockDriver { int GRAPH_UNLOCKED_PTR (*bdrv_open)( BlockDriverState *bs, QDict *options, int flags, Error **errp); =20 - void (*bdrv_close)(BlockDriverState *bs); + void GRAPH_UNLOCKED_PTR (*bdrv_close)(BlockDriverState *bs); =20 int coroutine_fn GRAPH_UNLOCKED_PTR (*bdrv_co_create)( BlockdevCreateOptions *opts, Error **errp); diff --git a/block.c b/block.c index fe5aa2e767..8d3dd5a8e3 100644 --- a/block.c +++ b/block.c @@ -5146,7 +5146,7 @@ static void GRAPH_UNLOCKED bdrv_reopen_abort(BDRVReop= enState *reopen_state) } =20 =20 -static void bdrv_close(BlockDriverState *bs) +static void GRAPH_UNLOCKED bdrv_close(BlockDriverState *bs) { BdrvAioNotifier *ban, *ban_next; BdrvChild *child, *next; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608347; cv=none; d=zohomail.com; s=zohoarc; b=efJGhHkd2WHrFwPfAogM1wDTMty3kV4492cFVIRtaN8hnIaYyDEFGkp58EMLuT4fy45gtbAl4/r3W3WkoWJ19rUCaurYutXt/YVRK20HSq4owoAR/wBsDI43GAWCiQRXF3YmOjujEKlKdMYjnZJ7i1ooyBXxaV3OxO4NGNx1wdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608347; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rEObCe5SI4WFqr30JFWEG6IuI2pn5Gii5i/TnHZnrbo=; b=kkl/FgmZmYXeab/w8fc0DqpQ0dm77zQAVe04oys1nQjGWO+KCOnUarRl+dwXVeigJ1g0ZZHNC2Vd114Veq6sBTgaX4u1nL9dloiErw6qDf63n2xFZvYDPGqwwTzZXP9mcJru7Pju+ATuN+GlfayTWE58tFhGumNZvqLK46QFnEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608347097767.798453861853; Tue, 15 Jul 2025 12:39:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublRY-0007L4-MY; Tue, 15 Jul 2025 15:36:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxB-00048I-Iq for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkx9-0001On-Jb for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:36 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-b-OykTV4Pu6dBMbrr8-RaQ-1; Tue, 15 Jul 2025 15:04:32 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A4C51195608E; Tue, 15 Jul 2025 19:04:30 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 254D2197702B; Tue, 15 Jul 2025 19:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606274; 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=rEObCe5SI4WFqr30JFWEG6IuI2pn5Gii5i/TnHZnrbo=; b=idsRIJjOH8S4xL4/SO3fO8qUz1aG5Mqrt9tRxFTClw2MOjsC4gsvK6rPU1iTPoamPrEhzX dwzg/3D4MKMDu38/ZjP9+dKoCOz5WU5g9TEq3w70lXkTj/XPoTUVrcrZt++u3nhMwlcDQv 5j5v4hnbLDRNx8Uh6nKCmmjyavhiQeg= X-MC-Unique: b-OykTV4Pu6dBMbrr8-RaQ-1 X-Mimecast-MFC-AGG-ID: b-OykTV4Pu6dBMbrr8-RaQ_1752606270 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 25/57] block: mark bdrv_open_child_common() and its callers GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:58 +0200 Message-ID: <20250715190330.378764-26-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608348554116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function bdrv_open_child_common() calls bdrv_graph_wrlock_drained(), which must be called with the graph unlocked. Mark it and its two callers bdrv_open_file_child() and bdrv_open_child() as GRAPH_UNLOCKED. This requires temporarily unlocking in vmdk_parse_extents() and making the locked section shorter in vmdk_open(). Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-48-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 9 +++++---- block.c | 13 ++++++------- block/vmdk.c | 6 ++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index e7c9acd2ba..62da83c616 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -81,7 +81,7 @@ bdrv_insert_node(BlockDriverState *bs, QDict *node_option= s, int flags, Error **errp); int bdrv_drop_filter(BlockDriverState *bs, Error **errp); =20 -BdrvChild * no_coroutine_fn +BdrvChild * no_coroutine_fn GRAPH_UNLOCKED bdrv_open_child(const char *filename, QDict *options, const char *bdref_ke= y, BlockDriverState *parent, const BdrvChildClass *child_clas= s, BdrvChildRole child_role, bool allow_none, Error **errp); @@ -91,9 +91,10 @@ bdrv_co_open_child(const char *filename, QDict *options,= const char *bdref_key, BlockDriverState *parent, const BdrvChildClass *child_clas= s, BdrvChildRole child_role, bool allow_none, Error **errp); =20 -int bdrv_open_file_child(const char *filename, - QDict *options, const char *bdref_key, - BlockDriverState *parent, Error **errp); +int GRAPH_UNLOCKED +bdrv_open_file_child(const char *filename, QDict *options, + const char *bdref_key, BlockDriverState *parent, + Error **errp); =20 BlockDriverState * no_coroutine_fn bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); diff --git a/block.c b/block.c index 8d3dd5a8e3..8848e9a7ed 100644 --- a/block.c +++ b/block.c @@ -3766,13 +3766,12 @@ done: return bs; } =20 -static BdrvChild *bdrv_open_child_common(const char *filename, - QDict *options, const char *bdref= _key, - BlockDriverState *parent, - const BdrvChildClass *child_class, - BdrvChildRole child_role, - bool allow_none, bool parse_filen= ame, - Error **errp) +static BdrvChild * GRAPH_UNLOCKED +bdrv_open_child_common(const char *filename, QDict *options, + const char *bdref_key, BlockDriverState *parent, + const BdrvChildClass *child_class, + BdrvChildRole child_role, bool allow_none, + bool parse_filename, Error **errp) { BlockDriverState *bs; BdrvChild *child; diff --git a/block/vmdk.c b/block/vmdk.c index 04986c8d55..7b98debc2b 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1229,9 +1229,11 @@ vmdk_parse_extents(const char *desc, BlockDriverStat= e *bs, QDict *options, extent_role |=3D BDRV_CHILD_METADATA; } =20 + bdrv_graph_rdunlock_main_loop(); extent_file =3D bdrv_open_child(extent_path, options, extent_opt_p= refix, bs, &child_of_bds, extent_role, fals= e, &local_err); + bdrv_graph_rdlock_main_loop(); g_free(extent_path); if (!extent_file) { error_propagate(errp, local_err); @@ -1352,13 +1354,13 @@ static int vmdk_open(BlockDriverState *bs, QDict *o= ptions, int flags, BDRVVmdkState *s =3D bs->opaque; uint32_t magic; =20 - GRAPH_RDLOCK_GUARD_MAINLOOP(); - ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); if (ret < 0) { return ret; } =20 + GRAPH_RDLOCK_GUARD_MAINLOOP(); + buf =3D vmdk_read_desc(bs->file, 0, errp); if (!buf) { return -EINVAL; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608367; cv=none; d=zohomail.com; s=zohoarc; b=RG+YtNmQoHcHaglauWxvTpi+q2OrmFS8nZmn0uX6Biu7IMohGvuH5vciRIDqAzWl2poxF0zXh89MymargMdcvR247BxX5EMRhD5WNzbdW/mz350BB4GA3NpYg8BnMhKohvB4uz5kJHjqHtO3mo95Ci9mo6+jKT2TZxqrkEMEfuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608367; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4mPA4vMb8GN/j2W+BNbBIzPkfNqvPPkxiMo1JDqKBgQ=; b=FP2rXbkE5tw/A7aefSeD4DaNm1mdwehXd0n2mRBqnmCwvehPgOiYPlU7w819oe0o8X09ZqazePeaIXN7fYKxxJELxPBOPpPa3x8foqNX8niQ/7d1Fjakrb+cdCDDgFRItQQMDhzNHz2T/lNMmqD/644+5bxVLHocmBGtnMGZ3HQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608367960419.38470490715474; Tue, 15 Jul 2025 12:39:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublTO-00005i-Mx; Tue, 15 Jul 2025 15:37:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxE-000494-Lp for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxB-0001P7-QR for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:40 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-lJj1m8dSNCqAM8n2wcrlbQ-1; Tue, 15 Jul 2025 15:04:33 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B04F8195609E; Tue, 15 Jul 2025 19:04:32 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25981197702B; Tue, 15 Jul 2025 19:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606277; 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=4mPA4vMb8GN/j2W+BNbBIzPkfNqvPPkxiMo1JDqKBgQ=; b=Oz7W1XwpbPfa6q+A1eWaPKnTk4ToCmDJUUpVey8vM40d9bRX35lbKBgMCuwxfh+XVZTFZO lHfhtpBh2wt8CSnKf1+4JfMa7ysNWiSiqpYD1+Mup3+cg/5AvOSryF1xAZv1Ick9hdOlY5 nHtU8ES12w1vtBVS5mhiBjJlOrTvJhE= X-MC-Unique: lJj1m8dSNCqAM8n2wcrlbQ-1 X-Mimecast-MFC-AGG-ID: lJj1m8dSNCqAM8n2wcrlbQ_1752606272 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 26/57] blockjob: mark block_job_remove_all_bdrv() as GRAPH_UNLOCKED Date: Tue, 15 Jul 2025 21:02:59 +0200 Message-ID: <20250715190330.378764-27-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608368545116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner The function block_job_remove_all_bdrv() calls bdrv_graph_wrlock_drained(), which must be called with the graph unlocked. Signed-off-by: Fiona Ebner Message-ID: <20250530151125.955508-49-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/blockjob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/block/blockjob.h b/include/block/blockjob.h index 990f3e179a..85284cb25e 100644 --- a/include/block/blockjob.h +++ b/include/block/blockjob.h @@ -151,7 +151,7 @@ block_job_add_bdrv(BlockJob *job, const char *name, Blo= ckDriverState *bs, * Remove all BlockDriverStates from the list of nodes that are involved i= n the * job. This removes the blockers added with block_job_add_bdrv(). */ -void block_job_remove_all_bdrv(BlockJob *job); +void GRAPH_UNLOCKED block_job_remove_all_bdrv(BlockJob *job); =20 /** * block_job_has_bdrv: --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608942; cv=none; d=zohomail.com; s=zohoarc; b=P8NY/NbNux9MUNbjfgPun7RhnX+edQBnbjNigT408YgWJ1/ryuGcsGtQH6DtwTFL+3t7NnmlcyTnCG8J6IwKoSTWpJ/7OeQ5wxPP7A7rNo+eJwjdrM6UAjiwdytB1hs1bJiTWQVClO1Z8p8nUIpjeE0BUTQNr2UccswQ90OqVyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608942; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RKUdoz6mS/MZpsOs9CYOwTTbuQUWMaH4GdV7/2+2JT0=; b=QsQGUz6CT9UHuoRzJNqOLOTYY+9vUwyc0rkGNWlnij3rtuMaG17umWNfI9oT5/9gtitYSXDF2rXNtk+7xI0rV6Ubwta8efBFCoz4bJRi7Q0Y8j5P0fXmZonIqdv3hMTZuCo2DcCikgcYOVQQVybuRyX2EF523gBgIIOXYYDR1Ww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608942160813.1491396158887; Tue, 15 Jul 2025 12:49:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublZ4-0004WY-Jn; Tue, 15 Jul 2025 15:43:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxF-00049D-Gb for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxD-0001PQ-LB for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:41 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-NUZYEn5eOPSIOknUwPYm7g-1; Tue, 15 Jul 2025 15:04:35 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B204818001E2; Tue, 15 Jul 2025 19:04:34 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 327B6197702B; Tue, 15 Jul 2025 19:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606278; 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=RKUdoz6mS/MZpsOs9CYOwTTbuQUWMaH4GdV7/2+2JT0=; b=At82nx/8EvyJ1gn04qq1Dk/rlyKgpG40sgJYLhjfO9RR0LJ7Ji0EgOpxVv5XPosWPeIU5u meJjKTA0JvoMj5ncLP7CiI57TSTTpWUPcJj++cg/1Wjeky/TWdsnmMzTlPdPdhUJTRazri mk/FXmLq0Pd6hezf/h9F2V8DzpAUv2g= X-MC-Unique: NUZYEn5eOPSIOknUwPYm7g-1 X-Mimecast-MFC-AGG-ID: NUZYEn5eOPSIOknUwPYm7g_1752606274 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 27/57] block/qapi: include child references in block device info Date: Tue, 15 Jul 2025 21:03:00 +0200 Message-ID: <20250715190330.378764-28-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608943177116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner In combination with using a throttle filter to enforce IO limits for a guest device, knowing the 'file' child of a block device can be useful. If the throttle filter is only intended for guest IO, block jobs should not also be limited by the throttle filter, so the block operations need to be done with the 'file' child of the top throttle node as the target. In combination with mirroring, the name of that child is not fixed. Another scenario is when unplugging a guest device after mirroring below a top throttle node, where the mirror target is added explicitly via blockdev-add. After mirroring, the target becomes the new 'file' child of the throttle node. For unplugging, both the top throttle node and the mirror target need to be deleted, because only implicitly added child nodes are deleted automatically, and the current 'file' child of the throttle node was explicitly added (as the mirror target). In other scenarios, it could be useful to follow the backing chain. Note that iotests 191 and 273 use _filter_img_info, so the 'children' information is filtered out there. Signed-off-by: Fiona Ebner Message-ID: <20250702123204.325470-2-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qapi/block-core.json | 16 ++++++++++++++++ block/qapi.c | 10 ++++++++++ tests/qemu-iotests/184.out | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 1df6644f0d..3e720af5ad 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -461,6 +461,19 @@ 'direct': 'bool', 'no-flush': 'bool' } } =20 +## +# @BlockdevChild: +# +# @child: The name of the child, for example 'file' or 'backing'. +# +# @node-name: The name of the child's block driver node. +# +# Since: 10.1 +## +{ 'struct': 'BlockdevChild', + 'data': { 'child': 'str', + 'node-name': 'str' } } + ## # @BlockDeviceInfo: # @@ -486,6 +499,8 @@ # @backing_file_depth: number of files in the backing file chain # (since: 1.2) # +# @children: Information about child block nodes. (since: 10.1) +# # @active: true if the backend is active; typical cases for inactive backe= nds # are on the migration source instance after migration completes and o= n the # destination before it completes. (since: 10.0) @@ -560,6 +575,7 @@ { 'struct': 'BlockDeviceInfo', 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', + 'children': ['BlockdevChild'], 'active': 'bool', 'encrypted': 'bool', 'detect_zeroes': 'BlockdevDetectZeroesOptions', 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int', diff --git a/block/qapi.c b/block/qapi.c index 2c50a6bf3b..e08a1e970f 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -51,6 +51,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, ImageInfo *backing_info; BlockDriverState *backing; BlockDeviceInfo *info; + BlockdevChildList **children_list_tail; + BdrvChild *child; =20 if (!bs->drv) { error_setg(errp, "Block device %s is ejected", bs->node_name); @@ -77,6 +79,14 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *bl= k, info->node_name =3D g_strdup(bs->node_name); } =20 + children_list_tail =3D &info->children; + QLIST_FOREACH(child, &bs->children, next) { + BlockdevChild *child_ref =3D g_new0(BlockdevChild, 1); + child_ref->child =3D g_strdup(child->name); + child_ref->node_name =3D g_strdup(child->bs->node_name); + QAPI_LIST_APPEND(children_list_tail, child_ref); + } + backing =3D bdrv_cow_bs(bs); if (backing) { info->backing_file =3D g_strdup(backing->filename); diff --git a/tests/qemu-iotests/184.out b/tests/qemu-iotests/184.out index 52692b6b3b..ef99bb2e9a 100644 --- a/tests/qemu-iotests/184.out +++ b/tests/qemu-iotests/184.out @@ -41,6 +41,12 @@ Testing: }, "iops_wr": 0, "ro": false, + "children": [ + { + "node-name": "disk0", + "child": "file" + } + ], "node-name": "throttle0", "backing_file_depth": 1, "drv": "throttle", @@ -69,6 +75,8 @@ Testing: }, "iops_wr": 0, "ro": false, + "children": [ + ], "node-name": "disk0", "backing_file_depth": 0, "drv": "null-co", --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608348; cv=none; d=zohomail.com; s=zohoarc; b=MU0gVs25inilAhPb0fK99GvKoioXjETcqUZBbD412sPJomri4fypR616TcK0FqZ5orO0drQz86rdfcgCIjYuNnyKjg4xN4NIHwWRgcZBy264nP22z/LnznCfM3MOwJrkF8J5Yh9PzVvxR3KUbXvXY2wwDI8e2JuR/FRM8LE8GIE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608348; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6fjLhhOT1GHA5GeL6hb0wUmyYfZeXw2frUz0mOAoe1I=; b=KPBZzxYzoYvJw3BApWz+i88Y/qDcXK4xg5XvOefSeq5j6H8G1yJuOe9O8khop9VR20OuiLUjRbJekJY/RBpFJleSrQzhjIygNvbv6IaEdNOQ4ttCPptV/VWe119CeCCidg+taaFFFLQLzAekWegxVzihaT90yMS2dLT29ukle00= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608348669390.6640542805028; Tue, 15 Jul 2025 12:39:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublS7-0007sE-Uo; Tue, 15 Jul 2025 15:36:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxG-00049J-3A for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxD-0001Pj-Rg for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:41 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-_ze_WRkgNE6Ff2ikOTHkNg-1; Tue, 15 Jul 2025 15:04:37 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B4DCC19560B8; Tue, 15 Jul 2025 19:04:36 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 33AD8197702B; Tue, 15 Jul 2025 19:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606279; 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=6fjLhhOT1GHA5GeL6hb0wUmyYfZeXw2frUz0mOAoe1I=; b=QYgFCF7S5Wz/OW3hrzfbXJIibnY/4z4vgloTvrfyCiZgfKZGKY9yY454XlUIhhiG1aG99r ir/Kqk80T/1zzGsB8CMjYcAEKhJRJT7YLV79E3qNJqxznpUKs9VhuHLGYaWxrse0EzigpM hZbvOdaMnpTpy7g+S+L6XjSoGeyRzd4= X-MC-Unique: _ze_WRkgNE6Ff2ikOTHkNg-1 X-Mimecast-MFC-AGG-ID: _ze_WRkgNE6Ff2ikOTHkNg_1752606276 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 28/57] block/qapi: make @node-name in @BlockDeviceInfo non-optional Date: Tue, 15 Jul 2025 21:03:01 +0200 Message-ID: <20250715190330.378764-29-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608350401116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner Since commit 15489c769b ("block: auto-generated node-names"), if the node name of a block driver state is not explicitly specified, it will be auto-generated. Signed-off-by: Fiona Ebner Message-ID: <20250702123204.325470-3-f.ebner@proxmox.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qapi/block-core.json | 2 +- block/qapi.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 3e720af5ad..9d36927fc1 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -573,7 +573,7 @@ # Since: 0.14 ## { 'struct': 'BlockDeviceInfo', - 'data': { 'file': 'str', '*node-name': 'str', 'ro': 'bool', 'drv': 'str', + 'data': { 'file': 'str', 'node-name': 'str', 'ro': 'bool', 'drv': 'str', '*backing_file': 'str', 'backing_file_depth': 'int', 'children': ['BlockdevChild'], 'active': 'bool', 'encrypted': 'bool', diff --git a/block/qapi.c b/block/qapi.c index e08a1e970f..12fbf8d1b7 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -75,9 +75,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, .no_flush =3D !!(bs->open_flags & BDRV_O_NO_FLUSH), }; =20 - if (bs->node_name[0]) { - info->node_name =3D g_strdup(bs->node_name); - } + info->node_name =3D g_strdup(bs->node_name); =20 children_list_tail =3D &info->children; QLIST_FOREACH(child, &bs->children, next) { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608387; cv=none; d=zohomail.com; s=zohoarc; b=DPn42kbrWxF3h2vZsB80xJOHRDhd1TePU/pO8C4WsqeMitNq08mIMarYXxmLHOfhvCdlI2tLUcptlaOzLLB44aXHudEZxRbHgYF0Y7ZXGfrSQuJ6vwYvNzt8g7LOxQYcIIpy6VBpD5lRcNF2noiNFMlSX21Ibo4MTuw2+TKpbkk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608387; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jwt5Mohty/49Ops6zWjl3ddGYpwcfvV3jj65uyvQ3wQ=; b=cGc8XcU8vcqXwEGropJCUb/G6tUK9c73fVPWvAQ0Ky7UFKb61RRvdcYjY7sZ05JoloszY008ThlHeErxDshPPDcyh9ymyGwN9XOMoKoi0zcBXztaqRB7dOELGLk6DAAoLJ5E6TWVC++1l4NTT0IuIdKkcRknMeeekql4vJElOwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17526083874631020.4488881705555; Tue, 15 Jul 2025 12:39:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublSS-0008Ay-D0; Tue, 15 Jul 2025 15:36:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxI-0004AI-KP for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxG-0001QK-Ni for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:44 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-91uSZhf0N5-xU644URNtvQ-1; Tue, 15 Jul 2025 15:04:39 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DB54D19560B2; Tue, 15 Jul 2025 19:04:38 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 35C7C197702B; Tue, 15 Jul 2025 19:04:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606281; 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=jwt5Mohty/49Ops6zWjl3ddGYpwcfvV3jj65uyvQ3wQ=; b=c4j9g7z4ECbH41oKZpGVN15x6+gCSnQVlr4XSSeNmgILGvZZPfS9Ez4GGhlBi51WQOJmWD v5veAi+87N4XazSCaogpaD7QVEyqNGfF4ZiEeOCrudnre3gxqdrfhwyZkgMN5X9satyvUC ASaPRrySNnjOGI6IB8jkN8ZLLv7stSc= X-MC-Unique: 91uSZhf0N5-xU644URNtvQ-1 X-Mimecast-MFC-AGG-ID: 91uSZhf0N5-xU644URNtvQ_1752606279 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 29/57] file-posix: Fix aio=threads performance regression after enablign FUA Date: Tue, 15 Jul 2025 21:03:02 +0200 Message-ID: <20250715190330.378764-30-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608388826116600 Content-Type: text/plain; charset="utf-8" For aio=3Dthreads, we're currently not implementing REQ_FUA in any useful way, but just do a separate raw_co_flush_to_disk() call. This changes behaviour compared to the old state, which used bdrv_co_flush() with its optimisations. As a quick fix, call bdrv_co_flush() again like before. Eventually, we can use pwritev2() to make use of RWF_DSYNC if available, but we'll still have to keep this code path as a fallback, so this fix is required either way. While the fix itself is a one-liner, some new graph locking annotations are needed to convince TSA that the locking is correct. Cc: qemu-stable@nongnu.org Fixes: 984a32f17e8d ("file-posix: Support FUA writes") Buglink: https://issues.redhat.com/browse/RHEL-96854 Reported-by: Tingting Mao Signed-off-by: Kevin Wolf Message-ID: <20250625085019.27735-1-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/file-posix.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 9b5f08ccb2..8c738674ce 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2564,9 +2564,9 @@ static inline bool raw_check_linux_aio(BDRVRawState *= s) } #endif =20 -static int coroutine_fn raw_co_prw(BlockDriverState *bs, int64_t *offset_p= tr, - uint64_t bytes, QEMUIOVector *qiov, int= type, - int flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr, uint64_t bytes, + QEMUIOVector *qiov, int type, int flags) { BDRVRawState *s =3D bs->opaque; RawPosixAIOData acb; @@ -2625,7 +2625,7 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, int64_t *offset_ptr, ret =3D raw_thread_pool_submit(handle_aiocb_rw, &acb); if (ret =3D=3D 0 && (flags & BDRV_REQ_FUA)) { /* TODO Use pwritev2() instead if it's available */ - ret =3D raw_co_flush_to_disk(bs); + ret =3D bdrv_co_flush(bs); } goto out; /* Avoid the compiler err of unused label */ =20 @@ -2660,16 +2660,16 @@ out: return ret; } =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) { return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_READ, 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) { return raw_co_prw(bs, &offset, bytes, qiov, QEMU_AIO_WRITE, flags); } @@ -3606,10 +3606,11 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDrive= rState *bs, BlockZoneOp op, #endif =20 #if defined(CONFIG_BLKZONED) -static int coroutine_fn raw_co_zone_append(BlockDriverState *bs, - int64_t *offset, - QEMUIOVector *qiov, - BdrvRequestFlags flags) { +static int coroutine_fn GRAPH_RDLOCK +raw_co_zone_append(BlockDriverState *bs, + int64_t *offset, + QEMUIOVector *qiov, + BdrvRequestFlags flags) { assert(flags =3D=3D 0); int64_t zone_size_mask =3D bs->bl.zone_size - 1; int64_t iov_len =3D 0; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608638; cv=none; d=zohomail.com; s=zohoarc; b=ZHmZ15as/gRlWelXzEPwNfQ3JnKw5Pvp05gUYkfo+387zd5n5rmDVBJkZneMS8qZgIJbN2Lz0zIgBMPNEWdG1r613IhIuWoJDdqRV/LHTKE3umyCJpIPwYHa0MSDS2U3KRzdtxLEOlRBBLCmLLtOeHvBVBedumRy5VfwQCwM64o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608638; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jwgv47YLUvO/F34uGxNiYd+WQOW4mbMcciSwO93qLOg=; b=Lclx87VY1ljNNRPZPRcLcbNKoBv2TIQ2lKUlyk1ATGL3pH5UC8KVXnPmGY6nb90m1ISBKyNjdpoI3+fwEguV298Dwlmk+n5ysnmv+fa9NPvhAB2WbdHLB7WZa2ACoOHbrhkSnuSnDWs0Jx+TIWPqb06I7LellY6JZKN9733XSeU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608638242178.7994735197251; Tue, 15 Jul 2025 12:43:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublYl-0002sx-87; Tue, 15 Jul 2025 15:43:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxK-0004Ad-Ea for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxI-0001Qg-5m for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:46 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-TUJmSdTaPyOVv6sPNnbCEg-1; Tue, 15 Jul 2025 15:04:41 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E4C6B19560B3; Tue, 15 Jul 2025 19:04:40 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5C62E197702B; Tue, 15 Jul 2025 19:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606283; 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=jwgv47YLUvO/F34uGxNiYd+WQOW4mbMcciSwO93qLOg=; b=EfpK9PG48idQ22HsV6SI/PA3KM/FOy9N1g6RZAqrEEO0JpxNypJc0uoXeirT1CZsAcoMFw XMJ2vOnJy/o8mTc/wg2WUnpc8QjSCZFyrxhvbaebPAWW2i3dkvfkZFSLDUJgm43rmdBZSe EPLiEna4yXTS42Rz/KQ2I4fQAnv4bvM= X-MC-Unique: TUJmSdTaPyOVv6sPNnbCEg-1 X-Mimecast-MFC-AGG-ID: TUJmSdTaPyOVv6sPNnbCEg_1752606281 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 30/57] iotests: add test for changing the 'drive' property via 'qom-set' Date: Tue, 15 Jul 2025 21:03:03 +0200 Message-ID: <20250715190330.378764-31-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608639218116600 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner Signed-off-by: Fiona Ebner Message-ID: <20250605100938.43133-1-f.ebner@proxmox.com> [kwolf: Fixed up pylint warnings flagged by 297] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/qom-set-drive | 75 ++++++++++++++++++++++ tests/qemu-iotests/tests/qom-set-drive.out | 11 ++++ 2 files changed, 86 insertions(+) create mode 100755 tests/qemu-iotests/tests/qom-set-drive create mode 100644 tests/qemu-iotests/tests/qom-set-drive.out diff --git a/tests/qemu-iotests/tests/qom-set-drive b/tests/qemu-iotests/te= sts/qom-set-drive new file mode 100755 index 0000000000..ec8ddac4fd --- /dev/null +++ b/tests/qemu-iotests/tests/qom-set-drive @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# group: quick +# +# Test how changing the 'drive' property via 'qom-set' behaves. +# +# Copyright (C) Proxmox Server Solutions GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import os +import iotests +from iotests import imgfmt, log, qemu_img_create, QMPTestCase + +image_size =3D 1 * 1024 * 1024 +images =3D [os.path.join(iotests.test_dir, f'{i}.img') for i in range(0, 4= )] + +class TestQOMSetDrive(QMPTestCase): + def setUp(self) -> None: + for image in images: + qemu_img_create('-f', imgfmt, image, str(image_size)) + + self.vm =3D iotests.VM() + for i, image in enumerate(images): + self.vm.add_blockdev(self.vm.qmp_to_opts({ + 'driver': imgfmt, + 'node-name': f'node{i}', + 'file': { + 'driver': 'file', + 'filename': image, + } + })) + self.vm.add_object('iothread,id=3Diothread0') + self.vm.add_device('virtio-scsi,iothread=3Diothread0') + self.vm.add_device('scsi-hd,id=3Diot,drive=3Dnode0') + self.vm.add_device('virtio-scsi') + self.vm.add_device('scsi-hd,id=3Dno-iot,drive=3Dnode1') + self.vm.launch() + + def tearDown(self) -> None: + self.vm.shutdown() + for image in images: + os.remove(image) + + def test_qom_set_drive(self) -> None: + log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/iot', + property=3D'drive')) + log(self.vm.qmp('qom-set', path=3D'/machine/peripheral/iot', + property=3D'drive', value=3D'node2')) + log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/iot', + property=3D'drive')) + + log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/no-iot', + property=3D'drive')) + log(self.vm.qmp('qom-set', path=3D'/machine/peripheral/no-iot', + property=3D'drive', value=3D'node3')) + log(self.vm.qmp('qom-get', path=3D'/machine/peripheral/no-iot', + property=3D'drive')) + +if __name__ =3D=3D '__main__': + iotests.activate_logging() + # LUKS would require special key-secret handling in add_blockdevs() + iotests.main(supported_fmts=3D['generic'], + unsupported_fmts=3D['luks']) diff --git a/tests/qemu-iotests/tests/qom-set-drive.out b/tests/qemu-iotest= s/tests/qom-set-drive.out new file mode 100644 index 0000000000..7fc243dca6 --- /dev/null +++ b/tests/qemu-iotests/tests/qom-set-drive.out @@ -0,0 +1,11 @@ +{"return": "node0"} +{"error": {"class": "GenericError", "desc": "Different aio context is not = supported for new node"}} +{"return": "node0"} +{"return": "node1"} +{"return": {}} +{"return": "node3"} +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608841; cv=none; d=zohomail.com; s=zohoarc; b=GCbskrYHvFNF0sgiRgAIjB/PJGeyb8TkDJ9C9ke/6/nwKCaz6PRTfOEaPLi8FYFCIct/Yfo56o4w6MsxFDeebNq3p8q7uVDMvbgFV1EqVBLWtxSM0G1sHgRYSWTJJp2qcAzMX6ft7xgoLl3JR+zZQtSuBRHV54dcAQEAi1FKoHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608841; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dyVMTv6sGhp4EucS+e3TQ9pqVVDsby/Mjxux88RCYOU=; b=TwanFfIUi1X++lbgz4703gMoXQ8skQgcQ8vurvr8/xYKosEXxnLoHqV+9aJgsMXc1y8US7hbLTJJlHbpkcX20S77S41cM6yqHYHOmw3lpoQxSq0Yf47HF3JqDBWEmHcpiVgYX1kqnmn1h5qSg1+aVcPbBYqj2/LbC1f21Z5LDTw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608841173231.34616746078393; Tue, 15 Jul 2025 12:47:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublYp-0003GB-OG; Tue, 15 Jul 2025 15:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxM-0004BD-72 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxK-0001RA-De for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:47 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-FOwqosT3MmOyx3uCB1DHZA-1; Tue, 15 Jul 2025 15:04:43 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EB1D31956080; Tue, 15 Jul 2025 19:04:42 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 66780197702B; Tue, 15 Jul 2025 19:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606285; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dyVMTv6sGhp4EucS+e3TQ9pqVVDsby/Mjxux88RCYOU=; b=OGLdp+lAofnAlFTwLibRKJNrP4LoIljX9CHxFYlIzOBhdlfNsN9OVNLkRQSy4nDPAXYhqP WUJWpSpng+dJ9JQE1cuSNPdCBwvqkECHbJTNwuFrB3YS9VLyIKbq3kjSbXPXkzND2rcmLr azbqcI0tfrTb9JMuV3+kOerzM5mvd5A= X-MC-Unique: FOwqosT3MmOyx3uCB1DHZA-1 X-Mimecast-MFC-AGG-ID: FOwqosT3MmOyx3uCB1DHZA_1752606283 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 31/57] qemu-img: measure: convert img_size to signed, simplify handling Date: Tue, 15 Jul 2025 21:03:04 +0200 Message-ID: <20250715190330.378764-32-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608841877116600 From: Michael Tokarev qemu_opt_set_number() expects signed int64_t. Use int64_t instead of uint64_t for img_size, use -1 as "unset" value instead of UINT64_MAX, and do not require temporary sval for conversion from string. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-2-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- qemu-img.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e75707180d..e676602fc7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5370,7 +5370,7 @@ static int img_measure(int argc, char **argv) QemuOpts *sn_opts =3D NULL; QemuOptsList *create_opts =3D NULL; bool image_opts =3D false; - uint64_t img_size =3D UINT64_MAX; + int64_t img_size =3D -1; BlockMeasureInfo *info =3D NULL; Error *local_err =3D NULL; int ret =3D 1; @@ -5428,16 +5428,11 @@ static int img_measure(int argc, char **argv) } break; case OPTION_SIZE: - { - int64_t sval; - - sval =3D cvtnum("image size", optarg); - if (sval < 0) { + img_size =3D cvtnum("image size", optarg); + if (img_size < 0) { goto out; } - img_size =3D (uint64_t)sval; - } - break; + break; } } =20 @@ -5452,11 +5447,11 @@ static int img_measure(int argc, char **argv) error_report("--image-opts, -f, and -l require a filename argument= ."); goto out; } - if (filename && img_size !=3D UINT64_MAX) { + if (filename && img_size !=3D -1) { error_report("--size N cannot be used together with a filename."); goto out; } - if (!filename && img_size =3D=3D UINT64_MAX) { + if (!filename && img_size =3D=3D -1) { error_report("Either --size N or one filename must be specified."); goto out; } @@ -5504,7 +5499,7 @@ static int img_measure(int argc, char **argv) goto out; } } - if (img_size !=3D UINT64_MAX) { + if (img_size !=3D -1) { qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort); } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608642; cv=none; d=zohomail.com; s=zohoarc; b=jvFKGWpf6674ILy43inWOimOttxdA4wL48EOFCClVVvBagcV0htf9VWfWKx0ASpBcmuQTZcF6owNB/cQBp9VkQovn+zjgIi6BGIk+us9l2L9IMAdBCogHvuBxv8C8kQzFgetPdGvpq8eH3kQi61i/j6i+s4IH/3q5S70ypsJS/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608642; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9NhuAW73W93wsBq/i0J12yeR0nN/1/SZBmn64E0RS5A=; b=higdJ0tpmqanZH2XLI0rnpIVmZMHowzVGoFUWQEfBC7jixb0kUBdXSRZC+mvJufbtzR2o++CnYerr45CyWlhE0nWrOArZ/2XluEm4XF5/V/xR7pJZCMnly2OldjeYDasaBU59NVWPLySHFGPEIx7ur6RHYbhKCfcrTFNPlHpdKo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608642215123.34212288916558; Tue, 15 Jul 2025 12:44:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublZ9-000512-HC; Tue, 15 Jul 2025 15:43:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxO-0004CS-Ma for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxM-0001RX-I1 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:49 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-685-7xOFwz53PGCAQ2b7K2TJcw-1; Tue, 15 Jul 2025 15:04:46 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5962E180120B; Tue, 15 Jul 2025 19:04:45 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C138197702C; Tue, 15 Jul 2025 19:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9NhuAW73W93wsBq/i0J12yeR0nN/1/SZBmn64E0RS5A=; b=P8cck4ZADp2AR3pM8caVYeoMtRCuAGS47oSjvErU1cv/77GnHWwv88wU16DBOM7hB8odpA tc2mDlZiw2Osn5bNe4jjoaMlFy6gU62qp4VHGcUvIua3Quity8eyMWI5iFjCaON5nMtcek a/ROehxZtCAn0IGVGjScFRu2MJK4CNM= X-MC-Unique: 7xOFwz53PGCAQ2b7K2TJcw-1 X-Mimecast-MFC-AGG-ID: 7xOFwz53PGCAQ2b7K2TJcw_1752606285 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 32/57] qemu-img: create: convert img_size to signed, simplify handling Date: Tue, 15 Jul 2025 21:03:05 +0200 Message-ID: <20250715190330.378764-33-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608643139116600 From: Michael Tokarev Initializing an unsigned as -1, or using temporary sval for conversion is awkward. Since we don't allow other "negative" values anyway, use signed value and pass it to bdrv_img_create() (where it is properly converted to unsigned), simplifying code. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-3-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- qemu-img.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e676602fc7..6750d0657c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -511,7 +511,7 @@ static int64_t cvtnum(const char *name, const char *val= ue) static int img_create(int argc, char **argv) { int c; - uint64_t img_size =3D -1; + int64_t img_size =3D -1; const char *fmt =3D "raw"; const char *base_fmt =3D NULL; const char *filename; @@ -582,13 +582,10 @@ static int img_create(int argc, char **argv) =20 /* Get image size, if specified */ if (optind < argc) { - int64_t sval; - - sval =3D cvtnum("image size", argv[optind++]); - if (sval < 0) { + img_size =3D cvtnum("image size", argv[optind++]); + if (img_size < 0) { goto fail; } - img_size =3D (uint64_t)sval; } if (optind !=3D argc) { error_exit("Unexpected argument: %s", argv[optind]); --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608561; cv=none; d=zohomail.com; s=zohoarc; b=Uv03kQHeHTbHKEvbC93W5TXr51ZtpQbMoYzoSUR76e/ywmqbXKGz/MTHUDURqiNhC3WhIApUGJhAih4x5Jsk+5ebXp1qQj2ocNxmLjsGsY78ChzOF6AaqKOomTSom7M3NzBcm3AQwPVE+l/EvVYLs5mziY9amQGKSXQAzkQ2dds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608561; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Lcx2wzGaS53mFUdsdlrkWfIFIGOdWPdB1nafAxmupgI=; b=eedtKH6krv9crKXOqBsDMYV9j6lufosHnTcHCyKv0vSofASQMR9lvmSsiuOQn5zNMPex2UJ4lYTWO8e/9iqqgQuCUbQav5f2FWLlgoCOAMmybMzs/wvoS/AG4dOyfCZd+KcwGr6llvmAytq4n/rWoq/coIhDxOv2vZlyfsVD69M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608561972421.04150336263206; Tue, 15 Jul 2025 12:42:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublUX-0001UD-No; Tue, 15 Jul 2025 15:39:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxR-0004I7-I5 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxP-0001SC-2l for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:53 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664--wAcHJHFPmOer6ljuAFwDw-1; Tue, 15 Jul 2025 15:04:48 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5B2EB19560A7; Tue, 15 Jul 2025 19:04:47 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CECBA197702B; Tue, 15 Jul 2025 19:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606290; 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=Lcx2wzGaS53mFUdsdlrkWfIFIGOdWPdB1nafAxmupgI=; b=itlhdTS9rgdys8imYJjqWfqvTSO1Js8fDdPf5J5dXzx0ectntT8baCmlyrkK6ayHyY6vEM fbxiOZekuNXxY/GaGc43AeqbL9ckupZxg+XZd0O7inyuclFRoZDPpkyp/mku0mN3mkxKmr T6HsL4jrkXcJ7v5jocxdvahLNKa2mfw= X-MC-Unique: -wAcHJHFPmOer6ljuAFwDw-1 X-Mimecast-MFC-AGG-ID: -wAcHJHFPmOer6ljuAFwDw_1752606287 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 33/57] qemu-img: global option processing and error printing Date: Tue, 15 Jul 2025 21:03:06 +0200 Message-ID: <20250715190330.378764-34-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608564559116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev In order to correctly print executable name in various error messages, pass argv[0] to error_exit() function. This way, error messages will refer to actual executable name, which may be different from 'qemu-img'. For subcommands, pass original command name from the qemu-img argv[0], plus the subcommand name, as its own argv[0] element, so error messages can be more useful. Also don't require at least 3 options on the command line: it makes no sense with options before subcommand. Introduce tryhelp() function which just prints try 'command-name --help' for more info and exits. When tryhelp() is called from within a subcommand handler, the message will look like: try 'command-name subcommand --help' for more information qemu-img uses getopt_long() with ':' as the first char in optstring parameter, which means it doesn't print error messages but return ':' or '?' instead, and qemu-img uses unrecognized_option() or missing_argument() function to print error messages. But it doesn't quite work: $ ./qemu-img -xx qemu-img: unrecognized option './qemu-img' so the aim is to let getopt_long() to print regular error messages instead (removing ':' prefix from optstring) and remove handling of '?' and ':' "options" entirely. With concatenated argv[0] and the subcommand, it all finally does the right thing in all cases. This will be done in subsequent changes command by command, with main() done last. unrecognized_option() and missing_argument() functions prototypes aren't changed by this patch, since they're called from many places and will be removed a few patches later. Only artifical "qemu-img" argv0 is provided in there for now. Signed-off-by: Michael Tokarev Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-4-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- qemu-img.c | 80 +++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6750d0657c..2b46c952bd 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -101,8 +101,15 @@ static void format_print(void *opaque, const char *nam= e) printf(" %s", name); } =20 -static G_NORETURN G_GNUC_PRINTF(1, 2) -void error_exit(const char *fmt, ...) +static G_NORETURN +void tryhelp(const char *argv0) +{ + error_printf("Try '%s --help' for more information\n", argv0); + exit(EXIT_FAILURE); +} + +static G_NORETURN G_GNUC_PRINTF(2, 3) +void error_exit(const char *argv0, const char *fmt, ...) { va_list ap; =20 @@ -110,20 +117,19 @@ void error_exit(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); =20 - error_printf("Try 'qemu-img --help' for more information\n"); - exit(EXIT_FAILURE); + tryhelp(argv0); } =20 static G_NORETURN void missing_argument(const char *option) { - error_exit("missing argument for option '%s'", option); + error_exit("qemu-img", "missing argument for option '%s'", option); } =20 static G_NORETURN void unrecognized_option(const char *option) { - error_exit("unrecognized option '%s'", option); + error_exit("qemu-img", "unrecognized option '%s'", option); } =20 /* Please keep in synch with docs/tools/qemu-img.rst */ @@ -576,7 +582,7 @@ static int img_create(int argc, char **argv) } =20 if (optind >=3D argc) { - error_exit("Expecting image file name"); + error_exit(argv[0], "Expecting image file name"); } optind++; =20 @@ -588,7 +594,7 @@ static int img_create(int argc, char **argv) } } if (optind !=3D argc) { - error_exit("Unexpected argument: %s", argv[optind]); + error_exit(argv[0], "Unexpected argument: %s", argv[optind]); } =20 bdrv_img_create(filename, fmt, base_filename, base_fmt, @@ -770,7 +776,7 @@ static int img_check(int argc, char **argv) } else if (!strcmp(optarg, "all")) { fix =3D BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit("Unknown option value for -r " + error_exit(argv[0], "Unknown option value for -r " "(expecting 'leaks' or 'all'): %s", optarg); } break; @@ -795,7 +801,7 @@ static int img_check(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -1025,7 +1031,7 @@ static int img_commit(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -1446,7 +1452,7 @@ static int img_compare(int argc, char **argv) =20 =20 if (optind !=3D argc - 2) { - error_exit("Expecting two image file names"); + error_exit(argv[0], "Expecting two image file names"); } filename1 =3D argv[optind++]; filename2 =3D argv[optind++]; @@ -3056,7 +3062,7 @@ static int img_info(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -3296,7 +3302,7 @@ static int img_map(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind]; =20 @@ -3411,7 +3417,7 @@ static int img_snapshot(int argc, char **argv) return 0; case 'l': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_LIST; @@ -3419,7 +3425,7 @@ static int img_snapshot(int argc, char **argv) break; case 'a': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_APPLY; @@ -3427,7 +3433,7 @@ static int img_snapshot(int argc, char **argv) break; case 'c': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_CREATE; @@ -3435,7 +3441,7 @@ static int img_snapshot(int argc, char **argv) break; case 'd': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_DELETE; @@ -3457,7 +3463,7 @@ static int img_snapshot(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -3626,10 +3632,11 @@ static int img_rebase(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } if (!unsafe && !out_baseimg) { - error_exit("Must specify backing file (-b) or use unsafe mode (-u)= "); + error_exit(argv[0], + "Must specify backing file (-b) or use unsafe mode (-u)= "); } filename =3D argv[optind++]; =20 @@ -4053,7 +4060,7 @@ static int img_resize(int argc, char **argv) /* Remove size from argv manually so that negative numbers are not tre= ated * as options by getopt. */ if (argc < 3) { - error_exit("Not enough arguments"); + error_exit(argv[0], "Not enough arguments"); return 1; } =20 @@ -4111,7 +4118,7 @@ static int img_resize(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting image file name and size"); + error_exit(argv[0], "Expecting image file name and size"); } filename =3D argv[optind++]; =20 @@ -4308,7 +4315,7 @@ static int img_amend(int argc, char **argv) } =20 if (!options) { - error_exit("Must specify options (-o)"); + error_exit(argv[0], "Must specify options (-o)"); } =20 if (quiet) { @@ -4674,7 +4681,7 @@ static int img_bench(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[argc - 1]; =20 @@ -5564,9 +5571,6 @@ int main(int argc, char **argv) =20 module_call_init(MODULE_INIT_QOM); bdrv_init(); - if (argc < 2) { - error_exit("Not enough arguments"); - } =20 qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); @@ -5591,15 +5595,11 @@ int main(int argc, char **argv) } } =20 - cmdname =3D argv[optind]; - - /* reset getopt_long scanning */ - argc -=3D optind; - if (argc < 1) { - return 0; + if (optind >=3D argc) { + error_exit(argv[0], "Not enough arguments"); } - argv +=3D optind; - qemu_reset_optind(); + + cmdname =3D argv[optind]; =20 if (!trace_init_backends()) { exit(1); @@ -5610,10 +5610,16 @@ int main(int argc, char **argv) /* find the command */ for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { + g_autofree char *argv0 =3D g_strdup_printf("%s %s", argv[0], c= mdname); + /* reset options and getopt processing (incl return order) */ + argv +=3D optind; + argc -=3D optind; + qemu_reset_optind(); + argv[0] =3D argv0; return cmd->handler(argc, argv); } } =20 /* not found */ - error_exit("Command not found: %s", cmdname); + error_exit(argv[0], "Command not found: %s", cmdname); } --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608377; cv=none; d=zohomail.com; s=zohoarc; b=caa9/q/Rgtk61xrJEL/LkUiCiAgC7UYnODUfBC+Zwk7dMyCU+oBWiK+tyd0XA/aqTxdZbbp9wEFSV2d0SSuQ+Ih+LkK7qe1M9aaSirJwwNE7ksZtfX45wShpemMfZwsz4H6ewCuKYE6vs29hbMcbFaXznij7yeezPSD7jXpjYuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608377; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MF94GLS9hbxCifMMuMwtaL2X4rcz7DYsJClkdEjiWBA=; b=aA9t5MOuX+nNWWQHmBPgKpA6D1tm3b2aoCrxGBVzvOrVRUl7yQi7RUaFyStZrSeLSC9byNo6OQ+9ROydgUz/jxSTGnbV9TNf5d/3fHIWdP74WprxPIj2nLsTWARpWjMuJ5sPT4+aWuzCnTpoU9er+Qn/hB6KUq7qjJI3uKfr88U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608377588295.13429188901614; Tue, 15 Jul 2025 12:39:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublUb-0001hq-V0; Tue, 15 Jul 2025 15:39:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxU-0004OC-QC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxR-0001Sg-RP for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:56 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-Zmb7VfpUPX6IgBV0WPZL0g-1; Tue, 15 Jul 2025 15:04:50 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5DB1A19560B3; Tue, 15 Jul 2025 19:04:49 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D134C197702B; Tue, 15 Jul 2025 19:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MF94GLS9hbxCifMMuMwtaL2X4rcz7DYsJClkdEjiWBA=; b=YfKwTzjIIV8ypGuASeRZJUW0o/Ea3F4SxqzyBvV3Ad4OE61M37PeNKnORZz4xemtTf3EX0 9LWNoG3haCaQAQxe+0ARDKmaZCOPB3JwrWPAOzjFqJ7VqlfD7eevv+JEmUvbPqNm/D9rLw 00+9wMrbO2NY0eghRSXLUZbshpFHIHM= X-MC-Unique: Zmb7VfpUPX6IgBV0WPZL0g-1 X-Mimecast-MFC-AGG-ID: Zmb7VfpUPX6IgBV0WPZL0g_1752606289 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 34/57] qemu-img: pass current cmd info into command handlers Date: Tue, 15 Jul 2025 21:03:07 +0200 Message-ID: <20250715190330.378764-35-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608378791116600 From: Michael Tokarev This info will be used to generate --help output. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-5-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- qemu-img.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 2b46c952bd..a414837355 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -60,7 +60,7 @@ =20 typedef struct img_cmd_t { const char *name; - int (*handler)(int argc, char **argv); + int (*handler)(const struct img_cmd_t *ccmd, int argc, char **argv); } img_cmd_t; =20 enum { @@ -514,7 +514,7 @@ static int64_t cvtnum(const char *name, const char *val= ue) return cvtnum_full(name, value, 0, INT64_MAX); } =20 -static int img_create(int argc, char **argv) +static int img_create(const img_cmd_t *ccmd, int argc, char **argv) { int c; int64_t img_size =3D -1; @@ -719,7 +719,7 @@ static int collect_image_check(BlockDriverState *bs, * 3 - Check completed, image has leaked clusters, but is good otherwise * 63 - Checks are not supported by the image format */ -static int img_check(int argc, char **argv) +static int img_check(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -951,7 +951,7 @@ static void run_block_job(BlockJob *job, Error **errp) } } =20 -static int img_commit(int argc, char **argv) +static int img_commit(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret, flags; const char *filename, *fmt, *cache, *base; @@ -1358,7 +1358,7 @@ static int check_empty_sectors(BlockBackend *blk, int= 64_t offset, * 1 - Images differ * >1 - Error occurred */ -static int img_compare(int argc, char **argv) +static int img_compare(const img_cmd_t *ccmd, int argc, char **argv) { const char *fmt1 =3D NULL, *fmt2 =3D NULL, *cache, *filename1, *filena= me2; BlockBackend *blk1, *blk2; @@ -2234,7 +2234,7 @@ static void set_rate_limit(BlockBackend *blk, int64_t= rate_limit) blk_set_io_limits(blk, &cfg); } =20 -static int img_convert(int argc, char **argv) +static int img_convert(const img_cmd_t *ccmd, int argc, char **argv) { int c, bs_i, flags, src_flags =3D BDRV_O_NO_SHARE; const char *fmt =3D NULL, *out_fmt =3D NULL, *cache =3D "unsafe", @@ -3002,7 +3002,7 @@ err: return NULL; } =20 -static int img_info(int argc, char **argv) +static int img_info(const img_cmd_t *ccmd, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3227,7 +3227,7 @@ static inline bool entry_mergeable(const MapEntry *cu= rr, const MapEntry *next) return true; } =20 -static int img_map(int argc, char **argv) +static int img_map(const img_cmd_t *ccmd, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3376,7 +3376,7 @@ out: #define SNAPSHOT_APPLY 3 #define SNAPSHOT_DELETE 4 =20 -static int img_snapshot(int argc, char **argv) +static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) { BlockBackend *blk; BlockDriverState *bs; @@ -3536,7 +3536,7 @@ static int img_snapshot(int argc, char **argv) return 0; } =20 -static int img_rebase(int argc, char **argv) +static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv) { BlockBackend *blk =3D NULL, *blk_old_backing =3D NULL, *blk_new_backin= g =3D NULL; uint8_t *buf_old =3D NULL; @@ -4030,7 +4030,7 @@ out: return 0; } =20 -static int img_resize(int argc, char **argv) +static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret, relative; @@ -4243,7 +4243,7 @@ static int print_amend_option_help(const char *format) return 0; } =20 -static int img_amend(int argc, char **argv) +static int img_amend(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 0; @@ -4511,7 +4511,7 @@ static void bench_cb(void *opaque, int ret) } } =20 -static int img_bench(int argc, char **argv) +static int img_bench(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret =3D 0; const char *fmt =3D NULL, *filename; @@ -4781,7 +4781,7 @@ typedef struct ImgBitmapAction { QSIMPLEQ_ENTRY(ImgBitmapAction) next; } ImgBitmapAction; =20 -static int img_bitmap(int argc, char **argv) +static int img_bitmap(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 1; @@ -5081,7 +5081,7 @@ static int img_dd_skip(const char *arg, return 0; } =20 -static int img_dd(int argc, char **argv) +static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) { int ret =3D 0; char *arg =3D NULL; @@ -5349,7 +5349,7 @@ static void dump_json_block_measure_info(BlockMeasure= Info *info) g_string_free(str, true); } =20 -static int img_measure(int argc, char **argv) +static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, @@ -5616,7 +5616,7 @@ int main(int argc, char **argv) argc -=3D optind; qemu_reset_optind(); argv[0] =3D argv0; - return cmd->handler(argc, argv); + return cmd->handler(cmd, argc, argv); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608358; cv=none; d=zohomail.com; s=zohoarc; b=mYizDlKLKhJ3EcC3ZH4H+Zu/FEl7Bj2w2JVqiuOUd2NazC8G9AwD3yQ4yDHm+gob1aMOx5i7dBssNBPsVl7vI8QFT13Mfl+Vr+bgF3LYiUYeF+DPtXv5q8YhVbUaolAL1sneJfiZ3/cwCFApmI1MjzB4aSgy0Ps9thoYmatpHW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608358; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MR2FV6a5MtTZ7KdPBHSUvlXl7xgnuFs2u3Ga4lwOEwo=; b=HnciljpxeuNYjq4H5BRX14T7VfvwWc2ox+QMDfDnRSxjDwhyLBDgK3TluU30uPXTVVqG7qny+cttie4KO+MzzQSGkrieO1WbgOHuaCbMwf74TlmKfcozNcNj69b8PSvouABzJ1RLIu2bcagAK3G30WrI4wINpAQUcCiEm0DCctY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608358191524.9204646823533; Tue, 15 Jul 2025 12:39:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublUf-00021M-IV; Tue, 15 Jul 2025 15:39:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxX-0004Oj-GS for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxU-0001T9-17 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:58 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-14-59K3q9-fMHOcBdJSk4pvRg-1; Tue, 15 Jul 2025 15:04:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A761119560B5; Tue, 15 Jul 2025 19:04:51 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5A25197702B; Tue, 15 Jul 2025 19:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606294; 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=MR2FV6a5MtTZ7KdPBHSUvlXl7xgnuFs2u3Ga4lwOEwo=; b=U+IDYTO/hDJVMKYx325xRT54Yg62t88YdVY379LCzuhl6yll2ip03W9nAYrDNyzVhEg9Xv MZpNIlVhS2EiY+IOcnUHi8w0h+gCC3JOfj4Q3tyjoLSdqGAHsmDEJQDdWBAd5l9eYDhoFq wyoN5AgnBl8S8igeMXfL2C2tXkVyBdk= X-MC-Unique: 59K3q9-fMHOcBdJSk4pvRg-1 X-Mimecast-MFC-AGG-ID: 59K3q9-fMHOcBdJSk4pvRg_1752606291 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 35/57] qemu-img: create: refresh options/--help (short option change) Date: Tue, 15 Jul 2025 21:03:08 +0200 Message-ID: <20250715190330.378764-36-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608358605116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Create helper function cmd_help() to display command-specific help text, and use it to print --help for 'create' subcommand. Add missing long options (eg --format) in img_create(). Recognize -B option for --backing-format, keep -F for backward compatibility, Reorder options for consistency. Remove usage of missing_argument()/unrecognized_option() in img_create(). Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-6-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 10 ++--- qemu-img.c | 84 +++++++++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 21 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 3653adb963..a21e439082 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -467,11 +467,11 @@ Command description: ``--skip-broken-bitmaps`` is also specified to copy only the consistent bitmaps. =20 -.. option:: create [--object OBJECTDEF] [-q] [-f FMT] [-b BACKING_FILE [-F= BACKING_FMT]] [-u] [-o OPTIONS] FILENAME [SIZE] +.. option:: create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILE [-B BACKING_FMT= ]] [-u] [-q] [--object OBJDEF] FILE [SIZE] =20 - Create the new disk image *FILENAME* of size *SIZE* and format - *FMT*. Depending on the file format, you can add one or more *OPTIONS* - that enable additional features of this format. + Create the new disk image *FILE* of size *SIZE* and format + *FMT*. Depending on the file format, you can add one or more *FMT_OPTS* + options that enable additional features of this format. =20 If the option *BACKING_FILE* is specified, then the image will record only the differences from *BACKING_FILE*. No size needs to be specified = in @@ -479,7 +479,7 @@ Command description: ``commit`` monitor command (or ``qemu-img commit``). =20 If a relative path name is given, the backing file is looked up relative= to - the directory containing *FILENAME*. + the directory containing *FILE*. =20 Note that a given backing file will be opened to check that it is valid.= Use the ``-u`` option to enable unsafe backing file mode, which means that t= he diff --git a/qemu-img.c b/qemu-img.c index a414837355..6569efd310 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -132,6 +132,32 @@ void unrecognized_option(const char *option) error_exit("qemu-img", "unrecognized option '%s'", option); } =20 +/* + * Print --help output for a command and exit. + * @syntax and @description are multi-line with trailing EOL + * (to allow easy extending of the text) + * @syntax has each subsequent line indented by 8 chars. + * @description is indented by 2 chars for argument on each own line, + * and with 5 chars for argument description (like -h arg below). + */ +static G_NORETURN +void cmd_help(const img_cmd_t *ccmd, + const char *syntax, const char *arguments) +{ + printf( +"Usage:\n" +"\n" +" %s %s %s" +"\n" +"Arguments:\n" +" -h, --help\n" +" print this help and exit\n" +"%s\n", + "qemu-img", ccmd->name, + syntax, arguments); + exit(EXIT_SUCCESS); +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -530,29 +556,46 @@ static int img_create(const img_cmd_t *ccmd, int argc= , char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"format", required_argument, 0, 'f'}, + {"options", required_argument, 0, 'o'}, + {"backing", required_argument, 0, 'b'}, + {"backing-format", required_argument, 0, 'B'}, /* was -F in 10= .0 */ + {"backing-unsafe", no_argument, 0, 'u'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":F:b:f:ho:qu", + c =3D getopt_long(argc, argv, "hf:o:b:F:B:uq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - break; - case 'F': - base_fmt =3D optarg; - break; - case 'b': - base_filename =3D optarg; + cmd_help(ccmd, "[-f FMT] [-o FMT_OPTS]\n" +" [-b BACKING_FILE [-B BACKING_FMT]] [-u]\n" +" [-q] [--object OBJDEF] FILE [SIZE]\n" +, +" -f, --format FMT\n" +" specifies the format of the new image (default: raw)\n" +" -o, --options FMT_OPTS\n" +" format-specific options (specify '-o help' for help)\n" +" -b, --backing BACKING_FILE\n" +" create target image to be a CoW on top of BACKING_FILE\n" +" -B, --backing-format BACKING_FMT (was -F in <=3D 10.0)\n" +" specifies the format of BACKING_FILE (default: probing is used)\n" +" -u, --backing-unsafe\n" +" do not fail if BACKING_FILE can not be read\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file to create (will be overritten if already exis= ts)\n" +" SIZE[bKMGTPE]\n" +" image size with optional multiplier suffix (powers of 1024)\n" +" (required unless BACKING_FILE is specified)\n" +); break; case 'f': fmt =3D optarg; @@ -562,15 +605,24 @@ static int img_create(const img_cmd_t *ccmd, int argc= , char **argv) goto fail; } break; - case 'q': - quiet =3D true; + case 'b': + base_filename =3D optarg; + break; + case 'F': /* <=3D10.0 */ + case 'B': + base_fmt =3D optarg; break; case 'u': flags |=3D BDRV_O_NO_BACKING; break; + case 'q': + quiet =3D true; + break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608012; cv=none; d=zohomail.com; s=zohoarc; b=IE7fuYtkAW/Lhj0P87fq6JFgZRB+Wg1k+XPADQje3kYRhgNhVa3Kk9zUVwpIjAIxWIIQtRIafpiChaHvlK+J43Md5/ZrsRygusyK1mTfx2rx8gKauAgSGaREQUSxldn7P9rUR+jf+kCj9glVIbmUsNCSlZZsRTcbgUwum0Gz/Mo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608012; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rijoJi/Ykv0GahCauUjFN1CRQ9kyD3BH1g9TE573ntg=; b=X8gV7He9CuCVEzjwFSsy6U8bv/w3muRRx8/AQ4sWKZSD+klHhh6Te68ky//xPSY7xw4mbDrdjm56/SsrCTGFq1L/j2vk9lE6zZ/7C3ebc0Iwboo5t2RZQpTUvJU02rBmGFfUzwRVEqdLnIfoNKhiI2ctLQ6sguJiYOaW+IytnZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608012664807.2870793669861; Tue, 15 Jul 2025 12:33:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublOj-0005tk-PZ; Tue, 15 Jul 2025 15:33:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxX-0004Ol-HC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxU-0001TN-GN for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:04:58 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-132-Z7B_Cy8BMuq2JVut03FOuw-1; Tue, 15 Jul 2025 15:04:54 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 74B3419560B5; Tue, 15 Jul 2025 19:04:53 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E81B8197702B; Tue, 15 Jul 2025 19:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606295; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rijoJi/Ykv0GahCauUjFN1CRQ9kyD3BH1g9TE573ntg=; b=VCIzxXPhHkxStvlTjNVo6lsAecPWFInavJl32DKolIYFIi8te1RSHqRpRSK2ELI7JDJlzY tyzmSTqJxYuaQwVkQOk9hWg4TRjvTsFsMDfTzXEuosQWwb5Q7JAdVFW9ybfX0X+xOUInrH xLRrEWsygYlWsQ5IhGL+QsX72qQvs/s= X-MC-Unique: Z7B_Cy8BMuq2JVut03FOuw-1 X-Mimecast-MFC-AGG-ID: Z7B_Cy8BMuq2JVut03FOuw_1752606293 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 36/57] qemu-img: factor out parse_output_format() and use it in the code Date: Tue, 15 Jul 2025 21:03:09 +0200 Message-ID: <20250715190330.378764-37-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608013338116600 From: Michael Tokarev Use common code and simplify error message Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-7-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- qemu-img.c | 63 +++++++++----------------------- tests/qemu-iotests/178 | 2 +- tests/qemu-iotests/178.out.qcow2 | 3 +- tests/qemu-iotests/178.out.raw | 3 +- tests/qemu-iotests/common.filter | 6 +++ 5 files changed, 29 insertions(+), 48 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 6569efd310..b60b4d38df 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -158,6 +158,17 @@ void cmd_help(const img_cmd_t *ccmd, exit(EXIT_SUCCESS); } =20 +static OutputFormat parse_output_format(const char *argv0, const char *arg) +{ + if (!strcmp(arg, "json")) { + return OFORMAT_JSON; + } else if (!strcmp(arg, "human")) { + return OFORMAT_HUMAN; + } else { + error_exit(argv0, "--output expects 'human' or 'json', not '%s'", = arg); + } +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -775,7 +786,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) { int c, ret; OutputFormat output_format =3D OFORMAT_HUMAN; - const char *filename, *fmt, *output, *cache; + const char *filename, *fmt, *cache; BlockBackend *blk; BlockDriverState *bs; int fix =3D 0; @@ -787,7 +798,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) bool force_share =3D false; =20 fmt =3D NULL; - output =3D NULL; cache =3D BDRV_DEFAULT_CACHE; =20 for(;;) { @@ -833,7 +843,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) } break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case 'T': cache =3D optarg; @@ -857,15 +867,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, = char **argv) } filename =3D argv[optind++]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - ret =3D bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -3059,13 +3060,12 @@ static int img_info(const img_cmd_t *ccmd, int argc= , char **argv) int c; OutputFormat output_format =3D OFORMAT_HUMAN; bool chain =3D false; - const char *filename, *fmt, *output; + const char *filename, *fmt; BlockGraphInfoList *list; bool image_opts =3D false; bool force_share =3D false; =20 fmt =3D NULL; - output =3D NULL; for(;;) { int option_index =3D 0; static const struct option long_options[] =3D { @@ -3100,7 +3100,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, = char **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case OPTION_BACKING_CHAIN: chain =3D true; @@ -3118,15 +3118,6 @@ static int img_info(const img_cmd_t *ccmd, int argc,= char **argv) } filename =3D argv[optind++]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - list =3D collect_image_info_list(image_opts, filename, fmt, chain, force_share); if (!list) { @@ -3285,7 +3276,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) OutputFormat output_format =3D OFORMAT_HUMAN; BlockBackend *blk; BlockDriverState *bs; - const char *filename, *fmt, *output; + const char *filename, *fmt; int64_t length; MapEntry curr =3D { .length =3D 0 }, next; int ret =3D 0; @@ -3295,7 +3286,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) int64_t max_length =3D -1; =20 fmt =3D NULL; - output =3D NULL; for (;;) { int option_index =3D 0; static const struct option long_options[] =3D { @@ -3331,7 +3321,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case 's': start_offset =3D cvtnum("start offset", optarg); @@ -3358,15 +3348,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, = char **argv) } filename =3D argv[optind]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - blk =3D img_open(image_opts, filename, fmt, 0, false, false, force_sha= re); if (!blk) { return 1; @@ -5473,15 +5454,7 @@ static int img_measure(const img_cmd_t *ccmd, int ar= gc, char **argv) image_opts =3D true; break; case OPTION_OUTPUT: - if (!strcmp(optarg, "json")) { - output_format =3D OFORMAT_JSON; - } else if (!strcmp(optarg, "human")) { - output_format =3D OFORMAT_HUMAN; - } else { - error_report("--output must be used with human or json " - "as argument."); - goto out; - } + output_format =3D parse_output_format(argv[0], optarg); break; case OPTION_SIZE: img_size =3D cvtnum("image size", optarg); diff --git a/tests/qemu-iotests/178 b/tests/qemu-iotests/178 index 8df241ead8..463c59a77f 100755 --- a/tests/qemu-iotests/178 +++ b/tests/qemu-iotests/178 @@ -58,7 +58,7 @@ $QEMU_IMG measure -f qcow2 # missing filename $QEMU_IMG measure -l snap1 # missing filename $QEMU_IMG measure -o , # invalid option list $QEMU_IMG measure -l snapshot.foo=3Dbar # invalid snapshot option -$QEMU_IMG measure --output foo # invalid output format +$QEMU_IMG measure --output foo 2>&1 | _filter_qemu_img # invalid output fo= rmat $QEMU_IMG measure --size -1 # invalid image size $QEMU_IMG measure -O foo "$TEST_IMG" # unknown image file format =20 diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.= qcow2 index fe193fd5f4..61506b519f 100644 --- a/tests/qemu-iotests/178.out.qcow2 +++ b/tests/qemu-iotests/178.out.qcow2 @@ -12,7 +12,8 @@ qemu-img: --image-opts, -f, and -l require a filename arg= ument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo=3Dbar' -qemu-img: --output must be used with human or json as argument. +qemu-img: --output expects 'human' or 'json', not 'foo' +Try 'qemu-img measure --help' for more information qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img: Unknown file format 'foo' =20 diff --git a/tests/qemu-iotests/178.out.raw b/tests/qemu-iotests/178.out.raw index 445e460fad..6d994a433a 100644 --- a/tests/qemu-iotests/178.out.raw +++ b/tests/qemu-iotests/178.out.raw @@ -12,7 +12,8 @@ qemu-img: --image-opts, -f, and -l require a filename arg= ument. qemu-img: Invalid option list: , qemu-img: Invalid parameter 'snapshot.foo' qemu-img: Failed in parsing snapshot param 'snapshot.foo=3Dbar' -qemu-img: --output must be used with human or json as argument. +qemu-img: --output expects 'human' or 'json', not 'foo' +Try 'qemu-img measure --help' for more information qemu-img: Invalid image size specified. Must be between 0 and 922337203685= 4775807. qemu-img: Unknown file format 'foo' =20 diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index fc3c64bcb8..67f819d866 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -86,6 +86,12 @@ _filter_qemu() -e $'s#\r##' # QEMU monitor uses \r\n line endings } =20 +# replace occurrences of QEMU_IMG_PROG with "qemu-img" +_filter_qemu_img() +{ + sed -e "s#$QEMU_IMG_PROG#qemu-img#g" +} + # replace problematic QMP output like timestamps _filter_qmp() { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608994; cv=none; d=zohomail.com; s=zohoarc; b=GbiEW1dWIzzu4/V91TeiyQoHGLpgO/YxCfaAGb3sgyRysvEuxZHZFmr8izfGCzfAFwA4cGxg+ZV9HrDT6DFlCie67RhiKJkHu/F3qpQYTv9srvPwQPbVBqsY+kxW29OXkzS+5WIPF8dOyKNPzqpNz+/WnKt2YjzAnVZ7wvSsnQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608994; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QtUCpwx+B+m845VIJ5WbVmDfe+AsAs8PMzBj9Z+WtJg=; b=gXMu6baUGcZiE2BPa4b7nxGyEpRdUP785LG85hoRBMCe53cm3EXqcOkwMxVgQBHH8+BBnhTD7p1A6uevne+FjjtSiAby0Ahew65JZk/1v7Q5gJCvfRPNzhdaUgwEtJRnh0AcnlXPi9pDIf7a/YM0c3bLpgfDfkxpHVpdAmzRkZE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608994388185.73849579036312; Tue, 15 Jul 2025 12:49:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublZJ-0005eR-BZ; Tue, 15 Jul 2025 15:44:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxa-0004PF-RK for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxX-0001Ty-HK for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:01 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-673-jwR3GiocOkGGxMcqJjP0FA-1; Tue, 15 Jul 2025 15:04:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 75C4A19560B3; Tue, 15 Jul 2025 19:04:55 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9D4F197702B; Tue, 15 Jul 2025 19:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606298; 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=QtUCpwx+B+m845VIJ5WbVmDfe+AsAs8PMzBj9Z+WtJg=; b=WKVs7iQMXhRJtf1DVcn8DbdWV7T1ICTXzHO9g+RkPdsYl3imTD+fMUMTq5Egd9mRW6j8tl q2mxd6G5suZsWsqN6G7zPxPyYS9lcxbwmuCOEqjgmRnsYGqfks1ZfVaFgYwchAn9r/t0zU gtcnCs/Djzcmtptdhh1x8gd4+/barSU= X-MC-Unique: jwR3GiocOkGGxMcqJjP0FA-1 X-Mimecast-MFC-AGG-ID: jwR3GiocOkGGxMcqJjP0FA_1752606295 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 37/57] qemu-img: check: refresh options/--help Date: Tue, 15 Jul 2025 21:03:10 +0200 Message-ID: <20250715190330.378764-38-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608995796116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-8-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 60 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b60b4d38df..d310f0de0d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -805,31 +805,57 @@ static int img_check(const img_cmd_t *ccmd, int argc,= char **argv) static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 'T'}, {"repair", required_argument, 0, 'r'}, + {"force-share", no_argument, 0, 'U'}, {"output", required_argument, 0, OPTION_OUTPUT}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, - {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:r:T:qU", + c =3D getopt_long(argc, argv, "hf:T:r:Uq", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, "[-f FMT | --image-opts] [-T CACHE_MODE] [-r le= aks|all]\n" +" [-U] [--output human|json] [-q] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specifies the format of the image explicitly (default: probing is us= ed)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -T, --cache CACHE_MODE\n" /* why not -t ? */ +" cache mode (default: " BDRV_DEFAULT_CACHE ")\n" +" -r, --repair leaks|all\n" +" repair errors of the given category in the image (image will be\n" +" opened in read-write mode, incompatible with -U|--force-share)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --output human|json\n" +" output format (default: human)\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or an option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; case 'f': fmt =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case 'T': + cache =3D optarg; + break; case 'r': flags |=3D BDRV_O_RDWR; =20 @@ -842,24 +868,20 @@ static int img_check(const img_cmd_t *ccmd, int argc,= char **argv) "(expecting 'leaks' or 'all'): %s", optarg); } break; + case 'U': + force_share =3D true; + break; case OPTION_OUTPUT: output_format =3D parse_output_format(argv[0], optarg); break; - case 'T': - cache =3D optarg; - break; case 'q': quiet =3D true; break; - case 'U': - force_share =3D true; - break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608039; cv=none; d=zohomail.com; s=zohoarc; b=OoU31JzlDhmncmUaXQjLUw3GDsM1s4BbKSTR3r704gEJZKaUTpeOk21SJWqeiVYFPysfJz8lGnuXAs1KoOuAIAiSQihPEgUJPjyNQmKMQGnKGtLCudaZf6vh+v/outu3mQ+LmI/5Kl4oBh8uZVDhFZRC8s7TrtIy+J5jZN+ynm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608039; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Ubs/fiMuaRgzsxNWnQ5UOjdp3l5nE50e8I9uhc1vPHg=; b=R3jC45bEucGai8HTU6j8zDyO5b5g+hctUfllkaMc/gwWyu6qI1m+OKMCqOn9V6mIN89NC1O5hbprQL9nO9MpusJQQL8nK7MOTicIYimpgjg/IlaLipZ2X4lbUuD0hMMDZyKlQ6LbnfKpSLO/xz8iGhNBYEJXW7CGZAh7WYAR2Ww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608039061402.5484716492771; Tue, 15 Jul 2025 12:33:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublPF-00077c-PN; Tue, 15 Jul 2025 15:33:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxe-0004Rz-Ek for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxb-0001Un-6z for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:05 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-0GoxDvAoMKuvtXgrgy8Rpw-1; Tue, 15 Jul 2025 15:04:58 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9664E180029E; Tue, 15 Jul 2025 19:04:57 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EB7E8197702B; Tue, 15 Jul 2025 19:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ubs/fiMuaRgzsxNWnQ5UOjdp3l5nE50e8I9uhc1vPHg=; b=M2vaHEsPsEOncxWRmbw7dB1wh3goKvzT2eNfpIVGaznk2RvAInduU5RCGTX/vISHn6jnmO fKtHo1U9ZFw/jtWV5fYhiSDD7RLIiwtiZ8BI3WJy0BwhtTs/pS8KmAu6xLJ9QbHQyj2MoH FiKgQkhBmxs4tl0jg6svXIyYSMZjSi8= X-MC-Unique: 0GoxDvAoMKuvtXgrgy8Rpw-1 X-Mimecast-MFC-AGG-ID: 0GoxDvAoMKuvtXgrgy8Rpw_1752606297 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 38/57] qemu-img: simplify --repair error message Date: Tue, 15 Jul 2025 21:03:11 +0200 Message-ID: <20250715190330.378764-39-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608039362116600 From: Michael Tokarev Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Message-ID: <20250531171609.197078-9-mjt@tls.msk.ru> [kwolf: Added missing comma in help text] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d310f0de0d..ec6802b03b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -864,8 +864,9 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) } else if (!strcmp(optarg, "all")) { fix =3D BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit(argv[0], "Unknown option value for -r " - "(expecting 'leaks' or 'all'): %s", optarg); + error_exit(argv[0], + "--repair (-r) expects 'leaks' or 'all', not '%= s'", + optarg); } break; case 'U': --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608055; cv=none; d=zohomail.com; s=zohoarc; b=fD++1SAgQvmA8T9a2KIYuJf5XZE202mRxdCrsYoaZikF4IHMWaCI9tNaY7kfVqq0bFCMH8e0qXXT5IiCGtDUQWutmAY1uBYMDLSxGokiUKoP3bcQiVNtxDU6BqYvDAUKAS8mAtvrGtOGFqGimcx2R4+70vYU3KCdhG7s7smYvtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608055; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bM/ndj+zs+ovWmu1zKPcZ9oQv4zNM2g/RteAdcjIdXM=; b=nmhN/oDV1nAyYA4WNMolk0VTrNjm3bZSYbFLDFUwkTw+IppQdAXq6lqRCwr2e9Td5WjhNxk/1jljk8nJ04+9+P25TDl/rlpv26lmFbhrj8BQBjji4C3UButcebU36n+83AN8VJxM57G8soEmZKhCtj83RxxoC+5ZSmbcyxezCEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608055724348.68944611323377; Tue, 15 Jul 2025 12:34:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublPB-0006jz-Jo; Tue, 15 Jul 2025 15:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxd-0004R8-N6 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxa-0001Uj-Sd for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:04 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683--FvOFCagNkuz38nNL-dYEQ-1; Tue, 15 Jul 2025 15:05:00 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC6AF18001D6; Tue, 15 Jul 2025 19:04:59 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 18ED0197702B; Tue, 15 Jul 2025 19:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606302; 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=bM/ndj+zs+ovWmu1zKPcZ9oQv4zNM2g/RteAdcjIdXM=; b=GcZjmGDUlJ1hjIT1pGE4QuEu0b+pta4tLydNyL0Biv7LCRcl42EEiihkCbOtvdxubWPW8r ibGAQPgWGuwFoF8T14aEiBSk0/TbnsKjL1i4OJbxK43a/cNM/Irt3ft45BSs7Sm/81n7qB 7Vd6I+SkDgoVprxkQ1a1ywbwwRrqP3s= X-MC-Unique: -FvOFCagNkuz38nNL-dYEQ-1 X-Mimecast-MFC-AGG-ID: -FvOFCagNkuz38nNL-dYEQ_1752606299 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 39/57] qemu-img: commit: refresh options/--help Date: Tue, 15 Jul 2025 21:03:12 +0200 Message-ID: <20250715190330.378764-40-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608057718116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-10-mjt@tls.msk.ru> [kwolf: Fixed up qemu-iotests] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 68 +++++++++++++++++++++++++++----------- tests/qemu-iotests/153 | 2 +- tests/qemu-iotests/153.out | 12 +++---- 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ec6802b03b..9d2eba3b36 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1047,38 +1047,73 @@ static int img_commit(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 't'}, + {"drop", no_argument, 0, 'd'}, + {"base", required_argument, 0, 'b'}, + {"rate-limit", required_argument, 0, 'r'}, + {"progress", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:ht:b:dpqr:", + c =3D getopt_long(argc, argv, "hf:t:db:r:pq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE_MODE] [-b BA= SE_IMG]\n" +" [-d] [-r RATE] [-q] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specify FILE image format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -t, --cache CACHE_MODE image cache mode (default: " BDRV_DEFAULT_CACHE = ")\n" +" -d, --drop\n" +" skip emptying FILE on completion\n" +" -b, --base BASE_IMG\n" +" image in the backing chain to commit change to\n" +" (default: immediate backing file; implies --drop)\n" +" -r, --rate-limit RATE\n" +" I/O rate limit, in bytes per second\n" +" -p, --progress\n" +" display progress information\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or an option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; case 'f': fmt =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; case 't': cache =3D optarg; break; + case 'd': + drop =3D true; + break; case 'b': base =3D optarg; /* -b implies -d */ drop =3D true; break; - case 'd': - drop =3D true; + case 'r': + rate_limit =3D cvtnum("rate limit", optarg); + if (rate_limit < 0) { + return 1; + } break; case 'p': progress =3D true; @@ -1086,18 +1121,11 @@ static int img_commit(const img_cmd_t *ccmd, int ar= gc, char **argv) case 'q': quiet =3D true; break; - case 'r': - rate_limit =3D cvtnum("rate limit", optarg); - if (rate_limit < 0) { - return 1; - } - break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } =20 diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153 index 9bc3be8f75..1e02f6a6e3 100755 --- a/tests/qemu-iotests/153 +++ b/tests/qemu-iotests/153 @@ -63,7 +63,7 @@ _supported_proto file _run_cmd() { echo - (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir + (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir | _filter_qemu_img } =20 _do_run_qemu() diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index ff8e55864a..a8ffd01266 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -124,8 +124,8 @@ qemu-img: unrecognized option '-U' Try 'qemu-img --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img commit: invalid option -- 'U' +Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M qemu-img: unrecognized option '-U' @@ -248,8 +248,8 @@ qemu-img: unrecognized option '-U' Try 'qemu-img --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img commit: invalid option -- 'U' +Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M qemu-img: unrecognized option '-U' @@ -353,8 +353,8 @@ qemu-img: unrecognized option '-U' Try 'qemu-img --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img commit: invalid option -- 'U' +Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M qemu-img: unrecognized option '-U' --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608732; cv=none; d=zohomail.com; s=zohoarc; b=beY0ZAC3OAzL6NJbg64taKXySpu5OS2GUbfaPflGCB2QcQFbXqgRd09sQkziF1JKp39fpZIlsiRsI5zpsEYvEpYzS5fBMq70C2E9V5oY81HsvB2fydl009+CuSGXVf1PzLPm9WCciZ1e0Lx/2Cyg3tuKb6CfXitD9Nlvuy7h/ds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608732; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=834C0oDXKZn6AI4lUTo5/qab+PV2c+RGK0C5HaB+c0Q=; b=EbO6LGVMspt9ZSJ9/BNHeJjF044AUoqwCEFS7iZ9DH4EUGvIylCcJ4hzMA0QVVcGUD1wVikbzh89Z/BIHeTT3VC1Lro9wZh0uqzg9zLQ920KALeSYO01ggp6FR1g1vFtMeadF+l+1XtJPwUog+3cQtHhWiO9ln4CTu2FBVpAXVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608732935340.70207702992604; Tue, 15 Jul 2025 12:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublZS-0006VM-SD; Tue, 15 Jul 2025 15:44:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxi-0004TN-9x for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxf-0001gA-SH for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:09 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-6mSjq-sgMuetMvgw-8JgFw-1; Tue, 15 Jul 2025 15:05:02 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0855A195608E; Tue, 15 Jul 2025 19:05:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 19C00197702B; Tue, 15 Jul 2025 19:04:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606306; 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=834C0oDXKZn6AI4lUTo5/qab+PV2c+RGK0C5HaB+c0Q=; b=cWoSrSXuKEbwD3pzI4UYFkfSwKMalmn86Mh93ikAbEROzxwIFDd2HO/66sCJYb4kDk3KCa ZLW4jCZeRDcPBSVErTmLOq5RT5GufEE8K7f/pLXqW6tk4R0VKRQ+Pg7DgoXN50jOK/eVuH nQi3/W5XzcsUGXRyHvoHlF8wZ9BFBzU= X-MC-Unique: 6mSjq-sgMuetMvgw-8JgFw-1 X-Mimecast-MFC-AGG-ID: 6mSjq-sgMuetMvgw-8JgFw_1752606302 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 40/57] qemu-img: compare: use helper function for --object Date: Tue, 15 Jul 2025 21:03:13 +0200 Message-ID: <20250715190330.378764-41-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608734530116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Use the same function to parse --object as used by all other qemu-img subcommands. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-11-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 9d2eba3b36..a7a07ed4bc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1529,20 +1529,8 @@ static int img_compare(const img_cmd_t *ccmd, int ar= gc, char **argv) force_share =3D true; break; case OPTION_OBJECT: - { - Error *local_err =3D NULL; - - if (!user_creatable_add_from_str(optarg, &local_err)) { - if (local_err) { - error_report_err(local_err); - exit(2); - } else { - /* Help was printed */ - exit(EXIT_SUCCESS); - } - } - break; - } + user_creatable_process_cmdline(optarg); + break; case OPTION_IMAGE_OPTS: image_opts =3D true; break; --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608073; cv=none; d=zohomail.com; s=zohoarc; b=SGKatruAw7RoV1tU2yEKRLppZ3/OH2iH2eKYZm/hiWiCP1hTmjnfWt32O9HhkxnRk0QzF+BjcB+WFNxvYhASII2IBR6hPQuoxJzx9CAylwwvsAQ5GprmKxaIbS/0fOXeePxEAdk3a6mQbWmYAOOCcnFojyxzhEvTWFxxi3k0oz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608073; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=taA1HNznqd+8+gUd6weUC37cDbdr9lH7xvfJoqHRmag=; b=j7y9C4EI/biR2f5plSiuut9VBcbrv1RG8yLbO2wpi0t7onRdsHsaTwbnq0teDgQNkEGKeO/jXR2APSVMPtMXOBybXQFzBZQAB84YsJEyvcQx8viLKcc9921lYfxRKIFhbMJRWCECdHd5QtaYVmsesDOJksP9qO5d2h14D/SqiBU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608073961240.85837439201703; Tue, 15 Jul 2025 12:34:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublPz-0000mg-ML; Tue, 15 Jul 2025 15:34:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxk-0004Tq-DL for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxi-0001h3-2O for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:11 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-JHv3wn5sOyC5UBGW2mQIvQ-1; Tue, 15 Jul 2025 15:05:04 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E03E5195608C; Tue, 15 Jul 2025 19:05:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 604C81977030; Tue, 15 Jul 2025 19:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606308; 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=taA1HNznqd+8+gUd6weUC37cDbdr9lH7xvfJoqHRmag=; b=CnnN1M3vlLQd1IvvcAmaL1ja4phQA2J0PTxOB0hWfkZLaj92foBMMLOSx8JhdxnGMib1/C uK+V52ETeejmWqGPSTwMWUA7KeAnhsCeO1Dfumc0p7MkXfsui9x6H5SXpZFmxqO3BfLjua hGNzxwJtg+8FuXpuWLWd+7l9AAiGoCk= X-MC-Unique: JHv3wn5sOyC5UBGW2mQIvQ-1 X-Mimecast-MFC-AGG-ID: JHv3wn5sOyC5UBGW2mQIvQ_1752606304 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 41/57] qemu-img: compare: refresh options/--help Date: Tue, 15 Jul 2025 21:03:14 +0200 Message-ID: <20250715190330.378764-42-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608075829116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add long options, add help, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-12-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 64 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index a7a07ed4bc..5697e45ae6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1487,25 +1487,51 @@ static int img_compare(const img_cmd_t *ccmd, int a= rgc, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"a-format", required_argument, 0, 'f'}, + {"b-format", required_argument, 0, 'F'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"strict", no_argument, 0, 's'}, + {"cache", required_argument, 0, 'T'}, {"force-share", no_argument, 0, 'U'}, + {"progress", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:F:T:pqsU", + c =3D getopt_long(argc, argv, "hf:F:sT:Upq", long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[[-f FMT] [-F FMT] | --image-opts] [-s] [-T CACHE]\n" +" [-U] [-p] [-q] [--object OBJDEF] FILE1 FILE2\n" +, +" -f, --a-format FMT\n" +" specify FILE1 image format explicitly (default: probing is used)\n" +" -F, --b-format FMT\n" +" specify FILE2 image format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE1 and FILE2 as option strings (key=3Dvalue,..), not file n= ames\n" +" (incompatible with -f|--a-format and -F|--b-format)\n" +" -s, --strict\n" +" strict mode, also check if sizes are equal\n" +" -T, --cache CACHE_MODE\n" +" images caching mode (default: " BDRV_DEFAULT_CACHE ")\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" -p, --progress\n" +" display progress information\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE1, FILE2\n" +" names of the image files, or option strings (key=3Dvalue,..)\n" +" with --image-opts, to compare\n" +); break; case 'f': fmt1 =3D optarg; @@ -1513,27 +1539,29 @@ static int img_compare(const img_cmd_t *ccmd, int a= rgc, char **argv) case 'F': fmt2 =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case 's': + strict =3D true; + break; case 'T': cache =3D optarg; break; + case 'U': + force_share =3D true; + break; case 'p': progress =3D true; break; case 'q': quiet =3D true; break; - case 's': - strict =3D true; - break; - case 'U': - force_share =3D true; - break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608481; cv=none; d=zohomail.com; s=zohoarc; b=MJDpoCff04jayHUaDeeWg+cxAf5x/q+6aV1Vyjjm+y4HTxZor+jbUfe2pzeB8oaGKEunB94Sq8sPiMFlA1G0SwT3wBliFmE11FDh5J3+P9wkXicyJU1Os9XfjpddrBmLRe2HDDui3ARfpFpfVQxDO8w93JK5GIOpifkz/yGv83I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608481; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lWiLzzXvPELupku94HukWcryHkJIvOghKEwZoyGl1aA=; b=A2EDQcUKehmfcGQ+LzQqMvSrVjnB7y8haisyhbQ3GhnOs/tfHxI3PgTRc1BjVFFM0OCdtEmwEs4hNgx4Cm+Uaoe08E/za/3hrbFFMu9Ur5gT6TWUNXqZcKworYzZjaYHAET68E6AGac+zXVZR+96QrEEh2sfdPq1yHdaSOFeufg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17526084817291015.7737031966966; Tue, 15 Jul 2025 12:41:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublUq-00036W-Kl; Tue, 15 Jul 2025 15:39:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxk-0004Tr-DC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxi-0001h0-1g for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:12 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-FiRcheNNOZqGcuShHH6Hnw-1; Tue, 15 Jul 2025 15:05:06 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E20981800368; Tue, 15 Jul 2025 19:05:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 624F3197702B; Tue, 15 Jul 2025 19:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606308; 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=lWiLzzXvPELupku94HukWcryHkJIvOghKEwZoyGl1aA=; b=BbCZi7WCjIi3li3C4pwRN74MRg06OktOM3J4JHNMBRoyxut2zWnlf+epXlGDk4Vg+rUaQd /X3Q2+JoRzdNQHRcM+N8dZBj4xSvMYppYawuHTuLStRK/I/S4dom8qXD3f3Ad5TlgjgGXh +uW8tW13jdaEptTyODf88vwwCGyYl9E= X-MC-Unique: FiRcheNNOZqGcuShHH6Hnw-1 X-Mimecast-MFC-AGG-ID: FiRcheNNOZqGcuShHH6Hnw_1752606306 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 42/57] qemu-img: convert: refresh options/--help (short option change) Date: Tue, 15 Jul 2025 21:03:15 +0200 Message-ID: <20250715190330.378764-43-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608483962116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output. Reorder options for consistency. Use -b for --backing, and recognize -B for backwards compatibility. Unfortunately we can't use -B to specify backing format. Signed-off-by: Michael Tokarev Message-ID: <20250715140702.131321-1-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 230 +++++++++++++++++++++++++++------------- 2 files changed, 159 insertions(+), 73 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index a21e439082..23715811e2 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -419,7 +419,7 @@ Command description: 4 Error on reading data =20 -.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps [--skip-broken-bitmaps]] [-U] [-C] [-c] [= -p] [-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-B BACKIN= G_FILE [-F BACKING_FMT]] [-o OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] = [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_= FILENAME +.. option:: convert [--object OBJECTDEF] [--image-opts] [--target-image-op= ts] [--target-is-zero] [--bitmaps [--skip-broken-bitmaps]] [-U] [-C] [-c] [= -p] [-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT] [-b BACKIN= G_FILE [-F BACKING_FMT]] [-o OPTIONS] [-l SNAPSHOT_PARAM] [-S SPARSE_SIZE] = [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W] FILENAME [FILENAME2 [...]] OUTPUT_= FILENAME =20 Convert the disk image *FILENAME* or a snapshot *SNAPSHOT_PARAM* to disk image *OUTPUT_FILENAME* using format *OUTPUT_FMT*. It can diff --git a/qemu-img.c b/qemu-img.c index 5697e45ae6..950f319a97 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2390,53 +2390,122 @@ static int img_convert(const img_cmd_t *ccmd, int = argc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"source-format", required_argument, 0, 'f'}, + /* + * XXX: historic --image-opts acts on source file only, + * it seems better to have it affect both source and target, + * and have separate --source-image-opts for source, + * but this might break existing setups. + */ {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"force-share", no_argument, 0, 'U'}, - {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, - {"salvage", no_argument, 0, OPTION_SALVAGE}, - {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, + {"source-cache", required_argument, 0, 'T'}, + {"snapshot", required_argument, 0, 'l'}, {"bitmaps", no_argument, 0, OPTION_BITMAPS}, {"skip-broken-bitmaps", no_argument, 0, OPTION_SKIP_BROKEN}, + {"salvage", no_argument, 0, OPTION_SALVAGE}, + {"target-format", required_argument, 0, 'O'}, + {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, + {"target-format-options", required_argument, 0, 'o'}, + {"target-cache", required_argument, 0, 't'}, + {"backing", required_argument, 0, 'b'}, + {"backing-format", required_argument, 0, 'F'}, + {"sparse-size", required_argument, 0, 'S'}, + {"no-create", no_argument, 0, 'n'}, + {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, + {"force-share", no_argument, 0, 'U'}, + {"rate-limit", required_argument, 0, 'r'}, + {"parallel", required_argument, 0, 'm'}, + {"oob-writes", no_argument, 0, 'W'}, + {"copy-range-offloading", no_argument, 0, 'C'}, + {"progress", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:", + c =3D getopt_long(argc, argv, "hf:O:b:B:CcF:o:l:S:pt:T:nm:WUr:q", long_options, NULL); if (c =3D=3D -1) { break; } - switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; + switch (c) { case 'h': - help(); + cmd_help(ccmd, "[-f SRC_FMT | --image-opts] [-T SRC_CACHE]\n" +" [-l SNAPSHOT] [--bitmaps [--skip-broken-bitmaps]] [--salvage]\n" +" [-O TGT_FMT | --target-image-opts] [-o TGT_FMT_OPTS] [-t TGT_CACH= E]\n" +" [-b BACKING_FILE [-F BACKING_FMT]] [-S SPARSE_SIZE]\n" +" [-n] [--target-is-zero] [-c]\n" +" [-U] [-r RATE] [-m NUM_PARALLEL] [-W] [-C] [-p] [-q] [--object OB= JDEF]\n" +" SRC_FILE [SRC_FILE2...] TGT_FILE\n" +, +" -f, --source-format SRC_FMT\n" +" specify format of all SRC_FILEs explicitly (default: probing is used= )\n" +" --image-opts\n" +" treat each SRC_FILE as an option string (key=3Dvalue,...), not a fil= e name\n" +" (incompatible with -f|--source-format)\n" +" -T, --source-cache SRC_CACHE\n" +" source image(s) cache mode (" BDRV_DEFAULT_CACHE ")\n" +" -l, --snapshot SNAPSHOT\n" +" specify source snapshot\n" +" --bitmaps\n" +" also copy any persistent bitmaps present in source\n" +" --skip-broken-bitmaps\n" +" skip (do not error out) any broken bitmaps\n" +" --salvage\n" +" ignore errors on input (convert unreadable areas to zeros)\n" +" -O, --target-format TGT_FMT\n" +" specify TGT_FILE image format (default: raw)\n" +" --target-image-opts\n" +" treat TGT_FILE as an option string (key=3Dvalue,...), not a file nam= e\n" +" (incompatible with -O|--target-format)\n" +" -o, --target-format-options TGT_FMT_OPTS\n" +" TGT_FMT-specific options\n" +" -t, --target-cache TGT_CACHE\n" +" cache mode when opening output image (default: unsafe)\n" +" -b, --backing BACKING_FILE (was -B in <=3D 10.0)\n" +" create target image to be a CoW on top of BACKING_FILE\n" +" -F, --backing-format BACKING_FMT\n" /* -B used for -b in <=3D10.0 */ +" specify BACKING_FILE image format explicitly (default: probing is us= ed)\n" +" -S, --sparse-size SPARSE_SIZE[bkKMGTPE]\n" +" specify number of consecutive zero bytes to treat as a gap on output= \n" +" (rounded down to nearest 512 bytes), with optional multiplier suffix= \n" +" -n, --no-create\n" +" omit target volume creation (e.g. on rbd)\n" +" --target-is-zero\n" +" indicates that the target volume is pre-zeroed\n" +" -c, --compress\n" +" create compressed output image (qcow and qcow2 formats only)\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" -r, --rate-limit RATE\n" +" I/O rate limit, in bytes per second\n" +" -m, --parallel NUM_PARALLEL\n" +" specify parallelism (default: 8)\n" +" -C, --copy-range-offloading\n" +" try to use copy offloading\n" +" -W, --oob-writes\n" +" enable out-of-order writes to improve performance\n" +" -p, --progress\n" +" display progress information\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" SRC_FILE...\n" +" one or more source image file names,\n" +" or option strings (key=3Dvalue,..) with --source-image-opts\n" +" TGT_FILE\n" +" target (output) image file name,\n" +" or option string (key=3Dvalue,..) with --target-image-opts\n" +); break; case 'f': fmt =3D optarg; break; - case 'O': - out_fmt =3D optarg; - break; - case 'B': - out_baseimg =3D optarg; - break; - case 'C': - s.copy_range =3D true; - break; - case 'c': - s.compressed =3D true; - break; - case 'F': - backing_fmt =3D optarg; + case OPTION_IMAGE_OPTS: + image_opts =3D true; break; - case 'o': - if (accumulate_options(&options, optarg) < 0) { - goto fail_getopt; - } + case 'T': + src_cache =3D optarg; break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { @@ -2451,6 +2520,36 @@ static int img_convert(const img_cmd_t *ccmd, int ar= gc, char **argv) snapshot_name =3D optarg; } break; + case OPTION_BITMAPS: + bitmaps =3D true; + break; + case OPTION_SKIP_BROKEN: + skip_broken =3D true; + break; + case OPTION_SALVAGE: + s.salvage =3D true; + break; + case 'O': + out_fmt =3D optarg; + break; + case OPTION_TARGET_IMAGE_OPTS: + tgt_image_opts =3D true; + break; + case 'o': + if (accumulate_options(&options, optarg) < 0) { + goto fail_getopt; + } + break; + case 't': + cache =3D optarg; + break; + case 'B': /* <=3D10.0 */ + case 'b': + out_baseimg =3D optarg; + break; + case 'F': /* can't use -B as it used as -b in <=3D10.0 */ + backing_fmt =3D optarg; + break; case 'S': { int64_t sval; @@ -2471,20 +2570,28 @@ static int img_convert(const img_cmd_t *ccmd, int a= rgc, char **argv) explict_min_sparse =3D true; break; } - case 'p': - progress =3D true; + case 'n': + skip_create =3D true; break; - case 't': - cache =3D optarg; + case OPTION_TARGET_IS_ZERO: + /* + * The user asserting that the target is blank has the + * same effect as the target driver supporting zero + * initialisation. + */ + s.has_zero_init =3D true; break; - case 'T': - src_cache =3D optarg; + case 'c': + s.compressed =3D true; break; - case 'q': - s.quiet =3D true; + case 'U': + force_share =3D true; break; - case 'n': - skip_create =3D true; + case 'r': + rate_limit =3D cvtnum("rate limit", optarg); + if (rate_limit < 0) { + goto fail_getopt; + } break; case 'm': if (qemu_strtol(optarg, NULL, 0, &s.num_coroutines) || @@ -2497,41 +2604,20 @@ static int img_convert(const img_cmd_t *ccmd, int a= rgc, char **argv) case 'W': s.wr_in_order =3D false; break; - case 'U': - force_share =3D true; + case 'C': + s.copy_range =3D true; break; - case 'r': - rate_limit =3D cvtnum("rate limit", optarg); - if (rate_limit < 0) { - goto fail_getopt; - } + case 'p': + progress =3D true; + break; + case 'q': + s.quiet =3D true; break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; - case OPTION_SALVAGE: - s.salvage =3D true; - break; - case OPTION_TARGET_IMAGE_OPTS: - tgt_image_opts =3D true; - break; - case OPTION_TARGET_IS_ZERO: - /* - * The user asserting that the target is blank has the - * same effect as the target driver supporting zero - * initialisation. - */ - s.has_zero_init =3D true; - break; - case OPTION_BITMAPS: - bitmaps =3D true; - break; - case OPTION_SKIP_BROKEN: - skip_broken =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608068; cv=none; d=zohomail.com; s=zohoarc; b=Ro3lQfj7vZV4yDWJUP3OQEkOw55gXQjiSGCro0GXZS9Nn6Q0caAN1xMd3dOqjZ2JP4BWygo2FMsOCsVYEQW1C18lQwxUYdAF07BvJdnmaaecT3eLxfBPmxclf5+udLo5/r3Pv6xMzHSvN9OrjnCYfVHPk7B+zlZ6MTBzyjmFcmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608068; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dm3I03o3ziU4+GurmjHfvlVgbFzvqDq0GAQA7zN0PPw=; b=ganZFl3y3tH7XPjtMJjc6yxMMLyuMOC/pEwt1ZxZUe6uSBs9ETudmrcASwB4hYNNjDlHLo4bMi+OdoaoiQJ6zcMmwkRQMQyfzAEJbNL5ClJ2Vv0mGeSXGFUxPkiedkm/8PXdpbf6jTEz0sQTUzeNs5eOiHmPWjs/YAinL10Tdk8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175260806812713.821799277222112; Tue, 15 Jul 2025 12:34:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublPP-00082r-OD; Tue, 15 Jul 2025 15:33:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxo-0004UE-68 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxl-0001hl-00 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:15 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678--klC0Qf9Mbeo-IIiWrwQow-1; Tue, 15 Jul 2025 15:05:08 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F0F28195608F; Tue, 15 Jul 2025 19:05:07 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 646DD197702B; Tue, 15 Jul 2025 19:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606312; 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=dm3I03o3ziU4+GurmjHfvlVgbFzvqDq0GAQA7zN0PPw=; b=N9ngwX9jVciCRfOeWzKAYIejwa1g9wC6c+A/XotyHvI1Ig+gQn9k30KvvA3WdnDwvy7kBH bjpjmkOuGZMZVFc+HiAYCYXMMbu0Ji+jHcsCUEwv8rfaI3jN4Wfmu48sXdXc0m/BxAAsCK bPN6ytYiluat+ZBWNP8n/U52bTscGUE= X-MC-Unique: -klC0Qf9Mbeo-IIiWrwQow-1 X-Mimecast-MFC-AGG-ID: -klC0Qf9Mbeo-IIiWrwQow_1752606308 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 43/57] qemu-img: info: refresh options/--help Date: Tue, 15 Jul 2025 21:03:16 +0200 Message-ID: <20250715190330.378764-44-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608070303116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output. Also add -b short option for --backing-chain, and remove now-unused OPTION_BACKING_CHAIN. Reorder options for consistency. While at it, remove unused option_index variable. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-14-mjt@tls.msk.ru> [kwolf: Fixed up help text formatting] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 950f319a97..530123bfdf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3220,50 +3220,63 @@ static int img_info(const img_cmd_t *ccmd, int argc= , char **argv) =20 fmt =3D NULL; for(;;) { - int option_index =3D 0; static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, - {"output", required_argument, 0, OPTION_OUTPUT}, - {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, - {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, {"force-share", no_argument, 0, 'U'}, + {"output", required_argument, 0, OPTION_OUTPUT}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hU", - long_options, &option_index); + c =3D getopt_long(argc, argv, "hf:U", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, "[-f FMT | --image-opts] [--backing-chain] [-U]= \n" +" [--output human|json] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specify FILE image format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" --backing-chain\n" +" display information about the backing chain for copy-on-write overla= ys\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --output human|json\n" +" specify output format (default: human)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; case 'f': fmt =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case OPTION_BACKING_CHAIN: + chain =3D true; + break; case 'U': force_share =3D true; break; case OPTION_OUTPUT: output_format =3D parse_output_format(argv[0], optarg); break; - case OPTION_BACKING_CHAIN: - chain =3D true; - break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608375; cv=none; d=zohomail.com; s=zohoarc; b=Vpqna3BS+uLmrh3X20LcZ4mD8MIMywFNLPXjQNVt5xQCdUMcLOIVc7l7PXsmBK/03jR+0Nr7W7yvVSOwTAzkoLwv4qA7zRB68LVaERkFaz6RLWnu1w7Qmvtk9N/9cUC6avMzSGSJsSBsazmhVp92O1ojMCkWHd/8xoIORDb3FuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608375; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PhLaAdsNrHeY9YCqj4vc9nJxGGtEE9fcIaoknxQSwGI=; b=b1JMzAoa0a15c3sfJX+DpqJWcQSi+KvPPSJNC/qwl/LbCJYKNJigvXbi08OXgpqOGoGcogpsv8LMzauKPX8JAsVbiQkVRs1Uw+sGw+/U9h2zzz23fZ8FiT5DpbgZXuhvRNCqLat8e0QOEhoyoOaDvF1qC+Tx8HkwI9jl6wUeTiw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608375750937.4948431273667; Tue, 15 Jul 2025 12:39:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublUv-0003bB-1K; Tue, 15 Jul 2025 15:39:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxp-0004Up-Qx for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxn-0001i0-1l for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:17 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-538-5chfcuU1NcyEo6uZm-_VRw-1; Tue, 15 Jul 2025 15:05:11 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5F786180024D; Tue, 15 Jul 2025 19:05:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 72655197702B; Tue, 15 Jul 2025 19:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606314; 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=PhLaAdsNrHeY9YCqj4vc9nJxGGtEE9fcIaoknxQSwGI=; b=OkvBcVLKQrzaxEYYG/KEZ4AU3WtRTmQgR/29R3c1rUfcbuf0zZLSJmCDFNFaCYMcR0NcvJ hR8IjzB4Y1JrufBZiDivtcvZXExlSmMyIv+AtRVCZCnWHO7+0WbQ7a79OPpGEaXPZ0o3oH c6JP8Mi1jMnP1mZ5rbH47GEAkjNP51M= X-MC-Unique: 5chfcuU1NcyEo6uZm-_VRw-1 X-Mimecast-MFC-AGG-ID: 5chfcuU1NcyEo6uZm-_VRw_1752606310 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 44/57] qemu-img: map: refresh options/--help Date: Tue, 15 Jul 2025 21:03:17 +0200 Message-ID: <20250715190330.378764-45-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608376688116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. While at it, remove unused option_index variable. Signed-off-by: Michael Tokarev Message-ID: <20250715140903.131529-1-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 59 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 530123bfdf..a02ccad943 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3453,41 +3453,53 @@ static int img_map(const img_cmd_t *ccmd, int argc,= char **argv) =20 fmt =3D NULL; for (;;) { - int option_index =3D 0; static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, - {"output", required_argument, 0, OPTION_OUTPUT}, - {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"force-share", no_argument, 0, 'U'}, {"start-offset", required_argument, 0, 's'}, {"max-length", required_argument, 0, 'l'}, + {"force-share", no_argument, 0, 'U'}, + {"output", required_argument, 0, OPTION_OUTPUT}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:s:l:hU", - long_options, &option_index); + c =3D getopt_long(argc, argv, "hf:s:l:U", + long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, "[-f FMT | --image-opts]\n" +" [--start-offset OFFSET] [--max-length LENGTH]\n" +" [--output human|json] [-U] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specify FILE image format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -s, --start-offset OFFSET\n" +" start at the given OFFSET in the image, not at the beginning\n" +" -l, --max-length LENGTH\n" +" process at most LENGTH bytes instead of up to the end of the image\n" +" --output human|json\n" +" specify output format name (default: human)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" the image file name, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; case 'f': fmt =3D optarg; break; - case 'U': - force_share =3D true; - break; - case OPTION_OUTPUT: - output_format =3D parse_output_format(argv[0], optarg); + case OPTION_IMAGE_OPTS: + image_opts =3D true; break; case 's': start_offset =3D cvtnum("start offset", optarg); @@ -3501,12 +3513,17 @@ static int img_map(const img_cmd_t *ccmd, int argc,= char **argv) return 1; } break; + case OPTION_OUTPUT: + output_format =3D parse_output_format(argv[0], optarg); + break; + case 'U': + force_share =3D true; + break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608864; cv=none; d=zohomail.com; s=zohoarc; b=VAwyaB+QmPYq3UKreS9qWMRDOszEuq9NWcmZq1P3ORpHkgkEphx0sJqA+9RDws6NRtiVdy/DbfLMwUYz8kLxytv3tce2fe0jMm1OvimTVxPPYezAse6DDuSX5AWsC81PGBWvX/NCKmK3TdZV7qCMZuugdvGg47oalc+qaqnFMH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608864; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tW4GMwuBh/KbfZkTuEwqZ8iYnIHhaMFl6ESuhXcPE00=; b=ELur8Un0dW4xJq+3jI3WRMr6GKIdWWhPd/n1A18u3dsLJO52ZE9+dbdc+le//7LE1/6QCHojZrX6TxdpJpKM5T7aboSZQMcpEti5ZPM+An+7SLk3hWPmIcqve5G+OEvm1z0EVpP5yS2Ja19xrkJoIKXb3o62o4Nzn7HQiSEbu6o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608864422485.55503347444073; Tue, 15 Jul 2025 12:47:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublZg-0007LB-SH; Tue, 15 Jul 2025 15:44:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxz-0004X6-NC for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxq-0001ij-VS for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:20 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-163-LRwHrpCyNRimzizPy5RYXw-1; Tue, 15 Jul 2025 15:05:13 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7776D19560B2; Tue, 15 Jul 2025 19:05:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5C7B197702B; Tue, 15 Jul 2025 19:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tW4GMwuBh/KbfZkTuEwqZ8iYnIHhaMFl6ESuhXcPE00=; b=RBCrvD8rfVJo29pCueei6VSJPBORTMxAj8hgf7ijFAKu49KU8M/aySvtH1wPXn7QKCgHbx ZQ1qnJOiAxY2BbnTJfS9uAoHYDX3y+Ew+ETIrKTzrE/l+7uPfYDocWd4CTCnb18lISeq7O 1Ju0eYcCh2prkj1fASYGx2THBKV4olA= X-MC-Unique: LRwHrpCyNRimzizPy5RYXw-1 X-Mimecast-MFC-AGG-ID: LRwHrpCyNRimzizPy5RYXw_1752606312 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 45/57] qemu-img: snapshot: allow specifying -f fmt Date: Tue, 15 Jul 2025 21:03:18 +0200 Message-ID: <20250715190330.378764-46-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608866481116600 From: Michael Tokarev For consistency with other commands, and since it already accepts --image-opts, allow specifying -f fmt too. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Message-ID: <20250531171609.197078-16-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 9 ++++++--- qemu-img-cmds.hx | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 23715811e2..935f28bbc5 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -663,7 +663,7 @@ Command description: bitmap support, or 0 if bitmaps are supported but there is nothing to copy. =20 -.. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -= a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME +.. option:: snapshot [--object OBJECTDEF] [-f FMT | --image-opts] [-U] [-q= ] [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME =20 List, apply, create or delete snapshots in image *FILENAME*. =20 diff --git a/qemu-img.c b/qemu-img.c index a02ccad943..49c61c8b54 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3597,7 +3597,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) BlockBackend *blk; BlockDriverState *bs; QEMUSnapshotInfo sn; - char *filename, *snapshot_name =3D NULL; + char *filename, *fmt =3D NULL, *snapshot_name =3D NULL; int c, ret =3D 0, bdrv_oflags; int action =3D 0; bool quiet =3D false; @@ -3616,7 +3616,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":la:c:d:hqU", + c =3D getopt_long(argc, argv, ":la:c:d:f:hqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -3631,6 +3631,9 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) case 'h': help(); return 0; + case 'f': + fmt =3D optarg; + break; case 'l': if (action) { error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); @@ -3684,7 +3687,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) filename =3D argv[optind++]; =20 /* Open the image */ - blk =3D img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, + blk =3D img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, force_share); if (!blk) { return 1; diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index c9dd70a892..2c5a8a28f9 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -84,9 +84,9 @@ SRST ERST =20 DEF("snapshot", img_snapshot, - "snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snaps= hot | -c snapshot | -d snapshot] filename") + "snapshot [--object objectdef] [-f fmt | --image-opts] [-U] [-q] [-l |= -a snapshot | -c snapshot | -d snapshot] filename") SRST -.. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -= a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME +.. option:: snapshot [--object OBJECTDEF] [-f FMT | --image-opts] [-U] [-q= ] [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME ERST =20 DEF("rebase", img_rebase, --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608069; cv=none; d=zohomail.com; s=zohoarc; b=CdFWBGyxIoR2CynGyYOqhA8uhoK4cmcAvDhmJtfP8pRoO+6nINmxaXfA5vRpkhlTPQXE8VLhZTa6dg72lkOW83RquBkPpmlMSi+hQE1AFtu4SD4Ytuh3nDz7e8t0B/TWwoxhX239fzMUjkLphWnDc+RLDGtB1Y6X/t1SbG1CrKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608069; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8YilhHk/UupSHNVVc6qLt52jWenjz4rlqCmqsdLRsaA=; b=fy4qUvAXjoDvD2Hc9ywtdVHz0bPMHVChsmQnbenzJYhwQCZp3NBGAIqHZb0C2n0eY5eY6sie12auEl2iX6fFA8E3Rh/AXSJZDXIWSaQmdbrhnd7LJZ1NKcXuXT1/Q/q3g6JrHQ+d2IlDwuxr5IazHZ1s6slK+VQnzQShu6dCRLo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608069003997.9027170365323; Tue, 15 Jul 2025 12:34:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublPq-0000Rz-Tm; Tue, 15 Jul 2025 15:34:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxz-0004X5-Mb for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxp-0001ie-K4 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:20 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-428-Bnmzms4UMJWY-IaFOVf78A-1; Tue, 15 Jul 2025 15:05:15 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 78529195608E; Tue, 15 Jul 2025 19:05:14 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EC480197702B; Tue, 15 Jul 2025 19:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606316; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8YilhHk/UupSHNVVc6qLt52jWenjz4rlqCmqsdLRsaA=; b=RgFIVkh0nQ893hzKBPbQC73z9VvukWoHPzFSk/6FcysFydmTp/HszjVENvbQLFV8zaJ//q bJIAEb9leshyfILKrrfG0iLaI/qxlEQO5VhSUL7jeSjxlOZSjvkRWt2L9Fm0/21VYoB3lb DazLdKaYckv9aEQOhGAZXhdzqbj/oxg= X-MC-Unique: Bnmzms4UMJWY-IaFOVf78A-1 X-Mimecast-MFC-AGG-ID: Bnmzms4UMJWY-IaFOVf78A_1752606314 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 46/57] qemu-img: snapshot: make -l (list) the default, simplify option handling Date: Tue, 15 Jul 2025 21:03:19 +0200 Message-ID: <20250715190330.378764-47-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608069746116600 From: Michael Tokarev When no -l/-a/-c/-d specified, assume -l (list). Use the same values for SNAPSHOT_LIST/etc constants as the option chars (lacd), this makes it possible to simplify option handling a lot, combining cases for 4 options into one. Also remove bdrv_oflags handling (only list can use RO mode). Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Message-ID: <20250531171609.197078-17-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 52 ++++++++++++++--------------------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 935f28bbc5..a346988292 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -256,7 +256,7 @@ Parameters to snapshot subcommand: =20 .. option:: -l =20 - Lists all snapshots in the given image + Lists all snapshots in the given image (default action) =20 Command description: =20 diff --git a/qemu-img.c b/qemu-img.c index 49c61c8b54..f117efe687 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3587,10 +3587,11 @@ out: return ret < 0; } =20 -#define SNAPSHOT_LIST 1 -#define SNAPSHOT_CREATE 2 -#define SNAPSHOT_APPLY 3 -#define SNAPSHOT_DELETE 4 +/* the same as options */ +#define SNAPSHOT_LIST 'l' +#define SNAPSHOT_CREATE 'c' +#define SNAPSHOT_APPLY 'a' +#define SNAPSHOT_DELETE 'd' =20 static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) { @@ -3598,7 +3599,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) BlockDriverState *bs; QEMUSnapshotInfo sn; char *filename, *fmt =3D NULL, *snapshot_name =3D NULL; - int c, ret =3D 0, bdrv_oflags; + int c, ret =3D 0; int action =3D 0; bool quiet =3D false; Error *err =3D NULL; @@ -3606,7 +3607,6 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) bool force_share =3D false; int64_t rt; =20 - bdrv_oflags =3D BDRV_O_RDWR; /* Parse commandline parameters */ for(;;) { static const struct option long_options[] =3D { @@ -3634,36 +3634,15 @@ static int img_snapshot(const img_cmd_t *ccmd, int = argc, char **argv) case 'f': fmt =3D optarg; break; - case 'l': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_LIST; - bdrv_oflags &=3D ~BDRV_O_RDWR; /* no need for RW */ - break; - case 'a': + case SNAPSHOT_LIST: + case SNAPSHOT_APPLY: + case SNAPSHOT_CREATE: + case SNAPSHOT_DELETE: if (action) { error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } - action =3D SNAPSHOT_APPLY; - snapshot_name =3D optarg; - break; - case 'c': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_CREATE; - snapshot_name =3D optarg; - break; - case 'd': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_DELETE; + action =3D c; snapshot_name =3D optarg; break; case 'q': @@ -3686,9 +3665,14 @@ static int img_snapshot(const img_cmd_t *ccmd, int a= rgc, char **argv) } filename =3D argv[optind++]; =20 + if (!action) { + action =3D SNAPSHOT_LIST; + } + /* Open the image */ - blk =3D img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, - force_share); + blk =3D img_open(image_opts, filename, fmt, + action =3D=3D SNAPSHOT_LIST ? 0 : BDRV_O_RDWR, + false, quiet, force_share); if (!blk) { return 1; } --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608391; cv=none; d=zohomail.com; s=zohoarc; b=WImp/xUWUqyv9726NgmXutvQV8ue6W43T+ubzliVNKyeW2I36SgibmCxdhvtbayb5I8ztxshDpKXXS20wvw6ixb3n7SrbOUbGxP/JtaxHa90l+tf1ID3qyojk+AlW330+fGfLE0cBI+2UH4HVGrUy0jJegEwMXxlTqoo3rB5+GU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608391; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NeOFjbUAUkbawhAGEAoI45uP3K98VPQeRTW+1GJ6km0=; b=cVDN14X23CyFttz42CtL1bE4CJ5NszWnZfFCazPXey6MQVrzhjyAok3xa9qOGJkV52rPlnd0U+pHuHW3yZulC9pffsYFVQz0dGfosw14aJwKkMFLmMXnAW6w3W/s8FJuayVnD5Vs3Kl0CsGJF1lu2Bq5QWh79It8FjGz1noKq9A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608391186958.4353188940465; Tue, 15 Jul 2025 12:39:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublV2-0004Ly-Ug; Tue, 15 Jul 2025 15:39:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky0-0004XW-Bi for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxr-0001j1-FW for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:21 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-5xLuTCxHNzaBqpsCNJWiYA-1; Tue, 15 Jul 2025 15:05:17 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 797D21800368; Tue, 15 Jul 2025 19:05:16 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EDCC2197702B; Tue, 15 Jul 2025 19:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606318; 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=NeOFjbUAUkbawhAGEAoI45uP3K98VPQeRTW+1GJ6km0=; b=Oa8vJ0NjDB4t3dwUhQCCTkcRX1ha80IOxzQo4OLtCyWn4GFvZr6rr7ATeDvMKbA4sp3Zgo YvMpYn5OMsaqGSlsWEeXCwIirCSoIJKLvsKQb/2LpHRfL4SweZM7n8RcQpyhb9TfVhdo98 dBO0dXO+6CX951Pa5fz14RkTuUA80dA= X-MC-Unique: 5xLuTCxHNzaBqpsCNJWiYA-1 X-Mimecast-MFC-AGG-ID: 5xLuTCxHNzaBqpsCNJWiYA_1752606316 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 47/57] qemu-img: snapshot: refresh options/--help Date: Tue, 15 Jul 2025 21:03:20 +0200 Message-ID: <20250715190330.378764-48-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608392909116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-18-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 60 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index f117efe687..cc26ae9100 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3611,29 +3611,58 @@ static int img_snapshot(const img_cmd_t *ccmd, int = argc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"list", no_argument, 0, SNAPSHOT_LIST}, + {"apply", required_argument, 0, SNAPSHOT_APPLY}, + {"create", required_argument, 0, SNAPSHOT_CREATE}, + {"delete", required_argument, 0, SNAPSHOT_DELETE}, {"force-share", no_argument, 0, 'U'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":la:c:d:f:hqU", + c =3D getopt_long(argc, argv, "hf:la:c:d:Uq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - return 0; + cmd_help(ccmd, "[-f FMT | --image-opts] [-l | -a|-c|-d SNAPSHO= T]\n" +" [-U] [-q] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specify FILE format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -l, --list\n" +" list snapshots in FILE (default action if no -l|-c|-a|-d is given)\n" +" -c, --create SNAPSHOT\n" +" create named snapshot\n" +" -a, --apply SNAPSHOT\n" +" apply named snapshot to the base\n" +" -d, --delete SNAPSHOT\n" +" delete named snapshot\n" +" (only one of -l|-c|-a|-d can be specified)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts) to operate on\n" +); + break; case 'f': fmt =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; case SNAPSHOT_LIST: case SNAPSHOT_APPLY: case SNAPSHOT_CREATE: @@ -3645,18 +3674,17 @@ static int img_snapshot(const img_cmd_t *ccmd, int = argc, char **argv) action =3D c; snapshot_name =3D optarg; break; - case 'q': - quiet =3D true; - break; case 'U': force_share =3D true; break; + case 'q': + quiet =3D true; + break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608605; cv=none; d=zohomail.com; s=zohoarc; b=bVISMDEVeWqmo3B2XqeHepXPj3m+N0pSohDYsRkcM1HgJzXjcHisRY5sAm5PIuYpLwsfje0OeWG04zeBbTGha7PrAR0JR5ewaF9uNRqxmmVsrI6BunvjNMGQYsg7Scr1I8A1LDnHCM1ZjoHylMKgJ++Vl4lHeKCxZz+VvdMNxVA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608605; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yXO12lqeAejIfqZYD1cIDDsv+hSmsSqDNw0zNqDMET8=; b=boTxiFczkm5R5C35ZRDQRYG6FHpRDHdTwT/uw1NXBuwuOIBsP9eRSR+LXmF9+az5KyZrhyDCqMJLSHHpi/IsTVa/pnwDqW0FpTqROFZdj5Wl2JQlNEun3UB1/2E3YnX4zv+09GKMrqQr627D4KpXyuk2jl+ndzBxAkB4gp6oHLI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608605921283.469939877916; Tue, 15 Jul 2025 12:43:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublVI-0005na-94; Tue, 15 Jul 2025 15:39:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky4-0004c8-7I for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkxy-0001jd-FZ for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:30 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-324-JHI-nqnmPv6EFrRgVs6WLw-1; Tue, 15 Jul 2025 15:05:19 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F110A19560B7; Tue, 15 Jul 2025 19:05:18 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EDEDF197702B; Tue, 15 Jul 2025 19:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606321; 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=yXO12lqeAejIfqZYD1cIDDsv+hSmsSqDNw0zNqDMET8=; b=AClOY5F/XLY6hlG3gAam83fHagSL0qolfsTe1KslUqDrccs4EOYx0qB6XOc3wPEUIijDwn ZCqLIkOfp8vC4qS9CXBWZzbwSyqrvqXj/5VOl/RZ80nNTh4ODzidHIRIpyPTSwOkNtUVgR JT/hiVHcRvOFnc7326i34NHXPFvOFpg= X-MC-Unique: JHI-nqnmPv6EFrRgVs6WLw-1 X-Mimecast-MFC-AGG-ID: JHI-nqnmPv6EFrRgVs6WLw_1752606319 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 48/57] qemu-img: rebase: refresh options/--help (short option change) Date: Tue, 15 Jul 2025 21:03:21 +0200 Message-ID: <20250715190330.378764-49-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608606869116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Use -B for --backing-format, keep -F for backwards compatibility. Options added: --format, --cache - for the image in question --backing, --backing-format, --backing-cache, --backing-unsafe - for the new backing file (was eg CACHE vs SRC_CACHE, which is unclear). Probably should rename local variables. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-19-mjt@tls.msk.ru> [kwolf: Removed command description from the argument list] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 87 +++++++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index a346988292..5e7b85079d 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -667,7 +667,7 @@ Command description: =20 List, apply, create or delete snapshots in image *FILENAME*. =20 -.. option:: rebase [--object OBJECTDEF] [--image-opts] [-U] [-q] [-f FMT] = [-t CACHE] [-T SRC_CACHE] [-p] [-u] [-c] -b BACKING_FILE [-F BACKING_FMT] F= ILENAME +.. option:: rebase [--object OBJECTDEF] [--image-opts] [-U] [-q] [-f FMT] = [-t CACHE] [-T SRC_CACHE] [-p] [-u] [-c] -b BACKING_FILE [-B BACKING_FMT] F= ILENAME =20 Changes the backing file of an image. Only the formats ``qcow2`` and ``qed`` support changing the backing file. diff --git a/qemu-img.c b/qemu-img.c index cc26ae9100..a02d271af1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3798,45 +3798,89 @@ static int img_rebase(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"force-share", no_argument, 0, 'U'}, + {"cache", required_argument, 0, 't'}, {"compress", no_argument, 0, 'c'}, + {"backing", required_argument, 0, 'b'}, + {"backing-format", required_argument, 0, 'B'}, + {"backing-cache", required_argument, 0, 'T'}, + {"backing-unsafe", no_argument, 0, 'u'}, + {"force-share", no_argument, 0, 'U'}, + {"progress", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:F:b:upt:T:qUc", + c =3D getopt_long(argc, argv, "hf:t:cb:F:B:T:uUpq", long_options, NULL); if (c =3D=3D -1) { break; } - switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; + switch (c) { case 'h': - help(); + cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE]\n" +" [-b BACKING_FILE [-B BACKING_FMT] [-T BACKING_CACHE]] [-u]\n" +" [-c] [-U] [-p] [-q] [--object OBJDEF] FILE\n" +, +" -f, --format FMT\n" +" specify FILE format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -t, --cache CACHE\n" +" cache mode for FILE (default: " BDRV_DEFAULT_CACHE ")\n" +" -b, --backing BACKING_FILE|\"\"\n" +" rebase onto this file (specify empty name for no backing file)\n" +" -B, --backing-format BACKING_FMT (was -F in <=3D10.0)\n" +" specify format for BACKING_FILE explicitly (default: probing is used= )\n" +" -T, --backing-cache CACHE\n" +" BACKING_FILE cache mode (default: " BDRV_DEFAULT_CACHE ")\n" +" -u, --backing-unsafe\n" +" do not fail if BACKING_FILE can not be read\n" +" -c, --compress\n" +" compress image (when image supports this)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" -p, --progress\n" +" display progress information\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); return 0; case 'f': fmt =3D optarg; break; - case 'F': - out_basefmt =3D optarg; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case 't': + cache =3D optarg; break; case 'b': out_baseimg =3D optarg; break; + case 'F': /* <=3D10.0 */ + case 'B': + out_basefmt =3D optarg; + break; case 'u': unsafe =3D 1; break; + case 'c': + compress =3D true; + break; + case 'U': + force_share =3D true; + break; case 'p': progress =3D 1; break; - case 't': - cache =3D optarg; - break; case 'T': src_cache =3D optarg; break; @@ -3846,15 +3890,8 @@ static int img_rebase(const img_cmd_t *ccmd, int arg= c, char **argv) case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; - case 'U': - force_share =3D true; - break; - case 'c': - compress =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608994; cv=none; d=zohomail.com; s=zohoarc; b=lKB4dqyr6849lJYC1BrkbsEhkLCsPWF8pDrczaTFFEA9ksYTyskKBzWTCxShMaiTf3AizQmQxPAsEcIfj5RZ78YPjuvqAfv4vrpXXpleB/hI6c8KMfK0KcsK39jH9i1mCp0GWNkrmihEkiXp8qWMtDg4QdXCEyvJi3E6N4xXqUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608994; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eoF5O3CxgYBmoMtLJ+YW7avYeQobfPJoF/M2V373gxU=; b=nlm8EkDbWgHmeQcP+AR/AhLd10F2/CJqc5ptwO/zoOWPhJz6gQSy24DdG7SxWkfH4qiWwQGfYpjmn/71THVIi0USAKgk5b4bw32U7TjSPIg58mfRKR/WR2qb4nCainHVzPSQqQ5I9ssAn/W1dpT7YGlXJMNiuAc5w2Rkg3AnDFQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608994646466.9651879755852; Tue, 15 Jul 2025 12:49:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublaC-00008d-8j; Tue, 15 Jul 2025 15:44:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky4-0004cQ-R6 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky1-0001js-MW for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:32 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-du1X5F9ZN4adgu98xciA5Q-1; Tue, 15 Jul 2025 15:05:21 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 008EE19560B8; Tue, 15 Jul 2025 19:05:21 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 721F0197702B; Tue, 15 Jul 2025 19:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606323; 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=eoF5O3CxgYBmoMtLJ+YW7avYeQobfPJoF/M2V373gxU=; b=Pn/bK5+rs43+kGLvGudBcpwdbxUMppWtMNoHyuGtQ12kVR544E0BzlREJuysQLzzGvGTCO wJuXyb2zbE/AkyHUhFjSPuspxYmM+lB6DnEBhY6MIfSwCruLgcCaWAE68hkv4qjNmOiwiJ i5fDwIcl6UD0D4ni12ltSXQXV/Bw9DE= X-MC-Unique: du1X5F9ZN4adgu98xciA5Q-1 X-Mimecast-MFC-AGG-ID: du1X5F9ZN4adgu98xciA5Q_1752606321 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 49/57] qemu-img: resize: do not always eat last argument Date: Tue, 15 Jul 2025 21:03:22 +0200 Message-ID: <20250715190330.378764-50-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608995817116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev 'qemu-img resize --help' does not work, since it wants more arguments. Also -size is only recognized as a very last argument, but it is common for tools to handle other options after positional arguments too. Tell getopt_long() to return non-options together with options, and process filename and size in the loop, and check if there's an argument right after filename which looks like -N (number), and treat it as size (decrement). This way we can handle --help, and we can also have options after filename and size, and `--' will be handled fine too. The only case which is not handled right is when there's an option between filename and size, and size is given as decrement, - in this case -size will be treated as option, not as size. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-20-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index a02d271af1..36ef998a34 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4302,7 +4302,7 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) { Error *err =3D NULL; int c, ret, relative; - const char *filename, *fmt, *size; + const char *filename =3D NULL, *fmt =3D NULL, *size =3D NULL; int64_t n, total_size, current_size; bool quiet =3D false; BlockBackend *blk =3D NULL; @@ -4325,17 +4325,7 @@ static int img_resize(const img_cmd_t *ccmd, int arg= c, char **argv) bool image_opts =3D false; bool shrink =3D false; =20 - /* Remove size from argv manually so that negative numbers are not tre= ated - * as options by getopt. */ - if (argc < 3) { - error_exit(argv[0], "Not enough arguments"); - return 1; - } - - size =3D argv[--argc]; - /* Parse getopt arguments */ - fmt =3D NULL; for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, @@ -4345,7 +4335,7 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) {"shrink", no_argument, 0, OPTION_SHRINK}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hq", + c =3D getopt_long(argc, argv, "-:f:hq", long_options, NULL); if (c =3D=3D -1) { break; @@ -4383,12 +4373,35 @@ static int img_resize(const img_cmd_t *ccmd, int ar= gc, char **argv) case OPTION_SHRINK: shrink =3D true; break; + case 1: /* a non-optional argument */ + if (!filename) { + filename =3D optarg; + /* see if we have -size (number) next to filename */ + if (optind < argc) { + size =3D argv[optind]; + if (size[0] =3D=3D '-' && size[1] >=3D '0' && size[1] = <=3D '9') { + ++optind; + } else { + size =3D NULL; + } + } + } else if (!size) { + size =3D optarg; + } else { + error_exit(argv[0], "Extra argument(s) in command line"); + } + break; } } - if (optind !=3D argc - 1) { + if (!filename && optind < argc) { + filename =3D argv[optind++]; + } + if (!size && optind < argc) { + size =3D argv[optind++]; + } + if (!filename || !size || optind < argc) { error_exit(argv[0], "Expecting image file name and size"); } - filename =3D argv[optind++]; =20 /* Choose grow, shrink, or absolute resize mode */ switch (size[0]) { --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608863; cv=none; d=zohomail.com; s=zohoarc; b=b5ynwm8qfqh37HxLFjlpNXDDNdnl4wO6cClthFqmF3yMy1znZAeks5Bud7Ibe12Ub43mnR1FSjewAlQhpxDYq/p/2wE39weQHI8HEM5uLcXi74KTctawwT2KOQ9gcJTjNo+vRwW88tPYF+h2VpS3MCpoAM0UpCEXhDgB+7WF+4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608863; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1lCKRAPXwO+P9hHFfO7gDlUoNGs/rw9v8WnCn3tdTh0=; b=MPXwPRrPxKCRS4gMTDoKhX6qikiUny/vpPlSc5inkWl8dymtnPZebXXV/B+R0nu3fuKpSPz/tqs4RSF9nLEDdpRNcDOdN9NXR6nnaCwitUU7VHuUoEvsHcam5oBy8MNt0NwKbKNj/PjFWFrW3ttLXwPE4AM7rt4y1DdF3uW/oD0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608863546481.72083509195215; Tue, 15 Jul 2025 12:47:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubla6-0007xc-GL; Tue, 15 Jul 2025 15:44:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky4-0004cM-O8 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky0-0001k0-4H for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:32 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-374--g6hd7EpNL2WrYmbLvbKUw-1; Tue, 15 Jul 2025 15:05:24 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F3A6D1800289; Tue, 15 Jul 2025 19:05:22 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 745E7197702B; Tue, 15 Jul 2025 19:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606325; 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=1lCKRAPXwO+P9hHFfO7gDlUoNGs/rw9v8WnCn3tdTh0=; b=F0m4h7FQZoSVBn3mG4ZxkpzwCFHgoujjU2YkCBeLsLuM3Xv1E9wwPK92s+eTQhvSIzEmkc nYj9OfBWufMR6D3FvjHhqvaQ7XS4Jl11AcUvKag15CnDa2aNHxmAfJqUiZZCFt9yWLbpeS qG+xW0VbA3egLV3BAE3UV5aIq0jO/gI= X-MC-Unique: -g6hd7EpNL2WrYmbLvbKUw-1 X-Mimecast-MFC-AGG-ID: -g6hd7EpNL2WrYmbLvbKUw_1752606323 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 50/57] qemu-img: resize: refresh options/--help Date: Tue, 15 Jul 2025 21:03:23 +0200 Message-ID: <20250715190330.378764-51-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608865288116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-21-mjt@tls.msk.ru> [kwolf: Fixed up qemu-iotests] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 52 ++++++++++++++++++++++++++------------ tests/qemu-iotests/153.out | 12 ++++----- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 36ef998a34..c16de265e0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4329,36 +4329,48 @@ static int img_resize(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"preallocation", required_argument, 0, OPTION_PREALLOCATION}, {"shrink", no_argument, 0, OPTION_SHRINK}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "-:f:hq", + c =3D getopt_long(argc, argv, "-hf:q", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - break; + cmd_help(ccmd, "[-f FMT | --image-opts] [--preallocation PREAL= LOC] [--shrink]\n" +" [-q] [--object OBJDEF] FILE [+-]SIZE[bkKMGTPE]\n" +, +" -f, --format FMT\n" +" specify FILE format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,...), not a file name\n" +" (incompatible with -f|--format)\n" +" --shrink\n" +" allow operation when the new size is smaller than the original\n" +" --preallocation PREALLOC\n" +" specify FMT-specific preallocation type for the new areas\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +" [+-]SIZE[bkKMGTPE]\n" +" new image size or amount by which to shrink (-)/grow (+),\n" +" with optional multiplier suffix (powers of 1024, default is bytes)\n" +); + return 0; case 'f': fmt =3D optarg; break; - case 'q': - quiet =3D true; - break; - case OPTION_OBJECT: - user_creatable_process_cmdline(optarg); - break; case OPTION_IMAGE_OPTS: image_opts =3D true; break; @@ -4373,6 +4385,12 @@ static int img_resize(const img_cmd_t *ccmd, int arg= c, char **argv) case OPTION_SHRINK: shrink =3D true; break; + case 'q': + quiet =3D true; + break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; case 1: /* a non-optional argument */ if (!filename) { filename =3D optarg; @@ -4391,6 +4409,8 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) error_exit(argv[0], "Extra argument(s) in command line"); } break; + default: + tryhelp(argv[0]); } } if (!filename && optind < argc) { diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index a8ffd01266..ac3e340e15 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -128,8 +128,8 @@ qemu-img commit: invalid option -- 'U' Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img resize: invalid option -- 'U' +Try 'qemu-img resize --help' for more information =20 _qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base -F q= cow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock @@ -252,8 +252,8 @@ qemu-img commit: invalid option -- 'U' Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img resize: invalid option -- 'U' +Try 'qemu-img resize --help' for more information =20 _qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base -F q= cow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock @@ -357,8 +357,8 @@ qemu-img commit: invalid option -- 'U' Try 'qemu-img commit --help' for more information =20 _qemu_img_wrapper resize -U TEST_DIR/t.qcow2 32M -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img resize: invalid option -- 'U' +Try 'qemu-img resize --help' for more information =20 _qemu_img_wrapper rebase -U TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base -F q= cow2 =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608608; cv=none; d=zohomail.com; s=zohoarc; b=QOvjAsksxhS2GwwY1rmqsRbd0JUlaQYIVLzWDzcO0MKN6mMSWq4j0pz8wJzYwfuPvGfBV1D3MXDqbu2+krnhdXCgzzzsMQWxWJtBBwuNYXeF3Z3keWD7PeGUjpMjRymYejmOBJZaguLU9OK3Dok2/mOglBEZkRrqLl57OIVO/mI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608608; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7uCRQHqcaIupLbmBWoiFd2iNSs6s7kpg5Vp92ZSuOuY=; b=PkUOKcKOJ769KSPX40z/jfqyVEGrulGVK6KEqFU1Anf+FkXq9Bg0X84Gf7n7bdNUA/IdUPKlUg/EJ8rpyXIG2Qct6ntS+GCxa0PRBF/JzEYEhp7EE81W3IITlxm69KQSYnI9iyFwDaW6p2uZOGOLoOJ2lgairJy5aCJjzlczBtI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608608653628.2383978676284; Tue, 15 Jul 2025 12:43:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublV7-0004sU-Mh; Tue, 15 Jul 2025 15:39:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky4-0004cP-R2 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky1-0001kR-EE for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:32 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-53-pAkKV5qzNqqY-YBUYroUxQ-1; Tue, 15 Jul 2025 15:05:25 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02CF41956087; Tue, 15 Jul 2025 19:05:25 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 75B8E197702F; Tue, 15 Jul 2025 19:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606327; 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=7uCRQHqcaIupLbmBWoiFd2iNSs6s7kpg5Vp92ZSuOuY=; b=LxbQb8oTRvnt13FenoIW+pl4nvLzG+49Q1bchWbrpTqkXvIfZr8DufGdCPekXs35XtnNQn qKGxBD4++nqFyzNv6Xr3BoF9BRVGnExV8XfxUDqGKZ3VYcu/N22VKJkTw0WwxWHF21yv0G U3b6gI/zIZ5AYGzTWmJQs7OqmXtg1Mc= X-MC-Unique: pAkKV5qzNqqY-YBUYroUxQ-1 X-Mimecast-MFC-AGG-ID: pAkKV5qzNqqY-YBUYroUxQ_1752606325 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 51/57] qemu-img: amend: refresh options/--help Date: Tue, 15 Jul 2025 21:03:24 +0200 Message-ID: <20250715190330.378764-52-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608610919116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-22-mjt@tls.msk.ru> [kwolf: Fixed up qemu-iotests] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 54 +++++++++++++++++++++++++++----------- tests/qemu-iotests/153.out | 12 ++++----- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c16de265e0..bb10569372 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4564,26 +4564,48 @@ static int img_amend(const img_cmd_t *ccmd, int arg= c, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"options", required_argument, 0, 'o'}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 't'}, {"force", no_argument, 0, OPTION_FORCE}, + {"progress", no_argument, 0, 'p'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":ho:f:t:pq", + c =3D getopt_long(argc, argv, "ho:f:t:pq", long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, "-o FMT_OPTS [-f FMT | --image-opts]\n" +" [-t CACHE] [--force] [-p] [-q] [--object OBJDEF] FILE\n" +, +" -o, --options FMT_OPTS\n" +" FMT-specfic format options (required)\n" +" -f, --format FMT\n" +" specify FILE format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -t, --cache CACHE\n" +" cache mode for FILE (default: " BDRV_DEFAULT_CACHE ")\n" +" --force\n" +" allow certain unsafe operations\n" +" -p, --progres\n" +" show operation progress\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; case 'o': if (accumulate_options(&options, optarg) < 0) { @@ -4594,9 +4616,15 @@ static int img_amend(const img_cmd_t *ccmd, int argc= , char **argv) case 'f': fmt =3D optarg; break; + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; case 't': cache =3D optarg; break; + case OPTION_FORCE: + force =3D true; + break; case 'p': progress =3D true; break; @@ -4606,12 +4634,8 @@ static int img_amend(const img_cmd_t *ccmd, int argc= , char **argv) case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; - case OPTION_FORCE: - force =3D true; - break; + default: + tryhelp(argv[0]); } } =20 diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index ac3e340e15..28e1a22952 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -120,8 +120,8 @@ _qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/= t.qcow2 _qemu_img_wrapper map -U TEST_DIR/t.qcow2 =20 _qemu_img_wrapper amend -o size=3D32M -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img amend: invalid option -- 'U' +Try 'qemu-img amend --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 qemu-img commit: invalid option -- 'U' @@ -244,8 +244,8 @@ _qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/= t.qcow2 _qemu_img_wrapper map -U TEST_DIR/t.qcow2 =20 _qemu_img_wrapper amend -o size=3D32M -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img amend: invalid option -- 'U' +Try 'qemu-img amend --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 qemu-img commit: invalid option -- 'U' @@ -349,8 +349,8 @@ _qemu_img_wrapper compare -U TEST_DIR/t.qcow2 TEST_DIR/= t.qcow2 _qemu_img_wrapper map -U TEST_DIR/t.qcow2 =20 _qemu_img_wrapper amend -o size=3D32M -U TEST_DIR/t.qcow2 -qemu-img: unrecognized option '-U' -Try 'qemu-img --help' for more information +qemu-img amend: invalid option -- 'U' +Try 'qemu-img amend --help' for more information =20 _qemu_img_wrapper commit -U TEST_DIR/t.qcow2 qemu-img commit: invalid option -- 'U' --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608120; cv=none; d=zohomail.com; s=zohoarc; b=L/qrQ77ror1AHSZp84QR6L9X1yBx9pppCranYsnDADMh9oWM9GXn2k9XtLRkqhkpX5iDSH3f8SbN2s4zQjYRlbQbu0BHHtvbh0M6TnsSeOoFkOX8Nr3t7ywmsGCi7ZtJW44wIFVDAkCuLJ1/Es4zQ+uai18MIQyd8TGUXFIAjCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608120; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RIw6lN3VR9AGDzYGEU+yhTDe/xM0MVxTUdBYuPo+K04=; b=ilbtY+dKivcCxbVk3s+ItO9v1KmZ0bGRZi/reLtLQhM4xE9/elGi8PpuURiOw/CfuRBRSwzfyiqMH5M8WwxzERs8pqQlWnxU7VLt0f2YN1EOYj+LDfQ+Na3DctiIplGTrLZvkZdxondjbymREn9Y5HkzqvFo1byYI8+EtXJnxl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608120935623.8333595848218; Tue, 15 Jul 2025 12:35:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQF-0001su-3G; Tue, 15 Jul 2025 15:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyA-0004fq-MN for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky8-0001mQ-MA for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:38 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-629-e2DNWBeGOHuH8qMIFjebTw-1; Tue, 15 Jul 2025 15:05:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 01BE518002A8; Tue, 15 Jul 2025 19:05:27 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76BC5197702B; Tue, 15 Jul 2025 19:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606335; 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=RIw6lN3VR9AGDzYGEU+yhTDe/xM0MVxTUdBYuPo+K04=; b=IOg++eACpWgaZ67/5kTC05LP04a/Y+kncYwPvAhuPABCxcpkEGgVrhwe9NpXNmXZiZWA7p wkt2+gONfO4i9ZFk4TrAo/n4ADuAC3Z7PLp/XwS2af7h+U/d+vkN7FDEAxTQvqdyksKkKj FF4Js7+HFnl6h5Ou69gaIXFnzNJRmwY= X-MC-Unique: e2DNWBeGOHuH8qMIFjebTw-1 X-Mimecast-MFC-AGG-ID: e2DNWBeGOHuH8qMIFjebTw_1752606327 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 52/57] qemu-img: bench: refresh options/--help Date: Tue, 15 Jul 2025 21:03:25 +0200 Message-ID: <20250715190330.378764-53-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608122448116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Add missing --object option. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-23-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 112 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 28 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index bb10569372..17f7516a68 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4864,28 +4864,93 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL= }, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 't'}, + {"count", required_argument, 0, 'c'}, + {"depth", required_argument, 0, 'd'}, + {"offset", required_argument, 0, 'o'}, + {"buffer-size", required_argument, 0, 's'}, + {"step-size", required_argument, 0, 'S'}, + {"write", no_argument, 0, 'w'}, {"pattern", required_argument, 0, OPTION_PATTERN}, + {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL= }, {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, + {"aio", required_argument, 0, 'i'}, + {"native", no_argument, 0, 'n'}, {"force-share", no_argument, 0, 'U'}, + {"quiet", no_argument, 0, 'q'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hc:d:f:ni:o:qs:S:t:wU", long_optio= ns, - NULL); + c =3D getopt_long(argc, argv, "hf:t:c:d:o:s:S:wi:nUq", + long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); + case 'h': + cmd_help(ccmd, "[-f FMT | --image-opts] [-t CACHE]\n" +" [-c COUNT] [-d DEPTH] [-o OFFSET] [-s BUFFER_SIZE] [-S STEP_SIZE]= \n" +" [-w [--pattern PATTERN] [--flush-interval INTERVAL [--no-drain]]]= \n" +" [-i AIO] [-n] [-U] [-q] FILE\n" +, +" -f, --format FMT\n" +" specify FILE format explicitly\n" +" --image-opts\n" +" indicates that FILE is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -t, --cache CACHE\n" +" cache mode for FILE (default: " BDRV_DEFAULT_CACHE ")\n" +" -c, --count COUNT\n" +" number of I/O requests to perform\n" +" -d, --depth DEPTH\n" +" number of requests to perform in parallel\n" +" -o, --offset OFFSET\n" +" start first request at this OFFSET\n" +" -s, --buffer-size BUFFER_SIZE[bkKMGTPE]\n" +" size of each I/O request, with optional multiplier suffix\n" +" (powers of 1024, default is 4K)\n" +" -S, --step-size STEP_SIZE[bkKMGTPE]\n" +" each next request offset increment, with optional multiplier suffix\= n" +" (powers of 1024, default is the same as BUFFER_SIZE)\n" +" -w, --write\n" +" perform write test (default is read)\n" +" --pattern PATTERN\n" +" write this pattern byte instead of zero\n" +" --flush-interval FLUSH_INTERVAL\n" +" issue flush after this number of requests\n" +" --no-drain\n" +" do not wait when flushing pending requests\n" +" -i, --aio AIO\n" +" async-io backend (threads, native, io_uring)\n" +" -n, --native\n" +" use native AIO backend if possible\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" -q, --quiet\n" +" quiet mode (produce only error messages if any)\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +); break; - case '?': - unrecognized_option(argv[optind - 1]); + case 'f': + fmt =3D optarg; break; - case 'h': - help(); + case OPTION_IMAGE_OPTS: + image_opts =3D true; + break; + case 't': + ret =3D bdrv_parse_cache_mode(optarg, &flags, &writethrough); + if (ret < 0) { + error_report("Invalid cache mode"); + ret =3D -1; + goto out; + } break; case 'c': { @@ -4909,9 +4974,6 @@ static int img_bench(const img_cmd_t *ccmd, int argc,= char **argv) depth =3D res; break; } - case 'f': - fmt =3D optarg; - break; case 'n': flags |=3D BDRV_O_NATIVE_AIO; break; @@ -4932,9 +4994,6 @@ static int img_bench(const img_cmd_t *ccmd, int argc,= char **argv) break; } break; - case 'q': - quiet =3D true; - break; case 's': { int64_t sval; @@ -4959,21 +5018,10 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) step =3D sval; break; } - case 't': - ret =3D bdrv_parse_cache_mode(optarg, &flags, &writethrough); - if (ret < 0) { - error_report("Invalid cache mode"); - ret =3D -1; - goto out; - } - break; case 'w': flags |=3D BDRV_O_RDWR; is_write =3D true; break; - case 'U': - force_share =3D true; - break; case OPTION_PATTERN: { unsigned long res; @@ -4999,9 +5047,17 @@ static int img_bench(const img_cmd_t *ccmd, int argc= , char **argv) case OPTION_NO_DRAIN: drain_on_flush =3D false; break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; + case 'U': + force_share =3D true; break; + case 'q': + quiet =3D true; + break; + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608085; cv=none; d=zohomail.com; s=zohoarc; b=hhkU7Oz+8aCn97/X+RIBfYN0MGGGKXt44wGxWJJwDVJThn5thyL9U43CGd3UBghNEc90UeJT/RY4rAmlwu+WmOwLIREnhWIxp+6BeVrx8xb2zSPhMr8BK0bl8RPVux003Al1z8W/wrPnemgMfMXwGcMmUo/YO56OPWcprWhHOMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608085; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xeqGBdSIo1Kezt99V2b6a5nLGVaHJEmc+IWu5aa0NyQ=; b=EadWofX/lBit5vB0kqYrnp6oap8uMur23+cH4Oc2GWsIwMGxN9CVy268jAg4vYL1Ij3MfwVJx6C8eFVaPewgstasbePUIfaORT3ZA0z1PLbKOhfS1+dHT6S+AvSto4Z+SY6eVEyRwACcoYPgSxds+iUDKfNShANiO+PrMBngRS0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608084990700.9481232290764; Tue, 15 Jul 2025 12:34:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQ5-000162-CX; Tue, 15 Jul 2025 15:34:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky8-0004eU-Uc for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky4-0001lQ-Ou for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:35 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-oYyfQ9VyMICZGLfrWliUng-1; Tue, 15 Jul 2025 15:05:29 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 028C118002AB; Tue, 15 Jul 2025 19:05:29 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 77223197702C; Tue, 15 Jul 2025 19:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606332; 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=xeqGBdSIo1Kezt99V2b6a5nLGVaHJEmc+IWu5aa0NyQ=; b=AHc/uc0cZI1T15cj2Ml8X224aDYsSKUGjM1NN2E3yYGq1AHep21Iszrl/9al1l15oGt1/A 5ecuYx+RNMyzr6eR4TjUsQsy5J7ujJiex5UWGzPPLkAksPZZ/kShaMaK15nm+3usJ2mG+A TYg7i3FyUauTfnw2ktOdJvyuPnOpiko= X-MC-Unique: oYyfQ9VyMICZGLfrWliUng-1 X-Mimecast-MFC-AGG-ID: oYyfQ9VyMICZGLfrWliUng_1752606329 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 53/57] qemu-img: bitmap: refresh options/--help Date: Tue, 15 Jul 2025 21:03:26 +0200 Message-ID: <20250715190330.378764-54-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608086035116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-24-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 80 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 17f7516a68..d7f69c4bfb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5184,48 +5184,69 @@ static int img_bitmap(const img_cmd_t *ccmd, int ar= gc, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"add", no_argument, 0, OPTION_ADD}, + {"granularity", required_argument, 0, 'g'}, {"remove", no_argument, 0, OPTION_REMOVE}, {"clear", no_argument, 0, OPTION_CLEAR}, {"enable", no_argument, 0, OPTION_ENABLE}, {"disable", no_argument, 0, OPTION_DISABLE}, {"merge", required_argument, 0, OPTION_MERGE}, - {"granularity", required_argument, 0, 'g'}, {"source-file", required_argument, 0, 'b'}, {"source-format", required_argument, 0, 'F'}, + {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":b:f:F:g:h", long_options, NULL); + c =3D getopt_long(argc, argv, "hf:g:b:F:", + long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - break; - case 'b': - src_filename =3D optarg; + cmd_help(ccmd, "[-f FMT | --image-opts]\n" +" ( --add [-g SIZE] | --remove | --clear | --enable | --disable |\n" +" --merge SOURCE [-b SRC_FILE [-F SRC_FMT]] )..\n" +" [--object OBJDEF] FILE BITMAP\n" +, +" -f, --format FMT\n" +" specify FILE format explicitly (default: probing is used)\n" +" --image-opts\n" +" treat FILE as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" --add\n" +" creates BITMAP in FILE, enables to record future edits\n" +" -g, --granularity SIZE[bKMGTPE]\n" +" sets non-default granularity for the bitmap being added,\n" +" with optional multiplier suffix (in powers of 1024)\n" +" --remove\n" +" removes BITMAP from FILE\n" +" --clear\n" +" clears BITMAP in FILE\n" +" --enable, --disable\n" +" starts and stops recording future edits to BITMAP in FILE\n" +" --merge SOURCE\n" +" merges contents of the SOURCE bitmap into BITMAP in FILE\n" +" -b, --source-file SRC_FILE\n" +" select alternative source file for --merge\n" +" -F, --source-format SRC_FMT\n" +" specify format for SRC_FILE explicitly\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" FILE\n" +" name of the image file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to operate on\n" +" BITMAP\n" +" name of the bitmap to add, remove, clear, enable, disable or merge t= o\n" +); break; case 'f': fmt =3D optarg; break; - case 'F': - src_fmt =3D optarg; - break; - case 'g': - granularity =3D cvtnum("granularity", optarg); - if (granularity < 0) { - return 1; - } + case OPTION_IMAGE_OPTS: + image_opts =3D true; break; case OPTION_ADD: act =3D g_new0(ImgBitmapAction, 1); @@ -5233,6 +5254,12 @@ static int img_bitmap(const img_cmd_t *ccmd, int arg= c, char **argv) QSIMPLEQ_INSERT_TAIL(&actions, act, next); add =3D true; break; + case 'g': + granularity =3D cvtnum("granularity", optarg); + if (granularity < 0) { + return 1; + } + break; case OPTION_REMOVE: act =3D g_new0(ImgBitmapAction, 1); act->act =3D BITMAP_REMOVE; @@ -5260,12 +5287,17 @@ static int img_bitmap(const img_cmd_t *ccmd, int ar= gc, char **argv) QSIMPLEQ_INSERT_TAIL(&actions, act, next); merge =3D true; break; + case 'b': + src_filename =3D optarg; + break; + case 'F': + src_fmt =3D optarg; + break; case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608104; cv=none; d=zohomail.com; s=zohoarc; b=lGQigCsizTG2DWwi7hsOi46M6HNgHiSy/hvlhi0jVouUIHfukTK0ZjvcMXw6vmi2+gG0FDtfJkx72JOv17W3eOLV14sjW5qFDIBzRQJimOWa4cV28WDoMP3bl+bEZJCtAOrWI6TUI9gI8UHuN5+yuET6NxP3SqRW4KX7jQVqO78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608104; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U0EOHuFMYVRcuZbgCHTLu4jqLIKx67Yh5hSOj0aEp0I=; b=mc8iPByOvEC/xyaOfy/UNSpgtRFVzK3qMIypiAPaWr6J49CrooLM7I72p0Ihkg9Ct1K4rpKXCl5en9cAgAasS9x7l7Hm+zL5dk2QS3EQoRKlZ65As/o8P9CzLlUrCDey2TiKFxg29JXIx7vMwZONAmYwYOmeNccs2VgPaLectoA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608104156980.1626968387991; Tue, 15 Jul 2025 12:35:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQL-0002iE-VF; Tue, 15 Jul 2025 15:34:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyD-0004h5-Fz for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyB-0001nY-L2 for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-QbDz8SZBOleUTZb4lL_XoQ-1; Tue, 15 Jul 2025 15:05:35 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0503119560B1; Tue, 15 Jul 2025 19:05:31 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 78603197702B; Tue, 15 Jul 2025 19:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606339; 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=U0EOHuFMYVRcuZbgCHTLu4jqLIKx67Yh5hSOj0aEp0I=; b=WgDOaaL3i6T8YgVvBxuJ2M4GZ0wrJkLW61TLGoyyOCOD+OHwkrY+BsTC/4J3Oh9eEOAPLO JC9Gv6/a8UFoKdwRZCjtrWPGZh6zI4RDE7Exkcv+Mpziwd6BlEmpf9+yAe67LrzUJzSStU Bq1TGZshhTgl2iI1bJuWml9W95qbexA= X-MC-Unique: QbDz8SZBOleUTZb4lL_XoQ-1 X-Mimecast-MFC-AGG-ID: QbDz8SZBOleUTZb4lL_XoQ_1752606331 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 54/57] qemu-img: dd: refresh options/--help Date: Tue, 15 Jul 2025 21:03:27 +0200 Message-ID: <20250715190330.378764-55-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608106435116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-25-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d7f69c4bfb..35c3d9ad48 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5538,31 +5538,54 @@ static int img_dd(const img_cmd_t *ccmd, int argc, = char **argv) }; const struct option long_options[] =3D { { "help", no_argument, 0, 'h'}, - { "object", required_argument, 0, OPTION_OBJECT}, + { "format", required_argument, 0, 'f'}, { "image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + { "output-format", required_argument, 0, 'O'}, { "force-share", no_argument, 0, 'U'}, + { "object", required_argument, 0, OPTION_OBJECT}, { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, ":hf:O:U", long_options, NULL)))= { + while ((c =3D getopt_long(argc, argv, "hf:O:U", long_options, NULL))) { if (c =3D=3D EOF) { break; } switch (c) { - case 'O': - out_fmt =3D optarg; + case 'h': + cmd_help(ccmd, "[-f FMT|--image-opts] [-O OUTPUT_FMT] [-U]\n" +" [--object OBJDEF] [bs=3DBLOCK_SIZE] [count=3DBLOCKS] if=3DINPUT o= f=3DOUTPUT\n" +, +" -f, --format FMT\n" +" specify format for INPUT explicitly (default: probing is used)\n" +" --image-opts\n" +" treat INPUT as an option string (key=3Dvalue,..), not a file name\n" +" (incompatible with -f|--format)\n" +" -O, --output-format OUTPUT_FMT\n" +" format of the OUTPUT (default: raw)\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" bs=3DBLOCK_SIZE[bKMGTP]\n" +" size of the I/O block, with optional multiplier suffix (powers of 10= 24)\n" +" (default: 512)\n" +" count=3DCOUNT\n" +" number of blocks to convert (default whole INPUT)\n" +" if=3DINPUT\n" +" name of the file, or option string (key=3Dvalue,..)\n" +" with --image-opts, to use for input\n" +" of=3DOUTPUT\n" +" output file name to create (will be overridden if alrady exists)\n" +); break; case 'f': fmt =3D optarg; break; - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); + case OPTION_IMAGE_OPTS: + image_opts =3D true; break; - case 'h': - help(); + case 'O': + out_fmt =3D optarg; break; case 'U': force_share =3D true; @@ -5570,9 +5593,8 @@ static int img_dd(const img_cmd_t *ccmd, int argc, ch= ar **argv) case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; - break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608992; cv=none; d=zohomail.com; s=zohoarc; b=MuCuals9n7N57zvb+3ZGCbCjLXinJpJnOpP6iBakOlWnXWgcO1pKih+Y4wM3Tc6dc2/jvq0pP+LcR2XoUqfInJP5fF7k+5XP1gUNeBoie53LMjCc2OFRWN2Owg0FLnKqlr9UsDMENAvXud6fRnMKogOuSdls+6L8VszKL/FUyF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608992; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dRAY1iHGe9JZU4c78ar1+cHtiyObqQqXuvtezlNWzEw=; b=n3mqm76hw3wtcRKB3zmbHhgglUsFhVJD55uxBKRCWe2VcKwN3nmHz6P5AbByFBkvjJBeGn3o9J5zXtHS/vYAa1zJ96NLKywp5bSrlkY3pT6RBBaRWS8P7/YYxQO+IROPDM9Tnpse54bnPGCH6AAKYCUEJgcLoL86XqQjkQnkylg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608992911505.2292552497519; Tue, 15 Jul 2025 12:49:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublaF-0000Sb-RZ; Tue, 15 Jul 2025 15:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyA-0004fs-Ma for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubky8-0001mT-MH for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:38 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-fnn8_Nh4MgeykDYI-33kAQ-1; Tue, 15 Jul 2025 15:05:33 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 04AB918002EC; Tue, 15 Jul 2025 19:05:33 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 79BE0197702B; Tue, 15 Jul 2025 19:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606335; 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=dRAY1iHGe9JZU4c78ar1+cHtiyObqQqXuvtezlNWzEw=; b=DSevb9wFuUvHWax9LiQm2CRaXUS9ICK4Px45YRaa7Aygf8eZTrkUNmu9z29AXUw58MZfXe Mhf/5XUlHy7cdPbCPbWnO+pchbq5A457gDa1/xmYkSw+XP/0m3oSX7it9yhZ11MY2Qre6c vId1jAvRH8/rXJIQ3ZPq3A+Jk4xGgNo= X-MC-Unique: fnn8_Nh4MgeykDYI-33kAQ-1 X-Mimecast-MFC-AGG-ID: fnn8_Nh4MgeykDYI-33kAQ_1752606333 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 55/57] qemu-img: measure: refresh options/--help Date: Tue, 15 Jul 2025 21:03:28 +0200 Message-ID: <20250715190330.378764-56-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608993909116600 Content-Type: text/plain; charset="utf-8" From: Michael Tokarev Add missing long options and --help output, reorder options for consistency. Also add -s short option for --size (and remove OPTION_SIZE). Signed-off-by: Michael Tokarev Message-ID: <20250531171609.197078-26-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 89 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 35c3d9ad48..a7d9d50250 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -72,7 +72,6 @@ enum { OPTION_FLUSH_INTERVAL =3D 261, OPTION_NO_DRAIN =3D 262, OPTION_TARGET_IMAGE_OPTS =3D 263, - OPTION_SIZE =3D 264, OPTION_PREALLOCATION =3D 265, OPTION_SHRINK =3D 266, OPTION_SALVAGE =3D 267, @@ -5786,15 +5785,6 @@ static void dump_json_block_measure_info(BlockMeasur= eInfo *info) =20 static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) { - static const struct option long_options[] =3D { - {"help", no_argument, 0, 'h'}, - {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"object", required_argument, 0, OPTION_OBJECT}, - {"output", required_argument, 0, OPTION_OUTPUT}, - {"size", required_argument, 0, OPTION_SIZE}, - {"force-share", no_argument, 0, 'U'}, - {0, 0, 0, 0} - }; OutputFormat output_format =3D OFORMAT_HUMAN; BlockBackend *in_blk =3D NULL; BlockDriver *drv; @@ -5815,23 +5805,61 @@ static int img_measure(const img_cmd_t *ccmd, int a= rgc, char **argv) int ret =3D 1; int c; =20 - while ((c =3D getopt_long(argc, argv, "hf:O:o:l:U", + static const struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"source-format", required_argument, 0, 'f'}, /* img_convert */ + {"format", required_argument, 0, 'f'}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"source-image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, /* img_c= onvert */ + {"snapshot", required_argument, 0, 'l'}, + {"target-format", required_argument, 0, 'O'}, + {"target-format-options", required_argument, 0, 'o'}, /* img_conve= rt */ + {"options", required_argument, 0, 'o'}, + {"force-share", no_argument, 0, 'U'}, + {"output", required_argument, 0, OPTION_OUTPUT}, + {"object", required_argument, 0, OPTION_OBJECT}, + {"size", required_argument, 0, 's'}, + {0, 0, 0, 0} + }; + + while ((c =3D getopt_long(argc, argv, "hf:l:O:o:Us:", long_options, NULL)) !=3D -1) { switch (c) { - case '?': case 'h': - help(); + cmd_help(ccmd, "[-f FMT|--image-opts] [-l SNAPSHOT]\n" +" [-O TARGET_FMT] [-o TARGET_FMT_OPTS] [--output human|json]\n" +" [--object OBJDEF] (--size SIZE | FILE)\n" +, +" -f, --format\n" +" specify format of FILE explicitly (default: probing is used)\n" +" --image-opts\n" +" indicates that FILE is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -l, --snapshot SNAPSHOT\n" +" use this snapshot in FILE as source\n" +" -O, --target-format TARGET_FMT\n" +" desired target/output image format (default: raw)\n" +" -o TARGET_FMT_OPTS\n" +" options specific to TARGET_FMT\n" +" --output human|json\n" +" output format (default: human)\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" --object OBJDEF\n" +" defines QEMU user-creatable object\n" +" -s, --size SIZE[bKMGTPE]\n" +" measure file size for given image size,\n" +" with optional multiplier suffix (powers of 1024)\n" +" FILE\n" +" measure file size required to convert from FILE (either a file name\= n" +" or an option string (key=3Dvalue,..) with --image-options)\n" +); break; case 'f': fmt =3D optarg; break; - case 'O': - out_fmt =3D optarg; - break; - case 'o': - if (accumulate_options(&options, optarg) < 0) { - goto out; - } + case OPTION_IMAGE_OPTS: + image_opts =3D true; break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { @@ -5846,24 +5874,31 @@ static int img_measure(const img_cmd_t *ccmd, int a= rgc, char **argv) snapshot_name =3D optarg; } break; - case 'U': - force_share =3D true; + case 'O': + out_fmt =3D optarg; break; - case OPTION_OBJECT: - user_creatable_process_cmdline(optarg); + case 'o': + if (accumulate_options(&options, optarg) < 0) { + goto out; + } break; - case OPTION_IMAGE_OPTS: - image_opts =3D true; + case 'U': + force_share =3D true; break; case OPTION_OUTPUT: output_format =3D parse_output_format(argv[0], optarg); break; - case OPTION_SIZE: + case OPTION_OBJECT: + user_creatable_process_cmdline(optarg); + break; + case 's': img_size =3D cvtnum("image size", optarg); if (img_size < 0) { goto out; } break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608602; cv=none; d=zohomail.com; s=zohoarc; b=lbQeV6XPKFtOzhzrOjqzXK7XSJZkAwZXJxVdEaoh3p7yaJ8ADg2U6L5XAb6kwB154dcd0OqUdIiAIIEL5M2r66O26sRX+hI2it4z7YbnUIebo5Qw2Tf7k0slWo+ko8B9qab1wiR7YYmoaop4oA/1WqQNHaqAD+eIIEnEjSWqjI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608602; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KvYy9gFRkmSNIVMesqdYxwUoz2shtD4R42Xm+y1sjj4=; b=GCeYVmXFSklnt28xz9I5GIJxAtWxlqgc8ImnG3cMJ6ilL67yNrRFtARWf7bBH7xAB2MML2Ou29n3fakjdPuIrlHadDCgB15xDnAPByTVF/LUMHF84uBnsKsZUlJ0E01YbchZmYpzhDmnQw/5gwMD6JZ1dEmMyF0U502AcY7+kOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608602967892.6509875254203; Tue, 15 Jul 2025 12:43:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublVL-0006Ea-EN; Tue, 15 Jul 2025 15:39:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyE-0004hB-1N for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyB-0001nL-4M for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:41 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-353-PN7smnLmNsCdHub9Z2_Tug-1; Tue, 15 Jul 2025 15:05:36 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5EF3219560BA; Tue, 15 Jul 2025 19:05:35 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B443197702B; Tue, 15 Jul 2025 19:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KvYy9gFRkmSNIVMesqdYxwUoz2shtD4R42Xm+y1sjj4=; b=hADy/NE7XpKAXSrpYXoHmCJYS7hMfycek+QpWnCNwQAdCFRfcatYXwp+seLypXXyX+eaOg f0gmr1feVDMTkX3rJqF7cX84AhXM46VzbkLIoUn3aGRbuBNzdJbg4ZCZHu1qXK8frKkBI+ btXDFyK2S7tDXNcaVWCQA5aQd64Hlrc= X-MC-Unique: PN7smnLmNsCdHub9Z2_Tug-1 X-Mimecast-MFC-AGG-ID: PN7smnLmNsCdHub9Z2_Tug_1752606335 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 56/57] qemu-img: implement short --help, remove global help() function Date: Tue, 15 Jul 2025 21:03:29 +0200 Message-ID: <20250715190330.378764-57-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608605166116600 From: Michael Tokarev now once all individual subcommands has --help support, remove the large unreadable help() thing and replace it with small global --help, which refers to individual command --help for more info. While at it, also line-wrap list of formats after 75 chars. Since missing_argument() and unrecognized_option() are now unused, remove them. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Message-ID: <20250531171609.197078-27-mjt@tls.msk.ru> [kwolf: Fixed up style and formatting] Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 214 ++++++++++++++++++----------------------------------- 1 file changed, 73 insertions(+), 141 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index a7d9d50250..b34b1390bb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -61,6 +61,7 @@ typedef struct img_cmd_t { const char *name; int (*handler)(const struct img_cmd_t *ccmd, int argc, char **argv); + const char *description; } img_cmd_t; =20 enum { @@ -95,11 +96,6 @@ typedef enum OutputFormat { /* Default to cache=3Dwriteback as data integrity is not important for qem= u-img */ #define BDRV_DEFAULT_CACHE "writeback" =20 -static void format_print(void *opaque, const char *name) -{ - printf(" %s", name); -} - static G_NORETURN void tryhelp(const char *argv0) { @@ -119,18 +115,6 @@ void error_exit(const char *argv0, const char *fmt, ..= .) tryhelp(argv0); } =20 -static G_NORETURN -void missing_argument(const char *option) -{ - error_exit("qemu-img", "missing argument for option '%s'", option); -} - -static G_NORETURN -void unrecognized_option(const char *option) -{ - error_exit("qemu-img", "unrecognized option '%s'", option); -} - /* * Print --help output for a command and exit. * @syntax and @description are multi-line with trailing EOL @@ -145,15 +129,14 @@ void cmd_help(const img_cmd_t *ccmd, { printf( "Usage:\n" -"\n" -" %s %s %s" +" %s %s %s\n" +"%s.\n" "\n" "Arguments:\n" " -h, --help\n" " print this help and exit\n" "%s\n", - "qemu-img", ccmd->name, - syntax, arguments); + "qemu-img", ccmd->name, syntax, ccmd->description, arguments); exit(EXIT_SUCCESS); } =20 @@ -168,114 +151,6 @@ static OutputFormat parse_output_format(const char *a= rgv0, const char *arg) } } =20 -/* Please keep in synch with docs/tools/qemu-img.rst */ -static G_NORETURN -void help(void) -{ - const char *help_msg =3D - QEMU_IMG_VERSION - "usage: qemu-img [standard options] command [command options]\n" - "QEMU disk image utility\n" - "\n" - " '-h', '--help' display this help and exit\n" - " '-V', '--version' output version information and exit\n" - " '-T', '--trace' [[enable=3D]][,events=3D][,file=3D]\n" - " specify tracing options\n" - "\n" - "Command syntax:\n" -#define DEF(option, callback, arg_string) \ - " " arg_string "\n" -#include "qemu-img-cmds.h" -#undef DEF - "\n" - "Command parameters:\n" - " 'filename' is a disk image filename\n" - " 'objectdef' is a QEMU user creatable object definition. See = the qemu(1)\n" - " manual page for a description of the object properties. Th= e most common\n" - " object type is a 'secret', which is used to supply passwor= ds and/or\n" - " encryption keys.\n" - " 'fmt' is the disk image format. It is guessed automatically = in most cases\n" - " 'cache' is the cache mode used to write the output disk imag= e, the valid\n" - " options are: 'none', 'writeback' (default, except for conv= ert), 'writethrough',\n" - " 'directsync' and 'unsafe' (default for convert)\n" - " 'src_cache' is the cache mode used to read input disk images= , the valid\n" - " options are the same as for the 'cache' option\n" - " 'size' is the disk image size in bytes. Optional suffixes\n" - " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (g= igabyte, 1024M),\n" - " 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exab= yte, 1024P) are\n" - " supported. 'b' is ignored.\n" - " 'output_filename' is the destination disk image filename\n" - " 'output_fmt' is the destination format\n" - " 'options' is a comma separated list of format specific optio= ns in a\n" - " name=3Dvalue format. Use -o help for an overview of the op= tions supported by\n" - " the used format\n" - " 'snapshot_param' is param used for internal snapshot, format= \n" - " is 'snapshot.id=3D[ID],snapshot.name=3D[NAME]', or\n" - " '[ID_OR_NAME]'\n" - " '-c' indicates that target image must be compressed (qcow fo= rmat only)\n" - " '-u' allows unsafe backing chains. For rebasing, it is assum= ed that old and\n" - " new backing file match exactly. The image doesn't need = a working\n" - " backing file before rebasing in this case (useful for r= enaming the\n" - " backing file). For image creation, allow creating witho= ut attempting\n" - " to open the backing file.\n" - " '-h' with or without a command shows this help and lists the= supported formats\n" - " '-p' show progress of command (only certain commands)\n" - " '-q' use Quiet mode - do not print any output (except errors= )\n" - " '-S' indicates the consecutive number of bytes (defaults to = 4k) that must\n" - " contain only zeros for qemu-img to create a sparse imag= e during\n" - " conversion. If the number of bytes is 0, the source wil= l not be scanned for\n" - " unallocated or zero sectors, and the destination image = will always be\n" - " fully allocated\n" - " '--output' takes the format in which the output must be done= (human or json)\n" - " '-n' skips the target volume creation (useful if the volume = is created\n" - " prior to running qemu-img)\n" - "\n" - "Parameters to bitmap subcommand:\n" - " 'bitmap' is the name of the bitmap to manipulate, through on= e or more\n" - " actions from '--add', '--remove', '--clear', '--enable'= , '--disable',\n" - " or '--merge source'\n" - " '-g granularity' sets the granularity for '--add' actions\n" - " '-b source' and '-F src_fmt' tell '--merge' actions to find = the source\n" - " bitmaps from an alternative file\n" - "\n" - "Parameters to check subcommand:\n" - " '-r' tries to repair any inconsistencies that are found duri= ng the check.\n" - " '-r leaks' repairs only cluster leaks, whereas '-r all'= fixes all\n" - " kinds of errors, with a higher risk of choosing the wro= ng fix or\n" - " hiding corruption that has already occurred.\n" - "\n" - "Parameters to convert subcommand:\n" - " '--bitmaps' copies all top-level persistent bitmaps to desti= nation\n" - " '-m' specifies how many coroutines work in parallel during t= he convert\n" - " process (defaults to 8)\n" - " '-W' allow to write to the target out of order rather than s= equential\n" - "\n" - "Parameters to snapshot subcommand:\n" - " 'snapshot' is the name of the snapshot to create, apply or d= elete\n" - " '-a' applies a snapshot (revert disk to saved state)\n" - " '-c' creates a snapshot\n" - " '-d' deletes a snapshot\n" - " '-l' lists all snapshots in the given image\n" - "\n" - "Parameters to compare subcommand:\n" - " '-f' first image format\n" - " '-F' second image format\n" - " '-s' run in Strict mode - fail on different image size or se= ctor allocation\n" - "\n" - "Parameters to dd subcommand:\n" - " 'bs=3DBYTES' read and write up to BYTES bytes at a time " - "(default: 512)\n" - " 'count=3DN' copy only N input blocks\n" - " 'if=3DFILE' read from FILE\n" - " 'of=3DFILE' write to FILE\n" - " 'skip=3DN' skip N bs-sized blocks at the start of input\n"; - - printf("%s\nSupported formats:", help_msg); - bdrv_iterate_format(format_print, NULL, false); - printf("\n\n" QEMU_HELP_BOTTOM "\n"); - exit(EXIT_SUCCESS); -} - /* * Is @list safe for accumulate_options()? * It is when multiple of them can be joined together separated by ','. @@ -5999,13 +5874,49 @@ out: } =20 static const img_cmd_t img_cmds[] =3D { -#define DEF(option, callback, arg_string) \ - { option, callback }, -#include "qemu-img-cmds.h" -#undef DEF + { "amend", img_amend, + "Update format-specific options of the image" }, + { "bench", img_bench, + "Run a simple image benchmark" }, + { "bitmap", img_bitmap, + "Perform modifications of the persistent bitmap in the image" }, + { "check", img_check, + "Check basic image integrity" }, + { "commit", img_commit, + "Commit image to its backing file" }, + { "compare", img_compare, + "Check if two images have the same contents" }, + { "convert", img_convert, + "Copy one or more images to another with optional format conversion"= }, + { "create", img_create, + "Create and format a new image file" }, + { "dd", img_dd, + "Copy input to output with optional format conversion" }, + { "info", img_info, + "Display information about the image" }, + { "map", img_map, + "Dump image metadata" }, + { "measure", img_measure, + "Calculate the file size required for a new image" }, + { "rebase", img_rebase, + "Change the backing file of the image" }, + { "resize", img_resize, + "Resize the image" }, + { "snapshot", img_snapshot, + "List or manipulate snapshots in the image" }, { NULL, NULL, }, }; =20 +static void format_print(void *opaque, const char *name) +{ + int *np =3D opaque; + if (*np + strlen(name) > 75) { + printf("\n "); + *np =3D 1; + } + *np +=3D printf(" %s", name); +} + int main(int argc, char **argv) { const img_cmd_t *cmd; @@ -6037,16 +5948,35 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); =20 - while ((c =3D getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != =3D -1) { + while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { switch (c) { - case ':': - missing_argument(argv[optind - 1]); - return 0; - case '?': - unrecognized_option(argv[optind - 1]); - return 0; case 'h': - help(); + printf( +QEMU_IMG_VERSION +"QEMU disk image utility. Usage:\n" +"\n" +" qemu-img [standard options] COMMAND [--help | command options]\n" +"\n" +"Standard options:\n" +" -h, --help\n" +" display this help and exit\n" +" -V, --version\n" +" display version info and exit\n" +" -T,--trace TRACE\n" +" specify tracing options:\n" +" [[enable=3D]][,events=3D][,file=3D]\n" +"\n" +"Recognized commands (run qemu-img COMMAND --help for command-specific hel= p):\n\n"); + for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { + printf(" %s - %s\n", cmd->name, cmd->description); + } + printf("\nSupported image formats:\n"); + c =3D 99; /* force a newline */ + bdrv_iterate_format(format_print, &c, false); + if (c) { + printf("\n"); + } + printf("\n" QEMU_HELP_BOTTOM "\n"); return 0; case 'V': printf(QEMU_IMG_VERSION); @@ -6054,6 +5984,8 @@ int main(int argc, char **argv) case 'T': trace_opt_parse(optarg); break; + default: + tryhelp(argv[0]); } } =20 --=20 2.50.1 From nobody Sat Nov 15 10:52:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752608094; cv=none; d=zohomail.com; s=zohoarc; b=eekTPrGuMsVf8XMjOo2qY29S1WWuZ7vGjypypIuGP3D0jaKjxXVWfQlpsCv3cLYWKBLPpnSl/ShDkA1FmE9dD1VmY43d/0JYPodwHZM2UeceCv2DO7RCNZr+YsHfwACtHuB+OyWck0B6db57Yb4OeuKRlf7o94UECFpDWxhkfSM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752608094; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1Qy9Tix5Uw1YpHnQdQLk8iYBh0aW/alhW9midwgBcck=; b=kJH/LyxT6jmcuAYY6aBNbfoTkRwTfEGFaCGSS60kq3z0EV6od93BsTnl7z3WB4C9XH4YKOVGpd1FN8IYYSeLmzT9UGnMJ/C9d2OKzfmSxf76Ah5k/VNsig28iBscI5+/KCjU1AZIwAMuXTjCHMxgDc7v3By7c47ujOkh+casDw8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752608094937795.2679595645844; Tue, 15 Jul 2025 12:34:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ublQA-0001Vf-6N; Tue, 15 Jul 2025 15:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyG-0004hn-JT for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ubkyE-0001oA-ET for qemu-devel@nongnu.org; Tue, 15 Jul 2025 15:05:44 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-304-ANPtvm_0OeiCn8WOrYHOEQ-1; Tue, 15 Jul 2025 15:05:38 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 775F31800BCB; Tue, 15 Jul 2025 19:05:37 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.44.34.84]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D47FB197702B; Tue, 15 Jul 2025 19:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752606341; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Qy9Tix5Uw1YpHnQdQLk8iYBh0aW/alhW9midwgBcck=; b=hTnm7LfV9mRREsMYC6fIM79amOjh57Npk8a41dnShkaTsNK1SgS8I4dSjkM7+SfBSdgm23 XUHMG7PlY92ifWLT/SqUCvsWrrMZICCIKsfMej8Dj46d5b2qMha4Evl5gvxxQNoZ37ufy3 ESzDxGKbl6PAwts3cchzU1+GHKndxMw= X-MC-Unique: ANPtvm_0OeiCn8WOrYHOEQ-1 X-Mimecast-MFC-AGG-ID: ANPtvm_0OeiCn8WOrYHOEQ_1752606337 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org Subject: [PULL 57/57] qemu-img: extend cvtnum() and use it in more places Date: Tue, 15 Jul 2025 21:03:30 +0200 Message-ID: <20250715190330.378764-58-kwolf@redhat.com> In-Reply-To: <20250715190330.378764-1-kwolf@redhat.com> References: <20250715190330.378764-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752608096226116600 From: Michael Tokarev cvtnum() expects input string to specify some sort of size (optionally with KMG... suffix). However, there are a lot of other number conversions in there (using qemu_strtol &Co), also, not all conversions which use cvtnum, actually expects size, - like dd count=3Dnn. Add bool is_size argument to cvtnum() to specify if it should treat the argument as a size or something else, - this changes conversion routine in use and error text. Use the new cvtnum() in more places (like where strtol were used), since it never return negative number in successful conversion. When it makes sense, also specify upper or lower bounds at the same time. This simplifies option processing in multiple places, removing the need of local temporary variables and longer error reporting code. While at it, fix errors, like depth in measure must be >=3D 1, while the previous code allowed it to be 0. In a few places, change unsigned variables (like of type size_t) to be signed instead, - to avoid the need of temporary conversion variable. All these variables are okay to be signed, we never assign <0 value to them except of the cases of conversion error, where we return immediately. While at it, remove allowed size suffixes from the error message as it makes no sense most of the time (should be in help instead). Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 Message-ID: <20250531171609.197078-28-mjt@tls.msk.ru> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qemu-img.c | 111 +++++++++++++------------------------ tests/qemu-iotests/049.out | 9 +-- 2 files changed, 40 insertions(+), 80 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b34b1390bb..7a162fdc08 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -398,18 +398,16 @@ static int add_old_style_options(const char *fmt, Qem= uOpts *opts, return 0; } =20 -static int64_t cvtnum_full(const char *name, const char *value, int64_t mi= n, - int64_t max) +static int64_t cvtnum_full(const char *name, const char *value, + bool is_size, int64_t min, int64_t max) { int err; uint64_t res; =20 - err =3D qemu_strtosz(value, NULL, &res); + err =3D is_size ? qemu_strtosz(value, NULL, &res) : + qemu_strtou64(value, NULL, 0, &res); if (err < 0 && err !=3D -ERANGE) { - error_report("Invalid %s specified. You may use " - "k, M, G, T, P or E suffixes for", name); - error_report("kilobytes, megabytes, gigabytes, terabytes, " - "petabytes and exabytes."); + error_report("Invalid %s specified: '%s'", name, value); return err; } if (err =3D=3D -ERANGE || res > max || res < min) { @@ -420,9 +418,9 @@ static int64_t cvtnum_full(const char *name, const char= *value, int64_t min, return res; } =20 -static int64_t cvtnum(const char *name, const char *value) +static int64_t cvtnum(const char *name, const char *value, bool is_size) { - return cvtnum_full(name, value, 0, INT64_MAX); + return cvtnum_full(name, value, is_size, 0, INT64_MAX); } =20 static int img_create(const img_cmd_t *ccmd, int argc, char **argv) @@ -525,7 +523,7 @@ static int img_create(const img_cmd_t *ccmd, int argc, = char **argv) =20 /* Get image size, if specified */ if (optind < argc) { - img_size =3D cvtnum("image size", argv[optind++]); + img_size =3D cvtnum("image size", argv[optind++], true); if (img_size < 0) { goto fail; } @@ -984,7 +982,7 @@ static int img_commit(const img_cmd_t *ccmd, int argc, = char **argv) drop =3D true; break; case 'r': - rate_limit =3D cvtnum("rate limit", optarg); + rate_limit =3D cvtnum("rate limit", optarg, true); if (rate_limit < 0) { return 1; } @@ -2428,7 +2426,7 @@ static int img_convert(const img_cmd_t *ccmd, int arg= c, char **argv) { int64_t sval; =20 - sval =3D cvtnum("buffer size for sparse output", optarg); + sval =3D cvtnum("buffer size for sparse output", optarg, true); if (sval < 0) { goto fail_getopt; } else if (!QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || @@ -2462,16 +2460,15 @@ static int img_convert(const img_cmd_t *ccmd, int a= rgc, char **argv) force_share =3D true; break; case 'r': - rate_limit =3D cvtnum("rate limit", optarg); + rate_limit =3D cvtnum("rate limit", optarg, true); if (rate_limit < 0) { goto fail_getopt; } break; case 'm': - if (qemu_strtol(optarg, NULL, 0, &s.num_coroutines) || - s.num_coroutines < 1 || s.num_coroutines > MAX_COROUTINES)= { - error_report("Invalid number of coroutines. Allowed number= of" - " coroutines is between 1 and %d", MAX_COROUT= INES); + s.num_coroutines =3D cvtnum_full("number of coroutines", optar= g, + false, 1, MAX_COROUTINES); + if (s.num_coroutines < 0) { goto fail_getopt; } break; @@ -3376,13 +3373,13 @@ static int img_map(const img_cmd_t *ccmd, int argc,= char **argv) image_opts =3D true; break; case 's': - start_offset =3D cvtnum("start offset", optarg); + start_offset =3D cvtnum("start offset", optarg, true); if (start_offset < 0) { return 1; } break; case 'l': - max_length =3D cvtnum("max length", optarg); + max_length =3D cvtnum("max length", optarg, true); if (max_length < 0) { return 1; } @@ -4720,9 +4717,9 @@ static int img_bench(const img_cmd_t *ccmd, int argc,= char **argv) int count =3D 75000; int depth =3D 64; int64_t offset =3D 0; - size_t bufsize =3D 4096; + ssize_t bufsize =3D 4096; int pattern =3D 0; - size_t step =3D 0; + ssize_t step =3D 0; int flush_interval =3D 0; bool drain_on_flush =3D true; int64_t image_size; @@ -4827,27 +4824,17 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) } break; case 'c': - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { - error_report("Invalid request count specified"); + count =3D cvtnum_full("request count", optarg, false, 1, INT_M= AX); + if (count < 0) { return 1; } - count =3D res; break; - } case 'd': - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) <=3D 0 || res > INT_MA= X) { - error_report("Invalid queue depth specified"); + depth =3D cvtnum_full("queue depth", optarg, false, 1, INT_MAX= ); + if (depth < 0) { return 1; } - depth =3D res; break; - } case 'n': flags |=3D BDRV_O_NATIVE_AIO; break; @@ -4860,64 +4847,40 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) } break; case 'o': - { - offset =3D cvtnum("offset", optarg); + offset =3D cvtnum("offset", optarg, true); if (offset < 0) { return 1; } break; - } - break; case 's': - { - int64_t sval; - - sval =3D cvtnum_full("buffer size", optarg, 0, INT_MAX); - if (sval < 0) { + bufsize =3D cvtnum_full("buffer size", optarg, true, 1, INT_MA= X); + if (bufsize < 0) { return 1; } - - bufsize =3D sval; break; - } case 'S': - { - int64_t sval; - - sval =3D cvtnum_full("step_size", optarg, 0, INT_MAX); - if (sval < 0) { + step =3D cvtnum_full("step size", optarg, true, 0, INT_MAX); + if (step < 0) { return 1; } - - step =3D sval; break; - } case 'w': flags |=3D BDRV_O_RDWR; is_write =3D true; break; case OPTION_PATTERN: - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > 0xff) { - error_report("Invalid pattern byte specified"); + pattern =3D cvtnum_full("pattern byte", optarg, false, 0, 0xff= ); + if (pattern < 0) { return 1; } - pattern =3D res; break; - } case OPTION_FLUSH_INTERVAL: - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { - error_report("Invalid flush interval specified"); + flush_interval =3D cvtnum_full("flush interval", optarg, + false, 0, INT_MAX); + if (flush_interval < 0) { return 1; } - flush_interval =3D res; break; - } case OPTION_NO_DRAIN: drain_on_flush =3D false; break; @@ -5129,7 +5092,7 @@ static int img_bitmap(const img_cmd_t *ccmd, int argc= , char **argv) add =3D true; break; case 'g': - granularity =3D cvtnum("granularity", optarg); + granularity =3D cvtnum("granularity", optarg, true); if (granularity < 0) { return 1; } @@ -5314,7 +5277,7 @@ static int img_dd_bs(const char *arg, { int64_t res; =20 - res =3D cvtnum_full("bs", arg, 1, INT_MAX); + res =3D cvtnum_full("bs", arg, true, 1, INT_MAX); =20 if (res < 0) { return 1; @@ -5328,7 +5291,7 @@ static int img_dd_count(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - dd->count =3D cvtnum("count", arg); + dd->count =3D cvtnum("count", arg, true); =20 if (dd->count < 0) { return 1; @@ -5359,7 +5322,7 @@ static int img_dd_skip(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - in->offset =3D cvtnum("skip", arg); + in->offset =3D cvtnum("skip", arg, true); =20 if (in->offset < 0) { return 1; @@ -5767,7 +5730,7 @@ static int img_measure(const img_cmd_t *ccmd, int arg= c, char **argv) user_creatable_process_cmdline(optarg); break; case 's': - img_size =3D cvtnum("image size", optarg); + img_size =3D cvtnum("image size", optarg, true); if (img_size < 0) { goto out; } diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index 34e1b452e6..70c627538b 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -98,8 +98,7 @@ qemu-img create -f qcow2 -o size=3D-1024 TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Value '-1024' is out of range for parameter 's= ize' =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1k -qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for -qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. +qemu-img: Invalid image size specified: '-1k' =20 qemu-img create -f qcow2 -o size=3D-1k TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number= below 2^64 @@ -107,8 +106,7 @@ Optional suffix k, M, G, T, P or E means kilo-, mega-, = giga-, tera-, peta- and exabytes, respectively. =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte -qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for -qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. +qemu-img: Invalid image size specified: '1kilobyte' =20 qemu-img create -f qcow2 -o size=3D1kilobyte TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number= below 2^64 @@ -116,8 +114,7 @@ Optional suffix k, M, G, T, P or E means kilo-, mega-, = giga-, tera-, peta- and exabytes, respectively. =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- foobar -qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suf= fixes for -qemu-img: kilobytes, megabytes, gigabytes, terabytes, petabytes and exabyt= es. +qemu-img: Invalid image size specified: 'foobar' =20 qemu-img create -f qcow2 -o size=3Dfoobar TEST_DIR/t.qcow2 qemu-img: TEST_DIR/t.qcow2: Parameter 'size' expects a non-negative number= below 2^64 --=20 2.50.1