Skip to content

Commit

Permalink
libsubprocess: drop bulk_exec_set_imp_path()
Browse files Browse the repository at this point in the history
Problem: bulk_exec_set_imp_path() and associated code no longer has
any users.

Remove it.

Update unit test.
  • Loading branch information
garlick committed Nov 6, 2024
1 parent 5f85b52 commit d985335
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 187 deletions.
182 changes: 4 additions & 178 deletions src/common/libsubprocess/bulk-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct bulk_exec {
char *service;
flux_jobid_t id;
char *name;
char *imp_path; /* Path to IMP. If set, use IMP for kill */

struct aux_item *aux;

Expand Down Expand Up @@ -504,7 +503,6 @@ void bulk_exec_destroy (struct bulk_exec *exec)
aux_destroy (&exec->aux);
free (exec->name);
free (exec->service);
free (exec->imp_path);
free (exec);
errno = saved_errno;
}
Expand Down Expand Up @@ -553,19 +551,6 @@ int bulk_exec_set_max_per_loop (struct bulk_exec *exec, int max)
return 0;
}

int bulk_exec_set_imp_path (struct bulk_exec *exec,
const char *imp_path)
{
if (!exec || !imp_path) {
errno = EINVAL;
return -1;
}
free (exec->imp_path);
if (!(exec->imp_path = strdup (imp_path)))
return -1;
return 0;
}

int bulk_exec_push_cmd (struct bulk_exec *exec,
const struct idset *ranks,
flux_cmd_t *cmd,
Expand Down Expand Up @@ -683,14 +668,14 @@ void bulk_exec_kill_log_error (flux_future_t *f, flux_jobid_t id)
}
}

