[PATCH pve-storage v1 29/54] plugin: simplify recently refactored logic in parse_volname method

Max R. Carrara
2026-04-22T11:18:51Z

Pull the if-clause with the definedness check out and make it a guard
clause, die-ing early if parsing fails.

Sum up the if-clauses of the `iso`, `vztmpl` and `snippets` volume
types, since their bodies have an identical pattern.

Keep the branches for the `backup` and `import` volume types separate.

Since the guard clause now already `die`s on a parsing failure, extend
the error message of the final `die` at the end of the method, stating
that the volume type is unhandled. This should never be hit unless we
introduce a new volume type and happen to forget to handle it in this
method.

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

diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index a3cb1343..376e2515 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -821,37 +821,31 @@ sub parse_volname {
return ('images', $name, $vmid, undef, undef, $isBase, $format);
}

- if (defined(my $parts = parse_volname_as_parts($volname))) {
- my ($vtype, $volume_path) = $parts->@{qw(vtype path)};
+ my $parts = parse_volname_as_parts($volname);
+ die "unable to parse directory volume name '$volname'\n"
+ if !defined($parts);

- if ($vtype eq 'iso') {
- return ($vtype, $volume_path, undef, undef, undef, undef, 'raw');
- }
+ my ($vtype, $volume_path) = $parts->@{qw(vtype path)};

- if ($vtype eq 'vztmpl') {
- return ($vtype, $volume_path, undef, undef, undef, undef, 'raw');
- }
-
- if ($vtype eq 'backup') {
- return ($vtype, $volume_path, $parts->{vmid}, undef, undef, undef, 'raw');
- }
-
- if ($vtype eq 'snippets') {
- return ($vtype, $volume_path, undef, undef, undef, undef, 'raw');
- }
-
- if ($vtype eq 'import') {
- my $format = $parts->{ext};
-
- if (defined(my $content_ext = $parts->{'content-ext'})) {
- $format .= "+$content_ext";
- }
-
- return ($vtype, $volume_path, undef, undef, undef, undef, $format);
- }
+ if ($vtype eq 'iso' || $vtype eq 'vztmpl' || $vtype eq 'snippets') {
+ return ($vtype, $volume_path, undef, undef, undef, undef, 'raw');
}

- die "unable to parse directory volume name '$volname'\n";
+ if ($vtype eq 'backup') {
+ return ($vtype, $volume_path, $parts->{vmid}, undef, undef, undef, 'raw');
+ }
+
+ if ($vtype eq 'import') {
+ my $format = $parts->{ext};
+
+ if (defined(my $content_ext = $parts->{'content-ext'})) {
+ $format .= "+$content_ext";
+ }
+
+ return ($vtype, $volume_path, undef, undef, undef, undef, $format);
+ }
+
+ die "unable to parse directory volume name '$volname' - unhandled volume type '$vtype'\n";
}

# FIXME: remove on the next APIAGE reset.
--
2.47.3