all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 qemu-server 12/13] migration: split out replication from scan_local_volumes
Date: Fri, 29 Jan 2021 16:11:42 +0100	[thread overview]
Message-ID: <20210129151143.10014-13-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210129151143.10014-1-f.ebner@proxmox.com>

and avoid one loop over the config, by extending foreach_volid to include the
drivename.

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

New in v2

Having the drivename attribute might also be useful to make the refactor the
target_drive handling, but that's something for a follow-up series

On my first version of this (local, not on the list), I had an
auto-vivification problem introducing 'none' from the CD drive to the
local_volumes hash, which is the reason patch #1 exists

 PVE/QemuMigrate.pm | 86 ++++++++++++++++++++++++++--------------------
 PVE/QemuServer.pm  |  2 ++
 2 files changed, 51 insertions(+), 37 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 64f3054..b503601 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -476,6 +476,9 @@ sub scan_local_volumes {
 
 	    $local_volumes->{$volid}->{is_vmstate} = $attr->{is_vmstate} ? 1 : 0;
 
+	    $local_volumes->{$volid}->{drivename} = $attr->{drivename}
+		if $attr->{drivename};
+
 	    if ($attr->{cdrom}) {
 		if ($volid =~ /vm-\d+-cloudinit/) {
 		    $local_volumes->{$volid}->{ref} = 'generated';
@@ -560,43 +563,6 @@ sub scan_local_volumes {
 	    }
 	}
 
-	if ($self->{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) };
-	    my $replicated_volumes = PVE::Replication::run_replication(
-	       'PVE::QemuConfig', $self->{replication_jobcfg}, $start_time, $start_time, $logfunc);
-	}
-
 	foreach my $volid (sort keys %$local_volumes) {
 	    my $ref = $local_volumes->{$volid}->{ref};
 	    if ($self->{running} && $ref eq 'config') {
@@ -611,6 +577,50 @@ sub scan_local_volumes {
     die "Problem found while scanning volumes - $@" if $@;
 }
 
+sub handle_replication {
+    my ($self, $vmid) = @_;
+
+    my $conf = $self->{vmconf};
+    my $local_volumes = $self->{local_volumes};
+
+    return if !$self->{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 = $self->filter_local_volumes('online', 1);
+	foreach my $volid (@live_replicatable_volumes) {
+	    my $drive = $local_volumes->{$volid}->{drivename};
+	    die "internal error - no drive for '$volid'\n" if !defined($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) };
+    my $actual_replicated_volumes = PVE::Replication::run_replication(
+       'PVE::QemuConfig', $self->{replication_jobcfg}, $start_time, $start_time, $logfunc);
+
+    # extra safety check
+    my @replicated_volumes = $self->filter_local_volumes(undef, 1);
+    foreach my $volid (@replicated_volumes) {
+	die "expected volume '$volid' to get replicated, but it wasn't\n"
+	    if !$actual_replicated_volumes->{$volid};
+    }
+}
+
 sub config_update_local_disksizes {
     my ($self) = @_;
 
@@ -744,6 +754,8 @@ sub phase1 {
     $self->config_update_local_disksizes();
     PVE::QemuConfig->write_config($vmid, $conf);
 
+    $self->handle_replication($vmid);
+
     $self->sync_offline_local_volumes();
 };
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9c65d76..c25743b 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -4323,6 +4323,8 @@ sub foreach_volid {
 
 	$volhash->{$volid}->{is_unused} //= 0;
 	$volhash->{$volid}->{is_unused} = 1 if $key =~ /^unused\d+$/;
+
+	$volhash->{$volid}->{drivename} = $key if is_valid_drivename($key);
     };
 
     my $include_opts = {
-- 
2.20.1





  parent reply	other threads:[~2021-01-29 15:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29 15:11 [pve-devel] [PATCH-SERIES v2 qemu-server] Cleanup migration code and improve migration disk cleanup Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 01/13] test: migration: add parse_volume_id calls Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 02/13] migration: split sync_disks into two functions Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 03/13] migration: avoid re-scanning all volumes Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 04/13] migration: split out config_update_local_disksizes from scan_local_volumes Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 05/13] migration: fix calculation of bandwith limit for non-disk migration Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 06/13] migration: save targetstorage and bwlimit in local_volumes hash and re-use information Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 07/13] migration: add nbd migrated volumes to volume_map earlier Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 08/13] migration: simplify removal of local volumes and get rid of self->{volumes} Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 09/13] migration: cleanup_remotedisks: simplify and include more disks Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 10/13] migration: use storage_migration for checks instead of online_local_volumes Fabian Ebner
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 11/13] migration: keep track of replicated volumes via local_volumes Fabian Ebner
2021-01-29 15:11 ` Fabian Ebner [this message]
2021-01-29 15:11 ` [pve-devel] [PATCH v2 qemu-server 13/13] migration: move finishing block jobs to phase2 for better/uniform error handling Fabian Ebner
2021-04-19  6:49 ` [pve-devel] [PATCH-SERIES v2 qemu-server] Cleanup migration code and improve migration disk cleanup Fabian Ebner
2021-04-19 11:50 ` [pve-devel] applied-series: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210129151143.10014-13-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal