confdb.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  1. /*
  2. * Copyright (c) 2008-2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * Provides access to data in the corosync object database
  36. */
  37. #include <config.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include <pthread.h>
  42. #include <sys/types.h>
  43. #include <errno.h>
  44. #include <corosync/corotypes.h>
  45. #include <corosync/confdb.h>
  46. #include <corosync/ipc_confdb.h>
  47. #include <corosync/mar_gen.h>
  48. #include <corosync/coroipcc.h>
  49. #include <corosync/list.h>
  50. #include "sa-confdb.h"
  51. /* Hold the information for iterators so that
  52. callers can do recursive tree traversals.
  53. each object_handle can have its own iterator */
  54. struct iter_context {
  55. struct list_head list;
  56. hdb_handle_t parent_object_handle;
  57. hdb_handle_t find_handle;
  58. hdb_handle_t next_entry;
  59. };
  60. struct confdb_inst {
  61. void *ipc_ctx;
  62. int finalize;
  63. int standalone;
  64. confdb_callbacks_t callbacks;
  65. const void *context;
  66. pthread_mutex_t response_mutex;
  67. pthread_mutex_t dispatch_mutex;
  68. struct list_head object_find_head;
  69. struct list_head object_iter_head;
  70. struct list_head key_iter_head;
  71. };
  72. static void confdb_instance_destructor (void *instance);
  73. static struct saHandleDatabase confdb_handle_t_db = {
  74. .handleCount = 0,
  75. .handles = 0,
  76. .mutex = PTHREAD_MUTEX_INITIALIZER,
  77. .handleInstanceDestructor = confdb_instance_destructor
  78. };
  79. static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
  80. /* Safely tidy one iterator context list */
  81. static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
  82. {
  83. struct iter_context *context;
  84. struct list_head *iter, *tmp;
  85. for (iter = list->next, tmp = iter->next;
  86. iter != list; iter = tmp, tmp = iter->next) {
  87. context = list_entry (iter, struct iter_context, list);
  88. (void)do_find_destroy(confdb_inst, context->find_handle);
  89. free(context);
  90. }
  91. }
  92. /*
  93. * Clean up function for a confdb instance (confdb_initialize) handle
  94. */
  95. static void confdb_instance_destructor (void *instance)
  96. {
  97. struct confdb_inst *confdb_inst = instance;
  98. pthread_mutex_destroy (&confdb_inst->response_mutex);
  99. pthread_mutex_destroy (&confdb_inst->dispatch_mutex);
  100. }
  101. static struct iter_context *find_iter_context(struct list_head *list, hdb_handle_t object_handle)
  102. {
  103. struct iter_context *context;
  104. struct list_head *iter;
  105. for (iter = list->next;
  106. iter != list; iter = iter->next) {
  107. context = list_entry (iter, struct iter_context, list);
  108. if (context->parent_object_handle == object_handle)
  109. return context;
  110. }
  111. return NULL;
  112. }
  113. /**
  114. * @defgroup confdb_corosync
  115. * @ingroup corosync
  116. *
  117. * @{
  118. */
  119. cs_error_t confdb_initialize (
  120. confdb_handle_t *handle,
  121. confdb_callbacks_t *callbacks)
  122. {
  123. cs_error_t error;
  124. struct confdb_inst *confdb_inst;
  125. error = saHandleCreate (&confdb_handle_t_db, sizeof (struct confdb_inst), handle);
  126. if (error != CS_OK) {
  127. goto error_no_destroy;
  128. }
  129. error = saHandleInstanceGet (&confdb_handle_t_db, *handle, (void *)&confdb_inst);
  130. if (error != CS_OK) {
  131. goto error_destroy;
  132. }
  133. if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
  134. error = confdb_sa_init();
  135. confdb_inst->standalone = 1;
  136. }
  137. else {
  138. error = coroipcc_service_connect (IPC_SOCKET_NAME, CONFDB_SERVICE, &confdb_inst->ipc_ctx);
  139. }
  140. if (error != CS_OK)
  141. goto error_put_destroy;
  142. memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
  143. pthread_mutex_init (&confdb_inst->response_mutex, NULL);
  144. pthread_mutex_init (&confdb_inst->dispatch_mutex, NULL);
  145. list_init (&confdb_inst->object_find_head);
  146. list_init (&confdb_inst->object_iter_head);
  147. list_init (&confdb_inst->key_iter_head);
  148. (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
  149. return (CS_OK);
  150. error_put_destroy:
  151. (void)saHandleInstancePut (&confdb_handle_t_db, *handle);
  152. error_destroy:
  153. (void)saHandleDestroy (&confdb_handle_t_db, *handle);
  154. error_no_destroy:
  155. return (error);
  156. }
  157. cs_error_t confdb_finalize (
  158. confdb_handle_t handle)
  159. {
  160. struct confdb_inst *confdb_inst;
  161. cs_error_t error;
  162. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  163. if (error != CS_OK) {
  164. return (error);
  165. }
  166. pthread_mutex_lock (&confdb_inst->response_mutex);
  167. /*
  168. * Another thread has already started finalizing
  169. */
  170. if (confdb_inst->finalize) {
  171. pthread_mutex_unlock (&confdb_inst->response_mutex);
  172. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  173. return (CS_ERR_BAD_HANDLE);
  174. }
  175. confdb_inst->finalize = 1;
  176. pthread_mutex_unlock (&confdb_inst->response_mutex);
  177. /* Free saved context handles */
  178. free_context_list(confdb_inst, &confdb_inst->object_find_head);
  179. free_context_list(confdb_inst, &confdb_inst->object_iter_head);
  180. free_context_list(confdb_inst, &confdb_inst->key_iter_head);
  181. if (!confdb_inst->standalone) {
  182. coroipcc_service_disconnect (confdb_inst->ipc_ctx);
  183. }
  184. (void)saHandleDestroy (&confdb_handle_t_db, handle);
  185. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  186. return (CS_OK);
  187. }
  188. cs_error_t confdb_fd_get (
  189. confdb_handle_t handle,
  190. int *fd)
  191. {
  192. cs_error_t error;
  193. struct confdb_inst *confdb_inst;
  194. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  195. if (error != CS_OK) {
  196. return (error);
  197. }
  198. *fd = coroipcc_fd_get (confdb_inst->ipc_ctx);
  199. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  200. return (CS_OK);
  201. }
  202. cs_error_t confdb_context_get (
  203. confdb_handle_t handle,
  204. const void **context)
  205. {
  206. cs_error_t error;
  207. struct confdb_inst *confdb_inst;
  208. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  209. if (error != CS_OK) {
  210. return (error);
  211. }
  212. *context = confdb_inst->context;
  213. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  214. return (CS_OK);
  215. }
  216. cs_error_t confdb_context_set (
  217. confdb_handle_t handle,
  218. const void *context)
  219. {
  220. cs_error_t error;
  221. struct confdb_inst *confdb_inst;
  222. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  223. if (error != CS_OK) {
  224. return (error);
  225. }
  226. confdb_inst->context = context;
  227. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  228. return (CS_OK);
  229. }
  230. struct confdb_res_overlay {
  231. mar_res_header_t header __attribute__((aligned(8)));
  232. char data[512000];
  233. };
  234. cs_error_t confdb_dispatch (
  235. confdb_handle_t handle,
  236. cs_dispatch_flags_t dispatch_types)
  237. {
  238. int timeout = -1;
  239. cs_error_t error;
  240. int cont = 1; /* always continue do loop except when set to 0 */
  241. int dispatch_avail;
  242. struct confdb_inst *confdb_inst;
  243. confdb_callbacks_t callbacks;
  244. struct res_lib_confdb_key_change_callback *res_key_changed_pt;
  245. struct res_lib_confdb_object_create_callback *res_object_created_pt;
  246. struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
  247. struct confdb_res_overlay dispatch_data;
  248. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  249. if (error != CS_OK) {
  250. return (error);
  251. }
  252. if (confdb_inst->standalone) {
  253. error = CS_ERR_NOT_SUPPORTED;
  254. goto error_put;
  255. }
  256. /*
  257. * Timeout instantly for SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  258. * wait indefinately for SA_DISPATCH_BLOCKING
  259. */
  260. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  261. timeout = 0;
  262. }
  263. do {
  264. pthread_mutex_lock (&confdb_inst->dispatch_mutex);
  265. dispatch_avail = coroipcc_dispatch_recv (confdb_inst->ipc_ctx,
  266. (void *)&dispatch_data, 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. if (dispatch_avail == 0 && dispatch_types == CONFDB_DISPATCH_ALL) {
  276. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  277. break; /* exit do while cont is 1 loop */
  278. } else
  279. if (dispatch_avail == 0) {
  280. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  281. continue; /* next poll */
  282. }
  283. /*
  284. * Make copy of callbacks, message data, unlock instance, and call callback
  285. * A risk of this dispatch method is that the callback routines may
  286. * operate at the same time that confdbFinalize has been called.
  287. */
  288. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  289. pthread_mutex_unlock (&confdb_inst->dispatch_mutex);
  290. /*
  291. * Dispatch incoming message
  292. */
  293. switch (dispatch_data.header.id) {
  294. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  295. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)&dispatch_data;
  296. callbacks.confdb_key_change_notify_fn(handle,
  297. res_key_changed_pt->change_type,
  298. res_key_changed_pt->object_handle,
  299. res_key_changed_pt->parent_object_handle,
  300. res_key_changed_pt->object_name.value,
  301. res_key_changed_pt->object_name.length,
  302. res_key_changed_pt->key_name.value,
  303. res_key_changed_pt->key_name.length,
  304. res_key_changed_pt->key_value.value,
  305. res_key_changed_pt->key_value.length);
  306. break;
  307. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  308. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)&dispatch_data;
  309. callbacks.confdb_object_create_change_notify_fn(handle,
  310. res_object_created_pt->object_handle,
  311. res_object_created_pt->parent_object_handle,
  312. res_object_created_pt->name.value,
  313. res_object_created_pt->name.length);
  314. break;
  315. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  316. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)&dispatch_data;
  317. callbacks.confdb_object_delete_change_notify_fn(handle,
  318. res_object_destroyed_pt->parent_object_handle,
  319. res_object_destroyed_pt->name.value,
  320. res_object_destroyed_pt->name.length);
  321. break;
  322. default:
  323. error = CS_ERR_LIBRARY;
  324. goto error_noput;
  325. break;
  326. }
  327. /*
  328. * Determine if more messages should be processed
  329. * */
  330. switch (dispatch_types) {
  331. case CONFDB_DISPATCH_ONE:
  332. cont = 0;
  333. break;
  334. case CONFDB_DISPATCH_ALL:
  335. break;
  336. case CONFDB_DISPATCH_BLOCKING:
  337. break;
  338. }
  339. } while (cont);
  340. error_put:
  341. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  342. error_noput:
  343. return (error);
  344. }
  345. cs_error_t confdb_object_create (
  346. confdb_handle_t handle,
  347. hdb_handle_t parent_object_handle,
  348. const void *object_name,
  349. int object_name_len,
  350. hdb_handle_t *object_handle)
  351. {
  352. cs_error_t error;
  353. struct confdb_inst *confdb_inst;
  354. struct iovec iov;
  355. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  356. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  357. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  358. if (error != CS_OK) {
  359. return (error);
  360. }
  361. if (confdb_inst->standalone) {
  362. error = CS_OK;
  363. if (confdb_sa_object_create(parent_object_handle,
  364. object_name, object_name_len,
  365. object_handle))
  366. error = CS_ERR_ACCESS;
  367. goto error_exit;
  368. }
  369. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  370. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  371. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  372. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  373. req_lib_confdb_object_create.object_name.length = object_name_len;
  374. iov.iov_base = (char *)&req_lib_confdb_object_create;
  375. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  376. pthread_mutex_lock (&confdb_inst->response_mutex);
  377. error = coroipcc_msg_send_reply_receive (
  378. confdb_inst->ipc_ctx,
  379. &iov,
  380. 1,
  381. &res_lib_confdb_object_create,
  382. sizeof (struct res_lib_confdb_object_create));
  383. pthread_mutex_unlock (&confdb_inst->response_mutex);
  384. if (error != CS_OK) {
  385. goto error_exit;
  386. }
  387. error = res_lib_confdb_object_create.header.error;
  388. *object_handle = res_lib_confdb_object_create.object_handle;
  389. error_exit:
  390. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  391. return (error);
  392. }
  393. cs_error_t confdb_object_destroy (
  394. confdb_handle_t handle,
  395. hdb_handle_t object_handle)
  396. {
  397. cs_error_t error;
  398. struct confdb_inst *confdb_inst;
  399. struct iovec iov;
  400. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  401. mar_res_header_t res;
  402. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  403. if (error != CS_OK) {
  404. return (error);
  405. }
  406. if (confdb_inst->standalone) {
  407. error = CS_OK;
  408. if (confdb_sa_object_destroy(object_handle))
  409. error = CS_ERR_ACCESS;
  410. goto error_exit;
  411. }
  412. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  413. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  414. req_lib_confdb_object_destroy.object_handle = object_handle;
  415. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  416. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  417. pthread_mutex_lock (&confdb_inst->response_mutex);
  418. error = coroipcc_msg_send_reply_receive (
  419. confdb_inst->ipc_ctx,
  420. &iov,
  421. 1,
  422. &res,
  423. sizeof (mar_res_header_t));
  424. pthread_mutex_unlock (&confdb_inst->response_mutex);
  425. if (error != CS_OK) {
  426. goto error_exit;
  427. }
  428. error = res.error;
  429. error_exit:
  430. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  431. return (error);
  432. }
  433. cs_error_t confdb_object_parent_get (
  434. confdb_handle_t handle,
  435. hdb_handle_t object_handle,
  436. hdb_handle_t *parent_object_handle)
  437. {
  438. cs_error_t error;
  439. struct confdb_inst *confdb_inst;
  440. struct iovec iov;
  441. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  442. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  443. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  444. if (error != CS_OK) {
  445. return (error);
  446. }
  447. if (confdb_inst->standalone) {
  448. error = CS_OK;
  449. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  450. error = CS_ERR_ACCESS;
  451. goto error_exit;
  452. }
  453. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  454. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  455. req_lib_confdb_object_parent_get.object_handle = object_handle;
  456. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  457. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  458. pthread_mutex_lock (&confdb_inst->response_mutex);
  459. error = coroipcc_msg_send_reply_receive (
  460. confdb_inst->ipc_ctx,
  461. &iov,
  462. 1,
  463. &res_lib_confdb_object_parent_get,
  464. sizeof (struct res_lib_confdb_object_parent_get));
  465. pthread_mutex_unlock (&confdb_inst->response_mutex);
  466. if (error != CS_OK) {
  467. goto error_exit;
  468. }
  469. error = res_lib_confdb_object_parent_get.header.error;
  470. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  471. error_exit:
  472. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  473. return (error);
  474. }
  475. static cs_error_t do_find_destroy(
  476. struct confdb_inst *confdb_inst,
  477. hdb_handle_t find_handle)
  478. {
  479. cs_error_t error;
  480. struct iovec iov;
  481. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  482. mar_res_header_t res;
  483. if (!find_handle)
  484. return CS_OK;
  485. if (confdb_inst->standalone) {
  486. error = CS_OK;
  487. if (confdb_sa_find_destroy(find_handle))
  488. error = CS_ERR_ACCESS;
  489. goto error_exit;
  490. }
  491. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  492. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  493. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  494. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  495. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  496. pthread_mutex_lock (&confdb_inst->response_mutex);
  497. error = coroipcc_msg_send_reply_receive (
  498. confdb_inst->ipc_ctx,
  499. &iov,
  500. 1,
  501. &res,
  502. sizeof (mar_res_header_t));
  503. pthread_mutex_unlock (&confdb_inst->response_mutex);
  504. if (error != CS_OK) {
  505. goto error_exit;
  506. }
  507. error = res.error;
  508. error_exit:
  509. return (error);
  510. }
  511. cs_error_t confdb_object_find_destroy(
  512. confdb_handle_t handle,
  513. hdb_handle_t parent_object_handle)
  514. {
  515. struct iter_context *context;
  516. cs_error_t error;
  517. struct confdb_inst *confdb_inst;
  518. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  519. if (error != CS_OK) {
  520. return (error);
  521. }
  522. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  523. error = do_find_destroy(confdb_inst, context->find_handle);
  524. if (error == CS_OK) {
  525. list_del(&context->list);
  526. free(context);
  527. }
  528. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  529. return error;
  530. }
  531. cs_error_t confdb_object_iter_destroy(
  532. confdb_handle_t handle,
  533. hdb_handle_t parent_object_handle)
  534. {
  535. struct iter_context *context;
  536. cs_error_t error;
  537. struct confdb_inst *confdb_inst;
  538. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  539. if (error != CS_OK) {
  540. return (error);
  541. }
  542. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  543. error = do_find_destroy(confdb_inst, context->find_handle);
  544. if (error == CS_OK) {
  545. list_del(&context->list);
  546. free(context);
  547. }
  548. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  549. return error;
  550. }
  551. cs_error_t confdb_key_create (
  552. confdb_handle_t handle,
  553. hdb_handle_t parent_object_handle,
  554. const void *key_name,
  555. int key_name_len,
  556. const void *value,
  557. int value_len)
  558. {
  559. cs_error_t error;
  560. struct confdb_inst *confdb_inst;
  561. struct iovec iov;
  562. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  563. mar_res_header_t res;
  564. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  565. if (error != CS_OK) {
  566. return (error);
  567. }
  568. if (confdb_inst->standalone) {
  569. error = CS_OK;
  570. if (confdb_sa_key_create(parent_object_handle,
  571. key_name, key_name_len,
  572. value, value_len))
  573. error = CS_ERR_ACCESS;
  574. goto error_exit;
  575. }
  576. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  577. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  578. req_lib_confdb_key_create.object_handle = parent_object_handle;
  579. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  580. req_lib_confdb_key_create.key_name.length = key_name_len;
  581. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  582. req_lib_confdb_key_create.value.length = value_len;
  583. iov.iov_base = (char *)&req_lib_confdb_key_create;
  584. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  585. pthread_mutex_lock (&confdb_inst->response_mutex);
  586. error = coroipcc_msg_send_reply_receive (
  587. confdb_inst->ipc_ctx,
  588. &iov,
  589. 1,
  590. &res,
  591. sizeof (res));
  592. pthread_mutex_unlock (&confdb_inst->response_mutex);
  593. if (error != CS_OK) {
  594. goto error_exit;
  595. }
  596. error = res.error;
  597. error_exit:
  598. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  599. return (error);
  600. }
  601. cs_error_t confdb_key_delete (
  602. confdb_handle_t handle,
  603. hdb_handle_t parent_object_handle,
  604. const void *key_name,
  605. int key_name_len,
  606. const void *value,
  607. int value_len)
  608. {
  609. cs_error_t error;
  610. struct confdb_inst *confdb_inst;
  611. struct iovec iov;
  612. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  613. mar_res_header_t res;
  614. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  615. if (error != CS_OK) {
  616. return (error);
  617. }
  618. if (confdb_inst->standalone) {
  619. error = CS_OK;
  620. if (confdb_sa_key_delete(parent_object_handle,
  621. key_name, key_name_len,
  622. value, value_len))
  623. error = CS_ERR_ACCESS;
  624. goto error_exit;
  625. }
  626. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  627. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  628. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  629. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  630. req_lib_confdb_key_delete.key_name.length = key_name_len;
  631. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  632. req_lib_confdb_key_delete.value.length = value_len;
  633. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  634. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  635. pthread_mutex_lock (&confdb_inst->response_mutex);
  636. error = coroipcc_msg_send_reply_receive (
  637. confdb_inst->ipc_ctx,
  638. &iov,
  639. 1,
  640. &res,
  641. sizeof (res));
  642. pthread_mutex_unlock (&confdb_inst->response_mutex);
  643. if (error != CS_OK) {
  644. goto error_exit;
  645. }
  646. error = res.error;
  647. error_exit:
  648. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  649. return (error);
  650. }
  651. cs_error_t confdb_key_get (
  652. confdb_handle_t handle,
  653. hdb_handle_t parent_object_handle,
  654. const void *key_name,
  655. int key_name_len,
  656. void *value,
  657. int *value_len)
  658. {
  659. cs_error_t error;
  660. struct confdb_inst *confdb_inst;
  661. struct iovec iov;
  662. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  663. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  664. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  665. if (error != CS_OK) {
  666. return (error);
  667. }
  668. if (confdb_inst->standalone) {
  669. error = CS_OK;
  670. if (confdb_sa_key_get(parent_object_handle,
  671. key_name, key_name_len,
  672. value, value_len))
  673. error = CS_ERR_ACCESS;
  674. goto error_exit;
  675. }
  676. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  677. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  678. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  679. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  680. req_lib_confdb_key_get.key_name.length = key_name_len;
  681. iov.iov_base = (char *)&req_lib_confdb_key_get;
  682. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  683. pthread_mutex_lock (&confdb_inst->response_mutex);
  684. error = coroipcc_msg_send_reply_receive (
  685. confdb_inst->ipc_ctx,
  686. &iov,
  687. 1,
  688. &res_lib_confdb_key_get,
  689. sizeof (struct res_lib_confdb_key_get));
  690. pthread_mutex_unlock (&confdb_inst->response_mutex);
  691. if (error != CS_OK) {
  692. goto error_exit;
  693. }
  694. error = res_lib_confdb_key_get.header.error;
  695. if (error == CS_OK) {
  696. *value_len = res_lib_confdb_key_get.value.length;
  697. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  698. }
  699. error_exit:
  700. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  701. return (error);
  702. }
  703. cs_error_t confdb_key_increment (
  704. confdb_handle_t handle,
  705. hdb_handle_t parent_object_handle,
  706. const void *key_name,
  707. int key_name_len,
  708. unsigned int *value)
  709. {
  710. cs_error_t error;
  711. struct confdb_inst *confdb_inst;
  712. struct iovec iov;
  713. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  714. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  715. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  716. if (error != CS_OK) {
  717. return (error);
  718. }
  719. if (confdb_inst->standalone) {
  720. error = CS_OK;
  721. if (confdb_sa_key_increment(parent_object_handle,
  722. key_name, key_name_len,
  723. value))
  724. error = CS_ERR_ACCESS;
  725. goto error_exit;
  726. }
  727. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  728. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  729. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  730. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  731. req_lib_confdb_key_get.key_name.length = key_name_len;
  732. iov.iov_base = (char *)&req_lib_confdb_key_get;
  733. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  734. pthread_mutex_lock (&confdb_inst->response_mutex);
  735. error = coroipcc_msg_send_reply_receive (
  736. confdb_inst->ipc_ctx,
  737. &iov,
  738. 1,
  739. &res_lib_confdb_key_incdec,
  740. sizeof (struct res_lib_confdb_key_incdec));
  741. pthread_mutex_unlock (&confdb_inst->response_mutex);
  742. if (error != CS_OK) {
  743. goto error_exit;
  744. }
  745. error = res_lib_confdb_key_incdec.header.error;
  746. if (error == CS_OK) {
  747. *value = res_lib_confdb_key_incdec.value;
  748. }
  749. error_exit:
  750. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  751. return (error);
  752. }
  753. cs_error_t confdb_key_decrement (
  754. confdb_handle_t handle,
  755. hdb_handle_t parent_object_handle,
  756. const void *key_name,
  757. int key_name_len,
  758. unsigned int *value)
  759. {
  760. cs_error_t error;
  761. struct confdb_inst *confdb_inst;
  762. struct iovec iov;
  763. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  764. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  765. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  766. if (error != CS_OK) {
  767. return (error);
  768. }
  769. if (confdb_inst->standalone) {
  770. error = CS_OK;
  771. if (confdb_sa_key_decrement(parent_object_handle,
  772. key_name, key_name_len,
  773. value))
  774. error = CS_ERR_ACCESS;
  775. goto error_exit;
  776. }
  777. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  778. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  779. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  780. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  781. req_lib_confdb_key_get.key_name.length = key_name_len;
  782. iov.iov_base = (char *)&req_lib_confdb_key_get;
  783. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  784. pthread_mutex_lock (&confdb_inst->response_mutex);
  785. error = coroipcc_msg_send_reply_receive (
  786. confdb_inst->ipc_ctx,
  787. &iov,
  788. 1,
  789. &res_lib_confdb_key_incdec,
  790. sizeof (struct res_lib_confdb_key_incdec));
  791. pthread_mutex_unlock (&confdb_inst->response_mutex);
  792. if (error != CS_OK) {
  793. goto error_exit;
  794. }
  795. error = res_lib_confdb_key_incdec.header.error;
  796. if (error == CS_OK) {
  797. *value = res_lib_confdb_key_incdec.value;
  798. }
  799. error_exit:
  800. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  801. return (error);
  802. }
  803. cs_error_t confdb_key_replace (
  804. confdb_handle_t handle,
  805. hdb_handle_t parent_object_handle,
  806. const void *key_name,
  807. int key_name_len,
  808. const void *old_value,
  809. int old_value_len,
  810. const void *new_value,
  811. int new_value_len)
  812. {
  813. cs_error_t error;
  814. struct confdb_inst *confdb_inst;
  815. struct iovec iov;
  816. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  817. mar_res_header_t res;
  818. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  819. if (error != CS_OK) {
  820. return (error);
  821. }
  822. if (confdb_inst->standalone) {
  823. error = CS_OK;
  824. if (confdb_sa_key_replace(parent_object_handle,
  825. key_name, key_name_len,
  826. old_value, old_value_len,
  827. new_value, new_value_len))
  828. error = CS_ERR_ACCESS;
  829. goto error_exit;
  830. }
  831. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  832. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  833. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  834. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  835. req_lib_confdb_key_replace.key_name.length = key_name_len;
  836. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  837. req_lib_confdb_key_replace.old_value.length = old_value_len;
  838. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  839. req_lib_confdb_key_replace.new_value.length = new_value_len;
  840. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  841. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  842. pthread_mutex_lock (&confdb_inst->response_mutex);
  843. error = coroipcc_msg_send_reply_receive (
  844. confdb_inst->ipc_ctx,
  845. &iov,
  846. 1,
  847. &res,
  848. sizeof (res));
  849. pthread_mutex_unlock (&confdb_inst->response_mutex);
  850. if (error != CS_OK) {
  851. goto error_exit;
  852. }
  853. error = res.error;
  854. error_exit:
  855. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  856. return (error);
  857. }
  858. cs_error_t confdb_object_iter_start (
  859. confdb_handle_t handle,
  860. hdb_handle_t object_handle)
  861. {
  862. struct confdb_inst *confdb_inst;
  863. cs_error_t error = CS_OK;
  864. struct iter_context *context;
  865. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  866. if (error != CS_OK) {
  867. return (error);
  868. }
  869. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  870. if (!context) {
  871. context = malloc(sizeof(struct iter_context));
  872. if (!context) {
  873. error = CS_ERR_NO_MEMORY;
  874. goto ret;
  875. }
  876. context->parent_object_handle = object_handle;
  877. context->find_handle = 0;
  878. list_add(&context->list, &confdb_inst->object_iter_head);
  879. }
  880. /* Start a new find context */
  881. if (context->find_handle) {
  882. (void)do_find_destroy(confdb_inst, context->find_handle);
  883. context->find_handle = 0;
  884. }
  885. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  886. ret:
  887. return error;
  888. }
  889. cs_error_t confdb_key_iter_start (
  890. confdb_handle_t handle,
  891. hdb_handle_t object_handle)
  892. {
  893. struct confdb_inst *confdb_inst;
  894. cs_error_t error = CS_OK;
  895. struct iter_context *context;
  896. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  897. if (error != CS_OK) {
  898. return (error);
  899. }
  900. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  901. if (!context) {
  902. context = malloc(sizeof(struct iter_context));
  903. if (!context) {
  904. error = CS_ERR_NO_MEMORY;
  905. goto ret;
  906. }
  907. context->parent_object_handle = object_handle;
  908. list_add(&context->list, &confdb_inst->key_iter_head);
  909. }
  910. context->find_handle = 0;
  911. context->next_entry = 0;
  912. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  913. ret:
  914. return error;
  915. }
  916. cs_error_t confdb_object_find_start (
  917. confdb_handle_t handle,
  918. hdb_handle_t parent_object_handle)
  919. {
  920. struct confdb_inst *confdb_inst;
  921. cs_error_t error = CS_OK;
  922. struct iter_context *context;
  923. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  924. if (error != CS_OK) {
  925. return (error);
  926. }
  927. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  928. if (!context) {
  929. context = malloc(sizeof(struct iter_context));
  930. if (!context) {
  931. error = CS_ERR_NO_MEMORY;
  932. goto ret;
  933. }
  934. context->find_handle = 0;
  935. context->parent_object_handle = parent_object_handle;
  936. list_add(&context->list, &confdb_inst->object_find_head);
  937. }
  938. /* Start a new find context */
  939. if (context->find_handle) {
  940. (void)do_find_destroy(confdb_inst, context->find_handle);
  941. context->find_handle = 0;
  942. }
  943. (void)saHandleInstancePut (&confdb_handle_t_db, handle);
  944. ret:
  945. return error;
  946. }
  947. cs_error_t confdb_object_find (
  948. confdb_handle_t handle,
  949. hdb_handle_t parent_object_handle,
  950. const void *object_name,
  951. int object_name_len,
  952. hdb_handle_t *object_handle)
  953. {
  954. cs_error_t error;
  955. struct confdb_inst *confdb_inst;
  956. struct iovec iov;
  957. struct iter_context *context;
  958. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  959. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  960. error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst);
  961. if (error != CS_OK) {
  962. return (error);
  963. }
  964. /* You MUST call confdb_object_find_start first */
  965. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  966. if (!context) {
  967. error = CS_ERR_CONTEXT_NOT_FOUND;
  968. goto error_exit;
  969. }
  970. if (confdb_inst->standalone) {
  971. error = CS_OK;
  972. if (confdb_sa_object_find(parent_object_handle,
  973. &context->find_handle,
  974. object_handle,
  975. object_name, object_name_len))
  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 = coroipcc_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. hdb_handle_t parent_object_handle,
  1008. hdb_handle_t *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_iter(parent_object_handle,
  1032. &context->find_handle,
  1033. object_handle,
  1034. NULL, 0,
  1035. object_name, object_name_len))
  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 = coroipcc_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. hdb_handle_t 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 = coroipcc_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 = coroipcc_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 = coroipcc_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. hdb_handle_t 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 = coroipcc_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 = coroipcc_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. }