fix #6391: restore: fall back to automatic VM state storage if unavailable

Restoring a backup keeps the 'vmstatestorage' option of the backed up
VM. When the backup is restored on another node or cluster, that
storage might not exist there or not be enabled for the node, so that
hibernating the VM or taking a snapshot including RAM fails later on,
for example with "storage 'local-zfs-pve1' does not exist".

If the configured VM state storage is not available on the node the
backup is restored to, drop the option, so that the storage is
selected automatically, like for VMs without it, and log that in the
restore task log.

A 'vmstatestorage' passed explicitly when restoring is applied after
this and is not affected.

Signed-off-by: Michal Fox <me@dualfroz.com>
This commit is contained in:
dualfroz committed 2026-10-03 01:40:02 +02:00
1 parent b2fcf5405f
commit 5ef4888910
10 files changed
+139 -1

No files matched your search

+10
View File
@@ -6697,6 +6697,16 @@ sub restore_update_config_line {
} else {
$res .= $line;
}
} elsif ($line =~ m/^vmstatestorage:\s*(\S+)\s*$/) {
my $storeid = $1;
my $storecfg = PVE::Storage::config();
my $scfg = PVE::Storage::storage_config($storecfg, $storeid, 1);
if ($scfg && PVE::Storage::storage_check_enabled($storecfg, $storeid, undef, 1)) {
$res .= $line;
} else {
print "VM state storage '$storeid' is not available on this node, using"
. " automatic selection instead\n";
}
} elsif (($line =~ m/^vmgenid: (.*)/)) {
my $vmgenid = $1;
if ($vmgenid ne '0') {
+13
View File
@@ -0,0 +1,13 @@
# VM state storage available on the target is kept
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: target:201/vm-201-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
vmstatestorage: mydir
+12
View File
@@ -0,0 +1,12 @@
# VM state storage missing on the target falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: target:202/vm-202-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
+12
View File
@@ -0,0 +1,12 @@
# VM state storage not available on this node falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: target:203/vm-203-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
+12
View File
@@ -0,0 +1,12 @@
# disabled VM state storage falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: target:204/vm-204-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
+14
View File
@@ -0,0 +1,14 @@
# VM state storage available on the target is kept
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: mydir:201/vm-201-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
vmstatestorage: mydir
#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
+14
View File
@@ -0,0 +1,14 @@
# VM state storage missing on the target falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: mydir:202/vm-202-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
vmstatestorage: local-zfs-pve1
#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
+14
View File
@@ -0,0 +1,14 @@
# VM state storage not available on this node falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: mydir:203/vm-203-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
vmstatestorage: othernode
#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
+14
View File
@@ -0,0 +1,14 @@
# disabled VM state storage falls back to automatic selection
boot: order=scsi0
cores: 1
memory: 2048
name: hibernated
net0: virtio=BC:24:11:6B:2A:5F,bridge=vmbr0
ostype: win10
scsi0: mydir:204/vm-204-disk-0.qcow2,size=32G
scsihw: virtio-scsi-single
smbios1: uuid=0c5a8b3e-9d43-4bd1-8a0e-3f6f2b1f3c11
sockets: 1
vmgenid: 0
vmstatestorage: disabledstore
#qmdump#map:scsi0:drive-scsi0:mydir:qcow2:
+24 -1
View File
@@ -17,7 +17,7 @@ my $INPUT_DIR = './restore-config-input';
my $EXPECTED_DIR = './restore-config-expected';
# NOTE update when you add/remove tests
plan tests => 4;
plan tests => 8;
my $pve_cluster_module = Test::MockModule->new("PVE::Cluster");
$pve_cluster_module->mock(
@@ -32,6 +32,29 @@ $pve_cluster_module->mock(
},
);
my $pve_storage_module = Test::MockModule->new("PVE::Storage");
$pve_storage_module->mock(
config => sub {
return {
ids => {
mydir => { type => 'dir', path => '/mnt/mydir', content => { images => 1 } },
othernode => {
type => 'dir',
path => '/mnt/othernode',
content => { images => 1 },
nodes => { 'some-other-node' => 1 },
},
disabledstore => {
type => 'dir',
path => '/mnt/disabled',
content => { images => 1 },
disable => 1,
},
},
};
},
);
dir_glob_foreach(
'./restore-config-input',
'[0-9]+.conf',