+ if ($replication_jobcfg) {
+ if ($self->{running}) {
+
+ my $version = PVE::QemuServer::kvm_user_version();
+ if (!min_version($version, 4, 2)) {
+ die "can't live migrate VM with replicated volumes, pve-qemu to old (< 4.2)!\n"
+ }
+
+ my $live_replicatable_volumes = {};
+ PVE::QemuConfig->foreach_volume($conf, sub {
+ my ($ds, $drive) = @_;
+
+ my $volid = $drive->{file};
+ $live_replicatable_volumes->{$ds} = $volid
+ if defined($replicatable_volumes->{$volid});
+ });
+ foreach my $drive (keys %$live_replicatable_volumes) {
+ my $volid = $live_replicatable_volumes->{$drive};
+
+ my $bitmap = "repl_$drive";
+
+ # start tracking before replication to get full delta + a few duplicates
+ $self->log('info', "$drive: start tracking writes using block-dirty-bitmap '$bitmap'");
+ mon_cmd($vmid, 'block-dirty-bitmap-add', node => "drive-$drive", name => $bitmap);
+
+ # other info comes from target node in phase 2
+ $self->{target_drive}->{$drive}->{bitmap} = $bitmap;
+ }
+ }
+ $self->log('info', "replicating disk images");
+
+ my $start_time = time();
+ my $logfunc = sub { $self->log('info', shift) };
+ $self->{replicated_volumes} = PVE::Replication::run_replication(
+ 'PVE::QemuConfig', $replication_jobcfg, $start_time, $start_time, $logfunc);
+ }
+
+ # 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::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)) {
+ $conf->{$key} = PVE::QemuServer::print_drive($updated);
+ $self->log('info', "size of disk '$updated->{file}' ($key) updated from $old_size to $new_size\n");
+ }
+ });
+
+ # we want to set the efidisk size in the config to the size of the
+ # real OVMF_VARS.fd image, else we can create a too big image, which does not work
+ if (defined($conf->{efidisk0})) {
+ PVE::QemuServer::update_efidisk_size($conf);
+ }
+
+ $self->log('info', "copying local disk images") if scalar(%$local_volumes);