cmap.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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 == 0) {
  389. log_printf(LOGSYS_LEVEL_DEBUG, "Other nodes version is 0 -> no action");
  390. return ;
  391. }
  392. if (cmap_highest_config_version_received != cmap_my_config_version) {
  393. log_printf(LOGSYS_LEVEL_ERROR,
  394. "Received config version (%"PRIu64") is different than my config version (%"PRIu64")! Exiting",
  395. cmap_highest_config_version_received, cmap_my_config_version);
  396. api->shutdown_request();
  397. return ;
  398. }
  399. }
  400. static void cmap_sync_abort (void)
  401. {
  402. }
  403. static void message_handler_req_lib_cmap_set(void *conn, const void *message)
  404. {
  405. const struct req_lib_cmap_set *req_lib_cmap_set = message;
  406. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  407. struct res_lib_cmap_set res_lib_cmap_set;
  408. cs_error_t ret;
  409. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_set->key_name.value)) {
  410. ret = CS_ERR_ACCESS;
  411. } else {
  412. ret = conn_info->map_fns.map_set((char *)req_lib_cmap_set->key_name.value, &req_lib_cmap_set->value,
  413. req_lib_cmap_set->value_len, req_lib_cmap_set->type);
  414. }
  415. memset(&res_lib_cmap_set, 0, sizeof(res_lib_cmap_set));
  416. res_lib_cmap_set.header.size = sizeof(res_lib_cmap_set);
  417. res_lib_cmap_set.header.id = MESSAGE_RES_CMAP_SET;
  418. res_lib_cmap_set.header.error = ret;
  419. api->ipc_response_send(conn, &res_lib_cmap_set, sizeof(res_lib_cmap_set));
  420. }
  421. static void message_handler_req_lib_cmap_delete(void *conn, const void *message)
  422. {
  423. const struct req_lib_cmap_set *req_lib_cmap_set = message;
  424. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  425. struct res_lib_cmap_delete res_lib_cmap_delete;
  426. cs_error_t ret;
  427. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_set->key_name.value)) {
  428. ret = CS_ERR_ACCESS;
  429. } else {
  430. ret = conn_info->map_fns.map_delete((char *)req_lib_cmap_set->key_name.value);
  431. }
  432. memset(&res_lib_cmap_delete, 0, sizeof(res_lib_cmap_delete));
  433. res_lib_cmap_delete.header.size = sizeof(res_lib_cmap_delete);
  434. res_lib_cmap_delete.header.id = MESSAGE_RES_CMAP_DELETE;
  435. res_lib_cmap_delete.header.error = ret;
  436. api->ipc_response_send(conn, &res_lib_cmap_delete, sizeof(res_lib_cmap_delete));
  437. }
  438. static void message_handler_req_lib_cmap_get(void *conn, const void *message)
  439. {
  440. const struct req_lib_cmap_get *req_lib_cmap_get = message;
  441. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  442. struct res_lib_cmap_get *res_lib_cmap_get;
  443. struct res_lib_cmap_get error_res_lib_cmap_get;
  444. cs_error_t ret;
  445. size_t value_len;
  446. size_t res_lib_cmap_get_size;
  447. icmap_value_types_t type;
  448. void *value;
  449. value_len = req_lib_cmap_get->value_len;
  450. res_lib_cmap_get_size = sizeof(*res_lib_cmap_get) + value_len;
  451. res_lib_cmap_get = malloc(res_lib_cmap_get_size);
  452. if (res_lib_cmap_get == NULL) {
  453. ret = CS_ERR_NO_MEMORY;
  454. goto error_exit;
  455. }
  456. memset(res_lib_cmap_get, 0, res_lib_cmap_get_size);
  457. if (value_len > 0) {
  458. value = res_lib_cmap_get->value;
  459. } else {
  460. value = NULL;
  461. }
  462. ret = conn_info->map_fns.map_get((char *)req_lib_cmap_get->key_name.value,
  463. value,
  464. &value_len,
  465. &type);
  466. if (ret != CS_OK) {
  467. free(res_lib_cmap_get);
  468. goto error_exit;
  469. }
  470. res_lib_cmap_get->header.size = res_lib_cmap_get_size;
  471. res_lib_cmap_get->header.id = MESSAGE_RES_CMAP_GET;
  472. res_lib_cmap_get->header.error = ret;
  473. res_lib_cmap_get->type = type;
  474. res_lib_cmap_get->value_len = value_len;
  475. api->ipc_response_send(conn, res_lib_cmap_get, res_lib_cmap_get_size);
  476. free(res_lib_cmap_get);
  477. return ;
  478. error_exit:
  479. memset(&error_res_lib_cmap_get, 0, sizeof(error_res_lib_cmap_get));
  480. error_res_lib_cmap_get.header.size = sizeof(error_res_lib_cmap_get);
  481. error_res_lib_cmap_get.header.id = MESSAGE_RES_CMAP_GET;
  482. error_res_lib_cmap_get.header.error = ret;
  483. api->ipc_response_send(conn, &error_res_lib_cmap_get, sizeof(error_res_lib_cmap_get));
  484. }
  485. static void message_handler_req_lib_cmap_adjust_int(void *conn, const void *message)
  486. {
  487. const struct req_lib_cmap_adjust_int *req_lib_cmap_adjust_int = message;
  488. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  489. struct res_lib_cmap_adjust_int res_lib_cmap_adjust_int;
  490. cs_error_t ret;
  491. if (conn_info->map_fns.map_is_key_ro((char *)req_lib_cmap_adjust_int->key_name.value)) {
  492. ret = CS_ERR_ACCESS;
  493. } else {
  494. ret = conn_info->map_fns.map_adjust_int((char *)req_lib_cmap_adjust_int->key_name.value,
  495. req_lib_cmap_adjust_int->step);
  496. }
  497. memset(&res_lib_cmap_adjust_int, 0, sizeof(res_lib_cmap_adjust_int));
  498. res_lib_cmap_adjust_int.header.size = sizeof(res_lib_cmap_adjust_int);
  499. res_lib_cmap_adjust_int.header.id = MESSAGE_RES_CMAP_ADJUST_INT;
  500. res_lib_cmap_adjust_int.header.error = ret;
  501. api->ipc_response_send(conn, &res_lib_cmap_adjust_int, sizeof(res_lib_cmap_adjust_int));
  502. }
  503. static void message_handler_req_lib_cmap_iter_init(void *conn, const void *message)
  504. {
  505. const struct req_lib_cmap_iter_init *req_lib_cmap_iter_init = message;
  506. struct res_lib_cmap_iter_init res_lib_cmap_iter_init;
  507. cs_error_t ret;
  508. icmap_iter_t iter;
  509. icmap_iter_t *hdb_iter;
  510. cmap_iter_handle_t handle = 0ULL;
  511. const char *prefix;
  512. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  513. if (req_lib_cmap_iter_init->prefix.length > 0) {
  514. prefix = (char *)req_lib_cmap_iter_init->prefix.value;
  515. } else {
  516. prefix = NULL;
  517. }
  518. iter = conn_info->map_fns.map_iter_init(prefix);
  519. if (iter == NULL) {
  520. ret = CS_ERR_NO_SECTIONS;
  521. goto reply_send;
  522. }
  523. ret = hdb_error_to_cs(hdb_handle_create(&conn_info->iter_db, sizeof(iter), &handle));
  524. if (ret != CS_OK) {
  525. goto reply_send;
  526. }
  527. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db, handle, (void *)&hdb_iter));
  528. if (ret != CS_OK) {
  529. goto reply_send;
  530. }
  531. *hdb_iter = iter;
  532. (void)hdb_handle_put (&conn_info->iter_db, handle);
  533. reply_send:
  534. memset(&res_lib_cmap_iter_init, 0, sizeof(res_lib_cmap_iter_init));
  535. res_lib_cmap_iter_init.header.size = sizeof(res_lib_cmap_iter_init);
  536. res_lib_cmap_iter_init.header.id = MESSAGE_RES_CMAP_ITER_INIT;
  537. res_lib_cmap_iter_init.header.error = ret;
  538. res_lib_cmap_iter_init.iter_handle = handle;
  539. api->ipc_response_send(conn, &res_lib_cmap_iter_init, sizeof(res_lib_cmap_iter_init));
  540. }
  541. static void message_handler_req_lib_cmap_iter_next(void *conn, const void *message)
  542. {
  543. const struct req_lib_cmap_iter_next *req_lib_cmap_iter_next = message;
  544. struct res_lib_cmap_iter_next res_lib_cmap_iter_next;
  545. cs_error_t ret;
  546. icmap_iter_t *iter;
  547. size_t value_len = 0;
  548. icmap_value_types_t type = 0;
  549. const char *res = NULL;
  550. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  551. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db,
  552. req_lib_cmap_iter_next->iter_handle, (void *)&iter));
  553. if (ret != CS_OK) {
  554. goto reply_send;
  555. }
  556. res = conn_info->map_fns.map_iter_next(*iter, &value_len, &type);
  557. if (res == NULL) {
  558. ret = CS_ERR_NO_SECTIONS;
  559. }
  560. (void)hdb_handle_put (&conn_info->iter_db, req_lib_cmap_iter_next->iter_handle);
  561. reply_send:
  562. memset(&res_lib_cmap_iter_next, 0, sizeof(res_lib_cmap_iter_next));
  563. res_lib_cmap_iter_next.header.size = sizeof(res_lib_cmap_iter_next);
  564. res_lib_cmap_iter_next.header.id = MESSAGE_RES_CMAP_ITER_NEXT;
  565. res_lib_cmap_iter_next.header.error = ret;
  566. if (res != NULL) {
  567. res_lib_cmap_iter_next.value_len = value_len;
  568. res_lib_cmap_iter_next.type = type;
  569. memcpy(res_lib_cmap_iter_next.key_name.value, res, strlen(res));
  570. res_lib_cmap_iter_next.key_name.length = strlen(res);
  571. }
  572. api->ipc_response_send(conn, &res_lib_cmap_iter_next, sizeof(res_lib_cmap_iter_next));
  573. }
  574. static void message_handler_req_lib_cmap_iter_finalize(void *conn, const void *message)
  575. {
  576. const struct req_lib_cmap_iter_finalize *req_lib_cmap_iter_finalize = message;
  577. struct res_lib_cmap_iter_finalize res_lib_cmap_iter_finalize;
  578. cs_error_t ret;
  579. icmap_iter_t *iter;
  580. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  581. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->iter_db,
  582. req_lib_cmap_iter_finalize->iter_handle, (void *)&iter));
  583. if (ret != CS_OK) {
  584. goto reply_send;
  585. }
  586. conn_info->map_fns.map_iter_finalize(*iter);
  587. (void)hdb_handle_destroy(&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  588. (void)hdb_handle_put (&conn_info->iter_db, req_lib_cmap_iter_finalize->iter_handle);
  589. reply_send:
  590. memset(&res_lib_cmap_iter_finalize, 0, sizeof(res_lib_cmap_iter_finalize));
  591. res_lib_cmap_iter_finalize.header.size = sizeof(res_lib_cmap_iter_finalize);
  592. res_lib_cmap_iter_finalize.header.id = MESSAGE_RES_CMAP_ITER_FINALIZE;
  593. res_lib_cmap_iter_finalize.header.error = ret;
  594. api->ipc_response_send(conn, &res_lib_cmap_iter_finalize, sizeof(res_lib_cmap_iter_finalize));
  595. }
  596. static void cmap_notify_fn(int32_t event,
  597. const char *key_name,
  598. struct icmap_notify_value new_val,
  599. struct icmap_notify_value old_val,
  600. void *user_data)
  601. {
  602. struct cmap_track_user_data *cmap_track_user_data = (struct cmap_track_user_data *)user_data;
  603. struct res_lib_cmap_notify_callback res_lib_cmap_notify_callback;
  604. struct iovec iov[3];
  605. memset(&res_lib_cmap_notify_callback, 0, sizeof(res_lib_cmap_notify_callback));
  606. res_lib_cmap_notify_callback.header.size = sizeof(res_lib_cmap_notify_callback) + new_val.len + old_val.len;
  607. res_lib_cmap_notify_callback.header.id = MESSAGE_RES_CMAP_NOTIFY_CALLBACK;
  608. res_lib_cmap_notify_callback.header.error = CS_OK;
  609. res_lib_cmap_notify_callback.new_value_type = new_val.type;
  610. res_lib_cmap_notify_callback.old_value_type = old_val.type;
  611. res_lib_cmap_notify_callback.new_value_len = new_val.len;
  612. res_lib_cmap_notify_callback.old_value_len = old_val.len;
  613. res_lib_cmap_notify_callback.event = event;
  614. res_lib_cmap_notify_callback.key_name.length = strlen(key_name);
  615. res_lib_cmap_notify_callback.track_inst_handle = cmap_track_user_data->track_inst_handle;
  616. memcpy(res_lib_cmap_notify_callback.key_name.value, key_name, strlen(key_name));
  617. iov[0].iov_base = (char *)&res_lib_cmap_notify_callback;
  618. iov[0].iov_len = sizeof(res_lib_cmap_notify_callback);
  619. iov[1].iov_base = (char *)new_val.data;
  620. iov[1].iov_len = new_val.len;
  621. iov[2].iov_base = (char *)old_val.data;
  622. iov[2].iov_len = old_val.len;
  623. api->ipc_dispatch_iov_send(cmap_track_user_data->conn, iov, 3);
  624. }
  625. static void message_handler_req_lib_cmap_track_add(void *conn, const void *message)
  626. {
  627. const struct req_lib_cmap_track_add *req_lib_cmap_track_add = message;
  628. struct res_lib_cmap_track_add res_lib_cmap_track_add;
  629. cs_error_t ret;
  630. cmap_track_handle_t handle = 0;
  631. icmap_track_t track = NULL;
  632. icmap_track_t *hdb_track;
  633. struct cmap_track_user_data *cmap_track_user_data;
  634. const char *key_name;
  635. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  636. cmap_track_user_data = malloc(sizeof(*cmap_track_user_data));
  637. if (cmap_track_user_data == NULL) {
  638. ret = CS_ERR_NO_MEMORY;
  639. goto reply_send;
  640. }
  641. memset(cmap_track_user_data, 0, sizeof(*cmap_track_user_data));
  642. if (req_lib_cmap_track_add->key_name.length > 0) {
  643. key_name = (char *)req_lib_cmap_track_add->key_name.value;
  644. } else {
  645. key_name = NULL;
  646. }
  647. ret = conn_info->map_fns.map_track_add(key_name,
  648. req_lib_cmap_track_add->track_type,
  649. cmap_notify_fn,
  650. cmap_track_user_data,
  651. &track);
  652. if (ret != CS_OK) {
  653. free(cmap_track_user_data);
  654. goto reply_send;
  655. }
  656. ret = hdb_error_to_cs(hdb_handle_create(&conn_info->track_db, sizeof(track), &handle));
  657. if (ret != CS_OK) {
  658. free(cmap_track_user_data);
  659. goto reply_send;
  660. }
  661. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db, handle, (void *)&hdb_track));
  662. if (ret != CS_OK) {
  663. free(cmap_track_user_data);
  664. goto reply_send;
  665. }
  666. *hdb_track = track;
  667. cmap_track_user_data->conn = conn;
  668. cmap_track_user_data->track_handle = handle;
  669. cmap_track_user_data->track_inst_handle = req_lib_cmap_track_add->track_inst_handle;
  670. (void)hdb_handle_put (&conn_info->track_db, handle);
  671. reply_send:
  672. memset(&res_lib_cmap_track_add, 0, sizeof(res_lib_cmap_track_add));
  673. res_lib_cmap_track_add.header.size = sizeof(res_lib_cmap_track_add);
  674. res_lib_cmap_track_add.header.id = MESSAGE_RES_CMAP_TRACK_ADD;
  675. res_lib_cmap_track_add.header.error = ret;
  676. res_lib_cmap_track_add.track_handle = handle;
  677. api->ipc_response_send(conn, &res_lib_cmap_track_add, sizeof(res_lib_cmap_track_add));
  678. }
  679. static void message_handler_req_lib_cmap_track_delete(void *conn, const void *message)
  680. {
  681. const struct req_lib_cmap_track_delete *req_lib_cmap_track_delete = message;
  682. struct res_lib_cmap_track_delete res_lib_cmap_track_delete;
  683. cs_error_t ret;
  684. icmap_track_t *track;
  685. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  686. uint64_t track_inst_handle = 0;
  687. ret = hdb_error_to_cs(hdb_handle_get(&conn_info->track_db,
  688. req_lib_cmap_track_delete->track_handle, (void *)&track));
  689. if (ret != CS_OK) {
  690. goto reply_send;
  691. }
  692. track_inst_handle = ((struct cmap_track_user_data *)icmap_track_get_user_data(*track))->track_inst_handle;
  693. free(conn_info->map_fns.map_track_get_user_data(*track));
  694. ret = conn_info->map_fns.map_track_delete(*track);
  695. (void)hdb_handle_put (&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  696. (void)hdb_handle_destroy(&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  697. reply_send:
  698. memset(&res_lib_cmap_track_delete, 0, sizeof(res_lib_cmap_track_delete));
  699. res_lib_cmap_track_delete.header.size = sizeof(res_lib_cmap_track_delete);
  700. res_lib_cmap_track_delete.header.id = MESSAGE_RES_CMAP_TRACK_DELETE;
  701. res_lib_cmap_track_delete.header.error = ret;
  702. res_lib_cmap_track_delete.track_inst_handle = track_inst_handle;
  703. api->ipc_response_send(conn, &res_lib_cmap_track_delete, sizeof(res_lib_cmap_track_delete));
  704. }
  705. static void message_handler_req_lib_cmap_set_current_map(void *conn, const void *message)
  706. {
  707. const struct req_lib_cmap_set_current_map *req_lib_cmap_set_current_map = message;
  708. struct qb_ipc_response_header res;
  709. cs_error_t ret = CS_OK;
  710. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  711. int handles_open = 0;
  712. hdb_handle_t iter_handle = 0;
  713. icmap_iter_t *iter;
  714. hdb_handle_t track_handle = 0;
  715. icmap_track_t *track;
  716. /* Cannot switch maps while there are tracks or iterators active */
  717. hdb_iterator_reset(&conn_info->iter_db);
  718. while (hdb_iterator_next(&conn_info->iter_db,
  719. (void*)&iter, &iter_handle) == 0) {
  720. handles_open++;
  721. }
  722. hdb_iterator_reset(&conn_info->track_db);
  723. while (hdb_iterator_next(&conn_info->track_db,
  724. (void*)&track, &track_handle) == 0) {
  725. handles_open++;
  726. }
  727. if (handles_open) {
  728. ret = CS_ERR_BUSY;
  729. goto reply_send;
  730. }
  731. switch (req_lib_cmap_set_current_map->map) {
  732. case CMAP_SETMAP_DEFAULT:
  733. conn_info->map_fns = icmap_map;
  734. break;
  735. case CMAP_SETMAP_STATS:
  736. conn_info->map_fns = stats_map;
  737. break;
  738. default:
  739. ret = CS_ERR_NOT_EXIST;
  740. break;
  741. }
  742. reply_send:
  743. res.size = sizeof(res);
  744. res.id = MESSAGE_RES_CMAP_SET_CURRENT_MAP;
  745. res.error = ret;
  746. api->ipc_response_send(conn, &res, sizeof(res));
  747. }
  748. static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char *argv[])
  749. {
  750. int i;
  751. size_t value_len;
  752. icmap_value_types_t value_type;
  753. cs_error_t err;
  754. size_t item_len;
  755. size_t msg_len = 0;
  756. struct req_exec_cmap_mcast req_exec_cmap_mcast;
  757. struct req_exec_cmap_mcast_item *item = NULL;
  758. struct iovec req_exec_cmap_iovec[MAX_REQ_EXEC_CMAP_MCAST_ITEMS + 1];
  759. ENTER();
  760. if (argc > MAX_REQ_EXEC_CMAP_MCAST_ITEMS) {
  761. return (CS_ERR_TOO_MANY_GROUPS);
  762. }
  763. memset(req_exec_cmap_iovec, 0, sizeof(req_exec_cmap_iovec));
  764. for (i = 0; i < argc; i++) {
  765. err = icmap_get(argv[i], NULL, &value_len, &value_type);
  766. if (err != CS_OK && err != CS_ERR_NOT_EXIST) {
  767. goto free_mem;
  768. }
  769. if (err == CS_ERR_NOT_EXIST) {
  770. value_type = ICMAP_VALUETYPE_NOT_EXIST;
  771. value_len = 0;
  772. }
  773. item_len = MAR_ALIGN_UP(sizeof(*item) + value_len, 8);
  774. item = malloc(item_len);
  775. if (item == NULL) {
  776. goto free_mem;
  777. }
  778. memset(item, 0, item_len);
  779. item->value_type = value_type;
  780. item->value_len = value_len;
  781. item->key_name.length = strlen(argv[i]);
  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 = 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 = &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 %x", 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. }