[libvirt] [PATCH v3 0/4] qemu: -dtb option support

Sometime QEMU need load specific device tree binary images. These patches provide -dtb option support and update docs/tests. Olivia Yin (4): QEMU: add -dtb option support qemu: add dtb capability docs: add -dtb option support to QEMU tests: add dtb test case src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 6 ++++++ src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + docs/formatdomain.html.in | 5 +++++ docs/schemas/domaincommon.rng | 5 +++++ tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml | 28 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 +

Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 6 ++++++ 3 files changed, 11 insertions(+), 0 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 995cf0c..9b71066 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1785,6 +1785,7 @@ void virDomainDefFree(virDomainDefPtr def) VIR_FREE(def->os.kernel); VIR_FREE(def->os.initrd); VIR_FREE(def->os.cmdline); + VIR_FREE(def->os.dtb); VIR_FREE(def->os.root); VIR_FREE(def->os.loader); VIR_FREE(def->os.bootloader); @@ -10047,6 +10048,7 @@ virDomainDefParseXML(virCapsPtr caps, def->os.kernel = virXPathString("string(./os/kernel[1])", ctxt); def->os.initrd = virXPathString("string(./os/initrd[1])", ctxt); def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt); + def->os.dtb = virXPathString("string(./os/dtb[1])", ctxt); def->os.root = virXPathString("string(./os/root[1])", ctxt); def->os.loader = virXPathString("string(./os/loader[1])", ctxt); } @@ -14666,6 +14668,8 @@ virDomainDefFormatInternal(virDomainDefPtr def, def->os.initrd); virBufferEscapeString(buf, " <cmdline>%s</cmdline>\n", def->os.cmdline); + virBufferEscapeString(buf, " <dtb>%s</dtb>\n", + def->os.dtb); virBufferEscapeString(buf, " <root>%s</root>\n", def->os.root); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5828ae2..a35f90a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1535,6 +1535,7 @@ struct _virDomainOSDef { char *kernel; char *initrd; char *cmdline; + char *dtb; char *root; char *loader; char *bootloader; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1c9bfc9..fb74ec5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5732,6 +5732,8 @@ 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) + virCommandAddArgList(cmd, "-dtb", def->os.dtb, NULL); } else { virCommandAddArgList(cmd, "-bootloader", def->os.bootloader, NULL); } @@ -8908,6 +8910,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(); -- 1.6.4

Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 40022c1..f6a6ab7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -210,6 +210,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "rng-random", /* 130 */ "rng-egd", + "dtb", ); struct _virQEMUCaps { @@ -944,6 +945,8 @@ virQEMUCapsComputeCmdFlags(const char *help, } if (strstr(help, "-uuid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_UUID); + if (strstr(help, "-dtb")) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB); if (strstr(help, "-xen-domid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_XEN_DOMID); else if (strstr(help, "-domid")) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a895867..f373285 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -171,6 +171,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_OBJECT_RNG_RANDOM = 130, /* the rng-random backend for virtio rng */ QEMU_CAPS_OBJECT_RNG_EGD = 131, /* EGD protocol daemon for rng */ + QEMU_CAPS_DTB = 132, /* -dtb available */ QEMU_CAPS_LAST, /* this must always be the last item */ }; -- 1.6.4

Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- docs/formatdomain.html.in | 5 +++++ docs/schemas/domaincommon.rng | 5 +++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 595f151..93b10ac 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -232,6 +232,7 @@ <kernel>/root/f8-i386-vmlinuz</kernel> <initrd>/root/f8-i386-initrd</initrd> <cmdline>console=ttyS0 ks=http://example.com/f8-i386/os/</cmdline> + <dtb>/root/ppc.dtb</dtb> </os> ...</pre> @@ -253,6 +254,10 @@ the kernel (or installer) at boottime. This is often used to specify an alternate primary console (eg serial port), or the installation media source / kickstart file</dd> + <dt><code>dtb</code></dt> + <dd>The contents of this element specify the fully-qualified path + to the (optional) device tree binary (dtb) image in the host OS. + Since 1.0.4</dd> </dl> <h4><a name="eleemntsOSContainer">Container boot</a></h4> diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index e7231cc..970976a 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -832,6 +832,11 @@ <text/> </element> </optional> + <optional> + <element name="dtb"> + <ref name="absFilePath"/> + </element> + </optional> </interleave> </define> <define name="osbootdev"> -- 1.6.4

Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml | 28 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 + 3 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args new file mode 100644 index 0000000..99ee22c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu-system-ppc -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -dtb /media/ram/test.dtb -serial pty diff --git a/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml new file mode 100644 index 0000000..3674621 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-ppc-dtb.xml @@ -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> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b6b5489..78da9cf 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -887,6 +887,8 @@ mymain(void) DO_TEST("virtio-rng-egd", QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_EGD); + DO_TEST("ppc-dtb", QEMU_CAPS_DTB); + virObjectUnref(driver.config); virObjectUnref(driver.caps); VIR_FREE(map); -- 1.6.4

On 02/27/2013 01:28 AM, Olivia Yin wrote:
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+), 0 deletions(-)
[not a patch review, but a general comment] You did deep threading: 0/4 \> 1/4 \> 2/4 \> 3/4 \> 4/4 But typically we prefer shallow threading: 0/4 +> 1/4 +> 2/4 +> 3/4 \> 4/4 You may want to investigate the settings you are using with git format-patch and/or send-email.
+++ b/src/qemu/qemu_capabilities.c @@ -210,6 +210,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"rng-random", /* 130 */ "rng-egd", + "dtb",
OK, so I lied - I'm also doing a patch review: This uses a TAB, which is forbidden by 'make syntax-check'.
);
struct _virQEMUCaps { @@ -944,6 +945,8 @@ virQEMUCapsComputeCmdFlags(const char *help, } if (strstr(help, "-uuid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_UUID); + if (strstr(help, "-dtb")) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
This won't work. -dtb did not exist prior to qemu 1.2, and for all qemu newer than 1.2, we do NOT scrape '-help' output; instead, we use QMP query commands. You need to figure out the corresponding QMP command that we can use to tell when dtb support exists in qemu. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 02/27/2013 09:56 AM, Eric Blake wrote:
@@ -944,6 +945,8 @@ virQEMUCapsComputeCmdFlags(const char *help, } if (strstr(help, "-uuid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_UUID); + if (strstr(help, "-dtb")) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
This won't work. -dtb did not exist prior to qemu 1.2, and for all qemu newer than 1.2, we do NOT scrape '-help' output; instead, we use QMP query commands. You need to figure out the corresponding QMP command that we can use to tell when dtb support exists in qemu.
I stand (slightly) corrected: it looks like -dtb was added in qemu 1.1 (qemu commit 379b5c7), which means we DO need -help scraping for that version of qemu. Then, since it predates when QMP queries are reliable, you can get away with blindly setting QEMU_CAPS_DTB when targetting a qemu new enough to support QMP queries without actually having to query for it. But it's still something to be fixed before this patch is ready :) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, Thanks for the comments. Could you please help review the next version? Best Regards, Olivia
-----Original Message----- From: Eric Blake [mailto:eblake@redhat.com] Sent: Thursday, February 28, 2013 1:02 AM Cc: Yin Olivia-R63875; libvir-list@redhat.com Subject: Re: [libvirt] [PATCH v3 2/4] qemu: add dtb capability
On 02/27/2013 09:56 AM, Eric Blake wrote:
@@ -944,6 +945,8 @@ virQEMUCapsComputeCmdFlags(const char *help, } if (strstr(help, "-uuid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_UUID); + if (strstr(help, "-dtb")) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
This won't work. -dtb did not exist prior to qemu 1.2, and for all qemu newer than 1.2, we do NOT scrape '-help' output; instead, we use QMP query commands. You need to figure out the corresponding QMP command that we can use to tell when dtb support exists in qemu.
I stand (slightly) corrected: it looks like -dtb was added in qemu 1.1 (qemu commit 379b5c7), which means we DO need -help scraping for that version of qemu. Then, since it predates when QMP queries are reliable, you can get away with blindly setting QEMU_CAPS_DTB when targetting a qemu new enough to support QMP queries without actually having to query for it. But it's still something to be fixed before this patch is ready :)
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, Thanks for your comments.
-----Original Message----- From: Eric Blake [mailto:eblake@redhat.com] Sent: Thursday, February 28, 2013 12:57 AM To: Yin Olivia-R63875 Cc: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH v3 2/4] qemu: add dtb capability
On 02/27/2013 01:28 AM, Olivia Yin wrote:
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/qemu/qemu_capabilities.c | 3 +++ src/qemu/qemu_capabilities.h | 1 + 2 files changed, 4 insertions(+), 0 deletions(-)
[not a patch review, but a general comment]
You did deep threading:
0/4 \> 1/4 \> 2/4 \> 3/4 \> 4/4
But typically we prefer shallow threading:
0/4 +> 1/4 +> 2/4 +> 3/4 \> 4/4
You may want to investigate the settings you are using with git format- patch and/or send-email.
+++ b/src/qemu/qemu_capabilities.c @@ -210,6 +210,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
"rng-random", /* 130 */ "rng-egd", + "dtb",
OK, so I lied - I'm also doing a patch review: This uses a TAB, which is forbidden by 'make syntax-check'.
I'll fix it in next version.
);
struct _virQEMUCaps { @@ -944,6 +945,8 @@ virQEMUCapsComputeCmdFlags(const char *help, } if (strstr(help, "-uuid")) virQEMUCapsSet(qemuCaps, QEMU_CAPS_UUID); + if (strstr(help, "-dtb")) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB);
This won't work. -dtb did not exist prior to qemu 1.2, and for all qemu newer than 1.2, we do NOT scrape '-help' output; instead, we use QMP query commands. You need to figure out the corresponding QMP command that we can use to tell when dtb support exists in qemu.
How about add QEMU_CAPS_DTB into virQEMUCapsInitQMPBasic? diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 40022c1..a5bda24 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -210,6 +210,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "rng-random", /* 130 */ "rng-egd", + "dtb", ); struct _virQEMUCaps { @@ -1177,6 +1178,9 @@ virQEMUCapsComputeCmdFlags(const char *help, if (version >= 1002000) virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY); + + if (version >= 11000) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DTB); return 0; } @@ -2294,6 +2298,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); }
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Feb 27, 2013 at 04:28:37PM +0800, Olivia Yin wrote:
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 6 ++++++ 3 files changed, 11 insertions(+), 0 deletions(-)
The split of code across your patches is sub-optimal. We prefer to keep changes to the XML parser/formatter separate from changes to drivers. Also the code to test the QEMU driver should be in the same patch as the patch which changes the command line parser. So what you really want is 2 patches. One with domain_conf.{c,h} changes, RNG schema addition & schema documentation, and the other patch with all the QEMU driver changes + testing Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Hi Daniel, Thanks. I've submit v4 version of these patches. Best Regards, Olivia
-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Thursday, February 28, 2013 1:08 AM To: Yin Olivia-R63875 Cc: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH v3 1/4] QEMU: add -dtb option support
On Wed, Feb 27, 2013 at 04:28:37PM +0800, Olivia Yin wrote:
Signed-off-by: Olivia Yin <hong-hua.yin@freescale.com> --- src/conf/domain_conf.c | 4 ++++ src/conf/domain_conf.h | 1 + src/qemu/qemu_command.c | 6 ++++++ 3 files changed, 11 insertions(+), 0 deletions(-)
The split of code across your patches is sub-optimal. We prefer to keep changes to the XML parser/formatter separate from changes to drivers.
Also the code to test the QEMU driver should be in the same patch as the patch which changes the command line parser.
So what you really want is 2 patches. One with domain_conf.{c,h} changes, RNG schema addition & schema documentation, and the other patch with all the QEMU driver changes + testing
Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt- manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk- vnc :|
participants (4)
-
Daniel P. Berrange
-
Eric Blake
-
Olivia Yin
-
Yin Olivia-R63875