From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 115E5606A33D for ; Tue, 1 Dec 2026 17:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ovhcloud.com header.i=@ovhcloud.com header.a=rsa-sha256 header.s=mailout header.b=NqLfs4B2 Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYRLY-00050N-93; Tue, 01 Dec 2026 12:08:53 -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 1xYRLM-0004zd-K4 for qemu-devel@nongnu.org; Tue, 01 Dec 2026 12:08:42 -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 1xYRLK-0005kb-91 for qemu-devel@nongnu.org; Tue, 01 Dec 2026 12:08:40 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.58.128]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jf6mL31szz3xWQ; Tue, 1 Dec 2026 17:08:34 +0000 (UTC) Received: from [10.15.146.202] (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; Tue, 1 Dec 2026 18:08:33 +0100 Message-ID: Date: Tue, 1 Dec 2026 18:08:33 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/2] nbd: Add an unstable query for the client state To: CC: , , Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , Markus Armbruster References: <20261130111327.178850-1-guillaume.vincke@ovhcloud.com> <20261130111327.178850-2-guillaume.vincke@ovhcloud.com> Content-Language: en-US From: guillaume vincke In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit 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: 18379753033507946936 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTGgKSpX7qIIoGvokDz3kgLmZDMgzPUcDB80aGbircYlMzESmTLWCOAwhg2/V6nCOaRKvNKNfEAVIot3GAt3QxfgD8Ekd076dShB7zACa2B56MO1tkx5SaTa44P1JTG1bQyYusdvH//GqMkxDSr9W1D/cPaeYfrZfxhwmRiGRTH/yW8o95xhYvJtdY0ZS0XIDsukekXoFz/AduGaJxgGXLDFGLz7TU46gh+zhYr7/RrG5KoJhqKsDXch76kIKDxQlznH3mSuZjTHxb7+KWNSEUqldzIz+t1X9MLzHC/bS8SiaNlGVHLba4W3BAyx3z7o4a7pQP9/tAx0vSVFW5+xCFJkStyEZ0DxZ8Fzib7VEuvV1XuBVVgvX94P74QebEExgoymhNnMzljtpjY+jzA8A1aYP6e1EafHXGVZ5O+bHBbWezK1G4Y2OBv2iOw2kE2XPrIna7Aho1h2sWlT2vkbSIdcaHbiaKKttHiRajNMQPvMKIMrB+tehrJ+Bz3IBHNno0W8UyMVIsJhXfiGogbBafTDEfck5c+V95Aww0zYWYt2RyBeHYySHwECweRRsoQy8yKSz/ju8u93ZlvYbPtHEAWTlwZHoZBJO25KM6fMtMXDWsM7cJMCiHXiEUq4hMbQVwM9RiVWQF3M+m0ksSl853LndvYLlgOX4GuE3IeA2uwEKQ DKIM-Signature: a=rsa-sha256; bh=VCmo500mpskSVF+Efa2YkVrQ4Z6kYOb1LBJbH9l6sgk=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1796144914; v=1; b=NqLfs4B2VFMtVNL7rlaV8fw5bZRx3sDTqJEUztMZv/sDLThLk/+iUiwLcCTww+T83cXohWT9 xSAKpHtIo2ntOxbytPj1qnbkg/ZyiWi0u/GoRwS/r2eun2wbtaksfCssPuTyEpNeLkiXtqBr45m g4+HtaaqVGd+r19D9/ZT16NE= 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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 >> 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(+) >> > >> +++ 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. >