[pve-devel] [RFC qemu-server 13/16] Take note of changes to volume ids when migrating and update config

Fabian Ebner f.ebner at proxmox.com
Wed Jan 29 14:30:11 CET 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Might make sense to combine this patch and patch 16.

 PVE/QemuMigrate.pm | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 81b52d1..702fda0 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -270,7 +270,9 @@ sub sync_disks {
     my $conf = $self->{vmconf};
 
     # local volumes which have been copied
+    # and their old_id => new_id pairs
     $self->{volumes} = [];
+    $self->{volume_map} = {};
 
     my $override_targetsid = $self->{opts}->{targetstorage};
 
@@ -478,8 +480,11 @@ sub sync_disks {
 		# JSONSchema and get_bandwidth_limit use kbps - storage_migrate bps
 		$bwlimit = $bwlimit * 1024 if defined($bwlimit);
 
-		PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $targetsid,
-					      undef, undef, undef, $bwlimit, $insecure, $with_snapshots);
+		my $new_volid = PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $targetsid,
+							      undef, undef, undef, $bwlimit, $insecure, $with_snapshots);
+
+		$self->{volume_map}->{$volid} = $new_volid if $volid ne $new_volid;
+		$self->log('info', "volume '$volid' is '$new_volid' on the target\n");
 	    }
 	}
     };
@@ -955,6 +960,13 @@ sub phase3_cleanup {
 
     my $tunnel = $self->{tunnel};
 
+    # Needs to happen before printing the drives that where migrated via qemu,
+    # since a new volume on the target might have the same ID as an old volume
+    # on the source and update_volume_ids relies on matching IDs in the config.
+    if ($self->{volume_map}) {
+	$conf = PVE::QemuConfig->update_volume_ids($conf, $self->{volume_map});
+    }
+
     if ($self->{storage_migration}) {
 	# finish block-job
 	eval { PVE::QemuServer::qemu_drive_mirror_monitor($vmid, undef, $self->{storage_migration_jobs}); };
@@ -967,11 +979,15 @@ sub phase3_cleanup {
 	    foreach my $target_drive (keys %{$self->{target_drive}}) {
 		my $drive = PVE::QemuServer::parse_drive($target_drive, $self->{target_drive}->{$target_drive}->{drivestr});
 		$conf->{$target_drive} = PVE::QemuServer::print_drive($drive);
-		PVE::QemuConfig->write_config($vmid, $conf);
 	    }
 	}
     }
 
+    # only write after successfully completing the migration
+    if ($self->{volume_map} || $self->{storage_migration}) {
+	PVE::QemuConfig->write_config($vmid, $conf);
+    }
+
     # transfer replication state before move config
     $self->transfer_replication_state() if $self->{replicated_volumes};
 
-- 
2.20.1





More information about the pve-devel mailing list