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