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:
John Ferlan 2017-05-12 15:31:10 -04:00
parent 12fa16eb98
commit 1c7bc64ef3
4 changed files with 52 additions and 37 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -970,6 +970,7 @@ virNodeDeviceObjListAssignDef;
virNodeDeviceObjListExport;
virNodeDeviceObjListFindByName;
virNodeDeviceObjListFindBySysfsPath;
virNodeDeviceObjListFindSCSIHostByWWNs;
virNodeDeviceObjListFree;
virNodeDeviceObjListGetNames;
virNodeDeviceObjListGetParentHost;

View File

@ -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;
}