mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
nodedev: Introduce virNodeDeviceObjListNew
In preparation to make things private, make the ->devs be pointers to a virNodeDeviceObjList and then manage everything inside virnodedeviceobj Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
65981c8596
commit
9c5d98fd83
@ -273,6 +273,17 @@ virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
|
||||
}
|
||||
|
||||
|
||||
virNodeDeviceObjListPtr
|
||||
virNodeDeviceObjListNew(void)
|
||||
{
|
||||
virNodeDeviceObjListPtr devs;
|
||||
|
||||
if (VIR_ALLOC(devs) < 0)
|
||||
return NULL;
|
||||
return devs;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs)
|
||||
{
|
||||
@ -280,7 +291,7 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs)
|
||||
for (i = 0; i < devs->count; i++)
|
||||
virNodeDeviceObjFree(devs->objs[i]);
|
||||
VIR_FREE(devs->objs);
|
||||
devs->count = 0;
|
||||
VIR_FREE(devs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@ typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr;
|
||||
struct _virNodeDeviceDriverState {
|
||||
virMutex lock;
|
||||
|
||||
virNodeDeviceObjList devs; /* currently-known devices */
|
||||
virNodeDeviceObjListPtr devs; /* currently-known devices */
|
||||
void *privateData; /* driver-specific private data */
|
||||
|
||||
/* Immutable pointer, self-locking APIs */
|
||||
@ -68,6 +68,9 @@ virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs,
|
||||
void
|
||||
virNodeDeviceObjFree(virNodeDeviceObjPtr dev);
|
||||
|
||||
virNodeDeviceObjListPtr
|
||||
virNodeDeviceObjListNew(void);
|
||||
|
||||
void
|
||||
virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs);
|
||||
|
||||
|
@ -972,6 +972,7 @@ virNodeDeviceObjGetNames;
|
||||
virNodeDeviceObjGetParentHost;
|
||||
virNodeDeviceObjListExport;
|
||||
virNodeDeviceObjListFree;
|
||||
virNodeDeviceObjListNew;
|
||||
virNodeDeviceObjLock;
|
||||
virNodeDeviceObjNumOfDevices;
|
||||
virNodeDeviceObjRemove;
|
||||
|
@ -182,7 +182,7 @@ nodeNumOfDevices(virConnectPtr conn,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
nodeDeviceLock();
|
||||
ndevs = virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap,
|
||||
ndevs = virNodeDeviceObjNumOfDevices(driver->devs, conn, cap,
|
||||
virNodeNumOfDevicesCheckACL);
|
||||
nodeDeviceUnlock();
|
||||
|
||||
@ -205,7 +205,7 @@ nodeListDevices(virConnectPtr conn,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
nodeDeviceLock();
|
||||
nnames = virNodeDeviceObjGetNames(&driver->devs, conn,
|
||||
nnames = virNodeDeviceObjGetNames(driver->devs, conn,
|
||||
virNodeListDevicesCheckACL,
|
||||
cap, names, maxnames);
|
||||
nodeDeviceUnlock();
|
||||
@ -227,7 +227,7 @@ nodeConnectListAllNodeDevices(virConnectPtr conn,
|
||||
return -1;
|
||||
|
||||
nodeDeviceLock();
|
||||
ret = virNodeDeviceObjListExport(conn, &driver->devs, devices,
|
||||
ret = virNodeDeviceObjListExport(conn, driver->devs, devices,
|
||||
virConnectListAllNodeDevicesCheckACL,
|
||||
flags);
|
||||
nodeDeviceUnlock();
|
||||
@ -241,7 +241,7 @@ nodeDeviceObjFindByName(const char *name)
|
||||
virNodeDeviceObjPtr obj;
|
||||
|
||||
nodeDeviceLock();
|
||||
obj = virNodeDeviceObjFindByName(&driver->devs, name);
|
||||
obj = virNodeDeviceObjFindByName(driver->devs, name);
|
||||
nodeDeviceUnlock();
|
||||
|
||||
if (!obj) {
|
||||
@ -289,7 +289,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i;
|
||||
virNodeDeviceObjListPtr devs = &driver->devs;
|
||||
virNodeDeviceObjListPtr devs = driver->devs;
|
||||
virNodeDevCapsDefPtr cap = NULL;
|
||||
virNodeDeviceObjPtr obj = NULL;
|
||||
virNodeDeviceDefPtr def;
|
||||
@ -587,7 +587,7 @@ nodeDeviceCreateXML(virConnectPtr conn,
|
||||
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
|
||||
goto cleanup;
|
||||
|
||||
if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
|
||||
if ((parent_host = virNodeDeviceObjGetParentHost(driver->devs, def,
|
||||
CREATE_DEVICE)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -639,7 +639,7 @@ nodeDeviceDestroy(virNodeDevicePtr device)
|
||||
* or parent_fabric_wwn) and drop the object lock. */
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
obj = NULL;
|
||||
if ((parent_host = virNodeDeviceObjGetParentHost(&driver->devs, def,
|
||||
if ((parent_host = virNodeDeviceObjGetParentHost(driver->devs, def,
|
||||
EXISTING_DEVICE)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -482,7 +482,7 @@ dev_create(const char *udi)
|
||||
/* Some devices don't have a path in sysfs, so ignore failure */
|
||||
(void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath);
|
||||
|
||||
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def))) {
|
||||
if (!(obj = virNodeDeviceObjAssignDef(driver->devs, def))) {
|
||||
VIR_FREE(devicePath);
|
||||
goto failure;
|
||||
}
|
||||
@ -509,11 +509,11 @@ dev_refresh(const char *udi)
|
||||
virNodeDeviceObjPtr obj;
|
||||
|
||||
nodeDeviceLock();
|
||||
if ((obj = virNodeDeviceObjFindByName(&driver->devs, name))) {
|
||||
if ((obj = virNodeDeviceObjFindByName(driver->devs, name))) {
|
||||
/* Simply "rediscover" device -- incrementally handling changes
|
||||
* to sub-capabilities (like net.80203) is nasty ... so avoid it.
|
||||
*/
|
||||
virNodeDeviceObjRemove(&driver->devs, obj);
|
||||
virNodeDeviceObjRemove(driver->devs, obj);
|
||||
} else {
|
||||
VIR_DEBUG("no device named %s", name);
|
||||
}
|
||||
@ -542,10 +542,10 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED,
|
||||
virNodeDeviceObjPtr obj;
|
||||
|
||||
nodeDeviceLock();
|
||||
obj = virNodeDeviceObjFindByName(&driver->devs, name);
|
||||
obj = virNodeDeviceObjFindByName(driver->devs, name);
|
||||
VIR_DEBUG("%s", name);
|
||||
if (obj)
|
||||
virNodeDeviceObjRemove(&driver->devs, obj);
|
||||
virNodeDeviceObjRemove(driver->devs, obj);
|
||||
else
|
||||
VIR_DEBUG("no device named %s", name);
|
||||
nodeDeviceUnlock();
|
||||
@ -562,7 +562,7 @@ device_cap_added(LibHalContext *ctx,
|
||||
virNodeDeviceDefPtr def;
|
||||
|
||||
nodeDeviceLock();
|
||||
obj = virNodeDeviceObjFindByName(&driver->devs, name);
|
||||
obj = virNodeDeviceObjFindByName(driver->devs, name);
|
||||
nodeDeviceUnlock();
|
||||
VIR_DEBUG("%s %s", cap, name);
|
||||
if (obj) {
|
||||
@ -627,6 +627,9 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
|
||||
}
|
||||
nodeDeviceLock();
|
||||
|
||||
if (!(driver->devs = virNodeDeviceObjListNew()))
|
||||
goto failure;
|
||||
|
||||
dbus_error_init(&err);
|
||||
if (!(sysbus = virDBusGetSystemBus())) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -701,7 +704,7 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
|
||||
_("%s: %s"), err.name, err.message);
|
||||
dbus_error_free(&err);
|
||||
}
|
||||
virNodeDeviceObjListFree(&driver->devs);
|
||||
virNodeDeviceObjListFree(driver->devs);
|
||||
if (hal_ctx)
|
||||
(void)libhal_ctx_free(hal_ctx);
|
||||
nodeDeviceUnlock();
|
||||
@ -717,7 +720,7 @@ nodeStateCleanup(void)
|
||||
if (driver) {
|
||||
nodeDeviceLock();
|
||||
LibHalContext *hal_ctx = DRV_STATE_HAL_CTX(driver);
|
||||
virNodeDeviceObjListFree(&driver->devs);
|
||||
virNodeDeviceObjListFree(driver->devs);
|
||||
(void)libhal_ctx_shutdown(hal_ctx, NULL);
|
||||
(void)libhal_ctx_free(hal_ctx);
|
||||
nodeDeviceUnlock();
|
||||
|
@ -1318,7 +1318,7 @@ udevRemoveOneDevice(struct udev_device *device)
|
||||
const char *name = NULL;
|
||||
|
||||
name = udev_device_get_syspath(device);
|
||||
if (!(obj = virNodeDeviceObjFindBySysfsPath(&driver->devs, name))) {
|
||||
if (!(obj = virNodeDeviceObjFindBySysfsPath(driver->devs, name))) {
|
||||
VIR_DEBUG("Failed to find device to remove that has udev name '%s'",
|
||||
name);
|
||||
return -1;
|
||||
@ -1331,7 +1331,7 @@ udevRemoveOneDevice(struct udev_device *device)
|
||||
|
||||
VIR_DEBUG("Removing device '%s' with sysfs path '%s'",
|
||||
def->name, name);
|
||||
virNodeDeviceObjRemove(&driver->devs, obj);
|
||||
virNodeDeviceObjRemove(driver->devs, obj);
|
||||
virNodeDeviceObjFree(obj);
|
||||
|
||||
if (event)
|
||||
@ -1365,7 +1365,7 @@ udevSetParent(struct udev_device *device,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if ((obj = virNodeDeviceObjFindBySysfsPath(&driver->devs,
|
||||
if ((obj = virNodeDeviceObjFindBySysfsPath(driver->devs,
|
||||
parent_sysfs_path))) {
|
||||
objdef = virNodeDeviceObjGetDef(obj);
|
||||
if (VIR_STRDUP(def->parent, objdef->name) < 0) {
|
||||
@ -1424,14 +1424,14 @@ udevAddOneDevice(struct udev_device *device)
|
||||
if (udevSetParent(device, def) != 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((obj = virNodeDeviceObjFindByName(&driver->devs, def->name))) {
|
||||
if ((obj = virNodeDeviceObjFindByName(driver->devs, def->name))) {
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
new_device = false;
|
||||
}
|
||||
|
||||
/* If this is a device change, the old definition will be freed
|
||||
* and the current definition will take its place. */
|
||||
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
|
||||
if (!(obj = virNodeDeviceObjAssignDef(driver->devs, def)))
|
||||
goto cleanup;
|
||||
objdef = virNodeDeviceObjGetDef(obj);
|
||||
|
||||
@ -1585,7 +1585,7 @@ nodeStateCleanup(void)
|
||||
if (udev != NULL)
|
||||
udev_unref(udev);
|
||||
|
||||
virNodeDeviceObjListFree(&driver->devs);
|
||||
virNodeDeviceObjListFree(driver->devs);
|
||||
nodeDeviceUnlock();
|
||||
virMutexDestroy(&driver->lock);
|
||||
VIR_FREE(driver);
|
||||
@ -1721,7 +1721,7 @@ udevSetupSystemDev(void)
|
||||
udevGetDMIData(&def->caps->data.system);
|
||||
#endif
|
||||
|
||||
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
|
||||
if (!(obj = virNodeDeviceObjAssignDef(driver->devs, def)))
|
||||
goto cleanup;
|
||||
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
@ -1790,6 +1790,10 @@ nodeStateInitialize(bool privileged,
|
||||
|
||||
driver->privateData = priv;
|
||||
nodeDeviceLock();
|
||||
|
||||
if (!(driver->devs = virNodeDeviceObjListNew()))
|
||||
goto cleanup;
|
||||
|
||||
driver->nodeDeviceEventState = virObjectEventStateNew();
|
||||
|
||||
if (udevPCITranslateInit(privileged) < 0)
|
||||
|
@ -101,7 +101,7 @@ struct _testDriver {
|
||||
bool transaction_running;
|
||||
virInterfaceObjListPtr backupIfaces;
|
||||
virStoragePoolObjList pools;
|
||||
virNodeDeviceObjList devs;
|
||||
virNodeDeviceObjListPtr devs;
|
||||
int numCells;
|
||||
testCell cells[MAX_CELLS];
|
||||
size_t numAuths;
|
||||
@ -152,7 +152,7 @@ testDriverFree(testDriverPtr driver)
|
||||
virObjectUnref(driver->caps);
|
||||
virObjectUnref(driver->xmlopt);
|
||||
virObjectUnref(driver->domains);
|
||||
virNodeDeviceObjListFree(&driver->devs);
|
||||
virNodeDeviceObjListFree(driver->devs);
|
||||
virObjectUnref(driver->networks);
|
||||
virInterfaceObjListFree(driver->ifaces);
|
||||
virStoragePoolObjListFree(&driver->pools);
|
||||
@ -418,7 +418,8 @@ testDriverNew(void)
|
||||
!(ret->eventState = virObjectEventStateNew()) ||
|
||||
!(ret->ifaces = virInterfaceObjListNew()) ||
|
||||
!(ret->domains = virDomainObjListNew()) ||
|
||||
!(ret->networks = virNetworkObjListNew()))
|
||||
!(ret->networks = virNetworkObjListNew()) ||
|
||||
!(ret->devs = virNodeDeviceObjListNew()))
|
||||
goto error;
|
||||
|
||||
virAtomicIntSet(&ret->nextDomID, 1);
|
||||
@ -1171,7 +1172,7 @@ testParseNodedevs(testDriverPtr privconn,
|
||||
if (!def)
|
||||
goto error;
|
||||
|
||||
if (!(obj = virNodeDeviceObjAssignDef(&privconn->devs, def))) {
|
||||
if (!(obj = virNodeDeviceObjAssignDef(privconn->devs, def))) {
|
||||
virNodeDeviceDefFree(def);
|
||||
goto error;
|
||||
}
|
||||
@ -4560,7 +4561,7 @@ testDestroyVport(testDriverPtr privconn,
|
||||
*
|
||||
* Reaching across the boundaries of space and time into the
|
||||
* Node Device in order to remove */
|
||||
if (!(obj = virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12"))) {
|
||||
if (!(obj = virNodeDeviceObjFindByName(privconn->devs, "scsi_host12"))) {
|
||||
virReportError(VIR_ERR_NO_NODE_DEVICE, "%s",
|
||||
_("no node device with matching name 'scsi_host12'"));
|
||||
return -1;
|
||||
@ -4570,7 +4571,7 @@ testDestroyVport(testDriverPtr privconn,
|
||||
VIR_NODE_DEVICE_EVENT_DELETED,
|
||||
0);
|
||||
|
||||
virNodeDeviceObjRemove(&privconn->devs, obj);
|
||||
virNodeDeviceObjRemove(privconn->devs, obj);
|
||||
virNodeDeviceObjFree(obj);
|
||||
|
||||
testObjectEventQueue(privconn, event);
|
||||
@ -5302,7 +5303,7 @@ testNodeDeviceObjFindByName(testDriverPtr driver,
|
||||
virNodeDeviceObjPtr obj;
|
||||
|
||||
testDriverLock(driver);
|
||||
obj = virNodeDeviceObjFindByName(&driver->devs, name);
|
||||
obj = virNodeDeviceObjFindByName(driver->devs, name);
|
||||
testDriverUnlock(driver);
|
||||
|
||||
if (!obj)
|
||||
@ -5325,7 +5326,7 @@ testNodeNumOfDevices(virConnectPtr conn,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
testDriverLock(driver);
|
||||
ndevs = virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap, NULL);
|
||||
ndevs = virNodeDeviceObjNumOfDevices(driver->devs, conn, cap, NULL);
|
||||
testDriverUnlock(driver);
|
||||
|
||||
return ndevs;
|
||||
@ -5345,7 +5346,7 @@ testNodeListDevices(virConnectPtr conn,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
testDriverLock(driver);
|
||||
nnames = virNodeDeviceObjGetNames(&driver->devs, conn, NULL,
|
||||
nnames = virNodeDeviceObjGetNames(driver->devs, conn, NULL,
|
||||
cap, names, maxnames);
|
||||
testDriverUnlock(driver);
|
||||
|
||||
@ -5492,7 +5493,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
|
||||
* using the scsi_host11 definition, changing the name and the
|
||||
* scsi_host capability fields before calling virNodeDeviceAssignDef
|
||||
* to add the def to the node device objects list. */
|
||||
if (!(objcopy = virNodeDeviceObjFindByName(&driver->devs, "scsi_host11")))
|
||||
if (!(objcopy = virNodeDeviceObjFindByName(driver->devs, "scsi_host11")))
|
||||
goto cleanup;
|
||||
|
||||
xml = virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy));
|
||||
@ -5532,7 +5533,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver,
|
||||
caps = caps->next;
|
||||
}
|
||||
|
||||
if (!(obj = virNodeDeviceObjAssignDef(&driver->devs, def)))
|
||||
if (!(obj = virNodeDeviceObjAssignDef(driver->devs, def)))
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
objdef = virNodeDeviceObjGetDef(obj);
|
||||
@ -5577,7 +5578,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
|
||||
/* Unlike the "real" code we don't need the parent_host in order to
|
||||
* call virVHBAManageVport, but still let's make sure the code finds
|
||||
* something valid and no one messed up the mock environment. */
|
||||
if (virNodeDeviceObjGetParentHost(&driver->devs, def, CREATE_DEVICE) < 0)
|
||||
if (virNodeDeviceObjGetParentHost(driver->devs, def, CREATE_DEVICE) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* In the real code, we'd call virVHBAManageVport followed by
|
||||
@ -5638,7 +5639,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
|
||||
|
||||
/* We do this just for basic validation, but also avoid finding a
|
||||
* vport capable HBA if for some reason our vHBA doesn't exist */
|
||||
if (virNodeDeviceObjGetParentHost(&driver->devs, def,
|
||||
if (virNodeDeviceObjGetParentHost(driver->devs, def,
|
||||
EXISTING_DEVICE) < 0) {
|
||||
obj = NULL;
|
||||
goto cleanup;
|
||||
@ -5649,7 +5650,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
|
||||
0);
|
||||
|
||||
virNodeDeviceObjLock(obj);
|
||||
virNodeDeviceObjRemove(&driver->devs, obj);
|
||||
virNodeDeviceObjRemove(driver->devs, obj);
|
||||
virNodeDeviceObjFree(obj);
|
||||
obj = NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user