debuggers.hg

changeset 20821:dd9250567d18

libxenlight: remove all cloning logic.

replace by simpler xl ctx init/free calls.
also don't segfault if there's no callback for log.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 08 11:46:52 2010 +0000 (2010-01-08)
parents 819c21064517
children 9a49e6a66bf0
files tools/libxl/libxl_device.c tools/libxl/libxl_internal.c tools/libxl/libxl_internal.h
line diff
     1.1 --- a/tools/libxl/libxl_device.c	Fri Jan 08 11:46:17 2010 +0000
     1.2 +++ b/tools/libxl/libxl_device.c	Fri Jan 08 11:46:52 2010 +0000
     1.3 @@ -240,9 +240,8 @@ int libxl_devices_destroy(struct libxl_c
     1.4      flexarray_t *toremove;
     1.5      struct libxl_ctx clone;
     1.6  
     1.7 -    if (libxl_clone_context_xs(ctx, &clone)) {
     1.8 -        XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
     1.9 -        return ERROR_NOMEM;
    1.10 +    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
    1.11 +        return -1;
    1.12      }
    1.13  
    1.14      toremove = flexarray_make(16, 1);
    1.15 @@ -250,7 +249,7 @@ int libxl_devices_destroy(struct libxl_c
    1.16      l1 = libxl_xs_directory(&clone, XBT_NULL, path, &num1);
    1.17      if (!l1) {
    1.18          XL_LOG(&clone, XL_LOG_ERROR, "%s is empty", path);
    1.19 -        libxl_discard_cloned_context_xs(&clone);
    1.20 +        libxl_ctx_free(&clone);
    1.21          return -1;
    1.22      }
    1.23      for (i = 0; i < num1; i++) {
    1.24 @@ -294,7 +293,7 @@ int libxl_devices_destroy(struct libxl_c
    1.25          xs_rm(clone.xsh, XBT_NULL, path);
    1.26      }
    1.27      flexarray_free(toremove);
    1.28 -    libxl_discard_cloned_context_xs(&clone);
    1.29 +    libxl_ctx_free(&clone);
    1.30      return 0;
    1.31  }
    1.32  
    1.33 @@ -304,9 +303,8 @@ int libxl_device_del(struct libxl_ctx *c
    1.34      int rc;
    1.35      struct libxl_ctx clone;
    1.36  
    1.37 -    if (libxl_clone_context_xs(ctx, &clone)) {
    1.38 -        XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
    1.39 -        return ERROR_NOMEM;
    1.40 +    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
    1.41 +        return -1;
    1.42      }
    1.43  
    1.44      /* Create strings */
    1.45 @@ -323,7 +321,7 @@ int libxl_device_del(struct libxl_ctx *c
    1.46  
    1.47      rc = libxl_device_destroy(&clone, backend_path, !wait);
    1.48      if (rc == -1) {
    1.49 -        libxl_discard_cloned_context_xs(&clone);
    1.50 +        libxl_ctx_free(&clone);
    1.51          return ERROR_FAIL;
    1.52      }
    1.53  
    1.54 @@ -335,9 +333,7 @@ int libxl_device_del(struct libxl_ctx *c
    1.55      }
    1.56  
    1.57      xs_rm(clone.xsh, XBT_NULL, hotplug_path);
    1.58 -    libxl_free(&clone, hotplug_path);
    1.59 -    libxl_free(&clone, backend_path);
    1.60 -    libxl_discard_cloned_context_xs(&clone);
    1.61 +    libxl_ctx_free(&clone);
    1.62      return 0;
    1.63  }
    1.64  
     2.1 --- a/tools/libxl/libxl_internal.c	Fri Jan 08 11:46:17 2010 +0000
     2.2 +++ b/tools/libxl/libxl_internal.c	Fri Jan 08 11:46:52 2010 +0000
     2.3 @@ -28,28 +28,6 @@ int libxl_error_set(struct libxl_ctx *ct
     2.4      return 0;
     2.5  }
     2.6  
     2.7 -int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to)
     2.8 -{
     2.9 -    /* We could just copy the structs, but since
    2.10 -     * maxsize is not a pointer we need to take care
    2.11 -     * of our own GC. */
    2.12 -    *to = *from;
    2.13 -    to->alloc_ptrs = NULL;
    2.14 -    to->alloc_maxsize = 256;
    2.15 -    to->alloc_ptrs = calloc(to->alloc_maxsize, sizeof(void *));
    2.16 -    if (!to->alloc_ptrs)
    2.17 -        return ERROR_NOMEM;
    2.18 -    return 0;
    2.19 -}
    2.20 -
    2.21 -void libxl_discard_cloned_context(struct libxl_ctx *ctx)
    2.22 -{
    2.23 -    /* We only need to worry about GC-related fields */
    2.24 -    (void)libxl_ctx_free(ctx);
    2.25 -    if (ctx->alloc_ptrs)
    2.26 -        free(ctx->alloc_ptrs);
    2.27 -}
    2.28 -
    2.29  int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr)
    2.30  {
    2.31      int i;
    2.32 @@ -180,6 +158,9 @@ void xl_logv(struct libxl_ctx *ctx, int 
    2.33      char *s;
    2.34      int rc;
    2.35  
    2.36 +    if (!ctx->log_callback)
    2.37 +        return;
    2.38 +
    2.39      rc = vasprintf(&s, fmt, ap);
    2.40      if (rc<0) { s = enomem; goto x; }
    2.41  
     3.1 --- a/tools/libxl/libxl_internal.h	Fri Jan 08 11:46:17 2010 +0000
     3.2 +++ b/tools/libxl/libxl_internal.h	Fri Jan 08 11:46:52 2010 +0000
     3.3 @@ -96,23 +96,6 @@ typedef struct {
     3.4  int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
     3.5  
     3.6  /* memory allocation tracking/helpers */
     3.7 -int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
     3.8 -static inline int libxl_clone_context_xs(
     3.9 -                struct libxl_ctx *from, struct libxl_ctx *to)
    3.10 -{
    3.11 -    int rc;
    3.12 -    rc = libxl_clone_context(from, to);
    3.13 -    if (rc) return rc;
    3.14 -    to->xsh = xs_daemon_open();
    3.15 -    return 0;
    3.16 -}
    3.17 -void libxl_discard_cloned_context(struct libxl_ctx *ctx);
    3.18 -static inline void libxl_discard_cloned_context_xs(
    3.19 -                struct libxl_ctx *ctx)
    3.20 -{
    3.21 -    libxl_discard_cloned_context(ctx);
    3.22 -    xs_daemon_close(ctx->xsh);
    3.23 -}
    3.24  int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr);
    3.25  int libxl_free(struct libxl_ctx *ctx, void *ptr);
    3.26  int libxl_free_all(struct libxl_ctx *ctx);