cmap.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  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. memcpy(res_lib_cmap_iter_next.key_name.value, res, strlen(res));
  566. res_lib_cmap_iter_next.key_name.length = strlen(res);
  567. }
  568. api->ipc_response_send(conn, &res_lib_cmap_iter_next, sizeof(res_lib_cmap_iter_next));
  569. }
  570. static void message_handler_req_lib_cmap_iter_finalize(void *conn, const void *message)
  571. {
  572. const struct req_lib_cmap_iter_finalize *req_lib_cmap_iter_finalize = message;
  573. struct res_lib_cmap_iter_finalize res_lib_cmap_iter_finalize;
  574. cs_error_t ret;
  575. icmap_iter_t *iter;
  576. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  577. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db,
  578. req_lib_cmap_iter_finalize->iter_handle, (void *)&iter));
  579. if (ret != CS_OK) {
  580. goto reply_send;
  581. }
  582. conn_info->map_fns.map_iter_finalize(*iter);
  583. (void)hdb_handle_destroy(&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  584. (void)hdb_handle_put (&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  585. reply_send:
  586. memset(&res_lib_cmap_iter_finalize, 0, sizeof(res_lib_cmap_iter_finalize));
  587. res_lib_cmap_iter_finalize.header.size = sizeof(res_lib_cmap_iter_finalize);
  588. res_lib_cmap_iter_finalize.header.id = MESSAGE_RES_CMAP_ITER_FINALIZE;
  589. res_lib_cmap_iter_finalize.header.error = ret;
  590. api->ipc_response_send(conn, &res_lib_cmap_iter_finalize, sizeof(res_lib_cmap_iter_finalize));
  591. }
  592. static void cmap_notify_fn(int32_t event,
  593. const char *key_name,
  594. struct icmap_notify_value new_val,
  595. struct icmap_notify_value old_val,
  596. void *user_data)
  597. {
  598. struct cmap_track_user_data *cmap_track_user_data = (struct cmap_track_user_data *)user_data;
  599. struct res_lib_cmap_notify_callback res_lib_cmap_notify_callback;
  600. struct iovec iov[3];
  601. memset(&res_lib_cmap_notify_callback, 0, sizeof(res_lib_cmap_notify_callback));
  602. res_lib_cmap_notify_callback.header.size = sizeof(res_lib_cmap_notify_callback) + new_val.len + old_val.len;
  603. res_lib_cmap_notify_callback.header.id = MESSAGE_RES_CMAP_NOTIFY_CALLBACK;
  604. res_lib_cmap_notify_callback.header.error = CS_OK;
  605. res_lib_cmap_notify_callback.new_value_type = new_val.type;
  606. res_lib_cmap_notify_callback.old_value_type = old_val.type;
  607. res_lib_cmap_notify_callback.new_value_len = new_val.len;
  608. res_lib_cmap_notify_callback.old_value_len = old_val.len;
  609. res_lib_cmap_notify_callback.event = event;
  610. res_lib_cmap_notify_callback.key_name.length = strlen(key_name);
  611. res_lib_cmap_notify_callback.track_inst_handle = cmap_track_user_data->track_inst_handle;
  612. memcpy(res_lib_cmap_notify_callback.key_name.value, key_name, strlen(key_name));
  613. iov[0].iov_base = (char *)&res_lib_cmap_notify_callback;
  614. iov[0].iov_len = sizeof(res_lib_cmap_notify_callback);
  615. iov[1].iov_base = (char *)new_val.data;
  616. iov[1].iov_len = new_val.len;
  617. iov[2].iov_base = (char *)old_val.data;
  618. iov[2].iov_len = old_val.len;
  619. api->ipc_dispatch_iov_send(cmap_track_user_data->conn, iov, 3);
  620. }
  621. static void message_handler_req_lib_cmap_track_add(void *conn, const void *message)
  622. {
  623. const struct req_lib_cmap_track_add *req_lib_cmap_track_add = message;
  624. struct res_lib_cmap_track_add res_lib_cmap_track_add;
  625. cs_error_t ret;
  626. cmap_track_handle_t handle = 0;
  627. icmap_track_t track = NULL;
  628. icmap_track_t *hdb_track;
  629. struct cmap_track_user_data *cmap_track_user_data;
  630. const char *key_name;
  631. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  632. cmap_track_user_data = malloc(sizeof(*cmap_track_user_data));
  633. if (cmap_track_user_data == NULL) {
  634. ret = CS_ERR_NO_MEMORY;
  635. goto reply_send;
  636. }
  637. memset(cmap_track_user_data, 0, sizeof(*cmap_track_user_data));
  638. if (req_lib_cmap_track_add->key_name.length > 0) {
  639. key_name = (char *)req_lib_cmap_track_add->key_name.value;
  640. } else {
  641. key_name = NULL;
  642. }
  643. ret = conn_info->map_fns.map_track_add(key_name,
  644. req_lib_cmap_track_add->track_type,
  645. cmap_notify_fn,
  646. cmap_track_user_data,
  647. &track);
  648. if (ret != CS_OK) {
  649. free(cmap_track_user_data);
  650. goto reply_send;
  651. }
  652. ret = hdb_error_to_cs(hdb_handle_create(&conn_info->track_db, sizeof(track), &handle));
  653. if (ret != CS_OK) {
  654. free(cmap_track_user_data);
  655. goto reply_send;
  656. }
  657. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db, handle, (void *)&hdb_track));
  658. if (ret != CS_OK) {
  659. free(cmap_track_user_data);
  660. goto reply_send;
  661. }
  662. *hdb_track = track;
  663. cmap_track_user_data->conn = conn;
  664. cmap_track_user_data->track_handle = handle;
  665. cmap_track_user_data->track_inst_handle = req_lib_cmap_track_add->track_inst_handle;
  666. (void)hdb_handle_put (&conn_info->track_db, handle);
  667. reply_send:
  668. memset(&res_lib_cmap_track_add, 0, sizeof(res_lib_cmap_track_add));
  669. res_lib_cmap_track_add.header.size = sizeof(res_lib_cmap_track_add);
  670. res_lib_cmap_track_add.header.id = MESSAGE_RES_CMAP_TRACK_ADD;
  671. res_lib_cmap_track_add.header.error = ret;
  672. res_lib_cmap_track_add.track_handle = handle;
  673. api->ipc_response_send(conn, &res_lib_cmap_track_add, sizeof(res_lib_cmap_track_add));
  674. }
  675. static void message_handler_req_lib_cmap_track_delete(void *conn, const void *message)
  676. {
  677. const struct req_lib_cmap_track_delete *req_lib_cmap_track_delete = message;
  678. struct res_lib_cmap_track_delete res_lib_cmap_track_delete;
  679. cs_error_t ret;
  680. icmap_track_t *track;
  681. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  682. uint64_t track_inst_handle = 0;
  683. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db,
  684. req_lib_cmap_track_delete->track_handle, (void *)&track));
  685. if (ret != CS_OK) {
  686. goto reply_send;
  687. }
  688. track_inst_handle = ((struct cmap_track_user_data *)icmap_track_get_user_data(*track))->track_inst_handle;
  689. free(conn_info->map_fns.map_track_get_user_data(*track));
  690. ret = conn_info->map_fns.map_track_delete(*track);
  691. (void)hdb_handle_put (&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  692. (void)hdb_handle_destroy(&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  693. reply_send:
  694. memset(&res_lib_cmap_track_delete, 0, sizeof(res_lib_cmap_track_delete));
  695. res_lib_cmap_track_delete.header.size = sizeof(res_lib_cmap_track_delete);
  696. res_lib_cmap_track_delete.header.id = MESSAGE_RES_CMAP_TRACK_DELETE;
  697. res_lib_cmap_track_delete.header.error = ret;
  698. res_lib_cmap_track_delete.track_inst_handle = track_inst_handle;
  699. api->ipc_response_send(conn, &res_lib_cmap_track_delete, sizeof(res_lib_cmap_track_delete));
  700. }
  701. static void message_handler_req_lib_cmap_set_current_map(void *conn, const void *message)
  702. {
  703. const struct req_lib_cmap_set_current_map *req_lib_cmap_set_current_map = message;
  704. struct qb_ipc_response_header res;
  705. cs_error_t ret = CS_OK;
  706. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  707. int handles_open = 0;
  708. hdb_handle_t iter_handle = 0;
  709. icmap_iter_t *iter;
  710. hdb_handle_t track_handle = 0;
  711. icmap_track_t *track;
  712. /* Cannot switch maps while there are tracks or iterators active */
  713. hdb_iterator_reset(&conn_info->iter_db);
  714. while (hdb_iterator_next(&conn_info->iter_db,
  715. (void*)&iter, &iter_handle) == 0) {
  716. handles_open++;
  717. }
  718. hdb_iterator_reset(&conn_info->track_db);
  719. while (hdb_iterator_next(&conn_info->track_db,
  720. (void*)&track, &track_handle) == 0) {
  721. handles_open++;
  722. }
  723. if (handles_open) {
  724. ret = CS_ERR_BUSY;
  725. goto reply_send;
  726. }
  727. switch (req_lib_cmap_set_current_map->map) {
  728. case CMAP_SETMAP_DEFAULT:
  729. conn_info->map_fns = icmap_map;
  730. break;
  731. case CMAP_SETMAP_STATS:
  732. conn_info->map_fns = stats_map;
  733. break;
  734. default:
  735. ret = CS_ERR_NOT_EXIST;
  736. break;
  737. }
  738. reply_send:
  739. res.size = sizeof(res);
  740. res.id = MESSAGE_RES_CMAP_SET_CURRENT_MAP;
  741. res.error = ret;
  742. api->ipc_response_send(conn, &res, sizeof(res));
  743. }
  744. static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char *argv[])
  745. {
  746. int i;
  747. size_t value_len;
  748. icmap_value_types_t value_type;
  749. cs_error_t err;
  750. size_t item_len;
  751. size_t msg_len = 0;
  752. struct req_exec_cmap_mcast req_exec_cmap_mcast;
  753. struct req_exec_cmap_mcast_item *item = NULL;
  754. struct iovec req_exec_cmap_iovec[MAX_REQ_EXEC_CMAP_MCAST_ITEMS + 1];
  755. ENTER();
  756. if (argc > MAX_REQ_EXEC_CMAP_MCAST_ITEMS) {
  757. return (CS_ERR_TOO_MANY_GROUPS);
  758. }
  759. memset(req_exec_cmap_iovec, 0, sizeof(req_exec_cmap_iovec));
  760. for (i = 0; i < argc; i++) {
  761. err = icmap_get(argv[i], NULL, &value_len, &value_type);
  762. if (err != CS_OK && err != CS_ERR_NOT_EXIST) {
  763. goto free_mem;
  764. }
  765. if (err == CS_ERR_NOT_EXIST) {
  766. value_type = ICMAP_VALUETYPE_NOT_EXIST;
  767. value_len = 0;
  768. }
  769. item_len = MAR_ALIGN_UP(sizeof(*item) + value_len, 8);
  770. item = malloc(item_len);
  771. if (item == NULL) {
  772. goto free_mem;
  773. }
  774. memset(item, 0, item_len);
  775. item->value_type = value_type;
  776. item->value_len = value_len;
  777. item->key_name.length = strlen(argv[i]);
  778. strcpy((char *)item->key_name.value, argv[i]);
  779. if (value_type != ICMAP_VALUETYPE_NOT_EXIST) {
  780. err = icmap_get(argv[i], item->value, &value_len, &value_type);
  781. if (err != CS_OK) {
  782. goto free_mem;
  783. }
  784. }
  785. req_exec_cmap_iovec[i + 1].iov_base = item;
  786. req_exec_cmap_iovec[i + 1].iov_len = item_len;
  787. msg_len += item_len;
  788. qb_log(LOG_TRACE, "Item %u - type %u, len %zu", i, item->value_type, item->value_len);
  789. item = NULL;
  790. }
  791. memset(&req_exec_cmap_mcast, 0, sizeof(req_exec_cmap_mcast));
  792. req_exec_cmap_mcast.header.size = sizeof(req_exec_cmap_mcast) + msg_len;
  793. req_exec_cmap_mcast.reason = reason;
  794. req_exec_cmap_mcast.no_items = argc;
  795. req_exec_cmap_iovec[0].iov_base = &req_exec_cmap_mcast;
  796. req_exec_cmap_iovec[0].iov_len = sizeof(req_exec_cmap_mcast);
  797. qb_log(LOG_TRACE, "Sending %u items (%u iovec) for reason %u", argc, argc + 1, reason);
  798. err = (api->totem_mcast(req_exec_cmap_iovec, argc + 1, TOTEM_AGREED) == 0 ? CS_OK : CS_ERR_MESSAGE_ERROR);
  799. free_mem:
  800. for (i = 0; i < argc; i++) {
  801. free(req_exec_cmap_iovec[i + 1].iov_base);
  802. }
  803. free(item);
  804. LEAVE();
  805. return (err);
  806. }
  807. static struct req_exec_cmap_mcast_item *cmap_mcast_item_find(
  808. const void *message,
  809. char *key)
  810. {
  811. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  812. int i;
  813. const char *p;
  814. struct req_exec_cmap_mcast_item *item;
  815. mar_uint16_t key_name_len;
  816. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  817. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  818. item = (struct req_exec_cmap_mcast_item *)p;
  819. key_name_len = item->key_name.length;
  820. if (strlen(key) == key_name_len && strcmp((char *)item->key_name.value, key) == 0) {
  821. return (item);
  822. }
  823. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  824. }
  825. return (NULL);
  826. }
  827. static void message_handler_req_exec_cmap_mcast_reason_sync_nv(
  828. enum cmap_mcast_reason reason,
  829. const void *message,
  830. unsigned int nodeid)
  831. {
  832. char member_config_version[ICMAP_KEYNAME_MAXLEN];
  833. uint64_t config_version = 0;
  834. struct req_exec_cmap_mcast_item *item;
  835. mar_size_t value_len;
  836. ENTER();
  837. item = cmap_mcast_item_find(message, (char *)"totem.config_version");
  838. if (item != NULL) {
  839. value_len = item->value_len;
  840. if (item->value_type == ICMAP_VALUETYPE_NOT_EXIST) {
  841. config_version = 0;
  842. }
  843. if (item->value_type == ICMAP_VALUETYPE_UINT64) {
  844. memcpy(&config_version, item->value, value_len);
  845. }
  846. }
  847. qb_log(LOG_TRACE, "Received config version %"PRIu64" from node %x", config_version, nodeid);
  848. if (nodeid != api->totem_nodeid_get() &&
  849. config_version > cmap_highest_config_version_received) {
  850. cmap_highest_config_version_received = config_version;
  851. }
  852. snprintf(member_config_version, ICMAP_KEYNAME_MAXLEN,
  853. "runtime.members.%u.config_version", nodeid);
  854. icmap_set_uint64(member_config_version, config_version);
  855. LEAVE();
  856. }
  857. static void message_handler_req_exec_cmap_mcast(
  858. const void *message,
  859. unsigned int nodeid)
  860. {
  861. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  862. ENTER();
  863. switch (req_exec_cmap_mcast->reason) {
  864. case CMAP_MCAST_REASON_SYNC:
  865. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  866. message, nodeid);
  867. break;
  868. case CMAP_MCAST_REASON_NEW_CONFIG_VERSION:
  869. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  870. message, nodeid);
  871. break;
  872. default:
  873. qb_log(LOG_TRACE, "Received mcast with unknown reason %u", req_exec_cmap_mcast->reason);
  874. };
  875. LEAVE();
  876. }
  877. static void exec_cmap_mcast_endian_convert(void *message)
  878. {
  879. struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  880. const char *p;
  881. int i;
  882. struct req_exec_cmap_mcast_item *item;
  883. uint16_t u16;
  884. uint32_t u32;
  885. uint64_t u64;
  886. float flt;
  887. double dbl;
  888. swab_coroipc_request_header_t(&req_exec_cmap_mcast->header);
  889. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  890. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  891. item = (struct req_exec_cmap_mcast_item *)p;
  892. swab_mar_uint16_t(&item->key_name.length);
  893. swab_mar_size_t(&item->value_len);
  894. switch (item->value_type) {
  895. case ICMAP_VALUETYPE_INT16:
  896. case ICMAP_VALUETYPE_UINT16:
  897. memcpy(&u16, item->value, sizeof(u16));
  898. u16 = swab16(u16);
  899. memcpy(item->value, &u16, sizeof(u16));
  900. break;
  901. case ICMAP_VALUETYPE_INT32:
  902. case ICMAP_VALUETYPE_UINT32:
  903. memcpy(&u32, item->value, sizeof(u32));
  904. u32 = swab32(u32);
  905. memcpy(item->value, &u32, sizeof(u32));
  906. break;
  907. case ICMAP_VALUETYPE_INT64:
  908. case ICMAP_VALUETYPE_UINT64:
  909. memcpy(&u64, item->value, sizeof(u64));
  910. u64 = swab64(u64);
  911. memcpy(item->value, &u64, sizeof(u64));
  912. break;
  913. case ICMAP_VALUETYPE_FLOAT:
  914. memcpy(&flt, item->value, sizeof(flt));
  915. swabflt(&flt);
  916. memcpy(item->value, &flt, sizeof(flt));
  917. break;
  918. case ICMAP_VALUETYPE_DOUBLE:
  919. memcpy(&dbl, item->value, sizeof(dbl));
  920. swabdbl(&dbl);
  921. memcpy(item->value, &dbl, sizeof(dbl));
  922. break;
  923. }
  924. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  925. }
  926. }