Newer
Older
/*****************************************************************************\
* proc_msg.c - process incomming messages to slurmctld
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Morris Jette <jette@llnl.gov>, Kevin Tew <tew1@llnl.gov>, et. al.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
* UCRL-CODE-2002-040.
*
* This file is part of SLURM, a resource management program.
* For details, see <http://www.llnl.gov/linux/slurm/>.
*
* SLURM is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with SLURM; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef WITH_PTHREADS
# include <pthread.h>
#endif /* WITH_PTHREADS */
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <slurm/slurm_errno.h>
#include "src/common/checkpoint.h"
#include "src/common/daemonize.h"
#include "src/common/fd.h"
#include "src/common/hostlist.h"
#include "src/common/log.h"
#include "src/common/macros.h"
#include "src/common/node_select.h"
#include "src/common/pack.h"
#include "src/common/read_config.h"
#include "src/common/slurm_auth.h"
#include "src/common/slurm_cred.h"
#include "src/common/slurm_protocol_api.h"
#include "src/common/switch.h"
#include "src/common/xstring.h"
#include "src/slurmctld/locks.h"
#include "src/slurmctld/proc_req.h"
#include "src/slurmctld/read_config.h"
#include "src/slurmctld/slurmctld.h"
#include "src/slurmctld/state_save.h"
#define BUF_SIZE 1024 /* Temporary buffer size */
static void _fill_ctld_conf(slurm_ctl_conf_t * build_ptr);
static inline bool _is_super_user(uid_t uid);
static void _kill_job_on_msg_fail(uint32_t job_id);
static int _make_step_cred(struct step_record *step_rec,
slurm_cred_t *slurm_cred);
inline static void _slurm_rpc_allocate_resources(slurm_msg_t * msg);
inline static void _slurm_rpc_allocate_and_run(slurm_msg_t * msg);
inline static void _slurm_rpc_checkpoint(slurm_msg_t * msg);
inline static void _slurm_rpc_dump_conf(slurm_msg_t * msg);
inline static void _slurm_rpc_dump_jobs(slurm_msg_t * msg);
inline static void _slurm_rpc_dump_nodes(slurm_msg_t * msg);
inline static void _slurm_rpc_dump_partitions(slurm_msg_t * msg);
inline static void _slurm_rpc_epilog_complete(slurm_msg_t * msg);
inline static void _slurm_rpc_job_step_kill(slurm_msg_t * msg);
inline static void _slurm_rpc_job_step_complete(slurm_msg_t * msg);
inline static void _slurm_rpc_job_step_create(slurm_msg_t * msg);
inline static void _slurm_rpc_job_step_get_info(slurm_msg_t * msg);
inline static void _slurm_rpc_job_will_run(slurm_msg_t * msg);
inline static void _slurm_rpc_node_registration(slurm_msg_t * msg);
inline static void _slurm_rpc_old_job_alloc(slurm_msg_t * msg);
inline static void _slurm_rpc_ping(slurm_msg_t * msg);
inline static void _slurm_rpc_reconfigure_controller(slurm_msg_t * msg);
inline static void _slurm_rpc_shutdown_controller(slurm_msg_t * msg);
inline static void _slurm_rpc_shutdown_controller_immediate(slurm_msg_t *
msg);
inline static void _slurm_rpc_submit_batch_job(slurm_msg_t * msg);
inline static void _slurm_rpc_update_job(slurm_msg_t * msg);
inline static void _slurm_rpc_update_node(slurm_msg_t * msg);
inline static void _slurm_rpc_update_partition(slurm_msg_t * msg);
inline static void _slurm_rpc_delete_partition(slurm_msg_t * msg);
inline static void _update_cred_key(void);
/*
* diff_tv_str - build a string showing the time difference between two times
* IN tv1 - start of event
* IN tv2 - end of event
* OUT tv_str - place to put delta time in format "usec=%ld"
* IN len_tv_str - size of tv_str in bytes
*/
inline void diff_tv_str(struct timeval *tv1,struct timeval *tv2,
char *tv_str, int len_tv_str)
{
long delta_t;
delta_t = (tv2->tv_sec - tv1->tv_sec) * 1000000;
delta_t += tv2->tv_usec - tv1->tv_usec;
snprintf(tv_str, len_tv_str, "usec=%ld", delta_t);
if (delta_t > 1000000)
info("Warning: Note very large processing time: %s",tv_str);
/*
* slurmctld_req - Process an individual RPC request
* IN/OUT msg - the request message, data associated with the message is freed
*/
void slurmctld_req (slurm_msg_t * msg)
{
switch (msg->msg_type) {
case REQUEST_RESOURCE_ALLOCATION:
_slurm_rpc_allocate_resources(msg);
slurm_free_job_desc_msg(msg->data);
break;
case REQUEST_ALLOCATION_AND_RUN_JOB_STEP:
_slurm_rpc_allocate_and_run(msg);
slurm_free_job_desc_msg(msg->data);
break;
case REQUEST_BUILD_INFO:
_slurm_rpc_dump_conf(msg);
slurm_free_last_update_msg(msg->data);
break;
case REQUEST_JOB_INFO:
_slurm_rpc_dump_jobs(msg);
slurm_free_job_info_request_msg(msg->data);
break;
case REQUEST_NODE_INFO:
_slurm_rpc_dump_nodes(msg);
slurm_free_node_info_request_msg(msg->data);
break;
case REQUEST_PARTITION_INFO:
_slurm_rpc_dump_partitions(msg);
slurm_free_part_info_request_msg(msg->data);
case MESSAGE_EPILOG_COMPLETE:
_slurm_rpc_epilog_complete(msg);
slurm_free_epilog_complete_msg(msg->data);
break;
case REQUEST_CANCEL_JOB_STEP:
_slurm_rpc_job_step_kill(msg);
slurm_free_job_step_kill_msg(msg->data);
break;
case REQUEST_COMPLETE_JOB_STEP:
_slurm_rpc_job_step_complete(msg);
slurm_free_job_complete_msg(msg->data);
break;
case REQUEST_JOB_STEP_CREATE:
_slurm_rpc_job_step_create(msg);
slurm_free_job_step_create_request_msg(msg->data);
break;
case REQUEST_JOB_STEP_INFO:
_slurm_rpc_job_step_get_info(msg);
slurm_free_job_step_info_request_msg(msg->data);
break;
case REQUEST_JOB_WILL_RUN:
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
slurm_free_job_desc_msg(msg->data);
break;
case MESSAGE_NODE_REGISTRATION_STATUS:
_slurm_rpc_node_registration(msg);
slurm_free_node_registration_status_msg(msg->data);
break;
case REQUEST_OLD_JOB_RESOURCE_ALLOCATION:
_slurm_rpc_old_job_alloc(msg);
slurm_free_old_job_alloc_msg(msg->data);
break;
case REQUEST_PING:
_slurm_rpc_ping(msg);
/* No body to free */
break;
case REQUEST_RECONFIGURE:
_slurm_rpc_reconfigure_controller(msg);
/* No body to free */
break;
case REQUEST_CONTROL:
_slurm_rpc_shutdown_controller(msg);
/* No body to free */
break;
case REQUEST_SHUTDOWN:
_slurm_rpc_shutdown_controller(msg);
slurm_free_shutdown_msg(msg->data);
break;
case REQUEST_SHUTDOWN_IMMEDIATE:
_slurm_rpc_shutdown_controller_immediate(msg);
/* No body to free */
break;
case REQUEST_SUBMIT_BATCH_JOB:
_slurm_rpc_submit_batch_job(msg);
slurm_free_job_desc_msg(msg->data);
break;
case REQUEST_UPDATE_JOB:
_slurm_rpc_update_job(msg);
slurm_free_job_desc_msg(msg->data);
break;
case REQUEST_UPDATE_NODE:
_slurm_rpc_update_node(msg);
slurm_free_update_node_msg(msg->data);
break;
case REQUEST_UPDATE_PARTITION:
_slurm_rpc_update_partition(msg);
slurm_free_update_part_msg(msg->data);
break;
case REQUEST_DELETE_PARTITION:
_slurm_rpc_delete_partition(msg);
slurm_free_delete_part_msg(msg->data);
break;
case REQUEST_NODE_REGISTRATION_STATUS:
error("slurmctld is talking with itself. "
"SlurmctldPort == SlurmdPort");
slurm_send_rc_msg(msg, EINVAL);
break;
case REQUEST_CHECKPOINT:
_slurm_rpc_checkpoint(msg);
slurm_free_checkpoint_msg(msg->data);
break;
default:
error("invalid RPC msg_type=%d", msg->msg_type);
slurm_send_rc_msg(msg, EINVAL);
break;
}
}
/*
* _fill_ctld_conf - make a copy of current slurm configuration
* this is done with locks set so the data can change at other times
* OUT conf_ptr - place to copy configuration to
*/
void _fill_ctld_conf(slurm_ctl_conf_t * conf_ptr)
{
conf_ptr->last_update = time(NULL);
conf_ptr->authtype = xstrdup(slurmctld_conf.authtype);
conf_ptr->backup_addr = xstrdup(slurmctld_conf.backup_addr);
conf_ptr->backup_controller = xstrdup(slurmctld_conf.
backup_controller);
conf_ptr->checkpoint_type = xstrdup(slurmctld_conf.checkpoint_type);
conf_ptr->control_addr = xstrdup(slurmctld_conf.control_addr);
conf_ptr->control_machine = xstrdup(slurmctld_conf.
control_machine);
conf_ptr->epilog = xstrdup(slurmctld_conf.epilog);
conf_ptr->fast_schedule = slurmctld_conf.fast_schedule;
conf_ptr->first_job_id = slurmctld_conf.first_job_id;
conf_ptr->heartbeat_interval = slurmctld_conf.heartbeat_interval;
conf_ptr->inactive_limit = slurmctld_conf.inactive_limit;
conf_ptr->job_comp_loc = xstrdup(slurmctld_conf.job_comp_loc);
conf_ptr->job_comp_type = xstrdup(slurmctld_conf.
job_comp_type);
conf_ptr->job_credential_private_key = xstrdup(slurmctld_conf.
job_credential_private_key);
conf_ptr->job_credential_public_certificate = xstrdup(slurmctld_conf.
job_credential_public_certificate);
conf_ptr->kill_tree = slurmctld_conf.kill_tree;
conf_ptr->kill_wait = slurmctld_conf.kill_wait;
conf_ptr->max_job_cnt = slurmctld_conf.max_job_cnt;
conf_ptr->min_job_age = slurmctld_conf.min_job_age;
conf_ptr->mpich_gm_dir = slurmctld_conf.mpich_gm_dir;
conf_ptr->plugindir = xstrdup(slurmctld_conf.plugindir);
conf_ptr->proctrack_type = xstrdup(slurmctld_conf.proctrack_type);
conf_ptr->prolog = xstrdup(slurmctld_conf.prolog);
conf_ptr->ret2service = slurmctld_conf.ret2service;
conf_ptr->schedauth = xstrdup(slurmctld_conf.schedauth);
conf_ptr->schedport = slurmctld_conf.schedport;
conf_ptr->schedrootfltr = slurmctld_conf.schedrootfltr;
conf_ptr->schedtype = xstrdup(slurmctld_conf.schedtype);
conf_ptr->select_type = xstrdup(slurmctld_conf.select_type);
conf_ptr->slurm_user_id = slurmctld_conf.slurm_user_id;
conf_ptr->slurm_user_name = xstrdup(slurmctld_conf.
slurm_user_name);
conf_ptr->slurmctld_debug = slurmctld_conf.slurmctld_debug;
conf_ptr->slurmctld_logfile = xstrdup(slurmctld_conf.
slurmctld_logfile);
conf_ptr->slurmctld_pidfile = xstrdup(slurmctld_conf.
slurmctld_pidfile);
conf_ptr->slurmctld_port = slurmctld_conf.slurmctld_port;
conf_ptr->slurmctld_timeout = slurmctld_conf.slurmctld_timeout;
conf_ptr->slurmd_debug = slurmctld_conf.slurmd_debug;
conf_ptr->slurmd_logfile = xstrdup(slurmctld_conf.
slurmd_logfile);
conf_ptr->slurmd_pidfile = xstrdup(slurmctld_conf.
slurmd_pidfile);
conf_ptr->slurmd_port = slurmctld_conf.slurmd_port;
conf_ptr->slurmd_spooldir = xstrdup(slurmctld_conf.
slurmd_spooldir);
conf_ptr->slurmd_timeout = slurmctld_conf.slurmd_timeout;
conf_ptr->slurm_conf = xstrdup(slurmctld_conf.slurm_conf);
conf_ptr->state_save_location = xstrdup(slurmctld_conf.
state_save_location);
conf_ptr->switch_type = xstrdup(slurmctld_conf.switch_type);
conf_ptr->tmp_fs = xstrdup(slurmctld_conf.tmp_fs);
conf_ptr->wait_time = slurmctld_conf.wait_time;
return;
}
/* return true if supplied uid is a super-user: root, self, or SlurmUser */
static inline bool _is_super_user(uid_t uid)
{
/* READ lock_slurmctld config would be ideal here, but
* that value should be identical to getuid() anyway.
* privileged calls should be coming from user root too,
* so we forgo the overhead here. */
if ( (uid == 0) ||
(uid == slurmctld_conf.slurm_user_id) ||
(uid == getuid()) )
return true;
else
return false;
}
/* _kill_job_on_msg_fail - The request to create a job record successed,
* but the reply message to srun failed. We kill the job to avoid
* leaving it orphaned */
static void _kill_job_on_msg_fail(uint32_t job_id)
{
/* Locks: Write job, write node */
slurmctld_lock_t job_write_lock = {
NO_LOCK, WRITE_LOCK, WRITE_LOCK, NO_LOCK };
error("Job allocate response msg send failure, killing JobId=%u",
job_id);
lock_slurmctld(job_write_lock);
job_complete(job_id, 0, false, 0);
unlock_slurmctld(job_write_lock);
}
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/* create a credential for a given job step, return error code */
static int _make_step_cred(struct step_record *step_rec,
slurm_cred_t *slurm_cred)
{
slurm_cred_arg_t cred_arg;
cred_arg.jobid = step_rec->job_ptr->job_id;
cred_arg.stepid = step_rec->step_id;
cred_arg.uid = step_rec->job_ptr->user_id;
cred_arg.hostlist = step_rec->step_node_list;
if ( (*slurm_cred = slurm_cred_create(slurmctld_config.cred_ctx,
&cred_arg)) == NULL) {
error("slurm_cred_create error");
return ESLURM_INVALID_JOB_CREDENTIAL;
}
return SLURM_SUCCESS;
}
/* _slurm_rpc_allocate_resources: process RPC to allocate resources for
* a job */
static void _slurm_rpc_allocate_resources(slurm_msg_t * msg)
{
/* init */
int error_code = SLURM_SUCCESS;
slurm_msg_t response_msg;
DEF_TIMERS;
job_desc_msg_t *job_desc_msg = (job_desc_msg_t *) msg->data;
resource_allocation_response_msg_t alloc_msg;
/* Locks: Read config, write job, write node, read partition */
slurmctld_lock_t job_write_lock = {
READ_LOCK, WRITE_LOCK, WRITE_LOCK, READ_LOCK };
uid_t uid;
int immediate = job_desc_msg->immediate;
bool do_unlock = false;
struct job_record *job_ptr;
START_TIMER;
debug2("Processing RPC: REQUEST_RESOURCE_ALLOCATION");
/* do RPC call */
dump_job_desc(job_desc_msg);
uid = g_slurm_auth_get_uid(msg->cred);
if ( (uid != job_desc_msg->user_id) && (!_is_super_user(uid)) ) {
error_code = ESLURM_USER_ID_MISSING;
error("Security violation, RESOURCE_ALLOCATE from uid=%u",
(unsigned int) uid);
}
if (error_code == SLURM_SUCCESS) {
do_unlock = true;
lock_slurmctld(job_write_lock);
error_code = job_allocate(job_desc_msg,
immediate, false, true, uid, &job_ptr);
/* unlock after finished using the job structure data */
END_TIMER;
}
/* return result */
if ((error_code == SLURM_SUCCESS) ||
((immediate == 0) &&
(error_code == ESLURM_REQUESTED_PART_CONFIG_UNAVAILABLE))) {
xassert(job_ptr);
info("_slurm_rpc_allocate_resources JobId=%u NodeList=%s %s",
job_ptr->job_id, job_ptr->nodes, TIME_STR);
/* send job_ID and node_name_ptr */
alloc_msg.cpu_count_reps = xmalloc(sizeof(uint32_t) *
job_ptr->num_cpu_groups);
memcpy(alloc_msg.cpu_count_reps, job_ptr->cpu_count_reps,
(sizeof(uint32_t) * job_ptr->num_cpu_groups));
alloc_msg.cpus_per_node = xmalloc(sizeof(uint32_t) *
job_ptr->num_cpu_groups);
memcpy(alloc_msg.cpus_per_node, job_ptr->cpus_per_node,
(sizeof(uint32_t) * job_ptr->num_cpu_groups));
alloc_msg.error_code = error_code;
alloc_msg.job_id = job_ptr->job_id;
alloc_msg.node_addr = xmalloc(sizeof(slurm_addr) *
job_ptr->node_cnt);
memcpy(alloc_msg.node_addr, job_ptr->node_addr,
(sizeof(slurm_addr) * job_ptr->node_cnt));
alloc_msg.node_cnt = job_ptr->node_cnt;
alloc_msg.node_list = xstrdup(job_ptr->nodes);
alloc_msg.num_cpu_groups = job_ptr->num_cpu_groups;
alloc_msg.select_jobinfo = select_g_copy_jobinfo(job_ptr->select_jobinfo);
unlock_slurmctld(job_write_lock);
response_msg.msg_type = RESPONSE_RESOURCE_ALLOCATION;
response_msg.data = &alloc_msg;
if (slurm_send_node_msg(msg->conn_fd, &response_msg) < 0)
_kill_job_on_msg_fail(job_ptr->job_id);
xfree(alloc_msg.cpu_count_reps);
xfree(alloc_msg.cpus_per_node);
xfree(alloc_msg.node_addr);
xfree(alloc_msg.node_list);
select_g_free_jobinfo(&alloc_msg.select_jobinfo);
schedule_job_save(); /* has own locks */
schedule_node_save(); /* has own locks */
} else { /* allocate error */
if (do_unlock)
unlock_slurmctld(job_write_lock);
info("_slurm_rpc_allocate_resources: %s ",
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
}
}
/* _slurm_rpc_allocate_and_run: process RPC to allocate resources for a job
* and initiate a job step */
static void _slurm_rpc_allocate_and_run(slurm_msg_t * msg)
{
/* init */
int error_code = SLURM_SUCCESS;
slurm_msg_t response_msg;
DEF_TIMERS;
job_desc_msg_t *job_desc_msg = (job_desc_msg_t *) msg->data;
resource_allocation_and_run_response_msg_t alloc_msg;
struct step_record *step_rec;
struct job_record *job_ptr;
slurm_cred_t slurm_cred;
job_step_create_request_msg_t req_step_msg;
/* Locks: Write job, write node, read partition */
slurmctld_lock_t job_write_lock = {
NO_LOCK, WRITE_LOCK, WRITE_LOCK, READ_LOCK };
uid_t uid;
int immediate = true; /* implicit job_desc_msg->immediate == true */
START_TIMER;
debug2("Processing RPC: REQUEST_ALLOCATE_AND_RUN_JOB_STEP");
/* do RPC call */
dump_job_desc(job_desc_msg);
uid = g_slurm_auth_get_uid(msg->cred);
if ( (uid != job_desc_msg->user_id) && (!_is_super_user(uid)) ) {
error("Security violation, ALLOCATE_AND_RUN RPC from uid=%u",
(unsigned int) uid);
slurm_send_rc_msg(msg, ESLURM_USER_ID_MISSING);
return;
}
#ifdef HAVE_FRONT_END /* Limited job step support */
/* Non-super users not permitted to run job steps on front-end.
* A single slurmd can not handle a heavy load. */
if (!_is_super_user(uid)) {
info("Attempt to execute job step by uid=%u",
(unsigned int) uid);
slurm_send_rc_msg(msg, ESLURM_BATCH_ONLY);
return;
}
#endif
lock_slurmctld(job_write_lock);
error_code = job_allocate(job_desc_msg,
immediate, false, true, uid, &job_ptr);
/* return result */
if (error_code) {
unlock_slurmctld(job_write_lock);
info("_slurm_rpc_allocate_and_run: %s",
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
return;
}
req_step_msg.job_id = job_ptr->job_id;
req_step_msg.user_id = job_desc_msg->user_id;
#ifdef HAVE_FRONT_END /* Execute only on front-end */
req_step_msg.node_count = 1;
req_step_msg.cpu_count = NO_VAL;
#else
req_step_msg.node_count = INFINITE;
req_step_msg.cpu_count = job_desc_msg->num_procs;
req_step_msg.num_tasks = job_desc_msg->num_tasks;
req_step_msg.task_dist = job_desc_msg->task_dist;
error_code = step_create(&req_step_msg, &step_rec, true);
if (error_code == SLURM_SUCCESS) {
error_code = _make_step_cred(step_rec, &slurm_cred);
END_TIMER;
}
/* note: no need to free step_rec, pointer to global job step record */
if (error_code) {
job_complete(job_ptr->job_id, job_desc_msg->user_id, false, 0);
unlock_slurmctld(job_write_lock);
info("_slurm_rpc_allocate_and_run creating job step: %s",
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
info("_slurm_rpc_allocate_and_run JobId=%u NodeList=%s %s",
job_ptr->job_id, job_ptr->nodes, TIME_STR);
/* send job_ID and node_name_ptr */
alloc_msg.job_id = job_ptr->job_id;
alloc_msg.node_list = job_ptr->nodes;
alloc_msg.num_cpu_groups = job_ptr->num_cpu_groups;
alloc_msg.cpus_per_node = job_ptr->cpus_per_node;
alloc_msg.cpu_count_reps = job_ptr->cpu_count_reps;
alloc_msg.job_step_id = step_rec->step_id;
alloc_msg.node_cnt = job_ptr->node_cnt;
alloc_msg.node_addr = job_ptr->node_addr;
alloc_msg.cred = slurm_cred;
alloc_msg.switch_job = switch_copy_jobinfo(
step_rec->switch_job);
unlock_slurmctld(job_write_lock);
response_msg.msg_type = RESPONSE_ALLOCATION_AND_RUN_JOB_STEP;
response_msg.data = &alloc_msg;
if (slurm_send_node_msg(msg->conn_fd, &response_msg) < 0)
_kill_job_on_msg_fail(job_ptr->job_id);
slurm_cred_destroy(slurm_cred);
switch_free_jobinfo(alloc_msg.switch_job);
schedule_job_save(); /* has own locks */
schedule_node_save(); /* has own locks */
}
}
/* _slurm_rpc_dump_conf - process RPC for Slurm configuration information */
static void _slurm_rpc_dump_conf(slurm_msg_t * msg)
{
DEF_TIMERS;
slurm_msg_t response_msg;
last_update_msg_t *last_time_msg = (last_update_msg_t *) msg->data;
slurm_ctl_conf_info_msg_t config_tbl;
/* Locks: Read config */
slurmctld_lock_t config_read_lock = {
READ_LOCK, NO_LOCK, NO_LOCK, NO_LOCK };
START_TIMER;
debug2("Processing RPC: REQUEST_BUILD_INFO");
lock_slurmctld(config_read_lock);
/* check to see if configuration data has changed */
if ((last_time_msg->last_update - 1) >= slurmctld_conf.last_update) {
unlock_slurmctld(config_read_lock);
debug2("_slurm_rpc_dump_conf, no change");
slurm_send_rc_msg(msg, SLURM_NO_CHANGE_IN_DATA);
} else {
_fill_ctld_conf(&config_tbl);
unlock_slurmctld(config_read_lock);
END_TIMER;
debug2("_slurm_rpc_dump_conf %s", TIME_STR);
/* init response_msg structure */
response_msg.address = msg->address;
response_msg.msg_type = RESPONSE_BUILD_INFO;
response_msg.data = &config_tbl;
/* send message */
slurm_send_node_msg(msg->conn_fd, &response_msg);
free_slurm_conf(&config_tbl);
}
}
/* _slurm_rpc_dump_jobs - process RPC for job state information */
static void _slurm_rpc_dump_jobs(slurm_msg_t * msg)
{
DEF_TIMERS;
char *dump;
int dump_size;
slurm_msg_t response_msg;
job_info_request_msg_t *job_info_request_msg =
(job_info_request_msg_t *) msg->data;
/* Locks: Read job, write node (for hiding) */
slurmctld_lock_t job_read_lock = {
NO_LOCK, READ_LOCK, NO_LOCK, WRITE_LOCK };
START_TIMER;
debug2("Processing RPC: REQUEST_JOB_INFO");
lock_slurmctld(job_read_lock);
if ((job_info_request_msg->last_update - 1) >= last_job_update) {
unlock_slurmctld(job_read_lock);
debug2("_slurm_rpc_dump_jobs, no change");
slurm_send_rc_msg(msg, SLURM_NO_CHANGE_IN_DATA);
} else {
pack_all_jobs(&dump, &dump_size,
job_info_request_msg->show_flags,
g_slurm_auth_get_uid(msg->cred));
unlock_slurmctld(job_read_lock);
END_TIMER;
debug2("_slurm_rpc_dump_jobs, size=%d %s",
dump_size, TIME_STR);
/* init response_msg structure */
response_msg.address = msg->address;
response_msg.msg_type = RESPONSE_JOB_INFO;
response_msg.data = dump;
response_msg.data_size = dump_size;
/* send message */
slurm_send_node_msg(msg->conn_fd, &response_msg);
xfree(dump);
}
}
/* _slurm_rpc_dump_nodes - process RPC for node state information */
static void _slurm_rpc_dump_nodes(slurm_msg_t * msg)
{
DEF_TIMERS;
char *dump;
int dump_size;
slurm_msg_t response_msg;
node_info_request_msg_t *node_req_msg =
(node_info_request_msg_t *) msg->data;
/* Locks: Read config, read node, write node (for hiding) */
slurmctld_lock_t node_read_lock = {
READ_LOCK, NO_LOCK, READ_LOCK, WRITE_LOCK };
START_TIMER;
debug2("Processing RPC: REQUEST_NODE_INFO");
lock_slurmctld(node_read_lock);
if ((node_req_msg->last_update - 1) >= last_node_update) {
unlock_slurmctld(node_read_lock);
debug2("_slurm_rpc_dump_nodes, no change");
slurm_send_rc_msg(msg, SLURM_NO_CHANGE_IN_DATA);
} else {
pack_all_node(&dump, &dump_size, node_req_msg->show_flags,
g_slurm_auth_get_uid(msg->cred));
unlock_slurmctld(node_read_lock);
END_TIMER;
debug2("_slurm_rpc_dump_nodes, size=%d %s",
dump_size, TIME_STR);
/* init response_msg structure */
response_msg.address = msg->address;
response_msg.msg_type = RESPONSE_NODE_INFO;
response_msg.data = dump;
response_msg.data_size = dump_size;
/* send message */
slurm_send_node_msg(msg->conn_fd, &response_msg);
xfree(dump);
}
}
/* _slurm_rpc_dump_partitions - process RPC for partition state information */
static void _slurm_rpc_dump_partitions(slurm_msg_t * msg)
{
DEF_TIMERS;
char *dump;
int dump_size;
slurm_msg_t response_msg;
part_info_request_msg_t *part_req_msg = (part_info_request_msg_t *) msg->data;
/* Locks: Read partition */
slurmctld_lock_t part_read_lock = {
NO_LOCK, NO_LOCK, NO_LOCK, READ_LOCK };
START_TIMER;
debug2("Processing RPC: REQUEST_PARTITION_INFO");
lock_slurmctld(part_read_lock);
if ((part_req_msg->last_update - 1) >= last_part_update) {
unlock_slurmctld(part_read_lock);
debug2("_slurm_rpc_dump_partitions, no change");
slurm_send_rc_msg(msg, SLURM_NO_CHANGE_IN_DATA);
} else {
pack_all_part(&dump, &dump_size, part_req_msg->show_flags,
g_slurm_auth_get_uid(msg->cred));
unlock_slurmctld(part_read_lock);
END_TIMER;
debug2("_slurm_rpc_dump_partitions, size=%d %s",
dump_size, TIME_STR);
/* init response_msg structure */
response_msg.address = msg->address;
response_msg.msg_type = RESPONSE_PARTITION_INFO;
response_msg.data = dump;
response_msg.data_size = dump_size;
/* send message */
slurm_send_node_msg(msg->conn_fd, &response_msg);
xfree(dump);
}
}
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/* _slurm_rpc_epilog_complete - process RPC noting the completion of
* the epilog denoting the completion of a job it its entirety */
static void _slurm_rpc_epilog_complete(slurm_msg_t * msg)
{
DEF_TIMERS;
/* Locks: Write job, write node */
slurmctld_lock_t job_write_lock = {
NO_LOCK, WRITE_LOCK, WRITE_LOCK, NO_LOCK };
uid_t uid;
epilog_complete_msg_t *epilog_msg =
(epilog_complete_msg_t *) msg->data;
bool run_scheduler = false;
START_TIMER;
debug2("Processing RPC: MESSAGE_EPILOG_COMPLETE");
uid = g_slurm_auth_get_uid(msg->cred);
if (!_is_super_user(uid)) {
error("Security violation, EPILOG_COMPLETE RPC from uid=%u",
(unsigned int) uid);
return;
}
lock_slurmctld(job_write_lock);
if (job_epilog_complete(epilog_msg->job_id, epilog_msg->node_name,
epilog_msg->return_code))
run_scheduler = true;
unlock_slurmctld(job_write_lock);
END_TIMER;
if (epilog_msg->return_code)
error("_slurm_rpc_epilog_complete JobId=%u Node=%s Err=%s %s",
epilog_msg->job_id, epilog_msg->node_name,
slurm_strerror(epilog_msg->return_code), TIME_STR);
else
debug2("_slurm_rpc_epilog_complete JobId=%u Node=%s %s",
epilog_msg->job_id, epilog_msg->node_name,
TIME_STR);
/* Functions below provide their own locking */
if (run_scheduler) {
(void) schedule();
schedule_node_save();
schedule_job_save();
/* NOTE: RPC has no response */
}
/* _slurm_rpc_job_step_kill - process RPC to cancel an entire job or
* an individual job step */
static void _slurm_rpc_job_step_kill(slurm_msg_t * msg)
{
/* init */
int error_code = SLURM_SUCCESS;
DEF_TIMERS;
job_step_kill_msg_t *job_step_kill_msg =
(job_step_kill_msg_t *) msg->data;
/* Locks: Read config, write job, write node */
slurmctld_lock_t job_write_lock = {
READ_LOCK, WRITE_LOCK, WRITE_LOCK, NO_LOCK };
uid_t uid;
START_TIMER;
debug2("Processing RPC: REQUEST_CANCEL_JOB_STEP");
uid = g_slurm_auth_get_uid(msg->cred);
lock_slurmctld(job_write_lock);
/* do RPC call */
if (job_step_kill_msg->job_step_id == NO_VAL) {
error_code = job_signal(job_step_kill_msg->job_id,
job_step_kill_msg->signal,
job_step_kill_msg->batch_flag, uid);
unlock_slurmctld(job_write_lock);
END_TIMER;
/* return result */
if (error_code) {
info("_slurm_rpc_job_step_kill JobId=%u: %s",
job_step_kill_msg->job_id,
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
info("_slurm_rpc_job_step_kill JobId=%u %s",
job_step_kill_msg->job_id, TIME_STR);
slurm_send_rc_msg(msg, SLURM_SUCCESS);
/* Below function provides its own locking */
schedule_job_save();
}
} else {
error_code = job_step_signal(job_step_kill_msg->job_id,
job_step_kill_msg->job_step_id,
job_step_kill_msg->signal,
uid);
unlock_slurmctld(job_write_lock);
END_TIMER;
/* return result */
if (error_code) {
info("_slurm_rpc_job_step_kill StepId=%u.%u: %s",
job_step_kill_msg->job_id,
job_step_kill_msg->job_step_id,
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
info("_slurm_rpc_job_step_kill StepId=%u.%u %s",
job_step_kill_msg->job_id,
job_step_kill_msg->job_step_id, TIME_STR);
slurm_send_rc_msg(msg, SLURM_SUCCESS);
/* Below function provides its own locking */
schedule_job_save();
}
}
}
/* _slurm_rpc_job_step_complete - process RPC to note the completion an
* entire job or an individual job step */
static void _slurm_rpc_job_step_complete(slurm_msg_t * msg)
{
int error_code = SLURM_SUCCESS;
DEF_TIMERS;
complete_job_step_msg_t *complete_job_step_msg =
(complete_job_step_msg_t *) msg->data;
/* Locks: Write job, write node */
slurmctld_lock_t job_write_lock = {
NO_LOCK, WRITE_LOCK, WRITE_LOCK, NO_LOCK
};
uid_t uid;
bool job_requeue = false;
bool dump_job = false, dump_node = false;
/* init */
START_TIMER;
debug2("Processing RPC: REQUEST_COMPLETE_JOB_STEP");
uid = g_slurm_auth_get_uid(msg->cred);
if (!_is_super_user(uid)) {
/* Don't trust slurm_rc, it is not from slurmd */
complete_job_step_msg->slurm_rc = SLURM_SUCCESS;
}
lock_slurmctld(job_write_lock);
/* do RPC call */
/* First set node DOWN if fatal error */
if (complete_job_step_msg->slurm_rc == ESLURM_ALREADY_DONE) {
/* race condition on job termination, not a real error */
info("slurmd error running JobId=%u from node=%s: %s",
complete_job_step_msg->job_id,
complete_job_step_msg->node_name,
slurm_strerror(complete_job_step_msg->slurm_rc));
complete_job_step_msg->slurm_rc = SLURM_SUCCESS;
}
if (complete_job_step_msg->slurm_rc != SLURM_SUCCESS) {
error("Fatal slurmd error running JobId=%u from node=%s: %s",
complete_job_step_msg->job_id,
complete_job_step_msg->node_name,
slurm_strerror(complete_job_step_msg->slurm_rc));
if (error_code == SLURM_SUCCESS) {
update_node_msg_t update_node_msg;
update_node_msg.node_names =
complete_job_step_msg->node_name;
update_node_msg.node_state = NODE_STATE_DOWN;
update_node_msg.reason = "step complete failure";
error_code = update_node(&update_node_msg);
if (complete_job_step_msg->job_rc != SLURM_SUCCESS)
job_requeue = true;
dump_job = true;
dump_node = true;
}
}
/* Mark job and/or job step complete */
if (complete_job_step_msg->job_step_id == NO_VAL) {
error_code = job_complete(complete_job_step_msg->job_id,
uid, job_requeue,
complete_job_step_msg->job_rc);
unlock_slurmctld(job_write_lock);
END_TIMER;
/* return result */
if (error_code) {
info("_slurm_rpc_job_step_complete JobId=%u: %s ",
complete_job_step_msg->job_id,
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
debug2("_slurm_rpc_job_step_complete JobId=%u %s",
complete_job_step_msg->job_id, TIME_STR);
slurm_send_rc_msg(msg, SLURM_SUCCESS);
dump_job = true;
}
} else {
error_code =
job_step_complete(complete_job_step_msg->job_id,
complete_job_step_msg->job_step_id,
uid, job_requeue,
complete_job_step_msg->job_rc);
unlock_slurmctld(job_write_lock);
END_TIMER;
/* return result */
if (error_code) {
info("_slurm_rpc_job_step_complete StepId=%u.%u: %s",
complete_job_step_msg->job_id,
complete_job_step_msg->job_step_id,
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
info("_slurm_rpc_job_step_complete StepId=%u.%u %s",
complete_job_step_msg->job_id,
complete_job_step_msg->job_step_id, TIME_STR);
slurm_send_rc_msg(msg, SLURM_SUCCESS);
dump_job = true;
}
}
if (dump_job)
(void) schedule_job_save(); /* Has own locking */
if (dump_node)
(void) schedule_node_save(); /* Has own locking */
}
/* _slurm_rpc_job_step_create - process RPC to creates/registers a job step
* with the step_mgr */
static void _slurm_rpc_job_step_create(slurm_msg_t * msg)
{
/* init */
int error_code = SLURM_SUCCESS;
DEF_TIMERS;
slurm_msg_t resp;
struct step_record *step_rec;
job_step_create_response_msg_t job_step_resp;
job_step_create_request_msg_t *req_step_msg =
(job_step_create_request_msg_t *) msg->data;
slurm_cred_t slurm_cred;
/* Locks: Write jobs, read nodes */
slurmctld_lock_t job_write_lock = {
NO_LOCK, WRITE_LOCK, READ_LOCK, NO_LOCK };
uid_t uid;
START_TIMER;
debug2("Processing RPC: REQUEST_JOB_STEP_CREATE");
dump_step_desc(req_step_msg);
uid = g_slurm_auth_get_uid(msg->cred);
if ( (uid != req_step_msg->user_id) && (!_is_super_user(uid)) ) {
error("Security violation, JOB_STEP_CREATE RPC from uid=%u",
(unsigned int) uid);
slurm_send_rc_msg(msg, ESLURM_USER_ID_MISSING);
return;
}
#ifdef HAVE_FRONT_END /* Limited job step support */
/* Non-super users not permitted to run job steps on front-end.
* A single slurmd can not handle a heavy load. */
if (!_is_super_user(uid)) {
info("Attempt to execute job step by uid=%u",
(unsigned int) uid);
slurm_send_rc_msg(msg, ESLURM_BATCH_ONLY);
if (error_code == SLURM_SUCCESS) {
/* issue the RPC */
lock_slurmctld(job_write_lock);
error_code = step_create(req_step_msg, &step_rec, false);
}
if (error_code == SLURM_SUCCESS)
error_code = _make_step_cred(step_rec, &slurm_cred);
END_TIMER;
/* return result */
if (error_code) {
unlock_slurmctld(job_write_lock);
info("_slurm_rpc_job_step_create: %s",
slurm_strerror(error_code));
slurm_send_rc_msg(msg, error_code);
} else {
info("_slurm_rpc_job_step_create: StepId=%u.%u %s",
step_rec->job_ptr->job_id, step_rec->step_id, TIME_STR);
job_step_resp.job_step_id = step_rec->step_id;
job_step_resp.node_list = xstrdup(step_rec->step_node_list);
job_step_resp.cred = slurm_cred;
job_step_resp.switch_job = switch_copy_jobinfo(
step_rec->switch_job);