From 450cf4963b020acd5bdfed993cb2f903d3b218b8 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 07:37:07 +0300 Subject: [PATCH 1/2] vitastor-disk: Accept symlinks to whole disks in prepare prepare looked up /sys/block/ 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. --- src/disk_tool/disk_tool_prepare.cpp | 13 ++++++++++--- tests/test_resize_auto.sh | 5 +++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index ea20f7a7..eee11ea3 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -347,13 +347,20 @@ std::vector disk_tool_t::collect_devices(const std::vector< { std::vector devinfo; std::set seen; - for (auto & dev: devices) + for (auto & orig_dev: devices) { - 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 == "") { - fprintf(stderr, "%s is specified multiple times, ignoring\n", dev.c_str()); continue; } + if (seen.find(dev) != seen.end()) + { + fprintf(stderr, "%s is specified multiple times, ignoring\n", orig_dev.c_str()); + continue; + } + seen.insert(dev); // Check if the device is a whole disk if (dev.substr(0, 5) != "/dev/") { diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 53589557..106770dd 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -15,6 +15,11 @@ trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2"' || true' EXIT # also test prepare --hybrid :) # non-vitastor random type UUID to prevent udev activation mount | grep '/dev type devtmpfs' || sudo mount udev /dev/ -t devtmpfs +# prepare should resolve symlinks (like /dev/disk/by-id/*) and take each disk only once +ln -s $LOOP1 ./testdata/bin/test_osd1_link1 +ln -s $LOOP1 ./testdata/bin/test_osd1_link2 +sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json ./testdata/bin/test_osd1_link1 ./testdata/bin/test_osd1_link2 | + jq -e '[ .devices[].device_path ] == [ "'$LOOP1'" ]' sudo -E build/src/disk_tool/vitastor-disk-test prepare $OFFSET_ARGS --no_init 1 --meta_reserve 1x,1M \ --block_size 131072 --osd_num 987654 --part_type_uuid 0df42ae0-3695-4395-a957-7d5ff3645c56 \ --hybrid --fast-devices $LOOP2 $LOOP1 -- 2.47.3 From 7b72edda686940e3bb5640be771401024f1be387 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 19:27:28 +0300 Subject: [PATCH 2/2] vitastor-disk: Keep the old checks for paths which fail to resolve in prepare 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". --- src/disk_tool/disk_tool_prepare.cpp | 6 +----- tests/test_resize_auto.sh | 8 +++++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index eee11ea3..0e8d46a7 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -350,11 +350,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< for (auto & orig_dev: devices) { // Resolve symlinks like /dev/disk/by-id/*, /sys/block/ only has real device names - std::string dev = realpath_str(orig_dev, false); - if (dev == "") - { - continue; - } + std::string dev = realpath_str(orig_dev); if (seen.find(dev) != seen.end()) { fprintf(stderr, "%s is specified multiple times, ignoring\n", orig_dev.c_str()); diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 106770dd..e8f4c7d6 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -15,11 +15,13 @@ trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2"' || true' EXIT # also test prepare --hybrid :) # non-vitastor random type UUID to prevent udev activation mount | grep '/dev type devtmpfs' || sudo mount udev /dev/ -t devtmpfs -# prepare should resolve symlinks (like /dev/disk/by-id/*) and take each disk only once +# prepare should resolve symlinks (like /dev/disk/by-id/*), take each disk only once +# and complain about a path which doesn't resolve ln -s $LOOP1 ./testdata/bin/test_osd1_link1 ln -s $LOOP1 ./testdata/bin/test_osd1_link2 -sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json ./testdata/bin/test_osd1_link1 ./testdata/bin/test_osd1_link2 | - jq -e '[ .devices[].device_path ] == [ "'$LOOP1'" ]' +sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json ./testdata/bin/test_osd1_link1 ./testdata/bin/test_osd1_link2 \ + ./testdata/bin/test_osd1_nolink 2>./testdata/prepare_err.txt | jq -e '[ .devices[].device_path ] == [ "'$LOOP1'" ]' +grep 'test_osd1_nolink does not start with /dev/, ignoring' ./testdata/prepare_err.txt sudo -E build/src/disk_tool/vitastor-disk-test prepare $OFFSET_ARGS --no_init 1 --meta_reserve 1x,1M \ --block_size 131072 --osd_num 987654 --part_type_uuid 0df42ae0-3695-4395-a957-7d5ff3645c56 \ --hybrid --fast-devices $LOOP2 $LOOP1 -- 2.47.3