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

[libvirt] [PATCH 10/11] caps: Use DomainDataLookup to replace GuestDefault*



This revealed that GuestDefaultEmulator was a bit buggy, capable
of returning an emulator that didn't match the passed domain type. Fix
up the test suite input to continue to pass.
---
 src/conf/capabilities.c                    | 122 -----------------------------
 src/conf/capabilities.h                    |  15 ----
 src/conf/domain_conf.c                     |  21 ++---
 src/libvirt_private.syms                   |   3 -
 src/qemu/qemu_capabilities.c               |  13 +--
 src/qemu/qemu_command.c                    |  19 +++--
 src/xenconfig/xen_common.c                 |  37 ++++-----
 tests/securityselinuxlabeldata/chardev.xml |   2 +-
 tests/securityselinuxlabeldata/disks.xml   |   2 +-
 tests/securityselinuxlabeldata/kernel.xml  |   2 +-
 tests/securityselinuxlabeldata/nfs.xml     |   2 +-
 11 files changed, 43 insertions(+), 195 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index a2b6451..c9e5a64 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -729,128 +729,6 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps,
     return ret;
 }
 
-/**
- * virCapabilitiesDefaultGuestArch:
- * @caps: capabilities to query
- * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
- * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT
- *
- * Returns the first architecture able to run the
- * requested operating system type
- */
-extern virArch
-virCapabilitiesDefaultGuestArch(virCapsPtr caps,
-                                int ostype,
-                                int domain)
-{
-    size_t i, j;
-
-    /* First try to find one matching host arch */
-    for (i = 0; i < caps->nguests; i++) {
-        if (caps->guests[i]->ostype == ostype) {
-            for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
-                if (caps->guests[i]->arch.domains[j]->type == domain &&
-                    caps->guests[i]->arch.id == caps->host.arch)
-                    return caps->guests[i]->arch.id;
-            }
-        }
-    }
-
-    /* Otherwise find the first match */
-    for (i = 0; i < caps->nguests; i++) {
-        if (caps->guests[i]->ostype == ostype) {
-            for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
-                if (caps->guests[i]->arch.domains[j]->type == domain)
-                    return caps->guests[i]->arch.id;
-            }
-        }
-    }
-
-    return VIR_ARCH_NONE;
-}
-
-/**
- * virCapabilitiesDefaultGuestMachine:
- * @caps: capabilities to query
- * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
- * @arch: architecture to search for
- * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT
- *
- * Returns the first machine variant associated with
- * the requested operating system type, architecture
- * and domain type
- */
-extern const char *
-virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
-                                   int ostype,
-                                   virArch arch,
-                                   int domain)
-{
-    size_t i;
-
-    for (i = 0; i < caps->nguests; i++) {
-        virCapsGuestPtr guest = caps->guests[i];
-        size_t j;
-
-        if (guest->ostype != ostype ||
-            guest->arch.id != arch)
-            continue;
-
-        for (j = 0; j < guest->arch.ndomains; j++) {
-            virCapsGuestDomainPtr dom = guest->arch.domains[j];
-
-            if (dom->type != domain)
-                continue;
-
-            if (!dom->info.nmachines)
-                break;
-
-            return dom->info.machines[0]->name;
-        }
-
-        if (guest->arch.defaultInfo.nmachines)
-            return caps->guests[i]->arch.defaultInfo.machines[0]->name;
-    }
-
-    return NULL;
-}
-
-/**
- * virCapabilitiesDefaultGuestEmulator:
- * @caps: capabilities to query
- * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
- * @arch: architecture to search for
- * @domain: domain type to search for, of enum VIR_DOMAIN_VIRT
- *
- * Returns the first emulator path associated with
- * the requested operating system type, architecture
- * and domain type
- */
-extern const char *
-virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
-                                    int ostype,
-                                    virArch arch,
-                                    int domain)
-{
-    size_t i, j;
-
-    for (i = 0; i < caps->nguests; i++) {
-        char *emulator;
-        if (caps->guests[i]->ostype == ostype &&
-            caps->guests[i]->arch.id == arch) {
-            emulator = caps->guests[i]->arch.defaultInfo.emulator;
-            for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
-                if (caps->guests[i]->arch.domains[j]->type == domain) {
-                    if (caps->guests[i]->arch.domains[j]->info.emulator)
-                        emulator = caps->guests[i]->arch.domains[j]->info.emulator;
-                }
-            }
-            return emulator;
-        }
-    }
-    return NULL;
-}
-
 static int
 virCapabilitiesFormatNUMATopology(virBufferPtr buf,
                                   size_t ncells,
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 948a1a5..2a3a8f0 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -284,21 +284,6 @@ void
 virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
                                             size_t ncpus);
 
