Skip to contentSkip to conversation

libxl: use LOG() macro where appropriate

PATCH Applied Wei Liu 2 participants 6 messages Oct 2, 2015 – Oct 7, 2015

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v2 cover libxl: use LOG() macro where appropriate

There are mixed usage of different logging macros. Ideally we only use one style to avoid confusion.

Rebased on top of staging.

Wei Liu (4):
libxl: convert to use LOG() macro
libxl: fix long lines and delete extraneous quotes
libxl: map LIBXL__LOG_VERBOSE to XTL_VERBOSE
libxl: fix places missed by spatch

 tools/libxl/libxl.c          | 408 +++++++++++++++++++++++--------------------
 tools/libxl/libxl_create.c   |  41 ++---
 tools/libxl/libxl_dm.c       |  50 +++---
 tools/libxl/libxl_dom.c      |  17 +-
 tools/libxl/libxl_event.c    |  48 +++--
 tools/libxl/libxl_exec.c     |   5 +-
 tools/libxl/libxl_internal.c |  17 +-
 tools/libxl/libxl_internal.h |   1 +
 tools/libxl/libxl_pci.c      | 201 ++++++++++-----------
 tools/libxl/libxl_utils.c    |  21 ++-
 tools/libxl/libxl_x86.c      |  26 ++-
 tools/libxl/libxl_xshelp.c   |   6 +-
 12 files changed, 415 insertions(+), 426 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/4 libxl: convert to use LOG() macro

This patch converts most LIBXL__LOG* macros to LOG macro. It's done with spatch plus some hand coding.

Using spatch rune:

    spatch --in-place --no-includes --include-headers \
        --sp-file libxl.spatch \
        tools/libxl/libxl*.c

with some exceptions.

libxl_json.c is untouched because the notion of ctx is in fact referring to yajl context.

libxl_qmp.c is untouched because libxl ctx is buried in qmp context.

libxl_fork.c is untouched because it's clearer to just use original code.

Some fallouts are dealt with manually. There are three categories.

Functions that don't have gc defined. Add gc definition with GC_INIT. Also try my best to make them conform with libxl coding style.

* libxl_list_domain
* libxl_domain_info
* libxl_domain_pause
* libxl_get_physinfo
* libxl_domain_set_nodeaffinity
* libxl_domain_get_nodeaffinity
* libxl_get_scheduler
* libxl_sched_credit_params_get
* libxl_sched_credit_params_set
* libxl_send_debug_keys
* libxl_xen_console_read_line
* libxl_tmem_list
* libxl_tmem_freeze
* libxl_tmem_thaw
* libxl_tmem_set
* libxl_tmem_shared_auth
* libxl_tmem_freeable
* libxl_fd_set_cloexec
* libxl_fd_set_nonblock
* libxl__init_recursive_mutex
* READ_WRITE_EXACTLY
* libxl__ao_complete_check_progress_reports

Functions don't need ctx variable anymore after conversion. Delete that variable.

* libxl__device_from_disk
* domcreate_rebuild_done
* domcreate_devmodel_started
* domcreate_attach_pci
* libxl__domain_device_model
* libxl__build_device_model_args_new
* libxl__build_device_model_args
* libxl__create_pci_backend
* libxl__device_pci_add_xenstore
* sysfs_write_bdf
* sysfs_dev_unbind
* pciback_dev_has_slot
* pciback_dev_is_assigned
* pciback_dev_assign
* pciback_dev_unassign
* pci_assignable_driver_path_write
* libxl__device_pci_assignable_remove
* libxl__xenstore_child_wait_deprecated
* libxl__xs_libxl_path
* libxl__device_model_version_running

Special handling for some functions.

* ao__abort: easier to just use original code.
* e820_sanitize: should have taken gc instead of ctx

=====
virtual patch
virtual context
virtual org
virtual report

@level1@
identifier FN =~ "LIBXL__LOG|LIBXL__LOG_ERRNO|LIBXL__LOG_ERRNOVAL"; constant l1 =~ "(LIBXL__LOG|XTL)_(DEBUG|INFO|WARNING|ERROR)"; expression ctx;
@@
FN(ctx, l1, ...);

@script:python level2@
l1 << level1.l1;
l2;
@@

import re
coccinelle.l2 = re.sub("LIBXL__LOG_|XTL_", "", l1); if coccinelle.l2 == "WARNING": coccinelle.l2 = "WARN"

@log10@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
@@
-LIBXL__LOG(ctx, l1, fmt);
+LOG(l2, fmt);

@log11@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression arg1;
@@
-LIBXL__LOG(ctx, l1, fmt, arg1);
+LOG(l2, fmt, arg1);

@log12@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression arg1, arg2;
@@
-LIBXL__LOG(ctx, l1, fmt, arg1, arg2);
+LOG(l2, fmt, arg1, arg2);

@log13@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression arg1, arg2, arg3;
@@
-LIBXL__LOG(ctx, l1, fmt, arg1, arg2, arg3);
+LOG(l2, fmt, arg1, arg2, arg3);

@log20@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
@@
-LIBXL__LOG_ERRNO(ctx, l1, fmt);
+LOGE(l2, fmt);

@log21@
expression ctx;
expression fmt;
constant level1.l1;
identifier level2.l2;
expression arg1;
@@
-LIBXL__LOG_ERRNO(ctx, l1, fmt, arg1);
+LOGE(l2, fmt, arg1);

@log22@
expression ctx;
expression fmt;
constant level1.l1;
identifier level2.l2;
expression arg1, arg2;
@@
-LIBXL__LOG_ERRNO(ctx, l1, fmt, arg1, arg2);
+LOGE(l2, fmt, arg1, arg2);

@log23@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression arg1, arg2, arg3;
@@
-LIBXL__LOG_ERRNO(ctx, l1, fmt, arg1, arg2, arg3); +LOGE(l2, fmt, arg1, arg2, arg3);

@log30@
expression fmt;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression errnoval;
@@
-LIBXL__LOG_ERRNOVAL(ctx, l1, errnoval, fmt);
+LOGEV(l2, errnoval, fmt);

@log31@
expression fmt;
expression arg1;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression errnoval;
@@
-LIBXL__LOG_ERRNOVAL(ctx, l1, errnoval, fmt, arg1); +LOGEV(l2, errnoval, fmt, arg1);

@log32@
expression fmt;
expression arg1, arg2;
expression ctx;
constant level1.l1;
identifier level2.l2;
expression errnoval;
@@
-LIBXL__LOG_ERRNOVAL(ctx, l1, errnoval, fmt, arg1, arg2); +LOGEV(l2, errnoval, fmt, arg1, arg2);
=====

---
 tools/libxl/libxl.c          | 386 +++++++++++++++++++++++--------------------
 tools/libxl/libxl_create.c   |  37 ++---
 tools/libxl/libxl_dm.c       |  50 +++---
 tools/libxl/libxl_dom.c      |  17 +-
 tools/libxl/libxl_event.c    |  48 +++---
 tools/libxl/libxl_exec.c     |   5 +-
 tools/libxl/libxl_internal.c |  17 +-
 tools/libxl/libxl_pci.c      | 158 ++++++++----------
 tools/libxl/libxl_utils.c    |  17 +-
 tools/libxl/libxl_x86.c      |  18 +-
 tools/libxl/libxl_xshelp.c   |   6 +-
 11 files changed, 372 insertions(+), 387 deletions(-)
tools/libxl/libxl.c +209 -177
index e4ea476..1b754c8 100644
@@ -90,7 +90,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
     /* The mutex is special because we can't idempotently destroy it */
 
     if (libxl__init_recursive_mutex(ctx, &ctx->lock) < 0) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Failed to initialize mutex");
+        LOG(ERROR, "Failed to initialize mutex");
         free(ctx);
         ctx = 0;
         rc = ERROR_FAIL;
@@ -402,15 +402,13 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
     if (!trans) {
         trans = our_trans = xs_transaction_start(ctx->xsh);
         if (!our_trans) {
-            LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno,
-                            "create xs transaction for domain (re)name");
+            LOGEV(ERROR, errno, "create xs transaction for domain (re)name");
             goto x_fail;
         }
     }
 
     if (!new_name) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                        "new domain name not specified");
+        LOG(ERROR, "new domain name not specified");
         rc = ERROR_INVAL;
         goto x_rc;
     }
@@ -422,16 +420,14 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
         if (rc == ERROR_INVAL) {
             /* no such domain, good */
         } else if (rc != 0) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unexpected error"
