[pve-devel] [PATCH] rbd: get volume size for volumes list

Alexandre Derumier aderumier at odiso.com
Tue Oct 16 16:38:13 CEST 2012


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

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index b05d299..33ae853 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -56,7 +56,7 @@ sub rbd_ls {
 
 	    $list->{$scfg->{pool}}->{$image} = {
 		name => $image,
-		size => 0,
+		size => rbd_volume_size($scfg, $storeid, $image),
 		vmid => $owner
 	    };
 	}
@@ -72,6 +72,26 @@ sub rbd_ls {
     return $list;
 }
 
+sub rbd_volume_size {
+    my ($scfg, $storeid, $volname) = @_;
+
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
+    my $size = undef;
+    my $parser = sub {
+	my $line = shift;
+
+	if ($line =~ m/size (\d+) MB in (\d+) objects/) {
+	    $size = $1;
+	}
+    };
+
+    run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
+
+    $size = $size*1024*1024 if $size;
+
+    return $size;
+}
+
 sub addslashes {
     my $text = shift;
     $text =~ s/;/\\;/g;
@@ -282,21 +302,7 @@ sub deactivate_volume {
 sub volume_size_info {
     my ($class, $scfg, $storeid, $volname, $timeout) = @_;
 
-    my $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
-    my $size = undef;
-    my $parser = sub {
-        my $line = shift;
-
-        if ($line =~ m/size (\d+) MB in (\d+) objects/) {
-            $size = $1;
-        }
-    };
-
-    run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
-
-    $size = $size*1024*1024 if $size;
-
-    return $size;
+    return rbd_volume_size($scfg, $storeid, $volname);
 }
 
 sub volume_resize {
-- 
1.7.10.4




More information about the pve-devel mailing list