[PATCH v2 5/7] qemu: do not create useless <cpu> element

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

 



Avoid creating an empty <cpu> element when the QEMU command-line simply
specifies the default "-cpu qemu32" or "-cpu qemu64".

This requires the previous patch, which lets us represent "-cpu qemu32"
as <os arch='i686'> in the generated XML.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
 src/qemu/qemu_command.c |   50 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7fe8c48..d01696e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6778,12 +6778,10 @@ static int
 qemuParseCommandLineCPU(virDomainDefPtr dom,
                         const char *val)
 {
-    virCPUDefPtr cpu;
+    virCPUDefPtr cpu = NULL;
     const char *p = val;
     const char *next;
-
-    if (!(cpu = qemuInitGuestCPU(dom)))
-        goto error;
+    char *model = NULL;
 
     do {
         if (*p == '\0' || *p == ',')
@@ -6792,14 +6790,22 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
         if ((next = strchr(p, ',')))
             next++;
 
-        if (!cpu->model) {
+        if (p == val) {
             if (next)
-                cpu->model = strndup(p, next - p - 1);
+                model = strndup(p, next - p - 1);
             else
-                cpu->model = strdup(p);
+                model = strdup(p);
 
-            if (!cpu->model)
+            if (!model)
                 goto no_memory;
+
+            if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
+                if (!(cpu = qemuInitGuestCPU(dom)))
+                    goto error;
+
+                cpu->model = model;
+                model = NULL;
+            }
         }
         else if (*p == '+' || *p == '-') {
             char *feature;
@@ -6823,6 +6829,13 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
             if (!feature)
                 goto no_memory;
 
+            if (!cpu) {
+                if (!(cpu = qemuInitGuestCPU(dom)))
+                    goto error;
+
+                cpu->model = model;
+                model = NULL;
+            }
             ret = virCPUDefAddFeature(cpu, feature, policy);
             VIR_FREE(feature);
             if (ret < 0)
@@ -6832,22 +6845,27 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
 
     if (STREQ(dom->os.arch, "x86_64")) {
         bool is_32bit = false;
-        union cpuData *cpuData = NULL;
-        int ret;
+        if (cpu) {
+            union cpuData *cpuData = NULL;
+            int ret;
 
-        ret = cpuEncode("x86_64", cpu, NULL, &cpuData,
-                        NULL, NULL, NULL, NULL);
-        if (ret < 0)
-            goto error;
+            ret = cpuEncode("x86_64", cpu, NULL, &cpuData,
+                            NULL, NULL, NULL, NULL);
+            if (ret < 0)
+                goto error;
 
-        is_32bit = (cpuHasFeature("x86_64", cpuData, "lm") != 1);
-        cpuDataFree("x86_64", cpuData);
+            is_32bit = (cpuHasFeature("x86_64", cpuData, "lm") != 1);
+            cpuDataFree("x86_64", cpuData);
+        } else if (model) {
+            is_32bit = STREQ(model, "qemu32");
+        }
 
         if (is_32bit) {
             VIR_FREE(dom->os.arch);
             dom->os.arch = strdup("i686");
         }
     }
+    VIR_FREE(model);
     return 0;
 
 syntax:
-- 
1.7.7.6


--
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]