Skip to contentSkip to conversation

watchdog: convert to QemuOpts

PATCH Superseded Paolo Bonzini 3 participants 7 messages May 27, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: convert to QemuOpts

This makes it possible to specify a watchdog action in a configuration file. The previous behavior of "-watchdog" is moved to the (implied) "-watchdog model" suboption. This is already more or less obsolete, since it is possible to achieve the same effect with "-device", but "-watchdog-action does not have an equivalent.

One alternative implementation is possible, namely to add an "action" property to the watchdog device. However, boards often have embedded watchdog devices; even if they currently don't, these should call watchdog_perform_action() so that they are affected by -watchdog-action. (This is listed in our BiteSizedTasks wiki page).

For these boards, "-watchdog action=foo" has two advantages:

1) it is much easier to use than a "-global" option, and can be configured globally for all boards.

2) it is harder to add a property to a device than it is to just s/qemu_system_reset_request/watchdog_perform_action/; in some cases, the devices are not even qdev-ified at all. The chance of the conversion happening then would basically be zero if one had to add a property as a prerequisite.

---
 docs/qdev-device-use.txt |  4 ++++
 qemu-options.hx          | 36 ++++++++++++++--------------
 vl.c                     | 61 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 68 insertions(+), 33 deletions(-)
docs/qdev-device-use.txt +4 -0
index 136d271..1906b7d 100644
@@ -365,6 +365,10 @@ The old way to define a guest watchdog device is -watchdog DEVNAME.
 The new way is -device DEVNAME.  For PCI devices, you can add
 bus=PCI-BUS,addr=DEVFN to control the PCI device address, as usual.
 
+No matter if you use -watchdog or -device to define the guest watchdog
+device, you can specify the watchdog action with "-watchdog-action ACTION"
+or "-watchdog action=ACTION".
+
 === Host Device Assignment ===
 
 QEMU supports assigning host PCI devices (qemu-kvm only at this time)
qemu-options.hx +19 -17
index ec356f6..719253c 100644
@@ -3115,12 +3115,19 @@ when the shift value is high (how high depends on the host machine).
 ETEXI
 
 DEF("watchdog", HAS_ARG, QEMU_OPTION_watchdog, \
-    "-watchdog i6300esb|ib700\n" \
-    "                enable virtual hardware watchdog [default=none]\n",
+    "-watchdog [model=]i6300esb|ib700,action=reset|shutdown|poweroff|pause|debug|none\n" \
+    "                enable virtual hardware watchdog (default: model=none,action=reset)\n",
+    QEMU_ARCH_ALL)
+DEF("watchdog-action", HAS_ARG, QEMU_OPTION_watchdog_action, \
+    "-watchdog-action reset|shutdown|poweroff|pause|debug|none\n" \
+    "                action when watchdog fires (default: reset)\n",
     QEMU_ARCH_ALL)
 STEXI
-@item -watchdog @var{model}
+@item -watchdog [model=]@var{model},action=@var{action}
 @findex -watchdog
+@itemx -watchdog-action @var{action}
+@findex -watchdog-action
+
 Create a virtual hardware watchdog device.  Once enabled (by a guest
 action), the watchdog must be periodically polled by an agent inside
 the guest or else the guest will be restarted.
@@ -3129,22 +3136,16 @@ The @var{model} is the model of hardware watchdog to emulate.  Choices
 for model are: @code{ib700} (iBASE 700) which is a very simple ISA
 watchdog with a single timer, or @code{i6300esb} (Intel 6300ESB I/O
 controller hub) which is a much more featureful PCI-based dual-timer
-watchdog.  Choose a model for which your guest has drivers.
-
-Use @code{-watchdog help} to list available hardware models.  Only one
+watchdog.  Choose a model for which your guest has drivers;
+use @code{-watchdog help} to list available hardware models.  Only one
 watchdog can be enabled for a guest.
-ETEXI
-
-DEF("watchdog-action", HAS_ARG, QEMU_OPTION_watchdog_action, \
-    "-watchdog-action reset|shutdown|poweroff|pause|debug|none\n" \
-    "                action when watchdog fires [default=reset]\n",
-    QEMU_ARCH_ALL)
-STEXI
-@item -watchdog-action @var{action}
-@findex -watchdog-action
 
 The @var{action} controls what QEMU will do when the watchdog timer
