summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/basic/ec/ec-readdir.t20
-rw-r--r--xlators/cluster/ec/src/ec-dir-read.c34
-rw-r--r--xlators/cluster/ec/src/ec.c46
-rw-r--r--xlators/cluster/ec/src/ec.h1
4 files changed, 93 insertions, 8 deletions
diff --git a/tests/basic/ec/ec-readdir.t b/tests/basic/ec/ec-readdir.t
new file mode 100644
index 00000000000..d57bb2869c7
--- /dev/null
+++ b/tests/basic/ec/ec-readdir.t
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+# This test checks that readdir works fine on distributed disperse volume
+
+cleanup
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume create $V0 disperse 3 redundancy 1 $H0:$B0/${V0}{0..5}
+TEST $CLI volume start $V0
+
+TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "3" ec_child_up_count $V0 0
+EXPECT_WITHIN $CHILD_UP_TIMEOUT "3" ec_child_up_count $V0 1
+
+TEST touch $M0/{1..100}
+EXPECT "100" echo $(ls $M0 | wc -l)
+cleanup
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__ */