-extern virArch
-virCapabilitiesDefaultGuestArch(virCapsPtr caps,
-                                int ostype,
-                                int domain);
-extern const char *
-virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
-                                   int ostype,
-                                   virArch arch,
-                                   int domain);
-extern const char *
-virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
-                                    int ostype,
-                                    virArch arch,
-                                    int domain);
-
 extern char *
 virCapabilitiesFormatXML(virCapsPtr caps);
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4d9d4b5..911cee3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12959,25 +12959,18 @@ char *
 virDomainDefGetDefaultEmulator(virDomainDefPtr def,
                                virCapsPtr caps)
 {
-    const char *emulator;
     char *retemu;
+    virCapsDomainDataPtr capsdata;
 
-    emulator = virCapabilitiesDefaultGuestEmulator(caps,
-                                                   def->os.type,
-                                                   def->os.arch,
-                                                   def->virtType);
+    if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
+            def->os.arch, def->virtType, NULL, NULL)))
+        return NULL;
 
-    if (!emulator) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("no emulator for domain %s os type %s "
-                         "on architecture %s"),
-                       virDomainVirtTypeToString(def->virtType),
-                       virDomainOSTypeToString(def->os.type),
-                       virArchToString(def->os.arch));
+    if (VIR_STRDUP(retemu, capsdata->emulator) < 0) {
+        VIR_FREE(capsdata);
         return NULL;
     }
-
-    ignore_value(VIR_STRDUP(retemu, emulator));
+    VIR_FREE(capsdata);
     return retemu;
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5843061..48785d1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -51,9 +51,6 @@ virCapabilitiesAddHostMigrateTransport;
 virCapabilitiesAddHostNUMACell;
 virCapabilitiesAllocMachines;
 virCapabilitiesClearHostNUMACellCPUTopology;
-virCapabilitiesDefaultGuestArch;
-virCapabilitiesDefaultGuestEmulator;
-virCapabilitiesDefaultGuestMachine;
 virCapabilitiesDomainDataLookup;
 virCapabilitiesFormatXML;
 virCapabilitiesFreeMachines;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ad50360..01ed1e2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1888,25 +1888,26 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr caps,
                                  virQEMUCapsCachePtr capsCache,
                                  unsigned int *version)
 {
-    const char *binary;
     virQEMUCapsPtr qemucaps;
     virArch hostarch;
+    virCapsDomainDataPtr capsdata;
 
     if (*version > 0)
         return 0;
 
     hostarch = virArchFromHost();
-    if ((binary = virCapabilitiesDefaultGuestEmulator(caps,
-                                                      VIR_DOMAIN_OSTYPE_HVM,
-                                                      hostarch,
-                                                      VIR_DOMAIN_VIRT_QEMU)) == NULL) {
+    if (!(capsdata = virCapabilitiesDomainDataLookup(caps,
+            VIR_DOMAIN_OSTYPE_HVM, hostarch, VIR_DOMAIN_VIRT_QEMU,
+            NULL, NULL))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Cannot find suitable emulator for %s"),
                        virArchToString(hostarch));
         return -1;
     }
 
-    if (!(qemucaps = virQEMUCapsCacheLookup(capsCache, binary)))
+    qemucaps = virQEMUCapsCacheLookup(capsCache, capsdata->emulator);
+    VIR_FREE(capsdata);
+    if (!qemucaps)
         return -1;
 
     *version = virQEMUCapsGetVersion(qemucaps);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8e7b689..29b876e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -13145,14 +13145,17 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
     }
 
     if (!def->os.machine) {
-        const char *defaultMachine =
-                        virCapabilitiesDefaultGuestMachine(qemuCaps,
-                                                           def->os.type,
-                                                           def->os.arch,
-                                                           def->virtType);
-        if (defaultMachine != NULL)
-            if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
-                goto error;
+        virCapsDomainDataPtr capsdata;
+
+        if (!(capsdata = virCapabilitiesDomainDataLookup(qemuCaps, def->os.type,
+                def->os.arch, def->virtType, NULL, NULL)))
+            goto error;
+
+        if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0) {
+            VIR_FREE(capsdata);
+            goto error;
+        }
+        VIR_FREE(capsdata);
     }
 
     if (!nographics && def->ngraphics == 0) {
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 728b910..0dfe60e 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -983,15 +983,15 @@ xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def)
 static int
 xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
 {
-    const char *defaultMachine;
+    virCapsDomainDataPtr capsdata = NULL;
     const char *str;
-    int hvm = 0;
+    int hvm = 0, ret = -1;
 
     if (xenConfigCopyString(conf, "name", &def->name) < 0)
-        return -1;
+        goto out;
 
     if (xenConfigGetUUID(conf, "uuid", def->uuid) < 0)
-        return -1;
+        goto out;
 
     if ((xenConfigGetString(conf, "builder", &str, "linux") == 0) &&
         STREQ(str, "hvm"))
@@ -999,27 +999,18 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
 
     def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN);
 
