[pve-devel] [PATCH qemu-server] migrate: handle local storage not selected manually in storage config

Tim Marx t.marx at proxmox.com
Fri Jun 28 11:51:15 CEST 2019


e.g. local storage was considered not allowed for offline migration
even if it is available on all nodes, this should now be fixed as it
is now considered available on all nodes if a local storage isn't
restricted to a specific subset of the available nodes. The user is
responseable to make sure that the datacenter storage config reflects
the actual setup, so there is no additional check for local storages
which aren't available on all nodes if they are not explicitly marked
at datacenter level.

Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
 PVE/API2/Qemu.pm  |  6 +++---
 PVE/QemuServer.pm | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index c9b2f67..d993989 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -3204,11 +3204,11 @@ __PACKAGE__->register_method({
 	# if vm is not running, return target nodes where local storage is available
 	# for offline migration
 	if (!$res->{running}) {
-	    my $shared_nodes = PVE::QemuServer::shared_nodes($vmconf, $storecfg);
+	    my $allowed_nodes = PVE::QemuServer::check_local_storage_availability($vmconf, $storecfg);

-	    delete $shared_nodes->{$localnode} if $shared_nodes->{$localnode};
+	    delete $allowed_nodes->{$localnode} if $allowed_nodes->{$localnode};

-	    $res->{allowed_nodes} = [ keys %$shared_nodes ];
+	    $res->{allowed_nodes} = [ keys %$allowed_nodes ];
 	}


diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fbfc3fb..09484d1 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2924,6 +2924,35 @@ sub shared_nodes {
     return $nodehash
 }

+sub check_local_storage_availability {
+    my ($conf, $storecfg) = @_;
+
+    my $nodelist = PVE::Cluster::get_nodelist();
+    my $nodehash = { map { $_ => 1 } @$nodelist };
+
+    foreach_drive($conf, sub {
+	my ($ds, $drive) = @_;
+
+	my $volid = $drive->{file};
+	return if !$volid;
+
+	my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
+	if ($storeid) {
+	    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+	    return if ($scfg->{shared});
+	    if ($scfg->{disable}) {
+		$nodehash = {};
+	    } elsif (my $avail = $scfg->{nodes}) {
+		foreach my $node (keys %$nodehash) {
+		    delete $nodehash->{$node} if !$avail->{$node};
+		}
+	    }
+	}
+    });
+
+    return $nodehash
+}
+
 sub check_cmdline {
     my ($pidfile, $pid) = @_;

--
2.11.0




More information about the pve-devel mailing list