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

Alexandre Derumier aderumier at odiso.com
Wed Feb 20 01:22:54 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 1f57643..60638d1 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1970,7 +1970,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 => {
@@ -2016,6 +2021,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')) {
@@ -2056,7 +2068,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 0665a59..4c5f6ca 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5063,7 +5063,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);
@@ -5088,7 +5088,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) = @_;
 
@@ -5284,7 +5296,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);
@@ -5303,7 +5315,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