9f5ccc
From 5b1bfebacac649e6f5051316e4075309caf93901 Mon Sep 17 00:00:00 2001
9f5ccc
From: Barak Sason Rofman <bsasonro@redhat.com>
9f5ccc
Date: Tue, 21 Apr 2020 19:13:41 +0300
9f5ccc
Subject: [PATCH 364/367] dht - fixing rebalance failures for files with holes
9f5ccc
9f5ccc
Rebalance process handling of files which contains holes casued
9f5ccc
rebalance to fail with "No space left on device" errors.
9f5ccc
This patch modifies the code-flow in such a way that files with holes
9f5ccc
will be rebalanced correctly.
9f5ccc
9f5ccc
backport of https://review.gluster.org/#/c/glusterfs/+/24357/
9f5ccc
>fixes: #1187
9f5ccc
>Change-Id: I89bc3d4ea7f074db7213d759c49307f379543932
9f5ccc
>Signed-off-by: Barak Sason Rofman <bsasonro@redhat.com>
9f5ccc
9f5ccc
BUG: 1823703
9f5ccc
Change-Id: I89bc3d4ea7f074db7213d759c49307f379543932
9f5ccc
Signed-off-by: Barak Sason Rofman <bsasonro@redhat.com>
9f5ccc
Reviewed-on: https://code.engineering.redhat.com/gerrit/198579
9f5ccc
Tested-by: RHGS Build Bot <nigelb@redhat.com>
9f5ccc
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9f5ccc
---
9f5ccc
 xlators/cluster/dht/src/dht-rebalance.c | 21 ++++++++++-----------
9f5ccc
 1 file changed, 10 insertions(+), 11 deletions(-)
9f5ccc
9f5ccc
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
9f5ccc
index f4c62b8..7d9df02 100644
9f5ccc
--- a/xlators/cluster/dht/src/dht-rebalance.c
9f5ccc
+++ b/xlators/cluster/dht/src/dht-rebalance.c
9f5ccc
@@ -650,7 +650,7 @@ out:
9f5ccc
 static int
9f5ccc
 __dht_rebalance_create_dst_file(xlator_t *this, xlator_t *to, xlator_t *from,
9f5ccc
                                 loc_t *loc, struct iatt *stbuf, fd_t **dst_fd,
9f5ccc
-                                int *fop_errno)
9f5ccc
+                                int *fop_errno, int file_has_holes)
9f5ccc
 {
9f5ccc
     int ret = -1;
9f5ccc
     int ret2 = -1;
9f5ccc
@@ -819,7 +819,7 @@ __dht_rebalance_create_dst_file(xlator_t *this, xlator_t *to, xlator_t *from,
9f5ccc
 
9f5ccc
     /* No need to bother about 0 byte size files */
9f5ccc
     if (stbuf->ia_size > 0) {
9f5ccc
-        if (conf->use_fallocate) {
9f5ccc
+        if (conf->use_fallocate && !file_has_holes) {
9f5ccc
             ret = syncop_fallocate(to, fd, 0, 0, stbuf->ia_size, NULL, NULL);
9f5ccc
             if (ret < 0) {
9f5ccc
                 if (ret == -EOPNOTSUPP || ret == -EINVAL || ret == -ENOSYS) {
9f5ccc
@@ -846,9 +846,7 @@ __dht_rebalance_create_dst_file(xlator_t *this, xlator_t *to, xlator_t *from,
9f5ccc
                     goto out;
9f5ccc
                 }
9f5ccc
             }
9f5ccc
-        }
9f5ccc
-
9f5ccc
-        if (!conf->use_fallocate) {
9f5ccc
+        } else {
9f5ccc
             ret = syncop_ftruncate(to, fd, stbuf->ia_size, NULL, NULL, NULL,
9f5ccc
                                    NULL);
9f5ccc
             if (ret < 0) {
9f5ccc
@@ -1728,9 +1726,13 @@ dht_migrate_file(xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
9f5ccc
         goto out;
9f5ccc
     }
9f5ccc
 
9f5ccc
+    /* Try to preserve 'holes' while migrating data */
9f5ccc
+    if (stbuf.ia_size > (stbuf.ia_blocks * GF_DISK_SECTOR_SIZE))
9f5ccc
+        file_has_holes = 1;
9f5ccc
+
9f5ccc
     /* create the destination, with required modes/xattr */
9f5ccc
     ret = __dht_rebalance_create_dst_file(this, to, from, loc, &stbuf, &dst_fd,
9f5ccc
-                                          fop_errno);
9f5ccc
+                                          fop_errno, file_has_holes);
9f5ccc
     if (ret) {
9f5ccc
         gf_msg(this->name, GF_LOG_ERROR, 0, 0,
9f5ccc
                "Create dst failed"
9f5ccc
@@ -1774,8 +1776,8 @@ dht_migrate_file(xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
9f5ccc
          * destination. We need to do update this only post migration
9f5ccc
          * as in case of failure the linkto needs to point to the source
9f5ccc
          * subvol */
9f5ccc
-        ret = __dht_rebalance_create_dst_file(this, to, from, loc, &stbuf,
9f5ccc
-                                              &dst_fd, fop_errno);
9f5ccc
+        ret = __dht_rebalance_create_dst_file(
9f5ccc
+            this, to, from, loc, &stbuf, &dst_fd, fop_errno, file_has_holes);
9f5ccc
         if (ret) {
9f5ccc
             gf_log(this->name, GF_LOG_ERROR,
9f5ccc
                    "Create dst failed"
9f5ccc
@@ -1862,9 +1864,6 @@ dht_migrate_file(xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
9f5ccc
             ret = 0;
9f5ccc
         goto out;
9f5ccc
     }
9f5ccc
-    /* Try to preserve 'holes' while migrating data */
9f5ccc
-    if (stbuf.ia_size > (stbuf.ia_blocks * GF_DISK_SECTOR_SIZE))
9f5ccc
-        file_has_holes = 1;
9f5ccc
 
9f5ccc
     ret = __dht_rebalance_migrate_data(this, defrag, from, to, src_fd, dst_fd,
9f5ccc
                                        stbuf.ia_size, file_has_holes,
9f5ccc
-- 
9f5ccc
1.8.3.1
9f5ccc