Skip to content

Commit 7b8b17e

Browse files
garlickmergify-bot
authored andcommitted
flux-resource: direct status to rank 0
Problem: if flux resource status is invoked on a rank other than zero, a segfault occurs. Explicitly set nodeid=0 in the command's resource.status RPC call. In additon, check the rank in the resource module's request handler and return an error response if invoked on a rank other than zero, rather than segfault. Add tests. Fixes #3484
1 parent c966a33 commit 7b8b17e

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/cmd/flux-resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def status(args):
274274
if args.from_stdin:
275275
resp = sys.stdin.read()
276276
else:
277-
resp = RPC(flux.Flux(), "resource.status").get()
277+
resp = RPC(flux.Flux(), "resource.status", nodeid=0).get()
278278

279279
rstat = ResourceStatus.from_status_response(resp, fmt)
280280

src/modules/resource/resource.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,18 @@ static void status_cb (flux_t *h,
156156
void *arg)
157157
{
158158
struct resource_ctx *ctx = arg;
159-
const struct idset *online = monitor_get_up (ctx->monitor);
160-
const struct idset *offline = monitor_get_down (ctx->monitor);
161-
const struct idset *exclude = exclude_get (ctx->exclude);
162159
json_t *drain;
163160
const json_t *R;
164161
json_t *o = NULL;
162+
const char *errstr = NULL;
165163

166164
if (flux_request_decode (msg, NULL, NULL) < 0)
167165
goto error;
166+
if (ctx->rank != 0) {
167+
errno = EPROTO;
168+
errstr = "this RPC only works on rank 0";
169+
goto error;
170+
}
168171
if (!(R = inventory_get (ctx->inventory)))
169172
goto error;
170173
if (!(drain = drain_get_info (ctx->drain)))
@@ -174,19 +177,25 @@ static void status_cb (flux_t *h,
174177
errno = ENOMEM;
175178
goto error;
176179
}
177-
if (rutil_set_json_idset (o, "online", online) < 0)
180+
if (rutil_set_json_idset (o,
181+
"online",
182+
monitor_get_up (ctx->monitor)) < 0)
178183
goto error;
179-
if (rutil_set_json_idset (o, "offline", offline) < 0)
184+
if (rutil_set_json_idset (o,
185+
"offline",
186+
monitor_get_down (ctx->monitor)) < 0)
180187
goto error;
181-
if (rutil_set_json_idset (o, "exclude", exclude) < 0)
188+
if (rutil_set_json_idset (o,
189+
"exclude",
190+
exclude_get (ctx->exclude)) < 0)
182191
goto error;
183192
if (flux_respond_pack (h, msg, "o", o) < 0) {
184193
flux_log_error (h, "error responding to resource.status request");
185194
json_decref (o);
186195
}
187196
return;
188197
error:
189-
if (flux_respond_error (h, msg, errno, NULL) < 0)
198+
if (flux_respond_error (h, msg, errno, errstr) < 0)
190199
flux_log_error (h, "error responding to resource.status request");
191200
json_decref (o);
192201
}

t/t2310-resource-module.t

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ test_expect_success 'resource.get-xml blocks until all ranks are up' '
195195
flux python ${SHARNESS_TEST_SRCDIR}/resource/get-xml-test.py
196196
'
197197

198+
test_expect_success 'flux resource status works on rank > 0' '
199+
flux exec -r 1 flux resource status
200+
'
201+
202+
status_onrank() {
203+
flux python -c "import flux; print(flux.Flux().rpc(\"resource.status\",nodeid=$1).get())"
204+
}
205+
206+
test_expect_success 'resource.status RPC fails on rank > 0' '
207+
test_must_fail status_onrank 1 2>status.err &&
208+
grep "only works on rank 0" status.err
209+
'
210+
198211
test_expect_success 'unload resource module' '
199212
flux exec -r all flux module remove resource
200213
'

0 commit comments

Comments
 (0)