root/opal/mca/pmix/pmix4x/pmix/src/mca/ptl/ptl_types.h

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

INCLUDED FROM


   1 /* -*- C -*-
   2  *
   3  * Copyright (c) 2004-2005 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) 2007-2011 Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
  15  * Copyright (c) 2014-2018 Intel, Inc. All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 /**
  23  * @file
  24  *
  25  * Buffer management types.
  26  */
  27 
  28 #ifndef PMIX_PTL_TYPES_H_
  29 #define PMIX_PTL_TYPES_H_
  30 
  31 #include <src/include/pmix_config.h>
  32 #include "src/include/types.h"
  33 
  34 #ifdef HAVE_UNISTD_H
  35 #include <unistd.h>
  36 #endif
  37 #ifdef HAVE_SYS_SOCKET_H
  38 #include <sys/socket.h>
  39 #endif
  40 #ifdef HAVE_SYS_UN_H
  41 #include <sys/un.h>
  42 #endif
  43 #ifdef HAVE_SYS_UIO_H
  44 #include <sys/uio.h>
  45 #endif
  46 #ifdef HAVE_NET_UIO_H
  47 #include <net/uio.h>
  48 #endif
  49 #ifdef HAVE_SYS_TYPES_H
  50 #include <sys/types.h>
  51 #endif
  52 #include PMIX_EVENT_HEADER
  53 
  54 #include "src/class/pmix_list.h"
  55 #include "src/util/output.h"
  56 #include "src/mca/bfrops/bfrops_types.h"
  57 
  58 BEGIN_C_DECLS
  59 
  60 // forward declaration
  61 struct pmix_peer_t;
  62 struct pmix_ptl_module_t;
  63 
  64 /* define a process type */
  65 typedef uint16_t pmix_proc_type_t;
  66 
  67 #define PMIX_PROC_UNDEF             0x0000
  68 #define PMIX_PROC_CLIENT            0x0001      // simple client process
  69 #define PMIX_PROC_SERVER            0x0002      // simple server process
  70 #define PMIX_PROC_TOOL              0x0004      // simple tool
  71 #define PMIX_PROC_V1                0x0008      // process is using PMIx v1 protocols
  72 #define PMIX_PROC_V20               0x0010      // process is using PMIx v2.0 protocols
  73 #define PMIX_PROC_V21               0x0020      // process is using PMIx v2.1 protocols
  74 #define PMIX_PROC_V3                0x0040      // process is using PMIx v3 protocols
  75 #define PMIX_PROC_LAUNCHER_ACT      0x1000      // process acting as launcher
  76 #define PMIX_PROC_LAUNCHER          (PMIX_PROC_TOOL | PMIX_PROC_SERVER | PMIX_PROC_LAUNCHER_ACT)
  77 #define PMIX_PROC_CLIENT_TOOL_ACT   0x2000
  78 #define PMIX_PROC_CLIENT_TOOL       (PMIX_PROC_TOOL | PMIX_PROC_CLIENT | PMIX_PROC_CLIENT_TOOL_ACT)
  79 #define PMIX_PROC_GATEWAY_ACT       0x4000
  80 #define PMIX_PROC_GATEWAY           (PMIX_PROC_SERVER | PMIX_PROC_GATEWAY_ACT)
  81 
  82 /* defins some convenience macros for testing proc type */
  83 #define PMIX_PROC_IS_CLIENT(p)      (PMIX_PROC_CLIENT & (p)->proc_type)
  84 #define PMIX_PROC_IS_SERVER(p)      (PMIX_PROC_SERVER & (p)->proc_type)
  85 #define PMIX_PROC_IS_TOOL(p)        (PMIX_PROC_TOOL & (p)->proc_type)
  86 #define PMIX_PROC_IS_V1(p)          (PMIX_PROC_V1 & (p)->proc_type)
  87 #define PMIX_PROC_IS_V20(p)         (PMIX_PROC_V20 & (p)->proc_type)
  88 #define PMIX_PROC_IS_V21(p)         (PMIX_PROC_V21 & (p)->proc_type)
  89 #define PMIX_PROC_IS_V3(p)          (PMIX_PROC_V3 & (p)->proc_type)
  90 #define PMIX_PROC_IS_LAUNCHER(p)    (PMIX_PROC_LAUNCHER_ACT & (p)->proc_type)
  91 #define PMIX_PROC_IS_CLIENT_TOOL(p) (PMIX_PROC_CLIENT_TOOL_ACT & (p)->proc_type)
  92 #define PMIX_PROC_IS_GATEWAY(p)     (PMIX_PROC_GATEWAY_ACT & (p)->proc_type)
  93 
  94 
  95 /****    MESSAGING STRUCTURES    ****/
  96 typedef uint32_t pmix_ptl_tag_t;
  97 /* define a range of "reserved" tags - these
  98  * are tags that are used for persistent recvs
  99  * within the system */
 100 #define PMIX_PTL_TAG_NOTIFY           0
 101 #define PMIX_PTL_TAG_HEARTBEAT        1
 102 #define PMIX_PTL_TAG_IOF              2
 103 
 104 /* define the start of dynamic tags that are
 105  * assigned for send/recv operations */
 106 #define PMIX_PTL_TAG_DYNAMIC        100
 107 
 108 
 109 /* header for messages */
 110 typedef struct {
 111     int32_t pindex;
 112     pmix_ptl_tag_t tag;
 113     size_t nbytes;
 114 } pmix_ptl_hdr_t;
 115 
 116 /* define the messaging cbfunc */
 117 typedef void (*pmix_ptl_cbfunc_t)(struct pmix_peer_t *peer,
 118                                   pmix_ptl_hdr_t *hdr,
 119                                   pmix_buffer_t *buf, void *cbdata);
 120 
 121 /* define a callback function for notifying that server connection
 122  * has completed */
 123 typedef void (*pmix_ptl_connect_cbfunc_t)(pmix_status_t status, void *cbdata);
 124 
 125 /* define a callback function for processing pending connections */
 126 typedef void (*pmix_ptl_pending_cbfunc_t)(int sd, short args, void *cbdata);
 127 
 128 
 129 /* structure for sending a message */
 130 typedef struct {
 131     pmix_list_item_t super;
 132     pmix_event_t ev;
 133     pmix_ptl_hdr_t hdr;
 134     pmix_buffer_t *data;
 135     bool hdr_sent;
 136     char *sdptr;
 137     size_t sdbytes;
 138 } pmix_ptl_send_t;
 139 PMIX_CLASS_DECLARATION(pmix_ptl_send_t);
 140 
 141 /* structure for recving a message */
 142 typedef struct {
 143     pmix_list_item_t super;
 144     pmix_event_t ev;
 145     struct pmix_peer_t *peer;
 146     int sd;
 147     pmix_ptl_hdr_t hdr;
 148     char *data;
 149     bool hdr_recvd;
 150     char *rdptr;
 151     size_t rdbytes;
 152 } pmix_ptl_recv_t;
 153 PMIX_CLASS_DECLARATION(pmix_ptl_recv_t);
 154 
 155 /* structure for tracking posted recvs */
 156 typedef struct {
 157     pmix_list_item_t super;
 158     pmix_event_t ev;
 159     uint32_t tag;
 160     pmix_ptl_cbfunc_t cbfunc;
 161     void *cbdata;
 162 } pmix_ptl_posted_recv_t;
 163 PMIX_CLASS_DECLARATION(pmix_ptl_posted_recv_t);
 164 
 165 /* struct for posting send/recv request */
 166 typedef struct {
 167     pmix_object_t super;
 168     volatile bool active;
 169     pmix_event_t ev;
 170     struct pmix_peer_t *peer;
 171     pmix_status_t status;
 172     pmix_buffer_t *bfr;
 173     pmix_ptl_cbfunc_t cbfunc;
 174     void *cbdata;
 175 } pmix_ptl_sr_t;
 176 PMIX_CLASS_DECLARATION(pmix_ptl_sr_t);
 177 
 178 typedef struct {
 179     pmix_object_t super;
 180     volatile bool active;
 181     pmix_event_t ev;
 182     struct pmix_peer_t *peer;
 183     pmix_buffer_t *buf;
 184     pmix_ptl_tag_t tag;
 185 } pmix_ptl_queue_t;
 186 PMIX_CLASS_DECLARATION(pmix_ptl_queue_t);
 187 
 188 /* define listener protocol types */
 189 typedef uint16_t pmix_listener_protocol_t;
 190 #define PMIX_PROTOCOL_UNDEF     0
 191 #define PMIX_PROTOCOL_V1        1       // legacy usock
 192 #define PMIX_PROTOCOL_V2        2       // tcp
 193 
 194 /* connection support */
 195 typedef struct {
 196     pmix_object_t super;
 197     pmix_event_t ev;
 198     pmix_listener_protocol_t protocol;
 199     int sd;
 200     bool need_id;
 201     uint8_t flag;
 202     char nspace[PMIX_MAX_NSLEN+1];
 203     pmix_info_t *info;
 204     size_t ninfo;
 205     pmix_status_t status;
 206     struct sockaddr_storage addr;
 207     struct pmix_peer_t *peer;
 208     char *bfrops;
 209     char *psec;
 210     char *gds;
 211     struct pmix_ptl_module_t *ptl;
 212     pmix_bfrop_buffer_type_t buffer_type;
 213     char *cred;
 214     size_t len;
 215     uid_t uid;
 216     gid_t gid;
 217     pmix_proc_type_t proc_type;
 218 } pmix_pending_connection_t;
 219 PMIX_CLASS_DECLARATION(pmix_pending_connection_t);
 220 
 221 /* listener objects */
 222 typedef struct pmix_listener_t {
 223     pmix_list_item_t super;
 224     pmix_listener_protocol_t protocol;
 225     struct pmix_ptl_module_t *ptl;
 226     int socket;
 227     char *varname;
 228     char *uri;
 229     uint32_t owner;
 230     bool owner_given;
 231     uint32_t group;
 232     bool group_given;
 233     uint32_t mode;
 234     pmix_ptl_pending_cbfunc_t cbfunc;
 235 } pmix_listener_t;
 236 PMIX_CLASS_DECLARATION(pmix_listener_t);
 237 
 238 /* provide a backdoor to the framework output for debugging */
 239 PMIX_EXPORT extern int pmix_ptl_base_output;
 240 
 241 #define PMIX_ACTIVATE_POST_MSG(ms)                                      \
 242     do {                                                                \
 243         pmix_event_assign(&((ms)->ev), pmix_globals.evbase, -1,         \
 244                           EV_WRITE, pmix_ptl_base_process_msg, (ms));   \
 245         PMIX_POST_OBJECT(ms);                                           \
 246         pmix_event_active(&((ms)->ev), EV_WRITE, 1);                    \
 247     } while (0)
 248 
 249 #define PMIX_SND_CADDY(c, h, s)                                         \
 250     do {                                                                \
 251         (c) = PMIX_NEW(pmix_server_caddy_t);                            \
 252         (void)memcpy(&(c)->hdr, &(h), sizeof(pmix_ptl_hdr_t));          \
 253         PMIX_RETAIN((s));                                               \
 254         (c)->snd = (s);                                                 \
 255     } while (0)
 256 
 257 /* queue a message to be sent to one of our procs - must
 258  * provide the following params:
 259  * p - pmix_peer_t of target recipient
 260  * t - tag to be sent to
 261  * b - buffer to be sent
 262  */
 263 #define PMIX_SERVER_QUEUE_REPLY(r, p, t, b)                                                 \
 264     do {                                                                                    \
 265         pmix_ptl_send_t *snd;                                                               \
 266         uint32_t nbytes;                                                                    \
 267         pmix_output_verbose(5, pmix_ptl_base_output,                                        \
 268                             "[%s:%d] queue callback called: reply to %s:%d on tag %d size %d",  \
 269                             __FILE__, __LINE__,                                             \
 270                             (p)->info->pname.nspace,                                        \
 271                             (p)->info->pname.rank, (t), (int)(b)->bytes_used);              \
 272         if ((p)->finalized) {                                                               \
 273             (r) = PMIX_ERR_UNREACH;                                                         \
 274         } else {                                                                            \
 275             snd = PMIX_NEW(pmix_ptl_send_t);                                                \
 276             snd->hdr.pindex = htonl(pmix_globals.pindex);                                   \
 277             snd->hdr.tag = htonl(t);                                                        \
 278             nbytes = (b)->bytes_used;                                                       \
 279             snd->hdr.nbytes = htonl(nbytes);                                                \
 280             snd->data = (b);                                                                \
 281             /* always start with the header */                                              \
 282             snd->sdptr = (char*)&snd->hdr;                                                  \
 283             snd->sdbytes = sizeof(pmix_ptl_hdr_t);                                          \
 284             /* if there is no message on-deck, put this one there */                        \
 285             if (NULL == (p)->send_msg) {                                                    \
 286                 (p)->send_msg = snd;                                                        \
 287             } else {                                                                        \
 288                 /* add it to the queue */                                                   \
 289                 pmix_list_append(&(p)->send_queue, &snd->super);                            \
 290             }                                                                               \
 291             /* ensure the send event is active */                                           \
 292             if (!(p)->send_ev_active && 0 <= (p)->sd) {                                     \
 293                 (p)->send_ev_active = true;                                                 \
 294                 PMIX_POST_OBJECT(snd);                                                      \
 295                 pmix_event_add(&(p)->send_event, 0);                                        \
 296             }                                                                               \
 297             (r) = PMIX_SUCCESS;                                                             \
 298         }                                                                                   \
 299     } while (0)
 300 
 301 #define CLOSE_THE_SOCKET(s)                     \
 302     do {                                        \
 303         if (0 <= (s)) {                         \
 304             shutdown((s), 2);                   \
 305             close((s));                         \
 306             (s) = -1;                           \
 307         }                                       \
 308     } while (0)
 309 
 310 
 311 END_C_DECLS
 312 
 313 #endif /* PMIX_PTL_TYPES_H */

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