my $conf = $self->{vmconf};
# local volumes which have been copied
+ # and their old_id => new_id pairs
$self->{volumes} = [];
+ $self->{volume_map} = {};
my $storecfg = $self->{storecfg};
eval {
$local_volumes->{$volid}->{ref} = $attr->{referenced_in_config} ? 'config' : 'snapshot';
+ $local_volumes->{$volid}->{is_vmstate} = $attr->{is_vmstate} ? 1 : 0;
+
if ($attr->{cdrom}) {
if ($volid =~ /vm-\d+-cloudinit/) {
$local_volumes->{$volid}->{ref} = 'generated';
next if $self->{replicated_volumes}->{$volid};
push @{$self->{volumes}}, $volid;
my $opts = $self->{opts};
- my $insecure = $opts->{migration_type} eq 'insecure';
- my $with_snapshots = $local_volumes->{$volid}->{snapshots};
# use 'migrate' limit for transfer to other node
my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', [$targetsid, $sid], $opts->{bwlimit});
# JSONSchema and get_bandwidth_limit use kbps - storage_migrate bps
$bwlimit = $bwlimit * 1024 if defined($bwlimit);
- PVE::Storage::storage_migrate($storecfg, $volid, $self->{ssh_info}, $targetsid,
- undef, undef, undef, $bwlimit, $insecure, $with_snapshots);
+ my $storage_migrate_opts = {
+ 'bwlimit' => $bwlimit,
+ 'insecure' => $opts->{migration_type} eq 'insecure',
+ 'with_snapshots' => $local_volumes->{$volid}->{snapshots},
+ 'allow_rename' => !$local_volumes->{$volid}->{is_vmstate},
+ };
+
+ my $new_volid = eval {
+ PVE::Storage::storage_migrate($storecfg, $volid, $self->{ssh_info},
+ $targetsid, $storage_migrate_opts);
+ };
+ if (my $err = $@) {
+ die "storage migration for '$volid' to storage '$targetsid' failed - $err\n";
+ }
+
+ $self->{volume_map}->{$volid} = $new_volid;
+ $self->log('info', "volume '$volid' is '$new_volid' on the target\n");
}
}
};
my $source_drive = PVE::QemuServer::parse_drive($drive, $conf->{$drive});
my $target_drive = PVE::QemuServer::parse_drive($drive, $target->{drivestr});
- my $source_sid = PVE::Storage::Plugin::parse_volume_id($source_drive->{file});
- my $target_sid = PVE::Storage::Plugin::parse_volume_id($target_drive->{file});
+ my $source_volid = $source_drive->{file};
+ my $target_volid = $target_drive->{file};
+
+ my $source_sid = PVE::Storage::Plugin::parse_volume_id($source_volid);
+ my $target_sid = PVE::Storage::Plugin::parse_volume_id($target_volid);
my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', [$source_sid, $target_sid], $opt_bwlimit);
my $bitmap = $target->{bitmap};
$self->log('info', "$drive: start migration to $nbd_uri");
PVE::QemuServer::qemu_drive_mirror($vmid, $drive, $nbd_uri, $vmid, undef, $self->{storage_migration_jobs}, 'skip', undef, $bwlimit, $bitmap);
+
+ $self->{volume_map}->{$source_volid} = $target_volid;
+ $self->log('info', "volume '$source_volid' is '$target_volid' on the target\n");
}
}
eval { PVE::QemuServer::qemu_blockjobs_cancel($vmid, $self->{storage_migration_jobs}) };
eval { PVE::QemuMigrate::cleanup_remotedisks($self) };
die "Failed to complete storage migration: $err\n";
- } else {
- 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);
- }
}
}
+ if ($self->{volume_map}) {
+ PVE::QemuConfig->update_volume_ids($conf, $self->{volume_map});
+ PVE::QemuConfig->write_config($vmid, $conf);
+ }
+
# transfer replication state before move config
$self->transfer_replication_state() if $self->{replicated_volumes};