Exemplo n.º 1
0
static ctx_t *getctx (flux_t h)
{
    int saved_errno;
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "req");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        ctx->ping_requests = zhash_new ();
        ctx->clog_requests = zlist_new ();
        if (!ctx->clog_requests || !ctx->ping_requests) {
            saved_errno = ENOMEM;
            goto error; 
        }
        if (flux_get_rank (h, &ctx->rank) < 0) {
            saved_errno = errno;
            goto error;
        }
        flux_aux_set (h, "req", ctx, freectx);
    }
    return ctx;
error:
    freectx (ctx);
    errno = saved_errno;
    return NULL;
}
Exemplo n.º 2
0
static ctx_t *getctx (flux_t *h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "flux::barrier");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->barriers = zhash_new ())) {
            errno = ENOMEM;
            goto error;
        }
        if (flux_get_rank (h, &ctx->rank) < 0) {
            flux_log_error (h, "flux_get_rank");
            goto error;
        }
        if (!(ctx->timer = flux_timer_watcher_create (flux_get_reactor (h),
                       barrier_reduction_timeout_sec, 0., timeout_cb, ctx) )) {
            flux_log_error (h, "flux_timer_watacher_create");
            goto error;
        }
        ctx->h = h;
        flux_aux_set (h, "flux::barrier", ctx, freectx);
    }
    return ctx;
