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.

(See https://issues.redhat.com/browse/RHEL-128573 -- specifically, the
idea is to allow incremental backups on a previously raw image.)

One reason why that currently does not work is that formatting the qcow2
image requires write access, which will automatically result in taking
the WRITE permission on the data-file child, i.e. the raw image.  If
that image is currently in use and thus the WRITE permission is not
shared, the qcow2 image cannot be created.  However, without data
preallocation, we don't really need to write to the data file, so this
series allows qcow2 to relax that requirement to make formatting work
while the data-file child is in use.

NOTE: One exception for needing the WRITE permission without data
preallocation is when creating a qcow2 image with a guest disk size that
is not aligned to the cluster size.  Then, we will implicitly COW the
cluster tail past the end of the guest disk.  I think that is
unnecessary, so commit 3 removes it.  This will cause images whose guest
disk size is not aligned to full clusters have a partial data cluster at
the end, after creation.  I think that’s fine, but maybe not...?

---

Side note: Another reason why it's difficult to replace a raw image with
a qcow2 image using that raw image as a raw data file is because we
don't have a comprehensive QMP command to fully replace one node by
another (there is no QMP command for bdrv_replace_node()).  You can kind
of get around that via qom-set for guest devices and blockdev-reopen for
in-graph changes, but (1) there is no command for changing a block
export's node yet, (2) this is not fully transactionable, and (3) it's
cumbersome.  blockdev-replace is supposed to solve (1) and can probably
also be made transactionable later to solve (2), but maybe we still want
a simple command that just calls bdrv_replace_node() for the case where
a user just wants to fully replace one node by another.

But this series does not concern itself with that problem.


Hanna Czenczek (5):
  qcow2: Skip data-file resize if possible
  block: Introduce BDRV_O_NO_DATA_{WRITE,RESIZE}
  qcow2: Preallocation: Do not COW after disk end
  qcow2: Suppress data-file WRITE/RESIZE if possible
  iotests: Add qcow2-live-data-file test

 include/block/block-common.h                  |   11 +
 block.c                                       |   15 +
 block/qcow2.c                                 |   96 +-
 tests/qemu-iotests/125                        |   17 +-
 tests/qemu-iotests/tests/qcow2-live-data-file |  274 ++
 .../tests/qcow2-live-data-file.out            | 2904 +++++++++++++++++
 6 files changed, 3302 insertions(+), 15 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.52.0


Reply via email to