Skip to content

Commit f7203c2

Browse files
committed
job-list: return nnodes if jobspec specifies nodes
Problem: job-list does not return nnodes until a job is running. When a job specifically requests a number of nodes, it may be useful for job-list to return nnodes so it can be listed in job listing tools such as flux-jobs. Solution: If the jobspec specifically lists nodes as a requested resource, have job-list return nnodes even before it is running. Fixes #4530
1 parent 91e53bf commit f7203c2

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/modules/job-list/job_state.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ static int jobspec_parse (struct list_ctx *ctx,
397397
json_error_t error;
398398
json_t *jobspec = NULL;
399399
json_t *tasks, *resources, *command, *jobspec_job = NULL;
400+
struct res_level res[3];
400401
int rc = -1;
401402

402403
if (!(jobspec = json_loads (s, 0, &error))) {
@@ -488,13 +489,33 @@ static int jobspec_parse (struct list_ctx *ctx,
488489
goto nonfatal_error;
489490
}
490491

492+
/* For jobspec version 1, expect either:
493+
* - node->slot->core->NIL
494+
* - slot->core->NIL
495+
*/
496+
memset (res, 0, sizeof (res));
497+
if (parse_res_level (ctx, job, resources, &res[0]) < 0)
498+
goto nonfatal_error;
499+
if (res[0].with && parse_res_level (ctx, job, res[0].with, &res[1]) < 0)
500+
goto nonfatal_error;
501+
if (res[1].with && parse_res_level (ctx, job, res[1].with, &res[2]) < 0)
502+
goto nonfatal_error;
503+
504+
/* Set job->nnodes if available. In jobspec version 1, only if
505+
* resources listed as node->slot->core->NIL
506+
*/
507+
if (res[0].type != NULL && !strcmp (res[0].type, "node")
508+
&& res[1].type != NULL && !strcmp (res[1].type, "slot")
509+
&& res[2].type != NULL && !strcmp (res[2].type, "core")
510+
&& res[2].with == NULL)
511+
job->nnodes = res[0].count;
512+
491513
/* Set job->ntasks
492514
*/
493515
if (json_unpack_ex (tasks, NULL, 0,
494516
"[{s:{s:i}}]",
495517
"count", "total", &job->ntasks) < 0) {
496518
int per_slot, slot_count = 0;
497-
struct res_level res[3];
498519

499520
if (json_unpack_ex (tasks, &error, 0,
500521
"[{s:{s:i}}]",
@@ -510,18 +531,6 @@ static int jobspec_parse (struct list_ctx *ctx,
510531
__FUNCTION__, (uintmax_t)job->id, per_slot);
511532
goto nonfatal_error;
512533
}
513-
/* For jobspec version 1, expect either:
514-
* - node->slot->core->NIL
515-
* - slot->core->NIL
516-
* Set job->slot_count.
517-
*/
518-
memset (res, 0, sizeof (res));
519-
if (parse_res_level (ctx, job, resources, &res[0]) < 0)
520-
goto nonfatal_error;
521-
if (res[0].with && parse_res_level (ctx, job, res[0].with, &res[1]) < 0)
522-
goto nonfatal_error;
523-
if (res[1].with && parse_res_level (ctx, job, res[1].with, &res[2]) < 0)
524-
goto nonfatal_error;
525534
if (res[0].type != NULL && !strcmp (res[0].type, "slot")
526535
&& res[1].type != NULL && !strcmp (res[1].type, "core")
527536
&& res[1].with == NULL) {

src/modules/job-list/job_util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ static int store_attr (struct job *job,
9191
val = json_integer (job->ntasks);
9292
}
9393
else if (!strcmp (attr, "nnodes")) {
94-
/* job->nnodes potentially < 0 if R invalid */
95-
if (!(job->states_mask & FLUX_JOB_STATE_RUN)
96-
|| job->nnodes < 0)
94+
/* job->nnodes < 0 if not set yet or R invalid, may be set in
95+
* DEPEND or RUN state */
96+
if (job->nnodes < 0)
9797
return 0;
9898
val = json_integer (job->nnodes);
9999
}

0 commit comments

Comments
 (0)