Open the device read-only in vitastor-nbd unmap #162
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:nbd-unmap-rdonly"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
vitastor-nbd unmapopened the NBD device read-write only to sendNBD_DISCONNECT. When it closes a writable descriptor, udev gets an inotify close-after-write event for the device (thewatchoption of60-block.rules, which coversnbd*) and opens the device itself. After the disconnect requestnbd_open()marks the disk for a partition rescan, so that open rereads the partition table. Ifvitastor-nbddoes not answer at that moment (stopped, or stuck before it reads the disconnect), the read never completes:blkdev_open→bdev_open_by_dev→blkdev_get_whole→bdev_disk_changed→read_part_sector, holding the disk's open lock;unmapitself waits for the same lock inclose()(blkdev_release→bdev_release) when udev wins the race;WatchdogSec, 3 minutes), or untilvitastor-nbdcontinues.NBD_DISCONNECTneeds no write access (nbd_ioctl()checks onlyCAP_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,SIGSTOPto the servingvitastor-nbd,vitastor-nbd unmap. With master4ee30fa7, 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 leftunmapitself 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
Давай это без теста замержим
0800fb1891to7541e0390b