static void _proc_msg(int new_fd, char *msg, slurm_addr_t cli_addr) { /* Locks: Read job and node data */ slurmctld_lock_t job_read_lock = { NO_LOCK, READ_LOCK, READ_LOCK, NO_LOCK, NO_LOCK }; /* Locks: Write job */ slurmctld_lock_t job_write_lock = { NO_LOCK, WRITE_LOCK, NO_LOCK, NO_LOCK, NO_LOCK }; /* Locks: Write job, write node, read partition */ slurmctld_lock_t job_write_lock2 = { NO_LOCK, WRITE_LOCK, WRITE_LOCK, READ_LOCK, READ_LOCK }; /* Locks: Write node data */ slurmctld_lock_t node_write_lock = { NO_LOCK, NO_LOCK, WRITE_LOCK, NO_LOCK, READ_LOCK }; char *cmd_ptr, *resp = NULL, *msg_decrypted = NULL; uid_t cmd_uid; uint32_t protocol_version = 0; if (!msg) { info("slurmctld/nonstop: NULL message received"); resp = xstrdup("Error:\"NULL message received\""); goto send_resp; } msg_decrypted = _decrypt(msg, &cmd_uid); if (!msg_decrypted) { info("slurmctld/nonstop: Message decrypt failure"); resp = xstrdup("Error:\"Message decrypt failure\""); goto send_resp; } if (nonstop_debug > 0) info("slurmctld/nonstop: msg decrypted:%s", msg_decrypted); cmd_ptr = msg_decrypted; /* 123456789012345678901234567890 */ if (xstrncmp(cmd_ptr, version_string, 13) == 0) { cmd_ptr = strchr(cmd_ptr + 13, ':'); if (cmd_ptr) { cmd_ptr++; protocol_version = SLURM_PROTOCOL_VERSION; } } if (protocol_version == 0) { info("slurmctld/nonstop: Message version invalid"); resp = xstrdup("Error:\"Message version invalid\""); goto send_resp; } if (xstrncmp(cmd_ptr, "CALLBACK:JOBID:", 15) == 0) { resp = register_callback(cmd_ptr, cmd_uid, cli_addr, protocol_version); } else if (xstrncmp(cmd_ptr, "DRAIN:NODES:", 12) == 0) { lock_slurmctld(node_write_lock); resp = drain_nodes_user(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(node_write_lock); } else if (xstrncmp(cmd_ptr, "DROP_NODE:JOBID:", 15) == 0) { lock_slurmctld(job_write_lock2); resp = drop_node(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock2); } else if (xstrncmp(cmd_ptr, "GET_FAIL_NODES:JOBID:", 21) == 0) { lock_slurmctld(job_read_lock); resp = fail_nodes(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_read_lock); } else if (xstrncmp(cmd_ptr, "REPLACE_NODE:JOBID:", 19) == 0) { lock_slurmctld(job_write_lock2); resp = replace_node(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock2); } else if (xstrncmp(cmd_ptr, "SHOW_CONFIG", 11) == 0) { resp = show_config(cmd_ptr, cmd_uid, protocol_version); } else if (xstrncmp(cmd_ptr, "SHOW_JOB:JOBID:", 15) == 0) { resp = show_job(cmd_ptr, cmd_uid, protocol_version); } else if (xstrncmp(cmd_ptr, "TIME_INCR:JOBID:", 16) == 0) { lock_slurmctld(job_write_lock); resp = time_incr(cmd_ptr, cmd_uid, protocol_version); unlock_slurmctld(job_write_lock); } else { info("slurmctld/nonstop: Invalid command: %s", cmd_ptr); xstrfmtcat(resp, "%s ECMD", SLURM_VERSION_STRING); } send_resp: if (nonstop_debug > 0) info("slurmctld/nonstop: msg send:%s", resp); _send_reply(new_fd, resp); xfree(resp); if (msg_decrypted) free(msg_decrypted); return; }
/*****************************************************************************\ * Parse, process and respond to a request \*****************************************************************************/ static void _proc_msg(slurm_fd_t new_fd, char *msg) { DEF_TIMERS; char *req, *cmd_ptr, *msg_type = NULL; char response[128]; if (new_fd < 0) return; START_TIMER; if (!msg) { err_code = -300; err_msg = "NULL request message"; error("wiki: NULL request message"); goto resp_msg; } if (_parse_msg(msg, &req) != 0) goto resp_msg; cmd_ptr = strstr(req, "CMD="); if (cmd_ptr == NULL) { err_code = -300; err_msg = "request lacks CMD"; error("wiki: request lacks CMD"); goto resp_msg; } cmd_ptr +=4; err_code = 0; if (strncmp(cmd_ptr, "GETJOBS", 7) == 0) { msg_type = "wiki:GETJOBS"; if (!get_jobs(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "GETNODES", 8) == 0) { msg_type = "wiki:GETNODES"; if (!get_nodes(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "STARTJOB", 8) == 0) { msg_type = "wiki:STARTJOB"; start_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "CANCELJOB", 9) == 0) { msg_type = "wiki:CANCELJOB"; cancel_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SUSPENDJOB", 10) == 0) { msg_type = "wiki:SUSPENDJOB"; suspend_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "RESUMEJOB", 9) == 0) { msg_type = "wiki:RESUMEJOB"; resume_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "MODIFYJOB", 9) == 0) { msg_type = "wiki:MODIFYJOB"; job_modify_wiki(cmd_ptr, &err_code, &err_msg); } else { err_code = -300; err_msg = "unsupported request type"; error("wiki: unrecognized request type: %s", req); } END_TIMER2(msg_type); resp_msg: snprintf(response, sizeof(response), "SC=%d RESPONSE=%s", err_code, err_msg); _send_reply(new_fd, response); return; free_resp_msg: /* Message is pre-formatted by get_jobs and get_nodes * ONLY if no error. Send message and xfree the buffer. */ _send_reply(new_fd, err_msg); xfree(err_msg); return; }
/*****************************************************************************\ * Parse, process and respond to a request \*****************************************************************************/ static void _proc_msg(slurm_fd_t new_fd, char *msg) { DEF_TIMERS; char *req, *cmd_ptr, *msg_type = NULL; char response[128]; if (new_fd < 0) return; START_TIMER; if (!msg) { err_code = -300; err_msg = "NULL request message"; error("wiki: NULL request message"); goto resp_msg; } if (_parse_msg(msg, &req) != 0) goto resp_msg; cmd_ptr = strstr(req, "CMD="); if (cmd_ptr == NULL) { err_code = -300; err_msg = "request lacks CMD"; error("wiki: request lacks CMD"); goto resp_msg; } cmd_ptr +=4; err_code = 0; if (strncmp(cmd_ptr, "GETJOBS", 7) == 0) { msg_type = "wiki:GETJOBS"; if (!get_jobs(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "GETNODES", 8) == 0) { msg_type = "wiki:GETNODES"; if (!get_nodes(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "STARTJOB", 8) == 0) { msg_type = "wiki:STARTJOB"; start_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "CANCELJOB", 9) == 0) { msg_type = "wiki:CANCELJOB"; cancel_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "REQUEUEJOB", 10) == 0) { msg_type = "wiki:REQUEUEJOB"; job_requeue_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SUSPENDJOB", 10) == 0) { msg_type = "wiki:SUSPENDJOB"; suspend_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "RESUMEJOB", 9) == 0) { msg_type = "wiki:RESUMEJOB"; resume_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBADDTASK", 10) == 0) { msg_type = "wiki:JOBADDTASK"; job_add_task(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBRELEASETASK", 14) == 0) { msg_type = "wiki:JOBRELEASETASK"; job_release_task(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBWILLRUN", 10) == 0) { msg_type = "wiki:JOBWILLRUN"; if (strstr(cmd_ptr, "NODES=")) { /* Updated format input and output */ if (!job_will_run2(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else { if (!job_will_run(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } } else if (strncmp(cmd_ptr, "MODIFYJOB", 9) == 0) { msg_type = "wiki:MODIFYJOB"; job_modify_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "NOTIFYJOB", 9) == 0) { msg_type = "wiki:NOTIFYJOB"; job_notify_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SIGNALJOB", 9) == 0) { msg_type = "wiki:SIGNALJOB"; job_signal_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "INITIALIZE", 10) == 0) { msg_type = "wiki:INITIALIZE"; initialize_wiki(cmd_ptr, &err_code, &err_msg); } else { err_code = -300; err_msg = "unsupported request type"; error("wiki: unrecognized request type: %s", req); } END_TIMER2(msg_type); resp_msg: snprintf(response, sizeof(response), "SC=%d RESPONSE=%s", err_code, err_msg); _send_reply(new_fd, response); return; free_resp_msg: /* Message is pre-formatted by get_jobs and get_nodes * ONLY if no error. Send message and xfree the buffer. */ _send_reply(new_fd, err_msg); xfree(err_msg); return; }