From 952958bc8720bfad655b296724337c6ca3d85348 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 5 Jun 2013 09:27:31 +0200 Subject: [PATCH] API extension: add 'machine' parameter to vm_start This allows us to overwrite the machine type at start - useful for migration to make sure we use the same machine at the target node. --- PVE/API2/Qemu.pm | 6 ++++-- PVE/QemuServer.pm | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 24b57ad..386d466 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1314,7 +1314,7 @@ __PACKAGE__->register_method({ skiplock => get_standard_option('skiplock'), stateuri => get_standard_option('pve-qm-stateuri'), migratedfrom => get_standard_option('pve-node',{ optional => 1 }), - + machine => get_standard_option('pve-qm-machine'), }, }, returns => { @@ -1331,6 +1331,8 @@ __PACKAGE__->register_method({ my $vmid = extract_param($param, 'vmid'); + my $machine = extract_param($param, 'machine'); + my $stateuri = extract_param($param, 'stateuri'); raise_param_exc({ stateuri => "Only root may use this option." }) if $stateuri && $authuser ne 'root@pam'; @@ -1371,7 +1373,7 @@ __PACKAGE__->register_method({ syslog('info', "start VM $vmid: $upid\n"); - PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $migratedfrom); + PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $migratedfrom, undef, $machine); return; }; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 4a6ff93..fca246d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2219,7 +2219,7 @@ sub foreach_volid { } sub config_to_command { - my ($storecfg, $vmid, $conf, $defaults) = @_; + my ($storecfg, $vmid, $conf, $defaults, $forcemachine) = @_; my $cmd = []; my $globalFlags = []; @@ -2384,8 +2384,9 @@ sub config_to_command { die "No accelerator found!\n" if !$cpuinfo->{hvm}; } - if ($conf->{machine}) { - push @$machineFlags, "type=$conf->{machine}"; + my $machine_type = $forcemachine || $conf->{machine}; + if ($machine_type) { + push @$machineFlags, "type=${machine_type}"; } if ($conf->{startdate}) { @@ -2972,7 +2973,7 @@ sub qga_unfreezefs { } sub vm_start { - my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused) = @_; + my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine) = @_; lock_config($vmid, sub { my $conf = load_config($vmid, $migratedfrom); @@ -2988,7 +2989,7 @@ sub vm_start { # set environment variable useful inside network script $ENV{PVE_MIGRATED_FROM} = $migratedfrom if $migratedfrom; - my ($cmd, $vollist) = config_to_command($storecfg, $vmid, $conf, $defaults); + my ($cmd, $vollist) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine); my $migrate_port = 0; -- 2.39.2