From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 qemu-server 02/13] migration: split sync_disks into two functions
Date: Fri, 29 Jan 2021 16:11:32 +0100 [thread overview]
Message-ID: <20210129151143.10014-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210129151143.10014-1-f.ebner@proxmox.com>
by making local_volumes class-accessible. One functions is for scanning all local
volumes and one is for actually syncing offline volumes via storage_migrate. The
exception is replicated volumes, this still happens during the scan for now.
Also introduce a filter_local_volumes helper, to makes life easier.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
Changes from v1:
* rebase (include the deactivate_volumes block that didn't exist back then)
PVE/QemuMigrate.pm | 108 +++++++++++++++++++++++++++++----------------
1 file changed, 69 insertions(+), 39 deletions(-)
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 5c019fc..0cc13df 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -9,6 +9,7 @@ use POSIX qw( WNOHANG );
use Time::HiRes qw( usleep );
use PVE::Cluster;
+use PVE::GuestHelpers qw(safe_string_ne);
use PVE::INotify;
use PVE::RPCEnvironment;
use PVE::Replication;
@@ -357,7 +358,7 @@ sub prepare {
return $running;
}
-sub sync_disks {
+sub scan_local_volumes {
my ($self, $vmid) = @_;
my $conf = $self->{vmconf};
@@ -366,12 +367,13 @@ sub sync_disks {
# and their old_id => new_id pairs
$self->{volumes} = [];
$self->{volume_map} = {};
+ $self->{local_volumes} = {};
my $storecfg = $self->{storecfg};
eval {
# found local volumes and their origin
- my $local_volumes = {};
+ my $local_volumes = $self->{local_volumes};
my $local_volumes_errors = {};
my $other_errors = [];
my $abort = 0;
@@ -608,11 +610,7 @@ sub sync_disks {
PVE::QemuServer::update_efidisk_size($conf);
}
- $self->log('info', "copying local disk images") if scalar(%$local_volumes);
-
foreach my $volid (sort keys %$local_volumes) {
- my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
- 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;
@@ -624,39 +622,70 @@ sub sync_disks {
} else {
next if $self->{replicated_volumes}->{$volid};
push @{$self->{volumes}}, $volid;
- my $opts = $self->{opts};
- # 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);
-
- my $storage_migrate_opts = {
- 'ratelimit_bps' => $bwlimit,
- 'insecure' => $opts->{migration_type} eq 'insecure',
- 'with_snapshots' => $local_volumes->{$volid}->{snapshots},
- 'allow_rename' => !$local_volumes->{$volid}->{is_vmstate},
- };
-
- my $logfunc = sub { $self->log('info', $_[0]); };
- my $new_volid = eval {
- PVE::Storage::storage_migrate($storecfg, $volid, $self->{ssh_info},
- $targetsid, $storage_migrate_opts, $logfunc);
- };
- 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");
-
- eval { PVE::Storage::deactivate_volumes($storecfg, [$volid]); };
- if (my $err = $@) {
- $self->log('warn', $err);
- }
+ $local_volumes->{$volid}->{migration_mode} = 'offline';
}
}
};
- die "Failed to sync data - $@" if $@;
+ die "Problem found while scanning volumes - $@" if $@;
+}
+
+sub filter_local_volumes {
+ my ($self, $migration_mode) = @_;
+
+ 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);
+ push @filtered_volids, $volid;
+ }
+
+ return @filtered_volids;
+}
+
+sub sync_offline_local_volumes {
+ my ($self) = @_;
+
+ my $local_volumes = $self->{local_volumes};
+ my @volids = $self->filter_local_volumes('offline');
+
+ my $storecfg = $self->{storecfg};
+ my $opts = $self->{opts};
+
+ $self->log('info', "copying local disk images") if scalar(@volids);
+
+ foreach my $volid (@volids) {
+ my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
+ my $targetsid = PVE::QemuServer::map_storage($self->{opts}->{storagemap}, $sid);
+ # use 'migration' 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);
+
+ my $storage_migrate_opts = {
+ 'ratelimit_bps' => $bwlimit,
+ 'insecure' => $opts->{migration_type} eq 'insecure',
+ 'with_snapshots' => $local_volumes->{$volid}->{snapshots},
+ 'allow_rename' => !$local_volumes->{$volid}->{is_vmstate},
+ };
+
+ my $logfunc = sub { $self->log('info', $_[0]); };
+ my $new_volid = eval {
+ PVE::Storage::storage_migrate($storecfg, $volid, $self->{ssh_info},
+ $targetsid, $storage_migrate_opts, $logfunc);
+ };
+ 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");
+
+ eval { PVE::Storage::deactivate_volumes($storecfg, [$volid]); };
+ if (my $err = $@) {
+ $self->log('warn', $err);
+ }
+ }
}
sub cleanup_remotedisks {
@@ -704,11 +733,12 @@ sub phase1 {
$conf->{lock} = 'migrate';
PVE::QemuConfig->write_config($vmid, $conf);
- sync_disks($self, $vmid);
-
- # sync_disks fixes disk sizes to match their actual size, write changes so
+ # scan_local_volumes fixes disk sizes to match their actual size, write changes so
# target allocates correct volumes
+ $self->scan_local_volumes($vmid);
PVE::QemuConfig->write_config($vmid, $conf);
+
+ $self->sync_offline_local_volumes();
};
sub phase1_cleanup {
--
2.20.1
next prev parent reply other threads:[~2021-01-29 15:12 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 ` Fabian Ebner [this message]
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 ` [pve-devel] [PATCH v2 qemu-server 12/13] migration: split out replication from scan_local_volumes Fabian Ebner
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-3-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