diff options
-rw-r--r-- | cli/src/cli-cmd-parser.c | 56 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 45 | ||||
-rw-r--r-- | cli/src/cli.h | 3 | ||||
-rw-r--r-- | cli/src/cli3_1-cops.c | 115 | ||||
-rw-r--r-- | rpc/rpc-lib/src/protocol-common.h | 2 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.c | 32 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.h | 27 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.c | 30 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.h | 12 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.x | 15 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 143 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 169 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 54 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 7 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd3_1-mops.c | 5 | ||||
-rw-r--r-- | xlators/protocol/server/src/server.c | 20 |
16 files changed, 728 insertions, 7 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 875ead0642e..a6f9cf915a1 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -288,6 +288,49 @@ out: return ret; } +int32_t +cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **options) +{ + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + + GF_ASSERT (words); + GF_ASSERT (options); + + GF_ASSERT ((strcmp (words[0], "volume")) == 0); + GF_ASSERT ((strcmp (words[1], "reset")) == 0); + + dict = dict_new (); + + if (!dict) + goto out; + + if (wordcount < 3) + goto out; + + volname = (char *)words[2]; + + if (!volname) { + ret = -1; + goto out; + } + + ret = dict_set_str (dict, "volname", volname); + + if (ret) + goto out; + + *options = dict; + +out: + if (ret) { + if (dict) + dict_destroy (dict); + } + + return ret; +} int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) @@ -329,6 +372,19 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) key = (char *) words[i]; value = (char *) words[i+1]; + if ( key && !value ) { + if ( !strcmp (key, "history")) { + ret = dict_set_str (dict, key, "history"); + if (ret) + goto out; + ret = dict_set_int32 (dict, "count", 1); + if (ret) + goto out; + *options = dict; + goto out; + } + } + if ( !key || !value) { ret = -1; cli_out ("Usage: volume set <VOLNAME> <KEY> <VALUE>"); diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 8d846d8732c..3c433c523e0 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -72,6 +72,12 @@ cli_cmd_volume_info_usage () } void +cli_cmd_volume_reset_usage () +{ + cli_out ("Usage: volume reset <VOLNAME> "); +} + +void cli_cmd_volume_set_usage () { cli_out ("Usage: volume set <VOLNAME> <KEY> <VALUE>"); @@ -481,6 +487,41 @@ out: return 0; } +int +cli_cmd_volume_reset_cbk (struct cli_state *state, struct cli_cmd_word *word, + const char **words, int wordcount) +{ + + int ret = -1; + rpc_clnt_procedure_t *proc = NULL; + call_frame_t *frame = NULL; + dict_t *options = NULL; + + proc = &cli_rpc_prog->proctable[GF1_CLI_RESET_VOLUME]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_volume_reset_parse (words, wordcount, &options); + + if (ret) { + cli_cmd_volume_reset_usage (); + goto out; + } + + if (proc->fn) { + ret = proc->fn (frame, THIS, options); + } + +out: + if (options) + dict_unref (options); + + return ret; + +} + int cli_cmd_volume_set_cbk (struct cli_state *state, struct cli_cmd_word *word, @@ -886,6 +927,10 @@ struct cli_cmd volume_cmds[] = { { "volume sync <HOSTNAME> [all|<VOLNAME>]", cli_cmd_sync_volume_cbk, "sync the volume information from a peer"}, + + { "volume reset <VOLNAME> ", + cli_cmd_volume_reset_cbk, + "reset all the reconfigured options"}, { NULL, NULL, NULL } }; diff --git a/cli/src/cli.h b/cli/src/cli.h index 216b743fdd1..f3ea9282873 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -172,6 +172,9 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options); int32_t +cli_cmd_volume_reset_parse (const char **words, int wordcount, dict_t **opt); + +int32_t cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options); diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index 8a775e974a6..0eb1ef77a33 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -746,11 +746,52 @@ out: } int +gf_cli3_1_reset_volume_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_reset_vol_rsp rsp = {0,}; + int ret = 0; + + if (-1 == req->rpc_status) { + goto out; + } + + ret = gf_xdr_to_cli_reset_vol_rsp (*iov, &rsp); + if (ret < 0) { + gf_log ("", GF_LOG_ERROR, "error"); + goto out; + } + + gf_log ("cli", GF_LOG_NORMAL, "Received resp to reset"); + cli_out ("reset volume %s", (rsp.op_ret) ? "unsuccessful": + "successful"); + + if (rsp.op_ret && rsp.op_errstr) + cli_out ("%s", rsp.op_errstr); + + ret = rsp.op_ret; + +out: + cli_cmd_broadcast_response (ret); + return ret; +} + +void +_cli_out_options (dict_t *this, char *key, data_t *value, void *count) +{ + + (*((int *) count))++; + cli_out ("%s - %s", key, value->data); +} + +int gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { gf1_cli_set_vol_rsp rsp = {0,}; int ret = 0; + dict_t *dict = NULL; + int dict_count = 0; if (-1 == req->rpc_status) { goto out; @@ -761,6 +802,38 @@ gf_cli3_1_set_volume_cbk (struct rpc_req *req, struct iovec *iov, gf_log ("", GF_LOG_ERROR, "error"); goto out; } + + if (rsp.op_ret == 1) { // if the command was volume set <vol> history + + if (!rsp.dict.dict_len) { + cli_out ("No volumes present"); + ret = 0; + goto out; + } + + dict = dict_new (); + + if (!dict) { + ret = -1; + goto out; + } + + ret = dict_unserialize (rsp.dict.dict_val, + rsp.dict.dict_len, + &dict); + + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Unable to allocate memory"); + goto out; + } + cli_out ("Options:"); + dict_foreach (dict, _cli_out_options, &dict_count); + if (!dict_count) + cli_out ("No Options Reconfigured!!"); + goto out; + } + gf_log ("cli", GF_LOG_NORMAL, "Received resp to set"); @@ -1572,6 +1645,47 @@ out: } int32_t +gf_cli3_1_reset_volume (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_reset_vol_req req = {0,}; + int ret = 0; + dict_t *dict = NULL; + + if (!frame || !this || !data) { + ret = -1; + goto out; + } + + dict = data; + + ret = dict_get_str (dict, "volname", &req.volname); + + if (ret) + goto out; + + ret = dict_allocate_and_serialize (dict, + &req.dict.dict_val, + (size_t *)&req.dict.dict_len); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, + "failed to get serialized length of dict"); + goto out; + } + + + ret = cli_cmd_submit (&req, frame, cli_rpc_prog, + GD_MGMT_CLI_RESET_VOLUME, NULL, + gf_xdr_from_cli_reset_vol_req, + this, gf_cli3_1_reset_volume_cbk); + +out: + gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret); + + return ret; +} + +int32_t gf_cli3_1_set_volume (call_frame_t *frame, xlator_t *this, void *data) { @@ -2022,6 +2136,7 @@ struct rpc_clnt_procedure gluster3_1_cli_actors[GF1_CLI_MAXVALUE] = { [GF1_CLI_GETSPEC] = {"GETSPEC", gf_cli3_1_getspec}, [GF1_CLI_PMAP_PORTBYBRICK] = {"PMAP PORTBYBRICK", gf_cli3_1_pmap_b2p}, [GF1_CLI_SYNC_VOLUME] = {"SYNC_VOLUME", gf_cli3_1_sync_volume}, + [GF1_CLI_RESET_VOLUME] = {"RESET_VOLUME", gf_cli3_1_reset_volume} }; struct rpc_clnt_program cli3_1_prog = { diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index a84c1eb7831..40283bf427b 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -103,6 +103,7 @@ enum gf_mgmt_procnum_ { GD_MGMT_CLI_LOG_LOCATE, GD_MGMT_CLI_LOG_ROTATE, GD_MGMT_CLI_SYNC_VOLUME, + GD_MGMT_CLI_RESET_VOLUME, GD_MGMT_MAXVALUE, }; @@ -131,6 +132,7 @@ enum gf_cli_procnum { GF1_CLI_GETSPEC, GF1_CLI_PMAP_PORTBYBRICK, GF1_CLI_SYNC_VOLUME, + GF1_CLI_RESET_VOLUME, GF1_CLI_MAXVALUE, }; diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index cdf7be28d84..334cd26de14 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> This file is part of GlusterFS. GlusterFS is free software; you can redistribute it and/or modify @@ -93,7 +93,7 @@ xdr_gf1_cli_probe_req (XDR *xdrs, gf1_cli_probe_req *objp) bool_t xdr_gf1_cli_probe_rsp (XDR *xdrs, gf1_cli_probe_rsp *objp) { - register int32_t *buf; + register int32_t *buf; if (xdrs->x_op == XDR_ENCODE) { @@ -464,6 +464,32 @@ xdr_gf1_cli_replace_brick_rsp (XDR *xdrs, gf1_cli_replace_brick_rsp *objp) } bool_t +xdr_gf1_cli_reset_vol_req (XDR *xdrs, gf1_cli_reset_vol_req *objp) +{ + + if (!xdr_string (xdrs, &objp->volname, ~0)) + return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_gf1_cli_reset_vol_rsp (XDR *xdrs, gf1_cli_reset_vol_rsp *objp) +{ + + if (!xdr_int (xdrs, &objp->op_ret)) + return FALSE; + if (!xdr_int (xdrs, &objp->op_errno)) + return FALSE; + if (!xdr_string (xdrs, &objp->volname, ~0)) + return FALSE; + if (!xdr_string (xdrs, &objp->op_errstr, ~0)) + return FALSE; + return TRUE; +} + +bool_t xdr_gf1_cli_set_vol_req (XDR *xdrs, gf1_cli_set_vol_req *objp) { @@ -484,6 +510,8 @@ xdr_gf1_cli_set_vol_rsp (XDR *xdrs, gf1_cli_set_vol_rsp *objp) return FALSE; if (!xdr_string (xdrs, &objp->volname, ~0)) return FALSE; + if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0)) + return FALSE; return TRUE; } diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index 9988d54f9c5..7369ba86669 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com> This file is part of GlusterFS. GlusterFS is free software; you can redistribute it and/or modify @@ -282,6 +282,23 @@ struct gf1_cli_replace_brick_rsp { }; typedef struct gf1_cli_replace_brick_rsp gf1_cli_replace_brick_rsp; +struct gf1_cli_reset_vol_req { + char *volname; + struct { + u_int dict_len; + char *dict_val; + } dict; +}; +typedef struct gf1_cli_reset_vol_req gf1_cli_reset_vol_req; + +struct gf1_cli_reset_vol_rsp { + int op_ret; + int op_errno; + char *volname; + char *op_errstr; +}; +typedef struct gf1_cli_reset_vol_rsp gf1_cli_reset_vol_rsp; + struct gf1_cli_set_vol_req { char *volname; struct { @@ -295,6 +312,10 @@ struct gf1_cli_set_vol_rsp { int op_ret; int op_errno; char *volname; + struct { + u_int dict_len; + char *dict_val; + } dict; }; typedef struct gf1_cli_set_vol_rsp gf1_cli_set_vol_rsp; @@ -387,6 +408,8 @@ extern bool_t xdr_gf1_cli_remove_brick_req (XDR *, gf1_cli_remove_brick_req*); extern bool_t xdr_gf1_cli_remove_brick_rsp (XDR *, gf1_cli_remove_brick_rsp*); extern bool_t xdr_gf1_cli_replace_brick_req (XDR *, gf1_cli_replace_brick_req*); extern bool_t xdr_gf1_cli_replace_brick_rsp (XDR *, gf1_cli_replace_brick_rsp*); +extern bool_t xdr_gf1_cli_reset_vol_req (XDR *, gf1_cli_reset_vol_req*); +extern bool_t xdr_gf1_cli_reset_vol_rsp (XDR *, gf1_cli_reset_vol_rsp*); extern bool_t xdr_gf1_cli_set_vol_req (XDR *, gf1_cli_set_vol_req*); extern bool_t xdr_gf1_cli_set_vol_rsp (XDR *, gf1_cli_set_vol_rsp*); extern bool_t xdr_gf1_cli_log_filename_req (XDR *, gf1_cli_log_filename_req*); @@ -431,6 +454,8 @@ extern bool_t xdr_gf1_cli_remove_brick_req (); extern bool_t xdr_gf1_cli_remove_brick_rsp (); extern bool_t xdr_gf1_cli_replace_brick_req (); extern bool_t xdr_gf1_cli_replace_brick_rsp (); +extern bool_t xdr_gf1_cli_reset_vol_req (); +extern bool_t xdr_gf1_cli_reset_vol_rsp (); extern bool_t xdr_gf1_cli_set_vol_req (); extern bool_t xdr_gf1_cli_set_vol_rsp (); extern bool_t xdr_gf1_cli_log_filename_req (); diff --git a/rpc/xdr/src/cli1.c b/rpc/xdr/src/cli1.c index 22b74fd7df5..41a97f983ac 100644 --- a/rpc/xdr/src/cli1.c +++ b/rpc/xdr/src/cli1.c @@ -408,6 +408,36 @@ gf_xdr_from_cli_replace_brick_req (struct iovec outmsg, void *req) } ssize_t +gf_xdr_serialize_cli_reset_vol_rsp (struct iovec outmsg, void *rsp) +{ + return xdr_serialize_generic (outmsg, (void *)rsp, + (xdrproc_t)xdr_gf1_cli_reset_vol_rsp); + +} + +ssize_t +gf_xdr_to_cli_reset_vol_req (struct iovec inmsg, void *args) +{ + return xdr_to_generic (inmsg, (void *)args, + (xdrproc_t)xdr_gf1_cli_reset_vol_req); +} + +ssize_t +gf_xdr_to_cli_reset_vol_rsp (struct iovec inmsg, void *args) +{ + return xdr_to_generic (inmsg, (void *)args, + (xdrproc_t)xdr_gf1_cli_reset_vol_rsp); +} + + +ssize_t +gf_xdr_from_cli_reset_vol_req (struct iovec outmsg, void *req) +{ + return xdr_serialize_generic (outmsg, (void *)req, + (xdrproc_t)xdr_gf1_cli_reset_vol_req); +} + +ssize_t gf_xdr_serialize_cli_set_vol_rsp (struct iovec outmsg, void *rsp) { return xdr_serialize_generic (outmsg, (void *)rsp, diff --git a/rpc/xdr/src/cli1.h b/rpc/xdr/src/cli1.h index ee225400145..8d9e1674a97 100644 --- a/rpc/xdr/src/cli1.h +++ b/rpc/xdr/src/cli1.h @@ -174,6 +174,18 @@ ssize_t gf_xdr_from_cli_replace_brick_req (struct iovec outmsg, void *req); ssize_t +gf_xdr_serialize_cli_reset_vol_rsp (struct iovec outmsg, void *rsp); + +ssize_t +gf_xdr_to_cli_reset_vol_req (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_to_cli_reset_vol_rsp (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_from_cli_reset_vol_req (struct iovec outmsg, void *req); + +ssize_t gf_xdr_serialize_cli_set_vol_rsp (struct iovec outmsg, void *rsp); ssize_t diff --git a/rpc/xdr/src/cli1.x b/rpc/xdr/src/cli1.x index 31a996861c8..b43bc46d201 100644 --- a/rpc/xdr/src/cli1.x +++ b/rpc/xdr/src/cli1.x @@ -194,6 +194,20 @@ struct gf1_cli_get_vol_rsp { string status<>; } ; +struct gf1_cli_reset_vol_req { + string volname<>; + opaque dict<>; +} ; + + + struct gf1_cli_reset_vol_rsp { + int op_ret; + int op_errno; + string volname<>; + string op_errstr<>; +} ; + + struct gf1_cli_set_vol_req { string volname<>; @@ -205,6 +219,7 @@ struct gf1_cli_set_vol_req { int op_ret; int op_errno; string volname<>; + opaque dict<>; } ; struct gf1_cli_log_filename_req { 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[] = { diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c index 719ffdc31cc..26848001171 100644 --- a/xlators/protocol/server/src/server.c +++ b/xlators/protocol/server/src/server.c @@ -481,16 +481,32 @@ reconfigure (xlator_t *this, dict_t *options) gf_log (this->name, GF_LOG_WARNING, "'trace' takes on only boolean values. " "Neglecting option"); - return -1; + ret = -1; + goto out; } conf->trace = trace; gf_log (this->name, GF_LOG_TRACE, "Reconfigured trace" " to %d", conf->trace); } + if (!conf->auth_modules) + conf->auth_modules = dict_new (); - return 0; + dict_foreach (options, get_auth_types, conf->auth_modules); + ret = validate_auth_options (this, options); + if (ret == -1) { + /* logging already done in validate_auth_options function. */ + goto out; + } + + ret = gf_auth_init (this, conf->auth_modules); + if (ret) { + dict_unref (conf->auth_modules); + goto out; + } +out: + return ret; } int |