提交 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, ...@@ -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 void
virNodeDeviceObjFree(virNodeDeviceObjPtr obj) virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
{ {
......
...@@ -52,6 +52,11 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs, ...@@ -52,6 +52,11 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs,
const char *sysfs_path) const char *sysfs_path)
ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(2);
virNodeDeviceObjPtr
virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs,
const char *wwnn,
const char *wwpn);
virNodeDeviceObjPtr virNodeDeviceObjPtr
virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs,
virNodeDeviceDefPtr def); virNodeDeviceDefPtr def);
......
...@@ -970,6 +970,7 @@ virNodeDeviceObjListAssignDef; ...@@ -970,6 +970,7 @@ virNodeDeviceObjListAssignDef;
virNodeDeviceObjListExport; virNodeDeviceObjListExport;
virNodeDeviceObjListFindByName; virNodeDeviceObjListFindByName;
virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFindBySysfsPath;
virNodeDeviceObjListFindSCSIHostByWWNs;
virNodeDeviceObjListFree; virNodeDeviceObjListFree;
virNodeDeviceObjListGetNames; virNodeDeviceObjListGetNames;
virNodeDeviceObjListGetParentHost; virNodeDeviceObjListGetParentHost;
......
...@@ -288,9 +288,6 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, ...@@ -288,9 +288,6 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
const char *wwpn, const char *wwpn,
unsigned int flags) unsigned int flags)
{ {
size_t i;
virNodeDeviceObjListPtr devs = driver->devs;
virNodeDevCapsDefPtr cap = NULL;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL;
virNodeDeviceDefPtr def; virNodeDeviceDefPtr def;
virNodeDevicePtr device = NULL; virNodeDevicePtr device = NULL;
...@@ -298,48 +295,27 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, ...@@ -298,48 +295,27 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn,
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
nodeDeviceLock(); nodeDeviceLock();
obj = virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, wwnn, wwpn);
nodeDeviceUnlock();
for (i = 0; i < devs->count; i++) { if (!obj)
obj = devs->objs[i]; return NULL;
virNodeDeviceObjLock(obj);
def = virNodeDeviceObjGetDef(obj);
cap = def->caps;
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)) {
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
goto error;
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;
}
virNodeDeviceObjUnlock(obj); def = virNodeDeviceObjGetDef(obj);
}
out: if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
nodeDeviceUnlock(); goto cleanup;
return device;
error: if ((device = virGetNodeDevice(conn, def->name))) {
if (VIR_STRDUP(device->parent, def->parent) < 0) {
virObjectUnref(device);
device = NULL;
}
}
cleanup:
virNodeDeviceObjUnlock(obj); virNodeDeviceObjUnlock(obj);
goto out; return device;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册