render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
404507
From b66931b0282f0209a262854b54b590d008070f85 Mon Sep 17 00:00:00 2001
404507
Message-Id: <b66931b0282f0209a262854b54b590d008070f85@dist-git>
404507
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
404507
Date: Wed, 29 Nov 2017 17:00:04 +0100
404507
Subject: [PATCH] qemu: add vmcoreinfo support
404507
MIME-Version: 1.0
404507
Content-Type: text/plain; charset=UTF-8
404507
Content-Transfer-Encoding: 8bit
404507
404507
Starting from qemu 2.11, the `-device vmcoreinfo` will create a fw_cfg
404507
entry for a guest to store dump details, necessary to process kernel
404507
dump with KASLR enabled and providing additional kernel details.
404507
404507
In essence, it is similar to -fw_cfg name=etc/vmcoreinfo,file=X but in
404507
this case it is not backed by a file, but collected by QEMU itself.
404507
404507
Since the device is a singleton and shouldn't use additional hardware
404507
resources, it is presented as a <feature> element in the libvirt
404507
domain XML.
404507
404507
The device is arm/x86 only for now (targets that support fw_cfg+dma).
404507
404507
Related to:
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1395248
404507
404507
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
404507
(cherry picked from commit 7e4177a35bae49a53b04940be04418daaa988734)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 docs/formatdomain.html.in                          |  4 +++
404507
 docs/schemas/domaincommon.rng                      |  9 +++++
404507
 src/conf/domain_conf.c                             |  3 ++
404507
 src/conf/domain_conf.h                             |  1 +
404507
 src/qemu/qemu_capabilities.c                       |  3 +-
404507
 src/qemu/qemu_capabilities.h                       |  2 +-
404507
 src/qemu/qemu_command.c                            | 25 ++++++++++++++
404507
 .../qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args  | 25 ++++++++++++++
404507
 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml | 28 ++++++++++++++++
404507
 tests/qemuxml2argvtest.c                           |  1 +
404507
 .../qemuxml2xmlout-vmcoreinfo.xml                  | 38 ++++++++++++++++++++++
404507
 tests/qemuxml2xmltest.c                            |  1 +
404507
 12 files changed, 138 insertions(+), 2 deletions(-)
404507
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
404507
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
404507
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
404507
404507
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
404507
index cc1c5577cd..6807da5c6f 100644
404507
--- a/docs/formatdomain.html.in
404507
+++ b/docs/formatdomain.html.in
404507
@@ -1940,6 +1940,10 @@
404507
           which is also known as a split I/O APIC mode.
404507
           Since 3.4.0 (QEMU/KVM only)
404507
       
404507
+      
vmcoreinfo
404507
+      
Enable QEMU vmcoreinfo device to let the guest kernel save debug
404507
+          details. Since 3.10.0 (QEMU only)
404507
+      
404507
     
404507
 
404507
     

Time keeping

404507
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
404507
index 5576128db5..05709afc0c 100644
404507
--- a/docs/schemas/domaincommon.rng
404507
+++ b/docs/schemas/domaincommon.rng
404507
@@ -4747,6 +4747,9 @@
404507
           <optional>
404507
             <ref name="hpt"/>
404507
           </optional>
404507
+          <optional>
404507
+            <ref name="vmcoreinfo"/>
404507
+          </optional>
404507
         </interleave>
404507
       </element>
404507
     </optional>
404507
@@ -4947,6 +4950,12 @@
404507
     </element>
404507
   </define>
404507
 
404507
+  <define name="vmcoreinfo">
404507
+    <element name="vmcoreinfo">
404507
+      <empty/>
404507
+    </element>
404507
+  </define>
404507
+
404507
   <define name="address">
404507
     <element name="address">
404507
       <choice>
