[pve-devel] [PATCH 3/5] add nodeconf param to start vm with conf file an another node

Alexandre Derumier aderumier at odiso.com
Mon Aug 13 16:41:13 CEST 2012


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm   |    8 +++++++-
 PVE/QemuMigrate.pm |    6 ++++--
 PVE/QemuServer.pm  |   21 ++++++++++++++-------
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 072e8cf..c12bc5f 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1194,6 +1194,8 @@ __PACKAGE__->register_method({
 	    vmid => get_standard_option('pve-vmid'),
 	    skiplock => get_standard_option('skiplock'),
 	    stateuri => get_standard_option('pve-qm-stateuri'),
+	    confnode => get_standard_option('pve-qm-confnode'),
+
 	},
     },
     returns => {
@@ -1218,6 +1220,10 @@ __PACKAGE__->register_method({
 	raise_param_exc({ skiplock => "Only root may use this option." })
 	    if $skiplock && $authuser ne 'root at pam';
 
+	my $confnode = extract_param($param, 'confnode');
+	raise_param_exc({ confnode => "Only root may use this option." })
+	    if $confnode && $authuser ne 'root at pam';
+
 	my $storecfg = PVE::Storage::config();
 
 	if (&$vm_is_ha_managed($vmid) && !$stateuri &&
@@ -1246,7 +1252,7 @@ __PACKAGE__->register_method({
 
 		syslog('info', "start VM $vmid: $upid\n");
 
-		PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock);
+		PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $confnode);
 
 		return;
 	    };
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 83bd9c9..e002848 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -298,9 +298,11 @@ sub phase2 {
 
     my $rport;
 
+    my $nodename = PVE::INotify::nodename();
+
     ## start on remote node
-    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'start', 
-	       $vmid, '--stateuri', 'tcp', '--skiplock'];
+    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'start',
+               $vmid, '--stateuri', 'tcp', '--skiplock', '--confnode', $nodename];
 
     PVE::Tools::run_command($cmd, outfunc => sub {
 	my $line = shift;
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index d3a710e..ee0caad 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -54,6 +54,13 @@ PVE::JSONSchema::register_standard_option('pve-qm-stateuri', {
     optional => 1,
 });
 
+PVE::JSONSchema::register_standard_option('pve-qm-confnode', {
+    description => "source node config",
+    type => 'string',
+    maxLength => 128,
+    optional => 1,
+});
+
 #no warnings 'redefine';
 
 unless(defined(&_VZSYSCALLS_H_)) {
@@ -1499,9 +1506,9 @@ sub destroy_vm {
 }
 
 sub load_config {
-    my ($vmid) = @_;
+    my ($vmid, $node) = @_;
 
-    my $cfspath = cfs_config_path($vmid);
+    my $cfspath = cfs_config_path($vmid, $node);
 
     my $conf = PVE::Cluster::cfs_read_file($cfspath);
 
@@ -1757,9 +1764,9 @@ sub check_cmdline {
 }
 
 sub check_running {
-    my ($vmid, $nocheck) = @_;
+    my ($vmid, $nocheck, $node) = @_;
 
-    my $filename = config_file($vmid);
+    my $filename = config_file($vmid, $node);
 
     die "unable to find configuration file for VM $vmid - no such machine\n"
 	if !$nocheck && ! -f $filename;
@@ -2561,14 +2568,14 @@ sub qemu_block_resize {
 }
 
 sub vm_start {
-    my ($storecfg, $vmid, $statefile, $skiplock) = @_;
+    my ($storecfg, $vmid, $statefile, $skiplock, $node) = @_;
 
     lock_config($vmid, sub {
-	my $conf = load_config($vmid);
+	my $conf = load_config($vmid, $node);
 
 	check_lock($conf) if !$skiplock;
 
-	die "VM $vmid already running\n" if check_running($vmid);
+	die "VM $vmid already running\n" if check_running($vmid, undef, $node);
 
 	my $migrate_uri;
 	my $migrate_port = 0;
-- 
1.7.2.5




More information about the pve-devel mailing list