-                       "checking for existing domain");
+            LOG(ERROR, "unexpected error""checking for existing domain");
             goto x_rc;
         } else if (domid_e == domid) {
             /* domain already has this name, ok (but we do still
              * need the rest of the code as we may need to check
              * old_name, for example). */
         } else {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "domain with name \"%s\""
-                       " already exists.", new_name);
+            LOG(ERROR, "domain with name \"%s\""" already exists.", new_name);
             rc = ERROR_INVAL;
             goto x_rc;
         }
@@ -440,15 +436,18 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
     if (old_name) {
         got_old_name = xs_read(ctx->xsh, trans, name_path, &got_old_len);
         if (!got_old_name) {
-            LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno, "check old name"
-                            " for domain %"PRIu32" allegedly named `%s'",
-                            domid, old_name);
+            LOGEV(ERROR, errno,
+                  "check old name"" for domain %"PRIu32" allegedly named `%s'",
+                  domid,
+                  old_name);
             goto x_fail;
         }
         if (strcmp(old_name, got_old_name)) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "domain %"PRIu32" allegedly named "
-                   "`%s' is actually named `%s' - racing ?",
-                   domid, old_name, got_old_name);
+            LOG(ERROR,
+                "domain %"PRIu32" allegedly named ""`%s' is actually named `%s' - racing ?",
+                domid,
+                old_name,
+                got_old_name);
             free(got_old_name);
             goto x_fail;
         }
@@ -456,9 +455,11 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
     }
     if (!xs_write(ctx->xsh, trans, name_path,
                   new_name, strlen(new_name))) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "failed to write new name `%s'"
-               " for domain %"PRIu32" previously named `%s'",
-               new_name, domid, old_name);
+        LOG(ERROR,
+            "failed to write new name `%s'"" for domain %"PRIu32" previously named `%s'",
+            new_name,
+            domid,
+            old_name);
         goto x_fail;
     }
 
@@ -487,14 +488,18 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
         if (!xs_transaction_end(ctx->xsh, our_trans, 0)) {
             trans = our_trans = 0;
             if (errno != EAGAIN) {
-                LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "failed to commit new name `%s'"
-                       " for domain %"PRIu32" previously named `%s'",
-                       new_name, domid, old_name);
+                LOG(ERROR,
+                    "failed to commit new name `%s'"" for domain %"PRIu32" previously named `%s'",
+                    new_name,
+                    domid,
+                    old_name);
                 goto x_fail;
             }
-            LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "need to retry rename transaction"
-                   " for domain %"PRIu32" (name_path=\"%s\", new_name=\"%s\")",
-                   domid, name_path, new_name);
+            LOG(DEBUG,
+                "need to retry rename transaction"" for domain %"PRIu32" (name_path=\"%s\", new_name=\"%s\")",
+                domid,
+                name_path,
+                new_name);
             goto retry_transaction;
         }
         our_trans = 0;
@@ -644,17 +649,20 @@ libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out)
     int i, ret;
     xc_domaininfo_t info[1024];
     int size = 1024;
+    GC_INIT(ctx);
 
     ptr = calloc(size, sizeof(libxl_dominfo));
     if (!ptr) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating domain info");
+        LOGE(ERROR, "allocating domain info");
+        GC_FREE;
         return NULL;
     }
 
     ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
+        LOGE(ERROR, "getting domain info list");
         free(ptr);
+        GC_FREE;
         return NULL;
     }
 
@@ -662,6 +670,7 @@ libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out)
         xcinfo2xlinfo(ctx, &info[i], &ptr[i]);
     }
     *nb_domain_out = ret;
+    GC_FREE;
     return ptr;
 }
 
@@ -669,16 +678,22 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r,
                       uint32_t domid) {
     xc_domaininfo_t xcinfo;
     int ret;
+    GC_INIT(ctx);
 
     ret = xc_domain_getinfolist(ctx->xch, domid, 1, &xcinfo);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
+        LOGE(ERROR, "getting domain info list");
+        GC_FREE;
         return ERROR_FAIL;
     }
-    if (ret==0 || xcinfo.domain != domid) return ERROR_DOMAIN_NOTFOUND;
+    if (ret==0 || xcinfo.domain != domid) {
+        GC_FREE;
+        return ERROR_DOMAIN_NOTFOUND;
+    }
 
     if (info_r)
         xcinfo2xlinfo(ctx, &xcinfo, info_r);
+    GC_FREE;
     return 0;
 }
 
@@ -787,7 +802,7 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm_out)
 
     ret = xc_domain_getinfolist(ctx->xch, 1, ARRAY_SIZE(info), info);
     if (ret < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
+        LOGE(ERROR, "getting domain info list");
         goto out;
     }
 
@@ -1001,11 +1016,14 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,
 int libxl_domain_pause(libxl_ctx *ctx, uint32_t domid)
 {
     int ret;
+    GC_INIT(ctx);
     ret = xc_domain_pause(ctx->xch, domid);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "pausing domain %d", domid);
+        LOGE(ERROR, "pausing domain %d", domid);
+        GC_FREE;
         return ERROR_FAIL;
     }
+    GC_FREE;
     return 0;
 }
 
@@ -1018,8 +1036,7 @@ int libxl_domain_core_dump(libxl_ctx *ctx, uint32_t domid,
 
     ret = xc_domain_dumpcore(ctx->xch, domid, filename);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "core dumping domain %d to %s",
-                     domid, filename);
+        LOGE(ERROR, "core dumping domain %d to %s", domid, filename);
         rc = ERROR_FAIL;
         goto out;
     }
@@ -1053,7 +1070,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, uint32_t domid)
     }
     ret = xc_domain_unpause(ctx->xch, domid);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unpausing domain %d", domid);
+        LOGE(ERROR, "unpausing domain %d", domid);
         rc = ERROR_FAIL;
     }
  out:
@@ -1077,7 +1094,7 @@ int libxl__domain_pvcontrol_available(libxl__gc *gc, uint32_t domid)
 
     ret = xc_hvm_param_get(ctx->xch, domid, HVM_PARAM_CALLBACK_IRQ, &pvdriver);
     if (ret<0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting HVM callback IRQ");
+        LOGE(ERROR, "getting HVM callback IRQ");
         return ERROR_FAIL;
     }
     return !!pvdriver;
@@ -1160,7 +1177,7 @@ static void domain_death_occurred(libxl__egc *egc,
     EGC_GC;
     libxl_evgen_domain_death *const evg = *evg_upd;
 
-    LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "%s", why);
+    LOG(DEBUG, "%s", why);
 
     libxl_evgen_domain_death *evg_next = LIBXL_TAILQ_NEXT(evg, entry);
     *evg_upd = evg_next;
@@ -1208,7 +1225,7 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
 
         for (;;) {
             if (!evg) {
-                LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "[evg=0] all reported");
+                LOG(DEBUG, "[evg=0] all reported");
                 goto all_reported;
             }
 
@@ -1223,7 +1240,7 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
             }
 
             if (got == gotend) {
-                LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, " got==gotend");
+                LOG(DEBUG, " got==gotend");
                 break;
             }
 
@@ -1240,9 +1257,8 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
             }
 
             assert(evg->domid == got->domain);
-            LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, " exists shutdown_reported=%d"
-                       " dominf.flags=%x",
-                       evg->shutdown_reported, got->flags);
+            LOG(DEBUG, " exists shutdown_reported=%d"" dominf.flags=%x",
+                evg->shutdown_reported, got->flags);
 
             if (got->flags & XEN_DOMINF_dying) {
                 domain_death_occurred(egc, &evg, "dying");
@@ -1254,7 +1270,7 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
                 libxl_event *ev = NEW_EVENT(egc, DOMAIN_SHUTDOWN,
                                             got->domain, evg->user);
 
-                LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, " shutdown reporting");
+                LOG(DEBUG, " shutdown reporting");
 
                 ev->u.domain_shutdown.shutdown_reason =
                     (got->flags >> XEN_DOMINF_shutdownshift) &
@@ -1271,7 +1287,7 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
  all_reported:
  out:
 
-    LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "domain death search done");
+    LOG(DEBUG, "domain death search done");
 
     CTX_UNLOCK;
 }
@@ -1590,7 +1606,7 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
     case 0:
         break;
     case ERROR_DOMAIN_NOTFOUND:
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "non-existant domain %d", domid);
+        LOG(ERROR, "non-existant domain %d", domid);
     default:
         goto out;
     }
