[pve-devel] [PATCH qemu-server v7 3/3] qemu : vm_start : add external_migration

Alexandre Derumier aderumier at odiso.com
Mon Apr 29 12:01:45 CEST 2019


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm  | 16 ++++++++++++++--
 PVE/QemuServer.pm | 20 ++++++++++++++++----
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 875feb0..3583caa 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2012,7 +2012,12 @@ __PACKAGE__->register_method({
 		description => "Target storage for the migration. (Can be '1' to use the same storage id as on the source node.)",
 		type => 'string',
 		optional => 1
-	    }
+	    },
+	    external_migration => {
+		description => "Enable external migration.",
+		type => 'boolean',
+		optional => 1,
+	    },
 	},
     },
     returns => {
@@ -2058,6 +2063,13 @@ __PACKAGE__->register_method({
 	raise_param_exc({ targetstorage => "targetstorage can only by used with migratedfrom." })
 	    if $targetstorage && !$migratedfrom;
 
+	my $external_migration = extract_param($param, 'external_migration');
+	raise_param_exc({ external_migration => "Only root may use this option." })
+	    if $external_migration && $authuser ne 'root at pam';
+
+	raise_param_exc({ external_migration => "targetstorage can't be used with external_migration." })
+	    if ($targetstorage && $external_migration);
+
 	# read spice ticket from STDIN
 	my $spice_ticket;
 	if ($stateuri && ($stateuri eq 'tcp') && $migratedfrom && ($rpcenv->{type} eq 'cli')) {
@@ -2098,7 +2110,7 @@ __PACKAGE__->register_method({
 		syslog('info', "start VM $vmid: $upid\n");
 
 		PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $migratedfrom, undef,
-					  $machine, $spice_ticket, $migration_network, $migration_type, $targetstorage);
+					  $machine, $spice_ticket, $migration_network, $migration_type, $targetstorage, $external_migration);
 
 		return;
 	    };
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 1bb6009..3371b1e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5160,7 +5160,7 @@ sub vmconfig_update_disk {
 
 sub vm_start {
     my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused,
-	$forcemachine, $spice_ticket, $migration_network, $migration_type, $targetstorage) = @_;
+	$forcemachine, $spice_ticket, $migration_network, $migration_type, $targetstorage, $external_migration) = @_;
 
     PVE::QemuConfig->lock_config($vmid, sub {
 	my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
@@ -5188,7 +5188,19 @@ sub vm_start {
 
 	my $local_volumes = {};
 
-	if ($targetstorage) {
+	if ($external_migration) {
+	    foreach_drive($conf, sub {
+		my ($ds, $drive) = @_;
+
+		return if drive_is_cdrom($drive);
+
+		my $volid = $drive->{file};
+
+		return if !$volid;
+
+		$local_volumes->{$ds} = $volid;
+	    });
+	} elsif ($targetstorage) {
 	    foreach_drive($conf, sub {
 		my ($ds, $drive) = @_;
 
@@ -5390,7 +5402,7 @@ sub vm_start {
 	}
 
 	#start nbd server for storage migration
-	if ($targetstorage) {
+	if ($targetstorage || $external_migration) {
 	    my $nodename = PVE::INotify::nodename();
 	    my $migrate_network_addr = PVE::Cluster::get_local_migration_ip($migration_network);
 	    my $localip = $migrate_network_addr ? $migrate_network_addr : PVE::Cluster::remote_node_ip($nodename, 1);
@@ -5409,7 +5421,7 @@ sub vm_start {
 	    }
 	}
 
-	if ($migratedfrom) {
+	if ($migratedfrom || $external_migration) {
 	    eval {
 		set_migration_caps($vmid);
 	    };
-- 
2.11.0




More information about the pve-devel mailing list