confdb.c 52 KB

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