887953
From 2029bf72400a380a4a0f1bf7f1b72816c70f9774 Mon Sep 17 00:00:00 2001
887953
From: N Balachandran <nbalacha@redhat.com>
887953
Date: Mon, 31 Dec 2018 17:42:27 +0530
887953
Subject: [PATCH 497/498] cluster/dht: Use percentages for space check
887953
887953
With heterogenous bricks now being supported in DHT
887953
we could run into issues where files are not migrated
887953
even though there is sufficient space in newly added bricks
887953
which just happen to be considerably smaller than older
887953
bricks. Using percentages instead of absolute available
887953
space for space checks can mitigate that to some extent.
887953
887953
upstream patch:https://review.gluster.org/#/c/glusterfs/+/19101/
887953
This is not an identical backport as there were some changes
887953
to upstream master that are not available in the downstream code.
887953
887953
Marking bug-1247563.t bad as that used to depend on the easier
887953
code to prevent a file from migrating. This will be removed
887953
once we find a way to force a file migration failure.
887953
887953
Change-Id: Ie89bfdd114406a986b3ff4f53b0bb0fae6574c8e
887953
BUG: 1290124
887953
Signed-off-by: N Balachandran <nbalacha@redhat.com>
887953
Reviewed-on: https://code.engineering.redhat.com/gerrit/159569
887953
Tested-by: RHGS Build Bot <nigelb@redhat.com>
887953
Reviewed-by: Susant Palai <spalai@redhat.com>
887953
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
887953
---
887953
 tests/bugs/distribute/bug-1247563.t     |  3 ++
887953
 xlators/cluster/dht/src/dht-rebalance.c | 57 ++++++++++++++++++++++++---------
887953
 2 files changed, 45 insertions(+), 15 deletions(-)
887953
887953
diff --git a/tests/bugs/distribute/bug-1247563.t b/tests/bugs/distribute/bug-1247563.t
887953
index f7f9258..12cd080 100644
887953
--- a/tests/bugs/distribute/bug-1247563.t
887953
+++ b/tests/bugs/distribute/bug-1247563.t
887953
@@ -55,3 +55,6 @@ COUNT=`getfacl $FPATH2 |grep -c "user:root:rwx"`
887953
 EXPECT "0" echo $COUNT
887953
 
887953
 cleanup;
887953
+
887953
+#G_TESTDEF_TEST_STATUS_CENTOS6=BAD_TEST,BUG=000000
887953
+#G_TESTDEF_TEST_STATUS_NETBSD7=BAD_TEST,BUG=000000
887953
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
887953
index d0f49d2..291b557 100644
887953
--- a/xlators/cluster/dht/src/dht-rebalance.c
887953
+++ b/xlators/cluster/dht/src/dht-rebalance.c
887953
@@ -880,8 +880,12 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
887953
         dict_t         *xdata      = NULL;
887953
         dht_layout_t   *layout     = NULL;
887953
         uint64_t        src_statfs_blocks = 1;
887953
+        uint64_t        src_total_blocks = 0;
887953
         uint64_t        dst_statfs_blocks = 1;
887953
-        double          post_availspacepercent = 0;
887953
+        uint64_t        dst_total_blocks = 0;
887953
+        uint64_t        file_blocks = 0;
887953
+        double          dst_post_availspacepercent = 0;
887953
+        double          src_post_availspacepercent = 0;
887953
 
887953
         xdata = dict_new ();
887953
         if (!xdata) {
887953
@@ -926,8 +930,24 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
887953
         }
887953
 
