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

Mira Limbeck m.limbeck at proxmox.com
Tue Mar 17 20:56:10 CET 2020


As the NBD server spawned by qemu can only listen on a single socket,
we're dependent 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>
---
v2:
 - added fallback to 0 if nbd_protocol_version is undefined
 - some cleanup regarding variables only used in one case

 PVE/QemuServer.pm | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 429ec05..2ef8bff 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4707,7 +4707,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);
@@ -4985,20 +4986,33 @@ sub vm_start {
 
 	#start nbd server for storage migration
 	if ($targetstorage) {
-	    my $nodename = nodename();
-	    my $localip = $get_migration_ip->($migration_network, $nodename);
-	    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;
+
+	    my $migrate_storage_uri;
+	    # nbd_protocol_version > 0 for unix socket support
+	    if ($nbd_protocol_version > 0 && $migration_type eq 'secure') {
+		my $socket_path = "/run/qemu-server/$vmid\_nbd.migrate";
+		mon_cmd($vmid, "nbd-server-start", addr => { type => 'unix', data => { path => $socket_path } } );
+		$migrate_storage_uri = "nbd:unix:$socket_path";
+	    } else {
+		my $nodename = nodename();
+		my $localip = $get_migration_ip->($migration_network, $nodename);
+		my $pfamily = PVE::Tools::get_host_address_family($nodename);
+		my $storage_migrate_port = PVE::Tools::next_migrate_port($pfamily);
 
-	    $localip = "[$localip]" if Net::IP::ip_is_ipv6($localip);
+		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);
+		$migrate_storage_uri = "nbd:${localip}:${storage_migrate_port}";
+	    }
 
 	    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 $migrate_storage_uri:exportname=drive-$opt volume:$drivestr\n";
+		} else {
+		    print "storage migration listens on $migrate_storage_uri:exportname=drive-$opt volume:$drivestr\n";
+		}
 	    }
 	}
 
-- 
2.20.1





More information about the pve-devel mailing list