From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 81A2E6C40D for ; Fri, 29 Jan 2021 16:12:25 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EC71D1134A for ; Fri, 29 Jan 2021 16:11:53 +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 205A811212 for ; Fri, 29 Jan 2021 16:11:48 +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 E0FF2409EB for ; Fri, 29 Jan 2021 16:11:47 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Fri, 29 Jan 2021 16:11:41 +0100 Message-Id: <20210129151143.10014-12-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 11/13] migration: keep track of replicated volumes via local_volumes X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jan 2021 15:12:25 -0000 by extending filter_local_volumes. Signed-off-by: Fabian Ebner --- Changes from v1: * rebase (new check for is_replicated was introduced in the meantime) * move setting of replicated flag to earlier (previously it happend after run_replication) so that the next patch works PVE/QemuMigrate.pm | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index 09289a5..64f3054 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -9,7 +9,7 @@ use POSIX qw( WNOHANG ); use Time::HiRes qw( usleep ); use PVE::Cluster; -use PVE::GuestHelpers qw(safe_string_ne); +use PVE::GuestHelpers qw(safe_boolean_ne safe_string_ne); use PVE::INotify; use PVE::RPCEnvironment; use PVE::Replication; @@ -434,6 +434,9 @@ sub scan_local_volumes { my $replicatable_volumes = !$self->{replication_jobcfg} ? {} : PVE::QemuConfig->get_replicatable_volumes($storecfg, $vmid, $conf, 0, 1); + foreach my $volid (keys %{$replicatable_volumes}) { + $local_volumes->{$volid}->{replicated} = 1; + } my $test_volid = sub { my ($volid, $attr) = @_; @@ -590,7 +593,7 @@ sub scan_local_volumes { my $start_time = time(); my $logfunc = sub { $self->log('info', shift) }; - $self->{replicated_volumes} = PVE::Replication::run_replication( + my $replicated_volumes = PVE::Replication::run_replication( 'PVE::QemuConfig', $self->{replication_jobcfg}, $start_time, $start_time, $logfunc); } @@ -601,7 +604,6 @@ sub scan_local_volumes { } elsif ($self->{running} && $ref eq 'generated') { die "can't live migrate VM with local cloudinit disk. use a shared storage instead\n"; } else { - next if $self->{replicated_volumes}->{$volid}; $local_volumes->{$volid}->{migration_mode} = 'offline'; } } @@ -637,13 +639,14 @@ sub config_update_local_disksizes { } sub filter_local_volumes { - my ($self, $migration_mode) = @_; + my ($self, $migration_mode, $replicated) = @_; my $volumes = $self->{local_volumes}; my @filtered_volids; foreach my $volid (sort keys %{$volumes}) { next if defined($migration_mode) && safe_string_ne($volumes->{$volid}->{migration_mode}, $migration_mode); + next if defined($replicated) && safe_boolean_ne($volumes->{$volid}->{replicated}, $replicated); push @filtered_volids, $volid; } @@ -654,7 +657,7 @@ sub sync_offline_local_volumes { my ($self) = @_; my $local_volumes = $self->{local_volumes}; - my @volids = $self->filter_local_volumes('offline'); + my @volids = $self->filter_local_volumes('offline', 0); my $storecfg = $self->{storecfg}; my $opts = $self->{opts}; @@ -695,9 +698,11 @@ sub sync_offline_local_volumes { sub cleanup_remotedisks { my ($self) = @_; + my $local_volumes = $self->{local_volumes}; + foreach my $volid (values %{$self->{volume_map}}) { # don't clean up replicated disks! - next if defined($self->{replicated_volumes}->{$volid}); + next if $local_volumes->{$volid}->{replicated}; my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid); @@ -825,10 +830,8 @@ sub phase2 { my $input = $spice_ticket ? "$spice_ticket\n" : "\n"; $input .= "nbd_protocol_version: $nbd_protocol_version\n"; - my $number_of_online_replicated_volumes = 0; - foreach my $volid (@online_local_volumes) { - next if !$self->{replicated_volumes}->{$volid}; - $number_of_online_replicated_volumes++; + my @online_replicated_volumes = $self->filter_local_volumes('online', 1); + foreach my $volid (@online_replicated_volumes) { $input .= "replicated_volume: $volid\n"; } @@ -906,7 +909,7 @@ sub phase2 { die "unable to detect remote migration address\n" if !$raddr; - if (scalar(keys %$target_replicated_volumes) != $number_of_online_replicated_volumes) { + if (scalar(keys %$target_replicated_volumes) != scalar(@online_replicated_volumes)) { die "number of replicated disks on source and target node do not match - target node too old?\n" } @@ -1308,11 +1311,10 @@ sub phase3_cleanup { $self->{errors} = 1; } - # destroy local copies - foreach my $volid (keys %{$self->{local_volumes}}) { - # keep replicated volumes! - next if $self->{replicated_volumes}->{$volid}; + my @not_replicated_volumes = $self->filter_local_volumes(undef, 0); + # destroy local copies + foreach my $volid (@not_replicated_volumes) { eval { PVE::Storage::vdisk_free($self->{storecfg}, $volid); }; if (my $err = $@) { $self->log('err', "removing local copy of '$volid' failed - $err"); -- 2.20.1