[pve-devel] applied: [PATCH storage] Fix #1858: lvm_find_free_diskname check for base
Dietmar Maurer
dietmar at proxmox.com
Tue Aug 7 12:15:48 CEST 2018
applied
> On August 6, 2018 at 4:01 PM Stoiko Ivanov <s.ivanov at proxmox.com> wrote:
>
>
> lvm_find_free_diskname only checked for existing volumes starting with 'vm-',
> and not with 'base-'.
>
> Unify implementation with other Plugins.
>
> Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
> ---
> I would refactor the various implementations in the storage plugins to use
> a common helper method, and send a follow-up, unless someone objects.
>
> PVE/Storage/LVMPlugin.pm | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm
> index e842bab..19bac55 100644
> --- a/PVE/Storage/LVMPlugin.pm
> +++ b/PVE/Storage/LVMPlugin.pm
> @@ -293,18 +293,21 @@ sub lvm_find_free_diskname {
>
> my $name;
>
> - for (my $i = 1; $i < 100; $i++) {
> - my $tn = "vm-$vmid-disk-$i";
> - if (!defined ($lvs->{$vg}->{$tn})) {
> - $name = $tn;
> - last;
> + my $disk_ids = {};
> + my @vols = keys(%{$lvs->{$vg}});
> +
> + foreach my $vol (@vols) {
> + if ($vol =~ m/(vm|base)-\Q$vmid\E-disk-(\d+)/){
> + $disk_ids->{$2} = 1;
> }
> }
>
> - die "unable to allocate an image name for ID $vmid in storage
> '$storeid'\n"
> - if !$name;
> + for (my $i = 1; $i < 100; $i++) {
> + return "vm-$vmid-disk-$i" if !$disk_ids->{$i};
> + }
> +
> + die "unable to allocate an image name for ID $vmid in storage
> '$storeid'\n";
>
> - return $name;
> }
>
> sub alloc_image {
> --
> 2.11.0
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list