404507
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
404507
index bd6d851f21..2d54037b71 100644
404507
--- a/src/conf/domain_conf.c
404507
+++ b/src/conf/domain_conf.c
404507
@@ -150,6 +150,7 @@ VIR_ENUM_IMPL(virDomainFeature, VIR_DOMAIN_FEATURE_LAST,
404507
               "smm",
404507
               "ioapic",
404507
               "hpt",
404507
+              "vmcoreinfo",
404507
 );
404507
 
404507
 VIR_ENUM_IMPL(virDomainCapabilitiesPolicy, VIR_DOMAIN_CAPABILITIES_POLICY_LAST,
404507
@@ -18824,6 +18825,7 @@ virDomainDefParseXML(xmlDocPtr xml,
404507
         case VIR_DOMAIN_FEATURE_VIRIDIAN:
404507
         case VIR_DOMAIN_FEATURE_PRIVNET:
404507
         case VIR_DOMAIN_FEATURE_HYPERV:
404507
+        case VIR_DOMAIN_FEATURE_VMCOREINFO:
404507
         case VIR_DOMAIN_FEATURE_KVM:
404507
             def->features[val] = VIR_TRISTATE_SWITCH_ON;
404507
             break;
404507
@@ -26265,6 +26267,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
404507
             case VIR_DOMAIN_FEATURE_ACPI:
404507
             case VIR_DOMAIN_FEATURE_PAE:
404507
             case VIR_DOMAIN_FEATURE_VIRIDIAN:
404507
+            case VIR_DOMAIN_FEATURE_VMCOREINFO:
404507
             case VIR_DOMAIN_FEATURE_PRIVNET:
404507
                 switch ((virTristateSwitch) def->features[i]) {
404507
                 case VIR_TRISTATE_SWITCH_ABSENT:
404507
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
404507
index 479a791f29..698d3280fe 100644
404507
--- a/src/conf/domain_conf.h
404507
+++ b/src/conf/domain_conf.h
404507
@@ -1735,6 +1735,7 @@ typedef enum {
404507
     VIR_DOMAIN_FEATURE_SMM,
404507
     VIR_DOMAIN_FEATURE_IOAPIC,
404507
     VIR_DOMAIN_FEATURE_HPT,
404507
+    VIR_DOMAIN_FEATURE_VMCOREINFO,
404507
 
404507
     VIR_DOMAIN_FEATURE_LAST
404507
 } virDomainFeature;
404507
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
404507
index 13ff1286c4..4301d2e799 100644
404507
--- a/src/qemu/qemu_capabilities.c
404507
+++ b/src/qemu/qemu_capabilities.c
404507
@@ -444,7 +444,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
404507
               "vxhs",
404507
               "virtio-blk.num-queues",
404507
               "machine.pseries.resize-hpt",
404507
-
404507
+              "vmcoreinfo",
404507
               "spapr-vty",
404507
 
404507
               /* 275 */
404507
@@ -1684,6 +1684,7 @@ struct virQEMUCapsStringFlags virQEMUCapsObjectTypes[] = {
404507
     { "pcie-root-port", QEMU_CAPS_DEVICE_PCIE_ROOT_PORT },
404507
     { "qemu-xhci", QEMU_CAPS_DEVICE_QEMU_XHCI },
404507
     { "spapr-pci-host-bridge", QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE },
404507
+    { "vmcoreinfo", QEMU_CAPS_DEVICE_VMCOREINFO },
404507
     { "spapr-vty", QEMU_CAPS_DEVICE_SPAPR_VTY },
404507
     { "sclplmconsole", QEMU_CAPS_DEVICE_SCLPLMCONSOLE },
404507
     { "isa-serial", QEMU_CAPS_DEVICE_ISA_SERIAL },
404507
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
404507
index 3e016b7c79..c6eb9df146 100644
404507
--- a/src/qemu/qemu_capabilities.h
404507
+++ b/src/qemu/qemu_capabilities.h
404507
@@ -430,7 +430,7 @@ typedef enum {
404507
     QEMU_CAPS_VXHS, /* -drive file.driver=vxhs via query-qmp-schema */
404507
     QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES, /* virtio-blk-*.num-queues */
404507
     QEMU_CAPS_MACHINE_PSERIES_RESIZE_HPT, /* -machine pseries,resize-hpt */
404507
-
404507
+    QEMU_CAPS_DEVICE_VMCOREINFO, /* -device vmcoreinfo */
404507
     QEMU_CAPS_DEVICE_SPAPR_VTY, /* -device spapr-vty */
404507
 
404507
     /* 275 */
404507
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
404507
index b462c7cf09..a1bf230fad 100644
404507
--- a/src/qemu/qemu_command.c
404507
+++ b/src/qemu/qemu_command.c
404507
@@ -9922,6 +9922,28 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
404507
 }
404507
 
404507
 
404507
+static int
404507
+qemuBuildVMCoreInfoCommandLine(virCommandPtr cmd,
404507
+                               const virDomainDef *def,
404507
+                               virQEMUCapsPtr qemuCaps)
404507
+{
404507
+    virTristateSwitch vmci = def->features[VIR_DOMAIN_FEATURE_VMCOREINFO];
404507
+
404507
+    if (vmci != VIR_TRISTATE_SWITCH_ON)
404507
+        return 0;
404507
+
404507
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VMCOREINFO)) {
404507
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
404507
+                       _("vmcoreinfo is not available "
404507
+                         "with this QEMU binary"));
404507
+        return -1;
404507
+    }
404507
+
404507
+    virCommandAddArgList(cmd, "-device", "vmcoreinfo", NULL);
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 static int
404507
 qemuBuildPanicCommandLine(virCommandPtr cmd,
404507
                           const virDomainDef *def,
404507
@@ -10341,6 +10363,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
404507
     if (qemuBuildNVRAMCommandLine(cmd, def, qemuCaps) < 0)
404507
         goto error;
404507
 
404507
+    if (qemuBuildVMCoreInfoCommandLine(cmd, def, qemuCaps) < 0)
404507
+        goto error;
404507
+
404507
     if (snapshot)
404507
         virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
404507
 
404507
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
404507
new file mode 100644
404507
index 0000000000..772e5a071f
404507
--- /dev/null
404507
+++ b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.args
404507
@@ -0,0 +1,25 @@
404507
+LC_ALL=C \
404507
+PATH=/bin \
404507
+HOME=/home/test \
404507
+USER=test \
404507
+LOGNAME=test \
404507
+QEMU_AUDIO_DRV=none \
404507
+/usr/bin/qemu-system-i686 \
404507
+-name QEMUGuest1 \
404507
+-S \
404507
+-M pc \
404507
+-m 214 \
404507
+-smp 1,sockets=1,cores=1,threads=1 \
404507
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
404507
+-nographic \
404507
+-nodefaults \
404507
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
404507
+server,nowait \
404507
+-mon chardev=charmonitor,id=monitor,mode=readline \
404507
+-no-acpi \
404507
+-boot c \
404507
+-usb \
404507
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
404507
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
404507
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
404507
+-device vmcoreinfo
404507
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
404507
new file mode 100644
404507
index 0000000000..f8e5865310
404507
--- /dev/null
404507
+++ b/tests/qemuxml2argvdata/qemuxml2argv-vmcoreinfo.xml
404507
@@ -0,0 +1,28 @@
404507
+<domain type='qemu'>
404507
+  <name>QEMUGuest1</name>
404507
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
404507
+  <memory unit='KiB'>219100</memory>
404507
+  <currentMemory unit='KiB'>219100</currentMemory>
404507
+  <vcpu placement='static'>1</vcpu>
404507
+  <os>
404507
+    <type arch='i686' machine='pc'>hvm</type>
404507
+    <boot dev='hd'/>
404507
+  </os>
404507
+  <features>
404507
+    <vmcoreinfo/>
404507
+  </features>
404507
+  <clock offset='utc'/>
404507
+  <on_poweroff>destroy</on_poweroff>
404507
+  <on_reboot>restart</on_reboot>
404507
+  <on_crash>destroy</on_crash>
404507
+  <devices>
404507
+    <emulator>/usr/bin/qemu-system-i686</emulator>
404507
+    <disk type='block' device='disk'>
404507
+      <source dev='/dev/HostVG/QEMUGuest1'/>
404507
+      <target dev='hda' bus='ide'/>
404507
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
404507
+    </disk>
404507
+    <controller type='ide' index='0'/>
404507
+    <memballoon model='virtio'/>
404507
+  </devices>
404507
+</domain>
404507
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
404507
index 686a63855c..686d289b89 100644
404507
--- a/tests/qemuxml2argvtest.c
404507
+++ b/tests/qemuxml2argvtest.c
404507
@@ -2933,6 +2933,7 @@ mymain(void)
404507
     DO_TEST_PARSE_ERROR("cpu-cache-emulate-l2", QEMU_CAPS_KVM);
404507
     DO_TEST_PARSE_ERROR("cpu-cache-passthrough3", QEMU_CAPS_KVM);
404507
     DO_TEST_PARSE_ERROR("cpu-cache-passthrough-l3", QEMU_CAPS_KVM);
404507
+    DO_TEST("vmcoreinfo", QEMU_CAPS_DEVICE_VMCOREINFO);
404507
 
404507
     DO_TEST("user-aliases", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_CIRRUS_VGA,
404507
             QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_PIIX_DISABLE_S3,
404507
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
404507
new file mode 100644
404507
index 0000000000..a3922d6304
404507
--- /dev/null
404507
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-vmcoreinfo.xml
404507
@@ -0,0 +1,38 @@
404507
+<domain type='qemu'>
404507
+  <name>QEMUGuest1</name>
404507
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
404507
+  <memory unit='KiB'>219100</memory>
404507
+  <currentMemory unit='KiB'>219100</currentMemory>
404507
+  <vcpu placement='static'>1</vcpu>
404507
+  <os>
404507
+    <type arch='i686' machine='pc'>hvm</type>
404507
+    <boot dev='hd'/>
404507
+  </os>
404507
+  <features>
404507
+    <vmcoreinfo/>
404507
+  </features>
404507
+  <clock offset='utc'/>
404507
+  <on_poweroff>destroy</on_poweroff>
404507
+  <on_reboot>restart</on_reboot>
404507
+  <on_crash>destroy</on_crash>
404507
+  <devices>
404507
+    <emulator>/usr/bin/qemu-system-i686</emulator>
404507
+    <disk type='block' device='disk'>
404507
+      <source dev='/dev/HostVG/QEMUGuest1'/>
404507
+      <target dev='hda' bus='ide'/>
404507
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
404507
+    </disk>
404507
+    <controller type='ide' index='0'>
404507
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
404507
+    </controller>
404507
+    <controller type='usb' index='0'>
404507
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
404507
+    </controller>
404507
+    <controller type='pci' index='0' model='pci-root'/>
404507
+    <input type='mouse' bus='ps2'/>
404507
+    <input type='keyboard' bus='ps2'/>
404507
+    <memballoon model='virtio'>
404507
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
404507
+    </memballoon>
404507
+  </devices>
404507
+</domain>
404507
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
404507
index 8766646738..5ca0ea3a22 100644
404507
--- a/tests/qemuxml2xmltest.c
404507
+++ b/tests/qemuxml2xmltest.c
404507
@@ -1319,6 +1319,7 @@ mymain(void)
404507
     DO_TEST("cpu-check-default-none2", NONE);
404507
     DO_TEST("cpu-check-default-partial", NONE);
404507
     DO_TEST("cpu-check-default-partial2", NONE);
404507
+    DO_TEST("vmcoreinfo", NONE);
404507
 
404507
     DO_TEST("smartcard-host", NONE);
404507
     DO_TEST("smartcard-host-certificates", NONE);
404507
-- 
404507
2.15.1
404507