All of lore.kernel.org
 help / color / mirror / Atom feed
From: guillaume vincke <guillaume.vincke@ovhcloud.com>
To: <eblake@redhat.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 18:08:33 +0100	[thread overview]
Message-ID: <d304f23f-5cfa-48b4-8645-e68e68637736@ovhcloud.com> (raw)
In-Reply-To: <aw7amVX7A5ibWgTw@redhat.com>

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.
> 



  reply	other threads:[~2026-12-01 17:09 UTC|newest]

Thread overview: 11+ 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
2026-12-01 17:08     ` guillaume vincke [this message]
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

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=d304f23f-5cfa-48b4-8645-e68e68637736@ovhcloud.com \
    --to=guillaume.vincke@ovhcloud.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.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.