From: Vincent Hanquez Subject: [PATCH 5/8] remove all cloning logic. Date: Fri, 8 Jan 2010 11:17:58 +0000 Message-ID: <1262949481-25530-6-git-send-email-vincent.hanquez@eu.citrix.com> References: <1262949481-25530-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.6" Return-path: In-Reply-To: <1262949481-25530-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.6 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable replace by simpler xl ctx init/free calls. also don't segfault if there's no callback for log. Signed-off-by: Vincent Hanquez --- 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(-) --------------1.6.6 Content-Type: text/x-patch; name="0005-remove-all-cloning-logic.patch" Content-Disposition: attachment; filename="0005-remove-all-cloning-logic.patch" Content-Transfer-Encoding: quoted-printable 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, uint= 32_t domid, int force) flexarray_t *toremove; struct libxl_ctx clone; =20 - 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; } =20 toremove =3D flexarray_make(16, 1); @@ -250,7 +249,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint= 32_t domid, int force) l1 =3D 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 =3D 0; i < num1; i++) { @@ -294,7 +293,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint= 32_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; } =20 @@ -304,9 +303,8 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_dev= ice *dev, int wait) int rc; struct libxl_ctx clone; =20 - 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; } =20 /* Create strings */ @@ -323,7 +321,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_dev= ice *dev, int wait) =20 rc =3D libxl_device_destroy(&clone, backend_path, !wait); if (rc =3D=3D -1) { - libxl_discard_cloned_context_xs(&clone); + libxl_ctx_free(&clone); return ERROR_FAIL; } =20 @@ -335,9 +333,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_dev= ice *dev, int wait) } =20 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; } =20 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; } =20 -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 =3D *from; - to->alloc_ptrs =3D NULL; - to->alloc_maxsize =3D 256; - to->alloc_ptrs =3D 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; =20 + if (!ctx->log_callback) + return; + rc =3D vasprintf(&s, fmt, ap); if (rc<0) { s =3D enomem; goto x; } =20 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[]); =20 /* 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 =3D libxl_clone_context(from, to); - if (rc) return rc; - to->xsh =3D 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); --------------1.6.6 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.6--