use PVE::Storage;
use PVE::Tools;
+use PVE::QemuConfig;
+use PVE::QemuServer::CPUConfig;
use PVE::QemuServer::Drive;
use PVE::QemuServer::Helpers qw(min_version);
use PVE::QemuServer::Machine;
$self->{forcemachine} = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
+ # To support custom CPU types, we keep QEMU's "-cpu" parameter intact.
+ # Since the parameter itself contains no reference to a custom model,
+ # this makes migration independent of changes to "cpu-models.conf".
+ if ($conf->{cpu}) {
+ my $cpuconf = PVE::QemuServer::CPUConfig::parse_cpu_conf_basic($conf->{cpu});
+ if ($cpuconf && PVE::QemuServer::CPUConfig::is_custom_model($cpuconf->{cputype})) {
+ $self->{forcecpu} = PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid);
+ }
+ }
}
+
my $loc_res = PVE::QemuServer::check_local_resources($conf, 1);
if (scalar @$loc_res) {
if ($self->{running} || !$self->{opts}->{force}) {
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
# check if storage is available on both nodes
- my $targetsid = $self->{opts}->{targetstorage} // $sid;
+ my $targetsid = PVE::QemuServer::map_storage($self->{opts}->{storagemap}, $sid);
my $scfg = PVE::Storage::storage_check_node($self->{storecfg}, $sid);
PVE::Storage::storage_check_node($self->{storecfg}, $targetsid, $self->{node});
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};
- my $override_targetsid = $self->{opts}->{targetstorage};
-
- if (defined($override_targetsid)) {
- my $scfg = PVE::Storage::storage_config($storecfg, $override_targetsid);
- die "content type 'images' is not available on storage '$override_targetsid'\n"
- if !$scfg->{content}->{images};
- }
-
eval {
# found local volumes and their origin
next if @{$dl->{$storeid}} == 0;
- my $targetsid = $override_targetsid // $storeid;
-
+ my $targetsid = PVE::QemuServer::map_storage($self->{opts}->{storagemap}, $storeid);
# check if storage is available on target node
PVE::Storage::storage_check_node($storecfg, $targetsid, $self->{node});
+ # grandfather in existing mismatches
+ if ($targetsid ne $storeid) {
+ my $target_scfg = PVE::Storage::storage_config($storecfg, $targetsid);
+ die "content type 'images' is not available on storage '$targetsid'\n"
+ if !$target_scfg->{content}->{images};
+ }
+
PVE::Storage::foreach_volid($dl, sub {
my ($volid, $sid, $volinfo) = @_;
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
- my $targetsid = $override_targetsid // $sid;
+ my $targetsid = PVE::QemuServer::map_storage($self->{opts}->{storagemap}, $sid);
# check if storage is available on both nodes
my $scfg = PVE::Storage::storage_check_node($storecfg, $sid);
PVE::Storage::storage_check_node($storecfg, $targetsid, $self->{node});
$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';
}
my $live_replicatable_volumes = {};
- PVE::QemuServer::foreach_drive($conf, sub {
+ PVE::QemuConfig->foreach_volume($conf, sub {
my ($ds, $drive) = @_;
my $volid = $drive->{file};
# sizes in config have to be accurate for remote node to correctly
# allocate disks, rescan to be sure
my $volid_hash = PVE::QemuServer::scan_volids($storecfg, $vmid);
- PVE::QemuServer::foreach_drive($conf, sub {
+ PVE::QemuConfig->foreach_volume($conf, sub {
my ($key, $drive) = @_;
my ($updated, $old_size, $new_size) = PVE::QemuServer::Drive::update_disksize($drive, $volid_hash);
if (defined($updated)) {
foreach my $volid (keys %$local_volumes) {
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
- my $targetsid = $override_targetsid // $sid;
+ my $targetsid = PVE::QemuServer::map_storage($self->{opts}->{storagemap}, $sid);
my $ref = $local_volumes->{$volid}->{ref};
if ($self->{running} && $ref eq 'config') {
push @{$self->{online_local_volumes}}, $volid;
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");
}
}
};
push @$cmd, '--machine', $self->{forcemachine};
}
+ if ($self->{forcecpu}) {
+ push @$cmd, '--force-cpu', $self->{forcecpu};
+ }
+
if ($self->{online_local_volumes}) {
push @$cmd, '--targetstorage', ($self->{opts}->{targetstorage} // '1');
}
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};