[libvirt] [PATCH] 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> --- src/parallels/parallels_storage.c | 2 +- src/storage/storage_backend_fs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 1186296..f696fcb 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -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; diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index a582804..c1684f7 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -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; -- 1.7.2.5

On 02/22/2013 04:43 PM, Sage Weil wrote:
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.
I checked POSIX as a reference: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_statvfs.h.html#... unsigned long f_bsize File system block size. unsigned long f_frsize Fundamental file system block size. fsblkcnt_t f_blocks Total number of blocks on file system in units of f_frsize. fsblkcnt_t f_bfree Total number of free blocks.
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> --- src/parallels/parallels_storage.c | 2 +- src/storage/storage_backend_fs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
ACK and pushed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Sage Weil