mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
nodedev: Introduce virNodeDeviceObjListFindSCSIHostByWWNs
In an overall effort to privatize access to virNodeDeviceObj and virNodeDeviceObjList into the virnodedeviceobj module, move the object list parsing from node_device_driver and replace with a call to a virnodedeviceobj helper. This follows other similar APIs/helpers which peruse the object list looking for some specific data in order to get/return an @device (virNodeDevice) object to the caller. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
12fa16eb98
commit
1c7bc64ef3
@ -273,6 +273,39 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr devs,
|
||||
}
|
||||
|
||||
|
||||
virNodeDeviceObjPtr
|
||||
virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs,
|
||||
const char *wwnn,
|
||||
const char *wwpn)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < devs->count; i++) {
|
||||
virNodeDeviceObjPtr obj = devs->objs[i];
|
||||
virNodeDevCapsDefPtr cap;
|
||||
|
||||
virNodeDeviceObjLock(obj);
|
||||
cap = obj->def->caps;
|
||||
|
||||
while (cap) {
|
||||
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
|
||||
virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host);
|
||||
if (cap->data.scsi_host.flags &
|
||||
VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
|
||||
if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
|
||||
STREQ(cap->data.scsi_host.wwpn, wwpn))
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
cap = cap->next;
|
||||
}
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
|
||||
{
|
||||
|
@ -52,6 +52,11 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs,
|
||||
const char *sysfs_path)
|
||||
ATTRIBUTE_NONNULL(2);
|
||||
|
||||
virNodeDeviceObjPtr
|
||||
virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs,
|
||||
const char *wwnn,
|
||||
const char *wwpn);
|
||||
|
||||
virNodeDeviceObjPtr
|
||||
virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
|
||||
virNodeDeviceDefPtr def);
|
||||
|
@ -970,6 +970,7 @@ virNodeDeviceObjListAssignDef;
|
||||
virNodeDeviceObjListExport;
|
||||
virNodeDeviceObjListFindByName;
|
||||
virNodeDeviceObjListFindBySysfsPath;
|
||||
virNodeDeviceObjListFindSCSIHostByWWNs;
|
||||
virNodeDeviceObjListFree;
|
||||
virNodeDeviceObjListGetNames;
|
||||
virNodeDeviceObjListGetParentHost;
|
||||
|
@ -288,9 +288,6 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
|
||||
const char *wwpn,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i;
|
||||
virNodeDeviceObjListPtr devs = driver->devs;
|
||||
virNodeDevCapsDefPtr cap = NULL;
|
||||
virNodeDeviceObjPtr obj = NULL;
|
||||
virNodeDeviceDefPtr def;
|
||||
virNodeDevicePtr device = NULL;
|
||||
@ -298,48 +295,27 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
nodeDeviceLock();
|
||||
obj = virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, wwnn, wwpn);
|
||||
nodeDeviceUnlock();
|
||||
|
||||
for (i = 0; i < devs->count; i++) {
|
||||
obj = devs->objs[i];
|
||||
virNodeDeviceObjLock(obj);
|
||||
def = virNodeDeviceObjGetDef(obj);
|
||||
cap = def->caps;
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
while (cap) {
|
||||
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
|
||||
nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host);
|
||||
if (cap->data.scsi_host.flags &
|
||||
VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
|
||||
if (STREQ(cap->data.scsi_host.wwnn, wwnn) &&
|
||||
STREQ(cap->data.scsi_host.wwpn, wwpn)) {
|
||||
def = virNodeDeviceObjGetDef(obj);
|
||||
|
||||
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
|
||||
goto error;
|
||||
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((device = virGetNodeDevice(conn, def->name))) {
|
||||
if (VIR_STRDUP(device->parent, def->parent) < 0) {
|
||||
virObjectUnref(device);
|
||||
device = NULL;
|
||||
}
|
||||
}
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
cap = cap->next;
|
||||
if ((device = virGetNodeDevice(conn, def->name))) {
|
||||
if (VIR_STRDUP(device->parent, def->parent) < 0) {
|
||||
virObjectUnref(device);
|
||||
device = NULL;
|
||||
}
|
||||
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
}
|
||||
|
||||
out:
|
||||
nodeDeviceUnlock();
|
||||
return device;
|
||||
|
||||
error:
|
||||
cleanup:
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
goto out;
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user