[pve-devel] [PATCH storage 2/2] Addition to #1542, get precent_used from RBDPlugin - add librados2-perl for rados commands - get RBD storage status through librados - calculate %USED if not available through librados (pre Kraken)

Alwin Antreich a.antreich at proxmox.com
Wed Nov 15 15:47:28 CET 2017


Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 PVE/CLI/pvesm.pm         |  1 +
 PVE/Storage.pm           |  6 ++++--
 PVE/Storage/RBDPlugin.pm | 14 +++++++++++++-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/PVE/CLI/pvesm.pm b/PVE/CLI/pvesm.pm
index 9455595..006f97f 100755
--- a/PVE/CLI/pvesm.pm
+++ b/PVE/CLI/pvesm.pm
@@ -144,6 +144,7 @@ my $print_status = sub {
 	my $active = $res->{active} ? 'active' : 'inactive';
 	my ($per, $per_fmt) = (0, '% 7.2f%%');
 	$per = ($res->{used}*100)/$res->{total} if $res->{total} > 0;
+	$per = $res->{percent_used} if $res->{percent_used};
 
 	if (!$res->{enabled}) {
 	    $per = 'N/A';
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 73b21e1..ada9baf 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -1063,14 +1063,16 @@ sub storage_info {
 	    next;
 	}
 
-	my ($total, $avail, $used, $active);
-	eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
+	my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+	my ($total, $avail, $used, $active, $percent_used);
+	eval { ($total, $avail, $used, $active, $percent_used) = $plugin->status($storeid, $scfg, $cache); };
 	warn $@ if $@;
 	next if !$active;
 	$info->{$storeid}->{total} = int($total);
 	$info->{$storeid}->{avail} = int($avail);
 	$info->{$storeid}->{used} = int($used);
 	$info->{$storeid}->{active} = $active;
+	$info->{$storeid}->{percent_used} = $percent_used;
     }
 
     return $info;
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 14386c4..74d19a8 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -540,6 +540,8 @@ sub status {
     my $df_cmd = &$rados_mon_cmd('df');
     my $pg_cmd = &$rados_mon_cmd('pg dump');
 
+    my ($free, $used, $total, $percent_used) = 0;
+
     foreach my $d (@{$df_cmd->{pools}}) {
 	next if ($d->{name} ne $scfg->{pool});
 	my $s_df = $d->{stats};
@@ -547,8 +549,18 @@ sub status {
 	my $used = $s_df->{bytes_used};
 	my $total = $used + $free;
 	my $active = 1;
+	my $calculation = 0;
+
+	foreach my $e (@{$pg_cmd->{pool_stats}}) {
+	    next if ($d->{id} ne $e->{poolid});
+	    my $s_pg = $e->{stat_sum};
+	    $calculation = $used * (($s_pg->{num_object_copies} - $s_pg->{num_objects_degraded}) / $s_pg->{num_object_copies});
+	    $calculation /= ($calculation + $free);
+	}
+
+	$percent_used = $s_df->{percent_used} ? $s_df->{percent_used} : ($calculation * 100);
 
-	return ($total, $free, $used, $active);
+	return ($total, $free, $used, $active, $percent_used);
     }
 }
 
-- 
2.11.0





More information about the pve-devel mailing list