Skip to contentSkip to conversation

: xl: randomly generate UUID's

PATCH Superseded Gianni Tedesco 1 participant 1 message Sep 1, 2010

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 : xl: randomly generate UUID's

Changes since v4:
- Really fix it for NetBSD? Define our own structure which is a byte array. Only use uuid_is_nul and uuid_create which should be safe for our portability purposes. Previous attempt at portability wrapper was just wrong minded.
- Remove uuid_to_string since our approach is to use a couple of macros for this
- License under LGPL in line with rest of libxl
Changes since v3:
- Fix LIBXL_UUID_BYTES on NetBSD. Note that the code assumes uint8_t[16] to always be interchangeable with libxl_uuid_t.
- Return error messages when uuid_parse fails, spotted by Owen Smith
- Implement "uuid" parameter in xl and exit with an error if parse fails
Changes since v2:
- Re-based to remove orthogonal concern of UUID string formatting fixed in 22001:0b6f82eaaea9 "xl: make libxl_uuid2string internal to libxenlight"
- Incorporated Christoph Egger's suggestions

8<--------------------------------------------------------------- This patch converts xl to randomly generate UUID's rather than using a dodgy time-seeded PRNG. I have ignored various suggestions so far on auto-generation of MAC addresses and left it as a topic for a future patch to solve. In other words the behaviour stays the same it's just using a true random source. This patch also implements the "uuid" config file parameter in xl.

tools/libxl/Makefile +3 -0
diff -r 573ddf5cc145 tools/libxl/Makefile
@@ -16,6 +16,9 @@ CFLAGS += -I. -fPIC
 CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
 
 LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS)
+ifeq ($(CONFIG_Linux),y)
+LIBS += -luuid
+endif
 
 LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o
 ifeq ($(LIBXL_BLKTAP),y)
tools/libxl/libxl.c +3 -3
diff -r 573ddf5cc145 tools/libxl/libxl.c
@@ -131,7 +131,7 @@ int libxl_domain_make(libxl_ctx *ctx, li
     *domid = -1;
 
     /* Ultimately, handle is an array of 16 uint8_t, same as uuid */
-    memcpy(handle, info->uuid, sizeof(xen_domain_handle_t));
+    libxl_uuid_copy((libxl_uuid *)handle, &info->uuid);
 
     ret = xc_domain_create(ctx->xch, info->ssidref, handle, flags, domid);
     if (ret < 0) {
@@ -1506,8 +1506,8 @@ static int libxl_create_stubdom(libxl_ct
     memset(&c_info, 0x00, sizeof(libxl_domain_create_info));
     c_info.hvm = 0;
     c_info.name = libxl_sprintf(&gc, "%s-dm", _libxl_domid_to_name(&gc, info->domid));
-    for (i = 0; i < 16; i++)
-        c_info.uuid[i] = info->uuid[i];
+
+    libxl_uuid_copy(&c_info.uuid, &info->uuid);
 
     memset(&b_info, 0x00, sizeof(libxl_domain_build_info));
     b_info.max_vcpus = 1;
tools/libxl/libxl.h +1 -7
diff -r 573ddf5cc145 tools/libxl/libxl.h
@@ -131,13 +131,7 @@
 #include <xs.h>
 #include <sys/wait.h> /* for pid_t */
 
-typedef uint8_t libxl_uuid[16];
-#define LIBXL_UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
-#define LIBXL_UUID_BYTES(uuid) uuid[0], uuid[1], uuid[2], uuid[3], \
-            uuid[4], uuid[5], uuid[6], uuid[7], \
-            uuid[8], uuid[9], uuid[10], uuid[11], \
-            uuid[12], uuid[13], uuid[14], uuid[15] \
-
+#include "libxl_uuid.h"
 
 typedef uint8_t libxl_mac[6];
 
tools/libxl/libxl_uuid.h new file +134 -0

134 lines not on this page · raw message

tools/libxl/xl.c +0 -2
diff -r 573ddf5cc145 tools/libxl/xl.c
@@ -74,8 +74,6 @@ int main(int argc, char **argv)
     argc -= optind;
     optind = 1;
 
-    srand(time(0));
-
     cspec = cmdtable_lookup(cmd);
     if (cspec)
         ret = cspec->cmd_impl(argc, argv);
tools/libxl/xl_cmdimpl.c +25 -19

94 lines not on this page · raw message