[PATCH 6/6] Convert QEMU capabilities code to use virArch

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 94 ++++++++++++++++++--------------------------
 src/qemu/qemu_capabilities.h |  2 +-
 2 files changed, 40 insertions(+), 56 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f6b53ca..a0fe1c5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -42,7 +42,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <sys/wait.h>
-#include <sys/utsname.h>
 #include <stdarg.h>
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
@@ -209,7 +208,7 @@ struct _qemuCaps {
     unsigned int version;
     unsigned int kvmVersion;
 
-    char *arch;
+    virArch arch;
 
     size_t ncpuDefinitions;
     char **cpuDefinitions;
@@ -544,14 +543,14 @@ qemuCapsProbeCPUModels(qemuCapsPtr caps, qemuCapsHookDataPtr hookData)
     qemuCapsParseCPUModels parse;
     virCommandPtr cmd;
 
-    if (STREQ(caps->arch, "i686") ||
-        STREQ(caps->arch, "x86_64"))
+    if (caps->arch == VIR_ARCH_I686 ||
+        caps->arch == VIR_ARCH_X86_64)
         parse = qemuCapsParseX86Models;
-    else if (STREQ(caps->arch, "ppc64"))
+    else if (caps->arch == VIR_ARCH_PPC64)
         parse = qemuCapsParsePPCModels;
     else {
         VIR_DEBUG("don't know how to parse %s CPU models",
-                  caps->arch);
+                  virArchToString(caps->arch));
         return 0;
     }
 
@@ -599,6 +598,8 @@ qemuCapsFindBinaryForArch(virArch hostarch,
             ret = virFindFileInPath("qemu");
     } else if (guestarch == VIR_ARCH_ITANIUM) {
         ret = virFindFileInPath("qemu-system-ia64");
+    } else if (guestarch == VIR_ARCH_ARMV7L) {
+        ret = virFindFileInPath("qemu-system-arm");
     } else {
         /* Default case we have matching arch strings */
         char *bin;
@@ -1596,20 +1597,6 @@ cleanup:
     return ret;
 }
 
