confdb.c 23 KB

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