confdb.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263
  1. /*
  2. * Copyright (c) 2008-2012 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 <config.h>
  35. #include <sys/types.h>
  36. #include <unistd.h>
  37. #include <fcntl.h>
  38. #include <stdlib.h>
  39. #include <errno.h>
  40. #include <unistd.h>
  41. #include <poll.h>
  42. #include <corosync/corotypes.h>
  43. #include <corosync/coroipc_types.h>
  44. #include <corosync/corodefs.h>
  45. #include <corosync/cfg.h>
  46. #include <corosync/list.h>
  47. #include <corosync/mar_gen.h>
  48. #include <corosync/ipc_confdb.h>
  49. #include <corosync/lcr/lcr_comp.h>
  50. #include <corosync/engine/logsys.h>
  51. #include <corosync/engine/coroapi.h>
  52. #include <corosync/totem/coropoll.h>
  53. LOGSYS_DECLARE_SUBSYS ("CONFDB");
  54. static hdb_handle_t *
  55. m2h (mar_uint64_t *m)
  56. {
  57. /* FIXME enable the following when/if we use gnulib:
  58. (it's a compile-time assertion; i.e., zero run-time cost)
  59. verify (sizeof (*m) == sizeof (hdb_handle_t)); */
  60. return (void *) m;
  61. }
  62. static struct corosync_api_v1 *api;
  63. static int notify_pipe[2];
  64. struct confdb_ipc_message_holder {
  65. void *conn;
  66. size_t mlen;
  67. struct list_head list;
  68. char msg[];
  69. };
  70. DECLARE_LIST_INIT(confdb_ipc_message_holder_list_head);
  71. pthread_mutex_t confdb_ipc_message_holder_list_mutex =
  72. PTHREAD_MUTEX_INITIALIZER;
  73. static int confdb_exec_init_fn (
  74. struct corosync_api_v1 *corosync_api);
  75. static int confdb_exec_exit_fn(void);
  76. static int fd_set_nonblocking(int fd);
  77. static int objdb_notify_dispatch(hdb_handle_t handle,
  78. int fd, int revents, void *data);
  79. static int confdb_lib_init_fn (void *conn);
  80. static int confdb_lib_exit_fn (void *conn);
  81. static void message_handler_req_lib_confdb_object_create (void *conn,
  82. const void *message);
  83. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  84. const void *message);
  85. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  86. const void *message);
  87. static void message_handler_req_lib_confdb_key_create (void *conn,
  88. const void *message);
  89. static void message_handler_req_lib_confdb_key_create_typed (void *conn,
  90. const void *message);
  91. static void message_handler_req_lib_confdb_key_create_typed2 (void *conn,
  92. const void *message);
  93. static void message_handler_req_lib_confdb_key_get (void *conn,
  94. const void *message);
  95. static void message_handler_req_lib_confdb_key_get_typed (void *conn,
  96. const void *message);
  97. static void message_handler_req_lib_confdb_key_get_typed2 (void *conn,
  98. const void *message);
  99. static void message_handler_req_lib_confdb_key_replace (void *conn,
  100. const void *message);
  101. static void message_handler_req_lib_confdb_key_replace2 (void *conn,
  102. const void *message);
  103. static void message_handler_req_lib_confdb_key_delete (void *conn,
  104. const void *message);
  105. static void message_handler_req_lib_confdb_key_iter (void *conn,
  106. const void *message);
  107. static void message_handler_req_lib_confdb_key_iter_typed (void *conn,
  108. const void *message);
  109. static void message_handler_req_lib_confdb_key_iter_typed2 (void *conn,
  110. const void *message);
  111. static void message_handler_req_lib_confdb_key_increment (void *conn,
  112. const void *message);
  113. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  114. const void *message);
  115. static void message_handler_req_lib_confdb_object_iter (void *conn,
  116. const void *message);
  117. static void message_handler_req_lib_confdb_object_find (void *conn,
  118. const void *message);
  119. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  120. const void *message);
  121. static void message_handler_req_lib_confdb_object_name_get (void *conn,
  122. const void *message);
  123. static void message_handler_req_lib_confdb_write (void *conn,
  124. const void *message);
  125. static void message_handler_req_lib_confdb_reload (void *conn,
  126. const void *message);
  127. static void message_handler_req_lib_confdb_track_start (void *conn,
  128. const void *message);
  129. static void message_handler_req_lib_confdb_track_stop (void *conn,
  130. const void *message);
  131. static void confdb_notify_lib_of_key_change(
  132. object_change_type_t change_type,
  133. hdb_handle_t parent_object_handle,
  134. hdb_handle_t object_handle,
  135. const void *object_name_pt, size_t object_name_len,
  136. const void *key_name_pt, size_t key_name_len,
  137. const void *key_value_pt, size_t key_value_len,
  138. void *priv_data_pt);
  139. static void confdb_notify_lib_of_new_object(
  140. hdb_handle_t parent_object_handle,
  141. hdb_handle_t object_handle,
  142. const void *name_pt, size_t name_len,
  143. void *priv_data_pt);
  144. static void confdb_notify_lib_of_destroyed_object(
  145. hdb_handle_t parent_object_handle,
  146. const void *name_pt, size_t name_len,
  147. void *priv_data_pt);
  148. static void confdb_notify_lib_of_reload(
  149. objdb_reload_notify_type_t notify_type,
  150. int flush,
  151. void *priv_data_pt);
  152. /*
  153. * Library Handler Definition
  154. */
  155. static struct corosync_lib_handler confdb_lib_engine[] =
  156. {
  157. { /* 0 */
  158. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  159. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  160. },
  161. { /* 1 */
  162. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  163. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  164. },
  165. { /* 2 */
  166. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  167. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  168. },
  169. { /* 3 */
  170. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  171. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  172. },
  173. { /* 4 */
  174. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  175. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  176. },
  177. { /* 5 */
  178. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  179. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  180. },
  181. { /* 6 */
  182. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  183. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  184. },
  185. { /* 7 */
  186. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  187. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  188. },
  189. { /* 8 */
  190. .lib_handler_fn = message_handler_req_lib_confdb_object_parent_get,
  191. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  192. },
  193. { /* 9 */
  194. .lib_handler_fn = message_handler_req_lib_confdb_key_iter,
  195. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  196. },
  197. { /* 10 */
  198. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  199. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  200. },
  201. { /* 11 */
  202. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  203. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  204. },
  205. { /* 12 */
  206. .lib_handler_fn = message_handler_req_lib_confdb_write,
  207. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  208. },
  209. { /* 13 */
  210. .lib_handler_fn = message_handler_req_lib_confdb_reload,
  211. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  212. },
  213. { /* 14 */
  214. .lib_handler_fn = message_handler_req_lib_confdb_object_find_destroy,
  215. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  216. },
  217. { /* 15 */
  218. .lib_handler_fn = message_handler_req_lib_confdb_key_increment,
  219. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  220. },
  221. { /* 16 */
  222. .lib_handler_fn = message_handler_req_lib_confdb_key_decrement,
  223. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  224. },
  225. { /* 17 */
  226. .lib_handler_fn = message_handler_req_lib_confdb_key_create_typed,
  227. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  228. },
  229. { /* 18 */
  230. .lib_handler_fn = message_handler_req_lib_confdb_key_get_typed,
  231. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  232. },
  233. { /* 19 */
  234. .lib_handler_fn = message_handler_req_lib_confdb_key_iter_typed,
  235. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  236. },
  237. { /* 20 */
  238. .lib_handler_fn = message_handler_req_lib_confdb_object_name_get,
  239. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  240. },
  241. { /* 21 */
  242. .lib_handler_fn = message_handler_req_lib_confdb_key_iter_typed2,
  243. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  244. },
  245. { /* 22 */
  246. .lib_handler_fn = message_handler_req_lib_confdb_key_replace2,
  247. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  248. },
  249. { /* 23 */
  250. .lib_handler_fn = message_handler_req_lib_confdb_key_get_typed2,
  251. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  252. },
  253. { /* 24 */
  254. .lib_handler_fn = message_handler_req_lib_confdb_key_create_typed2,
  255. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  256. },
  257. };
  258. struct corosync_service_engine confdb_service_engine = {
  259. .name = "corosync cluster config database access v1.01",
  260. .id = CONFDB_SERVICE,
  261. .priority = 1,
  262. .private_data_size = 0,
  263. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  264. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  265. .lib_init_fn = confdb_lib_init_fn,
  266. .lib_exit_fn = confdb_lib_exit_fn,
  267. .lib_engine = confdb_lib_engine,
  268. .lib_engine_count = sizeof (confdb_lib_engine) / sizeof (struct corosync_lib_handler),
  269. .exec_init_fn = confdb_exec_init_fn,
  270. .exec_exit_fn = confdb_exec_exit_fn,
  271. };
  272. /*
  273. * Dynamic loader definition
  274. */
  275. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void);
  276. static struct corosync_service_engine_iface_ver0 confdb_service_engine_iface = {
  277. .corosync_get_service_engine_ver0 = confdb_get_service_engine_ver0
  278. };
  279. static struct lcr_iface corosync_confdb_ver0[1] = {
  280. {
  281. .name = "corosync_confdb",
  282. .version = 0,
  283. .versions_replace = 0,
  284. .versions_replace_count = 0,
  285. .dependencies = 0,
  286. .dependency_count = 0,
  287. .constructor = NULL,
  288. .destructor = NULL,
  289. .interfaces = NULL
  290. }
  291. };
  292. static struct lcr_comp confdb_comp_ver0 = {
  293. .iface_count = 1,
  294. .ifaces = corosync_confdb_ver0
  295. };
  296. static struct corosync_service_engine *confdb_get_service_engine_ver0 (void)
  297. {
  298. return (&confdb_service_engine);
  299. }
  300. #ifdef COROSYNC_SOLARIS
  301. void corosync_lcr_component_register (void);
  302. void corosync_lcr_component_register (void) {
  303. #else
  304. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  305. #endif
  306. lcr_interfaces_set (&corosync_confdb_ver0[0], &confdb_service_engine_iface);
  307. lcr_component_register (&confdb_comp_ver0);
  308. }
  309. static int confdb_exec_exit_fn(void)
  310. {
  311. api->poll_dispatch_delete(api->poll_handle_get(), notify_pipe[0]);
  312. close(notify_pipe[0]);
  313. close(notify_pipe[1]);
  314. return 0;
  315. }
  316. static int confdb_exec_init_fn (
  317. struct corosync_api_v1 *corosync_api)
  318. {
  319. int i;
  320. #ifdef COROSYNC_SOLARIS
  321. logsys_subsys_init();
  322. #endif
  323. api = corosync_api;
  324. if (pipe(notify_pipe) != 0) {
  325. return -1;
  326. }
  327. for (i = 0; i < 2; i++) {
  328. if (fd_set_nonblocking (notify_pipe[i]) == -1) {
  329. return -1;
  330. }
  331. }
  332. return api->poll_dispatch_add(api->poll_handle_get(), notify_pipe[0],
  333. POLLIN, NULL, objdb_notify_dispatch);
  334. }
  335. static int confdb_lib_init_fn (void *conn)
  336. {
  337. log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  338. return (0);
  339. }
  340. static int confdb_lib_exit_fn (void *conn)
  341. {
  342. log_printf(LOGSYS_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  343. /* cleanup the object trackers for this client. */
  344. api->object_track_stop(confdb_notify_lib_of_key_change,
  345. confdb_notify_lib_of_new_object,
  346. confdb_notify_lib_of_destroyed_object,
  347. confdb_notify_lib_of_reload,
  348. conn);
  349. return (0);
  350. }
  351. static int fd_set_nonblocking(int fd)
  352. {
  353. int flags;
  354. int res;
  355. flags = fcntl (fd, F_GETFL);
  356. if (flags == -1) {
  357. return -1;
  358. }
  359. flags |= O_NONBLOCK;
  360. res = fcntl (fd, F_SETFL, flags);
  361. return res;
  362. }
  363. static void message_handler_req_lib_confdb_object_create (void *conn,
  364. const void *message)
  365. {
  366. const struct req_lib_confdb_object_create *req_lib_confdb_object_create
  367. = message;
  368. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  369. hdb_handle_t object_handle;
  370. int ret = CS_OK;
  371. if (api->object_create(req_lib_confdb_object_create->parent_object_handle,
  372. &object_handle,
  373. req_lib_confdb_object_create->object_name.value,
  374. req_lib_confdb_object_create->object_name.length))
  375. ret = CS_ERR_ACCESS;
  376. res_lib_confdb_object_create.object_handle = object_handle;
  377. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  378. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  379. res_lib_confdb_object_create.header.error = ret;
  380. api->ipc_response_send(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  381. }
  382. static void message_handler_req_lib_confdb_object_destroy (void *conn,
  383. const void *message)
  384. {
  385. const struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy
  386. = message;
  387. coroipc_response_header_t res;
  388. int ret = CS_OK;
  389. if (api->object_destroy(req_lib_confdb_object_destroy->object_handle))
  390. ret = CS_ERR_ACCESS;
  391. res.size = sizeof(res);
  392. res.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY;
  393. res.error = ret;
  394. api->ipc_response_send(conn, &res, sizeof(res));
  395. }
  396. static void message_handler_req_lib_confdb_object_find_destroy (void *conn,
  397. const void *message)
  398. {
  399. const struct req_lib_confdb_object_find_destroy
  400. *req_lib_confdb_object_find_destroy = message;
  401. coroipc_response_header_t res;
  402. int ret = CS_OK;
  403. if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle))
  404. ret = CS_ERR_ACCESS;
  405. res.size = sizeof(res);
  406. res.id = MESSAGE_RES_CONFDB_OBJECT_FIND_DESTROY;
  407. res.error = ret;
  408. api->ipc_response_send(conn, &res, sizeof(res));
  409. }
  410. static void message_handler_req_lib_confdb_key_create (void *conn,
  411. const void *message)
  412. {
  413. const struct req_lib_confdb_key_create *req_lib_confdb_key_create
  414. = message;
  415. coroipc_response_header_t res;
  416. int ret = CS_OK;
  417. if (api->object_key_create(req_lib_confdb_key_create->object_handle,
  418. req_lib_confdb_key_create->key_name.value,
  419. req_lib_confdb_key_create->key_name.length,
  420. req_lib_confdb_key_create->value.value,
  421. req_lib_confdb_key_create->value.length))
  422. ret = CS_ERR_ACCESS;
  423. res.size = sizeof(res);
  424. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  425. res.error = ret;
  426. api->ipc_response_send(conn, &res, sizeof(res));
  427. }
  428. static void message_handler_req_lib_confdb_key_create_typed (void *conn,
  429. const void *message)
  430. {
  431. const struct req_lib_confdb_key_create_typed *req_lib_confdb_key_create
  432. = message;
  433. coroipc_response_header_t res;
  434. int ret = CS_OK;
  435. if (api->object_key_create_typed(req_lib_confdb_key_create->object_handle,
  436. (char*)req_lib_confdb_key_create->key_name.value,
  437. req_lib_confdb_key_create->value.value,
  438. req_lib_confdb_key_create->value.length,
  439. req_lib_confdb_key_create->type))
  440. ret = CS_ERR_ACCESS;
  441. res.size = sizeof(res);
  442. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  443. res.error = ret;
  444. api->ipc_response_send(conn, &res, sizeof(res));
  445. }
  446. static void message_handler_req_lib_confdb_key_get (void *conn,
  447. const void *message)
  448. {
  449. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  450. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  451. size_t value_len;
  452. void *value;
  453. int ret = CS_OK;
  454. if (api->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  455. req_lib_confdb_key_get->key_name.value,
  456. req_lib_confdb_key_get->key_name.length,
  457. &value,
  458. &value_len))
  459. ret = CS_ERR_ACCESS;
  460. else {
  461. if (value_len > CS_MAX_NAME_LENGTH) {
  462. ret = CS_ERR_TOO_BIG;
  463. } else {
  464. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  465. }
  466. res_lib_confdb_key_get.value.length = value_len;
  467. }
  468. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  469. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  470. res_lib_confdb_key_get.header.error = ret;
  471. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  472. }
  473. static void message_handler_req_lib_confdb_key_get_typed (void *conn,
  474. const void *message)
  475. {
  476. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  477. struct res_lib_confdb_key_get_typed res_lib_confdb_key_get;
  478. size_t value_len;
  479. void *value;
  480. int ret = CS_OK;
  481. objdb_value_types_t type;
  482. char * key_name = (char*)req_lib_confdb_key_get->key_name.value;
  483. key_name[req_lib_confdb_key_get->key_name.length] = '\0';
  484. if (api->object_key_get_typed(req_lib_confdb_key_get->parent_object_handle,
  485. key_name,
  486. &value,
  487. &value_len, &type))
  488. ret = CS_ERR_ACCESS;
  489. else {
  490. if (value_len > CS_MAX_NAME_LENGTH) {
  491. ret = CS_ERR_TOO_BIG;
  492. } else {
  493. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  494. }
  495. res_lib_confdb_key_get.value.length = value_len;
  496. res_lib_confdb_key_get.type = type;
  497. }
  498. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  499. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET_TYPED;
  500. res_lib_confdb_key_get.header.error = ret;
  501. api->ipc_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  502. }
  503. static void message_handler_req_lib_confdb_key_get_typed2 (void *conn,
  504. const void *message)
  505. {
  506. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  507. struct res_lib_confdb_key_get_typed2 res_lib_confdb_key_get;
  508. struct res_lib_confdb_key_get_typed2 *res = &res_lib_confdb_key_get;
  509. size_t value_len;
  510. void *value;
  511. int ret = CS_OK;
  512. objdb_value_types_t type;
  513. char * key_name = (char*)req_lib_confdb_key_get->key_name.value;
  514. key_name[req_lib_confdb_key_get->key_name.length] = '\0';
  515. if (api->object_key_get_typed(req_lib_confdb_key_get->parent_object_handle,
  516. key_name,
  517. &value,
  518. &value_len, &type)) {
  519. ret = CS_ERR_ACCESS;
  520. res->header.size = sizeof(res_lib_confdb_key_get);
  521. }
  522. else {
  523. res = alloca(sizeof(struct res_lib_confdb_key_get_typed2) + value_len);
  524. memcpy(&res->value, value, value_len);
  525. res->value_length = value_len;
  526. res->type = type;
  527. res->header.size = sizeof(struct res_lib_confdb_key_get_typed2)+value_len;
  528. res->header.error = ret;
  529. }
  530. res->header.id = MESSAGE_RES_CONFDB_KEY_GET_TYPED2;
  531. res->header.error = ret;
  532. api->ipc_response_send(conn, res, res->header.size);
  533. }
  534. static void message_handler_req_lib_confdb_key_increment (void *conn,
  535. const void *message)
  536. {
  537. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  538. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  539. int ret = CS_OK;
  540. if (api->object_key_increment(req_lib_confdb_key_get->parent_object_handle,
  541. req_lib_confdb_key_get->key_name.value,
  542. req_lib_confdb_key_get->key_name.length,
  543. &res_lib_confdb_key_incdec.value))
  544. ret = CS_ERR_ACCESS;
  545. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  546. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_INCREMENT;
  547. res_lib_confdb_key_incdec.header.error = ret;
  548. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  549. }
  550. static void message_handler_req_lib_confdb_key_decrement (void *conn,
  551. const void *message)
  552. {
  553. const struct req_lib_confdb_key_get *req_lib_confdb_key_get = message;
  554. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  555. int ret = CS_OK;
  556. if (api->object_key_decrement(req_lib_confdb_key_get->parent_object_handle,
  557. req_lib_confdb_key_get->key_name.value,
  558. req_lib_confdb_key_get->key_name.length,
  559. &res_lib_confdb_key_incdec.value))
  560. ret = CS_ERR_ACCESS;
  561. res_lib_confdb_key_incdec.header.size = sizeof(res_lib_confdb_key_incdec);
  562. res_lib_confdb_key_incdec.header.id = MESSAGE_RES_CONFDB_KEY_DECREMENT;
  563. res_lib_confdb_key_incdec.header.error = ret;
  564. api->ipc_response_send(conn, &res_lib_confdb_key_incdec, sizeof(res_lib_confdb_key_incdec));
  565. }
  566. static void message_handler_req_lib_confdb_key_replace (void *conn,
  567. const void *message)
  568. {
  569. const struct req_lib_confdb_key_replace *req_lib_confdb_key_replace
  570. = message;
  571. coroipc_response_header_t res;
  572. int ret = CS_OK;
  573. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  574. req_lib_confdb_key_replace->key_name.value,
  575. req_lib_confdb_key_replace->key_name.length,
  576. req_lib_confdb_key_replace->new_value.value,
  577. req_lib_confdb_key_replace->new_value.length))
  578. ret = CS_ERR_ACCESS;
  579. res.size = sizeof(res);
  580. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  581. res.error = ret;
  582. api->ipc_response_send(conn, &res, sizeof(res));
  583. }
  584. static void message_handler_req_lib_confdb_key_delete (void *conn,
  585. const void *message)
  586. {
  587. const struct req_lib_confdb_key_delete *req_lib_confdb_key_delete
  588. = message;
  589. coroipc_response_header_t res;
  590. int ret = CS_OK;
  591. if (api->object_key_delete(req_lib_confdb_key_delete->object_handle,
  592. req_lib_confdb_key_delete->key_name.value,
  593. req_lib_confdb_key_delete->key_name.length))
  594. ret = CS_ERR_ACCESS;
  595. res.size = sizeof(res);
  596. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  597. res.error = ret;
  598. api->ipc_response_send(conn, &res, sizeof(res));
  599. }
  600. static void message_handler_req_lib_confdb_object_parent_get (void *conn,
  601. const void *message)
  602. {
  603. const struct req_lib_confdb_object_parent_get
  604. *req_lib_confdb_object_parent_get = message;
  605. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  606. hdb_handle_t object_handle;
  607. int ret = CS_OK;
  608. if (api->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  609. &object_handle))
  610. ret = CS_ERR_ACCESS;
  611. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  612. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  613. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  614. res_lib_confdb_object_parent_get.header.error = ret;
  615. api->ipc_response_send(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  616. }
  617. static void message_handler_req_lib_confdb_object_name_get (void *conn,
  618. const void *message)
  619. {
  620. const struct req_lib_confdb_object_name_get *request = message;
  621. struct res_lib_confdb_object_name_get response;
  622. int ret = CS_OK;
  623. char object_name[CS_MAX_NAME_LENGTH];
  624. size_t object_name_len;
  625. if (api->object_name_get(request->object_handle,
  626. object_name, &object_name_len)) {
  627. ret = CS_ERR_ACCESS;
  628. }
  629. response.object_name.length = object_name_len;
  630. strncpy((char*)response.object_name.value, object_name, CS_MAX_NAME_LENGTH);
  631. response.object_name.value[CS_MAX_NAME_LENGTH-1] = '\0';
  632. response.header.size = sizeof(response);
  633. response.header.id = MESSAGE_RES_CONFDB_OBJECT_NAME_GET;
  634. response.header.error = ret;
  635. api->ipc_response_send(conn, &response, sizeof(response));
  636. }
  637. static void message_handler_req_lib_confdb_key_iter (void *conn,
  638. const void *message)
  639. {
  640. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  641. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  642. void *key_name;
  643. size_t key_name_len;
  644. void *value;
  645. size_t value_len;
  646. int ret = CS_OK;
  647. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  648. req_lib_confdb_key_iter->next_entry,
  649. &key_name,
  650. &key_name_len,
  651. &value,
  652. &value_len))
  653. ret = CS_ERR_ACCESS;
  654. else {
  655. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  656. if (value_len > CS_MAX_NAME_LENGTH) {
  657. ret = CS_ERR_TOO_BIG;
  658. } else {
  659. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  660. }
  661. res_lib_confdb_key_iter.key_name.length = key_name_len;
  662. res_lib_confdb_key_iter.value.length = value_len;
  663. }
  664. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  665. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  666. res_lib_confdb_key_iter.header.error = ret;
  667. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  668. }
  669. static void message_handler_req_lib_confdb_key_iter_typed (void *conn,
  670. const void *message)
  671. {
  672. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  673. struct res_lib_confdb_key_iter_typed res_lib_confdb_key_iter;
  674. void *key_name;
  675. size_t key_name_len;
  676. void *value;
  677. size_t value_len;
  678. int ret = CS_OK;
  679. objdb_value_types_t my_type;
  680. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  681. req_lib_confdb_key_iter->next_entry,
  682. &key_name,
  683. &key_name_len,
  684. &value,
  685. &value_len))
  686. ret = CS_ERR_ACCESS;
  687. else {
  688. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  689. if (value_len > CS_MAX_NAME_LENGTH) {
  690. ret = CS_ERR_TOO_BIG;
  691. } else {
  692. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  693. }
  694. res_lib_confdb_key_iter.key_name.length = key_name_len;
  695. res_lib_confdb_key_iter.key_name.value[key_name_len] = '\0';
  696. res_lib_confdb_key_iter.value.length = value_len;
  697. api->object_key_get_typed(req_lib_confdb_key_iter->parent_object_handle,
  698. (const char*)res_lib_confdb_key_iter.key_name.value,
  699. &value,
  700. &value_len,
  701. &my_type);
  702. res_lib_confdb_key_iter.type = my_type;
  703. }
  704. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  705. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER_TYPED;
  706. res_lib_confdb_key_iter.header.error = ret;
  707. api->ipc_response_send(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  708. }
  709. static void message_handler_req_lib_confdb_key_iter_typed2 (void *conn,
  710. const void *message)
  711. {
  712. const struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = message;
  713. struct res_lib_confdb_key_iter_typed2 res_lib_confdb_key_iter;
  714. struct res_lib_confdb_key_iter_typed2 *res = &res_lib_confdb_key_iter;
  715. void *key_name;
  716. size_t key_name_len;
  717. void *value;
  718. size_t value_len;
  719. int ret = CS_OK;
  720. objdb_value_types_t my_type;
  721. if (api->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  722. req_lib_confdb_key_iter->next_entry,
  723. &key_name,
  724. &key_name_len,
  725. &value,
  726. &value_len)) {
  727. ret = CS_ERR_ACCESS;
  728. res->header.size = sizeof(res_lib_confdb_key_iter);
  729. }
  730. else {
  731. res = alloca(sizeof(struct res_lib_confdb_key_iter_typed2) + value_len);
  732. memcpy(res->key_name.value, key_name, key_name_len);
  733. res->key_name.length = key_name_len;
  734. res->key_name.value[key_name_len] = '\0';
  735. memcpy(&res->value, value, value_len);
  736. res->value_length = value_len;
  737. api->object_key_get_typed(req_lib_confdb_key_iter->parent_object_handle,
  738. (const char*)res->key_name.value,
  739. &value,
  740. &value_len,
  741. &my_type);
  742. res->type = my_type;
  743. res->header.size = sizeof(res_lib_confdb_key_iter)+value_len;
  744. }
  745. res->header.id = MESSAGE_RES_CONFDB_KEY_ITER_TYPED2;
  746. res->header.error = ret;
  747. api->ipc_response_send(conn, res, res->header.size);
  748. }
  749. static void message_handler_req_lib_confdb_object_iter (void *conn,
  750. const void *message)
  751. {
  752. const struct req_lib_confdb_object_iter *req_lib_confdb_object_iter
  753. = message;
  754. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  755. size_t object_name_len;
  756. int ret = CS_OK;
  757. if (!req_lib_confdb_object_iter->find_handle) {
  758. if (api->object_find_create(req_lib_confdb_object_iter->parent_object_handle,
  759. NULL, 0,
  760. m2h(&res_lib_confdb_object_iter.find_handle)) == -1) {
  761. ret = CS_ERR_ACCESS;
  762. goto response_send;
  763. }
  764. }
  765. else
  766. res_lib_confdb_object_iter.find_handle = req_lib_confdb_object_iter->find_handle;
  767. if (api->object_find_next(res_lib_confdb_object_iter.find_handle,
  768. m2h(&res_lib_confdb_object_iter.object_handle))) {
  769. ret = CS_ERR_ACCESS;
  770. api->object_find_destroy(res_lib_confdb_object_iter.find_handle);
  771. }
  772. else {
  773. if (api->object_name_get(res_lib_confdb_object_iter.object_handle,
  774. (char *)res_lib_confdb_object_iter.object_name.value,
  775. &object_name_len) == -1) {
  776. ret = CS_ERR_ACCESS;
  777. goto response_send;
  778. } else {
  779. res_lib_confdb_object_iter.object_name.length = object_name_len;
  780. }
  781. }
  782. response_send:
  783. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  784. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  785. res_lib_confdb_object_iter.header.error = ret;
  786. api->ipc_response_send(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  787. }
  788. static void message_handler_req_lib_confdb_object_find (void *conn,
  789. const void *message)
  790. {
  791. const struct req_lib_confdb_object_find *req_lib_confdb_object_find
  792. = message;
  793. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  794. int ret = CS_OK;
  795. if (!req_lib_confdb_object_find->find_handle) {
  796. if (api->object_find_create(req_lib_confdb_object_find->parent_object_handle,
  797. req_lib_confdb_object_find->object_name.value,
  798. req_lib_confdb_object_find->object_name.length,
  799. m2h(&res_lib_confdb_object_find.find_handle)) == -1) {
  800. ret = CS_ERR_ACCESS;
  801. goto response_send;
  802. }
  803. }
  804. else
  805. res_lib_confdb_object_find.find_handle = req_lib_confdb_object_find->find_handle;
  806. if (api->object_find_next(res_lib_confdb_object_find.find_handle,
  807. m2h(&res_lib_confdb_object_find.object_handle))) {
  808. ret = CS_ERR_ACCESS;
  809. api->object_find_destroy(res_lib_confdb_object_find.find_handle);
  810. }
  811. response_send:
  812. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  813. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  814. res_lib_confdb_object_find.header.error = ret;
  815. api->ipc_response_send(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  816. }
  817. static void message_handler_req_lib_confdb_write (void *conn,
  818. const void *message)
  819. {
  820. struct res_lib_confdb_write res_lib_confdb_write;
  821. int ret = CS_OK;
  822. const char *error_string = NULL;
  823. if (api->object_write_config(&error_string))
  824. ret = CS_ERR_ACCESS;
  825. res_lib_confdb_write.header.size = sizeof(res_lib_confdb_write);
  826. res_lib_confdb_write.header.id = MESSAGE_RES_CONFDB_WRITE;
  827. res_lib_confdb_write.header.error = ret;
  828. if (error_string) {
  829. strcpy((char *)res_lib_confdb_write.error.value, error_string);
  830. res_lib_confdb_write.error.length = strlen(error_string) + 1;
  831. } else
  832. res_lib_confdb_write.error.length = 0;
  833. api->ipc_response_send(conn, &res_lib_confdb_write, sizeof(res_lib_confdb_write));
  834. }
  835. static void message_handler_req_lib_confdb_reload (void *conn,
  836. const void *message)
  837. {
  838. const struct req_lib_confdb_reload *req_lib_confdb_reload = message;
  839. struct res_lib_confdb_reload res_lib_confdb_reload;
  840. int ret = CS_OK;
  841. const char *error_string = NULL;
  842. if (api->object_reload_config(req_lib_confdb_reload->flush, &error_string))
  843. ret = CS_ERR_ACCESS;
  844. res_lib_confdb_reload.header.size = sizeof(res_lib_confdb_reload);
  845. res_lib_confdb_reload.header.id = MESSAGE_RES_CONFDB_RELOAD;
  846. res_lib_confdb_reload.header.error = ret;
  847. if(error_string) {
  848. strcpy((char *)res_lib_confdb_reload.error.value, error_string);
  849. res_lib_confdb_reload.error.length = strlen(error_string) + 1;
  850. } else
  851. res_lib_confdb_reload.error.length = 0;
  852. api->ipc_response_send(conn, &res_lib_confdb_reload, sizeof(res_lib_confdb_reload));
  853. }
  854. static int objdb_notify_dispatch(hdb_handle_t handle,
  855. int fd, int revents, void *data)
  856. {
  857. struct confdb_ipc_message_holder *holder;
  858. ssize_t rc;
  859. char pipe_cmd;
  860. if (revents & POLLHUP) {
  861. return -1;
  862. }
  863. pthread_mutex_lock (&confdb_ipc_message_holder_list_mutex);
  864. retry_read:
  865. rc = read(fd, &pipe_cmd, sizeof(pipe_cmd));
  866. if (rc == sizeof(pipe_cmd)) {
  867. goto retry_read; /* Flush whole buffer */
  868. }
  869. if (rc == -1) {
  870. if (errno == EINTR) {
  871. goto retry_read;
  872. }
  873. if (errno != EAGAIN && errno != EWOULDBLOCK) {
  874. goto unlock_exit;
  875. }
  876. } else {
  877. goto unlock_exit; /* rc != -1 && rc != 1 -> end of file */
  878. }
  879. while (!list_empty (&confdb_ipc_message_holder_list_head)) {
  880. holder = list_entry (confdb_ipc_message_holder_list_head.next,
  881. struct confdb_ipc_message_holder, list);
  882. list_del (&holder->list);
  883. /*
  884. * All list operations are done now, so unlock list mutex to
  885. * prevent deadlock in IPC.
  886. */
  887. pthread_mutex_unlock (&confdb_ipc_message_holder_list_mutex);
  888. api->ipc_dispatch_send(holder->conn, holder->msg, holder->mlen);
  889. api->ipc_refcnt_dec(holder->conn);
  890. free(holder);
  891. /*
  892. * Next operation is again list one, so lock list again.
  893. */
  894. pthread_mutex_lock (&confdb_ipc_message_holder_list_mutex);
  895. }
  896. unlock_exit:
  897. pthread_mutex_unlock (&confdb_ipc_message_holder_list_mutex);
  898. return 0;
  899. }
  900. static int32_t ipc_dispatch_send_from_poll_thread(void *conn, const void *msg, size_t mlen)
  901. {
  902. struct confdb_ipc_message_holder *holder;
  903. ssize_t written;
  904. size_t holder_size;
  905. char pipe_cmd;
  906. api->ipc_refcnt_inc(conn);
  907. holder_size = sizeof (*holder) + mlen;
  908. holder = malloc (holder_size);
  909. if (holder == NULL) {
  910. api->ipc_refcnt_dec(conn);
  911. return -1;
  912. }
  913. memset(holder, 0, holder_size);
  914. holder->conn = conn;
  915. holder->mlen = mlen;
  916. memcpy(holder->msg, msg, mlen);
  917. list_init(&holder->list);
  918. pthread_mutex_lock (&confdb_ipc_message_holder_list_mutex);
  919. list_add_tail (&holder->list, &confdb_ipc_message_holder_list_head);
  920. pipe_cmd = 'M'; /* Message */
  921. retry_write:
  922. written = write(notify_pipe[1], &pipe_cmd, sizeof(pipe_cmd));
  923. if (written == -1) {
  924. if (errno == EINTR) {
  925. goto retry_write;
  926. }
  927. if (errno != EAGAIN && errno != EWOULDBLOCK) {
  928. /*
  929. * Different error then EINTR or BLOCK -> exit with error
  930. */
  931. goto refcnt_del_unlock_exit;
  932. }
  933. } else if (written != sizeof (pipe_cmd)) {
  934. goto refcnt_del_unlock_exit;
  935. }
  936. pthread_mutex_unlock (&confdb_ipc_message_holder_list_mutex);
  937. return 0;
  938. refcnt_del_unlock_exit:
  939. list_del (&holder->list);
  940. free(holder);
  941. api->ipc_refcnt_dec(conn);
  942. pthread_mutex_unlock (&confdb_ipc_message_holder_list_mutex);
  943. return -1;
  944. }
  945. static void confdb_notify_lib_of_key_change(object_change_type_t change_type,
  946. hdb_handle_t parent_object_handle,
  947. hdb_handle_t object_handle,
  948. const void *object_name_pt, size_t object_name_len,
  949. const void *key_name_pt, size_t key_name_len,
  950. const void *key_value_pt, size_t key_value_len,
  951. void *priv_data_pt)
  952. {
  953. struct res_lib_confdb_key_change_callback2 *res;
  954. res = alloca(sizeof(struct res_lib_confdb_key_change_callback2) + key_value_len);
  955. res->header.size = sizeof(struct res_lib_confdb_key_change_callback2) + key_value_len;
  956. res->header.id = MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK2;
  957. res->header.error = CS_OK;
  958. // handle & type
  959. res->change_type = change_type;
  960. res->parent_object_handle = parent_object_handle;
  961. res->object_handle = object_handle;
  962. //object
  963. memcpy(res->object_name.value, object_name_pt, object_name_len);
  964. res->object_name.length = object_name_len;
  965. //key name
  966. memcpy(res->key_name.value, key_name_pt, key_name_len);
  967. res->key_name.length = key_name_len;
  968. //key value
  969. memcpy(&res->key_value, key_value_pt, key_value_len);
  970. res->key_value_length = key_value_len;
  971. ipc_dispatch_send_from_poll_thread(priv_data_pt, res, res->header.size);
  972. }
  973. static void confdb_notify_lib_of_new_object(hdb_handle_t parent_object_handle,
  974. hdb_handle_t object_handle,
  975. const void *name_pt, size_t name_len,
  976. void *priv_data_pt)
  977. {
  978. struct res_lib_confdb_object_create_callback res;
  979. res.header.size = sizeof(res);
  980. res.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK;
  981. res.header.error = CS_OK;
  982. res.parent_object_handle = parent_object_handle;
  983. res.object_handle = object_handle;
  984. memcpy(res.name.value, name_pt, name_len);
  985. res.name.length = name_len;
  986. ipc_dispatch_send_from_poll_thread(priv_data_pt, &res, sizeof(res));
  987. }
  988. static void confdb_notify_lib_of_destroyed_object(
  989. hdb_handle_t parent_object_handle,
  990. const void *name_pt, size_t name_len,
  991. void *priv_data_pt)
  992. {
  993. struct res_lib_confdb_object_destroy_callback res;
  994. res.header.size = sizeof(res);
  995. res.header.id = MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK;
  996. res.header.error = CS_OK;
  997. res.parent_object_handle = parent_object_handle;
  998. memcpy(res.name.value, name_pt, name_len);
  999. res.name.length = name_len;
  1000. ipc_dispatch_send_from_poll_thread(priv_data_pt, &res, sizeof(res));
  1001. }
  1002. static void confdb_notify_lib_of_reload(objdb_reload_notify_type_t notify_type,
  1003. int flush,
  1004. void *priv_data_pt)
  1005. {
  1006. struct res_lib_confdb_reload_callback res;
  1007. res.header.size = sizeof(res);
  1008. res.header.id = MESSAGE_RES_CONFDB_RELOAD_CALLBACK;
  1009. res.header.error = CS_OK;
  1010. res.type = notify_type;
  1011. ipc_dispatch_send_from_poll_thread(priv_data_pt, &res, sizeof(res));
  1012. }
  1013. static void message_handler_req_lib_confdb_track_start (void *conn,
  1014. const void *message)
  1015. {
  1016. const struct req_lib_confdb_object_track_start *req = message;
  1017. coroipc_response_header_t res;
  1018. api->object_track_start(req->object_handle,
  1019. req->flags,
  1020. confdb_notify_lib_of_key_change,
  1021. confdb_notify_lib_of_new_object,
  1022. confdb_notify_lib_of_destroyed_object,
  1023. confdb_notify_lib_of_reload,
  1024. conn);
  1025. res.size = sizeof(res);
  1026. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  1027. res.error = CS_OK;
  1028. api->ipc_response_send(conn, &res, sizeof(res));
  1029. }
  1030. static void message_handler_req_lib_confdb_track_stop (void *conn,
  1031. const void *message)
  1032. {
  1033. coroipc_response_header_t res;
  1034. api->object_track_stop(confdb_notify_lib_of_key_change,
  1035. confdb_notify_lib_of_new_object,
  1036. confdb_notify_lib_of_destroyed_object,
  1037. confdb_notify_lib_of_reload,
  1038. conn);
  1039. res.size = sizeof(res);
  1040. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  1041. res.error = CS_OK;
  1042. api->ipc_response_send(conn, &res, sizeof(res));
  1043. }
  1044. static void message_handler_req_lib_confdb_key_create_typed2 (void *conn,
  1045. const void *message)
  1046. {
  1047. const struct req_lib_confdb_key_create_typed2 *req_lib_confdb_key_create
  1048. = message;
  1049. coroipc_response_header_t res;
  1050. int ret = CS_OK;
  1051. if (api->object_key_create_typed(req_lib_confdb_key_create->object_handle,
  1052. (char*)req_lib_confdb_key_create->key_name.value,
  1053. &req_lib_confdb_key_create->value,
  1054. req_lib_confdb_key_create->value_length,
  1055. req_lib_confdb_key_create->type))
  1056. ret = CS_ERR_ACCESS;
  1057. res.size = sizeof(res);
  1058. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  1059. res.error = ret;
  1060. api->ipc_response_send(conn, &res, sizeof(res));
  1061. }
  1062. static void message_handler_req_lib_confdb_key_replace2 (void *conn,
  1063. const void *message)
  1064. {
  1065. const struct req_lib_confdb_key_replace2 *req_lib_confdb_key_replace
  1066. = message;
  1067. coroipc_response_header_t res;
  1068. int ret = CS_OK;
  1069. if (api->object_key_replace(req_lib_confdb_key_replace->object_handle,
  1070. req_lib_confdb_key_replace->key_name.value,
  1071. req_lib_confdb_key_replace->key_name.length,
  1072. &req_lib_confdb_key_replace->new_value,
  1073. req_lib_confdb_key_replace->new_value_length))
  1074. ret = CS_ERR_ACCESS;
  1075. res.size = sizeof(res);
  1076. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  1077. res.error = ret;
  1078. api->ipc_response_send(conn, &res, sizeof(res));
  1079. }