提交 18ba452f 编写于 作者: T Tomasz Flendrich 提交者: Martin Kletzander

Split qemuDomainDetachDeviceFlags in two

Previously, qemuDomainDetachDeviceFlags was doing two things:
handling the job and detaching devices. Now the second part is
in a new function.
上级 8bad9048
......@@ -8324,40 +8324,26 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
return ret;
}
static int
qemuDomainDetachDeviceFlags(virDomainPtr dom,
const char *xml,
unsigned int flags)
qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *xml,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL;
virCapsPtr caps = NULL;
virQEMUDriverConfigPtr cfg = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
virDomainDefPtr vmdef = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
cfg = virQEMUDriverGetConfig(driver);
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
if (virDomainDetachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
goto endjob;
cfg = virQEMUDriverGetConfig(driver);
if ((flags & VIR_DOMAIN_AFFECT_CONFIG) &&
!(flags & VIR_DOMAIN_AFFECT_LIVE))
......@@ -8367,7 +8353,7 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
caps, driver->xmlopt,
parse_flags);
if (dev == NULL)
goto endjob;
goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
flags & VIR_DOMAIN_AFFECT_LIVE) {
......@@ -8377,32 +8363,32 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
*/
dev_copy = virDomainDeviceDefCopy(dev, vm->def, caps, driver->xmlopt);
if (!dev_copy)
goto endjob;
goto cleanup;
}
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
/* Make a copy for updated domain. */
vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt);
if (!vmdef)
goto endjob;
goto cleanup;
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto endjob;
goto cleanup;
if ((ret = qemuDomainDetachDeviceConfig(vmdef, dev, caps,
parse_flags,
driver->xmlopt)) < 0)
goto endjob;
goto cleanup;
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto endjob;
goto cleanup;
if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, driver)) < 0)
goto endjob;
goto cleanup;
/*
* update domain status forcibly because the domain status may be
* changed even if we failed to attach the device. For example,
......@@ -8410,7 +8396,7 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
*/
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) {
ret = -1;
goto endjob;
goto cleanup;
}
}
......@@ -8423,17 +8409,47 @@ qemuDomainDetachDeviceFlags(virDomainPtr dom,
}
}
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup:
virDomainDefFree(vmdef);
virObjectUnref(caps);
virObjectUnref(cfg);
if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev);
virDomainDefFree(vmdef);
return ret;
}
static int
qemuDomainDetachDeviceFlags(virDomainPtr dom,
const char *xml,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
int ret = -1;
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
if (virDomainDetachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
goto cleanup;
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
goto endjob;
if (qemuDomainDetachDeviceLiveAndConfig(driver, vm, xml, flags) < 0)
goto endjob;
ret = 0;
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup:
virDomainObjEndAPI(&vm);
virObjectUnref(caps);
virObjectUnref(cfg);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册