[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [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); ===== Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- 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(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index e4ea476..1b754c8 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -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; } diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index bf2099b..30380ec 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -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; } } diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 71a1a3e..cf8b535 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -61,7 +61,6 @@ static int libxl__create_qemu_logfile(libxl__gc *gc, char *name) const char *libxl__domain_device_model(libxl__gc *gc, const libxl_domain_build_info *info) { - libxl_ctx *ctx = libxl__gc_owner(gc); const char *dm; if (libxl_defbool_val(info->device_model_stubdomain)) @@ -78,9 +77,8 @@ const char *libxl__domain_device_model(libxl__gc *gc, dm = qemu_xen_path(gc); break; default: - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "invalid device model version %d", - info->device_model_version); + LOG(ERROR, "invalid device model version %d", + info->device_model_version); dm = NULL; break; } @@ -666,20 +664,18 @@ static char *dm_spice_options(libxl__gc *gc, char *opt; if (!spice->port && !spice->tls_port) { - LIBXL__LOG(CTX, LIBXL__LOG_ERROR, - "at least one of the spiceport or tls_port must be provided"); + LOG(ERROR, + "at least one of the spiceport or tls_port must be provided"); return NULL; } if (!libxl_defbool_val(spice->disable_ticketing)) { if (!spice->passwd) { - LIBXL__LOG(CTX, LIBXL__LOG_ERROR, - "spice ticketing is enabled but missing password"); + LOG(ERROR, "spice ticketing is enabled but missing password"); return NULL; } else if (!spice->passwd[0]) { - LIBXL__LOG(CTX, LIBXL__LOG_ERROR, - "spice password can't be empty"); + LOG(ERROR, "spice password can't be empty"); return NULL; } } @@ -731,7 +727,6 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, const libxl__domain_build_state *state, int *dm_state_fd) { - libxl_ctx *ctx = libxl__gc_owner(gc); const libxl_domain_create_info *c_info = &guest_config->c_info; const libxl_domain_build_info *b_info = &guest_config->b_info; const libxl_device_disk *disks = guest_config->disks; @@ -1140,8 +1135,8 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, const char *pdev_path; if (dev_number == -1) { - LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "unable to determine" - " disk number for %s", disks[i].vdev); + LOG(WARN, "unable to determine"" disk number for %s", + disks[i].vdev); continue; } @@ -1156,19 +1151,21 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, disks[i].pdev_path, disk, disks[i].readwrite ? "off" : "on", format, dev_number); } else { if (!disks[i].readwrite) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "qemu-xen doesn't support read-only disk drivers"); + LOG(ERROR, + "qemu-xen doesn't support read-only disk drivers"); return ERROR_INVAL; } if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) { - LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support" - " empty disk format for %s", disks[i].vdev); + LOG(WARN, "cannot support"" empty disk format for %s", + disks[i].vdev); continue; } if (format == NULL) { - LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "unable to determine" - " disk image format %s", disks[i].vdev); + LOG(WARN, + "unable to determine"" disk image format %s", + disks[i].vdev); continue; } @@ -1235,8 +1232,6 @@ static int libxl__build_device_model_args(libxl__gc *gc, /* dm_state_fd may be NULL iff caller knows we are using old stubdom * and therefore will be passing a filename rather than a fd. */ { - libxl_ctx *ctx = libxl__gc_owner(gc); - switch (guest_config->b_info.device_model_version) { case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: return libxl__build_device_model_args_old(gc, dm, @@ -1251,8 +1246,8 @@ static int libxl__build_device_model_args(libxl__gc *gc, args, envs, state, dm_state_fd); default: - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unknown device model version %d", - guest_config->b_info.device_model_version); + LOGE(ERROR, "unknown device model version %d", + guest_config->b_info.device_model_version); return ERROR_INVAL; } } @@ -1479,9 +1474,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) "%d", guest_domid); ret = xc_domain_set_target(ctx->xch, dm_domid, guest_domid); if (ret<0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "setting target domain %d -> %d", - dm_domid, guest_domid); + LOGE(ERROR, "setting target domain %d -> %d", dm_domid, guest_domid); ret = ERROR_FAIL; goto out; } @@ -1740,8 +1733,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) goto out; } if (access(dm, X_OK) < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "device model %s is not executable", dm); + LOGE(ERROR, "device model %s is not executable", dm); rc = ERROR_FAIL; goto out; } @@ -1813,9 +1805,9 @@ retry_transaction: } } - LIBXL__LOG(CTX, XTL_DEBUG, "Spawning device-model %s with arguments:", dm); + LOG(DEBUG, "Spawning device-model %s with arguments:", dm); for (arg = args; *arg; arg++) - LIBXL__LOG(CTX, XTL_DEBUG, " %s", *arg); + LOG(DEBUG, " %s", *arg); if (*envs) { LOG(DEBUG, "Spawning device-model %s with additional environment:", dm); for (arg = envs; *arg; arg += 2) diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index b514377..b26ce57 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -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; diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c index bfb6b31..7d549ad 100644 --- a/tools/libxl/libxl_event.c +++ b/tools/libxl/libxl_event.c @@ -277,7 +277,7 @@ int libxl__gettimeofday(libxl__gc *gc, struct timeval *now_r) { int rc = gettimeofday(now_r, 0); if (rc) { - LIBXL__LOG_ERRNO(CTX, LIBXL__LOG_ERROR, "gettimeofday failed"); + LOGE(ERROR, "gettimeofday failed"); return ERROR_FAIL; } return 0; @@ -523,9 +523,8 @@ static void watchfd_callback(libxl__egc *egc, libxl__ev_fd *ev, uint32_t counterval; int rc = sscanf(token, "%d/%"SCNx32, &slotnum, &counterval); if (rc != 2) { - LIBXL__LOG(CTX, LIBXL__LOG_ERROR, - "watch epath=%s token=%s: failed to parse token", - epath, token); + LOG(ERROR, "watch epath=%s token=%s: failed to parse token", + epath, token); /* oh well */ goto ignore; } @@ -540,9 +539,7 @@ static void watchfd_callback(libxl__egc *egc, libxl__ev_fd *ev, libxl__ev_xswatch *w = libxl__watch_slot_contents(gc, slotnum); if (!w) { - LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, - "watch epath=%s token=%s: empty slot", - epath, token); + LOG(DEBUG, "watch epath=%s token=%s: empty slot", epath, token); goto ignore; } @@ -639,8 +636,7 @@ int libxl__ev_xswatch_register(libxl__gc *gc, libxl__ev_xswatch *w, w, path, token, slotnum); if (!xs_watch(CTX->xsh, path, token)) { - LIBXL__LOG_ERRNOVAL(CTX, LIBXL__LOG_ERROR, errno, - "create watch for path %s", path); + LOGEV(ERROR, errno, "create watch for path %s", path); rc = ERROR_FAIL; goto out_rc; } @@ -679,8 +675,7 @@ void libxl__ev_xswatch_deregister(libxl__gc *gc, libxl__ev_xswatch *w) if (!xs_unwatch(CTX->xsh, w->path, token)) /* Oh well, we will just get watch events forever more * and ignore them. But we should complain to the log. */ - LIBXL__LOG_ERRNOVAL(CTX, LIBXL__LOG_ERROR, errno, - "remove watch for path %s", w->path); + LOGEV(ERROR, errno, "remove watch for path %s", w->path); libxl__ev_watch_slot *slot = &CTX->watch_slots[w->slotnum]; LIBXL_SLIST_INSERT_HEAD(&CTX->watch_freeslots, slot, empty); @@ -863,25 +858,24 @@ static void devstate_callback(libxl__egc *egc, libxl__xswait_state *xsw, if (rc) { if (rc == ERROR_TIMEDOUT) - LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "backend %s wanted state %d " - " timed out", ds->w.path, ds->wanted); + LOG(DEBUG, "backend %s wanted state %d "" timed out", ds->w.path, + ds->wanted); goto out; } if (!sstate) { - LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "backend %s wanted state %d" - " but it was removed", ds->w.path, ds->wanted); + LOG(DEBUG, "backend %s wanted state %d"" but it was removed", + ds->w.path, ds->wanted); rc = ERROR_INVAL; goto out; } int got = atoi(sstate); if (got == ds->wanted) { - LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "backend %s wanted state %d ok", - ds->w.path, ds->wanted); + LOG(DEBUG, "backend %s wanted state %d ok", ds->w.path, ds->wanted); rc = 0; } else { - LIBXL__LOG(CTX, LIBXL__LOG_DEBUG, "backend %s wanted state %d" - " still waiting state %d", ds->w.path, ds->wanted, got); + LOG(DEBUG, "backend %s wanted state %d"" still waiting state %d", + ds->w.path, ds->wanted, got); return; } @@ -1705,7 +1699,7 @@ static int eventloop_iteration(libxl__egc *egc, libxl__poller *poller) { if (errno == EINTR) return 0; /* will go round again if caller requires */ - LIBXL__LOG_ERRNOVAL(CTX, LIBXL__LOG_ERROR, errno, "poll failed"); + LOGEV(ERROR, errno, "poll failed"); rc = ERROR_FAIL; goto out; } @@ -1897,6 +1891,7 @@ static bool ao_work_outstanding(libxl__ao *ao) void libxl__ao_complete_check_progress_reports(libxl__egc *egc, libxl__ao *ao) { + EGC_GC; libxl_ctx *ctx = libxl__gc_owner(&egc->gc); assert(ao->progress_reports_outstanding >= 0); @@ -1909,7 +1904,7 @@ void libxl__ao_complete_check_progress_reports(libxl__egc *egc, libxl__ao *ao) /* don't bother with this if we're not in the event loop */ libxl__poller_wakeup(egc, ao->poller); } else if (ao->how.callback) { - LIBXL__LOG(ctx, XTL_DEBUG, "ao %p: complete for callback",ao); + LOG(DEBUG, "ao %p: complete for callback", ao); LIBXL_TAILQ_INSERT_TAIL(&egc->aos_for_callback, ao, entry_for_callback); } else { libxl_event *ev; @@ -2001,8 +1996,9 @@ int libxl__ao_inprogress(libxl__ao *ao, rc = eventloop_iteration(&egc,ao->poller); if (rc) { /* Oh dear, this is quite unfortunate. */ - LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "Error waiting for" - " event during long-running operation (rc=%d)", rc); + LOG(ERROR, + "Error waiting for"" event during long-running operation (rc=%d)", + rc); sleep(1); /* It's either this or return ERROR_I_DONT_KNOW_WHETHER * _THE_THING_YOU_ASKED_FOR_WILL_BE_DONE_LATER_WHEN @@ -2041,7 +2037,7 @@ static int ao__abort(libxl_ctx *ctx, libxl__ao *parent) parent->aborting = 1; if (LIBXL_LIST_EMPTY(&parent->abortables)) { - LIBXL__LOG(ctx, XTL_DEBUG, + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "ao %p: abort requested and noted, but no-one interested", parent); rc = 0; @@ -2061,8 +2057,8 @@ static int ao__abort(libxl_ctx *ctx, libxl__ao *parent) LIBXL_LIST_REMOVE(abrt, entry); abrt->registered = 0; - LIBXL__LOG(ctx, XTL_DEBUG, "ao %p: abrt=%p: aborting", - parent, abrt->ao); + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, + "ao %p: abrt=%p: aborting", parent, abrt->ao); abrt->callback(&egc, abrt, ERROR_ABORTED); libxl__ctx_unlock(ctx); diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c index ecb30cf..df4aead 100644 --- a/tools/libxl/libxl_exec.c +++ b/tools/libxl/libxl_exec.c @@ -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); diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 366ea05..c69d6f9 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -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; diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index 8434ec8..378f6b0 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -81,7 +81,6 @@ static int libxl__device_from_pcidev(libxl__gc *gc, uint32_t domid, int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num) { - libxl_ctx *ctx = libxl__gc_owner(gc); flexarray_t *front = NULL; flexarray_t *back = NULL; libxl__device device; @@ -92,7 +91,7 @@ int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, ret = 0; - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Creating pci backend"); + LOG(DEBUG, "Creating pci backend"); /* add pci device */ libxl__device_from_pcidev(gc, domid, pcidev, &device); @@ -119,7 +118,6 @@ int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting) { - libxl_ctx *ctx = libxl__gc_owner(gc); flexarray_t *back; char *num_devs, *be_path; int num = 0; @@ -150,7 +148,7 @@ static int libxl__device_pci_add_xenstore(libxl__gc *gc, uint32_t domid, libxl_d back = flexarray_make(gc, 16, 1); - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore"); + LOG(DEBUG, "Adding new pci device to xenstore"); num = atoi(num_devs); libxl_create_pci_backend_device(gc, back, num, pcidev); flexarray_append_pair(back, "num_devs", libxl__sprintf(gc, "%d", num + 1)); @@ -214,7 +212,7 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libx if (domtype == LIBXL_DOMAIN_TYPE_PV) { if (libxl__wait_for_backend(gc, be_path, GCSPRINTF("%d", XenbusStateConnected)) < 0) { - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path); + LOG(DEBUG, "pci backend at %s is not ready", be_path); return ERROR_FAIL; } } @@ -229,7 +227,7 @@ static int libxl__device_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libx } } if (i == num) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Couldn't find the device on xenstore"); + LOG(ERROR, "Couldn't find the device on xenstore"); return ERROR_INVAL; } @@ -243,7 +241,7 @@ retry_transaction: if (domtype == LIBXL_DOMAIN_TYPE_PV) { if (libxl__wait_for_backend(gc, be_path, GCSPRINTF("%d", XenbusStateConnected)) < 0) { - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "pci backend at %s is not ready", be_path); + LOG(DEBUG, "pci backend at %s is not ready", be_path); return ERROR_FAIL; } } @@ -374,14 +372,12 @@ static int is_pcidev_in_array(libxl_device_pci *assigned, int num_assigned, static int sysfs_write_bdf(libxl__gc *gc, const char * sysfs_path, libxl_device_pci *pcidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); int rc, fd; char *buf; fd = open(sysfs_path, O_WRONLY); if (fd < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", - sysfs_path); + LOGE(ERROR, "Couldn't open %s", sysfs_path); return ERROR_FAIL; } @@ -390,8 +386,7 @@ static int sysfs_write_bdf(libxl__gc *gc, const char * sysfs_path, rc = write(fd, buf, strlen(buf)); /* Annoying to have two if's, but we need the errno */ if (rc < 0) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "write to %s returned %d", sysfs_path, rc); + LOGE(ERROR, "write to %s returned %d", sysfs_path, rc); close(fd); if (rc < 0) @@ -417,9 +412,9 @@ libxl_device_pci *libxl_device_pci_assignable_list(libxl_ctx *ctx, int *num) dir = opendir(SYSFS_PCIBACK_DRIVER); if ( NULL == dir ) { if ( errno == ENOENT ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Looks like pciback driver not loaded"); + LOG(ERROR, "Looks like pciback driver not loaded"); }else{ - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", SYSFS_PCIBACK_DRIVER); + LOGE(ERROR, "Couldn't open %s", SYSFS_PCIBACK_DRIVER); } goto out_closedir; } @@ -456,7 +451,6 @@ out: static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pcidev, char **driver_path) { - libxl_ctx *ctx = libxl__gc_owner(gc); char * spath, *dp = NULL; struct stat st; @@ -470,17 +464,16 @@ static int sysfs_dev_unbind(libxl__gc *gc, libxl_device_pci *pcidev, dp = libxl__zalloc(gc, PATH_MAX); dp = realpath(spath, dp); if ( !dp ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "realpath() failed"); + LOGE(ERROR, "realpath() failed"); return -1; } - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Driver re-plug path: %s", - dp); + LOG(DEBUG, "Driver re-plug path: %s", dp); /* Unbind from the old driver */ spath = libxl__sprintf(gc, "%s/unbind", dp); if ( sysfs_write_bdf(gc, spath, pcidev) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't unbind device"); + LOGE(ERROR, "Couldn't unbind device"); return -1; } } @@ -633,7 +626,6 @@ bool libxl__is_igd_vga_passthru(libxl__gc *gc, /* Scan through /sys/.../pciback/slots looking for pcidev's BDF */ static int pciback_dev_has_slot(libxl__gc *gc, libxl_device_pci *pcidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); FILE *f; int rc = 0; unsigned dom, bus, dev, func; @@ -641,8 +633,7 @@ static int pciback_dev_has_slot(libxl__gc *gc, libxl_device_pci *pcidev) f = fopen(SYSFS_PCIBACK_DRIVER"/slots", "r"); if (f == NULL) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", - SYSFS_PCIBACK_DRIVER"/slots"); + LOGE(ERROR, "Couldn't open %s", SYSFS_PCIBACK_DRIVER"/slots"); return ERROR_FAIL; } @@ -662,18 +653,15 @@ out: static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pcidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); char * spath; int rc; struct stat st; if ( access(SYSFS_PCIBACK_DRIVER, F_OK) < 0 ) { if ( errno == ENOENT ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "Looks like pciback driver is not loaded"); + LOG(ERROR, "Looks like pciback driver is not loaded"); } else { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Can't access "SYSFS_PCIBACK_DRIVER); + LOGE(ERROR, "Can't access "SYSFS_PCIBACK_DRIVER); } return -1; } @@ -687,31 +675,27 @@ static int pciback_dev_is_assigned(libxl__gc *gc, libxl_device_pci *pcidev) return 1; if ( rc < 0 && errno == ENOENT ) return 0; - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Accessing %s", spath); + LOGE(ERROR, "Accessing %s", spath); return -1; } static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pcidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); int rc; if ( (rc=pciback_dev_has_slot(gc, pcidev)) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Error checking for pciback slot"); + LOGE(ERROR, "Error checking for pciback slot"); return ERROR_FAIL; } else if (rc == 0) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/new_slot", pcidev) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Couldn't bind device to pciback!"); + LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } } if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/bind", pcidev) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Couldn't bind device to pciback!"); + LOGE(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } return 0; @@ -719,11 +703,9 @@ static int pciback_dev_assign(libxl__gc *gc, libxl_device_pci *pcidev) static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pcidev) { - libxl_ctx *ctx = libxl__gc_owner(gc); - /* Remove from pciback */ if ( sysfs_dev_unbind(gc, pcidev, NULL) < 0 ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Couldn't unbind device!"); + LOG(ERROR, "Couldn't unbind device!"); return ERROR_FAIL; } @@ -731,8 +713,7 @@ static int pciback_dev_unassign(libxl__gc *gc, libxl_device_pci *pcidev) if ( pciback_dev_has_slot(gc, pcidev) > 0 ) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/remove_slot", pcidev) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Couldn't remove pciback slot"); + LOGE(ERROR, "Couldn't remove pciback slot"); return ERROR_FAIL; } } @@ -745,7 +726,6 @@ static void pci_assignable_driver_path_write(libxl__gc *gc, libxl_device_pci *pcidev, char *driver_path) { - libxl_ctx *ctx = libxl__gc_owner(gc); char *path; path = libxl__sprintf(gc, PCIBACK_INFO_PATH"/"PCI_BDF_XSPATH"/driver_path", @@ -754,9 +734,7 @@ static void pci_assignable_driver_path_write(libxl__gc *gc, pcidev->dev, pcidev->func); if ( libxl__xs_write(gc, XBT_NULL, path, "%s", driver_path) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_WARNING, - "Write of %s to node %s failed.", - driver_path, path); + LOGE(WARN, "Write of %s to node %s failed.", driver_path, path); } } @@ -805,7 +783,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *gc, /* See if the device exists */ spath = libxl__sprintf(gc, SYSFS_PCI_DEV"/"PCI_BDF, dom, bus, dev, func); if ( lstat(spath, &st) ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't lstat %s", spath); + LOGE(ERROR, "Couldn't lstat %s", spath); return ERROR_FAIL; } @@ -847,7 +825,7 @@ static int libxl__device_pci_assignable_add(libxl__gc *gc, } if ( pciback_dev_assign(gc, pcidev) ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Couldn't bind device to pciback!"); + LOG(ERROR, "Couldn't bind device to pciback!"); return ERROR_FAIL; } @@ -858,7 +836,6 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc, libxl_device_pci *pcidev, int rebind) { - libxl_ctx *ctx = libxl__gc_owner(gc); int rc; char *driver_path; @@ -868,8 +845,7 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc, } else if ( rc ) { pciback_dev_unassign(gc, pcidev); } else { - LIBXL__LOG(ctx, LIBXL__LOG_WARNING, - "Not bound to pciback"); + LOG(WARN, "Not bound to pciback"); } /* Rebind if necessary */ @@ -877,14 +853,12 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc, if ( driver_path ) { if ( rebind ) { - LIBXL__LOG(ctx, LIBXL__LOG_INFO, "Rebinding to driver at %s", - driver_path); + LOG(INFO, "Rebinding to driver at %s", driver_path); if ( sysfs_write_bdf(gc, libxl__sprintf(gc, "%s/bind", driver_path), pcidev) < 0 ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, - "Couldn't bind device to %s", driver_path); + LOGE(ERROR, "Couldn't bind device to %s", driver_path); return -1; } @@ -892,8 +866,8 @@ static int libxl__device_pci_assignable_remove(libxl__gc *gc, } } else { if ( rebind ) { - LIBXL__LOG(ctx, LIBXL__LOG_WARNING, - "Couldn't find path for original driver; not rebinding"); + LOG(WARN, + "Couldn't find path for original driver; not rebinding"); } } @@ -940,7 +914,7 @@ static int pci_multifunction_check(libxl__gc *gc, libxl_device_pci *pcidev, unsi dir = opendir(SYSFS_PCI_DEV); if ( NULL == dir ) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", SYSFS_PCI_DEV); + LOGE(ERROR, "Couldn't open %s", SYSFS_PCI_DEV); return -1; } @@ -964,7 +938,7 @@ static int pci_multifunction_check(libxl__gc *gc, libxl_device_pci *pcidev, unsi LIBXL__LOG(ctx, LIBXL__LOG_ERROR, PCI_BDF " is not assigned to pciback driver", dom, bus, dev, func); else - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't lstat %s", path); + LOGE(ERROR, "Couldn't lstat %s", path); closedir(dir); return -1; } @@ -1020,11 +994,9 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid, vdevfn = libxl__xs_read(gc, XBT_NULL, path); path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state"); if ( rc < 0 ) - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "qemu refused to add device: %s", vdevfn); + LOG(ERROR, "qemu refused to add device: %s", vdevfn); else if ( sscanf(vdevfn, "0x%x", &pcidev->vdevfn) != 1 ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "wrong format for the vdevfn: '%s'", vdevfn); + LOG(ERROR, "wrong format for the vdevfn: '%s'", vdevfn); rc = -1; } xs_write(ctx->xsh, XBT_NULL, path, state, strlen(state)); @@ -1072,7 +1044,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i irq = 0; if (f == NULL) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", sysfs_path); + LOGE(ERROR, "Couldn't open %s", sysfs_path); return ERROR_FAIL; } for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) { @@ -1083,7 +1055,10 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i if (flags & PCI_BAR_IO) { rc = xc_domain_ioport_permission(ctx->xch, domid, start, size, 1); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Error: xc_domain_ioport_permission error 0x%llx/0x%llx", start, size); + LOGE(ERROR, + "Error: xc_domain_ioport_permission error 0x%llx/0x%llx", + start, + size); fclose(f); return ERROR_FAIL; } @@ -1091,7 +1066,10 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i rc = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 1); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Error: xc_domain_iomem_permission error 0x%llx/0x%llx", start, size); + LOGE(ERROR, + "Error: xc_domain_iomem_permission error 0x%llx/0x%llx", + start, + size); fclose(f); return ERROR_FAIL; } @@ -1103,19 +1081,19 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i pcidev->bus, pcidev->dev, pcidev->func); f = fopen(sysfs_path, "r"); if (f == NULL) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", sysfs_path); + LOGE(ERROR, "Couldn't open %s", sysfs_path); goto out; } if ((fscanf(f, "%u", &irq) == 1) && irq) { rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Error: xc_physdev_map_pirq irq=%d", irq); + LOGE(ERROR, "Error: xc_physdev_map_pirq irq=%d", irq); fclose(f); return ERROR_FAIL; } rc = xc_domain_irq_permission(ctx->xch, domid, irq, 1); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Error: xc_domain_irq_permission irq=%d", irq); + LOGE(ERROR, "Error: xc_domain_irq_permission irq=%d", irq); fclose(f); return ERROR_FAIL; } @@ -1126,8 +1104,7 @@ static int do_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, i if (pcidev->permissive) { if ( sysfs_write_bdf(gc, SYSFS_PCIBACK_DRIVER"/permissive", pcidev) < 0 ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, - "Setting permissive for device"); + LOG(ERROR, "Setting permissive for device"); return ERROR_FAIL; } } @@ -1137,12 +1114,12 @@ out: if (pcidev->rdm_policy == LIBXL_RDM_RESERVE_POLICY_STRICT) { flag &= ~XEN_DOMCTL_DEV_RDM_RELAXED; } else if (pcidev->rdm_policy != LIBXL_RDM_RESERVE_POLICY_RELAXED) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unknown rdm check flag."); + LOGE(ERROR, "unknown rdm check flag."); return ERROR_FAIL; } rc = xc_assign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev), flag); if (rc < 0 && (hvm || errno != ENOSYS)) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_assign_device failed"); + LOGE(ERROR, "xc_assign_device failed"); return ERROR_FAIL; } } @@ -1167,25 +1144,25 @@ static int libxl__device_pci_reset(libxl__gc *gc, unsigned int domain, unsigned char *buf = libxl__sprintf(gc, PCI_BDF, domain, bus, dev, func); rc = write(fd, buf, strlen(buf)); if (rc < 0) - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "write to %s returned %d", reset, rc); + LOG(ERROR, "write to %s returned %d", reset, rc); close(fd); return rc < 0 ? rc : 0; } if (errno != ENOENT) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Failed to access pciback path %s", reset); + LOGE(ERROR, "Failed to access pciback path %s", reset); reset = libxl__sprintf(gc, "%s/"PCI_BDF"/reset", SYSFS_PCI_DEV, domain, bus, dev, func); fd = open(reset, O_WRONLY); if (fd >= 0) { rc = write(fd, "1", 1); if (rc < 0) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "write to %s returned %d", reset, rc); + LOGE(ERROR, "write to %s returned %d", reset, rc); close(fd); return rc < 0 ? rc : 0; } if (errno == ENOENT) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "The kernel doesn't support reset from sysfs for PCI device "PCI_BDF, domain, bus, dev, func); } else { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Failed to access reset path %s", reset); + LOGE(ERROR, "Failed to access reset path %s", reset); } return -1; } @@ -1264,12 +1241,13 @@ int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcide rc = get_all_assigned_devices(gc, &assigned, &num_assigned); if ( rc ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot determine if device is assigned, refusing to continue"); + LOG(ERROR, + "cannot determine if device is assigned, refusing to continue"); goto out; } if ( is_pcidev_in_array(assigned, num_assigned, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func) ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "PCI device already attached to a domain"); + LOG(ERROR, "PCI device already attached to a domain"); rc = ERROR_FAIL; goto out; } @@ -1289,7 +1267,7 @@ int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcide if ( pcidev->vfunc_mask == LIBXL_PCI_FUNC_ALL ) { if ( !(pcidev->vdevfn >> 3) ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Must specify a v-slot for multi-function devices"); + LOG(ERROR, "Must specify a v-slot for multi-function devices"); rc = ERROR_INVAL; goto out; } @@ -1346,7 +1324,7 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid, libxl__qemu_traditional_cmd(gc, domid, "pci-rem"); if (libxl__wait_for_device_model_deprecated(gc, domid, "pci-removed", NULL, NULL, NULL) < 0) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model didn't respond in time"); + LOG(ERROR, "Device Model didn't respond in time"); /* This depends on guest operating system acknowledging the * SCI, if it doesn't respond in time then we may wish to * force the removal. @@ -1379,7 +1357,7 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, rc = ERROR_INVAL; if ( !is_pcidev_in_array(assigned, num, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func) ) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "PCI device not attached to this domain"); + LOG(ERROR, "PCI device not attached to this domain"); goto out_fail; } @@ -1416,7 +1394,7 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, int i; if (f == NULL) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", sysfs_path); + LOGE(ERROR, "Couldn't open %s", sysfs_path); goto skip1; } for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) { @@ -1427,12 +1405,18 @@ static int do_pci_remove(libxl__gc *gc, uint32_t domid, if (flags & PCI_BAR_IO) { rc = xc_domain_ioport_permission(ctx->xch, domid, start, size, 0); if (rc < 0) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_ioport_permission error 0x%x/0x%x", start, size); + LOGE(ERROR, + "xc_domain_ioport_permission error 0x%x/0x%x", + start, + size); } else { rc = xc_domain_iomem_permission(ctx->xch, domid, start>>XC_PAGE_SHIFT, (size+(XC_PAGE_SIZE-1))>>XC_PAGE_SHIFT, 0); if (rc < 0) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_iomem_permission error 0x%x/0x%x", start, size); + LOGE(ERROR, + "xc_domain_iomem_permission error 0x%x/0x%x", + start, + size); } } } @@ -1442,17 +1426,17 @@ skip1: pcidev->bus, pcidev->dev, pcidev->func); f = fopen(sysfs_path, "r"); if (f == NULL) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", sysfs_path); + LOGE(ERROR, "Couldn't open %s", sysfs_path); goto out; } if ((fscanf(f, "%u", &irq) == 1) && irq) { rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_physdev_unmap_pirq irq=%d", irq); + LOGE(ERROR, "xc_physdev_unmap_pirq irq=%d", irq); } rc = xc_domain_irq_permission(ctx->xch, domid, irq, 0); if (rc < 0) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_domain_irq_permission irq=%d", irq); + LOGE(ERROR, "xc_domain_irq_permission irq=%d", irq); } } fclose(f); @@ -1466,7 +1450,7 @@ out: if (!libxl_is_stubdom(ctx, domid, NULL)) { rc = xc_deassign_device(ctx->xch, domid, pcidev_encode_bdf(pcidev)); if (rc < 0 && (hvm || errno != ENOSYS)) - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xc_deassign_device failed"); + LOGE(ERROR, "xc_deassign_device failed"); } stubdomid = libxl_get_stubdom_id(ctx, domid); diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 408ec85..2eba584 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -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; \ } diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c index 896f34c..a3e50df 100644 --- a/tools/libxl/libxl_x86.c +++ b/tools/libxl/libxl_x86.c @@ -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); } } diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index d7eaa66..b0db062 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -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; } -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |