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

Alexandre Derumier aderumier at odiso.com
Tue Jan 29 02:20:40 CET 2019


---
 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 97bae46..897aa0f 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1951,7 +1951,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 => {
@@ -1997,6 +2002,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')) {
@@ -2037,7 +2049,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 8acda64..badb694 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5046,7 +5046,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);
@@ -5071,7 +5071,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) = @_;
 
@@ -5265,7 +5277,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);
@@ -5284,7 +5296,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