From nobody Mon Nov 23 04:38:02 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=1794581753; cv=none; d=zohomail.com; s=zohoarc; b=TwZ2ALnHADx0t/qc/7t6MUFWPSDfjjnzJfprS3hLx36RaS9rElxD2Gv2/X/Q91hGbJrS786OGfyJJJvHcBp+LyVGyIbdCG1KgDyA35cYpTa4FrtVCaYWcr1FYvvrWUDuZPxuM3VM1E8CiAlaDj+PvkAfTcIDTcZ3ILtLl7C/Mxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794581753; 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=w2CsNwlKNWKmb9ROlRU20/DnVq9nc2W5pbX1KAQGj5g=; b=PUX6Oag+fca8jU3Ci+rU2hAZ3XPCGwlZHjJeJzKhTusgiR39ANHZLTCWFUI6+BMAbqCGgsnzFiRQHDuRin+c1lTSjN5GHCEFYmCadmtsgAeMELv5yozlPFEIwTVQbdAilNpzO3FYXXnbwgeCENkDJ1ruIzM32GUe4U6z9YNB4lg= 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 1794581753909546.0744022243566; Fri, 13 Nov 2026 06:55:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRrxz-0006bI-4g; Fri, 13 Nov 2026 09:09:23 -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 1xRrxx-0006ZR-Bu for qemu-devel@nongnu.org; Fri, 13 Nov 2026 09:09:21 -0500 Received: from 2.mo508.mail-out.ovh.net ([5.135.90.177]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRrxu-0004Oe-Tq for qemu-devel@nongnu.org; Fri, 13 Nov 2026 09:09:21 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.58.209]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jQzdm0Hb3z7tCX; Fri, 13 Nov 2026 14:09:16 +0000 (UTC) Received: from ovhcloud.com (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; Fri, 13 Nov 2026 15:09:15 +0100 From: Guillaume Vincke To: CC: , , , , , , Guillaume Vincke Subject: [PATCH v2 1/2] nbd: Add an unstable query for the client state Date: Fri, 13 Nov 2026 15:08:51 +0100 Message-ID: <20261113140852.702959-2-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> References: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.61] 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: 1876875148953272760 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTEaildEnH9HZvkKsOe+5Zdcife+EAsyGX++l8F/tVT2DfFMXfiUPWEc7bVXlDoJ7GmIlf66Vrx2OChfs9JkTL8irHXnImIKWEXg6Boq7tcGv5W9AnisV7ZakDZf50IrA6fbeaifF8VqGYTz5EBmOhamLXtxsfVHzGVigd5PM1Qk1tn+QhYSXvUc97iWPI6EPHeUOtZIDjKQ8mPr05rOI1zKvtMyI/qUV2jB21ik+ggAYNO3Yz3huPYy6hW7e+hOwhqVCA828D/2cJkCr3xqcjSO03i6Np5EqDgcxLhKItRxGb5lrljJl+CZiJIIuzBK8LLfbsyTQEvwZDnbzU1nIJsCHx2xA1IF4coMp7kwVU40od58q2cEv8VYnOtOzw+ua1wp+IYZ4H7azPLB4N4eAcgYrK3cD+e0PRdluNEgzwvYAuvoE+wBKwMskGZfvJGCRiC+WzpKpyLt2DwRhuI3JoDQWpOQsgsZ9VP1AsavP2A2h/n/nRyp81FIzKYzv0qnkq3hT7gTQ1kd4H8jYnp9X+wvS0nvmNZfcT4Gef0U3le7iKq7583gFiqHbYP2fZ8h81HXJWzAggvx3IxpIcqoPL3iAxuUs0bOjns9tjNYkK5FQn4UT1AT5VNyRWrGsCmfrZwNxEcS3wWBrMJeKQ08+MWTzgMkbQuMOsn4M1mEQtPZPw DKIM-Signature: a=rsa-sha256; bh=w2CsNwlKNWKmb9ROlRU20/DnVq9nc2W5pbX1KAQGj5g=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1794578956; v=1; b=lTlNlmbyqWv9sPXjsKc77tlBxMpkZQSKfws+Bp8/KplIZOvG3slcWWmRZGX7eu+MQPoQR6D7 EHAYaXfqP5hUaMJHK7UnqH/KGGRXdEhTFXh7k+f6FcAbKhyPXc1FhlODWqrALtwJ/Gv4BhiazmC e7nduY1SYdroV91TtPESnWE4= 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.177; envelope-from=guillaume.vincke@ovhcloud.com; helo=2.mo508.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: 1794581755828158500 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. The next patch uses this command to make the nbd-stale-connection test deterministic. Signed-off-by: Guillaume Vincke Acked-by: Markus Armbruster --- block/nbd.c | 57 +++++++++++++++++++++++++++ include/block/nbd.h | 9 +++++ nbd/client-connection.c | 22 +++++++++++ qapi/block-core.json | 87 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 175 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index e5e16722ba..49f585eab5 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" @@ -2246,6 +2248,61 @@ 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) { + switch (s->state) { + case NBD_CLIENT_CONNECTING_WAIT: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTING_WAIT; + break; + case NBD_CLIENT_CONNECTING_NOWAIT: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTING_NOWAIT; + break; + case NBD_CLIENT_CONNECTED: + info->state =3D XDBG_NBD_CLIENT_STATE_CONNECTED; + break; + case NBD_CLIENT_QUIT: + info->state =3D XDBG_NBD_CLIENT_STATE_QUIT; + break; + } + + info->connector =3D g_new0(XDbgNbdClientConnector, 1); + switch (nbd_client_connection_get_thread_state(s->conn)) { + case NBD_CLIENT_CONNECTION_THREAD_IDLE: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_IDL= E; + break; + case NBD_CLIENT_CONNECTION_THREAD_RUNNING: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_RUN= NING; + break; + case NBD_CLIENT_CONNECTION_THREAD_PARKED: + info->connector->state =3D XDBG_NBD_CLIENT_CONNECTOR_STATE_PAR= KED; + break; + } + } + + return info; +} + static void bdrv_nbd_init(void) { bdrv_register(&bdrv_nbd); 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); =20 +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/nbd/client-connection.c b/nbd/client-connection.c index aec62934d1..78caea3c37 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 +NBDClientConnectionThreadState +nbd_client_connection_get_thread_state(NBDClientConnection *conn) +{ + NBDClientConnectionThreadState ret; + + WITH_QEMU_LOCK_GUARD(&conn->mutex) { + if (conn->running) { + ret =3D NBD_CLIENT_CONNECTION_THREAD_RUNNING; + } else if (conn->sioc) { + ret =3D NBD_CLIENT_CONNECTION_THREAD_PARKED; + } else { + ret =3D NBD_CLIENT_CONNECTION_THREAD_IDLE; + } + } + + return ret; +} + NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr, bool do_negotiation, const char *export_name, 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 } =20 +## +# @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. --=20 2.43.0 From nobody Mon Nov 23 04:38:02 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=1794581917; cv=none; d=zohomail.com; s=zohoarc; b=CTdkxvm40ddTQ7xEmrTzpIDofNpOIbGcBSLsVOxchiv/GjeOjeST5zIf9g3mEy9AL/qH0jCEOhSiAHpPfCVUEKWQ5Y8kQbwqJKVMBLwj3GS/FptGs/UTwvM8/aS5akG6TiDp30Bb8dwdbmbzCMzj9S5jLPESZP1QEveYq13xoQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794581917; 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=KGcJOWN86dl8LqKRubF5zmk6oX/hhCsOYijf/YEW57E=; b=k0rZp3+Yq/Ghtrkyf3WVW9yTfmODF4PKNHHShqxKnd+I1tTr/DMGAsHGCVV/xJtwizwFCm8hsLCBtAS3/Oul3wnkIfdCSU0GPxvi0OC2ist2gHBI/Yk1uS4e8SOQ8wJumJQGETsGFCOSmJQhAiOy4bSohGpuDieTcfrjTvCr+oU= 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 1794581917190541.6413381150725; Fri, 13 Nov 2026 06:58:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRry6-0006vJ-FO; Fri, 13 Nov 2026 09:09: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 1xRrxy-0006bG-Lz; Fri, 13 Nov 2026 09:09:23 -0500 Received: from 1.mo15.mail-out.ovh.net ([5.135.90.178]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRrxv-0004RJ-Fm; Fri, 13 Nov 2026 09:09:22 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.58.50]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jQzdm6566z3y2B; Fri, 13 Nov 2026 14:09:16 +0000 (UTC) Received: from ovhcloud.com (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; Fri, 13 Nov 2026 15:09:15 +0100 From: Guillaume Vincke To: CC: , , , , , , Guillaume Vincke Subject: [PATCH v2 2/2] iotests: Make nbd-stale-connection test deterministic Date: Fri, 13 Nov 2026 15:08:52 +0100 Message-ID: <20261113140852.702959-3-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> References: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.61] 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: 1877156620531286456 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTF1JsA+MLnxH9Dj7qhLTm25Nm4o53p3GaQgNqMUIRY23It9nRwWJ9TgYOVB8Hove0W8gUUYVM3qiECAG5tUCZgiYtDjSwOV5ct8RAVrxl12KPLsN34lx3Yi+0ikiVgxI9y1JuJwchjQvRnxU5zRTRs3oi9bS/ehGeqRMzD1AhfXVXUlob7QTkX/0JG6Xsgz6XwSk09UyiZwfFaJqmuqGs+tJfECPN3Wb1eYJtSTxugOEHlMRzd8AK3F2t/CmXEiQ4jJYHdblAu2p0S4EVflb//4HzFow7sSmoQelFuiDkAq2u62YiT6Zvup5k4dqV5yXSMQizkFGYEelA76SUJIH+DlLFbTJKSWqek28iUmH1GpkjACcx3lL8QPr3ZFl4gl7thbEXTGYxb+tgmzoy+8dejCvGBjEV/bDsSVHHt3C8IYd9VPYp/Dp5u4mmgn9t396+XSJ5JifPohgsG3LpEbpG9Vmu10hkn2FYUtPd5uaiBS6a/AiCA/EkvY4iqZx+smq0xg0fSbFqRgOBLiLyHxqcJpGul4r4g5byyVecRHRUaHlVhUsZxAysP8ZEwiwwXXmFNCX5583MHtu43B9O16xr5QmF4+kwF77pvDRWWyITGqMkgC+mLgQ1nzNRnlIjjuRPG8RZWg0qivftMTbBbGSdCgugVyyp5IDos74NcabO7KUg DKIM-Signature: a=rsa-sha256; bh=KGcJOWN86dl8LqKRubF5zmk6oX/hhCsOYijf/YEW57E=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1794578957; v=1; b=Uz5H6abaflSFxANrc5uxGjsREQnCWy/dTUZ1GGS7b3H4Ntgjiw3pXFIQItjKQQOWFPLD5g1J z4dUCOf3uNuPUJnBqM08tkvxGlModMQ6zKMGIKyTCNSqFm8fNgUisQJC0/KJj0qr1UF4lS0E4R0 VDrQq6/LiFbfxxjNDUh7Jn3M= 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.178; envelope-from=guillaume.vincke@ovhcloud.com; helo=1.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: 1794581921057158500 Content-Type: text/plain; charset="utf-8" At the moment, the test sleeps to wait for the connector to park a new channel, which can fail on slow or loaded hosts. Poll the x-debug-query-nbd-client command to verify the current state instead of relying on timing. Signed-off-by: Guillaume Vincke --- tests/qemu-iotests/tests/nbd-stale-connection | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/tests/nbd-stale-connection b/tests/qemu-iot= ests/tests/nbd-stale-connection index e361bccfa9..3f7f68e979 100755 --- a/tests/qemu-iotests/tests/nbd-stale-connection +++ b/tests/qemu-iotests/tests/nbd-stale-connection @@ -12,14 +12,21 @@ import iotests from iotests import qemu_nbd_popen, qemu_img_create, file_path, log =20 =20 -# estimated duration required by the connect thread to reach a running ser= ver -MAX_NBD_CONNECT_DURATION =3D 1 - iotests.script_initialize(supported_fmts=3D['qcow2']) nbd_sock =3D file_path('nbd-sock', base_dir=3Diotests.sock_dir) disk =3D file_path('disk') qemu_img_create('-f', iotests.imgfmt, disk, '1M') =20 + +def wait_for_parked_connection(virtm, node_name): + with iotests.Timeout(30, "connect-thread did not reach 'parked' state"= ): + while True: + client =3D virtm.qmp('x-debug-query-nbd-client', node_name=3Dn= ode_name) + if client['return']['connector']['state'] =3D=3D 'parked': + return + time.sleep(0.1) + + with iotests.VM() as vm: =20 vm.launch() @@ -44,7 +51,7 @@ with iotests.VM() as vm: # in CONNECTING, the operation starts the connect thread log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) # wait for the connect thread to get a new channel and stop - time.sleep(MAX_NBD_CONNECT_DURATION) + wait_for_parked_connection(vm, 'nbd0') =20 iotests.log('=3D=3D=3D NBD server down. The parked channel is closed = =3D=3D=3D') =20 @@ -56,5 +63,5 @@ with iotests.VM() as vm: # Wait for it to succeed iotests.log('=3D=3D=3D Wait for the connect thread to park the new= channel. ' 'Subsequent operations are successful =3D=3D=3D') - time.sleep(MAX_NBD_CONNECT_DURATION) + wait_for_parked_connection(vm, 'nbd0') log(vm.qmp('x-qemu-io', device=3D'nbd0', command=3D'write -P 0x5a = 0 64k')) --=20 2.43.0