[PATCH pve-storage v1 15/54] storage: heave vtype file path parsing logic inside loop into helper

Max R. Carrara
2026-04-22T11:15:44Z

src/PVE/Storage.pm | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index e9b0cb7e..2886ab9e 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -712,10 +712,9 @@ sub path_to_volume_id {
# for example when nfs storage is not mounted
$path = abs_path($path) || $path;

- for my $sid (keys $ids->%*) {
- my $scfg = $ids->{$sid};
- next if !$scfg->{path};
- my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+ my $parse_volid_from_file_path = sub {
+ my ($plugin, $sid, $scfg) = @_;
+
my $imagedir = plugin_get_vtype_subdir($scfg, 'images');
my $isodir = plugin_get_vtype_subdir($scfg, 'iso');
my $tmpldir = plugin_get_vtype_subdir($scfg, 'vztmpl');
@@ -763,6 +762,17 @@ sub path_to_volume_id {
my $name = $1;
return ('import', "$sid:import/$name");
}
+
+ return ('');
+ };
+
+ for my $sid (keys $ids->%*) {
+ my $scfg = $ids->{$sid};
+ next if !$scfg->{path};
+ my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+ my ($vtype, $volid) = $parse_volid_from_file_path->($plugin, $sid, $scfg);
+ return ($vtype, $volid) if $vtype;
}

# can't map path to volume id
--
2.47.3