confdb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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 "main.h"
  46. #include "flow.h"
  47. #include "ipc.h"
  48. #include "objdb.h"
  49. #include "service.h"
  50. #include "ipc.h"
  51. #include "logsys.h"
  52. LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_INFO);
  53. static struct objdb_iface_ver0 *global_objdb;
  54. static int confdb_exec_init_fn (struct objdb_iface_ver0 *objdb);
  55. static int confdb_lib_init_fn (void *conn);
  56. static int confdb_lib_exit_fn (void *conn);
  57. static void message_handler_req_lib_confdb_object_create (void *conn, void *message);
  58. static void message_handler_req_lib_confdb_object_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_track_start (void *conn, void *message);
  68. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message);
  69. /*
  70. * Library Handler Definition
  71. */
  72. static struct openais_lib_handler confdb_lib_service[] =
  73. {
  74. { /* 0 */
  75. .lib_handler_fn = message_handler_req_lib_confdb_object_create,
  76. .response_size = sizeof (mar_res_header_t),
  77. .response_id = MESSAGE_RES_CONFDB_OBJECT_CREATE,
  78. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  79. },
  80. { /* 1 */
  81. .lib_handler_fn = message_handler_req_lib_confdb_object_destroy,
  82. .response_size = sizeof (mar_res_header_t),
  83. .response_id = MESSAGE_RES_CONFDB_OBJECT_DESTROY,
  84. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  85. },
  86. { /* 2 */
  87. .lib_handler_fn = message_handler_req_lib_confdb_object_find,
  88. .response_size = sizeof (struct res_lib_confdb_object_find),
  89. .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND,
  90. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  91. },
  92. { /* 3 */
  93. .lib_handler_fn = message_handler_req_lib_confdb_key_create,
  94. .response_size = sizeof (mar_res_header_t),
  95. .response_id = MESSAGE_RES_CONFDB_KEY_CREATE,
  96. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  97. },
  98. { /* 4 */
  99. .lib_handler_fn = message_handler_req_lib_confdb_key_get,
  100. .response_size = sizeof (struct res_lib_confdb_key_get),
  101. .response_id = MESSAGE_RES_CONFDB_KEY_GET,
  102. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  103. },
  104. { /* 5 */
  105. .lib_handler_fn = message_handler_req_lib_confdb_key_replace,
  106. .response_size = sizeof (mar_res_header_t),
  107. .response_id = MESSAGE_RES_CONFDB_KEY_REPLACE,
  108. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  109. },
  110. { /* 6 */
  111. .lib_handler_fn = message_handler_req_lib_confdb_key_delete,
  112. .response_size = sizeof (mar_res_header_t),
  113. .response_id = MESSAGE_RES_CONFDB_KEY_DELETE,
  114. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  115. },
  116. { /* 7 */
  117. .lib_handler_fn = message_handler_req_lib_confdb_object_iter,
  118. .response_size = sizeof (struct res_lib_confdb_object_iter),
  119. .response_id = MESSAGE_RES_CONFDB_OBJECT_ITER,
  120. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  121. },
  122. { /* 8 */
  123. .lib_handler_fn = message_handler_req_lib_confdb_object_parent_get,
  124. .response_size = sizeof (struct res_lib_confdb_object_parent_get),
  125. .response_id = MESSAGE_RES_CONFDB_OBJECT_PARENT_GET,
  126. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  127. },
  128. { /* 9 */
  129. .lib_handler_fn = message_handler_req_lib_confdb_key_iter,
  130. .response_size = sizeof (struct res_lib_confdb_key_iter),
  131. .response_id = MESSAGE_RES_CONFDB_KEY_ITER,
  132. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  133. },
  134. { /* 10 */
  135. .lib_handler_fn = message_handler_req_lib_confdb_track_start,
  136. .response_size = sizeof (mar_res_header_t),
  137. .response_id = MESSAGE_RES_CONFDB_TRACK_START,
  138. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  139. },
  140. { /* 11 */
  141. .lib_handler_fn = message_handler_req_lib_confdb_track_stop,
  142. .response_size = sizeof (mar_res_header_t),
  143. .response_id = MESSAGE_RES_CONFDB_TRACK_START,
  144. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  145. },
  146. };
  147. struct openais_service_handler confdb_service_handler = {
  148. .name = "openais cluster config database access v1.01",
  149. .id = CONFDB_SERVICE,
  150. .private_data_size = 0,
  151. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
  152. .lib_init_fn = confdb_lib_init_fn,
  153. .lib_exit_fn = confdb_lib_exit_fn,
  154. .lib_service = confdb_lib_service,
  155. .lib_service_count = sizeof (confdb_lib_service) / sizeof (struct openais_lib_handler),
  156. .exec_init_fn = confdb_exec_init_fn,
  157. };
  158. /*
  159. * Dynamic loader definition
  160. */
  161. static struct openais_service_handler *confdb_get_service_handler_ver0 (void);
  162. static struct openais_service_handler_iface_ver0 confdb_service_handler_iface = {
  163. .openais_get_service_handler_ver0 = confdb_get_service_handler_ver0
  164. };
  165. static struct lcr_iface openais_confdb_ver0[1] = {
  166. {
  167. .name = "openais_confdb",
  168. .version = 0,
  169. .versions_replace = 0,
  170. .versions_replace_count = 0,
  171. .dependencies = 0,
  172. .dependency_count = 0,
  173. .constructor = NULL,
  174. .destructor = NULL,
  175. .interfaces = NULL
  176. }
  177. };
  178. static struct lcr_comp confdb_comp_ver0 = {
  179. .iface_count = 1,
  180. .ifaces = openais_confdb_ver0
  181. };
  182. static struct openais_service_handler *confdb_get_service_handler_ver0 (void)
  183. {
  184. return (&confdb_service_handler);
  185. }
  186. __attribute__ ((constructor)) static void confdb_comp_register (void) {
  187. lcr_interfaces_set (&openais_confdb_ver0[0], &confdb_service_handler_iface);
  188. lcr_component_register (&confdb_comp_ver0);
  189. }
  190. static int confdb_exec_init_fn (struct objdb_iface_ver0 *objdb)
  191. {
  192. global_objdb = objdb;
  193. return 0;
  194. }
  195. static int confdb_lib_init_fn (void *conn)
  196. {
  197. log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn);
  198. return (0);
  199. }
  200. static int confdb_lib_exit_fn (void *conn)
  201. {
  202. log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn);
  203. return (0);
  204. }
  205. static void message_handler_req_lib_confdb_object_create (void *conn, void *message)
  206. {
  207. struct req_lib_confdb_object_create *req_lib_confdb_object_create = (struct req_lib_confdb_object_create *)message;
  208. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  209. unsigned int object_handle;
  210. int ret = SA_AIS_OK;
  211. if (global_objdb->object_create(req_lib_confdb_object_create->parent_object_handle,
  212. &object_handle,
  213. req_lib_confdb_object_create->object_name.value,
  214. req_lib_confdb_object_create->object_name.length))
  215. ret = SA_AIS_ERR_ACCESS;
  216. res_lib_confdb_object_create.object_handle = object_handle;
  217. res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create);
  218. res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  219. res_lib_confdb_object_create.header.error = ret;
  220. openais_conn_send_response(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create));
  221. }
  222. static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message)
  223. {
  224. struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy = (struct req_lib_confdb_object_destroy *)message;
  225. mar_res_header_t res;
  226. int ret = SA_AIS_OK;
  227. if (global_objdb->object_destroy(req_lib_confdb_object_destroy->object_handle))
  228. ret = SA_AIS_ERR_ACCESS;
  229. res.size = sizeof(res);
  230. res.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  231. res.error = ret;
  232. openais_conn_send_response(conn, &res, sizeof(res));
  233. }
  234. static void message_handler_req_lib_confdb_key_create (void *conn, void *message)
  235. {
  236. struct req_lib_confdb_key_create *req_lib_confdb_key_create = (struct req_lib_confdb_key_create *)message;
  237. mar_res_header_t res;
  238. int ret = SA_AIS_OK;
  239. if (global_objdb->object_key_create(req_lib_confdb_key_create->object_handle,
  240. req_lib_confdb_key_create->key_name.value,
  241. req_lib_confdb_key_create->key_name.length,
  242. req_lib_confdb_key_create->value.value,
  243. req_lib_confdb_key_create->value.length))
  244. ret = SA_AIS_ERR_ACCESS;
  245. res.size = sizeof(res);
  246. res.id = MESSAGE_RES_CONFDB_KEY_CREATE;
  247. res.error = ret;
  248. openais_conn_send_response(conn, &res, sizeof(res));
  249. }
  250. static void message_handler_req_lib_confdb_key_get (void *conn, void *message)
  251. {
  252. struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message;
  253. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  254. int value_len;
  255. void *value;
  256. int ret = SA_AIS_OK;
  257. if (global_objdb->object_key_get(req_lib_confdb_key_get->parent_object_handle,
  258. req_lib_confdb_key_get->key_name.value,
  259. req_lib_confdb_key_get->key_name.length,
  260. &value,
  261. &value_len))
  262. ret = SA_AIS_ERR_ACCESS;
  263. else {
  264. memcpy(res_lib_confdb_key_get.value.value, value, value_len);
  265. res_lib_confdb_key_get.value.length = value_len;
  266. }
  267. res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get);
  268. res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET;
  269. res_lib_confdb_key_get.header.error = ret;
  270. openais_conn_send_response(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get));
  271. }
  272. static void message_handler_req_lib_confdb_key_replace (void *conn, void *message)
  273. {
  274. struct req_lib_confdb_key_replace *req_lib_confdb_key_replace = (struct req_lib_confdb_key_replace *)message;
  275. mar_res_header_t res;
  276. int ret = SA_AIS_OK;
  277. if (global_objdb->object_key_replace(req_lib_confdb_key_replace->object_handle,
  278. req_lib_confdb_key_replace->key_name.value,
  279. req_lib_confdb_key_replace->key_name.length,
  280. req_lib_confdb_key_replace->old_value.value,
  281. req_lib_confdb_key_replace->old_value.length,
  282. req_lib_confdb_key_replace->new_value.value,
  283. req_lib_confdb_key_replace->new_value.length))
  284. ret = SA_AIS_ERR_ACCESS;
  285. res.size = sizeof(res);
  286. res.id = MESSAGE_RES_CONFDB_KEY_REPLACE;
  287. res.error = ret;
  288. openais_conn_send_response(conn, &res, sizeof(res));
  289. }
  290. static void message_handler_req_lib_confdb_key_delete (void *conn, void *message)
  291. {
  292. struct req_lib_confdb_key_delete *req_lib_confdb_key_delete = (struct req_lib_confdb_key_delete *)message;
  293. mar_res_header_t res;
  294. int ret = SA_AIS_OK;
  295. if (global_objdb->object_key_delete(req_lib_confdb_key_delete->object_handle,
  296. req_lib_confdb_key_delete->key_name.value,
  297. req_lib_confdb_key_delete->key_name.length,
  298. req_lib_confdb_key_delete->value.value,
  299. req_lib_confdb_key_delete->value.length))
  300. ret = SA_AIS_ERR_ACCESS;
  301. res.size = sizeof(res);
  302. res.id = MESSAGE_RES_CONFDB_KEY_DELETE;
  303. res.error = ret;
  304. openais_conn_send_response(conn, &res, sizeof(res));
  305. }
  306. static void message_handler_req_lib_confdb_object_parent_get (void *conn, void *message)
  307. {
  308. struct req_lib_confdb_object_parent_get *req_lib_confdb_object_parent_get = (struct req_lib_confdb_object_parent_get *)message;
  309. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  310. unsigned int object_handle;
  311. int ret = SA_AIS_OK;
  312. if (global_objdb->object_parent_get(req_lib_confdb_object_parent_get->object_handle,
  313. &object_handle))
  314. ret = SA_AIS_ERR_ACCESS;
  315. res_lib_confdb_object_parent_get.parent_object_handle = object_handle;
  316. res_lib_confdb_object_parent_get.header.size = sizeof(res_lib_confdb_object_parent_get);
  317. res_lib_confdb_object_parent_get.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE;
  318. res_lib_confdb_object_parent_get.header.error = ret;
  319. openais_conn_send_response(conn, &res_lib_confdb_object_parent_get, sizeof(res_lib_confdb_object_parent_get));
  320. }
  321. static void message_handler_req_lib_confdb_key_iter (void *conn, void *message)
  322. {
  323. struct req_lib_confdb_key_iter *req_lib_confdb_key_iter = (struct req_lib_confdb_key_iter *)message;
  324. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  325. void *key_name;
  326. int key_name_len;
  327. void *value;
  328. int value_len;
  329. int ret = SA_AIS_OK;
  330. if (global_objdb->object_key_iter_from(req_lib_confdb_key_iter->parent_object_handle,
  331. req_lib_confdb_key_iter->next_entry,
  332. &key_name,
  333. &key_name_len,
  334. &value,
  335. &value_len))
  336. ret = SA_AIS_ERR_ACCESS;
  337. else {
  338. memcpy(res_lib_confdb_key_iter.key_name.value, key_name, key_name_len);
  339. memcpy(res_lib_confdb_key_iter.value.value, value, value_len);
  340. res_lib_confdb_key_iter.key_name.length = key_name_len;
  341. res_lib_confdb_key_iter.value.length = value_len;
  342. }
  343. res_lib_confdb_key_iter.header.size = sizeof(res_lib_confdb_key_iter);
  344. res_lib_confdb_key_iter.header.id = MESSAGE_RES_CONFDB_KEY_ITER;
  345. res_lib_confdb_key_iter.header.error = ret;
  346. openais_conn_send_response(conn, &res_lib_confdb_key_iter, sizeof(res_lib_confdb_key_iter));
  347. }
  348. static void message_handler_req_lib_confdb_object_iter (void *conn, void *message)
  349. {
  350. struct req_lib_confdb_object_iter *req_lib_confdb_object_iter = (struct req_lib_confdb_object_iter *)message;
  351. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  352. void *object_name;
  353. int object_name_len;
  354. int ret = SA_AIS_OK;
  355. if (global_objdb->object_iter_from(req_lib_confdb_object_iter->parent_object_handle,
  356. req_lib_confdb_object_iter->next_entry,
  357. &object_name,
  358. &object_name_len,
  359. &res_lib_confdb_object_iter.object_handle))
  360. ret = SA_AIS_ERR_ACCESS;
  361. else {
  362. res_lib_confdb_object_iter.object_name.length = object_name_len;
  363. memcpy(res_lib_confdb_object_iter.object_name.value, object_name, object_name_len);
  364. }
  365. res_lib_confdb_object_iter.header.size = sizeof(res_lib_confdb_object_iter);
  366. res_lib_confdb_object_iter.header.id = MESSAGE_RES_CONFDB_OBJECT_ITER;
  367. res_lib_confdb_object_iter.header.error = ret;
  368. openais_conn_send_response(conn, &res_lib_confdb_object_iter, sizeof(res_lib_confdb_object_iter));
  369. }
  370. static void message_handler_req_lib_confdb_object_find (void *conn, void *message)
  371. {
  372. struct req_lib_confdb_object_find *req_lib_confdb_object_find = (struct req_lib_confdb_object_find *)message;
  373. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  374. int ret = SA_AIS_OK;
  375. if (global_objdb->object_find_from(req_lib_confdb_object_find->parent_object_handle,
  376. req_lib_confdb_object_find->next_entry,
  377. req_lib_confdb_object_find->object_name.value,
  378. req_lib_confdb_object_find->object_name.length,
  379. &res_lib_confdb_object_find.object_handle,
  380. &res_lib_confdb_object_find.next_entry))
  381. ret = SA_AIS_ERR_ACCESS;
  382. res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find);
  383. res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND;
  384. res_lib_confdb_object_find.header.error = ret;
  385. openais_conn_send_response(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find));
  386. }
  387. /* TODO: when we have notification in the objdb. */
  388. static void message_handler_req_lib_confdb_track_start (void *conn, void *message)
  389. {
  390. mar_res_header_t res;
  391. res.size = sizeof(res);
  392. res.id = MESSAGE_RES_CONFDB_TRACK_START;
  393. res.error = SA_AIS_ERR_NOT_SUPPORTED;
  394. openais_conn_send_response(conn, &res, sizeof(res));
  395. }
  396. static void message_handler_req_lib_confdb_track_stop (void *conn, void *message)
  397. {
  398. mar_res_header_t res;
  399. res.size = sizeof(res);
  400. res.id = MESSAGE_RES_CONFDB_TRACK_STOP;
  401. res.error = SA_AIS_ERR_NOT_SUPPORTED;
  402. openais_conn_send_response(conn, &res, sizeof(res));
  403. }