fix #4012: migrate: mention snapshots referencing a local ISO image

When a VM has no local ISO image attached anymore, but one of its
snapshots still references it, migration fails with:

  can't migrate local disk 'local:iso/debian.iso': local cdrom image

which does not tell where the image is coming from, since it is not
visible in the current configuration of the VM.

Add the names of the snapshots referencing the image to the error in
that case, like it is already done for a physical CD/DVD drive. The
check for the physical drive now reuses the same hint.

Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-10-03 01:44:51 +02:00
1 parent 5fa8c46714
commit fed54ce52a
2 files changed
+54 -7

No files matched your search

+7 -7
View File
@@ -412,15 +412,15 @@ sub scan_local_volumes {
} }
my $snaprefs = $attr->{referenced_in_snapshot}; my $snaprefs = $attr->{referenced_in_snapshot};
my $snapshot_hint = '';
if (defined($snaprefs) && !$attr->{is_attached}) {
my $snapnames = join(', ', sort keys %$snaprefs);
$snapshot_hint = " (referenced in snapshot - $snapnames)";
}
if ($attr->{cdrom}) { if ($attr->{cdrom}) {
if ($volid eq 'cdrom') { if ($volid eq 'cdrom') {
my $msg = "can't migrate local cdrom drive"; &$log_error("can't migrate local cdrom drive$snapshot_hint\n");
if (defined($snaprefs) && !$attr->{is_attached}) {
my $snapnames = join(', ', sort keys %$snaprefs);
$msg .= " (referenced in snapshot - $snapnames)";
}
&$log_error("$msg\n");
return; return;
} }
return if $volid eq 'none'; return if $volid eq 'none';
@@ -475,7 +475,7 @@ sub scan_local_volumes {
$local_volumes->{$volid}->{ref} = 'generated'; $local_volumes->{$volid}->{ref} = 'generated';
return; return;
} }
die "local cdrom image\n"; die "local cdrom image$snapshot_hint\n";
} }
my ($path, $owner) = PVE::Storage::path($storecfg, $volid); my ($path, $owner) = PVE::Storage::path($storecfg, $volid);
+47
View File
@@ -37,6 +37,7 @@ my $storage_config = {
local => { local => {
content => { content => {
images => 1, images => 1,
iso => 1,
}, },
path => "/var/lib/vz", path => "/var/lib/vz",
type => "dir", type => "dir",
@@ -346,6 +347,17 @@ my $source_vdisks = {
'volid' => 'local-dir:4567/vm-4567-state-snap2.raw', 'volid' => 'local-dir:4567/vm-4567-state-snap2.raw',
}, },
], ],
'local' => [
{
'ctime' => 1589439681,
'format' => 'iso',
'parent' => undef,
'size' => 663748608,
'used' => 663748608,
'vmid' => '0',
'volid' => 'local:iso/debian.iso',
},
],
'local-lvm' => [ 'local-lvm' => [
{ {
'ctime' => '1589277334', 'ctime' => '1589277334',
@@ -1236,6 +1248,41 @@ my $tests = [
}, },
}, },
}, },
{
name => '105_local_iso_in_snapshot',
target => 'pve1',
vmid => 105,
vm_status => {
running => 0,
},
config_patch => {
snapshots => {
ohsnap => {
ide2 => 'local:iso/debian.iso,media=cdrom',
},
},
},
expected_calls => {},
expect_die =>
"can't migrate local disk 'local:iso/debian.iso': local cdrom image (referenced in snapshot - ohsnap)",
expected => {
source_volids => local_volids_for_vm(105),
target_volids => {},
vm_config => get_patched_config(
105,
{
snapshots => {
ohsnap => {
ide2 => 'local:iso/debian.iso,media=cdrom',
},
},
},
),
vm_status => {
running => 0,
},
},
},
{ {
name => '105_cdrom', name => '105_cdrom',
target => 'pve1', target => 'pve1',