[pve-devel] [PATCH container 2/2] migration: avoid migrating volume images multiple times
Aaron Lauterer
a.lauterer at proxmox.com
Tue May 2 15:17:32 CEST 2023
Scan the VM config and store the volid and full path for each storage.
Do the same when we scan each storage. Then we can have these
scenarios:
* multiple storage configurations might point to the same storage
The result is, that when scanning the storages, we find the volume
multiple times.
-> we ignore them
* a VM might have multiple volumes configured, pointing to the same
volume
-> We fail with a warning that two mpX configs point to the same
volume
Without these checks, it was possible to multiply the number of volumes
with each migration (with local disk) if at least another storage was
configured, pointing to the same place.
Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---
src/PVE/LXC/Migrate.pm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm
index ccf5157..47cb94b 100644
--- a/src/PVE/LXC/Migrate.pm
+++ b/src/PVE/LXC/Migrate.pm
@@ -256,6 +256,28 @@ sub phase1 {
&$log_error($@, $volid) if $@;
};
+ # store and map already referenced absolute paths and volids
+ my $referencedpath = {}; # path -> volid
+ my $referenced = {}; # volid -> config key (e.g. mp0)
+
+ # reference volumes in config first
+ PVE::LXC::Config->foreach_volume_full($conf, { include_unused => 1 }, sub {
+ my ($key, $volume) = @_;
+ my $volid = $volume->{volume};
+ my $path = PVE::Storage::path($self->{storecfg}, $volid);
+ if (defined $referencedpath->{$path}) {
+ my $rkey = $referenced->{$referencedpath->{$path}};
+ &$log_error(
+ "'$key' and '$rkey' reference the same volume. ".
+ "(check guest and storage configuration?)\n",
+ $volid
+ );
+ return;
+ }
+ $referencedpath->{$path} = $volid;
+ $referenced->{$volid} = $key;
+ });
+
# first unused / lost volumes owned by this container
my @sids = PVE::Storage::storage_ids($self->{storecfg});
foreach my $storeid (@sids) {
@@ -280,6 +302,15 @@ sub phase1 {
PVE::Storage::foreach_volid($dl, sub {
my ($volid, $sid, $volname) = @_;
+ # check if volume is already referenced
+ my $path = PVE::Storage::path($self->{storecfg}, $volid);
+ if (defined $referencedpath->{$path} && !$referenced->{$volid}) {
+ $self->log('info', "ignoring '$volid' - already referenced by other storage '$referencedpath->{$path}'\n");
+ next;
+ }
+ $referencedpath->{$path} = $volid;
+ $referenced->{$volid} = 1;
+
$volhash->{$volid}->{ref} = 'storage';
$volhash->{$volid}->{targetsid} = $targetsid;
});
--
2.30.2
More information about the pve-devel
mailing list