From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id E2E5A1FF13B for ; Wed, 22 Apr 2026 13:18:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BA46819816; Wed, 22 Apr 2026 13:14:58 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 29/54] plugin: simplify recently refactored logic in parse_volname method Date: Wed, 22 Apr 2026 13:12:55 +0200 Message-ID: <20260422111322.257380-30-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260422111322.257380-1-m.carrara@proxmox.com> References: <20260422111322.257380-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1776856346540 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.084 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: Z4OGS6VAZGLF3L7H4UZ4YXWUIGB57A73 X-Message-ID-Hash: Z4OGS6VAZGLF3L7H4UZ4YXWUIGB57A73 X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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