vitastor-disk: Exit with 1 if prepare fails to initialize an OSD, list skipped disks #137

Merged
vitalif merged 8 commits from koolkhel/vitastor:prepare-exit-code into master 2026-11-23 00:10:41 +03:00
Contributor

Description

vitastor-disk prepare with a device list always exited with 0, also when an OSD failed to initialize. The failure was only visible in stderr, so a script that looks at the exit code took it for success. For example, vitastor-disk prepare --block_size 4M --data_csum_type crc32c --csum_block_size 4k /dev/sdX prints "Metadata entry size (4396 bytes) exceeds meta_block_size (4096 bytes) ..." and exits with 0.

Commits:

  1. Keep initializing the remaining OSDs, but exit with 1 if any of them failed. The single-OSD mode (--data_device) already returned the code of prepare_one().
  2. List each skipped disk with the reason in a new skipped key of the JSON output: {"osds": [...], "errors": [...], "skipped": [{"device_path": "/dev/sdb", "reason": "already_partitioned"}]}. Reasons: not_dev_path, not_found, partition, contains_data, already_partitioned. This commit also made prepare exit with 1 when it created no OSD; commit 5 takes that back.
  3. Don't list a disk given twice as skipped: the disk itself is used, only the repeated argument is ignored.
  4. With --dry-run --json and no suitable disk, print {"devices": []} instead of the JSON of a real run.
  5. Don't fail prepare when it creates no OSD (review): a prepare that skips every disk exits with 0, and the skipped disks are listed in skipped. "No suitable devices found" still exits with 1, as on master.
  6. List skipped disks by the path given (after #134): collect_devices() now resolves symlinks, so a skipped disk was listed by its real device name. It is listed by the path the caller gave, like /dev/disk/by-id/*, so the caller can match it to its arguments. The dry-run devices list keeps the resolved path, as master's test expects.

Not covered here: a failed partition creation in get_new_data_parts() still does not change the exit code.

Tested: test_resize_auto.sh and OLD=1 test_resize_auto.sh pass on loop devices. The checks: a prepare refused by the parameter check exits with non-zero; a prepare on a fully used disk, given through a symlink, exits with 0 and lists the symlink in skipped; a prepare of that disk and a fresh one creates one OSD and lists the other.

Rebased onto master after #134. Merges cleanly with #139.

Contributor Name

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

CLA

### Description `vitastor-disk prepare` with a device list always exited with 0, also when an OSD failed to initialize. The failure was only visible in stderr, so a script that looks at the exit code took it for success. For example, `vitastor-disk prepare --block_size 4M --data_csum_type crc32c --csum_block_size 4k /dev/sdX` prints "Metadata entry size (4396 bytes) exceeds meta_block_size (4096 bytes) ..." and exits with 0. Commits: 1. Keep initializing the remaining OSDs, but exit with 1 if any of them failed. The single-OSD mode (`--data_device`) already returned the code of `prepare_one()`. 2. List each skipped disk with the reason in a new `skipped` key of the JSON output: `{"osds": [...], "errors": [...], "skipped": [{"device_path": "/dev/sdb", "reason": "already_partitioned"}]}`. Reasons: `not_dev_path`, `not_found`, `partition`, `contains_data`, `already_partitioned`. This commit also made prepare exit with 1 when it created no OSD; commit 5 takes that back. 3. Don't list a disk given twice as skipped: the disk itself is used, only the repeated argument is ignored. 4. With `--dry-run --json` and no suitable disk, print `{"devices": []}` instead of the JSON of a real run. 5. Don't fail prepare when it creates no OSD (review): a prepare that skips every disk exits with 0, and the skipped disks are listed in `skipped`. "No suitable devices found" still exits with 1, as on master. 6. List skipped disks by the path given (after #134): `collect_devices()` now resolves symlinks, so a skipped disk was listed by its real device name. It is listed by the path the caller gave, like `/dev/disk/by-id/*`, so the caller can match it to its arguments. The dry-run `devices` list keeps the resolved path, as master's test expects. Not covered here: a failed partition creation in `get_new_data_parts()` still does not change the exit code. Tested: `test_resize_auto.sh` and `OLD=1 test_resize_auto.sh` pass on loop devices. The checks: a prepare refused by the parameter check exits with non-zero; a prepare on a fully used disk, given through a symlink, exits with 0 and lists the symlink in `skipped`; a prepare of that disk and a fresh one creates one OSD and lists the other. Rebased onto master after #134. Merges cleanly with #139. ### 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 1 commit 2026-11-20 08:39:02 +03:00
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.
koolkhel added 1 commit 2026-11-20 09:53:32 +03:00
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.
koolkhel added 1 commit 2026-11-20 09:54:43 +03:00
The disk itself is used, only its repeated argument is ignored.
koolkhel changed title from vitastor-disk: Exit with 1 if prepare fails to initialize an OSD to vitastor-disk: Exit with 1 if prepare fails to initialize an OSD or creates none 2026-11-20 09:54:57 +03:00
koolkhel added 1 commit 2026-11-20 11:15:55 +03:00
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.
vitalif requested changes 2026-11-20 18:53:23 +03:00
@@ -832,2 +854,3 @@
printf("%s\n", json11::Json(json11::Json::object{ { "osds", all_results }, { "errors", errors }, { "skipped", skipped_devices } }).dump().c_str());
}
return 0;
return prepare_failed || !created ? 1 : 0;
Owner

