File 2f97ea32-libxl-hostdev-fix.patch of Package libvirt.239
commit 2f97ea328f6c8df59e07b24122a8ff95efca95b8
Author: Chunyan Liu <cyliu@suse.com>
Date: Tue Jul 15 13:03:16 2014 +0800
libxl: fix return value error Attach|DetachDeviceFlags
Code logic in libxlDomainAttachDeviceFlags and libxlDomainDetachDeviceFlags
is wrong with return value in error cases.
'ret' was being set to 0 if 'flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG' was
false. Then if something like virDomainDeviceDefParse() failed in the
VIR_DOMAIN_DEVICE_MODIFY_LIVE logic, the error would be reported but the
function would return success.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
Index: libvirt-1.2.5/src/libxl/libxl_driver.c
===================================================================
--- libvirt-1.2.5.orig/src/libxl/libxl_driver.c
+++ libvirt-1.2.5/src/libxl/libxl_driver.c
@@ -3290,10 +3290,8 @@ libxlDomainAttachDeviceFlags(virDomainPt
driver->xmlopt)))
goto endjob;
- if ((ret = libxlDomainAttachDeviceConfig(vmdef, dev)) < 0)
+ if (libxlDomainAttachDeviceConfig(vmdef, dev) < 0)
goto endjob;
- } else {
- ret = 0;
}
if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -3304,7 +3302,7 @@ libxlDomainAttachDeviceFlags(virDomainPt
VIR_DOMAIN_XML_INACTIVE)))
goto endjob;
- if ((ret = libxlDomainAttachDeviceLive(driver, priv, vm, dev)) < 0)
+ if (libxlDomainAttachDeviceLive(driver, priv, vm, dev) < 0)
goto endjob;
/*
@@ -3312,11 +3310,13 @@ libxlDomainAttachDeviceFlags(virDomainPt
* changed even if we attach the device failed.
*/
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
- ret = -1;
+ goto endjob;
}
+ ret = 0;
+
/* Finally, if no error until here, we can save config. */
- if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) {
+ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
ret = virDomainSaveConfig(cfg->configDir, vmdef);
if (!ret) {
virDomainObjAssignDef(vm, vmdef, false, NULL);
@@ -3401,10 +3401,8 @@ libxlDomainDetachDeviceFlags(virDomainPt
driver->xmlopt)))
goto endjob;
- if ((ret = libxlDomainDetachDeviceConfig(vmdef, dev)) < 0)
+ if (libxlDomainDetachDeviceConfig(vmdef, dev) < 0)
goto endjob;
- } else {
- ret = 0;
}
if (flags & VIR_DOMAIN_DEVICE_MODIFY_LIVE) {
@@ -3415,7 +3413,7 @@ libxlDomainDetachDeviceFlags(virDomainPt
VIR_DOMAIN_XML_INACTIVE)))
goto endjob;
- if ((ret = libxlDomainDetachDeviceLive(driver, priv, vm, dev)) < 0)
+ if (libxlDomainDetachDeviceLive(driver, priv, vm, dev) < 0)
goto endjob;
/*
@@ -3423,11 +3421,13 @@ libxlDomainDetachDeviceFlags(virDomainPt
* changed even if we attach the device failed.
*/
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
- ret = -1;
+ goto endjob;
}
+ ret = 0;
+
/* Finally, if no error until here, we can save config. */
- if (!ret && (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG)) {
+ if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
ret = virDomainSaveConfig(cfg->configDir, vmdef);
if (!ret) {
virDomainObjAssignDef(vm, vmdef, false, NULL);