[pve-devel] [PATCH storage 16/26] common: add volume_type_from_name convenience helper

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jul 30 11:09:23 CEST 2025


On Wed, Jul 30, 2025 at 10:36:49AM +0200, Fabian Grünbichler wrote:
> On July 29, 2025 1:15 pm, Wolfgang Bumiller wrote:
> > For plugins which follow our new naming scheme.
> > 
> > Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> > ---
> >  src/PVE/Storage/Common.pm | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> > 
> > diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm
> > index 7086e1c..813fba6 100644
> > --- a/src/PVE/Storage/Common.pm
> > +++ b/src/PVE/Storage/Common.pm
> > @@ -313,6 +313,35 @@ sub should_list_images : prototype($$) ($expected_content_type, $volume_type) {
> >      return $expected_content_type eq $volume_type;
> >  }
> >  
> > +=head3 volume_type_from_name
> > +
> > +    volume_type_from_name($name)
> > +
> > +This is available for storages which follow our most common naming scheme relating to volume types:
> > +A "vol-vm-" prefix for the C<vm-vol> vtype, and a "vol-ct-" prefix for the C<ct-vol> vtype.
> > +
> > +This function allows (and ignores) an optional "base-" prefix, such that
> > +"base-vol-ct-100-disk-0.raw" would return C<ct-vol>.
> > +
> > +In any other case it returns C<images>.
> > +
> > +=cut
> > +
> > +sub volume_type_from_name : prototype($) {
> > +    my ($name) = @_;
> > +
> > +    if ($name =~ /^(?:base-)?(?:(?:sub)?vol-(vm|ct))-/) {
> > +        return "$1-vol";
> > +    }
> > +
> > +    # Note: Despite the legacy `subvol-*` and `basevol-*` dirs always being containers, giving
> > +    # them the vtype `ct-vol` would break `path_to_volume_id` which would expect their volids to
> > +    # be in the `cts/` subdir instead of in `images/`...
> > +    # return 'ct-vol' if $name =~ /^(?:subvol|basevol)-/;
> > +
> > +    return 'images';
> > +}
> 
> ZFSPoolPlugin has it's own variant of this, and this one here seems
> unused?

Yeah, that's a leftover from transitional patches I had...




More information about the pve-devel mailing list