error:
    freectx (ctx);
    return NULL;
}
Exemplo n.º 3
0
static struct dispatch *dispatch_get (flux_t h)
{
    struct dispatch *d = flux_aux_get (h, "flux::dispatch");
    if (!d) {
        flux_reactor_t *r = flux_get_reactor (h);
        if (!(d = malloc (sizeof (*d))))
            goto nomem;
        memset (d, 0, sizeof (*d));
        d->usecount = 1;
        if (!(d->handlers = zlist_new ()))
            goto nomem;
        if (!(d->handlers_new = zlist_new ()))
            goto nomem;
        d->h = h;
        d->w = flux_handle_watcher_create (r, h, FLUX_POLLIN, handle_cb, d);
        if (!d->w)
            goto nomem;
        fastpath_init (&d->norm);
        fastpath_init (&d->group);

        flux_aux_set (h, "flux::dispatch", d, dispatch_destroy);
    }
    return d;
nomem:
    dispatch_destroy (d);
    errno = ENOMEM;
    return NULL;
}
Exemplo n.º 4
0
static attr_ctx_t *getctx (flux_t *h)
{
    attr_ctx_t *ctx = flux_aux_get (h, "flux::attr");
    if (!ctx)
        ctx = attr_ctx_new (h);
    return ctx;
}
Exemplo n.º 5
0
int flux_set_reactor (flux_t h, flux_reactor_t *r)
{
    if (flux_aux_get (h, "flux::reactor")) {
        errno = EEXIST;
        return -1;
    }
    flux_aux_set (h, "flux::reactor", r, NULL);
    return 0;
}
Exemplo n.º 6
0
flux_reactor_t *flux_get_reactor (flux_t h)
{
    flux_reactor_t *r = flux_aux_get (h, "flux::reactor");
    if (!r) {
        if ((r = flux_reactor_create (0)))
            flux_aux_set (h, "flux::reactor", r,
                          (flux_free_f)flux_reactor_destroy);
    }
    return r;
}
Exemplo n.º 7
0
static jstatctx_t *getctx (flux_t h)
{
    jstatctx_t *ctx = (jstatctx_t *)flux_aux_get (h, "jstat");
    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        ctx->op = NULL;
        flux_aux_set (h, "jstat", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 8
0
static logctx_t *getctx (flux_t h)
{
    logctx_t *ctx = (logctx_t *)flux_aux_get (h, "flux::log");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        snprintf (ctx->appname, sizeof (ctx->appname), "%s", STDLOG_NILVALUE);
        snprintf (ctx->procid, sizeof (ctx->procid), "%d", getpid ());
        flux_aux_set (h, "flux::log", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 9
0
static wjctx_t *getctx (flux_t h)
{
    wjctx_t *ctx = (wjctx_t *)flux_aux_get (h, "waitjob");
    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->jobid = -1;
        ctx->h = h;
        ctx->start = NULL;
        ctx->complete = NULL;
        flux_aux_set (h, "waitjob", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 10
0
static ctx_t *getctx (flux_t h, module_t *p)
{
    ctx_t *ctx = flux_aux_get (h, "flux::modservice");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->handlers = zlist_new ()))
            oom ();
        ctx->h = h;
        ctx->p = p;
        flux_aux_set (h, "flux::modservice", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 11
0
static ctx_t *getctx (flux_t h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "barriersrv");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->barriers = zhash_new ()))
            oom ();
        ctx->h = h;
        flux_aux_set (h, "barriersrv", ctx, (FluxFreeFn)freectx);
    }

    return ctx;
}
Exemplo n.º 12
0
static logctx_t *getctx (flux_t *h)
{
    logctx_t *ctx = (logctx_t *)flux_aux_get (h, "flux::log");
    extern char *__progname;
    // or glib-ism: program_invocation_short_name

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        snprintf (ctx->procid, sizeof (ctx->procid), "%d", getpid ());
        snprintf (ctx->appname, sizeof (ctx->appname), "%s", __progname);
        flux_aux_set (h, "flux::log", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 13
0
static ctx_t *getctx (flux_t h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "flux::local_connector");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        if (!(ctx->clients = zlist_new ()))
            oom ();
        ctx->session_owner = geteuid ();
        flux_aux_set (h, "flux::local_connector", ctx, freectx);
    }

    return ctx;
}
Exemplo n.º 14
0
static ctx_t *getctx (flux_t h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "req");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        if (!(ctx->ping_requests = zhash_new ()))
            oom ();
        if (!(ctx->clog_requests = zlist_new ()))
            oom ();
        flux_aux_set (h, "req", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 15
0
static jscctx_t *getctx (flux_t h)
{
    jscctx_t *ctx = (jscctx_t *)flux_aux_get (h, "jstatctrl");
    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->active_jobs = zhash_new ()))
            oom ();
        if (!(ctx->callbacks = zlist_new ()))
            oom ();
        ctx->first_time = 1;
        ctx->h = h;
        flux_aux_set (h, "jstatctrl", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 16
0
static ctx_t *getctx (flux_t *h, bool exit_on_complete)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "simsrv");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        ctx->sim_state = new_simstate ();
        ctx->rdl_string = NULL;
        ctx->rdl_changed = false;
        ctx->exit_on_complete = exit_on_complete;
        flux_aux_set (h, "simsrv", ctx, freectx);
    }

    return ctx;
}
Exemplo n.º 17
0
static ctx_t *getctx (flux_t h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "barriersrv");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->barriers = zhash_new ()))
            oom ();
        if (flux_get_rank (h, &ctx->rank) < 0)
            err_exit ("flux_get_rank");
        ctx->h = h;
        flux_aux_set (h, "barriersrv", ctx, freectx);
    }

    return ctx;
}
Exemplo n.º 18
0
int exec_terminate_subprocesses_by_uuid (flux_t *h, const char *id)
{
    flux_subprocess_server_t *s = flux_aux_get (h, "flux::exec");

    if (!s) {
        flux_log (h, LOG_DEBUG, "no server_ctx found");
        return -1;
    }

    if (flux_subprocess_server_terminate_by_uuid (s, id) < 0) {
        flux_log_error (h, "flux_subprocess_server_terminate_by_uuid");
        return -1;
    }

    return 0;
}
Exemplo n.º 19
0
static ctx_t *getctx (flux_t *h)
{
    ctx_t *ctx = (ctx_t *)flux_aux_get (h, "sim_exec");

    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        ctx->h = h;
        ctx->sim_state = NULL;
        ctx->queued_events = zlist_new ();
        ctx->running_jobs = zlist_new ();
        ctx->prev_sim_time = 0;
        ctx->rdllib = rdllib_open ();
        ctx->rdl = NULL;
        flux_aux_set  (h, "sim_exec", ctx, freectx);
    }

    return ctx;
}
Exemplo n.º 20
0
static jscctx_t *getctx (flux_t *h)
{
    jscctx_t *ctx = (jscctx_t *)flux_aux_get (h, "jstatctrl");
    if (!ctx) {
        ctx = xzmalloc (sizeof (*ctx));
        if (!(ctx->active_jobs = zhash_new ()))
            oom ();
        if (!(ctx->kvs_paths = lru_cache_create (256)))
            oom ();
        lru_cache_set_free_f (ctx->kvs_paths, free);
        if (!(ctx->callbacks = zlist_new ()))
            oom ();
        ctx->first_time = 1;
        ctx->h = h;
        flux_aux_set (h, "jstatctrl", ctx, freectx);
    }
    return ctx;
}
Exemplo n.º 21
0
static struct dispatch *dispatch_get (flux_t h)
{
    struct dispatch *d = flux_aux_get (h, "flux::dispatch");
    if (!d) {
        flux_reactor_t *r = flux_get_reactor (h);
        d = xzmalloc (sizeof (*d));
        d->handlers = zlist_new ();
        d->waiters = zlist_new ();
        if (!d->handlers || !d->waiters)
            oom ();
        d->h = h;
        d->w = flux_handle_watcher_create (r, h, FLUX_POLLIN, handle_cb, d);
        if (!d->w)
            oom ();
        d->usecount = 1;
        flux_aux_set (h, "flux::dispatch", d, dispatch_destroy);
    }
    return d;
}
Exemplo n.º 22
0
static sqlite_ctx_t *getctx (flux_t *h)
{
    sqlite_ctx_t *ctx = (sqlite_ctx_t *)flux_aux_get (h, "flux::content-sqlite");
    const char *dir;
    const char *tmp;
    bool cleanup = false;

    if (!ctx) {
        if (!(ctx = calloc (1, sizeof (*ctx))))
            goto error;
        if (!(ctx->lzo_buf = calloc (1, lzo_buf_chunksize)))
            goto error;
        ctx->lzo_bufsize = lzo_buf_chunksize;
        ctx->h = h;
        if (!(ctx->hashfun = flux_attr_get (h, "content.hash"))) {
            flux_log_error (h, "content.hash");
            goto error;
        }
        if (!(tmp = flux_attr_get (h, "content.blob-size-limit"))) {
            flux_log_error (h, "content.blob-size-limit");
            goto error;
        }
        ctx->blob_size_limit = strtoul (tmp, NULL, 10);

        if (!(dir = flux_attr_get (h, "persist-directory"))) {
            if (!(dir = flux_attr_get (h, "broker.rundir"))) {
                flux_log_error (h, "broker.rundir");
                goto error;
            }
            cleanup = true;
        }
        if (asprintf (&ctx->dbdir, "%s/content", dir) < 0)
            goto error;
        if (mkdir (ctx->dbdir, 0755) < 0 && errno != EEXIST) {
            flux_log_error (h, "mkdir %s", ctx->dbdir);
            goto error;
        }
        if (cleanup)
            cleanup_push_string (cleanup_directory_recursive, ctx->dbdir);
        if (asprintf (&ctx->dbfile, "%s/sqlite", ctx->dbdir) < 0)
            goto error;

        if (sqlite3_open (ctx->dbfile, &ctx->db) != SQLITE_OK) {
            flux_log_error (h, "sqlite3_open %s", ctx->dbfile);
            goto error;
        }
        if (sqlite3_exec (ctx->db, "PRAGMA journal_mode=OFF",
                                            NULL, NULL, NULL) != SQLITE_OK
                || sqlite3_exec (ctx->db, "PRAGMA synchronous=OFF",
                                            NULL, NULL, NULL) != SQLITE_OK
                || sqlite3_exec (ctx->db, "PRAGMA locking_mode=EXCLUSIVE",
                                            NULL, NULL, NULL) != SQLITE_OK) {
            log_sqlite_error (ctx, "setting sqlite pragmas");
            goto error_sqlite;
        }
        if (sqlite3_exec (ctx->db, sql_create_table,
                                            NULL, NULL, NULL) != SQLITE_OK) {
            log_sqlite_error (ctx, "creating table");
            goto error_sqlite;
        }
        if (sqlite3_prepare_v2 (ctx->db, sql_load, -1, &ctx->load_stmt,
                                            NULL) != SQLITE_OK) {
            log_sqlite_error (ctx, "preparing load stmt");
            goto error_sqlite;
        }
        if (sqlite3_prepare_v2 (ctx->db, sql_store, -1, &ctx->store_stmt,
                                            NULL) != SQLITE_OK) {
            log_sqlite_error (ctx, "preparing store stmt");
            goto error_sqlite;
        }
        if (sqlite3_prepare_v2 (ctx->db, sql_dump, -1, &ctx->dump_stmt,
                                            NULL) != SQLITE_OK) {
            log_sqlite_error (ctx, "preparing dump stmt");
            goto error_sqlite;
        }
        if (flux_aux_set (h, "flux::content-sqlite", ctx, freectx) < 0)
            goto error;
    }
    return ctx;
error_sqlite:
    set_errno_from_sqlite_error (ctx);
error:
    freectx (ctx);
    return NULL;
}
Exemplo n.º 23
0
const char *flux_attr_next (flux_t *h)
{
    attr_ctx_t *ctx = flux_aux_get (h, "flux::attr");

    return ctx->names ? zlist_next (ctx->names) : NULL;
}