[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] libxl: add support for FreeBSD uuid implementation



commit 18b102a93341cd6c29ca97bcebbd19d3ae697771
Author:     Roger Pau Monne <roger.pau@xxxxxxxxxx>
AuthorDate: Fri Jun 27 16:06:28 2014 +0200
Commit:     Ian Campbell <ian.campbell@xxxxxxxxxx>
CommitDate: Wed Jul 2 15:53:12 2014 +0100

    libxl: add support for FreeBSD uuid implementation

    Add the FreeBSD specific uuid implementation. Since uuid_t is not
    defined as an array, but as a struct on FreeBSD, use a union with a
    array in order to be able to return the uuid as a bytearray.

    Also, added a libxl internal compile time assert macro, that is used
    to assert that the size of uuid_t is the same as the union used in
    libxl.

    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
    Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxl/libxl_internal.h |    9 +++++++++
 tools/libxl/libxl_uuid.c     |   40 ++++++++++++++++++++++++++++++++--------
 tools/libxl/libxl_uuid.h     |   12 +++++++-----
 3 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 2eea557..e8f2abb 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3184,6 +3184,15 @@ int libxl__string_parse_json(libxl__gc *gc, const 
libxl__json_object *o,

 int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, size_t len);

+/*
+ * Compile time assertion
+ */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#define BUILD_BUG_ON(p) ({ _Static_assert(!(p), "!(" #p ")"); })
+#else
+#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
+#endif
+
 #endif

 /*
diff --git a/tools/libxl/libxl_uuid.c b/tools/libxl/libxl_uuid.c
index 172b7d1..7d4a032 100644
--- a/tools/libxl/libxl_uuid.c
+++ b/tools/libxl/libxl_uuid.c
@@ -59,21 +59,35 @@ uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)
     return uuid->uuid;
 }

-#elif defined(__NetBSD__)
+#elif defined(__FreeBSD__) || defined(__NetBSD__)

 int libxl_uuid_is_nil(const libxl_uuid *uuid)
 {
     uint32_t status;
-    return uuid_is_nil((uuid_t *)uuid->uuid, &status);
+
+    return uuid_is_nil(&uuid->uuid, &status);
 }

 void libxl_uuid_generate(libxl_uuid *uuid)
 {
     uint32_t status;
-    uuid_create((uuid_t *)uuid->uuid, &status);
+
+    BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t));
+    uuid_create(&uuid->uuid, &status);
     assert(status == uuid_s_ok);
 }

+#ifdef __FreeBSD__
+int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
+{
+    uint32_t status;
+
+    uuid_from_string(in, &uuid->uuid, &status);
+    if (status != uuid_s_ok)
+        return -1;
+    return 0;
+}
+#else
 #define LIBXL__UUID_PTRS(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], \
@@ -85,33 +99,43 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)
     return 0;
 }
 #undef LIBXL__UUID_PTRS
+#endif

 void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst,
                      const libxl_uuid *src)
 {
-     memcpy(dst->uuid, src->uuid, sizeof(dst->uuid));
+    memcpy(&dst->uuid, &src->uuid, sizeof(dst->uuid));
 }

 void libxl_uuid_clear(libxl_uuid *uuid)
 {
-     memset(uuid->uuid, 0, sizeof(uuid->uuid));
+    memset(&uuid->uuid, 0, sizeof(uuid->uuid));
 }

+#ifdef __FreeBSD__
+int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2)
+{
+
+    return uuid_compare(&uuid1->uuid, &uuid2->uuid, NULL);
+}
+#else
 int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2)
 {
      return memcmp(uuid1->uuid, uuid2->uuid, sizeof(uuid1->uuid));
 }
+#endif

 const uint8_t *libxl_uuid_bytearray_const(const libxl_uuid *uuid)
 {
-    return uuid->uuid;
+
+    return uuid->uuid_raw;
 }

 uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)
 {
-    return uuid->uuid;
-}

+    return uuid->uuid_raw;
+}
 #else

 #error "Please update libxl_uuid.c for your OS"
diff --git a/tools/libxl/libxl_uuid.h b/tools/libxl/libxl_uuid.h
index 0c2a1e7..196b5bc 100644
--- a/tools/libxl/libxl_uuid.h
+++ b/tools/libxl/libxl_uuid.h
@@ -33,20 +33,22 @@ typedef struct {

 #define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(((uint8_t *)arg.uuid))

-#elif defined(__NetBSD__)
+#elif defined(__FreeBSD__) || defined(__NetBSD__)

 #include <uuid.h>
+#include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>

-#define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(arg.uuid)
-
-typedef struct {
-    uint8_t uuid[16];
+typedef union {
+    uuid_t uuid;
+    uint8_t uuid_raw[16];
 } libxl_uuid;

+#define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(arg.uuid_raw)
+
 #else

 #error "Please update libxl_uuid.h for your OS"
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.