Open the device read-only in vitastor-nbd unmap #162

Merged
vitalif merged 1 commits from koolkhel/vitastor:nbd-unmap-rdonly into master 2026-11-27 13:55:08 +03:00
Contributor

Description

vitastor-nbd unmap opened the NBD device read-write only to send NBD_DISCONNECT. When it closes a writable descriptor, udev gets an inotify close-after-write event for the device (the watch option of 60-block.rules, which covers nbd*) and opens the device itself. After the disconnect request nbd_open() marks the disk for a partition rescan, so that open rereads the partition table. If vitastor-nbd does not answer at that moment (stopped, or stuck before it reads the disconnect), the read never completes:

  • udevd's main process stays in D state: blkdev_open → bdev_open_by_dev → blkdev_get_whole → bdev_disk_changed → read_part_sector, holding the disk's open lock;
  • unmap itself waits for the same lock in close() (blkdev_release → bdev_release) when udev wins the race;
  • device events on the host stall until systemd kills udevd by its watchdog (WatchdogSec, 3 minutes), or until vitastor-nbd continues.

NBD_DISCONNECT needs no write access (nbd_ioctl() checks only CAP_SYS_ADMIN), so the fix opens the device read-only. Closing it then makes no close-after-write event, and udev does not touch the device.

Reproduced in a VM (Ubuntu 24.04, kernel 6.8.0-142, udev running) with tests/run_3osds.sh: map, SIGSTOP to the serving vitastor-nbd, vitastor-nbd unmap. With master 4ee30fa7, udevd's main process was stuck in the partition rescan after 6 unmaps of 6. With this PR, after none of 6. On a host with kernel 6.8.0-64 the same sequence also left unmap itself hanging in about half of the runs, and udevd was restarted by its watchdog.

Tested by the reproduction above. The PR adds no test to tests/.

Not checked: kernels older than 6.8.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description `vitastor-nbd unmap` opened the NBD device read-write only to send `NBD_DISCONNECT`. When it closes a writable descriptor, udev gets an inotify close-after-write event for the device (the `watch` option of `60-block.rules`, which covers `nbd*`) and opens the device itself. After the disconnect request `nbd_open()` marks the disk for a partition rescan, so that open rereads the partition table. If `vitastor-nbd` does not answer at that moment (stopped, or stuck before it reads the disconnect), the read never completes: - udevd's main process stays in D state: `blkdev_open` → `bdev_open_by_dev` → `blkdev_get_whole` → `bdev_disk_changed` → `read_part_sector`, holding the disk's open lock; - `unmap` itself waits for the same lock in `close()` (`blkdev_release` → `bdev_release`) when udev wins the race; - device events on the host stall until systemd kills udevd by its watchdog (`WatchdogSec`, 3 minutes), or until `vitastor-nbd` continues. `NBD_DISCONNECT` needs no write access (`nbd_ioctl()` checks only `CAP_SYS_ADMIN`), so the fix opens the device read-only. Closing it then makes no close-after-write event, and udev does not touch the device. Reproduced in a VM (Ubuntu 24.04, kernel 6.8.0-142, udev running) with `tests/run_3osds.sh`: map, `SIGSTOP` to the serving `vitastor-nbd`, `vitastor-nbd unmap`. With master 4ee30fa7, udevd's main process was stuck in the partition rescan after 6 unmaps of 6. With this PR, after none of 6. On a host with kernel 6.8.0-64 the same sequence also left `unmap` itself hanging in about half of the runs, and udevd was restarted by its watchdog. Tested by the reproduction above. The PR adds no test to `tests/`. Not checked: kernels older than 6.8. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-23 13:43:26 +03:00
vitastor-nbd unmap opened the NBD device read-write only to send
NBD_DISCONNECT. Closing a writable descriptor makes udev open the
device, and after the disconnect request the kernel then rereads the
partition table. If vitastor-nbd does not answer at that moment, for
example because it is stopped, udevd hangs in that read with the
device's open lock held, and the close in unmap waits for the same lock.
NBD_DISCONNECT needs no write access.
vitalif requested changes 2026-11-24 12:27:09 +03:00
vitalif left a comment
Owner

Давай это без теста замержим

Давай это без теста замержим
koolkhel force-pushed nbd-unmap-rdonly from 0800fb1891 to 7541e0390b 2026-11-24 12:55:37 +03:00 Compare
vitalif merged commit 4810971d96 into master 2026-11-27 13:55:08 +03:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#162
No description provided.