From 47e83dece438a8173b782542a8d1d350d43d2f90 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Tue, 26 Sep 2023 15:43:33 -0700 Subject: [PATCH] job-list: split up R parsing function Problem: In the near future, R may be updated and may need to be parsed multiple times. R parsing code sits in a function that is called only when R is initially loaded. Split R parsing into two functions, one for loading R and one for parsing R. That way parsing R can be done multiple times without the additional call to json_loads(). --- src/modules/job-list/job_data.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/modules/job-list/job_data.c b/src/modules/job-list/job_data.c index 1222e68a62b7..1bb2227cb38a 100644 --- a/src/modules/job-list/job_data.c +++ b/src/modules/job-list/job_data.c @@ -385,7 +385,20 @@ int job_parse_jobspec_fatal (struct job *job, const char *s, json_t *updates) return job_jobspec_update (job, updates); } -static int parse_R (struct job *job, const char *s, bool allow_nonfatal) +static int load_R (struct job *job, const char *s, bool allow_nonfatal) +{ + json_error_t error; + + if (!(job->R = json_loads (s, 0, &error))) { + flux_log (job->h, LOG_ERR, + "%s: job %s invalid R: %s", + __FUNCTION__, idf58 (job->id), error.text); + return allow_nonfatal ? 0 : -1; + } + return 0; +} + +static int parse_R (struct job *job, bool allow_nonfatal) { struct rlist *rl = NULL; struct idset *idset = NULL; @@ -396,13 +409,6 @@ static int parse_R (struct job *job, const char *s, bool allow_nonfatal) struct rnode *rnode; int saved_errno, rc = -1; - if (!(job->R = json_loads (s, 0, &error))) { - flux_log (job->h, LOG_ERR, - "%s: job %s invalid R: %s", - __FUNCTION__, idf58 (job->id), error.text); - goto nonfatal_error; - } - if (!(rl = rlist_from_json (job->R, &error))) { flux_log_error (job->h, "rlist_from_json: %s", error.text); goto nonfatal_error; @@ -456,12 +462,16 @@ static int parse_R (struct job *job, const char *s, bool allow_nonfatal) int job_parse_R (struct job *job, const char *s) { - return parse_R (job, s, true); + if (load_R (job, s, true) < 0) + return -1; + return parse_R (job, true); } int job_parse_R_fatal (struct job *job, const char *s) { - return parse_R (job, s, false); + if (load_R (job, s, false) < 0) + return -1; + return parse_R (job, false); } int job_jobspec_update (struct job *job, json_t *updates)