Patchwork [BUG:1789] Add log-level option to command volume set

login
register
Submitter shishir gowda
Date 2010-10-04 12:17:35
Message ID <20101004121735.GA6473@dev.gluster.com>
Download mbox | patch
Permalink /patch/5234/
State Accepted
Headers show

Comments

shishir gowda - 2010-10-04 12:17:35
log-level option to set brick's log-level
client-log-level to set client's log-level

Signed-off-by: shishir gowda <shishirng@gluster.com>
---
 libglusterfs/src/xlator.c                   |   90 +++++++++++++++++++++++++++
 libglusterfs/src/xlator.h                   |    1 +
 xlators/debug/io-stats/src/io-stats.c       |   24 +++++++
 xlators/mgmt/glusterd/src/glusterd-volgen.c |    2 +
 xlators/mount/fuse/src/fuse-bridge.h        |    1 -
 xlators/mount/fuse/src/fuse-helpers.c       |   85 -------------------------
 6 files changed, 117 insertions(+), 86 deletions(-)
Amar Tumballi - 2010-10-04 13:21:11
Reviewed OK (as long as this patch goes in before kaushik's/csaba's new
patch goes in, reason below).

This patch at the moment is fine. But we are bringing some changes in volume
set keys.

I recommend 'diagnostics.brick-log-level' and 'diagnostics.client-log-level'
as the corresponding keys.

-Amar


On Mon, Oct 4, 2010 at 5:47 PM, shishir gowda <shishirng@gluster.com> wrote:

> log-level option to set brick's log-level
> client-log-level to set client's log-level
>
> Signed-off-by: shishir gowda <shishirng@gluster.com>
>

Patch

diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 6650896..64f8b71 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -1166,3 +1166,93 @@  xlator_destroy (xlator_t *xl)
 
         return 0;
 }
+int
+is_gf_log_command (xlator_t *this, const char *name, char *value)
+{
+        xlator_t       *trav        = NULL;
+        char            key[1024]   = {0,};
+        int             ret         = -1;
+        int             log_level   = -1;
+        gf_boolean_t    syslog_flag = 0;
+        glusterfs_ctx_t *ctx        = NULL;
+
+        if (!strcmp ("trusted.glusterfs.syslog", name)) {
+                ret = gf_string2boolean (value, &syslog_flag);
+                if (ret) {
+                        ret = EOPNOTSUPP;
+                        goto out;
+                }
+                if (syslog_flag)
+                        gf_log_enable_syslog ();
+                else
+                        gf_log_disable_syslog ();
+
+                goto out;
+        }
+
+        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;
+        }
+
+        if (log_level == -1) {
+                ret = EOPNOTSUPP;
+                goto out;
+        }
+
+        /* Some crude way to change the log-level of process */
+        if (!strcmp (name, "trusted.glusterfs.set-log-level")) {
+                /* */
+                gf_log ("glusterfs", gf_log_get_loglevel(),
+                        "setting log level to %d (old-value=%d)",
+                        log_level, gf_log_get_loglevel());
+                gf_log_set_loglevel (log_level);
+                ret = 0;
+                goto out;
+        }
+        if (!strcmp (name, "trusted.glusterfs.fuse.set-log-level")) {
+                /* */
+                gf_log (this->name, gf_log_get_xl_loglevel (this),
+                        "setting log level to %d (old-value=%d)",
+                        log_level, gf_log_get_xl_loglevel (this));
+                gf_log_set_xl_loglevel (this, log_level);
+                ret = 0;
+                goto out;
+        }
+
+        ctx = glusterfs_ctx_get();
+        if (!ctx)
+                goto out;
+        if (!ctx->active)
+                goto out;
+        trav = ctx->active->top;
+
+        while (trav) {
+                snprintf (key, 1024, "trusted.glusterfs.%s.set-log-level",
+                          trav->name);
+                if (fnmatch (name, key, FNM_NOESCAPE) == 0) {
+                        gf_log (trav->name, gf_log_get_xl_loglevel (trav),
+                                "setting log level to %d (old-value=%d)",
+                                log_level, gf_log_get_xl_loglevel (trav));
+                        gf_log_set_xl_loglevel (trav, log_level);
+                        ret = 0;
+                }
+                trav = trav->next;
+        }
+out:
+        return ret;
+}
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index db5e652..d1cb839 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -859,6 +859,7 @@  int loc_copy (loc_t *dst, loc_t *src);
 void loc_wipe (loc_t *loc);
 int xlator_mem_acct_init (xlator_t *xl, int num_types);
 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);
 
 #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 bf51318..0fdefd1 100644
--- a/xlators/debug/io-stats/src/io-stats.c
+++ b/xlators/debug/io-stats/src/io-stats.c
@@ -20,6 +20,7 @@ 
 #ifndef _CONFIG_H
 #define _CONFIG_H
 #include "config.h"
