qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] watchdog: Export watchdog actions list.
@ 2014-06-15 10:03 Hani Benhabiles
  2014-06-15 13:57 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Hani Benhabiles @ 2014-06-15 10:03 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial

Also, use it instead of using hard-coded values.

Signed-off-by: Hani Benhabiles <hani@linux.com>
---
Should have been part of the last monitor completion series, but better late
then never. :)

 hw/watchdog/watchdog.c    | 35 +++++++++++++++++++----------------
 include/sysemu/watchdog.h |  6 ++++++
 monitor.c                 | 19 ++++++++++++-------
 3 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
index f28161b..3bea6fe 100644
--- a/hw/watchdog/watchdog.c
+++ b/hw/watchdog/watchdog.c
@@ -39,6 +39,16 @@
 static int watchdog_action = WDT_RESET;
 static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
 
+struct watchdog_action watchdog_actions[] = {
+    { "reset",  WDT_RESET },
+    { "shutdown", WDT_SHUTDOWN },
+    { "poweroff", WDT_POWEROFF },
+    { "pause", WDT_PAUSE },
+    { "debug", WDT_DEBUG },
+    { "none", WDT_NONE },
+    { NULL, 0 },
+};
+
 void watchdog_add_model(WatchdogTimerModel *model)
 {
     QLIST_INSERT_HEAD(&watchdog_list, model, entry);
@@ -83,22 +93,15 @@ int select_watchdog(const char *p)
 
 int select_watchdog_action(const char *p)
 {
-    if (strcasecmp(p, "reset") == 0)
-        watchdog_action = WDT_RESET;
-    else if (strcasecmp(p, "shutdown") == 0)
-        watchdog_action = WDT_SHUTDOWN;
-    else if (strcasecmp(p, "poweroff") == 0)
-        watchdog_action = WDT_POWEROFF;
-    else if (strcasecmp(p, "pause") == 0)
-        watchdog_action = WDT_PAUSE;
-    else if (strcasecmp(p, "debug") == 0)
-        watchdog_action = WDT_DEBUG;
-    else if (strcasecmp(p, "none") == 0)
-        watchdog_action = WDT_NONE;
-    else
-        return -1;
-
-    return 0;
+    int i;
+
+    for (i = 0; watchdog_actions[i].name; i++) {
+        if (!strcasecmp(p, watchdog_actions[i].name)) {
+            watchdog_action = watchdog_actions[i].action;
+            return 0;
+        }
+    }
+    return -1;
 }
 
 static void watchdog_mon_event(const char *action)
diff --git a/include/sysemu/watchdog.h b/include/sysemu/watchdog.h
index 3e9a970..2bfe2fc 100644
--- a/include/sysemu/watchdog.h
+++ b/include/sysemu/watchdog.h
@@ -34,6 +34,12 @@ struct WatchdogTimerModel {
 };
 typedef struct WatchdogTimerModel WatchdogTimerModel;
 
+struct watchdog_action {
+    const char *name;
+    int action;
+};
+extern struct watchdog_action watchdog_actions[];
+
 /* in hw/watchdog.c */
 int select_watchdog(const char *p);
 int select_watchdog_action(const char *action);
diff --git a/monitor.c b/monitor.c
index ee9390f..57d23c6 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4562,16 +4562,21 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
 
 void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
 {
+    int i;
+    size_t len;
+
     if (nb_args != 2) {
         return;
     }
-    readline_set_completion_index(rs, strlen(str));
-    add_completion_option(rs, str, "reset");
-    add_completion_option(rs, str, "shutdown");
-    add_completion_option(rs, str, "poweroff");
-    add_completion_option(rs, str, "pause");
-    add_completion_option(rs, str, "debug");
-    add_completion_option(rs, str, "none");
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    for (i = 0; watchdog_actions[i].name; i++) {
+        const char *name = watchdog_actions[i].name;
+
+        if (!strncmp(str, name, len)) {
+            readline_add_completion(rs, name);
+        }
+    }
 }
 
 void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] watchdog: Export watchdog actions list.
  2014-06-15 10:03 [Qemu-devel] [PATCH] watchdog: Export watchdog actions list Hani Benhabiles
@ 2014-06-15 13:57 ` Paolo Bonzini
  2014-06-15 14:32   ` Hani Benhabiles
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2014-06-15 13:57 UTC (permalink / raw)
  To: Hani Benhabiles, qemu-devel, qemu-trivial

