From 4e9ef2cc5ca8f5568bfb6328a756f4a824f69639 Mon Sep 17 00:00:00 2001 From: N Balachandran Date: Mon, 11 Jan 2016 12:55:03 +0530 Subject: cluster/dht : Rebalance process crashes due to double fd_unref The dst_fd was being unrefed twice in case the call to __dht_rebalance_create_dst_file failed. > BUG: 1296611 > Signed-off-by: N Balachandran > Reviewed-on: http://review.gluster.org/13193 > Reviewed-by: Susant Palai > Reviewed-by: Raghavendra G > Tested-by: Raghavendra G (cherry picked from commit 36fcaf275952202ce3f1e621d3b3a34d58054c99) Change-Id: I56c5aff7fa3827887e67936b8aa1ecbd1a08a9e9 BUG: 1297309 Signed-off-by: N Balachandran Reviewed-on: http://review.gluster.org/13212 Reviewed-by: Raghavendra G Reviewed-by: Pranith Kumar Karampuri Tested-by: Pranith Kumar Karampuri CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Vijay Bellur NetBSD-regression: NetBSD Build System --- xlators/cluster/dht/src/dht-rebalance.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index a9fceb366f0..3698b340fef 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -519,7 +519,7 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc DHT_MSG_GFID_MISMATCH, "file %s exists in %s with different gfid", loc->path, to->name); - fd_unref (fd); + ret = -1; goto out; } } @@ -563,8 +563,7 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc } fd_bind (fd); - if (dst_fd) - *dst_fd = fd; + /*Reason of doing lookup after create again: *In the create, there is some time-gap between opening fd at the *server (posix_layer) and binding it in server (incrementing fd count), @@ -575,7 +574,6 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc *at the backend. */ - ret = syncop_lookup (to, loc, &check_stbuf, NULL, NULL, NULL); if (!ret) { @@ -586,7 +584,6 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc "found in lookup after create", loc->path, to->name); ret = -1; - fd_unref (fd); goto out; } @@ -597,7 +594,6 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc DHT_MSG_MIGRATE_FILE_FAILED, "%s: file does not exists" "on %s (%s)", loc->path, to->name, strerror (-ret)); ret = -1; - fd_unref (fd); goto out; } @@ -627,7 +623,15 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc /* success */ ret = 0; + if (dst_fd) + *dst_fd = fd; + out: + if (ret) { + if (fd) { + fd_unref (fd); + } + } if (dict) dict_unref (dict); @@ -898,6 +902,7 @@ __dht_rebalance_open_src_file (xlator_t *from, xlator_t *to, loc_t *loc, } fd_bind (fd); + if (src_fd) *src_fd = fd; -- cgit