diff mbox

[v2,1/5] xen/console: consolidate log levels to an array

Message ID 1467645206-28142-2-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu July 4, 2016, 3:13 p.m. UTC
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(-)

Comments

Wei Liu July 4, 2016, 3:28 p.m. UTC | #1
On Mon, Jul 04, 2016 at 04:13:22PM +0100, Wei Liu wrote:
> 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;

This should be int instead of unsigned int.

Wei.
Jan Beulich July 7, 2016, 10:39 a.m. UTC | #2
>>> On 04.07.16 at 17:13, <wei.liu2@citrix.com> wrote:
> --- 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[] = {

const ... __initconstrel

But the question really is, as Ian had already indicated, whether this
can't be solved with less hypervisor changes (in the second patch).
And jftr - I did consider passing strings as part of the hypercall
arguments, but I generally dislike non-human interfaces taking human
readable strings.

Jan
diff mbox

Patch

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 */
 }