From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id EE25E6C33C
 for <pve-devel@lists.proxmox.com>; Fri, 29 Jan 2021 16:11:52 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id A1A24112BA
 for <pve-devel@lists.proxmox.com>; Fri, 29 Jan 2021 16:11:51 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id D55EF1120C
 for <pve-devel@lists.proxmox.com>; Fri, 29 Jan 2021 16:11:47 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9CFE543B3C
 for <pve-devel@lists.proxmox.com>; Fri, 29 Jan 2021 16:11:47 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Fri, 29 Jan 2021 16:11:40 +0100
Message-Id: <20210129151143.10014-11-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210129151143.10014-1-f.ebner@proxmox.com>
References: <20210129151143.10014-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.004 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemumigrate.pm]
Subject: [pve-devel] [PATCH v2 qemu-server 10/13] migration: use
 storage_migration for checks instead of online_local_volumes
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 29 Jan 2021 15:11:53 -0000

Like this we don't need to worry about auto-vivifaction.

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

No changes from v1

 PVE/QemuMigrate.pm | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 94f3328..09289a5 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -597,7 +597,7 @@ sub scan_local_volumes {
 	foreach my $volid (sort keys %$local_volumes) {
 	    my $ref = $local_volumes->{$volid}->{ref};
 	    if ($self->{running} && $ref eq 'config') {
-		push @{$self->{online_local_volumes}}, $volid;
+		$local_volumes->{$volid}->{migration_mode} = 'online';
 	    } elsif ($self->{running} && $ref eq 'generated') {
 		die "can't live migrate VM with local cloudinit disk. use a shared storage instead\n";
 	    } else {
@@ -770,6 +770,9 @@ sub phase2 {
 
     my $conf = $self->{vmconf};
     my $local_volumes = $self->{local_volumes};
+    my @online_local_volumes = $self->filter_local_volumes('online');
+
+    $self->{storage_migration} = 1 if scalar(@online_local_volumes);
 
     $self->log('info', "starting VM $vmid on remote node '$self->{node}'");
 
@@ -810,7 +813,7 @@ sub phase2 {
 	push @$cmd, '--force-cpu', $self->{forcecpu};
     }
 
-    if ($self->{online_local_volumes}) {
+    if ($self->{storage_migration}) {
 	push @$cmd, '--targetstorage', ($self->{opts}->{targetstorage} // '1');
     }
 
@@ -823,14 +826,10 @@ sub phase2 {
     $input .= "nbd_protocol_version: $nbd_protocol_version\n";
 
     my $number_of_online_replicated_volumes = 0;
-
-    # prevent auto-vivification
-    if ($self->{online_local_volumes}) {
-	foreach my $volid (@{$self->{online_local_volumes}}) {
-	    next if !$self->{replicated_volumes}->{$volid};
-	    $number_of_online_replicated_volumes++;
-	    $input .= "replicated_volume: $volid\n";
-	}
+    foreach my $volid (@online_local_volumes) {
+	next if !$self->{replicated_volumes}->{$volid};
+	$number_of_online_replicated_volumes++;
+	$input .= "replicated_volume: $volid\n";
     }
 
     my $handle_storage_migration_listens = sub {
@@ -916,13 +915,12 @@ sub phase2 {
 
     my $start = time();
 
-    if (defined($self->{online_local_volumes})) {
-	$self->{storage_migration} = 1;
+    if ($self->{storage_migration}) {
 	$self->{storage_migration_jobs} = {};
 	$self->log('info', "starting storage migration");
 
 	die "The number of local disks does not match between the source and the destination.\n"
-	    if (scalar(keys %{$self->{target_drive}}) != scalar @{$self->{online_local_volumes}});
+	    if (scalar(keys %{$self->{target_drive}}) != scalar(@online_local_volumes));
 	foreach my $drive (keys %{$self->{target_drive}}){
 	    my $target = $self->{target_drive}->{$drive};
 	    my $nbd_uri = $target->{nbd_uri};
-- 
2.20.1