diff --git a/src/common/gres.c b/src/common/gres.c index 5acccd054e291a1c460a226c1f7baa06c29a249a..ef8e3ddb140e8b70461738f9bb235bd51a418644 100644 --- a/src/common/gres.c +++ b/src/common/gres.c @@ -98,6 +98,7 @@ typedef struct slurm_gres_ops { Buf buffer ); int (*unpack_node_state) ( void **gres_data, Buf buffer ); + void * (*dup_node_state) ( void *gres_data ); void (*node_state_log) ( void *gres_data, char *node_name ); @@ -164,6 +165,7 @@ static int _load_gres_plugin(char *plugin_name, "node_config_delete", "pack_node_state", "unpack_node_state", + "dup_node_state", "node_state_log", "job_config_delete", "job_gres_validate", @@ -567,7 +569,8 @@ static void _gres_node_list_delete(void *list_element) for (i=0; i<gres_context_cnt; i++) { if (gres_ptr->plugin_id != *(gres_context[i].ops.plugin_id)) continue; - (*(gres_context[i].ops.node_config_delete))(gres_ptr->gres_data); + (*(gres_context[i].ops.node_config_delete)) + (gres_ptr->gres_data); xfree(gres_ptr); break; } @@ -852,6 +855,55 @@ unpack_error: goto fini; } +/* + * Duplicate a node gres status (used for will-run logic) + */ +extern List gres_plugin_dup_node_state(List gres_list) +{ + int i; + List new_list = NULL; + ListIterator gres_iter; + gres_state_t *gres_ptr, *new_gres; + void *gres_data; + + if (gres_list == NULL) + return new_list; + + (void) gres_plugin_init(); + + slurm_mutex_lock(&gres_context_lock); + if ((gres_context_cnt > 0)) { + new_list = list_create(_gres_node_list_delete); + if (new_list == NULL) + fatal("list_create malloc failure"); + } + gres_iter = list_iterator_create(gres_list); + while ((gres_ptr = (gres_state_t *) list_next(gres_iter))) { + for (i=0; i<gres_context_cnt; i++) { + if (gres_ptr->plugin_id != + *(gres_context[i].ops.plugin_id)) + continue; + gres_data = (*(gres_context[i].ops.dup_node_state)) + (gres_ptr->gres_data); + if (gres_data) { + new_gres = xmalloc(sizeof(gres_state_t)); + new_gres->plugin_id = gres_ptr->plugin_id; + new_gres->gres_data = gres_data; + list_append(new_list, new_gres); + } + break; + } + if (i >= gres_context_cnt) { + error("Could not find plugin id %u to dup node record", + gres_ptr->plugin_id); + } + } + list_iterator_destroy(gres_iter); + slurm_mutex_unlock(&gres_context_lock); + + return new_list; +} + /* * Log a node's current gres state * IN gres_list - generated by gres_plugin_node_config_validate() diff --git a/src/common/gres.h b/src/common/gres.h index a90b6d5cff46b5803126ee646e7005ee5285f729..a54b961fef4f6889e704c25c45e0c0ad127de486 100644 --- a/src/common/gres.h +++ b/src/common/gres.h @@ -155,6 +155,11 @@ extern int gres_plugin_pack_node_state(List gres_list, Buf buffer, extern int gres_plugin_unpack_node_state(List *gres_list, Buf buffer, char *node_name); +/* + * Duplicate a node gres status (used for will-run logic) + */ +extern List gres_plugin_dup_node_state(List gres_list); + /* * Log a node's current gres state * IN gres_list - generated by gres_plugin_node_config_validate() diff --git a/src/plugins/gres/gpu/gres_gpu.c b/src/plugins/gres/gpu/gres_gpu.c index 0dee5538fa469692a47addc60b53396541b25ffd..0f1b1fd1a4822137393950c79a192c6179d6e997 100644 --- a/src/plugins/gres/gpu/gres_gpu.c +++ b/src/plugins/gres/gpu/gres_gpu.c @@ -505,6 +505,24 @@ unpack_error: return SLURM_ERROR; } +extern void *dup_node_state(void *gres_data) +{ + gpu_node_state_t *gres_ptr = (gpu_node_state_t *) gres_data; + gpu_node_state_t *new_gres; + + if (gres_ptr == NULL) + return NULL; + + new_gres = xmalloc(sizeof(gpu_node_state_t)); + new_gres->gpu_cnt_found = gres_ptr->gpu_cnt_found; + new_gres->gpu_cnt_config = gres_ptr->gpu_cnt_config; + new_gres->gpu_cnt_avail = gres_ptr->gpu_cnt_avail; + new_gres->gpu_cnt_alloc = gres_ptr->gpu_cnt_alloc; + new_gres->gpu_bit_alloc = bit_copy(gres_ptr->gpu_bit_alloc); + + return new_gres; +} + extern void node_state_log(void *gres_data, char *node_name) { gpu_node_state_t *gres_ptr; diff --git a/src/plugins/gres/nic/gres_nic.c b/src/plugins/gres/nic/gres_nic.c index a9799e2c1f7e4497fb2e1b0a790f896218c8f568..9646a90d7bfdfe78e0f7eff1bdef584041c1cc8f 100644 --- a/src/plugins/gres/nic/gres_nic.c +++ b/src/plugins/gres/nic/gres_nic.c @@ -505,6 +505,24 @@ unpack_error: return SLURM_ERROR; } +extern void *dup_node_state(void *gres_data) +{ + nic_node_state_t *gres_ptr = (nic_node_state_t *) gres_data; + nic_node_state_t *new_gres; + + if (gres_ptr == NULL) + return NULL; + + new_gres = xmalloc(sizeof(nic_node_state_t)); + new_gres->nic_cnt_found = gres_ptr->nic_cnt_found; + new_gres->nic_cnt_config = gres_ptr->nic_cnt_config; + new_gres->nic_cnt_avail = gres_ptr->nic_cnt_avail; + new_gres->nic_cnt_alloc = gres_ptr->nic_cnt_alloc; + new_gres->nic_bit_alloc = bit_copy(gres_ptr->nic_bit_alloc); + + return new_gres; +} + extern void node_state_log(void *gres_data, char *node_name) { nic_node_state_t *gres_ptr;