Blob Blame History Raw
From 1fb696dfda55579f323f53141b40b9e847723755 Mon Sep 17 00:00:00 2001
Message-Id: <1fb696dfda55579f323f53141b40b9e847723755.1387385061.git.jdenemar@redhat.com>
From: Hu Tao <hutao@cn.fujitsu.com>
Date: Mon, 16 Dec 2013 11:58:22 -0700
Subject: [PATCH] qemu: add support for -device pvpanic

RHEL 7.0: https://bugzilla.redhat.com/show_bug.cgi?id=996520

Map the new <panic> device in XML to the '-device pvpanic' command
line of qemu.  Clients can then couple the <panic> device and the
<on_crash> directive to control behavior when the guest reports
a panic to qemu.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 4d18758df88c7b1b646cab37979667a19f858a9c)

Conflicts:
	src/qemu/qemu_capabilities.c - skipped other upstream capabilities
	src/qemu/qemu_capabilities.h - likewise
	tests/qemucapabilitiesdata/caps_1.5.3-1.caps - new upstream test not backported
	tests/qemucapabilitiesdata/caps_1.6.0-1.caps - likewise
	tests/qemucapabilitiesdata/caps_1.6.50-1.caps - likewise
	tests/qemuxml2argvtest.c - context of upstream tests not backported
	tests/qemuxml2xmltest.c - likewise
	tests/qemuxml2argvdata/qemuxml2argv-panic.args - QEMU_AUDIO_DRV changes not backported
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_capabilities.c                   |  4 ++++
 src/qemu/qemu_capabilities.h                   |  8 +++++--
 src/qemu/qemu_command.c                        | 16 +++++++++++++
 tests/qemuxml2argvdata/qemuxml2argv-panic.args |  6 +++++
 tests/qemuxml2argvdata/qemuxml2argv-panic.xml  | 31 ++++++++++++++++++++++++++
 tests/qemuxml2argvtest.c                       |  3 +++
 tests/qemuxml2xmltest.c                        |  2 ++
 7 files changed, 68 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-panic.xml

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9e0e597..ba17cce 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -235,8 +235,11 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
               "vnc-share-policy", /* 150 */
               "device-del-event",
               "dmi-to-pci-bridge",
+
+              /* RHEL backports below here */
               "ich9-intel-hda",
               "boot-strict",
+              "pvpanic",
     );
 
 struct _virQEMUCaps {
@@ -1386,6 +1389,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
     { "scsi-generic", QEMU_CAPS_DEVICE_SCSI_GENERIC },
     { "i82801b11-bridge", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE },
     { "ich9-intel-hda", QEMU_CAPS_DEVICE_ICH9_INTEL_HDA },
+    { "pvpanic", QEMU_CAPS_DEVICE_PANIC },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 7113185..dea1e13 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -191,8 +191,12 @@ enum virQEMUCapsFlags {
     QEMU_CAPS_VNC_SHARE_POLICY   = 150, /* set display sharing policy */
     QEMU_CAPS_DEVICE_DEL_EVENT   = 151, /* DEVICE_DELETED event */
     QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE  = 152, /* -device i82801b11-bridge */
-    QEMU_CAPS_DEVICE_ICH9_INTEL_HDA = 153, /* -device ich9-intel-hda */
-    QEMU_CAPS_BOOT_STRICT        = 154, /* -boot strict */
+
+    /* RHEL backports below here; since we are cherry-picking out of
+     * order, we no longer track enum values in order. */
+    QEMU_CAPS_DEVICE_ICH9_INTEL_HDA,    /* -device ich9-intel-hda */
+    QEMU_CAPS_BOOT_STRICT,              /* -boot strict */
+    QEMU_CAPS_DEVICE_PANIC,             /* -device pvpanic */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4458f9a..35355b7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -9370,6 +9370,22 @@ qemuBuildCommandLine(virConnectPtr conn,
         goto error;
     }
 
+    if (def->panic) {
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PANIC)) {
+            if (def->panic->info.addr.isa.iobase > 0) {
+                virCommandAddArg(cmd, "-device");
+                virCommandAddArgFormat(cmd, "pvpanic,ioport=%d",
+                                       def->panic->info.addr.isa.iobase);
+            } else {
+                virCommandAddArgList(cmd, "-device", "pvpanic", NULL);
+            }
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("your QEMU is too old to support pvpanic"));
+            goto error;
+        }
+    }
+
     if (mlock) {
         unsigned long long memKB;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic.args b/tests/qemuxml2argvdata/qemuxml2argv-panic.args
new file mode 100644
index 0000000..dba0739
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-panic.args
@@ -0,0 +1,6 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \
+/usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb \
+-hda /dev/HostVG/QEMUGuest1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-device pvpanic,ioport=1285
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-panic.xml b/tests/qemuxml2argvdata/qemuxml2argv-panic.xml
new file mode 100644
index 0000000..e354511
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-panic.xml
@@ -0,0 +1,31 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='fdc' index='0'/>
+    <controller type='ide' index='0'/>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='virtio'/>
+    <panic>
+      <address type='isa' iobase='0x505'/>
+    </panic>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1beb49f..790d610 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1062,6 +1062,9 @@ mymain(void)
     DO_TEST_PARSE_ERROR("pci-root-address",
                         QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE);
 
+    DO_TEST("panic", QEMU_CAPS_DEVICE_PANIC,
+            QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+
     virObjectUnref(driver.config);
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 4b6b01d..1f655ef 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -315,6 +315,8 @@ mymain(void)
 
     DO_TEST_DIFFERENT("s390-defaultconsole");
 
+    DO_TEST("panic");
+
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);
 
-- 
1.8.5.1