@@ -1620,14 +1636,14 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
     }
 
     if (libxl__device_pci_destroy_all(gc, domid) < 0)
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
+        LOG(ERROR, "pci shutdown failed for domid %d", domid);
     rc = xc_domain_pause(ctx->xch, domid);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
+        LOGEV(ERROR, rc, "xc_domain_pause failed for %d", domid);
     }
     if (dm_present) {
         if (libxl__destroy_device_model(gc, domid) < 0)
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
+            LOG(ERROR, "libxl__destroy_device_model failed for %d", domid);
 
         libxl__qmp_cleanup(gc, domid);
     }
@@ -1663,16 +1679,15 @@ static void devices_destroy_cb(libxl__egc *egc,
     }
 
     if (rc < 0)
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, 
-                   "libxl__devices_destroy failed for %d", domid);
+        LOG(ERROR, "libxl__devices_destroy failed for %d", domid);
 
     vm_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/vm", dom_path));
     if (vm_path)
         if (!xs_rm(ctx->xsh, XBT_NULL, vm_path))
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_rm failed for %s", vm_path);
+            LOGE(ERROR, "xs_rm failed for %s", vm_path);
 
     if (!xs_rm(ctx->xsh, XBT_NULL, dom_path))
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_rm failed for %s", dom_path);
+        LOGE(ERROR, "xs_rm failed for %s", dom_path);
 
     xs_rm(ctx->xsh, XBT_NULL, libxl__xs_libxl_path(gc, domid));
     xs_rm(ctx->xsh, XBT_NULL, libxl__sprintf(gc,
@@ -1942,15 +1957,13 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
         char tmpname[] = "/tmp/vncautopass.XXXXXX";
         autopass_fd = mkstemp(tmpname);
         if ( autopass_fd < 0 ) {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                             "mkstemp %s failed", tmpname);
+            LOGE(ERROR, "mkstemp %s failed", tmpname);
             goto x_fail;
         }
 
         if ( unlink(tmpname) ) {
             /* should never happen */
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                             "unlink %s failed", tmpname);
+            LOGE(ERROR, "unlink %s failed", tmpname);
             goto x_fail;
         }
 
@@ -1959,8 +1972,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
             goto x_fail;
 
         if ( lseek(autopass_fd, SEEK_SET, 0) ) {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                             "rewind %s (autopass) failed", tmpname);
+            LOGE(ERROR, "rewind %s (autopass) failed", tmpname);
             goto x_fail;
         }
 
@@ -2353,13 +2365,12 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
                                    libxl_device_disk *disk,
                                    libxl__device *device)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     int devid;
 
     devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
     if (devid==-1) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-               " virtual disk identifier %s", disk->vdev);
+        LOG(ERROR, "Invalid or unsupported"" virtual disk identifier %s",
+            disk->vdev);
         return ERROR_INVAL;
     }
 
@@ -2377,8 +2388,7 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
             device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
             break;
         default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                       "unrecognized disk backend type: %d", disk->backend);
+            LOG(ERROR, "unrecognized disk backend type: %d", disk->backend);
             return ERROR_INVAL;
     }
 
@@ -2471,8 +2481,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         GCNEW(device);
         rc = libxl__device_from_disk(gc, domid, disk, device);
         if (rc != 0) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-                   " virtual disk identifier %s", disk->vdev);
+            LOG(ERROR, "Invalid or unsupported"" virtual disk identifier %s",
+                disk->vdev);
             goto out;
         }
 
@@ -2544,9 +2554,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
                 assert(device->backend_kind == LIBXL__DEVICE_KIND_QDISK);
                 break;
             default:
-                LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                           "unrecognized disk backend type: %d",
-                           disk->backend);
+                LOG(ERROR, "unrecognized disk backend type: %d",
+                    disk->backend);
                 rc = ERROR_INVAL;
                 goto out;
         }
@@ -2805,7 +2814,7 @@ libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *n
     return disks;
 
 out_err:
-    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list disks");
+    LOG(ERROR, "Unable to list disks");
     while (disks && *num) {
         (*num)--;
         libxl_device_disk_dispose(&disks[*num]);
@@ -2909,7 +2918,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
         }
     }
     if (i == num) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual device not found");
+        LOG(ERROR, "Virtual device not found");
         rc = ERROR_FAIL;
         goto out;
     }
@@ -2968,8 +2977,8 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
         tmp = libxl__xs_read(gc, t, libxl__sprintf(gc, "%s/frontend", path));
         if (!tmp)
         {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
-                       libxl__sprintf(gc, "%s/frontend", path));
+            LOG(ERROR, "Internal error: %s does not exist",
+                libxl__sprintf(gc, "%s/frontend", path));
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3000,8 +3009,8 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
         tmp = libxl__xs_read(gc, t, libxl__sprintf(gc, "%s/frontend", path));
         if (!tmp)
         {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
-                       libxl__sprintf(gc, "%s/frontend", path));
+            LOG(ERROR, "Internal error: %s does not exist",
+                libxl__sprintf(gc, "%s/frontend", path));
             rc = ERROR_FAIL;
             goto out;
         }
@@ -3572,7 +3581,7 @@ libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num
     return nics;
 
 out_err:
-    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list nics");
+    LOG(ERROR, "Unable to list nics");
     while (*num) {
         (*num)--;
         libxl_device_nic_dispose(&nics[*num]);
@@ -4604,27 +4613,24 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb)
 
     mem = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/memory/target", dompath));
     if (!mem) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "cannot get memory info from %s/memory/target",
-                         dompath);
+        LOGE(ERROR, "cannot get memory info from %s/memory/target", dompath);
         goto out;
     }
     memorykb = strtoul(mem, &endptr, 10);
     if (*endptr != '\0') {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "invalid memory %s from %s/memory/target\n", mem, dompath);
+        LOGE(ERROR, "invalid memory %s from %s/memory/target\n", mem, dompath);
         goto out;
     }
 
     if (max_memkb < memorykb) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "memory_static_max must be greater than or or equal to memory_dynamic_max");
+        LOGE(ERROR,
+             "memory_static_max must be greater than or or equal to memory_dynamic_max");
         goto out;
     }
     rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + LIBXL_MAXMEM_CONSTANT);
     if (rc != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                "xc_domain_setmaxmem domid=%d memkb=%d failed "
-                "rc=%d\n", domid, max_memkb + LIBXL_MAXMEM_CONSTANT, rc);
+        LOGE(ERROR, "xc_domain_setmaxmem domid=%d memkb=%d failed ""rc=%d\n",
+             domid, max_memkb + LIBXL_MAXMEM_CONSTANT, rc);
         goto out;
     }
 
@@ -4663,8 +4669,8 @@ retry_transaction:
     if (target) {
         *target_memkb = strtoul(target, &endptr, 10);
         if (*endptr != '\0') {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                    "invalid memory target %s from %s\n", target, target_path);
+            LOGE(ERROR, "invalid memory target %s from %s\n", target,
+                 target_path);
             rc = ERROR_FAIL;
             goto out;
         }
@@ -4673,9 +4679,8 @@ retry_transaction:
     if (staticmax) {
         *max_memkb = strtoul(staticmax, &endptr, 10);
         if (*endptr != '\0') {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                             "invalid memory static-max %s from %s\n",
-                             staticmax, max_path);
+            LOGE(ERROR, "invalid memory static-max %s from %s\n", staticmax,
+                 max_path);
             rc = ERROR_FAIL;
             goto out;
         }
@@ -4755,17 +4760,15 @@ retry_transaction:
             goto out_no_transaction;
         goto retry_transaction;
     } else if (!target) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "cannot get target memory info from %s/memory/target",
-                         dompath);
+        LOGE(ERROR, "cannot get target memory info from %s/memory/target",
+             dompath);
         abort_transaction = 1;
         goto out;
     } else {
         current_target_memkb = strtoul(target, &endptr, 10);
         if (*endptr != '\0') {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                    "invalid memory target %s from %s/memory/target\n",
-                    target, dompath);
+            LOGE(ERROR, "invalid memory target %s from %s/memory/target\n",
+                 target, dompath);
             abort_transaction = 1;
             goto out;
         }
@@ -4773,17 +4776,15 @@ retry_transaction:
     memmax = libxl__xs_read(gc, t, libxl__sprintf(gc,
                 "%s/memory/static-max", dompath));
     if (!memmax) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "cannot get memory info from %s/memory/static-max",
