From 4797cb1c9dbf3910952f9d28d8272ff83cd25e7b Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 8 Apr 2015 21:42:49 +0530 Subject: cluster/ec: Fix readdir de-itransform Problem: gf_deitransform returns the glbal client-id in the complete graph. So except for the first disperse subvolume under dht, all the other disperse subvolumes will return a client-id greater than ec->nodes, so readdir will always error out in those subvolumes. Fix: Get the client subvolume whose client-id matches the client-id returned by gf_deitransform of offset. Change-Id: I26aa17504352d48d7ff14b390b62f49d7ab2d699 BUG: 1209113 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.org/10165 Tested-by: Gluster Build System Reviewed-by: Xavier Hernandez --- xlators/cluster/ec/src/ec-dir-read.c | 34 +++++++++++++++++++------- xlators/cluster/ec/src/ec.c | 46 ++++++++++++++++++++++++++++++++++++ xlators/cluster/ec/src/ec.h | 1 + 3 files changed, 73 insertions(+), 8 deletions(-) (limited to 'xlators') diff --git a/xlators/cluster/ec/src/ec-dir-read.c b/xlators/cluster/ec/src/ec-dir-read.c index 17e1a3d124e..ffc3ed5a7cd 100644 --- a/xlators/cluster/ec/src/ec-dir-read.c +++ b/xlators/cluster/ec/src/ec-dir-read.c @@ -296,6 +296,30 @@ out: } } +/* Returns -1 if client_id is invalid else index of child subvol in xl_list */ +int +ec_deitransform (xlator_t *this, off_t offset) +{ + int idx = -1; + int client_id = -1; + ec_t *ec = this->private; + char id[32] = {0}; + + client_id = gf_deitransform (this, offset); + sprintf (id, "%d", client_id); + if (dict_get_int32 (ec->leaf_to_subvolid, id, &idx)) { + idx = -1; + goto out; + } + +out: + if (idx < 0) { + gf_log (this->name, GF_LOG_ERROR, + "Invalid index %d in readdirp request", client_id); + } + return idx; +} + /* FOP: readdir */ void ec_adjust_readdir(ec_t * ec, int32_t idx, gf_dirent_t * entries) @@ -412,17 +436,11 @@ int32_t ec_manager_readdir(ec_fop_data_t * fop, int32_t state) if (fop->offset != 0) { int32_t idx = -1; - ec_t *ec = fop->xl->private; - - idx = gf_deitransform(fop->xl, fop->offset); - if ((idx < 0) || (idx >= ec->nodes)) { - - gf_log(fop->xl->name, GF_LOG_ERROR, - "Invalid index %d in readdirp request", idx); + idx = ec_deitransform (fop->xl, fop->offset); + if (idx < 0) { fop->error = EIO; - return EC_STATE_REPORT; } fop->mask &= 1ULL << idx; diff --git a/xlators/cluster/ec/src/ec.c b/xlators/cluster/ec/src/ec.c index fd5123d61da..5476ac6562e 100644 --- a/xlators/cluster/ec/src/ec.c +++ b/xlators/cluster/ec/src/ec.c @@ -115,6 +115,35 @@ int32_t ec_prepare_childs(xlator_t * this) return 0; } +/* This function transforms the subvol to subvol-id*/ +static int +_subvol_to_subvolid (dict_t *this, char *key, data_t *value, void *data) +{ + ec_t *ec = data; + xlator_t *subvol = NULL; + int i = 0; + int ret = -1; + + subvol = data_to_ptr (value); + for (i = 0; i < ec->nodes; i++) { + if (ec->xl_list[i] == subvol) { + ret = dict_set_int32 (this, key, i); + /* -1 stops dict_foreach and returns -1*/ + if (ret < 0) + ret = -1; + goto out; + } + } +out: + return ret; +} + +int +ec_subvol_to_subvol_id_transform (ec_t *ec, dict_t *leaf_to_subvolid) +{ + return dict_foreach (leaf_to_subvolid, _subvol_to_subvolid, ec); +} + void __ec_destroy_private(xlator_t * this) { ec_t * ec = this->private; @@ -165,6 +194,8 @@ void __ec_destroy_private(xlator_t * this) LOCK_DESTROY(&ec->lock); + if (ec->leaf_to_subvolid) + dict_unref (ec->leaf_to_subvolid); GF_FREE(ec); } } @@ -480,6 +511,21 @@ init (xlator_t *this) ec_selfheal_daemon_init (this); gf_log(this->name, GF_LOG_DEBUG, "Disperse translator initialized."); + ec->leaf_to_subvolid = dict_new (); + if (!ec->leaf_to_subvolid) + goto failed; + if (glusterfs_reachable_leaves (this, ec->leaf_to_subvolid)) { + gf_log (this->name, GF_LOG_ERROR, "Failed to build subvol " + "dictionary"); + goto failed; + } + + if (ec_subvol_to_subvol_id_transform (ec, ec->leaf_to_subvolid) < 0) { + gf_log (this->name, GF_LOG_ERROR, "Failed to build subvol-id " + "dictionary"); + goto failed; + } + return 0; failed: diff --git a/xlators/cluster/ec/src/ec.h b/xlators/cluster/ec/src/ec.h index d565bf8fcb4..54c13077993 100644 --- a/xlators/cluster/ec/src/ec.h +++ b/xlators/cluster/ec/src/ec.h @@ -47,5 +47,6 @@ struct _ec struct mem_pool * lock_pool; ec_self_heald_t shd; char vol_uuid[UUID_SIZE + 1]; + dict_t *leaf_to_subvolid; }; #endif /* __EC_H__ */ -- cgit