'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(a)redhat.com>
---
src/lxc/lxc_driver.c | 36 ++++++++++++++----------------------
1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 2801ed3d6d..5a16e7375e 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -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;
}
--
2.37.3