From 0144fde1b1639a6917e487f78490f2b84dceeae6 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 5 Jun 2017 11:30:45 +0100 Subject: [PATCH] client: avoid returning negative space available ...when a quota is set and the used bytes exceed the quota. Fixes: http://tracker.ceph.com/issues/20178 Signed-off-by: John Spray --- src/client/Client.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index cbb216aa768..9d5ad6bc140 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9361,8 +9361,9 @@ int Client::statfs(const char *path, struct statvfs *stbuf, // as the filesystem statistics. const fsblkcnt_t total = quota_root->quota.max_bytes >> CEPH_BLOCK_SHIFT; const fsblkcnt_t used = quota_root->rstat.rbytes >> CEPH_BLOCK_SHIFT; - const fsblkcnt_t free = total - used; - + // It is possible for a quota to be exceeded: arithmetic here must + // handle case where used > total. + const fsblkcnt_t free = total > used ? total - used : 0; stbuf->f_blocks = total; stbuf->f_bfree = free; -- 2.47.3