confdb.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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. 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. 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. 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. 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. void *key_name,
  552. int key_name_len,
  553. 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. void *key_name,
  602. int key_name_len,
  603. 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. 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. 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. 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. void *key_name,
  804. int key_name_len,
  805. void *old_value,
  806. int old_value_len,
  807. 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. 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. 0))
  974. error = CS_ERR_ACCESS;
  975. goto error_exit;
  976. }
  977. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  978. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  979. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  980. req_lib_confdb_object_find.find_handle = context->find_handle;
  981. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  982. req_lib_confdb_object_find.object_name.length = object_name_len;
  983. iov.iov_base = (char *)&req_lib_confdb_object_find;
  984. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  985. pthread_mutex_lock (&confdb_inst->response_mutex);
  986. error = cslib_msg_send_reply_receive (
  987. confdb_inst->ipc_ctx,
  988. &iov,
  989. 1,
  990. &res_lib_confdb_object_find,
  991. sizeof (struct res_lib_confdb_object_find));
  992. pthread_mutex_unlock (&confdb_inst->response_mutex);
  993. if (error != CS_OK) {
  994. goto error_exit;
  995. }
  996. error = res_lib_confdb_object_find.header.error;
  997. *object_handle = res_lib_confdb_object_find.object_handle;
  998. context->find_handle = res_lib_confdb_object_find.find_handle;
  999. error_exit:
  1000. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1001. return (error);
  1002. }
  1003. cs_error_t confdb_object_iter (
  1004. confdb_handle_t handle,
  1005. hdb_handle_t parent_object_handle,
  1006. hdb_handle_t *object_handle,
  1007. void *object_name,
  1008. int *object_name_len)
  1009. {
  1010. cs_error_t error;
  1011. struct confdb_inst *confdb_inst;
  1012. struct iovec iov;
  1013. struct iter_context *context;
  1014. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1015. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1016. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1017. if (error != CS_OK) {
  1018. return (error);
  1019. }
  1020. /* You MUST call confdb_object_iter_start first */
  1021. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1022. if (!context) {
  1023. error = CS_ERR_CONTEXT_NOT_FOUND;
  1024. goto error_exit;
  1025. }
  1026. if (confdb_inst->standalone) {
  1027. error = CS_OK;
  1028. *object_name_len = 0;
  1029. if (confdb_sa_object_find(parent_object_handle,
  1030. &context->find_handle,
  1031. object_handle,
  1032. object_name, object_name_len,
  1033. 1))
  1034. error = CS_ERR_ACCESS;
  1035. goto sa_exit;
  1036. }
  1037. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1038. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1039. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1040. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1041. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1042. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1043. pthread_mutex_lock (&confdb_inst->response_mutex);
  1044. error = cslib_msg_send_reply_receive (
  1045. confdb_inst->ipc_ctx,
  1046. &iov,
  1047. 1,
  1048. &res_lib_confdb_object_iter,
  1049. sizeof (struct res_lib_confdb_object_iter));
  1050. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1051. if (error != CS_OK) {
  1052. goto error_exit;
  1053. }
  1054. error = res_lib_confdb_object_iter.header.error;
  1055. if (error == CS_OK) {
  1056. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1057. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1058. *object_handle = res_lib_confdb_object_iter.object_handle;
  1059. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1060. }
  1061. sa_exit:
  1062. error_exit:
  1063. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1064. return (error);
  1065. }
  1066. cs_error_t confdb_key_iter (
  1067. confdb_handle_t handle,
  1068. hdb_handle_t parent_object_handle,
  1069. void *key_name,
  1070. int *key_name_len,
  1071. void *value,
  1072. int *value_len)
  1073. {
  1074. cs_error_t error;
  1075. struct confdb_inst *confdb_inst;
  1076. struct iovec iov;
  1077. struct iter_context *context;
  1078. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1079. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1080. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1081. if (error != CS_OK) {
  1082. return (error);
  1083. }
  1084. /* You MUST call confdb_key_iter_start first */
  1085. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1086. if (!context) {
  1087. error = CS_ERR_CONTEXT_NOT_FOUND;
  1088. goto error_exit;
  1089. }
  1090. if (confdb_inst->standalone) {
  1091. error = CS_OK;
  1092. if (confdb_sa_key_iter(parent_object_handle,
  1093. context->next_entry,
  1094. key_name, key_name_len,
  1095. value, value_len))
  1096. error = CS_ERR_ACCESS;
  1097. goto sa_exit;
  1098. }
  1099. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1100. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1101. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1102. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1103. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1104. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1105. pthread_mutex_lock (&confdb_inst->response_mutex);
  1106. error = cslib_msg_send_reply_receive (
  1107. confdb_inst->ipc_ctx,
  1108. &iov,
  1109. 1,
  1110. &res_lib_confdb_key_iter,
  1111. sizeof (struct res_lib_confdb_key_iter));
  1112. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1113. if (error != CS_OK) {
  1114. goto error_exit;
  1115. }
  1116. error = res_lib_confdb_key_iter.header.error;
  1117. if (error == CS_OK) {
  1118. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1119. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1120. *value_len = res_lib_confdb_key_iter.value.length;
  1121. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1122. }
  1123. sa_exit:
  1124. context->next_entry++;
  1125. error_exit:
  1126. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1127. return (error);
  1128. }
  1129. cs_error_t confdb_write (
  1130. confdb_handle_t handle,
  1131. char *error_text)
  1132. {
  1133. cs_error_t error;
  1134. struct confdb_inst *confdb_inst;
  1135. struct iovec iov;
  1136. mar_req_header_t req;
  1137. struct res_lib_confdb_write res_lib_confdb_write;
  1138. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1139. if (error != CS_OK) {
  1140. return (error);
  1141. }
  1142. if (confdb_inst->standalone) {
  1143. error = CS_OK;
  1144. if (confdb_sa_write(error_text))
  1145. error = CS_ERR_ACCESS;
  1146. goto error_exit;
  1147. }
  1148. req.size = sizeof (mar_req_header_t);
  1149. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1150. iov.iov_base = (char *)&req;
  1151. iov.iov_len = sizeof (mar_req_header_t);
  1152. pthread_mutex_lock (&confdb_inst->response_mutex);
  1153. error = cslib_msg_send_reply_receive (
  1154. confdb_inst->ipc_ctx,
  1155. &iov,
  1156. 1,
  1157. &res_lib_confdb_write,
  1158. sizeof (struct res_lib_confdb_write));
  1159. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1160. if (error != CS_OK) {
  1161. goto error_exit;
  1162. }
  1163. error = res_lib_confdb_write.header.error;
  1164. if (res_lib_confdb_write.error.length)
  1165. memcpy(error_text, res_lib_confdb_write.error.value, res_lib_confdb_write.error.length);
  1166. error_exit:
  1167. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1168. return (error);
  1169. }
  1170. cs_error_t confdb_reload (
  1171. confdb_handle_t handle,
  1172. int flush,
  1173. char *error_text)
  1174. {
  1175. cs_error_t error;
  1176. struct confdb_inst *confdb_inst;
  1177. struct iovec iov;
  1178. struct res_lib_confdb_reload res_lib_confdb_reload;
  1179. struct req_lib_confdb_reload req_lib_confdb_reload;
  1180. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1181. if (error != CS_OK) {
  1182. return (error);
  1183. }
  1184. if (confdb_inst->standalone) {
  1185. error = CS_OK;
  1186. if (confdb_sa_reload(flush, error_text))
  1187. error = CS_ERR_ACCESS;
  1188. goto error_exit;
  1189. }
  1190. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1191. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1192. req_lib_confdb_reload.flush = flush;
  1193. iov.iov_base = (char *)&req_lib_confdb_reload;
  1194. iov.iov_len = sizeof (req_lib_confdb_reload);
  1195. pthread_mutex_lock (&confdb_inst->response_mutex);
  1196. error = cslib_msg_send_reply_receive (
  1197. confdb_inst->ipc_ctx,
  1198. &iov,
  1199. 1,
  1200. &res_lib_confdb_reload,
  1201. sizeof (struct res_lib_confdb_reload));
  1202. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1203. if (error != CS_OK) {
  1204. goto error_exit;
  1205. }
  1206. error = res_lib_confdb_reload.header.error;
  1207. if(res_lib_confdb_reload.error.length)
  1208. memcpy(error_text, res_lib_confdb_reload.error.value, res_lib_confdb_reload.error.length);
  1209. error_exit:
  1210. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1211. return (error);
  1212. }
  1213. cs_error_t confdb_track_changes (
  1214. confdb_handle_t handle,
  1215. hdb_handle_t object_handle,
  1216. unsigned int flags)
  1217. {
  1218. cs_error_t error;
  1219. struct confdb_inst *confdb_inst;
  1220. struct iovec iov;
  1221. struct req_lib_confdb_object_track_start req;
  1222. mar_res_header_t res;
  1223. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1224. if (error != CS_OK) {
  1225. return (error);
  1226. }
  1227. if (confdb_inst->standalone) {
  1228. error = CS_ERR_NOT_SUPPORTED;
  1229. goto error_exit;
  1230. }
  1231. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1232. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1233. req.object_handle = object_handle;
  1234. req.flags = flags;
  1235. iov.iov_base = (char *)&req;
  1236. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1237. pthread_mutex_lock (&confdb_inst->response_mutex);
  1238. error = cslib_msg_send_reply_receive (
  1239. confdb_inst->ipc_ctx,
  1240. &iov,
  1241. 1,
  1242. &res,
  1243. sizeof (mar_res_header_t));
  1244. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1245. if (error != CS_OK) {
  1246. goto error_exit;
  1247. }
  1248. error = res.error;
  1249. error_exit:
  1250. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1251. return (error);
  1252. }
  1253. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1254. {
  1255. cs_error_t error;
  1256. struct confdb_inst *confdb_inst;
  1257. struct iovec iov;
  1258. mar_req_header_t req;
  1259. mar_res_header_t res;
  1260. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  1261. if (error != CS_OK) {
  1262. return (error);
  1263. }
  1264. if (confdb_inst->standalone) {
  1265. error = CS_ERR_NOT_SUPPORTED;
  1266. goto error_exit;
  1267. }
  1268. req.size = sizeof (mar_req_header_t);
  1269. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1270. iov.iov_base = (char *)&req;
  1271. iov.iov_len = sizeof (mar_req_header_t);
  1272. pthread_mutex_lock (&confdb_inst->response_mutex);
  1273. error = cslib_msg_send_reply_receive (
  1274. confdb_inst->ipc_ctx,
  1275. &iov,
  1276. 1,
  1277. &res,
  1278. sizeof (mar_res_header_t));
  1279. pthread_mutex_unlock (&confdb_inst->response_mutex);
  1280. if (error != CS_OK) {
  1281. goto error_exit;
  1282. }
  1283. error = res.error;
  1284. error_exit:
  1285. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  1286. return (error);
  1287. }