887953
         gf_msg_debug (this->name, 0, "min_free_disk - %f , block available - %lu ,"
887953
-                      " block size - %lu ", conf->min_free_disk, dst_statfs.f_bavail,
887953
-                      dst_statfs.f_bsize);
887953
+                      " block size - %lu ", conf->min_free_disk,
887953
+                      dst_statfs.f_bavail, dst_statfs.f_frsize);
887953
+
887953
+        dst_statfs_blocks = ((dst_statfs.f_bavail *
887953
+                             dst_statfs.f_frsize) /
887953
+                             GF_DISK_SECTOR_SIZE);
887953
+
887953
+        src_statfs_blocks = ((src_statfs.f_bavail *
887953
+                             src_statfs.f_frsize) /
887953
+                             GF_DISK_SECTOR_SIZE);
887953
+
887953
+        dst_total_blocks = ((dst_statfs.f_blocks *
887953
+                            dst_statfs.f_frsize) /
887953
+                            GF_DISK_SECTOR_SIZE);
887953
+
887953
+        src_total_blocks = ((src_statfs.f_blocks *
887953
+                            src_statfs.f_frsize) /
887953
+                            GF_DISK_SECTOR_SIZE);
887953
 
887953
         /* if force option is given, do not check for space @ dst.
887953
          * Check only if space is avail for the file */
887953
@@ -940,17 +960,22 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
887953
            subvol gains certain 'blocks' of free space. A valid check is
887953
            necessary here to avoid errorneous move to destination where
887953
            the space could be scantily available.
887953
+           With heterogenous brick support, an actual space comparison could
887953
+           prevent any files being migrated to newly added bricks if they are
887953
+           smaller then the free space available on the existing bricks.
887953
          */
887953
         if (stbuf) {
887953
-                dst_statfs_blocks = ((dst_statfs.f_bavail *
887953
-                                      dst_statfs.f_bsize) /
887953
-                                     GF_DISK_SECTOR_SIZE);
887953
-                src_statfs_blocks = ((src_statfs.f_bavail *
887953
-                                      src_statfs.f_bsize) /
887953
-                                     GF_DISK_SECTOR_SIZE);
887953
-                if ((dst_statfs_blocks) <
887953
-                    (src_statfs_blocks + stbuf->ia_blocks)) {
887953
+                file_blocks = stbuf->ia_size + GF_DISK_SECTOR_SIZE - 1;
887953
+                file_blocks /= GF_DISK_SECTOR_SIZE;
887953
 
887953
+                src_post_availspacepercent =
887953
+                        (((src_statfs_blocks + file_blocks) * 100) /
887953
+                         src_total_blocks);
887953
+
887953
+                dst_post_availspacepercent = ((dst_statfs_blocks * 100) /
887953
+                                              dst_total_blocks);
887953
+
887953
+                if (dst_post_availspacepercent < src_post_availspacepercent) {
887953
                         gf_msg (this->name, GF_LOG_WARNING, 0,
887953
                                DHT_MSG_MIGRATE_FILE_FAILED,
887953
                                "data movement of file "
887953
@@ -969,16 +994,18 @@ __dht_check_free_space (xlator_t *this, xlator_t *to, xlator_t *from, loc_t *loc
887953
                 }
887953
         }
887953
 
887953
-
887953
 check_avail_space:
887953
 
887953
         if (conf->disk_unit == 'p' && dst_statfs.f_blocks) {
887953
-                post_availspacepercent = (dst_statfs.f_bavail * 100) / dst_statfs.f_blocks;
887953
+                dst_post_availspacepercent =
887953
+                                     (dst_statfs_blocks) / dst_total_blocks;
887953
+
887953
                 gf_msg_debug (this->name, 0, "file : %s, post_availspacepercent : %lf "
887953
                               "f_bavail : %lu min-free-disk: %lf", loc->path,
887953
-                              post_availspacepercent, dst_statfs.f_bavail, conf->min_free_disk);
887953
+                              dst_post_availspacepercent, dst_statfs.f_bavail,
887953
+                              conf->min_free_disk);
887953
 
887953
-                if (post_availspacepercent < conf->min_free_disk) {
887953
+                if (dst_post_availspacepercent < conf->min_free_disk) {
887953
                         gf_msg (this->name, GF_LOG_WARNING, 0, 0,
887953
                                 "Write will cross min-free-disk for "
887953
                                 "file - %s on subvol - %s. Looking "
887953
-- 
887953
1.8.3.1
887953