-                         dompath);
+        LOGE(ERROR, "cannot get memory info from %s/memory/static-max",
+             dompath);
         abort_transaction = 1;
         goto out;
     }
     memorykb = strtoul(memmax, &endptr, 10);
     if (*endptr != '\0') {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                "invalid max memory %s from %s/memory/static-max\n",
-                memmax, dompath);
+        LOGE(ERROR, "invalid max memory %s from %s/memory/static-max\n",
+             memmax, dompath);
         abort_transaction = 1;
         goto out;
     }
@@ -4800,17 +4801,15 @@ retry_transaction:
     } else
         new_target_memkb = target_memkb - videoram;
     if (new_target_memkb > memorykb) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                "memory_dynamic_max must be less than or equal to"
-                " memory_static_max\n");
+        LOG(ERROR,
+            "memory_dynamic_max must be less than or equal to"" memory_static_max\n");
         abort_transaction = 1;
         goto out;
     }
 
     if (!domid && new_target_memkb < LIBXL_MIN_DOM0_MEM) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                   "new target %d for dom0 is below the minimum threshold",
-                   new_target_memkb);
+        LOG(ERROR, "new target %d for dom0 is below the minimum threshold",
+            new_target_memkb);
         abort_transaction = 1;
         goto out;
     }
@@ -4820,9 +4819,11 @@ retry_transaction:
         rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb +
                 LIBXL_MAXMEM_CONSTANT);
         if (rc != 0) {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                    "xc_domain_setmaxmem domid=%u memkb=%"PRIu64" failed "
-                    "rc=%d\n", domid, memorykb + LIBXL_MAXMEM_CONSTANT, rc);
+            LOGE(ERROR,
+                 "xc_domain_setmaxmem domid=%u memkb=%"PRIu64" failed ""rc=%d\n",
+                 domid,
+                 memorykb + LIBXL_MAXMEM_CONSTANT,
+                 rc);
             abort_transaction = 1;
             goto out;
         }
@@ -4831,10 +4832,11 @@ retry_transaction:
     rc = xc_domain_set_pod_target(ctx->xch, domid,
             new_target_memkb / 4, NULL, NULL, NULL);
     if (rc != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                "xc_domain_set_pod_target domid=%d, memkb=%d "
-                "failed rc=%d\n", domid, new_target_memkb / 4,
-                rc);
+        LOGE(ERROR,
+             "xc_domain_set_pod_target domid=%d, memkb=%d ""failed rc=%d\n",
+             domid,
+             new_target_memkb / 4,
+             rc);
         abort_transaction = 1;
         goto out;
     }
@@ -4889,28 +4891,27 @@ static int libxl__get_memory_target(libxl__gc *gc, uint32_t domid,
         if (rc < 0)
             goto out;
     } else if (!target) {
-        LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
-                         "cannot get target memory info from %s/memory/target",
-                         dompath);
+        LOGE(ERROR, "cannot get target memory info from %s/memory/target",
+             dompath);
         goto out;
     } else if (!static_max) {
-        LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
-                "cannot get target memory info from %s/memory/static-max",
-                dompath);
+        LOGE(ERROR,
+             "cannot get target memory info from %s/memory/static-max",
+             dompath);
         goto out;
     } else {
         target_memkb = strtoul(target, &endptr, 10);
         if (*endptr != '\0') {
-            LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
-                    "invalid memory target %s from %s/memory/target\n",
-                    target, dompath);
+            LOGE(ERROR, "invalid memory target %s from %s/memory/target\n",
+                 target, dompath);
             goto out;
         }
         max_memkb = strtoul(static_max, &endptr, 10);
         if (*endptr != '\0') {
-            LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
-                    "invalid memory target %s from %s/memory/static-max\n",
-                    static_max, dompath);
+            LOGE(ERROR,
+                 "invalid memory target %s from %s/memory/static-max\n",
+                 static_max,
+                 dompath);
             goto out;
         }
 
@@ -5067,10 +5068,12 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     xc_physinfo_t xcphysinfo = { 0 };
     int rc;
     long l;
+    GC_INIT(ctx);
 
     rc = xc_physinfo(ctx->xch, &xcphysinfo);
     if (rc != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting physinfo");
+        LOGE(ERROR, "getting physinfo");
+        GC_FREE;
         return ERROR_FAIL;
     }
     physinfo->threads_per_core = xcphysinfo.threads_per_core;
@@ -5086,8 +5089,8 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     if (l < 0 && errno == ENOSYS) {
         l = 0;
     } else if (l < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, l,
-                            "getting sharing freed pages");
+        LOGEV(ERROR, l, "getting sharing freed pages");
+        GC_FREE;
         return ERROR_FAIL;
     }
     physinfo->sharing_freed_pages = l;
@@ -5095,8 +5098,8 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     if (l < 0 && errno == ENOSYS) {
         l = 0;
     } else if (l < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, l,
-                            "getting sharing used frames");
+        LOGEV(ERROR, l, "getting sharing used frames");
+        GC_FREE;
         return ERROR_FAIL;
     }
     physinfo->sharing_used_frames = l;
@@ -5107,6 +5110,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     physinfo->cap_hvm_directio =
         !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm_directio);
 
+    GC_FREE;
     return 0;
 }
 
@@ -5447,20 +5451,26 @@ int libxl_set_vcpuaffinity_all(libxl_ctx *ctx, uint32_t domid,
 int libxl_domain_set_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
                                   libxl_bitmap *nodemap)
 {
+    GC_INIT(ctx);
     if (xc_domain_node_setaffinity(ctx->xch, domid, nodemap->map)) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "setting node affinity");
+        LOGE(ERROR, "setting node affinity");
+        GC_FREE;
         return ERROR_FAIL;
     }
+    GC_FREE;
     return 0;
 }
 
 int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
                                   libxl_bitmap *nodemap)
 {
+    GC_INIT(ctx);
     if (xc_domain_node_getaffinity(ctx->xch, domid, nodemap->map)) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting node affinity");
+        LOGE(ERROR, "getting node affinity");
+        GC_FREE;
         return ERROR_FAIL;
     }
+    GC_FREE;
     return 0;
 }
 
@@ -5560,11 +5570,13 @@ out:
 libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx)
 {
     libxl_scheduler sched, ret;
-
+    GC_INIT(ctx);
     if ((ret = xc_sched_id(ctx->xch, (int *)&sched)) != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list");
+        LOGE(ERROR, "getting domain info list");
         return ERROR_FAIL;
+        GC_FREE;
     }
+    GC_FREE;
     return sched;
 }
 
@@ -5651,16 +5663,19 @@ int libxl_sched_credit_params_get(libxl_ctx *ctx, uint32_t poolid,
 {
     struct xen_sysctl_credit_schedule sparam;
     int rc;
+    GC_INIT(ctx);
 
     rc = xc_sched_credit_params_get(ctx->xch, poolid, &sparam);
     if (rc != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting sched credit param");
+        LOGE(ERROR, "getting sched credit param");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
     scinfo->tslice_ms = sparam.tslice_ms;
     scinfo->ratelimit_us = sparam.ratelimit_us;
 
+    GC_FREE;
     return 0;
 }
 
@@ -5669,26 +5684,25 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
 {
     struct xen_sysctl_credit_schedule sparam;
     int rc=0;
+    GC_INIT(ctx);
 
     if (scinfo->tslice_ms <  XEN_SYSCTL_CSCHED_TSLICE_MIN
         || scinfo->tslice_ms > XEN_SYSCTL_CSCHED_TSLICE_MAX) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-            "Time slice out of range, valid range is from %d to %d",
-                            XEN_SYSCTL_CSCHED_TSLICE_MIN,
-                            XEN_SYSCTL_CSCHED_TSLICE_MAX);
+        LOG(ERROR, "Time slice out of range, valid range is from %d to %d",
+            XEN_SYSCTL_CSCHED_TSLICE_MIN, XEN_SYSCTL_CSCHED_TSLICE_MAX);
+        GC_FREE;
         return ERROR_INVAL;
     }
     if (scinfo->ratelimit_us <  XEN_SYSCTL_SCHED_RATELIMIT_MIN
         || scinfo->ratelimit_us > XEN_SYSCTL_SCHED_RATELIMIT_MAX) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-            "Ratelimit out of range, valid range is from %d to %d",
-                            XEN_SYSCTL_SCHED_RATELIMIT_MIN,
-                            XEN_SYSCTL_SCHED_RATELIMIT_MAX);
+        LOG(ERROR, "Ratelimit out of range, valid range is from %d to %d",
+            XEN_SYSCTL_SCHED_RATELIMIT_MIN, XEN_SYSCTL_SCHED_RATELIMIT_MAX);
+        GC_FREE;
         return ERROR_INVAL;
     }
     if (scinfo->ratelimit_us > scinfo->tslice_ms*1000) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                   "Ratelimit cannot be greater than timeslice");
