block/block-backend.c | 12 +++ block/crypto.c | 7 ++ block/io.c | 24 +++++ block/nbd.c | 95 +++++++++++++++---- block/raw-format.c | 7 ++ blockdev.c | 9 ++ include/block/block-io.h | 8 ++ include/block/block_int-common.h | 3 + include/block/nbd.h | 1 + include/system/block-backend-io.h | 2 + nbd/client-connection.c | 7 +- tests/qemu-iotests/tests/nbd-resize | 116 ++++++++++++++++++++++++ tests/qemu-iotests/tests/nbd-resize.out | 24 +++++ 13 files changed, 297 insertions(+), 18 deletions(-) create mode 100755 tests/qemu-iotests/tests/nbd-resize create mode 100644 tests/qemu-iotests/tests/nbd-resize.out
When using an NBD backed device, the size is exchanged during handshake. Therefore, when a volume gets resized on the target, it closes its clients' connections to force a new handshake. Then, management like OpenStack calls the block_resize QMP command to update the node size. This method works on active devices but, considering the NBD client reconnection is lazy, the handshake does not happen on idle ones which leads to a "Cannot grow NBD nodes" error when calling block_resize. This patchset adds a function to manually trigger reconnection on an NBD device and calls it in the block_resize QMP command to make sure the new size gets exchanged before trying to update the device internals. It also implements the refresh callback in the raw and luks drivers, which forward it to their file child. Based-on: <20261105164124.249395-1-guillaume.vincke@ovhcloud.com> Needed to detect if the channel was closed by the server. Based-on: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> Needed to implement a deterministic test. Guillaume Vincke (5): block/nbd: Extract request slot access and reconnection block: Refresh the connection before block_resize block/nbd: Refresh the connection on block_resize iotests: Add coverage for NBD resize block: Add refresh connection support to raw and luks block/block-backend.c | 12 +++ block/crypto.c | 7 ++ block/io.c | 24 +++++ block/nbd.c | 95 +++++++++++++++---- block/raw-format.c | 7 ++ blockdev.c | 9 ++ include/block/block-io.h | 8 ++ include/block/block_int-common.h | 3 + include/block/nbd.h | 1 + include/system/block-backend-io.h | 2 + nbd/client-connection.c | 7 +- tests/qemu-iotests/tests/nbd-resize | 116 ++++++++++++++++++++++++ tests/qemu-iotests/tests/nbd-resize.out | 24 +++++ 13 files changed, 297 insertions(+), 18 deletions(-) create mode 100755 tests/qemu-iotests/tests/nbd-resize create mode 100644 tests/qemu-iotests/tests/nbd-resize.out base-commit: 6883fb508cb7a93e2e7b44c0582bfd9fc2196d4d prerequisite-patch-id: 484bee7f7d30179f284198c8fc5162830f56b2e2 prerequisite-patch-id: 73f560b55444e04d1615f3351b13a47f375bcd82 prerequisite-patch-id: 722470bc9ae187fc429d7af8a5f3eefb46bf80d7 prerequisite-patch-id: 6c1f8d46edf0e6dc070764a755d34740855af4f1 -- 2.43.0
[cc NBD list for a protocol discussion] On Thu, Nov 19, 2026 at 03:46:27PM +0100, Guillaume Vincke wrote: > When using an NBD backed device, the size is exchanged during > handshake. Therefore, when a volume gets resized on the target, it > closes its clients' connections to force a new handshake. Then, > management like OpenStack calls the block_resize QMP command to update > the node size. > This method works on active devices but, considering the NBD client > reconnection is lazy, the handshake does not happen on idle ones which > leads to a "Cannot grow NBD nodes" error when calling block_resize. > > This patchset adds a function to manually trigger reconnection on an > NBD device and calls it in the block_resize QMP command to make sure > the new size gets exchanged before trying to update the device > internals. It also implements the refresh callback in the raw and luks > drivers, which forward it to their file child. Before I even review this series, I wonder if it is time to consider reviving discussion on the upstream NBD protocol mailing list about an extension to allow NBD to optionally support resize messages. If I recall the last time it was discussed several years ago, there are competing needs: some scenarios want resize to be driven by the server (for example, in response to a high-water write event done by the client, the server detects that storage should grow; now the server needs to advertise to the client that the exported volume is larger); and some want it to be driven by the client (the client wants to specifically ask the server for the export size to grow; the server may or may not be able to comply). NBD is normally client-driven, so a client asking the server for a new size is easy to implement by documenting a new NBD_CMD_RESIZE (in fact, opcode 8 is already reserved for this in the NBD protocol document). But the server being able to advertise a new size to the client is an event-driven task, not client-driven. Here, structured commands and the fact that the protocol allows out-of-order responses appears to provide a nice solution - the idea was that a new command initiated by the client requests an open-ended registration of resize events, and the server can reply with as many chunks as wanted over a long length of time reusing the client's cookie, and not using the NBD_REPLY_FLAG_DONE flag to end the stream of reply chunks until the client deregisters from the request (either two new NBD_CMD to register/deregister, or one command with a client flag to request registration or deregistration). Ultimately, having NBD able to support live resizes will be even nicer than forcing client reconnections just to learn a new server size. That said, your series probably still has merit, because even if we extend the NBD protocol to allow live resize, it may take a while before both client and server ends are upgraded to understand the new protocol extension, while this reconnection should work with older protocol. > > Based-on: <20261105164124.249395-1-guillaume.vincke@ovhcloud.com> > Needed to detect if the channel was closed by the server. > > Based-on: <20261113140852.702959-1-guillaume.vincke@ovhcloud.com> > Needed to implement a deterministic test. Based on the dependencies, this is definitely qemu 12.0 material, not 11.2; but that shouldn't stop me from starting review now. -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
On 11/19/26 17:20, Eric Blake wrote: > [cc NBD list for a protocol discussion] > > On Thu, Nov 19, 2026 at 03:46:27PM +0100, Guillaume Vincke wrote: >> When using an NBD backed device, the size is exchanged during >> handshake. Therefore, when a volume gets resized on the target, it >> closes its clients' connections to force a new handshake. Then, >> management like OpenStack calls the block_resize QMP command to update >> the node size. >> This method works on active devices but, considering the NBD client >> reconnection is lazy, the handshake does not happen on idle ones which >> leads to a "Cannot grow NBD nodes" error when calling block_resize. >> >> This patchset adds a function to manually trigger reconnection on an >> NBD device and calls it in the block_resize QMP command to make sure >> the new size gets exchanged before trying to update the device >> internals. It also implements the refresh callback in the raw and luks >> drivers, which forward it to their file child. > > Before I even review this series, I wonder if it is time to consider > reviving discussion on the upstream NBD protocol mailing list about an > extension to allow NBD to optionally support resize messages. > > If I recall the last time it was discussed several years ago, there > are competing needs: some scenarios want resize to be driven by the > server (for example, in response to a high-water write event done by > the client, the server detects that storage should grow; now the > server needs to advertise to the client that the exported volume is > larger); and some want it to be driven by the client (the client wants > to specifically ask the server for the export size to grow; the server > may or may not be able to comply). NBD is normally client-driven, so > a client asking the server for a new size is easy to implement by > documenting a new NBD_CMD_RESIZE (in fact, opcode 8 is already > reserved for this in the NBD protocol document). > > But the server being able to advertise a new size to the client is an > event-driven task, not client-driven. Here, structured commands and > the fact that the protocol allows out-of-order responses appears to > provide a nice solution - the idea was that a new command initiated by > the client requests an open-ended registration of resize events, and > the server can reply with as many chunks as wanted over a long length > of time reusing the client's cookie, and not using the > NBD_REPLY_FLAG_DONE flag to end the stream of reply chunks until the > client deregisters from the request (either two new NBD_CMD to > register/deregister, or one command with a client flag to request > registration or deregistration). > > Ultimately, having NBD able to support live resizes will be even nicer > than forcing client reconnections just to learn a new server size. > That said, your series probably still has merit, because even if we > extend the NBD protocol to allow live resize, it may take a while > before both client and server ends are upgraded to understand the new > protocol extension, while this reconnection should work with older > protocol. > I suppose you're talking about the resize extension https://github.com/NetworkBlockDevice/nbd/blob/extension-resize/doc/proto.md?plain=1#L1366 It would cover my use case nicely. Since management grows the volume first, sending the NBD_CMD_RESIZE in block_resize would work. The reason why I decided not to go that route is because getting the extension accepted looked like a lot more than the current changes. Moreover, the two approaches can coexist. Handling resizes done on the server through a reconnection does not prevent the integration of the client-side solution in the future. Live resize would indeed be a nicer option. If you back it up, I would be happy to submit a patch to QEMU with the client-initiated live resize. If I get it right, your suggestion for server-side initiated resize has a lot in common with NVMe's Asynchronous Event Request. That pattern could help with other events like the server going away or space running low.
© 2016 - 2026 Red Hat, Inc.