confdb.c 41 KB

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