48#include <qb/qbipc_common.h>
64#define MAX_REQ_EXEC_CMAP_MCAST_ITEMS 32
65#define ICMAP_VALUETYPE_NOT_EXIST 0
153static int cmap_exec_exit_fn(
void);
155static int cmap_lib_init_fn (
void *conn);
156static int cmap_lib_exit_fn (
void *conn);
158static void message_handler_req_lib_cmap_set(
void *conn,
const void *message);
159static void message_handler_req_lib_cmap_delete(
void *conn,
const void *message);
160static void message_handler_req_lib_cmap_get(
void *conn,
const void *message);
161static void message_handler_req_lib_cmap_adjust_int(
void *conn,
const void *message);
162static void message_handler_req_lib_cmap_iter_init(
void *conn,
const void *message);
163static void message_handler_req_lib_cmap_iter_next(
void *conn,
const void *message);
164static void message_handler_req_lib_cmap_iter_finalize(
void *conn,
const void *message);
165static void message_handler_req_lib_cmap_track_add(
void *conn,
const void *message);
166static void message_handler_req_lib_cmap_track_delete(
void *conn,
const void *message);
167static void message_handler_req_lib_cmap_set_current_map(
void *conn,
const void *message);
169static void cmap_notify_fn(int32_t event,
170 const char *key_name,
175static void message_handler_req_exec_cmap_mcast(
179static void exec_cmap_mcast_endian_convert(
void *message);
190static void cmap_sync_init (
191 const unsigned int *trans_list,
192 size_t trans_list_entries,
193 const unsigned int *member_list,
194 size_t member_list_entries,
197static int cmap_sync_process (
void);
198static void cmap_sync_activate (
void);
199static void cmap_sync_abort (
void);
201static void cmap_config_version_track_cb(
203 const char *key_name,
218 .lib_handler_fn = message_handler_req_lib_cmap_delete,
222 .lib_handler_fn = message_handler_req_lib_cmap_get,
226 .lib_handler_fn = message_handler_req_lib_cmap_adjust_int,
230 .lib_handler_fn = message_handler_req_lib_cmap_iter_init,
234 .lib_handler_fn = message_handler_req_lib_cmap_iter_next,
238 .lib_handler_fn = message_handler_req_lib_cmap_iter_finalize,
242 .lib_handler_fn = message_handler_req_lib_cmap_track_add,
246 .lib_handler_fn = message_handler_req_lib_cmap_track_delete,
250 .lib_handler_fn = message_handler_req_lib_cmap_set_current_map,
259 .exec_endian_convert_fn = exec_cmap_mcast_endian_convert
264 .
name =
"corosync configuration map access",
270 .lib_init_fn = cmap_lib_init_fn,
271 .lib_exit_fn = cmap_lib_exit_fn,
272 .lib_engine = cmap_lib_engine,
274 .exec_init_fn = cmap_exec_init_fn,
275 .exec_exit_fn = cmap_exec_exit_fn,
276 .exec_engine = cmap_exec_engine,
278 .sync_init = cmap_sync_init,
279 .sync_process = cmap_sync_process,
280 .sync_activate = cmap_sync_activate,
281 .sync_abort = cmap_sync_abort
307static size_t cmap_sync_trans_list_entries = 0;
308static size_t cmap_sync_member_list_entries = 0;
309static uint64_t cmap_highest_config_version_received = 0;
310static uint64_t cmap_my_config_version = 0;
311static int cmap_first_sync = 1;
314static void cmap_config_version_track_cb(
316 const char *key_name,
321 const char *key =
"totem.config_version";
327 cmap_my_config_version = 0;
339static int cmap_exec_exit_fn(
void)
349static char *cmap_exec_init_fn (
358 cmap_config_version_track_cb,
360 &cmap_config_version_track);
363 return ((
char *)
"Can't add config_version icmap tracker");
369static int cmap_lib_init_fn (
void *conn)
377 memset(conn_info, 0,
sizeof(*conn_info));
379 hdb_create(&conn_info->
iter_db);
385static int cmap_lib_exit_fn (
void *conn)
395 hdb_iterator_reset(&conn_info->
iter_db);
396 while (hdb_iterator_next(&conn_info->
iter_db,
397 (
void*)&iter, &iter_handle) == 0) {
401 (void)hdb_handle_put (&conn_info->
iter_db, iter_handle);
404 hdb_destroy(&conn_info->
iter_db);
406 hdb_iterator_reset(&conn_info->
track_db);
407 while (hdb_iterator_next(&conn_info->
track_db,
408 (
void*)&track, &track_handle) == 0) {
414 (void)hdb_handle_put (&conn_info->
track_db, track_handle);
423static void cmap_sync_init (
424 const unsigned int *trans_list,
425 size_t trans_list_entries,
426 const unsigned int *member_list,
427 size_t member_list_entries,
431 cmap_sync_trans_list_entries = trans_list_entries;
432 cmap_sync_member_list_entries = member_list_entries;
435 cmap_my_config_version = 0;
438 cmap_highest_config_version_received = cmap_my_config_version;
441static int cmap_sync_process (
void)
443 const char *key =
"totem.config_version";
448 return (ret ==
CS_OK ? 0 : -1);
451static void cmap_sync_activate (
void)
454 if (cmap_sync_trans_list_entries == 0) {
460 if (cmap_first_sync == 1) {
468 if (cmap_my_config_version == 0) {
474 if (cmap_highest_config_version_received != cmap_my_config_version) {
476 "Received config version (%"PRIu64
") is different than my config version (%"PRIu64
")! Exiting",
477 cmap_highest_config_version_received, cmap_my_config_version);
483static void cmap_sync_abort (
void)
489static void message_handler_req_lib_cmap_set(
void *conn,
const void *message)
511static void message_handler_req_lib_cmap_delete(
void *conn,
const void *message)
532static void message_handler_req_lib_cmap_get(
void *conn,
const void *message)
540 size_t res_lib_cmap_get_size;
546 res_lib_cmap_get_size =
sizeof(*res_lib_cmap_get) + value_len;
583 memset(&error_res_lib_cmap_get, 0,
sizeof(error_res_lib_cmap_get));
584 error_res_lib_cmap_get.header.size =
sizeof(error_res_lib_cmap_get);
586 error_res_lib_cmap_get.header.error = ret;
588 api->
ipc_response_send(conn, &error_res_lib_cmap_get,
sizeof(error_res_lib_cmap_get));
591static void message_handler_req_lib_cmap_adjust_int(
void *conn,
const void *message)
614static void message_handler_req_lib_cmap_iter_init(
void *conn,
const void *message)
649 (void)hdb_handle_put (&conn_info->
iter_db, handle);
661static void message_handler_req_lib_cmap_iter_next(
void *conn,
const void *message)
667 size_t value_len = 0;
669 const char *res = NULL;
704static void message_handler_req_lib_cmap_iter_finalize(
void *conn,
const void *message)
733static void cmap_notify_fn(int32_t event,
734 const char *key_name,
763 iov[1].iov_base = (
char *)new_val.
data;
764 iov[1].iov_len = new_val.
len;
765 iov[2].iov_base = (
char *)old_val.
data;
766 iov[2].iov_len = old_val.
len;
771static void message_handler_req_lib_cmap_track_add(
void *conn,
const void *message)
780 const char *key_name;
828 (void)hdb_handle_put (&conn_info->
track_db, handle);
840static void message_handler_req_lib_cmap_track_delete(
void *conn,
const void *message)
847 uint64_t track_inst_handle = 0;
876static void message_handler_req_lib_cmap_set_current_map(
void *
conn,
const void *message)
879 struct qb_ipc_response_header res;
882 int handles_open = 0;
889 hdb_iterator_reset(&conn_info->
iter_db);
890 while (hdb_iterator_next(&conn_info->
iter_db,
891 (
void*)&iter, &iter_handle) == 0) {
895 hdb_iterator_reset(&conn_info->
track_db);
896 while (hdb_iterator_next(&conn_info->
track_db,
897 (
void*)&track, &track_handle) == 0) {
919 res.size =
sizeof(res);
944 memset(req_exec_cmap_iovec, 0,
sizeof(req_exec_cmap_iovec));
946 for (i = 0; i < argc; i++) {
947 err =
icmap_get(argv[i], NULL, &value_len, &value_type);
958 item = malloc(item_len);
962 memset(item, 0, item_len);
964 item->value_type = value_type;
965 item->value_len = value_len;
966 item->key_name.length = strlen(argv[i]);
968 assert(strlen(argv[i]) <
sizeof(item->key_name.value));
970 strcpy((
char *)item->key_name.value, argv[i]);
973 err =
icmap_get(argv[i], item->value, &value_len, &value_type);
979 req_exec_cmap_iovec[i + 1].iov_base = item;
980 req_exec_cmap_iovec[i + 1].iov_len = item_len;
983 qb_log(LOG_TRACE,
"Item %u - type %u, len %zu", i, item->value_type, item->value_len);
995 qb_log(LOG_TRACE,
"Sending %u items (%u iovec) for reason %u", argc, argc + 1, reason);
999 for (i = 0; i < argc; i++) {
1000 free(req_exec_cmap_iovec[i + 1].iov_base);
1010 const void *message,
1024 key_name_len = item->key_name.length;
1025 if (strlen(key) == key_name_len && strcmp((
char *)item->key_name.value, key) == 0) {
1035static void message_handler_req_exec_cmap_mcast_reason_sync_nv(
1037 const void *message,
1041 uint64_t config_version = 0;
1047 item = cmap_mcast_item_find(message, (
char *)
"totem.config_version");
1049 value_len = item->value_len;
1056 memcpy(&config_version, item->value, value_len);
1060 qb_log(LOG_TRACE,
"Received config version %"PRIu64
" from node " CS_PRI_NODE_ID, config_version,
nodeid);
1063 config_version > cmap_highest_config_version_received) {
1064 cmap_highest_config_version_received = config_version;
1068 "runtime.members.%u.config_version",
nodeid);
1074static void message_handler_req_exec_cmap_mcast(
1075 const void *message,
1100static void exec_cmap_mcast_endian_convert(
void *message)
1119 swab_mar_uint16_t(&item->key_name.length);
1120 swab_mar_size_t(&item->value_len);
1122 switch (item->value_type) {
1125 memcpy(&u16, item->value,
sizeof(u16));
1127 memcpy(item->value, &u16,
sizeof(u16));
1131 memcpy(&u32, item->value,
sizeof(u32));
1133 memcpy(item->value, &u32,
sizeof(u32));
1137 memcpy(&u64, item->value,
sizeof(u64));
1139 memcpy(item->value, &u64,
sizeof(u64));
1142 memcpy(&flt, item->value,
sizeof(flt));
1144 memcpy(item->value, &flt,
sizeof(flt));
1147 memcpy(&dbl, item->value,
sizeof(dbl));
1149 memcpy(item->value, &dbl,
sizeof(dbl));
@ CS_LIB_FLOW_CONTROL_NOT_REQUIRED
cs_error_t
The cs_error_t enum.
LOGSYS_DECLARE_SUBSYS("CMAP")
uint64_t cmap_iter_handle_t
struct cmap_map stats_map
#define ICMAP_VALUETYPE_NOT_EXIST
#define MAX_REQ_EXEC_CMAP_MCAST_ITEMS
struct corosync_service_engine * cmap_get_service_engine_ver0(void)
@ MESSAGE_REQ_EXEC_CMAP_MCAST
uint64_t cmap_track_handle_t
struct cmap_map icmap_map
@ CMAP_MCAST_REASON_NEW_CONFIG_VERSION
struct corosync_service_engine cmap_service_engine
uint64_t cmap_iter_handle_t
uint64_t cmap_track_handle_t
#define hdb_handle_database
#define ICMAP_TRACK_MODIFY
cs_error_t icmap_set(const char *key_name, const void *value, size_t value_len, icmap_value_types_t type)
Store value with value_len length and type as key_name name in global icmap.
cs_error_t icmap_adjust_int(const char *key_name, int32_t step)
icmap_adjust_int
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
icmap_value_types_t
Possible types of value.
#define ICMAP_TRACK_DELETE
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Add tracking function for given key_name.
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
void(* icmap_notify_fn_t)(int32_t event, const char *key_name, struct icmap_notify_value new_value, struct icmap_notify_value old_value, void *user_data)
Prototype for notify callback function.
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Retrieve value of key key_name and store it in user preallocated value pointer.
qb_map_iter_t * icmap_iter_t
Itterator type.
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
cs_error_t icmap_track_delete(icmap_track_t icmap_track)
Remove previously added track.
cs_error_t icmap_set_uint64(const char *key_name, uint64_t value)
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
void * icmap_track_get_user_data(icmap_track_t icmap_track)
Return user data associated with given track.
cs_error_t icmap_get_uint64(const char *key_name, uint64_t *u64)
int icmap_is_key_ro(const char *key_name)
Check in given key is read only.
@ MESSAGE_RES_CMAP_ITER_FINALIZE
@ MESSAGE_RES_CMAP_SET_CURRENT_MAP
@ MESSAGE_RES_CMAP_ITER_INIT
@ MESSAGE_RES_CMAP_ITER_NEXT
@ MESSAGE_RES_CMAP_DELETE
@ MESSAGE_RES_CMAP_NOTIFY_CALLBACK
@ MESSAGE_RES_CMAP_TRACK_ADD
@ MESSAGE_RES_CMAP_TRACK_DELETE
@ MESSAGE_RES_CMAP_ADJUST_INT
cs_error_t hdb_error_to_cs(int res)
#define LOGSYS_LEVEL_ERROR
#define log_printf(level, format, args...)
#define LOGSYS_LEVEL_DEBUG
#define MAR_ALIGN_UP(addr, size)
mar_uint64_t mar_size_t
mar_size_t
const char * stats_map_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
void * stats_map_track_get_user_data(icmap_track_t icmap_track)
cs_error_t stats_map_delete(const char *key_name)
cs_error_t stats_map_track_delete(icmap_track_t icmap_track)
icmap_iter_t stats_map_iter_init(const char *prefix)
int stats_map_is_key_ro(const char *key_name)
cs_error_t stats_map_set(const char *key_name, const void *value, size_t value_len, icmap_value_types_t type)
void stats_map_iter_finalize(icmap_iter_t iter)
cs_error_t stats_map_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
cs_error_t stats_map_adjust_int(const char *key_name, int32_t step)
cs_error_t stats_map_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
struct hdb_handle_database iter_db
struct hdb_handle_database track_db
void *(* map_track_get_user_data)(icmap_track_t icmap_track)
const char *(* map_iter_next)(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
cs_error_t(* map_track_add)(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
cs_error_t(* map_track_delete)(icmap_track_t icmap_track)
void(* map_iter_finalize)(icmap_iter_t iter)
cs_error_t(* map_get)(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
int(* map_is_key_ro)(const char *key_name)
cs_error_t(* map_delete)(const char *key_name)
cs_error_t(* map_set)(const char *key_name, const void *value, size_t value_len, icmap_value_types_t type)
cs_error_t(* map_adjust_int)(const char *key_name, int32_t step)
icmap_iter_t(* map_iter_init)(const char *prefix)
cmap_track_handle_t track_handle
uint64_t track_inst_handle
The corosync_api_v1 struct.
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
void *(* ipc_private_data_get)(void *conn)
unsigned int(* totem_nodeid_get)(void)
void(* ipc_refcnt_dec)(void *conn)
void(* shutdown_request)(void)
void(* ipc_refcnt_inc)(void *conn)
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
int(* ipc_dispatch_iov_send)(void *conn, const struct iovec *iov, unsigned int iov_len)
The corosync_exec_handler struct.
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
The corosync_lib_handler struct.
void(* lib_handler_fn)(void *conn, const void *msg)
The corosync_service_engine struct.
Structure passed as new_value and old_value in change callback.
mar_size_t value_len __attribute__((aligned(8)))
mar_name_t key_name __attribute__((aligned(8)))
mar_uint8_t value_type __attribute__((aligned(8)))
uint8_t value[] __attribute__((aligned(8)))
mar_uint8_t reason __attribute__((aligned(8)))
mar_uint8_t no_items __attribute__((aligned(8)))
mar_uint8_t reserver2 __attribute__((aligned(8)))
mar_uint8_t reserved1 __attribute__((aligned(8)))
struct qb_ipc_request_header header __attribute__((aligned(8)))
The req_lib_cmap_adjust_int struct.
The req_lib_cmap_get struct.
The req_lib_cmap_iter_finalize struct.
The req_lib_cmap_iter_init struct.
The req_lib_cmap_iter_next struct.
The req_lib_cmap_set_current_map struct used by cmap_initialize_map()
The req_lib_cmap_set struct.
The req_lib_cmap_track_add struct.
The req_lib_cmap_track_delete struct.
The res_lib_cmap_adjust_int struct.
The res_lib_cmap_delete struct.
The res_lib_cmap_get struct.
The res_lib_cmap_iter_finalize struct.
The res_lib_cmap_iter_init struct.
The res_lib_cmap_iter_next struct.
The res_lib_cmap_notify_callback struct.
The res_lib_cmap_set struct.
The res_lib_cmap_track_add struct.
The res_lib_cmap_track_delete struct.
#define swab64(x)
The swab64 macro.
#define swab16(x)
The swab16 macro.
#define swab32(x)
The swab32 macro.
struct memb_ring_id ring_id
struct totem_message_header header