Blob Blame History Raw
From 92d3d162567828c15f9e3aa7bd2cb70c7d058efb Mon Sep 17 00:00:00 2001
From: N Balachandran <nbalacha@redhat.com>
Date: Fri, 9 Feb 2018 13:49:44 +0530
Subject: [PATCH 146/148] cluster/dht: Cleanup on fallocate failure

It looks like fallocate leaves a non-empty
file behind in case of some failures. We now
truncate the file to 0 bytes on failure in
__dht_rebalance_create_dst_file.

upstream patch: https://review.gluster.org/#/c/19514/

> Change-Id: Ia4ad7b94bb3624a301fcc87d9e36c4dc751edb59
> BUG: 1541916
> Signed-off-by: N Balachandran <nbalacha@redhat.com>

Change-Id: I0c67f62a638300d98b93710dedde438e69edb7f4
BUG: 1540961
Signed-off-by: N Balachandran <nbalacha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/129923
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-by: Susant Palai <spalai@redhat.com>
---
 xlators/cluster/dht/src/dht-rebalance.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
index 3343a2b..f9a25fb 100644
--- a/xlators/cluster/dht/src/dht-rebalance.c
+++ b/xlators/cluster/dht/src/dht-rebalance.c
@@ -668,6 +668,7 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
                                  int *fop_errno)
 {
         int          ret  = -1;
+        int          ret2 = -1;
         fd_t        *fd   = NULL;
         struct iatt  new_stbuf = {0,};
         struct iatt  check_stbuf= {0,};
@@ -803,7 +804,7 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
 
         if (-ret == ENOENT) {
                 gf_msg (this->name, GF_LOG_ERROR, -ret,
-                        DHT_MSG_MIGRATE_FILE_FAILED, "%s: file does not exists"
+                        DHT_MSG_MIGRATE_FILE_FAILED, "%s: file does not exist "
                         "on %s", loc->path, to->name);
                 *fop_errno = -ret;
                 ret = -1;
@@ -831,6 +832,19 @@ __dht_rebalance_create_dst_file (xlator_t *this, xlator_t *to, xlator_t *from,
                                 DHT_MSG_MIGRATE_FILE_FAILED,
                                 "fallocate failed for %s on %s",
                                 loc->path, to->name);
+
+                        /* fallocate does not release the space in some cases
+                         */
+
+                        ret2 = syncop_ftruncate (to, fd, 0,
+                                                 NULL, NULL);
+                        if (ret2 < 0) {
+                                gf_msg (this->name, GF_LOG_WARNING, -ret2,
+                                        DHT_MSG_MIGRATE_FILE_FAILED,
+                                        "ftruncate failed for %s on %s",
+                                        loc->path, to->name);
+                        }
+                        *fop_errno = -ret;
                         ret = -1;
                         goto out;
                 }
-- 
1.8.3.1