ensure correct machine type gets saved on snapshot

instead of overwriting the 'machine' config in the snapshot,
use its own 'runningmachine' config only for the snapshot

this way, we do not lose the machine type if it was
explicitely set during the snapshot, but deleted afterwards

we also have to adapt the tests for this

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2018-09-14 14:08:43 +02:00 committed by Thomas Lamprecht
parent 58b1a8d75d
commit c6737ef18b
8 changed files with 34 additions and 23 deletions

View File

@ -146,9 +146,7 @@ sub __snapshot_save_vmstate {
my $scfg = PVE::Storage::storage_config($storecfg, $target);
$name .= ".raw" if $scfg->{path}; # add filename extension for file base storage
$snap->{vmstate} = PVE::Storage::vdisk_alloc($storecfg, $target, $vmid, 'raw', $name, $size*1024);
# always overwrite machine if we save vmstate. This makes sure we
# can restore it later using correct machine type
$snap->{machine} = PVE::QemuServer::get_current_qemu_machine($vmid);
$snap->{runningmachine} = PVE::QemuServer::get_current_qemu_machine($vmid);
}
sub __snapshot_check_running {
@ -287,6 +285,13 @@ sub __snapshot_rollback_hook {
if ($prepare) {
# we save the machine of the current config
$data->{oldmachine} = $conf->{machine};
} else {
# if we have a 'runningmachine' entry in the snapshot
# we use that for the forcemachine parameter,
# else we use the old logic
if (defined($conf->{runningmachine})) {
$data->{forcemachine} = $conf->{runningmachine};
delete $conf->{runningmachine};
} else {
# Note: old code did not store 'machine', so we try to be smart
# and guess the snapshot was generated with kvm 1.4 (pc-i440fx-1.4).
@ -296,6 +301,7 @@ sub __snapshot_rollback_hook {
# in the original config.
delete $conf->{machine} if $snap->{vmstate} && !defined($data->{oldmachine});
}
}
return;
}

View File

@ -80,6 +80,14 @@ PVE::JSONSchema::register_standard_option('pve-qm-image-format', {
optional => 1,
});
PVE::JSONSchema::register_standard_option('pve-qemu-machine', {
description => "Specifies the Qemu machine type.",
type => 'string',
pattern => '(pc|pc(-i440fx)?-\d+\.\d+(\.pxe)?|q35|pc-q35-\d+\.\d+(\.pxe)?)',
maxLength => 40,
optional => 1,
});
#no warnings 'redefine';
sub cgroups_write {
@ -528,13 +536,10 @@ EODESCR
description => "Default storage for VM state volumes/files.",
optional => 1,
}),
machine => {
description => "Specific the Qemu machine type.",
type => 'string',
pattern => '(pc|pc(-i440fx)?-\d+\.\d+(\.pxe)?|q35|pc-q35-\d+\.\d+(\.pxe)?)',
maxLength => 40,
optional => 1,
},
runningmachine => get_standard_option('pve-qemu-machine', {
description => "Specifies the Qemu machine type of the running vm. This is used internally for snapshots.",
}),
machine => get_standard_option('pve-qemu-machine'),
smbios1 => {
description => "Specify SMBIOS type 1 fields.",
type => 'string', format => 'pve-qm-smbios1',
@ -2255,7 +2260,7 @@ sub json_config_properties {
my $prop = shift;
foreach my $opt (keys %$confdesc) {
next if $opt eq 'parent' || $opt eq 'snaptime' || $opt eq 'vmstate';
next if $opt eq 'parent' || $opt eq 'snaptime' || $opt eq 'vmstate' || $opt eq 'runningmachine';
$prop->{$opt} = $confdesc->{$opt};
}

View File

@ -20,12 +20,12 @@ bootdisk: ide0
cores: 4
ide0: local:snapshotable-disk-1,discard=on,size=32G
ide2: none,media=cdrom
machine: somemachine
memory: 8192
name: win
net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
numa: 0
ostype: win7
runningmachine: somemachine
smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
snaptime: 1234567890
sockets: 1

View File

@ -39,13 +39,13 @@ bootdisk: ide0
cores: 4
ide0: local:snapshotable-disk-1,discard=on,size=32G
ide2: none,media=cdrom
machine: somemachine
memory: 8192
name: win
net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
numa: 0
ostype: win7
parent: test
runningmachine: somemachine
smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
snaptime: 1234567890
sockets: 1

View File

@ -20,12 +20,12 @@ bootdisk: ide0
cores: 4
ide0: local:snapshotable-disk-1,discard=on,size=32G
ide2: none,media=cdrom
machine: somemachine
memory: 8192
name: win
net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
numa: 0
ostype: win7
runningmachine: somemachine
smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
snaptime: 1234567890
sockets: 1

View File

@ -18,12 +18,12 @@ bootdisk: ide0
cores: 4
ide0: somestore:somedisk,discard=on,size=32G
ide2: none,media=cdrom
machine: somemachine
memory: 8192
name: win
net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
numa: 0
ostype: win7
runningmachine: somemachine
smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
snapstate: prepare
snaptime: 1234567890

View File

@ -35,13 +35,13 @@ bootdisk: ide0
cores: 4
ide0: somestore:somedisk,discard=on,size=32G
ide2: none,media=cdrom
machine: somemachine
memory: 8192
name: win
net0: e1000=12:34:56:78:90:12,bridge=somebr0,firewall=1
numa: 0
ostype: win7
parent: test
runningmachine: somemachine
smbios1: uuid=01234567-890a-bcde-f012-34567890abcd
snapstate: prepare
snaptime: 1234567890

View File

@ -295,7 +295,7 @@ sub __snapshot_save_vmstate {
my $snap = $conf->{snapshots}->{$snapname};
$snap->{vmstate} = "somestorage:state-volume";
$snap->{machine} = "somemachine";
$snap->{runningmachine} = "somemachine"
}
# END mocked PVE::QemuConfig methods