+        LOG(ERROR, "Ratelimit cannot be greater than timeslice");
+        GC_FREE;
         return ERROR_INVAL;
     }
 
@@ -5697,13 +5711,15 @@ int libxl_sched_credit_params_set(libxl_ctx *ctx, uint32_t poolid,
 
     rc = xc_sched_credit_params_set(ctx->xch, poolid, &sparam);
     if ( rc < 0 ) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "setting sched credit param");
+        LOGE(ERROR, "setting sched credit param");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
     scinfo->tslice_ms = sparam.tslice_ms;
     scinfo->ratelimit_us = sparam.ratelimit_us;
 
+    GC_FREE;
     return 0;
 }
 
@@ -5956,9 +5972,8 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,
     }
 
     if (rc != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "Send trigger '%s' failed",
-                         libxl_trigger_to_string(trigger));
+        LOGE(ERROR, "Send trigger '%s' failed",
+             libxl_trigger_to_string(trigger));
         rc = ERROR_FAIL;
     }
 
@@ -5980,11 +5995,14 @@ int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq)
 int libxl_send_debug_keys(libxl_ctx *ctx, char *keys)
 {
     int ret;
+    GC_INIT(ctx);
     ret = xc_send_debug_keys(ctx->xch, keys);
     if ( ret < 0 ) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "sending debug keys");
+        LOGE(ERROR, "sending debug keys");
+        GC_FREE;
         return ERROR_FAIL;
     }
+    GC_FREE;
     return 0;
 }
 
@@ -6019,12 +6037,14 @@ int libxl_xen_console_read_line(libxl_ctx *ctx,
                                 char **line_r)
 {
     int ret;
+    GC_INIT(ctx);
 
     memset(cr->buffer, 0, cr->size);
     ret = xc_readconsolering(ctx->xch, cr->buffer, &cr->count,
                              cr->clear, cr->incremental, &cr->index);
     if (ret < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "reading console ring buffer");
+        LOGE(ERROR, "reading console ring buffer");
+        GC_FREE;
         return ERROR_FAIL;
     }
     if (!ret) {
@@ -6037,6 +6057,7 @@ int libxl_xen_console_read_line(libxl_ctx *ctx,
         }
     }
 
+    GC_FREE;
     return ret;
 }
 
@@ -6059,8 +6080,7 @@ uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid)
     start_time = libxl__xs_read(
         gc, XBT_NULL, libxl__sprintf(gc, "%s/start_time", vm_path));
     if (start_time == NULL) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, -1,
-                        "Can't get start time of domain '%d'", domid);
+        LOGEV(ERROR, -1, "Can't get start time of domain '%d'", domid);
         ret = -1;
     }else{
         ret = strtoul(start_time, NULL, 10);
@@ -6073,45 +6093,51 @@ char *libxl_tmem_list(libxl_ctx *ctx, uint32_t domid, int use_long)
 {
     int rc;
     char _buf[32768];
+    GC_INIT(ctx);
 
     rc = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_LIST, domid, 32768, use_long,
                          _buf);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not get tmem list");
+        LOGEV(ERROR, rc, "Can not get tmem list");
+        GC_FREE;
         return NULL;
     }
 
+    GC_FREE;
     return strdup(_buf);
 }
 
 int libxl_tmem_freeze(libxl_ctx *ctx, uint32_t domid)
 {
     int rc;
+    GC_INIT(ctx);
 
     rc = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_FREEZE, domid, 0, 0,
                          NULL);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not freeze tmem pools");
+        LOGEV(ERROR, rc, "Can not freeze tmem pools");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return rc;
 }
 
 int libxl_tmem_thaw(libxl_ctx *ctx, uint32_t domid)
 {
     int rc;
+    GC_INIT(ctx);
 
     rc = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_THAW, domid, 0, 0,
                          NULL);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not thaw tmem pools");
+        LOGEV(ERROR, rc, "Can not thaw tmem pools");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return rc;
 }
 
@@ -6131,19 +6157,21 @@ int libxl_tmem_set(libxl_ctx *ctx, uint32_t domid, char* name, uint32_t set)
 {
     int rc;
     int32_t subop = tmem_setop_from_string(name);
+    GC_INIT(ctx);
 
     if (subop == -1) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, -1,
-            "Invalid set, valid sets are <weight|cap|compress>");
+        LOGEV(ERROR, -1, "Invalid set, valid sets are <weight|cap|compress>");
+        GC_FREE;
         return ERROR_INVAL;
     }
     rc = xc_tmem_control(ctx->xch, -1, subop, domid, set, 0, NULL);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not set tmem %s", name);
+        LOGEV(ERROR, rc, "Can not set tmem %s", name);
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return rc;
 }
 
@@ -6151,28 +6179,32 @@ int libxl_tmem_shared_auth(libxl_ctx *ctx, uint32_t domid,
                            char* uuid, int auth)
 {
     int rc;
+    GC_INIT(ctx);
 
     rc = xc_tmem_auth(ctx->xch, domid, uuid, auth);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not set tmem shared auth");
+        LOGEV(ERROR, rc, "Can not set tmem shared auth");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return rc;
 }
 
 int libxl_tmem_freeable(libxl_ctx *ctx)
 {
     int rc;
+    GC_INIT(ctx);
 
     rc = xc_tmem_control(ctx->xch, -1, XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB, -1, 0, 0, 0);
     if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Can not get tmem freeable memory");
+        LOGEV(ERROR, rc, "Can not get tmem freeable memory");
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return rc;
 }
 
@@ -6212,8 +6244,7 @@ int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
 
     rc = xc_cpupool_create(ctx->xch, poolid, sched);
     if (rc) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-           "Could not create cpupool");
+        LOGEV(ERROR, rc, "Could not create cpupool");
         GC_FREE;
         return ERROR_FAIL;
     }
@@ -6222,8 +6253,7 @@ int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
         if (libxl_bitmap_test(&cpumap, i)) {
             rc = xc_cpupool_addcpu(ctx->xch, *poolid, i);
             if (rc) {
-                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-                    "Error moving cpu to cpupool");
+                LOGEV(ERROR, rc, "Error moving cpu to cpupool");
                 libxl_cpupool_destroy(ctx, *poolid);
                 GC_FREE;
                 return ERROR_FAIL;
@@ -6275,8 +6305,7 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid)
         if (libxl_bitmap_test(&cpumap, i)) {
             rc = xc_cpupool_removecpu(ctx->xch, poolid, i);
             if (rc) {
-                LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-                    "Error removing cpu from cpupool");
+                LOGEV(ERROR, rc, "Error removing cpu from cpupool");
                 rc = ERROR_FAIL;
                 goto out1;
             }
@@ -6284,7 +6313,7 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid)
 
     rc = xc_cpupool_destroy(ctx->xch, poolid);
     if (rc) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "Could not destroy cpupool");
+        LOGEV(ERROR, rc, "Could not destroy cpupool");
         rc = ERROR_FAIL;
         goto out1;
     }
@@ -6494,8 +6523,7 @@ int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
 
     rc = xc_cpupool_movedomain(ctx->xch, poolid, domid);
     if (rc) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc,
-            "Error moving domain to cpupool");
+        LOGEV(ERROR, rc, "Error moving domain to cpupool");
         GC_FREE;
         return ERROR_FAIL;
     }
@@ -6509,10 +6537,12 @@ static int fd_set_flags(libxl_ctx *ctx, int fd,
                         int flagmask, int set_p)
 {
     int flags, r;
+    GC_INIT(ctx);
 
     flags = fcntl(fd, fcntlgetop);
     if (flags == -1) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "fcntl(,F_GET%s) failed",fl);
+        LOGE(ERROR, "fcntl(,F_GET%s) failed", fl);
+        GC_FREE;
         return ERROR_FAIL;
     }
 
@@ -6523,10 +6553,12 @@ static int fd_set_flags(libxl_ctx *ctx, int fd,
 
     r = fcntl(fd, fcntlsetop, flags);
     if (r == -1) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "fcntl(,F_SET%s) failed",fl);
+        LOGE(ERROR, "fcntl(,F_SET%s) failed", fl);
+        GC_FREE;
         return ERROR_FAIL;
     }
 
+    GC_FREE;
     return 0;
 }
 
