提交 18a8c366 编写于 作者: P Peter Krempa

qemu: domain: Don't re-allocate qemuCaps in post parse callbacks

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.
上级 e168bc8a
...@@ -2971,14 +2971,6 @@ qemuDomainDefPostParse(virDomainDefPtr def, ...@@ -2971,14 +2971,6 @@ qemuDomainDefPostParse(virDomainDefPtr def,
goto cleanup; goto cleanup;
} }
if (qemuCaps) {
virObjectRef(qemuCaps);
} else {
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
def->emulator)))
goto cleanup;
}
if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0) if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0)
goto cleanup; goto cleanup;
...@@ -3004,7 +2996,6 @@ qemuDomainDefPostParse(virDomainDefPtr def, ...@@ -3004,7 +2996,6 @@ qemuDomainDefPostParse(virDomainDefPtr def,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(qemuCaps);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -3573,13 +3564,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ...@@ -3573,13 +3564,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1; int ret = -1;
if (qemuCaps) {
virObjectRef(qemuCaps);
} else {
qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
def->emulator);
}
if (dev->type == VIR_DOMAIN_DEVICE_NET && if (dev->type == VIR_DOMAIN_DEVICE_NET &&
dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && dev->data.net->type != VIR_DOMAIN_NET_TYPE_HOSTDEV &&
!dev->data.net->model) { !dev->data.net->model) {
...@@ -3688,7 +3672,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, ...@@ -3688,7 +3672,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(qemuCaps);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -3703,29 +3686,42 @@ qemuDomainDefAssignAddresses(virDomainDef *def, ...@@ -3703,29 +3686,42 @@ qemuDomainDefAssignAddresses(virDomainDef *def,
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
virQEMUCapsPtr qemuCaps = parseOpaque; virQEMUCapsPtr qemuCaps = parseOpaque;
int ret = -1;
bool newDomain = parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; bool newDomain = parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
if (qemuCaps) { return qemuDomainAssignAddresses(def, qemuCaps, driver, NULL, newDomain);
virObjectRef(qemuCaps); }
} else {
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
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))) def->emulator)))
goto cleanup; return -1;
}
if (qemuDomainAssignAddresses(def, qemuCaps, driver, NULL, newDomain) < 0) return 0;
goto cleanup; }
static void
qemuDomainPostParseDataFree(void *parseOpaque)
{
virQEMUCapsPtr qemuCaps = parseOpaque;
ret = 0;
cleanup:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
return ret;
} }
virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = { virDomainDefParserConfig virQEMUDriverDomainDefParserConfig = {
.domainPostParseBasicCallback = qemuDomainDefPostParseBasic, .domainPostParseBasicCallback = qemuDomainDefPostParseBasic,
.domainPostParseDataAlloc = qemuDomainPostParseDataAlloc,
.domainPostParseDataFree = qemuDomainPostParseDataFree,
.devicesPostParseCallback = qemuDomainDeviceDefPostParse, .devicesPostParseCallback = qemuDomainDeviceDefPostParse,
.domainPostParseCallback = qemuDomainDefPostParse, .domainPostParseCallback = qemuDomainDefPostParse,
.assignAddressesCallback = qemuDomainDefAssignAddresses, .assignAddressesCallback = qemuDomainDefAssignAddresses,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册