Exemple #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;
}
Exemple #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;
}
Exemple #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;
}
Exemple #4
0
int ping_initialize (flux_t *h, const char *service)
{
    struct flux_match match = FLUX_MATCH_ANY;
    struct ping_context *p = calloc (1, sizeof (*p));
    if (!p) {
        errno = ENOMEM;
        goto error;
    }
    match.typemask = FLUX_MSGTYPE_REQUEST;
    if (asprintf (&match.topic_glob, "%s.ping", service) < 0) {
        errno = ENOMEM;
        goto error;
    }
    if (!(p->mh = flux_msg_handler_create (h, match, ping_request_cb, p)))
        goto error;
    flux_msg_handler_allow_rolemask (p->mh, FLUX_ROLE_ALL);
    flux_msg_handler_start (p->mh);
    flux_aux_set (h, "flux::ping", p, ping_finalize);
    free (match.topic_glob);
    return 0;
error:
    free (match.topic_glob);
    if (p)
        ping_finalize (p);
    return -1;
}
Exemple #5
0
int heaptrace_initialize (flux_t *h)
{
    char *dummy = "hello";
    if (flux_msg_handler_addvec (h, htab, NULL, &handlers) < 0)
        return -1;
    flux_aux_set (h, "flux::heaptrace", dummy, heaptrace_finalize);
    return 0;
}
Exemple #6
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;
}
Exemple #7
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;
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #10
0
static attr_ctx_t *attr_ctx_new (flux_t *h)
{
    attr_ctx_t *ctx = calloc (1, sizeof (*ctx));
    if (!ctx || !(ctx->hash = zhash_new ())) {
        free (ctx);
        /* Ensure errno set properly, in case zhash_new doesn't do it */
        errno = ENOMEM;
        return NULL;
    }
    ctx->h = h;
    flux_aux_set (h, "flux::attr", ctx, freectx);
    return ctx;
}
Exemple #11
0
flux_t connector_init (const char *path, int flags)
{
    ctx_t *c = xzmalloc (sizeof (*c));
    c->magic = CTX_MAGIC;
    c->rank = 0;
    if (!(c->queue = msglist_create ((msglist_free_f)flux_msg_destroy)))
        goto error;
    c->h = flux_handle_create (c, &handle_ops, flags);
    /* Fake out flux_size() and flux_rank () for testing.
     */
    c->size = 1;
    flux_aux_set (c->h, "flux::size", &c->size, NULL);
    flux_aux_set (c->h, "flux::rank", &c->rank, NULL);
    return c->h;
error:
    if (c) {
        int saved_errno = errno;
        op_fini (c);
        errno = saved_errno;
    }
    return NULL;
}
Exemple #12
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;
}
Exemple #13
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;
}
Exemple #14
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;
}
Exemple #15
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;
}
Exemple #16
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;
}
Exemple #17
0
int exec_initialize (flux_t *h, uint32_t rank, attr_t *attrs)
{
    flux_subprocess_server_t *s = NULL;
    const char *local_uri;

    if (attr_get (attrs, "local-uri", &local_uri, NULL) < 0)
        goto cleanup;
    if (!(s = flux_subprocess_server_start (h, "cmb", local_uri, rank)))
        goto cleanup;
    flux_aux_set (h, "flux::exec", s, exec_finalize);
    return 0;
cleanup:
    flux_subprocess_server_stop (s);
    return -1;
}
Exemple #18
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;
}
Exemple #19
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;
}
Exemple #20
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;
}
Exemple #21
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;
}
Exemple #22
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;
}
Exemple #23
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;
}
Exemple #24
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;
}
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;
}