# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1262951212 0
# Node ID dd9250567d18e8d0bfe5149692f22fb849952647
# Parent 819c21064517703461143701a60792218f0afd7f
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@xxxxxxxxxxxxx>
---
tools/libxl/libxl_device.c | 20 ++++++++------------
tools/libxl/libxl_internal.c | 25 +++----------------------
tools/libxl/libxl_internal.h | 17 -----------------
3 files changed, 11 insertions(+), 51 deletions(-)
diff -r 819c21064517 -r dd9250567d18 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c Fri Jan 08 11:46:17 2010 +0000
+++ b/tools/libxl/libxl_device.c Fri Jan 08 11:46:52 2010 +0000
@@ -240,9 +240,8 @@ int libxl_devices_destroy(struct libxl_c
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_c
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_c
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 *c
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 *c
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 *c
}
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 -r 819c21064517 -r dd9250567d18 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c Fri Jan 08 11:46:17 2010 +0000
+++ b/tools/libxl/libxl_internal.c Fri Jan 08 11:46:52 2010 +0000
@@ -26,28 +26,6 @@ int libxl_error_set(struct libxl_ctx *ct
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)
@@ -180,6 +158,9 @@ void xl_logv(struct libxl_ctx *ctx, int
char *s;
int rc;
+ if (!ctx->log_callback)
+ return;
+
rc = vasprintf(&s, fmt, ap);
if (rc<0) { s = enomem; goto x; }
diff -r 819c21064517 -r dd9250567d18 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Fri Jan 08 11:46:17 2010 +0000
+++ b/tools/libxl/libxl_internal.h Fri Jan 08 11:46:52 2010 +0000
@@ -96,23 +96,6 @@ int xs_writev(struct xs_handle *xsh, xs_
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);
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|