[pve-devel] [PATCH qemu-server] migrate: don't accidentally take NBD code paths

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Apr 30 09:35:29 CEST 2020


by avoiding auto-vivification of $self->{online_local_volumes} via
iteration. most code paths don't care whether it's undef or a reference
to an empty list, but this caused the (already) fixed bug of calling
nbd_stop without having started an NBD server in the first place.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
This technically makes the previous NBD stop related patches no longer
needed - but let's keep them until we clean up the whole volume handling
properly to avoid falling into this trap again.

 PVE/QemuMigrate.pm | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 7644922..d9b104c 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -713,10 +713,14 @@ sub phase2 {
     $input .= "nbd_protocol_version: $nbd_protocol_version\n";
 
     my $number_of_online_replicated_volumes = 0;
-    foreach my $volid (@{$self->{online_local_volumes}}) {
-	next if !$self->{replicated_volumes}->{$volid};
-	$number_of_online_replicated_volumes++;
-	$input .= "replicated_volume: $volid\n";
+
+    # prevent auto-vivification
+    if ($self->{online_local_volumes}) {
+	foreach my $volid (@{$self->{online_local_volumes}}) {
+	    next if !$self->{replicated_volumes}->{$volid};
+	    $number_of_online_replicated_volumes++;
+	    $input .= "replicated_volume: $volid\n";
+	}
     }
 
     my $target_replicated_volumes = {};
-- 
2.20.1





More information about the pve-devel mailing list