Il 15/06/2014 12:03, Hani Benhabiles ha scritto:
> Also, use it instead of using hard-coded values.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
> Should have been part of the last monitor completion series, but better late
> then never. :)
>
>  hw/watchdog/watchdog.c    | 35 +++++++++++++++++++----------------
>  include/sysemu/watchdog.h |  6 ++++++
>  monitor.c                 | 19 ++++++++++++-------
>  3 files changed, 37 insertions(+), 23 deletions(-)
>
> diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
> index f28161b..3bea6fe 100644
> --- a/hw/watchdog/watchdog.c
> +++ b/hw/watchdog/watchdog.c
> @@ -39,6 +39,16 @@
>  static int watchdog_action = WDT_RESET;
>  static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
>
> +struct watchdog_action watchdog_actions[] = {
> +    { "reset",  WDT_RESET },
> +    { "shutdown", WDT_SHUTDOWN },
> +    { "poweroff", WDT_POWEROFF },
> +    { "pause", WDT_PAUSE },
> +    { "debug", WDT_DEBUG },
> +    { "none", WDT_NONE },
> +    { NULL, 0 },
> +};

The QAPI event series instead used a QAPI enum and renamed this to 
something like WATCHDOG_ACTION_{RESET,SHUTDOWN,...} at the same time.

I guess we can wait for those patches to go in.

Paolo

>  void watchdog_add_model(WatchdogTimerModel *model)
>  {
>      QLIST_INSERT_HEAD(&watchdog_list, model, entry);
> @@ -83,22 +93,15 @@ int select_watchdog(const char *p)
>
>  int select_watchdog_action(const char *p)
>  {
> -    if (strcasecmp(p, "reset") == 0)
> -        watchdog_action = WDT_RESET;
> -    else if (strcasecmp(p, "shutdown") == 0)
> -        watchdog_action = WDT_SHUTDOWN;
> -    else if (strcasecmp(p, "poweroff") == 0)
> -        watchdog_action = WDT_POWEROFF;
> -    else if (strcasecmp(p, "pause") == 0)
> -        watchdog_action = WDT_PAUSE;
> -    else if (strcasecmp(p, "debug") == 0)
> -        watchdog_action = WDT_DEBUG;
> -    else if (strcasecmp(p, "none") == 0)
> -        watchdog_action = WDT_NONE;
> -    else
> -        return -1;
> -
> -    return 0;
> +    int i;
> +
> +    for (i = 0; watchdog_actions[i].name; i++) {
> +        if (!strcasecmp(p, watchdog_actions[i].name)) {
> +            watchdog_action = watchdog_actions[i].action;
> +            return 0;
> +        }
> +    }
> +    return -1;
>  }
>
>  static void watchdog_mon_event(const char *action)
> diff --git a/include/sysemu/watchdog.h b/include/sysemu/watchdog.h
> index 3e9a970..2bfe2fc 100644
> --- a/include/sysemu/watchdog.h
> +++ b/include/sysemu/watchdog.h
> @@ -34,6 +34,12 @@ struct WatchdogTimerModel {
>  };
>  typedef struct WatchdogTimerModel WatchdogTimerModel;
>
> +struct watchdog_action {
> +    const char *name;
> +    int action;
> +};
> +extern struct watchdog_action watchdog_actions[];
> +
>  /* in hw/watchdog.c */
>  int select_watchdog(const char *p);
>  int select_watchdog_action(const char *action);
> diff --git a/monitor.c b/monitor.c
> index ee9390f..57d23c6 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4562,16 +4562,21 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
>
>  void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
>  {
> +    int i;
> +    size_t len;
> +
>      if (nb_args != 2) {
>          return;
>      }
> -    readline_set_completion_index(rs, strlen(str));
> -    add_completion_option(rs, str, "reset");
> -    add_completion_option(rs, str, "shutdown");
> -    add_completion_option(rs, str, "poweroff");
> -    add_completion_option(rs, str, "pause");
> -    add_completion_option(rs, str, "debug");
> -    add_completion_option(rs, str, "none");
> +    len = strlen(str);
> +    readline_set_completion_index(rs, len);
> +    for (i = 0; watchdog_actions[i].name; i++) {
> +        const char *name = watchdog_actions[i].name;
> +
> +        if (!strncmp(str, name, len)) {
> +            readline_add_completion(rs, name);
> +        }
> +    }
>  }
>
>  void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] watchdog: Export watchdog actions list.
  2014-06-15 13:57 ` Paolo Bonzini
@ 2014-06-15 14:32   ` Hani Benhabiles
  0 siblings, 0 replies; 3+ messages in thread
From: Hani Benhabiles @ 2014-06-15 14:32 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-trivial, qemu-devel

