retspen/webvirtmgr — pull request #360 by EmbeddedAndroid (2014-07-06 00:52:26+00:00)
Title: storage: correct usage calculation for rbd

I noticed a discrepancy in the reported used space for my ceph (rbd) cluster. The usage being report was off by approximately factor of two.

tyler@compute01:~$ sudo ceph -s
[sudo] password for tyler:
cluster 31845ace-9e1e-462e-bf15-76ed8a8dd851
health HEALTH_OK
monmap e8: 3 mons at {compute01=192.168.1.2:6789/0,compute02=192.168.1.3:6789/0,compute03=192.168.1.4:6789/0}, election epoch 976, quorum 0,1,2 compute01,compute02,compute03
mdsmap e1570: 1/1/1 up {0=compute01=up:active}
osdmap e1530: 14 osds: 14 up, 14 in
pgmap v6444614: 384 pgs, 3 pools, 4708 GB data, 1183 kobjects
9409 GB used, 27818 GB / 37228 GB avail
384 active+clean
client io 3396 B/s wr, 1 op/s

(4708 GB * 100) / 37228 GB = 12%
it should be
(9409 GB * 100) / 37228 GB = 25%

After some investigation I can conclude the following. conn.get_size() returns size, free, usage. 'free' represents the data (4708 GB), but due to replication 'usage' actually reflects the used space (9409 GB). By calculating 'used' as ('size' - 'usage') we can obtain the proper amount of used space.

I've tested this patch with DIR, LLVM, and RBD storage pools and the reflected used space / usage is correct for all variants.