From: Elias Huhsovitz <e.huhsovitz@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Elias Huhsovitz <e.huhsovitz@proxmox.com>
Subject: [PATCH storage 1/3] plugin: refactor format parsing in parse_volname and parse_name_dir
Date: Wed, 12 Aug 2026 17:32:50 +0200 [thread overview]
Message-ID: <20260812153252.222298-2-e.huhsovitz@proxmox.com> (raw)
In-Reply-To: <20260812153252.222298-1-e.huhsovitz@proxmox.com>
Previously, `parse_volname` in several plugins (LVM, LvmThin, RBD)
hardcoded the returned format to 'raw', ignoring any format extension
present in the volume name. This prevented the detection of mismatched
formats, such as passing a `.qcow2` name to a raw-only storage.
Update `parse_volname` in `LVMPlugin`, `LvmThinPlugin`, and `RBDPlugin`
to dynamically extract the format from the volume name extension (e.g.,
`.raw`, `.qcow2`, `.vmdk`, `.subvol`), falling back to 'raw' if no known
extension is present.
Ajust `parse_name_dir` in `Plugin.pm` to allow parsing of names without
an extension, returning 'raw' as the default format. This prepares the
base class for extension-less volume names used by block storages.
Signed-off-by: Elias Huhsovitz <e.huhsovitz@proxmox.com>
---
src/PVE/Storage/LVMPlugin.pm | 2 +-
src/PVE/Storage/LvmThinPlugin.pm | 6 +++++-
src/PVE/Storage/Plugin.pm | 2 ++
src/PVE/Storage/RBDPlugin.pm | 8 +++++++-
4 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index 67ba0f7..0f2ef66 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -526,7 +526,7 @@ sub parse_volname {
if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
my $name = $1;
my $vmid = $2;
- my $format = $volname =~ m/\.qcow2$/ ? 'qcow2' : 'raw';
+ my $format = ($volname =~ m/\.(raw|qcow2|vmdk|subvol)$/) ? $1 : 'raw';
return ('images', $name, $vmid, undef, undef, undef, $format);
}
diff --git a/src/PVE/Storage/LvmThinPlugin.pm b/src/PVE/Storage/LvmThinPlugin.pm
index cadf343..d44e04d 100644
--- a/src/PVE/Storage/LvmThinPlugin.pm
+++ b/src/PVE/Storage/LvmThinPlugin.pm
@@ -66,7 +66,11 @@ sub parse_volname {
PVE::Storage::Plugin::parse_lvm_name($volname);
if ($volname =~ m/^((vm|base)-(\d+)-\S+)$/) {
- return ('images', $1, $3, undef, undef, $2 eq 'base', 'raw');
+ my $name = $1;
+ my $isbase = $2 eq 'base';
+ my $vmid = $3;
+ my $format = ($volname =~ m/\.(raw|qcow2|vmdk|subvol)$/) ? $1 : 'raw';
+ return ('images', $name, $vmid, undef, undef, $isbase, $format);
}
die "unable to parse lvm volume name '$volname'\n";
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index 4f69f9b..c5046a4 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -789,6 +789,8 @@ sub parse_name_dir {
return ($1, $4, $isbase); # (name, format, isBase)
} elsif ($name =~ m!^snap-.*\.qcow2$!) {
die "'$name' is a snapshot filename, not a volume!\n";
+ } elsif ($name =~ m!^((base-)?[^/\s]+)$!) {
+ return ($1, 'raw', $2); # (name, format, isBase)
} elsif ($name =~ m!^((base-)?[^/\s]+\.(raw|qcow2|vmdk|subvol))$!) {
return ($1, $3, $2); # (name ,format, isBase)
}
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index b537425..8ebb999 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -510,7 +510,13 @@ sub parse_volname {
my ($class, $volname) = @_;
if ($volname =~ m/^((base-(\d+)-\S+)\/)?((base)?(vm)?-(\d+)-\S+)$/) {
- return ('images', $4, $7, $2, $3, $5, 'raw');
+ my $basename = $2;
+ my $basevmid = $3;
+ my $name = $4;
+ my $isbase = $5;
+ my $vmid = $7;
+ my $format = ($volname =~ m/\.(raw|qcow2|vmdk|subvol)$/) ? $1 : 'raw';
+ return ('images', $name, $vmid, $basename, $basevmid, $isbase, $format);
}
die "unable to parse rbd volume name '$volname'\n";
--
2.47.3
next prev parent reply other threads:[~2026-08-12 15:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-12 15:32 [PATCH storage 0/3] generalize volname_for_format across storage plugins Elias Huhsovitz
2026-08-12 15:32 ` Elias Huhsovitz [this message]
2026-08-12 15:32 ` [PATCH storage 2/3] plugin: " Elias Huhsovitz
2026-08-12 15:32 ` [PATCH storage 3/3] test: plugin: add unit tests for volname_for_format Elias Huhsovitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260812153252.222298-2-e.huhsovitz@proxmox.com \
--to=e.huhsovitz@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.