confdb.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. /*
  2. * Copyright (c) 2008-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * Provides access to data in the corosync object database
  36. */
  37. #include <config.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include <pthread.h>
  42. #include <sys/types.h>
  43. #include <errno.h>
  44. #include <corosync/corotypes.h>
  45. #include <corosync/coroipc_types.h>
  46. #include <corosync/coroipcc.h>
  47. #include <corosync/corodefs.h>
  48. #include <corosync/hdb.h>
  49. #include <corosync/list.h>
  50. #include <corosync/confdb.h>
  51. #include <corosync/ipc_confdb.h>
  52. #include "util.h"
  53. #include "sa-confdb.h"
  54. #undef MIN
  55. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  56. /* Hold the information for iterators so that
  57. callers can do recursive tree traversals.
  58. each object_handle can have its own iterator */
  59. struct iter_context {
  60. struct list_head list;
  61. hdb_handle_t parent_object_handle;
  62. hdb_handle_t find_handle;
  63. hdb_handle_t next_entry;
  64. };
  65. struct confdb_inst {
  66. hdb_handle_t handle;
  67. int finalize;
  68. int standalone;
  69. confdb_callbacks_t callbacks;
  70. const void *context;
  71. struct list_head object_find_head;
  72. struct list_head object_iter_head;
  73. struct list_head key_iter_head;
  74. };
  75. DECLARE_HDB_DATABASE(confdb_handle_t_db,NULL);
  76. static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
  77. /* Safely tidy one iterator context list */
  78. static void free_context_list(struct confdb_inst *confdb_inst, struct list_head *list)
  79. {
  80. struct iter_context *context;
  81. struct list_head *iter, *tmp;
  82. for (iter = list->next, tmp = iter->next;
  83. iter != list; iter = tmp, tmp = iter->next) {
  84. context = list_entry (iter, struct iter_context, list);
  85. (void)do_find_destroy(confdb_inst, context->find_handle);
  86. free(context);
  87. }
  88. }
  89. static struct iter_context *find_iter_context(struct list_head *list, hdb_handle_t object_handle)
  90. {
  91. struct iter_context *context;
  92. struct list_head *iter;
  93. for (iter = list->next;
  94. iter != list; iter = iter->next) {
  95. context = list_entry (iter, struct iter_context, list);
  96. if (context->parent_object_handle == object_handle)
  97. return context;
  98. }
  99. return NULL;
  100. }
  101. /**
  102. * @defgroup confdb_corosync
  103. * @ingroup corosync
  104. *
  105. * @{
  106. */
  107. cs_error_t confdb_initialize (
  108. confdb_handle_t *handle,
  109. confdb_callbacks_t *callbacks)
  110. {
  111. cs_error_t error;
  112. struct confdb_inst *confdb_inst;
  113. error = hdb_error_to_cs(hdb_handle_create (&confdb_handle_t_db, sizeof (struct confdb_inst), handle));
  114. if (error != CS_OK) {
  115. goto error_no_destroy;
  116. }
  117. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, *handle, (void *)&confdb_inst));
  118. if (error != CS_OK) {
  119. goto error_destroy;
  120. }
  121. if (getenv("COROSYNC_DEFAULT_CONFIG_IFACE")) {
  122. error = confdb_sa_init();
  123. confdb_inst->standalone = 1;
  124. }
  125. else {
  126. error = coroipcc_service_connect (
  127. COROSYNC_SOCKET_NAME,
  128. CONFDB_SERVICE,
  129. IPC_REQUEST_SIZE,
  130. IPC_RESPONSE_SIZE,
  131. IPC_DISPATCH_SIZE,
  132. &confdb_inst->handle);
  133. }
  134. if (error != CS_OK)
  135. goto error_put_destroy;
  136. if (callbacks) {
  137. memcpy (&confdb_inst->callbacks, callbacks, sizeof (confdb_callbacks_t));
  138. }
  139. list_init (&confdb_inst->object_find_head);
  140. list_init (&confdb_inst->object_iter_head);
  141. list_init (&confdb_inst->key_iter_head);
  142. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  143. return (CS_OK);
  144. error_put_destroy:
  145. (void)hdb_handle_put (&confdb_handle_t_db, *handle);
  146. error_destroy:
  147. (void)hdb_handle_destroy (&confdb_handle_t_db, *handle);
  148. error_no_destroy:
  149. return (error);
  150. }
  151. cs_error_t confdb_finalize (
  152. confdb_handle_t handle)
  153. {
  154. struct confdb_inst *confdb_inst;
  155. cs_error_t error;
  156. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  157. if (error != CS_OK) {
  158. return (error);
  159. }
  160. /*
  161. * Another thread has already started finalizing
  162. */
  163. if (confdb_inst->finalize) {
  164. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  165. return (CS_ERR_BAD_HANDLE);
  166. }
  167. confdb_inst->finalize = 1;
  168. /* Free saved context handles */
  169. free_context_list(confdb_inst, &confdb_inst->object_find_head);
  170. free_context_list(confdb_inst, &confdb_inst->object_iter_head);
  171. free_context_list(confdb_inst, &confdb_inst->key_iter_head);
  172. if (!confdb_inst->standalone) {
  173. coroipcc_service_disconnect (confdb_inst->handle);
  174. }
  175. (void)hdb_handle_destroy (&confdb_handle_t_db, handle);
  176. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  177. return (CS_OK);
  178. }
  179. cs_error_t confdb_fd_get (
  180. confdb_handle_t handle,
  181. int *fd)
  182. {
  183. cs_error_t error;
  184. struct confdb_inst *confdb_inst;
  185. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  186. if (error != CS_OK) {
  187. return (error);
  188. }
  189. error = coroipcc_fd_get (confdb_inst->handle, fd);
  190. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  191. return (error);
  192. }
  193. cs_error_t confdb_context_get (
  194. confdb_handle_t handle,
  195. const void **context)
  196. {
  197. cs_error_t error;
  198. struct confdb_inst *confdb_inst;
  199. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  200. if (error != CS_OK) {
  201. return (error);
  202. }
  203. *context = confdb_inst->context;
  204. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  205. return (CS_OK);
  206. }
  207. cs_error_t confdb_context_set (
  208. confdb_handle_t handle,
  209. const void *context)
  210. {
  211. cs_error_t error;
  212. struct confdb_inst *confdb_inst;
  213. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  214. if (error != CS_OK) {
  215. return (error);
  216. }
  217. confdb_inst->context = context;
  218. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  219. return (CS_OK);
  220. }
  221. cs_error_t confdb_dispatch (
  222. confdb_handle_t handle,
  223. cs_dispatch_flags_t dispatch_types)
  224. {
  225. int timeout = -1;
  226. cs_error_t error;
  227. int cont = 1; /* always continue do loop except when set to 0 */
  228. struct confdb_inst *confdb_inst;
  229. confdb_callbacks_t callbacks;
  230. struct res_lib_confdb_key_change_callback *res_key_changed_pt;
  231. struct res_lib_confdb_object_create_callback *res_object_created_pt;
  232. struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt;
  233. struct res_lib_confdb_reload_callback *res_reload_pt;
  234. coroipc_response_header_t *dispatch_data;
  235. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  236. if (error != CS_OK) {
  237. return (error);
  238. }
  239. if (confdb_inst->standalone) {
  240. error = CS_ERR_NOT_SUPPORTED;
  241. goto error_put;
  242. }
  243. /*
  244. * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
  245. * wait indefinitely for CS_DISPATCH_BLOCKING
  246. */
  247. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  248. timeout = 0;
  249. }
  250. do {
  251. error = coroipcc_dispatch_get (
  252. confdb_inst->handle,
  253. (void **)&dispatch_data,
  254. timeout);
  255. if (error == CS_ERR_BAD_HANDLE) {
  256. error = CS_OK;
  257. goto error_put;
  258. }
  259. if (error == CS_ERR_TRY_AGAIN) {
  260. error = CS_OK;
  261. if (dispatch_types == CONFDB_DISPATCH_ALL) {
  262. break; /* exit do while cont is 1 loop */
  263. } else {
  264. continue; /* next poll */
  265. }
  266. }
  267. if (error != CS_OK) {
  268. goto error_put;
  269. }
  270. /*
  271. * Make copy of callbacks, message data, unlock instance, and call callback
  272. * A risk of this dispatch method is that the callback routines may
  273. * operate at the same time that confdbFinalize has been called.
  274. */
  275. memcpy (&callbacks, &confdb_inst->callbacks, sizeof (confdb_callbacks_t));
  276. /*
  277. * Dispatch incoming message
  278. */
  279. switch (dispatch_data->id) {
  280. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK:
  281. if (callbacks.confdb_key_change_notify_fn == NULL) {
  282. break;
  283. }
  284. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  285. callbacks.confdb_key_change_notify_fn(handle,
  286. res_key_changed_pt->change_type,
  287. res_key_changed_pt->object_handle,
  288. res_key_changed_pt->parent_object_handle,
  289. res_key_changed_pt->object_name.value,
  290. res_key_changed_pt->object_name.length,
  291. res_key_changed_pt->key_name.value,
  292. res_key_changed_pt->key_name.length,
  293. res_key_changed_pt->key_value.value,
  294. res_key_changed_pt->key_value.length);
  295. break;
  296. case MESSAGE_RES_CONFDB_KEY_CHANGE_CALLBACK2:
  297. if (callbacks.confdb_key_change_notify_fn == NULL) {
  298. break;
  299. }
  300. res_key_changed_pt = (struct res_lib_confdb_key_change_callback *)dispatch_data;
  301. callbacks.confdb_key_change_notify_fn(handle,
  302. res_key_changed_pt->change_type,
  303. res_key_changed_pt->object_handle,
  304. res_key_changed_pt->parent_object_handle,
  305. res_key_changed_pt->object_name.value,
  306. res_key_changed_pt->object_name.length,
  307. res_key_changed_pt->key_name.value,
  308. res_key_changed_pt->key_name.length,
  309. &res_key_changed_pt->key_value.value,
  310. res_key_changed_pt->key_value.length);
  311. break;
  312. case MESSAGE_RES_CONFDB_OBJECT_CREATE_CALLBACK:
  313. if (callbacks.confdb_object_create_change_notify_fn == NULL) {
  314. break;
  315. }
  316. res_object_created_pt = (struct res_lib_confdb_object_create_callback *)dispatch_data;
  317. callbacks.confdb_object_create_change_notify_fn(handle,
  318. res_object_created_pt->object_handle,
  319. res_object_created_pt->parent_object_handle,
  320. res_object_created_pt->name.value,
  321. res_object_created_pt->name.length);
  322. break;
  323. case MESSAGE_RES_CONFDB_OBJECT_DESTROY_CALLBACK:
  324. if (callbacks.confdb_object_delete_change_notify_fn == NULL) {
  325. break;
  326. }
  327. res_object_destroyed_pt = (struct res_lib_confdb_object_destroy_callback *)dispatch_data;
  328. callbacks.confdb_object_delete_change_notify_fn(handle,
  329. res_object_destroyed_pt->parent_object_handle,
  330. res_object_destroyed_pt->name.value,
  331. res_object_destroyed_pt->name.length);
  332. break;
  333. case MESSAGE_RES_CONFDB_RELOAD_CALLBACK:
  334. if (callbacks.confdb_reload_notify_fn == NULL) {
  335. continue;
  336. }
  337. res_reload_pt = (struct res_lib_confdb_reload_callback *)dispatch_data;
  338. callbacks.confdb_reload_notify_fn(handle,
  339. res_reload_pt->type);
  340. break;
  341. default:
  342. error = coroipcc_dispatch_put (confdb_inst->handle);
  343. if (error == CS_OK) {
  344. error = CS_ERR_LIBRARY;
  345. }
  346. goto error_put;
  347. break;
  348. }
  349. error = coroipcc_dispatch_put (confdb_inst->handle);
  350. if (error != CS_OK) {
  351. goto error_put;
  352. }
  353. /*
  354. * Determine if more messages should be processed
  355. */
  356. if (dispatch_types == CS_DISPATCH_ONE) {
  357. cont = 0;
  358. }
  359. } while (cont);
  360. error_put:
  361. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  362. return (error);
  363. }
  364. cs_error_t confdb_object_create (
  365. confdb_handle_t handle,
  366. hdb_handle_t parent_object_handle,
  367. const void *object_name,
  368. size_t object_name_len,
  369. hdb_handle_t *object_handle)
  370. {
  371. cs_error_t error;
  372. struct confdb_inst *confdb_inst;
  373. struct iovec iov;
  374. struct req_lib_confdb_object_create req_lib_confdb_object_create;
  375. struct res_lib_confdb_object_create res_lib_confdb_object_create;
  376. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  377. if (error != CS_OK) {
  378. return (error);
  379. }
  380. if (confdb_inst->standalone) {
  381. error = CS_OK;
  382. if (confdb_sa_object_create(parent_object_handle,
  383. object_name, object_name_len,
  384. object_handle))
  385. error = CS_ERR_ACCESS;
  386. goto error_exit;
  387. }
  388. req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create);
  389. req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE;
  390. req_lib_confdb_object_create.parent_object_handle = parent_object_handle;
  391. memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len);
  392. req_lib_confdb_object_create.object_name.length = object_name_len;
  393. iov.iov_base = (char *)&req_lib_confdb_object_create;
  394. iov.iov_len = sizeof (struct req_lib_confdb_object_create);
  395. error = coroipcc_msg_send_reply_receive (
  396. confdb_inst->handle,
  397. &iov,
  398. 1,
  399. &res_lib_confdb_object_create,
  400. sizeof (struct res_lib_confdb_object_create));
  401. if (error != CS_OK) {
  402. goto error_exit;
  403. }
  404. error = res_lib_confdb_object_create.header.error;
  405. *object_handle = res_lib_confdb_object_create.object_handle;
  406. error_exit:
  407. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  408. return (error);
  409. }
  410. cs_error_t confdb_object_destroy (
  411. confdb_handle_t handle,
  412. hdb_handle_t object_handle)
  413. {
  414. cs_error_t error;
  415. struct confdb_inst *confdb_inst;
  416. struct iovec iov;
  417. struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy;
  418. coroipc_response_header_t res;
  419. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  420. if (error != CS_OK) {
  421. return (error);
  422. }
  423. if (confdb_inst->standalone) {
  424. error = CS_OK;
  425. if (confdb_sa_object_destroy(object_handle))
  426. error = CS_ERR_ACCESS;
  427. goto error_exit;
  428. }
  429. req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy);
  430. req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY;
  431. req_lib_confdb_object_destroy.object_handle = object_handle;
  432. iov.iov_base = (char *)&req_lib_confdb_object_destroy;
  433. iov.iov_len = sizeof (struct req_lib_confdb_object_destroy);
  434. error = coroipcc_msg_send_reply_receive (
  435. confdb_inst->handle,
  436. &iov,
  437. 1,
  438. &res,
  439. sizeof (coroipc_response_header_t));
  440. if (error != CS_OK) {
  441. goto error_exit;
  442. }
  443. error = res.error;
  444. error_exit:
  445. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  446. return (error);
  447. }
  448. cs_error_t confdb_object_parent_get (
  449. confdb_handle_t handle,
  450. hdb_handle_t object_handle,
  451. hdb_handle_t *parent_object_handle)
  452. {
  453. cs_error_t error;
  454. struct confdb_inst *confdb_inst;
  455. struct iovec iov;
  456. struct req_lib_confdb_object_parent_get req_lib_confdb_object_parent_get;
  457. struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get;
  458. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  459. if (error != CS_OK) {
  460. return (error);
  461. }
  462. if (confdb_inst->standalone) {
  463. error = CS_OK;
  464. if (confdb_sa_object_parent_get(object_handle, parent_object_handle))
  465. error = CS_ERR_ACCESS;
  466. goto error_exit;
  467. }
  468. req_lib_confdb_object_parent_get.header.size = sizeof (struct req_lib_confdb_object_parent_get);
  469. req_lib_confdb_object_parent_get.header.id = MESSAGE_REQ_CONFDB_OBJECT_PARENT_GET;
  470. req_lib_confdb_object_parent_get.object_handle = object_handle;
  471. iov.iov_base = (char *)&req_lib_confdb_object_parent_get;
  472. iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get);
  473. error = coroipcc_msg_send_reply_receive (
  474. confdb_inst->handle,
  475. &iov,
  476. 1,
  477. &res_lib_confdb_object_parent_get,
  478. sizeof (struct res_lib_confdb_object_parent_get));
  479. if (error != CS_OK) {
  480. goto error_exit;
  481. }
  482. error = res_lib_confdb_object_parent_get.header.error;
  483. *parent_object_handle = res_lib_confdb_object_parent_get.parent_object_handle;
  484. error_exit:
  485. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  486. return (error);
  487. }
  488. cs_error_t confdb_object_name_get (
  489. confdb_handle_t handle,
  490. hdb_handle_t object_handle,
  491. char *object_name,
  492. size_t *object_name_len)
  493. {
  494. cs_error_t error;
  495. struct confdb_inst *confdb_inst;
  496. struct iovec iov;
  497. struct req_lib_confdb_object_name_get request;
  498. struct res_lib_confdb_object_name_get response;
  499. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  500. if (error != CS_OK) {
  501. return (error);
  502. }
  503. if (confdb_inst->standalone) {
  504. error = CS_OK;
  505. if (confdb_sa_object_name_get(object_handle, object_name, object_name_len))
  506. error = CS_ERR_ACCESS;
  507. goto error_exit;
  508. }
  509. request.header.size = sizeof (struct req_lib_confdb_object_name_get);
  510. request.header.id = MESSAGE_REQ_CONFDB_OBJECT_NAME_GET;
  511. request.object_handle = object_handle;
  512. iov.iov_base = (char *)&request;
  513. iov.iov_len = sizeof (struct req_lib_confdb_object_name_get);
  514. error = coroipcc_msg_send_reply_receive (
  515. confdb_inst->handle,
  516. &iov,
  517. 1,
  518. &response,
  519. sizeof (struct res_lib_confdb_object_name_get));
  520. if (error != CS_OK) {
  521. goto error_exit;
  522. }
  523. error = response.header.error;
  524. if (error == CS_OK) {
  525. *object_name_len = response.object_name.length;
  526. memcpy(object_name, response.object_name.value, *object_name_len);
  527. }
  528. error_exit:
  529. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  530. return (error);
  531. }
  532. static cs_error_t do_find_destroy(
  533. struct confdb_inst *confdb_inst,
  534. hdb_handle_t find_handle)
  535. {
  536. cs_error_t error;
  537. struct iovec iov;
  538. struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy;
  539. coroipc_response_header_t res;
  540. if (!find_handle)
  541. return CS_OK;
  542. if (confdb_inst->standalone) {
  543. error = CS_OK;
  544. if (confdb_sa_find_destroy(find_handle))
  545. error = CS_ERR_ACCESS;
  546. goto error_exit;
  547. }
  548. req_lib_confdb_object_find_destroy.header.size = sizeof (struct req_lib_confdb_object_find_destroy);
  549. req_lib_confdb_object_find_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_DESTROY;
  550. req_lib_confdb_object_find_destroy.find_handle = find_handle;
  551. iov.iov_base = (char *)&req_lib_confdb_object_find_destroy;
  552. iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy);
  553. error = coroipcc_msg_send_reply_receive (
  554. confdb_inst->handle,
  555. &iov,
  556. 1,
  557. &res,
  558. sizeof (coroipc_response_header_t));
  559. if (error != CS_OK) {
  560. goto error_exit;
  561. }
  562. error = res.error;
  563. error_exit:
  564. return (error);
  565. }
  566. cs_error_t confdb_object_find_destroy(
  567. confdb_handle_t handle,
  568. hdb_handle_t parent_object_handle)
  569. {
  570. struct iter_context *context;
  571. cs_error_t error;
  572. struct confdb_inst *confdb_inst;
  573. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  574. if (error != CS_OK) {
  575. return (error);
  576. }
  577. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  578. error = do_find_destroy(confdb_inst, context->find_handle);
  579. if (error == CS_OK) {
  580. list_del(&context->list);
  581. free(context);
  582. }
  583. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  584. return error;
  585. }
  586. cs_error_t confdb_object_iter_destroy(
  587. confdb_handle_t handle,
  588. hdb_handle_t parent_object_handle)
  589. {
  590. struct iter_context *context;
  591. cs_error_t error;
  592. struct confdb_inst *confdb_inst;
  593. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  594. if (error != CS_OK) {
  595. return (error);
  596. }
  597. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  598. error = do_find_destroy(confdb_inst, context->find_handle);
  599. if (error == CS_OK) {
  600. list_del(&context->list);
  601. free(context);
  602. }
  603. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  604. return error;
  605. }
  606. cs_error_t confdb_key_create (
  607. confdb_handle_t handle,
  608. hdb_handle_t parent_object_handle,
  609. const void *key_name,
  610. size_t key_name_len,
  611. const void *value,
  612. size_t value_len)
  613. {
  614. cs_error_t error;
  615. struct confdb_inst *confdb_inst;
  616. struct iovec iov;
  617. struct req_lib_confdb_key_create req_lib_confdb_key_create;
  618. coroipc_response_header_t res;
  619. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  620. if (error != CS_OK) {
  621. return (error);
  622. }
  623. if (confdb_inst->standalone) {
  624. error = CS_OK;
  625. if (confdb_sa_key_create(parent_object_handle,
  626. key_name, key_name_len,
  627. value, value_len))
  628. error = CS_ERR_ACCESS;
  629. goto error_exit;
  630. }
  631. req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create);
  632. req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE;
  633. req_lib_confdb_key_create.object_handle = parent_object_handle;
  634. memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len);
  635. req_lib_confdb_key_create.key_name.length = key_name_len;
  636. memcpy(req_lib_confdb_key_create.value.value, value, value_len);
  637. req_lib_confdb_key_create.value.length = value_len;
  638. iov.iov_base = (char *)&req_lib_confdb_key_create;
  639. iov.iov_len = sizeof (struct req_lib_confdb_key_create);
  640. error = coroipcc_msg_send_reply_receive (
  641. confdb_inst->handle,
  642. &iov,
  643. 1,
  644. &res,
  645. sizeof (res));
  646. if (error != CS_OK) {
  647. goto error_exit;
  648. }
  649. error = res.error;
  650. error_exit:
  651. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  652. return (error);
  653. }
  654. cs_error_t confdb_key_create_typed (
  655. confdb_handle_t handle,
  656. hdb_handle_t parent_object_handle,
  657. const char *key_name,
  658. const void *value,
  659. size_t value_len,
  660. confdb_value_types_t type)
  661. {
  662. cs_error_t error;
  663. struct confdb_inst *confdb_inst;
  664. struct iovec iov;
  665. struct req_lib_confdb_key_create_typed2 *request;
  666. coroipc_response_header_t res;
  667. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  668. if (error != CS_OK) {
  669. return (error);
  670. }
  671. if (confdb_inst->standalone) {
  672. error = CS_OK;
  673. if (confdb_sa_key_create_typed(parent_object_handle,
  674. key_name, value, value_len, type))
  675. error = CS_ERR_ACCESS;
  676. goto error_exit;
  677. }
  678. request = malloc(sizeof(struct req_lib_confdb_key_create_typed2)+value_len);
  679. if (!request) {
  680. error = CS_ERR_NO_MEMORY;
  681. goto error_exit;
  682. }
  683. request->header.size = sizeof (struct req_lib_confdb_key_create_typed2) + value_len;
  684. request->header.id = MESSAGE_REQ_CONFDB_KEY_CREATE_TYPED2;
  685. request->object_handle = parent_object_handle;
  686. request->key_name.length = strlen(key_name)+1;
  687. memcpy(request->key_name.value, key_name, request->key_name.length);
  688. memcpy(&request->value, value, value_len);
  689. request->value_length = value_len;
  690. request->type = type;
  691. iov.iov_base = (char *)request;
  692. iov.iov_len = request->header.size;
  693. error = coroipcc_msg_send_reply_receive (
  694. confdb_inst->handle,
  695. &iov,
  696. 1,
  697. &res,
  698. sizeof (res));
  699. if (error != CS_OK) {
  700. goto free_exit;
  701. }
  702. error = res.error;
  703. free_exit:
  704. free(request);
  705. error_exit:
  706. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  707. return (error);
  708. }
  709. cs_error_t confdb_key_delete (
  710. confdb_handle_t handle,
  711. hdb_handle_t parent_object_handle,
  712. const void *key_name,
  713. size_t key_name_len,
  714. const void *value,
  715. size_t value_len)
  716. {
  717. cs_error_t error;
  718. struct confdb_inst *confdb_inst;
  719. struct iovec iov;
  720. struct req_lib_confdb_key_delete req_lib_confdb_key_delete;
  721. coroipc_response_header_t res;
  722. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  723. if (error != CS_OK) {
  724. return (error);
  725. }
  726. if (confdb_inst->standalone) {
  727. error = CS_OK;
  728. if (confdb_sa_key_delete(parent_object_handle,
  729. key_name, key_name_len,
  730. value, value_len))
  731. error = CS_ERR_ACCESS;
  732. goto error_exit;
  733. }
  734. req_lib_confdb_key_delete.header.size = sizeof (struct req_lib_confdb_key_delete);
  735. req_lib_confdb_key_delete.header.id = MESSAGE_REQ_CONFDB_KEY_DELETE;
  736. req_lib_confdb_key_delete.object_handle = parent_object_handle;
  737. memcpy(req_lib_confdb_key_delete.key_name.value, key_name, key_name_len);
  738. req_lib_confdb_key_delete.key_name.length = key_name_len;
  739. memcpy(req_lib_confdb_key_delete.value.value, value, value_len);
  740. req_lib_confdb_key_delete.value.length = value_len;
  741. iov.iov_base = (char *)&req_lib_confdb_key_delete;
  742. iov.iov_len = sizeof (struct req_lib_confdb_key_delete);
  743. error = coroipcc_msg_send_reply_receive (
  744. confdb_inst->handle,
  745. &iov,
  746. 1,
  747. &res,
  748. sizeof (res));
  749. if (error != CS_OK) {
  750. goto error_exit;
  751. }
  752. error = res.error;
  753. error_exit:
  754. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  755. return (error);
  756. }
  757. cs_error_t confdb_key_get (
  758. confdb_handle_t handle,
  759. hdb_handle_t parent_object_handle,
  760. const void *key_name,
  761. size_t key_name_len,
  762. void *value,
  763. size_t *value_len)
  764. {
  765. cs_error_t error;
  766. struct confdb_inst *confdb_inst;
  767. struct iovec iov;
  768. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  769. struct res_lib_confdb_key_get res_lib_confdb_key_get;
  770. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  771. if (error != CS_OK) {
  772. return (error);
  773. }
  774. if (confdb_inst->standalone) {
  775. error = CS_OK;
  776. if (confdb_sa_key_get(parent_object_handle,
  777. key_name, key_name_len,
  778. value, value_len))
  779. error = CS_ERR_ACCESS;
  780. goto error_exit;
  781. }
  782. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  783. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET;
  784. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  785. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  786. req_lib_confdb_key_get.key_name.length = key_name_len;
  787. iov.iov_base = (char *)&req_lib_confdb_key_get;
  788. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  789. error = coroipcc_msg_send_reply_receive (
  790. confdb_inst->handle,
  791. &iov,
  792. 1,
  793. &res_lib_confdb_key_get,
  794. sizeof (struct res_lib_confdb_key_get));
  795. if (error != CS_OK) {
  796. goto error_exit;
  797. }
  798. error = res_lib_confdb_key_get.header.error;
  799. if (error == CS_OK) {
  800. *value_len = res_lib_confdb_key_get.value.length;
  801. memcpy(value, res_lib_confdb_key_get.value.value, *value_len);
  802. }
  803. error_exit:
  804. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  805. return (error);
  806. }
  807. cs_error_t confdb_key_get_typed (
  808. confdb_handle_t handle,
  809. hdb_handle_t parent_object_handle,
  810. const char *key_name,
  811. void *value,
  812. size_t *value_len,
  813. confdb_value_types_t *type)
  814. {
  815. cs_error_t error;
  816. struct confdb_inst *confdb_inst;
  817. struct iovec iov;
  818. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  819. struct res_lib_confdb_key_get_typed response;
  820. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  821. if (error != CS_OK) {
  822. return (error);
  823. }
  824. if (confdb_inst->standalone) {
  825. error = CS_OK;
  826. if (confdb_sa_key_get_typed(parent_object_handle,
  827. key_name, &value, value_len, (int*)type))
  828. error = CS_ERR_ACCESS;
  829. goto error_exit;
  830. }
  831. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  832. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED;
  833. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  834. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  835. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  836. iov.iov_base = (char *)&req_lib_confdb_key_get;
  837. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  838. error = coroipcc_msg_send_reply_receive (
  839. confdb_inst->handle,
  840. &iov,
  841. 1,
  842. &response,
  843. sizeof (struct res_lib_confdb_key_get_typed));
  844. if (error != CS_OK) {
  845. goto error_exit;
  846. }
  847. error = response.header.error;
  848. if (error == CS_OK) {
  849. *value_len = response.value.length;
  850. *type = response.type;
  851. memcpy(value, response.value.value, *value_len);
  852. }
  853. error_exit:
  854. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  855. return (error);
  856. }
  857. cs_error_t confdb_key_get_typed2 (
  858. confdb_handle_t handle,
  859. hdb_handle_t parent_object_handle,
  860. const char *key_name,
  861. void **value,
  862. size_t *value_len,
  863. confdb_value_types_t *type)
  864. {
  865. cs_error_t error;
  866. struct confdb_inst *confdb_inst;
  867. struct iovec iov;
  868. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  869. struct res_lib_confdb_key_get_typed2 *response;
  870. void *return_address;
  871. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  872. if (error != CS_OK) {
  873. return (error);
  874. }
  875. if (confdb_inst->standalone) {
  876. error = CS_OK;
  877. if (confdb_sa_key_get_typed(parent_object_handle,
  878. key_name, value, value_len, (int*)type))
  879. error = CS_ERR_ACCESS;
  880. goto error_exit;
  881. }
  882. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  883. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET_TYPED2;
  884. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  885. req_lib_confdb_key_get.key_name.length = strlen(key_name) + 1;
  886. memcpy(req_lib_confdb_key_get.key_name.value, key_name, req_lib_confdb_key_get.key_name.length);
  887. iov.iov_base = (char *)&req_lib_confdb_key_get;
  888. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  889. error = coroipcc_msg_send_reply_receive_in_buf_get (
  890. confdb_inst->handle,
  891. &iov,
  892. 1,
  893. &return_address);
  894. response = return_address;
  895. if (error != CS_OK) {
  896. goto error_exit;
  897. }
  898. error = response->header.error;
  899. if (error == CS_OK) {
  900. if (!*value) {
  901. /* Allow space for naughty callers to put a NUL for printing */
  902. *value = malloc(response->value_length+1);
  903. if (!*value) {
  904. error = CS_ERR_NO_MEMORY;
  905. goto error_exit;
  906. }
  907. }
  908. memcpy(*value, &response->value, response->value_length);
  909. *value_len = response->value_length;
  910. *type = response->type;
  911. }
  912. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  913. error_exit:
  914. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  915. return (error);
  916. }
  917. cs_error_t confdb_key_increment (
  918. confdb_handle_t handle,
  919. hdb_handle_t parent_object_handle,
  920. const void *key_name,
  921. size_t key_name_len,
  922. unsigned int *value)
  923. {
  924. cs_error_t error;
  925. struct confdb_inst *confdb_inst;
  926. struct iovec iov;
  927. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  928. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  929. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  930. if (error != CS_OK) {
  931. return (error);
  932. }
  933. if (confdb_inst->standalone) {
  934. error = CS_OK;
  935. if (confdb_sa_key_increment(parent_object_handle,
  936. key_name, key_name_len,
  937. value))
  938. error = CS_ERR_ACCESS;
  939. goto error_exit;
  940. }
  941. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  942. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_INCREMENT;
  943. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  944. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  945. req_lib_confdb_key_get.key_name.length = key_name_len;
  946. iov.iov_base = (char *)&req_lib_confdb_key_get;
  947. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  948. error = coroipcc_msg_send_reply_receive (
  949. confdb_inst->handle,
  950. &iov,
  951. 1,
  952. &res_lib_confdb_key_incdec,
  953. sizeof (struct res_lib_confdb_key_incdec));
  954. if (error != CS_OK) {
  955. goto error_exit;
  956. }
  957. error = res_lib_confdb_key_incdec.header.error;
  958. if (error == CS_OK) {
  959. *value = res_lib_confdb_key_incdec.value;
  960. }
  961. error_exit:
  962. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  963. return (error);
  964. }
  965. cs_error_t confdb_key_decrement (
  966. confdb_handle_t handle,
  967. hdb_handle_t parent_object_handle,
  968. const void *key_name,
  969. size_t key_name_len,
  970. unsigned int *value)
  971. {
  972. cs_error_t error;
  973. struct confdb_inst *confdb_inst;
  974. struct iovec iov;
  975. struct req_lib_confdb_key_get req_lib_confdb_key_get;
  976. struct res_lib_confdb_key_incdec res_lib_confdb_key_incdec;
  977. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  978. if (error != CS_OK) {
  979. return (error);
  980. }
  981. if (confdb_inst->standalone) {
  982. error = CS_OK;
  983. if (confdb_sa_key_decrement(parent_object_handle,
  984. key_name, key_name_len,
  985. value))
  986. error = CS_ERR_ACCESS;
  987. goto error_exit;
  988. }
  989. req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get);
  990. req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_DECREMENT;
  991. req_lib_confdb_key_get.parent_object_handle = parent_object_handle;
  992. memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len);
  993. req_lib_confdb_key_get.key_name.length = key_name_len;
  994. iov.iov_base = (char *)&req_lib_confdb_key_get;
  995. iov.iov_len = sizeof (struct req_lib_confdb_key_get);
  996. error = coroipcc_msg_send_reply_receive (
  997. confdb_inst->handle,
  998. &iov,
  999. 1,
  1000. &res_lib_confdb_key_incdec,
  1001. sizeof (struct res_lib_confdb_key_incdec));
  1002. if (error != CS_OK) {
  1003. goto error_exit;
  1004. }
  1005. error = res_lib_confdb_key_incdec.header.error;
  1006. if (error == CS_OK) {
  1007. *value = res_lib_confdb_key_incdec.value;
  1008. }
  1009. error_exit:
  1010. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1011. return (error);
  1012. }
  1013. cs_error_t confdb_key_replace (
  1014. confdb_handle_t handle,
  1015. hdb_handle_t parent_object_handle,
  1016. const void *key_name,
  1017. size_t key_name_len,
  1018. const void *old_value,
  1019. size_t old_value_len,
  1020. const void *new_value,
  1021. size_t new_value_len)
  1022. {
  1023. cs_error_t error;
  1024. struct confdb_inst *confdb_inst;
  1025. struct iovec iov;
  1026. struct req_lib_confdb_key_replace2 *req_lib_confdb_key_replace;
  1027. coroipc_response_header_t res;
  1028. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1029. if (error != CS_OK) {
  1030. return (error);
  1031. }
  1032. if (confdb_inst->standalone) {
  1033. error = CS_OK;
  1034. if (confdb_sa_key_replace(parent_object_handle,
  1035. key_name, key_name_len,
  1036. old_value, old_value_len,
  1037. new_value, new_value_len))
  1038. error = CS_ERR_ACCESS;
  1039. goto error_exit;
  1040. }
  1041. req_lib_confdb_key_replace = malloc(sizeof(struct req_lib_confdb_key_replace2) + new_value_len);
  1042. req_lib_confdb_key_replace->header.size = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1043. req_lib_confdb_key_replace->header.id = MESSAGE_REQ_CONFDB_KEY_REPLACE2;
  1044. req_lib_confdb_key_replace->object_handle = parent_object_handle;
  1045. memcpy(req_lib_confdb_key_replace->key_name.value, key_name, key_name_len);
  1046. req_lib_confdb_key_replace->key_name.length = key_name_len;
  1047. memcpy(&req_lib_confdb_key_replace->new_value, new_value, new_value_len);
  1048. req_lib_confdb_key_replace->new_value_length = new_value_len;
  1049. /* Oddly objdb doesn't use the old value, so we don't bother sending it */
  1050. iov.iov_base = (char *)req_lib_confdb_key_replace;
  1051. iov.iov_len = sizeof(struct req_lib_confdb_key_replace2) + new_value_len;
  1052. error = coroipcc_msg_send_reply_receive (
  1053. confdb_inst->handle,
  1054. &iov,
  1055. 1,
  1056. &res,
  1057. sizeof (res));
  1058. if (error != CS_OK) {
  1059. goto free_exit;
  1060. }
  1061. error = res.error;
  1062. free_exit:
  1063. free(req_lib_confdb_key_replace);
  1064. error_exit:
  1065. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1066. return (error);
  1067. }
  1068. cs_error_t confdb_object_iter_start (
  1069. confdb_handle_t handle,
  1070. hdb_handle_t object_handle)
  1071. {
  1072. struct confdb_inst *confdb_inst;
  1073. cs_error_t error = CS_OK;
  1074. struct iter_context *context;
  1075. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1076. if (error != CS_OK) {
  1077. return (error);
  1078. }
  1079. context = find_iter_context(&confdb_inst->object_iter_head, object_handle);
  1080. if (!context) {
  1081. context = malloc(sizeof(struct iter_context));
  1082. if (!context) {
  1083. error = CS_ERR_NO_MEMORY;
  1084. goto ret;
  1085. }
  1086. context->parent_object_handle = object_handle;
  1087. context->find_handle = 0;
  1088. list_add(&context->list, &confdb_inst->object_iter_head);
  1089. }
  1090. /* Start a new find context */
  1091. if (context->find_handle) {
  1092. (void)do_find_destroy(confdb_inst, context->find_handle);
  1093. context->find_handle = 0;
  1094. }
  1095. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1096. ret:
  1097. return error;
  1098. }
  1099. cs_error_t confdb_key_iter_start (
  1100. confdb_handle_t handle,
  1101. hdb_handle_t object_handle)
  1102. {
  1103. struct confdb_inst *confdb_inst;
  1104. cs_error_t error = CS_OK;
  1105. struct iter_context *context;
  1106. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1107. if (error != CS_OK) {
  1108. return (error);
  1109. }
  1110. context = find_iter_context(&confdb_inst->key_iter_head, object_handle);
  1111. if (!context) {
  1112. context = malloc(sizeof(struct iter_context));
  1113. if (!context) {
  1114. error = CS_ERR_NO_MEMORY;
  1115. goto ret;
  1116. }
  1117. context->parent_object_handle = object_handle;
  1118. list_add(&context->list, &confdb_inst->key_iter_head);
  1119. }
  1120. context->find_handle = 0;
  1121. context->next_entry = 0;
  1122. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1123. ret:
  1124. return error;
  1125. }
  1126. cs_error_t confdb_object_find_start (
  1127. confdb_handle_t handle,
  1128. hdb_handle_t parent_object_handle)
  1129. {
  1130. struct confdb_inst *confdb_inst;
  1131. cs_error_t error = CS_OK;
  1132. struct iter_context *context;
  1133. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1134. if (error != CS_OK) {
  1135. return (error);
  1136. }
  1137. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1138. if (!context) {
  1139. context = malloc(sizeof(struct iter_context));
  1140. if (!context) {
  1141. error = CS_ERR_NO_MEMORY;
  1142. goto ret;
  1143. }
  1144. context->find_handle = 0;
  1145. context->parent_object_handle = parent_object_handle;
  1146. list_add(&context->list, &confdb_inst->object_find_head);
  1147. }
  1148. /* Start a new find context */
  1149. if (context->find_handle) {
  1150. (void)do_find_destroy(confdb_inst, context->find_handle);
  1151. context->find_handle = 0;
  1152. }
  1153. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1154. ret:
  1155. return error;
  1156. }
  1157. cs_error_t confdb_object_find (
  1158. confdb_handle_t handle,
  1159. hdb_handle_t parent_object_handle,
  1160. const void *object_name,
  1161. size_t object_name_len,
  1162. hdb_handle_t *object_handle)
  1163. {
  1164. cs_error_t error;
  1165. struct confdb_inst *confdb_inst;
  1166. struct iovec iov;
  1167. struct iter_context *context;
  1168. struct req_lib_confdb_object_find req_lib_confdb_object_find;
  1169. struct res_lib_confdb_object_find res_lib_confdb_object_find;
  1170. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1171. if (error != CS_OK) {
  1172. return (error);
  1173. }
  1174. /* You MUST call confdb_object_find_start first */
  1175. context = find_iter_context(&confdb_inst->object_find_head, parent_object_handle);
  1176. if (!context) {
  1177. error = CS_ERR_CONTEXT_NOT_FOUND;
  1178. goto error_exit;
  1179. }
  1180. if (confdb_inst->standalone) {
  1181. error = CS_OK;
  1182. if (confdb_sa_object_find(parent_object_handle,
  1183. &context->find_handle,
  1184. object_handle,
  1185. object_name, object_name_len))
  1186. error = CS_ERR_ACCESS;
  1187. goto error_exit;
  1188. }
  1189. req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find);
  1190. req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND;
  1191. req_lib_confdb_object_find.parent_object_handle = parent_object_handle;
  1192. req_lib_confdb_object_find.find_handle = context->find_handle;
  1193. memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len);
  1194. req_lib_confdb_object_find.object_name.length = object_name_len;
  1195. iov.iov_base = (char *)&req_lib_confdb_object_find;
  1196. iov.iov_len = sizeof (struct req_lib_confdb_object_find);
  1197. error = coroipcc_msg_send_reply_receive (
  1198. confdb_inst->handle,
  1199. &iov,
  1200. 1,
  1201. &res_lib_confdb_object_find,
  1202. sizeof (struct res_lib_confdb_object_find));
  1203. if (error != CS_OK) {
  1204. goto error_exit;
  1205. }
  1206. error = res_lib_confdb_object_find.header.error;
  1207. *object_handle = res_lib_confdb_object_find.object_handle;
  1208. context->find_handle = res_lib_confdb_object_find.find_handle;
  1209. error_exit:
  1210. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1211. return (error);
  1212. }
  1213. cs_error_t confdb_object_iter (
  1214. confdb_handle_t handle,
  1215. hdb_handle_t parent_object_handle,
  1216. hdb_handle_t *object_handle,
  1217. void *object_name,
  1218. size_t *object_name_len)
  1219. {
  1220. cs_error_t error;
  1221. struct confdb_inst *confdb_inst;
  1222. struct iovec iov;
  1223. struct iter_context *context;
  1224. struct req_lib_confdb_object_iter req_lib_confdb_object_iter;
  1225. struct res_lib_confdb_object_iter res_lib_confdb_object_iter;
  1226. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1227. if (error != CS_OK) {
  1228. return (error);
  1229. }
  1230. /* You MUST call confdb_object_iter_start first */
  1231. context = find_iter_context(&confdb_inst->object_iter_head, parent_object_handle);
  1232. if (!context) {
  1233. error = CS_ERR_CONTEXT_NOT_FOUND;
  1234. goto error_exit;
  1235. }
  1236. if (confdb_inst->standalone) {
  1237. error = CS_OK;
  1238. *object_name_len = 0;
  1239. if (confdb_sa_object_iter(parent_object_handle,
  1240. &context->find_handle,
  1241. object_handle,
  1242. NULL, 0,
  1243. object_name, object_name_len))
  1244. error = CS_ERR_ACCESS;
  1245. goto sa_exit;
  1246. }
  1247. req_lib_confdb_object_iter.header.size = sizeof (struct req_lib_confdb_object_iter);
  1248. req_lib_confdb_object_iter.header.id = MESSAGE_REQ_CONFDB_OBJECT_ITER;
  1249. req_lib_confdb_object_iter.parent_object_handle = parent_object_handle;
  1250. req_lib_confdb_object_iter.find_handle = context->find_handle;
  1251. iov.iov_base = (char *)&req_lib_confdb_object_iter;
  1252. iov.iov_len = sizeof (struct req_lib_confdb_object_iter);
  1253. error = coroipcc_msg_send_reply_receive (
  1254. confdb_inst->handle,
  1255. &iov,
  1256. 1,
  1257. &res_lib_confdb_object_iter,
  1258. sizeof (struct res_lib_confdb_object_iter));
  1259. if (error != CS_OK) {
  1260. goto error_exit;
  1261. }
  1262. error = res_lib_confdb_object_iter.header.error;
  1263. if (error == CS_OK) {
  1264. *object_name_len = res_lib_confdb_object_iter.object_name.length;
  1265. memcpy(object_name, res_lib_confdb_object_iter.object_name.value, *object_name_len);
  1266. *object_handle = res_lib_confdb_object_iter.object_handle;
  1267. context->find_handle = res_lib_confdb_object_iter.find_handle;
  1268. }
  1269. sa_exit:
  1270. error_exit:
  1271. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1272. return (error);
  1273. }
  1274. cs_error_t confdb_key_iter (
  1275. confdb_handle_t handle,
  1276. hdb_handle_t parent_object_handle,
  1277. void *key_name,
  1278. size_t *key_name_len,
  1279. void *value,
  1280. size_t *value_len)
  1281. {
  1282. cs_error_t error;
  1283. struct confdb_inst *confdb_inst;
  1284. struct iovec iov;
  1285. struct iter_context *context;
  1286. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1287. struct res_lib_confdb_key_iter res_lib_confdb_key_iter;
  1288. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1289. if (error != CS_OK) {
  1290. return (error);
  1291. }
  1292. /* You MUST call confdb_key_iter_start first */
  1293. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1294. if (!context) {
  1295. error = CS_ERR_CONTEXT_NOT_FOUND;
  1296. goto error_exit;
  1297. }
  1298. if (confdb_inst->standalone) {
  1299. error = CS_OK;
  1300. if (confdb_sa_key_iter(parent_object_handle,
  1301. context->next_entry,
  1302. key_name, key_name_len,
  1303. value, value_len))
  1304. error = CS_ERR_ACCESS;
  1305. goto sa_exit;
  1306. }
  1307. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1308. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER;
  1309. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1310. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1311. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1312. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1313. error = coroipcc_msg_send_reply_receive (
  1314. confdb_inst->handle,
  1315. &iov,
  1316. 1,
  1317. &res_lib_confdb_key_iter,
  1318. sizeof (struct res_lib_confdb_key_iter));
  1319. if (error != CS_OK) {
  1320. goto error_exit;
  1321. }
  1322. error = res_lib_confdb_key_iter.header.error;
  1323. if (error == CS_OK) {
  1324. char* key_name_str = (char*)key_name;
  1325. *key_name_len = res_lib_confdb_key_iter.key_name.length;
  1326. memcpy(key_name, res_lib_confdb_key_iter.key_name.value, *key_name_len);
  1327. key_name_str[res_lib_confdb_key_iter.key_name.length] = '\0';
  1328. *value_len = res_lib_confdb_key_iter.value.length;
  1329. memcpy(value, res_lib_confdb_key_iter.value.value, *value_len);
  1330. }
  1331. sa_exit:
  1332. context->next_entry++;
  1333. error_exit:
  1334. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1335. return (error);
  1336. }
  1337. cs_error_t confdb_key_iter_typed (
  1338. confdb_handle_t handle,
  1339. hdb_handle_t parent_object_handle,
  1340. char *key_name,
  1341. void *value,
  1342. size_t *value_len,
  1343. confdb_value_types_t *type)
  1344. {
  1345. cs_error_t error;
  1346. struct confdb_inst *confdb_inst;
  1347. struct iovec iov;
  1348. struct iter_context *context;
  1349. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1350. struct res_lib_confdb_key_iter_typed response;
  1351. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1352. if (error != CS_OK) {
  1353. return (error);
  1354. }
  1355. /* You MUST call confdb_key_iter_start first */
  1356. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1357. if (!context) {
  1358. error = CS_ERR_CONTEXT_NOT_FOUND;
  1359. goto error_exit;
  1360. }
  1361. if (confdb_inst->standalone) {
  1362. error = CS_OK;
  1363. if (confdb_sa_key_iter_typed(parent_object_handle,
  1364. context->next_entry,
  1365. key_name,
  1366. &value, value_len, (int*)type))
  1367. error = CS_ERR_ACCESS;
  1368. goto sa_exit;
  1369. }
  1370. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1371. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED;
  1372. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1373. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1374. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1375. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1376. error = coroipcc_msg_send_reply_receive (
  1377. confdb_inst->handle,
  1378. &iov,
  1379. 1,
  1380. &response,
  1381. sizeof (struct res_lib_confdb_key_iter_typed));
  1382. if (error != CS_OK) {
  1383. goto error_exit;
  1384. }
  1385. error = response.header.error;
  1386. if (error == CS_OK) {
  1387. memcpy(key_name, response.key_name.value, response.key_name.length);
  1388. key_name[response.key_name.length] = '\0';
  1389. *value_len = response.value.length;
  1390. memcpy(value, response.value.value, *value_len);
  1391. *type = response.type;
  1392. }
  1393. sa_exit:
  1394. context->next_entry++;
  1395. error_exit:
  1396. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1397. return (error);
  1398. }
  1399. cs_error_t confdb_key_iter_typed2 (
  1400. confdb_handle_t handle,
  1401. hdb_handle_t parent_object_handle,
  1402. char *key_name,
  1403. void **value,
  1404. size_t *value_len,
  1405. confdb_value_types_t *type)
  1406. {
  1407. cs_error_t error;
  1408. struct confdb_inst *confdb_inst;
  1409. struct iovec iov;
  1410. struct iter_context *context;
  1411. struct req_lib_confdb_key_iter req_lib_confdb_key_iter;
  1412. struct res_lib_confdb_key_iter_typed2 *response;
  1413. void *return_address;
  1414. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1415. if (error != CS_OK) {
  1416. return (error);
  1417. }
  1418. /* You MUST call confdb_key_iter_start first */
  1419. context = find_iter_context(&confdb_inst->key_iter_head, parent_object_handle);
  1420. if (!context) {
  1421. error = CS_ERR_CONTEXT_NOT_FOUND;
  1422. goto error_exit;
  1423. }
  1424. if (confdb_inst->standalone) {
  1425. error = CS_OK;
  1426. if (confdb_sa_key_iter_typed(parent_object_handle,
  1427. context->next_entry,
  1428. key_name,
  1429. value, value_len, (int*)type))
  1430. error = CS_ERR_ACCESS;
  1431. goto sa_exit;
  1432. }
  1433. req_lib_confdb_key_iter.header.size = sizeof (struct req_lib_confdb_key_iter);
  1434. req_lib_confdb_key_iter.header.id = MESSAGE_REQ_CONFDB_KEY_ITER_TYPED2;
  1435. req_lib_confdb_key_iter.parent_object_handle = parent_object_handle;
  1436. req_lib_confdb_key_iter.next_entry= context->next_entry;
  1437. iov.iov_base = (char *)&req_lib_confdb_key_iter;
  1438. iov.iov_len = sizeof (struct req_lib_confdb_key_iter);
  1439. error = coroipcc_msg_send_reply_receive_in_buf_get (
  1440. confdb_inst->handle,
  1441. &iov,
  1442. 1,
  1443. &return_address);
  1444. response = return_address;
  1445. if (error != CS_OK) {
  1446. goto error_exit;
  1447. }
  1448. error = response->header.error;
  1449. if (error == CS_OK) {
  1450. if (!*value) {
  1451. /* Allow space for naughty callers to put a NUL for printing */
  1452. *value = malloc(response->value_length+1);
  1453. if (!*value) {
  1454. error = CS_ERR_NO_MEMORY;
  1455. goto error_exit;
  1456. }
  1457. }
  1458. memcpy(key_name, response->key_name.value, response->key_name.length);
  1459. key_name[response->key_name.length] = '\0';
  1460. memcpy(*value, &response->value, response->value_length);
  1461. *value_len = response->value_length;
  1462. *type = response->type;
  1463. }
  1464. coroipcc_msg_send_reply_receive_in_buf_put(confdb_inst->handle);
  1465. sa_exit:
  1466. context->next_entry++;
  1467. error_exit:
  1468. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1469. return (error);
  1470. }
  1471. cs_error_t confdb_write (
  1472. confdb_handle_t handle,
  1473. char *error_text,
  1474. size_t errbuf_len)
  1475. {
  1476. cs_error_t error;
  1477. struct confdb_inst *confdb_inst;
  1478. struct iovec iov;
  1479. coroipc_request_header_t req;
  1480. struct res_lib_confdb_write res_lib_confdb_write;
  1481. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1482. if (error != CS_OK) {
  1483. /* FIXME: set error_text */
  1484. return (error);
  1485. }
  1486. if (confdb_inst->standalone) {
  1487. error = CS_OK;
  1488. if (confdb_sa_write(error_text, errbuf_len))
  1489. error = CS_ERR_ACCESS;
  1490. goto error_exit;
  1491. }
  1492. req.size = sizeof (coroipc_request_header_t);
  1493. req.id = MESSAGE_REQ_CONFDB_WRITE;
  1494. iov.iov_base = (char *)&req;
  1495. iov.iov_len = sizeof (coroipc_request_header_t);
  1496. error = coroipcc_msg_send_reply_receive (
  1497. confdb_inst->handle,
  1498. &iov,
  1499. 1,
  1500. &res_lib_confdb_write,
  1501. sizeof (struct res_lib_confdb_write));
  1502. if (error != CS_OK) {
  1503. /* FIXME: set error_text */
  1504. goto error_exit;
  1505. }
  1506. error = res_lib_confdb_write.header.error;
  1507. if (res_lib_confdb_write.error.length) {
  1508. memcpy(error_text, res_lib_confdb_write.error.value,
  1509. MIN(res_lib_confdb_write.error.length,errbuf_len));
  1510. error_text[errbuf_len-1] = '\0';
  1511. }
  1512. error_exit:
  1513. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1514. return (error);
  1515. }
  1516. cs_error_t confdb_reload (
  1517. confdb_handle_t handle,
  1518. int flush,
  1519. char *error_text,
  1520. size_t errbuf_len)
  1521. {
  1522. cs_error_t error;
  1523. struct confdb_inst *confdb_inst;
  1524. struct iovec iov;
  1525. struct res_lib_confdb_reload res_lib_confdb_reload;
  1526. struct req_lib_confdb_reload req_lib_confdb_reload;
  1527. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1528. if (error != CS_OK) {
  1529. /* FIXME: set error_text */
  1530. return (error);
  1531. }
  1532. if (confdb_inst->standalone) {
  1533. error = CS_OK;
  1534. if (confdb_sa_reload(flush, error_text, errbuf_len))
  1535. error = CS_ERR_ACCESS;
  1536. goto error_exit;
  1537. }
  1538. req_lib_confdb_reload.header.size = sizeof (req_lib_confdb_reload);
  1539. req_lib_confdb_reload.header.id = MESSAGE_REQ_CONFDB_RELOAD;
  1540. req_lib_confdb_reload.flush = flush;
  1541. iov.iov_base = (char *)&req_lib_confdb_reload;
  1542. iov.iov_len = sizeof (req_lib_confdb_reload);
  1543. error = coroipcc_msg_send_reply_receive (
  1544. confdb_inst->handle,
  1545. &iov,
  1546. 1,
  1547. &res_lib_confdb_reload,
  1548. sizeof (struct res_lib_confdb_reload));
  1549. if (error != CS_OK) {
  1550. /* FIXME: set error_text */
  1551. goto error_exit;
  1552. }
  1553. error = res_lib_confdb_reload.header.error;
  1554. if(res_lib_confdb_reload.error.length) {
  1555. memcpy(error_text, res_lib_confdb_reload.error.value,
  1556. MIN(res_lib_confdb_reload.error.length,errbuf_len));
  1557. error_text[errbuf_len-1] = '\0';
  1558. }
  1559. error_exit:
  1560. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1561. return (error);
  1562. }
  1563. cs_error_t confdb_track_changes (
  1564. confdb_handle_t handle,
  1565. hdb_handle_t object_handle,
  1566. unsigned int flags)
  1567. {
  1568. cs_error_t error;
  1569. struct confdb_inst *confdb_inst;
  1570. struct iovec iov;
  1571. struct req_lib_confdb_object_track_start req;
  1572. coroipc_response_header_t res;
  1573. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1574. if (error != CS_OK) {
  1575. return (error);
  1576. }
  1577. if (confdb_inst->standalone) {
  1578. error = CS_ERR_NOT_SUPPORTED;
  1579. goto error_exit;
  1580. }
  1581. req.header.size = sizeof (struct req_lib_confdb_object_track_start);
  1582. req.header.id = MESSAGE_REQ_CONFDB_TRACK_START;
  1583. req.object_handle = object_handle;
  1584. req.flags = flags;
  1585. iov.iov_base = (char *)&req;
  1586. iov.iov_len = sizeof (struct req_lib_confdb_object_track_start);
  1587. error = coroipcc_msg_send_reply_receive (
  1588. confdb_inst->handle,
  1589. &iov,
  1590. 1,
  1591. &res,
  1592. sizeof (coroipc_response_header_t));
  1593. if (error != CS_OK) {
  1594. goto error_exit;
  1595. }
  1596. error = res.error;
  1597. error_exit:
  1598. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1599. return (error);
  1600. }
  1601. cs_error_t confdb_stop_track_changes (confdb_handle_t handle)
  1602. {
  1603. cs_error_t error;
  1604. struct confdb_inst *confdb_inst;
  1605. struct iovec iov;
  1606. coroipc_request_header_t req;
  1607. coroipc_response_header_t res;
  1608. error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst));
  1609. if (error != CS_OK) {
  1610. return (error);
  1611. }
  1612. if (confdb_inst->standalone) {
  1613. error = CS_ERR_NOT_SUPPORTED;
  1614. goto error_exit;
  1615. }
  1616. req.size = sizeof (coroipc_request_header_t);
  1617. req.id = MESSAGE_REQ_CONFDB_TRACK_STOP;
  1618. iov.iov_base = (char *)&req;
  1619. iov.iov_len = sizeof (coroipc_request_header_t);
  1620. error = coroipcc_msg_send_reply_receive (
  1621. confdb_inst->handle,
  1622. &iov,
  1623. 1,
  1624. &res,
  1625. sizeof (coroipc_response_header_t));
  1626. if (error != CS_OK) {
  1627. goto error_exit;
  1628. }
  1629. error = res.error;
  1630. error_exit:
  1631. (void)hdb_handle_put (&confdb_handle_t_db, handle);
  1632. return (error);
  1633. }