Check that the image exists in qemu_driver create instead of always succeeding #185

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:qemu-create-check into master
Contributor

Description

qemu-img create -f raw vitastor:image=<name> <size> printed Formatting… and exited with 0, but
vitastor_co_create_opts() didn't create anything: the next open failed with image does not exist,
and for an existing smaller image the size silently stayed the same.

QEMU can't create Vitastor images, so create now opens the named image read-only (the same way
block/crypto.c opens the protocol layer in its create: bdrv_open() before 8.0, bdrv_co_open()
from 8.0, bdrv_co_unref() from 8.1) and:

  • fails if the image doesn't exist: Can't open the image (QEMU doesn't create Vitastor images, use vitastor-cli create): image does not exist;
  • fails if the image is smaller than the requested size: Image is smaller than requested: 33554432 < 67108864 bytes (QEMU doesn't resize Vitastor images, use vitastor-cli modify --resize);
  • succeeds without writing anything if the image is large enough, or if no size is passed (luks and qcow2
    strip it before creating the protocol layer). So qemu-img convert without -n into an existing image,
    as in the docs, keeps working;
  • inode addressing (pool=…:inode=…:size=…) is unchanged: inodes need no creation.

The docs (docs/usage/qemu.{en,ru}.md) now say that the target image must exist and be at least as
large as the source.

Tested: new tests/test_qemu_img_create.sh (missing image, smaller image, same size, qemu-img convert
without -n into a larger image with a data check, inode addressing). The same five cases were run
against QEMU 8.2.2 with this driver: all pass, and the missing/smaller cases exit with 0 without the
change. The pre-8.0 path (bdrv_open() + bdrv_unref() in the create coroutine) was not run: bdrv_open()
has this signature in the QEMU 2.12–7.2 headers, and block/crypto.c calls both from its create coroutine there.

The test sets IMMEDIATE_COMMIT=1 because qemu-img convert uses cache=unsafe by default and never
flushes: with immediate_commit=none the data read back after the convert didn't match (from byte 1).

Contributor Name

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

CLA

### Description `qemu-img create -f raw vitastor:image=<name> <size>` printed `Formatting…` and exited with 0, but `vitastor_co_create_opts()` didn't create anything: the next open failed with `image does not exist`, and for an existing smaller image the size silently stayed the same. QEMU can't create Vitastor images, so create now opens the named image read-only (the same way `block/crypto.c` opens the protocol layer in its create: `bdrv_open()` before 8.0, `bdrv_co_open()` from 8.0, `bdrv_co_unref()` from 8.1) and: - fails if the image doesn't exist: `Can't open the image (QEMU doesn't create Vitastor images, use vitastor-cli create): image does not exist`; - fails if the image is smaller than the requested size: `Image is smaller than requested: 33554432 < 67108864 bytes (QEMU doesn't resize Vitastor images, use vitastor-cli modify --resize)`; - succeeds without writing anything if the image is large enough, or if no size is passed (luks and qcow2 strip it before creating the protocol layer). So `qemu-img convert` without `-n` into an existing image, as in the docs, keeps working; - inode addressing (`pool=…:inode=…:size=…`) is unchanged: inodes need no creation. The docs (`docs/usage/qemu.{en,ru}.md`) now say that the target image must exist and be at least as large as the source. Tested: new `tests/test_qemu_img_create.sh` (missing image, smaller image, same size, `qemu-img convert` without `-n` into a larger image with a data check, inode addressing). The same five cases were run against QEMU 8.2.2 with this driver: all pass, and the missing/smaller cases exit with 0 without the change. The pre-8.0 path (`bdrv_open()` + `bdrv_unref()` in the create coroutine) was not run: `bdrv_open()` has this signature in the QEMU 2.12–7.2 headers, and `block/crypto.c` calls both from its create coroutine there. The test sets `IMMEDIATE_COMMIT=1` because `qemu-img convert` uses `cache=unsafe` by default and never flushes: with `immediate_commit=none` the data read back after the convert didn't match (from byte 1). ### 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-25 03:19:56 +03:00
qemu-img create on a named image reported success without creating it,
so the next open failed with "image does not exist", and an existing
smaller image silently kept its size. QEMU can't create Vitastor images,
so open the image instead and fail if it doesn't exist or is smaller
than the requested size. qemu-img convert into an existing image that is
large enough keeps working without -n; inode addressing is unchanged.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 qemu-create-check:koolkhel-qemu-create-check
git checkout koolkhel-qemu-create-check
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#185
No description provided.