From 3ec6ae1c1fb103df077f44b18604e768fea00ddc Mon Sep 17 00:00:00 2001 From: Susant Palai Date: Thu, 3 May 2018 17:41:16 +0530 Subject: features/cloudsync: Make plugins configurable This patch brings the configuration option for plugins. For new plugins, an entry has to be created in to cs_plugin structure e.g. struct cs_plugin plugins[] = { { .name = "amazons3", .library = "libamazons3.so", .description = "amazon s3 store." }, {.name = NULL}, }; Library field describes the name of the shared library for the plugin. To configure plugin type "feature.cloudsync-storetype" option need to be set to the remote-store type. e.g. gluster volume set VOLNAME cloudsync-storetype amazons3. This should be same as the ".name" field in cs_plugin structure. cs_init will pick this up in run time to load the plugin. Change-Id: I2cec10b206f71ac4e71d472631a3a5badf278b59 fixes: bz#1576842 Signed-off-by: Susant Palai --- xlators/features/cloudsync/src/cloudsync.c | 54 ++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'xlators/features/cloudsync/src/cloudsync.c') diff --git a/xlators/features/cloudsync/src/cloudsync.c b/xlators/features/cloudsync/src/cloudsync.c index 48e27c372b6..e14fc544957 100644 --- a/xlators/features/cloudsync/src/cloudsync.c +++ b/xlators/features/cloudsync/src/cloudsync.c @@ -34,15 +34,27 @@ cs_cleanup_private (cs_private_t *priv) return; } +struct cs_plugin plugins[] = { + { + .name = "amazons3", + .library = "libamazons3.so", + .description = "amazon s3 store." + }, + + {.name = NULL}, +}; + int cs_init (xlator_t *this) { cs_private_t *priv = NULL; gf_boolean_t per_vol = _gf_false; int ret = 0; - char *libpath = ("libaws.so"); + char *libpath = NULL; store_methods_t *store_methods = NULL; void *handle = NULL; + char *temp_str = NULL; + int index = 0; priv = GF_CALLOC (1, sizeof (*priv), gf_cs_mt_cs_private_t); if (!priv) { @@ -66,7 +78,25 @@ cs_init (xlator_t *this) per_vol = _gf_true; if (per_vol) { - /*TODO:Need to make it configurable. This is a temp workaround*/ + if (dict_get_str (this->options, "cloudsync-storetype", + &temp_str) == 0) { + for (index = 0; plugins[index].name; index++) { + if (!strcmp (temp_str, plugins[index].name)) { + libpath = plugins[index].library; + break; + } + } + } else { + ret = 0; + } + + if (!libpath) { + gf_msg (this->name, GF_LOG_WARNING, 0, 0, + "no plugin enabled"); + ret = 0; + goto out; + } + handle = dlopen (libpath, RTLD_NOW); if (!handle) { gf_msg (this->name, GF_LOG_ERROR, 0, 0, "could not load" @@ -848,15 +878,23 @@ cs_download_task (void *arg) priv = this->private; - local = frame->local; - retval = GF_CALLOC (1, sizeof(int), gf_common_mt_int); if (!retval) { - gf_log (this->name, GF_LOG_ERROR, "insufficient memory"); + gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory"); + ret = -1; + goto out; + } + + if (!priv->stores) { + gf_msg (this->name, GF_LOG_ERROR, 0, 0, "No remote store " + "plugins found"); ret = -1; goto out; } + local = frame->local; + + if (local->fd) fd = fd_anonymous (local->fd->inode); else @@ -1656,7 +1694,11 @@ struct xlator_dumpops cs_dumpops = { }; struct volume_options cs_options[] = { - { .key = {NULL} }, + { .key = {"cloudsync-storetype"}, + .type = GF_OPTION_TYPE_STR, + .description = "Defines which remote store is enabled" + }, + { .key = {NULL} }, }; xlator_api_t xlator_api = { -- cgit