From aa2c10acfb0451f2ff61042a9b9a63a13c262dab Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Fri, 9 Jul 2010 22:30:40 +0000 Subject: [PATCH] move node_state_pack and unpack from plugin/gres to src/common/gres.c --- src/common/gres.c | 67 +++++++++++++++++++++++++++------ src/plugins/gres/gpu/gres_gpu.c | 50 ------------------------ src/plugins/gres/nic/gres_nic.c | 50 ------------------------ 3 files changed, 55 insertions(+), 112 deletions(-) diff --git a/src/common/gres.c b/src/common/gres.c index a581bb2d7ed..52078056d1a 100644 --- a/src/common/gres.c +++ b/src/common/gres.c @@ -85,10 +85,6 @@ typedef struct slurm_gres_ops { char (*gres_name); char (*help_msg); int (*node_config_load) ( List gres_conf_list ); - int (*node_state_pack) ( void *gres_data, - Buf buffer ); - int (*node_state_unpack) ( void **gres_data, - Buf buffer ); void * (*node_state_dup) ( void *gres_data ); void (*node_state_dealloc) ( void *gres_data ); int (*node_state_realloc) ( void *job_gres_data, @@ -185,8 +181,6 @@ static int _load_gres_plugin(char *plugin_name, "gres_name", "help_msg", "node_config_load", - "node_state_pack", - "node_state_unpack", "node_state_dup", "node_state_dealloc", "node_state_realloc", @@ -1195,6 +1189,55 @@ extern int gres_plugin_node_reconfig(char *node_name, return rc; } +static int _node_state_pack(void *gres_data, Buf buffer) +{ + gres_node_state_t *gres_ptr = (gres_node_state_t *) gres_data; + + pack32(gres_ptr->gres_cnt_avail, buffer); + pack32(gres_ptr->gres_cnt_alloc, buffer); + pack_bit_str(gres_ptr->gres_bit_alloc, buffer); + + return SLURM_SUCCESS; +} + +static int _node_state_unpack(void **gres_data, Buf buffer) +{ + gres_node_state_t *gres_ptr; + + gres_ptr = xmalloc(sizeof(gres_node_state_t)); + + gres_ptr->gres_cnt_found = NO_VAL; + if (buffer) { + safe_unpack32(&gres_ptr->gres_cnt_avail, buffer); + safe_unpack32(&gres_ptr->gres_cnt_alloc, buffer); + unpack_bit_str(&gres_ptr->gres_bit_alloc, buffer); + if (gres_ptr->gres_bit_alloc == NULL) + goto unpack_error; + if (gres_ptr->gres_cnt_avail != + bit_size(gres_ptr->gres_bit_alloc)) { + gres_ptr->gres_bit_alloc = + bit_realloc(gres_ptr->gres_bit_alloc, + gres_ptr->gres_cnt_avail); + if (gres_ptr->gres_bit_alloc == NULL) + goto unpack_error; + } + if (gres_ptr->gres_cnt_alloc != + bit_set_count(gres_ptr->gres_bit_alloc)) { + error("gres _node_state_unpack bit count inconsistent"); + goto unpack_error; + } + } + + *gres_data = gres_ptr; + return SLURM_SUCCESS; + +unpack_error: + FREE_NULL_BITMAP(gres_ptr->gres_bit_alloc); + xfree(gres_ptr); + *gres_data = NULL; + return SLURM_ERROR; +} + /* * Pack a node's current gres status, called from slurmctld for save/restore * IN gres_list - generated by gres_plugin_node_config_validate() @@ -1238,8 +1281,7 @@ extern int gres_plugin_node_state_pack(List gres_list, Buf buffer, size_offset = get_buf_offset(buffer); pack32(gres_size, buffer); /* placeholder */ data_offset = get_buf_offset(buffer); - rc2 = (*(gres_context[i].ops.node_state_pack)) - (gres_ptr->gres_data, buffer); + rc2 = _node_state_pack(gres_ptr->gres_data, buffer); if (rc2 != SLURM_SUCCESS) { rc = rc2; set_buf_offset(buffer, header_offset); @@ -1326,9 +1368,11 @@ extern int gres_plugin_node_state_unpack(List *gres_list, Buf buffer, continue; } gres_context[i].unpacked_info = true; - rc2 = (*(gres_context[i].ops.node_state_unpack)) - (&gres_data, buffer); + rc2 = _node_state_unpack(&gres_data, buffer); if (rc2 != SLURM_SUCCESS) { + error("gres_plugin_node_state_unpack: error unpacking " + "data of type %s from node %s", + gres_context[i].ops.gres_name, node_name); rc = rc2; } else { gres_ptr = xmalloc(sizeof(gres_state_t)); @@ -1347,8 +1391,7 @@ fini: /* Insure that every gres plugin is called for unpack, even if no data error("gres_plugin_node_state_unpack: no info packed for %s " "by node %s", gres_context[i].gres_type, node_name); - rc2 = (*(gres_context[i].ops.node_state_unpack)) - (&gres_data, NULL); + rc2 = _node_state_unpack(&gres_data, NULL); if (rc2 != SLURM_SUCCESS) { rc = rc2; } else { diff --git a/src/plugins/gres/gpu/gres_gpu.c b/src/plugins/gres/gpu/gres_gpu.c index f94b1adb439..0501993bed7 100644 --- a/src/plugins/gres/gpu/gres_gpu.c +++ b/src/plugins/gres/gpu/gres_gpu.c @@ -191,56 +191,6 @@ extern int node_config_load(List gres_conf_list) return rc; } -extern int node_state_pack(void *gres_data, Buf buffer) -{ - gpu_node_state_t *gres_ptr = (gpu_node_state_t *) gres_data; - - pack32(gres_ptr->gpu_cnt_avail, buffer); - pack32(gres_ptr->gpu_cnt_alloc, buffer); - pack_bit_str(gres_ptr->gpu_bit_alloc, buffer); - - return SLURM_SUCCESS; -} - -extern int node_state_unpack(void **gres_data, Buf buffer) -{ - gpu_node_state_t *gres_ptr; - - gres_ptr = xmalloc(sizeof(gpu_node_state_t)); - - gres_ptr->gpu_cnt_found = NO_VAL; - if (buffer) { - safe_unpack32(&gres_ptr->gpu_cnt_avail, buffer); - safe_unpack32(&gres_ptr->gpu_cnt_alloc, buffer); - unpack_bit_str(&gres_ptr->gpu_bit_alloc, buffer); - if (gres_ptr->gpu_bit_alloc == NULL) - goto unpack_error; - if (gres_ptr->gpu_cnt_avail != - bit_size(gres_ptr->gpu_bit_alloc)) { - gres_ptr->gpu_bit_alloc = - bit_realloc(gres_ptr->gpu_bit_alloc, - gres_ptr->gpu_cnt_avail); - if (gres_ptr->gpu_bit_alloc == NULL) - goto unpack_error; - } - if (gres_ptr->gpu_cnt_alloc != - bit_set_count(gres_ptr->gpu_bit_alloc)) { - error("%s node_state_unpack bit count inconsistent", - plugin_name); - goto unpack_error; - } - } - - *gres_data = gres_ptr; - return SLURM_SUCCESS; - -unpack_error: - FREE_NULL_BITMAP(gres_ptr->gpu_bit_alloc); - xfree(gres_ptr); - *gres_data = NULL; - return SLURM_ERROR; -} - extern void *node_state_dup(void *gres_data) { gpu_node_state_t *gres_ptr = (gpu_node_state_t *) gres_data; diff --git a/src/plugins/gres/nic/gres_nic.c b/src/plugins/gres/nic/gres_nic.c index 7a436e5acd4..8e7e6a897fa 100644 --- a/src/plugins/gres/nic/gres_nic.c +++ b/src/plugins/gres/nic/gres_nic.c @@ -191,56 +191,6 @@ extern int node_config_load(List gres_conf_list) return rc; } -extern int node_state_pack(void *gres_data, Buf buffer) -{ - nic_node_state_t *gres_ptr = (nic_node_state_t *) gres_data; - - pack32(gres_ptr->nic_cnt_avail, buffer); - pack32(gres_ptr->nic_cnt_alloc, buffer); - pack_bit_str(gres_ptr->nic_bit_alloc, buffer); - - return SLURM_SUCCESS; -} - -extern int node_state_unpack(void **gres_data, Buf buffer) -{ - nic_node_state_t *gres_ptr; - - gres_ptr = xmalloc(sizeof(nic_node_state_t)); - - gres_ptr->nic_cnt_found = NO_VAL; - if (buffer) { - safe_unpack32(&gres_ptr->nic_cnt_avail, buffer); - safe_unpack32(&gres_ptr->nic_cnt_alloc, buffer); - unpack_bit_str(&gres_ptr->nic_bit_alloc, buffer); - if (gres_ptr->nic_bit_alloc == NULL) - goto unpack_error; - if (gres_ptr->nic_cnt_avail != - bit_size(gres_ptr->nic_bit_alloc)) { - gres_ptr->nic_bit_alloc = - bit_realloc(gres_ptr->nic_bit_alloc, - gres_ptr->nic_cnt_avail); - if (gres_ptr->nic_bit_alloc == NULL) - goto unpack_error; - } - if (gres_ptr->nic_cnt_alloc != - bit_set_count(gres_ptr->nic_bit_alloc)) { - error("%s node_state_unpack bit count inconsistent", - plugin_name); - goto unpack_error; - } - } - - *gres_data = gres_ptr; - return SLURM_SUCCESS; - -unpack_error: - FREE_NULL_BITMAP(gres_ptr->nic_bit_alloc); - xfree(gres_ptr); - *gres_data = NULL; - return SLURM_ERROR; -} - extern void *node_state_dup(void *gres_data) { nic_node_state_t *gres_ptr = (nic_node_state_t *) gres_data; -- GitLab