all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
Subject: [PATCH storage 1/2] add subroutine to classify volume ids
Date: Tue, 28 Jul 2026 14:22:17 +0200	[thread overview]
Message-ID: <20260728122218.202963-2-t.ellmenreich@proxmox.com> (raw)
In-Reply-To: <20260728122218.202963-1-t.ellmenreich@proxmox.com>

To enable easier branching on different types of volume id's a new
subroutine classify_volume_id is added. It classifies the passed type
as one of 'volume', 'cdrom', 'none' or 'absolute'. Depending on how
the 'noerr' option is set values that cannot be categorized throw an
error or return undef.

The constants and subroutine are exported by the Storage module

Signed-off-by: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
---
 src/PVE/Storage.pm        | 21 +++++++++++++++++++++
 src/PVE/Storage/Plugin.pm | 25 +++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index 64ea9da..1401d69 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -40,6 +40,16 @@ use PVE::Storage::PBSPlugin;
 use PVE::Storage::BTRFSPlugin;
 use PVE::Storage::ESXiPlugin;
 
+use base qw(Exporter);
+
+our @EXPORT_OK = qw(
+    classify_volume_id
+    $VOL_NONE
+    $VOL_CDROM
+    $VOL_ABSOLUTE
+    $VOL_VOLUME
+);
+
 # Storage API version. Increment it on changes in storage API interface.
 use constant APIVER => 15;
 # Age is the number of versions we're backward compatible with.
@@ -131,6 +141,11 @@ our $OVA_CONTENT_RE_1 = qr/${SAFE_CHAR_WITH_WHITESPACE_CLASS_RE}+\.(qcow2|raw|vm
 # FIXME remove with PVE 9.0, add versioned breaks for pve-manager
 our $vztmpl_extension_re = $VZTMPL_EXT_RE_1;
 
+our $VOL_NONE = PVE::Storage::Plugin::VOL_NONE();
+our $VOL_CDROM = PVE::Storage::Plugin::VOL_CDROM();
+our $VOL_ABSOLUTE = PVE::Storage::Plugin::VOL_ABSOLUTE();
+our $VOL_VOLUME = PVE::Storage::Plugin::VOL_VOLUME();
+
 # See the QMP reference documentation.
 my $allowed_qemu_blockdev_options_file = {
     filename => 1,
@@ -615,6 +630,12 @@ sub parse_volume_id {
     return PVE::Storage::Plugin::parse_volume_id($volid, $noerr);
 }
 
+sub classify_volume_id {
+    my ($volid, $noerr) = @_;
+
+    return PVE::Storage::Plugin::classify_volume_id($volid, $noerr);
+}
+
 # test if we have read access to volid
 sub check_volume_access {
     my ($rpcenv, $user, $cfg, $vmid, $volid, $type) = @_;
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index 4f69f9b..180ad6c 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -27,6 +27,14 @@ use constant COMPRESSOR_RE => join('|', KNOWN_COMPRESSION_FORMATS);
 use constant LOG_EXT => ".log";
 use constant NOTES_EXT => ".notes";
 
+# types of volume ids
+use constant {
+    VOL_NONE => 'none',
+    VOL_CDROM => 'cdrom',
+    VOL_ABSOLUTE => 'absolute',
+    VOL_VOLUME => 'volume',
+};
+
 our @COMMON_TAR_FLAGS = qw(
     --one-file-system
     -p --sparse --numeric-owner --acls
@@ -427,6 +435,23 @@ sub parse_volume_id {
     die "unable to parse volume ID '$volid'\n";
 }
 
+sub classify_volume_id {
+    my ($volid, $noerr) = @_;
+
+    if (!defined($volid) || $volid eq "none") {
+        return VOL_NONE;
+    } elsif ($volid eq 'cdrom') {
+        return VOL_CDROM;
+    } elsif ($volid =~ m|^/|) {
+        return VOL_ABSOLUTE;
+    } elsif (parse_volume_id($volid, 1)) {
+        return VOL_VOLUME;
+    }
+
+    return undef if $noerr;
+    die "unable to classify volume ID '$volid'";
+}
+
 PVE::JSONSchema::register_format('pve-dir-override', \&verify_dir_override);
 
 sub verify_dir_override {
-- 
2.47.3





  reply	other threads:[~2026-07-28 12:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 12:22 [RFC qemu-server/storage 0/2] refactor of volume_id classification Thomas Ellmenreich
2026-07-28 12:22 ` Thomas Ellmenreich [this message]
2026-07-31 10:13   ` [PATCH storage 1/2] add subroutine to classify volume ids Fiona Ebner
2026-07-31 10:21     ` Fiona Ebner
2026-07-28 12:22 ` [PATCH qemu-server 2/2] use new classify_volume_id subroutine Thomas Ellmenreich
2026-07-31 10:13   ` Fiona Ebner
2026-07-28 13:30 ` [RFC qemu-server/storage 0/2] refactor of volume_id classification Max R. Carrara
2026-07-28 14:29   ` Thomas Ellmenreich
2026-07-29  8:27     ` Max R. Carrara
2026-07-31  9:56     ` Fiona Ebner

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=20260728122218.202963-2-t.ellmenreich@proxmox.com \
    --to=t.ellmenreich@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal