e7a346
From 92d3d162567828c15f9e3aa7bd2cb70c7d058efb Mon Sep 17 00:00:00 2001
e7a346
From: N Balachandran <nbalacha@redhat.com>
e7a346
Date: Fri, 9 Feb 2018 13:49:44 +0530
e7a346
Subject: [PATCH 146/148] cluster/dht: Cleanup on fallocate failure
e7a346
e7a346
It looks like fallocate leaves a non-empty
e7a346
file behind in case of some failures. We now
e7a346
truncate the file to 0 bytes on failure in
e7a346
__dht_rebalance_create_dst_file.
e7a346
e7a346
upstream patch: https://review.gluster.org/#/c/19514/
e7a346
e7a346
> Change-Id: Ia4ad7b94bb3624a301fcc87d9e36c4dc751edb59
e7a346
> BUG: 1541916
e7a346
> Signed-off-by: N Balachandran <nbalacha@redhat.com>
e7a346
e7a346
Change-Id: I0c67f62a638300d98b93710dedde438e69edb7f4
e7a346
BUG: 1540961
e7a346
Signed-off-by: N Balachandran <nbalacha@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/129923
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
Reviewed-by: Susant Palai <spalai@redhat.com>
e7a346
---
e7a346
 xlators/cluster/dht/src/dht-rebalance.c | 16 +++++++++++++++-
e7a346
 1 file changed, 15 insertions(+), 1 deletion(-)
e7a346
e7a346
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
e7a346
index 3343a2b..f9a25fb 100644
e7a346
--- a/xlators/cluster/dht/src/dht-rebalance.c
e7a346
+++ b/xlators/cluster/dht/src/dht-rebalance.c
e7a346
@@ -668,6 +668,7 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
e7a346
                                  int *fop_errno)
e7a346
 {
e7a346
         int          ret  = -1;
e7a346
+        int          ret2 = -1;
e7a346
         fd_t        *fd   = NULL;
e7a346
         struct iatt  new_stbuf = {0,};
e7a346
         struct iatt  check_stbuf= {0,};
e7a346
@@ -803,7 +804,7 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
e7a346
 
e7a346
         if (-ret == ENOENT) {
e7a346
                 gf_msg (this->name, GF_LOG_ERROR, -ret,
e7a346
-                        DHT_MSG_MIGRATE_FILE_FAILED, "%s: file does not exists"
e7a346
+                        DHT_MSG_MIGRATE_FILE_FAILED, "%s: file does not exist "
e7a346
                         "on %s", loc->path, to->name);
e7a346
                 *fop_errno = -ret;
e7a346
                 ret = -1;
e7a346
@@ -831,6 +832,19 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
e7a346
                                 DHT_MSG_MIGRATE_FILE_FAILED,
e7a346
                                 "fallocate failed for %s on %s",
e7a346
                                 loc->path, to->name);
e7a346
+
e7a346
+                        /* fallocate does not release the space in some cases
e7a346
+                         */
e7a346
+
e7a346
+                        ret2 = syncop_ftruncate (to, fd, 0,
e7a346
+                                                 NULL, NULL);
e7a346
+                        if (ret2 < 0) {
e7a346
+                                gf_msg (this->name, GF_LOG_WARNING, -ret2,
e7a346
+                                        DHT_MSG_MIGRATE_FILE_FAILED,
e7a346
+                                        "ftruncate failed for %s on %s",
e7a346
+                                        loc->path, to->name);
e7a346
+                        }
e7a346
+                        *fop_errno = -ret;
e7a346
                         ret = -1;
e7a346
                         goto out;
e7a346
                 }
e7a346
-- 
e7a346
1.8.3.1
e7a346