vitastor-disk: Check prepare options before partitioning, don't reuse damaged OSD partitions #139

Open
koolkhel wants to merge 6 commits from koolkhel/vitastor:prepare-check-before-partitioning into master

6 Commits

Author SHA1 Message Date
f675a19dc2 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.
2026-11-23 01:49:24 +03:00
3771ca9e77 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.
2026-11-23 01:46:39 +03:00
3d2d208182 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.
2026-11-23 01:46:39 +03:00
c8f4a5ab34 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.
2026-11-23 01:46:39 +03:00
ccf25f839b 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.
2026-11-23 01:46:39 +03:00
48ef719166 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.
2026-11-23 01:46:39 +03:00