[libvirt] [PATCH 0/2] Simplify and test CPU feature formatting code

Ján Tomko (2): Add an XML test for host-model CPU with features Simplify condition for formatting CPU features src/conf/cpu_conf.c | 42 +++++++++++----------- .../qemuxml2argv-cpu-host-model-features.xml | 33 +++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 3 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml -- 2.0.4

This was broken in a dowstream build due to a missing backport: https://bugzilla.redhat.com/show_bug.cgi?id=1182448 --- .../qemuxml2argv-cpu-host-model-features.xml | 33 ++++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 2 files changed, 34 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml new file mode 100644 index 0000000..c56d62a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml @@ -0,0 +1,33 @@ +<domain type='kvm'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <title>A description of the test machine.</title> + <description> + A test of qemu's minimal configuration. + This test also tests the description and title elements. + </description> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='host-model'> + <model fallback='allow'/> + <feature policy='require' name='abm'/> + <feature policy='force' name='ds'/> + <feature policy='disable' name='invtsc'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0d799b2..fe53c10 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -188,6 +188,7 @@ mymain(void) DO_TEST("cpu-kvmclock"); DO_TEST("cpu-host-kvmclock"); DO_TEST("cpu-host-passthrough-features"); + DO_TEST("cpu-host-model-features"); DO_TEST("clock-catchup"); DO_TEST("kvmclock"); DO_TEST("clock-timer-hyperv-rtc"); -- 2.0.4

On Thu, Jan 15, 2015 at 12:53:13 +0100, Ján Tomko wrote:
This was broken in a dowstream build due to a missing backport: https://bugzilla.redhat.com/show_bug.cgi?id=1182448 --- .../qemuxml2argv-cpu-host-model-features.xml | 33 ++++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 2 files changed, 34 insertions(+) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-host-model-features.xml
ACK, Peter

Commit adff345 added support for features to MODE_HOSTPASSTHROUGH as well. Since we support all modes now, the condition can be eliminated. --- src/conf/cpu_conf.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) Mostly whitespace changes. diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index d6d579f..4a367a1 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -660,32 +660,30 @@ virCPUDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } - if (formatModel || def->mode == VIR_CPU_MODE_HOST_PASSTHROUGH) { - for (i = 0; i < def->nfeatures; i++) { - virCPUFeatureDefPtr feature = def->features + i; + for (i = 0; i < def->nfeatures; i++) { + virCPUFeatureDefPtr feature = def->features + i; - if (!feature->name) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Missing CPU feature name")); - return -1; - } + if (!feature->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Missing CPU feature name")); + return -1; + } - if (def->type == VIR_CPU_TYPE_GUEST) { - const char *policy; + if (def->type == VIR_CPU_TYPE_GUEST) { + const char *policy; - policy = virCPUFeaturePolicyTypeToString(feature->policy); - if (!policy) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected CPU feature policy %d"), - feature->policy); - return -1; - } - virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n", - policy, feature->name); - } else { - virBufferAsprintf(buf, "<feature name='%s'/>\n", - feature->name); + policy = virCPUFeaturePolicyTypeToString(feature->policy); + if (!policy) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected CPU feature policy %d"), + feature->policy); + return -1; } + virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n", + policy, feature->name); + } else { + virBufferAsprintf(buf, "<feature name='%s'/>\n", + feature->name); } } -- 2.0.4

On Thu, Jan 15, 2015 at 12:53:14 +0100, Ján Tomko wrote:
Commit adff345 added support for features to MODE_HOSTPASSTHROUGH as well. Since we support all modes now, the condition can be eliminated. --- src/conf/cpu_conf.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-)
Mostly whitespace changes.
ACK, Peter
participants (2)
-
Ján Tomko
-
Peter Krempa