Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> --- src/libvirt_private.syms | 4 ++ src/util/virhostdev.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ src/util/virhostdev.h | 20 +++++++++ 3 files changed, 127 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e7d9d56..4b42cbb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1297,15 +1297,19 @@ virHostdevManagerGetDefault; virHostdevPciNodeDeviceDetach; virHostdevPciNodeDeviceReAttach; virHostdevPciNodeDeviceReset; +virHostdevPrepareDomainHostdevs; virHostdevPreparePciHostdevs; virHostdevPrepareScsiHostdevs; virHostdevPrepareUsbHostdevs; +virHostdevReAttachDomainHostdevs; virHostdevReAttachPciHostdevs; virHostdevReAttachScsiHostdevs; virHostdevReAttachUsbHostdevs; virHostdevUpdateActivePciHostdevs; virHostdevUpdateActiveScsiHostdevs; virHostdevUpdateActiveUsbHostdevs; +virHostdevUpdateDomainActiveHostdevs; + # util/viridentity.h virIdentityGetAttr; diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 5fddd8a..577de48 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -1471,3 +1471,106 @@ out: virObjectUnlock(hostdev_mgr->activePciHostdevs); return ret; } + +int +virHostdevPrepareDomainHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags) +{ + if (!def->nhostdevs) + return 0; + + if (mgr == NULL) + return -1; + + if (flags & VIR_HOSTDEV_SP_PCI) { + if (virHostdevPreparePciHostdevs(mgr, driver, + def->name, def->uuid, + def->hostdevs, + def->nhostdevs, + flags) < 0) + return -1; + } + + if (flags & VIR_HOSTDEV_SP_USB) { + if (virHostdevPrepareUsbHostdevs(mgr, driver, def->name, + def->hostdevs, def->nhostdevs, + flags) < 0) + return -1; + } + + if (flags & VIR_HOSTDEV_SP_SCSI) { + if (virHostdevPrepareScsiHostdevs(mgr, driver, def->name, + def->hostdevs, def->nhostdevs) < 0) + return -1; + } + + return 0; +} + +/* @oldStateDir + * For upgrade purpose: see virHostdevReAttachPciHostdevs + */ +void +virHostdevReAttachDomainHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags, + char *oldStateDir) +{ + if (!def->nhostdevs || !mgr) + return; + + if (flags & VIR_HOSTDEV_SP_PCI) { + virHostdevReAttachPciHostdevs(mgr, driver, def->name, + def->hostdevs, def->nhostdevs, + oldStateDir); + } + + if (flags & VIR_HOSTDEV_SP_USB) { + virHostdevReAttachUsbHostdevs(mgr, driver, def->name, + def->hostdevs, def->nhostdevs); + } + + if (flags & VIR_HOSTDEV_SP_SCSI) { + virHostdevReAttachScsiHostdevs(mgr, driver, def->name, + def->hostdevs, def->nhostdevs); + } +} + +int +virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags) +{ + if (!def->nhostdevs) + return 0; + + if (flags & VIR_HOSTDEV_SP_PCI) { + if (virHostdevUpdateActivePciHostdevs(mgr, + def->hostdevs, + def->nhostdevs, + driver, def->name) < 0) + return -1; + } + + if (flags & VIR_HOSTDEV_SP_USB) { + if (virHostdevUpdateActiveUsbHostdevs(mgr, + def->hostdevs, + def->nhostdevs, + driver, def->name) < 0) + return -1; + } + + if (flags & VIR_HOSTDEV_SP_SCSI) { + if (virHostdevUpdateActiveScsiHostdevs(mgr, + def->hostdevs, + def->nhostdevs, + driver, def->name) < 0) + return -1; + } + + return 0; +} diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h index 8680e5d..820b408 100644 --- a/src/util/virhostdev.h +++ b/src/util/virhostdev.h @@ -35,6 +35,10 @@ typedef enum { VIR_HOSTDEV_STRICT_ACS_CHECK = (1 << 0), /* strict acs check */ VIR_HOSTDEV_COLD_BOOT = (1 << 1), /* cold boot */ + + VIR_HOSTDEV_SP_PCI = (1 << 8), /* support pci passthrough */ + VIR_HOSTDEV_SP_USB = (1 << 9), /* support usb passthrough */ + VIR_HOSTDEV_SP_SCSI = (1 << 10), /* support scsi passthrough */ } virHostdevFlag; @@ -108,6 +112,22 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr, int nhostdevs, const char *drv_name, const char *dom_name); +int +virHostdevUpdateDomainActiveHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags); +int +virHostdevPrepareDomainHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags); +void +virHostdevReAttachDomainHostdevs(virHostdevManagerPtr mgr, + const char *driver, + virDomainDefPtr def, + unsigned int flags, + char *oldStateDir); /* functions used by NodeDevDetach/Reattach/Reset */ int virHostdevPciNodeDeviceDetach(virHostdevManagerPtr mgr, -- 1.9.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list