root/opal/dss/dss_unpack.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_dss_unpack
  2. opal_dss_unpack_buffer
  3. opal_dss_unpack_bool
  4. opal_dss_unpack_int
  5. opal_dss_unpack_sizet
  6. opal_dss_unpack_pid
  7. opal_dss_unpack_null
  8. opal_dss_unpack_byte
  9. opal_dss_unpack_int16
  10. opal_dss_unpack_int32
  11. opal_dss_unpack_int64
  12. opal_dss_unpack_string
  13. opal_dss_unpack_float
  14. opal_dss_unpack_double
  15. opal_dss_unpack_timeval
  16. opal_dss_unpack_time
  17. opal_dss_unpack_data_type
  18. opal_dss_unpack_byte_object
  19. opal_dss_unpack_pstat
  20. unpack_disk_stats
  21. unpack_net_stats
  22. opal_dss_unpack_node_stat
  23. opal_dss_unpack_value
  24. opal_dss_unpack_buffer_contents
  25. opal_dss_unpack_name
  26. opal_dss_unpack_jobid
  27. opal_dss_unpack_vpid
  28. opal_dss_unpack_status
  29. opal_dss_unpack_envar

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2006 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2012-2015 Los Alamos National Security, Inc.  All rights reserved.
  14  * Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
  15  * Copyright (c) 2014-2015 Research Organization for Information Science
  16  *                         and Technology (RIST). All rights reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "opal_config.h"
  25 #include "opal/types.h"
  26 #include "opal/util/error.h"
  27 #include "opal/util/output.h"
  28 #include "opal/dss/dss_internal.h"
  29 
  30 int opal_dss_unpack(opal_buffer_t *buffer, void *dst, int32_t *num_vals,
  31                     opal_data_type_t type)
  32 {
  33     int rc, ret;
  34     int32_t local_num, n=1;
  35     opal_data_type_t local_type;
  36 
  37     /* check for error */
  38     if (NULL == buffer || NULL == dst || NULL == num_vals) {
  39         return OPAL_ERR_BAD_PARAM;
  40     }
  41 
  42     /* if user provides a zero for num_vals, then there is no storage allocated
  43      * so return an appropriate error
  44      */
  45     if (0 == *num_vals) {
  46         OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack: inadequate space ( %p, %p, %lu, %d )\n",
  47                        (void*)buffer, dst, (long unsigned int)*num_vals, (int)type ) );
  48         return OPAL_ERR_UNPACK_INADEQUATE_SPACE;
  49     }
  50 
  51     /** Unpack the declared number of values
  52      * REMINDER: it is possible that the buffer is corrupted and that
  53      * the DSS will *think* there is a proper int32_t variable at the
  54      * beginning of the unpack region - but that the value is bogus (e.g., just
  55      * a byte field in a string array that so happens to have a value that
  56      * matches the int32_t data type flag). Therefore, this error check is
  57      * NOT completely safe. This is true for ALL unpack functions, not just
  58      * int32_t as used here.
  59      */
  60     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
  61         if (OPAL_SUCCESS != (
  62             rc = opal_dss_get_data_type(buffer, &local_type))) {
  63             *num_vals = 0;
  64             return rc;
  65         }
  66         if (OPAL_INT32 != local_type) { /* if the length wasn't first, then error */
  67             *num_vals = 0;
  68             return OPAL_ERR_UNPACK_FAILURE;
  69         }
  70     }
  71 
  72     n=1;
  73     if (OPAL_SUCCESS != (rc = opal_dss_unpack_int32(buffer, &local_num, &n, OPAL_INT32))) {
  74         *num_vals = 0;
  75         return rc;
  76     }
  77 
  78     /** if the storage provided is inadequate, set things up
  79      * to unpack as much as we can and to return an error code
  80      * indicating that everything was not unpacked - the buffer
  81      * is left in a state where it can not be further unpacked.
  82      */
  83     if (local_num > *num_vals) {
  84         local_num = *num_vals;
  85         OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack: inadequate space ( %p, %p, %lu, %d )\n",
  86                        (void*)buffer, dst, (long unsigned int)*num_vals, (int)type ) );
  87         ret = OPAL_ERR_UNPACK_INADEQUATE_SPACE;
  88     } else {  /** enough or more than enough storage */
  89         *num_vals = local_num;  /** let the user know how many we actually unpacked */
  90         ret = OPAL_SUCCESS;
  91     }
  92 
  93     /** Unpack the value(s) */
  94     if (OPAL_SUCCESS != (rc = opal_dss_unpack_buffer(buffer, dst, &local_num, type))) {
  95         *num_vals = 0;
  96         ret = rc;
  97     }
  98 
  99     return ret;
 100 }
 101 
 102 int opal_dss_unpack_buffer(opal_buffer_t *buffer, void *dst, int32_t *num_vals,
 103                     opal_data_type_t type)
 104 {
 105     int rc;
 106     opal_data_type_t local_type;
 107     opal_dss_type_info_t *info;
 108 
 109     OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_buffer( %p, %p, %lu, %d )\n",
 110                    (void*)buffer, dst, (long unsigned int)*num_vals, (int)type ) );
 111 
 112     /** Unpack the declared data type */
 113     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
 114         if (OPAL_SUCCESS != (rc = opal_dss_get_data_type(buffer, &local_type))) {
 115             return rc;
 116         }
 117         /* if the data types don't match, then return an error */
 118         if (type != local_type) {
 119             opal_output(0, "OPAL dss:unpack: got type %d when expecting type %d", local_type, type);
 120             return OPAL_ERR_PACK_MISMATCH;
 121         }
 122     }
 123 
 124     /* Lookup the unpack function for this type and call it */
 125 
 126     if (NULL == (info = (opal_dss_type_info_t*)opal_pointer_array_get_item(&opal_dss_types, type))) {
 127         return OPAL_ERR_UNPACK_FAILURE;
 128     }
 129 
 130     return info->odti_unpack_fn(buffer, dst, num_vals, type);
 131 }
 132 
 133 
 134 /* UNPACK GENERIC SYSTEM TYPES */
 135 
 136 /*
 137  * BOOL
 138  */
 139 int opal_dss_unpack_bool(opal_buffer_t *buffer, void *dest,
 140                          int32_t *num_vals, opal_data_type_t type)
 141 {
 142     int ret;
 143     opal_data_type_t remote_type;
 144 
 145     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
 146         /* see what type was actually packed */
 147         if (OPAL_SUCCESS != (ret = opal_dss_peek_type(buffer, &remote_type))) {
 148             return ret;
 149         }
 150     } else {
 151         if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(buffer, &remote_type))) {
 152             return ret;
 153         }
 154     }
 155 
 156     if (remote_type == DSS_TYPE_BOOL) {
 157         /* fast path it if the sizes are the same */
 158         /* Turn around and unpack the real type */
 159         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, DSS_TYPE_BOOL))) {
 160         }
 161     } else {
 162         /* slow path - types are different sizes */
 163         UNPACK_SIZE_MISMATCH(bool, remote_type, ret);
 164     }
 165     return ret;
 166 }
 167 
 168 /*
 169  * INT
 170  */
 171 int opal_dss_unpack_int(opal_buffer_t *buffer, void *dest,
 172                         int32_t *num_vals, opal_data_type_t type)
 173 {
 174     int ret;
 175     opal_data_type_t remote_type;
 176 
 177     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
 178         /* see what type was actually packed */
 179         if (OPAL_SUCCESS != (ret = opal_dss_peek_type(buffer, &remote_type))) {
 180             return ret;
 181         }
 182     } else {
 183         if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(buffer, &remote_type))) {
 184             return ret;
 185         }
 186     }
 187 
 188     if (remote_type == DSS_TYPE_INT) {
 189         /* fast path it if the sizes are the same */
 190         /* Turn around and unpack the real type */
 191         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, DSS_TYPE_INT))) {
 192         }
 193     } else {
 194         /* slow path - types are different sizes */
 195         UNPACK_SIZE_MISMATCH(int, remote_type, ret);
 196     }
 197 
 198     return ret;
 199 }
 200 
 201 /*
 202  * SIZE_T
 203  */
 204 int opal_dss_unpack_sizet(opal_buffer_t *buffer, void *dest,
 205                           int32_t *num_vals, opal_data_type_t type)
 206 {
 207     int ret;
 208     opal_data_type_t remote_type;
 209 
 210     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
 211         /* see what type was actually packed */
 212         if (OPAL_SUCCESS != (ret = opal_dss_peek_type(buffer, &remote_type))) {
 213             return ret;
 214         }
 215     } else {
 216         if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(buffer, &remote_type))) {
 217             return ret;
 218         }
 219     }
 220 
 221     if (remote_type == DSS_TYPE_SIZE_T) {
 222         /* fast path it if the sizes are the same */
 223         /* Turn around and unpack the real type */
 224         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, DSS_TYPE_SIZE_T))) {
 225         }
 226     } else {
 227         /* slow path - types are different sizes */
 228         UNPACK_SIZE_MISMATCH(size_t, remote_type, ret);
 229     }
 230 
 231     return ret;
 232 }
 233 
 234 /*
 235  * PID_T
 236  */
 237 int opal_dss_unpack_pid(opal_buffer_t *buffer, void *dest,
 238                         int32_t *num_vals, opal_data_type_t type)
 239 {
 240     int ret;
 241     opal_data_type_t remote_type;
 242 
 243     if (OPAL_DSS_BUFFER_FULLY_DESC == buffer->type) {
 244         /* see what type was actually packed */
 245         if (OPAL_SUCCESS != (ret = opal_dss_peek_type(buffer, &remote_type))) {
 246             return ret;
 247         }
 248     } else {
 249         if (OPAL_SUCCESS != (ret = opal_dss_get_data_type(buffer, &remote_type))) {
 250             return ret;
 251         }
 252     }
 253 
 254     if (remote_type == DSS_TYPE_PID_T) {
 255         /* fast path it if the sizes are the same */
 256         /* Turn around and unpack the real type */
 257         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, DSS_TYPE_PID_T))) {
 258         }
 259     } else {
 260         /* slow path - types are different sizes */
 261         UNPACK_SIZE_MISMATCH(pid_t, remote_type, ret);
 262     }
 263 
 264     return ret;
 265 }
 266 
 267 
 268 /* UNPACK FUNCTIONS FOR NON-GENERIC SYSTEM TYPES */
 269 
 270 /*
 271  * NULL
 272  */
 273 int opal_dss_unpack_null(opal_buffer_t *buffer, void *dest,
 274                          int32_t *num_vals, opal_data_type_t type)
 275 {
 276     OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_null * %d\n", (int)*num_vals ) );
 277     /* check to see if there's enough data in buffer */
 278     if (opal_dss_too_small(buffer, *num_vals)) {
 279         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 280     }
 281 
 282     /* unpack the data */
 283     memcpy(dest, buffer->unpack_ptr, *num_vals);
 284 
 285     /* update buffer pointer */
 286     buffer->unpack_ptr += *num_vals;
 287 
 288     return OPAL_SUCCESS;
 289 }
 290 
 291 /*
 292  * BYTE, CHAR, INT8
 293  */
 294 int opal_dss_unpack_byte(opal_buffer_t *buffer, void *dest,
 295                          int32_t *num_vals, opal_data_type_t type)
 296 {
 297     OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_byte * %d\n", (int)*num_vals ) );
 298     /* check to see if there's enough data in buffer */
 299     if (opal_dss_too_small(buffer, *num_vals)) {
 300         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 301     }
 302 
 303     /* unpack the data */
 304     memcpy(dest, buffer->unpack_ptr, *num_vals);
 305 
 306     /* update buffer pointer */
 307     buffer->unpack_ptr += *num_vals;
 308 
 309     return OPAL_SUCCESS;
 310 }
 311 
 312 int opal_dss_unpack_int16(opal_buffer_t *buffer, void *dest,
 313                           int32_t *num_vals, opal_data_type_t type)
 314 {
 315     int32_t i;
 316     uint16_t tmp, *desttmp = (uint16_t*) dest;
 317 
 318    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_int16 * %d\n", (int)*num_vals ) );
 319     /* check to see if there's enough data in buffer */
 320     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(tmp))) {
 321         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 322     }
 323 
 324     /* unpack the data */
 325     for (i = 0; i < (*num_vals); ++i) {
 326         memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
 327         tmp = ntohs(tmp);
 328         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 329         buffer->unpack_ptr += sizeof(tmp);
 330     }
 331 
 332     return OPAL_SUCCESS;
 333 }
 334 
 335 int opal_dss_unpack_int32(opal_buffer_t *buffer, void *dest,
 336                           int32_t *num_vals, opal_data_type_t type)
 337 {
 338     int32_t i;
 339     uint32_t tmp, *desttmp = (uint32_t*) dest;
 340 
 341    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_int32 * %d\n", (int)*num_vals ) );
 342     /* check to see if there's enough data in buffer */
 343     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(tmp))) {
 344         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 345     }
 346 
 347     /* unpack the data */
 348     for (i = 0; i < (*num_vals); ++i) {
 349         memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
 350         tmp = ntohl(tmp);
 351         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 352         buffer->unpack_ptr += sizeof(tmp);
 353     }
 354 
 355     return OPAL_SUCCESS;
 356 }
 357 
 358 int opal_dss_unpack_int64(opal_buffer_t *buffer, void *dest,
 359                           int32_t *num_vals, opal_data_type_t type)
 360 {
 361     int32_t i;
 362     uint64_t tmp, *desttmp = (uint64_t*) dest;
 363 
 364    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_int64 * %d\n", (int)*num_vals ) );
 365     /* check to see if there's enough data in buffer */
 366     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(tmp))) {
 367         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 368     }
 369 
 370     /* unpack the data */
 371     for (i = 0; i < (*num_vals); ++i) {
 372         memcpy( &(tmp), buffer->unpack_ptr, sizeof(tmp) );
 373         tmp = ntoh64(tmp);
 374         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 375         buffer->unpack_ptr += sizeof(tmp);
 376     }
 377 
 378     return OPAL_SUCCESS;
 379 }
 380 
 381 int opal_dss_unpack_string(opal_buffer_t *buffer, void *dest,
 382                            int32_t *num_vals, opal_data_type_t type)
 383 {
 384     int ret;
 385     int32_t i, len, n=1;
 386     char **sdest = (char**) dest;
 387 
 388     for (i = 0; i < (*num_vals); ++i) {
 389         if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &len, &n, OPAL_INT32))) {
 390             return ret;
 391         }
 392         if (0 ==  len) {   /* zero-length string - unpack the NULL */
 393             sdest[i] = NULL;
 394         } else {
 395         sdest[i] = (char*)malloc(len);
 396             if (NULL == sdest[i]) {
 397                 return OPAL_ERR_OUT_OF_RESOURCE;
 398             }
 399             if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, sdest[i], &len, OPAL_BYTE))) {
 400                 return ret;
 401             }
 402         }
 403     }
 404 
 405     return OPAL_SUCCESS;
 406 }
 407 
 408 int opal_dss_unpack_float(opal_buffer_t *buffer, void *dest,
 409                           int32_t *num_vals, opal_data_type_t type)
 410 {
 411     int32_t i, n;
 412     float *desttmp = (float*) dest, tmp;
 413     int ret;
 414     char *convert;
 415 
 416    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_float * %d\n", (int)*num_vals ) );
 417     /* check to see if there's enough data in buffer */
 418     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(float))) {
 419         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 420     }
 421 
 422     /* unpack the data */
 423     for (i = 0; i < (*num_vals); ++i) {
 424         n=1;
 425         if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &convert, &n, OPAL_STRING))) {
 426             return ret;
 427         }
 428         if (NULL == convert) {
 429             return OPAL_ERR_UNPACK_FAILURE;
 430         }
 431         tmp = strtof(convert, NULL);
 432         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 433         free(convert);
 434         convert = NULL;
 435     }
 436     return OPAL_SUCCESS;
 437 }
 438 
 439 int opal_dss_unpack_double(opal_buffer_t *buffer, void *dest,
 440                            int32_t *num_vals, opal_data_type_t type)
 441 {
 442     int32_t i, n;
 443     double *desttmp = (double*) dest, tmp;
 444     int ret;
 445     char *convert;
 446 
 447    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_double * %d\n", (int)*num_vals ) );
 448     /* check to see if there's enough data in buffer */
 449     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(double))) {
 450         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 451     }
 452 
 453     /* unpack the data */
 454     for (i = 0; i < (*num_vals); ++i) {
 455         n=1;
 456         if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &convert, &n, OPAL_STRING))) {
 457             return ret;
 458         }
 459         if (NULL == convert) {
 460             return OPAL_ERR_UNPACK_FAILURE;
 461         }
 462         tmp = strtod(convert, NULL);
 463         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 464         free(convert);
 465         convert = NULL;
 466     }
 467     return OPAL_SUCCESS;
 468 }
 469 
 470 int opal_dss_unpack_timeval(opal_buffer_t *buffer, void *dest,
 471                             int32_t *num_vals, opal_data_type_t type)
 472 {
 473     int32_t i, n;
 474     int64_t tmp[2];
 475     struct timeval *desttmp = (struct timeval *) dest, tt;
 476     int ret;
 477 
 478    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_timeval * %d\n", (int)*num_vals ) );
 479     /* check to see if there's enough data in buffer */
 480     if (opal_dss_too_small(buffer, (*num_vals)*sizeof(struct timeval))) {
 481         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 482     }
 483 
 484     /* unpack the data */
 485     for (i = 0; i < (*num_vals); ++i) {
 486         n=2;
 487         if (OPAL_SUCCESS != (ret = opal_dss_unpack_int64(buffer, tmp, &n, OPAL_INT64))) {
 488             return ret;
 489         }
 490         tt.tv_sec = tmp[0];
 491         tt.tv_usec = tmp[1];
 492         memcpy(&desttmp[i], &tt, sizeof(tt));
 493     }
 494     return OPAL_SUCCESS;
 495 }
 496 
 497 int opal_dss_unpack_time(opal_buffer_t *buffer, void *dest,
 498                          int32_t *num_vals, opal_data_type_t type)
 499 {
 500     int32_t i, n;
 501     time_t *desttmp = (time_t *) dest, tmp;
 502     int ret;
 503     uint64_t ui64;
 504 
 505     /* time_t is a system-dependent size, so cast it
 506      * to uint64_t as a generic safe size
 507      */
 508 
 509    OPAL_OUTPUT( ( opal_dss_verbose, "opal_dss_unpack_time * %d\n", (int)*num_vals ) );
 510     /* check to see if there's enough data in buffer */
 511    if (opal_dss_too_small(buffer, (*num_vals)*(sizeof(uint64_t)))) {
 512         return OPAL_ERR_UNPACK_READ_PAST_END_OF_BUFFER;
 513     }
 514 
 515     /* unpack the data */
 516     for (i = 0; i < (*num_vals); ++i) {
 517         n=1;
 518         if (OPAL_SUCCESS != (ret = opal_dss_unpack_int64(buffer, &ui64, &n, OPAL_UINT64))) {
 519             return ret;
 520         }
 521         tmp = (time_t)ui64;
 522         memcpy(&desttmp[i], &tmp, sizeof(tmp));
 523     }
 524     return OPAL_SUCCESS;
 525 }
 526 
 527 
 528 /* UNPACK FUNCTIONS FOR GENERIC OPAL TYPES */
 529 
 530 /*
 531  * OPAL_DATA_TYPE
 532  */
 533 int opal_dss_unpack_data_type(opal_buffer_t *buffer, void *dest, int32_t *num_vals,
 534                              opal_data_type_t type)
 535 {
 536      /* turn around and unpack the real type */
 537     return opal_dss_unpack_buffer(buffer, dest, num_vals, OPAL_DATA_TYPE_T);
 538 }
 539 
 540 /*
 541  * OPAL_BYTE_OBJECT
 542  */
 543 int opal_dss_unpack_byte_object(opal_buffer_t *buffer, void *dest, int32_t *num,
 544                              opal_data_type_t type)
 545 {
 546     int ret;
 547     int32_t i, n, m=1;
 548     opal_byte_object_t **dbyteptr;
 549 
 550     dbyteptr = (opal_byte_object_t**)dest;
 551     n = *num;
 552     for(i=0; i<n; i++) {
 553         /* allocate memory for the byte object itself */
 554         dbyteptr[i] = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
 555         if (NULL == dbyteptr[i]) {
 556             return OPAL_ERR_OUT_OF_RESOURCE;
 557         }
 558 
 559         /* unpack object size in bytes */
 560         if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &(dbyteptr[i]->size), &m, OPAL_INT32))) {
 561             return ret;
 562         }
 563         if (0 < dbyteptr[i]->size) {
 564             dbyteptr[i]->bytes = (uint8_t*)malloc(dbyteptr[i]->size);
 565             if (NULL == dbyteptr[i]->bytes) {
 566                 return OPAL_ERR_OUT_OF_RESOURCE;
 567             }
 568             if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, (dbyteptr[i]->bytes),
 569                                             &(dbyteptr[i]->size), OPAL_BYTE))) {
 570                 return ret;
 571             }
 572         } else {
 573             /* be sure to init the bytes pointer to NULL! */
 574             dbyteptr[i]->bytes = NULL;
 575         }
 576     }
 577 
 578     return OPAL_SUCCESS;
 579 }
 580 
 581 /*
 582  * OPAL_PSTAT
 583  */
 584 int opal_dss_unpack_pstat(opal_buffer_t *buffer, void *dest,
 585                           int32_t *num_vals, opal_data_type_t type)
 586 {
 587     opal_pstats_t **ptr;
 588     int32_t i, n, m;
 589     int ret;
 590     char *cptr;
 591 
 592     ptr = (opal_pstats_t **) dest;
 593     n = *num_vals;
 594 
 595     for (i = 0; i < n; ++i) {
 596         /* allocate the new object */
 597         ptr[i] = OBJ_NEW(opal_pstats_t);
 598         if (NULL == ptr[i]) {
 599             return OPAL_ERR_OUT_OF_RESOURCE;
 600         }
 601         m=1;
 602         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &cptr, &m, OPAL_STRING))) {
 603             OPAL_ERROR_LOG(ret);
 604             return ret;
 605         }
 606         memmove(ptr[i]->node, cptr, strlen(cptr));
 607         free(cptr);
 608         m=1;
 609         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->rank, &m, OPAL_INT32))) {
 610             OPAL_ERROR_LOG(ret);
 611             return ret;
 612         }
 613         m=1;
 614         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->pid, &m, OPAL_PID))) {
 615             OPAL_ERROR_LOG(ret);
 616             return ret;
 617         }
 618         m=1;
 619         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &cptr, &m, OPAL_STRING))) {
 620             OPAL_ERROR_LOG(ret);
 621             return ret;
 622         }
 623         memmove(ptr[i]->cmd, cptr, strlen(cptr));
 624         free(cptr);
 625         m=1;
 626         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->state[0], &m, OPAL_BYTE))) {
 627             OPAL_ERROR_LOG(ret);
 628             return ret;
 629         }
 630         m=1;
 631         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->time, &m, OPAL_TIMEVAL))) {
 632             OPAL_ERROR_LOG(ret);
 633             return ret;
 634         }
 635         m=1;
 636         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->priority, &m, OPAL_INT32))) {
 637             OPAL_ERROR_LOG(ret);
 638             return ret;
 639         }
 640         m=1;
 641         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->num_threads, &m, OPAL_INT16))) {
 642             OPAL_ERROR_LOG(ret);
 643             return ret;
 644         }
 645         m=1;
 646         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->pss, &m, OPAL_FLOAT))) {
 647             OPAL_ERROR_LOG(ret);
 648             return ret;
 649         }
 650         m=1;
 651         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->vsize, &m, OPAL_FLOAT))) {
 652             OPAL_ERROR_LOG(ret);
 653             return ret;
 654         }
 655         m=1;
 656         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->rss, &m, OPAL_FLOAT))) {
 657             OPAL_ERROR_LOG(ret);
 658             return ret;
 659         }
 660         m=1;
 661         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->peak_vsize, &m, OPAL_FLOAT))) {
 662             OPAL_ERROR_LOG(ret);
 663             return ret;
 664         }
 665         m=1;
 666         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->processor, &m, OPAL_INT16))) {
 667             OPAL_ERROR_LOG(ret);
 668             return ret;
 669         }
 670         m=1;
 671         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->sample_time, &m, OPAL_TIMEVAL))) {
 672             OPAL_ERROR_LOG(ret);
 673             return ret;
 674         }
 675     }
 676 
 677     return OPAL_SUCCESS;
 678 }
 679 
 680 static int unpack_disk_stats(opal_buffer_t *buffer, opal_node_stats_t *ns)
 681 {
 682     int32_t i, m, n;
 683     int ret;
 684     opal_diskstats_t *dk;
 685     uint64_t i64;
 686 
 687     /* unpack the number of disk stat objects */
 688     m=1;
 689     if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &n, &m, OPAL_INT32))) {
 690         OPAL_ERROR_LOG(ret);
 691         return ret;
 692     }
 693     /* unpack them */
 694     for (i=0; i < n; i++) {
 695         dk = OBJ_NEW(opal_diskstats_t);
 696         assert(dk);
 697         m=1;
 698         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &dk->disk, &m, OPAL_STRING))) {
 699             OPAL_ERROR_LOG(ret);
 700             OBJ_RELEASE(dk);
 701             return ret;
 702         }
 703         m=1;
 704         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 705             OPAL_ERROR_LOG(ret);
 706             OBJ_RELEASE(dk);
 707             return ret;
 708         }
 709         dk->num_reads_completed = i64;
 710         m=1;
 711         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 712             OPAL_ERROR_LOG(ret);
 713             OBJ_RELEASE(dk);
 714             return ret;
 715         }
 716         dk->num_reads_merged = i64;
 717         m=1;
 718         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 719             OPAL_ERROR_LOG(ret);
 720             OBJ_RELEASE(dk);
 721             return ret;
 722         }
 723         dk->num_sectors_read = i64;
 724         m=1;
 725         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 726             OPAL_ERROR_LOG(ret);
 727             OBJ_RELEASE(dk);
 728             return ret;
 729         }
 730         dk->milliseconds_reading = i64;
 731         m=1;
 732         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 733             OPAL_ERROR_LOG(ret);
 734             OBJ_RELEASE(dk);
 735             return ret;
 736         }
 737         dk->num_writes_completed = i64;
 738         m=1;
 739         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 740             OPAL_ERROR_LOG(ret);
 741             OBJ_RELEASE(dk);
 742             return ret;
 743         }
 744         dk->num_writes_merged = i64;
 745         m=1;
 746         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 747             OPAL_ERROR_LOG(ret);
 748             OBJ_RELEASE(dk);
 749             return ret;
 750         }
 751         dk->num_sectors_written = i64;
 752         m=1;
 753         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 754             OPAL_ERROR_LOG(ret);
 755             OBJ_RELEASE(dk);
 756             return ret;
 757         }
 758         dk->milliseconds_writing = i64;
 759         m=1;
 760         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 761             OPAL_ERROR_LOG(ret);
 762             OBJ_RELEASE(dk);
 763             return ret;
 764         }
 765         dk->num_ios_in_progress = i64;
 766         m=1;
 767         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 768             OPAL_ERROR_LOG(ret);
 769             OBJ_RELEASE(dk);
 770             return ret;
 771         }
 772         dk->milliseconds_io = i64;
 773         m=1;
 774         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 775             OPAL_ERROR_LOG(ret);
 776             OBJ_RELEASE(dk);
 777             return ret;
 778         }
 779         dk->weighted_milliseconds_io = i64;
 780         opal_list_append(&ns->diskstats, &dk->super);
 781     }
 782     return OPAL_SUCCESS;
 783 }
 784 
 785 static int unpack_net_stats(opal_buffer_t *buffer, opal_node_stats_t *ns)
 786 {
 787     int32_t i, m, n;
 788     int ret;
 789     opal_netstats_t *net;
 790     uint64_t i64;
 791 
 792     /* unpack the number of net stat objects */
 793     m=1;
 794     if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &n, &m, OPAL_INT32))) {
 795         OPAL_ERROR_LOG(ret);
 796         return ret;
 797     }
 798     /* unpack them */
 799     for (i=0; i < n; i++) {
 800         net = OBJ_NEW(opal_netstats_t);
 801         assert(net);
 802         m=1;
 803         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &net->net_interface, &m, OPAL_STRING))) {
 804             OPAL_ERROR_LOG(ret);
 805             OBJ_RELEASE(net);
 806             return ret;
 807         }
 808         m=1;
 809         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 810             OPAL_ERROR_LOG(ret);
 811             OBJ_RELEASE(net);
 812             return ret;
 813         }
 814         net->num_bytes_recvd = i64;
 815         m=1;
 816         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 817             OPAL_ERROR_LOG(ret);
 818             OBJ_RELEASE(net);
 819             return ret;
 820         }
 821         net->num_packets_recvd = i64;
 822         m=1;
 823         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 824             OPAL_ERROR_LOG(ret);
 825             OBJ_RELEASE(net);
 826             return ret;
 827         }
 828         net->num_recv_errs = i64;
 829         m=1;
 830         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 831             OPAL_ERROR_LOG(ret);
 832             OBJ_RELEASE(net);
 833             return ret;
 834         }
 835         net->num_bytes_sent = i64;
 836         m=1;
 837         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 838             OPAL_ERROR_LOG(ret);
 839             OBJ_RELEASE(net);
 840             return ret;
 841         }
 842         net->num_packets_sent = i64;
 843         m=1;
 844         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &i64, &m, OPAL_UINT64))) {
 845             OPAL_ERROR_LOG(ret);
 846             OBJ_RELEASE(net);
 847             return ret;
 848         }
 849         net->num_send_errs = i64;
 850         opal_list_append(&ns->netstats, &net->super);
 851     }
 852     return OPAL_SUCCESS;
 853 }
 854 
 855 /*
 856  * OPAL_NODE_STAT
 857  */
 858 int opal_dss_unpack_node_stat(opal_buffer_t *buffer, void *dest,
 859                               int32_t *num_vals, opal_data_type_t type)
 860 {
 861     opal_node_stats_t **ptr;
 862     int32_t i, n, m;
 863     int ret;
 864 
 865     ptr = (opal_node_stats_t **) dest;
 866     n = *num_vals;
 867 
 868     for (i = 0; i < n; ++i) {
 869         /* allocate the new object */
 870         ptr[i] = OBJ_NEW(opal_node_stats_t);
 871         if (NULL == ptr[i]) {
 872             return OPAL_ERR_OUT_OF_RESOURCE;
 873         }
 874         m=1;
 875         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->la, &m, OPAL_FLOAT))) {
 876             OPAL_ERROR_LOG(ret);
 877             return ret;
 878         }
 879         m=1;
 880         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->la5, &m, OPAL_FLOAT))) {
 881             OPAL_ERROR_LOG(ret);
 882             return ret;
 883         }
 884         m=1;
 885         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->la15, &m, OPAL_FLOAT))) {
 886             OPAL_ERROR_LOG(ret);
 887             return ret;
 888         }
 889         m=1;
 890         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->total_mem, &m, OPAL_FLOAT))) {
 891             OPAL_ERROR_LOG(ret);
 892             return ret;
 893         }
 894         m=1;
 895         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->free_mem, &m, OPAL_FLOAT))) {
 896             OPAL_ERROR_LOG(ret);
 897             return ret;
 898         }
 899         m=1;
 900         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->buffers, &m, OPAL_FLOAT))) {
 901             OPAL_ERROR_LOG(ret);
 902             return ret;
 903         }
 904         m=1;
 905         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->cached, &m, OPAL_FLOAT))) {
 906             OPAL_ERROR_LOG(ret);
 907             return ret;
 908         }
 909         m=1;
 910         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->swap_cached, &m, OPAL_FLOAT))) {
 911             OPAL_ERROR_LOG(ret);
 912             return ret;
 913         }
 914         m=1;
 915         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->swap_total, &m, OPAL_FLOAT))) {
 916             OPAL_ERROR_LOG(ret);
 917             return ret;
 918         }
 919         m=1;
 920         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->swap_free, &m, OPAL_FLOAT))) {
 921             OPAL_ERROR_LOG(ret);
 922             return ret;
 923         }
 924         m=1;
 925         if (OPAL_SUCCESS != (ret = opal_dss_unpack_float(buffer, &ptr[i]->mapped, &m, OPAL_FLOAT))) {
 926             OPAL_ERROR_LOG(ret);
 927             return ret;
 928         }
 929         m=1;
 930         if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->sample_time, &m, OPAL_TIMEVAL))) {
 931             OPAL_ERROR_LOG(ret);
 932             return ret;
 933         }
 934         /* unpack the disk stat objects */
 935         if (OPAL_SUCCESS != (ret = unpack_disk_stats(buffer, ptr[i]))) {
 936             OPAL_ERROR_LOG(ret);
 937             return ret;
 938         }
 939         /* unpack the net stat objects */
 940         if (OPAL_SUCCESS != (ret = unpack_net_stats(buffer, ptr[i]))) {
 941             OPAL_ERROR_LOG(ret);
 942             return ret;
 943         }
 944         OBJ_RELEASE(ptr[i]);
 945     }
 946 
 947     return OPAL_SUCCESS;
 948 }
 949 
 950 /*
 951  * OPAL_VALUE
 952  */
 953 int opal_dss_unpack_value(opal_buffer_t *buffer, void *dest,
 954                           int32_t *num_vals, opal_data_type_t type)
 955 {
 956     opal_value_t **ptr;
 957     int32_t i, n, m;
 958     int ret;
 959 
 960     ptr = (opal_value_t **) dest;
 961     n = *num_vals;
 962 
 963     for (i = 0; i < n; ++i) {
 964         /* allocate the new object */
 965         ptr[i] = OBJ_NEW(opal_value_t);
 966         if (NULL == ptr[i]) {
 967             return OPAL_ERR_OUT_OF_RESOURCE;
 968         }
 969         /* unpack the key and type */
 970         m=1;
 971         if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &ptr[i]->key, &m, OPAL_STRING))) {
 972             return ret;
 973         }
 974         m=1;
 975         if (OPAL_SUCCESS != (ret = opal_dss_unpack_data_type(buffer, &ptr[i]->type, &m, OPAL_DATA_TYPE))) {
 976             return ret;
 977         }
 978         /* now unpack the right field */
 979         m=1;
 980         switch (ptr[i]->type) {
 981         case OPAL_BOOL:
 982             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.flag, &m, OPAL_BOOL))) {
 983                 return ret;
 984             }
 985             break;
 986         case OPAL_BYTE:
 987             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.byte, &m, OPAL_BYTE))) {
 988                 return ret;
 989             }
 990             break;
 991         case OPAL_STRING:
 992             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.string, &m, OPAL_STRING))) {
 993                 return ret;
 994             }
 995             break;
 996         case OPAL_SIZE:
 997             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.size, &m, OPAL_SIZE))) {
 998                 return ret;
 999             }
