reformat code and job array

This commit is contained in:
Rongsong Shen 2025-11-07 16:14:27 +08:00
parent a665ccd4fe
commit 9ff857db9f
64 changed files with 1497 additions and 2476 deletions

View file

@ -117,12 +117,10 @@ static command_t top_commands[] = {
{ (char*)NULL, (cmd_func_t)NULL, (char*)NULL }
};
static command_ctx_t topctx = {
.parent = NULL,
.prompt = "xce",
.settings = settings,
.commands = top_commands
};
static command_ctx_t topctx = { .parent = NULL,
.prompt = "xce",
.settings = settings,
.commands = top_commands };
static command_t worker_commands[] = {
{ "..", cmd_up, "Goto upper context" },
@ -134,12 +132,10 @@ static command_t worker_commands[] = {
{ (char*)NULL, (cmd_func_t)NULL, (char*)NULL }
};
static command_ctx_t workerctx = {
.parent = &topctx,
.prompt = "worker",
.settings = settings,
.commands = worker_commands
};
static command_ctx_t workerctx = { .parent = &topctx,
.prompt = "worker",
.settings = settings,
.commands = worker_commands };
static command_t client_commands[] = {
{ "..", cmd_up, "Goto upper context" },
@ -160,12 +156,10 @@ static command_t client_commands[] = {
{ (char*)NULL, (cmd_func_t)NULL, (char*)NULL }
};
static command_ctx_t clientctx = {
.parent = &topctx,
.prompt = "client",
.settings = settings,
.commands = client_commands
};
static command_ctx_t clientctx = { .parent = &topctx,
.prompt = "client",
.settings = settings,
.commands = client_commands };
static command_t scheduler_commands[] = {
{ "..", cmd_up, "Goto upper context" },
@ -176,12 +170,10 @@ static command_t scheduler_commands[] = {
{ (char*)NULL, (cmd_func_t)NULL, (char*)NULL }
};
static command_ctx_t schedulerctx = {
.parent = &topctx,
.prompt = "scheduler",
.settings = settings,
.commands = scheduler_commands
};
static command_ctx_t schedulerctx = { .parent = &topctx,
.prompt = "scheduler",
.settings = settings,
.commands = scheduler_commands };
static command_ctx_t* active_ctx = &topctx;
@ -191,7 +183,8 @@ static int break_out = 0;
static char doc[] = "xce_test";
static char args_doc[] = "";
const char* argp_program_version = MK_VERSION("xce v0.0.1-", STR(VERSION_COMMIT_ID));
const char* argp_program_version
= MK_VERSION("xce v0.0.1-", STR(VERSION_COMMIT_ID));
const char* argp_program_bug_address = BUG_EMAIL;
struct arguments {
@ -203,9 +196,7 @@ static struct argp_option options[] = {
{ 0 }
};
static error_t parse_opt(int key,
char* arg,
struct argp_state* state)
static error_t parse_opt(int key, char* arg, struct argp_state* state)
{
struct arguments* arguments = state->input;
@ -220,12 +211,7 @@ static error_t parse_opt(int key,
return 0;
}
static struct argp argp = {
options,
parse_opt,
args_doc,
doc
};
static struct argp argp = { options, parse_opt, args_doc, doc };
static char* verbose_to_loglevel(int verbose)
{
@ -251,10 +237,7 @@ static char* verbose_to_loglevel(int verbose)
return loglevel;
}
void sigbreak(int signo)
{
break_out = 1;
}
void sigbreak(int signo) { break_out = 1; }
static char* get_setting(char* key)
{
@ -272,8 +255,7 @@ static char* get_setting(char* key)
return active_ctx->settings[i].defval;
}
printf("Key `%s' is not in settings\n",
key);
printf("Key `%s' is not in settings\n", key);
return NULL;
}
@ -312,8 +294,7 @@ int leave_ctx(command_ctx_t* ctx)
return 0;
}
static int fill_prompt(command_ctx_t* ctx,
char* buf)
static int fill_prompt(command_ctx_t* ctx, char* buf)
{
if (ctx->parent != NULL) {
fill_prompt(ctx->parent, buf);
@ -360,8 +341,7 @@ int execute_line(char* line)
command = find_command(argv[0]);
if (!command) {
fprintf(stderr, "%s: No such command for xce test.\n",
argv[0]);
fprintf(stderr, "%s: No such command for xce test.\n", argv[0]);
free_argv(argv, argc);
return (-1);
}
@ -382,8 +362,7 @@ int cmd_help(int argc, char* argv[])
for (i = 0; active_ctx->commands[i].name != NULL; i++) {
if (strcmp(argv[1], active_ctx->commands[i].name) == 0) {
printf("%s\t\t%s.\n",
active_ctx->commands[i].name,
printf("%s\t\t%s.\n", active_ctx->commands[i].name,
active_ctx->commands[i].doc);
return 0;
}
@ -394,8 +373,7 @@ int cmd_help(int argc, char* argv[])
}
for (i = 0; active_ctx->commands[i].name != NULL; i++) {
printf("\t%-12s\t%s\n",
active_ctx->commands[i].name,
printf("\t%-12s\t%s\n", active_ctx->commands[i].name,
active_ctx->commands[i].doc);
}
@ -485,7 +463,7 @@ int cmd_quit(int argc, char* argv[])
int cmd_hello(int argc, char* argv[])
{
int rc;
int rc = 0;
int opt;
char* msg = "Greeting from xce client";
int count = 1;
@ -542,15 +520,11 @@ int cmd_reslist(int argc, char* argv[])
return rc;
}
printf("%10s%10s%10s%64s\n",
"Name", "Flags",
"Interval", "Description");
printf("%10s%10s%10s%64s\n", "Name", "Flags", "Interval", "Description");
for (i = 0; i < rc; i++) {
printf("%10s%10x%10d%64s\n",
res[i]->name,
res[i]->flags, res[i]->interval,
res[i]->desc);
printf("%10s%10x%10d%64s\n", res[i]->name, res[i]->flags,
res[i]->interval, res[i]->desc);
}
free(res);
@ -588,23 +562,17 @@ int cmd_workerlist(int argc, char* argv[])
return rc;
}
printf("%-20s%-8s%-15s%-15s%12s%12s%12s%12s%12s%12s\n",
"HostName", "Status", "HostType", "HostModel",
"CPUfactor", "MaxCPU", "MaxMem",
printf("%-20s%-8s%-15s%-15s%12s%12s%12s%12s%12s%12s\n", "HostName",
"Status", "HostType", "HostModel", "CPUfactor", "MaxCPU", "MaxMem",
"MaxSwap", "MaxTmp", "NDisks");
for (i = 0; i < rc; i++) {
printf("%-20s%-8s%-15s%-15s%12f%12d%12f%12f%12f%12d\n",
workers[i]->name,
worker_status_str(workers[i]->status),
workers[i]->attrs->hosttype,
workers[i]->attrs->hostmodel,
workers[i]->attrs->cpufactor,
workers[i]->attrs->maxcpus,
workers[i]->attrs->maxmem,
workers[i]->attrs->maxswap,
workers[i]->attrs->maxtmp,
workers[i]->attrs->ndisks);
workers[i]->name, worker_status_str(workers[i]->status),
workers[i]->attrs->hosttype, workers[i]->attrs->hostmodel,
workers[i]->attrs->cpufactor, workers[i]->attrs->maxcpus,
workers[i]->attrs->maxmem, workers[i]->attrs->maxswap,
workers[i]->attrs->maxtmp, workers[i]->attrs->ndisks);
}
free(workers);
@ -651,23 +619,16 @@ int cmd_joblist(int argc, char* argv[])
return rc;
}
printf("%-16s%-10s%-10s%-8s%-16s%-16s%-16s%10s%30s\n",
"JobId", "User", "Queue", "State",
"SubmitTime", "StartTime", "FinishTime",
"NTasks", "Command");
printf("%-16s%-10s%-10s%-8s%-16s%-16s%-16s%10s%30s\n", "JobId", "User",
"Queue", "State", "SubmitTime", "StartTime", "FinishTime", "NTasks",
"Command");
for (i = 0; i < rc; i++) {
printf("%-16ld%-10s%-10s%-8s%-16ld%-16ld%-16ld%4d,%-5d%30s\n",
jobs[i]->jobid,
jobs[i]->user,
jobs[i]->queue,
job_state_str(jobs[i]->state),
jobs[i]->queue_time,
jobs[i]->start_time,
jobs[i]->finish_time,
jobs[i]->mintasks,
jobs[i]->maxtasks,
jobs[i]->start_info->cmdline);
jobs[i]->jobid, jobs[i]->user, jobs[i]->queue,
job_state_str(jobs[i]->state), jobs[i]->queue_time,
jobs[i]->start_time, jobs[i]->finish_time, jobs[i]->mintasks,
jobs[i]->maxtasks, jobs[i]->start_info->cmdline);
}
free(jobs);
@ -675,9 +636,8 @@ int cmd_joblist(int argc, char* argv[])
return 0;
}
static int fill_job_alloc(xce_job_alloc_t* jalloc,
int nhosts,
host_task_t* hosts)
static int fill_job_alloc(xce_job_alloc_t* jalloc, int nhosts,
host_task_t* hosts)
{
xce_host_alloc_t** halloc = NULL;
int i;
@ -722,13 +682,11 @@ int cmd_jobrun(int argc, char* argv[])
{
int rc;
int opt;
uint64_t jobid;
uint64_t jobid = 0;
host_task_t hosts[MAX_TASK_HOSTS];
xce_job_alloc_t jalloc;
xce_job_dispatch_t jdispatch = {
.njobs = 1,
.allocs = (xce_job_alloc_t*[]) { &jalloc }
};
xce_job_dispatch_t jdispatch
= { .njobs = 1, .allocs = (xce_job_alloc_t*[]) { &jalloc } };
int nhosts = 0;
char* host;
int count;
@ -739,7 +697,8 @@ int cmd_jobrun(int argc, char* argv[])
switch (opt) {
case 'm':
if (nhosts >= MAX_TASK_HOSTS) {
fprintf(stderr, "too many run hosts, we only support max %d hosts\n",
fprintf(stderr,
"too many run hosts, we only support max %d hosts\n",
MAX_TASK_HOSTS);
return -1;
}
@ -765,10 +724,19 @@ int cmd_jobrun(int argc, char* argv[])
break;
case 'j':
jobid = atol(optarg);
if (jobid == 0) {
printf("you need to specify a positive jobid with -j");
return -1;
}
break;
}
}
if (jobid == 0) {
printf("no jobid specified");
return -1;
}
fill_job_alloc(&jalloc, nhosts, &hosts[0]);
jalloc.jobid = jobid;
@ -828,7 +796,8 @@ int cmd_jobsub(int argc, char* argv[])
min = atoi(buf);
if (max == 0) {
printf("Incorrect setting of max tasks count, set to same as min task value\n");
printf("Incorrect setting of max tasks count, set to same "
"as min task value\n");
max = min;
}
} else {
@ -837,7 +806,8 @@ int cmd_jobsub(int argc, char* argv[])
}
break;
default:
printf("jobsub -u <user> -q <queue> -R <resreq> -c <command line>\n");
printf(
"jobsub -u <user> -q <queue> -R <resreq> -c <command line>\n");
return -EINVAL;
}
}
@ -913,16 +883,15 @@ int cmd_resval(int argc, char* argv[])
}
}
rc = xcecli_resval(active_ctx->ctx, host,
res, &vals);
rc = xcecli_resval(active_ctx->ctx, host, res, &vals);
if (rc > 0) {
int i;
for (i = 0; i < rc; i++) {
xce_resval_t* val = vals[i];
printf("resource %s@%s:\n",
val->name, (val->host == NULL) ? "cluster" : val->host);
printf("resource %s@%s:\n", val->name,
(val->host == NULL) ? "cluster" : val->host);
printf("value: ");
switch (val->val->which) {
case Value_u_svalue:
@ -932,8 +901,7 @@ int cmd_resval(int argc, char* argv[])
printf("%f\n", val->val->u.fvalue);
break;
case Value_u_bvalue:
printf("%s\n",
(val->val->u.bvalue == 0) ? "false" : "true");
printf("%s\n", (val->val->u.bvalue == 0) ? "false" : "true");
break;
default:
printf(" <unknown type>\n");
@ -1107,7 +1075,7 @@ int cmd_qctrl(int argc, char* argv[])
int cmd_runtasks(int argc, char* argv[])
{
xce_taskhost_t hosts[MAX_TASK_HOSTS];
int nhosts = 0;
size_t nhosts = 0;
xce_taskrun_t taskrun;
int opt;
int rc;
@ -1128,7 +1096,8 @@ int cmd_runtasks(int argc, char* argv[])
switch (opt) {
case 'm':
if (nhosts >= MAX_TASK_HOSTS) {
fprintf(stderr, "too many run hosts, just support %d run hosts\n",
fprintf(stderr,
"too many run hosts, just support %d run hosts\n",
MAX_TASK_HOSTS);
return -1;
}
@ -1203,7 +1172,8 @@ int cmd_runtasks(int argc, char* argv[])
}
}
taskrun.taskhosts = (xce_taskhost_t**)calloc(nhosts, sizeof(xce_taskhost_t*));
taskrun.taskhosts
= (xce_taskhost_t**)calloc(nhosts, sizeof(xce_taskhost_t*));
taskrun.clientidx = -1;
if (taskrun.taskhosts != NULL) {
@ -1233,14 +1203,12 @@ int cmd_join_worker(int argc, char* argv[])
int rc;
int role;
int opt;
hostattrs_t attrs = {
.cpufactor = 1.0,
.maxcpus = 4,
.maxmem = 64,
.maxswap = 1024,
.maxtmp = 2048,
.ndisks = 1
};
hostattrs_t attrs = { .cpufactor = 1.0,
.maxcpus = 4,
.maxmem = 64,
.maxswap = 1024,
.maxtmp = 2048,
.ndisks = 1 };
role = HostRole_worker;
@ -1270,7 +1238,8 @@ int cmd_join_worker(int argc, char* argv[])
attrs.ndisks = atoi(optarg);
break;
default:
printf(" join [-f cpufactor] [-c maxcpus] [-m maxmem] [-s maxswap] [-t maxtmp] [-d ndisks]\n");
printf(" join [-f cpufactor] [-c maxcpus] [-m maxmem] [-s maxswap] "
"[-t maxtmp] [-d ndisks]\n");
return -EINVAL;
}
}
@ -1330,10 +1299,7 @@ int cmd_jobfinish(int argc, char* argv[])
return 0;
}
static int set_resval(xce_resval_t* vals,
int idx,
char* name,
char* val)
static int set_resval(xce_resval_t* vals, int idx, char* name, char* val)
{
static struct {
char* name;
@ -1433,10 +1399,10 @@ int cmd_resupdate(int argc, char* argv[])
switch (opt) {
case 'n':
if (resname != NULL) {
printf("res `%s' has no value specified, default will be used\n",
resname);
rc = set_resval(vals, nres,
resname, NULL);
printf(
"res `%s' has no value specified, default will be used\n",
resname);
rc = set_resval(vals, nres, resname, NULL);
if (rc >= 0) {
valptrs[nres] = &vals[nres];
nres++;
@ -1448,23 +1414,20 @@ int cmd_resupdate(int argc, char* argv[])
break;
case 'v':
if (resname != NULL) {
rc = set_resval(vals, nres,
resname, optarg);
rc = set_resval(vals, nres, resname, optarg);
if (rc >= 0) {
valptrs[nres] = &vals[nres];
nres++;
}
resname = NULL;
} else {
printf("ignore res value `%s' as no res name found\n",
optarg);
printf("ignore res value `%s' as no res name found\n", optarg);
}
break;
}
}
rc = xcecli_update_resvals(active_ctx->ctx,
nres, &valptrs[0]);
rc = xcecli_update_resvals(active_ctx->ctx, nres, &valptrs[0]);
if (rc >= 0) {
printf("resource update ok!\n");
} else {
@ -1496,10 +1459,8 @@ static int print_reslist(xce_reslist_t reslist)
for (i = 0; i < reslist.count; i++) {
printf("name: %s\nflags: %d\ninterval: %d\ndesc: %s\n\n",
reslist.res[i]->name,
reslist.res[i]->flags,
reslist.res[i]->interval,
reslist.res[i]->desc);
reslist.res[i]->name, reslist.res[i]->flags,
reslist.res[i]->interval, reslist.res[i]->desc);
}
return 0;
}
@ -1509,10 +1470,8 @@ static int print_queuelist(xce_queuelist_t qlist)
int i;
for (i = 0; i < qlist.count; i++) {
printf("name: %s\nstatus: %d\npriority: %d\n\n",
qlist.queues[i]->queue,
qlist.queues[i]->status,
qlist.queues[i]->priority);
printf("name: %s\nstatus: %d\npriority: %d\n\n", qlist.queues[i]->queue,
qlist.queues[i]->status, qlist.queues[i]->priority);
}
return 0;
}
@ -1522,22 +1481,15 @@ static int print_workerlist(xce_workerlist_t wlist)
int i;
for (i = 0; i < wlist.count; i++) {
printf("name: %s\nstatus: %d\n\n",
wlist.workers[i]->name,
printf("name: %s\nstatus: %d\n\n", wlist.workers[i]->name,
wlist.workers[i]->status);
}
return 0;
}
static int print_grouplist(xce_grouplist_t glist)
{
return 0;
}
static int print_grouplist(xce_grouplist_t glist) { return 0; }
static int print_configlist(xce_configlist_t clist)
{
return 0;
}
static int print_configlist(xce_configlist_t clist) { return 0; }
int cmd_getconf(int argc, char* argv[])
{
@ -1583,8 +1535,7 @@ int cmd_set(int argc, char* argv[])
if (argc == 1) {
for (i = 0; active_ctx->settings[i].key; i++) {
printf("%-12s:%s default: %s\n",
active_ctx->settings[i].key,
printf("%-12s:%s default: %s\n", active_ctx->settings[i].key,
KVAL(active_ctx->settings[i].value),
KVAL(active_ctx->settings[i].defval));
}
@ -1664,26 +1615,21 @@ static int get_avail_run_task_slots()
return -1;
}
static int sched_on_jobs(int njobs,
xce_job_t** jobs)
static int sched_on_jobs(int njobs, xce_job_t** jobs)
{
printf("%s %d jobs gotten\n",
__func__, njobs);
printf("%s %d jobs gotten\n", __func__, njobs);
return 0;
}
static int sched_on_workers(int nworkers,
xce_worker_t** workers)
static int sched_on_workers(int nworkers, xce_worker_t** workers)
{
printf("%s %d workers gotten\n",
__func__, nworkers);
printf("%s %d workers gotten\n", __func__, nworkers);
return 0;
}
static void notify_job_fail(uint64_t jobid,
int code)
static void notify_job_fail(uint64_t jobid, int code)
{
/* clang-format off */
job_failinfo_t failinfo = {
@ -1733,32 +1679,27 @@ static void notify_jobstart(uint64_t jobid,
return;
}
static void notify_task_start(uint64_t jobid,
int clientidx,
int taskidx,
int pid,
int pgid)
static void notify_task_start(uint64_t jobid, int clientidx, int taskidx,
int pid, int pgid)
{
xce_task_pidinfo_t pidinfo = {
.jobid = jobid,
.host = get_setting("myname"),
.clientidx = clientidx,
.taskidx = taskidx,
.npids = 1,
.pids = (unsigned int[]) { (unsigned int)pid },
.npgids = 1,
.pgids = (unsigned int[]) { (unsigned int)pgid },
.exdata = NULL
};
xce_task_pidinfo_t pidinfo
= { .jobid = jobid,
.host = get_setting("myname"),
.clientidx = clientidx,
.taskidx = taskidx,
.npids = 1,
.pids = (unsigned int[]) { (unsigned int)pid },
.npgids = 1,
.pgids = (unsigned int[]) { (unsigned int)pgid },
.exdata = NULL };
xcecli_notify_taskstart(active_ctx->ctx, &pidinfo);
return;
}
static int run_task_remote(uint64_t jobid,
job_startinfo_t* startinfo,
xce_launch_t* launchinfo)
static int run_task_remote(uint64_t jobid, job_startinfo_t* startinfo,
xce_launch_t* launchinfo)
{
xce_taskhost_t hosts[launchinfo->nhosts - 1];
xce_taskrun_t taskrun;
@ -1805,9 +1746,8 @@ static int run_task_remote(uint64_t jobid,
return rc;
}
static int run_task_local(uint64_t jobid,
job_startinfo_t* startinfo,
int ntasks)
static int run_task_local(uint64_t jobid, job_startinfo_t* startinfo,
int ntasks)
{
pid_t pid;
@ -1869,8 +1809,7 @@ static int run_task_local(uint64_t jobid,
exit(rc);
}
printf("Job %lu started, PID: %d\n",
jobid, pid);
printf("Job %lu started, PID: %d\n", jobid, pid);
return pid;
}
@ -1899,9 +1838,11 @@ int run_job(xce_job_exec_t* startmsg)
printf("%s: q_post_exec= %s\n", __func__,
(startinfo->q_post_exec == NULL) ? "NULL" : startinfo->q_post_exec);
printf("%s: job_pre_exec= %s\n", __func__,
(startinfo->job_pre_exec == NULL) ? "NULL" : startinfo->job_pre_exec);
(startinfo->job_pre_exec == NULL) ? "NULL"
: startinfo->job_pre_exec);
printf("%s: job_post_exec= %s\n", __func__,
(startinfo->job_post_exec == NULL) ? "NULL" : startinfo->job_post_exec);
(startinfo->job_post_exec == NULL) ? "NULL"
: startinfo->job_post_exec);
if (launchinfo->nhosts > 1) {
rc = run_task_remote(jobid, startinfo, launchinfo);
@ -1911,8 +1852,7 @@ int run_job(xce_job_exec_t* startmsg)
}
}
rc = run_task_local(jobid, startinfo,
launchinfo->hosts[0]->nranks);
rc = run_task_local(jobid, startinfo, launchinfo->hosts[0]->nranks);
if (rc < 0) {
notify_job_fail(jobid, rc);
} else {
@ -1947,22 +1887,17 @@ static int handle_notify(xce_request_t* request)
switch (data->event) {
case NotifyData_data_taskPidInfo:
printf("job %lu host %s taskidx %d pid %d\n",
data->data.taskinfo->jobid,
data->data.taskinfo->host,
data->data.taskinfo->taskidx,
data->data.taskinfo->pids[0]);
data->data.taskinfo->jobid, data->data.taskinfo->host,
data->data.taskinfo->taskidx, data->data.taskinfo->pids[0]);
break;
case NotifyData_data_taskFailInfo:
printf("job %lu host %s task %d error code %d\n",
data->data.taskfailinfo->jobid,
data->data.taskfailinfo->host,
data->data.taskfailinfo->taskidx,
data->data.taskfailinfo->code);
data->data.taskfailinfo->jobid, data->data.taskfailinfo->host,
data->data.taskfailinfo->taskidx, data->data.taskfailinfo->code);
break;
case NotifyData_data_taskFinish:
printf("job %lu host %s task %d exit code %d\n",
data->data.taskfinish->jobid,
data->data.taskfinish->host,
data->data.taskfinish->jobid, data->data.taskfinish->host,
data->data.taskfinish->taskidx,
data->data.taskfinish->exit_code);
break;
@ -1970,8 +1905,7 @@ static int handle_notify(xce_request_t* request)
return 0;
}
static int job_kill(uint64_t jobid,
int signo)
static int job_kill(uint64_t jobid, int signo)
{
int i;
int killed = 0;
@ -1990,23 +1924,21 @@ static int job_kill(uint64_t jobid,
return killed;
}
static int job_chkpnt(uint64_t jobid,
char* method,
int kill)
static int job_chkpnt(uint64_t jobid, char* method, int kill)
{
char buf[128];
char info[256];
printf("checkpoint job %ld by method %s\n",
jobid, method);
printf("checkpoint job %ld by method %s\n", jobid, method);
sprintf(buf, "/tmp/%ld/ckpt_dir", jobid);
/* do some actions to checkpoint jobs */
sprintf(info, "{\nhost_select=\"criu\"; \nrestart_command=\"cd %s; criu restore -vvv\"}\n",
sprintf(info,
"{\nhost_select=\"criu\"; \nrestart_command=\"cd %s; criu restore "
"-vvv\"}\n",
buf);
xcecli_notify_jobchkpt(active_ctx->ctx,
jobid, info);
xcecli_notify_jobchkpt(active_ctx->ctx, jobid, info);
if (kill) {
job_kill(jobid, SIGTERM);
@ -2029,14 +1961,12 @@ static int handle_jobcontrol(xce_request_t* request)
rc = job_kill(jobid, signo);
break;
case JobControl_u_ckptoption:
rc = job_chkpnt(jobctrl->jobid,
jobctrl->u.ckptoption->method,
rc = job_chkpnt(jobctrl->jobid, jobctrl->u.ckptoption->method,
jobctrl->u.ckptoption->kill);
break;
default:
rc = -EINVAL;
ERROR("unknown job control action %d",
jobctrl->action);
ERROR("unknown job control action %d", jobctrl->action);
break;
}
@ -2056,9 +1986,7 @@ static int handle_runtasks(xce_request_t* request)
/* something wrong */
rc = -EINVAL;
notify_task_fail(runmsg->jobid,
runmsg->clientidx,
-1, rc);
notify_task_fail(runmsg->jobid, runmsg->clientidx, -1, rc);
return rc;
}
@ -2066,9 +1994,7 @@ static int handle_runtasks(xce_request_t* request)
/* something wrong */
rc = -EINVAL;
notify_task_fail(runmsg->jobid,
runmsg->clientidx,
-1, rc);
notify_task_fail(runmsg->jobid, runmsg->clientidx, -1, rc);
return rc;
}
@ -2093,14 +2019,11 @@ static int handle_runtasks(xce_request_t* request)
rc = run_task(runmsg->taskhosts[0]->cmdline, &pid);
if (rc < 0) {
notify_task_fail(runmsg->jobid,
runmsg->clientidx,
i, rc);
notify_task_fail(runmsg->jobid, runmsg->clientidx, i, rc);
} else {
int idx;
printf("job %lu task %d started, PID: %d\n",
runmsg->jobid, i, pid);
printf("job %lu task %d started, PID: %d\n", runmsg->jobid, i, pid);
idx = get_avail_run_task_slots();
if (idx < 0) {
@ -2112,9 +2035,7 @@ static int handle_runtasks(xce_request_t* request)
run_tasks[idx].pid = pid;
run_tasks[idx].ts = 0;
}
notify_task_start(runmsg->jobid,
runmsg->clientidx,
i, pid, pgid);
notify_task_start(runmsg->jobid, runmsg->clientidx, i, pid, pgid);
}
}
@ -2133,13 +2054,11 @@ static int myreq_handler(xce_request_t* request)
switch (datamsg->table) {
case Data_data_schedjobs:
case Data_data_jobs:
sched_on_jobs(datamsg->nrows,
(xce_job_t**)datamsg->rows);
sched_on_jobs(datamsg->nrows, (xce_job_t**)datamsg->rows);
break;
case Data_data_schedworkers:
case Data_data_workers:
sched_on_workers(datamsg->nrows,
(xce_worker_t**)datamsg->rows);
sched_on_workers(datamsg->nrows, (xce_worker_t**)datamsg->rows);
break;
default:
break;
@ -2181,7 +2100,8 @@ static void check_run_jobs()
continue;
}
if (waitpid(run_jobs[i].pid, &wstatus, WNOHANG | WUNTRACED | WCONTINUED) <= 0) {
if (waitpid(run_jobs[i].pid, &wstatus, WNOHANG | WUNTRACED | WCONTINUED)
<= 0) {
/* fake job rusage */
int npids = 1;
int npgids = 0;
@ -2190,15 +2110,12 @@ static void check_run_jobs()
{ "cputime", 100.0 },
{ "mem", 200.0 }
};
xce_rusage_t* usages[] = {
&(data[0]),
&(data[1])
};
xce_rusage_t* usages[] = { &(data[0]), &(data[1]) };
if (now - run_jobs[i].ts > RUSAGE_UPDATE_INTERVAL) {
xcecli_update_jusage(active_ctx->ctx, run_jobs[i].jobid,
npids, &(run_jobs[i].pid), npgids, NULL,
nusage, &usages[0]);
xcecli_update_jusage(active_ctx->ctx, run_jobs[i].jobid, npids,
&(run_jobs[i].pid), npgids, NULL, nusage,
&usages[0]);
run_jobs[i].ts = now;
}
@ -2220,8 +2137,7 @@ static void check_run_jobs()
finish.exit_code = 128 + WTERMSIG(wstatus);
}
printf("job %lu exit code %d\n",
finish.jobid, finish.exit_code);
printf("job %lu exit code %d\n", finish.jobid, finish.exit_code);
xcecli_notify_jobfinish(active_ctx->ctx, &finish);
run_jobs[i].jobid = 0;
run_jobs[i].pid = 0;
@ -2245,7 +2161,9 @@ static void check_run_tasks()
continue;
}
if (waitpid(run_tasks[i].pid, &wstatus, WNOHANG | WUNTRACED | WCONTINUED) <= 0) {
if (waitpid(run_tasks[i].pid, &wstatus,
WNOHANG | WUNTRACED | WCONTINUED)
<= 0) {
/* fake job rusage */
int npids = 1;
int npgids = 0;
@ -2254,28 +2172,23 @@ static void check_run_tasks()
{ "cputime", 100.0 },
{ "mem", 200.0 }
};
xce_rusage_t* usages[] = {
&(data[0]),
&(data[1])
};
xce_rusage_t* usages[] = { &(data[0]), &(data[1]) };
if (now - run_tasks[i].ts > RUSAGE_UPDATE_INTERVAL) {
xcecli_update_jusage(active_ctx->ctx, run_tasks[i].jobid,
npids, &(run_tasks[i].pid), npgids, NULL,
nusage, &usages[0]);
xcecli_update_jusage(active_ctx->ctx, run_tasks[i].jobid, npids,
&(run_tasks[i].pid), npgids, NULL, nusage,
&usages[0]);
run_tasks[i].ts = now;
}
continue;
}
if (WIFEXITED(wstatus) || WIFSIGNALED(wstatus)) {
xce_task_finish_t finish = {
.jobid = run_tasks[i].jobid,
.host = get_setting("myname"),
.taskidx = run_tasks[i].taskid,
.clientidx = run_tasks[i].clientidx,
.exit_code = 0
};
xce_task_finish_t finish = { .jobid = run_tasks[i].jobid,
.host = get_setting("myname"),
.taskidx = run_tasks[i].taskid,
.clientidx = run_tasks[i].clientidx,
.exit_code = 0 };
if (WIFEXITED(wstatus)) {
finish.exit_code = WEXITSTATUS(wstatus);
@ -2283,9 +2196,8 @@ static void check_run_tasks()
finish.exit_code = 128 + WTERMSIG(wstatus);
}
printf("job %lu task %d exit code %d\n",
finish.jobid, finish.taskidx,
finish.exit_code);
printf("job %lu task %d exit code %d\n", finish.jobid,
finish.taskidx, finish.exit_code);
xcecli_notify_taskfinish(active_ctx->ctx, &finish);
run_tasks[i].jobid = 0;
run_tasks[i].pid = 0;
@ -2311,7 +2223,7 @@ int main(int argc, char* argv[])
{
struct arguments arguments;
char* buf;
char* logfile = "/tmp/xce_test.log";
char* logfile = "/tmp/xce_test.log";
char* loglevel = "info";
int logsize = 64 * 1024 * 1024;
int logcount = 10;