[pve-devel] [PATCH v2 storage 28/28] storage_migrate: use volname_for_storage to determine $target_volname

Fabian Ebner f.ebner at proxmox.com
Mon Feb 24 13:44:18 CET 2020

This makes it possible to migrate raw volumes between 'dir' and 'lvm'

The call to volname_for_storage is only done when the storage types
are different. The main reason is that when X is a plugin that needs more
than the default implementation of print_volname, but doesn't implement
its own variant yet, then migration from X to X does not break.

If X is as above and a migration from Y to X happens, we end up with
the old behavior (except when X and Y use the same non-standard naming
Previously, the volname on Y was re-used, which is (most probably)
invalid for X, so import died.
Now, volname_for_storage returns a volname that (by our assumption)
is invalid for X, so import dies.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
 PVE/Storage.pm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 7a76b2c..bd58b20 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -586,14 +586,21 @@ sub storage_migrate {
     my $allow_rename = $opts->{allow_rename} ? 1 : 0; # sanitize for passing as cli parameter
     my ($storeid, $volname) = parse_volume_id($volid);
-    my $target_volname = $opts->{target_volname} || $volname;
     my $scfg = storage_config($cfg, $storeid);
+    my $tcfg = storage_config($cfg, $target_storeid);
     # no need to migrate shared content
     return $volid if $storeid eq $target_storeid && $scfg->{shared};
-    my $tcfg = storage_config($cfg, $target_storeid);
+    my $target_volname;
+    if ($opts->{target_volname}) {
+	$target_volname = $opts->{target_volname};
+    } elsif ($scfg->{type} eq $tcfg->{type}) {
+	$target_volname = $volname;
+    } else {
+	$target_volname = volname_for_storage($cfg, $volid, $target_storeid);
+    }
     my $target_volid = "${target_storeid}:${target_volname}";

More information about the pve-devel mailing list