#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <slurm/slurm_errno.h>
#include <stdlib.h>
#include <string.h>
#include "src/common/log.h"
#include "src/common/node_select.h"
#include "src/common/xmalloc.h"
#include "src/common/xstring.h"
#include "src/slurmctld/basil_interface.h"
#include "src/slurmctld/slurmctld.h"
#define BASIL_DEBUG 1
#ifdef HAVE_CRAY_XT
#ifndef APBASIL_LOC
static int last_res_id = 0;
#endif
#ifdef APBASIL_LOC
static void _validate_basil_node_id(void)
{
int i;
struct node_record *node_ptr = node_record_table_ptr;
for (i=0; i<node_record_cnt; i++, node_ptr++)
if (node_ptr->basil_node_id != NO_VAL)
continue;
if (IS_NODE_DOWN(node_ptr))
continue;
error("Node %s has no basil node_id", node_ptr->name);
last_node_update = time(NULL);
set_node_down(node_ptr->name, "No BASIL node_id");
}
}
#endif
#endif
extern int basil_query(void)
{
int error_code = SLURM_SUCCESS;
#ifdef HAVE_CRAY_XT
#ifdef APBASIL_LOC
struct config_record *config_ptr;
struct node_record *node_ptr;
struct job_record *job_ptr;
ListIterator job_iterator;
int i;
char *reason, *res_id;
static bool first_run = true;
if (request_failure) {
fatal("basil query error: %s", "TBD");
return SLURM_ERROR;
}
debug("basil query initiated");
if (first_run) {
node_ptr = node_record_table_ptr;
for (i=0; i<node_record_cnt; i++, node_ptr++)
node_ptr->basil_node_id = NO_VAL;
first_run = false;
}
for (each_basil_node) {
#if BASIL_DEBUG
info("basil query: name=%s arch=%s",
basil_node_name, basil_node_arch, etc.);
#endif
node_ptr = find_node_record(basil_node_name);
if (node_ptr == NULL) {
error("basil node %s not found in slurm",
basil_node_name);
continue;
}
node_ptr->basil_node_id = basil_node_id;
if (node_ptr->arch == NULL) {
xfree(node_ptr->arch);
node_ptr->arch = xstrdup(basil_node_arch);
}
reason = NULL;
if (!IS_NODE_DOWN(node_ptr)) {
if (strcmp(basil_state, "UP"))
reason = "basil state not UP";
else if (strcmp(basil_role, "BATCH"))
reason = "basil role not BATCH";
}
config_ptr = node_ptr->config_ptr;
if ((slurmctld_conf.fast_schedule != 2) &&
(basil_cpus < config_ptr->cpus)) {
error("Node %s has low cpu count %d",
node_ptr->name, basil_cpus);
reason = "Low CPUs";
}
node_ptr->cpus = basil_cpus;
if ((slurmctld_conf.fast_schedule != 2) &&
(basil_memory < config_ptr->real_memory)) {
error("Node %s has low real_memory size %d",
node_ptr->name, basil_memory);
reason = "Low RealMemory";
}
node_ptr->real_memory = basil_memory;
if (reason) {
last_node_update = time(NULL);
set_node_down(node_ptr->name, reason);
}
}
_validate_basil_node_id();
for (each_basil_reservation) {
bool found = false;
job_iterator = list_iterator_create(job_list);
while ((job_ptr = (struct job_record *)
list_next(job_iterator))) {
select_g_get_jobinfo(job_ptr->select_jobinfo,
SELECT_DATA_RESV_ID, &res_id);
found = !strcmp(res_id, basil_reservation_id);
xfree(res_id);
if (found)
break;
}
list_iterator_destroy(job_iterator);
if (found) {
error("vestigial basil reservation %s being removed",
basil_reservation_id);
basil_dealloc(basil_reservation_id);
}
}
#else
struct job_record *job_ptr;
ListIterator job_iterator;
char *res_id, *tmp;
int job_res_id;
job_iterator = list_iterator_create(job_list);
while ((job_ptr = (struct job_record *) list_next(job_iterator))) {
res_id = NULL;
select_g_get_jobinfo(job_ptr->select_jobinfo,
SELECT_DATA_RESV_ID, &res_id);
if (res_id) {
tmp = strchr(res_id, '_');
if (tmp) {
job_res_id = atoi(tmp+1);
last_res_id = MAX(last_res_id, job_res_id);
}
xfree(res_id);
}
}
list_iterator_destroy(job_iterator);
debug("basil_query() executed, last_res_id=%d", last_res_id);
#endif
#endif
return error_code;
}
extern int basil_reserve(struct job_record *job_ptr)
{
int error_code = SLURM_SUCCESS;
#ifdef HAVE_CRAY_XT
#ifdef APBASIL_LOC
if (request_failure) {
error("basil reserve error: %s", "TBD");
return SLURM_ERROR;
}
select_g_set_jobinfo(job_ptr->select_jobinfo,
SELECT_DATA_RESV_ID, reservation_id);
debug("basil reservation made job_id=%u resv_id=%s",
job_ptr->job_id, reservation_id);
#else
char reservation_id[32];
snprintf(reservation_id, sizeof(reservation_id),
"resv_%d", ++last_res_id);
select_g_set_jobinfo(job_ptr->select_jobinfo,
SELECT_DATA_RESV_ID, reservation_id);
debug("basil reservation made job_id=%u resv_id=%s",
job_ptr->job_id, reservation_id);
#endif
#endif
return error_code;
}
extern int basil_release(struct job_record *job_ptr)
{
int error_code = SLURM_SUCCESS;
#ifdef HAVE_CRAY_XT
char *reservation_id = NULL;
select_g_get_jobinfo(job_ptr->select_jobinfo,
SELECT_DATA_RESV_ID, &reservation_id);
if (reservation_id) {
error_code = basil_release_id(reservation_id);
xfree(reservation_id);
}
#endif
return error_code;
}
extern int basil_release_id(char *reservation_id)
{
int error_code = SLURM_SUCCESS;
#ifdef HAVE_CRAY_XT
#ifdef APBASIL_LOC
if (request_failure) {
error("basil release of %s error: %s", reservation_id, "TBD");
return SLURM_ERROR;
}
debug("basil release of reservation %s complete", reservation_id);
#else
debug("basil release of reservation %s complete", reservation_id);
#endif
#endif
return error_code;
}