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