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

-- 
2.53.0


Reply via email to