confdb.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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 free_exit;
  697. }
  698. error = res.error;
  699. free_exit:
  700. free(request);
  701. error_exit:
  702. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  703. return (error);
  704. }
  705. cs_error_t confdb_key_delete (
  706. confdb_handle_t handle,
  707. hdb_handle_t parent_object_handle,
  708. const void *key_name,
  709. size_t key_name_len,
  710. const void *value,
  711. size_t value_len)
  712. {
  713. cs_error_t error;
  714. struct confdb_inst *confdb_inst;
  715. struct iovec iov;
  716. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  717. coroipc_response_header_t res;
  718. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  719. if (error != CS_OK) {
  720. return (error);
  721. }
  722. if (confdb_inst->standalone) {
  723. error = CS_OK;
  724. if (confdb_sa_key_delete(parent_object_handle,
  725. key_name, key_name_len,
  726. value, value_len))
  727. error = CS_ERR_ACCESS;
  728. goto error_exit;
  729. }
  730. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  731. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  732. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  733. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  734. req_lib_confdb_key_delete.key_name.length = key_name_len;
  735. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  736. req_lib_confdb_key_delete.value.length = value_len;
  737. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  738. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  739. error = coroipcc_msg_send_reply_receive (
  740. confdb_inst->handle,
  741. &iov,
  742. 1,
  743. &res,
  744. sizeof (res));
  745. if (error != CS_OK) {
  746. goto error_exit;
  747. }
  748. error = res.error;
  749. error_exit:
  750. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  751. return (error);
  752. }
  753. cs_error_t confdb_key_get (
  754. confdb_handle_t handle,
  755. hdb_handle_t parent_object_handle,
  756. const void *key_name,
  757. size_t key_name_len,
  758. void *value,
  759. size_t *value_len)
  760. {
  761. cs_error_t error;
  762. struct confdb_inst *confdb_inst;
  763. struct iovec iov;
  764. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  765. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  766. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  767. if (error != CS_OK) {
  768. return (error);
  769. }
  770. if (confdb_inst->standalone) {
  771. error = CS_OK;
  772. if (confdb_sa_key_get(parent_object_handle,
  773. key_name, key_name_len,
  774. value, value_len))
  775. error = CS_ERR_ACCESS;
  776. goto error_exit;
  777. }
  778. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  779. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  780. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  781. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  782. req_lib_confdb_key_get.key_name.length = key_name_len;
  783. iov.iov_base = (char *)&req_lib_confdb_key_get;
  784. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  785. error = coroipcc_msg_send_reply_receive (
  786. confdb_inst->handle,
  787. &iov,
  788. 1,
  789. &res_lib_confdb_key_get,
  790. sizeof (struct res_lib_confdb_key_get));
  791. if (error != CS_OK) {
  792. goto error_exit;
  793. }
  794. error = res_lib_confdb_key_get.header.error;
  795. if (error == CS_OK) {
  796. *value_len = res_lib_confdb_key_get.value.length;
  797. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  798. }
  799. error_exit:
  800. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  801. return (error);
  802. }
  803. cs_error_t confdb_key_get_typed (
  804. confdb_handle_t handle,
  805. hdb_handle_t parent_object_handle,
  806. const char *key_name,
  807. void *value,
  808. size_t *value_len,
  809. confdb_value_types_t *type)
  810. {
  811. cs_error_t error;
  812. struct confdb_inst *confdb_inst;
  813. struct iovec iov;
  814. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  815. struct res_lib_confdb_key_get_typed response;
  816. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  817. if (error != CS_OK) {
  818. return (error);
  819. }
  820. if (confdb_inst->standalone) {
  821. error = CS_OK;
  822. if (confdb_sa_key_get_typed(parent_object_handle,
  823. key_name, &value, value_len, (int*)type))
  824. error = CS_ERR_ACCESS;
  825. goto error_exit;
  826. }
  827. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  828. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  829. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  830. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  831. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  832. iov.iov_base = (char *)&req_lib_confdb_key_get;
  833. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  834. error = coroipcc_msg_send_reply_receive (
  835. confdb_inst->handle,
  836. &iov,
  837. 1,
  838. &response,
  839. sizeof (struct res_lib_confdb_key_get_typed));
  840. if (error != CS_OK) {
  841. goto error_exit;
  842. }
  843. error = response.header.error;
  844. if (error == CS_OK) {
  845. *value_len = response.value.length;
  846. *type = response.type;
  847. memcpy(value, response.value.value, *value_len);
  848. }
  849. error_exit:
  850. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  851. return (error);
  852. }
  853. cs_error_t confdb_key_get_typed2 (
  854. confdb_handle_t handle,
  855. hdb_handle_t parent_object_handle,
  856. const char *key_name,
  857. void **value,
  858. size_t *value_len,
  859. confdb_value_types_t *type)
  860. {
  861. cs_error_t error;
  862. struct confdb_inst *confdb_inst;
  863. struct iovec iov;
  864. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  865. struct res_lib_confdb_key_get_typed2 *response;
  866. void *return_address;
  867. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  868. if (error != CS_OK) {
  869. return (error);
  870. }
  871. if (confdb_inst->standalone) {
  872. error = CS_OK;
  873. if (confdb_sa_key_get_typed(parent_object_handle,
  874. key_name, value, value_len, (int*)type))
  875. error = CS_ERR_ACCESS;
  876. goto error_exit;
  877. }
  878. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  879. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED2;
  880. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  881. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  882. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  883. iov.iov_base = (char *)&req_lib_confdb_key_get;
  884. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  885. error = coroipcc_msg_send_reply_receive_in_buf_get (
  886. confdb_inst->handle,
  887. &iov,
  888. 1,
  889. &return_address);
  890. response = return_address;
  891. if (error != CS_OK) {
  892. goto error_exit;
  893. }
  894. error = response->header.error;
  895. if (error == CS_OK) {
  896. if (!*value) {
  897. /* Allow space for naughty callers to put a NUL for printing */
  898. *value = malloc(response->value_length+1);
  899. if (!*value) {
  900. error = CS_ERR_NO_MEMORY;
  901. goto error_exit;
  902. }
  903. }
  904. memcpy(*value, &response->value, response->value_length);
  905. *value_len = response->value_length;
  906. *type = response->type;
  907. }
  908. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  909. error_exit:
  910. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  911. return (error);
  912. }
  913. cs_error_t confdb_key_increment (
  914. confdb_handle_t handle,
  915. hdb_handle_t parent_object_handle,
  916. const void *key_name,
  917. size_t key_name_len,
  918. unsigned int *value)
  919. {
  920. cs_error_t error;
  921. struct confdb_inst *confdb_inst;
  922. struct iovec iov;
  923. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  924. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  925. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  926. if (error != CS_OK) {
  927. return (error);
  928. }
  929. if (confdb_inst->standalone) {
  930. error = CS_OK;
  931. if (confdb_sa_key_increment(parent_object_handle,
  932. key_name, key_name_len,
  933. value))
  934. error = CS_ERR_ACCESS;
  935. goto error_exit;
  936. }
  937. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  938. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  939. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  940. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  941. req_lib_confdb_key_get.key_name.length = key_name_len;
  942. iov.iov_base = (char *)&req_lib_confdb_key_get;
  943. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  944. error = coroipcc_msg_send_reply_receive (
  945. confdb_inst->handle,
  946. &iov,
  947. 1,
  948. &res_lib_confdb_key_incdec,
  949. sizeof (struct res_lib_confdb_key_incdec));
  950. if (error != CS_OK) {
  951. goto error_exit;
  952. }
  953. error = res_lib_confdb_key_incdec.header.error;
  954. if (error == CS_OK) {
  955. *value = res_lib_confdb_key_incdec.value;
  956. }
  957. error_exit:
  958. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  959. return (error);
  960. }
  961. cs_error_t confdb_key_decrement (
  962. confdb_handle_t handle,
  963. hdb_handle_t parent_object_handle,
  964. const void *key_name,
  965. size_t key_name_len,
  966. unsigned int *value)
  967. {
  968. cs_error_t error;
  969. struct confdb_inst *confdb_inst;
  970. struct iovec iov;
  971. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  972. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  973. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  974. if (error != CS_OK) {
  975. return (error);
  976. }
  977. if (confdb_inst->standalone) {
  978. error = CS_OK;
  979. if (confdb_sa_key_decrement(parent_object_handle,
  980. key_name, key_name_len,
  981. value))
  982. error = CS_ERR_ACCESS;
  983. goto error_exit;
  984. }
  985. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  986. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  987. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  988. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  989. req_lib_confdb_key_get.key_name.length = key_name_len;
  990. iov.iov_base = (char *)&req_lib_confdb_key_get;
  991. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  992. error = coroipcc_msg_send_reply_receive (
  993. confdb_inst->handle,
  994. &iov,
  995. 1,
  996. &res_lib_confdb_key_incdec,
  997. sizeof (struct res_lib_confdb_key_incdec));
  998. if (error != CS_OK) {
  999. goto error_exit;
  1000. }
  1001. error = res_lib_confdb_key_incdec.header.error;
  1002. if (error == CS_OK) {
  1003. *value = res_lib_confdb_key_incdec.value;
  1004. }
  1005. error_exit:
  1006. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1007. return (error);
  1008. }
  1009. cs_error_t confdb_key_replace (
  1010. confdb_handle_t handle,
  1011. hdb_handle_t parent_object_handle,
  1012. const void *key_name,
  1013. size_t key_name_len,
  1014. const void *old_value,
  1015. size_t old_value_len,
  1016. const void *new_value,
  1017. size_t new_value_len)
  1018. {
  1019. cs_error_t error;
  1020. struct confdb_inst *confdb_inst;
  1021. struct iovec iov;
  1022. struct req_lib_confdb_key_replace2 *req_lib_confdb_key_replace;
  1023. coroipc_response_header_t res;
  1024. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1025. if (error != CS_OK) {
  1026. return (error);
  1027. }
  1028. if (confdb_inst->standalone) {
  1029. error = CS_OK;
  1030. if (confdb_sa_key_replace(parent_object_handle,
  1031. key_name, key_name_len,
  1032. old_value, old_value_len,
  1033. new_value, new_value_len))
  1034. error = CS_ERR_ACCESS;
  1035. goto error_exit;
  1036. }
  1037. req_lib_confdb_key_replace = malloc(sizeof(struct req_lib_confdb_key_replace2) + new_value_len);
  1038. req_lib_confdb_key_replace->header.size = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1039. req_lib_confdb_key_replace->header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE2;
  1040. req_lib_confdb_key_replace->object_handle = parent_object_handle;
  1041. memcpy(req_lib_confdb_key_replace->key_name.value, key_name, key_name_len);
  1042. req_lib_confdb_key_replace->key_name.length = key_name_len;
  1043. memcpy(&req_lib_confdb_key_replace->new_value, new_value, new_value_len);
  1044. req_lib_confdb_key_replace->new_value_length = new_value_len;
  1045. /* Oddly objdb doesn't use the old value, so we don't bother sending it */
  1046. iov.iov_base = (char *)req_lib_confdb_key_replace;
  1047. iov.iov_len = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1048. error = coroipcc_msg_send_reply_receive (
  1049. confdb_inst->handle,
  1050. &iov,
  1051. 1,
  1052. &res,
  1053. sizeof (res));
  1054. if (error != CS_OK) {
  1055. goto free_exit;
  1056. }
  1057. error = res.error;
  1058. free_exit:
  1059. free(req_lib_confdb_key_replace);
  1060. error_exit:
  1061. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1062. return (error);
  1063. }
  1064. cs_error_t confdb_object_iter_start (
  1065. confdb_handle_t handle,
  1066. hdb_handle_t object_handle)
  1067. {
  1068. struct confdb_inst *confdb_inst;
  1069. cs_error_t error = CS_OK;
  1070. struct iter_context *context;
  1071. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1072. if (error != CS_OK) {
  1073. return (error);
  1074. }
  1075. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  1076. if (!context) {
  1077. context = malloc(sizeof(struct iter_context));
  1078. if (!context) {
  1079. error = CS_ERR_NO_MEMORY;
  1080. goto ret;
  1081. }
  1082. context->parent_object_handle = object_handle;
  1083. context->find_handle = 0;
  1084. list_add(&context->list, &confdb_inst->object_iter_head);
  1085. }
  1086. /* Start a new find context */
  1087. if (context->find_handle) {
  1088. (void)do_find_destroy(confdb_inst, context->find_handle);
  1089. context->find_handle = 0;
  1090. }
  1091. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1092. ret:
  1093. return error;
  1094. }
  1095. cs_error_t confdb_key_iter_start (
  1096. confdb_handle_t handle,
  1097. hdb_handle_t object_handle)
  1098. {
  1099. struct confdb_inst *confdb_inst;
  1100. cs_error_t error = CS_OK;
  1101. struct iter_context *context;
  1102. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1103. if (error != CS_OK) {
  1104. return (error);
  1105. }
  1106. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  1107. if (!context) {
  1108. context = malloc(sizeof(struct iter_context));
  1109. if (!context) {
  1110. error = CS_ERR_NO_MEMORY;
  1111. goto ret;
  1112. }
  1113. context->parent_object_handle = object_handle;
  1114. list_add(&context->list, &confdb_inst->key_iter_head);
  1115. }
  1116. context->find_handle = 0;
  1117. context->next_entry = 0;
  1118. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1119. ret:
  1120. return error;
  1121. }
  1122. cs_error_t confdb_object_find_start (
  1123. confdb_handle_t handle,
  1124. hdb_handle_t parent_object_handle)
  1125. {
  1126. struct confdb_inst *confdb_inst;
  1127. cs_error_t error = CS_OK;
  1128. struct iter_context *context;
  1129. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1130. if (error != CS_OK) {
  1131. return (error);
  1132. }
  1133. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1134. if (!context) {
  1135. context = malloc(sizeof(struct iter_context));
  1136. if (!context) {
  1137. error = CS_ERR_NO_MEMORY;
  1138. goto ret;
  1139. }
  1140. context->find_handle = 0;
  1141. context->parent_object_handle = parent_object_handle;
  1142. list_add(&context->list, &confdb_inst->object_find_head);
  1143. }
  1144. /* Start a new find context */
  1145. if (context->find_handle) {
  1146. (void)do_find_destroy(confdb_inst, context->find_handle);
  1147. context->find_handle = 0;
  1148. }
  1149. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1150. ret:
  1151. return error;
  1152. }
  1153. cs_error_t confdb_object_find (
  1154. confdb_handle_t handle,
  1155. hdb_handle_t parent_object_handle,
  1156. const void *object_name,
  1157. size_t object_name_len,
  1158. hdb_handle_t *object_handle)
  1159. {
  1160. cs_error_t error;
  1161. struct confdb_inst *confdb_inst;
  1162. struct iovec iov;
  1163. struct iter_context *context;
  1164. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1165. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1166. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1167. if (error != CS_OK) {
  1168. return (error);
  1169. }
  1170. /* You MUST call confdb_object_find_start first */
  1171. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1172. if (!context) {
  1173. error = CS_ERR_CONTEXT_NOT_FOUND;
  1174. goto error_exit;
  1175. }
  1176. if (confdb_inst->standalone) {
  1177. error = CS_OK;
  1178. if (confdb_sa_object_find(parent_object_handle,
  1179. &context->find_handle,
  1180. object_handle,
  1181. object_name, object_name_len))
  1182. error = CS_ERR_ACCESS;
  1183. goto error_exit;
  1184. }
  1185. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1186. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1187. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1188. req_lib_confdb_object_find.find_handle = context->find_handle;
  1189. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1190. req_lib_confdb_object_find.object_name.length = object_name_len;
  1191. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1192. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1193. error = coroipcc_msg_send_reply_receive (
  1194. confdb_inst->handle,
  1195. &iov,
  1196. 1,
  1197. &res_lib_confdb_object_find,
  1198. sizeof (struct res_lib_confdb_object_find));
  1199. if (error != CS_OK) {
  1200. goto error_exit;
  1201. }
  1202. error = res_lib_confdb_object_find.header.error;
  1203. *object_handle = res_lib_confdb_object_find.object_handle;
  1204. context->find_handle = res_lib_confdb_object_find.find_handle;
  1205. error_exit:
  1206. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1207. return (error);
  1208. }
  1209. cs_error_t confdb_object_iter (
  1210. confdb_handle_t handle,
  1211. hdb_handle_t parent_object_handle,
  1212. hdb_handle_t *object_handle,
  1213. void *object_name,
  1214. size_t *object_name_len)
  1215. {
  1216. cs_error_t error;
  1217. struct confdb_inst *confdb_inst;
  1218. struct iovec iov;
  1219. struct iter_context *context;
  1220. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1221. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1222. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1223. if (error != CS_OK) {
  1224. return (error);
  1225. }
  1226. /* You MUST call confdb_object_iter_start first */
  1227. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1228. if (!context) {
  1229. error = CS_ERR_CONTEXT_NOT_FOUND;
  1230. goto error_exit;
  1231. }
  1232. if (confdb_inst->standalone) {
  1233. error = CS_OK;
  1234. *object_name_len = 0;
  1235. if (confdb_sa_object_iter(parent_object_handle,
  1236. &context->find_handle,
  1237. object_handle,
  1238. NULL, 0,
  1239. object_name, object_name_len))
  1240. error = CS_ERR_ACCESS;
  1241. goto sa_exit;
  1242. }
  1243. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1244. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1245. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1246. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1247. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1248. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1249. error = coroipcc_msg_send_reply_receive (
  1250. confdb_inst->handle,
  1251. &iov,
  1252. 1,
  1253. &res_lib_confdb_object_iter,
  1254. sizeof (struct res_lib_confdb_object_iter));
  1255. if (error != CS_OK) {
  1256. goto error_exit;
  1257. }
  1258. error = res_lib_confdb_object_iter.header.error;
  1259. if (error == CS_OK) {
  1260. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1261. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1262. *object_handle = res_lib_confdb_object_iter.object_handle;
  1263. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1264. }
  1265. sa_exit:
  1266. error_exit:
  1267. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1268. return (error);
  1269. }
  1270. cs_error_t confdb_key_iter (
  1271. confdb_handle_t handle,
  1272. hdb_handle_t parent_object_handle,
  1273. void *key_name,
  1274. size_t *key_name_len,
  1275. void *value,
  1276. size_t *value_len)
  1277. {
  1278. cs_error_t error;
  1279. struct confdb_inst *confdb_inst;
  1280. struct iovec iov;
  1281. struct iter_context *context;
  1282. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1283. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1284. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1285. if (error != CS_OK) {
  1286. return (error);
  1287. }
  1288. /* You MUST call confdb_key_iter_start first */
  1289. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1290. if (!context) {
  1291. error = CS_ERR_CONTEXT_NOT_FOUND;
  1292. goto error_exit;
  1293. }
  1294. if (confdb_inst->standalone) {
  1295. error = CS_OK;
  1296. if (confdb_sa_key_iter(parent_object_handle,
  1297. context->next_entry,
  1298. key_name, key_name_len,
  1299. value, value_len))
  1300. error = CS_ERR_ACCESS;
  1301. goto sa_exit;
  1302. }
  1303. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1304. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1305. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1306. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1307. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1308. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1309. error = coroipcc_msg_send_reply_receive (
  1310. confdb_inst->handle,
  1311. &iov,
  1312. 1,
  1313. &res_lib_confdb_key_iter,
  1314. sizeof (struct res_lib_confdb_key_iter));
  1315. if (error != CS_OK) {
  1316. goto error_exit;
  1317. }
  1318. error = res_lib_confdb_key_iter.header.error;
  1319. if (error == CS_OK) {
  1320. char* key_name_str = (char*)key_name;
  1321. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1322. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1323. key_name_str[res_lib_confdb_key_iter.key_name.length] = '\0';
  1324. *value_len = res_lib_confdb_key_iter.value.length;
  1325. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1326. }
  1327. sa_exit:
  1328. context->next_entry++;
  1329. error_exit:
  1330. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1331. return (error);
  1332. }
  1333. cs_error_t confdb_key_iter_typed (
  1334. confdb_handle_t handle,
  1335. hdb_handle_t parent_object_handle,
  1336. char *key_name,
  1337. void *value,
  1338. size_t *value_len,
  1339. confdb_value_types_t *type)
  1340. {
  1341. cs_error_t error;
  1342. struct confdb_inst *confdb_inst;
  1343. struct iovec iov;
  1344. struct iter_context *context;
  1345. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1346. struct res_lib_confdb_key_iter_typed response;
  1347. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1348. if (error != CS_OK) {
  1349. return (error);
  1350. }
  1351. /* You MUST call confdb_key_iter_start first */
  1352. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1353. if (!context) {
  1354. error = CS_ERR_CONTEXT_NOT_FOUND;
  1355. goto error_exit;
  1356. }
  1357. if (confdb_inst->standalone) {
  1358. error = CS_OK;
  1359. if (confdb_sa_key_iter_typed(parent_object_handle,
  1360. context->next_entry,
  1361. key_name,
  1362. &value, value_len, (int*)type))
  1363. error = CS_ERR_ACCESS;
  1364. goto sa_exit;
  1365. }
  1366. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1367. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1368. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1369. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1370. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1371. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1372. error = coroipcc_msg_send_reply_receive (
  1373. confdb_inst->handle,
  1374. &iov,
  1375. 1,
  1376. &response,
  1377. sizeof (struct res_lib_confdb_key_iter_typed));
  1378. if (error != CS_OK) {
  1379. goto error_exit;
  1380. }
  1381. error = response.header.error;
  1382. if (error == CS_OK) {
  1383. memcpy(key_name, response.key_name.value, response.key_name.length);
  1384. key_name[response.key_name.length] = '\0';
  1385. *value_len = response.value.length;
  1386. memcpy(value, response.value.value, *value_len);
  1387. *type = response.type;
  1388. }
  1389. sa_exit:
  1390. context->next_entry++;
  1391. error_exit:
  1392. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1393. return (error);
  1394. }
  1395. cs_error_t confdb_key_iter_typed2 (
  1396. confdb_handle_t handle,
  1397. hdb_handle_t parent_object_handle,
  1398. char *key_name,
  1399. void **value,
  1400. size_t *value_len,
  1401. confdb_value_types_t *type)
  1402. {
  1403. cs_error_t error;
  1404. struct confdb_inst *confdb_inst;
  1405. struct iovec iov;
  1406. struct iter_context *context;
  1407. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1408. struct res_lib_confdb_key_iter_typed2 *response;
  1409. void *return_address;
  1410. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1411. if (error != CS_OK) {
  1412. return (error);
  1413. }
  1414. /* You MUST call confdb_key_iter_start first */
  1415. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1416. if (!context) {
  1417. error = CS_ERR_CONTEXT_NOT_FOUND;
  1418. goto error_exit;
  1419. }
  1420. if (confdb_inst->standalone) {
  1421. error = CS_OK;
  1422. if (confdb_sa_key_iter_typed(parent_object_handle,
  1423. context->next_entry,
  1424. key_name,
  1425. value, value_len, (int*)type))
  1426. error = CS_ERR_ACCESS;
  1427. goto sa_exit;
  1428. }
  1429. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1430. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED2;
  1431. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1432. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1433. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1434. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1435. error = coroipcc_msg_send_reply_receive_in_buf_get (
  1436. confdb_inst->handle,
  1437. &iov,
  1438. 1,
  1439. &return_address);
  1440. response = return_address;
  1441. if (error != CS_OK) {
  1442. goto error_exit;
  1443. }
  1444. error = response->header.error;
  1445. if (error == CS_OK) {
  1446. if (!*value) {
  1447. /* Allow space for naughty callers to put a NUL for printing */
  1448. *value = malloc(response->value_length+1);
  1449. if (!*value) {
  1450. error = CS_ERR_NO_MEMORY;
  1451. goto error_exit;
  1452. }
  1453. }
  1454. memcpy(key_name, response->key_name.value, response->key_name.length);
  1455. key_name[response->key_name.length] = '\0';
  1456. memcpy(*value, &response->value, response->value_length);
  1457. *value_len = response->value_length;
  1458. *type = response->type;
  1459. }
  1460. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  1461. sa_exit:
  1462. context->next_entry++;
  1463. error_exit:
  1464. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1465. return (error);
  1466. }
  1467. cs_error_t confdb_write (
  1468. confdb_handle_t handle,
  1469. char *error_text,
  1470. size_t errbuf_len)
  1471. {
  1472. cs_error_t error;
  1473. struct confdb_inst *confdb_inst;
  1474. struct iovec iov;
  1475. coroipc_request_header_t req;
  1476. struct res_lib_confdb_write res_lib_confdb_write;
  1477. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1478. if (error != CS_OK) {
  1479. /* FIXME: set error_text */
  1480. return (error);
  1481. }
  1482. if (confdb_inst->standalone) {
  1483. error = CS_OK;
  1484. if (confdb_sa_write(error_text, errbuf_len))
  1485. error = CS_ERR_ACCESS;
  1486. goto error_exit;
  1487. }
  1488. req.size = sizeof (coroipc_request_header_t);
  1489. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1490. iov.iov_base = (char *)&req;
  1491. iov.iov_len = sizeof (coroipc_request_header_t);
  1492. error = coroipcc_msg_send_reply_receive (
  1493. confdb_inst->handle,
  1494. &iov,
  1495. 1,
  1496. &res_lib_confdb_write,
  1497. sizeof (struct res_lib_confdb_write));
  1498. if (error != CS_OK) {
  1499. /* FIXME: set error_text */
  1500. goto error_exit;
  1501. }
  1502. error = res_lib_confdb_write.header.error;
  1503. if (res_lib_confdb_write.error.length) {
  1504. memcpy(error_text, res_lib_confdb_write.error.value,
  1505. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1506. error_text[errbuf_len-1] = '\0';
  1507. }
  1508. error_exit:
  1509. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1510. return (error);
  1511. }
  1512. cs_error_t confdb_reload (
  1513. confdb_handle_t handle,
  1514. int flush,
  1515. char *error_text,
  1516. size_t errbuf_len)
  1517. {
  1518. cs_error_t error;
  1519. struct confdb_inst *confdb_inst;
  1520. struct iovec iov;
  1521. struct res_lib_confdb_reload res_lib_confdb_reload;
  1522. struct req_lib_confdb_reload req_lib_confdb_reload;
  1523. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1524. if (error != CS_OK) {
  1525. /* FIXME: set error_text */
  1526. return (error);
  1527. }
  1528. if (confdb_inst->standalone) {
  1529. error = CS_OK;
  1530. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1531. error = CS_ERR_ACCESS;
  1532. goto error_exit;
  1533. }
  1534. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1535. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1536. req_lib_confdb_reload.flush = flush;
  1537. iov.iov_base = (char *)&req_lib_confdb_reload;
  1538. iov.iov_len = sizeof (req_lib_confdb_reload);
  1539. error = coroipcc_msg_send_reply_receive (
  1540. confdb_inst->handle,
  1541. &iov,
  1542. 1,
  1543. &res_lib_confdb_reload,
  1544. sizeof (struct res_lib_confdb_reload));
  1545. if (error != CS_OK) {
  1546. /* FIXME: set error_text */
  1547. goto error_exit;
  1548. }
  1549. error = res_lib_confdb_reload.header.error;
  1550. if(res_lib_confdb_reload.error.length) {
  1551. memcpy(error_text, res_lib_confdb_reload.error.value,
  1552. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1553. error_text[errbuf_len-1] = '\0';
  1554. }
  1555. error_exit:
  1556. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1557. return (error);
  1558. }
  1559. cs_error_t confdb_track_changes (
  1560. confdb_handle_t handle,
  1561. hdb_handle_t object_handle,
  1562. unsigned int flags)
  1563. {
  1564. cs_error_t error;
  1565. struct confdb_inst *confdb_inst;
  1566. struct iovec iov;
  1567. struct req_lib_confdb_object_track_start req;
  1568. coroipc_response_header_t res;
  1569. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1570. if (error != CS_OK) {
  1571. return (error);
  1572. }
  1573. if (confdb_inst->standalone) {
  1574. error = CS_ERR_NOT_SUPPORTED;
  1575. goto error_exit;
  1576. }
  1577. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1578. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1579. req.object_handle = object_handle;
  1580. req.flags = flags;
  1581. iov.iov_base = (char *)&req;
  1582. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1583. error = coroipcc_msg_send_reply_receive (
  1584. confdb_inst->handle,
  1585. &iov,
  1586. 1,
  1587. &res,
  1588. sizeof (coroipc_response_header_t));
  1589. if (error != CS_OK) {
  1590. goto error_exit;
  1591. }
  1592. error = res.error;
  1593. error_exit:
  1594. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1595. return (error);
  1596. }
  1597. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1598. {
  1599. cs_error_t error;
  1600. struct confdb_inst *confdb_inst;
  1601. struct iovec iov;
  1602. coroipc_request_header_t req;
  1603. coroipc_response_header_t res;
  1604. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1605. if (error != CS_OK) {
  1606. return (error);
  1607. }
  1608. if (confdb_inst->standalone) {
  1609. error = CS_ERR_NOT_SUPPORTED;
  1610. goto error_exit;
  1611. }
  1612. req.size = sizeof (coroipc_request_header_t);
  1613. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1614. iov.iov_base = (char *)&req;
  1615. iov.iov_len = sizeof (coroipc_request_header_t);
  1616. error = coroipcc_msg_send_reply_receive (
  1617. confdb_inst->handle,
  1618. &iov,
  1619. 1,
  1620. &res,
  1621. sizeof (coroipc_response_header_t));
  1622. if (error != CS_OK) {
  1623. goto error_exit;
  1624. }
  1625. error = res.error;
  1626. error_exit:
  1627. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1628. return (error);
  1629. }