diff options
author | Venky Shankar <venky@gluster.com> | 2011-04-25 03:10:01 +0000 |
---|---|---|
committer | Anand Avati <avati@gluster.com> | 2011-05-20 11:01:49 -0700 |
commit | 2cd8411a0278f98ed820aad3e482de079d0540c0 (patch) | |
tree | 66cd9fa15fe8d269277b41469c3f45a12f59c24b /xlators | |
parent | 03c58c782d99440a5947289d0ff216bca8ef7c57 (diff) |
cli log level command and per translator log level
Signed-off-by: Venky Shankar <venky@gluster.com>
Signed-off-by: Anand Avati <avati@gluster.com>
BUG: 2714 (implement cli log level command)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2714
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 67 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-op-sm.c | 156 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 15 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 91 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 4 |
5 files changed, 321 insertions, 12 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index df7a5f9fc..8d963b9ab 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -2356,6 +2356,69 @@ out: } int +glusterd_handle_log_level (rpcsvc_request_t *req) +{ + int32_t ret = -1; + int lock_fail = 0; + dict_t *dict = NULL; + gf1_cli_log_level_req cli_req = {0,}; + glusterd_op_t cli_op = GD_OP_LOG_LEVEL; + + GF_ASSERT(req); + + ret = glusterd_op_set_cli_op (cli_op); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to set cli op: %d", + ret); + lock_fail = 1; + goto out; + } + + if (!gf_xdr_to_cli_log_level_req(req->msg[0], &cli_req)) { + gf_log ("glusterd", GF_LOG_ERROR, "Failed to decode rpc message"); + req->rpc_err = GARBAGE_ARGS; + goto out; + } + + gf_log ("glusterd", GF_LOG_DEBUG, "Got log level request for: Volume [%s]" + " Xlator [%s] LogLevel [\"%s\"]", cli_req.volname, cli_req.xlator, cli_req.loglevel); + + dict = dict_new (); + if (!dict) + goto out; + + ret = dict_set_dynmstr (dict, "volname", cli_req.volname); + if (ret) + goto out; + + ret = dict_set_dynmstr (dict, "xlator", cli_req.xlator); + if (ret) + goto out; + + ret = dict_set_dynmstr (dict, "loglevel", cli_req.loglevel); + if (ret) + goto out; + + ret = glusterd_op_begin (req, cli_op, dict, _gf_true); + + out: + if (ret && dict) + dict_unref (dict); + + glusterd_friend_sm(); + glusterd_op_sm(); + + if (ret) { + ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, + "Operation failed"); + if (!lock_fail) + (void)glusterd_opinfo_unlock (); + } + + return ret; +} + +int glusterd_handle_log_rotate (rpcsvc_request_t *req) { int32_t ret = -1; @@ -3923,6 +3986,7 @@ rpcsvc_actor_t gd_svc_cli_actors[] = { [GLUSTER_CLI_GSYNC_SET] = { "GSYNC_SET", GLUSTER_CLI_GSYNC_SET, glusterd_handle_gsync_set, NULL, NULL}, [GLUSTER_CLI_PROFILE_VOLUME] = { "STATS_VOLUME", GLUSTER_CLI_PROFILE_VOLUME, glusterd_handle_cli_profile_volume, NULL, NULL}, [GLUSTER_CLI_QUOTA] = { "QUOTA", GLUSTER_CLI_QUOTA, glusterd_handle_quota, NULL, NULL}, + [GLUSTER_CLI_LOG_LEVEL] = {"LOG_LEVEL", GLUSTER_CLI_LOG_LEVEL, glusterd_handle_log_level, NULL, NULL}, [GLUSTER_CLI_GETWD] = { "GETWD", GLUSTER_CLI_GETWD, glusterd_handle_getwd, NULL, NULL}, }; @@ -3967,7 +4031,8 @@ rpcsvc_actor_t glusterd1_mgmt_actors[] = { [GD_MGMT_CLI_RESET_VOLUME] = { "RESET_VOLUME", GD_MGMT_CLI_RESET_VOLUME, glusterd_handle_reset_volume, NULL, NULL}, [GD_MGMT_CLI_FSM_LOG] = { "FSM_LOG", GD_MGMT_CLI_FSM_LOG, glusterd_handle_fsm_log, NULL, NULL}, [GD_MGMT_CLI_GSYNC_SET] = {"GSYNC_SET", GD_MGMT_CLI_GSYNC_SET, glusterd_handle_gsync_set, NULL, NULL}, - [GD_MGMT_CLI_PROFILE_VOLUME] = { "STATS_VOLUME", GD_MGMT_CLI_PROFILE_VOLUME, glusterd_handle_cli_profile_volume, NULL, NULL} + [GD_MGMT_CLI_PROFILE_VOLUME] = { "STATS_VOLUME", GD_MGMT_CLI_PROFILE_VOLUME, glusterd_handle_cli_profile_volume, NULL, NULL}, + [GD_MGMT_CLI_LOG_LEVEL] = {"LOG_LEVEL", GD_MGMT_CLI_LOG_LEVEL, glusterd_handle_log_level, NULL, NULL} }; struct rpcsvc_program glusterd1_mop_prog = { diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 7a187963d..e61d294c8 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -1102,6 +1102,80 @@ out: } static int +glusterd_op_stage_log_level (dict_t *dict, char **op_errstr) +{ + int ret = -1; + gf_boolean_t exists = _gf_false; + dict_t *val_dict = NULL; + char *volname = NULL; + char *xlator = NULL; + char *loglevel = NULL; + glusterd_volinfo_t *volinfo = NULL; + glusterd_conf_t *priv = NULL; + xlator_t *this = NULL; + char msg[2048] = {0,}; + + GF_ASSERT (dict); + this = THIS; + GF_ASSERT (this); + priv = this->private; + GF_ASSERT(priv); + + val_dict = dict_new (); + if (!val_dict) + goto out; + + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get volume name"); + goto out; + } + + /* + * check for existence of the gieven volume + */ + exists = glusterd_check_volume_exists (volname); + ret = glusterd_volinfo_find (volname, &volinfo); + if (!exists || ret) { + snprintf (msg, sizeof(msg), "Volume %s does not exist", volname); + gf_log ("glusterd", GF_LOG_ERROR, "%s", msg); + + *op_errstr = gf_strdup(msg); + ret = -1; + goto out; + } + + ret = dict_get_str (dict, "xlator", &xlator); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get translator name"); + goto out; + } + + ret = dict_get_str (dict, "loglevel", &loglevel); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get loglevel"); + goto out; + } + + ret = 0; + + out: + if (val_dict) + dict_unref (val_dict); + + if (ret) { + if (!(*op_errstr)) { + *op_errstr = gf_strdup ("Error, Validation Failed"); + gf_log ("glusterd", GF_LOG_DEBUG, "Error, Cannot Validate option: %s", + *op_errstr); + } + } + + gf_log ("glusterd", GF_LOG_DEBUG, "Returning: %d", ret); + return ret; +} + +static int glusterd_op_stage_log_filename (dict_t *dict, char **op_errstr) { int ret = -1; @@ -5368,6 +5442,78 @@ glusterd_restart_brick_servers (glusterd_volinfo_t *volinfo) } static int +glusterd_op_log_level (dict_t *dict) +{ + int32_t ret = -1; + glusterd_volinfo_t *volinfo = NULL; + char *volname = NULL; + char *xlator = NULL; + char *loglevel = NULL; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + + this = THIS; + GF_ASSERT (this); + + priv = this->private; + GF_ASSERT (priv); + + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get volume name"); + goto out; + } + + ret = dict_get_str (dict, "xlator", &xlator); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get translator name"); + goto out; + } + + ret = dict_get_str (dict, "loglevel", &loglevel); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to get Loglevel to use"); + goto out; + } + + ret = glusterd_volinfo_find (volname, &volinfo); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Cannot find volume: %s", volname); + goto out; + } + + xlator = gf_strdup (xlator); + + ret = dict_set_dynstr (volinfo->dict, "xlator", xlator); + if (ret) + goto out; + + loglevel = gf_strdup (loglevel); + + ret = dict_set_dynstr (volinfo->dict, "loglevel", loglevel); + if (ret) + goto out; + + ret = glusterd_create_volfiles_and_notify_services (volinfo); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "Unable to create volfile for command" + " 'log level'"); + ret = -1; + goto out; + } + + ret = glusterd_store_volinfo (volinfo, GLUSTERD_VOLINFO_VER_AC_INCREMENT); + if (ret) + goto out; + + ret = 0; + + out: + gf_log ("glusterd", GF_LOG_DEBUG, "(cli log level) Returning: %d", ret); + return ret; +} + +static int glusterd_op_set_volume (dict_t *dict) { int ret = 0; @@ -6389,6 +6535,7 @@ glusterd_op_build_payload (glusterd_op_t op, dict_t **req) case GD_OP_QUOTA: case GD_OP_GSYNC_SET: case GD_OP_PROFILE_VOLUME: + case GD_OP_LOG_LEVEL: { dict_t *dict = ctx; dict_copy (dict, req_dict); @@ -7349,6 +7496,10 @@ glusterd_op_stage_validate (glusterd_op_t op, dict_t *dict, char **op_errstr, ret = glusterd_op_stage_quota (dict, op_errstr); break; + case GD_OP_LOG_LEVEL: + ret = glusterd_op_stage_log_level (dict, op_errstr); + break; + default: gf_log ("", GF_LOG_ERROR, "Unknown op %d", op); @@ -7428,6 +7579,10 @@ glusterd_op_commit_perform (glusterd_op_t op, dict_t *dict, char **op_errstr, ret = glusterd_op_quota (dict, op_errstr); break; + case GD_OP_LOG_LEVEL: + ret = glusterd_op_log_level (dict); + break; + default: gf_log ("", GF_LOG_ERROR, "Unknown op %d", op); @@ -8433,6 +8588,7 @@ glusterd_op_free_ctx (glusterd_op_t op, void *ctx, gf_boolean_t ctx_free) case GD_OP_GSYNC_SET: case GD_OP_QUOTA: case GD_OP_PROFILE_VOLUME: + case GD_OP_LOG_LEVEL: dict_unref (ctx); break; case GD_OP_DELETE_VOLUME: diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index bee892873..d03200b47 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -364,6 +364,21 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, break; } + case GD_OP_LOG_LEVEL: + { + gf1_cli_log_level_rsp rsp = {0,}; + rsp.op_ret = op_ret; + rsp.op_errno = op_errno; + if (op_errstr) + rsp.op_errstr = op_errstr; + else + rsp.op_errstr = ""; + + cli_rsp = &rsp; + sfunc = gf_xdr_serialize_cli_log_level_rsp; + break; + } + case GD_OP_NONE: case GD_OP_MAX: { diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index da9a2c9e8..a8b88160f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -1238,6 +1238,39 @@ server_check_marker_off (volgen_graph_t *graph, struct volopt_map_entry *vme, } static int +volgen_graph_set_xl_options (volgen_graph_t *graph, dict_t *dict) +{ + int32_t ret = -1; + char *xlator = NULL; + char xlator_match[1024] = {0,}; /* for posix* -> *posix* */ + char *loglevel = NULL; + xlator_t *trav = NULL; + + ret = dict_get_str (dict, "xlator", &xlator); + if (ret) + goto out; + + ret = dict_get_str (dict, "loglevel", &loglevel); + if (ret) + goto out; + + snprintf (xlator_match, 1024, "*%s", xlator); + + for (trav = first_of (graph); trav; trav = trav->next) { + if (fnmatch(xlator_match, trav->type, FNM_NOESCAPE) == 0) { + gf_log ("glusterd", GF_LOG_DEBUG, "Setting log level for xlator: %s", + trav->type); + ret = xlator_set_option (trav, "log-level", loglevel); + if (ret) + break; + } + } + + out: + return ret; +} + +static int server_spec_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, void *param) { @@ -1256,27 +1289,58 @@ server_spec_option_handler (volgen_graph_t *graph, return ret; } +static int +server_spec_extended_option_handler (volgen_graph_t *graph, + struct volopt_map_entry *vme, void *param) +{ + int ret = 0; + dict_t *dict = NULL; + + GF_ASSERT (param); + dict = (dict_t *)param; + + ret = server_auth_option_handler (graph, vme, NULL); + if (!ret) + ret = volgen_graph_set_xl_options (graph, dict); + + return ret; +} + static void get_vol_tstamp_file (char *filename, glusterd_volinfo_t *volinfo); static int server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, dict_t *set_dict, void *param) { - char *volname = NULL; - char *path = NULL; - int pump = 0; - xlator_t *xl = NULL; - xlator_t *txl = NULL; - xlator_t *rbxl = NULL; - char transt[16] = {0,}; - char volume_id[64] = {0,}; + char *volname = NULL; + char *path = NULL; + int pump = 0; + xlator_t *xl = NULL; + xlator_t *txl = NULL; + xlator_t *rbxl = NULL; + char transt[16] = {0,}; + char volume_id[64] = {0,}; char tstamp_file[PATH_MAX] = {0,}; - int ret = 0; + int ret = 0; + char *xlator = NULL; + char *loglevel = NULL; path = param; volname = volinfo->volname; get_vol_transport_type (volinfo, transt); + ret = dict_get_str (set_dict, "xlator", &xlator); + + /* got a cli log level request */ + if (!ret) { + ret = dict_get_str (set_dict, "loglevel", &loglevel); + if (ret) { + gf_log ("glusterd", GF_LOG_ERROR, "could not get both" + " translator name and loglevel for log level request"); + goto out; + } + } + xl = volgen_graph_add (graph, "storage/posix", volname); if (!xl) return -1; @@ -1347,9 +1411,12 @@ server_graph_builder (volgen_graph_t *graph, glusterd_volinfo_t *volinfo, if (ret) return -1; - ret = volgen_graph_set_options_generic (graph, set_dict, volinfo, - &server_spec_option_handler); + ret = volgen_graph_set_options_generic (graph, set_dict, + (xlator && loglevel) ? (void *)set_dict : volinfo, + (xlator && loglevel) ? &server_spec_extended_option_handler : + &server_spec_option_handler); + out: return ret; } @@ -1923,6 +1990,8 @@ glusterd_generate_brick_volfile (glusterd_volinfo_t *volinfo, return ret; } + + static void get_vol_tstamp_file (char *filename, glusterd_volinfo_t *volinfo) { diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 2fcd11c11..96e24be30 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -75,6 +75,7 @@ typedef enum glusterd_op_ { GD_OP_GSYNC_SET, GD_OP_PROFILE_VOLUME, GD_OP_QUOTA, + GD_OP_LOG_LEVEL, GD_OP_MAX, } glusterd_op_t; @@ -512,4 +513,7 @@ int glusterd_rpc_create (struct rpc_clnt **rpc, dict_t *options, rpc_clnt_notify_t notify_fn, void *notify_data); +int +glusterd_handle_log_level (rpcsvc_request_t *req); + #endif |