cmap.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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 *)
  689. conn_info->map_fns.map_track_get_user_data(*track))->track_inst_handle;
  690. free(conn_info->map_fns.map_track_get_user_data(*track));
  691. ret = conn_info->map_fns.map_track_delete(*track);
  692. (void)hdb_handle_put (&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  693. (void)hdb_handle_destroy(&conn_info->track_db, req_lib_cmap_track_delete->track_handle);
  694. reply_send:
  695. memset(&res_lib_cmap_track_delete, 0, sizeof(res_lib_cmap_track_delete));
  696. res_lib_cmap_track_delete.header.size = sizeof(res_lib_cmap_track_delete);
  697. res_lib_cmap_track_delete.header.id = MESSAGE_RES_CMAP_TRACK_DELETE;
  698. res_lib_cmap_track_delete.header.error = ret;
  699. res_lib_cmap_track_delete.track_inst_handle = track_inst_handle;
  700. api->ipc_response_send(conn, &res_lib_cmap_track_delete, sizeof(res_lib_cmap_track_delete));
  701. }
  702. static void message_handler_req_lib_cmap_set_current_map(void *conn, const void *message)
  703. {
  704. const struct req_lib_cmap_set_current_map *req_lib_cmap_set_current_map = message;
  705. struct qb_ipc_response_header res;
  706. cs_error_t ret = CS_OK;
  707. struct cmap_conn_info *conn_info = (struct cmap_conn_info *)api->ipc_private_data_get (conn);
  708. int handles_open = 0;
  709. hdb_handle_t iter_handle = 0;
  710. icmap_iter_t *iter;
  711. hdb_handle_t track_handle = 0;
  712. icmap_track_t *track;
  713. /* Cannot switch maps while there are tracks or iterators active */
  714. hdb_iterator_reset(&conn_info->iter_db);
  715. while (hdb_iterator_next(&conn_info->iter_db,
  716. (void*)&iter, &iter_handle) == 0) {
  717. handles_open++;
  718. }
  719. hdb_iterator_reset(&conn_info->track_db);
  720. while (hdb_iterator_next(&conn_info->track_db,
  721. (void*)&track, &track_handle) == 0) {
  722. handles_open++;
  723. }
  724. if (handles_open) {
  725. ret = CS_ERR_BUSY;
  726. goto reply_send;
  727. }
  728. switch (req_lib_cmap_set_current_map->map) {
  729. case CMAP_SETMAP_DEFAULT:
  730. conn_info->map_fns = icmap_map;
  731. break;
  732. case CMAP_SETMAP_STATS:
  733. conn_info->map_fns = stats_map;
  734. break;
  735. default:
  736. ret = CS_ERR_NOT_EXIST;
  737. break;
  738. }
  739. reply_send:
  740. res.size = sizeof(res);
  741. res.id = MESSAGE_RES_CMAP_SET_CURRENT_MAP;
  742. res.error = ret;
  743. api->ipc_response_send(conn, &res, sizeof(res));
  744. }
  745. static cs_error_t cmap_mcast_send(enum cmap_mcast_reason reason, int argc, char *argv[])
  746. {
  747. int i;
  748. size_t value_len;
  749. icmap_value_types_t value_type;
  750. cs_error_t err;
  751. size_t item_len;
  752. size_t msg_len = 0;
  753. struct req_exec_cmap_mcast req_exec_cmap_mcast;
  754. struct req_exec_cmap_mcast_item *item = NULL;
  755. struct iovec req_exec_cmap_iovec[MAX_REQ_EXEC_CMAP_MCAST_ITEMS + 1];
  756. ENTER();
  757. if (argc > MAX_REQ_EXEC_CMAP_MCAST_ITEMS) {
  758. return (CS_ERR_TOO_MANY_GROUPS);
  759. }
  760. memset(req_exec_cmap_iovec, 0, sizeof(req_exec_cmap_iovec));
  761. for (i = 0; i < argc; i++) {
  762. err = icmap_get(argv[i], NULL, &value_len, &value_type);
  763. if (err != CS_OK && err != CS_ERR_NOT_EXIST) {
  764. goto free_mem;
  765. }
  766. if (err == CS_ERR_NOT_EXIST) {
  767. value_type = ICMAP_VALUETYPE_NOT_EXIST;
  768. value_len = 0;
  769. }
  770. item_len = MAR_ALIGN_UP(sizeof(*item) + value_len, 8);
  771. item = malloc(item_len);
  772. if (item == NULL) {
  773. goto free_mem;
  774. }
  775. memset(item, 0, item_len);
  776. item->value_type = value_type;
  777. item->value_len = value_len;
  778. item->key_name.length = strlen(argv[i]);
  779. strcpy((char *)item->key_name.value, argv[i]);
  780. if (value_type != ICMAP_VALUETYPE_NOT_EXIST) {
  781. err = icmap_get(argv[i], item->value, &value_len, &value_type);
  782. if (err != CS_OK) {
  783. goto free_mem;
  784. }
  785. }
  786. req_exec_cmap_iovec[i + 1].iov_base = item;
  787. req_exec_cmap_iovec[i + 1].iov_len = item_len;
  788. msg_len += item_len;
  789. qb_log(LOG_TRACE, "Item %u - type %u, len %zu", i, item->value_type, item->value_len);
  790. item = NULL;
  791. }
  792. memset(&req_exec_cmap_mcast, 0, sizeof(req_exec_cmap_mcast));
  793. req_exec_cmap_mcast.header.size = sizeof(req_exec_cmap_mcast) + msg_len;
  794. req_exec_cmap_mcast.reason = reason;
  795. req_exec_cmap_mcast.no_items = argc;
  796. req_exec_cmap_iovec[0].iov_base = &req_exec_cmap_mcast;
  797. req_exec_cmap_iovec[0].iov_len = sizeof(req_exec_cmap_mcast);
  798. qb_log(LOG_TRACE, "Sending %u items (%u iovec) for reason %u", argc, argc + 1, reason);
  799. err = (api->totem_mcast(req_exec_cmap_iovec, argc + 1, TOTEM_AGREED) == 0 ? CS_OK : CS_ERR_MESSAGE_ERROR);
  800. free_mem:
  801. for (i = 0; i < argc; i++) {
  802. free(req_exec_cmap_iovec[i + 1].iov_base);
  803. }
  804. free(item);
  805. LEAVE();
  806. return (err);
  807. }
  808. static struct req_exec_cmap_mcast_item *cmap_mcast_item_find(
  809. const void *message,
  810. char *key)
  811. {
  812. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  813. int i;
  814. const char *p;
  815. struct req_exec_cmap_mcast_item *item;
  816. mar_uint16_t key_name_len;
  817. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  818. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  819. item = (struct req_exec_cmap_mcast_item *)p;
  820. key_name_len = item->key_name.length;
  821. if (strlen(key) == key_name_len && strcmp((char *)item->key_name.value, key) == 0) {
  822. return (item);
  823. }
  824. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  825. }
  826. return (NULL);
  827. }
  828. static void message_handler_req_exec_cmap_mcast_reason_sync_nv(
  829. enum cmap_mcast_reason reason,
  830. const void *message,
  831. unsigned int nodeid)
  832. {
  833. char member_config_version[ICMAP_KEYNAME_MAXLEN];
  834. uint64_t config_version = 0;
  835. struct req_exec_cmap_mcast_item *item;
  836. mar_size_t value_len;
  837. ENTER();
  838. item = cmap_mcast_item_find(message, (char *)"totem.config_version");
  839. if (item != NULL) {
  840. value_len = item->value_len;
  841. if (item->value_type == ICMAP_VALUETYPE_NOT_EXIST) {
  842. config_version = 0;
  843. }
  844. if (item->value_type == ICMAP_VALUETYPE_UINT64) {
  845. memcpy(&config_version, item->value, value_len);
  846. }
  847. }
  848. qb_log(LOG_TRACE, "Received config version %"PRIu64" from node %x", config_version, nodeid);
  849. if (nodeid != api->totem_nodeid_get() &&
  850. config_version > cmap_highest_config_version_received) {
  851. cmap_highest_config_version_received = config_version;
  852. }
  853. snprintf(member_config_version, ICMAP_KEYNAME_MAXLEN,
  854. "runtime.members.%u.config_version", nodeid);
  855. icmap_set_uint64(member_config_version, config_version);
  856. LEAVE();
  857. }
  858. static void message_handler_req_exec_cmap_mcast(
  859. const void *message,
  860. unsigned int nodeid)
  861. {
  862. const struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  863. ENTER();
  864. switch (req_exec_cmap_mcast->reason) {
  865. case CMAP_MCAST_REASON_SYNC:
  866. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  867. message, nodeid);
  868. break;
  869. case CMAP_MCAST_REASON_NEW_CONFIG_VERSION:
  870. message_handler_req_exec_cmap_mcast_reason_sync_nv(req_exec_cmap_mcast->reason,
  871. message, nodeid);
  872. break;
  873. default:
  874. qb_log(LOG_TRACE, "Received mcast with unknown reason %u", req_exec_cmap_mcast->reason);
  875. };
  876. LEAVE();
  877. }
  878. static void exec_cmap_mcast_endian_convert(void *message)
  879. {
  880. struct req_exec_cmap_mcast *req_exec_cmap_mcast = message;
  881. const char *p;
  882. int i;
  883. struct req_exec_cmap_mcast_item *item;
  884. uint16_t u16;
  885. uint32_t u32;
  886. uint64_t u64;
  887. float flt;
  888. double dbl;
  889. swab_coroipc_request_header_t(&req_exec_cmap_mcast->header);
  890. p = (const char *)message + sizeof(*req_exec_cmap_mcast);
  891. for (i = 0; i < req_exec_cmap_mcast->no_items; i++) {
  892. item = (struct req_exec_cmap_mcast_item *)p;
  893. swab_mar_uint16_t(&item->key_name.length);
  894. swab_mar_size_t(&item->value_len);
  895. switch (item->value_type) {
  896. case ICMAP_VALUETYPE_INT16:
  897. case ICMAP_VALUETYPE_UINT16:
  898. memcpy(&u16, item->value, sizeof(u16));
  899. u16 = swab16(u16);
  900. memcpy(item->value, &u16, sizeof(u16));
  901. break;
  902. case ICMAP_VALUETYPE_INT32:
  903. case ICMAP_VALUETYPE_UINT32:
  904. memcpy(&u32, item->value, sizeof(u32));
  905. u32 = swab32(u32);
  906. memcpy(item->value, &u32, sizeof(u32));
  907. break;
  908. case ICMAP_VALUETYPE_INT64:
  909. case ICMAP_VALUETYPE_UINT64:
  910. memcpy(&u64, item->value, sizeof(u64));
  911. u64 = swab64(u64);
  912. memcpy(item->value, &u64, sizeof(u64));
  913. break;
  914. case ICMAP_VALUETYPE_FLOAT:
  915. memcpy(&flt, item->value, sizeof(flt));
  916. swabflt(&flt);
  917. memcpy(item->value, &flt, sizeof(flt));
  918. break;
  919. case ICMAP_VALUETYPE_DOUBLE:
  920. memcpy(&dbl, item->value, sizeof(dbl));
  921. swabdbl(&dbl);
  922. memcpy(item->value, &dbl, sizeof(dbl));
  923. break;
  924. }
  925. p += MAR_ALIGN_UP(sizeof(*item) + item->value_len, 8);
  926. }
  927. }