[pve-devel] [PATCH] rbd: add storage space stats

Alexandre Derumier aderumier at odiso.com
Tue Oct 16 16:08:25 CEST 2012


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

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 6d1d741..b05d299 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -25,6 +25,22 @@ my $rbd_cmd = sub {
     return $cmd;
 };
 
+my $rados_cmd = sub {
+    my ($scfg, $storeid, $op, @options) = @_;
+
+    my $monhost = $scfg->{monhost};
+    $monhost =~ s/;/,/g;
+
+    my $cmd = ['/usr/bin/rados', '-p', $scfg->{pool}, '-m', $monhost, '-n', 
+	       "client.$scfg->{username}", 
+	       '--keyring', "/etc/pve/priv/ceph/${storeid}.keyring", 
+	       '--auth_supported', $scfg->{authsupported}, $op];
+
+    push @$cmd, @options if scalar(@options);
+
+    return $cmd;
+};
+
 sub rbd_ls {
     my ($scfg, $storeid) = @_;
 
@@ -220,9 +236,24 @@ sub list_images {
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
-    my $total = 0;
-    my $free = 0;
-    my $used = 0;
+    my $cmd = &$rados_cmd($scfg, $storeid, 'df');
+
+    my $stats = {};
+
+    my $parser = sub {
+	my $line = shift;
+	if ($line =~ m/^\s+total\s(\S+)\s+(\d+)/) {
+	    $stats->{$1} = $2;
+	}
+    };
+
+    eval {
+	run_command($cmd, errmsg => "rados error", errfunc => sub {}, outfunc => $parser);
+    };
+
+    my $total = $stats->{space} ? $stats->{space}*1024 : 0;
+    my $free = $stats->{avail} ? $stats->{avail}*1024 : 0;
+    my $used = $stats->{used} ? $stats->{used}*1024: 0;
     my $active = 1;
 
     return ($total, $free, $used, $active);
-- 
1.7.10.4




More information about the pve-devel mailing list