]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: add dtb option support
authorOlivia Yin <hong-hua.yin@freescale.com>
Thu, 14 Mar 2013 04:49:43 +0000 (12:49 +0800)
committerEric Blake <eblake@redhat.com>
Tue, 19 Mar 2013 21:48:58 +0000 (15:48 -0600)
The "dtb" option sets the filename for the device tree.
If without this option support, "-dtb file" will be converted into
<qemu:commandline> in domain XML file.
For example, '-dtb /media/ram/test.dtb' will be converted into
  <qemu:commandline>
    <qemu:arg value='-dtb'/>
    <qemu:arg value='/media/ram/test.dtb'/>
  </qemu:commandline>

This is not very friendly.
This patchset add special <dtb> tag like <kernel> and <initrd>
which is easier for user to write domain XML file.
  <os>
    <type arch='ppc' machine='ppce500v2'>hvm</type>
    <kernel>/media/ram/uImage</kernel>
    <initrd>/media/ram/ramdisk</initrd>
    <dtb>/media/ram/test.dtb</dtb>
    <cmdline>root=/dev/ram rw console=ttyS0,115200</cmdline>
  </os>

Signed-off-by: Eric Blake <eblake@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_command.c
tests/qemuhelptest.c
tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/testutilsqemu.c

index 519d2c5173c13324b00623b2a9345777df009996..50f8084426b9b2164cf6c9676a645a425e8b8de5 100644 (file)
@@ -210,7 +210,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
 
               "rng-random", /* 130 */
               "rng-egd",
-              "virtio-ccw"
+              "virtio-ccw",
+              "dtb",
     );
 
 struct _virQEMUCaps {
@@ -1086,6 +1087,9 @@ virQEMUCapsComputeCmdFlags(const char *help,
     if (strstr(help, "dump-guest-core=on|off"))
         virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
 
+    if (strstr(help, "-dtb"))
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
+
     /*
      * Handling of -incoming arg with varying features
      *  -incoming tcp    (kvm >= 79, qemu >= 0.10.0)
@@ -2310,6 +2314,7 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_NETDEV_BRIDGE);
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_SECCOMP_SANDBOX);
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_NO_KVM_PIT);
+    virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
 }
 
 
index da06e27b868bbdb9e480b8207450570df65881e9..b0f8c5b6d65613773f83d903eb2c6b28b6a47791 100644 (file)
@@ -172,6 +172,7 @@ enum virQEMUCapsFlags {
                                            virtio rng */
     QEMU_CAPS_OBJECT_RNG_EGD     = 131, /* EGD protocol daemon for rng */
     QEMU_CAPS_VIRTIO_CCW         = 132, /* -device virtio-*-ccw */
+    QEMU_CAPS_DTB                = 133, /* -dtb file */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
index 4891b65262535de223c0206377fb3f030c4a5250..8626b629b91d6a591ce86d06dc958e427d3a92c9 100644 (file)
@@ -6152,6 +6152,15 @@ qemuBuildCommandLine(virConnectPtr conn,
             virCommandAddArgList(cmd, "-initrd", def->os.initrd, NULL);
         if (def->os.cmdline)
             virCommandAddArgList(cmd, "-append", def->os.cmdline, NULL);
+        if (def->os.dtb) {
+            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DTB)) {
+                virCommandAddArgList(cmd, "-dtb", def->os.dtb, NULL);
+            } else {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("dtb is not supported with this QEMU binary"));
+                goto error;
+            }
+        }
     } else {
         virCommandAddArgList(cmd, "-bootloader", def->os.bootloader, NULL);
     }
@@ -9239,6 +9248,10 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps,
             WANT_VALUE();
             if (!(def->os.cmdline = strdup(val)))
                 goto no_memory;