1000             break;
1001         case OPAL_PID:
1002             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.pid, &m, OPAL_PID))) {
1003                 return ret;
1004             }
1005             break;
1006         case OPAL_INT:
1007             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.integer, &m, OPAL_INT))) {
1008                 return ret;
1009             }
1010             break;
1011         case OPAL_INT8:
1012             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int8, &m, OPAL_INT8))) {
1013                 return ret;
1014             }
1015             break;
1016         case OPAL_INT16:
1017             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int16, &m, OPAL_INT16))) {
1018                 return ret;
1019             }
1020             break;
1021         case OPAL_INT32:
1022             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int32, &m, OPAL_INT32))) {
1023                 return ret;
1024             }
1025             break;
1026         case OPAL_INT64:
1027             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.int64, &m, OPAL_INT64))) {
1028                 return ret;
1029             }
1030             break;
1031         case OPAL_UINT:
1032             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint, &m, OPAL_UINT))) {
1033                 return ret;
1034             }
1035             break;
1036         case OPAL_UINT8:
1037             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint8, &m, OPAL_UINT8))) {
1038                 return ret;
1039             }
1040             break;
1041         case OPAL_UINT16:
1042             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint16, &m, OPAL_UINT16))) {
1043                 return ret;
1044             }
1045             break;
1046         case OPAL_UINT32:
1047             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint32, &m, OPAL_UINT32))) {
1048                 return ret;
1049             }
1050             break;
1051         case OPAL_UINT64:
1052             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.uint64, &m, OPAL_UINT64))) {
1053                 return ret;
1054             }
1055             break;
1056         case OPAL_BYTE_OBJECT:
1057             /* cannot use byte object unpack as it allocates memory, so unpack object size in bytes */
1058             if (OPAL_SUCCESS != (ret = opal_dss_unpack_int32(buffer, &(ptr[i]->data.bo.size), &m, OPAL_INT32))) {
1059                 return ret;
1060             }
1061             if (0 < ptr[i]->data.bo.size) {
1062                 ptr[i]->data.bo.bytes = (uint8_t*)malloc(ptr[i]->data.bo.size);
1063                 if (NULL == ptr[i]->data.bo.bytes) {
1064                     return OPAL_ERR_OUT_OF_RESOURCE;
1065                 }
1066                 if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, ptr[i]->data.bo.bytes,
1067                                                                 &(ptr[i]->data.bo.size), OPAL_BYTE))) {
1068                     return ret;
1069                 }
1070             } else {
1071                 ptr[i]->data.bo.bytes = NULL;
1072             }
1073             break;
1074         case OPAL_FLOAT:
1075             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.fval, &m, OPAL_FLOAT))) {
1076                 return ret;
1077             }
1078             break;
1079         case OPAL_DOUBLE:
1080             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.dval, &m, OPAL_DOUBLE))) {
1081                 return ret;
1082             }
1083             break;
1084         case OPAL_TIMEVAL:
1085             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.tv, &m, OPAL_TIMEVAL))) {
1086                 return ret;
1087             }
1088             break;
1089         case OPAL_PTR:
1090             /* just ignore these values */
1091             break;
1092         case OPAL_NAME:
1093             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.name, &m, OPAL_NAME))) {
1094                 return ret;
1095             }
1096             break;
1097         case OPAL_STATUS:
1098             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.status, &m, OPAL_INT))) {
1099                 return ret;
1100             }
1101             break;
1102         case OPAL_ENVAR:
1103             if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, &ptr[i]->data.envar, &m, OPAL_ENVAR))) {
1104                 return ret;
1105             }
1106             break;
1107         default:
1108             opal_output(0, "UNPACK-OPAL-VALUE: UNSUPPORTED TYPE %d FOR KEY %s", (int)ptr[i]->type, ptr[i]->key);
1109             return OPAL_ERROR;
1110         }
1111     }
1112 
1113     return OPAL_SUCCESS;
1114 }
1115 
1116 /*
1117  * OPAL_BUFFER
1118  */
1119 int opal_dss_unpack_buffer_contents(opal_buffer_t *buffer, void *dest,
1120                                     int32_t *num_vals, opal_data_type_t type)
1121 {
1122     opal_buffer_t **ptr;
1123     int32_t i, n, m;
1124     int ret;
1125     size_t nbytes;
1126 
1127     ptr = (opal_buffer_t **) dest;
1128     n = *num_vals;
1129 
1130     for (i = 0; i < n; ++i) {
1131         /* allocate the new object */
1132         ptr[i] = OBJ_NEW(opal_buffer_t);
1133         if (NULL == ptr[i]) {
1134             return OPAL_ERR_OUT_OF_RESOURCE;
1135         }
1136         /* unpack the number of bytes */
1137         m=1;
1138         if (OPAL_SUCCESS != (ret = opal_dss_unpack_sizet(buffer, &nbytes, &m, OPAL_SIZE))) {
1139             return ret;
1140         }
1141         m = nbytes;
1142         /* setup the buffer's data region */
1143         if (0 < nbytes) {
1144             ptr[i]->base_ptr = (char*)malloc(nbytes);
1145             /* unpack the bytes */
1146             if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, ptr[i]->base_ptr, &m, OPAL_BYTE))) {
1147                 return ret;
1148             }
1149         }
1150         ptr[i]->pack_ptr = ptr[i]->base_ptr + m;
1151         ptr[i]->unpack_ptr = ptr[i]->base_ptr;
1152         ptr[i]->bytes_allocated = nbytes;
1153         ptr[i]->bytes_used = m;
1154     }
1155     return OPAL_SUCCESS;
1156 }
1157 
1158 /*
1159  * NAME
1160  */
1161 int opal_dss_unpack_name(opal_buffer_t *buffer, void *dest,
1162                         int32_t *num_vals, opal_data_type_t type)
1163 {
1164     int rc;
1165     int32_t i, num;
1166     opal_process_name_t* proc;
1167     opal_jobid_t *jobid;
1168     opal_vpid_t *vpid;
1169 
1170     num = *num_vals;
1171 
1172     /* allocate space for all the jobids in a contiguous array */
1173     jobid = (opal_jobid_t*)malloc(num * sizeof(opal_jobid_t));
1174     if (NULL == jobid) {
1175         OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
1176         *num_vals = 0;
1177         return OPAL_ERR_OUT_OF_RESOURCE;
1178     }
1179     /* now unpack them in one shot */
1180     if (OPAL_SUCCESS != (rc =
1181                          opal_dss_unpack_jobid(buffer, jobid, num_vals, OPAL_JOBID))) {
1182         OPAL_ERROR_LOG(rc);
1183         *num_vals = 0;
1184         free(jobid);
1185         return rc;
1186     }
1187 
1188     /* collect all the vpids in a contiguous array */
1189     vpid = (opal_vpid_t*)malloc(num * sizeof(opal_vpid_t));
1190     if (NULL == vpid) {
1191         OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
1192         *num_vals = 0;
1193         free(jobid);
1194         return OPAL_ERR_OUT_OF_RESOURCE;
1195     }
1196     /* now unpack them in one shot */
1197     if (OPAL_SUCCESS != (rc =
1198                          opal_dss_unpack_vpid(buffer, vpid, num_vals, OPAL_VPID))) {
1199         OPAL_ERROR_LOG(rc);
1200         *num_vals = 0;
1201         free(vpid);
1202         free(jobid);
1203         return rc;
1204     }
1205 
1206     /* build the names from the jobid/vpid arrays */
1207     proc = (opal_process_name_t*)dest;
1208     for (i=0; i < num; i++) {
1209         proc->jobid = jobid[i];
1210         proc->vpid = vpid[i];
1211         proc++;
1212     }
1213 
1214     /* cleanup */
1215     free(vpid);
1216     free(jobid);
1217 
1218     return OPAL_SUCCESS;
1219 }
1220 
1221 /*
1222  * JOBID
1223  */
1224 int opal_dss_unpack_jobid(opal_buffer_t *buffer, void *dest,
1225                          int32_t *num_vals, opal_data_type_t type)
1226 {
1227     int ret;
1228 
1229     /* Turn around and unpack the real type */
1230     if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, OPAL_JOBID_T))) {
1231         OPAL_ERROR_LOG(ret);
1232     }
1233 
1234     return ret;
1235 }
1236 
1237 /*
1238  * VPID
1239  */
1240 int opal_dss_unpack_vpid(opal_buffer_t *buffer, void *dest,
1241                         int32_t *num_vals, opal_data_type_t type)
1242 {
1243     int ret;
1244 
1245     /* Turn around and unpack the real type */
1246     if (OPAL_SUCCESS != (ret = opal_dss_unpack_buffer(buffer, dest, num_vals, OPAL_VPID_T))) {
1247         OPAL_ERROR_LOG(ret);
1248     }
1249 
1250     return ret;
1251 }
1252 
1253 /*
1254  * STATUS
1255  */
1256 int opal_dss_unpack_status(opal_buffer_t *buffer, void *dest,
1257                            int32_t *num_vals, opal_data_type_t type)
1258 {
1259     int ret;
1260 
1261     /* Turn around and unpack the real type */
1262     ret = opal_dss_unpack_buffer(buffer, dest, num_vals, OPAL_INT);
1263     if (OPAL_SUCCESS != ret) {
1264         OPAL_ERROR_LOG(ret);
1265     }
1266 
1267     return ret;
1268 }
1269 
1270 
1271 int opal_dss_unpack_envar(opal_buffer_t *buffer, void *dest,
1272                           int32_t *num_vals, opal_data_type_t type)
1273 {
1274     opal_envar_t *ptr;
1275     int32_t i, n, m;
1276     int ret;
1277 
1278     ptr = (opal_envar_t *) dest;
1279     n = *num_vals;
1280 
1281     for (i = 0; i < n; ++i) {
1282         m=1;
1283         if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &ptr[i].envar, &m, OPAL_STRING))) {
1284             OPAL_ERROR_LOG(ret);
1285             return ret;
1286         }
1287         m=1;
1288         if (OPAL_SUCCESS != (ret = opal_dss_unpack_string(buffer, &ptr[i].value, &m, OPAL_STRING))) {
1289             OPAL_ERROR_LOG(ret);
1290             return ret;
1291         }
1292         m=1;
1293         if (OPAL_SUCCESS != (ret = opal_dss_unpack_byte(buffer, &ptr[i].separator, &m, OPAL_BYTE))) {
1294             OPAL_ERROR_LOG(ret);
1295             return ret;
1296         }
1297     }
1298 
1299     return OPAL_SUCCESS;
1300 }

/* [<][>][^][v][top][bottom][index][help] */