|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 17/23] 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>
---
tools/libxl/libxl_internal.h | 4 +++
tools/libxl/libxl_uuid.c | 51 ++++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_uuid.h | 12 ++++++++++
3 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index c2b73c4..9f8ab49 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -3085,6 +3085,10 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc,
*/
#define CTYPE(isfoo,c) (isfoo((unsigned char)(c)))
+/*
+ * Compile time assertion
+ */
+#define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
#endif
diff --git a/tools/libxl/libxl_uuid.c b/tools/libxl/libxl_uuid.c
index ecc29c7..4b35e88 100644
--- a/tools/libxl/libxl_uuid.c
+++ b/tools/libxl/libxl_uuid.c
@@ -102,6 +102,57 @@ uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid)
return uuid->uuid;
}
+#elif defined(__FreeBSD__)
+
+int libxl_uuid_is_nil(libxl_uuid *uuid)
+{
+
+ return uuid_is_nil(&uuid->uuid, NULL);
+}
+
+void libxl_uuid_generate(libxl_uuid *uuid)
+{
+ uint32_t status;
+
+ BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t));
+ uuid_create(&uuid->uuid, &status);
+ assert(status == uuid_s_ok);
+}
+
+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;
+}
+
+void libxl_uuid_copy(libxl_uuid *dst, const libxl_uuid *src)
+{
+
+ memcpy(&dst->uuid, &src->uuid, sizeof(dst->uuid));
+}
+
+void libxl_uuid_clear(libxl_uuid *uuid)
+{
+
+ memset(&uuid->uuid, 0, sizeof(uuid->uuid));
+}
+
+int libxl_uuid_compare(libxl_uuid *uuid1, libxl_uuid *uuid2)
+{
+
+ return uuid_compare(&uuid1->uuid, &uuid2->uuid, NULL);
+}
+
+uint8_t *libxl_uuid_bytearray(libxl_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 93c65a7..3604180 100644
--- a/tools/libxl/libxl_uuid.h
+++ b/tools/libxl/libxl_uuid.h
@@ -47,6 +47,18 @@ typedef struct {
uint8_t uuid[16];
} libxl_uuid;
+#elif defined(__FreeBSD__)
+
+#include <uuid.h>
+#include <stdint.h>
+
+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"
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |