confdb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Copyright (c) 2008 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@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 MontaVista Software, 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 CONTIBUTORS "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 <sys/types.h>
  35. #include <unistd.h>
  36. #include <fcntl.h>
  37. #include <stdlib.h>
  38. #include <errno.h>
  39. #include <unistd.h>
  40. #include <corosync/saAis.h>
  41. #include <corosync/cfg.h>
  42. #include <corosync/list.h>
  43. #include <corosync/queue.h>
  44. #include <corosync/mar_gen.h>
  45. #include <corosync/ipc_gen.h>
  46. #include <corosync/ipc_confdb.h>
  47. #include <corosync/lcr/lcr_comp.h>
  48. #include <corosync/engine/logsys.h>
  49. #include <corosync/engine/coroapi.h>
  50. LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_DEBUG);
  51. static struct corosync_api_v1 *api;
  52. static int confdb_exec_init_fn (
  53. struct corosync_api_v1 *corosync_api);
  54. static int confdb_lib_init_fn (void *conn);
  55. static int confdb_lib_exit_fn (void *conn);
  56. static void message_handler_req_lib_confdb_object_create (void *conn, void *message);
  57. static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message);
  58. static void message_handler_req_lib_confdb_object_find_destroy (void *conn, void *message);
  59. static void message_handler_req_lib_confdb_key_create (void *conn, void *message);
  60. static void message_handler_req_lib_confdb_key_get (void *conn, void *message);
  61. static void message_handler_req_lib_confdb_key_replace (void *conn, void *message);
  62. static void message_handler_req_lib_confdb_key_delete (void *conn, void *message);
  63. static void message_handler_req_lib_confdb_key_iter (void *conn, void *message);
  64. static void message_handler_req_lib_confdb_key_increment (void *conn, void *message);
  65. static void message_handler_req_lib_confdb_key_decrement (void *conn, void *message);
  66. static void message_handler_req_lib_confdb_object_iter (void *conn, void *message);
  67. static void message_handler_req_lib_confdb_object_find (void *conn, void *message);
  68. static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message);
  69. static void message_handler_req_lib_confdb_write (void *conn, void *message);
  70. static void message_handler_req_lib_confdb_reload (void *conn, void *message);
  71. static void message_handler_req_lib_confdb_track_start (void *conn, void *message);
  72. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message);
  73. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  74. unsigned int parent_object_handle,
  75. unsigned int object_handle,
  76. void *object_name_pt, int object_name_len,
  77. void *key_name_pt, int key_name_len,
  78. void *key_value_pt, int key_value_len,
  79. void *priv_data_pt);
  80. static void confdb_notify_lib_of_new_object(unsigned int parent_object_handle,
  81. unsigned int object_handle,
  82. uint8_t *name_pt, int name_len,
  83. void *priv_data_pt);
  84. static void confdb_notify_lib_of_destroyed_object(unsigned int parent_object_handle,
  85. uint8_t *name_pt, int name_len,
  86. void *priv_data_pt);
  87. /*
  88. * Library Handler Definition
  89. */
  90. static struct corosync_lib_handler confdb_lib_engine[] =
  91. {
  92. { /* 0 */
  93. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  94. .response_size = sizeof (mar_res_header_t),
  95. .response_id = MESSAGE_RES_CONFDB_OBJECT_CREATE,
  96. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  97. },
  98. { /* 1 */
  99. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  100. .response_size = sizeof (mar_res_header_t),
  101. .response_id = MESSAGE_RES_CONFDB_OBJECT_DESTROY,
  102. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  103. },
  104. { /* 2 */
  105. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  106. .response_size = sizeof (struct res_lib_confdb_object_find),
  107. .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND,
  108. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  109. },
  110. { /* 3 */
  111. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  112. .response_size = sizeof (mar_res_header_t),
  113. .response_id = MESSAGE_RES_CONFDB_KEY_CREATE,
  114. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  115. },
  116. { /* 4 */
  117. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  118. .response_size = sizeof (struct res_lib_confdb_key_get),
  119. .response_id = MESSAGE_RES_CONFDB_KEY_GET,
  120. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  121. },
  122. { /* 5 */
  123. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  124. .response_size = sizeof (mar_res_header_t),
  125. .response_id = MESSAGE_RES_CONFDB_KEY_REPLACE,
  126. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  127. },
  128. { /* 6 */
  129. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  130. .response_size = sizeof (mar_res_header_t),
  131. .response_id = MESSAGE_RES_CONFDB_KEY_DELETE,
  132. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  133. },
  134. { /* 7 */
  135. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  136. .response_size = sizeof (struct res_lib_confdb_object_iter),
  137. .response_id = MESSAGE_RES_CONFDB_OBJECT_ITER,
  138. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  139. },
  140. { /* 8 */
  141. .lib_handler_fn = message_handler_req_lib_confdb_object_parent_get,
  142. .response_size = sizeof (struct res_lib_confdb_object_parent_get),
  143. .response_id = MESSAGE_RES_CONFDB_OBJECT_PARENT_GET,
  144. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  145. },
  146. { /* 9 */
  147. .lib_handler_fn = message_handler_req_lib_confdb_key_iter,
  148. .response_size = sizeof (struct res_lib_confdb_key_iter),
  149. .response_id = MESSAGE_RES_CONFDB_KEY_ITER,
  150. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  151. },
  152. { /* 10 */
  153. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  154. .response_size = sizeof (mar_res_header_t),
  155. .response_id = MESSAGE_RES_CONFDB_TRACK_START,
  156. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  157. },
  158. { /* 11 */
  159. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  160. .response_size = sizeof (mar_res_header_t),
  161. .response_id = MESSAGE_RES_CONFDB_TRACK_STOP,
  162. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  163. },
  164. { /* 12 */
  165. .lib_handler_fn = message_handler_req_lib_confdb_write,
  166. .response_size = sizeof (struct res_lib_confdb_write),
  167. .response_id = MESSAGE_RES_CONFDB_WRITE,
  168. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  169. },
  170. { /* 13 */
  171. .lib_handler_fn = message_handler_req_lib_confdb_reload,
  172. .response_size = sizeof (struct res_lib_confdb_reload),
  173. .response_id = MESSAGE_RES_CONFDB_RELOAD,
  174. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  175. },
  176. { /* 14 */
  177. .lib_handler_fn = message_handler_req_lib_confdb_object_find_destroy,
  178. .response_size = sizeof (mar_res_header_t),
  179. .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY,
  180. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  181. },
  182. { /* 15 */
  183. .lib_handler_fn = message_handler_req_lib_confdb_key_increment,
  184. .response_size = sizeof (struct res_lib_confdb_key_incdec),
  185. .response_id = MESSAGE_RES_CONFDB_KEY_INCREMENT,
  186. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  187. },
  188. { /* 16 */
  189. .lib_handler_fn = message_handler_req_lib_confdb_key_decrement,
  190. .response_size = sizeof (struct res_lib_confdb_key_incdec),
  191. .response_id = MESSAGE_RES_CONFDB_KEY_DECREMENT,
  192. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  193. },
  194. };
  195. struct corosync_service_engine confdb_service_engine = {
  196. .name = "corosync cluster config database access v1.01",
  197. .id = CONFDB_SERVICE,
  198. .private_data_size = 0,
  199. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED,
  200. .lib_init_fn = confdb_lib_init_fn,
  201. .lib_exit_fn = confdb_lib_exit_fn,
  202. .lib_engine = confdb_lib_engine,
  203. .lib_engine_count = sizeof (confdb_lib_engine) / sizeof (struct corosync_lib_handler),
  204. .exec_init_fn = confdb_exec_init_fn,
  205. };
  206. /*
  207. * Dynamic loader definition
  208. */
  209. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void);
  210. static struct corosync_service_engine_iface_ver0 confdb_service_engine_iface = {
  211. .corosync_get_service_engine_ver0 = confdb_get_service_engine_ver0
  212. };
  213. static struct lcr_iface corosync_confdb_ver0[1] = {
  214. {
  215. .name = "corosync_confdb",
  216. .version = 0,
  217. .versions_replace = 0,
  218. .versions_replace_count = 0,
  219. .dependencies = 0,
  220. .dependency_count = 0,
  221. .constructor = NULL,
  222. .destructor = NULL,
  223. .interfaces = NULL
  224. }
  225. };
  226. static struct lcr_comp confdb_comp_ver0 = {
  227. .iface_count = 1,
  228. .ifaces = corosync_confdb_ver0
  229. };
  230. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void)
  231. {
  232. return (&confdb_service_engine);
  233. }
  234. __attribute__ ((constructor)) static void confdb_comp_register (void) {
  235. lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
  236. lcr_component_register (&confdb_comp_ver0);
  237. }
  238. static int confdb_exec_init_fn (
  239. struct corosync_api_v1 *corosync_api)
  240. {
  241. api = corosync_api;
  242. return 0;
  243. }
  244. static int confdb_lib_init_fn (void *conn)
  245. {
  246. log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  247. return (0);
  248. }
  249. static int confdb_lib_exit_fn (void *conn)
  250. {
  251. log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  252. /* cleanup the object trackers for this client. */
  253. api->object_track_stop(confdb_notify_lib_of_key_change,
  254. confdb_notify_lib_of_new_object,
  255. confdb_notify_lib_of_destroyed_object,
  256. api->ipc_conn_partner_get (conn));
  257. return (0);
  258. }
  259. static void message_handler_req_lib_confdb_object_create (void *conn, void *message)
  260. {
  261. struct req_lib_confdb_object_create *req_lib_confdb_object_create = (struct req_lib_confdb_object_create *)message;
  262. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  263. unsigned int object_handle;
  264. int ret = SA_AIS_OK;
  265. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  266. &object_handle,
  267. req_lib_confdb_object_create->object_name.value,
  268. req_lib_confdb_object_create->object_name.length))
  269. ret = SA_AIS_ERR_ACCESS;
  270. res_lib_confdb_object_create.object_handle = object_handle;
  271. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  272. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  273. res_lib_confdb_object_create.header.error = ret;
  274. api->ipc_conn_send_response(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  275. }
  276. static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message)
  277. {
  278. struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy = (struct req_lib_confdb_object_destroy *)message;
  279. mar_res_header_t res;
  280. int ret = SA_AIS_OK;
  281. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  282. ret = SA_AIS_ERR_ACCESS;
  283. res.size = sizeof(res);
  284. res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
  285. res.error = ret;
  286. api->ipc_conn_send_response(conn, &res, sizeof(res));
  287. }
  288. static void message_handler_req_lib_confdb_object_find_destroy (void *conn, void *message)
  289. {
  290. struct req_lib_confdb_object_find_destroy *req_lib_confdb_object_find_destroy = (struct req_lib_confdb_object_find_destroy *)message;
  291. mar_res_header_t res;
  292. int ret = SA_AIS_OK;
  293. log_printf(LOG_LEVEL_DEBUG, "object_find_destroy for conn=%p, %d\n", conn, req_lib_confdb_object_find_destroy->find_handle);
  294. if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
  295. ret = SA_AIS_ERR_ACCESS;
  296. res.size = sizeof(res);
  297. res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
  298. res.error = ret;
  299. api->ipc_conn_send_response(conn, &res, sizeof(res));
  300. }
  301. static void message_handler_req_lib_confdb_key_create (void *conn, void *message)
  302. {
  303. struct req_lib_confdb_key_create *req_lib_confdb_key_create = (struct req_lib_confdb_key_create *)message;
  304. mar_res_header_t res;
  305. int ret = SA_AIS_OK;
  306. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  307. req_lib_confdb_key_create->key_name.value,
  308. req_lib_confdb_key_create->key_name.length,
  309. req_lib_confdb_key_create->value.value,
  310. req_lib_confdb_key_create->value.length))
  311. ret = SA_AIS_ERR_ACCESS;
  312. res.size = sizeof(res);
  313. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  314. res.error = ret;
  315. api->ipc_conn_send_response(conn, &res, sizeof(res));
  316. }
  317. static void message_handler_req_lib_confdb_key_get (void *conn, void *message)
  318. {
  319. struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message;
  320. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  321. int value_len;
  322. void *value;
  323. int ret = SA_AIS_OK;
  324. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  325. req_lib_confdb_key_get->key_name.value,
  326. req_lib_confdb_key_get->key_name.length,
  327. &value,
  328. &value_len))
  329. ret = SA_AIS_ERR_ACCESS;
  330. else {
  331. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  332. res_lib_confdb_key_get.value.length = value_len;
  333. }
  334. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  335. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  336. res_lib_confdb_key_get.header.error = ret;
  337. api->ipc_conn_send_response(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  338. }
  339. static void message_handler_req_lib_confdb_key_increment (void *conn, void *message)
  340. {
  341. struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message;
  342. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  343. int ret = SA_AIS_OK;
  344. if (api->object_key_increment(req_lib_confdb_key_get->parent_object_handle,
  345. req_lib_confdb_key_get->key_name.value,
  346. req_lib_confdb_key_get->key_name.length,
  347. &res_lib_confdb_key_incdec.value))
  348. ret = SA_AIS_ERR_ACCESS;
  349. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  350. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_INCREMENT;
  351. res_lib_confdb_key_incdec.header.error = ret;
  352. api->ipc_conn_send_response(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  353. }
  354. static void message_handler_req_lib_confdb_key_decrement (void *conn, void *message)
  355. {
  356. struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message;
  357. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  358. int ret = SA_AIS_OK;
  359. if (api->object_key_decrement(req_lib_confdb_key_get->parent_object_handle,
  360. req_lib_confdb_key_get->key_name.value,
  361. req_lib_confdb_key_get->key_name.length,
  362. &res_lib_confdb_key_incdec.value))
  363. ret = SA_AIS_ERR_ACCESS;
  364. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  365. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_DECREMENT;
  366. res_lib_confdb_key_incdec.header.error = ret;
  367. api->ipc_conn_send_response(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  368. }
  369. static void message_handler_req_lib_confdb_key_replace (void *conn, void *message)
  370. {
  371. struct req_lib_confdb_key_replace *req_lib_confdb_key_replace = (struct req_lib_confdb_key_replace *)message;
  372. mar_res_header_t res;
  373. int ret = SA_AIS_OK;
  374. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  375. req_lib_confdb_key_replace->key_name.value,
  376. req_lib_confdb_key_replace->key_name.length,
  377. req_lib_confdb_key_replace->old_value.value,
  378. req_lib_confdb_key_replace->old_value.length,
  379. req_lib_confdb_key_replace->new_value.value,
  380. req_lib_confdb_key_replace->new_value.length))
  381. ret = SA_AIS_ERR_ACCESS;
  382. res.size = sizeof(res);
  383. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  384. res.error = ret;
  385. api->ipc_conn_send_response(conn, &res, sizeof(res));
  386. }
  387. static void message_handler_req_lib_confdb_key_delete (void *conn, void *message)
  388. {
  389. struct req_lib_confdb_key_delete *req_lib_confdb_key_delete = (struct req_lib_confdb_key_delete *)message;
  390. mar_res_header_t res;
  391. int ret = SA_AIS_OK;
  392. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  393. req_lib_confdb_key_delete->key_name.value,
  394. req_lib_confdb_key_delete->key_name.length,
  395. req_lib_confdb_key_delete->value.value,
  396. req_lib_confdb_key_delete->value.length))
  397. ret = SA_AIS_ERR_ACCESS;
  398. res.size = sizeof(res);
  399. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  400. res.error = ret;
  401. api->ipc_conn_send_response(conn, &res, sizeof(res));
  402. }
  403. static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message)
  404. {
  405. struct req_lib_confdb_object_parent_get *req_lib_confdb_object_parent_get = (struct req_lib_confdb_object_parent_get *)message;
  406. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  407. unsigned int object_handle;
  408. int ret = SA_AIS_OK;
  409. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  410. &object_handle))
  411. ret = SA_AIS_ERR_ACCESS;
  412. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  413. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  414. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  415. res_lib_confdb_object_parent_get.header.error = ret;
  416. api->ipc_conn_send_response(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  417. }
  418. static void message_handler_req_lib_confdb_key_iter (void *conn, void *message)
  419. {
  420. struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = (struct req_lib_confdb_key_iter *)message;
  421. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  422. void *key_name;
  423. int key_name_len;
  424. void *value;
  425. int value_len;
  426. int ret = SA_AIS_OK;
  427. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  428. req_lib_confdb_key_iter->next_entry,
  429. &key_name,
  430. &key_name_len,
  431. &value,
  432. &value_len))
  433. ret = SA_AIS_ERR_ACCESS;
  434. else {
  435. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  436. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  437. res_lib_confdb_key_iter.key_name.length = key_name_len;
  438. res_lib_confdb_key_iter.value.length = value_len;
  439. }
  440. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  441. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  442. res_lib_confdb_key_iter.header.error = ret;
  443. api->ipc_conn_send_response(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  444. }
  445. static void message_handler_req_lib_confdb_object_iter (void *conn, void *message)
  446. {
  447. struct req_lib_confdb_object_iter *req_lib_confdb_object_iter = (struct req_lib_confdb_object_iter *)message;
  448. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  449. int object_name_len;
  450. int ret = SA_AIS_OK;
  451. if (!req_lib_confdb_object_iter->find_handle) {
  452. api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
  453. NULL, 0,
  454. &res_lib_confdb_object_iter.find_handle);
  455. }
  456. else
  457. res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
  458. if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
  459. &res_lib_confdb_object_iter.object_handle))
  460. ret = SA_AIS_ERR_ACCESS;
  461. else {
  462. api->object_name_get(res_lib_confdb_object_iter.object_handle,
  463. (char *)res_lib_confdb_object_iter.object_name.value,
  464. &object_name_len);
  465. res_lib_confdb_object_iter.object_name.length = object_name_len;
  466. }
  467. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  468. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  469. res_lib_confdb_object_iter.header.error = ret;
  470. api->ipc_conn_send_response(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  471. }
  472. static void message_handler_req_lib_confdb_object_find (void *conn, void *message)
  473. {
  474. struct req_lib_confdb_object_find *req_lib_confdb_object_find = (struct req_lib_confdb_object_find *)message;
  475. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  476. int ret = SA_AIS_OK;
  477. if (!req_lib_confdb_object_find->find_handle) {
  478. api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
  479. req_lib_confdb_object_find->object_name.value,
  480. req_lib_confdb_object_find->object_name.length,
  481. &res_lib_confdb_object_find.find_handle);
  482. }
  483. else
  484. res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
  485. if (api->object_find_next(res_lib_confdb_object_find.find_handle,
  486. &res_lib_confdb_object_find.object_handle))
  487. ret = SA_AIS_ERR_ACCESS;
  488. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  489. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  490. res_lib_confdb_object_find.header.error = ret;
  491. api->ipc_conn_send_response(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  492. }
  493. static void message_handler_req_lib_confdb_write (void *conn, void *message)
  494. {
  495. struct res_lib_confdb_write res_lib_confdb_write;
  496. int ret = SA_AIS_OK;
  497. char *error_string = NULL;
  498. if (api->object_write_config(&error_string))
  499. ret = SA_AIS_ERR_ACCESS;
  500. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  501. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  502. res_lib_confdb_write.header.error = ret;
  503. if (error_string) {
  504. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  505. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  506. } else
  507. res_lib_confdb_write.error.length = 0;
  508. api->ipc_conn_send_response(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  509. }
  510. static void message_handler_req_lib_confdb_reload (void *conn, void *message)
  511. {
  512. struct req_lib_confdb_reload *req_lib_confdb_reload = (struct req_lib_confdb_reload *)message;
  513. struct res_lib_confdb_reload res_lib_confdb_reload;
  514. int ret = SA_AIS_OK;
  515. char *error_string = NULL;
  516. if (api->object_reload_config(req_lib_confdb_reload->flush, &error_string))
  517. ret = SA_AIS_ERR_ACCESS;
  518. res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
  519. res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
  520. res_lib_confdb_reload.header.error = ret;
  521. if(error_string) {
  522. strcpy((char *)res_lib_confdb_reload.error.value, error_string);
  523. res_lib_confdb_reload.error.length = strlen(error_string) + 1;
  524. } else
  525. res_lib_confdb_reload.error.length = 0;
  526. api->ipc_conn_send_response(conn, &res_lib_confdb_reload, sizeof(res_lib_confdb_reload));
  527. }
  528. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  529. unsigned int parent_object_handle,
  530. unsigned int object_handle,
  531. void *object_name_pt, int object_name_len,
  532. void *key_name_pt, int key_name_len,
  533. void *key_value_pt, int key_value_len,
  534. void *priv_data_pt)
  535. {
  536. struct res_lib_confdb_key_change_callback res;
  537. res.header.size = sizeof(res);
  538. res.header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK;
  539. res.header.error = SA_AIS_OK;
  540. // handle & type
  541. res.change_type = change_type;
  542. res.parent_object_handle = parent_object_handle;
  543. res.object_handle = object_handle;
  544. //object
  545. memcpy(res.object_name.value, object_name_pt, object_name_len);
  546. res.object_name.length = object_name_len;
  547. //key name
  548. memcpy(res.key_name.value, key_name_pt, key_name_len);
  549. res.key_name.length = key_name_len;
  550. //key value
  551. memcpy(res.key_value.value, key_value_pt, key_value_len);
  552. res.key_value.length = key_value_len;
  553. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  554. }
  555. static void confdb_notify_lib_of_new_object(unsigned int parent_object_handle,
  556. unsigned int object_handle,
  557. uint8_t *name_pt, int name_len,
  558. void *priv_data_pt)
  559. {
  560. struct res_lib_confdb_object_create_callback res;
  561. res.header.size = sizeof(res);
  562. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  563. res.header.error = SA_AIS_OK;
  564. res.parent_object_handle = parent_object_handle;
  565. res.object_handle = object_handle;
  566. memcpy(res.name.value, name_pt, name_len);
  567. res.name.length = name_len;
  568. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  569. }
  570. static void confdb_notify_lib_of_destroyed_object(unsigned int parent_object_handle,
  571. uint8_t *name_pt, int name_len,
  572. void *priv_data_pt)
  573. {
  574. struct res_lib_confdb_object_destroy_callback res;
  575. res.header.size = sizeof(res);
  576. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  577. res.header.error = SA_AIS_OK;
  578. res.parent_object_handle = parent_object_handle;
  579. memcpy(res.name.value, name_pt, name_len);
  580. res.name.length = name_len;
  581. api->ipc_conn_send_response(priv_data_pt, &res, sizeof(res));
  582. }
  583. static void message_handler_req_lib_confdb_track_start (void *conn, void *message)
  584. {
  585. struct req_lib_confdb_object_track_start *req = (struct req_lib_confdb_object_track_start *)message;
  586. mar_res_header_t res;
  587. api->object_track_start(req->object_handle, req->flags,
  588. confdb_notify_lib_of_key_change,
  589. confdb_notify_lib_of_new_object,
  590. confdb_notify_lib_of_destroyed_object,
  591. api->ipc_conn_partner_get (conn));
  592. res.size = sizeof(res);
  593. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  594. res.error = SA_AIS_OK;
  595. api->ipc_conn_send_response(conn, &res, sizeof(res));
  596. }
  597. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message)
  598. {
  599. mar_res_header_t res;
  600. api->object_track_stop(confdb_notify_lib_of_key_change,
  601. confdb_notify_lib_of_new_object,
  602. confdb_notify_lib_of_destroyed_object,
  603. api->ipc_conn_partner_get (conn));
  604. res.size = sizeof(res);
  605. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  606. res.error = SA_AIS_OK;
  607. api->ipc_conn_send_response(conn, &res, sizeof(res));
  608. }