From nobody Sat Dec 5 19:36:33 2026 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=ovhcloud.com ARC-Seal: i=1; a=rsa-sha256; t=1796037259; cv=none; d=zohomail.com; s=zohoarc; b=FUMiQ0p5X6egVTChEIYZobywp2kCNzjZvYHtONkG9Sdn40O+D8rhRw6KF7QiuvKEj+AQoBxFjGcvlFwYDG19LnAuxsPAl2jTxrVv8g/YSQU3FtI9eeBH8j+7N8vSG8fEbWQwWNUwLrQcpme56vQBTO97ne+E8+r95T3SnR1rvFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796037259; 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:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=+Ty5HDgbS8cRyKMuF7nkPsleyanMv0PcYuznceFpUqc=; b=adZBVsz9taSAZaurwgehOfc6AkyGBovTIuHZLVPNQVARL9Pj3DKtPQ3nFQU+2CEKE0g2Ll9qYI0sa1RjSH7pnwlvRSGPJKzaDuJkniP9NGA64vQQ5gmeXmEfN8k4miXIWzVr7fufqfTEA8lQCdMf6WPngWDAF0BtpSYySPeJ6NQ= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1796037259527786.6178829224788; Mon, 30 Nov 2026 03:14:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xXzKq-0001S0-Cc; Mon, 30 Nov 2026 06:14:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xXzKm-0001PB-Oz for qemu-devel@nongnu.org; Mon, 30 Nov 2026 06:14:13 -0500 Received: from 2.mo508.mail-out.ovh.net ([5.135.90.177]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xXzKj-0001UL-AB for qemu-devel@nongnu.org; Mon, 30 Nov 2026 06:14:12 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.0.169]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jdLxX4r4pz7tGl; Mon, 30 Nov 2026 11:13:52 +0000 (UTC) Received: from ovhcloud.com (109.190.254.61) by DAGFR11EX3.OVH.local (172.16.2.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 12:13:47 +0100 From: Guillaume Vincke To: CC: , Eric Blake , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Markus Armbruster , Guillaume Vincke Subject: [PATCH v3 1/2] nbd: Add an unstable query for the client state Date: Mon, 30 Nov 2026 12:13:26 +0100 Message-ID: <20261130111327.178850-2-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130111327.178850-1-guillaume.vincke@ovhcloud.com> References: <20261130111327.178850-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.61] X-ClientProxiedBy: CAS4.OVH.local (172.16.1.4) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 6516708662356820408 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTEto2/n9/fqQi/a47Aq9KAo+1M1PMHHly+Z7VPNYtddY/FdjEzCWzpm4BQwgkIj4rh72LKoRZxh1sfSBrx/r7a5ys03z0+8a4EnoOGwBUcgqohh3abCaUfsAOn7e70+6OzzDDnPWwZLq9rYeCVEBcJPN+k88WoVenefQ5iNbivzMKZuBDqWrJv2xTiIMeUu4zD0vAL1g09DUR96c9sRMrrag5WK4Xg0C7zeKL6pKWrf7Zq49X1IDEkz6mRWtNBwaJ09LiQRJmnSpQseklK+6vximmTnJEhFLKYCm5ShE/cQOXeMoI7Hf9pKX87vYisedO/IFIbmqpUp9aziHNfbsjD+ZcbAtxWIRm1aJFnFuCMsSNMfe6DmMEFYeqCueVCRvuRn9FXjj4gzEQsqCgXF+LvcoxWqkZ94HvWAMXFwYvmOCHPeYY1JDe3B7B1nWfKRrWIajOJwxKiNvI6SQaRpQf85kVDvGujCNQ7TGoGwa0otdSwd3ZJtKISKWmdF++A4KhidgVeIrIi5x4ymqGxyYcV6nXsmM5h6KFyUiaw+zzPgn9hpWwvwk+45dr3eU4Y/gzpYZF09OyBZHkcU7LxO09juOPMpkAN/m73wiE5xxGKNMl4sIBQK3FCE2hG/HxECPIDyboBFwfsPCoCFq2oRDffKu6wU8UXpiujFLa/shgOfUw DKIM-Signature: a=rsa-sha256; bh=+Ty5HDgbS8cRyKMuF7nkPsleyanMv0PcYuznceFpUqc=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1796037232; v=1; b=CsU8g7Jyr+r2qVQoHmpBlnTpJPDwgrl67KbmQkveDIf7kXmh5Bw2Xgowsll6w231wgOR9Faq 05DrvAUZbAC793GCw4ICtz4D4eF0q0o4mIr0GAmEFhB/2XEWJc2fnjZNFAkjJsvIZ5CzwUU7NR2 pEzbHQ9b0EG/HNUKaFScU+VE= 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=lists1p.gnu.org; Received-SPF: pass client-ip=5.135.90.177; envelope-from=guillaume.vincke@ovhcloud.com; helo=2.mo508.mail-out.ovh.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: guillaume.vincke@ovhcloud.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ovhcloud.com) X-ZM-MESSAGEID: 1796037263843158500 Content-Type: text/plain; charset="utf-8" At the moment, NBD client internals cannot be accessed. Therefore, tests have to infer the client state from I/O results and wait with sleeps, which is racy. Add the x-debug-query-nbd-client QMP command that reports the state of the client's connection and of its connector. Other fields will be added when needed. Signed-off-by: Guillaume Vincke Acked-by: Markus Armbruster --- qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++ include/block/nbd.h | 9 +++++ block/nbd.c | 57 +++++++++++++++++++++++++++ nbd/client-connection.c | 22 +++++++++++ 4 files changed, 175 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index 23c5787d99..0aa3ced3fe 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2217,6 +2217,93 @@ 'features': [ 'unstable' ], 'allow-preconfig': true } =20 +## +# @XDbgNbdClientState: +# An enumeration of NBD client states. +# +# @connecting-wait: No active connection. Reached when the client +# hits an I/O error. A request waits for the connection attempt +# to finish, while reconnect-delay has not expired. +# +# @connecting-nowait: No active connection. Reached when +# reconnect-delay expires. A request fails at once if no channel +# is ready. +# +# @connected: Client has a valid connection. Reached when a request +# gets a channel from the connector. +# +# @quit: Client stopped and will never reconnect. New requests +# fail. A running attempt or a parked channel stays until the +# node is closed. Reached on fatal error, teardown or yank. +# +# Since: 12.0 +## +{ 'enum': 'XDbgNbdClientState', + 'data': [ 'connecting-wait', 'connecting-nowait', 'connected', 'quit' ] } + +## +# @XDbgNbdClientConnectorState: +# An enumeration of NBD client connector states. +# +# @idle: No connection attempt running and no parked channel. In +# 'connecting-wait' or 'connecting-nowait', the next request +# starts an attempt. +# +# @running: Connection attempt is in progress. A request waits or +# fails, as described in 'connecting-wait' and +# 'connecting-nowait'. +# +# @parked: Connection was successful and channel is kept. The next +# request takes the channel and the client goes to 'connected'. +# +# Since: 12.0 +## +{ 'enum': 'XDbgNbdClientConnectorState', + 'data': [ 'idle', 'running', 'parked' ] } + +## +# @XDbgNbdClientConnector: +# The NBD connector information. +# +# @state: State of the connector. +# +# Since: 12.0 +## +{ 'struct': 'XDbgNbdClientConnector', + 'data': { 'state': 'XDbgNbdClientConnectorState' } } + +## +# @XDbgNbdClient: +# The NBD connection state of the client and its connector. +# +# @state: The client state. +# +# @connector: The connector details. +# +# Since: 12.0 +## +{ 'struct': 'XDbgNbdClient', + 'data': { 'state': 'XDbgNbdClientState', + 'connector': 'XDbgNbdClientConnector' } } + +## +# @x-debug-query-nbd-client: +# Get the NBD client state. +# +# @node-name: node name of a block node using the nbd driver. +# Use `query-named-block-nodes` to list block nodes. +# +# Features: +# +# @unstable: This command is meant for debugging and testing. +# +# Since: 12.0 +## +{ 'command': 'x-debug-query-nbd-client', + 'data': { 'node-name': 'str' }, + 'returns': 'XDbgNbdClient', + 'features': [ 'unstable' ] } + ## # @drive-mirror: # Start mirroring a block device's writes to a new destination. diff --git a/include/block/nbd.h b/include/block/nbd.h index ab40842da9..15ddec91ac 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -492,6 +492,15 @@ const char *nbd_mode_lookup(NBDMode mode); /* nbd/client-connection.c */ void nbd_client_connection_enable_retry(NBDClientConnection *conn); =20 +typedef enum NBDClientConnectionThreadState { + NBD_CLIENT_CONNECTION_THREAD_IDLE, + NBD_CLIENT_CONNECTION_THREAD_RUNNING, + NBD_CLIENT_CONNECTION_THREAD_PARKED, +} NBDClientConnectionThreadState; + +NBDClientConnectionThreadState +nbd_client_connection_get_thread_state(NBDClientConnection *conn); + NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr, bool do_negotiation, const char *export_name, diff --git a/block/nbd.c b/block/nbd.c index fb4295bb23..93d84e2a47 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -35,9 +35,11 @@ #include "qemu/cutils.h" #include "qemu/main-loop.h" =20 +#include "qapi/qapi-commands-block-core.h" #include "qapi/qapi-visit-sockets.h" #include "qobject/qstring.h" #include "qapi/clone-visitor.h" +#include "qapi/error.h" =20 #include "block/qdict.h" #include "block/nbd.h" @@ -2305,6 +2307,61 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, }; =20 +XDbgNbdClient *qmp_x_debug_query_nbd_client(const char *node_name, + Error **errp) +{ + BlockDriverState *bs; + BDRVNBDState *s; + XDbgNbdClient *info; + + bs =3D bdrv_find_node(node_name); + if (!bs) { + error_setg(errp, "Node '%s' not found", node_name); + return NULL; + } + + if (bs->drv !=3D &bdrv_nbd && + bs->drv !=3D &bdrv_nbd_tcp && + bs->drv !=3D &bdrv_nbd_unix) { + error_setg(errp, "Node '%s' is not an NBD client", node_name); + return NULL; + } + + s =3D bs->opaque; + info =3D g_new0(XDbgNbdClient, 1); + WITH_QEMU_LOCK_GUARD(&s->requests_lock) { + switch (s->state) { + case NBD_CLIENT_CONNECTING_WAIT: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTING_WAIT; + break; + case NBD_CLIENT_CONNECTING_NOWAIT: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTING_NOWAIT; + break; + case NBD_CLIENT_CONNECTED: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTED; + break; + case NBD_CLIENT_QUIT: + info->state =3D XDBG_NBD_CLIENT_STATE_QUIT; + break; + } + + info->connector =3D g_new0(XDbgNbdClientConnector, 1); + switch (nbd_client_connection_get_thread_state(s->conn)) { + case NBD_CLIENT_CONNECTION_THREAD_IDLE: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_IDL= E; + break; + case NBD_CLIENT_CONNECTION_THREAD_RUNNING: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_RUN= NING; + break; + case NBD_CLIENT_CONNECTION_THREAD_PARKED: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_PAR= KED; + break; + } + } + + return info; +} + static void bdrv_nbd_init(void) { bdrv_register(&bdrv_nbd); diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 6a4f080717..580ebe160b 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -42,6 +42,10 @@ struct NBDClientConnection { bool do_negotiation; bool do_retry; =20 + /* + * @mutex is taken under BDRVNBDState.requests_lock. Calling back into= the + * block driver with it held is unsafe. + */ QemuMutex mutex; =20 NBDExportInfo updated_info; @@ -78,6 +82,24 @@ void nbd_client_connection_enable_retry(NBDClientConnect= ion *conn) conn->do_retry =3D true; } =20 +NBDClientConnectionThreadState +nbd_client_connection_get_thread_state(NBDClientConnection *conn) +{ + NBDClientConnectionThreadState ret; + + WITH_QEMU_LOCK_GUARD(&conn->mutex) { + if (conn->running) { + ret =3D NBD_CLIENT_CONNECTION_THREAD_RUNNING; + } else if (conn->sioc) { + ret =3D NBD_CLIENT_CONNECTION_THREAD_PARKED; + } else { + ret =3D NBD_CLIENT_CONNECTION_THREAD_IDLE; + } + } + + return ret; +} + NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr, bool do_negotiation, const char *export_name, --=20 2.43.0 From nobody Sat Dec 5 19:36:33 2026 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=ovhcloud.com ARC-Seal: i=1; a=rsa-sha256; t=1796037295; cv=none; d=zohomail.com; s=zohoarc; b=dC46QNQba+yY9dcVktFz5355TxZRtF4jFDqVdv4xRrU2MPHx5clRJsmPy2G+Y7UMyLNvYTyOQHffDv2GTw3iW9LUGd4KFRUcE8zQBjwi9AkYn6vaJ3aiJWMPWheSMp/YPvQHIS5i1oaOh+cpUGnXDJ139M7508n4eVwjZDDLYzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796037295; 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:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=Og1oRrreHIMepEq/06sCuClqKQRAWacCwmJc8yk4G9I=; b=TDQ4FUk93SM4w9s6am5VgROA9el+j0Xo2BCXBk6fVS2htyxp90DhawwXpx/wSEKTLGcvAVGnajQI9D6IV37va3AjzNVVDPrwKq5N4uKfwpjQLlcl+Ax0fiOAIVAk5z3ZZtK5/BcTA+bLM3RWPvR08SNv7j3hXgHVTs7gCCZWL00= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1796037295108580.7973949489055; Mon, 30 Nov 2026 03:14:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xXzKq-0001S9-SH; Mon, 30 Nov 2026 06:14:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xXzKl-0001Oy-4e for qemu-devel@nongnu.org; Mon, 30 Nov 2026 06:14:11 -0500 Received: from 1.mo508.mail-out.ovh.net ([5.135.90.176]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xXzKj-0001Vf-4V for qemu-devel@nongnu.org; Mon, 30 Nov 2026 06:14:10 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.0.169]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jdLxX6k5cz7tGm; Mon, 30 Nov 2026 11:13:52 +0000 (UTC) Received: from ovhcloud.com (109.190.254.61) by DAGFR11EX3.OVH.local (172.16.2.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 12:13:48 +0100 From: Guillaume Vincke To: CC: , Eric Blake , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Markus Armbruster , Guillaume Vincke Subject: [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Date: Mon, 30 Nov 2026 12:13:27 +0100 Message-ID: <20261130111327.178850-3-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130111327.178850-1-guillaume.vincke@ovhcloud.com> References: <20261130111327.178850-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.61] X-ClientProxiedBy: CAS4.OVH.local (172.16.1.4) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 6516990136056234424 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTEto2/n9/fqQi/a47Aq9KAo+1M1PMHHly+Z7VPNYtddY/FdjEzCWzpm4BQwgkIj4rh72LKoRZxh1sfSBrx/r7a5ys03z0+8a4EnoOGwBUcgqohh3abCaUfsAOn7e70+6OzzDDnPWwZLq9rYeCVEBcJPN+k88WoVenefQ5iNbivzMKZuBDqWrJv2xTiIMeUu4zD0vAL1g09DUR96c9sRMrrag5WK4Xg0C7zeKL6pKWrf7Zq49X1IDEkz6mRWtNBwaJ09LiQRJmnSpQseklK+6vximmTnJEhFLKYCm5ShE/cQOXeMoI7Hf9pKX87vYisedO/IFIbmqpUp9aziHNfbsjD+pVSpi0GylEO4lJ04ijRxR+UcZiYb8dGh5zypwkgpZsKxxlF1Dn1lFjQa+ZfdTvjzG9IBXBuRyIBZjjH9SX6/Em3BC4nG4YEC1owg2oGu3GKH/0q6BvxK9e8+3Iov0vOc3wS20djoRcGtUZF3IajZBbgd4CZnBL5Fxb+XmRo+xEbVvgmVt5XHLPdpz6TjOxU1G2Y2c0xHnJEvzx5GZKq5EVY3+ZBAW90AdiKi/Ydbf6vWUUFXuktxsO0JwMgU8mmN1wzvWTiNLvFlHGYpasa1CafNhd1D9ZE6QmbahnJFPw5IfVp1PCCY9wT5jt9LUqSh1CsUoYl9dnX8rZ3Z4wV+/g DKIM-Signature: a=rsa-sha256; bh=Og1oRrreHIMepEq/06sCuClqKQRAWacCwmJc8yk4G9I=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1796037233; v=1; b=sxUkc9C14ELlnV4dBeCjK60nBYti5lIsflfqe6anH6pDUdJ7I2i8QfXqaztH0EjheMCrrUYz h5NuD4VlKtS2K8j6KAaVIi6BbgR1NXEKvDRZtzaP0uyVjxUAGaAprwL/ZCpulOHKvq10BPBG9Ty gicnUbHQX0g3eCpaa6GZemwc= 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=lists1p.gnu.org; Received-SPF: pass client-ip=5.135.90.176; envelope-from=guillaume.vincke@ovhcloud.com; helo=1.mo508.mail-out.ovh.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: guillaume.vincke@ovhcloud.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ovhcloud.com) X-ZM-MESSAGEID: 1796037297504158500 Content-Type: text/plain; charset="utf-8" Check that running it on a nonexistent or non-nbd node fails. Also check each state reached when the server restarts. Running x-qemu-io on a bare node would drain its temporary BlockBackend, which blocks until the request completes and hides connecting-wait. We force the I/O to go through a device to avoid this issue. Signed-off-by: Guillaume Vincke Reviewed-by: Eric Blake Tested-by: Eric Blake --- tests/qemu-iotests/tests/nbd-client-query | 73 +++++++++++++++++++ tests/qemu-iotests/tests/nbd-client-query.out | 13 ++++ 2 files changed, 86 insertions(+) create mode 100755 tests/qemu-iotests/tests/nbd-client-query create mode 100644 tests/qemu-iotests/tests/nbd-client-query.out diff --git a/tests/qemu-iotests/tests/nbd-client-query b/tests/qemu-iotests= /tests/nbd-client-query new file mode 100755 index 0000000000..bdd4d95d72 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-client-query @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +# group: rw auto quick +# +# Test the x-debug-query-nbd-client QMP command +# +# Copyright (C) 2026 OVHcloud +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import time +import iotests + + +iotests.script_initialize(supported_fmts=3D['qcow2']) +nbd_sock =3D iotests.file_path('nbd-sock', base_dir=3Diotests.sock_dir) +disk =3D iotests.file_path('disk') +iotests.qemu_img_create('-f', iotests.imgfmt, disk, '1M') +node_name =3D 'nbd0' + + +def wait_for_state(virtm, state, connector_state): + with iotests.Timeout(30, f"did not reach {state}/{connector_state}"): + while True: + resp =3D virtm.qmp('x-debug-query-nbd-client', node_name=3Dnod= e_name) + resp_st =3D resp['return']['state'] + resp_conn_st =3D resp['return']['connector']['state'] + if resp_st =3D=3D state and resp_conn_st =3D=3D connector_stat= e: + break + time.sleep(0.1) + iotests.log(resp) + + +with iotests.VM() as vm: + vm.add_device('virtio-scsi,id=3Dscsi0') + vm.launch() + + # error when the node does not exist + iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=3Dnode_name)) + + # error when the node is not an nbd client + vm.cmd('blockdev-add', driver=3D'null-co', node_name=3D'null0') + iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=3D'null0')) + + # start the server + with iotests.qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk= ): + # add a nbd node + vm.cmd('blockdev-add', { + 'driver': 'nbd', + 'node-name': 'nbd0', + 'server': {'type': 'unix', 'path': nbd_sock}, + 'reconnect-delay': 2, + }) + vm.cmd('device_add', driver=3D'scsi-hd', drive=3D'nbd0', id=3D'dev= 0') + # the client is connected + iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=3Dnode_na= me)) + + # server is down. An IO moves it to the connecting-wait state + iotests.log( + vm.qmp('x-qemu-io', qdev=3D'dev0', command=3D'aio_write -P 0x5a 0 = 64k')) + wait_for_state(vm, 'connecting-wait', 'running') + + # when reconnect delay is reached, we get to connecting-nowait + wait_for_state(vm, 'connecting-nowait', 'running') + + # restart the server + with iotests.qemu_nbd_popen('-k', nbd_sock, '-f', iotests.imgfmt, disk= ): + # the connector gets to the parked state + wait_for_state(vm, 'connecting-nowait', 'parked') + + # new request is successful and the client is back in connected + iotests.log( + vm.qmp('x-qemu-io', qdev=3D'dev0', command=3D'write -P 0x5a 0 = 64k')) + iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=3Dnode_na= me)) diff --git a/tests/qemu-iotests/tests/nbd-client-query.out b/tests/qemu-iot= ests/tests/nbd-client-query.out new file mode 100644 index 0000000000..188078676e --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-client-query.out @@ -0,0 +1,13 @@ +{"error": {"class": "GenericError", "desc": "Node 'nbd0' not found"}} +{"error": {"class": "GenericError", "desc": "Node 'null0' is not an NBD cl= ient"}} +Start NBD server +{"return": {"connector": {"state": "idle"}, "state": "connected"}} +Kill NBD server +{"return": {}} +{"return": {"connector": {"state": "running"}, "state": "connecting-wait"}} +{"return": {"connector": {"state": "running"}, "state": "connecting-nowait= "}} +Start NBD server +{"return": {"connector": {"state": "parked"}, "state": "connecting-nowait"= }} +{"return": {}} +{"return": {"connector": {"state": "idle"}, "state": "connected"}} +Kill NBD server --=20 2.43.0