提交 166eabdb 编写于 作者: T Tomasz Flendrich 提交者: Martin Kletzander

Split qemuDomainAttachDeviceFlags in two

Previously, qemuDomainAttachDeviceFlags was doing two things:
handling the job and attaching devices. Now the second part is
in a new function.

This change is required to make it possible to test more complex
device attachment situations, like attaching a device to both
config and live at once.
上级 346d2be2
...@@ -8066,49 +8066,34 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef, ...@@ -8066,49 +8066,34 @@ qemuDomainUpdateDeviceConfig(virDomainDefPtr vmdef,
return 0; return 0;
} }
static int static int
qemuDomainAttachDeviceFlags(virDomainPtr dom, qemuDomainAttachDeviceLiveAndConfig(virConnectPtr conn,
virDomainObjPtr vm,
virQEMUDriverPtr driver,
const char *xml, const char *xml,
unsigned int flags) unsigned int flags)
{ {
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
virDomainDefPtr vmdef = NULL; virDomainDefPtr vmdef = NULL;
virQEMUDriverConfigPtr cfg = NULL;
virDomainDeviceDefPtr dev = NULL, dev_copy = NULL; virDomainDeviceDefPtr dev = NULL, dev_copy = NULL;
int ret = -1; int ret = -1;
virCapsPtr caps = NULL;
unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE | unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE |
VIR_DOMAIN_DEF_PARSE_ABI_UPDATE; VIR_DOMAIN_DEF_PARSE_ABI_UPDATE;
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1); VIR_DOMAIN_AFFECT_CONFIG, -1);
virNWFilterReadLockFilterUpdates();
cfg = virQEMUDriverGetConfig(driver); cfg = virQEMUDriverGetConfig(driver);
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
if (virDomainAttachDeviceFlagsEnsureACL(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;
dev = dev_copy = virDomainDeviceDefParse(xml, vm->def, dev = dev_copy = virDomainDeviceDefParse(xml, vm->def,
caps, driver->xmlopt, caps, driver->xmlopt,
parse_flags); parse_flags);
if (dev == NULL) if (dev == NULL)
goto endjob; goto cleanup;
if (flags & VIR_DOMAIN_AFFECT_CONFIG && if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
flags & VIR_DOMAIN_AFFECT_LIVE) { flags & VIR_DOMAIN_AFFECT_LIVE) {
...@@ -8118,33 +8103,31 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -8118,33 +8103,31 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom,
*/ */
dev_copy = virDomainDeviceDefCopy(dev, vm->def, caps, driver->xmlopt); dev_copy = virDomainDeviceDefCopy(dev, vm->def, caps, driver->xmlopt);
if (!dev_copy) if (!dev_copy)
goto endjob; goto cleanup;
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
/* Make a copy for updated domain. */ /* Make a copy for updated domain. */
vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt); vmdef = virDomainObjCopyPersistentDef(vm, caps, driver->xmlopt);
if (!vmdef) if (!vmdef)
goto endjob; goto cleanup;
if (virDomainDefCompatibleDevice(vmdef, dev, if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto endjob; goto cleanup;
if ((ret = qemuDomainAttachDeviceConfig(vmdef, dev, conn, caps,
if ((ret = qemuDomainAttachDeviceConfig(vmdef, dev, dom->conn, caps,
parse_flags, parse_flags,
driver->xmlopt)) < 0) driver->xmlopt)) < 0)
goto endjob; goto cleanup;
} }
if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy, if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0) VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto endjob; goto cleanup;
if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom->conn, if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, conn, driver)) < 0)
driver)) < 0) goto cleanup;
goto endjob;
/* /*
* update domain status forcibly because the domain status may be * update domain status forcibly because the domain status may be
* changed even if we failed to attach the device. For example, * changed even if we failed to attach the device. For example,
...@@ -8152,7 +8135,7 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -8152,7 +8135,7 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom,
*/ */
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) { if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) {
ret = -1; ret = -1;
goto endjob; goto cleanup;
} }
} }
...@@ -8165,17 +8148,50 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom, ...@@ -8165,17 +8148,50 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom,
} }
} }
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup: cleanup:
virDomainDefFree(vmdef); virDomainDefFree(vmdef);
if (dev != dev_copy) if (dev != dev_copy)
virDomainDeviceDefFree(dev_copy); virDomainDeviceDefFree(dev_copy);
virDomainDeviceDefFree(dev); virDomainDeviceDefFree(dev);
virDomainObjEndAPI(&vm);
virObjectUnref(caps);
virObjectUnref(cfg); virObjectUnref(cfg);
virObjectUnref(caps);
return ret;
}
static int
qemuDomainAttachDeviceFlags(virDomainPtr dom,
const char *xml,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL;
int ret = -1;
virNWFilterReadLockFilterUpdates();
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
if (virDomainAttachDeviceFlagsEnsureACL(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 (qemuDomainAttachDeviceLiveAndConfig(dom->conn, vm, driver, xml, flags) < 0)
goto endjob;
ret = 0;
endjob:
qemuDomainObjEndJob(driver, vm);
cleanup:
virDomainObjEndAPI(&vm);
virNWFilterUnlockFilterUpdates(); virNWFilterUnlockFilterUpdates();
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册