From nobody Mon Nov 23 04:30:09 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=1795099680; cv=none; d=zohomail.com; s=zohoarc; b=AvKc8G82Z+wdKB7wWlGsXPZxhV/3Q4/xBnvTy/ABn0pLOx3aVU3aPnNFINBMwBrfEm/K85uTpzSW0Lnlo2g8tux/a5RnliMPvAHGx4BkUppkkRh43wQ+8MUumZYoM3RBGH5CIwBI38ZtRc2Gm+4y06W1ftmV8c+KMK3Ukk49J+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795099680; 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=pkivKi2mGSn86PSOqWBospvkalCrAdgbwZmI0PynFMg=; b=LGoRp0XhkLCAZJfyGxrVsZfHVmTvpjwn7d9UnLoHdvC4Q+xySkyXCDrNUte3pI7wRwOvX7Kp86cJX044c6xs/FqCXBZqpeSBcZ50dGN4JXWcKXH3t/8ul/0xMHl2cBmdD5Oy5ebx1PK6lUNG6WsJv43we42zznCAU/BXZ+a3wMg= 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 1795099680091365.7021758239257; Thu, 19 Nov 2026 06:48:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3Q6-0004Tk-N8; Thu, 19 Nov 2026 09:47:26 -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 1xU3Pv-0004R1-Ab for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:17 -0500 Received: from 1.mo508.mail-out.ovh.net ([5.135.90.176]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xU3Pp-0006D3-6l for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:12 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.58.62]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jVhBR26w5z7tDX; Thu, 19 Nov 2026 14:46:55 +0000 (UTC) Received: from ovhcloud.com (109.190.254.2) 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; Thu, 19 Nov 2026 15:46:54 +0100 From: Guillaume Vincke To: CC: , , , , , , , Guillaume Vincke Subject: [PATCH 1/5] block/nbd: Extract request slot access and reconnection Date: Thu, 19 Nov 2026 15:46:28 +0100 Message-ID: <20261119144632.232457-2-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> References: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.2] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 855402457656345053 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGNg8ZCMaeiEnm5IiUVUXzyhKI0RFBvxIMqnEJ1I1WQBifGe+C255M2IP0G0oWwZb95OrcL5+U9se63SmfHP1skwQNw0BHULBhUyMYdnupKYkpfuuR1RI2c5UPKJsDR7j/nHiZdWNolzrdPyEO5DQhbUqw9XIZodjSC+aDIVoGPaOOVVxvj7Pqs76s0IA/EFdC0FUElNYEy0+T4i10kgByx8od1JLgleLsDF7qdMs+jPuI19ToRtfq/1MPyRVV0JiTq9eQ7bqdj3CCbZQr5kSSqXcMYxKz0CpTFQ12zS0XiddxzOc6C5ovjxPdWBRPRRCfBxBreIMLVmpqeV73oSJOjp6/baUZGhQgbGbheaU84EXGdxYuY7KNdDzCgBpaaRsBUnZpNNngMKTUzSw25kLBgLxQywG6EYDCyIJurccft5E/hr6iDS8kCDz7TAPaKImuPPRCH69uhQwRs11GBjZx8UX02aD1lkvTr9VD/2SlAO2ECcmBHJsXk9i5SbqoiuPYJlcY4j49znft/zi8HnGGivS4SsNzKuQPR4jiCmWZBu7PHfKTPO1riB2v4j8HZu0OU1XTEBsS9IwZYhfo4m4qIoGMv83teMBTO6PkNLo/O+l9N2JaVkNwsSEhvF4GWdU5gH0rulwENSKbnHYEVRMjZipv8W1n16coIgETxB4pWdA DKIM-Signature: a=rsa-sha256; bh=pkivKi2mGSn86PSOqWBospvkalCrAdgbwZmI0PynFMg=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1795099615; v=1; b=fDi8YL5A9rDPs3Y8rWckrj5fwFzUiRnsFmvaNDo0gEGL++MHSHqJG3seNbupONGZ+U2beNeB b5uZ8GuSOxzURpF17WxxwJ/EuqHtXpozqz2RV3ks9wPZkYncswZezP5ECmEnQoAd3v9JgqHqisS CTd6rkFfbXSVcA1fwLfeVP8c= 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.176; envelope-from=guillaume.vincke@ovhcloud.com; helo=1.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=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: 1795099681677158500 Content-Type: text/plain; charset="utf-8" The number of concurrent requests in the NBD block driver is bounded by MAX_NBD_REQUESTS. When reaching that level of concurrency, we park coroutines in a queue and, on completion, we resume the first. That logic is implemented in nbd_co_send_request(). Coroutines also get queued when the channel is disconnected to make sure only one request triggers reconnection. This patch extracts nbd_co_acquire_slot(), nbd_co_release_slot() and nbd_co_reconnect() out of the request sending. This will help use nbd_reconnect_attempt() outside of the request sending logic in a later patch of the series. No functional change. Signed-off-by: Guillaume Vincke Reviewed-by: Eric Blake --- block/nbd.c | 56 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 49f585eab5..df72b17ade 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -510,6 +510,41 @@ err: return ret; } =20 +/* + * Parks until a slot in the request queue is available or when, being the= only + * in flight operation running, the caller is ready to run reconnection. + * Increments s->in_flight on return. + * Called with s->requests_lock held. + */ +static void coroutine_fn nbd_co_acquire_slot(BDRVNBDState *s) +{ + while (s->in_flight =3D=3D MAX_NBD_REQUESTS || + (s->state !=3D NBD_CLIENT_CONNECTED && s->in_flight > 0)) { + qemu_co_queue_wait(&s->free_sema, &s->requests_lock); + } + s->in_flight++; +} + +/* Called with s->requests_lock held. */ +static void coroutine_fn nbd_co_release_slot(BDRVNBDState *s) +{ + s->in_flight--; + qemu_co_queue_next(&s->free_sema); +} + +/* Called with s->requests_lock held. */ +static int coroutine_fn GRAPH_RDLOCK nbd_co_reconnect(BDRVNBDState *s) +{ + if (nbd_client_connecting(s)) { + nbd_reconnect_attempt(s); + qemu_co_queue_restart_all(&s->free_sema); + } + if (s->state !=3D NBD_CLIENT_CONNECTED) { + return -EIO; + } + return 0; +} + static int coroutine_fn GRAPH_RDLOCK nbd_co_send_request(BlockDriverState *bs, NBDRequest *request, QEMUIOVector *qiov) @@ -518,19 +553,10 @@ nbd_co_send_request(BlockDriverState *bs, NBDRequest = *request, int rc, i =3D -1; =20 qemu_mutex_lock(&s->requests_lock); - while (s->in_flight =3D=3D MAX_NBD_REQUESTS || - (s->state !=3D NBD_CLIENT_CONNECTED && s->in_flight > 0)) { - qemu_co_queue_wait(&s->free_sema, &s->requests_lock); - } - - s->in_flight++; + nbd_co_acquire_slot(s); if (s->state !=3D NBD_CLIENT_CONNECTED) { - if (nbd_client_connecting(s)) { - nbd_reconnect_attempt(s); - qemu_co_queue_restart_all(&s->free_sema); - } - if (s->state !=3D NBD_CLIENT_CONNECTED) { - rc =3D -EIO; + rc =3D nbd_co_reconnect(s); + if (rc !=3D 0) { goto err; } } @@ -573,8 +599,7 @@ err: if (i !=3D -1) { s->requests[i].coroutine =3D NULL; } - s->in_flight--; - qemu_co_queue_next(&s->free_sema); + nbd_co_release_slot(s); qemu_mutex_unlock(&s->requests_lock); } return rc; @@ -1085,8 +1110,7 @@ static bool coroutine_fn nbd_reply_chunk_iter_receive= (BDRVNBDState *s, break_loop: qemu_mutex_lock(&s->requests_lock); nbd_request_by_cookie(s, cookie, &error_abort)->coroutine =3D NULL; - s->in_flight--; - qemu_co_queue_next(&s->free_sema); + nbd_co_release_slot(s); qemu_mutex_unlock(&s->requests_lock); =20 return false; --=20 2.43.0 From nobody Mon Nov 23 04:30:09 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=1795099729; cv=none; d=zohomail.com; s=zohoarc; b=DeC7u+kfhhKdKZFxz+LCjKrXBquuzikfn5MlM27gTnV/1Q/mnJYyPTobdeBmz3hO5SsMpZlpJKePUXRLRYHsyU3zfHW1ri9av6RHNbwQ0D6ZwKSSmjxb/Nhh7S4cT4Mv56zltErhiWHews0IOX7jjsqGylj89b1FvqHFgJFOxKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795099729; 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=d/DytXrpjrrOlaVJ3b69UCyHaZFzBJ41QwLBqIEFELE=; b=jQ+zEtk3/2Li47gMZubv+9kpQRkb4Vcy7RghMhFsAXPNQaaYBw8XCQOm8PkKBPHISqNCXaNBYU1D0jipHCr7MQuq0YZpNhprttXujGpekCYLW0UHSUxwFiYoQ9xDTEJx6d72+x3RH4yuvu9uUzMlfiwk/PJaSYxC9N5Yy9eGHS0= 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 1795099729782938.8736622241482; Thu, 19 Nov 2026 06:48:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3Q5-0004T8-Gv; Thu, 19 Nov 2026 09:47:25 -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 1xU3Pv-0004Qz-AU; Thu, 19 Nov 2026 09:47:17 -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 1xU3Pp-0006D4-K2; Thu, 19 Nov 2026 09:47:13 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.58.62]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jVhBR3vVRz7tDf; Thu, 19 Nov 2026 14:46:55 +0000 (UTC) Received: from ovhcloud.com (109.190.254.2) 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; Thu, 19 Nov 2026 15:46:54 +0100 From: Guillaume Vincke To: CC: , , , , , , , Guillaume Vincke Subject: [PATCH 2/5] block: Refresh the connection before block_resize Date: Thu, 19 Nov 2026 15:46:29 +0100 Message-ID: <20261119144632.232457-3-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> References: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.2] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 855402457260638685 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGOS8EGrX643+ovyXsH+QFTmB5aOgoJ08jxUdSO/s6XgvT7M/VuQQ/Ds/8vMAVUddgP1bWDSw41OV9jyN0q52MhAPgS0yoC2ODGuYv1BBob7jhQ7dDNOfGz7zhBa7QJumewrS892C6gqnCQx9qVlOOB+KxYueih+lDUybnRAI53OitkcpkFTDvwmUxZnALuqa95QZrlzfljSUx8on3qABkAFuxLMjxQP7sm7omnCeHybC2x1J2w07QRuPY6b/1YmXdD271GM23xOVXa9HL1eexNQ/d+NppEKUVhgxm4GKbkD1Pt3B/0ooUNcyKYtby1iye42fekcpfDjPqPXYgcnp0Ldss2GKTgWCKuexDgcgQKIee2fxVRHp6S7qUfwBwiQRly/D/qh1frVKd/5Jg6O3Rxnq9bOg3LugFeB5DWUFufWXb5ZgJgxd/RzfuCqhtU1aFhvKDHTlJ+BTnsCbhtIwkWbSOhgYbTd8Jmrfu7fe5d0R233HIFRF7D6HYwAt8MCNDlIIZMSPkXC3eN6c8EeZRtKzHRwmgHeEYcmr3AGznj0HJi0JqJHeqU/62P1cFgmbIARf7kuPPjt1N1HUhO7eD3D8Z3DSqbSIi0XeNxjUZCk7ECoVuXsP2A0VGcp2eG6vUC5jqYPmurlx97j1sYInsgoowAdtRVsOt+nSiAQiQoPQ DKIM-Signature: a=rsa-sha256; bh=d/DytXrpjrrOlaVJ3b69UCyHaZFzBJ41QwLBqIEFELE=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1795099615; v=1; b=HHoi4bbuZaef68dr0/TMrRoIUdLyDDVkwoXLkKUTr7RM7DsZL1z8F6sUPfgJJ0PA/Xe1TuqZ Bl1p7BV4X/Z1hgTlRUoTSpV/Jc3XegautqXzbEXgAREMDI+122wKGeQw4UiC3odzbpDcOLzV1+T 8V/m6Q7x2gvJRMP9VFNNqGIA= 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=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: 1795099731857158500 Content-Type: text/plain; charset="utf-8" When a network based device is not connected, there is no way for the backend to notify a change. For instance, the NBD client relies on lazy reconnection. Therefore, if an NBD backend changes size, there is currently no way to update the device size until at least one I/O operation is sent. This patch adds the bdrv_co_refresh_connection callback to the BlockDriver structure so a reconnection can be forced. Considering nbd_co_truncate() does not perform any I/O, it also modifies the QMP block_resize implementation to execute the callback, if defined, before truncating. No functional change. Signed-off-by: Guillaume Vincke --- block/block-backend.c | 12 ++++++++++++ block/io.c | 24 ++++++++++++++++++++++++ blockdev.c | 9 +++++++++ include/block/block-io.h | 8 ++++++++ include/block/block_int-common.h | 3 +++ include/system/block-backend-io.h | 2 ++ 6 files changed, 58 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 656c0aed67..b133bb8292 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2600,6 +2600,18 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, = int64_t offset, bool exact, return bdrv_co_truncate(blk->root, offset, exact, prealloc, flags, err= p); } =20 +int coroutine_fn blk_co_refresh_connection(BlockBackend *blk, Error **errp) +{ + IO_OR_GS_CODE(); + GRAPH_RDLOCK_GUARD(); + if (!blk_co_is_available(blk)) { + error_setg(errp, "No medium inserted"); + return -ENOMEDIUM; + } + + return bdrv_co_refresh_connection(blk->root, errp); +} + int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int64_t pos, int size) { diff --git a/block/io.c b/block/io.c index e4568d4d24..3c5c05b9a0 100644 --- a/block/io.c +++ b/block/io.c @@ -3274,6 +3274,30 @@ out: return ret; } =20 +int coroutine_fn bdrv_co_refresh_connection(BdrvChild *child, Error **errp) +{ + BlockDriverState *bs =3D child->bs; + BlockDriver *drv =3D bs->drv; + int ret; + IO_CODE(); + assert_bdrv_graph_readable(); + + if (!drv) { + error_setg(errp, "No medium inserted"); + return -ENOMEDIUM; + } + + if (!drv->bdrv_co_refresh_connection) { + return 0; + } + + bdrv_inc_in_flight(bs); + ret =3D drv->bdrv_co_refresh_connection(bs, errp); + bdrv_dec_in_flight(bs); + + return ret; +} + int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) { BlockDriver *drv =3D bs->drv; diff --git a/blockdev.c b/blockdev.c index 0f70973326..5d6d618bce 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2314,6 +2314,7 @@ void coroutine_fn qmp_block_resize(const char *device= , const char *node_name, BlockBackend *blk; BlockDriverState *bs; AioContext *old_ctx; + int ret; =20 bs =3D bdrv_lookup_bs(device, node_name, &local_err); if (local_err) { @@ -2338,6 +2339,14 @@ void coroutine_fn qmp_block_resize(const char *devic= e, const char *node_name, return; } =20 + old_ctx =3D bdrv_co_enter(bs); + ret =3D blk_co_refresh_connection(blk, errp); + bdrv_co_leave(bs, old_ctx); + if (ret < 0) { + blk_co_unref(blk); + return; + } + bdrv_drained_begin(bs); =20 old_ctx =3D bdrv_co_enter(bs); diff --git a/include/block/block-io.h b/include/block/block-io.h index f671476f08..5a7328fed5 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -114,6 +114,14 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDrive= rState *bs); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, int64_t bytes); =20 +/* + * Ensure the connection is ready to process requests by re-establishing i= t if + * closed. + * Returns 0 when the driver does not declare the callback. + */ +int coroutine_fn GRAPH_RDLOCK bdrv_co_refresh_connection(BdrvChild *child, + Error **errp); + /* Report zone information of zone block device. */ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_report(BlockDriverState *bs, int64_t offset, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 0c7746a544..a0411e2947 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -591,6 +591,9 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( BlockDriverState *bs, int64_t offset, int64_t bytes); =20 + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_refresh_connection)( + BlockDriverState *bs, Error **errp); + /* * Map [offset, offset + nbytes) range onto a child of @bs to copy fro= m, * and invoke bdrv_co_copy_range_from(child, ...), or invoke diff --git a/include/system/block-backend-io.h b/include/system/block-backe= nd-io.h index 78d410b8df..811264622c 100644 --- a/include/system/block-backend-io.h +++ b/include/system/block-backend-io.h @@ -238,4 +238,6 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int= 64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags f= lags, Error **errp); =20 +int coroutine_fn blk_co_refresh_connection(BlockBackend *blk, Error **errp= ); + #endif /* BLOCK_BACKEND_IO_H */ --=20 2.43.0 From nobody Mon Nov 23 04:30:09 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=1795099664; cv=none; d=zohomail.com; s=zohoarc; b=DlWV5qRp2Gu6Zwoq0eGpH0h0F3TEItDK0Go/AtFLCXzvAcXEHUVl7FrP+wm99z/x6YtkFvPRwPpiX9Sp0gJ/pCKWA+UzeQcy5aN6se6Ig5pstkIAn9r8sZClefKf+edSrWIv0tcgWmVIMq19qMEWSt3hGOq4pbH32nvqu5+4a50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795099664; 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=3jEj/wqTF6rn/9Et/Rm6BzNnE8rRvY2zcwSFs49RLgE=; b=PTXb5h3qyLmYiwnVAg7ZTjta5pzaUHeGw0cuTSpNwpvBm91jwQuGIUPxTu1o8ETvbhWk7u+Ej1R1yIS5tQwakzxOT8de2aXGx5VBhbZ8iLs3bC/Mzla5nrAoXlubnOJBl6Nv7jyTE0TZeAY/WwFYpHP5v0eCz0k691ivAanHEA4= 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 1795099664490906.1956358075441; Thu, 19 Nov 2026 06:47:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3Q6-0004Tw-OT; Thu, 19 Nov 2026 09:47:26 -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 1xU3Pv-0004R3-Ai; Thu, 19 Nov 2026 09:47:17 -0500 Received: from 1.mo508.mail-out.ovh.net ([5.135.90.176]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xU3Pp-0006DA-Jo; Thu, 19 Nov 2026 09:47:13 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.0.133]) by mo508.mail-out.ovh.net (Postfix) with ESMTPS id 4jVhBS1ckDz7tDg; Thu, 19 Nov 2026 14:46:56 +0000 (UTC) Received: from ovhcloud.com (109.190.254.2) 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; Thu, 19 Nov 2026 15:46:55 +0100 From: Guillaume Vincke To: CC: , , , , , , , Guillaume Vincke Subject: [PATCH 3/5] block/nbd: Refresh the connection on block_resize Date: Thu, 19 Nov 2026 15:46:30 +0100 Message-ID: <20261119144632.232457-4-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> References: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.2] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 855683929345114589 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGOS8EGrX643+ovyXsH+QFTmB5aOgoJ08jxUdSO/s6XgvT7M/VuQQ/Ds/8vMAVUddgP1bWDSw41OV9jyN0q52MhAPgS0yoC2ODGuYv1BBob7jhQ7dDNOfGz7zhBa7QJumewrS892C6gqnCQx9qVlOOB+KxYueih+lDUybnRAI53OitkcpkFTDvwmUxZnALuqa95QZrlzfljSUx8on3qABkAFuxLMjxQP7sm7omnCeHybC2x1J2w07QRuPY6b/1YmXdD271GM23xOVXa9HL1eexNQ/d+NppEKUVhgxm4GKbkD1Pt3B/0ooUNcyKYtby1iye42fekcpfDjPqPXYgcnp0LgOl5mlkJCyQuhgCd48i0hN/s+zx3P9wyeOjFnzin8r2vniNgSKVuZx3khYp80nKt6uQhrUP7FREiOxIBZdpSMwHCo/ovPjWyWU839tM6N4IescdiLITSzZpP6Hit1mUZ5eDYBKsqNH/IkVJ8hu7VOsgMw3BwD2S4+DSgifXHVuDVTg1jOs8MVg7wGcKHlzBaG3AIgNFSc74Y4tzsfQd1nTiLDG+4o2tRV6MfcYbsIxSkz8E263CWxezyhMhifdTTWGBrB+maeFj3qusnU2OHoXPruALoAuefb3FWrfuMTxIcmvvQDJrfuEYc3igiqbM1T+MAFswTwfhY5UcbPas4iA DKIM-Signature: a=rsa-sha256; bh=3jEj/wqTF6rn/9Et/Rm6BzNnE8rRvY2zcwSFs49RLgE=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1795099616; v=1; b=IjwTBi4bstKlJlJQIygsHAiPEI7C9ZxoYmBBi04lepfKmtIRFKSTFWhkmwzC7MjDKJVt3tED PWLnQWSrzQ/v+EaA7OC0Une6MJup6jpSsajvoMJADActzFEAG8LF+PmJAZzbOxt9MwvhikrhSAh WeWNiS9cRupNWgmrC6atJmKw= 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.176; envelope-from=guillaume.vincke@ovhcloud.com; helo=1.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=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: 1795099668177158500 Content-Type: text/plain; charset="utf-8" When an NBD device is resized, two steps are needed to propagate the information. First, as the size is only exchanged at handshake, the connection needs to be reset. Then, the new size needs to be updated by calling bdrv_co_refresh_total_sectors(). The QMP block_resize method, by calling bdrv_co_truncate(), takes care of the second step but, considering the NBD connection is lazy, nothing deals with reconnection when the device is idle. This patch uses the new bdrv_co_refresh_connection() to force the handshake by manually starting the reconnection routine. It creates a clean flow to resize an NBD-backed block device on the server side by closing the connection and calling block_resize. When the node is configured with reconnect-delay=3D0, refreshing starts the reconnection but returns immediately with -EIO. The management application can handle this case by waiting for the connection to be established and re-running block_resize. To detect disconnection, we peek the channel. This does not detect dead peers or disconnected TLS-secured connections. Therefore, this flow will not work if the server does not disconnect cleanly or if the communication is encrypted. Signed-off-by: Guillaume Vincke --- block/nbd.c | 39 +++++++++++++++++++++++++++++++++++++++ include/block/nbd.h | 1 + nbd/client-connection.c | 7 +++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index df72b17ade..759a6ef480 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -2081,6 +2081,42 @@ static int coroutine_fn nbd_co_truncate(BlockDriverS= tate *bs, int64_t offset, return 0; } =20 +/* + * Start the reconnection routine unless the node is connected and its cha= nnel + * is still open. When used with a zero reconnect-delay, this function + * triggers the reconnection and returns -EIO. + */ +static int coroutine_fn GRAPH_RDLOCK +nbd_co_refresh_connection(BlockDriverState *bs, Error **errp) +{ + BDRVNBDState *s =3D bs->opaque; + int ret; + + QEMU_LOCK_GUARD(&s->requests_lock); + + if (s->state =3D=3D NBD_CLIENT_QUIT) { + error_setg(errp, "Cannot refresh a permanently unavailable NBD nod= e"); + return -ECONNREFUSED; + } + + if (s->state =3D=3D NBD_CLIENT_CONNECTED) { + if (!nbd_channel_is_closed(s->ioc)) { + return 0; + } + /* A connection closed by its peer is treated as an error */ + nbd_channel_error_locked(s, -EIO); + } + + nbd_co_acquire_slot(s); + ret =3D nbd_co_reconnect(s); + nbd_co_release_slot(s); + + if (ret < 0) { + error_setg(errp, "Failed to reconnect NBD node"); + } + return ret; +} + static int64_t coroutine_fn nbd_co_getlength(BlockDriverState *bs) { BDRVNBDState *s =3D bs->opaque; @@ -2205,6 +2241,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, + .bdrv_co_refresh_connection =3D nbd_co_refresh_connection, .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, @@ -2233,6 +2270,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, + .bdrv_co_refresh_connection =3D nbd_co_refresh_connection, .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, @@ -2261,6 +2299,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, + .bdrv_co_refresh_connection =3D nbd_co_refresh_connection, .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, diff --git a/include/block/nbd.h b/include/block/nbd.h index 15ddec91ac..b459788534 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -508,6 +508,7 @@ NBDClientConnection *nbd_client_connection_new(const So= cketAddress *saddr, QCryptoTLSCreds *tlscreds, const char *tlshostname); void nbd_client_connection_release(NBDClientConnection *conn); +bool nbd_channel_is_closed(QIOChannel *ioc); =20 QIOChannel *coroutine_fn nbd_co_establish_connection(NBDClientConnection *conn, NBDExportInfo *info, diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 78caea3c37..e6e346d9fc 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -296,8 +296,11 @@ void nbd_client_connection_release(NBDClientConnection= *conn) } } =20 -/* Only true when the peer closed the channel. Does not detect if dead. */ -static bool nbd_channel_is_closed(QIOChannel *ioc) +/* + * Only true when the peer closed the channel. Always returns false for TLS + * channels. Does not detect if dead. + */ +bool nbd_channel_is_closed(QIOChannel *ioc) { char data; struct iovec iov =3D { .iov_base =3D &data, .iov_len =3D 1 }; --=20 2.43.0 From nobody Mon Nov 23 04:30:09 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=1795099679; cv=none; d=zohomail.com; s=zohoarc; b=Aqht4otVgZO1mIIXCIv9RHORVGrCUMxaApNH1Bb1lBPbUOqw5lYpOIRhlSAp9wz9CUHsGGPh3Va4Q735iRT0vaGOwJEgrjLaufcAfaT4bklK+wbAYXKbuyMQ4EV13lu7hJ5OyQg4XE2/6JscQnI9pg/mAzi1j+gw4EOoTYMkV9I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795099679; 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=0ia8OpYUMfisiLn9YZYC10KD5H2WNL7fCwjQsBTXoWQ=; b=SL12atNgRGeuGhxC5YH2qhN1+J0Woo1b2rO+J0S6sfVxSk9xYly6PmfBTFN2xkHfpC+SJchOhuRiXUoMyhSF8EzBCAZbG7JnsVHqaLkaPid8h6OzDuxdrzLvA543tX1bxRhQeHjPyANbdwSIWHThTy7coeGse6efXvjLSZRa6QU= 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 1795099679965705.252665435311; Thu, 19 Nov 2026 06:47:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3Pz-0004SG-RA; Thu, 19 Nov 2026 09:47:21 -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 1xU3Pr-0004QY-8X for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:11 -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 1xU3Pp-0006DS-6O for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:10 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.0.73]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jVhBT0tBZz42Mw; Thu, 19 Nov 2026 14:46:56 +0000 (UTC) Received: from ovhcloud.com (109.190.254.2) 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; Thu, 19 Nov 2026 15:46:56 +0100 From: Guillaume Vincke To: CC: , , , , , , , Guillaume Vincke Subject: [PATCH 4/5] iotests: Add coverage for NBD resize Date: Thu, 19 Nov 2026 15:46:31 +0100 Message-ID: <20261119144632.232457-5-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> References: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.2] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 855965406749278685 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGQhBK1U4xr/AMRFXRFeSFunzyiF6YtPFyxOtiBV85ZL5XARzZl8Z6U/ThfSP8t+5aj6ASB256lQMITIDvCr2bW5VG3AmVbjnFNPYSKTRwG+4DbCS6uE9SzdlmglbW/hDwGl+LfYUd+e+1PYDLewjTk7sCr/qyWO8hNVUp+rWsuv8BS/lxxOolWzCkc3Xy5dfi1Qbv4IFpRs09fIF/+f6kNcUVFFQXKiVq//Ej4Dz3sfLD8Tqa+8pP0afr1+xcIpXKR8UAhCmDiKlWfaRtcm7LIKr3ZkiesntSSjmnxh5QoyNvoLGs7VCnKrYAd4aeVDJ0oxd0UIGBSk78TrOY87RF6fcukzdNHupHSdL8MB4y/i/MBb4/Vs397E60UASxLlmL66Mh1SxJ4x/r556cQFb/7oQKAj8KsJrqYTO2/GjgghEZh4SfF5dEqgbjzcvaSXd8iBb2wbSw7VOFPqbWKBa/ngtEaY2UQ8pN1waPRQSjRiNCElrqnOPVHgGfr3dU8F9MqI1A3EKWv1i0rFTaEEe2HWSQiUV4flRzcAjTtG6O3WzOqqwVdAGzbCarD03Hgqg4DKR6/4DhjRtXjeOg//vZts82nYZxNqEnT//r3+U0f5XCVXm8u5HD5071TE/J/Qe5IhidCkJo8baVUwM5J9OKpCM9GTPEQkVlYWlyVMvHDqQ DKIM-Signature: a=rsa-sha256; bh=0ia8OpYUMfisiLn9YZYC10KD5H2WNL7fCwjQsBTXoWQ=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1795099617; v=1; b=bxdgmnk6fFCySGpgbYIeo03q2ThrdEI95BKKeoQfFAKHxD6wjao0mba8zMP7uTIlp2xR3F14 DAZHnv8TbNAyUOb1IXKnBLZune9JzjPlC/jcZf7tEBufashYXlZ1ylml9NLMl77LdURkTxomkm6 XSWQ6AN9JOfVe34APXgeluSA= 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: 1795099681706158500 Content-Type: text/plain; charset="utf-8" Test the block_resize QMP function on an NBD device. Prior to the addition of bdrv_co_refresh_connection(), running block_resize on a node that did not process any requests between the device size update and the function call failed with "Cannot grow NBD nodes". Add a test that updates an NBD node size and verifies that the block_resize behaves as expected. The first part configures a reconnect delay and asserts that the call succeeds. The second uses the default reconnect-delay=3D0 and asserts that, even though the function returns an error, the reconnection routine gets started and that retrying succeeds once the node has successfully reconnected. Signed-off-by: Guillaume Vincke --- tests/qemu-iotests/tests/nbd-resize | 81 +++++++++++++++++++++++++ tests/qemu-iotests/tests/nbd-resize.out | 24 ++++++++ 2 files changed, 105 insertions(+) create mode 100755 tests/qemu-iotests/tests/nbd-resize create mode 100644 tests/qemu-iotests/tests/nbd-resize.out diff --git a/tests/qemu-iotests/tests/nbd-resize b/tests/qemu-iotests/tests= /nbd-resize new file mode 100755 index 0000000000..4f305eaebf --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-resize @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +# group: quick +# +# Test the NBD resize +# +# Copyright (C) 2026 OVHcloud +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import time +import iotests + +iotests.script_initialize(supported_fmts=3D['qcow2']) +nbd_sock =3D iotests.file_path('nbd-sock', base_dir=3Diotests.sock_dir) +disk =3D iotests.file_path('disk') +node_name =3D 'nbd0' + + +def node_size(virtm): + for node in virtm.cmd('query-named-block-nodes', flat=3DTrue): + if node['node-name'] =3D=3D node_name: + return node['image']['virtual-size'] + return None + + +def wait_for_parked_connection(virtm): + 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) + + +for reconnect_delay in [10, 0]: + iotests.log(f"=3D=3D=3D Resize with reconnect-delay=3D{reconnect_delay= } =3D=3D=3D") + with iotests.VM() as vm: + vm.launch() + + iotests.qemu_img_create('-f', iotests.imgfmt, disk, '1M') + with iotests.qemu_nbd_popen('-k', + nbd_sock, + '-f', + iotests.imgfmt, + disk): + vm.cmd('blockdev-add', { + 'driver': 'nbd', + 'node-name': node_name, + 'server': { 'type': 'unix', 'path': nbd_sock }, + 'reconnect-delay': reconnect_delay, + }) + + iotests.log('Size before resize:') + iotests.log(node_size(vm)) + + iotests.qemu_img('resize', '-f', iotests.imgfmt, disk, '2M') + with iotests.qemu_nbd_popen('-k', + nbd_sock, + '-f', + iotests.imgfmt, + disk): + iotests.log(vm.qmp('block_resize', { + 'node-name': node_name, + 'size': 2097152, + })) + iotests.log('Size after resize:') + iotests.log(node_size(vm)) + if reconnect_delay =3D=3D 0: + # With delay=3D0, block_resize fails while the client reco= nnects. + # Retry once parked. + iotests.log('Waiting until the reconnection succeeds') + wait_for_parked_connection(vm) + + iotests.log(vm.qmp('block_resize', { + 'node-name': node_name, + 'size': 2097152, + })) + iotests.log('Size after retried resize:') + iotests.log(node_size(vm)) + + vm.shutdown() diff --git a/tests/qemu-iotests/tests/nbd-resize.out b/tests/qemu-iotests/t= ests/nbd-resize.out new file mode 100644 index 0000000000..89eda39740 --- /dev/null +++ b/tests/qemu-iotests/tests/nbd-resize.out @@ -0,0 +1,24 @@ +=3D=3D=3D Resize with reconnect-delay=3D10 =3D=3D=3D +Start NBD server +Size before resize: +1048576 +Kill NBD server +Start NBD server +{"return": {}} +Size after resize: +2097152 +Kill NBD server +=3D=3D=3D Resize with reconnect-delay=3D0 =3D=3D=3D +Start NBD server +Size before resize: +1048576 +Kill NBD server +Start NBD server +{"error": {"class": "GenericError", "desc": "Failed to reconnect NBD node"= }} +Size after resize: +1048576 +Waiting until the reconnection succeeds +{"return": {}} +Size after retried resize: +2097152 +Kill NBD server --=20 2.43.0 From nobody Mon Nov 23 04:30:09 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=1795099729; cv=none; d=zohomail.com; s=zohoarc; b=O6jZYShAiKd7WLTeNDZnWHV8VKq63L+xSUkIgUxiirvS6Hw2XNqDMBFzr7actTcp7QizvGc4Ck2Qs+DSEQPQFSYNj3tnRIVUZoJ7rAoFS9p/Oz6Ag28Tg18hCzX0hU4AyRS6v8FH4jot6HRBdUW7PRjyCVgBun1HDtGiaom+sJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1795099729; 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=XqfV3xygi1sxCzdjjD8L4mS8tUYOUq9c9D58YPg31CY=; b=M0iIcorT5tC3E2vnwHV4CxRapx3R4YCpzRgkkhzFTIgVFiZrHZ21uONO/QdEFNlL3qNvUlHWBfGFyVysYC2WYpI37LzzT4oOZ9XHr7wIMI21PoJcqyPzMPhrbmXxFf9AaAuufNg7kZktnnxd1CHDD+8ydpyegYhwlBZuQ1vl8og= 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 17950997292631010.4781338631278; Thu, 19 Nov 2026 06:48:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3QD-0004WV-5e; Thu, 19 Nov 2026 09:47:33 -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 1xU3Pv-0004R2-AZ for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:17 -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 1xU3Pp-0006DU-6m for qemu-devel@nongnu.org; Thu, 19 Nov 2026 09:47:12 -0500 Received: from DAGFR11EX3.OVH.local (unknown [10.110.0.73]) by mo15.mail-out.ovh.net (Postfix) with ESMTPS id 4jVhBT62ncz42N0; Thu, 19 Nov 2026 14:46:57 +0000 (UTC) Received: from ovhcloud.com (109.190.254.2) 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; Thu, 19 Nov 2026 15:46:56 +0100 From: Guillaume Vincke To: CC: , , , , , , , Guillaume Vincke Subject: [PATCH 5/5] block: Add refresh connection support to raw and luks Date: Thu, 19 Nov 2026 15:46:32 +0100 Message-ID: <20261119144632.232457-6-guillaume.vincke@ovhcloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> References: <20261119144632.232457-1-guillaume.vincke@ovhcloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [109.190.254.2] X-ClientProxiedBy: CAS2.OVH.local (172.16.1.2) To DAGFR11EX3.OVH.local (172.16.2.113) X-OVH-CORPLIMIT-SKIP: true x-ovh-tracer-id: 856246879468667357 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: dmFkZTGQhBK1U4xr/AMRFXRFeSFunzyiF6YtPFyxOtiBV85ZL5XARzZl8Z6U/ThfSP8t+5aj6ASB256lQMITIDvCr2bW5VG3AmVbjnFNPYSKTRwG+4DbCS6uE9SzdlmglbW/hDwGl+LfYUd+e+1PYDLewjTk7sCr/qyWO8hNVUp+rWsuv8BS/lxxOolWzCkc3Xy5dfi1Qbv4IFpRs09fIF/+f6kNcUVFFQXKiVq//Ej4Dz3sfLD8Tqa+8pP0afr1+xcIpXKR8UAhCmDiKlWfaRtcm7LIKr3ZkiesntSSjmnxh5QoyNvoLGs7VCnKrYAd4aeVDJ0oxd0UIGBSk78TrOY87RF6NyIMpuMhF1SpyAM3IA/msXwFc/bN0yJ566n9d7A+PU9kzmxp62YtFiKtIiG/T3b80vvcs08xscTmXJ3rq46l17TuFzwQcjEcdNBJ3fe8YNWWJceQCuYtcJORz1C7ckzdBSAHlylawtm92F1thiYnEifB3Wy7BsNZdhf3BOTmjT4MYAMz7FGqht48520my8drMKTeeZQBx5uYrG6BY8HANBnXpZ6vAym1yCFeac90W2WHsvRh49IOyGHgYYAGoyi1/yEPDUuLDghPxKgM1r56uIvKxYxx8IBR1yFfLPEsZwFY6VsTxy/Mgy28lok98w6klnMR/kmtgSBCJC33xPcwcg DKIM-Signature: a=rsa-sha256; bh=XqfV3xygi1sxCzdjjD8L4mS8tUYOUq9c9D58YPg31CY=; c=relaxed/relaxed; d=ovhcloud.com; h=From; s=mailout; t=1795099618; v=1; b=f46Lx5PU7W1w5H/wP469vtrqhfVNDoBkO6O4EhusLMiI+Ovws650kLk/Y4mGZeGY9NkQiNA9 6pnME+HviqSlJGnRbGSCsnb8YMoABdqkTkgxa0yDgJcpvg9WXri3pQ4913L1n2oAMUgNezWRwLc pnmHjzmL3G+zNCIN3wtB+lCg= 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=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: 1795099730099158500 Content-Type: text/plain; charset="utf-8" The bdrv_co_refresh_connection callback is used to force an idle NBD client to reconnect before the node is truncated. However, when a format node such as luks or raw is on top of the NBD node, the call is not forwarded. Implement the bdrv_co_refresh_connection callback in raw and luks to forward the request to their file child. Update the nbd-resize test to exercise it with luks and raw format drivers. Signed-off-by: Guillaume Vincke --- block/crypto.c | 7 ++++ block/raw-format.c | 7 ++++ tests/qemu-iotests/tests/nbd-resize | 51 ++++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 8a34d92fde..7e13a3a917 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -462,6 +462,12 @@ block_crypto_co_truncate(BlockDriverState *bs, int64_t= offset, bool exact, return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp); } =20 +static int coroutine_fn GRAPH_RDLOCK +block_crypto_co_refresh_connection(BlockDriverState *bs, Error **errp) +{ + return bdrv_co_refresh_connection(bs->file, errp); +} + static void block_crypto_close(BlockDriverState *bs) { BlockCrypto *crypto =3D bs->opaque; @@ -1086,6 +1092,7 @@ static BlockDriver bdrv_crypto_luks =3D { .bdrv_co_create =3D block_crypto_co_create_luks, .bdrv_co_create_opts =3D block_crypto_co_create_opts_luks, .bdrv_co_truncate =3D block_crypto_co_truncate, + .bdrv_co_refresh_connection =3D block_crypto_co_refresh_connection, .create_opts =3D &block_crypto_create_opts_luks, .amend_opts =3D &block_crypto_amend_opts_luks, =20 diff --git a/block/raw-format.c b/block/raw-format.c index a57c2922d5..389ab16201 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -432,6 +432,12 @@ raw_co_truncate(BlockDriverState *bs, int64_t offset, = bool exact, return bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp= ); } =20 +static int coroutine_fn GRAPH_RDLOCK +raw_co_refresh_connection(BlockDriverState *bs, Error **errp) +{ + return bdrv_co_refresh_connection(bs->file, errp); +} + static void coroutine_fn GRAPH_RDLOCK raw_co_eject(BlockDriverState *bs, bool eject_flag) { @@ -657,6 +663,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, .bdrv_co_truncate =3D &raw_co_truncate, + .bdrv_co_refresh_connection =3D &raw_co_refresh_connection, .bdrv_co_getlength =3D &raw_co_getlength, .is_format =3D true, .bdrv_measure =3D &raw_measure, diff --git a/tests/qemu-iotests/tests/nbd-resize b/tests/qemu-iotests/tests= /nbd-resize index 4f305eaebf..ac283c74e5 100755 --- a/tests/qemu-iotests/tests/nbd-resize +++ b/tests/qemu-iotests/tests/nbd-resize @@ -10,10 +10,34 @@ import time import iotests =20 -iotests.script_initialize(supported_fmts=3D['qcow2']) +iotests.script_initialize(supported_fmts=3D['qcow2', 'raw', 'luks']) nbd_sock =3D iotests.file_path('nbd-sock', base_dir=3Diotests.sock_dir) disk =3D iotests.file_path('disk') -node_name =3D 'nbd0' +nbd_node_name =3D 'nbd0' + +qemu_nbd_volume_format =3D iotests.imgfmt +node_name =3D nbd_node_name +format_driver_extra_opts: dict[str, object] =3D {} + +if iotests.imgfmt =3D=3D 'raw': + node_name =3D f"raw_{node_name}" + +elif iotests.imgfmt =3D=3D 'luks': + qemu_nbd_volume_format =3D 'raw' + node_name =3D f"luks_{node_name}" + format_driver_extra_opts =3D { 'key-secret': 'keysec0' } + + +def create_img(): + iotests.qemu_img_create('-f', iotests.imgfmt, disk, '1M') + + +def resize_img(): + if iotests.imgfmt =3D=3D 'qcow2': + iotests.qemu_img('resize', '-f', iotests.imgfmt, disk, '2M') + else: + # raw and luks virtual size follows the file size + iotests.qemu_img('resize', '-f', 'raw', disk, '+1M') =20 =20 def node_size(virtm): @@ -26,7 +50,8 @@ def node_size(virtm): def wait_for_parked_connection(virtm): 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) + client =3D virtm.qmp('x-debug-query-nbd-client', + node_name=3Dnbd_node_name) if client['return']['connector']['state'] =3D=3D 'parked': return time.sleep(0.1) @@ -35,29 +60,39 @@ def wait_for_parked_connection(virtm): for reconnect_delay in [10, 0]: iotests.log(f"=3D=3D=3D Resize with reconnect-delay=3D{reconnect_delay= } =3D=3D=3D") with iotests.VM() as vm: + if iotests.imgfmt =3D=3D 'luks': + vm.add_object(iotests.luks_default_secret_object) + vm.launch() =20 - iotests.qemu_img_create('-f', iotests.imgfmt, disk, '1M') + create_img() with iotests.qemu_nbd_popen('-k', nbd_sock, '-f', - iotests.imgfmt, + qemu_nbd_volume_format, disk): vm.cmd('blockdev-add', { 'driver': 'nbd', - 'node-name': node_name, + 'node-name': nbd_node_name, 'server': { 'type': 'unix', 'path': nbd_sock }, 'reconnect-delay': reconnect_delay, }) =20 + if iotests.imgfmt !=3D 'qcow2': + vm.cmd('blockdev-add', { + 'driver': iotests.imgfmt, + 'node-name': node_name, + 'file': nbd_node_name, + } | format_driver_extra_opts) + iotests.log('Size before resize:') iotests.log(node_size(vm)) =20 - iotests.qemu_img('resize', '-f', iotests.imgfmt, disk, '2M') + resize_img() with iotests.qemu_nbd_popen('-k', nbd_sock, '-f', - iotests.imgfmt, + qemu_nbd_volume_format, disk): iotests.log(vm.qmp('block_resize', { 'node-name': node_name, --=20 2.43.0