Ejemplo n.º 1
0
int libxl_get_free_memory_0x040700(libxl_ctx *ctx, uint32_t *memkb)
{
    uint64_t my_memkb;
    int rc;

    rc = libxl_get_free_memory(ctx, &my_memkb);
    return libxl__memkb_64to32(ctx, rc, my_memkb, memkb);
}
Ejemplo n.º 2
0
int  hyperxl_initialize_driver(hyperxl_driver** pdriver, bool verbose) {

#ifndef LIBXL_HAVE_BUILDINFO_KERNEL

    return -1;

#else

    hyperxl_driver *driver;
    const libxl_version_info* version = NULL;
    uint32_t mem = 0;
    xentoollog_level log_level = XTL_INFO;

    *pdriver = (hyperxl_driver*)malloc(sizeof(hyperxl_driver));
    if ( *pdriver == NULL ) {
        return -1;
    }

    driver = *pdriver;

    if (verbose) {
        log_level = XTL_DEBUG;
    }
    driver->logger = (xentoollog_logger*)xtl_createlogger_hyperxl(log_level, 0);
    if (driver->logger == NULL) {
        goto release_driver;
    }

    if(libxl_ctx_alloc(&driver->ctx, LIBXL_VERSION, 0, driver->logger)) {
        goto close_logger;
    }

    libxl_childproc_setmode(driver->ctx, &libxl_child_hooks, driver->ctx);

    version = libxl_get_version_info(driver->ctx);
    if (version == NULL) {
        goto free_ctx;
    }

    driver->version = version->xen_version_major * 1000000 + version->xen_version_minor * 1000;
    driver->capabilities = strdup(version->capabilities);

    if(libxl_get_free_memory(driver->ctx, &mem)) {
        goto free_ctx;
    }

    libxl_event_register_callbacks(driver->ctx, &ev_hooks, driver);

    return 0;

free_ctx:
    libxl_ctx_free(driver->ctx);
close_logger:
    xtl_logger_destroy(driver->logger);
release_driver:
    free(driver);
    driver = NULL;
    return -1;

#endif //LIBXL_HAVE_BUILDINFO_KERNEL
}
Ejemplo n.º 3
0
libxlDriverConfigPtr
libxlDriverConfigNew(void)
{
    libxlDriverConfigPtr cfg;
    char *log_file = NULL;
    char ebuf[1024];
    unsigned int free_mem;

    if (libxlConfigInitialize() < 0)
        return NULL;

    if (!(cfg = virObjectNew(libxlDriverConfigClass)))
        return NULL;

    if (VIR_STRDUP(cfg->configDir, LIBXL_CONFIG_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->autostartDir, LIBXL_AUTOSTART_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->logDir, LIBXL_LOG_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->stateDir, LIBXL_STATE_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->libDir, LIBXL_LIB_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->saveDir, LIBXL_SAVE_DIR) < 0)
        goto error;
    if (VIR_STRDUP(cfg->autoDumpDir, LIBXL_DUMP_DIR) < 0)
        goto error;

    if (virAsprintf(&log_file, "%s/libxl-driver.log", cfg->logDir) < 0)
        goto error;

    if (virFileMakePath(cfg->logDir) < 0) {
        virReportError(VIR_ERR_INTERNAL_ERROR,
                       _("failed to create log dir '%s': %s"),
                       cfg->logDir,
                       virStrerror(errno, ebuf, sizeof(ebuf)));
        goto error;
    }

    if ((cfg->logger_file = fopen(log_file, "a")) == NULL)  {
        VIR_ERROR(_("Failed to create log file '%s': %s"),
                  log_file, virStrerror(errno, ebuf, sizeof(ebuf)));
        goto error;
    }
    VIR_FREE(log_file);

    cfg->logger =
        (xentoollog_logger *)xtl_createlogger_stdiostream(cfg->logger_file,
                                                          XTL_DEBUG, 0);
    if (!cfg->logger) {
        VIR_ERROR(_("cannot create logger for libxenlight, disabling driver"));
        goto error;
    }

    if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, cfg->logger)) {
        VIR_ERROR(_("cannot initialize libxenlight context, probably not "
                    "running in a Xen Dom0, disabling driver"));
        goto error;
    }

    if ((cfg->verInfo = libxl_get_version_info(cfg->ctx)) == NULL) {
        VIR_ERROR(_("cannot version information from libxenlight, "
                    "disabling driver"));
        goto error;
    }
    cfg->version = (cfg->verInfo->xen_version_major * 1000000) +
        (cfg->verInfo->xen_version_minor * 1000);

    /* This will fill xenstore info about free and dom0 memory if missing,
     * should be called before starting first domain */
    if (libxl_get_free_memory(cfg->ctx, &free_mem)) {
        VIR_ERROR(_("Unable to configure libxl's memory management parameters"));
        goto error;
    }

    /* setup autoballoon */
    if (libxlGetAutoballoonConf(cfg, &cfg->autoballoon) < 0)
        goto error;

    return cfg;

error:
    VIR_FREE(log_file);
    virObjectUnref(cfg);
    return NULL;
}