[pve-devel] [PATCH qemu-server 6/6] fix #6543: use qcow2 'discard-no-unref' option when using snapshot-as-volume-chain

Fiona Ebner f.ebner at proxmox.com
Fri Jul 25 10:24:11 CEST 2025


Am 25.07.25 um 9:39 AM schrieb Fabian Grünbichler:
> On July 24, 2025 3:59 pm, Fiona Ebner wrote:
>> diff --git a/src/PVE/QemuServer/QemuImage.pm b/src/PVE/QemuServer/QemuImage.pm
>> index 026c24e9..7f6d5f01 100644
>> --- a/src/PVE/QemuServer/QemuImage.pm
>> +++ b/src/PVE/QemuServer/QemuImage.pm
>> @@ -3,6 +3,9 @@ package PVE::QemuServer::QemuImage;
>>  use strict;
>>  use warnings;
>>  
>> +use Fcntl qw(S_ISBLK);
>> +use File::stat;
>> +
>>  use PVE::Format qw(render_bytes);
>>  use PVE::Storage;
>>  use PVE::Tools;
>> @@ -27,6 +30,18 @@ sub convert_iscsi_path {
>>      die "cannot convert iscsi path '$path', unknown format\n";
>>  }
>>  
>> +my sub qcow2_target_image_opts {
>> +    my ($path, @qcow2_opts) = @_;
>> +
>> +    my $st = File::stat::stat($path) or die "stat for '$path' failed - $!\n";
> 
> right now this is only called for PVE-managed volumes.. so we could
> actually call qemu_blockdev_options instead in `convert` below, and use
> the driver (and possibly other things?) from there?

I guess that could also be done for iscsi as a next step and we could go
on and always use target-image-opts constructed from the return value of
qemu_blockdev_options(). Sadly, target-image-opts doesn't take JSON as
input AFAICS, so the conversion to string is a bit more cumbersome.

> 
>> +
>> +    my $driver = S_ISBLK($st->mode) ? 'host_device' : 'file';
>> +
>> +    my $qcow2_opts_str = ',' . join(',', @qcow2_opts);
>> +
>> +    return "driver=qcow2$qcow2_opts_str,file.driver=$driver,file.filename=$path";
>> +}
>> +
>>  # The possible options are:
>>  # bwlimit - The bandwidth limit in KiB/s.
>>  # is-zero-initialized - If the destination image is zero-initialized.
>> @@ -71,6 +86,7 @@ sub convert {
>>      my $dst_format = checked_volume_format($storecfg, $dst_volid);
>>      my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
>>      my $dst_is_iscsi = ($dst_path =~ m|^iscsi://|);
>> +    my $dst_needs_discard_no_unref = $dst_scfg->{'snapshot-as-volume-chain'};
> 
> && $dst_format eq 'qcow2'
> 
> as above in Blockdev.pm?

Yes, nice catch!




More information about the pve-devel mailing list