libxenlight: fix uuid code
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 1 Dec 2009 13:45:45 +0000 (13:45 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 1 Dec 2009 13:45:45 +0000 (13:45 +0000)
- Use proper constants
- Use functions from the uuid library
- Fix broken pointer handling in libxl_dominfo

Signed-off-by: Andres Lagar-Cavilla <andres@lagarcavilla.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_utils.c
tools/libxl/xen_uuid.h

index a684ccdcff962c89116acdea85952b328e10c97f..002abf1a951175421393588b71f7e6c4554092d7 100644 (file)
@@ -284,7 +284,7 @@ redo:
             ptr = ptr2;
             size *= 2;
         }
-        memcpy(ptr[index].uuid, info[i].handle, 16 * sizeof(uint8_t));
+        memcpy(&(ptr[index].uuid), info[i].handle, sizeof(xen_domain_handle_t));
         ptr[index].domid = info[i].domain;
         first_domain = info[i].domain + 1;
         index++;
@@ -478,7 +478,7 @@ static int libxl_destroy_device_model(struct libxl_ctx *ctx, uint32_t domid)
 
 int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
 {
-    char *dom_path, vm_path[41];
+    char *dom_path, vm_path[UUID_LEN_STR + 5];
     xen_uuid_t *uuid;
     int rc;
 
index 15a217feb5fb3953fa1bb0fe088bb4974dc1636b..7a215e7d7e171993de97210c070acd8926e162a3 100644 (file)
@@ -28,7 +28,7 @@
 typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *file,
                                    int line, const char *func, char *s);
 struct libxl_dominfo {
-    xen_uuid_t uuid[16];
+    xen_uuid_t uuid;
     uint32_t domid;
 };
 
index b42bfc6991a7885fc5584c61d3349ffb96abe73d..6c4b04fd0f8b4538b1f2e8278a0bef204728bc7c 100644 (file)
@@ -92,7 +92,7 @@ int libxl_uuid_to_domid(struct libxl_ctx *ctx, xen_uuid_t *uuid, uint32_t *domid
     int nb_domain, i;
     struct libxl_dominfo *info = libxl_domain_list(ctx, &nb_domain);
     for (i = 0; i < nb_domain; i++) {
-        if (!memcmp(info[i].uuid, uuid, 16)) {
+        if (!xen_uuid_compare(&(info[i].uuid), uuid)) {
             *domid = info[i].domid;
             free(info);
             return 0;
@@ -108,8 +108,8 @@ int libxl_domid_to_uuid(struct libxl_ctx *ctx, xen_uuid_t **uuid, uint32_t domid
     struct libxl_dominfo *info = libxl_domain_list(ctx, &nb_domain);
     for (i = 0; i < nb_domain; i++) {
         if (domid == info[i].domid) {
-            *uuid = libxl_zalloc(ctx, 16);
-            memcpy(*uuid, info[i].uuid, 16);
+            *uuid = libxl_zalloc(ctx, sizeof(xen_uuid_t));
+            xen_uuid_copy(*uuid, &(info[i].uuid));
             free(info);
             return 0;
         }
@@ -121,9 +121,9 @@ int libxl_domid_to_uuid(struct libxl_ctx *ctx, xen_uuid_t **uuid, uint32_t domid
 int libxl_is_uuid(char *s)
 {
     int i;
-    if (!s || strlen(s) != 36)
+    if (!s || strlen(s) != UUID_LEN_STR)
         return 0;
-    for (i = 0; i < 36; i++) {
+    for (i = 0; i < UUID_LEN_STR; i++) {
         if (i == 8 || i == 13 || i == 18 || i == 23) {
             if (s[i] != '-')
                 return 0;
@@ -147,7 +147,7 @@ xen_uuid_t *libxl_string_to_uuid(struct libxl_ctx *ctx, char *s)
 
 char *libxl_uuid_to_string(struct libxl_ctx *ctx, xen_uuid_t *uuid)
 {
-    char uuid_str[39];
+    char uuid_str[UUID_LEN_STR + 3];
     if (!uuid)
         return NULL;
     xen_uuid_to_string(uuid, uuid_str, sizeof(uuid_str));
index 21c41f79bf275d78539e6eb1e822d9aa5995f3a7..9f6540f3259845eff93f49ba2022b2b1857a4ae5 100644 (file)
@@ -128,4 +128,8 @@ static inline int xen_uuid_compare(xen_uuid_t *uuid1, xen_uuid_t *uuid2)
 
 #endif
 
+#ifndef UUID_LEN_STR
+#define UUID_LEN_STR  (128 /*bit*/ / 4 /*nibbles*/ + 4 /*hyphens*/)
+#endif /* UUID_LEN_STR */
+
 #endif /* __XEN_UUID_H__ */