tools/libxl/libxl_create.c +14 -23
index bf2099b..30380ec 100644
@@ -102,7 +102,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
                     b_info->device_model_version =
                         LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
                 } else {
-                    LIBXL__LOG_ERRNO(CTX, XTL_ERROR, "qemu-xen access error");
+                    LOGE(ERROR, "qemu-xen access error");
                     return ERROR_FAIL;
                 }
             }
@@ -148,7 +148,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         b_info->device_model_version !=
             LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL &&
         libxl_defbool_val(b_info->device_model_stubdomain)) {
-        LIBXL__LOG(CTX, XTL_ERROR,
+        LOG(ERROR,
             "device model stubdomains require \"qemu-xen-traditional\"");
         return ERROR_INVAL;
     }
@@ -374,9 +374,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         }
         break;
     default:
-        LIBXL__LOG(CTX, LIBXL__LOG_ERROR,
-                   "invalid domain type %s in create info",
-                   libxl_domain_type_to_string(b_info->type));
+        LOG(ERROR, "invalid domain type %s in create info",
+            libxl_domain_type_to_string(b_info->type));
         return ERROR_INVAL;
     }
     return 0;
@@ -522,7 +521,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
 
     ret = libxl__arch_domain_prepare_config(gc, d_config, xc_config);
     if (ret < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "fail to get domain config");
+        LOGE(ERROR, "fail to get domain config");
         rc = ERROR_FAIL;
         goto out;
     }
@@ -533,8 +532,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
                                       handle, flags, domid,
                                       xc_config);
         if (ret < 0) {
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                             "domain creation fail");
+            LOGE(ERROR, "domain creation fail");
             rc = ERROR_FAIL;
             goto out;
         }
@@ -546,7 +544,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
 
     ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid);
     if (ret < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "domain move fail");
+        LOGE(ERROR, "domain move fail");
         rc = ERROR_FAIL;
         goto out;
     }
@@ -559,7 +557,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config *d_config,
 
     vm_path = libxl__sprintf(gc, "/vm/%s", uuid_string);
     if (!vm_path) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot allocate create paths");
+        LOG(ERROR, "cannot allocate create paths");
         rc = ERROR_FAIL;
         goto out;
     }
@@ -661,8 +659,7 @@ retry_transaction:
             t = 0;
             goto retry_transaction;
         }
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "domain creation "
-                         "xenstore transaction commit failed");
+        LOGE(ERROR, "domain creation ""xenstore transaction commit failed");
         rc = ERROR_FAIL;
         goto out;
     }
@@ -878,7 +875,7 @@ static void initiate_domain_create(libxl__egc *egc,
 
     ret = libxl__domain_make(gc, d_config, &domid, &state->config);
     if (ret) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot make domain: %d", ret);
+        LOG(ERROR, "cannot make domain: %d", ret);
         dcs->guest_domid = domid;
         ret = ERROR_FAIL;
         goto error_out;
@@ -1141,10 +1138,9 @@ static void domcreate_rebuild_done(libxl__egc *egc,
     /* convenience aliases */
     const uint32_t domid = dcs->guest_domid;
     libxl_domain_config *const d_config = dcs->guest_config;
-    libxl_ctx *const ctx = CTX;
 
     if (ret) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot (re-)build domain: %d", ret);
+        LOG(ERROR, "cannot (re-)build domain: %d", ret);
         ret = ERROR_FAIL;
         goto error_out;
     }
@@ -1335,15 +1331,13 @@ static void domcreate_devmodel_started(libxl__egc *egc,
 {
     libxl__domain_create_state *dcs = CONTAINER_OF(dmss, *dcs, dmss.dm);
     STATE_AO_GC(dmss->spawn.ao);
-    libxl_ctx *ctx = CTX;
     int domid = dcs->guest_domid;
 
     /* convenience aliases */
     libxl_domain_config *const d_config = dcs->guest_config;
 
     if (ret) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                   "device model did not start: %d", ret);
+        LOG(ERROR, "device model did not start: %d", ret);
         goto error_out;
     }
 
@@ -1411,7 +1405,6 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev,
     libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev);
     STATE_AO_GC(dcs->ao);
     int i;
-    libxl_ctx *ctx = CTX;
     int domid = dcs->guest_domid;
 
     /* convenience aliases */
@@ -1425,8 +1418,7 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev,
     for (i = 0; i < d_config->num_pcidevs; i++) {
         ret = libxl__device_pci_add(gc, domid, &d_config->pcidevs[i], 1);
         if (ret < 0) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                       "libxl_device_pci_add failed: %d", ret);
+            LOG(ERROR, "libxl_device_pci_add failed: %d", ret);
             goto error_out;
         }
     }
@@ -1435,8 +1427,7 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev,
         ret = libxl__create_pci_backend(gc, domid, d_config->pcidevs,
             d_config->num_pcidevs);
         if (ret < 0) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                "libxl_create_pci_backend failed: %d", ret);
+            LOG(ERROR, "libxl_create_pci_backend failed: %d", ret);
             goto error_out;
         }
     }
tools/libxl/libxl_dm.c +21 -29

133 lines not on this page · raw message

tools/libxl/libxl_dom.c +7 -10
index b514377..b26ce57 100644
@@ -216,8 +216,8 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
 
     libxl_for_each_set_bit(v, info->u.hvm.viridian_enable) {
         if (libxl_bitmap_test(&info->u.hvm.viridian_disable, v)) {
-            LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "%s group both enabled and disabled",
-                       libxl_viridian_enlightenment_to_string(v));
+            LOG(ERROR, "%s group both enabled and disabled",
+                libxl_viridian_enlightenment_to_string(v));
             goto err;
         }
         if (libxl_viridian_enlightenment_to_string(v)) /* check validity */
@@ -231,7 +231,7 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     /* The base set is a pre-requisite for all others */
     if (!libxl_bitmap_is_empty(&enlightenments) &&
         !libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_BASE)) {
-        LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "base group not enabled");
+        LOG(ERROR, "base group not enabled");
         goto err;
     }
 
@@ -256,9 +256,7 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
                          domid,
                          HVM_PARAM_VIRIDIAN,
                          mask) != 0) {
-        LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR,
-                         "Couldn't set viridian feature mask (0x%"PRIx64")",
-                         mask);
+        LOGE(ERROR, "Couldn't set viridian feature mask (0x%"PRIx64")", mask);
         goto err;
     }
 
@@ -404,7 +402,7 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
 
     if (xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb +
         LIBXL_MAXMEM_CONSTANT) < 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't set max memory");
+        LOGE(ERROR, "Couldn't set max memory");
         return ERROR_FAIL;
     }
 
@@ -1992,8 +1990,7 @@ err:
     }
 
     if (rc)
-        LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR, "cannot write/rename %s for %s",
-                 newfilename, filename);
+        LOGE(ERROR, "cannot write/rename %s for %s", newfilename, filename);
 out:
     return rc;
 }
@@ -2045,7 +2042,7 @@ int libxl__userdata_retrieve(libxl__gc *gc, uint32_t domid,
         goto out;
     }
     if (!e && !datalen) {
-        LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "userdata file %s is empty", filename);
+        LOG(ERROR, "userdata file %s is empty", filename);
         if (data_r) assert(!*data_r);
         rc = ERROR_FAIL;
         goto out;
tools/libxl/libxl_event.c +22 -26

131 lines not on this page · raw message

tools/libxl/libxl_exec.c +2 -3
index ecb30cf..df4aead 100644
@@ -168,7 +168,6 @@ int libxl__xenstore_child_wait_deprecated(libxl__gc *gc,
                                                        void *userdata),
                                  void *check_callback_userdata)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     char *p;
     unsigned int len;
     int rc = 0;
@@ -181,7 +180,7 @@ int libxl__xenstore_child_wait_deprecated(libxl__gc *gc,
 
     xsh = xs_daemon_open();
     if (xsh == NULL) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to open xenstore connection");
+        LOG(ERROR, "Unable to open xenstore connection");
         goto err;
     }
 
@@ -224,7 +223,7 @@ again:
             }
         }
     }
-    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "%s not ready", what);
+    LOG(ERROR, "%s not ready", what);
 
     xs_unwatch(xsh, path, path);
     xs_daemon_close(xsh);
tools/libxl/libxl_internal.c +8 -9
index 366ea05..c69d6f9 100644
@@ -336,27 +336,28 @@ _hidden int libxl__mac_is_default(libxl_mac *mac)
 
 _hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock)
 {
+    GC_INIT(ctx);
     pthread_mutexattr_t attr;
     int rc = 0;
 
     if (pthread_mutexattr_init(&attr) != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "Failed to init mutex attributes");
-        return ERROR_FAIL;
+        LOGE(ERROR, "Failed to init mutex attributes");
+        rc = ERROR_FAIL;
+        goto out;
     }
     if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
