提交 1c7bc64e 编写于 作者: J John Ferlan

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: NJohn Ferlan <jferlan@redhat.com>
上级 12fa16eb
......@@ -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,23 +295,16 @@ 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;
goto cleanup;
if ((device = virGetNodeDevice(conn, def->name))) {
if (VIR_STRDUP(device->parent, def->parent) < 0) {
......@@ -322,24 +312,10 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
device = NULL;
}
}
virNodeDeviceObjUnlock(obj);
goto out;
}
}
}
cap = cap->next;
}
cleanup:
virNodeDeviceObjUnlock(obj);
}
out:
nodeDeviceUnlock();
return device;
error:
virNodeDeviceObjUnlock(obj);
goto out;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册