[pve-devel] [PATCH 07/16] rbd: fix: move find_free_diskname + fix trailing whitespace

Alexandre Derumier aderumier at odiso.com
Sun Feb 3 09:49:34 CET 2013


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

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index acfd27f..46c66e8 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -208,6 +208,29 @@ sub path {
     return ($path, $vmid, $vtype);
 }
 
+my $find_free_diskname = sub {
+    my ($storeid, $scfg, $vmid) = @_;
+
+    my $rbd = rbd_ls($scfg, $storeid);
+    my $disk_ids = {};
+    my $dat = $rbd->{$scfg->{pool}};
+
+    foreach my $image (keys %$dat) {
+	my $volname = $dat->{$image}->{name};
+	if ($volname =~ m/(vm|base)-$vmid-disk-(\d+)/){
+	    $disk_ids->{$2} = 1;
+	}
+    }
+    #fix: can we search in $rbd hash key with a regex to find (vm|base) ?
+    for (my $i = 1; $i < 100; $i++) {
+        if (!$disk_ids->{$i}) {
+            return "vm-$vmid-disk-$i";
+        }
+    }
+
+    die "unable to allocate an image name for VM $vmid in storage '$storeid'\n";
+};
+
 sub create_base {
     my ($class, $storeid, $scfg, $volname) = @_;
 
@@ -271,29 +294,6 @@ sub clone_image {
     return $newvol;
 }
 
-my $find_free_diskname = sub {
-    my ($storeid, $scfg, $vmid) = @_;
-
-    my $rbd = rbd_ls($scfg, $storeid);
-    my $disk_ids = {};
-    my $dat = $rbd->{$scfg->{pool}};
-
-    foreach my $image (keys %$dat) {
-	my $volname = $dat->{$image}->{name};
-	if ($volname =~ m/(vm|base)-$vmid-disk-(\d+)/){
-	    $disk_ids->{$2} = 1;
-	}
-    }
-    #fix: can we search in $rbd hash key with a regex to find (vm|base) ?
-    for (my $i = 1; $i < 100; $i++) {
-        if (!$disk_ids->{$i}) {
-            return "vm-$vmid-disk-$i";
-        }
-    } 
-
-    die "unable to allocate an image name for VM $vmid in storage '$storeid'\n";
-};
-
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list