diff --git a/src/common/pack.c b/src/common/pack.c index 935ff4342fa5e34db75aa7eed766583a1408ba4e..e17f6d2a4c0a474db046f8d5430e85a93f2e44d1 100644 --- a/src/common/pack.c +++ b/src/common/pack.c @@ -46,7 +46,34 @@ _unpack32(uint32_t *valp, void **bufp, int *lenp) (size_t)*bufp += sizeof(nl); *lenp -= sizeof(nl); } + +/* Given a int ptr, it will pack an array of size_val + */ +void +_pack32array(uint32_t *valp, uint16_t size_val, void **bufp, int *lenp) +{ + int i=0; + uint16_t nl = htons(size_val); + _pack16( nl, bufp, lenp ); + + for ( i=0; i < size_val; i++ ) { + _pack32( *(valp + i ), bufp, lenp ); + } +} + +/* Given a int ptr, it will pack an array of size_val + */ +void +_unpack32array( uint32_t **valp, uint16_t* size_val, void **bufp, int *lenp) +{ + int i=0; + _unpack16( size_val, bufp, lenp ); + valp = xmalloc( (*size_val) * sizeof( uint32_t ) ); + for ( i=0; i < *size_val; i++ ) { + _unpack32( valp + i , bufp, lenp ); + } +} /* * Given a 16-bit integer in host byte order, convert to network byte order * and store at 'bufp'. Advance bufp by 2 bytes, decrement lenp by 2 bytes. @@ -101,6 +128,8 @@ _packmem(char *valp, uint16_t size_val, void **bufp, int *lenp) } + + /* * Given 'bufp' pointing to a network byte order 32-bit integer * (size) and an arbitrary data string, return a pointer to the @@ -161,7 +190,8 @@ _unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp) *valp = NULL; } - /* + +/* * Given 'bufp' pointing to a network byte order 32-bit integer * (size) and an arbitrary data string, return a pointer to the * data string in 'valp'. Also return the sizes of 'valp' in bytes. diff --git a/src/common/pack.h b/src/common/pack.h index d9c53eaf029e9d3f5fef075d9e58eee413048ffd..db32ad7802a383137bb48a75c717ba5d85dee50a 100644 --- a/src/common/pack.h +++ b/src/common/pack.h @@ -25,6 +25,9 @@ void _unpack32(uint32_t *valp, void **bufp, int *lenp); void _pack16(uint16_t val, void **bufp, int *lenp); void _unpack16(uint16_t *valp, void **bufp, int *lenp); +void _pack32array(uint32_t *valp, uint16_t size_val, void **bufp, int *lenp); +void _unpack32array( uint32_t **valp, uint16_t* size_val, void **bufp, int *lenp); + void _packmem(char *valp, uint16_t size_val, void **bufp, int *lenp); void _unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp); void _unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp); @@ -83,6 +86,23 @@ void _unpackmem_malloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp) _packmem(str,(uint16_t)_size,bufp,lenp); \ } while (0) +#define packint_array(array,_size,bufp,lenp) do { \ + assert((bufp) != NULL && *(bufp) != NULL); \ + assert((lenp) != NULL); \ + assert(*(lenp) >= (sizeof(_size)+_size)); \ + _pack32array(array,(uint16_t)_size,bufp,lenp); \ +} while (0) + +#define unpackint_array(valp,size_valp,bufp,lenp) do { \ + assert(valp != NULL); \ + assert(sizeof(size_valp) == sizeof(uint16_t *));\ + assert((bufp) != NULL && *(bufp) != NULL); \ + assert((lenp) != NULL); \ + assert(*(lenp) >= sizeof(uint16_t)); \ + _unpack32array(valp,(uint16_t *)size_valp,bufp,lenp);\ +} while (0) + + #define unpackmem_ptr(valp,size_valp,bufp,lenp) do { \ assert(valp != NULL); \ assert(sizeof(size_valp) == sizeof(uint16_t *));\ diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h index 05b15e179151cf558c494d5d568cd7987bb84674..b80eb80c5fd8b33248811299d7998d0dddedcad5 100644 --- a/src/common/slurm_protocol_defs.h +++ b/src/common/slurm_protocol_defs.h @@ -169,8 +169,9 @@ typedef struct resource_allocation_response_msg { uint32_t job_id; char* node_list; - uint32_t* cpus_per_node; - uint32_t* cpu_count_reps; + int16_t num_cpu_groups; + int32_t* cpus_per_node; + int32_t* cpu_count_reps; } resource_allocation_response_msg_t ; typedef struct job_desc_msg { /* Job descriptor for submit, allocate, and update requests */ diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c index 3e57c195aa8aacbf1c1e2c3e516720f6c819c887..a95a10c24b2da119d928745652735ff8f4e8b3a9 100644 --- a/src/common/slurm_protocol_pack.c +++ b/src/common/slurm_protocol_pack.c @@ -84,7 +84,7 @@ int pack_msg ( slurm_msg_t const * msg , char ** buffer , uint32_t * buf_len ) case RESPONSE_RESOURCE_ALLOCATION : case RESPONSE_IMMEDIATE_RESOURCE_ALLOCATION : case RESPONSE_JOB_WILL_RUN : - pack_job_allocation_response_msg ( ( resource_allocation_response_msg_t * ) msg -> data , ( void ** ) buffer , buf_len ) ; + pack_resource_allocation_response_msg ( ( resource_allocation_response_msg_t * ) msg -> data , ( void ** ) buffer , buf_len ) ; break ; case REQUEST_UPDATE_NODE : pack_update_node_msg ( ( update_node_msg_t * ) msg-> data , ( void ** ) buffer , buf_len ) ; @@ -198,7 +198,7 @@ int unpack_msg ( slurm_msg_t * msg , char ** buffer , uint32_t * buf_len ) case RESPONSE_RESOURCE_ALLOCATION : case RESPONSE_IMMEDIATE_RESOURCE_ALLOCATION : case RESPONSE_JOB_WILL_RUN : - unpack_job_allocation_response_msg ( ( resource_allocation_response_msg_t ** ) & ( msg -> data ) , ( void ** ) buffer , buf_len ) ; + unpack_resource_allocation_response_msg ( ( resource_allocation_response_msg_t ** ) & ( msg -> data ) , ( void ** ) buffer , buf_len ) ; break ; case REQUEST_UPDATE_NODE : @@ -289,30 +289,6 @@ int unpack_update_node_msg ( update_node_msg_t ** msg , void ** buffer , uint32_ return 0 ; } -void pack_job_allocation_response_msg ( resource_allocation_response_msg_t * msg, void ** buffer , uint32_t * length ) -{ - pack32 ( msg -> job_id , ( void ** ) buffer , length ) ; - packstr ( msg -> node_list , ( void ** ) buffer , length ) ; -} - -int unpack_job_allocation_response_msg ( resource_allocation_response_msg_t ** msg , void ** buffer , uint32_t * length ) -{ - uint16_t uint16_tmp; - resource_allocation_response_msg_t * tmp_ptr ; - /* alloc memory for structure */ - tmp_ptr = xmalloc ( sizeof ( resource_allocation_response_msg_t ) ) ; - if (tmp_ptr == NULL) - { - return ENOMEM; - } - - /* load the data values */ - unpack32 ( & tmp_ptr -> job_id , ( void ** ) buffer , length ) ; - unpackstr_xmalloc ( & tmp_ptr -> node_list , &uint16_tmp, ( void ** ) buffer , length ) ; - *msg = tmp_ptr ; - return 0 ; -} - void pack_node_registration_status_msg ( slurm_node_registration_status_msg_t * msg, void ** buffer , uint32_t * length ) { pack32 ( msg -> timestamp , ( void ** ) buffer , length ) ; @@ -344,6 +320,36 @@ int unpack_node_registration_status_msg ( slurm_node_registration_status_msg_t * return 0 ; } +void pack_resource_allocation_response_msg ( resource_allocation_response_msg_t * msg, void ** buffer , int * length ) +{ + pack32 ( msg->job_id , ( void ** ) buffer , length ) ; + packstr ( msg->node_list , ( void ** ) buffer , length ) ; + pack16 ( msg->num_cpu_groups , ( void ** ) buffer , length ) ; + packint_array ( msg->cpus_per_node, msg->num_cpu_groups , ( void ** ) buffer , length ) ; + packint_array ( msg->cpu_count_reps, msg->num_cpu_groups, ( void ** ) buffer , length ) ; +} + +int unpack_resource_allocation_response_msg ( resource_allocation_response_msg_t ** msg , void ** buffer , int * length ) +{ + uint16_t uint16_tmp; + resource_allocation_response_msg_t * tmp_ptr ; + /* alloc memory for structure */ + tmp_ptr = xmalloc ( sizeof ( resource_allocation_response_msg_t ) ) ; + if (tmp_ptr == NULL) + { + return ENOMEM; + } + + /* load the data values */ + unpack32 ( & tmp_ptr -> job_id , ( void ** ) buffer , length ) ; + unpackstr_xmalloc ( & tmp_ptr -> node_list , &uint16_tmp, ( void ** ) buffer , length ) ; + unpack16 ( & tmp_ptr -> num_cpu_groups , ( void ** ) buffer , length ) ; + unpackint_array ( &tmp_ptr->cpus_per_node, &uint16_tmp, ( void ** ) buffer , length ) ; + unpackint_array ( &tmp_ptr->cpu_count_reps,&uint16_tmp, ( void ** ) buffer , length ) ; + *msg = tmp_ptr ; + return 0 ; +} + void pack_node_info_msg ( slurm_msg_t * msg, void ** buf_ptr , int * buffer_size ) { assert ( msg != NULL ); diff --git a/src/common/slurm_protocol_pack.h b/src/common/slurm_protocol_pack.h index 7332b88e8d3645755a58249ee90822e38dddf58e..f305e94bb5dff68e1cb5bc9eb63b9a71e45fdfbf 100644 --- a/src/common/slurm_protocol_pack.h +++ b/src/common/slurm_protocol_pack.h @@ -58,8 +58,8 @@ int unpack_node_info_msg ( node_info_msg_t ** msg , void ** buf_ptr , int * buff int unpack_node_table_msg ( node_table_msg_t ** node , void ** buf_ptr , int * buffer_size ); int unpack_node_table ( node_table_msg_t * node , void ** buf_ptr , int * buffer_size ); -void pack_job_allocation_response_msg ( resource_allocation_response_msg_t * msg, void ** buffer , uint32_t * length ); -int unpack_job_allocation_response_msg ( resource_allocation_response_msg_t ** msg , void ** buffer , uint32_t * length ); +void pack_resource_allocation_response_msg ( resource_allocation_response_msg_t * msg, void ** buffer , int * length ); +int unpack_resource_allocation_response_msg ( resource_allocation_response_msg_t ** msg , void ** buffer , int * length ); void pack_update_node_msg ( update_node_msg_t * msg, void ** buffer , uint32_t * length ); int unpack_update_node_msg ( update_node_msg_t ** msg , void ** buffer , uint32_t * length );