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

Added node read API with new communications library.

Minor cleanup (i.e. comments) on other APIs.
parent f370d04e
No related branches found
No related tags found
No related merge requests found
/*
* partition_info.c - get the partition information of slurm
* build_info.c - get the build information of slurm
* see slurm.h for documentation on external functions and data structures
*
* author: moe jette, jette@llnl.gov
......
/*
* job_info.c - get the job records of slurm
* see slurm.h for documentation on external functions and data structures
*
* author: moe jette, jette@llnl.gov
*/
/*****************************************************************************\
* job_info.c - get the job records of slurm
* see slurm.h for documentation on external functions and data structures
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Moe Jette <jette1@llnl.gov> et. al.
* 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 ConMan; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/
#define DEBUG_SYSTEM 1
......@@ -29,7 +49,7 @@ main (int argc, char *argv[])
error_code = slurm_load_jobs (last_update_time, &job_info_msg_ptr);
if (error_code) {
printf ("slurm_load_job error %d\n", error_code);
printf ("slurm_load_jobs error %d\n", error_code);
exit (error_code);
}
......@@ -56,7 +76,7 @@ slurm_print_job_info_msg ( job_info_msg_t * job_info_msg_ptr )
}
}
/* print an individual job_table row */
/* print an individual job_table entry */
void
slurm_print_job_table (job_table_t * job_ptr )
{
......@@ -96,18 +116,7 @@ slurm_print_job_table (job_table_t * job_ptr )
printf("\n\n");
}
/*
* slurm_load_job - load the supplied job information buffer for use by info
* gathering APIs if job records have changed since the time specified.
* input: update_time - time of last update
* job_buffer_ptr - place to park job_buffer pointer
* output: job_buffer_ptr - pointer to allocated job_buffer
* returns -1 if no update since update_time,
* 0 if update with no error,
* EINVAL if the buffer (version or otherwise) is invalid,
* ENOMEM if malloc failure
* NOTE: the allocated memory at job_info_msg_pptr freed by slurm_free_job_info.
*/
/* slurm_load_job - load the supplied job information buffer if changed */
int
slurm_load_jobs (time_t update_time, job_info_msg_t **job_info_msg_pptr)
{
......@@ -117,7 +126,7 @@ slurm_load_jobs (time_t update_time, job_info_msg_t **job_info_msg_pptr)
slurm_msg_t request_msg ;
slurm_msg_t response_msg ;
last_update_msg_t last_time_msg ;
return_code_msg_t * slurm_rc_msg ;
return_code_msg_t * slurm_rc_msg ;
/* init message connection for message communication with controller */
if ( ( sockfd = slurm_open_controller_conn ( SLURM_PORT ) ) == SLURM_SOCKET_ERROR )
......
/*
* node_info.c - get the node records of slurm
* see slurm.h for documentation on external functions and data structures
*
* author: moe jette, jette@llnl.gov
*/
/*****************************************************************************\
* node_info.c - get the node records of slurm
* see slurm.h for documentation on external functions and data structures
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Moe Jette <jette1@llnl.gov> et. al.
* 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 ConMan; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\*****************************************************************************/
#define DEBUG_SYSTEM 1
......@@ -22,7 +42,7 @@
#include <unistd.h>
#include "slurm.h"
#include "pack.h"
#include <src/common/slurm_protocol_api.h>
#if DEBUG_MODULE
/* main is used here for testing purposes only */
......@@ -31,173 +51,112 @@ main (int argc, char *argv[])
{
static time_t last_update_time = (time_t) NULL;
int error_code, i;
struct node_buffer *node_buffer_ptr = NULL;
struct node_table *node_ptr = NULL;
node_info_msg_t * node_info_msg_ptr = NULL;
node_table_t * node_ptr = node_info_msg_ptr -> node_array ;
error_code = slurm_load_node (last_update_time, &node_buffer_ptr);
error_code = slurm_load_node (last_update_time, &node_info_msg_ptr);
if (error_code) {
printf ("slurm_load_node error %d\n", error_code);
exit (error_code);
}
printf("Updated at %lx, record count %u\n",
node_buffer_ptr->last_update, node_buffer_ptr->node_count);
node_ptr = node_buffer_ptr->node_table_ptr;
printf("Nodes updated at %d, record count %d\n",
node_info_msg_ptr ->last_update, node_info_msg_ptr->record_count);
for (i = 0; i < node_buffer_ptr->node_count; i++) {
for (i = 0; i < node_info_msg_ptr-> record_count; i++)
{
/* to limit output we print only the first 10 entries,
* last 1 entry, and every 200th entry */
if ((i < 10) || (i % 200 == 0) ||
((i + 1) == node_buffer_ptr->node_count)) {
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);
((i + 1) == node_info_msg_ptr-> record_count)) {
slurm_print_node_table ( & node_ptr[i] ) ;
}
else if ((i==10) || (i % 200 == 1))
printf ("skipping...\n");
}
slurm_free_node_info (node_buffer_ptr);
}
slurm_free_node_info ( node_info_msg_ptr ) ;
exit (0);
}
#endif
/* print the entire node_info_msg */
void
slurm_print_node_info_msg ( node_info_msg_t * node_info_msg_ptr )
{
int i;
node_table_t * node_ptr = node_info_msg_ptr -> node_array ;
printf("Nodes updated at %d, record count %d\n",
node_info_msg_ptr ->last_update, node_info_msg_ptr->record_count);
for (i = 0; i < node_info_msg_ptr-> record_count; i++)
{
slurm_print_node_table ( & node_ptr[i] ) ;
}
}
/*
* slurm_free_node_info - free the node information buffer (if allocated)
* NOTE: buffer is loaded by slurm_load_node.
*/
/* print an individual node_table entry */
void
slurm_free_node_info (struct node_buffer *node_buffer_ptr)
slurm_print_node_table (node_table_t * node_ptr )
{
if (node_buffer_ptr == NULL)
return;
if (node_buffer_ptr->raw_buffer_ptr)
free (node_buffer_ptr->raw_buffer_ptr);
if (node_buffer_ptr->node_table_ptr)
free (node_buffer_ptr->node_table_ptr);
printf ("NodeName=%s CPUs=%u ",
node_ptr->name, node_ptr->cpus);
printf ("RealMemory=%u TmpDisk=%u ",
node_ptr->real_memory, node_ptr->tmp_disk);
printf ("State=%u Weight=%u ",
node_ptr->node_state, node_ptr->weight);
printf ("Features=%s Partition=%s\n\n",
node_ptr->features, node_ptr->partition);
}
/*
* slurm_load_node - load the supplied node information buffer for use by info
* gathering APIs if node records have changed since the time specified.
* input: update_time - time of last update
* node_buffer_ptr - place to park node_buffer pointer
* output: node_buffer_ptr - pointer to allocated node_buffer
* returns -1 if no update since update_time,
* 0 if update with no error,
* EINVAL if the buffer (version or otherwise) is invalid,
* ENOMEM if malloc failure
* NOTE: the allocated memory at node_buffer_ptr freed by slurm_free_node_info.
*/
/* slurm_load_node - load the supplied node information buffer if changed */
int
slurm_load_node (time_t update_time, struct node_buffer **node_buffer_ptr)
slurm_load_node (time_t update_time, node_info_msg_t **node_info_msg_pptr)
{
int buffer_offset, buffer_size, in_size, i, sockfd;
char request_msg[64], *buffer;
void *buf_ptr;
struct sockaddr_in serv_addr;
uint32_t uint32_tmp, uint32_time;
uint16_t uint16_tmp;
struct node_table *node;
*node_buffer_ptr = NULL;
if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
return EINVAL;
serv_addr.sin_family = PF_INET;
serv_addr.sin_addr.s_addr = inet_addr (SLURMCTLD_HOST);
serv_addr.sin_port = htons (SLURMCTLD_PORT);
if (connect
(sockfd, (struct sockaddr *) &serv_addr,
sizeof (serv_addr)) < 0) {
close (sockfd);
return EINVAL;
}
sprintf (request_msg, "DumpNode LastUpdate=%lu",
(long) (update_time));
if (send (sockfd, request_msg, strlen (request_msg) + 1, 0) <
strlen (request_msg)) {
close (sockfd);
return EINVAL;
}
buffer = NULL;
buffer_offset = 0;
buffer_size = 8 * 1024;
while (1) {
buffer = realloc (buffer, buffer_size);
if (buffer == NULL) {
close (sockfd);
return ENOMEM;
}
in_size =
recv (sockfd, &buffer[buffer_offset],
(buffer_size - buffer_offset), 0);
if (in_size <= 0) { /* end of input */
in_size = 0;
break;
}
buffer_offset += in_size;
buffer_size += in_size;
}
close (sockfd);
buffer_size = buffer_offset + in_size;
buffer = realloc (buffer, buffer_size);
if (buffer == NULL)
return ENOMEM;
if (strcmp (buffer, "nochange") == 0) {
free (buffer);
return -1;
int msg_size ;
int rc ;
slurm_fd sockfd ;
slurm_msg_t request_msg ;
slurm_msg_t response_msg ;
last_update_msg_t last_time_msg ;
return_code_msg_t * slurm_rc_msg ;
/* init message connection for message communication with controller */
if ( ( sockfd = slurm_open_controller_conn ( SLURM_PORT ) ) == SLURM_SOCKET_ERROR )
return SLURM_SOCKET_ERROR ;
/* send request message */
/* pack32 ( update_time , &buf_ptr , &buffer_size ); */
last_time_msg . last_update = update_time ;
request_msg . msg_type = REQUEST_NODE_INFO ;
request_msg . data = &last_time_msg ;
if ( ( rc = slurm_send_controller_msg ( sockfd , & request_msg ) ) == SLURM_SOCKET_ERROR )
return SLURM_SOCKET_ERROR ;
/* receive message */
if ( ( msg_size = slurm_receive_msg ( sockfd , & response_msg ) ) == SLURM_SOCKET_ERROR )
return SLURM_SOCKET_ERROR ;
/* shutdown message connection */
if ( ( rc = slurm_shutdown_msg_conn ( sockfd ) ) == SLURM_SOCKET_ERROR )
return SLURM_SOCKET_ERROR ;
switch ( response_msg . msg_type )
{
case RESPONSE_NODE_INFO:
*node_info_msg_pptr = ( node_info_msg_t * ) response_msg . data ;
break ;
case RESPONSE_SLURM_RC:
slurm_rc_msg = ( return_code_msg_t * ) response_msg . data ;
break ;
default:
return SLURM_UNEXPECTED_MSG_ERROR ;
break ;
}
/* load buffer's header (data structure version and time) */
buf_ptr = buffer;
unpack32 (&uint32_tmp, &buf_ptr, &buffer_size);
if (uint32_tmp != NODE_STRUCT_VERSION) {
free (buffer);
return EINVAL;
}
unpack32 (&uint32_time, &buf_ptr, &buffer_size);
/* load individual node info */
node = NULL;
for (i = 0; buffer_size > 0; i++) {
node = realloc (node, sizeof(struct node_table) * (i+1));
if (node == NULL) {
free (buffer);
return ENOMEM;
}
unpackstr_ptr (&node[i].name, &uint16_tmp, &buf_ptr, &buffer_size);
if (node[i].name == NULL)
node[i].name = "";
unpack16 (&node[i].node_state, &buf_ptr, &buffer_size);
unpack32 (&node[i].cpus, &buf_ptr, &buffer_size);
unpack32 (&node[i].real_memory, &buf_ptr, &buffer_size);
unpack32 (&node[i].tmp_disk, &buf_ptr, &buffer_size);
unpack32 (&node[i].weight, &buf_ptr, &buffer_size);
unpackstr_ptr (&node[i].features, &uint16_tmp,
&buf_ptr, &buffer_size);
if (node[i].features == NULL)
node[i].features = "";
unpackstr_ptr (&node[i].partition, &uint16_tmp,
&buf_ptr, &buffer_size);
if (node[i].partition == NULL)
node[i].partition = "";
}
*node_buffer_ptr = malloc (sizeof (struct node_buffer));
if (*node_buffer_ptr == NULL) {
free (buffer);
free (node);
return ENOMEM;
}
(*node_buffer_ptr)->last_update = (time_t) uint32_time;
(*node_buffer_ptr)->node_count = i;
(*node_buffer_ptr)->raw_buffer_ptr = buffer;
(*node_buffer_ptr)->node_table_ptr = node;
return 0;
return SLURM_SUCCESS ;
}
......@@ -19,9 +19,9 @@
#include <arpa/inet.h>
#include <unistd.h>
#include "slurm.h"
#include "pack.h"
#include "nodelist.h"
#include <src/api/slurm.h>
#include <src/common/nodelist.h>
#include <src/common/pack.h>
#if DEBUG_MODULE
/* main is used here for module testing purposes only */
......
......@@ -71,24 +71,6 @@ struct job_buffer {
struct job_table *job_table_ptr;
};
struct node_table {
char *name; /* name of the node. a null name indicates defunct node */
uint16_t node_state; /* state of the node, see node_states */
uint32_t cpus; /* count of processors running on the node */
uint32_t real_memory; /* megabytes of real memory on the node */
uint32_t tmp_disk; /* megabytes of total disk in TMP_FS */
uint32_t weight; /* desirability of use */
char *partition; /* partition name */
char *features; /* features associated with the node */
};
struct node_buffer {
time_t last_update; /* time of last buffer update */
uint32_t node_count; /* count of entries in node_table */
void *raw_buffer_ptr; /* raw network buffer info */
struct node_table *node_table_ptr;
};
struct part_table {
char *name; /* name of the partition */
uint32_t max_time; /* minutes or INFINITE */
......@@ -158,26 +140,33 @@ extern void slurm_print_build_info ( FILE * out, struct build_table * build_tabl
/*
* slurm_free_job_info - free the job information buffer (if allocated)
* NOTE: buffer is loaded by load_job.
* NOTE: buffer is loaded by slurm_load_job.
*/
extern void slurm_free_job_info (job_info_msg_t * job_buffer_ptr);
/*
* slurm_print_job_table - prints the job table object (if allocated)
* slurm_free_node_info - free the node information buffer (if allocated)
* NOTE: buffer is loaded by slurm_load_node.
*/
extern void slurm_print_job_table ( job_table_t * job_ptr );
extern void slurm_free_node_info (node_info_msg_t * node_buffer_ptr);
/*
* slurm_print_build_info - prints the build information buffer (if allocated)
* slurm_print_job_info_msg - prints the job information buffer (if allocated)
* NOTE: buffer is loaded by slurm_load_job_info .
*/
extern void slurm_print_job_info_msg ( job_info_msg_t * job_info_msg_ptr ) ;
/*
* slurm_free_node_info - free the node information buffer (if allocated)
* NOTE: buffer is loaded by slurm_load_node.
/* slurm_print_job_table - prints the job table object (if allocated) */
extern void slurm_print_job_table ( job_table_t * job_ptr );
/*
* slurm_print_node_info_msg - prints the node information buffer (if allocated)
* NOTE: buffer is loaded by slurm_load_node_info .
*/
extern void slurm_free_node_info (struct node_buffer *node_buffer_ptr);
extern void slurm_print_node_info_msg ( node_info_msg_t * node_info_msg_ptr ) ;
/* slurm_print_node_table - prints the node table object (if allocated) */
extern void slurm_print_node_table (node_table_t * node_ptr );
/*
* slurm_free_part_info - free the partition information buffer (if allocated)
......@@ -201,33 +190,11 @@ extern int slurm_load_build (time_t update_time,
struct build_table **build_table_ptr);
/*
* slurm_load_job - load the supplied job information buffer for use by info
* gathering APIs if job records have changed since the time specified.
* input: update_time - time of last update
* job_buffer_ptr - place to park job_buffer pointer
* output: job_buffer_ptr - pointer to allocated job_buffer
* returns -1 if no update since update_time,
* 0 if update with no error,
* EINVAL if the buffer (version or otherwise) is invalid,
* ENOMEM if malloc failure
* NOTE: the allocated memory at job_buffer_ptr freed by slurm_free_job_info.
*/
extern int slurm_load_jobs (time_t update_time, job_info_msg_t **job_info_msg_ptr);
/* slurm_load_job - load the supplied job information buffer if changed */
extern int slurm_load_jobs (time_t update_time, job_info_msg_t **job_info_msg_pptr);
/*
* slurm_load_node - load the supplied node information buffer for use by info
* gathering APIs if node records have changed since the time specified.
* input: update_time - time of last update
* node_buffer_ptr - place to park node_buffer pointer
* output: node_buffer_ptr - pointer to allocated node_buffer
* returns -1 if no update since update_time,
* 0 if update with no error,
* EINVAL if the buffer (version or otherwise) is invalid,
* ENOMEM if malloc failure
* NOTE: the allocated memory at node_buffer_ptr freed by slurm_free_node_info.
*/
extern int slurm_load_node (time_t update_time, struct node_buffer **node_buffer_ptr);
/* slurm_load_node - load the supplied node information buffer if changed */
extern int slurm_load_node (time_t update_time, node_info_msg_t **node_info_msg_pptr);
/*
* slurm_load_part - load the supplied partition information buffer for use by info
......
......@@ -19,6 +19,7 @@
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <src/common/nodelist.h>
/*
* bitfmt2int - convert a string describing bitmap (e.g. "0-30,45,50-60")
......
......@@ -83,3 +83,29 @@ void slurm_free_job_table ( job_table_t * job )
free ( job ) ;
}
}
void slurm_free_node_info ( node_info_msg_t * msg )
{
int i;
if ( msg )
{
if ( msg -> node_array )
{
for (i = 0; i < msg -> record_count; i++) {
slurm_free_node_table ( & ( msg->node_array[i] ) ) ;
}
}
free ( msg );
}
}
void slurm_free_node_table ( node_table_t * node )
{
if ( node )
{
free (node->name) ;
free (node->features) ;
free (node->partition) ;
free ( node ) ;
}
}
......@@ -211,6 +211,27 @@ typedef struct job_info_msg {
job_table_t * job_array;
} job_info_msg_t ;
struct node_table {
char *name; /* node name */
uint16_t node_state; /* enum node_states, ORed with STATE_NO_RESPOND if down */
uint32_t cpus; /* configured count of cpus running on the node */
uint32_t real_memory; /* configured megabytes of real memory on the node */
uint32_t tmp_disk; /* configured megabytes of total disk in TMP_FS */
uint32_t weight; /* arbitrary priority of node for scheduling work on */
char *features; /* arbitrary list of features associated with a node */
char *partition; /* name of partition node configured to */
};
typedef struct node_table node_table_t ;
typedef struct node_table node_table_msg_t ;
typedef struct node_info_msg {
uint32_t last_update;
uint32_t record_count;
node_table_t * node_array;
} node_info_msg_t ;
/* the following typedefs follow kevin's communication message naming comvention */
/* free message functions */
......@@ -224,4 +245,7 @@ void inline slurm_free_job_info ( job_info_msg_t * msg ) ;
void inline slurm_free_job_table ( job_table_t * job ) ;
void inline slurm_free_job_desc_msg ( job_desc_msg_t * msg ) ;
void inline slurm_free_node_info ( node_info_msg_t * msg ) ;
void inline slurm_free_node_table ( node_table_t * node ) ;
#endif
/*
/*****************************************************************************\
* controller.c - main control machine daemon for slurm
* see slurm.h for documentation on external functions and data structures
*
* NOTE: DEBUG_MODULE of read_config requires that it be loaded with
* bits_bytes, partition_mgr, read_config, and node_mgr
*
* author: moe jette, jette@llnl.gov
*/
/* Changes
* Kevin Tew June 3, 2002
* reimplemented the entire routine to use the new communication library*/
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Kevin Tew <tew1@llnl.gov> et. al.
* 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 ConMan; 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>
......@@ -504,14 +517,11 @@ fill_build_table ( struct build_table * build_ptr )
void
slurmctld_req_old (int sockfd) {
int error_code, in_size, i;
char in_line[BUF_SIZE], node_name[MAX_NAME_LEN];
int cpus, real_memory, tmp_disk;
char *node_name_ptr, *part_name, *time_stamp;
char in_line[BUF_SIZE];
char *node_name_ptr, *part_name;
uint32_t job_id;
time_t last_update;
clock_t start_time;
char *dump;
int dump_size, dump_loc;
in_size = recv (sockfd, in_line, sizeof (in_line), 0);
start_time = clock ();
......
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