[libvirt] [PATCH 22/34] Convert watchdog to -device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The current syntax for watchdogs is

    -watchdog i6300esb

The new syntax will now be

    -device i6300esb,id=watchdogNN,addr=<PCI-SLOT>
---
 src/qemu/qemu_conf.c                               |   91 ++++++++++++++++++--
 .../qemuxml2argv-watchdog-device.args              |    1 +
 .../qemuxml2argv-watchdog-device.xml               |   23 +++++
 tests/qemuxml2argvtest.c                           |    2 +
 4 files changed, 109 insertions(+), 8 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.xml

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index eded887..fa16f8c 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1629,6 +1629,38 @@ qemuAssignDiskAliases(virDomainDefPtr def, int qemuCmdFlags)
     return 0;
 }
 
+static int
+qemuBuildDeviceAddressStr(virBufferPtr buf,
+                          virDomainDeviceInfoPtr info)
+{
+    if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+        if (info->addr.pci.domain != 0) {
+            qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Only PCI device addresses with domain=0 are supported"));
+            return -1;
+        }
+        if (info->addr.pci.bus != 0) {
+            qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Only PCI device addresses with bus=0 are supported"));
+            return -1;
+        }
+        if (info->addr.pci.function != 0) {
+            qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("Only PCI device addresses with function=0 are supported"));
+            return -1;
+        }
+
+        /* XXX
+         * When QEMU grows support for > 1 PCI bus, then pci.0 changes
+         * to pci.1, pci.2, etc
+         * When QEMU grows support for > 1 PCI domain, then pci.0 change
+         * to pciNN.0  where NN is the domain number
+         */
+        virBufferVSprintf(buf, ",bus=pci.0,addr=0x%x", info->addr.pci.slot);
+    }
+    return 0;
+}
+
 
 static const char *
 qemuNetTypeToHostNet(int type)
@@ -1991,7 +2023,36 @@ qemuBuildHostNetStr(virConnectPtr conn,
     return 0;
 }
 
-/* This function outputs a -chardev command line option which describes only the
+
+static char *qemuBuildWatchdogDevStr(virDomainWatchdogDefPtr dev)
+{
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+    const char *model = virDomainWatchdogModelTypeToString(dev->model);
+    if (!model) {
+        qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                         "%s", _("missing watchdog model"));
+        goto error;
+    }
+
+    virBufferVSprintf(&buf, "%s", model);
+    virBufferVSprintf(&buf, ",id=%s", dev->info.alias);
+    if (qemuBuildDeviceAddressStr(&buf, &dev->info) < 0)
+        goto error;
+
+    if (virBufferError(&buf)) {
+        virReportOOMError(NULL);
+        goto error;
+    }
+
+    return virBufferContentAndReset(&buf);
+
+error:
+    virBufferFreeAndReset(&buf);
+    return NULL;
+}
+
+/* this function outputs a -chardev command line option which describes only the
  * host side of the character device */
 static void qemudBuildCommandLineChrDevChardevStr(virDomainChrDefPtr dev,
                                                   virBufferPtr buf)
@@ -3086,14 +3147,28 @@ int qemudBuildCommandLine(virConnectPtr conn,
     /* Add watchdog hardware */
     if (def->watchdog) {
         virDomainWatchdogDefPtr watchdog = def->watchdog;
-        const char *model = virDomainWatchdogModelTypeToString(watchdog->model);
-        if (!model) {
-            qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
-                             "%s", _("invalid watchdog model"));
-            goto error;
+        char *optstr;
+
+        if (qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE) {
+            ADD_ARG_LIT("-device");
+
+            optstr = qemuBuildWatchdogDevStr(watchdog);
+            if (!optstr)
+                goto error;
+        } else {
+            ADD_ARG_LIT("-watchdog");
+
+            const char *model = virDomainWatchdogModelTypeToString(watchdog->model);
+            if (!model) {
+                qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+                                 "%s", _("missing watchdog model"));
+                goto error;
+            }
+
+            if (!(optstr = strdup(model)))
+                goto no_memory;
         }
-        ADD_ARG_LIT("-watchdog");
-        ADD_ARG_LIT(model);
+        ADD_ARG(optstr);
 
         const char *action = virDomainWatchdogActionTypeToString(watchdog->action);
         if (!action) {
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.args b/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.args
new file mode 100644
index 0000000..5f3a428
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.args
@@ -0,0 +1 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -nodefaults -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -usb -device ib700,id=watchdog0 -watchdog-action poweroff
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.xml b/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.xml
new file mode 100644
index 0000000..9b2ffdf
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-watchdog-device.xml
@@ -0,0 +1,23 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory>219200</memory>
+  <currentMemory>219200</currentMemory>
+  <vcpu>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'/>
+    </disk>
+    <watchdog model='ib700' action='poweroff'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 42d1579..6bfc217 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -290,6 +290,8 @@ mymain(int argc, char **argv)
 
     DO_TEST("channel-guestfwd", QEMUD_CMD_FLAG_CHARDEV|QEMUD_CMD_FLAG_DEVICE);
 
+    DO_TEST("watchdog", 0);
+    DO_TEST("watchdog-device", QEMUD_CMD_FLAG_DEVICE);
     DO_TEST("sound", 0);
 
     DO_TEST("hostdev-usb-product", 0);
-- 
1.6.5.2

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]