confdb.c 45 KB

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