1 #ifndef DSTORE_FORMAT_H
2 #define DSTORE_FORMAT_H
3
4 typedef size_t (*pmix_common_dstore_kv_size_fn)(uint8_t *addr);
5 typedef char* (*pmix_common_dstore_key_name_ptr_fn)(uint8_t *addr);
6 typedef size_t (*pmix_common_dstore_key_name_len_fn)(char *key);
7 typedef uint8_t* (*pmix_common_dstore_data_ptr_fn)(uint8_t *addr);
8 typedef size_t (*pmix_common_dstore_data_size_fn)(uint8_t *addr, uint8_t* data_ptr);
9 typedef size_t (*pmix_common_dstore_key_size_fn)(char *key, size_t data_size);
10 typedef size_t (*pmix_common_dstore_ext_slot_size_fn)(void);
11 typedef int (*pmix_common_dstore_put_key_fn)(uint8_t *addr, char *key, void *buf,
12 size_t size);
13 typedef bool (*pmix_common_dstore_is_invalid_fn)(uint8_t *addr);
14 typedef bool (*pmix_common_dstore_is_extslot_fn)(uint8_t *addr);
15 typedef void (*pmix_common_dstore_set_invalid_fn)(uint8_t *addr);
16 typedef size_t (*pmix_common_dstore_key_hash_fn)(const char *key);
17 typedef bool (*pmix_common_dstore_key_match_fn)(uint8_t *addr, const char *key,
18 size_t key_hash);
19
20 typedef struct {
21 const char *name;
22 pmix_common_dstore_kv_size_fn kval_size;
23 pmix_common_dstore_key_name_ptr_fn kname_ptr;
24 pmix_common_dstore_key_name_len_fn kname_len;
25 pmix_common_dstore_data_ptr_fn data_ptr;
26 pmix_common_dstore_data_size_fn data_size;
27 pmix_common_dstore_key_size_fn key_size;
28 pmix_common_dstore_ext_slot_size_fn ext_slot_size;
29 pmix_common_dstore_put_key_fn put_key;
30 pmix_common_dstore_is_invalid_fn is_invalid;
31 pmix_common_dstore_is_extslot_fn is_extslot;
32 pmix_common_dstore_set_invalid_fn set_invalid;
33 pmix_common_dstore_key_hash_fn key_hash;
34 pmix_common_dstore_key_match_fn key_match;
35 } pmix_common_dstore_file_cbs_t;
36
37 #define ESH_REGION_EXTENSION "EXTENSION_SLOT"
38 #define ESH_REGION_INVALIDATED "INVALIDATED"
39 #define ESH_ENV_INITIAL_SEG_SIZE "INITIAL_SEG_SIZE"
40 #define ESH_ENV_NS_META_SEG_SIZE "NS_META_SEG_SIZE"
41 #define ESH_ENV_NS_DATA_SEG_SIZE "NS_DATA_SEG_SIZE"
42 #define ESH_ENV_LINEAR "SM_USE_LINEAR_SEARCH"
43
44 #define ESH_MIN_KEY_LEN (sizeof(ESH_REGION_INVALIDATED))
45
46 #define PMIX_DS_PUT_KEY(rc, ctx, addr, key, buf, size) \
47 do { \
48 rc = PMIX_ERROR; \
49 if ((ctx)->file_cbs && (ctx)->file_cbs->put_key) { \
50 rc = (ctx)->file_cbs->put_key(addr, key, buf, size); \
51 } \
52 } while(0)
53
54 #define PMIX_DS_KV_SIZE(ctx, addr) \
55 __pmix_attribute_extension__ ({ \
56 size_t size = 0; \
57 if ((ctx)->file_cbs && (ctx)->file_cbs->kval_size) { \
58 size = (ctx)->file_cbs->kval_size(addr); \
59 } \
60 size; \
61 })
62
63 #define PMIX_DS_KNAME_PTR(ctx, addr) \
64 __pmix_attribute_extension__ ({ \
65 char *name_ptr = NULL; \
66 if ((ctx)->file_cbs && (ctx)->file_cbs->kname_ptr) { \
67 name_ptr = (ctx)->file_cbs->kname_ptr(addr); \
68 } \
69 name_ptr; \
70 })
71
72 #define PMIX_DS_KNAME_LEN(ctx, addr) \
73 __pmix_attribute_extension__ ({ \
74 size_t len = 0; \
75 if ((ctx)->file_cbs && (ctx)->file_cbs->kname_len) { \
76 len = (ctx)->file_cbs->kname_len((char*)addr); \
77 } \
78 len; \
79 })
80
81 #define PMIX_DS_DATA_PTR(ctx, addr) \
82 __pmix_attribute_extension__ ({ \
83 uint8_t *data_ptr = NULL; \
84 if ((ctx)->file_cbs && (ctx)->file_cbs->data_ptr) { \
85 data_ptr = (ctx)->file_cbs->data_ptr(addr); \
86 } \
87 data_ptr; \
88 })
89
90 #define PMIX_DS_DATA_SIZE(ctx, addr, data_ptr) \
91 __pmix_attribute_extension__ ({ \
92 size_t size = 0; \
93 if ((ctx)->file_cbs && (ctx)->file_cbs->data_size) { \
94 size = (ctx)->file_cbs->data_size(addr, data_ptr); \
95 } \
96 size; \
97 })
98
99 #define PMIX_DS_KEY_SIZE(ctx, key, data_size) \
100 __pmix_attribute_extension__ ({ \
101 size_t __size = 0; \
102 if ((ctx)->file_cbs && (ctx)->file_cbs->key_size) { \
103 __size = (ctx)->file_cbs->key_size(key, data_size); \
104 } \
105 __size; \
106 })
107
108 #define PMIX_DS_SLOT_SIZE(ctx) \
109 __pmix_attribute_extension__ ({ \
110 size_t __size = 0; \
111 if ((ctx)->file_cbs && (ctx)->file_cbs->ext_slot_size) { \
112 __size = (ctx)->file_cbs->ext_slot_size(); \
113 } \
114 __size; \
115 })
116
117 #define PMIX_DS_KEY_HASH(ctx, key) \
118 __pmix_attribute_extension__ ({ \
119 size_t keyhash = 0; \
120 if ((ctx)->file_cbs && (ctx)->file_cbs->key_hash) { \
121 keyhash = (ctx)->file_cbs->key_hash(key); \
122 } \
123 keyhash; \
124 })
125
126 #define PMIX_DS_KEY_MATCH(ctx, addr, key, hash) \
127 __pmix_attribute_extension__ ({ \
128 int ret = 0; \
129 if ((ctx)->file_cbs && (ctx)->file_cbs->key_match) { \
130 ret = (ctx)->file_cbs->key_match(addr, key, hash); \
131 } \
132 ret; \
133 })
134
135 #define PMIX_DS_KEY_IS_INVALID(ctx, addr) \
136 __pmix_attribute_extension__ ({ \
137 int ret = 0; \
138 if ((ctx)->file_cbs && (ctx)->file_cbs->is_invalid) { \
139 ret = (ctx)->file_cbs->is_invalid(addr); \
140 } \
141 ret; \
142 })
143
144 #define PMIX_DS_KEY_SET_INVALID(ctx, addr) \
145 do { \
146 if ((ctx)->file_cbs && (ctx)->file_cbs->set_invalid) { \
147 (ctx)->file_cbs->set_invalid(addr); \
148 } \
149 } while(0)
150
151 #define PMIX_DS_KEY_IS_EXTSLOT(ctx, addr) \
152 __pmix_attribute_extension__ ({ \
153 int ret = 0; \
154 if ((ctx)->file_cbs && (ctx)->file_cbs->is_invalid) { \
155 ret = (ctx)->file_cbs->is_extslot(addr); \
156 } \
157 ret; \
158 })
159
160
161 #endif