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>
<dt><code>host</code></dt>
<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>
<dd>Current capabilities include "vports_ops" (indicates
vport operations are supported) and "fc_host". "vport_ops"

View File

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

View File

@ -442,6 +442,9 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
case VIR_NODE_DEV_CAP_SCSI_HOST:
virBufferAsprintf(&buf, "<host>%d</host>\n",
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) {
virBufferAddLit(&buf, "<capability type='fc_host'>\n");
virBufferAdjustIndent(&buf, 2);
@ -826,12 +829,20 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
orignode = ctxt->node;
ctxt->node = node;
if (create == EXISTING_DEVICE &&
virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
&data->scsi_host.host, def,
_("no SCSI host ID supplied for '%s'"),
_("invalid SCSI host ID supplied for '%s'")) < 0) {
goto out;
if (create == EXISTING_DEVICE) {
if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
&data->scsi_host.host, def,
_("no SCSI host ID supplied for '%s'"),
_("invalid SCSI host ID supplied for '%s'")) < 0) {
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) {

View File

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

View File

@ -47,6 +47,12 @@ detect_scsi_host_caps(union _virNodeDevCapData *d)
char *vports = NULL;
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);
if (virIsCapableFCHost(NULL, d->scsi_host.host)) {

View File

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