The auto-generated WWN comply with the new addressing schema of WWN: <quote> the first nibble is either hex 5 or 6 followed by a 3-byte vendor identifier and 36 bits for a vendor-specified serial number. </quote> We choose hex 5 for the first nibble. And use Qumranet's OUI (00:1A:4A) as the 3-byte vendor indentifier. The last 36 bits are auto-generated. --- src/conf/node_device_conf.c | 36 +++++++++++++++++++----------------- src/libvirt_private.syms | 1 + src/util/virrandom.c | 18 ++++++++++++++++++ src/util/virrandom.h | 1 + 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index d9dc9ac..127a4ae 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -37,6 +37,7 @@ #include "buf.h" #include "uuid.h" #include "pci.h" +#include "virrandom.h" #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -63,19 +64,12 @@ VIR_ENUM_IMPL(virNodeDevHBACap, VIR_NODE_DEV_CAP_HBA_LAST, static int virNodeDevCapsDefParseString(const char *xpath, xmlXPathContextPtr ctxt, - char **string, - virNodeDeviceDefPtr def, - const char *missing_error_fmt) + char **string) { char *s; - s = virXPathString(xpath, ctxt); - if (s == NULL) { - virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, - missing_error_fmt, - def->name); + if (!(s = virXPathString(xpath, ctxt))) return -1; - } *string = s; return 0; @@ -763,18 +757,26 @@ virNodeDevCapScsiHostParseXML(xmlXPathContextPtr ctxt, if (virNodeDevCapsDefParseString("string(./wwnn[1])", ctxt, - &data->scsi_host.wwnn, - def, - _("no WWNN supplied for '%s'")) < 0) { - goto out; + &data->scsi_host.wwnn) < 0) { + if (virRandomGenerateWWN(&data->scsi_host.wwnn) < 0) { + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, + _("no WWNN supplied for '%s', and " + "auto-generation failed"), + def->name); + goto out; + } } if (virNodeDevCapsDefParseString("string(./wwpn[1])", ctxt, - &data->scsi_host.wwpn, - def, - _("no WWPN supplied for '%s'")) < 0) { - goto out; + &data->scsi_host.wwpn) < 0) { + if (virRandomGenerateWWN(&data->scsi_host.wwpn) < 0) { + virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR, + _("no WWPN supplied for '%s', and " + "auto-generation failed"), + def->name); + goto out; + } } ctxt->node = orignode2; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d6ad36c..421986b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1373,6 +1373,7 @@ virPidFileDeletePath; # virrandom.h virRandomBits; +virRandomGenerateWWN; virRandomInitialize; diff --git a/src/util/virrandom.c b/src/util/virrandom.c index ec0cf03..3116275 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -22,10 +22,15 @@ #include <config.h> #include <stdlib.h> +#include <inttypes.h> #include "virrandom.h" #include "threads.h" #include "count-one-bits.h" +#include "util.h" +#include "virterror_internal.h" + +#define VIR_FROM_THIS VIR_FROM_NONE static char randomState[128]; static struct random_data randomData; @@ -79,3 +84,16 @@ uint64_t virRandomBits(int nbits) virMutexUnlock(&randomLock); return ret; } + +#define QUMRANET_OUI "001a4a" + +int +virRandomGenerateWWN(char **wwn) { + if (virAsprintf(wwn, "5" QUMRANET_OUI "%09" PRIx64, + virRandomBits(36)) < 0) { + virReportOOMError(); + return -1; + } + + return 0; +} diff --git a/src/util/virrandom.h b/src/util/virrandom.h index e180a2f..443451e 100644 --- a/src/util/virrandom.h +++ b/src/util/virrandom.h @@ -27,5 +27,6 @@ int virRandomInitialize(uint32_t seed) ATTRIBUTE_RETURN_CHECK; uint64_t virRandomBits(int nbits); +int virRandomGenerateWWN(char **wwn); #endif /* __VIR_RANDOM_H__ */ -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list