From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 095E81FF138 for ; Tue, 21 Jul 2026 14:50:38 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6D2E92144D; Tue, 21 Jul 2026 14:50:37 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 21 Jul 2026 14:50:32 +0200 Message-Id: Subject: Re: [PATCH storage] fix #7811: storage: lvm: reject allocation on format and volume name mismatch To: "Elias Huhsovitz" , From: "Max R. Carrara" X-Mailer: aerc 0.18.2-0-ge037c095a049 References: <20260716103243.61836-1-e.huhsovitz@proxmox.com> In-Reply-To: <20260716103243.61836-1-e.huhsovitz@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784638206625 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.119 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) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: BSZNZWBNTZE36ESVX3MFJ7YOWZEODBKM X-Message-ID-Hash: BSZNZWBNTZE36ESVX3MFJ7YOWZEODBKM 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: On Thu Jul 16, 2026 at 12:32 PM CEST, Elias Huhsovitz wrote: > When users allocate a new volume via the API and request a specific > format (like 'qcow2'), but provide a volume name without the > corresponding extension (like 'vm-100-disk-0'), the generic API > validation misses the inconsistency. This occurs because standard LVM > raw volumes do not use file extensions. > > The LVMPlugin ignored this mismatch. It created a raw > logical volume and logged a misleading "formatting as qcow2" message. > This resulted in a confusing state where the storage lists the volume > as 'raw', but the underlying block device contains a 'qcow2' image. > > To fix this, add a new file-private subroutine, `verify_volname_format`, > to the LVM plugin. This subroutine compares the requested format with > the format implied by the volume name. If they differ, the plugin > rejects the allocation and provides a hint to correct the > volume name. Gave this a spin on my local development VM and can confirm that the check prevents allocating new qcow2 disks if the filename doesn't end with .qcow2. In particular, this fails: pvesh create /nodes/localhost/storage/lvm-thick/content \ --filename vm-116-disk-1 \ --size 4G \ --vmid 116 \ --format qcow2 But this succeeds: pvesh create /nodes/localhost/storage/lvm-thick/content \ --filename vm-116-disk-1.qcow2 \ --size 4G \ --vmid 116 \ --format qcow2 Just for completeness' sake, I also tested this with a regular `dir` storage to see if the behavior is the same now -- and indeed it is! So, what this this commit implements matches the expected behavior. The code is also neat; very nice that you're using `my sub` for the helper you're adding. The only thing that's missing is a `make tidy` run, but honestly, since that only changes one line (see below), I think it can just be run when applying this IMO. Therefore, consider: Reviewed-by: Max R. Carrara Tested-by: Max R. Carrara > > Signed-off-by: Elias Huhsovitz > --- > src/PVE/Storage/LVMPlugin.pm | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > > diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm > index a313ecc..3be833e 100644 > --- a/src/PVE/Storage/LVMPlugin.pm > +++ b/src/PVE/Storage/LVMPlugin.pm > @@ -738,12 +738,36 @@ my sub alloc_lvm_image { > > } > > +my %LVM_FORMAT_EXTENSIONS =3D ( > + raw =3D> '', ^ this guy here gets un-indented by `make tidy`. > + qcow2 =3D> 'qcow2', > +); > + > +my sub verify_volname_format { > + my ($class, $name, $fmt) =3D @_; > + > + my $expected_ext =3D $LVM_FORMAT_EXTENSIONS{$fmt}; > + return if !defined($expected_ext); > + > + my (undef, undef, undef, undef, undef, undef, $parsed_fmt) =3D $clas= s->parse_volname($name); > + > + return if $fmt eq $parsed_fmt; > + > + my $base_name =3D $name =3D~ s/\.[^.]+$//r; > + my $suggested_name =3D $expected_ext ? "$base_name.$expected_ext" : = $base_name; > + > + die "volume name '$name' does not match requested format '$fmt' " > + . "(did you mean '$suggested_name'?)\n"; > +} > + > sub alloc_image { > my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) =3D @_; > > $name =3D $class->find_free_diskname($storeid, $scfg, $vmid, $fmt) > if !$name; > > + verify_volname_format($class, $name, $fmt); > + > alloc_lvm_image($class, $storeid, $scfg, $vmid, $fmt, $name, $size); > > return $name;