volname_for_storage: parse volname before calling

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 <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2022-02-03 13:41:40 +01:00
committed by Thomas Lamprecht
parent e7bc1f03b7
commit f78f26ae60

View File

@ -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}";