[pve-devel] [PATCH 11/48] sheepdog : add find_free_volname

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


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

diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm
index be1549d..6702ba3 100644
--- a/PVE/Storage/SheepdogPlugin.pm
+++ b/PVE/Storage/SheepdogPlugin.pm
@@ -151,28 +151,37 @@ sub alloc_image {
     die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
 	if  $name && $name !~ m/^vm-$vmid-/;
 
-    if (!$name) {
-	my $sheepdog = sheepdog_ls($scfg, $storeid);
-
-	for (my $i = 1; $i < 100; $i++) {
-	    my $tn = "vm-$vmid-disk-$i";
-	    if (!defined ($sheepdog->{$storeid}->{$tn})) {
-		$name = $tn;
-		last;
-	    }
+    $name = $class->find_free_volname($storeid, $scfg, $vmid);
+
+    my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
+
+    run_command($cmd, errmsg => "sheepdog create $name' error");
+
+    return $name;
+}
+
+sub find_free_volname {
+    my ($class, $storeid, $scfg, $vmid, $fmt, $type) = @_;
+
+    $type = "vm" if !$type;
+    my $name = undef;
+    my $sheepdog = sheepdog_ls($scfg, $storeid);
+
+    for (my $i = 1; $i < 100; $i++) {
+	my $tn = "$type-$vmid-disk-$i";
+	if (!defined ($sheepdog->{$storeid}->{$tn})) {
+	    $name = $tn;
+	    last;
 	}
     }
 
     die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
 	if !$name;
 
-    my $cmd = &$collie_cmd($scfg, 'vdi', 'create', $name , "${size}KB");
-
-    run_command($cmd, errmsg => "sheepdog create $name' error");
-
     return $name;
 }
 
+
 sub free_image {
     my ($class, $storeid, $scfg, $volname) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list