[pve-devel] [PATCH 12/48] nexenta: add find_free_volname

Alexandre Derumier aderumier at odiso.com
Tue Jan 29 17:13:54 CET 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Storage/NexentaPlugin.pm |   31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/PVE/Storage/NexentaPlugin.pm b/PVE/Storage/NexentaPlugin.pm
index 08accb1..d4806f3 100644
--- a/PVE/Storage/NexentaPlugin.pm
+++ b/PVE/Storage/NexentaPlugin.pm
@@ -214,27 +214,36 @@ 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, $type) = @_;
+
+    $type = "vm" if !$type;
+    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 = "$type-$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