diff options
Diffstat (limited to 'xlators/cluster/nsr-server/src/nsr.c')
-rw-r--r-- | xlators/cluster/nsr-server/src/nsr.c | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/xlators/cluster/nsr-server/src/nsr.c b/xlators/cluster/nsr-server/src/nsr.c index 214c54f18..eda9e555a 100644 --- a/xlators/cluster/nsr-server/src/nsr.c +++ b/xlators/cluster/nsr-server/src/nsr.c @@ -500,6 +500,25 @@ out: extern void *nsr_leader_thread (void *); +void +nsr_deallocate_priv (nsr_private_t *priv) +{ + if (!priv) { + return; + } + + if (priv->leader_key) { + GF_FREE(priv->leader_key); + } + + if (priv->term_key) { + GF_FREE(priv->term_key); + } + + GF_FREE(priv); +} + + int32_t nsr_init (xlator_t *this) { @@ -571,12 +590,22 @@ nsr_init (xlator_t *this) gf_log (this->name, GF_LOG_ERROR, "etcd servers not generated. ???"); goto err; } - priv->vol_uuid = "temporary"; + + GF_OPTION_INIT ("subvol-uuid", priv->subvol_uuid, str, err); + gf_log (this->name, GF_LOG_INFO, "subvol_uuid = %s", priv->subvol_uuid); + if (gf_asprintf(&priv->leader_key,"%s:leader",priv->subvol_uuid) <= 0) { + gf_log (this->name, GF_LOG_ERROR, + "could not generate leader key"); + goto err; + } + if (gf_asprintf(&priv->term_key,"%s:term",priv->subvol_uuid) <= 0) { + gf_log (this->name, GF_LOG_ERROR, + "could not generate term key"); + goto err; + } uuid_generate(tmp_uuid); priv->brick_uuid = strdup(uuid_utoa(tmp_uuid)); - priv->term_uuid = "nsr-term"; - gf_log (this->name, GF_LOG_INFO, - "brick_uuid = %s\n", priv->brick_uuid); + gf_log (this->name, GF_LOG_INFO, "brick_uuid = %s\n", priv->brick_uuid); GF_OPTION_INIT ("my-name", my_name, str, err); if (!my_name) { @@ -707,7 +736,10 @@ nsr_init (xlator_t *this) sleep(1); } - (void)pthread_create(&kid,NULL,nsr_leader_thread,this); + if (pthread_create(&kid,NULL,nsr_leader_thread,this) != 0) { + gf_log (this->name, GF_LOG_ERROR, + "failed to start leader thread"); + } while (priv->leader_inited == 0) { sleep(1); } @@ -726,9 +758,7 @@ nsr_init (xlator_t *this) return 0; err: - if (priv) { - GF_FREE(priv); - } + nsr_deallocate_priv(priv); return -1; } @@ -736,6 +766,7 @@ err: void nsr_fini (xlator_t *this) { + nsr_deallocate_priv(this->private); } class_methods_t class_methods = { @@ -765,5 +796,9 @@ struct volume_options options[] = { .type = GF_OPTION_TYPE_STR, .description = "list of comma seperated etc servers" }, + { .key = {"subvol-uuid"}, + .type = GF_OPTION_TYPE_STR, + .description = "UUID for this NSR (sub)volume" + }, { .key = {NULL} }, }; |