Răsfoiți Sursa

watchdog: remove select_watchdog_action

Instead of invoking select_watchdog_action from both HMP and command line,
go directly from HMP to QMP and use QemuOpts as the intermediary for the
command line.

This makes -watchdog-action explicitly a shortcut for "-action watchdog",
so that "-watchdog-action" and "-action watchdog" override each other
based on the position on the command line; previously, "-action watchdog"
always won.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 3 ani în urmă
părinte
comite
22afb46e7c
4 a modificat fișierele cu 17 adăugiri și 23 ștergeri
  1. 0 14
      hw/watchdog/watchdog.c
  2. 0 1
      include/sysemu/watchdog.h
  3. 12 3
      monitor/misc.c
  4. 5 5
      softmmu/vl.c

+ 0 - 14
hw/watchdog/watchdog.c

@@ -76,20 +76,6 @@ int select_watchdog(const char *p)
     return 1;
     return 1;
 }
 }
 
 
-int select_watchdog_action(const char *p)
-{
-    int action;
-    char *qapi_value;
-
-    qapi_value = g_ascii_strdown(p, -1);
-    action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, NULL);
-    g_free(qapi_value);
-    if (action < 0)
-        return -1;
-    qmp_watchdog_set_action(action, &error_abort);
-    return 0;
-}
-
 WatchdogAction get_watchdog_action(void)
 WatchdogAction get_watchdog_action(void)
 {
 {
     return watchdog_action;
     return watchdog_action;

+ 0 - 1
include/sysemu/watchdog.h

@@ -37,7 +37,6 @@ typedef struct WatchdogTimerModel WatchdogTimerModel;
 
 
 /* in hw/watchdog.c */
 /* in hw/watchdog.c */
 int select_watchdog(const char *p);
 int select_watchdog(const char *p);
-int select_watchdog_action(const char *action);
 WatchdogAction get_watchdog_action(void);
 WatchdogAction get_watchdog_action(void);
 void watchdog_add_model(WatchdogTimerModel *model);
 void watchdog_add_model(WatchdogTimerModel *model);
 void watchdog_perform_action(void);
 void watchdog_perform_action(void);

+ 12 - 3
monitor/misc.c

@@ -70,6 +70,7 @@
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-misc.h"
 #include "qapi/qapi-commands-qom.h"
 #include "qapi/qapi-commands-qom.h"
+#include "qapi/qapi-commands-run-state.h"
 #include "qapi/qapi-commands-trace.h"
 #include "qapi/qapi-commands-trace.h"
 #include "qapi/qapi-init-commands.h"
 #include "qapi/qapi-init-commands.h"
 #include "qapi/error.h"
 #include "qapi/error.h"
@@ -471,10 +472,18 @@ static void hmp_gdbserver(Monitor *mon, const QDict *qdict)
 
 
 static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
 static void hmp_watchdog_action(Monitor *mon, const QDict *qdict)
 {
 {
-    const char *action = qdict_get_str(qdict, "action");
-    if (select_watchdog_action(action) == -1) {
-        monitor_printf(mon, "Unknown watchdog action '%s'\n", action);
+    Error *err = NULL;
+    WatchdogAction action;
+    char *qapi_value;
+
+    qapi_value = g_ascii_strdown(qdict_get_str(qdict, "action"), -1);
+    action = qapi_enum_parse(&WatchdogAction_lookup, qapi_value, -1, &err);
+    g_free(qapi_value);
+    if (err) {
+        hmp_handle_error(mon, err);
+        return;
     }
     }
+    qmp_watchdog_set_action(action, &error_abort);
 }
 }
 
 
 static void monitor_printc(Monitor *mon, int c)
 static void monitor_printc(Monitor *mon, int c)

+ 5 - 5
softmmu/vl.c

@@ -3265,12 +3265,12 @@ void qemu_init(int argc, char **argv, char **envp)
                      exit(1);
                      exit(1);
                 }
                 }
                 break;
                 break;
-            case QEMU_OPTION_watchdog_action:
-                if (select_watchdog_action(optarg) == -1) {
-                    error_report("unknown -watchdog-action parameter");
-                    exit(1);
-                }
+            case QEMU_OPTION_watchdog_action: {
+                QemuOpts *opts;
+                opts = qemu_opts_create(qemu_find_opts("action"), NULL, 0, &error_abort);
+                qemu_opt_set(opts, "watchdog", optarg, &error_abort);
                 break;
                 break;
+            }
             case QEMU_OPTION_parallel:
             case QEMU_OPTION_parallel:
                 add_device_config(DEV_PARALLEL, optarg);
                 add_device_config(DEV_PARALLEL, optarg);
                 default_parallel = 0;
                 default_parallel = 0;