confdb.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  1. /*
  2. * Copyright (c) 2008-2009 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 CONTRIBUTORS "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. /*
  35. * Provides access to data in the corosync object database
  36. */
  37. #include <config.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include <pthread.h>
  42. #include <sys/types.h>
  43. #include <errno.h>
  44. #include <corosync/corotypes.h>
  45. #include <corosync/confdb.h>
  46. #include <corosync/ipc_confdb.h>
  47. #include <corosync/mar_gen.h>
  48. #include <corosync/coroipcc.h>
  49. #include <corosync/list.h>
  50. #include "sa-confdb.h"
  51. /* Hold the information for iterators so that
  52. callers can do recursive tree traversals.
  53. each object_handle can have its own iterator */
  54. struct iter_context {
  55. struct list_head list;
  56. hdb_handle_t parent_object_handle;
  57. hdb_handle_t find_handle;
  58. hdb_handle_t next_entry;
  59. };
  60. struct confdb_inst {
  61. void *ipc_ctx;
  62. int finalize;
  63. int standalone;
  64. confdb_callbacks_t callbacks;
  65. const void *context;
  66. pthread_mutex_t response_mutex;
  67. pthread_mutex_t dispatch_mutex;
  68. struct list_head object_find_head;
  69. struct list_head object_iter_head;
  70. struct list_head key_iter_head;
  71. };
  72. static void confdb_instance_destructor (void *instance);
  73. static struct saHandleDatabase confdb_handle_t_db = {
  74. .handleCount = 0,
  75. .handles = 0,
  76. .mutex = PTHREAD_MUTEX_INITIALIZER,
  77. .handleInstanceDestructor = confdb_instance_destructor
  78. };
  79. static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
  80. /* Safely tidy one iterator context list */
  81. static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
  82. {
  83. struct iter_context *context;
  84. struct list_head *iter, *tmp;
  85. for (iter = list->next, tmp = iter->next;
  86. iter != list; iter = tmp, tmp = iter->next) {
  87. context = list_entry (iter, struct iter_context, list);
  88. (void)do_find_destroy(confdb_inst, context->find_handle);
  89. free(context);
  90. }
  91. }
  92. /*
  93. * Clean up function for a confdb instance (confdb_initialize) handle
  94. */
  95. static void confdb_instance_destructor (void *instance)
  96. {
  97. struct confdb_inst *confdb_inst = instance;
  98. pthread_mutex_destroy (&confdb_inst->response_mutex);
  99. pthread_mutex_destroy (&confdb_inst->dispatch_mutex);
  100. }
  101. static struct iter_context *find_iter_context(struct list_head *list, hdb_handle_t object_handle)
  102. {
  103. struct iter_context *context;
  104. struct list_head *iter;
  105. for (iter = list->next;
  106. iter != list; iter = iter->next) {
  107. context = list_entry (iter, struct iter_context, list);
  108. if (context->parent_object_handle == object_handle)
  109. return context;
  110. }
  111. return NULL;
  112. }
  113. /**
  114. * @defgroup confdb_corosync
  115. * @ingroup corosync
  116. *
  117. * @{
  118. */
  119. cs_error_t confdb_initialize (
  120. confdb_handle_t *handle,
  121. confdb_callbacks_t *callbacks)
  122. {
  123. cs_error_t error;
  124. struct confdb_inst *confdb_inst;
  125. error = saHandleCreate (&confdb_handle_t_db, sizeof (struct confdb_inst), handle);
  126. if (error != CS_OK) {
  127. goto error_no_destroy;
  128. }
  129. error = saHandleInstanceGet (&confdb_handle_t_db, *handle, (void *)&confdb_inst);
  130. if (error != CS_OK) {
  131. goto error_destroy;
  132. }
  133. if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
  134. error = confdb_sa_init();
  135. confdb_inst->standalone = 1;
  136. }
  137. else {
  138. error = coroipcc_service_connect (IPC_SOCKET_NAME, CONFDB_SERVICE, &confdb_inst->ipc_ctx);
  139. }
  140. if (error != CS_OK)
  141. goto error_put_destroy;
  142. memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
  143. pthread_mutex_init (&confdb_inst->response_mutex, NULL);
  144. pthread_mutex_init (&confdb_inst->dispatch_mutex, NULL);
  145. list_init (&confdb_inst->object_find_head);
  146. list_init (&confdb_inst->object_iter_head);
  147. list_init (&confdb_inst->key_iter_head);
  148. (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
  149. return (CS_OK);
  150. error_put_destroy:
  151. (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
  152. error_destroy:
  153. (void)saHandleDestroy (&confdb_handle_t_db, *handle);
  154. error_no_destroy:
  155. return (error);
  156. }
  157. cs_error_t confdb_finalize (
  158. confdb_handle_t handle)
  159. {
  160. struct confdb_inst *confdb_inst;
  161. cs_error_t error;
  162. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  163. if (error != CS_OK) {
  164. return (error);
  165. }
  166. pthread_mutex_lock (&confdb_inst->response_mutex);
  167. /*
  168. * Another thread has already started finalizing
  169. */
  170. if (confdb_inst->finalize) {
  171. pthread_mutex_unlock (&confdb_inst->response_mutex);
  172. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  173. return (CS_ERR_BAD_HANDLE);
  174. }
  175. confdb_inst->finalize = 1;
  176. pthread_mutex_unlock (&confdb_inst->response_mutex);
  177. /* Free saved context handles */
  178. free_context_list(confdb_inst, &confdb_inst->object_find_head);
  179. free_context_list(confdb_inst, &confdb_inst->object_iter_head);
  180. free_context_list(confdb_inst, &confdb_inst->key_iter_head);
  181. if (!confdb_inst->standalone) {
  182. coroipcc_service_disconnect (confdb_inst->ipc_ctx);
  183. }
  184. (void)saHandleDestroy (&confdb_handle_t_db, handle);
  185. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  186. return (CS_OK);
  187. }
  188. cs_error_t confdb_fd_get (
  189. confdb_handle_t handle,
  190. int *fd)
  191. {
  192. cs_error_t error;
  193. struct confdb_inst *confdb_inst;
  194. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  195. if (error != CS_OK) {
  196. return (error);
  197. }
  198. *fd = coroipcc_fd_get (confdb_inst->ipc_ctx);
  199. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  200. return (CS_OK);
  201. }
  202. cs_error_t confdb_context_get (
  203. confdb_handle_t handle,
  204. const void **context)
  205. {
  206. cs_error_t error;
  207. struct confdb_inst *confdb_inst;
  208. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  209. if (error != CS_OK) {
  210. return (error);
  211. }
  212. *context = confdb_inst->context;
  213. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  214. return (CS_OK);
  215. }
  216. cs_error_t confdb_context_set (
  217. confdb_handle_t handle,
  218. const void *context)
  219. {
  220. cs_error_t error;
  221. struct confdb_inst *confdb_inst;
  222. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  223. if (error != CS_OK) {
  224. return (error);
  225. }
  226. confdb_inst->context = context;
  227. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  228. return (CS_OK);
  229. }
  230. struct confdb_res_overlay {
  231. mar_res_header_t header __attribute__((aligned(8)));
  232. char data[512000];
  233. };
  234. cs_error_t confdb_dispatch (
  235. confdb_handle_t handle,
  236. cs_dispatch_flags_t dispatch_types)
  237. {
  238. int timeout = -1;
  239. cs_error_t error;
  240. int cont = 1; /* always continue do loop except when set to 0 */
  241. int dispatch_avail;
  242. struct confdb_inst *confdb_inst;
  243. confdb_callbacks_t callbacks;
  244. struct res_lib_confdb_key_change_callback *res_key_changed_pt;
  245. struct res_lib_confdb_object_create_callback *res_object_created_pt;
  246. struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
  247. struct confdb_res_overlay dispatch_data;
  248. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  249. if (error != CS_OK) {
  250. return (error);
  251. }
  252. if (confdb_inst->standalone) {
  253. error = CS_ERR_NOT_SUPPORTED;
  254. goto error_put;
  255. }
  256. /*
  257. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  258. * wait indefinately for SA_DISPATCH_BLOCKING
  259. */
  260. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  261. timeout = 0;
  262. }
  263. do {
  264. pthread_mutex_lock (&confdb_inst->dispatch_mutex);
  265. dispatch_avail = coroipcc_dispatch_recv (confdb_inst->ipc_ctx,
  266. (void *)&dispatch_data,
  267. sizeof (dispatch_data),
  268. timeout);
  269. /*
  270. * Handle has been finalized in another thread
  271. */
  272. if (confdb_inst->finalize == 1) {
  273. error = CS_OK;
  274. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  275. goto error_put;
  276. }
  277. if (dispatch_avail == 0 && dispatch_types == CONFDB_DISPATCH_ALL) {
  278. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  279. break; /* exit do while cont is 1 loop */
  280. } else
  281. if (dispatch_avail == 0) {
  282. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  283. continue; /* next poll */
  284. }
  285. /*
  286. * Make copy of callbacks, message data, unlock instance, and call callback
  287. * A risk of this dispatch method is that the callback routines may
  288. * operate at the same time that confdbFinalize has been called.
  289. */
  290. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  291. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  292. /*
  293. * Dispatch incoming message
  294. */
  295. switch (dispatch_data.header.id) {
  296. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  297. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)&dispatch_data;
  298. callbacks.confdb_key_change_notify_fn(handle,
  299. res_key_changed_pt->change_type,
  300. res_key_changed_pt->object_handle,
  301. res_key_changed_pt->parent_object_handle,
  302. res_key_changed_pt->object_name.value,
  303. res_key_changed_pt->object_name.length,
  304. res_key_changed_pt->key_name.value,
  305. res_key_changed_pt->key_name.length,
  306. res_key_changed_pt->key_value.value,
  307. res_key_changed_pt->key_value.length);
  308. break;
  309. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  310. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)&dispatch_data;
  311. callbacks.confdb_object_create_change_notify_fn(handle,
  312. res_object_created_pt->object_handle,
  313. res_object_created_pt->parent_object_handle,
  314. res_object_created_pt->name.value,
  315. res_object_created_pt->name.length);
  316. break;
  317. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  318. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)&dispatch_data;
  319. callbacks.confdb_object_delete_change_notify_fn(handle,
  320. res_object_destroyed_pt->parent_object_handle,
  321. res_object_destroyed_pt->name.value,
  322. res_object_destroyed_pt->name.length);
  323. break;
  324. default:
  325. error = CS_ERR_LIBRARY;
  326. goto error_noput;
  327. break;
  328. }
  329. /*
  330. * Determine if more messages should be processed
  331. * */
  332. switch (dispatch_types) {
  333. case CONFDB_DISPATCH_ONE:
  334. cont = 0;
  335. break;
  336. case CONFDB_DISPATCH_ALL:
  337. break;
  338. case CONFDB_DISPATCH_BLOCKING:
  339. break;
  340. }
  341. } while (cont);
  342. error_put:
  343. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  344. error_noput:
  345. return (error);
  346. }
  347. cs_error_t confdb_object_create (
  348. confdb_handle_t handle,
  349. hdb_handle_t parent_object_handle,
  350. const void *object_name,
  351. int object_name_len,
  352. hdb_handle_t *object_handle)
  353. {
  354. cs_error_t error;
  355. struct confdb_inst *confdb_inst;
  356. struct iovec iov;
  357. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  358. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  359. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  360. if (error != CS_OK) {
  361. return (error);
  362. }
  363. if (confdb_inst->standalone) {
  364. error = CS_OK;
  365. if (confdb_sa_object_create(parent_object_handle,
  366. object_name, object_name_len,
  367. object_handle))
  368. error = CS_ERR_ACCESS;
  369. goto error_exit;
  370. }
  371. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  372. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  373. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  374. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  375. req_lib_confdb_object_create.object_name.length = object_name_len;
  376. iov.iov_base = (char *)&req_lib_confdb_object_create;
  377. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  378. pthread_mutex_lock (&confdb_inst->response_mutex);
  379. error = coroipcc_msg_send_reply_receive (
  380. confdb_inst->ipc_ctx,
  381. &iov,
  382. 1,
  383. &res_lib_confdb_object_create,
  384. sizeof (struct res_lib_confdb_object_create));
  385. pthread_mutex_unlock (&confdb_inst->response_mutex);
  386. if (error != CS_OK) {
  387. goto error_exit;
  388. }
  389. error = res_lib_confdb_object_create.header.error;
  390. *object_handle = res_lib_confdb_object_create.object_handle;
  391. error_exit:
  392. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  393. return (error);
  394. }
  395. cs_error_t confdb_object_destroy (
  396. confdb_handle_t handle,
  397. hdb_handle_t object_handle)
  398. {
  399. cs_error_t error;
  400. struct confdb_inst *confdb_inst;
  401. struct iovec iov;
  402. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  403. mar_res_header_t res;
  404. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  405. if (error != CS_OK) {
  406. return (error);
  407. }
  408. if (confdb_inst->standalone) {
  409. error = CS_OK;
  410. if (confdb_sa_object_destroy(object_handle))
  411. error = CS_ERR_ACCESS;
  412. goto error_exit;
  413. }
  414. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  415. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  416. req_lib_confdb_object_destroy.object_handle = object_handle;
  417. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  418. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  419. pthread_mutex_lock (&confdb_inst->response_mutex);
  420. error = coroipcc_msg_send_reply_receive (
  421. confdb_inst->ipc_ctx,
  422. &iov,
  423. 1,
  424. &res,
  425. sizeof (mar_res_header_t));
  426. pthread_mutex_unlock (&confdb_inst->response_mutex);
  427. if (error != CS_OK) {
  428. goto error_exit;
  429. }
  430. error = res.error;
  431. error_exit:
  432. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  433. return (error);
  434. }
  435. cs_error_t confdb_object_parent_get (
  436. confdb_handle_t handle,
  437. hdb_handle_t object_handle,
  438. hdb_handle_t *parent_object_handle)
  439. {
  440. cs_error_t error;
  441. struct confdb_inst *confdb_inst;
  442. struct iovec iov;
  443. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  444. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  445. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  446. if (error != CS_OK) {
  447. return (error);
  448. }
  449. if (confdb_inst->standalone) {
  450. error = CS_OK;
  451. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  452. error = CS_ERR_ACCESS;
  453. goto error_exit;
  454. }
  455. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  456. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  457. req_lib_confdb_object_parent_get.object_handle = object_handle;
  458. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  459. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  460. pthread_mutex_lock (&confdb_inst->response_mutex);
  461. error = coroipcc_msg_send_reply_receive (
  462. confdb_inst->ipc_ctx,
  463. &iov,
  464. 1,
  465. &res_lib_confdb_object_parent_get,
  466. sizeof (struct res_lib_confdb_object_parent_get));
  467. pthread_mutex_unlock (&confdb_inst->response_mutex);
  468. if (error != CS_OK) {
  469. goto error_exit;
  470. }
  471. error = res_lib_confdb_object_parent_get.header.error;
  472. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  473. error_exit:
  474. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  475. return (error);
  476. }
  477. static cs_error_t do_find_destroy(
  478. struct confdb_inst *confdb_inst,
  479. hdb_handle_t find_handle)
  480. {
  481. cs_error_t error;
  482. struct iovec iov;
  483. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  484. mar_res_header_t res;
  485. if (!find_handle)
  486. return CS_OK;
  487. if (confdb_inst->standalone) {
  488. error = CS_OK;
  489. if (confdb_sa_find_destroy(find_handle))
  490. error = CS_ERR_ACCESS;
  491. goto error_exit;
  492. }
  493. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  494. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  495. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  496. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  497. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  498. pthread_mutex_lock (&confdb_inst->response_mutex);
  499. error = coroipcc_msg_send_reply_receive (
  500. confdb_inst->ipc_ctx,
  501. &iov,
  502. 1,
  503. &res,
  504. sizeof (mar_res_header_t));
  505. pthread_mutex_unlock (&confdb_inst->response_mutex);
  506. if (error != CS_OK) {
  507. goto error_exit;
  508. }
  509. error = res.error;
  510. error_exit:
  511. return (error);
  512. }
  513. cs_error_t confdb_object_find_destroy(
  514. confdb_handle_t handle,
  515. hdb_handle_t parent_object_handle)
  516. {
  517. struct iter_context *context;
  518. cs_error_t error;
  519. struct confdb_inst *confdb_inst;
  520. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  521. if (error != CS_OK) {
  522. return (error);
  523. }
  524. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  525. error = do_find_destroy(confdb_inst, context->find_handle);
  526. if (error == CS_OK) {
  527. list_del(&context->list);
  528. free(context);
  529. }
  530. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  531. return error;
  532. }
  533. cs_error_t confdb_object_iter_destroy(
  534. confdb_handle_t handle,
  535. hdb_handle_t parent_object_handle)
  536. {
  537. struct iter_context *context;
  538. cs_error_t error;
  539. struct confdb_inst *confdb_inst;
  540. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  541. if (error != CS_OK) {
  542. return (error);
  543. }
  544. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  545. error = do_find_destroy(confdb_inst, context->find_handle);
  546. if (error == CS_OK) {
  547. list_del(&context->list);
  548. free(context);
  549. }
  550. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  551. return error;
  552. }
  553. cs_error_t confdb_key_create (
  554. confdb_handle_t handle,
  555. hdb_handle_t parent_object_handle,
  556. const void *key_name,
  557. int key_name_len,
  558. const void *value,
  559. int value_len)
  560. {
  561. cs_error_t error;
  562. struct confdb_inst *confdb_inst;
  563. struct iovec iov;
  564. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  565. mar_res_header_t res;
  566. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  567. if (error != CS_OK) {
  568. return (error);
  569. }
  570. if (confdb_inst->standalone) {
  571. error = CS_OK;
  572. if (confdb_sa_key_create(parent_object_handle,
  573. key_name, key_name_len,
  574. value, value_len))
  575. error = CS_ERR_ACCESS;
  576. goto error_exit;
  577. }
  578. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  579. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  580. req_lib_confdb_key_create.object_handle = parent_object_handle;
  581. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  582. req_lib_confdb_key_create.key_name.length = key_name_len;
  583. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  584. req_lib_confdb_key_create.value.length = value_len;
  585. iov.iov_base = (char *)&req_lib_confdb_key_create;
  586. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  587. pthread_mutex_lock (&confdb_inst->response_mutex);
  588. error = coroipcc_msg_send_reply_receive (
  589. confdb_inst->ipc_ctx,
  590. &iov,
  591. 1,
  592. &res,
  593. sizeof (res));
  594. pthread_mutex_unlock (&confdb_inst->response_mutex);
  595. if (error != CS_OK) {
  596. goto error_exit;
  597. }
  598. error = res.error;
  599. error_exit:
  600. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  601. return (error);
  602. }
  603. cs_error_t confdb_key_delete (
  604. confdb_handle_t handle,
  605. hdb_handle_t parent_object_handle,
  606. const void *key_name,
  607. int key_name_len,
  608. const void *value,
  609. int value_len)
  610. {
  611. cs_error_t error;
  612. struct confdb_inst *confdb_inst;
  613. struct iovec iov;
  614. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  615. mar_res_header_t res;
  616. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  617. if (error != CS_OK) {
  618. return (error);
  619. }
  620. if (confdb_inst->standalone) {
  621. error = CS_OK;
  622. if (confdb_sa_key_delete(parent_object_handle,
  623. key_name, key_name_len,
  624. value, value_len))
  625. error = CS_ERR_ACCESS;
  626. goto error_exit;
  627. }
  628. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  629. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  630. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  631. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  632. req_lib_confdb_key_delete.key_name.length = key_name_len;
  633. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  634. req_lib_confdb_key_delete.value.length = value_len;
  635. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  636. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  637. pthread_mutex_lock (&confdb_inst->response_mutex);
  638. error = coroipcc_msg_send_reply_receive (
  639. confdb_inst->ipc_ctx,
  640. &iov,
  641. 1,
  642. &res,
  643. sizeof (res));
  644. pthread_mutex_unlock (&confdb_inst->response_mutex);
  645. if (error != CS_OK) {
  646. goto error_exit;
  647. }
  648. error = res.error;
  649. error_exit:
  650. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  651. return (error);
  652. }
  653. cs_error_t confdb_key_get (
  654. confdb_handle_t handle,
  655. hdb_handle_t parent_object_handle,
  656. const void *key_name,
  657. int key_name_len,
  658. void *value,
  659. int *value_len)
  660. {
  661. cs_error_t error;
  662. struct confdb_inst *confdb_inst;
  663. struct iovec iov;
  664. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  665. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  666. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  667. if (error != CS_OK) {
  668. return (error);
  669. }
  670. if (confdb_inst->standalone) {
  671. error = CS_OK;
  672. if (confdb_sa_key_get(parent_object_handle,
  673. key_name, key_name_len,
  674. value, value_len))
  675. error = CS_ERR_ACCESS;
  676. goto error_exit;
  677. }
  678. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  679. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  680. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  681. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  682. req_lib_confdb_key_get.key_name.length = key_name_len;
  683. iov.iov_base = (char *)&req_lib_confdb_key_get;
  684. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  685. pthread_mutex_lock (&confdb_inst->response_mutex);
  686. error = coroipcc_msg_send_reply_receive (
  687. confdb_inst->ipc_ctx,
  688. &iov,
  689. 1,
  690. &res_lib_confdb_key_get,
  691. sizeof (struct res_lib_confdb_key_get));
  692. pthread_mutex_unlock (&confdb_inst->response_mutex);
  693. if (error != CS_OK) {
  694. goto error_exit;
  695. }
  696. error = res_lib_confdb_key_get.header.error;
  697. if (error == CS_OK) {
  698. *value_len = res_lib_confdb_key_get.value.length;
  699. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  700. }
  701. error_exit:
  702. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  703. return (error);
  704. }
  705. cs_error_t confdb_key_increment (
  706. confdb_handle_t handle,
  707. hdb_handle_t parent_object_handle,
  708. const void *key_name,
  709. int key_name_len,
  710. unsigned int *value)
  711. {
  712. cs_error_t error;
  713. struct confdb_inst *confdb_inst;
  714. struct iovec iov;
  715. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  716. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  717. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  718. if (error != CS_OK) {
  719. return (error);
  720. }
  721. if (confdb_inst->standalone) {
  722. error = CS_OK;
  723. if (confdb_sa_key_increment(parent_object_handle,
  724. key_name, key_name_len,
  725. value))
  726. error = CS_ERR_ACCESS;
  727. goto error_exit;
  728. }
  729. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  730. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  731. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  732. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  733. req_lib_confdb_key_get.key_name.length = key_name_len;
  734. iov.iov_base = (char *)&req_lib_confdb_key_get;
  735. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  736. pthread_mutex_lock (&confdb_inst->response_mutex);
  737. error = coroipcc_msg_send_reply_receive (
  738. confdb_inst->ipc_ctx,
  739. &iov,
  740. 1,
  741. &res_lib_confdb_key_incdec,
  742. sizeof (struct res_lib_confdb_key_incdec));
  743. pthread_mutex_unlock (&confdb_inst->response_mutex);
  744. if (error != CS_OK) {
  745. goto error_exit;
  746. }
  747. error = res_lib_confdb_key_incdec.header.error;
  748. if (error == CS_OK) {
  749. *value = res_lib_confdb_key_incdec.value;
  750. }
  751. error_exit:
  752. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  753. return (error);
  754. }
  755. cs_error_t confdb_key_decrement (
  756. confdb_handle_t handle,
  757. hdb_handle_t parent_object_handle,
  758. const void *key_name,
  759. int key_name_len,
  760. unsigned int *value)
  761. {
  762. cs_error_t error;
  763. struct confdb_inst *confdb_inst;
  764. struct iovec iov;
  765. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  766. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  767. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  768. if (error != CS_OK) {
  769. return (error);
  770. }
  771. if (confdb_inst->standalone) {
  772. error = CS_OK;
  773. if (confdb_sa_key_decrement(parent_object_handle,
  774. key_name, key_name_len,
  775. value))
  776. error = CS_ERR_ACCESS;
  777. goto error_exit;
  778. }
  779. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  780. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  781. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  782. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  783. req_lib_confdb_key_get.key_name.length = key_name_len;
  784. iov.iov_base = (char *)&req_lib_confdb_key_get;
  785. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  786. pthread_mutex_lock (&confdb_inst->response_mutex);
  787. error = coroipcc_msg_send_reply_receive (
  788. confdb_inst->ipc_ctx,
  789. &iov,
  790. 1,
  791. &res_lib_confdb_key_incdec,
  792. sizeof (struct res_lib_confdb_key_incdec));
  793. pthread_mutex_unlock (&confdb_inst->response_mutex);
  794. if (error != CS_OK) {
  795. goto error_exit;
  796. }
  797. error = res_lib_confdb_key_incdec.header.error;
  798. if (error == CS_OK) {
  799. *value = res_lib_confdb_key_incdec.value;
  800. }
  801. error_exit:
  802. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  803. return (error);
  804. }
  805. cs_error_t confdb_key_replace (
  806. confdb_handle_t handle,
  807. hdb_handle_t parent_object_handle,
  808. const void *key_name,
  809. int key_name_len,
  810. const void *old_value,
  811. int old_value_len,
  812. const void *new_value,
  813. int new_value_len)
  814. {
  815. cs_error_t error;
  816. struct confdb_inst *confdb_inst;
  817. struct iovec iov;
  818. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  819. mar_res_header_t res;
  820. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  821. if (error != CS_OK) {
  822. return (error);
  823. }
  824. if (confdb_inst->standalone) {
  825. error = CS_OK;
  826. if (confdb_sa_key_replace(parent_object_handle,
  827. key_name, key_name_len,
  828. old_value, old_value_len,
  829. new_value, new_value_len))
  830. error = CS_ERR_ACCESS;
  831. goto error_exit;
  832. }
  833. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  834. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  835. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  836. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  837. req_lib_confdb_key_replace.key_name.length = key_name_len;
  838. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  839. req_lib_confdb_key_replace.old_value.length = old_value_len;
  840. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  841. req_lib_confdb_key_replace.new_value.length = new_value_len;
  842. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  843. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  844. pthread_mutex_lock (&confdb_inst->response_mutex);
  845. error = coroipcc_msg_send_reply_receive (
  846. confdb_inst->ipc_ctx,
  847. &iov,
  848. 1,
  849. &res,
  850. sizeof (res));
  851. pthread_mutex_unlock (&confdb_inst->response_mutex);
  852. if (error != CS_OK) {
  853. goto error_exit;
  854. }
  855. error = res.error;
  856. error_exit:
  857. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  858. return (error);
  859. }
  860. cs_error_t confdb_object_iter_start (
  861. confdb_handle_t handle,
  862. hdb_handle_t object_handle)
  863. {
  864. struct confdb_inst *confdb_inst;
  865. cs_error_t error = CS_OK;
  866. struct iter_context *context;
  867. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  868. if (error != CS_OK) {
  869. return (error);
  870. }
  871. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  872. if (!context) {
  873. context = malloc(sizeof(struct iter_context));
  874. if (!context) {
  875. error = CS_ERR_NO_MEMORY;
  876. goto ret;
  877. }
  878. context->parent_object_handle = object_handle;
  879. context->find_handle = 0;
  880. list_add(&context->list, &confdb_inst->object_iter_head);
  881. }
  882. /* Start a new find context */
  883. if (context->find_handle) {
  884. (void)do_find_destroy(confdb_inst, context->find_handle);
  885. context->find_handle = 0;
  886. }
  887. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  888. ret:
  889. return error;
  890. }
  891. cs_error_t confdb_key_iter_start (
  892. confdb_handle_t handle,
  893. hdb_handle_t object_handle)
  894. {
  895. struct confdb_inst *confdb_inst;
  896. cs_error_t error = CS_OK;
  897. struct iter_context *context;
  898. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  899. if (error != CS_OK) {
  900. return (error);
  901. }
  902. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  903. if (!context) {
  904. context = malloc(sizeof(struct iter_context));
  905. if (!context) {
  906. error = CS_ERR_NO_MEMORY;
  907. goto ret;
  908. }
  909. context->parent_object_handle = object_handle;
  910. list_add(&context->list, &confdb_inst->key_iter_head);
  911. }
  912. context->find_handle = 0;
  913. context->next_entry = 0;
  914. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  915. ret:
  916. return error;
  917. }
  918. cs_error_t confdb_object_find_start (
  919. confdb_handle_t handle,
  920. hdb_handle_t parent_object_handle)
  921. {
  922. struct confdb_inst *confdb_inst;
  923. cs_error_t error = CS_OK;
  924. struct iter_context *context;
  925. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  926. if (error != CS_OK) {
  927. return (error);
  928. }
  929. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  930. if (!context) {
  931. context = malloc(sizeof(struct iter_context));
  932. if (!context) {
  933. error = CS_ERR_NO_MEMORY;
  934. goto ret;
  935. }
  936. context->find_handle = 0;
  937. context->parent_object_handle = parent_object_handle;
  938. list_add(&context->list, &confdb_inst->object_find_head);
  939. }
  940. /* Start a new find context */
  941. if (context->find_handle) {
  942. (void)do_find_destroy(confdb_inst, context->find_handle);
  943. context->find_handle = 0;
  944. }
  945. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  946. ret:
  947. return error;
  948. }
  949. cs_error_t confdb_object_find (
  950. confdb_handle_t handle,
  951. hdb_handle_t parent_object_handle,
  952. const void *object_name,
  953. int object_name_len,
  954. hdb_handle_t *object_handle)
  955. {
  956. cs_error_t error;
  957. struct confdb_inst *confdb_inst;
  958. struct iovec iov;
  959. struct iter_context *context;
  960. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  961. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  962. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  963. if (error != CS_OK) {
  964. return (error);
  965. }
  966. /* You MUST call confdb_object_find_start first */
  967. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  968. if (!context) {
  969. error = CS_ERR_CONTEXT_NOT_FOUND;
  970. goto error_exit;
  971. }
  972. if (confdb_inst->standalone) {
  973. error = CS_OK;
  974. if (confdb_sa_object_find(parent_object_handle,
  975. &context->find_handle,
  976. object_handle,
  977. object_name, object_name_len))
  978. error = CS_ERR_ACCESS;
  979. goto error_exit;
  980. }
  981. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  982. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  983. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  984. req_lib_confdb_object_find.find_handle = context->find_handle;
  985. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  986. req_lib_confdb_object_find.object_name.length = object_name_len;
  987. iov.iov_base = (char *)&req_lib_confdb_object_find;
  988. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  989. pthread_mutex_lock (&confdb_inst->response_mutex);
  990. error = coroipcc_msg_send_reply_receive (
  991. confdb_inst->ipc_ctx,
  992. &iov,
  993. 1,
  994. &res_lib_confdb_object_find,
  995. sizeof (struct res_lib_confdb_object_find));
  996. pthread_mutex_unlock (&confdb_inst->response_mutex);
  997. if (error != CS_OK) {
  998. goto error_exit;
  999. }
  1000. error = res_lib_confdb_object_find.header.error;
  1001. *object_handle = res_lib_confdb_object_find.object_handle;
  1002. context->find_handle = res_lib_confdb_object_find.find_handle;
  1003. error_exit:
  1004. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1005. return (error);
  1006. }
  1007. cs_error_t confdb_object_iter (
  1008. confdb_handle_t handle,
  1009. hdb_handle_t parent_object_handle,
  1010. hdb_handle_t *object_handle,
  1011. void *object_name,
  1012. int *object_name_len)
  1013. {
  1014. cs_error_t error;
  1015. struct confdb_inst *confdb_inst;
  1016. struct iovec iov;
  1017. struct iter_context *context;
  1018. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1019. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1020. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1021. if (error != CS_OK) {
  1022. return (error);
  1023. }
  1024. /* You MUST call confdb_object_iter_start first */
  1025. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1026. if (!context) {
  1027. error = CS_ERR_CONTEXT_NOT_FOUND;
  1028. goto error_exit;
  1029. }
  1030. if (confdb_inst->standalone) {
  1031. error = CS_OK;
  1032. *object_name_len = 0;
  1033. if (confdb_sa_object_iter(parent_object_handle,
  1034. &context->find_handle,
  1035. object_handle,
  1036. NULL, 0,
  1037. object_name, object_name_len))
  1038. error = CS_ERR_ACCESS;
  1039. goto sa_exit;
  1040. }
  1041. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1042. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1043. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1044. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1045. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1046. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1047. pthread_mutex_lock (&confdb_inst->response_mutex);
  1048. error = coroipcc_msg_send_reply_receive (
  1049. confdb_inst->ipc_ctx,
  1050. &iov,
  1051. 1,
  1052. &res_lib_confdb_object_iter,
  1053. sizeof (struct res_lib_confdb_object_iter));
  1054. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1055. if (error != CS_OK) {
  1056. goto error_exit;
  1057. }
  1058. error = res_lib_confdb_object_iter.header.error;
  1059. if (error == CS_OK) {
  1060. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1061. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1062. *object_handle = res_lib_confdb_object_iter.object_handle;
  1063. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1064. }
  1065. sa_exit:
  1066. error_exit:
  1067. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1068. return (error);
  1069. }
  1070. cs_error_t confdb_key_iter (
  1071. confdb_handle_t handle,
  1072. hdb_handle_t parent_object_handle,
  1073. void *key_name,
  1074. int *key_name_len,
  1075. void *value,
  1076. int *value_len)
  1077. {
  1078. cs_error_t error;
  1079. struct confdb_inst *confdb_inst;
  1080. struct iovec iov;
  1081. struct iter_context *context;
  1082. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1083. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1084. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1085. if (error != CS_OK) {
  1086. return (error);
  1087. }
  1088. /* You MUST call confdb_key_iter_start first */
  1089. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1090. if (!context) {
  1091. error = CS_ERR_CONTEXT_NOT_FOUND;
  1092. goto error_exit;
  1093. }
  1094. if (confdb_inst->standalone) {
  1095. error = CS_OK;
  1096. if (confdb_sa_key_iter(parent_object_handle,
  1097. context->next_entry,
  1098. key_name, key_name_len,
  1099. value, value_len))
  1100. error = CS_ERR_ACCESS;
  1101. goto sa_exit;
  1102. }
  1103. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1104. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1105. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1106. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1107. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1108. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1109. pthread_mutex_lock (&confdb_inst->response_mutex);
  1110. error = coroipcc_msg_send_reply_receive (
  1111. confdb_inst->ipc_ctx,
  1112. &iov,
  1113. 1,
  1114. &res_lib_confdb_key_iter,
  1115. sizeof (struct res_lib_confdb_key_iter));
  1116. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1117. if (error != CS_OK) {
  1118. goto error_exit;
  1119. }
  1120. error = res_lib_confdb_key_iter.header.error;
  1121. if (error == CS_OK) {
  1122. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1123. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1124. *value_len = res_lib_confdb_key_iter.value.length;
  1125. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1126. }
  1127. sa_exit:
  1128. context->next_entry++;
  1129. error_exit:
  1130. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1131. return (error);
  1132. }
  1133. cs_error_t confdb_write (
  1134. confdb_handle_t handle,
  1135. char *error_text)
  1136. {
  1137. cs_error_t error;
  1138. struct confdb_inst *confdb_inst;
  1139. struct iovec iov;
  1140. mar_req_header_t req;
  1141. struct res_lib_confdb_write res_lib_confdb_write;
  1142. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1143. if (error != CS_OK) {
  1144. return (error);
  1145. }
  1146. if (confdb_inst->standalone) {
  1147. error = CS_OK;
  1148. if (confdb_sa_write(error_text))
  1149. error = CS_ERR_ACCESS;
  1150. goto error_exit;
  1151. }
  1152. req.size = sizeof (mar_req_header_t);
  1153. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1154. iov.iov_base = (char *)&req;
  1155. iov.iov_len = sizeof (mar_req_header_t);
  1156. pthread_mutex_lock (&confdb_inst->response_mutex);
  1157. error = coroipcc_msg_send_reply_receive (
  1158. confdb_inst->ipc_ctx,
  1159. &iov,
  1160. 1,
  1161. &res_lib_confdb_write,
  1162. sizeof (struct res_lib_confdb_write));
  1163. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1164. if (error != CS_OK) {
  1165. goto error_exit;
  1166. }
  1167. error = res_lib_confdb_write.header.error;
  1168. if (res_lib_confdb_write.error.length)
  1169. memcpy(error_text, res_lib_confdb_write.error.value, res_lib_confdb_write.error.length);
  1170. error_exit:
  1171. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1172. return (error);
  1173. }
  1174. cs_error_t confdb_reload (
  1175. confdb_handle_t handle,
  1176. int flush,
  1177. char *error_text)
  1178. {
  1179. cs_error_t error;
  1180. struct confdb_inst *confdb_inst;
  1181. struct iovec iov;
  1182. struct res_lib_confdb_reload res_lib_confdb_reload;
  1183. struct req_lib_confdb_reload req_lib_confdb_reload;
  1184. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1185. if (error != CS_OK) {
  1186. return (error);
  1187. }
  1188. if (confdb_inst->standalone) {
  1189. error = CS_OK;
  1190. if (confdb_sa_reload(flush, error_text))
  1191. error = CS_ERR_ACCESS;
  1192. goto error_exit;
  1193. }
  1194. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1195. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1196. req_lib_confdb_reload.flush = flush;
  1197. iov.iov_base = (char *)&req_lib_confdb_reload;
  1198. iov.iov_len = sizeof (req_lib_confdb_reload);
  1199. pthread_mutex_lock (&confdb_inst->response_mutex);
  1200. error = coroipcc_msg_send_reply_receive (
  1201. confdb_inst->ipc_ctx,
  1202. &iov,
  1203. 1,
  1204. &res_lib_confdb_reload,
  1205. sizeof (struct res_lib_confdb_reload));
  1206. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1207. if (error != CS_OK) {
  1208. goto error_exit;
  1209. }
  1210. error = res_lib_confdb_reload.header.error;
  1211. if(res_lib_confdb_reload.error.length)
  1212. memcpy(error_text, res_lib_confdb_reload.error.value, res_lib_confdb_reload.error.length);
  1213. error_exit:
  1214. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1215. return (error);
  1216. }
  1217. cs_error_t confdb_track_changes (
  1218. confdb_handle_t handle,
  1219. hdb_handle_t object_handle,
  1220. unsigned int flags)
  1221. {
  1222. cs_error_t error;
  1223. struct confdb_inst *confdb_inst;
  1224. struct iovec iov;
  1225. struct req_lib_confdb_object_track_start req;
  1226. mar_res_header_t res;
  1227. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1228. if (error != CS_OK) {
  1229. return (error);
  1230. }
  1231. if (confdb_inst->standalone) {
  1232. error = CS_ERR_NOT_SUPPORTED;
  1233. goto error_exit;
  1234. }
  1235. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1236. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1237. req.object_handle = object_handle;
  1238. req.flags = flags;
  1239. iov.iov_base = (char *)&req;
  1240. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1241. pthread_mutex_lock (&confdb_inst->response_mutex);
  1242. error = coroipcc_msg_send_reply_receive (
  1243. confdb_inst->ipc_ctx,
  1244. &iov,
  1245. 1,
  1246. &res,
  1247. sizeof (mar_res_header_t));
  1248. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1249. if (error != CS_OK) {
  1250. goto error_exit;
  1251. }
  1252. error = res.error;
  1253. error_exit:
  1254. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1255. return (error);
  1256. }
  1257. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1258. {
  1259. cs_error_t error;
  1260. struct confdb_inst *confdb_inst;
  1261. struct iovec iov;
  1262. mar_req_header_t req;
  1263. mar_res_header_t res;
  1264. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1265. if (error != CS_OK) {
  1266. return (error);
  1267. }
  1268. if (confdb_inst->standalone) {
  1269. error = CS_ERR_NOT_SUPPORTED;
  1270. goto error_exit;
  1271. }
  1272. req.size = sizeof (mar_req_header_t);
  1273. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1274. iov.iov_base = (char *)&req;
  1275. iov.iov_len = sizeof (mar_req_header_t);
  1276. pthread_mutex_lock (&confdb_inst->response_mutex);
  1277. error = coroipcc_msg_send_reply_receive (
  1278. confdb_inst->ipc_ctx,
  1279. &iov,
  1280. 1,
  1281. &res,
  1282. sizeof (mar_res_header_t));
  1283. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1284. if (error != CS_OK) {
  1285. goto error_exit;
  1286. }
  1287. error = res.error;
  1288. error_exit:
  1289. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1290. return (error);
  1291. }