Example #1
0
static int internal_content_load (optparse_t *p, int ac, char *av[])
{
    int n;
    const char *blobref;
    uint8_t *data;
    int size;
    flux_t *h;
    flux_rpc_t *rpc;
    const char *topic;

    n = optparse_optind (p);
    if (n != ac - 1) {
        optparse_print_usage (p);
        exit (1);
    }
    blobref = av[n];
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (optparse_hasopt (p, "bypass-cache"))
        topic = "content-backing.load";
    else
        topic = "content.load";
    if (!(rpc = flux_rpc_raw (h, topic, blobref, strlen (blobref) + 1, 0, 0)))
        log_err_exit ("%s", topic);
    if (flux_rpc_get_raw (rpc, &data, &size) < 0)
        log_err_exit ("%s", topic);
    if (write_all (STDOUT_FILENO, data, size) < 0)
        log_err_exit ("write");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Example #2
0
static int cmd_setattr (optparse_t *p, int ac, char *av[])
{
    int n;
    const char *name = NULL, *val = NULL;
    flux_t h;

    log_init ("flux-setattr");

    n = optparse_optind (p);
    if (optparse_hasopt (p, "expunge") && n == ac - 1) {
        name = av[n];
    } else if (!optparse_hasopt (p, "expunge") && n == ac - 2) {
        name = av[n];
        val = av[n + 1];
    } else {
        optparse_print_usage (p);
        exit (1);
    }

    h = builtin_get_flux_handle (p);
    if (flux_attr_set (h, name, val) < 0)
        log_err_exit ("%s", av[1]);
    flux_close (h);
    return (0);
}
Example #3
0
static int internal_content_store (optparse_t *p, int ac, char *av[])
{
    const uint32_t blob_size_limit = 1048576; /* RFC 10 */
    uint8_t *data;
    int size;
    flux_t *h;
    flux_rpc_t *rpc;
    const char *topic;

    if (optparse_optind (p)  != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if ((size = read_all (STDIN_FILENO, &data)) < 0)
        log_err_exit ("read");
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (optparse_hasopt (p, "dry-run")) {
        int flags;
        const char *hashfun;

        if (size > blob_size_limit)
            log_errn_exit (EFBIG, "content-store");
        if (!(hashfun = flux_attr_get (h, "content-hash", &flags)))
            log_err_exit ("flux_attr_get content-hash");
        if (!strcmp (hashfun, "sha1")) {
            uint8_t hash[SHA1_DIGEST_SIZE];
            char hashstr[SHA1_STRING_SIZE];
            SHA1_CTX sha1_ctx;

            SHA1_Init (&sha1_ctx);
            SHA1_Update (&sha1_ctx, (uint8_t *)data, size);
            SHA1_Final (&sha1_ctx, hash);
            sha1_hashtostr (hash, hashstr);
            printf ("%s\n", hashstr);
        } else
            log_msg_exit ("content-store: unsupported hash function: %s", hashfun);
    } else {
        const char *blobref;
        int blobref_size;
        if (optparse_hasopt (p, "bypass-cache"))
            topic = "content-backing.store";
        else
            topic = "content.store";
        if (!(rpc = flux_rpc_raw (h, topic, data, size, 0, 0)))
            log_err_exit ("%s", topic);
        if (flux_rpc_get_raw (rpc, &blobref, &blobref_size) < 0)
            log_err_exit ("%s", topic);
        if (!blobref || blobref[blobref_size - 1] != '\0')
            log_msg_exit ("%s: protocol error", topic);
        printf ("%s\n", blobref);
        flux_rpc_destroy (rpc);
    }
    flux_close (h);
    free (data);
    return (0);
}
Example #4
0
/*
 * Gather concatenated hwloc xml topo file with resource-hwloc.topo RPC
 *  and save results until destroyed by hwloc_topo_destroy ().
 */
static struct hwloc_topo * hwloc_topo_create (optparse_t *p)
{
    const char *json_str;
    struct hwloc_topo *t = xzmalloc (sizeof (*t));

    if (!(t->h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");

    t->rpc = flux_rpc (t->h, "resource-hwloc.topo", NULL, 0, 0);
    if (!t->rpc || (flux_rpc_get (t->rpc, NULL, &json_str) < 0))
        log_err_exit ("flux_rpc");

    if (!(t->o = Jfromstr (json_str)) || !Jget_str (t->o, "topology", &t->topo))
        log_msg_exit ("failed to parse json topology");

    return (t);
}
Example #5
0
static int cmd_getattr (optparse_t *p, int ac, char *av[])
{
    flux_t h = NULL;
    const char *val;
    int n, flags;

    n = optparse_optind (p);
    if (n != ac - 1)
        optparse_fatal_usage (p, 1, NULL);

    h = builtin_get_flux_handle (p);
    if (!(val = flux_attr_get (h, av[n], &flags)))
        err_exit ("%s", av[n]);
    printf ("%s\n", val);
    flux_close (h);
    return (0);
}
Example #6
0
static int internal_heaptrace_stop (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc;

    if (optparse_optind (p) != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.heaptrace.stop", NULL, FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("cmb.heaptrace.stop");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Example #7
0
static int cmd_lsattr (optparse_t *p, int ac, char *av[])
{
    const char *name, *val;
    flux_t h;
    if (optparse_optind (p) != ac)
        optparse_fatal_usage (p, 1, NULL);
    h = builtin_get_flux_handle (p);
    name = flux_attr_first (h);
    while (name) {
        if (optparse_hasopt (p, "values")) {
            val = flux_attr_get (h, name, NULL);
            printf ("%-40s%s\n", name, val ? val : "-");
        } else {
            printf ("%s\n", name);
        }
        name = flux_attr_next (h);
    }
    flux_close (h);
    return (0);
}
Example #8
0
static int internal_content_dropcache (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc = NULL;
    const char *topic = "content.dropcache";

    if (optparse_optind (p) != ac) {
        optparse_print_usage (p);
        exit (1);
    }
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, topic, NULL, FLUX_NODEID_ANY, 0)))
        log_err_exit ("%s", topic);
    if (flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("%s", topic);
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}
Example #9
0
static int internal_hwloc_reload (optparse_t *p, int ac, char *av[])
{
    int n = optparse_optind (p);
    const char *default_nodeset = "all";
    const char *nodeset = optparse_get_str (p, "rank", default_nodeset);
    char *dirpath = NULL;
    flux_t h;

    if (!(h = builtin_get_flux_handle (p)))
        err_exit ("flux_open");
    if (av[n] && !(dirpath = realpath (av[n], NULL)))
        err_exit ("%s", av[n]);

    config_hwloc_paths (h, dirpath);
    request_hwloc_reload (h, nodeset);

    free (dirpath);
    flux_close (h);
    return (0);
}
Example #10
0
static int internal_content_spam (optparse_t *p, int ac, char *av[])
{
    int i, count;
    flux_rpc_t *rpc;
    flux_t *h;
    flux_reactor_t *r;
    char data[256];
    int size = 256;

    if (ac != 2 && ac != 3) {
        optparse_print_usage (p);
        exit (1);
    }
    count = strtoul (av[1], NULL, 10);
    if (ac == 3)
        spam_max_inflight = strtoul (av[2], NULL, 10);
    else
        spam_max_inflight = 1;

    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(r = flux_get_reactor (h)))
        log_err_exit ("flux_get_reactor");

    spam_cur_inflight = 0;
    i = 0;
    while (i < count || spam_cur_inflight > 0) {
        while (i < count && spam_cur_inflight < spam_max_inflight) {
            snprintf (data, size, "spam-o-matic pid=%d seq=%d", getpid(), i);
            if (!(rpc = flux_rpc_raw (h, "content.store", data, size, 0, 0)))
                log_err_exit ("content.store(%d)", i);
            if (flux_rpc_then (rpc, store_completion, r) < 0)
                log_err_exit ("flux_rpc_then(%d)", i);
            spam_cur_inflight++;
            i++;
        }
        if (flux_reactor_run (r, 0) < 0)
            log_err ("flux_reactor_run");
    }
    return (0);
}
Example #11
0
static int internal_heaptrace_dump (optparse_t *p, int ac, char *av[])
{
    flux_t *h;
    flux_rpc_t *rpc;
    json_object *in = Jnew ();

    if (optparse_optind (p) != ac - 1) {
        optparse_print_usage (p);
        exit (1);
    }
    Jadd_str (in, "reason", av[ac - 1]);
    if (!(h = builtin_get_flux_handle (p)))
        log_err_exit ("flux_open");
    if (!(rpc = flux_rpc (h, "cmb.heaptrace.dump", Jtostr (in),
                          FLUX_NODEID_ANY, 0))
            || flux_rpc_get (rpc, NULL) < 0)
        log_err_exit ("cmb.heaptrace.dump");
    flux_rpc_destroy (rpc);
    flux_close (h);
    return (0);
}