Skip to content

qcow2: Suppress data-file WRITE during creation

Hanna Czenczek qemu-devel 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 0 repliesNew
  2. v15 patches 7 repliesSuperseded

Changes in v2 from the cover letter

- Drop the new flags, use BDRV_O_NO_IO and !BDRV_O_RESIZE instead
- This necessitates making qcow2_do_open() attach the data-file child even with BDRV_O_NO_IO if the "data-file" option is a string (i.e. a node name), that's patch 2
- It also requires bypassing the block layer for resizing the qcow2 image, i.e. we need to call qcow2_co_truncate() directly instead of going through blk_co_truncate(), that's patch 4
- Fixed the typing in patch 3 for a subtraction (should have cast both new_length and m->offset to int64_t, not just the latter)
- Proper locking around bdrv_co_getlength()
- Check bdrv_co_getlength() against (int64_t)qcow2_opts->size to catch error cases (instead of not casting the latter and having the former underflow)
- Fixed f-string compatibility in the new test

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6qcow2: Skip data-file resize if possibleblock/qcow2.c+11 -40 replies
2/6qcow2: Always attach data-file given by node nameblock/qcow2.c+18 -80 replies
3/6qcow2: Preallocation: Do not COW after disk endblock/qcow2.c tests/qemu-iotests/125+29 -60 replies
4/6qcow2: Call qcow2_co_truncate() directlyblock/qcow2.c tests/qemu-iotests/206.out+18 -50 replies
5/6qcow2: Suppress data-file WRITE/RESIZE if possibleblock/qcow2.c+64 -50 replies
6/6iotests: Add qcow2-live-data-file testtests/qemu-iotests/tests/qcow2-live-data-file tests/qemu-iotests/tests/qcow2-live-data-file.out+3184 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/6] qcow2: Suppress data-file WRITE during creation

Hi,

Some people want to create a qcow2 image for an existing raw image while that raw image is in use by a VM. That is, the raw image is attached to a guest device, and the new qcow2 image is supposed to use it as its raw external data file.

This series makes that work by relaxing the permissions taken by the qcow2 driver on the external data file during qcow2 image creation, i.e. no longer taking the WRITE flag (unless preallocation was requested), which allows simultaneous use of the file e.g. as a raw image attached to the VM.

The v1 cover letter with some more info is here:

https://lists.nongnu.org/archive/html/qemu-block/2026-02/msg00090.html

v2:
- Drop the new flags, use BDRV_O_NO_IO and !BDRV_O_RESIZE instead
- This necessitates making qcow2_do_open() attach the data-file child even with BDRV_O_NO_IO if the "data-file" option is a string (i.e. a node name), that's patch 2
- It also requires bypassing the block layer for resizing the qcow2 image, i.e. we need to call qcow2_co_truncate() directly instead of going through blk_co_truncate(), that's patch 4
- Fixed the typing in patch 3 for a subtraction (should have cast both new_length and m->offset to int64_t, not just the latter)
- Proper locking around bdrv_co_getlength()
- Check bdrv_co_getlength() against (int64_t)qcow2_opts->size to catch error cases (instead of not casting the latter and having the former underflow)
- Fixed f-string compatibility in the new test

git-backport-diff against v1:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch [down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/6:[----] [--] 'qcow2: Skip data-file resize if possible' 002/6:[down] 'qcow2: Always attach data-file given by node name' 003/6:[0006] [FC] 'qcow2: Preallocation: Do not COW after disk end' 004/6:[down] 'qcow2: Call qcow2_co_truncate() directly' 005/6:[0058] [FC] 'qcow2: Suppress data-file WRITE/RESIZE if possible' 006/6:[0030] [FC] 'iotests: Add qcow2-live-data-file test'

Hanna Czenczek (6):
qcow2: Skip data-file resize if possible
qcow2: Always attach data-file given by node name
qcow2: Preallocation: Do not COW after disk end
qcow2: Call qcow2_co_truncate() directly
qcow2: Suppress data-file WRITE/RESIZE if possible
iotests: Add qcow2-live-data-file test

 block/qcow2.c                                 |  145 +-
 tests/qemu-iotests/125                        |   17 +-
 tests/qemu-iotests/206.out                    |    6 +-
 tests/qemu-iotests/tests/qcow2-live-data-file |  280 ++
 .../tests/qcow2-live-data-file.out            | 2904 +++++++++++++++++
 5 files changed, 3324 insertions(+), 28 deletions(-)
 create mode 100755 tests/qemu-iotests/tests/qcow2-live-data-file
 create mode 100644 tests/qemu-iotests/tests/qcow2-live-data-file.out
Signature · 1 line
2.53.0