-                         "Failed to set mutex attributes");
+        LOGE(ERROR, "Failed to set mutex attributes");
         rc = ERROR_FAIL;
         goto out;
     }
     if (pthread_mutex_init(lock, &attr) != 0) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Failed to init mutex");
+        LOGE(ERROR, "Failed to init mutex");
         rc = ERROR_FAIL;
         goto out;
     }
 out:
     pthread_mutexattr_destroy(&attr);
+    GC_FREE;
     return rc;
 }
 
@@ -374,9 +375,7 @@ int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid)
     }
 
     if (libxl_device_model_version_from_string(dm_version, &value) < 0) {
-        libxl_ctx *ctx = libxl__gc_owner(gc);
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                   "fatal: %s contain a wrong value (%s)", path, dm_version);
+        LOG(ERROR, "fatal: %s contain a wrong value (%s)", path, dm_version);
         return -1;
     }
     return value;
tools/libxl/libxl_pci.c +71 -87

511 lines not on this page · raw message

tools/libxl/libxl_utils.c +8 -9
index 408ec85..2eba584 100644
@@ -402,28 +402,27 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
                            constdata void *data, ssize_t sz,              \
                            const char *source, const char *what) {        \
       ssize_t got;                                                        \
+      GC_INIT(ctx);                                                       \
                                                                           \
       while (sz > 0) {                                                    \
           got = rw(fd, data, sz);                                         \
           if (got == -1) {                                                \
               if (errno == EINTR) continue;                               \
-              if (!ctx) return errno;                                     \
-              LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to " #rw " %s%s%s", \
-                           what?what:"", what?" from ":"", source);       \
+              if (!ctx) { GC_FREE; return errno; }                        \
+              LOGE(ERROR, "failed to "#rw" %s%s%s", what ? what : "", what ? " from " : "", source);       \
+              GC_FREE;                                                    \
               return errno;                                               \
           }                                                               \
           if (got == 0) {                                                 \
-              if (!ctx) return EPROTO;                                    \
-              LIBXL__LOG(ctx, LIBXL__LOG_ERROR,                                   \
-                     zero_is_eof                                          \
-                     ? "file/stream truncated reading %s%s%s"             \
-                     : "file/stream write returned 0! writing %s%s%s",    \
-                     what?what:"", what?" from ":"", source);             \
+              if (!ctx) { GC_FREE; return  EPROTO; }                      \
+              LOG(ERROR, zero_is_eof ? "file/stream truncated reading %s%s%s" : "file/stream write returned 0! writing %s%s%s", what ? what : "", what ? " from " : "", source);             \
+              GC_FREE;                                                    \
               return EPROTO;                                              \
           }                                                               \
           sz -= got;                                                      \
           data = (char*)data + got;                                       \
       }                                                                   \
+      GC_FREE;                                                            \
       return 0;                                                           \
   }
 
tools/libxl/libxl_x86.c +8 -10
index 896f34c..a3e50df 100644
@@ -30,7 +30,7 @@ static const char *e820_names(int type)
     return "Unknown";
 }
 
-static int e820_sanitize(libxl_ctx *ctx, struct e820entry src[],
+static int e820_sanitize(libxl__gc *gc, struct e820entry src[],
                          uint32_t *nr_entries,
                          unsigned long map_limitkb,
                          unsigned long balloon_kb)
@@ -91,7 +91,7 @@ static int e820_sanitize(libxl_ctx *ctx, struct e820entry src[],
     ram_end = e820[idx].addr + e820[idx].size;
     idx ++;
 
-    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Memory: %"PRIu64"kB End of RAM: " \
+    LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "Memory: %"PRIu64"kB End of RAM: " \
                "0x%"PRIx64" (PFN) Delta: %"PRIu64"kB, PCI start: %"PRIu64"kB " \
                "(0x%"PRIx64" PFN), Balloon %"PRIu64"kB\n", (uint64_t)map_limitkb,
                ram_end >> 12, delta_kb, start_kb ,start >> 12,
@@ -150,7 +150,7 @@ static int e820_sanitize(libxl_ctx *ctx, struct e820entry src[],
             if (src[i].addr + src[i].size != end) {
                 /* We messed up somewhere */
                 src[i].type = 0;
-                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Computed E820 wrongly. Continuing on.");
+                LOGE(ERROR, "Computed E820 wrongly. Continuing on.");
             }
         }
         /* Lastly, convert the RAM to UNSUABLE. Look in the Linux kernel
@@ -212,9 +212,8 @@ static int e820_sanitize(libxl_ctx *ctx, struct e820entry src[],
     nr = idx;
 
     for (i = 0; i < nr; i++) {
-      LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, ":\t[%"PRIx64" -> %"PRIx64"] %s",
-                 e820[i].addr >> 12, (e820[i].addr + e820[i].size) >> 12,
-                 e820_names(e820[i].type));
+      LOG(DEBUG, ":\t[%"PRIx64" -> %"PRIx64"] %s", e820[i].addr >> 12,
+          (e820[i].addr + e820[i].size) >> 12, e820_names(e820[i].type));
     }
 
     /* Done: copy the sanitized version. */
@@ -236,7 +235,7 @@ static int e820_host_sanitize(libxl__gc *gc,
 
     *nr = rc;
 
-    rc = e820_sanitize(CTX, map, nr, b_info->target_memkb,
+    rc = e820_sanitize(gc, map, nr, b_info->target_memkb,
                        (b_info->max_memkb - b_info->target_memkb) +
                        b_info->u.pv.slack_memkb);
     return rc;
@@ -335,9 +334,8 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
             libxl_defbool_val(d_config->b_info.u.pv.e820_host)) {
         ret = libxl__e820_alloc(gc, domid, d_config);
         if (ret) {
-            LIBXL__LOG_ERRNO(gc->owner, LIBXL__LOG_ERROR,
-                    "Failed while collecting E820 with: %d (errno:%d)\n",
-                    ret, errno);
+            LOGE(ERROR, "Failed while collecting E820 with: %d (errno:%d)\n",
+                 ret, errno);
         }
     }
 
tools/libxl/libxl_xshelp.c +2 -4
index d7eaa66..b0db062 100644
@@ -130,8 +130,7 @@ char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid)
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s = xs_get_domain_path(ctx->xsh, domid);
     if (!s) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to get dompath for %" PRIu32,
-                     domid);
+        LOGE(ERROR, "failed to get dompath for %"PRIu32, domid);
         return NULL;
     }
     libxl__ptr_add(gc, s);
@@ -160,10 +159,9 @@ bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
 
 char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s = libxl__sprintf(gc, "/libxl/%i", domid);
     if (!s)
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot allocate create paths");
+        LOG(ERROR, "cannot allocate create paths");
     return s;
 }
 
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH v2 2/4 libxl: fix long lines and delete extraneous quotes

In reply to Wei Liu
---
 tools/libxl/libxl.c       | 21 +++++++++++++--------
 tools/libxl/libxl_utils.c |  8 ++++++--
 2 files changed, 19 insertions(+), 10 deletions(-)
tools/libxl/libxl.c +13 -8
index 1b754c8..ca725a9 100644
@@ -420,14 +420,14 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
         if (rc == ERROR_INVAL) {
             /* no such domain, good */
         } else if (rc != 0) {
-            LOG(ERROR, "unexpected error""checking for existing domain");
+            LOG(ERROR, "unexpected error checking for existing domain");
             goto x_rc;
         } else if (domid_e == domid) {
             /* domain already has this name, ok (but we do still
              * need the rest of the code as we may need to check
              * old_name, for example). */
         } else {
-            LOG(ERROR, "domain with name \"%s\""" already exists.", new_name);
+            LOG(ERROR, "domain with name \"%s\" already exists.", new_name);
             rc = ERROR_INVAL;
             goto x_rc;
         }
@@ -437,14 +437,15 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
         got_old_name = xs_read(ctx->xsh, trans, name_path, &got_old_len);
         if (!got_old_name) {
             LOGEV(ERROR, errno,
-                  "check old name"" for domain %"PRIu32" allegedly named `%s'",
+                  "check old name for domain %"PRIu32" allegedly named `%s'",
                   domid,
                   old_name);
             goto x_fail;
         }
         if (strcmp(old_name, got_old_name)) {
             LOG(ERROR,
-                "domain %"PRIu32" allegedly named ""`%s' is actually named `%s' - racing ?",
+                "domain %"PRIu32" allegedly named "
+                "`%s' is actually named `%s' - racing ?",
                 domid,
                 old_name,
                 got_old_name);
@@ -456,7 +457,8 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
     if (!xs_write(ctx->xsh, trans, name_path,
                   new_name, strlen(new_name))) {
         LOG(ERROR,
-            "failed to write new name `%s'"" for domain %"PRIu32" previously named `%s'",
+            "failed to write new name `%s'"
+            " for domain %"PRIu32" previously named `%s'",
             new_name,
             domid,
             old_name);
@@ -489,14 +491,16 @@ int libxl__domain_rename(libxl__gc *gc, uint32_t domid,
             trans = our_trans = 0;
             if (errno != EAGAIN) {
                 LOG(ERROR,
-                    "failed to commit new name `%s'"" for domain %"PRIu32" previously named `%s'",
+                    "failed to commit new name `%s'"
+                    " for domain %"PRIu32" previously named `%s'",
                     new_name,
                     domid,
                     old_name);
                 goto x_fail;
             }
             LOG(DEBUG,
-                "need to retry rename transaction"" for domain %"PRIu32" (name_path=\"%s\", new_name=\"%s\")",
+                "need to retry rename transaction"
+                " for domain %"PRIu32" (name_path=\"%s\", new_name=\"%s\")",
                 domid,
                 name_path,
                 new_name);
@@ -4802,7 +4806,8 @@ retry_transaction:
         new_target_memkb = target_memkb - videoram;
     if (new_target_memkb > memorykb) {
         LOG(ERROR,
-            "memory_dynamic_max must be less than or equal to"" memory_static_max\n");
+            "memory_dynamic_max must be less than or equal to"
+            " memory_static_max\n");
         abort_transaction = 1;
         goto out;
     }
tools/libxl/libxl_utils.c +6 -2
index 2eba584..e42422a 100644
@@ -409,13 +409,17 @@ int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
           if (got == -1) {                                                \
               if (errno == EINTR) continue;                               \
               if (!ctx) { GC_FREE; return errno; }                        \
-              LOGE(ERROR, "failed to "#rw" %s%s%s", what ? what : "", what ? " from " : "", source);       \
+              LOGE(ERROR, "failed to "#rw" %s%s%s",                       \
+                   what ? what : "", what ? " from " : "", source);       \
               GC_FREE;                                                    \
               return errno;                                               \
           }                                                               \
           if (got == 0) {                                                 \
               if (!ctx) { GC_FREE; return  EPROTO; }                      \
-              LOG(ERROR, zero_is_eof ? "file/stream truncated reading %s%s%s" : "file/stream write returned 0! writing %s%s%s", what ? what : "", what ? " from " : "", source);             \
+              LOG(ERROR, zero_is_eof                                      \
+                  ? "file/stream truncated reading %s%s%s"                \
+                  : "file/stream write returned 0! writing %s%s%s",       \
+                  what ? what : "", what ? " from " : "", source);        \
               GC_FREE;                                                    \
               return EPROTO;                                              \
           }                                                               \
Signature · 1 line
2.1.4
author
#3 lore raw

PATCH v2 3/4 libxl: map LIBXL__LOG_VERBOSE to XTL_VERBOSE

In reply to Wei Liu

There is code in libxl using XTL_VERBOSE. We should provide a libxl mapping for it.

---
 tools/libxl/libxl_internal.h | 1 +
 1 file changed, 1 insertion(+)
tools/libxl/libxl_internal.h +1 -0
index c2413c2..d035b6d 100644
@@ -1637,6 +1637,7 @@ _hidden const libxl_vnc_info *libxl__dm_vnc(const libxl_domain_config *g_cfg);
 _hidden char *libxl__abs_path(libxl__gc *gc, const char *s, const char *path);
 
 #define LIBXL__LOG_DEBUG   XTL_DEBUG
+#define LIBXL__LOG_VERBOSE XTL_VERBOSE
 #define LIBXL__LOG_INFO    XTL_INFO
 #define LIBXL__LOG_WARNING XTL_WARN
 #define LIBXL__LOG_ERROR   XTL_ERROR
Signature · 1 line
2.1.4
author
#4 lore raw

PATCH v2 4/4 libxl: fix places missed by spatch

In reply to Wei Liu

The spatch provided in previous patch didn't handle all sites that need transformation.

---
 tools/libxl/libxl.c        | 17 ++++++++---------
 tools/libxl/libxl_create.c |  4 ++--
 tools/libxl/libxl_pci.c    | 43 +++++++++++++++++++------------------------
 tools/libxl/libxl_x86.c    | 10 +++++-----
 4 files changed, 34 insertions(+), 40 deletions(-)
tools/libxl/libxl.c +8 -9
index ca725a9..22bbc29 100644
@@ -1221,11 +1221,10 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
         }
         gotend = &domaininfos[rc];
 
-        LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "[evg=%p:%"PRIu32"]"
-                   " nentries=%d rc=%d %ld..%ld",
-                   evg, evg->domid, nentries, rc,
-                   rc>0 ? (long)domaininfos[0].domain : 0,
-                   rc>0 ? (long)domaininfos[rc-1].domain : 0);
+        LOG(DEBUG, "[evg=%p:%"PRIu32"] nentries=%d rc=%d %ld..%ld",
+            evg, evg->domid, nentries, rc,
+            rc>0 ? (long)domaininfos[0].domain : 0,
+            rc>0 ? (long)domaininfos[rc-1].domain : 0);
 
         for (;;) {
             if (!evg) {
@@ -1233,10 +1232,10 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
                 goto all_reported;
             }
 
-            LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "[evg=%p:%"PRIu32"]"
-                       "   got=domaininfos[%d] got->domain=%ld",
-                       evg, evg->domid, (int)(got - domaininfos),
-                       got < gotend ? (long)got->domain : -1L);
+            LOG(DEBUG, "[evg=%p:%"PRIu32"]"
+                "   got=domaininfos[%d] got->domain=%ld",
+                evg, evg->domid, (int)(got - domaininfos),
+                got < gotend ? (long)got->domain : -1L);
 
             if (!rc) {
                 domain_death_occurred(egc, &evg, "empty list");
tools/libxl/libxl_create.c +2 -2
index 30380ec..f0fee00 100644
@@ -97,8 +97,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
             if (rc < 0) {
                 /* qemu-xen unavailable, use qemu-xen-traditional */
                 if (errno == ENOENT) {
-                    LIBXL__LOG_ERRNO(CTX, XTL_VERBOSE, "qemu-xen is unavailable"
-                                     ", use qemu-xen-traditional instead");
+                    LOGE(VERBOSE, "qemu-xen is unavailable"
+                         ", use qemu-xen-traditional instead");
                     b_info->device_model_version =
                         LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL;
                 } else {
tools/libxl/libxl_pci.c +19 -24

103 lines not on this page · raw message

tools/libxl/libxl_x86.c +5 -5
index a3e50df..bedd941 100644
@@ -91,11 +91,11 @@ static int e820_sanitize(libxl__gc *gc, struct e820entry src[],
     ram_end = e820[idx].addr + e820[idx].size;
     idx ++;
 
-    LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "Memory: %"PRIu64"kB End of RAM: " \
-               "0x%"PRIx64" (PFN) Delta: %"PRIu64"kB, PCI start: %"PRIu64"kB " \
-               "(0x%"PRIx64" PFN), Balloon %"PRIu64"kB\n", (uint64_t)map_limitkb,
-               ram_end >> 12, delta_kb, start_kb ,start >> 12,
-               (uint64_t)balloon_kb);
+    LOG(DEBUG, "Memory: %"PRIu64"kB End of RAM: " \
+        "0x%"PRIx64" (PFN) Delta: %"PRIu64"kB, PCI start: %"PRIu64"kB " \
+        "(0x%"PRIx64" PFN), Balloon %"PRIu64"kB\n", (uint64_t)map_limitkb,
+        ram_end >> 12, delta_kb, start_kb ,start >> 12,
+        (uint64_t)balloon_kb);
 
 
     /* This whole code below is to guard against if the Intel IGD is passed into
Signature · 1 line
2.1.4
Applied
#5 lore raw
In reply to Wei Liu
Quoted 5 lines · Wei Liu

There are mixed usage of different logging macros. Ideally we only use one
style to avoid confusion.

Rebased on top of staging.

Applied, thanks.