[pve-devel] [PATCH 4/4] sheepdog : retrieve parent of a clone

Alexandre Derumier aderumier at odiso.com
Wed Nov 21 18:11:34 CET 2012


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

diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm
index 5aff893..3e5839e 100644
--- a/PVE/Storage/SheepdogPlugin.pm
+++ b/PVE/Storage/SheepdogPlugin.pm
@@ -25,21 +25,51 @@ my $collie_cmd = sub {
 sub sheepdog_ls {
     my ($scfg, $storeid) = @_;
 
-    my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
+    my $cmd = &$collie_cmd($scfg, 'vdi', 'graph');
+
+    my $relationship = {};
+    my $child = undef;
+
+    run_command($cmd, outfunc => sub {
+        my $line = shift;
+
+	my $parent = undef;
+	my $name = undef;
+
+        $line = trim($line);
+
+	if ($line =~ /\"(\S+)\"\s->\s\"(\S+)\"/) {
+	    $parent = $1;
+	    $child = $2;
+	    $relationship->{$child}->{parent} = $parent;
+	}
+	elsif ($line =~ /group\s\=\s\"(\S+)\",/) {
+	    $name = $1;
+	    $relationship->{$child}->{name} = $name if $child;
+
+	}
+
+    });
+
+
+    $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
 
     my $list = {};
 
     run_command($cmd, outfunc => sub {
         my $line = shift;
         $line = trim($line);
-	if ($line =~ /= (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s/) {
-	    my $image = $1;
-	    my $owner = $2;
+	if ($line =~ /(=|c) (vm-(\d+)-\S+)\s+(\d+)\s+(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)\s(\d+)/) {
+	    my $image = $2;
+	    my $owner = $3;
 	    my $size = $4;
-
+	    my $idvdi = $9;
+	    my $parentid = $relationship->{$idvdi}->{parent} if $relationship->{$idvdi}->{parent};
+	    my $parent = $relationship->{$parentid}->{name};
 	    $list->{$storeid}->{$image} = {
 		name => $image,
 		size => $size,
+		parent => $parent,
 		vmid => $owner
 	    };
 	}
-- 
1.7.10.4




More information about the pve-devel mailing list