]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Split up qemudGetOldMachines()
authorMark McLoughlin <markmc@redhat.com>
Mon, 7 Sep 2009 11:12:42 +0000 (12:12 +0100)
committerMark McLoughlin <markmc@redhat.com>
Thu, 10 Sep 2009 11:37:42 +0000 (12:37 +0100)
We need to look at all the domain infos in guest capabilities, not
just the defaults.

In order to allow that, split out a qemudGetOldMachinesFromInfo()
from qemudGetOldMachines(). We'll make more use of it in the next
patch.

* src/qemu_conf.c: split out qemudGetOldMachinesFromInfo() from
  qemudGetOldMachines()

src/qemu_conf.c

index caf518c1ce88aa592b581771dc354858c085be62..882f9f9145be61a26c222b93c7fb3fe11216428f 100644 (file)
@@ -495,6 +495,51 @@ rewait:
     return ret;
 }
 
+static int
+qemudGetOldMachinesFromInfo(virCapsGuestDomainInfoPtr info,
+                            const char *emulator,
+                            time_t emulator_mtime,
+                            virCapsGuestMachinePtr **machines,
+                            int *nmachines)
+{
+    virCapsGuestMachinePtr *list;
+    int i;
+
+    if (!info->emulator || !STREQ(emulator, info->emulator))
+        return 0;
+
+    if (emulator_mtime != info->emulator_mtime) {
+        VIR_DEBUG("mtime on %s has changed, refreshing machine types",
+                  info->emulator);
+        return 0;
+    }
+
+    if (VIR_ALLOC_N(list, info->nmachines) < 0)
+        return 0;
+
+    for (i = 0; i < info->nmachines; i++) {
+        if (VIR_ALLOC(list[i]) < 0) {
+            virCapabilitiesFreeMachines(list, info->nmachines);
+            return 0;
+        }
+        if (info->machines[i]->name &&
+            !(list[i]->name = strdup(info->machines[i]->name))) {
+            virCapabilitiesFreeMachines(list, info->nmachines);
+            return 0;
+        }
+        if (info->machines[i]->canonical &&
+            !(list[i]->canonical = strdup(info->machines[i]->canonical))) {
+            virCapabilitiesFreeMachines(list, info->nmachines);
+            return 0;
+        }
+    }
+
+    *machines = list;
+    *nmachines = info->nmachines;
+
+    return 1;
+}
+
 static int
 qemudGetOldMachines(const char *ostype,
                     const char *arch,
@@ -509,51 +554,16 @@ qemudGetOldMachines(const char *ostype,
 
     for (i = 0; i < old_caps->nguests; i++) {
         virCapsGuestPtr guest = old_caps->guests[i];
-        virCapsGuestDomainInfoPtr info = &guest->arch.defaultInfo;
-        virCapsGuestMachinePtr *list;
 
         if (!STREQ(ostype, guest->ostype) ||
             !STREQ(arch, guest->arch.name) ||
-            wordsize != guest->arch.wordsize ||
-            !STREQ(emulator, info->emulator))
+            wordsize != guest->arch.wordsize)
             continue;
 
-        if (emulator_mtime != info->emulator_mtime) {
-            VIR_DEBUG("mtime on %s has changed, refreshing machine types",
-                      info->emulator);
-            return 0;
-        }
-
-        /* It sucks to have to dup these, when we're most likely going
-         * to free the old caps anyway - except if an error occurs, we'll
-         * stick with the old caps.
-         * Also, if we get OOM here, just let the caller try and probe
-         * the binary directly, which will probably fail too.
-         */
-        if (VIR_ALLOC_N(list, info->nmachines) < 0)
-            return 0;
-
-        for (i = 0; i < info->nmachines; i++) {
-            if (VIR_ALLOC(list[i]) < 0) {
-                virCapabilitiesFreeMachines(list, info->nmachines);
-                return 0;
-            }
-            if (info->machines[i]->name &&
-                !(list[i]->name = strdup(info->machines[i]->name))) {
-                virCapabilitiesFreeMachines(list, info->nmachines);
-                return 0;
-            }
-            if (info->machines[i]->canonical &&
-                !(list[i]->canonical = strdup(info->machines[i]->canonical))) {
-                virCapabilitiesFreeMachines(list, info->nmachines);
-                return 0;
-            }
-        }
-
-        *machines = list;
-        *nmachines = info->nmachines;
-
-        return 1;
+        if (qemudGetOldMachinesFromInfo(&guest->arch.defaultInfo,
+                                        emulator, emulator_mtime,
+                                        machines, nmachines))
+            return 1;
     }
 
     return 0;