Skip to content
Snippets Groups Projects
Commit ceb8bad4 authored by Moe Jette's avatar Moe Jette
Browse files

Change format of test in api/build_info.c

Updated scontrol/scontrol.c for new APIs
parent 4d5c9379
No related branches found
No related tags found
No related merge requests found
......@@ -3,10 +3,14 @@
* provides interface to read, write, update, and configurations.
*/
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "slurmlib.h"
#define BUF_SIZE 1024
......@@ -20,14 +24,16 @@ static int input_words; /* number of words of input permitted */
void dump_command (int argc, char *argv[]);
int get_command (int *argc, char *argv[]);
void print_build (char *build_param);
void print_node (char *node_name);
void print_node (char *node_name, struct node_buffer *node_buffer_ptr);
void print_node_list (char *node_list);
void print_part (char *partition_name);
int process_command (int argc, char *argv[]);
int update_it (int argc, char *argv[]);
void usage ();
main (int argc, char *argv[]) {
int
main (int argc, char *argv[])
{
int error_code, i, input_field_count;
char **input_fields;
......@@ -55,7 +61,7 @@ main (int argc, char *argv[]) {
}
else {
input_fields[input_field_count++] = argv[i];
} /* else */
}
}
if (input_field_count)
......@@ -88,7 +94,8 @@ main (int argc, char *argv[]) {
* argv - the arguments
*/
void
dump_command (int argc, char *argv[]) {
dump_command (int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++) {
......@@ -103,7 +110,9 @@ dump_command (int argc, char *argv[]) {
* argv - location to store the argument list
* output: returns error code, 0 if no problems
*/
int get_command (int *argc, char **argv) {
int
get_command (int *argc, char **argv)
{
static char *in_line;
static int in_line_size = 0;
int in_line_pos = 0;
......@@ -169,93 +178,131 @@ int get_command (int *argc, char **argv) {
* print_build - print the specified build parameter and value
* input: build_param - NULL to print all parameters and values
*/
void print_build (char *build_param) {
char req_name[BUILD_SIZE], next_name[BUILD_SIZE], value[BUILD_SIZE];
void
print_build (char *build_param)
{
int error_code;
error_code = slurm_load_build ();
if (error_code) {
static struct build_buffer *old_build_buffer_ptr = NULL;
struct build_buffer *build_buffer_ptr = NULL;
struct build_table *build_table_ptr = NULL;
if (old_build_buffer_ptr) {
error_code = slurm_load_build (old_build_buffer_ptr->last_update,
&build_buffer_ptr);
if (error_code == 0)
slurm_free_build_info(old_build_buffer_ptr);
else if (error_code == -1)
build_buffer_ptr = old_build_buffer_ptr;
}
else
error_code = slurm_load_build ((time_t) NULL, &build_buffer_ptr);
if (error_code > 0) {
if (quiet_flag != 1)
printf ("slurm_load_build error %d\n", error_code);
return;
}
if (build_param)
strncpy (req_name, build_param, BUILD_SIZE);
else
strcpy (req_name, ""); /* start at beginning of node list */
while (1) {
error_code = slurm_load_build_name (req_name, next_name, value);
if (error_code != 0) {
if (quiet_flag != 1) {
if (error_code == ENOENT)
printf ("no parameter %s found\n",
req_name);
else
printf ("error %d finding value for parameter %s\n",
error_code, req_name);
}
break;
}
printf ("%s=%s\n", req_name, value);
if (build_param || (strlen (next_name) == 0))
break;
strcpy (req_name, next_name);
}
/* slurm_free_build_info(); keep data for reuse, cleaned on exit */
}
old_build_buffer_ptr = build_buffer_ptr;
build_table_ptr = build_buffer_ptr->build_table_ptr;
if (build_param == NULL ||
strcmp (build_param, "BACKUP_INTERVAL") == 0)
printf ("BACKUP_INTERVAL = %u\n",
build_table_ptr->backup_interval);
if (build_param == NULL ||
strcmp (build_param, "BACKUP_LOCATION") == 0)
printf ("BACKUP_LOCATION = %s\n",
build_table_ptr->backup_location);
if (build_param == NULL ||
strcmp (build_param, "BACKUP_MACHINE") == 0)
printf ("BACKUP_MACHINE = %s\n",
build_table_ptr->backup_machine);
if (build_param == NULL ||
strcmp (build_param, "CONTROL_DAEMON") == 0)
printf ("CONTROL_DAEMON = %s\n",
build_table_ptr->control_daemon);
if (build_param == NULL ||
strcmp (build_param, "CONTROL_MACHINE") == 0)
printf ("CONTROL_MACHINE = %s\n",
build_table_ptr->control_machine);
if (build_param == NULL ||
strcmp (build_param, "EPILOG") == 0)
printf ("EPILOG = %s\n", build_table_ptr->epilog);
if (build_param == NULL ||
strcmp (build_param, "FAST_SCHEDULE") == 0)
printf ("FAST_SCHEDULE = %u\n",
build_table_ptr->fast_schedule);
if (build_param == NULL ||
strcmp (build_param, "HASH_BASE") == 0)
printf ("HASH_BASE = %u\n",
build_table_ptr->hash_base);
if (build_param == NULL ||
strcmp (build_param, "HEARTBEAT_INTERVAL") == 0)
printf ("HEARTBEAT_INTERVAL = %u\n",
build_table_ptr->heartbeat_interval);
if (build_param == NULL ||
strcmp (build_param, "INIT_PROGRAM") == 0)
printf ("INIT_PROGRAM = %s\n", build_table_ptr->init_program);
if (build_param == NULL ||
strcmp (build_param, "KILL_WAIT") == 0)
printf ("KILL_WAIT = %u\n", build_table_ptr->kill_wait);
if (build_param == NULL ||
strcmp (build_param, "PRIORITIZE") == 0)
printf ("PRIORITIZE = %s\n", build_table_ptr->prioritize);
if (build_param == NULL ||
strcmp (build_param, "PROLOG") == 0)
printf ("PROLOG = %s\n", build_table_ptr->prolog);
if (build_param == NULL ||
strcmp (build_param, "SERVER_DAEMON") == 0)
printf ("SERVER_DAEMON = %s\n",
build_table_ptr->server_daemon);
if (build_param == NULL ||
strcmp (build_param, "SERVER_TIMEOUT") == 0)
printf ("SERVER_TIMEOUT = %u\n",
build_table_ptr->server_timeout);
if (build_param == NULL ||
strcmp (build_param, "SLURM_CONF") == 0)
printf ("SLURM_CONF = %s\n", build_table_ptr->slurm_conf);
if (build_param == NULL ||
strcmp (build_param, "TMP_FS") == 0)
printf ("TMP_FS = %s\n", build_table_ptr->tmp_fs);
}
/*
* print_node - print the specified node's information
* input: node_name - NULL to print all node information
* node_ptr - pointer to node table of information
* NOTE: call this only after executing load_node, called from print_node_list
*/
void
print_node (char *node_name) {
int error_code, size, i;
char partition[MAX_NAME_LEN], node_state[MAX_NAME_LEN],
features[FEATURE_SIZE];
char req_name[MAX_NAME_LEN]; /* name of the partition */
char next_name[MAX_NAME_LEN]; /* name of the next partition */
int cpus, real_memory, tmp_disk, weight;
char *dump;
int dump_size;
time_t update_time;
unsigned *node_bitmap; /* bitmap of nodes in partition */
int bitmap_size; /* bytes in node_bitmap */
if (node_name)
strncpy (req_name, node_name, MAX_NAME_LEN);
else
strcpy (req_name, ""); /* start at beginning of node list */
while (1) {
error_code =
load_node_config (req_name, next_name, &cpus,
&real_memory, &tmp_disk, &weight,
features, partition, node_state);
if (error_code != 0) {
if (quiet_flag != 1) {
if (error_code == ENOENT)
printf ("no node %s found\n",
req_name);
else
printf ("error %d finding information for node %s\n", error_code, req_name);
}
print_node (char *node_name, struct node_buffer *node_buffer_ptr)
{
int i, j;
static int last_inx = 0;
struct node_table *node_ptr;
node_ptr = node_buffer_ptr->node_table_ptr;
for (j = 0; j < node_buffer_ptr->node_count; j++) {
if (node_name) {
i = (j + last_inx) % node_buffer_ptr->node_count;
if (strcmp (node_name, node_ptr[i].name) != 0)
continue;
}
else
i = j;
printf ("NodeName=%s CPUs=%u ",
node_ptr[i].name, node_ptr[i].cpus);
printf ("RealMemory=%u TmpDisk=%u ",
node_ptr[i].real_memory, node_ptr[i].tmp_disk);
printf ("State=%u Weight=%u ",
node_ptr[i].node_state, node_ptr[i].weight);
printf ("Features=%s Partition=%s\n",
node_ptr[i].features, node_ptr[i].partition);
if (node_name) {
last_inx = i;
break;
}
printf ("NodeName=%s CPUs=%d RealMemory=%d TmpDisk=%d ",
req_name, cpus, real_memory, tmp_disk);
printf ("State=%s Weight=%d Features=%s Partition=%s\n",
node_state, weight, features, partition);
}
}
if (node_name || (strlen (next_name) == 0))
break;
strcpy (req_name, next_name);
}
}
......@@ -264,25 +311,42 @@ print_node (char *node_name) {
* input: node_list - print information about the supplied node list (or regular expression)
*/
void
print_node_list (char *node_list) {
static time_t last_update_time = (time_t) NULL;
print_node_list (char *node_list)
{
static struct node_buffer *old_node_buffer_ptr = NULL;
struct node_buffer *node_buffer_ptr = NULL;
int start_inx, end_inx, count_inx, error_code, i;
char *str_ptr1, *str_ptr2, *format, *my_node_list,
this_node_name[BUF_SIZE];;
char *str_ptr1, *str_ptr2, *format, *my_node_list;
char this_node_name[BUF_SIZE];
error_code = load_node (&last_update_time);
if (error_code) {
if (old_node_buffer_ptr) {
error_code = slurm_load_node (old_node_buffer_ptr->last_update,
&node_buffer_ptr);
if (error_code == 0)
slurm_free_node_info (old_node_buffer_ptr);
else if (error_code == -1)
node_buffer_ptr = old_node_buffer_ptr;
}
else
error_code = slurm_load_node ((time_t) NULL, &node_buffer_ptr);
if (error_code > 0) {
if (quiet_flag != 1)
printf ("load_node error %d\n", error_code);
return;
}
}
else if (error_code == 0)
old_node_buffer_ptr = node_buffer_ptr;
if (quiet_flag == -1)
printf ("last_update_time=%ld\n", (long) last_update_time);
printf ("last_update_time=%ld\n", (long) node_buffer_ptr->last_update);
if (node_list == NULL) {
print_node (NULL);
print_node (NULL, node_buffer_ptr);
}
else {
format = NULL;
my_node_list = malloc (strlen (node_list) + 1);
if (my_node_list == NULL) {
if (quiet_flag != 1)
......@@ -319,15 +383,14 @@ print_node_list (char *node_list) {
sizeof (this_node_name));
else
sprintf (this_node_name, format, i);
print_node (this_node_name);
}
free (format);
print_node (this_node_name, node_buffer_ptr);
}
if (format)
free (format);
str_ptr2 = (char *) strtok_r (NULL, ",", &str_ptr1);
}
free (my_node_list);
} /* else */
/* free_node_info(); keep data for reuse, cleaned on exit */
}
return;
}
......@@ -336,66 +399,55 @@ print_node_list (char *node_list) {
* print_part - print the specified partition's information
* input: partition_name - NULL to print all partition information
*/
void print_part (char *partition_name) {
static time_t last_update_time = (time_t) NULL; /* time desired for data */
static char *yes_no[0] = { "NO", "YES" };
static char *up_down[0] = { "DOWN", "UP" };
char req_name[MAX_NAME_LEN]; /* name of the partition */
char next_name[MAX_NAME_LEN]; /* name of the next partition */
int max_time; /* -1 if unlimited */
int max_nodes; /* -1 if unlimited */
int total_nodes; /* total number of nodes in the partition */
int total_cpus; /* total number of cpus in the partition */
char nodes[FEATURE_SIZE]; /* names of nodes in partition */
char allow_groups[FEATURE_SIZE];/* NULL indicates all */
int key; /* 1 if slurm distributed key is required */
int state_up; /* 1 if state is up */
int shared; /* 1 if partition can be shared */
int default_flag; /* 1 if default partition */
int error_code;
error_code = load_part (&last_update_time);
if (error_code) {
void
print_part (char *partition_name)
{
int error_code, i;
static struct part_buffer *old_part_buffer_ptr = NULL;
struct part_buffer *part_buffer_ptr = NULL;
struct part_table *part_ptr = NULL;
if (old_part_buffer_ptr) {
error_code = slurm_load_part (old_part_buffer_ptr->last_update,
&part_buffer_ptr);
if (error_code == 0)
slurm_free_part_info (old_part_buffer_ptr);
else if (error_code == -1)
part_buffer_ptr = old_part_buffer_ptr;
}
else
error_code = slurm_load_part ((time_t) NULL, &part_buffer_ptr);
if (error_code > 0) {
if (quiet_flag != 1)
printf ("load_part error %d\n", error_code);
return;
}
if (quiet_flag == -1)
printf ("last_update_time=%ld\n", (long) last_update_time);
if (partition_name)
strncpy (req_name, partition_name, MAX_NAME_LEN);
else
strcpy (req_name, ""); /* start at beginning of partition list */
while (1) {
error_code =
load_part_name (req_name, next_name, &max_time,
&max_nodes, &total_nodes, &total_cpus,
&key, &state_up, &shared, &default_flag,
nodes, allow_groups);
if (error_code != 0) {
if (quiet_flag != 1) {
if (error_code == ENOENT)
printf ("no partition %s found\n",
req_name);
else
printf ("error %d finding information for partition %s\n", error_code, req_name);
}
break;
}
}
else if (error_code == 0)
old_part_buffer_ptr = part_buffer_ptr;
printf ("PartitionName=%s Nodes=%s MaxTime=%d MaxNodes=%d Default=%s ",
req_name, nodes, max_time, max_nodes, yes_no[default_flag]);
printf ("Key=%s State=%s Shared=%s AllowGroups=%s ",
yes_no[key], up_down[state_up], yes_no[shared], allow_groups);
printf ("TotalNodes=%d total_cpus=%d \n", total_nodes, total_cpus);
if (quiet_flag == -1)
printf ("last_update_time=%ld\n", (long) part_buffer_ptr->last_update);
if (partition_name || (strlen (next_name) == 0))
part_ptr = part_buffer_ptr->part_table_ptr;
for (i = 0; i < part_buffer_ptr->part_count; i++) {
if (partition_name &&
strcmp (partition_name, part_ptr[i].name) != 0)
continue;
printf ("PartitionName=%s MaxTime=%u ",
part_ptr[i].name, part_ptr[i].max_time);
printf ("MaxNodes=%u TotalNodes=%u ",
part_ptr[i].max_nodes, part_ptr[i].total_nodes);
printf ("TotalCPUs=%u Key=%u\n",
part_ptr[i].total_cpus, part_ptr[i].key);
printf (" Default=%u ",
part_ptr[i].default_part);
printf ("Shared=%u StateUp=%u ",
part_ptr[i].shared, part_ptr[i].state_up);
printf ("Nodes=%s AllowGroups=%s\n\n",
part_ptr[i].nodes, part_ptr[i].allow_groups);
if (partition_name)
break;
strcpy (req_name, next_name);
}
/* free_part_info(); keep data for reuse, cleaned on exit */
}
}
......@@ -406,7 +458,8 @@ void print_part (char *partition_name) {
* ourput: return code is 0 or errno (only for errors fatal to scontrol)
*/
int
process_command (int argc, char *argv[]) {
process_command (int argc, char *argv[])
{
int error_code;
if ((strcmp (argv[0], "exit") == 0) ||
......@@ -528,7 +581,8 @@ process_command (int argc, char *argv[]) {
* output: returns 0 if no error, errno otherwise
*/
int
update_it (int argc, char *argv[]) {
update_it (int argc, char *argv[])
{
char *in_line;
int error_code, i, in_line_size;
......@@ -568,7 +622,8 @@ usage () {
printf ("%s [-q | -v] [<keyword>]\n", command_name);
printf (" -q is equivalent to the keyword \"quiet\" described below.\n");
printf (" -v is equivalent to the keyword \"verbose\" described below.\n");
printf (" <keyword> may be omitted from the execute line and %s will execute in interactive\n");
printf (" <keyword> may be omitted from the execute line and %s will execute in interactive\n",
command_name);
printf (" mode to process multiple keywords (i.e. commands). valid <entity> values are:\n");
printf (" build, job, node, and partition. node names may be sepcified using regular simple \n");
printf (" expressions. valid <keyword> values are:\n");
......@@ -581,4 +636,4 @@ usage () {
printf (" update <options> update configuration per configuration file format.\n");
printf (" verbose enable detailed logging.\n");
printf (" version display tool version number.\n");
} /* usage */
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment