storage: use f_frsize, not f_bsize, for calculating available space

The bfree and blocks fields are supposed to be in units of frsize.  We were
calculating capacity correctly using those units, but the available
calculation was using bsize instead.  Most file systems report these as the
same value specifically because many programs are buggy, but that is no
reason to rely on that behavior, or to behave inconsistently.

This bug has been present since e266ded (2008) and aa296e6c, when the code
was originally introduced (the latter via cut and paste).

Signed-off-by: Sage Weil <sage@newdream.net>
This commit is contained in:
Sage Weil 2013-02-22 15:43:00 -08:00 committed by Eric Blake
parent 91ffb42c2c
commit c2092abfb9
2 changed files with 2 additions and 2 deletions

View File

@ -709,7 +709,7 @@ parallelsStoragePoolGetAlloc(virStoragePoolDefPtr def)
def->capacity = ((unsigned long long)sb.f_frsize *
(unsigned long long)sb.f_blocks);
def->available = ((unsigned long long)sb.f_bfree *
(unsigned long long)sb.f_bsize);
(unsigned long long)sb.f_frsize);
def->allocation = def->capacity - def->available;
return 0;

View File

@ -910,7 +910,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
pool->def->capacity = ((unsigned long long)sb.f_frsize *
(unsigned long long)sb.f_blocks);
pool->def->available = ((unsigned long long)sb.f_bfree *
(unsigned long long)sb.f_bsize);
(unsigned long long)sb.f_frsize);
pool->def->allocation = pool->def->capacity - pool->def->available;
return 0;