diff options
author | Raghavendra G <rgowdapp@redhat.com> | 2014-09-10 23:44:48 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2014-10-01 03:35:55 -0700 |
commit | ab29e0fed53f4628281be6e8290546fb88f4f6d2 (patch) | |
tree | b4de2f4e2fdd57780ab82d97fe81f1a79c637dfa /xlators/cluster/dht/src/dht-rebalance.c | |
parent | 98e8883787dc6943c4a3fc8282f91a8c73fb0803 (diff) |
cluster/dht: synchronize rename and file-migration
Change-Id: I4f243c946f76d440680b651235f925e3d0ebf0fd
BUG: 1140348
Signed-off-by: Raghavendra G <rgowdapp@redhat.com>
Reviewed-on: http://review.gluster.org/8523
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
(cherry picked from commit 21c8946b0bc05d0bc8f84906e16b8c2cbca4c9f9)
Signed-off-by: Nithya Balachandran <nbalacha@redhat.com>
Reviewed-on: http://review.gluster.org/8726
Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'xlators/cluster/dht/src/dht-rebalance.c')
-rw-r--r-- | xlators/cluster/dht/src/dht-rebalance.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c index adf723a9fb2..eda0172c3ee 100644 --- a/xlators/cluster/dht/src/dht-rebalance.c +++ b/xlators/cluster/dht/src/dht-rebalance.c @@ -714,19 +714,22 @@ int dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, int flag) { - int ret = -1; - struct iatt new_stbuf = {0,}; - struct iatt stbuf = {0,}; - struct iatt empty_iatt = {0,}; - ia_prot_t src_ia_prot = {0,}; - fd_t *src_fd = NULL; - fd_t *dst_fd = NULL; - dict_t *dict = NULL; - dict_t *xattr = NULL; - dict_t *xattr_rsp = NULL; - int file_has_holes = 0; - dht_conf_t *conf = this->private; - int rcvd_enoent_from_src = 0; + int ret = -1; + struct iatt new_stbuf = {0,}; + struct iatt stbuf = {0,}; + struct iatt empty_iatt = {0,}; + ia_prot_t src_ia_prot = {0,}; + fd_t *src_fd = NULL; + fd_t *dst_fd = NULL; + dict_t *dict = NULL; + dict_t *xattr = NULL; + dict_t *xattr_rsp = NULL; + int file_has_holes = 0; + dht_conf_t *conf = this->private; + int rcvd_enoent_from_src = 0; + struct gf_flock flock = {0, }; + loc_t tmp_loc = {0, }; + gf_boolean_t locked = _gf_false; gf_log (this->name, GF_LOG_INFO, "%s: attempting to move from %s to %s", loc->path, from->name, to->name); @@ -742,6 +745,24 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, goto out; } + flock.l_type = F_WRLCK; + + tmp_loc.inode = inode_ref (loc->inode); + uuid_copy (tmp_loc.gfid, loc->gfid); + + ret = syncop_inodelk (from, DHT_FILE_MIGRATE_DOMAIN, &tmp_loc, F_SETLKW, + &flock, NULL, NULL); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "migrate file failed: " + "%s: failed to lock file on %s (%s)", + loc->path, from->name, strerror (-ret)); + ret = -1; + goto out; + } + + locked = _gf_true; + /* Phase 1 - Data migration is in progress from now on */ ret = syncop_lookup (from, loc, dict, &stbuf, &xattr_rsp, NULL); if (ret) { @@ -952,6 +973,18 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to, ret = 0; out: + if (locked) { + flock.l_type = F_UNLCK; + + ret = syncop_inodelk (from, DHT_FILE_MIGRATE_DOMAIN, &tmp_loc, + F_SETLK, &flock, NULL, NULL); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "%s: failed to unlock file on %s (%s)", + loc->path, from->name, strerror (-ret)); + } + } + if (dict) dict_unref (dict); @@ -965,6 +998,8 @@ out: if (src_fd) syncop_close (src_fd); + loc_wipe (&tmp_loc); + return ret; } |