From f68887999e89d894c3125e3b26517221ad1543fc Mon Sep 17 00:00:00 2001 From: "Kaleb S. KEITHLEY" Date: Tue, 1 Aug 2017 08:04:48 -0400 Subject: logging: localtime logging, cmdline, volume set option Despite the fact that appliances generally use UTC, some users really want log entries in localtime. fixes gluster/glusterfs#272 feature page: https://review.gluster.org/17807 Change-Id: I5fbf2c3eedd9eb128fb3f851dd67b2f4081c8bba Signed-off-by: Kaleb S. KEITHLEY Reviewed-on: https://review.gluster.org/16911 CentOS-regression: Gluster Build System Smoke: Gluster Build System Reviewed-by: Samikshan Bairagya Reviewed-by: Shyamsundar Ranganathan --- xlators/mgmt/glusterd/src/glusterd-handler.c | 1 + xlators/mgmt/glusterd/src/glusterd-messages.h | 26 +++++++++- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 66 ++++++++++++++++++++++++- xlators/mgmt/glusterd/src/glusterd-utils.c | 7 +++ xlators/mgmt/glusterd/src/glusterd-volgen.c | 30 +++++++++++ xlators/mgmt/glusterd/src/glusterd-volume-set.c | 7 ++- xlators/mgmt/glusterd/src/glusterd.c | 20 ++++++++ xlators/mgmt/glusterd/src/glusterd.h | 2 +- 8 files changed, 155 insertions(+), 4 deletions(-) (limited to 'xlators') diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index 580a2e2ffc9..230d2196d41 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -4585,6 +4585,7 @@ gd_is_global_option (char *opt_key) strcmp (opt_key, GLUSTERD_QUORUM_RATIO_KEY) == 0 || strcmp (opt_key, GLUSTERD_GLOBAL_OP_VERSION_KEY) == 0 || strcmp (opt_key, GLUSTERD_BRICK_MULTIPLEX_KEY) == 0 || + strcmp (opt_key, GLUSTERD_LOCALTIME_LOGGING_KEY) == 0 || strcmp (opt_key, GLUSTERD_MAX_OP_VERSION_KEY) == 0); out: diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h index 035ba82b7de..eebc14901a1 100644 --- a/xlators/mgmt/glusterd/src/glusterd-messages.h +++ b/xlators/mgmt/glusterd/src/glusterd-messages.h @@ -41,7 +41,7 @@ #define GLUSTERD_COMP_BASE GLFS_MSGID_GLUSTERD -#define GLFS_NUM_MESSAGES 608 +#define GLFS_NUM_MESSAGES 611 #define GLFS_MSGID_END (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1) /* Messaged with message IDs */ @@ -4913,6 +4913,30 @@ */ #define GD_MSG_GARBAGE_ARGS (GLUSTERD_COMP_BASE + 608) +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */ +#define GD_MSG_LOCALTIME_LOGGING_VOL_OPT_VALIDATE_FAIL (GLUSTERD_COMP_BASE + 609) + +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */ +#define GD_MSG_LOCALTIME_LOGGING_ENABLE (GLUSTERD_COMP_BASE + 610) + +/*! + * @messageid + * @diagnosis + * @recommendedaction + * + */ +#define GD_MSG_LOCALTIME_LOGGING_DISABLE (GLUSTERD_COMP_BASE + 611) + /*------------*/ #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 6be92d8ad7e..7bb3d537097 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -85,6 +85,7 @@ glusterd_all_vol_opts valid_all_vol_opts[] = { * TBD: Discuss the default value for this. Maybe this should be a * dynamic value depending on the memory specifications per node */ { GLUSTERD_BRICKMUX_LIMIT_KEY, "0"}, + { GLUSTERD_LOCALTIME_LOGGING_KEY, "disable"}, { NULL }, }; @@ -869,6 +870,60 @@ out: return ret; } +static int +glusterd_validate_localtime_logging (char *key, char *value, char *errstr) +{ + int32_t ret = -1; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + int already_enabled = 0; + + this = THIS; + GF_VALIDATE_OR_GOTO ("glusterd", this, out); + + conf = this->private; + GF_VALIDATE_OR_GOTO (this->name, conf, out); + + GF_VALIDATE_OR_GOTO (this->name, key, out); + GF_VALIDATE_OR_GOTO (this->name, value, out); + GF_VALIDATE_OR_GOTO (this->name, errstr, out); + + ret = 0; + + if (strcmp (key, GLUSTERD_LOCALTIME_LOGGING_KEY)) { + goto out; + } + + if ((strcmp (value, "enable")) && + (strcmp (value, "disable"))) { + snprintf (errstr, PATH_MAX, + "Invalid option(%s). Valid options " + "are 'enable' and 'disable'", value); + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "%s", errstr); + ret = -1; + } + + already_enabled = gf_log_get_localtime (); + + if (strcmp (value, "enable") == 0) { + gf_log_set_localtime (1); + if (!already_enabled) + gf_msg (this->name, GF_LOG_INFO, 0, + GD_MSG_LOCALTIME_LOGGING_ENABLE, + "localtime logging enable"); + } else if (strcmp (value, "disable") == 0) { + gf_log_set_localtime (0); + if (already_enabled) + gf_msg (this->name, GF_LOG_INFO, 0, + GD_MSG_LOCALTIME_LOGGING_DISABLE, + "localtime logging disable"); + } + +out: + return ret; +} + static int glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) { @@ -1253,6 +1308,14 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr) goto out; } + ret = glusterd_validate_localtime_logging (key, value, errstr); + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, + GD_MSG_LOCALTIME_LOGGING_VOL_OPT_VALIDATE_FAIL, + "Failed to validate localtime " + "logging volume options"); + goto out; + } if (volinfo) { ret = glusterd_volinfo_get (volinfo, @@ -2639,6 +2702,7 @@ out: return ret; } + int glusterd_op_get_max_opversion (char **op_errstr, dict_t *rsp_dict) { @@ -2658,6 +2722,7 @@ out: return ret; } + static int glusterd_set_shared_storage (dict_t *dict, char *key, char *value, char **op_errstr) @@ -2735,7 +2800,6 @@ out: } - static int glusterd_op_set_volume (dict_t *dict, char **errstr) { diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 522872d4815..1502f4d37dc 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -1944,6 +1944,7 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo, int port = 0; int rdma_port = 0; char *bind_address = NULL; + char *localtime_logging = NULL; char socketpath[PATH_MAX] = {0}; char glusterd_uuid[1024] = {0,}; char valgrind_logfile[PATH_MAX] = {0}; @@ -2063,6 +2064,12 @@ retry: "--xlator-option", glusterd_uuid, NULL); + if (dict_get_str (priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, + &localtime_logging) == 0) { + if (strcmp (localtime_logging, "enable") == 0) + runner_add_arg (&runner, "--localtime-logging"); + } + runner_add_arg (&runner, "--brick-port"); if (volinfo->transport_type != GF_TRANSPORT_BOTH_TCP_RDMA) { runner_argprintf (&runner, "%d", port); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index 1ada7232f3e..d82e0f1ae86 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -1309,6 +1309,25 @@ log_format_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, return basic_option_handler (graph, &vme2, NULL); } +static int +log_localtime_logging_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, + void *param) +{ + char *role = NULL; + struct volopt_map_entry vme2 = {0,}; + + role = (char *) param; + + if (strcmp (vme->option, "!cluster.localtime-logging") != 0 || + !strstr (vme->key, role)) + return 0; + + memcpy (&vme2, vme, sizeof (vme2)); + vme2.option = GLUSTERD_LOCALTIME_LOGGING_KEY; + + return basic_option_handler (graph, &vme2, NULL); +} + static int log_buf_size_option_handler (volgen_graph_t *graph, struct volopt_map_entry *vme, @@ -1414,6 +1433,9 @@ server_spec_option_handler (volgen_graph_t *graph, if (!ret) ret = log_flush_timeout_option_handler (graph, vme, "brick"); + if (!ret) + ret = log_localtime_logging_option_handler (graph, vme, "brick"); + return ret; } @@ -3974,6 +3996,14 @@ graph_set_generic_options (xlator_t *this, volgen_graph_t *graph, GD_MSG_GRAPH_SET_OPT_FAIL, "Failed to change " "log-flush-timeout option"); + + ret = volgen_graph_set_options_generic (graph, set_dict, "client", + &log_localtime_logging_option_handler); + if (ret) + gf_msg (this->name, GF_LOG_WARNING, 0, + GD_MSG_GRAPH_SET_OPT_FAIL, + "Failed to change " + "log-localtime-logging option"); return 0; } diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index d336d383986..112d46f8979 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -3519,7 +3519,12 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = GD_OP_VERSION_3_11_0, .flags = OPT_FLAG_CLIENT_OPT }, - + { .key = GLUSTERD_LOCALTIME_LOGGING_KEY, + .voltype = "mgmt/glusterd", + .type = GLOBAL_DOC, + .op_version = GD_OP_VERSION_3_12_0, + .validate_fn = validate_boolean + }, { .key = NULL } }; diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c index f8a38f965a6..68998f0a877 100644 --- a/xlators/mgmt/glusterd/src/glusterd.c +++ b/xlators/mgmt/glusterd/src/glusterd.c @@ -1401,6 +1401,7 @@ init (xlator_t *this) int32_t workers = 0; gf_boolean_t upgrade = _gf_false; gf_boolean_t downgrade = _gf_false; + char *localtime_logging = NULL; #ifndef GF_DARWIN_HOST_OS { @@ -1846,6 +1847,25 @@ init (xlator_t *this) if (ret < 0) goto out; + if (dict_get_str (conf->opts, GLUSTERD_LOCALTIME_LOGGING_KEY, + &localtime_logging) == 0) { + int already_enabled = gf_log_get_localtime (); + + if (strcmp (localtime_logging, "enable") == 0) { + gf_log_set_localtime (1); + if (!already_enabled) + gf_msg (this->name, GF_LOG_INFO, 0, + GD_MSG_LOCALTIME_LOGGING_ENABLE, + "localtime logging enable"); + } else if (strcmp (localtime_logging, "disable") == 0) { + gf_log_set_localtime (0); + if (already_enabled) + gf_msg (this->name, GF_LOG_INFO, 0, + GD_MSG_LOCALTIME_LOGGING_DISABLE, + "localtime logging disable"); + } + } + conf->blockers = 0; /* If the peer count is less than 2 then this would be the best time to * spawn process/bricks that may need (re)starting since last time diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index 3b7ee152f82..12a0c392d95 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -54,8 +54,8 @@ #define GLUSTER_SHARED_STORAGE "gluster_shared_storage" #define GLUSTERD_SHARED_STORAGE_KEY "cluster.enable-shared-storage" #define GLUSTERD_BRICK_MULTIPLEX_KEY "cluster.brick-multiplex" - #define GLUSTERD_BRICKMUX_LIMIT_KEY "cluster.max-bricks-per-process" +#define GLUSTERD_LOCALTIME_LOGGING_KEY "cluster.localtime-logging" #define GLUSTERD_SNAPS_MAX_HARD_LIMIT 256 #define GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT 90 -- cgit