[pve-devel] [PATCH 11/20] sheepdog : add find_free_volname
Alexandre Derumier
aderumier at odiso.com
Wed Dec 12 13:54:54 CET 2012
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Storage/SheepdogPlugin.pm | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm
index 8c295a1..651b270 100644
--- a/PVE/Storage/SheepdogPlugin.pm
+++ b/PVE/Storage/SheepdogPlugin.pm
@@ -151,28 +151,36 @@ 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) = @_;
+
+ my $name = undef;
+ 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;
}
}
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