-    def->os.arch =
-        virCapabilitiesDefaultGuestArch(caps,
-                                        def->os.type,
-                                        def->virtType);
-    if (!def->os.arch) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("no supported architecture for os type '%s'"),
-                       virDomainOSTypeToString(def->os.type));
-        return -1;
-    }
+    if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
+            VIR_ARCH_NONE, def->virtType, NULL, NULL)))
+        goto out;
 
-    defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
-                                                        def->os.type,
-                                                        def->os.arch,
-                                                        def->virtType);
-    if (defaultMachine != NULL) {
-        if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
-            return -1;
-    }
+    def->os.arch = capsdata->arch;
+    if (VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)
+        goto out;
 
-    return 0;
+    ret = 0;
+ out:
+    VIR_FREE(capsdata);
+    return ret;
 }
 
 
diff --git a/tests/securityselinuxlabeldata/chardev.xml b/tests/securityselinuxlabeldata/chardev.xml
index 64b6b5f..33002e4 100644
--- a/tests/securityselinuxlabeldata/chardev.xml
+++ b/tests/securityselinuxlabeldata/chardev.xml
@@ -3,7 +3,7 @@
   <uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
   <memory unit='KiB'>219200</memory>
   <os>
-    <type arch='i686' machine='pc-1.0'>hvm</type>
+    <type arch='x86_64' machine='pc-1.0'>hvm</type>
     <boot dev='cdrom'/>
   </os>
   <devices>
diff --git a/tests/securityselinuxlabeldata/disks.xml b/tests/securityselinuxlabeldata/disks.xml
index 33e8763..08f0587 100644
--- a/tests/securityselinuxlabeldata/disks.xml
+++ b/tests/securityselinuxlabeldata/disks.xml
@@ -3,7 +3,7 @@
   <uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
   <memory unit='KiB'>219200</memory>
   <os>
-    <type arch='i686' machine='pc-1.0'>hvm</type>
+    <type arch='x86_64' machine='pc-1.0'>hvm</type>
     <boot dev='cdrom'/>
   </os>
   <devices>
diff --git a/tests/securityselinuxlabeldata/kernel.xml b/tests/securityselinuxlabeldata/kernel.xml
index 0fd551d..1e0cd15 100644
--- a/tests/securityselinuxlabeldata/kernel.xml
+++ b/tests/securityselinuxlabeldata/kernel.xml
@@ -3,7 +3,7 @@
   <uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
   <memory unit='KiB'>219200</memory>
   <os>
-    <type arch='i686' machine='pc-1.0'>hvm</type>
+    <type arch='x86_64' machine='pc-1.0'>hvm</type>
     <kernel>/vmlinuz.raw</kernel>
     <initrd>/initrd.raw</initrd>
   </os>
diff --git a/tests/securityselinuxlabeldata/nfs.xml b/tests/securityselinuxlabeldata/nfs.xml
index 46a1440..cac12dd 100644
--- a/tests/securityselinuxlabeldata/nfs.xml
+++ b/tests/securityselinuxlabeldata/nfs.xml
@@ -3,7 +3,7 @@
   <uuid>c7b3edbd-edaf-9455-926a-d65c16db1800</uuid>
   <memory unit='KiB'>219200</memory>
   <os>
-    <type arch='i686' machine='pc-1.0'>hvm</type>
+    <type arch='x86_64' machine='pc-1.0'>hvm</type>
     <boot dev='cdrom'/>
   </os>
   <devices>
-- 
2.3.5


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