confdb.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  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 SA_DISPATCH_ONE or SA_DISPATCH_ALL and
  244. * wait indefinately for SA_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. switch (dispatch_types) {
  327. case CONFDB_DISPATCH_ONE:
  328. cont = 0;
  329. break;
  330. case CONFDB_DISPATCH_ALL:
  331. break;
  332. case CONFDB_DISPATCH_BLOCKING:
  333. break;
  334. }
  335. } while (cont);
  336. error_put:
  337. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  338. error_noput:
  339. return (error);
  340. }
  341. cs_error_t confdb_object_create (
  342. confdb_handle_t handle,
  343. hdb_handle_t parent_object_handle,
  344. const void *object_name,
  345. size_t object_name_len,
  346. hdb_handle_t *object_handle)
  347. {
  348. cs_error_t error;
  349. struct confdb_inst *confdb_inst;
  350. struct iovec iov;
  351. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  352. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  353. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  354. if (error != CS_OK) {
  355. return (error);
  356. }
  357. if (confdb_inst->standalone) {
  358. error = CS_OK;
  359. if (confdb_sa_object_create(parent_object_handle,
  360. object_name, object_name_len,
  361. object_handle))
  362. error = CS_ERR_ACCESS;
  363. goto error_exit;
  364. }
  365. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  366. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  367. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  368. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  369. req_lib_confdb_object_create.object_name.length = object_name_len;
  370. iov.iov_base = (char *)&req_lib_confdb_object_create;
  371. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  372. error = coroipcc_msg_send_reply_receive (
  373. confdb_inst->handle,
  374. &iov,
  375. 1,
  376. &res_lib_confdb_object_create,
  377. sizeof (struct res_lib_confdb_object_create));
  378. if (error != CS_OK) {
  379. goto error_exit;
  380. }
  381. error = res_lib_confdb_object_create.header.error;
  382. *object_handle = res_lib_confdb_object_create.object_handle;
  383. error_exit:
  384. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  385. return (error);
  386. }
  387. cs_error_t confdb_object_destroy (
  388. confdb_handle_t handle,
  389. hdb_handle_t object_handle)
  390. {
  391. cs_error_t error;
  392. struct confdb_inst *confdb_inst;
  393. struct iovec iov;
  394. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  395. coroipc_response_header_t res;
  396. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  397. if (error != CS_OK) {
  398. return (error);
  399. }
  400. if (confdb_inst->standalone) {
  401. error = CS_OK;
  402. if (confdb_sa_object_destroy(object_handle))
  403. error = CS_ERR_ACCESS;
  404. goto error_exit;
  405. }
  406. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  407. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  408. req_lib_confdb_object_destroy.object_handle = object_handle;
  409. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  410. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  411. error = coroipcc_msg_send_reply_receive (
  412. confdb_inst->handle,
  413. &iov,
  414. 1,
  415. &res,
  416. sizeof (coroipc_response_header_t));
  417. if (error != CS_OK) {
  418. goto error_exit;
  419. }
  420. error = res.error;
  421. error_exit:
  422. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  423. return (error);
  424. }
  425. cs_error_t confdb_object_parent_get (
  426. confdb_handle_t handle,
  427. hdb_handle_t object_handle,
  428. hdb_handle_t *parent_object_handle)
  429. {
  430. cs_error_t error;
  431. struct confdb_inst *confdb_inst;
  432. struct iovec iov;
  433. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  434. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  435. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  436. if (error != CS_OK) {
  437. return (error);
  438. }
  439. if (confdb_inst->standalone) {
  440. error = CS_OK;
  441. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  442. error = CS_ERR_ACCESS;
  443. goto error_exit;
  444. }
  445. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  446. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  447. req_lib_confdb_object_parent_get.object_handle = object_handle;
  448. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  449. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  450. error = coroipcc_msg_send_reply_receive (
  451. confdb_inst->handle,
  452. &iov,
  453. 1,
  454. &res_lib_confdb_object_parent_get,
  455. sizeof (struct res_lib_confdb_object_parent_get));
  456. if (error != CS_OK) {
  457. goto error_exit;
  458. }
  459. error = res_lib_confdb_object_parent_get.header.error;
  460. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  461. error_exit:
  462. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  463. return (error);
  464. }
  465. static cs_error_t do_find_destroy(
  466. struct confdb_inst *confdb_inst,
  467. hdb_handle_t find_handle)
  468. {
  469. cs_error_t error;
  470. struct iovec iov;
  471. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  472. coroipc_response_header_t res;
  473. if (!find_handle)
  474. return CS_OK;
  475. if (confdb_inst->standalone) {
  476. error = CS_OK;
  477. if (confdb_sa_find_destroy(find_handle))
  478. error = CS_ERR_ACCESS;
  479. goto error_exit;
  480. }
  481. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  482. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  483. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  484. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  485. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  486. error = coroipcc_msg_send_reply_receive (
  487. confdb_inst->handle,
  488. &iov,
  489. 1,
  490. &res,
  491. sizeof (coroipc_response_header_t));
  492. if (error != CS_OK) {
  493. goto error_exit;
  494. }
  495. error = res.error;
  496. error_exit:
  497. return (error);
  498. }
  499. cs_error_t confdb_object_find_destroy(
  500. confdb_handle_t handle,
  501. hdb_handle_t parent_object_handle)
  502. {
  503. struct iter_context *context;
  504. cs_error_t error;
  505. struct confdb_inst *confdb_inst;
  506. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  507. if (error != CS_OK) {
  508. return (error);
  509. }
  510. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  511. error = do_find_destroy(confdb_inst, context->find_handle);
  512. if (error == CS_OK) {
  513. list_del(&context->list);
  514. free(context);
  515. }
  516. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  517. return error;
  518. }
  519. cs_error_t confdb_object_iter_destroy(
  520. confdb_handle_t handle,
  521. hdb_handle_t parent_object_handle)
  522. {
  523. struct iter_context *context;
  524. cs_error_t error;
  525. struct confdb_inst *confdb_inst;
  526. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  527. if (error != CS_OK) {
  528. return (error);
  529. }
  530. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  531. error = do_find_destroy(confdb_inst, context->find_handle);
  532. if (error == CS_OK) {
  533. list_del(&context->list);
  534. free(context);
  535. }
  536. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  537. return error;
  538. }
  539. cs_error_t confdb_key_create (
  540. confdb_handle_t handle,
  541. hdb_handle_t parent_object_handle,
  542. const void *key_name,
  543. size_t key_name_len,
  544. const void *value,
  545. size_t value_len)
  546. {
  547. cs_error_t error;
  548. struct confdb_inst *confdb_inst;
  549. struct iovec iov;
  550. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  551. coroipc_response_header_t res;
  552. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  553. if (error != CS_OK) {
  554. return (error);
  555. }
  556. if (confdb_inst->standalone) {
  557. error = CS_OK;
  558. if (confdb_sa_key_create(parent_object_handle,
  559. key_name, key_name_len,
  560. value, value_len))
  561. error = CS_ERR_ACCESS;
  562. goto error_exit;
  563. }
  564. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  565. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  566. req_lib_confdb_key_create.object_handle = parent_object_handle;
  567. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  568. req_lib_confdb_key_create.key_name.length = key_name_len;
  569. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  570. req_lib_confdb_key_create.value.length = value_len;
  571. iov.iov_base = (char *)&req_lib_confdb_key_create;
  572. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  573. error = coroipcc_msg_send_reply_receive (
  574. confdb_inst->handle,
  575. &iov,
  576. 1,
  577. &res,
  578. sizeof (res));
  579. if (error != CS_OK) {
  580. goto error_exit;
  581. }
  582. error = res.error;
  583. error_exit:
  584. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  585. return (error);
  586. }
  587. cs_error_t confdb_key_create_typed (
  588. confdb_handle_t handle,
  589. hdb_handle_t parent_object_handle,
  590. const char *key_name,
  591. const void *value,
  592. size_t value_len,
  593. confdb_value_types_t type)
  594. {
  595. cs_error_t error;
  596. struct confdb_inst *confdb_inst;
  597. struct iovec iov;
  598. struct req_lib_confdb_key_create_typed request;
  599. coroipc_response_header_t res;
  600. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  601. if (error != CS_OK) {
  602. return (error);
  603. }
  604. if (confdb_inst->standalone) {
  605. error = CS_OK;
  606. if (confdb_sa_key_create_typed(parent_object_handle,
  607. key_name, value, value_len, type))
  608. error = CS_ERR_ACCESS;
  609. goto error_exit;
  610. }
  611. request.header.size = sizeof (struct req_lib_confdb_key_create_typed);
  612. request.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED;
  613. request.object_handle = parent_object_handle;
  614. request.key_name.length = strlen(key_name)+1;
  615. memcpy(request.key_name.value, key_name, request.key_name.length);
  616. memcpy(request.value.value, value, value_len);
  617. request.value.length = value_len;
  618. request.type = type;
  619. iov.iov_base = (char *)&request;
  620. iov.iov_len = sizeof (struct req_lib_confdb_key_create_typed);
  621. error = coroipcc_msg_send_reply_receive (
  622. confdb_inst->handle,
  623. &iov,
  624. 1,
  625. &res,
  626. sizeof (res));
  627. if (error != CS_OK) {
  628. goto error_exit;
  629. }
  630. error = res.error;
  631. error_exit:
  632. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  633. return (error);
  634. }
  635. cs_error_t confdb_key_delete (
  636. confdb_handle_t handle,
  637. hdb_handle_t parent_object_handle,
  638. const void *key_name,
  639. size_t key_name_len,
  640. const void *value,
  641. size_t value_len)
  642. {
  643. cs_error_t error;
  644. struct confdb_inst *confdb_inst;
  645. struct iovec iov;
  646. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  647. coroipc_response_header_t res;
  648. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  649. if (error != CS_OK) {
  650. return (error);
  651. }
  652. if (confdb_inst->standalone) {
  653. error = CS_OK;
  654. if (confdb_sa_key_delete(parent_object_handle,
  655. key_name, key_name_len,
  656. value, value_len))
  657. error = CS_ERR_ACCESS;
  658. goto error_exit;
  659. }
  660. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  661. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  662. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  663. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  664. req_lib_confdb_key_delete.key_name.length = key_name_len;
  665. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  666. req_lib_confdb_key_delete.value.length = value_len;
  667. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  668. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  669. error = coroipcc_msg_send_reply_receive (
  670. confdb_inst->handle,
  671. &iov,
  672. 1,
  673. &res,
  674. sizeof (res));
  675. if (error != CS_OK) {
  676. goto error_exit;
  677. }
  678. error = res.error;
  679. error_exit:
  680. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  681. return (error);
  682. }
  683. cs_error_t confdb_key_get (
  684. confdb_handle_t handle,
  685. hdb_handle_t parent_object_handle,
  686. const void *key_name,
  687. size_t key_name_len,
  688. void *value,
  689. size_t *value_len)
  690. {
  691. cs_error_t error;
  692. struct confdb_inst *confdb_inst;
  693. struct iovec iov;
  694. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  695. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  696. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  697. if (error != CS_OK) {
  698. return (error);
  699. }
  700. if (confdb_inst->standalone) {
  701. error = CS_OK;
  702. if (confdb_sa_key_get(parent_object_handle,
  703. key_name, key_name_len,
  704. value, value_len))
  705. error = CS_ERR_ACCESS;
  706. goto error_exit;
  707. }
  708. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  709. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  710. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  711. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  712. req_lib_confdb_key_get.key_name.length = key_name_len;
  713. iov.iov_base = (char *)&req_lib_confdb_key_get;
  714. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  715. error = coroipcc_msg_send_reply_receive (
  716. confdb_inst->handle,
  717. &iov,
  718. 1,
  719. &res_lib_confdb_key_get,
  720. sizeof (struct res_lib_confdb_key_get));
  721. if (error != CS_OK) {
  722. goto error_exit;
  723. }
  724. error = res_lib_confdb_key_get.header.error;
  725. if (error == CS_OK) {
  726. *value_len = res_lib_confdb_key_get.value.length;
  727. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  728. }
  729. error_exit:
  730. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  731. return (error);
  732. }
  733. cs_error_t confdb_key_get_typed (
  734. confdb_handle_t handle,
  735. hdb_handle_t parent_object_handle,
  736. const char *key_name,
  737. void *value,
  738. size_t *value_len,
  739. confdb_value_types_t *type)
  740. {
  741. cs_error_t error;
  742. struct confdb_inst *confdb_inst;
  743. struct iovec iov;
  744. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  745. struct res_lib_confdb_key_get_typed response;
  746. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  747. if (error != CS_OK) {
  748. return (error);
  749. }
  750. if (confdb_inst->standalone) {
  751. error = CS_OK;
  752. if (confdb_sa_key_get_typed(parent_object_handle,
  753. key_name, value, value_len, (int*)type))
  754. error = CS_ERR_ACCESS;
  755. goto error_exit;
  756. }
  757. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  758. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  759. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  760. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  761. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  762. iov.iov_base = (char *)&req_lib_confdb_key_get;
  763. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  764. error = coroipcc_msg_send_reply_receive (
  765. confdb_inst->handle,
  766. &iov,
  767. 1,
  768. &response,
  769. sizeof (struct res_lib_confdb_key_get_typed));
  770. if (error != CS_OK) {
  771. goto error_exit;
  772. }
  773. error = response.header.error;
  774. if (error == CS_OK) {
  775. *value_len = response.value.length;
  776. *type = response.type;
  777. memcpy(value, response.value.value, *value_len);
  778. }
  779. error_exit:
  780. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  781. return (error);
  782. }
  783. cs_error_t confdb_key_increment (
  784. confdb_handle_t handle,
  785. hdb_handle_t parent_object_handle,
  786. const void *key_name,
  787. size_t key_name_len,
  788. unsigned int *value)
  789. {
  790. cs_error_t error;
  791. struct confdb_inst *confdb_inst;
  792. struct iovec iov;
  793. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  794. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  795. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  796. if (error != CS_OK) {
  797. return (error);
  798. }
  799. if (confdb_inst->standalone) {
  800. error = CS_OK;
  801. if (confdb_sa_key_increment(parent_object_handle,
  802. key_name, key_name_len,
  803. value))
  804. error = CS_ERR_ACCESS;
  805. goto error_exit;
  806. }
  807. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  808. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  809. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  810. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  811. req_lib_confdb_key_get.key_name.length = key_name_len;
  812. iov.iov_base = (char *)&req_lib_confdb_key_get;
  813. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  814. error = coroipcc_msg_send_reply_receive (
  815. confdb_inst->handle,
  816. &iov,
  817. 1,
  818. &res_lib_confdb_key_incdec,
  819. sizeof (struct res_lib_confdb_key_incdec));
  820. if (error != CS_OK) {
  821. goto error_exit;
  822. }
  823. error = res_lib_confdb_key_incdec.header.error;
  824. if (error == CS_OK) {
  825. *value = res_lib_confdb_key_incdec.value;
  826. }
  827. error_exit:
  828. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  829. return (error);
  830. }
  831. cs_error_t confdb_key_decrement (
  832. confdb_handle_t handle,
  833. hdb_handle_t parent_object_handle,
  834. const void *key_name,
  835. size_t key_name_len,
  836. unsigned int *value)
  837. {
  838. cs_error_t error;
  839. struct confdb_inst *confdb_inst;
  840. struct iovec iov;
  841. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  842. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  843. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  844. if (error != CS_OK) {
  845. return (error);
  846. }
  847. if (confdb_inst->standalone) {
  848. error = CS_OK;
  849. if (confdb_sa_key_decrement(parent_object_handle,
  850. key_name, key_name_len,
  851. value))
  852. error = CS_ERR_ACCESS;
  853. goto error_exit;
  854. }
  855. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  856. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  857. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  858. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  859. req_lib_confdb_key_get.key_name.length = key_name_len;
  860. iov.iov_base = (char *)&req_lib_confdb_key_get;
  861. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  862. error = coroipcc_msg_send_reply_receive (
  863. confdb_inst->handle,
  864. &iov,
  865. 1,
  866. &res_lib_confdb_key_incdec,
  867. sizeof (struct res_lib_confdb_key_incdec));
  868. if (error != CS_OK) {
  869. goto error_exit;
  870. }
  871. error = res_lib_confdb_key_incdec.header.error;
  872. if (error == CS_OK) {
  873. *value = res_lib_confdb_key_incdec.value;
  874. }
  875. error_exit:
  876. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  877. return (error);
  878. }
  879. cs_error_t confdb_key_replace (
  880. confdb_handle_t handle,
  881. hdb_handle_t parent_object_handle,
  882. const void *key_name,
  883. size_t key_name_len,
  884. const void *old_value,
  885. size_t old_value_len,
  886. const void *new_value,
  887. size_t new_value_len)
  888. {
  889. cs_error_t error;
  890. struct confdb_inst *confdb_inst;
  891. struct iovec iov;
  892. struct req_lib_confdb_key_replace req_lib_confdb_key_replace;
  893. coroipc_response_header_t res;
  894. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  895. if (error != CS_OK) {
  896. return (error);
  897. }
  898. if (confdb_inst->standalone) {
  899. error = CS_OK;
  900. if (confdb_sa_key_replace(parent_object_handle,
  901. key_name, key_name_len,
  902. old_value, old_value_len,
  903. new_value, new_value_len))
  904. error = CS_ERR_ACCESS;
  905. goto error_exit;
  906. }
  907. req_lib_confdb_key_replace.header.size = sizeof (struct req_lib_confdb_key_replace);
  908. req_lib_confdb_key_replace.header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE;
  909. req_lib_confdb_key_replace.object_handle = parent_object_handle;
  910. memcpy(req_lib_confdb_key_replace.key_name.value, key_name, key_name_len);
  911. req_lib_confdb_key_replace.key_name.length = key_name_len;
  912. memcpy(req_lib_confdb_key_replace.old_value.value, old_value, old_value_len);
  913. req_lib_confdb_key_replace.old_value.length = old_value_len;
  914. memcpy(req_lib_confdb_key_replace.new_value.value, new_value, new_value_len);
  915. req_lib_confdb_key_replace.new_value.length = new_value_len;
  916. iov.iov_base = (char *)&req_lib_confdb_key_replace;
  917. iov.iov_len = sizeof (struct req_lib_confdb_key_replace);
  918. error = coroipcc_msg_send_reply_receive (
  919. confdb_inst->handle,
  920. &iov,
  921. 1,
  922. &res,
  923. sizeof (res));
  924. if (error != CS_OK) {
  925. goto error_exit;
  926. }
  927. error = res.error;
  928. error_exit:
  929. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  930. return (error);
  931. }
  932. cs_error_t confdb_object_iter_start (
  933. confdb_handle_t handle,
  934. hdb_handle_t object_handle)
  935. {
  936. struct confdb_inst *confdb_inst;
  937. cs_error_t error = CS_OK;
  938. struct iter_context *context;
  939. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  940. if (error != CS_OK) {
  941. return (error);
  942. }
  943. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  944. if (!context) {
  945. context = malloc(sizeof(struct iter_context));
  946. if (!context) {
  947. error = CS_ERR_NO_MEMORY;
  948. goto ret;
  949. }
  950. context->parent_object_handle = object_handle;
  951. context->find_handle = 0;
  952. list_add(&context->list, &confdb_inst->object_iter_head);
  953. }
  954. /* Start a new find context */
  955. if (context->find_handle) {
  956. (void)do_find_destroy(confdb_inst, context->find_handle);
  957. context->find_handle = 0;
  958. }
  959. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  960. ret:
  961. return error;
  962. }
  963. cs_error_t confdb_key_iter_start (
  964. confdb_handle_t handle,
  965. hdb_handle_t object_handle)
  966. {
  967. struct confdb_inst *confdb_inst;
  968. cs_error_t error = CS_OK;
  969. struct iter_context *context;
  970. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  971. if (error != CS_OK) {
  972. return (error);
  973. }
  974. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  975. if (!context) {
  976. context = malloc(sizeof(struct iter_context));
  977. if (!context) {
  978. error = CS_ERR_NO_MEMORY;
  979. goto ret;
  980. }
  981. context->parent_object_handle = object_handle;
  982. list_add(&context->list, &confdb_inst->key_iter_head);
  983. }
  984. context->find_handle = 0;
  985. context->next_entry = 0;
  986. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  987. ret:
  988. return error;
  989. }
  990. cs_error_t confdb_object_find_start (
  991. confdb_handle_t handle,
  992. hdb_handle_t parent_object_handle)
  993. {
  994. struct confdb_inst *confdb_inst;
  995. cs_error_t error = CS_OK;
  996. struct iter_context *context;
  997. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  998. if (error != CS_OK) {
  999. return (error);
  1000. }
  1001. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1002. if (!context) {
  1003. context = malloc(sizeof(struct iter_context));
  1004. if (!context) {
  1005. error = CS_ERR_NO_MEMORY;
  1006. goto ret;
  1007. }
  1008. context->find_handle = 0;
  1009. context->parent_object_handle = parent_object_handle;
  1010. list_add(&context->list, &confdb_inst->object_find_head);
  1011. }
  1012. /* Start a new find context */
  1013. if (context->find_handle) {
  1014. (void)do_find_destroy(confdb_inst, context->find_handle);
  1015. context->find_handle = 0;
  1016. }
  1017. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1018. ret:
  1019. return error;
  1020. }
  1021. cs_error_t confdb_object_find (
  1022. confdb_handle_t handle,
  1023. hdb_handle_t parent_object_handle,
  1024. const void *object_name,
  1025. size_t object_name_len,
  1026. hdb_handle_t *object_handle)
  1027. {
  1028. cs_error_t error;
  1029. struct confdb_inst *confdb_inst;
  1030. struct iovec iov;
  1031. struct iter_context *context;
  1032. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1033. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1034. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1035. if (error != CS_OK) {
  1036. return (error);
  1037. }
  1038. /* You MUST call confdb_object_find_start first */
  1039. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1040. if (!context) {
  1041. error = CS_ERR_CONTEXT_NOT_FOUND;
  1042. goto error_exit;
  1043. }
  1044. if (confdb_inst->standalone) {
  1045. error = CS_OK;
  1046. if (confdb_sa_object_find(parent_object_handle,
  1047. &context->find_handle,
  1048. object_handle,
  1049. object_name, object_name_len))
  1050. error = CS_ERR_ACCESS;
  1051. goto error_exit;
  1052. }
  1053. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1054. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1055. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1056. req_lib_confdb_object_find.find_handle = context->find_handle;
  1057. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1058. req_lib_confdb_object_find.object_name.length = object_name_len;
  1059. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1060. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1061. error = coroipcc_msg_send_reply_receive (
  1062. confdb_inst->handle,
  1063. &iov,
  1064. 1,
  1065. &res_lib_confdb_object_find,
  1066. sizeof (struct res_lib_confdb_object_find));
  1067. if (error != CS_OK) {
  1068. goto error_exit;
  1069. }
  1070. error = res_lib_confdb_object_find.header.error;
  1071. *object_handle = res_lib_confdb_object_find.object_handle;
  1072. context->find_handle = res_lib_confdb_object_find.find_handle;
  1073. error_exit:
  1074. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1075. return (error);
  1076. }
  1077. cs_error_t confdb_object_iter (
  1078. confdb_handle_t handle,
  1079. hdb_handle_t parent_object_handle,
  1080. hdb_handle_t *object_handle,
  1081. void *object_name,
  1082. size_t *object_name_len)
  1083. {
  1084. cs_error_t error;
  1085. struct confdb_inst *confdb_inst;
  1086. struct iovec iov;
  1087. struct iter_context *context;
  1088. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1089. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1090. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1091. if (error != CS_OK) {
  1092. return (error);
  1093. }
  1094. /* You MUST call confdb_object_iter_start first */
  1095. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1096. if (!context) {
  1097. error = CS_ERR_CONTEXT_NOT_FOUND;
  1098. goto error_exit;
  1099. }
  1100. if (confdb_inst->standalone) {
  1101. error = CS_OK;
  1102. *object_name_len = 0;
  1103. if (confdb_sa_object_iter(parent_object_handle,
  1104. &context->find_handle,
  1105. object_handle,
  1106. NULL, 0,
  1107. object_name, object_name_len))
  1108. error = CS_ERR_ACCESS;
  1109. goto sa_exit;
  1110. }
  1111. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1112. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1113. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1114. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1115. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1116. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1117. error = coroipcc_msg_send_reply_receive (
  1118. confdb_inst->handle,
  1119. &iov,
  1120. 1,
  1121. &res_lib_confdb_object_iter,
  1122. sizeof (struct res_lib_confdb_object_iter));
  1123. if (error != CS_OK) {
  1124. goto error_exit;
  1125. }
  1126. error = res_lib_confdb_object_iter.header.error;
  1127. if (error == CS_OK) {
  1128. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1129. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1130. *object_handle = res_lib_confdb_object_iter.object_handle;
  1131. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1132. }
  1133. sa_exit:
  1134. error_exit:
  1135. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1136. return (error);
  1137. }
  1138. cs_error_t confdb_key_iter (
  1139. confdb_handle_t handle,
  1140. hdb_handle_t parent_object_handle,
  1141. void *key_name,
  1142. size_t *key_name_len,
  1143. void *value,
  1144. size_t *value_len)
  1145. {
  1146. cs_error_t error;
  1147. struct confdb_inst *confdb_inst;
  1148. struct iovec iov;
  1149. struct iter_context *context;
  1150. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1151. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1152. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1153. if (error != CS_OK) {
  1154. return (error);
  1155. }
  1156. /* You MUST call confdb_key_iter_start first */
  1157. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1158. if (!context) {
  1159. error = CS_ERR_CONTEXT_NOT_FOUND;
  1160. goto error_exit;
  1161. }
  1162. if (confdb_inst->standalone) {
  1163. error = CS_OK;
  1164. if (confdb_sa_key_iter(parent_object_handle,
  1165. context->next_entry,
  1166. key_name, key_name_len,
  1167. value, value_len))
  1168. error = CS_ERR_ACCESS;
  1169. goto sa_exit;
  1170. }
  1171. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1172. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1173. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1174. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1175. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1176. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1177. error = coroipcc_msg_send_reply_receive (
  1178. confdb_inst->handle,
  1179. &iov,
  1180. 1,
  1181. &res_lib_confdb_key_iter,
  1182. sizeof (struct res_lib_confdb_key_iter));
  1183. if (error != CS_OK) {
  1184. goto error_exit;
  1185. }
  1186. error = res_lib_confdb_key_iter.header.error;
  1187. if (error == CS_OK) {
  1188. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1189. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1190. *value_len = res_lib_confdb_key_iter.value.length;
  1191. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1192. }
  1193. sa_exit:
  1194. context->next_entry++;
  1195. error_exit:
  1196. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1197. return (error);
  1198. }
  1199. cs_error_t confdb_key_iter_typed (
  1200. confdb_handle_t handle,
  1201. hdb_handle_t parent_object_handle,
  1202. char *key_name,
  1203. void *value,
  1204. size_t *value_len,
  1205. confdb_value_types_t *type)
  1206. {
  1207. cs_error_t error;
  1208. struct confdb_inst *confdb_inst;
  1209. struct iovec iov;
  1210. struct iter_context *context;
  1211. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1212. struct res_lib_confdb_key_iter_typed response;
  1213. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1214. if (error != CS_OK) {
  1215. return (error);
  1216. }
  1217. /* You MUST call confdb_key_iter_start first */
  1218. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1219. if (!context) {
  1220. error = CS_ERR_CONTEXT_NOT_FOUND;
  1221. goto error_exit;
  1222. }
  1223. if (confdb_inst->standalone) {
  1224. error = CS_OK;
  1225. if (confdb_sa_key_iter_typed(parent_object_handle,
  1226. context->next_entry,
  1227. key_name,
  1228. value, value_len, (int*)type))
  1229. error = CS_ERR_ACCESS;
  1230. goto sa_exit;
  1231. }
  1232. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1233. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1234. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1235. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1236. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1237. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1238. error = coroipcc_msg_send_reply_receive (
  1239. confdb_inst->handle,
  1240. &iov,
  1241. 1,
  1242. &response,
  1243. sizeof (struct res_lib_confdb_key_iter_typed));
  1244. if (error != CS_OK) {
  1245. goto error_exit;
  1246. }
  1247. error = response.header.error;
  1248. if (error == CS_OK) {
  1249. memcpy(key_name, response.key_name.value, response.key_name.length);
  1250. key_name[response.key_name.length] = '\0';
  1251. *value_len = response.value.length;
  1252. memcpy(value, response.value.value, *value_len);
  1253. *type = response.type;
  1254. }
  1255. sa_exit:
  1256. context->next_entry++;
  1257. error_exit:
  1258. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1259. return (error);
  1260. }
  1261. cs_error_t confdb_write (
  1262. confdb_handle_t handle,
  1263. char *error_text,
  1264. size_t errbuf_len)
  1265. {
  1266. cs_error_t error;
  1267. struct confdb_inst *confdb_inst;
  1268. struct iovec iov;
  1269. coroipc_request_header_t req;
  1270. struct res_lib_confdb_write res_lib_confdb_write;
  1271. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1272. if (error != CS_OK) {
  1273. /* FIXME: set error_text */
  1274. return (error);
  1275. }
  1276. if (confdb_inst->standalone) {
  1277. error = CS_OK;
  1278. if (confdb_sa_write(error_text, errbuf_len))
  1279. error = CS_ERR_ACCESS;
  1280. goto error_exit;
  1281. }
  1282. req.size = sizeof (coroipc_request_header_t);
  1283. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1284. iov.iov_base = (char *)&req;
  1285. iov.iov_len = sizeof (coroipc_request_header_t);
  1286. error = coroipcc_msg_send_reply_receive (
  1287. confdb_inst->handle,
  1288. &iov,
  1289. 1,
  1290. &res_lib_confdb_write,
  1291. sizeof (struct res_lib_confdb_write));
  1292. if (error != CS_OK) {
  1293. /* FIXME: set error_text */
  1294. goto error_exit;
  1295. }
  1296. error = res_lib_confdb_write.header.error;
  1297. if (res_lib_confdb_write.error.length) {
  1298. memcpy(error_text, res_lib_confdb_write.error.value,
  1299. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1300. error_text[errbuf_len-1] = '\0';
  1301. }
  1302. error_exit:
  1303. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1304. return (error);
  1305. }
  1306. cs_error_t confdb_reload (
  1307. confdb_handle_t handle,
  1308. int flush,
  1309. char *error_text,
  1310. size_t errbuf_len)
  1311. {
  1312. cs_error_t error;
  1313. struct confdb_inst *confdb_inst;
  1314. struct iovec iov;
  1315. struct res_lib_confdb_reload res_lib_confdb_reload;
  1316. struct req_lib_confdb_reload req_lib_confdb_reload;
  1317. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1318. if (error != CS_OK) {
  1319. /* FIXME: set error_text */
  1320. return (error);
  1321. }
  1322. if (confdb_inst->standalone) {
  1323. error = CS_OK;
  1324. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1325. error = CS_ERR_ACCESS;
  1326. goto error_exit;
  1327. }
  1328. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1329. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1330. req_lib_confdb_reload.flush = flush;
  1331. iov.iov_base = (char *)&req_lib_confdb_reload;
  1332. iov.iov_len = sizeof (req_lib_confdb_reload);
  1333. error = coroipcc_msg_send_reply_receive (
  1334. confdb_inst->handle,
  1335. &iov,
  1336. 1,
  1337. &res_lib_confdb_reload,
  1338. sizeof (struct res_lib_confdb_reload));
  1339. if (error != CS_OK) {
  1340. /* FIXME: set error_text */
  1341. goto error_exit;
  1342. }
  1343. error = res_lib_confdb_reload.header.error;
  1344. if(res_lib_confdb_reload.error.length) {
  1345. memcpy(error_text, res_lib_confdb_reload.error.value,
  1346. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1347. error_text[errbuf_len-1] = '\0';
  1348. }
  1349. error_exit:
  1350. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1351. return (error);
  1352. }
  1353. cs_error_t confdb_track_changes (
  1354. confdb_handle_t handle,
  1355. hdb_handle_t object_handle,
  1356. unsigned int flags)
  1357. {
  1358. cs_error_t error;
  1359. struct confdb_inst *confdb_inst;
  1360. struct iovec iov;
  1361. struct req_lib_confdb_object_track_start req;
  1362. coroipc_response_header_t res;
  1363. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1364. if (error != CS_OK) {
  1365. return (error);
  1366. }
  1367. if (confdb_inst->standalone) {
  1368. error = CS_ERR_NOT_SUPPORTED;
  1369. goto error_exit;
  1370. }
  1371. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1372. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1373. req.object_handle = object_handle;
  1374. req.flags = flags;
  1375. iov.iov_base = (char *)&req;
  1376. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1377. error = coroipcc_msg_send_reply_receive (
  1378. confdb_inst->handle,
  1379. &iov,
  1380. 1,
  1381. &res,
  1382. sizeof (coroipc_response_header_t));
  1383. if (error != CS_OK) {
  1384. goto error_exit;
  1385. }
  1386. error = res.error;
  1387. error_exit:
  1388. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1389. return (error);
  1390. }
  1391. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1392. {
  1393. cs_error_t error;
  1394. struct confdb_inst *confdb_inst;
  1395. struct iovec iov;
  1396. coroipc_request_header_t req;
  1397. coroipc_response_header_t res;
  1398. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1399. if (error != CS_OK) {
  1400. return (error);
  1401. }
  1402. if (confdb_inst->standalone) {
  1403. error = CS_ERR_NOT_SUPPORTED;
  1404. goto error_exit;
  1405. }
  1406. req.size = sizeof (coroipc_request_header_t);
  1407. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1408. iov.iov_base = (char *)&req;
  1409. iov.iov_len = sizeof (coroipc_request_header_t);
  1410. error = coroipcc_msg_send_reply_receive (
  1411. confdb_inst->handle,
  1412. &iov,
  1413. 1,
  1414. &res,
  1415. sizeof (coroipc_response_header_t));
  1416. if (error != CS_OK) {
  1417. goto error_exit;
  1418. }
  1419. error = res.error;
  1420. error_exit:
  1421. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1422. return (error);
  1423. }