1
0

nodedev: factor out nodeDeviceHasCapability()

Currently nodeDeviceCreateXML() and nodeDeviceDestroy() only support
NPIV HBAs, but we want to be able to create mdev devices as well. This
is a first step to enabling that support.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma 2020-06-18 16:05:55 -05:00 committed by Erik Skultety
parent 9baffe90b5
commit 37ab63a6fc

View File

@ -488,6 +488,21 @@ nodeDeviceFindNewDevice(virConnectPtr conn,
}
static bool
nodeDeviceHasCapability(virNodeDeviceDefPtr def, virNodeDevCapType type)
{
virNodeDevCapsDefPtr cap = def->caps;
while (cap != NULL) {
if (cap->data.type == type)
return true;
cap = cap->next;
}
return false;
}
virNodeDevicePtr
nodeDeviceCreateXML(virConnectPtr conn,
const char *xmlDesc,
@ -513,6 +528,7 @@ nodeDeviceCreateXML(virConnectPtr conn,
if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0)
return NULL;
if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_SCSI_HOST)) {
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
return NULL;
@ -531,6 +547,10 @@ nodeDeviceCreateXML(virConnectPtr conn,
_("no node device for '%s' with matching "
"wwnn '%s' and wwpn '%s'"),
def->name, wwnn, wwpn);
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Unsupported device type"));
}
return device;
}
@ -557,6 +577,7 @@ nodeDeviceDestroy(virNodeDevicePtr device)
if (virNodeDeviceDestroyEnsureACL(device->conn, def) < 0)
goto cleanup;
if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_SCSI_HOST)) {
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0)
goto cleanup;
@ -582,6 +603,10 @@ nodeDeviceDestroy(virNodeDevicePtr device)
goto cleanup;
ret = 0;
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Unsupported device type"));
}
cleanup:
virNodeDeviceObjEndAPI(&obj);