confdb.c 23 KB

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