void send_ping (struct ping_ctx *ctx) { struct timespec t0; json_object *in = Jnew (); flux_rpc_t *rpc; struct ping_data *pdata = xzmalloc (sizeof (*pdata)); pdata->tstat = xzmalloc (sizeof (*(pdata->tstat))); pdata->seq = 0; pdata->route = NULL; pdata->rpc_count = 0; Jadd_int (in, "seq", ctx->send_count); monotime (&t0); Jadd_int64 (in, "time.tv_sec", t0.tv_sec); Jadd_int64 (in, "time.tv_nsec", t0.tv_nsec); Jadd_str (in, "pad", ctx->pad); if (ctx->rank) rpc = flux_rpc_multi (ctx->h, ctx->topic, Jtostr (in), ctx->rank, 0); else rpc = flux_rpc (ctx->h, ctx->topic, Jtostr (in), ctx->nodeid, 0); if (!rpc) log_err_exit ("flux_rpc"); flux_rpc_aux_set (rpc, pdata, ping_data_free); if (flux_rpc_then (rpc, ping_continuation, ctx) < 0) log_err_exit ("flux_rpc_then"); Jput (in); ctx->send_count++; }
static void request_hwloc_reload (flux_t h, const char *nodeset, const char *walk_topology) { flux_rpc_t *rpc; JSON o = NULL; const char *json_str = NULL; if ((o = hwloc_reload_json_create (walk_topology))) json_str = Jtostr (o); if (!(rpc = flux_rpc_multi (h, "resource-hwloc.reload", json_str, nodeset, 0))) log_err_exit ("flux_rpc_multi"); while (!flux_rpc_completed (rpc)) { const char *json_str; uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (rpc, &nodeid, &json_str) < 0) { if (nodeid == FLUX_NODEID_ANY) log_err ("flux_rpc_get"); else log_err ("rpc(%"PRIu32")", nodeid); } } flux_rpc_destroy (rpc); Jput (o); }
void mod_lsmod (flux_t h, opt_t opt) { char *service = "cmb"; if (opt.argc > 1) usage (); if (opt.argc == 1) service = opt.argv[0]; printf ("%-20s %6s %7s %4s %s\n", "Module", "Size", "Digest", "Idle", "Nodeset"); if (opt.direct) { zhash_t *mods = zhash_new (); if (!mods) oom (); char *topic = xasprintf ("%s.lsmod", service); flux_rpc_t *r = flux_rpc_multi (h, topic, NULL, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { const char *json_str; uint32_t nodeid; if (flux_rpc_get (r, &nodeid, &json_str) < 0) err_exit ("%s", topic); if (lsmod_hash_cb (nodeid, json_str, mods) < 0) err_exit ("%s[%u]", topic, nodeid); } flux_rpc_destroy (r); lsmod_map_hash (mods, lsmod_print_cb, NULL); zhash_destroy (&mods); free (topic); } else { if (flux_modctl_list (h, service, opt.nodeset, lsmod_print_cb, NULL) < 0) err_exit ("modctl_list"); } }
void mod_rmmod (flux_t h, opt_t opt) { char *modname = NULL; if (opt.argc != 1) usage (); modname = opt.argv[0]; if (opt.direct) { char *service = getservice (modname); char *topic = xasprintf ("%s.rmmod", service); char *json_str = flux_rmmod_json_encode (modname); assert (json_str != NULL); flux_rpc_t *r = flux_rpc_multi (h, topic, json_str, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (r, &nodeid, NULL) < 0) err ("%s[%d]", topic, nodeid == FLUX_NODEID_ANY ? -1 : nodeid); } flux_rpc_destroy (r); free (topic); free (service); free (json_str); } else { if (flux_modctl_unload (h, opt.nodeset, modname) < 0) err_exit ("%s", modname); } }
void mod_insmod (flux_t h, opt_t opt) { char *modpath = NULL; char *modname = NULL; if (opt.argc < 1) usage (); if (strchr (opt.argv[0], '/')) { if (!(modpath = realpath (opt.argv[0], NULL))) oom (); if (!(modname = flux_modname (modpath))) msg_exit ("%s", dlerror ()); } else { char *searchpath = getenv ("FLUX_MODULE_PATH"); if (!searchpath) searchpath = MODULE_PATH; modname = xstrdup (opt.argv[0]); if (!(modpath = flux_modfind (searchpath, modname))) msg_exit ("%s: not found in module search path", modname); } opt.argv++; opt.argc--; if (opt.direct) { char *service = getservice (modname); char *topic = xasprintf ("%s.insmod", service); char *json_str = flux_insmod_json_encode (modpath, opt.argc, opt.argv); assert (json_str != NULL); flux_rpc_t *r = flux_rpc_multi (h, topic, json_str, opt.nodeset, 0); if (!r) err_exit ("%s", topic); while (!flux_rpc_completed (r)) { uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (r, NULL, NULL) < 0) err_exit ("%s[%d]", topic, nodeid == FLUX_NODEID_ANY ? -1 : nodeid); } flux_rpc_destroy (r); free (topic); free (service); free (json_str); } else { if (flux_modctl_load (h, opt.nodeset, modpath, opt.argc, opt.argv) < 0) err_exit ("%s", modname); } if (modpath) free (modpath); if (modname) free (modname); }
static void request_hwloc_reload (flux_t h, const char *nodeset) { flux_rpc_t *rpc; if (!(rpc = flux_rpc_multi (h, "resource-hwloc.reload", NULL, nodeset, 0))) err_exit ("flux_rpc_multi"); while (!flux_rpc_completed (rpc)) { const char *json_str; uint32_t nodeid = FLUX_NODEID_ANY; if (flux_rpc_get (rpc, &nodeid, &json_str) < 0) { if (nodeid == FLUX_NODEID_ANY) err ("flux_rpc_get"); else err ("rpc(%"PRIu32")", nodeid); } } flux_rpc_destroy (rpc); }
int rpctest_begin_cb (flux_t h, int type, zmsg_t **zmsg, void *arg) { uint32_t nodeid; int i, errors; int old_count; flux_rpc_t *r; const char *json_str; errno = 0; ok (!(r = flux_rpc_multi (h, NULL, "foo", "all", 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL topic fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", NULL, 0)) && errno == EINVAL, "flux_rpc_multi [0] with NULL nodeset fails with EINVAL"); errno = 0; ok (!(r = flux_rpc_multi (h, "bar", "foo", "xyz", 0)) && errno == EINVAL, "flux_rpc_multi [0] with bad nodeset fails with EINVAL"); /* working no-payload RPC */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0] with no payload when none is expected works"); if (!r) BAIL_OUT ("can't continue without successful rpc call"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); ok (flux_rpc_get (r, NULL, NULL) == 0, "flux_rpc_get works"); ok (hello_count == old_count + 1, "rpc was called once"); flux_rpc_destroy (r); /* cause remote EPROTO (unexpected payload) - picked up in _get() */ ok ((r = flux_rpc_multi (h, "rpctest.hello", "foo", "all", 0)) != NULL, "flux_rpc_multi [0] with unexpected payload works, at first"); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errno = 0; ok (flux_rpc_get (r, NULL, NULL) < 0 && errno == EPROTO, "flux_rpc_get fails with EPROTO"); flux_rpc_destroy (r); /* fake that we have a larger session */ fake_size = 128; char s[16]; uint32_t size = 0; snprintf (s, sizeof (s), "%u", fake_size); flux_attr_fake (h, "size", s, FLUX_ATTRFLAG_IMMUTABLE); flux_get_size (h, &size); cmp_ok (size, "==", fake_size, "successfully faked flux_get_size() of %d", fake_size); /* repeat working no-payload RPC test (now with 128 nodes) */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "all", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", fake_size - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < fake_size; i++) if (flux_rpc_get (r, NULL, NULL) < 0) errors++; ok (errors == 0, "flux_rpc_get succeded %d times", fake_size); cmp_ok (hello_count - old_count, "==", fake_size, "rpc was called %d times", fake_size); flux_rpc_destroy (r); /* same with a subset */ old_count = hello_count; ok ((r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] with no payload when none is expected works", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) if (flux_rpc_get (r, &nodeid, NULL) < 0 || nodeid != i) errors++; ok (errors == 0, "flux_rpc_get succeded %d times, with correct nodeid map", 64); cmp_ok (hello_count - old_count, "==", 64, "rpc was called %d times", 64); flux_rpc_destroy (r); /* same with echo payload */ ok ((r = flux_rpc_multi (h, "rpctest.echo", "foo", "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); errors = 0; for (i = 0; i < 64; i++) { if (flux_rpc_get (r, NULL, &json_str) < 0 || !json_str || strcmp (json_str, "foo") != 0) errors++; } ok (errors == 0, "flux_rpc_get succeded %d times, with correct return payload", 64); flux_rpc_destroy (r); /* detect partial failure without mresponse */ nodeid_fake_error = 20; ok ((r = flux_rpc_multi (h, "rpctest.nodeid", NULL, "[0-63]", 0)) != NULL, "flux_rpc_multi [0-%d] ok", 64 - 1); ok (flux_rpc_check (r) == false, "flux_rpc_check says get would block"); for (i = 0; i < 64; i++) { if (flux_rpc_get (r, &nodeid, &json_str) < 0) break; } ok (i == 20 && errno == EPERM, "flux_rpc_get correctly reports single error"); flux_rpc_destroy (r); /* test _then (still at fake session size of 128) */ ok ((then_r = flux_rpc_multi (h, "rpctest.hello", NULL, "[0-127]", 0)) != NULL, "flux_rpc_multi [0-127] ok"); ok (flux_rpc_then (then_r, then_cb, h) == 0, "flux_rpc_then works"); /* then_cb stops reactor; results reported, then_r destroyed in main() */ return 0; }