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
|
void
|
||||||
virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
|
virNodeDeviceObjFree(virNodeDeviceObjPtr obj)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
|||||||
virNodeDeviceObjListExport;
|
virNodeDeviceObjListExport;
|
||||||
virNodeDeviceObjListFindByName;
|
virNodeDeviceObjListFindByName;
|
||||||
virNodeDeviceObjListFindBySysfsPath;
|
virNodeDeviceObjListFindBySysfsPath;
|
||||||
|
virNodeDeviceObjListFindSCSIHostByWWNs;
|
||||||
virNodeDeviceObjListFree;
|
virNodeDeviceObjListFree;
|
||||||
virNodeDeviceObjListGetNames;
|
virNodeDeviceObjListGetNames;
|
||||||
virNodeDeviceObjListGetParentHost;
|
virNodeDeviceObjListGetParentHost;
|
||||||
|
@ -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,
|
|||||||
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) {
|
def = virNodeDeviceObjGetDef(obj);
|
||||||
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)
|
if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if ((device = virGetNodeDevice(conn, def->name))) {
|
if ((device = virGetNodeDevice(conn, def->name))) {
|
||||||
if (VIR_STRDUP(device->parent, def->parent) < 0) {
|
if (VIR_STRDUP(device->parent, def->parent) < 0) {
|
||||||
virObjectUnref(device);
|
virObjectUnref(device);
|
||||||
device = NULL;
|
device = NULL;
|
||||||
}
|
|
||||||
}
|
|
||||||
virNodeDeviceObjUnlock(obj);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cap = cap->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virNodeDeviceObjUnlock(obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
cleanup:
|
||||||
nodeDeviceUnlock();
|
|
||||||
return device;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virNodeDeviceObjUnlock(obj);
|
virNodeDeviceObjUnlock(obj);
|
||||||
goto out;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user