root/opal/mca/pmix/pmix4x/pmix/src/mca/gds/ds12/gds_ds12_file.c

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

DEFINITIONS

This source file includes following definitions.
  1. pmix_ds12_kv_size
  2. pmix_ds12_key_name_ptr
  3. pmix_ds12_key_name_len
  4. pmix_ds12_data_ptr
  5. pmix_ds12_data_size
  6. pmix_ds12_key_size
  7. pmix_ds12_ext_slot_size
  8. pmix_ds12_put_key
  9. pmix_ds12_is_invalid
  10. pmix_ds12_set_invalid
  11. pmix_ds12_is_ext_slot
  12. pmix_ds12_kname_match

   1 /*
   2  * Copyright (c) 2018      Mellanox Technologies, Inc.
   3  *                         All rights reserved.
   4  *
   5  * $COPYRIGHT$
   6  *
   7  * Additional copyrights may follow
   8  *
   9  * $HEADER$
  10  */
  11 
  12 #include <pmix_common.h>
  13 
  14 #include "src/include/pmix_globals.h"
  15 #include "src/mca/gds/base/base.h"
  16 
  17 #include "src/mca/common/dstore/dstore_file.h"
  18 #include "gds_ds12_file.h"
  19 
  20 #define ESH_KEY_SIZE_V12(key, size)                         \
  21 __pmix_attribute_extension__ ({                             \
  22     size_t len = strlen((char*)key) + 1 + sizeof(size_t) + size;   \
  23     len;                                                    \
  24 })
  25 
  26 /* in ext slot new offset will be stored in case if
  27  * new data were added for the same process during
  28  * next commit
  29  */
  30 #define EXT_SLOT_SIZE_V12()                                 \
  31     (ESH_KEY_SIZE_V12(ESH_REGION_EXTENSION, sizeof(size_t)))
  32 
  33 #define ESH_KV_SIZE_V12(addr)                               \
  34 __pmix_attribute_extension__ ({                             \
  35     size_t sz;                                              \
  36     memcpy(&sz, addr +                                      \
  37         ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr)),         \
  38         sizeof(size_t));                                    \
  39     sz += ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr)) +      \
  40         sizeof(size_t);                                     \
  41     sz;                                                     \
  42 })
  43 
  44 #define ESH_KNAME_PTR_V12(addr)                             \
  45 __pmix_attribute_extension__ ({                             \
  46     char *name_ptr = (char*)addr;                           \
  47     name_ptr;                                               \
  48 })
  49 
  50 #define ESH_KNAME_LEN_V12(key)                              \
  51 __pmix_attribute_extension__ ({                             \
  52     size_t len = strlen((char*)key) + 1;                    \
  53     len;                                                    \
  54 })
  55 
  56 #define ESH_DATA_PTR_V12(addr)                              \
  57 __pmix_attribute_extension__ ({                             \
  58     uint8_t *data_ptr =                                     \
  59         addr +                                              \
  60         sizeof(size_t) +                                    \
  61         ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr));         \
  62     data_ptr;                                               \
  63 })
  64 
  65 #define ESH_DATA_SIZE_V12(addr)                             \
  66 __pmix_attribute_extension__ ({                             \
  67     size_t data_size;                                       \
  68     memcpy(&data_size,                                      \
  69         addr + ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr)),  \
  70         sizeof(size_t));                                    \
  71     data_size;                                              \
  72 })
  73 
  74 #define ESH_PUT_KEY_V12(addr, key, buffer, size)            \
  75 __pmix_attribute_extension__ ({                             \
  76     size_t sz = size;                                       \
  77     memset(addr, 0, ESH_KNAME_LEN_V12(key));                \
  78     strncpy((char *)addr, key, ESH_KNAME_LEN_V12(key));     \
  79     memcpy(addr + ESH_KNAME_LEN_V12(key), &sz,              \
  80         sizeof(size_t));                                    \
  81     memcpy(addr + ESH_KNAME_LEN_V12(key) + sizeof(size_t),  \
  82             buffer, size);                                  \
  83 })
  84 
  85 static size_t pmix_ds12_kv_size(uint8_t *addr)
  86 {
  87     size_t size;
  88 
  89     memcpy(&size, addr + ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr)),
  90            sizeof(size_t));
  91     size += ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr)) + sizeof(size_t);
  92     return size;
  93 }
  94 
  95 static char* pmix_ds12_key_name_ptr(uint8_t *addr)
  96 {
  97     return ESH_KNAME_PTR_V12(addr);
  98 }
  99 
 100 static size_t pmix_ds12_key_name_len(char *key)
 101 {
 102     return ESH_KNAME_LEN_V12(key);
 103 }
 104 
 105 static uint8_t* pmix_ds12_data_ptr(uint8_t *addr)
 106 {
 107     return ESH_DATA_PTR_V12(addr);
 108 }
 109 
 110 static size_t pmix_ds12_data_size(uint8_t *addr, uint8_t* data_ptr)
 111 {
 112     return ESH_DATA_SIZE_V12(addr);
 113 }
 114 
 115 static size_t pmix_ds12_key_size(char *addr, size_t data_size)
 116 {
 117     return ESH_KEY_SIZE_V12(addr, data_size);
 118 }
 119 
 120 static size_t pmix_ds12_ext_slot_size(void)
 121 {
 122     return EXT_SLOT_SIZE_V12();
 123 }
 124 
 125 static int pmix_ds12_put_key(uint8_t *addr, char *key, void *buf, size_t size)
 126 {
 127     ESH_PUT_KEY_V12(addr, key, buf, size);
 128     return PMIX_SUCCESS;
 129 }
 130 
 131 static bool pmix_ds12_is_invalid(uint8_t *addr)
 132 {
 133     bool ret = (0 == strncmp(ESH_REGION_INVALIDATED, ESH_KNAME_PTR_V12(addr),
 134                             ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr))));
 135     return ret;
 136 }
 137 
 138 static void pmix_ds12_set_invalid(uint8_t *addr)
 139 {
 140     strncpy(ESH_KNAME_PTR_V12(addr), ESH_REGION_INVALIDATED,
 141             ESH_KNAME_LEN_V12(ESH_REGION_INVALIDATED));
 142 }
 143 
 144 static bool pmix_ds12_is_ext_slot(uint8_t *addr)
 145 {
 146     bool ret;
 147     ret = (0 == strncmp(ESH_REGION_EXTENSION, ESH_KNAME_PTR_V12(addr),
 148                         ESH_KNAME_LEN_V12(ESH_KNAME_PTR_V12(addr))));
 149     return ret;
 150 }
 151 
 152 static bool pmix_ds12_kname_match(uint8_t *addr, const char *key, size_t key_hash)
 153 {
 154     bool ret = 0;
 155 
 156     ret =  (0 == strncmp(ESH_KNAME_PTR_V12(addr),
 157                          key, ESH_KNAME_LEN_V12(key)));
 158     return ret;
 159 }
 160 
 161 pmix_common_dstore_file_cbs_t pmix_ds12_file_module = {
 162     .name = "ds12",
 163     .kval_size = pmix_ds12_kv_size,
 164     .kname_ptr = pmix_ds12_key_name_ptr,
 165     .kname_len = pmix_ds12_key_name_len,
 166     .data_ptr = pmix_ds12_data_ptr,
 167     .data_size = pmix_ds12_data_size,
 168     .key_size = pmix_ds12_key_size,
 169     .ext_slot_size = pmix_ds12_ext_slot_size,
 170     .put_key = pmix_ds12_put_key,
 171     .is_invalid = pmix_ds12_is_invalid,
 172     .is_extslot = pmix_ds12_is_ext_slot,
 173     .set_invalid = pmix_ds12_set_invalid,
 174     .key_hash = NULL,
 175     .key_match = pmix_ds12_kname_match
 176 };

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