コード例 #1
0
ファイル: xen_helper.c プロジェクト: JaonLin/drakvuf
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;
}
コード例 #2
0
ファイル: core.c プロジェクト: 0day-ci/xen
xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags)
{
    xenevtchn_handle *xce = malloc(sizeof(*xce));
    int rc;

    if (!xce) return NULL;

    xce->fd = -1;
    xce->logger = logger;
    xce->logger_tofree  = NULL;

    if (!xce->logger) {
        xce->logger = xce->logger_tofree =
            (xentoollog_logger*)
            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
        if (!xce->logger) goto err;
    }

    rc = osdep_evtchn_open(xce);
    if ( rc  < 0 ) goto err;

    return xce;

err:
    osdep_evtchn_close(xce);
    xtl_logger_destroy(xce->logger_tofree);
    free(xce);
    return NULL;
}
コード例 #3
0
ファイル: core.c プロジェクト: 0day-ci/xen
xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger,
                                               unsigned open_flags)
{
    xenforeignmemory_handle *fmem = malloc(sizeof(*fmem));
    int rc;

    if (!fmem) return NULL;

    fmem->fd = -1;
    fmem->logger = logger;
    fmem->logger_tofree = NULL;

    if (!fmem->logger) {
        fmem->logger = fmem->logger_tofree =
            (xentoollog_logger*)
            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
        if (!fmem->logger) goto err;
    }

    rc = osdep_xenforeignmemory_open(fmem);
    if ( rc  < 0 ) goto err;

    return fmem;

err:
    osdep_xenforeignmemory_close(fmem);
    xtl_logger_destroy(fmem->logger_tofree);
    free(fmem);
    return NULL;
}
コード例 #4
0
ファイル: test_common.c プロジェクト: 0day-ci/xen
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);
}
コード例 #5
0
ファイル: xc_private.c プロジェクト: tklengyel/xen
struct xc_interface_core *xc_interface_open(xentoollog_logger *logger,
                                            xentoollog_logger *dombuild_logger,
                                            unsigned open_flags)
{
    struct xc_interface_core xch_buf = { 0 }, *xch = &xch_buf;

    xch->flags = open_flags;
    xch->dombuild_logger_file = 0;
    xc_clear_last_error(xch);

    xch->error_handler   = logger;           xch->error_handler_tofree   = 0;
    xch->dombuild_logger = dombuild_logger;  xch->dombuild_logger_tofree = 0;

    if (!xch->error_handler) {
        xch->error_handler = xch->error_handler_tofree =
            (xentoollog_logger*)
            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
        if (!xch->error_handler)
            goto err;
    }

    xch = malloc(sizeof(*xch));
    if (!xch) {
        xch = &xch_buf;
        PERROR("Could not allocate new xc_interface struct");
        goto err;
    }
    *xch = xch_buf;

    if (open_flags & XC_OPENFLAG_DUMMY)
        return xch; /* We are done */

    xch->xcall = xencall_open(xch->error_handler,
        open_flags & XC_OPENFLAG_NON_REENTRANT ? XENCALL_OPENFLAG_NON_REENTRANT : 0U);
    if ( xch->xcall == NULL )
        goto err;

    xch->fmem = xenforeignmemory_open(xch->error_handler, 0);
    if ( xch->fmem == NULL )
        goto err;

    xch->dmod = xendevicemodel_open(xch->error_handler, 0);
    if ( xch->dmod == NULL )
        goto err;

    return xch;

 err:
    xenforeignmemory_close(xch->fmem);
    xencall_close(xch->xcall);
    xtl_logger_destroy(xch->error_handler_tofree);
    if (xch != &xch_buf) free(xch);
    return NULL;
}
コード例 #6
0
ファイル: xc_dom_core.c プロジェクト: avsm/xen-1
int xc_dom_loginit(xc_interface *xch) {
    if (xch->dombuild_logger) return 0;

    if (!xch->dombuild_logger_file) {
        xch->dombuild_logger_file = fopen(default_logfile, "a");
        if (!xch->dombuild_logger_file) {
            PERROR("Could not open logfile `%s'", default_logfile);
            return -1;
        }
    }
    
    xch->dombuild_logger = xch->dombuild_logger_tofree =
        (xentoollog_logger*)
        xtl_createlogger_stdiostream(xch->dombuild_logger_file, XTL_DETAIL,
             XTL_STDIOSTREAM_SHOW_DATE|XTL_STDIOSTREAM_SHOW_PID);
    if (!xch->dombuild_logger)
        return -1;

    xc_dom_printf(xch, "### ----- xc domain builder logfile opened -----");

    return 0;
}
コード例 #7
0
ファイル: core.c プロジェクト: royger/xen
xendevicemodel_handle *xendevicemodel_open(xentoollog_logger *logger,
                                           unsigned open_flags)
{
    xendevicemodel_handle *dmod = calloc(1, sizeof(*dmod));
    int rc;

    if (!dmod)
        return NULL;

    dmod->flags = open_flags;
    dmod->logger = logger;
    dmod->logger_tofree = NULL;

    if (!dmod->logger) {
        dmod->logger = dmod->logger_tofree =
            (xentoollog_logger*)
            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
        if (!dmod->logger)
            goto err;
    }

    dmod->xcall = xencall_open(dmod->logger, 0);
    if (!dmod->xcall)
        goto err;

    rc = osdep_xendevicemodel_open(dmod);
    if (rc)
        goto err;

    return dmod;

err:
    xtl_logger_destroy(dmod->logger_tofree);
    xencall_close(dmod->xcall);
    free(dmod);
    return NULL;
}
コード例 #8
0
ファイル: xl.c プロジェクト: Chong-Li/xen
int main(int argc, char **argv)
{
    int opt = 0;
    char *cmd = 0;
    struct cmd_spec *cspec;
    int ret;
    void *config_data = 0;
    int config_len = 0;

    while ((opt = getopt(argc, argv, "+vftN")) >= 0) {
        switch (opt) {
        case 'v':
            if (minmsglevel > 0) minmsglevel--;
            break;
        case 'N':
            dryrun_only = 1;
            break;
        case 'f':
            force_execution = 1;
            break;
        case 't':
            progress_use_cr = 1;
            break;
        default:
            fprintf(stderr, "unknown global option\n");
            exit(EXIT_FAILURE);
        }
    }

    cmd = argv[optind];

    if (!cmd) {
        help(NULL);
        exit(EXIT_FAILURE);
    }
    opterr = 0;

    logger = xtl_createlogger_stdiostream(stderr, minmsglevel,
        (progress_use_cr ? XTL_STDIOSTREAM_PROGRESS_USE_CR : 0));
    if (!logger) exit(EXIT_FAILURE);

    atexit(xl_ctx_free);

    xl_ctx_alloc();

    ret = libxl_read_file_contents(ctx, XL_GLOBAL_CONFIG,
            &config_data, &config_len);
    if (ret)
        fprintf(stderr, "Failed to read config file: %s: %s\n",
                XL_GLOBAL_CONFIG, strerror(errno));
    parse_global_config(XL_GLOBAL_CONFIG, config_data, config_len);
    free(config_data);

    /* Reset options for per-command use of getopt. */
    argv += optind;
    argc -= optind;
    optind = 1;

    cspec = cmdtable_lookup(cmd);
    if (cspec) {
        if (dryrun_only && !cspec->can_dryrun) {
            fprintf(stderr, "command does not implement -N (dryrun) option\n");
            ret = EXIT_FAILURE;
            goto xit;
        }
        ret = cspec->cmd_impl(argc, argv);
    } else if (!strcmp(cmd, "help")) {
        help(argv[1]);
        ret = EXIT_SUCCESS;
    } else {
        fprintf(stderr, "command not implemented\n");
        ret = EXIT_FAILURE;
    }

 xit:
    return ret;
}
コード例 #9
0
ファイル: libxl_conf.c プロジェクト: dmitryilyin/libvirt
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;
}
コード例 #10
0
ファイル: xl.c プロジェクト: HackLinux/xen
int main(int argc, char **argv)
{
    int opt = 0;
    char *cmd = 0;
    struct cmd_spec *cspec;
    int ret;
    void *config_data = 0;
    int config_len = 0;
    const char *locks[] = XEND_LOCK;

    while ((opt = getopt(argc, argv, "+vfN")) >= 0) {
        switch (opt) {
        case 'v':
            if (minmsglevel > 0) minmsglevel--;
            break;
        case 'N':
            dryrun_only = 1;
            break;
        case 'f':
            force_execution = 1;
            break;
        default:
            fprintf(stderr, "unknown global option\n");
            exit(2);
        }
    }

    cmd = argv[optind];

    if (!cmd) {
        help(NULL);
        exit(1);
    }
    opterr = 0;

    logger = xtl_createlogger_stdiostream(stderr, minmsglevel,  0);
    if (!logger) exit(1);

    atexit(xl_ctx_free);

    xl_ctx_alloc();

    ret = libxl_read_file_contents(ctx, XL_GLOBAL_CONFIG,
            &config_data, &config_len);
    if (ret)
        fprintf(stderr, "Failed to read config file: %s: %s\n",
                XL_GLOBAL_CONFIG, strerror(errno));
    parse_global_config(XL_GLOBAL_CONFIG, config_data, config_len);
    free(config_data);

    /* Reset options for per-command use of getopt. */
    argv += optind;
    argc -= optind;
    optind = 1;

    cspec = cmdtable_lookup(cmd);
    if (cspec) {
        if (dryrun_only && !cspec->can_dryrun) {
            fprintf(stderr, "command does not implement -N (dryrun) option\n");
            ret = 1;
            goto xit;
        }
        if (cspec->modifies && !dryrun_only) {
            for (int i = 0; i < sizeof(locks)/sizeof(locks[0]); i++) {
                if (!access(locks[i], F_OK) && !force_execution) {
                    fprintf(stderr,
"xend is running, which may cause unpredictable results when using\n"
"this xl command.  Please shut down xend before continuing.\n\n"
"(This check can be overridden with the -f option.)\n"
                            );
                    ret = 1;
                    goto xit;
                }
            }
        }
        ret = cspec->cmd_impl(argc, argv);
    } else if (!strcmp(cmd, "help")) {
        help(argv[1]);
        ret = 0;
    } else {
        fprintf(stderr, "command not implemented\n");
        ret = 1;
    }

 xit:
    return ret;
}
コード例 #11
0
ファイル: async_test.c プロジェクト: euanh/xl-test
#include <stdio.h>
#include <stdlib.h>

