Patchwork [BUG:1886] Log level mess clean up

login
register
Submitter shishir gowda
Date 2010-10-18 13:45:30
Message ID <20101018134530.GA9241@dev.gluster.com>
Download mbox | patch
Permalink /patch/5520/
State Accepted
Headers show

Comments

shishir gowda - 2010-10-18 13:45:30
Signed-off-by: shishir gowda <shishirng@gluster.com>
---
 libglusterfs/src/xlator.c                   |   45 +++++++++++++++++---------
 libglusterfs/src/xlator.h                   |    1 +
 xlators/debug/io-stats/src/io-stats.c       |   17 ++++++++++
 xlators/mgmt/glusterd/src/glusterd-volgen.c |   30 ------------------
 xlators/mgmt/glusterd/src/glusterd-volgen.h |    1 -
 5 files changed, 47 insertions(+), 47 deletions(-)

Patch

diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 7966b3d..fa1ad19 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -1260,22 +1260,7 @@  is_gf_log_command (xlator_t *this, const char *name, char *value)
         if (fnmatch ("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE))
                 goto out;
 
-        if (!strcasecmp (value, "CRITICAL")) {
-                log_level = GF_LOG_CRITICAL;
-        } else if (!strcasecmp (value, "ERROR")) {
-                log_level = GF_LOG_ERROR;
-        } else if (!strcasecmp (value, "WARNING")) {
-                log_level = GF_LOG_WARNING;
-        } else if (!strcasecmp (value, "INFO")) {
-                log_level = GF_LOG_INFO;
-        } else if (!strcasecmp (value, "DEBUG")) {
-                log_level = GF_LOG_DEBUG;
-        } else if (!strcasecmp (value, "TRACE")) {
-                log_level = GF_LOG_TRACE;
-        } else if (!strcasecmp (value, "NONE")) {
-                log_level = GF_LOG_NONE;
-        }
-
+        log_level = glusterd_check_log_level (value);
         if (log_level == -1) {
                 ret = EOPNOTSUPP;
                 goto out;
@@ -1323,3 +1308,31 @@  is_gf_log_command (xlator_t *this, const char *name, char *value)
 out:
         return ret;
 }
+
+int
+glusterd_check_log_level (const char *value)
+{
+        int log_level = -1;
+
+        if (!strcasecmp (value, "CRITICAL")) {
+                log_level = GF_LOG_CRITICAL;
+        } else if (!strcasecmp (value, "ERROR")) {
+                log_level = GF_LOG_ERROR;
+        } else if (!strcasecmp (value, "WARNING")) {
+                log_level = GF_LOG_WARNING;
+        } else if (!strcasecmp (value, "INFO")) {
+                log_level = GF_LOG_INFO;
+        } else if (!strcasecmp (value, "DEBUG")) {
+                log_level = GF_LOG_DEBUG;
+        } else if (!strcasecmp (value, "TRACE")) {
+                log_level = GF_LOG_TRACE;
+        } else if (!strcasecmp (value, "NONE")) {
+                log_level = GF_LOG_NONE;
+        }
+
+        if (log_level == -1)
+                gf_log ("", GF_LOG_ERROR, "Invalid log-level. possible values "
+                        "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE");
+
+        return log_level;
+}
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 5d90a6e..e583e8c 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -864,6 +864,7 @@  int xlator_tree_reconfigure (xlator_t *old_xl, xlator_t *new_xl);
 int is_gf_log_command (xlator_t *trans, const char *name, char *value);
 int xlator_validate_rec (xlator_t *xlator, char **op_errstr);
 int graph_reconf_validateopt (glusterfs_graph_t *graph, char **op_errstr);
+int glusterd_check_log_level (const char *value);
 
 #define GF_STAT_PRINT_FMT_STR "%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx64",%"PRIx64",%"PRIx32",%"PRIx64",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32",%"PRIx32"\n"
 
diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c
index 17d4e29..8068ff4 100644
--- a/xlators/debug/io-stats/src/io-stats.c
+++ b/xlators/debug/io-stats/src/io-stats.c
@@ -1702,6 +1702,23 @@  fini (xlator_t *this)
         return;
 }
 
+int
+validate_options (xlator_t *this, dict_t *options, char **op_errstr)
+{
+        int             ret = -1;
+        char            *log_str = NULL;
+
+        ret = dict_get_str (options, "log-level", &log_str);
+        if (ret)
+                return 0;
+        ret = glusterd_check_log_level(log_str);
+        if (ret == -1)
+                *op_errstr = gf_strdup ("Invalid log level. possible option are"
+                                    " DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE");
+        else
+                ret = 0;
+        return ret;
+}
 
 struct xlator_fops fops = {
         .stat        = io_stats_stat,
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 9874499..177be9d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -738,8 +738,6 @@  loglevel_option_handler (glusterfs_graph_t *graph,
             !strstr (vme->key, role))
                 return 0;
 
-        if (glusterd_check_log_level(vme->value) == -1)
-                return -1;
         memcpy (&vme2, vme, sizeof (vme2));
         vme2.option = "log-level";
 
@@ -1390,31 +1388,3 @@  out:
                 gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
                 return ret;
 }
-
-int
-glusterd_check_log_level (const char *value)
-{
-        int log_level = -1;
-
-        if (!strcasecmp (value, "CRITICAL")) {
-                log_level = GF_LOG_CRITICAL;
-        } else if (!strcasecmp (value, "ERROR")) {
-                log_level = GF_LOG_ERROR;
-        } else if (!strcasecmp (value, "WARNING")) {
-                log_level = GF_LOG_WARNING;
-        } else if (!strcasecmp (value, "INFO")) {
-                log_level = GF_LOG_INFO;
-        } else if (!strcasecmp (value, "DEBUG")) {
-                log_level = GF_LOG_DEBUG;
-        } else if (!strcasecmp (value, "TRACE")) {
-                log_level = GF_LOG_TRACE;
-        } else if (!strcasecmp (value, "NONE")) {
-                log_level = GF_LOG_NONE;
-        }
-
-        if (log_level == -1)
-                gf_log ("", GF_LOG_ERROR, "Invalid log-level. possible values "
-                        "are DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE");
-
-        return log_level;
-}
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
index 0e6be80..e84e183 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
@@ -41,5 +41,4 @@  int glusterd_delete_volfile (glusterd_volinfo_t *volinfo,
 
 int glusterd_volinfo_get (glusterd_volinfo_t *volinfo, char *key, char **value);
 
-int glusterd_check_log_level (const char *log_level);
 #endif