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.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
docs/formatnode.html.in | 11 +++++++++++
docs/schemas/nodedev.rng | 6 ++++++
src/conf/node_device_conf.c | 23 ++++++++++++++++------
src/conf/node_device_conf.h | 1 +
src/node_device/node_device_linux_sysfs.c | 6 ++++++
src/test/test_driver.c | 5 +++--
.../pci_8086_27c5_scsi_host_0_unique_id.xml | 8 ++++++++
tests/nodedevxml2xmltest.c | 1 +
8 files changed, 53 insertions(+), 8 deletions(-)
create mode 100644 tests/nodedevschemadata/pci_8086_27c5_scsi_host_0_unique_id.xml
diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in
index 5932811..b820a34 100644
--- a/docs/formatnode.html.in
+++ b/docs/formatnode.html.in
@@ -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"
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
index b6de201..c4f402c 100644
--- a/docs/schemas/nodedev.rng
+++ b/docs/schemas/nodedev.rng
@@ -340,6 +340,12 @@
</element>
<optional>
+ <element name='unique_id'>
+ <ref name='positiveInteger'/>
+ </element>
+ </optional>
+
+ <optional>
<zeroOrMore>
<element name='capability'>
<choice>
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 30aa477..910a371 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -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) {
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 61d2e19..b5bfb7b 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -171,6 +171,7 @@ struct _virNodeDevCapsDef {
} net;
struct {
unsigned int host;
+ int unique_id;
char *wwnn;
char *wwpn;
char *fabric_wwn;
diff --git a/src/node_device/node_device_linux_sysfs.c
b/src/node_device/node_device_linux_sysfs.c
index 6d9726f..be95e51 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -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)) {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 7bfc88d..11821af 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -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;
}
diff --git a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0_unique_id.xml
b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0_unique_id.xml
new file mode 100644
index 0000000..5428f59
--- /dev/null
+++ b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0_unique_id.xml
@@ -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>
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index fe1fd88..a37d729 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -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");
--
1.9.3