diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index ddb36ce..7bbc924 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -240,9 +240,8 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force) flexarray_t *toremove; struct libxl_ctx clone; - if (libxl_clone_context_xs(ctx, &clone)) { - XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context"); - return ERROR_NOMEM; + if (libxl_ctx_init(&clone, LIBXL_VERSION)) { + return -1; } toremove = flexarray_make(16, 1); @@ -250,7 +249,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force) l1 = libxl_xs_directory(&clone, XBT_NULL, path, &num1); if (!l1) { XL_LOG(&clone, XL_LOG_ERROR, "%s is empty", path); - libxl_discard_cloned_context_xs(&clone); + libxl_ctx_free(&clone); return -1; } for (i = 0; i < num1; i++) { @@ -294,7 +293,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force) xs_rm(clone.xsh, XBT_NULL, path); } flexarray_free(toremove); - libxl_discard_cloned_context_xs(&clone); + libxl_ctx_free(&clone); return 0; } @@ -304,9 +303,8 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait) int rc; struct libxl_ctx clone; - if (libxl_clone_context_xs(ctx, &clone)) { - XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context"); - return ERROR_NOMEM; + if (libxl_ctx_init(&clone, LIBXL_VERSION)) { + return -1; } /* Create strings */ @@ -323,7 +321,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait) rc = libxl_device_destroy(&clone, backend_path, !wait); if (rc == -1) { - libxl_discard_cloned_context_xs(&clone); + libxl_ctx_free(&clone); return ERROR_FAIL; } @@ -335,9 +333,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait) } xs_rm(clone.xsh, XBT_NULL, hotplug_path); - libxl_free(&clone, hotplug_path); - libxl_free(&clone, backend_path); - libxl_discard_cloned_context_xs(&clone); + libxl_ctx_free(&clone); return 0; } diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index eeadbfd..f48e9eb 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -28,28 +28,6 @@ int libxl_error_set(struct libxl_ctx *ctx, int code) return 0; } -int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to) -{ - /* We could just copy the structs, but since - * maxsize is not a pointer we need to take care - * of our own GC. */ - *to = *from; - to->alloc_ptrs = NULL; - to->alloc_maxsize = 256; - to->alloc_ptrs = calloc(to->alloc_maxsize, sizeof(void *)); - if (!to->alloc_ptrs) - return ERROR_NOMEM; - return 0; -} - -void libxl_discard_cloned_context(struct libxl_ctx *ctx) -{ - /* We only need to worry about GC-related fields */ - (void)libxl_ctx_free(ctx); - if (ctx->alloc_ptrs) - free(ctx->alloc_ptrs); -} - int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr) { int i; @@ -180,6 +158,9 @@ void xl_logv(struct libxl_ctx *ctx, int loglevel, int errnoval, char *s; int rc; + if (!ctx->log_callback) + return; + rc = vasprintf(&s, fmt, ap); if (rc<0) { s = enomem; goto x; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 1f7e64a..44e97d1 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -96,23 +96,6 @@ typedef struct { int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]); /* memory allocation tracking/helpers */ -int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to); -static inline int libxl_clone_context_xs( - struct libxl_ctx *from, struct libxl_ctx *to) -{ - int rc; - rc = libxl_clone_context(from, to); - if (rc) return rc; - to->xsh = xs_daemon_open(); - return 0; -} -void libxl_discard_cloned_context(struct libxl_ctx *ctx); -static inline void libxl_discard_cloned_context_xs( - struct libxl_ctx *ctx) -{ - libxl_discard_cloned_context(ctx); - xs_daemon_close(ctx->xsh); -} int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr); int libxl_free(struct libxl_ctx *ctx, void *ptr); int libxl_free_all(struct libxl_ctx *ctx);