I understand that this is preexisting logic, but could I ask: why?
if driver can guarantee that created file is all-zero, but is not sure
file resizing? I agree that it's normal for these flags to have the same
but what is the reason for this restriction?..
If areas added by truncation (or growth, rather) are always zero, then
the file can always be created with size 0 and grown from there. Thus,
images where truncation adds zeroed areas will generally always be zero
So, the only possible combination of flags, when they differs, is
truncate=1.. How is it possible?
For preallocated qcow2 images, it depends on the storage whether they
are actually 0 after creation. Hence qcow2_has_zero_init() then defers
to bdrv_has_zero_init() of s->data_file->bs.
But when you truncate them (with PREALLOC_MODE_OFF, as
BlockDriver.bdrv_has_zero_init_truncate()’s comment explains), the new
area is always going to be 0, regardless of initial preallocation.
I just noticed a bug there, though: Encrypted qcow2 images will not see
areas added through growth as 0. Hence, qcow2’s
bdrv_has_zero_init_truncate() implementation should not return true
unconditionally, but only for unencrypted images.