+        } else if (STREQ(arg, "-dtb")) {
+            WANT_VALUE();
+            if (!(def->os.dtb = strdup(val)))
+                goto no_memory;
         } else if (STREQ(arg, "-boot")) {
             const char *token = NULL;
             WANT_VALUE();
index 842cdc9afdb0521052b65fb4027661863c77944f..059fa861f58202f39e6b512f5edecc428d03a2c5 100644 (file)
@@ -811,7 +811,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_CIRRUS_VGA,
             QEMU_CAPS_DEVICE_VMWARE_SVGA,
             QEMU_CAPS_DEVICE_USB_SERIAL,
-            QEMU_CAPS_DEVICE_USB_NET);
+            QEMU_CAPS_DEVICE_USB_NET,
+            QEMU_CAPS_DTB);
     DO_TEST("qemu-1.2.0", 1002000, 0, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -910,7 +911,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_VMWARE_SVGA,
             QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
             QEMU_CAPS_DEVICE_USB_SERIAL,
-            QEMU_CAPS_DEVICE_USB_NET);
+            QEMU_CAPS_DEVICE_USB_NET,
+            QEMU_CAPS_DTB);
     DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0,
             QEMU_CAPS_VNC_COLON,
             QEMU_CAPS_NO_REBOOT,
@@ -1014,7 +1016,8 @@ mymain(void)
             QEMU_CAPS_DEVICE_VMWARE_SVGA,
             QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
             QEMU_CAPS_DEVICE_USB_SERIAL,
-            QEMU_CAPS_DEVICE_USB_NET);
+            QEMU_CAPS_DEVICE_USB_NET,
+            QEMU_CAPS_DTB);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args
new file mode 100644 (file)
index 0000000..93e8f9c
--- /dev/null
@@ -0,0 +1,6 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test \
+/usr/bin/qemu-system-ppc -S -M ppce500v2 -m 256 -smp 1 -nographic \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-kernel /media/ram/uImage -initrd /media/ram/ramdisk \
+-append 'root=/dev/ram rw console=ttyS0,115200' -dtb /media/ram/test.dtb \
+-usb -net none -serial pty -parallel none
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml
new file mode 100644 (file)
index 0000000..3674621
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>49545eb3-75e1-2d0a-acdd-f0294406c99e</uuid>
+  <memory unit='KiB'>262144</memory>
+  <currentMemory unit='KiB'>262144</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc' machine='ppce500v2'>hvm</type>
+    <kernel>/media/ram/uImage</kernel>
+    <initrd>/media/ram/ramdisk</initrd>
+    <cmdline>root=/dev/ram rw console=ttyS0,115200</cmdline>
+    <dtb>/media/ram/test.dtb</dtb>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc</emulator>
+    <serial type='pty'>
+      <target port='0'/>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
index e76d84491a0505262b579d562ca015c2d95b6730..44bfe678c8c81ed81fe1d65afcf2e1d8d93b6d6e 100644 (file)
@@ -916,6 +916,8 @@ mymain(void)
             QEMU_CAPS_VIRTIO_S390, QEMU_CAPS_DEVICE_VIRTIO_RNG,
             QEMU_CAPS_OBJECT_RNG_RANDOM);
 
+    DO_TEST("ppc-dtb", QEMU_CAPS_KVM, QEMU_CAPS_DTB);
+
     virObjectUnref(driver.config);
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlconf);
index 4e13db915fec5dae2596c475d2bea4e0e97e7f57..db15ee66aa5e0f413c80b79f1917c382179d1069 100644 (file)
@@ -92,6 +92,36 @@ error:
     return -1;
 }
 
+static int testQemuAddPPCGuest(virCapsPtr caps)
+{
+    static const char *machine[] = { "g3beige",
+                                     "mac99",
+                                     "prep",
+                                     "ppce500v2" };
+    virCapsGuestMachinePtr *machines = NULL;
+    virCapsGuestPtr guest;
+
+    machines = virCapabilitiesAllocMachines(machine, 1);
+    if (!machines)
+        goto error;
+
+    guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_PPC,
+                                    "/usr/bin/qemu-system-ppc", NULL,
+                                     1, machines);
+    if (!guest)
+        goto error;
+
+    if (!virCapabilitiesAddGuestDomain(guest, "qemu", NULL, NULL, 0, NULL))
+        goto error;
+
+    return 0;
+
+error:
+    /* No way to free a guest? */
+    virCapabilitiesFreeMachines(machines, 1);
+    return -1;
+}
+
 static int testQemuAddS390Guest(virCapsPtr caps)
 {
     static const char *s390_machines[] = { "s390-virtio",
@@ -242,6 +272,9 @@ virCapsPtr testQemuCapsInit(void) {
     if (testQemuAddPPC64Guest(caps))
         goto cleanup;
 
+    if (testQemuAddPPCGuest(caps))
+        goto cleanup;
+
     if (testQemuAddS390Guest(caps))
         goto cleanup;