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