提交 8f3054a0 编写于 作者: J John Ferlan

nodedev: Create helpers to search for vport capable nodedevs

Extract out code from virNodeDeviceGetParentHost into helpers - it's
going to be reused in upcoming patches to search on more fields

Create virNodeDeviceFindVPORTCapDef in order to return a virNodeDevCapsDefPtr
of the VPORT_OPS and virNodeDeviceFindFCParentHost to use the function and
generate an error message if the device doesn't have the capability.

Also clean up the processing in virNodeDeviceGetParentHost to remove
need for goto's.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 79bf25cd
......@@ -92,6 +92,30 @@ int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap)
}
/* virNodeDeviceFindVPORTCapDef:
* @dev: Pointer to current device
*
* Search the device object 'caps' array for vport_ops capability.
*
* Returns:
* Pointer to the caps or NULL if not found
*/
static virNodeDevCapsDefPtr
virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev)
{
virNodeDevCapsDefPtr caps = dev->def->caps;
while (caps) {
if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
(caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))
break;
caps = caps->next;
}
return caps;
}
virNodeDeviceObjPtr
virNodeDeviceFindBySysfsPath(virNodeDeviceObjListPtr devs,
const char *sysfs_path)
......@@ -1752,6 +1776,35 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
/*
* Return the NPIV dev's parent device name
*/
/* virNodeDeviceFindFCParentHost:
* @parent: Pointer to node device object
* @parent_host: Pointer to return parent host number
*
* Search the capabilities for the device to find the FC capabilities
* in order to set the parent_host value.
*
* Returns:
* 0 on success with parent_host set, -1 otherwise;
*/
static int
virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent,
int *parent_host)
{
virNodeDevCapsDefPtr cap = virNodeDeviceFindVPORTCapDef(parent);
if (!cap) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Parent device %s is not capable "
"of vport operations"),
parent->def->name);
return -1;
}
*parent_host = cap->data.scsi_host.host;
return 0;
}
int
virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
const char *dev_name,
......@@ -1759,41 +1812,19 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
int *parent_host)
{
virNodeDeviceObjPtr parent = NULL;
virNodeDevCapsDefPtr cap = NULL;
int ret = 0;
int ret;
parent = virNodeDeviceFindByName(devs, parent_name);
if (parent == NULL) {
if (!(parent = virNodeDeviceFindByName(devs, parent_name))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not find parent device for '%s'"),
dev_name);
ret = -1;
goto out;
}
cap = parent->def->caps;
while (cap != NULL) {
if (cap->data.type == VIR_NODE_DEV_CAP_SCSI_HOST &&
(cap->data.scsi_host.flags &
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)) {
*parent_host = cap->data.scsi_host.host;
break;
}
cap = cap->next;
return -1;
}
if (cap == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Parent device %s is not capable "
"of vport operations"),
parent->def->name);
ret = -1;
}
ret = virNodeDeviceFindFCParentHost(parent, parent_host);
virNodeDeviceObjUnlock(parent);
out:
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册