Add unique_id to nodedev output

Add an optional unique_id parameter to nodedev.  Allows for easier lookup
and display of the unique_id value in order to document for use with
scsi_host code.
This commit is contained in:
John Ferlan 2014-06-05 13:17:05 -04:00
parent fbd91d496e
commit f3271f4cb3
8 changed files with 53 additions and 8 deletions

View File

@ -195,6 +195,17 @@
<dl> <dl>
<dt><code>host</code></dt> <dt><code>host</code></dt>
<dd>The SCSI host number.</dd> <dd>The SCSI host number.</dd>
<dt><code>unique_id</code></dt>
<dd>On input, this optionally provides the value from the
'unique_id' file found in the scsi_host's directory. To
view the values of all 'unique_id' files, use <code>find -H
/sys/class/scsi_host/host{0..9}/unique_id |
xargs grep '[0-9]'</code>. On output, if the unique_id
file exists, the value from the file will be displayed.
This can be used in order to help uniquely identify the
scsi_host adapter in a <a href="formatstorage.html">
Storage Pool</a>. <span class="since">Since 1.2.7</span>
</dd>
<dt><code>capability</code></dt> <dt><code>capability</code></dt>
<dd>Current capabilities include "vports_ops" (indicates <dd>Current capabilities include "vports_ops" (indicates
vport operations are supported) and "fc_host". "vport_ops" vport operations are supported) and "fc_host". "vport_ops"

View File

@ -339,6 +339,12 @@
<ref name='unsignedLong'/> <ref name='unsignedLong'/>
</element> </element>
<optional>
<element name='unique_id'>
<ref name='positiveInteger'/>
</element>
</optional>
<optional> <optional>
<zeroOrMore> <zeroOrMore>
<element name='capability'> <element name='capability'>

View File

@ -442,6 +442,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
case VIR_NODE_DEV_CAP_SCSI_HOST: case VIR_NODE_DEV_CAP_SCSI_HOST:
virBufferAsprintf(&buf, "<host>%d</host>\n", virBufferAsprintf(&buf, "<host>%d</host>\n",
data->scsi_host.host); data->scsi_host.host);
if (data->scsi_host.unique_id != -1)
virBufferAsprintf(&buf, "<unique_id>%d</unique_id>\n",
data->scsi_host.unique_id);
if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
virBufferAddLit(&buf, "<capability type='fc_host'>\n"); virBufferAddLit(&buf, "<capability type='fc_host'>\n");
virBufferAdjustIndent(&buf, 2); virBufferAdjustIndent(&buf, 2);
@ -826,13 +829,21 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node; orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (create == EXISTING_DEVICE && if (create == EXISTING_DEVICE) {
virNodeDevCapsDefParseULong("number(./host[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
&data->scsi_host.host, def, &data->scsi_host.host, def,
_("no SCSI host ID supplied for '%s'"), _("no SCSI host ID supplied for '%s'"),
_("invalid SCSI host ID supplied for '%s'")) < 0) { _("invalid SCSI host ID supplied for '%s'")) < 0) {
goto out; goto out;
} }
/* Optional unique_id value */
data->scsi_host.unique_id = -1;
if (virNodeDevCapsDefParseIntOptional("number(./unique_id[1])", ctxt,
&data->scsi_host.unique_id, def,
_("invalid unique_id supplied for '%s'")) < 0) {
goto out;
}
}
if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) { if ((n = virXPathNodeSet("./capability", ctxt, &nodes)) < 0) {
goto out; goto out;

View File

@ -171,6 +171,7 @@ struct _virNodeDevCapsDef {
} net; } net;
struct { struct {
unsigned int host; unsigned int host;
int unique_id;
char *wwnn; char *wwnn;
char *wwpn; char *wwpn;
char *fabric_wwn; char *fabric_wwn;

View File

@ -47,6 +47,12 @@ detect_scsi_host_caps(union _virNodeDevCapData *d)
char *vports = NULL; char *vports = NULL;
int ret = -1; int ret = -1;
if (virReadSCSIUniqueId(NULL, d->scsi_host.host,
&d->scsi_host.unique_id) < 0) {
VIR_DEBUG("Failed to read unique_id for host%d", d->scsi_host.host);
d->scsi_host.unique_id = -1;
}
VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host); VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host);
if (virIsCapableFCHost(NULL, d->scsi_host.host)) { if (virIsCapableFCHost(NULL, d->scsi_host.host)) {

View File

@ -6087,14 +6087,15 @@ testNodeDeviceCreateXML(virConnectPtr conn,
if (VIR_STRDUP(def->name, wwpn) < 0) if (VIR_STRDUP(def->name, wwpn) < 0)
goto cleanup; goto cleanup;
/* Fill in a random 'host' value, since this would also come from /* Fill in a random 'host' and 'unique_id' value,
* the backend */ * since this would also come from the backend */
caps = def->caps; caps = def->caps;
while (caps) { while (caps) {
if (caps->type != VIR_NODE_DEV_CAP_SCSI_HOST) if (caps->type != VIR_NODE_DEV_CAP_SCSI_HOST)
continue; continue;
caps->data.scsi_host.host = virRandomBits(10); caps->data.scsi_host.host = virRandomBits(10);
caps->data.scsi_host.unique_id = 2;
caps = caps->next; caps = caps->next;
} }

View File

@ -0,0 +1,8 @@
<device>
<name>pci_8086_27c5_scsi_host_0</name>
<parent>pci_8086_27c5</parent>
<capability type='scsi_host'>
<host>1</host>
<unique_id>2</unique_id>
</capability>
</device>

View File

@ -82,6 +82,7 @@ mymain(void)
DO_TEST("pci_1002_71c4"); DO_TEST("pci_1002_71c4");
DO_TEST("pci_8086_10c9_sriov_pf"); DO_TEST("pci_8086_10c9_sriov_pf");
DO_TEST("pci_8086_27c5_scsi_host_0"); DO_TEST("pci_8086_27c5_scsi_host_0");
DO_TEST("pci_8086_27c5_scsi_host_0_unique_id");
DO_TEST("pci_8086_27c5_scsi_host_scsi_device_lun0"); DO_TEST("pci_8086_27c5_scsi_host_scsi_device_lun0");
DO_TEST("pci_8086_27c5_scsi_host_scsi_host"); DO_TEST("pci_8086_27c5_scsi_host_scsi_host");
DO_TEST("pci_8086_27c5_scsi_host"); DO_TEST("pci_8086_27c5_scsi_host");