root/opal/mca/pmix/pmix4x/pmix/src/common/pmix_data.c

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

DEFINITIONS

This source file includes following definitions.
  1. find_peer
  2. PMIx_Data_pack
  3. PMIx_Data_unpack
  4. PMIx_Data_copy
  5. PMIx_Data_print
  6. PMIx_Data_copy_payload

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2007-2012 Los Alamos National Security, LLC.
  13  *                         All rights reserved.
  14  * Copyright (c) 2014-2018 Intel, Inc.  All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include <src/include/pmix_config.h>
  23 
  24 
  25 #ifdef HAVE_STRING_H
  26 #include <string.h>
  27 #endif
  28 #include <errno.h>
  29 #include <stdio.h>
  30 #ifdef HAVE_STDLIB_H
  31 #include <stdlib.h>
  32 #endif
  33 
  34 #include <pmix.h>
  35 #include <pmix_rename.h>
  36 
  37 #include "src/mca/bfrops/bfrops.h"
  38 #include "src/include/pmix_globals.h"
  39 #include "src/server/pmix_server_ops.h"
  40 #include "src/client/pmix_client_ops.h"
  41 
  42 #define PMIX_EMBED_DATA_BUFFER(b, db)                       \
  43     do {                                                    \
  44         (b)->type = pmix_globals.mypeer->nptr->compat.type; \
  45         (b)->base_ptr = (db)->base_ptr;                     \
  46         (b)->pack_ptr = (db)->pack_ptr;                     \
  47         (b)->unpack_ptr = (db)->unpack_ptr;                 \
  48         (b)->bytes_allocated = (db)->bytes_allocated;       \
  49         (b)->bytes_used = (db)->bytes_used;                 \
  50         (db)->base_ptr = NULL;                              \
  51         (db)->pack_ptr = NULL;                              \
  52         (db)->unpack_ptr = NULL;                            \
  53         (db)->bytes_allocated = 0;                          \
  54         (db)->bytes_used = 0;                               \
  55     } while (0)
  56 
  57 #define PMIX_EXTRACT_DATA_BUFFER(b, db)                 \
  58     do {                                                \
  59         (db)->base_ptr = (b)->base_ptr;                 \
  60         (db)->pack_ptr = (b)->pack_ptr;                 \
  61         (db)->unpack_ptr = (b)->unpack_ptr;             \
  62         (db)->bytes_allocated = (b)->bytes_allocated;   \
  63         (db)->bytes_used = (b)->bytes_used;             \
  64         (b)->base_ptr = NULL;                           \
  65         (b)->pack_ptr = NULL;                           \
  66         (b)->unpack_ptr = NULL;                         \
  67         (b)->bytes_allocated = 0;                       \
  68         (b)->bytes_used = 0;                            \
  69     } while (0)
  70 
  71 static pmix_peer_t* find_peer(const pmix_proc_t *proc)
  72 {
  73     pmix_status_t rc;
  74     pmix_peer_t *peer;
  75     pmix_proc_t wildcard;
  76     pmix_value_t *value;
  77     int i;
  78 
  79     if (NULL == proc ) {
  80         return pmix_globals.mypeer;
  81     }
  82 
  83     /* if the target is someone in my nspace, then use my own peer */
  84     if (0 == strncmp(proc->nspace, pmix_globals.myid.nspace, PMIX_MAX_NSLEN)) {
  85         return pmix_globals.mypeer;
  86     }
  87 
  88     if (PMIX_PROC_IS_SERVER(pmix_globals.mypeer)) {
  89         /* see if we know this proc */
  90         for (i=0; i < pmix_server_globals.clients.size; i++) {
  91             if (NULL != (peer = (pmix_peer_t*)pmix_pointer_array_get_item(&pmix_server_globals.clients, i))) {
  92                 continue;
  93             }
  94             if (0 == strncmp(proc->nspace, peer->nptr->nspace, PMIX_MAX_NSLEN)) {
  95                 return peer;
  96             }
  97         }
  98         /* didn't find it, so try to get the library version of the target
  99          * from the host - the result will be cached, so we will only have
 100          * to retrieve it once */
 101         pmix_strncpy(wildcard.nspace, proc->nspace, PMIX_MAX_NSLEN);
 102         wildcard.rank = PMIX_RANK_WILDCARD;
 103         if (PMIX_SUCCESS != (rc = PMIx_Get(&wildcard, PMIX_BFROPS_MODULE, NULL, 0, &value))) {
 104             /* couldn't get it - nothing we can do */
 105             return NULL;
 106         }
 107         /* setup a peer for this nspace */
 108         peer = PMIX_NEW(pmix_peer_t);
 109         if (NULL == peer) {
 110             PMIX_RELEASE(value);
 111             return NULL;
 112         }
 113         peer->nptr = PMIX_NEW(pmix_namespace_t);
 114         if (NULL == peer->nptr) {
 115             PMIX_RELEASE(peer);
 116             PMIX_RELEASE(value);
 117             return NULL;
 118         }
 119         peer->nptr->nspace = strdup(proc->nspace);
 120         /* assign a module to it based on the returned version */
 121         peer->nptr->compat.bfrops = pmix_bfrops_base_assign_module(value->data.string);
 122         PMIX_RELEASE(value);
 123         if (NULL == peer->nptr->compat.bfrops) {
 124             PMIX_RELEASE(peer);
 125             return NULL;
 126         }
 127         /* cache the peer object */
 128         pmix_pointer_array_add(&pmix_server_globals.clients, peer);
 129         return peer;
 130     }
 131 
 132     // we are a client or tool
 133 
 134     /* If the target is for the server, then
 135      * pack it using that peer. */
 136     if (0 == strncmp(proc->nspace, pmix_client_globals.myserver->info->pname.nspace, PMIX_MAX_NSLEN)) {
 137         return pmix_client_globals.myserver;
 138     }
 139 
 140     /* try to get the library version of this peer - the result will be
 141      * cached, so we will only have to retrieve it once */
 142     pmix_strncpy(wildcard.nspace, proc->nspace, PMIX_MAX_NSLEN);
 143     wildcard.rank = PMIX_RANK_WILDCARD;
 144     if (PMIX_SUCCESS != (rc = PMIx_Get(&wildcard, PMIX_BFROPS_MODULE, NULL, 0, &value))) {
 145         /* couldn't get it - nothing we can do */
 146         return NULL;
 147     }
 148     /* setup a peer for this nspace */
 149     peer = PMIX_NEW(pmix_peer_t);
 150     if (NULL == peer) {
 151         PMIX_RELEASE(value);
 152         return NULL;
 153     }
 154     peer->nptr = PMIX_NEW(pmix_namespace_t);
 155     if (NULL == peer->nptr) {
 156         PMIX_RELEASE(peer);
 157         PMIX_RELEASE(value);
 158         return NULL;
 159     }
 160     peer->nptr->nspace = strdup(proc->nspace);
 161     /* assign a module to it based on the returned version */
 162     peer->nptr->compat.bfrops = pmix_bfrops_base_assign_module(value->data.string);
 163     PMIX_RELEASE(value);
 164     if (NULL == peer->nptr->compat.bfrops) {
 165         PMIX_RELEASE(peer);
 166         return NULL;
 167     }
 168     /* need to cache the peer someplace so we can clean it
 169      * up later */
 170     return peer;
 171 }
 172 
 173 PMIX_EXPORT pmix_status_t PMIx_Data_pack(const pmix_proc_t *target,
 174                                          pmix_data_buffer_t *buffer,
 175                                          void *src, int32_t num_vals,
 176                                          pmix_data_type_t type)
 177 {
 178     pmix_status_t rc;
 179     pmix_buffer_t buf;
 180     pmix_peer_t *peer;
 181 
 182     if (NULL == (peer = find_peer(target))) {
 183         return PMIX_ERR_NOT_SUPPORTED;
 184     }
 185 
 186     /* setup the host */
 187     PMIX_CONSTRUCT(&buf, pmix_buffer_t);
 188 
 189     /* embed the data buffer into a buffer */
 190     PMIX_EMBED_DATA_BUFFER(&buf, buffer);
 191 
 192     /* pack the value */
 193     PMIX_BFROPS_PACK(rc, peer,
 194                      &buf, src, num_vals, type);
 195 
 196     /* extract the data buffer - the pointers may have changed */
 197     PMIX_EXTRACT_DATA_BUFFER(&buf, buffer);
 198 
 199     /* no need to cleanup as all storage was xfered */
 200     return rc;
 201 }
 202 
 203 
 204 PMIX_EXPORT pmix_status_t PMIx_Data_unpack(const pmix_proc_t *source,
 205                                            pmix_data_buffer_t *buffer, void *dest,
 206                                            int32_t *max_num_values,
 207                                            pmix_data_type_t type)
 208 {
 209     pmix_status_t rc;
 210     pmix_buffer_t buf;
 211     pmix_peer_t *peer;
 212 
 213     if (NULL == (peer = find_peer(source))) {
 214         return PMIX_ERR_NOT_SUPPORTED;
 215     }
 216 
 217     /* setup the host */
 218     PMIX_CONSTRUCT(&buf, pmix_buffer_t);
 219 
 220     /* embed the data buffer into a buffer */
 221     PMIX_EMBED_DATA_BUFFER(&buf, buffer);
 222 
 223     /* unpack the value */
 224     PMIX_BFROPS_UNPACK(rc, peer,
 225                        &buf, dest, max_num_values, type);
 226 
 227     /* extract the data buffer - the pointers may have changed */
 228     PMIX_EXTRACT_DATA_BUFFER(&buf, buffer);
 229 
 230     /* no need to cleanup as all storage was xfered */
 231     return rc;
 232 }
 233 
 234 PMIX_EXPORT pmix_status_t PMIx_Data_copy(void **dest, void *src,
 235                                          pmix_data_type_t type)
 236 {
 237     pmix_status_t rc;
 238 
 239     /* copy the value */
 240     PMIX_BFROPS_COPY(rc, pmix_globals.mypeer,
 241                      dest, src, type);
 242 
 243     return rc;
 244 }
 245 
 246 PMIX_EXPORT pmix_status_t PMIx_Data_print(char **output, char *prefix,
 247                                           void *src, pmix_data_type_t type)
 248 {
 249     pmix_status_t rc;
 250 
 251     /* print the value */
 252     PMIX_BFROPS_PRINT(rc, pmix_globals.mypeer,
 253                       output, prefix, src, type);
 254 
 255     return rc;
 256 }
 257 
 258 PMIX_EXPORT pmix_status_t PMIx_Data_copy_payload(pmix_data_buffer_t *dest,
 259                                                  pmix_data_buffer_t *src)
 260 {
 261     pmix_status_t rc;
 262     pmix_buffer_t buf1, buf2;
 263 
 264     /* setup the hosts */
 265     PMIX_CONSTRUCT(&buf1, pmix_buffer_t);
 266     PMIX_CONSTRUCT(&buf2, pmix_buffer_t);
 267 
 268     /* embed the data buffer into a buffer */
 269     PMIX_EMBED_DATA_BUFFER(&buf1, dest);
 270     PMIX_EMBED_DATA_BUFFER(&buf2, src);
 271 
 272     /* copy payload */
 273     PMIX_BFROPS_COPY_PAYLOAD(rc, pmix_globals.mypeer,
 274                              &buf1, &buf2);
 275 
 276     /* extract the dest data buffer - the pointers may have changed */
 277     PMIX_EXTRACT_DATA_BUFFER(&buf1, dest);
 278     PMIX_EXTRACT_DATA_BUFFER(&buf2, src);
 279 
 280     /* no need to cleanup as all storage was xfered */
 281     return rc;
 282 }

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