mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 18:45:16 +00:00
add 'driver' info to used_by
Specify which driver and which domain in used_by area to avoid conflict among different drivers. Signed-off-by: Chunyan Liu <cyliu@suse.com>
This commit is contained in:
parent
9194ccecf1
commit
de6fa535b0
@ -60,7 +60,7 @@ virLXCUpdateActiveUsbHostdevs(virLXCDriverPtr driver,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUSBDeviceSetUsedBy(usb, def->name);
|
virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, def->name);
|
||||||
|
|
||||||
virObjectLock(driver->activeUsbHostdevs);
|
virObjectLock(driver->activeUsbHostdevs);
|
||||||
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
|
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
|
||||||
@ -90,12 +90,16 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
|
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
|
||||||
if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
|
if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
|
||||||
const char *other_name = virUSBDeviceGetUsedBy(tmp);
|
const char *other_drvname;
|
||||||
|
const char *other_domname;
|
||||||
|
|
||||||
if (other_name)
|
virUSBDeviceGetUsedBy(tmp, &other_drvname, &other_domname);
|
||||||
|
if (other_drvname && other_domname)
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("USB device %s is in use by domain %s"),
|
_("USB device %s is in use by "
|
||||||
virUSBDeviceGetName(tmp), other_name);
|
"driver %s, domain %s"),
|
||||||
|
virUSBDeviceGetName(tmp),
|
||||||
|
other_drvname, other_domname);
|
||||||
else
|
else
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("USB device %s is already in use"),
|
_("USB device %s is already in use"),
|
||||||
@ -103,7 +107,7 @@ virLXCPrepareHostdevUSBDevices(virLXCDriverPtr driver,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUSBDeviceSetUsedBy(usb, name);
|
virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, name);
|
||||||
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
|
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
|
||||||
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
|
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
|
||||||
/*
|
/*
|
||||||
@ -351,7 +355,8 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
|
|||||||
for (i = 0; i < nhostdevs; i++) {
|
for (i = 0; i < nhostdevs; i++) {
|
||||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||||
virUSBDevicePtr usb, tmp;
|
virUSBDevicePtr usb, tmp;
|
||||||
const char *used_by = NULL;
|
const char *usedby_domname = NULL;
|
||||||
|
const char *usedby_drvname = NULL;
|
||||||
|
|
||||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
continue;
|
continue;
|
||||||
@ -389,8 +394,9 @@ virLXCDomainReAttachHostUsbDevices(virLXCDriverPtr driver,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
used_by = virUSBDeviceGetUsedBy(tmp);
|
virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
|
||||||
if (STREQ_NULLABLE(used_by, name)) {
|
if (STREQ_NULLABLE(LXC_DRIVER_NAME, usedby_drvname) &&
|
||||||
|
STREQ_NULLABLE(name, usedby_domname)) {
|
||||||
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
|
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
|
||||||
hostdev->source.subsys.u.usb.bus,
|
hostdev->source.subsys.u.usb.bus,
|
||||||
hostdev->source.subsys.u.usb.device,
|
hostdev->source.subsys.u.usb.device,
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
# error "Port me"
|
# error "Port me"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# define QEMU_DRIVER_NAME "QEMU"
|
||||||
|
|
||||||
typedef struct _virQEMUDriver virQEMUDriver;
|
typedef struct _virQEMUDriver virQEMUDriver;
|
||||||
typedef virQEMUDriver *virQEMUDriverPtr;
|
typedef virQEMUDriver *virQEMUDriverPtr;
|
||||||
|
|
||||||
|
@ -98,8 +98,6 @@
|
|||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
#define QEMU_DRIVER_NAME "QEMU"
|
|
||||||
|
|
||||||
#define QEMU_NB_MEM_PARAM 3
|
#define QEMU_NB_MEM_PARAM 3
|
||||||
|
|
||||||
#define QEMU_NB_BLOCK_IO_TUNE_PARAM 6
|
#define QEMU_NB_BLOCK_IO_TUNE_PARAM 6
|
||||||
@ -11352,12 +11350,16 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
|
|||||||
virObjectLock(driver->inactivePciHostdevs);
|
virObjectLock(driver->inactivePciHostdevs);
|
||||||
other = virPCIDeviceListFind(driver->activePciHostdevs, pci);
|
other = virPCIDeviceListFind(driver->activePciHostdevs, pci);
|
||||||
if (other) {
|
if (other) {
|
||||||
const char *other_name = virPCIDeviceGetUsedBy(other);
|
const char *other_drvname = NULL;
|
||||||
|
const char *other_domname = NULL;
|
||||||
|
virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname);
|
||||||
|
|
||||||
if (other_name)
|
if (other_drvname && other_domname)
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is still in use by domain %s"),
|
_("PCI device %s is still in use by "
|
||||||
virPCIDeviceGetName(pci), other_name);
|
"driver %s, domain %s"),
|
||||||
|
virPCIDeviceGetName(pci),
|
||||||
|
other_drvname, other_domname);
|
||||||
else
|
else
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is still in use"),
|
_("PCI device %s is still in use"),
|
||||||
@ -16766,7 +16768,7 @@ static virDriver qemuDriver = {
|
|||||||
|
|
||||||
|
|
||||||
static virStateDriver qemuStateDriver = {
|
static virStateDriver qemuStateDriver = {
|
||||||
.name = "QEMU",
|
.name = QEMU_DRIVER_NAME,
|
||||||
.stateInitialize = qemuStateInitialize,
|
.stateInitialize = qemuStateInitialize,
|
||||||
.stateAutoStart = qemuStateAutoStart,
|
.stateAutoStart = qemuStateAutoStart,
|
||||||
.stateCleanup = qemuStateCleanup,
|
.stateCleanup = qemuStateCleanup,
|
||||||
|
@ -177,7 +177,7 @@ qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
}
|
}
|
||||||
virPCIDeviceSetUsedBy(dev, def->name);
|
virPCIDeviceSetUsedBy(dev, QEMU_DRIVER_NAME, def->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);
|
||||||
@ -230,7 +230,7 @@ qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUSBDeviceSetUsedBy(usb, def->name);
|
virUSBDeviceSetUsedBy(usb, QEMU_DRIVER_NAME, def->name);
|
||||||
|
|
||||||
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
|
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
@ -274,13 +274,13 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((tmp = virSCSIDeviceListFind(driver->activeScsiHostdevs, scsi))) {
|
if ((tmp = virSCSIDeviceListFind(driver->activeScsiHostdevs, scsi))) {
|
||||||
if (virSCSIDeviceSetUsedBy(tmp, def->name) < 0) {
|
if (virSCSIDeviceSetUsedBy(tmp, QEMU_DRIVER_NAME, def->name) < 0) {
|
||||||
virSCSIDeviceFree(scsi);
|
virSCSIDeviceFree(scsi);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virSCSIDeviceFree(scsi);
|
virSCSIDeviceFree(scsi);
|
||||||
} else {
|
} else {
|
||||||
if (virSCSIDeviceSetUsedBy(scsi, def->name) < 0 ||
|
if (virSCSIDeviceSetUsedBy(scsi, QEMU_DRIVER_NAME, def->name) < 0 ||
|
||||||
virSCSIDeviceListAdd(driver->activeScsiHostdevs, scsi) < 0) {
|
virSCSIDeviceListAdd(driver->activeScsiHostdevs, scsi) < 0) {
|
||||||
virSCSIDeviceFree(scsi);
|
virSCSIDeviceFree(scsi);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -693,12 +693,16 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
* the dev is in list driver->activePciHostdevs.
|
* the dev is in list driver->activePciHostdevs.
|
||||||
*/
|
*/
|
||||||
if ((other = virPCIDeviceListFind(driver->activePciHostdevs, dev))) {
|
if ((other = virPCIDeviceListFind(driver->activePciHostdevs, dev))) {
|
||||||
const char *other_name = virPCIDeviceGetUsedBy(other);
|
const char *other_drvname;
|
||||||
|
const char *other_domname;
|
||||||
|
|
||||||
if (other_name)
|
virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname);
|
||||||
|
if (other_drvname && other_domname)
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is in use by domain %s"),
|
_("PCI device %s is in use by "
|
||||||
virPCIDeviceGetName(dev), other_name);
|
"driver %s, domain %s"),
|
||||||
|
virPCIDeviceGetName(dev),
|
||||||
|
other_drvname, other_domname);
|
||||||
else
|
else
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is already in use"),
|
_("PCI device %s is already in use"),
|
||||||
@ -766,7 +770,7 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
|
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
|
||||||
|
|
||||||
if (activeDev)
|
if (activeDev)
|
||||||
virPCIDeviceSetUsedBy(activeDev, name);
|
virPCIDeviceSetUsedBy(activeDev, QEMU_DRIVER_NAME, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop 8: Now set the original states for hostdev def */
|
/* Loop 8: Now set the original states for hostdev def */
|
||||||
@ -857,12 +861,16 @@ qemuPrepareHostdevUSBDevices(virQEMUDriverPtr driver,
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
|
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
|
||||||
if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
|
if ((tmp = virUSBDeviceListFind(driver->activeUsbHostdevs, usb))) {
|
||||||
const char *other_name = virUSBDeviceGetUsedBy(tmp);
|
const char *other_drvname;
|
||||||
|
const char *other_domname;
|
||||||
|
|
||||||
if (other_name)
|
virUSBDeviceGetUsedBy(tmp, &other_drvname, &other_domname);
|
||||||
|
if (other_drvname && other_domname)
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("USB device %s is in use by domain %s"),
|
_("USB device %s is in use by "
|
||||||
virUSBDeviceGetName(tmp), other_name);
|
"driver %s, domain %s"),
|
||||||
|
virUSBDeviceGetName(tmp),
|
||||||
|
other_drvname, other_domname);
|
||||||
else
|
else
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("USB device %s is already in use"),
|
_("USB device %s is already in use"),
|
||||||
@ -870,7 +878,7 @@ qemuPrepareHostdevUSBDevices(virQEMUDriverPtr driver,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virUSBDeviceSetUsedBy(usb, name);
|
virUSBDeviceSetUsedBy(usb, QEMU_DRIVER_NAME, name);
|
||||||
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
|
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
|
||||||
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
|
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
|
||||||
/*
|
/*
|
||||||
@ -1140,10 +1148,10 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSCSIDeviceSetUsedBy(tmp, name) < 0)
|
if (virSCSIDeviceSetUsedBy(tmp, QEMU_DRIVER_NAME, name) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
if (virSCSIDeviceSetUsedBy(scsi, name) < 0)
|
if (virSCSIDeviceSetUsedBy(scsi, QEMU_DRIVER_NAME, name) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
VIR_DEBUG("Adding %s to activeScsiHostdevs", virSCSIDeviceGetName(scsi));
|
VIR_DEBUG("Adding %s to activeScsiHostdevs", virSCSIDeviceGetName(scsi));
|
||||||
@ -1275,10 +1283,15 @@ qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
|
|||||||
* been used by this domain.
|
* been used by this domain.
|
||||||
*/
|
*/
|
||||||
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
|
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
|
||||||
if (activeDev &&
|
if (activeDev) {
|
||||||
STRNEQ_NULLABLE(name, virPCIDeviceGetUsedBy(activeDev))) {
|
const char *usedby_drvname;
|
||||||
virPCIDeviceListDel(pcidevs, dev);
|
const char *usedby_domname;
|
||||||
continue;
|
virPCIDeviceGetUsedBy(activeDev, &usedby_drvname, &usedby_domname);
|
||||||
|
if (STRNEQ_NULLABLE(QEMU_DRIVER_NAME, usedby_drvname) ||
|
||||||
|
STRNEQ_NULLABLE(name, usedby_domname)) {
|
||||||
|
virPCIDeviceListDel(pcidevs, dev);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virPCIDeviceListDel(driver->activePciHostdevs, dev);
|
virPCIDeviceListDel(driver->activePciHostdevs, dev);
|
||||||
@ -1332,7 +1345,8 @@ qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
|
|||||||
for (i = 0; i < nhostdevs; i++) {
|
for (i = 0; i < nhostdevs; i++) {
|
||||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||||
virUSBDevicePtr usb, tmp;
|
virUSBDevicePtr usb, tmp;
|
||||||
const char *used_by = NULL;
|
const char *usedby_drvname;
|
||||||
|
const char *usedby_domname;
|
||||||
|
|
||||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
continue;
|
continue;
|
||||||
@ -1370,8 +1384,9 @@ qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
used_by = virUSBDeviceGetUsedBy(tmp);
|
virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
|
||||||
if (STREQ_NULLABLE(used_by, name)) {
|
if (STREQ_NULLABLE(QEMU_DRIVER_NAME, usedby_drvname) &&
|
||||||
|
STREQ_NULLABLE(name, usedby_domname)) {
|
||||||
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
|
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
|
||||||
hostdev->source.subsys.u.usb.bus,
|
hostdev->source.subsys.u.usb.bus,
|
||||||
hostdev->source.subsys.u.usb.device,
|
hostdev->source.subsys.u.usb.device,
|
||||||
@ -1445,7 +1460,7 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
|
|||||||
hostdev->source.subsys.u.scsi.unit,
|
hostdev->source.subsys.u.scsi.unit,
|
||||||
name);
|
name);
|
||||||
|
|
||||||
virSCSIDeviceListDel(driver->activeScsiHostdevs, tmp, name);
|
virSCSIDeviceListDel(driver->activeScsiHostdevs, tmp, QEMU_DRIVER_NAME, name);
|
||||||
virSCSIDeviceFree(scsi);
|
virSCSIDeviceFree(scsi);
|
||||||
}
|
}
|
||||||
virObjectUnlock(driver->activeScsiHostdevs);
|
virObjectUnlock(driver->activeScsiHostdevs);
|
||||||
|
@ -59,7 +59,10 @@ struct _virPCIDevice {
|
|||||||
char name[PCI_ADDR_LEN]; /* domain:bus:slot.function */
|
char name[PCI_ADDR_LEN]; /* domain:bus:slot.function */
|
||||||
char id[PCI_ID_LEN]; /* product vendor */
|
char id[PCI_ID_LEN]; /* product vendor */
|
||||||
char *path;
|
char *path;
|
||||||
const char *used_by; /* The domain which uses the device */
|
|
||||||
|
/* The driver:domain which uses the device */
|
||||||
|
char *used_by_drvname;
|
||||||
|
char *used_by_domname;
|
||||||
|
|
||||||
unsigned int pcie_cap_pos;
|
unsigned int pcie_cap_pos;
|
||||||
unsigned int pci_pm_cap_pos;
|
unsigned int pci_pm_cap_pos;
|
||||||
@ -1615,8 +1618,11 @@ virPCIDeviceCopy(virPCIDevicePtr dev)
|
|||||||
/* shallow copy to take care of most attributes */
|
/* shallow copy to take care of most attributes */
|
||||||
*copy = *dev;
|
*copy = *dev;
|
||||||
copy->path = copy->stubDriver = NULL;
|
copy->path = copy->stubDriver = NULL;
|
||||||
|
copy->used_by_drvname = copy->used_by_domname = NULL;
|
||||||
if (VIR_STRDUP(copy->path, dev->path) < 0 ||
|
if (VIR_STRDUP(copy->path, dev->path) < 0 ||
|
||||||
VIR_STRDUP(copy->stubDriver, dev->stubDriver) < 0) {
|
VIR_STRDUP(copy->stubDriver, dev->stubDriver) < 0 ||
|
||||||
|
VIR_STRDUP(copy->used_by_drvname, dev->used_by_drvname) < 0 ||
|
||||||
|
VIR_STRDUP(copy->used_by_domname, dev->used_by_domname) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
return copy;
|
return copy;
|
||||||
@ -1635,6 +1641,8 @@ virPCIDeviceFree(virPCIDevicePtr dev)
|
|||||||
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
|
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
|
||||||
VIR_FREE(dev->path);
|
VIR_FREE(dev->path);
|
||||||
VIR_FREE(dev->stubDriver);
|
VIR_FREE(dev->stubDriver);
|
||||||
|
VIR_FREE(dev->used_by_drvname);
|
||||||
|
VIR_FREE(dev->used_by_domname);
|
||||||
VIR_FREE(dev);
|
VIR_FREE(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1704,16 +1712,28 @@ virPCIDeviceSetReprobe(virPCIDevicePtr dev, bool reprobe)
|
|||||||
dev->reprobe = reprobe;
|
dev->reprobe = reprobe;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
virPCIDeviceSetUsedBy(virPCIDevicePtr dev, const char *name)
|
virPCIDeviceSetUsedBy(virPCIDevicePtr dev,
|
||||||
|
const char *drv_name,
|
||||||
|
const char *dom_name)
|
||||||
{
|
{
|
||||||
dev->used_by = name;
|
VIR_FREE(dev->used_by_drvname);
|
||||||
|
VIR_FREE(dev->used_by_domname);
|
||||||
|
if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
|
||||||
|
return -1;
|
||||||
|
if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
void
|
||||||
virPCIDeviceGetUsedBy(virPCIDevicePtr dev)
|
virPCIDeviceGetUsedBy(virPCIDevicePtr dev,
|
||||||
|
const char **drv_name,
|
||||||
|
const char **dom_name)
|
||||||
{
|
{
|
||||||
return dev->used_by;
|
*drv_name = dev->used_by_drvname;
|
||||||
|
*dom_name = dev->used_by_domname;
|
||||||
}
|
}
|
||||||
|
|
||||||
void virPCIDeviceReattachInit(virPCIDevicePtr pci)
|
void virPCIDeviceReattachInit(virPCIDevicePtr pci)
|
||||||
|
@ -66,9 +66,12 @@ int virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
|
|||||||
const char *driver)
|
const char *driver)
|
||||||
ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(2);
|
||||||
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
|
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
|
||||||
void virPCIDeviceSetUsedBy(virPCIDevice *dev,
|
int virPCIDeviceSetUsedBy(virPCIDevice *dev,
|
||||||
const char *used_by);
|
const char *drv_name,
|
||||||
const char *virPCIDeviceGetUsedBy(virPCIDevice *dev);
|
const char *dom_name);
|
||||||
|
void virPCIDeviceGetUsedBy(virPCIDevice *dev,
|
||||||
|
const char **drv_name,
|
||||||
|
const char **dom_name);
|
||||||
unsigned int virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
|
unsigned int virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
|
||||||
void virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
|
void virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
|
||||||
bool unbind);
|
bool unbind);
|
||||||
|
@ -47,6 +47,11 @@
|
|||||||
|
|
||||||
/* For virReportOOMError() and virReportSystemError() */
|
/* For virReportOOMError() and virReportSystemError() */
|
||||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
struct _virUsedByInfo {
|
||||||
|
char *drvname; /* which driver */
|
||||||
|
char *domname; /* which domain */
|
||||||
|
};
|
||||||
|
typedef struct _virUsedByInfo *virUsedByInfoPtr;
|
||||||
|
|
||||||
struct _virSCSIDevice {
|
struct _virSCSIDevice {
|
||||||
unsigned int adapter;
|
unsigned int adapter;
|
||||||
@ -57,7 +62,7 @@ struct _virSCSIDevice {
|
|||||||
char *name; /* adapter:bus:target:unit */
|
char *name; /* adapter:bus:target:unit */
|
||||||
char *id; /* model:vendor */
|
char *id; /* model:vendor */
|
||||||
char *sg_path; /* e.g. /dev/sg2 */
|
char *sg_path; /* e.g. /dev/sg2 */
|
||||||
char **used_by; /* name of the domains using this dev */
|
virUsedByInfoPtr *used_by; /* driver:domain(s) using this dev */
|
||||||
size_t n_used_by; /* how many domains are using this dev */
|
size_t n_used_by; /* how many domains are using this dev */
|
||||||
|
|
||||||
bool readonly;
|
bool readonly;
|
||||||
@ -274,19 +279,26 @@ virSCSIDeviceFree(virSCSIDevicePtr dev)
|
|||||||
VIR_FREE(dev->id);
|
VIR_FREE(dev->id);
|
||||||
VIR_FREE(dev->name);
|
VIR_FREE(dev->name);
|
||||||
VIR_FREE(dev->sg_path);
|
VIR_FREE(dev->sg_path);
|
||||||
for (i = 0; i < dev->n_used_by; i++)
|
for (i = 0; i < dev->n_used_by; i++) {
|
||||||
|
VIR_FREE(dev->used_by[i]->drvname);
|
||||||
|
VIR_FREE(dev->used_by[i]->domname);
|
||||||
VIR_FREE(dev->used_by[i]);
|
VIR_FREE(dev->used_by[i]);
|
||||||
|
}
|
||||||
VIR_FREE(dev->used_by);
|
VIR_FREE(dev->used_by);
|
||||||
VIR_FREE(dev);
|
VIR_FREE(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
|
virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
|
||||||
const char *name)
|
const char *drvname,
|
||||||
|
const char *domname)
|
||||||
{
|
{
|
||||||
char *copy = NULL;
|
virUsedByInfoPtr copy;
|
||||||
|
if (VIR_ALLOC(copy) < 0)
|
||||||
if (VIR_STRDUP(copy, name) < 0)
|
return -1;
|
||||||
|
if (VIR_STRDUP(copy->drvname, drvname) < 0)
|
||||||
|
return -1;
|
||||||
|
if (VIR_STRDUP(copy->domname, domname) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy);
|
return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy);
|
||||||
@ -427,14 +439,18 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
|
|||||||
void
|
void
|
||||||
virSCSIDeviceListDel(virSCSIDeviceListPtr list,
|
virSCSIDeviceListDel(virSCSIDeviceListPtr list,
|
||||||
virSCSIDevicePtr dev,
|
virSCSIDevicePtr dev,
|
||||||
const char *name)
|
const char *drvname,
|
||||||
|
const char *domname)
|
||||||
{
|
{
|
||||||
virSCSIDevicePtr tmp = NULL;
|
virSCSIDevicePtr tmp = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < dev->n_used_by; i++) {
|
for (i = 0; i < dev->n_used_by; i++) {
|
||||||
if (STREQ_NULLABLE(dev->used_by[i], name)) {
|
if (STREQ_NULLABLE(dev->used_by[i]->drvname, drvname) &&
|
||||||
|
STREQ_NULLABLE(dev->used_by[i]->domname, domname)) {
|
||||||
if (dev->n_used_by > 1) {
|
if (dev->n_used_by > 1) {
|
||||||
|
VIR_FREE(dev->used_by[i]->drvname);
|
||||||
|
VIR_FREE(dev->used_by[i]->domname);
|
||||||
VIR_FREE(dev->used_by[i]);
|
VIR_FREE(dev->used_by[i]);
|
||||||
VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by);
|
VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by);
|
||||||
} else {
|
} else {
|
||||||
|
@ -53,7 +53,9 @@ virSCSIDevicePtr virSCSIDeviceNew(const char *sysfs_prefix,
|
|||||||
bool shareable);
|
bool shareable);
|
||||||
|
|
||||||
void virSCSIDeviceFree(virSCSIDevicePtr dev);
|
void virSCSIDeviceFree(virSCSIDevicePtr dev);
|
||||||
int virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, const char *name);
|
int virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
|
||||||
|
const char *drvname,
|
||||||
|
const char *domname);
|
||||||
bool virSCSIDeviceIsAvailable(virSCSIDevicePtr dev);
|
bool virSCSIDeviceIsAvailable(virSCSIDevicePtr dev);
|
||||||
const char *virSCSIDeviceGetName(virSCSIDevicePtr dev);
|
const char *virSCSIDeviceGetName(virSCSIDevicePtr dev);
|
||||||
unsigned int virSCSIDeviceGetAdapter(virSCSIDevicePtr dev);
|
unsigned int virSCSIDeviceGetAdapter(virSCSIDevicePtr dev);
|
||||||
@ -87,7 +89,8 @@ virSCSIDevicePtr virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
|
|||||||
virSCSIDevicePtr dev);
|
virSCSIDevicePtr dev);
|
||||||
void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
|
void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
|
||||||
virSCSIDevicePtr dev,
|
virSCSIDevicePtr dev,
|
||||||
const char *name);
|
const char *drvname,
|
||||||
|
const char *domname);
|
||||||
virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
|
virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
|
||||||
virSCSIDevicePtr dev);
|
virSCSIDevicePtr dev);
|
||||||
|
|
||||||
|
@ -55,7 +55,10 @@ struct _virUSBDevice {
|
|||||||
char name[USB_ADDR_LEN]; /* domain:bus:slot.function */
|
char name[USB_ADDR_LEN]; /* domain:bus:slot.function */
|
||||||
char id[USB_ID_LEN]; /* product vendor */
|
char id[USB_ID_LEN]; /* product vendor */
|
||||||
char *path;
|
char *path;
|
||||||
const char *used_by; /* name of the domain using this dev */
|
|
||||||
|
/* driver:domain using this dev */
|
||||||
|
char *used_by_drvname;
|
||||||
|
char *used_by_domname;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _virUSBDeviceList {
|
struct _virUSBDeviceList {
|
||||||
@ -375,19 +378,33 @@ virUSBDeviceFree(virUSBDevicePtr dev)
|
|||||||
return;
|
return;
|
||||||
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
|
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
|
||||||
VIR_FREE(dev->path);
|
VIR_FREE(dev->path);
|
||||||
|
VIR_FREE(dev->used_by_drvname);
|
||||||
|
VIR_FREE(dev->used_by_domname);
|
||||||
VIR_FREE(dev);
|
VIR_FREE(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
void virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
|
virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
|
||||||
const char *name)
|
const char *drv_name,
|
||||||
|
const char *dom_name)
|
||||||
{
|
{
|
||||||
dev->used_by = name;
|
VIR_FREE(dev->used_by_drvname);
|
||||||
|
VIR_FREE(dev->used_by_domname);
|
||||||
|
if (VIR_STRDUP(dev->used_by_drvname, drv_name) < 0)
|
||||||
|
return -1;
|
||||||
|
if (VIR_STRDUP(dev->used_by_domname, dom_name) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * virUSBDeviceGetUsedBy(virUSBDevicePtr dev)
|
void
|
||||||
|
virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
|
||||||
|
const char **drv_name,
|
||||||
|
const char **dom_name)
|
||||||
{
|
{
|
||||||
return dev->used_by;
|
*drv_name = dev->used_by_drvname;
|
||||||
|
*dom_name = dev->used_by_domname;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *virUSBDeviceGetName(virUSBDevicePtr dev)
|
const char *virUSBDeviceGetName(virUSBDevicePtr dev)
|
||||||
|
@ -60,8 +60,12 @@ int virUSBDeviceFind(unsigned int vendor,
|
|||||||
virUSBDevicePtr *usb);
|
virUSBDevicePtr *usb);
|
||||||
|
|
||||||
void virUSBDeviceFree(virUSBDevicePtr dev);
|
void virUSBDeviceFree(virUSBDevicePtr dev);
|
||||||
void virUSBDeviceSetUsedBy(virUSBDevicePtr dev, const char *name);
|
int virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
|
||||||
const char *virUSBDeviceGetUsedBy(virUSBDevicePtr dev);
|
const char *drv_name,
|
||||||
|
const char *dom_name);
|
||||||
|
void virUSBDeviceGetUsedBy(virUSBDevicePtr dev,
|
||||||
|
const char **drv_name,
|
||||||
|
const char **dom_name);
|
||||||
const char *virUSBDeviceGetName(virUSBDevicePtr dev);
|
const char *virUSBDeviceGetName(virUSBDevicePtr dev);
|
||||||
|
|
||||||
unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
|
unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
|
||||||
|
@ -91,13 +91,13 @@ test2(const void *data ATTRIBUTE_UNUSED)
|
|||||||
if (!virSCSIDeviceIsAvailable(dev))
|
if (!virSCSIDeviceIsAvailable(dev))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSCSIDeviceSetUsedBy(dev, "fc18") < 0)
|
if (virSCSIDeviceSetUsedBy(dev, "QEMU", "fc18") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSCSIDeviceIsAvailable(dev))
|
if (virSCSIDeviceIsAvailable(dev))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSCSIDeviceSetUsedBy(dev, "fc20") < 0)
|
if (virSCSIDeviceSetUsedBy(dev, "QEMU", "fc20") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virSCSIDeviceIsAvailable(dev))
|
if (virSCSIDeviceIsAvailable(dev))
|
||||||
@ -117,7 +117,7 @@ test2(const void *data ATTRIBUTE_UNUSED)
|
|||||||
if (!virSCSIDeviceListFind(list, dev))
|
if (!virSCSIDeviceListFind(list, dev))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virSCSIDeviceListDel(list, dev, "fc20");
|
virSCSIDeviceListDel(list, dev, "QEMU", "fc20");
|
||||||
|
|
||||||
if (!virSCSIDeviceListFind(list, dev))
|
if (!virSCSIDeviceListFind(list, dev))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user