summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorKaushik BV <kaushikbv@gluster.com>2011-04-18 10:42:03 +0000
committerAnand Avati <avati@gluster.com>2011-04-19 02:29:44 -0700
commit7f61b4d1c31181a2c01285a45a99a3ded22349ee (patch)
tree46418ed6429e5761c56552ff946bb7b740dd655c /xlators/mgmt
parent94d32434fdb1d7fc333ab9bf4bf8d3a4eb0dff9e (diff)
mgmt/glusterd: Send the gsync sessions that are running to the new peer.
Signed-off-by: Kaushik BV <kaushikbv@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2797 ([glusterfs-3.2.0qa13]: peer probe fails with gsync running) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2797
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c135
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h6
2 files changed, 100 insertions, 41 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 16b2bf08136..b7ecc4ccd44 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -1299,30 +1299,26 @@ out:
}
void
-_add_volume_option_to_dict (dict_t *this, char *key, data_t *value, void *data)
+_add_volinfo_dict_to_prdict (dict_t *this, char *key, data_t *value, void *data)
{
int exists = 0;
- glusterd_volopt_ctx_t *ctx = NULL;
+ glusterd_voldict_ctx_t *ctx = NULL;
char optkey[512] = {0,};
int ret = -1;
- exists = glusterd_check_option_exists (key, NULL);
- if (0 == exists)
- return;
-
ctx = data;
- snprintf (optkey, sizeof (optkey), "volume%d.key%d", ctx->count,
- ctx->opt_count);
+ snprintf (optkey, sizeof (optkey), "volume%d.%s%d", ctx->count,
+ ctx->key_name, ctx->opt_count);
ret = dict_set_str (ctx->dict, optkey, key);
if (ret)
- gf_log ("", GF_LOG_ERROR, "option add for key%d %s",
- ctx->count, key);
- snprintf (optkey, sizeof (optkey), "volume%d.value%d", ctx->count,
- ctx->opt_count);
+ gf_log ("", GF_LOG_ERROR, "option add for %s%d %s",
+ ctx->key_name, ctx->count, key);
+ snprintf (optkey, sizeof (optkey), "volume%d.%s%d", ctx->count,
+ ctx->val_name, ctx->opt_count);
ret = dict_set_str (ctx->dict, optkey, value->data);
if (ret)
- gf_log ("", GF_LOG_ERROR, "option add for value%d %s",
- ctx->count, value->data);
+ gf_log ("", GF_LOG_ERROR, "option add for %s%d %s",
+ ctx->val_name, ctx->count, value->data);
ctx->opt_count++;
return;
@@ -1337,7 +1333,7 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo = NULL;
int32_t i = 1;
char *volume_id_str = NULL;
- glusterd_volopt_ctx_t ctx = {0};
+ glusterd_voldict_ctx_t ctx = {0};
GF_ASSERT (dict);
GF_ASSERT (volinfo);
@@ -1402,9 +1398,11 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
ctx.dict = dict;
ctx.count = count;
ctx.opt_count = 1;
+ ctx.key_name = "key";
+ ctx.val_name = "value";
GF_ASSERT (volinfo->dict);
- dict_foreach (volinfo->dict, _add_volume_option_to_dict, &ctx);
+ dict_foreach (volinfo->dict, _add_volinfo_dict_to_prdict, &ctx);
ctx.opt_count--;
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.opt-count", count);
@@ -1412,6 +1410,22 @@ glusterd_add_volume_to_dict (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
+ ctx.dict = dict;
+ ctx.count = count;
+ ctx.opt_count = 1;
+ ctx.key_name = "slave-num";
+ ctx.val_name = "slave-val";
+ GF_ASSERT (volinfo->gsync_slaves);
+
+ dict_foreach (volinfo->gsync_slaves, _add_volinfo_dict_to_prdict, &ctx);
+ ctx.opt_count--;
+
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.gsync-count", count);
+ ret = dict_set_int32 (dict, key, ctx.opt_count);
+ if (ret)
+ goto out;
+
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "volume%d.brick%d.hostname",
@@ -1545,45 +1559,36 @@ out:
return ret;
}
-int32_t
-glusterd_import_friend_volume_opts (dict_t *vols, int count,
- glusterd_volinfo_t *volinfo)
+static int32_t
+import_prdict_volinfo_dict (dict_t *vols, dict_t *dst_dict, char *key_prefix,
+ char *value_prefix, int opt_count, int count)
{
char key[512] = {0,};
int32_t ret = -1;
int i = 1;
- int opt_count = 0;
char *opt_key = NULL;
char *opt_val = NULL;
char *dup_opt_val = NULL;
char msg[2048] = {0};
- memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "volume%d.opt-count", count);
- ret = dict_get_int32 (vols, key, &opt_count);
- if (ret) {
- snprintf (msg, sizeof (msg), "Volume option count not "
- "specified for %s", volinfo->volname);
- goto out;
- }
while (i <= opt_count) {
memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "volume%d.key%d",
- count, i);
+ snprintf (key, sizeof (key), "volume%d.%s%d",
+ count, key_prefix, i);
ret = dict_get_str (vols, key, &opt_key);
if (ret) {
- snprintf (msg, sizeof (msg), "Volume option key not "
- "specified for %s", volinfo->volname);
+ snprintf (msg, sizeof (msg), "Volume dict key not "
+ "specified");
goto out;
}
memset (key, 0, sizeof (key));
- snprintf (key, sizeof (key), "volume%d.value%d",
- count, i);
+ snprintf (key, sizeof (key), "volume%d.%s%d",
+ count, value_prefix, i);
ret = dict_get_str (vols, key, &opt_val);
if (ret) {
- snprintf (msg, sizeof (msg), "Volume option value not "
- "specified for %s", volinfo->volname);
+ snprintf (msg, sizeof (msg), "Volume dict value not "
+ "specified");
goto out;
}
dup_opt_val = gf_strdup (opt_val);
@@ -1591,15 +1596,67 @@ glusterd_import_friend_volume_opts (dict_t *vols, int count,
ret = -1;
goto out;
}
- ret = dict_set_dynstr (volinfo->dict, opt_key, dup_opt_val);
+ ret = dict_set_dynstr (dst_dict, opt_key, dup_opt_val);
if (ret) {
snprintf (msg, sizeof (msg), "Volume set %s %s "
- "unsuccessful for %s", opt_key, dup_opt_val,
- volinfo->volname);
+ "unsuccessful", opt_key, dup_opt_val);
goto out;
}
i++;
}
+
+out:
+ if (msg[0])
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ return ret;
+
+}
+
+int32_t
+glusterd_import_friend_volume_opts (dict_t *vols, int count,
+ glusterd_volinfo_t *volinfo)
+{
+ char key[512] = {0,};
+ int32_t ret = -1;
+ int opt_count = 0;
+ char msg[2048] = {0};
+
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.opt-count", count);
+ ret = dict_get_int32 (vols, key, &opt_count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Volume option count not "
+ "specified for %s", volinfo->volname);
+ goto out;
+ }
+
+ ret = import_prdict_volinfo_dict (vols, volinfo->dict, "key",
+ "value", opt_count, count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Unable to import options dict "
+ "specified for %s", volinfo->volname);
+ goto out;
+ }
+
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "volume%d.gsync-count", count);
+ ret = dict_get_int32 (vols, key, &opt_count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Gsync count not "
+ "specified for %s", volinfo->volname);
+ goto out;
+ }
+
+ ret = import_prdict_volinfo_dict (vols, volinfo->gsync_slaves,
+ "slave-num", "slave-val", opt_count,
+ count);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Unable to import gsync sessions "
+ "specified for %s", volinfo->volname);
+ goto out;
+ }
+
out:
if (msg[0])
gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 26f3f2a73d6..7cf06f7ae1f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -43,11 +43,13 @@ struct glusterd_lock_ {
time_t timestamp;
};
-typedef struct glusterd_volopt_ctx_ {
+typedef struct glusterd_voldict_ctx_ {
dict_t *dict;
int count;
int opt_count;
-} glusterd_volopt_ctx_t;
+ char *key_name;
+ char *val_name;
+} glusterd_voldict_ctx_t;
typedef int (*glusterd_condition_func) (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,