* [PATCH v3 0/2] nbd: Add an unstable query for the client state
@ 2026-11-30 11:13 Guillaume Vincke
2026-11-30 11:13 ` [PATCH v3 1/2] " Guillaume Vincke
2026-11-30 11:13 ` [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Guillaume Vincke
0 siblings, 2 replies; 11+ messages in thread
From: Guillaume Vincke @ 2026-11-30 11:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, Eric Blake, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster, Guillaume Vincke
These changes follow the discussion on:
https://patchew.org/QEMU/20261105164124.249395-1-guillaume.vincke@ovhcloud.com/#au4tsMuhKjq62dVB@redhat.com
Even though Eric Blake suggested a query for NBD server state,
considering the nbd-stale-connection test we are trying to make
deterministic relies on qemu-nbd, which does not have QMP, this
patchset adds a command to query the NBD client state.
The created QMP command output lists the client internals. The
connector field is used to give the NBD client connection thread
details, i.e. when idle, running or when a channel is ready to be
picked up. Other fields such as in-flight or negotiated size can easily
be added at the top level while others like the connector's last error
would be added into the connector one.
Considering this command accesses the client's private state, it is
implemented in block/nbd.c where BDRVNBDState is defined.
v1: https://patchew.org/QEMU/20261109160609.1434289-1-guillaume.vincke@ovhcloud.com
v2: https://patchew.org/QEMU/20261113140852.702959-1-guillaume.vincke@ovhcloud.com
v1 -> v2:
- patch 1: Connector is now always present, with an idle state. Read
client and connector states under the same lock. Add the NBD state
information to the QMP documentation. Fix documentation wording and
version number.
- patch 2: Simplify the connector lookup using the new QMP command
output.
v2 -> v3:
- Break dependency on <20261105164124.249395-1-guillaume.vincke@ovhcloud.com>
- patch 1: Add Markus Armbruster's Acked-by
- patch 2: Replace the integration into an existing test with a new one
covering the command capabilities. nbd-stale-connection changes move
to its own v4 patchset.
Guillaume Vincke (2):
nbd: Add an unstable query for the client state
iotests: Add coverage for x-debug-query-nbd-client QMP command
qapi/block-core.json | 87 +++++++++++++++++++
include/block/nbd.h | 9 ++
block/nbd.c | 57 ++++++++++++
nbd/client-connection.c | 22 +++++
tests/qemu-iotests/tests/nbd-client-query | 73 ++++++++++++++++
tests/qemu-iotests/tests/nbd-client-query.out | 13 +++
6 files changed, 261 insertions(+)
create mode 100755 tests/qemu-iotests/tests/nbd-client-query
create mode 100644 tests/qemu-iotests/tests/nbd-client-query.out
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/2] nbd: Add an unstable query for the client state
2026-11-30 11:13 [PATCH v3 0/2] nbd: Add an unstable query for the client state Guillaume Vincke
@ 2026-11-30 11:13 ` Guillaume Vincke
2026-12-01 14:59 ` Eric Blake
2026-11-30 11:13 ` [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Guillaume Vincke
1 sibling, 1 reply; 11+ messages in thread
From: Guillaume Vincke @ 2026-11-30 11:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, Eric Blake, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster, Guillaume Vincke
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 <guillaume.vincke@ovhcloud.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
---
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 }
+##
+# @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);
+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"
+#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"
#include "block/qdict.h"
#include "block/nbd.h"
@@ -2305,6 +2307,61 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_detach_aio_context = nbd_detach_aio_context,
};
+XDbgNbdClient *qmp_x_debug_query_nbd_client(const char *node_name,
+ Error **errp)
+{
+ BlockDriverState *bs;
+ BDRVNBDState *s;
+ XDbgNbdClient *info;
+
+ bs = bdrv_find_node(node_name);
+ if (!bs) {
+ error_setg(errp, "Node '%s' not found", node_name);
+ return NULL;
+ }
+
+ if (bs->drv != &bdrv_nbd &&
+ bs->drv != &bdrv_nbd_tcp &&
+ bs->drv != &bdrv_nbd_unix) {
+ error_setg(errp, "Node '%s' is not an NBD client", node_name);
+ return NULL;
+ }
+
+ s = bs->opaque;
+ info = g_new0(XDbgNbdClient, 1);
+ WITH_QEMU_LOCK_GUARD(&s->requests_lock) {
+ switch (s->state) {
+ case NBD_CLIENT_CONNECTING_WAIT:
+ info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_WAIT;
+ break;
+ case NBD_CLIENT_CONNECTING_NOWAIT:
+ info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_NOWAIT;
+ break;
+ case NBD_CLIENT_CONNECTED:
+ info->state = XDBG_NBD_CLIENT_STATE_CONNECTED;
+ break;
+ case NBD_CLIENT_QUIT:
+ info->state = XDBG_NBD_CLIENT_STATE_QUIT;
+ break;
+ }
+
+ info->connector = g_new0(XDbgNbdClientConnector, 1);
+ switch (nbd_client_connection_get_thread_state(s->conn)) {
+ case NBD_CLIENT_CONNECTION_THREAD_IDLE:
+ info->connector->state = XDBG_NBD_CLIENT_CONNECTOR_STATE_IDLE;
+ break;
+ case NBD_CLIENT_CONNECTION_THREAD_RUNNING:
+ info->connector->state = XDBG_NBD_CLIENT_CONNECTOR_STATE_RUNNING;
+ break;
+ case NBD_CLIENT_CONNECTION_THREAD_PARKED:
+ info->connector->state = XDBG_NBD_CLIENT_CONNECTOR_STATE_PARKED;
+ 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;
+ /*
+ * @mutex is taken under BDRVNBDState.requests_lock. Calling back into the
+ * block driver with it held is unsafe.
+ */
QemuMutex mutex;
NBDExportInfo updated_info;
@@ -78,6 +82,24 @@ void nbd_client_connection_enable_retry(NBDClientConnection *conn)
conn->do_retry = true;
}
+NBDClientConnectionThreadState
+nbd_client_connection_get_thread_state(NBDClientConnection *conn)
+{
+ NBDClientConnectionThreadState ret;
+
+ WITH_QEMU_LOCK_GUARD(&conn->mutex) {
+ if (conn->running) {
+ ret = NBD_CLIENT_CONNECTION_THREAD_RUNNING;
+ } else if (conn->sioc) {
+ ret = NBD_CLIENT_CONNECTION_THREAD_PARKED;
+ } else {
+ ret = NBD_CLIENT_CONNECTION_THREAD_IDLE;
+ }
+ }
+
+ return ret;
+}
+
NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr,
bool do_negotiation,
const char *export_name,
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command
2026-11-30 11:13 [PATCH v3 0/2] nbd: Add an unstable query for the client state Guillaume Vincke
2026-11-30 11:13 ` [PATCH v3 1/2] " Guillaume Vincke
@ 2026-11-30 11:13 ` Guillaume Vincke
2026-12-01 15:39 ` Eric Blake
2026-12-01 16:32 ` Eric Blake
1 sibling, 2 replies; 11+ messages in thread
From: Guillaume Vincke @ 2026-11-30 11:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-block, Eric Blake, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster, Guillaume Vincke
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 <guillaume.vincke@ovhcloud.com>
---
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=['qcow2'])
+nbd_sock = iotests.file_path('nbd-sock', base_dir=iotests.sock_dir)
+disk = iotests.file_path('disk')
+iotests.qemu_img_create('-f', iotests.imgfmt, disk, '1M')
+node_name = 'nbd0'
+
+
+def wait_for_state(virtm, state, connector_state):
+ with iotests.Timeout(30, f"did not reach {state}/{connector_state}"):
+ while True:
+ resp = virtm.qmp('x-debug-query-nbd-client', node_name=node_name)
+ resp_st = resp['return']['state']
+ resp_conn_st = resp['return']['connector']['state']
+ if resp_st == state and resp_conn_st == connector_state:
+ break
+ time.sleep(0.1)
+ iotests.log(resp)
+
+
+with iotests.VM() as vm:
+ vm.add_device('virtio-scsi,id=scsi0')
+ vm.launch()
+
+ # error when the node does not exist
+ iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=node_name))
+
+ # error when the node is not an nbd client
+ vm.cmd('blockdev-add', driver='null-co', node_name='null0')
+ iotests.log(vm.qmp('x-debug-query-nbd-client', node_name='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='scsi-hd', drive='nbd0', id='dev0')
+ # the client is connected
+ iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=node_name))
+
+ # server is down. An IO moves it to the connecting-wait state
+ iotests.log(
+ vm.qmp('x-qemu-io', qdev='dev0', command='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='dev0', command='write -P 0x5a 0 64k'))
+ iotests.log(vm.qmp('x-debug-query-nbd-client', node_name=node_name))
diff --git a/tests/qemu-iotests/tests/nbd-client-query.out b/tests/qemu-iotests/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 client"}}
+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
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state
2026-11-30 11:13 ` [PATCH v3 1/2] " Guillaume Vincke
@ 2026-12-01 14:59 ` Eric Blake
2026-12-01 17:08 ` guillaume vincke
0 siblings, 1 reply; 11+ messages in thread
From: Eric Blake @ 2026-12-01 14:59 UTC (permalink / raw)
To: Guillaume Vincke
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On Mon, Nov 30, 2026 at 12:13:26PM +0100, Guillaume Vincke wrote:
> 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 <guillaume.vincke@ovhcloud.com>
> Acked-by: Markus Armbruster <armbru@redhat.com>
> ---
> qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++
> include/block/nbd.h | 9 +++++
> block/nbd.c | 57 +++++++++++++++++++++++++++
> nbd/client-connection.c | 22 +++++++++++
> 4 files changed, 175 insertions(+)
>
> +++ b/qapi/block-core.json
> +##
> +{ 'enum': 'XDbgNbdClientConnectorState',
> + 'data': [ 'idle', 'running', 'parked' ] }
QAPI gives us an enum,...
> +++ 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);
>
> +typedef enum NBDClientConnectionThreadState {
> + NBD_CLIENT_CONNECTION_THREAD_IDLE,
> + NBD_CLIENT_CONNECTION_THREAD_RUNNING,
> + NBD_CLIENT_CONNECTION_THREAD_PARKED,
> +} NBDClientConnectionThreadState;
...but you are defining yet another one with similar naming. Is there
a reason we can't reuse the generated enum from QAPI?
> +++ b/block/nbd.c
> +XDbgNbdClient *qmp_x_debug_query_nbd_client(const char *node_name,
> + Error **errp)
> +{
> + BlockDriverState *bs;
> + BDRVNBDState *s;
> + XDbgNbdClient *info;
> +
> + bs = bdrv_find_node(node_name);
> + if (!bs) {
> + error_setg(errp, "Node '%s' not found", node_name);
> + return NULL;
> + }
> +
> + if (bs->drv != &bdrv_nbd &&
> + bs->drv != &bdrv_nbd_tcp &&
> + bs->drv != &bdrv_nbd_unix) {
> + error_setg(errp, "Node '%s' is not an NBD client", node_name);
> + return NULL;
> + }
> +
> + s = bs->opaque;
> + info = g_new0(XDbgNbdClient, 1);
> + WITH_QEMU_LOCK_GUARD(&s->requests_lock) {
> + switch (s->state) {
> + case NBD_CLIENT_CONNECTING_WAIT:
> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_WAIT;
> + break;
> + case NBD_CLIENT_CONNECTING_NOWAIT:
> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_NOWAIT;
> + break;
> + case NBD_CLIENT_CONNECTED:
> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTED;
> + break;
> + case NBD_CLIENT_QUIT:
> + info->state = XDBG_NBD_CLIENT_STATE_QUIT;
> + break;
> + }
Another example of mapping between an existing enum and a
QAPI-generated one; would it be smarter to just use the QAPI-generated
one everywhere? Although in that case, we would want naming better
than the XDBG_ prefix.
> +++ b/nbd/client-connection.c
> @@ -42,6 +42,10 @@ struct NBDClientConnection {
> bool do_negotiation;
> bool do_retry;
>
> + /*
> + * @mutex is taken under BDRVNBDState.requests_lock. Calling back into the
> + * block driver with it held is unsafe.
> + */
> QemuMutex mutex;
>
> NBDExportInfo updated_info;
> @@ -78,6 +82,24 @@ void nbd_client_connection_enable_retry(NBDClientConnection *conn)
> conn->do_retry = true;
> }
>
> +NBDClientConnectionThreadState
> +nbd_client_connection_get_thread_state(NBDClientConnection *conn)
> +{
> + NBDClientConnectionThreadState ret;
> +
> + WITH_QEMU_LOCK_GUARD(&conn->mutex) {
> + if (conn->running) {
> + ret = NBD_CLIENT_CONNECTION_THREAD_RUNNING;
> + } else if (conn->sioc) {
> + ret = NBD_CLIENT_CONNECTION_THREAD_PARKED;
> + } else {
> + ret = NBD_CLIENT_CONNECTION_THREAD_IDLE;
> + }
> + }
> +
> + return ret;
> +}
Overall, the idea makes sense.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command
2026-11-30 11:13 ` [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Guillaume Vincke
@ 2026-12-01 15:39 ` Eric Blake
2026-12-01 16:57 ` guillaume vincke
2026-12-01 16:32 ` Eric Blake
1 sibling, 1 reply; 11+ messages in thread
From: Eric Blake @ 2026-12-01 15:39 UTC (permalink / raw)
To: Guillaume Vincke
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On Mon, Nov 30, 2026 at 12:13:27PM +0100, Guillaume Vincke wrote:
> 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 <guillaume.vincke@ovhcloud.com>
> ---
> 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
> +++ 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 client"}}
> +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
> --
I tried to think of a reliable way to show a client in the "quit"
state, but am not coming up with anything easy. If I understand, that
state exists in the small window between when the client has stopped
transmission (such as if we just did a yank on the client) but the
socket still hasn't been cleaned up. So the set of states that you
did manage to test is reasonable.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command
2026-11-30 11:13 ` [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Guillaume Vincke
2026-12-01 15:39 ` Eric Blake
@ 2026-12-01 16:32 ` Eric Blake
1 sibling, 0 replies; 11+ messages in thread
From: Eric Blake @ 2026-12-01 16:32 UTC (permalink / raw)
To: Guillaume Vincke
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On Mon, Nov 30, 2026 at 12:13:27PM +0100, Guillaume Vincke wrote:
> 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 <guillaume.vincke@ovhcloud.com>
> ---
> 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
In playing with this, the test completed in 5.5s on my laptop. I think
that's still within reason for giving it the 'quick' label.
Tested-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command
2026-12-01 15:39 ` Eric Blake
@ 2026-12-01 16:57 ` guillaume vincke
2026-12-01 17:28 ` Eric Blake
0 siblings, 1 reply; 11+ messages in thread
From: guillaume vincke @ 2026-12-01 16:57 UTC (permalink / raw)
To: eblake
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On 12/1/26 16:39, Eric Blake wrote:
> On Mon, Nov 30, 2026 at 12:13:27PM +0100, Guillaume Vincke wrote:
>> 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 <guillaume.vincke@ovhcloud.com>
>> ---
>> 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
>
>> +++ 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 client"}}
>> +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
>> --
>
> I tried to think of a reliable way to show a client in the "quit"
> state, but am not coming up with anything easy. If I understand, that
> state exists in the small window between when the client has stopped
> transmission (such as if we just did a yank on the client) but the
> socket still hasn't been cleaned up. So the set of states that you
> did manage to test is reasonable.
Once we reach the quit state, it does not go away. Even once the socket
is cleaned up.
Using QMP yank will move the client to the quit state. I can add that
step in v4 if you want.
Can I keep your Reviewed-by with that extra step?
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state
2026-12-01 14:59 ` Eric Blake
@ 2026-12-01 17:08 ` guillaume vincke
2026-12-01 17:26 ` Eric Blake
0 siblings, 1 reply; 11+ messages in thread
From: guillaume vincke @ 2026-12-01 17:08 UTC (permalink / raw)
To: eblake
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On 12/1/26 15:59, Eric Blake wrote:
> On Mon, Nov 30, 2026 at 12:13:26PM +0100, Guillaume Vincke wrote:
>> 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 <guillaume.vincke@ovhcloud.com>
>> Acked-by: Markus Armbruster <armbru@redhat.com>
>> ---
>> qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++
>> include/block/nbd.h | 9 +++++
>> block/nbd.c | 57 +++++++++++++++++++++++++++
>> nbd/client-connection.c | 22 +++++++++++
>> 4 files changed, 175 insertions(+)
>>
>
>> +++ b/qapi/block-core.json
>
>> +##
>> +{ 'enum': 'XDbgNbdClientConnectorState',
>> + 'data': [ 'idle', 'running', 'parked' ] }
>
> QAPI gives us an enum,...
>
>> +++ 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);
>>
>> +typedef enum NBDClientConnectionThreadState {
>> + NBD_CLIENT_CONNECTION_THREAD_IDLE,
>> + NBD_CLIENT_CONNECTION_THREAD_RUNNING,
>> + NBD_CLIENT_CONNECTION_THREAD_PARKED,
>> +} NBDClientConnectionThreadState;
>
> ...but you are defining yet another one with similar naming. Is there
> a reason we can't reuse the generated enum from QAPI?
My goal was to be consistent for both enums and decided to go with the
extra one. I will remove it in v4.
>
>> +++ b/block/nbd.c
>
>> +XDbgNbdClient *qmp_x_debug_query_nbd_client(const char *node_name,
>> + Error **errp)
>> +{
>> + BlockDriverState *bs;
>> + BDRVNBDState *s;
>> + XDbgNbdClient *info;
>> +
>> + bs = bdrv_find_node(node_name);
>> + if (!bs) {
>> + error_setg(errp, "Node '%s' not found", node_name);
>> + return NULL;
>> + }
>> +
>> + if (bs->drv != &bdrv_nbd &&
>> + bs->drv != &bdrv_nbd_tcp &&
>> + bs->drv != &bdrv_nbd_unix) {
>> + error_setg(errp, "Node '%s' is not an NBD client", node_name);
>> + return NULL;
>> + }
>> +
>> + s = bs->opaque;
>> + info = g_new0(XDbgNbdClient, 1);
>> + WITH_QEMU_LOCK_GUARD(&s->requests_lock) {
>> + switch (s->state) {
>> + case NBD_CLIENT_CONNECTING_WAIT:
>> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_WAIT;
>> + break;
>> + case NBD_CLIENT_CONNECTING_NOWAIT:
>> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTING_NOWAIT;
>> + break;
>> + case NBD_CLIENT_CONNECTED:
>> + info->state = XDBG_NBD_CLIENT_STATE_CONNECTED;
>> + break;
>> + case NBD_CLIENT_QUIT:
>> + info->state = XDBG_NBD_CLIENT_STATE_QUIT;
>> + break;
>> + }
>
> Another example of mapping between an existing enum and a
> QAPI-generated one; would it be smarter to just use the QAPI-generated
> one everywhere? Although in that case, we would want naming better
> than the XDBG_ prefix.
I'd be happy to replace the NBDClientState with the QAPI enum if you
think the XDBG prefix can be removed.
Markus, would that be acceptable for the QAPI schema ?
>
>> +++ b/nbd/client-connection.c
>> @@ -42,6 +42,10 @@ struct NBDClientConnection {
>> bool do_negotiation;
>> bool do_retry;
>>
>> + /*
>> + * @mutex is taken under BDRVNBDState.requests_lock. Calling back into the
>> + * block driver with it held is unsafe.
>> + */
>> QemuMutex mutex;
>>
>> NBDExportInfo updated_info;
>> @@ -78,6 +82,24 @@ void nbd_client_connection_enable_retry(NBDClientConnection *conn)
>> conn->do_retry = true;
>> }
>>
>> +NBDClientConnectionThreadState
>> +nbd_client_connection_get_thread_state(NBDClientConnection *conn)
>> +{
>> + NBDClientConnectionThreadState ret;
>> +
>> + WITH_QEMU_LOCK_GUARD(&conn->mutex) {
>> + if (conn->running) {
>> + ret = NBD_CLIENT_CONNECTION_THREAD_RUNNING;
>> + } else if (conn->sioc) {
>> + ret = NBD_CLIENT_CONNECTION_THREAD_PARKED;
>> + } else {
>> + ret = NBD_CLIENT_CONNECTION_THREAD_IDLE;
>> + }
>> + }
>> +
>> + return ret;
>> +}
>
> Overall, the idea makes sense.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state
2026-12-01 17:08 ` guillaume vincke
@ 2026-12-01 17:26 ` Eric Blake
2026-12-02 8:37 ` Markus Armbruster
0 siblings, 1 reply; 11+ messages in thread
From: Eric Blake @ 2026-12-01 17:26 UTC (permalink / raw)
To: guillaume vincke
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On Tue, Dec 01, 2026 at 06:08:33PM +0100, guillaume vincke wrote:
> On 12/1/26 15:59, Eric Blake wrote:
> > On Mon, Nov 30, 2026 at 12:13:26PM +0100, Guillaume Vincke wrote:
> > > 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 <guillaume.vincke@ovhcloud.com>
> > > Acked-by: Markus Armbruster <armbru@redhat.com>
> > > ---
> > > qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++
> > > include/block/nbd.h | 9 +++++
> > > block/nbd.c | 57 +++++++++++++++++++++++++++
> > > nbd/client-connection.c | 22 +++++++++++
> > > 4 files changed, 175 insertions(+)
> > >
> >
> > > +++ b/qapi/block-core.json
> >
> > > +##
> > > +{ 'enum': 'XDbgNbdClientConnectorState',
> > > + 'data': [ 'idle', 'running', 'parked' ] }
> >
> > QAPI gives us an enum,...
> >
> > > +++ 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);
> > > +typedef enum NBDClientConnectionThreadState {
> > > + NBD_CLIENT_CONNECTION_THREAD_IDLE,
> > > + NBD_CLIENT_CONNECTION_THREAD_RUNNING,
> > > + NBD_CLIENT_CONNECTION_THREAD_PARKED,
> > > +} NBDClientConnectionThreadState;
> >
> > ...but you are defining yet another one with similar naming. Is there
> > a reason we can't reuse the generated enum from QAPI?
>
> My goal was to be consistent for both enums and decided to go with the
> extra one. I will remove it in v4.
>
> > > + case NBD_CLIENT_QUIT:
> > > + info->state = XDBG_NBD_CLIENT_STATE_QUIT;
> > > + break;
> > > + }
> >
> > Another example of mapping between an existing enum and a
> > QAPI-generated one; would it be smarter to just use the QAPI-generated
> > one everywhere? Although in that case, we would want naming better
> > than the XDBG_ prefix.
>
> I'd be happy to replace the NBDClientState with the QAPI enum if you
> think the XDBG prefix can be removed.
> Markus, would that be acceptable for the QAPI schema ?
The type names in QAPI are flexible and don't get exposed to the end
user over introspection. I get why you initially used the XDbg prefix
on the types, to make it easier to match the x-debug- command you
added; but unless Markus sees a problem that I'm overlooking, there's
nothing that prevents you from just naming the new enum type
NbdClientConnectorState instead of XDbgNbdClientConnectorState, since
you would then be using the type in more use cases than just the
x-debug- command.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command
2026-12-01 16:57 ` guillaume vincke
@ 2026-12-01 17:28 ` Eric Blake
0 siblings, 0 replies; 11+ messages in thread
From: Eric Blake @ 2026-12-01 17:28 UTC (permalink / raw)
To: guillaume vincke
Cc: qemu-devel, qemu-block, Vladimir Sementsov-Ogievskiy, Kevin Wolf,
Hanna Reitz, Markus Armbruster
On Tue, Dec 01, 2026 at 05:57:15PM +0100, guillaume vincke wrote:
> On 12/1/26 16:39, Eric Blake wrote:
> > On Mon, Nov 30, 2026 at 12:13:27PM +0100, Guillaume Vincke wrote:
> > > 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 <guillaume.vincke@ovhcloud.com>
> > > ---
> >
> > I tried to think of a reliable way to show a client in the "quit"
> > state, but am not coming up with anything easy. If I understand, that
> > state exists in the small window between when the client has stopped
> > transmission (such as if we just did a yank on the client) but the
> > socket still hasn't been cleaned up. So the set of states that you
> > did manage to test is reasonable.
>
> Once we reach the quit state, it does not go away. Even once the socket
> is cleaned up.
> Using QMP yank will move the client to the quit state. I can add that
> step in v4 if you want.
If it reliably works for exposing the quit state in the test, I'm game
to see that change.
> Can I keep your Reviewed-by with that extra step?
In this instance, go ahead. I'll still end up reviewing v4 either way
:)
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state
2026-12-01 17:26 ` Eric Blake
@ 2026-12-02 8:37 ` Markus Armbruster
0 siblings, 0 replies; 11+ messages in thread
From: Markus Armbruster @ 2026-12-02 8:37 UTC (permalink / raw)
To: Eric Blake
Cc: guillaume vincke, qemu-devel, qemu-block,
Vladimir Sementsov-Ogievskiy, Kevin Wolf, Hanna Reitz
Eric Blake <eblake@redhat.com> writes:
> On Tue, Dec 01, 2026 at 06:08:33PM +0100, guillaume vincke wrote:
>> On 12/1/26 15:59, Eric Blake wrote:
>> > On Mon, Nov 30, 2026 at 12:13:26PM +0100, Guillaume Vincke wrote:
>> > > 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 <guillaume.vincke@ovhcloud.com>
>> > > Acked-by: Markus Armbruster <armbru@redhat.com>
>> > > ---
>> > > qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++
>> > > include/block/nbd.h | 9 +++++
>> > > block/nbd.c | 57 +++++++++++++++++++++++++++
>> > > nbd/client-connection.c | 22 +++++++++++
>> > > 4 files changed, 175 insertions(+)
>> > >
>> >
>> > > +++ b/qapi/block-core.json
>> >
>> > > +##
>> > > +{ 'enum': 'XDbgNbdClientConnectorState',
>> > > + 'data': [ 'idle', 'running', 'parked' ] }
>> >
>> > QAPI gives us an enum,...
>> >
>> > > +++ 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);
>> > > +typedef enum NBDClientConnectionThreadState {
>> > > + NBD_CLIENT_CONNECTION_THREAD_IDLE,
>> > > + NBD_CLIENT_CONNECTION_THREAD_RUNNING,
>> > > + NBD_CLIENT_CONNECTION_THREAD_PARKED,
>> > > +} NBDClientConnectionThreadState;
>> >
>> > ...but you are defining yet another one with similar naming. Is there
>> > a reason we can't reuse the generated enum from QAPI?
Eric has a point there. I didn't see this because I only looked at the
QAPI schema.
>> My goal was to be consistent for both enums and decided to go with the
>> extra one. I will remove it in v4.
>>
>
>> > > + case NBD_CLIENT_QUIT:
>> > > + info->state = XDBG_NBD_CLIENT_STATE_QUIT;
>> > > + break;
>> > > + }
>> >
>> > Another example of mapping between an existing enum and a
>> > QAPI-generated one; would it be smarter to just use the QAPI-generated
>> > one everywhere? Although in that case, we would want naming better
>> > than the XDBG_ prefix.
>>
>> I'd be happy to replace the NBDClientState with the QAPI enum if you
>> think the XDBG prefix can be removed.
>> Markus, would that be acceptable for the QAPI schema ?
>
> The type names in QAPI are flexible and don't get exposed to the end
> user over introspection.
Correct.
> I get why you initially used the XDbg prefix
> on the types, to make it easier to match the x-debug- command you
> added; but unless Markus sees a problem that I'm overlooking, there's
> nothing that prevents you from just naming the new enum type
> NbdClientConnectorState instead of XDbgNbdClientConnectorState, since
> you would then be using the type in more use cases than just the
> x-debug- command.
Renaming types is fine. Use the type name that makes the most sense.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-02 8:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 11:13 [PATCH v3 0/2] nbd: Add an unstable query for the client state Guillaume Vincke
2026-11-30 11:13 ` [PATCH v3 1/2] " Guillaume Vincke
2026-12-01 14:59 ` Eric Blake
2026-12-01 17:08 ` guillaume vincke
2026-12-01 17:26 ` Eric Blake
2026-12-02 8:37 ` Markus Armbruster
2026-11-30 11:13 ` [PATCH v3 2/2] iotests: Add coverage for x-debug-query-nbd-client QMP command Guillaume Vincke
2026-12-01 15:39 ` Eric Blake
2026-12-01 16:57 ` guillaume vincke
2026-12-01 17:28 ` Eric Blake
2026-12-01 16:32 ` Eric Blake
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.