From: Peter Krempa Date: Tue, 22 Nov 2022 16:01:31 +0000 (+0100) Subject: lxcDomainDetachDeviceFlags: Parse XML twice rather than use virDomainDeviceDefCopy X-Git-Tag: v9.0.0-rc1~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b09af96f95bb730238d7de163a2d4c3cf1c8805;p=thirdparty%2Flibvirt.git 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 Reviewed-by: Ján Tomko --- 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; }