Тут нужно не возвращать ошибку, если !created

Тут нужно не возвращать ошибку, если !created
vitalif marked this conversation as resolved
koolkhel added 1 commit 2026-11-21 10:12:44 +03:00
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.
koolkhel changed title from vitastor-disk: Exit with 1 if prepare fails to initialize an OSD or creates none to vitastor-disk: Exit with 1 if prepare fails to initialize an OSD, list skipped disks 2026-11-21 10:15:49 +03:00
Author
Contributor

Сделал в fd21c3fc, как вы и писали в Telegram (идемпотентно: если всё уже создано, создавать нечего, и это не ошибка): если не создан ни один OSD, потому что все диски пропущены, prepare завершается с 0, а пропущенные диски видны в skipped в JSON. Код 1 остался для OSD, который не удалось инициализировать, и для "No suitable devices found", как в master.

Сделал в fd21c3fc, как вы и писали в Telegram (идемпотентно: если всё уже создано, создавать нечего, и это не ошибка): если не создан ни один OSD, потому что все диски пропущены, prepare завершается с 0, а пропущенные диски видны в `skipped` в JSON. Код 1 остался для OSD, который не удалось инициализировать, и для "No suitable devices found", как в master.
vitalif requested changes 2026-11-22 15:15:07 +03:00
@@ -347,1 +347,4 @@
{
auto skip = [this](const std::string & dev, const char *reason)
{
skipped_devices.push_back(json11::Json::object{ { "device_path", dev }, { "reason", reason } });
Owner

можно этот враппер убрать плиз, строчки кода он как-то не экономит)

можно этот враппер убрать плиз, строчки кода он как-то не экономит)
vitalif marked this conversation as resolved
koolkhel force-pushed prepare-exit-code from fd21c3fcb0 to 03a51506c8 2026-11-22 15:41:07 +03:00 Compare
koolkhel added 1 commit 2026-11-22 16:50:20 +03:00
Author
Contributor

можно этот враппер убрать плиз, строчки кода он как-то не экономит)

Убрал в da3b509a: обёртки skip() больше нет, записи в skipped добавляются на месте. Заодно ветка перебазирована на master после #134, и пропущенные диски теперь пишутся в skipped по пути в том виде, в каком его передали (03a51506), а не по разрешённому /dev/sdX.

> можно этот враппер убрать плиз, строчки кода он как-то не экономит) Убрал в da3b509a: обёртки `skip()` больше нет, записи в `skipped` добавляются на месте. Заодно ветка перебазирована на master после #134, и пропущенные диски теперь пишутся в `skipped` по пути в том виде, в каком его передали (03a51506), а не по разрешённому `/dev/sdX`.
koolkhel added 1 commit 2026-11-22 18:06:12 +03:00
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.
Author
Contributor

Added e648aa91: the --fast-devices overlap test from #135 now gives the fast device as a symlink to the data disk and fails on a zero exit (before, prepare … 2>&1 | grep dropped the exit code, so it passed without the return 1).

Added e648aa91: the `--fast-devices` overlap test from #135 now gives the fast device as a symlink to the data disk and fails on a zero exit (before, `prepare … 2>&1 | grep` dropped the exit code, so it passed without the `return 1`).
vitalif merged commit 74fea63bfa into master 2026-11-23 00:10:41 +03:00
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#137
No description provided.