The domain post parse callback, domain address callback and the domain device callback (for every single device) would each grab qemuCaps for the current emulator. This is quite wasteful. Use the new callback to do this just once. --- src/qemu/qemu_domain.c | 54 +++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9e395aec9..dc8041b86 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2971,14 +2971,6 @@ qemuDomainDefPostParse(virDomainDefPtr def, goto cleanup; } - if (qemuCaps) { - virObjectRef(qemuCaps); - } else { - if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, - def->emulator))) - goto cleanup; - } - if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0) goto cleanup; @@ -3004,7 +2996,6 @@ qemuDomainDefPostParse(virDomainDefPtr def, ret = 0; cleanup: - virObjectUnref(qemuCaps); virObjectUnref(cfg); return ret; } @@ -3573,13 +3564,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); int ret = -1; - if (qemuCaps) { - virObjectRef(qemuCaps); - } else { - qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, - def->emulator); - } - if (dev->type == VIR_DOMAIN_DEVICE_NET && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && !dev->data.net->model) { @@ -3688,7 +3672,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ret = 0; cleanup: - virObjectUnref(qemuCaps); virObjectUnref(cfg); return ret; } @@ -3703,29 +3686,42 @@ qemuDomainDefAssignAddresses(virDomainDef *def, { virQEMUDriverPtr driver = opaque; virQEMUCapsPtr qemuCaps = parseOpaque; - int ret = -1; bool newDomain = parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; - if (qemuCaps) { - virObjectRef(qemuCaps); - } else { - if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, + return qemuDomainAssignAddresses(def, qemuCaps, driver, NULL, newDomain); +} + + +static int +qemuDomainPostParseDataAlloc(const virDomainDef *def, + virCapsPtr caps ATTRIBUTE_UNUSED, + unsigned int parseFlags ATTRIBUTE_UNUSED, + void *opaque, + void **parseOpaque) +{ + virQEMUDriverPtr driver = opaque; + + if (!(*parseOpaque = virQEMUCapsCacheLookup(driver->qemuCapsCache, def->emulator))) - goto cleanup; - } + return -1; - if (qemuDomainAssignAddresses(def, qemuCaps, driver, NULL, newDomain) < 0) - goto cleanup; + return 0; +} + + +static void +qemuDomainPostParseDataFree(void *parseOpaque) +{ + virQEMUCapsPtr qemuCaps = parseOpaque; - ret = 0; - cleanup: virObjectUnref(qemuCaps); - return ret; } virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = { .domainPostParseBasicCallback = qemuDomainDefPostParseBasic, + .domainPostParseDataAlloc = qemuDomainPostParseDataAlloc, + .domainPostParseDataFree = qemuDomainPostParseDataFree, .devicesPostParseCallback = qemuDomainDeviceDefPostParse, .domainPostParseCallback = qemuDomainDefPostParse, .assignAddressesCallback = qemuDomainDefAssignAddresses, -- 2.14.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list