Pass action to virDomainDefCompatibleDevice

When checking compatibility of a device with a domain definition, we
should know what we're going to do with the device. Because we may need
to check for different things when we're attaching a new device versus
detaching an existing device.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2014-03-20 13:39:20 +01:00
parent 6dc75f5654
commit 1c13166134
4 changed files with 37 additions and 14 deletions

View File

@ -17828,8 +17828,12 @@ virDomainDeviceIsUSB(virDomainDeviceDefPtr dev)
int
virDomainDefCompatibleDevice(virDomainDefPtr def,
virDomainDeviceDefPtr dev)
virDomainDeviceDefPtr dev,
virDomainDeviceAction action)
{
if (action != VIR_DOMAIN_DEVICE_ACTION_ATTACH)
return 0;
if (!virDomainDefHasUSB(def) &&
STRNEQ(def->os.type, "exe") &&
virDomainDeviceIsUSB(dev)) {

View File

@ -2407,8 +2407,15 @@ int virDomainNetDefFormat(virBufferPtr buf,
virDomainNetDefPtr def,
unsigned int flags);
typedef enum {
VIR_DOMAIN_DEVICE_ACTION_ATTACH,
VIR_DOMAIN_DEVICE_ACTION_DETACH,
VIR_DOMAIN_DEVICE_ACTION_UPDATE,
} virDomainDeviceAction;
int virDomainDefCompatibleDevice(virDomainDefPtr def,
virDomainDeviceDefPtr dev);
virDomainDeviceDefPtr dev,
virDomainDeviceAction action);
int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list,
size_t *nvcpupin,

View File

@ -5030,7 +5030,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
if (!vmdef)
goto cleanup;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto cleanup;
if ((ret = lxcDomainAttachDeviceConfig(vmdef, dev)) < 0)
@ -5038,7 +5039,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto cleanup;
if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) < 0)
@ -5157,7 +5159,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
if (!vmdef)
goto cleanup;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
goto cleanup;
if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0)
@ -5165,7 +5168,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
goto cleanup;
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@ -5268,7 +5272,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
if (!vmdef)
goto cleanup;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto cleanup;
if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev)) < 0)
@ -5276,7 +5281,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto cleanup;
if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_copy)) < 0)

View File

@ -6977,7 +6977,8 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
if (!vmdef)
goto endjob;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto endjob;
if ((ret = qemuDomainAttachDeviceConfig(qemuCaps, vmdef, dev)) < 0)
@ -6985,7 +6986,8 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
goto endjob;
if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom)) < 0)
@ -7121,7 +7123,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
if (!vmdef)
goto endjob;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
goto endjob;
if ((ret = qemuDomainUpdateDeviceConfig(qemuCaps, vmdef, dev)) < 0)
@ -7129,7 +7132,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
goto endjob;
if ((ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force)) < 0)
@ -7260,7 +7264,8 @@ static int qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
if (!vmdef)
goto endjob;
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
if (virDomainDefCompatibleDevice(vmdef, dev,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto endjob;
if ((ret = qemuDomainDetachDeviceConfig(vmdef, dev)) < 0)
@ -7268,7 +7273,8 @@ static int qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
if (virDomainDefCompatibleDevice(vm->def, dev_copy) < 0)
if (virDomainDefCompatibleDevice(vm->def, dev_copy,
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
goto endjob;
if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, dom)) < 0)