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(a)redhat.com>
---
src/conf/domain_conf.c | 6 +++++-
src/conf/domain_conf.h | 9 ++++++++-
src/lxc/lxc_driver.c | 18 ++++++++++++------
src/qemu/qemu_driver.c | 18 ++++++++++++------
4 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 89aa52c..ecfec0d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17825,8 +17825,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)) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 27f07e6..d5d5fd3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -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,
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index ca82fd2..109132e 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -5020,7 +5020,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)
@@ -5028,7 +5029,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)
@@ -5147,7 +5149,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)
@@ -5155,7 +5158,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",
@@ -5258,7 +5262,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)
@@ -5266,7 +5271,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)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8ec8912..dec216c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6951,7 +6951,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)
@@ -6959,7 +6960,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)
@@ -7095,7 +7097,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)
@@ -7103,7 +7106,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)
@@ -7234,7 +7238,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)
@@ -7242,7 +7247,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)
--
1.9.1