Skip to content

Commit aea9201

Browse files
committed
broker: add flub RPC methods to overlay
Problem: the flub bootstrap method requires broker services. Add the following services (instance owner only): overlay.flub-getinfo (rank 0 only) Allocate an unused rank from rank 0 and also return size and misc. broker attributes to be set in the new broker overlay.flub-kex (peer rank) Exchange public keys with the TBON parent and obtain its zeromq URI.
1 parent f1c303a commit aea9201

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

src/broker/boot_pmi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ int boot_pmi (struct overlay *overlay, attr_t *attrs)
278278
if (topology_set_rank (topo, info.rank) < 0
279279
|| overlay_set_topology (overlay, topo) < 0)
280280
goto error;
281+
if (info.rank == 0 && size > info.size) {
282+
if (overlay_flub_provision (overlay, info.size) < 0) {
283+
log_msg ("error provisioning flub allocator");
284+
goto error;
285+
}
286+
}
281287
if (gethostname (hostname, sizeof (hostname)) < 0) {
282288
log_err ("gethostname");
283289
goto error;

src/broker/overlay.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "src/common/librouter/rpc_track.h"
3434
#include "src/common/libccan/ccan/ptrint/ptrint.h"
3535
#include "src/common/libyuarel/yuarel.h"
36+
#include "ccan/array_size/array_size.h"
3637

3738
#include "overlay.h"
3839
#include "attr.h"
@@ -178,6 +179,7 @@ struct overlay {
178179
void *recv_arg;
179180

180181
struct flux_msglist *health_requests;
182+
struct idset *flub_rankpool;
181183
};
182184

183185
static void overlay_mcast_child (struct overlay *ov, const flux_msg_t *msg);
@@ -2061,11 +2063,140 @@ static int overlay_configure_topo (struct overlay *ov)
20612063
return 0;
20622064
}
20632065

