mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
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:
parent
6dc75f5654
commit
1c13166134
@ -17828,8 +17828,12 @@ virDomainDeviceIsUSB(virDomainDeviceDefPtr dev)
|
|||||||
|
|
||||||
int
|
int
|
||||||
virDomainDefCompatibleDevice(virDomainDefPtr def,
|
virDomainDefCompatibleDevice(virDomainDefPtr def,
|
||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev,
|
||||||
|
virDomainDeviceAction action)
|
||||||
{
|
{
|
||||||
|
if (action != VIR_DOMAIN_DEVICE_ACTION_ATTACH)
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (!virDomainDefHasUSB(def) &&
|
if (!virDomainDefHasUSB(def) &&
|
||||||
STRNEQ(def->os.type, "exe") &&
|
STRNEQ(def->os.type, "exe") &&
|
||||||
virDomainDeviceIsUSB(dev)) {
|
virDomainDeviceIsUSB(dev)) {
|
||||||
|
@ -2407,8 +2407,15 @@ int virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
virDomainNetDefPtr def,
|
virDomainNetDefPtr def,
|
||||||
unsigned int flags);
|
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,
|
int virDomainDefCompatibleDevice(virDomainDefPtr def,
|
||||||
virDomainDeviceDefPtr dev);
|
virDomainDeviceDefPtr dev,
|
||||||
|
virDomainDeviceAction action);
|
||||||
|
|
||||||
int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list,
|
int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr **vcpupin_list,
|
||||||
size_t *nvcpupin,
|
size_t *nvcpupin,
|
||||||
|
@ -5030,7 +5030,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
|
|||||||
if (!vmdef)
|
if (!vmdef)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = lxcDomainAttachDeviceConfig(vmdef, dev)) < 0)
|
if ((ret = lxcDomainAttachDeviceConfig(vmdef, dev)) < 0)
|
||||||
@ -5038,7 +5039,8 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
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;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) < 0)
|
if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) < 0)
|
||||||
@ -5157,7 +5159,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
|
|||||||
if (!vmdef)
|
if (!vmdef)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0)
|
if ((ret = lxcDomainUpdateDeviceConfig(vmdef, dev)) < 0)
|
||||||
@ -5165,7 +5168,8 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
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;
|
goto cleanup;
|
||||||
|
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||||
@ -5268,7 +5272,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
|
|||||||
if (!vmdef)
|
if (!vmdef)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev)) < 0)
|
if ((ret = lxcDomainDetachDeviceConfig(vmdef, dev)) < 0)
|
||||||
@ -5276,7 +5281,8 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
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;
|
goto cleanup;
|
||||||
|
|
||||||
if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_copy)) < 0)
|
if ((ret = lxcDomainDetachDeviceLive(driver, vm, dev_copy)) < 0)
|
||||||
|
@ -6977,7 +6977,8 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
|
|||||||
if (!vmdef)
|
if (!vmdef)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_ATTACH) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainAttachDeviceConfig(qemuCaps, vmdef, dev)) < 0)
|
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 (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;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom)) < 0)
|
if ((ret = qemuDomainAttachDeviceLive(vm, dev_copy, dom)) < 0)
|
||||||
@ -7121,7 +7123,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
|
|||||||
if (!vmdef)
|
if (!vmdef)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_UPDATE) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainUpdateDeviceConfig(qemuCaps, vmdef, dev)) < 0)
|
if ((ret = qemuDomainUpdateDeviceConfig(qemuCaps, vmdef, dev)) < 0)
|
||||||
@ -7129,7 +7132,8 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
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;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force)) < 0)
|
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)
|
if (!vmdef)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virDomainDefCompatibleDevice(vmdef, dev) < 0)
|
if (virDomainDefCompatibleDevice(vmdef, dev,
|
||||||
|
VIR_DOMAIN_DEVICE_ACTION_DETACH) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainDetachDeviceConfig(vmdef, dev)) < 0)
|
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 (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;
|
goto endjob;
|
||||||
|
|
||||||
if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, dom)) < 0)
|
if ((ret = qemuDomainDetachDeviceLive(vm, dev_copy, dom)) < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user