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 E3D3C1FF0C0 for ; Wed, 18 Nov 2026 10:14:23 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6C4A921676; Wed, 18 Nov 2026 10:14:22 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 45/51] fix #2884: support nested subdir scanning for 'vztmpl' volume type Date: Wed, 18 Nov 2026 10:14:07 +0100 Message-ID: <20261118091416.27183-1-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-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: 1794993256997 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.238 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: 6WTEARUB6EDKQ5JYVPNIC23JXTWNECTV X-Message-ID-Hash: 6WTEARUB6EDKQ5JYVPNIC23JXTWNECTV 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: Add support for parsing nested subdirectories for the 'vztmpl' volume type by adapting its corresponding regex used by parsing helpers. Add additional test cases wherever applicable to account for nested subdirectories for 'vztmpl' volumes, as done for the 'iso' volume type. Originally-by: Noel Ullreich Signed-off-by: Max R. Carrara --- src/PVE/Storage/Common/Parse.pm | 3 +- src/PVE/Storage/Common/test/parser_tests.pl | 54 ++++++++++++++ src/PVE/Storage/Plugin.pm | 4 +- src/test/filesystem_path_test.pm | 18 +++++ src/test/list_volumes_test.pm | 81 +++++++++++++++++++++ src/test/parse_volname_test.pm | 57 +++++++++++++++ src/test/path_to_volume_id_test.pm | 8 ++ 7 files changed, 222 insertions(+), 3 deletions(-) diff --git a/src/PVE/Storage/Common/Parse.pm b/src/PVE/Storage/Common/Parse.pm index 2b6ae70e..4137d09d 100644 --- a/src/PVE/Storage/Common/Parse.pm +++ b/src/PVE/Storage/Common/Parse.pm @@ -87,10 +87,11 @@ my $RE_ISO_FILE_PATH = qr! ) !xn; my $RE_VZTMPL_FILE_PATH = qr! (? + (? $RE_DIRECTORY_COMPONENTS )? (? [^/]+ \. (? (? (?i: tar) ) @@ -345,11 +346,11 @@ These are: volname => 'iso/custom-debian.iso', } Volume types that support subdirectories in their C part also have a C part if a subdirectory is specified. This is currently limited to the -C volume type. +C and C volume types. The following volume types have more specific parts in addition to the common ones: =over diff --git a/src/PVE/Storage/Common/test/parser_tests.pl b/src/PVE/Storage/Common/test/parser_tests.pl index cb8d706f..20c57885 100755 --- a/src/PVE/Storage/Common/test/parser_tests.pl +++ b/src/PVE/Storage/Common/test/parser_tests.pl @@ -228,21 +228,75 @@ my $volname_cases_vztmpl_valid = [ path => 'Alpine 3.10 default_20190626_amd64.Tar.xZ', vtype => 'vztmpl', volname => 'vztmpl/Alpine 3.10 default_20190626_amd64.Tar.xZ', }, }, + + # subdirectories + { + path => 'subdir/debian-10.0-standard_10.0-1_amd64.tar.zst', + expected => { + file => 'debian-10.0-standard_10.0-1_amd64.tar.zst', + ext => 'tar.zst', + 'ext-archive' => 'tar', + 'ext-compression' => 'zst', + dir => 'subdir', + 'disk-path' => 'subdir/debian-10.0-standard_10.0-1_amd64.tar.zst', + path => 'subdir/debian-10.0-standard_10.0-1_amd64.tar.zst', + vtype => 'vztmpl', + volname => 'vztmpl/subdir/debian-10.0-standard_10.0-1_amd64.tar.zst', + }, + }, + { + path => 'deeply/nested/dir/debian-11.0-standard_11.0-1_amd64.tar.bz2', + expected => { + file => 'debian-11.0-standard_11.0-1_amd64.tar.bz2', + ext => 'tar.bz2', + 'ext-archive' => 'tar', + 'ext-compression' => 'bz2', + dir => 'deeply/nested/dir', + 'disk-path' => 'deeply/nested/dir/debian-11.0-standard_11.0-1_amd64.tar.bz2', + path => 'deeply/nested/dir/debian-11.0-standard_11.0-1_amd64.tar.bz2', + vtype => 'vztmpl', + volname => 'vztmpl/deeply/nested/dir/debian-11.0-standard_11.0-1_amd64.tar.bz2', + }, + }, ]; my $volname_cases_vztmpl_invalid = [ { description => "Invalid file extension (vztmpl)", args => { path => 'archlinux-base_20190924-1_amd64.zip', vtype => 'vztmpl', }, expected => undef, }, + { + description => "Parent dir reference in path (beginning) (vztmpl)", + args => { + path => '../archlinux-base_20190924-1_amd64.tar.gz', + vtype => 'vztmpl', + }, + expected => undef, + }, + { + description => "Parent dir reference in path (middle) (vztmpl)", + args => { + path => 'subdir/../archlinux-base_20190924-1_amd64.tar.gz', + vtype => 'vztmpl', + }, + expected => undef, + }, + { + description => "Parent dir reference in path (end) (vztmpl)", + args => { + path => 'subdir/archlinux-base_20190924-1_amd64.tar.gz/..', + vtype => 'vztmpl', + }, + expected => undef, + }, ]; my $volname_cases_backup_valid = [ { path => 'vzdump-qemu-16110-2020_03_30-21_13_55.vma', diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 37fdc921..c932ec16 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -274,11 +274,11 @@ my $defaultData = { optional => 1, }, 'max-scan-depth' => { title => "Maximum Directory Scan Depth", description => "Maximum depth of subdirectories to traverse when searching for" - . " ISOs in directories.", + . " ISOs and container templates in directories.", type => 'integer', default => 0, minimum => 0, maximum => 50, optional => 1, @@ -2111,11 +2111,11 @@ sub list_volumes { if ($type eq 'iso' && !defined($vmid)) { return get_subdir_files($class, $storeid, $scfg, 'iso', undef, $depth); } if ($type eq 'vztmpl' && !defined($vmid)) { - return get_subdir_files($class, $storeid, $scfg, 'vztmpl', undef); + return get_subdir_files($class, $storeid, $scfg, 'vztmpl', undef, $depth); } if ($type eq 'backup') { return get_subdir_files($class, $storeid, $scfg, 'backup', $vmid); } diff --git a/src/test/filesystem_path_test.pm b/src/test/filesystem_path_test.pm index 8b3b9fdf..a511f4ef 100644 --- a/src/test/filesystem_path_test.pm +++ b/src/test/filesystem_path_test.pm @@ -81,10 +81,28 @@ my $tests = [ expected => [ "$DEFAULT_STORAGE_DIR/template/iso/foo/bar/baz/my-awesome-proxmox.iso", undef, 'iso', ], }, + { + volname => 'vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz', + snapname => undef, + expected => [ + "$DEFAULT_STORAGE_DIR/template/cache/debian-10.0-standard_10.0-1_amd64.tar.gz", + undef, + 'vztmpl', + ], + }, + { + volname => 'vztmpl/foo/bar/baz/debian-10.0-standard_10.0-1_amd64.tar.gz', + snapname => undef, + expected => [ + "$DEFAULT_STORAGE_DIR/template/cache/foo/bar/baz/debian-10.0-standard_10.0-1_amd64.tar.gz", + undef, + 'vztmpl', + ], + }, { volname => "backup/vzdump-qemu-1234-2020_03_30-21_12_40.vma", snapname => undef, expected => [ "$DEFAULT_STORAGE_DIR/dump/vzdump-qemu-1234-2020_03_30-21_12_40.vma", 1234, diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm index 59d8a56e..6d8d4faf 100644 --- a/src/test/list_volumes_test.pm +++ b/src/test/list_volumes_test.pm @@ -1387,10 +1387,29 @@ my $test_param_list = [ }, { file => "$DEFAULT_STORAGE_PATH/template/iso/1/2/3/4/5/some-installer.iso", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/some-lxc-template.tar.gz', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/1/some-lxc-template.tar.gz", + expected => undef, + }, + { + file => + "$DEFAULT_STORAGE_PATH/template/cache/1/2/3/4/5/some-lxc-template.tar.gz", + expected => undef, + }, ], }, { description => "VMID: none, nested subdirectories allowed, max-scan-depth = 1", storeid => $DEFAULT_STOREID, @@ -1432,10 +1451,35 @@ my $test_param_list = [ { # Exceeds max-scan-depth file => "$DEFAULT_STORAGE_PATH/template/iso/1/2/some-installer.iso", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/some-lxc-template.tar.gz', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/1/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/1/some-lxc-template.tar.gz', + }, + }, + { + # Exceeds max-scan-depth + file => "$DEFAULT_STORAGE_PATH/template/cache/1/2/some-lxc-template.tar.gz", + expected => undef, + }, ], }, { description => "VMID: none, nested subdirectories allowed, max-scan-depth = 5", storeid => $DEFAULT_STOREID, @@ -1487,10 +1531,47 @@ my $test_param_list = [ { # Exceeds max-scan-depth file => "$DEFAULT_STORAGE_PATH/template/iso/1/2/3/4/5/6/some-installer.iso", expected => undef, }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/some-lxc-template.tar.gz', + }, + }, + { + file => "$DEFAULT_STORAGE_PATH/template/cache/1/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/1/some-lxc-template.tar.gz', + }, + }, + { + file => + "$DEFAULT_STORAGE_PATH/template/cache/1/2/3/4/5/some-lxc-template.tar.gz", + expected => { + content => 'vztmpl', + ctime => $DEFAULT_CTIME, + format => 'tgz', + size => $DEFAULT_SIZE, + volid => 'local:vztmpl/1/2/3/4/5/some-lxc-template.tar.gz', + }, + }, + { + # Exceeds max-scan-depth + file => + "$DEFAULT_STORAGE_PATH/template/cache/1/2/3/4/5/6/some-lxc-template.tar.gz", + expected => undef, + }, ], }, { description => "VMID: none, max-scan-depth = 2, nested content dir of snippets", storeid => $DEFAULT_STOREID, diff --git a/src/test/parse_volname_test.pm b/src/test/parse_volname_test.pm index a9900152..37f2f705 100644 --- a/src/test/parse_volname_test.pm +++ b/src/test/parse_volname_test.pm @@ -280,14 +280,71 @@ my $tests = [ volname => "vztmpl/$file_name", expected => [ 'vztmpl', "$file_name", undef, undef, undef, undef, 'raw', ], }, + { + description => "Container template, $suffix, subdirectory", + volname => "vztmpl/foo/$file_name", + expected => [ + 'vztmpl', "foo/$file_name", undef, undef, undef, undef, 'raw', + ], + }, + { + description => "Container template, $suffix, nested subdirectories", + volname => "vztmpl/foo/bar/baz/$file_name", + expected => [ + 'vztmpl', "foo/bar/baz/$file_name", undef, undef, undef, undef, 'raw', + ], + }, + { + description => + "Container template, $suffix, subdirectory with same name as file", + volname => "vztmpl/$file_name/$file_name", + expected => [ + 'vztmpl', "$file_name/$file_name", undef, undef, undef, undef, 'raw', + ], + }, ); push($tests->@*, @extra_tests); } + + # Expected to fail + { + my $file_name = "$prefix.tar.gz"; + + my @extra_failed_tests = ( + { + description => + "Container template, tar.gz, parent directory reference before volume type prefix", + volname => "../vztmpl/$file_name", + expected => "unable to parse directory volume name '../vztmpl/$file_name'\n", + }, + { + description => + "Container template, tar.gz, parent directory reference at beginning of volume path", + volname => "vztmpl/../$file_name", + expected => "unable to parse directory volume name 'vztmpl/../$file_name'\n", + }, + { + description => + "Container template, tar.gz, parent directory reference at end of volume path", + volname => "vztmpl/$file_name/..", + expected => "unable to parse directory volume name 'vztmpl/$file_name/..'\n", + }, + { + description => + "Container template, tar.gz, parent directory reference between dir components of volume path", + volname => "vztmpl/foo/../bar/$file_name", + expected => + "unable to parse directory volume name 'vztmpl/foo/../bar/$file_name'\n", + }, + ); + + push($tests->@*, @extra_failed_tests); + } } # Additional tests for backup files { my $bkp_suffixes = { diff --git a/src/test/path_to_volume_id_test.pm b/src/test/path_to_volume_id_test.pm index c6c1b2e1..2f45c9b4 100644 --- a/src/test/path_to_volume_id_test.pm +++ b/src/test/path_to_volume_id_test.pm @@ -135,10 +135,18 @@ my $tests = [ file => "$DEFAULT_STORAGE_DIR/template/cache/debian-10.0-standard_10.0-1_amd64.tar.gz", expected => [ 'vztmpl', 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.gz', ], }, + { + description => 'CT template, tar.gz, nested subdirectories', + file => + "$DEFAULT_STORAGE_DIR/template/cache/foo/bar/debian-10.0-standard_10.0-1_amd64.tar.gz", + expected => [ + 'vztmpl', 'local:vztmpl/foo/bar/debian-10.0-standard_10.0-1_amd64.tar.gz', + ], + }, { description => 'CT template, wrong ending, tar bz2', file => "$DEFAULT_STORAGE_DIR/template/cache/debian-10.0-standard_10.0-1_amd64.tar.bz2", expected => [ 'vztmpl', 'local:vztmpl/debian-10.0-standard_10.0-1_amd64.tar.bz2', -- 2.47.3