From 48ef719166e620aea210477687e8671a30e9633c Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 09:35:41 +0300 Subject: [PATCH 1/6] vitastor-disk: Check prepare options before creating partitions prepare with a device list validated the blockstore options only in prepare_one(), after the disk was already partitioned. Options that can't work, for example a block_size with more checksums than fit into one metadata block, left the disk with empty OSD partitions. Check the options for every disk before creating any partitions, with the same HDD defaults as prepare_one(). --dry-run now refuses such options too. --- src/disk_tool/disk_tool_prepare.cpp | 48 +++++++++++++++++++++++------ tests/test_resize_auto.sh | 10 ++++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 269b47ac..7771adca 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -24,6 +24,39 @@ void disk_tool_t::parse_meta_reserve() } } +static void set_hdd_defaults(std::map & options, bool is_hybrid) +{ + if (options["block_size"] == "") + options["block_size"] = "1M"; + if (is_hybrid && options["atomic_write_size"] == "") + options["atomic_write_size"] = "0"; + if (is_hybrid && options["throttle_small_writes"] == "") + options["throttle_small_writes"] = "1"; + if (!is_hybrid && options.find("data_csum_type") != options.end() && options.at("data_csum_type") != "" && + options["csum_block_size"] == "") + options["csum_block_size"] = "32k"; +} + +// Check the options which don't depend on the partition, before creating any partitions +static int check_prepare_options(std::map options, bool is_hdd, bool is_hybrid, uint64_t disk_size) +{ + if (is_hdd) + set_hdd_defaults(options, is_hybrid); + try + { + blockstore_disk_t dsk; + dsk.parse_config(options); + dsk.data_device_size = dsk.meta_device_size = dsk.journal_device_size = disk_size; + dsk.calc_lengths(true); + } + catch (std::exception & e) + { + fprintf(stderr, "%s\n", e.what()); + return 1; + } + return 0; +} + int disk_tool_t::prepare_one(std::map options, int is_hdd, json11::Json::object & result) { static const char *allow_additional_params[] = { @@ -147,15 +180,7 @@ int disk_tool_t::prepare_one(std::map options, int is_ bool is_hybrid = is_hdd && options["journal_device"] != "" && options["journal_device"] != options["data_device"]; if (is_hdd) { - if (options["block_size"] == "") - options["block_size"] = "1M"; - if (is_hybrid && options["atomic_write_size"] == "") - options["atomic_write_size"] = "0"; - if (is_hybrid && options["throttle_small_writes"] == "") - options["throttle_small_writes"] = "1"; - if (!is_hybrid && options.find("data_csum_type") != options.end() && options.at("data_csum_type") != "" && - options["csum_block_size"] == "") - options["csum_block_size"] = "32k"; + set_hdd_defaults(options, is_hybrid); } else if (!json_is_true(options["disable_data_fsync"])) { @@ -813,6 +838,11 @@ int disk_tool_t::prepare(std::vector devices) options.erase("disable_meta_fsync"); options.erase("disable_journal_fsync"); } + for (auto & dev: devinfo) + { + if (check_prepare_options(options, dev.is_hdd, hybrid && dev.is_hdd, dev.size) != 0) + return 1; + } json11::Json::array all_results, errors; auto journal_size = options["journal_size"]; if (options.find("dry_run") != options.end()) diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 82546106..e9d60b63 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -8,6 +8,16 @@ ANTIETCD=1 dd if=/dev/zero of=./testdata/bin/test_osd1.bin bs=1 count=1 seek=$((100*1024*1024*1024-1)) LOOP1=$(sudo losetup --show -f ./testdata/bin/test_osd1.bin) trap "kill -9 $(jobs -p) || true; sudo losetup -d $LOOP1"' || true' EXIT + +# prepare should refuse invalid options before creating partitions +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 $LOOP1; then + format_error "prepare accepted options which don't fit into a metadata block" +fi +if sudo sfdisk --dump $LOOP1; then + format_error "prepare created partitions before refusing the options" +fi + dd if=/dev/zero of=./testdata/bin/test_meta.bin bs=1 count=1 seek=$((1024*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 -- 2.47.3 From ccf25f839b994b33595918f66aeb6fe8a3292b02 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 09:36:32 +0300 Subject: [PATCH 2/6] vitastor-disk: Reuse empty OSD partitions in prepare prepare meant to reuse empty OSD partitions, but counted only the initialized ones as OSD space. A disk with empty OSD partitions, for example left by a failed prepare, looked full of other data and was skipped as already partitioned, so prepare couldn't be repeated on it. Count empty OSD partitions as OSD space too. --- src/disk_tool/disk_tool_prepare.cpp | 2 ++ tests/test_resize_auto.sh | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 7771adca..bde7b029 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -596,6 +596,8 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d { // Use this partition use_parts.push_back(part["uuid"].string_value()); + // It's not other data + osds_size += part["size"].uint64_value()*dev.pt["sectorsize"].uint64_value(); } else { diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index e9d60b63..f30ac78c 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -18,6 +18,12 @@ if sudo sfdisk --dump $LOOP1; then format_error "prepare created partitions before refusing the options" fi +# prepare should reuse an empty OSD partition, for example one left by a failed prepare +echo ',,e7009fac-a5a1-4d72-af72-53de13059903' | sudo sfdisk --no-reread --no-tell-kernel --label gpt $LOOP1 +[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 1 ]] || \ + format_error "prepare didn't reuse an empty OSD partition" +sudo wipefs -a $LOOP1 + dd if=/dev/zero of=./testdata/bin/test_meta.bin bs=1 count=1 seek=$((1024*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 -- 2.47.3 From c8f4a5ab34a453d4f8bc75b8e19fc37361ff3260 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 09:57:33 +0300 Subject: [PATCH 3/6] vitastor-disk: Don't reuse or overwrite a partition with a damaged OSD superblock read_osd_superblock() returned null both when a partition had no OSD superblock and when its superblock was damaged or the partition could not be read. prepare took such a partition for an empty one: with a device list it reused it, and with --data_device it created an OSD on it without --force, although the old OSD could still be repaired by rewriting its superblock. Let read_osd_superblock() tell a damaged superblock from a missing one. prepare skips such a partition in a device list and refuses it without --force. --- src/disk_tool/disk_tool.h | 3 ++- src/disk_tool/disk_tool_prepare.cpp | 15 +++++++++++---- src/disk_tool/disk_tool_udev.cpp | 9 ++++++++- tests/test_resize_auto.sh | 11 +++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/disk_tool/disk_tool.h b/src/disk_tool/disk_tool.h index 1f910d5f..447b3924 100644 --- a/src/disk_tool/disk_tool.h +++ b/src/disk_tool/disk_tool.h @@ -155,7 +155,8 @@ struct disk_tool_t int clear_osd_superblock(const std::string & dev); int trim_data(std::string device); - json11::Json read_osd_superblock(std::string device, bool expect_exist = true, bool ignore_nonref = false); + // damaged: set if the device can't be read or has an invalid superblock, not just none + json11::Json read_osd_superblock(std::string device, bool expect_exist = true, bool ignore_nonref = false, bool *damaged = NULL); uint32_t write_osd_superblock(std::string device, json11::Json params); void parse_meta_reserve(); diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index bde7b029..df10891b 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -358,8 +358,9 @@ int disk_tool_t::check_existing_partition(std::string & dev) fprintf(stderr, "%s contains data, not creating OSD without --force. wipefs shows:\n%s", dev.c_str(), out.c_str()); return 1; } - json11::Json sb = read_osd_superblock(dev, false); - if (!sb.is_null()) + bool damaged = false; + json11::Json sb = read_osd_superblock(dev, false, false, &damaged); + if (!sb.is_null() || damaged) { fprintf(stderr, "%s already contains Vitastor OSD superblock, not creating OSD without --force\n", dev.c_str()); return 1; @@ -591,8 +592,14 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d if (strtolower(part["type"].string_value()) == VITASTOR_PART_TYPE) { // Check if an existing Vitastor partition is empty - json11::Json sb = read_osd_superblock(part["node"].string_value(), false); - if (sb.is_null()) + bool damaged = false; + json11::Json sb = read_osd_superblock(part["node"].string_value(), false, false, &damaged); + if (damaged) + { + // It may still be repaired, so it's other data + fprintf(stderr, "%s has an unreadable or invalid OSD superblock, skipping\n", part["node"].string_value().c_str()); + } + else if (sb.is_null()) { // Use this partition use_parts.push_back(part["uuid"].string_value()); diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index 504efbb9..dabc8b88 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -148,17 +148,20 @@ uint32_t disk_tool_t::write_osd_superblock(std::string device, json11::Json para return sb_size; } -json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_exist, bool ignore_errors) +json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_exist, bool ignore_errors, bool *damaged) { vitastor_disk_superblock_t *sb = NULL; uint8_t *buf = NULL; json11::Json osd_params; std::string json_err; std::string real_device, device_type, real_data, real_meta, real_journal; + bool absent = false; int r, fd = open(device.c_str(), (options["io"] == "cached" ? 0 : O_DIRECT) | O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open device %s: %s\n", device.c_str(), strerror(errno)); + if (damaged) + *damaged = true; return osd_params; } buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, 4096); @@ -173,6 +176,7 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex { if (expect_exist) fprintf(stderr, "Invalid OSD superblock on %s: magic number mismatch\n", device.c_str()); + absent = true; goto ex; } if (sb->size > VITASTOR_DISK_MAX_SB_SIZE || @@ -255,6 +259,7 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex if (expect_exist) fprintf(stderr, "Invalid OSD superblock on %s: does not refer to the device itself\n", device.c_str()); osd_params = json11::Json(); + absent = true; goto ex; } osd_params = json11::Json::object{ @@ -265,6 +270,8 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex { "real_journal_device", real_journal }, }; ex: + if (damaged) + *damaged = osd_params.is_null() && !absent; free(buf); close(fd); return osd_params; diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index f30ac78c..5dd9d1d7 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -20,9 +20,20 @@ fi # prepare should reuse an empty OSD partition, for example one left by a failed prepare echo ',,e7009fac-a5a1-4d72-af72-53de13059903' | sudo sfdisk --no-reread --no-tell-kernel --label gpt $LOOP1 +sudo partprobe $LOOP1 [[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 1 ]] || \ format_error "prepare didn't reuse an empty OSD partition" +# but not one with a damaged superblock, the OSD may still be repaired +echo '{"osd_num":987654,"data_device":"'${LOOP1}p1'"}' | sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p1 +printf X | sudo dd of=${LOOP1}p1 bs=1 seek=40 conv=notrunc +[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 0 ]] || \ + format_error "prepare would reuse an OSD partition with a damaged superblock" +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 --data_device ${LOOP1}p1; then + format_error "prepare overwrote a damaged OSD superblock without --force" +fi +sudo dd if=/dev/zero of=${LOOP1}p1 bs=4096 count=1 conv=notrunc sudo wipefs -a $LOOP1 +sudo partprobe $LOOP1 dd if=/dev/zero of=./testdata/bin/test_meta.bin bs=1 count=1 seek=$((1024*1024*1024-1)) LOOP2=$(sudo losetup --show -f ./testdata/bin/test_meta.bin) -- 2.47.3 From 3d2d20818217dfd5209114cfa3f7c8c29c0f69b3 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 20 Nov 2026 11:15:13 +0300 Subject: [PATCH 4/6] vitastor-disk: Don't reuse a partition with another device's OSD superblock A partition whose superblock names another device, for example after its partition UUID changed or a disk was cloned, was taken for an empty one and reused. Treat it like a damaged superblock instead. Count partition sizes in 512-byte sectors when sfdisk doesn't report the sector size, as free_from_parttable() does: otherwise empty and initialized OSD partitions counted as zero bytes. Also test creating an OSD on a reused empty partition. --- src/disk_tool/disk_tool_prepare.cpp | 5 +++-- src/disk_tool/disk_tool_udev.cpp | 1 - tests/test_resize_auto.sh | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index df10891b..af6c05ac 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -587,6 +587,7 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d { // Disk already has partitions. If these are empty Vitastor OSD partitions, we can use them uint64_t osds_exist = 0, osds_size = 0; + uint64_t sector_size = dev.pt["sectorsize"].uint64_value() ? dev.pt["sectorsize"].uint64_value() : 512; for (const auto & part: dev.pt["partitions"].array_items()) { if (strtolower(part["type"].string_value()) == VITASTOR_PART_TYPE) @@ -604,7 +605,7 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d // Use this partition use_parts.push_back(part["uuid"].string_value()); // It's not other data - osds_size += part["size"].uint64_value()*dev.pt["sectorsize"].uint64_value(); + osds_size += part["size"].uint64_value()*sector_size; } else { @@ -619,7 +620,7 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d ); if (is_data || sb["params"]["data_device"].string_value().substr(0, 22) != "/dev/disk/by-partuuid/") { - osds_size += part["size"].uint64_value()*dev.pt["sectorsize"].uint64_value(); + osds_size += part["size"].uint64_value()*sector_size; osds_exist++; } } diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index dabc8b88..5eaa3e7c 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -259,7 +259,6 @@ json11::Json disk_tool_t::read_osd_superblock(std::string device, bool expect_ex if (expect_exist) fprintf(stderr, "Invalid OSD superblock on %s: does not refer to the device itself\n", device.c_str()); osd_params = json11::Json(); - absent = true; goto ex; } osd_params = json11::Json::object{ diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 5dd9d1d7..65ba1973 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -19,11 +19,20 @@ if sudo sfdisk --dump $LOOP1; then fi # prepare should reuse an empty OSD partition, for example one left by a failed prepare +mount | grep '/dev type devtmpfs' || sudo mount udev /dev/ -t devtmpfs echo ',,e7009fac-a5a1-4d72-af72-53de13059903' | sudo sfdisk --no-reread --no-tell-kernel --label gpt $LOOP1 sudo partprobe $LOOP1 [[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 1 ]] || \ format_error "prepare didn't reuse an empty OSD partition" -# but not one with a damaged superblock, the OSD may still be repaired +PART_UUID=$(sudo sfdisk --part-uuid $LOOP1 1 | tr A-Z a-z) +for i in $(seq 1 100); do [[ -e /dev/disk/by-partuuid/$PART_UUID ]] && break; sleep 0.1; done +sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 $LOOP1 +sudo build/src/disk_tool/vitastor-disk read-sb ${LOOP1}p1 > /dev/null || format_error "prepare didn't create an OSD on the reused partition" +# but not one with a superblock of another device or a damaged one, the OSD may still be repaired +echo '{"osd_num":987654,"data_device":"/dev/disk/by-partuuid/00000000-0000-0000-0000-000000000000"}' | \ + sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p1 +[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 0 ]] || \ + format_error "prepare would reuse an OSD partition with a superblock of another device" echo '{"osd_num":987654,"data_device":"'${LOOP1}p1'"}' | sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p1 printf X | sudo dd of=${LOOP1}p1 bs=1 seek=40 conv=notrunc [[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 0 ]] || \ -- 2.47.3 From 3771ca9e77174b78752c3e41f62f68c2631b4208 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Sat, 21 Nov 2026 10:11:16 +0300 Subject: [PATCH 5/6] vitastor-disk: Don't reuse empty OSD partitions that fill the disk Stop counting empty OSD partitions as OSD space in prepare, so a disk mostly taken by an empty or unknown partition is skipped as before: the user removes the partition explicitly before a new OSD is created there. Test the checks for a damaged superblock and a superblock of another device on partitions small enough that prepare still uses the disk. --- src/disk_tool/disk_tool_prepare.cpp | 2 -- tests/test_resize_auto.sh | 31 +++++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index af6c05ac..a0a59c7d 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -604,8 +604,6 @@ std::vector disk_tool_t::get_new_data_parts(vitastor_dev_info_t & d { // Use this partition use_parts.push_back(part["uuid"].string_value()); - // It's not other data - osds_size += part["size"].uint64_value()*sector_size; } else { diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 65ba1973..00103805 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -18,29 +18,26 @@ if sudo sfdisk --dump $LOOP1; then format_error "prepare created partitions before refusing the options" fi -# prepare should reuse an empty OSD partition, for example one left by a failed prepare +# prepare should leave alone an OSD partition with a superblock of another device or a damaged one, +# the OSD may still be repaired. The partitions are small, so the rest of the disk is still used mount | grep '/dev type devtmpfs' || sudo mount udev /dev/ -t devtmpfs -echo ',,e7009fac-a5a1-4d72-af72-53de13059903' | sudo sfdisk --no-reread --no-tell-kernel --label gpt $LOOP1 +printf ',1G,e7009fac-a5a1-4d72-af72-53de13059903\n,1G,e7009fac-a5a1-4d72-af72-53de13059903\n' | \ + sudo sfdisk --no-reread --no-tell-kernel --label gpt $LOOP1 sudo partprobe $LOOP1 -[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 1 ]] || \ - format_error "prepare didn't reuse an empty OSD partition" -PART_UUID=$(sudo sfdisk --part-uuid $LOOP1 1 | tr A-Z a-z) -for i in $(seq 1 100); do [[ -e /dev/disk/by-partuuid/$PART_UUID ]] && break; sleep 0.1; done -sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 $LOOP1 -sudo build/src/disk_tool/vitastor-disk read-sb ${LOOP1}p1 > /dev/null || format_error "prepare didn't create an OSD on the reused partition" -# but not one with a superblock of another device or a damaged one, the OSD may still be repaired +for i in $(seq 1 100); do [[ -e ${LOOP1}p2 ]] && break; sleep 0.1; done echo '{"osd_num":987654,"data_device":"/dev/disk/by-partuuid/00000000-0000-0000-0000-000000000000"}' | \ sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p1 -[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 0 ]] || \ - format_error "prepare would reuse an OSD partition with a superblock of another device" -echo '{"osd_num":987654,"data_device":"'${LOOP1}p1'"}' | sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p1 -printf X | sudo dd of=${LOOP1}p1 bs=1 seek=40 conv=notrunc -[[ "$(sudo -E build/src/disk_tool/vitastor-disk-test prepare --dry-run --json $LOOP1 | jq '.devices[0].new_osd_count')" == 0 ]] || \ - format_error "prepare would reuse an OSD partition with a damaged superblock" -if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 --data_device ${LOOP1}p1; then +echo '{"osd_num":987654,"data_device":"'${LOOP1}p2'"}' | sudo build/src/disk_tool/vitastor-disk write-sb ${LOOP1}p2 +printf X | sudo dd of=${LOOP1}p2 bs=1 seek=40 conv=notrunc +SB_BEFORE=$(for p in 1 2; do sudo dd if=${LOOP1}p$p bs=4096 count=1 status=none; done | md5sum) +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 --data_device ${LOOP1}p2; then format_error "prepare overwrote a damaged OSD superblock without --force" fi -sudo dd if=/dev/zero of=${LOOP1}p1 bs=4096 count=1 conv=notrunc +sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 987654 $LOOP1 +[[ "$(for p in 1 2; do sudo dd if=${LOOP1}p$p bs=4096 count=1 status=none; done | md5sum)" == "$SB_BEFORE" ]] || \ + format_error "prepare reused an OSD partition with a superblock of another device or a damaged one" +sudo build/src/disk_tool/vitastor-disk read-sb ${LOOP1}p3 > /dev/null || format_error "prepare didn't create an OSD on the free space" +for p in 1 2 3; do sudo dd if=/dev/zero of=${LOOP1}p$p bs=4096 count=1 conv=notrunc; done sudo wipefs -a $LOOP1 sudo partprobe $LOOP1 -- 2.47.3 From f675a19dc21eadbcdf3567f6facbd7afe1efbb54 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Mon, 23 Nov 2026 01:49:24 +0300 Subject: [PATCH 6/6] vitastor-disk: Fail OSD initialization in the test after the options check Prepare now refuses the test's invalid options before partitioning, so the test of an OSD that fails to initialize no longer reached it. Give osd_num 0 instead, which only prepare_one() refuses, and check that the disk was partitioned before the failure. --- tests/test_resize_auto.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_resize_auto.sh b/tests/test_resize_auto.sh index 00103805..b1876c3c 100755 --- a/tests/test_resize_auto.sh +++ b/tests/test_resize_auto.sh @@ -188,10 +188,10 @@ diff ./testdata/1.json ./testdata/2.json 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 +if sudo -E build/src/disk_tool/vitastor-disk-test prepare --no_init 1 --osd_num 0 $LOOP3; then format_error "prepare exited with 0 after failing to initialize an OSD" fi +sudo sfdisk --dump $LOOP3 > /dev/null || format_error "prepare failed before partitioning, not when initializing the OSD" # 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 || \ -- 2.47.3