[pve-devel] [PATCH 10/31] rbd : add find_free_volname

Alexandre Derumier aderumier at odiso.com
Tue Jan 8 15:45:16 CET 2013


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

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index b08fe54..003585a 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -208,24 +208,31 @@ sub alloc_image {
     die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
 	if  $name && $name !~ m/^vm-$vmid-/;
 
-    if (!$name) {
-	my $rdb = rbd_ls($scfg, $storeid);
-
-	for (my $i = 1; $i < 100; $i++) {
-	    my $tn = "vm-$vmid-disk-$i";
-	    if (!defined ($rdb->{$scfg->{pool}}->{$tn})) {
-		$name = $tn;
-		last;
-	    }
+    $name = $class->find_free_volname($storeid, $scfg, $vmid, $fmt);
+
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--format' , 2, '--size', ($size/1024), $name);
+    run_command($cmd, errmsg => "rbd create $name' error", errfunc => sub {});
+
+    return $name;
+}
+
+sub find_free_volname {
+    my ($class, $storeid, $scfg, $vmid, $fmt) = @_;
+
+    my $name = undef;
+    my $rdb = rbd_ls($scfg, $storeid);
+
+    for (my $i = 1; $i < 100; $i++) {
+	my $tn = "vm-$vmid-disk-$i";
+	if (!defined ($rdb->{$scfg->{pool}}->{$tn})) {
+	    $name = $tn;
+	    last;
 	}
     }
 
     die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
 	if !$name;
 
-    my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--format' , 2, '--size', ($size/1024), $name);
-    run_command($cmd, errmsg => "rbd create $name' error", errfunc => sub {});
-
     return $name;
 }
 
-- 
1.7.10.4




More information about the pve-devel mailing list