diff --git a/src/api/update_config.c b/src/api/update_config.c index 53da2e4f9b585d2f981c7b5450a27ce35078d534..326d48718c8ec80cd589d9fcf644e5c827e69bf4 100644 --- a/src/api/update_config.c +++ b/src/api/update_config.c @@ -36,8 +36,8 @@ int slurm_update_node ( update_node_msg_t * node_msg ) /* send request message */ - /*request_msg . msg_type = REQUEST_UPDATE_CONFIG_INFO ;*/ - request_msg . data = NULL ; + request_msg . msg_type = REQUEST_UPDATE_NODE ; + request_msg . data = node_msg ; if ( ( rc = slurm_send_controller_msg ( sockfd , & request_msg ) ) == SLURM_SOCKET_ERROR ) return SLURM_SOCKET_ERROR ; diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h index faad47b520cea414f2e9540e4eb1e77746ec0dab..c7ed74e5c79d46c46775ff225574805c7af48de9 100644 --- a/src/common/slurm_protocol_defs.h +++ b/src/common/slurm_protocol_defs.h @@ -165,7 +165,7 @@ typedef struct job_id_msg { typedef struct slurm_update_node_msg { char * node_names ; - uint32_t node_state ; + uint16_t node_state ; } update_node_msg_t ; typedef struct slurm_node_registration_status_msg diff --git a/src/common/slurm_protocol_errno.h b/src/common/slurm_protocol_errno.h index 32299194d77d46ace8af08175f32ec6f01344349..80a96ad5860ef01ec70c4f53eba0de84be9d8bf3 100644 --- a/src/common/slurm_protocol_errno.h +++ b/src/common/slurm_protocol_errno.h @@ -38,4 +38,8 @@ /* partition_mgr.c/update_part */ #define ESLURM_PROTOCOL_INVALID_PARTITION_NAME -2101 + +/* node_mgr.c/update_node */ +#define ESLURM_INVALID_NODE_NAME -2201 + #endif diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c index 93e6181f0e437352e71a59a1e5e424576323af0c..50a436093bf3742001b740fa7970ada3b56de55d 100644 --- a/src/common/slurm_protocol_pack.c +++ b/src/common/slurm_protocol_pack.c @@ -268,8 +268,10 @@ int unpack_msg ( slurm_msg_t * msg , char ** buffer , uint32_t * buf_len ) void pack_update_node_msg ( update_node_msg_t * msg, void ** buffer , uint32_t * length ) { + assert ( msg != NULL ); + packstr ( msg -> node_names , ( void ** ) buffer , length ) ; - pack32 ( msg -> node_state , ( void ** ) buffer , length ) ; + pack16 ( msg -> node_state , ( void ** ) buffer , length ) ; } int unpack_update_node_msg ( update_node_msg_t ** msg , void ** buffer , uint32_t * length ) @@ -284,7 +286,7 @@ int unpack_update_node_msg ( update_node_msg_t ** msg , void ** buffer , uint32_ } unpackstr_xmalloc ( & tmp_ptr -> node_names , &uint16_tmp, ( void ** ) buffer , length ) ; - unpack32 ( & tmp_ptr -> node_state , ( void ** ) buffer , length ) ; + unpack16 ( & tmp_ptr -> node_state , ( void ** ) buffer , length ) ; *msg = tmp_ptr ; return 0 ; } diff --git a/src/scontrol/scontrol.c b/src/scontrol/scontrol.c index 52938ee7cbaa06200d617a116c78b2433e6627cb..93334eb63df0ead9d09ddb229d972cc55865bbc4 100644 --- a/src/scontrol/scontrol.c +++ b/src/scontrol/scontrol.c @@ -36,7 +36,7 @@ static char *command_name; static int exit_flag; /* program to terminate if =1 */ static int quiet_flag; /* quiet=1, verbose=-1, normal=0 */ -static int input_words; /* number of words of input permitted */ +static int input_words; /* number of words of input permitted */ void dump_command (int argc, char *argv[]); int get_command (int *argc, char *argv[]); @@ -47,6 +47,9 @@ 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[]); +int update_job (int argc, char *argv[]); +int update_node (int argc, char *argv[]); +int update_part (int argc, char *argv[]); void usage (); int @@ -658,40 +661,112 @@ process_command (int argc, char *argv[]) int update_it (int argc, char *argv[]) { - char *in_line; - int error_code, i, in_line_size; + int error_code, i; error_code = 0; - in_line_size = BUF_SIZE; - in_line = (char *) xmalloc (in_line_size); - if (in_line == NULL) { - fprintf (stderr, "%s: error %d allocating memory\n", - command_name, errno); - return ENOMEM; - } - strcpy (in_line, ""); + /* First identify the entity to update */ + for (i=0; i<argc; i++) { + if (strncmp (argv[i], "NodeName=", 9) == 0) { + error_code = update_node (argc, argv); + break; + } + else if (strncmp (argv[i], "PartitionName=", 14) == 0) { + error_code = update_part (argc, argv); + break; + } + else if (strncmp (argv[i], "JobId=", 6) == 0) { + error_code = update_job (argc, argv); + break; + } + } + + if (i >= argc) { + printf("No valid entity in update command\n"); + printf("Input line must include \"NodeName\", \"PartitionName\", or \"JobId\"\n"); + error_code = EINVAL; + } + else if (error_code) { + printf("errorno=%d\n",error_code); + } + return error_code; +} - for (i = 0; i < argc; i++) { - if ((strlen (in_line) + strlen (argv[i]) + 2) > in_line_size) { - in_line_size += BUF_SIZE; - xrealloc (in_line, in_line_size); - if (in_line == NULL) { - fprintf (stderr, - "%s: error %d allocating memory\n", - command_name, errno); - return ENOMEM; - } - } +/* + * update_job - update the slurm job configuration per the supplied arguments + * input: argc - count of arguments + * argv - list of arguments + * output: returns 0 if no error, errno otherwise + */ +int +update_job (int argc, char *argv[]) +{ + printf("Not yet implemented\n"); + return EINVAL; +} - strcat (in_line, argv[i]); - strcat (in_line, " "); - } +/* + * update_node - update the slurm node configuration per the supplied arguments + * input: argc - count of arguments + * argv - list of arguments + * output: returns 0 if no error, errno otherwise + */ +int +update_node (int argc, char *argv[]) +{ + int error_code, i, j, k; + uint16_t state_val; + update_node_msg_t node_msg; + + error_code = 0; + node_msg.node_names = NULL; + node_msg.node_state = (uint16_t) NO_VAL; + for (i=0; i<argc; i++) { + if (strncmp(argv[i], "NodeName=", 9) == 0) + node_msg.node_names = &argv[i][9]; + else if (strncmp(argv[i], "State=", 6) == 0) { + state_val = (uint16_t) NO_VAL; + for (j = 0; j <= NODE_STATE_END; j++) { + if (strcmp (node_state_string(j), "END") == 0) { + fprintf (stderr, "Invalid input: %s\n", argv[i]); + fprintf (stderr, "Request aborted\n Valid states are:"); + for (k = 0; k <= NODE_STATE_END; k++) { + fprintf (stderr, "%s ", node_state_string(k)); + } + fprintf (stderr, "\n"); + return EINVAL; + } + if (strcmp (node_state_string(j), &argv[i][6]) == 0) { + state_val = (uint16_t) j; + break; + } + } + node_msg.node_state = state_val; + } + else { + fprintf (stderr, "Invalid input: %s\n", argv[i]); + fprintf (stderr, "Request aborted\n"); + return EINVAL; + } + } -/* error_code = slurm_update_config (in_line); */ - xfree (in_line); +printf("Node=%s,State=%u\n",node_msg.node_names,node_msg.node_state); + error_code = slurm_update_node(&node_msg); return error_code; } +/* + * update_part - update the slurm partition configuration per the supplied arguments + * input: argc - count of arguments + * argv - list of arguments + * output: returns 0 if no error, errno otherwise + */ +int +update_part (int argc, char *argv[]) +{ + printf("Not yet implemented\n"); + return EINVAL; +} + /* usage - show the valid scontrol commands */ void usage () { diff --git a/src/slurmctld/controller.c b/src/slurmctld/controller.c index a31ad91469ddbad56bf86051d09852571115990e..87c8d5c6fdf0ff3f9ab3b9d45f1fbb865b03f1d8 100644 --- a/src/slurmctld/controller.c +++ b/src/slurmctld/controller.c @@ -61,6 +61,7 @@ inline static void slurm_rpc_submit_batch_job ( slurm_msg_t * msg ) ; inline static void slurm_rpc_reconfigure_controller ( slurm_msg_t * msg ) ; inline static void slurm_rpc_node_registration ( slurm_msg_t * msg ) ; inline static void slurm_rpc_register_node_status ( slurm_msg_t * msg ) ; +inline static void slurm_rpc_update_node ( slurm_msg_t * msg ) ; inline static void slurm_rpc_job_will_run ( slurm_msg_t * msg ) ; inline static void slurm_rpc_allocate_resources ( slurm_msg_t * msg , uint8_t immediate ) ; @@ -182,6 +183,9 @@ slurmctld_req ( slurm_msg_t * msg ) case REQUEST_RECONFIGURE: slurm_rpc_reconfigure_controller ( msg ) ; break; + case REQUEST_UPDATE_NODE: + slurm_rpc_update_node ( msg ) ; + break; default: error ("slurmctld_req: invalid request msg type %d\n", msg-> msg_type); slurm_send_rc_msg ( msg , EINVAL ); @@ -372,30 +376,30 @@ slurm_rpc_update_node ( slurm_msg_t * msg ) int error_code; clock_t start_time; update_node_msg_t * update_node_msg_ptr ; - char * node_name_ptr = NULL; start_time = clock (); update_node_msg_ptr = (update_node_msg_t * ) msg-> data ; /* do RPC call */ - error_code = update_node ( update_node_msg_ptr ); /* skip "Update" */ + error_code = update_node ( update_node_msg_ptr ); /* return result */ if (error_code) { error ("slurmctld_req: update error %d on node %s, time=%ld", - error_code, node_name_ptr, (long) (clock () - start_time)); + error_code, update_node_msg_ptr->node_names, + (long) (clock () - start_time)); slurm_send_rc_msg ( msg , error_code ); } else { info ("slurmctld_req: updated node %s, time=%ld", - node_name_ptr, (long) (clock () - start_time)); + update_node_msg_ptr->node_names, + (long) (clock () - start_time)); slurm_send_rc_msg ( msg , SLURM_SUCCESS ); } - if (node_name_ptr) - xfree (node_name_ptr); - + if (update_node_msg_ptr->node_names) + xfree (update_node_msg_ptr->node_names); } void @@ -542,7 +546,7 @@ void slurm_rpc_job_will_run ( slurm_msg_t * msg ) } -/* Reconfigure - re-initialized from configuration files */ +/* slurm_rpc_reconfigure_controller - re-initialize controller from configuration files */ void slurm_rpc_reconfigure_controller ( slurm_msg_t * msg ) { diff --git a/src/slurmctld/node_mgr.c b/src/slurmctld/node_mgr.c index 7b1781934d0d1d8f82d313096fbfb61fd64771a9..66d950c1bac151517e4c0dce8e82663f4d829e61 100644 --- a/src/slurmctld/node_mgr.c +++ b/src/slurmctld/node_mgr.c @@ -871,7 +871,7 @@ node_name2list (char *node_names, char **node_list, int *node_count) xfree(buffer); xfree (my_node_list); xfree (format); - return EINVAL; + return ESLURM_INVALID_NODE_NAME; } for (i = start_inx; i <= end_inx; i++) { if (count_inx == 0) @@ -885,7 +885,7 @@ node_name2list (char *node_names, char **node_list, int *node_count) xfree(buffer); xfree (my_node_list); xfree (format); - return EINVAL; + return ESLURM_INVALID_NODE_NAME; } if ((buf_rec_inx+1) >= buf_recs) { buf_recs += 200; @@ -1210,11 +1210,7 @@ split_node_name (char *name, char *prefix, char *suffix, int *index, /* * update_node - update the configuration data for one or more nodes - * input: node_names - node names, may contain regular expression - * spec - the updates to the node's specification - * output: return - 0 if no error, otherwise an error code * global: node_record_table_ptr - pointer to global node table - * NOTE: the contents of spec are overwritten by white space */ int update_node ( update_node_msg_t * update_node_msg ) @@ -1228,7 +1224,7 @@ update_node ( update_node_msg_t * update_node_msg ) if (update_node_msg -> node_names == NULL ) { error ("update_node: invalid node name %s\n", update_node_msg -> node_names ); - return EINVAL; + return ESLURM_INVALID_NODE_NAME; } state_val = update_node_msg -> node_state ; @@ -1237,11 +1233,12 @@ update_node ( update_node_msg_t * update_node_msg ) if (error_code) return error_code; + last_node_update = time (NULL); for (i = 0; i < node_count; i++) { node_record_point = find_node_record (&node_list[i*MAX_NAME_LEN]); if (node_record_point == NULL) { error ("update_node: node name %s does not exist, can not be updated", &node_list[i*MAX_NAME_LEN]); - error_code = EINVAL; + error_code = ESLURM_INVALID_NODE_NAME; break; }