[PATCH pve-storage v1 31/54] storage: simplify recently refactored logic in path_to_volume_id sub

Max R. Carrara
2026-04-22T11:17:01Z

Since the branches for all volume types except `images` do exactly the
same thing, just return the result of the `parse_path_as_volid()`
parsing function directly.

In order to avoid unnecessary work for the other volume types, strip
the volume type subdirectory from the given file path only for the
`images` volume type.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/PVE/Storage.pm | 40 ++++++++++------------------------------
1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 3a716894..199a6375 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -730,16 +730,16 @@ sub path_to_volume_id {
my $parse_volid_from_file_path = sub {
my ($plugin, $sid, $scfg, $vtype) = @_;

- my $vtype_subdir = plugin_get_vtype_subdir($scfg, $vtype);
-
- # Strip the vtype subdir from beginning of the current path
- # so that we don't have to take it into account when parsing the file name
- my $filename = $path;
- if ($filename !~ s!^\Q$vtype_subdir\E!!) {
- return;
- }
-
if ($vtype eq 'images') {
+ my $vtype_subdir = plugin_get_vtype_subdir($scfg, $vtype);
+
+ # Strip the vtype subdir from beginning of the current path
+ # so that we don't have to take it into account when parsing the file name
+ my $filename = $path;
+ if ($filename !~ s!^\Q$vtype_subdir\E!!) {
+ return;
+ }
+
return if $filename !~ m!/(\d+)/([^/\s]+)$!;
my $vmid = $1;
my $name = $2;
@@ -756,27 +756,7 @@ sub path_to_volume_id {
return;
}

- if ($vtype eq 'iso') {
- return parse_path_as_volid($sid, $scfg, $path, $vtype);
- }
-
- if ($vtype eq 'vztmpl') {
- return parse_path_as_volid($sid, $scfg, $path, $vtype);
- }
-
- if ($vtype eq 'backup') {
- return parse_path_as_volid($sid, $scfg, $path, $vtype);
- }
-
- if ($vtype eq 'snippets') {
- return parse_path_as_volid($sid, $scfg, $path, $vtype);
- }
-
- if ($vtype eq 'import') {
- return parse_path_as_volid($sid, $scfg, $path, $vtype);
- }
-
- return;
+ return parse_path_as_volid($sid, $scfg, $path, $vtype);
};

my $vtypes_to_check = $get_vtypes_to_check->();
--
2.47.3