Ignore image resize events after disconnect in vitastor-nbd and vitastor-ublk #156

Merged
vitalif merged 3 commits from koolkhel/vitastor:nbd-resize-after-disc into master 2026-11-25 14:42:35 +03:00

3 Commits

Author SHA1 Message Date
b411d71ead Send UPDATE_SIZE only after the device is started in vitastor-ublk
The ring consumer is registered before START_DEV, so that the server
answers the I/O the kernel sends while the disk is added, and the
synchronous control commands run the ring loop. A resize event that
arrived before the device was started therefore sent UPDATE_SIZE to a
device without a disk: kernels 6.16-6.19 without 25966fc09769
dereference NULL there, and patched kernels refuse it, so the device
kept the size given in SET_PARAMS. Keep the resize pending until the
device is started.
2026-11-25 11:12:26 +03:00
dec1295ed5 Send UPDATE_SIZE once per resize and not after stop in vitastor-ublk
try_resize() set size_changed to true instead of false, so after the
first online resize every ring loop iteration sent another
UBLK_U_CMD_UPDATE_SIZE: about 100k commands per second at full CPU, and
a log line for each on kernels without UPDATE_SIZE.

The commands also went on in the final flush after unmap had stopped
the device. UPDATE_SIZE on a stopped device crashes 6.16-6.19 kernels
without 25966fc09769 ("ublk: fix NULL pointer dereference in
ublk_ctrl_set_size()"). Don't resize once the server is stopping, and
submit the command at once rather than with some later submit.
2026-11-24 22:59:15 +03:00
8ac1eea221 Ignore image resize events after NBD disconnect in vitastor-nbd
vitastor-nbd kept its image watch during the final flush, after the NBD
device was already disconnected. A resize of the image in that time
made it call NBD_SET_SIZE on the device, which by then could be mapped
again to another image and so got the wrong size.

Close the watch when the main loop ends with the device disconnected.
After SIGINT or SIGTERM the device is still connected and the flush
still reads requests, which use the watch, so it stays open there.
2026-11-24 13:06:00 +03:00