-static void
-uname_normalize(struct utsname *ut)
-{
-    uname(ut);
-
-    /* Map i386, i486, i586 to i686.  */
-    if (ut->machine[0] == 'i' &&
-        ut->machine[1] != '\0' &&
-        ut->machine[2] == '8' &&
-        ut->machine[3] == '6' &&
-        ut->machine[4] == '\0')
-        ut->machine[1] = '6';
-}
-
 
 int qemuCapsGetDefaultVersion(virCapsPtr caps,
                               qemuCapsCachePtr capsCache,
@@ -1677,10 +1664,7 @@ qemuCapsPtr qemuCapsNewCopy(qemuCapsPtr caps)
 
     ret->version = caps->version;
     ret->kvmVersion = caps->kvmVersion;
-
-    if (caps->arch &&
-        !(ret->arch = strdup(caps->arch)))
-        goto no_memory;
+    ret->arch = caps->arch;
 
     if (VIR_ALLOC_N(ret->cpuDefinitions, caps->ncpuDefinitions) < 0)
         goto no_memory;
@@ -1717,8 +1701,6 @@ void qemuCapsDispose(void *obj)
     qemuCapsPtr caps = obj;
     size_t i;
 
-    VIR_FREE(caps->arch);
-
     for (i = 0 ; i < caps->nmachineTypes ; i++) {
         VIR_FREE(caps->machineTypes[i]);
         VIR_FREE(caps->machineAliases[i]);
@@ -1789,7 +1771,7 @@ const char *qemuCapsGetBinary(qemuCapsPtr caps)
     return caps->binary;
 }
 
-const char *qemuCapsGetArch(qemuCapsPtr caps)
+virArch qemuCapsGetArch(qemuCapsPtr caps)
 {
     return caps->arch;
 }
@@ -2120,6 +2102,18 @@ int qemuCapsProbeQMP(qemuCapsPtr caps,
 }
 
 
+static virArch qemuCapsArchFromString(const char *arch)
+{
+    if (STREQ(arch, "ia64"))
+        return VIR_ARCH_ITANIUM;
+    if (STREQ(arch, "i386"))
+        return VIR_ARCH_I686;
+    if (STREQ(arch, "arm"))
+        return VIR_ARCH_ARMV7L;
+
+    return virArchFromString(arch);
+}
+
 #define QEMU_SYSTEM_PREFIX "qemu-system-"
 
 static int
@@ -2130,7 +2124,6 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
     char *help = NULL;
     int ret = -1;
     const char *tmp;
-    struct utsname ut;
     qemuCapsHookData hookData;
 
     VIR_DEBUG("caps=%p", caps);
@@ -2139,18 +2132,9 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
     if (tmp) {
         tmp += strlen(QEMU_SYSTEM_PREFIX);
 
-        /* For historical compat we use 'itanium' as arch name */
-        if (STREQ(tmp, "ia64"))
-            tmp = "itanium";
-        else if (STREQ(tmp, "i386"))
-            tmp = "i686";
+        caps->arch = qemuCapsArchFromString(tmp);
     } else {
-        uname_normalize(&ut);
-        tmp = ut.machine;
-    }
-    if (!(caps->arch = strdup(tmp))) {
-        virReportOOMError();
-        goto cleanup;
+        caps->arch = virArchFromHost();
     }
 
     hookData.runUid = runUid;
@@ -2171,14 +2155,15 @@ qemuCapsInitHelp(qemuCapsPtr caps, uid_t runUid, gid_t runGid)
         goto cleanup;
 
     /* Currently only x86_64 and i686 support PCI-multibus. */
-    if (STREQLEN(caps->arch, "x86_64", 6) ||
-        STREQLEN(caps->arch, "i686", 4)) {
+    if (caps->arch == VIR_ARCH_X86_64 ||
+        caps->arch == VIR_ARCH_I686) {
         qemuCapsSet(caps, QEMU_CAPS_PCI_MULTIBUS);
     }
 
     /* S390 and probably other archs do not support no-acpi -
        maybe the qemu option parsing should be re-thought. */
-    if (STRPREFIX(caps->arch, "s390"))
+    if (caps->arch == VIR_ARCH_S390 ||
+        caps->arch == VIR_ARCH_S390X)
         qemuCapsClear(caps, QEMU_CAPS_NO_ACPI);
 
     /* qemuCapsExtractDeviceStr will only set additional caps if qemu
@@ -2289,6 +2274,7 @@ qemuCapsInitQMP(qemuCapsPtr caps,
     char *monpath = NULL;
     char *pidfile = NULL;
     qemuCapsHookData hookData;
+    char *archstr;
 
     /* the ".sock" sufix is important to avoid a possible clash with a qemu
      * domain called "capabilities"
@@ -2381,26 +2367,24 @@ qemuCapsInitQMP(qemuCapsPtr caps,
 
     qemuCapsInitQMPBasic(caps);
 
-    if (!(caps->arch = qemuMonitorGetTargetArch(mon)))
+    archstr = qemuMonitorGetTargetArch(mon);
+    if ((caps->arch = qemuCapsArchFromString(archstr)) == VIR_ARCH_NONE) {
+        VIR_DEBUG("Unknown QEMU arch %s", archstr);
+        ret = 0;
+        VIR_FREE(archstr);
         goto cleanup;
-
-    /* Map i386, i486, i586 to i686.  */
-    if (caps->arch[0] == 'i' &&
-        caps->arch[1] != '\0' &&
-        caps->arch[2] == '8' &&
-        caps->arch[3] == '6' &&
-        caps->arch[4] == '\0')
-        caps->arch[1] = '6';
+    }
+    VIR_FREE(archstr);
 
     /* Currently only x86_64 and i686 support PCI-multibus. */
-    if (STREQLEN(caps->arch, "x86_64", 6) ||
-        STREQLEN(caps->arch, "i686", 4)) {
+    if (caps->arch == VIR_ARCH_X86_64 ||
+        caps->arch == VIR_ARCH_I686)
         qemuCapsSet(caps, QEMU_CAPS_PCI_MULTIBUS);
-    }
 
     /* S390 and probably other archs do not support no-acpi -
        maybe the qemu option parsing should be re-thought. */
-    if (STRPREFIX(caps->arch, "s390"))
+    if (caps->arch == VIR_ARCH_S390 ||
+        caps->arch == VIR_ARCH_S390X)
         qemuCapsClear(caps, QEMU_CAPS_NO_ACPI);
 
     if (qemuCapsProbeQMPCommands(caps, mon) < 0)
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 3da8672..c27b48c 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -191,7 +191,7 @@ bool qemuCapsGet(qemuCapsPtr caps,
 char *qemuCapsFlagsString(qemuCapsPtr caps);
 
 const char *qemuCapsGetBinary(qemuCapsPtr caps);
-const char *qemuCapsGetArch(qemuCapsPtr caps);
+virArch qemuCapsGetArch(qemuCapsPtr caps);
 unsigned int qemuCapsGetVersion(qemuCapsPtr caps);
 unsigned int qemuCapsGetKVMVersion(qemuCapsPtr caps);
 int qemuCapsAddCPUDefinition(qemuCapsPtr caps,
-- 
1.7.11.7

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