nodedev: Introduce virNodeDeviceGetSCSIHostCaps

We're about to move the call to nodeDeviceSysfsGetSCSIHostCaps from
node_device_driver into virnodedeviceobj, so move the guts of the code
from the driver specific node_device_linux_sysfs into its own API
since virnodedeviceobj cannot callback into the driver.

Nothing in the code deals with sysfs anyway, as that's hidden by the
various virSCSIHost* and virVHBA* utility function calls.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-05-25 10:20:58 -04:00
parent fc768b9063
commit 12fa16eb98
4 changed files with 87 additions and 76 deletions

View File

@ -2483,3 +2483,85 @@ virNodeDeviceDeleteVport(virConnectPtr conn,
VIR_FREE(scsi_host_name);
return ret;
}
int
virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
{
char *tmp = NULL;
int ret = -1;
if ((scsi_host->unique_id =
virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) {
VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host);
scsi_host->unique_id = -1;
}
VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host);
if (virVHBAPathExists(NULL, scsi_host->host)) {
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "port_name"))) {
VIR_WARN("Failed to read WWPN for host%d", scsi_host->host);
goto cleanup;
}
VIR_FREE(scsi_host->wwpn);
VIR_STEAL_PTR(scsi_host->wwpn, tmp);
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "node_name"))) {
VIR_WARN("Failed to read WWNN for host%d", scsi_host->host);
goto cleanup;
}
VIR_FREE(scsi_host->wwnn);
VIR_STEAL_PTR(scsi_host->wwnn, tmp);
if ((tmp = virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"))) {
VIR_FREE(scsi_host->fabric_wwn);
VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp);
}
}
if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"max_npiv_vports"))) {
VIR_WARN("Failed to read max_npiv_vports for host%d",
scsi_host->host);
goto cleanup;
}
if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
goto cleanup;
}
VIR_FREE(tmp);
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"npiv_vports_inuse"))) {
VIR_WARN("Failed to read npiv_vports_inuse for host%d",
scsi_host->host);
goto cleanup;
}
if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
goto cleanup;
}
}
ret = 0;
cleanup:
if (ret < 0) {
/* Clear the two flags in case of producing confusing XML output */
scsi_host->flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
VIR_FREE(scsi_host->wwnn);
VIR_FREE(scsi_host->wwpn);
VIR_FREE(scsi_host->fabric_wwn);
}
VIR_FREE(tmp);
return ret;
}

View File

@ -408,4 +408,7 @@ int
virNodeDeviceDeleteVport(virConnectPtr conn,
virStorageAdapterFCHostPtr fchost);
int
virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host);
#endif /* __VIR_NODE_DEVICE_CONF_H__ */

View File

@ -688,6 +688,7 @@ virNodeDeviceDefParseNode;
virNodeDeviceDefParseString;
virNodeDeviceDeleteVport;
virNodeDeviceGetParentName;
virNodeDeviceGetSCSIHostCaps;
virNodeDeviceGetWWNs;

View File

@ -48,82 +48,7 @@ VIR_LOG_INIT("node_device.node_device_linux_sysfs");
int
nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host)
{
char *tmp = NULL;
int ret = -1;
if ((scsi_host->unique_id =
virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) {
VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host);
scsi_host->unique_id = -1;
}
VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host);
if (virVHBAPathExists(NULL, scsi_host->host)) {
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "port_name"))) {
VIR_WARN("Failed to read WWPN for host%d", scsi_host->host);
goto cleanup;
}
VIR_FREE(scsi_host->wwpn);
VIR_STEAL_PTR(scsi_host->wwpn, tmp);
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host, "node_name"))) {
VIR_WARN("Failed to read WWNN for host%d", scsi_host->host);
goto cleanup;
}
VIR_FREE(scsi_host->wwnn);
VIR_STEAL_PTR(scsi_host->wwnn, tmp);
if ((tmp = virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"))) {
VIR_FREE(scsi_host->fabric_wwn);
VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp);
}
}
if (virVHBAIsVportCapable(NULL, scsi_host->host)) {
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"max_npiv_vports"))) {
VIR_WARN("Failed to read max_npiv_vports for host%d",
scsi_host->host);
goto cleanup;
}
if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) {
VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp);
goto cleanup;
}
VIR_FREE(tmp);
if (!(tmp = virVHBAGetConfig(NULL, scsi_host->host,
"npiv_vports_inuse"))) {
VIR_WARN("Failed to read npiv_vports_inuse for host%d",
scsi_host->host);
goto cleanup;
}
if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) {
VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tmp);
goto cleanup;
}
}
ret = 0;
cleanup:
if (ret < 0) {
/* Clear the two flags in case of producing confusing XML output */
scsi_host->flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST |
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS);
VIR_FREE(scsi_host->wwnn);
VIR_FREE(scsi_host->wwpn);
VIR_FREE(scsi_host->fabric_wwn);
}
VIR_FREE(tmp);
return ret;
return virNodeDeviceGetSCSIHostCaps(scsi_host);
}