On Sun, Jun 15, 2014 at 03:57:46PM +0200, Paolo Bonzini wrote:
> Il 15/06/2014 12:03, Hani Benhabiles ha scritto:
> >Also, use it instead of using hard-coded values.
> >
> >Signed-off-by: Hani Benhabiles <hani@linux.com>
> >---
> >Should have been part of the last monitor completion series, but better late
> >then never. :)
> >
> > hw/watchdog/watchdog.c    | 35 +++++++++++++++++++----------------
> > include/sysemu/watchdog.h |  6 ++++++
> > monitor.c                 | 19 ++++++++++++-------
> > 3 files changed, 37 insertions(+), 23 deletions(-)
> >
> >diff --git a/hw/watchdog/watchdog.c b/hw/watchdog/watchdog.c
> >index f28161b..3bea6fe 100644
> >--- a/hw/watchdog/watchdog.c
> >+++ b/hw/watchdog/watchdog.c
> >@@ -39,6 +39,16 @@
> > static int watchdog_action = WDT_RESET;
> > static QLIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
> >
> >+struct watchdog_action watchdog_actions[] = {
> >+    { "reset",  WDT_RESET },
> >+    { "shutdown", WDT_SHUTDOWN },
> >+    { "poweroff", WDT_POWEROFF },
> >+    { "pause", WDT_PAUSE },
> >+    { "debug", WDT_DEBUG },
> >+    { "none", WDT_NONE },
> >+    { NULL, 0 },
> >+};
> 
> The QAPI event series instead used a QAPI enum and renamed this to something
> like WATCHDOG_ACTION_{RESET,SHUTDOWN,...} at the same time.
> 
> I guess we can wait for those patches to go in.

Sounds alright to me. Will wait for them.

> 
> Paolo
> 
> > void watchdog_add_model(WatchdogTimerModel *model)
> > {
> >     QLIST_INSERT_HEAD(&watchdog_list, model, entry);
> >@@ -83,22 +93,15 @@ int select_watchdog(const char *p)
> >
> > int select_watchdog_action(const char *p)
> > {
> >-    if (strcasecmp(p, "reset") == 0)
> >-        watchdog_action = WDT_RESET;
> >-    else if (strcasecmp(p, "shutdown") == 0)
> >-        watchdog_action = WDT_SHUTDOWN;
> >-    else if (strcasecmp(p, "poweroff") == 0)
> >-        watchdog_action = WDT_POWEROFF;
> >-    else if (strcasecmp(p, "pause") == 0)
> >-        watchdog_action = WDT_PAUSE;
> >-    else if (strcasecmp(p, "debug") == 0)
> >-        watchdog_action = WDT_DEBUG;
> >-    else if (strcasecmp(p, "none") == 0)
> >-        watchdog_action = WDT_NONE;
> >-    else
> >-        return -1;
> >-
> >-    return 0;
> >+    int i;
> >+
> >+    for (i = 0; watchdog_actions[i].name; i++) {
> >+        if (!strcasecmp(p, watchdog_actions[i].name)) {
> >+            watchdog_action = watchdog_actions[i].action;
> >+            return 0;
> >+        }
> >+    }
> >+    return -1;
> > }
> >
> > static void watchdog_mon_event(const char *action)
> >diff --git a/include/sysemu/watchdog.h b/include/sysemu/watchdog.h
> >index 3e9a970..2bfe2fc 100644
> >--- a/include/sysemu/watchdog.h
> >+++ b/include/sysemu/watchdog.h
> >@@ -34,6 +34,12 @@ struct WatchdogTimerModel {
> > };
> > typedef struct WatchdogTimerModel WatchdogTimerModel;
> >
> >+struct watchdog_action {
> >+    const char *name;
> >+    int action;
> >+};
> >+extern struct watchdog_action watchdog_actions[];
> >+
> > /* in hw/watchdog.c */
> > int select_watchdog(const char *p);
> > int select_watchdog_action(const char *action);
> >diff --git a/monitor.c b/monitor.c
> >index ee9390f..57d23c6 100644
> >--- a/monitor.c
> >+++ b/monitor.c
> >@@ -4562,16 +4562,21 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
> >
> > void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
> > {
> >+    int i;
> >+    size_t len;
> >+
> >     if (nb_args != 2) {
> >         return;
> >     }
> >-    readline_set_completion_index(rs, strlen(str));
> >-    add_completion_option(rs, str, "reset");
> >-    add_completion_option(rs, str, "shutdown");
> >-    add_completion_option(rs, str, "poweroff");
> >-    add_completion_option(rs, str, "pause");
> >-    add_completion_option(rs, str, "debug");
> >-    add_completion_option(rs, str, "none");
> >+    len = strlen(str);
> >+    readline_set_completion_index(rs, len);
> >+    for (i = 0; watchdog_actions[i].name; i++) {
> >+        const char *name = watchdog_actions[i].name;
> >+
> >+        if (!strncmp(str, name, len)) {
> >+            readline_add_completion(rs, name);
> >+        }
> >+    }
> > }
> >
> > void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
> >
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-15 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-15 10:03 [Qemu-devel] [PATCH] watchdog: Export watchdog actions list Hani Benhabiles
2014-06-15 13:57 ` Paolo Bonzini
2014-06-15 14:32   ` Hani Benhabiles

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).