[libvirt] [PATCH v2 0/2] Couple of virCaps improvements

diff to v1: -rename the test -drop even more from the original documentation Michal Privoznik (2): vircaps2xmltest: Introduce basic testing formatcaps: Rework and add stubs to document docs/formatcaps.html.in | 139 +++++++++++++++------ tests/Makefile.am | 6 + tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml | 74 +++++++++++ tests/vircaps2xmltest.c | 164 +++++++++++++++++++++++++ 4 files changed, 345 insertions(+), 38 deletions(-) create mode 100644 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml create mode 100644 tests/vircaps2xmltest.c -- 2.0.0

For now only one test is introduced. It's purpose in life is to check we don't break NUMA host distances XML format. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/Makefile.am | 6 + tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml | 74 +++++++++++ tests/vircaps2xmltest.c | 164 +++++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml create mode 100644 tests/vircaps2xmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 1fdfd3b..9f4dff3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -124,6 +124,7 @@ EXTRA_DIST = \ storagevolxml2xmlout \ sysinfodata \ test-lib.sh \ + vircaps2xmldata \ virsh-uriprecedence \ virfiledata \ virpcitestdata \ @@ -167,6 +168,7 @@ test_programs = virshtest sockettest \ vircapstest \ domainconftest \ virhostdevtest \ + vircaps2xmltest \ $(NULL) if WITH_REMOTE @@ -803,6 +805,10 @@ vircapstest_SOURCES = \ vircapstest.c testutils.h testutils.c vircapstest_LDADD = $(LDADDS) +vircaps2xmltest_SOURCES = \ + vircaps2xmltest.c testutils.h testutils.c +vircaps2xmltest_LDADD = $(LDADDS) + if WITH_LIBVIRTD libvirtdconftest_SOURCES = \ libvirtdconftest.c testutils.h testutils.c \ diff --git a/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml new file mode 100644 index 0000000..8694f87 --- /dev/null +++ b/tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml @@ -0,0 +1,74 @@ +<capabilities> + + <host> + <cpu> + <arch>x86_64</arch> + </cpu> + <power_management/> + <topology> + <cells num='4'> + <cell id='0'> + <memory unit='KiB'>2097152</memory> + <distances> + <sibling id='0' value='10'/> + <sibling id='1' value='20'/> + <sibling id='2' value='20'/> + <sibling id='3' value='20'/> + </distances> + <cpus num='4'> + <cpu id='0' socket_id='0' core_id='0' siblings='0'/> + <cpu id='0' socket_id='0' core_id='1' siblings='0'/> + <cpu id='0' socket_id='0' core_id='2' siblings='0'/> + <cpu id='0' socket_id='0' core_id='3' siblings='0'/> + </cpus> + </cell> + <cell id='1'> + <memory unit='KiB'>2097152</memory> + <distances> + <sibling id='0' value='20'/> + <sibling id='1' value='10'/> + <sibling id='2' value='20'/> + <sibling id='3' value='20'/> + </distances> + <cpus num='4'> + <cpu id='1' socket_id='1' core_id='1' siblings='1'/> + <cpu id='1' socket_id='1' core_id='2' siblings='1'/> + <cpu id='1' socket_id='1' core_id='3' siblings='1'/> + <cpu id='1' socket_id='1' core_id='4' siblings='1'/> + </cpus> + </cell> + <cell id='2'> + <memory unit='KiB'>2097152</memory> + <distances> + <sibling id='0' value='20'/> + <sibling id='1' value='20'/> + <sibling id='2' value='10'/> + <sibling id='3' value='20'/> + </distances> + <cpus num='4'> + <cpu id='2' socket_id='2' core_id='2' siblings='2'/> + <cpu id='2' socket_id='2' core_id='3' siblings='2'/> + <cpu id='2' socket_id='2' core_id='4' siblings='2'/> + <cpu id='2' socket_id='2' core_id='5' siblings='2'/> + </cpus> + </cell> + <cell id='3'> + <memory unit='KiB'>2097152</memory> + <distances> + <sibling id='0' value='20'/> + <sibling id='1' value='20'/> + <sibling id='2' value='20'/> + <sibling id='3' value='10'/> + </distances> + <cpus num='4'> + <cpu id='3' socket_id='3' core_id='3' siblings='3'/> + <cpu id='3' socket_id='3' core_id='4' siblings='3'/> + <cpu id='3' socket_id='3' core_id='5' siblings='3'/> + <cpu id='3' socket_id='3' core_id='6' siblings='3'/> + </cpus> + </cell> + </cells> + </topology> + </host> + +</capabilities> diff --git a/tests/vircaps2xmltest.c b/tests/vircaps2xmltest.c new file mode 100644 index 0000000..fa02534 --- /dev/null +++ b/tests/vircaps2xmltest.c @@ -0,0 +1,164 @@ +/* + * Copyright (C) Red Hat, Inc. 2014 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + * + * Authors: + * Michal Privoznik <mprivozn@redhat.com> + */ + +#include <config.h> +#include <stdlib.h> + +#include "testutils.h" +#include "capabilities.h" +#include "virbitmap.h" + + +#define VIR_FROM_THIS VIR_FROM_NONE + +static virCapsPtr +buildVirCapabilities(int max_cells, + int max_cpus_in_cell, + int max_mem_in_cell) +{ + virCapsPtr caps; + virCapsHostNUMACellCPUPtr cell_cpus = NULL; + virCapsHostNUMACellSiblingInfoPtr siblings = NULL; + int core_id, cell_id, nsiblings; + int id; + size_t i; + + if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64, 0, 0)) == NULL) + goto error; + + id = 0; + for (cell_id = 0; cell_id < max_cells; cell_id++) { + if (VIR_ALLOC_N(cell_cpus, max_cpus_in_cell) < 0) + goto error; + + for (core_id = 0; core_id < max_cpus_in_cell; core_id++) { + cell_cpus[core_id].id = id; + cell_cpus[core_id].socket_id = cell_id; + cell_cpus[core_id].core_id = id + core_id; + if (!(cell_cpus[core_id].siblings = + virBitmapNew(max_cpus_in_cell))) + goto error; + ignore_value(virBitmapSetBit(cell_cpus[core_id].siblings, id)); + } + id++; + + if (VIR_ALLOC_N(siblings, max_cells) < 0) + goto error; + nsiblings = max_cells; + + for (i = 0; i < nsiblings; i++) { + siblings[i].node = i; + /* Some magical constants, see virNumaGetDistances() + * for their description. */ + siblings[i].distance = cell_id == i ? 10 : 20; + } + + if (virCapabilitiesAddHostNUMACell(caps, cell_id, + max_mem_in_cell, + max_cpus_in_cell, cell_cpus, + nsiblings, siblings) < 0) + goto error; + + cell_cpus = NULL; + siblings = NULL; + } + + return caps; + + error: + virCapabilitiesClearHostNUMACellCPUTopology(cell_cpus, max_cpus_in_cell); + VIR_FREE(cell_cpus); + VIR_FREE(siblings); + virObjectUnref(caps); + return NULL; +} + + +struct virCapabilitiesFormatData { + const char *filename; + int max_cells; + int max_cpus_in_cell; + int max_mem_in_cell; +}; + +static int +test_virCapabilitiesFormat(const void *opaque) +{ + struct virCapabilitiesFormatData *data = (struct virCapabilitiesFormatData *) opaque; + virCapsPtr caps = NULL; + char *capsXML = NULL; + char *capsFromFile = NULL; + char *path = NULL; + int ret = -1; + + if (!(caps = buildVirCapabilities(data->max_cells, data->max_cpus_in_cell, + data->max_mem_in_cell))) + goto cleanup; + + if (!(capsXML = virCapabilitiesFormatXML(caps))) { + fprintf(stderr, "Unable to format capabilities XML"); + goto cleanup; + } + + if (virAsprintf(&path, "%s/vircaps2xmldata/vircaps-%s.xml", + abs_srcdir, data->filename) < 0) + goto cleanup; + + if (virFileReadAll(path, 8192, &capsFromFile) < 0) + goto cleanup; + + + if (STRNEQ(capsXML, capsFromFile)) { + virtTestDifference(stderr, capsFromFile, capsXML); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(path); + VIR_FREE(capsFromFile); + VIR_FREE(capsXML); + virObjectUnref(caps); + return ret; +} + +static int +mymain(void) +{ + int ret = 0; + +#define DO_TEST(filename, max_cells, \ + max_cpus_in_cell, max_mem_in_cell) \ + do { \ + struct virCapabilitiesFormatData data = {filename, max_cells, \ + max_cpus_in_cell, \ + max_mem_in_cell}; \ + if (virtTestRun(filename, test_virCapabilitiesFormat, &data) < 0) \ + ret = -1; \ + } while (0) + + DO_TEST("basic-4-4-2G", 4, 4, 2*1024*1024); + + return ret; +} + +VIRT_TEST_MAIN(mymain) -- 2.0.0

