Blob Blame History Raw
From 6a24eed225ba8e325af3585959407e4fe36ec89f Mon Sep 17 00:00:00 2001
From: Susant Palai <spalai@redhat.com>
Date: Wed, 26 Jul 2017 17:12:03 +0530
Subject: [PATCH 581/587] cluster/dht: rebalance min-free-disk fix

To calculate available space on a subvolume we used to do
the following in __dht_check_free_space.

post_availspace = (dst_statfs.f_bavail * dst_statfs.f_frsize) - stbuf->ia_size

Now to subtracting the file size from available space is tricky here.
Sometime available space will be lesser than the file size and since all the
participating members in calculation are unsigned int, the result is a large
number (integer overflow).

Solution: We do not need to subtract the file size from the space available,
since fallocate would have reserved file size space already.

> Change-Id: I4f724358c44b9911933742ff3ff8d55b3dfda1cb
> BUG: 1475282
> Signed-off-by: Susant Palai <spalai@redhat.com>
> Reviewed-on: https://review.gluster.org/17876
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
> Reviewed-by: N Balachandran <nbalacha@redhat.com>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Signed-off-by: Susant Palai <spalai@redhat.com>

Change-Id: I4f724358c44b9911933742ff3ff8d55b3dfda1cb
BUG: 1474812
Signed-off-by: Susant Palai <spalai@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/114017
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/cluster/dht/src/dht-rebalance.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
index c4d58ed..896db79 100644
--- a/xlators/cluster/dht/src/dht-rebalance.c
+++ b/xlators/cluster/dht/src/dht-rebalance.c
@@ -881,8 +881,7 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
         dht_layout_t   *layout     = NULL;
         uint64_t        src_statfs_blocks = 1;
         uint64_t        dst_statfs_blocks = 1;
-        double   post_availspace = 0;
-        double   post_percent = 0;
+        double          post_availspacepercent = 0;
         int             i = 0;
 
         xdata = dict_new ();
@@ -975,9 +974,12 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
 check_avail_space:
 
         if (conf->disk_unit == 'p' && dst_statfs.f_blocks) {
-                post_availspace = (dst_statfs.f_bavail * dst_statfs.f_frsize) - stbuf->ia_size;
-                post_percent = (post_availspace * 100) / (dst_statfs.f_blocks * dst_statfs.f_frsize);
-                if (post_percent < conf->min_free_disk) {
+                post_availspacepercent = (dst_statfs.f_bavail * 100) / dst_statfs.f_blocks;
+                gf_msg_debug (this->name, 0, "file : %s, post_availspacepercent : %lf "
+                              "f_bavail : %lu min-free-disk: %lf", loc->path,
+                              post_availspacepercent, dst_statfs.f_bavail, conf->min_free_disk);
+
+                if (post_availspacepercent < conf->min_free_disk) {
                         gf_msg (this->name, GF_LOG_WARNING, 0, 0,
                                 "Write will cross min-free-disk for "
                                 "file - %s on subvol - %s. Looking "
@@ -991,7 +993,11 @@ check_avail_space:
         }
 
         if (conf->disk_unit != 'p' &&
-            ((dst_statfs.f_bavail * dst_statfs.f_frsize) - stbuf->ia_size) < conf->min_free_disk) {
+            ((dst_statfs.f_bavail * dst_statfs.f_frsize) < conf->min_free_disk)) {
+                gf_msg_debug (this->name, 0, "file : %s,  destination frsize: %lu "
+                              "f_bavail : %lu min-free-disk: %lf", loc->path,
+                              dst_statfs.f_frsize, dst_statfs.f_bavail, conf->min_free_disk);
+
                 gf_msg (this->name, GF_LOG_WARNING, 0, 0, "Write will cross "
                         "min-free-disk for file - %s on subvol - %s. Looking "
                         "for new subvol", loc->path, to->name);
-- 
1.8.3.1