[pve-devel] [PATCH storage] Fix #1858: lvm_find_free_diskname check for base
Stoiko Ivanov
s.ivanov at proxmox.com
Mon Aug 6 16:01:15 CEST 2018
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
More information about the pve-devel
mailing list