提交 4dd9f103 编写于 作者: C Chunyan Liu 提交者: Daniel P. Berrange

improve virHostdevUpdate* parameters to make it more widely used

Changes parameter from vm def to specific hostdevs info and name info, so that
it could be used more widely, e.g, could be used without full vm def info.
上级 a65e6d36
...@@ -50,7 +50,8 @@ qemuUpdateActivePCIHostdevs(virQEMUDriverPtr driver, ...@@ -50,7 +50,8 @@ qemuUpdateActivePCIHostdevs(virQEMUDriverPtr driver,
if (!def->nhostdevs) if (!def->nhostdevs)
return 0; return 0;
return virHostdevUpdateActivePCIDevices(mgr, QEMU_DRIVER_NAME, def); return virHostdevUpdateActivePCIDevices(mgr, def->hostdevs, def->nhostdevs,
QEMU_DRIVER_NAME, def->name);
} }
int int
...@@ -62,7 +63,8 @@ qemuUpdateActiveUSBHostdevs(virQEMUDriverPtr driver, ...@@ -62,7 +63,8 @@ qemuUpdateActiveUSBHostdevs(virQEMUDriverPtr driver,
if (!def->nhostdevs) if (!def->nhostdevs)
return 0; return 0;
return virHostdevUpdateActiveUSBDevices(mgr, QEMU_DRIVER_NAME, def); return virHostdevUpdateActiveUSBDevices(mgr, def->hostdevs, def->nhostdevs,
QEMU_DRIVER_NAME, def->name);
} }
int int
...@@ -74,7 +76,8 @@ qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver, ...@@ -74,7 +76,8 @@ qemuUpdateActiveSCSIHostdevs(virQEMUDriverPtr driver,
if (!def->nhostdevs) if (!def->nhostdevs)
return 0; return 0;
return virHostdevUpdateActiveSCSIDevices(mgr, QEMU_DRIVER_NAME, def); return virHostdevUpdateActiveSCSIDevices(mgr, def->hostdevs, def->nhostdevs,
QEMU_DRIVER_NAME, def->name);
} }
......
...@@ -776,8 +776,10 @@ cleanup: ...@@ -776,8 +776,10 @@ cleanup:
int int
virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def) const char *dom_name)
{ {
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
virPCIDevicePtr dev = NULL; virPCIDevicePtr dev = NULL;
...@@ -787,8 +789,8 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, ...@@ -787,8 +789,8 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
virObjectLock(mgr->activePCIHostdevs); virObjectLock(mgr->activePCIHostdevs);
virObjectLock(mgr->inactivePCIHostdevs); virObjectLock(mgr->inactivePCIHostdevs);
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
hostdev = def->hostdevs[i]; hostdev = hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue; continue;
...@@ -813,7 +815,7 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, ...@@ -813,7 +815,7 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
goto cleanup; goto cleanup;
} }
virPCIDeviceSetUsedBy(dev, drv_name, def->name); virPCIDeviceSetUsedBy(dev, drv_name, dom_name);
/* Setup the original states for the PCI device */ /* Setup the original states for the PCI device */
virPCIDeviceSetUnbindFromStub(dev, hostdev->origstates.states.pci.unbind_from_stub); virPCIDeviceSetUnbindFromStub(dev, hostdev->origstates.states.pci.unbind_from_stub);
...@@ -835,17 +837,19 @@ cleanup: ...@@ -835,17 +837,19 @@ cleanup:
int int
virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr, virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def) const char *dom_name)
{ {
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
size_t i; size_t i;
int ret = -1; int ret = -1;
virObjectLock(mgr->activeUSBHostdevs); virObjectLock(mgr->activeUSBHostdevs);
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
virUSBDevicePtr usb = NULL; virUSBDevicePtr usb = NULL;
hostdev = def->hostdevs[i]; hostdev = hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue; continue;
...@@ -859,11 +863,11 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr, ...@@ -859,11 +863,11 @@ virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s", VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
hostdev->source.subsys.u.usb.bus, hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device, hostdev->source.subsys.u.usb.device,
def->name); dom_name);
continue; continue;
} }
virUSBDeviceSetUsedBy(usb, drv_name, def->name); virUSBDeviceSetUsedBy(usb, drv_name, dom_name);
if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, usb) < 0) { if (virUSBDeviceListAdd(mgr->activeUSBHostdevs, usb) < 0) {
virUSBDeviceFree(usb); virUSBDeviceFree(usb);
...@@ -878,8 +882,10 @@ cleanup: ...@@ -878,8 +882,10 @@ cleanup:
int int
virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def) const char *dom_name)
{ {
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
size_t i; size_t i;
...@@ -888,8 +894,8 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, ...@@ -888,8 +894,8 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
virSCSIDevicePtr tmp = NULL; virSCSIDevicePtr tmp = NULL;
virObjectLock(mgr->activeSCSIHostdevs); virObjectLock(mgr->activeSCSIHostdevs);
for (i = 0; i < def->nhostdevs; i++) { for (i = 0; i < nhostdevs; i++) {
hostdev = def->hostdevs[i]; hostdev = hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)
...@@ -905,13 +911,13 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, ...@@ -905,13 +911,13 @@ virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
goto cleanup; goto cleanup;
if ((tmp = virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) { if ((tmp = virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) {
if (virSCSIDeviceSetUsedBy(tmp, drv_name, def->name) < 0) { if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) {
virSCSIDeviceFree(scsi); virSCSIDeviceFree(scsi);
goto cleanup; goto cleanup;
} }
virSCSIDeviceFree(scsi); virSCSIDeviceFree(scsi);
} else { } else {
if (virSCSIDeviceSetUsedBy(scsi, drv_name, def->name) < 0 || if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 ||
virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) { virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) {
virSCSIDeviceFree(scsi); virSCSIDeviceFree(scsi);
goto cleanup; goto cleanup;
......
...@@ -92,16 +92,22 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr, ...@@ -92,16 +92,22 @@ virHostdevReAttachSCSIDevices(virHostdevManagerPtr hostdev_mgr,
int nhostdevs); int nhostdevs);
int int
virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr, virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def); const char *dom_name);
int int
virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr, virHostdevUpdateActiveUSBDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def); const char *dom_name);
int int
virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr, virHostdevUpdateActiveSCSIDevices(virHostdevManagerPtr mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
const char *drv_name, const char *drv_name,
virDomainDefPtr def); const char *dom_name);
/* functions used by NodeDevDetach/Reattach/Reset */ /* functions used by NodeDevDetach/Reattach/Reset */
int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr, int virHostdevPCINodeDeviceDetach(virHostdevManagerPtr mgr,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册