2066+
static int overlay_flub_alloc (struct overlay *ov, int *rank)
2067+
{
2068+
unsigned int id;
2069+
2070+
if (ov->flub_rankpool) {
2071+
if ((id = idset_first (ov->flub_rankpool)) != IDSET_INVALID_ID) {
2072+
if (idset_clear (ov->flub_rankpool, id) < 0)
2073+
return -1;
2074+
*rank = (int)id;
2075+
return 0;
2076+
}
2077+
}
2078+
errno = ENOENT;
2079+
return -1;
2080+
}
2081+
2082+
int overlay_flub_provision (struct overlay *ov, int start_rank)
2083+
{
2084+
struct idset *ids;
2085+
2086+
if (!(ids = idset_create (ov->size, 0))
2087+
|| idset_range_set (ids, start_rank, ov->size - 1) < 0) {
2088+
idset_destroy (ids);
2089+
return -1;
2090+
}
2091+
idset_destroy (ov->flub_rankpool);
2092+
ov->flub_rankpool = ids;
2093+
return 0;
2094+
}
2095+
2096+
static json_t *flub_dict_create (attr_t *attrs)
2097+
{
2098+
const char *names[] = { "hostlist", "instance-level" };
2099+
json_t *dict;
2100+
2101+
if (!(dict = json_object ()))
2102+
goto nomem;
2103+
for (int i = 0; i < ARRAY_SIZE (names); i++) {
2104+
const char *val;
2105+
json_t *o;
2106+
if (attr_get (attrs, names[i], &val, NULL) < 0)
2107+
goto error;
2108+
if (!(o = json_string (val))
2109+
|| json_object_set_new (dict, names[i], o) < 0) {
2110+
json_decref (o);
2111+
goto nomem;
2112+
}
2113+
}
2114+
return dict;
2115+
nomem:
2116+
errno = ENOMEM;
2117+
error:
2118+
ERRNO_SAFE_WRAP (json_decref, dict);
2119+
return NULL;
2120+
}
2121+
2122+
static void overlay_flub_getinfo_cb (flux_t *h,
2123+
flux_msg_handler_t *mh,
2124+
const flux_msg_t *msg,
2125+
void *arg)
2126+
{
2127+
struct overlay *ov = arg;
2128+
const char *errmsg = NULL;
2129+
json_t *attrs = NULL;
2130+
int rank;
2131+
2132+
if (flux_request_unpack (msg, NULL, "{}") < 0)
2133+
goto error;
2134+
if (overlay_flub_alloc (ov, &rank) < 0) {
2135+
errmsg = "there are no available ranks";
2136+
goto error;
2137+
}
2138+
if (!(attrs = flub_dict_create (ov->attrs)))
2139+
goto error;
2140+
if (flux_respond_pack (h,
2141+
msg,
2142+
"{s:i s:i s:O}",
2143+
"rank", rank,
2144+
"size", ov->size,
2145+
"attrs", attrs) < 0)
2146+
flux_log_error (h, "error responding to overlay.flub-getinfo request");
2147+
json_decref (attrs);
2148+
return;
2149+
error:
2150+
if (flux_respond_error (h, msg, errno, errmsg) < 0)
2151+
flux_log_error (h, "error responding to overlay.flub-getinfo request");
2152+
json_decref (attrs);
2153+
}
2154+
2155+
static void overlay_flub_kex_cb (flux_t *h,
2156+
flux_msg_handler_t *mh,
2157+
const flux_msg_t *msg,
2158+
void *arg)
2159+
{
2160+
struct overlay *ov = arg;
2161+
const char *errmsg = NULL;
2162+
const char *name;
2163+
const char *pubkey;
2164+
2165+
if (flux_request_unpack (msg,
2166+
NULL,
2167+
"{s:s s:s}",
2168+
"name", &name,
2169+
"pubkey", &pubkey) < 0)
2170+
goto error;
2171+
if (ov->child_count == 0) {
2172+
errmsg = "this broker cannot have children";
2173+
errno = EINVAL;
2174+
goto error;
2175+
}
2176+
if (overlay_authorize (ov, name, pubkey) < 0) {
2177+
errmsg = "failed to authorize public key";
2178+
goto error;
2179+
}
2180+
if (flux_respond_pack (h,
2181+
msg,
2182+
"{s:s s:s s:s}",
2183+
"pubkey", overlay_cert_pubkey (ov),
2184+
"name", overlay_cert_name (ov),
2185+
"uri", overlay_get_bind_uri (ov)) < 0)
2186+
flux_log_error (h, "error responding to overlay.flub-kex request");
2187+
return;
2188+
error:
2189+
if (flux_respond_error (h, msg, errno, errmsg) < 0)
2190+
flux_log_error (h, "error responding to overlay.flub-kex request");
2191+
}
2192+
20642193
void overlay_destroy (struct overlay *ov)
20652194
{
20662195
if (ov) {
20672196
int saved_errno = errno;
20682197

2198+
idset_destroy (ov->flub_rankpool);
2199+
20692200
flux_msglist_destroy (ov->health_requests);
20702201

20712202
zcert_destroy (&ov->cert);
@@ -2109,6 +2240,18 @@ void overlay_destroy (struct overlay *ov)
21092240
}
21102241

21112242
static const struct flux_msg_handler_spec htab[] = {
2243+
{
2244+
FLUX_MSGTYPE_REQUEST,
2245+
"overlay.flub-kex",
2246+
overlay_flub_kex_cb,
2247+
0,
2248+
},
2249+
{
2250+
FLUX_MSGTYPE_REQUEST,
2251+
"overlay.flub-getinfo",
2252+
overlay_flub_getinfo_cb,
2253+
0,
2254+
},
21122255
{
21132256
FLUX_MSGTYPE_REQUEST,
21142257
"overlay.stats-get",

src/broker/overlay.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int overlay_set_monitor_cb (struct overlay *ov,
138138
overlay_monitor_f cb,
139139
void *arg);
140140

141+
int overlay_flub_provision (struct overlay *ov, int rank_start);
142+
141143
/* Register overlay-related broker attributes.
142144
*/
143145
int overlay_register_attrs (struct overlay *overlay);

0 commit comments

Comments
 (0)