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

nodedev: Add ability to find a vport capable vHBA

If a <parent> is not supplied in the XML used to create a non-persistent
vHBA, then instead of failing, let's try to find a "vports" capable node
device and use that.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 8f3054a0
......@@ -75,14 +75,19 @@ virNodeDevCapsDefParseString(const char *xpath,
int virNodeDeviceHasCap(const virNodeDeviceObj *dev, const char *cap)
{
virNodeDevCapsDefPtr caps = dev->def->caps;
const char *fc_host_cap =
virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST);
const char *vports_cap =
virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS);
while (caps) {
if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type)))
return 1;
else if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST)
if ((STREQ(cap, "fc_host") &&
if ((STREQ(cap, fc_host_cap) &&
(caps->data.scsi_host.flags &
VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) ||
(STREQ(cap, "vports") &&
(STREQ(cap, vports_cap) &&
(caps->data.scsi_host.flags &
VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)))
return 1;
......@@ -151,6 +156,23 @@ virNodeDeviceObjPtr virNodeDeviceFindByName(virNodeDeviceObjListPtr devs,
}
static virNodeDeviceObjPtr
virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs,
const char *cap)
{
size_t i;
for (i = 0; i < devs->count; i++) {
virNodeDeviceObjLock(devs->objs[i]);
if (virNodeDeviceHasCap(devs->objs[i], cap))
return devs->objs[i];
virNodeDeviceObjUnlock(devs->objs[i]);
}
return NULL;
}
void virNodeDeviceDefFree(virNodeDeviceDefPtr def)
{
virNodeDevCapsDefPtr caps;
......@@ -1828,6 +1850,29 @@ virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
return ret;
}
int
virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs,
int *parent_host)
{
virNodeDeviceObjPtr parent = NULL;
const char *cap = virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS);
int ret;
if (!(parent = virNodeDeviceFindByCap(devs, cap))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not find any vport capable device"));
return -1;
}
ret = virNodeDeviceFindFCParentHost(parent, parent_host);
virNodeDeviceObjUnlock(parent);
return ret;
}
void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
{
size_t i = 0;
......
......@@ -273,6 +273,9 @@ int virNodeDeviceGetParentHost(virNodeDeviceObjListPtr devs,
const char *parent_name,
int *parent_host);
int virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs,
int *parent_host);
void virNodeDeviceDefFree(virNodeDeviceDefPtr def);
void virNodeDeviceObjFree(virNodeDeviceObjPtr dev);
......
......@@ -700,6 +700,7 @@ virNodeDeviceDefParseNode;
virNodeDeviceDefParseString;
virNodeDeviceFindByName;
virNodeDeviceFindBySysfsPath;
virNodeDeviceFindVportParentHost;
virNodeDeviceGetParentHost;
virNodeDeviceGetWWNs;
virNodeDeviceHasCap;
......
......@@ -584,11 +584,16 @@ nodeDeviceCreateXML(virConnectPtr conn,
if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1)
goto cleanup;
if (virNodeDeviceGetParentHost(&driver->devs,
def->name,
def->parent,
&parent_host) == -1) {
goto cleanup;
if (def->parent) {
if (virNodeDeviceGetParentHost(&driver->devs,
def->name,
def->parent,
&parent_host) < 0)
goto cleanup;
} else {
/* Try to find a vport capable scsi_host when no parent supplied */
if (virNodeDeviceFindVportParentHost(&driver->devs, &parent_host) < 0)
goto cleanup;
}
if (virManageVport(parent_host,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册