From 1c13166134bd2dd1fc5711e421ac5f983bece6a6 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Thu, 20 Mar 2014 13:39:20 +0100 Subject: [PATCH] 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 --- 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 081ec8de59..4dc93c6351 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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)) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 27f07e632c..d5d5fd3269 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 bc65815d7b..ce4064573c 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -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) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1d90a20675..a9d7615fb9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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) -- GitLab