From nobody Sat Dec 5 19:46: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=1796300517; cv=none; d=zohomail.com; s=zohoarc; b=beNgIIwmjQYEY8OyvsHuCWt1W+mvSYAykNaf6S3CkqJmxkCCdGUP9t5aSU+AzSmWDYN8w55xCLkj9OqBbDgq5xTK/K/xm81CKEpVQbnz+d5sxnHS4SWN7hNxvJa/F3ap1QuZqZmgrdTHSOK3pZEwRu68opOT6Fw0qgLgfGmhFNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796300517; 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=N14VBHoL+eKtaSw+idQtm4Jum9rRbzIdoW6fQbhgnHo=; b=bkmxhADk0tT9+1AgS5Yh8mHuHuxrF0CddayoaVbueq1SVP2sjaOtODolJ1vMrXUp8HV9QObWrlqUzVAGWX0cF2gsgrLXeYDwnYVuMd+eaROcUoTZ2Om7SI/b1s4LUwj7nnnENzKokBtDB8D3V4FZ1WADBK6HvCvRUJC7rIgMGmU= 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 1796300517681402.9802829138763; Thu, 3 Dec 2026 04:21:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZ5oZ-0008Eh-O8; Thu, 03 Dec 2026 07:21:31 -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 1xZ5oX-00089s-Mm for qemu-devel@nongnu.org; Thu, 03 Dec 2026 07:21:29 -0500 Received: from 2.mo15.mail-out.ovh.net ([5.135.90.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZ5oU-00065b-HL for qemu-devel@nongnu.org; Thu, 03 Dec 2026 07:21:29 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.54.78]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jgDHt4Ph8z3xg3; Thu, 3 Dec 2026 12:21:14 +0000 (UTC) Received: from ovhcloud.com (109.190.254.5) 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; Thu, 3 Dec 2026 13:21:13 +0100 From: Guillaume Vincke To: CC: , Eric Blake , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Markus Armbruster , Guillaume Vincke Subject: [PATCH v4 1/2] nbd: Add an unstable query for the client state Date: Thu, 3 Dec 2026 13:20:54 +0100 Message-ID: <20261203122055.134148-2-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203122055.134148-1-guillaume.vincke@ovhcloud.com> References: <20261203122055.134148-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.5] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 6825768185579323832 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTEq69cDspz7zuhH0FURZWXz6atqakHey8PophP8M2DiIlvZ4H+96a5ELjwWZUdwBNiQAgv50Rb+1KnwqqQ6dZ3/JsGrQj/F+t0QzcNdfzRm/gmVmdJ10bFSthYwPK/q0HAe+qy7+VlaJynKsTYtDl/jZ16ZYfRItYPkYoRLK3OmXA8KilnRB7jHCx9wLhZUWbVDEi3ZisBJXi1uRRWPLE3x1uZpxNXmLfbvCFuHmmWZ/0R7b66SxiyrQLwV3Kpq8/TkDLr7heyJiNLTsJdZICd92s9PVh0ADl4q4cDi61Nxia051oWO60Q7AxeZew84lDp2BSFIBmMyMZFXS1ZcW927IIcQbV9aE/H+NaMtIqRUrRCmNrC72kPSSM5XKdspC2nqr7n0Cc3vahbaelMqvvvPdL0YUrSc1Dx0d3HcPcuQKuOgrUX4zeFjokBecigBaanwmTV6qZGpFqEMVBWiozryFkZEe1uPLJnhfePyDTymbb+qxIJhS00kpKpCP8BmTDkytpmERgY8XREYFVKBu4iGYp6Px7sJyC/a6dIeuQn0e0K7mDJI+GMlewhSCb/6nhI65/vxb6YOgyiaKKas5iKyGZw7ZQKEgC7qUixoem1ndZzkOCsNv7FzOemz00RQyaXeNWXOAyetokQSPvaAjwbmQzgp2FGOiIL0T/rs4v0zUQ DKIM-Signature: a=rsa-sha256; bh=N14VBHoL+eKtaSw+idQtm4Jum9rRbzIdoW6fQbhgnHo=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1796300474; v=1; b=mRVhKXYByovGPgIN4LQxSv50RypMYLmHJivj4AWS7/ddTuSVFypOjqc7KUiWL99PNxB04a4H 1YR25sRnny1qYX4dcVaYML/m5nrgT1UETKfVfv/RGMBSk+1blNMrOO7NFiyhMJVaGLZaAqeUJf5 EGbe4NlyDJ54eT1hC5cTyZHo= 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.179; envelope-from=guillaume.vincke@ovhcloud.com; helo=2.mo15.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: 1796300521424158500 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 | 4 ++ block/nbd.c | 84 +++++++++++++++++++++++++-------------- nbd/client-connection.c | 22 +++++++++++ 4 files changed, 168 insertions(+), 29 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 7aa4fa2df9..be5d120071 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2217,6 +2217,93 @@ 'features': [ 'unstable' ], 'allow-preconfig': true } =20 +## +# @NbdClientState: +# 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': 'NbdClientState', + 'data': [ 'connecting-wait', 'connecting-nowait', 'connected', 'quit' ] } + +## +# @NbdClientConnectorState: +# 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': 'NbdClientConnectorState', + 'data': [ 'idle', 'running', 'parked' ] } + +## +# @XDbgNbdClientConnector: +# The NBD connector information. +# +# @state: State of the connector. +# +# Since: 12.0 +## +{ 'struct': 'XDbgNbdClientConnector', + 'data': { 'state': 'NbdClientConnectorState' } } + +## +# @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': 'NbdClientState', + '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..b7a1a8ebbe 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -23,6 +23,7 @@ #include "block/export.h" #include "io/channel-socket.h" #include "crypto/tlscreds.h" +#include "qapi/qapi-types-block-core.h" #include "qapi/error.h" #include "qemu/bswap.h" =20 @@ -492,6 +493,9 @@ const char *nbd_mode_lookup(NBDMode mode); /* nbd/client-connection.c */ void nbd_client_connection_enable_retry(NBDClientConnection *conn); =20 +NbdClientConnectorState +nbd_client_get_connector_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..01f27db726 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" @@ -58,13 +60,6 @@ typedef struct { bool receiving; /* sleeping in the yield in nbd_receive_replie= s */ } NBDClientRequest; =20 -typedef enum NBDClientState { - NBD_CLIENT_CONNECTING_WAIT, - NBD_CLIENT_CONNECTING_NOWAIT, - NBD_CLIENT_CONNECTED, - NBD_CLIENT_QUIT -} NBDClientState; - typedef struct BDRVNBDState { QIOChannel *ioc; /* The current I/O channel */ NBDExportInfo info; @@ -74,7 +69,7 @@ typedef struct BDRVNBDState { * reconnect_delay_timer. */ QemuMutex requests_lock; - NBDClientState state; + NbdClientState state; CoQueue free_sema; unsigned in_flight; NBDClientRequest requests[MAX_NBD_REQUESTS]; @@ -176,17 +171,17 @@ static void coroutine_fn nbd_recv_coroutines_wake(BDR= VNBDState *s) /* Called with s->requests_lock held. */ static void coroutine_fn nbd_channel_error_locked(BDRVNBDState *s, int ret) { - if (s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (s->state =3D=3D NBD_CLIENT_STATE_CONNECTED) { qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); } =20 if (ret =3D=3D -EIO) { - if (s->state =3D=3D NBD_CLIENT_CONNECTED) { - s->state =3D s->reconnect_delay ? NBD_CLIENT_CONNECTING_WAIT : - NBD_CLIENT_CONNECTING_NOWAIT; + if (s->state =3D=3D NBD_CLIENT_STATE_CONNECTED) { + s->state =3D s->reconnect_delay ? NBD_CLIENT_STATE_CONNECTING_= WAIT : + NBD_CLIENT_STATE_CONNECTING_NO= WAIT; } } else { - s->state =3D NBD_CLIENT_QUIT; + s->state =3D NBD_CLIENT_STATE_QUIT; } } =20 @@ -210,10 +205,10 @@ static void reconnect_delay_timer_cb(void *opaque) =20 reconnect_delay_timer_del(s); WITH_QEMU_LOCK_GUARD(&s->requests_lock) { - if (s->state !=3D NBD_CLIENT_CONNECTING_WAIT) { + if (s->state !=3D NBD_CLIENT_STATE_CONNECTING_WAIT) { return; } - s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; + s->state =3D NBD_CLIENT_STATE_CONNECTING_NOWAIT; } nbd_co_establish_connection_cancel(s->conn); } @@ -243,7 +238,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) } =20 WITH_QEMU_LOCK_GUARD(&s->requests_lock) { - s->state =3D NBD_CLIENT_QUIT; + s->state =3D NBD_CLIENT_STATE_QUIT; } } =20 @@ -279,7 +274,7 @@ static bool nbd_client_will_reconnect(BDRVNBDState *s) * Called only after a socket error, so this is not performance sensit= ive. */ QEMU_LOCK_GUARD(&s->requests_lock); - return s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT; + return s->state =3D=3D NBD_CLIENT_STATE_CONNECTING_WAIT; } =20 /* @@ -371,7 +366,7 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, =20 /* successfully connected */ WITH_QEMU_LOCK_GUARD(&s->requests_lock) { - s->state =3D NBD_CLIENT_CONNECTED; + s->state =3D NBD_CLIENT_STATE_CONNECTED; } =20 return 0; @@ -380,15 +375,15 @@ int coroutine_fn nbd_co_do_establish_connection(Block= DriverState *bs, /* Called with s->requests_lock held. */ static bool nbd_client_connecting(BDRVNBDState *s) { - return s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT || - s->state =3D=3D NBD_CLIENT_CONNECTING_NOWAIT; + return s->state =3D=3D NBD_CLIENT_STATE_CONNECTING_WAIT || + s->state =3D=3D NBD_CLIENT_STATE_CONNECTING_NOWAIT; } =20 /* Called with s->requests_lock taken. */ static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_attempt(BDRVNBDState *= s) { int ret; - bool blocking =3D s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT; + bool blocking =3D s->state =3D=3D NBD_CLIENT_STATE_CONNECTING_WAIT; =20 /* * Now we are sure that nobody is accessing the channel, and no one wi= ll @@ -402,7 +397,7 @@ static void coroutine_fn GRAPH_RDLOCK nbd_reconnect_att= empt(BDRVNBDState *s) if (blocking && !s->reconnect_delay_timer) { /* * It's the first reconnect attempt after switching to - * NBD_CLIENT_CONNECTING_WAIT + * NBD_CLIENT_STATE_CONNECTING_WAIT */ g_assert(s->reconnect_delay); reconnect_delay_timer_init(s, @@ -517,17 +512,17 @@ nbd_co_send_request(BlockDriverState *bs, NBDRequest = *request, =20 qemu_mutex_lock(&s->requests_lock); while (s->in_flight =3D=3D MAX_NBD_REQUESTS || - (s->state !=3D NBD_CLIENT_CONNECTED && s->in_flight > 0)) { + (s->state !=3D NBD_CLIENT_STATE_CONNECTED && s->in_flight > 0))= { qemu_co_queue_wait(&s->free_sema, &s->requests_lock); } =20 s->in_flight++; - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (s->state !=3D NBD_CLIENT_STATE_CONNECTED) { if (nbd_client_connecting(s)) { nbd_reconnect_attempt(s); qemu_co_queue_restart_all(&s->free_sema); } - if (s->state !=3D NBD_CLIENT_CONNECTED) { + if (s->state !=3D NBD_CLIENT_STATE_CONNECTED) { rc =3D -EIO; goto err; } @@ -1573,7 +1568,7 @@ static void nbd_yank(void *opaque) =20 QEMU_LOCK_GUARD(&s->requests_lock); qio_channel_shutdown(s->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); - s->state =3D NBD_CLIENT_QUIT; + s->state =3D NBD_CLIENT_STATE_QUIT; } =20 static void nbd_client_close(BlockDriverState *bs) @@ -2016,7 +2011,7 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, s->open_timeout * NANOSECONDS_PER_SECOND); } =20 - s->state =3D NBD_CLIENT_CONNECTING_WAIT; + s->state =3D NBD_CLIENT_STATE_CONNECTING_WAIT; ret =3D nbd_do_establish_connection(bs, true, errp); if (ret < 0) { goto fail; @@ -2185,8 +2180,8 @@ static void nbd_cancel_in_flight(BlockDriverState *bs) reconnect_delay_timer_del(s); =20 qemu_mutex_lock(&s->requests_lock); - if (s->state =3D=3D NBD_CLIENT_CONNECTING_WAIT) { - s->state =3D NBD_CLIENT_CONNECTING_NOWAIT; + if (s->state =3D=3D NBD_CLIENT_STATE_CONNECTING_WAIT) { + s->state =3D NBD_CLIENT_STATE_CONNECTING_NOWAIT; } qemu_mutex_unlock(&s->requests_lock); =20 @@ -2305,6 +2300,37 @@ 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) { + info->state =3D s->state; + info->connector =3D g_new0(XDbgNbdClientConnector, 1); + info->connector->state =3D nbd_client_get_connector_state(s->conn); + } + + 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..231164766e 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 +NbdClientConnectorState +nbd_client_get_connector_state(NBDClientConnection *conn) +{ + NbdClientConnectorState ret; + + WITH_QEMU_LOCK_GUARD(&conn->mutex) { + if (conn->running) { + ret =3D NBD_CLIENT_CONNECTOR_STATE_RUNNING; + } else if (conn->sioc) { + ret =3D NBD_CLIENT_CONNECTOR_STATE_PARKED; + } else { + ret =3D NBD_CLIENT_CONNECTOR_STATE_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:46: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=1796300518; cv=none; d=zohomail.com; s=zohoarc; b=TkONch++LbBnUwsaDuaMG/24hqConskIOWKT3s3Up2Kv4vykoTIi70ffrIIvhUN3Ns961kt7R2exATfm6ECrRVCOcECgQmRnXQgMMdpoCpblEdeyC7K4nR6hbQkmF49TeqA+ae0M2YtLC/arkXe+Phk64qMo4xICBMKERZaQw/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796300518; 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=a/z/7O19/IIs9+RHeZbLb8m+iLFrM4hJ8R9zGCuRHmA=; b=KmyDgj07V2gJA932QoYV8sGRGaPVjyuVikqI1+GsfyCEr5ru74dxZ1Hc3dRtDmSY8gAlVMKTPu6JoJW/TDSUt1wGxBSfMaCr0vRlSNhVtnhhUuXBguVl6zJnjgPF2JqZGwN+uccFqrVWieJ8lddzKlNcEybmSfJaDjsY/98KByI= 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 1796300517800393.3389330437543; Thu, 3 Dec 2026 04:21:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZ5ob-0008Fy-8C; Thu, 03 Dec 2026 07:21:33 -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 1xZ5oY-0008Ap-Id for qemu-devel@nongnu.org; Thu, 03 Dec 2026 07:21:30 -0500 Received: from 2.mo15.mail-out.ovh.net ([5.135.90.179]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZ5oU-00066u-VQ for qemu-devel@nongnu.org; Thu, 03 Dec 2026 07:21:30 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.54.78]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jgDHt71bMz3xgC; Thu, 3 Dec 2026 12:21:14 +0000 (UTC) Received: from ovhcloud.com (109.190.254.5) 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; Thu, 3 Dec 2026 13:21:14 +0100 From: Guillaume Vincke To: CC: , Eric Blake , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Markus Armbruster , Guillaume Vincke Subject: [PATCH v4 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Date: Thu, 3 Dec 2026 13:20:55 +0100 Message-ID: <20261203122055.134148-3-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203122055.134148-1-guillaume.vincke@ovhcloud.com> References: <20261203122055.134148-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.5] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 6826049662360830392 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTEq69cDspz7zuhH0FURZWXz6atqakHey8PophP8M2DiIlvZ4H+96a5ELjwWZUdwBNiQAgv50Rb+1KnwqqQ6dZ3/JsGrQj/F+t0QzcNdfzRm/gmVmdJ10bFSthYwPK/q0HAe+qy7+VlaJynKsTYtDl/jZ16ZYfRItYPkYoRLK3OmXA8KilnRB7jHCx9wLhZUWbVDEi3ZisBJXi1uRRWPLE3x1uZpxNXmLfbvCFuHmmWZ/0R7b66SxiyrQLwV3Kpq8/TkDLr7heyJiNLTsJdZICd92s9PVh0ADl4q4cDi61Nxia051oWO60Q7AxeZew84lDp2BSFIBmMyMZFXS1ZcW927RM9V3Ib/9WMDlq+Vo06fkP/emXxWLRPVv9v3NQXkdOSEWjD/lz9Dyzrm3En2HuzCkN6nJ83UKwFytaoR3BAHAiuDRJlE2+stpSc8CVvMJMMEBZCWxxYEMLKZPMzyUf2IcG52qi3HN9erWWOHyvUlF4W6Fwi38HXQiDMh42Qa/YYk3vE+dpUWYPUZogbFIsT7y3S8FgxhJC64gF3jPMAb7QqoXHgwOVHIBsLhtwmFe/DDTVAyr+DJeJjlZkB73QzM/6F/PUlBS8DJ3bJTF/wv3jMEmKuSPbETUgM1GMBjOCMIXTQl6oNcbIu9kwVCWBhtM+lsQmqx60Ndy8VCluvt0Q DKIM-Signature: a=rsa-sha256; bh=a/z/7O19/IIs9+RHeZbLb8m+iLFrM4hJ8R9zGCuRHmA=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1796300475; v=1; b=BjXjerxZVb71og+MQieoE4cMVyEnqLBHsRB6fsliXuYWch/ISP2hqIRhn8eAfRzvux3stXxk ptO75/o6+Oe1n20impZAr814xlazZa7bMJL0QOJY6c0I0Tdrm56oydpynWpZRukSR30L++/ZXnz L8Eu4zDiKbjs3OxbX4iAfAwI= 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.179; envelope-from=guillaume.vincke@ovhcloud.com; helo=2.mo15.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: 1796300521414158500 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 | 78 +++++++++++++++++++ tests/qemu-iotests/tests/nbd-client-query.out | 15 ++++ 2 files changed, 93 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..1cc2be7404 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-client-query @@ -0,0 +1,78 @@ +#!/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)) + + # yanking the NBD node moves the client to the quit state + nbd_block_node =3D {'type': 'block-node', 'node-name': node_name} + iotests.log(vm.qmp('yank', instances=3D[nbd_block_node])) + 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..100b66df64 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-client-query.out @@ -0,0 +1,15 @@ +{"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"}} +{"return": {}} +{"return": {"connector": {"state": "idle"}, "state": "quit"}} +Kill NBD server --=20 2.43.0