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

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


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

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 9a27199..b2f17bc 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -214,24 +214,33 @@ 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, $type) = @_;
+
+    $type = 'vm' if !$type;
+
+    my $name = undef;
+    my $rdb = rbd_ls($scfg, $storeid);
+
+    for (my $i = 1; $i < 100; $i++) {
+	my $tn = "$type-$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