From e46a57fda716c00b7c490be74485863c80d6f7b4 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Sun, 8 Apr 2012 11:40:48 +0530 Subject: features/quota: don't adjust statfs buffer if size used is already greater than available limit. members f_bfree and f_bavail of struct statfs are unsigned types. A negative value assigned to them is interpreted as some positive number and resulting in incorrect output of df output. Signed-off-by: Raghavendra G Change-Id: I4d3d38b9bb6f675958ee38ad4d6c71ebcf4bb9a1 BUG: 773530 Reviewed-on: http://review.gluster.com/3102 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Vijay Bellur --- xlators/features/quota/src/quota.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'xlators/features/quota/src') diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 77218bc4eb4..f6c4e0099b9 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -2805,18 +2805,20 @@ quota_fremovexattr (call_frame_t *frame, xlator_t *this, return 0; } + int32_t quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, struct statvfs *buf, dict_t *xdata) { - inode_t *root_inode = NULL; - quota_priv_t *priv = NULL; - uint64_t value = 0; - quota_inode_ctx_t *ctx = NULL; - limits_t *limit_node = NULL; - int64_t usage = -1; - int64_t avail = -1; + inode_t *root_inode = NULL; + quota_priv_t *priv = NULL; + uint64_t value = 0; + quota_inode_ctx_t *ctx = NULL; + limits_t *limit_node = NULL; + int64_t usage = -1; + int64_t avail = -1; + int64_t blocks = 0; root_inode = cookie; @@ -2851,7 +2853,12 @@ quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, list_for_each_entry (limit_node, &priv->limit_head, limit_list) { /* Notice that this only works for volume-level quota. */ if (strcmp (limit_node->path, "/") == 0) { - buf->f_blocks = limit_node->value / buf->f_bsize; + blocks = limit_node->value / buf->f_bsize; + if (usage > blocks) { + break; + } + + buf->f_blocks = blocks; avail = buf->f_blocks - usage; if (buf->f_bfree > avail) { buf->f_bfree = avail; -- cgit