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
Contributor

Description

Commits for vitastor-disk prepare with a device list:

  1. Check prepare options before creating partitions. The blockstore options were validated only in prepare_one(), after the disk was already partitioned. Options that can't work, for example --block_size 4M --data_csum_type crc32c --csum_block_size 4k (more checksums than fit into one metadata block), left the disk with empty OSD partitions. Now the options are checked for every disk before any partition is created, with the same HDD defaults as prepare_one(). --dry-run refuses them too.
  2. Count empty OSD partitions as OSD space: dropped after review by commit 5.
  3. Don't reuse or overwrite a partition with a damaged OSD superblock. read_osd_superblock(dev, false) returned null both for a missing superblock and for a damaged one (valid magic, bad size, checksum or JSON) or an unreadable partition. get_new_data_parts() already uses empty OSD partitions on a disk that passes the max_other_percent check, and took such a partition for an empty one; --data_device without --force created an OSD on it too, although the old OSD could still be repaired by rewriting its superblock. read_osd_superblock() now reports a damaged superblock through an optional out-parameter; prepare skips such a partition in a device list and refuses it without --force.
  4. Don't reuse a partition with another device's OSD superblock. A superblock that names another device (the partition UUID changed, a cloned disk) was taken for none; it is now treated like a damaged one. Partition sizes are counted in 512-byte sectors when sfdisk doesn't report sectorsize, as free_from_parttable() does (before, initialized OSD partitions counted as zero bytes then).
  5. Don't reuse empty OSD partitions that fill the disk (review): a disk mostly taken by an empty or unknown partition is skipped as before, and the user removes the partition. The checks of commits 3 and 4 now use two small partitions next to free space: a real prepare must leave their superblocks unchanged and create the OSD in a new partition.

Tested: tests/test_resize_auto.sh and OLD=1 tests/test_resize_auto.sh pass. With the damaged-superblock skip disabled, the check of commits 3 and 4 fails. Rebased onto master after #137; the last commit adjusts its OSD initialization failure test to the options check.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description Commits for `vitastor-disk prepare` with a device list: 1. **Check prepare options before creating partitions.** The blockstore options were validated only in `prepare_one()`, after the disk was already partitioned. Options that can't work, for example `--block_size 4M --data_csum_type crc32c --csum_block_size 4k` (more checksums than fit into one metadata block), left the disk with empty OSD partitions. Now the options are checked for every disk before any partition is created, with the same HDD defaults as `prepare_one()`. `--dry-run` refuses them too. 2. Count empty OSD partitions as OSD space: dropped after review by commit 5. 3. **Don't reuse or overwrite a partition with a damaged OSD superblock.** `read_osd_superblock(dev, false)` returned null both for a missing superblock and for a damaged one (valid magic, bad size, checksum or JSON) or an unreadable partition. `get_new_data_parts()` already uses empty OSD partitions on a disk that passes the `max_other_percent` check, and took such a partition for an empty one; `--data_device` without `--force` created an OSD on it too, although the old OSD could still be repaired by rewriting its superblock. `read_osd_superblock()` now reports a damaged superblock through an optional out-parameter; prepare skips such a partition in a device list and refuses it without `--force`. 4. **Don't reuse a partition with another device's OSD superblock.** A superblock that names another device (the partition UUID changed, a cloned disk) was taken for none; it is now treated like a damaged one. Partition sizes are counted in 512-byte sectors when sfdisk doesn't report `sectorsize`, as `free_from_parttable()` does (before, initialized OSD partitions counted as zero bytes then). 5. **Don't reuse empty OSD partitions that fill the disk** (review): a disk mostly taken by an empty or unknown partition is skipped as before, and the user removes the partition. The checks of commits 3 and 4 now use two small partitions next to free space: a real prepare must leave their superblocks unchanged and create the OSD in a new partition. Tested: `tests/test_resize_auto.sh` and `OLD=1 tests/test_resize_auto.sh` pass. With the damaged-superblock skip disabled, the check of commits 3 and 4 fails. Rebased onto master after #137; the last commit adjusts its OSD initialization failure test to the options check. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 2 commits 2026-11-20 09:45:33 +03:00
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.
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.
koolkhel added 1 commit 2026-11-20 09:57:36 +03:00
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.
koolkhel changed title from vitastor-disk: Check prepare options before partitioning, reuse empty OSD partitions to vitastor-disk: Check prepare options before partitioning, reuse only empty OSD partitions 2026-11-20 09:57:48 +03:00
koolkhel added 1 commit 2026-11-20 11:15:16 +03:00
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.
Owner

