summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c143
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c169
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c54
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h7
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c5
5 files changed, 376 insertions, 2 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 39c1d59240e..031e07481a9 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -47,6 +47,7 @@
#include "cli1.h"
#include "rpc-clnt.h"
#include "glusterd1-xdr.h"
+#include "glusterd-volgen.h"
#include <sys/resource.h>
#include <inttypes.h>
@@ -1322,6 +1323,50 @@ out:
return ret;
}
+
+
+
+int
+glusterd_handle_reset_volume (rpcsvc_request_t *req)
+{
+ int32_t ret = -1;
+ gf1_cli_reset_vol_req cli_req = {0,};
+ dict_t *dict = NULL;
+
+ GF_ASSERT (req);
+
+ if (!gf_xdr_to_cli_set_vol_req (req->msg[0], &cli_req)) {
+ //failed to decode msg;
+ req->rpc_err = GARBAGE_ARGS;
+ goto out;
+ }
+
+ if (cli_req.dict.dict_len) {
+ /* Unserialize the dictionary */
+ dict = dict_new ();
+
+ ret = dict_unserialize (cli_req.dict.dict_val,
+ cli_req.dict.dict_len,
+ &dict);
+ if (ret < 0) {
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "failed to "
+ "unserialize req-buffer to dictionary");
+ goto out;
+ } else {
+ dict->extra_stdfree = cli_req.dict.dict_val;
+ }
+ }
+
+ ret = glusterd_reset_volume (req, dict);
+
+out:
+ if (cli_req.volname)
+ free (cli_req.volname);//malloced by xdr
+
+ return ret;
+}
+
int
glusterd_handle_set_volume (rpcsvc_request_t *req)
{
@@ -2756,13 +2801,106 @@ glusterd_replace_brick (rpcsvc_request_t *req, dict_t *dict)
return ret;
}
+static void
+_print (dict_t *unused, char *key, data_t *value, void *newdict)
+{
+ gf_log ("", GF_LOG_DEBUG, "key=%s, value=%s", key, value->data);
+}
+
+int
+glusterd_set_volume_history (rpcsvc_request_t *req,dict_t *dict)
+{
+// dict_t *reply_dict = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ gf1_cli_set_vol_rsp rsp = {0, };
+ int ret = -1;
+ char *volname = NULL;
+
+ gf_log ("", GF_LOG_DEBUG, "'volume set history' command");
+
+ ret = dict_get_str (dict, "volname", &volname);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
+ }
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");
+ goto out;
+ }
+
+
+
+ dict_foreach (volinfo->dict, _print, volinfo->dict);
+
+ ret = dict_allocate_and_serialize (volinfo->dict, &rsp.dict.dict_val,
+ (size_t *)&rsp.dict.dict_len);
+
+
+ if (ret) {
+ gf_log ("", GF_LOG_DEBUG, "FAILED: allocatea n serialize dict");
+ goto out;
+ }
+
+ if (!ret)
+ rsp.op_ret = 1;
+ else
+ rsp.op_ret = ret;
+ if (!rsp.volname)
+ rsp.volname = "";
+
+ ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
+ gf_xdr_serialize_cli_set_vol_rsp);
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+int32_t
+glusterd_reset_volume (rpcsvc_request_t *req, dict_t *dict)
+{
+ int ret = -1;
+
+
+ glusterd_op_set_op (GD_OP_RESET_VOLUME);
+
+ glusterd_op_set_ctx (GD_OP_RESET_VOLUME, dict);
+
+ glusterd_op_set_ctx_free (GD_OP_RESET_VOLUME, _gf_true);
+
+ glusterd_op_set_cli_op (GD_MGMT_CLI_RESET_VOLUME);
+
+ glusterd_op_set_req (req);
+
+ ret = glusterd_op_txn_begin ();
+
+ return ret;
+}
+
+
+
int32_t
glusterd_set_volume (rpcsvc_request_t *req, dict_t *dict)
{
- int32_t ret = -1;
+ int32_t ret = -1;
+ int32_t dict_count = 0;
GF_ASSERT (req);
GF_ASSERT (dict);
+
+ ret = dict_get_int32 (dict, "count", &dict_count);
+ if (ret)
+ goto out;
+
+ if (dict_count == 1) {
+ if (dict_get (dict, "history")) {
+ ret = glusterd_set_volume_history(req, dict);
+ goto out;
+ }
+ }
glusterd_op_set_op (GD_OP_SET_VOLUME);
@@ -2776,6 +2914,8 @@ glusterd_set_volume (rpcsvc_request_t *req, dict_t *dict)
ret = glusterd_op_txn_begin ();
+out:
+
return ret;
}
@@ -2813,6 +2953,7 @@ glusterd_log_filename (rpcsvc_request_t *req, dict_t *dict)
ret = glusterd_op_txn_begin ();
+
return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 317eab700ba..513be5b4d29 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -144,6 +144,7 @@ glusterd_op_get_len (glusterd_op_t op)
break;
case GD_OP_SET_VOLUME:
+ case GD_OP_RESET_VOLUME:
case GD_OP_REPLACE_BRICK:
case GD_OP_ADD_BRICK:
{
@@ -242,6 +243,7 @@ glusterd_op_build_payload (glusterd_op_t op, gd1_mgmt_stage_op_req **req)
case GD_OP_ADD_BRICK:
case GD_OP_REPLACE_BRICK:
case GD_OP_SET_VOLUME:
+ case GD_OP_RESET_VOLUME:
case GD_OP_REMOVE_BRICK:
case GD_OP_LOG_FILENAME:
case GD_OP_LOG_ROTATE:
@@ -1118,6 +1120,54 @@ out:
return ret;
}
+static int
+glusterd_op_stage_reset_volume (gd1_mgmt_stage_op_req *req)
+{
+ int ret = 0;
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ gf_boolean_t exists = _gf_false;
+
+ GF_ASSERT (req);
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
+ }
+
+ exists = glusterd_check_volume_exists (volname);
+
+ if (!exists) {
+ gf_log ("", GF_LOG_ERROR, "Volume with name: %s "
+ "does not exist",
+ volname);
+ ret = -1;
+ goto out;
+ }
+
+
+out:
+ if (dict)
+ dict_unref (dict);
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+
+ return ret;
+}
+
+
gf_boolean_t
glusterd_check_option_exists(char *optstring)
@@ -2746,6 +2796,102 @@ out:
return ret;
}
+void
+_delete_reconfig_opt (dict_t *this, char *key, data_t *value, void *data)
+{
+
+ gf_boolean_t exists = _gf_false;
+
+ exists = glusterd_check_option_exists(key);
+
+ if (exists) {
+ gf_log ("", GF_LOG_DEBUG, "deleting dict with key=%s,value=%s",
+ key, value->data);
+ dict_del (this, key);
+ }
+
+}
+
+int
+glusterd_options_reset (glusterd_volinfo_t *volinfo)
+{
+ int ret = 0;
+
+ gf_log ("", GF_LOG_DEBUG, "Received volume set reset command");
+
+ GF_ASSERT (volinfo->dict);
+
+ dict_foreach (volinfo->dict, _delete_reconfig_opt, volinfo->dict);
+
+ ret = glusterd_create_volfiles (volinfo);
+
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to create volfile for"
+ " 'volume set'");
+ ret = -1;
+ goto out;
+ }
+
+ ret = glusterd_store_update_volume (volinfo);
+ if (ret)
+ goto out;
+
+ ret = glusterd_volume_compute_cksum (volinfo);
+ if (ret)
+ goto out;
+
+ if (GLUSTERD_STATUS_STARTED == volinfo->status)
+ ret = glusterd_check_generate_start_nfs (volinfo);
+ if (ret)
+ goto out;
+
+ ret = 0;
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+
+static int
+glusterd_op_reset_volume (gd1_mgmt_stage_op_req *req)
+{
+ glusterd_volinfo_t *volinfo = NULL;
+ int ret = -1;
+ char *volname = NULL;
+ dict_t *dict = NULL;
+
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+
+
+ ret = dict_unserialize (req->buf.buf_val, req->buf.buf_len, &dict);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to unserialize dict");
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name " );
+ goto out;
+ }
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");
+ goto out;
+ }
+
+ ret = glusterd_options_reset (volinfo);
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "'volume reset' returning %d", ret);
+ return ret;
+
+}
+
static int
glusterd_op_set_volume (gd1_mgmt_stage_op_req *req)
{
@@ -4033,6 +4179,22 @@ glusterd_op_send_cli_response (int32_t op, int32_t op_ret,
sfunc = gf_xdr_serialize_cli_set_vol_rsp;
break;
}
+
+ case GD_MGMT_CLI_RESET_VOLUME:
+ {
+ gf_log ("", GF_LOG_DEBUG, "Return value to CLI");
+ gf1_cli_reset_vol_rsp rsp = {0,};
+ rsp.op_ret = op_ret;
+ rsp.op_errno = 1;
+ rsp.volname = "";
+ if (op_errstr)
+ rsp.op_errstr = op_errstr;
+ else
+ rsp.op_errstr = "Error while resetting options";
+ cli_rsp = &rsp;
+ sfunc = gf_xdr_serialize_cli_reset_vol_rsp;
+ break;
+ }
case GD_MGMT_CLI_LOG_FILENAME:
{
@@ -4315,6 +4477,9 @@ glusterd_op_stage_validate (gd1_mgmt_stage_op_req *req, char **op_errstr)
case GD_OP_SET_VOLUME:
ret = glusterd_op_stage_set_volume (req);
break;
+
+ case GD_OP_RESET_VOLUME:
+ ret = glusterd_op_stage_reset_volume (req);
case GD_OP_REMOVE_BRICK:
ret = glusterd_op_stage_remove_brick (req);
@@ -4380,6 +4545,10 @@ glusterd_op_commit_perform (gd1_mgmt_stage_op_req *req, char **op_errstr,
ret = glusterd_op_set_volume (req);
break;
+ case GD_OP_RESET_VOLUME:
+ ret = glusterd_op_reset_volume (req);
+ break;
+
case GD_OP_REMOVE_BRICK:
ret = glusterd_op_remove_brick (req);
break;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 27bed10d21f..7c18b69a927 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -20,6 +20,8 @@
#define _CONFIG_H
#include "config.h"
#endif
+
+#include "glusterd-op-sm.h"
#include <inttypes.h>
@@ -970,6 +972,7 @@ glusterd_store_retrieve_volume (char *volname)
char volpath[PATH_MAX] = {0,};
glusterd_conf_t *priv = NULL;
char path[PATH_MAX] = {0,};
+ gf_boolean_t exists = _gf_false;
ret = glusterd_volinfo_new (&volinfo);
@@ -1025,7 +1028,21 @@ glusterd_store_retrieve_volume (char *volname)
gf_log ("", GF_LOG_WARNING,
"failed to parse uuid");
} else {
- gf_log ("", GF_LOG_ERROR, "Unknown key: %s",
+ exists = glusterd_check_option_exists (key);
+ if (exists) {
+ ret = dict_set_str(volinfo->dict, key,
+ gf_strdup (value));
+ if (ret) {
+ gf_log ("",GF_LOG_ERROR, "Error in "
+ "dict_set_str");
+ goto out;
+ }
+ gf_log ("", GF_LOG_DEBUG, "Parsed as Volume-"
+ "set:key=%s,value:%s",
+ key, value);
+ }
+ else
+ gf_log ("", GF_LOG_DEBUG, "Unknown key: %s",
key);
}
@@ -1104,6 +1121,39 @@ out:
return ret;
}
+void _setopts(dict_t *this, char *key, data_t *value, void *data)
+{
+ int ret = 0;
+ glusterd_store_handle_t *shandle = NULL;
+ gf_boolean_t exists = _gf_false;
+
+
+ shandle = (glusterd_store_handle_t *) data;
+
+ GF_ASSERT (shandle);
+ if (!key)
+ return;
+ if (!value || !value->data)
+ return;
+
+ exists = glusterd_check_option_exists (key);
+ if (exists)
+ gf_log ("", GF_LOG_DEBUG, "Storing in volinfo:key= %s, val=%s",
+ key, value->data);
+ else {
+ gf_log ("", GF_LOG_DEBUG, "Discarding:key= %s, val=%s",
+ key, value->data);
+ return;
+ }
+
+ ret = glusterd_store_save_value (shandle, key, value->data);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to write into store"
+ " handle for path: %s", shandle->path);
+ return;
+ }
+}
+
int32_t
glusterd_store_update_volume (glusterd_volinfo_t *volinfo)
{
@@ -1171,6 +1221,8 @@ glusterd_store_update_volume (glusterd_volinfo_t *volinfo)
goto out;
brick_count++;
}
+
+ dict_foreach (volinfo->dict, _setopts, volinfo->shandle);
ret = 0;
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index b11ce09fb65..e1cbc3583d1 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -64,6 +64,7 @@ typedef enum glusterd_op_ {
GD_OP_REMOVE_BRICK,
GD_OP_REPLACE_BRICK,
GD_OP_SET_VOLUME,
+ GD_OP_RESET_VOLUME,
GD_OP_SYNC_VOLUME,
GD_OP_LOG_FILENAME,
GD_OP_LOG_LOCATE,
@@ -416,10 +417,16 @@ glusterd_remove_brick (rpcsvc_request_t *req, dict_t *dict);
int32_t
glusterd_set_volume (rpcsvc_request_t *req, dict_t *dict);
+int32_t
+glusterd_reset_volume (rpcsvc_request_t *req, dict_t *dict);
+
int
glusterd_handle_set_volume (rpcsvc_request_t *req);
int
+glusterd_handle_reset_volume (rpcsvc_request_t *req);
+
+int
glusterd_xfer_cli_deprobe_resp (rpcsvc_request_t *req, int32_t op_ret,
int32_t op_errno, char *hostname);
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index a92ccf4c55c..c21b43bcfb9 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -1425,6 +1425,10 @@ glusterd_handle_rpc_msg (rpcsvc_request_t *req)
ret = glusterd_handle_sync_volume (req);
break;
+ case GD_MGMT_CLI_RESET_VOLUME:
+ ret = glusterd_handle_reset_volume (req);
+ break;
+
default:
gf_log("", GF_LOG_ERROR, "Recieved Invalid procnum:%d",
req->procnum);
@@ -1480,6 +1484,7 @@ rpcsvc_actor_t glusterd1_mgmt_actors[] = {
[GD_MGMT_CLI_LOG_ROTATE] = { "LOG FILENAME", GD_MGMT_CLI_LOG_ROTATE, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_SET_VOLUME] = { "SET_VOLUME", GD_MGMT_CLI_SET_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
[GD_MGMT_CLI_SYNC_VOLUME] = { "SYNC_VOLUME", GD_MGMT_CLI_SYNC_VOLUME, glusterd_handle_rpc_msg, NULL, NULL},
+ [GD_MGMT_CLI_RESET_VOLUME] = { "RESET_VOLUME", GD_MGMT_CLI_RESET_VOLUME, glusterd_handle_rpc_msg, NULL, NULL}
};
/*rpcsvc_actor_t glusterd1_mgmt_actors[] = {