On Thu, Jun 05, 2014 at 01:53:16PM +0200, Michal Privoznik wrote:
For now only one test is introduced. It's purpose in life is to check we don't break NUMA host distances XML format.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/Makefile.am | 6 + tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml | 74 +++++++++++ tests/vircaps2xmltest.c | 164 +++++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 tests/vircaps2xmldata/vircaps-basic-4-4-2G.xml create mode 100644 tests/vircaps2xmltest.c
AKC Regards, 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 :|

At the moment we are missing even basic documentation on our capabilities XML. Without demand on completeness, I'm reorganizing the document structure and adding very basic documentation to two major components of the capabilities XML. These stubs are intended to be enhanced in the future. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatcaps.html.in | 139 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 38 deletions(-) diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in index d060a5b..137af25 100644 --- a/docs/formatcaps.html.in +++ b/docs/formatcaps.html.in @@ -4,19 +4,107 @@ <body> <h1>Driver capabilities XML format</h1> - <p>As new virtualization engine support gets added to libvirt, and to handle -cases like QEmu supporting a variety of emulations, a query interface has -been added in 0.2.1 allowing to list the set of supported virtualization -capabilities on the host:</p> - <pre> char * virConnectGetCapabilities (virConnectPtr conn);</pre> - <p>The value returned is an XML document listing the virtualization -capabilities of the host and virtualization engine to which -<code>@conn</code> is connected. One can test it using <code>virsh</code> -command line tool command '<code>capabilities</code>', it dumps the XML -associated to the current connection. For example in the case of a 64 bits -machine with hardware virtualization capabilities enabled in the chip and -BIOS you will see</p> - <pre><capabilities> + <ul id="toc"></ul> + + <h2><a name="elements">Element and attribute overview</a></h2> + + <p>As new virtualization engine support gets added to libvirt, and to + handle cases like QEMU supporting a variety of emulations, a query + interface has been added in 0.2.1 allowing to list the set of supported + virtualization capabilities on the host:</p> + + <pre> char * virConnectGetCapabilities (virConnectPtr conn);</pre> + + <p>The value returned is an XML document listing the virtualization + capabilities of the host and virtualization engine to which + <code>@conn</code> is connected. One can test it using <code>virsh</code> + command line tool command '<code>capabilities</code>', it dumps the XML + associated to the current connection. </p> + + <p>As can be seen seen in the <a href="#elementExamples">example</a>, the + capabilities XML consists of the <code>capabilities</code> element which + have exactly one <code>host</code> child element to report information on + host capabilities, and zero or more <code>guest</code> element to express + the set of architectures the host can run at the moment.</p> + + + <h3><a name="elementHost">Host capabilities</a></h3> + + <p>The <code><host/></code> element consists of the following child + elements:</p> + <dl> + <dt><code>uuid</code></dt> + <dd>The host UUID.</dd> + + <dt><code>cpu</code></dt> + <dd>The host CPU architecture and features.</dd> + + <dt><code>power_management</code></dt> + <dd>whether host is capable of memory suspend, disk hibernation, or + hybrid suspend.</dd> + + <dt><code>migration</code></dt> + <dd>This element exposes information on the hypervisor's migration + capabilities, like live migration, supported URI transports, and so + on.</dd> + + <dt><code>topology</code></dt> + <dd>This element embodies the host internal topology. Management + applications may want to learn this information when orchestrating new + guests - e.g. due to reduce inter-NUMA node transfers.</dd> + + <dt><code>secmodel</code></dt> + <dd>To find out default security labels for different security models you + need to parse this element. In contrast with the former elements, this is + repeated for each security model the libvirt daemon currently supports. + </dd> + </dl> + + + <h3><a name="elementGuest">Guest capabilities</a></h3> + + <p>While the <a href="#elementHost">previous section</a> aims at host + capabilities, this one focuses on capabilities available to a guest + using a given hypervisor. The <code><guest/></code> element will + typically wrap up the following elements:</p> + + <dl> + <dt><code>os_type</code></dt> + <dd>This expresses what kind of operating system the hypervisor + is able to run. Possible values are: + <dl> + <dt>xen</dt> + <dd>for XEN</dd> + + <dt>linux</dt> + <dd>legacy alias for <code>xen</code></dd> + + <dt>hvm</dt> + <dd>Unmodified operating system</dd> + + <dt>exe</dt> + <dd>Container based virtualization</dd> + + <dt>uml</dt> + <dd>User Mode Linux</dd> + </dl> + </dd> + + <dt><code>arch</code></dt> + <dd>This element brings some information on supported guest architecture.</dd> + + <dt><code>features</code></dt> + <dd>This optional element encases possible features that can be used + with a guest of described type.</dd> + </dl> + + <h3><a name="elementExamples">Examples</a></h3> + + <p>For example, in the case of a 64-bit machine with hardware + virtualization capabilities enabled in the chip and + BIOS you will see:</p> + + <pre><capabilities> <span style="color: #E50000"><host> <cpu> <arch>x86_64</arch> @@ -67,30 +155,5 @@ BIOS you will see</p> </guest></span> ... </capabilities></pre> - <p>The first block (in red) indicates the host hardware - capabilities, such as CPU properties and the power - management features of the host platform. CPU models are - shown as additional features relative to the closest base - model, within a feature block (the block is similar to what - you will find in a Xen fully virtualized domain - description). Further, the power management features - supported by the host are shown, such as Suspend-to-RAM (S3), - Suspend-to-Disk (S4) and Hybrid-Suspend (a combination of S3 - and S4). In case the host does not support - any such feature, then an empty <power_management/> - tag will be shown. </p> - <p>The second block (in blue) indicates the paravirtualization - support of the Xen support, you will see the os_type of xen - to indicate a paravirtual kernel, then architecture - information and potential features.</p> - <p>The third block (in green) gives similar information but - when running a 32 bit OS fully virtualized with Xen using - the hvm support.</p> - <p>This section is likely to be updated and augmented in the - future, - see <a href="https://www.redhat.com/archives/libvir-list/2007-March/msg00215.html">the - discussion</a> which led to the capabilities format in the - mailing-list archives.</p> - </body> </html> -- 2.0.0

On Thu, Jun 05, 2014 at 01:53:17PM +0200, Michal Privoznik wrote:
At the moment we are missing even basic documentation on our capabilities XML. Without demand on completeness, I'm reorganizing the document structure and adding very basic documentation to two major components of the capabilities XML. These stubs are intended to be enhanced in the future.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatcaps.html.in | 139 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 38 deletions(-)
ACK Regards, 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 (2)
-
Daniel P. Berrange
-
Michal Privoznik