On Tue, Feb 07, 2012 at 09:38:50PM +0800, Osier Yang wrote:
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 for the 3-bytes vendor ID,
we uses the OUI according to underlying hypervisor type, (invoking
virConnectGetType to get the virt type). e.g. If virConnectGetType
returns "QEMU", we use Qumranet's OUI (00:1A:4A), if returns
ESX|VMWARE, we use VMWARE's OUI (00:05:69). Currently it only
supports qemu|xen|libxl|xenapi|hyperv|esx|vmware drivers. The last
36 bits are auto-generated.
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
index ec0cf03..760b975 100644
--- a/src/util/virrandom.c
+++ b/src/util/virrandom.c
@@ -22,10 +22,20 @@
#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"
+#include "conf/domain_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+#define virRandomError(code, ...) \
+ virReportErrorHelper(VIR_FROM_NONE, code, __FILE__, \
+ __FUNCTION__, __LINE__, __VA_ARGS__)
static char randomState[128];
static struct random_data randomData;
@@ -79,3 +89,46 @@ uint64_t virRandomBits(int nbits)
virMutexUnlock(&randomLock);
return ret;
}
+
+#define QUMRANET_OUI "001a4a"
+#define VMWARE_OUI "000569"
+#define MICROSOFT_OUI "0050f2"
+#define XEN_OUI "00163e"
+
+int
+virRandomGenerateWWN(char **wwn,
+ const char *virt_type) {
+ const char *oui = NULL;
+
+ if (!virt_type) {
+ virRandomError(VIR_ERR_INVALID_ARG, "%s",
+ _("argument virt_type must not be NULL"));
+ return -1;
+ }
+
+ if (STREQ(virt_type, "QEMU")) {
+ oui = QUMRANET_OUI;
+ } else if (STREQ(virt_type, "Xen") ||
+ STREQ(virt_type, "xenlight") ||
+ STREQ(virt_type, "XenAPI")) {
+ oui = XEN_OUI;
+ } else if (STREQ(virt_type, "ESX") ||
+ STREQ(virt_type, "VMWARE")) {
+ oui = VMWARE_OUI;
+ } else if (STREQ(virt_type, "HYPER-V")) {
+ oui = MICROSOFT_OUI;
+ } else {
+ virRandomError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Unsupported virt type"));
+ return -1;
+ }
+
+ if (virAsprintf(wwn, "5" "%s%09" PRIx64,
+ oui, virRandomBits(36)) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ return 0;
+}
This has broken the build on Mingw32, because PRIx64 is coming
from the Win32 headers, but virAsprintf uses the gnulib printf.
You need to use the normal "%09llu" format specific here,
not the PRIx64 macro.
We ought to have a syntax check test to forbid use of PRIx*
stuff really.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|