vitastor-disk: Accept symlinks to whole disks in prepare #134

Merged
vitalif merged 2 commits from koolkhel/vitastor:disk-prepare-symlinks into master 2026-11-22 15:09:53 +03:00
Contributor

Description

vitastor-disk prepare looked up /sys/block/<name> by the device path as given, so a symlink to a whole disk, like /dev/disk/by-id/* or /dev/disk/by-path/*, was refused as "probably a partition". collect_devices() now resolves each path once with realpath_str() and uses the real device name after that.

One disk can now be given under several names, and the seen set meant to catch duplicates was never filled, so a disk given twice was taken twice. It is now filled with the resolved names.

What else changes:

  • A path that does not resolve is passed on as given: after the "Failed to resolve" message of realpath_str() it goes through the old checks and is reported like before ("does not start with /dev/" or "does not exist"). The test passes such a path and checks the message.
  • A symlink to a partition is still refused, under the partition's real name.
  • A symlink outside /dev that points to a whole disk is accepted too. The test uses that.

Tested: test_resize_auto.sh and OLD=1 test_resize_auto.sh pass on loop devices. The added check (two symlinks to one loop device must give exactly that device) fails without the fix: both links are refused and prepare ends with "No suitable devices found".

Not tested: device-mapper names. /dev/mapper/* resolves to /dev/dm-N and is then handled like /dev/dm-N given directly.

Contributor Name

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

CLA

### Description `vitastor-disk prepare` looked up `/sys/block/<name>` by the device path as given, so a symlink to a whole disk, like `/dev/disk/by-id/*` or `/dev/disk/by-path/*`, was refused as "probably a partition". `collect_devices()` now resolves each path once with `realpath_str()` and uses the real device name after that. One disk can now be given under several names, and the `seen` set meant to catch duplicates was never filled, so a disk given twice was taken twice. It is now filled with the resolved names. What else changes: - A path that does not resolve is passed on as given: after the "Failed to resolve" message of `realpath_str()` it goes through the old checks and is reported like before ("does not start with /dev/" or "does not exist"). The test passes such a path and checks the message. - A symlink to a partition is still refused, under the partition's real name. - A symlink outside `/dev` that points to a whole disk is accepted too. The test uses that. Tested: `test_resize_auto.sh` and `OLD=1 test_resize_auto.sh` pass on loop devices. The added check (two symlinks to one loop device must give exactly that device) fails without the fix: both links are refused and prepare ends with "No suitable devices found". Not tested: device-mapper names. `/dev/mapper/*` resolves to `/dev/dm-N` and is then handled like `/dev/dm-N` given directly. ### 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-20 07:37:23 +03:00
prepare looked up /sys/block/<name> by the device path as given, so a
symlink to a whole disk, like /dev/disk/by-id/* or /dev/disk/by-path/*,
was refused as "probably a partition". Resolve each path once at the
start of collect_devices() and use the real device name after that.

One disk can now be given under several names, and the `seen` set meant
to catch duplicates was never filled, so a disk given twice was taken
twice. Fill it with the resolved names.
vitalif reviewed 2026-11-20 18:57:39 +03:00
@@ -352,1 +352,3 @@
if (seen.find(dev) != seen.end())
// Resolve symlinks like /dev/disk/by-id/*, /sys/block/ only has real device names
std::string dev = realpath_str(orig_dev, false);
if (dev == "")
Owner

тут бы добавить ошибку при == "" - раньше на косой симлинк оно бы по крайней мере ругнулось, что он не в /dev/

тут бы добавить ошибку при == "" - раньше на косой симлинк оно бы по крайней мере ругнулось, что он не в /dev/
vitalif marked this conversation as resolved
koolkhel added 1 commit 2026-11-20 19:27:30 +03:00
A path which realpath() can't resolve was skipped with only the "Failed
to resolve" message. Pass it on as given instead, so prepare reports it
like before: "does not start with /dev/" or "does not exist".
vitalif merged commit ce33722edf into master 2026-11-22 15:09:53 +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#134
No description provided.