From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D520E1FF0C0 for ; Wed, 18 Nov 2026 10:15:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1164321523; Wed, 18 Nov 2026 10:14:44 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 49/51] storage: resolve images in content dir overrides ending with a slash Date: Wed, 18 Nov 2026 10:14:11 +0100 Message-ID: <20261118091416.27183-5-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118091416.27183-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> <20261118091416.27183-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: 1794993265383 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.234 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: 7YUG4TE7FKXF7REDEXO5OKW3P4R4G2ZM X-Message-ID-Hash: 7YUG4TE7FKXF7REDEXO5OKW3P4R4G2ZM 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 CC: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The content dir option accepts overrides like 'images=imgs/'. The `images` branch of `path_to_volume_id()` strips the subdirectory only if it is followed by a slash, and compares the path of each listed image with the given path as strings. With a trailing slash, neither matches, so such images were never resolved, also not before the parsing rework. Since the files of other volume types may now be found in nested subdirectories, such a path falls through to the volume type of an enclosing content directory instead. With 'snippets=/' and 'images=imgs/', for example, a VM disk can resolve to a snippet. Strip trailing slashes from the subdirectory and compare the image paths in canonical form. Signed-off-by: Max R. Carrara --- src/PVE/Storage.pm | 3 +- src/PVE/Storage/Common.pm | 5 +- src/test/path_to_volume_id_test.pm | 99 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm index f3d1298d..3cd17993 100755 --- a/src/PVE/Storage.pm +++ b/src/PVE/Storage.pm @@ -8,10 +8,11 @@ use IO::Select; use IO::File; use IO::Socket::IP; use IPC::Open3; use File::Basename; use File::Path; +use File::Spec; use Cwd 'abs_path'; use Socket; use Time::Local qw(timelocal); use PVE::Cmd qw(build_ssh_command); @@ -815,11 +816,11 @@ sub path_to_volume_id { my $vollist = $plugin->list_images($sid, $scfg, $vmid); for my $info ($vollist->@*) { my ($storeid, $volname) = parse_volume_id($info->{volid}); my $volpath = $plugin->path($scfg, $volname, $storeid); - if ($volpath eq $path) { + if (File::Spec->canonpath($volpath) eq $path) { my ($parsed_vtype) = $plugin->parse_volname($volname); return ($parsed_vtype, $info->{volid}); } } diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm index d39ee3d0..68464a1a 100644 --- a/src/PVE/Storage/Common.pm +++ b/src/PVE/Storage/Common.pm @@ -431,9 +431,12 @@ sub plugin_get_vtype_subdir : prototype($$) ($scfg, $vtype) { # Intermediate step to prevent autovivification my $content_dirs = $scfg->{'content-dirs'} // {}; my $subdir = $content_dirs->{$vtype} // $DEFAULT_VTYPE_SUBDIRS->{$vtype}; - return "$path/$subdir"; + # Content dirs may contain a trailing slash, but shouldn't! + my $without_trailing_slash = "$path/$subdir" =~ s!/+$!!r; + + return $without_trailing_slash; } 1; diff --git a/src/test/path_to_volume_id_test.pm b/src/test/path_to_volume_id_test.pm index bcd9db9c..12ed94d3 100644 --- a/src/test/path_to_volume_id_test.pm +++ b/src/test/path_to_volume_id_test.pm @@ -34,10 +34,53 @@ my $DEFAULT_CFG = { }, }, }, 'order' => { 'local' => 1, + 'overrides' => 2, + 'nested' => 3, + }, +}; + +my $OVERRIDES_STORAGE_DIR = File::Temp->newdir(); # unlinks on exit +$DEFAULT_CFG->{ids}->{overrides} = { + 'shared' => 0, + 'path' => "$OVERRIDES_STORAGE_DIR", + 'type' => 'dir', + 'content' => { + 'images' => 1, + 'snippets' => 1, + 'iso' => 1, + 'vztmpl' => 1, + }, + 'content-dirs' => { + # nested inside each other + 'snippets' => 'tpl', + 'vztmpl' => 'tpl/cache', + # trailing slash + 'iso' => 'isos/', + 'images' => 'imgs/', + }, +}; + +my $NESTED_STORAGE_DIR = File::Temp->newdir(); # unlinks on exit +$DEFAULT_CFG->{ids}->{nested} = { + 'shared' => 0, + 'path' => "$NESTED_STORAGE_DIR", + 'type' => 'dir', + 'content' => { + 'iso' => 1, + 'vztmpl' => 1, + 'backup' => 1, + 'snippets' => 1, + }, + 'content-dirs' => { + # vtypes that accept subdirectories contain the directories of other vtypes + 'iso' => 'data', + 'vztmpl' => 'data/tpl', + 'backup' => 'data/tpl/dump', + 'snippets' => 'data/snippets', }, }; # Each test is comprised of the following keys: # description => to identify a single test @@ -278,10 +321,66 @@ my $tests = [ # currently not possible because it would introduce parsing ambiguities. description => 'Import, ova, subdirectory', file => "$DEFAULT_STORAGE_DIR/import/foo/import.ova", expected => [''], }, + { + description => 'Content dir override with trailing slash, ISO', + file => "$OVERRIDES_STORAGE_DIR/isos/debian.iso", + expected => [ + 'iso', 'overrides:iso/debian.iso', + ], + }, + { + description => 'Content dir override with trailing slash, image', + file => "$OVERRIDES_STORAGE_DIR/imgs/100/vm-100-disk-0.raw", + expected => [ + 'vm-vol', 'overrides:100/vm-100-disk-0.raw', + ], + }, + { + description => 'Content dir override nested in another one, vztmpl', + file => "$OVERRIDES_STORAGE_DIR/tpl/cache/debian.tar.zst", + expected => [ + 'vztmpl', 'overrides:vztmpl/debian.tar.zst', + ], + }, + { + description => 'Content dir nested in an ISO dir, snippets', + file => "$NESTED_STORAGE_DIR/data/snippets/seed.img", + expected => [ + 'snippets', 'nested:snippets/seed.img', + ], + }, + { + description => 'Content dir nested in an ISO dir, vztmpl', + file => "$NESTED_STORAGE_DIR/data/tpl/debian.tar.zst", + expected => [ + 'vztmpl', 'nested:vztmpl/debian.tar.zst', + ], + }, + { + description => 'Content dir nested in a vztmpl dir, backup', + file => "$NESTED_STORAGE_DIR/data/tpl/dump/vzdump-lxc-100-2020_03_30-21_39_30.tar.zst", + expected => [ + 'backup', 'nested:backup/vzdump-lxc-100-2020_03_30-21_39_30.tar.zst', + ], + }, + { + description => 'Content dir containing other ones, ISO in subdirectory', + file => "$NESTED_STORAGE_DIR/data/sub/debian.iso", + expected => [ + 'iso', 'nested:iso/sub/debian.iso', + ], + }, + { + description => 'Content dir override containing another one, snippets', + file => "$OVERRIDES_STORAGE_DIR/tpl/userconfig.yaml", + expected => [ + 'snippets', 'overrides:snippets/userconfig.yaml', + ], + }, ]; my sub run_tests($tests) { my $seen_vtype; my $vtype_subdirs = { map { $_ => 1 } keys plugin_get_default_vtype_subdirs()->%* }; -- 2.47.3