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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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