libvirt/qemu - Centralize device modification in the more flexible APIs

Centralize device modification in the more flexible APIs, to allow future
honoring of additional flags.  Explicitly reject the
VIR_DOMAIN_DEVICE_MODIFY_FORCE flag on attach/detach.

Based on Eric Blake<eblake@redhat.com>'s work.

* src/qemu/qemu_driver.c
(qemudDomainAttachDevice)(qemudDomainAttachDeviceFlags): Swap bodies,rename...
(qemudDomainDetachDevice, qemudDomainDetachDeviceFlags): Likewise.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
KAMEZAWA Hiroyuki 2011-04-21 16:22:30 +09:00 committed by Eric Blake
parent eb954ede72
commit 2160116ff8

View File

@ -3786,8 +3786,8 @@ cleanup:
}
static int qemudDomainAttachDevice(virDomainPtr dom,
const char *xml)
static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
@ -3796,6 +3796,14 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
virCgroupPtr cgroup = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE |
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain"));
return -1;
}
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@ -3943,16 +3951,10 @@ cleanup:
return ret;
}
static int qemudDomainAttachDeviceFlags(virDomainPtr dom,
const char *xml,
unsigned int flags) {
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain"));
return -1;
}
return qemudDomainAttachDevice(dom, xml);
static int qemuDomainAttachDevice(virDomainPtr dom, const char *xml)
{
return qemuDomainAttachDeviceFlags(dom, xml,
VIR_DOMAIN_DEVICE_MODIFY_LIVE);
}
@ -4078,14 +4080,23 @@ cleanup:
}
static int qemudDomainDetachDevice(virDomainPtr dom,
const char *xml) {
static int qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
virBitmapPtr qemuCaps = NULL;
virDomainDeviceDefPtr dev = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_DEVICE_MODIFY_LIVE|
VIR_DOMAIN_DEVICE_MODIFY_CONFIG, -1);
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain:"));
return -1;
}
qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@ -4164,16 +4175,10 @@ cleanup:
return ret;
}
static int qemudDomainDetachDeviceFlags(virDomainPtr dom,
const char *xml,
unsigned int flags) {
if (flags & VIR_DOMAIN_DEVICE_MODIFY_CONFIG) {
qemuReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("cannot modify the persistent configuration of a domain"));
return -1;
}
return qemudDomainDetachDevice(dom, xml);
static int qemuDomainDetachDevice(virDomainPtr dom, const char *xml)
{
return qemuDomainDetachDeviceFlags(dom, xml,
VIR_DOMAIN_DEVICE_MODIFY_LIVE);
}
static int qemudDomainGetAutostart(virDomainPtr dom,
@ -6975,10 +6980,10 @@ static virDriver qemuDriver = {
qemudDomainStartWithFlags, /* domainCreateWithFlags */
qemudDomainDefine, /* domainDefineXML */
qemudDomainUndefine, /* domainUndefine */
qemudDomainAttachDevice, /* domainAttachDevice */
qemudDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
qemudDomainDetachDevice, /* domainDetachDevice */
qemudDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
qemuDomainAttachDevice, /* domainAttachDevice */
qemuDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
qemuDomainDetachDevice, /* domainDetachDevice */
qemuDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
qemuDomainUpdateDeviceFlags, /* domainUpdateDeviceFlags */
qemudDomainGetAutostart, /* domainGetAutostart */
qemudDomainSetAutostart, /* domainSetAutostart */