提交 44646747 编写于 作者: M Mark McLoughlin

Split up qemudGetOldMachines()

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()
上级 aa67241b
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册