/* daq_recv_channel_groups() * * Get channel groups description * Returns zero on success. * Sets `*num_channel_groups_received' to the actual number of * configured channel groups. */ int daq_recv_channel_groups (daq_t *daq, daq_channel_group_t *group, int num_groups, int *num_channel_groups_received) { int i; int resp; int groups; fprintf( stderr, "daq_recv_channel_groups: entry\n" ); if ((resp = daq_send (daq, "status channel-groups;"))) return resp; /* Read the number of channels */ if ( ( groups = read_server_response (daq -> conceal -> sockfd)) <= 0) { fprintf (stderr, "couldn't determine the number of channel groups\n"); return DAQD_ERROR; } fprintf( stderr, "daq_recv_channel_groups: num_groups: %d groups: %d\n", num_groups, groups ); *num_channel_groups_received = groups; if (num_groups < groups) groups = num_groups; for (i = 0; i < groups; i++) { int len=read_bytes(daq->conceal->sockfd, group[i].name, (size_t)MAX_CHANNEL_NAME_LENGTH); if (len != MAX_CHANNEL_NAME_LENGTH) return DAQD_ERROR; null_term(group [i].name, len); group [i].group_num = read_server_response (daq -> conceal -> sockfd); if (group [i].group_num < 0) return DAQD_ERROR; } return 0; }
/* Start a job: * CMD=STARTJOB ARG=<jobid> TASKLIST=<node_list> [COMMENT=<whatever>] * RET 0 on success, -1 on failure */ extern int start_job(char *cmd_ptr, int *err_code, char **err_msg) { char *arg_ptr, *comment_ptr, *task_ptr, *tasklist, *tmp_char; int i, rc, task_cnt; uint32_t jobid; hostlist_t hl = (hostlist_t) NULL; char *host_string; static char reply_msg[128]; arg_ptr = strstr(cmd_ptr, "ARG="); if (arg_ptr == NULL) { *err_code = -300; *err_msg = "STARTJOB lacks ARG"; error("wiki: STARTJOB lacks ARG"); return -1; } jobid = strtoul(arg_ptr+4, &tmp_char, 10); if (!isspace(tmp_char[0])) { *err_code = -300; *err_msg = "Invalid ARG value"; error("wiki: STARTJOB has invalid jobid"); return -1; } comment_ptr = strstr(cmd_ptr, "COMMENT="); task_ptr = strstr(cmd_ptr, "TASKLIST="); if (comment_ptr) { comment_ptr[7] = ':'; comment_ptr += 8; if (comment_ptr[0] == '\"') { comment_ptr++; for (i=0; i<MAX_COMMENT_LEN; i++) { if (comment_ptr[i] == '\0') break; if (comment_ptr[i] == '\"') { comment_ptr[i] = '\0'; break; } } if (i == MAX_COMMENT_LEN) comment_ptr[i-1] = '\0'; } else if (comment_ptr[0] == '\'') { comment_ptr++; for (i=0; i<MAX_COMMENT_LEN; i++) { if (comment_ptr[i] == '\0') break; if (comment_ptr[i] == '\'') { comment_ptr[i] = '\0'; break; } } if (i == MAX_COMMENT_LEN) comment_ptr[i-1] = '\0'; } else null_term(comment_ptr); } if (task_ptr == NULL) { *err_code = -300; *err_msg = "STARTJOB lacks TASKLIST"; error("wiki: STARTJOB lacks TASKLIST"); return -1; } task_ptr += 9; /* skip over "TASKLIST=" */ if ((task_ptr[0] == '\0') || isspace(task_ptr[0])) { /* No TASKLIST specification, useful for testing */ host_string = xstrdup(""); task_cnt = 0; tasklist = NULL; } else { null_term(task_ptr); tasklist = moab2slurm_task_list(task_ptr, &task_cnt); if (tasklist) hl = hostlist_create(tasklist); if ((tasklist == NULL) || (hl == NULL)) { *err_code = -300; *err_msg = "STARTJOB TASKLIST is invalid"; error("wiki: STARTJOB TASKLIST is invalid: %s", task_ptr); xfree(tasklist); return -1; } hostlist_uniq(hl); hostlist_sort(hl); host_string = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); if (host_string == NULL) { *err_code = -300; *err_msg = "STARTJOB has invalid TASKLIST"; error("wiki: STARTJOB has invalid TASKLIST: %s", tasklist); xfree(tasklist); return -1; } } rc = _start_job(jobid, task_cnt, host_string, tasklist, comment_ptr, err_code, err_msg); xfree(host_string); xfree(tasklist); if (rc == 0) { snprintf(reply_msg, sizeof(reply_msg), "job %u started successfully", jobid); *err_msg = reply_msg; } return rc; }
/* Modify a job: * CMD=MODIFYJOB ARG=<jobid> * [BANK=<name>;] * [COMMENT=<whatever>;] * [DEPEND=afterany:<jobid>;] * [JOBNAME=<name>;] * [MINSTARTTIME=<uts>;] * [NODES=<number>;] * [PARTITION=<name>;] * [RFEATURES=<features>;] * [TIMELIMT=<seconds>;] * [VARIABLELIST=<env_vars>;] * [GRES=<name:value>;] * [WCKEY=<name>;] * * RET 0 on success, -1 on failure */ extern int job_modify_wiki(char *cmd_ptr, int *err_code, char **err_msg) { char *arg_ptr, *bank_ptr, *depend_ptr, *nodes_ptr, *start_ptr; char *host_ptr, *name_ptr, *part_ptr, *time_ptr, *tmp_char; char *comment_ptr, *feature_ptr, *env_ptr, *gres_ptr, *wckey_ptr; int i, slurm_rc; uint32_t jobid, new_node_cnt = 0, new_time_limit = 0; static char reply_msg[128]; /* Locks: write job, read node and partition info */ slurmctld_lock_t job_write_lock = { NO_LOCK, WRITE_LOCK, READ_LOCK, READ_LOCK }; arg_ptr = strstr(cmd_ptr, "ARG="); if (arg_ptr == NULL) { *err_code = -300; *err_msg = "MODIFYJOB lacks ARG="; error("wiki: MODIFYJOB lacks ARG="); return -1; } /* Change all parsed "=" to ":" then search for remaining "=" * and report results as unrecognized options */ arg_ptr[3] = ':'; arg_ptr += 4; jobid = strtoul(arg_ptr, &tmp_char, 10); if ((tmp_char[0] != '\0') && (!isspace(tmp_char[0]))) { *err_code = -300; *err_msg = "Invalid ARG value"; error("wiki: MODIFYJOB has invalid jobid"); return -1; } bank_ptr = strstr(cmd_ptr, "BANK="); comment_ptr = strstr(cmd_ptr, "COMMENT="); depend_ptr = strstr(cmd_ptr, "DEPEND="); gres_ptr = strstr(cmd_ptr, "GRES="); host_ptr = strstr(cmd_ptr, "HOSTLIST="); name_ptr = strstr(cmd_ptr, "JOBNAME="); start_ptr = strstr(cmd_ptr, "MINSTARTTIME="); nodes_ptr = strstr(cmd_ptr, "NODES="); part_ptr = strstr(cmd_ptr, "PARTITION="); feature_ptr = strstr(cmd_ptr, "RFEATURES="); time_ptr = strstr(cmd_ptr, "TIMELIMIT="); env_ptr = strstr(cmd_ptr, "VARIABLELIST="); wckey_ptr = strstr(cmd_ptr, "WCKEY="); if (bank_ptr) { bank_ptr[4] = ':'; bank_ptr += 5; null_term(bank_ptr); } if (comment_ptr) { comment_ptr[7] = ':'; comment_ptr += 8; if (comment_ptr[0] == '\"') { comment_ptr++; for (i=0; ; i++) { if (comment_ptr[i] == '\0') break; if (comment_ptr[i] == '\"') { comment_ptr[i] = '\0'; break; } } } else if (comment_ptr[0] == '\'') { comment_ptr++; for (i=0; ; i++) { if (comment_ptr[i] == '\0') break; if (comment_ptr[i] == '\'') { comment_ptr[i] = '\0'; break; } } } else null_term(comment_ptr); } if (depend_ptr) { depend_ptr[6] = ':'; depend_ptr += 7; null_term(depend_ptr); } if (feature_ptr) { feature_ptr[9] = ':'; feature_ptr += 10; null_term(feature_ptr); } if (gres_ptr) { gres_ptr[4] = ':'; gres_ptr += 5; null_term(gres_ptr); } if (host_ptr) { host_ptr[8] = ':'; host_ptr += 9; null_term(host_ptr); } if (name_ptr) { name_ptr[7] = ':'; name_ptr += 8; if (name_ptr[0] == '\"') { name_ptr++; for (i=0; ; i++) { if (name_ptr[i] == '\0') break; if (name_ptr[i] == '\"') { name_ptr[i] = '\0'; break; } } } else if (name_ptr[0] == '\'') { name_ptr++; for (i=0; ; i++) { if (name_ptr[i] == '\0') break; if (name_ptr[i] == '\'') { name_ptr[i] = '\0'; break; } } } else null_term(name_ptr); } if (start_ptr) { start_ptr[12] = ':'; start_ptr += 13; null_term(start_ptr); } if (nodes_ptr) { nodes_ptr[5] = ':'; nodes_ptr += 6; new_node_cnt = strtoul(nodes_ptr, NULL, 10); } if (part_ptr) { part_ptr[9] = ':'; part_ptr += 10; null_term(part_ptr); } if (time_ptr) { time_ptr[9] = ':'; time_ptr += 10; new_time_limit = strtoul(time_ptr, NULL, 10); } if (env_ptr) { env_ptr[12] = ':'; env_ptr += 13; null_term(env_ptr); } if (wckey_ptr) { wckey_ptr[5] = ':'; wckey_ptr += 6; null_term(wckey_ptr); } /* Look for any un-parsed "=" ignoring anything after VARIABLELIST * which is expected to contain "=" in its value*/ tmp_char = strchr(cmd_ptr, '='); if (tmp_char && (!env_ptr || (env_ptr > tmp_char))) { tmp_char[0] = '\0'; while (tmp_char[-1] && (!isspace(tmp_char[-1]))) tmp_char--; error("wiki: Invalid MODIFYJOB option %s", tmp_char); } lock_slurmctld(job_write_lock); slurm_rc = _job_modify(jobid, bank_ptr, depend_ptr, host_ptr, new_node_cnt, part_ptr, new_time_limit, name_ptr, start_ptr, feature_ptr, env_ptr, comment_ptr, gres_ptr, wckey_ptr); unlock_slurmctld(job_write_lock); if (slurm_rc != SLURM_SUCCESS) { *err_code = -700; *err_msg = slurm_strerror(slurm_rc); error("wiki: Failed to modify job %u (%m)", jobid); return -1; } snprintf(reply_msg, sizeof(reply_msg), "job %u modified successfully", jobid); *err_msg = reply_msg; return 0; }
/* Start a job: * CMD=STARTJOB ARG=<jobid> TASKLIST=<node_list> * RET 0 on success, -1 on failure */ extern int start_job(char *cmd_ptr, int *err_code, char **err_msg) { char *arg_ptr, *task_ptr, *tasklist, *tmp_char; int rc, task_cnt; uint32_t jobid; hostlist_t hl = (hostlist_t) NULL; char *host_string; static char reply_msg[128]; arg_ptr = strstr(cmd_ptr, "ARG="); if (arg_ptr == NULL) { *err_code = -300; *err_msg = "STARTJOB lacks ARG"; error("wiki: STARTJOB lacks ARG"); return -1; } jobid = strtoul(arg_ptr+4, &tmp_char, 10); if (!isspace(tmp_char[0])) { *err_code = -300; *err_msg = "Invalid ARG value"; error("wiki: STARTJOB has invalid jobid"); return -1; } task_ptr = strstr(cmd_ptr, "TASKLIST="); if (task_ptr == NULL) { *err_code = -300; *err_msg = "STARTJOB lacks TASKLIST"; error("wiki: STARTJOB lacks TASKLIST"); return -1; } task_ptr += 9; /* skip over "TASKLIST=" */ null_term(task_ptr); tasklist = moab2slurm_task_list(task_ptr, &task_cnt); if (tasklist) hl = hostlist_create(tasklist); if ((tasklist == NULL) || (hl == NULL)) { *err_code = -300; *err_msg = "STARTJOB TASKLIST is invalid"; error("wiki: STARTJOB TASKLIST is invalid: %s", task_ptr); xfree(tasklist); return -1; } hostlist_uniq(hl); hostlist_sort(hl); host_string = hostlist_ranged_string_xmalloc(hl); hostlist_destroy(hl); if (host_string == NULL) { *err_code = -300; *err_msg = "STARTJOB has invalid TASKLIST"; error("wiki: STARTJOB has invalid TASKLIST: %s", tasklist); xfree(tasklist); return -1; } rc = _start_job(jobid, task_cnt, host_string, tasklist, err_code, err_msg); xfree(host_string); xfree(tasklist); if (rc == 0) { snprintf(reply_msg, sizeof(reply_msg), "job %u started successfully", jobid); *err_msg = reply_msg; } return rc; }
/* Modify a job: * CMD=MODIFYJOB ARG=<jobid> PARTITION=<name> NODES=<number> * DEPEND=afterany:<jobid> TIMELIMT=<seconds> BANK=<name> * RET 0 on success, -1 on failure */ extern int job_modify_wiki(char *cmd_ptr, int *err_code, char **err_msg) { char *arg_ptr, *bank_ptr, *depend_ptr, *nodes_ptr; char *host_ptr, *part_ptr, *time_ptr, *tmp_char; int slurm_rc; uint32_t jobid, new_node_cnt = 0, new_time_limit = 0; static char reply_msg[128]; /* Locks: write job, read node and partition info */ slurmctld_lock_t job_write_lock = { NO_LOCK, WRITE_LOCK, READ_LOCK, READ_LOCK, NO_LOCK }; arg_ptr = strstr(cmd_ptr, "ARG="); if (arg_ptr == NULL) { *err_code = -300; *err_msg = "MODIFYJOB lacks ARG="; error("wiki: MODIFYJOB lacks ARG="); return -1; } /* Change all parsed "=" to ":" then search for remaining "=" * and report results as unrecognized options */ arg_ptr[3] = ':'; arg_ptr += 4; jobid = strtoul(arg_ptr, &tmp_char, 10); if ((tmp_char[0] != '\0') && (!isspace(tmp_char[0]))) { *err_code = -300; *err_msg = "Invalid ARG value"; error("wiki: MODIFYJOB has invalid jobid"); return -1; } bank_ptr = strstr(cmd_ptr, "BANK="); depend_ptr = strstr(cmd_ptr, "DEPEND="); host_ptr = strstr(cmd_ptr, "HOSTLIST="); nodes_ptr = strstr(cmd_ptr, "NODES="); part_ptr = strstr(cmd_ptr, "PARTITION="); time_ptr = strstr(cmd_ptr, "TIMELIMIT="); if (bank_ptr) { bank_ptr[4] = ':'; bank_ptr += 5; null_term(bank_ptr); } if (depend_ptr) { depend_ptr[6] = ':'; depend_ptr += 7; null_term(depend_ptr); } if (host_ptr) { host_ptr[8] = ':'; host_ptr += 9; null_term(bank_ptr); } if (nodes_ptr) { nodes_ptr[5] = ':'; nodes_ptr += 6; new_node_cnt = strtoul(nodes_ptr, NULL, 10); } if (part_ptr) { part_ptr[9] = ':'; part_ptr += 10; null_term(part_ptr); } if (time_ptr) { time_ptr[9] = ':'; time_ptr += 10; new_time_limit = strtoul(time_ptr, NULL, 10); } /* Look for any un-parsed "=" */ tmp_char = strchr(cmd_ptr, '='); if (tmp_char) { tmp_char[0] = '\0'; while (tmp_char[-1] && (!isspace(tmp_char[-1]))) tmp_char--; error("wiki: Invalid MODIFYJOB option %s", tmp_char); } lock_slurmctld(job_write_lock); slurm_rc = _job_modify(jobid, bank_ptr, depend_ptr, host_ptr, new_node_cnt, part_ptr, new_time_limit); unlock_slurmctld(job_write_lock); if (slurm_rc != SLURM_SUCCESS) { *err_code = -700; *err_msg = slurm_strerror(slurm_rc); error("wiki: Failed to modify job %u (%m)", jobid); return -1; } snprintf(reply_msg, sizeof(reply_msg), "job %u modified successfully", jobid); *err_msg = reply_msg; return 0; }