#include "testcase_runner.h"
#include "eventloop_runner.h"

void *testcase(struct test *tc);

int main(int argc __attribute__((unused)), 
         char **argv __attribute__((unused)))
{
    struct test t;
    xentoollog_logger *logger;

    logger = (xentoollog_logger *)
        xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);

    if (! !test_spawn(&t, logger, testcase)) {
        perror("Failed to spawn test thread");
        exit(EXIT_FAILURE);
    }

    eventloop_start(&t);

    fprintf(stderr, "Waiting for test thread to exit\n");
    test_join(&t);
    fprintf(stderr, "Test thread exited\n");
    test_destroy(&t);
    xtl_logger_destroy(logger);

    exit(EXIT_SUCCESS);
コード例 #12
0
ファイル: common.c プロジェクト: armoredsoftware/xenVchan
xentoollog_logger_stdiostream * createDebugLogger(){

  return xtl_createlogger_stdiostream(stdout, XTL_DEBUG, 0);
}
コード例 #13
0
ファイル: xc_private.c プロジェクト: mymas/xen-4.4.0
static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger,
                                                          xentoollog_logger *dombuild_logger,
                                                          unsigned open_flags,
                                                          enum xc_osdep_type type)
{
    struct xc_interface_core xch_buf, *xch = &xch_buf;

