From d95ac612bdf3fd7ec9b84ce6698224e83df86b79 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 08:03:03 +0300 Subject: [PATCH] vitastor-disk: Refuse a disk given both as data and in --fast-devices prepare collects the device list and --fast-devices separately, so a disk given in both got two entries, each with its own copy of the partition table, and they overwrote each other's new partitions. The data partition of such a disk was dropped right after it was created, its OSD was not initialized, and the journal and metadata partitions made for it were left behind. Refuse such a command before anything is changed. --- src/disk_tool/disk_tool_prepare.cpp | 11 +++++++++++ tests/test_resize_auto.sh | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index ea20f7a7..29aae933 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -728,6 +728,17 @@ int disk_tool_t::prepare(std::vector devices) fprintf(stderr, "No fast devices found\n"); return 1; } + for (auto & ssd: ssds) + { + for (auto & dev: devinfo) + { + if (dev.path == ssd.path) + { + fprintf(stderr, "%s is specified both in the device list and in --fast-devices\n", dev.path.c_str()); + return 1; + } + } + } if (options["journal_size"] == "") { auto auto_journal_size = DEFAULT_HYBRID_SSD_JOURNAL; diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 53589557..665e760b 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -12,6 +12,10 @@ dd if=/dev/zero of=./testdata/bin/test_meta.bin bs=1 count=1 seek=$((1024*1024*1 LOOP2=$(sudo losetup --show -f ./testdata/bin/test_meta.bin) trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2"' || true' EXIT +# prepare should refuse a disk given both in the device list and in --fast-devices +sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --hybrid --fast-devices $LOOP1 $LOOP1 2>&1 | + grep 'both in the device list and in --fast-devices' + # also test prepare --hybrid :) # non-vitastor random type UUID to prevent udev activation mount | grep '/dev type devtmpfs' || sudo mount udev /dev/ -t devtmpfs -- 2.47.3