continue;
}
- virUSBDeviceSetUsedBy(usb, def->name);
+ virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, def->name);
virObjectLock(driver->activeUsbHostdevs);
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
for (i = 0; i < count; i++) {
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
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,
- _("USB device %s is in use by domain %s"),
- virUSBDeviceGetName(tmp), other_name);
+ _("USB device %s is in use by "
+ "driver %s, domain %s"),
+ virUSBDeviceGetName(tmp),
+ other_drvname, other_domname);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is already in use"),
goto error;
}
- virUSBDeviceSetUsedBy(usb, name);
+ virUSBDeviceSetUsedBy(usb, LXC_DRIVER_NAME, name);
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
/*
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
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)
continue;
continue;
}
- used_by = virUSBDeviceGetUsedBy(tmp);
- if (STREQ_NULLABLE(used_by, name)) {
+ virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
+ if (STREQ_NULLABLE(LXC_DRIVER_NAME, usedby_drvname) &&
+ STREQ_NULLABLE(name, usedby_domname)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
# error "Port me"
# endif
+# define QEMU_DRIVER_NAME "QEMU"
+
typedef struct _virQEMUDriver virQEMUDriver;
typedef virQEMUDriver *virQEMUDriverPtr;
#define VIR_FROM_THIS VIR_FROM_QEMU
-#define QEMU_DRIVER_NAME "QEMU"
-
#define QEMU_NB_MEM_PARAM 3
#define QEMU_NB_BLOCK_IO_TUNE_PARAM 6
virObjectLock(driver->inactivePciHostdevs);
other = virPCIDeviceListFind(driver->activePciHostdevs, pci);
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,
- _("PCI device %s is still in use by domain %s"),
- virPCIDeviceGetName(pci), other_name);
+ _("PCI device %s is still in use by "
+ "driver %s, domain %s"),
+ virPCIDeviceGetName(pci),
+ other_drvname, other_domname);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is still in use"),
static virStateDriver qemuStateDriver = {
- .name = "QEMU",
+ .name = QEMU_DRIVER_NAME,
.stateInitialize = qemuStateInitialize,
.stateAutoStart = qemuStateAutoStart,
.stateCleanup = qemuStateCleanup,
goto cleanup;
}
- virPCIDeviceSetUsedBy(dev, def->name);
+ virPCIDeviceSetUsedBy(dev, QEMU_DRIVER_NAME, def->name);
/* Setup the original states for the PCI device */
virPCIDeviceSetUnbindFromStub(dev, hostdev->origstates.states.pci.unbind_from_stub);
continue;
}
- virUSBDeviceSetUsedBy(usb, def->name);
+ virUSBDeviceSetUsedBy(usb, QEMU_DRIVER_NAME, def->name);
if (virUSBDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
virUSBDeviceFree(usb);
goto cleanup;
if ((tmp = virSCSIDeviceListFind(driver->activeScsiHostdevs, scsi))) {
- if (virSCSIDeviceSetUsedBy(tmp, def->name) < 0) {
+ if (virSCSIDeviceSetUsedBy(tmp, QEMU_DRIVER_NAME, def->name) < 0) {
virSCSIDeviceFree(scsi);
goto cleanup;
}
virSCSIDeviceFree(scsi);
} else {
- if (virSCSIDeviceSetUsedBy(scsi, def->name) < 0 ||
+ if (virSCSIDeviceSetUsedBy(scsi, QEMU_DRIVER_NAME, def->name) < 0 ||
virSCSIDeviceListAdd(driver->activeScsiHostdevs, scsi) < 0) {
virSCSIDeviceFree(scsi);
goto cleanup;
* the dev is in list driver->activePciHostdevs.
*/
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,
- _("PCI device %s is in use by domain %s"),
- virPCIDeviceGetName(dev), other_name);
+ _("PCI device %s is in use by "
+ "driver %s, domain %s"),
+ virPCIDeviceGetName(dev),
+ other_drvname, other_domname);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is already in use"),
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
if (activeDev)
- virPCIDeviceSetUsedBy(activeDev, name);
+ virPCIDeviceSetUsedBy(activeDev, QEMU_DRIVER_NAME, name);
}
/* Loop 8: Now set the original states for hostdev def */
for (i = 0; i < count; i++) {
virUSBDevicePtr usb = virUSBDeviceListGet(list, i);
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,
- _("USB device %s is in use by domain %s"),
- virUSBDeviceGetName(tmp), other_name);
+ _("USB device %s is in use by "
+ "driver %s, domain %s"),
+ virUSBDeviceGetName(tmp),
+ other_drvname, other_domname);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("USB device %s is already in use"),
goto error;
}
- virUSBDeviceSetUsedBy(usb, name);
+ virUSBDeviceSetUsedBy(usb, QEMU_DRIVER_NAME, name);
VIR_DEBUG("Adding %03d.%03d dom=%s to activeUsbHostdevs",
virUSBDeviceGetBus(usb), virUSBDeviceGetDevno(usb), name);
/*
goto error;
}
- if (virSCSIDeviceSetUsedBy(tmp, name) < 0)
+ if (virSCSIDeviceSetUsedBy(tmp, QEMU_DRIVER_NAME, name) < 0)
goto error;
} else {
- if (virSCSIDeviceSetUsedBy(scsi, name) < 0)
+ if (virSCSIDeviceSetUsedBy(scsi, QEMU_DRIVER_NAME, name) < 0)
goto error;
VIR_DEBUG("Adding %s to activeScsiHostdevs", virSCSIDeviceGetName(scsi));
* been used by this domain.
*/
activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
- if (activeDev &&
- STRNEQ_NULLABLE(name, virPCIDeviceGetUsedBy(activeDev))) {
- virPCIDeviceListDel(pcidevs, dev);
- continue;
+ if (activeDev) {
+ const char *usedby_drvname;
+ const char *usedby_domname;
+ 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);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virUSBDevicePtr usb, tmp;
- const char *used_by = NULL;
+ const char *usedby_drvname;
+ const char *usedby_domname;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
continue;
}
- used_by = virUSBDeviceGetUsedBy(tmp);
- if (STREQ_NULLABLE(used_by, name)) {
+ virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
+ if (STREQ_NULLABLE(QEMU_DRIVER_NAME, usedby_drvname) &&
+ STREQ_NULLABLE(name, usedby_domname)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
hostdev->source.subsys.u.scsi.unit,
name);
- virSCSIDeviceListDel(driver->activeScsiHostdevs, tmp, name);
+ virSCSIDeviceListDel(driver->activeScsiHostdevs, tmp, QEMU_DRIVER_NAME, name);
virSCSIDeviceFree(scsi);
}
virObjectUnlock(driver->activeScsiHostdevs);
char name[PCI_ADDR_LEN]; /* domain:bus:slot.function */
char id[PCI_ID_LEN]; /* product vendor */
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 pci_pm_cap_pos;
/* shallow copy to take care of most attributes */
*copy = *dev;
copy->path = copy->stubDriver = NULL;
+ copy->used_by_drvname = copy->used_by_domname = NULL;
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;
}
return copy;
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
VIR_FREE(dev->path);
VIR_FREE(dev->stubDriver);
+ VIR_FREE(dev->used_by_drvname);
+ VIR_FREE(dev->used_by_domname);
VIR_FREE(dev);
}
dev->reprobe = reprobe;
}
-void
-virPCIDeviceSetUsedBy(virPCIDevicePtr dev, const char *name)
+int
+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 *
-virPCIDeviceGetUsedBy(virPCIDevicePtr dev)
+void
+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)
const char *driver)
ATTRIBUTE_NONNULL(2);
const char *virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
-void virPCIDeviceSetUsedBy(virPCIDevice *dev,
- const char *used_by);
-const char *virPCIDeviceGetUsedBy(virPCIDevice *dev);
+int virPCIDeviceSetUsedBy(virPCIDevice *dev,
+ const char *drv_name,
+ const char *dom_name);
+void virPCIDeviceGetUsedBy(virPCIDevice *dev,
+ const char **drv_name,
+ const char **dom_name);
unsigned int virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
void virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
bool unbind);
/* For virReportOOMError() and virReportSystemError() */
#define VIR_FROM_THIS VIR_FROM_NONE
+struct _virUsedByInfo {
+ char *drvname; /* which driver */
+ char *domname; /* which domain */
+};
+typedef struct _virUsedByInfo *virUsedByInfoPtr;
struct _virSCSIDevice {
unsigned int adapter;
char *name; /* adapter:bus:target:unit */
char *id; /* model:vendor */
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 */
bool readonly;
VIR_FREE(dev->id);
VIR_FREE(dev->name);
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);
VIR_FREE(dev);
}
int
virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev,
- const char *name)
+ const char *drvname,
+ const char *domname)
{
- char *copy = NULL;
-
- if (VIR_STRDUP(copy, name) < 0)
+ virUsedByInfoPtr copy;
+ if (VIR_ALLOC(copy) < 0)
+ return -1;
+ if (VIR_STRDUP(copy->drvname, drvname) < 0)
+ return -1;
+ if (VIR_STRDUP(copy->domname, domname) < 0)
return -1;
return VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy);
void
virSCSIDeviceListDel(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev,
- const char *name)
+ const char *drvname,
+ const char *domname)
{
virSCSIDevicePtr tmp = NULL;
size_t 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) {
+ VIR_FREE(dev->used_by[i]->drvname);
+ VIR_FREE(dev->used_by[i]->domname);
VIR_FREE(dev->used_by[i]);
VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by);
} else {
bool shareable);
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);
const char *virSCSIDeviceGetName(virSCSIDevicePtr dev);
unsigned int virSCSIDeviceGetAdapter(virSCSIDevicePtr dev);
virSCSIDevicePtr dev);
void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev,
- const char *name);
+ const char *drvname,
+ const char *domname);
virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev);
char name[USB_ADDR_LEN]; /* domain:bus:slot.function */
char id[USB_ID_LEN]; /* product vendor */
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 {
return;
VIR_DEBUG("%s %s: freeing", dev->id, dev->name);
VIR_FREE(dev->path);
+ VIR_FREE(dev->used_by_drvname);
+ VIR_FREE(dev->used_by_domname);
VIR_FREE(dev);
}
-
-void virUSBDeviceSetUsedBy(virUSBDevicePtr dev,
- const char *name)
+int
+virUSBDeviceSetUsedBy(virUSBDevicePtr 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 * 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)
virUSBDevicePtr *usb);
void virUSBDeviceFree(virUSBDevicePtr dev);
-void virUSBDeviceSetUsedBy(virUSBDevicePtr dev, const char *name);
-const char *virUSBDeviceGetUsedBy(virUSBDevicePtr dev);
+int virUSBDeviceSetUsedBy(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);
unsigned int virUSBDeviceGetBus(virUSBDevicePtr dev);
if (!virSCSIDeviceIsAvailable(dev))
goto cleanup;
- if (virSCSIDeviceSetUsedBy(dev, "fc18") < 0)
+ if (virSCSIDeviceSetUsedBy(dev, "QEMU", "fc18") < 0)
goto cleanup;
if (virSCSIDeviceIsAvailable(dev))
goto cleanup;
- if (virSCSIDeviceSetUsedBy(dev, "fc20") < 0)
+ if (virSCSIDeviceSetUsedBy(dev, "QEMU", "fc20") < 0)
goto cleanup;
if (virSCSIDeviceIsAvailable(dev))
if (!virSCSIDeviceListFind(list, dev))
goto cleanup;
- virSCSIDeviceListDel(list, dev, "fc20");
+ virSCSIDeviceListDel(list, dev, "QEMU", "fc20");
if (!virSCSIDeviceListFind(list, dev))
goto cleanup;