From: Eric Blake <eblake@redhat.com>
To: Guillaume Vincke <guillaume.vincke@ovhcloud.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state
Date: Tue, 1 Dec 2026 08:59:25 -0600 [thread overview]
Message-ID: <aw7amVX7A5ibWgTw@redhat.com> (raw)
In-Reply-To: <20261130111327.178850-2-guillaume.vincke@ovhcloud.com>
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
next prev parent reply other threads:[~2026-12-01 15:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-01 17:08 ` guillaume vincke
2026-12-01 17:26 ` Eric Blake
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aw7amVX7A5ibWgTw@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=guillaume.vincke@ovhcloud.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@yandex-team.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.