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 | |
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
-rw-r--r-- | cli/src/cli-cmd-parser.c | 55 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 37 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 69 | ||||
-rw-r--r-- | cli/src/cli.h | 5 | ||||
-rw-r--r-- | libglusterfs/src/logging.c | 39 | ||||
-rw-r--r-- | rpc/rpc-lib/src/protocol-common.h | 2 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.c | 30 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.h | 18 | ||||
-rw-r--r-- | rpc/xdr/src/cli1-xdr.x | 12 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.c | 36 | ||||
-rw-r--r-- | rpc/xdr/src/cli1.h | 15 | ||||
-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 |
16 files changed, 618 insertions, 33 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 1b3c5ca2d26..d18336e7e28 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1015,6 +1015,61 @@ out: } int32_t +cli_cmd_log_level_parse (const char **words, int worcount, dict_t **options) +{ + dict_t *dict = NULL; + int ret = -1; + + GF_ASSERT (words); + GF_ASSERT (options); + + /* + * loglevel command format: + * > volume log level <VOL> <XLATOR[*]> <LOGLEVEL> + * > volume log level colon-o posix WARNING + * > volume log level colon-o replicate* DEBUG + * > volume log level coon-o * TRACE + */ + + GF_ASSERT ((strncmp(words[0], "volume", 6) == 0)); + GF_ASSERT ((strncmp(words[1], "log", 3) == 0)); + GF_ASSERT ((strncmp(words[2], "level", 5) == 0)); + + ret = glusterd_check_log_level(words[5]); + if (ret == -1) { + cli_out("invalid log level [%s] specified", words[4]); + goto out; + } + + dict = dict_new (); + if (!dict) + goto out; + + GF_ASSERT(words[3]); + GF_ASSERT(words[4]); + + ret = dict_set_str (dict, "volname", (char *)words[3]); + if (ret) + goto out; + + ret = dict_set_str (dict, "xlator", (char *)words[4]); + if (ret) + goto out; + + ret = dict_set_str (dict, "loglevel", (char *)words[5]); + if (ret) + goto out; + + *options = dict; + + out: + if (ret && dict) + dict_destroy (dict); + + return ret; +} + +int32_t cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 673202440fc..7ca9ed4bb2f 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1171,6 +1171,39 @@ out: return ret; } +int +cli_cmd_log_level_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 *dict = NULL; + int parse_error = 0; + + if (wordcount != 6) { + cli_usage_out (word->pattern); + parse_error = 1; + goto out; + } + + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LOG_LEVEL]; + + frame = create_frame (THIS, THIS->ctx->pool); + if (!frame) + goto out; + + ret = cli_cmd_log_level_parse (words, wordcount, &dict); + if (ret) + goto out; + + if (proc->fn) + ret = proc->fn (frame, THIS, dict); + + out: + return ret; +} + struct cli_cmd volume_cmds[] = { { "volume info [all|<VOLNAME>]", cli_cmd_volume_info_cbk, @@ -1265,6 +1298,10 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_top_cbk, "volume top operations"}, + {"volume log level <VOLNAME> <XLATOR[*]> <LOGLEVEL>", + cli_cmd_log_level_cbk, + "log level for translator"}, + { NULL, NULL, NULL } }; diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 1a2c4ee94ed..83abb865bcb 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -2277,6 +2277,74 @@ out: return ret; } +static int +gf_cli3_1_log_level_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + gf1_cli_log_level_rsp rsp = {0,}; + int ret = -1; + + if (req->rpc_status == -1) + goto out; + + ret = gf_xdr_to_cli_log_level_rsp (*iov, &rsp); + if (ret < 0) { + gf_log ("cli", GF_LOG_ERROR, "log level response error"); + goto out; + } + + gf_log ("cli", GF_LOG_DEBUG, "Received response to log level cmd"); + + if (rsp.op_ret && strcmp (rsp.op_errstr, "")) + cli_out (rsp.op_errstr); + else + cli_out ("log level set: %s", (rsp.op_ret) ? "unsuccessful" : + "successful"); + + ret = rsp.op_ret; + + out: + cli_cmd_broadcast_response (ret); + return ret; +} + +int32_t +gf_cli3_1_log_level (call_frame_t *frame, xlator_t *this, + void *data) +{ + gf1_cli_log_level_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_get_str (dict, "xlator", &req.xlator); + if (ret) + goto out; + + ret = dict_get_str (dict, "loglevel", &req.loglevel); + if (ret) + goto out; + + ret = cli_cmd_submit (&req, frame, cli_rpc_prog, + GLUSTER_CLI_LOG_LEVEL, NULL, + gf_xdr_from_cli_log_level_req, + this, gf_cli3_1_log_level_cbk); + + out: + gf_log ("cli", GF_LOG_DEBUG, "Returning: %d", ret); + return ret; +} + int32_t gf_cli3_1_log_locate (call_frame_t *frame, xlator_t *this, @@ -3429,6 +3497,7 @@ struct rpc_clnt_procedure gluster_cli_actors[GLUSTER_CLI_MAXVALUE] = { [GLUSTER_CLI_PROFILE_VOLUME] = {"PROFILE_VOLUME", gf_cli3_1_profile_volume}, [GLUSTER_CLI_QUOTA] = {"QUOTA", gf_cli3_1_quota}, [GLUSTER_CLI_TOP_VOLUME] = {"TOP_VOLUME", gf_cli3_1_top_volume}, + [GLUSTER_CLI_LOG_LEVEL] = {"VOLUME_LOGLEVEL", gf_cli3_1_log_level}, [GLUSTER_CLI_GETWD] = {"GETWD", gf_cli3_1_getwd} }; diff --git a/cli/src/cli.h b/cli/src/cli.h index 5d83f0fc1df..c81ae47e5cd 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -227,10 +227,15 @@ cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data); void cli_path_strip_trailing_slashes (char *path); + int32_t cli_cmd_volume_profile_parse (const char **words, int wordcount, dict_t **options); int32_t cli_cmd_volume_top_parse (const char **words, int wordcount, dict_t **options); + +int32_t +cli_cmd_log_level_parse (const char **words, int wordcount, + dict_t **options); #endif /* __CLI_H__ */ diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index eaa735d5f03..550aadef120 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -196,19 +196,18 @@ _gf_log_nomem (const char *domain, const char *file, xlator_t *this = NULL; struct timeval tv = {0,}; int ret = 0; - gf_loglevel_t xlator_loglevel = 0; char msg[8092]; char timestr[256]; char callstr[4096]; this = THIS; - xlator_loglevel = this->loglevel; - if (xlator_loglevel == 0) - xlator_loglevel = loglevel; - - if (level > xlator_loglevel) - goto out; + if (gf_log_xl_log_set) { + if (this->loglevel && (level > this->loglevel)) + goto out; + else if (level > gf_log_loglevel) + goto out; + } static char *level_strings[] = {"", /* NONE */ "M", /* EMERGENCY */ @@ -318,17 +317,16 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function, struct timeval tv = {0,}; size_t len = 0; int ret = 0; - gf_loglevel_t xlator_loglevel = 0; va_list ap; this = THIS; - xlator_loglevel = this->loglevel; - if (xlator_loglevel == 0) - xlator_loglevel = loglevel; - - if (level > xlator_loglevel) - goto out; + if (gf_log_xl_log_set) { + if (this->loglevel && (level > this->loglevel)) + goto out; + else if (level > gf_log_loglevel) + goto out; + } static char *level_strings[] = {"", /* NONE */ "M", /* EMERGENCY */ @@ -465,16 +463,15 @@ _gf_log (const char *domain, const char *file, const char *function, int line, size_t len = 0; int ret = 0; xlator_t *this = NULL; - gf_loglevel_t xlator_loglevel = 0; this = THIS; - xlator_loglevel = this->loglevel; - if (xlator_loglevel == 0) - xlator_loglevel = loglevel; - - if (level > xlator_loglevel) - goto out; + if (gf_log_xl_log_set) { + if (this->loglevel && (level > this->loglevel)) + goto out; + else if (level > gf_log_loglevel) + goto out; + } static char *level_strings[] = {"", /* NONE */ "M", /* EMERGENCY */ diff --git a/rpc/rpc-lib/src/protocol-common.h b/rpc/rpc-lib/src/protocol-common.h index a54c29fc55a..83ea1fc81c1 100644 --- a/rpc/rpc-lib/src/protocol-common.h +++ b/rpc/rpc-lib/src/protocol-common.h @@ -108,6 +108,7 @@ enum gf_mgmt_procnum_ { GD_MGMT_CLI_GSYNC_SET, GD_MGMT_CLI_PROFILE_VOLUME, GD_MGMT_BRICK_OP, + GD_MGMT_CLI_LOG_LEVEL, GD_MGMT_MAXVALUE, }; @@ -199,6 +200,7 @@ enum gluster_cli_procnum { GLUSTER_CLI_QUOTA, GLUSTER_CLI_TOP_VOLUME, GLUSTER_CLI_GETWD, + GLUSTER_CLI_LOG_LEVEL, GLUSTER_CLI_MAXVALUE, }; diff --git a/rpc/xdr/src/cli1-xdr.c b/rpc/xdr/src/cli1-xdr.c index e525bb755c5..5c3bc0c47be 100644 --- a/rpc/xdr/src/cli1-xdr.c +++ b/rpc/xdr/src/cli1-xdr.c @@ -804,3 +804,33 @@ xdr_gf1_cli_getwd_rsp (XDR *xdrs, gf1_cli_getwd_rsp *objp) return FALSE; return TRUE; } + +bool_t +xdr_gf1_cli_log_level_req (XDR *xdrs, gf1_cli_log_level_req *objp) +{ + if (!xdr_string (xdrs, &objp->volname, ~0)) + return FALSE; + + if (!xdr_string (xdrs, &objp->xlator, ~0)) + return FALSE; + + if (!xdr_string (xdrs, &objp->loglevel, ~0)) + return FALSE; + + return TRUE; +} + +bool_t +xdr_gf1_cli_log_level_rsp (XDR *xdrs, gf1_cli_log_level_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->op_errstr, ~0)) + return FALSE; + + return TRUE; +} diff --git a/rpc/xdr/src/cli1-xdr.h b/rpc/xdr/src/cli1-xdr.h index 42e5cbff860..6d65ead6a44 100644 --- a/rpc/xdr/src/cli1-xdr.h +++ b/rpc/xdr/src/cli1-xdr.h @@ -514,6 +514,20 @@ struct gf1_cli_getwd_rsp { }; typedef struct gf1_cli_getwd_rsp gf1_cli_getwd_rsp; +struct gf1_cli_log_level_req { + char *volname; + char *xlator; + char *loglevel; +}; +typedef struct gf1_cli_log_level_req gf1_cli_log_level_req; + +struct gf1_cli_log_level_rsp { + int op_ret; + int op_errno; + char *op_errstr; +}; +typedef struct gf1_cli_log_level_rsp gf1_cli_log_level_rsp; + /* the xdr functions */ #if defined(__STDC__) || defined(__cplusplus) @@ -574,6 +588,8 @@ extern bool_t xdr_gf1_cli_gsync_set_req (XDR *, gf1_cli_gsync_set_req*); extern bool_t xdr_gf1_cli_gsync_set_rsp (XDR *, gf1_cli_gsync_set_rsp*); extern bool_t xdr_gf1_cli_stats_volume_req (XDR *, gf1_cli_stats_volume_req*); extern bool_t xdr_gf1_cli_stats_volume_rsp (XDR *, gf1_cli_stats_volume_rsp*); +extern bool_t xdr_gf1_cli_log_level_req (XDR *, gf1_cli_log_level_req *); +extern bool_t xdr_gf1_cli_log_level_rsp (XDR *, gf1_cli_log_level_rsp *); extern bool_t xdr_gf1_cli_getwd_req (XDR *, gf1_cli_getwd_req*); extern bool_t xdr_gf1_cli_getwd_rsp (XDR *, gf1_cli_getwd_rsp*); @@ -635,6 +651,8 @@ extern bool_t xdr_gf1_cli_gsync_set_req (); extern bool_t xdr_gf1_cli_gsync_set_rsp (); extern bool_t xdr_gf1_cli_stats_volume_req (); extern bool_t xdr_gf1_cli_stats_volume_rsp (); +extern bool_t xdr_gf1_cli_log_level_req (); +extern bool_t xdr_gf1_cli_log_level_rsp (); extern bool_t xdr_gf1_cli_getwd_req (); extern bool_t xdr_gf1_cli_getwd_rsp (); diff --git a/rpc/xdr/src/cli1-xdr.x b/rpc/xdr/src/cli1-xdr.x index 4b15dcd2957..ee21d4bb3d8 100644 --- a/rpc/xdr/src/cli1-xdr.x +++ b/rpc/xdr/src/cli1-xdr.x @@ -376,3 +376,15 @@ struct gf1_cli_getwd_rsp { int op_errno; string wd<>; }; + +struct gf1_cli_log_level_req { + char *volname; + char *xlator; + char *loglevel; +}; + +struct gf1_cli_log_level_rsp { + int op_ret; + int op_errno; + char *op_errstr; +}; diff --git a/rpc/xdr/src/cli1.c b/rpc/xdr/src/cli1.c index e917929b349..78ef24f3dfd 100644 --- a/rpc/xdr/src/cli1.c +++ b/rpc/xdr/src/cli1.c @@ -740,3 +740,39 @@ gf_xdr_from_cli_getwd_rsp (struct iovec outmsg, void *args) return xdr_serialize_generic (outmsg, (void *)args, (xdrproc_t)xdr_gf1_cli_getwd_rsp); } + +ssize_t +gf_xdr_serialize_cli_log_level_rsp (struct iovec outmsg, void *rsp) +{ + return xdr_serialize_generic (outmsg, (void *)rsp, + (xdrproc_t)xdr_gf1_cli_log_level_rsp); + +} + +ssize_t +gf_xdr_to_cli_log_level_req (struct iovec inmsg, void *args) +{ + return xdr_to_generic (inmsg, (void *)args, + (xdrproc_t)xdr_gf1_cli_log_level_req); +} + +ssize_t +gf_xdr_from_cli_log_level_req (struct iovec outmsg, void *args) +{ + return xdr_serialize_generic (outmsg, (void*)args, + (xdrproc_t)xdr_gf1_cli_log_level_req); +} + +ssize_t +gf_xdr_to_cli_log_level_rsp (struct iovec inmsg, void *args) +{ + return xdr_to_generic (inmsg, (void *)args, + (xdrproc_t)xdr_gf1_cli_log_level_rsp); +} + +ssize_t +gf_xdr_from_cli_log_level_rsp (struct iovec outmsg, void *args) +{ + return xdr_serialize_generic (outmsg, (void *)args, + (xdrproc_t)xdr_gf1_cli_log_level_rsp); +} diff --git a/rpc/xdr/src/cli1.h b/rpc/xdr/src/cli1.h index 32e310aae83..26b142031a8 100644 --- a/rpc/xdr/src/cli1.h +++ b/rpc/xdr/src/cli1.h @@ -317,6 +317,21 @@ ssize_t gf_xdr_from_cli_stats_volume_rsp (struct iovec outmsg, void *args); ssize_t +gf_xdr_serialize_cli_log_level_rsp (struct iovec outmsg, void *rsp); + +ssize_t +gf_xdr_to_cli_log_level_req (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_to_cli_log_level_rsp (struct iovec inmsg, void *args); + +ssize_t +gf_xdr_from_cli_log_level_req (struct iovec outmsg, void *req); + +ssize_t +gf_xdr_serialize_cli_log_level_rsp (struct iovec outmsg, void *rsp); + +ssize_t gf_xdr_to_cli_getwd_req (struct iovec inmsg, void *args); ssize_t diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index df7a5f9fc91..8d963b9ab09 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 7a187963d0d..e61d294c815 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 bee892873a2..d03200b4714 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 da9a2c9e86b..a8b88160ffa 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 2fcd11c11f1..96e24be308a 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 |