Тут не нужно добавлять переиспользование пустых разделов. Генеральная линия такая - если есть пустой/непонятный раздел, не трогаем его, пусть юзер его явно удалит и тогда можно создавать новый.

Тут не нужно добавлять переиспользование пустых разделов. Генеральная линия такая - если есть пустой/непонятный раздел, не трогаем его, пусть юзер его явно удалит и тогда можно создавать новый.
vitalif requested changes 2026-11-20 19:19:01 +03:00
vitalif left a comment
Owner

выше отписал (требуется коммент при request changes)

выше отписал (требуется коммент при request changes)
koolkhel added 1 commit 2026-11-21 10:12:44 +03:00
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.
koolkhel changed title from vitastor-disk: Check prepare options before partitioning, reuse only empty OSD partitions to vitastor-disk: Check prepare options before partitioning, don't reuse damaged OSD partitions 2026-11-21 10:15:51 +03:00
Author
Contributor

Убрал в 52d16e66: пустые разделы OSD больше не считаются местом под OSD, и диск с пустым или непонятным разделом пропускается, как раньше. В PR остались проверка параметров до разметки и защита раздела с битым суперблоком или суперблоком другого устройства: в списке дисков такой раздел пропускается, а с --data_device без --force prepare от него отказывается.

В Telegram вы написали, что пустые разделы вообще не надо подхватывать автоматически. Сейчас get_new_data_parts() в master ещё берёт мелкие пустые разделы OSD, если диск проходит проверку max_other_percent. Предлагаю убрать и это: тогда проверка битого суперблока в режиме списка не нужна, останется только отказ с --data_device без --force. Если согласны, сделаю отдельным коммитом в этом PR.

Убрал в 52d16e66: пустые разделы OSD больше не считаются местом под OSD, и диск с пустым или непонятным разделом пропускается, как раньше. В PR остались проверка параметров до разметки и защита раздела с битым суперблоком или суперблоком другого устройства: в списке дисков такой раздел пропускается, а с `--data_device` без `--force` prepare от него отказывается. В Telegram вы написали, что пустые разделы вообще не надо подхватывать автоматически. Сейчас `get_new_data_parts()` в master ещё берёт мелкие пустые разделы OSD, если диск проходит проверку `max_other_percent`. Предлагаю убрать и это: тогда проверка битого суперблока в режиме списка не нужна, останется только отказ с `--data_device` без `--force`. Если согласны, сделаю отдельным коммитом в этом PR.
koolkhel force-pushed prepare-check-before-partitioning from 52d16e66d1 to f675a19dc2 2026-11-23 01:49:28 +03:00 Compare
Author
Contributor

Rebased onto master 4ee30fa7 (with #137). The rebase applied cleanly, and one commit is added on top, f675a19d: the #137 test "prepare should exit with an error when it fails to initialize an OSD" used the same invalid options that this PR now refuses before partitioning, so it no longer reached prepare_one(). It now gives --osd_num 0, which only prepare_one() refuses, and checks that the disk was partitioned before the failure. test_resize_auto.sh and OLD=1 test_resize_auto.sh pass; with return prepare_failed ? 1 : 0 changed to return 0 the test fails.

Rebased onto master 4ee30fa7 (with #137). The rebase applied cleanly, and one commit is added on top, f675a19d: the #137 test "prepare should exit with an error when it fails to initialize an OSD" used the same invalid options that this PR now refuses before partitioning, so it no longer reached `prepare_one()`. It now gives `--osd_num 0`, which only `prepare_one()` refuses, and checks that the disk was partitioned before the failure. `test_resize_auto.sh` and `OLD=1 test_resize_auto.sh` pass; with `return prepare_failed ? 1 : 0` changed to `return 0` the test fails.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u prepare-check-before-partitioning:koolkhel-prepare-check-before-partitioning
git checkout koolkhel-prepare-check-before-partitioning
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#139
No description provided.