[pve-devel] [PATCH 12/20] nexenta: add find_free_volname
Alexandre Derumier
aderumier at odiso.com
Mon Dec 3 14:32:37 CET 2012
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Storage/NexentaPlugin.pm | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/PVE/Storage/NexentaPlugin.pm b/PVE/Storage/NexentaPlugin.pm
index e4fc7f1..25a097c 100644
--- a/PVE/Storage/NexentaPlugin.pm
+++ b/PVE/Storage/NexentaPlugin.pm
@@ -214,27 +214,35 @@ sub alloc_image {
die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
if $name && $name !~ m/^vm-$vmid-/;
+ $name = $class->find_free_volname($storeid, $scfg, $vmid, $fmt);
+
+ nexenta_create_zvol($scfg, $name, $size);
+ nexenta_create_lu($scfg, $name);
+ nexenta_add_lun_mapping_entry($scfg, $name);
+
+ return $name;
+}
+
+sub find_free_volname {
+ my ($class, $storeid, $scfg, $vmid, $fmt) = @_;
+
+ my $name = undef;
my $nexentapool = $scfg->{'pool'};
- if (!$name) {
- my $volumes = nexenta_list_zvol($scfg);
+ my $volumes = nexenta_list_zvol($scfg);
die "unable de get zvol list" if !$volumes;
- for (my $i = 1; $i < 100; $i++) {
- my $tn = "vm-$vmid-disk-$i";
- if (!defined ($volumes->{$nexentapool}->{$tn})) {
- $name = $tn;
- last;
- }
+ for (my $i = 1; $i < 100; $i++) {
+ my $tn = "vm-$vmid-disk-$i";
+ if (!defined ($volumes->{$nexentapool}->{$tn})) {
+ $name = $tn;
+ last;
}
}
die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
if !$name;
- nexenta_create_zvol($scfg, $name, $size);
- nexenta_create_lu($scfg, $name);
- nexenta_add_lun_mapping_entry($scfg, $name);
return $name;
}
--
1.7.10.4
More information about the pve-devel
mailing list