Skip to content

Commit

Permalink
jobtap: add flux_jobtap_jobspec_update_id_pack()
Browse files Browse the repository at this point in the history
Problem: There's no interface to update the jobspec of a job
outside of a jobtap callback for that job.

Add flux_jobtap_jobspec_update_id_pack(). This function just does
some nominal checks on the target job, then wraps event_post_pack().
  • Loading branch information
grondo committed Dec 10, 2024
1 parent 7cd6705 commit 4fcbc6f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/modules/job-manager/jobtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,61 @@ int flux_jobtap_event_post_pack (flux_plugin_t *p,
return rc;
}

int flux_jobtap_jobspec_update_id_pack (flux_plugin_t *p,
flux_jobid_t id,
const char *fmt,
...)
{
int rc = -1;
va_list ap;
struct jobtap *jobtap;
struct job *job;
json_error_t error;
json_t *update = NULL;

if (!p
|| !(jobtap = flux_plugin_aux_get (p, "flux::jobtap"))
|| !(job = jobtap_lookup_active_jobid (p, id))
|| job->state == FLUX_JOB_STATE_RUN
|| job->state == FLUX_JOB_STATE_CLEANUP
|| job->eventlog_readonly) {
errno = EINVAL;
return -1;
}

/* This interface is only appropriate from outside a jobtap callback,
* i.e. called asynchronously to update a job. If 'job' is equivalent
* to the current job at the top of the jobtap stack, return an error.
*/
if (job == current_job (jobtap)) {
errno = EINVAL;
return -1;
}

va_start (ap, fmt);
update = json_vpack_ex (&error, 0, fmt, ap);
va_end (ap);
if (!update) {
errno = EINVAL;
return -1;
}
if (!validate_jobspec_updates (update)) {
errno = EINVAL;
goto out;
}
/* XXX: should job.validate be called on these updates before posting?
*/
rc = event_job_post_pack (jobtap->ctx->event,
job,
"jobspec-update",
0,
"O",
update);
out:
ERRNO_SAFE_WRAP (json_decref, update);
return rc;
}

int flux_jobtap_jobspec_update_pack (flux_plugin_t *p, const char *fmt, ...)
{
int rc = -1;
Expand Down
13 changes: 13 additions & 0 deletions src/modules/job-manager/jobtap.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ int flux_jobtap_event_post_pack (flux_plugin_t *p,
*/
int flux_jobtap_jobspec_update_pack (flux_plugin_t *p, const char *fmt, ...);

/* Similar to flux_jobtap_jobspec_update_pack(), but asynchronously update
* a specific jobid. This version assumes the job is quiescent, so the event
* is applied immediately.
*
* Returns -1 with errno set to EINVAL for invalid arguments, if the job
* does not exist, if the target job is in RUN, CLEANUP or INACTIVE states,
* or if the function is called from a jobtap callback for the target job.
*/
int flux_jobtap_jobspec_update_id_pack (flux_plugin_t *p,
flux_jobid_t id,
const char *fmt,
...);

/* Return a flux_plugin_arg_t object for a job.
*
* The result can then be unpacked with flux_plugin_arg_unpack(3) to get
Expand Down

0 comments on commit 4fcbc6f

Please sign in to comment.