api: check storage access: import: use checked_parse_volname

Use the same logic as the actual import later.

Has the nice side effect of getting rid of the unnecessary manual
dispatch to the plugin too.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2024-12-06 17:25:37 +01:00 committed by Fabian Grünbichler
parent 17f7813b2e
commit ccc3bae30a

View File

@ -164,11 +164,11 @@ my $check_storage_access = sub {
if (my $src_image = $drive->{'import-from'}) {
my $src_vmid;
my ($storeid, $volname) = PVE::Storage::parse_volume_id($src_image, 1);
my ($storeid) = PVE::Storage::parse_volume_id($src_image, 1);
if ($storeid) { # PVE-managed volume
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
(my $vtype, undef, $src_vmid, undef, undef, undef, my $fmt) = $plugin->parse_volname($volname);
(my $vtype, undef, $src_vmid, undef, undef, undef, my $fmt)
= checked_parse_volname($storecfg, $src_image);
raise_param_exc({ $ds => "$src_image has wrong type '$vtype' - needs to be 'images' or 'import'" })
if $vtype ne 'images' && $vtype ne 'import';