confdb.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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. uint32_t parent_object_handle;
  56. uint32_t find_handle;
  57. uint32_t next_entry;
  58. };
  59. struct confdb_inst {
  60. void *ipc_ctx;
  61. int finalize;
  62. int standalone;
  63. confdb_callbacks_t callbacks;
  64. 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, unsigned int 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, unsigned int 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. 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. 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. struct pollfd ufds;
  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 = cslib_dispatch_recv (confdb_inst->ipc_ctx,
  266. (void *)&dispatch_data, timeout);
  267. /*
  268. * Handle has been finalized in another thread
  269. */
  270. if (confdb_inst->finalize == 1) {
  271. error = CS_OK;
  272. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  273. goto error_put;
  274. }
  275. dispatch_avail = ufds.revents & POLLIN;
  276. if (dispatch_avail == 0 && dispatch_types == CONFDB_DISPATCH_ALL) {
  277. break; /* exit do while cont is 1 loop */
  278. } else
  279. if (dispatch_avail == 0) {
  280. continue; /* next poll */
  281. }
  282. /*
  283. * Make copy of callbacks, message data, unlock instance, and call callback
  284. * A risk of this dispatch method is that the callback routines may
  285. * operate at the same time that confdbFinalize has been called.
  286. */
  287. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  288. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  289. /*
  290. * Dispatch incoming message
  291. */
  292. switch (dispatch_data.header.id) {
  293. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  294. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)&dispatch_data;
  295. callbacks.confdb_key_change_notify_fn(handle,
  296. res_key_changed_pt->change_type,
  297. res_key_changed_pt->object_handle,
  298. res_key_changed_pt->parent_object_handle,
  299. res_key_changed_pt->object_name.value,
  300. res_key_changed_pt->object_name.length,
  301. res_key_changed_pt->key_name.value,
  302. res_key_changed_pt->key_name.length,
  303. res_key_changed_pt->key_value.value,
  304. res_key_changed_pt->key_value.length);
  305. break;
  306. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  307. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)&dispatch_data;
  308. callbacks.confdb_object_create_change_notify_fn(handle,
  309. res_object_created_pt->object_handle,
  310. res_object_created_pt->parent_object_handle,
  311. res_object_created_pt->name.value,
  312. res_object_created_pt->name.length);
  313. break;
  314. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  315. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)&dispatch_data;
  316. callbacks.confdb_object_delete_change_notify_fn(handle,
  317. res_object_destroyed_pt->parent_object_handle,
  318. res_object_destroyed_pt->name.value,
  319. res_object_destroyed_pt->name.length);
  320. break;
  321. default:
  322. error = CS_ERR_LIBRARY;
  323. goto error_noput;
  324. break;
  325. }
  326. /*
  327. * Determine if more messages should be processed
  328. * */
  329. switch (dispatch_types) {
  330. case CONFDB_DISPATCH_ONE:
  331. cont = 0;
  332. break;
  333. case CONFDB_DISPATCH_ALL:
  334. break;
  335. case CONFDB_DISPATCH_BLOCKING:
  336. break;
  337. }
  338. } while (cont);
  339. error_put:
  340. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  341. error_noput:
  342. return (error);
  343. }
  344. cs_error_t confdb_object_create (
  345. confdb_handle_t handle,
  346. unsigned int parent_object_handle,
  347. void *object_name,
  348. int object_name_len,
  349. unsigned int *object_handle)
  350. {
  351. cs_error_t error;
  352. struct confdb_inst *confdb_inst;
  353. struct iovec iov;
  354. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  355. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  356. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  357. if (error != CS_OK) {
  358. return (error);
  359. }
  360. if (confdb_inst->standalone) {
  361. error = CS_OK;
  362. if (confdb_sa_object_create(parent_object_handle,
  363. object_name, object_name_len,
  364. object_handle))
  365. error = CS_ERR_ACCESS;
  366. goto error_exit;
  367. }
  368. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  369. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  370. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  371. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  372. req_lib_confdb_object_create.object_name.length = object_name_len;
  373. iov.iov_base = (char *)&req_lib_confdb_object_create;
  374. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  375. pthread_mutex_lock (&confdb_inst->response_mutex);
  376. error = cslib_msg_send_reply_receive (
  377. confdb_inst->ipc_ctx,
  378. &iov,
  379. 1,
  380. &res_lib_confdb_object_create,
  381. sizeof (struct res_lib_confdb_object_create));
  382. pthread_mutex_unlock (&confdb_inst->response_mutex);
  383. if (error != CS_OK) {
  384. goto error_exit;
  385. }
  386. error = res_lib_confdb_object_create.header.error;
  387. *object_handle = res_lib_confdb_object_create.object_handle;
  388. error_exit:
  389. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  390. return (error);
  391. }
  392. cs_error_t confdb_object_destroy (
  393. confdb_handle_t handle,
  394. unsigned int object_handle)
  395. {
  396. cs_error_t error;
  397. struct confdb_inst *confdb_inst;
  398. struct iovec iov;
  399. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  400. mar_res_header_t res;
  401. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  402. if (error != CS_OK) {
  403. return (error);
  404. }
  405. if (confdb_inst->standalone) {
  406. error = CS_OK;
  407. if (confdb_sa_object_destroy(object_handle))
  408. error = CS_ERR_ACCESS;
  409. goto error_exit;
  410. }
  411. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  412. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  413. req_lib_confdb_object_destroy.object_handle = object_handle;
  414. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  415. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  416. pthread_mutex_lock (&confdb_inst->response_mutex);
  417. error = cslib_msg_send_reply_receive (
  418. confdb_inst->ipc_ctx,
  419. &iov,
  420. 1,
  421. &res,
  422. sizeof (mar_res_header_t));
  423. pthread_mutex_unlock (&confdb_inst->response_mutex);
  424. if (error != CS_OK) {
  425. goto error_exit;
  426. }
  427. error = res.error;
  428. error_exit:
  429. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  430. return (error);
  431. }
  432. cs_error_t confdb_object_parent_get (
  433. confdb_handle_t handle,
  434. unsigned int object_handle,
  435. unsigned int *parent_object_handle)
  436. {
  437. cs_error_t error;
  438. struct confdb_inst *confdb_inst;
  439. struct iovec iov;
  440. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  441. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  442. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  443. if (error != CS_OK) {
  444. return (error);
  445. }
  446. if (confdb_inst->standalone) {
  447. error = CS_OK;
  448. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  449. error = CS_ERR_ACCESS;
  450. goto error_exit;
  451. }
  452. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  453. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  454. req_lib_confdb_object_parent_get.object_handle = object_handle;
  455. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  456. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  457. pthread_mutex_lock (&confdb_inst->response_mutex);
  458. error = cslib_msg_send_reply_receive (
  459. confdb_inst->ipc_ctx,
  460. &iov,
  461. 1,
  462. &res_lib_confdb_object_parent_get,
  463. sizeof (struct res_lib_confdb_object_parent_get));
  464. pthread_mutex_unlock (&confdb_inst->response_mutex);
  465. if (error != CS_OK) {
  466. goto error_exit;
  467. }
  468. error = res_lib_confdb_object_parent_get.header.error;
  469. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  470. error_exit:
  471. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  472. return (error);
  473. }
  474. static cs_error_t do_find_destroy(
  475. struct confdb_inst *confdb_inst,
  476. unsigned int find_handle)
  477. {
  478. cs_error_t error;
  479. struct iovec iov;
  480. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  481. mar_res_header_t res;
  482. if (!find_handle)
  483. return CS_OK;
  484. if (confdb_inst->standalone) {
  485. error = CS_OK;
  486. if (confdb_sa_find_destroy(find_handle))
  487. error = CS_ERR_ACCESS;
  488. goto error_exit;
  489. }
  490. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  491. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  492. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  493. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  494. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  495. pthread_mutex_lock (&confdb_inst->response_mutex);
  496. error = cslib_msg_send_reply_receive (
  497. confdb_inst->ipc_ctx,
  498. &iov,
  499. 1,
  500. &res,
  501. sizeof (mar_res_header_t));
  502. pthread_mutex_unlock (&confdb_inst->response_mutex);
  503. if (error != CS_OK) {
  504. goto error_exit;
  505. }
  506. error = res.error;
  507. error_exit:
  508. return (error);
  509. }
  510. cs_error_t confdb_object_find_destroy(
  511. confdb_handle_t handle,
  512. unsigned int parent_object_handle)
  513. {
  514. struct iter_context *context;
  515. cs_error_t error;
  516. struct confdb_inst *confdb_inst;
  517. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  518. if (error != CS_OK) {
  519. return (error);
  520. }
  521. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  522. error = do_find_destroy(confdb_inst, context->find_handle);
  523. if (error == CS_OK) {
  524. list_del(&context->list);
  525. free(context);
  526. }
  527. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  528. return error;
  529. }
  530. cs_error_t confdb_object_iter_destroy(
  531. confdb_handle_t handle,
  532. unsigned int parent_object_handle)
  533. {
  534. struct iter_context *context;
  535. cs_error_t error;
  536. struct confdb_inst *confdb_inst;
  537. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  538. if (error != CS_OK) {
  539. return (error);
  540. }
  541. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  542. error = do_find_destroy(confdb_inst, context->find_handle);
  543. if (error == CS_OK) {
  544. list_del(&context->list);
  545. free(context);
  546. }
  547. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  548. return error;
  549. }
  550. cs_error_t confdb_key_create (
  551. confdb_handle_t handle,
  552. unsigned int parent_object_handle,
  553. void *key_name,
  554. int key_name_len,
  555. void *value,
  556. int value_len)
  557. {
  558. cs_error_t error;
  559. struct confdb_inst *confdb_inst;
  560. struct iovec iov;
  561. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  562. mar_res_header_t res;
  563. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  564. if (error != CS_OK) {
  565. return (error);
  566. }
  567. if (confdb_inst->standalone) {
  568. error = CS_OK;
  569. if (confdb_sa_key_create(parent_object_handle,
  570. key_name, key_name_len,
  571. value, value_len))
  572. error = CS_ERR_ACCESS;
  573. goto error_exit;
  574. }
  575. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  576. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  577. req_lib_confdb_key_create.object_handle = parent_object_handle;
  578. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  579. req_lib_confdb_key_create.key_name.length = key_name_len;
  580. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  581. req_lib_confdb_key_create.value.length = value_len;
  582. iov.iov_base = (char *)&req_lib_confdb_key_create;
  583. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  584. pthread_mutex_lock (&confdb_inst->response_mutex);
  585. error = cslib_msg_send_reply_receive (
  586. confdb_inst->ipc_ctx,
  587. &iov,
  588. 1,
  589. &res,
  590. sizeof (res));
  591. pthread_mutex_unlock (&confdb_inst->response_mutex);
  592. if (error != CS_OK) {
  593. goto error_exit;
  594. }
  595. error = res.error;
  596. error_exit:
  597. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  598. return (error);
  599. }
  600. cs_error_t confdb_key_delete (
  601. confdb_handle_t handle,
  602. unsigned int parent_object_handle,
  603. void *key_name,
  604. int key_name_len,
  605. void *value,
  606. int value_len)
  607. {
  608. cs_error_t error;
  609. struct confdb_inst *confdb_inst;
  610. struct iovec iov;
  611. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  612. mar_res_header_t res;
  613. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  614. if (error != CS_OK) {
  615. return (error);
  616. }
  617. if (confdb_inst->standalone) {
  618. error = CS_OK;
  619. if (confdb_sa_key_delete(parent_object_handle,
  620. key_name, key_name_len,
  621. value, value_len))
  622. error = CS_ERR_ACCESS;
  623. goto error_exit;
  624. }
  625. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  626. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  627. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  628. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  629. req_lib_confdb_key_delete.key_name.length = key_name_len;
  630. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  631. req_lib_confdb_key_delete.value.length = value_len;
  632. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  633. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  634. pthread_mutex_lock (&confdb_inst->response_mutex);
  635. error = cslib_msg_send_reply_receive (
  636. confdb_inst->ipc_ctx,
  637. &iov,
  638. 1,
  639. &res,
  640. sizeof (res));
  641. pthread_mutex_unlock (&confdb_inst->response_mutex);
  642. if (error != CS_OK) {
  643. goto error_exit;
  644. }
  645. error = res.error;
  646. error_exit:
  647. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  648. return (error);
  649. }
  650. cs_error_t confdb_key_get (
  651. confdb_handle_t handle,
  652. unsigned int parent_object_handle,
  653. void *key_name,
  654. int key_name_len,
  655. void *value,
  656. int *value_len)
  657. {
  658. cs_error_t error;
  659. struct confdb_inst *confdb_inst;
  660. struct iovec iov;
  661. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  662. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  663. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  664. if (error != CS_OK) {
  665. return (error);
  666. }
  667. if (confdb_inst->standalone) {
  668. error = CS_OK;
  669. if (confdb_sa_key_get(parent_object_handle,
  670. key_name, key_name_len,
  671. value, value_len))
  672. error = CS_ERR_ACCESS;
  673. goto error_exit;
  674. }
  675. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  676. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  677. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  678. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  679. req_lib_confdb_key_get.key_name.length = key_name_len;
  680. iov.iov_base = (char *)&req_lib_confdb_key_get;
  681. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  682. pthread_mutex_lock (&confdb_inst->response_mutex);
  683. error = cslib_msg_send_reply_receive (
  684. confdb_inst->ipc_ctx,
  685. &iov,
  686. 1,
  687. &res_lib_confdb_key_get,
  688. sizeof (struct res_lib_confdb_key_get));
  689. pthread_mutex_unlock (&confdb_inst->response_mutex);
  690. if (error != CS_OK) {
  691. goto error_exit;
  692. }
  693. error = res_lib_confdb_key_get.header.error;
  694. if (error == CS_OK) {
  695. *value_len = res_lib_confdb_key_get.value.length;
  696. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  697. }
  698. error_exit:
  699. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  700. return (error);
  701. }
  702. cs_error_t confdb_key_increment (
  703. confdb_handle_t handle,
  704. unsigned int parent_object_handle,
  705. void *key_name,
  706. int key_name_len,
  707. unsigned int *value)
  708. {
  709. cs_error_t error;
  710. struct confdb_inst *confdb_inst;
  711. struct iovec iov;
  712. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  713. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  714. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  715. if (error != CS_OK) {
  716. return (error);
  717. }
  718. if (confdb_inst->standalone) {
  719. error = CS_OK;
  720. if (confdb_sa_key_increment(parent_object_handle,
  721. key_name, key_name_len,
  722. value))
  723. error = CS_ERR_ACCESS;
  724. goto error_exit;
  725. }
  726. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  727. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  728. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  729. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  730. req_lib_confdb_key_get.key_name.length = key_name_len;
  731. iov.iov_base = (char *)&req_lib_confdb_key_get;
  732. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  733. pthread_mutex_lock (&confdb_inst->response_mutex);
  734. error = cslib_msg_send_reply_receive (
  735. confdb_inst->ipc_ctx,
  736. &iov,
  737. 1,
  738. &res_lib_confdb_key_incdec,
  739. sizeof (struct res_lib_confdb_key_incdec));
  740. pthread_mutex_unlock (&confdb_inst->response_mutex);
  741. if (error != CS_OK) {
  742. goto error_exit;
  743. }
  744. error = res_lib_confdb_key_incdec.header.error;
  745. if (error == CS_OK) {
  746. *value = res_lib_confdb_key_incdec.value;
  747. }
  748. error_exit:
  749. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  750. return (error);
  751. }
  752. cs_error_t confdb_key_decrement (
  753. confdb_handle_t handle,
  754. unsigned int parent_object_handle,
  755. void *key_name,
  756. int key_name_len,
  757. unsigned int *value)
  758. {
  759. cs_error_t error;
  760. struct confdb_inst *confdb_inst;
  761. struct iovec iov;
  762. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  763. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  764. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  765. if (error != CS_OK) {
  766. return (error);
  767. }
  768. if (confdb_inst->standalone) {
  769. error = CS_OK;
  770. if (confdb_sa_key_decrement(parent_object_handle,
  771. key_name, key_name_len,
  772. value))
  773. error = CS_ERR_ACCESS;
  774. goto error_exit;
  775. }
  776. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  777. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  778. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  779. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  780. req_lib_confdb_key_get.key_name.length = key_name_len;
  781. iov.iov_base = (char *)&req_lib_confdb_key_get;
  782. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  783. pthread_mutex_lock (&confdb_inst->response_mutex);
  784. error = cslib_msg_send_reply_receive (
  785. confdb_inst->ipc_ctx,
  786. &iov,
  787. 1,
  788. &res_lib_confdb_key_incdec,
  789. sizeof (struct res_lib_confdb_key_incdec));
  790. pthread_mutex_unlock (&confdb_inst->response_mutex);
  791. if (error != CS_OK) {
  792. goto error_exit;
  793. }
  794. error = res_lib_confdb_key_incdec.header.error;
  795. if (error == CS_OK) {
  796. *value = res_lib_confdb_key_incdec.value;
  797. }
  798. error_exit:
  799. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  800. return (error);
  801. }
  802. cs_error_t confdb_key_replace (
  803. confdb_handle_t handle,
  804. unsigned int parent_object_handle,
  805. void *key_name,
  806. int key_name_len,
  807. void *old_value,
  808. int old_value_len,
  809. void *new_value,
  810. int new_value_len)
  811. {
  812. cs_error_t error;
  813. struct confdb_inst *confdb_inst;
  814. struct iovec iov;
  815. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  816. mar_res_header_t res;
  817. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  818. if (error != CS_OK) {
  819. return (error);
  820. }
  821. if (confdb_inst->standalone) {
  822. error = CS_OK;
  823. if (confdb_sa_key_replace(parent_object_handle,
  824. key_name, key_name_len,
  825. old_value, old_value_len,
  826. new_value, new_value_len))
  827. error = CS_ERR_ACCESS;
  828. goto error_exit;
  829. }
  830. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  831. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  832. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  833. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  834. req_lib_confdb_key_replace.key_name.length = key_name_len;
  835. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  836. req_lib_confdb_key_replace.old_value.length = old_value_len;
  837. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  838. req_lib_confdb_key_replace.new_value.length = new_value_len;
  839. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  840. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  841. pthread_mutex_lock (&confdb_inst->response_mutex);
  842. error = cslib_msg_send_reply_receive (
  843. confdb_inst->ipc_ctx,
  844. &iov,
  845. 1,
  846. &res,
  847. sizeof (res));
  848. pthread_mutex_unlock (&confdb_inst->response_mutex);
  849. if (error != CS_OK) {
  850. goto error_exit;
  851. }
  852. error = res.error;
  853. error_exit:
  854. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  855. return (error);
  856. }
  857. cs_error_t confdb_object_iter_start (
  858. confdb_handle_t handle,
  859. unsigned int object_handle)
  860. {
  861. struct confdb_inst *confdb_inst;
  862. cs_error_t error = CS_OK;
  863. struct iter_context *context;
  864. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  865. if (error != CS_OK) {
  866. return (error);
  867. }
  868. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  869. if (!context) {
  870. context = malloc(sizeof(struct iter_context));
  871. if (!context) {
  872. error = CS_ERR_NO_MEMORY;
  873. goto ret;
  874. }
  875. context->parent_object_handle = object_handle;
  876. context->find_handle = 0;
  877. list_add(&context->list, &confdb_inst->object_iter_head);
  878. }
  879. /* Start a new find context */
  880. if (context->find_handle) {
  881. (void)do_find_destroy(confdb_inst, context->find_handle);
  882. context->find_handle = 0;
  883. }
  884. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  885. ret:
  886. return error;
  887. }
  888. cs_error_t confdb_key_iter_start (
  889. confdb_handle_t handle,
  890. unsigned int object_handle)
  891. {
  892. struct confdb_inst *confdb_inst;
  893. cs_error_t error = CS_OK;
  894. struct iter_context *context;
  895. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  896. if (error != CS_OK) {
  897. return (error);
  898. }
  899. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  900. if (!context) {
  901. context = malloc(sizeof(struct iter_context));
  902. if (!context) {
  903. error = CS_ERR_NO_MEMORY;
  904. goto ret;
  905. }
  906. context->parent_object_handle = object_handle;
  907. list_add(&context->list, &confdb_inst->key_iter_head);
  908. }
  909. context->find_handle = 0;
  910. context->next_entry = 0;
  911. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  912. ret:
  913. return error;
  914. }
  915. cs_error_t confdb_object_find_start (
  916. confdb_handle_t handle,
  917. unsigned int parent_object_handle)
  918. {
  919. struct confdb_inst *confdb_inst;
  920. cs_error_t error = CS_OK;
  921. struct iter_context *context;
  922. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  923. if (error != CS_OK) {
  924. return (error);
  925. }
  926. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  927. if (!context) {
  928. context = malloc(sizeof(struct iter_context));
  929. if (!context) {
  930. error = CS_ERR_NO_MEMORY;
  931. goto ret;
  932. }
  933. context->find_handle = 0;
  934. context->parent_object_handle = parent_object_handle;
  935. list_add(&context->list, &confdb_inst->object_find_head);
  936. }
  937. /* Start a new find context */
  938. if (context->find_handle) {
  939. (void)do_find_destroy(confdb_inst, context->find_handle);
  940. context->find_handle = 0;
  941. }
  942. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  943. ret:
  944. return error;
  945. }
  946. cs_error_t confdb_object_find (
  947. confdb_handle_t handle,
  948. unsigned int parent_object_handle,
  949. void *object_name,
  950. int object_name_len,
  951. unsigned int *object_handle)
  952. {
  953. cs_error_t error;
  954. struct confdb_inst *confdb_inst;
  955. struct iovec iov;
  956. struct iter_context *context;
  957. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  958. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  959. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  960. if (error != CS_OK) {
  961. return (error);
  962. }
  963. /* You MUST call confdb_object_find_start first */
  964. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  965. if (!context) {
  966. error = CS_ERR_CONTEXT_NOT_FOUND;
  967. goto error_exit;
  968. }
  969. if (confdb_inst->standalone) {
  970. error = CS_OK;
  971. if (confdb_sa_object_find(parent_object_handle,
  972. &context->find_handle,
  973. object_handle,
  974. object_name, &object_name_len,
  975. 0))
  976. error = CS_ERR_ACCESS;
  977. goto error_exit;
  978. }
  979. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  980. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  981. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  982. req_lib_confdb_object_find.find_handle = context->find_handle;
  983. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  984. req_lib_confdb_object_find.object_name.length = object_name_len;
  985. iov.iov_base = (char *)&req_lib_confdb_object_find;
  986. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  987. pthread_mutex_lock (&confdb_inst->response_mutex);
  988. error = cslib_msg_send_reply_receive (
  989. confdb_inst->ipc_ctx,
  990. &iov,
  991. 1,
  992. &res_lib_confdb_object_find,
  993. sizeof (struct res_lib_confdb_object_find));
  994. pthread_mutex_unlock (&confdb_inst->response_mutex);
  995. if (error != CS_OK) {
  996. goto error_exit;
  997. }
  998. error = res_lib_confdb_object_find.header.error;
  999. *object_handle = res_lib_confdb_object_find.object_handle;
  1000. context->find_handle = res_lib_confdb_object_find.find_handle;
  1001. error_exit:
  1002. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1003. return (error);
  1004. }
  1005. cs_error_t confdb_object_iter (
  1006. confdb_handle_t handle,
  1007. unsigned int parent_object_handle,
  1008. unsigned int *object_handle,
  1009. void *object_name,
  1010. int *object_name_len)
  1011. {
  1012. cs_error_t error;
  1013. struct confdb_inst *confdb_inst;
  1014. struct iovec iov;
  1015. struct iter_context *context;
  1016. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1017. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1018. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1019. if (error != CS_OK) {
  1020. return (error);
  1021. }
  1022. /* You MUST call confdb_object_iter_start first */
  1023. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1024. if (!context) {
  1025. error = CS_ERR_CONTEXT_NOT_FOUND;
  1026. goto error_exit;
  1027. }
  1028. if (confdb_inst->standalone) {
  1029. error = CS_OK;
  1030. *object_name_len = 0;
  1031. if (confdb_sa_object_find(parent_object_handle,
  1032. &context->find_handle,
  1033. object_handle,
  1034. object_name, object_name_len,
  1035. 1))
  1036. error = CS_ERR_ACCESS;
  1037. goto sa_exit;
  1038. }
  1039. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1040. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1041. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1042. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1043. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1044. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1045. pthread_mutex_lock (&confdb_inst->response_mutex);
  1046. error = cslib_msg_send_reply_receive (
  1047. confdb_inst->ipc_ctx,
  1048. &iov,
  1049. 1,
  1050. &res_lib_confdb_object_iter,
  1051. sizeof (struct res_lib_confdb_object_iter));
  1052. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1053. if (error != CS_OK) {
  1054. goto error_exit;
  1055. }
  1056. error = res_lib_confdb_object_iter.header.error;
  1057. if (error == CS_OK) {
  1058. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1059. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1060. *object_handle = res_lib_confdb_object_iter.object_handle;
  1061. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1062. }
  1063. sa_exit:
  1064. error_exit:
  1065. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1066. return (error);
  1067. }
  1068. cs_error_t confdb_key_iter (
  1069. confdb_handle_t handle,
  1070. unsigned int parent_object_handle,
  1071. void *key_name,
  1072. int *key_name_len,
  1073. void *value,
  1074. int *value_len)
  1075. {
  1076. cs_error_t error;
  1077. struct confdb_inst *confdb_inst;
  1078. struct iovec iov;
  1079. struct iter_context *context;
  1080. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1081. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1082. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1083. if (error != CS_OK) {
  1084. return (error);
  1085. }
  1086. /* You MUST call confdb_key_iter_start first */
  1087. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1088. if (!context) {
  1089. error = CS_ERR_CONTEXT_NOT_FOUND;
  1090. goto error_exit;
  1091. }
  1092. if (confdb_inst->standalone) {
  1093. error = CS_OK;
  1094. if (confdb_sa_key_iter(parent_object_handle,
  1095. context->next_entry,
  1096. key_name, key_name_len,
  1097. value, value_len))
  1098. error = CS_ERR_ACCESS;
  1099. goto sa_exit;
  1100. }
  1101. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1102. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1103. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1104. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1105. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1106. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1107. pthread_mutex_lock (&confdb_inst->response_mutex);
  1108. error = cslib_msg_send_reply_receive (
  1109. confdb_inst->ipc_ctx,
  1110. &iov,
  1111. 1,
  1112. &res_lib_confdb_key_iter,
  1113. sizeof (struct res_lib_confdb_key_iter));
  1114. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1115. if (error != CS_OK) {
  1116. goto error_exit;
  1117. }
  1118. error = res_lib_confdb_key_iter.header.error;
  1119. if (error == CS_OK) {
  1120. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1121. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1122. *value_len = res_lib_confdb_key_iter.value.length;
  1123. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1124. }
  1125. sa_exit:
  1126. context->next_entry++;
  1127. error_exit:
  1128. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1129. return (error);
  1130. }
  1131. cs_error_t confdb_write (
  1132. confdb_handle_t handle,
  1133. char *error_text)
  1134. {
  1135. cs_error_t error;
  1136. struct confdb_inst *confdb_inst;
  1137. struct iovec iov;
  1138. mar_req_header_t req;
  1139. struct res_lib_confdb_write res_lib_confdb_write;
  1140. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1141. if (error != CS_OK) {
  1142. return (error);
  1143. }
  1144. if (confdb_inst->standalone) {
  1145. error = CS_OK;
  1146. if (confdb_sa_write(error_text))
  1147. error = CS_ERR_ACCESS;
  1148. goto error_exit;
  1149. }
  1150. req.size = sizeof (mar_req_header_t);
  1151. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1152. iov.iov_base = (char *)&req;
  1153. iov.iov_len = sizeof (mar_req_header_t);
  1154. pthread_mutex_lock (&confdb_inst->response_mutex);
  1155. error = cslib_msg_send_reply_receive (
  1156. confdb_inst->ipc_ctx,
  1157. &iov,
  1158. 1,
  1159. &res_lib_confdb_write,
  1160. sizeof (struct res_lib_confdb_write));
  1161. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1162. if (error != CS_OK) {
  1163. goto error_exit;
  1164. }
  1165. error = res_lib_confdb_write.header.error;
  1166. if (res_lib_confdb_write.error.length)
  1167. memcpy(error_text, res_lib_confdb_write.error.value, res_lib_confdb_write.error.length);
  1168. error_exit:
  1169. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1170. return (error);
  1171. }
  1172. cs_error_t confdb_reload (
  1173. confdb_handle_t handle,
  1174. int flush,
  1175. char *error_text)
  1176. {
  1177. cs_error_t error;
  1178. struct confdb_inst *confdb_inst;
  1179. struct iovec iov;
  1180. struct res_lib_confdb_reload res_lib_confdb_reload;
  1181. struct req_lib_confdb_reload req_lib_confdb_reload;
  1182. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1183. if (error != CS_OK) {
  1184. return (error);
  1185. }
  1186. if (confdb_inst->standalone) {
  1187. error = CS_OK;
  1188. if (confdb_sa_reload(flush, error_text))
  1189. error = CS_ERR_ACCESS;
  1190. goto error_exit;
  1191. }
  1192. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1193. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1194. req_lib_confdb_reload.flush = flush;
  1195. iov.iov_base = (char *)&req_lib_confdb_reload;
  1196. iov.iov_len = sizeof (req_lib_confdb_reload);
  1197. pthread_mutex_lock (&confdb_inst->response_mutex);
  1198. error = cslib_msg_send_reply_receive (
  1199. confdb_inst->ipc_ctx,
  1200. &iov,
  1201. 1,
  1202. &res_lib_confdb_reload,
  1203. sizeof (struct res_lib_confdb_reload));
  1204. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1205. if (error != CS_OK) {
  1206. goto error_exit;
  1207. }
  1208. error = res_lib_confdb_reload.header.error;
  1209. if(res_lib_confdb_reload.error.length)
  1210. memcpy(error_text, res_lib_confdb_reload.error.value, res_lib_confdb_reload.error.length);
  1211. error_exit:
  1212. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1213. return (error);
  1214. }
  1215. cs_error_t confdb_track_changes (
  1216. confdb_handle_t handle,
  1217. unsigned int object_handle,
  1218. unsigned int flags)
  1219. {
  1220. cs_error_t error;
  1221. struct confdb_inst *confdb_inst;
  1222. struct iovec iov;
  1223. struct req_lib_confdb_object_track_start req;
  1224. mar_res_header_t res;
  1225. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1226. if (error != CS_OK) {
  1227. return (error);
  1228. }
  1229. if (confdb_inst->standalone) {
  1230. error = CS_ERR_NOT_SUPPORTED;
  1231. goto error_exit;
  1232. }
  1233. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1234. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1235. req.object_handle = object_handle;
  1236. req.flags = flags;
  1237. iov.iov_base = (char *)&req;
  1238. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1239. pthread_mutex_lock (&confdb_inst->response_mutex);
  1240. error = cslib_msg_send_reply_receive (
  1241. confdb_inst->ipc_ctx,
  1242. &iov,
  1243. 1,
  1244. &res,
  1245. sizeof (mar_res_header_t));
  1246. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1247. if (error != CS_OK) {
  1248. goto error_exit;
  1249. }
  1250. error = res.error;
  1251. error_exit:
  1252. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1253. return (error);
  1254. }
  1255. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1256. {
  1257. cs_error_t error;
  1258. struct confdb_inst *confdb_inst;
  1259. struct iovec iov;
  1260. mar_req_header_t req;
  1261. mar_res_header_t res;
  1262. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1263. if (error != CS_OK) {
  1264. return (error);
  1265. }
  1266. if (confdb_inst->standalone) {
  1267. error = CS_ERR_NOT_SUPPORTED;
  1268. goto error_exit;
  1269. }
  1270. req.size = sizeof (mar_req_header_t);
  1271. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1272. iov.iov_base = (char *)&req;
  1273. iov.iov_len = sizeof (mar_req_header_t);
  1274. pthread_mutex_lock (&confdb_inst->response_mutex);
  1275. error = cslib_msg_send_reply_receive (
  1276. confdb_inst->ipc_ctx,
  1277. &iov,
  1278. 1,
  1279. &res,
  1280. sizeof (mar_res_header_t));
  1281. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1282. if (error != CS_OK) {
  1283. goto error_exit;
  1284. }
  1285. error = res.error;
  1286. error_exit:
  1287. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1288. return (error);
  1289. }