From e936d9737543e1a928791c9e24890c5a08f7f68b Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 08:38:37 +0300 Subject: [PATCH 1/8] vitastor-disk: Exit with 1 if prepare fails to initialize an OSD prepare with a device list ignored the result of prepare_one() and always exited with 0, even when none of the OSDs was initialized. The failure was only visible in stderr and in "errors" of the JSON output. Keep initializing the remaining OSDs, but exit with 1 if any of them failed. --- src/disk_tool/disk_tool_prepare.cpp | 6 +++++- tests/test_resize_auto.sh | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index c6621567..805158d6 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -819,6 +819,8 @@ int disk_tool_t::prepare(std::vector devices) printf("%s\n", json11::Json(json11::Json::object{{ "devices", results }}).dump().c_str()); return 0; } + // An OSD that fails doesn't stop the others, but the command fails + bool prepare_failed = false; for (auto & dev: devinfo) { // Select new partitions and create an OSD on each of them @@ -839,6 +841,8 @@ int disk_tool_t::prepare(std::vector devices) // Treat all disks as SSDs if not in the hybrid mode json11::Json::object result; int r = prepare_one(options, dev.is_hdd ? 1 : 0, result); + if (r != 0) + prepare_failed = true; if (json) { if (!r) @@ -858,5 +862,5 @@ int disk_tool_t::prepare(std::vector devices) { printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors } }).dump().c_str()); } - return 0; + return prepare_failed ? 1 : 0; } diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index b0c3eaa4..1872194b 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -147,4 +147,13 @@ sudo -E build/src/disk_tool/vitastor-disk-test resize --data-size max ${LOOP1}p1 sudo -E build/src/disk_tool/vitastor-disk dump-meta ${LOOP1}p1 | jq -S '. + {"entries": (.entries | sort_by(.stripe)) }' > ./testdata/2.json diff ./testdata/1.json ./testdata/2.json +# prepare should exit with an error when it fails to initialize an OSD +dd if=/dev/zero of=./testdata/bin/test_bad.bin bs=1 count=1 seek=$((1024*1024*1024-1)) +LOOP3=$(sudo losetup --show -f ./testdata/bin/test_bad.bin) +trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2 $LOOP3"' || true' EXIT +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 \ + --block_size 4M --data_csum_type crc32c --csum_block_size 4k $LOOP3; then + format_error "prepare exited with 0 after failing to initialize an OSD" +fi + format_green OK -- 2.47.3 From c061180135bf040954e78931ea6ec2b4a6670b26 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 09:53:28 +0300 Subject: [PATCH 2/8] vitastor-disk: Exit with 1 if prepare creates no OSD, list skipped disks prepare with a device list exited with 0 when every disk was skipped, for example as already partitioned, although no OSD was created, and the JSON output didn't mention the skipped disks. Exit with 1 when no OSD is created, and list each skipped disk with the reason in "skipped" of the JSON output. A disk skipped while OSDs are created on other disks still gives exit code 0. --- src/disk_tool/disk_tool.h | 2 ++ src/disk_tool/disk_tool_prepare.cpp | 22 ++++++++++++++++++++-- tests/test_resize_auto.sh | 13 +++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/disk_tool/disk_tool.h b/src/disk_tool/disk_tool.h index b0f3a427..4440b257 100644 --- a/src/disk_tool/disk_tool.h +++ b/src/disk_tool/disk_tool.h @@ -53,6 +53,8 @@ struct disk_tool_t bool dump_with_blocks = false, dump_with_data = false; bool dump_as_old = false; int log_level = 1; + // prepare: disks given but not used, for the JSON output + json11::Json::array skipped_devices; double meta_reserve_multiple = 2; uint64_t meta_reserve_min_size = (uint64_t)1024*1024*1024; blockstore_disk_t dsk; diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 805158d6..3e6e13ea 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -361,6 +361,10 @@ std::vector disk_tool_t::collect_devices(const std::vector< { std::vector devinfo; std::set seen; + auto skip = [this](const std::string & dev, const char *reason) + { + skipped_devices.push_back(json11::Json::object{ { "device_path", dev }, { "reason", reason } }); + }; for (auto & orig_dev: devices) { // Resolve symlinks like /dev/disk/by-id/*, /sys/block/ only has real device names @@ -368,6 +372,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (seen.find(dev) != seen.end()) { fprintf(stderr, "%s is specified multiple times, ignoring\n", orig_dev.c_str()); + skip(dev, "duplicate"); continue; } seen.insert(dev); @@ -375,6 +380,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (dev.substr(0, 5) != "/dev/") { fprintf(stderr, "%s does not start with /dev/, ignoring\n", dev.c_str()); + skip(dev, "not_dev_path"); continue; } struct stat sys_st; @@ -386,6 +392,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< else if (!dev_size) { fprintf(stderr, "%s does not exist, skipping\n", dev.c_str()); + skip(dev, "not_found"); continue; } if (stat(("/sys/block/"+dev.substr(5)).c_str(), &sys_st) < 0) @@ -393,6 +400,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (errno == ENOENT) { fprintf(stderr, "%s is probably a partition (no entry in /sys/block/), ignoring\n", dev.c_str()); + skip(dev, "partition"); continue; } fprintf(stderr, "Error checking /sys/block/%s: %s\n", dev.c_str()+5, strerror(errno)); @@ -415,6 +423,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (r != 0 || out != "") { fprintf(stderr, "%s contains data, skipping:\n %s\n", dev.c_str(), str_replace(trim(out), "\n", "\n ").c_str()); + skip(dev, "contains_data"); continue; } } @@ -590,6 +599,7 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d if (osds_exist >= osd_per_disk || (dev.free+osds_size) < dev.size*(100-max_other_percent)/100) { fprintf(stderr, "%s is already partitioned, skipping\n", dev.path.c_str()); + skipped_devices.push_back(json11::Json::object{ { "device_path", dev.path }, { "reason", "already_partitioned" } }); use_parts.clear(); } else @@ -713,6 +723,9 @@ int disk_tool_t::prepare(std::vector devices) if (!devinfo.size()) { fprintf(stderr, "No suitable devices found\n"); + if (json) + printf("%s\n", json11::Json(json11::Json::object{ { "osds", json11::Json::array() }, + { "errors", json11::Json::array() }, { "skipped", skipped_devices } }).dump().c_str()); return 1; } bool explicit_fast = options.find("fast_devices") != options.end(); @@ -821,6 +834,7 @@ int disk_tool_t::prepare(std::vector devices) } // An OSD that fails doesn't stop the others, but the command fails bool prepare_failed = false; + int created = 0; for (auto & dev: devinfo) { // Select new partitions and create an OSD on each of them @@ -843,6 +857,8 @@ int disk_tool_t::prepare(std::vector devices) int r = prepare_one(options, dev.is_hdd ? 1 : 0, result); if (r != 0) prepare_failed = true; + else + created++; if (json) { if (!r) @@ -858,9 +874,11 @@ int disk_tool_t::prepare(std::vector devices) } } } + if (!created) + fprintf(stderr, "No OSDs were created\n"); if (json) { - printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors } }).dump().c_str()); + printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors }, { "skipped", skipped_devices } }).dump().c_str()); } - return prepare_failed ? 1 : 0; + return prepare_failed || !created ? 1 : 0; } diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 1872194b..59860213 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -156,4 +156,17 @@ if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num format_error "prepare exited with 0 after failing to initialize an OSD" fi +# prepare should exit with 1 when it creates no OSD, and list the skipped disks in JSON +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 > ./testdata/prepare.json; then + format_error "prepare exited with 0 without creating an OSD" +fi +[[ "$(jq -c '[(.osds | length), .skipped]' ./testdata/prepare.json)" == '[0,[{"device_path":"'$LOOP1'","reason":"already_partitioned"}]]' ]] || \ + format_error "prepare didn't list the skipped disk" +dd if=/dev/zero of=./testdata/bin/test_osd4.bin bs=1 count=1 seek=$((10*1024*1024*1024-1)) +LOOP4=$(sudo losetup --show -f ./testdata/bin/test_osd4.bin) +trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2 $LOOP3 $LOOP4"' || true' EXIT +sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 $LOOP4 > ./testdata/prepare.json +[[ "$(jq -c '[(.osds | length), .skipped[0].device_path]' ./testdata/prepare.json)" == '[1,"'$LOOP1'"]' ]] || \ + format_error "prepare didn't create an OSD on one disk and skip the other" + format_green OK -- 2.47.3 From 0e696c9498ffb53161277f16ca785eed1d59f4c6 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 09:53:55 +0300 Subject: [PATCH 3/8] vitastor-disk: Don't list a disk given twice as skipped The disk itself is used, only its repeated argument is ignored. --- src/disk_tool/disk_tool_prepare.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 3e6e13ea..79072594 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -359,12 +359,12 @@ int disk_tool_t::fix_partition_type(std::string & dev) std::vector disk_tool_t::collect_devices(const std::vector & devices) { - std::vector devinfo; - std::set seen; auto skip = [this](const std::string & dev, const char *reason) { skipped_devices.push_back(json11::Json::object{ { "device_path", dev }, { "reason", reason } }); }; + std::vector devinfo; + std::set seen; for (auto & orig_dev: devices) { // Resolve symlinks like /dev/disk/by-id/*, /sys/block/ only has real device names @@ -372,7 +372,6 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (seen.find(dev) != seen.end()) { fprintf(stderr, "%s is specified multiple times, ignoring\n", orig_dev.c_str()); - skip(dev, "duplicate"); continue; } seen.insert(dev); -- 2.47.3 From f99b62bc5c22367d1eb5a61d482bd76f24a9f66b Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 11:15:53 +0300 Subject: [PATCH 4/8] vitastor-disk: Print the dry-run JSON shape when prepare finds no disk With --dry-run --json and no suitable disk, prepare printed the JSON of a real run instead of {"devices": []}. Also test the JSON output and the exit code when no disk is suitable. --- src/disk_tool/disk_tool_prepare.cpp | 4 +++- tests/test_resize_auto.sh | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 79072594..bc7319d0 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -722,7 +722,9 @@ int disk_tool_t::prepare(std::vector devices) if (!devinfo.size()) { fprintf(stderr, "No suitable devices found\n"); - if (json) + if (json && options.find("dry_run") != options.end()) + printf("%s\n", json11::Json(json11::Json::object{ { "devices", json11::Json::array() } }).dump().c_str()); + else if (json) printf("%s\n", json11::Json(json11::Json::object{ { "osds", json11::Json::array() }, { "errors", json11::Json::array() }, { "skipped", skipped_devices } }).dump().c_str()); return 1; diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 59860213..da606833 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -168,5 +168,12 @@ trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2 $LOOP3 $LOOP4"' sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 $LOOP4 > ./testdata/prepare.json [[ "$(jq -c '[(.osds | length), .skipped[0].device_path]' ./testdata/prepare.json)" == '[1,"'$LOOP1'"]' ]] || \ format_error "prepare didn't create an OSD on one disk and skip the other" +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --json /dev/nonexistent > ./testdata/prepare.json; then + format_error "prepare exited with 0 without a suitable disk" +fi +[[ "$(jq -c .skipped ./testdata/prepare.json)" == '[{"device_path":"/dev/nonexistent","reason":"not_found"}]' ]] || \ + format_error "prepare didn't list a missing disk" +[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json /dev/nonexistent | jq -c .devices)" == '[]' ]] || \ + format_error "prepare --dry-run printed the wrong JSON without a suitable disk" format_green OK -- 2.47.3 From 8a6ffae3cffc8d9a07b92478fc9ec45fb5ed54a7 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sat, 21 Nov 2026 10:12:16 +0300 Subject: [PATCH 5/8] vitastor-disk: Don't fail prepare when it creates no OSD A prepare that skips every disk, for example because they are already partitioned, has nothing to do rather than failing. Exit with 0 then; the skipped disks are listed in the JSON output. An OSD that fails to initialize still makes prepare exit with 1. --- src/disk_tool/disk_tool_prepare.cpp | 7 +------ tests/test_resize_auto.sh | 7 +++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index bc7319d0..0433dc61 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -835,7 +835,6 @@ int disk_tool_t::prepare(std::vector devices) } // An OSD that fails doesn't stop the others, but the command fails bool prepare_failed = false; - int created = 0; for (auto & dev: devinfo) { // Select new partitions and create an OSD on each of them @@ -858,8 +857,6 @@ int disk_tool_t::prepare(std::vector devices) int r = prepare_one(options, dev.is_hdd ? 1 : 0, result); if (r != 0) prepare_failed = true; - else - created++; if (json) { if (!r) @@ -875,11 +872,9 @@ int disk_tool_t::prepare(std::vector devices) } } } - if (!created) - fprintf(stderr, "No OSDs were created\n"); if (json) { printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors }, { "skipped", skipped_devices } }).dump().c_str()); } - return prepare_failed || !created ? 1 : 0; + return prepare_failed ? 1 : 0; } diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index da606833..2bb640c9 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -156,10 +156,9 @@ if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num format_error "prepare exited with 0 after failing to initialize an OSD" fi -# prepare should exit with 1 when it creates no OSD, and list the skipped disks in JSON -if sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 > ./testdata/prepare.json; then - format_error "prepare exited with 0 without creating an OSD" -fi +# prepare should exit with 0 when it skips every disk, and list the skipped disks in JSON +sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 > ./testdata/prepare.json || \ + format_error "prepare failed when it had nothing to do" [[ "$(jq -c '[(.osds | length), .skipped]' ./testdata/prepare.json)" == '[0,[{"device_path":"'$LOOP1'","reason":"already_partitioned"}]]' ]] || \ format_error "prepare didn't list the skipped disk" dd if=/dev/zero of=./testdata/bin/test_osd4.bin bs=1 count=1 seek=$((10*1024*1024*1024-1)) -- 2.47.3 From 03a51506c8f5575c280aa347dc979c97c6ae1632 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 22 Nov 2026 15:40:41 +0300 Subject: [PATCH 6/8] vitastor-disk: List skipped disks by the path given prepare resolves symlinks in the device list, so a skipped disk was listed by its real device name rather than by the path the caller gave, like /dev/disk/by-id/*. List it by the path as given, so the caller can match the skipped disks to its arguments. --- src/disk_tool/disk_tool.h | 1 + src/disk_tool/disk_tool_prepare.cpp | 11 ++++++----- tests/test_resize_auto.sh | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/disk_tool/disk_tool.h b/src/disk_tool/disk_tool.h index 4440b257..1f910d5f 100644 --- a/src/disk_tool/disk_tool.h +++ b/src/disk_tool/disk_tool.h @@ -36,6 +36,7 @@ struct resizer_data_moving_t; struct vitastor_dev_info_t { std::string path; + std::string orig_path; // as given on the command line, for the "skipped" JSON bool is_hdd; json11::Json pt; // pt = partition table int osd_part_count; diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 0433dc61..c6ce1eee 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -379,7 +379,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (dev.substr(0, 5) != "/dev/") { fprintf(stderr, "%s does not start with /dev/, ignoring\n", dev.c_str()); - skip(dev, "not_dev_path"); + skip(orig_dev, "not_dev_path"); continue; } struct stat sys_st; @@ -391,7 +391,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< else if (!dev_size) { fprintf(stderr, "%s does not exist, skipping\n", dev.c_str()); - skip(dev, "not_found"); + skip(orig_dev, "not_found"); continue; } if (stat(("/sys/block/"+dev.substr(5)).c_str(), &sys_st) < 0) @@ -399,7 +399,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (errno == ENOENT) { fprintf(stderr, "%s is probably a partition (no entry in /sys/block/), ignoring\n", dev.c_str()); - skip(dev, "partition"); + skip(orig_dev, "partition"); continue; } fprintf(stderr, "Error checking /sys/block/%s: %s\n", dev.c_str()+5, strerror(errno)); @@ -422,7 +422,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (r != 0 || out != "") { fprintf(stderr, "%s contains data, skipping:\n %s\n", dev.c_str(), str_replace(trim(out), "\n", "\n ").c_str()); - skip(dev, "contains_data"); + skip(orig_dev, "contains_data"); continue; } } @@ -432,6 +432,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< osds++; devinfo.push_back((vitastor_dev_info_t){ .path = dev, + .orig_path = orig_dev, .is_hdd = is_hdd, .pt = pt, .osd_part_count = osds, @@ -598,7 +599,7 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d if (osds_exist >= osd_per_disk || (dev.free+osds_size) < dev.size*(100-max_other_percent)/100) { fprintf(stderr, "%s is already partitioned, skipping\n", dev.path.c_str()); - skipped_devices.push_back(json11::Json::object{ { "device_path", dev.path }, { "reason", "already_partitioned" } }); + skipped_devices.push_back(json11::Json::object{ { "device_path", dev.orig_path }, { "reason", "already_partitioned" } }); use_parts.clear(); } else diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 2bb640c9..d4fa7538 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -156,11 +156,11 @@ if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num format_error "prepare exited with 0 after failing to initialize an OSD" fi -# prepare should exit with 0 when it skips every disk, and list the skipped disks in JSON -sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 $LOOP1 > ./testdata/prepare.json || \ +# prepare should exit with 0 when it skips every disk, and list the skipped disks in JSON by the path given +sudo -E build/src/disk_tool/vitastor-disk-test prepare --json --no_init 1 --osd_num 987655 ./testdata/bin/test_osd1_link1 > ./testdata/prepare.json || \ format_error "prepare failed when it had nothing to do" -[[ "$(jq -c '[(.osds | length), .skipped]' ./testdata/prepare.json)" == '[0,[{"device_path":"'$LOOP1'","reason":"already_partitioned"}]]' ]] || \ - format_error "prepare didn't list the skipped disk" +[[ "$(jq -c '[(.osds | length), .skipped]' ./testdata/prepare.json)" == '[0,[{"device_path":"./testdata/bin/test_osd1_link1","reason":"already_partitioned"}]]' ]] || \ + format_error "prepare didn't list the skipped disk by the path given" dd if=/dev/zero of=./testdata/bin/test_osd4.bin bs=1 count=1 seek=$((10*1024*1024*1024-1)) LOOP4=$(sudo losetup --show -f ./testdata/bin/test_osd4.bin) trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1 $LOOP2 $LOOP3 $LOOP4"' || true' EXIT -- 2.47.3 From da3b509a3e07cab449f683ceab871daca56a6148 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 22 Nov 2026 16:49:54 +0300 Subject: [PATCH 7/8] vitastor-disk: Remove the skip() wrapper from collect_devices() --- src/disk_tool/disk_tool_prepare.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index c6ce1eee..269b47ac 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -359,10 +359,6 @@ int disk_tool_t::fix_partition_type(std::string & dev) std::vector disk_tool_t::collect_devices(const std::vector & devices) { - auto skip = [this](const std::string & dev, const char *reason) - { - skipped_devices.push_back(json11::Json::object{ { "device_path", dev }, { "reason", reason } }); - }; std::vector devinfo; std::set seen; for (auto & orig_dev: devices) @@ -379,7 +375,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (dev.substr(0, 5) != "/dev/") { fprintf(stderr, "%s does not start with /dev/, ignoring\n", dev.c_str()); - skip(orig_dev, "not_dev_path"); + skipped_devices.push_back(json11::Json::object{ { "device_path", orig_dev }, { "reason", "not_dev_path" } }); continue; } struct stat sys_st; @@ -391,7 +387,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< else if (!dev_size) { fprintf(stderr, "%s does not exist, skipping\n", dev.c_str()); - skip(orig_dev, "not_found"); + skipped_devices.push_back(json11::Json::object{ { "device_path", orig_dev }, { "reason", "not_found" } }); continue; } if (stat(("/sys/block/"+dev.substr(5)).c_str(), &sys_st) < 0) @@ -399,7 +395,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (errno == ENOENT) { fprintf(stderr, "%s is probably a partition (no entry in /sys/block/), ignoring\n", dev.c_str()); - skip(orig_dev, "partition"); + skipped_devices.push_back(json11::Json::object{ { "device_path", orig_dev }, { "reason", "partition" } }); continue; } fprintf(stderr, "Error checking /sys/block/%s: %s\n", dev.c_str()+5, strerror(errno)); @@ -422,7 +418,7 @@ std::vector disk_tool_t::collect_devices(const std::vector< if (r != 0 || out != "") { fprintf(stderr, "%s contains data, skipping:\n %s\n", dev.c_str(), str_replace(trim(out), "\n", "\n ").c_str()); - skip(orig_dev, "contains_data"); + skipped_devices.push_back(json11::Json::object{ { "device_path", orig_dev }, { "reason", "contains_data" } }); continue; } } -- 2.47.3 From e648aa91693ee0553b2dab14e5d670e396b1cb24 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sun, 22 Nov 2026 18:06:10 +0300 Subject: [PATCH 8/8] vitastor-disk: Check the exit code in the --fast-devices overlap test The test gave the same path twice and piped prepare into grep, so it passed without the "return 1" and never went through a symlink. Give the fast device as a symlink to the data disk and fail on a zero exit. --- tests/test_resize_auto.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index d4fa7538..82546106 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -12,9 +12,13 @@ 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' +# prepare should refuse a disk given both in the device list and in --fast-devices, also through a symlink +ln -s $LOOP1 ./testdata/bin/test_osd1_fast +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --hybrid --fast-devices ./testdata/bin/test_osd1_fast $LOOP1 \ + 2>./testdata/prepare_err.txt; then + format_error "prepare accepted a disk given both in the device list and in --fast-devices" +fi +grep 'both in the device list and in --fast-devices' ./testdata/prepare_err.txt # also test prepare --hybrid :) # non-vitastor random type UUID to prevent udev activation -- 2.47.3