cmap.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. /*
  2. * Copyright (c) 2011-2017 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Jan Friesse (jfriesse@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the Red Hat, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <sys/types.h>
  36. #include <unistd.h>
  37. #include <fcntl.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <poll.h>
  41. #include <assert.h>
  42. #include <qb/qbloop.h>
  43. #include <qb/qblist.h>
  44. #include <qb/qbipcs.h>
  45. #include <qb/qbipc_common.h>
  46. #include <corosync/corotypes.h>
  47. #include <corosync/corodefs.h>
  48. #include <corosync/mar_gen.h>
  49. #include <corosync/ipc_cmap.h>
  50. #include <corosync/logsys.h>
  51. #include <corosync/coroapi.h>
  52. #include <corosync/icmap.h>
  53. #include "service.h"
  54. #include "ipcs_stats.h"
  55. #include "stats.h"
  56. LOGSYS_DECLARE_SUBSYS ("CMAP");
  57. #define MAX_REQ_EXEC_CMAP_MCAST_ITEMS 32
  58. #define ICMAP_VALUETYPE_NOT_EXIST 0
  59. struct cmap_map {
  60. cs_error_t (*map_get)(const char *key_name,
  61. void *value,
  62. size_t *value_len,
  63. icmap_value_types_t *type);
  64. cs_error_t (*map_set)(const char *key_name,
  65. const void *value,
  66. size_t value_len,
  67. icmap_value_types_t type);
  68. cs_error_t (*map_adjust_int)(const char *key_name, int32_t step);
  69. cs_error_t (*map_delete)(const char *key_name);
  70. int (*map_is_key_ro)(const char *key_name);
  71. icmap_iter_t (*map_iter_init)(const char *prefix);
  72. const char * (*map_iter_next)(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type);
  73. void (*map_iter_finalize)(icmap_iter_t iter);
  74. cs_error_t (*map_track_add)(const char *key_name,
  75. int32_t track_type,
  76. icmap_notify_fn_t notify_fn,
  77. void *user_data,
  78. icmap_track_t *icmap_track);
  79. cs_error_t (*map_track_delete)(icmap_track_t icmap_track);
  80. void * (*map_track_get_user_data)(icmap_track_t icmap_track);
  81. };
  82. struct cmap_map icmap_map = {
  83. .map_get = icmap_get,
  84. .map_set = icmap_set,
  85. .map_adjust_int = icmap_adjust_int,
  86. .map_delete = icmap_delete,
  87. .map_is_key_ro = icmap_is_key_ro,
  88. .map_iter_init = icmap_iter_init,
  89. .map_iter_next = icmap_iter_next,
  90. .map_iter_finalize = icmap_iter_finalize,
  91. .map_track_add = icmap_track_add,
  92. .map_track_delete = icmap_track_delete,
  93. .map_track_get_user_data = icmap_track_get_user_data,
  94. };
  95. struct cmap_map stats_map = {
  96. .map_get = stats_map_get,
  97. .map_set = stats_map_set,
  98. .map_adjust_int = stats_map_adjust_int,
  99. .map_delete = stats_map_delete,
  100. .map_is_key_ro = stats_map_is_key_ro,
  101. .map_iter_init = stats_map_iter_init,
  102. .map_iter_next = stats_map_iter_next,
  103. .map_iter_finalize = stats_map_iter_finalize,
  104. .map_track_add = stats_map_track_add,
  105. .map_track_delete = stats_map_track_delete,
  106. .map_track_get_user_data = stats_map_track_get_user_data,
  107. };
  108. struct cmap_conn_info {
  109. struct hdb_handle_database iter_db;
  110. struct hdb_handle_database track_db;
  111. struct cmap_map map_fns;
  112. };
  113. typedef uint64_t cmap_iter_handle_t;
  114. typedef uint64_t cmap_track_handle_t;
  115. struct cmap_track_user_data {
  116. void *conn;
  117. cmap_track_handle_t track_handle;
  118. uint64_t track_inst_handle;
  119. };
  120. enum cmap_message_req_types {
  121. MESSAGE_REQ_EXEC_CMAP_MCAST = 0,
  122. };
  123. enum cmap_mcast_reason {
  124. CMAP_MCAST_REASON_SYNC = 0,
  125. CMAP_MCAST_REASON_NEW_CONFIG_VERSION = 1,
  126. };
  127. static struct corosync_api_v1 *api;
  128. static char *cmap_exec_init_fn (struct corosync_api_v1 *corosync_api);
  129. static int cmap_exec_exit_fn(void);
  130. static int cmap_lib_init_fn (void *conn);
  131. static int cmap_lib_exit_fn (void *conn);
  132. static void message_handler_req_lib_cmap_set(void *conn, const void *message);
  133. static void message_handler_req_lib_cmap_delete(void *conn, const void *message);
  134. static void message_handler_req_lib_cmap_get(void *conn, const void *message);
  135. static void message_handler_req_lib_cmap_adjust_int(void *conn, const void *message);
  136. static void message_handler_req_lib_cmap_iter_init(void *conn, const void *message);
  137. static void message_handler_req_lib_cmap_iter_next(void *conn, const void *message);
  138. static void message_handler_req_lib_cmap_iter_finalize(void *conn, const void *message);
  139. static void message_handler_req_lib_cmap_track_add(void *conn, const void *message);
  140. static void message_handler_req_lib_cmap_track_delete(void *conn, const void *message);
  141. static void message_handler_req_lib_cmap_set_current_map(void *conn, const void *message);
  142. static void cmap_notify_fn(int32_t event,
  143. const char *key_name,
  144. struct icmap_notify_value new_val,
  145. struct icmap_notify_value old_val,
  146. void *user_data);
  147. static void message_handler_req_exec_cmap_mcast(
  148. const void *message,
  149. unsigned int nodeid);
  150. static void exec_cmap_mcast_endian_convert(void *message);
  151. /*
  152. * Reson is subtype of message. argc is number of items in argv array. Argv is array
  153. * of strings (key names) which will be send to wire. There can be maximum
  154. * MAX_REQ_EXEC_CMAP_MCAST_ITEMS items (for more items, CS_ERR_TOO_MANY_GROUPS
  155. * error is returned). If key is not found, item has type ICMAP_VALUETYPE_NOT_EXIST
  156. * and length zero.
  157. */
  158. static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char *argv[]);
  159. static void cmap_sync_init (
  160. const unsigned int *trans_list,
  161. size_t trans_list_entries,
  162. const unsigned int *member_list,
  163. size_t member_list_entries,
  164. const struct memb_ring_id *ring_id);
  165. static int cmap_sync_process (void);
  166. static void cmap_sync_activate (void);
  167. static void cmap_sync_abort (void);
  168. static void cmap_config_version_track_cb(
  169. int32_t event,
  170. const char *key_name,
  171. struct icmap_notify_value new_value,
  172. struct icmap_notify_value old_value,
  173. void *user_data);
  174. /*
  175. * Library Handler Definition
  176. */
  177. static struct corosync_lib_handler cmap_lib_engine[] =
  178. {
  179. { /* 0 */
  180. .lib_handler_fn = message_handler_req_lib_cmap_set,
  181. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  182. },
  183. { /* 1 */
  184. .lib_handler_fn = message_handler_req_lib_cmap_delete,
  185. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  186. },
  187. { /* 2 */
  188. .lib_handler_fn = message_handler_req_lib_cmap_get,
  189. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  190. },
  191. { /* 3 */
  192. .lib_handler_fn = message_handler_req_lib_cmap_adjust_int,
  193. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  194. },
  195. { /* 4 */
  196. .lib_handler_fn = message_handler_req_lib_cmap_iter_init,
  197. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  198. },
  199. { /* 5 */
  200. .lib_handler_fn = message_handler_req_lib_cmap_iter_next,
  201. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  202. },
  203. { /* 6 */
  204. .lib_handler_fn = message_handler_req_lib_cmap_iter_finalize,
  205. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  206. },
  207. { /* 7 */
  208. .lib_handler_fn = message_handler_req_lib_cmap_track_add,
  209. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  210. },
  211. { /* 8 */
  212. .lib_handler_fn = message_handler_req_lib_cmap_track_delete,
  213. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  214. },
  215. { /* 9 */
  216. .lib_handler_fn = message_handler_req_lib_cmap_set_current_map,
  217. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  218. },
  219. };
  220. static struct corosync_exec_handler cmap_exec_engine[] =
  221. {
  222. { /* 0 - MESSAGE_REQ_EXEC_CMAP_MCAST */
  223. .exec_handler_fn = message_handler_req_exec_cmap_mcast,
  224. .exec_endian_convert_fn = exec_cmap_mcast_endian_convert
  225. },
  226. };
  227. struct corosync_service_engine cmap_service_engine = {
  228. .name = "corosync configuration map access",
  229. .id = CMAP_SERVICE,
  230. .priority = 1,
  231. .private_data_size = sizeof(struct cmap_conn_info),
  232. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  233. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  234. .lib_init_fn = cmap_lib_init_fn,
  235. .lib_exit_fn = cmap_lib_exit_fn,
  236. .lib_engine = cmap_lib_engine,
  237. .lib_engine_count = sizeof (cmap_lib_engine) / sizeof (struct corosync_lib_handler),
  238. .exec_init_fn = cmap_exec_init_fn,
  239. .exec_exit_fn = cmap_exec_exit_fn,
  240. .exec_engine = cmap_exec_engine,
  241. .exec_engine_count = sizeof (cmap_exec_engine) / sizeof (struct corosync_exec_handler),
  242. .sync_init = cmap_sync_init,
  243. .sync_process = cmap_sync_process,
  244. .sync_activate = cmap_sync_activate,
  245. .sync_abort = cmap_sync_abort
  246. };
  247. struct corosync_service_engine *cmap_get_service_engine_ver0 (void)
  248. {
  249. return (&cmap_service_engine);
  250. }
  251. struct req_exec_cmap_mcast_item {
  252. mar_name_t key_name __attribute__((aligned(8)));
  253. mar_uint8_t value_type __attribute__((aligned(8)));
  254. mar_size_t value_len __attribute__((aligned(8)));
  255. uint8_t value[] __attribute__((aligned(8)));
  256. };
  257. struct req_exec_cmap_mcast {
  258. struct qb_ipc_request_header header __attribute__((aligned(8)));
  259. mar_uint8_t reason __attribute__((aligned(8)));
  260. mar_uint8_t no_items __attribute__((aligned(8)));
  261. mar_uint8_t reserved1 __attribute__((aligned(8)));
  262. mar_uint8_t reserver2 __attribute__((aligned(8)));
  263. /*
  264. * Following are array of req_exec_cmap_mcast_item alligned to 8 bytes
  265. */
  266. };
  267. static size_t cmap_sync_trans_list_entries = 0;
  268. static size_t cmap_sync_member_list_entries = 0;
  269. static uint64_t cmap_highest_config_version_received = 0;
  270. static uint64_t cmap_my_config_version = 0;
  271. static int cmap_first_sync = 1;
  272. static icmap_track_t cmap_config_version_track;
  273. static void cmap_config_version_track_cb(
  274. int32_t event,
  275. const char *key_name,
  276. struct icmap_notify_value new_value,
  277. struct icmap_notify_value old_value,
  278. void *user_data)
  279. {
  280. const char *key = "totem.config_version";
  281. cs_error_t ret;
  282. ENTER();
  283. if (icmap_get_uint64("totem.config_version", &cmap_my_config_version) != CS_OK) {
  284. cmap_my_config_version = 0;
  285. }
  286. ret = cmap_mcast_send(CMAP_MCAST_REASON_NEW_CONFIG_VERSION, 1, (char **)&key);
  287. if (ret != CS_OK) {
  288. log_printf(LOGSYS_LEVEL_ERROR, "Can't inform other nodes about new config version");
  289. }
  290. LEAVE();
  291. }
  292. static int cmap_exec_exit_fn(void)
  293. {
  294. if (icmap_track_delete(cmap_config_version_track) != CS_OK) {
  295. log_printf(LOGSYS_LEVEL_ERROR, "Can't delete config_version icmap tracker");
  296. }
  297. return 0;
  298. }
  299. static char *cmap_exec_init_fn (
  300. struct corosync_api_v1 *corosync_api)
  301. {
  302. cs_error_t ret;
  303. api = corosync_api;
  304. ret = icmap_track_add("totem.config_version",
  305. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY,
  306. cmap_config_version_track_cb,
  307. NULL,
  308. &cmap_config_version_track);
  309. if (ret != CS_OK) {
  310. return ((char *)"Can't add config_version icmap tracker");
  311. }
  312. return (NULL);
  313. }
  314. static int cmap_lib_init_fn (void *conn)
  315. {
  316. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  317. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p", conn);
  318. api->ipc_refcnt_inc(conn);
  319. memset(conn_info, 0, sizeof(*conn_info));
  320. conn_info->map_fns = icmap_map;
  321. hdb_create(&conn_info->iter_db);
  322. hdb_create(&conn_info->track_db);
  323. return (0);
  324. }
  325. static int cmap_lib_exit_fn (void *conn)
  326. {
  327. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  328. hdb_handle_t iter_handle = 0;
  329. icmap_iter_t *iter;
  330. hdb_handle_t track_handle = 0;
  331. icmap_track_t *track;
  332. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p", conn);
  333. hdb_iterator_reset(&conn_info->iter_db);
  334. while (hdb_iterator_next(&conn_info->iter_db,
  335. (void*)&iter, &iter_handle) == 0) {
  336. conn_info->map_fns.map_iter_finalize(*iter);
  337. (void)hdb_handle_put (&conn_info->iter_db, iter_handle);
  338. }
  339. hdb_destroy(&conn_info->iter_db);
  340. hdb_iterator_reset(&conn_info->track_db);
  341. while (hdb_iterator_next(&conn_info->track_db,
  342. (void*)&track, &track_handle) == 0) {
  343. free(conn_info->map_fns.map_track_get_user_data(*track));
  344. conn_info->map_fns.map_track_delete(*track);
  345. (void)hdb_handle_put (&conn_info->track_db, track_handle);
  346. }
  347. hdb_destroy(&conn_info->track_db);
  348. api->ipc_refcnt_dec(conn);
  349. return (0);
  350. }
  351. static void cmap_sync_init (
  352. const unsigned int *trans_list,
  353. size_t trans_list_entries,
  354. const unsigned int *member_list,
  355. size_t member_list_entries,
  356. const struct memb_ring_id *ring_id)
  357. {
  358. cmap_sync_trans_list_entries = trans_list_entries;
  359. cmap_sync_member_list_entries = member_list_entries;
  360. if (icmap_get_uint64("totem.config_version", &cmap_my_config_version) != CS_OK) {
  361. cmap_my_config_version = 0;
  362. }
  363. cmap_highest_config_version_received = cmap_my_config_version;
  364. }
  365. static int cmap_sync_process (void)
  366. {
  367. const char *key = "totem.config_version";
  368. cs_error_t ret;
  369. ret = cmap_mcast_send(CMAP_MCAST_REASON_SYNC, 1, (char **)&key);
  370. return (ret == CS_OK ? 0 : -1);
  371. }
  372. static void cmap_sync_activate (void)
  373. {
  374. if (cmap_sync_trans_list_entries == 0) {
  375. log_printf(LOGSYS_LEVEL_DEBUG, "Single node sync -> no action");
  376. return ;
  377. }
  378. if (cmap_first_sync == 1) {
  379. cmap_first_sync = 0;
  380. } else {
  381. log_printf(LOGSYS_LEVEL_DEBUG, "Not first sync -> no action");
  382. return ;
  383. }
  384. if (cmap_my_config_version == 0) {
  385. log_printf(LOGSYS_LEVEL_DEBUG, "My config version is 0 -> no action");
  386. return ;
  387. }
  388. if (cmap_highest_config_version_received != cmap_my_config_version) {
  389. log_printf(LOGSYS_LEVEL_ERROR,
  390. "Received config version (%"PRIu64") is different than my config version (%"PRIu64")! Exiting",
  391. cmap_highest_config_version_received, cmap_my_config_version);
  392. api->shutdown_request();
  393. return ;
  394. }
  395. }
  396. static void cmap_sync_abort (void)
  397. {
  398. }
  399. static void message_handler_req_lib_cmap_set(void *conn, const void *message)
  400. {
  401. const struct req_lib_cmap_set *req_lib_cmap_set = message;
  402. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  403. struct res_lib_cmap_set res_lib_cmap_set;
  404. cs_error_t ret;
  405. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_set->key_name.value)) {
  406. ret = CS_ERR_ACCESS;
  407. } else {
  408. ret = conn_info->map_fns.map_set((char *)req_lib_cmap_set->key_name.value, &req_lib_cmap_set->value,
  409. req_lib_cmap_set->value_len, req_lib_cmap_set->type);
  410. }
  411. memset(&res_lib_cmap_set, 0, sizeof(res_lib_cmap_set));
  412. res_lib_cmap_set.header.size = sizeof(res_lib_cmap_set);
  413. res_lib_cmap_set.header.id = MESSAGE_RES_CMAP_SET;
  414. res_lib_cmap_set.header.error = ret;
  415. api->ipc_response_send(conn, &res_lib_cmap_set, sizeof(res_lib_cmap_set));
  416. }
  417. static void message_handler_req_lib_cmap_delete(void *conn, const void *message)
  418. {
  419. const struct req_lib_cmap_set *req_lib_cmap_set = message;
  420. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  421. struct res_lib_cmap_delete res_lib_cmap_delete;
  422. cs_error_t ret;
  423. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_set->key_name.value)) {
  424. ret = CS_ERR_ACCESS;
  425. } else {
  426. ret = conn_info->map_fns.map_delete((char *)req_lib_cmap_set->key_name.value);
  427. }
  428. memset(&res_lib_cmap_delete, 0, sizeof(res_lib_cmap_delete));
  429. res_lib_cmap_delete.header.size = sizeof(res_lib_cmap_delete);
  430. res_lib_cmap_delete.header.id = MESSAGE_RES_CMAP_DELETE;
  431. res_lib_cmap_delete.header.error = ret;
  432. api->ipc_response_send(conn, &res_lib_cmap_delete, sizeof(res_lib_cmap_delete));
  433. }
  434. static void message_handler_req_lib_cmap_get(void *conn, const void *message)
  435. {
  436. const struct req_lib_cmap_get *req_lib_cmap_get = message;
  437. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  438. struct res_lib_cmap_get *res_lib_cmap_get;
  439. struct res_lib_cmap_get error_res_lib_cmap_get;
  440. cs_error_t ret;
  441. size_t value_len;
  442. size_t res_lib_cmap_get_size;
  443. icmap_value_types_t type;
  444. void *value;
  445. value_len = req_lib_cmap_get->value_len;
  446. res_lib_cmap_get_size = sizeof(*res_lib_cmap_get) + value_len;
  447. res_lib_cmap_get = malloc(res_lib_cmap_get_size);
  448. if (res_lib_cmap_get == NULL) {
  449. ret = CS_ERR_NO_MEMORY;
  450. goto error_exit;
  451. }
  452. memset(res_lib_cmap_get, 0, res_lib_cmap_get_size);
  453. if (value_len > 0) {
  454. value = res_lib_cmap_get->value;
  455. } else {
  456. value = NULL;
  457. }
  458. ret = conn_info->map_fns.map_get((char *)req_lib_cmap_get->key_name.value,
  459. value,
  460. &value_len,
  461. &type);
  462. if (ret != CS_OK) {
  463. free(res_lib_cmap_get);
  464. goto error_exit;
  465. }
  466. res_lib_cmap_get->header.size = res_lib_cmap_get_size;
  467. res_lib_cmap_get->header.id = MESSAGE_RES_CMAP_GET;
  468. res_lib_cmap_get->header.error = ret;
  469. res_lib_cmap_get->type = type;
  470. res_lib_cmap_get->value_len = value_len;
  471. api->ipc_response_send(conn, res_lib_cmap_get, res_lib_cmap_get_size);
  472. free(res_lib_cmap_get);
  473. return ;
  474. error_exit:
  475. memset(&error_res_lib_cmap_get, 0, sizeof(error_res_lib_cmap_get));
  476. error_res_lib_cmap_get.header.size = sizeof(error_res_lib_cmap_get);
  477. error_res_lib_cmap_get.header.id = MESSAGE_RES_CMAP_GET;
  478. error_res_lib_cmap_get.header.error = ret;
  479. api->ipc_response_send(conn, &error_res_lib_cmap_get, sizeof(error_res_lib_cmap_get));
  480. }
  481. static void message_handler_req_lib_cmap_adjust_int(void *conn, const void *message)
  482. {
  483. const struct req_lib_cmap_adjust_int *req_lib_cmap_adjust_int = message;
  484. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  485. struct res_lib_cmap_adjust_int res_lib_cmap_adjust_int;
  486. cs_error_t ret;
  487. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_adjust_int->key_name.value)) {
  488. ret = CS_ERR_ACCESS;
  489. } else {
  490. ret = conn_info->map_fns.map_adjust_int((char *)req_lib_cmap_adjust_int->key_name.value,
  491. req_lib_cmap_adjust_int->step);
  492. }
  493. memset(&res_lib_cmap_adjust_int, 0, sizeof(res_lib_cmap_adjust_int));
  494. res_lib_cmap_adjust_int.header.size = sizeof(res_lib_cmap_adjust_int);
  495. res_lib_cmap_adjust_int.header.id = MESSAGE_RES_CMAP_ADJUST_INT;
  496. res_lib_cmap_adjust_int.header.error = ret;
  497. api->ipc_response_send(conn, &res_lib_cmap_adjust_int, sizeof(res_lib_cmap_adjust_int));
  498. }
  499. static void message_handler_req_lib_cmap_iter_init(void *conn, const void *message)
  500. {
  501. const struct req_lib_cmap_iter_init *req_lib_cmap_iter_init = message;
  502. struct res_lib_cmap_iter_init res_lib_cmap_iter_init;
  503. cs_error_t ret;
  504. icmap_iter_t iter;
  505. icmap_iter_t *hdb_iter;
  506. cmap_iter_handle_t handle = 0ULL;
  507. const char *prefix;
  508. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  509. if (req_lib_cmap_iter_init->prefix.length > 0) {
  510. prefix = (char *)req_lib_cmap_iter_init->prefix.value;
  511. } else {
  512. prefix = NULL;
  513. }
  514. iter = conn_info->map_fns.map_iter_init(prefix);
  515. if (iter == NULL) {
  516. ret = CS_ERR_NO_SECTIONS;
  517. goto reply_send;
  518. }
  519. ret = hdb_error_to_cs(hdb_handle_create(&conn_info->iter_db, sizeof(iter), &handle));
  520. if (ret != CS_OK) {
  521. goto reply_send;
  522. }
  523. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db, handle, (void *)&hdb_iter));
  524. if (ret != CS_OK) {
  525. goto reply_send;
  526. }
  527. *hdb_iter = iter;
  528. (void)hdb_handle_put (&conn_info->iter_db, handle);
  529. reply_send:
  530. memset(&res_lib_cmap_iter_init, 0, sizeof(res_lib_cmap_iter_init));
  531. res_lib_cmap_iter_init.header.size = sizeof(res_lib_cmap_iter_init);
  532. res_lib_cmap_iter_init.header.id = MESSAGE_RES_CMAP_ITER_INIT;
  533. res_lib_cmap_iter_init.header.error = ret;
  534. res_lib_cmap_iter_init.iter_handle = handle;
  535. api->ipc_response_send(conn, &res_lib_cmap_iter_init, sizeof(res_lib_cmap_iter_init));
  536. }
  537. static void message_handler_req_lib_cmap_iter_next(void *conn, const void *message)
  538. {
  539. const struct req_lib_cmap_iter_next *req_lib_cmap_iter_next = message;
  540. struct res_lib_cmap_iter_next res_lib_cmap_iter_next;
  541. cs_error_t ret;
  542. icmap_iter_t *iter;
  543. size_t value_len = 0;
  544. icmap_value_types_t type = 0;
  545. const char *res = NULL;
  546. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  547. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db,
  548. req_lib_cmap_iter_next->iter_handle, (void *)&iter));
  549. if (ret != CS_OK) {
  550. goto reply_send;
  551. }
  552. res = conn_info->map_fns.map_iter_next(*iter, &value_len, &type);
  553. if (res == NULL) {
  554. ret = CS_ERR_NO_SECTIONS;
  555. }
  556. (void)hdb_handle_put (&conn_info->iter_db, req_lib_cmap_iter_next->iter_handle);
  557. reply_send:
  558. memset(&res_lib_cmap_iter_next, 0, sizeof(res_lib_cmap_iter_next));
  559. res_lib_cmap_iter_next.header.size = sizeof(res_lib_cmap_iter_next);
  560. res_lib_cmap_iter_next.header.id = MESSAGE_RES_CMAP_ITER_NEXT;
  561. res_lib_cmap_iter_next.header.error = ret;
  562. if (res != NULL) {
  563. res_lib_cmap_iter_next.value_len = value_len;
  564. res_lib_cmap_iter_next.type = type;
  565. assert(strlen(res) <= sizeof(res_lib_cmap_iter_next.key_name.value));
  566. memcpy(res_lib_cmap_iter_next.key_name.value, res, strlen(res));
  567. res_lib_cmap_iter_next.key_name.length = strlen(res);
  568. }
  569. api->ipc_response_send(conn, &res_lib_cmap_iter_next, sizeof(res_lib_cmap_iter_next));
  570. }
  571. static void message_handler_req_lib_cmap_iter_finalize(void *conn, const void *message)
  572. {
  573. const struct req_lib_cmap_iter_finalize *req_lib_cmap_iter_finalize = message;
  574. struct res_lib_cmap_iter_finalize res_lib_cmap_iter_finalize;
  575. cs_error_t ret;
  576. icmap_iter_t *iter;
  577. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  578. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db,
  579. req_lib_cmap_iter_finalize->iter_handle, (void *)&iter));
  580. if (ret != CS_OK) {
  581. goto reply_send;
  582. }
  583. conn_info->map_fns.map_iter_finalize(*iter);
  584. (void)hdb_handle_destroy(&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  585. (void)hdb_handle_put (&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  586. reply_send:
  587. memset(&res_lib_cmap_iter_finalize, 0, sizeof(res_lib_cmap_iter_finalize));
  588. res_lib_cmap_iter_finalize.header.size = sizeof(res_lib_cmap_iter_finalize);
  589. res_lib_cmap_iter_finalize.header.id = MESSAGE_RES_CMAP_ITER_FINALIZE;
  590. res_lib_cmap_iter_finalize.header.error = ret;
  591. api->ipc_response_send(conn, &res_lib_cmap_iter_finalize, sizeof(res_lib_cmap_iter_finalize));
  592. }
  593. static void cmap_notify_fn(int32_t event,
  594. const char *key_name,
  595. struct icmap_notify_value new_val,
  596. struct icmap_notify_value old_val,
  597. void *user_data)
  598. {
  599. struct cmap_track_user_data *cmap_track_user_data = (struct cmap_track_user_data *)user_data;
  600. struct res_lib_cmap_notify_callback res_lib_cmap_notify_callback;
  601. struct iovec iov[3];
  602. memset(&res_lib_cmap_notify_callback, 0, sizeof(res_lib_cmap_notify_callback));
  603. res_lib_cmap_notify_callback.header.size = sizeof(res_lib_cmap_notify_callback) + new_val.len + old_val.len;
  604. res_lib_cmap_notify_callback.header.id = MESSAGE_RES_CMAP_NOTIFY_CALLBACK;
  605. res_lib_cmap_notify_callback.header.error = CS_OK;
  606. res_lib_cmap_notify_callback.new_value_type = new_val.type;
  607. res_lib_cmap_notify_callback.old_value_type = old_val.type;
  608. res_lib_cmap_notify_callback.new_value_len = new_val.len;
  609. res_lib_cmap_notify_callback.old_value_len = old_val.len;
  610. res_lib_cmap_notify_callback.event = event;
  611. res_lib_cmap_notify_callback.key_name.length = strlen(key_name);
  612. res_lib_cmap_notify_callback.track_inst_handle = cmap_track_user_data->track_inst_handle;
  613. assert(strlen(key_name) <= sizeof(res_lib_cmap_notify_callback.key_name.value));
  614. memcpy(res_lib_cmap_notify_callback.key_name.value, key_name, strlen(key_name));
  615. iov[0].iov_base = (char *)&res_lib_cmap_notify_callback;
  616. iov[0].iov_len = sizeof(res_lib_cmap_notify_callback);
  617. iov[1].iov_base = (char *)new_val.data;
  618. iov[1].iov_len = new_val.len;
  619. iov[2].iov_base = (char *)old_val.data;
  620. iov[2].iov_len = old_val.len;
  621. api->ipc_dispatch_iov_send(cmap_track_user_data->conn, iov, 3);
  622. }
  623. static void message_handler_req_lib_cmap_track_add(void *conn, const void *message)
  624. {
  625. const struct req_lib_cmap_track_add *req_lib_cmap_track_add = message;
  626. struct res_lib_cmap_track_add res_lib_cmap_track_add;
  627. cs_error_t ret;
  628. cmap_track_handle_t handle = 0;
  629. icmap_track_t track = NULL;
  630. icmap_track_t *hdb_track;
  631. struct cmap_track_user_data *cmap_track_user_data;
  632. const char *key_name;
  633. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  634. cmap_track_user_data = malloc(sizeof(*cmap_track_user_data));
  635. if (cmap_track_user_data == NULL) {
  636. ret = CS_ERR_NO_MEMORY;
  637. goto reply_send;
  638. }
  639. memset(cmap_track_user_data, 0, sizeof(*cmap_track_user_data));
  640. if (req_lib_cmap_track_add->key_name.length > 0) {
  641. key_name = (char *)req_lib_cmap_track_add->key_name.value;
  642. } else {
  643. key_name = NULL;
  644. }
  645. ret = conn_info->map_fns.map_track_add(key_name,
  646. req_lib_cmap_track_add->track_type,
  647. cmap_notify_fn,
  648. cmap_track_user_data,
  649. &track);
  650. if (ret != CS_OK) {
  651. free(cmap_track_user_data);
  652. goto reply_send;
  653. }
  654. ret = hdb_error_to_cs(hdb_handle_create(&conn_info->track_db, sizeof(track), &handle));
  655. if (ret != CS_OK) {
  656. free(cmap_track_user_data);
  657. goto reply_send;
  658. }
  659. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db, handle, (void *)&hdb_track));
  660. if (ret != CS_OK) {
  661. free(cmap_track_user_data);
  662. goto reply_send;
  663. }
  664. *hdb_track = track;
  665. cmap_track_user_data->conn = conn;
  666. cmap_track_user_data->track_handle = handle;
  667. cmap_track_user_data->track_inst_handle = req_lib_cmap_track_add->track_inst_handle;
  668. (void)hdb_handle_put (&conn_info->track_db, handle);
  669. reply_send:
  670. memset(&res_lib_cmap_track_add, 0, sizeof(res_lib_cmap_track_add));
  671. res_lib_cmap_track_add.header.size = sizeof(res_lib_cmap_track_add);
  672. res_lib_cmap_track_add.header.id = MESSAGE_RES_CMAP_TRACK_ADD;
  673. res_lib_cmap_track_add.header.error = ret;
  674. res_lib_cmap_track_add.track_handle = handle;
  675. api->ipc_response_send(conn, &res_lib_cmap_track_add, sizeof(res_lib_cmap_track_add));
  676. }
  677. static void message_handler_req_lib_cmap_track_delete(void *conn, const void *message)
  678. {
  679. const struct req_lib_cmap_track_delete *req_lib_cmap_track_delete = message;
  680. struct res_lib_cmap_track_delete res_lib_cmap_track_delete;
  681. cs_error_t ret;
  682. icmap_track_t *track;
  683. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  684. uint64_t track_inst_handle = 0;
  685. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db,
  686. req_lib_cmap_track_delete->track_handle, (void *)&track));
  687. if (ret != CS_OK) {
  688. goto reply_send;
  689. }
  690. track_inst_handle = ((struct cmap_track_user_data *)
  691. conn_info->map_fns.map_track_get_user_data(*track))->track_inst_handle;
  692. free(conn_info->map_fns.map_track_get_user_data(*track));
  693. ret = conn_info->map_fns.map_track_delete(*track);
  694. (void)hdb_handle_put (&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  695. (void)hdb_handle_destroy(&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  696. reply_send:
  697. memset(&res_lib_cmap_track_delete, 0, sizeof(res_lib_cmap_track_delete));
  698. res_lib_cmap_track_delete.header.size = sizeof(res_lib_cmap_track_delete);
  699. res_lib_cmap_track_delete.header.id = MESSAGE_RES_CMAP_TRACK_DELETE;
  700. res_lib_cmap_track_delete.header.error = ret;
  701. res_lib_cmap_track_delete.track_inst_handle = track_inst_handle;
  702. api->ipc_response_send(conn, &res_lib_cmap_track_delete, sizeof(res_lib_cmap_track_delete));
  703. }
  704. static void message_handler_req_lib_cmap_set_current_map(void *conn, const void *message)
  705. {
  706. const struct req_lib_cmap_set_current_map *req_lib_cmap_set_current_map = message;
  707. struct qb_ipc_response_header res;
  708. cs_error_t ret = CS_OK;
  709. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  710. int handles_open = 0;
  711. hdb_handle_t iter_handle = 0;
  712. icmap_iter_t *iter;
  713. hdb_handle_t track_handle = 0;
  714. icmap_track_t *track;
  715. /* Cannot switch maps while there are tracks or iterators active */
  716. hdb_iterator_reset(&conn_info->iter_db);
  717. while (hdb_iterator_next(&conn_info->iter_db,
  718. (void*)&iter, &iter_handle) == 0) {
  719. handles_open++;
  720. }
  721. hdb_iterator_reset(&conn_info->track_db);
  722. while (hdb_iterator_next(&conn_info->track_db,
  723. (void*)&track, &track_handle) == 0) {
  724. handles_open++;
  725. }
  726. if (handles_open) {
  727. ret = CS_ERR_BUSY;
  728. goto reply_send;
  729. }
  730. switch (req_lib_cmap_set_current_map->map) {
  731. case CMAP_SETMAP_DEFAULT:
  732. conn_info->map_fns = icmap_map;
  733. break;
  734. case CMAP_SETMAP_STATS:
  735. conn_info->map_fns = stats_map;
  736. break;
  737. default:
  738. ret = CS_ERR_NOT_EXIST;
  739. break;
  740. }
  741. reply_send:
  742. res.size = sizeof(res);
  743. res.id = MESSAGE_RES_CMAP_SET_CURRENT_MAP;
  744. res.error = ret;
  745. api->ipc_response_send(conn, &res, sizeof(res));
  746. }
  747. static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char *argv[])
  748. {
  749. int i;
  750. size_t value_len;
  751. icmap_value_types_t value_type;
  752. cs_error_t err;
  753. size_t item_len;
  754. size_t msg_len = 0;
  755. struct req_exec_cmap_mcast req_exec_cmap_mcast;
  756. struct req_exec_cmap_mcast_item *item = NULL;
  757. struct iovec req_exec_cmap_iovec[MAX_REQ_EXEC_CMAP_MCAST_ITEMS + 1];
  758. ENTER();
  759. if (argc > MAX_REQ_EXEC_CMAP_MCAST_ITEMS) {
  760. return (CS_ERR_TOO_MANY_GROUPS);
  761. }
  762. memset(req_exec_cmap_iovec, 0, sizeof(req_exec_cmap_iovec));
  763. for (i = 0; i < argc; i++) {
  764. err = icmap_get(argv[i], NULL, &value_len, &value_type);
  765. if (err != CS_OK && err != CS_ERR_NOT_EXIST) {
  766. goto free_mem;
  767. }
  768. if (err == CS_ERR_NOT_EXIST) {
  769. value_type = ICMAP_VALUETYPE_NOT_EXIST;
  770. value_len = 0;
  771. }
  772. item_len = MAR_ALIGN_UP(sizeof(*item) + value_len, 8);
  773. item = malloc(item_len);
  774. if (item == NULL) {
  775. goto free_mem;
  776. }
  777. memset(item, 0, item_len);
  778. item->value_type = value_type;
  779. item->value_len = value_len;
  780. item->key_name.length = strlen(argv[i]);
  781. assert(strlen(argv[i]) < sizeof(item->key_name.value));
  782. strcpy((char *)item->key_name.value, argv[i]);
  783. if (value_type != ICMAP_VALUETYPE_NOT_EXIST) {
  784. err = icmap_get(argv[i], item->value, &value_len, &value_type);
  785. if (err != CS_OK) {
  786. goto free_mem;
  787. }
  788. }
  789. req_exec_cmap_iovec[i + 1].iov_base = (char *)item;
  790. req_exec_cmap_iovec[i + 1].iov_len = item_len;
  791. msg_len += item_len;
  792. qb_log(LOG_TRACE, "Item %u - type %u, len %zu", i, item->value_type, item->value_len);
  793. item = NULL;
  794. }
  795. memset(&req_exec_cmap_mcast, 0, sizeof(req_exec_cmap_mcast));
  796. req_exec_cmap_mcast.header.size = sizeof(req_exec_cmap_mcast) + msg_len;
  797. req_exec_cmap_mcast.reason = reason;
  798. req_exec_cmap_mcast.no_items = argc;
  799. req_exec_cmap_iovec[0].iov_base = (char *)&req_exec_cmap_mcast;
  800. req_exec_cmap_iovec[0].iov_len = sizeof(req_exec_cmap_mcast);
  801. qb_log(LOG_TRACE, "Sending %u items (%u iovec) for reason %u", argc, argc + 1, reason);
  802. err = (api->totem_mcast(req_exec_cmap_iovec, argc + 1, TOTEM_AGREED) == 0 ? CS_OK : CS_ERR_MESSAGE_ERROR);
  803. free_mem:
  804. for (i = 0; i < argc; i++) {
  805. free(req_exec_cmap_iovec[i + 1].iov_base);
  806. }
  807. free(item);
  808. LEAVE();
  809. return (err);
  810. }
  811. static struct req_exec_cmap_mcast_item *cmap_mcast_item_find(
  812. const void *message,
  813. char *key)
  814. {
  815. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  816. int i;
  817. const char *p;
  818. struct req_exec_cmap_mcast_item *item;
  819. mar_uint16_t key_name_len;
  820. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  821. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  822. item = (struct req_exec_cmap_mcast_item *)p;
  823. key_name_len = item->key_name.length;
  824. if (strlen(key) == key_name_len && strcmp((char *)item->key_name.value, key) == 0) {
  825. return (item);
  826. }
  827. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  828. }
  829. return (NULL);
  830. }
  831. static void message_handler_req_exec_cmap_mcast_reason_sync_nv(
  832. enum cmap_mcast_reason reason,
  833. const void *message,
  834. unsigned int nodeid)
  835. {
  836. char member_config_version[ICMAP_KEYNAME_MAXLEN];
  837. uint64_t config_version = 0;
  838. struct req_exec_cmap_mcast_item *item;
  839. mar_size_t value_len;
  840. ENTER();
  841. item = cmap_mcast_item_find(message, (char *)"totem.config_version");
  842. if (item != NULL) {
  843. value_len = item->value_len;
  844. if (item->value_type == ICMAP_VALUETYPE_NOT_EXIST) {
  845. config_version = 0;
  846. }
  847. if (item->value_type == ICMAP_VALUETYPE_UINT64) {
  848. memcpy(&config_version, item->value, value_len);
  849. }
  850. }
  851. qb_log(LOG_TRACE, "Received config version %"PRIu64" from node " CS_PRI_NODE_ID, config_version, nodeid);
  852. if (nodeid != api->totem_nodeid_get() &&
  853. config_version > cmap_highest_config_version_received) {
  854. cmap_highest_config_version_received = config_version;
  855. }
  856. snprintf(member_config_version, ICMAP_KEYNAME_MAXLEN,
  857. "runtime.members.%u.config_version", nodeid);
  858. icmap_set_uint64(member_config_version, config_version);
  859. LEAVE();
  860. }
  861. static void message_handler_req_exec_cmap_mcast(
  862. const void *message,
  863. unsigned int nodeid)
  864. {
  865. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  866. ENTER();
  867. switch (req_exec_cmap_mcast->reason) {
  868. case CMAP_MCAST_REASON_SYNC:
  869. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  870. message, nodeid);
  871. break;
  872. case CMAP_MCAST_REASON_NEW_CONFIG_VERSION:
  873. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  874. message, nodeid);
  875. break;
  876. default:
  877. qb_log(LOG_TRACE, "Received mcast with unknown reason %u", req_exec_cmap_mcast->reason);
  878. };
  879. LEAVE();
  880. }
  881. static void exec_cmap_mcast_endian_convert(void *message)
  882. {
  883. struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  884. const char *p;
  885. int i;
  886. struct req_exec_cmap_mcast_item *item;
  887. uint16_t u16;
  888. uint32_t u32;
  889. uint64_t u64;
  890. float flt;
  891. double dbl;
  892. swab_coroipc_request_header_t(&req_exec_cmap_mcast->header);
  893. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  894. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  895. item = (struct req_exec_cmap_mcast_item *)p;
  896. swab_mar_uint16_t(&item->key_name.length);
  897. swab_mar_size_t(&item->value_len);
  898. switch (item->value_type) {
  899. case ICMAP_VALUETYPE_INT16:
  900. case ICMAP_VALUETYPE_UINT16:
  901. memcpy(&u16, item->value, sizeof(u16));
  902. u16 = swab16(u16);
  903. memcpy(item->value, &u16, sizeof(u16));
  904. break;
  905. case ICMAP_VALUETYPE_INT32:
  906. case ICMAP_VALUETYPE_UINT32:
  907. memcpy(&u32, item->value, sizeof(u32));
  908. u32 = swab32(u32);
  909. memcpy(item->value, &u32, sizeof(u32));
  910. break;
  911. case ICMAP_VALUETYPE_INT64:
  912. case ICMAP_VALUETYPE_UINT64:
  913. memcpy(&u64, item->value, sizeof(u64));
  914. u64 = swab64(u64);
  915. memcpy(item->value, &u64, sizeof(u64));
  916. break;
  917. case ICMAP_VALUETYPE_FLOAT:
  918. memcpy(&flt, item->value, sizeof(flt));
  919. swabflt(&flt);
  920. memcpy(item->value, &flt, sizeof(flt));
  921. break;
  922. case ICMAP_VALUETYPE_DOUBLE:
  923. memcpy(&dbl, item->value, sizeof(dbl));
  924. swabdbl(&dbl);
  925. memcpy(item->value, &dbl, sizeof(dbl));
  926. break;
  927. }
  928. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  929. }
  930. }