static flux_future_t *bulk_exec_simple_kill (struct bulk_exec *exec,
const struct idset *ranks,
int signum)
flux_future_t *bulk_exec_kill (struct bulk_exec *exec,
const struct idset *ranks,
int signum)
{
flux_subprocess_t *p;
flux_future_t *cf;

if (!exec) {
if (!exec || signum < 0) {
errno = EINVAL;
return NULL;
}
Expand Down Expand Up @@ -738,165 +723,6 @@ static flux_future_t *bulk_exec_simple_kill (struct bulk_exec *exec,
return cf;
}

static void imp_kill_output (struct bulk_exec *kill,
flux_subprocess_t *p,
const char *stream,
const char *data,
int len,
void *arg)
{
int rank = flux_subprocess_rank (p);
flux_log (kill->h,
LOG_INFO,
"%s (rank %d): imp kill: %.*s",
flux_get_hostbyrank (kill->h, rank),
rank,
len,
data);
}

static void imp_kill_complete (struct bulk_exec *kill, void *arg)
{
flux_future_t *f = arg;
if (bulk_exec_rc (kill) < 0)
flux_future_fulfill_error (f, 0, NULL);
else
flux_future_fulfill (f, NULL, NULL);
}

static void imp_kill_error (struct bulk_exec *kill,
flux_subprocess_t *p,
void *arg)
{
int rank = flux_subprocess_rank (p);
flux_log_error (kill->h,
"imp kill on %s (rank %d) failed",
flux_get_hostbyrank (kill->h, rank),
rank);
}


struct bulk_exec_ops imp_kill_ops = {
.on_output = imp_kill_output,
.on_error = imp_kill_error,
.on_complete = imp_kill_complete,
};

static int bulk_exec_push_one (struct bulk_exec *exec,
int rank,
flux_cmd_t *cmd,
int flags)
{
int rc = -1;
struct idset *ids = idset_create (0, IDSET_FLAG_AUTOGROW);
if (!ids || idset_set (ids, rank) < 0)
return -1;
rc = bulk_exec_push_cmd (exec, ids, cmd, flags);
idset_destroy (ids);
return rc;
}

/* Kill all currently executing processes in bulk-exec object `exec`
* using "flux-imp kill" helper for processes potentially running
* under a different userid.
*
* Spawns "flux-imp kill <signal> <pid>" on each rank.
*/
flux_future_t *bulk_exec_imp_kill (struct bulk_exec *exec,
const char *imp_path,
const struct idset *ranks,
int signum)
{
struct bulk_exec *killcmd = NULL;
flux_subprocess_t *p = NULL;
flux_future_t *f = NULL;
int count = 0;

if (!exec || !imp_path) {
errno = EINVAL;
return NULL;
}

/* Empty future for return value
*/
if (!(f = flux_future_create (NULL, NULL))) {
flux_log_error (exec->h, "bulk_exec_imp_kill: future_create");
goto err;
}
flux_future_set_flux (f, exec->h);

if (!(killcmd = bulk_exec_create (&imp_kill_ops,
exec->service,
exec->id,
"imp-kill",
f)))
return NULL;

/* Tie bulk exec object destruction to future */
flux_future_aux_set (f, NULL, killcmd, (flux_free_f) bulk_exec_destroy);

p = zlist_first (exec->processes);
while (p) {
if ((!ranks || idset_test (ranks, flux_subprocess_rank (p)))
&& (flux_subprocess_state (p) == FLUX_SUBPROCESS_RUNNING
|| flux_subprocess_state (p) == FLUX_SUBPROCESS_INIT)) {

pid_t pid = flux_subprocess_pid (p);
int rank = flux_subprocess_rank (p);
flux_cmd_t *cmd = flux_cmd_create (0, NULL, environ);

if (!cmd
|| flux_cmd_argv_append (cmd, imp_path) < 0
|| flux_cmd_argv_append (cmd, "kill") < 0
|| flux_cmd_argv_appendf (cmd, "%d", signum) < 0
|| flux_cmd_argv_appendf (cmd, "%ld", (long) pid)) {
flux_log_error (exec->h,
"bulk_exec_imp_kill: flux_cmd_argv_append");
goto err;
}

if (bulk_exec_push_one (killcmd, rank, cmd, 0) < 0) {
flux_log_error (exec->h, "bulk_exec_imp_kill: push_cmd");
goto err;
}

count++;
flux_cmd_destroy (cmd);
}
p = zlist_next (exec->processes);
}

if (count == 0) {
errno = ENOENT;
goto err;
}

bulk_exec_aux_set (killcmd, "future", f, NULL);

if (bulk_exec_start (exec->h, killcmd) < 0) {
flux_log_error (exec->h, "bulk_exec_start");
goto err;
}

return f;
err:
flux_future_destroy (f);
return NULL;
}

flux_future_t *bulk_exec_kill (struct bulk_exec *exec,
const struct idset *ranks,
int signum)
{
if (!exec || signum < 0) {
errno = EINVAL;
return NULL;
}
if (exec->imp_path)
return bulk_exec_imp_kill (exec, exec->imp_path, ranks, signum);
return bulk_exec_simple_kill (exec, ranks, signum);
}

int bulk_exec_aux_set (struct bulk_exec *exec,
const char *key,
void *val,
Expand Down
5 changes: 0 additions & 5 deletions src/common/libsubprocess/bulk-exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ int bulk_exec_aux_set (struct bulk_exec *exec,
*/
int bulk_exec_set_max_per_loop (struct bulk_exec *exec, int max);

/* Set path to an IMP to use for bulk_exec_kill().
*/
int bulk_exec_set_imp_path (struct bulk_exec *exec,
const char *imp_path);

void bulk_exec_destroy (struct bulk_exec *exec);

int bulk_exec_push_cmd (struct bulk_exec *exec,
Expand Down
4 changes: 0 additions & 4 deletions src/common/libsubprocess/test/bulk-exec-einval.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,12 @@ int main (int argc, char *argv[])
"bulk_exec_aux_set (NULL, ..) returns EINVAL");
ok (bulk_exec_set_max_per_loop (NULL, 1) < 0 && errno == EINVAL,
"bulk_exec_set_max_per_loop (NULL, 1) returns EINVAL");
ok (bulk_exec_set_imp_path (NULL, NULL) < 0 && errno == EINVAL,
"bulk_exec_set_imp_path (NULL, NULL) returns EINVAL");
ok (bulk_exec_push_cmd (NULL, NULL, NULL, 0) < 0 && errno == EINVAL,
"bulk_exec_push_cmd (NULL, ...) returns EINVAL");
ok (bulk_exec_start (NULL, NULL) < 0 && errno == EINVAL,
"bulk_exec_start (NULL, NULL) returns EINVAL");
ok (bulk_exec_kill (NULL, NULL, 0) == NULL && errno == EINVAL,
"bulk_exec_kill (NULL, NULL, 0) returns EINVAL");
ok (bulk_exec_imp_kill (NULL, NULL, NULL, 0) == NULL && errno == EINVAL,
"bulk_exec_imp_kill (NULL, NULL, NULL, 0) returns EINVAL");
ok (bulk_exec_cancel (NULL) < 0 && errno == EINVAL,
"bulk_exec_cancel (NULL) returns EINVAL");
ok (bulk_exec_rc (NULL) < 0 && errno == EINVAL,
Expand Down

0 comments on commit d985335

Please sign in to comment.