bool xen_init_interface(xen_interface_t **xen) { *xen = g_malloc0(sizeof(xen_interface_t)); /* We create an xc interface to test connection to it */ (*xen)->xc = xc_interface_open(0, 0, 0); if ((*xen)->xc == NULL) { fprintf(stderr, "xc_interface_open() failed!\n"); goto err; } /* We don't need this at the moment, but just in case */ //xen->xsh=xs_open(XS_OPEN_READONLY); (*xen)->xl_logger = (xentoollog_logger *) xtl_createlogger_stdiostream( stderr, XTL_PROGRESS, 0); if (!(*xen)->xl_logger) { goto err; } if (libxl_ctx_alloc(&(*xen)->xl_ctx, LIBXL_VERSION, 0, (*xen)->xl_logger)) { fprintf(stderr, "libxl_ctx_alloc() failed!\n"); goto err; } return 1; err: xen_free_interface(*xen); *xen = NULL; return 0; }
void xl_ctx_alloc(void) { if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, (xentoollog_logger*)logger)) { fprintf(stderr, "cannot init xl context\n"); exit(1); } libxl_childproc_setmode(ctx, &childproc_hooks, 0); }
void test_common_setup(int level) { xentoollog_logger_stdiostream *logger_s = xtl_createlogger_stdiostream(stderr, level, 0); assert(logger_s); xentoollog_logger *logger = (xentoollog_logger*)logger_s; int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, logger); assert(!rc); }
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 }
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; }