summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-op-sm.c
diff options
context:
space:
mode:
authorPranith Kumar K <pranithk@gluster.com>2011-03-31 03:31:01 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-31 04:20:13 -0700
commita728fc84b67f8ba37cf63a8e3ef67cf8b0bb1f32 (patch)
treead4728ec2d0617c80b70603682b7ef8c99012575 /xlators/mgmt/glusterd/src/glusterd-op-sm.c
parent43700ed04c1bac15f5df3702410c83fb63607476 (diff)
mgmt/glusterd: Improve profile output messages
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2616 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2616
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-op-sm.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c96
1 files changed, 49 insertions, 47 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 3b3a482cdba..b9a4139db2f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -2014,6 +2014,33 @@ out:
return ret;
}
+static gf_boolean_t
+glusterd_is_profile_on (glusterd_volinfo_t *volinfo)
+{
+ int ret = -1;
+ char *latency_key = NULL;
+ char *fd_stats_key = NULL;
+ gf_boolean_t is_latency_on = _gf_false;
+ gf_boolean_t is_fd_stats_on = _gf_false;
+
+ GF_ASSERT (volinfo);
+ latency_key = "diagnostics.latency-measurement";
+ fd_stats_key = "diagnostics.dump-fd-stats";
+
+ ret = dict_get_str_boolean (volinfo->dict, fd_stats_key,
+ _gf_false);
+ if (ret != -1)
+ is_fd_stats_on = ret;
+ ret = dict_get_str_boolean (volinfo->dict, latency_key,
+ _gf_false);
+ if (ret != -1)
+ is_latency_on = ret;
+ if ((_gf_true == is_latency_on) &&
+ (_gf_true == is_fd_stats_on))
+ return _gf_true;
+ return _gf_false;
+}
+
static int
glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr)
{
@@ -2022,88 +2049,63 @@ glusterd_op_stage_stats_volume (dict_t *dict, char **op_errstr)
gf_boolean_t exists = _gf_false;
char msg[2048] = {0,};
int32_t stats_op = GF_CLI_STATS_NONE;
- char *latency_key = NULL;
- char *fd_stats_key = NULL;
- char *value = NULL;
- gf_boolean_t enabled = _gf_false;
glusterd_volinfo_t *volinfo = NULL;
- latency_key = "diagnostics.latency-measurement";
- fd_stats_key = "diagnostics.dump-fd-stats";
-
ret = dict_get_str (dict, "volname", &volname);
if (ret) {
- gf_log ("glusterd", GF_LOG_ERROR, "volume name get failed");
+ snprintf (msg, sizeof (msg), "Volume name get failed");
goto out;
}
exists = glusterd_check_volume_exists (volname);
ret = glusterd_volinfo_find (volname, &volinfo);
if ((!exists) || (ret < 0)) {
- snprintf (msg, sizeof (msg), "volume %s, "
+ snprintf (msg, sizeof (msg), "Volume %s, "
"doesn't exist", volname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
ret = -1;
goto out;
}
ret = dict_get_int32 (dict, "op", &stats_op);
if (ret) {
- gf_log ("glusterd", GF_LOG_ERROR, "volume profile op get failed");
+ snprintf (msg, sizeof (msg), "Volume profile op get failed");
goto out;
}
- if (GF_CLI_STATS_INFO == stats_op) {
- if (_gf_false == glusterd_is_volume_started (volinfo)) {
- snprintf (msg, sizeof (msg), "volume %s is not started.",
- volinfo->volname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
+ if (GF_CLI_STATS_START == stats_op) {
+ if (_gf_true == glusterd_is_profile_on (volinfo)) {
+ snprintf (msg, sizeof (msg), "Profile on Volume %s is"
+ " already started", volinfo->volname);
ret = -1;
goto out;
}
-
- ret = dict_get_str (volinfo->dict, latency_key, &value);
- if (value) {
- ret = gf_string2boolean (value, &enabled);
- }
- if (ret || (_gf_false == enabled)) {
- snprintf (msg, sizeof (msg), "Profiling is not enabled for "
- "volume %s", volinfo->volname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
- ret = -1;
- goto out;
- }
- enabled = _gf_false;
- value = NULL;
- ret = dict_get_str (volinfo->dict, fd_stats_key, &value);
- if (value) {
- ret = gf_string2boolean (value, &enabled);
- }
- if (ret || (_gf_false == enabled)) {
- snprintf (msg, sizeof (msg), "Profiling is not enabled for "
- "volume %s", volinfo->volname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
+ }
+ if ((GF_CLI_STATS_STOP == stats_op) ||
+ (GF_CLI_STATS_INFO == stats_op)) {
+ if (_gf_false == glusterd_is_profile_on (volinfo)) {
+ snprintf (msg, sizeof (msg), "Profile on Volume %s is"
+ " not started", volinfo->volname);
ret = -1;
goto out;
}
- } else if (GF_CLI_STATS_TOP == stats_op) {
+ }
+ if ((GF_CLI_STATS_TOP == stats_op) ||
+ (GF_CLI_STATS_INFO == stats_op)) {
if (_gf_false == glusterd_is_volume_started (volinfo)) {
- snprintf (msg, sizeof (msg), "volume %s is not started.",
+ snprintf (msg, sizeof (msg), "Volume %s is not started.",
volinfo->volname);
gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
ret = -1;
goto out;
}
}
-
+ ret = 0;
out:
+ if (msg[0] != '\0') {
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", msg);
+ *op_errstr = gf_strdup (msg);
+ }
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
-
return ret;
}