summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-ganesha.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-ganesha.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-ganesha.c159
1 files changed, 157 insertions, 2 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
index 267e4b995cd..d8111afa423 100644
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
@@ -24,7 +24,161 @@
#define MAXBUF 1024
#define DELIM "=\""
-/* Following 2 functions parses GANESHA_HA_CONF
+int
+glusterd_check_ganesha_cmd (char *key, char *value, char **errstr, dict_t *dict)
+{
+ int ret = 0;
+ gf_boolean_t b = _gf_false;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+ GF_ASSERT (key);
+ GF_ASSERT (value);
+
+ if ((strcmp (key, "ganesha.enable") == 0) ||
+ (strcmp (key, "features.ganesha") == 0)) {
+ ret = gf_string2boolean (value, &b);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to parse bool"
+ "string");
+ goto out;
+ }
+ if ((strcmp (value, "on")) && (strcmp (value, "off"))) {
+ gf_log (this->name, GF_LOG_ERROR, "Invalid value"
+ "for volume set command. Use on/off only");
+ ret = -1;
+ goto out;
+ }
+ ret = glusterd_handle_ganesha_op (dict, errstr, key, value);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Handling NFS-Ganesha op"
+ "failed.");
+ }
+ }
+out:
+ return ret;
+}
+
+int
+glusterd_op_stage_set_ganesha (dict_t *dict, char **op_errstr)
+{
+ int ret = -1;
+ char *volname = NULL;
+ int exists = 0;
+ char *key = NULL;
+ char *value = NULL;
+ char str[100] = {0, } ;
+ int dict_count = 0;
+ int flags = 0;
+ char errstr[2048] = {0, } ;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_conf_t *priv = NULL;
+ xlator_t *this = NULL;
+
+ GF_ASSERT (dict);
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ ret = dict_get_str (dict, "key", &key);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "invalid key");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "value", &value);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "invalid key,value pair in 'global vol set'");
+ goto out;
+ }
+out:
+
+ if (ret) {
+ if (!(*op_errstr)) {
+ *op_errstr = gf_strdup ("Error, Validation Failed");
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Error, Cannot Validate option :%s %s",
+ key, value);
+ } else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Error, Cannot Validate option");
+ }
+ }
+ return ret;
+}
+
+int
+glusterd_op_set_ganesha (dict_t *dict, char **errstr)
+{
+ int ret = 0;
+ int flags = 0;
+ glusterd_volinfo_t *volinfo = NULL;
+ char *volname = NULL;
+ xlator_t *this = NULL;
+ glusterd_conf_t *priv = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ char str[50] = {0, };
+ int32_t dict_count = 0;
+ dict_t *vol_opts = NULL;
+ int count = 0;
+
+ this = THIS;
+ GF_ASSERT (this);
+ GF_ASSERT (dict);
+
+ priv = this->private;
+ GF_ASSERT (priv);
+
+
+ ret = dict_get_str (dict, "key", &key);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Couldn't get key in global option set");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "value", &value);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Couldn't get value in global option set");
+ goto out;
+ }
+
+ ret = glusterd_handle_ganesha_op (dict, errstr, key, value);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Initial NFS-Ganesha set up failed");
+ ret = -1;
+ goto out;
+ }
+ ret = dict_set_str(priv->opts, "features.ganesha", value);
+ if (ret) {
+ gf_log (this->name, GF_LOG_WARNING, "Failed to set"
+ " features.ganesha in dict.");
+ goto out;
+ }
+
+ /* To do : Lock the global options file before writing */
+ /* into this file. Bug ID : 1200254 */
+
+ ret = glusterd_store_options (this, priv->opts);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to store options");
+ goto out;
+ }
+
+out:
+ gf_log (this->name, GF_LOG_DEBUG, "returning %d", ret);
+ return ret;
+}
+
+/* Following 2 functions parse GANESHA_HA_CONF
* The sample file looks like below,
* HA_NAME="ganesha-ha-360"
* HA_VOL_NAME="ha-state"
@@ -181,6 +335,7 @@ ganesha_manage_export (dict_t *dict, char *value, char **op_errstr)
FMTSTR_CHECK_VOL_EXISTS, volname);
goto out;
}
+ /* Todo : check if global option is enabled, proceed only then */
/* Create the export file only when ganesha.enable "on" is executed */
if (strcmp (value, "on") == 0) {
@@ -253,7 +408,7 @@ stop_ganesha (char **op_errstr)
if (check_host_list ()) {
runinit (&runner);
- runner_add_args (&runner, "service nfs-ganesha", "stop", NULL);
+ runner_add_args (&runner, "service", " nfs-ganesha", "stop", NULL);
ret = runner_run (&runner);
}
out: