confdb.c 24 KB

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