Skip to content

Commit 9e3a706

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 c0fbbb5 commit 9e3a706

File tree

3 files changed

+157
-0
lines changed

3 files changed

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

2200+
idset_destroy (ov->flub_rankpool);
2201+
20692202
flux_msglist_destroy (ov->health_requests);
20702203

20712204
zcert_destroy (&ov->cert);
@@ -2109,6 +2242,18 @@ void overlay_destroy (struct overlay *ov)
21092242
}
21102243

21112244
static const struct flux_msg_handler_spec htab[] = {
2245+
{
2246+
FLUX_MSGTYPE_REQUEST,
2247+
"overlay.flub-kex",
2248+
overlay_flub_kex_cb,
2249+
0,
2250+
},
2251+
{
2252+
FLUX_MSGTYPE_REQUEST,
2253+
"overlay.flub-getinfo",
2254+
overlay_flub_getinfo_cb,
2255+
0,
2256+
},
21122257
{
21132258
FLUX_MSGTYPE_REQUEST,
21142259
"overlay.stats-get",

src/broker/overlay.h

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

141+
/* Make a range of ranks available for flub bootstrap
142+
*/
143+
int overlay_flub_provision (struct overlay *ov,
144+
uint32_t lo_rank,
145+
uint32_t hi_rank);
146+
141147
/* Register overlay-related broker attributes.
142148
*/
143149
int overlay_register_attrs (struct overlay *overlay);

0 commit comments

Comments
 (0)