From f78f26ae606c8b8f408346db0ff99027e86199d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Thu, 3 Feb 2022 13:41:40 +0100 Subject: [PATCH] volname_for_storage: parse volname before calling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to allow reusing this with remote migration, where parsing of the source volid has to happen on the source node, but this call has to happen on the target node. Signed-off-by: Fabian Grünbichler --- PVE/Storage.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index d64019f..05be3dd 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -623,19 +623,20 @@ sub abs_filesystem_path { return $path; } +# used as last resort to adapt volnames when migrating my $volname_for_storage = sub { - my ($cfg, $volid, $target_storeid) = @_; + my ($cfg, $storeid, $name, $vmid, $format) = @_; - my (undef, $name, $vmid, undef, undef, undef, $format) = parse_volname($cfg, $volid); - my $target_scfg = storage_config($cfg, $target_storeid); + my $scfg = storage_config($cfg, $storeid); - my (undef, $valid_formats) = PVE::Storage::Plugin::default_format($target_scfg); + my (undef, $valid_formats) = PVE::Storage::Plugin::default_format($scfg); my $format_is_valid = grep { $_ eq $format } @$valid_formats; - die "unsupported format '$format' for storage type $target_scfg->{type}\n" if !$format_is_valid; + die "unsupported format '$format' for storage type $scfg->{type}\n" + if !$format_is_valid; (my $name_without_extension = $name) =~ s/\.$format$//; - if ($target_scfg->{path}) { + if ($scfg->{path}) { return "$vmid/$name_without_extension.$format"; } else { return "$name_without_extension"; @@ -667,7 +668,8 @@ sub storage_migrate { } elsif ($scfg->{type} eq $tcfg->{type}) { $target_volname = $volname; } else { - $target_volname = $volname_for_storage->($cfg, $volid, $target_storeid); + my (undef, $name, $vmid, undef, undef, undef, $format) = parse_volname($cfg, $volid); + $target_volname = $volname_for_storage->($cfg, $target_storeid, $name, $vmid, $format); } my $target_volid = "${target_storeid}:${target_volname}";