[pve-devel] [PATCH storage 1/2] add generic get_next_vm_diskname sub
Thomas Lamprecht
t.lamprecht at proxmox.com
Fri Aug 24 16:47:38 CEST 2018
On 8/22/18 3:41 PM, Stoiko Ivanov wrote:
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
> PVE/Storage/Plugin.pm | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index 7db3a95..e9fe4ec 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -523,6 +523,37 @@ sub create_base {
> return $newvolname;
> }
>
> +sub get_next_vm_diskname {
> + my ($disk_list, $storeid, $vmid, $fmt, $scfg, $add_fmt_suffix) = @_;
> +
> + my $type = $scfg->{type};
> + my $plugindata = $defaultData->{plugindata}->{$type};
this is called $def in all other methods in this modules, please stick to
that... maybe also add a $valid_fmts (or $valid_formats) helper variable:
my $valid_formats = $def->{format}->[0];
could make the post-if below easier to understand.
> +
> + my $disk_regex = qr/(vm|base)-\Q$vmid\E-disk-(\d+)/;
> + $disk_regex = qr/(vm|base|subvol|basevol)-\Q$vmid\E-disk-(\d+)/
> + if $plugindata->{format}[0]->{subvol};
> +
> + my $disk_ids = {};
> + foreach my $disk (@$disk_list) {
> + if ($disk =~ m/$disk_regex/){
> + $disk_ids->{$2} = 1;
> + }
> + }
> +
> + $fmt //= '';
> + my $prefix = ($fmt eq 'subvol') ? 'subvol' : 'vm';
> + my $suffix = $add_fmt_suffix ? ".$fmt" : '';
> +
> + my $next_disk;
^^^^^^^^^
(left over) unused variable
> + for (my $i = 1; $i < 100; $i++) {
> + if (!$disk_ids->{$i}) {
> + return "$prefix-$vmid-disk-$i$suffix";
> + }
> + }
> +
> + die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
> +};
> +
> my $find_free_diskname = sub {
> my ($imgdir, $vmid, $fmt) = @_;
>
>
More information about the pve-devel
mailing list