partially fix #3227: ensure that target image for mirror has the same size for EFI disks

When the format is raw, the size can be explicitly passed. When the
format is a container format like qcow2, the image should already be
allocated with the correct virtual size.

It is not possible to resize a disk with an explicit 'size' set, so
only set this for EFI disks.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2025-07-02 18:28:23 +02:00 committed by Fabian Grünbichler
parent 82391f066b
commit f5fc943c07
2 changed files with 19 additions and 1 deletions

View file

@ -455,6 +455,24 @@ sub blockdev_mirror {
my $attach_dest_opts = { 'no-throttle' => 1 };
$attach_dest_opts->{'zero-initialized'} = 1 if $dest->{'zero-initialized'};
# Source and target need to have the exact same virtual size, see bug #3227.
# However, it won't be possible to resize a disk with 'size' explicitly set afterwards, so only
# set it for EFI disks.
if ($drive_id eq 'efidisk0' && !PVE::QemuServer::Blockdev::is_nbd($dest_drive)) {
my ($storeid) = PVE::Storage::parse_volume_id($dest_drive->{file}, 1);
if (
$storeid
&& PVE::QemuServer::Drive::checked_volume_format($storecfg, $dest->{volid}) eq 'raw'
) {
my $block_info = PVE::QemuServer::Blockdev::get_block_info($vmid);
if (my $size = $block_info->{$drive_id}->{inserted}->{image}->{'virtual-size'}) {
$attach_dest_opts->{size} = $size;
} else {
log_warn("unable to determine source block node size - continuing anyway");
}
}
}
# Note that if 'aio' is not explicitly set, i.e. default, it can change if source and target
# don't both allow or both not allow 'io_uring' as the default.
my $target_node_name =

View file

@ -19,7 +19,7 @@ use PVE::QemuServer::Monitor qw(mon_cmd);
my $NBD_TCP_PATH_RE_3 = qr/nbd:(\S+):(\d+):exportname=(\S+)/;
my $NBD_UNIX_PATH_RE_2 = qr/nbd:unix:(\S+):exportname=(\S+)/;
my sub is_nbd {
sub is_nbd {
my ($drive) = @_;
return 1 if $drive->{file} =~ $NBD_TCP_PATH_RE_3;