confdb.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000
  1. /*
  2. * Copyright (c) 2008-2012 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. struct res_lib_confdb_reload_callback *res_reload_pt;
  234. coroipc_response_header_t *dispatch_data;
  235. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  236. if (error != CS_OK) {
  237. return (error);
  238. }
  239. if (confdb_inst->standalone) {
  240. error = CS_ERR_NOT_SUPPORTED;
  241. goto error_put;
  242. }
  243. /*
  244. * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
  245. * wait indefinitely for CS_DISPATCH_BLOCKING
  246. */
  247. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  248. timeout = 0;
  249. }
  250. do {
  251. error = coroipcc_dispatch_get (
  252. confdb_inst->handle,
  253. (void **)&dispatch_data,
  254. timeout);
  255. if (error == CS_ERR_BAD_HANDLE) {
  256. error = CS_OK;
  257. goto error_put;
  258. }
  259. if (error == CS_ERR_TRY_AGAIN) {
  260. error = CS_OK;
  261. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  262. break; /* exit do while cont is 1 loop */
  263. } else {
  264. continue; /* next poll */
  265. }
  266. }
  267. if (error != CS_OK) {
  268. goto error_put;
  269. }
  270. /*
  271. * Make copy of callbacks, message data, unlock instance, and call callback
  272. * A risk of this dispatch method is that the callback routines may
  273. * operate at the same time that confdbFinalize has been called.
  274. */
  275. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  276. /*
  277. * Dispatch incoming message
  278. */
  279. switch (dispatch_data->id) {
  280. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  281. if (callbacks.confdb_key_change_notify_fn == NULL) {
  282. break;
  283. }
  284. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  285. callbacks.confdb_key_change_notify_fn(handle,
  286. res_key_changed_pt->change_type,
  287. res_key_changed_pt->object_handle,
  288. res_key_changed_pt->parent_object_handle,
  289. res_key_changed_pt->object_name.value,
  290. res_key_changed_pt->object_name.length,
  291. res_key_changed_pt->key_name.value,
  292. res_key_changed_pt->key_name.length,
  293. res_key_changed_pt->key_value.value,
  294. res_key_changed_pt->key_value.length);
  295. break;
  296. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK2:
  297. if (callbacks.confdb_key_change_notify_fn == NULL) {
  298. break;
  299. }
  300. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  301. callbacks.confdb_key_change_notify_fn(handle,
  302. res_key_changed_pt->change_type,
  303. res_key_changed_pt->object_handle,
  304. res_key_changed_pt->parent_object_handle,
  305. res_key_changed_pt->object_name.value,
  306. res_key_changed_pt->object_name.length,
  307. res_key_changed_pt->key_name.value,
  308. res_key_changed_pt->key_name.length,
  309. &res_key_changed_pt->key_value.value,
  310. res_key_changed_pt->key_value.length);
  311. break;
  312. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  313. if (callbacks.confdb_object_create_change_notify_fn == NULL) {
  314. break;
  315. }
  316. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  317. callbacks.confdb_object_create_change_notify_fn(handle,
  318. res_object_created_pt->object_handle,
  319. res_object_created_pt->parent_object_handle,
  320. res_object_created_pt->name.value,
  321. res_object_created_pt->name.length);
  322. break;
  323. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  324. if (callbacks.confdb_object_delete_change_notify_fn == NULL) {
  325. break;
  326. }
  327. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  328. callbacks.confdb_object_delete_change_notify_fn(handle,
  329. res_object_destroyed_pt->parent_object_handle,
  330. res_object_destroyed_pt->name.value,
  331. res_object_destroyed_pt->name.length);
  332. break;
  333. case MESSAGE_RES_CONFDB_RELOAD_CALLBACK:
  334. if (callbacks.confdb_reload_notify_fn == NULL) {
  335. continue;
  336. }
  337. res_reload_pt = (struct res_lib_confdb_reload_callback *)dispatch_data;
  338. callbacks.confdb_reload_notify_fn(handle,
  339. res_reload_pt->type);
  340. break;
  341. default:
  342. coroipcc_dispatch_put (confdb_inst->handle);
  343. error = CS_ERR_LIBRARY;
  344. goto error_put;
  345. break;
  346. }
  347. coroipcc_dispatch_put (confdb_inst->handle);
  348. /*
  349. * Determine if more messages should be processed
  350. */
  351. if (dispatch_types == CS_DISPATCH_ONE) {
  352. cont = 0;
  353. }
  354. } while (cont);
  355. error_put:
  356. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  357. return (error);
  358. }
  359. cs_error_t confdb_object_create (
  360. confdb_handle_t handle,
  361. hdb_handle_t parent_object_handle,
  362. const void *object_name,
  363. size_t object_name_len,
  364. hdb_handle_t *object_handle)
  365. {
  366. cs_error_t error;
  367. struct confdb_inst *confdb_inst;
  368. struct iovec iov;
  369. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  370. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  371. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  372. if (error != CS_OK) {
  373. return (error);
  374. }
  375. if (confdb_inst->standalone) {
  376. error = CS_OK;
  377. if (confdb_sa_object_create(parent_object_handle,
  378. object_name, object_name_len,
  379. object_handle))
  380. error = CS_ERR_ACCESS;
  381. goto error_exit;
  382. }
  383. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  384. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  385. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  386. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  387. req_lib_confdb_object_create.object_name.length = object_name_len;
  388. iov.iov_base = (char *)&req_lib_confdb_object_create;
  389. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  390. error = coroipcc_msg_send_reply_receive (
  391. confdb_inst->handle,
  392. &iov,
  393. 1,
  394. &res_lib_confdb_object_create,
  395. sizeof (struct res_lib_confdb_object_create));
  396. if (error != CS_OK) {
  397. goto error_exit;
  398. }
  399. error = res_lib_confdb_object_create.header.error;
  400. *object_handle = res_lib_confdb_object_create.object_handle;
  401. error_exit:
  402. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  403. return (error);
  404. }
  405. cs_error_t confdb_object_destroy (
  406. confdb_handle_t handle,
  407. hdb_handle_t object_handle)
  408. {
  409. cs_error_t error;
  410. struct confdb_inst *confdb_inst;
  411. struct iovec iov;
  412. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  413. coroipc_response_header_t res;
  414. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  415. if (error != CS_OK) {
  416. return (error);
  417. }
  418. if (confdb_inst->standalone) {
  419. error = CS_OK;
  420. if (confdb_sa_object_destroy(object_handle))
  421. error = CS_ERR_ACCESS;
  422. goto error_exit;
  423. }
  424. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  425. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  426. req_lib_confdb_object_destroy.object_handle = object_handle;
  427. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  428. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  429. error = coroipcc_msg_send_reply_receive (
  430. confdb_inst->handle,
  431. &iov,
  432. 1,
  433. &res,
  434. sizeof (coroipc_response_header_t));
  435. if (error != CS_OK) {
  436. goto error_exit;
  437. }
  438. error = res.error;
  439. error_exit:
  440. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  441. return (error);
  442. }
  443. cs_error_t confdb_object_parent_get (
  444. confdb_handle_t handle,
  445. hdb_handle_t object_handle,
  446. hdb_handle_t *parent_object_handle)
  447. {
  448. cs_error_t error;
  449. struct confdb_inst *confdb_inst;
  450. struct iovec iov;
  451. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  452. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  453. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  454. if (error != CS_OK) {
  455. return (error);
  456. }
  457. if (confdb_inst->standalone) {
  458. error = CS_OK;
  459. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  460. error = CS_ERR_ACCESS;
  461. goto error_exit;
  462. }
  463. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  464. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  465. req_lib_confdb_object_parent_get.object_handle = object_handle;
  466. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  467. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  468. error = coroipcc_msg_send_reply_receive (
  469. confdb_inst->handle,
  470. &iov,
  471. 1,
  472. &res_lib_confdb_object_parent_get,
  473. sizeof (struct res_lib_confdb_object_parent_get));
  474. if (error != CS_OK) {
  475. goto error_exit;
  476. }
  477. error = res_lib_confdb_object_parent_get.header.error;
  478. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  479. error_exit:
  480. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  481. return (error);
  482. }
  483. cs_error_t confdb_object_name_get (
  484. confdb_handle_t handle,
  485. hdb_handle_t object_handle,
  486. char *object_name,
  487. size_t *object_name_len)
  488. {
  489. cs_error_t error;
  490. struct confdb_inst *confdb_inst;
  491. struct iovec iov;
  492. struct req_lib_confdb_object_name_get request;
  493. struct res_lib_confdb_object_name_get response;
  494. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  495. if (error != CS_OK) {
  496. return (error);
  497. }
  498. if (confdb_inst->standalone) {
  499. error = CS_OK;
  500. if (confdb_sa_object_name_get(object_handle, object_name, object_name_len))
  501. error = CS_ERR_ACCESS;
  502. goto error_exit;
  503. }
  504. request.header.size = sizeof (struct req_lib_confdb_object_name_get);
  505. request.header.id = MESSAGE_REQ_CONFDB_OBJECT_NAME_GET;
  506. request.object_handle = object_handle;
  507. iov.iov_base = (char *)&request;
  508. iov.iov_len = sizeof (struct req_lib_confdb_object_name_get);
  509. error = coroipcc_msg_send_reply_receive (
  510. confdb_inst->handle,
  511. &iov,
  512. 1,
  513. &response,
  514. sizeof (struct res_lib_confdb_object_name_get));
  515. if (error != CS_OK) {
  516. goto error_exit;
  517. }
  518. error = response.header.error;
  519. if (error == CS_OK) {
  520. *object_name_len = response.object_name.length;
  521. memcpy(object_name, response.object_name.value, *object_name_len);
  522. }
  523. error_exit:
  524. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  525. return (error);
  526. }
  527. static cs_error_t do_find_destroy(
  528. struct confdb_inst *confdb_inst,
  529. hdb_handle_t find_handle)
  530. {
  531. cs_error_t error;
  532. struct iovec iov;
  533. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  534. coroipc_response_header_t res;
  535. if (!find_handle)
  536. return CS_OK;
  537. if (confdb_inst->standalone) {
  538. error = CS_OK;
  539. if (confdb_sa_find_destroy(find_handle))
  540. error = CS_ERR_ACCESS;
  541. goto error_exit;
  542. }
  543. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  544. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  545. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  546. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  547. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  548. error = coroipcc_msg_send_reply_receive (
  549. confdb_inst->handle,
  550. &iov,
  551. 1,
  552. &res,
  553. sizeof (coroipc_response_header_t));
  554. if (error != CS_OK) {
  555. goto error_exit;
  556. }
  557. error = res.error;
  558. error_exit:
  559. return (error);
  560. }
  561. cs_error_t confdb_object_find_destroy(
  562. confdb_handle_t handle,
  563. hdb_handle_t parent_object_handle)
  564. {
  565. struct iter_context *context;
  566. cs_error_t error;
  567. struct confdb_inst *confdb_inst;
  568. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  569. if (error != CS_OK) {
  570. return (error);
  571. }
  572. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  573. error = do_find_destroy(confdb_inst, context->find_handle);
  574. if (error == CS_OK) {
  575. list_del(&context->list);
  576. free(context);
  577. }
  578. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  579. return error;
  580. }
  581. cs_error_t confdb_object_iter_destroy(
  582. confdb_handle_t handle,
  583. hdb_handle_t parent_object_handle)
  584. {
  585. struct iter_context *context;
  586. cs_error_t error;
  587. struct confdb_inst *confdb_inst;
  588. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  589. if (error != CS_OK) {
  590. return (error);
  591. }
  592. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  593. error = do_find_destroy(confdb_inst, context->find_handle);
  594. if (error == CS_OK) {
  595. list_del(&context->list);
  596. free(context);
  597. }
  598. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  599. return error;
  600. }
  601. cs_error_t confdb_key_create (
  602. confdb_handle_t handle,
  603. hdb_handle_t parent_object_handle,
  604. const void *key_name,
  605. size_t key_name_len,
  606. const void *value,
  607. size_t value_len)
  608. {
  609. cs_error_t error;
  610. struct confdb_inst *confdb_inst;
  611. struct iovec iov;
  612. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  613. coroipc_response_header_t res;
  614. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  615. if (error != CS_OK) {
  616. return (error);
  617. }
  618. if (confdb_inst->standalone) {
  619. error = CS_OK;
  620. if (confdb_sa_key_create(parent_object_handle,
  621. key_name, key_name_len,
  622. value, value_len))
  623. error = CS_ERR_ACCESS;
  624. goto error_exit;
  625. }
  626. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  627. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  628. req_lib_confdb_key_create.object_handle = parent_object_handle;
  629. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  630. req_lib_confdb_key_create.key_name.length = key_name_len;
  631. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  632. req_lib_confdb_key_create.value.length = value_len;
  633. iov.iov_base = (char *)&req_lib_confdb_key_create;
  634. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  635. error = coroipcc_msg_send_reply_receive (
  636. confdb_inst->handle,
  637. &iov,
  638. 1,
  639. &res,
  640. sizeof (res));
  641. if (error != CS_OK) {
  642. goto error_exit;
  643. }
  644. error = res.error;
  645. error_exit:
  646. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  647. return (error);
  648. }
  649. cs_error_t confdb_key_create_typed (
  650. confdb_handle_t handle,
  651. hdb_handle_t parent_object_handle,
  652. const char *key_name,
  653. const void *value,
  654. size_t value_len,
  655. confdb_value_types_t type)
  656. {
  657. cs_error_t error;
  658. struct confdb_inst *confdb_inst;
  659. struct iovec iov;
  660. struct req_lib_confdb_key_create_typed2 *request;
  661. coroipc_response_header_t res;
  662. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  663. if (error != CS_OK) {
  664. return (error);
  665. }
  666. if (confdb_inst->standalone) {
  667. error = CS_OK;
  668. if (confdb_sa_key_create_typed(parent_object_handle,
  669. key_name, value, value_len, type))
  670. error = CS_ERR_ACCESS;
  671. goto error_exit;
  672. }
  673. request = malloc(sizeof(struct req_lib_confdb_key_create_typed2)+value_len);
  674. if (!request) {
  675. error = CS_ERR_NO_MEMORY;
  676. goto error_exit;
  677. }
  678. request->header.size = sizeof (struct req_lib_confdb_key_create_typed2) + value_len;
  679. request->header.id = MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED2;
  680. request->object_handle = parent_object_handle;
  681. request->key_name.length = strlen(key_name)+1;
  682. memcpy(request->key_name.value, key_name, request->key_name.length);
  683. memcpy(&request->value, value, value_len);
  684. request->value_length = value_len;
  685. request->type = type;
  686. iov.iov_base = (char *)request;
  687. iov.iov_len = request->header.size;
  688. error = coroipcc_msg_send_reply_receive (
  689. confdb_inst->handle,
  690. &iov,
  691. 1,
  692. &res,
  693. sizeof (res));
  694. if (error != CS_OK) {
  695. goto free_exit;
  696. }
  697. error = res.error;
  698. free_exit:
  699. free(request);
  700. error_exit:
  701. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  702. return (error);
  703. }
  704. cs_error_t confdb_key_delete (
  705. confdb_handle_t handle,
  706. hdb_handle_t parent_object_handle,
  707. const void *key_name,
  708. size_t key_name_len,
  709. const void *value,
  710. size_t value_len)
  711. {
  712. cs_error_t error;
  713. struct confdb_inst *confdb_inst;
  714. struct iovec iov;
  715. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  716. coroipc_response_header_t res;
  717. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  718. if (error != CS_OK) {
  719. return (error);
  720. }
  721. if (confdb_inst->standalone) {
  722. error = CS_OK;
  723. if (confdb_sa_key_delete(parent_object_handle,
  724. key_name, key_name_len,
  725. value, value_len))
  726. error = CS_ERR_ACCESS;
  727. goto error_exit;
  728. }
  729. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  730. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  731. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  732. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  733. req_lib_confdb_key_delete.key_name.length = key_name_len;
  734. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  735. req_lib_confdb_key_delete.value.length = value_len;
  736. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  737. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  738. error = coroipcc_msg_send_reply_receive (
  739. confdb_inst->handle,
  740. &iov,
  741. 1,
  742. &res,
  743. sizeof (res));
  744. if (error != CS_OK) {
  745. goto error_exit;
  746. }
  747. error = res.error;
  748. error_exit:
  749. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  750. return (error);
  751. }
  752. cs_error_t confdb_key_get (
  753. confdb_handle_t handle,
  754. hdb_handle_t parent_object_handle,
  755. const void *key_name,
  756. size_t key_name_len,
  757. void *value,
  758. size_t *value_len)
  759. {
  760. cs_error_t error;
  761. struct confdb_inst *confdb_inst;
  762. struct iovec iov;
  763. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  764. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  765. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  766. if (error != CS_OK) {
  767. return (error);
  768. }
  769. if (confdb_inst->standalone) {
  770. error = CS_OK;
  771. if (confdb_sa_key_get(parent_object_handle,
  772. key_name, key_name_len,
  773. value, value_len))
  774. error = CS_ERR_ACCESS;
  775. goto error_exit;
  776. }
  777. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  778. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  779. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  780. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  781. req_lib_confdb_key_get.key_name.length = key_name_len;
  782. iov.iov_base = (char *)&req_lib_confdb_key_get;
  783. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  784. error = coroipcc_msg_send_reply_receive (
  785. confdb_inst->handle,
  786. &iov,
  787. 1,
  788. &res_lib_confdb_key_get,
  789. sizeof (struct res_lib_confdb_key_get));
  790. if (error != CS_OK) {
  791. goto error_exit;
  792. }
  793. error = res_lib_confdb_key_get.header.error;
  794. if (error == CS_OK) {
  795. *value_len = res_lib_confdb_key_get.value.length;
  796. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  797. }
  798. error_exit:
  799. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  800. return (error);
  801. }
  802. cs_error_t confdb_key_get_typed (
  803. confdb_handle_t handle,
  804. hdb_handle_t parent_object_handle,
  805. const char *key_name,
  806. void *value,
  807. size_t *value_len,
  808. confdb_value_types_t *type)
  809. {
  810. cs_error_t error;
  811. struct confdb_inst *confdb_inst;
  812. struct iovec iov;
  813. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  814. struct res_lib_confdb_key_get_typed response;
  815. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  816. if (error != CS_OK) {
  817. return (error);
  818. }
  819. if (confdb_inst->standalone) {
  820. error = CS_OK;
  821. if (confdb_sa_key_get_typed(parent_object_handle,
  822. key_name, &value, value_len, (int*)type))
  823. error = CS_ERR_ACCESS;
  824. goto error_exit;
  825. }
  826. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  827. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  828. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  829. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  830. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  831. iov.iov_base = (char *)&req_lib_confdb_key_get;
  832. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  833. error = coroipcc_msg_send_reply_receive (
  834. confdb_inst->handle,
  835. &iov,
  836. 1,
  837. &response,
  838. sizeof (struct res_lib_confdb_key_get_typed));
  839. if (error != CS_OK) {
  840. goto error_exit;
  841. }
  842. error = response.header.error;
  843. if (error == CS_OK) {
  844. *value_len = response.value.length;
  845. *type = response.type;
  846. memcpy(value, response.value.value, *value_len);
  847. }
  848. error_exit:
  849. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  850. return (error);
  851. }
  852. cs_error_t confdb_key_get_typed2 (
  853. confdb_handle_t handle,
  854. hdb_handle_t parent_object_handle,
  855. const char *key_name,
  856. void **value,
  857. size_t *value_len,
  858. confdb_value_types_t *type)
  859. {
  860. cs_error_t error;
  861. struct confdb_inst *confdb_inst;
  862. struct iovec iov;
  863. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  864. struct res_lib_confdb_key_get_typed2 *response;
  865. void *return_address;
  866. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  867. if (error != CS_OK) {
  868. return (error);
  869. }
  870. if (confdb_inst->standalone) {
  871. error = CS_OK;
  872. if (confdb_sa_key_get_typed(parent_object_handle,
  873. key_name, value, value_len, (int*)type))
  874. error = CS_ERR_ACCESS;
  875. goto error_exit;
  876. }
  877. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  878. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED2;
  879. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  880. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  881. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  882. iov.iov_base = (char *)&req_lib_confdb_key_get;
  883. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  884. error = coroipcc_msg_send_reply_receive_in_buf_get (
  885. confdb_inst->handle,
  886. &iov,
  887. 1,
  888. &return_address);
  889. response = return_address;
  890. if (error != CS_OK) {
  891. goto error_exit;
  892. }
  893. error = response->header.error;
  894. if (error == CS_OK) {
  895. if (!*value) {
  896. /* Allow space for naughty callers to put a NUL for printing */
  897. *value = malloc(response->value_length+1);
  898. if (!*value) {
  899. error = CS_ERR_NO_MEMORY;
  900. goto error_exit;
  901. }
  902. }
  903. memcpy(*value, &response->value, response->value_length);
  904. *value_len = response->value_length;
  905. *type = response->type;
  906. }
  907. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  908. error_exit:
  909. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  910. return (error);
  911. }
  912. cs_error_t confdb_key_increment (
  913. confdb_handle_t handle,
  914. hdb_handle_t parent_object_handle,
  915. const void *key_name,
  916. size_t key_name_len,
  917. unsigned int *value)
  918. {
  919. cs_error_t error;
  920. struct confdb_inst *confdb_inst;
  921. struct iovec iov;
  922. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  923. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  924. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  925. if (error != CS_OK) {
  926. return (error);
  927. }
  928. if (confdb_inst->standalone) {
  929. error = CS_OK;
  930. if (confdb_sa_key_increment(parent_object_handle,
  931. key_name, key_name_len,
  932. value))
  933. error = CS_ERR_ACCESS;
  934. goto error_exit;
  935. }
  936. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  937. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  938. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  939. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  940. req_lib_confdb_key_get.key_name.length = key_name_len;
  941. iov.iov_base = (char *)&req_lib_confdb_key_get;
  942. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  943. error = coroipcc_msg_send_reply_receive (
  944. confdb_inst->handle,
  945. &iov,
  946. 1,
  947. &res_lib_confdb_key_incdec,
  948. sizeof (struct res_lib_confdb_key_incdec));
  949. if (error != CS_OK) {
  950. goto error_exit;
  951. }
  952. error = res_lib_confdb_key_incdec.header.error;
  953. if (error == CS_OK) {
  954. *value = res_lib_confdb_key_incdec.value;
  955. }
  956. error_exit:
  957. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  958. return (error);
  959. }
  960. cs_error_t confdb_key_decrement (
  961. confdb_handle_t handle,
  962. hdb_handle_t parent_object_handle,
  963. const void *key_name,
  964. size_t key_name_len,
  965. unsigned int *value)
  966. {
  967. cs_error_t error;
  968. struct confdb_inst *confdb_inst;
  969. struct iovec iov;
  970. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  971. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  972. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  973. if (error != CS_OK) {
  974. return (error);
  975. }
  976. if (confdb_inst->standalone) {
  977. error = CS_OK;
  978. if (confdb_sa_key_decrement(parent_object_handle,
  979. key_name, key_name_len,
  980. value))
  981. error = CS_ERR_ACCESS;
  982. goto error_exit;
  983. }
  984. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  985. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  986. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  987. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  988. req_lib_confdb_key_get.key_name.length = key_name_len;
  989. iov.iov_base = (char *)&req_lib_confdb_key_get;
  990. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  991. error = coroipcc_msg_send_reply_receive (
  992. confdb_inst->handle,
  993. &iov,
  994. 1,
  995. &res_lib_confdb_key_incdec,
  996. sizeof (struct res_lib_confdb_key_incdec));
  997. if (error != CS_OK) {
  998. goto error_exit;
  999. }
  1000. error = res_lib_confdb_key_incdec.header.error;
  1001. if (error == CS_OK) {
  1002. *value = res_lib_confdb_key_incdec.value;
  1003. }
  1004. error_exit:
  1005. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1006. return (error);
  1007. }
  1008. cs_error_t confdb_key_replace (
  1009. confdb_handle_t handle,
  1010. hdb_handle_t parent_object_handle,
  1011. const void *key_name,
  1012. size_t key_name_len,
  1013. const void *old_value,
  1014. size_t old_value_len,
  1015. const void *new_value,
  1016. size_t new_value_len)
  1017. {
  1018. cs_error_t error;
  1019. struct confdb_inst *confdb_inst;
  1020. struct iovec iov;
  1021. struct req_lib_confdb_key_replace2 *req_lib_confdb_key_replace;
  1022. coroipc_response_header_t res;
  1023. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1024. if (error != CS_OK) {
  1025. return (error);
  1026. }
  1027. if (confdb_inst->standalone) {
  1028. error = CS_OK;
  1029. if (confdb_sa_key_replace(parent_object_handle,
  1030. key_name, key_name_len,
  1031. old_value, old_value_len,
  1032. new_value, new_value_len))
  1033. error = CS_ERR_ACCESS;
  1034. goto error_exit;
  1035. }
  1036. req_lib_confdb_key_replace = malloc(sizeof(struct req_lib_confdb_key_replace2) + new_value_len);
  1037. req_lib_confdb_key_replace->header.size = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1038. req_lib_confdb_key_replace->header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE2;
  1039. req_lib_confdb_key_replace->object_handle = parent_object_handle;
  1040. memcpy(req_lib_confdb_key_replace->key_name.value, key_name, key_name_len);
  1041. req_lib_confdb_key_replace->key_name.length = key_name_len;
  1042. memcpy(&req_lib_confdb_key_replace->new_value, new_value, new_value_len);
  1043. req_lib_confdb_key_replace->new_value_length = new_value_len;
  1044. /* Oddly objdb doesn't use the old value, so we don't bother sending it */
  1045. iov.iov_base = (char *)req_lib_confdb_key_replace;
  1046. iov.iov_len = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1047. error = coroipcc_msg_send_reply_receive (
  1048. confdb_inst->handle,
  1049. &iov,
  1050. 1,
  1051. &res,
  1052. sizeof (res));
  1053. if (error != CS_OK) {
  1054. goto free_exit;
  1055. }
  1056. error = res.error;
  1057. free_exit:
  1058. free(req_lib_confdb_key_replace);
  1059. error_exit:
  1060. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1061. return (error);
  1062. }
  1063. cs_error_t confdb_object_iter_start (
  1064. confdb_handle_t handle,
  1065. hdb_handle_t object_handle)
  1066. {
  1067. struct confdb_inst *confdb_inst;
  1068. cs_error_t error = CS_OK;
  1069. struct iter_context *context;
  1070. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1071. if (error != CS_OK) {
  1072. return (error);
  1073. }
  1074. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  1075. if (!context) {
  1076. context = malloc(sizeof(struct iter_context));
  1077. if (!context) {
  1078. error = CS_ERR_NO_MEMORY;
  1079. goto ret;
  1080. }
  1081. context->parent_object_handle = object_handle;
  1082. context->find_handle = 0;
  1083. list_add(&context->list, &confdb_inst->object_iter_head);
  1084. }
  1085. /* Start a new find context */
  1086. if (context->find_handle) {
  1087. (void)do_find_destroy(confdb_inst, context->find_handle);
  1088. context->find_handle = 0;
  1089. }
  1090. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1091. ret:
  1092. return error;
  1093. }
  1094. cs_error_t confdb_key_iter_start (
  1095. confdb_handle_t handle,
  1096. hdb_handle_t object_handle)
  1097. {
  1098. struct confdb_inst *confdb_inst;
  1099. cs_error_t error = CS_OK;
  1100. struct iter_context *context;
  1101. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1102. if (error != CS_OK) {
  1103. return (error);
  1104. }
  1105. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  1106. if (!context) {
  1107. context = malloc(sizeof(struct iter_context));
  1108. if (!context) {
  1109. error = CS_ERR_NO_MEMORY;
  1110. goto ret;
  1111. }
  1112. context->parent_object_handle = object_handle;
  1113. list_add(&context->list, &confdb_inst->key_iter_head);
  1114. }
  1115. context->find_handle = 0;
  1116. context->next_entry = 0;
  1117. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1118. ret:
  1119. return error;
  1120. }
  1121. cs_error_t confdb_object_find_start (
  1122. confdb_handle_t handle,
  1123. hdb_handle_t parent_object_handle)
  1124. {
  1125. struct confdb_inst *confdb_inst;
  1126. cs_error_t error = CS_OK;
  1127. struct iter_context *context;
  1128. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1129. if (error != CS_OK) {
  1130. return (error);
  1131. }
  1132. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1133. if (!context) {
  1134. context = malloc(sizeof(struct iter_context));
  1135. if (!context) {
  1136. error = CS_ERR_NO_MEMORY;
  1137. goto ret;
  1138. }
  1139. context->find_handle = 0;
  1140. context->parent_object_handle = parent_object_handle;
  1141. list_add(&context->list, &confdb_inst->object_find_head);
  1142. }
  1143. /* Start a new find context */
  1144. if (context->find_handle) {
  1145. (void)do_find_destroy(confdb_inst, context->find_handle);
  1146. context->find_handle = 0;
  1147. }
  1148. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1149. ret:
  1150. return error;
  1151. }
  1152. cs_error_t confdb_object_find (
  1153. confdb_handle_t handle,
  1154. hdb_handle_t parent_object_handle,
  1155. const void *object_name,
  1156. size_t object_name_len,
  1157. hdb_handle_t *object_handle)
  1158. {
  1159. cs_error_t error;
  1160. struct confdb_inst *confdb_inst;
  1161. struct iovec iov;
  1162. struct iter_context *context;
  1163. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1164. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1165. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1166. if (error != CS_OK) {
  1167. return (error);
  1168. }
  1169. /* You MUST call confdb_object_find_start first */
  1170. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1171. if (!context) {
  1172. error = CS_ERR_CONTEXT_NOT_FOUND;
  1173. goto error_exit;
  1174. }
  1175. if (confdb_inst->standalone) {
  1176. error = CS_OK;
  1177. if (confdb_sa_object_find(parent_object_handle,
  1178. &context->find_handle,
  1179. object_handle,
  1180. object_name, object_name_len))
  1181. error = CS_ERR_ACCESS;
  1182. goto error_exit;
  1183. }
  1184. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1185. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1186. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1187. req_lib_confdb_object_find.find_handle = context->find_handle;
  1188. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1189. req_lib_confdb_object_find.object_name.length = object_name_len;
  1190. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1191. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1192. error = coroipcc_msg_send_reply_receive (
  1193. confdb_inst->handle,
  1194. &iov,
  1195. 1,
  1196. &res_lib_confdb_object_find,
  1197. sizeof (struct res_lib_confdb_object_find));
  1198. if (error != CS_OK) {
  1199. goto error_exit;
  1200. }
  1201. error = res_lib_confdb_object_find.header.error;
  1202. *object_handle = res_lib_confdb_object_find.object_handle;
  1203. context->find_handle = res_lib_confdb_object_find.find_handle;
  1204. error_exit:
  1205. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1206. return (error);
  1207. }
  1208. cs_error_t confdb_object_iter (
  1209. confdb_handle_t handle,
  1210. hdb_handle_t parent_object_handle,
  1211. hdb_handle_t *object_handle,
  1212. void *object_name,
  1213. size_t *object_name_len)
  1214. {
  1215. cs_error_t error;
  1216. struct confdb_inst *confdb_inst;
  1217. struct iovec iov;
  1218. struct iter_context *context;
  1219. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1220. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1221. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1222. if (error != CS_OK) {
  1223. return (error);
  1224. }
  1225. /* You MUST call confdb_object_iter_start first */
  1226. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1227. if (!context) {
  1228. error = CS_ERR_CONTEXT_NOT_FOUND;
  1229. goto error_exit;
  1230. }
  1231. if (confdb_inst->standalone) {
  1232. error = CS_OK;
  1233. *object_name_len = 0;
  1234. if (confdb_sa_object_iter(parent_object_handle,
  1235. &context->find_handle,
  1236. object_handle,
  1237. NULL, 0,
  1238. object_name, object_name_len))
  1239. error = CS_ERR_ACCESS;
  1240. goto sa_exit;
  1241. }
  1242. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1243. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1244. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1245. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1246. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1247. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1248. error = coroipcc_msg_send_reply_receive (
  1249. confdb_inst->handle,
  1250. &iov,
  1251. 1,
  1252. &res_lib_confdb_object_iter,
  1253. sizeof (struct res_lib_confdb_object_iter));
  1254. if (error != CS_OK) {
  1255. goto error_exit;
  1256. }
  1257. error = res_lib_confdb_object_iter.header.error;
  1258. if (error == CS_OK) {
  1259. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1260. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1261. *object_handle = res_lib_confdb_object_iter.object_handle;
  1262. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1263. }
  1264. sa_exit:
  1265. error_exit:
  1266. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1267. return (error);
  1268. }
  1269. cs_error_t confdb_key_iter (
  1270. confdb_handle_t handle,
  1271. hdb_handle_t parent_object_handle,
  1272. void *key_name,
  1273. size_t *key_name_len,
  1274. void *value,
  1275. size_t *value_len)
  1276. {
  1277. cs_error_t error;
  1278. struct confdb_inst *confdb_inst;
  1279. struct iovec iov;
  1280. struct iter_context *context;
  1281. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1282. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1283. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1284. if (error != CS_OK) {
  1285. return (error);
  1286. }
  1287. /* You MUST call confdb_key_iter_start first */
  1288. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1289. if (!context) {
  1290. error = CS_ERR_CONTEXT_NOT_FOUND;
  1291. goto error_exit;
  1292. }
  1293. if (confdb_inst->standalone) {
  1294. error = CS_OK;
  1295. if (confdb_sa_key_iter(parent_object_handle,
  1296. context->next_entry,
  1297. key_name, key_name_len,
  1298. value, value_len))
  1299. error = CS_ERR_ACCESS;
  1300. goto sa_exit;
  1301. }
  1302. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1303. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1304. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1305. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1306. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1307. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1308. error = coroipcc_msg_send_reply_receive (
  1309. confdb_inst->handle,
  1310. &iov,
  1311. 1,
  1312. &res_lib_confdb_key_iter,
  1313. sizeof (struct res_lib_confdb_key_iter));
  1314. if (error != CS_OK) {
  1315. goto error_exit;
  1316. }
  1317. error = res_lib_confdb_key_iter.header.error;
  1318. if (error == CS_OK) {
  1319. char* key_name_str = (char*)key_name;
  1320. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1321. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1322. key_name_str[res_lib_confdb_key_iter.key_name.length] = '\0';
  1323. *value_len = res_lib_confdb_key_iter.value.length;
  1324. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1325. }
  1326. sa_exit:
  1327. context->next_entry++;
  1328. error_exit:
  1329. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1330. return (error);
  1331. }
  1332. cs_error_t confdb_key_iter_typed (
  1333. confdb_handle_t handle,
  1334. hdb_handle_t parent_object_handle,
  1335. char *key_name,
  1336. void *value,
  1337. size_t *value_len,
  1338. confdb_value_types_t *type)
  1339. {
  1340. cs_error_t error;
  1341. struct confdb_inst *confdb_inst;
  1342. struct iovec iov;
  1343. struct iter_context *context;
  1344. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1345. struct res_lib_confdb_key_iter_typed response;
  1346. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1347. if (error != CS_OK) {
  1348. return (error);
  1349. }
  1350. /* You MUST call confdb_key_iter_start first */
  1351. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1352. if (!context) {
  1353. error = CS_ERR_CONTEXT_NOT_FOUND;
  1354. goto error_exit;
  1355. }
  1356. if (confdb_inst->standalone) {
  1357. error = CS_OK;
  1358. if (confdb_sa_key_iter_typed(parent_object_handle,
  1359. context->next_entry,
  1360. key_name,
  1361. &value, value_len, (int*)type))
  1362. error = CS_ERR_ACCESS;
  1363. goto sa_exit;
  1364. }
  1365. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1366. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1367. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1368. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1369. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1370. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1371. error = coroipcc_msg_send_reply_receive (
  1372. confdb_inst->handle,
  1373. &iov,
  1374. 1,
  1375. &response,
  1376. sizeof (struct res_lib_confdb_key_iter_typed));
  1377. if (error != CS_OK) {
  1378. goto error_exit;
  1379. }
  1380. error = response.header.error;
  1381. if (error == CS_OK) {
  1382. memcpy(key_name, response.key_name.value, response.key_name.length);
  1383. key_name[response.key_name.length] = '\0';
  1384. *value_len = response.value.length;
  1385. memcpy(value, response.value.value, *value_len);
  1386. *type = response.type;
  1387. }
  1388. sa_exit:
  1389. context->next_entry++;
  1390. error_exit:
  1391. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1392. return (error);
  1393. }
  1394. cs_error_t confdb_key_iter_typed2 (
  1395. confdb_handle_t handle,
  1396. hdb_handle_t parent_object_handle,
  1397. char *key_name,
  1398. void **value,
  1399. size_t *value_len,
  1400. confdb_value_types_t *type)
  1401. {
  1402. cs_error_t error;
  1403. struct confdb_inst *confdb_inst;
  1404. struct iovec iov;
  1405. struct iter_context *context;
  1406. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1407. struct res_lib_confdb_key_iter_typed2 *response;
  1408. void *return_address;
  1409. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1410. if (error != CS_OK) {
  1411. return (error);
  1412. }
  1413. /* You MUST call confdb_key_iter_start first */
  1414. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1415. if (!context) {
  1416. error = CS_ERR_CONTEXT_NOT_FOUND;
  1417. goto error_exit;
  1418. }
  1419. if (confdb_inst->standalone) {
  1420. error = CS_OK;
  1421. if (confdb_sa_key_iter_typed(parent_object_handle,
  1422. context->next_entry,
  1423. key_name,
  1424. value, value_len, (int*)type))
  1425. error = CS_ERR_ACCESS;
  1426. goto sa_exit;
  1427. }
  1428. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1429. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED2;
  1430. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1431. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1432. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1433. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1434. error = coroipcc_msg_send_reply_receive_in_buf_get (
  1435. confdb_inst->handle,
  1436. &iov,
  1437. 1,
  1438. &return_address);
  1439. response = return_address;
  1440. if (error != CS_OK) {
  1441. goto error_exit;
  1442. }
  1443. error = response->header.error;
  1444. if (error == CS_OK) {
  1445. if (!*value) {
  1446. /* Allow space for naughty callers to put a NUL for printing */
  1447. *value = malloc(response->value_length+1);
  1448. if (!*value) {
  1449. error = CS_ERR_NO_MEMORY;
  1450. goto error_exit;
  1451. }
  1452. }
  1453. memcpy(key_name, response->key_name.value, response->key_name.length);
  1454. key_name[response->key_name.length] = '\0';
  1455. memcpy(*value, &response->value, response->value_length);
  1456. *value_len = response->value_length;
  1457. *type = response->type;
  1458. }
  1459. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  1460. sa_exit:
  1461. context->next_entry++;
  1462. error_exit:
  1463. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1464. return (error);
  1465. }
  1466. cs_error_t confdb_write (
  1467. confdb_handle_t handle,
  1468. char *error_text,
  1469. size_t errbuf_len)
  1470. {
  1471. cs_error_t error;
  1472. struct confdb_inst *confdb_inst;
  1473. struct iovec iov;
  1474. coroipc_request_header_t req;
  1475. struct res_lib_confdb_write res_lib_confdb_write;
  1476. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1477. if (error != CS_OK) {
  1478. /* FIXME: set error_text */
  1479. return (error);
  1480. }
  1481. if (confdb_inst->standalone) {
  1482. error = CS_OK;
  1483. if (confdb_sa_write(error_text, errbuf_len))
  1484. error = CS_ERR_ACCESS;
  1485. goto error_exit;
  1486. }
  1487. req.size = sizeof (coroipc_request_header_t);
  1488. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1489. iov.iov_base = (char *)&req;
  1490. iov.iov_len = sizeof (coroipc_request_header_t);
  1491. error = coroipcc_msg_send_reply_receive (
  1492. confdb_inst->handle,
  1493. &iov,
  1494. 1,
  1495. &res_lib_confdb_write,
  1496. sizeof (struct res_lib_confdb_write));
  1497. if (error != CS_OK) {
  1498. /* FIXME: set error_text */
  1499. goto error_exit;
  1500. }
  1501. error = res_lib_confdb_write.header.error;
  1502. if (res_lib_confdb_write.error.length) {
  1503. memcpy(error_text, res_lib_confdb_write.error.value,
  1504. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1505. error_text[errbuf_len-1] = '\0';
  1506. }
  1507. error_exit:
  1508. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1509. return (error);
  1510. }
  1511. cs_error_t confdb_reload (
  1512. confdb_handle_t handle,
  1513. int flush,
  1514. char *error_text,
  1515. size_t errbuf_len)
  1516. {
  1517. cs_error_t error;
  1518. struct confdb_inst *confdb_inst;
  1519. struct iovec iov;
  1520. struct res_lib_confdb_reload res_lib_confdb_reload;
  1521. struct req_lib_confdb_reload req_lib_confdb_reload;
  1522. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1523. if (error != CS_OK) {
  1524. /* FIXME: set error_text */
  1525. return (error);
  1526. }
  1527. if (confdb_inst->standalone) {
  1528. error = CS_OK;
  1529. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1530. error = CS_ERR_ACCESS;
  1531. goto error_exit;
  1532. }
  1533. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1534. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1535. req_lib_confdb_reload.flush = flush;
  1536. iov.iov_base = (char *)&req_lib_confdb_reload;
  1537. iov.iov_len = sizeof (req_lib_confdb_reload);
  1538. error = coroipcc_msg_send_reply_receive (
  1539. confdb_inst->handle,
  1540. &iov,
  1541. 1,
  1542. &res_lib_confdb_reload,
  1543. sizeof (struct res_lib_confdb_reload));
  1544. if (error != CS_OK) {
  1545. /* FIXME: set error_text */
  1546. goto error_exit;
  1547. }
  1548. error = res_lib_confdb_reload.header.error;
  1549. if(res_lib_confdb_reload.error.length) {
  1550. memcpy(error_text, res_lib_confdb_reload.error.value,
  1551. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1552. error_text[errbuf_len-1] = '\0';
  1553. }
  1554. error_exit:
  1555. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1556. return (error);
  1557. }
  1558. cs_error_t confdb_track_changes (
  1559. confdb_handle_t handle,
  1560. hdb_handle_t object_handle,
  1561. unsigned int flags)
  1562. {
  1563. cs_error_t error;
  1564. struct confdb_inst *confdb_inst;
  1565. struct iovec iov;
  1566. struct req_lib_confdb_object_track_start req;
  1567. coroipc_response_header_t res;
  1568. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1569. if (error != CS_OK) {
  1570. return (error);
  1571. }
  1572. if (confdb_inst->standalone) {
  1573. error = CS_ERR_NOT_SUPPORTED;
  1574. goto error_exit;
  1575. }
  1576. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1577. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1578. req.object_handle = object_handle;
  1579. req.flags = flags;
  1580. iov.iov_base = (char *)&req;
  1581. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1582. error = coroipcc_msg_send_reply_receive (
  1583. confdb_inst->handle,
  1584. &iov,
  1585. 1,
  1586. &res,
  1587. sizeof (coroipc_response_header_t));
  1588. if (error != CS_OK) {
  1589. goto error_exit;
  1590. }
  1591. error = res.error;
  1592. error_exit:
  1593. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1594. return (error);
  1595. }
  1596. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1597. {
  1598. cs_error_t error;
  1599. struct confdb_inst *confdb_inst;
  1600. struct iovec iov;
  1601. coroipc_request_header_t req;
  1602. coroipc_response_header_t res;
  1603. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1604. if (error != CS_OK) {
  1605. return (error);
  1606. }
  1607. if (confdb_inst->standalone) {
  1608. error = CS_ERR_NOT_SUPPORTED;
  1609. goto error_exit;
  1610. }
  1611. req.size = sizeof (coroipc_request_header_t);
  1612. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1613. iov.iov_base = (char *)&req;
  1614. iov.iov_len = sizeof (coroipc_request_header_t);
  1615. error = coroipcc_msg_send_reply_receive (
  1616. confdb_inst->handle,
  1617. &iov,
  1618. 1,
  1619. &res,
  1620. sizeof (coroipc_response_header_t));
  1621. if (error != CS_OK) {
  1622. goto error_exit;
  1623. }
  1624. error = res.error;
  1625. error_exit:
  1626. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1627. return (error);
  1628. }