+#include "xlator.h"
 #endif
 
 /**
@@ -1549,6 +1550,8 @@  reconfigure (xlator_t *this, dict_t *options)
         struct ios_conf    *conf = NULL;
         char               *str = NULL;
         int                 ret = 0;
+        char               *log_str = NULL;
+        glusterfs_ctx_t     *ctx = NULL;
 
         if (!this || !this->private)
                 return -1;
@@ -1579,6 +1582,21 @@  reconfigure (xlator_t *this, dict_t *options)
                 }
                 conf->measure_latency = ret;
         }
+        ctx = glusterfs_ctx_get ();
+        if (!ctx)
+                return -1;
+
+        if (ctx->cmd_args.brick_name)
+                ret = dict_get_str (options, "log-level", &log_str);
+        else
+                ret = dict_get_str (options, "client-log-level", &log_str);
+
+        if (!ret) {
+                if (!is_gf_log_command(this, "trusted.glusterfs*set-log-level", log_str)) {
+                        gf_log (this->name, GF_LOG_DEBUG,
+                               "changing log-level to %s", log_str);
+                }
+        }
         return 0;
 }
 
@@ -1737,5 +1755,11 @@  struct volume_options options[] = {
         { .key  = { "latency-measurement" },
           .type = GF_OPTION_TYPE_BOOL,
         },
+        { .key = {"log-level"},
+          .type = GF_OPTION_TYPE_STR,
+        },
+        { .key = {"client-log-level"},
+          .type = GF_OPTION_TYPE_STR,
+        },
         { .key  = {NULL} },
 };
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 9e672a5..53250cc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -87,6 +87,8 @@  static struct volopt_map_entry glusterd_volopt_map[] = {
 
         {"latency-measurement",         "debug/io-stats"},
         {"dump-fd-stats",               "debug/io-stats"},
+        {"log-level",                   "debug/io-stats"},
+        {"client-log-level",            "debug/io-stats"},
 
         {"max-file-size",               "performance/io-cache"},
         {"min-file-size",               "performance/io-cache"},
diff --git a/xlators/mount/fuse/src/fuse-bridge.h b/xlators/mount/fuse/src/fuse-bridge.h
index d719832..285b4ec 100644
--- a/xlators/mount/fuse/src/fuse-bridge.h
+++ b/xlators/mount/fuse/src/fuse-bridge.h
@@ -285,7 +285,6 @@  xlator_t *fuse_state_subvol (fuse_state_t *state);
 xlator_t *fuse_active_subvol (xlator_t *fuse);
 inode_t *fuse_ino_to_inode (uint64_t ino, xlator_t *fuse);
 int fuse_resolve_and_resume (fuse_state_t *state, fuse_resume_fn_t fn);
-int is_gf_log_command (xlator_t *this, const char *name, char *value);
 int send_fuse_err (xlator_t *this, fuse_in_header_t *finh, int error);
 int fuse_gfid_set (fuse_state_t *state);
 #endif /* _GF_FUSE_BRIDGE_H_ */
diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c
index 9a6b135..edddb77 100644
--- a/xlators/mount/fuse/src/fuse-helpers.c
+++ b/xlators/mount/fuse/src/fuse-helpers.c
@@ -300,89 +300,4 @@  gf_fuse_stat2attr (struct iatt *st, struct fuse_attr *fa)
 }
 
 
-int
-is_gf_log_command (xlator_t *this, const char *name, char *value)
-{
-        fuse_private_t *priv        = NULL;
-        xlator_t       *trav        = NULL;
-        char            key[1024]   = {0,};
-        int             ret         = -1;
-        int             log_level   = -1;
-        gf_boolean_t    syslog_flag = 0;
-
-        priv = this->private;
-
-        if (!strcmp ("trusted.glusterfs.syslog", name)) {
-                ret = gf_string2boolean (value, &syslog_flag);
-                if (ret) {
-                        ret = EOPNOTSUPP;
-                        goto out;
-                }
-                if (syslog_flag)
-                        gf_log_enable_syslog ();
-                else
-                        gf_log_disable_syslog ();
-
-                goto out;
-        }
-
-        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;
-        }
-
-        if (log_level == -1) {
-                ret = EOPNOTSUPP;
-                goto out;
-        }
-
-        /* Some crude way to change the log-level of process */
-        if (!strcmp (name, "trusted.glusterfs.set-log-level")) {
-                /* */
-                gf_log ("glusterfs", gf_log_get_loglevel(),
-                        "setting log level to %d (old-value=%d)",
-                        log_level, gf_log_get_loglevel());
-                gf_log_set_loglevel (log_level);
-                ret = 0;
-                goto out;
-        }
-        if (!strcmp (name, "trusted.glusterfs.fuse.set-log-level")) {
-                /* */
-                gf_log (this->name, gf_log_get_xl_loglevel (this),
-                        "setting log level to %d (old-value=%d)",
-                        log_level, gf_log_get_xl_loglevel (this));
-                gf_log_set_xl_loglevel (this, log_level);
-                ret = 0;
-                goto out;
-        }
 
-        trav = priv->active_subvol;
-        while (trav) {
-                snprintf (key, 1024, "trusted.glusterfs.%s.set-log-level",
-                          trav->name);
-                if (fnmatch (name, key, FNM_NOESCAPE) == 0) {
-                        gf_log (trav->name, gf_log_get_xl_loglevel (trav),
-                                "setting log level to %d (old-value=%d)",
-                                log_level, gf_log_get_xl_loglevel (trav));
-                        gf_log_set_xl_loglevel (trav, log_level);
-                        ret = 0;
-                }
-                trav = trav->next;
-        }
-out:
-        return ret;
-}