1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

lxcDomainDetachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy

'virDomainDeviceDefCopy' formats the definition and parses it back.
Since we already are parsing the XML here, we're better off parsing it
twice and save the formatting step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-11-22 17:01:31 +01:00
parent 904d80b773
commit 5b09af96f9

View File

@ -4416,8 +4416,10 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
g_autoptr(virCaps) caps = NULL;
virDomainObj *vm = NULL;
g_autoptr(virDomainDef) vmdef = NULL;
virDomainDeviceDef *dev = NULL;
virDomainDeviceDef *dev_copy = NULL;
g_autoptr(virDomainDeviceDef) dev_config = NULL;
g_autoptr(virDomainDeviceDef) dev_live = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE |
VIR_DOMAIN_DEF_PARSE_INACTIVE;
int ret = -1;
g_autoptr(virLXCDriverConfig) cfg = virLXCDriverGetConfig(driver);
@ -4439,22 +4441,15 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
goto endjob;
dev = dev_copy = virDomainDeviceDefParse(xml, vm->def,
driver->xmlopt, NULL,
VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
if (dev == NULL)
goto endjob;
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
if (!(dev_config = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt,
NULL, parse_flags)))
goto endjob;
}
if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
flags & VIR_DOMAIN_AFFECT_LIVE) {
/* If we are affecting both CONFIG and LIVE
* create a deep copy of device as adding
* to CONFIG takes one instance.
*/
dev_copy = virDomainDeviceDefCopy(dev, vm->def,
driver->xmlopt, NULL);
if (!dev_copy)
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (!(dev_live = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt,
NULL, parse_flags)))
goto endjob;
}
@ -4464,12 +4459,12 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
if (!vmdef)
goto endjob;
if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev_copy)) < 0)
if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev_config)) < 0)
goto endjob;
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev)) < 0)
if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_live)) < 0)
goto endjob;
/*
* update domain status forcibly because the domain status may be
@ -4493,9 +4488,6 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
virDomainObjEndJob(vm);
cleanup:
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
return ret;
}