confdb.c 51 KB

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