[pve-devel] [PATCH qemu-server 2/4] add NBD server unix socket support in vm_start

Mira Limbeck m.limbeck at proxmox.com
Wed Mar 11 11:44:18 CET 2020


As the NBD server spawned by qemu can only listen on a single socket,
we're dependant on a version being passed to vm_start that indicates
which protocol can be used (TCP or Unix) by the source node.

The change in socket type (TCP to Unix) comes with a different URI. For
unix sockets it has the form: 'nbd:unix:<path/to/socket>:exportname=<device>'.

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
 PVE/QemuServer.pm | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 24f2e16..7d2e0d4 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4696,7 +4696,8 @@ sub vmconfig_update_disk {
 
 sub vm_start {
     my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused,
-	$forcemachine, $spice_ticket, $migration_network, $migration_type, $targetstorage, $timeout) = @_;
+	$forcemachine, $spice_ticket, $migration_network, $migration_type,
+	$targetstorage, $timeout, $nbd_protocol_version) = @_;
 
     PVE::QemuConfig->lock_config($vmid, sub {
 	my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
@@ -4979,15 +4980,25 @@ sub vm_start {
 	    my $pfamily = PVE::Tools::get_host_address_family($nodename);
 	    my $storage_migrate_port = PVE::Tools::next_migrate_port($pfamily);
 
-	    mon_cmd($vmid, "nbd-server-start", addr => { type => 'inet', data => { host => "${localip}", port => "${storage_migrate_port}" } } );
+	    # nbd_protocol_version > 0 for unix socket support
+	    # this is communicated by the source node via STDIN
+	    if ($nbd_protocol_version > 0 && $migration_type eq 'secure') {
+		mon_cmd($vmid, "nbd-server-start", addr => { type => 'unix', data => { path => "/run/qemu-server/$vmid\_nbd.migrate" } } );
+	    } else {
+		mon_cmd($vmid, "nbd-server-start", addr => { type => 'inet', data => { host => "${localip}", port => "${storage_migrate_port}" } } );
+	    }
 
 	    $localip = "[$localip]" if Net::IP::ip_is_ipv6($localip);
 
 	    foreach my $opt (sort keys %$local_volumes) {
 		my $drivestr = $local_volumes->{$opt};
 		mon_cmd($vmid, "nbd-server-add", device => "drive-$opt", writable => JSON::true );
-		my $migrate_storage_uri = "nbd:${localip}:${storage_migrate_port}:exportname=drive-$opt";
-		print "storage migration listens on $migrate_storage_uri volume:$drivestr\n";
+		if ($nbd_protocol_version > 0 && $migration_type eq 'secure') {
+		    print "storage migration listens on nbd:unix:/run/qemu-server/$vmid\_nbd.migrate:exportname=drive-$opt volume:$drivestr\n";
+		} else {
+		    my $migrate_storage_uri = "nbd:${localip}:${storage_migrate_port}:exportname=drive-$opt";
+		    print "storage migration listens on $migrate_storage_uri volume:$drivestr\n";
+		}
 	    }
 	}
 
-- 
2.20.1





More information about the pve-devel mailing list