-expires.
+expires.  It can be specified directly in the @option{-watchdog} option,
+or as the argument of a separate @option{-watchdog-action} parameter.
+The effect is the same.  The watchdog action can be specified even if
+the watchdog is enabled through the @option{-device} option.
+
 The default is
 @code{reset} (forcefully reset the guest).
 Other possible actions are:
@@ -3162,8 +3163,9 @@ situations where the watchdog would have expired, and thus
 Examples:
 
 @table @code
-@item -watchdog i6300esb -watchdog-action pause
+@item -watchdog i6300esb,action=pause
 @item -watchdog ib700
+@item -device ib700 -watchdog action=poweroff
 @end table
 ETEXI
 
vl.c +45 -16

106 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw

vl.c int main(int argc, char **argv, char **envp) · line 3386

Quoted 10 lines · Paolo Bonzini

case QEMU_OPTION_watchdog:

vl.c +4 -4
-                if (watchdog) {
-                    fprintf(stderr,
-                            "qemu: only one watchdog option may be given\n");
-                    return 1;
+                olist = qemu_find_opts("watchdog");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
                 }

Is there an error message missing (before the call to exit)?

Patch seems OK otherwise.

libvirt still uses

-watchdog <model> -watchdog-action <action>

Should it be changed to use -device? I'm guessing for backwards compatibility with old and current qemu it probably shouldn't be changed for a few years.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
#2 lore raw
Quoted 16 lines · Richard W.M. Jones

vl.c int main(int argc, char **argv, char **envp) · line 3386

Quoted 10 lines · Paolo Bonzini

case QEMU_OPTION_watchdog:

vl.c +4 -4
-                if (watchdog) {
-                    fprintf(stderr,
-                            "qemu: only one watchdog option may be given\n");
-                    return 1;
+                olist = qemu_find_opts("watchdog");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
                 }

Is there an error message missing (before the call to exit)?

Patch seems OK otherwise.

Quoted 7 lines

libvirt still uses

-watchdog <model> -watchdog-action <action>

Should it be changed to use -device? I'm guessing for backwards compatibility with old and current qemu it probably shouldn't be changed for a few years.

-device has been working forever for watchdogs. Changing libvirt to -device would be possible, but cosmetic. Changing to "-watchdog action=foo" is also entirely cosmetic, and would not work on older QEMUs, so again there's no need.

The advantage of this patch would be for -readconfig users, which couldn't specify the watchdog action. Or you could put '[watchdog] action="pause"' in /etc/qemu/qemu.conf if you're into obscure configuration files.

Paolo

#3 lore raw
In reply to Richard W.M. Jones
Quoted 10 lines · Richard W.M. Jones
Quoted 9 lines

vl.c int main(int argc, char **argv, char **envp) · line 3386

Quoted 9 lines
vl.c +4 -4
-                if (watchdog) {
-                    fprintf(stderr,
-                            "qemu: only one watchdog option may be given\n");
-                    return 1;
+                olist = qemu_find_opts("watchdog");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
                 }

Is there an error message missing (before the call to exit)?

Oh, I forgot to answer this. Any error message is printed by qemu_opts_parse, for example:

$ x86_64-softmmu/qemu-system-x86_64 -watchdog foo=bar
qemu-system-x86_64: -watchdog foo=bar: Invalid parameter 'foo'

Paolo

#4 lore raw
Quoted 12 lines · Paolo Bonzini
Quoted 9 lines · Richard W.M. Jones
Quoted 9 lines
Quoted 9 lines
vl.c +4 -4
-                if (watchdog) {
-                    fprintf(stderr,
-                            "qemu: only one watchdog option may be given\n");
-                    return 1;
+                olist = qemu_find_opts("watchdog");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
                 }
Quoted 7 lines
Quoted 1 line

Is there an error message missing (before the call to exit)?

Oh, I forgot to answer this. Any error message is printed by qemu_opts_parse, for example:

$ x86_64-softmmu/qemu-system-x86_64 -watchdog foo=bar
qemu-system-x86_64: -watchdog foo=bar: Invalid parameter 'foo'

Patch seems fine then, ACK.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org
#5 lore raw
In reply to Paolo Bonzini
Quoted 33 lines · Paolo Bonzini

This makes it possible to specify a watchdog action in a configuration file. The previous behavior of "-watchdog" is moved to the (implied) "-watchdog model" suboption. This is already more or less obsolete, since it is possible to achieve the same effect with "-device", but "-watchdog-action does not have an equivalent.

One alternative implementation is possible, namely to add an "action" property to the watchdog device. However, boards often have embedded watchdog devices; even if they currently don't, these should call watchdog_perform_action() so that they are affected by -watchdog-action. (This is listed in our BiteSizedTasks wiki page).

For these boards, "-watchdog action=foo" has two advantages:

1) it is much easier to use than a "-global" option, and can be configured globally for all boards.

2) it is harder to add a property to a device than it is to just s/qemu_system_reset_request/watchdog_perform_action/; in some cases, the devices are not even qdev-ified at all. The chance of the conversion happening then would basically be zero if one had to add a property as a prerequisite.

---
 docs/qdev-device-use.txt |  4 ++++
 qemu-options.hx          | 36 ++++++++++++++--------------
 vl.c                     | 61 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 68 insertions(+), 33 deletions(-)

+++ b/qemu-options.hx

qemu-options.hx when the shift value is high (how high depends on the host machine). · line 3118

Quoted 6 lines
qemu-options.hx +1 -2
@@ -3115,12 +3115,19 @@ when the shift value is high (how high depends on the host machine).
 ETEXI
 
 DEF("watchdog", HAS_ARG, QEMU_OPTION_watchdog, \
-    "-watchdog i6300esb|ib700\n" \
-    "                enable virtual hardware watchdog [default=none]\n",
+    "-watchdog [model=]i6300esb|ib700,action=reset|shutdown|poweroff|pause|debug|none\n" \

Should this be

-watchdog [model=]i6300esb|ib700[,action=...none]

to make it obvious that ,action= is optional for back-compat with old usage?

qemu-options.hx when the shift value is high (how high depends on the host machine). · line 3126

Quoted 9 lines
qemu-options.hx +6 -1
+    "                enable virtual hardware watchdog (default: model=none,action=reset)\n",
+    QEMU_ARCH_ALL)
+DEF("watchdog-action", HAS_ARG, QEMU_OPTION_watchdog_action, \
+    "-watchdog-action reset|shutdown|poweroff|pause|debug|none\n" \
+    "                action when watchdog fires (default: reset)\n",
     QEMU_ARCH_ALL)
 STEXI
-@item -watchdog @var{model}
+@item -watchdog [model=]@var{model},action=@var{action}

same here.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Quoted 6 lines · Eric Blake

Should this be

-watchdog [model=]i6300esb|ib700[,action=...none]

to make it obvious that ,action= is optional for back-compat with old usage?

Sure, but then it should be

-watchdog [[model=]i6300esb|ib700][,action=...none]

Paolo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJVZcB5AAoJEL/70l94x66DyZMIAJN5YCp+NwIxYMieIEssXDsG sZCyu3pv7RG8tx66VnExBXSUxMd4U4JXvDbME9g6jVPie3CNGXbkgE0f7BWAfBbi 1oA07px8Zx0xOMZIMWDJc803viSixHn/UJxFcN00baS+lx9l6a0yRt013Z0sFbNl 0TBSVpYUOM0JNo42QXuSiMClbxLE/DaSS4NO+2uPV9NV1USz3LDM+/bd7BKHmRsb JZhVPXYmmq/ZxSrb+UJprwJOqQ7yHqZeLU0IL76TrWGthRWfMZP7Dg6y5QZgR3cd cM00qERu4iIYH18TwA6jBdoPjgsHMDWvHuwLhrpqOcnl5KKu/F4rKjdXLOvfxHw= =XXtJ
-----END PGP SIGNATURE-----