[pve-devel] [PATCH v4 qemu-server 26/27] cleanup_remotedisks: also include those migrated with storage_migrate

Fabian Ebner f.ebner at proxmox.com
Thu Mar 26 09:09:56 CET 2020


Call cleanup_remotedisks in phase1_cleanup as well, because that's where
we end if sync_disks fails and some disks might already have been
transfered successfully.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/QemuMigrate.pm | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 4fb204d..2b78b8f 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -559,12 +559,29 @@ sub sync_disks {
 sub cleanup_remotedisks {
     my ($self) = @_;
 
-    foreach my $target_drive (keys %{$self->{target_drive}}) {
-	# don't clean up replicated disks!
-	next if defined($self->{target_drive}->{$target_drive}->{bitmap});
+    my $cleanup_volids = {};
+
+    foreach my $volid (values %{$self->{volume_map}}) {
+	$cleanup_volids->{$volid} = 1;
+    }
 
+    foreach my $target_drive (keys %{$self->{target_drive}}) {
 	my $drive = PVE::QemuServer::parse_drive($target_drive, $self->{target_drive}->{$target_drive}->{drivestr});
-	my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
+	my $volid = $drive->{file};
+	next if !defined($volid);
+
+	if (defined($self->{target_drive}->{$target_drive}->{bitmap})) {
+	    # don't clean up replicated disks!
+	    delete $cleanup_volids->{$volid};
+	} else {
+	    # volume_map might not yet contain all of the live-migrating volumes
+	    # if there's an error while starting the drive-mirror jobs
+	    $cleanup_volids->{$volid} = 1;
+	}
+    }
+
+    foreach my $volid (keys %{$cleanup_volids}) {
+	my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid);
 
 	my $cmd = [@{$self->{rem_ssh}}, 'pvesm', 'free', "$storeid:$volname"];
 
@@ -616,11 +633,9 @@ sub phase1_cleanup {
 	$self->log('err', $err);
     }
 
-    if ($self->{volumes}) {
-	foreach my $volid (@{$self->{volumes}}) {
-	    $self->log('err', "found stale volume copy '$volid' on node '$self->{node}'");
-	    # fixme: try to remove ?
-	}
+    eval { $self->cleanup_remotedisks() };
+    if (my $err = $@) {
+	$self->log('err', $err);
     }
 
     eval { $self->cleanup_bitmaps() };
-- 
2.20.1





More information about the pve-devel mailing list