mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
Re-factor hostdev hotplug
Re-factor the hostdev hotplug code so that we can easily add PCI hostdev hotplug to qemudDomainAttachHostDevice(). * src/qemu_driver.c: rename qemudDomainAttachHostDevice() to qemudDomainAttachHostUsbDevice(); make qemudDomainAttachHostDevice() handle all hostdev types * src/libvirt_private.syms: export a couple of hostdev related ToString() functions
This commit is contained in:
parent
19bac57b26
commit
7636ef4630
@ -88,6 +88,8 @@ virDomainGetRootFilesystem;
|
|||||||
virDomainGraphicsTypeFromString;
|
virDomainGraphicsTypeFromString;
|
||||||
virDomainGraphicsDefFree;
|
virDomainGraphicsDefFree;
|
||||||
virDomainHostdevDefFree;
|
virDomainHostdevDefFree;
|
||||||
|
virDomainHostdevModeTypeToString;
|
||||||
|
virDomainHostdevSubsysTypeToString;
|
||||||
virDomainInputDefFree;
|
virDomainInputDefFree;
|
||||||
virDomainLifecycleTypeFromString;
|
virDomainLifecycleTypeFromString;
|
||||||
virDomainLifecycleTypeToString;
|
virDomainLifecycleTypeToString;
|
||||||
|
@ -5148,9 +5148,9 @@ cleanup:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qemudDomainAttachHostDevice(virConnectPtr conn,
|
static int qemudDomainAttachHostUsbDevice(virConnectPtr conn,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainDeviceDefPtr dev)
|
virDomainDeviceDefPtr dev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char *cmd, *reply;
|
char *cmd, *reply;
|
||||||
@ -5200,6 +5200,34 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int qemudDomainAttachHostDevice(virConnectPtr conn,
|
||||||
|
struct qemud_driver *driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
virDomainDeviceDefPtr dev)
|
||||||
|
{
|
||||||
|
virDomainHostdevDefPtr hostdev = dev->data.hostdev;
|
||||||
|
|
||||||
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
|
||||||
|
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
|
||||||
|
_("hostdev mode '%s' not supported"),
|
||||||
|
virDomainHostdevModeTypeToString(hostdev->mode));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuDomainSetDeviceOwnership(conn, driver, dev, 0) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
switch (hostdev->source.subsys.type) {
|
||||||
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
|
||||||
|
return qemudDomainAttachHostUsbDevice(conn, vm, dev);
|
||||||
|
default:
|
||||||
|
qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
|
||||||
|
_("hostdev subsys type '%s' not supported"),
|
||||||
|
virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int qemudDomainAttachDevice(virDomainPtr dom,
|
static int qemudDomainAttachDevice(virDomainPtr dom,
|
||||||
const char *xml) {
|
const char *xml) {
|
||||||
struct qemud_driver *driver = dom->conn->privateData;
|
struct qemud_driver *driver = dom->conn->privateData;
|
||||||
@ -5301,13 +5329,8 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
} else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
} else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
||||||
ret = qemudDomainAttachNetDevice(dom->conn, driver, vm, dev, qemuCmdFlags);
|
ret = qemudDomainAttachNetDevice(dom->conn, driver, vm, dev, qemuCmdFlags);
|
||||||
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
|
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
|
||||||
dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
|
ret = qemudDomainAttachHostDevice(dom->conn, driver, vm, dev);
|
||||||
dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
|
|
||||||
if (qemuDomainSetDeviceOwnership(dom->conn, driver, dev, 0) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
ret = qemudDomainAttachHostDevice(dom->conn, vm, dev);
|
|
||||||
} else {
|
} else {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
|
||||||
_("device type '%s' cannot be attached"),
|
_("device type '%s' cannot be attached"),
|
||||||
|
Loading…
Reference in New Issue
Block a user