From: Osier Yang Date: Mon, 7 Jan 2013 17:05:32 +0000 (+0800) Subject: nodedev: Dump max vports and vports in use for HBA's XML X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=448be8f706693327d77756fb47aa275edfb14977;p=libvirt.git nodedev: Dump max vports and vports in use for HBA's XML This enrichs HBA's xml by dumping the number of max vports and vports in use. Format is like: 164 5 * docs/formatnode.html.in: (Document the new XML) * docs/schemas/nodedev.rng: (Add the schema) * src/conf/node_device_conf.h: (New member for data.scsi_host) * src/node_device/node_device_linux_sysfs.c: (Collect the value of max_vports and vports) --- diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index fcaaaafa39..5712bcf1f5 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -136,9 +136,13 @@
The SCSI host number.
capability
Current capabilities include "vports_ops" (indicates - vport operations are supported) and "fc_host", the later - implies following sub-elements: wwnn, - wwpn, fabric_wwn. + vport operations are supported) and "fc_host". "vport_ops" + could contain two optional sub-elements: vports, + and max_vports. vports shows the + number of vport in use. max_vports shows the + maximum vports the HBA supports. "fc_host" implies following + sub-elements: wwnn, wwpn, and + fabric_wwn.
diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 04d8ee9b1d..1f5dcb9718 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -268,6 +268,12 @@ vports_ops + + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index f743b26b1b..b4d8cb3169 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -391,7 +391,12 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDefPtr def) virBufferAddLit(&buf, " \n"); } if (data->scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS) { - virBufferAddLit(&buf, " \n"); + virBufferAddLit(&buf, " \n"); + virBufferAsprintf(&buf, " %d\n", + data->scsi_host.max_vports); + virBufferAsprintf(&buf, " %d\n", + data->scsi_host.vports); + virBufferAddLit(&buf, " \n"); } break; diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 2946026c40..ca5ec726d5 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -138,6 +138,8 @@ struct _virNodeDevCapsDef { char *wwpn; char *fabric_wwn; unsigned int flags; + int max_vports; + int vports; } scsi_host; struct { char *name; diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c index 85bbab610f..a1c36372b1 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -40,6 +40,8 @@ int detect_scsi_host_caps_linux(union _virNodeDevCapData *d) { + char *max_vports = NULL; + char *vports = NULL; int ret = -1; VIR_DEBUG("Checking if host%d is an FC HBA", d->scsi_host.host); @@ -50,7 +52,7 @@ detect_scsi_host_caps_linux(union _virNodeDevCapData *d) if (virReadFCHost(NULL, d->scsi_host.host, "port_name", - &d->scsi_host.wwpn) == -1) { + &d->scsi_host.wwpn) < 0) { VIR_ERROR(_("Failed to read WWPN for host%d"), d->scsi_host.host); goto cleanup; } @@ -58,7 +60,7 @@ detect_scsi_host_caps_linux(union _virNodeDevCapData *d) if (virReadFCHost(NULL, d->scsi_host.host, "node_name", - &d->scsi_host.wwnn) == -1) { + &d->scsi_host.wwnn) < 0) { VIR_ERROR(_("Failed to read WWNN for host%d"), d->scsi_host.host); goto cleanup; } @@ -66,23 +68,62 @@ detect_scsi_host_caps_linux(union _virNodeDevCapData *d) if (virReadFCHost(NULL, d->scsi_host.host, "fabric_name", - &d->scsi_host.fabric_wwn) == -1) { + &d->scsi_host.fabric_wwn) < 0) { VIR_ERROR(_("Failed to read fabric WWN for host%d"), d->scsi_host.host); goto cleanup; } } - if (virIsCapableVport(NULL, d->scsi_host.host) == 0) + if (virIsCapableVport(NULL, d->scsi_host.host) == 0) { d->scsi_host.flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; + if (virReadFCHost(NULL, + d->scsi_host.max_vports, + "max_npiv_vports", + &max_vports) < 0) { + VIR_ERROR(_("Failed to read max_npiv_vports for host%d"), + d->scsi_host.host); + goto cleanup; + } + + if (virReadFCHost(NULL, + d->scsi_host.max_vports, + "npiv_vports_inuse", + &vports) < 0) { + VIR_ERROR(_("Failed to read npiv_vports_inuse for host%d"), + d->scsi_host.host); + goto cleanup; + } + + if (virStrToLong_i(max_vports, NULL, 10, + &d->scsi_host.max_vports) < 0) { + VIR_ERROR(_("Failed to parse value of max_npiv_vports '%s'"), + max_vports); + goto cleanup; + } + + if (virStrToLong_i(vports, NULL, 10, + &d->scsi_host.vports) < 0) { + VIR_ERROR(_("Failed to parse value of npiv_vports_inuse '%s'"), + vports); + goto cleanup; + } + } + ret = 0; cleanup: if (ret < 0) { + /* Clear the two flags in case of producing confusing XML output */ + d->scsi_host.flags &= ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS); + VIR_FREE(d->scsi_host.wwnn); VIR_FREE(d->scsi_host.wwpn); VIR_FREE(d->scsi_host.fabric_wwn); } + VIR_FREE(max_vports); + VIR_FREE(vports); return ret; }