xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v2 1/5] xen/console: consolidate log levels to an array
Date: Mon, 4 Jul 2016 16:13:22 +0100	[thread overview]
Message-ID: <1467645206-28142-2-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1467645206-28142-1-git-send-email-wei.liu2@citrix.com>

It cleaner than open-coding strings and numbers. The array will also
become handy later when we need to refactor things a bit.

No functional change.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
---
 xen/drivers/char/console.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 650035d..6620a1c 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -139,6 +139,20 @@ custom_param("guest_loglvl", parse_guest_loglvl);
 
 static atomic_t print_everything = ATOMIC_INIT(0);
 
+struct log_level {
+    const char *str;
+    unsigned int num;
+};
+
+static struct log_level __initdata log_levels[] = {
+    { "none",    0 },
+    { "error",   1 },
+    { "warning", 2 },
+    { "info",    3 },
+    { "debug",   4 },
+    { "all",     4 },
+};
+
 #define ___parse_loglvl(s, ps, lvlstr, lvlnum)          \
     if ( !strncmp((s), (lvlstr), strlen(lvlstr)) ) {    \
         *(ps) = (s) + strlen(lvlstr);                   \
@@ -147,12 +161,11 @@ static atomic_t print_everything = ATOMIC_INIT(0);
 
 static int __init __parse_loglvl(char *s, char **ps)
 {
-    ___parse_loglvl(s, ps, "none",    0);
-    ___parse_loglvl(s, ps, "error",   1);
-    ___parse_loglvl(s, ps, "warning", 2);
-    ___parse_loglvl(s, ps, "info",    3);
-    ___parse_loglvl(s, ps, "debug",   4);
-    ___parse_loglvl(s, ps, "all",     4);
+    unsigned int i;
+
+    for ( i = 0; i < ARRAY_SIZE(log_levels); i++ )
+        ___parse_loglvl(s, ps, log_levels[i].str, log_levels[i].num);
+
     return 2; /* sane fallback */
 }
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2016-07-04 15:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04 15:13 [PATCH v2 0/5] Allow runtime adjustment to log level thresholds Wei Liu
2016-07-04 15:13 ` Wei Liu [this message]
2016-07-04 15:28   ` [PATCH v2 1/5] xen/console: consolidate log levels to an array Wei Liu
2016-07-07 10:39   ` Jan Beulich
2016-07-04 15:13 ` [PATCH v2 2/5] xen/console: allow log level threshold adjustments Wei Liu
2016-07-05 17:52   ` Daniel De Graaf
2016-07-06 11:14   ` Ian Jackson
2016-07-07 11:51   ` Jan Beulich
2016-07-04 15:13 ` [PATCH v2 3/5] libxc: wrapper for log level sysctl Wei Liu
2016-07-06 11:11   ` Ian Jackson
2016-07-04 15:13 ` [PATCH v2 4/5] libxl: introduce APIs to get and set log level Wei Liu
2016-07-06 11:15   ` Ian Jackson
2016-07-04 15:13 ` [PATCH v2 5/5] xl: new loglvl command Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467645206-28142-2-git-send-email-wei.liu2@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).