Blob Blame History Raw
From 78918cf18ead4637c5aea20025c319d845518733 Mon Sep 17 00:00:00 2001
From: moagrawa <moagrawa@redhat.com>
Date: Mon, 26 Mar 2018 11:00:22 +0530
Subject: [PATCH 201/201] posix: After set storage.reserve limit df does not
 show correct output

Problem: After set storage.reserve limit df does not show correct
         output on client

Solution: Update code in posix_statfs to reflect the disk usage
          correctly on client

> BUG: 1533736
> Change-Id: I2c5feda0303d0f4abe5af22fac903011792b2dc8
> Reviewed on https://review.gluster.org/#/c/19186/
> Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
> (cherry pick from commit c494445c886e16ddc6a960b9074a68fe9621ee09)

BUG: 1550982
Change-Id: I5444fad40f2df2fdcf4ab80c2641fc9cc56b18fe
Signed-off-by: moagrawa <moagrawa@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/133745
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
---
 xlators/storage/posix/src/posix.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 6856e5e..56a2ca9 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -3751,6 +3751,7 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
         struct posix_private * priv      = NULL;
         int                    shared_by = 1;
         int                    percent   = 0;
+        uint64_t               reserved_blocks = 0;
 
         VALIDATE_OR_GOTO (frame, out);
         VALIDATE_OR_GOTO (this, out);
@@ -3776,7 +3777,17 @@ posix_statfs (call_frame_t *frame, xlator_t *this,
         }
 
         percent = priv->disk_reserve;
-        buf.f_bfree = (buf.f_bfree - ((buf.f_blocks * percent) / 100));
+        reserved_blocks = (buf.f_blocks * percent) / 100;
+
+        if (buf.f_bfree > reserved_blocks) {
+                buf.f_bfree = (buf.f_bfree - reserved_blocks);
+                if (buf.f_bavail > buf.f_bfree) {
+                        buf.f_bavail = buf.f_bfree;
+                }
+        } else {
+                buf.f_bfree = 0;
+                buf.f_bavail = 0;
+        }
 
         shared_by = priv->shared_brick_count;
         if (shared_by > 1) {
-- 
1.8.3.1