confdb.c 42 KB

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