    xch->type = type;
    xch->flags = open_flags;
    xch->dombuild_logger_file = 0;
    xc_clear_last_error(xch);

    xch->error_handler   = logger;           xch->error_handler_tofree   = 0;
    xch->dombuild_logger = dombuild_logger;  xch->dombuild_logger_tofree = 0;

    xch->hypercall_buffer_cache_nr = 0;

    xch->hypercall_buffer_total_allocations = 0;
    xch->hypercall_buffer_total_releases = 0;
    xch->hypercall_buffer_current_allocations = 0;
    xch->hypercall_buffer_maximum_allocations = 0;
    xch->hypercall_buffer_cache_hits = 0;
    xch->hypercall_buffer_cache_misses = 0;
    xch->hypercall_buffer_cache_toobig = 0;

    xch->ops_handle = XC_OSDEP_OPEN_ERROR;
    xch->ops = NULL;

    if (!xch->error_handler) {
        xch->error_handler = xch->error_handler_tofree =
            (xentoollog_logger*)
            xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
        if (!xch->error_handler)
            goto err;
    }

    xch = malloc(sizeof(*xch));
    if (!xch) {
        xch = &xch_buf;
        PERROR("Could not allocate new xc_interface struct");
        goto err;
    }
    *xch = xch_buf;

    if (!(open_flags & XC_OPENFLAG_DUMMY)) {
        if ( xc_osdep_get_info(xch, &xch->osdep) < 0 )
            goto err;

        xch->ops = xch->osdep.init(xch, type);
        if ( xch->ops == NULL )
        {
            DPRINTF("OSDEP: interface %d (%s) not supported on this platform",
                  type, xc_osdep_type_name(type));
            goto err_put_iface;
        }

        xch->ops_handle = xch->ops->open(xch);
        if (xch->ops_handle == XC_OSDEP_OPEN_ERROR)
            goto err_put_iface;
    }

    return xch;

err_put_iface:
    xc_osdep_put(&xch->osdep);
 err:
    xtl_logger_destroy(xch->error_handler_tofree);
    if (xch != &xch_buf) free(xch);
    return NULL;
}