On Fri 19 Jun 2020 12:40:11 PM CEST, Max Reitz wrote:
> + if (qcow2_opts->data_file_raw &&
> + qcow2_opts->preallocation == PREALLOC_MODE_OFF)
> + {
> + /*
> + * data-file-raw means that "the external data file can be
> + * read as a consistent standalone raw image without looking
> + * at the qcow2 metadata." It does not say that the metadata
> + * must be ignored, though (and the qcow2 driver in fact does
> + * not ignore it), so the L1/L2 tables must be present and
> + * give a 1:1 mapping, so you get the same result regardless
> + * of whether you look at the metadata or whether you ignore
> + * it.
> + */
> + qcow2_opts->preallocation = PREALLOC_MODE_METADATA;
I'm not convinced by this, but your comment made me think of another
possible alternative: in qcow2_get_cluster_offset(), if the cluster is
unallocated and we are using a raw data file then we return _ZERO_PLAIN:
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -654,6 +654,10 @@ out:
assert(bytes_available - offset_in_cluster <= UINT_MAX);
*bytes = bytes_available - offset_in_cluster;
+ if (type == QCOW2_CLUSTER_UNALLOCATED && data_file_is_raw(bs)) {
+ type = QCOW2_CLUSTER_ZERO_PLAIN;
+ }
+
return type;
You could even add a '&& bs->backing' to the condition and emit a
warning to make it more explicit.
Berto