]> xenbits.xensource.com Git - libvirt.git/commitdiff
Take domain type into account when looking up default machine
authorMark McLoughlin <markmc@redhat.com>
Mon, 12 Oct 2009 09:52:13 +0000 (10:52 +0100)
committerMark McLoughlin <markmc@redhat.com>
Mon, 12 Oct 2009 09:57:35 +0000 (10:57 +0100)
If one has e.g.

  <guest>
    <os_type>hvm</os_type>
    <arch name='x86_64'>
      <wordsize>64</wordsize>
      <emulator>/usr/bin/qemu-system-x86_64</emulator>
      <machine>pc-0.11</machine>
      <machine canonical='pc-0.11'>pc</machine>
      <machine>pc-0.10</machine>
      <machine>isapc</machine>
      <domain type='qemu'>
      </domain>
      <domain type='kvm'>
        <emulator>/usr/bin/kvm</emulator>
        <machine>pc</machine>
        <machine>isapc</machine>
      </domain>
    </arch>
  </guest>

and start a guest with:

  <domain type='kvm'>
    ...
    <os>
      <type arch='x86_64'>hvm</type>
      ...
    </os>
  </domain>

then the default machine type should be 'pc' and not 'pc-0.11'

Issue was reported by Anton Protopopov.

* src/capabilities.[ch]: pass the domain type to
  virCapabilitiesDefaultGuestArch() and use it to look up the default
  machine type from a specific guest domain if needed.

* src/conf/domain_conf.c, src/xen/xm_internal.c: update

* tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml: update
  the domain type to 'kvm' and remove the machine type to check
  that the default gets looked up correctly

src/conf/capabilities.c
src/conf/capabilities.h
src/conf/domain_conf.c
src/xen/xm_internal.c
tests/qemuxml2argvdata/qemuxml2argv-machine-aliases2.xml

index 38fe7fc02373b1e819f4995984bcce53305ac85f..6ebddf5f2a7dd891682796a037b59dc8f67df5d4 100644 (file)
@@ -549,22 +549,43 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
  * @caps: capabilities to query
  * @ostype: OS type to search for
  * @arch: architecture to search for
+ * @domain: domain type to search for
  *
  * Returns the first machine variant associated with
- * the requested operating system type and architecture
+ * the requested operating system type, architecture
+ * and domain type
  */
 extern const char *
 virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
                                    const char *ostype,
-                                   const char *arch)
+                                   const char *arch,
+                                   const char *domain)
 {
     int i;
+
     for (i = 0 ; i < caps->nguests ; i++) {
-        if (STREQ(caps->guests[i]->ostype, ostype) &&
-            STREQ(caps->guests[i]->arch.name, arch) &&
-            caps->guests[i]->arch.defaultInfo.nmachines)
+        virCapsGuestPtr guest = caps->guests[i];
+        int j;
+
+        if (!STREQ(guest->ostype, ostype) || !STREQ(guest->arch.name, arch))
+            continue;
+
+        for (j = 0; j < guest->arch.ndomains; j++) {
+            virCapsGuestDomainPtr dom= guest->arch.domains[j];
+
+            if (!STREQ(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;
 }
 
index b958d950450de5f1df3619f8bbe487e24700cd5e..2f24605b55f00ba220b58a06662b64d53fdf6dea 100644 (file)
@@ -207,7 +207,8 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
 extern const char *
 virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
                                    const char *ostype,
-                                   const char *arch);
+                                   const char *arch,
+                                   const char *domain);
 extern const char *
 virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
                                     const char *ostype,
index 87e05c28fc354f7b0670ce3dcc3fa1f009828b31..f50a8ef4a48cd72ac41fe3489e5512ba0829175c 100644 (file)
@@ -2669,7 +2669,8 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
     if (!def->os.machine) {
         const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
                                                                         def->os.type,
-                                                                        def->os.arch);
+                                                                        def->os.arch,
+                                                                        virDomainVirtTypeToString(def->virtType));
         if (defaultMachine != NULL) {
             if (!(def->os.machine = strdup(defaultMachine))) {
                 virReportOOMError(conn);
index 9c78f0defb98657e693e815c725bea789e7727f8..ebbaae89f964c514338f4f7ef2151b57c5d7112e 100644 (file)
@@ -720,7 +720,8 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
 
     defaultMachine = virCapabilitiesDefaultGuestMachine(priv->caps,
                                                         def->os.type,
-                                                        def->os.arch);
+                                                        def->os.arch,
+                                                        virDomainVirtTypeToString(def->virtType));
     if (defaultMachine != NULL) {
         if (!(def->os.machine = strdup(defaultMachine)))
             goto no_memory;
index 6f6224375a559d559dd2e1c2aac9279af21632b6..a2c62541512ea310921ab755daa35e1018af7a54 100644 (file)
@@ -1,11 +1,11 @@
-<domain type='qemu'>
+<domain type='kvm'>
   <name>QEMUGuest1</name>
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory>219200</memory>
   <currentMemory>219200</currentMemory>
   <vcpu>1</vcpu>
   <os>
-    <type arch='x86_64' machine='pc'>hvm</type>
+    <type arch='x86_64'>hvm</type>
     <boot dev='hd'/>
   </os>
   <clock offset='utc'/>