mirror of https://gitee.com/openkylin/libvirt.git
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()
This commit is contained in:
parent
aa67241bde
commit
44646747a7
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue